diff options
author | jhb <jhb@FreeBSD.org> | 2005-10-27 21:18:37 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2005-10-27 21:18:37 +0000 |
commit | 6034c52fb7b00595c543066768d02175be7400c3 (patch) | |
tree | c827f1c3fc1640e5dd6550edb0e3b40bcc7e9dec /sys/pci/if_vr.c | |
parent | c08a62eaa2d862633a4ac6fb6bdad9993b14c17a (diff) | |
download | FreeBSD-src-6034c52fb7b00595c543066768d02175be7400c3.zip FreeBSD-src-6034c52fb7b00595c543066768d02175be7400c3.tar.gz |
- Use if_printf() and device_printf() and remove vr_unit from the softc.
I had to initialize the ifnet a bit earlier in attach so that the
if_printf()'s in vr_reset() didn't explode with a page fault.
- Use M_ZERO with contigmalloc() rather than an explicit bzero.
Diffstat (limited to 'sys/pci/if_vr.c')
-rw-r--r-- | sys/pci/if_vr.c | 96 |
1 files changed, 44 insertions, 52 deletions
diff --git a/sys/pci/if_vr.c b/sys/pci/if_vr.c index 5a5d934..d4f5932 100644 --- a/sys/pci/if_vr.c +++ b/sys/pci/if_vr.c @@ -592,7 +592,7 @@ vr_reset(struct vr_softc *sc) { register int i; - /*VR_LOCK_ASSERT(sc);*/ /* XXX: Called during detach w/o lock. */ + /*VR_LOCK_ASSERT(sc);*/ /* XXX: Called during attach w/o lock. */ VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RESET); @@ -603,11 +603,10 @@ vr_reset(struct vr_softc *sc) } if (i == VR_TIMEOUT) { if (sc->vr_revid < REV_ID_VT3065_A) - printf("vr%d: reset never completed!\n", sc->vr_unit); + if_printf(sc->vr_ifp, "reset never completed!\n"); else { /* Use newer force reset command */ - printf("vr%d: Using force reset command.\n", - sc->vr_unit); + if_printf(sc->vr_ifp, "Using force reset command.\n"); VR_SETBIT(sc, VR_MISC_CR1, VR_MISCCR1_FORSRST); } } @@ -666,7 +665,7 @@ vr_attach(dev) sc->vr_res = bus_alloc_resource_any(dev, VR_RES, &rid, RF_ACTIVE); if (sc->vr_res == NULL) { - printf("vr%d: couldn't map ports/memory\n", unit); + device_printf(dev, "couldn't map ports/memory\n"); error = ENXIO; goto fail; } @@ -680,11 +679,35 @@ vr_attach(dev) RF_SHAREABLE | RF_ACTIVE); if (sc->vr_irq == NULL) { - printf("vr%d: couldn't map interrupt\n", unit); + device_printf(dev, "couldn't map interrupt\n"); error = ENXIO; goto fail; } + /* Allocate ifnet structure. */ + ifp = sc->vr_ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + device_printf(dev, "can not if_alloc()\n"); + error = ENOSPC; + goto fail; + } + ifp->if_softc = sc; + if_initname(ifp, device_get_name(dev), device_get_unit(dev)); + ifp->if_mtu = ETHERMTU; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = vr_ioctl; + ifp->if_start = vr_start; + ifp->if_watchdog = vr_watchdog; + ifp->if_init = vr_init; + ifp->if_baudrate = 10000000; + IFQ_SET_MAXLEN(&ifp->if_snd, VR_TX_LIST_CNT - 1); + ifp->if_snd.ifq_maxlen = VR_TX_LIST_CNT - 1; + IFQ_SET_READY(&ifp->if_snd); + ifp->if_capenable = ifp->if_capabilities; +#ifdef DEVICE_POLLING + ifp->if_capabilities |= IFCAP_POLLING; +#endif + /* * Windows may put the chip in suspend mode when it * shuts down. Be sure to kick it in the head to wake it @@ -715,46 +738,19 @@ vr_attach(dev) for (i = 0; i < ETHER_ADDR_LEN; i++) eaddr[i] = CSR_READ_1(sc, VR_PAR0 + i); - sc->vr_unit = unit; - sc->vr_ldata = contigmalloc(sizeof(struct vr_list_data), M_DEVBUF, - M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); + M_NOWAIT | M_ZERO, 0, 0xffffffff, PAGE_SIZE, 0); if (sc->vr_ldata == NULL) { - printf("vr%d: no memory for list buffers!\n", unit); + device_printf(dev, "no memory for list buffers!\n"); error = ENXIO; goto fail; } - bzero(sc->vr_ldata, sizeof(struct vr_list_data)); - - ifp = sc->vr_ifp = if_alloc(IFT_ETHER); - if (ifp == NULL) { - printf("vr%d: can not if_alloc()\n", unit); - error = ENOSPC; - goto fail; - } - ifp->if_softc = sc; - if_initname(ifp, device_get_name(dev), device_get_unit(dev)); - ifp->if_mtu = ETHERMTU; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_ioctl = vr_ioctl; - ifp->if_start = vr_start; - ifp->if_watchdog = vr_watchdog; - ifp->if_init = vr_init; - ifp->if_baudrate = 10000000; - IFQ_SET_MAXLEN(&ifp->if_snd, VR_TX_LIST_CNT - 1); - ifp->if_snd.ifq_maxlen = VR_TX_LIST_CNT - 1; - IFQ_SET_READY(&ifp->if_snd); - ifp->if_capenable = ifp->if_capabilities; -#ifdef DEVICE_POLLING - ifp->if_capabilities |= IFCAP_POLLING; -#endif - /* Do MII setup. */ if (mii_phy_probe(dev, &sc->vr_miibus, vr_ifmedia_upd, vr_ifmedia_sts)) { - printf("vr%d: MII without any phy!\n", sc->vr_unit); + device_printf(dev, "MII without any phy!\n"); error = ENXIO; goto fail; } @@ -771,7 +767,7 @@ vr_attach(dev) vr_intr, sc, &sc->vr_intrhand); if (error) { - printf("vr%d: couldn't set up irq\n", unit); + device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); goto fail; } @@ -981,8 +977,7 @@ vr_rxeof(struct vr_softc *sc) */ if (rxstat & VR_RXSTAT_RXERR) { ifp->if_ierrors++; - printf("vr%d: rx error (%02x):", sc->vr_unit, - rxstat & 0x000000ff); + if_printf(ifp, "rx error (%02x):", rxstat & 0x000000ff); if (rxstat & VR_RXSTAT_CRCERR) printf(" crc error"); if (rxstat & VR_RXSTAT_FRAMEALIGNERR) @@ -1051,7 +1046,7 @@ vr_rxeoc(struct vr_softc *sc) } if (!i) { - printf("vr%d: rx shutdown error!\n", sc->vr_unit); + if_printf(ifp, "rx shutdown error!\n"); sc->vr_flags |= VR_F_RESTART; return; } @@ -1093,8 +1088,7 @@ vr_txeof(struct vr_softc *sc) i--) ; /* Wait for chip to shutdown */ if (!i) { - printf("vr%d: tx shutdown timeout\n", - sc->vr_unit); + if_printf(ifp, "tx shutdown timeout\n"); sc->vr_flags |= VR_F_RESTART; break; } @@ -1137,7 +1131,7 @@ vr_tick(void *xsc) VR_LOCK(sc); if (sc->vr_flags & VR_F_RESTART) { - printf("vr%d: restarting\n", sc->vr_unit); + if_printf(sc->vr_ifp, "restarting\n"); vr_stop(sc); vr_reset(sc); vr_init_locked(sc); @@ -1191,14 +1185,13 @@ vr_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count) return; if (status & VR_ISR_RX_DROPPED) { - printf("vr%d: rx packet lost\n", sc->vr_unit); + if_printf(ifp, "rx packet lost\n"); ifp->if_ierrors++; } if ((status & VR_ISR_RX_ERR) || (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_OFLOW)) { - printf("vr%d: receive error (%04x)", - sc->vr_unit, status); + if_printf(ifp, "receive error (%04x)", status); if (status & VR_ISR_RX_NOBUF) printf(" no buffers"); if (status & VR_ISR_RX_OFLOW) @@ -1274,14 +1267,13 @@ vr_intr(void *arg) vr_rxeof(sc); if (status & VR_ISR_RX_DROPPED) { - printf("vr%d: rx packet lost\n", sc->vr_unit); + if_printf(ifp, "rx packet lost\n"); ifp->if_ierrors++; } if ((status & VR_ISR_RX_ERR) || (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_OFLOW)) { - printf("vr%d: receive error (%04x)", - sc->vr_unit, status); + if_printf(ifp, "receive error (%04x)", status); if (status & VR_ISR_RX_NOBUF) printf(" no buffers"); if (status & VR_ISR_RX_OFLOW) @@ -1483,8 +1475,8 @@ vr_init_locked(struct vr_softc *sc) /* Init circular RX list. */ if (vr_list_rx_init(sc) == ENOBUFS) { - printf( -"vr%d: initialization failed: no memory for rx buffers\n", sc->vr_unit); + if_printf(ifp, + "initialization failed: no memory for rx buffers\n"); vr_stop(sc); return; } @@ -1649,7 +1641,7 @@ vr_watchdog(struct ifnet *ifp) VR_LOCK(sc); ifp->if_oerrors++; - printf("vr%d: watchdog timeout\n", sc->vr_unit); + if_printf(ifp, "watchdog timeout\n"); vr_stop(sc); vr_reset(sc); |