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>
69 #include <net/if_var.h>
71 #include <net/ethernet.h>
72 #include <net/if_dl.h>
73 #include <net/if_types.h>
75 #include <machine/bus.h>
81 #include <dev/vx/if_vxreg.h>
82 #include <dev/vx/if_vxvar.h>
84 #define ETHER_MAX_LEN 1518
85 #define ETHER_ADDR_LEN 6
88 static struct connector_entry {
91 } conn_tab[VX_CONNECTORS] = {
93 #define CONNECTOR_UTP 0
97 #define CONNECTOR_AUI 1
105 #define CONNECTOR_BNC 3
109 #define CONNECTOR_TX 4
113 #define CONNECTOR_FX 5
117 #define CONNECTOR_MII 6
126 static void vx_txstat(struct vx_softc *);
127 static int vx_status(struct vx_softc *);
128 static void vx_init(void *);
129 static void vx_init_locked(struct vx_softc *);
130 static int vx_ioctl(struct ifnet *, u_long, caddr_t);
131 static void vx_start(struct ifnet *);
132 static void vx_start_locked(struct ifnet *);
133 static void vx_watchdog(void *);
134 static void vx_reset(struct vx_softc *);
135 static void vx_read(struct vx_softc *);
136 static struct mbuf *vx_get(struct vx_softc *, u_int);
137 static void vx_mbuf_fill(void *);
138 static void vx_mbuf_empty(struct vx_softc *);
139 static void vx_setfilter(struct vx_softc *);
140 static void vx_getlink(struct vx_softc *);
141 static void vx_setlink(struct vx_softc *);
144 vx_attach(device_t dev)
146 struct vx_softc *sc = device_get_softc(dev);
151 ifp = sc->vx_ifp = if_alloc(IFT_ETHER);
153 device_printf(dev, "can not if_alloc()\n");
156 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
158 mtx_init(&sc->vx_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
160 callout_init_mtx(&sc->vx_callout, &sc->vx_mtx, 0);
161 callout_init_mtx(&sc->vx_watchdog, &sc->vx_mtx, 0);
163 CSR_WRITE_2(sc, VX_COMMAND, GLOBAL_RESET);
169 * Read the station address from the eeprom
172 for (i = 0; i < 3; i++) {
175 if (vx_busy_eeprom(sc)) {
176 mtx_destroy(&sc->vx_mtx);
180 CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND, EEPROM_CMD_RD
181 | (EEPROM_OEM_ADDR0 + i));
182 if (vx_busy_eeprom(sc)) {
183 mtx_destroy(&sc->vx_mtx);
187 x = CSR_READ_2(sc, VX_W0_EEPROM_DATA);
188 eaddr[(i << 1)] = x >> 8;
189 eaddr[(i << 1) + 1] = x;
192 ifp->if_snd.ifq_maxlen = ifqmaxlen;
193 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
194 ifp->if_start = vx_start;
195 ifp->if_ioctl = vx_ioctl;
196 ifp->if_init = vx_init;
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;
272 callout_reset(&sc->vx_watchdog, hz, vx_watchdog, sc);
274 /* Attempt to start output, if any. */
275 vx_start_locked(ifp);
279 vx_setfilter(struct vx_softc *sc)
281 struct ifnet *ifp = sc->vx_ifp;
284 GO_WINDOW(1); /* Window 1 is operating window */
285 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER |
286 FIL_INDIVIDUAL | FIL_BRDCST | FIL_MULTICAST |
287 ((ifp->if_flags & IFF_PROMISC) ? FIL_PROMISC : 0));
291 vx_getlink(struct vx_softc *sc)
296 sc->vx_connectors = CSR_READ_2(sc, VX_W3_RESET_OPT) & 0x7f;
297 for (n = 0, k = 0; k < VX_CONNECTORS; k++) {
298 if (sc->vx_connectors & conn_tab[k].bit) {
301 printf("%s", conn_tab[k].name);
305 if (sc->vx_connectors == 0) {
306 printf("no connectors!\n");
311 (CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & INTERNAL_CONNECTOR_MASK)
312 >> INTERNAL_CONNECTOR_BITS;
313 if (sc->vx_connector & 0x10) {
314 sc->vx_connector &= 0x0f;
315 printf("[*%s*]", conn_tab[(int)sc->vx_connector].name);
316 printf(": disable 'auto select' with DOS util!\n");
318 printf("[*%s*]\n", conn_tab[(int)sc->vx_connector].name);
323 vx_setlink(struct vx_softc *sc)
325 struct ifnet *ifp = sc->vx_ifp;
327 char *reason, *warning;
328 static int prev_flags;
329 static signed char prev_conn = -1;
333 prev_conn = sc->vx_connector;
338 * Now behavior was slightly changed:
340 * if any of flags link[0-2] is used and its connector is
341 * physically present the following connectors are used:
343 * link0 - AUI * highest precedence
345 * link2 - UTP * lowest precedence
347 * If none of them is specified then
348 * connector specified in the EEPROM is used
349 * (if present on card or UTP if not).
351 i = sc->vx_connector; /* default in EEPROM */
355 if (ifp->if_flags & IFF_LINK0) {
356 if (sc->vx_connectors & conn_tab[CONNECTOR_AUI].bit) {
360 warning = "aui not present! (link0)";
362 } else if (ifp->if_flags & IFF_LINK1) {
363 if (sc->vx_connectors & conn_tab[CONNECTOR_BNC].bit) {
367 warning = "bnc not present! (link1)";
369 } else if (ifp->if_flags & IFF_LINK2) {
370 if (sc->vx_connectors & conn_tab[CONNECTOR_UTP].bit) {
374 warning = "utp not present! (link2)";
376 } else if ((sc->vx_connectors & conn_tab[(int)sc->vx_connector].bit) == 0) {
377 warning = "strange connector type in EEPROM.";
381 /* Avoid unnecessary message. */
382 k = (prev_flags ^ ifp->if_flags) & (IFF_LINK0 | IFF_LINK1 | IFF_LINK2);
383 if ((k != 0) || (prev_conn != i)) {
385 if_printf(ifp, "warning: %s\n", warning);
386 if_printf(ifp, "selected %s. (%s)\n", conn_tab[i].name, reason);
388 /* Set the selected connector. */
390 j = CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
391 CSR_WRITE_4(sc, VX_W3_INTERNAL_CFG, j | (i << INTERNAL_CONNECTOR_BITS));
393 /* First, disable all. */
394 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
397 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, 0);
399 /* Second, enable the selected one. */
403 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, ENABLE_UTP);
406 CSR_WRITE_2(sc, VX_COMMAND, START_TRANSCEIVER);
412 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, LINKBEAT_ENABLE);
414 default: /* AUI and MII fall here */
419 prev_flags = ifp->if_flags;
424 vx_start(struct ifnet *ifp)
426 struct vx_softc *sc = ifp->if_softc;
429 vx_start_locked(ifp);
434 vx_start_locked(struct ifnet *ifp)
436 struct vx_softc *sc = ifp->if_softc;
442 /* Don't transmit if interface is busy or not running */
443 if ((sc->vx_ifp->if_drv_flags &
444 (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING)
448 /* Sneak a peek at the next packet */
449 m = ifp->if_snd.ifq_head;
453 /* We need to use m->m_pkthdr.len, so require the header */
455 len = m->m_pkthdr.len;
460 * The 3c509 automatically pads short packets to minimum ethernet
461 * length, but we drop packets that are too large. Perhaps we should
462 * truncate them instead?
464 if (len + pad > ETHER_MAX_LEN) {
465 /* packet is obviously too large: toss it */
467 IF_DEQUEUE(&ifp->if_snd, m);
472 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
473 CSR_WRITE_2(sc, VX_COMMAND,
474 SET_TX_AVAIL_THRESH | ((len + pad + 4) >> 2));
475 /* not enough room in FIFO - make sure */
476 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
477 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
482 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_AVAIL_THRESH | (8188 >> 2));
483 IF_DEQUEUE(&ifp->if_snd, m);
484 if (m == NULL) /* not really needed */
488 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_START_THRESH |
489 ((len / 4 + sc->vx_tx_start_thresh) >> 2));
491 BPF_MTAP(sc->vx_ifp, m);
494 * Do the output at splhigh() so that an interrupt from another device
495 * won't cause a FIFO underrun.
497 * XXX: Can't enforce that anymore.
500 CSR_WRITE_4(sc, VX_W1_TX_PIO_WR_1, len | TX_INDICATE);
504 bus_space_write_multi_4(sc->vx_bst, sc->vx_bsh,
505 VX_W1_TX_PIO_WR_1, (u_int32_t *)mtod(m, caddr_t),
508 bus_space_write_multi_1(sc->vx_bst, sc->vx_bsh,
510 mtod(m, caddr_t) + (m->m_len & ~3), m->m_len & 3);
514 CSR_WRITE_1(sc, VX_W1_TX_PIO_WR_1, 0); /* Padding */
520 if ((CSR_READ_2(sc, VX_W1_RX_STATUS) & ERR_INCOMPLETE) == 0) {
521 /* We received a complete packet. */
523 if ((CSR_READ_2(sc, VX_STATUS) & S_INTR_LATCH) == 0) {
525 * No interrupt, read the packet and continue
526 * Is this supposed to happen? Is my motherboard
532 * Got an interrupt, return so that it gets
537 /* Check if we are stuck and reset [see XXX comment] */
539 if (ifp->if_flags & IFF_DEBUG)
540 if_printf(ifp, "adapter reset\n");
549 * XXX: The 3c509 card can get in a mode where both the fifo status bit
550 * FIFOS_RX_OVERRUN and the status bit ERR_INCOMPLETE are set
551 * We detect this situation and we reset the adapter.
552 * It happens at times when there is a lot of broadcast traffic
553 * on the cable (once in a blue moon).
556 vx_status(struct vx_softc *sc)
564 * Check the FIFO status and act accordingly
567 fifost = CSR_READ_2(sc, VX_W4_FIFO_DIAG);
571 if (fifost & FIFOS_RX_UNDERRUN) {
572 if (ifp->if_flags & IFF_DEBUG)
573 if_printf(ifp, "RX underrun\n");
577 if (fifost & FIFOS_RX_STATUS_OVERRUN) {
578 if (ifp->if_flags & IFF_DEBUG)
579 if_printf(ifp, "RX Status overrun\n");
582 if (fifost & FIFOS_RX_OVERRUN) {
583 if (ifp->if_flags & IFF_DEBUG)
584 if_printf(ifp, "RX overrun\n");
587 if (fifost & FIFOS_TX_OVERRUN) {
588 if (ifp->if_flags & IFF_DEBUG)
589 if_printf(ifp, "TX overrun\n");
597 vx_txstat(struct vx_softc *sc)
605 * We need to read+write TX_STATUS until we get a 0 status
606 * in order to turn off the interrupt flag.
609 while ((i = CSR_READ_1(sc, VX_W1_TX_STATUS)) & TXS_COMPLETE) {
610 CSR_WRITE_1(sc, VX_W1_TX_STATUS, 0x0);
612 if (i & TXS_JABBER) {
614 if (ifp->if_flags & IFF_DEBUG)
615 if_printf(ifp, "jabber (%x)\n", i);
617 } else if (i & TXS_UNDERRUN) {
619 if (ifp->if_flags & IFF_DEBUG)
620 if_printf(ifp, "fifo underrun (%x) @%d\n", i,
621 sc->vx_tx_start_thresh);
622 if (sc->vx_tx_succ_ok < 100)
623 sc->vx_tx_start_thresh =
625 sc->vx_tx_start_thresh + 20);
626 sc->vx_tx_succ_ok = 0;
628 } else if (i & TXS_MAX_COLLISION) {
629 ++ifp->if_collisions;
630 CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE);
631 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
633 sc->vx_tx_succ_ok = (sc->vx_tx_succ_ok + 1) & 127;
638 vx_intr(void *voidsc)
641 struct vx_softc *sc = voidsc;
642 struct ifnet *ifp = sc->vx_ifp;
646 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
648 status = CSR_READ_2(sc, VX_STATUS);
650 if ((status & (S_TX_COMPLETE | S_TX_AVAIL |
651 S_RX_COMPLETE | S_CARD_FAILURE)) == 0)
655 * Acknowledge any interrupts. It's important that we do this
656 * first, since there would otherwise be a race condition.
657 * Due to the i386 interrupt queueing, we may get spurious
658 * interrupts occasionally.
660 CSR_WRITE_2(sc, VX_COMMAND, ACK_INTR | status);
662 if (status & S_RX_COMPLETE)
664 if (status & S_TX_AVAIL) {
666 sc->vx_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
667 vx_start_locked(sc->vx_ifp);
669 if (status & S_CARD_FAILURE) {
670 if_printf(ifp, "adapter failure (%x)\n", status);
675 if (status & S_TX_COMPLETE) {
678 vx_start_locked(ifp);
683 /* no more interrupts */
688 vx_read(struct vx_softc *sc)
690 struct ifnet *ifp = sc->vx_ifp;
692 struct ether_header *eh;
696 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
699 if (ifp->if_flags & IFF_DEBUG) {
700 int err = len & ERR_MASK;
703 if (len & ERR_INCOMPLETE)
704 s = "incomplete packet";
705 else if (err == ERR_OVERRUN)
706 s = "packet overrun";
707 else if (err == ERR_RUNT)
709 else if (err == ERR_ALIGNMENT)
711 else if (err == ERR_CRC)
713 else if (err == ERR_OVERSIZE)
714 s = "oversized packet";
715 else if (err == ERR_DRIBBLE)
719 if_printf(ifp, "%s\n", s);
721 if (len & ERR_INCOMPLETE)
728 len &= RX_BYTES_MASK; /* Lower 11 bits = RX bytes. */
730 /* Pull packet off interface. */
741 m0 = m_devget(mtod(m, char *), m->m_pkthdr.len, ETHER_ALIGN,
751 /* We assume the header fit entirely in one mbuf. */
752 eh = mtod(m, struct ether_header *);
755 * XXX: Some cards seem to be in promiscous mode all the time.
756 * we need to make sure we only get our own stuff always.
760 if (!(ifp->if_flags & IFF_PROMISC)
761 && (eh->ether_dhost[0] & 1) == 0 /* !mcast and !bcast */
762 && bcmp(eh->ether_dhost, IF_LLADDR(sc->vx_ifp),
763 ETHER_ADDR_LEN) != 0) {
768 (*ifp->if_input)(ifp, m);
772 * In periods of high traffic we can actually receive enough
773 * packets so that the fifo overrun bit will be set at this point,
774 * even though we just read a packet. In this case we
775 * are not going to receive any more interrupts. We check for
776 * this condition and read again until the fifo is not full.
777 * We could simplify this test by not using vx_status(), but
778 * rechecking the RX_STATUS register directly. This test could
779 * result in unnecessary looping in cases where there is a new
780 * packet but the fifo is not full, but it will not fix the
783 * Even with this improvement, we still get packet overrun errors
784 * which are hurting performance. Maybe when I get some more time
785 * I'll modify vx_read() so that it can handle RX_EARLY interrupts.
788 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
789 /* Check if we are stuck and reset [see XXX comment] */
790 if (len & ERR_INCOMPLETE) {
791 if (ifp->if_flags & IFF_DEBUG)
792 if_printf(ifp, "adapter reset\n");
801 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
805 vx_get(struct vx_softc *sc, u_int totlen)
807 struct ifnet *ifp = sc->vx_ifp;
808 struct mbuf *top, **mp, *m;
812 m = sc->vx_mb[sc->vx_next_mb];
813 sc->vx_mb[sc->vx_next_mb] = NULL;
815 MGETHDR(m, M_NOWAIT, MT_DATA);
819 /* If the queue is no longer full, refill. */
820 if (sc->vx_last_mb == sc->vx_next_mb &&
821 sc->vx_buffill_pending == 0) {
822 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill,
824 sc->vx_buffill_pending = 1;
826 /* Convert one of our saved mbuf's. */
827 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
828 m->m_data = m->m_pktdat;
829 m->m_flags = M_PKTHDR;
830 bzero(&m->m_pkthdr, sizeof(m->m_pkthdr));
832 m->m_pkthdr.rcvif = ifp;
833 m->m_pkthdr.len = totlen;
839 * We read the packet at splhigh() so that an interrupt from another
840 * device doesn't cause the card's buffer to overflow while we're
841 * reading it. We may still lose packets at other times.
843 * XXX: Can't enforce this anymore.
847 * Since we don't set allowLargePackets bit in MacControl register,
848 * we can assume that totlen <= 1500bytes.
849 * The while loop will be performed iff we have a packet with
850 * MLEN < m_len < MINCLSIZE.
854 m = sc->vx_mb[sc->vx_next_mb];
855 sc->vx_mb[sc->vx_next_mb] = NULL;
857 MGET(m, M_NOWAIT, MT_DATA);
863 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
867 if (totlen >= MINCLSIZE) {
869 if (m->m_flags & M_EXT)
872 len = min(totlen, len);
874 bus_space_read_multi_4(sc->vx_bst, sc->vx_bsh,
875 VX_W1_RX_PIO_RD_1, mtod(m, u_int32_t *), len / 4);
877 bus_space_read_multi_1(sc->vx_bst, sc->vx_bsh,
878 VX_W1_RX_PIO_RD_1, mtod(m, u_int8_t *) + (len & ~3),
887 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
894 vx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
896 struct vx_softc *sc = ifp->if_softc;
897 struct ifreq *ifr = (struct ifreq *) data;
903 if ((ifp->if_flags & IFF_UP) == 0 &&
904 (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
906 * If interface is marked up and it is stopped, then
910 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
911 } else if ((ifp->if_flags & IFF_UP) != 0 &&
912 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
914 * If interface is marked up and it is stopped, then
920 * deal with flags changes:
921 * IFF_MULTICAST, IFF_PROMISC,
922 * IFF_LINK0, IFF_LINK1,
932 * Set the interface MTU.
935 if (ifr->ifr_mtu > ETHERMTU) {
938 ifp->if_mtu = ifr->ifr_mtu;
946 * Multicast list has changed; set the hardware filter
957 error = ether_ioctl(ifp, cmd, data);
965 vx_reset(struct vx_softc *sc)
974 vx_watchdog(void *arg)
981 callout_reset(&sc->vx_watchdog, hz, vx_watchdog, sc);
982 if (sc->vx_timer == 0 || --sc->vx_timer > 0)
986 if (ifp->if_flags & IFF_DEBUG)
987 if_printf(ifp, "device timeout\n");
988 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
989 vx_start_locked(ifp);
994 vx_stop(struct vx_softc *sc)
999 callout_stop(&sc->vx_watchdog);
1001 CSR_WRITE_2(sc, VX_COMMAND, RX_DISABLE);
1002 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
1004 CSR_WRITE_2(sc, VX_COMMAND, TX_DISABLE);
1005 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
1007 CSR_WRITE_2(sc, VX_COMMAND, RX_RESET);
1009 CSR_WRITE_2(sc, VX_COMMAND, TX_RESET);
1011 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
1012 CSR_WRITE_2(sc, VX_COMMAND, SET_RD_0_MASK);
1013 CSR_WRITE_2(sc, VX_COMMAND, SET_INTR_MASK);
1014 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER);
1020 vx_busy_eeprom(struct vx_softc *sc)
1025 j = CSR_READ_2(sc, VX_W0_EEPROM_COMMAND);
1026 if (j & EEPROM_BUSY)
1032 if_printf(sc->vx_ifp, "eeprom failed to come ready\n");
1039 vx_mbuf_fill(void *sp)
1041 struct vx_softc *sc = (struct vx_softc *)sp;
1047 if (sc->vx_mb[i] == NULL)
1048 MGET(sc->vx_mb[i], M_NOWAIT, MT_DATA);
1049 if (sc->vx_mb[i] == NULL)
1051 i = (i + 1) % MAX_MBS;
1052 } while (i != sc->vx_next_mb);
1054 /* If the queue was not filled, try again. */
1055 if (sc->vx_last_mb != sc->vx_next_mb) {
1056 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill, sc);
1057 sc->vx_buffill_pending = 1;
1059 sc->vx_buffill_pending = 0;
1064 vx_mbuf_empty(struct vx_softc *sc)
1069 for (i = 0; i < MAX_MBS; i++) {
1071 m_freem(sc->vx_mb[i]);
1072 sc->vx_mb[i] = NULL;
1075 sc->vx_last_mb = sc->vx_next_mb = 0;
1076 if (sc->vx_buffill_pending != 0)
1077 callout_stop(&sc->vx_callout);