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. */
209 gone_by_fcp101_dev(dev);
215 * The order in here seems important. Otherwise we may not receive
221 struct vx_softc *sc = (struct vx_softc *)xsc;
229 vx_init_locked(struct vx_softc *sc)
231 struct ifnet *ifp = sc->vx_ifp;
240 for (i = 0; i < 6; i++) /* Reload the ether_addr. */
241 CSR_WRITE_1(sc, VX_W2_ADDR_0 + i, IF_LLADDR(sc->vx_ifp)[i]);
243 CSR_WRITE_2(sc, VX_COMMAND, RX_RESET);
245 CSR_WRITE_2(sc, VX_COMMAND, TX_RESET);
248 GO_WINDOW(1); /* Window 1 is operating window */
249 for (i = 0; i < 31; i++)
250 CSR_READ_1(sc, VX_W1_TX_STATUS);
252 CSR_WRITE_2(sc, VX_COMMAND, SET_RD_0_MASK | S_CARD_FAILURE |
253 S_RX_COMPLETE | S_TX_COMPLETE | S_TX_AVAIL);
254 CSR_WRITE_2(sc, VX_COMMAND, SET_INTR_MASK | S_CARD_FAILURE |
255 S_RX_COMPLETE | S_TX_COMPLETE | S_TX_AVAIL);
258 * Attempt to get rid of any stray interrupts that occurred during
259 * configuration. On the i386 this isn't possible because one may
260 * already be queued. However, a single stray interrupt is
263 CSR_WRITE_2(sc, VX_COMMAND, ACK_INTR | 0xff);
268 CSR_WRITE_2(sc, VX_COMMAND, RX_ENABLE);
269 CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE);
273 /* Interface is now `running', with no output active. */
274 ifp->if_drv_flags |= IFF_DRV_RUNNING;
275 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
276 callout_reset(&sc->vx_watchdog, hz, vx_watchdog, sc);
278 /* Attempt to start output, if any. */
279 vx_start_locked(ifp);
283 vx_setfilter(struct vx_softc *sc)
285 struct ifnet *ifp = sc->vx_ifp;
288 GO_WINDOW(1); /* Window 1 is operating window */
289 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER |
290 FIL_INDIVIDUAL | FIL_BRDCST | FIL_MULTICAST |
291 ((ifp->if_flags & IFF_PROMISC) ? FIL_PROMISC : 0));
295 vx_getlink(struct vx_softc *sc)
300 sc->vx_connectors = CSR_READ_2(sc, VX_W3_RESET_OPT) & 0x7f;
301 for (n = 0, k = 0; k < VX_CONNECTORS; k++) {
302 if (sc->vx_connectors & conn_tab[k].bit) {
305 printf("%s", conn_tab[k].name);
309 if (sc->vx_connectors == 0) {
310 printf("no connectors!\n");
315 (CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & INTERNAL_CONNECTOR_MASK)
316 >> INTERNAL_CONNECTOR_BITS;
317 if (sc->vx_connector & 0x10) {
318 sc->vx_connector &= 0x0f;
319 printf("[*%s*]", conn_tab[(int)sc->vx_connector].name);
320 printf(": disable 'auto select' with DOS util!\n");
322 printf("[*%s*]\n", conn_tab[(int)sc->vx_connector].name);
327 vx_setlink(struct vx_softc *sc)
329 struct ifnet *ifp = sc->vx_ifp;
331 char *reason, *warning;
332 static int prev_flags;
333 static signed char prev_conn = -1;
337 prev_conn = sc->vx_connector;
342 * Now behavior was slightly changed:
344 * if any of flags link[0-2] is used and its connector is
345 * physically present the following connectors are used:
347 * link0 - AUI * highest precedence
349 * link2 - UTP * lowest precedence
351 * If none of them is specified then
352 * connector specified in the EEPROM is used
353 * (if present on card or UTP if not).
355 i = sc->vx_connector; /* default in EEPROM */
359 if (ifp->if_flags & IFF_LINK0) {
360 if (sc->vx_connectors & conn_tab[CONNECTOR_AUI].bit) {
364 warning = "aui not present! (link0)";
366 } else if (ifp->if_flags & IFF_LINK1) {
367 if (sc->vx_connectors & conn_tab[CONNECTOR_BNC].bit) {
371 warning = "bnc not present! (link1)";
373 } else if (ifp->if_flags & IFF_LINK2) {
374 if (sc->vx_connectors & conn_tab[CONNECTOR_UTP].bit) {
378 warning = "utp not present! (link2)";
380 } else if ((sc->vx_connectors & conn_tab[(int)sc->vx_connector].bit) == 0) {
381 warning = "strange connector type in EEPROM.";
385 /* Avoid unnecessary message. */
386 k = (prev_flags ^ ifp->if_flags) & (IFF_LINK0 | IFF_LINK1 | IFF_LINK2);
387 if ((k != 0) || (prev_conn != i)) {
389 if_printf(ifp, "warning: %s\n", warning);
390 if_printf(ifp, "selected %s. (%s)\n", conn_tab[i].name, reason);
392 /* Set the selected connector. */
394 j = CSR_READ_4(sc, VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
395 CSR_WRITE_4(sc, VX_W3_INTERNAL_CFG, j | (i << INTERNAL_CONNECTOR_BITS));
397 /* First, disable all. */
398 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
401 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, 0);
403 /* Second, enable the selected one. */
407 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, ENABLE_UTP);
410 CSR_WRITE_2(sc, VX_COMMAND, START_TRANSCEIVER);
416 CSR_WRITE_2(sc, VX_W4_MEDIA_TYPE, LINKBEAT_ENABLE);
418 default: /* AUI and MII fall here */
423 prev_flags = ifp->if_flags;
428 vx_start(struct ifnet *ifp)
430 struct vx_softc *sc = ifp->if_softc;
433 vx_start_locked(ifp);
438 vx_start_locked(struct ifnet *ifp)
440 struct vx_softc *sc = ifp->if_softc;
446 /* Don't transmit if interface is busy or not running */
447 if ((sc->vx_ifp->if_drv_flags &
448 (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING)
452 /* Sneak a peek at the next packet */
453 m = ifp->if_snd.ifq_head;
457 /* We need to use m->m_pkthdr.len, so require the header */
459 len = m->m_pkthdr.len;
464 * The 3c509 automatically pads short packets to minimum ethernet
465 * length, but we drop packets that are too large. Perhaps we should
466 * truncate them instead?
468 if (len + pad > ETHER_MAX_LEN) {
469 /* packet is obviously too large: toss it */
470 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
471 IF_DEQUEUE(&ifp->if_snd, m);
476 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
477 CSR_WRITE_2(sc, VX_COMMAND,
478 SET_TX_AVAIL_THRESH | ((len + pad + 4) >> 2));
479 /* not enough room in FIFO - make sure */
480 if (CSR_READ_2(sc, VX_W1_FREE_TX) < len + pad + 4) {
481 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
486 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_AVAIL_THRESH | (8188 >> 2));
487 IF_DEQUEUE(&ifp->if_snd, m);
488 if (m == NULL) /* not really needed */
492 CSR_WRITE_2(sc, VX_COMMAND, SET_TX_START_THRESH |
493 ((len / 4 + sc->vx_tx_start_thresh) >> 2));
495 BPF_MTAP(sc->vx_ifp, m);
498 * Do the output at splhigh() so that an interrupt from another device
499 * won't cause a FIFO underrun.
501 * XXX: Can't enforce that anymore.
504 CSR_WRITE_4(sc, VX_W1_TX_PIO_WR_1, len | TX_INDICATE);
508 bus_space_write_multi_4(sc->vx_bst, sc->vx_bsh,
509 VX_W1_TX_PIO_WR_1, (u_int32_t *)mtod(m, caddr_t),
512 bus_space_write_multi_1(sc->vx_bst, sc->vx_bsh,
514 mtod(m, caddr_t) + (m->m_len & ~3), m->m_len & 3);
518 CSR_WRITE_1(sc, VX_W1_TX_PIO_WR_1, 0); /* Padding */
520 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
524 if ((CSR_READ_2(sc, VX_W1_RX_STATUS) & ERR_INCOMPLETE) == 0) {
525 /* We received a complete packet. */
527 if ((CSR_READ_2(sc, VX_STATUS) & S_INTR_LATCH) == 0) {
529 * No interrupt, read the packet and continue
530 * Is this supposed to happen? Is my motherboard
536 * Got an interrupt, return so that it gets
541 /* Check if we are stuck and reset [see XXX comment] */
543 if (ifp->if_flags & IFF_DEBUG)
544 if_printf(ifp, "adapter reset\n");
553 * XXX: The 3c509 card can get in a mode where both the fifo status bit
554 * FIFOS_RX_OVERRUN and the status bit ERR_INCOMPLETE are set
555 * We detect this situation and we reset the adapter.
556 * It happens at times when there is a lot of broadcast traffic
557 * on the cable (once in a blue moon).
560 vx_status(struct vx_softc *sc)
568 * Check the FIFO status and act accordingly
571 fifost = CSR_READ_2(sc, VX_W4_FIFO_DIAG);
575 if (fifost & FIFOS_RX_UNDERRUN) {
576 if (ifp->if_flags & IFF_DEBUG)
577 if_printf(ifp, "RX underrun\n");
581 if (fifost & FIFOS_RX_STATUS_OVERRUN) {
582 if (ifp->if_flags & IFF_DEBUG)
583 if_printf(ifp, "RX Status overrun\n");
586 if (fifost & FIFOS_RX_OVERRUN) {
587 if (ifp->if_flags & IFF_DEBUG)
588 if_printf(ifp, "RX overrun\n");
591 if (fifost & FIFOS_TX_OVERRUN) {
592 if (ifp->if_flags & IFF_DEBUG)
593 if_printf(ifp, "TX overrun\n");
601 vx_txstat(struct vx_softc *sc)
609 * We need to read+write TX_STATUS until we get a 0 status
610 * in order to turn off the interrupt flag.
613 while ((i = CSR_READ_1(sc, VX_W1_TX_STATUS)) & TXS_COMPLETE) {
614 CSR_WRITE_1(sc, VX_W1_TX_STATUS, 0x0);
616 if (i & TXS_JABBER) {
617 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
618 if (ifp->if_flags & IFF_DEBUG)
619 if_printf(ifp, "jabber (%x)\n", i);
621 } else if (i & TXS_UNDERRUN) {
622 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
623 if (ifp->if_flags & IFF_DEBUG)
624 if_printf(ifp, "fifo underrun (%x) @%d\n", i,
625 sc->vx_tx_start_thresh);
626 if (sc->vx_tx_succ_ok < 100)
627 sc->vx_tx_start_thresh =
629 sc->vx_tx_start_thresh + 20);
630 sc->vx_tx_succ_ok = 0;
632 } else if (i & TXS_MAX_COLLISION) {
633 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1);
634 CSR_WRITE_2(sc, VX_COMMAND, TX_ENABLE);
635 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
637 sc->vx_tx_succ_ok = (sc->vx_tx_succ_ok + 1) & 127;
642 vx_intr(void *voidsc)
645 struct vx_softc *sc = voidsc;
646 struct ifnet *ifp = sc->vx_ifp;
650 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
652 status = CSR_READ_2(sc, VX_STATUS);
654 if ((status & (S_TX_COMPLETE | S_TX_AVAIL |
655 S_RX_COMPLETE | S_CARD_FAILURE)) == 0)
659 * Acknowledge any interrupts. It's important that we do this
660 * first, since there would otherwise be a race condition.
661 * Due to the i386 interrupt queueing, we may get spurious
662 * interrupts occasionally.
664 CSR_WRITE_2(sc, VX_COMMAND, ACK_INTR | status);
666 if (status & S_RX_COMPLETE)
668 if (status & S_TX_AVAIL) {
670 sc->vx_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
671 vx_start_locked(sc->vx_ifp);
673 if (status & S_CARD_FAILURE) {
674 if_printf(ifp, "adapter failure (%x)\n", status);
679 if (status & S_TX_COMPLETE) {
682 vx_start_locked(ifp);
687 /* no more interrupts */
692 vx_read(struct vx_softc *sc)
694 struct ifnet *ifp = sc->vx_ifp;
696 struct ether_header *eh;
700 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
703 if (ifp->if_flags & IFF_DEBUG) {
704 int err = len & ERR_MASK;
707 if (len & ERR_INCOMPLETE)
708 s = "incomplete packet";
709 else if (err == ERR_OVERRUN)
710 s = "packet overrun";
711 else if (err == ERR_RUNT)
713 else if (err == ERR_ALIGNMENT)
715 else if (err == ERR_CRC)
717 else if (err == ERR_OVERSIZE)
718 s = "oversized packet";
719 else if (err == ERR_DRIBBLE)
723 if_printf(ifp, "%s\n", s);
725 if (len & ERR_INCOMPLETE)
729 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
732 len &= RX_BYTES_MASK; /* Lower 11 bits = RX bytes. */
734 /* Pull packet off interface. */
737 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
740 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
745 m0 = m_devget(mtod(m, char *), m->m_pkthdr.len, ETHER_ALIGN,
748 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
755 /* We assume the header fit entirely in one mbuf. */
756 eh = mtod(m, struct ether_header *);
759 * XXX: Some cards seem to be in promiscuous mode all the time.
760 * we need to make sure we only get our own stuff always.
764 if (!(ifp->if_flags & IFF_PROMISC)
765 && (eh->ether_dhost[0] & 1) == 0 /* !mcast and !bcast */
766 && bcmp(eh->ether_dhost, IF_LLADDR(sc->vx_ifp),
767 ETHER_ADDR_LEN) != 0) {
772 (*ifp->if_input)(ifp, m);
776 * In periods of high traffic we can actually receive enough
777 * packets so that the fifo overrun bit will be set at this point,
778 * even though we just read a packet. In this case we
779 * are not going to receive any more interrupts. We check for
780 * this condition and read again until the fifo is not full.
781 * We could simplify this test by not using vx_status(), but
782 * rechecking the RX_STATUS register directly. This test could
783 * result in unnecessary looping in cases where there is a new
784 * packet but the fifo is not full, but it will not fix the
787 * Even with this improvement, we still get packet overrun errors
788 * which are hurting performance. Maybe when I get some more time
789 * I'll modify vx_read() so that it can handle RX_EARLY interrupts.
792 len = CSR_READ_2(sc, VX_W1_RX_STATUS);
793 /* Check if we are stuck and reset [see XXX comment] */
794 if (len & ERR_INCOMPLETE) {
795 if (ifp->if_flags & IFF_DEBUG)
796 if_printf(ifp, "adapter reset\n");
805 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
809 vx_get(struct vx_softc *sc, u_int totlen)
811 struct ifnet *ifp = sc->vx_ifp;
812 struct mbuf *top, **mp, *m;
816 m = sc->vx_mb[sc->vx_next_mb];
817 sc->vx_mb[sc->vx_next_mb] = NULL;
819 MGETHDR(m, M_NOWAIT, MT_DATA);
823 /* If the queue is no longer full, refill. */
824 if (sc->vx_last_mb == sc->vx_next_mb &&
825 sc->vx_buffill_pending == 0) {
826 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill,
828 sc->vx_buffill_pending = 1;
830 /* Convert one of our saved mbuf's. */
831 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
832 m->m_data = m->m_pktdat;
833 m->m_flags = M_PKTHDR;
834 bzero(&m->m_pkthdr, sizeof(m->m_pkthdr));
836 m->m_pkthdr.rcvif = ifp;
837 m->m_pkthdr.len = totlen;
843 * We read the packet at splhigh() so that an interrupt from another
844 * device doesn't cause the card's buffer to overflow while we're
845 * reading it. We may still lose packets at other times.
847 * XXX: Can't enforce this anymore.
851 * Since we don't set allowLargePackets bit in MacControl register,
852 * we can assume that totlen <= 1500bytes.
853 * The while loop will be performed iff we have a packet with
854 * MLEN < m_len < MINCLSIZE.
858 m = sc->vx_mb[sc->vx_next_mb];
859 sc->vx_mb[sc->vx_next_mb] = NULL;
861 MGET(m, M_NOWAIT, MT_DATA);
867 sc->vx_next_mb = (sc->vx_next_mb + 1) % MAX_MBS;
871 if (totlen >= MINCLSIZE) {
872 if (MCLGET(m, M_NOWAIT))
875 len = min(totlen, len);
877 bus_space_read_multi_4(sc->vx_bst, sc->vx_bsh,
878 VX_W1_RX_PIO_RD_1, mtod(m, u_int32_t *), len / 4);
880 bus_space_read_multi_1(sc->vx_bst, sc->vx_bsh,
881 VX_W1_RX_PIO_RD_1, mtod(m, u_int8_t *) + (len & ~3),
890 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
897 vx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
899 struct vx_softc *sc = ifp->if_softc;
900 struct ifreq *ifr = (struct ifreq *) data;
906 if ((ifp->if_flags & IFF_UP) == 0 &&
907 (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
909 * If interface is marked up and it is stopped, then
913 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
914 } else if ((ifp->if_flags & IFF_UP) != 0 &&
915 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
917 * If interface is marked up and it is stopped, then
923 * deal with flags changes:
924 * IFF_MULTICAST, IFF_PROMISC,
925 * IFF_LINK0, IFF_LINK1,
935 * Set the interface MTU.
938 if (ifr->ifr_mtu > ETHERMTU) {
941 ifp->if_mtu = ifr->ifr_mtu;
949 * Multicast list has changed; set the hardware filter
960 error = ether_ioctl(ifp, cmd, data);
968 vx_reset(struct vx_softc *sc)
977 vx_watchdog(void *arg)
984 callout_reset(&sc->vx_watchdog, hz, vx_watchdog, sc);
985 if (sc->vx_timer == 0 || --sc->vx_timer > 0)
989 if (ifp->if_flags & IFF_DEBUG)
990 if_printf(ifp, "device timeout\n");
991 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
992 vx_start_locked(ifp);
997 vx_stop(struct vx_softc *sc)
1002 callout_stop(&sc->vx_watchdog);
1004 CSR_WRITE_2(sc, VX_COMMAND, RX_DISABLE);
1005 CSR_WRITE_2(sc, VX_COMMAND, RX_DISCARD_TOP_PACK);
1007 CSR_WRITE_2(sc, VX_COMMAND, TX_DISABLE);
1008 CSR_WRITE_2(sc, VX_COMMAND, STOP_TRANSCEIVER);
1010 CSR_WRITE_2(sc, VX_COMMAND, RX_RESET);
1012 CSR_WRITE_2(sc, VX_COMMAND, TX_RESET);
1014 CSR_WRITE_2(sc, VX_COMMAND, C_INTR_LATCH);
1015 CSR_WRITE_2(sc, VX_COMMAND, SET_RD_0_MASK);
1016 CSR_WRITE_2(sc, VX_COMMAND, SET_INTR_MASK);
1017 CSR_WRITE_2(sc, VX_COMMAND, SET_RX_FILTER);
1023 vx_busy_eeprom(struct vx_softc *sc)
1028 j = CSR_READ_2(sc, VX_W0_EEPROM_COMMAND);
1029 if (j & EEPROM_BUSY)
1035 if_printf(sc->vx_ifp, "eeprom failed to come ready\n");
1042 vx_mbuf_fill(void *sp)
1044 struct vx_softc *sc = (struct vx_softc *)sp;
1050 if (sc->vx_mb[i] == NULL)
1051 MGET(sc->vx_mb[i], M_NOWAIT, MT_DATA);
1052 if (sc->vx_mb[i] == NULL)
1054 i = (i + 1) % MAX_MBS;
1055 } while (i != sc->vx_next_mb);
1057 /* If the queue was not filled, try again. */
1058 if (sc->vx_last_mb != sc->vx_next_mb) {
1059 callout_reset(&sc->vx_callout, hz / 100, vx_mbuf_fill, sc);
1060 sc->vx_buffill_pending = 1;
1062 sc->vx_buffill_pending = 0;
1067 vx_mbuf_empty(struct vx_softc *sc)
1072 for (i = 0; i < MAX_MBS; i++) {
1074 m_freem(sc->vx_mb[i]);
1075 sc->vx_mb[i] = NULL;
1078 sc->vx_last_mb = sc->vx_next_mb = 0;
1079 if (sc->vx_buffill_pending != 0)
1080 callout_stop(&sc->vx_callout);