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