Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe.h revision 1.1
      1 /******************************************************************************
      2 
      3   Copyright (c) 2001-2011, Intel Corporation
      4   All rights reserved.
      5 
      6   Redistribution and use in source and binary forms, with or without
      7   modification, are permitted provided that the following conditions are met:
      8 
      9    1. Redistributions of source code must retain the above copyright notice,
     10       this list of conditions and the following disclaimer.
     11 
     12    2. Redistributions in binary form must reproduce the above copyright
     13       notice, this list of conditions and the following disclaimer in the
     14       documentation and/or other materials provided with the distribution.
     15 
     16    3. Neither the name of the Intel Corporation nor the names of its
     17       contributors may be used to endorse or promote products derived from
     18       this software without specific prior written permission.
     19 
     20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   POSSIBILITY OF SUCH DAMAGE.
     31 
     32 ******************************************************************************/
     33 /*
     34  * Copyright (c) 2011 The NetBSD Foundation, Inc.
     35  * All rights reserved.
     36  *
     37  * This code is derived from software contributed to The NetBSD Foundation
     38  * by Coyote Point Systems, Inc.
     39  *
     40  * Redistribution and use in source and binary forms, with or without
     41  * modification, are permitted provided that the following conditions
     42  * are met:
     43  * 1. Redistributions of source code must retain the above copyright
     44  *    notice, this list of conditions and the following disclaimer.
     45  * 2. Redistributions in binary form must reproduce the above copyright
     46  *    notice, this list of conditions and the following disclaimer in the
     47  *    documentation and/or other materials provided with the distribution.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     50  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     51  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     52  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     53  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     54  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     55  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     56  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     57  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     58  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     59  * POSSIBILITY OF SUCH DAMAGE.
     60  */
     61 /*$FreeBSD: src/sys/dev/ixgbe/ixgbe.h,v 1.24 2011/04/28 23:21:40 jfv Exp $*/
     62 /*$NetBSD: ixgbe.h,v 1.1 2011/08/12 21:55:29 dyoung Exp $*/
     63 
     64 
     65 #ifndef _IXGBE_H_
     66 #define _IXGBE_H_
     67 
     68 
     69 #include <sys/param.h>
     70 #include <sys/reboot.h>
     71 #include <sys/systm.h>
     72 #include <sys/time.h>
     73 #if __FreeBSD_version >= 800000
     74 #include <sys/buf_ring.h>
     75 #endif
     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 
     84 #include <net/if.h>
     85 #include <net/if_arp.h>
     86 #include <net/bpf.h>
     87 #include <net/if_ether.h>
     88 #include <net/if_dl.h>
     89 #include <net/if_media.h>
     90 
     91 #include <net/bpf.h>
     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 
    110 #ifdef IXGBE_IEEE1588
    111 #include <sys/ieee1588.h>
    112 #endif
    113 
    114 #include "ixgbe_netbsd.h"
    115 #include "ixgbe_api.h"
    116 
    117 /* Tunables */
    118 
    119 /*
    120  * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
    121  * number of transmit descriptors allocated by the driver. Increasing this
    122  * value allows the driver to queue more transmits. Each descriptor is 16
    123  * bytes. Performance tests have show the 2K value to be optimal for top
    124  * performance.
    125  */
    126 #define DEFAULT_TXD	1024
    127 #define PERFORM_TXD	2048
    128 #define MAX_TXD		4096
    129 #define MIN_TXD		64
    130 
    131 /*
    132  * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
    133  * number of receive descriptors allocated for each RX queue. Increasing this
    134  * value allows the driver to buffer more incoming packets. Each descriptor
    135  * is 16 bytes.  A receive buffer is also allocated for each descriptor.
    136  *
    137  * Note: with 8 rings and a dual port card, it is possible to bump up
    138  *	against the system mbuf pool limit, you can tune nmbclusters
    139  *	to adjust for this.
    140  */
    141 #define DEFAULT_RXD	1024
    142 #define PERFORM_RXD	2048
    143 #define MAX_RXD		4096
    144 #define MIN_RXD		64
    145 
    146 /* Alignment for rings */
    147 #define DBA_ALIGN	128
    148 
    149 /*
    150  * This parameter controls the maximum no of times the driver will loop in
    151  * the isr. Minimum Value = 1
    152  */
    153 #define MAX_LOOP	10
    154 
    155 /*
    156  * This is the max watchdog interval, ie. the time that can
    157  * pass between any two TX clean operations, such only happening
    158  * when the TX hardware is functioning.
    159  */
    160 #define IXGBE_WATCHDOG                   (10 * hz)
    161 
    162 /*
    163  * This parameters control when the driver calls the routine to reclaim
    164  * transmit descriptors.
    165  */
    166 #define IXGBE_TX_CLEANUP_THRESHOLD	(adapter->num_tx_desc / 8)
    167 #define IXGBE_TX_OP_THRESHOLD		(adapter->num_tx_desc / 32)
    168 
    169 #define IXGBE_MAX_FRAME_SIZE	0x3F00
    170 
    171 /* Flow control constants */
    172 #define IXGBE_FC_PAUSE		0xFFFF
    173 #define IXGBE_FC_HI		0x20000
    174 #define IXGBE_FC_LO		0x10000
    175 
    176 /* Keep older OS drivers building... */
    177 #if !defined(SYSCTL_ADD_UQUAD)
    178 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
    179 #endif
    180 
    181 /* Defines for printing debug information */
    182 #define DEBUG_INIT  0
    183 #define DEBUG_IOCTL 0
    184 #define DEBUG_HW    0
    185 
    186 #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
    187 #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
    188 #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
    189 #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
    190 #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
    191 #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
    192 #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
    193 #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
    194 #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
    195 
    196 #define MAX_NUM_MULTICAST_ADDRESSES     128
    197 #define IXGBE_82598_SCATTER		100
    198 #define IXGBE_82599_SCATTER		32
    199 #define MSIX_82598_BAR			3
    200 #define MSIX_82599_BAR			4
    201 #define IXGBE_TSO_SIZE			65535
    202 #define IXGBE_TX_BUFFER_SIZE		((u32) 1514)
    203 #define IXGBE_RX_HDR			128
    204 #define IXGBE_VFTA_SIZE			128
    205 #define IXGBE_BR_SIZE			4096
    206 #define IXGBE_QUEUE_IDLE		0
    207 #define IXGBE_QUEUE_WORKING		1
    208 #define IXGBE_QUEUE_HUNG		2
    209 
    210 /* Offload bits in mbuf flag */
    211 #define	M_CSUM_OFFLOAD	\
    212     (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4|M_CSUM_UDPv6|M_CSUM_TCPv6)
    213 
    214 /*
    215  * Interrupt Moderation parameters
    216  */
    217 #define IXGBE_LOW_LATENCY	128
    218 #define IXGBE_AVE_LATENCY	400
    219 #define IXGBE_BULK_LATENCY	1200
    220 #define IXGBE_LINK_ITR		2000
    221 
    222 /*
    223  *****************************************************************************
    224  * vendor_info_array
    225  *
    226  * This array contains the list of Subvendor/Subdevice IDs on which the driver
    227  * should load.
    228  *
    229  *****************************************************************************
    230  */
    231 typedef struct _ixgbe_vendor_info_t {
    232 	unsigned int    vendor_id;
    233 	unsigned int    device_id;
    234 	unsigned int    subvendor_id;
    235 	unsigned int    subdevice_id;
    236 	unsigned int    index;
    237 } ixgbe_vendor_info_t;
    238 
    239 
    240 struct ixgbe_tx_buf {
    241 	u32		eop_index;
    242 	struct mbuf	*m_head;
    243 	bus_dmamap_t	map;
    244 };
    245 
    246 struct ixgbe_rx_buf {
    247 	struct mbuf	*m_head;
    248 	struct mbuf	*m_pack;
    249 	struct mbuf	*fmp;
    250 	bus_dmamap_t	hmap;
    251 	bus_dmamap_t	pmap;
    252 };
    253 
    254 /*
    255  * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
    256  */
    257 struct ixgbe_dma_alloc {
    258 	bus_addr_t		dma_paddr;
    259 	void			*dma_vaddr;
    260 	ixgbe_dma_tag_t		*dma_tag;
    261 	bus_dmamap_t		dma_map;
    262 	bus_dma_segment_t	dma_seg;
    263 	bus_size_t		dma_size;
    264 };
    265 
    266 /*
    267 ** Driver queue struct: this is the interrupt container
    268 **  for the associated tx and rx ring.
    269 */
    270 struct ix_queue {
    271 	struct adapter		*adapter;
    272 	u32			msix;           /* This queue's MSIX vector */
    273 	u32			eims;           /* This queue's EIMS bit */
    274 	u32			eitr_setting;
    275 	struct resource		*res;
    276 	void			*tag;
    277 	struct tx_ring		*txr;
    278 	struct rx_ring		*rxr;
    279 	void			*que_si;
    280 	u64			irqs;
    281 	char			namebuf[32];
    282 	char			evnamebuf[32];
    283 };
    284 
    285 /*
    286  * The transmit ring, one per queue
    287  */
    288 struct tx_ring {
    289         struct adapter		*adapter;
    290 	kmutex_t		tx_mtx;
    291 	u32			me;
    292 	int			queue_status;
    293 	struct timeval		watchdog_time;
    294 	union ixgbe_adv_tx_desc	*tx_base;
    295 	struct ixgbe_dma_alloc	txdma;
    296 	u32			next_avail_desc;
    297 	u32			next_to_clean;
    298 	struct ixgbe_tx_buf	*tx_buffers;
    299 	volatile u16		tx_avail;
    300 	u32			txd_cmd;
    301 	ixgbe_dma_tag_t		*txtag;
    302 	char			mtx_name[16];
    303 #if __FreeBSD_version >= 800000
    304 	struct buf_ring		*br;
    305 #endif
    306 #ifdef IXGBE_FDIR
    307 	u16			atr_sample;
    308 	u16			atr_count;
    309 #endif
    310 	u32			bytes;  /* used for AIM */
    311 	u32			packets;
    312 	/* Soft Stats */
    313 	struct evcnt		no_desc_avail;
    314 	struct evcnt		total_packets;
    315 };
    316 
    317 
    318 /*
    319  * The Receive ring, one per rx queue
    320  */
    321 struct rx_ring {
    322         struct adapter		*adapter;
    323 	kmutex_t		rx_mtx;
    324 	u32			me;
    325 	union ixgbe_adv_rx_desc	*rx_base;
    326 	struct ixgbe_dma_alloc	rxdma;
    327 #ifdef LRO
    328 	struct lro_ctrl		lro;
    329 #endif /* LRO */
    330 	bool			lro_enabled;
    331 	bool			hdr_split;
    332 	bool			hw_rsc;
    333 	bool			discard;
    334         u32			next_to_refresh;
    335         u32 			next_to_check;
    336 	char			mtx_name[16];
    337 	struct ixgbe_rx_buf	*rx_buffers;
    338 	ixgbe_dma_tag_t		*htag;
    339 	ixgbe_dma_tag_t		*ptag;
    340 
    341 	u32			bytes; /* Used for AIM calc */
    342 	u32			packets;
    343 
    344 	/* Soft stats */
    345 	struct evcnt		rx_irq;
    346 	struct evcnt		rx_split_packets;
    347 	struct evcnt		rx_packets;
    348 	struct evcnt 		rx_bytes;
    349 	struct evcnt 		rx_discarded;
    350 	struct evcnt 		no_jmbuf;
    351 	u64 			rsc_num;
    352 #ifdef IXGBE_FDIR
    353 	u64			flm;
    354 #endif
    355 };
    356 
    357 /* Our adapter structure */
    358 struct adapter {
    359 	struct ifnet		*ifp;
    360 	struct ixgbe_hw		hw;
    361 
    362 	struct ixgbe_osdep	osdep;
    363 	device_t		dev;
    364 
    365 	struct resource		*pci_mem;
    366 	struct resource		*msix_mem;
    367 
    368 	/*
    369 	 * Interrupt resources: this set is
    370 	 * either used for legacy, or for Link
    371 	 * when doing MSIX
    372 	 */
    373 	void			*tag;
    374 	struct resource 	*res;
    375 
    376 	struct ifmedia		media;
    377 	callout_t		timer;
    378 	int			msix;
    379 	int			if_flags;
    380 
    381 	kmutex_t		core_mtx;
    382 
    383 	unsigned int		num_queues;
    384 
    385 	/*
    386 	** Shadow VFTA table, this is needed because
    387 	** the real vlan filter table gets cleared during
    388 	** a soft reset and the driver needs to be able
    389 	** to repopulate it.
    390 	*/
    391 	u32			shadow_vfta[IXGBE_VFTA_SIZE];
    392 
    393 	/* Info about the interface */
    394 	u32			optics;
    395 	int			advertise;  /* link speeds */
    396 	bool			link_active;
    397 	u16			max_frame_size;
    398 	u16			num_segs;
    399 	u32			link_speed;
    400 	bool			link_up;
    401 	u32 			linkvec;
    402 
    403 	/* Mbuf cluster size */
    404 	u32			rx_mbuf_sz;
    405 
    406 	/* Support for pluggable optics */
    407 	bool			sfp_probe;
    408 	void			*link_si;  /* Link tasklet */
    409 	void			*mod_si;   /* SFP tasklet */
    410 	void			*msf_si;   /* Multispeed Fiber */
    411 #ifdef IXGBE_FDIR
    412 	int			fdir_reinit;
    413 	void			*fdir_si;
    414 #endif
    415 
    416 	/*
    417 	** Queues:
    418 	**   This is the irq holder, it has
    419 	**   and RX/TX pair or rings associated
    420 	**   with it.
    421 	*/
    422 	struct ix_queue		*queues;
    423 
    424 	/*
    425 	 * Transmit rings:
    426 	 *	Allocated at run time, an array of rings.
    427 	 */
    428 	struct tx_ring		*tx_rings;
    429 	int			num_tx_desc;
    430 
    431 	/*
    432 	 * Receive rings:
    433 	 *	Allocated at run time, an array of rings.
    434 	 */
    435 	struct rx_ring		*rx_rings;
    436 	int			num_rx_desc;
    437 	u64			que_mask;
    438 	u32			rx_process_limit;
    439 
    440 	/* Multicast array memory */
    441 	u8			*mta;
    442 
    443 	/* Misc stats maintained by the driver */
    444 	struct evcnt   		dropped_pkts;
    445 	struct evcnt   		mbuf_defrag_failed;
    446 	struct evcnt	   	mbuf_header_failed;
    447 	struct evcnt	   	mbuf_packet_failed;
    448 	struct evcnt	   	no_tx_map_avail;
    449 	struct evcnt	   	efbig_tx_dma_setup;
    450 	struct evcnt	   	efbig2_tx_dma_setup;
    451 	struct evcnt	   	m_defrag_failed;
    452 	struct evcnt	   	einval_tx_dma_setup;
    453 	struct evcnt	   	other_tx_dma_setup;
    454 	struct evcnt	   	eagain_tx_dma_setup;
    455 	struct evcnt	   	enomem_tx_dma_setup;
    456 	struct evcnt	   	watchdog_events;
    457 	struct evcnt	   	tso_err;
    458 	struct evcnt	   	tso_tx;
    459 	struct evcnt		link_irq;
    460 	struct evcnt		morerx;
    461 	struct evcnt		moretx;
    462 	struct evcnt		txloops;
    463 	struct evcnt		handleq;
    464 	struct evcnt		req;
    465 
    466 	struct ixgbe_hw_stats 	stats;
    467 	struct sysctllog	*sysctllog;
    468 	ixgbe_extmem_head_t jcl_head;
    469 };
    470 
    471 /* Precision Time Sync (IEEE 1588) defines */
    472 #define ETHERTYPE_IEEE1588      0x88F7
    473 #define PICOSECS_PER_TICK       20833
    474 #define TSYNC_UDP_PORT          319 /* UDP port for the protocol */
    475 #define IXGBE_ADVTXD_TSTAMP	0x00080000
    476 
    477 
    478 #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
    479         mutex_init(&(_sc)->core_mtx, MUTEX_DEFAULT, IPL_NET)
    480 #define IXGBE_CORE_LOCK_DESTROY(_sc)      mutex_destroy(&(_sc)->core_mtx)
    481 #define IXGBE_TX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->tx_mtx)
    482 #define IXGBE_RX_LOCK_DESTROY(_sc)        mutex_destroy(&(_sc)->rx_mtx)
    483 #define IXGBE_CORE_LOCK(_sc)              mutex_enter(&(_sc)->core_mtx)
    484 #define IXGBE_TX_LOCK(_sc)                mutex_enter(&(_sc)->tx_mtx)
    485 #define IXGBE_TX_TRYLOCK(_sc)             mutex_tryenter(&(_sc)->tx_mtx)
    486 #define IXGBE_RX_LOCK(_sc)                mutex_enter(&(_sc)->rx_mtx)
    487 #define IXGBE_CORE_UNLOCK(_sc)            mutex_exit(&(_sc)->core_mtx)
    488 #define IXGBE_TX_UNLOCK(_sc)              mutex_exit(&(_sc)->tx_mtx)
    489 #define IXGBE_RX_UNLOCK(_sc)              mutex_exit(&(_sc)->rx_mtx)
    490 #define IXGBE_CORE_LOCK_ASSERT(_sc)       KASSERT(mutex_owned(&(_sc)->core_mtx)
    491 #define IXGBE_TX_LOCK_ASSERT(_sc)         KASSERT(mutex_owned(&(_sc)->tx_mtx))
    492 
    493 
    494 static inline bool
    495 ixgbe_is_sfp(struct ixgbe_hw *hw)
    496 {
    497 	switch (hw->phy.type) {
    498 	case ixgbe_phy_sfp_avago:
    499 	case ixgbe_phy_sfp_ftl:
    500 	case ixgbe_phy_sfp_intel:
    501 	case ixgbe_phy_sfp_unknown:
    502 	case ixgbe_phy_sfp_passive_tyco:
    503 	case ixgbe_phy_sfp_passive_unknown:
    504 		return TRUE;
    505 	default:
    506 		return FALSE;
    507 	}
    508 }
    509 
    510 /* Workaround to make 8.0 buildable */
    511 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
    512 static __inline int
    513 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
    514 {
    515 #ifdef ALTQ
    516         if (ALTQ_IS_ENABLED(&ifp->if_snd))
    517                 return (1);
    518 #endif
    519         return (!buf_ring_empty(br));
    520 }
    521 #endif
    522 
    523 /*
    524 ** Find the number of unrefreshed RX descriptors
    525 */
    526 static inline u16
    527 ixgbe_rx_unrefreshed(struct rx_ring *rxr)
    528 {
    529 	struct adapter  *adapter = rxr->adapter;
    530 
    531 	if (rxr->next_to_check > rxr->next_to_refresh)
    532 		return (rxr->next_to_check - rxr->next_to_refresh - 1);
    533 	else
    534 		return ((adapter->num_rx_desc + rxr->next_to_check) -
    535 		    rxr->next_to_refresh - 1);
    536 }
    537 
    538 #endif /* _IXGBE_H_ */
    539