xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
3*4882a593Smuzhiyun  * driver for Linux.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * This software is available to you under a choice of one of two
8*4882a593Smuzhiyun  * licenses.  You may choose to be licensed under the terms of the GNU
9*4882a593Smuzhiyun  * General Public License (GPL) Version 2, available from the file
10*4882a593Smuzhiyun  * COPYING in the main directory of this source tree, or the
11*4882a593Smuzhiyun  * OpenIB.org BSD license below:
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  *     Redistribution and use in source and binary forms, with or
14*4882a593Smuzhiyun  *     without modification, are permitted provided that the following
15*4882a593Smuzhiyun  *     conditions are met:
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  *      - Redistributions of source code must retain the above
18*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
19*4882a593Smuzhiyun  *        disclaimer.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  *      - Redistributions in binary form must reproduce the above
22*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
23*4882a593Smuzhiyun  *        disclaimer in the documentation and/or other materials
24*4882a593Smuzhiyun  *        provided with the distribution.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29*4882a593Smuzhiyun  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33*4882a593Smuzhiyun  * SOFTWARE.
34*4882a593Smuzhiyun  */
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #ifndef __T4VF_COMMON_H__
37*4882a593Smuzhiyun #define __T4VF_COMMON_H__
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #include "../cxgb4/t4_hw.h"
40*4882a593Smuzhiyun #include "../cxgb4/t4fw_api.h"
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
43*4882a593Smuzhiyun #define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
44*4882a593Smuzhiyun #define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* All T4 and later chips have their PCI-E Device IDs encoded as 0xVFPP where:
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  *   V  = "4" for T4; "5" for T5, etc. or
49*4882a593Smuzhiyun  *      = "a" for T4 FPGA; "b" for T4 FPGA, etc.
50*4882a593Smuzhiyun  *   F  = "0" for PF 0..3; "4".."7" for PF4..7; and "8" for VFs
51*4882a593Smuzhiyun  *   PP = adapter product designation
52*4882a593Smuzhiyun  */
53*4882a593Smuzhiyun #define CHELSIO_T4		0x4
54*4882a593Smuzhiyun #define CHELSIO_T5		0x5
55*4882a593Smuzhiyun #define CHELSIO_T6		0x6
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun enum chip_type {
58*4882a593Smuzhiyun 	T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
59*4882a593Smuzhiyun 	T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
60*4882a593Smuzhiyun 	T4_FIRST_REV	= T4_A1,
61*4882a593Smuzhiyun 	T4_LAST_REV	= T4_A2,
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
64*4882a593Smuzhiyun 	T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
65*4882a593Smuzhiyun 	T5_FIRST_REV	= T5_A0,
66*4882a593Smuzhiyun 	T5_LAST_REV	= T5_A1,
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /*
70*4882a593Smuzhiyun  * The "len16" field of a Firmware Command Structure ...
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun #define FW_LEN16(fw_struct) FW_CMD_LEN16_V(sizeof(fw_struct) / 16)
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun  * Per-VF statistics.
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun struct t4vf_port_stats {
78*4882a593Smuzhiyun 	/*
79*4882a593Smuzhiyun 	 * TX statistics.
80*4882a593Smuzhiyun 	 */
81*4882a593Smuzhiyun 	u64 tx_bcast_bytes;		/* broadcast */
82*4882a593Smuzhiyun 	u64 tx_bcast_frames;
83*4882a593Smuzhiyun 	u64 tx_mcast_bytes;		/* multicast */
84*4882a593Smuzhiyun 	u64 tx_mcast_frames;
85*4882a593Smuzhiyun 	u64 tx_ucast_bytes;		/* unicast */
86*4882a593Smuzhiyun 	u64 tx_ucast_frames;
87*4882a593Smuzhiyun 	u64 tx_drop_frames;		/* TX dropped frames */
88*4882a593Smuzhiyun 	u64 tx_offload_bytes;		/* offload */
89*4882a593Smuzhiyun 	u64 tx_offload_frames;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	/*
92*4882a593Smuzhiyun 	 * RX statistics.
93*4882a593Smuzhiyun 	 */
94*4882a593Smuzhiyun 	u64 rx_bcast_bytes;		/* broadcast */
95*4882a593Smuzhiyun 	u64 rx_bcast_frames;
96*4882a593Smuzhiyun 	u64 rx_mcast_bytes;		/* multicast */
97*4882a593Smuzhiyun 	u64 rx_mcast_frames;
98*4882a593Smuzhiyun 	u64 rx_ucast_bytes;
99*4882a593Smuzhiyun 	u64 rx_ucast_frames;		/* unicast */
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	u64 rx_err_frames;		/* RX error frames */
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun /*
105*4882a593Smuzhiyun  * Per-"port" (Virtual Interface) link configuration ...
106*4882a593Smuzhiyun  */
107*4882a593Smuzhiyun typedef u16 fw_port_cap16_t;    /* 16-bit Port Capabilities integral value */
108*4882a593Smuzhiyun typedef u32 fw_port_cap32_t;    /* 32-bit Port Capabilities integral value */
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun enum fw_caps {
111*4882a593Smuzhiyun 	FW_CAPS_UNKNOWN	= 0,	/* 0'ed out initial state */
112*4882a593Smuzhiyun 	FW_CAPS16	= 1,	/* old Firmware: 16-bit Port Capabilities */
113*4882a593Smuzhiyun 	FW_CAPS32	= 2,	/* new Firmware: 32-bit Port Capabilities */
114*4882a593Smuzhiyun };
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun enum cc_pause {
117*4882a593Smuzhiyun 	PAUSE_RX	= 1 << 0,
118*4882a593Smuzhiyun 	PAUSE_TX	= 1 << 1,
119*4882a593Smuzhiyun 	PAUSE_AUTONEG	= 1 << 2
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun enum cc_fec {
123*4882a593Smuzhiyun 	FEC_AUTO	= 1 << 0,	/* IEEE 802.3 "automatic" */
124*4882a593Smuzhiyun 	FEC_RS		= 1 << 1,	/* Reed-Solomon */
125*4882a593Smuzhiyun 	FEC_BASER_RS	= 1 << 2,	/* BaseR/Reed-Solomon */
126*4882a593Smuzhiyun };
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun struct link_config {
129*4882a593Smuzhiyun 	fw_port_cap32_t pcaps;		/* link capabilities */
130*4882a593Smuzhiyun 	fw_port_cap32_t	acaps;		/* advertised capabilities */
131*4882a593Smuzhiyun 	fw_port_cap32_t	lpacaps;	/* peer advertised capabilities */
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	fw_port_cap32_t	speed_caps;	/* speed(s) user has requested */
134*4882a593Smuzhiyun 	u32		speed;		/* actual link speed */
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	enum cc_pause	requested_fc;	/* flow control user has requested */
137*4882a593Smuzhiyun 	enum cc_pause	fc;		/* actual link flow control */
138*4882a593Smuzhiyun 	enum cc_pause   advertised_fc;  /* actual advertised flow control */
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	enum cc_fec	auto_fec;	/* Forward Error Correction: */
141*4882a593Smuzhiyun 	enum cc_fec	requested_fec;	/*   "automatic" (IEEE 802.3), */
142*4882a593Smuzhiyun 	enum cc_fec	fec;		/*   requested, and actual in use */
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	unsigned char	autoneg;	/* autonegotiating? */
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	unsigned char	link_ok;	/* link up? */
147*4882a593Smuzhiyun 	unsigned char	link_down_rc;	/* link down reason */
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /* Return true if the Link Configuration supports "High Speeds" (those greater
151*4882a593Smuzhiyun  * than 1Gb/s).
152*4882a593Smuzhiyun  */
is_x_10g_port(const struct link_config * lc)153*4882a593Smuzhiyun static inline bool is_x_10g_port(const struct link_config *lc)
154*4882a593Smuzhiyun {
155*4882a593Smuzhiyun 	fw_port_cap32_t speeds, high_speeds;
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
158*4882a593Smuzhiyun 	high_speeds =
159*4882a593Smuzhiyun 		speeds & ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	return high_speeds != 0;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun /*
165*4882a593Smuzhiyun  * General device parameters ...
166*4882a593Smuzhiyun  */
167*4882a593Smuzhiyun struct dev_params {
168*4882a593Smuzhiyun 	u32 fwrev;			/* firmware version */
169*4882a593Smuzhiyun 	u32 tprev;			/* TP Microcode Version */
170*4882a593Smuzhiyun };
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun /*
173*4882a593Smuzhiyun  * Scatter Gather Engine parameters.  These are almost all determined by the
174*4882a593Smuzhiyun  * Physical Function Driver.  We just need to grab them to see within which
175*4882a593Smuzhiyun  * environment we're playing ...
176*4882a593Smuzhiyun  */
177*4882a593Smuzhiyun struct sge_params {
178*4882a593Smuzhiyun 	u32 sge_control;		/* padding, boundaries, lengths, etc. */
179*4882a593Smuzhiyun 	u32 sge_control2;		/* T5: more of the same */
180*4882a593Smuzhiyun 	u32 sge_host_page_size;		/* PF0-7 page sizes */
181*4882a593Smuzhiyun 	u32 sge_egress_queues_per_page;	/* PF0-7 egress queues/page */
182*4882a593Smuzhiyun 	u32 sge_ingress_queues_per_page;/* PF0-7 ingress queues/page */
183*4882a593Smuzhiyun 	u32 sge_vf_hps;                 /* host page size for our vf */
184*4882a593Smuzhiyun 	u32 sge_vf_eq_qpp;		/* egress queues/page for our VF */
185*4882a593Smuzhiyun 	u32 sge_vf_iq_qpp;		/* ingress queues/page for our VF */
186*4882a593Smuzhiyun 	u32 sge_fl_buffer_size[16];	/* free list buffer sizes */
187*4882a593Smuzhiyun 	u32 sge_ingress_rx_threshold;	/* RX counter interrupt threshold[4] */
188*4882a593Smuzhiyun 	u32 sge_congestion_control;     /* congestion thresholds, etc. */
189*4882a593Smuzhiyun 	u32 sge_timer_value_0_and_1;	/* interrupt coalescing timer values */
190*4882a593Smuzhiyun 	u32 sge_timer_value_2_and_3;
191*4882a593Smuzhiyun 	u32 sge_timer_value_4_and_5;
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun /*
195*4882a593Smuzhiyun  * Vital Product Data parameters.
196*4882a593Smuzhiyun  */
197*4882a593Smuzhiyun struct vpd_params {
198*4882a593Smuzhiyun 	u32 cclk;			/* Core Clock (KHz) */
199*4882a593Smuzhiyun };
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /* Stores chip specific parameters */
202*4882a593Smuzhiyun struct arch_specific_params {
203*4882a593Smuzhiyun 	u32 sge_fl_db;
204*4882a593Smuzhiyun 	u16 mps_tcam_size;
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun /*
208*4882a593Smuzhiyun  * Global Receive Side Scaling (RSS) parameters in host-native format.
209*4882a593Smuzhiyun  */
210*4882a593Smuzhiyun struct rss_params {
211*4882a593Smuzhiyun 	unsigned int mode;		/* RSS mode */
212*4882a593Smuzhiyun 	union {
213*4882a593Smuzhiyun 	    struct {
214*4882a593Smuzhiyun 		unsigned int synmapen:1;	/* SYN Map Enable */
215*4882a593Smuzhiyun 		unsigned int syn4tupenipv6:1;	/* enable hashing 4-tuple IPv6 SYNs */
216*4882a593Smuzhiyun 		unsigned int syn2tupenipv6:1;	/* enable hashing 2-tuple IPv6 SYNs */
217*4882a593Smuzhiyun 		unsigned int syn4tupenipv4:1;	/* enable hashing 4-tuple IPv4 SYNs */
218*4882a593Smuzhiyun 		unsigned int syn2tupenipv4:1;	/* enable hashing 2-tuple IPv4 SYNs */
219*4882a593Smuzhiyun 		unsigned int ofdmapen:1;	/* Offload Map Enable */
220*4882a593Smuzhiyun 		unsigned int tnlmapen:1;	/* Tunnel Map Enable */
221*4882a593Smuzhiyun 		unsigned int tnlalllookup:1;	/* Tunnel All Lookup */
222*4882a593Smuzhiyun 		unsigned int hashtoeplitz:1;	/* use Toeplitz hash */
223*4882a593Smuzhiyun 	    } basicvirtual;
224*4882a593Smuzhiyun 	} u;
225*4882a593Smuzhiyun };
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun /*
228*4882a593Smuzhiyun  * Virtual Interface RSS Configuration in host-native format.
229*4882a593Smuzhiyun  */
230*4882a593Smuzhiyun union rss_vi_config {
231*4882a593Smuzhiyun     struct {
232*4882a593Smuzhiyun 	u16 defaultq;			/* Ingress Queue ID for !tnlalllookup */
233*4882a593Smuzhiyun 	unsigned int ip6fourtupen:1;	/* hash 4-tuple IPv6 ingress packets */
234*4882a593Smuzhiyun 	unsigned int ip6twotupen:1;	/* hash 2-tuple IPv6 ingress packets */
235*4882a593Smuzhiyun 	unsigned int ip4fourtupen:1;	/* hash 4-tuple IPv4 ingress packets */
236*4882a593Smuzhiyun 	unsigned int ip4twotupen:1;	/* hash 2-tuple IPv4 ingress packets */
237*4882a593Smuzhiyun 	int udpen;			/* hash 4-tuple UDP ingress packets */
238*4882a593Smuzhiyun     } basicvirtual;
239*4882a593Smuzhiyun };
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun /*
242*4882a593Smuzhiyun  * Maximum resources provisioned for a PCI VF.
243*4882a593Smuzhiyun  */
244*4882a593Smuzhiyun struct vf_resources {
245*4882a593Smuzhiyun 	unsigned int nvi;		/* N virtual interfaces */
246*4882a593Smuzhiyun 	unsigned int neq;		/* N egress Qs */
247*4882a593Smuzhiyun 	unsigned int nethctrl;		/* N egress ETH or CTRL Qs */
248*4882a593Smuzhiyun 	unsigned int niqflint;		/* N ingress Qs/w free list(s) & intr */
249*4882a593Smuzhiyun 	unsigned int niq;		/* N ingress Qs */
250*4882a593Smuzhiyun 	unsigned int tc;		/* PCI-E traffic class */
251*4882a593Smuzhiyun 	unsigned int pmask;		/* port access rights mask */
252*4882a593Smuzhiyun 	unsigned int nexactf;		/* N exact MPS filters */
253*4882a593Smuzhiyun 	unsigned int r_caps;		/* read capabilities */
254*4882a593Smuzhiyun 	unsigned int wx_caps;		/* write/execute capabilities */
255*4882a593Smuzhiyun };
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun /*
258*4882a593Smuzhiyun  * Per-"adapter" (Virtual Function) parameters.
259*4882a593Smuzhiyun  */
260*4882a593Smuzhiyun struct adapter_params {
261*4882a593Smuzhiyun 	struct dev_params dev;		/* general device parameters */
262*4882a593Smuzhiyun 	struct sge_params sge;		/* Scatter Gather Engine */
263*4882a593Smuzhiyun 	struct vpd_params vpd;		/* Vital Product Data */
264*4882a593Smuzhiyun 	struct rss_params rss;		/* Receive Side Scaling */
265*4882a593Smuzhiyun 	struct vf_resources vfres;	/* Virtual Function Resource limits */
266*4882a593Smuzhiyun 	struct arch_specific_params arch; /* chip specific params */
267*4882a593Smuzhiyun 	enum chip_type chip;		/* chip code */
268*4882a593Smuzhiyun 	u8 nports;			/* # of Ethernet "ports" */
269*4882a593Smuzhiyun 	u8 fw_caps_support;		/* 32-bit Port Capabilities */
270*4882a593Smuzhiyun };
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun /* Firmware Mailbox Command/Reply log.  All values are in Host-Endian format.
273*4882a593Smuzhiyun  * The access and execute times are signed in order to accommodate negative
274*4882a593Smuzhiyun  * error returns.
275*4882a593Smuzhiyun  */
276*4882a593Smuzhiyun struct mbox_cmd {
277*4882a593Smuzhiyun 	u64 cmd[MBOX_LEN / 8];		/* a Firmware Mailbox Command/Reply */
278*4882a593Smuzhiyun 	u64 timestamp;			/* OS-dependent timestamp */
279*4882a593Smuzhiyun 	u32 seqno;			/* sequence number */
280*4882a593Smuzhiyun 	s16 access;			/* time (ms) to access mailbox */
281*4882a593Smuzhiyun 	s16 execute;			/* time (ms) to execute */
282*4882a593Smuzhiyun };
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun struct mbox_cmd_log {
285*4882a593Smuzhiyun 	unsigned int size;		/* number of entries in the log */
286*4882a593Smuzhiyun 	unsigned int cursor;		/* next position in the log to write */
287*4882a593Smuzhiyun 	u32 seqno;			/* next sequence number */
288*4882a593Smuzhiyun 	/* variable length mailbox command log starts here */
289*4882a593Smuzhiyun };
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun /* Given a pointer to a Firmware Mailbox Command Log and a log entry index,
292*4882a593Smuzhiyun  * return a pointer to the specified entry.
293*4882a593Smuzhiyun  */
mbox_cmd_log_entry(struct mbox_cmd_log * log,unsigned int entry_idx)294*4882a593Smuzhiyun static inline struct mbox_cmd *mbox_cmd_log_entry(struct mbox_cmd_log *log,
295*4882a593Smuzhiyun 						  unsigned int entry_idx)
296*4882a593Smuzhiyun {
297*4882a593Smuzhiyun 	return &((struct mbox_cmd *)&(log)[1])[entry_idx];
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun #include "adapter.h"
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun #ifndef PCI_VENDOR_ID_CHELSIO
303*4882a593Smuzhiyun # define PCI_VENDOR_ID_CHELSIO 0x1425
304*4882a593Smuzhiyun #endif
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun #define for_each_port(adapter, iter) \
307*4882a593Smuzhiyun 	for (iter = 0; iter < (adapter)->params.nports; iter++)
308*4882a593Smuzhiyun 
core_ticks_per_usec(const struct adapter * adapter)309*4882a593Smuzhiyun static inline unsigned int core_ticks_per_usec(const struct adapter *adapter)
310*4882a593Smuzhiyun {
311*4882a593Smuzhiyun 	return adapter->params.vpd.cclk / 1000;
312*4882a593Smuzhiyun }
313*4882a593Smuzhiyun 
us_to_core_ticks(const struct adapter * adapter,unsigned int us)314*4882a593Smuzhiyun static inline unsigned int us_to_core_ticks(const struct adapter *adapter,
315*4882a593Smuzhiyun 					    unsigned int us)
316*4882a593Smuzhiyun {
317*4882a593Smuzhiyun 	return (us * adapter->params.vpd.cclk) / 1000;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun 
core_ticks_to_us(const struct adapter * adapter,unsigned int ticks)320*4882a593Smuzhiyun static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
321*4882a593Smuzhiyun 					    unsigned int ticks)
322*4882a593Smuzhiyun {
323*4882a593Smuzhiyun 	return (ticks * 1000) / adapter->params.vpd.cclk;
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun int t4vf_wr_mbox_core(struct adapter *, const void *, int, void *, bool);
327*4882a593Smuzhiyun 
t4vf_wr_mbox(struct adapter * adapter,const void * cmd,int size,void * rpl)328*4882a593Smuzhiyun static inline int t4vf_wr_mbox(struct adapter *adapter, const void *cmd,
329*4882a593Smuzhiyun 			       int size, void *rpl)
330*4882a593Smuzhiyun {
331*4882a593Smuzhiyun 	return t4vf_wr_mbox_core(adapter, cmd, size, rpl, true);
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun 
t4vf_wr_mbox_ns(struct adapter * adapter,const void * cmd,int size,void * rpl)334*4882a593Smuzhiyun static inline int t4vf_wr_mbox_ns(struct adapter *adapter, const void *cmd,
335*4882a593Smuzhiyun 				  int size, void *rpl)
336*4882a593Smuzhiyun {
337*4882a593Smuzhiyun 	return t4vf_wr_mbox_core(adapter, cmd, size, rpl, false);
338*4882a593Smuzhiyun }
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun #define CHELSIO_PCI_ID_VER(dev_id)  ((dev_id) >> 12)
341*4882a593Smuzhiyun 
is_t4(enum chip_type chip)342*4882a593Smuzhiyun static inline int is_t4(enum chip_type chip)
343*4882a593Smuzhiyun {
344*4882a593Smuzhiyun 	return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
345*4882a593Smuzhiyun }
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun /**
348*4882a593Smuzhiyun  *	hash_mac_addr - return the hash value of a MAC address
349*4882a593Smuzhiyun  *	@addr: the 48-bit Ethernet MAC address
350*4882a593Smuzhiyun  *
351*4882a593Smuzhiyun  *	Hashes a MAC address according to the hash function used by hardware
352*4882a593Smuzhiyun  *	inexact (hash) address matching.
353*4882a593Smuzhiyun  */
hash_mac_addr(const u8 * addr)354*4882a593Smuzhiyun static inline int hash_mac_addr(const u8 *addr)
355*4882a593Smuzhiyun {
356*4882a593Smuzhiyun 	u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2];
357*4882a593Smuzhiyun 	u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5];
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun 	a ^= b;
360*4882a593Smuzhiyun 	a ^= (a >> 12);
361*4882a593Smuzhiyun 	a ^= (a >> 6);
362*4882a593Smuzhiyun 	return a & 0x3f;
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun int t4vf_wait_dev_ready(struct adapter *);
366*4882a593Smuzhiyun int t4vf_port_init(struct adapter *, int);
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun int t4vf_fw_reset(struct adapter *);
369*4882a593Smuzhiyun int t4vf_set_params(struct adapter *, unsigned int, const u32 *, const u32 *);
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun int t4vf_fl_pkt_align(struct adapter *adapter);
372*4882a593Smuzhiyun enum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
373*4882a593Smuzhiyun int t4vf_bar2_sge_qregs(struct adapter *adapter,
374*4882a593Smuzhiyun 			unsigned int qid,
375*4882a593Smuzhiyun 			enum t4_bar2_qtype qtype,
376*4882a593Smuzhiyun 			u64 *pbar2_qoffset,
377*4882a593Smuzhiyun 			unsigned int *pbar2_qid);
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun unsigned int t4vf_get_pf_from_vf(struct adapter *);
380*4882a593Smuzhiyun int t4vf_get_sge_params(struct adapter *);
381*4882a593Smuzhiyun int t4vf_get_vpd_params(struct adapter *);
382*4882a593Smuzhiyun int t4vf_get_dev_params(struct adapter *);
383*4882a593Smuzhiyun int t4vf_get_rss_glb_config(struct adapter *);
384*4882a593Smuzhiyun int t4vf_get_vfres(struct adapter *);
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun int t4vf_read_rss_vi_config(struct adapter *, unsigned int,
387*4882a593Smuzhiyun 			    union rss_vi_config *);
388*4882a593Smuzhiyun int t4vf_write_rss_vi_config(struct adapter *, unsigned int,
389*4882a593Smuzhiyun 			     union rss_vi_config *);
390*4882a593Smuzhiyun int t4vf_config_rss_range(struct adapter *, unsigned int, int, int,
391*4882a593Smuzhiyun 			  const u16 *, int);
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun int t4vf_alloc_vi(struct adapter *, int);
394*4882a593Smuzhiyun int t4vf_free_vi(struct adapter *, int);
395*4882a593Smuzhiyun int t4vf_enable_vi(struct adapter *adapter, unsigned int viid, bool rx_en,
396*4882a593Smuzhiyun 		   bool tx_en);
397*4882a593Smuzhiyun int t4vf_enable_pi(struct adapter *adapter, struct port_info *pi, bool rx_en,
398*4882a593Smuzhiyun 		   bool tx_en);
399*4882a593Smuzhiyun int t4vf_identify_port(struct adapter *, unsigned int, unsigned int);
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun int t4vf_set_rxmode(struct adapter *, unsigned int, int, int, int, int, int,
402*4882a593Smuzhiyun 		    bool);
403*4882a593Smuzhiyun int t4vf_alloc_mac_filt(struct adapter *, unsigned int, bool, unsigned int,
404*4882a593Smuzhiyun 			const u8 **, u16 *, u64 *, bool);
405*4882a593Smuzhiyun int t4vf_free_mac_filt(struct adapter *, unsigned int, unsigned int naddr,
406*4882a593Smuzhiyun 		       const u8 **, bool);
407*4882a593Smuzhiyun int t4vf_change_mac(struct adapter *, unsigned int, int, const u8 *, bool);
408*4882a593Smuzhiyun int t4vf_set_addr_hash(struct adapter *, unsigned int, bool, u64, bool);
409*4882a593Smuzhiyun int t4vf_get_port_stats(struct adapter *, int, struct t4vf_port_stats *);
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun int t4vf_iq_free(struct adapter *, unsigned int, unsigned int, unsigned int,
412*4882a593Smuzhiyun 		 unsigned int);
413*4882a593Smuzhiyun int t4vf_eth_eq_free(struct adapter *, unsigned int);
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun int t4vf_update_port_info(struct port_info *pi);
416*4882a593Smuzhiyun int t4vf_handle_fw_rpl(struct adapter *, const __be64 *);
417*4882a593Smuzhiyun int t4vf_prep_adapter(struct adapter *);
418*4882a593Smuzhiyun int t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int port,
419*4882a593Smuzhiyun 			unsigned int *naddr, u8 *addr);
420*4882a593Smuzhiyun int t4vf_get_vf_vlan_acl(struct adapter *adapter);
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun #endif /* __T4VF_COMMON_H__ */
423