Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb port cue(4), mue(4) and url(4) to usbnet(9). di...



details:   https://anonhg.NetBSD.org/src/rev/a8e2857d2b0d
branches:  trunk
changeset: 458885:a8e2857d2b0d
user:      mrg <mrg%NetBSD.org@localhost>
date:      Thu Aug 15 08:02:32 2019 +0000

description:
port cue(4), mue(4) and url(4) to usbnet(9).  diffstat says:

8 files changed, 911 insertions(+), 3087 deletions(-)

diffstat:

 sys/dev/usb/files.usb   |     8 +-
 sys/dev/usb/if_cue.c    |  1125 ++++++++--------------------------
 sys/dev/usb/if_cuereg.h |    73 +--
 sys/dev/usb/if_mue.c    |  1506 +++++++++++++---------------------------------
 sys/dev/usb/if_muereg.h |     6 +-
 sys/dev/usb/if_muevar.h |    67 +--
 sys/dev/usb/if_url.c    |  1327 +++++++++--------------------------------
 sys/dev/usb/if_urlreg.h |    60 +-
 8 files changed, 998 insertions(+), 3174 deletions(-)

diffs (truncated from 5737 to 300 lines):

diff -r e0cf89a964c5 -r a8e2857d2b0d sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Thu Aug 15 05:52:23 2019 +0000
+++ b/sys/dev/usb/files.usb     Thu Aug 15 08:02:32 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.163 2019/08/11 11:17:35 skrll Exp $
+#      $NetBSD: files.usb,v 1.164 2019/08/15 08:02:32 mrg Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -344,7 +344,7 @@
 file   dev/usb/if_cdce.c               cdce
 
 # CATC USB-EL1201A
-device cue: arp, ether, ifnet
+device cue: arp, ether, ifnet, usbnet
 attach cue at usbdevif
 file   dev/usb/if_cue.c                cue
 
@@ -359,7 +359,7 @@
 file   dev/usb/if_upl.c                upl
 
 # Realtek RTL8150L(M)
-device url: arp, ether, ifnet, mii
+device url: arp, ether, ifnet, mii, usbnet
 attach url at usbdevif
 file   dev/usb/if_url.c                url
 
@@ -374,7 +374,7 @@
 file   dev/usb/if_axen.c               axen
 
 # Microchip LAN750x and LAN85xx
-device mue: arp, ether, ifnet, mii, mii_phy
+device mue: arp, ether, ifnet, mii, mii_phy, usbnet
 attach mue at usbdevif
 file   dev/usb/if_mue.c                mue
 
diff -r e0cf89a964c5 -r a8e2857d2b0d sys/dev/usb/if_cue.c
--- a/sys/dev/usb/if_cue.c      Thu Aug 15 05:52:23 2019 +0000
+++ b/sys/dev/usb/if_cue.c      Thu Aug 15 08:02:32 2019 +0000
@@ -1,4 +1,5 @@
-/*     $NetBSD: if_cue.c,v 1.84 2019/05/28 07:41:50 msaitoh Exp $      */
+/*     $NetBSD: if_cue.c,v 1.85 2019/08/15 08:02:32 mrg Exp $  */
+
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
  *     Bill Paul <wpaul%ee.columbia.edu@localhost>.  All rights reserved.
@@ -56,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.84 2019/05/28 07:41:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.85 2019/08/15 08:02:32 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -64,34 +65,15 @@
 #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/bus.h>
-#include <sys/device.h>
 
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/if_dl.h>
-#include <net/bpf.h>
-#include <net/if_ether.h>
+#include <dev/usb/usbnet.h>
+#include <dev/usb/if_cuereg.h>
 
 #ifdef INET
 #include <netinet/in.h>
 #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/usbdivar.h>
-#include <dev/usb/usbdevs.h>
-
-#include <dev/usb/if_cuereg.h>
-
 #ifdef CUE_DEBUG
 #define DPRINTF(x)     if (cuedebug) printf x
 #define DPRINTFN(n, x) if (cuedebug >= (n)) printf x
@@ -101,10 +83,48 @@
 #define DPRINTFN(n, x)
 #endif
 
+#define CUE_BUFSZ              1536
+#define CUE_MIN_FRAMELEN       60
+#define CUE_RX_FRAMES          1
+#define CUE_TX_FRAMES          1
+
+#define CUE_CONFIG_NO          1
+#define CUE_IFACE_IDX          0
+
+#define CUE_RX_LIST_CNT                1
+#define CUE_TX_LIST_CNT                1
+
+struct cue_type {
+       uint16_t                cue_vid;
+       uint16_t                cue_did;
+};
+
+struct cue_softc;
+
+struct cue_chain {
+       struct cue_softc        *cue_sc;
+       struct usbd_xfer        *cue_xfer;
+       char                    *cue_buf;
+       struct mbuf             *cue_mbuf;
+       int                     cue_idx;
+};
+
+struct cue_cdata {
+       struct cue_chain        cue_tx_chain[CUE_TX_LIST_CNT];
+       struct cue_chain        cue_rx_chain[CUE_RX_LIST_CNT];
+       int                     cue_tx_prod;
+       int                     cue_tx_cnt;
+};
+
+struct cue_softc {
+       struct usbnet           cue_un;
+       uint8_t                 cue_mctab[CUE_MCAST_TABLE_LEN];
+};
+
 /*
  * Various supported device vendors/products.
  */
-Static struct usb_devno cue_devs[] = {
+static struct usb_devno cue_devs[] = {
        { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
        { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
        { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
@@ -114,54 +134,36 @@
 
 int cue_match(device_t, cfdata_t, void *);
 void cue_attach(device_t, device_t, void *);
-int cue_detach(device_t, int);
-int cue_activate(device_t, enum devact);
 
 CFATTACH_DECL_NEW(cue, sizeof(struct cue_softc), cue_match, cue_attach,
-    cue_detach, cue_activate);
+    usbnet_detach, usbnet_activate);
 
-Static int cue_open_pipes(struct cue_softc *);
-Static int cue_tx_list_init(struct cue_softc *);
-Static int cue_rx_list_init(struct cue_softc *);
-Static int cue_newbuf(struct cue_softc *, struct cue_chain *, struct mbuf *);
-Static int cue_send(struct cue_softc *, struct mbuf *, int);
-Static void cue_rxeof(struct usbd_xfer *, void *, usbd_status);
-Static void cue_txeof(struct usbd_xfer *, void *, usbd_status);
-Static void cue_tick(void *);
-Static void cue_tick_task(void *);
-Static void cue_start(struct ifnet *);
-Static int cue_ioctl(struct ifnet *, u_long, void *);
-Static void cue_init(void *);
-Static void cue_stop(struct cue_softc *);
-Static void cue_watchdog(struct ifnet *);
+static unsigned cue_tx_prepare(struct usbnet *, struct mbuf *,
+                         struct usbnet_chain *);
+static void cue_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
+static int cue_ioctl_cb(struct ifnet *, u_long, void *);
+static void cue_stop_cb(struct ifnet *, int);
+static int cue_init(struct ifnet *);
+static void cue_tick(struct usbnet *);
 
-Static void cue_setmulti(struct cue_softc *);
-Static uint32_t cue_crc(const char *);
-Static void cue_reset(struct cue_softc *);
+static struct usbnet_ops cue_ops = {
+       .uno_stop = cue_stop_cb,
+       .uno_ioctl = cue_ioctl_cb,
+       .uno_tx_prepare = cue_tx_prepare,
+       .uno_rx_loop = cue_rx_loop,
+       .uno_init = cue_init,
+       .uno_tick = cue_tick,
+};
 
-Static int cue_csr_read_1(struct cue_softc *, int);
-Static int cue_csr_write_1(struct cue_softc *, int, int);
-Static int cue_csr_read_2(struct cue_softc *, int);
-#if 0
-Static int cue_csr_write_2(struct cue_softc *, int, int);
-#endif
-Static int cue_mem(struct cue_softc *, int, int, void *, int);
-Static int cue_getmac(struct cue_softc *, void *);
-
-#define CUE_SETBIT(sc, reg, x)                         \
-       cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
-
-#define CUE_CLRBIT(sc, reg, x)                         \
-       cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
-
-Static int
-cue_csr_read_1(struct cue_softc        *sc, int reg)
+#ifdef CUE_DEBUG
+static int
+cue_csr_read_1(struct usbnet *un, int reg)
 {
        usb_device_request_t    req;
        usbd_status             err;
        uint8_t                 val = 0;
 
-       if (sc->cue_dying)
+       if (usbnet_isdying(un))
                return 0;
 
        req.bmRequestType = UT_READ_VENDOR_DEVICE;
@@ -170,28 +172,29 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, 1);
 
-       err = usbd_do_request(sc->cue_udev, &req, &val);
+       err = usbd_do_request(un->un_udev, &req, &val);
 
        if (err) {
                DPRINTF(("%s: cue_csr_read_1: reg=0x%x err=%s\n",
-                   device_xname(sc->cue_dev), reg, usbd_errstr(err)));
+                   device_xname(un->un_dev), reg, usbd_errstr(err)));
                return 0;
        }
 
        DPRINTFN(10,("%s: cue_csr_read_1 reg=0x%x val=0x%x\n",
-           device_xname(sc->cue_dev), reg, val));
+           device_xname(un->un_dev), reg, val));
 
        return val;
 }
+#endif
 
-Static int
-cue_csr_read_2(struct cue_softc        *sc, int reg)
+static int
+cue_csr_read_2(struct usbnet *un, int reg)
 {
        usb_device_request_t    req;
        usbd_status             err;
        uWord                   val;
 
-       if (sc->cue_dying)
+       if (usbnet_isdying(un))
                return 0;
 
        req.bmRequestType = UT_READ_VENDOR_DEVICE;
@@ -200,31 +203,31 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, 2);
 
-       err = usbd_do_request(sc->cue_udev, &req, &val);
+       err = usbd_do_request(un->un_udev, &req, &val);
 
        DPRINTFN(10,("%s: cue_csr_read_2 reg=0x%x val=0x%x\n",
-           device_xname(sc->cue_dev), reg, UGETW(val)));
+           device_xname(un->un_dev), reg, UGETW(val)));
 
        if (err) {
                DPRINTF(("%s: cue_csr_read_2: reg=0x%x err=%s\n",
-                   device_xname(sc->cue_dev), reg, usbd_errstr(err)));
+                   device_xname(un->un_dev), reg, usbd_errstr(err)));
                return 0;
        }
 
        return UGETW(val);
 }
 
-Static int
-cue_csr_write_1(struct cue_softc *sc, int reg, int val)
+static int
+cue_csr_write_1(struct usbnet *un, int reg, int val)
 {
        usb_device_request_t    req;
        usbd_status             err;
 
-       if (sc->cue_dying)
+       if (usbnet_isdying(un))
                return 0;
 
        DPRINTFN(10,("%s: cue_csr_write_1 reg=0x%x val=0x%x\n",
-           device_xname(sc->cue_dev), reg, val));
+           device_xname(un->un_dev), reg, val));
 
        req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
        req.bRequest = CUE_CMD_WRITEREG;
@@ -232,34 +235,34 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, 0);
 
-       err = usbd_do_request(sc->cue_udev, &req, NULL);
+       err = usbd_do_request(un->un_udev, &req, NULL);
 
        if (err) {



Home | Main Index | Thread Index | Old Index