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 ******************************************************************************/
40 #include <sys/param.h>
41 #include <sys/systm.h>
43 #include <sys/protosw.h>
44 #include <sys/socket.h>
45 #include <sys/malloc.h>
46 #include <sys/kernel.h>
47 #include <sys/module.h>
48 #include <sys/sockio.h>
51 #include <net/if_arp.h>
53 #include <net/ethernet.h>
54 #include <net/if_dl.h>
55 #include <net/if_media.h>
58 #include <net/if_types.h>
59 #include <net/if_vlan_var.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/in.h>
63 #include <netinet/if_ether.h>
64 #include <netinet/ip.h>
65 #include <netinet/ip6.h>
66 #include <netinet/tcp.h>
67 #include <netinet/tcp_lro.h>
68 #include <netinet/udp.h>
70 #include <machine/in_cksum.h>
73 #include <machine/bus.h>
75 #include <machine/resource.h>
78 #include <machine/clock.h>
79 #include <dev/pci/pcivar.h>
80 #include <dev/pci/pcireg.h>
82 #include <sys/sysctl.h>
83 #include <sys/endian.h>
84 #include <sys/taskqueue.h>
87 #include <machine/smp.h>
89 #include "ixgbe_api.h"
95 * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
96 * number of transmit descriptors allocated by the driver. Increasing this
97 * value allows the driver to queue more transmits. Each descriptor is 16
98 * bytes. Performance tests have show the 2K value to be optimal for top
101 #define DEFAULT_TXD 1024
102 #define PERFORM_TXD 2048
107 * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
108 * number of receive descriptors allocated for each RX queue. Increasing this
109 * value allows the driver to buffer more incoming packets. Each descriptor
110 * is 16 bytes. A receive buffer is also allocated for each descriptor.
112 * Note: with 8 rings and a dual port card, it is possible to bump up
113 * against the system mbuf pool limit, you can tune nmbclusters
114 * to adjust for this.
116 #define DEFAULT_RXD 1024
117 #define PERFORM_RXD 2048
121 /* Alignment for rings */
122 #define DBA_ALIGN 128
125 * This parameter controls the maximum no of times the driver will loop in
126 * the isr. Minimum Value = 1
131 * This is the max watchdog interval, ie. the time that can
132 * pass between any two TX clean operations, such only happening
133 * when the TX hardware is functioning.
135 #define IXV_WATCHDOG (10 * hz)
138 * This parameters control when the driver calls the routine to reclaim
139 * transmit descriptors.
141 #define IXV_TX_CLEANUP_THRESHOLD (adapter->num_tx_desc / 8)
142 #define IXV_TX_OP_THRESHOLD (adapter->num_tx_desc / 32)
144 #define IXV_MAX_FRAME_SIZE 0x3F00
146 /* Flow control constants */
147 #define IXV_FC_PAUSE 0xFFFF
148 #define IXV_FC_HI 0x20000
149 #define IXV_FC_LO 0x10000
151 /* Defines for printing debug information */
153 #define DEBUG_IOCTL 0
156 #define INIT_DEBUGOUT(S) if (DEBUG_INIT) printf(S "\n")
157 #define INIT_DEBUGOUT1(S, A) if (DEBUG_INIT) printf(S "\n", A)
158 #define INIT_DEBUGOUT2(S, A, B) if (DEBUG_INIT) printf(S "\n", A, B)
159 #define IOCTL_DEBUGOUT(S) if (DEBUG_IOCTL) printf(S "\n")
160 #define IOCTL_DEBUGOUT1(S, A) if (DEBUG_IOCTL) printf(S "\n", A)
161 #define IOCTL_DEBUGOUT2(S, A, B) if (DEBUG_IOCTL) printf(S "\n", A, B)
162 #define HW_DEBUGOUT(S) if (DEBUG_HW) printf(S "\n")
163 #define HW_DEBUGOUT1(S, A) if (DEBUG_HW) printf(S "\n", A)
164 #define HW_DEBUGOUT2(S, A, B) if (DEBUG_HW) printf(S "\n", A, B)
166 #define MAX_NUM_MULTICAST_ADDRESSES 128
167 #define IXV_EITR_DEFAULT 128
168 #define IXV_SCATTER 32
169 #define IXV_RX_HDR 128
171 #define IXV_TSO_SIZE 65535
172 #define IXV_BR_SIZE 4096
173 #define IXV_LINK_ITR 2000
174 #define TX_BUFFER_SIZE ((u32) 1514)
175 #define VFTA_SIZE 128
177 /* Offload bits in mbuf flag */
178 #if __FreeBSD_version >= 800000
179 #define CSUM_OFFLOAD (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
181 #define CSUM_OFFLOAD (CSUM_IP|CSUM_TCP|CSUM_UDP)
185 *****************************************************************************
188 * This array contains the list of Subvendor/Subdevice IDs on which the driver
191 *****************************************************************************
193 typedef struct _ixv_vendor_info_t {
194 unsigned int vendor_id;
195 unsigned int device_id;
196 unsigned int subvendor_id;
197 unsigned int subdevice_id;
217 * Bus dma allocation structure used by ixv_dma_malloc and ixv_dma_free.
219 struct ixv_dma_alloc {
220 bus_addr_t dma_paddr;
222 bus_dma_tag_t dma_tag;
223 bus_dmamap_t dma_map;
224 bus_dma_segment_t dma_seg;
230 ** Driver queue struct: this is the interrupt container
231 ** for the associated tx and rx ring.
234 struct adapter *adapter;
235 u32 msix; /* This queue's MSIX vector */
236 u32 eims; /* This queue's EIMS bit */
238 u32 eitr; /* cached reg */
239 struct resource *res;
243 struct task que_task;
244 struct taskqueue *tq;
249 * The transmit ring, one per queue
252 struct adapter *adapter;
257 union ixgbe_adv_tx_desc *tx_base;
258 struct ixv_dma_alloc txdma;
261 struct ixv_tx_buf *tx_buffers;
262 volatile u16 tx_avail;
276 * The Receive ring, one per rx queue
279 struct adapter *adapter;
282 union ixgbe_adv_rx_desc *rx_base;
283 struct ixv_dma_alloc rxdma;
291 struct ixv_rx_buf *rx_buffers;
295 u32 bytes; /* Used for AIM calc */
300 u64 rx_split_packets;
306 /* Our adapter structure */
311 struct ixgbe_osdep osdep;
314 struct resource *pci_mem;
315 struct resource *msix_mem;
318 * Interrupt resources: this set is
319 * either used for legacy, or for Link
323 struct resource *res;
325 struct ifmedia media;
326 struct callout timer;
332 eventhandler_tag vlan_attach;
333 eventhandler_tag vlan_detach;
338 /* Info about the board itself */
345 /* Mbuf cluster size */
348 /* Support for pluggable optics */
349 struct task mbx_task; /* Mailbox tasklet */
350 struct taskqueue *tq;
354 ** This is the irq holder, it has
355 ** and RX/TX pair or rings associated
358 struct ix_queue *queues;
362 * Allocated at run time, an array of rings.
364 struct tx_ring *tx_rings;
369 * Allocated at run time, an array of rings.
371 struct rx_ring *rx_rings;
374 u32 rx_process_limit;
376 /* Misc stats maintained by the driver */
377 unsigned long dropped_pkts;
378 unsigned long mbuf_defrag_failed;
379 unsigned long mbuf_header_failed;
380 unsigned long mbuf_packet_failed;
381 unsigned long no_tx_map_avail;
382 unsigned long no_tx_dma_setup;
383 unsigned long watchdog_events;
384 unsigned long tso_tx;
385 unsigned long mbx_irq;
387 struct ixgbevf_hw_stats stats;
391 #define IXV_CORE_LOCK_INIT(_sc, _name) \
392 mtx_init(&(_sc)->core_mtx, _name, "IXV Core Lock", MTX_DEF)
393 #define IXV_CORE_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->core_mtx)
394 #define IXV_TX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->tx_mtx)
395 #define IXV_RX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->rx_mtx)
396 #define IXV_CORE_LOCK(_sc) mtx_lock(&(_sc)->core_mtx)
397 #define IXV_TX_LOCK(_sc) mtx_lock(&(_sc)->tx_mtx)
398 #define IXV_TX_TRYLOCK(_sc) mtx_trylock(&(_sc)->tx_mtx)
399 #define IXV_RX_LOCK(_sc) mtx_lock(&(_sc)->rx_mtx)
400 #define IXV_CORE_UNLOCK(_sc) mtx_unlock(&(_sc)->core_mtx)
401 #define IXV_TX_UNLOCK(_sc) mtx_unlock(&(_sc)->tx_mtx)
402 #define IXV_RX_UNLOCK(_sc) mtx_unlock(&(_sc)->rx_mtx)
403 #define IXV_CORE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->core_mtx, MA_OWNED)
404 #define IXV_TX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->tx_mtx, MA_OWNED)
406 /* Workaround to make 8.0 buildable */
407 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
409 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
412 if (ALTQ_IS_ENABLED(&ifp->if_snd))
415 return (!buf_ring_empty(br));
420 ** Find the number of unrefreshed RX descriptors
423 ixv_rx_unrefreshed(struct rx_ring *rxr)
425 struct adapter *adapter = rxr->adapter;
427 if (rxr->next_to_check > rxr->next_to_refresh)
428 return (rxr->next_to_check - rxr->next_to_refresh - 1);
430 return ((adapter->num_rx_desc + rxr->next_to_check) -
431 rxr->next_to_refresh - 1);