ixgbe.h revision 1.5 1 /******************************************************************************
2
3 Copyright (c) 2001-2012, 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: head/sys/dev/ixgbe/ixgbe.h 234620 2012-04-23 22:05:09Z bz $*/
62 /*$NetBSD: ixgbe.h,v 1.5 2015/04/02 09:26:55 msaitoh 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 262140
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_MIN_FREE 32
207 #define IXGBE_QUEUE_IDLE 1
208 #define IXGBE_QUEUE_WORKING 2
209 #define IXGBE_QUEUE_HUNG 4
210 #define IXGBE_QUEUE_DEPLETED 8
211
212 /* Offload bits in mbuf flag */
213 #define M_CSUM_OFFLOAD \
214 (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4|M_CSUM_UDPv6|M_CSUM_TCPv6)
215
216 /*
217 * Interrupt Moderation parameters
218 */
219 #define IXGBE_LOW_LATENCY 128
220 #define IXGBE_AVE_LATENCY 400
221 #define IXGBE_BULK_LATENCY 1200
222 #define IXGBE_LINK_ITR 2000
223
224 /*
225 *****************************************************************************
226 * vendor_info_array
227 *
228 * This array contains the list of Subvendor/Subdevice IDs on which the driver
229 * should load.
230 *
231 *****************************************************************************
232 */
233 typedef struct _ixgbe_vendor_info_t {
234 unsigned int vendor_id;
235 unsigned int device_id;
236 unsigned int subvendor_id;
237 unsigned int subdevice_id;
238 unsigned int index;
239 } ixgbe_vendor_info_t;
240
241
242 struct ixgbe_tx_buf {
243 u32 eop_index;
244 struct mbuf *m_head;
245 bus_dmamap_t map;
246 };
247
248 struct ixgbe_rx_buf {
249 struct mbuf *m_head;
250 struct mbuf *m_pack;
251 struct mbuf *fmp;
252 bus_dmamap_t hmap;
253 bus_dmamap_t pmap;
254 };
255
256 /*
257 * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
258 */
259 struct ixgbe_dma_alloc {
260 bus_addr_t dma_paddr;
261 void *dma_vaddr;
262 ixgbe_dma_tag_t *dma_tag;
263 bus_dmamap_t dma_map;
264 bus_dma_segment_t dma_seg;
265 bus_size_t dma_size;
266 };
267
268 /*
269 ** Driver queue struct: this is the interrupt container
270 ** for the associated tx and rx ring.
271 */
272 struct ix_queue {
273 struct adapter *adapter;
274 u32 msix; /* This queue's MSIX vector */
275 u32 eims; /* This queue's EIMS bit */
276 u32 eitr_setting;
277 struct resource *res;
278 void *tag;
279 struct tx_ring *txr;
280 struct rx_ring *rxr;
281 void *que_si;
282 u64 irqs;
283 char namebuf[32];
284 char evnamebuf[32];
285 };
286
287 /*
288 * The transmit ring, one per queue
289 */
290 struct tx_ring {
291 struct adapter *adapter;
292 kmutex_t tx_mtx;
293 u32 me;
294 int queue_status;
295 struct timeval watchdog_time;
296 union ixgbe_adv_tx_desc *tx_base;
297 struct ixgbe_dma_alloc txdma;
298 u32 next_avail_desc;
299 u32 next_to_clean;
300 struct ixgbe_tx_buf *tx_buffers;
301 volatile u16 tx_avail;
302 u32 txd_cmd;
303 ixgbe_dma_tag_t *txtag;
304 char mtx_name[16];
305 #if __FreeBSD_version >= 800000
306 struct buf_ring *br;
307 #endif
308 #ifdef IXGBE_FDIR
309 u16 atr_sample;
310 u16 atr_count;
311 #endif
312 u32 bytes; /* used for AIM */
313 u32 packets;
314 /* Soft Stats */
315 struct evcnt no_desc_avail;
316 struct evcnt total_packets;
317 };
318
319
320 /*
321 * The Receive ring, one per rx queue
322 */
323 struct rx_ring {
324 struct adapter *adapter;
325 kmutex_t rx_mtx;
326 u32 me;
327 union ixgbe_adv_rx_desc *rx_base;
328 struct ixgbe_dma_alloc rxdma;
329 #ifdef LRO
330 struct lro_ctrl lro;
331 #endif /* LRO */
332 bool lro_enabled;
333 bool hdr_split;
334 bool hw_rsc;
335 bool discard;
336 bool vtag_strip;
337 u32 next_to_refresh;
338 u32 next_to_check;
339 char mtx_name[16];
340 struct ixgbe_rx_buf *rx_buffers;
341 ixgbe_dma_tag_t *htag;
342 ixgbe_dma_tag_t *ptag;
343
344 u32 bytes; /* Used for AIM calc */
345 u32 packets;
346
347 /* Soft stats */
348 struct evcnt rx_irq;
349 struct evcnt rx_split_packets;
350 struct evcnt rx_packets;
351 struct evcnt rx_bytes;
352 struct evcnt rx_discarded;
353 struct evcnt no_jmbuf;
354 u64 rsc_num;
355 #ifdef IXGBE_FDIR
356 u64 flm;
357 #endif
358 };
359
360 /* Our adapter structure */
361 struct adapter {
362 struct ifnet *ifp;
363 struct ixgbe_hw hw;
364
365 struct ixgbe_osdep osdep;
366 device_t dev;
367
368 struct resource *pci_mem;
369 struct resource *msix_mem;
370
371 /*
372 * Interrupt resources: this set is
373 * either used for legacy, or for Link
374 * when doing MSIX
375 */
376 void *tag;
377 struct resource *res;
378
379 struct ifmedia media;
380 callout_t timer;
381 int msix;
382 int if_flags;
383
384 kmutex_t core_mtx;
385
386 unsigned int num_queues;
387
388 /*
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
392 ** to repopulate it.
393 */
394 u32 shadow_vfta[IXGBE_VFTA_SIZE];
395
396 /* Info about the interface */
397 u32 optics;
398 u32 fc; /* local flow ctrl setting */
399 int advertise; /* link speeds */
400 bool link_active;
401 u16 max_frame_size;
402 u16 num_segs;
403 u32 link_speed;
404 bool link_up;
405 u32 linkvec;
406
407 /* Mbuf cluster size */
408 u32 rx_mbuf_sz;
409
410 /* Support for pluggable optics */
411 bool sfp_probe;
412 void *link_si; /* Link tasklet */
413 void *mod_si; /* SFP tasklet */
414 void *msf_si; /* Multispeed Fiber */
415 #ifdef IXGBE_FDIR
416 int fdir_reinit;
417 void *fdir_si;
418 #endif
419
420 /*
421 ** Queues:
422 ** This is the irq holder, it has
423 ** and RX/TX pair or rings associated
424 ** with it.
425 */
426 struct ix_queue *queues;
427
428 /*
429 * Transmit rings:
430 * Allocated at run time, an array of rings.
431 */
432 struct tx_ring *tx_rings;
433 int num_tx_desc;
434
435 /*
436 * Receive rings:
437 * Allocated at run time, an array of rings.
438 */
439 struct rx_ring *rx_rings;
440 int num_rx_desc;
441 u64 que_mask;
442 u32 rx_process_limit;
443
444 /* Multicast array memory */
445 u8 *mta;
446
447 /* Misc stats maintained by the driver */
448 struct evcnt dropped_pkts;
449 struct evcnt mbuf_defrag_failed;
450 struct evcnt mbuf_header_failed;
451 struct evcnt mbuf_packet_failed;
452 struct evcnt no_tx_map_avail;
453 struct evcnt efbig_tx_dma_setup;
454 struct evcnt efbig2_tx_dma_setup;
455 struct evcnt m_defrag_failed;
456 struct evcnt einval_tx_dma_setup;
457 struct evcnt other_tx_dma_setup;
458 struct evcnt eagain_tx_dma_setup;
459 struct evcnt enomem_tx_dma_setup;
460 struct evcnt watchdog_events;
461 struct evcnt tso_err;
462 struct evcnt tso_tx;
463 struct evcnt link_irq;
464 struct evcnt morerx;
465 struct evcnt moretx;
466 struct evcnt txloops;
467 struct evcnt handleq;
468 struct evcnt req;
469
470 struct ixgbe_hw_stats stats;
471 struct sysctllog *sysctllog;
472 ixgbe_extmem_head_t jcl_head;
473 };
474
475 /* Precision Time Sync (IEEE 1588) defines */
476 #define ETHERTYPE_IEEE1588 0x88F7
477 #define PICOSECS_PER_TICK 20833
478 #define TSYNC_UDP_PORT 319 /* UDP port for the protocol */
479 #define IXGBE_ADVTXD_TSTAMP 0x00080000
480
481
482 #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
483 mutex_init(&(_sc)->core_mtx, MUTEX_DEFAULT, IPL_SOFTNET)
484 #define IXGBE_CORE_LOCK_DESTROY(_sc) mutex_destroy(&(_sc)->core_mtx)
485 #define IXGBE_TX_LOCK_DESTROY(_sc) mutex_destroy(&(_sc)->tx_mtx)
486 #define IXGBE_RX_LOCK_DESTROY(_sc) mutex_destroy(&(_sc)->rx_mtx)
487 #define IXGBE_CORE_LOCK(_sc) mutex_enter(&(_sc)->core_mtx)
488 #define IXGBE_TX_LOCK(_sc) mutex_enter(&(_sc)->tx_mtx)
489 #define IXGBE_TX_TRYLOCK(_sc) mutex_tryenter(&(_sc)->tx_mtx)
490 #define IXGBE_RX_LOCK(_sc) mutex_enter(&(_sc)->rx_mtx)
491 #define IXGBE_CORE_UNLOCK(_sc) mutex_exit(&(_sc)->core_mtx)
492 #define IXGBE_TX_UNLOCK(_sc) mutex_exit(&(_sc)->tx_mtx)
493 #define IXGBE_RX_UNLOCK(_sc) mutex_exit(&(_sc)->rx_mtx)
494 #define IXGBE_CORE_LOCK_ASSERT(_sc) KASSERT(mutex_owned(&(_sc)->core_mtx))
495 #define IXGBE_TX_LOCK_ASSERT(_sc) KASSERT(mutex_owned(&(_sc)->tx_mtx))
496
497
498 static inline bool
499 ixgbe_is_sfp(struct ixgbe_hw *hw)
500 {
501 switch (hw->phy.type) {
502 case ixgbe_phy_sfp_avago:
503 case ixgbe_phy_sfp_ftl:
504 case ixgbe_phy_sfp_intel:
505 case ixgbe_phy_sfp_unknown:
506 case ixgbe_phy_sfp_passive_tyco:
507 case ixgbe_phy_sfp_passive_unknown:
508 return TRUE;
509 default:
510 return FALSE;
511 }
512 }
513
514 /* Workaround to make 8.0 buildable */
515 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
516 static __inline int
517 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
518 {
519 #ifdef ALTQ
520 if (ALTQ_IS_ENABLED(&ifp->if_snd))
521 return (1);
522 #endif
523 return (!buf_ring_empty(br));
524 }
525 #endif
526
527 /*
528 ** Find the number of unrefreshed RX descriptors
529 */
530 static inline u16
531 ixgbe_rx_unrefreshed(struct rx_ring *rxr)
532 {
533 struct adapter *adapter = rxr->adapter;
534
535 if (rxr->next_to_check > rxr->next_to_refresh)
536 return (rxr->next_to_check - rxr->next_to_refresh - 1);
537 else
538 return ((adapter->num_rx_desc + rxr->next_to_check) -
539 rxr->next_to_refresh - 1);
540 }
541
542 #endif /* _IXGBE_H_ */
543