2 * Copyright (c) 1997, 1998
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
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 Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * VIA Rhine fast ethernet PCI NIC driver
39 * Supports various network adapters based on the VIA Rhine
40 * and Rhine II PCI controllers, including the D-Link DFE530TX.
41 * Datasheets are available at http://www.via.com.tw.
43 * Written by Bill Paul <wpaul@ctr.columbia.edu>
44 * Electrical Engineering Department
45 * Columbia University, New York City
49 * The VIA Rhine controllers are similar in some respects to the
50 * the DEC tulip chips, except less complicated. The controller
51 * uses an MII bus and an external physical layer interface. The
52 * receiver has a one entry perfect filter and a 64-bit hash table
53 * multicast filter. Transmit and receive descriptors are similar
56 * The Rhine has a serious flaw in its transmit DMA mechanism:
57 * transmit buffers must be longword aligned. Unfortunately,
58 * FreeBSD doesn't guarantee that mbufs will be filled in starting
59 * at longword boundaries, so we have to do a buffer copy before
63 #ifdef HAVE_KERNEL_OPTION_HEADERS
64 #include "opt_device_polling.h"
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/sockio.h>
71 #include <sys/malloc.h>
72 #include <sys/kernel.h>
73 #include <sys/module.h>
74 #include <sys/socket.h>
77 #include <net/if_arp.h>
78 #include <net/ethernet.h>
79 #include <net/if_dl.h>
80 #include <net/if_media.h>
81 #include <net/if_types.h>
85 #include <vm/vm.h> /* for vtophys */
86 #include <vm/pmap.h> /* for vtophys */
87 #include <machine/bus.h>
88 #include <machine/resource.h>
92 #include <dev/mii/mii.h>
93 #include <dev/mii/miivar.h>
95 #include <dev/pci/pcireg.h>
96 #include <dev/pci/pcivar.h>
100 #include <pci/if_vrreg.h>
102 MODULE_DEPEND(vr, pci, 1, 1, 1);
103 MODULE_DEPEND(vr, ether, 1, 1, 1);
104 MODULE_DEPEND(vr, miibus, 1, 1, 1);
106 /* "device miibus" required. See GENERIC if you get errors here. */
107 #include "miibus_if.h"
112 * Various supported device vendors/types and their names.
114 static struct vr_type vr_devs[] = {
115 { VIA_VENDORID, VIA_DEVICEID_RHINE,
116 "VIA VT3043 Rhine I 10/100BaseTX" },
117 { VIA_VENDORID, VIA_DEVICEID_RHINE_II,
118 "VIA VT86C100A Rhine II 10/100BaseTX" },
119 { VIA_VENDORID, VIA_DEVICEID_RHINE_II_2,
120 "VIA VT6102 Rhine II 10/100BaseTX" },
121 { VIA_VENDORID, VIA_DEVICEID_RHINE_III,
122 "VIA VT6105 Rhine III 10/100BaseTX" },
123 { VIA_VENDORID, VIA_DEVICEID_RHINE_III_M,
124 "VIA VT6105M Rhine III 10/100BaseTX" },
125 { DELTA_VENDORID, DELTA_DEVICEID_RHINE_II,
126 "Delta Electronics Rhine II 10/100BaseTX" },
127 { ADDTRON_VENDORID, ADDTRON_DEVICEID_RHINE_II,
128 "Addtron Technology Rhine II 10/100BaseTX" },
132 static int vr_probe(device_t);
133 static int vr_attach(device_t);
134 static int vr_detach(device_t);
136 static int vr_newbuf(struct vr_softc *, struct vr_chain_onefrag *,
138 static int vr_encap(struct vr_softc *, struct vr_chain *, struct mbuf * );
140 static void vr_rxeof(struct vr_softc *);
141 static void vr_rxeoc(struct vr_softc *);
142 static void vr_txeof(struct vr_softc *);
143 static void vr_tick(void *);
144 static void vr_intr(void *);
145 static void vr_start(struct ifnet *);
146 static void vr_start_locked(struct ifnet *);
147 static int vr_ioctl(struct ifnet *, u_long, caddr_t);
148 static void vr_init(void *);
149 static void vr_init_locked(struct vr_softc *);
150 static void vr_stop(struct vr_softc *);
151 static void vr_watchdog(struct ifnet *);
152 static void vr_shutdown(device_t);
153 static int vr_ifmedia_upd(struct ifnet *);
154 static void vr_ifmedia_sts(struct ifnet *, struct ifmediareq *);
157 static void vr_mii_sync(struct vr_softc *);
158 static void vr_mii_send(struct vr_softc *, uint32_t, int);
160 static int vr_mii_readreg(struct vr_softc *, struct vr_mii_frame *);
161 static int vr_mii_writereg(struct vr_softc *, struct vr_mii_frame *);
162 static int vr_miibus_readreg(device_t, uint16_t, uint16_t);
163 static int vr_miibus_writereg(device_t, uint16_t, uint16_t, uint16_t);
164 static void vr_miibus_statchg(device_t);
166 static void vr_setcfg(struct vr_softc *, int);
167 static void vr_setmulti(struct vr_softc *);
168 static void vr_reset(struct vr_softc *);
169 static int vr_list_rx_init(struct vr_softc *);
170 static int vr_list_tx_init(struct vr_softc *);
173 #define VR_RES SYS_RES_IOPORT
174 #define VR_RID VR_PCI_LOIO
176 #define VR_RES SYS_RES_MEMORY
177 #define VR_RID VR_PCI_LOMEM
180 static device_method_t vr_methods[] = {
181 /* Device interface */
182 DEVMETHOD(device_probe, vr_probe),
183 DEVMETHOD(device_attach, vr_attach),
184 DEVMETHOD(device_detach, vr_detach),
185 DEVMETHOD(device_shutdown, vr_shutdown),
188 DEVMETHOD(bus_print_child, bus_generic_print_child),
189 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
192 DEVMETHOD(miibus_readreg, vr_miibus_readreg),
193 DEVMETHOD(miibus_writereg, vr_miibus_writereg),
194 DEVMETHOD(miibus_statchg, vr_miibus_statchg),
199 static driver_t vr_driver = {
202 sizeof(struct vr_softc)
205 static devclass_t vr_devclass;
207 DRIVER_MODULE(vr, pci, vr_driver, vr_devclass, 0, 0);
208 DRIVER_MODULE(miibus, vr, miibus_driver, miibus_devclass, 0, 0);
210 #define VR_SETBIT(sc, reg, x) \
211 CSR_WRITE_1(sc, reg, \
212 CSR_READ_1(sc, reg) | (x))
214 #define VR_CLRBIT(sc, reg, x) \
215 CSR_WRITE_1(sc, reg, \
216 CSR_READ_1(sc, reg) & ~(x))
218 #define VR_SETBIT16(sc, reg, x) \
219 CSR_WRITE_2(sc, reg, \
220 CSR_READ_2(sc, reg) | (x))
222 #define VR_CLRBIT16(sc, reg, x) \
223 CSR_WRITE_2(sc, reg, \
224 CSR_READ_2(sc, reg) & ~(x))
226 #define VR_SETBIT32(sc, reg, x) \
227 CSR_WRITE_4(sc, reg, \
228 CSR_READ_4(sc, reg) | (x))
230 #define VR_CLRBIT32(sc, reg, x) \
231 CSR_WRITE_4(sc, reg, \
232 CSR_READ_4(sc, reg) & ~(x))
235 CSR_WRITE_1(sc, VR_MIICMD, \
236 CSR_READ_1(sc, VR_MIICMD) | (x))
239 CSR_WRITE_1(sc, VR_MIICMD, \
240 CSR_READ_1(sc, VR_MIICMD) & ~(x))
244 * Sync the PHYs by setting data bit and strobing the clock 32 times.
247 vr_mii_sync(struct vr_softc *sc)
251 SIO_SET(VR_MIICMD_DIR|VR_MIICMD_DATAIN);
253 for (i = 0; i < 32; i++) {
254 SIO_SET(VR_MIICMD_CLK);
256 SIO_CLR(VR_MIICMD_CLK);
262 * Clock a series of bits through the MII.
265 vr_mii_send(struct vr_softc *sc, uint32_t bits, int cnt)
269 SIO_CLR(VR_MIICMD_CLK);
271 for (i = (0x1 << (cnt - 1)); i; i >>= 1) {
273 SIO_SET(VR_MIICMD_DATAIN);
275 SIO_CLR(VR_MIICMD_DATAIN);
278 SIO_CLR(VR_MIICMD_CLK);
280 SIO_SET(VR_MIICMD_CLK);
286 * Read an PHY register through the MII.
289 vr_mii_readreg(struct vr_softc *sc, struct vr_mii_frame *frame)
294 /* Set up frame for RX. */
295 frame->mii_stdelim = VR_MII_STARTDELIM;
296 frame->mii_opcode = VR_MII_READOP;
297 frame->mii_turnaround = 0;
300 CSR_WRITE_1(sc, VR_MIICMD, 0);
301 VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_DIRECTPGM);
303 /* Turn on data xmit. */
304 SIO_SET(VR_MIICMD_DIR);
308 /* Send command/address info. */
309 vr_mii_send(sc, frame->mii_stdelim, 2);
310 vr_mii_send(sc, frame->mii_opcode, 2);
311 vr_mii_send(sc, frame->mii_phyaddr, 5);
312 vr_mii_send(sc, frame->mii_regaddr, 5);
315 SIO_CLR((VR_MIICMD_CLK|VR_MIICMD_DATAIN));
317 SIO_SET(VR_MIICMD_CLK);
321 SIO_CLR(VR_MIICMD_DIR);
324 SIO_CLR(VR_MIICMD_CLK);
326 ack = CSR_READ_4(sc, VR_MIICMD) & VR_MIICMD_DATAOUT;
327 SIO_SET(VR_MIICMD_CLK);
331 * Now try reading data bits. If the ack failed, we still
332 * need to clock through 16 cycles to keep the PHY(s) in sync.
335 for(i = 0; i < 16; i++) {
336 SIO_CLR(VR_MIICMD_CLK);
338 SIO_SET(VR_MIICMD_CLK);
344 for (i = 0x8000; i; i >>= 1) {
345 SIO_CLR(VR_MIICMD_CLK);
348 if (CSR_READ_4(sc, VR_MIICMD) & VR_MIICMD_DATAOUT)
349 frame->mii_data |= i;
352 SIO_SET(VR_MIICMD_CLK);
357 SIO_CLR(VR_MIICMD_CLK);
359 SIO_SET(VR_MIICMD_CLK);
370 /* Set the PHY address. */
371 CSR_WRITE_1(sc, VR_PHYADDR, (CSR_READ_1(sc, VR_PHYADDR)& 0xe0)|
374 /* Set the register address. */
375 CSR_WRITE_1(sc, VR_MIIADDR, frame->mii_regaddr);
376 VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_READ_ENB);
378 for (i = 0; i < 10000; i++) {
379 if ((CSR_READ_1(sc, VR_MIICMD) & VR_MIICMD_READ_ENB) == 0)
383 frame->mii_data = CSR_READ_2(sc, VR_MIIDATA);
391 * Write to a PHY register through the MII.
394 vr_mii_writereg(struct vr_softc *sc, struct vr_mii_frame *frame)
397 CSR_WRITE_1(sc, VR_MIICMD, 0);
398 VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_DIRECTPGM);
400 /* Set up frame for TX. */
401 frame->mii_stdelim = VR_MII_STARTDELIM;
402 frame->mii_opcode = VR_MII_WRITEOP;
403 frame->mii_turnaround = VR_MII_TURNAROUND;
405 /* Turn on data output. */
406 SIO_SET(VR_MIICMD_DIR);
410 vr_mii_send(sc, frame->mii_stdelim, 2);
411 vr_mii_send(sc, frame->mii_opcode, 2);
412 vr_mii_send(sc, frame->mii_phyaddr, 5);
413 vr_mii_send(sc, frame->mii_regaddr, 5);
414 vr_mii_send(sc, frame->mii_turnaround, 2);
415 vr_mii_send(sc, frame->mii_data, 16);
418 SIO_SET(VR_MIICMD_CLK);
420 SIO_CLR(VR_MIICMD_CLK);
424 SIO_CLR(VR_MIICMD_DIR);
432 /* Set the PHY address. */
433 CSR_WRITE_1(sc, VR_PHYADDR, (CSR_READ_1(sc, VR_PHYADDR)& 0xe0)|
436 /* Set the register address and data to write. */
437 CSR_WRITE_1(sc, VR_MIIADDR, frame->mii_regaddr);
438 CSR_WRITE_2(sc, VR_MIIDATA, frame->mii_data);
440 VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_WRITE_ENB);
442 for (i = 0; i < 10000; i++) {
443 if ((CSR_READ_1(sc, VR_MIICMD) & VR_MIICMD_WRITE_ENB) == 0)
453 vr_miibus_readreg(device_t dev, uint16_t phy, uint16_t reg)
455 struct vr_mii_frame frame;
456 struct vr_softc *sc = device_get_softc(dev);
458 switch (sc->vr_revid) {
459 case REV_ID_VT6102_APOLLO:
468 bzero((char *)&frame, sizeof(frame));
469 frame.mii_phyaddr = phy;
470 frame.mii_regaddr = reg;
471 vr_mii_readreg(sc, &frame);
474 return (frame.mii_data);
478 vr_miibus_writereg(device_t dev, uint16_t phy, uint16_t reg, uint16_t data)
480 struct vr_mii_frame frame;
481 struct vr_softc *sc = device_get_softc(dev);
483 switch (sc->vr_revid) {
484 case REV_ID_VT6102_APOLLO:
491 bzero((char *)&frame, sizeof(frame));
492 frame.mii_phyaddr = phy;
493 frame.mii_regaddr = reg;
494 frame.mii_data = data;
495 vr_mii_writereg(sc, &frame);
501 vr_miibus_statchg(device_t dev)
503 struct mii_data *mii;
504 struct vr_softc *sc = device_get_softc(dev);
506 mii = device_get_softc(sc->vr_miibus);
507 vr_setcfg(sc, mii->mii_media_active);
511 * Program the 64-bit multicast hash filter.
514 vr_setmulti(struct vr_softc *sc)
516 struct ifnet *ifp = sc->vr_ifp;
518 uint32_t hashes[2] = { 0, 0 };
519 struct ifmultiaddr *ifma;
525 rxfilt = CSR_READ_1(sc, VR_RXCFG);
527 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
528 rxfilt |= VR_RXCFG_RX_MULTI;
529 CSR_WRITE_1(sc, VR_RXCFG, rxfilt);
530 CSR_WRITE_4(sc, VR_MAR0, 0xFFFFFFFF);
531 CSR_WRITE_4(sc, VR_MAR1, 0xFFFFFFFF);
535 /* First, zero out all the existing hash bits. */
536 CSR_WRITE_4(sc, VR_MAR0, 0);
537 CSR_WRITE_4(sc, VR_MAR1, 0);
539 /* Now program new ones. */
541 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
542 if (ifma->ifma_addr->sa_family != AF_LINK)
544 h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
545 ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
547 hashes[0] |= (1 << h);
549 hashes[1] |= (1 << (h - 32));
555 rxfilt |= VR_RXCFG_RX_MULTI;
557 rxfilt &= ~VR_RXCFG_RX_MULTI;
559 CSR_WRITE_4(sc, VR_MAR0, hashes[0]);
560 CSR_WRITE_4(sc, VR_MAR1, hashes[1]);
561 CSR_WRITE_1(sc, VR_RXCFG, rxfilt);
565 * In order to fiddle with the
566 * 'full-duplex' and '100Mbps' bits in the netconfig register, we
567 * first have to put the transmit and/or receive logic in the idle state.
570 vr_setcfg(struct vr_softc *sc, int media)
576 if (CSR_READ_2(sc, VR_COMMAND) & (VR_CMD_TX_ON|VR_CMD_RX_ON)) {
578 VR_CLRBIT16(sc, VR_COMMAND, (VR_CMD_TX_ON|VR_CMD_RX_ON));
581 if ((media & IFM_GMASK) == IFM_FDX)
582 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_FULLDUPLEX);
584 VR_CLRBIT16(sc, VR_COMMAND, VR_CMD_FULLDUPLEX);
587 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_TX_ON|VR_CMD_RX_ON);
591 vr_reset(struct vr_softc *sc)
595 /*VR_LOCK_ASSERT(sc);*/ /* XXX: Called during attach w/o lock. */
597 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RESET);
599 for (i = 0; i < VR_TIMEOUT; i++) {
601 if (!(CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RESET))
604 if (i == VR_TIMEOUT) {
605 if (sc->vr_revid < REV_ID_VT3065_A)
606 device_printf(sc->vr_dev, "reset never completed!\n");
608 /* Use newer force reset command */
609 device_printf(sc->vr_dev, "Using force reset command.\n");
610 VR_SETBIT(sc, VR_MISC_CR1, VR_MISCCR1_FORSRST);
614 /* Wait a little while for the chip to get its brains in order. */
619 * Probe for a VIA Rhine chip. Check the PCI vendor and device
620 * IDs against our list and return a device name if we find a match.
623 vr_probe(device_t dev)
625 struct vr_type *t = vr_devs;
627 while (t->vr_name != NULL) {
628 if ((pci_get_vendor(dev) == t->vr_vid) &&
629 (pci_get_device(dev) == t->vr_did)) {
630 device_set_desc(dev, t->vr_name);
631 return (BUS_PROBE_DEFAULT);
640 * Attach the interface. Allocate softc structures, do ifmedia
641 * setup and ethernet/BPF attach.
648 u_char eaddr[ETHER_ADDR_LEN];
651 int unit, error = 0, rid;
653 sc = device_get_softc(dev);
655 unit = device_get_unit(dev);
657 mtx_init(&sc->vr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
659 callout_init_mtx(&sc->vr_stat_callout, &sc->vr_mtx, 0);
662 * Map control/status registers.
664 pci_enable_busmaster(dev);
665 sc->vr_revid = pci_read_config(dev, VR_PCI_REVID, 4) & 0x000000FF;
668 sc->vr_res = bus_alloc_resource_any(dev, VR_RES, &rid, RF_ACTIVE);
670 if (sc->vr_res == NULL) {
671 device_printf(dev, "couldn't map ports/memory\n");
676 sc->vr_btag = rman_get_bustag(sc->vr_res);
677 sc->vr_bhandle = rman_get_bushandle(sc->vr_res);
679 /* Allocate interrupt */
681 sc->vr_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
682 RF_SHAREABLE | RF_ACTIVE);
684 if (sc->vr_irq == NULL) {
685 device_printf(dev, "couldn't map interrupt\n");
690 /* Allocate ifnet structure. */
691 ifp = sc->vr_ifp = if_alloc(IFT_ETHER);
693 device_printf(dev, "can not if_alloc()\n");
698 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
699 ifp->if_mtu = ETHERMTU;
700 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
701 ifp->if_ioctl = vr_ioctl;
702 ifp->if_start = vr_start;
703 ifp->if_watchdog = vr_watchdog;
704 ifp->if_init = vr_init;
705 IFQ_SET_MAXLEN(&ifp->if_snd, VR_TX_LIST_CNT - 1);
706 ifp->if_snd.ifq_maxlen = VR_TX_LIST_CNT - 1;
707 IFQ_SET_READY(&ifp->if_snd);
708 ifp->if_capenable = ifp->if_capabilities;
709 #ifdef DEVICE_POLLING
710 ifp->if_capabilities |= IFCAP_POLLING;
714 * Windows may put the chip in suspend mode when it
715 * shuts down. Be sure to kick it in the head to wake it
718 VR_CLRBIT(sc, VR_STICKHW, (VR_STICKHW_DS0|VR_STICKHW_DS1));
720 /* Reset the adapter. */
724 * Turn on bit2 (MIION) in PCI configuration register 0x53 during
725 * initialization and disable AUTOPOLL.
727 pci_write_config(dev, VR_PCI_MODE,
728 pci_read_config(dev, VR_PCI_MODE, 4) | (VR_MODE3_MIION << 24), 4);
729 VR_CLRBIT(sc, VR_MIICMD, VR_MIICMD_AUTOPOLL);
732 * Get station address. The way the Rhine chips work,
733 * you're not allowed to directly access the EEPROM once
734 * they've been programmed a special way. Consequently,
735 * we need to read the node address from the PAR0 and PAR1
738 VR_SETBIT(sc, VR_EECSR, VR_EECSR_LOAD);
740 for (i = 0; i < ETHER_ADDR_LEN; i++)
741 eaddr[i] = CSR_READ_1(sc, VR_PAR0 + i);
743 sc->vr_ldata = contigmalloc(sizeof(struct vr_list_data), M_DEVBUF,
744 M_NOWAIT | M_ZERO, 0, 0xffffffff, PAGE_SIZE, 0);
746 if (sc->vr_ldata == NULL) {
747 device_printf(dev, "no memory for list buffers!\n");
753 if (mii_phy_probe(dev, &sc->vr_miibus,
754 vr_ifmedia_upd, vr_ifmedia_sts)) {
755 device_printf(dev, "MII without any phy!\n");
760 /* Call MI attach routine. */
761 ether_ifattach(ifp, eaddr);
765 /* Hook interrupt last to avoid having to lock softc */
766 error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET | INTR_MPSAFE,
767 vr_intr, sc, &sc->vr_intrhand);
770 device_printf(dev, "couldn't set up irq\n");
783 * Shutdown hardware and free up resources. This can be called any
784 * time after the mutex has been initialized. It is called in both
785 * the error case in attach and the normal detach case so it needs
786 * to be careful about only freeing resources that have actually been
790 vr_detach(device_t dev)
792 struct vr_softc *sc = device_get_softc(dev);
793 struct ifnet *ifp = sc->vr_ifp;
795 KASSERT(mtx_initialized(&sc->vr_mtx), ("vr mutex not initialized"));
797 #ifdef DEVICE_POLLING
798 if (ifp->if_capenable & IFCAP_POLLING)
799 ether_poll_deregister(ifp);
802 /* These should only be active if attach succeeded */
803 if (device_is_attached(dev)) {
808 callout_drain(&sc->vr_stat_callout);
812 device_delete_child(dev, sc->vr_miibus);
813 bus_generic_detach(dev);
816 bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
818 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
820 bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
826 contigfree(sc->vr_ldata, sizeof(struct vr_list_data), M_DEVBUF);
828 mtx_destroy(&sc->vr_mtx);
834 * Initialize the transmit descriptors.
837 vr_list_tx_init(struct vr_softc *sc)
839 struct vr_chain_data *cd;
840 struct vr_list_data *ld;
845 for (i = 0; i < VR_TX_LIST_CNT; i++) {
846 cd->vr_tx_chain[i].vr_ptr = &ld->vr_tx_list[i];
847 if (i == (VR_TX_LIST_CNT - 1))
848 cd->vr_tx_chain[i].vr_nextdesc =
851 cd->vr_tx_chain[i].vr_nextdesc =
852 &cd->vr_tx_chain[i + 1];
854 cd->vr_tx_cons = cd->vr_tx_prod = &cd->vr_tx_chain[0];
861 * Initialize the RX descriptors and allocate mbufs for them. Note that
862 * we arrange the descriptors in a closed ring, so that the last descriptor
863 * points back to the first.
866 vr_list_rx_init(struct vr_softc *sc)
868 struct vr_chain_data *cd;
869 struct vr_list_data *ld;
877 for (i = 0; i < VR_RX_LIST_CNT; i++) {
878 cd->vr_rx_chain[i].vr_ptr =
879 (struct vr_desc *)&ld->vr_rx_list[i];
880 if (vr_newbuf(sc, &cd->vr_rx_chain[i], NULL) == ENOBUFS)
882 if (i == (VR_RX_LIST_CNT - 1)) {
883 cd->vr_rx_chain[i].vr_nextdesc =
885 ld->vr_rx_list[i].vr_next =
886 vtophys(&ld->vr_rx_list[0]);
888 cd->vr_rx_chain[i].vr_nextdesc =
889 &cd->vr_rx_chain[i + 1];
890 ld->vr_rx_list[i].vr_next =
891 vtophys(&ld->vr_rx_list[i + 1]);
895 cd->vr_rx_head = &cd->vr_rx_chain[0];
901 * Initialize an RX descriptor and attach an MBUF cluster.
902 * Note: the length fields are only 11 bits wide, which means the
903 * largest size we can specify is 2047. This is important because
904 * MCLBYTES is 2048, so we have to subtract one otherwise we'll
905 * overflow the field and make a mess.
908 vr_newbuf(struct vr_softc *sc, struct vr_chain_onefrag *c, struct mbuf *m)
910 struct mbuf *m_new = NULL;
913 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
917 MCLGET(m_new, M_DONTWAIT);
918 if (!(m_new->m_flags & M_EXT)) {
922 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
925 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
926 m_new->m_data = m_new->m_ext.ext_buf;
929 m_adj(m_new, sizeof(uint64_t));
932 c->vr_ptr->vr_status = VR_RXSTAT;
933 c->vr_ptr->vr_data = vtophys(mtod(m_new, caddr_t));
934 c->vr_ptr->vr_ctl = VR_RXCTL | VR_RXLEN;
940 * A frame has been uploaded: pass the resulting mbuf chain up to
941 * the higher level protocols.
944 vr_rxeof(struct vr_softc *sc)
948 struct vr_chain_onefrag *cur_rx;
955 while (!((rxstat = sc->vr_cdata.vr_rx_head->vr_ptr->vr_status) &
957 #ifdef DEVICE_POLLING
958 if (ifp->if_capenable & IFCAP_POLLING) {
959 if (sc->rxcycles <= 0)
965 cur_rx = sc->vr_cdata.vr_rx_head;
966 sc->vr_cdata.vr_rx_head = cur_rx->vr_nextdesc;
970 * If an error occurs, update stats, clear the
971 * status word and leave the mbuf cluster in place:
972 * it should simply get re-used next time this descriptor
973 * comes up in the ring.
975 if (rxstat & VR_RXSTAT_RXERR) {
977 device_printf(sc->vr_dev,
978 "rx error (%02x):", rxstat & 0x000000ff);
979 if (rxstat & VR_RXSTAT_CRCERR)
980 printf(" crc error");
981 if (rxstat & VR_RXSTAT_FRAMEALIGNERR)
982 printf(" frame alignment error\n");
983 if (rxstat & VR_RXSTAT_FIFOOFLOW)
984 printf(" FIFO overflow");
985 if (rxstat & VR_RXSTAT_GIANT)
986 printf(" received giant packet");
987 if (rxstat & VR_RXSTAT_RUNT)
988 printf(" received runt packet");
989 if (rxstat & VR_RXSTAT_BUSERR)
990 printf(" system bus error");
991 if (rxstat & VR_RXSTAT_BUFFERR)
992 printf("rx buffer error");
994 vr_newbuf(sc, cur_rx, m);
998 /* No errors; receive the packet. */
999 total_len = VR_RXBYTES(cur_rx->vr_ptr->vr_status);
1002 * XXX The VIA Rhine chip includes the CRC with every
1003 * received frame, and there's no way to turn this
1004 * behavior off (at least, I can't find anything in
1005 * the manual that explains how to do it) so we have
1006 * to trim off the CRC manually.
1008 total_len -= ETHER_CRC_LEN;
1010 m0 = m_devget(mtod(m, char *), total_len, ETHER_ALIGN, ifp,
1012 vr_newbuf(sc, cur_rx, m);
1021 (*ifp->if_input)(ifp, m);
1027 vr_rxeoc(struct vr_softc *sc)
1029 struct ifnet *ifp = sc->vr_ifp;
1036 VR_CLRBIT16(sc, VR_COMMAND, VR_CMD_RX_ON);
1039 /* Wait for receiver to stop */
1041 i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RX_ON);
1047 device_printf(sc->vr_dev, "rx shutdown error!\n");
1048 sc->vr_flags |= VR_F_RESTART;
1054 CSR_WRITE_4(sc, VR_RXADDR, vtophys(sc->vr_cdata.vr_rx_head->vr_ptr));
1055 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RX_ON);
1056 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RX_GO);
1060 * A frame was downloaded to the chip. It's safe for us to clean up
1064 vr_txeof(struct vr_softc *sc)
1066 struct vr_chain *cur_tx;
1067 struct ifnet *ifp = sc->vr_ifp;
1072 * Go through our tx list and free mbufs for those
1073 * frames that have been transmitted.
1075 cur_tx = sc->vr_cdata.vr_tx_cons;
1076 while (cur_tx->vr_mbuf != NULL) {
1080 txstat = cur_tx->vr_ptr->vr_status;
1082 if ((txstat & VR_TXSTAT_ABRT) ||
1083 (txstat & VR_TXSTAT_UDF)) {
1085 i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_TX_ON);
1087 ; /* Wait for chip to shutdown */
1089 device_printf(sc->vr_dev, "tx shutdown timeout\n");
1090 sc->vr_flags |= VR_F_RESTART;
1093 VR_TXOWN(cur_tx) = VR_TXSTAT_OWN;
1094 CSR_WRITE_4(sc, VR_TXADDR, vtophys(cur_tx->vr_ptr));
1098 if (txstat & VR_TXSTAT_OWN)
1101 if (txstat & VR_TXSTAT_ERRSUM) {
1103 if (txstat & VR_TXSTAT_DEFER)
1104 ifp->if_collisions++;
1105 if (txstat & VR_TXSTAT_LATECOLL)
1106 ifp->if_collisions++;
1109 ifp->if_collisions +=(txstat & VR_TXSTAT_COLLCNT) >> 3;
1112 m_freem(cur_tx->vr_mbuf);
1113 cur_tx->vr_mbuf = NULL;
1114 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1116 cur_tx = cur_tx->vr_nextdesc;
1118 sc->vr_cdata.vr_tx_cons = cur_tx;
1119 if (cur_tx->vr_mbuf == NULL)
1126 struct vr_softc *sc = xsc;
1127 struct mii_data *mii;
1131 if (sc->vr_flags & VR_F_RESTART) {
1132 device_printf(sc->vr_dev, "restarting\n");
1136 sc->vr_flags &= ~VR_F_RESTART;
1139 mii = device_get_softc(sc->vr_miibus);
1141 callout_reset(&sc->vr_stat_callout, hz, vr_tick, sc);
1144 #ifdef DEVICE_POLLING
1145 static poll_handler_t vr_poll;
1146 static poll_handler_t vr_poll_locked;
1149 vr_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
1151 struct vr_softc *sc = ifp->if_softc;
1154 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1155 vr_poll_locked(ifp, cmd, count);
1160 vr_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count)
1162 struct vr_softc *sc = ifp->if_softc;
1166 sc->rxcycles = count;
1169 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1170 vr_start_locked(ifp);
1172 if (cmd == POLL_AND_CHECK_STATUS) {
1175 /* Also check status register. */
1176 status = CSR_READ_2(sc, VR_ISR);
1178 CSR_WRITE_2(sc, VR_ISR, status);
1180 if ((status & VR_INTRS) == 0)
1183 if (status & VR_ISR_RX_DROPPED) {
1184 if_printf(ifp, "rx packet lost\n");
1188 if ((status & VR_ISR_RX_ERR) || (status & VR_ISR_RX_NOBUF) ||
1189 (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_OFLOW)) {
1190 if_printf(ifp, "receive error (%04x)", status);
1191 if (status & VR_ISR_RX_NOBUF)
1192 printf(" no buffers");
1193 if (status & VR_ISR_RX_OFLOW)
1194 printf(" overflow");
1195 if (status & VR_ISR_RX_DROPPED)
1196 printf(" packet lost");
1201 if ((status & VR_ISR_BUSERR) ||
1202 (status & VR_ISR_TX_UNDERRUN)) {
1208 if ((status & VR_ISR_UDFI) ||
1209 (status & VR_ISR_TX_ABRT2) ||
1210 (status & VR_ISR_TX_ABRT)) {
1212 if (sc->vr_cdata.vr_tx_cons->vr_mbuf != NULL) {
1213 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_TX_ON);
1214 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_TX_GO);
1219 #endif /* DEVICE_POLLING */
1224 struct vr_softc *sc = arg;
1225 struct ifnet *ifp = sc->vr_ifp;
1230 if (sc->suspended) {
1232 * Forcibly disable interrupts.
1233 * XXX: Mobile VIA based platforms may need
1234 * interrupt re-enable on resume.
1236 CSR_WRITE_2(sc, VR_IMR, 0x0000);
1240 #ifdef DEVICE_POLLING
1241 if (ifp->if_capenable & IFCAP_POLLING)
1245 /* Suppress unwanted interrupts. */
1246 if (!(ifp->if_flags & IFF_UP)) {
1251 /* Disable interrupts. */
1252 CSR_WRITE_2(sc, VR_IMR, 0x0000);
1255 status = CSR_READ_2(sc, VR_ISR);
1257 CSR_WRITE_2(sc, VR_ISR, status);
1259 if ((status & VR_INTRS) == 0)
1262 if (status & VR_ISR_RX_OK)
1265 if (status & VR_ISR_RX_DROPPED) {
1266 device_printf(sc->vr_dev, "rx packet lost\n");
1270 if ((status & VR_ISR_RX_ERR) || (status & VR_ISR_RX_NOBUF) ||
1271 (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_OFLOW)) {
1272 device_printf(sc->vr_dev, "receive error (%04x)", status);
1273 if (status & VR_ISR_RX_NOBUF)
1274 printf(" no buffers");
1275 if (status & VR_ISR_RX_OFLOW)
1276 printf(" overflow");
1277 if (status & VR_ISR_RX_DROPPED)
1278 printf(" packet lost");
1283 if ((status & VR_ISR_BUSERR) || (status & VR_ISR_TX_UNDERRUN)) {
1289 if ((status & VR_ISR_TX_OK) || (status & VR_ISR_TX_ABRT) ||
1290 (status & VR_ISR_TX_ABRT2) || (status & VR_ISR_UDFI)) {
1292 if ((status & VR_ISR_UDFI) ||
1293 (status & VR_ISR_TX_ABRT2) ||
1294 (status & VR_ISR_TX_ABRT)) {
1296 if (sc->vr_cdata.vr_tx_cons->vr_mbuf != NULL) {
1297 VR_SETBIT16(sc, VR_COMMAND,
1299 VR_SETBIT16(sc, VR_COMMAND,
1306 /* Re-enable interrupts. */
1307 CSR_WRITE_2(sc, VR_IMR, VR_INTRS);
1309 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1310 vr_start_locked(ifp);
1317 * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
1318 * pointers to the fragment pointers.
1321 vr_encap(struct vr_softc *sc, struct vr_chain *c, struct mbuf *m_head)
1323 struct vr_desc *f = NULL;
1328 * The VIA Rhine wants packet buffers to be longword
1329 * aligned, but very often our mbufs aren't. Rather than
1330 * waste time trying to decide when to copy and when not
1331 * to copy, just do it all the time.
1333 m = m_defrag(m_head, M_DONTWAIT);
1338 * The Rhine chip doesn't auto-pad, so we have to make
1339 * sure to pad short frames out to the minimum frame length
1342 if (m->m_len < VR_MIN_FRAMELEN) {
1343 m->m_pkthdr.len += VR_MIN_FRAMELEN - m->m_len;
1344 m->m_len = m->m_pkthdr.len;
1349 f->vr_data = vtophys(mtod(m, caddr_t));
1350 f->vr_ctl = m->m_len;
1351 f->vr_ctl |= VR_TXCTL_TLINK|VR_TXCTL_FIRSTFRAG;
1353 f->vr_ctl |= VR_TXCTL_LASTFRAG|VR_TXCTL_FINT;
1354 f->vr_next = vtophys(c->vr_nextdesc->vr_ptr);
1360 * Main transmit routine. To avoid having to do mbuf copies, we put pointers
1361 * to the mbuf data regions directly in the transmit lists. We also save a
1362 * copy of the pointers since the transmit list fragment pointers are
1363 * physical addresses.
1367 vr_start(struct ifnet *ifp)
1369 struct vr_softc *sc = ifp->if_softc;
1372 vr_start_locked(ifp);
1377 vr_start_locked(struct ifnet *ifp)
1379 struct vr_softc *sc = ifp->if_softc;
1380 struct mbuf *m_head;
1381 struct vr_chain *cur_tx;
1383 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
1386 cur_tx = sc->vr_cdata.vr_tx_prod;
1387 while (cur_tx->vr_mbuf == NULL) {
1388 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
1392 /* Pack the data into the descriptor. */
1393 if (vr_encap(sc, cur_tx, m_head)) {
1394 /* Rollback, send what we were able to encap. */
1395 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
1399 VR_TXOWN(cur_tx) = VR_TXSTAT_OWN;
1402 * If there's a BPF listener, bounce a copy of this frame
1405 BPF_MTAP(ifp, cur_tx->vr_mbuf);
1407 cur_tx = cur_tx->vr_nextdesc;
1409 if (cur_tx != sc->vr_cdata.vr_tx_prod || cur_tx->vr_mbuf != NULL) {
1410 sc->vr_cdata.vr_tx_prod = cur_tx;
1412 /* Tell the chip to start transmitting. */
1413 VR_SETBIT16(sc, VR_COMMAND, /*VR_CMD_TX_ON|*/ VR_CMD_TX_GO);
1415 /* Set a timeout in case the chip goes out to lunch. */
1418 if (cur_tx->vr_mbuf != NULL)
1419 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1426 struct vr_softc *sc = xsc;
1434 vr_init_locked(struct vr_softc *sc)
1436 struct ifnet *ifp = sc->vr_ifp;
1437 struct mii_data *mii;
1442 mii = device_get_softc(sc->vr_miibus);
1444 /* Cancel pending I/O and free all RX/TX buffers. */
1448 /* Set our station address. */
1449 for (i = 0; i < ETHER_ADDR_LEN; i++)
1450 CSR_WRITE_1(sc, VR_PAR0 + i, IF_LLADDR(sc->vr_ifp)[i]);
1453 VR_CLRBIT(sc, VR_BCR0, VR_BCR0_DMA_LENGTH);
1454 VR_SETBIT(sc, VR_BCR0, VR_BCR0_DMA_STORENFWD);
1457 * BCR0 and BCR1 can override the RXCFG and TXCFG registers,
1458 * so we must set both.
1460 VR_CLRBIT(sc, VR_BCR0, VR_BCR0_RX_THRESH);
1461 VR_SETBIT(sc, VR_BCR0, VR_BCR0_RXTHRESH128BYTES);
1463 VR_CLRBIT(sc, VR_BCR1, VR_BCR1_TX_THRESH);
1464 VR_SETBIT(sc, VR_BCR1, VR_BCR1_TXTHRESHSTORENFWD);
1466 VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_THRESH);
1467 VR_SETBIT(sc, VR_RXCFG, VR_RXTHRESH_128BYTES);
1469 VR_CLRBIT(sc, VR_TXCFG, VR_TXCFG_TX_THRESH);
1470 VR_SETBIT(sc, VR_TXCFG, VR_TXTHRESH_STORENFWD);
1472 /* Init circular RX list. */
1473 if (vr_list_rx_init(sc) == ENOBUFS) {
1474 device_printf(sc->vr_dev,
1475 "initialization failed: no memory for rx buffers\n");
1480 /* Init tx descriptors. */
1481 vr_list_tx_init(sc);
1483 /* If we want promiscuous mode, set the allframes bit. */
1484 if (ifp->if_flags & IFF_PROMISC)
1485 VR_SETBIT(sc, VR_RXCFG, VR_RXCFG_RX_PROMISC);
1487 VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_PROMISC);
1489 /* Set capture broadcast bit to capture broadcast frames. */
1490 if (ifp->if_flags & IFF_BROADCAST)
1491 VR_SETBIT(sc, VR_RXCFG, VR_RXCFG_RX_BROAD);
1493 VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_BROAD);
1496 * Program the multicast filter, if necessary.
1501 * Load the address of the RX list.
1503 CSR_WRITE_4(sc, VR_RXADDR, vtophys(sc->vr_cdata.vr_rx_head->vr_ptr));
1505 /* Enable receiver and transmitter. */
1506 CSR_WRITE_2(sc, VR_COMMAND, VR_CMD_TX_NOPOLL|VR_CMD_START|
1507 VR_CMD_TX_ON|VR_CMD_RX_ON|
1510 CSR_WRITE_4(sc, VR_TXADDR, vtophys(&sc->vr_ldata->vr_tx_list[0]));
1512 CSR_WRITE_2(sc, VR_ISR, 0xFFFF);
1513 #ifdef DEVICE_POLLING
1515 * Disable interrupts if we are polling.
1517 if (ifp->if_capenable & IFCAP_POLLING)
1518 CSR_WRITE_2(sc, VR_IMR, 0);
1522 * Enable interrupts.
1524 CSR_WRITE_2(sc, VR_IMR, VR_INTRS);
1528 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1529 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1531 callout_reset(&sc->vr_stat_callout, hz, vr_tick, sc);
1535 * Set media options.
1538 vr_ifmedia_upd(struct ifnet *ifp)
1540 struct vr_softc *sc = ifp->if_softc;
1542 if (ifp->if_flags & IFF_UP)
1549 * Report current media status.
1552 vr_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1554 struct vr_softc *sc = ifp->if_softc;
1555 struct mii_data *mii;
1557 mii = device_get_softc(sc->vr_miibus);
1561 ifmr->ifm_active = mii->mii_media_active;
1562 ifmr->ifm_status = mii->mii_media_status;
1566 vr_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1568 struct vr_softc *sc = ifp->if_softc;
1569 struct ifreq *ifr = (struct ifreq *) data;
1570 struct mii_data *mii;
1576 if (ifp->if_flags & IFF_UP) {
1579 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
1594 mii = device_get_softc(sc->vr_miibus);
1595 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1598 #ifdef DEVICE_POLLING
1599 if (ifr->ifr_reqcap & IFCAP_POLLING &&
1600 !(ifp->if_capenable & IFCAP_POLLING)) {
1601 error = ether_poll_register(vr_poll, ifp);
1605 /* Disable interrupts */
1606 CSR_WRITE_2(sc, VR_IMR, 0x0000);
1607 ifp->if_capenable |= IFCAP_POLLING;
1612 if (!(ifr->ifr_reqcap & IFCAP_POLLING) &&
1613 ifp->if_capenable & IFCAP_POLLING) {
1614 error = ether_poll_deregister(ifp);
1615 /* Enable interrupts. */
1617 CSR_WRITE_2(sc, VR_IMR, VR_INTRS);
1618 ifp->if_capenable &= ~IFCAP_POLLING;
1622 #endif /* DEVICE_POLLING */
1625 error = ether_ioctl(ifp, command, data);
1633 vr_watchdog(struct ifnet *ifp)
1635 struct vr_softc *sc = ifp->if_softc;
1640 if_printf(ifp, "watchdog timeout\n");
1646 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1647 vr_start_locked(ifp);
1653 * Stop the adapter and free any mbufs allocated to the
1657 vr_stop(struct vr_softc *sc)
1667 callout_stop(&sc->vr_stat_callout);
1668 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1670 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_STOP);
1671 VR_CLRBIT16(sc, VR_COMMAND, (VR_CMD_RX_ON|VR_CMD_TX_ON));
1672 CSR_WRITE_2(sc, VR_IMR, 0x0000);
1673 CSR_WRITE_4(sc, VR_TXADDR, 0x00000000);
1674 CSR_WRITE_4(sc, VR_RXADDR, 0x00000000);
1677 * Free data in the RX lists.
1679 for (i = 0; i < VR_RX_LIST_CNT; i++) {
1680 if (sc->vr_cdata.vr_rx_chain[i].vr_mbuf != NULL) {
1681 m_freem(sc->vr_cdata.vr_rx_chain[i].vr_mbuf);
1682 sc->vr_cdata.vr_rx_chain[i].vr_mbuf = NULL;
1685 bzero((char *)&sc->vr_ldata->vr_rx_list,
1686 sizeof(sc->vr_ldata->vr_rx_list));
1689 * Free the TX list buffers.
1691 for (i = 0; i < VR_TX_LIST_CNT; i++) {
1692 if (sc->vr_cdata.vr_tx_chain[i].vr_mbuf != NULL) {
1693 m_freem(sc->vr_cdata.vr_tx_chain[i].vr_mbuf);
1694 sc->vr_cdata.vr_tx_chain[i].vr_mbuf = NULL;
1697 bzero((char *)&sc->vr_ldata->vr_tx_list,
1698 sizeof(sc->vr_ldata->vr_tx_list));
1702 * Stop all chip I/O so that the kernel's probe routines don't
1703 * get confused by errant DMAs when rebooting.
1706 vr_shutdown(device_t dev)