From b946173aa49041a01ee46d89bdf1a340042774b4 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Thu, 11 Oct 2012 11:18:06 +0200 Subject: [PATCH] usb4bsd: Port network devices (uether, udav, axe) and hook into build. Submitted-by: Markus Pfeiffer --- sys/bus/u4b/Makefile | 2 +- sys/bus/u4b/net/Makefile | 3 + sys/bus/u4b/net/if_axe.c | 156 ++++++++++++++++++------------- sys/bus/u4b/net/if_axe/Makefile | 8 ++ sys/bus/u4b/net/if_axereg.h | 8 +- sys/bus/u4b/net/if_udav.c | 62 ++++++------ sys/bus/u4b/net/if_udav/Makefile | 8 ++ sys/bus/u4b/net/if_udavreg.h | 8 +- sys/bus/u4b/net/uether/Makefile | 8 ++ sys/bus/u4b/net/usb_ethernet.c | 122 ++++++++++++++---------- sys/bus/u4b/net/usb_ethernet.h | 8 +- 11 files changed, 236 insertions(+), 157 deletions(-) create mode 100644 sys/bus/u4b/net/Makefile create mode 100644 sys/bus/u4b/net/if_axe/Makefile create mode 100644 sys/bus/u4b/net/if_udav/Makefile create mode 100644 sys/bus/u4b/net/uether/Makefile diff --git a/sys/bus/u4b/Makefile b/sys/bus/u4b/Makefile index 3347092269..fd55599648 100644 --- a/sys/bus/u4b/Makefile +++ b/sys/bus/u4b/Makefile @@ -1,5 +1,5 @@ #SUBDIR= controller input misc net quirk serial storage template -SUBDIR= usb audio controller input storage +SUBDIR= usb audio controller input net storage .include diff --git a/sys/bus/u4b/net/Makefile b/sys/bus/u4b/net/Makefile new file mode 100644 index 0000000000..15294bf988 --- /dev/null +++ b/sys/bus/u4b/net/Makefile @@ -0,0 +1,3 @@ +SUBDIR= uether if_axe if_udav + +.include diff --git a/sys/bus/u4b/net/if_axe.c b/sys/bus/u4b/net/if_axe.c index 02bb358de2..b72921b438 100644 --- a/sys/bus/u4b/net/if_axe.c +++ b/sys/bus/u4b/net/if_axe.c @@ -30,9 +30,6 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#include -__FBSDID("$FreeBSD$"); - /* * ASIX Electronics AX88172/AX88178/AX88778 USB 2.0 ethernet driver. * Used in the LinkSys USB200M and various other adapters. @@ -86,32 +83,31 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include -#include #include #include #include #include -#include +#include +#include -#include -#include +#include +#include -#include -#include -#include -#include "usbdevs.h" +#include +#include +#include +#include #define USB_DEBUG_VAR axe_debug -#include -#include +#include +#include -#include -#include +#include +#include /* * AXE_178_MAX_FRAME_BURST @@ -187,6 +183,11 @@ static miibus_readreg_t axe_miibus_readreg; static miibus_writereg_t axe_miibus_writereg; static miibus_statchg_t axe_miibus_statchg; +/* +static int axe_miibus_readreg(device_t dev, int phy, int reg); +static int axe_miibus_writereg(device_t dev, int phy, int reg, int val); +static void axe_miibus_statchg(device_t dev); +*/ static uether_fn_t axe_attach_post; static uether_fn_t axe_init; static uether_fn_t axe_stop; @@ -205,7 +206,7 @@ static void axe_ax88772_phywake(struct axe_softc *); static void axe_ax88772a_init(struct axe_softc *); static void axe_ax88772b_init(struct axe_softc *); static int axe_get_phyno(struct axe_softc *, int); -static int axe_ioctl(struct ifnet *, u_long, caddr_t); +static int axe_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); static int axe_rx_frame(struct usb_ether *, struct usb_page_cache *, int); static int axe_rxeof(struct usb_ether *, struct usb_page_cache *, unsigned int offset, unsigned int, struct axe_csum_hdr *); @@ -257,7 +258,7 @@ static device_method_t axe_methods[] = { DEVMETHOD(miibus_writereg, axe_miibus_writereg), DEVMETHOD(miibus_statchg, axe_miibus_statchg), - DEVMETHOD_END + {0, 0} }; static driver_t axe_driver = { @@ -295,7 +296,7 @@ axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf) struct usb_device_request req; usb_error_t err; - AXE_LOCK_ASSERT(sc, MA_OWNED); + AXE_LOCK_ASSERT(sc); req.bmRequestType = (AXE_CMD_IS_WRITE(cmd) ? UT_WRITE_VENDOR_DEVICE : @@ -317,15 +318,23 @@ axe_miibus_readreg(device_t dev, int phy, int reg) uint16_t val; int locked; - locked = mtx_owned(&sc->sc_mtx); + locked = lockowned(&sc->sc_lock); + + if(phy != sc->sc_phyno){ + return(0); + } + if (!locked) AXE_LOCK(sc); axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL); axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, &val); axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL); - + DPRINTFN(9,"reg %x\n", reg); + DPRINTFN(9,"pre val %x\n", val); val = le16toh(val); + DPRINTFN(9,"pos val %x\n", val); + if (AXE_IS_772(sc) && reg == MII_BMSR) { /* * BMSR of AX88772 indicates that it supports extended @@ -348,7 +357,7 @@ axe_miibus_writereg(device_t dev, int phy, int reg, int val) int locked; val = htole32(val); - locked = mtx_owned(&sc->sc_mtx); + locked = lockowned(&sc->sc_lock); if (!locked) AXE_LOCK(sc); @@ -370,13 +379,13 @@ axe_miibus_statchg(device_t dev) uint16_t val; int err, locked; - locked = mtx_owned(&sc->sc_mtx); + locked = lockowned(&sc->sc_lock); if (!locked) AXE_LOCK(sc); ifp = uether_getifp(&sc->sc_ue); if (mii == NULL || ifp == NULL || - (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + (ifp->if_flags & IFF_RUNNING) == 0) goto done; sc->sc_flags &= ~AXE_FLAG_LINK; @@ -391,15 +400,19 @@ axe_miibus_statchg(device_t dev) if ((sc->sc_flags & AXE_FLAG_178) == 0) break; sc->sc_flags |= AXE_FLAG_LINK; + DPRINTFN(11, "miibus_statchg: link should be up\n"); break; default: break; } + } else { + DPRINTFN(11, "miibus_statchg: not active or not valid: %x\n", mii->mii_media_status); } /* Lost link, do nothing. */ - if ((sc->sc_flags & AXE_FLAG_LINK) == 0) + if ((sc->sc_flags & AXE_FLAG_LINK) == 0) { goto done; + } val = 0; if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) { @@ -448,10 +461,10 @@ axe_ifmedia_upd(struct ifnet *ifp) struct mii_softc *miisc; int error; - AXE_LOCK_ASSERT(sc, MA_OWNED); + AXE_LOCK_ASSERT(sc); LIST_FOREACH(miisc, &mii->mii_phys, mii_list) - PHY_RESET(miisc); + mii_phy_reset(miisc); error = mii_mediachg(mii); return (error); } @@ -482,7 +495,7 @@ axe_setmulti(struct usb_ether *ue) uint16_t rxmode; uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - AXE_LOCK_ASSERT(sc, MA_OWNED); + AXE_LOCK_ASSERT(sc); axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, &rxmode); rxmode = le16toh(rxmode); @@ -494,7 +507,7 @@ axe_setmulti(struct usb_ether *ue) } rxmode &= ~AXE_RXCMD_ALLMULTI; - if_maddr_rlock(ifp); + /* if_maddr_rlock(ifp); */ TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { if (ifma->ifma_addr->sa_family != AF_LINK) @@ -503,7 +516,7 @@ axe_setmulti(struct usb_ether *ue) ifma->ifma_addr), ETHER_ADDR_LEN) >> 26; hashtbl[h / 8] |= 1 << (h % 8); } - if_maddr_runlock(ifp); +/* if_maddr_runlock(ifp); */ axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl); axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); @@ -789,7 +802,7 @@ axe_reset(struct axe_softc *sc) cd = usbd_get_config_descriptor(sc->sc_ue.ue_udev); - err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx, + err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_lock, cd->bConfigurationValue); if (err) DPRINTF("reset failed (ignored)\n"); @@ -874,9 +887,11 @@ axe_attach_post_sub(struct usb_ether *ue) ifp->if_start = uether_start; ifp->if_ioctl = axe_ioctl; ifp->if_init = uether_init; - IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); + ifq_set_maxlen(&ifp->if_snd, ifqmaxlen); + /* XXX ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; - IFQ_SET_READY(&ifp->if_snd); + */ + ifq_set_ready(&ifp->if_snd); if (AXE_IS_178_FAMILY(sc)) ifp->if_capabilities |= IFCAP_VLAN_MTU; @@ -898,12 +913,14 @@ axe_attach_post_sub(struct usb_ether *ue) adv_pause = MIIF_DOPAUSE; else adv_pause = 0; - mtx_lock(&Giant); + + error = mii_phy_probe(ue->ue_dev, &ue->ue_miibus, + uether_ifmedia_upd, ue->ue_methods->ue_mii_sts); + /* XXX error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, uether_ifmedia_upd, ue->ue_methods->ue_mii_sts, BMSR_DEFCAPMASK, sc->sc_phyno, MII_OFFSET_ANY, adv_pause); - mtx_unlock(&Giant); - + */ return (error); } @@ -942,11 +959,11 @@ axe_attach(device_t dev) device_set_usb_desc(dev); - mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); + lockinit(&sc->sc_lock, device_get_nameunit(dev), 0, 0); iface_index = AXE_IFACE_IDX; error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, - axe_config, AXE_N_TRANSFER, sc, &sc->sc_mtx); + axe_config, AXE_N_TRANSFER, sc, &sc->sc_lock); if (error) { device_printf(dev, "allocating USB transfers failed\n"); goto detach; @@ -955,7 +972,7 @@ axe_attach(device_t dev) ue->ue_sc = sc; ue->ue_dev = dev; ue->ue_udev = uaa->device; - ue->ue_mtx = &sc->sc_mtx; + ue->ue_lock = &sc->sc_lock; ue->ue_methods = &axe_ue_methods; error = uether_ifattach(ue); @@ -978,7 +995,8 @@ axe_detach(device_t dev) usbd_transfer_unsetup(sc->sc_xfer, AXE_N_TRANSFER); uether_ifdetach(ue); - mtx_destroy(&sc->sc_mtx); + lockuninit(&sc->sc_lock); + return (0); } @@ -1114,7 +1132,7 @@ axe_rxeof(struct usb_ether *ue, struct usb_page_cache *pc, unsigned int offset, return (EINVAL); } - m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); + m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR); if (m == NULL) { ifp->if_iqdrops++; return (ENOMEM); @@ -1143,8 +1161,8 @@ axe_rxeof(struct usb_ether *ue, struct usb_page_cache *pc, unsigned int offset, } } } - - _IF_ENQUEUE(&ue->ue_rxq, m); + + IF_ENQUEUE(&ue->ue_rxq, m); return (0); } @@ -1162,25 +1180,31 @@ axe_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error) struct mbuf *m; int nframes, pos; + DPRINTFN(11, "starting transfer\n"); + switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: DPRINTFN(11, "transfer complete\n"); - ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + + ifp->if_flags &= ~IFF_OACTIVE; + /* FALLTHROUGH */ case USB_ST_SETUP: tr_setup: if ((sc->sc_flags & AXE_FLAG_LINK) == 0 || - (ifp->if_drv_flags & IFF_DRV_OACTIVE) != 0) { + (ifp->if_flags & IFF_OACTIVE) != 0) { /* * Don't send anything if there is no link or * controller is busy. */ + DPRINTFN(11, "controller busy: sc_flags: %x if_flags %x\n",sc->sc_flags, ifp->if_flags); return; } + DPRINTFN(11, "copying frames, 16 at a time\n"); for (nframes = 0; nframes < 16 && - !IFQ_DRV_IS_EMPTY(&ifp->if_snd); nframes++) { - IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + !ifq_is_empty(&ifp->if_snd); nframes++) { + m = ifq_dequeue(&ifp->if_snd, NULL); if (m == NULL) break; usbd_xfer_set_frame_offset(xfer, nframes * MCLBYTES, @@ -1205,6 +1229,7 @@ tr_setup: hdr.len |= htole16( AXE_TX_CSUM_DIS); } + DPRINTFN(11, "usbd copy in\n"); usbd_copy_in(pc, pos, &hdr, sizeof(hdr)); pos += sizeof(hdr); usbd_m_copy_in(pc, pos, m, 0, m->m_pkthdr.len); @@ -1245,8 +1270,9 @@ tr_setup: } if (nframes != 0) { usbd_xfer_set_frames(xfer, nframes); + DPRINTFN(5, "submitting transfer\n"); usbd_transfer_submit(xfer); - ifp->if_drv_flags |= IFF_DRV_OACTIVE; + ifp->if_flags |= IFF_OACTIVE; } return; /* NOTREACHED */ @@ -1255,8 +1281,7 @@ tr_setup: usbd_errstr(error)); ifp->if_oerrors++; - ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; - + ifp->if_flags &= ~IFF_OACTIVE; if (error != USB_ERR_CANCELLED) { /* try to clear stall first */ usbd_xfer_set_stall(xfer); @@ -1273,7 +1298,7 @@ axe_tick(struct usb_ether *ue) struct axe_softc *sc = uether_getsc(ue); struct mii_data *mii = GET_MII(sc); - AXE_LOCK_ASSERT(sc, MA_OWNED); + AXE_LOCK_ASSERT(sc); mii_tick(mii); if ((sc->sc_flags & AXE_FLAG_LINK) == 0) { @@ -1303,7 +1328,7 @@ axe_csum_cfg(struct usb_ether *ue) uint16_t csum1, csum2; sc = uether_getsc(ue); - AXE_LOCK_ASSERT(sc, MA_OWNED); + AXE_LOCK_ASSERT(sc); if ((sc->sc_flags & AXE_FLAG_772B) != 0) { ifp = uether_getifp(ue); @@ -1330,11 +1355,12 @@ axe_init(struct usb_ether *ue) struct ifnet *ifp = uether_getifp(ue); uint16_t rxmode; - AXE_LOCK_ASSERT(sc, MA_OWNED); + AXE_LOCK_ASSERT(sc); - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) + + if ((ifp->if_flags & IFF_RUNNING) != 0) return; - + /* Cancel pending I/O */ axe_stop(ue); @@ -1417,7 +1443,9 @@ axe_init(struct usb_ether *ue) usbd_xfer_set_stall(sc->sc_xfer[AXE_BULK_DT_WR]); - ifp->if_drv_flags |= IFF_DRV_RUNNING; + + ifp->if_flags |= IFF_RUNNING; + /* Switch to selected media. */ axe_ifmedia_upd(ifp); } @@ -1450,9 +1478,11 @@ axe_stop(struct usb_ether *ue) struct axe_softc *sc = uether_getsc(ue); struct ifnet *ifp = uether_getifp(ue); - AXE_LOCK_ASSERT(sc, MA_OWNED); + AXE_LOCK_ASSERT(sc); - ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); + + ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); + sc->sc_flags &= ~AXE_FLAG_LINK; /* @@ -1463,7 +1493,7 @@ axe_stop(struct usb_ether *ue) } static int -axe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) +axe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *uc) { struct usb_ether *ue = ifp->if_softc; struct axe_softc *sc; @@ -1491,15 +1521,15 @@ axe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) ifp->if_capenable ^= IFCAP_RXCSUM; reinit++; } - if (reinit > 0 && ifp->if_drv_flags & IFF_DRV_RUNNING) - ifp->if_drv_flags &= ~IFF_DRV_RUNNING; - else + if (reinit > 0 && ifp->if_flags & IFF_RUNNING) + ifp->if_flags &= ~IFF_RUNNING; + else reinit = 0; AXE_UNLOCK(sc); if (reinit > 0) uether_init(ue); } else - error = uether_ioctl(ifp, cmd, data); + error = uether_ioctl(ifp, cmd, data, uc); return (error); } diff --git a/sys/bus/u4b/net/if_axe/Makefile b/sys/bus/u4b/net/if_axe/Makefile new file mode 100644 index 0000000000..a29f072699 --- /dev/null +++ b/sys/bus/u4b/net/if_axe/Makefile @@ -0,0 +1,8 @@ +.PATH: ${.CURDIR}/.. + +KMOD= if_axe +SRCS= opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h \ + miibus_if.h opt_inet.h \ + if_axe.c + +.include diff --git a/sys/bus/u4b/net/if_axereg.h b/sys/bus/u4b/net/if_axereg.h index ab2b28d24f..c5f5e6a7f7 100644 --- a/sys/bus/u4b/net/if_axereg.h +++ b/sys/bus/u4b/net/if_axereg.h @@ -332,7 +332,7 @@ enum { struct axe_softc { struct usb_ether sc_ue; - struct mtx sc_mtx; + struct lock sc_lock; struct usb_xfer *sc_xfer[AXE_N_TRANSFER]; int sc_phyno; @@ -359,6 +359,6 @@ struct axe_softc { #define AXE_IS_772(sc) \ ((sc)->sc_flags & (AXE_FLAG_772 | AXE_FLAG_772A | AXE_FLAG_772B)) -#define AXE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) -#define AXE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) -#define AXE_LOCK_ASSERT(_sc, t) mtx_assert(&(_sc)->sc_mtx, t) +#define AXE_LOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_EXCLUSIVE) +#define AXE_UNLOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_RELEASE) +#define AXE_LOCK_ASSERT(_sc) KKASSERT(lockowned(&(_sc)->sc_lock)) diff --git a/sys/bus/u4b/net/if_udav.c b/sys/bus/u4b/net/if_udav.c index 8160a3b5c3..5f1e60f20f 100644 --- a/sys/bus/u4b/net/if_udav.c +++ b/sys/bus/u4b/net/if_udav.c @@ -43,11 +43,7 @@ * External PHYs */ -#include -__FBSDID("$FreeBSD$"); - #include -#include #include #include #include @@ -59,23 +55,24 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include #include -#include -#include -#include -#include "usbdevs.h" +#include + +#include +#include +#include +#include #define USB_DEBUG_VAR udav_debug -#include -#include +#include +#include -#include -#include +#include +#include /* prototypes */ @@ -150,7 +147,7 @@ static device_method_t udav_methods[] = { DEVMETHOD(miibus_writereg, udav_miibus_writereg), DEVMETHOD(miibus_statchg, udav_miibus_statchg), - DEVMETHOD_END + {0, 0} }; static driver_t udav_driver = { @@ -249,11 +246,11 @@ udav_attach(device_t dev) device_set_usb_desc(dev); - mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); + lockinit(&sc->sc_lock, device_get_nameunit(dev), 0, 0); iface_index = UDAV_IFACE_INDEX; error = usbd_transfer_setup(uaa->device, &iface_index, - sc->sc_xfer, udav_config, UDAV_N_TRANSFER, sc, &sc->sc_mtx); + sc->sc_xfer, udav_config, UDAV_N_TRANSFER, sc, &sc->sc_lock); if (error) { device_printf(dev, "allocating USB transfers failed\n"); goto detach; @@ -262,7 +259,7 @@ udav_attach(device_t dev) ue->ue_sc = sc; ue->ue_dev = dev; ue->ue_udev = uaa->device; - ue->ue_mtx = &sc->sc_mtx; + ue->ue_lock = &sc->sc_lock; ue->ue_methods = &udav_ue_methods; error = uether_ifattach(ue); @@ -286,7 +283,7 @@ udav_detach(device_t dev) usbd_transfer_unsetup(sc->sc_xfer, UDAV_N_TRANSFER); uether_ifdetach(ue); - mtx_destroy(&sc->sc_mtx); + lockuninit(&sc->sc_lock); return (0); } @@ -407,7 +404,7 @@ udav_init(struct usb_ether *ue) struct udav_softc *sc = ue->ue_sc; struct ifnet *ifp = uether_getifp(&sc->sc_ue); - UDAV_LOCK_ASSERT(sc, MA_OWNED); + UDAV_LOCK_ASSERT(sc); /* * Cancel pending I/O @@ -437,7 +434,8 @@ udav_init(struct usb_ether *ue) usbd_xfer_set_stall(sc->sc_xfer[UDAV_BULK_DT_WR]); - ifp->if_drv_flags |= IFF_DRV_RUNNING; +/* XXX ifp->if_drv_flags |= IFF_DRV_RUNNING; + */ udav_start(ue); } @@ -482,7 +480,7 @@ udav_setmulti(struct usb_ether *ue) uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; int h = 0; - UDAV_LOCK_ASSERT(sc, MA_OWNED); + UDAV_LOCK_ASSERT(sc); if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { UDAV_SETBIT(sc, UDAV_RCR, UDAV_RCR_ALL|UDAV_RCR_PRMSC); @@ -495,7 +493,6 @@ udav_setmulti(struct usb_ether *ue) udav_csr_write(sc, UDAV_MAR, hashtbl, sizeof(hashtbl)); /* now program new ones */ - if_maddr_rlock(ifp); TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { if (ifma->ifma_addr->sa_family != AF_LINK) @@ -504,7 +501,6 @@ udav_setmulti(struct usb_ether *ue) ifma->ifma_addr), ETHER_ADDR_LEN) >> 26; hashtbl[h / 8] |= 1 << (h % 8); } - if_maddr_runlock(ifp); /* disable all multicast */ UDAV_CLRBIT(sc, UDAV_RCR, UDAV_RCR_ALL); @@ -570,7 +566,7 @@ tr_setup: */ return; } - IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + m = ifq_dequeue(&ifp->if_snd, NULL); if (m == NULL) return; @@ -709,9 +705,11 @@ udav_stop(struct usb_ether *ue) struct udav_softc *sc = ue->ue_sc; struct ifnet *ifp = uether_getifp(&sc->sc_ue); - UDAV_LOCK_ASSERT(sc, MA_OWNED); + UDAV_LOCK_ASSERT(sc); + /* XXX ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + */ sc->sc_flags &= ~UDAV_FLAG_LINK; /* @@ -731,11 +729,13 @@ udav_ifmedia_upd(struct ifnet *ifp) struct mii_data *mii = GET_MII(sc); struct mii_softc *miisc; - UDAV_LOCK_ASSERT(sc, MA_OWNED); + kprintf("ifmedia upd\n"); + + UDAV_LOCK_ASSERT(sc); sc->sc_flags &= ~UDAV_FLAG_LINK; LIST_FOREACH(miisc, &mii->mii_phys, mii_list) - PHY_RESET(miisc); + mii_phy_reset(miisc); mii_mediachg(mii); return (0); } @@ -746,6 +746,8 @@ udav_ifmedia_status(struct ifnet *ifp, struct ifmediareq *ifmr) struct udav_softc *sc = ifp->if_softc; struct mii_data *mii = GET_MII(sc); + kprintf("ifmedia status\n"); + UDAV_LOCK(sc); mii_pollstat(mii); ifmr->ifm_active = mii->mii_media_active; @@ -759,7 +761,7 @@ udav_tick(struct usb_ether *ue) struct udav_softc *sc = ue->ue_sc; struct mii_data *mii = GET_MII(sc); - UDAV_LOCK_ASSERT(sc, MA_OWNED); + UDAV_LOCK_ASSERT(sc); mii_tick(mii); if ((sc->sc_flags & UDAV_FLAG_LINK) == 0 @@ -782,7 +784,7 @@ udav_miibus_readreg(device_t dev, int phy, int reg) if (phy != 0) return (0); - locked = mtx_owned(&sc->sc_mtx); + locked = lockowned(&sc->sc_lock); if (!locked) UDAV_LOCK(sc); @@ -822,7 +824,7 @@ udav_miibus_writereg(device_t dev, int phy, int reg, int data) if (phy != 0) return (0); - locked = mtx_owned(&sc->sc_mtx); + locked = lockowned(&sc->sc_lock); if (!locked) UDAV_LOCK(sc); diff --git a/sys/bus/u4b/net/if_udav/Makefile b/sys/bus/u4b/net/if_udav/Makefile new file mode 100644 index 0000000000..2b7bc91fba --- /dev/null +++ b/sys/bus/u4b/net/if_udav/Makefile @@ -0,0 +1,8 @@ +.PATH: ${.CURDIR}/.. + +KMOD= if_udav +SRCS= opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h \ + miibus_if.h opt_inet.h \ + if_udav.c + +.include diff --git a/sys/bus/u4b/net/if_udavreg.h b/sys/bus/u4b/net/if_udavreg.h index 82715e8bf3..4a1687bb64 100644 --- a/sys/bus/u4b/net/if_udavreg.h +++ b/sys/bus/u4b/net/if_udavreg.h @@ -153,7 +153,7 @@ enum { struct udav_softc { struct usb_ether sc_ue; - struct mtx sc_mtx; + struct lock sc_lock; struct usb_xfer *sc_xfer[UDAV_N_TRANSFER]; int sc_flags; @@ -161,6 +161,6 @@ struct udav_softc { #define UDAV_FLAG_EXT_PHY 0x0040 }; -#define UDAV_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) -#define UDAV_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) -#define UDAV_LOCK_ASSERT(_sc, t) mtx_assert(&(_sc)->sc_mtx, t) +#define UDAV_LOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_EXCLUSIVE) +#define UDAV_UNLOCK(_sc) lockmgr(&(_sc)->sc_lock, LK_RELEASE) +#define UDAV_LOCK_ASSERT(_sc) KKASSERT(lockowned(&(_sc)->sc_lock)) diff --git a/sys/bus/u4b/net/uether/Makefile b/sys/bus/u4b/net/uether/Makefile new file mode 100644 index 0000000000..2f20516f41 --- /dev/null +++ b/sys/bus/u4b/net/uether/Makefile @@ -0,0 +1,8 @@ +.PATH: ${.CURDIR}/.. + +KMOD= uether +SRCS= opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h \ + miibus_if.h opt_inet.h \ + usb_ethernet.c + +.include diff --git a/sys/bus/u4b/net/usb_ethernet.c b/sys/bus/u4b/net/usb_ethernet.c index 2a7bddfdbe..439b70110a 100644 --- a/sys/bus/u4b/net/usb_ethernet.c +++ b/sys/bus/u4b/net/usb_ethernet.c @@ -24,9 +24,6 @@ * SUCH DAMAGE. */ -#include -__FBSDID("$FreeBSD$"); - #include #include #include @@ -36,38 +33,42 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include -#include #include +#include #include #include #include -#include +#include + +#include -#include -#include +#include +#include -#include -#include +#include +#include -#include -#include +#include +#include static SYSCTL_NODE(_net, OID_AUTO, ue, CTLFLAG_RD, 0, "USB Ethernet parameters"); -#define UE_LOCK(_ue) mtx_lock((_ue)->ue_mtx) -#define UE_UNLOCK(_ue) mtx_unlock((_ue)->ue_mtx) -#define UE_LOCK_ASSERT(_ue, t) mtx_assert((_ue)->ue_mtx, t) +#define UE_LOCK(_ue) lockmgr((_ue)->ue_lock, LK_EXCLUSIVE) +#define UE_UNLOCK(_ue) lockmgr((_ue)->ue_lock, LK_RELEASE) +#define UE_LOCK_ASSERT(_ue) KKASSERT(lockowned((_ue)->ue_lock)) MODULE_DEPEND(uether, usb, 1, 1, 1); MODULE_DEPEND(uether, miibus, 1, 1, 1); +/* static struct unrhdr *ueunit; +*/ +DEVFS_DECLARE_CLONE_BITMAP(ue); static usb_proc_callback_t ue_attach_post_task; static usb_proc_callback_t ue_promisc_task; @@ -94,7 +95,7 @@ uether_pause(struct usb_ether *ue, unsigned int _ticks) /* nothing to do */ return (1); } - usb_pause_mtx(ue->ue_mtx, _ticks); + usb_pause_mtx(ue->ue_lock, _ticks); return (0); } @@ -105,7 +106,7 @@ ue_queue_command(struct usb_ether *ue, { struct usb_ether_cfg_task *task; - UE_LOCK_ASSERT(ue, MA_OWNED); + UE_LOCK_ASSERT(ue); if (usb_proc_is_gone(&ue->ue_tq)) { return; /* nothing to do */ @@ -165,11 +166,11 @@ uether_ifattach(struct usb_ether *ue) /* check some critical parameters */ if ((ue->ue_dev == NULL) || (ue->ue_udev == NULL) || - (ue->ue_mtx == NULL) || + (ue->ue_lock == NULL) || (ue->ue_methods == NULL)) return (EINVAL); - error = usb_proc_create(&ue->ue_tq, ue->ue_mtx, + error = usb_proc_create(&ue->ue_tq, ue->ue_lock, device_get_nameunit(ue->ue_dev), USB_PRI_MED); if (error) { device_printf(ue->ue_dev, "could not setup taskqueue\n"); @@ -202,8 +203,11 @@ ue_attach_post_task(struct usb_proc_msg *_task) UE_UNLOCK(ue); + /* XXX ue->ue_unit = alloc_unr(ueunit); - usb_callout_init_mtx(&ue->ue_watchdog, ue->ue_mtx, 0); + */ + ue->ue_unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(ue), 0); + usb_callout_init_mtx(&ue->ue_watchdog, ue->ue_lock, 0); sysctl_ctx_init(&ue->ue_sysctl_ctx); error = 0; @@ -226,19 +230,24 @@ ue_attach_post_task(struct usb_proc_msg *_task) ifp->if_ioctl = uether_ioctl; ifp->if_start = ue_start; ifp->if_init = ue_init; - IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); + ifq_set_maxlen(&ifp->if_snd, ifqmaxlen); + /* XXX ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; - IFQ_SET_READY(&ifp->if_snd); + */ + ifq_set_ready(&ifp->if_snd); ue->ue_ifp = ifp; if (ue->ue_methods->ue_mii_upd != NULL && ue->ue_methods->ue_mii_sts != NULL) { /* device_xxx() depends on this */ - mtx_lock(&Giant); +/* mtx_lock(&Giant);*/ + error = mii_phy_probe(ue->ue_dev, &ue->ue_miibus, + ue_ifmedia_upd, ue->ue_methods->ue_mii_sts); + /* error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, ue_ifmedia_upd, ue->ue_methods->ue_mii_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0); - mtx_unlock(&Giant); +*/ /* mtx_unlock(&Giant);*/ } } @@ -248,12 +257,12 @@ ue_attach_post_task(struct usb_proc_msg *_task) } if_printf(ifp, " on %s\n", device_get_nameunit(ue->ue_dev)); - ether_ifattach(ifp, ue->ue_eaddr); + ether_ifattach(ifp, ue->ue_eaddr, NULL); /* Tell upper layer we support VLAN oversized frames. */ if (ifp->if_capabilities & IFCAP_VLAN_MTU) ifp->if_hdrlen = sizeof(struct ether_vlan_header); - snprintf(num, sizeof(num), "%u", ue->ue_unit); + ksnprintf(num, sizeof(num), "%u", ue->ue_unit); ue->ue_sysctl_oid = SYSCTL_ADD_NODE(&ue->ue_sysctl_ctx, &SYSCTL_NODE_CHILDREN(_net, ue), OID_AUTO, num, CTLFLAG_RD, NULL, ""); @@ -266,7 +275,10 @@ ue_attach_post_task(struct usb_proc_msg *_task) return; fail: + /* XXX free_unr(ueunit, ue->ue_unit); + */ + devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(ue), ue->ue_unit); if (ue->ue_ifp != NULL) { if_free(ue->ue_ifp); ue->ue_ifp = NULL; @@ -290,17 +302,17 @@ uether_ifdetach(struct usb_ether *ue) /* we are not running any more */ UE_LOCK(ue); - ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + ifp->if_flags &= ~IFF_RUNNING; UE_UNLOCK(ue); - + /* drain any callouts */ usb_callout_drain(&ue->ue_watchdog); /* detach miibus */ if (ue->ue_miibus != NULL) { - mtx_lock(&Giant); /* device_xxx() depends on this */ + /*mtx_lock(&Giant);*/ /* device_xxx() depends on this */ device_delete_child(ue->ue_dev, ue->ue_miibus); - mtx_unlock(&Giant); + /*mtx_unlock(&Giant);*/ } /* detach ethernet */ @@ -313,7 +325,10 @@ uether_ifdetach(struct usb_ether *ue) sysctl_ctx_free(&ue->ue_sysctl_ctx); /* free unit */ + devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(ue), ue->ue_unit); + /* free_unr(ueunit, ue->ue_unit); + */ } /* free taskqueue, if any */ @@ -353,13 +368,12 @@ ue_start_task(struct usb_proc_msg *_task) struct usb_ether *ue = task->ue; struct ifnet *ifp = ue->ue_ifp; - UE_LOCK_ASSERT(ue, MA_OWNED); + UE_LOCK_ASSERT(ue); ue->ue_methods->ue_init(ue); - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + if ((ifp->if_flags & IFF_RUNNING) == 0) return; - if (ue->ue_methods->ue_tick != NULL) usb_callout_reset(&ue->ue_watchdog, hz, ue_watchdog, ue); } @@ -371,7 +385,7 @@ ue_stop_task(struct usb_proc_msg *_task) (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; - UE_LOCK_ASSERT(ue, MA_OWNED); + UE_LOCK_ASSERT(ue); usb_callout_stop(&ue->ue_watchdog); @@ -390,9 +404,8 @@ ue_start(struct ifnet *ifp) { struct usb_ether *ue = ifp->if_softc; - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + if ((ifp->if_flags & IFF_RUNNING) == 0) return; - UE_LOCK(ue); ue->ue_methods->ue_start(ue); UE_UNLOCK(ue); @@ -456,8 +469,8 @@ ue_watchdog(void *arg) { struct usb_ether *ue = arg; struct ifnet *ifp = ue->ue_ifp; - - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + + if ((ifp->if_flags & IFF_RUNNING) == 0) return; ue_queue_command(ue, ue_tick_task, @@ -474,15 +487,15 @@ ue_tick_task(struct usb_proc_msg *_task) (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; struct ifnet *ifp = ue->ue_ifp; - - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) + + if ((ifp->if_flags & IFF_RUNNING) == 0) return; ue->ue_methods->ue_tick(ue); } int -uether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) +uether_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred* uc) { struct usb_ether *ue = ifp->if_softc; struct ifreq *ifr = (struct ifreq *)data; @@ -493,7 +506,7 @@ uether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) case SIOCSIFFLAGS: UE_LOCK(ue); if (ifp->if_flags & IFF_UP) { - if (ifp->if_drv_flags & IFF_DRV_RUNNING) + if (ifp->if_flags & IFF_RUNNING) ue_queue_command(ue, ue_promisc_task, &ue->ue_promisc_task[0].hdr, &ue->ue_promisc_task[1].hdr); @@ -534,12 +547,19 @@ uether_ioctl(struct ifnet *ifp, u_long command, caddr_t data) static int uether_modevent(module_t mod, int type, void *data) { + static int attached = 0; switch (type) { case MOD_LOAD: - ueunit = new_unrhdr(0, INT_MAX, NULL); - break; + if (attached) + return (EEXIST); + + devfs_clone_bitmap_init(&DEVFS_CLONE_BITMAP(ue)); + + attached = 1; + break; case MOD_UNLOAD: + devfs_clone_bitmap_uninit(&DEVFS_CLONE_BITMAP(ue)); break; default: return (EOPNOTSUPP); @@ -557,7 +577,7 @@ uether_newbuf(void) { struct mbuf *m_new; - m_new = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); + m_new = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR); if (m_new == NULL) return (NULL); m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; @@ -572,7 +592,7 @@ uether_rxmbuf(struct usb_ether *ue, struct mbuf *m, { struct ifnet *ifp = ue->ue_ifp; - UE_LOCK_ASSERT(ue, MA_OWNED); + UE_LOCK_ASSERT(ue); /* finalize mbuf */ ifp->if_ipackets++; @@ -580,7 +600,7 @@ uether_rxmbuf(struct usb_ether *ue, struct mbuf *m, m->m_pkthdr.len = m->m_len = len; /* enqueue for later when the lock can be released */ - _IF_ENQUEUE(&ue->ue_rxq, m); + IF_ENQUEUE(&ue->ue_rxq, m); return (0); } @@ -591,7 +611,7 @@ uether_rxbuf(struct usb_ether *ue, struct usb_page_cache *pc, struct ifnet *ifp = ue->ue_ifp; struct mbuf *m; - UE_LOCK_ASSERT(ue, MA_OWNED); + UE_LOCK_ASSERT(ue); if (len < ETHER_HDR_LEN || len > MCLBYTES - ETHER_ALIGN) return (1); @@ -610,7 +630,7 @@ uether_rxbuf(struct usb_ether *ue, struct usb_page_cache *pc, m->m_pkthdr.len = m->m_len = len; /* enqueue for later when the lock can be released */ - _IF_ENQUEUE(&ue->ue_rxq, m); + IF_ENQUEUE(&ue->ue_rxq, m); return (0); } @@ -620,10 +640,10 @@ uether_rxflush(struct usb_ether *ue) struct ifnet *ifp = ue->ue_ifp; struct mbuf *m; - UE_LOCK_ASSERT(ue, MA_OWNED); + UE_LOCK_ASSERT(ue); for (;;) { - _IF_DEQUEUE(&ue->ue_rxq, m); + IF_DEQUEUE(&ue->ue_rxq, m); if (m == NULL) break; diff --git a/sys/bus/u4b/net/usb_ethernet.h b/sys/bus/u4b/net/usb_ethernet.h index af7cad437f..ced7369931 100644 --- a/sys/bus/u4b/net/usb_ethernet.h +++ b/sys/bus/u4b/net/usb_ethernet.h @@ -48,8 +48,8 @@ #include "miibus_if.h" -#include -#include +#include +#include struct usb_ether; struct usb_device_request; @@ -79,7 +79,7 @@ struct usb_ether_cfg_task { struct usb_ether { /* NOTE: the "ue_ifp" pointer must be first --hps */ struct ifnet *ue_ifp; - struct mtx *ue_mtx; + struct lock *ue_lock; const struct usb_ether_methods *ue_methods; struct sysctl_oid *ue_sysctl_oid; void *ue_sc; @@ -114,7 +114,7 @@ int uether_ifattach(struct usb_ether *); void uether_ifdetach(struct usb_ether *); int uether_ifmedia_upd(struct ifnet *); void uether_init(void *); -int uether_ioctl(struct ifnet *, u_long, caddr_t); +int uether_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *); struct mbuf *uether_newbuf(void); int uether_rxmbuf(struct usb_ether *, struct mbuf *, unsigned int); -- 2.41.0