2 * Copyright (c) 1992, 1993, University of Vermont and State
3 * Agricultural College.
4 * Copyright (c) 1992, 1993, Garrett A. Wollman.
7 * Copyright (c) 1990, 1991, William F. Jolitz
8 * Copyright (c) 1990, The Regents of the University of California
11 * Copyright (c) 1993, 1994, Charles M. Hannum
13 * EtherExpress 16 support:
14 * Copyright (c) 1993, 1994, 1995, Rodney W. Grimes
15 * Copyright (c) 1997, Aaron C. Smith
17 * All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 * 3. All advertising materials mentioning features or use of this software
28 * must display the following acknowledgement:
29 * This product includes software developed by the University of
30 * Vermont and State Agricultural College and Garrett A. Wollman, by
31 * William F. Jolitz, by the University of California, Berkeley,
32 * Lawrence Berkeley Laboratory, and their contributors, by
33 * Charles M. Hannum, by Rodney W. Grimes, and by Aaron C. Smith.
34 * 4. Neither the names of the Universities nor the names of the authors
35 * may be used to endorse or promote products derived from this software
36 * without specific prior written permission.
38 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR AUTHORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * MAINTAINER: Matthew N. Dodd <winter@jurai.net>
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
57 * Intel 82586 Ethernet chip
58 * Register, bit, and structure definitions.
60 * Written by GAW with reference to the Clarkson Packet Driver code for this
61 * chip written by Russ Nelson and others.
63 * Intel EtherExpress 16 support from if_ix.c, written by Rodney W. Grimes.
67 * The i82586 is a very versatile chip, found in many implementations.
68 * Programming this chip is mostly the same, but certain details differ
69 * from card to card. This driver is written so that different cards
70 * can be automatically detected at run-time.
76 * We run the 82586 in a standard Ethernet mode. We keep NFRAMES
77 * received frame descriptors around for the receiver to use, and
78 * NRXBUFS associated receive buffer descriptors, both in a circular
79 * list. Whenever a frame is received, we rotate both lists as
80 * necessary. (The 586 treats both lists as a simple queue.) We also
81 * keep a transmit command around so that packets can be sent off
84 * We configure the adapter in AL-LOC = 1 mode, which means that the
85 * Ethernet/802.3 MAC header is placed at the beginning of the receive
86 * buffer rather than being split off into various fields in the RFD.
87 * This also means that we must include this header in the transmit
90 * By convention, all transmit commands, and only transmit commands,
91 * shall have the I (IE_CMD_INTR) bit set in the command. This way,
92 * when an interrupt arrives at ieintr(), it is immediately possible
93 * to tell what precisely caused it. ANY OTHER command-sending routines
94 * should run at splimp(), and should post an acknowledgement to every
95 * interrupt they generate.
97 * The 82586 has a 24-bit address space internally, and the adaptor's
98 * memory is located at the top of this region. However, the value
99 * we are given in configuration is normally the *bottom* of the adaptor
100 * RAM. So, we must go through a few gyrations to come up with a
101 * kernel virtual address which represents the actual beginning of the
102 * 586 address space. First, we autosize the RAM by running through
103 * several possible sizes and trying to initialize the adapter under
104 * the assumption that the selected size is correct. Then, knowing
105 * the correct RAM size, we set up our pointers in the softc `iomem'
106 * represents the computed base of the 586 address space. `iomembot'
107 * represents the actual configured base of adapter RAM. Finally,
108 * `iosize' represents the calculated size of 586 RAM. Then, when
109 * laying out commands, we use the interval [iomembot, iomembot +
110 * iosize); to make 24-pointers, we subtract iomem, and to make
111 * 16-pointers, we subtract iomem and and with 0xffff.
114 #include <sys/param.h>
115 #include <sys/systm.h>
116 #include <sys/eventhandler.h>
117 #include <sys/kernel.h>
118 #include <sys/malloc.h>
119 #include <sys/mbuf.h>
120 #include <sys/socket.h>
121 #include <sys/sockio.h>
122 #include <sys/syslog.h>
124 #include <sys/module.h>
127 #include <machine/bus.h>
128 #include <machine/resource.h>
129 #include <sys/rman.h>
131 #include <net/ethernet.h>
133 #include <net/if_types.h>
134 #include <net/if_dl.h>
136 #include <netinet/in.h>
137 #include <netinet/if_ether.h>
139 #include <dev/ic/i82586.h>
140 #include <dev/ie/if_ievar.h>
141 #include <dev/ie/if_iereg.h>
142 #include <dev/ie/if_ie507.h>
143 #include <dev/ie/if_iee16.h>
144 #include <i386/isa/elink.h>
149 #define IED_RINT 0x01
150 #define IED_TINT 0x02
153 #define IED_READFRAME 0x10
154 static int ie_debug = IED_RNR;
158 #define IE_BUF_LEN ETHER_MAX_LEN /* length of transmit buffer */
160 /* Forward declaration */
163 static void ieinit (void *);
164 static void ieinit_locked (struct ie_softc *);
165 static void ie_stop (struct ie_softc *);
166 static int ieioctl (struct ifnet *, u_long, caddr_t);
167 static void iestart (struct ifnet *);
168 static void iestart_locked (struct ifnet *);
171 ee16_interrupt_enable (struct ie_softc *);
172 static void ee16_eeprom_outbits (struct ie_softc *, int, int);
173 static void ee16_eeprom_clock (struct ie_softc *, int);
174 static u_short ee16_read_eeprom (struct ie_softc *, int);
175 static int ee16_eeprom_inbits (struct ie_softc *);
178 ie_ack (struct ie_softc *, u_int);
179 static void iereset (struct ie_softc *);
180 static void ie_readframe (struct ie_softc *, int);
181 static void ie_drop_packet_buffer (struct ie_softc *);
182 static void find_ie_mem_size (struct ie_softc *);
183 static int command_and_wait (struct ie_softc *,
184 int, void volatile *, int);
185 static void run_tdr (struct ie_softc *,
186 volatile struct ie_tdr_cmd *);
187 static int ierint (struct ie_softc *);
188 static int ietint (struct ie_softc *);
189 static int iernr (struct ie_softc *);
190 static void start_receiver (struct ie_softc *);
192 ieget (struct ie_softc *, struct mbuf **);
193 static v_caddr_t setup_rfa (struct ie_softc *, v_caddr_t);
194 static int mc_setup (struct ie_softc *);
195 static void ie_mc_reset (struct ie_softc *);
198 static void print_rbd (volatile struct ie_recv_buf_desc * rbd);
199 static int in_ierint = 0;
200 static int in_ietint = 0;
203 static const char *ie_hardware_names[] = {
215 * sizeof(iscp) == 1+1+2+4 == 8
216 * sizeof(scb) == 2+2+2+2+2+2+2+2 == 16
217 * NFRAMES * sizeof(rfd) == NFRAMES*(2+2+2+2+6+6+2+2) == NFRAMES*24 == 384
218 * sizeof(xmit_cmd) == 2+2+2+2+6+2 == 18
219 * sizeof(transmit buffer) == 1512
220 * sizeof(transmit buffer desc) == 8
224 * NRXBUFS * sizeof(rbd) == NRXBUFS*(2+2+4+2+2) == NRXBUFS*12
225 * NRXBUFS * IE_RBUF_SIZE == NRXBUFS*256
227 * NRXBUFS should be (16384 - 1946) / (256 + 12) == 14438 / 268 == 53
229 * With NRXBUFS == 48, this leaves us 1574 bytes for another command or
230 * more buffers. Another transmit command would be 18+8+1512 == 1538
231 * ---just barely fits!
233 * Obviously all these would have to be reduced for smaller memory sizes.
234 * With a larger memory, it would be possible to roughly double the number
235 * of both transmit and receive buffers.
238 #define NFRAMES 4 /* number of receive frames */
239 #define NRXBUFS 24 /* number of buffers to allocate */
240 #define IE_RBUF_SIZE 256 /* size of each buffer, MUST BE POWER OF TWO */
241 #define NTXBUFS 1 /* number of transmit commands */
242 #define IE_TBUF_SIZE ETHER_MAX_LEN /* size of transmit buffer */
244 #define MK_24(base, ptr) ((caddr_t)((uintptr_t)ptr - (uintptr_t)base))
245 #define MK_16(base, ptr) ((u_short)(uintptr_t)MK_24(base, ptr))
248 ee16_shutdown(struct ie_softc *sc)
252 outb(PORT(sc) + IEE16_ECTRL, IEE16_RESET_ASIC);
253 outb(PORT(sc) + IEE16_ECTRL, 0);
257 * Taken almost exactly from Bill's if_is.c, then modified beyond recognition.
260 ie_attach(device_t dev)
262 struct ie_softc * sc;
267 sc = device_get_softc(dev);
268 ifp = sc->ifp = if_alloc(IFT_ETHER);
270 device_printf(sc->dev, "can not if_alloc()\n");
275 mtx_init(&sc->lock, device_get_nameunit(dev), MTX_NETWORK_LOCK,
279 * based on the amount of memory we have, allocate our tx and rx
282 factor = rman_get_size(sc->mem_res) / 8192;
283 sc->nframes = factor * NFRAMES;
284 sc->nrxbufs = factor * NRXBUFS;
285 sc->ntxbufs = factor * NTXBUFS;
288 * Since all of these guys are arrays of pointers, allocate as one
289 * big chunk and dole out accordingly.
291 allocsize = sizeof(void *) * (sc->nframes
293 + (sc->ntxbufs * 3));
294 sc->rframes = (volatile struct ie_recv_frame_desc **) malloc(allocsize,
297 if (sc->rframes == NULL) {
298 mtx_destroy(&sc->lock);
302 (volatile struct ie_recv_buf_desc **)&sc->rframes[sc->nframes];
303 sc->cbuffs = (volatile u_char **)&sc->rbuffs[sc->nrxbufs];
305 (volatile struct ie_xmit_cmd **)&sc->cbuffs[sc->nrxbufs];
307 (volatile struct ie_xmit_buf **)&sc->xmit_cmds[sc->ntxbufs];
308 sc->xmit_cbuffs = (volatile u_char **)&sc->xmit_buffs[sc->ntxbufs];
311 device_printf(sc->dev, "hardware type %s, revision %d\n",
312 ie_hardware_names[sc->hard_type], sc->hard_vers + 1);
315 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
316 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
317 ifp->if_start = iestart;
318 ifp->if_ioctl = ieioctl;
319 ifp->if_init = ieinit;
320 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
322 ether_ifattach(ifp, sc->enaddr);
324 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
325 NULL, ie_intr, sc, &sc->irq_ih);
327 device_printf(dev, "Unable to register interrupt handler\n");
328 mtx_destroy(&sc->lock);
336 ie_ack(struct ie_softc *sc, u_int mask)
339 sc->scb->ie_command = sc->scb->ie_status & mask;
340 (*sc->ie_chan_attn) (sc);
344 * What to do upon receipt of an interrupt.
349 struct ie_softc *sc = (struct ie_softc *)xsc;
354 /* Clear the interrupt latch on the 3C507. */
355 if (sc->hard_type == IE_3C507
356 && (inb(PORT(sc) + IE507_CTRL) & EL_CTRL_INTL))
357 outb(PORT(sc) + IE507_ICTRL, 1);
359 /* disable interrupts on the EE16. */
360 if (sc->hard_type == IE_EE16)
361 outb(PORT(sc) + IEE16_IRQ, sc->irq_encoded);
363 status = sc->scb->ie_status;
367 /* Don't ack interrupts which we didn't receive */
368 ie_ack(sc, IE_ST_WHENCE & status);
370 if (status & (IE_ST_RECV | IE_ST_RNR)) {
373 if (ie_debug & IED_RINT)
374 if_printf(sc->ifp, "rint\n");
381 if (status & IE_ST_DONE) {
384 if (ie_debug & IED_TINT)
385 if_printf(sc->ifp, "tint\n");
392 if (status & IE_ST_RNR) {
394 if (ie_debug & IED_RNR)
395 if_printf(sc->ifp, "rnr\n");
400 if ((status & IE_ST_ALLDONE) && (ie_debug & IED_CNA))
401 if_printf(sc->ifp, "cna\n");
404 if ((status = sc->scb->ie_status) & IE_ST_WHENCE)
407 /* Clear the interrupt latch on the 3C507. */
408 if (sc->hard_type == IE_3C507)
409 outb(PORT(sc) + IE507_ICTRL, 1);
411 /* enable interrupts on the EE16. */
412 if (sc->hard_type == IE_EE16)
413 outb(PORT(sc) + IEE16_IRQ, sc->irq_encoded | IEE16_IRQ_ENABLE);
418 * Process a received-frame interrupt.
421 ierint(struct ie_softc *sc)
424 static int timesthru = 1024;
428 status = sc->rframes[i]->ie_fd_status;
430 if ((status & IE_FD_COMPLETE) && (status & IE_FD_OK)) {
431 sc->ifp->if_ipackets++;
433 sc->ifp->if_ierrors +=
434 sc->scb->ie_err_crc +
435 sc->scb->ie_err_align +
436 sc->scb->ie_err_resource +
437 sc->scb->ie_err_overrun;
438 sc->scb->ie_err_crc = 0;
439 sc->scb->ie_err_align = 0;
440 sc->scb->ie_err_resource = 0;
441 sc->scb->ie_err_overrun = 0;
446 if (status & IE_FD_RNR) {
447 if (!(sc->scb->ie_status & IE_RU_READY)) {
448 sc->rframes[0]->ie_fd_next =
449 MK_16(MEM(sc), sc->rbuffs[0]);
450 sc->scb->ie_recv_list =
451 MK_16(MEM(sc), sc->rframes[0]);
452 command_and_wait(sc, IE_RU_START, 0, 0);
457 i = (i + 1) % sc->nframes;
463 * Process a command-complete interrupt. These are only generated by
464 * the transmission of frames. This routine is deceptively simple, since
465 * most of the real work is done by iestart().
468 ietint(struct ie_softc *sc)
470 struct ifnet *ifp = sc->ifp;
474 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
476 for (i = 0; i < sc->xmit_count; i++) {
477 status = sc->xmit_cmds[i]->ie_xmit_status;
479 if (status & IE_XS_LATECOLL) {
480 if_printf(ifp, "late collision\n");
481 ifp->if_collisions++;
483 } else if (status & IE_XS_NOCARRIER) {
484 if_printf(ifp, "no carrier\n");
486 } else if (status & IE_XS_LOSTCTS) {
487 if_printf(ifp, "lost CTS\n");
489 } else if (status & IE_XS_UNDERRUN) {
490 if_printf(ifp, "DMA underrun\n");
492 } else if (status & IE_XS_EXCMAX) {
493 if_printf(ifp, "too many collisions\n");
494 ifp->if_collisions += 16;
498 ifp->if_collisions += status & IE_XS_MAXCOLL;
504 * If multicast addresses were added or deleted while we were
505 * transmitting, ie_mc_reset() set the want_mcsetup flag indicating
506 * that we should do it.
508 if (sc->want_mcsetup) {
510 sc->want_mcsetup = 0;
512 /* Wish I knew why this seems to be necessary... */
513 sc->xmit_cmds[0]->ie_xmit_status |= IE_STAT_COMPL;
516 return (0); /* shouldn't be necessary */
520 * Process a receiver-not-ready interrupt. I believe that we get these
521 * when there aren't enough buffers to go around. For now (FIXME), we
522 * just restart the receiver, and hope everything's ok.
525 iernr(struct ie_softc *sc)
528 setup_rfa(sc, (v_caddr_t) sc->rframes[0]);
530 sc->scb->ie_recv_list = MK_16(MEM(sc), sc->rframes[0]);
531 command_and_wait(sc, IE_RU_START, 0, 0);
533 /* This doesn't work either, but it doesn't hang either. */
534 command_and_wait(sc, IE_RU_DISABLE, 0, 0); /* just in case */
535 setup_rfa(sc, (v_caddr_t) sc->rframes[0]); /* ignore cast-qual */
537 sc->scb->ie_recv_list = MK_16(MEM(sc), sc->rframes[0]);
538 command_and_wait(sc, IE_RU_START, 0, 0); /* was ENABLE */
541 ie_ack(sc, IE_ST_WHENCE);
543 sc->ifp->if_ierrors++;
548 * Compare two Ether/802 addresses for equality, inlined and
549 * unrolled for speed. I'd love to have an inline assembler
553 ether_equal(u_char * one, u_char * two)
555 if (one[0] != two[0])
557 if (one[1] != two[1])
559 if (one[2] != two[2])
561 if (one[3] != two[3])
563 if (one[4] != two[4])
565 if (one[5] != two[5])
571 * Determine quickly whether we should bother reading in this packet.
572 * This depends on whether BPF and/or bridging is enabled, whether we
573 * are receiving multicast address, and whether promiscuous mode is enabled.
574 * We assume that if IFF_PROMISC is set, then *somebody* wants to see
575 * all incoming packets.
578 check_eh(struct ie_softc *sc, struct ether_header *eh)
580 /* Optimize the common case: normal operation. We've received
581 either a unicast with our dest or a multicast packet. */
582 if (sc->promisc == 0) {
585 /* If not multicast, it's definitely for us */
586 if ((eh->ether_dhost[0] & 1) == 0)
589 /* Accept broadcasts (loose but fast check) */
590 if (eh->ether_dhost[0] == 0xff)
593 /* Compare against our multicast addresses */
594 for (i = 0; i < sc->mcast_count; i++) {
595 if (ether_equal(eh->ether_dhost,
596 (u_char *)&sc->mcast_addrs[i]))
602 /* Always accept packets when in promiscuous mode */
603 if ((sc->promisc & IFF_PROMISC) != 0)
606 /* Always accept packets directed at us */
607 if (ether_equal(eh->ether_dhost, IF_LLADDR(sc->ifp)))
610 /* Must have IFF_ALLMULTI but not IFF_PROMISC set. The chip is
611 actually in promiscuous mode, so discard unicast packets. */
612 return((eh->ether_dhost[0] & 1) != 0);
616 * We want to isolate the bits that have meaning... This assumes that
617 * IE_RBUF_SIZE is an even power of two. If somehow the act_len exceeds
618 * the size of the buffer, then we are screwed anyway.
621 ie_buflen(struct ie_softc *sc, int head)
623 return (sc->rbuffs[head]->ie_rbd_actual
624 & (IE_RBUF_SIZE | (IE_RBUF_SIZE - 1)));
628 ie_packet_len(struct ie_softc *sc)
631 int head = sc->rbhead;
635 if (!(sc->rbuffs[sc->rbhead]->ie_rbd_actual & IE_RBD_USED)) {
637 print_rbd(sc->rbuffs[sc->rbhead]);
640 "%s: receive descriptors out of sync at %d\n",
641 sc->ifp->if_xname, sc->rbhead);
645 i = sc->rbuffs[head]->ie_rbd_actual & IE_RBD_LAST;
647 acc += ie_buflen(sc, head);
648 head = (head + 1) % sc->nrxbufs;
655 * Read data off the interface, and turn it into an mbuf chain.
657 * This code is DRAMATICALLY different from the previous version; this
658 * version tries to allocate the entire mbuf chain up front, given the
659 * length of the data available. This enables us to allocate mbuf
660 * clusters in many situations where before we would have had a long
661 * chain of partially-full mbufs. This should help to speed up the
662 * operation considerably. (Provided that it works, of course.)
665 ieget(struct ie_softc *sc, struct mbuf **mp)
667 struct ether_header eh;
668 struct mbuf *m, *top, **mymp;
674 totlen = ie_packet_len(sc);
679 * Snarf the Ethernet header.
681 bcopy(sc->cbuffs[sc->rbhead], &eh, sizeof(struct ether_header));
682 /* ignore cast-qual warning here */
685 * As quickly as possible, check if this packet is for us. If not,
686 * don't waste a single cycle copying the rest of the packet in.
687 * This is only a consideration when FILTER is defined; i.e., when
688 * we are either running BPF or doing multicasting.
690 if (!check_eh(sc, &eh)) {
691 ie_drop_packet_buffer(sc);
692 sc->ifp->if_ierrors--; /* just this case, it's not an
698 MGETHDR(m, M_DONTWAIT, MT_DATA);
700 ie_drop_packet_buffer(sc);
701 /* XXXX if_ierrors++; */
706 m->m_pkthdr.rcvif = sc->ifp;
708 resid = m->m_pkthdr.len = totlen;
714 * This loop goes through and allocates mbufs for all the data we
715 * will be copying in. It does not actually do the copying yet.
717 do { /* while(resid > 0) */
719 * Try to allocate an mbuf to hold the data that we have.
720 * If we already allocated one, just get another one and
721 * stick it on the end (eventually). If we don't already
722 * have one, try to allocate an mbuf cluster big enough to
723 * hold the whole packet, if we think it's reasonable, or a
724 * single mbuf which may or may not be big enough. Got that?
727 MGET(m, M_DONTWAIT, MT_DATA);
730 ie_drop_packet_buffer(sc);
735 if (resid >= MINCLSIZE) {
736 MCLGET(m, M_DONTWAIT);
737 if (m->m_flags & M_EXT)
738 m->m_len = min(resid, MCLBYTES);
740 if (resid < m->m_len) {
741 if (!top && resid + max_linkhdr <= m->m_len)
742 m->m_data += max_linkhdr;
751 resid = totlen; /* remaining data */
752 offset = 0; /* packet offset */
753 thismboff = 0; /* offset in m */
755 m = top; /* current mbuf */
756 head = sc->rbhead; /* current rx buffer */
759 * Now we take the mbuf chain (hopefully only one mbuf most of the
760 * time) and stuff the data into it. There are no possible failures
761 * at or after this point.
763 while (resid > 0) { /* while there's stuff left */
764 int thislen = ie_buflen(sc, head) - offset;
767 * If too much data for the current mbuf, then fill the
768 * current one up, go to the next one, and try again.
770 if (thislen > m->m_len - thismboff) {
771 int newlen = m->m_len - thismboff;
773 bcopy((v_caddr_t) (sc->cbuffs[head] + offset),
774 mtod(m, caddr_t) +thismboff, (unsigned) newlen);
775 /* ignore cast-qual warning */
777 thismboff = 0; /* new mbuf, so no offset */
778 offset += newlen; /* we are now this far into
780 resid -= newlen; /* so there is this much left
785 * If there is more than enough space in the mbuf to hold
786 * the contents of this buffer, copy everything in, advance
787 * pointers, and so on.
789 if (thislen < m->m_len - thismboff) {
790 bcopy((v_caddr_t) (sc->cbuffs[head] + offset),
791 mtod(m, caddr_t) +thismboff, (unsigned) thislen);
792 thismboff += thislen; /* we are this far into the
794 resid -= thislen; /* and this much is left */
798 * Otherwise, there is exactly enough space to put this
799 * buffer's contents into the current mbuf. Do the
800 * combination of the above actions.
802 bcopy((v_caddr_t) (sc->cbuffs[head] + offset),
803 mtod(m, caddr_t) + thismboff, (unsigned) thislen);
805 thismboff = 0; /* new mbuf, start at the beginning */
806 resid -= thislen; /* and we are this far through */
809 * Advance all the pointers. We can get here from either of
810 * the last two cases, but never the first.
814 sc->rbuffs[head]->ie_rbd_actual = 0;
815 sc->rbuffs[head]->ie_rbd_length |= IE_RBD_LAST;
816 sc->rbhead = head = (head + 1) % sc->nrxbufs;
817 sc->rbuffs[sc->rbtail]->ie_rbd_length &= ~IE_RBD_LAST;
818 sc->rbtail = (sc->rbtail + 1) % sc->nrxbufs;
822 * Unless something changed strangely while we were doing the copy,
823 * we have now copied everything in from the shared memory. This
824 * means that we are done.
830 * Read frame NUM from unit UNIT (pre-cached as IE).
832 * This routine reads the RFD at NUM, and copies in the buffers from
833 * the list of RBD, then rotates the RBD and RFD lists so that the receiver
834 * doesn't start complaining. Trailers are DROPPED---there's no point
835 * in wasting time on confusing code to deal with them. Hopefully,
836 * this machine will never ARP for trailers anyway.
839 ie_readframe(struct ie_softc *sc, int num/* frame number to read */)
841 struct ifnet *ifp = sc->ifp;
842 struct ie_recv_frame_desc rfd;
845 struct ether_header *eh;
848 bcopy((v_caddr_t) (sc->rframes[num]), &rfd,
849 sizeof(struct ie_recv_frame_desc));
852 * Immediately advance the RFD list, since we we have copied ours
855 sc->rframes[num]->ie_fd_status = 0;
856 sc->rframes[num]->ie_fd_last |= IE_FD_LAST;
857 sc->rframes[sc->rftail]->ie_fd_last &= ~IE_FD_LAST;
858 sc->rftail = (sc->rftail + 1) % sc->nframes;
859 sc->rfhead = (sc->rfhead + 1) % sc->nframes;
861 if (rfd.ie_fd_status & IE_FD_OK) {
863 sc->ifp->if_ierrors++; /* this counts as an
869 eh = mtod(m, struct ether_header *);
870 if (ie_debug & IED_READFRAME) {
871 if_printf(ifp, "frame from ether %6D type %x\n",
872 eh->ether_shost, ":", (unsigned) eh->ether_type);
874 if (ntohs(eh->ether_type) > ETHERTYPE_TRAIL
875 && ntohs(eh->ether_type) < (ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER))
876 printf("received trailer!\n");
883 * Finally pass this packet up to higher layers.
886 (*ifp->if_input)(ifp, m);
891 ie_drop_packet_buffer(struct ie_softc *sc)
897 * This means we are somehow out of sync. So, we reset the
900 if (!(sc->rbuffs[sc->rbhead]->ie_rbd_actual & IE_RBD_USED)) {
902 print_rbd(sc->rbuffs[sc->rbhead]);
904 log(LOG_ERR, "%s: receive descriptors out of sync at %d\n",
905 sc->ifp->if_xname, sc->rbhead);
909 i = sc->rbuffs[sc->rbhead]->ie_rbd_actual & IE_RBD_LAST;
911 sc->rbuffs[sc->rbhead]->ie_rbd_length |= IE_RBD_LAST;
912 sc->rbuffs[sc->rbhead]->ie_rbd_actual = 0;
913 sc->rbhead = (sc->rbhead + 1) % sc->nrxbufs;
914 sc->rbuffs[sc->rbtail]->ie_rbd_length &= ~IE_RBD_LAST;
915 sc->rbtail = (sc->rbtail + 1) % sc->nrxbufs;
921 * Start transmission on an interface.
924 iestart(struct ifnet *ifp)
926 struct ie_softc *sc = ifp->if_softc;
934 iestart_locked(struct ifnet *ifp)
936 struct ie_softc *sc = ifp->if_softc;
938 volatile unsigned char *buffer;
942 * This is not really volatile, in this routine, but it makes gcc
945 volatile u_short *bptr = &sc->scb->ie_command_list;
947 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
949 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
953 IF_DEQUEUE(&sc->ifp->if_snd, m);
957 buffer = sc->xmit_cbuffs[sc->xmit_count];
960 for (m0 = m; m && len < IE_BUF_LEN; m = m->m_next) {
961 bcopy(mtod(m, caddr_t), buffer, m->m_len);
967 len = max(len, ETHER_MIN_LEN);
970 * See if bpf is listening on this interface, let it see the
971 * packet before we commit it to the wire.
974 (void *)sc->xmit_cbuffs[sc->xmit_count], len);
976 sc->xmit_buffs[sc->xmit_count]->ie_xmit_flags =
978 sc->xmit_buffs[sc->xmit_count]->ie_xmit_next = 0xffff;
979 sc->xmit_buffs[sc->xmit_count]->ie_xmit_buf =
980 MK_24(sc->iomem, sc->xmit_cbuffs[sc->xmit_count]);
982 sc->xmit_cmds[sc->xmit_count]->com.ie_cmd_cmd = IE_CMD_XMIT;
983 sc->xmit_cmds[sc->xmit_count]->ie_xmit_status = 0;
984 sc->xmit_cmds[sc->xmit_count]->ie_xmit_desc =
985 MK_16(sc->iomem, sc->xmit_buffs[sc->xmit_count]);
987 *bptr = MK_16(sc->iomem, sc->xmit_cmds[sc->xmit_count]);
988 bptr = &sc->xmit_cmds[sc->xmit_count]->com.ie_cmd_link;
990 } while (sc->xmit_count < sc->ntxbufs);
993 * If we queued up anything for transmission, send it.
995 if (sc->xmit_count) {
996 sc->xmit_cmds[sc->xmit_count - 1]->com.ie_cmd_cmd |=
997 IE_CMD_LAST | IE_CMD_INTR;
1000 * By passing the command pointer as a null, we tell
1001 * command_and_wait() to pretend that this isn't an action
1002 * command. I wish I understood what was happening here.
1004 command_and_wait(sc, IE_CU_START, 0, 0);
1005 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1011 * Check to see if there's an 82586 out there.
1014 check_ie_present(struct ie_softc *sc)
1016 volatile struct ie_sys_conf_ptr *scp;
1017 volatile struct ie_int_sys_conf_ptr *iscp;
1018 volatile struct ie_sys_ctl_block *scb;
1021 realbase = (uintptr_t) sc->iomembot + sc->iosize - (1 << 24);
1023 scp = (volatile struct ie_sys_conf_ptr *) (uintptr_t)
1024 (realbase + IE_SCP_ADDR);
1025 bzero((volatile char *) scp, sizeof *scp);
1028 * First we put the ISCP at the bottom of memory; this tests to make
1029 * sure that our idea of the size of memory is the same as the
1030 * controller's. This is NOT where the ISCP will be in normal
1033 iscp = (volatile struct ie_int_sys_conf_ptr *) sc->iomembot;
1034 bzero((volatile char *)iscp, sizeof *iscp);
1036 scb = (volatile struct ie_sys_ctl_block *) sc->iomembot;
1037 bzero((volatile char *)scb, sizeof *scb);
1039 scp->ie_bus_use = sc->bus_use; /* 8-bit or 16-bit */
1040 scp->ie_iscp_ptr = (caddr_t) (uintptr_t)
1041 ((volatile char *) iscp - (volatile char *) (uintptr_t) realbase);
1044 iscp->ie_scb_offset = MK_16(realbase, scb) + 256;
1046 (*sc->ie_reset_586) (sc);
1047 (*sc->ie_chan_attn) (sc);
1049 DELAY(100); /* wait a while... */
1051 if (iscp->ie_busy) {
1055 * Now relocate the ISCP to its real home, and reset the controller
1058 iscp = (void *) Align((caddr_t) (uintptr_t)
1059 (realbase + IE_SCP_ADDR -
1060 sizeof(struct ie_int_sys_conf_ptr)));
1061 bzero((volatile char *) iscp, sizeof *iscp); /* ignore cast-qual */
1063 scp->ie_iscp_ptr = (caddr_t) (uintptr_t)
1064 ((volatile char *) iscp - (volatile char *) (uintptr_t) realbase);
1067 iscp->ie_scb_offset = MK_16(realbase, scb);
1069 (*sc->ie_reset_586) (sc);
1070 (*sc->ie_chan_attn) (sc);
1074 if (iscp->ie_busy) {
1077 sc->iomem = (caddr_t) (uintptr_t) realbase;
1083 * Acknowledge any interrupts we may have caused...
1085 ie_ack(sc, IE_ST_WHENCE);
1091 * Divine the memory size of ie board UNIT.
1092 * Better hope there's nothing important hiding just below the ie card...
1095 find_ie_mem_size(struct ie_softc *sc)
1101 for (size = 65536; size >= 8192; size -= 8192) {
1102 if (check_ie_present(sc)) {
1111 el_reset_586(struct ie_softc *sc)
1113 outb(PORT(sc) + IE507_CTRL, EL_CTRL_RESET);
1115 outb(PORT(sc) + IE507_CTRL, EL_CTRL_NORMAL);
1120 sl_reset_586(struct ie_softc *sc)
1122 outb(PORT(sc) + IEATT_RESET, 0);
1126 ee16_reset_586(struct ie_softc *sc)
1128 outb(PORT(sc) + IEE16_ECTRL, IEE16_RESET_586);
1130 outb(PORT(sc) + IEE16_ECTRL, 0);
1135 el_chan_attn(struct ie_softc *sc)
1137 outb(PORT(sc) + IE507_ATTN, 1);
1141 sl_chan_attn(struct ie_softc *sc)
1143 outb(PORT(sc) + IEATT_ATTN, 0);
1147 ee16_chan_attn(struct ie_softc *sc)
1149 outb(PORT(sc) + IEE16_ATTN, 0);
1153 ee16_read_eeprom(struct ie_softc *sc, int location)
1157 ectrl = inb(sc->port + IEE16_ECTRL);
1158 ectrl &= IEE16_ECTRL_MASK;
1159 ectrl |= IEE16_ECTRL_EECS;
1160 outb(sc->port + IEE16_ECTRL, ectrl);
1162 ee16_eeprom_outbits(sc, IEE16_EEPROM_READ, IEE16_EEPROM_OPSIZE1);
1163 ee16_eeprom_outbits(sc, location, IEE16_EEPROM_ADDR_SIZE);
1164 edata = ee16_eeprom_inbits(sc);
1165 ectrl = inb(sc->port + IEE16_ECTRL);
1166 ectrl &= ~(IEE16_RESET_ASIC | IEE16_ECTRL_EEDI | IEE16_ECTRL_EECS);
1167 outb(sc->port + IEE16_ECTRL, ectrl);
1168 ee16_eeprom_clock(sc, 1);
1169 ee16_eeprom_clock(sc, 0);
1174 ee16_eeprom_outbits(struct ie_softc *sc, int edata, int count)
1178 ectrl = inb(sc->port + IEE16_ECTRL);
1179 ectrl &= ~IEE16_RESET_ASIC;
1180 for (i = count - 1; i >= 0; i--) {
1181 ectrl &= ~IEE16_ECTRL_EEDI;
1182 if (edata & (1 << i)) {
1183 ectrl |= IEE16_ECTRL_EEDI;
1185 outb(sc->port + IEE16_ECTRL, ectrl);
1186 DELAY(1); /* eeprom data must be setup for 0.4 uSec */
1187 ee16_eeprom_clock(sc, 1);
1188 ee16_eeprom_clock(sc, 0);
1190 ectrl &= ~IEE16_ECTRL_EEDI;
1191 outb(sc->port + IEE16_ECTRL, ectrl);
1192 DELAY(1); /* eeprom data must be held for 0.4 uSec */
1196 ee16_eeprom_inbits(struct ie_softc *sc)
1198 int ectrl, edata, i;
1200 ectrl = inb(sc->port + IEE16_ECTRL);
1201 ectrl &= ~IEE16_RESET_ASIC;
1202 for (edata = 0, i = 0; i < 16; i++) {
1204 ee16_eeprom_clock(sc, 1);
1205 ectrl = inb(sc->port + IEE16_ECTRL);
1206 if (ectrl & IEE16_ECTRL_EEDO) {
1209 ee16_eeprom_clock(sc, 0);
1215 ee16_eeprom_clock(struct ie_softc *sc, int state)
1219 ectrl = inb(sc->port + IEE16_ECTRL);
1220 ectrl &= ~(IEE16_RESET_ASIC | IEE16_ECTRL_EESK);
1222 ectrl |= IEE16_ECTRL_EESK;
1224 outb(sc->port + IEE16_ECTRL, ectrl);
1225 DELAY(9); /* EESK must be stable for 8.38 uSec */
1228 static __inline void
1229 ee16_interrupt_enable(struct ie_softc *sc)
1232 outb(sc->port + IEE16_IRQ, sc->irq_encoded | IEE16_IRQ_ENABLE);
1237 sl_read_ether(struct ie_softc *sc, unsigned char *addr)
1241 for (i = 0; i < 6; i++)
1242 addr[i] = inb(PORT(sc) + i);
1246 iereset(struct ie_softc *sc)
1248 struct ifnet *ifp = sc->ifp;
1250 if_printf(ifp, "reset\n");
1254 * Stop i82586 dead in its tracks.
1256 if (command_and_wait(sc, IE_RU_ABORT | IE_CU_ABORT, 0, 0))
1257 if_printf(ifp, "abort commands timed out\n");
1259 if (command_and_wait(sc, IE_RU_DISABLE | IE_CU_STOP, 0, 0))
1260 if_printf(ifp, "disable commands timed out\n");
1263 if (!check_ie_present(sc))
1264 panic("ie disappeared!");
1267 if (ifp->if_flags & IFF_UP)
1274 * Send a command to the controller and wait for it to either
1275 * complete or be accepted, depending on the command. If the
1276 * command pointer is null, then pretend that the command is
1277 * not an action command. If the command pointer is not null,
1278 * and the command is an action command, wait for
1279 * ((volatile struct ie_cmd_common *)pcmd)->ie_cmd_status & MASK
1283 command_and_wait(struct ie_softc *sc, int cmd, volatile void *pcmd, int mask)
1285 volatile struct ie_cmd_common *cc = pcmd;
1288 sc->scb->ie_command = (u_short) cmd;
1290 if (IE_ACTION_COMMAND(cmd) && pcmd) {
1291 (*sc->ie_chan_attn) (sc);
1294 * Now spin-lock waiting for status. This is not a very
1295 * nice thing to do, but I haven't figured out how, or
1296 * indeed if, we can put the process waiting for action to
1297 * sleep. (We may be getting called through some other
1298 * timeout running in the kernel.)
1300 * According to the packet driver, the minimum timeout
1301 * should be .369 seconds, which we round up to .37.
1303 for (i = 0; i < 370; i++) {
1304 if (cc->ie_cmd_status & mask)
1313 * Otherwise, just wait for the command to be accepted.
1315 (*sc->ie_chan_attn) (sc);
1317 while (sc->scb->ie_command); /* spin lock */
1324 * Run the time-domain reflectometer...
1327 run_tdr(struct ie_softc *sc, volatile struct ie_tdr_cmd *cmd)
1331 cmd->com.ie_cmd_status = 0;
1332 cmd->com.ie_cmd_cmd = IE_CMD_TDR | IE_CMD_LAST;
1333 cmd->com.ie_cmd_link = 0xffff;
1334 cmd->ie_tdr_time = 0;
1336 sc->scb->ie_command_list = MK_16(MEM(sc), cmd);
1337 cmd->ie_tdr_time = 0;
1339 if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL))
1342 result = cmd->ie_tdr_time;
1344 ie_ack(sc, IE_ST_WHENCE);
1346 if (result & IE_TDR_SUCCESS)
1349 if (result & IE_TDR_XCVR) {
1350 if_printf(sc->ifp, "transceiver problem\n");
1351 } else if (result & IE_TDR_OPEN) {
1352 if_printf(sc->ifp, "TDR detected an open %d clocks away\n",
1353 result & IE_TDR_TIME);
1354 } else if (result & IE_TDR_SHORT) {
1355 if_printf(sc->ifp, "TDR detected a short %d clocks away\n",
1356 result & IE_TDR_TIME);
1358 if_printf(sc->ifp, "TDR returned unknown status %x\n", result);
1363 start_receiver(struct ie_softc *sc)
1366 sc->scb->ie_recv_list = MK_16(MEM(sc), sc->rframes[0]);
1367 command_and_wait(sc, IE_RU_START, 0, 0);
1369 ie_ack(sc, IE_ST_WHENCE);
1373 * Here is a helper routine for iernr() and ieinit(). This sets up
1377 setup_rfa(struct ie_softc *sc, v_caddr_t ptr)
1379 volatile struct ie_recv_frame_desc *rfd = (volatile void *)ptr;
1380 volatile struct ie_recv_buf_desc *rbd;
1383 /* First lay them out */
1384 for (i = 0; i < sc->nframes; i++) {
1385 sc->rframes[i] = rfd;
1386 bzero((volatile char *) rfd, sizeof *rfd); /* ignore cast-qual */
1390 ptr = Alignvol(rfd); /* ignore cast-qual */
1392 /* Now link them together */
1393 for (i = 0; i < sc->nframes; i++) {
1394 sc->rframes[i]->ie_fd_next =
1395 MK_16(MEM(sc), sc->rframes[(i + 1) % sc->nframes]);
1398 /* Finally, set the EOL bit on the last one. */
1399 sc->rframes[sc->nframes - 1]->ie_fd_last |= IE_FD_LAST;
1402 * Now lay out some buffers for the incoming frames. Note that we
1403 * set aside a bit of slop in each buffer, to make sure that we have
1404 * enough space to hold a single frame in every buffer.
1406 rbd = (volatile void *) ptr;
1408 for (i = 0; i < sc->nrxbufs; i++) {
1409 sc->rbuffs[i] = rbd;
1410 bzero((volatile char *)rbd, sizeof *rbd);
1411 ptr = Alignvol(ptr + sizeof *rbd);
1412 rbd->ie_rbd_length = IE_RBUF_SIZE;
1413 rbd->ie_rbd_buffer = MK_24(MEM(sc), ptr);
1414 sc->cbuffs[i] = (volatile void *) ptr;
1415 ptr += IE_RBUF_SIZE;
1416 rbd = (volatile void *) ptr;
1419 /* Now link them together */
1420 for (i = 0; i < sc->nrxbufs; i++) {
1421 sc->rbuffs[i]->ie_rbd_next =
1422 MK_16(MEM(sc), sc->rbuffs[(i + 1) % sc->nrxbufs]);
1425 /* Tag EOF on the last one */
1426 sc->rbuffs[sc->nrxbufs - 1]->ie_rbd_length |= IE_RBD_LAST;
1429 * We use the head and tail pointers on receive to keep track of the
1430 * order in which RFDs and RBDs are used.
1433 sc->rftail = sc->nframes - 1;
1435 sc->rbtail = sc->nrxbufs - 1;
1437 sc->scb->ie_recv_list = MK_16(MEM(sc), sc->rframes[0]);
1438 sc->rframes[0]->ie_fd_buf_desc = MK_16(MEM(sc), sc->rbuffs[0]);
1440 ptr = Alignvol(ptr);
1445 * Run the multicast setup command.
1448 mc_setup(struct ie_softc *sc)
1450 volatile struct ie_mcast_cmd *cmd = (volatile void *)sc->xmit_cbuffs[0];
1452 cmd->com.ie_cmd_status = 0;
1453 cmd->com.ie_cmd_cmd = IE_CMD_MCAST | IE_CMD_LAST;
1454 cmd->com.ie_cmd_link = 0xffff;
1456 /* ignore cast-qual */
1457 bcopy((v_caddr_t) sc->mcast_addrs, (v_caddr_t) cmd->ie_mcast_addrs,
1458 sc->mcast_count * sizeof *sc->mcast_addrs);
1460 cmd->ie_mcast_bytes = sc->mcast_count * 6; /* grrr... */
1462 sc->scb->ie_command_list = MK_16(MEM(sc), cmd);
1463 if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL)
1464 || !(cmd->com.ie_cmd_status & IE_STAT_OK)) {
1465 if_printf(sc->ifp, "multicast address setup command failed\n");
1472 * This routine takes the environment generated by check_ie_present()
1473 * and adds to it all the other structures we need to operate the adapter.
1474 * This includes executing the CONFIGURE, IA-SETUP, and MC-SETUP commands,
1475 * starting the receiver unit, and clearing interrupts.
1481 struct ie_softc *sc = xsc;
1489 ieinit_locked(struct ie_softc *sc)
1491 struct ifnet *ifp = sc->ifp;
1492 volatile struct ie_sys_ctl_block *scb = sc->scb;
1496 ptr = Alignvol((volatile char *) scb + sizeof *scb);
1499 * Send the configure command first.
1502 volatile struct ie_config_cmd *cmd = (volatile void *) ptr;
1504 ie_setup_config(cmd, sc->promisc,
1505 sc->hard_type == IE_STARLAN10);
1506 cmd->com.ie_cmd_status = 0;
1507 cmd->com.ie_cmd_cmd = IE_CMD_CONFIG | IE_CMD_LAST;
1508 cmd->com.ie_cmd_link = 0xffff;
1510 scb->ie_command_list = MK_16(MEM(sc), cmd);
1512 if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL)
1513 || !(cmd->com.ie_cmd_status & IE_STAT_OK)) {
1514 if_printf(ifp, "configure command failed\n");
1519 * Now send the Individual Address Setup command.
1522 volatile struct ie_iasetup_cmd *cmd = (volatile void *) ptr;
1524 cmd->com.ie_cmd_status = 0;
1525 cmd->com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST;
1526 cmd->com.ie_cmd_link = 0xffff;
1528 bcopy((volatile char *)IF_LLADDR(ifp),
1529 (volatile char *)&cmd->ie_address, sizeof cmd->ie_address);
1530 scb->ie_command_list = MK_16(MEM(sc), cmd);
1531 if (command_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL)
1532 || !(cmd->com.ie_cmd_status & IE_STAT_OK)) {
1533 if_printf(ifp, "individual address "
1534 "setup command failed\n");
1540 * Now run the time-domain reflectometer.
1542 run_tdr(sc, (volatile void *) ptr);
1545 * Acknowledge any interrupts we have generated thus far.
1547 ie_ack(sc, IE_ST_WHENCE);
1552 ptr = setup_rfa(sc, ptr);
1555 * Finally, the transmit command and buffer are the last little bit
1559 /* transmit command buffers */
1560 for (i = 0; i < sc->ntxbufs; i++) {
1561 sc->xmit_cmds[i] = (volatile void *) ptr;
1562 ptr += sizeof *sc->xmit_cmds[i];
1563 ptr = Alignvol(ptr);
1564 sc->xmit_buffs[i] = (volatile void *)ptr;
1565 ptr += sizeof *sc->xmit_buffs[i];
1566 ptr = Alignvol(ptr);
1569 /* transmit buffers */
1570 for (i = 0; i < sc->ntxbufs - 1; i++) {
1571 sc->xmit_cbuffs[i] = (volatile void *)ptr;
1573 ptr = Alignvol(ptr);
1575 sc->xmit_cbuffs[sc->ntxbufs - 1] = (volatile void *) ptr;
1577 for (i = 1; i < sc->ntxbufs; i++) {
1578 bzero((v_caddr_t) sc->xmit_cmds[i], sizeof *sc->xmit_cmds[i]);
1579 bzero((v_caddr_t) sc->xmit_buffs[i], sizeof *sc->xmit_buffs[i]);
1583 * This must be coordinated with iestart() and ietint().
1585 sc->xmit_cmds[0]->ie_xmit_status = IE_STAT_COMPL;
1587 /* take the ee16 out of loopback */
1588 if (sc->hard_type == IE_EE16) {
1589 u_int8_t bart_config;
1591 bart_config = inb(PORT(sc) + IEE16_CONFIG);
1592 bart_config &= ~IEE16_BART_LOOPBACK;
1593 /* inb doesn't get bit! */
1594 bart_config |= IEE16_BART_MCS16_TEST;
1595 outb(PORT(sc) + IEE16_CONFIG, bart_config);
1596 ee16_interrupt_enable(sc);
1599 ifp->if_drv_flags |= IFF_DRV_RUNNING; /* tell higher levels
1601 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1609 ie_stop(struct ie_softc *sc)
1611 struct ifnet *ifp = sc->ifp;
1613 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1614 command_and_wait(sc, IE_RU_DISABLE, 0, 0);
1618 ieioctl(struct ifnet *ifp, u_long command, caddr_t data)
1621 struct ie_softc *sc = ifp->if_softc;
1626 * Note that this device doesn't have an "all multicast"
1627 * mode, so we must turn on promiscuous mode and do the
1628 * filtering manually.
1631 if ((ifp->if_flags & IFF_UP) == 0 &&
1632 (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
1634 } else if ((ifp->if_flags & IFF_UP) &&
1635 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
1637 ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI);
1639 } else if (sc->promisc ^
1640 (ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI))) {
1642 ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI);
1651 * Update multicast listeners
1653 /* reset multicast filtering */
1661 error = ether_ioctl(ifp, command, data);
1669 ie_mc_reset(struct ie_softc *sc)
1671 struct ifmultiaddr *ifma;
1674 * Step through the list of addresses.
1676 sc->mcast_count = 0;
1677 if_maddr_rlock(sc->ifp);
1678 TAILQ_FOREACH(ifma, &sc->ifp->if_multiaddrs, ifma_link) {
1679 if (ifma->ifma_addr->sa_family != AF_LINK)
1682 /* XXX - this is broken... */
1683 if (sc->mcast_count >= MAXMCAST) {
1684 sc->ifp->if_flags |= IFF_ALLMULTI;
1685 if (sc->ifp->if_flags & IFF_UP)
1689 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
1690 &(sc->mcast_addrs[sc->mcast_count]), 6);
1693 if_maddr_runlock(sc->ifp);
1696 sc->want_mcsetup = 1;
1702 print_rbd(volatile struct ie_recv_buf_desc * rbd)
1704 printf("RBD at %p:\n"
1705 "actual %04x, next %04x, buffer %p\n"
1706 "length %04x, mbz %04x\n",
1707 (volatile void *) rbd,
1708 rbd->ie_rbd_actual, rbd->ie_rbd_next,
1709 (void *) rbd->ie_rbd_buffer,
1710 rbd->ie_rbd_length, rbd->mbz);
1716 ie_alloc_resources (device_t dev)
1718 struct ie_softc * sc;
1722 sc = device_get_softc(dev);
1724 sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->io_rid,
1727 device_printf(dev, "No I/O space?!\n");
1731 sc->io_bt = rman_get_bustag(sc->io_res);
1732 sc->io_bh = rman_get_bushandle(sc->io_res);
1734 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
1737 device_printf(dev, "No Memory!\n");
1741 sc->mem_bt = rman_get_bustag(sc->mem_res);
1742 sc->mem_bh = rman_get_bushandle(sc->mem_res);
1744 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
1747 device_printf(dev, "No IRQ!\n");
1752 sc->port = rman_get_start(sc->io_res); /* XXX hack */
1753 sc->iomembot = rman_get_virtual(sc->mem_res);
1754 sc->iosize = rman_get_size(sc->mem_res);
1762 ie_release_resources (device_t dev)
1764 struct ie_softc * sc;
1766 sc = device_get_softc(dev);
1769 bus_teardown_intr(dev, sc->irq_res, sc->irq_ih);
1771 free(sc->rframes, M_DEVBUF);
1773 bus_release_resource(dev, SYS_RES_IOPORT,
1774 sc->io_rid, sc->io_res);
1776 bus_release_resource(dev, SYS_RES_IRQ,
1777 sc->irq_rid, sc->irq_res);
1779 bus_release_resource(dev, SYS_RES_MEMORY,
1780 sc->mem_rid, sc->mem_res);
1788 ie_detach (device_t dev)
1790 struct ie_softc * sc;
1793 sc = device_get_softc(dev);
1797 if (sc->hard_type == IE_EE16)
1802 ether_ifdetach(ifp);
1803 ie_release_resources(dev);
1804 mtx_destroy(&sc->lock);