1 /******************************************************************************
3 Copyright (c) 2001-2012, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
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.
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.
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.
32 ******************************************************************************/
33 /*$FreeBSD: src/sys/dev/ixgbe/ixgbe.h,v 1.26 2012/04/23 22:05:09 bz Exp $*/
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #if __FreeBSD_version >= 800000
43 #include <sys/buf_ring.h>
46 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <sys/malloc.h>
49 #include <sys/kernel.h>
50 #include <sys/module.h>
51 #include <sys/sockio.h>
54 #include <net/if_arp.h>
55 #include <net/ifq_var.h>
57 #include <net/ethernet.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
62 #include <net/if_types.h>
63 #include <net/vlan/if_vlan_var.h>
64 #include <net/vlan/if_vlan_ether.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/in.h>
68 #include <netinet/if_ether.h>
69 #include <netinet/ip.h>
70 #include <netinet/ip6.h>
71 #include <netinet/tcp.h>
73 #include <netinet/tcp_lro.h> /* XXX: IPv4 only */
75 #include <netinet/udp.h>
77 #include <sys/in_cksum.h>
81 #include <sys/resource.h>
84 #include <machine/clock.h>
85 #include <bus/pci/pcivar.h>
86 #include <bus/pci/pcireg.h>
88 #include <sys/sysctl.h>
89 #include <sys/endian.h>
90 #include <sys/taskqueue.h>
91 #include <machine/smp.h>
93 #include <sys/spinlock.h>
94 #include <sys/spinlock2.h>
97 #include <sys/ieee1588.h>
100 #include "ixgbe_api.h"
101 #include "ixgbe_defines.h"
106 * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
107 * number of transmit descriptors allocated by the driver. Increasing this
108 * value allows the driver to queue more transmits. Each descriptor is 16
109 * bytes. Performance tests have show the 2K value to be optimal for top
112 #define DEFAULT_TXD 1024
113 #define PERFORM_TXD 2048
118 * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
119 * number of receive descriptors allocated for each RX queue. Increasing this
120 * value allows the driver to buffer more incoming packets. Each descriptor
121 * is 16 bytes. A receive buffer is also allocated for each descriptor.
123 * Note: with 8 rings and a dual port card, it is possible to bump up
124 * against the system mbuf pool limit, you can tune nmbclusters
125 * to adjust for this.
127 #define DEFAULT_RXD 1024
128 #define PERFORM_RXD 2048
132 /* Alignment for rings */
133 #define DBA_ALIGN 128
136 * This parameter controls the maximum no of times the driver will loop in
137 * the isr. Minimum Value = 1
142 * This is the max watchdog interval, ie. the time that can
143 * pass between any two TX clean operations, such only happening
144 * when the TX hardware is functioning.
146 #define IXGBE_WATCHDOG (10 * hz)
149 * This parameters control when the driver calls the routine to reclaim
150 * transmit descriptors.
152 #define IXGBE_TX_CLEANUP_THRESHOLD (adapter->num_tx_desc / 8)
153 #define IXGBE_TX_OP_THRESHOLD (adapter->num_tx_desc / 32)
155 #define IXGBE_MAX_FRAME_SIZE 0x3F00
157 /* Flow control constants */
158 #define IXGBE_FC_PAUSE 0xFFFF
159 #define IXGBE_FC_HI 0x20000
160 #define IXGBE_FC_LO 0x10000
162 /* Keep older OS drivers building... */
163 #if !defined(SYSCTL_ADD_UQUAD)
164 #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
167 /* Defines for printing debug information */
169 #define DEBUG_IOCTL 0
172 #define INIT_DEBUGOUT(S) if (DEBUG_INIT) kprintf(S "\n")
173 #define INIT_DEBUGOUT1(S, A) if (DEBUG_INIT) kprintf(S "\n", A)
174 #define INIT_DEBUGOUT2(S, A, B) if (DEBUG_INIT) kprintf(S "\n", A, B)
175 #define IOCTL_DEBUGOUT(S) if (DEBUG_IOCTL) kprintf(S "\n")
176 #define IOCTL_DEBUGOUT1(S, A) if (DEBUG_IOCTL) kprintf(S "\n", A)
177 #define IOCTL_DEBUGOUT2(S, A, B) if (DEBUG_IOCTL) kprintf(S "\n", A, B)
178 #define HW_DEBUGOUT(S) if (DEBUG_HW) kprintf(S "\n")
179 #define HW_DEBUGOUT1(S, A) if (DEBUG_HW) kprintf(S "\n", A)
180 #define HW_DEBUGOUT2(S, A, B) if (DEBUG_HW) kprintf(S "\n", A, B)
182 #define MAX_NUM_MULTICAST_ADDRESSES 128
183 #define IXGBE_82598_SCATTER 100
184 #define IXGBE_82599_SCATTER 32
185 #define MSIX_82598_BAR 3
186 #define MSIX_82599_BAR 4
187 #define IXGBE_TSO_SIZE 262140
188 #define IXGBE_TX_BUFFER_SIZE ((u32) 1514)
189 #define IXGBE_RX_HDR 128
190 #define IXGBE_VFTA_SIZE 128
191 #define IXGBE_BR_SIZE 4096
192 #define IXGBE_QUEUE_MIN_FREE 32
193 #define IXGBE_QUEUE_IDLE 1
194 #define IXGBE_QUEUE_WORKING 2
195 #define IXGBE_QUEUE_HUNG 4
196 #define IXGBE_QUEUE_DEPLETED 8
198 /* Offload bits in mbuf flag */
199 #if __FreeBSD_version >= 800000
200 #define CSUM_OFFLOAD (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
202 #define CSUM_OFFLOAD (CSUM_IP|CSUM_TCP|CSUM_UDP)
205 /* For 6.X code compatibility */
206 #if !defined(ETHER_BPF_MTAP)
207 #define ETHER_BPF_MTAP BPF_MTAP
211 * Interrupt Moderation parameters
213 #define IXGBE_LOW_LATENCY 128
214 #define IXGBE_AVE_LATENCY 400
215 #define IXGBE_BULK_LATENCY 1200
216 #define IXGBE_LINK_ITR 2000
219 *****************************************************************************
222 * This array contains the list of Subvendor/Subdevice IDs on which the driver
225 *****************************************************************************
227 typedef struct _ixgbe_vendor_info_t {
228 unsigned int vendor_id;
229 unsigned int device_id;
230 unsigned int subvendor_id;
231 unsigned int subdevice_id;
233 } ixgbe_vendor_info_t;
236 struct ixgbe_tx_buf {
242 struct ixgbe_rx_buf {
251 * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
253 struct ixgbe_dma_alloc {
254 bus_addr_t dma_paddr;
256 bus_dma_tag_t dma_tag;
257 bus_dmamap_t dma_map;
258 bus_dma_segment_t dma_seg;
264 ** Driver queue struct: this is the interrupt container
265 ** for the associated tx and rx ring.
268 struct adapter *adapter;
269 u32 msix; /* This queue's MSIX vector */
270 u32 eims; /* This queue's EIMS bit */
272 struct resource *res;
276 struct task que_task;
277 struct taskqueue *tq;
279 struct lwkt_serialize serializer;
283 * The transmit ring, one per queue
286 struct adapter *adapter;
291 union ixgbe_adv_tx_desc *tx_base;
292 struct ixgbe_dma_alloc txdma;
295 struct ixgbe_tx_buf *tx_buffers;
296 volatile u16 tx_avail;
300 #if __FreeBSD_version >= 800000
307 u32 bytes; /* used for AIM */
316 * The Receive ring, one per rx queue
319 struct adapter *adapter;
322 union ixgbe_adv_rx_desc *rx_base;
323 struct ixgbe_dma_alloc rxdma;
335 struct ixgbe_rx_buf *rx_buffers;
339 u32 bytes; /* Used for AIM calc */
344 u64 rx_split_packets;
354 /* Our adapter structure */
359 struct ixgbe_osdep osdep;
362 struct resource *pci_mem;
363 struct resource *msix_mem;
366 * Interrupt resources: this set is
367 * either used for legacy, or for Link
371 struct resource *res;
374 struct ifmedia media;
375 struct callout timer;
379 struct lock core_lock;
380 struct spinlock mcast_spin;
382 eventhandler_tag vlan_attach;
383 eventhandler_tag vlan_detach;
389 ** Shadow VFTA table, this is needed because
390 ** the real vlan filter table gets cleared during
391 ** a soft reset and the driver needs to be able
394 u32 shadow_vfta[IXGBE_VFTA_SIZE];
396 /* Info about the interface */
398 u32 fc; /* local flow ctrl setting */
399 int advertise; /* link speeds */
407 /* Mbuf cluster size */
410 /* Support for pluggable optics */
412 struct task link_task; /* Link tasklet */
413 struct task mod_task; /* SFP tasklet */
414 struct task msf_task; /* Multispeed Fiber */
417 struct task fdir_task;
419 struct taskqueue *tq;
423 ** This is the irq holder, it has
424 ** and RX/TX pair or rings associated
427 struct ix_queue *queues;
431 * Allocated at run time, an array of rings.
433 struct tx_ring *tx_rings;
438 * Allocated at run time, an array of rings.
440 struct rx_ring *rx_rings;
443 u32 rx_process_limit;
445 /* Multicast array memory */
448 /* Misc stats maintained by the driver */
449 unsigned long dropped_pkts;
450 unsigned long mbuf_defrag_failed;
451 unsigned long mbuf_header_failed;
452 unsigned long mbuf_packet_failed;
453 unsigned long no_tx_map_avail;
454 unsigned long no_tx_dma_setup;
455 unsigned long watchdog_events;
456 unsigned long tso_tx;
457 unsigned long link_irq;
459 struct ixgbe_hw_stats stats;
461 struct lwkt_serialize serializer;
462 struct sysctl_ctx_list sysctl_ctx;
463 struct sysctl_oid *sysctl_tree;
466 /* Precision Time Sync (IEEE 1588) defines */
467 #define ETHERTYPE_IEEE1588 0x88F7
468 #define PICOSECS_PER_TICK 20833
469 #define TSYNC_UDP_PORT 319 /* UDP port for the protocol */
470 #define IXGBE_ADVTXD_TSTAMP 0x00080000
473 #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
474 lockinit(&(_sc)->core_lock, _name, 0, LK_CANRECURSE)
475 #define IXGBE_CORE_LOCK_DESTROY(_sc) lockuninit(&(_sc)->core_lock)
476 #define IXGBE_TX_LOCK_DESTROY(_sc) lockuninit(&(_sc)->tx_lock)
477 #define IXGBE_RX_LOCK_DESTROY(_sc) lockuninit(&(_sc)->rx_lock)
478 #define IXGBE_CORE_LOCK(_sc) lockmgr(&(_sc)->core_lock, LK_EXCLUSIVE)
479 #define IXGBE_TX_LOCK(_sc) lockmgr(&(_sc)->tx_lock, LK_EXCLUSIVE)
480 #define IXGBE_TX_TRYLOCK(_sc) lockmgr(&(_sc)->tx_mtx, LK_EXCLUSIVE|LK_NOWAIT)
481 #define IXGBE_RX_LOCK(_sc) lockmgr(&(_sc)->rx_lock, LK_EXCLUSIVE)
482 #define IXGBE_CORE_UNLOCK(_sc) lockmgr(&(_sc)->core_lock, LK_RELEASE)
483 #define IXGBE_TX_UNLOCK(_sc) lockmgr(&(_sc)->tx_lock, LK_RELEASE)
484 #define IXGBE_RX_UNLOCK(_sc) lockmgr(&(_sc)->rx_lock, LK_RELEASE)
485 #define IXGBE_CORE_LOCK_ASSERT(_sc) KKASSERT(lockstatus(&(_sc)->core_lock, curthread) !=0)
486 #define IXGBE_TX_LOCK_ASSERT(_sc) KKASSERT(lockstatus(&(_sc)->tx_lock, curthread) != 0)
490 ixgbe_is_sfp(struct ixgbe_hw *hw)
492 switch (hw->phy.type) {
493 case ixgbe_phy_sfp_avago:
494 case ixgbe_phy_sfp_ftl:
495 case ixgbe_phy_sfp_intel:
496 case ixgbe_phy_sfp_unknown:
497 case ixgbe_phy_sfp_passive_tyco:
498 case ixgbe_phy_sfp_passive_unknown:
505 /* Workaround to make 8.0 buildable */
506 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
508 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
511 if (ALTQ_IS_ENABLED(&ifp->if_snd))
514 return (!buf_ring_empty(br));
519 ** Find the number of unrefreshed RX descriptors
522 ixgbe_rx_unrefreshed(struct rx_ring *rxr)
524 struct adapter *adapter = rxr->adapter;
526 if (rxr->next_to_check > rxr->next_to_refresh)
527 return (rxr->next_to_check - rxr->next_to_refresh - 1);
529 return ((adapter->num_rx_desc + rxr->next_to_check) -
530 rxr->next_to_refresh - 1);
533 #endif /* _IXGBE_H_ */