net/hns3: clear residual hardware configurations on init
authorHongbo Zheng <zhenghongbo3@huawei.com>
Wed, 1 Jul 2020 11:54:38 +0000 (19:54 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 7 Jul 2020 21:38:26 +0000 (23:38 +0200)
When the last driver exits abnormally, for example, it is killed by
'kill -9', it may be too late to clear the configuration and cause the
configuration to remain. Therefore, to ensure that the hardware
environment is clean during initialization, the PF driver actively clear
the hardware environment during initialization, including PF and
corresponding VFs' vlan, mac, flow table configurations, etc.

Fixes: d51867db65c1 ("net/hns3: add initialization")
Cc: stable@dpdk.org
Signed-off-by: Hongbo Zheng <zhenghongbo3@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
drivers/net/hns3/hns3_cmd.h
drivers/net/hns3/hns3_ethdev.c

index da770ac..b203e66 100644 (file)
@@ -207,6 +207,9 @@ enum hns3_opcode_type {
        HNS3_OPC_FD_AD_OP               = 0x1204,
        HNS3_OPC_FD_COUNTER_OP          = 0x1205,
 
+       /* Clear hardware state command */
+       HNS3_OPC_CLEAR_HW_STATE         = 0x700A,
+
        /* SFP command */
        HNS3_OPC_SFP_GET_SPEED          = 0x7104,
 
index 4afee5d..8b18b47 100644 (file)
@@ -4318,6 +4318,21 @@ err_mac_init:
        return ret;
 }
 
+static int
+hns3_clear_hw(struct hns3_hw *hw)
+{
+       struct hns3_cmd_desc desc;
+       int ret;
+
+       hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CLEAR_HW_STATE, false);
+
+       ret = hns3_cmd_send(hw, &desc, 1);
+       if (ret && ret != -EOPNOTSUPP)
+               return ret;
+
+       return 0;
+}
+
 static int
 hns3_init_pf(struct rte_eth_dev *eth_dev)
 {
@@ -4348,6 +4363,18 @@ hns3_init_pf(struct rte_eth_dev *eth_dev)
                goto err_cmd_init;
        }
 
+       /*
+        * To ensure that the hardware environment is clean during
+        * initialization, the driver actively clear the hardware environment
+        * during initialization, including PF and corresponding VFs' vlan, mac,
+        * flow table configurations, etc.
+        */
+       ret = hns3_clear_hw(hw);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "failed to clear hardware: %d", ret);
+               goto err_cmd_init;
+       }
+
        ret = rte_intr_callback_register(&pci_dev->intr_handle,
                                         hns3_interrupt_handler,
                                         eth_dev);