Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe.h revision 1.11
      1   1.1    dyoung /******************************************************************************
      2   1.1    dyoung 
      3  1.11   msaitoh   Copyright (c) 2001-2015, Intel Corporation
      4   1.1    dyoung   All rights reserved.
      5   1.1    dyoung 
      6   1.1    dyoung   Redistribution and use in source and binary forms, with or without
      7   1.1    dyoung   modification, are permitted provided that the following conditions are met:
      8   1.1    dyoung 
      9   1.1    dyoung    1. Redistributions of source code must retain the above copyright notice,
     10   1.1    dyoung       this list of conditions and the following disclaimer.
     11   1.1    dyoung 
     12   1.1    dyoung    2. Redistributions in binary form must reproduce the above copyright
     13   1.1    dyoung       notice, this list of conditions and the following disclaimer in the
     14   1.1    dyoung       documentation and/or other materials provided with the distribution.
     15   1.1    dyoung 
     16   1.1    dyoung    3. Neither the name of the Intel Corporation nor the names of its
     17   1.1    dyoung       contributors may be used to endorse or promote products derived from
     18   1.1    dyoung       this software without specific prior written permission.
     19   1.1    dyoung 
     20   1.1    dyoung   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     21   1.1    dyoung   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22   1.1    dyoung   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23   1.1    dyoung   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     24   1.1    dyoung   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.1    dyoung   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.1    dyoung   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.1    dyoung   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.1    dyoung   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.1    dyoung   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1    dyoung   POSSIBILITY OF SUCH DAMAGE.
     31   1.1    dyoung 
     32   1.1    dyoung ******************************************************************************/
     33   1.1    dyoung /*
     34   1.1    dyoung  * Copyright (c) 2011 The NetBSD Foundation, Inc.
     35   1.1    dyoung  * All rights reserved.
     36   1.1    dyoung  *
     37   1.1    dyoung  * This code is derived from software contributed to The NetBSD Foundation
     38   1.1    dyoung  * by Coyote Point Systems, Inc.
     39   1.1    dyoung  *
     40   1.1    dyoung  * Redistribution and use in source and binary forms, with or without
     41   1.1    dyoung  * modification, are permitted provided that the following conditions
     42   1.1    dyoung  * are met:
     43   1.1    dyoung  * 1. Redistributions of source code must retain the above copyright
     44   1.1    dyoung  *    notice, this list of conditions and the following disclaimer.
     45   1.1    dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     46   1.1    dyoung  *    notice, this list of conditions and the following disclaimer in the
     47   1.1    dyoung  *    documentation and/or other materials provided with the distribution.
     48   1.1    dyoung  *
     49   1.1    dyoung  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     50   1.1    dyoung  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     51   1.1    dyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     52   1.1    dyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     53   1.1    dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     54   1.1    dyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     55   1.1    dyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     56   1.1    dyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     57   1.1    dyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     58   1.1    dyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     59   1.1    dyoung  * POSSIBILITY OF SUCH DAMAGE.
     60   1.1    dyoung  */
     61  1.11   msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixgbe.h 280182 2015-03-17 18:32:28Z jfv $*/
     62  1.11   msaitoh /*$NetBSD: ixgbe.h,v 1.11 2016/12/01 06:27:18 msaitoh Exp $*/
     63   1.1    dyoung 
     64   1.1    dyoung 
     65   1.1    dyoung #ifndef _IXGBE_H_
     66   1.1    dyoung #define _IXGBE_H_
     67   1.1    dyoung 
     68   1.1    dyoung 
     69   1.1    dyoung #include <sys/param.h>
     70   1.1    dyoung #include <sys/reboot.h>
     71   1.1    dyoung #include <sys/systm.h>
     72   1.1    dyoung #if __FreeBSD_version >= 800000
     73   1.1    dyoung #include <sys/buf_ring.h>
     74   1.1    dyoung #endif
     75   1.1    dyoung #include <sys/mbuf.h>
     76   1.1    dyoung #include <sys/protosw.h>
     77   1.1    dyoung #include <sys/socket.h>
     78   1.1    dyoung #include <sys/malloc.h>
     79   1.1    dyoung #include <sys/kernel.h>
     80   1.1    dyoung #include <sys/module.h>
     81   1.1    dyoung #include <sys/sockio.h>
     82   1.1    dyoung 
     83   1.1    dyoung #include <net/if.h>
     84   1.1    dyoung #include <net/if_arp.h>
     85   1.1    dyoung #include <net/bpf.h>
     86   1.1    dyoung #include <net/if_ether.h>
     87   1.1    dyoung #include <net/if_dl.h>
     88   1.1    dyoung #include <net/if_media.h>
     89   1.1    dyoung 
     90   1.1    dyoung #include <net/bpf.h>
     91   1.1    dyoung #include <net/if_types.h>
     92   1.1    dyoung #include <net/if_vlanvar.h>
     93   1.1    dyoung 
     94   1.1    dyoung #include <netinet/in_systm.h>
     95   1.1    dyoung #include <netinet/in.h>
     96   1.1    dyoung #include <netinet/ip.h>
     97   1.1    dyoung #include <netinet/ip6.h>
     98   1.1    dyoung #include <netinet/tcp.h>
     99   1.1    dyoung #include <netinet/udp.h>
    100   1.1    dyoung 
    101   1.1    dyoung #include <sys/bus.h>
    102   1.1    dyoung #include <dev/pci/pcivar.h>
    103   1.1    dyoung #include <dev/pci/pcireg.h>
    104   1.1    dyoung #include <sys/proc.h>
    105   1.1    dyoung #include <sys/sysctl.h>
    106   1.1    dyoung #include <sys/endian.h>
    107   1.1    dyoung #include <sys/workqueue.h>
    108   1.7   msaitoh #include <sys/cpu.h>
    109   1.9  knakahar #include <sys/interrupt.h>
    110   1.1    dyoung 
    111   1.1    dyoung #include "ixgbe_netbsd.h"
    112   1.1    dyoung #include "ixgbe_api.h"
    113  1.10   msaitoh #include "ixgbe_vf.h"
    114   1.1    dyoung 
    115   1.1    dyoung /* Tunables */
    116   1.1    dyoung 
    117   1.1    dyoung /*
    118   1.1    dyoung  * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
    119   1.1    dyoung  * number of transmit descriptors allocated by the driver. Increasing this
    120   1.1    dyoung  * value allows the driver to queue more transmits. Each descriptor is 16
    121   1.1    dyoung  * bytes. Performance tests have show the 2K value to be optimal for top
    122   1.1    dyoung  * performance.
    123   1.1    dyoung  */
    124   1.1    dyoung #define DEFAULT_TXD	1024
    125   1.1    dyoung #define PERFORM_TXD	2048
    126   1.1    dyoung #define MAX_TXD		4096
    127   1.1    dyoung #define MIN_TXD		64
    128   1.1    dyoung 
    129   1.1    dyoung /*
    130   1.1    dyoung  * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
    131   1.1    dyoung  * number of receive descriptors allocated for each RX queue. Increasing this
    132   1.1    dyoung  * value allows the driver to buffer more incoming packets. Each descriptor
    133   1.1    dyoung  * is 16 bytes.  A receive buffer is also allocated for each descriptor.
    134   1.1    dyoung  *
    135   1.1    dyoung  * Note: with 8 rings and a dual port card, it is possible to bump up
    136   1.1    dyoung  *	against the system mbuf pool limit, you can tune nmbclusters
    137   1.1    dyoung  *	to adjust for this.
    138   1.1    dyoung  */
    139   1.1    dyoung #define DEFAULT_RXD	1024
    140   1.1    dyoung #define PERFORM_RXD	2048
    141   1.1    dyoung #define MAX_RXD		4096
    142   1.1    dyoung #define MIN_RXD		64
    143   1.1    dyoung 
    144   1.1    dyoung /* Alignment for rings */
    145   1.1    dyoung #define DBA_ALIGN	128
    146   1.1    dyoung 
    147   1.1    dyoung /*
    148   1.1    dyoung  * This parameter controls the maximum no of times the driver will loop in
    149   1.1    dyoung  * the isr. Minimum Value = 1
    150   1.1    dyoung  */
    151   1.1    dyoung #define MAX_LOOP	10
    152   1.1    dyoung 
    153   1.1    dyoung /*
    154   1.1    dyoung  * This is the max watchdog interval, ie. the time that can
    155   1.1    dyoung  * pass between any two TX clean operations, such only happening
    156   1.1    dyoung  * when the TX hardware is functioning.
    157   1.1    dyoung  */
    158   1.1    dyoung #define IXGBE_WATCHDOG                   (10 * hz)
    159   1.1    dyoung 
    160   1.1    dyoung /*
    161   1.1    dyoung  * This parameters control when the driver calls the routine to reclaim
    162   1.1    dyoung  * transmit descriptors.
    163   1.1    dyoung  */
    164   1.1    dyoung #define IXGBE_TX_CLEANUP_THRESHOLD	(adapter->num_tx_desc / 8)
    165   1.1    dyoung #define IXGBE_TX_OP_THRESHOLD		(adapter->num_tx_desc / 32)
    166   1.1    dyoung 
    167   1.1    dyoung #define IXGBE_MAX_FRAME_SIZE	0x3F00
    168   1.1    dyoung 
    169   1.1    dyoung /* Flow control constants */
    170   1.1    dyoung #define IXGBE_FC_PAUSE		0xFFFF
    171   1.1    dyoung #define IXGBE_FC_HI		0x20000
    172   1.1    dyoung #define IXGBE_FC_LO		0x10000
    173   1.1    dyoung 
    174   1.6   msaitoh /*
    175   1.6   msaitoh  * Used for optimizing small rx mbufs.  Effort is made to keep the copy
    176   1.6   msaitoh  * small and aligned for the CPU L1 cache.
    177   1.6   msaitoh  *
    178   1.6   msaitoh  * MHLEN is typically 168 bytes, giving us 8-byte alignment.  Getting
    179   1.6   msaitoh  * 32 byte alignment needed for the fast bcopy results in 8 bytes being
    180   1.6   msaitoh  * wasted.  Getting 64 byte alignment, which _should_ be ideal for
    181   1.6   msaitoh  * modern Intel CPUs, results in 40 bytes wasted and a significant drop
    182   1.6   msaitoh  * in observed efficiency of the optimization, 97.9% -> 81.8%.
    183   1.6   msaitoh  */
    184   1.8   msaitoh #define	MPKTHSIZE		(offsetof(struct _mbuf_dummy, m_pktdat))
    185   1.8   msaitoh #define IXGBE_RX_COPY_HDR_PADDED	((((MPKTHSIZE - 1) / 32) + 1) * 32)
    186   1.8   msaitoh #define IXGBE_RX_COPY_LEN		(MSIZE - IXGBE_RX_COPY_HDR_PADDED)
    187   1.8   msaitoh #define IXGBE_RX_COPY_ALIGN		(IXGBE_RX_COPY_HDR_PADDED - MPKTHSIZE)
    188   1.6   msaitoh 
    189   1.1    dyoung /* Keep older OS drivers building... */
    190   1.1    dyoung #if !defined(SYSCTL_ADD_UQUAD)
    191   1.1    dyoung #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
    192   1.1    dyoung #endif
    193   1.1    dyoung 
    194   1.1    dyoung /* Defines for printing debug information */
    195   1.1    dyoung #define DEBUG_INIT  0
    196   1.1    dyoung #define DEBUG_IOCTL 0
    197   1.1    dyoung #define DEBUG_HW    0
    198   1.1    dyoung 
    199   1.1    dyoung #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
    200   1.1    dyoung #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
    201   1.1    dyoung #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
    202   1.1    dyoung #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
    203   1.1    dyoung #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
    204   1.1    dyoung #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
    205   1.1    dyoung #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
    206   1.1    dyoung #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
    207   1.1    dyoung #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
    208   1.1    dyoung 
    209   1.1    dyoung #define MAX_NUM_MULTICAST_ADDRESSES     128
    210   1.1    dyoung #define IXGBE_82598_SCATTER		100
    211   1.1    dyoung #define IXGBE_82599_SCATTER		32
    212   1.1    dyoung #define MSIX_82598_BAR			3
    213   1.1    dyoung #define MSIX_82599_BAR			4
    214   1.5   msaitoh #define IXGBE_TSO_SIZE			262140
    215   1.1    dyoung #define IXGBE_TX_BUFFER_SIZE		((u32) 1514)
    216   1.1    dyoung #define IXGBE_RX_HDR			128
    217   1.1    dyoung #define IXGBE_VFTA_SIZE			128
    218   1.1    dyoung #define IXGBE_BR_SIZE			4096
    219   1.4   msaitoh #define IXGBE_QUEUE_MIN_FREE		32
    220  1.11   msaitoh #define IXGBE_MAX_TX_BUSY		10
    221  1.11   msaitoh #define IXGBE_QUEUE_HUNG		0x80000000
    222  1.11   msaitoh 
    223  1.11   msaitoh #define IXV_EITR_DEFAULT		128
    224  1.11   msaitoh 
    225  1.11   msaitoh #define IXV_EITR_DEFAULT		128
    226   1.1    dyoung 
    227   1.7   msaitoh /* IOCTL define to gather SFP+ Diagnostic data */
    228   1.7   msaitoh #define SIOCGI2C	SIOCGIFGENERIC
    229   1.7   msaitoh 
    230   1.1    dyoung /* Offload bits in mbuf flag */
    231   1.1    dyoung #define	M_CSUM_OFFLOAD	\
    232   1.1    dyoung     (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4|M_CSUM_UDPv6|M_CSUM_TCPv6)
    233   1.1    dyoung 
    234  1.11   msaitoh /* Backward compatibility items for very old versions */
    235  1.11   msaitoh #ifndef pci_find_cap
    236  1.11   msaitoh #define pci_find_cap pci_find_extcap
    237  1.11   msaitoh #endif
    238  1.11   msaitoh 
    239  1.11   msaitoh #ifndef DEVMETHOD_END
    240  1.11   msaitoh #define DEVMETHOD_END { NULL, NULL }
    241  1.11   msaitoh #endif
    242  1.11   msaitoh 
    243   1.1    dyoung /*
    244   1.1    dyoung  * Interrupt Moderation parameters
    245   1.1    dyoung  */
    246   1.1    dyoung #define IXGBE_LOW_LATENCY	128
    247   1.1    dyoung #define IXGBE_AVE_LATENCY	400
    248   1.1    dyoung #define IXGBE_BULK_LATENCY	1200
    249   1.1    dyoung #define IXGBE_LINK_ITR		2000
    250   1.1    dyoung 
    251   1.1    dyoung /*
    252   1.1    dyoung  *****************************************************************************
    253   1.1    dyoung  * vendor_info_array
    254   1.1    dyoung  *
    255   1.1    dyoung  * This array contains the list of Subvendor/Subdevice IDs on which the driver
    256   1.1    dyoung  * should load.
    257   1.1    dyoung  *
    258   1.1    dyoung  *****************************************************************************
    259   1.1    dyoung  */
    260   1.1    dyoung typedef struct _ixgbe_vendor_info_t {
    261   1.1    dyoung 	unsigned int    vendor_id;
    262   1.1    dyoung 	unsigned int    device_id;
    263   1.1    dyoung 	unsigned int    subvendor_id;
    264   1.1    dyoung 	unsigned int    subdevice_id;
    265   1.1    dyoung 	unsigned int    index;
    266   1.1    dyoung } ixgbe_vendor_info_t;
    267   1.1    dyoung 
    268   1.7   msaitoh /* This is used to get SFP+ module data */
    269   1.7   msaitoh struct ixgbe_i2c_req {
    270   1.7   msaitoh         u8 dev_addr;
    271   1.7   msaitoh         u8 offset;
    272   1.7   msaitoh         u8 len;
    273   1.7   msaitoh         u8 data[8];
    274   1.7   msaitoh };
    275   1.1    dyoung 
    276   1.1    dyoung struct ixgbe_tx_buf {
    277   1.7   msaitoh 	union ixgbe_adv_tx_desc	*eop;
    278   1.1    dyoung 	struct mbuf	*m_head;
    279   1.1    dyoung 	bus_dmamap_t	map;
    280   1.1    dyoung };
    281   1.1    dyoung 
    282   1.1    dyoung struct ixgbe_rx_buf {
    283   1.6   msaitoh 	struct mbuf	*buf;
    284   1.1    dyoung 	struct mbuf	*fmp;
    285   1.7   msaitoh 	bus_dmamap_t	pmap;
    286   1.6   msaitoh 	u_int		flags;
    287   1.6   msaitoh #define IXGBE_RX_COPY	0x01
    288   1.6   msaitoh 	uint64_t	addr;
    289   1.1    dyoung };
    290   1.1    dyoung 
    291   1.1    dyoung /*
    292   1.1    dyoung  * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
    293   1.1    dyoung  */
    294   1.1    dyoung struct ixgbe_dma_alloc {
    295   1.1    dyoung 	bus_addr_t		dma_paddr;
    296   1.1    dyoung 	void			*dma_vaddr;
    297   1.1    dyoung 	ixgbe_dma_tag_t		*dma_tag;
    298   1.1    dyoung 	bus_dmamap_t		dma_map;
    299   1.1    dyoung 	bus_dma_segment_t	dma_seg;
    300   1.1    dyoung 	bus_size_t		dma_size;
    301   1.1    dyoung };
    302   1.1    dyoung 
    303   1.1    dyoung /*
    304   1.1    dyoung ** Driver queue struct: this is the interrupt container
    305   1.1    dyoung **  for the associated tx and rx ring.
    306   1.1    dyoung */
    307   1.1    dyoung struct ix_queue {
    308   1.1    dyoung 	struct adapter		*adapter;
    309   1.1    dyoung 	u32			msix;           /* This queue's MSIX vector */
    310   1.1    dyoung 	u32			eims;           /* This queue's EIMS bit */
    311   1.1    dyoung 	u32			eitr_setting;
    312  1.11   msaitoh 	u32			me;
    313   1.1    dyoung 	struct resource		*res;
    314   1.1    dyoung 	void			*tag;
    315  1.11   msaitoh 	int			busy;
    316   1.1    dyoung 	struct tx_ring		*txr;
    317   1.1    dyoung 	struct rx_ring		*rxr;
    318   1.1    dyoung 	void			*que_si;
    319  1.11   msaitoh 	struct evcnt		irqs;
    320   1.1    dyoung 	char			namebuf[32];
    321   1.1    dyoung 	char			evnamebuf[32];
    322   1.1    dyoung };
    323   1.1    dyoung 
    324   1.1    dyoung /*
    325   1.1    dyoung  * The transmit ring, one per queue
    326   1.1    dyoung  */
    327   1.1    dyoung struct tx_ring {
    328   1.1    dyoung         struct adapter		*adapter;
    329   1.1    dyoung 	kmutex_t		tx_mtx;
    330   1.1    dyoung 	u32			me;
    331  1.11   msaitoh 	u32			tail;
    332  1.11   msaitoh 	int			busy;
    333   1.7   msaitoh 	union ixgbe_adv_tx_desc	*tx_base;
    334   1.7   msaitoh 	struct ixgbe_tx_buf	*tx_buffers;
    335   1.7   msaitoh 	struct ixgbe_dma_alloc	txdma;
    336   1.7   msaitoh 	volatile u16		tx_avail;
    337   1.7   msaitoh 	u16			next_avail_desc;
    338   1.7   msaitoh 	u16			next_to_clean;
    339   1.7   msaitoh 	u32			process_limit;
    340   1.7   msaitoh 	u16			num_desc;
    341   1.1    dyoung 	u32			txd_cmd;
    342   1.1    dyoung 	ixgbe_dma_tag_t		*txtag;
    343   1.1    dyoung 	char			mtx_name[16];
    344   1.7   msaitoh #ifndef IXGBE_LEGACY_TX
    345   1.1    dyoung 	struct buf_ring		*br;
    346   1.7   msaitoh 	void			*txq_si;
    347   1.1    dyoung #endif
    348   1.1    dyoung #ifdef IXGBE_FDIR
    349   1.1    dyoung 	u16			atr_sample;
    350   1.1    dyoung 	u16			atr_count;
    351   1.1    dyoung #endif
    352   1.1    dyoung 	u32			bytes;  /* used for AIM */
    353   1.1    dyoung 	u32			packets;
    354   1.1    dyoung 	/* Soft Stats */
    355  1.11   msaitoh 	struct evcnt	   	tx_bytes;
    356   1.7   msaitoh 	struct evcnt	   	tso_tx;
    357   1.7   msaitoh 	struct evcnt	   	no_tx_map_avail;
    358   1.1    dyoung 	struct evcnt		no_desc_avail;
    359   1.1    dyoung 	struct evcnt		total_packets;
    360   1.1    dyoung };
    361   1.1    dyoung 
    362   1.1    dyoung 
    363   1.1    dyoung /*
    364   1.1    dyoung  * The Receive ring, one per rx queue
    365   1.1    dyoung  */
    366   1.1    dyoung struct rx_ring {
    367   1.1    dyoung         struct adapter		*adapter;
    368   1.1    dyoung 	kmutex_t		rx_mtx;
    369   1.1    dyoung 	u32			me;
    370  1.11   msaitoh 	u32			tail;
    371   1.1    dyoung 	union ixgbe_adv_rx_desc	*rx_base;
    372   1.1    dyoung 	struct ixgbe_dma_alloc	rxdma;
    373   1.1    dyoung #ifdef LRO
    374   1.1    dyoung 	struct lro_ctrl		lro;
    375   1.1    dyoung #endif /* LRO */
    376   1.1    dyoung 	bool			lro_enabled;
    377   1.1    dyoung 	bool			hw_rsc;
    378   1.4   msaitoh 	bool			vtag_strip;
    379   1.7   msaitoh         u16			next_to_refresh;
    380   1.7   msaitoh         u16 			next_to_check;
    381   1.7   msaitoh 	u16			num_desc;
    382   1.7   msaitoh 	u16			mbuf_sz;
    383   1.7   msaitoh 	u32			process_limit;
    384   1.1    dyoung 	char			mtx_name[16];
    385   1.1    dyoung 	struct ixgbe_rx_buf	*rx_buffers;
    386   1.7   msaitoh 	ixgbe_dma_tag_t		*ptag;
    387   1.1    dyoung 
    388   1.1    dyoung 	u32			bytes; /* Used for AIM calc */
    389   1.1    dyoung 	u32			packets;
    390   1.1    dyoung 
    391   1.1    dyoung 	/* Soft stats */
    392   1.1    dyoung 	struct evcnt		rx_irq;
    393   1.6   msaitoh 	struct evcnt		rx_copies;
    394   1.1    dyoung 	struct evcnt		rx_packets;
    395   1.1    dyoung 	struct evcnt 		rx_bytes;
    396   1.1    dyoung 	struct evcnt 		rx_discarded;
    397   1.1    dyoung 	struct evcnt 		no_jmbuf;
    398   1.1    dyoung 	u64 			rsc_num;
    399   1.1    dyoung #ifdef IXGBE_FDIR
    400   1.1    dyoung 	u64			flm;
    401   1.1    dyoung #endif
    402   1.1    dyoung };
    403   1.1    dyoung 
    404   1.1    dyoung /* Our adapter structure */
    405   1.1    dyoung struct adapter {
    406   1.1    dyoung 	struct ifnet		*ifp;
    407   1.1    dyoung 	struct ixgbe_hw		hw;
    408   1.1    dyoung 
    409   1.1    dyoung 	struct ixgbe_osdep	osdep;
    410   1.1    dyoung 	device_t		dev;
    411   1.1    dyoung 
    412   1.1    dyoung 	struct resource		*pci_mem;
    413   1.1    dyoung 	struct resource		*msix_mem;
    414   1.1    dyoung 
    415   1.1    dyoung 	/*
    416   1.1    dyoung 	 * Interrupt resources: this set is
    417   1.1    dyoung 	 * either used for legacy, or for Link
    418   1.1    dyoung 	 * when doing MSIX
    419   1.1    dyoung 	 */
    420   1.1    dyoung 	void			*tag;
    421   1.1    dyoung 	struct resource 	*res;
    422   1.1    dyoung 
    423   1.1    dyoung 	struct ifmedia		media;
    424   1.1    dyoung 	callout_t		timer;
    425   1.1    dyoung 	int			msix;
    426   1.1    dyoung 	int			if_flags;
    427   1.1    dyoung 
    428   1.1    dyoung 	kmutex_t		core_mtx;
    429   1.1    dyoung 
    430   1.1    dyoung 	unsigned int		num_queues;
    431   1.1    dyoung 
    432   1.1    dyoung 	/*
    433   1.1    dyoung 	** Shadow VFTA table, this is needed because
    434   1.1    dyoung 	** the real vlan filter table gets cleared during
    435   1.1    dyoung 	** a soft reset and the driver needs to be able
    436   1.1    dyoung 	** to repopulate it.
    437   1.1    dyoung 	*/
    438   1.1    dyoung 	u32			shadow_vfta[IXGBE_VFTA_SIZE];
    439   1.1    dyoung 
    440   1.1    dyoung 	/* Info about the interface */
    441   1.1    dyoung 	u32			optics;
    442   1.4   msaitoh 	u32			fc; /* local flow ctrl setting */
    443   1.1    dyoung 	int			advertise;  /* link speeds */
    444   1.1    dyoung 	bool			link_active;
    445   1.1    dyoung 	u16			max_frame_size;
    446   1.1    dyoung 	u16			num_segs;
    447   1.1    dyoung 	u32			link_speed;
    448   1.1    dyoung 	bool			link_up;
    449  1.11   msaitoh 	u32 			vector;
    450   1.1    dyoung 
    451   1.1    dyoung 	/* Mbuf cluster size */
    452   1.1    dyoung 	u32			rx_mbuf_sz;
    453   1.1    dyoung 
    454   1.1    dyoung 	/* Support for pluggable optics */
    455   1.1    dyoung 	bool			sfp_probe;
    456   1.1    dyoung 	void			*link_si;  /* Link tasklet */
    457   1.1    dyoung 	void			*mod_si;   /* SFP tasklet */
    458   1.1    dyoung 	void			*msf_si;   /* Multispeed Fiber */
    459   1.1    dyoung #ifdef IXGBE_FDIR
    460   1.1    dyoung 	int			fdir_reinit;
    461   1.1    dyoung 	void			*fdir_si;
    462   1.1    dyoung #endif
    463   1.1    dyoung 
    464   1.1    dyoung 	/*
    465   1.1    dyoung 	** Queues:
    466   1.1    dyoung 	**   This is the irq holder, it has
    467   1.1    dyoung 	**   and RX/TX pair or rings associated
    468   1.1    dyoung 	**   with it.
    469   1.1    dyoung 	*/
    470   1.1    dyoung 	struct ix_queue		*queues;
    471   1.1    dyoung 
    472   1.1    dyoung 	/*
    473   1.1    dyoung 	 * Transmit rings:
    474   1.1    dyoung 	 *	Allocated at run time, an array of rings.
    475   1.1    dyoung 	 */
    476   1.1    dyoung 	struct tx_ring		*tx_rings;
    477   1.7   msaitoh 	u32			num_tx_desc;
    478   1.1    dyoung 
    479   1.1    dyoung 	/*
    480   1.1    dyoung 	 * Receive rings:
    481   1.1    dyoung 	 *	Allocated at run time, an array of rings.
    482   1.1    dyoung 	 */
    483   1.1    dyoung 	struct rx_ring		*rx_rings;
    484  1.11   msaitoh 	u64			active_queues;
    485   1.7   msaitoh 	u32			num_rx_desc;
    486   1.1    dyoung 
    487   1.1    dyoung 	/* Multicast array memory */
    488   1.1    dyoung 	u8			*mta;
    489   1.1    dyoung 
    490   1.8   msaitoh 
    491   1.1    dyoung 	/* Misc stats maintained by the driver */
    492   1.1    dyoung 	struct evcnt   		dropped_pkts;
    493   1.1    dyoung 	struct evcnt   		mbuf_defrag_failed;
    494   1.1    dyoung 	struct evcnt	   	mbuf_header_failed;
    495   1.1    dyoung 	struct evcnt	   	mbuf_packet_failed;
    496   1.1    dyoung 	struct evcnt	   	efbig_tx_dma_setup;
    497   1.1    dyoung 	struct evcnt	   	efbig2_tx_dma_setup;
    498   1.1    dyoung 	struct evcnt	   	m_defrag_failed;
    499   1.1    dyoung 	struct evcnt	   	einval_tx_dma_setup;
    500   1.1    dyoung 	struct evcnt	   	other_tx_dma_setup;
    501   1.1    dyoung 	struct evcnt	   	eagain_tx_dma_setup;
    502   1.1    dyoung 	struct evcnt	   	enomem_tx_dma_setup;
    503   1.1    dyoung 	struct evcnt	   	watchdog_events;
    504   1.1    dyoung 	struct evcnt	   	tso_err;
    505  1.11   msaitoh 	struct evcnt		vector_irq;
    506   1.1    dyoung 	struct evcnt		morerx;
    507   1.1    dyoung 	struct evcnt		moretx;
    508   1.1    dyoung 	struct evcnt		txloops;
    509   1.1    dyoung 	struct evcnt		handleq;
    510   1.1    dyoung 	struct evcnt		req;
    511   1.1    dyoung 
    512  1.11   msaitoh 	union {
    513  1.11   msaitoh 		struct ixgbe_hw_stats pf;
    514  1.11   msaitoh 		struct ixgbevf_hw_stats	vf;
    515  1.11   msaitoh 	} stats;
    516  1.11   msaitoh #if __FreeBSD_version >= 1100036
    517  1.11   msaitoh 	/* counter(9) stats */
    518  1.11   msaitoh 	u64			ipackets;
    519  1.11   msaitoh 	u64			ierrors;
    520  1.11   msaitoh 	u64			opackets;
    521  1.11   msaitoh 	u64			oerrors;
    522  1.11   msaitoh 	u64			ibytes;
    523  1.11   msaitoh 	u64			obytes;
    524  1.11   msaitoh 	u64			imcasts;
    525  1.11   msaitoh 	u64			omcasts;
    526  1.11   msaitoh 	u64			iqdrops;
    527  1.11   msaitoh 	u64			noproto;
    528  1.11   msaitoh #endif
    529   1.1    dyoung 	struct sysctllog	*sysctllog;
    530   1.1    dyoung 	ixgbe_extmem_head_t jcl_head;
    531   1.1    dyoung };
    532   1.1    dyoung 
    533   1.8   msaitoh 
    534   1.1    dyoung /* Precision Time Sync (IEEE 1588) defines */
    535   1.1    dyoung #define ETHERTYPE_IEEE1588      0x88F7
    536   1.1    dyoung #define PICOSECS_PER_TICK       20833
    537   1.1    dyoung #define TSYNC_UDP_PORT          319 /* UDP port for the protocol */
    538   1.1    dyoung #define IXGBE_ADVTXD_TSTAMP	0x00080000
    539   1.1    dyoung 
    540   1.1    dyoung 
    541   1.1    dyoung #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
    542   1.2   msaitoh         mutex_init(&(_sc)->core_mtx, MUTEX_DEFAULT, IPL_SOFTNET)
    543   1.1    dyoung #define IXGBE_CORE_LOCK_DESTROY(_sc)      mutex_destroy(&(_sc)->core_mtx)
    544   1.1    dyoung #define IXGBE_TX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->tx_mtx)
    545   1.1    dyoung #define IXGBE_RX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->rx_mtx)
    546   1.1    dyoung #define IXGBE_CORE_LOCK(_sc)              mutex_enter(&(_sc)->core_mtx)
    547   1.1    dyoung #define IXGBE_TX_LOCK(_sc)                mutex_enter(&(_sc)->tx_mtx)
    548   1.1    dyoung #define IXGBE_TX_TRYLOCK(_sc)             mutex_tryenter(&(_sc)->tx_mtx)
    549   1.1    dyoung #define IXGBE_RX_LOCK(_sc)                mutex_enter(&(_sc)->rx_mtx)
    550   1.1    dyoung #define IXGBE_CORE_UNLOCK(_sc)            mutex_exit(&(_sc)->core_mtx)
    551   1.1    dyoung #define IXGBE_TX_UNLOCK(_sc)              mutex_exit(&(_sc)->tx_mtx)
    552   1.1    dyoung #define IXGBE_RX_UNLOCK(_sc)              mutex_exit(&(_sc)->rx_mtx)
    553   1.3   msaitoh #define IXGBE_CORE_LOCK_ASSERT(_sc)       KASSERT(mutex_owned(&(_sc)->core_mtx))
    554   1.1    dyoung #define IXGBE_TX_LOCK_ASSERT(_sc)         KASSERT(mutex_owned(&(_sc)->tx_mtx))
    555   1.1    dyoung 
    556  1.11   msaitoh /* Stats macros */
    557  1.11   msaitoh #if __FreeBSD_version >= 1100036
    558  1.11   msaitoh #define IXGBE_SET_IPACKETS(sc, count)    (sc)->ipackets = (count)
    559  1.11   msaitoh #define IXGBE_SET_IERRORS(sc, count)     (sc)->ierrors = (count)
    560  1.11   msaitoh #define IXGBE_SET_OPACKETS(sc, count)    (sc)->opackets = (count)
    561  1.11   msaitoh #define IXGBE_SET_OERRORS(sc, count)     (sc)->oerrors = (count)
    562  1.11   msaitoh #define IXGBE_SET_COLLISIONS(sc, count)
    563  1.11   msaitoh #define IXGBE_SET_IBYTES(sc, count)      (sc)->ibytes = (count)
    564  1.11   msaitoh #define IXGBE_SET_OBYTES(sc, count)      (sc)->obytes = (count)
    565  1.11   msaitoh #define IXGBE_SET_IMCASTS(sc, count)     (sc)->imcasts = (count)
    566  1.11   msaitoh #define IXGBE_SET_OMCASTS(sc, count)     (sc)->omcasts = (count)
    567  1.11   msaitoh #define IXGBE_SET_IQDROPS(sc, count)     (sc)->iqdrops = (count)
    568  1.11   msaitoh #else
    569  1.11   msaitoh #define IXGBE_SET_IPACKETS(sc, count)    (sc)->ifp->if_ipackets = (count)
    570  1.11   msaitoh #define IXGBE_SET_IERRORS(sc, count)     (sc)->ifp->if_ierrors = (count)
    571  1.11   msaitoh #define IXGBE_SET_OPACKETS(sc, count)    (sc)->ifp->if_opackets = (count)
    572  1.11   msaitoh #define IXGBE_SET_OERRORS(sc, count)     (sc)->ifp->if_oerrors = (count)
    573  1.11   msaitoh #define IXGBE_SET_COLLISIONS(sc, count)  (sc)->ifp->if_collisions = (count)
    574  1.11   msaitoh #define IXGBE_SET_IBYTES(sc, count)      (sc)->ifp->if_ibytes = (count)
    575  1.11   msaitoh #define IXGBE_SET_OBYTES(sc, count)      (sc)->ifp->if_obytes = (count)
    576  1.11   msaitoh #define IXGBE_SET_IMCASTS(sc, count)     (sc)->ifp->if_imcasts = (count)
    577  1.11   msaitoh #define IXGBE_SET_OMCASTS(sc, count)     (sc)->ifp->if_omcasts = (count)
    578  1.11   msaitoh #define IXGBE_SET_IQDROPS(sc, count)     (sc)->ifp->if_iqdrops = (count)
    579  1.11   msaitoh #endif
    580  1.11   msaitoh 
    581  1.11   msaitoh /* Sysctl help messages; displayed with sysctl -d */
    582  1.11   msaitoh #define IXGBE_SYSCTL_DESC_ADV_SPEED \
    583  1.11   msaitoh 	"\nControl advertised link speed using these flags:\n" \
    584  1.11   msaitoh 	"\t0x1 - advertise 100M\n" \
    585  1.11   msaitoh 	"\t0x2 - advertise 1G\n" \
    586  1.11   msaitoh 	"\t0x4 - advertise 10G"
    587  1.11   msaitoh 
    588  1.11   msaitoh #define IXGBE_SYSCTL_DESC_SET_FC \
    589  1.11   msaitoh 	"\nSet flow control mode using these values:\n" \
    590  1.11   msaitoh 	"\t0 - off\n" \
    591  1.11   msaitoh 	"\t1 - rx pause\n" \
    592  1.11   msaitoh 	"\t2 - tx pause\n" \
    593  1.11   msaitoh 	"\t3 - tx and rx pause"
    594  1.11   msaitoh 
    595   1.1    dyoung static inline bool
    596   1.1    dyoung ixgbe_is_sfp(struct ixgbe_hw *hw)
    597   1.1    dyoung {
    598   1.1    dyoung 	switch (hw->phy.type) {
    599   1.1    dyoung 	case ixgbe_phy_sfp_avago:
    600   1.1    dyoung 	case ixgbe_phy_sfp_ftl:
    601   1.1    dyoung 	case ixgbe_phy_sfp_intel:
    602   1.1    dyoung 	case ixgbe_phy_sfp_unknown:
    603   1.1    dyoung 	case ixgbe_phy_sfp_passive_tyco:
    604   1.1    dyoung 	case ixgbe_phy_sfp_passive_unknown:
    605  1.11   msaitoh 	case ixgbe_phy_qsfp_passive_unknown:
    606  1.11   msaitoh 	case ixgbe_phy_qsfp_active_unknown:
    607  1.11   msaitoh 	case ixgbe_phy_qsfp_intel:
    608  1.11   msaitoh 	case ixgbe_phy_qsfp_unknown:
    609   1.1    dyoung 		return TRUE;
    610   1.1    dyoung 	default:
    611   1.1    dyoung 		return FALSE;
    612   1.1    dyoung 	}
    613   1.1    dyoung }
    614   1.1    dyoung 
    615   1.1    dyoung /* Workaround to make 8.0 buildable */
    616   1.1    dyoung #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
    617   1.1    dyoung static __inline int
    618   1.1    dyoung drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
    619   1.1    dyoung {
    620   1.1    dyoung #ifdef ALTQ
    621   1.1    dyoung         if (ALTQ_IS_ENABLED(&ifp->if_snd))
    622   1.1    dyoung                 return (1);
    623   1.1    dyoung #endif
    624   1.1    dyoung         return (!buf_ring_empty(br));
    625   1.1    dyoung }
    626   1.1    dyoung #endif
    627   1.1    dyoung 
    628   1.1    dyoung /*
    629   1.1    dyoung ** Find the number of unrefreshed RX descriptors
    630   1.1    dyoung */
    631   1.1    dyoung static inline u16
    632   1.1    dyoung ixgbe_rx_unrefreshed(struct rx_ring *rxr)
    633   1.1    dyoung {
    634   1.1    dyoung 	if (rxr->next_to_check > rxr->next_to_refresh)
    635   1.1    dyoung 		return (rxr->next_to_check - rxr->next_to_refresh - 1);
    636   1.1    dyoung 	else
    637   1.7   msaitoh 		return ((rxr->num_desc + rxr->next_to_check) -
    638   1.1    dyoung 		    rxr->next_to_refresh - 1);
    639   1.1    dyoung }
    640   1.1    dyoung 
    641  1.11   msaitoh /*
    642  1.11   msaitoh ** This checks for a zero mac addr, something that will be likely
    643  1.11   msaitoh ** unless the Admin on the Host has created one.
    644  1.11   msaitoh */
    645  1.11   msaitoh static inline bool
    646  1.11   msaitoh ixv_check_ether_addr(u8 *addr)
    647  1.11   msaitoh {
    648  1.11   msaitoh 	bool status = TRUE;
    649  1.11   msaitoh 
    650  1.11   msaitoh 	if ((addr[0] == 0 && addr[1]== 0 && addr[2] == 0 &&
    651  1.11   msaitoh 	    addr[3] == 0 && addr[4]== 0 && addr[5] == 0))
    652  1.11   msaitoh 		status = FALSE;
    653  1.11   msaitoh 	return (status);
    654  1.11   msaitoh }
    655  1.11   msaitoh 
    656  1.11   msaitoh /* Shared Prototypes */
    657  1.11   msaitoh 
    658  1.10   msaitoh #ifdef IXGBE_LEGACY_TX
    659  1.11   msaitoh void	ixgbe_start(struct ifnet *);
    660  1.11   msaitoh void	ixgbe_start_locked(struct tx_ring *, struct ifnet *);
    661  1.10   msaitoh #else /* ! IXGBE_LEGACY_TX */
    662  1.10   msaitoh int	ixgbe_mq_start(struct ifnet *, struct mbuf *);
    663  1.10   msaitoh int	ixgbe_mq_start_locked(struct ifnet *, struct tx_ring *);
    664  1.10   msaitoh void	ixgbe_qflush(struct ifnet *);
    665  1.10   msaitoh void	ixgbe_deferred_mq_start(void *, int);
    666  1.10   msaitoh #endif /* IXGBE_LEGACY_TX */
    667  1.10   msaitoh 
    668  1.10   msaitoh int	ixgbe_allocate_queues(struct adapter *);
    669  1.11   msaitoh int	ixgbe_allocate_transmit_buffers(struct tx_ring *);
    670  1.10   msaitoh int	ixgbe_setup_transmit_structures(struct adapter *);
    671  1.11   msaitoh void	ixgbe_free_transmit_structures(struct adapter *);
    672  1.11   msaitoh int	ixgbe_allocate_receive_buffers(struct rx_ring *);
    673  1.11   msaitoh int	ixgbe_setup_receive_structures(struct adapter *);
    674  1.11   msaitoh void	ixgbe_free_receive_structures(struct adapter *);
    675  1.10   msaitoh void	ixgbe_txeof(struct tx_ring *);
    676  1.10   msaitoh bool	ixgbe_rxeof(struct ix_queue *);
    677  1.10   msaitoh 
    678  1.10   msaitoh int	ixgbe_dma_malloc(struct adapter *,
    679  1.11   msaitoh 	    bus_size_t, struct ixgbe_dma_alloc *, int);
    680  1.11   msaitoh void	ixgbe_dma_free(struct adapter *, struct ixgbe_dma_alloc *);
    681   1.1    dyoung #endif /* _IXGBE_H_ */
    682