1 | /* $NetBSD: i82586var.h,v 1.15 2001/01/22 22:28:45 bjh21 Exp $ */ |
---|
2 | |
---|
3 | /*- |
---|
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. |
---|
5 | * All rights reserved. |
---|
6 | * |
---|
7 | * This code is derived from software contributed to The NetBSD Foundation |
---|
8 | * by Paul Kranenburg and Charles M. Hannum. |
---|
9 | * |
---|
10 | * Redistribution and use in source and binary forms, with or without |
---|
11 | * modification, are permitted provided that the following conditions |
---|
12 | * are met: |
---|
13 | * 1. Redistributions of source code must retain the above copyright |
---|
14 | * notice, this list of conditions and the following disclaimer. |
---|
15 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer in the |
---|
17 | * documentation and/or other materials provided with the distribution. |
---|
18 | * 3. All advertising materials mentioning features or use of this software |
---|
19 | * must display the following acknowledgement: |
---|
20 | * This product includes software developed by the NetBSD |
---|
21 | * Foundation, Inc. and its contributors. |
---|
22 | * 4. Neither the name of The NetBSD Foundation nor the names of its |
---|
23 | * contributors may be used to endorse or promote products derived |
---|
24 | * from this software without specific prior written permission. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
---|
27 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
---|
28 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
---|
29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
---|
30 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
36 | * POSSIBILITY OF SUCH DAMAGE. |
---|
37 | */ |
---|
38 | |
---|
39 | /*- |
---|
40 | * Copyright (c) 1992, 1993, University of Vermont and State |
---|
41 | * Agricultural College. |
---|
42 | * Copyright (c) 1992, 1993, Garrett A. Wollman. |
---|
43 | * |
---|
44 | * Portions: |
---|
45 | * Copyright (c) 1994, 1995, Rafal K. Boni |
---|
46 | * Copyright (c) 1990, 1991, William F. Jolitz |
---|
47 | * Copyright (c) 1990, The Regents of the University of California |
---|
48 | * |
---|
49 | * All rights reserved. |
---|
50 | * |
---|
51 | * Redistribution and use in source and binary forms, with or without |
---|
52 | * modification, are permitted provided that the following conditions |
---|
53 | * are met: |
---|
54 | * 1. Redistributions of source code must retain the above copyright |
---|
55 | * notice, this list of conditions and the following disclaimer. |
---|
56 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
57 | * notice, this list of conditions and the following disclaimer in the |
---|
58 | * documentation and/or other materials provided with the distribution. |
---|
59 | * 3. All advertising materials mentioning features or use of this software |
---|
60 | * must display the following acknowledgement: |
---|
61 | * This product includes software developed by the University of Vermont |
---|
62 | * and State Agricultural College and Garrett A. Wollman, by William F. |
---|
63 | * Jolitz, and by the University of California, Berkeley, Lawrence |
---|
64 | * Berkeley Laboratory, and its contributors. |
---|
65 | * 4. Neither the names of the Universities nor the names of the authors |
---|
66 | * may be used to endorse or promote products derived from this software |
---|
67 | * without specific prior written permission. |
---|
68 | * |
---|
69 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
70 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
71 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
72 | * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHORS BE LIABLE |
---|
73 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
74 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
75 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
76 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
77 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
78 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
79 | * SUCH DAMAGE. |
---|
80 | */ |
---|
81 | |
---|
82 | /* |
---|
83 | * Intel 82586 Ethernet chip |
---|
84 | * Register, bit, and structure definitions. |
---|
85 | * |
---|
86 | * Original StarLAN driver written by Garrett Wollman with reference to the |
---|
87 | * Clarkson Packet Driver code for this chip written by Russ Nelson and others. |
---|
88 | * |
---|
89 | * BPF support code taken from hpdev/if_le.c, supplied with tcpdump. |
---|
90 | * |
---|
91 | * 3C507 support is loosely based on code donated to NetBSD by Rafal Boni. |
---|
92 | * |
---|
93 | * Majorly cleaned up and 3C507 code merged by Charles Hannum. |
---|
94 | * |
---|
95 | * Converted to SUN ie driver by Charles D. Cranor, |
---|
96 | * October 1994, January 1995. |
---|
97 | * This sun version based on i386 version 1.30. |
---|
98 | */ |
---|
99 | |
---|
100 | #ifndef I82586_DEBUG |
---|
101 | #define I82586_DEBUG 0 |
---|
102 | #endif |
---|
103 | |
---|
104 | /* Debug elements */ |
---|
105 | #define IED_RINT 0x01 |
---|
106 | #define IED_TINT 0x02 |
---|
107 | #define IED_RNR 0x04 |
---|
108 | #define IED_CNA 0x08 |
---|
109 | #define IED_READFRAME 0x10 |
---|
110 | #define IED_ENQ 0x20 |
---|
111 | #define IED_XMIT 0x40 |
---|
112 | #define IED_ALL 0x7f |
---|
113 | |
---|
114 | #define B_PER_F 3 /* recv buffers per frame */ |
---|
115 | #define IE_RBUF_SIZE 256 /* size of each receive buffer; |
---|
116 | MUST BE POWER OF TWO */ |
---|
117 | #define NTXBUF 2 /* number of transmit commands */ |
---|
118 | #define IE_TBUF_SIZE ETHER_MAX_LEN /* length of transmit buffer */ |
---|
119 | |
---|
120 | #define IE_MAXMCAST (IE_TBUF_SIZE/6)/* must fit in transmit buffer */ |
---|
121 | |
---|
122 | |
---|
123 | #define INTR_ENTER 0 /* intr hook called on ISR entry */ |
---|
124 | #define INTR_EXIT 1 /* intr hook called on ISR exit */ |
---|
125 | #define INTR_LOOP 2 /* intr hook called on ISR loop */ |
---|
126 | #define INTR_ACK 3 /* intr hook called on ie_ack */ |
---|
127 | |
---|
128 | #define CHIP_PROBE 0 /* reset called from chip probe */ |
---|
129 | #define CARD_RESET 1 /* reset called from card reset */ |
---|
130 | |
---|
131 | #if I82586_DEBUG |
---|
132 | #define I82586_INTS_REQ 0 |
---|
133 | #define I82586_INTS_IN 1 |
---|
134 | #define I82586_INTS_LOOPS 2 |
---|
135 | #define I82586_INTS_OUT 3 |
---|
136 | #define I82586_RX_INT 4 |
---|
137 | #define I82586_RX_DROP 5 |
---|
138 | #define I82586_RX_ERR 6 |
---|
139 | #define I82586_RX_OK 7 |
---|
140 | #define I82586_RX_START 8 |
---|
141 | #define I82586_START_TX 9 |
---|
142 | #define I82586_TX_START 10 |
---|
143 | #define I82586_TX_INT 11 |
---|
144 | #define I82586_TX_REQ 12 |
---|
145 | #define I82586_TX_EVT 13 |
---|
146 | #define I82586_TX_EMIT 14 |
---|
147 | #define I82586_TX_BAD 15 |
---|
148 | #define I82586_TX_ACTIVE 16 |
---|
149 | #define I82586_TRACE_CNT 17 |
---|
150 | |
---|
151 | #define I82586_TRACE_FLOW (10000) |
---|
152 | #endif |
---|
153 | |
---|
154 | /* |
---|
155 | * Ethernet status, per interface. |
---|
156 | * |
---|
157 | * The chip uses two types of pointers: 16 bit and 24 bit |
---|
158 | * 24 bit pointers cover the board's memory. |
---|
159 | * 16 bit pointers are offsets from the ISCP's `ie_base' |
---|
160 | * |
---|
161 | * The board's memory is represented by the bus handle `bh'. The MI |
---|
162 | * i82586 driver deals exclusively with offsets relative to the |
---|
163 | * board memory bus handle. The `ie_softc' fields below that are marked |
---|
164 | * `MD' are in the domain of the front-end driver; they opaque to the |
---|
165 | * MI driver part. |
---|
166 | * |
---|
167 | * The front-end is required to manage the SCP and ISCP structures. i.e. |
---|
168 | * allocate room for them on the board's memory, and arrange to point the |
---|
169 | * chip at the SCB stucture, the offset of which is passed to the MI |
---|
170 | * driver in `sc_scb'. |
---|
171 | * |
---|
172 | * The following functions provide the glue necessary to deal with |
---|
173 | * host and bus idiosyncracies: |
---|
174 | * |
---|
175 | * hwreset - board reset |
---|
176 | * hwinit - board initialization |
---|
177 | * chan_attn - get chip to look at prepared commands |
---|
178 | * intrhook - board dependent interrupt processing |
---|
179 | * |
---|
180 | * All of the following shared-memory access function use an offset |
---|
181 | * relative to the bus handle to indicate the shared memory location. |
---|
182 | * The bus_{read/write}N function take or return offset into the |
---|
183 | * shared memory in the host's byte-order. |
---|
184 | * |
---|
185 | * memcopyin - copy device memory: board to KVA |
---|
186 | * memcopyout - copy device memory: KVA to board |
---|
187 | * bus_read16 - read a 16-bit i82586 pointer |
---|
188 | `offset' argument will be 16-bit aligned |
---|
189 | * bus_write16 - write a 16-bit i82586 pointer |
---|
190 | `offset' argument will be 16-bit aligned |
---|
191 | * bus_write24 - write a 24-bit i82586 pointer |
---|
192 | `offset' argument will be 32-bit aligned |
---|
193 | * bus_barrier - perform a bus barrier operation, forcing |
---|
194 | all outstanding reads/writes to complete |
---|
195 | * |
---|
196 | */ |
---|
197 | |
---|
198 | struct ie_softc { |
---|
199 | struct arpcom arpcom; |
---|
200 | |
---|
201 | /* |
---|
202 | * For RTEMS we run the tx and rx handlers under a task due to the |
---|
203 | * network semaphore stuff. |
---|
204 | */ |
---|
205 | |
---|
206 | rtems_id intr_task; |
---|
207 | rtems_id tx_task; |
---|
208 | |
---|
209 | void *sc_iobase; /* (MD) KVA of base of 24 bit addr space */ |
---|
210 | void *sc_maddr; /* (MD) KVA of base of chip's RAM |
---|
211 | (16bit addr space) */ |
---|
212 | u_int sc_msize; /* (MD) how much RAM we have/use */ |
---|
213 | |
---|
214 | /* Bus glue */ |
---|
215 | void (*hwreset) (struct ie_softc *, int); |
---|
216 | void (*hwinit) (struct ie_softc *); |
---|
217 | void (*chan_attn) (struct ie_softc *, int); |
---|
218 | int (*intrhook) (struct ie_softc *, int where); |
---|
219 | |
---|
220 | void (*memcopyin) (struct ie_softc *, void *, int, size_t); |
---|
221 | void (*memcopyout) (struct ie_softc *, const void *, |
---|
222 | int, size_t); |
---|
223 | u_int16_t (*ie_bus_read16) (struct ie_softc *, int offset); |
---|
224 | void (*ie_bus_write16) (struct ie_softc *, int offset, |
---|
225 | u_int16_t value); |
---|
226 | void (*ie_bus_write24) (struct ie_softc *, int offset, |
---|
227 | int addr); |
---|
228 | void (*ie_bus_barrier) (struct ie_softc *, int offset, |
---|
229 | int length, int flags); |
---|
230 | |
---|
231 | /* Media management */ |
---|
232 | int (*sc_mediachange) (struct ie_softc *); |
---|
233 | /* card dependent media change */ |
---|
234 | void (*sc_mediastatus) (struct ie_softc *, struct ifmediareq *); |
---|
235 | /* card dependent media status */ |
---|
236 | |
---|
237 | /* |
---|
238 | * Offsets (relative to bus handle) of the i82586 SYSTEM structures. |
---|
239 | */ |
---|
240 | int scp; /* Offset to the SCP (set by front-end) */ |
---|
241 | int iscp; /* Offset to the ISCP (set by front-end) */ |
---|
242 | int scb; /* Offset to SCB (set by front-end) */ |
---|
243 | |
---|
244 | /* |
---|
245 | * Offset and size of a block of board memory where the buffers |
---|
246 | * are to be allocated from (initialized by front-end). |
---|
247 | */ |
---|
248 | int buf_area; /* Start of descriptors and buffers */ |
---|
249 | int buf_area_sz; /* Size of above */ |
---|
250 | |
---|
251 | /* |
---|
252 | * The buffers & descriptors (recv and xmit) |
---|
253 | */ |
---|
254 | int rframes; /* Offset to `nrxbuf' frame descriptors */ |
---|
255 | int rbds; /* Offset to `nrxbuf' buffer descriptors */ |
---|
256 | int rbufs; /* Offset to `nrxbuf' receive buffers */ |
---|
257 | #define IE_RBUF_ADDR(sc, i) (sc->rbufs + ((i) * IE_RBUF_SIZE)) |
---|
258 | int rfhead, rftail; |
---|
259 | int rbhead, rbtail; |
---|
260 | int nframes; /* number of frames in use */ |
---|
261 | int nrxbuf; /* number of recv buffs in use */ |
---|
262 | int rnr_expect; /* XXX - expect a RCVR not ready interrupt */ |
---|
263 | |
---|
264 | int nop_cmds; /* Offset to NTXBUF no-op commands */ |
---|
265 | int xmit_cmds; /* Offset to NTXBUF transmit commands */ |
---|
266 | int xbds; /* Offset to NTXBUF buffer descriptors */ |
---|
267 | int xbufs; /* Offset to NTXBUF transmit buffers */ |
---|
268 | #define IE_XBUF_ADDR(sc, i) (sc->xbufs + ((i) * IE_TBUF_SIZE)) |
---|
269 | |
---|
270 | int xchead, xctail; |
---|
271 | int xmit_busy; |
---|
272 | int do_xmitnopchain; /* Controls use of xmit NOP chains */ |
---|
273 | int xmit_req; |
---|
274 | |
---|
275 | /* Multicast addresses */ |
---|
276 | char *mcast_addrs; /* Current MC filter addresses */ |
---|
277 | int mcast_addrs_size; /* Current size of MC buffer */ |
---|
278 | int mcast_count; /* Current # of addrs in buffer */ |
---|
279 | int want_mcsetup; /* run mcsetup at next opportunity */ |
---|
280 | |
---|
281 | int promisc; /* are we in promisc mode? */ |
---|
282 | int async_cmd_inprogress; /* we didn't wait for 586 to accept |
---|
283 | a command */ |
---|
284 | |
---|
285 | #if I82586_DEBUG |
---|
286 | #define I82586_TRACE(s, e, d) \ |
---|
287 | do { rtems_interrupt_level level; rtems_interrupt_disable (level); \ |
---|
288 | (s)->trace_flow[(s)->trace_flow_in++] = (e); \ |
---|
289 | (s)->trace_flow[(s)->trace_flow_in++] = (unsigned int)(d); \ |
---|
290 | if ((s)->trace_flow_in >= I82586_TRACE_FLOW) { \ |
---|
291 | (s)->trace_flow_in = 0; \ |
---|
292 | (s)->trace_flow_wrap = 1; \ |
---|
293 | } \ |
---|
294 | rtems_interrupt_enable (level); \ |
---|
295 | } while (0) |
---|
296 | |
---|
297 | int sc_debug; |
---|
298 | unsigned int trace_flow[I82586_TRACE_FLOW * 2]; |
---|
299 | unsigned int trace_flow_wrap; |
---|
300 | #endif |
---|
301 | unsigned int trace_flow_in; |
---|
302 | }; |
---|
303 | |
---|
304 | /* Exported functions */ |
---|
305 | rtems_isr i82586_intr (rtems_vector_number , void *); |
---|
306 | int i82586_proberam (struct ie_softc *); |
---|
307 | int i82586_attach (struct rtems_bsdnet_ifconfig *config, int attaching); |
---|
308 | |
---|
309 | /* Shortcut macros to optional (driver uses default if unspecified) callbacks */ |
---|
310 | #define xIE_BUS_BARRIER(sc, offset, length, flags) \ |
---|
311 | do { \ |
---|
312 | if ((sc)->ie_bus_barrier) \ |
---|
313 | ((sc)->ie_bus_barrier)((sc), (offset), (length), (flags));\ |
---|
314 | else \ |
---|
315 | bus_space_barrier((sc)->bt, (sc)->bh, (offset), (length), \ |
---|
316 | (flags)); \ |
---|
317 | } while (0) |
---|
318 | |
---|
319 | #define IE_BUS_BARRIER(sc, offset, length, flags) |
---|