Skip to content

Commit 139ad11

Browse files
vladimirolteandavem330
authored andcommitted
phy: lynx-28g: serialize concurrent phy_set_mode_ext() calls to shared registers
The protocol converter configuration registers PCC8, PCCC, PCCD (implemented by the driver), as well as others, control protocol converters from multiple lanes (each represented as a different struct phy). So, if there are simultaneous calls to phy_set_mode_ext() to lanes sharing the same PCC register (either for the "old" or for the "new" protocol), corruption of the values programmed to hardware is possible, because lynx_28g_rmw() has no locking. Add a spinlock in the struct lynx_28g_priv shared by all lanes, and take the global spinlock from the phy_ops :: set_mode() implementation. There are no other callers which modify PCC registers. Fixes: 8f73b37 ("phy: add support for the Layerscape SerDes 28G") Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0ac87fe commit 139ad11

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/phy/freescale/phy-fsl-lynx-28g.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ struct lynx_28g_lane {
127127
struct lynx_28g_priv {
128128
void __iomem *base;
129129
struct device *dev;
130+
/* Serialize concurrent access to registers shared between lanes,
131+
* like PCCn
132+
*/
133+
spinlock_t pcc_lock;
130134
struct lynx_28g_pll pll[LYNX_28G_NUM_PLL];
131135
struct lynx_28g_lane lane[LYNX_28G_NUM_LANE];
132136

@@ -397,6 +401,8 @@ static int lynx_28g_set_mode(struct phy *phy, enum phy_mode mode, int submode)
397401
if (powered_up)
398402
lynx_28g_power_off(phy);
399403

404+
spin_lock(&priv->pcc_lock);
405+
400406
switch (submode) {
401407
case PHY_INTERFACE_MODE_SGMII:
402408
case PHY_INTERFACE_MODE_1000BASEX:
@@ -413,6 +419,8 @@ static int lynx_28g_set_mode(struct phy *phy, enum phy_mode mode, int submode)
413419
lane->interface = submode;
414420

415421
out:
422+
spin_unlock(&priv->pcc_lock);
423+
416424
/* Power up the lane if necessary */
417425
if (powered_up)
418426
lynx_28g_power_on(phy);
@@ -596,6 +604,7 @@ static int lynx_28g_probe(struct platform_device *pdev)
596604

597605
dev_set_drvdata(dev, priv);
598606

607+
spin_lock_init(&priv->pcc_lock);
599608
INIT_DELAYED_WORK(&priv->cdr_check, lynx_28g_cdr_lock_check);
600609

601610
queue_delayed_work(system_power_efficient_wq, &priv->cdr_check,

0 commit comments

Comments
 (0)