xref: /dragonfly/sys/dev/netif/em/if_em.h (revision 74dc37549af2a2c5a84a4b9aa9493437b50f294f)
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                            512
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                            512
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  * NOTE:
83  * It is not used.  In DragonFly the TX interrupt moderation is done by
84  * conditionally setting RS bit in TX descriptors.  See the description
85  * in struct adapter.
86  */
87 #define EM_TIDV                                   64
88 
89 /*
90  * EM_TADV - Transmit Absolute Interrupt Delay Value
91  * (Not valid for 82542/82543/82544)
92  * Valid Range: 0-65535 (0=off)
93  * Default Value: 64
94  *   This value, in units of 1.024 microseconds, limits the delay in which a
95  *   transmit interrupt is generated. Useful only if EM_TIDV is non-zero,
96  *   this value ensures that an interrupt is generated after the initial
97  *   packet is sent on the wire within the set amount of time.  Proper tuning,
98  *   along with EM_TIDV, may improve traffic throughput in specific
99  *   network conditions.
100  *
101  * NOTE:
102  * It is not used.  In DragonFly the TX interrupt moderation is done by
103  * conditionally setting RS bit in TX descriptors.  See the description
104  * in struct adapter.
105  */
106 #define EM_TADV                                   64
107 
108 /*
109  * Receive Interrupt Delay Timer (Packet Timer)
110  *
111  * NOTE:
112  * RDTR and RADV are deprecated; use ITR instead.  They are only used to
113  * workaround hardware bug on certain 82573 based NICs.
114  */
115 #define EM_RDTR_82573                             32
116 
117 /*
118  * Receive Interrupt Absolute Delay Timer (Not valid for 82542/82543/82544)
119  *
120  * NOTE:
121  * RDTR and RADV are deprecated; use ITR instead.  They are only used to
122  * workaround hardware bug on certain 82573 based NICs.
123  */
124 #define EM_RADV_82573                             64
125 
126 /*
127  * This parameter controls the duration of transmit watchdog timer.
128  */
129 #define EM_TX_TIMEOUT                             5
130 
131 /* One for TX csum offloading desc, the other 2 are reserved */
132 #define EM_TX_RESERVED                            3
133 
134 /* Large enough for 16K jumbo frame */
135 #define EM_TX_SPARE                     8
136 /* Large enough for 64K jumbo frame */
137 #define EM_TX_SPARE_TSO                           33
138 
139 #define EM_TX_OACTIVE_MAX               64
140 
141 /* Interrupt throttle rate */
142 #define EM_DEFAULT_ITR                            6000
143 
144 /* Number of segments sent before writing to TX related registers */
145 #define EM_DEFAULT_TXWREG               8
146 
147 /*
148  * This parameter controls whether or not autonegotation is enabled.
149  *              0 - Disable autonegotiation
150  *              1 - Enable  autonegotiation
151  */
152 #define DO_AUTO_NEG                     1
153 
154 /*
155  * This parameter control whether or not the driver will wait for
156  * autonegotiation to complete.
157  *              1 - Wait for autonegotiation to complete
158  *              0 - Don't wait for autonegotiation to complete
159  */
160 #define WAIT_FOR_AUTO_NEG_DEFAULT       0
161 
162 /* Tunables -- End */
163 
164 #define AUTONEG_ADV_DEFAULT             (ADVERTISE_10_HALF | \
165                                                    ADVERTISE_10_FULL | \
166                                                    ADVERTISE_100_HALF | \
167                                                    ADVERTISE_100_FULL | \
168                                                    ADVERTISE_1000_FULL)
169 
170 #define AUTO_ALL_MODES                            0
171 
172 /* PHY master/slave setting */
173 #define EM_MASTER_SLAVE                           e1000_ms_hw_default
174 
175 /*
176  * Micellaneous constants
177  */
178 #define EM_VENDOR_ID                              0x8086
179 
180 #define EM_BAR_MEM                      PCIR_BAR(0)
181 #define EM_BAR_FLASH                              PCIR_BAR(1)
182 
183 #define EM_JUMBO_PBA                              0x00000028
184 #define EM_DEFAULT_PBA                            0x00000030
185 #define EM_SMARTSPEED_DOWNSHIFT                   3
186 #define EM_SMARTSPEED_MAX               15
187 #define EM_MAX_INTR                     10
188 
189 #define MAX_NUM_MULTICAST_ADDRESSES     128
190 #define PCI_ANY_ID                      (~0U)
191 #define EM_FC_PAUSE_TIME                1000
192 #define EM_EEPROM_APME                            0x400;
193 
194 #define PCICFG_DESC_RING_STATUS                   0xe4
195 #define FLUSH_DESC_REQUIRED             0x100
196 
197 /*
198  * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
199  * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
200  * also optimize cache line size effect. H/W supports up to cache line size 128.
201  */
202 #define EM_DBA_ALIGN                              128
203 
204 #define TARC_SPEED_MODE_BIT             (1 << 21) /* On PCI-E MACs only */
205 #define TARC_ERRATA_BIT                           (1 << 26) /* Note from errata on 82574 */
206 
207 /* PCI Config defines */
208 #define EM_BAR_TYPE(v)                            ((v) & EM_BAR_TYPE_MASK)
209 #define EM_BAR_TYPE_MASK                0x00000001
210 #define EM_BAR_TYPE_MMEM                0x00000000
211 #define EM_BAR_TYPE_IO                            0x00000001
212 #define EM_BAR_MEM_TYPE(v)              ((v) & EM_BAR_MEM_TYPE_MASK)
213 #define EM_BAR_MEM_TYPE_MASK            0x00000006
214 #define EM_BAR_MEM_TYPE_32BIT           0x00000000
215 #define EM_BAR_MEM_TYPE_64BIT           0x00000004
216 
217 #define EM_MAX_SCATTER                            64
218 #define EM_TSO_SIZE                     (IP_MAXPACKET + \
219                                                    sizeof(struct ether_vlan_header))
220 #define EM_MSIX_MASK                              0x01F00000 /* For 82574 use */
221 #define ETH_ZLEN                        60
222 
223 #define EM_CSUM_FEATURES                (CSUM_IP | CSUM_TCP | CSUM_UDP)
224 
225 /*
226  * 82574 has a nonstandard address for EIAC
227  * and since its only used in MSIX, and in
228  * the em driver only 82574 uses MSIX we can
229  * solve it just using this define.
230  */
231 #define EM_EIAC                                   0x000DC
232 
233 /* Used in for 82547 10Mb Half workaround */
234 #define EM_PBA_BYTES_SHIFT              0xA
235 #define EM_TX_HEAD_ADDR_SHIFT           7
236 #define EM_PBA_TX_MASK                            0xFFFF0000
237 #define EM_FIFO_HDR                     0x10
238 #define EM_82547_PKT_THRESH             0x3e0
239 
240 /*
241  * Bus dma allocation structure used by
242  * em_dma_malloc and em_dma_free.
243  */
244 struct em_dma_alloc {
245           bus_addr_t                    dma_paddr;
246           void                          *dma_vaddr;
247           bus_dma_tag_t                 dma_tag;
248           bus_dmamap_t                  dma_map;
249 };
250 
251 /* Our adapter structure */
252 struct adapter {
253           struct arpcom                 arpcom;
254           struct e1000_hw               hw;
255           int                           flags;
256 #define EM_FLAG_SHARED_INTR   0x0001
257 #define EM_FLAG_HAS_MGMT      0x0002
258 #define EM_FLAG_HAS_AMT                 0x0004
259 #define EM_FLAG_HW_CTRL                 0x0008
260 #define EM_FLAG_TSO           0x0010
261 #define EM_FLAG_TSO_PULLEX    0x0020
262 #define EM_FLAG_GEN2                    0x0040
263 
264           /* DragonFly operating-system-specific structures. */
265           struct e1000_osdep  osdep;
266           device_t            dev;
267 
268           bus_dma_tag_t                 parent_dtag;
269 
270           struct resource               *memory;
271           int                           memory_rid;
272           struct resource               *flash;
273           int                           flash_rid;
274 
275           struct resource               *ioport;
276           int                           io_rid;
277 
278           struct resource               *intr_res;
279           void                          *intr_tag;
280           int                           intr_rid;
281           int                           intr_type;
282 
283           struct ifmedia                media;
284           struct callout                timer;
285           struct callout                tx_fifo_timer;
286           int                           if_flags;
287           int                           min_frame_size;
288 
289           /* WOL register value */
290           int                           wol;
291 
292           /* Multicast array memory */
293           uint8_t                       *mta;
294 
295           /* Info about the board itself */
296           uint8_t                       link_active;
297           uint16_t            link_speed;
298           uint16_t            link_duplex;
299           uint32_t            smartspeed;
300           int                           int_throttle_ceil;
301 
302           /* Polling */
303           struct ifpoll_compat          npoll;
304 
305           /*
306            * Transmit definitions
307            *
308            * We have an array of num_tx_desc descriptors (handled
309            * by the controller) paired with an array of tx_buffers
310            * (at tx_buffer_area).
311            * The index of the next available descriptor is next_avail_tx_desc.
312            * The number of remaining tx_desc is num_tx_desc_avail.
313            */
314           struct em_dma_alloc txdma;              /* bus_dma glue for tx desc */
315           struct e1000_tx_desc          *tx_desc_base;
316           struct em_buffer    *tx_buffer_area;
317           uint32_t            next_avail_tx_desc;
318           uint32_t            next_tx_to_clean;
319           int                           num_tx_desc_avail;
320           int                           num_tx_desc;
321           bus_dma_tag_t                 txtag;              /* dma tag for tx */
322           int                           spare_tx_desc;
323           int                           oact_tx_desc;
324           int                           tx_nmbuf;
325           int                           tx_running;
326 #define EM_TX_RUNNING                   100
327 #define EM_TX_RUNNING_DEC     25
328           struct callout                tx_gc_timer;
329 
330           /* Saved csum offloading context information */
331           int                           csum_flags;
332           int                           csum_lhlen;
333           int                           csum_iphlen;
334 
335           int                           csum_thlen;         /* TSO */
336           int                           csum_mss; /* TSO */
337           int                           csum_pktlen;        /* TSO */
338 
339           uint32_t            csum_txd_upper;
340           uint32_t            csum_txd_lower;
341 
342           int                           tx_wreg_nsegs;
343 
344           /*
345            * Variables used to reduce TX interrupt rate and
346            * number of device's TX ring write requests.
347            *
348            * tx_nsegs:
349            * Number of TX descriptors setup so far.
350            *
351            * tx_int_nsegs:
352            * Once tx_nsegs > tx_int_nsegs, RS bit will be set
353            * in the last TX descriptor of the packet, and
354            * tx_nsegs will be reset to 0.  So TX interrupt and
355            * TX ring write request should be generated roughly
356            * every tx_int_nsegs TX descriptors.
357            *
358            * tx_dd[]:
359            * Index of the TX descriptors which have RS bit set,
360            * i.e. DD bit will be set on this TX descriptor after
361            * the data of the TX descriptor are transfered to
362            * hardware's internal packet buffer.  Only the TX
363            * descriptors listed in tx_dd[] will be checked upon
364            * TX interrupt.  This array is used as circular ring.
365            *
366            * tx_dd_tail, tx_dd_head:
367            * Tail and head index of valid elements in tx_dd[].
368            * tx_dd_tail == tx_dd_head means there is no valid
369            * elements in tx_dd[].  tx_dd_tail points to the position
370            * which is one beyond the last valid element in tx_dd[].
371            * tx_dd_head points to the first valid element in
372            * tx_dd[].
373            */
374           int                           tx_int_nsegs;
375           int                           tx_nsegs;
376           int                           tx_dd_tail;
377           int                           tx_dd_head;
378 #define EM_TXDD_MAX 64
379 #define EM_TXDD_SAFE          48 /* must be less than EM_TXDD_MAX */
380           int                           tx_dd[EM_TXDD_MAX];
381 
382           /*
383            * Receive definitions
384            *
385            * we have an array of num_rx_desc rx_desc (handled by the
386            * controller), and paired with an array of rx_buffers
387            * (at rx_buffer_area).
388            * The next pair to check on receive is at offset next_rx_desc_to_check
389            */
390           struct em_dma_alloc rxdma;              /* bus_dma glue for rx desc */
391           struct e1000_rx_desc          *rx_desc_base;
392           uint32_t            next_rx_desc_to_check;
393           uint32_t            rx_buffer_len;
394           int                           num_rx_desc;
395           struct em_buffer    *rx_buffer_area;
396           bus_dma_tag_t                 rxtag;
397           bus_dmamap_t                  rx_sparemap;
398 
399           /*
400            * First/last mbuf pointers, for
401            * collecting multisegment RX packets.
402            */
403           struct mbuf                   *fmp;
404           struct mbuf                   *lmp;
405 
406           int                           ifm_flowctrl;
407 
408           /* Misc stats maintained by the driver */
409           unsigned long                 dropped_pkts;
410           unsigned long                 mbuf_alloc_failed;
411           unsigned long                 mbuf_cluster_failed;
412           unsigned long                 no_tx_desc_avail1;
413           unsigned long                 no_tx_desc_avail2;
414           unsigned long                 no_tx_map_avail;
415           unsigned long                 no_tx_dma_setup;
416           unsigned long                 watchdog_events;
417           unsigned long                 rx_overruns;
418           unsigned long                 rx_irq;
419           unsigned long                 tx_irq;
420           unsigned long                 link_irq;
421           unsigned long                 tx_gc;
422 
423           /* 82547 workaround */
424           uint32_t            tx_fifo_size;
425           uint32_t            tx_fifo_head;
426           uint32_t            tx_fifo_head_addr;
427           uint64_t            tx_fifo_reset_cnt;
428           uint64_t            tx_fifo_wrk_cnt;
429           uint32_t            tx_head_addr;
430 
431         /* For 82544 PCIX Workaround */
432           boolean_t           pcix_82544;
433 
434           struct e1000_hw_stats         stats;
435 };
436 
437 struct em_vendor_info {
438           uint16_t  vendor_id;
439           uint16_t  device_id;
440           int                 ret;
441           const char          *desc;
442 };
443 
444 struct em_buffer {
445           struct mbuf         *m_head;
446           bus_dmamap_t        map;                /* bus_dma map for packet */
447 };
448 
449 /* For 82544 PCIX  Workaround */
450 typedef struct _ADDRESS_LENGTH_PAIR {
451           uint64_t  address;
452           uint32_t  length;
453 } ADDRESS_LENGTH_PAIR, *PADDRESS_LENGTH_PAIR;
454 
455 typedef struct _DESCRIPTOR_PAIR {
456           ADDRESS_LENGTH_PAIR descriptor[4];
457           uint32_t  elements;
458 } DESC_ARRAY, *PDESC_ARRAY;
459 
460 #define EM_IS_OACTIVE(adapter) \
461           ((adapter)->num_tx_desc_avail <= (adapter)->oact_tx_desc)
462 
463 #define EM_INC_TXDD_IDX(idx) \
464 do { \
465           if (++(idx) == EM_TXDD_MAX) \
466                     (idx) = 0; \
467 } while (0)
468 
469 #endif /* _IF_EM_H_ */
470