igb: Enable multiple RX rings and integrate it w/ DragonFly's RSS
[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
46 /*
47  * Max TX/RX interrupt bits
48  */
49 #define IGB_MAX_TXRXINT_82575   4       /* XXX not used */
50 #define IGB_MAX_TXRXINT_I350    8
51 #define IGB_MAX_TXRXINT_82580   8
52 #define IGB_MAX_TXRXINT_82576   16
53 #define IGB_MIN_TXRXINT         2       /* XXX VF? */
54
55 /*
56  * IGB_TXD: Maximum number of Transmit Descriptors
57  *
58  *   This value is the number of transmit descriptors allocated by the driver.
59  *   Increasing this value allows the driver to queue more transmits. Each
60  *   descriptor is 16 bytes.
61  *   Since TDLEN should be multiple of 128bytes, the number of transmit
62  *   desscriptors should meet the following condition.
63  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
64  */
65 #define IGB_MIN_TXD             256
66 #define IGB_DEFAULT_TXD         1024
67 #define IGB_MAX_TXD             4096
68
69 /*
70  * IGB_RXD: Maximum number of Transmit Descriptors
71  *
72  *   This value is the number of receive descriptors allocated by the driver.
73  *   Increasing this value allows the driver to buffer more incoming packets.
74  *   Each descriptor is 16 bytes.  A receive buffer is also allocated for each
75  *   descriptor. The maximum MTU size is 16110.
76  *   Since TDLEN should be multiple of 128bytes, the number of transmit
77  *   desscriptors should meet the following condition.
78  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
79  */
80 #define IGB_MIN_RXD             256
81 #define IGB_DEFAULT_RXD         1024
82 #define IGB_MAX_RXD             4096
83
84 /*
85  * This parameter controls when the driver calls the routine to reclaim
86  * transmit descriptors. Cleaning earlier seems a win.
87  */
88 #define IGB_TX_CLEANUP_THRESHOLD(sc)    ((sc)->num_tx_desc / 2)
89
90 /*
91  * This parameter controls whether or not autonegotation is enabled.
92  *              0 - Disable autonegotiation
93  *              1 - Enable  autonegotiation
94  */
95 #define DO_AUTO_NEG             1
96
97 /*
98  * This parameter control whether or not the driver will wait for
99  * autonegotiation to complete.
100  *              1 - Wait for autonegotiation to complete
101  *              0 - Don't wait for autonegotiation to complete
102  */
103 #define WAIT_FOR_AUTO_NEG_DEFAULT       0
104
105 /* Tunables -- End */
106
107 #define AUTONEG_ADV_DEFAULT     (ADVERTISE_10_HALF | ADVERTISE_10_FULL | \
108                                  ADVERTISE_100_HALF | ADVERTISE_100_FULL | \
109                                  ADVERTISE_1000_FULL)
110
111 #define AUTO_ALL_MODES                  0
112
113 /* PHY master/slave setting */
114 #define IGB_MASTER_SLAVE                e1000_ms_hw_default
115
116 /*
117  * Micellaneous constants
118  */
119 #define IGB_VENDOR_ID                   0x8086
120
121 #define IGB_JUMBO_PBA                   0x00000028
122 #define IGB_DEFAULT_PBA                 0x00000030
123 #define IGB_SMARTSPEED_DOWNSHIFT        3
124 #define IGB_SMARTSPEED_MAX              15
125 #define IGB_MAX_LOOP                    10
126
127 #define IGB_RX_PTHRESH                  (hw->mac.type <= e1000_82576 ? 16 : 8)
128 #define IGB_RX_HTHRESH                  8
129 #define IGB_RX_WTHRESH                  1
130
131 #define IGB_TX_PTHRESH                  8
132 #define IGB_TX_HTHRESH                  1
133 #define IGB_TX_WTHRESH                  16
134
135 #define MAX_NUM_MULTICAST_ADDRESSES     128
136 #define IGB_FC_PAUSE_TIME               0x0680
137
138 #define IGB_INTR_RATE                   10000
139
140 /*
141  * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
142  * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
143  * also optimize cache line size effect. H/W supports up to cache line size 128.
144  */
145 #define IGB_DBA_ALIGN                   128
146
147 /* PCI Config defines */
148 #define IGB_MSIX_BAR                    3
149
150 #define IGB_MAX_SCATTER                 64
151 #define IGB_VFTA_SIZE                   128
152 #define IGB_TSO_SIZE                    (65535 + \
153                                          sizeof(struct ether_vlan_header))
154 #define IGB_TSO_SEG_SIZE                4096    /* Max dma segment size */
155 #define IGB_HDR_BUF                     128
156 #define IGB_PKTTYPE_MASK                0x0000FFF0
157
158 #define IGB_CSUM_FEATURES               (CSUM_IP | CSUM_TCP | CSUM_UDP)
159 #define IGB_IPVHL_SIZE                  1 /* sizeof(ip.ip_vhl) */
160 #define IGB_TXCSUM_MINHL                (ETHER_HDR_LEN + EVL_ENCAPLEN + \
161                                          IGB_IPVHL_SIZE)
162
163 /* One for TX csum offloading desc, the other 2 are reserved */
164 #define IGB_TX_RESERVED                 3
165
166 /* Large enough for 64K TSO */
167 #define IGB_TX_SPARE                    32
168
169 #define IGB_TX_OACTIVE_MAX              64
170
171 /* main + 16x RX + 16x TX */
172 #define IGB_NSERIALIZE                  33
173
174 #define IGB_NRSSRK                      10
175 #define IGB_RSSRK_SIZE                  4
176 #define IGB_RSSRK_VAL(key, i)           (key[(i) * IGB_RSSRK_SIZE] | \
177                                          key[(i) * IGB_RSSRK_SIZE + 1] << 8 | \
178                                          key[(i) * IGB_RSSRK_SIZE + 2] << 16 | \
179                                          key[(i) * IGB_RSSRK_SIZE + 3] << 24)
180
181 #define IGB_NRETA                       32
182 #define IGB_RETA_SIZE                   4
183 #define IGB_RETA_SHIFT                  0
184 #define IGB_RETA_SHIFT_82575            6
185
186 struct igb_softc;
187
188 /*
189  * Bus dma information structure
190  */
191 struct igb_dma {
192         bus_addr_t              dma_paddr;
193         void                    *dma_vaddr;
194         bus_dma_tag_t           dma_tag;
195         bus_dmamap_t            dma_map;
196 };
197
198 /*
199  * Transmit ring: one per queue
200  */
201 struct igb_tx_ring {
202         struct lwkt_serialize   tx_serialize;
203         struct igb_softc        *sc;
204         uint32_t                me;
205         struct igb_dma          txdma;
206         bus_dma_tag_t           tx_hdr_dtag;
207         bus_dmamap_t            tx_hdr_dmap;
208         bus_addr_t              tx_hdr_paddr;
209         struct e1000_tx_desc    *tx_base;
210         int                     num_tx_desc;
211         uint32_t                next_avail_desc;
212         uint32_t                next_to_clean;
213         uint32_t                *tx_hdr;
214         int                     tx_avail;
215         struct igb_tx_buf       *tx_buf;
216         bus_dma_tag_t           tx_tag;
217         int                     tx_nsegs;
218         int                     spare_desc;
219         int                     oact_lo_desc;
220         int                     oact_hi_desc;
221         int                     intr_nsegs;
222         int                     tx_intr_bit;
223         uint32_t                tx_intr_mask;
224
225         u_long                  no_desc_avail;
226         u_long                  tx_packets;
227
228         u_long                  ctx_try_pullup;
229         u_long                  ctx_drop1;
230         u_long                  ctx_drop2;
231         u_long                  ctx_pullup1;
232         u_long                  ctx_pullup1_failed;
233         u_long                  ctx_pullup2;
234         u_long                  ctx_pullup2_failed;
235 };
236
237 /*
238  * Receive ring: one per queue
239  */
240 struct igb_rx_ring {
241         struct lwkt_serialize   rx_serialize;
242         struct igb_softc        *sc;
243         uint32_t                me;
244         struct igb_dma          rxdma;
245         union e1000_adv_rx_desc *rx_base;
246         boolean_t               discard;
247         int                     num_rx_desc;
248         uint32_t                next_to_check;
249         struct igb_rx_buf       *rx_buf;
250         bus_dma_tag_t           rx_tag;
251         bus_dmamap_t            rx_sparemap;
252         int                     rx_intr_bit;
253         uint32_t                rx_intr_mask;
254
255         /*
256          * First/last mbuf pointers, for
257          * collecting multisegment RX packets.
258          */
259         struct mbuf             *fmp;
260         struct mbuf             *lmp;
261
262         /* Soft stats */
263         u_long                  rx_packets;
264 };
265
266 struct igb_softc {
267         struct arpcom           arpcom;
268         struct e1000_hw         hw;
269
270         struct e1000_osdep      osdep;
271         device_t                dev;
272         uint32_t                flags;
273 #define IGB_FLAG_SHARED_INTR    0x1
274 #define IGB_FLAG_HAS_MGMT       0x2
275
276         bus_dma_tag_t           parent_tag;
277
278         int                     mem_rid;
279         struct resource         *mem_res;
280
281         struct ifmedia          media;
282         struct callout          timer;
283
284         int                     intr_type;
285         int                     intr_rid;
286         struct resource         *intr_res;
287         void                    *intr_tag;
288
289         int                     if_flags;
290         int                     max_frame_size;
291         int                     pause_frames;
292         uint16_t                vf_ifp; /* a VF interface */
293
294         /* Management and WOL features */
295         int                     wol;
296
297         /* Info about the interface */
298         uint8_t                 link_active;
299         uint16_t                link_speed;
300         uint16_t                link_duplex;
301         uint32_t                smartspeed;
302         uint32_t                dma_coalesce;
303
304         /* Multicast array pointer */
305         uint8_t                 *mta;
306
307         int                     serialize_cnt;
308         int                     tx_serialize;
309         int                     rx_serialize;
310         struct lwkt_serialize   *serializes[IGB_NSERIALIZE];
311         struct lwkt_serialize   main_serialize;
312
313         int                     intr_rate;
314         uint32_t                intr_mask;
315
316         /*
317          * Transmit rings
318          */
319         int                     tx_ring_cnt;
320         struct igb_tx_ring      *tx_rings;
321
322         /*
323          * Receive rings
324          */
325         int                     rss_debug;
326         int                     rx_ring_cnt;
327         struct igb_rx_ring      *rx_rings;
328
329         /* Misc stats maintained by the driver */
330         u_long                  dropped_pkts;
331         u_long                  mbuf_defrag_failed;
332         u_long                  no_tx_dma_setup;
333         u_long                  watchdog_events;
334         u_long                  rx_overruns;
335         u_long                  device_control;
336         u_long                  rx_control;
337         u_long                  int_mask;
338         u_long                  eint_mask;
339         u_long                  packet_buf_alloc_rx;
340         u_long                  packet_buf_alloc_tx;
341
342         /* sysctl tree glue */
343         struct sysctl_ctx_list  sysctl_ctx;
344         struct sysctl_oid       *sysctl_tree;
345
346         void                    *stats;
347 };
348
349 #define IGB_ENABLE_HWRSS(sc)    ((sc)->rx_ring_cnt > 1)
350
351 struct igb_tx_buf {
352         struct mbuf     *m_head;
353         bus_dmamap_t    map;            /* bus_dma map for packet */
354 };
355
356 struct igb_rx_buf {
357         struct mbuf     *m_head;
358         bus_dmamap_t    map;    /* bus_dma map for packet */
359         bus_addr_t      paddr;
360 };
361
362 #define UPDATE_VF_REG(reg, last, cur)           \
363 {                                               \
364         uint32_t new = E1000_READ_REG(hw, reg); \
365         if (new < last)                         \
366                 cur += 0x100000000LL;           \
367         last = new;                             \
368         cur &= 0xFFFFFFFF00000000LL;            \
369         cur |= new;                             \
370 }
371
372 #define IGB_IS_OACTIVE(txr)     ((txr)->tx_avail < (txr)->oact_lo_desc)
373 #define IGB_IS_NOT_OACTIVE(txr) ((txr)->tx_avail >= (txr)->oact_hi_desc)
374
375 #endif /* _IF_IGB_H_ */