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
This commit is contained in:
parent
d75a788085
commit
6d011946c5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=312224
@ -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 *sc, int phy, int led, int style)
|
||||
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
|
||||
|
@ -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_softc *sc)
|
||||
arswitch_modifyreg(sc->sc_dev, AR8X16_REG_SERVICE_TAG,
|
||||
AR8X16_SERVICE_TAG_MASK, 0);
|
||||
|
||||
ARSWITCH_UNLOCK(sc);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -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_softc *sc)
|
||||
arswitch_modifyreg(sc->sc_dev, AR8X16_REG_SERVICE_TAG,
|
||||
AR8X16_SERVICE_TAG_MASK, 0);
|
||||
|
||||
ARSWITCH_UNLOCK(sc);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -708,6 +708,8 @@ ar8327_hw_global_setup(struct arswitch_softc *sc)
|
||||
{
|
||||
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_softc *sc)
|
||||
/* GMAC0 (CPU), GMAC1..5 (PHYs), GMAC6 (CPU) */
|
||||
sc->info.es_nports = 7;
|
||||
|
||||
ARSWITCH_UNLOCK(sc);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -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_softc *sc)
|
||||
} 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_softc *sc)
|
||||
/* Settle time */
|
||||
DELAY(1000);
|
||||
|
||||
ARSWITCH_UNLOCK(sc);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user