Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb convert aue(4) to usbnet(9).



details:   https://anonhg.NetBSD.org/src/rev/01f1d3da33c8
branches:  trunk
changeset: 459074:01f1d3da33c8
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Aug 23 04:34:51 2019 +0000

description:
convert aue(4) to usbnet(9).

besides the not-enabled umb(4), this completes the conversion
of all the non-wifi usb network devices.

diffstat:

 sys/dev/usb/if_aue.c    |  1359 +++++++++-------------------------------------
 sys/dev/usb/if_auereg.h |     7 +-
 2 files changed, 270 insertions(+), 1096 deletions(-)

diffs (truncated from 1855 to 300 lines):

diff -r 527fbdb5404d -r 01f1d3da33c8 sys/dev/usb/if_aue.c
--- a/sys/dev/usb/if_aue.c      Fri Aug 23 04:34:01 2019 +0000
+++ b/sys/dev/usb/if_aue.c      Fri Aug 23 04:34:51 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_aue.c,v 1.160 2019/08/22 09:16:08 mrg Exp $ */
+/*     $NetBSD: if_aue.c,v 1.161 2019/08/23 04:34:51 mrg Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.160 2019/08/22 09:16:08 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.161 2019/08/23 04:34:51 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -84,49 +84,21 @@
 #endif
 
 #include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sockio.h>
-#include <sys/mutex.h>
-#include <sys/mbuf.h>
-#include <sys/kernel.h>
-#include <sys/socket.h>
-#include <sys/device.h>
-#include <sys/rndsource.h>
 
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
+#include <dev/usb/usbnet.h>
+#include <dev/usb/usbhist.h>
+#include <dev/usb/if_auereg.h>
 
-#include <net/bpf.h>
-
-#include <net/if_ether.h>
 #ifdef INET
 #include <netinet/in.h>
 #include <netinet/if_inarp.h>
 #endif
 
-
-
-#include <dev/mii/mii.h>
-#include <dev/mii/miivar.h>
-
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usbdevs.h>
-#include <dev/usb/usbhist.h>
-
-#include <sys/condvar.h>
-#include <sys/kthread.h>
-
-#include <dev/usb/if_auereg.h>
-
 #ifdef USB_DEBUG
 #ifndef AUE_DEBUG
 #define auedebug 0
 #else
-static int auedebug = 0;
+static int auedebug = 10;
 
 SYSCTL_SETUP(sysctl_hw_aue_setup, "sysctl hw.aue setup")
 {
@@ -170,62 +142,10 @@
 #define AUE_TX_LIST_CNT                1
 #define AUE_RX_LIST_CNT                1
 
-struct aue_softc;
-
-struct aue_chain {
-       struct aue_softc        *aue_sc;
-       struct usbd_xfer        *aue_xfer;
-       char                    *aue_buf;
-       struct mbuf             *aue_mbuf;
-};
-
-struct aue_cdata {
-       struct aue_chain        aue_tx_chain[AUE_TX_LIST_CNT];
-       struct aue_chain        aue_rx_chain[AUE_RX_LIST_CNT];
+struct aue_softc {
+       struct usbnet           aue_un;
+       struct usbnet_intr      aue_intr;
        struct aue_intrpkt      aue_ibuf;
-       int                     aue_tx_prod;
-       int                     aue_tx_cnt;
-};
-
-struct aue_softc {
-       device_t aue_dev;
-
-       struct ethercom         aue_ec;
-       struct mii_data         aue_mii;
-       krndsource_t    rnd_source;
-       struct lwp              *aue_thread;
-       int                     aue_closing;
-       kcondvar_t              aue_domc;
-       kcondvar_t              aue_closemc;
-       kmutex_t                aue_mcmtx;
-#define GET_IFP(sc) (&(sc)->aue_ec.ec_if)
-#define GET_MII(sc) (&(sc)->aue_mii)
-
-       struct callout aue_stat_ch;
-
-       struct usbd_device      *aue_udev;
-       struct usbd_interface   *aue_iface;
-       uint16_t                aue_vendor;
-       uint16_t                aue_product;
-       int                     aue_ed[AUE_ENDPT_MAX];
-       struct usbd_pipe        *aue_ep[AUE_ENDPT_MAX];
-       uint8_t                 aue_link;
-       int                     aue_if_flags;
-       struct aue_cdata        aue_cdata;
-
-       uint16_t                aue_flags;
-
-       int                     aue_refcnt;
-       char                    aue_dying;
-       char                    aue_attached;
-       u_int                   aue_rx_errs;
-       u_int                   aue_intr_errs;
-       struct timeval          aue_rx_notice;
-
-       struct usb_task         aue_tick_task;
-       struct usb_task         aue_stop_task;
-
-       kmutex_t                aue_mii_lock;
 };
 
 #define AUE_TIMEOUT            1000
@@ -313,42 +233,35 @@
 
 int aue_match(device_t, cfdata_t, void *);
 void aue_attach(device_t, device_t, void *);
-int aue_detach(device_t, int);
-int aue_activate(device_t, enum devact);
 
 CFATTACH_DECL_NEW(aue, sizeof(struct aue_softc), aue_match, aue_attach,
-    aue_detach, aue_activate);
-
-static void aue_multithread(void *);
+    usbnet_detach, usbnet_activate);
 
 static void aue_reset_pegasus_II(struct aue_softc *);
-static int aue_tx_list_init(struct aue_softc *);
-static int aue_rx_list_init(struct aue_softc *);
-static int aue_newbuf(struct aue_softc *, struct aue_chain *, struct mbuf *);
-static int aue_send(struct aue_softc *, struct mbuf *, int);
-static void aue_intr(struct usbd_xfer *, void *, usbd_status);
-static void aue_rxeof(struct usbd_xfer *, void *, usbd_status);
-static void aue_txeof(struct usbd_xfer *, void *, usbd_status);
-static void aue_tick(void *);
-static void aue_tick_task(void *);
-static void aue_start(struct ifnet *);
-static int aue_ioctl(struct ifnet *, u_long, void *);
-static void aue_init(void *);
-static void aue_stop(struct aue_softc *);
-static void aue_watchdog(struct ifnet *);
-static int aue_openpipes(struct aue_softc *);
-static int aue_ifmedia_upd(struct ifnet *);
+
+static void aue_stop_cb(struct ifnet *, int);
+static int aue_ioctl_cb(struct ifnet *, u_long, void *);
+static int aue_mii_read_reg(struct usbnet *, int, int, uint16_t *);
+static int aue_mii_write_reg(struct usbnet *, int, int, uint16_t);
+static void aue_mii_statchg(struct ifnet *);
+static unsigned aue_tx_prepare(struct usbnet *, struct mbuf *,
+                              struct usbnet_chain *);
+static void aue_rx_loop(struct usbnet *, struct usbnet_chain *, uint32_t);
+static int aue_init(struct ifnet *);
+static void aue_intr(struct usbnet *, usbd_status);
 
-static int aue_eeprom_getword(struct aue_softc *, int);
-static void aue_read_mac(struct aue_softc *, u_char *);
-static int aue_miibus_readreg(device_t, int, int, uint16_t *);
-static int aue_miibus_writereg(device_t, int, int, uint16_t);
-static void aue_miibus_statchg(struct ifnet *);
+static struct usbnet_ops aue_ops = {
+       .uno_stop = aue_stop_cb,
+       .uno_ioctl = aue_ioctl_cb,
+       .uno_read_reg = aue_mii_read_reg,
+       .uno_write_reg = aue_mii_write_reg,
+       .uno_statchg = aue_mii_statchg,
+       .uno_tx_prepare = aue_tx_prepare,
+       .uno_rx_loop = aue_rx_loop,
+       .uno_init = aue_init,
+       .uno_intr = aue_intr,
+};
 
-static void aue_lock_mii(struct aue_softc *);
-static void aue_unlock_mii(struct aue_softc *);
-
-static void aue_setmulti(struct aue_softc *);
 static uint32_t aue_crc(void *);
 static void aue_reset(struct aue_softc *);
 
@@ -366,11 +279,14 @@
 static int
 aue_csr_read_1(struct aue_softc *sc, int reg)
 {
+       struct usbnet * const   un = &sc->aue_un;
        usb_device_request_t    req;
        usbd_status             err;
        uByte                   val = 0;
 
-       if (sc->aue_dying)
+       usbnet_isowned_mii(un);
+
+       if (usbnet_isdying(un))
                return 0;
 
        req.bmRequestType = UT_READ_VENDOR_DEVICE;
@@ -379,12 +295,12 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, 1);
 
-       err = usbd_do_request(sc->aue_udev, &req, &val);
+       err = usbd_do_request(un->un_udev, &req, &val);
 
        if (err) {
                AUEHIST_FUNC();
                AUEHIST_CALLARGS("%d: aue_csr_read_1: reg=%#x err=%d",
-                   device_unit(sc->aue_dev), reg, err, 0);
+                   device_unit(un->un_dev), reg, err, 0);
                return 0;
        }
 
@@ -394,11 +310,14 @@
 static int
 aue_csr_read_2(struct aue_softc *sc, int reg)
 {
+       struct usbnet * const   un = &sc->aue_un;
        usb_device_request_t    req;
        usbd_status             err;
        uWord                   val;
 
-       if (sc->aue_dying)
+       usbnet_isowned_mii(un);
+
+       if (usbnet_isdying(un))
                return 0;
 
        req.bmRequestType = UT_READ_VENDOR_DEVICE;
@@ -407,12 +326,12 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, 2);
 
-       err = usbd_do_request(sc->aue_udev, &req, &val);
+       err = usbd_do_request(un->un_udev, &req, &val);
 
        if (err) {
                AUEHIST_FUNC();
                AUEHIST_CALLARGS("%d: aue_csr_read_2: reg=%#x err=%d",
-                   device_unit(sc->aue_dev), reg, err, 0);
+                   device_unit(un->un_dev), reg, err, 0);
                return 0;
        }
 
@@ -422,11 +341,14 @@
 static int
 aue_csr_write_1(struct aue_softc *sc, int reg, int aval)
 {
+       struct usbnet * const   un = &sc->aue_un;
        usb_device_request_t    req;
        usbd_status             err;
        uByte                   val;
 
-       if (sc->aue_dying)
+       usbnet_isowned_mii(un);
+
+       if (usbnet_isdying(un))
                return 0;
 
        val = aval;
@@ -436,12 +358,12 @@
        USETW(req.wIndex, reg);
        USETW(req.wLength, 1);
 
-       err = usbd_do_request(sc->aue_udev, &req, &val);
+       err = usbd_do_request(un->un_udev, &req, &val);
 
        if (err) {
                AUEHIST_FUNC();
                AUEHIST_CALLARGS("%d: aue_csr_write_1: reg=%#x err=%d",
-                   device_unit(sc->aue_dev), reg, err, 0);
+                   device_unit(un->un_dev), reg, err, 0);
                return -1;
        }
 
@@ -451,11 +373,14 @@
 static int
 aue_csr_write_2(struct aue_softc *sc, int reg, int aval)



Home | Main Index | Thread Index | Old Index