Source-Changes-HG archive

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

[src/trunk]: src/sys/net80211 Define and implement a locking protocol for the...



details:   https://anonhg.NetBSD.org/src/rev/a9cee29f7116
branches:  trunk
changeset: 970206:a9cee29f7116
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Mar 15 23:04:50 2020 +0000

description:
Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
  access to media-related structures / hardware regsiters.  Converted
  drivers use the new ifmedia_init_with_lock() function for this.  The
  new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
  a compatibility lock to be used instead.  Several media-related entry
  points must be aware of this compatibility lock, and are able to acquire
  it recursively a limited number of times, if needed.  This is a SPIN
  mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
  MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex.  The mcx driver still needs to be fully converted to
NET_MPSAFE.

diffstat:

 sys/arch/arm/amlogic/gxlphy.c   |   12 +-
 sys/arch/x86/pci/if_vmx.c       |   14 +-
 sys/dev/mii/acphy.c             |   16 +-
 sys/dev/mii/amhphy.c            |   12 +-
 sys/dev/mii/atphy.c             |   16 +-
 sys/dev/mii/bmtphy.c            |   14 +-
 sys/dev/mii/brgphy.c            |   36 ++++-
 sys/dev/mii/ciphy.c             |   14 +-
 sys/dev/mii/dmphy.c             |   12 +-
 sys/dev/mii/etphy.c             |   14 +-
 sys/dev/mii/exphy.c             |   12 +-
 sys/dev/mii/gentbi.c            |   22 ++-
 sys/dev/mii/glxtphy.c           |   12 +-
 sys/dev/mii/gphyter.c           |   16 +-
 sys/dev/mii/icsphy.c            |   14 +-
 sys/dev/mii/igphy.c             |   14 +-
 sys/dev/mii/ihphy.c             |   16 +-
 sys/dev/mii/ikphy.c             |   14 +-
 sys/dev/mii/inphy.c             |   12 +-
 sys/dev/mii/iophy.c             |   12 +-
 sys/dev/mii/ipgphy.c            |   16 +-
 sys/dev/mii/jmphy.c             |   14 +-
 sys/dev/mii/lxtphy.c            |   16 +-
 sys/dev/mii/makphy.c            |   13 +-
 sys/dev/mii/micphy.c            |   17 ++-
 sys/dev/mii/mii.c               |  131 ++++++++++++++++-
 sys/dev/mii/mii_ethersubr.c     |   10 +-
 sys/dev/mii/mii_physubr.c       |   88 +++++++++--
 sys/dev/mii/miivar.h            |   93 ++++++++----
 sys/dev/mii/mvphy.c             |   14 +-
 sys/dev/mii/nsphy.c             |   14 +-
 sys/dev/mii/nsphyter.c          |   14 +-
 sys/dev/mii/pnaphy.c            |   12 +-
 sys/dev/mii/qsphy.c             |   14 +-
 sys/dev/mii/rdcphy.c            |   12 +-
 sys/dev/mii/rgephy.c            |   35 +++-
 sys/dev/mii/rlphy.c             |   14 +-
 sys/dev/mii/smscphy.c           |    8 +
 sys/dev/mii/sqphy.c             |   14 +-
 sys/dev/mii/tlphy.c             |   13 +-
 sys/dev/mii/tqphy.c             |   12 +-
 sys/dev/mii/ukphy.c             |   10 +-
 sys/dev/mii/ukphy_subr.c        |    6 +-
 sys/dev/pci/if_mcx.c            |   20 +-
 sys/dev/pci/if_wm.c             |   82 ++++++----
 sys/dev/pci/ixgbe/ixgbe.c       |   14 +-
 sys/dev/pci/ixgbe/ixv.c         |   10 +-
 sys/dev/usb/if_atu.c            |    9 +-
 sys/dev/usb/if_atureg.h         |    4 +-
 sys/dev/usb/if_aue.c            |  116 ++++++---------
 sys/dev/usb/if_axe.c            |  115 +++++++--------
 sys/dev/usb/if_axen.c           |  130 ++++++++----------
 sys/dev/usb/if_cdce.c           |   31 ++--
 sys/dev/usb/if_cue.c            |   64 +++++---
 sys/dev/usb/if_kue.c            |   50 +++---
 sys/dev/usb/if_mos.c            |   87 +++++------
 sys/dev/usb/if_mue.c            |   98 ++++++------
 sys/dev/usb/if_otus.c           |   10 +-
 sys/dev/usb/if_otusvar.h        |    3 +-
 sys/dev/usb/if_rum.c            |   10 +-
 sys/dev/usb/if_rumvar.h         |    4 +-
 sys/dev/usb/if_run.c            |   10 +-
 sys/dev/usb/if_runvar.h         |    4 +-
 sys/dev/usb/if_smsc.c           |  125 +++++++----------
 sys/dev/usb/if_udav.c           |  119 +++++++--------
 sys/dev/usb/if_upgt.c           |   10 +-
 sys/dev/usb/if_upgtvar.h        |    4 +-
 sys/dev/usb/if_upl.c            |   37 ++--
 sys/dev/usb/if_ural.c           |   10 +-
 sys/dev/usb/if_uralvar.h        |    4 +-
 sys/dev/usb/if_ure.c            |   94 ++++++------
 sys/dev/usb/if_url.c            |  109 ++++++--------
 sys/dev/usb/if_urndis.c         |   48 +++---
 sys/dev/usb/if_urtw.c           |   10 +-
 sys/dev/usb/if_urtwn.c          |   10 +-
 sys/dev/usb/if_urtwnvar.h       |    3 +-
 sys/dev/usb/if_urtwreg.h        |    2 +
 sys/dev/usb/if_zyd.c            |   10 +-
 sys/dev/usb/if_zydreg.h         |    4 +-
 sys/dev/usb/usbnet.c            |  210 +++++++++++++---------------
 sys/dev/usb/usbnet.h            |   71 +++++----
 sys/net/if_media.c              |  288 +++++++++++++++++++++++++++++++--------
 sys/net/if_media.h              |   87 ++++++++++--
 sys/net80211/ieee80211.c        |   20 ++-
 sys/net80211/ieee80211_netbsd.h |    7 +-
 sys/net80211/ieee80211_var.h    |    4 +-
 86 files changed, 1914 insertions(+), 1137 deletions(-)

diffs (truncated from 8717 to 300 lines):

diff -r 6324ca0edaea -r a9cee29f7116 sys/arch/arm/amlogic/gxlphy.c
--- a/sys/arch/arm/amlogic/gxlphy.c     Sun Mar 15 22:44:32 2020 +0000
+++ b/sys/arch/arm/amlogic/gxlphy.c     Sun Mar 15 23:04:50 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gxlphy.c,v 1.2 2019/11/27 10:19:21 msaitoh Exp $ */
+/* $NetBSD: gxlphy.c,v 1.3 2020/03/15 23:04:50 thorpej Exp $ */
 
 /*
  * Copyright (c) 2019 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gxlphy.c,v 1.2 2019/11/27 10:19:21 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gxlphy.c,v 1.3 2020/03/15 23:04:50 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -169,6 +169,8 @@
        sc->mii_pdata = mii;
        sc->mii_flags = ma->mii_flags;
 
+       mii_lock(mii);
+
        PHY_RESET(sc);
 
        gxl_writereg(sc, BANK_BIST, BIST_PLL_CTRL, 0x5);
@@ -180,6 +182,8 @@
        if (sc->mii_capabilities & BMSR_EXTSTAT)
                PHY_READ(sc, MII_EXTSR, &sc->mii_extcapabilities);
 
+       mii_unlock(mii);
+
        mii_phy_add_media(sc);
 }
 
@@ -189,6 +193,8 @@
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
        uint16_t reg;
 
+       KASSERT(mii_locked(mii));
+
        switch (cmd) {
        case MII_POLLSTAT:
                /* If we're not polling our PHY instance, just return. */
@@ -241,6 +247,8 @@
 {
        uint16_t bmcr, bmsr, wol, lpa, aner;
 
+       KASSERT(mii_locked(sc->mii_pdata));
+
        PHY_READ(sc, MII_BMCR, &bmcr);
        if ((bmcr & BMCR_AUTOEN) == 0)
                goto done;
diff -r 6324ca0edaea -r a9cee29f7116 sys/arch/x86/pci/if_vmx.c
--- a/sys/arch/x86/pci/if_vmx.c Sun Mar 15 22:44:32 2020 +0000
+++ b/sys/arch/x86/pci/if_vmx.c Sun Mar 15 23:04:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vmx.c,v 1.57 2020/02/02 05:27:21 thorpej Exp $      */
+/*     $NetBSD: if_vmx.c,v 1.58 2020/03/15 23:04:50 thorpej Exp $      */
 /*     $OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $        */
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.57 2020/02/02 05:27:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.58 2020/03/15 23:04:50 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -1857,8 +1857,8 @@
 
        /* Initialize ifmedia structures. */
        sc->vmx_ethercom.ec_ifmedia = &sc->vmx_media;
-       ifmedia_init(&sc->vmx_media, IFM_IMASK, vmxnet3_media_change,
-           vmxnet3_media_status);
+       ifmedia_init_with_lock(&sc->vmx_media, IFM_IMASK, vmxnet3_media_change,
+           vmxnet3_media_status, sc->vmx_mtx);
        ifmedia_add(&sc->vmx_media, IFM_ETHER | IFM_AUTO, 0, NULL);
        ifmedia_add(&sc->vmx_media, IFM_ETHER | IFM_10G_T | IFM_FDX, 0, NULL);
        ifmedia_add(&sc->vmx_media, IFM_ETHER | IFM_10G_T, 0, NULL);
@@ -3511,17 +3511,13 @@
        ifmr->ifm_status = IFM_AVALID;
        ifmr->ifm_active = IFM_ETHER;
 
-       VMXNET3_CORE_LOCK(sc);
-       if (ifp->if_link_state != LINK_STATE_UP) {
-               VMXNET3_CORE_UNLOCK(sc);
+       if (ifp->if_link_state != LINK_STATE_UP)
                return;
-       }
 
        ifmr->ifm_status |= IFM_ACTIVE;
 
        if (ifp->if_baudrate >= IF_Gbps(10ULL))
                ifmr->ifm_active |= IFM_10G_T;
-       VMXNET3_CORE_UNLOCK(sc);
 }
 
 static int
diff -r 6324ca0edaea -r a9cee29f7116 sys/dev/mii/acphy.c
--- a/sys/dev/mii/acphy.c       Sun Mar 15 22:44:32 2020 +0000
+++ b/sys/dev/mii/acphy.c       Sun Mar 15 23:04:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acphy.c,v 1.29 2019/11/27 10:19:20 msaitoh Exp $       */
+/*     $NetBSD: acphy.c,v 1.30 2020/03/15 23:04:50 thorpej Exp $       */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acphy.c,v 1.29 2019/11/27 10:19:20 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acphy.c,v 1.30 2020/03/15 23:04:50 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -111,17 +111,23 @@
        sc->mii_pdata = mii;
        sc->mii_flags = ma->mii_flags;
 
+       mii_lock(mii);
+
        PHY_RESET(sc);
 
        /* XXX Check MCR_FX_SEL to set MIIF_HAVE_FIBER? */
 
        PHY_READ(sc, MII_BMSR, &sc->mii_capabilities);
        sc->mii_capabilities &= ma->mii_capmask;
-       aprint_normal_dev(sc->mii_dev, "");
+
+       mii_unlock(mii);
 
 #define        ADD(m, c)       ifmedia_add(&mii->mii_media, (m), (c), NULL)
        if (sc->mii_flags & MIIF_HAVEFIBER) {
+               aprint_normal_dev(sc->mii_dev, "");
+               mii_lock(mii);
                sc->mii_anegticks = MII_ANEGTICKS;
+               mii_unlock(mii);
                ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst),
                    MII_MEDIA_100_TX);
                aprint_normal("100baseFX, ");
@@ -140,6 +146,8 @@
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
        uint16_t reg;
 
+       KASSERT(mii_locked(mii));
+
        switch (cmd) {
        case MII_POLLSTAT:
                /* If we're not polling our PHY instance, just return. */
@@ -194,6 +202,8 @@
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
        uint16_t bmsr, bmcr, dr;
 
+       KASSERT(mii_locked(mii));
+
        mii->mii_media_status = IFM_AVALID;
        mii->mii_media_active = IFM_ETHER;
 
diff -r 6324ca0edaea -r a9cee29f7116 sys/dev/mii/amhphy.c
--- a/sys/dev/mii/amhphy.c      Sun Mar 15 22:44:32 2020 +0000
+++ b/sys/dev/mii/amhphy.c      Sun Mar 15 23:04:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amhphy.c,v 1.25 2019/11/27 10:19:20 msaitoh Exp $      */
+/*     $NetBSD: amhphy.c,v 1.26 2020/03/15 23:04:50 thorpej Exp $      */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amhphy.c,v 1.25 2019/11/27 10:19:20 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amhphy.c,v 1.26 2020/03/15 23:04:50 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -106,11 +106,15 @@
        sc->mii_pdata = mii;
        sc->mii_flags = ma->mii_flags;
 
+       mii_lock(mii);
+
        PHY_RESET(sc);
 
        PHY_READ(sc, MII_BMSR, &sc->mii_capabilities);
        sc->mii_capabilities &= ma->mii_capmask;
 
+       mii_unlock(mii);
+
        mii_phy_add_media(sc);
 }
 
@@ -120,6 +124,8 @@
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
        uint16_t reg;
 
+       KASSERT(mii_locked(mii));
+
        switch (cmd) {
        case MII_POLLSTAT:
                /* If we're not polling our PHY instance, just return. */
@@ -174,6 +180,8 @@
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
        uint16_t bmsr, bmcr, ssr;
 
+       KASSERT(mii_locked(mii));
+
        mii->mii_media_status = IFM_AVALID;
        mii->mii_media_active = IFM_ETHER;
 
diff -r 6324ca0edaea -r a9cee29f7116 sys/dev/mii/atphy.c
--- a/sys/dev/mii/atphy.c       Sun Mar 15 22:44:32 2020 +0000
+++ b/sys/dev/mii/atphy.c       Sun Mar 15 23:04:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atphy.c,v 1.29 2020/03/13 18:57:49 msaitoh Exp $ */
+/*     $NetBSD: atphy.c,v 1.30 2020/03/15 23:04:50 thorpej Exp $ */
 /*     $OpenBSD: atphy.c,v 1.1 2008/09/25 20:47:16 brad Exp $  */
 
 /*-
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atphy.c,v 1.29 2020/03/13 18:57:49 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atphy.c,v 1.30 2020/03/15 23:04:50 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -200,6 +200,8 @@
        if (asc->mii_clk_25m != 0)
                atphy_clk_25m(asc);
 
+       mii_lock(mii);
+
        PHY_RESET(sc);
 
        PHY_READ(sc, MII_BMSR, &bmsr);
@@ -208,6 +210,8 @@
        if (atphy_is_gige(mpd) && (sc->mii_capabilities & BMSR_EXTSTAT))
                PHY_READ(sc, MII_EXTSR, &sc->mii_extcapabilities);
 
+       mii_unlock(mii);
+
        mii_phy_add_media(sc);
 }
 
@@ -217,6 +221,8 @@
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
        uint16_t anar, bmcr, bmsr;
 
+       KASSERT(mii_locked(mii));
+
        switch (cmd) {
        case MII_POLLSTAT:
                /* If we're not polling our PHY instance, just return. */
@@ -338,6 +344,8 @@
        struct mii_data *mii = sc->mii_pdata;
        uint16_t bmsr, bmcr, gsr, ssr;
 
+       KASSERT(mii_locked(mii));
+
        mii->mii_media_status = IFM_AVALID;
        mii->mii_media_active = IFM_ETHER;
 
@@ -404,6 +412,8 @@
        uint16_t reg;
        int i;
 
+       KASSERT(mii_locked(sc->mii_pdata));
+
        /*
         * Take PHY out of power down mode.
         *
@@ -468,6 +478,8 @@
 {
        uint16_t anar;
 
+       KASSERT(mii_locked(sc->mii_pdata));
+
        sc->mii_ticks = 0;
        anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
        if (sc->mii_flags & MIIF_DOPAUSE)
diff -r 6324ca0edaea -r a9cee29f7116 sys/dev/mii/bmtphy.c
--- a/sys/dev/mii/bmtphy.c      Sun Mar 15 22:44:32 2020 +0000
+++ b/sys/dev/mii/bmtphy.c      Sun Mar 15 23:04:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bmtphy.c,v 1.36 2019/11/27 10:19:20 msaitoh Exp $      */
+/*     $NetBSD: bmtphy.c,v 1.37 2020/03/15 23:04:50 thorpej Exp $      */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index