xref: /freebsd/sys/dev/ixl/ixl.h (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2015, Intel Corporation
4   All rights reserved.
5 
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are met:
8 
9    1. Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11 
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15 
16    3. Neither the name of the Intel Corporation nor the names of its
17       contributors may be used to endorse or promote products derived from
18       this software without specific prior written permission.
19 
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31 
32 ******************************************************************************/
33 /*$FreeBSD$*/
34 
35 
36 #ifndef _IXL_H_
37 #define _IXL_H_
38 
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/buf_ring.h>
43 #include <sys/mbuf.h>
44 #include <sys/protosw.h>
45 #include <sys/socket.h>
46 #include <sys/malloc.h>
47 #include <sys/kernel.h>
48 #include <sys/module.h>
49 #include <sys/sockio.h>
50 #include <sys/eventhandler.h>
51 
52 #include <net/if.h>
53 #include <net/if_var.h>
54 #include <net/if_arp.h>
55 #include <net/bpf.h>
56 #include <net/ethernet.h>
57 #include <net/if_dl.h>
58 #include <net/if_media.h>
59 
60 #include <net/bpf.h>
61 #include <net/if_types.h>
62 #include <net/if_vlan_var.h>
63 
64 #include <netinet/in_systm.h>
65 #include <netinet/in.h>
66 #include <netinet/if_ether.h>
67 #include <netinet/ip.h>
68 #include <netinet/ip6.h>
69 #include <netinet/tcp.h>
70 #include <netinet/tcp_lro.h>
71 #include <netinet/udp.h>
72 #include <netinet/sctp.h>
73 
74 #include <machine/in_cksum.h>
75 
76 #include <sys/bus.h>
77 #include <machine/bus.h>
78 #include <sys/rman.h>
79 #include <machine/resource.h>
80 #include <vm/vm.h>
81 #include <vm/pmap.h>
82 #include <machine/clock.h>
83 #include <dev/pci/pcivar.h>
84 #include <dev/pci/pcireg.h>
85 #include <sys/proc.h>
86 #include <sys/sysctl.h>
87 #include <sys/endian.h>
88 #include <sys/taskqueue.h>
89 #include <sys/pcpu.h>
90 #include <sys/smp.h>
91 #include <machine/smp.h>
92 
93 #ifdef PCI_IOV
94 #include <sys/nv.h>
95 #include <sys/iov_schema.h>
96 #include <dev/pci/pci_iov.h>
97 #endif
98 
99 #include "i40e_type.h"
100 #include "i40e_prototype.h"
101 
102 #if defined(IXL_DEBUG) || defined(IXL_DEBUG_SYSCTL)
103 #include <sys/sbuf.h>
104 
105 #define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x"
106 #define MAC_FORMAT_ARGS(mac_addr) \
107 	(mac_addr)[0], (mac_addr)[1], (mac_addr)[2], (mac_addr)[3], \
108 	(mac_addr)[4], (mac_addr)[5]
109 #define ON_OFF_STR(is_set) ((is_set) ? "On" : "Off")
110 #endif /* IXL_DEBUG || IXL_DEBUG_SYSCTL */
111 
112 #ifdef IXL_DEBUG
113 /* Enable debug sysctls */
114 #ifndef IXL_DEBUG_SYSCTL
115 #define IXL_DEBUG_SYSCTL 1
116 #endif
117 
118 #define _DBG_PRINTF(S, ...)		printf("%s: " S "\n", __func__, ##__VA_ARGS__)
119 #define _DEV_DBG_PRINTF(dev, S, ...)	device_printf(dev, "%s: " S "\n", __func__, ##__VA_ARGS__)
120 #define _IF_DBG_PRINTF(ifp, S, ...)	if_printf(ifp, "%s: " S "\n", __func__, ##__VA_ARGS__)
121 
122 /* Defines for printing generic debug information */
123 #define DPRINTF(...)			_DBG_PRINTF(__VA_ARGS__)
124 #define DDPRINTF(...)			_DEV_DBG_PRINTF(__VA_ARGS__)
125 #define IDPRINTF(...)			_IF_DBG_PRINTF(__VA_ARGS__)
126 
127 /* Defines for printing specific debug information */
128 #define DEBUG_INIT  1
129 #define DEBUG_IOCTL 1
130 #define DEBUG_HW    1
131 
132 #define INIT_DEBUGOUT(...)		if (DEBUG_INIT) _DBG_PRINTF(__VA_ARGS__)
133 #define INIT_DBG_DEV(...)		if (DEBUG_INIT) _DEV_DBG_PRINTF(__VA_ARGS__)
134 #define INIT_DBG_IF(...)		if (DEBUG_INIT) _IF_DBG_PRINTF(__VA_ARGS__)
135 
136 #define IOCTL_DEBUGOUT(...)		if (DEBUG_IOCTL) _DBG_PRINTF(__VA_ARGS__)
137 #define IOCTL_DBG_IF2(ifp, S, ...)	if (DEBUG_IOCTL) \
138 					    if_printf(ifp, S "\n", ##__VA_ARGS__)
139 #define IOCTL_DBG_IF(...)		if (DEBUG_IOCTL) _IF_DBG_PRINTF(__VA_ARGS__)
140 
141 #define HW_DEBUGOUT(...)		if (DEBUG_HW) _DBG_PRINTF(__VA_ARGS__)
142 
143 #else /* no IXL_DEBUG */
144 #define DEBUG_INIT  0
145 #define DEBUG_IOCTL 0
146 #define DEBUG_HW    0
147 
148 #define DPRINTF(...)
149 #define DDPRINTF(...)
150 #define IDPRINTF(...)
151 
152 #define INIT_DEBUGOUT(...)
153 #define INIT_DBG_DEV(...)
154 #define INIT_DBG_IF(...)
155 #define IOCTL_DEBUGOUT(...)
156 #define IOCTL_DBG_IF2(...)
157 #define IOCTL_DBG_IF(...)
158 #define HW_DEBUGOUT(...)
159 #endif /* IXL_DEBUG */
160 
161 /* Tunables */
162 
163 /*
164  * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the
165  * number of tx/rx descriptors allocated by the driver. Increasing this
166  * value allows the driver to queue more operations. Each descriptor is 16
167  * or 32 bytes (configurable in FVL)
168  */
169 #define DEFAULT_RING	1024
170 #define PERFORM_RING	2048
171 #define MAX_RING	4096
172 #define MIN_RING	32
173 
174 /*
175 ** Default number of entries in Tx queue buf_ring.
176 */
177 #define SMALL_TXBRSZ 4096
178 /* This may require mbuf cluster tuning */
179 #define DEFAULT_TXBRSZ (SMALL_TXBRSZ * SMALL_TXBRSZ)
180 
181 /* Alignment for rings */
182 #define DBA_ALIGN	128
183 
184 /*
185  * This parameter controls the maximum no of times the driver will loop in
186  * the isr. Minimum Value = 1
187  */
188 #define MAX_LOOP	10
189 
190 /*
191  * This is the max watchdog interval, ie. the time that can
192  * pass between any two TX clean operations, such only happening
193  * when the TX hardware is functioning.
194  */
195 #define IXL_WATCHDOG                   (10 * hz)
196 
197 /*
198  * This parameters control when the driver calls the routine to reclaim
199  * transmit descriptors.
200  */
201 #define IXL_TX_CLEANUP_THRESHOLD	(que->num_desc / 8)
202 #define IXL_TX_OP_THRESHOLD		(que->num_desc / 32)
203 
204 /* Flow control constants */
205 #define IXL_FC_PAUSE		0xFFFF
206 #define IXL_FC_HI		0x20000
207 #define IXL_FC_LO		0x10000
208 
209 #define MAX_MULTICAST_ADDR	128
210 
211 #define IXL_BAR			3
212 #define IXL_ADM_LIMIT		2
213 #define IXL_TSO_SIZE		65535
214 #define IXL_TX_BUF_SZ		((u32) 1514)
215 #define IXL_AQ_BUF_SZ		((u32) 4096)
216 #define IXL_RX_HDR		128
217 /* Controls the length of the Admin Queue */
218 #define IXL_AQ_LEN		256
219 #define IXL_AQ_LEN_MAX		1024
220 #define IXL_AQ_BUFSZ		4096
221 #define IXL_RX_LIMIT		512
222 #define IXL_RX_ITR		0
223 #define IXL_TX_ITR		1
224 #define IXL_ITR_NONE		3
225 #define IXL_QUEUE_EOL		0x7FF
226 #define IXL_MAX_FRAME		0x2600
227 #define IXL_MAX_TX_SEGS		8
228 #define IXL_MAX_TSO_SEGS	66
229 #define IXL_SPARSE_CHAIN	6
230 #define IXL_QUEUE_HUNG		0x80000000
231 #define IXL_KEYSZ		10
232 
233 #define IXL_VF_MAX_BUFFER	0x3F80
234 #define IXL_VF_MAX_HDR_BUFFER	0x840
235 #define IXL_VF_MAX_FRAME	0x3FFF
236 
237 /* ERJ: hardware can support ~1.5k filters between all functions */
238 #define IXL_MAX_FILTERS	256
239 #define IXL_MAX_TX_BUSY	10
240 
241 #define IXL_NVM_VERSION_LO_SHIFT	0
242 #define IXL_NVM_VERSION_LO_MASK		(0xff << IXL_NVM_VERSION_LO_SHIFT)
243 #define IXL_NVM_VERSION_HI_SHIFT	12
244 #define IXL_NVM_VERSION_HI_MASK		(0xf << IXL_NVM_VERSION_HI_SHIFT)
245 
246 
247 /*
248  * Interrupt Moderation parameters
249  */
250 #define IXL_MAX_ITR		0x07FF
251 #define IXL_ITR_100K		0x0005
252 #define IXL_ITR_20K		0x0019
253 #define IXL_ITR_8K		0x003E
254 #define IXL_ITR_4K		0x007A
255 #define IXL_ITR_DYNAMIC		0x8000
256 #define IXL_LOW_LATENCY		0
257 #define IXL_AVE_LATENCY		1
258 #define IXL_BULK_LATENCY	2
259 
260 /* MacVlan Flags */
261 #define IXL_FILTER_USED		(u16)(1 << 0)
262 #define IXL_FILTER_VLAN		(u16)(1 << 1)
263 #define IXL_FILTER_ADD		(u16)(1 << 2)
264 #define IXL_FILTER_DEL		(u16)(1 << 3)
265 #define IXL_FILTER_MC		(u16)(1 << 4)
266 
267 /* used in the vlan field of the filter when not a vlan */
268 #define IXL_VLAN_ANY		-1
269 
270 #define CSUM_OFFLOAD_IPV4	(CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
271 #define CSUM_OFFLOAD_IPV6	(CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6)
272 #define CSUM_OFFLOAD		(CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO)
273 
274 /* Misc flags for ixl_vsi.flags */
275 #define IXL_FLAGS_KEEP_TSO4	(1 << 0)
276 #define IXL_FLAGS_KEEP_TSO6	(1 << 1)
277 
278 #define IXL_VF_RESET_TIMEOUT	100
279 
280 #define IXL_VSI_DATA_PORT	0x01
281 
282 #define IXLV_MAX_QUEUES		16
283 #define IXL_MAX_VSI_QUEUES	(2 * (I40E_VSILAN_QTABLE_MAX_INDEX + 1))
284 
285 #define IXL_RX_CTX_BASE_UNITS	128
286 #define IXL_TX_CTX_BASE_UNITS	128
287 
288 #define IXL_VPINT_LNKLSTN_REG(hw, vector, vf_num) \
289 	I40E_VPINT_LNKLSTN(((vector) - 1) + \
290 	    (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num)))
291 
292 #define IXL_VFINT_DYN_CTLN_REG(hw, vector, vf_num) \
293 	I40E_VFINT_DYN_CTLN(((vector) - 1) + \
294 	    (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num)))
295 
296 #define IXL_PF_PCI_CIAA_VF_DEVICE_STATUS	0xAA
297 
298 #define IXL_PF_PCI_CIAD_VF_TRANS_PENDING_MASK	0x20
299 
300 #define IXL_GLGEN_VFLRSTAT_INDEX(glb_vf)	((glb_vf) / 32)
301 #define IXL_GLGEN_VFLRSTAT_MASK(glb_vf)	(1 << ((glb_vf) % 32))
302 
303 #define IXL_MAX_ITR_IDX		3
304 
305 #define IXL_END_OF_INTR_LNKLST	0x7FF
306 
307 #define IXL_TX_LOCK(_sc)                mtx_lock(&(_sc)->mtx)
308 #define IXL_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->mtx)
309 #define IXL_TX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->mtx)
310 #define IXL_TX_TRYLOCK(_sc)             mtx_trylock(&(_sc)->mtx)
311 #define IXL_TX_LOCK_ASSERT(_sc)         mtx_assert(&(_sc)->mtx, MA_OWNED)
312 
313 #define IXL_RX_LOCK(_sc)                mtx_lock(&(_sc)->mtx)
314 #define IXL_RX_UNLOCK(_sc)              mtx_unlock(&(_sc)->mtx)
315 #define IXL_RX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->mtx)
316 
317 #if __FreeBSD_version >= 1100036
318 #define IXL_SET_IPACKETS(vsi, count)	(vsi)->ipackets = (count)
319 #define IXL_SET_IERRORS(vsi, count)	(vsi)->ierrors = (count)
320 #define IXL_SET_OPACKETS(vsi, count)	(vsi)->opackets = (count)
321 #define IXL_SET_OERRORS(vsi, count)	(vsi)->oerrors = (count)
322 #define IXL_SET_COLLISIONS(vsi, count)	/* Do nothing; collisions is always 0. */
323 #define IXL_SET_IBYTES(vsi, count)	(vsi)->ibytes = (count)
324 #define IXL_SET_OBYTES(vsi, count)	(vsi)->obytes = (count)
325 #define IXL_SET_IMCASTS(vsi, count)	(vsi)->imcasts = (count)
326 #define IXL_SET_OMCASTS(vsi, count)	(vsi)->omcasts = (count)
327 #define IXL_SET_IQDROPS(vsi, count)	(vsi)->iqdrops = (count)
328 #define IXL_SET_OQDROPS(vsi, count)	(vsi)->oqdrops = (count)
329 #define IXL_SET_NOPROTO(vsi, count)	(vsi)->noproto = (count)
330 #else
331 #define IXL_SET_IPACKETS(vsi, count)	(vsi)->ifp->if_ipackets = (count)
332 #define IXL_SET_IERRORS(vsi, count)	(vsi)->ifp->if_ierrors = (count)
333 #define IXL_SET_OPACKETS(vsi, count)	(vsi)->ifp->if_opackets = (count)
334 #define IXL_SET_OERRORS(vsi, count)	(vsi)->ifp->if_oerrors = (count)
335 #define IXL_SET_COLLISIONS(vsi, count)	(vsi)->ifp->if_collisions = (count)
336 #define IXL_SET_IBYTES(vsi, count)	(vsi)->ifp->if_ibytes = (count)
337 #define IXL_SET_OBYTES(vsi, count)	(vsi)->ifp->if_obytes = (count)
338 #define IXL_SET_IMCASTS(vsi, count)	(vsi)->ifp->if_imcasts = (count)
339 #define IXL_SET_OMCASTS(vsi, count)	(vsi)->ifp->if_omcasts = (count)
340 #define IXL_SET_IQDROPS(vsi, count)	(vsi)->ifp->if_iqdrops = (count)
341 #define IXL_SET_OQDROPS(vsi, odrops)	(vsi)->ifp->if_snd.ifq_drops = (odrops)
342 #define IXL_SET_NOPROTO(vsi, count)	(vsi)->noproto = (count)
343 #endif
344 
345 /*
346  *****************************************************************************
347  * vendor_info_array
348  *
349  * This array contains the list of Subvendor/Subdevice IDs on which the driver
350  * should load.
351  *
352  *****************************************************************************
353  */
354 typedef struct _ixl_vendor_info_t {
355 	unsigned int    vendor_id;
356 	unsigned int    device_id;
357 	unsigned int    subvendor_id;
358 	unsigned int    subdevice_id;
359 	unsigned int    index;
360 } ixl_vendor_info_t;
361 
362 
363 struct ixl_tx_buf {
364 	u32		eop_index;
365 	struct mbuf	*m_head;
366 	bus_dmamap_t	map;
367 	bus_dma_tag_t	tag;
368 };
369 
370 struct ixl_rx_buf {
371 	struct mbuf	*m_head;
372 	struct mbuf	*m_pack;
373 	struct mbuf	*fmp;
374 	bus_dmamap_t	hmap;
375 	bus_dmamap_t	pmap;
376 };
377 
378 /*
379 ** This struct has multiple uses, multicast
380 ** addresses, vlans, and mac filters all use it.
381 */
382 struct ixl_mac_filter {
383 	SLIST_ENTRY(ixl_mac_filter) next;
384 	u8	macaddr[ETHER_ADDR_LEN];
385 	s16	vlan;
386 	u16	flags;
387 };
388 
389 
390 /*
391  * The Transmit ring control struct
392  */
393 struct tx_ring {
394         struct ixl_queue	*que;
395 	struct mtx		mtx;
396 	u32			tail;
397 	struct i40e_tx_desc	*base;
398 	struct i40e_dma_mem	dma;
399 	u16			next_avail;
400 	u16			next_to_clean;
401 	u16			atr_rate;
402 	u16			atr_count;
403 	u16			itr;
404 	u16			latency;
405 	struct ixl_tx_buf	*buffers;
406 	volatile u16		avail;
407 	u32			cmd;
408 	bus_dma_tag_t		tx_tag;
409 	bus_dma_tag_t		tso_tag;
410 	char			mtx_name[16];
411 	struct buf_ring		*br;
412 
413 	/* Used for Dynamic ITR calculation */
414 	u32			packets;
415 	u32 			bytes;
416 
417 	/* Soft Stats */
418 	u64			tx_bytes;
419 	u64			no_desc;
420 	u64			total_packets;
421 };
422 
423 
424 /*
425  * The Receive ring control struct
426  */
427 struct rx_ring {
428         struct ixl_queue	*que;
429 	struct mtx		mtx;
430 	union i40e_rx_desc	*base;
431 	struct i40e_dma_mem	dma;
432 	struct lro_ctrl		lro;
433 	bool			lro_enabled;
434 	bool			hdr_split;
435 	bool			discard;
436         u16			next_refresh;
437         u16 			next_check;
438 	u16			itr;
439 	u16			latency;
440 	char			mtx_name[16];
441 	struct ixl_rx_buf	*buffers;
442 	u32			mbuf_sz;
443 	u32			tail;
444 	bus_dma_tag_t		htag;
445 	bus_dma_tag_t		ptag;
446 
447 	/* Used for Dynamic ITR calculation */
448 	u32			packets;
449 	u32 			bytes;
450 
451 	/* Soft stats */
452 	u64			split;
453 	u64			rx_packets;
454 	u64 			rx_bytes;
455 	u64 			discarded;
456 	u64 			not_done;
457 };
458 
459 /*
460 ** Driver queue struct: this is the interrupt container
461 **  for the associated tx and rx ring pair.
462 */
463 struct ixl_queue {
464 	struct ixl_vsi		*vsi;
465 	u32			me;
466 	u32			msix;           /* This queue's MSIX vector */
467 	u32			eims;           /* This queue's EIMS bit */
468 	struct resource		*res;
469 	void			*tag;
470 	int			num_desc;	/* both tx and rx */
471 	int			busy;
472 	struct tx_ring		txr;
473 	struct rx_ring		rxr;
474 	struct task		task;
475 	struct task		tx_task;
476 	struct taskqueue	*tq;
477 
478 	/* Queue stats */
479 	u64			irqs;
480 	u64			tso;
481 	u64			mbuf_defrag_failed;
482 	u64			mbuf_hdr_failed;
483 	u64			mbuf_pkt_failed;
484 	u64			tx_map_avail;
485 	u64			tx_dma_setup;
486 	u64			dropped_pkts;
487 };
488 
489 /*
490 ** Virtual Station interface:
491 **	there would be one of these per traffic class/type
492 **	for now just one, and its embedded in the pf
493 */
494 SLIST_HEAD(ixl_ftl_head, ixl_mac_filter);
495 struct ixl_vsi {
496 	void 			*back;
497 	struct ifnet		*ifp;
498 	struct device		*dev;
499 	struct i40e_hw		*hw;
500 	struct ifmedia		media;
501 	u64			que_mask;
502 	int			id;
503 	u16			vsi_num;
504 	u16			msix_base;	/* station base MSIX vector */
505 	u16			first_queue;
506 	u16			num_queues;
507 	u16			rx_itr_setting;
508 	u16			tx_itr_setting;
509 	struct ixl_queue	*queues;	/* head of queues */
510 	bool			link_active;
511 	u16			seid;
512 	u16			uplink_seid;
513 	u16			downlink_seid;
514 	u16			max_frame_size;
515 
516 	/* MAC/VLAN Filter list */
517 	struct ixl_ftl_head ftl;
518 	u16			num_macs;
519 
520 	struct i40e_aqc_vsi_properties_data info;
521 
522 	eventhandler_tag 	vlan_attach;
523 	eventhandler_tag 	vlan_detach;
524 	u16			num_vlans;
525 
526 	/* Per-VSI stats from hardware */
527 	struct i40e_eth_stats	eth_stats;
528 	struct i40e_eth_stats	eth_stats_offsets;
529 	bool 			stat_offsets_loaded;
530 	/* VSI stat counters */
531 	u64			ipackets;
532 	u64			ierrors;
533 	u64			opackets;
534 	u64			oerrors;
535 	u64			ibytes;
536 	u64			obytes;
537 	u64			imcasts;
538 	u64			omcasts;
539 	u64			iqdrops;
540 	u64			oqdrops;
541 	u64			noproto;
542 
543 	/* Driver statistics */
544 	u64			hw_filters_del;
545 	u64			hw_filters_add;
546 
547 	/* Misc. */
548 	u64 			active_queues;
549 	u64 			flags;
550 	struct sysctl_oid	*vsi_node;
551 };
552 
553 /*
554 ** Find the number of unrefreshed RX descriptors
555 */
556 static inline u16
557 ixl_rx_unrefreshed(struct ixl_queue *que)
558 {
559         struct rx_ring	*rxr = &que->rxr;
560 
561 	if (rxr->next_check > rxr->next_refresh)
562 		return (rxr->next_check - rxr->next_refresh - 1);
563 	else
564 		return ((que->num_desc + rxr->next_check) -
565 		    rxr->next_refresh - 1);
566 }
567 
568 /*
569 ** Find the next available unused filter
570 */
571 static inline struct ixl_mac_filter *
572 ixl_get_filter(struct ixl_vsi *vsi)
573 {
574 	struct ixl_mac_filter  *f;
575 
576 	/* create a new empty filter */
577 	f = malloc(sizeof(struct ixl_mac_filter),
578 	    M_DEVBUF, M_NOWAIT | M_ZERO);
579 	if (f)
580 		SLIST_INSERT_HEAD(&vsi->ftl, f, next);
581 
582 	return (f);
583 }
584 
585 /*
586 ** Compare two ethernet addresses
587 */
588 static inline bool
589 cmp_etheraddr(const u8 *ea1, const u8 *ea2)
590 {
591 	bool cmp = FALSE;
592 
593 	if ((ea1[0] == ea2[0]) && (ea1[1] == ea2[1]) &&
594 	    (ea1[2] == ea2[2]) && (ea1[3] == ea2[3]) &&
595 	    (ea1[4] == ea2[4]) && (ea1[5] == ea2[5]))
596 		cmp = TRUE;
597 
598 	return (cmp);
599 }
600 
601 /*
602  * Info for stats sysctls
603  */
604 struct ixl_sysctl_info {
605 	u64	*stat;
606 	char	*name;
607 	char	*description;
608 };
609 
610 extern int ixl_atr_rate;
611 
612 /*
613 ** ixl_fw_version_str - format the FW and NVM version strings
614 */
615 static inline char *
616 ixl_fw_version_str(struct i40e_hw *hw)
617 {
618 	static char buf[32];
619 
620 	snprintf(buf, sizeof(buf),
621 	    "f%d.%d a%d.%d n%02x.%02x e%08x",
622 	    hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
623 	    hw->aq.api_maj_ver, hw->aq.api_min_ver,
624 	    (hw->nvm.version & IXL_NVM_VERSION_HI_MASK) >>
625 	    IXL_NVM_VERSION_HI_SHIFT,
626 	    (hw->nvm.version & IXL_NVM_VERSION_LO_MASK) >>
627 	    IXL_NVM_VERSION_LO_SHIFT,
628 	    hw->nvm.eetrack);
629 	return buf;
630 }
631 
632 /*********************************************************************
633  *  TXRX Function prototypes
634  *********************************************************************/
635 int	ixl_allocate_tx_data(struct ixl_queue *);
636 int	ixl_allocate_rx_data(struct ixl_queue *);
637 void	ixl_init_tx_ring(struct ixl_queue *);
638 int	ixl_init_rx_ring(struct ixl_queue *);
639 bool	ixl_rxeof(struct ixl_queue *, int);
640 bool	ixl_txeof(struct ixl_queue *);
641 int	ixl_mq_start(struct ifnet *, struct mbuf *);
642 int	ixl_mq_start_locked(struct ifnet *, struct tx_ring *);
643 void	ixl_deferred_mq_start(void *, int);
644 void	ixl_qflush(struct ifnet *);
645 void	ixl_free_vsi(struct ixl_vsi *);
646 void	ixl_free_que_tx(struct ixl_queue *);
647 void	ixl_free_que_rx(struct ixl_queue *);
648 #ifdef IXL_FDIR
649 void	ixl_atr(struct ixl_queue *, struct tcphdr *, int);
650 #endif
651 #if __FreeBSD_version >= 1100000
652 uint64_t ixl_get_counter(if_t ifp, ift_counter cnt);
653 #endif
654 
655 #endif /* _IXL_H_ */
656