Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe.h revision 1.33
      1 /* $NetBSD: ixgbe.h,v 1.33 2018/03/06 03:47:23 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 320688 2017-07-05 17:27:03Z 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/bpf.h>
     93 #include <net/if_types.h>
     94 #include <net/if_vlanvar.h>
     95 
     96 #include <netinet/in_systm.h>
     97 #include <netinet/in.h>
     98 #include <netinet/ip.h>
     99 #include <netinet/ip6.h>
    100 #include <netinet/tcp.h>
    101 #include <netinet/udp.h>
    102 
    103 #include <sys/bus.h>
    104 #include <dev/pci/pcivar.h>
    105 #include <dev/pci/pcireg.h>
    106 #include <sys/proc.h>
    107 #include <sys/sysctl.h>
    108 #include <sys/endian.h>
    109 #include <sys/workqueue.h>
    110 #include <sys/cpu.h>
    111 #include <sys/interrupt.h>
    112 #include <sys/bitops.h>
    113 
    114 #include "ixgbe_netbsd.h"
    115 #include "ixgbe_api.h"
    116 #include "ixgbe_common.h"
    117 #include "ixgbe_phy.h"
    118 #include "ixgbe_vf.h"
    119 #include "ixgbe_features.h"
    120 
    121 /* Tunables */
    122 
    123 /*
    124  * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
    125  * number of transmit descriptors allocated by the driver. Increasing this
    126  * value allows the driver to queue more transmits. Each descriptor is 16
    127  * bytes. Performance tests have show the 2K value to be optimal for top
    128  * performance.
    129  */
    130 #define DEFAULT_TXD	1024
    131 #define PERFORM_TXD	2048
    132 #define MAX_TXD		4096
    133 #define MIN_TXD		64
    134 
    135 /*
    136  * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
    137  * number of receive descriptors allocated for each RX queue. Increasing this
    138  * value allows the driver to buffer more incoming packets. Each descriptor
    139  * is 16 bytes.  A receive buffer is also allocated for each descriptor.
    140  *
    141  * Note: with 8 rings and a dual port card, it is possible to bump up
    142  *	against the system mbuf pool limit, you can tune nmbclusters
    143  *	to adjust for this.
    144  */
    145 #define DEFAULT_RXD	1024
    146 #define PERFORM_RXD	2048
    147 #define MAX_RXD		4096
    148 #define MIN_RXD		64
    149 
    150 /* Alignment for rings */
    151 #define DBA_ALIGN	128
    152 
    153 /*
    154  * This is the max watchdog interval, ie. the time that can
    155  * pass between any two TX clean operations, such only happening
    156  * when the TX hardware is functioning.
    157  */
    158 #define IXGBE_WATCHDOG  (10 * hz)
    159 
    160 /*
    161  * This parameters control when the driver calls the routine to reclaim
    162  * transmit descriptors.
    163  */
    164 #define IXGBE_TX_CLEANUP_THRESHOLD(_a)  ((_a)->num_tx_desc / 8)
    165 #define IXGBE_TX_OP_THRESHOLD(_a)       ((_a)->num_tx_desc / 32)
    166 
    167 /* These defines are used in MTU calculations */
    168 #define IXGBE_MAX_FRAME_SIZE  9728
    169 #define IXGBE_MTU_HDR         (ETHER_HDR_LEN + ETHER_CRC_LEN)
    170 #define IXGBE_MTU_HDR_VLAN    (ETHER_HDR_LEN + ETHER_CRC_LEN + \
    171                                ETHER_VLAN_ENCAP_LEN)
    172 #define IXGBE_MAX_MTU         (IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR)
    173 #define IXGBE_MAX_MTU_VLAN    (IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR_VLAN)
    174 
    175 /* Flow control constants */
    176 #define IXGBE_FC_PAUSE        0xFFFF
    177 #define IXGBE_FC_HI           0x20000
    178 #define IXGBE_FC_LO           0x10000
    179 
    180 /*
    181  * Used for optimizing small rx mbufs.  Effort is made to keep the copy
    182  * small and aligned for the CPU L1 cache.
    183  *
    184  * MHLEN is typically 168 bytes, giving us 8-byte alignment.  Getting
    185  * 32 byte alignment needed for the fast bcopy results in 8 bytes being
    186  * wasted.  Getting 64 byte alignment, which _should_ be ideal for
    187  * modern Intel CPUs, results in 40 bytes wasted and a significant drop
    188  * in observed efficiency of the optimization, 97.9% -> 81.8%.
    189  */
    190 #define	MPKTHSIZE		(offsetof(struct _mbuf_dummy, m_pktdat))
    191 #define IXGBE_RX_COPY_HDR_PADDED  ((((MPKTHSIZE - 1) / 32) + 1) * 32)
    192 #define IXGBE_RX_COPY_LEN         (MSIZE - IXGBE_RX_COPY_HDR_PADDED)
    193 #define IXGBE_RX_COPY_ALIGN       (IXGBE_RX_COPY_HDR_PADDED - MPKTHSIZE)
    194 
    195 /* Keep older OS drivers building... */
    196 #if !defined(SYSCTL_ADD_UQUAD)
    197 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
    198 #endif
    199 
    200 /* Defines for printing debug information */
    201 #define DEBUG_INIT  0
    202 #define DEBUG_IOCTL 0
    203 #define DEBUG_HW    0
    204 
    205 #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
    206 #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
    207 #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
    208 #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
    209 #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
    210 #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
    211 #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
    212 #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
    213 #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
    214 
    215 #define MAX_NUM_MULTICAST_ADDRESSES     128
    216 #define IXGBE_82598_SCATTER             100
    217 #define IXGBE_82599_SCATTER             32
    218 #define MSIX_82598_BAR                  3
    219 #define MSIX_82599_BAR                  4
    220 #define IXGBE_TSO_SIZE                  262140
    221 #define IXGBE_RX_HDR                    128
    222 #define IXGBE_VFTA_SIZE                 128
    223 #define IXGBE_BR_SIZE                   4096
    224 #define IXGBE_QUEUE_MIN_FREE            32
    225 #define IXGBE_MAX_TX_BUSY               10
    226 #define IXGBE_QUEUE_HUNG                0x80000000
    227 
    228 #define IXGBE_EITR_DEFAULT		128
    229 
    230 /* IOCTL define to gather SFP+ Diagnostic data */
    231 #define SIOCGI2C	SIOCGIFGENERIC
    232 
    233 /* Offload bits in mbuf flag */
    234 #define	M_CSUM_OFFLOAD	\
    235     (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4|M_CSUM_UDPv6|M_CSUM_TCPv6)
    236 
    237 /* Backward compatibility items for very old versions */
    238 #ifndef pci_find_cap
    239 #define pci_find_cap pci_find_extcap
    240 #endif
    241 
    242 #ifndef DEVMETHOD_END
    243 #define DEVMETHOD_END { NULL, NULL }
    244 #endif
    245 
    246 /*
    247  * Interrupt Moderation parameters
    248  */
    249 #define IXGBE_LOW_LATENCY	128
    250 #define IXGBE_AVE_LATENCY	400
    251 #define IXGBE_BULK_LATENCY	1200
    252 
    253 /* Using 1FF (the max value), the interval is ~1.05ms */
    254 #define IXGBE_LINK_ITR_QUANTA  0x1FF
    255 #define IXGBE_LINK_ITR         ((IXGBE_LINK_ITR_QUANTA << 3) & \
    256                                 IXGBE_EITR_ITR_INT_MASK)
    257 
    258 
    259 
    260 /************************************************************************
    261  * vendor_info_array
    262  *
    263  *   Contains the list of Subvendor/Subdevice IDs on
    264  *   which the driver should load.
    265  ************************************************************************/
    266 typedef struct _ixgbe_vendor_info_t {
    267 	unsigned int vendor_id;
    268 	unsigned int device_id;
    269 	unsigned int subvendor_id;
    270 	unsigned int subdevice_id;
    271 	unsigned int index;
    272 } ixgbe_vendor_info_t;
    273 
    274 /* This is used to get SFP+ module data */
    275 struct ixgbe_i2c_req {
    276         u8 dev_addr;
    277         u8 offset;
    278         u8 len;
    279         u8 data[8];
    280 };
    281 
    282 struct ixgbe_bp_data {
    283 	u32 low;
    284 	u32 high;
    285 	u32 log;
    286 };
    287 
    288 struct ixgbe_tx_buf {
    289 	union ixgbe_adv_tx_desc	*eop;
    290 	struct mbuf             *m_head;
    291 	bus_dmamap_t            map;
    292 };
    293 
    294 struct ixgbe_rx_buf {
    295 	struct mbuf    *buf;
    296 	struct mbuf    *fmp;
    297 	bus_dmamap_t   pmap;
    298 	u_int          flags;
    299 #define IXGBE_RX_COPY  0x01
    300 	uint64_t       addr;
    301 };
    302 
    303 /*
    304  * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free
    305  */
    306 struct ixgbe_dma_alloc {
    307 	bus_addr_t        dma_paddr;
    308 	void              *dma_vaddr;
    309 	ixgbe_dma_tag_t   *dma_tag;
    310 	bus_dmamap_t      dma_map;
    311 	bus_dma_segment_t dma_seg;
    312 	bus_size_t        dma_size;
    313 };
    314 
    315 struct ixgbe_mc_addr {
    316 	u8  addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
    317 	u32 vmdq;
    318 };
    319 
    320 /*
    321  * Driver queue struct: this is the interrupt container
    322  *                      for the associated tx and rx ring.
    323  */
    324 struct ix_queue {
    325 	struct adapter   *adapter;
    326 	u32              msix;           /* This queue's MSI-X vector */
    327 	u32              eims;           /* This queue's EIMS bit */
    328 	u32              eitr_setting;
    329 	u32              me;
    330 	struct resource  *res;
    331 	void             *tag;
    332 	int              busy;
    333 	struct tx_ring   *txr;
    334 	struct rx_ring   *rxr;
    335 	struct work      wq_cookie;
    336 	void             *que_si;
    337 	struct evcnt     irqs;
    338 	char             namebuf[32];
    339 	char             evnamebuf[32];
    340 
    341 	kmutex_t         im_mtx;	/* lock for im_nest and this queue's EIMS/EIMC bit */
    342 	int              im_nest;
    343 };
    344 
    345 /*
    346  * The transmit ring, one per queue
    347  */
    348 struct tx_ring {
    349         struct adapter		*adapter;
    350 	kmutex_t		tx_mtx;
    351 	u32			me;
    352 	u32			tail;
    353 	int			busy;
    354 	union ixgbe_adv_tx_desc	*tx_base;
    355 	struct ixgbe_tx_buf	*tx_buffers;
    356 	struct ixgbe_dma_alloc	txdma;
    357 	volatile u16		tx_avail;
    358 	u16			next_avail_desc;
    359 	u16			next_to_clean;
    360 	u16			num_desc;
    361 	u32			txd_cmd;
    362 	ixgbe_dma_tag_t		*txtag;
    363 	char			mtx_name[16];
    364 	pcq_t			*txr_interq;
    365 	struct work		wq_cookie;
    366 	void			*txr_si;
    367 
    368 	/* Flow Director */
    369 	u16			atr_sample;
    370 	u16			atr_count;
    371 
    372 	u32			bytes;  /* used for AIM */
    373 	u32			packets;
    374 	/* Soft Stats */
    375 	struct evcnt	   	tso_tx;
    376 	struct evcnt		no_desc_avail;
    377 	struct evcnt		total_packets;
    378 	struct evcnt		pcq_drops;
    379 };
    380 
    381 
    382 /*
    383  * The Receive ring, one per rx queue
    384  */
    385 struct rx_ring {
    386         struct adapter		*adapter;
    387 	kmutex_t		rx_mtx;
    388 	u32			me;
    389 	u32			tail;
    390 	union ixgbe_adv_rx_desc	*rx_base;
    391 	struct ixgbe_dma_alloc	rxdma;
    392 #ifdef LRO
    393 	struct lro_ctrl		lro;
    394 #endif /* LRO */
    395 	bool			lro_enabled;
    396 	bool			hw_rsc;
    397 	bool			vtag_strip;
    398         u16			next_to_refresh;
    399         u16 			next_to_check;
    400 	u16			num_desc;
    401 	u16			mbuf_sz;
    402 	char			mtx_name[16];
    403 	struct ixgbe_rx_buf	*rx_buffers;
    404 	ixgbe_dma_tag_t		*ptag;
    405 
    406 	u32			bytes; /* Used for AIM calc */
    407 	u32			packets;
    408 
    409 	/* Soft stats */
    410 	struct evcnt		rx_copies;
    411 	struct evcnt		rx_packets;
    412 	struct evcnt 		rx_bytes;
    413 	struct evcnt 		rx_discarded;
    414 	struct evcnt 		no_jmbuf;
    415 	u64 			rsc_num;
    416 
    417 	/* Flow Director */
    418 	u64			flm;
    419 };
    420 
    421 #define IXGBE_MAX_VF_MC 30  /* Max number of multicast entries */
    422 
    423 struct ixgbe_vf {
    424 	u_int    pool;
    425 	u_int    rar_index;
    426 	u_int    max_frame_size;
    427 	uint32_t flags;
    428 	uint8_t  ether_addr[ETHER_ADDR_LEN];
    429 	uint16_t mc_hash[IXGBE_MAX_VF_MC];
    430 	uint16_t num_mc_hashes;
    431 	uint16_t default_vlan;
    432 	uint16_t vlan_tag;
    433 	uint16_t api_ver;
    434 };
    435 
    436 /* Our adapter structure */
    437 struct adapter {
    438 	struct ixgbe_hw		hw;
    439 	struct ixgbe_osdep	osdep;
    440 
    441 	device_t		dev;
    442 	struct ifnet		*ifp;
    443 	struct if_percpuq	*ipq;	/* softint-based input queues */
    444 
    445 	struct resource		*pci_mem;
    446 	struct resource		*msix_mem;
    447 
    448 	/*
    449 	 * Interrupt resources: this set is
    450 	 * either used for legacy, or for Link
    451 	 * when doing MSI-X
    452 	 */
    453 	void			*tag;
    454 	struct resource 	*res;
    455 
    456 	struct ifmedia		media;
    457 	callout_t		timer;
    458 	int			link_rid;
    459 	int			if_flags;
    460 
    461 	kmutex_t		core_mtx;
    462 
    463 	unsigned int		num_queues;
    464 
    465 	/*
    466 	 * Shadow VFTA table, this is needed because
    467 	 * the real vlan filter table gets cleared during
    468 	 * a soft reset and the driver needs to be able
    469 	 * to repopulate it.
    470 	 */
    471 	u32			shadow_vfta[IXGBE_VFTA_SIZE];
    472 
    473 	/* Info about the interface */
    474 	int			advertise;  /* link speeds */
    475 	bool			enable_aim; /* adaptive interrupt moderation */
    476 	bool			link_active;
    477 	u16			max_frame_size;
    478 	u16			num_segs;
    479 	u32			link_speed;
    480 	bool			link_up;
    481 	u32 			vector;
    482 	u16			dmac;
    483 	u32			phy_layer;
    484 
    485 	/* Power management-related */
    486 	bool			wol_support;
    487 	u32			wufc;
    488 
    489 	/* Mbuf cluster size */
    490 	u32			rx_mbuf_sz;
    491 
    492 	/* Support for pluggable optics */
    493 	bool			sfp_probe;
    494 	void			*link_si;  /* Link tasklet */
    495 	void			*mod_si;   /* SFP tasklet */
    496 	void			*msf_si;   /* Multispeed Fiber */
    497 	void			*mbx_si;   /* VF -> PF mailbox interrupt */
    498 
    499 	/* Flow Director */
    500 	int			fdir_reinit;
    501 	void			*fdir_si;
    502 
    503 	void			*phy_si;   /* PHY intr tasklet */
    504 
    505 	bool			txrx_use_workqueue;
    506 	struct workqueue	*que_wq;    /* workqueue for ixgbe_handle_que_work() */
    507 					    /*
    508 					     * que_wq's "enqueued flag" is not required,
    509 					     * because twice workqueue_enqueue() for
    510 					     * ixgbe_handle_que_work() is avoided by masking
    511 					     * the queue's interrupt by EIMC.
    512 					     * See also ixgbe_msix_que().
    513 					     */
    514 	struct workqueue	*txr_wq;    /* workqueue for ixgbe_deferred_mq_start_work() */
    515 	percpu_t		*txr_wq_enqueued;
    516 
    517 	/*
    518 	 * Queues:
    519 	 *   This is the irq holder, it has
    520 	 *   and RX/TX pair or rings associated
    521 	 *   with it.
    522 	 */
    523 	struct ix_queue		*queues;
    524 
    525 	/*
    526 	 * Transmit rings
    527 	 *      Allocated at run time, an array of rings
    528 	 */
    529 	struct tx_ring		*tx_rings;
    530 	u32			num_tx_desc;
    531 	u32			tx_process_limit;
    532 
    533 	/*
    534 	 * Receive rings
    535 	 *      Allocated at run time, an array of rings
    536 	 */
    537 	struct rx_ring		*rx_rings;
    538 	u64			active_queues;
    539 	u32			num_rx_desc;
    540 	u32			rx_process_limit;
    541 
    542 	/* Multicast array memory */
    543 	struct ixgbe_mc_addr	*mta;
    544 
    545 	/* SR-IOV */
    546 	int                     iov_mode;
    547 	int			num_vfs;
    548 	int			pool;
    549 	struct ixgbe_vf		*vfs;
    550 
    551 	/* Bypass */
    552 	struct ixgbe_bp_data    bypass;
    553 
    554 	/* Netmap */
    555 	void 			(*init_locked)(struct adapter *);
    556 	void 			(*stop_locked)(void *);
    557 
    558 	/* Misc stats maintained by the driver */
    559 	struct evcnt   		mbuf_defrag_failed;
    560 	struct evcnt	   	efbig_tx_dma_setup;
    561 	struct evcnt	   	efbig2_tx_dma_setup;
    562 	struct evcnt	   	einval_tx_dma_setup;
    563 	struct evcnt	   	other_tx_dma_setup;
    564 	struct evcnt	   	eagain_tx_dma_setup;
    565 	struct evcnt	   	enomem_tx_dma_setup;
    566 	struct evcnt	   	tso_err;
    567 	struct evcnt	   	watchdog_events;
    568 	struct evcnt		link_irq;
    569 	struct evcnt		handleq;
    570 	struct evcnt		req;
    571 
    572 	union {
    573 		struct ixgbe_hw_stats pf;
    574 		struct ixgbevf_hw_stats	vf;
    575 	} stats;
    576 #if __FreeBSD_version >= 1100036
    577 	/* counter(9) stats */
    578 	u64			ipackets;
    579 	u64			ierrors;
    580 	u64			opackets;
    581 	u64			oerrors;
    582 	u64			ibytes;
    583 	u64			obytes;
    584 	u64			imcasts;
    585 	u64			omcasts;
    586 	u64			iqdrops;
    587 	u64			noproto;
    588 #endif
    589 	/* Feature capable/enabled flags.  See ixgbe_features.h */
    590 	u32                     feat_cap;
    591 	u32                     feat_en;
    592 
    593 	struct sysctllog	*sysctllog;
    594 	const struct sysctlnode *sysctltop;
    595 	ixgbe_extmem_head_t jcl_head;
    596 };
    597 
    598 
    599 /* Precision Time Sync (IEEE 1588) defines */
    600 #define ETHERTYPE_IEEE1588      0x88F7
    601 #define PICOSECS_PER_TICK       20833
    602 #define TSYNC_UDP_PORT          319 /* UDP port for the protocol */
    603 #define IXGBE_ADVTXD_TSTAMP     0x00080000
    604 
    605 
    606 #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
    607         mutex_init(&(_sc)->core_mtx, MUTEX_DEFAULT, IPL_SOFTNET)
    608 #define IXGBE_CORE_LOCK_DESTROY(_sc)      mutex_destroy(&(_sc)->core_mtx)
    609 #define IXGBE_TX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->tx_mtx)
    610 #define IXGBE_RX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->rx_mtx)
    611 #define IXGBE_CORE_LOCK(_sc)              mutex_enter(&(_sc)->core_mtx)
    612 #define IXGBE_TX_LOCK(_sc)                mutex_enter(&(_sc)->tx_mtx)
    613 #define IXGBE_TX_TRYLOCK(_sc)             mutex_tryenter(&(_sc)->tx_mtx)
    614 #define IXGBE_RX_LOCK(_sc)                mutex_enter(&(_sc)->rx_mtx)
    615 #define IXGBE_CORE_UNLOCK(_sc)            mutex_exit(&(_sc)->core_mtx)
    616 #define IXGBE_TX_UNLOCK(_sc)              mutex_exit(&(_sc)->tx_mtx)
    617 #define IXGBE_RX_UNLOCK(_sc)              mutex_exit(&(_sc)->rx_mtx)
    618 #define IXGBE_CORE_LOCK_ASSERT(_sc)       KASSERT(mutex_owned(&(_sc)->core_mtx))
    619 #define IXGBE_TX_LOCK_ASSERT(_sc)         KASSERT(mutex_owned(&(_sc)->tx_mtx))
    620 
    621 /* Stats macros */
    622 #if __FreeBSD_version >= 1100036
    623 #define IXGBE_SET_IPACKETS(sc, count)    (sc)->ipackets = (count)
    624 #define IXGBE_SET_IERRORS(sc, count)     (sc)->ierrors = (count)
    625 #define IXGBE_SET_OPACKETS(sc, count)    (sc)->opackets = (count)
    626 #define IXGBE_SET_OERRORS(sc, count)     (sc)->oerrors = (count)
    627 #define IXGBE_SET_COLLISIONS(sc, count)
    628 #define IXGBE_SET_IBYTES(sc, count)      (sc)->ibytes = (count)
    629 #define IXGBE_SET_OBYTES(sc, count)      (sc)->obytes = (count)
    630 #define IXGBE_SET_IMCASTS(sc, count)     (sc)->imcasts = (count)
    631 #define IXGBE_SET_OMCASTS(sc, count)     (sc)->omcasts = (count)
    632 #define IXGBE_SET_IQDROPS(sc, count)     (sc)->iqdrops = (count)
    633 #else
    634 #define IXGBE_SET_IPACKETS(sc, count)    (sc)->ifp->if_ipackets = (count)
    635 #define IXGBE_SET_IERRORS(sc, count)     (sc)->ifp->if_ierrors = (count)
    636 #define IXGBE_SET_OPACKETS(sc, count)    (sc)->ifp->if_opackets = (count)
    637 #define IXGBE_SET_OERRORS(sc, count)     (sc)->ifp->if_oerrors = (count)
    638 #define IXGBE_SET_COLLISIONS(sc, count)  (sc)->ifp->if_collisions = (count)
    639 #define IXGBE_SET_IBYTES(sc, count)      (sc)->ifp->if_ibytes = (count)
    640 #define IXGBE_SET_OBYTES(sc, count)      (sc)->ifp->if_obytes = (count)
    641 #define IXGBE_SET_IMCASTS(sc, count)     (sc)->ifp->if_imcasts = (count)
    642 #define IXGBE_SET_OMCASTS(sc, count)     (sc)->ifp->if_omcasts = (count)
    643 #define IXGBE_SET_IQDROPS(sc, count)     (sc)->ifp->if_iqdrops = (count)
    644 #endif
    645 
    646 /* External PHY register addresses */
    647 #define IXGBE_PHY_CURRENT_TEMP		0xC820
    648 #define IXGBE_PHY_OVERTEMP_STATUS	0xC830
    649 
    650 /* Sysctl help messages; displayed with sysctl -d */
    651 #define IXGBE_SYSCTL_DESC_ADV_SPEED \
    652 	"\nControl advertised link speed using these flags:\n" \
    653 	"\t0x01 - advertise 100M\n" \
    654 	"\t0x02 - advertise 1G\n" \
    655         "\t0x04 - advertise 10G\n" \
    656         "\t0x08 - advertise 10M\n" \
    657         "\t0x10 - advertise 2.5G\n" \
    658         "\t0x20 - advertise 5G\n\n" \
    659         "\t5G, 2.5G, 100M and 10M are only supported on certain adapters."
    660 
    661 #define IXGBE_SYSCTL_DESC_SET_FC \
    662 	"\nSet flow control mode using these values:\n" \
    663 	"\t0 - off\n" \
    664 	"\t1 - rx pause\n" \
    665 	"\t2 - tx pause\n" \
    666 	"\t3 - tx and rx pause"
    667 
    668 /* Workaround to make 8.0 buildable */
    669 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
    670 static __inline int
    671 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
    672 {
    673 #ifdef ALTQ
    674         if (ALTQ_IS_ENABLED(&ifp->if_snd))
    675                 return (1);
    676 #endif
    677         return (!buf_ring_empty(br));
    678 }
    679 #endif
    680 
    681 /*
    682  * Find the number of unrefreshed RX descriptors
    683  */
    684 static inline u16
    685 ixgbe_rx_unrefreshed(struct rx_ring *rxr)
    686 {
    687 	if (rxr->next_to_check > rxr->next_to_refresh)
    688 		return (rxr->next_to_check - rxr->next_to_refresh - 1);
    689 	else
    690 		return ((rxr->num_desc + rxr->next_to_check) -
    691 		    rxr->next_to_refresh - 1);
    692 }
    693 
    694 static inline int
    695 ixgbe_legacy_ring_empty(struct ifnet *ifp, pcq_t *dummy)
    696 {
    697 	UNREFERENCED_1PARAMETER(dummy);
    698 
    699 	return IFQ_IS_EMPTY(&ifp->if_snd);
    700 }
    701 
    702 static inline int
    703 ixgbe_mq_ring_empty(struct ifnet *dummy, pcq_t *interq)
    704 {
    705 	UNREFERENCED_1PARAMETER(dummy);
    706 
    707 	return (pcq_peek(interq) == NULL);
    708 }
    709 
    710 /*
    711  * This checks for a zero mac addr, something that will be likely
    712  * unless the Admin on the Host has created one.
    713  */
    714 static inline bool
    715 ixv_check_ether_addr(u8 *addr)
    716 {
    717 	bool status = TRUE;
    718 
    719 	if ((addr[0] == 0 && addr[1]== 0 && addr[2] == 0 &&
    720 	    addr[3] == 0 && addr[4]== 0 && addr[5] == 0))
    721 		status = FALSE;
    722 
    723 	return (status);
    724 }
    725 
    726 /* Shared Prototypes */
    727 void ixgbe_legacy_start(struct ifnet *);
    728 int  ixgbe_legacy_start_locked(struct ifnet *, struct tx_ring *);
    729 int  ixgbe_mq_start(struct ifnet *, struct mbuf *);
    730 int  ixgbe_mq_start_locked(struct ifnet *, struct tx_ring *);
    731 void ixgbe_deferred_mq_start(void *);
    732 void ixgbe_deferred_mq_start_work(struct work *, void *);
    733 
    734 int  ixgbe_allocate_queues(struct adapter *);
    735 int  ixgbe_setup_transmit_structures(struct adapter *);
    736 void ixgbe_free_transmit_structures(struct adapter *);
    737 int  ixgbe_setup_receive_structures(struct adapter *);
    738 void ixgbe_free_receive_structures(struct adapter *);
    739 bool ixgbe_txeof(struct tx_ring *);
    740 bool ixgbe_rxeof(struct ix_queue *);
    741 
    742 const struct sysctlnode *ixgbe_sysctl_instance(struct adapter *);
    743 
    744 #include "ixgbe_bypass.h"
    745 #include "ixgbe_sriov.h"
    746 #include "ixgbe_fdir.h"
    747 #include "ixgbe_rss.h"
    748 #include "ixgbe_netmap.h"
    749 
    750 #endif /* _IXGBE_H_ */
    751