i82586.c revision 1.5 1 1.5 pk /* $NetBSD: i82586.c,v 1.5 1997/07/29 20:24:47 pk Exp $ */
2 1.1 pk
3 1.1 pk /*-
4 1.1 pk * Copyright (c) 1997 Paul Kranenburg.
5 1.1 pk * Copyright (c) 1993, 1994, 1995 Charles Hannum.
6 1.1 pk * Copyright (c) 1992, 1993, University of Vermont and State
7 1.1 pk * Agricultural College.
8 1.1 pk * Copyright (c) 1992, 1993, Garrett A. Wollman.
9 1.1 pk *
10 1.1 pk * Portions:
11 1.1 pk * Copyright (c) 1994, 1995, Rafal K. Boni
12 1.1 pk * Copyright (c) 1990, 1991, William F. Jolitz
13 1.1 pk * Copyright (c) 1990, The Regents of the University of California
14 1.1 pk *
15 1.1 pk * All rights reserved.
16 1.1 pk *
17 1.1 pk * Redistribution and use in source and binary forms, with or without
18 1.1 pk * modification, are permitted provided that the following conditions
19 1.1 pk * are met:
20 1.1 pk * 1. Redistributions of source code must retain the above copyright
21 1.1 pk * notice, this list of conditions and the following disclaimer.
22 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
23 1.1 pk * notice, this list of conditions and the following disclaimer in the
24 1.1 pk * documentation and/or other materials provided with the distribution.
25 1.1 pk * 3. All advertising materials mentioning features or use of this software
26 1.1 pk * must display the following acknowledgement:
27 1.1 pk * This product includes software developed by Charles Hannum, by the
28 1.1 pk * University of Vermont and State Agricultural College and Garrett A.
29 1.1 pk * Wollman, by William F. Jolitz, and by the University of California,
30 1.1 pk * Berkeley, Lawrence Berkeley Laboratory, and its contributors.
31 1.1 pk * 4. Neither the names of the Universities nor the names of the authors
32 1.1 pk * may be used to endorse or promote products derived from this software
33 1.1 pk * without specific prior written permission.
34 1.1 pk *
35 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
36 1.1 pk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 1.1 pk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 1.1 pk * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHORS BE LIABLE
39 1.1 pk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 1.1 pk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 1.1 pk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 1.1 pk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 1.1 pk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 1.1 pk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 1.1 pk * SUCH DAMAGE.
46 1.1 pk */
47 1.1 pk
48 1.1 pk /*
49 1.1 pk * Intel 82586 Ethernet chip
50 1.1 pk * Register, bit, and structure definitions.
51 1.1 pk *
52 1.1 pk * Original StarLAN driver written by Garrett Wollman with reference to the
53 1.1 pk * Clarkson Packet Driver code for this chip written by Russ Nelson and others.
54 1.1 pk *
55 1.1 pk * BPF support code taken from hpdev/if_le.c, supplied with tcpdump.
56 1.1 pk *
57 1.1 pk * 3C507 support is loosely based on code donated to NetBSD by Rafal Boni.
58 1.1 pk *
59 1.1 pk * Majorly cleaned up and 3C507 code merged by Charles Hannum.
60 1.1 pk *
61 1.1 pk * Converted to SUN ie driver by Charles D. Cranor,
62 1.1 pk * October 1994, January 1995.
63 1.1 pk * This sun version based on i386 version 1.30.
64 1.1 pk */
65 1.1 pk
66 1.1 pk /*
67 1.1 pk * The i82586 is a very painful chip, found in sun3's, sun-4/100's
68 1.1 pk * sun-4/200's, and VME based suns. The byte order is all wrong for a
69 1.1 pk * SUN, making life difficult. Programming this chip is mostly the same,
70 1.1 pk * but certain details differ from system to system. This driver is
71 1.1 pk * written so that different "ie" interfaces can be controled by the same
72 1.1 pk * driver.
73 1.1 pk */
74 1.1 pk
75 1.1 pk /*
76 1.1 pk Mode of operation:
77 1.1 pk
78 1.1 pk We run the 82586 in a standard Ethernet mode. We keep NFRAMES
79 1.1 pk received frame descriptors around for the receiver to use, and
80 1.1 pk NRXBUF associated receive buffer descriptors, both in a circular
81 1.1 pk list. Whenever a frame is received, we rotate both lists as
82 1.1 pk necessary. (The 586 treats both lists as a simple queue.) We also
83 1.1 pk keep a transmit command around so that packets can be sent off
84 1.1 pk quickly.
85 1.1 pk
86 1.1 pk We configure the adapter in AL-LOC = 1 mode, which means that the
87 1.1 pk Ethernet/802.3 MAC header is placed at the beginning of the receive
88 1.1 pk buffer rather than being split off into various fields in the RFD.
89 1.1 pk This also means that we must include this header in the transmit
90 1.1 pk buffer as well.
91 1.1 pk
92 1.1 pk By convention, all transmit commands, and only transmit commands,
93 1.1 pk shall have the I (IE_CMD_INTR) bit set in the command. This way,
94 1.1 pk when an interrupt arrives at ieintr(), it is immediately possible
95 1.1 pk to tell what precisely caused it. ANY OTHER command-sending
96 1.1 pk routines should run at splnet(), and should post an acknowledgement
97 1.1 pk to every interrupt they generate.
98 1.1 pk
99 1.1 pk */
100 1.1 pk
101 1.1 pk #include "bpfilter.h"
102 1.1 pk
103 1.1 pk #include <sys/param.h>
104 1.1 pk #include <sys/systm.h>
105 1.1 pk #include <sys/mbuf.h>
106 1.1 pk #include <sys/buf.h>
107 1.1 pk #include <sys/protosw.h>
108 1.1 pk #include <sys/socket.h>
109 1.1 pk #include <sys/ioctl.h>
110 1.1 pk #include <sys/errno.h>
111 1.1 pk #include <sys/syslog.h>
112 1.1 pk #include <sys/device.h>
113 1.1 pk
114 1.1 pk #include <net/if.h>
115 1.1 pk #include <net/if_types.h>
116 1.1 pk #include <net/if_dl.h>
117 1.1 pk #include <net/if_ether.h>
118 1.1 pk
119 1.1 pk #if NBPFILTER > 0
120 1.1 pk #include <net/bpf.h>
121 1.1 pk #include <net/bpfdesc.h>
122 1.1 pk #endif
123 1.1 pk
124 1.1 pk #ifdef INET
125 1.1 pk #include <netinet/in.h>
126 1.1 pk #include <netinet/in_systm.h>
127 1.1 pk #include <netinet/in_var.h>
128 1.1 pk #include <netinet/ip.h>
129 1.1 pk #include <netinet/if_inarp.h>
130 1.1 pk #endif
131 1.1 pk
132 1.1 pk #ifdef NS
133 1.1 pk #include <netns/ns.h>
134 1.1 pk #include <netns/ns_if.h>
135 1.1 pk #endif
136 1.1 pk
137 1.5 pk #include <machine/bus.h>
138 1.5 pk
139 1.1 pk #include <dev/ic/i82586reg.h>
140 1.1 pk #include <dev/ic/i82586var.h>
141 1.1 pk
142 1.1 pk void iewatchdog __P((struct ifnet *));
143 1.1 pk int ieinit __P((struct ie_softc *));
144 1.1 pk int ieioctl __P((struct ifnet *, u_long, caddr_t));
145 1.1 pk void iestart __P((struct ifnet *));
146 1.1 pk void iereset __P((struct ie_softc *));
147 1.1 pk static void ie_readframe __P((struct ie_softc *, int));
148 1.1 pk static void ie_drop_packet_buffer __P((struct ie_softc *));
149 1.1 pk int ie_setupram __P((struct ie_softc *));
150 1.1 pk static int command_and_wait __P((struct ie_softc *, int,
151 1.1 pk void volatile *, int));
152 1.1 pk /*static*/ void ierint __P((struct ie_softc *));
153 1.1 pk /*static*/ void ietint __P((struct ie_softc *));
154 1.3 pk static struct mbuf *ieget __P((struct ie_softc *,
155 1.1 pk struct ether_header *, int *));
156 1.1 pk static void setup_bufs __P((struct ie_softc *));
157 1.1 pk static int mc_setup __P((struct ie_softc *, void *));
158 1.1 pk static void mc_reset __P((struct ie_softc *));
159 1.1 pk static __inline int ether_equal __P((u_char *, u_char *));
160 1.1 pk static __inline void ie_ack __P((struct ie_softc *, u_int));
161 1.1 pk static __inline void ie_setup_config __P((volatile struct ie_config_cmd *,
162 1.1 pk int, int));
163 1.1 pk static __inline int check_eh __P((struct ie_softc *, struct ether_header *,
164 1.1 pk int *));
165 1.1 pk static __inline int ie_buflen __P((struct ie_softc *, int));
166 1.1 pk static __inline int ie_packet_len __P((struct ie_softc *));
167 1.1 pk static __inline void iexmit __P((struct ie_softc *));
168 1.1 pk
169 1.1 pk static void run_tdr __P((struct ie_softc *, struct ie_tdr_cmd *));
170 1.1 pk static void iestop __P((struct ie_softc *));
171 1.1 pk
172 1.1 pk #ifdef IEDEBUG
173 1.1 pk void print_rbd __P((volatile struct ie_recv_buf_desc *));
174 1.1 pk
175 1.1 pk int in_ierint = 0;
176 1.1 pk int in_ietint = 0;
177 1.1 pk #endif
178 1.1 pk
179 1.1 pk struct cfdriver ie_cd = {
180 1.1 pk NULL, "ie", DV_IFNET
181 1.1 pk };
182 1.1 pk
183 1.1 pk /*
184 1.1 pk * Address generation macros:
185 1.1 pk * MK_24 = KVA -> 24 bit address in native byte order
186 1.1 pk * MK_16 = KVA -> 16 bit address in INTEL byte order
187 1.1 pk * ST_24 = store a 24 bit address in native byte order to INTEL byte order
188 1.1 pk */
189 1.1 pk #define MK_24(base, ptr) ((caddr_t)((u_long)ptr - (u_long)base))
190 1.1 pk
191 1.1 pk #if BYTE_ORDER == BIG_ENDIAN
192 1.1 pk #define XSWAP(y) ( ((y) >> 8) | ((y) << 8) )
193 1.1 pk #define SWAP(x) ({u_short _z=(x); (u_short)XSWAP(_z);})
194 1.1 pk
195 1.1 pk #define MK_16(base, ptr) SWAP((u_short)( ((u_long)(ptr)) - ((u_long)(base)) ))
196 1.1 pk #define ST_24(to, from) { \
197 1.1 pk u_long fval = (u_long)(from); \
198 1.1 pk u_char *t = (u_char *)&(to), *f = (u_char *)&fval; \
199 1.1 pk t[0] = f[3]; t[1] = f[2]; t[2] = f[1]; /*t[3] = f[0] ;*/ \
200 1.1 pk }
201 1.1 pk #else
202 1.1 pk #define SWAP(x) x
203 1.1 pk #define MK_16(base, ptr) ((u_short)(u_long)MK_24(base, ptr))
204 1.1 pk #define ST_24(to, from) {to = (from);}
205 1.1 pk #endif
206 1.1 pk
207 1.1 pk /*
208 1.1 pk * Here are a few useful functions. We could have done these as macros, but
209 1.1 pk * since we have the inline facility, it makes sense to use that instead.
210 1.1 pk */
211 1.1 pk static __inline void
212 1.1 pk ie_setup_config(cmd, promiscuous, manchester)
213 1.1 pk volatile struct ie_config_cmd *cmd;
214 1.1 pk int promiscuous, manchester;
215 1.1 pk {
216 1.1 pk
217 1.1 pk cmd->ie_config_count = 0x0c;
218 1.1 pk cmd->ie_fifo = 8;
219 1.1 pk cmd->ie_save_bad = 0x40;
220 1.1 pk cmd->ie_addr_len = 0x2e;
221 1.1 pk cmd->ie_priority = 0;
222 1.1 pk cmd->ie_ifs = 0x60;
223 1.1 pk cmd->ie_slot_low = 0;
224 1.1 pk cmd->ie_slot_high = 0xf2;
225 1.1 pk cmd->ie_promisc = !!promiscuous | manchester << 2;
226 1.1 pk cmd->ie_crs_cdt = 0;
227 1.1 pk cmd->ie_min_len = 64;
228 1.1 pk cmd->ie_junk = 0xff;
229 1.1 pk }
230 1.1 pk
231 1.1 pk static __inline void
232 1.1 pk ie_ack(sc, mask)
233 1.1 pk struct ie_softc *sc;
234 1.1 pk u_int mask; /* in native byte-order */
235 1.1 pk {
236 1.1 pk volatile struct ie_sys_ctl_block *scb = sc->scb;
237 1.1 pk
238 1.1 pk command_and_wait(sc, SWAP(scb->ie_status) & mask, 0, 0);
239 1.1 pk }
240 1.1 pk
241 1.1 pk
242 1.1 pk /*
243 1.1 pk * Taken almost exactly from Bill's if_is.c, then modified beyond recognition.
244 1.1 pk */
245 1.1 pk void
246 1.1 pk ie_attach(sc, name, etheraddr)
247 1.1 pk struct ie_softc *sc;
248 1.1 pk char *name;
249 1.1 pk u_int8_t *etheraddr;
250 1.1 pk {
251 1.1 pk struct ifnet *ifp = &sc->sc_ethercom.ec_if;
252 1.1 pk
253 1.1 pk if (ie_setupram(sc) == 0) { /* XXX - ISA version? */
254 1.1 pk printf(": RAM CONFIG FAILED!\n");
255 1.1 pk /* XXX should reclaim resources? */
256 1.1 pk return;
257 1.1 pk }
258 1.1 pk
259 1.1 pk bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
260 1.1 pk ifp->if_softc = sc;
261 1.1 pk ifp->if_start = iestart;
262 1.1 pk ifp->if_ioctl = ieioctl;
263 1.1 pk ifp->if_watchdog = iewatchdog;
264 1.1 pk ifp->if_flags =
265 1.1 pk IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
266 1.1 pk
267 1.1 pk /* Attach the interface. */
268 1.1 pk if_attach(ifp);
269 1.1 pk ether_ifattach(ifp, etheraddr);
270 1.1 pk
271 1.1 pk printf(" address %s, type %s\n", ether_sprintf(etheraddr), name);
272 1.1 pk
273 1.1 pk #if NBPFILTER > 0
274 1.1 pk bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
275 1.1 pk #endif
276 1.1 pk }
277 1.1 pk
278 1.1 pk
279 1.1 pk /*
280 1.1 pk * Device timeout/watchdog routine. Entered if the device neglects to generate
281 1.1 pk * an interrupt after a transmit has been started on it.
282 1.1 pk */
283 1.1 pk void
284 1.1 pk iewatchdog(ifp)
285 1.1 pk struct ifnet *ifp;
286 1.1 pk {
287 1.1 pk struct ie_softc *sc = ifp->if_softc;
288 1.1 pk
289 1.1 pk log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
290 1.1 pk ++ifp->if_oerrors;
291 1.1 pk
292 1.1 pk iereset(sc);
293 1.1 pk }
294 1.1 pk
295 1.1 pk /*
296 1.1 pk * What to do upon receipt of an interrupt.
297 1.1 pk */
298 1.1 pk int
299 1.1 pk ieintr(v)
300 1.1 pk void *v;
301 1.1 pk {
302 1.1 pk struct ie_softc *sc = v;
303 1.1 pk register u_short status;
304 1.1 pk
305 1.5 pk bus_space_barrier(sc->bt, sc->bh, 0, 0, BUS_SPACE_BARRIER_READ);
306 1.1 pk status = SWAP(sc->scb->ie_status);
307 1.1 pk
308 1.1 pk /*
309 1.1 pk * Implementation dependent interrupt handling.
310 1.1 pk */
311 1.1 pk if (sc->intrhook)
312 1.1 pk (*sc->intrhook)(sc);
313 1.1 pk
314 1.1 pk loop:
315 1.1 pk /* Ack interrupts FIRST in case we receive more during the ISR. */
316 1.1 pk ie_ack(sc, IE_ST_WHENCE & status);
317 1.1 pk
318 1.1 pk if (status & (IE_ST_FR | IE_ST_RNR)) {
319 1.1 pk #ifdef IEDEBUG
320 1.1 pk in_ierint++;
321 1.1 pk if (sc->sc_debug & IED_RINT)
322 1.1 pk printf("%s: rint\n", sc->sc_dev.dv_xname);
323 1.1 pk #endif
324 1.1 pk ierint(sc);
325 1.1 pk #ifdef IEDEBUG
326 1.1 pk in_ierint--;
327 1.1 pk #endif
328 1.1 pk }
329 1.1 pk
330 1.1 pk if (status & IE_ST_CX) {
331 1.1 pk #ifdef IEDEBUG
332 1.1 pk in_ietint++;
333 1.1 pk if (sc->sc_debug & IED_TINT)
334 1.1 pk printf("%s: tint\n", sc->sc_dev.dv_xname);
335 1.1 pk #endif
336 1.1 pk ietint(sc);
337 1.1 pk #ifdef IEDEBUG
338 1.1 pk in_ietint--;
339 1.1 pk #endif
340 1.1 pk }
341 1.1 pk
342 1.1 pk if (status & IE_ST_RNR) {
343 1.1 pk printf("%s: receiver not ready\n", sc->sc_dev.dv_xname);
344 1.1 pk sc->sc_ethercom.ec_if.if_ierrors++;
345 1.1 pk iereset(sc);
346 1.1 pk return (1);
347 1.1 pk }
348 1.1 pk
349 1.1 pk #ifdef IEDEBUG
350 1.1 pk if ((status & IE_ST_CNA) && (sc->sc_debug & IED_CNA))
351 1.1 pk printf("%s: cna\n", sc->sc_dev.dv_xname);
352 1.1 pk #endif
353 1.1 pk
354 1.5 pk bus_space_barrier(sc->bt, sc->bh, 0, 0, BUS_SPACE_BARRIER_READ);
355 1.1 pk status = SWAP(sc->scb->ie_status);
356 1.1 pk if (status & IE_ST_WHENCE)
357 1.1 pk goto loop;
358 1.1 pk
359 1.1 pk return (1);
360 1.1 pk }
361 1.1 pk
362 1.1 pk /*
363 1.1 pk * Process a received-frame interrupt.
364 1.1 pk */
365 1.1 pk void
366 1.1 pk ierint(sc)
367 1.1 pk struct ie_softc *sc;
368 1.1 pk {
369 1.1 pk volatile struct ie_sys_ctl_block *scb = sc->scb;
370 1.1 pk int i, status;
371 1.1 pk static int timesthru = 1024;
372 1.1 pk
373 1.1 pk i = sc->rfhead;
374 1.1 pk for (;;) {
375 1.1 pk status = SWAP(sc->rframes[i]->ie_fd_status);
376 1.1 pk
377 1.1 pk if ((status & IE_FD_COMPLETE) && (status & IE_FD_OK)) {
378 1.3 pk if (--timesthru == 0) {
379 1.1 pk sc->sc_ethercom.ec_if.if_ierrors +=
380 1.1 pk SWAP(scb->ie_err_crc) +
381 1.1 pk SWAP(scb->ie_err_align) +
382 1.1 pk SWAP(scb->ie_err_resource) +
383 1.1 pk SWAP(scb->ie_err_overrun);
384 1.1 pk scb->ie_err_crc = scb->ie_err_align =
385 1.1 pk scb->ie_err_resource = scb->ie_err_overrun =
386 1.1 pk SWAP(0);
387 1.1 pk timesthru = 1024;
388 1.1 pk }
389 1.1 pk ie_readframe(sc, i);
390 1.1 pk } else {
391 1.1 pk if ((status & IE_FD_RNR) != 0 &&
392 1.1 pk (SWAP(scb->ie_status) & IE_RU_READY) == 0) {
393 1.1 pk sc->rframes[0]->ie_fd_buf_desc =
394 1.1 pk MK_16(sc->sc_maddr, sc->rbuffs[0]);
395 1.1 pk scb->ie_recv_list =
396 1.1 pk MK_16(sc->sc_maddr, sc->rframes[0]);
397 1.1 pk command_and_wait(sc, IE_RU_START, 0, 0);
398 1.1 pk }
399 1.1 pk break;
400 1.1 pk }
401 1.1 pk i = (i + 1) % sc->nframes;
402 1.1 pk }
403 1.1 pk }
404 1.1 pk
405 1.1 pk /*
406 1.1 pk * Process a command-complete interrupt. These are only generated by the
407 1.1 pk * transmission of frames. This routine is deceptively simple, since most of
408 1.1 pk * the real work is done by iestart().
409 1.1 pk */
410 1.1 pk void
411 1.1 pk ietint(sc)
412 1.1 pk struct ie_softc *sc;
413 1.1 pk {
414 1.5 pk struct ifnet *ifp = &sc->sc_ethercom.ec_if;
415 1.1 pk int status;
416 1.1 pk
417 1.5 pk ifp->if_timer = 0;
418 1.5 pk ifp->if_flags &= ~IFF_OACTIVE;
419 1.1 pk
420 1.1 pk status = SWAP(sc->xmit_cmds[sc->xctail]->ie_xmit_status);
421 1.1 pk
422 1.3 pk if ((status & IE_STAT_COMPL) == 0 || (status & IE_STAT_BUSY))
423 1.1 pk printf("ietint: command still busy!\n");
424 1.1 pk
425 1.1 pk if (status & IE_STAT_OK) {
426 1.5 pk ifp->if_opackets++;
427 1.5 pk ifp->if_collisions += (status & IE_XS_MAXCOLL);
428 1.5 pk } else {
429 1.5 pk ifp->if_oerrors++;
430 1.5 pk /*
431 1.5 pk * Check SQE and DEFERRED?
432 1.5 pk * What if more than one bit is set?
433 1.5 pk */
434 1.5 pk if (status & IE_STAT_ABORT)
435 1.5 pk printf("%s: send aborted\n", sc->sc_dev.dv_xname);
436 1.5 pk else if (status & IE_XS_NOCARRIER)
437 1.5 pk printf("%s: no carrier\n", sc->sc_dev.dv_xname);
438 1.5 pk else if (status & IE_XS_LOSTCTS)
439 1.5 pk printf("%s: lost CTS\n", sc->sc_dev.dv_xname);
440 1.5 pk else if (status & IE_XS_UNDERRUN)
441 1.5 pk printf("%s: DMA underrun\n", sc->sc_dev.dv_xname);
442 1.5 pk else if (status & IE_XS_EXCMAX) {
443 1.5 pk printf("%s: too many collisions\n",
444 1.5 pk sc->sc_dev.dv_xname);
445 1.5 pk sc->sc_ethercom.ec_if.if_collisions += 16;
446 1.5 pk }
447 1.1 pk }
448 1.1 pk
449 1.1 pk /*
450 1.1 pk * If multicast addresses were added or deleted while transmitting,
451 1.1 pk * mc_reset() set the want_mcsetup flag indicating that we should do
452 1.1 pk * it.
453 1.1 pk */
454 1.1 pk if (sc->want_mcsetup) {
455 1.1 pk mc_setup(sc, (caddr_t)sc->xmit_cbuffs[sc->xctail]);
456 1.1 pk sc->want_mcsetup = 0;
457 1.1 pk }
458 1.1 pk
459 1.1 pk /* Done with the buffer. */
460 1.3 pk sc->xmit_busy--;
461 1.1 pk sc->xctail = (sc->xctail + 1) % NTXBUF;
462 1.1 pk
463 1.3 pk /* Start the next packet, if any, transmitting. */
464 1.3 pk if (sc->xmit_busy > 0)
465 1.3 pk iexmit(sc);
466 1.3 pk
467 1.5 pk iestart(ifp);
468 1.1 pk }
469 1.1 pk
470 1.1 pk /*
471 1.1 pk * Compare two Ether/802 addresses for equality, inlined and unrolled for
472 1.3 pk * speed.
473 1.1 pk */
474 1.1 pk static __inline int
475 1.1 pk ether_equal(one, two)
476 1.1 pk u_char *one, *two;
477 1.1 pk {
478 1.1 pk
479 1.1 pk if (one[5] != two[5] || one[4] != two[4] || one[3] != two[3] ||
480 1.1 pk one[2] != two[2] || one[1] != two[1] || one[0] != two[0])
481 1.1 pk return 0;
482 1.1 pk return 1;
483 1.1 pk }
484 1.1 pk
485 1.1 pk /*
486 1.1 pk * Check for a valid address. to_bpf is filled in with one of the following:
487 1.1 pk * 0 -> BPF doesn't get this packet
488 1.1 pk * 1 -> BPF does get this packet
489 1.1 pk * 2 -> BPF does get this packet, but we don't
490 1.1 pk * Return value is true if the packet is for us, and false otherwise.
491 1.1 pk *
492 1.1 pk * This routine is a mess, but it's also critical that it be as fast
493 1.1 pk * as possible. It could be made cleaner if we can assume that the
494 1.1 pk * only client which will fiddle with IFF_PROMISC is BPF. This is
495 1.1 pk * probably a good assumption, but we do not make it here. (Yet.)
496 1.1 pk */
497 1.1 pk static __inline int
498 1.1 pk check_eh(sc, eh, to_bpf)
499 1.1 pk struct ie_softc *sc;
500 1.1 pk struct ether_header *eh;
501 1.1 pk int *to_bpf;
502 1.1 pk {
503 1.1 pk struct ifnet *ifp;
504 1.1 pk int i;
505 1.1 pk
506 1.1 pk ifp = &sc->sc_ethercom.ec_if;
507 1.1 pk
508 1.1 pk switch(sc->promisc) {
509 1.1 pk case IFF_ALLMULTI:
510 1.1 pk /*
511 1.1 pk * Receiving all multicasts, but no unicasts except those
512 1.1 pk * destined for us.
513 1.1 pk */
514 1.1 pk #if NBPFILTER > 0
515 1.1 pk /* BPF gets this packet if anybody cares */
516 1.3 pk *to_bpf = (ifp->if_bpf != 0);
517 1.1 pk #endif
518 1.1 pk if (eh->ether_dhost[0] & 1)
519 1.1 pk return 1;
520 1.1 pk if (ether_equal(eh->ether_dhost, LLADDR(ifp->if_sadl)))
521 1.1 pk return 1;
522 1.1 pk return 0;
523 1.1 pk
524 1.1 pk case IFF_PROMISC:
525 1.1 pk /*
526 1.1 pk * Receiving all packets. These need to be passed on to BPF.
527 1.1 pk */
528 1.1 pk #if NBPFILTER > 0
529 1.3 pk *to_bpf = (ifp->if_bpf != 0);
530 1.1 pk #endif
531 1.1 pk /* If for us, accept and hand up to BPF */
532 1.1 pk if (ether_equal(eh->ether_dhost, LLADDR(ifp->if_sadl)))
533 1.1 pk return 1;
534 1.1 pk
535 1.1 pk #if NBPFILTER > 0
536 1.1 pk if (*to_bpf)
537 1.1 pk *to_bpf = 2; /* we don't need to see it */
538 1.1 pk #endif
539 1.1 pk
540 1.1 pk /*
541 1.1 pk * Not a multicast, so BPF wants to see it but we don't.
542 1.1 pk */
543 1.3 pk if ((eh->ether_dhost[0] & 1) == 0)
544 1.1 pk return 1;
545 1.1 pk
546 1.1 pk /*
547 1.1 pk * If it's one of our multicast groups, accept it and pass it
548 1.1 pk * up.
549 1.1 pk */
550 1.1 pk for (i = 0; i < sc->mcast_count; i++) {
551 1.1 pk if (ether_equal(eh->ether_dhost,
552 1.1 pk (u_char *)&sc->mcast_addrs[i])) {
553 1.1 pk #if NBPFILTER > 0
554 1.1 pk if (*to_bpf)
555 1.1 pk *to_bpf = 1;
556 1.1 pk #endif
557 1.1 pk return 1;
558 1.1 pk }
559 1.1 pk }
560 1.1 pk return 1;
561 1.1 pk
562 1.1 pk case IFF_ALLMULTI | IFF_PROMISC:
563 1.1 pk /*
564 1.1 pk * Acting as a multicast router, and BPF running at the same
565 1.1 pk * time. Whew! (Hope this is a fast machine...)
566 1.1 pk */
567 1.1 pk #if NBPFILTER > 0
568 1.3 pk *to_bpf = (ifp->if_bpf != 0);
569 1.1 pk #endif
570 1.1 pk /* We want to see multicasts. */
571 1.1 pk if (eh->ether_dhost[0] & 1)
572 1.1 pk return 1;
573 1.1 pk
574 1.1 pk /* We want to see our own packets */
575 1.1 pk if (ether_equal(eh->ether_dhost, LLADDR(ifp->if_sadl)))
576 1.1 pk return 1;
577 1.1 pk
578 1.1 pk /* Anything else goes to BPF but nothing else. */
579 1.1 pk #if NBPFILTER > 0
580 1.1 pk if (*to_bpf)
581 1.1 pk *to_bpf = 2;
582 1.1 pk #endif
583 1.1 pk return 1;
584 1.1 pk
585 1.1 pk default:
586 1.1 pk /*
587 1.1 pk * Only accept unicast packets destined for us, or multicasts
588 1.1 pk * for groups that we belong to. For now, we assume that the
589 1.1 pk * '586 will only return packets that we asked it for. This
590 1.1 pk * isn't strictly true (it uses hashing for the multicast
591 1.1 pk * filter), but it will do in this case, and we want to get
592 1.1 pk * out of here as quickly as possible.
593 1.1 pk */
594 1.1 pk #if NBPFILTER > 0
595 1.3 pk *to_bpf = (ifp->if_bpf != 0);
596 1.1 pk #endif
597 1.1 pk return 1;
598 1.1 pk }
599 1.1 pk return 0;
600 1.1 pk }
601 1.1 pk
602 1.1 pk /*
603 1.1 pk * We want to isolate the bits that have meaning... This assumes that
604 1.1 pk * IE_RBUF_SIZE is an even power of two. If somehow the act_len exceeds
605 1.1 pk * the size of the buffer, then we are screwed anyway.
606 1.1 pk */
607 1.1 pk static __inline int
608 1.1 pk ie_buflen(sc, head)
609 1.1 pk struct ie_softc *sc;
610 1.1 pk int head;
611 1.1 pk {
612 1.1 pk
613 1.1 pk return (SWAP(sc->rbuffs[head]->ie_rbd_actual)
614 1.1 pk & (IE_RBUF_SIZE | (IE_RBUF_SIZE - 1)));
615 1.1 pk }
616 1.1 pk
617 1.3 pk
618 1.1 pk static __inline int
619 1.1 pk ie_packet_len(sc)
620 1.1 pk struct ie_softc *sc;
621 1.1 pk {
622 1.1 pk int i;
623 1.1 pk int head = sc->rbhead;
624 1.1 pk int acc = 0;
625 1.1 pk int oldhead = head;
626 1.1 pk
627 1.1 pk do {
628 1.5 pk bus_space_barrier(sc->bt, sc->bh, 0, 0, BUS_SPACE_BARRIER_READ);
629 1.3 pk i = SWAP(sc->rbuffs[head]->ie_rbd_actual);
630 1.3 pk if ((i & IE_RBD_USED) == 0) {
631 1.1 pk #ifdef IEDEBUG
632 1.3 pk print_rbd(sc->rbuffs[head]);
633 1.1 pk #endif
634 1.1 pk log(LOG_ERR, "%s: receive descriptors out of sync at %d\n",
635 1.1 pk sc->sc_dev.dv_xname, sc->rbhead);
636 1.1 pk iereset(sc);
637 1.1 pk return -1;
638 1.1 pk }
639 1.1 pk
640 1.3 pk i = (i & IE_RBD_LAST) != 0;
641 1.1 pk
642 1.1 pk acc += ie_buflen(sc, head);
643 1.1 pk head = (head + 1) % sc->nrxbuf;
644 1.3 pk if (oldhead == head) {
645 1.1 pk printf("ie: packet len: looping: acc = %d (head=%d)\n",
646 1.1 pk acc, head);
647 1.1 pk iereset(sc);
648 1.1 pk return -1;
649 1.1 pk }
650 1.1 pk } while (!i);
651 1.1 pk
652 1.1 pk return acc;
653 1.1 pk }
654 1.1 pk
655 1.1 pk /*
656 1.1 pk * Setup all necessary artifacts for an XMIT command, and then pass the XMIT
657 1.1 pk * command to the chip to be executed. On the way, if we have a BPF listener
658 1.1 pk * also give him a copy.
659 1.1 pk */
660 1.1 pk static __inline void
661 1.1 pk iexmit(sc)
662 1.1 pk struct ie_softc *sc;
663 1.1 pk {
664 1.1 pk
665 1.3 pk #ifdef IEDEBUG
666 1.3 pk if (sc->sc_debug & IED_XMIT)
667 1.3 pk printf("%s: xmit buffer %d\n", sc->sc_dev.dv_xname,
668 1.3 pk sc->xctail);
669 1.1 pk #endif
670 1.1 pk
671 1.1 pk sc->xmit_buffs[sc->xctail]->ie_xmit_flags |= SWAP(IE_XMIT_LAST);
672 1.1 pk sc->xmit_buffs[sc->xctail]->ie_xmit_next = SWAP(0xffff);
673 1.1 pk ST_24(sc->xmit_buffs[sc->xctail]->ie_xmit_buf,
674 1.1 pk MK_24(sc->sc_iobase, sc->xmit_cbuffs[sc->xctail]));
675 1.1 pk
676 1.1 pk sc->xmit_cmds[sc->xctail]->com.ie_cmd_link = SWAP(0xffff);
677 1.1 pk sc->xmit_cmds[sc->xctail]->com.ie_cmd_cmd =
678 1.1 pk SWAP(IE_CMD_XMIT | IE_CMD_INTR | IE_CMD_LAST);
679 1.1 pk
680 1.1 pk sc->xmit_cmds[sc->xctail]->ie_xmit_status = SWAP(0);
681 1.1 pk sc->xmit_cmds[sc->xctail]->ie_xmit_desc =
682 1.1 pk MK_16(sc->sc_maddr, sc->xmit_buffs[sc->xctail]);
683 1.1 pk
684 1.1 pk sc->scb->ie_command_list =
685 1.1 pk MK_16(sc->sc_maddr, sc->xmit_cmds[sc->xctail]);
686 1.1 pk
687 1.1 pk command_and_wait(sc, IE_CU_START, 0, 0);
688 1.1 pk
689 1.1 pk sc->sc_ethercom.ec_if.if_timer = 5;
690 1.1 pk }
691 1.1 pk
692 1.1 pk /*
693 1.1 pk * Read data off the interface, and turn it into an mbuf chain.
694 1.1 pk *
695 1.1 pk * This code is DRAMATICALLY different from the previous version; this
696 1.1 pk * version tries to allocate the entire mbuf chain up front, given the
697 1.1 pk * length of the data available. This enables us to allocate mbuf
698 1.1 pk * clusters in many situations where before we would have had a long
699 1.1 pk * chain of partially-full mbufs. This should help to speed up the
700 1.1 pk * operation considerably. (Provided that it works, of course.)
701 1.1 pk */
702 1.3 pk struct mbuf *
703 1.3 pk ieget(sc, ehp, to_bpf)
704 1.1 pk struct ie_softc *sc;
705 1.1 pk struct ether_header *ehp;
706 1.1 pk int *to_bpf;
707 1.1 pk {
708 1.3 pk struct mbuf *top, **mp, *m;
709 1.3 pk int len, totlen, resid;
710 1.3 pk int thisrboff, thismboff;
711 1.1 pk int head;
712 1.1 pk
713 1.1 pk totlen = ie_packet_len(sc);
714 1.1 pk if (totlen <= 0)
715 1.3 pk return 0;
716 1.1 pk
717 1.3 pk head = sc->rbhead;
718 1.1 pk
719 1.1 pk /*
720 1.1 pk * Snarf the Ethernet header.
721 1.1 pk */
722 1.5 pk (sc->memcopy)((caddr_t)sc->cbuffs[head], (caddr_t)ehp, sizeof *ehp);
723 1.1 pk
724 1.1 pk /*
725 1.1 pk * As quickly as possible, check if this packet is for us.
726 1.1 pk * If not, don't waste a single cycle copying the rest of the
727 1.1 pk * packet in.
728 1.1 pk * This is only a consideration when FILTER is defined; i.e., when
729 1.1 pk * we are either running BPF or doing multicasting.
730 1.1 pk */
731 1.1 pk if (!check_eh(sc, ehp, to_bpf)) {
732 1.1 pk /* just this case, it's not an error */
733 1.1 pk sc->sc_ethercom.ec_if.if_ierrors--;
734 1.3 pk return 0;
735 1.1 pk }
736 1.1 pk
737 1.3 pk resid = totlen -= (thisrboff = sizeof *ehp);
738 1.1 pk
739 1.3 pk MGETHDR(m, M_DONTWAIT, MT_DATA);
740 1.3 pk if (m == 0)
741 1.3 pk return 0;
742 1.1 pk m->m_pkthdr.rcvif = &sc->sc_ethercom.ec_if;
743 1.3 pk m->m_pkthdr.len = totlen;
744 1.3 pk len = MHLEN;
745 1.1 pk top = 0;
746 1.3 pk mp = ⊤
747 1.1 pk
748 1.1 pk /*
749 1.1 pk * This loop goes through and allocates mbufs for all the data we will
750 1.1 pk * be copying in. It does not actually do the copying yet.
751 1.1 pk */
752 1.3 pk while (totlen > 0) {
753 1.1 pk if (top) {
754 1.1 pk MGET(m, M_DONTWAIT, MT_DATA);
755 1.3 pk if (m == 0) {
756 1.1 pk m_freem(top);
757 1.3 pk return 0;
758 1.1 pk }
759 1.3 pk len = MLEN;
760 1.1 pk }
761 1.3 pk if (totlen >= MINCLSIZE) {
762 1.1 pk MCLGET(m, M_DONTWAIT);
763 1.3 pk if ((m->m_flags & M_EXT) == 0) {
764 1.3 pk m_freem(top);
765 1.3 pk return 0;
766 1.1 pk }
767 1.3 pk len = MCLBYTES;
768 1.1 pk }
769 1.3 pk m->m_len = len = min(totlen, len);
770 1.3 pk totlen -= len;
771 1.3 pk *mp = m;
772 1.3 pk mp = &m->m_next;
773 1.3 pk }
774 1.1 pk
775 1.1 pk m = top;
776 1.1 pk thismboff = 0;
777 1.1 pk
778 1.1 pk /*
779 1.1 pk * Now we take the mbuf chain (hopefully only one mbuf most of the
780 1.3 pk * time) and stuff the data into it. There are no possible failures at
781 1.3 pk * or after this point.
782 1.1 pk */
783 1.3 pk while (resid > 0) {
784 1.3 pk int thisrblen = ie_buflen(sc, head) - thisrboff,
785 1.3 pk thismblen = m->m_len - thismboff;
786 1.3 pk len = min(thisrblen, thismblen);
787 1.3 pk
788 1.5 pk (sc->memcopy)((caddr_t)(sc->cbuffs[head] + thisrboff),
789 1.5 pk mtod(m, caddr_t) + thismboff, (u_int)len);
790 1.3 pk resid -= len;
791 1.1 pk
792 1.3 pk if (len == thismblen) {
793 1.1 pk m = m->m_next;
794 1.3 pk thismboff = 0;
795 1.3 pk } else
796 1.3 pk thismboff += len;
797 1.3 pk
798 1.3 pk if (len == thisrblen) {
799 1.3 pk head = (head + 1) % sc->nrxbuf;
800 1.3 pk thisrboff = 0;
801 1.3 pk } else
802 1.3 pk thisrboff += len;
803 1.1 pk }
804 1.1 pk
805 1.1 pk /*
806 1.1 pk * Unless something changed strangely while we were doing the copy, we
807 1.1 pk * have now copied everything in from the shared memory.
808 1.1 pk * This means that we are done.
809 1.1 pk */
810 1.3 pk return top;
811 1.1 pk }
812 1.1 pk
813 1.1 pk /*
814 1.1 pk * Read frame NUM from unit UNIT (pre-cached as IE).
815 1.1 pk *
816 1.1 pk * This routine reads the RFD at NUM, and copies in the buffers from the list
817 1.1 pk * of RBD, then rotates the RBD and RFD lists so that the receiver doesn't
818 1.1 pk * start complaining. Trailers are DROPPED---there's no point in wasting time
819 1.1 pk * on confusing code to deal with them. Hopefully, this machine will never ARP
820 1.1 pk * for trailers anyway.
821 1.1 pk */
822 1.1 pk static void
823 1.1 pk ie_readframe(sc, num)
824 1.1 pk struct ie_softc *sc;
825 1.1 pk int num; /* frame number to read */
826 1.1 pk {
827 1.1 pk int status;
828 1.1 pk struct mbuf *m = 0;
829 1.1 pk struct ether_header eh;
830 1.1 pk #if NBPFILTER > 0
831 1.1 pk int bpf_gets_it = 0;
832 1.1 pk #endif
833 1.1 pk
834 1.1 pk status = SWAP(sc->rframes[num]->ie_fd_status);
835 1.1 pk
836 1.1 pk /* Immediately advance the RFD list, since we have copied ours now. */
837 1.1 pk sc->rframes[num]->ie_fd_status = SWAP(0);
838 1.1 pk sc->rframes[num]->ie_fd_last |= SWAP(IE_FD_LAST);
839 1.1 pk sc->rframes[sc->rftail]->ie_fd_last &= ~SWAP(IE_FD_LAST);
840 1.1 pk sc->rftail = (sc->rftail + 1) % sc->nframes;
841 1.1 pk sc->rfhead = (sc->rfhead + 1) % sc->nframes;
842 1.1 pk
843 1.1 pk if (status & IE_FD_OK) {
844 1.1 pk #if NBPFILTER > 0
845 1.3 pk m = ieget(sc, &eh, &bpf_gets_it);
846 1.1 pk #else
847 1.3 pk m = ieget(sc, &eh, 0);
848 1.1 pk #endif
849 1.3 pk ie_drop_packet_buffer(sc);
850 1.3 pk }
851 1.3 pk if (m == 0) {
852 1.3 pk sc->sc_ethercom.ec_if.if_ierrors++;
853 1.3 pk return;
854 1.1 pk }
855 1.1 pk
856 1.1 pk #ifdef IEDEBUG
857 1.1 pk if (sc->sc_debug & IED_READFRAME)
858 1.5 pk printf("%s: frame from ether %s type 0x%x\n",
859 1.5 pk sc->sc_dev.dv_xname,
860 1.5 pk ether_sprintf(eh.ether_shost), (u_int)eh.ether_type);
861 1.1 pk #endif
862 1.1 pk
863 1.1 pk #if NBPFILTER > 0
864 1.1 pk /*
865 1.1 pk * Check for a BPF filter; if so, hand it up.
866 1.1 pk * Note that we have to stick an extra mbuf up front, because bpf_mtap
867 1.1 pk * expects to have the ether header at the front.
868 1.1 pk * It doesn't matter that this results in an ill-formatted mbuf chain,
869 1.1 pk * since BPF just looks at the data. (It doesn't try to free the mbuf,
870 1.1 pk * tho' it will make a copy for tcpdump.)
871 1.1 pk */
872 1.1 pk if (bpf_gets_it) {
873 1.1 pk struct mbuf m0;
874 1.1 pk m0.m_len = sizeof eh;
875 1.1 pk m0.m_data = (caddr_t)&eh;
876 1.1 pk m0.m_next = m;
877 1.1 pk
878 1.1 pk /* Pass it up. */
879 1.1 pk bpf_mtap(sc->sc_ethercom.ec_if.if_bpf, &m0);
880 1.3 pk
881 1.3 pk /*
882 1.3 pk * A signal passed up from the filtering code indicating that
883 1.3 pk * the packet is intended for BPF but not for the protocol
884 1.3 pk * machinery. We can save a few cycles by not handing it off
885 1.3 pk * to them.
886 1.3 pk */
887 1.3 pk if (bpf_gets_it == 2) {
888 1.3 pk m_freem(m);
889 1.3 pk return;
890 1.3 pk }
891 1.1 pk }
892 1.1 pk #endif /* NBPFILTER > 0 */
893 1.1 pk
894 1.1 pk /*
895 1.1 pk * In here there used to be code to check destination addresses upon
896 1.1 pk * receipt of a packet. We have deleted that code, and replaced it
897 1.1 pk * with code to check the address much earlier in the cycle, before
898 1.1 pk * copying the data in; this saves us valuable cycles when operating
899 1.1 pk * as a multicast router or when using BPF.
900 1.1 pk */
901 1.1 pk
902 1.1 pk /*
903 1.1 pk * Finally pass this packet up to higher layers.
904 1.1 pk */
905 1.1 pk ether_input(&sc->sc_ethercom.ec_if, &eh, m);
906 1.3 pk sc->sc_ethercom.ec_if.if_ipackets++;
907 1.1 pk }
908 1.1 pk
909 1.1 pk static void
910 1.1 pk ie_drop_packet_buffer(sc)
911 1.1 pk struct ie_softc *sc;
912 1.1 pk {
913 1.1 pk int i;
914 1.1 pk
915 1.1 pk do {
916 1.5 pk bus_space_barrier(sc->bt, sc->bh, 0, 0, BUS_SPACE_BARRIER_READ);
917 1.1 pk i = SWAP(sc->rbuffs[sc->rbhead]->ie_rbd_actual);
918 1.1 pk if ((i & IE_RBD_USED) == 0) {
919 1.3 pk /*
920 1.3 pk * This means we are somehow out of sync. So, we
921 1.3 pk * reset the adapter.
922 1.3 pk */
923 1.1 pk #ifdef IEDEBUG
924 1.1 pk print_rbd(sc->rbuffs[sc->rbhead]);
925 1.1 pk #endif
926 1.1 pk log(LOG_ERR, "%s: receive descriptors out of sync at %d\n",
927 1.1 pk sc->sc_dev.dv_xname, sc->rbhead);
928 1.1 pk iereset(sc);
929 1.1 pk return;
930 1.1 pk }
931 1.1 pk
932 1.1 pk i = (i & IE_RBD_LAST) != 0;
933 1.1 pk
934 1.1 pk sc->rbuffs[sc->rbhead]->ie_rbd_length |= SWAP(IE_RBD_LAST);
935 1.1 pk sc->rbuffs[sc->rbhead]->ie_rbd_actual = SWAP(0);
936 1.1 pk sc->rbhead = (sc->rbhead + 1) % sc->nrxbuf;
937 1.1 pk sc->rbuffs[sc->rbtail]->ie_rbd_length &= ~SWAP(IE_RBD_LAST);
938 1.1 pk sc->rbtail = (sc->rbtail + 1) % sc->nrxbuf;
939 1.1 pk } while (!i);
940 1.1 pk }
941 1.1 pk
942 1.1 pk
943 1.1 pk /*
944 1.1 pk * Start transmission on an interface.
945 1.1 pk */
946 1.1 pk void
947 1.1 pk iestart(ifp)
948 1.1 pk struct ifnet *ifp;
949 1.1 pk {
950 1.1 pk struct ie_softc *sc = ifp->if_softc;
951 1.1 pk struct mbuf *m0, *m;
952 1.1 pk u_char *buffer;
953 1.1 pk u_short len;
954 1.1 pk
955 1.3 pk if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
956 1.1 pk return;
957 1.1 pk
958 1.3 pk for (;;) {
959 1.3 pk if (sc->xmit_busy == NTXBUF) {
960 1.3 pk ifp->if_flags |= IFF_OACTIVE;
961 1.3 pk break;
962 1.3 pk }
963 1.1 pk
964 1.3 pk IF_DEQUEUE(&ifp->if_snd, m0);
965 1.3 pk if (m0 == 0)
966 1.1 pk break;
967 1.1 pk
968 1.3 pk /* We need to use m->m_pkthdr.len, so require the header */
969 1.3 pk if ((m0->m_flags & M_PKTHDR) == 0)
970 1.3 pk panic("iestart: no header mbuf");
971 1.3 pk
972 1.3 pk #if NBPFILTER > 0
973 1.3 pk /* Tap off here if there is a BPF listener. */
974 1.3 pk if (ifp->if_bpf)
975 1.3 pk bpf_mtap(ifp->if_bpf, m0);
976 1.3 pk #endif
977 1.3 pk
978 1.3 pk #ifdef IEDEBUG
979 1.3 pk if (sc->sc_debug & IED_ENQ)
980 1.3 pk printf("%s: fill buffer %d\n", sc->sc_dev.dv_xname,
981 1.3 pk sc->xchead);
982 1.3 pk #endif
983 1.3 pk
984 1.3 pk if (m0->m_pkthdr.len > IE_TBUF_SIZE)
985 1.3 pk printf("%s: tbuf overflow\n", sc->sc_dev.dv_xname);
986 1.3 pk
987 1.1 pk buffer = sc->xmit_cbuffs[sc->xchead];
988 1.3 pk for (m = m0; m != 0; m = m->m_next) {
989 1.5 pk (sc->memcopy)(mtod(m, caddr_t), buffer, m->m_len);
990 1.1 pk buffer += m->m_len;
991 1.1 pk }
992 1.1 pk
993 1.3 pk len = max(m0->m_pkthdr.len, ETHER_MIN_LEN);
994 1.1 pk m_freem(m0);
995 1.3 pk
996 1.1 pk sc->xmit_buffs[sc->xchead]->ie_xmit_flags = SWAP(len);
997 1.1 pk
998 1.3 pk /* Start the first packet transmitting. */
999 1.3 pk if (sc->xmit_busy == 0)
1000 1.3 pk iexmit(sc);
1001 1.3 pk
1002 1.1 pk sc->xchead = (sc->xchead + 1) % NTXBUF;
1003 1.3 pk sc->xmit_busy++;
1004 1.3 pk }
1005 1.1 pk }
1006 1.1 pk
1007 1.1 pk /*
1008 1.1 pk * set up IE's ram space
1009 1.1 pk */
1010 1.1 pk int
1011 1.1 pk ie_setupram(sc)
1012 1.1 pk struct ie_softc *sc;
1013 1.1 pk {
1014 1.1 pk volatile struct ie_sys_conf_ptr *scp;
1015 1.1 pk volatile struct ie_int_sys_conf_ptr *iscp;
1016 1.1 pk volatile struct ie_sys_ctl_block *scb;
1017 1.1 pk int s;
1018 1.1 pk
1019 1.1 pk s = splnet();
1020 1.1 pk
1021 1.1 pk scp = sc->scp;
1022 1.1 pk (sc->memzero)((char *) scp, sizeof *scp);
1023 1.1 pk
1024 1.1 pk iscp = sc->iscp;
1025 1.1 pk (sc->memzero)((char *) iscp, sizeof *iscp);
1026 1.1 pk
1027 1.1 pk scb = sc->scb;
1028 1.1 pk (sc->memzero)((char *) scb, sizeof *scb);
1029 1.1 pk
1030 1.1 pk scp->ie_bus_use = 0; /* 16-bit */
1031 1.1 pk ST_24(scp->ie_iscp_ptr, MK_24(sc->sc_iobase, iscp));
1032 1.1 pk
1033 1.1 pk iscp->ie_busy = 1; /* ie_busy == char */
1034 1.1 pk iscp->ie_scb_offset = MK_16(sc->sc_maddr, scb);
1035 1.1 pk ST_24(iscp->ie_base, MK_24(sc->sc_iobase, sc->sc_maddr));
1036 1.1 pk
1037 1.1 pk if (sc->hwreset)
1038 1.1 pk (sc->hwreset)(sc);
1039 1.1 pk
1040 1.1 pk (sc->chan_attn) (sc);
1041 1.1 pk
1042 1.1 pk delay(100); /* wait a while... */
1043 1.1 pk
1044 1.1 pk if (iscp->ie_busy) {
1045 1.1 pk splx(s);
1046 1.1 pk return 0;
1047 1.1 pk }
1048 1.1 pk /*
1049 1.1 pk * Acknowledge any interrupts we may have caused...
1050 1.1 pk */
1051 1.1 pk ie_ack(sc, IE_ST_WHENCE);
1052 1.1 pk splx(s);
1053 1.1 pk
1054 1.1 pk return 1;
1055 1.1 pk }
1056 1.1 pk
1057 1.1 pk void
1058 1.1 pk iereset(sc)
1059 1.1 pk struct ie_softc *sc;
1060 1.1 pk {
1061 1.1 pk int s = splnet();
1062 1.1 pk
1063 1.1 pk printf("%s: reset\n", sc->sc_dev.dv_xname);
1064 1.1 pk
1065 1.1 pk /* Clear OACTIVE in case we're called from watchdog (frozen xmit). */
1066 1.1 pk sc->sc_ethercom.ec_if.if_flags &= ~IFF_OACTIVE;
1067 1.1 pk
1068 1.1 pk /*
1069 1.1 pk * Stop i82586 dead in its tracks.
1070 1.1 pk */
1071 1.1 pk if (command_and_wait(sc, IE_RU_ABORT | IE_CU_ABORT, 0, 0))
1072 1.1 pk printf("%s: abort commands timed out\n", sc->sc_dev.dv_xname);
1073 1.1 pk
1074 1.1 pk if (command_and_wait(sc, IE_RU_DISABLE | IE_CU_STOP, 0, 0))
1075 1.1 pk printf("%s: disable commands timed out\n", sc->sc_dev.dv_xname);
1076 1.1 pk
1077 1.1 pk
1078 1.5 pk #if 1
1079 1.1 pk if (sc->hwreset)
1080 1.1 pk (sc->hwreset)(sc);
1081 1.1 pk #endif
1082 1.5 pk ie_ack(sc, IE_ST_WHENCE);
1083 1.1 pk #ifdef notdef
1084 1.1 pk if (!check_ie_present(sc, sc->sc_maddr, sc->sc_msize))
1085 1.1 pk panic("ie disappeared!\n");
1086 1.1 pk #endif
1087 1.1 pk
1088 1.1 pk ieinit(sc);
1089 1.1 pk
1090 1.1 pk splx(s);
1091 1.1 pk }
1092 1.1 pk
1093 1.1 pk /*
1094 1.1 pk * Send a command to the controller and wait for it to either complete
1095 1.1 pk * or be accepted, depending on the command. If the command pointer
1096 1.1 pk * is null, then pretend that the command is not an action command.
1097 1.1 pk * If the command pointer is not null, and the command is an action
1098 1.1 pk * command, wait for
1099 1.1 pk * ((volatile struct ie_cmd_common *)pcmd)->ie_cmd_status & MASK
1100 1.1 pk * to become true.
1101 1.1 pk */
1102 1.1 pk static int
1103 1.1 pk command_and_wait(sc, cmd, pcmd, mask)
1104 1.1 pk struct ie_softc *sc;
1105 1.1 pk int cmd; /* native byte-order */
1106 1.1 pk volatile void *pcmd;
1107 1.1 pk int mask; /* native byte-order */
1108 1.1 pk {
1109 1.1 pk volatile struct ie_cmd_common *cc = pcmd;
1110 1.1 pk volatile struct ie_sys_ctl_block *scb = sc->scb;
1111 1.1 pk int i;
1112 1.1 pk
1113 1.1 pk scb->ie_command = (u_short)SWAP(cmd);
1114 1.5 pk bus_space_barrier(sc->bt, sc->bh, 0, 0, BUS_SPACE_BARRIER_WRITE);
1115 1.2 pk (sc->chan_attn)(sc);
1116 1.1 pk
1117 1.1 pk if (IE_ACTION_COMMAND(cmd) && pcmd) {
1118 1.1 pk /*
1119 1.1 pk * According to the packet driver, the minimum timeout should
1120 1.1 pk * be .369 seconds, which we round up to .4.
1121 1.1 pk */
1122 1.1 pk
1123 1.1 pk /*
1124 1.1 pk * Now spin-lock waiting for status. This is not a very nice
1125 1.1 pk * thing to do, but I haven't figured out how, or indeed if, we
1126 1.1 pk * can put the process waiting for action to sleep. (We may
1127 1.1 pk * be getting called through some other timeout running in the
1128 1.1 pk * kernel.)
1129 1.1 pk */
1130 1.2 pk for (i = 0; i < 369000; i++) {
1131 1.2 pk delay(1);
1132 1.1 pk if ((SWAP(cc->ie_cmd_status) & mask))
1133 1.1 pk return (0);
1134 1.1 pk }
1135 1.1 pk
1136 1.1 pk } else {
1137 1.1 pk /*
1138 1.1 pk * Otherwise, just wait for the command to be accepted.
1139 1.1 pk */
1140 1.1 pk
1141 1.1 pk /* XXX spin lock; wait at most 0.1 seconds */
1142 1.2 pk for (i = 0; i < 100000; i++) {
1143 1.1 pk if (scb->ie_command)
1144 1.1 pk return (0);
1145 1.2 pk delay(1);
1146 1.1 pk }
1147 1.2 pk }
1148 1.1 pk
1149 1.2 pk /* Timeout */
1150 1.2 pk return (1);
1151 1.1 pk }
1152 1.1 pk
1153 1.1 pk /*
1154 1.1 pk * Run the time-domain reflectometer.
1155 1.1 pk */
1156 1.1 pk static void
1157 1.1 pk run_tdr(sc, cmd)
1158 1.1 pk struct ie_softc *sc;
1159 1.1 pk struct ie_tdr_cmd *cmd;
1160 1.1 pk {
1161 1.1 pk int result;
1162 1.1 pk
1163 1.1 pk cmd->com.ie_cmd_status = SWAP(0);
1164 1.1 pk cmd->com.ie_cmd_cmd = SWAP(IE_CMD_TDR | IE_CMD_LAST);
1165 1.1 pk cmd->com.ie_cmd_link = SWAP(0xffff);
1166 1.1 pk
1167 1.1 pk sc->scb->ie_command_list = MK_16(sc->sc_maddr, cmd);
1168 1.1 pk cmd->ie_tdr_time = SWAP(0);
1169 1.1 pk
1170 1.1 pk if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
1171 1.3 pk (SWAP(cmd->com.ie_cmd_status) & IE_STAT_OK) == 0)
1172 1.1 pk result = 0x10000; /* XXX */
1173 1.1 pk else
1174 1.1 pk result = SWAP(cmd->ie_tdr_time);
1175 1.1 pk
1176 1.1 pk ie_ack(sc, IE_ST_WHENCE);
1177 1.1 pk
1178 1.1 pk if (result & IE_TDR_SUCCESS)
1179 1.1 pk return;
1180 1.1 pk
1181 1.1 pk if (result & 0x10000)
1182 1.1 pk printf("%s: TDR command failed\n", sc->sc_dev.dv_xname);
1183 1.1 pk else if (result & IE_TDR_XCVR)
1184 1.1 pk printf("%s: transceiver problem\n", sc->sc_dev.dv_xname);
1185 1.1 pk else if (result & IE_TDR_OPEN)
1186 1.1 pk printf("%s: TDR detected an open %d clocks away\n",
1187 1.1 pk sc->sc_dev.dv_xname, result & IE_TDR_TIME);
1188 1.1 pk else if (result & IE_TDR_SHORT)
1189 1.1 pk printf("%s: TDR detected a short %d clocks away\n",
1190 1.1 pk sc->sc_dev.dv_xname, result & IE_TDR_TIME);
1191 1.1 pk else
1192 1.5 pk printf("%s: TDR returned unknown status 0x%x\n",
1193 1.1 pk sc->sc_dev.dv_xname, result);
1194 1.1 pk }
1195 1.1 pk
1196 1.1 pk #ifdef notdef
1197 1.1 pk /* ALIGN works on 8 byte boundaries.... but 4 byte boundaries are ok for sun */
1198 1.1 pk #define _ALLOC(p, n) (bzero(p, n), p += n, p - n)
1199 1.1 pk #define ALLOC(p, n) _ALLOC(p, ALIGN(n)) /* XXX convert to this? */
1200 1.1 pk #endif
1201 1.1 pk
1202 1.1 pk /*
1203 1.1 pk * setup_bufs: set up the buffers
1204 1.1 pk *
1205 1.1 pk * we have a block of KVA at sc->buf_area which is of size sc->buf_area_sz.
1206 1.1 pk * this is to be used for the buffers. the chip indexs its control data
1207 1.1 pk * structures with 16 bit offsets, and it indexes actual buffers with
1208 1.1 pk * 24 bit addresses. so we should allocate control buffers first so that
1209 1.1 pk * we don't overflow the 16 bit offset field. The number of transmit
1210 1.1 pk * buffers is fixed at compile time.
1211 1.1 pk *
1212 1.1 pk * note: this function was written to be easy to understand, rather than
1213 1.1 pk * highly efficient (it isn't in the critical path).
1214 1.1 pk */
1215 1.1 pk static void
1216 1.1 pk setup_bufs(sc)
1217 1.1 pk struct ie_softc *sc;
1218 1.1 pk {
1219 1.1 pk caddr_t ptr = sc->buf_area; /* memory pool */
1220 1.1 pk int n, r;
1221 1.1 pk
1222 1.1 pk /*
1223 1.1 pk * step 0: zero memory and figure out how many recv buffers and
1224 1.3 pk * frames we can have.
1225 1.1 pk */
1226 1.1 pk (sc->memzero)(ptr, sc->buf_area_sz);
1227 1.1 pk ptr = (sc->align)(ptr); /* set alignment and stick with it */
1228 1.1 pk
1229 1.1 pk n = (int)(sc->align)((caddr_t) sizeof(struct ie_xmit_cmd)) +
1230 1.1 pk (int)(sc->align)((caddr_t) sizeof(struct ie_xmit_buf)) + IE_TBUF_SIZE;
1231 1.1 pk n *= NTXBUF; /* n = total size of xmit area */
1232 1.1 pk
1233 1.1 pk n = sc->buf_area_sz - n;/* n = free space for recv stuff */
1234 1.1 pk
1235 1.1 pk r = (int)(sc->align)((caddr_t) sizeof(struct ie_recv_frame_desc)) +
1236 1.1 pk (((int)(sc->align)((caddr_t) sizeof(struct ie_recv_buf_desc)) +
1237 1.1 pk IE_RBUF_SIZE) * B_PER_F);
1238 1.1 pk
1239 1.1 pk /* r = size of one R frame */
1240 1.1 pk
1241 1.1 pk sc->nframes = n / r;
1242 1.1 pk if (sc->nframes <= 0)
1243 1.1 pk panic("ie: bogus buffer calc\n");
1244 1.3 pk if (sc->nframes > MAXFRAMES)
1245 1.3 pk sc->nframes = MAXFRAMES;
1246 1.1 pk
1247 1.1 pk sc->nrxbuf = sc->nframes * B_PER_F;
1248 1.1 pk
1249 1.1 pk #ifdef IEDEBUG
1250 1.1 pk printf("IEDEBUG: %d frames %d bufs\n", sc->nframes, sc->nrxbuf);
1251 1.1 pk #endif
1252 1.1 pk
1253 1.1 pk /*
1254 1.1 pk * step 1a: lay out and zero frame data structures for transmit and recv
1255 1.1 pk */
1256 1.1 pk for (n = 0; n < NTXBUF; n++) {
1257 1.1 pk sc->xmit_cmds[n] = (volatile struct ie_xmit_cmd *) ptr;
1258 1.1 pk ptr = (sc->align)(ptr + sizeof(struct ie_xmit_cmd));
1259 1.1 pk }
1260 1.1 pk
1261 1.1 pk for (n = 0; n < sc->nframes; n++) {
1262 1.1 pk sc->rframes[n] = (volatile struct ie_recv_frame_desc *) ptr;
1263 1.1 pk ptr = (sc->align)(ptr + sizeof(struct ie_recv_frame_desc));
1264 1.1 pk }
1265 1.1 pk
1266 1.1 pk /*
1267 1.1 pk * step 1b: link together the recv frames and set EOL on last one
1268 1.1 pk */
1269 1.1 pk for (n = 0; n < sc->nframes; n++) {
1270 1.1 pk sc->rframes[n]->ie_fd_next =
1271 1.1 pk MK_16(sc->sc_maddr, sc->rframes[(n + 1) % sc->nframes]);
1272 1.1 pk }
1273 1.1 pk sc->rframes[sc->nframes - 1]->ie_fd_last |= SWAP(IE_FD_LAST);
1274 1.1 pk
1275 1.1 pk /*
1276 1.1 pk * step 2a: lay out and zero frame buffer structures for xmit and recv
1277 1.1 pk */
1278 1.1 pk for (n = 0; n < NTXBUF; n++) {
1279 1.1 pk sc->xmit_buffs[n] = (volatile struct ie_xmit_buf *) ptr;
1280 1.1 pk ptr = (sc->align)(ptr + sizeof(struct ie_xmit_buf));
1281 1.1 pk }
1282 1.1 pk
1283 1.1 pk for (n = 0; n < sc->nrxbuf; n++) {
1284 1.1 pk sc->rbuffs[n] = (volatile struct ie_recv_buf_desc *) ptr;
1285 1.1 pk ptr = (sc->align)(ptr + sizeof(struct ie_recv_buf_desc));
1286 1.1 pk }
1287 1.1 pk
1288 1.1 pk /*
1289 1.1 pk * step 2b: link together recv bufs and set EOL on last one
1290 1.1 pk */
1291 1.1 pk for (n = 0; n < sc->nrxbuf; n++) {
1292 1.1 pk sc->rbuffs[n]->ie_rbd_next =
1293 1.1 pk MK_16(sc->sc_maddr, sc->rbuffs[(n + 1) % sc->nrxbuf]);
1294 1.1 pk }
1295 1.1 pk sc->rbuffs[sc->nrxbuf - 1]->ie_rbd_length |= SWAP(IE_RBD_LAST);
1296 1.1 pk
1297 1.1 pk /*
1298 1.1 pk * step 3: allocate the actual data buffers for xmit and recv
1299 1.1 pk * recv buffer gets linked into recv_buf_desc list here
1300 1.1 pk */
1301 1.1 pk for (n = 0; n < NTXBUF; n++) {
1302 1.1 pk sc->xmit_cbuffs[n] = (u_char *) ptr;
1303 1.1 pk ptr = (sc->align)(ptr + IE_TBUF_SIZE);
1304 1.1 pk }
1305 1.1 pk
1306 1.1 pk /* Pointers to last packet sent and next available transmit buffer. */
1307 1.1 pk sc->xchead = sc->xctail = 0;
1308 1.1 pk
1309 1.1 pk /* Clear transmit-busy flag and set number of free transmit buffers. */
1310 1.1 pk sc->xmit_busy = 0;
1311 1.1 pk
1312 1.1 pk for (n = 0; n < sc->nrxbuf; n++) {
1313 1.1 pk sc->cbuffs[n] = (char *) ptr; /* XXX why char vs uchar? */
1314 1.1 pk sc->rbuffs[n]->ie_rbd_length = SWAP(IE_RBUF_SIZE);
1315 1.1 pk ST_24(sc->rbuffs[n]->ie_rbd_buffer, MK_24(sc->sc_iobase, ptr));
1316 1.1 pk ptr = (sc->align)(ptr + IE_RBUF_SIZE);
1317 1.1 pk }
1318 1.1 pk
1319 1.1 pk /*
1320 1.1 pk * step 4: set the head and tail pointers on receive to keep track of
1321 1.1 pk * the order in which RFDs and RBDs are used. link in recv frames
1322 1.1 pk * and buffer into the scb.
1323 1.1 pk */
1324 1.1 pk
1325 1.1 pk sc->rfhead = 0;
1326 1.1 pk sc->rftail = sc->nframes - 1;
1327 1.1 pk sc->rbhead = 0;
1328 1.1 pk sc->rbtail = sc->nrxbuf - 1;
1329 1.1 pk
1330 1.1 pk sc->scb->ie_recv_list = MK_16(sc->sc_maddr, sc->rframes[0]);
1331 1.1 pk sc->rframes[0]->ie_fd_buf_desc = MK_16(sc->sc_maddr, sc->rbuffs[0]);
1332 1.1 pk
1333 1.1 pk #ifdef IEDEBUG
1334 1.1 pk printf("IE_DEBUG: reserved %d bytes\n", ptr - sc->buf_area);
1335 1.1 pk #endif
1336 1.1 pk }
1337 1.1 pk
1338 1.1 pk /*
1339 1.1 pk * Run the multicast setup command.
1340 1.1 pk * Called at splnet().
1341 1.1 pk */
1342 1.1 pk static int
1343 1.1 pk mc_setup(sc, ptr)
1344 1.1 pk struct ie_softc *sc;
1345 1.1 pk void *ptr;
1346 1.1 pk {
1347 1.1 pk volatile struct ie_mcast_cmd *cmd = ptr;
1348 1.1 pk
1349 1.1 pk cmd->com.ie_cmd_status = SWAP(0);
1350 1.1 pk cmd->com.ie_cmd_cmd = SWAP(IE_CMD_MCAST | IE_CMD_LAST);
1351 1.1 pk cmd->com.ie_cmd_link = SWAP(0xffff);
1352 1.1 pk
1353 1.1 pk (sc->memcopy)((caddr_t)sc->mcast_addrs, (caddr_t)cmd->ie_mcast_addrs,
1354 1.1 pk sc->mcast_count * sizeof *sc->mcast_addrs);
1355 1.1 pk
1356 1.1 pk cmd->ie_mcast_bytes =
1357 1.1 pk SWAP(sc->mcast_count * ETHER_ADDR_LEN); /* grrr... */
1358 1.1 pk
1359 1.1 pk sc->scb->ie_command_list = MK_16(sc->sc_maddr, cmd);
1360 1.1 pk if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
1361 1.3 pk (SWAP(cmd->com.ie_cmd_status) & IE_STAT_OK) == 0) {
1362 1.1 pk printf("%s: multicast address setup command failed\n",
1363 1.1 pk sc->sc_dev.dv_xname);
1364 1.1 pk return 0;
1365 1.1 pk }
1366 1.1 pk return 1;
1367 1.1 pk }
1368 1.1 pk
1369 1.1 pk /*
1370 1.1 pk * This routine takes the environment generated by check_ie_present() and adds
1371 1.1 pk * to it all the other structures we need to operate the adapter. This
1372 1.1 pk * includes executing the CONFIGURE, IA-SETUP, and MC-SETUP commands, starting
1373 1.1 pk * the receiver unit, and clearing interrupts.
1374 1.1 pk *
1375 1.1 pk * THIS ROUTINE MUST BE CALLED AT splnet() OR HIGHER.
1376 1.1 pk */
1377 1.1 pk int
1378 1.1 pk ieinit(sc)
1379 1.1 pk struct ie_softc *sc;
1380 1.1 pk {
1381 1.1 pk volatile struct ie_sys_ctl_block *scb = sc->scb;
1382 1.3 pk struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1383 1.1 pk void *ptr;
1384 1.1 pk
1385 1.1 pk ptr = sc->buf_area;
1386 1.1 pk
1387 1.1 pk /*
1388 1.1 pk * Send the configure command first.
1389 1.1 pk */
1390 1.1 pk {
1391 1.1 pk volatile struct ie_config_cmd *cmd = ptr;
1392 1.1 pk
1393 1.1 pk scb->ie_command_list = MK_16(sc->sc_maddr, cmd);
1394 1.1 pk cmd->com.ie_cmd_status = SWAP(0);
1395 1.1 pk cmd->com.ie_cmd_cmd = SWAP(IE_CMD_CONFIG | IE_CMD_LAST);
1396 1.1 pk cmd->com.ie_cmd_link = SWAP(0xffff);
1397 1.1 pk
1398 1.1 pk ie_setup_config(cmd, sc->promisc, 0);
1399 1.1 pk
1400 1.1 pk if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
1401 1.3 pk (SWAP(cmd->com.ie_cmd_status) & IE_STAT_OK) == 0) {
1402 1.1 pk printf("%s: configure command failed\n",
1403 1.1 pk sc->sc_dev.dv_xname);
1404 1.1 pk return 0;
1405 1.1 pk }
1406 1.1 pk }
1407 1.1 pk
1408 1.1 pk /*
1409 1.1 pk * Now send the Individual Address Setup command.
1410 1.1 pk */
1411 1.1 pk {
1412 1.1 pk volatile struct ie_iasetup_cmd *cmd = ptr;
1413 1.1 pk
1414 1.1 pk scb->ie_command_list = MK_16(sc->sc_maddr, cmd);
1415 1.1 pk cmd->com.ie_cmd_status = SWAP(0);
1416 1.1 pk cmd->com.ie_cmd_cmd = SWAP(IE_CMD_IASETUP | IE_CMD_LAST);
1417 1.1 pk cmd->com.ie_cmd_link = SWAP(0xffff);
1418 1.1 pk
1419 1.3 pk (sc->memcopy)(LLADDR(ifp->if_sadl),
1420 1.1 pk (caddr_t)&cmd->ie_address, sizeof cmd->ie_address);
1421 1.1 pk
1422 1.1 pk if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
1423 1.3 pk (SWAP(cmd->com.ie_cmd_status) & IE_STAT_OK) == 0) {
1424 1.1 pk printf("%s: individual address setup command failed\n",
1425 1.1 pk sc->sc_dev.dv_xname);
1426 1.1 pk return 0;
1427 1.1 pk }
1428 1.1 pk }
1429 1.1 pk
1430 1.1 pk /*
1431 1.1 pk * Now run the time-domain reflectometer.
1432 1.1 pk */
1433 1.1 pk run_tdr(sc, ptr);
1434 1.1 pk
1435 1.1 pk /*
1436 1.1 pk * Acknowledge any interrupts we have generated thus far.
1437 1.1 pk */
1438 1.1 pk ie_ack(sc, IE_ST_WHENCE);
1439 1.1 pk
1440 1.1 pk /*
1441 1.1 pk * Set up the transmit and recv buffers.
1442 1.1 pk */
1443 1.1 pk setup_bufs(sc);
1444 1.1 pk
1445 1.3 pk ifp->if_flags |= IFF_RUNNING;
1446 1.3 pk ifp->if_flags &= ~IFF_OACTIVE;
1447 1.1 pk
1448 1.1 pk sc->scb->ie_recv_list = MK_16(sc->sc_maddr, sc->rframes[0]);
1449 1.1 pk command_and_wait(sc, IE_RU_START, 0, 0);
1450 1.1 pk
1451 1.1 pk ie_ack(sc, IE_ST_WHENCE);
1452 1.1 pk
1453 1.1 pk if (sc->hwinit)
1454 1.1 pk (sc->hwinit)(sc);
1455 1.1 pk
1456 1.1 pk return 0;
1457 1.1 pk }
1458 1.1 pk
1459 1.1 pk static void
1460 1.1 pk iestop(sc)
1461 1.1 pk struct ie_softc *sc;
1462 1.1 pk {
1463 1.1 pk
1464 1.1 pk command_and_wait(sc, IE_RU_DISABLE, 0, 0);
1465 1.1 pk }
1466 1.1 pk
1467 1.1 pk int
1468 1.1 pk ieioctl(ifp, cmd, data)
1469 1.1 pk register struct ifnet *ifp;
1470 1.1 pk u_long cmd;
1471 1.1 pk caddr_t data;
1472 1.1 pk {
1473 1.1 pk struct ie_softc *sc = ifp->if_softc;
1474 1.1 pk struct ifaddr *ifa = (struct ifaddr *)data;
1475 1.1 pk struct ifreq *ifr = (struct ifreq *)data;
1476 1.1 pk int s, error = 0;
1477 1.1 pk
1478 1.1 pk s = splnet();
1479 1.1 pk
1480 1.1 pk switch(cmd) {
1481 1.1 pk
1482 1.1 pk case SIOCSIFADDR:
1483 1.1 pk ifp->if_flags |= IFF_UP;
1484 1.1 pk
1485 1.1 pk switch(ifa->ifa_addr->sa_family) {
1486 1.1 pk #ifdef INET
1487 1.1 pk case AF_INET:
1488 1.1 pk ieinit(sc);
1489 1.1 pk arp_ifinit(ifp, ifa);
1490 1.1 pk break;
1491 1.1 pk #endif
1492 1.1 pk #ifdef NS
1493 1.1 pk /* XXX - This code is probably wrong. */
1494 1.1 pk case AF_NS:
1495 1.1 pk {
1496 1.1 pk struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
1497 1.1 pk
1498 1.1 pk if (ns_nullhost(*ina))
1499 1.1 pk ina->x_host =
1500 1.1 pk *(union ns_host *)LLADDR(ifp->if_sadl);
1501 1.1 pk else
1502 1.1 pk bcopy(ina->x_host.c_host,
1503 1.1 pk LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
1504 1.1 pk /* Set new address. */
1505 1.1 pk ieinit(sc);
1506 1.1 pk break;
1507 1.1 pk }
1508 1.1 pk #endif /* NS */
1509 1.1 pk default:
1510 1.1 pk ieinit(sc);
1511 1.1 pk break;
1512 1.1 pk }
1513 1.1 pk break;
1514 1.1 pk
1515 1.1 pk case SIOCSIFFLAGS:
1516 1.1 pk sc->promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI);
1517 1.1 pk if ((ifp->if_flags & IFF_UP) == 0 &&
1518 1.1 pk (ifp->if_flags & IFF_RUNNING) != 0) {
1519 1.1 pk /*
1520 1.1 pk * If interface is marked down and it is running, then
1521 1.1 pk * stop it.
1522 1.1 pk */
1523 1.1 pk iestop(sc);
1524 1.1 pk ifp->if_flags &= ~IFF_RUNNING;
1525 1.1 pk } else if ((ifp->if_flags & IFF_UP) != 0 &&
1526 1.1 pk (ifp->if_flags & IFF_RUNNING) == 0) {
1527 1.1 pk /*
1528 1.1 pk * If interface is marked up and it is stopped, then
1529 1.1 pk * start it.
1530 1.1 pk */
1531 1.1 pk ieinit(sc);
1532 1.1 pk } else {
1533 1.1 pk /*
1534 1.1 pk * Reset the interface to pick up changes in any other
1535 1.1 pk * flags that affect hardware registers.
1536 1.1 pk */
1537 1.1 pk iestop(sc);
1538 1.1 pk ieinit(sc);
1539 1.1 pk }
1540 1.1 pk #ifdef IEDEBUG
1541 1.1 pk if (ifp->if_flags & IFF_DEBUG)
1542 1.1 pk sc->sc_debug = IED_ALL;
1543 1.1 pk else
1544 1.1 pk sc->sc_debug = 0;
1545 1.1 pk #endif
1546 1.1 pk break;
1547 1.1 pk
1548 1.1 pk case SIOCADDMULTI:
1549 1.1 pk case SIOCDELMULTI:
1550 1.1 pk error = (cmd == SIOCADDMULTI) ?
1551 1.1 pk ether_addmulti(ifr, &sc->sc_ethercom):
1552 1.1 pk ether_delmulti(ifr, &sc->sc_ethercom);
1553 1.1 pk
1554 1.1 pk if (error == ENETRESET) {
1555 1.1 pk /*
1556 1.1 pk * Multicast list has changed; set the hardware filter
1557 1.1 pk * accordingly.
1558 1.1 pk */
1559 1.1 pk mc_reset(sc);
1560 1.1 pk error = 0;
1561 1.1 pk }
1562 1.1 pk break;
1563 1.1 pk
1564 1.1 pk default:
1565 1.1 pk error = EINVAL;
1566 1.1 pk }
1567 1.1 pk splx(s);
1568 1.1 pk return error;
1569 1.1 pk }
1570 1.1 pk
1571 1.1 pk static void
1572 1.1 pk mc_reset(sc)
1573 1.1 pk struct ie_softc *sc;
1574 1.1 pk {
1575 1.1 pk struct ether_multi *enm;
1576 1.1 pk struct ether_multistep step;
1577 1.1 pk
1578 1.1 pk /*
1579 1.1 pk * Step through the list of addresses.
1580 1.1 pk */
1581 1.1 pk sc->mcast_count = 0;
1582 1.1 pk ETHER_FIRST_MULTI(step, &sc->sc_ethercom, enm);
1583 1.1 pk while (enm) {
1584 1.1 pk if (sc->mcast_count >= MAXMCAST ||
1585 1.1 pk bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) {
1586 1.1 pk sc->sc_ethercom.ec_if.if_flags |= IFF_ALLMULTI;
1587 1.1 pk ieioctl(&sc->sc_ethercom.ec_if, SIOCSIFFLAGS, (void *)0);
1588 1.1 pk goto setflag;
1589 1.1 pk }
1590 1.1 pk
1591 1.1 pk bcopy(enm->enm_addrlo, &sc->mcast_addrs[sc->mcast_count], 6);
1592 1.1 pk sc->mcast_count++;
1593 1.1 pk ETHER_NEXT_MULTI(step, enm);
1594 1.1 pk }
1595 1.1 pk setflag:
1596 1.1 pk sc->want_mcsetup = 1;
1597 1.1 pk }
1598 1.1 pk
1599 1.1 pk #ifdef IEDEBUG
1600 1.1 pk void
1601 1.1 pk print_rbd(rbd)
1602 1.1 pk volatile struct ie_recv_buf_desc *rbd;
1603 1.1 pk {
1604 1.3 pk u_long bufval;
1605 1.3 pk
1606 1.3 pk bcopy((char *)&rbd->ie_rbd_buffer, &bufval, 4); /*XXX*/
1607 1.1 pk
1608 1.3 pk printf("RBD at %08lx:\nactual %04x, next %04x, buffer %lx\n"
1609 1.1 pk "length %04x, mbz %04x\n", (u_long)rbd,
1610 1.3 pk SWAP(rbd->ie_rbd_actual),
1611 1.1 pk SWAP(rbd->ie_rbd_next),
1612 1.3 pk bufval,
1613 1.1 pk SWAP(rbd->ie_rbd_length),
1614 1.1 pk rbd->mbz);
1615 1.1 pk }
1616 1.1 pk #endif
1617