Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
[dragonfly.git] / sys / dev / netif / emx / if_emx.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_EMX_H_
33 #define _IF_EMX_H_
34
35 /* Tunables */
36
37 /*
38  * EMX_TXD: Maximum number of Transmit Descriptors
39  * Valid Range: 256-4096 for others
40  * Default Value: 512
41  *   This value is the number of transmit descriptors allocated by the driver.
42  *   Increasing this value allows the driver to queue more transmits. Each
43  *   descriptor is 16 bytes.
44  *   Since TDLEN should be multiple of 128bytes, the number of transmit
45  *   desscriptors should meet the following condition.
46  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
47  */
48 #define EMX_MIN_TXD                     256
49 #define EMX_MAX_TXD                     4096
50 #define EMX_DEFAULT_TXD                 512
51
52 /*
53  * EMX_RXD - Maximum number of receive Descriptors
54  * Valid Range: 256-4096 for others
55  * Default Value: 512
56  *   This value is the number of receive descriptors allocated by the driver.
57  *   Increasing this value allows the driver to buffer more incoming packets.
58  *   Each descriptor is 16 bytes.  A receive buffer is also allocated for each
59  *   descriptor. The maximum MTU size is 16110.
60  *   Since TDLEN should be multiple of 128bytes, the number of transmit
61  *   desscriptors should meet the following condition.
62  *      (num_tx_desc * sizeof(struct e1000_tx_desc)) % 128 == 0
63  */
64 #define EMX_MIN_RXD                     256
65 #define EMX_MAX_RXD                     4096
66 #define EMX_DEFAULT_RXD                 512
67
68 /*
69  * Receive Interrupt Delay Timer (Packet Timer)
70  *
71  * NOTE:
72  * RDTR and RADV are deprecated; use ITR instead.  They are only used to
73  * workaround hardware bug on certain 82573 based NICs.
74  */
75 #define EMX_RDTR_82573                  32
76
77 /*
78  * Receive Interrupt Absolute Delay Timer (Not valid for 82542/82543/82544)
79  *
80  * NOTE:
81  * RDTR and RADV are deprecated; use ITR instead.  They are only used to
82  * workaround hardware bug on certain 82573 based NICs.
83  */
84 #define EMX_RADV_82573                  64
85
86 /*
87  * This parameter controls the duration of transmit watchdog timer.
88  */
89 #define EMX_TX_TIMEOUT                  5
90
91 /* One for TX csum offloading desc, the other is reserved */
92 #define EMX_TX_RESERVED                 2
93
94 /* Large enough for 16K jumbo frame */
95 #define EMX_TX_SPARE                    8
96
97 #define EMX_TX_OACTIVE_MAX              64
98
99 /* Interrupt throttle rate */
100 #define EMX_DEFAULT_ITR                 10000
101
102 /*
103  * This parameter controls whether or not autonegotation is enabled.
104  *              0 - Disable autonegotiation
105  *              1 - Enable  autonegotiation
106  */
107 #define EMX_DO_AUTO_NEG                 1
108
109 /* Tunables -- End */
110
111 #define EMX_AUTONEG_ADV_DEFAULT         (ADVERTISE_10_HALF | \
112                                          ADVERTISE_10_FULL | \
113                                          ADVERTISE_100_HALF | \
114                                          ADVERTISE_100_FULL | \
115                                          ADVERTISE_1000_FULL)
116
117 #define EMX_AUTO_ALL_MODES              0
118
119 /* PHY master/slave setting */
120 #define EMX_MASTER_SLAVE                e1000_ms_hw_default
121
122 /*
123  * Micellaneous constants
124  */
125 #define EMX_VENDOR_ID                   0x8086
126
127 #define EMX_BAR_MEM                     PCIR_BAR(0)
128
129 #define EMX_JUMBO_PBA                   0x00000028
130 #define EMX_DEFAULT_PBA                 0x00000030
131 #define EMX_SMARTSPEED_DOWNSHIFT        3
132 #define EMX_SMARTSPEED_MAX              15
133 #define EMX_MAX_INTR                    10
134
135 #define EMX_MCAST_ADDR_MAX              128
136 #define EMX_FC_PAUSE_TIME               1000
137 #define EMX_EEPROM_APME                 0x400;
138
139 /*
140  * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
141  * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
142  * also optimize cache line size effect. H/W supports up to cache line size 128.
143  */
144 #define EMX_DBA_ALIGN                   128
145
146 /*
147  * Speed mode bit in TARC0/TARC1.
148  * 82571EB/82572EI only, used to improve small packet transmit performance.
149  */
150 #define EMX_TARC_SPEED_MODE             (1 << 21)
151
152 #define EMX_MAX_SCATTER                 64
153 #define EMX_TSO_SIZE                    (65535 + \
154                                          sizeof(struct ether_vlan_header))
155 #define EMX_MAX_SEGSIZE                 4096
156 #define EMX_MSIX_MASK                   0x01F00000 /* For 82574 use */
157
158 #define EMX_CSUM_FEATURES               (CSUM_IP | CSUM_TCP | CSUM_UDP)
159 #define EMX_IPVHL_SIZE                  1 /* sizeof(ip.ip_vhl) */
160 #define EMX_TXCSUM_MINHL                (ETHER_HDR_LEN + EVL_ENCAPLEN + \
161                                          EMX_IPVHL_SIZE)
162
163 /*
164  * 82574 has a nonstandard address for EIAC
165  * and since its only used in MSIX, and in
166  * the em driver only 82574 uses MSIX we can
167  * solve it just using this define.
168  */
169 #define EMX_EIAC                        0x000DC
170
171 /*
172  * busdma(9) information structure used by
173  * emx_dma_malloc() and emx_dma_free().
174  */
175 struct emx_dma {
176         bus_addr_t              dma_paddr;
177         void                    *dma_vaddr;
178         bus_dma_tag_t           dma_tag;
179         bus_dmamap_t            dma_map;
180 };
181
182 struct emx_softc {
183         struct arpcom           arpcom;
184         struct e1000_hw         hw;
185
186         /* DragonFly operating-system-specific structures. */
187         struct e1000_osdep      osdep;
188         device_t                dev;
189
190         bus_dma_tag_t           parent_dtag;
191         struct emx_dma          rxdma;          /* bus_dma glue for rx desc */
192         struct emx_dma          txdma;          /* bus_dma glue for tx desc */
193
194         struct resource         *memory;
195         int                     memory_rid;
196
197         struct resource         *intr_res;
198         void                    *intr_tag;
199         int                     intr_rid;
200
201         struct ifmedia          media;
202         struct callout          timer;
203         int                     if_flags;
204         int                     max_frame_size;
205         int                     min_frame_size;
206
207         /* Management and WOL features */
208         int                     wol;
209         int                     has_manage;
210
211         /* Info about the board itself */
212         uint8_t                 link_active;
213         uint16_t                link_speed;
214         uint16_t                link_duplex;
215         uint32_t                smartspeed;
216         int                     int_throttle_ceil;
217
218         /*
219          * Transmit definitions
220          *
221          * We have an array of num_tx_desc descriptors (handled
222          * by the controller) paired with an array of tx_buffers
223          * (at tx_buffer_area).
224          * The index of the next available descriptor is next_avail_tx_desc.
225          * The number of remaining tx_desc is num_tx_desc_avail.
226          */
227         struct e1000_tx_desc    *tx_desc_base;
228         struct emx_buf          *tx_buffer_area;
229         uint32_t                next_avail_tx_desc;
230         uint32_t                next_tx_to_clean;
231         int                     num_tx_desc_avail;
232         int                     num_tx_desc;
233         bus_dma_tag_t           txtag;          /* dma tag for tx */
234         int                     spare_tx_desc;
235         int                     oact_tx_desc;
236
237         /* Saved csum offloading context information */
238         int                     csum_flags;
239         int                     csum_ehlen;
240         int                     csum_iphlen;
241         uint32_t                csum_txd_upper;
242         uint32_t                csum_txd_lower;
243
244         /*
245          * Variables used to reduce TX interrupt rate and
246          * number of device's TX ring write requests.
247          *
248          * tx_nsegs:
249          * Number of TX descriptors setup so far.
250          *
251          * tx_int_nsegs:
252          * Once tx_nsegs > tx_int_nsegs, RS bit will be set
253          * in the last TX descriptor of the packet, and
254          * tx_nsegs will be reset to 0.  So TX interrupt and
255          * TX ring write request should be generated roughly
256          * every tx_int_nsegs TX descriptors.
257          *
258          * tx_dd[]:
259          * Index of the TX descriptors which have RS bit set,
260          * i.e. DD bit will be set on this TX descriptor after
261          * the data of the TX descriptor are transfered to
262          * hardware's internal packet buffer.  Only the TX
263          * descriptors listed in tx_dd[] will be checked upon
264          * TX interrupt.  This array is used as circular ring.
265          *
266          * tx_dd_tail, tx_dd_head:
267          * Tail and head index of valid elements in tx_dd[].
268          * tx_dd_tail == tx_dd_head means there is no valid
269          * elements in tx_dd[].  tx_dd_tail points to the position
270          * which is one beyond the last valid element in tx_dd[].
271          * tx_dd_head points to the first valid element in
272          * tx_dd[].
273          */
274         int                     tx_int_nsegs;
275         int                     tx_nsegs;
276         int                     tx_dd_tail;
277         int                     tx_dd_head;
278 #define EMX_TXDD_MAX    64
279 #define EMX_TXDD_SAFE   48 /* 48 <= val < EMX_TXDD_MAX */
280         int                     tx_dd[EMX_TXDD_MAX];
281
282         /*
283          * Receive definitions
284          *
285          * we have an array of num_rx_desc rx_desc (handled by the
286          * controller), and paired with an array of rx_buffers
287          * (at rx_buffer_area).
288          * The next pair to check on receive is at offset next_rx_desc_to_check
289          */
290         struct e1000_rx_desc    *rx_desc_base;
291         uint32_t                next_rx_desc_to_check;
292         uint32_t                rx_buffer_len;
293         int                     num_rx_desc;
294         struct emx_buf          *rx_buffer_area;
295         bus_dma_tag_t           rxtag;
296         bus_dmamap_t            rx_sparemap;
297
298         /*
299          * First/last mbuf pointers, for
300          * collecting multisegment RX packets.
301          */
302         struct mbuf             *fmp;
303         struct mbuf             *lmp;
304
305         /* Misc stats maintained by the driver */
306         unsigned long           dropped_pkts;
307         unsigned long           mbuf_alloc_failed;
308         unsigned long           mbuf_cluster_failed;
309         unsigned long           no_tx_desc_avail1;
310         unsigned long           no_tx_desc_avail2;
311         unsigned long           no_tx_map_avail;
312         unsigned long           no_tx_dma_setup;
313         unsigned long           watchdog_events;
314         unsigned long           rx_overruns;
315         unsigned long           rx_irq;
316         unsigned long           tx_irq;
317         unsigned long           link_irq;
318         unsigned long           tx_csum_try_pullup;
319         unsigned long           tx_csum_pullup1;
320         unsigned long           tx_csum_pullup1_failed;
321         unsigned long           tx_csum_pullup2;
322         unsigned long           tx_csum_pullup2_failed;
323         unsigned long           tx_csum_drop1;
324         unsigned long           tx_csum_drop2;
325
326         /* sysctl tree glue */
327         struct sysctl_ctx_list  sysctl_ctx;
328         struct sysctl_oid       *sysctl_tree;
329
330         struct e1000_hw_stats   stats;
331 };
332
333 struct emx_buf {
334         struct mbuf     *m_head;
335         bus_dmamap_t    map;
336 };
337
338 #define EMX_IS_OACTIVE(sc)      ((sc)->num_tx_desc_avail <= (sc)->oact_tx_desc)
339
340 #define EMX_INC_TXDD_IDX(idx) \
341 do { \
342         if (++(idx) == EMX_TXDD_MAX) \
343                 (idx) = 0; \
344 } while (0)
345
346 #endif /* !_IF_EMX_H_ */