if_em.h revision 1.2
1/**************************************************************************
2
3Copyright (c) 2001-2003, Intel Corporation
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10    this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
15
16 3. Neither the name of the Intel Corporation nor the names of its
17    contributors may be used to endorse or promote products derived from
18    this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30POSSIBILITY OF SUCH DAMAGE.
31
32***************************************************************************/
33
34/*$FreeBSD: if_em.h,v 1.16 2003/06/05 17:51:38 pdeuskar Exp $*/
35/* $OpenBSD: if_em.h,v 1.2 2003/06/13 19:21:21 henric Exp $ */
36
37#ifndef _EM_H_DEFINED_
38#define _EM_H_DEFINED_
39
40#include <dev/pci/if_em_hw.h>
41
42/* Tunables */
43
44/*
45 * TxDescriptors
46 * Valid Range: 80-256 for 82542 and 82543-based adapters
47 *              80-4096 for others
48 * Default Value: 256
49 *   This value is the number of transmit descriptors allocated by the driver.
50 *   Increasing this value allows the driver to queue more transmits. Each
51 *   descriptor is 16 bytes.
52 */
53#define EM_MAX_TXD                      256
54
55/*
56 * RxDescriptors
57 * Valid Range: 80-256 for 82542 and 82543-based adapters
58 *              80-4096 for others
59 * Default Value: 256
60 *   This value is the number of receive descriptors allocated by the driver.
61 *   Increasing this value allows the driver to buffer more incoming packets.
62 *   Each descriptor is 16 bytes.  A receive buffer is also allocated for each
63 *   descriptor. The maximum MTU size is 16110.
64 *
65 */
66#define EM_MAX_RXD                      256
67
68/*
69 * TxIntDelay
70 * Valid Range: 0-65535 (0=off)
71 * Default Value: 64
72 *   This value delays the generation of transmit interrupts in units of
73 *   1.024 microseconds. Transmit interrupt reduction can improve CPU
74 *   efficiency if properly tuned for specific network traffic. If the
75 *   system is reporting dropped transmits, this value may be set too high
76 *   causing the driver to run out of available transmit descriptors.
77 */
78#define EM_TIDV                         64
79
80/*
81 * TxAbsIntDelay (Not valid for 82542 and 82543)
82 * Valid Range: 0-65535 (0=off)
83 * Default Value: 64
84 *   This value, in units of 1.024 microseconds, limits the delay in which a
85 *   transmit interrupt is generated. Useful only if TxIntDelay is non-zero,
86 *   this value ensures that an interrupt is generated after the initial
87 *   packet is sent on the wire within the set amount of time.  Proper tuning,
88 *   along with TxIntDelay, may improve traffic throughput in specific
89 *   network conditions.
90 */
91#define EM_TADV                         64
92
93/*
94 * RxIntDelay
95 * Valid Range: 0-65535 (0=off)
96 * Default Value: 0
97 *   This value delays the generation of receive interrupts in units of 1.024
98 *   microseconds.  Receive interrupt reduction can improve CPU efficiency if
99 *   properly tuned for specific network traffic. Increasing this value adds
100 *   extra latency to frame reception and can end up decreasing the throughput
101 *   of TCP traffic. If the system is reporting dropped receives, this value
102 *   may be set too high, causing the driver to run out of available receive
103 *   descriptors.
104 *
105 *   CAUTION: When setting RxIntDelay to a value other than 0, adapters
106 *            may hang (stop transmitting) under certain network conditions.
107 *            If this occurs a WATCHDOG message is logged in the system event log.
108 *            In addition, the controller is automatically reset, restoring the
109 *            network connection. To eliminate the potential for the hang
110 *            ensure that RxIntDelay is set to 0.
111 */
112#define EM_RDTR                         0
113
114/*
115 * RxAbsIntDelay (Not valid for 82542 and 82543)
116 * Valid Range: 0-65535 (0=off)
117 * Default Value: 64
118 *   This value, in units of 1.024 microseconds, limits the delay in which a
119 *   receive interrupt is generated. Useful only if RxIntDelay is non-zero,
120 *   this value ensures that an interrupt is generated after the initial
121 *   packet is received within the set amount of time.  Proper tuning,
122 *   along with RxIntDelay, may improve traffic throughput in specific network
123 *   conditions.
124 */
125#define EM_RADV                         64
126
127
128/*
129 * This parameter controls the maximum no of times the driver will loop
130 * in the isr.
131 *           Minimum Value = 1
132 */
133#define EM_MAX_INTR                     3
134
135/*
136 * Inform the stack about transmit checksum offload capabilities.
137 */
138#define EM_CHECKSUM_FEATURES            (CSUM_TCP | CSUM_UDP)
139
140/*
141 * This parameter controls the duration of transmit watchdog timer.
142 */
143#define EM_TX_TIMEOUT                   5    /* set to 5 seconds */
144
145/*
146 * This parameter controls when the driver calls the routine to reclaim
147 * transmit descriptors.
148 */
149#define EM_TX_CLEANUP_THRESHOLD         EM_MAX_TXD / 8
150
151/*
152 * This parameter controls whether or not autonegotation is enabled.
153 *              0 - Disable autonegotiation
154 *              1 - Enable  autonegotiation
155 */
156#define DO_AUTO_NEG                     1
157
158/*
159 * This parameter control whether or not the driver will wait for
160 * autonegotiation to complete.
161 *              1 - Wait for autonegotiation to complete
162 *              0 - Don't wait for autonegotiation to complete
163 */
164#define WAIT_FOR_AUTO_NEG_DEFAULT       0
165
166
167/* Tunables -- End */
168
169#define AUTONEG_ADV_DEFAULT      (ADVERTISE_10_HALF | ADVERTISE_10_FULL | \
170                                  ADVERTISE_100_HALF | ADVERTISE_100_FULL | \
171                                  ADVERTISE_1000_FULL)
172
173#define EM_VENDOR_ID                    0x8086
174#define EM_MMBA                         0x0010 /* Mem base address */
175#define EM_ROUNDUP(size, unit) (((size) + (unit) - 1) & ~((unit) - 1))
176
177#define EM_JUMBO_PBA                    0x00000028
178#define EM_DEFAULT_PBA                  0x00000030
179#define EM_SMARTSPEED_DOWNSHIFT         3
180#define EM_SMARTSPEED_MAX               15
181
182
183#define MAX_NUM_MULTICAST_ADDRESSES     128
184#define PCI_ANY_ID                      (~0U)
185#define ETHER_ALIGN                     2
186
187/* Defines for printing debug information */
188#define DEBUG_INIT  0
189#define DEBUG_IOCTL 0
190#define DEBUG_HW    0
191
192#define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
193#define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
194#define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
195#define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
196#define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
197#define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
198#define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
199#define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
200#define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
201
202
203/* Supported RX Buffer Sizes */
204#define EM_RXBUFFER_2048        2048
205#define EM_RXBUFFER_4096        4096
206#define EM_RXBUFFER_8192        8192
207#define EM_RXBUFFER_16384      16384
208
209#define EM_MAX_SCATTER            64
210
211#ifdef __FreeBSD__
212#ifdef __alpha__
213       #undef vtophys
214       #define vtophys(va)     alpha_XXX_dmamap((vm_offset_t)(va))
215#endif /* __alpha__ */
216#endif /* __FreeBSD__ */
217
218/* ******************************************************************************
219 * vendor_info_array
220 *
221 * This array contains the list of Subvendor/Subdevice IDs on which the driver
222 * should load.
223 *
224 * ******************************************************************************/
225#ifdef __FreeBSD__
226typedef struct _em_vendor_info_t {
227        unsigned int vendor_id;
228        unsigned int device_id;
229        unsigned int subvendor_id;
230        unsigned int subdevice_id;
231        unsigned int index;
232} em_vendor_info_t;
233#endif /* __FreeBSD__ */
234
235
236struct em_buffer {
237        struct mbuf    *m_head;
238	bus_dmamap_t	map;		/* bus_dma map for packet */
239};
240
241struct em_q {
242	bus_dmamap_t       map;         /* bus_dma map for packet */
243#ifdef __FreeBSD__
244	int                nsegs;       /* # of segments/descriptors */
245	bus_dma_segment_t  segs[EM_MAX_SCATTER];
246#endif /* __FreeBSD__ */
247};
248
249/*
250 * Bus dma allocation structure used by
251 * em_dma_malloc and em_dma_free.
252 */
253struct em_dma_alloc {
254	bus_addr_t              dma_paddr;
255	caddr_t                 dma_vaddr;
256	bus_dma_tag_t           dma_tag;
257	bus_dmamap_t            dma_map;
258	bus_dma_segment_t       dma_seg;
259	bus_size_t              dma_size;
260	int                     dma_nseg;
261};
262
263typedef enum _XSUM_CONTEXT_T {
264	OFFLOAD_NONE,
265	OFFLOAD_TCP_IP,
266	OFFLOAD_UDP_IP
267} XSUM_CONTEXT_T;
268
269/* Our adapter structure */
270struct em_softc {
271	struct device	sc_dv;
272	struct arpcom	interface_data;
273	struct em_softc *next;
274	struct em_softc *prev;
275	struct em_hw    hw;
276
277	/* FreeBSD operating-system-specific structures */
278	struct em_osdep osdep;
279
280	int             io_rid;
281	void           *sc_intrhand;
282	struct ifmedia  media;
283
284	struct timeout	em_intr_enable;
285	struct timeout	timer_handle;
286	struct timeout	tx_fifo_timer_handle;
287
288	/* Info about the board itself */
289	u_int32_t       part_num;
290	u_int8_t        link_active;
291	u_int16_t       link_speed;
292	u_int16_t       link_duplex;
293	u_int32_t       smartspeed;
294	u_int32_t       tx_int_delay;
295	u_int32_t	tx_abs_int_delay;
296	u_int32_t       rx_int_delay;
297	u_int32_t	rx_abs_int_delay;
298
299	XSUM_CONTEXT_T  active_checksum_context;
300
301        /*
302         * Transmit definitions
303         *
304         * We have an array of num_tx_desc descriptors (handled
305         * by the controller) paired with an array of tx_buffers
306         * (at tx_buffer_area).
307         * The index of the next available descriptor is next_avail_tx_desc.
308         * The number of remaining tx_desc is num_tx_desc_avail.
309         */
310	struct em_dma_alloc	txdma;		/* bus_dma glue for tx desc */
311	struct em_tx_desc	*tx_desc_base;
312	u_int32_t		next_avail_tx_desc;
313	u_int32_t		oldest_used_tx_desc;
314	volatile u_int16_t	num_tx_desc_avail;
315	u_int16_t		num_tx_desc;
316	u_int32_t		txd_cmd;
317	struct em_buffer	*tx_buffer_area;
318	bus_dma_tag_t		txtag;		/* dma tag for tx */
319
320        /*
321         * Receive definitions
322         *
323         * we have an array of num_rx_desc rx_desc (handled by the
324         * controller), and paired with an array of rx_buffers
325         * (at rx_buffer_area).
326         * The next pair to check on receive is at offset next_rx_desc_to_check
327         */
328	struct em_dma_alloc	rxdma;		/* bus_dma glue for rx desc */
329	struct em_rx_desc	*rx_desc_base;
330	u_int32_t		next_rx_desc_to_check;
331	u_int16_t		num_rx_desc;
332	u_int32_t		rx_buffer_len;
333	struct em_buffer	*rx_buffer_area;
334	bus_dma_tag_t		rxtag;
335
336	/* Jumbo frame */
337	struct mbuf        *fmp;
338	struct mbuf        *lmp;
339
340	u_int16_t          tx_fifo_head;
341
342	/* Misc stats maintained by the driver */
343	unsigned long   dropped_pkts;
344	unsigned long   mbuf_alloc_failed;
345	unsigned long   mbuf_cluster_failed;
346	unsigned long   no_tx_desc_avail1;
347	unsigned long   no_tx_desc_avail2;
348	unsigned long   no_tx_map_avail;
349        unsigned long   no_tx_dma_setup;
350	u_int64_t       tx_fifo_reset;
351	u_int64_t       tx_fifo_wrk;
352
353#ifdef DBG_STATS
354	unsigned long   no_pkts_avail;
355	unsigned long   clean_tx_interrupts;
356
357#endif
358	struct em_hw_stats stats;
359};
360
361#endif                                                  /* _EM_H_DEFINED_ */
362