Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb - adjust usbnet interface to allow usbd_open_pip...



details:   https://anonhg.NetBSD.org/src/rev/9b5d3d47ee1f
branches:  trunk
changeset: 462996:9b5d3d47ee1f
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Aug 04 08:59:13 2019 +0000

description:
- adjust usbnet interface to allow usbd_open_pipe_intr(), from the
  new comment:
         * if un_intr_buf is not NULL, use usbd_open_pipe_intr() not
         * usbd_open_pipe() for USBNET_ENDPT_INTR, with this buffer,
         * size, and interval.
  the standard handling is in usbnet.c, with a callback to deal with
  the interrupt it self.  not fully tested, designed for if_aue.c
  and a few others not yet converted.
- make usbhist for usbnet.c work, thanks paulg
- usbnet_init_rx_tx() clears out all allocations upon failure now
- add usbnet_ec() to get a pointer to the struct ethercom
- add usbnet_{lock,unlock,owned}*() to lock/unlock the various locks
  and *owned*() for asserting

welcome 9.99.3!

diffstat:

 sys/dev/usb/if_axen.c |   31 ++++++------
 sys/dev/usb/if_cdce.c |   16 +++---
 sys/dev/usb/usbnet.c  |  122 ++++++++++++++++++++++++++++++++++++++++++-------
 sys/dev/usb/usbnet.h  |   87 ++++++++++++++++++++++++++++++++++-
 4 files changed, 212 insertions(+), 44 deletions(-)

diffs (truncated from 670 to 300 lines):

diff -r f645f4b95d00 -r 9b5d3d47ee1f sys/dev/usb/if_axen.c
--- a/sys/dev/usb/if_axen.c     Sun Aug 04 01:22:49 2019 +0000
+++ b/sys/dev/usb/if_axen.c     Sun Aug 04 08:59:13 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axen.c,v 1.52 2019/07/31 23:47:16 mrg Exp $ */
+/*     $NetBSD: if_axen.c,v 1.53 2019/08/04 08:59:13 mrg Exp $ */
 /*     $OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $ */
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.52 2019/07/31 23:47:16 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.53 2019/08/04 08:59:13 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -100,7 +100,7 @@
        usb_device_request_t req;
        usbd_status err;
 
-       KASSERT(mutex_owned(&un->un_miilock));
+       usbnet_isowned_mii(un);
 
        if (un->un_dying)
                return 0;
@@ -217,7 +217,7 @@
 {
        struct axen_softc * const sc = usbnet_softc(un);
        struct ifnet * const ifp = usbnet_ifp(un);
-       struct ethercom *ec = &un->un_ec;
+       struct ethercom *ec = usbnet_ec(un);
        struct ether_multi *enm;
        struct ether_multistep step;
        uint32_t h = 0;
@@ -228,7 +228,7 @@
        if (un->un_dying)
                return;
 
-       KASSERT(mutex_owned(&un->un_miilock));
+       usbnet_isowned_mii(un);
 
        rxmode = 0;
 
@@ -294,7 +294,7 @@
 {
        struct usbnet * const un = &sc->axen_un;
 
-       KASSERT(mutex_owned(&un->un_lock));
+       usbnet_isowned(un);
        if (un->un_dying)
                return;
        /* XXX What to reset? */
@@ -524,7 +524,7 @@
        uint64_t enabled = ifp->if_capenable;
        uint8_t val;
 
-       KASSERT(mutex_owned(&un->un_miilock));
+       usbnet_isowned_mii(un);
 
        val = AXEN_RXCOE_OFF;
        if (enabled & IFCAP_CSUM_IPv4_Rx)
@@ -711,10 +711,11 @@
        aprint_normal_dev(self, "Ethernet address %s\n",
            ether_sprintf(un->un_eaddr));
 
-       struct ifnet *ifp = usbnet_ifp(un);
-       un->un_ec.ec_capabilities = ETHERCAP_VLAN_MTU;
+       struct ethercom *ec = usbnet_ec(un);
+       ec->ec_capabilities = ETHERCAP_VLAN_MTU;
 
        /* Adapter does not support TSOv6 (They call it LSOv2). */
+       struct ifnet *ifp = usbnet_ifp(un);
        ifp->if_capabilities |= IFCAP_TSOv4 |
            IFCAP_CSUM_IPv4_Rx  | IFCAP_CSUM_IPv4_Tx  |
            IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_TCPv4_Tx |
@@ -772,7 +773,7 @@
 }
 
 static void
-axen_rxeof_loop(struct usbnet * un, struct usbd_xfer *xfer,
+axen_rxeof_loop(struct usbnet *un, struct usbd_xfer *xfer,
                struct usbnet_chain *c, uint32_t total_len)
 {
        struct ifnet *ifp = usbnet_ifp(un);
@@ -783,7 +784,7 @@
        size_t pkt_len;
        size_t temp;
 
-       KASSERT(mutex_owned(&un->un_rxlock));
+       usbnet_isowned_rx(un);
 
        if (total_len < sizeof(pkt_hdr)) {
                aprint_error_dev(un->un_dev, "rxeof: too short transfer\n");
@@ -877,7 +878,7 @@
        struct axen_sframe_hdr hdr;
        u_int length, boundary;
 
-       KASSERT(mutex_owned(&un->un_txlock));
+       usbnet_isowned_tx(un);
 
        /* XXX Is this needed?  wMaxPacketSize? */
        switch (un->un_udev->ud_speed) {
@@ -920,7 +921,7 @@
        uint16_t wval;
        uint8_t bval;
 
-       KASSERT(mutex_owned(&un->un_lock));
+       usbnet_isowned(un);
 
        if (un->un_dying)
                return EIO;
@@ -960,9 +961,9 @@
 {
        struct usbnet * const un = ifp->if_softc;
 
-       mutex_enter(&un->un_lock);
+       usbnet_lock(un);
        int ret = axen_init_locked(ifp);
-       mutex_exit(&un->un_lock);
+       usbnet_unlock(un);
 
        return ret;
 }
diff -r f645f4b95d00 -r 9b5d3d47ee1f sys/dev/usb/if_cdce.c
--- a/sys/dev/usb/if_cdce.c     Sun Aug 04 01:22:49 2019 +0000
+++ b/sys/dev/usb/if_cdce.c     Sun Aug 04 08:59:13 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cdce.c,v 1.55 2019/07/31 23:47:16 mrg Exp $ */
+/*     $NetBSD: if_cdce.c,v 1.56 2019/08/04 08:59:13 mrg Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul%windriver.com@localhost>
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.55 2019/07/31 23:47:16 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.56 2019/08/04 08:59:13 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -263,7 +263,7 @@
        struct usbnet           *un = ifp->if_softc;
        int rv;
 
-       mutex_enter(&un->un_lock);
+       usbnet_lock(un);
        if (un->un_dying)
                rv = EIO;
        else {
@@ -272,7 +272,7 @@
                if (rv == 0)
                        un->un_link = true;
        }
-       mutex_exit(&un->un_lock);
+       usbnet_unlock(un);
 
        return rv;
 }
@@ -282,9 +282,9 @@
                struct usbnet_chain *c, uint32_t total_len)
 {
        struct ifnet            *ifp = usbnet_ifp(un);
-       struct cdce_softc       *sc = un->un_sc;
+       struct cdce_softc       *sc = usbnet_softc(un);
 
-       KASSERT(mutex_owned(&un->un_rxlock));
+       usbnet_isowned_rx(un);
 
        /* Strip off CRC added by Zaurus, if present */
        if (sc->cdce_flags & CDCE_ZAURUS && total_len > 4)
@@ -301,10 +301,10 @@
 static unsigned
 cdce_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
 {
-       struct cdce_softc       *sc = un->un_sc;
+       struct cdce_softc       *sc = usbnet_softc(un);
        int                      extra = 0;
 
-       KASSERT(mutex_owned(&un->un_txlock));
+       usbnet_isowned_tx(un);
 
        m_copydata(m, 0, m->m_pkthdr.len, c->unc_buf);
        if (sc->cdce_flags & CDCE_ZAURUS) {
diff -r f645f4b95d00 -r 9b5d3d47ee1f sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c      Sun Aug 04 01:22:49 2019 +0000
+++ b/sys/dev/usb/usbnet.c      Sun Aug 04 08:59:13 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbnet.c,v 1.3 2019/08/03 15:58:14 skrll Exp $ */
+/*     $NetBSD: usbnet.c,v 1.4 2019/08/04 08:59:13 mrg Exp $   */
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.3 2019/08/03 15:58:14 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.4 2019/08/04 08:59:13 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -41,6 +41,7 @@
 #include <sys/module.h>
 
 #include <dev/usb/usbnet.h>
+#include <dev/usb/usbhist.h>
 
 static int usbnet_modcmd(modcmd_t, void *);
 
@@ -48,7 +49,9 @@
 #ifndef USBNET_DEBUG
 #define usbnetdebug 0
 #else
-static int usbnetdebug = 20;
+static int usbnetdebug = 1;
+
+int     sysctl_hw_usbnet_setup(SYSCTLFN_PROTO);
 
 SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup")
 {
@@ -118,6 +121,7 @@
 usbnet_enqueue(struct usbnet * const un, uint8_t *buf, size_t buflen,
                int flags)
 {
+       USBNETHIST_FUNC(); USBNETHIST_CALLED();
        struct ifnet *ifp = &un->un_ec.ec_if;
        struct mbuf *m;
 
@@ -143,9 +147,10 @@
  * the higher level protocols.
  */
 static void
-usbnet_rxeof(struct usbd_xfer *xfer, void * priv, usbd_status status)
+usbnet_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {
-       struct usbnet_chain *c = (struct usbnet_chain *)priv;
+       USBNETHIST_FUNC(); USBNETHIST_CALLED();
+       struct usbnet_chain *c = priv;
        struct usbnet * const un = c->unc_un;
        struct ifnet *ifp = &un->un_ec.ec_if;
        uint32_t total_len;
@@ -195,9 +200,10 @@
 }
 
 static void
-usbnet_txeof(struct usbd_xfer *xfer, void * priv, usbd_status status)
+usbnet_txeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {
-       struct usbnet_chain *c = (struct usbnet_chain *)priv;
+       USBNETHIST_FUNC(); USBNETHIST_CALLED();
+       struct usbnet_chain *c = priv;
        struct usbnet * const un = c->unc_un;
        struct usbnet_cdata *cd = &un->un_cdata;
        struct ifnet * const ifp = usbnet_ifp(un);
@@ -240,8 +246,35 @@
 }
 
 static void
+usbnet_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
+{
+       USBNETHIST_FUNC(); USBNETHIST_CALLED();
+       struct usbnet           *un = priv;
+       struct ifnet            *ifp = usbnet_ifp(un);
+
+       if (un->un_dying || un->un_stopping ||
+           status == USBD_INVAL || status == USBD_NOT_STARTED ||
+           status == USBD_CANCELLED || !(ifp->if_flags & IFF_RUNNING))
+               return;
+
+       if (status != USBD_NORMAL_COMPLETION) {
+               if (usbd_ratecheck(&un->un_intr_notice)) {
+                       aprint_error_dev(un->un_dev, "usb error on intr: %s\n",
+                           usbd_errstr(status));
+               }
+               if (status == USBD_STALLED)
+                       usbd_clear_endpoint_stall_async(un->un_ep[USBNET_ENDPT_INTR]);
+               return;
+       }
+
+       if (un->un_intr_cb)
+               (*un->un_intr_cb)(un, status);
+}
+
+static void
 usbnet_start_locked(struct ifnet *ifp)
 {
+       USBNETHIST_FUNC(); USBNETHIST_CALLED();
        struct usbnet * const un = ifp->if_softc;
        struct usbnet_cdata *cd = &un->un_cdata;
        struct mbuf *m;
@@ -495,10 +528,20 @@
 usbnet_ep_open_pipes(struct usbnet *un)
 {
        for (size_t i = 0; i < __arraycount(un->un_ep); i++) {
+               usbd_status err;
+
                if (un->un_ed[i] == 0)



Home | Main Index | Thread Index | Old Index