Skip to content

Commit c4f922e

Browse files
shimodayPaolo Abeni
authored andcommitted
net: renesas: rswitch: Add spin lock protection for irq {un}mask
Add spin lock protection for irq {un}mask registers' control. After napi_complete_done() and this protection were applied, a lot of redundant interrupts no longer occur. For example: when "iperf3 -c <ipaddr> -R" on R-Car S4-8 Spider Before the patches are applied: about 800,000 times happened After the patches were applied: about 100,000 times happened Fixes: 3590918 ("net: ethernet: renesas: Add support for "Ethernet Switch"") Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent e7b1ef2 commit c4f922e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

drivers/net/ethernet/renesas/rswitch.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ static int rswitch_poll(struct napi_struct *napi, int budget)
799799
struct net_device *ndev = napi->dev;
800800
struct rswitch_private *priv;
801801
struct rswitch_device *rdev;
802+
unsigned long flags;
802803
int quota = budget;
803804

804805
rdev = netdev_priv(ndev);
@@ -817,8 +818,10 @@ static int rswitch_poll(struct napi_struct *napi, int budget)
817818
netif_wake_subqueue(ndev, 0);
818819

819820
if (napi_complete_done(napi, budget - quota)) {
821+
spin_lock_irqsave(&priv->lock, flags);
820822
rswitch_enadis_data_irq(priv, rdev->tx_queue->index, true);
821823
rswitch_enadis_data_irq(priv, rdev->rx_queue->index, true);
824+
spin_unlock_irqrestore(&priv->lock, flags);
822825
}
823826

824827
out:
@@ -835,8 +838,10 @@ static void rswitch_queue_interrupt(struct net_device *ndev)
835838
struct rswitch_device *rdev = netdev_priv(ndev);
836839

837840
if (napi_schedule_prep(&rdev->napi)) {
841+
spin_lock(&rdev->priv->lock);
838842
rswitch_enadis_data_irq(rdev->priv, rdev->tx_queue->index, false);
839843
rswitch_enadis_data_irq(rdev->priv, rdev->rx_queue->index, false);
844+
spin_unlock(&rdev->priv->lock);
840845
__napi_schedule(&rdev->napi);
841846
}
842847
}
@@ -1440,14 +1445,17 @@ static void rswitch_ether_port_deinit_all(struct rswitch_private *priv)
14401445
static int rswitch_open(struct net_device *ndev)
14411446
{
14421447
struct rswitch_device *rdev = netdev_priv(ndev);
1448+
unsigned long flags;
14431449

14441450
phy_start(ndev->phydev);
14451451

14461452
napi_enable(&rdev->napi);
14471453
netif_start_queue(ndev);
14481454

1455+
spin_lock_irqsave(&rdev->priv->lock, flags);
14491456
rswitch_enadis_data_irq(rdev->priv, rdev->tx_queue->index, true);
14501457
rswitch_enadis_data_irq(rdev->priv, rdev->rx_queue->index, true);
1458+
spin_unlock_irqrestore(&rdev->priv->lock, flags);
14511459

14521460
if (bitmap_empty(rdev->priv->opened_ports, RSWITCH_NUM_PORTS))
14531461
iowrite32(GWCA_TS_IRQ_BIT, rdev->priv->addr + GWTSDIE);
@@ -1461,6 +1469,7 @@ static int rswitch_stop(struct net_device *ndev)
14611469
{
14621470
struct rswitch_device *rdev = netdev_priv(ndev);
14631471
struct rswitch_gwca_ts_info *ts_info, *ts_info2;
1472+
unsigned long flags;
14641473

14651474
netif_tx_stop_all_queues(ndev);
14661475
bitmap_clear(rdev->priv->opened_ports, rdev->port, 1);
@@ -1476,8 +1485,10 @@ static int rswitch_stop(struct net_device *ndev)
14761485
kfree(ts_info);
14771486
}
14781487

1488+
spin_lock_irqsave(&rdev->priv->lock, flags);
14791489
rswitch_enadis_data_irq(rdev->priv, rdev->tx_queue->index, false);
14801490
rswitch_enadis_data_irq(rdev->priv, rdev->rx_queue->index, false);
1491+
spin_unlock_irqrestore(&rdev->priv->lock, flags);
14811492

14821493
phy_stop(ndev->phydev);
14831494
napi_disable(&rdev->napi);
@@ -1887,6 +1898,7 @@ static int renesas_eth_sw_probe(struct platform_device *pdev)
18871898
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
18881899
if (!priv)
18891900
return -ENOMEM;
1901+
spin_lock_init(&priv->lock);
18901902

18911903
attr = soc_device_match(rswitch_soc_no_speed_change);
18921904
if (attr)

drivers/net/ethernet/renesas/rswitch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,8 @@ struct rswitch_private {
10111011
struct rswitch_etha etha[RSWITCH_NUM_PORTS];
10121012
struct rswitch_mfwd mfwd;
10131013

1014+
spinlock_t lock; /* lock interrupt registers' control */
1015+
10141016
bool etha_no_runtime_change;
10151017
bool gwca_halt;
10161018
};

0 commit comments

Comments
 (0)