xref: /netbsd-src/sys/dev/pci/ixgbe/ixgbe.h (revision 924795e69c8bb3f17afd8fcbb799710cc1719dc4)
1 /* $NetBSD: ixgbe.h,v 1.86 2022/05/30 05:08:17 msaitoh Exp $ */
2 
3 /******************************************************************************
4   SPDX-License-Identifier: BSD-3-Clause
5 
6   Copyright (c) 2001-2017, Intel Corporation
7   All rights reserved.
8 
9   Redistribution and use in source and binary forms, with or without
10   modification, are permitted provided that the following conditions are met:
11 
12    1. Redistributions of source code must retain the above copyright notice,
13       this list of conditions and the following disclaimer.
14 
15    2. Redistributions in binary form must reproduce the above copyright
16       notice, this list of conditions and the following disclaimer in the
17       documentation and/or other materials provided with the distribution.
18 
19    3. Neither the name of the Intel Corporation nor the names of its
20       contributors may be used to endorse or promote products derived from
21       this software without specific prior written permission.
22 
23   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33   POSSIBILITY OF SUCH DAMAGE.
34 
35 ******************************************************************************/
36 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe.h 327031 2017-12-20 18:15:06Z erj $*/
37 
38 /*
39  * Copyright (c) 2011 The NetBSD Foundation, Inc.
40  * All rights reserved.
41  *
42  * This code is derived from software contributed to The NetBSD Foundation
43  * by Coyote Point Systems, Inc.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions
47  * are met:
48  * 1. Redistributions of source code must retain the above copyright
49  *    notice, this list of conditions and the following disclaimer.
50  * 2. Redistributions in binary form must reproduce the above copyright
51  *    notice, this list of conditions and the following disclaimer in the
52  *    documentation and/or other materials provided with the distribution.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
55  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
58  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64  * POSSIBILITY OF SUCH DAMAGE.
65  */
66 
67 
68 #ifndef _IXGBE_H_
69 #define _IXGBE_H_
70 
71 
72 #include <sys/param.h>
73 #include <sys/reboot.h>
74 #include <sys/systm.h>
75 #include <sys/pcq.h>
76 #include <sys/mbuf.h>
77 #include <sys/protosw.h>
78 #include <sys/socket.h>
79 #include <sys/malloc.h>
80 #include <sys/kernel.h>
81 #include <sys/module.h>
82 #include <sys/sockio.h>
83 #include <sys/percpu.h>
84 
85 #include <net/if.h>
86 #include <net/if_arp.h>
87 #include <net/bpf.h>
88 #include <net/if_ether.h>
89 #include <net/if_dl.h>
90 #include <net/if_media.h>
91 
92 #include <net/if_types.h>
93 #include <net/if_vlanvar.h>
94 
95 #include <netinet/in_systm.h>
96 #include <netinet/in.h>
97 #include <netinet/ip.h>
98 #include <netinet/ip6.h>
99 #include <netinet/tcp.h>
100 #include <netinet/udp.h>
101 
102 #include <sys/bus.h>
103 #include <dev/pci/pcivar.h>
104 #include <dev/pci/pcireg.h>
105 #include <sys/proc.h>
106 #include <sys/sysctl.h>
107 #include <sys/endian.h>
108 #include <sys/workqueue.h>
109 #include <sys/cpu.h>
110 #include <sys/interrupt.h>
111 #include <sys/bitops.h>
112 
113 #include "ixgbe_netbsd.h"
114 #include "ixgbe_api.h"
115 #include "ixgbe_common.h"
116 #include "ixgbe_vf.h"
117 #include "ixgbe_features.h"
118 
119 /* Tunables */
120 
121 /*
122  * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
123  * number of transmit descriptors allocated by the driver. Increasing this
124  * value allows the driver to queue more transmits. Each descriptor is 16
125  * bytes. Performance tests have show the 2K value to be optimal for top
126  * performance.
127  */
128 #define DEFAULT_TXD	1024
129 #define PERFORM_TXD	2048
130 #define MAX_TXD		4096
131 #define MIN_TXD		64
132 
133 /*
134  * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
135  * number of receive descriptors allocated for each RX queue. Increasing this
136  * value allows the driver to buffer more incoming packets. Each descriptor
137  * is 16 bytes.  A receive buffer is also allocated for each descriptor.
138  *
139  * Note: with 8 rings and a dual port card, it is possible to bump up
140  *	against the system mbuf pool limit, you can tune nmbclusters
141  *	to adjust for this.
142  */
143 #define DEFAULT_RXD	1024
144 #define PERFORM_RXD	2048
145 #define MAX_RXD		4096
146 #define MIN_RXD		64
147 
148 /* Alignment for rings */
149 #define DBA_ALIGN	128
150 
151 /*
152  * This is the max watchdog interval, ie. the time that can
153  * pass between any two TX clean operations, such only happening
154  * when the TX hardware is functioning.
155  */
156 #define IXGBE_WATCHDOG  (10 * hz)
157 
158 /*
159  * This parameters control when the driver calls the routine to reclaim
160  * transmit descriptors.
161  */
162 #define IXGBE_TX_CLEANUP_THRESHOLD(_a)  ((_a)->num_tx_desc / 8)
163 #define IXGBE_TX_OP_THRESHOLD(_a)       ((_a)->num_tx_desc / 32)
164 
165 /* These defines are used in MTU calculations */
166 #define IXGBE_MAX_FRAME_SIZE  9728
167 #define IXGBE_MTU_HDR         (ETHER_HDR_LEN + ETHER_CRC_LEN)
168 #define IXGBE_MTU_HDR_VLAN    (ETHER_HDR_LEN + ETHER_CRC_LEN + \
169                                ETHER_VLAN_ENCAP_LEN)
170 #define IXGBE_MAX_MTU         (IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR)
171 #define IXGBE_MAX_MTU_VLAN    (IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR_VLAN)
172 
173 /* Flow control constants */
174 #define IXGBE_FC_PAUSE        0xFFFF
175 
176 /*
177  * Used for optimizing small rx mbufs.  Effort is made to keep the copy
178  * small and aligned for the CPU L1 cache.
179  *
180  * MHLEN is typically 168 bytes, giving us 8-byte alignment.  Getting
181  * 32 byte alignment needed for the fast bcopy results in 8 bytes being
182  * wasted.  Getting 64 byte alignment, which _should_ be ideal for
183  * modern Intel CPUs, results in 40 bytes wasted and a significant drop
184  * in observed efficiency of the optimization, 97.9% -> 81.8%.
185  */
186 #define IXGBE_RX_COPY_LEN_MAX     (MHLEN - ETHER_ALIGN)
187 
188 /*
189  * Default TX WTHRESH value.
190  * Currently, we don't use the Tx Head Pointer Write Back function.
191  */
192 #define IXGBE_TX_WTHRESH	5
193 
194 /*
195  * The max number of descriptors that one packet can use is 40 - WTHRESH - 2.
196  * Though 82598 does not have this limit, we don't want long TX chain.
197  * 33 should be large enough even for 64K TSO
198  * (32 * 2K mbuf cluster and 1 x mbuf header).
199  *
200  * Reference: 82599-X550 datasheet 7.2.1.1 "Transmit Storage in System Memory".
201  */
202 #define IXGBE_82599_SCATTER_MAX	(40 - IXGBE_TX_WTHRESH - 2)
203 #define IXGBE_SCATTER_DEFAULT	33
204 
205 /* Keep older OS drivers building... */
206 #if !defined(SYSCTL_ADD_UQUAD)
207 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
208 #endif
209 
210 /* Defines for printing debug information */
211 #define DEBUG_INIT  0
212 #define DEBUG_IOCTL 0
213 #define DEBUG_HW    0
214 
215 #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
216 #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
217 #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
218 #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
219 #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
220 #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
221 #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
222 #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
223 #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
224 
225 #define MAX_NUM_MULTICAST_ADDRESSES     128
226 #define MSIX_82598_BAR                  3
227 #define MSIX_82599_BAR                  4
228 #define IXGBE_TSO_SIZE                  262140
229 #define IXGBE_RX_HDR                    128
230 #define IXGBE_VFTA_SIZE                 128
231 #define IXGBE_BR_SIZE                   2048
232 #define IXGBE_QUEUE_MIN_FREE            32
233 #define IXGBE_MAX_TX_BUSY               10
234 #define IXGBE_QUEUE_HUNG                0x80000000
235 
236 #define IXGBE_EITR_DEFAULT		128
237 
238 /* IOCTL define to gather SFP+ Diagnostic data */
239 #define SIOCGI2C	SIOCGIFGENERIC
240 
241 /* Offload bits in mbuf flag */
242 #define	M_CSUM_OFFLOAD	\
243     (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4|M_CSUM_UDPv6|M_CSUM_TCPv6)
244 
245 /* Backward compatibility items for very old versions */
246 #ifndef pci_find_cap
247 #define pci_find_cap pci_find_extcap
248 #endif
249 
250 #ifndef DEVMETHOD_END
251 #define DEVMETHOD_END { NULL, NULL }
252 #endif
253 
254 /*
255  * Interrupt Moderation parameters
256  */
257 #define IXGBE_LOW_LATENCY	128
258 #define IXGBE_AVE_LATENCY	400
259 #define IXGBE_BULK_LATENCY	1200
260 
261 /* Using 1FF (the max value), the interval is ~1.05ms */
262 #define IXGBE_LINK_ITR_QUANTA  0x1FF
263 #define IXGBE_LINK_ITR         ((IXGBE_LINK_ITR_QUANTA << 3) & \
264                                 IXGBE_EITR_ITR_INT_MASK)
265 
266 
267 /************************************************************************
268  * vendor_info_array
269  *
270  *   Contains the list of Subvendor/Subdevice IDs on
271  *   which the driver should load.
272  ************************************************************************/
273 typedef struct _ixgbe_vendor_info_t {
274 	unsigned int vendor_id;
275 	unsigned int device_id;
276 	unsigned int subvendor_id;
277 	unsigned int subdevice_id;
278 	unsigned int index;
279 } ixgbe_vendor_info_t;
280 
281 /* This is used to get SFP+ module data */
282 struct ixgbe_i2c_req {
283 	u8 dev_addr;
284 	u8 offset;
285 	u8 len;
286 	u8 data[8];
287 };
288 
289 struct ixgbe_bp_data {
290 	u32 low;
291 	u32 high;
292 	u32 log;
293 };
294 
295 struct ixgbe_tx_buf {
296 	union ixgbe_adv_tx_desc	*eop;
297 	struct mbuf             *m_head;
298 	bus_dmamap_t            map;
299 };
300 
301 struct ixgbe_rx_buf {
302 	struct mbuf    *buf;
303 	struct mbuf    *fmp;
304 	bus_dmamap_t   pmap;
305 	u_int          flags;
306 #define IXGBE_RX_COPY  0x01
307 	uint64_t       addr;
308 };
309 
310 /*
311  * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free
312  */
313 struct ixgbe_dma_alloc {
314 	bus_addr_t        dma_paddr;
315 	void              *dma_vaddr;
316 	ixgbe_dma_tag_t   *dma_tag;
317 	bus_dmamap_t      dma_map;
318 	bus_dma_segment_t dma_seg;
319 	bus_size_t        dma_size;
320 };
321 
322 struct ixgbe_mc_addr {
323 	u8  addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
324 	u32 vmdq;
325 };
326 
327 /*
328  * Driver queue struct: this is the interrupt container
329  *                      for the associated tx and rx ring.
330  */
331 struct ix_queue {
332 	struct adapter   *adapter;
333 	u32              msix;           /* This queue's MSI-X vector */
334 	u32              eitr_setting;
335 	u32              me;
336 	struct resource  *res;
337 	int              busy;
338 	struct tx_ring   *txr;
339 	struct rx_ring   *rxr;
340 	struct work      wq_cookie;
341 	void             *que_si;
342 	/* Per queue event conters */
343 	struct evcnt     irqs;		/* Hardware interrupt */
344 	struct evcnt     handleq;	/* software_interrupt */
345 	struct evcnt     req;		/* deferred */
346 	char             namebuf[32];	/* Name for sysctl */
347 	char             evnamebuf[32];	/* Name for evcnt */
348 
349 	/* Lock for disabled_count and this queue's EIMS/EIMC bit */
350 	kmutex_t         dc_mtx;
351 	/*
352 	 * disabled_count means:
353 	 *     0   : this queue is enabled
354 	 *     > 0 : this queue is disabled
355 	 *           the value is ixgbe_disable_queue() called count
356 	 */
357 	int              disabled_count;
358 	bool             txrx_use_workqueue;
359 };
360 
361 /*
362  * The transmit ring, one per queue
363  */
364 struct tx_ring {
365 	struct adapter		*adapter;
366 	kmutex_t		tx_mtx;
367 	u32			me;
368 	u32			tail;
369 	int			busy;
370 	union ixgbe_adv_tx_desc	*tx_base;
371 	struct ixgbe_tx_buf	*tx_buffers;
372 	struct ixgbe_dma_alloc	txdma;
373 	volatile u16		tx_avail;
374 	u16			next_avail_desc;
375 	u16			next_to_clean;
376 	u16			num_desc;
377 	ixgbe_dma_tag_t		*txtag;
378 #if 0
379 	char			mtx_name[16]; /* NetBSD has no mutex name */
380 #endif
381 	pcq_t			*txr_interq;
382 	struct work		wq_cookie;
383 	void			*txr_si;
384 	bool			txr_no_space; /* Like IFF_OACTIVE */
385 
386 	/* Flow Director */
387 	u16			atr_sample;
388 	u16			atr_count;
389 
390 	u64			bytes;  /* Used for AIM */
391 	u64			packets;
392 	/* Soft Stats */
393 	struct evcnt		tso_tx;
394 	struct evcnt		no_desc_avail;
395 	struct evcnt		total_packets;
396 	struct evcnt		pcq_drops;
397 	/* Per queue conters.  The adapter total is in struct adapter */
398 	u64              q_efbig_tx_dma_setup;
399 	u64              q_mbuf_defrag_failed;
400 	u64              q_efbig2_tx_dma_setup;
401 	u64              q_einval_tx_dma_setup;
402 	u64              q_other_tx_dma_setup;
403 	u64              q_eagain_tx_dma_setup;
404 	u64              q_enomem_tx_dma_setup;
405 	u64              q_tso_err;
406 };
407 
408 
409 /*
410  * The Receive ring, one per rx queue
411  */
412 struct rx_ring {
413 	struct adapter		*adapter;
414 	kmutex_t		rx_mtx;
415 	u32			me;
416 	u32			tail;
417 	union ixgbe_adv_rx_desc	*rx_base;
418 	struct ixgbe_dma_alloc	rxdma;
419 #ifdef LRO
420 	struct lro_ctrl		lro;
421 #endif /* LRO */
422 	bool			lro_enabled;
423 	bool			hw_rsc;
424 	bool			vtag_strip;
425 	bool			discard_multidesc;
426 	u16			next_to_refresh;
427 	u16			next_to_check;
428 	u16			num_desc;
429 	u16			mbuf_sz;
430 #if 0
431 	char			mtx_name[16]; /* NetBSD has no mutex name */
432 #endif
433 	struct ixgbe_rx_buf	*rx_buffers;
434 	ixgbe_dma_tag_t		*ptag;
435 
436 	u64			bytes; /* Used for AIM calc */
437 	u64			packets;
438 
439 	/* Soft stats */
440 	struct evcnt		rx_copies;
441 	struct evcnt		rx_packets;
442 	struct evcnt		rx_bytes;
443 	struct evcnt		rx_discarded;
444 	struct evcnt		no_mbuf;
445 	u64			rsc_num;
446 
447 	/* Flow Director */
448 	u64			flm;
449 };
450 
451 struct ixgbe_vf {
452 	u_int    pool;
453 	u_int    rar_index;
454 	u_int    max_frame_size;
455 	uint32_t flags;
456 	uint8_t  ether_addr[ETHER_ADDR_LEN];
457 	uint16_t mc_hash[IXGBE_MAX_VF_MC];
458 	uint16_t num_mc_hashes;
459 	uint16_t default_vlan;
460 	uint16_t vlan_tag;
461 	uint16_t api_ver;
462 };
463 
464 /*
465  * NetBSD: For trafic class
466  * Crrently, the following structure is only for statistics.
467  */
468 struct ixgbe_tc {
469 	char             evnamebuf[32];
470 };
471 
472 /* Our adapter structure */
473 struct adapter {
474 	struct ixgbe_hw		hw;
475 	struct ixgbe_osdep	osdep;
476 
477 	device_t		dev;
478 	struct ifnet		*ifp;
479 	struct if_percpuq	*ipq;	/* softint-based input queues */
480 
481 	struct resource		*pci_mem;
482 
483 	/* NetBSD: Interrupt resources are in osdep */
484 
485 	struct ifmedia		media;
486 	callout_t		timer;
487 	struct workqueue	*timer_wq;
488 	struct work		timer_wc;
489 	u_int			timer_pending;
490 
491 	u_short			if_flags;	/* saved ifp->if_flags */
492 	int			ec_capenable;	/* saved ec->ec_capenable */
493 
494 	kmutex_t		core_mtx;
495 
496 	unsigned int		num_queues;
497 
498 	/*
499 	 * Shadow VFTA table, this is needed because
500 	 * the real vlan filter table gets cleared during
501 	 * a soft reset and the driver needs to be able
502 	 * to repopulate it.
503 	 */
504 	u32			shadow_vfta[IXGBE_VFTA_SIZE];
505 
506 	/* Info about the interface */
507 	int			advertise;  /* link speeds */
508 	bool			enable_aim; /* adaptive interrupt moderation */
509 	int			link_active; /* Use LINK_STATE_* value */
510 	u16			max_frame_size;
511 	u16			num_segs;
512 	u32			link_speed;
513 	bool			link_up;
514 	u32			vector;
515 	u16			dmac;
516 	u32			phy_layer;
517 
518 	/* Power management-related */
519 	bool			wol_support;
520 	u32			wufc;
521 
522 	/* Mbuf cluster size */
523 	u32			rx_mbuf_sz;
524 
525 	bool			schedule_wqs_ok;
526 
527 	/* Flow Director */
528 	int			fdir_reinit;
529 
530 	/* Admin task */
531 	struct workqueue	*admin_wq; /* Link, SFP, PHY and FDIR */
532 	struct work		admin_wc;
533 	u_int			admin_pending;
534 	volatile u32		task_requests;
535 	kmutex_t		admin_mtx; /* lock for admin_pending, task_request */
536 					   /*
537 					    * Don't acquire this mutex while
538 					    * holding rx_mtx or tx_mtx, and
539 					    * vice versa.
540 					    */
541 
542 	bool			txrx_use_workqueue;
543 
544 	/*
545 	 * Workqueue for ixgbe_handle_que_work().
546 	 *
547 	 * que_wq's "enqueued flag" is not required, because twice
548 	 * workqueue_enqueue() for ixgbe_handle_que_work() is avoided by
549 	 * masking the queue's interrupt by EIMC. See also ixgbe_msix_que().
550 	 */
551 	struct workqueue	*que_wq;
552 	/* Workqueue for ixgbe_deferred_mq_start_work() */
553 	struct workqueue	*txr_wq;
554 	percpu_t		*txr_wq_enqueued;
555 
556 	/*
557 	 * Queues:
558 	 *   This is the irq holder, it has
559 	 *   and RX/TX pair or rings associated
560 	 *   with it.
561 	 */
562 	struct ix_queue		*queues;
563 
564 	/*
565 	 * Transmit rings
566 	 *      Allocated at run time, an array of rings
567 	 */
568 	struct tx_ring		*tx_rings;
569 	u32			num_tx_desc;
570 	u32			tx_process_limit;
571 
572 	/*
573 	 * Receive rings
574 	 *      Allocated at run time, an array of rings
575 	 */
576 	struct rx_ring		*rx_rings;
577 	u64			active_queues;
578 	u32			num_rx_desc;
579 	u32			rx_process_limit;
580 	u32			rx_copy_len;
581 
582 	/* Multicast array memory */
583 	struct ixgbe_mc_addr	*mta;
584 
585 	/* SR-IOV */
586 	int                     iov_mode;
587 	int			num_vfs;
588 	int			pool;
589 	struct ixgbe_vf		*vfs;
590 
591 	/* Bypass */
592 	struct ixgbe_bp_data    bypass;
593 
594 	/* Netmap */
595 	void			(*init_locked)(struct adapter *);
596 	void			(*stop_locked)(void *);
597 
598 	/* Firmware error check */
599 	u_int                   recovery_mode;
600 	callout_t               recovery_mode_timer;
601 	struct workqueue        *recovery_mode_timer_wq;
602 	struct work             recovery_mode_timer_wc;
603 	u_int			recovery_mode_timer_pending;
604 
605 	/* Misc stats maintained by the driver */
606 	struct evcnt		efbig_tx_dma_setup;
607 	struct evcnt		mbuf_defrag_failed;
608 	struct evcnt		efbig2_tx_dma_setup;
609 	struct evcnt		einval_tx_dma_setup;
610 	struct evcnt		other_tx_dma_setup;
611 	struct evcnt		eagain_tx_dma_setup;
612 	struct evcnt		enomem_tx_dma_setup;
613 	struct evcnt		tso_err;
614 	struct evcnt		watchdog_events;
615 	struct evcnt		admin_irqev;
616 	struct evcnt		link_workev;
617 	struct evcnt		mod_workev;
618 	struct evcnt		msf_workev;
619 	struct evcnt		phy_workev;
620 
621 	union {
622 		struct ixgbe_hw_stats pf;
623 		struct ixgbevf_hw_stats	vf;
624 	} stats;
625 #if __FreeBSD_version >= 1100036
626 	/* counter(9) stats */
627 	u64			ipackets;
628 	u64			ierrors;
629 	u64			opackets;
630 	u64			oerrors;
631 	u64			ibytes;
632 	u64			obytes;
633 	u64			imcasts;
634 	u64			omcasts;
635 	u64			iqdrops;
636 	u64			noproto;
637 #endif
638 	/* Feature capable/enabled flags.  See ixgbe_features.h */
639 	u32                     feat_cap;
640 	u32                     feat_en;
641 
642 	/* Traffic classes */
643 	struct ixgbe_tc tcs[IXGBE_DCB_MAX_TRAFFIC_CLASS];
644 
645 	struct sysctllog	*sysctllog;
646 	const struct sysctlnode *sysctltop;
647 	struct timeval		lasterr_time;
648 };
649 
650 /* Precision Time Sync (IEEE 1588) defines */
651 #define ETHERTYPE_IEEE1588      0x88F7
652 #define PICOSECS_PER_TICK       20833
653 #define TSYNC_UDP_PORT          319 /* UDP port for the protocol */
654 #define IXGBE_ADVTXD_TSTAMP     0x00080000
655 
656 
657 #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
658 	mutex_init(&(_sc)->core_mtx, MUTEX_DEFAULT, IPL_SOFTNET)
659 #define IXGBE_CORE_LOCK_DESTROY(_sc)      mutex_destroy(&(_sc)->core_mtx)
660 #define IXGBE_TX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->tx_mtx)
661 #define IXGBE_RX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->rx_mtx)
662 #define IXGBE_CORE_LOCK(_sc)              mutex_enter(&(_sc)->core_mtx)
663 #define IXGBE_TX_LOCK(_sc)                mutex_enter(&(_sc)->tx_mtx)
664 #define IXGBE_TX_TRYLOCK(_sc)             mutex_tryenter(&(_sc)->tx_mtx)
665 #define IXGBE_RX_LOCK(_sc)                mutex_enter(&(_sc)->rx_mtx)
666 #define IXGBE_CORE_UNLOCK(_sc)            mutex_exit(&(_sc)->core_mtx)
667 #define IXGBE_TX_UNLOCK(_sc)              mutex_exit(&(_sc)->tx_mtx)
668 #define IXGBE_RX_UNLOCK(_sc)              mutex_exit(&(_sc)->rx_mtx)
669 #define IXGBE_CORE_LOCK_ASSERT(_sc)       KASSERT(mutex_owned(&(_sc)->core_mtx))
670 #define IXGBE_TX_LOCK_ASSERT(_sc)         KASSERT(mutex_owned(&(_sc)->tx_mtx))
671 
672 /* External PHY register addresses */
673 #define IXGBE_PHY_CURRENT_TEMP		0xC820
674 #define IXGBE_PHY_OVERTEMP_STATUS	0xC830
675 
676 /* Sysctl help messages; displayed with sysctl -d */
677 #define IXGBE_SYSCTL_DESC_ADV_SPEED \
678 	"\nControl advertised link speed using these flags:\n" \
679 	"\t0x1  - advertise 100M\n" \
680 	"\t0x2  - advertise 1G\n" \
681 	"\t0x4  - advertise 10G\n" \
682 	"\t0x8  - advertise 10M\n" \
683 	"\t0x10 - advertise 2.5G\n" \
684 	"\t0x20 - advertise 5G\n\n" \
685 	"\t5G, 2.5G, 100M and 10M are only supported on certain adapters."
686 
687 #define IXGBE_SYSCTL_DESC_SET_FC \
688 	"\nSet flow control mode using these values:\n" \
689 	"\t0 - off\n" \
690 	"\t1 - rx pause\n" \
691 	"\t2 - tx pause\n" \
692 	"\t3 - tx and rx pause"
693 
694 /* Workaround to make 8.0 buildable */
695 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
696 static __inline int
697 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
698 {
699 #ifdef ALTQ
700 	if (ALTQ_IS_ENABLED(&ifp->if_snd))
701 		return (1);
702 #endif
703 	return (!buf_ring_empty(br));
704 }
705 #endif
706 
707 /*
708  * Find the number of unrefreshed RX descriptors
709  */
710 static __inline u16
711 ixgbe_rx_unrefreshed(struct rx_ring *rxr)
712 {
713 	if (rxr->next_to_check > rxr->next_to_refresh)
714 		return (rxr->next_to_check - rxr->next_to_refresh - 1);
715 	else
716 		return ((rxr->num_desc + rxr->next_to_check) -
717 		    rxr->next_to_refresh - 1);
718 }
719 
720 static __inline int
721 ixgbe_legacy_ring_empty(struct ifnet *ifp, pcq_t *dummy)
722 {
723 	UNREFERENCED_1PARAMETER(dummy);
724 
725 	return IFQ_IS_EMPTY(&ifp->if_snd);
726 }
727 
728 static __inline int
729 ixgbe_mq_ring_empty(struct ifnet *dummy, pcq_t *interq)
730 {
731 	UNREFERENCED_1PARAMETER(dummy);
732 
733 	return (pcq_peek(interq) == NULL);
734 }
735 
736 /*
737  * This checks for a zero mac addr, something that will be likely
738  * unless the Admin on the Host has created one.
739  */
740 static __inline bool
741 ixv_check_ether_addr(u8 *addr)
742 {
743 	bool status = TRUE;
744 
745 	if ((addr[0] == 0 && addr[1]== 0 && addr[2] == 0 &&
746 	    addr[3] == 0 && addr[4]== 0 && addr[5] == 0))
747 		status = FALSE;
748 
749 	return (status);
750 }
751 
752 /*
753  * This checks the adapter->recovery_mode software flag which is
754  * set by ixgbe_fw_recovery_mode().
755  *
756  */
757 static inline bool
758 ixgbe_fw_recovery_mode_swflag(struct adapter *adapter)
759 {
760 	return (adapter->feat_en & IXGBE_FEATURE_RECOVERY_MODE) &&
761 	    atomic_load_acq_uint(&adapter->recovery_mode);
762 }
763 
764 /* Shared Prototypes */
765 void ixgbe_legacy_start(struct ifnet *);
766 int  ixgbe_legacy_start_locked(struct ifnet *, struct tx_ring *);
767 int  ixgbe_mq_start(struct ifnet *, struct mbuf *);
768 int  ixgbe_mq_start_locked(struct ifnet *, struct tx_ring *);
769 void ixgbe_deferred_mq_start(void *);
770 void ixgbe_deferred_mq_start_work(struct work *, void *);
771 void ixgbe_drain_all(struct adapter *);
772 
773 int  ixgbe_allocate_queues(struct adapter *);
774 void ixgbe_free_queues(struct adapter *);
775 int  ixgbe_setup_transmit_structures(struct adapter *);
776 void ixgbe_free_transmit_structures(struct adapter *);
777 int  ixgbe_setup_receive_structures(struct adapter *);
778 void ixgbe_free_receive_structures(struct adapter *);
779 bool ixgbe_txeof(struct tx_ring *);
780 bool ixgbe_rxeof(struct ix_queue *);
781 
782 #define IXGBE_REQUEST_TASK_MOD		0x01
783 #define IXGBE_REQUEST_TASK_MOD_WOI	0x02
784 #define IXGBE_REQUEST_TASK_MSF		0x04
785 #define IXGBE_REQUEST_TASK_MSF_WOI	0x08
786 #define IXGBE_REQUEST_TASK_MBX		0x10
787 #define IXGBE_REQUEST_TASK_FDIR		0x20
788 #define IXGBE_REQUEST_TASK_PHY		0x40
789 #define IXGBE_REQUEST_TASK_LSC		0x80
790 
791 /* For NetBSD */
792 const struct sysctlnode *ixgbe_sysctl_instance(struct adapter *);
793 
794 #include "ixgbe_bypass.h"
795 #include "ixgbe_fdir.h"
796 #include "ixgbe_rss.h"
797 #include "ixgbe_netmap.h"
798 
799 #endif /* _IXGBE_H_ */
800