Source-Changes-HG archive

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

[src/trunk]: src/sys/sys update usbnet some:



details:   https://anonhg.NetBSD.org/src/rev/be812a655169
branches:  trunk
changeset: 964607:be812a655169
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Aug 09 01:17:33 2019 +0000

description:
update usbnet some:
- move rx/tx xfer flags into usbnet_cdata
- move the callbacks into usbnet_ops structure
- move rx/tx xfer flags arguments from usbnet_init_rx_tx()
  and move them all into usbnet_attach() arguments
- s/miibus/mii/ in some places for consistency

other clean up:
- create wrapper functions for callbacks, move knowledge about
  special handling (OK to be missing, error eating) there.
- use cdata pointer if already available
- provide some more macros (will be real functions later) for
  accessing usbnet members, use existing ones more

bump kernel version.

diffstat:

 sys/dev/usb/if_axe.c  |   54 +++++++------
 sys/dev/usb/if_axen.c |   81 +++++++++++----------
 sys/dev/usb/if_cdce.c |   33 ++++----
 sys/dev/usb/if_smsc.c |   59 ++++++++-------
 sys/dev/usb/if_udav.c |   59 ++++++++-------
 sys/dev/usb/if_ure.c  |   68 ++++++++++-------
 sys/dev/usb/usbnet.c  |  183 +++++++++++++++++++++++++++++++++++--------------
 sys/dev/usb/usbnet.h  |   51 +++++++------
 sys/sys/param.h       |    4 +-
 9 files changed, 351 insertions(+), 241 deletions(-)

diffs (truncated from 1538 to 300 lines):

diff -r c0e7aa8d741a -r be812a655169 sys/dev/usb/if_axe.c
--- a/sys/dev/usb/if_axe.c      Thu Aug 08 21:29:15 2019 +0000
+++ b/sys/dev/usb/if_axe.c      Fri Aug 09 01:17:33 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axe.c,v 1.106 2019/08/06 01:42:22 mrg Exp $ */
+/*     $NetBSD: if_axe.c,v 1.107 2019/08/09 01:17:33 mrg Exp $ */
 /*     $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.106 2019/08/06 01:42:22 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.107 2019/08/09 01:17:33 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -261,19 +261,33 @@
 CFATTACH_DECL_NEW(axe, sizeof(struct axe_softc),
        axe_match, axe_attach, usbnet_detach, usbnet_activate);
 
+static void    axe_stop_cb(struct ifnet *, int);
+static int     axe_ioctl_cb(struct ifnet *, u_long, void *);
+static int     axe_init(struct ifnet *);
+static usbd_status axe_mii_read_reg(struct usbnet *, int, int, uint16_t *);
+static usbd_status axe_mii_write_reg(struct usbnet *, int, int, uint16_t);
+static void    axe_mii_statchg_cb(struct ifnet *);
 static void    axe_rx_loop_cb(struct usbnet *, struct usbd_xfer *,
                               struct usbnet_chain *, uint32_t);
 static unsigned axe_tx_prepare_cb(struct usbnet *, struct mbuf *,
                                  struct usbnet_chain *);
-static int     axe_init(struct ifnet *);
-static void    axe_stop_cb(struct ifnet *, int);
-static int     axe_ioctl_cb(struct ifnet *, u_long, void *);
 
 static void    axe_ax88178_init(struct axe_softc *);
 static void    axe_ax88772_init(struct axe_softc *);
 static void    axe_ax88772a_init(struct axe_softc *);
 static void    axe_ax88772b_init(struct axe_softc *);
 
+static struct usbnet_ops axe_ops = {
+       .uno_stop = axe_stop_cb,
+       .uno_ioctl = axe_ioctl_cb,
+       .uno_read_reg = axe_mii_read_reg,
+       .uno_write_reg = axe_mii_write_reg,
+       .uno_statchg = axe_mii_statchg_cb,
+       .uno_tx_prepare = axe_tx_prepare_cb,
+       .uno_rx_loop = axe_rx_loop_cb,
+       .uno_init = axe_init,
+};
+
 static usbd_status
 axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
 {
@@ -284,7 +298,7 @@
 
        usbnet_isowned_mii(un);
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return -1;
 
        DPRINTFN(20, "cmd %#jx index %#jx val %#jx", cmd, index, val, 0);
@@ -364,10 +378,10 @@
 
        struct usbnet * const un = ifp->if_softc;
        struct axe_softc * const sc = usbnet_softc(un);
-       struct mii_data *mii = &un->un_mii;
+       struct mii_data *mii = usbnet_mii(un);
        int val, err;
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return;
 
        val = 0;
@@ -425,7 +439,7 @@
 
        usbnet_isowned_mii(un);
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return;
 
        if (axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, &rxmode)) {
@@ -516,7 +530,7 @@
 
        usbnet_isowned_mii(un);
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return;
 
        /*
@@ -871,16 +885,7 @@
        un->un_dev = self;
        un->un_udev = dev;
        un->un_sc = sc;
-       un->un_stop_cb = axe_stop_cb;
-       un->un_ioctl_cb = axe_ioctl_cb;
-       un->un_read_reg_cb = axe_mii_read_reg;
-       un->un_write_reg_cb = axe_mii_write_reg;
-       un->un_statchg_cb = axe_mii_statchg_cb;
-       un->un_tx_prepare_cb = axe_tx_prepare_cb;
-       un->un_rx_loop_cb = axe_rx_loop_cb;
-       un->un_init_cb = axe_init;
-       un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
-       un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       un->un_ops = &axe_ops;
 
        err = usbd_set_config_no(dev, AXE_CONFIG_NO, 1);
        if (err) {
@@ -905,8 +910,6 @@
                    AXE_178_MAX_BUFSZ : AXE_178_MIN_BUFSZ;
        else
                bufsz = AXE_172_BUFSZ;
-       un->un_cdata.uncd_rx_bufsz = bufsz;
-       un->un_cdata.uncd_tx_bufsz = bufsz;
 
        un->un_ed[USBNET_ENDPT_RX] = 0;
        un->un_ed[USBNET_ENDPT_TX] = 0;
@@ -934,7 +937,8 @@
        }
 
        /* Set these up now for axe_cmd().  */
-       usbnet_attach(un, "axedet", AXE_RX_LIST_CNT, AXE_TX_LIST_CNT);
+       usbnet_attach(un, "axedet", AXE_RX_LIST_CNT, AXE_TX_LIST_CNT,
+                     USBD_SHORT_XFER_OK, USBD_FORCE_SHORT_XFER, bufsz, bufsz);
 
        /* We need the PHYID for init dance in some cases */
        usbnet_lock_mii(un);
@@ -1245,7 +1249,7 @@
 
        usbnet_isowned(un);
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return EIO;
 
        /* Cancel pending I/O */
@@ -1342,7 +1346,7 @@
 
        usbnet_unlock_mii_un_locked(un);
 
-       return usbnet_init_rx_tx(un, 0, USBD_FORCE_SHORT_XFER);
+       return usbnet_init_rx_tx(un);
 }
 
 static int
diff -r c0e7aa8d741a -r be812a655169 sys/dev/usb/if_axen.c
--- a/sys/dev/usb/if_axen.c     Thu Aug 08 21:29:15 2019 +0000
+++ b/sys/dev/usb/if_axen.c     Fri Aug 09 01:17:33 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axen.c,v 1.56 2019/08/06 01:42:22 mrg Exp $ */
+/*     $NetBSD: if_axen.c,v 1.57 2019/08/09 01:17:33 mrg Exp $ */
 /*     $OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $ */
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.56 2019/08/06 01:42:22 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.57 2019/08/09 01:17:33 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -79,19 +79,32 @@
 CFATTACH_DECL_NEW(axen, sizeof(struct axen_softc),
        axen_match, axen_attach, usbnet_detach, usbnet_activate);
 
-static unsigned        axen_tx_prepare(struct usbnet *, struct mbuf *,
-                               struct usbnet_chain *);
-static int     axen_init(struct ifnet *);
 static int     axen_cmd(struct axen_softc *, int, int, int, void *);
 static void    axen_reset(struct axen_softc *);
 static int     axen_get_eaddr(struct axen_softc *, void *);
-static void    axen_stop_cb(struct ifnet *, int);
 static void    axen_ax88179_init(struct axen_softc *);
 
+static void    axen_stop_cb(struct ifnet *, int);
+static int     axen_ioctl_cb(struct ifnet *, u_long, void *);
 static usbd_status axen_mii_read_reg(struct usbnet *, int, int, uint16_t *);
 static usbd_status axen_mii_write_reg(struct usbnet *, int, int, uint16_t);
+static void    axen_mii_statchg(struct ifnet *);
 static void    axen_rxeof_loop(struct usbnet *, struct usbd_xfer *,
                    struct usbnet_chain *, uint32_t);
+static unsigned        axen_tx_prepare(struct usbnet *, struct mbuf *,
+                               struct usbnet_chain *);
+static int     axen_init(struct ifnet *);
+
+static struct usbnet_ops axen_ops = {
+       .uno_stop = axen_stop_cb,
+       .uno_ioctl = axen_ioctl_cb,
+       .uno_read_reg = axen_mii_read_reg,
+       .uno_write_reg = axen_mii_write_reg,
+       .uno_statchg = axen_mii_statchg,
+       .uno_tx_prepare = axen_tx_prepare,
+       .uno_rx_loop = axen_rxeof_loop,
+       .uno_init = axen_init,
+};
 
 static int
 axen_cmd(struct axen_softc *sc, int cmd, int index, int val, void *buf)
@@ -102,7 +115,7 @@
 
        usbnet_isowned_mii(un);
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return 0;
 
        if (AXEN_CMD_DIR(cmd))
@@ -162,7 +175,7 @@
        uint16_t val;
        uint16_t wval;
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return;
 
        un->un_link = false;
@@ -225,7 +238,7 @@
        uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
        uint16_t wval;
 
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return;
 
        usbnet_isowned_mii(un);
@@ -295,7 +308,7 @@
        struct usbnet * const un = &sc->axen_un;
 
        usbnet_isowned(un);
-       if (un->un_dying)
+       if (usbnet_isdying(un))
                return;
        /* XXX What to reset? */
 
@@ -501,18 +514,18 @@
 #define GMII_PHY_PAGE_SEL      0x1e
 #define GMII_PHY_PAGE_SEL      0x1f
 #define GMII_PAGE_EXT          0x0007
-       usbnet_miibus_writereg(un->un_dev, un->un_phyno, GMII_PHY_PAGE_SEL,
+       usbnet_mii_writereg(un->un_dev, un->un_phyno, GMII_PHY_PAGE_SEL,
            GMII_PAGE_EXT);
-       usbnet_miibus_writereg(un->un_dev, un->un_phyno, GMII_PHY_PAGE,
+       usbnet_mii_writereg(un->un_dev, un->un_phyno, GMII_PHY_PAGE,
            0x002c);
 #endif
 
 #if 1 /* XXX: phy hack ? */
-       usbnet_miibus_writereg(un->un_dev, un->un_phyno, 0x1F, 0x0005);
-       usbnet_miibus_writereg(un->un_dev, un->un_phyno, 0x0C, 0x0000);
-       usbnet_miibus_readreg(un->un_dev, un->un_phyno, 0x0001, &wval);
-       usbnet_miibus_writereg(un->un_dev, un->un_phyno, 0x01, wval | 0x0080);
-       usbnet_miibus_writereg(un->un_dev, un->un_phyno, 0x1F, 0x0000);
+       usbnet_mii_writereg(un->un_dev, un->un_phyno, 0x1F, 0x0005);
+       usbnet_mii_writereg(un->un_dev, un->un_phyno, 0x0C, 0x0000);
+       usbnet_mii_readreg(un->un_dev, un->un_phyno, 0x0001, &wval);
+       usbnet_mii_writereg(un->un_dev, un->un_phyno, 0x01, wval | 0x0080);
+       usbnet_mii_writereg(un->un_dev, un->un_phyno, 0x1F, 0x0000);
 #endif
 }
 
@@ -604,6 +617,7 @@
        usb_interface_descriptor_t *id;
        usb_endpoint_descriptor_t *ed;
        char *devinfop;
+       unsigned rx_bufsz, tx_bufsz;
        uint16_t axen_flags;
        int i;
 
@@ -619,16 +633,7 @@
        un->un_dev = self;
        un->un_udev = dev;
        un->un_sc = sc;
-       un->un_stop_cb = axen_stop_cb;
-       un->un_ioctl_cb = axen_ioctl_cb;
-       un->un_read_reg_cb = axen_mii_read_reg;
-       un->un_write_reg_cb = axen_mii_write_reg;
-       un->un_statchg_cb = axen_mii_statchg;
-       un->un_tx_prepare_cb = axen_tx_prepare;
-       un->un_rx_loop_cb = axen_rxeof_loop;
-       un->un_init_cb = axen_init;
-       un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
-       un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       un->un_ops = &axen_ops;
 
        err = usbd_set_config_no(dev, AXEN_CONFIG_NO, 1);
        if (err) {
@@ -648,19 +653,17 @@
        /* decide on what our bufsize will be */
        switch (dev->ud_speed) {
        case USB_SPEED_SUPER:
-               un->un_cdata.uncd_rx_bufsz = AXEN_BUFSZ_SS * 1024;
+               rx_bufsz = AXEN_BUFSZ_SS * 1024;
                break;



Home | Main Index | Thread Index | Old Index