X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/blobdiff_plain/32dbbc8744a73e4722ff02d0a60a9bbc9b0187c7..78195a764d5e70464a6d4f49bc08332a2a8bb4d0:/sys/dev/netif/cue/if_cue.c diff --git a/sys/dev/netif/cue/if_cue.c b/sys/dev/netif/cue/if_cue.c index 06ca8c6de0..b71970477e 100644 --- a/sys/dev/netif/cue/if_cue.c +++ b/sys/dev/netif/cue/if_cue.c @@ -30,8 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/usb/if_cue.c,v 1.45 2003/12/08 07:54:14 obrien Exp $ - * $DragonFly: src/sys/dev/netif/cue/if_cue.c,v 1.15 2004/10/14 18:31:02 dillon Exp $ - * + * $DragonFly: src/sys/dev/netif/cue/if_cue.c,v 1.24 2005/11/28 17:13:41 dillon Exp $ */ /* @@ -61,6 +60,7 @@ #include #include +#include #include #include #include @@ -69,9 +69,6 @@ #include #include -#if defined(__DragonFly__) || __FreeBSD_version < 500000 -#include -#endif #include #include @@ -92,8 +89,6 @@ Static struct cue_type cue_devs[] = { { 0, 0 } }; -Static struct usb_qdat cue_qdat; - Static int cue_match(device_ptr_t); Static int cue_attach(device_ptr_t); Static int cue_detach(device_ptr_t); @@ -114,7 +109,6 @@ Static void cue_watchdog(struct ifnet *); Static void cue_shutdown(device_ptr_t); Static void cue_setmulti(struct cue_softc *); -Static uint32_t cue_mchash(const uint8_t *); Static void cue_reset(struct cue_softc *); Static int cue_csr_read_1(struct cue_softc *, int); @@ -318,33 +312,14 @@ cue_getmac(struct cue_softc *sc, void *buf) CUE_UNLOCK(sc); if (err) { - printf("cue%d: read MAC address failed\n", sc->cue_unit); + if_printf(&sc->arpcom.ac_if, "read MAC address failed\n"); return(-1); } return(0); } -#define CUE_POLY 0xEDB88320 -#define CUE_BITS 9 - -Static uint32_t -cue_mchash(const uint8_t *addr) -{ - uint32_t crc; - int idx, bit; - uint8_t data; - - /* Compute CRC for the address value. */ - crc = 0xFFFFFFFF; /* initial value */ - - for (idx = 0; idx < 6; idx++) { - for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) - crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0); - } - - return (crc & ((1 << CUE_BITS) - 1)); -} +#define CUE_BITS 9 Static void cue_setmulti(struct cue_softc *sc) @@ -368,15 +343,13 @@ cue_setmulti(struct cue_softc *sc) sc->cue_mctab[i] = 0; /* now program new ones */ -#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 - TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) -#else LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) -#endif { if (ifma->ifma_addr->sa_family != AF_LINK) continue; - h = cue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr)); + h = ether_crc32_le( + LLADDR((struct sockaddr_dl *)ifma->ifma_addr), + ETHER_ADDR_LEN) & ((1 << CUE_BITS) - 1); sc->cue_mctab[h >> 3] |= 1 << (h & 0x7); } @@ -385,7 +358,8 @@ cue_setmulti(struct cue_softc *sc) * so we can receive broadcast frames. */ if (ifp->if_flags & IFF_BROADCAST) { - h = cue_mchash(ifp->if_broadcastaddr); + h = ether_crc32_le(ifp->if_broadcastaddr, ETHER_ADDR_LEN) & + ((1 << CUE_BITS) - 1); sc->cue_mctab[h >> 3] |= 1 << (h & 0x7); } @@ -411,7 +385,7 @@ cue_reset(struct cue_softc *sc) USETW(req.wLength, 0); err = usbd_do_request(sc->cue_udev, &req, NULL); if (err) - printf("cue%d: reset failed\n", sc->cue_unit); + if_printf(&sc->arpcom.ac_if, "reset failed\n"); /* Wait a little while for the chip to get its brains in order. */ DELAY(1000); @@ -455,15 +429,13 @@ USB_ATTACH(cue) usb_endpoint_descriptor_t *ed; int i; - bzero(sc, sizeof(struct cue_softc)); sc->cue_iface = uaa->iface; sc->cue_udev = uaa->device; - sc->cue_unit = device_get_unit(self); callout_init(&sc->cue_stat_timer); if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) { - printf("cue%d: getting interface handle failed\n", - sc->cue_unit); + device_printf(self, "setting config no %d failed\n", + CUE_CONFIG_NO); USB_ATTACH_ERROR_RETURN; } @@ -471,14 +443,13 @@ USB_ATTACH(cue) usbd_devinfo(uaa->device, 0, devinfo); device_set_desc_copy(self, devinfo); - printf("%s: %s\n", USBDEVNAME(self), devinfo); + device_printf(self, "%s\n", devinfo); /* Find endpoints. */ for (i = 0; i < id->bNumEndpoints; i++) { ed = usbd_interface2endpoint_descriptor(uaa->iface, i); if (!ed) { - printf("cue%d: couldn't get ep %d\n", - sc->cue_unit, i); + device_printf(self, "couldn't get ep %d\n", i); USB_ATTACH_ERROR_RETURN; } if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && @@ -493,12 +464,11 @@ USB_ATTACH(cue) } } -#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 - mtx_init(&sc->cue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK, - MTX_DEF | MTX_RECURSE); -#endif CUE_LOCK(sc); + ifp = &sc->arpcom.ac_if; + if_initname(ifp, device_get_name(self), device_get_unit(self)); + #ifdef notdef /* Reset the adapter. */ cue_reset(sc); @@ -508,9 +478,7 @@ USB_ATTACH(cue) */ cue_getmac(sc, &eaddr); - ifp = &sc->arpcom.ac_if; ifp->if_softc = sc; - if_initname(ifp, "cue", sc->cue_unit); ifp->if_mtu = ETHERMTU; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = cue_ioctl; @@ -518,15 +486,13 @@ USB_ATTACH(cue) ifp->if_watchdog = cue_watchdog; ifp->if_init = cue_init; ifp->if_baudrate = 10000000; - ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; - - cue_qdat.ifp = ifp; - cue_qdat.if_rxstart = cue_rxstart; + ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); + ifq_set_ready(&ifp->if_snd); /* * Call MI attach routine. */ - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, eaddr, NULL); usb_register_netisr(); sc->cue_dying = 0; @@ -556,9 +522,6 @@ cue_detach(device_ptr_t dev) usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]); CUE_UNLOCK(sc); -#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 - mtx_destroy(&sc->cue_mtx); -#endif return(0); } @@ -574,15 +537,15 @@ cue_newbuf(struct cue_softc *sc, struct cue_chain *c, struct mbuf *m) if (m == NULL) { MGETHDR(m_new, MB_DONTWAIT, MT_DATA); if (m_new == NULL) { - printf("cue%d: no memory for rx list " - "-- packet dropped!\n", sc->cue_unit); + if_printf(&sc->arpcom.ac_if, "no memory for rx list " + "-- packet dropped!\n"); return(ENOBUFS); } MCLGET(m_new, MB_DONTWAIT); if (!(m_new->m_flags & M_EXT)) { - printf("cue%d: no memory for rx list " - "-- packet dropped!\n", sc->cue_unit); + if_printf(&sc->arpcom.ac_if, "no memory for rx list " + "-- packet dropped!\n"); m_freem(m_new); return(ENOBUFS); } @@ -702,9 +665,10 @@ cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) CUE_UNLOCK(sc); return; } - if (usbd_ratecheck(&sc->cue_rx_notice)) - printf("cue%d: usb error on rx: %s\n", sc->cue_unit, - usbd_errstr(status)); + if (usbd_ratecheck(&sc->cue_rx_notice)) { + if_printf(ifp, "usb error on rx: %s\n", + usbd_errstr(status)); + } if (status == USBD_STALLED) usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]); goto done; @@ -725,11 +689,13 @@ cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) ifp->if_ipackets++; m_adj(m, sizeof(u_int16_t)); - m->m_pkthdr.rcvif = (struct ifnet *)&cue_qdat; + m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = m->m_len = total_len; /* Put the packet on the special USB input queue. */ usb_ether_input(m); + cue_rxstart(ifp); + CUE_UNLOCK(sc); return; @@ -767,8 +733,7 @@ cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) CUE_UNLOCK(sc); return; } - printf("cue%d: usb error on tx: %s\n", sc->cue_unit, - usbd_errstr(status)); + if_printf(ifp, "usb error on tx: %s\n", usbd_errstr(status)); if (status == USBD_STALLED) usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]); CUE_UNLOCK(sc); @@ -780,8 +745,7 @@ cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err); if (c->cue_mbuf != NULL) { - c->cue_mbuf->m_pkthdr.rcvif = ifp; - usb_tx_done(c->cue_mbuf); + m_freem(c->cue_mbuf); c->cue_mbuf = NULL; } @@ -790,6 +754,9 @@ cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) else ifp->if_opackets++; + if (!ifq_is_empty(&ifp->if_snd)) + (*ifp->if_start)(ifp); + CUE_UNLOCK(sc); return; @@ -875,18 +842,18 @@ cue_start(struct ifnet *ifp) return; } - IF_DEQUEUE(&ifp->if_snd, m_head); + m_head = ifq_poll(&ifp->if_snd); if (m_head == NULL) { CUE_UNLOCK(sc); return; } if (cue_encap(sc, m_head, 0)) { - IF_PREPEND(&ifp->if_snd, m_head); ifp->if_flags |= IFF_OACTIVE; CUE_UNLOCK(sc); return; } + ifq_dequeue(&ifp->if_snd, m_head); /* * If there's a BPF listener, bounce a copy of this frame @@ -942,14 +909,14 @@ cue_init(void *xsc) /* Init TX ring. */ if (cue_tx_list_init(sc) == ENOBUFS) { - printf("cue%d: tx list init failed\n", sc->cue_unit); + if_printf(ifp, "tx list init failed\n"); CUE_UNLOCK(sc); return; } /* Init RX ring. */ if (cue_rx_list_init(sc) == ENOBUFS) { - printf("cue%d: rx list init failed\n", sc->cue_unit); + if_printf(ifp, "rx list init failed\n"); CUE_UNLOCK(sc); return; } @@ -975,16 +942,14 @@ cue_init(void *xsc) err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX], USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]); if (err) { - printf("cue%d: open rx pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "open rx pipe failed: %s\n", usbd_errstr(err)); CUE_UNLOCK(sc); return; } err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX], USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]); if (err) { - printf("cue%d: open tx pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "open tx pipe failed: %s\n", usbd_errstr(err)); CUE_UNLOCK(sc); return; } @@ -1062,13 +1027,13 @@ cue_watchdog(struct ifnet *ifp) CUE_LOCK(sc); ifp->if_oerrors++; - printf("cue%d: watchdog timeout\n", sc->cue_unit); + if_printf(ifp, "watchdog timeout\n"); c = &sc->cue_cdata.cue_tx_chain[0]; usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &stat); cue_txeof(c->cue_xfer, c, stat); - if (ifp->if_snd.ifq_head != NULL) + if (!ifq_is_empty(&ifp->if_snd)) cue_start(ifp); CUE_UNLOCK(sc); @@ -1099,13 +1064,13 @@ cue_stop(struct cue_softc *sc) if (sc->cue_ep[CUE_ENDPT_RX] != NULL) { err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]); if (err) { - printf("cue%d: abort rx pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "abort rx pipe failed: %s\n", + usbd_errstr(err)); } err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]); if (err) { - printf("cue%d: close rx pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "close rx pipe failed: %s\n", + usbd_errstr(err)); } sc->cue_ep[CUE_ENDPT_RX] = NULL; } @@ -1113,13 +1078,13 @@ cue_stop(struct cue_softc *sc) if (sc->cue_ep[CUE_ENDPT_TX] != NULL) { err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]); if (err) { - printf("cue%d: abort tx pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "abort tx pipe failed: %s\n", + usbd_errstr(err)); } err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]); if (err) { - printf("cue%d: close tx pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "close tx pipe failed: %s\n", + usbd_errstr(err)); } sc->cue_ep[CUE_ENDPT_TX] = NULL; } @@ -1127,13 +1092,13 @@ cue_stop(struct cue_softc *sc) if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) { err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]); if (err) { - printf("cue%d: abort intr pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "abort intr pipe failed: %s\n", + usbd_errstr(err)); } err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]); if (err) { - printf("cue%d: close intr pipe failed: %s\n", - sc->cue_unit, usbd_errstr(err)); + if_printf(ifp, "close intr pipe failed: %s\n", + usbd_errstr(err)); } sc->cue_ep[CUE_ENDPT_INTR] = NULL; }