2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Herb Peyerl.
16 * 4. The name of Herb Peyerl may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * Created from if_ep.c driver by Fred Gray (fgray@rice.edu) to support
42 * Modified from the FreeBSD 1.1.5.1 version by:
44 * INRIA - Sophia Antipolis, France
45 * avega@sophia.inria.fr
49 * Promiscuous mode added and interrupt logic slightly changed
50 * to reduce the number of adapter failures. Transceiver select
51 * logic changed to use value from EEPROM. Autoconfiguration
55 * Chelindbank (Chelyabinsk, Russia)
56 * babkin@hq.icb.chel.su
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/sockio.h>
63 #include <sys/kernel.h>
64 #include <sys/malloc.h>
66 #include <sys/socket.h>
70 #include <net/ethernet.h>
71 #include <net/if_dl.h>
72 #include <net/if_types.h>
74 #include <machine/bus.h>
80 #include <dev/vx/if_vxreg.h>
81 #include <dev/vx/if_vxvar.h>
83 #define ETHER_MAX_LEN 1518
84 #define ETHER_ADDR_LEN 6
87 static struct connector_entry {
90 } conn_tab[VX_CONNECTORS] = {
92 #define CONNECTOR_UTP 0
96 #define CONNECTOR_AUI 1
104 #define CONNECTOR_BNC 3
108 #define CONNECTOR_TX 4
112 #define CONNECTOR_FX 5
116 #define CONNECTOR_MII 6
125 static void vx_txstat(struct vx_softc *);
126 static int vx_status(struct vx_softc *);
127 static void vx_init(void *);
128 static void vx_init_locked(struct vx_softc *);
129 static int vx_ioctl(struct ifnet *, u_long, caddr_t);
130 static void vx_start(struct ifnet *);
131 static void vx_start_locked(struct ifnet *);
132 static void vx_watchdog(struct ifnet *);
133 static void vx_reset(struct vx_softc *);
134 static void vx_read(struct vx_softc *);
135 static struct mbuf *vx_get(struct vx_softc *, u_int);
136 static void vx_mbuf_fill(void *);
137 static void vx_mbuf_empty(struct vx_softc *);
138 static void vx_setfilter(struct vx_softc *);
139 static void vx_getlink(struct vx_softc *);
140 static void vx_setlink(struct vx_softc *);
143 vx_attach(device_t dev)
145 struct vx_softc *sc = device_get_softc(dev);
150 ifp = sc->vx_ifp = if_alloc(IFT_ETHER);
152 device_printf(dev, "can not if_alloc()\n");
155 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
157 mtx_init(&sc->vx_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
159 callout_init_mtx(&sc->vx_callout, &sc->vx_mtx, 0);
161 CSR_WRITE_2(sc, VX_COMMAND, GLOBAL_RESET);
167 * Read the station address from the eeprom
170 for (i = 0; i < 3; i++) {
173 if (vx_busy_eeprom(sc)) {
174 mtx_destroy(&sc->vx_mtx);
178 CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND, EEPROM_CMD_RD
179 | (EEPROM_OEM_ADDR0 + i));
180 if (vx_busy_eeprom(sc)) {
181 mtx_destroy(&sc->vx_mtx);
185 x = CSR_READ_2(sc, VX_W0_EEPROM_DATA);
186 eaddr[(i << 1)] = x >> 8;
187 eaddr[(i << 1) + 1] = x;
190 ifp->if_mtu = ETHERMTU;
191 ifp->if_snd.ifq_maxlen = ifqmaxlen;
192 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
193 ifp->if_start = vx_start;
194 ifp->if_ioctl = vx_ioctl;
195 ifp->if_init = vx_init;
196 ifp->if_watchdog = vx_watchdog;
199 ether_ifattach(ifp, eaddr);
201 sc->vx_tx_start_thresh = 20; /* probably a good starting point. */
211 * The order in here seems important. Otherwise we may not receive
217 struct vx_softc *sc = (struct vx_softc *)xsc;
225 vx_init_locked(struct vx_softc *sc)
227 struct ifnet *ifp = sc->vx_ifp;
236 for (i = 0; i < 6; i++) /* Reload the ether_addr. */
237 CSR_WRITE_1(sc, VX_W2_ADDR_0 + i, IF_LLADDR(sc->vx_ifp)[i]);
239 CSR_WRITE_2(sc, VX_COMMAND, RX_RESET);
241 CSR_WRITE_2(sc, VX_COMMAND, TX_RESET);
244 GO_WINDOW(1); /* Window 1 is operating window */
245 for (i = 0; i < 31; i++)
246 CSR_READ_1(sc, VX_W1_TX_STATUS);
248 CSR_WRITE_2(sc, VX_COMMAND, SET_RD_0_MASK | S_CARD_FAILURE |
249 S_RX_COMPLETE | S_TX_COMPLETE | S_TX_AVAIL);
250 CSR_WRITE_2(sc, VX_COMMAND, SET_INTR_MASK | S_CARD_FAILURE |
251 S_RX_COMPLETE | S_TX_COMPLETE | S_TX_AVAIL);
254 * Attempt to get rid of any stray interrupts that occured during
255 * configuration. On the i386 this isn't possible because one may
256 * already be queued. However, a single stray interrupt is
259 CSR_WRITE_2(sc, VX_COMMAND, ACK_INTR | 0xff);
264 CSR_WRITE_2(sc, VX_COMMAND, RX_ENABLE);
265 CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE);
269 /* Interface is now `running', with no output active. */
270 ifp->if_drv_flags |= IFF_DRV_RUNNING;
271 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
273 /* Attempt to start output, if any. */
274 vx_start_locked(ifp);
278 vx_setfilter(struct vx_softc *sc)
280 struct ifnet *ifp = sc->vx_ifp;
283 GO_WINDOW(1); /* Window 1 is operating window */
284 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER |
285 FIL_INDIVIDUAL | FIL_BRDCST | FIL_MULTICAST |
286 ((ifp->if_flags & IFF_PROMISC) ? FIL_PROMISC : 0));
290 vx_getlink(struct vx_softc *sc)
295 sc->vx_connectors = CSR_READ_2(sc, VX_W3_RESET_OPT) & 0x7f;
296 for (n = 0, k = 0; k < VX_CONNECTORS; k++) {
297 if (sc->vx_connectors & conn_tab[k].bit) {
300 printf("%s", conn_tab[k].name);
304 if (sc->vx_connectors == 0) {
305 printf("no connectors!\n");
310 (CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & INTERNAL_CONNECTOR_MASK)
311 >> INTERNAL_CONNECTOR_BITS;
312 if (sc->vx_connector & 0x10) {
313 sc->vx_connector &= 0x0f;
314 printf("[*%s*]", conn_tab[(int)sc->vx_connector].name);
315 printf(": disable 'auto select' with DOS util!\n");
317 printf("[*%s*]\n", conn_tab[(int)sc->vx_connector].name);
322 vx_setlink(struct vx_softc *sc)
324 struct ifnet *ifp = sc->vx_ifp;
326 char *reason, *warning;
327 static int prev_flags;
328 static signed char prev_conn = -1;
332 prev_conn = sc->vx_connector;
337 * Now behavior was slightly changed:
339 * if any of flags link[0-2] is used and its connector is
340 * physically present the following connectors are used:
342 * link0 - AUI * highest precedence
344 * link2 - UTP * lowest precedence
346 * If none of them is specified then
347 * connector specified in the EEPROM is used
348 * (if present on card or UTP if not).
350 i = sc->vx_connector; /* default in EEPROM */
354 if (ifp->if_flags & IFF_LINK0) {
355 if (sc->vx_connectors & conn_tab[CONNECTOR_AUI].bit) {
359 warning = "aui not present! (link0)";
361 } else if (ifp->if_flags & IFF_LINK1) {
362 if (sc->vx_connectors & conn_tab[CONNECTOR_BNC].bit) {
366 warning = "bnc not present! (link1)";
368 } else if (ifp->if_flags & IFF_LINK2) {
369 if (sc->vx_connectors & conn_tab[CONNECTOR_UTP].bit) {
373 warning = "utp not present! (link2)";
375 } else if ((sc->vx_connectors & conn_tab[(int)sc->vx_connector].bit) == 0) {
376 warning = "strange connector type in EEPROM.";
380 /* Avoid unnecessary message. */
381 k = (prev_flags ^ ifp->if_flags) & (IFF_LINK0 | IFF_LINK1 | IFF_LINK2);
382 if ((k != 0) || (prev_conn != i)) {
384 if_printf(ifp, "warning: %s\n", warning);
385 if_printf(ifp, "selected %s. (%s)\n", conn_tab[i].name, reason);
387 /* Set the selected connector. */
389 j = CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
390 CSR_WRITE_4(sc, VX_W3_INTERNAL_CFG, j | (i << INTERNAL_CONNECTOR_BITS));
392 /* First, disable all. */
393 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
396 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, 0);
398 /* Second, enable the selected one. */
402 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, ENABLE_UTP);
405 CSR_WRITE_2(sc, VX_COMMAND, START_TRANSCEIVER);
411 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, LINKBEAT_ENABLE);
413 default: /* AUI and MII fall here */
418 prev_flags = ifp->if_flags;
423 vx_start(struct ifnet *ifp)
425 struct vx_softc *sc = ifp->if_softc;
428 vx_start_locked(ifp);
433 vx_start_locked(struct ifnet *ifp)
435 struct vx_softc *sc = ifp->if_softc;
441 /* Don't transmit if interface is busy or not running */
442 if ((sc->vx_ifp->if_drv_flags &
443 (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING)
447 /* Sneak a peek at the next packet */
448 m = ifp->if_snd.ifq_head;
452 /* We need to use m->m_pkthdr.len, so require the header */
454 len = m->m_pkthdr.len;
459 * The 3c509 automatically pads short packets to minimum ethernet
460 * length, but we drop packets that are too large. Perhaps we should
461 * truncate them instead?
463 if (len + pad > ETHER_MAX_LEN) {
464 /* packet is obviously too large: toss it */
466 IF_DEQUEUE(&ifp->if_snd, m);
471 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
472 CSR_WRITE_2(sc, VX_COMMAND,
473 SET_TX_AVAIL_THRESH | ((len + pad + 4) >> 2));
474 /* not enough room in FIFO - make sure */
475 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
476 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
481 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_AVAIL_THRESH | (8188 >> 2));
482 IF_DEQUEUE(&ifp->if_snd, m);
483 if (m == NULL) /* not really needed */
487 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_START_THRESH |
488 ((len / 4 + sc->vx_tx_start_thresh) >> 2));
490 BPF_MTAP(sc->vx_ifp, m);
493 * Do the output at splhigh() so that an interrupt from another device
494 * won't cause a FIFO underrun.
496 * XXX: Can't enforce that anymore.
499 CSR_WRITE_4(sc, VX_W1_TX_PIO_WR_1, len | TX_INDICATE);
503 bus_space_write_multi_4(sc->vx_bst, sc->vx_bsh,
504 VX_W1_TX_PIO_WR_1, (u_int32_t *)mtod(m, caddr_t),
507 bus_space_write_multi_1(sc->vx_bst, sc->vx_bsh,
509 mtod(m, caddr_t) + (m->m_len & ~3), m->m_len & 3);
513 CSR_WRITE_1(sc, VX_W1_TX_PIO_WR_1, 0); /* Padding */
519 if ((CSR_READ_2(sc, VX_W1_RX_STATUS) & ERR_INCOMPLETE) == 0) {
520 /* We received a complete packet. */
522 if ((CSR_READ_2(sc, VX_STATUS) & S_INTR_LATCH) == 0) {
524 * No interrupt, read the packet and continue
525 * Is this supposed to happen? Is my motherboard
531 * Got an interrupt, return so that it gets
536 /* Check if we are stuck and reset [see XXX comment] */
538 if (ifp->if_flags & IFF_DEBUG)
539 if_printf(ifp, "adapter reset\n");
548 * XXX: The 3c509 card can get in a mode where both the fifo status bit
549 * FIFOS_RX_OVERRUN and the status bit ERR_INCOMPLETE are set
550 * We detect this situation and we reset the adapter.
551 * It happens at times when there is a lot of broadcast traffic
552 * on the cable (once in a blue moon).
555 vx_status(struct vx_softc *sc)
563 * Check the FIFO status and act accordingly
566 fifost = CSR_READ_2(sc, VX_W4_FIFO_DIAG);
570 if (fifost & FIFOS_RX_UNDERRUN) {
571 if (ifp->if_flags & IFF_DEBUG)
572 if_printf(ifp, "RX underrun\n");
576 if (fifost & FIFOS_RX_STATUS_OVERRUN) {
577 if (ifp->if_flags & IFF_DEBUG)
578 if_printf(ifp, "RX Status overrun\n");
581 if (fifost & FIFOS_RX_OVERRUN) {
582 if (ifp->if_flags & IFF_DEBUG)
583 if_printf(ifp, "RX overrun\n");
586 if (fifost & FIFOS_TX_OVERRUN) {
587 if (ifp->if_flags & IFF_DEBUG)
588 if_printf(ifp, "TX overrun\n");
596 vx_txstat(struct vx_softc *sc)
604 * We need to read+write TX_STATUS until we get a 0 status
605 * in order to turn off the interrupt flag.
608 while ((i = CSR_READ_1(sc, VX_W1_TX_STATUS)) & TXS_COMPLETE) {
609 CSR_WRITE_1(sc, VX_W1_TX_STATUS, 0x0);
611 if (i & TXS_JABBER) {
613 if (ifp->if_flags & IFF_DEBUG)
614 if_printf(ifp, "jabber (%x)\n", i);
616 } else if (i & TXS_UNDERRUN) {
618 if (ifp->if_flags & IFF_DEBUG)
619 if_printf(ifp, "fifo underrun (%x) @%d\n", i,
620 sc->vx_tx_start_thresh);
621 if (sc->vx_tx_succ_ok < 100)
622 sc->vx_tx_start_thresh =
624 sc->vx_tx_start_thresh + 20);
625 sc->vx_tx_succ_ok = 0;
627 } else if (i & TXS_MAX_COLLISION) {
628 ++ifp->if_collisions;
629 CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE);
630 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
632 sc->vx_tx_succ_ok = (sc->vx_tx_succ_ok + 1) & 127;
637 vx_intr(void *voidsc)
640 struct vx_softc *sc = voidsc;
641 struct ifnet *ifp = sc->vx_ifp;
645 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
647 status = CSR_READ_2(sc, VX_STATUS);
649 if ((status & (S_TX_COMPLETE | S_TX_AVAIL |
650 S_RX_COMPLETE | S_CARD_FAILURE)) == 0)
654 * Acknowledge any interrupts. It's important that we do this
655 * first, since there would otherwise be a race condition.
656 * Due to the i386 interrupt queueing, we may get spurious
657 * interrupts occasionally.
659 CSR_WRITE_2(sc, VX_COMMAND, ACK_INTR | status);
661 if (status & S_RX_COMPLETE)
663 if (status & S_TX_AVAIL) {
665 sc->vx_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
666 vx_start_locked(sc->vx_ifp);
668 if (status & S_CARD_FAILURE) {
669 if_printf(ifp, "adapter failure (%x)\n", status);
674 if (status & S_TX_COMPLETE) {
677 vx_start_locked(ifp);
682 /* no more interrupts */
687 vx_read(struct vx_softc *sc)
689 struct ifnet *ifp = sc->vx_ifp;
691 struct ether_header *eh;
695 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
698 if (ifp->if_flags & IFF_DEBUG) {
699 int err = len & ERR_MASK;
702 if (len & ERR_INCOMPLETE)
703 s = "incomplete packet";
704 else if (err == ERR_OVERRUN)
705 s = "packet overrun";
706 else if (err == ERR_RUNT)
708 else if (err == ERR_ALIGNMENT)
710 else if (err == ERR_CRC)
712 else if (err == ERR_OVERSIZE)
713 s = "oversized packet";
714 else if (err == ERR_DRIBBLE)
718 if_printf(ifp, "%s\n", s);
720 if (len & ERR_INCOMPLETE)
727 len &= RX_BYTES_MASK; /* Lower 11 bits = RX bytes. */
729 /* Pull packet off interface. */
740 m0 = m_devget(mtod(m, char *), m->m_pkthdr.len, ETHER_ALIGN,
750 /* We assume the header fit entirely in one mbuf. */
751 eh = mtod(m, struct ether_header *);
754 * XXX: Some cards seem to be in promiscous mode all the time.
755 * we need to make sure we only get our own stuff always.
759 if (!(ifp->if_flags & IFF_PROMISC)
760 && (eh->ether_dhost[0] & 1) == 0 /* !mcast and !bcast */
761 && bcmp(eh->ether_dhost, IF_LLADDR(sc->vx_ifp),
762 ETHER_ADDR_LEN) != 0) {
767 (*ifp->if_input)(ifp, m);
771 * In periods of high traffic we can actually receive enough
772 * packets so that the fifo overrun bit will be set at this point,
773 * even though we just read a packet. In this case we
774 * are not going to receive any more interrupts. We check for
775 * this condition and read again until the fifo is not full.
776 * We could simplify this test by not using vx_status(), but
777 * rechecking the RX_STATUS register directly. This test could
778 * result in unnecessary looping in cases where there is a new
779 * packet but the fifo is not full, but it will not fix the
782 * Even with this improvement, we still get packet overrun errors
783 * which are hurting performance. Maybe when I get some more time
784 * I'll modify vx_read() so that it can handle RX_EARLY interrupts.
787 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
788 /* Check if we are stuck and reset [see XXX comment] */
789 if (len & ERR_INCOMPLETE) {
790 if (ifp->if_flags & IFF_DEBUG)
791 if_printf(ifp, "adapter reset\n");
800 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
804 vx_get(struct vx_softc *sc, u_int totlen)
806 struct ifnet *ifp = sc->vx_ifp;
807 struct mbuf *top, **mp, *m;
811 m = sc->vx_mb[sc->vx_next_mb];
812 sc->vx_mb[sc->vx_next_mb] = NULL;
814 MGETHDR(m, M_DONTWAIT, MT_DATA);
818 /* If the queue is no longer full, refill. */
819 if (sc->vx_last_mb == sc->vx_next_mb &&
820 sc->vx_buffill_pending == 0) {
821 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill,
823 sc->vx_buffill_pending = 1;
825 /* Convert one of our saved mbuf's. */
826 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
827 m->m_data = m->m_pktdat;
828 m->m_flags = M_PKTHDR;
829 bzero(&m->m_pkthdr, sizeof(m->m_pkthdr));
831 m->m_pkthdr.rcvif = ifp;
832 m->m_pkthdr.len = totlen;
838 * We read the packet at splhigh() so that an interrupt from another
839 * device doesn't cause the card's buffer to overflow while we're
840 * reading it. We may still lose packets at other times.
842 * XXX: Can't enforce this anymore.
846 * Since we don't set allowLargePackets bit in MacControl register,
847 * we can assume that totlen <= 1500bytes.
848 * The while loop will be performed iff we have a packet with
849 * MLEN < m_len < MINCLSIZE.
853 m = sc->vx_mb[sc->vx_next_mb];
854 sc->vx_mb[sc->vx_next_mb] = NULL;
856 MGET(m, M_DONTWAIT, MT_DATA);
862 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
866 if (totlen >= MINCLSIZE) {
867 MCLGET(m, M_DONTWAIT);
868 if (m->m_flags & M_EXT)
871 len = min(totlen, len);
873 bus_space_read_multi_4(sc->vx_bst, sc->vx_bsh,
874 VX_W1_RX_PIO_RD_1, mtod(m, u_int32_t *), len / 4);
876 bus_space_read_multi_1(sc->vx_bst, sc->vx_bsh,
877 VX_W1_RX_PIO_RD_1, mtod(m, u_int8_t *) + (len & ~3),
886 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
893 vx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
895 struct vx_softc *sc = ifp->if_softc;
896 struct ifreq *ifr = (struct ifreq *) data;
902 if ((ifp->if_flags & IFF_UP) == 0 &&
903 (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
905 * If interface is marked up and it is stopped, then
909 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
910 } else if ((ifp->if_flags & IFF_UP) != 0 &&
911 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
913 * If interface is marked up and it is stopped, then
919 * deal with flags changes:
920 * IFF_MULTICAST, IFF_PROMISC,
921 * IFF_LINK0, IFF_LINK1,
931 * Set the interface MTU.
934 if (ifr->ifr_mtu > ETHERMTU) {
937 ifp->if_mtu = ifr->ifr_mtu;
945 * Multicast list has changed; set the hardware filter
956 error = ether_ioctl(ifp, cmd, data);
964 vx_reset(struct vx_softc *sc)
973 vx_watchdog(struct ifnet *ifp)
975 struct vx_softc *sc = ifp->if_softc;
978 if (ifp->if_flags & IFF_DEBUG)
979 if_printf(ifp, "device timeout\n");
980 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
981 vx_start_locked(ifp);
987 vx_stop(struct vx_softc *sc)
989 struct ifnet *ifp = sc->vx_ifp;
994 CSR_WRITE_2(sc, VX_COMMAND, RX_DISABLE);
995 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
997 CSR_WRITE_2(sc, VX_COMMAND, TX_DISABLE);
998 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
1000 CSR_WRITE_2(sc, VX_COMMAND, RX_RESET);
1002 CSR_WRITE_2(sc, VX_COMMAND, TX_RESET);
1004 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
1005 CSR_WRITE_2(sc, VX_COMMAND, SET_RD_0_MASK);
1006 CSR_WRITE_2(sc, VX_COMMAND, SET_INTR_MASK);
1007 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER);
1013 vx_busy_eeprom(struct vx_softc *sc)
1018 j = CSR_READ_2(sc, VX_W0_EEPROM_COMMAND);
1019 if (j & EEPROM_BUSY)
1025 if_printf(sc->vx_ifp, "eeprom failed to come ready\n");
1032 vx_mbuf_fill(void *sp)
1034 struct vx_softc *sc = (struct vx_softc *)sp;
1040 if (sc->vx_mb[i] == NULL)
1041 MGET(sc->vx_mb[i], M_DONTWAIT, MT_DATA);
1042 if (sc->vx_mb[i] == NULL)
1044 i = (i + 1) % MAX_MBS;
1045 } while (i != sc->vx_next_mb);
1047 /* If the queue was not filled, try again. */
1048 if (sc->vx_last_mb != sc->vx_next_mb) {
1049 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill, sc);
1050 sc->vx_buffill_pending = 1;
1052 sc->vx_buffill_pending = 0;
1057 vx_mbuf_empty(struct vx_softc *sc)
1062 for (i = 0; i < MAX_MBS; i++) {
1064 m_freem(sc->vx_mb[i]);
1065 sc->vx_mb[i] = NULL;
1068 sc->vx_last_mb = sc->vx_next_mb = 0;
1069 if (sc->vx_buffill_pending != 0)
1070 callout_stop(&sc->vx_callout);