Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe.h revision 1.62
      1 /* $NetBSD: ixgbe.h,v 1.62 2020/01/21 14:55:55 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	MPKTHSIZE		(offsetof(struct _mbuf_dummy, m_pktdat))
    187 #define IXGBE_RX_COPY_HDR_PADDED  ((((MPKTHSIZE - 1) / 32) + 1) * 32)
    188 #define IXGBE_RX_COPY_LEN         (MSIZE - IXGBE_RX_COPY_HDR_PADDED)
    189 #define IXGBE_RX_COPY_ALIGN       (IXGBE_RX_COPY_HDR_PADDED - MPKTHSIZE)
    190 
    191 /* Keep older OS drivers building... */
    192 #if !defined(SYSCTL_ADD_UQUAD)
    193 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
    194 #endif
    195 
    196 /* Defines for printing debug information */
    197 #define DEBUG_INIT  0
    198 #define DEBUG_IOCTL 0
    199 #define DEBUG_HW    0
    200 
    201 #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
    202 #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
    203 #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
    204 #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
    205 #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
    206 #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
    207 #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
    208 #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
    209 #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
    210 
    211 #define MAX_NUM_MULTICAST_ADDRESSES     128
    212 #define IXGBE_82598_SCATTER             100
    213 #define IXGBE_82599_SCATTER             32
    214 #define MSIX_82598_BAR                  3
    215 #define MSIX_82599_BAR                  4
    216 #define IXGBE_TSO_SIZE                  262140
    217 #define IXGBE_RX_HDR                    128
    218 #define IXGBE_VFTA_SIZE                 128
    219 #define IXGBE_BR_SIZE                   4096
    220 #define IXGBE_QUEUE_MIN_FREE            32
    221 #define IXGBE_MAX_TX_BUSY               10
    222 #define IXGBE_QUEUE_HUNG                0x80000000
    223 
    224 #define IXGBE_EITR_DEFAULT		128
    225 
    226 /* IOCTL define to gather SFP+ Diagnostic data */
    227 #define SIOCGI2C	SIOCGIFGENERIC
    228 
    229 /* Offload bits in mbuf flag */
    230 #define	M_CSUM_OFFLOAD	\
    231     (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4|M_CSUM_UDPv6|M_CSUM_TCPv6)
    232 
    233 /* Backward compatibility items for very old versions */
    234 #ifndef pci_find_cap
    235 #define pci_find_cap pci_find_extcap
    236 #endif
    237 
    238 #ifndef DEVMETHOD_END
    239 #define DEVMETHOD_END { NULL, NULL }
    240 #endif
    241 
    242 /*
    243  * Interrupt Moderation parameters
    244  */
    245 #define IXGBE_LOW_LATENCY	128
    246 #define IXGBE_AVE_LATENCY	400
    247 #define IXGBE_BULK_LATENCY	1200
    248 
    249 /* Using 1FF (the max value), the interval is ~1.05ms */
    250 #define IXGBE_LINK_ITR_QUANTA  0x1FF
    251 #define IXGBE_LINK_ITR         ((IXGBE_LINK_ITR_QUANTA << 3) & \
    252                                 IXGBE_EITR_ITR_INT_MASK)
    253 
    254 
    255 /************************************************************************
    256  * vendor_info_array
    257  *
    258  *   Contains the list of Subvendor/Subdevice IDs on
    259  *   which the driver should load.
    260  ************************************************************************/
    261 typedef struct _ixgbe_vendor_info_t {
    262 	unsigned int vendor_id;
    263 	unsigned int device_id;
    264 	unsigned int subvendor_id;
    265 	unsigned int subdevice_id;
    266 	unsigned int index;
    267 } ixgbe_vendor_info_t;
    268 
    269 /* This is used to get SFP+ module data */
    270 struct ixgbe_i2c_req {
    271         u8 dev_addr;
    272         u8 offset;
    273         u8 len;
    274         u8 data[8];
    275 };
    276 
    277 struct ixgbe_bp_data {
    278 	u32 low;
    279 	u32 high;
    280 	u32 log;
    281 };
    282 
    283 struct ixgbe_tx_buf {
    284 	union ixgbe_adv_tx_desc	*eop;
    285 	struct mbuf             *m_head;
    286 	bus_dmamap_t            map;
    287 };
    288 
    289 struct ixgbe_rx_buf {
    290 	struct mbuf    *buf;
    291 	struct mbuf    *fmp;
    292 	bus_dmamap_t   pmap;
    293 	u_int          flags;
    294 #define IXGBE_RX_COPY  0x01
    295 	uint64_t       addr;
    296 };
    297 
    298 /*
    299  * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free
    300  */
    301 struct ixgbe_dma_alloc {
    302 	bus_addr_t        dma_paddr;
    303 	void              *dma_vaddr;
    304 	ixgbe_dma_tag_t   *dma_tag;
    305 	bus_dmamap_t      dma_map;
    306 	bus_dma_segment_t dma_seg;
    307 	bus_size_t        dma_size;
    308 };
    309 
    310 struct ixgbe_mc_addr {
    311 	u8  addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
    312 	u32 vmdq;
    313 };
    314 
    315 /*
    316  * Driver queue struct: this is the interrupt container
    317  *                      for the associated tx and rx ring.
    318  */
    319 struct ix_queue {
    320 	struct adapter   *adapter;
    321 	u32              msix;           /* This queue's MSI-X vector */
    322 	u32              eitr_setting;
    323 	u32              me;
    324 	struct resource  *res;
    325 	int              busy;
    326 	struct tx_ring   *txr;
    327 	struct rx_ring   *rxr;
    328 	struct work      wq_cookie;
    329 	void             *que_si;
    330 	/* Per queue event conters */
    331 	struct evcnt     irqs;		/* Hardware interrupt */
    332 	struct evcnt     handleq;	/* software_interrupt */
    333 	struct evcnt     req;		/* deferred */
    334 	char             namebuf[32];
    335 	char             evnamebuf[32];
    336 
    337 	kmutex_t         dc_mtx;	/* lock for disabled_count and this queue's EIMS/EIMC bit */
    338 	int              disabled_count;/*
    339 					 * means
    340 					 *     0   : this queue is enabled
    341 					 *     > 0 : this queue is disabled
    342 					 *           the value is ixgbe_disable_queue() called count
    343 					 */
    344 	bool             txrx_use_workqueue;
    345 };
    346 
    347 /*
    348  * The transmit ring, one per queue
    349  */
    350 struct tx_ring {
    351 	struct adapter		*adapter;
    352 	kmutex_t		tx_mtx;
    353 	u32			me;
    354 	u32			tail;
    355 	int			busy;
    356 	union ixgbe_adv_tx_desc	*tx_base;
    357 	struct ixgbe_tx_buf	*tx_buffers;
    358 	struct ixgbe_dma_alloc	txdma;
    359 	volatile u16		tx_avail;
    360 	u16			next_avail_desc;
    361 	u16			next_to_clean;
    362 	u16			num_desc;
    363 	ixgbe_dma_tag_t		*txtag;
    364 #if 0
    365 	char			mtx_name[16]; /* NetBSD has no mutex name */
    366 #endif
    367 	pcq_t			*txr_interq;
    368 	struct work		wq_cookie;
    369 	void			*txr_si;
    370 	bool			txr_no_space; /* Like IFF_OACTIVE */
    371 
    372 	/* Flow Director */
    373 	u16			atr_sample;
    374 	u16			atr_count;
    375 
    376 	u64			bytes;  /* used for AIM */
    377 	u64			packets;
    378 	/* Soft Stats */
    379 	struct evcnt	   	tso_tx;
    380 	struct evcnt		no_desc_avail;
    381 	struct evcnt		total_packets;
    382 	struct evcnt		pcq_drops;
    383 	/* Per queue conters.  The adapter total is in struct adapter */
    384 	u64              q_efbig_tx_dma_setup;
    385 	u64              q_mbuf_defrag_failed;
    386 	u64              q_efbig2_tx_dma_setup;
    387 	u64              q_einval_tx_dma_setup;
    388 	u64              q_other_tx_dma_setup;
    389 	u64              q_eagain_tx_dma_setup;
    390 	u64              q_enomem_tx_dma_setup;
    391 	u64              q_tso_err;
    392 };
    393 
    394 
    395 /*
    396  * The Receive ring, one per rx queue
    397  */
    398 struct rx_ring {
    399 	struct adapter		*adapter;
    400 	kmutex_t		rx_mtx;
    401 	u32			me;
    402 	u32			tail;
    403 	union ixgbe_adv_rx_desc	*rx_base;
    404 	struct ixgbe_dma_alloc	rxdma;
    405 #ifdef LRO
    406 	struct lro_ctrl		lro;
    407 #endif /* LRO */
    408 	bool			lro_enabled;
    409 	bool			hw_rsc;
    410 	bool			vtag_strip;
    411 	u16			next_to_refresh;
    412 	u16 			next_to_check;
    413 	u16			num_desc;
    414 	u16			mbuf_sz;
    415 #if 0
    416 	char			mtx_name[16]; /* NetBSD has no mutex name */
    417 #endif
    418 	struct ixgbe_rx_buf	*rx_buffers;
    419 	ixgbe_dma_tag_t		*ptag;
    420 	u16	                last_rx_mbuf_sz;
    421 	u32                	last_num_rx_desc;
    422 	ixgbe_extmem_head_t	jcl_head;
    423 
    424 	u64			bytes; /* Used for AIM calc */
    425 	u64			packets;
    426 
    427 	/* Soft stats */
    428 	struct evcnt		rx_copies;
    429 	struct evcnt		rx_packets;
    430 	struct evcnt 		rx_bytes;
    431 	struct evcnt 		rx_discarded;
    432 	struct evcnt 		no_jmbuf;
    433 	u64 			rsc_num;
    434 
    435 	/* Flow Director */
    436 	u64			flm;
    437 };
    438 
    439 struct ixgbe_vf {
    440 	u_int    pool;
    441 	u_int    rar_index;
    442 	u_int    max_frame_size;
    443 	uint32_t flags;
    444 	uint8_t  ether_addr[ETHER_ADDR_LEN];
    445 	uint16_t mc_hash[IXGBE_MAX_VF_MC];
    446 	uint16_t num_mc_hashes;
    447 	uint16_t default_vlan;
    448 	uint16_t vlan_tag;
    449 	uint16_t api_ver;
    450 };
    451 
    452 /*
    453  * NetBSD: For trafic class
    454  * Crrently, the following structure is only for statistics.
    455  */
    456 struct ixgbe_tc {
    457 	char             evnamebuf[32];
    458 };
    459 
    460 /* Our adapter structure */
    461 struct adapter {
    462 	struct ixgbe_hw		hw;
    463 	struct ixgbe_osdep	osdep;
    464 
    465 	device_t		dev;
    466 	struct ifnet		*ifp;
    467 	struct if_percpuq	*ipq;	/* softint-based input queues */
    468 
    469 	struct resource		*pci_mem;
    470 	struct resource		*msix_mem;
    471 
    472 	/* NetBSD: Interrupt resources are in osdep */
    473 
    474 	struct ifmedia		media;
    475 	callout_t		timer;
    476 	u_short			if_flags;	/* saved ifp->if_flags */
    477 	int			ec_capenable;	/* saved ec->ec_capenable */
    478 
    479 	kmutex_t		core_mtx;
    480 
    481 	unsigned int		num_queues;
    482 
    483 	/*
    484 	 * Shadow VFTA table, this is needed because
    485 	 * the real vlan filter table gets cleared during
    486 	 * a soft reset and the driver needs to be able
    487 	 * to repopulate it.
    488 	 */
    489 	u32			shadow_vfta[IXGBE_VFTA_SIZE];
    490 
    491 	/* Info about the interface */
    492 	int			advertise;  /* link speeds */
    493 	bool			enable_aim; /* adaptive interrupt moderation */
    494 	int			link_active; /* Use LINK_STATE_* value */
    495 	u16			max_frame_size;
    496 	u16			num_segs;
    497 	u32			link_speed;
    498 	bool			link_up;
    499 	u32 			vector;
    500 	u16			dmac;
    501 	u32			phy_layer;
    502 
    503 	/* Power management-related */
    504 	bool			wol_support;
    505 	u32			wufc;
    506 
    507 	/* Mbuf cluster size */
    508 	u32			rx_mbuf_sz;
    509 
    510 	/* Support for pluggable optics */
    511 	bool			sfp_probe;
    512 	void			*link_si;  /* Link tasklet */
    513 	void			*mod_si;   /* SFP tasklet */
    514 	void			*msf_si;   /* Multispeed Fiber */
    515 	void			*mbx_si;   /* VF -> PF mailbox interrupt */
    516 
    517 	/* Flow Director */
    518 	int			fdir_reinit;
    519 	void			*fdir_si;
    520 
    521 	void			*phy_si;   /* PHY intr tasklet */
    522 
    523 	bool			txrx_use_workqueue;
    524 	struct workqueue	*que_wq;    /* workqueue for ixgbe_handle_que_work() */
    525 					    /*
    526 					     * que_wq's "enqueued flag" is not required,
    527 					     * because twice workqueue_enqueue() for
    528 					     * ixgbe_handle_que_work() is avoided by masking
    529 					     * the queue's interrupt by EIMC.
    530 					     * See also ixgbe_msix_que().
    531 					     */
    532 	struct workqueue	*txr_wq;    /* workqueue for ixgbe_deferred_mq_start_work() */
    533 	percpu_t		*txr_wq_enqueued;
    534 
    535 	/*
    536 	 * Queues:
    537 	 *   This is the irq holder, it has
    538 	 *   and RX/TX pair or rings associated
    539 	 *   with it.
    540 	 */
    541 	struct ix_queue		*queues;
    542 
    543 	/*
    544 	 * Transmit rings
    545 	 *      Allocated at run time, an array of rings
    546 	 */
    547 	struct tx_ring		*tx_rings;
    548 	u32			num_tx_desc;
    549 	u32			tx_process_limit;
    550 
    551 	/*
    552 	 * Receive rings
    553 	 *      Allocated at run time, an array of rings
    554 	 */
    555 	struct rx_ring		*rx_rings;
    556 	u64			active_queues;
    557 	u32			num_rx_desc;
    558 	u32			rx_process_limit;
    559 
    560 	/* Multicast array memory */
    561 	struct ixgbe_mc_addr	*mta;
    562 
    563 	/* SR-IOV */
    564 	int                     iov_mode;
    565 	int			num_vfs;
    566 	int			pool;
    567 	struct ixgbe_vf		*vfs;
    568 
    569 	/* Bypass */
    570 	struct ixgbe_bp_data    bypass;
    571 
    572 	/* Netmap */
    573 	void 			(*init_locked)(struct adapter *);
    574 	void 			(*stop_locked)(void *);
    575 
    576 	/* Firmware error check */
    577 	u_int                   recovery_mode;
    578 	struct callout          recovery_mode_timer;
    579 
    580 	/* Misc stats maintained by the driver */
    581 	struct evcnt	   	efbig_tx_dma_setup;
    582 	struct evcnt   		mbuf_defrag_failed;
    583 	struct evcnt	   	efbig2_tx_dma_setup;
    584 	struct evcnt	   	einval_tx_dma_setup;
    585 	struct evcnt	   	other_tx_dma_setup;
    586 	struct evcnt	   	eagain_tx_dma_setup;
    587 	struct evcnt	   	enomem_tx_dma_setup;
    588 	struct evcnt	   	tso_err;
    589 	struct evcnt	   	watchdog_events;
    590 	struct evcnt		link_irq;
    591 	struct evcnt		link_sicount;
    592 	struct evcnt		mod_sicount;
    593 	struct evcnt		msf_sicount;
    594 	struct evcnt		phy_sicount;
    595 
    596 	union {
    597 		struct ixgbe_hw_stats pf;
    598 		struct ixgbevf_hw_stats	vf;
    599 	} stats;
    600 #if __FreeBSD_version >= 1100036
    601 	/* counter(9) stats */
    602 	u64			ipackets;
    603 	u64			ierrors;
    604 	u64			opackets;
    605 	u64			oerrors;
    606 	u64			ibytes;
    607 	u64			obytes;
    608 	u64			imcasts;
    609 	u64			omcasts;
    610 	u64			iqdrops;
    611 	u64			noproto;
    612 #endif
    613 	/* Feature capable/enabled flags.  See ixgbe_features.h */
    614 	u32                     feat_cap;
    615 	u32                     feat_en;
    616 
    617 	/* Traffic classes */
    618 	struct ixgbe_tc tcs[IXGBE_DCB_MAX_TRAFFIC_CLASS];
    619 
    620 	struct sysctllog	*sysctllog;
    621 	const struct sysctlnode *sysctltop;
    622 };
    623 
    624 /* Precision Time Sync (IEEE 1588) defines */
    625 #define ETHERTYPE_IEEE1588      0x88F7
    626 #define PICOSECS_PER_TICK       20833
    627 #define TSYNC_UDP_PORT          319 /* UDP port for the protocol */
    628 #define IXGBE_ADVTXD_TSTAMP     0x00080000
    629 
    630 
    631 #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
    632         mutex_init(&(_sc)->core_mtx, MUTEX_DEFAULT, IPL_SOFTNET)
    633 #define IXGBE_CORE_LOCK_DESTROY(_sc)      mutex_destroy(&(_sc)->core_mtx)
    634 #define IXGBE_TX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->tx_mtx)
    635 #define IXGBE_RX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->rx_mtx)
    636 #define IXGBE_CORE_LOCK(_sc)              mutex_enter(&(_sc)->core_mtx)
    637 #define IXGBE_TX_LOCK(_sc)                mutex_enter(&(_sc)->tx_mtx)
    638 #define IXGBE_TX_TRYLOCK(_sc)             mutex_tryenter(&(_sc)->tx_mtx)
    639 #define IXGBE_RX_LOCK(_sc)                mutex_enter(&(_sc)->rx_mtx)
    640 #define IXGBE_CORE_UNLOCK(_sc)            mutex_exit(&(_sc)->core_mtx)
    641 #define IXGBE_TX_UNLOCK(_sc)              mutex_exit(&(_sc)->tx_mtx)
    642 #define IXGBE_RX_UNLOCK(_sc)              mutex_exit(&(_sc)->rx_mtx)
    643 #define IXGBE_CORE_LOCK_ASSERT(_sc)       KASSERT(mutex_owned(&(_sc)->core_mtx))
    644 #define IXGBE_TX_LOCK_ASSERT(_sc)         KASSERT(mutex_owned(&(_sc)->tx_mtx))
    645 
    646 /* Stats macros */
    647 #if __FreeBSD_version >= 1100036
    648 #define IXGBE_SET_IERRORS(sc, count)     (sc)->ierrors = (count)
    649 #define IXGBE_SET_OPACKETS(sc, count)    (sc)->opackets = (count)
    650 #define IXGBE_SET_OERRORS(sc, count)     (sc)->oerrors = (count)
    651 #define IXGBE_SET_COLLISIONS(sc, count)
    652 #define IXGBE_SET_IBYTES(sc, count)      (sc)->ibytes = (count)
    653 #define IXGBE_SET_OBYTES(sc, count)      (sc)->obytes = (count)
    654 #define IXGBE_SET_IMCASTS(sc, count)     (sc)->imcasts = (count)
    655 #define IXGBE_SET_OMCASTS(sc, count)     (sc)->omcasts = (count)
    656 #define IXGBE_SET_IQDROPS(sc, count)     (sc)->iqdrops = (count)
    657 #else
    658 #define IXGBE_SET_IERRORS(sc, count)     (sc)->ifp->if_ierrors = (count)
    659 #define IXGBE_SET_OPACKETS(sc, count)    (sc)->ifp->if_opackets = (count)
    660 #define IXGBE_SET_OERRORS(sc, count)     (sc)->ifp->if_oerrors = (count)
    661 #define IXGBE_SET_COLLISIONS(sc, count)  (sc)->ifp->if_collisions = (count)
    662 #define IXGBE_SET_IBYTES(sc, count)      (sc)->ifp->if_ibytes = (count)
    663 #define IXGBE_SET_OBYTES(sc, count)      (sc)->ifp->if_obytes = (count)
    664 #define IXGBE_SET_IMCASTS(sc, count)     (sc)->ifp->if_imcasts = (count)
    665 #define IXGBE_SET_OMCASTS(sc, count)     (sc)->ifp->if_omcasts = (count)
    666 #define IXGBE_SET_IQDROPS(sc, count)     (sc)->ifp->if_iqdrops = (count)
    667 #endif
    668 
    669 /* External PHY register addresses */
    670 #define IXGBE_PHY_CURRENT_TEMP		0xC820
    671 #define IXGBE_PHY_OVERTEMP_STATUS	0xC830
    672 
    673 /* Sysctl help messages; displayed with sysctl -d */
    674 #define IXGBE_SYSCTL_DESC_ADV_SPEED \
    675 	"\nControl advertised link speed using these flags:\n" \
    676 	"\t0x01 - advertise 100M\n" \
    677 	"\t0x02 - advertise 1G\n" \
    678 	"\t0x04 - advertise 10G\n" \
    679 	"\t0x08 - advertise 10M\n" \
    680 	"\t0x10 - advertise 2.5G\n" \
    681 	"\t0x20 - advertise 5G\n\n" \
    682 	"\t5G, 2.5G, 100M and 10M are only supported on certain adapters."
    683 
    684 #define IXGBE_SYSCTL_DESC_SET_FC \
    685 	"\nSet flow control mode using these values:\n" \
    686 	"\t0 - off\n" \
    687 	"\t1 - rx pause\n" \
    688 	"\t2 - tx pause\n" \
    689 	"\t3 - tx and rx pause"
    690 
    691 /* Workaround to make 8.0 buildable */
    692 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
    693 static __inline int
    694 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
    695 {
    696 #ifdef ALTQ
    697 	if (ALTQ_IS_ENABLED(&ifp->if_snd))
    698 		return (1);
    699 #endif
    700 	return (!buf_ring_empty(br));
    701 }
    702 #endif
    703 
    704 /*
    705  * Find the number of unrefreshed RX descriptors
    706  */
    707 static __inline u16
    708 ixgbe_rx_unrefreshed(struct rx_ring *rxr)
    709 {
    710 	if (rxr->next_to_check > rxr->next_to_refresh)
    711 		return (rxr->next_to_check - rxr->next_to_refresh - 1);
    712 	else
    713 		return ((rxr->num_desc + rxr->next_to_check) -
    714 		    rxr->next_to_refresh - 1);
    715 }
    716 
    717 static __inline int
    718 ixgbe_legacy_ring_empty(struct ifnet *ifp, pcq_t *dummy)
    719 {
    720 	UNREFERENCED_1PARAMETER(dummy);
    721 
    722 	return IFQ_IS_EMPTY(&ifp->if_snd);
    723 }
    724 
    725 static __inline int
    726 ixgbe_mq_ring_empty(struct ifnet *dummy, pcq_t *interq)
    727 {
    728 	UNREFERENCED_1PARAMETER(dummy);
    729 
    730 	return (pcq_peek(interq) == NULL);
    731 }
    732 
    733 /*
    734  * This checks for a zero mac addr, something that will be likely
    735  * unless the Admin on the Host has created one.
    736  */
    737 static __inline bool
    738 ixv_check_ether_addr(u8 *addr)
    739 {
    740 	bool status = TRUE;
    741 
    742 	if ((addr[0] == 0 && addr[1]== 0 && addr[2] == 0 &&
    743 	    addr[3] == 0 && addr[4]== 0 && addr[5] == 0))
    744 		status = FALSE;
    745 
    746 	return (status);
    747 }
    748 
    749 /*
    750  * This checks the adapter->recovery_mode software flag which is
    751  * set by ixgbe_fw_recovery_mode().
    752  *
    753  */
    754 static inline bool
    755 ixgbe_fw_recovery_mode_swflag(struct adapter *adapter)
    756 {
    757 	return (adapter->feat_en & IXGBE_FEATURE_RECOVERY_MODE) &&
    758 	    atomic_load_acq_uint(&adapter->recovery_mode);
    759 }
    760 
    761 /* Shared Prototypes */
    762 void ixgbe_legacy_start(struct ifnet *);
    763 int  ixgbe_legacy_start_locked(struct ifnet *, struct tx_ring *);
    764 int  ixgbe_mq_start(struct ifnet *, struct mbuf *);
    765 int  ixgbe_mq_start_locked(struct ifnet *, struct tx_ring *);
    766 void ixgbe_deferred_mq_start(void *);
    767 void ixgbe_deferred_mq_start_work(struct work *, void *);
    768 void ixgbe_drain_all(struct adapter *);
    769 
    770 int  ixgbe_allocate_queues(struct adapter *);
    771 void ixgbe_free_queues(struct adapter *);
    772 int  ixgbe_setup_transmit_structures(struct adapter *);
    773 void ixgbe_free_transmit_structures(struct adapter *);
    774 int  ixgbe_setup_receive_structures(struct adapter *);
    775 void ixgbe_free_receive_structures(struct adapter *);
    776 bool ixgbe_txeof(struct tx_ring *);
    777 bool ixgbe_rxeof(struct ix_queue *);
    778 
    779 const struct sysctlnode *ixgbe_sysctl_instance(struct adapter *);
    780 
    781 /* For NetBSD */
    782 void ixgbe_jcl_reinit(struct adapter *, bus_dma_tag_t, struct rx_ring *,
    783     int, size_t);
    784 void ixgbe_jcl_destroy(struct adapter *,  struct rx_ring *);
    785 
    786 #include "ixgbe_bypass.h"
    787 #include "ixgbe_fdir.h"
    788 #include "ixgbe_rss.h"
    789 #include "ixgbe_netmap.h"
    790 
    791 #endif /* _IXGBE_H_ */
    792