Source-Changes-HG archive

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

[src/trunk]: src/sys/sys reduce the scope of struct usbnet:



details:   https://anonhg.NetBSD.org/src/rev/01fe189ff443
branches:  trunk
changeset: 964631:01fe189ff443
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Aug 10 02:17:36 2019 +0000

description:
reduce the scope of struct usbnet:
- move a large number of members internal to usbnet.c's new
  "struct usbnet_private".
- provide accessors for a few of these
- move struct usbnet_cdata into usbnet.c as well, but move
  bufsz, list count, and xfer flags back out into struct usbnet,
  and have them set as part of the setup efore usbnet_attach()
- split the intr pipe parts into their own structure
- move all the main usbnet*lock* code into usbnet.c too

usbnet_attach() goes down to 2 args, and the inputs needed are
now the full contents of 'struct usbnet' besides the driver
owned 'un_flags' and usbnet owned 'un_pri'.

welcome netbsd 9.99.6.

diffstat:

 sys/dev/usb/if_axe.c    |   20 +-
 sys/dev/usb/if_axen.c   |   33 +-
 sys/dev/usb/if_cdce.c   |   17 +-
 sys/dev/usb/if_smsc.c   |   19 +-
 sys/dev/usb/if_udav.c   |   20 +-
 sys/dev/usb/if_ure.c    |   20 +-
 sys/dev/usb/if_urndis.c |   23 +-
 sys/dev/usb/usbnet.c    |  631 +++++++++++++++++++++++++++++++----------------
 sys/dev/usb/usbnet.h    |  234 +++++++----------
 sys/sys/param.h         |    4 +-
 10 files changed, 600 insertions(+), 421 deletions(-)

diffs (truncated from 2057 to 300 lines):

diff -r 360665362ded -r 01fe189ff443 sys/dev/usb/if_axe.c
--- a/sys/dev/usb/if_axe.c      Sat Aug 10 01:24:17 2019 +0000
+++ b/sys/dev/usb/if_axe.c      Sat Aug 10 02:17:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axe.c,v 1.108 2019/08/09 02:52:59 mrg Exp $ */
+/*     $NetBSD: if_axe.c,v 1.109 2019/08/10 02:17:36 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.108 2019/08/09 02:52:59 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.109 2019/08/10 02:17:36 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -385,7 +385,7 @@
                return;
 
        val = 0;
-       un->un_link = false;
+       usbnet_set_link(un, false);
        if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
                val |= AXE_MEDIA_FULL_DUPLEX;
                if (AXE_IS_178_FAMILY(un)) {
@@ -404,14 +404,14 @@
                switch (IFM_SUBTYPE(mii->mii_media_active)) {
                case IFM_1000_T:
                        val |= AXE_178_MEDIA_GMII | AXE_178_MEDIA_ENCK;
-                       un->un_link = true;
+                       usbnet_set_link(un, true);
                        break;
                case IFM_100_TX:
                        val |= AXE_178_MEDIA_100TX;
-                       un->un_link = true;
+                       usbnet_set_link(un, true);
                        break;
                case IFM_10_T:
-                       un->un_link = true;
+                       usbnet_set_link(un, true);
                        break;
                }
        }
@@ -886,6 +886,10 @@
        un->un_udev = dev;
        un->un_sc = sc;
        un->un_ops = &axe_ops;
+       un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
+       un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       un->un_rx_list_cnt = AXE_RX_LIST_CNT;
+       un->un_tx_list_cnt = AXE_TX_LIST_CNT;
 
        err = usbd_set_config_no(dev, AXE_CONFIG_NO, 1);
        if (err) {
@@ -910,6 +914,7 @@
                    AXE_178_MAX_BUFSZ : AXE_178_MIN_BUFSZ;
        else
                bufsz = AXE_172_BUFSZ;
+       un->un_rx_bufsz = un->un_tx_bufsz = bufsz;
 
        un->un_ed[USBNET_ENDPT_RX] = 0;
        un->un_ed[USBNET_ENDPT_TX] = 0;
@@ -937,8 +942,7 @@
        }
 
        /* Set these up now for axe_cmd().  */
-       usbnet_attach(un, "axedet", AXE_RX_LIST_CNT, AXE_TX_LIST_CNT,
-                     USBD_SHORT_XFER_OK, USBD_FORCE_SHORT_XFER, bufsz, bufsz);
+       usbnet_attach(un, "axedet");
 
        /* We need the PHYID for init dance in some cases */
        usbnet_lock_mii(un);
diff -r 360665362ded -r 01fe189ff443 sys/dev/usb/if_axen.c
--- a/sys/dev/usb/if_axen.c     Sat Aug 10 01:24:17 2019 +0000
+++ b/sys/dev/usb/if_axen.c     Sat Aug 10 02:17:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axen.c,v 1.58 2019/08/09 02:52:59 mrg Exp $ */
+/*     $NetBSD: if_axen.c,v 1.59 2019/08/10 02:17:36 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.58 2019/08/09 02:52:59 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.59 2019/08/10 02:17:36 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -169,16 +169,16 @@
        if (usbnet_isdying(un))
                return;
 
-       un->un_link = false;
+       usbnet_set_link(un, false);
        if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
            (IFM_ACTIVE | IFM_AVALID)) {
                switch (IFM_SUBTYPE(mii->mii_media_active)) {
                case IFM_10_T:
                case IFM_100_TX:
-                       un->un_link = true;
+                       usbnet_set_link(un, true);
                        break;
                case IFM_1000_T:
-                       un->un_link = true;
+                       usbnet_set_link(un, true);
                        break;
                default:
                        break;
@@ -186,7 +186,7 @@
        }
 
        /* Lost link, do nothing. */
-       if (!un->un_link)
+       if (!usbnet_havelink(un))
                return;
 
        val = 0;
@@ -599,7 +599,6 @@
        usb_interface_descriptor_t *id;
        usb_endpoint_descriptor_t *ed;
        char *devinfop;
-       unsigned rx_bufsz, tx_bufsz;
        uint16_t axen_flags;
        int i;
 
@@ -613,6 +612,10 @@
        un->un_udev = dev;
        un->un_sc = un;
        un->un_ops = &axen_ops;
+       un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
+       un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       un->un_rx_list_cnt = AXEN_RX_LIST_CNT;
+       un->un_tx_list_cnt = AXEN_TX_LIST_CNT;
 
        err = usbd_set_config_no(dev, AXEN_CONFIG_NO, 1);
        if (err) {
@@ -632,17 +635,17 @@
        /* decide on what our bufsize will be */
        switch (dev->ud_speed) {
        case USB_SPEED_SUPER:
-               rx_bufsz = AXEN_BUFSZ_SS * 1024;
+               un->un_rx_bufsz = AXEN_BUFSZ_SS * 1024;
                break;
        case USB_SPEED_HIGH:
-               rx_bufsz = AXEN_BUFSZ_HS * 1024;
+               un->un_rx_bufsz = AXEN_BUFSZ_HS * 1024;
                break;
        default:
-               rx_bufsz = AXEN_BUFSZ_LS * 1024;
+               un->un_rx_bufsz = AXEN_BUFSZ_LS * 1024;
                break;
        }
-       tx_bufsz = IP_MAXPACKET + ETHER_HDR_LEN + ETHER_CRC_LEN +
-                  ETHER_VLAN_ENCAP_LEN + sizeof(struct axen_sframe_hdr);
+       un->un_tx_bufsz = IP_MAXPACKET + ETHER_HDR_LEN + ETHER_CRC_LEN +
+           ETHER_VLAN_ENCAP_LEN + sizeof(struct axen_sframe_hdr);
 
        /* Find endpoints. */
        id = usbd_get_interface_descriptor(un->un_iface);
@@ -667,9 +670,7 @@
        }
 
        /* Set these up now for axen_cmd().  */
-       usbnet_attach(un, "axendet", AXEN_RX_LIST_CNT, AXEN_TX_LIST_CNT,
-                     USBD_SHORT_XFER_OK, USBD_FORCE_SHORT_XFER,
-                     rx_bufsz, tx_bufsz);
+       usbnet_attach(un, "axendet");
 
        un->un_phyno = AXEN_PHY_ID;
        DPRINTF(("%s: phyno %d\n", device_xname(self), un->un_phyno));
@@ -876,7 +877,7 @@
        }
 
        length = m->m_pkthdr.len + sizeof(hdr);
-       KASSERT(length <= un->un_cdata.uncd_tx_bufsz);
+       KASSERT(length <= un->un_tx_bufsz);
 
        hdr.plen = htole32(m->m_pkthdr.len);
 
diff -r 360665362ded -r 01fe189ff443 sys/dev/usb/if_cdce.c
--- a/sys/dev/usb/if_cdce.c     Sat Aug 10 01:24:17 2019 +0000
+++ b/sys/dev/usb/if_cdce.c     Sat Aug 10 02:17:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cdce.c,v 1.60 2019/08/09 02:52:59 mrg Exp $ */
+/*     $NetBSD: if_cdce.c,v 1.61 2019/08/10 02:17:36 mrg Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul%windriver.com@localhost>
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.60 2019/08/09 02:52:59 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.61 2019/08/10 02:17:36 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -133,6 +133,12 @@
        un->un_udev = dev;
        un->un_sc = un;
        un->un_ops = &cdce_ops;
+       un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
+       un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       un->un_rx_list_cnt = CDCE_RX_LIST_CNT;
+       un->un_tx_list_cnt = CDCE_TX_LIST_CNT;
+       un->un_rx_bufsz = CDCE_BUFSZ;
+       un->un_tx_bufsz = CDCE_BUFSZ;
 
        t = cdce_lookup(uiaa->uiaa_vendor, uiaa->uiaa_product);
        if (t)
@@ -242,9 +248,7 @@
                un->un_eaddr[5] = (uint8_t)(device_unit(un->un_dev));
        }
 
-       usbnet_attach(un, "cdcedet", CDCE_RX_LIST_CNT, CDCE_TX_LIST_CNT,
-                     USBD_SHORT_XFER_OK, USBD_FORCE_SHORT_XFER,
-                     CDCE_BUFSZ, CDCE_BUFSZ);
+       usbnet_attach(un, "cdcedet");
        usbnet_attach_ifp(un, false, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
             0, 0);
 }
@@ -261,8 +265,7 @@
        else {
                usbnet_stop(un, ifp, 1);
                rv = usbnet_init_rx_tx(un);
-               if (rv == 0)
-                       un->un_link = true;
+               usbnet_set_link(un, rv == 0);
        }
        usbnet_unlock(un);
 
diff -r 360665362ded -r 01fe189ff443 sys/dev/usb/if_smsc.c
--- a/sys/dev/usb/if_smsc.c     Sat Aug 10 01:24:17 2019 +0000
+++ b/sys/dev/usb/if_smsc.c     Sat Aug 10 02:17:36 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_smsc.c,v 1.50 2019/08/09 07:54:05 skrll Exp $       */
+/*     $NetBSD: if_smsc.c,v 1.51 2019/08/10 02:17:36 mrg Exp $ */
 
 /*     $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */
 /*     $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.50 2019/08/09 07:54:05 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.51 2019/08/10 02:17:36 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -319,13 +319,13 @@
        uint32_t flow;
        uint32_t afc_cfg;
 
-       un->un_link = false;
+       usbnet_set_link(un, false);
        if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
            (IFM_ACTIVE | IFM_AVALID)) {
                switch (IFM_SUBTYPE(mii->mii_media_active)) {
                        case IFM_10_T:
                        case IFM_100_TX:
-                               un->un_link = true;
+                               usbnet_set_link(un, true);
                                break;
                        case IFM_1000_T:
                                /* Gigabit ethernet not supported by chipset */
@@ -336,7 +336,7 @@
        }
 
        /* Lost link, do nothing. */
-       if (!un->un_link)
+       if (!usbnet_havelink(un))
                return;
 
        usbnet_lock_mii(un);
@@ -801,6 +801,10 @@
        un->un_udev = dev;
        un->un_sc = sc;
        un->un_ops = &smsc_ops;
+       un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
+       un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
+       un->un_rx_list_cnt = SMSC_RX_LIST_CNT;
+       un->un_tx_list_cnt = SMSC_TX_LIST_CNT;
 
        devinfop = usbd_devinfo_alloc(un->un_udev, 0);
        aprint_normal_dev(self, "%s\n", devinfop);
@@ -827,6 +831,8 @@
        } else {
                bufsz = SMSC_MIN_BUFSZ;
        }
+       un->un_rx_bufsz = bufsz;
+       un->un_tx_bufsz = bufsz;
 
        /* Find endpoints. */
        for (i = 0; i < id->bNumEndpoints; i++) {
@@ -849,8 +855,7 @@
                }



Home | Main Index | Thread Index | Old Index