Commit bef1e4c8 authored by David S. Miller's avatar David S. Miller

Merge branch 'bcmgenet-protect-contended-accesses'

Doug Berger says:

====================
net: bcmgenet: protect contended accesses

Some registers may be modified by parallel execution contexts and
require protections to prevent corruption.

A review of the driver revealed the need for these additional
protections.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b2ff42c6 0d5e2a82
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
* Broadcom GENET (Gigabit Ethernet) controller driver * Broadcom GENET (Gigabit Ethernet) controller driver
* *
* Copyright (c) 2014-2020 Broadcom * Copyright (c) 2014-2024 Broadcom
*/ */
#define pr_fmt(fmt) "bcmgenet: " fmt #define pr_fmt(fmt) "bcmgenet: " fmt
...@@ -2467,14 +2467,18 @@ static void umac_enable_set(struct bcmgenet_priv *priv, u32 mask, bool enable) ...@@ -2467,14 +2467,18 @@ static void umac_enable_set(struct bcmgenet_priv *priv, u32 mask, bool enable)
{ {
u32 reg; u32 reg;
spin_lock_bh(&priv->reg_lock);
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
if (reg & CMD_SW_RESET) if (reg & CMD_SW_RESET) {
spin_unlock_bh(&priv->reg_lock);
return; return;
}
if (enable) if (enable)
reg |= mask; reg |= mask;
else else
reg &= ~mask; reg &= ~mask;
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
spin_unlock_bh(&priv->reg_lock);
/* UniMAC stops on a packet boundary, wait for a full-size packet /* UniMAC stops on a packet boundary, wait for a full-size packet
* to be processed * to be processed
...@@ -2490,8 +2494,10 @@ static void reset_umac(struct bcmgenet_priv *priv) ...@@ -2490,8 +2494,10 @@ static void reset_umac(struct bcmgenet_priv *priv)
udelay(10); udelay(10);
/* issue soft reset and disable MAC while updating its registers */ /* issue soft reset and disable MAC while updating its registers */
spin_lock_bh(&priv->reg_lock);
bcmgenet_umac_writel(priv, CMD_SW_RESET, UMAC_CMD); bcmgenet_umac_writel(priv, CMD_SW_RESET, UMAC_CMD);
udelay(2); udelay(2);
spin_unlock_bh(&priv->reg_lock);
} }
static void bcmgenet_intr_disable(struct bcmgenet_priv *priv) static void bcmgenet_intr_disable(struct bcmgenet_priv *priv)
...@@ -3334,7 +3340,9 @@ static void bcmgenet_netif_start(struct net_device *dev) ...@@ -3334,7 +3340,9 @@ static void bcmgenet_netif_start(struct net_device *dev)
struct bcmgenet_priv *priv = netdev_priv(dev); struct bcmgenet_priv *priv = netdev_priv(dev);
/* Start the network engine */ /* Start the network engine */
netif_addr_lock_bh(dev);
bcmgenet_set_rx_mode(dev); bcmgenet_set_rx_mode(dev);
netif_addr_unlock_bh(dev);
bcmgenet_enable_rx_napi(priv); bcmgenet_enable_rx_napi(priv);
umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, true); umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, true);
...@@ -3595,16 +3603,19 @@ static void bcmgenet_set_rx_mode(struct net_device *dev) ...@@ -3595,16 +3603,19 @@ static void bcmgenet_set_rx_mode(struct net_device *dev)
* 3. The number of filters needed exceeds the number filters * 3. The number of filters needed exceeds the number filters
* supported by the hardware. * supported by the hardware.
*/ */
spin_lock(&priv->reg_lock);
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) || if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) ||
(nfilter > MAX_MDF_FILTER)) { (nfilter > MAX_MDF_FILTER)) {
reg |= CMD_PROMISC; reg |= CMD_PROMISC;
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
spin_unlock(&priv->reg_lock);
bcmgenet_umac_writel(priv, 0, UMAC_MDF_CTRL); bcmgenet_umac_writel(priv, 0, UMAC_MDF_CTRL);
return; return;
} else { } else {
reg &= ~CMD_PROMISC; reg &= ~CMD_PROMISC;
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
spin_unlock(&priv->reg_lock);
} }
/* update MDF filter */ /* update MDF filter */
...@@ -4003,6 +4014,7 @@ static int bcmgenet_probe(struct platform_device *pdev) ...@@ -4003,6 +4014,7 @@ static int bcmgenet_probe(struct platform_device *pdev)
goto err; goto err;
} }
spin_lock_init(&priv->reg_lock);
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
/* Set default pause parameters */ /* Set default pause parameters */
......
/* SPDX-License-Identifier: GPL-2.0-only */ /* SPDX-License-Identifier: GPL-2.0-only */
/* /*
* Copyright (c) 2014-2020 Broadcom * Copyright (c) 2014-2024 Broadcom
*/ */
#ifndef __BCMGENET_H__ #ifndef __BCMGENET_H__
...@@ -573,6 +573,8 @@ struct bcmgenet_rxnfc_rule { ...@@ -573,6 +573,8 @@ struct bcmgenet_rxnfc_rule {
/* device context */ /* device context */
struct bcmgenet_priv { struct bcmgenet_priv {
void __iomem *base; void __iomem *base;
/* reg_lock: lock to serialize access to shared registers */
spinlock_t reg_lock;
enum bcmgenet_version version; enum bcmgenet_version version;
struct net_device *dev; struct net_device *dev;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
* Broadcom GENET (Gigabit Ethernet) Wake-on-LAN support * Broadcom GENET (Gigabit Ethernet) Wake-on-LAN support
* *
* Copyright (c) 2014-2020 Broadcom * Copyright (c) 2014-2024 Broadcom
*/ */
#define pr_fmt(fmt) "bcmgenet_wol: " fmt #define pr_fmt(fmt) "bcmgenet_wol: " fmt
...@@ -151,6 +151,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, ...@@ -151,6 +151,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
} }
/* Can't suspend with WoL if MAC is still in reset */ /* Can't suspend with WoL if MAC is still in reset */
spin_lock_bh(&priv->reg_lock);
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
if (reg & CMD_SW_RESET) if (reg & CMD_SW_RESET)
reg &= ~CMD_SW_RESET; reg &= ~CMD_SW_RESET;
...@@ -158,6 +159,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, ...@@ -158,6 +159,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
/* disable RX */ /* disable RX */
reg &= ~CMD_RX_EN; reg &= ~CMD_RX_EN;
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
spin_unlock_bh(&priv->reg_lock);
mdelay(10); mdelay(10);
if (priv->wolopts & (WAKE_MAGIC | WAKE_MAGICSECURE)) { if (priv->wolopts & (WAKE_MAGIC | WAKE_MAGICSECURE)) {
...@@ -203,6 +205,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, ...@@ -203,6 +205,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
} }
/* Enable CRC forward */ /* Enable CRC forward */
spin_lock_bh(&priv->reg_lock);
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
priv->crc_fwd_en = 1; priv->crc_fwd_en = 1;
reg |= CMD_CRC_FWD; reg |= CMD_CRC_FWD;
...@@ -210,6 +213,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, ...@@ -210,6 +213,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
/* Receiver must be enabled for WOL MP detection */ /* Receiver must be enabled for WOL MP detection */
reg |= CMD_RX_EN; reg |= CMD_RX_EN;
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
spin_unlock_bh(&priv->reg_lock);
reg = UMAC_IRQ_MPD_R; reg = UMAC_IRQ_MPD_R;
if (hfb_enable) if (hfb_enable)
...@@ -256,7 +260,9 @@ void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv, ...@@ -256,7 +260,9 @@ void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv,
} }
/* Disable CRC Forward */ /* Disable CRC Forward */
spin_lock_bh(&priv->reg_lock);
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
reg &= ~CMD_CRC_FWD; reg &= ~CMD_CRC_FWD;
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
spin_unlock_bh(&priv->reg_lock);
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
* Broadcom GENET MDIO routines * Broadcom GENET MDIO routines
* *
* Copyright (c) 2014-2017 Broadcom * Copyright (c) 2014-2024 Broadcom
*/ */
#include <linux/acpi.h> #include <linux/acpi.h>
...@@ -76,6 +76,7 @@ static void bcmgenet_mac_config(struct net_device *dev) ...@@ -76,6 +76,7 @@ static void bcmgenet_mac_config(struct net_device *dev)
reg |= RGMII_LINK; reg |= RGMII_LINK;
bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL); bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL);
spin_lock_bh(&priv->reg_lock);
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
reg &= ~((CMD_SPEED_MASK << CMD_SPEED_SHIFT) | reg &= ~((CMD_SPEED_MASK << CMD_SPEED_SHIFT) |
CMD_HD_EN | CMD_HD_EN |
...@@ -88,6 +89,7 @@ static void bcmgenet_mac_config(struct net_device *dev) ...@@ -88,6 +89,7 @@ static void bcmgenet_mac_config(struct net_device *dev)
reg |= CMD_TX_EN | CMD_RX_EN; reg |= CMD_TX_EN | CMD_RX_EN;
} }
bcmgenet_umac_writel(priv, reg, UMAC_CMD); bcmgenet_umac_writel(priv, reg, UMAC_CMD);
spin_unlock_bh(&priv->reg_lock);
active = phy_init_eee(phydev, 0) >= 0; active = phy_init_eee(phydev, 0) >= 0;
bcmgenet_eee_enable_set(dev, bcmgenet_eee_enable_set(dev,
...@@ -275,6 +277,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init) ...@@ -275,6 +277,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
* block for the interface to work, unconditionally clear the * block for the interface to work, unconditionally clear the
* Out-of-band disable since we do not need it. * Out-of-band disable since we do not need it.
*/ */
mutex_lock(&phydev->lock);
reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL); reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL);
reg &= ~OOB_DISABLE; reg &= ~OOB_DISABLE;
if (priv->ext_phy) { if (priv->ext_phy) {
...@@ -286,6 +289,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init) ...@@ -286,6 +289,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
reg |= RGMII_MODE_EN; reg |= RGMII_MODE_EN;
} }
bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL); bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL);
mutex_unlock(&phydev->lock);
if (init) if (init)
dev_info(kdev, "configuring instance for %s\n", phy_name); dev_info(kdev, "configuring instance for %s\n", phy_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment