d4bec2c3777c63e543c34d92637bfc8626f0a0bd
[dragonfly.git] / sys / dev / netif / igb / if_igb.h
1 /*
2  * Copyright (c) 2001-2011, Intel Corporation 
3  * All rights reserved.
4  * 
5  * Redistribution and use in source and binary forms, with or without 
6  * modification, are permitted provided that the following conditions are met:
7  * 
8  *  1. Redistributions of source code must retain the above copyright notice, 
9  *     this list of conditions and the following disclaimer.
10  * 
11  *  2. Redistributions in binary form must reproduce the above copyright 
12  *     notice, this list of conditions and the following disclaimer in the 
13  *     documentation and/or other materials provided with the distribution.
14  * 
15  *  3. Neither the name of the Intel Corporation nor the names of its 
16  *     contributors may be used to endorse or promote products derived from 
17  *     this software without specific prior written permission.
18  * 
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef _IF_IGB_H_
33 #define _IF_IGB_H_
34
35 /* Tunables */
36
37 /*
38  * Max ring count
39  */
40 #define IGB_MAX_RING_82575      4
41 #define IGB_MAX_RING_I350       8
42 #define IGB_MAX_RING_82580      8
43 #define IGB_MAX_RING_82576      16
44 #define IGB_MIN_RING            1
45 #define IGB_MIN_RING_RSS        2
46
47 /*
48  * Max TX/RX interrupt bits
49  */
50 #define IGB_MAX_TXRXINT_82575   4       /* XXX not used */
51 #define IGB_MAX_TXRXINT_I350    8
52 #define IGB_MAX_TXRXINT_82580   8
53 #define IGB_MAX_TXRXINT_82576   16
54 #define IGB_MIN_TXRXINT         2       /* XXX VF? */
55
56 /*
57  * Max IVAR count
58  */
59 #define IGB_MAX_IVAR_I350       4
60 #define IGB_MAX_IVAR_82580      4
61 #define IGB_MAX_IVAR_82576      8
62 #define IGB_MAX_IVAR_VF         1
63
64 /*
65  * Default number of segments received before writing to RX related registers
66  */
67 #define IGB_DEF_RXWREG_NSEGS    32
68
69 /*
70  * Default number of segments sent before writing to RX related registers
71  */
72 #define IGB_DEF_TXWREG_NSEGS    8
73
74 /*
75  * IGB_TXD: Maximum number of Transmit Descriptors
76  *
77  *   This value is the number of transmit descriptors allocated by the driver.
78  *   Increasing this value allows the driver to queue more transmits. Each
79  *   descriptor is 16 bytes.
80  *   Since TDLEN should be multiple of 128bytes, the number of transmit
81  *   desscriptors should meet the following condition.
82  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
83  */
84 #define IGB_MIN_TXD             256
85 #define IGB_DEFAULT_TXD         1024
86 #define IGB_MAX_TXD             4096
87
88 /*
89  * IGB_RXD: Maximum number of Transmit Descriptors
90  *
91  *   This value is the number of receive descriptors allocated by the driver.
92  *   Increasing this value allows the driver to buffer more incoming packets.
93  *   Each descriptor is 16 bytes.  A receive buffer is also allocated for each
94  *   descriptor. The maximum MTU size is 16110.
95  *   Since TDLEN should be multiple of 128bytes, the number of transmit
96  *   desscriptors should meet the following condition.
97  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
98  */
99 #define IGB_MIN_RXD             256
100 #define IGB_DEFAULT_RXD         512
101 #define IGB_MAX_RXD             4096
102
103 /*
104  * This parameter controls when the driver calls the routine to reclaim
105  * transmit descriptors. Cleaning earlier seems a win.
106  */
107 #define IGB_TX_CLEANUP_THRESHOLD(sc)    ((sc)->num_tx_desc / 2)
108
109 /*
110  * This parameter controls whether or not autonegotation is enabled.
111  *              0 - Disable autonegotiation
112  *              1 - Enable  autonegotiation
113  */
114 #define DO_AUTO_NEG             1
115
116 /*
117  * This parameter control whether or not the driver will wait for
118  * autonegotiation to complete.
119  *              1 - Wait for autonegotiation to complete
120  *              0 - Don't wait for autonegotiation to complete
121  */
122 #define WAIT_FOR_AUTO_NEG_DEFAULT       0
123
124 /* Tunables -- End */
125
126 #define AUTONEG_ADV_DEFAULT     (ADVERTISE_10_HALF | ADVERTISE_10_FULL | \
127                                  ADVERTISE_100_HALF | ADVERTISE_100_FULL | \
128                                  ADVERTISE_1000_FULL)
129
130 #define AUTO_ALL_MODES                  0
131
132 /* PHY master/slave setting */
133 #define IGB_MASTER_SLAVE                e1000_ms_hw_default
134
135 /*
136  * Micellaneous constants
137  */
138 #define IGB_VENDOR_ID                   0x8086
139
140 #define IGB_JUMBO_PBA                   0x00000028
141 #define IGB_DEFAULT_PBA                 0x00000030
142 #define IGB_SMARTSPEED_DOWNSHIFT        3
143 #define IGB_SMARTSPEED_MAX              15
144 #define IGB_MAX_LOOP                    10
145
146 #define IGB_RX_PTHRESH                  (hw->mac.type <= e1000_82576 ? 16 : 8)
147 #define IGB_RX_HTHRESH                  8
148 #define IGB_RX_WTHRESH                  1
149
150 #define IGB_TX_PTHRESH                  8
151 #define IGB_TX_HTHRESH                  1
152 #define IGB_TX_WTHRESH                  16
153
154 #define MAX_NUM_MULTICAST_ADDRESSES     128
155 #define IGB_FC_PAUSE_TIME               0x0680
156
157 #define IGB_INTR_RATE                   6000
158 #define IGB_MSIX_RX_RATE                6000
159 #define IGB_MSIX_TX_RATE                4000
160
161 /*
162  * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
163  * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
164  * also optimize cache line size effect. H/W supports up to cache line size 128.
165  */
166 #define IGB_DBA_ALIGN                   128
167
168 /* PCI Config defines */
169 #define IGB_MSIX_BAR                    3
170
171 #define IGB_MAX_SCATTER                 64
172 #define IGB_VFTA_SIZE                   128
173 #define IGB_TSO_SIZE                    (IP_MAXPACKET + \
174                                          sizeof(struct ether_vlan_header))
175 #define IGB_HDR_BUF                     128
176 #define IGB_PKTTYPE_MASK                0x0000FFF0
177
178 #define IGB_CSUM_FEATURES               (CSUM_IP | CSUM_TCP | CSUM_UDP)
179 #define IGB_IPVHL_SIZE                  1 /* sizeof(ip.ip_vhl) */
180 #define IGB_TXCSUM_MINHL                (ETHER_HDR_LEN + EVL_ENCAPLEN + \
181                                          IGB_IPVHL_SIZE)
182
183 /* One for TX csum offloading desc, the other 2 are reserved */
184 #define IGB_TX_RESERVED                 3
185
186 /* Large enough for 64K TSO */
187 #define IGB_TX_SPARE                    33
188
189 #define IGB_TX_OACTIVE_MAX              64
190
191 /* main + 16x RX + 16x TX */
192 #define IGB_NSERIALIZE                  33
193
194 #define IGB_NRSSRK                      10
195 #define IGB_RSSRK_SIZE                  4
196 #define IGB_RSSRK_VAL(key, i)           (key[(i) * IGB_RSSRK_SIZE] | \
197                                          key[(i) * IGB_RSSRK_SIZE + 1] << 8 | \
198                                          key[(i) * IGB_RSSRK_SIZE + 2] << 16 | \
199                                          key[(i) * IGB_RSSRK_SIZE + 3] << 24)
200
201 #define IGB_NRETA                       32
202 #define IGB_RETA_SIZE                   4
203 #define IGB_RETA_SHIFT                  0
204 #define IGB_RETA_SHIFT_82575            6
205
206 #define IGB_EITR_INTVL_MASK             0x7ffc
207 #define IGB_EITR_INTVL_SHIFT            2
208
209 struct igb_softc;
210
211 /*
212  * Bus dma information structure
213  */
214 struct igb_dma {
215         bus_addr_t              dma_paddr;
216         void                    *dma_vaddr;
217         bus_dma_tag_t           dma_tag;
218         bus_dmamap_t            dma_map;
219 };
220
221 /*
222  * Transmit ring: one per queue
223  */
224 struct igb_tx_ring {
225         struct lwkt_serialize   tx_serialize;
226         struct igb_softc        *sc;
227         struct ifaltq_subque    *ifsq;
228         uint32_t                me;
229         struct e1000_tx_desc    *tx_base;
230         int                     num_tx_desc;
231         uint32_t                next_avail_desc;
232         uint32_t                next_to_clean;
233         uint32_t                *tx_hdr;
234         int                     tx_avail;
235         struct igb_tx_buf       *tx_buf;
236         bus_dma_tag_t           tx_tag;
237         int                     tx_nsegs;
238         int                     spare_desc;
239         int                     oact_lo_desc;
240         int                     oact_hi_desc;
241         int                     intr_nsegs;
242         int                     wreg_nsegs;
243         int                     tx_intr_bit;
244         uint32_t                tx_intr_mask;
245         struct ifsubq_watchdog  tx_watchdog;
246
247         /* Soft stats */
248         u_long                  no_desc_avail;
249         u_long                  tx_packets;
250
251         struct igb_dma          txdma;
252         bus_dma_tag_t           tx_hdr_dtag;
253         bus_dmamap_t            tx_hdr_dmap;
254         bus_addr_t              tx_hdr_paddr;
255         int                     tx_intr_cpuid;
256 } __cachealign;
257
258 /*
259  * Receive ring: one per queue
260  */
261 struct igb_rx_ring {
262         struct lwkt_serialize   rx_serialize;
263         struct igb_softc        *sc;
264         uint32_t                me;
265         union e1000_adv_rx_desc *rx_base;
266         boolean_t               discard;
267         int                     num_rx_desc;
268         uint32_t                next_to_check;
269         struct igb_rx_buf       *rx_buf;
270         bus_dma_tag_t           rx_tag;
271         bus_dmamap_t            rx_sparemap;
272         int                     rx_intr_bit;
273         uint32_t                rx_intr_mask;
274
275         /*
276          * First/last mbuf pointers, for
277          * collecting multisegment RX packets.
278          */
279         struct mbuf             *fmp;
280         struct mbuf             *lmp;
281         int                     wreg_nsegs;
282
283         /* Soft stats */
284         u_long                  rx_packets;
285
286         struct igb_dma          rxdma;
287 } __cachealign;
288
289 struct igb_msix_data {
290         struct lwkt_serialize   *msix_serialize;
291         struct lwkt_serialize   msix_serialize0;
292         struct igb_softc        *msix_sc;
293         uint32_t                msix_mask;
294         struct igb_rx_ring      *msix_rx;
295         struct igb_tx_ring      *msix_tx;
296
297         driver_intr_t           *msix_func;
298         void                    *msix_arg;
299
300         int                     msix_cpuid;
301         char                    msix_desc[32];
302         int                     msix_rid;
303         struct resource         *msix_res;
304         void                    *msix_handle;
305         u_int                   msix_vector;
306         int                     msix_rate;
307         char                    msix_rate_desc[32];
308 } __cachealign;
309
310 struct igb_softc {
311         struct arpcom           arpcom;
312         struct e1000_hw         hw;
313
314         struct e1000_osdep      osdep;
315         device_t                dev;
316         uint32_t                flags;
317 #define IGB_FLAG_SHARED_INTR    0x1
318 #define IGB_FLAG_HAS_MGMT       0x2
319 #define IGB_FLAG_TSO_IPLEN0     0x4
320
321         bus_dma_tag_t           parent_tag;
322
323         int                     mem_rid;
324         struct resource         *mem_res;
325
326         struct ifmedia          media;
327         struct callout          timer;
328         int                     timer_cpuid;
329
330         int                     intr_type;
331         int                     intr_rid;
332         struct resource         *intr_res;
333         void                    *intr_tag;
334
335         int                     if_flags;
336         int                     max_frame_size;
337         int                     pause_frames;
338         uint16_t                vf_ifp; /* a VF interface */
339
340         /* Management and WOL features */
341         int                     wol;
342
343         /* Info about the interface */
344         uint8_t                 link_active;
345         uint16_t                link_speed;
346         uint16_t                link_duplex;
347         uint32_t                smartspeed;
348         uint32_t                dma_coalesce;
349
350         /* Multicast array pointer */
351         uint8_t                 *mta;
352
353         int                     rx_npoll_off;
354         int                     tx_npoll_off;
355         int                     serialize_cnt;
356         int                     tx_serialize;
357         int                     rx_serialize;
358         struct lwkt_serialize   *serializes[IGB_NSERIALIZE];
359         struct lwkt_serialize   main_serialize;
360
361         int                     intr_rate;
362         uint32_t                intr_mask;
363         int                     sts_intr_bit;
364         uint32_t                sts_intr_mask;
365
366         /*
367          * Transmit rings
368          */
369         int                     tx_ring_cnt;
370         int                     tx_ring_msix;
371         int                     tx_ring_inuse;
372         struct igb_tx_ring      *tx_rings;
373
374         /*
375          * Receive rings
376          */
377         int                     rss_debug;
378         int                     rx_ring_cnt;
379         int                     rx_ring_msix;
380         int                     rx_ring_inuse;
381         struct igb_rx_ring      *rx_rings;
382
383         /* Misc stats maintained by the driver */
384         u_long                  dropped_pkts;
385         u_long                  mbuf_defrag_failed;
386         u_long                  no_tx_dma_setup;
387         u_long                  watchdog_events;
388         u_long                  rx_overruns;
389         u_long                  device_control;
390         u_long                  rx_control;
391         u_long                  int_mask;
392         u_long                  eint_mask;
393         u_long                  packet_buf_alloc_rx;
394         u_long                  packet_buf_alloc_tx;
395
396         /* sysctl tree glue */
397         struct sysctl_ctx_list  sysctl_ctx;
398         struct sysctl_oid       *sysctl_tree;
399
400         void                    *stats;
401
402         int                     msix_mem_rid;
403         struct resource         *msix_mem_res;
404         int                     msix_cnt;
405         struct igb_msix_data    *msix_data;
406 };
407
408 #define IGB_ENABLE_HWRSS(sc)    ((sc)->rx_ring_cnt > 1)
409 #define IGB_ENABLE_HWTSS(sc)    ((sc)->tx_ring_cnt > 1)
410
411 struct igb_tx_buf {
412         struct mbuf     *m_head;
413         bus_dmamap_t    map;            /* bus_dma map for packet */
414 };
415
416 struct igb_rx_buf {
417         struct mbuf     *m_head;
418         bus_dmamap_t    map;    /* bus_dma map for packet */
419         bus_addr_t      paddr;
420 };
421
422 #define UPDATE_VF_REG(reg, last, cur)           \
423 {                                               \
424         uint32_t new = E1000_READ_REG(hw, reg); \
425         if (new < last)                         \
426                 cur += 0x100000000LL;           \
427         last = new;                             \
428         cur &= 0xFFFFFFFF00000000LL;            \
429         cur |= new;                             \
430 }
431
432 #define IGB_IS_OACTIVE(txr)     ((txr)->tx_avail < (txr)->oact_lo_desc)
433 #define IGB_IS_NOT_OACTIVE(txr) ((txr)->tx_avail >= (txr)->oact_hi_desc)
434
435 #endif /* _IF_IGB_H_ */