Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb switch urndis(4) to usbnet. thanks to maya@ for...



details:   https://anonhg.NetBSD.org/src/rev/7fda41d6faea
branches:  trunk
changeset: 964612:7fda41d6faea
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Aug 09 06:38:39 2019 +0000

description:
switch urndis(4) to usbnet.  thanks to maya@ for testing and helping
fix the few issues in the conversion.

diffstat:

 sys/dev/usb/TODO        |    2 +-
 sys/dev/usb/files.usb   |    4 +-
 sys/dev/usb/if_urndis.c |  971 +++++++++++------------------------------------
 3 files changed, 236 insertions(+), 741 deletions(-)

diffs (truncated from 1663 to 300 lines):

diff -r 4d7a52f94160 -r 7fda41d6faea sys/dev/usb/TODO
--- a/sys/dev/usb/TODO  Fri Aug 09 06:27:21 2019 +0000
+++ b/sys/dev/usb/TODO  Fri Aug 09 06:38:39 2019 +0000
@@ -73,7 +73,7 @@
        if_upl - patch available
        if_ure - done
        if_url - patch available
-       if_urndis - patch available, probably works
+       if_urndis - done
 
 Get rid of hcpriv.
 
diff -r 4d7a52f94160 -r 7fda41d6faea sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Fri Aug 09 06:27:21 2019 +0000
+++ b/sys/dev/usb/files.usb     Fri Aug 09 06:38:39 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.161 2019/08/07 19:21:48 skrll Exp $
+#      $NetBSD: files.usb,v 1.162 2019/08/09 06:38:39 mrg Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -528,7 +528,7 @@
 file   dev/usb/uyurex.c                uyurex
 
 # Microsoft RNDIS
-device urndis: arp, ether, ifnet
+device urndis: arp, ether, ifnet, usbnet
 attach urndis at usbifif
 file   dev/usb/if_urndis.c             urndis
 
diff -r 4d7a52f94160 -r 7fda41d6faea sys/dev/usb/if_urndis.c
--- a/sys/dev/usb/if_urndis.c   Fri Aug 09 06:27:21 2019 +0000
+++ b/sys/dev/usb/if_urndis.c   Fri Aug 09 06:38:39 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_urndis.c,v 1.25 2019/08/08 18:03:40 mrg Exp $ */
+/*     $NetBSD: if_urndis.c,v 1.26 2019/08/09 06:38:39 mrg 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.25 2019/08/08 18:03:40 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.26 2019/08/09 06:38:39 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -29,28 +29,10 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/sockio.h>
-#include <sys/rwlock.h>
-#include <sys/mbuf.h>
 #include <sys/kmem.h>
 #include <sys/kernel.h>
-#include <sys/proc.h>
-#include <sys/socket.h>
-#include <sys/device.h>
-#include <sys/endian.h>
 
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-#include <net/if_ether.h>
-
-#include <net/bpf.h>
-
-#include <sys/bus.h>
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usbdivar.h>
+#include <dev/usb/usbnet.h>
 #include <dev/usb/usbdevs.h>
 #include <dev/usb/usbcdc.h>
 
@@ -60,48 +42,16 @@
 #define RNDIS_TX_LIST_CNT      1
 #define RNDIS_BUFSZ            1562
 
-struct urndis_softc;
-
-struct urndis_chain {
-       struct urndis_softc     *sc_softc;
-       struct usbd_xfer        *sc_xfer;
-       char                    *sc_buf;
-       struct mbuf             *sc_mbuf;
-};
+struct urndis_softc {
+       struct usbnet                   sc_un;
 
-struct urndis_cdata {
-       struct urndis_chain     sc_rx_chain[RNDIS_RX_LIST_CNT];
-       struct urndis_chain     sc_tx_chain[RNDIS_TX_LIST_CNT];
-       int                     sc_tx_cnt;
-};
-
-#define GET_IFP(sc) (&(sc)->sc_ec.ec_if)
-struct urndis_softc {
-       device_t                        sc_dev;
-
-       char                            sc_attached;
-       int                             sc_dying;
-       struct ethercom                 sc_ec;
+       int                             sc_ifaceno_ctl;
 
        /* RNDIS device info */
        uint32_t                        sc_filter;
        uint32_t                        sc_maxppt;
        uint32_t                        sc_maxtsz;
        uint32_t                        sc_palign;
-
-       /* USB goo */
-       struct usbd_device *            sc_udev;
-       int                             sc_ifaceno_ctl;
-       struct usbd_interface *         sc_iface_ctl;
-       struct usbd_interface *         sc_iface_data;
-
-       struct timeval                  sc_rx_notice;
-       int                             sc_bulkin_no;
-       struct usbd_pipe *              sc_bulkin_pipe;
-       int                             sc_bulkout_no;
-       struct usbd_pipe *              sc_bulkout_pipe;
-
-       struct urndis_cdata             sc_data;
 };
 
 #ifdef URNDIS_DEBUG
@@ -110,69 +60,45 @@
 #define DPRINTF(x)
 #endif
 
-#define DEVNAME(sc)    (device_xname(sc->sc_dev))
+#define DEVNAME(un)    (device_xname(un->un_dev))
 
 #define URNDIS_RESPONSE_LEN 0x400
 
-
-static int urndis_newbuf(struct urndis_softc *, struct urndis_chain *);
-
-static int urndis_ioctl(struct ifnet *, unsigned long, void *);
 #if 0
 static void urndis_watchdog(struct ifnet *);
 #endif
 
-static void urndis_start(struct ifnet *);
-static void urndis_rxeof(struct usbd_xfer *, void *, usbd_status);
-static void urndis_txeof(struct usbd_xfer *, void *, usbd_status);
-static int urndis_rx_list_init(struct urndis_softc *);
-static int urndis_tx_list_init(struct urndis_softc *);
+static int urndis_init(struct ifnet *);
+static void urndis_rx_loop(struct usbnet *, struct usbd_xfer *,
+                          struct usbnet_chain *, uint32_t);
+static unsigned urndis_tx_prepare(struct usbnet *, struct mbuf *,
+                                 struct usbnet_chain *);
 
-static int urndis_init(struct ifnet *);
-static void urndis_stop(struct ifnet *);
+static int urndis_init_un(struct ifnet *, struct usbnet *);
 
-static usbd_status urndis_ctrl_msg(struct urndis_softc *, uint8_t, uint8_t,
-    uint16_t, uint16_t, void *, size_t);
-static usbd_status urndis_ctrl_send(struct urndis_softc *, void *, size_t);
-static struct rndis_comp_hdr *urndis_ctrl_recv(struct urndis_softc *);
-
-static uint32_t urndis_ctrl_handle(struct urndis_softc *,
-    struct rndis_comp_hdr *, void **, size_t *);
-static uint32_t urndis_ctrl_handle_init(struct urndis_softc *,
+static uint32_t urndis_ctrl_handle_init(struct usbnet *,
     const struct rndis_comp_hdr *);
-static uint32_t urndis_ctrl_handle_query(struct urndis_softc *,
+static uint32_t urndis_ctrl_handle_query(struct usbnet *,
     const struct rndis_comp_hdr *, void **, size_t *);
-static uint32_t urndis_ctrl_handle_reset(struct urndis_softc *,
+static uint32_t urndis_ctrl_handle_reset(struct usbnet *,
     const struct rndis_comp_hdr *);
-static uint32_t urndis_ctrl_handle_status(struct urndis_softc *,
+static uint32_t urndis_ctrl_handle_status(struct usbnet *,
     const struct rndis_comp_hdr *);
 
-static uint32_t urndis_ctrl_init(struct urndis_softc *);
-#if 0
-static uint32_t urndis_ctrl_halt(struct urndis_softc *);
-#endif
-static uint32_t urndis_ctrl_query(struct urndis_softc *, uint32_t, void *,
-    size_t, void **, size_t *);
-static uint32_t urndis_ctrl_set(struct urndis_softc *, uint32_t, void *,
+static uint32_t urndis_ctrl_set(struct usbnet *, uint32_t, void *,
     size_t);
-#if 0
-static uint32_t urndis_ctrl_set_param(struct urndis_softc *, const char *,
-    uint32_t, void *, size_t);
-static uint32_t urndis_ctrl_reset(struct urndis_softc *);
-static uint32_t urndis_ctrl_keepalive(struct urndis_softc *);
-#endif
-
-static int urndis_encap(struct urndis_softc *, struct mbuf *, int);
-static void urndis_decap(struct urndis_softc *, struct urndis_chain *,
-    uint32_t);
 
 static int urndis_match(device_t, cfdata_t, void *);
 static void urndis_attach(device_t, device_t, void *);
-static int urndis_detach(device_t, int);
-static int urndis_activate(device_t, enum devact);
+
+static struct usbnet_ops urndis_ops = {
+       .uno_init = urndis_init,
+       .uno_tx_prepare = urndis_tx_prepare,
+       .uno_rx_loop = urndis_rx_loop,
+};
 
 CFATTACH_DECL_NEW(urndis, sizeof(struct urndis_softc),
-    urndis_match, urndis_attach, urndis_detach, urndis_activate);
+    urndis_match, urndis_attach, usbnet_detach, usbnet_activate);
 
 /*
  * Supported devices that we can't match by class IDs.
@@ -184,7 +110,7 @@
 };
 
 static usbd_status
-urndis_ctrl_msg(struct urndis_softc *sc, uint8_t rt, uint8_t r,
+urndis_ctrl_msg(struct usbnet *un, uint8_t rt, uint8_t r,
     uint16_t index, uint16_t value, void *buf, size_t buflen)
 {
        usb_device_request_t req;
@@ -195,52 +121,57 @@
        USETW(req.wIndex, index);
        USETW(req.wLength, buflen);
 
-       return usbd_do_request(sc->sc_udev, &req, buf);
+       return usbd_do_request(un->un_udev, &req, buf);
 }
 
 static usbd_status
-urndis_ctrl_send(struct urndis_softc *sc, void *buf, size_t len)
+urndis_ctrl_send(struct usbnet *un, void *buf, size_t len)
 {
+       struct urndis_softc     *sc = usbnet_softc(un);
        usbd_status err;
 
-       if (sc->sc_dying)
+       if (un->un_dying)
                return(0);
 
-       err = urndis_ctrl_msg(sc, UT_WRITE_CLASS_INTERFACE, UR_GET_STATUS,
+       err = urndis_ctrl_msg(un, UT_WRITE_CLASS_INTERFACE, UR_GET_STATUS,
            sc->sc_ifaceno_ctl, 0, buf, len);
 
        if (err != USBD_NORMAL_COMPLETION)
-               printf("%s: %s\n", DEVNAME(sc), usbd_errstr(err));
+               printf("%s: %s\n", DEVNAME(un), usbd_errstr(err));
 
        return err;
 }
 
 static struct rndis_comp_hdr *
-urndis_ctrl_recv(struct urndis_softc *sc)
+urndis_ctrl_recv(struct usbnet *un)
 {
+       struct urndis_softc     *sc = usbnet_softc(un);
        struct rndis_comp_hdr   *hdr;
        char                    *buf;
        usbd_status              err;
 
+       if (un->un_dying)
+               return(0);
+
        buf = kmem_alloc(URNDIS_RESPONSE_LEN, KM_SLEEP);
-       err = urndis_ctrl_msg(sc, UT_READ_CLASS_INTERFACE, UR_CLEAR_FEATURE,
+       err = urndis_ctrl_msg(un, UT_READ_CLASS_INTERFACE, UR_CLEAR_FEATURE,
            sc->sc_ifaceno_ctl, 0, buf, URNDIS_RESPONSE_LEN);
 
        if (err != USBD_NORMAL_COMPLETION && err != USBD_SHORT_XFER) {
-               printf("%s: %s\n", DEVNAME(sc), usbd_errstr(err));
+               printf("%s: %s\n", DEVNAME(un), usbd_errstr(err));
                kmem_free(buf, URNDIS_RESPONSE_LEN);
                return NULL;
        }
 
        hdr = (struct rndis_comp_hdr *)buf;
        DPRINTF(("%s: urndis_ctrl_recv: type 0x%x len %u\n",
-           DEVNAME(sc),
+           DEVNAME(un),
            le32toh(hdr->rm_type),
            le32toh(hdr->rm_len)));
 
        if (le32toh(hdr->rm_len) > URNDIS_RESPONSE_LEN) {
                printf("%s: ctrl message error: wrong size %u > %u\n",
-                   DEVNAME(sc),
+                   DEVNAME(un),
                    le32toh(hdr->rm_len),
                    URNDIS_RESPONSE_LEN);
                kmem_free(buf, URNDIS_RESPONSE_LEN);
@@ -251,12 +182,12 @@
 }
 
 static uint32_t



Home | Main Index | Thread Index | Old Index