1/* bnx2x_vfpf.h: Qlogic Everest network driver.
2 *
3 * Copyright (c) 2011-2013 Broadcom Corporation
4 * Copyright (c) 2014 QLogic Corporation
5 * All rights reserved
6 *
7 * Unless you and Qlogic execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the “GPL”),
10 * available at http://www.gnu.org/licenses/gpl-2.0.html, with the following
11 * added to such license:
12 *
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions
17 * of the license of that module.  An independent module is a module which is
18 * not derived from this software.  The special exception does not apply to any
19 * modifications of the software.
20 *
21 * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
22 * Written by: Ariel Elior <ariel.elior@qlogic.com>
23 */
24#ifndef VF_PF_IF_H
25#define VF_PF_IF_H
26
27#ifdef CONFIG_BNX2X_SRIOV
28
29/* Common definitions for all HVs */
30struct vf_pf_resc_request {
31	u8  num_rxqs;
32	u8  num_txqs;
33	u8  num_sbs;
34	u8  num_mac_filters;
35	u8  num_vlan_filters;
36	u8  num_mc_filters; /* No limit  so superfluous */
37};
38
39struct hw_sb_info {
40	u8 hw_sb_id;	/* aka absolute igu id, used to ack the sb */
41	u8 sb_qid;	/* used to update DHC for sb */
42};
43
44/* HW VF-PF channel definitions
45 * A.K.A VF-PF mailbox
46 */
47#define TLV_BUFFER_SIZE			1024
48#define PF_VF_BULLETIN_SIZE		512
49
50#define VFPF_QUEUE_FLG_TPA		0x0001
51#define VFPF_QUEUE_FLG_TPA_IPV6		0x0002
52#define VFPF_QUEUE_FLG_TPA_GRO		0x0004
53#define VFPF_QUEUE_FLG_CACHE_ALIGN	0x0008
54#define VFPF_QUEUE_FLG_STATS		0x0010
55#define VFPF_QUEUE_FLG_OV		0x0020
56#define VFPF_QUEUE_FLG_VLAN		0x0040
57#define VFPF_QUEUE_FLG_COS		0x0080
58#define VFPF_QUEUE_FLG_HC		0x0100
59#define VFPF_QUEUE_FLG_DHC		0x0200
60#define VFPF_QUEUE_FLG_LEADING_RSS	0x0400
61
62#define VFPF_QUEUE_DROP_IP_CS_ERR	(1 << 0)
63#define VFPF_QUEUE_DROP_TCP_CS_ERR	(1 << 1)
64#define VFPF_QUEUE_DROP_TTL0		(1 << 2)
65#define VFPF_QUEUE_DROP_UDP_CS_ERR	(1 << 3)
66
67#define VFPF_RX_MASK_ACCEPT_NONE		0x00000000
68#define VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST	0x00000001
69#define VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST	0x00000002
70#define VFPF_RX_MASK_ACCEPT_ALL_UNICAST		0x00000004
71#define VFPF_RX_MASK_ACCEPT_ALL_MULTICAST	0x00000008
72#define VFPF_RX_MASK_ACCEPT_BROADCAST		0x00000010
73#define VFPF_RX_MASK_ACCEPT_ANY_VLAN		0x00000020
74
75#define BULLETIN_CONTENT_SIZE		(sizeof(struct pf_vf_bulletin_content))
76#define BULLETIN_CONTENT_LEGACY_SIZE	(32)
77#define BULLETIN_ATTEMPTS	5 /* crc failures before throwing towel */
78#define BULLETIN_CRC_SEED	0
79
80enum {
81	PFVF_STATUS_WAITING = 0,
82	PFVF_STATUS_SUCCESS,
83	PFVF_STATUS_FAILURE,
84	PFVF_STATUS_NOT_SUPPORTED,
85	PFVF_STATUS_NO_RESOURCE
86};
87
88/* vf pf channel tlvs */
89/* general tlv header (used for both vf->pf request and pf->vf response) */
90struct channel_tlv {
91	u16 type;
92	u16 length;
93};
94
95/* header of first vf->pf tlv carries the offset used to calculate response
96 * buffer address
97 */
98struct vfpf_first_tlv {
99	struct channel_tlv tl;
100	u32 resp_msg_offset;
101};
102
103/* header of pf->vf tlvs, carries the status of handling the request */
104struct pfvf_tlv {
105	struct channel_tlv tl;
106	u8 status;
107	u8 padding[3];
108};
109
110/* response tlv used for most tlvs */
111struct pfvf_general_resp_tlv {
112	struct pfvf_tlv hdr;
113};
114
115/* used to terminate and pad a tlv list */
116struct channel_list_end_tlv {
117	struct channel_tlv tl;
118	u8 padding[4];
119};
120
121/* Acquire */
122struct vfpf_acquire_tlv {
123	struct vfpf_first_tlv first_tlv;
124
125	struct vf_pf_vfdev_info {
126		/* the following fields are for debug purposes */
127		u8  vf_id;		/* ME register value */
128		u8  vf_os;		/* e.g. Linux, W2K8 */
129#define VF_OS_SUBVERSION_MASK	(0x1f)
130#define VF_OS_MASK		(0xe0)
131#define VF_OS_SHIFT		(5)
132#define VF_OS_UNDEFINED		(0 << VF_OS_SHIFT)
133#define VF_OS_WINDOWS		(1 << VF_OS_SHIFT)
134
135		u8 fp_hsi_ver;
136		u8 caps;
137#define VF_CAP_SUPPORT_EXT_BULLETIN	(1 << 0)
138#define VF_CAP_SUPPORT_VLAN_FILTER	(1 << 1)
139	} vfdev_info;
140
141	struct vf_pf_resc_request resc_request;
142
143	aligned_u64 bulletin_addr;
144};
145
146/* simple operation request on queue */
147struct vfpf_q_op_tlv {
148	struct vfpf_first_tlv	first_tlv;
149	u8 vf_qid;
150	u8 padding[3];
151};
152
153/* receive side scaling tlv */
154struct vfpf_rss_tlv {
155	struct vfpf_first_tlv	first_tlv;
156	u32			rss_flags;
157#define VFPF_RSS_MODE_DISABLED	(1 << 0)
158#define VFPF_RSS_MODE_REGULAR	(1 << 1)
159#define VFPF_RSS_SET_SRCH	(1 << 2)
160#define VFPF_RSS_IPV4		(1 << 3)
161#define VFPF_RSS_IPV4_TCP	(1 << 4)
162#define VFPF_RSS_IPV4_UDP	(1 << 5)
163#define VFPF_RSS_IPV6		(1 << 6)
164#define VFPF_RSS_IPV6_TCP	(1 << 7)
165#define VFPF_RSS_IPV6_UDP	(1 << 8)
166	u8			rss_result_mask;
167	u8			ind_table_size;
168	u8			rss_key_size;
169	u8			padding;
170	u8			ind_table[T_ETH_INDIRECTION_TABLE_SIZE];
171	u32			rss_key[T_ETH_RSS_KEY];	/* hash values */
172};
173
174/* acquire response tlv - carries the allocated resources */
175struct pfvf_acquire_resp_tlv {
176	struct pfvf_tlv hdr;
177	struct pf_vf_pfdev_info {
178		u32 chip_num;
179		u32 pf_cap;
180#define PFVF_CAP_RSS          0x00000001
181#define PFVF_CAP_DHC          0x00000002
182#define PFVF_CAP_TPA          0x00000004
183#define PFVF_CAP_TPA_UPDATE   0x00000008
184#define PFVF_CAP_VLAN_FILTER  0x00000010
185
186		char fw_ver[32];
187		u16 db_size;
188		u8  indices_per_sb;
189		u8  padding;
190	} pfdev_info;
191	struct pf_vf_resc {
192		/* in case of status NO_RESOURCE in message hdr, pf will fill
193		 * this struct with suggested amount of resources for next
194		 * acquire request
195		 */
196#define PFVF_MAX_QUEUES_PER_VF         16
197#define PFVF_MAX_SBS_PER_VF            16
198		struct hw_sb_info hw_sbs[PFVF_MAX_SBS_PER_VF];
199		u8	hw_qid[PFVF_MAX_QUEUES_PER_VF];
200		u8	num_rxqs;
201		u8	num_txqs;
202		u8	num_sbs;
203		u8	num_mac_filters;
204		u8	num_vlan_filters;
205		u8	num_mc_filters;
206		u8	permanent_mac_addr[ETH_ALEN];
207		u8	current_mac_addr[ETH_ALEN];
208		u8	padding[2];
209	} resc;
210};
211
212struct vfpf_port_phys_id_resp_tlv {
213	struct channel_tlv tl;
214	u8 id[ETH_ALEN];
215	u8 padding[2];
216};
217
218struct vfpf_fp_hsi_resp_tlv {
219	struct channel_tlv tl;
220	u8 is_supported;
221	u8 padding[3];
222};
223
224#define VFPF_INIT_FLG_STATS_COALESCE	(1 << 0) /* when set the VFs queues
225						  * stats will be coalesced on
226						  * the leading RSS queue
227						  */
228
229/* Init VF */
230struct vfpf_init_tlv {
231	struct vfpf_first_tlv first_tlv;
232	aligned_u64 sb_addr[PFVF_MAX_SBS_PER_VF]; /* vf_sb based */
233	aligned_u64 spq_addr;
234	aligned_u64 stats_addr;
235	u16 stats_stride;
236	u32 flags;
237	u32 padding[2];
238};
239
240/* Setup Queue */
241struct vfpf_setup_q_tlv {
242	struct vfpf_first_tlv first_tlv;
243
244	struct vf_pf_rxq_params {
245		/* physical addresses */
246		aligned_u64 rcq_addr;
247		aligned_u64 rcq_np_addr;
248		aligned_u64 rxq_addr;
249		aligned_u64 sge_addr;
250
251		/* sb + hc info */
252		u8  vf_sb;		/* index in hw_sbs[] */
253		u8  sb_index;		/* Index in the SB */
254		u16 hc_rate;		/* desired interrupts per sec. */
255					/* valid iff VFPF_QUEUE_FLG_HC */
256		/* rx buffer info */
257		u16 mtu;
258		u16 buf_sz;
259		u16 flags;		/* VFPF_QUEUE_FLG_X flags */
260		u16 stat_id;		/* valid iff VFPF_QUEUE_FLG_STATS */
261
262		/* valid iff VFPF_QUEUE_FLG_TPA */
263		u16 sge_buf_sz;
264		u16 tpa_agg_sz;
265		u8 max_sge_pkt;
266
267		u8 drop_flags;		/* VFPF_QUEUE_DROP_X, for Linux VMs
268					 * all the flags are turned off
269					 */
270
271		u8 cache_line_log;	/* VFPF_QUEUE_FLG_CACHE_ALIGN */
272		u8 padding;
273	} rxq;
274
275	struct vf_pf_txq_params {
276		/* physical addresses */
277		aligned_u64 txq_addr;
278
279		/* sb + hc info */
280		u8  vf_sb;		/* index in hw_sbs[] */
281		u8  sb_index;		/* Index in the SB */
282		u16 hc_rate;		/* desired interrupts per sec. */
283					/* valid iff VFPF_QUEUE_FLG_HC */
284		u32 flags;		/* VFPF_QUEUE_FLG_X flags */
285		u16 stat_id;		/* valid iff VFPF_QUEUE_FLG_STATS */
286		u8  traffic_type;	/* see in setup_context() */
287		u8  padding;
288	} txq;
289
290	u8 vf_qid;			/* index in hw_qid[] */
291	u8 param_valid;
292#define VFPF_RXQ_VALID		0x01
293#define VFPF_TXQ_VALID		0x02
294	u8 padding[2];
295};
296
297/* Set Queue Filters */
298struct vfpf_q_mac_vlan_filter {
299	u32 flags;
300#define VFPF_Q_FILTER_DEST_MAC_VALID	0x01
301#define VFPF_Q_FILTER_VLAN_TAG_VALID	0x02
302#define VFPF_Q_FILTER_SET		0x100	/* set/clear */
303	u8  mac[ETH_ALEN];
304	u16 vlan_tag;
305};
306
307/* configure queue filters */
308struct vfpf_set_q_filters_tlv {
309	struct vfpf_first_tlv first_tlv;
310
311	u32 flags;
312#define VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED	0x01
313#define VFPF_SET_Q_FILTERS_MULTICAST_CHANGED	0x02
314#define VFPF_SET_Q_FILTERS_RX_MASK_CHANGED	0x04
315
316	u8 vf_qid;			/* index in hw_qid[] */
317	u8 n_mac_vlan_filters;
318	u8 n_multicast;
319	u8 padding;
320
321#define PFVF_MAX_MAC_FILTERS                   16
322#define PFVF_MAX_VLAN_FILTERS                  16
323#define PFVF_MAX_FILTERS               (PFVF_MAX_MAC_FILTERS +\
324					 PFVF_MAX_VLAN_FILTERS)
325	struct vfpf_q_mac_vlan_filter filters[PFVF_MAX_FILTERS];
326
327#define PFVF_MAX_MULTICAST_PER_VF              32
328	u8  multicast[PFVF_MAX_MULTICAST_PER_VF][ETH_ALEN];
329
330	u32 rx_mask;	/* see mask constants at the top of the file */
331};
332
333struct vfpf_tpa_tlv {
334	struct vfpf_first_tlv	first_tlv;
335
336	struct vf_pf_tpa_client_info {
337		aligned_u64 sge_addr[PFVF_MAX_QUEUES_PER_VF];
338		u8 update_ipv4;
339		u8 update_ipv6;
340		u8 max_tpa_queues;
341		u8 max_sges_for_packet;
342		u8 complete_on_both_clients;
343		u8 dont_verify_thr;
344		u8 tpa_mode;
345		u16 sge_buff_size;
346		u16 max_agg_size;
347		u16 sge_pause_thr_low;
348		u16 sge_pause_thr_high;
349	} tpa_client_info;
350};
351
352/* close VF (disable VF) */
353struct vfpf_close_tlv {
354	struct vfpf_first_tlv   first_tlv;
355	u16			vf_id;  /* for debug */
356	u8 padding[2];
357};
358
359/* release the VF's acquired resources */
360struct vfpf_release_tlv {
361	struct vfpf_first_tlv	first_tlv;
362	u16			vf_id;
363	u8 padding[2];
364};
365
366struct tlv_buffer_size {
367	u8 tlv_buffer[TLV_BUFFER_SIZE];
368};
369
370union vfpf_tlvs {
371	struct vfpf_first_tlv		first_tlv;
372	struct vfpf_acquire_tlv		acquire;
373	struct vfpf_init_tlv		init;
374	struct vfpf_close_tlv		close;
375	struct vfpf_q_op_tlv		q_op;
376	struct vfpf_setup_q_tlv		setup_q;
377	struct vfpf_set_q_filters_tlv	set_q_filters;
378	struct vfpf_release_tlv		release;
379	struct vfpf_rss_tlv		update_rss;
380	struct vfpf_tpa_tlv		update_tpa;
381	struct channel_list_end_tlv	list_end;
382	struct tlv_buffer_size		tlv_buf_size;
383};
384
385union pfvf_tlvs {
386	struct pfvf_general_resp_tlv	general_resp;
387	struct pfvf_acquire_resp_tlv	acquire_resp;
388	struct channel_list_end_tlv	list_end;
389	struct tlv_buffer_size		tlv_buf_size;
390};
391
392/* This is a structure which is allocated in the VF, which the PF may update
393 * when it deems it necessary to do so. The bulletin board is sampled
394 * periodically by the VF. A copy per VF is maintained in the PF (to prevent
395 * loss of data upon multiple updates (or the need for read modify write)).
396 */
397struct pf_vf_bulletin_size {
398	u8 size[PF_VF_BULLETIN_SIZE];
399};
400
401struct pf_vf_bulletin_content {
402	u32 crc;			/* crc of structure to ensure is not in
403					 * mid-update
404					 */
405	u16 version;
406	u16 length;
407
408	aligned_u64 valid_bitmap;	/* bitmap indicating which fields
409					 * hold valid values
410					 */
411
412#define MAC_ADDR_VALID		0	/* alert the vf that a new mac address
413					 * is available for it
414					 */
415#define VLAN_VALID		1	/* when set, the vf should not access
416					 * the vfpf channel
417					 */
418#define CHANNEL_DOWN		2	/* vfpf channel is disabled. VFs are not
419					 * to attempt to send messages on the
420					 * channel after this bit is set
421					 */
422#define LINK_VALID		3	/* alert the VF thet a new link status
423					 * update is available for it
424					 */
425	u8 mac[ETH_ALEN];
426	u8 mac_padding[2];
427
428	u16 vlan;
429	u8 vlan_padding[6];
430
431	u16 link_speed;			 /* Effective line speed */
432	u8 link_speed_padding[6];
433	u32 link_flags;			 /* VFPF_LINK_REPORT_XXX flags */
434#define VFPF_LINK_REPORT_LINK_DOWN	 (1 << 0)
435#define VFPF_LINK_REPORT_FULL_DUPLEX	 (1 << 1)
436#define VFPF_LINK_REPORT_RX_FC_ON	 (1 << 2)
437#define VFPF_LINK_REPORT_TX_FC_ON	 (1 << 3)
438	u8 link_flags_padding[4];
439};
440
441union pf_vf_bulletin {
442	struct pf_vf_bulletin_content content;
443	struct pf_vf_bulletin_size size;
444};
445
446#define MAX_TLVS_IN_LIST 50
447
448enum channel_tlvs {
449	CHANNEL_TLV_NONE,
450	CHANNEL_TLV_ACQUIRE,
451	CHANNEL_TLV_INIT,
452	CHANNEL_TLV_SETUP_Q,
453	CHANNEL_TLV_SET_Q_FILTERS,
454	CHANNEL_TLV_ACTIVATE_Q,
455	CHANNEL_TLV_DEACTIVATE_Q,
456	CHANNEL_TLV_TEARDOWN_Q,
457	CHANNEL_TLV_CLOSE,
458	CHANNEL_TLV_RELEASE,
459	CHANNEL_TLV_UPDATE_RSS_DEPRECATED,
460	CHANNEL_TLV_PF_RELEASE_VF,
461	CHANNEL_TLV_LIST_END,
462	CHANNEL_TLV_FLR,
463	CHANNEL_TLV_PF_SET_MAC,
464	CHANNEL_TLV_PF_SET_VLAN,
465	CHANNEL_TLV_UPDATE_RSS,
466	CHANNEL_TLV_PHYS_PORT_ID,
467	CHANNEL_TLV_UPDATE_TPA,
468	CHANNEL_TLV_FP_HSI_SUPPORT,
469	CHANNEL_TLV_MAX
470};
471
472#endif /* CONFIG_BNX2X_SRIOV */
473#endif /* VF_PF_IF_H */
474