1 /******************************************************************************
3 Copyright (c) 2001-2009, 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>
88 #include <sys/ioccom.h>
92 #include "ixgbe_api.h"
97 * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
98 * number of transmit descriptors allocated by the driver. Increasing this
99 * value allows the driver to queue more transmits. Each descriptor is 16
100 * bytes. Performance tests have show the 2K value to be optimal for top
103 #define DEFAULT_TXD 1024
104 #define PERFORM_TXD 2048
109 * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
110 * number of receive descriptors allocated for each RX queue. Increasing this
111 * value allows the driver to buffer more incoming packets. Each descriptor
112 * is 16 bytes. A receive buffer is also allocated for each descriptor.
114 * Note: with 8 rings and a dual port card, it is possible to bump up
115 * against the system mbuf pool limit, you can tune nmbclusters
116 * to adjust for this.
118 #define DEFAULT_RXD 1024
119 #define PERFORM_RXD 2048
123 /* Alignment for rings */
124 #define DBA_ALIGN 128
127 * This parameter controls the maximum no of times the driver will loop in
128 * the isr. Minimum Value = 1
133 * This parameter controls the duration of transmit watchdog timer.
135 #define IXGBE_TX_TIMEOUT 5 /* set to 5 seconds */
138 * This parameters control when the driver calls the routine to reclaim
139 * transmit descriptors.
141 #define IXGBE_TX_CLEANUP_THRESHOLD (adapter->num_tx_desc / 8)
142 #define IXGBE_TX_OP_THRESHOLD (adapter->num_tx_desc / 32)
144 #define IXGBE_MAX_FRAME_SIZE 0x3F00
146 /* Flow control constants */
147 #define IXGBE_FC_PAUSE 0x680
148 #define IXGBE_FC_HI 0x20000
149 #define IXGBE_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 IXGBE_82598_SCATTER 100
168 #define IXGBE_82599_SCATTER 32
169 #define MSIX_82598_BAR 3
170 #define MSIX_82599_BAR 4
171 #define IXGBE_TSO_SIZE 65535
172 #define IXGBE_TX_BUFFER_SIZE ((u32) 1514)
173 #define IXGBE_RX_HDR 128
174 #define CSUM_OFFLOAD 7 /* Bits in csum flags */
176 /* The number of MSIX messages the 82598 supports */
177 #define IXGBE_MSGS 18
179 /* For 6.X code compatibility */
180 #if !defined(ETHER_BPF_MTAP)
181 #define ETHER_BPF_MTAP BPF_MTAP
184 #if __FreeBSD_version < 700000
190 * Interrupt Moderation parameters
192 #define IXGBE_LOW_LATENCY 128
193 #define IXGBE_AVE_LATENCY 400
194 #define IXGBE_BULK_LATENCY 1200
195 #define IXGBE_LINK_ITR 2000
197 /* Header split args for get_bug */
198 #define IXGBE_CLEAN_HDR 1
199 #define IXGBE_CLEAN_PKT 2
200 #define IXGBE_CLEAN_ALL 3
202 /* Used for auto RX queue configuration */
206 *****************************************************************************
209 * This array contains the list of Subvendor/Subdevice IDs on which the driver
212 *****************************************************************************
214 typedef struct _ixgbe_vendor_info_t {
215 unsigned int vendor_id;
216 unsigned int device_id;
217 unsigned int subvendor_id;
218 unsigned int subdevice_id;
220 } ixgbe_vendor_info_t;
223 struct ixgbe_tx_buf {
229 struct ixgbe_rx_buf {
236 * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
238 struct ixgbe_dma_alloc {
239 bus_addr_t dma_paddr;
241 bus_dma_tag_t dma_tag;
242 bus_dmamap_t dma_map;
243 bus_dma_segment_t dma_seg;
249 * The transmit ring, one per tx queue
252 struct adapter *adapter;
258 union ixgbe_adv_tx_desc *tx_base;
260 struct ixgbe_dma_alloc txdma;
262 struct taskqueue *tq;
263 u32 next_avail_tx_desc;
264 u32 next_tx_to_clean;
265 struct ixgbe_tx_buf *tx_buffers;
266 volatile u16 tx_avail;
271 u32 no_tx_desc_avail;
279 * The Receive ring, one per rx queue
282 struct adapter *adapter;
289 struct taskqueue *tq;
290 union ixgbe_adv_rx_desc *rx_base;
291 struct ixgbe_dma_alloc rxdma;
293 unsigned int last_cleaned;
294 unsigned int next_to_check;
295 struct ixgbe_rx_buf *rx_buffers;
297 bus_dmamap_t spare_map;
302 u32 bytes; /* Used for AIM calc */
307 u64 rx_split_packets;
312 /* Our adapter structure */
317 struct ixgbe_osdep osdep;
320 struct resource *pci_mem;
321 struct resource *msix_mem;
324 * Interrupt resources:
326 void *tag[IXGBE_MSGS];
327 struct resource *res[IXGBE_MSGS];
330 struct ifmedia media;
331 struct callout timer;
337 /* Info about the board itself */
346 u32 tx_abs_int_delay;
348 u32 rx_abs_int_delay;
350 #ifdef IXGBE_HW_VLAN_SUPPORT
351 eventhandler_tag vlan_attach;
352 eventhandler_tag vlan_detach;
355 /* Mbuf cluster size */
358 /* Support for pluggable optics */
360 struct task link_task; /* Link tasklet */
361 struct task mod_task; /* SFP tasklet */
362 struct task msf_task; /* Multispeed Fiber tasklet */
363 struct taskqueue *tq;
367 * Allocated at run time, an array of rings.
369 struct tx_ring *tx_rings;
375 * Allocated at run time, an array of rings.
377 struct rx_ring *rx_rings;
381 u32 rx_process_limit;
383 #ifdef IXGBE_TIMESYNC
389 /* Misc stats maintained by the driver */
390 unsigned long dropped_pkts;
391 unsigned long mbuf_defrag_failed;
392 unsigned long mbuf_header_failed;
393 unsigned long mbuf_packet_failed;
394 unsigned long no_tx_map_avail;
395 unsigned long no_tx_dma_setup;
396 unsigned long watchdog_events;
397 unsigned long tso_tx;
398 unsigned long link_irq;
400 struct ixgbe_hw_stats stats;
403 #ifdef IXGBE_TIMESYNC
404 /* Precision Time Sync (IEEE 1588) defines */
405 #define ETHERTYPE_IEEE1588 0x88F7
406 #define PICOSECS_PER_TICK 20833
407 #define TSYNC_UDP_PORT 319 /* UDP port for the protocol */
408 #define IXGBE_ADVTXD_TSTAMP 0x00080000
410 /* TIMESYNC IOCTL defines */
411 #define IXGBE_TIMESYNC_READTS _IOWR('i', 127, struct ixgbe_tsync_read)
412 #define IXGBE_TIMESTAMP 5 /* A unique return value */
414 /* Used in the READTS IOCTL */
415 struct ixgbe_tsync_read {
416 int read_current_time;
417 struct timespec system_time;
422 unsigned char srcid[6];
427 #endif /* IXGBE_TIMESYNC */
429 #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
430 mtx_init(&(_sc)->core_mtx, _name, "IXGBE Core Lock", MTX_DEF)
431 #define IXGBE_CORE_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->core_mtx)
432 #define IXGBE_TX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->tx_mtx)
433 #define IXGBE_RX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->rx_mtx)
434 #define IXGBE_CORE_LOCK(_sc) mtx_lock(&(_sc)->core_mtx)
435 #define IXGBE_TX_LOCK(_sc) mtx_lock(&(_sc)->tx_mtx)
436 #define IXGBE_TX_TRYLOCK(_sc) mtx_trylock(&(_sc)->tx_mtx)
437 #define IXGBE_RX_LOCK(_sc) mtx_lock(&(_sc)->rx_mtx)
438 #define IXGBE_CORE_UNLOCK(_sc) mtx_unlock(&(_sc)->core_mtx)
439 #define IXGBE_TX_UNLOCK(_sc) mtx_unlock(&(_sc)->tx_mtx)
440 #define IXGBE_RX_UNLOCK(_sc) mtx_unlock(&(_sc)->rx_mtx)
441 #define IXGBE_CORE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->core_mtx, MA_OWNED)
442 #define IXGBE_TX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->tx_mtx, MA_OWNED)
446 ixgbe_is_sfp(struct ixgbe_hw *hw)
448 switch (hw->phy.type) {
449 case ixgbe_phy_sfp_avago:
450 case ixgbe_phy_sfp_ftl:
451 case ixgbe_phy_sfp_intel:
452 case ixgbe_phy_sfp_unknown:
453 case ixgbe_phy_tw_tyco:
454 case ixgbe_phy_tw_unknown:
461 #endif /* _IXGBE_H_ */