Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/dev/usb Pull up following revision(s) (requested by m...



details:   https://anonhg.NetBSD.org/src/rev/834db76541be
branches:  netbsd-9
changeset: 458342:834db76541be
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Sep 13 06:51:58 2019 +0000

description:
Pull up following revision(s) (requested by mrg in ticket #197):

        sys/dev/usb/if_url.c: revision 1.71
        sys/dev/usb/usbnet.h: revision 1.15
        sys/dev/usb/usb_mem.c: revision 1.72
        sys/dev/usb/if_urndis.c: revision 1.24
        sys/dev/usb/if_upl.c: revision 1.67
        sys/dev/usb/usbnet.c: revision 1.25
        sys/dev/usb/usbnet.c: revision 1.26
        sys/dev/usb/usbnet.c: revision 1.27
        sys/dev/usb/usbnet.c: revision 1.28

Teach urndis to handle some REMOTE_NDIS_INDICATE_STATUS_MSG. If the status
is reasonable, don't tell userland we got an error. Stops spurious EIO.
>From openbsd.

Fix bug, remove {0,0} because we switched to usb_lookup().

s/no free/no freelist entry/ in a debug message.

fix a lock hang reported by sc.dying in PR#54495.

remove locking in usbnet_tick().  assume that all locking
needs are handled inside usbnet_tick_task(), which runs in
the usbtask thread.  ensure that usbnet private is valid
before using it.

also check NULL private pointer in usbnet_isdying().
all the other cases should never happen.

don't try to set dying when we haven't usbnet_attach()d yet.
reported by maxv.

- use CALLARGS vs CALLED for better usbhist
- turn off usbnetdebug default
- log for all entry/exit points of usbnet_pipe_intr()
- in usbnet_start_locked() track whether any packet has been
  transmitted for setting the timer.  avoids spurious
  "watchdog timeouts"
- in usbnet_stop() use callout_halt() vs callout_halt, and
  also stop the usb task.  fixes crash of usbtask after the
  phy has detached.
- add a little more defensive checking in the tick task, and
  add some high-log-level logs.
- in usbnet_detach() move the call to usbnet_stop_ifp() above
  the calls to callout/usbtask stopping.
- set ec_mii and unp_pri to NULL when freeing their data

normalise an error message.

document usbnet_private locking.  minor knf.

diffstat:

 sys/dev/usb/if_upl.c    |   7 ++--
 sys/dev/usb/if_url.c    |  12 ++++----
 sys/dev/usb/if_urndis.c |  42 ++++++++++++++++++++++++++++-
 sys/dev/usb/usb_mem.c   |   6 ++--
 sys/dev/usb/usbnet.c    |  70 +++++++++++++++++++++++++++++++++++++-----------
 sys/dev/usb/usbnet.h    |   5 ++-
 6 files changed, 109 insertions(+), 33 deletions(-)

diffs (truncated from 448 to 300 lines):

diff -r c35ee95dec92 -r 834db76541be sys/dev/usb/if_upl.c
--- a/sys/dev/usb/if_upl.c      Fri Sep 13 06:32:11 2019 +0000
+++ b/sys/dev/usb/if_upl.c      Fri Sep 13 06:51:58 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_upl.c,v 1.64.2.1 2019/09/01 13:00:36 martin Exp $   */
+/*     $NetBSD: if_upl.c,v 1.64.2.2 2019/09/13 06:51:58 martin Exp $   */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.64.2.1 2019/09/01 13:00:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.64.2.2 2019/09/13 06:51:58 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -95,8 +95,7 @@
        { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2302 },
        { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL25A1 },
        { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U258 },
-       { USB_VENDOR_NI, USB_PRODUCT_NI_HTOH_7825 },
-       { 0, 0 }
+       { USB_VENDOR_NI, USB_PRODUCT_NI_HTOH_7825 }
 };
 
 int    upl_match(device_t, cfdata_t, void *);
diff -r c35ee95dec92 -r 834db76541be sys/dev/usb/if_url.c
--- a/sys/dev/usb/if_url.c      Fri Sep 13 06:32:11 2019 +0000
+++ b/sys/dev/usb/if_url.c      Fri Sep 13 06:51:58 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_url.c,v 1.66.2.1 2019/09/01 13:00:36 martin Exp $   */
+/*     $NetBSD: if_url.c,v 1.66.2.2 2019/09/13 06:51:58 martin Exp $   */
 
 /*
  * Copyright (c) 2001, 2002
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.66.2.1 2019/09/01 13:00:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.66.2.2 2019/09/13 06:51:58 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -190,7 +190,7 @@
        if (err) {
                aprint_error_dev(self, "failed to set configuration"
                    ", err=%s\n", usbd_errstr(err));
-               goto bad;
+               return;
        }
 
        /* get control interface */
@@ -198,7 +198,7 @@
        if (err) {
                aprint_error_dev(self, "failed to get interface, err=%s\n",
                       usbd_errstr(err));
-               goto bad;
+               return;
        }
 
        un->un_iface = iface;
@@ -221,7 +221,7 @@
                if (ed == NULL) {
                        aprint_error_dev(self,
                            "couldn't get endpoint %d\n", i);
-                       goto bad;
+                       return;
                }
                if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK &&
                    UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN)
@@ -238,7 +238,7 @@
            un->un_ed[USBNET_ENDPT_TX] == 0 ||
            un->un_ed[USBNET_ENDPT_INTR] == 0) {
                aprint_error_dev(self, "missing endpoint\n");
-               goto bad;
+               return;
        }
 
        /* Set these up now for url_mem().  */
diff -r c35ee95dec92 -r 834db76541be sys/dev/usb/if_urndis.c
--- a/sys/dev/usb/if_urndis.c   Fri Sep 13 06:32:11 2019 +0000
+++ b/sys/dev/usb/if_urndis.c   Fri Sep 13 06:51:58 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_urndis.c,v 1.21.4.1 2019/09/01 13:00:36 martin Exp $ */
+/*     $NetBSD: if_urndis.c,v 1.21.4.2 2019/09/13 06:51:58 martin Exp $ */
 /*     $OpenBSD: if_urndis.c,v 1.31 2011/07/03 15:47:17 matthew Exp $ */
 
 /*
@@ -21,7 +21,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.21.4.1 2019/09/01 13:00:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.21.4.2 2019/09/13 06:51:58 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -79,6 +79,8 @@
     const struct rndis_comp_hdr *, void **, size_t *);
 static uint32_t urndis_ctrl_handle_reset(struct usbnet *,
     const struct rndis_comp_hdr *);
+static uint32_t urndis_ctrl_handle_status(struct usbnet *,
+    const struct rndis_comp_hdr *);
 
 static uint32_t urndis_ctrl_set(struct usbnet *, uint32_t, void *,
     size_t);
@@ -207,6 +209,10 @@
                        rval = le32toh(hdr->rm_status);
                        break;
 
+               case REMOTE_NDIS_INDICATE_STATUS_MSG:
+                       rval = urndis_ctrl_handle_status(un, hdr);
+                       break;
+
                default:
                        printf("%s: ctrl message error: unknown event 0x%x\n",
                            DEVNAME(un), le32toh(hdr->rm_type));
@@ -380,6 +386,38 @@
 }
 
 static uint32_t
+urndis_ctrl_handle_status(struct usbnet *un,
+    const struct rndis_comp_hdr *hdr)
+{
+       const struct rndis_status_msg   *msg;
+       uint32_t                        rval;
+
+       msg = (const struct rndis_status_msg *)hdr;
+
+       rval = le32toh(msg->rm_status);
+
+       DPRINTF(("%s: urndis_ctrl_handle_status: len %u status 0x%x "
+           "stbuflen %u\n",
+           DEVNAME(un),
+           le32toh(msg->rm_len),
+           rval,
+           le32toh(msg->rm_stbuflen)));
+
+       switch (rval) {
+               case RNDIS_STATUS_MEDIA_CONNECT:
+               case RNDIS_STATUS_MEDIA_DISCONNECT:
+               case RNDIS_STATUS_OFFLOAD_CURRENT_CONFIG:
+                       rval = RNDIS_STATUS_SUCCESS;
+                       break;
+
+               default:
+                       printf("%s: status 0x%x\n", DEVNAME(un), rval);
+       }
+
+       return rval;
+}
+
+static uint32_t
 urndis_ctrl_init(struct usbnet *un)
 {
        struct rndis_init_req   *msg;
diff -r c35ee95dec92 -r 834db76541be sys/dev/usb/usb_mem.c
--- a/sys/dev/usb/usb_mem.c     Fri Sep 13 06:32:11 2019 +0000
+++ b/sys/dev/usb/usb_mem.c     Fri Sep 13 06:51:58 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb_mem.c,v 1.70.10.1 2019/09/01 13:00:36 martin Exp $ */
+/*     $NetBSD: usb_mem.c,v 1.70.10.2 2019/09/13 06:51:58 martin Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.70.10.1 2019/09/01 13:00:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.70.10.2 2019/09/13 06:51:58 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -136,7 +136,7 @@
                }
        }
 
-       DPRINTFN(6, "no free", 0, 0, 0, 0);
+       DPRINTFN(6, "no freelist entry", 0, 0, 0, 0);
        mutex_exit(&usb_blk_lock);
 
        b = kmem_zalloc(sizeof(*b), KM_SLEEP);
diff -r c35ee95dec92 -r 834db76541be sys/dev/usb/usbnet.c
--- a/sys/dev/usb/usbnet.c      Fri Sep 13 06:32:11 2019 +0000
+++ b/sys/dev/usb/usbnet.c      Fri Sep 13 06:51:58 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbnet.c,v 1.25.2.2 2019/09/01 13:00:36 martin Exp $   */
+/*     $NetBSD: usbnet.c,v 1.25.2.3 2019/09/13 06:51:58 martin Exp $   */
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.25.2.2 2019/09/01 13:00:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.25.2.3 2019/09/13 06:51:58 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -59,6 +59,11 @@
         * - unp_rxlock protects the rx path and its data
         * - unp_txlock protects the tx path and its data
         * - unp_detachcv handles detach vs open references
+        *
+        * the lock ordering is:
+        *      ifnet lock -> unp_lock -> unp_rxlock -> unp_txlock
+        *      unp_lock -> unp_miilock
+        * and unp_lock may be dropped after taking unp_miilock.
         */
        kmutex_t                unp_lock;
        kmutex_t                unp_miilock;
@@ -101,7 +106,7 @@
 #ifndef USBNET_DEBUG
 #define usbnetdebug 0
 #else
-static int usbnetdebug = 1;
+static int usbnetdebug = 0;
 
 SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup")
 {
@@ -418,6 +423,7 @@
 static void
 usbnet_pipe_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
 {
+       USBNETHIST_FUNC();
        struct usbnet * const un = priv;
        struct usbnet_private * const unp = un->un_pri;
        struct usbnet_intr * const uni = un->un_intr;
@@ -425,8 +431,12 @@
 
        if (uni == NULL || unp->unp_dying || unp->unp_stopping ||
            status == USBD_INVAL || status == USBD_NOT_STARTED ||
-           status == USBD_CANCELLED || !(ifp->if_flags & IFF_RUNNING))
+           status == USBD_CANCELLED || !(ifp->if_flags & IFF_RUNNING)) {
+               USBNETHIST_CALLARGS("%d: uni %jx d/s %x status %x",
+                   unp->unp_number, (uintptr_t)uni,
+                   (unp->unp_dying << 8) | unp->unp_stopping, status);
                return;
+       }
 
        if (status != USBD_NORMAL_COMPLETION) {
                if (usbd_ratecheck(&unp->unp_intr_notice)) {
@@ -435,6 +445,8 @@
                }
                if (status == USBD_STALLED)
                        usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_INTR]);
+               USBNETHIST_CALLARGS("%d: not normal status %x",
+                   unp->unp_number, status, 0, 0);
                return;
        }
 
@@ -444,14 +456,19 @@
 static void
 usbnet_start_locked(struct ifnet *ifp)
 {
-       USBNETHIST_FUNC(); USBNETHIST_CALLED();
+       USBNETHIST_FUNC();
        struct usbnet * const un = ifp->if_softc;
        struct usbnet_cdata * const cd = un_cdata(un);
        struct usbnet_private * const unp = un->un_pri;
        struct mbuf *m;
        unsigned length;
+       bool done_transmit = false;
        int idx;
 
+       USBNETHIST_CALLARGS("%d: tx_cnt %d list_cnt %d link %d",
+           unp->unp_number, cd->uncd_tx_cnt, un->un_tx_list_cnt,
+           unp->unp_link);
+
        usbnet_isowned_tx(un);
        KASSERT(cd->uncd_tx_cnt <= un->un_tx_list_cnt);
 
@@ -502,6 +519,7 @@
                        ifp->if_oerrors++;
                        break;
                }
+               done_transmit = true;
 
                IFQ_DEQUEUE(&ifp->if_snd, m);
 
@@ -517,10 +535,14 @@
        }
        cd->uncd_tx_prod = idx;
 
+       DPRINTF("finished with start; tx_cnt %d list_cnt %d link %d",
+           cd->uncd_tx_cnt, un->un_tx_list_cnt, unp->unp_link, 0);
+
        /*
         * Set a timeout in case the chip goes out to lunch.
         */
-       unp->unp_timer = 5;
+       if (done_transmit)
+               unp->unp_timer = 5;
 }
 



Home | Main Index | Thread Index | Old Index