Commit 44343418 authored by Marek Vasut's avatar Marek Vasut Committed by David S. Miller

net: ks8851-ml: Fix IRQ handling and locking

The KS8851 requires that packet RX and TX are mutually exclusive.
Currently, the driver hopes to achieve this by disabling interrupt
from the card by writing the card registers and by disabling the
interrupt on the interrupt controller. This however is racy on SMP.

Replace this approach by expanding the spinlock used around the
ks_start_xmit() TX path to ks_irq() RX path to assure true mutual
exclusion and remove the interrupt enabling/disabling, which is
now not needed anymore. Furthermore, disable interrupts also in
ks_net_stop(), which was missing before.

Note that a massive improvement here would be to re-use the KS8851
driver approach, which is to move the TX path into a worker thread,
interrupt handling to threaded interrupt, and synchronize everything
with mutexes, but that would be a much bigger rework, for a separate
patch.
Signed-off-by: default avatarMarek Vasut <marex@denx.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Lukas Wunner <lukas@wunner.de>
Cc: Petr Stetiar <ynezz@true.cz>
Cc: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52df1e56
...@@ -513,14 +513,17 @@ static irqreturn_t ks_irq(int irq, void *pw) ...@@ -513,14 +513,17 @@ static irqreturn_t ks_irq(int irq, void *pw)
{ {
struct net_device *netdev = pw; struct net_device *netdev = pw;
struct ks_net *ks = netdev_priv(netdev); struct ks_net *ks = netdev_priv(netdev);
unsigned long flags;
u16 status; u16 status;
spin_lock_irqsave(&ks->statelock, flags);
/*this should be the first in IRQ handler */ /*this should be the first in IRQ handler */
ks_save_cmd_reg(ks); ks_save_cmd_reg(ks);
status = ks_rdreg16(ks, KS_ISR); status = ks_rdreg16(ks, KS_ISR);
if (unlikely(!status)) { if (unlikely(!status)) {
ks_restore_cmd_reg(ks); ks_restore_cmd_reg(ks);
spin_unlock_irqrestore(&ks->statelock, flags);
return IRQ_NONE; return IRQ_NONE;
} }
...@@ -546,6 +549,7 @@ static irqreturn_t ks_irq(int irq, void *pw) ...@@ -546,6 +549,7 @@ static irqreturn_t ks_irq(int irq, void *pw)
ks->netdev->stats.rx_over_errors++; ks->netdev->stats.rx_over_errors++;
/* this should be the last in IRQ handler*/ /* this should be the last in IRQ handler*/
ks_restore_cmd_reg(ks); ks_restore_cmd_reg(ks);
spin_unlock_irqrestore(&ks->statelock, flags);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -615,6 +619,7 @@ static int ks_net_stop(struct net_device *netdev) ...@@ -615,6 +619,7 @@ static int ks_net_stop(struct net_device *netdev)
/* shutdown RX/TX QMU */ /* shutdown RX/TX QMU */
ks_disable_qmu(ks); ks_disable_qmu(ks);
ks_disable_int(ks);
/* set powermode to soft power down to save power */ /* set powermode to soft power down to save power */
ks_set_powermode(ks, PMECR_PM_SOFTDOWN); ks_set_powermode(ks, PMECR_PM_SOFTDOWN);
...@@ -671,10 +676,9 @@ static netdev_tx_t ks_start_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -671,10 +676,9 @@ static netdev_tx_t ks_start_xmit(struct sk_buff *skb, struct net_device *netdev)
{ {
netdev_tx_t retv = NETDEV_TX_OK; netdev_tx_t retv = NETDEV_TX_OK;
struct ks_net *ks = netdev_priv(netdev); struct ks_net *ks = netdev_priv(netdev);
unsigned long flags;
disable_irq(netdev->irq); spin_lock_irqsave(&ks->statelock, flags);
ks_disable_int(ks);
spin_lock(&ks->statelock);
/* Extra space are required: /* Extra space are required:
* 4 byte for alignment, 4 for status/length, 4 for CRC * 4 byte for alignment, 4 for status/length, 4 for CRC
...@@ -688,9 +692,7 @@ static netdev_tx_t ks_start_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -688,9 +692,7 @@ static netdev_tx_t ks_start_xmit(struct sk_buff *skb, struct net_device *netdev)
dev_kfree_skb(skb); dev_kfree_skb(skb);
} else } else
retv = NETDEV_TX_BUSY; retv = NETDEV_TX_BUSY;
spin_unlock(&ks->statelock); spin_unlock_irqrestore(&ks->statelock, flags);
ks_enable_int(ks);
enable_irq(netdev->irq);
return retv; return retv;
} }
......
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