net: lan966x: Add spinlock for frame transmission from CPU.
authorHoratiu Vultur <horatiu.vultur@microchip.com>
Tue, 8 Mar 2022 10:29:04 +0000 (11:29 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 9 Mar 2022 14:59:14 +0000 (14:59 +0000)
The registers used to inject a frame to one of the ports is shared
between all the net devices. Therefore, there can be race conditions for
accessing the registers when two processes send frames at the same time
on different ports.

To fix this, add a spinlock around the function
'lan966x_port_ifh_xmit()'.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/microchip/lan966x/lan966x_main.c
drivers/net/ethernet/microchip/lan966x/lan966x_main.h

index 750f2cc2f69563a25a084fc641bba6b05d3a7322..81c01665d01e36daaef6b28ee47cbba909002e7a 100644 (file)
@@ -318,6 +318,7 @@ static void lan966x_ifh_set_timestamp(void *ifh, u64 timestamp)
 static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct lan966x_port *port = netdev_priv(dev);
+       struct lan966x *lan966x = port->lan966x;
        __be32 ifh[IFH_LEN];
        int err;
 
@@ -338,7 +339,11 @@ static int lan966x_port_xmit(struct sk_buff *skb, struct net_device *dev)
                lan966x_ifh_set_timestamp(ifh, LAN966X_SKB_CB(skb)->ts_id);
        }
 
-       return lan966x_port_ifh_xmit(skb, ifh, dev);
+       spin_lock(&lan966x->tx_lock);
+       err = lan966x_port_ifh_xmit(skb, ifh, dev);
+       spin_unlock(&lan966x->tx_lock);
+
+       return err;
 }
 
 static int lan966x_port_change_mtu(struct net_device *dev, int new_mtu)
@@ -885,6 +890,8 @@ static void lan966x_init(struct lan966x *lan966x)
        lan_rmw(ANA_ANAINTR_INTR_ENA_SET(1),
                ANA_ANAINTR_INTR_ENA,
                lan966x, ANA_ANAINTR);
+
+       spin_lock_init(&lan966x->tx_lock);
 }
 
 static int lan966x_ram_init(struct lan966x *lan966x)
index 058e435318183d1eca619b3ca7003fa10d4f9721..ae282da1da748fc41e9d70106baef27cfa871d29 100644 (file)
@@ -108,6 +108,8 @@ struct lan966x {
 
        u8 base_mac[ETH_ALEN];
 
+       spinlock_t tx_lock; /* lock for frame transmition */
+
        struct net_device *bridge;
        u16 bridge_mask;
        u16 bridge_fwd_mask;