em(4): Adjust RDTR/RADV comment that they should not be used
[dragonfly.git] / sys / dev / netif / em / if_em.h
1 /*
2  * Copyright (c) 2001-2008, 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_EM_H_
33 #define _IF_EM_H_
34
35 /* Tunables */
36
37 /*
38  * EM_TXD: Maximum number of Transmit Descriptors
39  * Valid Range: 256 for 82542 and 82543-based adapters
40  *              256-4096 for others
41  * Default Value: 256
42  *   This value is the number of transmit descriptors allocated by the driver.
43  *   Increasing this value allows the driver to queue more transmits. Each
44  *   descriptor is 16 bytes.
45  *   Since TDLEN should be multiple of 128bytes, the number of transmit
46  *   desscriptors should meet the following condition.
47  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
48  */
49 #define EM_MIN_TXD                      256
50 #define EM_MAX_TXD_82543                EM_MIN_TXD
51 #define EM_MAX_TXD                      4096
52 #define EM_DEFAULT_TXD                  EM_MIN_TXD
53
54 /*
55  * EM_RXD - Maximum number of receive Descriptors
56  * Valid Range: 256 for 82542 and 82543-based adapters
57  *              256-4096 for others
58  * Default Value: 256
59  *   This value is the number of receive descriptors allocated by the driver.
60  *   Increasing this value allows the driver to buffer more incoming packets.
61  *   Each descriptor is 16 bytes.  A receive buffer is also allocated for each
62  *   descriptor. The maximum MTU size is 16110.
63  *   Since TDLEN should be multiple of 128bytes, the number of transmit
64  *   desscriptors should meet the following condition.
65  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
66  */
67 #define EM_MIN_RXD                      256
68 #define EM_MAX_RXD_82543                EM_MIN_RXD
69 #define EM_MAX_RXD                      4096
70 #define EM_DEFAULT_RXD                  EM_MIN_RXD
71
72 /*
73  * EM_TIDV - Transmit Interrupt Delay Value
74  * Valid Range: 0-65535 (0=off)
75  * Default Value: 64
76  *   This value delays the generation of transmit interrupts in units of
77  *   1.024 microseconds. Transmit interrupt reduction can improve CPU
78  *   efficiency if properly tuned for specific network traffic. If the
79  *   system is reporting dropped transmits, this value may be set too high
80  *   causing the driver to run out of available transmit descriptors.
81  */
82 #define EM_TIDV                         64
83
84 /*
85  * EM_TADV - Transmit Absolute Interrupt Delay Value
86  * (Not valid for 82542/82543/82544)
87  * Valid Range: 0-65535 (0=off)
88  * Default Value: 64
89  *   This value, in units of 1.024 microseconds, limits the delay in which a
90  *   transmit interrupt is generated. Useful only if EM_TIDV is non-zero,
91  *   this value ensures that an interrupt is generated after the initial
92  *   packet is sent on the wire within the set amount of time.  Proper tuning,
93  *   along with EM_TIDV, may improve traffic throughput in specific
94  *   network conditions.
95  */
96 #define EM_TADV                         64
97
98 /*
99  * Receive Interrupt Delay Timer (Packet Timer)
100  *
101  * NOTE:
102  * RDTR and RADV are deprecated; use ITR instead.  They are only used to
103  * workaround hardware bug on certain 82573 based NICs.
104  */
105 #define EM_RDTR_82573                   32
106
107 /*
108  * Receive Interrupt Absolute Delay Timer (Not valid for 82542/82543/82544)
109  *
110  * NOTE:
111  * RDTR and RADV are deprecated; use ITR instead.  They are only used to
112  * workaround hardware bug on certain 82573 based NICs.
113  */
114 #define EM_RADV_82573                   64
115
116 /*
117  * This parameter controls the duration of transmit watchdog timer.
118  */
119 #define EM_TX_TIMEOUT                   5
120
121 /* One for TX csum offloading desc, the other is reserved */
122 #define EM_TX_RESERVED                  2
123
124 /* Large enough for 16K jumbo frame */
125 #define EM_TX_SPARE                     8
126
127 #define EM_TX_OACTIVE_MAX               64
128
129 /* Interrupt throttle rate */
130 #define EM_DEFAULT_ITR                  10000
131
132 /*
133  * This parameter controls whether or not autonegotation is enabled.
134  *              0 - Disable autonegotiation
135  *              1 - Enable  autonegotiation
136  */
137 #define DO_AUTO_NEG                     1
138
139 /*
140  * This parameter control whether or not the driver will wait for
141  * autonegotiation to complete.
142  *              1 - Wait for autonegotiation to complete
143  *              0 - Don't wait for autonegotiation to complete
144  */
145 #define WAIT_FOR_AUTO_NEG_DEFAULT       0
146
147 /* Tunables -- End */
148
149 #define AUTONEG_ADV_DEFAULT             (ADVERTISE_10_HALF | \
150                                          ADVERTISE_10_FULL | \
151                                          ADVERTISE_100_HALF | \
152                                          ADVERTISE_100_FULL | \
153                                          ADVERTISE_1000_FULL)
154
155 #define AUTO_ALL_MODES                  0
156
157 /* PHY master/slave setting */
158 #define EM_MASTER_SLAVE                 e1000_ms_hw_default
159
160 /*
161  * Micellaneous constants
162  */
163 #define EM_VENDOR_ID                    0x8086
164
165 #define EM_BAR_MEM                      PCIR_BAR(0)
166 #define EM_BAR_FLASH                    PCIR_BAR(1)
167
168 #define EM_JUMBO_PBA                    0x00000028
169 #define EM_DEFAULT_PBA                  0x00000030
170 #define EM_SMARTSPEED_DOWNSHIFT         3
171 #define EM_SMARTSPEED_MAX               15
172 #define EM_MAX_INTR                     10
173
174 #define MAX_NUM_MULTICAST_ADDRESSES     128
175 #define PCI_ANY_ID                      (~0U)
176 #define EM_FC_PAUSE_TIME                1000
177 #define EM_EEPROM_APME                  0x400;
178
179 /*
180  * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
181  * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
182  * also optimize cache line size effect. H/W supports up to cache line size 128.
183  */
184 #define EM_DBA_ALIGN                    128
185
186 #define SPEED_MODE_BIT                  (1 << 21) /* On PCI-E MACs only */
187
188 /* PCI Config defines */
189 #define EM_BAR_TYPE(v)                  ((v) & EM_BAR_TYPE_MASK)
190 #define EM_BAR_TYPE_MASK                0x00000001
191 #define EM_BAR_TYPE_MMEM                0x00000000
192 #define EM_BAR_TYPE_IO                  0x00000001
193 #define EM_BAR_MEM_TYPE(v)              ((v) & EM_BAR_MEM_TYPE_MASK)
194 #define EM_BAR_MEM_TYPE_MASK            0x00000006
195 #define EM_BAR_MEM_TYPE_32BIT           0x00000000
196 #define EM_BAR_MEM_TYPE_64BIT           0x00000004
197
198 #define EM_MAX_SCATTER                  64
199 #define EM_TSO_SIZE                     (65535 + \
200                                          sizeof(struct ether_vlan_header))
201 #define EM_MAX_SEGSIZE                  4096
202 #define EM_MSIX_MASK                    0x01F00000 /* For 82574 use */
203 #define ETH_ZLEN                        60
204
205 #define EM_CSUM_FEATURES                (CSUM_IP | CSUM_TCP | CSUM_UDP)
206 #define EM_IPVHL_SIZE                   1 /* sizeof(ip.ip_vhl) */
207 #define EM_TXCSUM_MINHL                 (ETHER_HDR_LEN + EVL_ENCAPLEN + \
208                                          EM_IPVHL_SIZE)
209
210 /*
211  * 82574 has a nonstandard address for EIAC
212  * and since its only used in MSIX, and in
213  * the em driver only 82574 uses MSIX we can
214  * solve it just using this define.
215  */
216 #define EM_EIAC                         0x000DC
217
218 /* Used in for 82547 10Mb Half workaround */
219 #define EM_PBA_BYTES_SHIFT              0xA
220 #define EM_TX_HEAD_ADDR_SHIFT           7
221 #define EM_PBA_TX_MASK                  0xFFFF0000
222 #define EM_FIFO_HDR                     0x10
223 #define EM_82547_PKT_THRESH             0x3e0
224
225 struct adapter;
226
227 struct em_int_delay_info {
228         struct adapter  *adapter;       /* Back-pointer to the adapter struct */
229         int             offset;         /* Register offset to read/write */
230         int             value;          /* Current value in usecs */
231 };
232
233 /*
234  * Bus dma allocation structure used by
235  * e1000_dma_malloc and e1000_dma_free.
236  */
237 struct em_dma_alloc {
238         bus_addr_t              dma_paddr;
239         void                    *dma_vaddr;
240         bus_dma_tag_t           dma_tag;
241         bus_dmamap_t            dma_map;
242 };
243
244 /* Our adapter structure */
245 struct adapter {
246         struct arpcom           arpcom;
247         struct e1000_hw         hw;
248
249         /* DragonFly operating-system-specific structures. */
250         struct e1000_osdep      osdep;
251         device_t                dev;
252
253         bus_dma_tag_t           parent_dtag;
254
255         struct resource         *memory;
256         int                     memory_rid;
257         struct resource         *flash;
258         int                     flash_rid;
259
260         struct resource         *ioport;
261         int                     io_rid;
262
263         struct resource         *intr_res;
264         void                    *intr_tag;
265         int                     intr_rid;
266
267         struct ifmedia          media;
268         struct callout          timer;
269         struct callout          tx_fifo_timer;
270         int                     if_flags;
271         int                     max_frame_size;
272         int                     min_frame_size;
273
274         /* Management and WOL features */
275         int                     wol;
276         int                     has_manage;
277
278         /* Info about the board itself */
279         uint8_t                 link_active;
280         uint16_t                link_speed;
281         uint16_t                link_duplex;
282         uint32_t                smartspeed;
283         struct em_int_delay_info tx_int_delay;
284         struct em_int_delay_info tx_abs_int_delay;
285         int                     int_throttle_ceil;
286
287         /*
288          * Transmit definitions
289          *
290          * We have an array of num_tx_desc descriptors (handled
291          * by the controller) paired with an array of tx_buffers
292          * (at tx_buffer_area).
293          * The index of the next available descriptor is next_avail_tx_desc.
294          * The number of remaining tx_desc is num_tx_desc_avail.
295          */
296         struct em_dma_alloc     txdma;          /* bus_dma glue for tx desc */
297         struct e1000_tx_desc    *tx_desc_base;
298         struct em_buffer        *tx_buffer_area;
299         uint32_t                next_avail_tx_desc;
300         uint32_t                next_tx_to_clean;
301         int                     num_tx_desc_avail;
302         int                     num_tx_desc;
303         uint32_t                txd_cmd;
304         bus_dma_tag_t           txtag;          /* dma tag for tx */
305         int                     spare_tx_desc;
306         int                     oact_tx_desc;
307
308         /* Saved csum offloading context information */
309         int                     csum_flags;
310         int                     csum_ehlen;
311         int                     csum_iphlen;
312         uint32_t                csum_txd_upper;
313         uint32_t                csum_txd_lower;
314
315         /*
316          * Variables used to reduce TX interrupt rate and
317          * number of device's TX ring write requests.
318          *
319          * tx_nsegs:
320          * Number of TX descriptors setup so far.
321          *
322          * tx_int_nsegs:
323          * Once tx_nsegs > tx_int_nsegs, RS bit will be set
324          * in the last TX descriptor of the packet, and
325          * tx_nsegs will be reset to 0.  So TX interrupt and
326          * TX ring write request should be generated roughly
327          * every tx_int_nsegs TX descriptors.
328          *
329          * tx_dd[]:
330          * Index of the TX descriptors which have RS bit set,
331          * i.e. DD bit will be set on this TX descriptor after
332          * the data of the TX descriptor are transfered to
333          * hardware's internal packet buffer.  Only the TX
334          * descriptors listed in tx_dd[] will be checked upon
335          * TX interrupt.  This array is used as circular ring.
336          *
337          * tx_dd_tail, tx_dd_head:
338          * Tail and head index of valid elements in tx_dd[].
339          * tx_dd_tail == tx_dd_head means there is no valid
340          * elements in tx_dd[].  tx_dd_tail points to the position
341          * which is one beyond the last valid element in tx_dd[].
342          * tx_dd_head points to the first valid element in
343          * tx_dd[].
344          */
345         int                     tx_int_nsegs;
346         int                     tx_nsegs;
347         int                     tx_dd_tail;
348         int                     tx_dd_head;
349 #define EM_TXDD_MAX     64
350 #define EM_TXDD_SAFE    50 /* must be less than EM_TXDD_MAX */
351         int                     tx_dd[EM_TXDD_MAX];
352
353         /*
354          * Receive definitions
355          *
356          * we have an array of num_rx_desc rx_desc (handled by the
357          * controller), and paired with an array of rx_buffers
358          * (at rx_buffer_area).
359          * The next pair to check on receive is at offset next_rx_desc_to_check
360          */
361         struct em_dma_alloc     rxdma;          /* bus_dma glue for rx desc */
362         struct e1000_rx_desc    *rx_desc_base;
363         uint32_t                next_rx_desc_to_check;
364         uint32_t                rx_buffer_len;
365         int                     num_rx_desc;
366         struct em_buffer        *rx_buffer_area;
367         bus_dma_tag_t           rxtag;
368         bus_dmamap_t            rx_sparemap;
369
370         /*
371          * First/last mbuf pointers, for
372          * collecting multisegment RX packets.
373          */
374         struct mbuf             *fmp;
375         struct mbuf             *lmp;
376
377         /* Misc stats maintained by the driver */
378         unsigned long           dropped_pkts;
379         unsigned long           mbuf_alloc_failed;
380         unsigned long           mbuf_cluster_failed;
381         unsigned long           no_tx_desc_avail1;
382         unsigned long           no_tx_desc_avail2;
383         unsigned long           no_tx_map_avail;
384         unsigned long           no_tx_dma_setup;
385         unsigned long           watchdog_events;
386         unsigned long           rx_overruns;
387         unsigned long           rx_irq;
388         unsigned long           tx_irq;
389         unsigned long           link_irq;
390         unsigned long           tx_csum_try_pullup;
391         unsigned long           tx_csum_pullup1;
392         unsigned long           tx_csum_pullup1_failed;
393         unsigned long           tx_csum_pullup2;
394         unsigned long           tx_csum_pullup2_failed;
395         unsigned long           tx_csum_drop1;
396         unsigned long           tx_csum_drop2;
397
398         /* sysctl tree glue */
399         struct sysctl_ctx_list  sysctl_ctx;
400         struct sysctl_oid       *sysctl_tree;
401
402         /* 82547 workaround */
403         uint32_t                tx_fifo_size;
404         uint32_t                tx_fifo_head;
405         uint32_t                tx_fifo_head_addr;
406         uint64_t                tx_fifo_reset_cnt;
407         uint64_t                tx_fifo_wrk_cnt;
408         uint32_t                tx_head_addr;
409
410         /* For 82544 PCIX Workaround */
411         boolean_t               pcix_82544;
412         boolean_t               in_detach;
413
414         struct e1000_hw_stats   stats;
415 };
416
417 struct em_vendor_info {
418         uint16_t        vendor_id;
419         uint16_t        device_id;
420         const char      *desc;
421 };
422
423 struct em_buffer {
424         struct mbuf     *m_head;
425         bus_dmamap_t    map;            /* bus_dma map for packet */
426 };
427
428 /* For 82544 PCIX  Workaround */
429 typedef struct _ADDRESS_LENGTH_PAIR {
430         uint64_t        address;
431         uint32_t        length;
432 } ADDRESS_LENGTH_PAIR, *PADDRESS_LENGTH_PAIR;
433
434 typedef struct _DESCRIPTOR_PAIR {
435         ADDRESS_LENGTH_PAIR descriptor[4];
436         uint32_t        elements;
437 } DESC_ARRAY, *PDESC_ARRAY;
438
439 #define EM_IS_OACTIVE(adapter) \
440         ((adapter)->num_tx_desc_avail <= (adapter)->oact_tx_desc)
441
442 #define EM_INC_TXDD_IDX(idx) \
443 do { \
444         if (++(idx) == EM_TXDD_MAX) \
445                 (idx) = 0; \
446 } while (0)
447
448 #endif /* _IF_EM_H_ */