1 /* $NetBSD: i82586.c,v 1.65 2009/03/14 15:36:17 dsl Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg and Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1997 Paul Kranenburg.
34 * Copyright (c) 1992, 1993, University of Vermont and State
35 * Agricultural College.
36 * Copyright (c) 1992, 1993, Garrett A. Wollman.
39 * Copyright (c) 1994, 1995, Rafal K. Boni
40 * Copyright (c) 1990, 1991, William F. Jolitz
41 * Copyright (c) 1990, The Regents of the University of California
43 * All rights reserved.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of Vermont
56 * and State Agricultural College and Garrett A. Wollman, by William F.
57 * Jolitz, and by the University of California, Berkeley, Lawrence
58 * Berkeley Laboratory, and its contributors.
59 * 4. Neither the names of the Universities nor the names of the authors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77 * Intel 82586 Ethernet chip
78 * Register, bit, and structure definitions.
80 * Original StarLAN driver written by Garrett Wollman with reference to the
81 * Clarkson Packet Driver code for this chip written by Russ Nelson and others.
83 * BPF support code taken from hpdev/if_le.c, supplied with tcpdump.
85 * 3C507 support is loosely based on code donated to NetBSD by Rafal Boni.
87 * Majorly cleaned up and 3C507 code merged by Charles Hannum.
89 * Converted to SUN ie driver by Charles D. Cranor,
90 * October 1994, January 1995.
91 * This sun version based on i386 version 1.30.
95 * The i82586 is a very painful chip, found in sun3's, sun-4/100's
96 * sun-4/200's, and VME based suns. The byte order is all wrong for a
97 * SUN, making life difficult. Programming this chip is mostly the same,
98 * but certain details differ from system to system. This driver is
99 * written so that different "ie" interfaces can be controled by the same
106 We run the 82586 in a standard Ethernet mode. We keep NFRAMES
107 received frame descriptors around for the receiver to use, and
108 NRXBUF associated receive buffer descriptors, both in a circular
109 list. Whenever a frame is received, we rotate both lists as
110 necessary. (The 586 treats both lists as a simple queue.) We also
111 keep a transmit command around so that packets can be sent off
114 We configure the adapter in AL-LOC = 1 mode, which means that the
115 Ethernet/802.3 MAC header is placed at the beginning of the receive
116 buffer rather than being split off into various fields in the RFD.
117 This also means that we must include this header in the transmit
120 By convention, all transmit commands, and only transmit commands,
121 shall have the I (IE_CMD_INTR) bit set in the command. This way,
122 when an interrupt arrives at i82586_intr(), it is immediately possible
123 to tell what precisely caused it. ANY OTHER command-sending
124 routines should run at splnet(), and should post an acknowledgement
125 to every interrupt they generate.
127 To save the expense of shipping a command to 82586 every time we
128 want to send a frame, we use a linked list of commands consisting
129 of alternate XMIT and NOP commands. The links of these elements
130 are manipulated (in iexmit()) such that the NOP command loops back
131 to itself whenever the following XMIT command is not yet ready to
132 go. Whenever an XMIT is ready, the preceding NOP link is pointed
133 at it, while its own link field points to the following NOP command.
134 Thus, a single transmit command sets off an interlocked traversal
135 of the xmit command chain, with the host processor in control of
139 #include <sys/cdefs.h>
140 __KERNEL_RCSID(0, "$NetBSD: i82586.c,v 1.65 2009/03/14 15:36:17 dsl Exp $");
142 #include "bpfilter.h"
144 #include <sys/param.h>
145 #include <sys/systm.h>
146 #include <sys/mbuf.h>
147 #include <sys/socket.h>
148 #include <sys/ioctl.h>
149 #include <sys/errno.h>
150 #include <sys/syslog.h>
151 #include <sys/device.h>
154 #include <net/if_dl.h>
155 #include <net/if_types.h>
156 #include <net/if_media.h>
157 #include <net/if_ether.h>
161 #include <net/bpfdesc.h>
166 #include <dev/ic/i82586reg.h>
167 #include <dev/ic/i82586var.h>
169 void i82586_reset(struct ie_softc
*, int);
170 void i82586_watchdog(struct ifnet
*);
171 int i82586_init(struct ifnet
*);
172 int i82586_ioctl(struct ifnet
*, u_long
, void *);
173 void i82586_start(struct ifnet
*);
174 void i82586_stop(struct ifnet
*, int);
177 int i82586_rint(struct ie_softc
*, int);
178 int i82586_tint(struct ie_softc
*, int);
180 int i82586_mediachange(struct ifnet
*);
181 void i82586_mediastatus(struct ifnet
*, struct ifmediareq
*);
183 static int ie_readframe(struct ie_softc
*, int);
184 static struct mbuf
*ieget(struct ie_softc
*, int, int);
185 static int i82586_get_rbd_list(struct ie_softc
*,
186 u_int16_t
*, u_int16_t
*, int *);
187 static void i82586_release_rbd_list(struct ie_softc
*,
188 u_int16_t
, u_int16_t
);
189 static int i82586_drop_frames(struct ie_softc
*);
190 static int i82586_chk_rx_ring(struct ie_softc
*);
192 static inline void ie_ack(struct ie_softc
*, u_int
);
193 static inline void iexmit(struct ie_softc
*);
194 static void i82586_start_transceiver(struct ie_softc
*);
196 static void i82586_count_errors(struct ie_softc
*);
197 static void i82586_rx_errors(struct ie_softc
*, int, int);
198 static void i82586_setup_bufs(struct ie_softc
*);
199 static void setup_simple_command(struct ie_softc
*, int, int);
200 static int ie_cfg_setup(struct ie_softc
*, int, int, int);
201 static int ie_ia_setup(struct ie_softc
*, int);
202 static void ie_run_tdr(struct ie_softc
*, int);
203 static int ie_mc_setup(struct ie_softc
*, int);
204 static void ie_mc_reset(struct ie_softc
*);
205 static int i82586_start_cmd(struct ie_softc
*, int, int, int, int);
206 static int i82586_cmd_wait(struct ie_softc
*);
209 void print_rbd(struct ie_softc
*, int);
212 static char* padbuf
= NULL
;
215 * Front-ends call this function to attach to the MI driver.
217 * The front-end has responsibility for managing the ICP and ISCP
218 * structures. Both of these are opaque to us. Also, the front-end
219 * chooses a location for the SCB which is expected to be addressable
220 * (through `sc->scb') as an offset against the shared-memory bus handle.
222 * The following MD interface function must be setup by the front-end
223 * before calling here:
225 * hwreset - board dependent reset
226 * hwinit - board dependent initialization
227 * chan_attn - channel attention
228 * intrhook - board dependent interrupt processing
229 * memcopyin - shared memory copy: board to KVA
230 * memcopyout - shared memory copy: KVA to board
231 * ie_bus_read16 - read a sixteen-bit i82586 pointer
232 * ie_bus_write16 - write a sixteen-bit i82586 pointer
233 * ie_bus_write24 - write a twenty-four-bit i82586 pointer
237 i82586_attach(struct ie_softc
*sc
, const char *name
, u_int8_t
*etheraddr
, int *media
, int nmedia
, int defmedia
)
240 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
242 strlcpy(ifp
->if_xname
, device_xname(&sc
->sc_dev
), IFNAMSIZ
);
244 ifp
->if_start
= i82586_start
;
245 ifp
->if_ioctl
= i82586_ioctl
;
246 ifp
->if_init
= i82586_init
;
247 ifp
->if_stop
= i82586_stop
;
248 ifp
->if_watchdog
= i82586_watchdog
;
250 IFF_BROADCAST
| IFF_SIMPLEX
| IFF_NOTRAILERS
| IFF_MULTICAST
;
251 IFQ_SET_READY(&ifp
->if_snd
);
253 /* Initialize media goo. */
254 ifmedia_init(&sc
->sc_media
, 0, i82586_mediachange
, i82586_mediastatus
);
256 for (i
= 0; i
< nmedia
; i
++)
257 ifmedia_add(&sc
->sc_media
, media
[i
], 0, NULL
);
258 ifmedia_set(&sc
->sc_media
, defmedia
);
260 ifmedia_add(&sc
->sc_media
, IFM_ETHER
|IFM_MANUAL
, 0, NULL
);
261 ifmedia_set(&sc
->sc_media
, IFM_ETHER
|IFM_MANUAL
);
264 if (padbuf
== NULL
) {
265 padbuf
= malloc(ETHER_MIN_LEN
- ETHER_CRC_LEN
, M_DEVBUF
,
267 if (padbuf
== NULL
) {
268 aprint_error_dev(&sc
->sc_dev
, "can't allocate pad buffer\n");
273 /* Attach the interface. */
275 ether_ifattach(ifp
, etheraddr
);
277 printf(" address %s, type %s\n", ether_sprintf(etheraddr
), name
);
282 * Device timeout/watchdog routine.
283 * Entered if the device neglects to generate an interrupt after a
284 * transmit has been started on it.
287 i82586_watchdog(struct ifnet
*ifp
)
289 struct ie_softc
*sc
= ifp
->if_softc
;
291 log(LOG_ERR
, "%s: device timeout\n", device_xname(&sc
->sc_dev
));
298 i82586_cmd_wait(struct ie_softc
*sc
)
300 /* spin on i82586 command acknowledge; wait at most 0.9 (!) seconds */
304 for (i
= 0; i
< 900000; i
++) {
305 /* Read the command word */
306 off
= IE_SCB_CMD(sc
->scb
);
308 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
309 if ((cmd
= sc
->ie_bus_read16(sc
, off
)) == 0)
314 off
= IE_SCB_STATUS(sc
->scb
);
315 printf("i82586_cmd_wait: timo(%ssync): scb status: 0x%x, cmd: 0x%x\n",
316 sc
->async_cmd_inprogress
?"a":"",
317 sc
->ie_bus_read16(sc
, off
), cmd
);
319 return (1); /* Timeout */
323 * Send a command to the controller and wait for it to either complete
324 * or be accepted, depending on the command. If the command pointer
325 * is null, then pretend that the command is not an action command.
326 * If the command pointer is not null, and the command is an action
327 * command, wait for one of the MASK bits to turn on in the command's
329 * If ASYNC is set, we just call the chip's attention and return.
330 * We may have to wait for the command's acceptance later though.
333 i82586_start_cmd(struct ie_softc
*sc
, int cmd
, int iecmdbuf
, int mask
, int async
)
338 if (sc
->async_cmd_inprogress
!= 0) {
340 * If previous command was issued asynchronously, wait
343 if (i82586_cmd_wait(sc
) != 0)
345 sc
->async_cmd_inprogress
= 0;
348 off
= IE_SCB_CMD(sc
->scb
);
349 sc
->ie_bus_write16(sc
, off
, cmd
);
350 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_WRITE
);
351 (sc
->chan_attn
)(sc
, CARD_RESET
);
354 sc
->async_cmd_inprogress
= 1;
358 if (IE_ACTION_COMMAND(cmd
) && iecmdbuf
) {
361 * Now spin-lock waiting for status. This is not a very nice
362 * thing to do, and can kill performance pretty well...
363 * According to the packet driver, the minimum timeout
364 * should be .369 seconds.
366 for (i
= 0; i
< 369000; i
++) {
367 /* Read the command status */
368 off
= IE_CMD_COMMON_STATUS(iecmdbuf
);
369 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
370 status
= sc
->ie_bus_read16(sc
, off
);
378 * Otherwise, just wait for the command to be accepted.
380 return (i82586_cmd_wait(sc
));
388 * Interrupt Acknowledge.
391 ie_ack(struct ie_softc
*sc
, u_int mask
)
392 /* mask: in native byte-order */
396 IE_BUS_BARRIER(sc
, 0, 0, BUS_SPACE_BARRIER_READ
);
397 status
= sc
->ie_bus_read16(sc
, IE_SCB_STATUS(sc
->scb
));
398 i82586_start_cmd(sc
, status
& mask
, 0, 0, 0);
400 sc
->intrhook(sc
, INTR_ACK
);
404 * Transfer accumulated chip error counters to IF.
407 i82586_count_errors(struct ie_softc
*sc
)
411 sc
->sc_ethercom
.ec_if
.if_ierrors
+=
412 sc
->ie_bus_read16(sc
, IE_SCB_ERRCRC(scb
)) +
413 sc
->ie_bus_read16(sc
, IE_SCB_ERRALN(scb
)) +
414 sc
->ie_bus_read16(sc
, IE_SCB_ERRRES(scb
)) +
415 sc
->ie_bus_read16(sc
, IE_SCB_ERROVR(scb
));
417 /* Clear error counters */
418 sc
->ie_bus_write16(sc
, IE_SCB_ERRCRC(scb
), 0);
419 sc
->ie_bus_write16(sc
, IE_SCB_ERRALN(scb
), 0);
420 sc
->ie_bus_write16(sc
, IE_SCB_ERRRES(scb
), 0);
421 sc
->ie_bus_write16(sc
, IE_SCB_ERROVR(scb
), 0);
425 i82586_rx_errors(struct ie_softc
*sc
, int fn
, int status
)
428 snprintb(bits
, sizeof(bits
), IE_FD_STATUSBITS
, status
);
429 log(LOG_ERR
, "%s: rx error (frame# %d): %s\n",
430 device_xname(&sc
->sc_dev
), fn
, bits
);
435 * i82586 interrupt entry point.
440 struct ie_softc
*sc
= v
;
445 * Implementation dependent interrupt handling.
448 (sc
->intrhook
)(sc
, INTR_ENTER
);
450 off
= IE_SCB_STATUS(sc
->scb
);
451 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
452 status
= sc
->ie_bus_read16(sc
, off
) & IE_ST_WHENCE
;
454 if ((status
& IE_ST_WHENCE
) == 0) {
456 (sc
->intrhook
)(sc
, INTR_EXIT
);
462 /* Ack interrupts FIRST in case we receive more during the ISR. */
464 ie_ack(sc
, status
& IE_ST_WHENCE
);
466 i82586_start_cmd(sc
, status
& IE_ST_WHENCE
, 0, 0, 1);
468 if (status
& (IE_ST_FR
| IE_ST_RNR
))
469 if (i82586_rint(sc
, status
) != 0)
472 if (status
& IE_ST_CX
)
473 if (i82586_tint(sc
, status
) != 0)
477 if ((status
& IE_ST_CNA
) && (sc
->sc_debug
& IED_CNA
))
478 printf("%s: cna; status=0x%x\n", device_xname(&sc
->sc_dev
), status
);
481 (sc
->intrhook
)(sc
, INTR_LOOP
);
484 * Interrupt ACK was posted asynchronously; wait for
485 * completion here before reading SCB status again.
487 * If ACK fails, try to reset the chip, in hopes that
490 if (i82586_cmd_wait(sc
) != 0)
493 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
494 status
= sc
->ie_bus_read16(sc
, off
);
495 if ((status
& IE_ST_WHENCE
) != 0)
500 (sc
->intrhook
)(sc
, INTR_EXIT
);
511 * Process a received-frame interrupt.
514 i82586_rint(struct ie_softc
*sc
, int scbstatus
)
516 static int timesthru
= 1024;
520 if (sc
->sc_debug
& IED_RINT
)
521 printf("%s: rint: status 0x%x\n",
522 device_xname(&sc
->sc_dev
), scbstatus
);
529 off
= IE_RFRAME_STATUS(sc
->rframes
, i
);
530 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
531 status
= sc
->ie_bus_read16(sc
, off
);
534 if (sc
->sc_debug
& IED_RINT
)
535 printf("%s: rint: frame(%d) status 0x%x\n",
536 device_xname(&sc
->sc_dev
), i
, status
);
538 if ((status
& IE_FD_COMPLETE
) == 0) {
539 if ((status
& IE_FD_OK
) != 0) {
540 printf("%s: rint: weird: ",
541 device_xname(&sc
->sc_dev
));
542 i82586_rx_errors(sc
, i
, status
);
545 if (--timesthru
== 0) {
546 /* Account the accumulated errors */
547 i82586_count_errors(sc
);
551 } else if ((status
& IE_FD_OK
) == 0) {
553 * If the chip is configured to automatically
554 * discard bad frames, the only reason we can
555 * get here is an "out-of-resource" condition.
557 i82586_rx_errors(sc
, i
, status
);
562 if ((status
& IE_FD_BUSY
) != 0)
563 printf("%s: rint: frame(%d) busy; status=0x%x\n",
564 device_xname(&sc
->sc_dev
), i
, status
);
569 * Advance the RFD list, since we're done with
573 /* Clear frame status */
574 sc
->ie_bus_write16(sc
, off
, 0);
576 /* Put fence at this frame (the head) */
577 off
= IE_RFRAME_LAST(sc
->rframes
, i
);
578 sc
->ie_bus_write16(sc
, off
, IE_FD_EOL
|IE_FD_SUSP
);
580 /* and clear RBD field */
581 off
= IE_RFRAME_BUFDESC(sc
->rframes
, i
);
582 sc
->ie_bus_write16(sc
, off
, 0xffff);
584 /* Remove fence from current tail */
585 off
= IE_RFRAME_LAST(sc
->rframes
, sc
->rftail
);
586 sc
->ie_bus_write16(sc
, off
, 0);
588 if (++sc
->rftail
== sc
->nframes
)
590 if (++sc
->rfhead
== sc
->nframes
)
593 /* Pull the frame off the board */
595 i82586_drop_frames(sc
);
596 if ((status
& IE_FD_RNR
) != 0)
598 sc
->sc_ethercom
.ec_if
.if_ierrors
++;
599 } else if (ie_readframe(sc
, i
) != 0)
603 if ((scbstatus
& IE_ST_RNR
) != 0) {
606 * Receiver went "Not Ready". We try to figure out
607 * whether this was an expected event based on past
608 * frame status values.
611 if ((scbstatus
& IE_RUS_SUSPEND
) != 0) {
613 * We use the "suspend on last frame" flag.
614 * Send a RU RESUME command in response, since
615 * we should have dealt with all completed frames
618 printf("RINT: SUSPENDED; scbstatus=0x%x\n",
620 if (i82586_start_cmd(sc
, IE_RUC_RESUME
, 0, 0, 0) == 0)
622 aprint_error_dev(&sc
->sc_dev
, "RU RESUME command timed out\n");
623 return (1); /* Ask for a reset */
626 if (sc
->rnr_expect
!= 0) {
628 * The RNR condition was announced in the previously
629 * completed frame. Assume the receive ring is Ok,
630 * so restart the receiver without further delay.
632 i82586_start_transceiver(sc
);
636 } else if ((scbstatus
& IE_RUS_NOSPACE
) != 0) {
638 * We saw no previous IF_FD_RNR flag.
639 * We check our ring invariants and, if ok,
640 * just restart the receiver at the current
643 if (i82586_chk_rx_ring(sc
) != 0)
646 i82586_start_transceiver(sc
);
647 sc
->sc_ethercom
.ec_if
.if_ierrors
++;
650 printf("%s: receiver not ready; scbstatus=0x%x\n",
651 device_xname(&sc
->sc_dev
), scbstatus
);
653 sc
->sc_ethercom
.ec_if
.if_ierrors
++;
654 return (1); /* Ask for a reset */
661 * Process a command-complete interrupt. These are only generated by the
662 * transmission of frames. This routine is deceptively simple, since most
663 * of the real work is done by i82586_start().
666 i82586_tint(struct ie_softc
*sc
, int scbstatus
)
668 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
672 ifp
->if_flags
&= ~IFF_OACTIVE
;
675 if (sc
->xmit_busy
<= 0) {
676 printf("i82586_tint: WEIRD: xmit_busy=%d, xctail=%d, xchead=%d\n",
677 sc
->xmit_busy
, sc
->xctail
, sc
->xchead
);
682 status
= sc
->ie_bus_read16(sc
, IE_CMD_XMIT_STATUS(sc
->xmit_cmds
,
686 if (sc
->sc_debug
& IED_TINT
)
687 printf("%s: tint: SCB status 0x%x; xmit status 0x%x\n",
688 device_xname(&sc
->sc_dev
), scbstatus
, status
);
691 if ((status
& IE_STAT_COMPL
) == 0 || (status
& IE_STAT_BUSY
)) {
692 printf("i82586_tint: command still busy; status=0x%x; tail=%d\n",
694 printf("iestatus = 0x%x\n", scbstatus
);
697 if (status
& IE_STAT_OK
) {
699 ifp
->if_collisions
+= (status
& IE_XS_MAXCOLL
);
703 * Check SQE and DEFERRED?
704 * What if more than one bit is set?
706 if (status
& IE_STAT_ABORT
)
707 aprint_error_dev(&sc
->sc_dev
, "send aborted\n");
708 else if (status
& IE_XS_NOCARRIER
)
709 aprint_error_dev(&sc
->sc_dev
, "no carrier\n");
710 else if (status
& IE_XS_LOSTCTS
)
711 aprint_error_dev(&sc
->sc_dev
, "lost CTS\n");
712 else if (status
& IE_XS_UNDERRUN
)
713 aprint_error_dev(&sc
->sc_dev
, "DMA underrun\n");
714 else if (status
& IE_XS_EXCMAX
) {
715 aprint_error_dev(&sc
->sc_dev
, "too many collisions\n");
716 sc
->sc_ethercom
.ec_if
.if_collisions
+= 16;
721 * If multicast addresses were added or deleted while transmitting,
722 * ie_mc_reset() set the want_mcsetup flag indicating that we
725 if (sc
->want_mcsetup
) {
726 ie_mc_setup(sc
, IE_XBUF_ADDR(sc
, sc
->xctail
));
727 sc
->want_mcsetup
= 0;
730 /* Done with the buffer. */
732 sc
->xctail
= (sc
->xctail
+ 1) % NTXBUF
;
734 /* Start the next packet, if any, transmitting. */
735 if (sc
->xmit_busy
> 0)
743 * Get a range of receive buffer descriptors that represent one packet.
746 i82586_get_rbd_list(struct ie_softc
*sc
, u_int16_t
*start
, u_int16_t
*end
, int *pktlen
)
748 int off
, rbbase
= sc
->rbds
;
749 int rbindex
, count
= 0;
753 *start
= rbindex
= sc
->rbhead
;
756 off
= IE_RBD_STATUS(rbbase
, rbindex
);
757 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
758 rbdstatus
= sc
->ie_bus_read16(sc
, off
);
759 if ((rbdstatus
& IE_RBD_USED
) == 0) {
761 * This means we are somehow out of sync. So, we
765 print_rbd(sc
, rbindex
);
768 "%s: receive descriptors out of sync at %d\n",
769 device_xname(&sc
->sc_dev
), rbindex
);
772 plen
+= (rbdstatus
& IE_RBD_CNTMASK
);
774 if (++rbindex
== sc
->nrxbuf
)
778 } while ((rbdstatus
& IE_RBD_LAST
) == 0);
786 * Release a range of receive buffer descriptors after we've copied the packet.
789 i82586_release_rbd_list(struct ie_softc
*sc
, u_int16_t start
, u_int16_t end
)
791 int off
, rbbase
= sc
->rbds
;
795 /* Clear buffer status */
796 off
= IE_RBD_STATUS(rbbase
, rbindex
);
797 sc
->ie_bus_write16(sc
, off
, 0);
798 if (++rbindex
== sc
->nrxbuf
)
800 } while (rbindex
!= end
);
802 /* Mark EOL at new tail */
803 rbindex
= ((rbindex
== 0) ? sc
->nrxbuf
: rbindex
) - 1;
804 off
= IE_RBD_BUFLEN(rbbase
, rbindex
);
805 sc
->ie_bus_write16(sc
, off
, IE_RBUF_SIZE
|IE_RBD_EOL
);
807 /* Remove EOL from current tail */
808 off
= IE_RBD_BUFLEN(rbbase
, sc
->rbtail
);
809 sc
->ie_bus_write16(sc
, off
, IE_RBUF_SIZE
);
811 /* New head & tail pointer */
812 /* hmm, why have both? head is always (tail + 1) % NRXBUF */
814 sc
->rbtail
= rbindex
;
818 * Drop the packet at the head of the RX buffer ring.
819 * Called if the frame descriptor reports an error on this packet.
820 * Returns 1 if the buffer descriptor ring appears to be corrupt;
824 i82586_drop_frames(struct ie_softc
*sc
)
826 u_int16_t bstart
, bend
;
829 if (i82586_get_rbd_list(sc
, &bstart
, &bend
, &pktlen
) == 0)
831 i82586_release_rbd_list(sc
, bstart
, bend
);
836 * Check the RX frame & buffer descriptor lists for our invariants,
837 * i.e.: EOL bit set iff. it is pointed at by the r*tail pointer.
839 * Called when the receive unit has stopped unexpectedly.
840 * Returns 1 if an inconsistency is detected; 0 otherwise.
842 * The Receive Unit is expected to be NOT RUNNING.
845 i82586_chk_rx_ring(struct ie_softc
*sc
)
849 for (n
= 0; n
< sc
->nrxbuf
; n
++) {
850 off
= IE_RBD_BUFLEN(sc
->rbds
, n
);
851 val
= sc
->ie_bus_read16(sc
, off
);
852 if ((n
== sc
->rbtail
) ^ ((val
& IE_RBD_EOL
) != 0)) {
853 /* `rbtail' and EOL flag out of sync */
855 "%s: rx buffer descriptors out of sync at %d\n",
856 device_xname(&sc
->sc_dev
), n
);
860 /* Take the opportunity to clear the status fields here ? */
863 for (n
= 0; n
< sc
->nframes
; n
++) {
864 off
= IE_RFRAME_LAST(sc
->rframes
, n
);
865 val
= sc
->ie_bus_read16(sc
, off
);
866 if ((n
== sc
->rftail
) ^ ((val
& (IE_FD_EOL
|IE_FD_SUSP
)) != 0)) {
867 /* `rftail' and EOL flag out of sync */
869 "%s: rx frame list out of sync at %d\n",
870 device_xname(&sc
->sc_dev
), n
);
879 * Read data off the interface, and turn it into an mbuf chain.
881 * This code is DRAMATICALLY different from the previous version; this
882 * version tries to allocate the entire mbuf chain up front, given the
883 * length of the data available. This enables us to allocate mbuf
884 * clusters in many situations where before we would have had a long
885 * chain of partially-full mbufs. This should help to speed up the
886 * operation considerably. (Provided that it works, of course.)
888 static inline struct mbuf
*
889 ieget(struct ie_softc
*sc
, int head
, int totlen
)
891 struct mbuf
*m
, *m0
, *newm
;
893 int thisrboff
, thismboff
;
894 struct ether_header eh
;
897 * Snarf the Ethernet header.
899 (sc
->memcopyin
)(sc
, &eh
, IE_RBUF_ADDR(sc
, head
),
900 sizeof(struct ether_header
));
904 MGETHDR(m0
, M_DONTWAIT
, MT_DATA
);
907 m0
->m_pkthdr
.rcvif
= &sc
->sc_ethercom
.ec_if
;
908 m0
->m_pkthdr
.len
= totlen
;
913 * This loop goes through and allocates mbufs for all the data we will
914 * be copying in. It does not actually do the copying yet.
917 if (totlen
>= MINCLSIZE
) {
918 MCLGET(m
, M_DONTWAIT
);
919 if ((m
->m_flags
& M_EXT
) == 0)
925 char *newdata
= (char *)
926 ALIGN(m
->m_data
+ sizeof(struct ether_header
)) -
927 sizeof(struct ether_header
);
928 len
-= newdata
- m
->m_data
;
932 m
->m_len
= len
= min(totlen
, len
);
936 MGET(newm
, M_DONTWAIT
, MT_DATA
);
940 m
= m
->m_next
= newm
;
948 * Copy the Ethernet header into the mbuf chain.
950 memcpy(mtod(m
, void *), &eh
, sizeof(struct ether_header
));
951 thismboff
= sizeof(struct ether_header
);
952 thisrboff
= sizeof(struct ether_header
);
953 resid
-= sizeof(struct ether_header
);
956 * Now we take the mbuf chain (hopefully only one mbuf most of the
957 * time) and stuff the data into it. There are no possible failures
958 * at or after this point.
961 int thisrblen
= IE_RBUF_SIZE
- thisrboff
,
962 thismblen
= m
->m_len
- thismboff
;
963 len
= min(thisrblen
, thismblen
);
965 (sc
->memcopyin
)(sc
, mtod(m
, char *) + thismboff
,
966 IE_RBUF_ADDR(sc
,head
) + thisrboff
,
970 if (len
== thismblen
) {
976 if (len
== thisrblen
) {
977 if (++head
== sc
->nrxbuf
)
985 * Unless something changed strangely while we were doing the copy,
986 * we have now copied everything in from the shared memory.
987 * This means that we are done.
997 * Read frame NUM from unit UNIT (pre-cached as IE).
999 * This routine reads the RFD at NUM, and copies in the buffers from the list
1000 * of RBD, then rotates the RBD list so that the receiver doesn't start
1001 * complaining. Trailers are DROPPED---there's no point in wasting time
1002 * on confusing code to deal with them. Hopefully, this machine will
1003 * never ARP for trailers anyway.
1007 struct ie_softc
*sc
,
1008 int num
) /* frame number to read */
1011 u_int16_t bstart
, bend
;
1014 if (i82586_get_rbd_list(sc
, &bstart
, &bend
, &pktlen
) == 0) {
1015 sc
->sc_ethercom
.ec_if
.if_ierrors
++;
1019 m
= ieget(sc
, bstart
, pktlen
);
1020 i82586_release_rbd_list(sc
, bstart
, bend
);
1023 sc
->sc_ethercom
.ec_if
.if_ierrors
++;
1028 if (sc
->sc_debug
& IED_READFRAME
) {
1029 struct ether_header
*eh
= mtod(m
, struct ether_header
*);
1031 printf("%s: frame from ether %s type 0x%x len %d\n",
1032 device_xname(&sc
->sc_dev
),
1033 ether_sprintf(eh
->ether_shost
),
1034 (u_int
)ntohs(eh
->ether_type
),
1040 /* Check for a BPF filter; if so, hand it up. */
1041 if (sc
->sc_ethercom
.ec_if
.if_bpf
!= 0)
1043 bpf_mtap(sc
->sc_ethercom
.ec_if
.if_bpf
, m
);
1044 #endif /* NBPFILTER > 0 */
1047 * Finally pass this packet up to higher layers.
1049 (*sc
->sc_ethercom
.ec_if
.if_input
)(&sc
->sc_ethercom
.ec_if
, m
);
1050 sc
->sc_ethercom
.ec_if
.if_ipackets
++;
1056 * Setup all necessary artifacts for an XMIT command, and then pass the XMIT
1057 * command to the chip to be executed.
1060 iexmit(struct ie_softc
*sc
)
1068 if (sc
->sc_debug
& IED_XMIT
)
1069 printf("%s: xmit buffer %d\n", device_xname(&sc
->sc_dev
), cur
);
1073 * Setup the transmit command.
1075 sc
->ie_bus_write16(sc
, IE_CMD_XMIT_DESC(sc
->xmit_cmds
, cur
),
1076 IE_XBD_ADDR(sc
->xbds
, cur
));
1078 sc
->ie_bus_write16(sc
, IE_CMD_XMIT_STATUS(sc
->xmit_cmds
, cur
), 0);
1080 if (sc
->do_xmitnopchain
) {
1082 * Gate this XMIT command to the following NOP
1084 sc
->ie_bus_write16(sc
, IE_CMD_XMIT_LINK(sc
->xmit_cmds
, cur
),
1085 IE_CMD_NOP_ADDR(sc
->nop_cmds
, cur
));
1086 sc
->ie_bus_write16(sc
, IE_CMD_XMIT_CMD(sc
->xmit_cmds
, cur
),
1087 IE_CMD_XMIT
| IE_CMD_INTR
);
1090 * Loopback at following NOP
1092 sc
->ie_bus_write16(sc
, IE_CMD_NOP_STATUS(sc
->nop_cmds
, cur
), 0);
1093 sc
->ie_bus_write16(sc
, IE_CMD_NOP_LINK(sc
->nop_cmds
, cur
),
1094 IE_CMD_NOP_ADDR(sc
->nop_cmds
, cur
));
1097 * Gate preceding NOP to this XMIT command
1099 prev
= (cur
+ NTXBUF
- 1) % NTXBUF
;
1100 sc
->ie_bus_write16(sc
, IE_CMD_NOP_STATUS(sc
->nop_cmds
, prev
), 0);
1101 sc
->ie_bus_write16(sc
, IE_CMD_NOP_LINK(sc
->nop_cmds
, prev
),
1102 IE_CMD_XMIT_ADDR(sc
->xmit_cmds
, cur
));
1104 off
= IE_SCB_STATUS(sc
->scb
);
1105 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
1106 if ((sc
->ie_bus_read16(sc
, off
) & IE_CUS_ACTIVE
) == 0) {
1107 printf("iexmit: CU not active\n");
1108 i82586_start_transceiver(sc
);
1111 sc
->ie_bus_write16(sc
, IE_CMD_XMIT_LINK(sc
->xmit_cmds
,cur
),
1114 sc
->ie_bus_write16(sc
, IE_CMD_XMIT_CMD(sc
->xmit_cmds
, cur
),
1115 IE_CMD_XMIT
| IE_CMD_INTR
| IE_CMD_LAST
);
1117 off
= IE_SCB_CMDLST(sc
->scb
);
1118 sc
->ie_bus_write16(sc
, off
, IE_CMD_XMIT_ADDR(sc
->xmit_cmds
, cur
));
1119 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
1121 if (i82586_start_cmd(sc
, IE_CUC_START
, 0, 0, 1))
1122 aprint_error_dev(&sc
->sc_dev
, "iexmit: start xmit command timed out\n");
1125 sc
->sc_ethercom
.ec_if
.if_timer
= 5;
1130 * Start transmission on an interface.
1133 i82586_start(struct ifnet
*ifp
)
1135 struct ie_softc
*sc
= ifp
->if_softc
;
1136 struct mbuf
*m0
, *m
;
1137 int buffer
, head
, xbase
;
1141 if ((ifp
->if_flags
& (IFF_RUNNING
| IFF_OACTIVE
)) != IFF_RUNNING
)
1145 if (sc
->xmit_busy
== NTXBUF
) {
1146 ifp
->if_flags
|= IFF_OACTIVE
;
1153 IFQ_DEQUEUE(&ifp
->if_snd
, m0
);
1157 /* We need to use m->m_pkthdr.len, so require the header */
1158 if ((m0
->m_flags
& M_PKTHDR
) == 0)
1159 panic("i82586_start: no header mbuf");
1162 /* Tap off here if there is a BPF listener. */
1164 bpf_mtap(ifp
->if_bpf
, m0
);
1168 if (sc
->sc_debug
& IED_ENQ
)
1169 printf("%s: fill buffer %d\n", device_xname(&sc
->sc_dev
),
1173 if (m0
->m_pkthdr
.len
> IE_TBUF_SIZE
)
1174 printf("%s: tbuf overflow\n", device_xname(&sc
->sc_dev
));
1176 buffer
= IE_XBUF_ADDR(sc
, head
);
1177 for (m
= m0
; m
!= 0; m
= m
->m_next
) {
1178 (sc
->memcopyout
)(sc
, mtod(m
,void *), buffer
, m
->m_len
);
1181 len
= m0
->m_pkthdr
.len
;
1182 if (len
< ETHER_MIN_LEN
- ETHER_CRC_LEN
) {
1183 (sc
->memcopyout
)(sc
, padbuf
, buffer
,
1184 ETHER_MIN_LEN
- ETHER_CRC_LEN
- len
);
1185 buffer
+= ETHER_MIN_LEN
-ETHER_CRC_LEN
- len
;
1186 len
= ETHER_MIN_LEN
- ETHER_CRC_LEN
;
1191 * Setup the transmit buffer descriptor here, while we
1192 * know the packet's length.
1194 sc
->ie_bus_write16(sc
, IE_XBD_FLAGS(xbase
, head
),
1196 sc
->ie_bus_write16(sc
, IE_XBD_NEXT(xbase
, head
), 0xffff);
1197 sc
->ie_bus_write24(sc
, IE_XBD_BUF(xbase
, head
),
1198 IE_XBUF_ADDR(sc
, head
));
1200 if (++head
== NTXBUF
)
1205 /* Start the first packet transmitting. */
1206 if (sc
->xmit_busy
== 0)
1215 * Probe IE's ram setup [ Move all this into MD front-end!? ]
1216 * Use only if SCP and ISCP represent offsets into shared ram space.
1219 i82586_proberam(struct ie_softc
*sc
)
1223 /* Put in 16-bit mode */
1224 off
= IE_SCP_BUS_USE(sc
->scp
);
1225 sc
->ie_bus_write16(sc
, off
, IE_SYSBUS_16BIT
);
1226 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_WRITE
);
1228 /* Set the ISCP `busy' bit */
1229 off
= IE_ISCP_BUSY(sc
->iscp
);
1230 sc
->ie_bus_write16(sc
, off
, 1);
1231 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_WRITE
);
1234 (sc
->hwreset
)(sc
, CHIP_PROBE
);
1236 (sc
->chan_attn
) (sc
, CHIP_PROBE
);
1238 delay(100); /* wait a while... */
1240 /* Read back the ISCP `busy' bit; it should be clear by now */
1241 off
= IE_ISCP_BUSY(sc
->iscp
);
1242 IE_BUS_BARRIER(sc
, off
, 2, BUS_SPACE_BARRIER_READ
);
1243 result
= sc
->ie_bus_read16(sc
, off
) == 0;
1245 /* Acknowledge any interrupts we may have caused. */
1246 ie_ack(sc
, IE_ST_WHENCE
);
1252 i82586_reset(struct ie_softc
*sc
, int hard
)
1257 printf("%s: reset\n", device_xname(&sc
->sc_dev
));
1259 /* Clear OACTIVE in case we're called from watchdog (frozen xmit). */
1260 sc
->sc_ethercom
.ec_if
.if_timer
= 0;
1261 sc
->sc_ethercom
.ec_if
.if_flags
&= ~IFF_OACTIVE
;
1264 * Stop i82586 dead in its tracks.
1266 if (i82586_start_cmd(sc
, IE_RUC_ABORT
| IE_CUC_ABORT
, 0, 0, 0))
1267 aprint_error_dev(&sc
->sc_dev
, "abort commands timed out\n");
1270 * This can really slow down the i82586_reset() on some cards, but it's
1271 * necessary to unwedge other ones (eg, the Sun VME ones) from certain
1274 if (hard
&& sc
->hwreset
)
1275 (sc
->hwreset
)(sc
, CARD_RESET
);
1278 ie_ack(sc
, IE_ST_WHENCE
);
1280 if ((sc
->sc_ethercom
.ec_if
.if_flags
& IFF_UP
) != 0) {
1281 int retries
=0; /* XXX - find out why init sometimes fails */
1282 while (retries
++ < 2)
1283 if (i82586_init(&sc
->sc_ethercom
.ec_if
) == 0)
1292 setup_simple_command(struct ie_softc
*sc
, int cmd
, int cmdbuf
)
1294 /* Setup a simple command */
1295 sc
->ie_bus_write16(sc
, IE_CMD_COMMON_STATUS(cmdbuf
), 0);
1296 sc
->ie_bus_write16(sc
, IE_CMD_COMMON_CMD(cmdbuf
), cmd
| IE_CMD_LAST
);
1297 sc
->ie_bus_write16(sc
, IE_CMD_COMMON_LINK(cmdbuf
), 0xffff);
1299 /* Assign the command buffer to the SCB command list */
1300 sc
->ie_bus_write16(sc
, IE_SCB_CMDLST(sc
->scb
), cmdbuf
);
1304 * Run the time-domain reflectometer.
1307 ie_run_tdr(struct ie_softc
*sc
, int cmd
)
1311 setup_simple_command(sc
, IE_CMD_TDR
, cmd
);
1312 sc
->ie_bus_write16(sc
, IE_CMD_TDR_TIME(cmd
), 0);
1314 if (i82586_start_cmd(sc
, IE_CUC_START
, cmd
, IE_STAT_COMPL
, 0) ||
1315 (sc
->ie_bus_read16(sc
, IE_CMD_COMMON_STATUS(cmd
)) & IE_STAT_OK
) == 0)
1316 result
= 0x10000; /* XXX */
1318 result
= sc
->ie_bus_read16(sc
, IE_CMD_TDR_TIME(cmd
));
1320 /* Squash any pending interrupts */
1321 ie_ack(sc
, IE_ST_WHENCE
);
1323 if (result
& IE_TDR_SUCCESS
)
1326 if (result
& 0x10000)
1327 aprint_error_dev(&sc
->sc_dev
, "TDR command failed\n");
1328 else if (result
& IE_TDR_XCVR
)
1329 aprint_error_dev(&sc
->sc_dev
, "transceiver problem\n");
1330 else if (result
& IE_TDR_OPEN
)
1331 aprint_error_dev(&sc
->sc_dev
, "TDR detected incorrect termination %d clocks away\n",
1332 result
& IE_TDR_TIME
);
1333 else if (result
& IE_TDR_SHORT
)
1334 aprint_error_dev(&sc
->sc_dev
, "TDR detected a short circuit %d clocks away\n",
1335 result
& IE_TDR_TIME
);
1337 aprint_error_dev(&sc
->sc_dev
, "TDR returned unknown status 0x%x\n",
1343 * i82586_setup_bufs: set up the buffers
1345 * We have a block of KVA at sc->buf_area which is of size sc->buf_area_sz.
1346 * this is to be used for the buffers. The chip indexs its control data
1347 * structures with 16 bit offsets, and it indexes actual buffers with
1348 * 24 bit addresses. So we should allocate control buffers first so that
1349 * we don't overflow the 16 bit offset field. The number of transmit
1350 * buffers is fixed at compile time.
1354 i82586_setup_bufs(struct ie_softc
*sc
)
1356 int ptr
= sc
->buf_area
; /* memory pool */
1360 * step 0: zero memory and figure out how many recv buffers and
1361 * frames we can have.
1363 ptr
= (ptr
+ 3) & ~3; /* set alignment and stick with it */
1367 * step 1: lay out data structures in the shared-memory area
1370 /* The no-op commands; used if "nop-chaining" is in effect */
1372 ptr
+= NTXBUF
* IE_CMD_NOP_SZ
;
1374 /* The transmit commands */
1375 sc
->xmit_cmds
= ptr
;
1376 ptr
+= NTXBUF
* IE_CMD_XMIT_SZ
;
1378 /* The transmit buffers descriptors */
1380 ptr
+= NTXBUF
* IE_XBD_SZ
;
1382 /* The transmit buffers */
1384 ptr
+= NTXBUF
* IE_TBUF_SIZE
;
1386 ptr
= (ptr
+ 3) & ~3; /* re-align.. just in case */
1388 /* Compute free space for RECV stuff */
1389 n
= sc
->buf_area_sz
- (ptr
- sc
->buf_area
);
1391 /* Compute size of one RECV frame */
1392 r
= IE_RFRAME_SZ
+ ((IE_RBD_SZ
+ IE_RBUF_SIZE
) * B_PER_F
);
1394 sc
->nframes
= n
/ r
;
1396 if (sc
->nframes
<= 0)
1397 panic("ie: bogus buffer calc");
1399 sc
->nrxbuf
= sc
->nframes
* B_PER_F
;
1401 /* The receive frame descriptors */
1403 ptr
+= sc
->nframes
* IE_RFRAME_SZ
;
1405 /* The receive buffer descriptors */
1407 ptr
+= sc
->nrxbuf
* IE_RBD_SZ
;
1409 /* The receive buffers */
1411 ptr
+= sc
->nrxbuf
* IE_RBUF_SIZE
;
1414 printf("%s: %d frames %d bufs\n", device_xname(&sc
->sc_dev
), sc
->nframes
,
1419 * step 2: link together the recv frames and set EOL on last one
1421 for (n
= 0; n
< sc
->nframes
; n
++) {
1422 int m
= (n
== sc
->nframes
- 1) ? 0 : n
+ 1;
1425 sc
->ie_bus_write16(sc
, IE_RFRAME_STATUS(sc
->rframes
,n
), 0);
1427 /* RBD link = NULL */
1428 sc
->ie_bus_write16(sc
, IE_RFRAME_BUFDESC(sc
->rframes
,n
),
1431 /* Make a circular list */
1432 sc
->ie_bus_write16(sc
, IE_RFRAME_NEXT(sc
->rframes
,n
),
1433 IE_RFRAME_ADDR(sc
->rframes
,m
));
1435 /* Mark last as EOL */
1436 sc
->ie_bus_write16(sc
, IE_RFRAME_LAST(sc
->rframes
,n
),
1437 ((m
==0)? (IE_FD_EOL
|IE_FD_SUSP
) : 0));
1441 * step 3: link the RBDs and set EOL on last one
1443 for (n
= 0; n
< sc
->nrxbuf
; n
++) {
1444 int m
= (n
== sc
->nrxbuf
- 1) ? 0 : n
+ 1;
1447 sc
->ie_bus_write16(sc
, IE_RBD_STATUS(sc
->rbds
,n
), 0);
1449 /* Make a circular list */
1450 sc
->ie_bus_write16(sc
, IE_RBD_NEXT(sc
->rbds
,n
),
1451 IE_RBD_ADDR(sc
->rbds
,m
));
1453 /* Link to data buffers */
1454 sc
->ie_bus_write24(sc
, IE_RBD_BUFADDR(sc
->rbds
, n
),
1455 IE_RBUF_ADDR(sc
, n
));
1456 sc
->ie_bus_write16(sc
, IE_RBD_BUFLEN(sc
->rbds
,n
),
1457 IE_RBUF_SIZE
| ((m
==0)?IE_RBD_EOL
:0));
1461 * step 4: all xmit no-op commands loopback onto themselves
1463 for (n
= 0; n
< NTXBUF
; n
++) {
1464 sc
->ie_bus_write16(sc
, IE_CMD_NOP_STATUS(sc
->nop_cmds
, n
), 0);
1466 sc
->ie_bus_write16(sc
, IE_CMD_NOP_CMD(sc
->nop_cmds
, n
),
1469 sc
->ie_bus_write16(sc
, IE_CMD_NOP_LINK(sc
->nop_cmds
, n
),
1470 IE_CMD_NOP_ADDR(sc
->nop_cmds
, n
));
1475 * step 6: set the head and tail pointers on receive to keep track of
1476 * the order in which RFDs and RBDs are used.
1479 /* Pointers to last packet sent and next available transmit buffer. */
1480 sc
->xchead
= sc
->xctail
= 0;
1482 /* Clear transmit-busy flag and set number of free transmit buffers. */
1486 * Pointers to first and last receive frame.
1487 * The RFD pointed to by rftail is the only one that has EOL set.
1490 sc
->rftail
= sc
->nframes
- 1;
1493 * Pointers to first and last receive descriptor buffer.
1494 * The RBD pointed to by rbtail is the only one that has EOL set.
1497 sc
->rbtail
= sc
->nrxbuf
- 1;
1499 /* link in recv frames * and buffer into the scb. */
1501 printf("%s: reserved %d bytes\n",
1502 device_xname(&sc
->sc_dev
), ptr
- sc
->buf_area
);
1507 ie_cfg_setup(struct ie_softc
*sc
, int cmd
, int promiscuous
, int manchester
)
1509 int cmdresult
, status
;
1510 u_int8_t buf
[IE_CMD_CFG_SZ
]; /* XXX malloc? */
1512 *IE_CMD_CFG_CNT(buf
) = 0x0c;
1513 *IE_CMD_CFG_FIFO(buf
) = 8;
1514 *IE_CMD_CFG_SAVEBAD(buf
) = 0x40;
1515 *IE_CMD_CFG_ADDRLEN(buf
) = 0x2e;
1516 *IE_CMD_CFG_PRIORITY(buf
) = 0;
1517 *IE_CMD_CFG_IFS(buf
) = 0x60;
1518 *IE_CMD_CFG_SLOT_LOW(buf
) = 0;
1519 *IE_CMD_CFG_SLOT_HIGH(buf
) = 0xf2;
1520 *IE_CMD_CFG_PROMISC(buf
) = !!promiscuous
| manchester
<< 2;
1521 *IE_CMD_CFG_CRSCDT(buf
) = 0;
1522 *IE_CMD_CFG_MINLEN(buf
) = 64;
1523 *IE_CMD_CFG_JUNK(buf
) = 0xff;
1524 sc
->memcopyout(sc
, buf
, cmd
, IE_CMD_CFG_SZ
);
1525 setup_simple_command(sc
, IE_CMD_CONFIG
, cmd
);
1526 IE_BUS_BARRIER(sc
, cmd
, IE_CMD_CFG_SZ
, BUS_SPACE_BARRIER_WRITE
);
1528 cmdresult
= i82586_start_cmd(sc
, IE_CUC_START
, cmd
, IE_STAT_COMPL
, 0);
1529 status
= sc
->ie_bus_read16(sc
, IE_CMD_COMMON_STATUS(cmd
));
1530 if (cmdresult
!= 0) {
1531 aprint_error_dev(&sc
->sc_dev
, "configure command timed out; status %x\n", status
);
1534 if ((status
& IE_STAT_OK
) == 0) {
1535 aprint_error_dev(&sc
->sc_dev
, "configure command failed; status %x\n", status
);
1539 /* Squash any pending interrupts */
1540 ie_ack(sc
, IE_ST_WHENCE
);
1545 ie_ia_setup(struct ie_softc
*sc
, int cmdbuf
)
1547 int cmdresult
, status
;
1548 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
1550 setup_simple_command(sc
, IE_CMD_IASETUP
, cmdbuf
);
1552 (sc
->memcopyout
)(sc
, CLLADDR(ifp
->if_sadl
),
1553 IE_CMD_IAS_EADDR(cmdbuf
), ETHER_ADDR_LEN
);
1555 cmdresult
= i82586_start_cmd(sc
, IE_CUC_START
, cmdbuf
, IE_STAT_COMPL
, 0);
1556 status
= sc
->ie_bus_read16(sc
, IE_CMD_COMMON_STATUS(cmdbuf
));
1557 if (cmdresult
!= 0) {
1558 aprint_error_dev(&sc
->sc_dev
, "individual address command timed out; status %x\n", status
);
1561 if ((status
& IE_STAT_OK
) == 0) {
1562 aprint_error_dev(&sc
->sc_dev
, "individual address command failed; status %x\n", status
);
1566 /* Squash any pending interrupts */
1567 ie_ack(sc
, IE_ST_WHENCE
);
1572 * Run the multicast setup command.
1573 * Called at splnet().
1576 ie_mc_setup(struct ie_softc
*sc
, int cmdbuf
)
1578 int cmdresult
, status
;
1580 if (sc
->mcast_count
== 0)
1583 setup_simple_command(sc
, IE_CMD_MCAST
, cmdbuf
);
1585 (sc
->memcopyout
)(sc
, (void *)sc
->mcast_addrs
,
1586 IE_CMD_MCAST_MADDR(cmdbuf
),
1587 sc
->mcast_count
* ETHER_ADDR_LEN
);
1589 sc
->ie_bus_write16(sc
, IE_CMD_MCAST_BYTES(cmdbuf
),
1590 sc
->mcast_count
* ETHER_ADDR_LEN
);
1592 /* Start the command */
1593 cmdresult
= i82586_start_cmd(sc
, IE_CUC_START
, cmdbuf
, IE_STAT_COMPL
, 0);
1594 status
= sc
->ie_bus_read16(sc
, IE_CMD_COMMON_STATUS(cmdbuf
));
1595 if (cmdresult
!= 0) {
1596 aprint_error_dev(&sc
->sc_dev
, "multicast setup command timed out; status %x\n", status
);
1599 if ((status
& IE_STAT_OK
) == 0) {
1600 aprint_error_dev(&sc
->sc_dev
, "multicast setup command failed; status %x\n",
1605 /* Squash any pending interrupts */
1606 ie_ack(sc
, IE_ST_WHENCE
);
1611 * This routine takes the environment generated by check_ie_present() and adds
1612 * to it all the other structures we need to operate the adapter. This
1613 * includes executing the CONFIGURE, IA-SETUP, and MC-SETUP commands, starting
1614 * the receiver unit, and clearing interrupts.
1616 * THIS ROUTINE MUST BE CALLED AT splnet() OR HIGHER.
1619 i82586_init(struct ifnet
*ifp
)
1621 struct ie_softc
*sc
= ifp
->if_softc
;
1624 sc
->async_cmd_inprogress
= 0;
1629 * Send the configure command first.
1631 if (ie_cfg_setup(sc
, cmd
, sc
->promisc
, 0) == 0)
1635 * Send the Individual Address Setup command.
1637 if (ie_ia_setup(sc
, cmd
) == 0)
1641 * Run the time-domain reflectometer.
1643 ie_run_tdr(sc
, cmd
);
1646 * Set the multi-cast filter, if any
1648 if (ie_mc_setup(sc
, cmd
) == 0)
1652 * Acknowledge any interrupts we have generated thus far.
1654 ie_ack(sc
, IE_ST_WHENCE
);
1657 * Set up the transmit and recv buffers.
1659 i82586_setup_bufs(sc
);
1664 ifp
->if_flags
|= IFF_RUNNING
;
1665 ifp
->if_flags
&= ~IFF_OACTIVE
;
1668 sc
->do_xmitnopchain
= 0;
1670 i82586_start_transceiver(sc
);
1675 * Start the RU and possibly the CU unit
1678 i82586_start_transceiver(struct ie_softc
*sc
)
1682 * Start RU at current position in frame & RBD lists.
1684 sc
->ie_bus_write16(sc
, IE_RFRAME_BUFDESC(sc
->rframes
,sc
->rfhead
),
1685 IE_RBD_ADDR(sc
->rbds
, sc
->rbhead
));
1687 sc
->ie_bus_write16(sc
, IE_SCB_RCVLST(sc
->scb
),
1688 IE_RFRAME_ADDR(sc
->rframes
,sc
->rfhead
));
1690 if (sc
->do_xmitnopchain
) {
1691 /* Stop transmit command chain */
1692 if (i82586_start_cmd(sc
, IE_CUC_SUSPEND
|IE_RUC_SUSPEND
, 0, 0, 0))
1693 aprint_error_dev(&sc
->sc_dev
, "CU/RU stop command timed out\n");
1695 /* Start the receiver & transmitter chain */
1696 /* sc->scb->ie_command_list =
1697 IEADDR(sc->nop_cmds[(sc->xctail+NTXBUF-1) % NTXBUF]);*/
1698 sc
->ie_bus_write16(sc
, IE_SCB_CMDLST(sc
->scb
),
1701 (sc
->xctail
+ NTXBUF
- 1) % NTXBUF
));
1703 if (i82586_start_cmd(sc
, IE_CUC_START
|IE_RUC_START
, 0, 0, 0))
1704 aprint_error_dev(&sc
->sc_dev
, "CU/RU command timed out\n");
1706 if (i82586_start_cmd(sc
, IE_RUC_START
, 0, 0, 0))
1707 aprint_error_dev(&sc
->sc_dev
, "RU command timed out\n");
1716 struct ie_softc
*sc
= ifp
->if_softc
;
1718 if (i82586_start_cmd(sc
, IE_RUC_SUSPEND
| IE_CUC_SUSPEND
, 0, 0, 0))
1719 aprint_error_dev(&sc
->sc_dev
, "iestop: disable commands timed out\n");
1723 i82586_ioctl(struct ifnet
*ifp
, unsigned long cmd
, void *data
)
1725 struct ie_softc
*sc
= ifp
->if_softc
;
1726 struct ifreq
*ifr
= (struct ifreq
*)data
;
1733 error
= ifmedia_ioctl(ifp
, ifr
, &sc
->sc_media
, cmd
);
1736 error
= ether_ioctl(ifp
, cmd
, data
);
1737 if (error
== ENETRESET
) {
1739 * Multicast list has changed; set the hardware filter
1742 if (ifp
->if_flags
& IFF_RUNNING
)
1749 if (cmd
== SIOCSIFFLAGS
)
1750 sc
->sc_debug
= (ifp
->if_flags
& IFF_DEBUG
) ? IED_ALL
: 0;
1757 ie_mc_reset(struct ie_softc
*sc
)
1759 struct ether_multi
*enm
;
1760 struct ether_multistep step
;
1764 * Step through the list of addresses.
1768 sc
->mcast_count
= 0;
1769 ETHER_FIRST_MULTI(step
, &sc
->sc_ethercom
, enm
);
1772 if (sc
->mcast_count
>= IE_MAXMCAST
||
1773 memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, 6) != 0) {
1774 sc
->sc_ethercom
.ec_if
.if_flags
|= IFF_ALLMULTI
;
1775 i82586_ioctl(&sc
->sc_ethercom
.ec_if
,
1776 SIOCSIFFLAGS
, NULL
);
1779 ETHER_NEXT_MULTI(step
, enm
);
1782 if (size
> sc
->mcast_addrs_size
) {
1783 /* Need to allocate more space */
1784 if (sc
->mcast_addrs_size
)
1785 free(sc
->mcast_addrs
, M_IFMADDR
);
1786 sc
->mcast_addrs
= (char *)
1787 malloc(size
, M_IFMADDR
, M_WAITOK
);
1788 sc
->mcast_addrs_size
= size
;
1792 * We've got the space; now copy the addresses
1794 ETHER_FIRST_MULTI(step
, &sc
->sc_ethercom
, enm
);
1796 if (sc
->mcast_count
>= IE_MAXMCAST
)
1797 goto again
; /* Just in case */
1799 memcpy(&sc
->mcast_addrs
[sc
->mcast_count
], enm
->enm_addrlo
, 6);
1801 ETHER_NEXT_MULTI(step
, enm
);
1803 sc
->want_mcsetup
= 1;
1807 * Media change callback.
1810 i82586_mediachange(struct ifnet
*ifp
)
1812 struct ie_softc
*sc
= ifp
->if_softc
;
1814 if (sc
->sc_mediachange
)
1815 return ((*sc
->sc_mediachange
)(sc
));
1820 * Media status callback.
1823 i82586_mediastatus(struct ifnet
*ifp
, struct ifmediareq
*ifmr
)
1825 struct ie_softc
*sc
= ifp
->if_softc
;
1827 if (sc
->sc_mediastatus
)
1828 (*sc
->sc_mediastatus
)(sc
, ifmr
);
1833 print_rbd(struct ie_softc
*sc
, int n
)
1836 printf("RBD at %08x:\n status %04x, next %04x, buffer %lx\n"
1837 "length/EOL %04x\n", IE_RBD_ADDR(sc
->rbds
,n
),
1838 sc
->ie_bus_read16(sc
, IE_RBD_STATUS(sc
->rbds
,n
)),
1839 sc
->ie_bus_read16(sc
, IE_RBD_NEXT(sc
->rbds
,n
)),
1840 (u_long
)0,/*bus_space_read_4(sc->bt, sc->bh, IE_RBD_BUFADDR(sc->rbds,n)),-* XXX */
1841 sc
->ie_bus_read16(sc
, IE_RBD_BUFLEN(sc
->rbds
,n
)));