mirror of
https://github.com/opnsense/src.git
synced 2026-02-19 02:30:08 -05:00
e6000sw: Fix locking in miibus_{read,write}reg implementations
Commit4692906480made e6000sw's implementation of miibus_(read|write)reg assume that the softc lock is held. I presume that is to avoid lock recursion in e6000sw_attach() -> e6000sw_attach_miibus() -> mii_attach() -> MIIBUS_READREG(). However, the lock assertion in e6000sw_readphy_locked() can fail if a different driver uses the interface to probe registers. Work around the problem by providing implementations which lock the softc if it is not already locked. PR: 274795 Fixes:4692906480("e6000sw: add readphy and writephy wrappers") Reviewed by: kp, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42466 (cherry picked from commit 725962a9f4c050b21488edd58d317e87c76d6f66)
This commit is contained in:
parent
95ddbac6d3
commit
766cceba19
1 changed files with 19 additions and 12 deletions
|
|
@ -66,6 +66,7 @@ MALLOC_DEFINE(M_E6000SW, "e6000sw", "e6000sw switch");
|
|||
#define E6000SW_UNLOCK(_sc) sx_unlock(&(_sc)->sx)
|
||||
#define E6000SW_LOCK_ASSERT(_sc, _what) sx_assert(&(_sc)->sx, (_what))
|
||||
#define E6000SW_TRYLOCK(_sc) sx_tryxlock(&(_sc)->sx)
|
||||
#define E6000SW_LOCKED(_sc) sx_xlocked(&(_sc)->sx)
|
||||
#define E6000SW_WAITREADY(_sc, _reg, _bit) \
|
||||
e6000sw_waitready((_sc), REG_GLOBAL, (_reg), (_bit))
|
||||
#define E6000SW_WAITREADY2(_sc, _reg, _bit) \
|
||||
|
|
@ -169,8 +170,8 @@ static device_method_t e6000sw_methods[] = {
|
|||
DEVMETHOD(bus_add_child, device_add_child_ordered),
|
||||
|
||||
/* mii interface */
|
||||
DEVMETHOD(miibus_readreg, e6000sw_readphy_locked),
|
||||
DEVMETHOD(miibus_writereg, e6000sw_writephy_locked),
|
||||
DEVMETHOD(miibus_readreg, e6000sw_readphy),
|
||||
DEVMETHOD(miibus_writereg, e6000sw_writephy),
|
||||
|
||||
/* etherswitch interface */
|
||||
DEVMETHOD(etherswitch_getinfo, e6000sw_getinfo),
|
||||
|
|
@ -744,17 +745,20 @@ e6000sw_write_xmdio(device_t dev, int phy, int devaddr, int devreg, int val)
|
|||
return (0);
|
||||
}
|
||||
|
||||
static int e6000sw_readphy(device_t dev, int phy, int reg)
|
||||
static int
|
||||
e6000sw_readphy(device_t dev, int phy, int reg)
|
||||
{
|
||||
e6000sw_softc_t *sc;
|
||||
int ret;
|
||||
int locked, ret;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
|
||||
|
||||
E6000SW_LOCK(sc);
|
||||
locked = E6000SW_LOCKED(sc);
|
||||
if (!locked)
|
||||
E6000SW_LOCK(sc);
|
||||
ret = e6000sw_readphy_locked(dev, phy, reg);
|
||||
E6000SW_UNLOCK(sc);
|
||||
if (!locked)
|
||||
E6000SW_UNLOCK(sc);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -795,17 +799,20 @@ e6000sw_readphy_locked(device_t dev, int phy, int reg)
|
|||
return (val & PHY_DATA_MASK);
|
||||
}
|
||||
|
||||
static int e6000sw_writephy(device_t dev, int phy, int reg, int data)
|
||||
static int
|
||||
e6000sw_writephy(device_t dev, int phy, int reg, int data)
|
||||
{
|
||||
e6000sw_softc_t *sc;
|
||||
int ret;
|
||||
int locked, ret;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED);
|
||||
|
||||
E6000SW_LOCK(sc);
|
||||
locked = E6000SW_LOCKED(sc);
|
||||
if (!locked)
|
||||
E6000SW_LOCK(sc);
|
||||
ret = e6000sw_writephy_locked(dev, phy, reg, data);
|
||||
E6000SW_UNLOCK(sc);
|
||||
if (!locked)
|
||||
E6000SW_UNLOCK(sc);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue