svn commit: r312224 - head/sys/dev/etherswitch/arswitch
Kristof Provost
kp at FreeBSD.org
Sun Jan 15 10:21:26 UTC 2017
Author: kp
Date: Sun Jan 15 10:21:25 2017
New Revision: 312224
URL: https://svnweb.freebsd.org/changeset/base/312224
Log:
arswitch: Ensure the lock is always held when calling arswitch_modifyreg()
arswitch_setled() and a number of _global_setup functions did not acquire the
lock before calling arswitch_modifyreg(). With WITNESS enabled this would
instantly panic.
Discovered on a TPLink-3600:
("panic: mutex arswitch not owned at sys/dev/etherswitch/arswitch/arswitch_reg.c:236")
Reviewed by: adrian, kan
Differential Revision: https://reviews.freebsd.org/D9187
Modified:
head/sys/dev/etherswitch/arswitch/arswitch.c
head/sys/dev/etherswitch/arswitch/arswitch_7240.c
head/sys/dev/etherswitch/arswitch/arswitch_8316.c
head/sys/dev/etherswitch/arswitch/arswitch_8327.c
head/sys/dev/etherswitch/arswitch/arswitch_9340.c
Modified: head/sys/dev/etherswitch/arswitch/arswitch.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch.c Sun Jan 15 10:17:15 2017 (r312223)
+++ head/sys/dev/etherswitch/arswitch/arswitch.c Sun Jan 15 10:21:25 2017 (r312224)
@@ -845,6 +845,7 @@ static int
arswitch_setled(struct arswitch_softc *sc, int phy, int led, int style)
{
int shift;
+ int err;
if (phy < 0 || phy > sc->numphys)
return EINVAL;
@@ -852,10 +853,15 @@ arswitch_setled(struct arswitch_softc *s
if (style < 0 || style > ETHERSWITCH_PORT_LED_MAX)
return (EINVAL);
+ ARSWITCH_LOCK(sc);
+
shift = ar8327_led_mapping[phy][led].shift;
- return (arswitch_modifyreg(sc->sc_dev,
+ err = (arswitch_modifyreg(sc->sc_dev,
ar8327_led_mapping[phy][led].reg,
0x03 << shift, led_pattern_table[style] << shift));
+ ARSWITCH_UNLOCK(sc);
+
+ return (err);
}
static void
Modified: head/sys/dev/etherswitch/arswitch/arswitch_7240.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch_7240.c Sun Jan 15 10:17:15 2017 (r312223)
+++ head/sys/dev/etherswitch/arswitch/arswitch_7240.c Sun Jan 15 10:21:25 2017 (r312224)
@@ -81,6 +81,8 @@ static int
ar7240_hw_global_setup(struct arswitch_softc *sc)
{
+ ARSWITCH_LOCK(sc);
+
/* Enable CPU port; disable mirror port */
arswitch_writereg(sc->sc_dev, AR8X16_REG_CPU_PORT,
AR8X16_CPU_PORT_EN | AR8X16_CPU_MIRROR_DIS);
@@ -103,6 +105,8 @@ ar7240_hw_global_setup(struct arswitch_s
arswitch_modifyreg(sc->sc_dev, AR8X16_REG_SERVICE_TAG,
AR8X16_SERVICE_TAG_MASK, 0);
+ ARSWITCH_UNLOCK(sc);
+
return (0);
}
Modified: head/sys/dev/etherswitch/arswitch/arswitch_8316.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch_8316.c Sun Jan 15 10:17:15 2017 (r312223)
+++ head/sys/dev/etherswitch/arswitch/arswitch_8316.c Sun Jan 15 10:21:25 2017 (r312224)
@@ -127,6 +127,8 @@ static int
ar8316_hw_global_setup(struct arswitch_softc *sc)
{
+ ARSWITCH_LOCK(sc);
+
arswitch_writereg(sc->sc_dev, 0x38, AR8X16_MAGIC);
/* Enable CPU port and disable mirror port. */
@@ -156,6 +158,7 @@ ar8316_hw_global_setup(struct arswitch_s
arswitch_modifyreg(sc->sc_dev, AR8X16_REG_SERVICE_TAG,
AR8X16_SERVICE_TAG_MASK, 0);
+ ARSWITCH_UNLOCK(sc);
return (0);
}
Modified: head/sys/dev/etherswitch/arswitch/arswitch_8327.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch_8327.c Sun Jan 15 10:17:15 2017 (r312223)
+++ head/sys/dev/etherswitch/arswitch/arswitch_8327.c Sun Jan 15 10:21:25 2017 (r312224)
@@ -708,6 +708,8 @@ ar8327_hw_global_setup(struct arswitch_s
{
uint32_t t;
+ ARSWITCH_LOCK(sc);
+
/* enable CPU port and disable mirror port */
t = AR8327_FWD_CTRL0_CPU_PORT_EN |
AR8327_FWD_CTRL0_MIRROR_PORT;
@@ -741,6 +743,7 @@ ar8327_hw_global_setup(struct arswitch_s
/* GMAC0 (CPU), GMAC1..5 (PHYs), GMAC6 (CPU) */
sc->info.es_nports = 7;
+ ARSWITCH_UNLOCK(sc);
return (0);
}
Modified: head/sys/dev/etherswitch/arswitch/arswitch_9340.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch_9340.c Sun Jan 15 10:17:15 2017 (r312223)
+++ head/sys/dev/etherswitch/arswitch/arswitch_9340.c Sun Jan 15 10:21:25 2017 (r312224)
@@ -81,6 +81,8 @@ static int
ar9340_hw_global_setup(struct arswitch_softc *sc)
{
+ ARSWITCH_LOCK(sc);
+
/* Enable CPU port; disable mirror port */
arswitch_writereg(sc->sc_dev, AR8X16_REG_CPU_PORT,
AR8X16_CPU_PORT_EN | AR8X16_CPU_MIRROR_DIS);
@@ -142,6 +144,7 @@ ar9340_hw_global_setup(struct arswitch_s
} else {
device_printf(sc->sc_dev, "%s: need is_gmii or is_mii set\n",
__func__);
+ ARSWITCH_UNLOCK(sc);
return (ENXIO);
}
@@ -163,6 +166,7 @@ ar9340_hw_global_setup(struct arswitch_s
/* Settle time */
DELAY(1000);
+ ARSWITCH_UNLOCK(sc);
return (0);
}
More information about the svn-src-head
mailing list