]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
net: hns: add spin lock for tcam table operation
authorDaode Huang <huangdaode@hisilicon.com>
Tue, 21 Jun 2016 03:56:31 +0000 (11:56 +0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 21 Jun 2016 08:51:55 +0000 (04:51 -0400)
This patch adds spin lock for tcam table operation,
there maybe a race condition happens when more than
one thread try to change the tcam talbe entries.

Signed-off-by: Daode Huang <huangdaode@hisilicon.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h

index 0edea9c3b8daff736819d846f92c69a23fb747a8..0958ceb3df2c6f83bbab709b7f3cca981a78e357 100644 (file)
@@ -860,6 +860,8 @@ static void hns_dsaf_single_line_tbl_cfg(
        struct dsaf_device *dsaf_dev,
        u32 address, struct dsaf_tbl_line_cfg *ptbl_line)
 {
+       spin_lock_bh(&dsaf_dev->tcam_lock);
+
        /*Write Addr*/
        hns_dsaf_tbl_line_addr_cfg(dsaf_dev, address);
 
@@ -868,6 +870,8 @@ static void hns_dsaf_single_line_tbl_cfg(
 
        /*Write Plus*/
        hns_dsaf_tbl_line_pul(dsaf_dev);
+
+       spin_unlock_bh(&dsaf_dev->tcam_lock);
 }
 
 /**
@@ -881,6 +885,8 @@ static void hns_dsaf_tcam_uc_cfg(
        struct dsaf_tbl_tcam_data *ptbl_tcam_data,
        struct dsaf_tbl_tcam_ucast_cfg *ptbl_tcam_ucast)
 {
+       spin_lock_bh(&dsaf_dev->tcam_lock);
+
        /*Write Addr*/
        hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
        /*Write Tcam Data*/
@@ -889,6 +895,8 @@ static void hns_dsaf_tcam_uc_cfg(
        hns_dsaf_tbl_tcam_ucast_cfg(dsaf_dev, ptbl_tcam_ucast);
        /*Write Plus*/
        hns_dsaf_tbl_tcam_data_ucast_pul(dsaf_dev);
+
+       spin_unlock_bh(&dsaf_dev->tcam_lock);
 }
 
 /**
@@ -903,6 +911,8 @@ static void hns_dsaf_tcam_mc_cfg(
        struct dsaf_tbl_tcam_data *ptbl_tcam_data,
        struct dsaf_tbl_tcam_mcast_cfg *ptbl_tcam_mcast)
 {
+       spin_lock_bh(&dsaf_dev->tcam_lock);
+
        /*Write Addr*/
        hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
        /*Write Tcam Data*/
@@ -911,6 +921,8 @@ static void hns_dsaf_tcam_mc_cfg(
        hns_dsaf_tbl_tcam_mcast_cfg(dsaf_dev, ptbl_tcam_mcast);
        /*Write Plus*/
        hns_dsaf_tbl_tcam_data_mcast_pul(dsaf_dev);
+
+       spin_unlock_bh(&dsaf_dev->tcam_lock);
 }
 
 /**
@@ -920,6 +932,8 @@ static void hns_dsaf_tcam_mc_cfg(
  */
 static void hns_dsaf_tcam_mc_invld(struct dsaf_device *dsaf_dev, u32 address)
 {
+       spin_lock_bh(&dsaf_dev->tcam_lock);
+
        /*Write Addr*/
        hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
 
@@ -932,6 +946,8 @@ static void hns_dsaf_tcam_mc_invld(struct dsaf_device *dsaf_dev, u32 address)
 
        /*Write Plus*/
        hns_dsaf_tbl_tcam_mcast_pul(dsaf_dev);
+
+       spin_unlock_bh(&dsaf_dev->tcam_lock);
 }
 
 /**
@@ -949,6 +965,8 @@ static void hns_dsaf_tcam_uc_get(
        u32 tcam_read_data0;
        u32 tcam_read_data4;
 
+       spin_lock_bh(&dsaf_dev->tcam_lock);
+
        /*Write Addr*/
        hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
 
@@ -981,6 +999,8 @@ static void hns_dsaf_tcam_uc_get(
                                 DSAF_TBL_UCAST_CFG1_OUT_PORT_S);
        ptbl_tcam_ucast->tbl_ucast_dvc
                = dsaf_get_bit(tcam_read_data0, DSAF_TBL_UCAST_CFG1_DVC_S);
+
+       spin_unlock_bh(&dsaf_dev->tcam_lock);
 }
 
 /**
@@ -997,6 +1017,8 @@ static void hns_dsaf_tcam_mc_get(
 {
        u32 data_tmp;
 
+       spin_lock_bh(&dsaf_dev->tcam_lock);
+
        /*Write Addr*/
        hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
 
@@ -1027,6 +1049,8 @@ static void hns_dsaf_tcam_mc_get(
        ptbl_tcam_mcast->tbl_mcast_port_msk[4] =
                dsaf_get_field(data_tmp, DSAF_TBL_MCAST_CFG4_VM128_112_M,
                               DSAF_TBL_MCAST_CFG4_VM128_112_S);
+
+       spin_unlock_bh(&dsaf_dev->tcam_lock);
 }
 
 /**
@@ -1351,6 +1375,7 @@ static int hns_dsaf_init(struct dsaf_device *dsaf_dev)
        if (HNS_DSAF_IS_DEBUG(dsaf_dev))
                return 0;
 
+       spin_lock_init(&dsaf_dev->tcam_lock);
        ret = hns_dsaf_init_hw(dsaf_dev);
        if (ret)
                return ret;
index 00a13debbf9a38f7d2dddb78eb689de2ea52e564..1daf018d907160f4e268b78557c90daa49004627 100644 (file)
@@ -322,6 +322,8 @@ struct dsaf_device {
 
        struct dsaf_hw_stats hw_stats[DSAF_NODE_NUM];
        struct dsaf_int_stat int_stat;
+       /* make sure tcam table config spinlock */
+       spinlock_t tcam_lock;
 };
 
 static inline void *hns_dsaf_dev_priv(const struct dsaf_device *dsaf_dev)