Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb update usbnet slight:



details:   https://anonhg.NetBSD.org/src/rev/f6d921a7bfca
branches:  trunk
changeset: 964811:f6d921a7bfca
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Aug 18 09:29:38 2019 +0000

description:
update usbnet slight:
- drivers that want to use if_input() will also set _if_input.  for
  now, avoid attaching a per-cpu queue for them.  use if_initialize()
  and if_register().
- when stopping pipes, don't give up after the first failure, but
  keep the first failure error for return and keep going
- if 0 a KASSERT() in usbnet_init_rx_tx().  there's a path via
  if_mcast_op() that can have the ifnet unlocked today..
- in usbnet_watchdog(), abort the pipe instead of faking tx
  completion.  avoids issues with devices with more than one tx
  descriptor, as well as avoiding triggering usb asserts.

with these, upl(4) port to usbnet(9) now works.  (would be a version
bump, but upl(4) and the unported umb(4) are the only consumers that
would care.)

diffstat:

 sys/dev/usb/files.usb |    4 +-
 sys/dev/usb/if_upl.c  |  909 +++++--------------------------------------------
 sys/dev/usb/usbnet.c  |   45 +-
 3 files changed, 137 insertions(+), 821 deletions(-)

diffs (truncated from 1219 to 300 lines):

diff -r f2c8cdd041c0 -r f6d921a7bfca sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Sun Aug 18 09:14:30 2019 +0000
+++ b/sys/dev/usb/files.usb     Sun Aug 18 09:29:38 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.165 2019/08/16 08:52:46 mrg Exp $
+#      $NetBSD: files.usb,v 1.166 2019/08/18 09:29:38 mrg Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -354,7 +354,7 @@
 file   dev/usb/if_kue.c                kue
 
 # Prolific PL2302 host-host
-device upl: ifnet
+device upl: ifnet, usbnet
 attach upl at usbdevif
 file   dev/usb/if_upl.c                upl
 
diff -r f2c8cdd041c0 -r f6d921a7bfca sys/dev/usb/if_upl.c
--- a/sys/dev/usb/if_upl.c      Sun Aug 18 09:14:30 2019 +0000
+++ b/sys/dev/usb/if_upl.c      Sun Aug 18 09:29:38 2019 +0000
@@ -1,4 +1,5 @@
-/*     $NetBSD: if_upl.c,v 1.64 2019/07/21 10:27:56 mrg Exp $  */
+/*     $NetBSD: if_upl.c,v 1.65 2019/08/18 09:29:38 mrg Exp $  */
+
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.64 2019/07/21 10:27:56 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.65 2019/08/18 09:29:38 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -42,22 +43,10 @@
 #endif
 
 #include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/callout.h>
-#include <sys/sockio.h>
-#include <sys/mbuf.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
 
-#include <sys/device.h>
-#include <sys/rndsource.h>
+#include <dev/usb/usbnet.h>
 
-#include <net/if.h>
 #include <net/if_types.h>
-#include <net/if_dl.h>
-#include <net/netisr.h>
-
-#include <net/bpf.h>
 
 #ifdef INET
 #include <netinet/in.h>
@@ -65,12 +54,6 @@
 #include <netinet/if_inarp.h>
 #endif
 
-
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usbdevs.h>
-
 /*
  * 7  6  5  4  3  2  1  0
  * tx rx 1  0
@@ -83,8 +66,6 @@
 #define UPL_RXDATA             0x40
 #define UPL_TXOK               0x80
 
-#define UPL_INTR_PKTLEN                1
-
 #define UPL_CONFIG_NO          1
 #define UPL_IFACE_IDX          0
 
@@ -94,63 +75,9 @@
 
 #define UPL_BUFSZ              1024
 
-#define UPL_RX_FRAMES          1
-#define UPL_TX_FRAMES          1
-
 #define UPL_RX_LIST_CNT                1
 #define UPL_TX_LIST_CNT                1
 
-#define UPL_ENDPT_RX           0x0
-#define UPL_ENDPT_TX           0x1
-#define UPL_ENDPT_INTR         0x2
-#define UPL_ENDPT_MAX          0x3
-
-struct upl_type {
-       uint16_t                upl_vid;
-       uint16_t                upl_did;
-};
-
-struct upl_softc;
-
-struct upl_chain {
-       struct upl_softc        *upl_sc;
-       struct usbd_xfer        *upl_xfer;
-       char                    *upl_buf;
-       struct mbuf             *upl_mbuf;
-};
-
-struct upl_cdata {
-       struct upl_chain        upl_tx_chain[UPL_TX_LIST_CNT];
-       struct upl_chain        upl_rx_chain[UPL_RX_LIST_CNT];
-       int                     upl_tx_prod;
-       int                     upl_tx_cnt;
-};
-
-struct upl_softc {
-       device_t                sc_dev;
-
-       struct ifnet            sc_if;
-       krndsource_t    sc_rnd_source;
-
-       struct callout          sc_stat_ch;
-
-       struct usbd_device *    sc_udev;
-       struct usbd_interface * sc_iface;
-       uint16_t                sc_vendor;
-       uint16_t                sc_product;
-       int                     sc_ed[UPL_ENDPT_MAX];
-       struct usbd_pipe *      sc_ep[UPL_ENDPT_MAX];
-       struct upl_cdata        sc_cdata;
-
-       uByte                   sc_ibuf;
-
-       char                    sc_dying;
-       char                    sc_attached;
-       u_int                   sc_rx_errs;
-       struct timeval          sc_rx_notice;
-       u_int                   sc_intr_errs;
-};
-
 #ifdef UPL_DEBUG
 #define DPRINTF(x)     if (upldebug) printf x
 #define DPRINTFN(n,x)  if (upldebug >= (n)) printf x
@@ -163,37 +90,43 @@
 /*
  * Various supported device vendors/products.
  */
-Static struct upl_type sc_devs[] = {
+static struct usb_devno sc_devs[] = {
        { USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2301 },
        { 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 }
 };
 
 int    upl_match(device_t, cfdata_t, void *);
 void   upl_attach(device_t, device_t, void *);
-int    upl_detach(device_t, int);
-int    upl_activate(device_t, enum devact);
+
+CFATTACH_DECL_NEW(upl, sizeof(struct usbnet), upl_match, upl_attach,
+    usbnet_detach, usbnet_activate);
 
-CFATTACH_DECL_NEW(upl, sizeof(struct upl_softc), upl_match, upl_attach,
-    upl_detach, upl_activate);
+#if 0
+static void upl_intr_cb(struct usbnet *, usbd_status);
+#endif
+static void upl_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
+static unsigned upl_tx_prepare(struct usbnet *, struct mbuf *,
+                              struct usbnet_chain *);
+static int upl_ioctl_cb(struct ifnet *, u_long, void *);
+static int upl_init(struct ifnet *);
 
-Static int upl_openpipes(struct upl_softc *);
-Static int upl_tx_list_init(struct upl_softc *);
-Static int upl_rx_list_init(struct upl_softc *);
-Static int upl_newbuf(struct upl_softc *, struct upl_chain *, struct mbuf *);
-Static int upl_send(struct upl_softc *, struct mbuf *, int);
-Static void upl_intr(struct usbd_xfer *, void *, usbd_status);
-Static void upl_rxeof(struct usbd_xfer *, void *, usbd_status);
-Static void upl_txeof(struct usbd_xfer *, void *, usbd_status);
-Static void upl_start(struct ifnet *);
-Static int upl_ioctl(struct ifnet *, u_long, void *);
-Static void upl_init(void *);
-Static void upl_stop(struct upl_softc *);
-Static void upl_watchdog(struct ifnet *);
+static struct usbnet_ops upl_ops = {
+       .uno_init = upl_init,
+       .uno_tx_prepare = upl_tx_prepare,
+       .uno_rx_loop = upl_rx_loop,
+       .uno_ioctl = upl_ioctl_cb,
+#if 0
+       .uno_intr = upl_intr_cb,
+#endif
+};
 
-Static int upl_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
+static int upl_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
                      const struct rtentry *);
-Static void upl_input(struct ifnet *, struct mbuf *);
+static void upl_input(struct ifnet *, struct mbuf *);
 
 /*
  * Probe for a Prolific chip.
@@ -202,42 +135,42 @@
 upl_match(device_t parent, cfdata_t match, void *aux)
 {
        struct usb_attach_arg *uaa = aux;
-       struct upl_type                 *t;
 
-       for (t = sc_devs; t->upl_vid != 0; t++)
-               if (uaa->uaa_vendor == t->upl_vid && uaa->uaa_product == t->upl_did)
-                       return UMATCH_VENDOR_PRODUCT;
-
-       return UMATCH_NONE;
+       return usb_lookup(sc_devs, uaa->uaa_vendor, uaa->uaa_product) != NULL ?
+               UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
 }
 
 void
 upl_attach(device_t parent, device_t self, void *aux)
 {
-       struct upl_softc *sc = device_private(self);
-       struct usb_attach_arg *uaa = aux;
+       struct usbnet * const   un = device_private(self);
+       struct usb_attach_arg   *uaa = aux;
        char                    *devinfop;
-       int                     s;
        struct usbd_device *    dev = uaa->uaa_device;
-       struct usbd_interface * iface;
        usbd_status             err;
-       struct ifnet            *ifp;
        usb_interface_descriptor_t      *id;
        usb_endpoint_descriptor_t       *ed;
        int                     i;
-       int                     rv;
 
-       DPRINTFN(5,(" : upl_attach: sc=%p, dev=%p", sc, dev));
-
-       sc->sc_dev = self;
+       DPRINTFN(5,(" : upl_attach: un=%p, dev=%p", un, dev));
 
        aprint_naive("\n");
        aprint_normal("\n");
-
        devinfop = usbd_devinfo_alloc(dev, 0);
        aprint_normal_dev(self, "%s\n", devinfop);
        usbd_devinfo_free(devinfop);
 
+       un->un_dev = self;
+       un->un_udev = dev;
+       un->un_sc = un;
+       un->un_ops = &upl_ops;
+       un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
+       un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       un->un_rx_list_cnt = UPL_RX_LIST_CNT;
+       un->un_tx_list_cnt = UPL_TX_LIST_CNT;
+       un->un_rx_bufsz = UPL_BUFSZ;
+       un->un_tx_bufsz = UPL_BUFSZ;
+
        err = usbd_set_config_no(dev, UPL_CONFIG_NO, 1);
        if (err) {
                aprint_error_dev(self, "failed to set configuration"
@@ -245,56 +178,41 @@
                return;
        }
 
-       sc->sc_udev = dev;
-       sc->sc_product = uaa->uaa_product;
-       sc->sc_vendor = uaa->uaa_vendor;
-
-       err = usbd_device2interface_handle(dev, UPL_IFACE_IDX, &iface);
+       err = usbd_device2interface_handle(dev, UPL_IFACE_IDX, &un->un_iface);
        if (err) {
                aprint_error_dev(self, "getting interface handle failed\n");
                return;
        }
 
-       sc->sc_iface = iface;
-       id = usbd_get_interface_descriptor(iface);
+       id = usbd_get_interface_descriptor(un->un_iface);
 
        /* Find endpoints. */
        for (i = 0; i < id->bNumEndpoints; i++) {
-               ed = usbd_interface2endpoint_descriptor(iface, i);
+               ed = usbd_interface2endpoint_descriptor(un->un_iface, i);
                if (ed == NULL) {
                        aprint_error_dev(self, "couldn't get ep %d\n", i);
                        return;
                }
                if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
                    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
-                       sc->sc_ed[UPL_ENDPT_RX] = ed->bEndpointAddress;



Home | Main Index | Thread Index | Old Index