if_em.h revision 102452
1/**************************************************************************
2
3Copyright (c) 2001-2002 Intel Corporation
4All rights reserved.
5
6Redistribution and use in source and binary forms of the Software, with or
7without modification, are permitted provided that the following conditions
8are met:
9
10 1. Redistributions of source code of the Software may retain the above
11    copyright notice, this list of conditions and the following disclaimer.
12
13 2. Redistributions in binary form of the Software may reproduce the above
14    copyright notice, this list of conditions and the following disclaimer
15    in the documentation and/or other materials provided with the
16    distribution.
17
18 3. Neither the name of the Intel Corporation nor the names of its
19    contributors shall be used to endorse or promote products derived from
20    this Software without specific prior written permission.
21
22THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS CONTRIBUTORS BE LIABLE
26FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32SUCH DAMAGE.
33
34***************************************************************************/
35
36/*$FreeBSD: head/sys/dev/em/if_em.h 102452 2002-08-26 18:59:16Z pdeuskar $*/
37
38#ifndef _EM_H_DEFINED_
39#define _EM_H_DEFINED_
40
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/mbuf.h>
45#include <sys/protosw.h>
46#include <sys/socket.h>
47#include <sys/malloc.h>
48#include <sys/kernel.h>
49#include <sys/sockio.h>
50
51#include <net/if.h>
52#include <net/if_arp.h>
53#include <net/ethernet.h>
54#include <net/if_dl.h>
55#include <net/if_media.h>
56
57#include <net/bpf.h>
58#include <net/if_types.h>
59#include <net/if_vlan_var.h>
60
61#include <netinet/in_systm.h>
62#include <netinet/in.h>
63#include <netinet/ip.h>
64#include <netinet/tcp.h>
65#include <netinet/udp.h>
66
67#include <sys/bus.h>
68#include <machine/bus.h>
69#include <sys/rman.h>
70#include <machine/resource.h>
71#include <vm/vm.h>
72#include <vm/pmap.h>
73#include <machine/clock.h>
74#include <pci/pcivar.h>
75#include <pci/pcireg.h>
76#include "opt_bdg.h"
77
78#include <dev/em/if_em_hw.h>
79
80/* Tunables */
81#define MAX_TXD                         256
82#define MAX_RXD                         256
83#define TX_CLEANUP_THRESHOLD            MAX_TXD / 8
84#define TIDV                            128
85#define RIDV                            28
86#define DO_AUTO_NEG                     1
87#define WAIT_FOR_AUTO_NEG_DEFAULT       1
88#define AUTONEG_ADV_DEFAULT             (ADVERTISE_10_HALF | ADVERTISE_10_FULL | \
89                                         ADVERTISE_100_HALF | ADVERTISE_100_FULL | \
90                                         ADVERTISE_1000_FULL)
91#define EM_REPORT_TX_EARLY              2
92#define EM_CHECKSUM_FEATURES            (CSUM_TCP | CSUM_UDP)
93#define EM_MAX_INTR                     3
94#define EM_TX_TIMEOUT                   5    /* set to 5 seconds */
95
96
97#define EM_VENDOR_ID                    0x8086
98#define EM_MMBA                         0x0010 /* Mem base address */
99#define EM_ROUNDUP(size, unit) (((size) + (unit) - 1) & ~((unit) - 1))
100#define EM_JUMBO_PBA                    0x00000028
101#define EM_DEFAULT_PBA                  0x00000030
102
103#define IOCTL_CMD_TYPE                  u_long
104#define MAX_NUM_MULTICAST_ADDRESSES     128
105#define PCI_ANY_ID                      (~0U)
106#define ETHER_ALIGN                     2
107#define QTAG_TYPE                       0x8100
108
109/* Defines for printing debug information */
110#define DEBUG_INIT  0
111#define DEBUG_IOCTL 0
112#define DEBUG_HW    0
113
114#define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
115#define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
116#define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
117#define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
118#define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
119#define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
120#define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
121#define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
122#define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
123
124
125/* Supported RX Buffer Sizes */
126#define EM_RXBUFFER_2048        2048
127#define EM_RXBUFFER_4096        4096
128#define EM_RXBUFFER_8192        8192
129#define EM_RXBUFFER_16384      16384
130
131#ifdef __alpha__
132	#undef vtophys
133	#define vtophys(va)     alpha_XXX_dmamap((vm_offset_t)(va))
134#endif /* __alpha__ */
135
136/* ******************************************************************************
137 * vendor_info_array
138 *
139 * This array contains the list of Subvendor/Subdevice IDs on which the driver
140 * should load.
141 *
142 * ******************************************************************************/
143typedef struct _em_vendor_info_t
144{
145	unsigned int vendor_id;
146	unsigned int device_id;
147	unsigned int subvendor_id;
148	unsigned int subdevice_id;
149	unsigned int index;
150} em_vendor_info_t;
151
152
153struct em_tx_buffer {
154	STAILQ_ENTRY(em_tx_buffer) em_tx_entry;
155	struct mbuf    *m_head;
156	u_int32_t       num_tx_desc_used;
157};
158
159
160/* ******************************************************************************
161 * This structure stores information about the 2k aligned receive buffer
162 * into which the E1000 DMA's frames.
163 * ******************************************************************************/
164struct em_rx_buffer {
165	STAILQ_ENTRY(em_rx_buffer) em_rx_entry;
166	struct mbuf    *m_head;
167	u_int64_t      buffer_addr;
168};
169
170typedef enum _XSUM_CONTEXT_T {
171	OFFLOAD_NONE,
172	OFFLOAD_TCP_IP,
173	OFFLOAD_UDP_IP
174} XSUM_CONTEXT_T;
175
176/* Our adapter structure */
177struct adapter {
178	struct arpcom   interface_data;
179	struct adapter *next;
180	struct adapter *prev;
181	struct em_hw    hw;
182
183	/* FreeBSD operating-system-specific structures */
184	struct em_osdep osdep;
185	struct device   *dev;
186	struct resource *res_memory;
187	struct resource *res_ioport;
188	struct resource *res_interrupt;
189	void            *int_handler_tag;
190	struct ifmedia  media;
191	struct callout_handle timer_handle;
192	int             io_rid;
193	u_int8_t        unit;
194
195	/* Info about the board itself */
196	u_int32_t       part_num;
197	u_int8_t        link_active;
198	u_int16_t       link_speed;
199	u_int16_t       link_duplex;
200	u_int32_t       tx_int_delay;
201	u_int32_t       rx_int_delay;
202
203	XSUM_CONTEXT_T  active_checksum_context;
204
205	/* Transmit definitions */
206	struct em_tx_desc *first_tx_desc;
207	struct em_tx_desc *last_tx_desc;
208	struct em_tx_desc *next_avail_tx_desc;
209	struct em_tx_desc *oldest_used_tx_desc;
210	struct em_tx_desc *tx_desc_base;
211	volatile u_int16_t num_tx_desc_avail;
212	u_int16_t       num_tx_desc;
213	u_int32_t       txd_cmd;
214	struct em_tx_buffer   *tx_buffer_area;
215	STAILQ_HEAD(__em_tx_buffer_free, em_tx_buffer)  free_tx_buffer_list;
216	STAILQ_HEAD(__em_tx_buffer_used, em_tx_buffer)  used_tx_buffer_list;
217
218	/* Receive definitions */
219	struct em_rx_desc *first_rx_desc;
220	struct em_rx_desc *last_rx_desc;
221	struct em_rx_desc *next_rx_desc_to_check;
222	struct em_rx_desc *rx_desc_base;
223	u_int16_t       num_rx_desc;
224	u_int32_t       rx_buffer_len;
225	struct em_rx_buffer   *rx_buffer_area;
226	STAILQ_HEAD(__em_rx_buffer, em_rx_buffer)  rx_buffer_list;
227
228	/* Jumbo frame */
229	struct mbuf     *fmp;
230	struct mbuf     *lmp;
231
232
233	/* Misc stats maintained by the driver */
234	unsigned long   dropped_pkts;
235	unsigned long   mbuf_alloc_failed;
236	unsigned long   mbuf_cluster_failed;
237	unsigned long   xmit_pullup;
238	unsigned long   no_tx_desc_avail;
239	unsigned long   no_tx_buffer_avail1;
240	unsigned long   no_tx_buffer_avail2;
241#ifdef DBG_STATS
242	unsigned long   no_pkts_avail;
243	unsigned long   clean_tx_interrupts;
244
245#endif
246
247	struct em_hw_stats stats;
248};
249
250#endif                                                  /* _EM_H_DEFINED_ */
251