2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Herb Peyerl.
18 * 4. The name of Herb Peyerl may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 * Created from if_ep.c driver by Fred Gray (fgray@rice.edu) to support
44 * Modified from the FreeBSD 1.1.5.1 version by:
46 * INRIA - Sophia Antipolis, France
47 * avega@sophia.inria.fr
51 * Promiscuous mode added and interrupt logic slightly changed
52 * to reduce the number of adapter failures. Transceiver select
53 * logic changed to use value from EEPROM. Autoconfiguration
57 * Chelindbank (Chelyabinsk, Russia)
58 * babkin@hq.icb.chel.su
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/sockio.h>
65 #include <sys/kernel.h>
66 #include <sys/malloc.h>
68 #include <sys/socket.h>
71 #include <net/if_var.h>
73 #include <net/ethernet.h>
74 #include <net/if_dl.h>
75 #include <net/if_types.h>
77 #include <machine/bus.h>
83 #include <dev/vx/if_vxreg.h>
84 #include <dev/vx/if_vxvar.h>
86 #define ETHER_MAX_LEN 1518
87 #define ETHER_ADDR_LEN 6
90 static struct connector_entry {
93 } conn_tab[VX_CONNECTORS] = {
95 #define CONNECTOR_UTP 0
99 #define CONNECTOR_AUI 1
107 #define CONNECTOR_BNC 3
111 #define CONNECTOR_TX 4
115 #define CONNECTOR_FX 5
119 #define CONNECTOR_MII 6
128 static void vx_txstat(struct vx_softc *);
129 static int vx_status(struct vx_softc *);
130 static void vx_init(void *);
131 static void vx_init_locked(struct vx_softc *);
132 static int vx_ioctl(struct ifnet *, u_long, caddr_t);
133 static void vx_start(struct ifnet *);
134 static void vx_start_locked(struct ifnet *);
135 static void vx_watchdog(void *);
136 static void vx_reset(struct vx_softc *);
137 static void vx_read(struct vx_softc *);
138 static struct mbuf *vx_get(struct vx_softc *, u_int);
139 static void vx_mbuf_fill(void *);
140 static void vx_mbuf_empty(struct vx_softc *);
141 static void vx_setfilter(struct vx_softc *);
142 static void vx_getlink(struct vx_softc *);
143 static void vx_setlink(struct vx_softc *);
146 vx_attach(device_t dev)
148 struct vx_softc *sc = device_get_softc(dev);
153 ifp = sc->vx_ifp = if_alloc(IFT_ETHER);
155 device_printf(dev, "can not if_alloc()\n");
158 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
160 mtx_init(&sc->vx_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
162 callout_init_mtx(&sc->vx_callout, &sc->vx_mtx, 0);
163 callout_init_mtx(&sc->vx_watchdog, &sc->vx_mtx, 0);
165 CSR_WRITE_2(sc, VX_COMMAND, GLOBAL_RESET);
171 * Read the station address from the eeprom
174 for (i = 0; i < 3; i++) {
177 if (vx_busy_eeprom(sc)) {
178 mtx_destroy(&sc->vx_mtx);
182 CSR_WRITE_2(sc, VX_W0_EEPROM_COMMAND, EEPROM_CMD_RD
183 | (EEPROM_OEM_ADDR0 + i));
184 if (vx_busy_eeprom(sc)) {
185 mtx_destroy(&sc->vx_mtx);
189 x = CSR_READ_2(sc, VX_W0_EEPROM_DATA);
190 eaddr[(i << 1)] = x >> 8;
191 eaddr[(i << 1) + 1] = x;
194 ifp->if_snd.ifq_maxlen = ifqmaxlen;
195 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
196 ifp->if_start = vx_start;
197 ifp->if_ioctl = vx_ioctl;
198 ifp->if_init = vx_init;
201 ether_ifattach(ifp, eaddr);
203 sc->vx_tx_start_thresh = 20; /* probably a good starting point. */
213 * The order in here seems important. Otherwise we may not receive
219 struct vx_softc *sc = (struct vx_softc *)xsc;
227 vx_init_locked(struct vx_softc *sc)
229 struct ifnet *ifp = sc->vx_ifp;
238 for (i = 0; i < 6; i++) /* Reload the ether_addr. */
239 CSR_WRITE_1(sc, VX_W2_ADDR_0 + i, IF_LLADDR(sc->vx_ifp)[i]);
241 CSR_WRITE_2(sc, VX_COMMAND, RX_RESET);
243 CSR_WRITE_2(sc, VX_COMMAND, TX_RESET);
246 GO_WINDOW(1); /* Window 1 is operating window */
247 for (i = 0; i < 31; i++)
248 CSR_READ_1(sc, VX_W1_TX_STATUS);
250 CSR_WRITE_2(sc, VX_COMMAND, SET_RD_0_MASK | S_CARD_FAILURE |
251 S_RX_COMPLETE | S_TX_COMPLETE | S_TX_AVAIL);
252 CSR_WRITE_2(sc, VX_COMMAND, SET_INTR_MASK | S_CARD_FAILURE |
253 S_RX_COMPLETE | S_TX_COMPLETE | S_TX_AVAIL);
256 * Attempt to get rid of any stray interrupts that occurred during
257 * configuration. On the i386 this isn't possible because one may
258 * already be queued. However, a single stray interrupt is
261 CSR_WRITE_2(sc, VX_COMMAND, ACK_INTR | 0xff);
266 CSR_WRITE_2(sc, VX_COMMAND, RX_ENABLE);
267 CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE);
271 /* Interface is now `running', with no output active. */
272 ifp->if_drv_flags |= IFF_DRV_RUNNING;
273 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
274 callout_reset(&sc->vx_watchdog, hz, vx_watchdog, sc);
276 /* Attempt to start output, if any. */
277 vx_start_locked(ifp);
281 vx_setfilter(struct vx_softc *sc)
283 struct ifnet *ifp = sc->vx_ifp;
286 GO_WINDOW(1); /* Window 1 is operating window */
287 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER |
288 FIL_INDIVIDUAL | FIL_BRDCST | FIL_MULTICAST |
289 ((ifp->if_flags & IFF_PROMISC) ? FIL_PROMISC : 0));
293 vx_getlink(struct vx_softc *sc)
298 sc->vx_connectors = CSR_READ_2(sc, VX_W3_RESET_OPT) & 0x7f;
299 for (n = 0, k = 0; k < VX_CONNECTORS; k++) {
300 if (sc->vx_connectors & conn_tab[k].bit) {
303 printf("%s", conn_tab[k].name);
307 if (sc->vx_connectors == 0) {
308 printf("no connectors!\n");
313 (CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & INTERNAL_CONNECTOR_MASK)
314 >> INTERNAL_CONNECTOR_BITS;
315 if (sc->vx_connector & 0x10) {
316 sc->vx_connector &= 0x0f;
317 printf("[*%s*]", conn_tab[(int)sc->vx_connector].name);
318 printf(": disable 'auto select' with DOS util!\n");
320 printf("[*%s*]\n", conn_tab[(int)sc->vx_connector].name);
325 vx_setlink(struct vx_softc *sc)
327 struct ifnet *ifp = sc->vx_ifp;
329 char *reason, *warning;
330 static int prev_flags;
331 static signed char prev_conn = -1;
335 prev_conn = sc->vx_connector;
340 * Now behavior was slightly changed:
342 * if any of flags link[0-2] is used and its connector is
343 * physically present the following connectors are used:
345 * link0 - AUI * highest precedence
347 * link2 - UTP * lowest precedence
349 * If none of them is specified then
350 * connector specified in the EEPROM is used
351 * (if present on card or UTP if not).
353 i = sc->vx_connector; /* default in EEPROM */
357 if (ifp->if_flags & IFF_LINK0) {
358 if (sc->vx_connectors & conn_tab[CONNECTOR_AUI].bit) {
362 warning = "aui not present! (link0)";
364 } else if (ifp->if_flags & IFF_LINK1) {
365 if (sc->vx_connectors & conn_tab[CONNECTOR_BNC].bit) {
369 warning = "bnc not present! (link1)";
371 } else if (ifp->if_flags & IFF_LINK2) {
372 if (sc->vx_connectors & conn_tab[CONNECTOR_UTP].bit) {
376 warning = "utp not present! (link2)";
378 } else if ((sc->vx_connectors & conn_tab[(int)sc->vx_connector].bit) == 0) {
379 warning = "strange connector type in EEPROM.";
383 /* Avoid unnecessary message. */
384 k = (prev_flags ^ ifp->if_flags) & (IFF_LINK0 | IFF_LINK1 | IFF_LINK2);
385 if ((k != 0) || (prev_conn != i)) {
387 if_printf(ifp, "warning: %s\n", warning);
388 if_printf(ifp, "selected %s. (%s)\n", conn_tab[i].name, reason);
390 /* Set the selected connector. */
392 j = CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
393 CSR_WRITE_4(sc, VX_W3_INTERNAL_CFG, j | (i << INTERNAL_CONNECTOR_BITS));
395 /* First, disable all. */
396 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
399 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, 0);
401 /* Second, enable the selected one. */
405 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, ENABLE_UTP);
408 CSR_WRITE_2(sc, VX_COMMAND, START_TRANSCEIVER);
414 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, LINKBEAT_ENABLE);
416 default: /* AUI and MII fall here */
421 prev_flags = ifp->if_flags;
426 vx_start(struct ifnet *ifp)
428 struct vx_softc *sc = ifp->if_softc;
431 vx_start_locked(ifp);
436 vx_start_locked(struct ifnet *ifp)
438 struct vx_softc *sc = ifp->if_softc;
444 /* Don't transmit if interface is busy or not running */
445 if ((sc->vx_ifp->if_drv_flags &
446 (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING)
450 /* Sneak a peek at the next packet */
451 m = ifp->if_snd.ifq_head;
455 /* We need to use m->m_pkthdr.len, so require the header */
457 len = m->m_pkthdr.len;
462 * The 3c509 automatically pads short packets to minimum ethernet
463 * length, but we drop packets that are too large. Perhaps we should
464 * truncate them instead?
466 if (len + pad > ETHER_MAX_LEN) {
467 /* packet is obviously too large: toss it */
468 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
469 IF_DEQUEUE(&ifp->if_snd, m);
474 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
475 CSR_WRITE_2(sc, VX_COMMAND,
476 SET_TX_AVAIL_THRESH | ((len + pad + 4) >> 2));
477 /* not enough room in FIFO - make sure */
478 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
479 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
484 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_AVAIL_THRESH | (8188 >> 2));
485 IF_DEQUEUE(&ifp->if_snd, m);
486 if (m == NULL) /* not really needed */
490 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_START_THRESH |
491 ((len / 4 + sc->vx_tx_start_thresh) >> 2));
493 BPF_MTAP(sc->vx_ifp, m);
496 * Do the output at splhigh() so that an interrupt from another device
497 * won't cause a FIFO underrun.
499 * XXX: Can't enforce that anymore.
502 CSR_WRITE_4(sc, VX_W1_TX_PIO_WR_1, len | TX_INDICATE);
506 bus_space_write_multi_4(sc->vx_bst, sc->vx_bsh,
507 VX_W1_TX_PIO_WR_1, (u_int32_t *)mtod(m, caddr_t),
510 bus_space_write_multi_1(sc->vx_bst, sc->vx_bsh,
512 mtod(m, caddr_t) + (m->m_len & ~3), m->m_len & 3);
516 CSR_WRITE_1(sc, VX_W1_TX_PIO_WR_1, 0); /* Padding */
518 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
522 if ((CSR_READ_2(sc, VX_W1_RX_STATUS) & ERR_INCOMPLETE) == 0) {
523 /* We received a complete packet. */
525 if ((CSR_READ_2(sc, VX_STATUS) & S_INTR_LATCH) == 0) {
527 * No interrupt, read the packet and continue
528 * Is this supposed to happen? Is my motherboard
534 * Got an interrupt, return so that it gets
539 /* Check if we are stuck and reset [see XXX comment] */
541 if (ifp->if_flags & IFF_DEBUG)
542 if_printf(ifp, "adapter reset\n");
551 * XXX: The 3c509 card can get in a mode where both the fifo status bit
552 * FIFOS_RX_OVERRUN and the status bit ERR_INCOMPLETE are set
553 * We detect this situation and we reset the adapter.
554 * It happens at times when there is a lot of broadcast traffic
555 * on the cable (once in a blue moon).
558 vx_status(struct vx_softc *sc)
566 * Check the FIFO status and act accordingly
569 fifost = CSR_READ_2(sc, VX_W4_FIFO_DIAG);
573 if (fifost & FIFOS_RX_UNDERRUN) {
574 if (ifp->if_flags & IFF_DEBUG)
575 if_printf(ifp, "RX underrun\n");
579 if (fifost & FIFOS_RX_STATUS_OVERRUN) {
580 if (ifp->if_flags & IFF_DEBUG)
581 if_printf(ifp, "RX Status overrun\n");
584 if (fifost & FIFOS_RX_OVERRUN) {
585 if (ifp->if_flags & IFF_DEBUG)
586 if_printf(ifp, "RX overrun\n");
589 if (fifost & FIFOS_TX_OVERRUN) {
590 if (ifp->if_flags & IFF_DEBUG)
591 if_printf(ifp, "TX overrun\n");
599 vx_txstat(struct vx_softc *sc)
607 * We need to read+write TX_STATUS until we get a 0 status
608 * in order to turn off the interrupt flag.
611 while ((i = CSR_READ_1(sc, VX_W1_TX_STATUS)) & TXS_COMPLETE) {
612 CSR_WRITE_1(sc, VX_W1_TX_STATUS, 0x0);
614 if (i & TXS_JABBER) {
615 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
616 if (ifp->if_flags & IFF_DEBUG)
617 if_printf(ifp, "jabber (%x)\n", i);
619 } else if (i & TXS_UNDERRUN) {
620 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
621 if (ifp->if_flags & IFF_DEBUG)
622 if_printf(ifp, "fifo underrun (%x) @%d\n", i,
623 sc->vx_tx_start_thresh);
624 if (sc->vx_tx_succ_ok < 100)
625 sc->vx_tx_start_thresh =
627 sc->vx_tx_start_thresh + 20);
628 sc->vx_tx_succ_ok = 0;
630 } else if (i & TXS_MAX_COLLISION) {
631 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1);
632 CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE);
633 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
635 sc->vx_tx_succ_ok = (sc->vx_tx_succ_ok + 1) & 127;
640 vx_intr(void *voidsc)
643 struct vx_softc *sc = voidsc;
644 struct ifnet *ifp = sc->vx_ifp;
648 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
650 status = CSR_READ_2(sc, VX_STATUS);
652 if ((status & (S_TX_COMPLETE | S_TX_AVAIL |
653 S_RX_COMPLETE | S_CARD_FAILURE)) == 0)
657 * Acknowledge any interrupts. It's important that we do this
658 * first, since there would otherwise be a race condition.
659 * Due to the i386 interrupt queueing, we may get spurious
660 * interrupts occasionally.
662 CSR_WRITE_2(sc, VX_COMMAND, ACK_INTR | status);
664 if (status & S_RX_COMPLETE)
666 if (status & S_TX_AVAIL) {
668 sc->vx_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
669 vx_start_locked(sc->vx_ifp);
671 if (status & S_CARD_FAILURE) {
672 if_printf(ifp, "adapter failure (%x)\n", status);
677 if (status & S_TX_COMPLETE) {
680 vx_start_locked(ifp);
685 /* no more interrupts */
690 vx_read(struct vx_softc *sc)
692 struct ifnet *ifp = sc->vx_ifp;
694 struct ether_header *eh;
698 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
701 if (ifp->if_flags & IFF_DEBUG) {
702 int err = len & ERR_MASK;
705 if (len & ERR_INCOMPLETE)
706 s = "incomplete packet";
707 else if (err == ERR_OVERRUN)
708 s = "packet overrun";
709 else if (err == ERR_RUNT)
711 else if (err == ERR_ALIGNMENT)
713 else if (err == ERR_CRC)
715 else if (err == ERR_OVERSIZE)
716 s = "oversized packet";
717 else if (err == ERR_DRIBBLE)
721 if_printf(ifp, "%s\n", s);
723 if (len & ERR_INCOMPLETE)
727 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
730 len &= RX_BYTES_MASK; /* Lower 11 bits = RX bytes. */
732 /* Pull packet off interface. */
735 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
738 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
743 m0 = m_devget(mtod(m, char *), m->m_pkthdr.len, ETHER_ALIGN,
746 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
753 /* We assume the header fit entirely in one mbuf. */
754 eh = mtod(m, struct ether_header *);
757 * XXX: Some cards seem to be in promiscuous mode all the time.
758 * we need to make sure we only get our own stuff always.
762 if (!(ifp->if_flags & IFF_PROMISC)
763 && (eh->ether_dhost[0] & 1) == 0 /* !mcast and !bcast */
764 && bcmp(eh->ether_dhost, IF_LLADDR(sc->vx_ifp),
765 ETHER_ADDR_LEN) != 0) {
770 (*ifp->if_input)(ifp, m);
774 * In periods of high traffic we can actually receive enough
775 * packets so that the fifo overrun bit will be set at this point,
776 * even though we just read a packet. In this case we
777 * are not going to receive any more interrupts. We check for
778 * this condition and read again until the fifo is not full.
779 * We could simplify this test by not using vx_status(), but
780 * rechecking the RX_STATUS register directly. This test could
781 * result in unnecessary looping in cases where there is a new
782 * packet but the fifo is not full, but it will not fix the
785 * Even with this improvement, we still get packet overrun errors
786 * which are hurting performance. Maybe when I get some more time
787 * I'll modify vx_read() so that it can handle RX_EARLY interrupts.
790 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
791 /* Check if we are stuck and reset [see XXX comment] */
792 if (len & ERR_INCOMPLETE) {
793 if (ifp->if_flags & IFF_DEBUG)
794 if_printf(ifp, "adapter reset\n");
803 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
807 vx_get(struct vx_softc *sc, u_int totlen)
809 struct ifnet *ifp = sc->vx_ifp;
810 struct mbuf *top, **mp, *m;
814 m = sc->vx_mb[sc->vx_next_mb];
815 sc->vx_mb[sc->vx_next_mb] = NULL;
817 MGETHDR(m, M_NOWAIT, MT_DATA);
821 /* If the queue is no longer full, refill. */
822 if (sc->vx_last_mb == sc->vx_next_mb &&
823 sc->vx_buffill_pending == 0) {
824 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill,
826 sc->vx_buffill_pending = 1;
828 /* Convert one of our saved mbuf's. */
829 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
830 m->m_data = m->m_pktdat;
831 m->m_flags = M_PKTHDR;
832 bzero(&m->m_pkthdr, sizeof(m->m_pkthdr));
834 m->m_pkthdr.rcvif = ifp;
835 m->m_pkthdr.len = totlen;
841 * We read the packet at splhigh() so that an interrupt from another
842 * device doesn't cause the card's buffer to overflow while we're
843 * reading it. We may still lose packets at other times.
845 * XXX: Can't enforce this anymore.
849 * Since we don't set allowLargePackets bit in MacControl register,
850 * we can assume that totlen <= 1500bytes.
851 * The while loop will be performed iff we have a packet with
852 * MLEN < m_len < MINCLSIZE.
856 m = sc->vx_mb[sc->vx_next_mb];
857 sc->vx_mb[sc->vx_next_mb] = NULL;
859 MGET(m, M_NOWAIT, MT_DATA);
865 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
869 if (totlen >= MINCLSIZE) {
870 if (MCLGET(m, M_NOWAIT))
873 len = min(totlen, len);
875 bus_space_read_multi_4(sc->vx_bst, sc->vx_bsh,
876 VX_W1_RX_PIO_RD_1, mtod(m, u_int32_t *), len / 4);
878 bus_space_read_multi_1(sc->vx_bst, sc->vx_bsh,
879 VX_W1_RX_PIO_RD_1, mtod(m, u_int8_t *) + (len & ~3),
888 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
895 vx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
897 struct vx_softc *sc = ifp->if_softc;
898 struct ifreq *ifr = (struct ifreq *) data;
904 if ((ifp->if_flags & IFF_UP) == 0 &&
905 (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
907 * If interface is marked up and it is stopped, then
911 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
912 } else if ((ifp->if_flags & IFF_UP) != 0 &&
913 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
915 * If interface is marked up and it is stopped, then
921 * deal with flags changes:
922 * IFF_MULTICAST, IFF_PROMISC,
923 * IFF_LINK0, IFF_LINK1,
933 * Set the interface MTU.
936 if (ifr->ifr_mtu > ETHERMTU) {
939 ifp->if_mtu = ifr->ifr_mtu;
947 * Multicast list has changed; set the hardware filter
958 error = ether_ioctl(ifp, cmd, data);
966 vx_reset(struct vx_softc *sc)
975 vx_watchdog(void *arg)
982 callout_reset(&sc->vx_watchdog, hz, vx_watchdog, sc);
983 if (sc->vx_timer == 0 || --sc->vx_timer > 0)
987 if (ifp->if_flags & IFF_DEBUG)
988 if_printf(ifp, "device timeout\n");
989 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
990 vx_start_locked(ifp);
995 vx_stop(struct vx_softc *sc)
1000 callout_stop(&sc->vx_watchdog);
1002 CSR_WRITE_2(sc, VX_COMMAND, RX_DISABLE);
1003 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
1005 CSR_WRITE_2(sc, VX_COMMAND, TX_DISABLE);
1006 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
1008 CSR_WRITE_2(sc, VX_COMMAND, RX_RESET);
1010 CSR_WRITE_2(sc, VX_COMMAND, TX_RESET);
1012 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
1013 CSR_WRITE_2(sc, VX_COMMAND, SET_RD_0_MASK);
1014 CSR_WRITE_2(sc, VX_COMMAND, SET_INTR_MASK);
1015 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER);
1021 vx_busy_eeprom(struct vx_softc *sc)
1026 j = CSR_READ_2(sc, VX_W0_EEPROM_COMMAND);
1027 if (j & EEPROM_BUSY)
1033 if_printf(sc->vx_ifp, "eeprom failed to come ready\n");
1040 vx_mbuf_fill(void *sp)
1042 struct vx_softc *sc = (struct vx_softc *)sp;
1048 if (sc->vx_mb[i] == NULL)
1049 MGET(sc->vx_mb[i], M_NOWAIT, MT_DATA);
1050 if (sc->vx_mb[i] == NULL)
1052 i = (i + 1) % MAX_MBS;
1053 } while (i != sc->vx_next_mb);
1055 /* If the queue was not filled, try again. */
1056 if (sc->vx_last_mb != sc->vx_next_mb) {
1057 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill, sc);
1058 sc->vx_buffill_pending = 1;
1060 sc->vx_buffill_pending = 0;
1065 vx_mbuf_empty(struct vx_softc *sc)
1070 for (i = 0; i < MAX_MBS; i++) {
1072 m_freem(sc->vx_mb[i]);
1073 sc->vx_mb[i] = NULL;
1076 sc->vx_last_mb = sc->vx_next_mb = 0;
1077 if (sc->vx_buffill_pending != 0)
1078 callout_stop(&sc->vx_callout);