]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ixgbe/ixv.h
MFV of 255902, tzdata2013f
[FreeBSD/FreeBSD.git] / sys / dev / ixgbe / ixv.h
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 /*$FreeBSD$*/
34
35
36 #ifndef _IXV_H_
37 #define _IXV_H_
38
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/mbuf.h>
43 #include <sys/protosw.h>
44 #include <sys/socket.h>
45 #include <sys/malloc.h>
46 #include <sys/kernel.h>
47 #include <sys/lock.h>
48 #include <sys/module.h>
49 #include <sys/mutex.h>
50 #include <sys/sockio.h>
51 #include <sys/eventhandler.h>
52
53 #include <net/if.h>
54 #include <net/if_var.h>
55 #include <net/if_arp.h>
56 #include <net/bpf.h>
57 #include <net/ethernet.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
60
61 #include <net/bpf.h>
62 #include <net/if_types.h>
63 #include <net/if_vlan_var.h>
64
65 #include <netinet/in_systm.h>
66 #include <netinet/in.h>
67 #include <netinet/if_ether.h>
68 #include <netinet/ip.h>
69 #include <netinet/ip6.h>
70 #include <netinet/tcp.h>
71 #include <netinet/tcp_lro.h>
72 #include <netinet/udp.h>
73
74 #include <machine/in_cksum.h>
75
76 #include <sys/bus.h>
77 #include <machine/bus.h>
78 #include <sys/rman.h>
79 #include <machine/resource.h>
80 #include <vm/vm.h>
81 #include <vm/pmap.h>
82 #include <machine/clock.h>
83 #include <dev/pci/pcivar.h>
84 #include <dev/pci/pcireg.h>
85 #include <sys/proc.h>
86 #include <sys/sysctl.h>
87 #include <sys/endian.h>
88 #include <sys/taskqueue.h>
89 #include <sys/pcpu.h>
90 #include <sys/smp.h>
91 #include <machine/smp.h>
92
93 #include "ixgbe_api.h"
94 #include "ixgbe_vf.h"
95
96 /* Tunables */
97
98 /*
99  * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
100  * number of transmit descriptors allocated by the driver. Increasing this
101  * value allows the driver to queue more transmits. Each descriptor is 16
102  * bytes. Performance tests have show the 2K value to be optimal for top
103  * performance.
104  */
105 #define DEFAULT_TXD     1024
106 #define PERFORM_TXD     2048
107 #define MAX_TXD         4096
108 #define MIN_TXD         64
109
110 /*
111  * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
112  * number of receive descriptors allocated for each RX queue. Increasing this
113  * value allows the driver to buffer more incoming packets. Each descriptor
114  * is 16 bytes.  A receive buffer is also allocated for each descriptor. 
115  * 
116  * Note: with 8 rings and a dual port card, it is possible to bump up 
117  *      against the system mbuf pool limit, you can tune nmbclusters
118  *      to adjust for this.
119  */
120 #define DEFAULT_RXD     1024
121 #define PERFORM_RXD     2048
122 #define MAX_RXD         4096
123 #define MIN_RXD         64
124
125 /* Alignment for rings */
126 #define DBA_ALIGN       128
127
128 /*
129  * This parameter controls the maximum no of times the driver will loop in
130  * the isr. Minimum Value = 1
131  */
132 #define MAX_LOOP        10
133
134 /*
135  * This is the max watchdog interval, ie. the time that can
136  * pass between any two TX clean operations, such only happening
137  * when the TX hardware is functioning.
138  */
139 #define IXV_WATCHDOG                   (10 * hz)
140
141 /*
142  * This parameters control when the driver calls the routine to reclaim
143  * transmit descriptors.
144  */
145 #define IXV_TX_CLEANUP_THRESHOLD        (adapter->num_tx_desc / 8)
146 #define IXV_TX_OP_THRESHOLD             (adapter->num_tx_desc / 32)
147
148 #define IXV_MAX_FRAME_SIZE      0x3F00
149
150 /* Flow control constants */
151 #define IXV_FC_PAUSE            0xFFFF
152 #define IXV_FC_HI               0x20000
153 #define IXV_FC_LO               0x10000
154
155 /* Defines for printing debug information */
156 #define DEBUG_INIT  0
157 #define DEBUG_IOCTL 0
158 #define DEBUG_HW    0
159
160 #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
161 #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
162 #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
163 #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
164 #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
165 #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
166 #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
167 #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
168 #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
169
170 #define MAX_NUM_MULTICAST_ADDRESSES     128
171 #define IXV_EITR_DEFAULT                128
172 #define IXV_SCATTER                     32
173 #define IXV_RX_HDR                      128
174 #define MSIX_BAR                        3
175 #define IXV_TSO_SIZE                    65535
176 #define IXV_BR_SIZE                     4096
177 #define IXV_LINK_ITR                    2000
178 #define TX_BUFFER_SIZE          ((u32) 1514)
179 #define VFTA_SIZE                       128
180
181 /* Offload bits in mbuf flag */
182 #if __FreeBSD_version >= 800000
183 #define CSUM_OFFLOAD            (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
184 #else
185 #define CSUM_OFFLOAD            (CSUM_IP|CSUM_TCP|CSUM_UDP)
186 #endif
187
188 /*
189  *****************************************************************************
190  * vendor_info_array
191  * 
192  * This array contains the list of Subvendor/Subdevice IDs on which the driver
193  * should load.
194  * 
195  *****************************************************************************
196  */
197 typedef struct _ixv_vendor_info_t {
198         unsigned int    vendor_id;
199         unsigned int    device_id;
200         unsigned int    subvendor_id;
201         unsigned int    subdevice_id;
202         unsigned int    index;
203 } ixv_vendor_info_t;
204
205
206 struct ixv_tx_buf {
207         u32             eop_index;
208         struct mbuf     *m_head;
209         bus_dmamap_t    map;
210 };
211
212 struct ixv_rx_buf {
213         struct mbuf     *m_head;
214         struct mbuf     *m_pack;
215         struct mbuf     *fmp;
216         bus_dmamap_t    hmap;
217         bus_dmamap_t    pmap;
218 };
219
220 /*
221  * Bus dma allocation structure used by ixv_dma_malloc and ixv_dma_free.
222  */
223 struct ixv_dma_alloc {
224         bus_addr_t              dma_paddr;
225         caddr_t                 dma_vaddr;
226         bus_dma_tag_t           dma_tag;
227         bus_dmamap_t            dma_map;
228         bus_dma_segment_t       dma_seg;
229         bus_size_t              dma_size;
230         int                     dma_nseg;
231 };
232
233 /*
234 ** Driver queue struct: this is the interrupt container
235 **  for the associated tx and rx ring.
236 */
237 struct ix_queue {
238         struct adapter          *adapter;
239         u32                     msix;           /* This queue's MSIX vector */
240         u32                     eims;           /* This queue's EIMS bit */
241         u32                     eitr_setting;
242         u32                     eitr;           /* cached reg */
243         struct resource         *res;
244         void                    *tag;
245         struct tx_ring          *txr;
246         struct rx_ring          *rxr;
247         struct task             que_task;
248         struct taskqueue        *tq;
249         u64                     irqs;
250 };
251
252 /*
253  * The transmit ring, one per queue
254  */
255 struct tx_ring {
256         struct adapter          *adapter;
257         struct mtx              tx_mtx;
258         u32                     me;
259         bool                    watchdog_check;
260         int                     watchdog_time;
261         union ixgbe_adv_tx_desc *tx_base;
262         struct ixv_dma_alloc    txdma;
263         u32                     next_avail_desc;
264         u32                     next_to_clean;
265         struct ixv_tx_buf       *tx_buffers;
266         volatile u16            tx_avail;
267         u32                     txd_cmd;
268         bus_dma_tag_t           txtag;
269         char                    mtx_name[16];
270         struct buf_ring         *br;
271         /* Soft Stats */
272         u32                     bytes;
273         u32                     packets;
274         u64                     no_desc_avail;
275         u64                     total_packets;
276 };
277
278
279 /*
280  * The Receive ring, one per rx queue
281  */
282 struct rx_ring {
283         struct adapter          *adapter;
284         struct mtx              rx_mtx;
285         u32                     me;
286         union ixgbe_adv_rx_desc *rx_base;
287         struct ixv_dma_alloc    rxdma;
288         struct lro_ctrl         lro;
289         bool                    lro_enabled;
290         bool                    hdr_split;
291         bool                    discard;
292         u32                     next_to_refresh;
293         u32                     next_to_check;
294         char                    mtx_name[16];
295         struct ixv_rx_buf       *rx_buffers;
296         bus_dma_tag_t           htag;
297         bus_dma_tag_t           ptag;
298
299         u32                     bytes; /* Used for AIM calc */
300         u32                     packets;
301
302         /* Soft stats */
303         u64                     rx_irq;
304         u64                     rx_split_packets;
305         u64                     rx_packets;
306         u64                     rx_bytes;
307         u64                     rx_discarded;
308 };
309
310 /* Our adapter structure */
311 struct adapter {
312         struct ifnet            *ifp;
313         struct ixgbe_hw         hw;
314
315         struct ixgbe_osdep      osdep;
316         struct device           *dev;
317
318         struct resource         *pci_mem;
319         struct resource         *msix_mem;
320
321         /*
322          * Interrupt resources: this set is
323          * either used for legacy, or for Link
324          * when doing MSIX
325          */
326         void                    *tag;
327         struct resource         *res;
328
329         struct ifmedia          media;
330         struct callout          timer;
331         int                     msix;
332         int                     if_flags;
333
334         struct mtx              core_mtx;
335
336         eventhandler_tag        vlan_attach;
337         eventhandler_tag        vlan_detach;
338
339         u16                     num_vlans;
340         u16                     num_queues;
341
342         /* Info about the board itself */
343         bool                    link_active;
344         u16                     max_frame_size;
345         u32                     link_speed;
346         bool                    link_up;
347         u32                     mbxvec;
348
349         /* Mbuf cluster size */
350         u32                     rx_mbuf_sz;
351
352         /* Support for pluggable optics */
353         struct task             mbx_task;  /* Mailbox tasklet */
354         struct taskqueue        *tq;
355
356         /*
357         ** Queues: 
358         **   This is the irq holder, it has
359         **   and RX/TX pair or rings associated
360         **   with it.
361         */
362         struct ix_queue         *queues;
363
364         /*
365          * Transmit rings:
366          *      Allocated at run time, an array of rings.
367          */
368         struct tx_ring          *tx_rings;
369         int                     num_tx_desc;
370
371         /*
372          * Receive rings:
373          *      Allocated at run time, an array of rings.
374          */
375         struct rx_ring          *rx_rings;
376         int                     num_rx_desc;
377         u64                     que_mask;
378         u32                     rx_process_limit;
379
380         /* Misc stats maintained by the driver */
381         unsigned long           dropped_pkts;
382         unsigned long           mbuf_defrag_failed;
383         unsigned long           mbuf_header_failed;
384         unsigned long           mbuf_packet_failed;
385         unsigned long           no_tx_map_avail;
386         unsigned long           no_tx_dma_setup;
387         unsigned long           watchdog_events;
388         unsigned long           tso_tx;
389         unsigned long           mbx_irq;
390
391         struct ixgbevf_hw_stats stats;
392 };
393
394
395 #define IXV_CORE_LOCK_INIT(_sc, _name) \
396         mtx_init(&(_sc)->core_mtx, _name, "IXV Core Lock", MTX_DEF)
397 #define IXV_CORE_LOCK_DESTROY(_sc)      mtx_destroy(&(_sc)->core_mtx)
398 #define IXV_TX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->tx_mtx)
399 #define IXV_RX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->rx_mtx)
400 #define IXV_CORE_LOCK(_sc)              mtx_lock(&(_sc)->core_mtx)
401 #define IXV_TX_LOCK(_sc)                mtx_lock(&(_sc)->tx_mtx)
402 #define IXV_TX_TRYLOCK(_sc)             mtx_trylock(&(_sc)->tx_mtx)
403 #define IXV_RX_LOCK(_sc)                mtx_lock(&(_sc)->rx_mtx)
404 #define IXV_CORE_UNLOCK(_sc)            mtx_unlock(&(_sc)->core_mtx)
405 #define IXV_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->tx_mtx)
406 #define IXV_RX_UNLOCK(_sc)              mtx_unlock(&(_sc)->rx_mtx)
407 #define IXV_CORE_LOCK_ASSERT(_sc)       mtx_assert(&(_sc)->core_mtx, MA_OWNED)
408 #define IXV_TX_LOCK_ASSERT(_sc)         mtx_assert(&(_sc)->tx_mtx, MA_OWNED)
409
410 /* Workaround to make 8.0 buildable */
411 #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
412 static __inline int
413 drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
414 {
415 #ifdef ALTQ
416         if (ALTQ_IS_ENABLED(&ifp->if_snd))
417                 return (1);
418 #endif
419         return (!buf_ring_empty(br));
420 }
421 #endif
422
423 /*
424 ** Find the number of unrefreshed RX descriptors
425 */
426 static inline u16
427 ixv_rx_unrefreshed(struct rx_ring *rxr)
428 {       
429         struct adapter  *adapter = rxr->adapter;
430         
431         if (rxr->next_to_check > rxr->next_to_refresh)
432                 return (rxr->next_to_check - rxr->next_to_refresh - 1);
433         else
434                 return ((adapter->num_rx_desc + rxr->next_to_check) -
435                     rxr->next_to_refresh - 1);
436 }       
437
438 #endif /* _IXV_H_ */