net/enic: enable flow API for VF representor
[dpdk.git] / drivers / net / hns3 / hns3_ethdev_vf.c
index ccf44a1..037a5be 100644 (file)
@@ -693,7 +693,7 @@ hns3vf_bind_ring_with_vector(struct hns3_hw *hw, uint8_t vector_id,
 static int
 hns3vf_init_ring_with_vector(struct hns3_hw *hw)
 {
-       uint8_t vec;
+       uint16_t vec;
        int ret;
        int i;
 
@@ -704,27 +704,23 @@ hns3vf_init_ring_with_vector(struct hns3_hw *hw)
         * vector. In the initialization clearing the all hardware mapping
         * relationship configurations between queues and interrupt vectors is
         * needed, so some error caused by the residual configurations, such as
-        * the unexpected Tx interrupt, can be avoid. Because of the hardware
-        * constraints in hns3 hardware engine, we have to implement clearing
-        * the mapping relationship configurations by binding all queues to the
-        * last interrupt vector and reserving the last interrupt vector. This
-        * method results in a decrease of the maximum queues when upper
-        * applications call the rte_eth_dev_configure API function to enable
-        * Rx interrupt.
+        * the unexpected Tx interrupt, can be avoid.
         */
        vec = hw->num_msi - 1; /* vector 0 for misc interrupt, not for queue */
-       /* vec - 1: the last interrupt is reserved */
-       hw->intr_tqps_num = vec > hw->tqps_num ? hw->tqps_num : vec - 1;
+       if (hw->intr.mapping_mode == HNS3_INTR_MAPPING_VEC_RSV_ONE)
+               vec = vec - 1; /* the last interrupt is reserved */
+       hw->intr_tqps_num = RTE_MIN(vec, hw->tqps_num);
        for (i = 0; i < hw->intr_tqps_num; i++) {
                /*
-                * Set gap limiter and rate limiter configuration of queue's
-                * interrupt.
+                * Set gap limiter/rate limiter/quanity limiter algorithm
+                * configuration for interrupt coalesce of queue's interrupt.
                 */
                hns3_set_queue_intr_gl(hw, i, HNS3_RING_GL_RX,
                                       HNS3_TQP_INTR_GL_DEFAULT);
                hns3_set_queue_intr_gl(hw, i, HNS3_RING_GL_TX,
                                       HNS3_TQP_INTR_GL_DEFAULT);
                hns3_set_queue_intr_rl(hw, i, HNS3_TQP_INTR_RL_DEFAULT);
+               hns3_set_queue_intr_ql(hw, i, HNS3_TQP_INTR_QL_DEFAULT);
 
                ret = hns3vf_bind_ring_with_vector(hw, vec, false,
                                                   HNS3_RING_TYPE_TX, i);
@@ -749,7 +745,8 @@ hns3vf_init_ring_with_vector(struct hns3_hw *hw)
 static int
 hns3vf_dev_configure(struct rte_eth_dev *dev)
 {
-       struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct hns3_adapter *hns = dev->data->dev_private;
+       struct hns3_hw *hw = &hns->hw;
        struct hns3_rss_conf *rss_cfg = &hw->rss_info;
        struct rte_eth_conf *conf = &dev->data->dev_conf;
        enum rte_eth_rx_mq_mode mq_mode = conf->rxmode.mq_mode;
@@ -824,6 +821,13 @@ hns3vf_dev_configure(struct rte_eth_dev *dev)
        if (ret)
                goto cfg_err;
 
+       hns->rx_simple_allowed = true;
+       hns->rx_vec_allowed = true;
+       hns->tx_simple_allowed = true;
+       hns->tx_vec_allowed = true;
+
+       hns3_init_rx_ptype_tble(dev);
+
        hw->adapter_state = HNS3_NIC_CONFIGURED;
        return 0;
 
@@ -867,6 +871,25 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
                return -EIO;
        }
 
+       /*
+        * when Rx of scattered packets is off, we have some possibility of
+        * using vector Rx process function or simple Rx functions in hns3 PMD
+        * driver. If the input MTU is increased and the maximum length of
+        * received packets is greater than the length of a buffer for Rx
+        * packet, the hardware network engine needs to use multiple BDs and
+        * buffers to store these packets. This will cause problems when still
+        * using vector Rx process function or simple Rx function to receiving
+        * packets. So, when Rx of scattered packets is off and device is
+        * started, it is not permitted to increase MTU so that the maximum
+        * length of Rx packets is greater than Rx buffer length.
+        */
+       if (dev->data->dev_started && !dev->data->scattered_rx &&
+           frame_size > hw->rx_buf_len) {
+               hns3_err(hw, "failed to set mtu because current is "
+                       "not scattered rx mode");
+               return -EOPNOTSUPP;
+       }
+
        rte_spinlock_lock(&hw->lock);
        ret = hns3vf_config_mtu(hw, mtu);
        if (ret) {
@@ -902,7 +925,7 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
        info->max_rx_queues = q_num;
        info->max_tx_queues = hw->tqps_num;
        info->max_rx_pktlen = HNS3_MAX_FRAME_LEN; /* CRC included */
-       info->min_rx_bufsize = hw->rx_buf_len;
+       info->min_rx_bufsize = HNS3_MIN_BD_BUF_SIZE;
        info->max_mac_addrs = HNS3_VF_UC_MACADDR_NUM;
        info->max_mtu = info->max_rx_pktlen - HNS3_ETH_OVERHEAD;
        info->max_lro_pkt_size = HNS3_MAX_LRO_SIZE;
@@ -913,27 +936,24 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
                                 DEV_RX_OFFLOAD_SCTP_CKSUM |
                                 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
                                 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM |
-                                DEV_RX_OFFLOAD_KEEP_CRC |
                                 DEV_RX_OFFLOAD_SCATTER |
                                 DEV_RX_OFFLOAD_VLAN_STRIP |
                                 DEV_RX_OFFLOAD_VLAN_FILTER |
                                 DEV_RX_OFFLOAD_JUMBO_FRAME |
                                 DEV_RX_OFFLOAD_RSS_HASH |
                                 DEV_RX_OFFLOAD_TCP_LRO);
-       info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
        info->tx_offload_capa = (DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
                                 DEV_TX_OFFLOAD_IPV4_CKSUM |
                                 DEV_TX_OFFLOAD_TCP_CKSUM |
                                 DEV_TX_OFFLOAD_UDP_CKSUM |
                                 DEV_TX_OFFLOAD_SCTP_CKSUM |
-                                DEV_TX_OFFLOAD_VLAN_INSERT |
-                                DEV_TX_OFFLOAD_QINQ_INSERT |
                                 DEV_TX_OFFLOAD_MULTI_SEGS |
                                 DEV_TX_OFFLOAD_TCP_TSO |
                                 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
                                 DEV_TX_OFFLOAD_GRE_TNL_TSO |
                                 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
-                                info->tx_queue_offload_capa);
+                                DEV_TX_OFFLOAD_MBUF_FAST_FREE |
+                                hns3_txvlan_cap_get(hw));
 
        info->rx_desc_lim = (struct rte_eth_desc_lim) {
                .nb_max = HNS3_MAX_RING_DESC,
@@ -945,6 +965,23 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
                .nb_max = HNS3_MAX_RING_DESC,
                .nb_min = HNS3_MIN_RING_DESC,
                .nb_align = HNS3_ALIGN_RING_DESC,
+               .nb_seg_max = HNS3_MAX_TSO_BD_PER_PKT,
+               .nb_mtu_seg_max = HNS3_MAX_NON_TSO_BD_PER_PKT,
+       };
+
+       info->default_rxconf = (struct rte_eth_rxconf) {
+               .rx_free_thresh = HNS3_DEFAULT_RX_FREE_THRESH,
+               /*
+                * If there are no available Rx buffer descriptors, incoming
+                * packets are always dropped by hardware based on hns3 network
+                * engine.
+                */
+               .rx_drop_en = 1,
+               .offloads = 0,
+       };
+       info->default_txconf = (struct rte_eth_txconf) {
+               .tx_rs_thresh = HNS3_DEFAULT_TX_RS_THRESH,
+               .offloads = 0,
        };
 
        info->vmdq_queue_num = 0;
@@ -1059,6 +1096,95 @@ hns3vf_interrupt_handler(void *param)
        hns3vf_enable_irq0(hw);
 }
 
+static void
+hns3vf_set_default_dev_specifications(struct hns3_hw *hw)
+{
+       hw->max_non_tso_bd_num = HNS3_MAX_NON_TSO_BD_PER_PKT;
+       hw->rss_ind_tbl_size = HNS3_RSS_IND_TBL_SIZE;
+       hw->rss_key_size = HNS3_RSS_KEY_SIZE;
+}
+
+static void
+hns3vf_parse_dev_specifications(struct hns3_hw *hw, struct hns3_cmd_desc *desc)
+{
+       struct hns3_dev_specs_0_cmd *req0;
+
+       req0 = (struct hns3_dev_specs_0_cmd *)desc[0].data;
+
+       hw->max_non_tso_bd_num = req0->max_non_tso_bd_num;
+       hw->rss_ind_tbl_size = rte_le_to_cpu_16(req0->rss_ind_tbl_size);
+       hw->rss_key_size = rte_le_to_cpu_16(req0->rss_key_size);
+}
+
+static int
+hns3vf_query_dev_specifications(struct hns3_hw *hw)
+{
+       struct hns3_cmd_desc desc[HNS3_QUERY_DEV_SPECS_BD_NUM];
+       int ret;
+       int i;
+
+       for (i = 0; i < HNS3_QUERY_DEV_SPECS_BD_NUM - 1; i++) {
+               hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS,
+                                         true);
+               desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
+       }
+       hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_QUERY_DEV_SPECS, true);
+
+       ret = hns3_cmd_send(hw, desc, HNS3_QUERY_DEV_SPECS_BD_NUM);
+       if (ret)
+               return ret;
+
+       hns3vf_parse_dev_specifications(hw, desc);
+
+       return 0;
+}
+
+static int
+hns3vf_get_capability(struct hns3_hw *hw)
+{
+       struct rte_pci_device *pci_dev;
+       struct rte_eth_dev *eth_dev;
+       uint8_t revision;
+       int ret;
+
+       eth_dev = &rte_eth_devices[hw->data->port_id];
+       pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+       /* Get PCI revision id */
+       ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN,
+                                 HNS3_PCI_REVISION_ID);
+       if (ret != HNS3_PCI_REVISION_ID_LEN) {
+               PMD_INIT_LOG(ERR, "failed to read pci revision id, ret = %d",
+                            ret);
+               return -EIO;
+       }
+       hw->revision = revision;
+
+       if (revision < PCI_REVISION_ID_HIP09_A) {
+               hns3vf_set_default_dev_specifications(hw);
+               hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
+               hw->intr.coalesce_mode = HNS3_INTR_COALESCE_NON_QL;
+               hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
+               hw->min_tx_pkt_len = HNS3_HIP08_MIN_TX_PKT_LEN;
+               return 0;
+       }
+
+       ret = hns3vf_query_dev_specifications(hw);
+       if (ret) {
+               PMD_INIT_LOG(ERR,
+                            "failed to query dev specifications, ret = %d",
+                            ret);
+               return ret;
+       }
+
+       hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_ALL;
+       hw->intr.coalesce_mode = HNS3_INTR_COALESCE_QL;
+       hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_1US;
+       hw->min_tx_pkt_len = HNS3_HIP09_MIN_TX_PKT_LEN;
+
+       return 0;
+}
+
 static int
 hns3vf_check_tqp_info(struct hns3_hw *hw)
 {
@@ -1072,12 +1198,53 @@ hns3vf_check_tqp_info(struct hns3_hw *hw)
                return -EINVAL;
        }
 
-       if (hw->rx_buf_len == 0)
-               hw->rx_buf_len = HNS3_DEFAULT_RX_BUF_LEN;
        hw->alloc_rss_size = RTE_MIN(hw->rss_size_max, hw->tqps_num);
 
        return 0;
 }
+static int
+hns3vf_get_port_base_vlan_filter_state(struct hns3_hw *hw)
+{
+       uint8_t resp_msg;
+       int ret;
+
+       ret = hns3_send_mbx_msg(hw, HNS3_MBX_SET_VLAN,
+                               HNS3_MBX_GET_PORT_BASE_VLAN_STATE, NULL, 0,
+                               true, &resp_msg, sizeof(resp_msg));
+       if (ret) {
+               if (ret == -ETIME) {
+                       /*
+                        * Getting current port based VLAN state from PF driver
+                        * will not affect VF driver's basic function. Because
+                        * the VF driver relies on hns3 PF kernel ether driver,
+                        * to avoid introducing compatibility issues with older
+                        * version of PF driver, no failure will be returned
+                        * when the return value is ETIME. This return value has
+                        * the following scenarios:
+                        * 1) Firmware didn't return the results in time
+                        * 2) the result return by firmware is timeout
+                        * 3) the older version of kernel side PF driver does
+                        *    not support this mailbox message.
+                        * For scenarios 1 and 2, it is most likely that a
+                        * hardware error has occurred, or a hardware reset has
+                        * occurred. In this case, these errors will be caught
+                        * by other functions.
+                        */
+                       PMD_INIT_LOG(WARNING,
+                               "failed to get PVID state for timeout, maybe "
+                               "kernel side PF driver doesn't support this "
+                               "mailbox message, or firmware didn't respond.");
+                       resp_msg = HNS3_PORT_BASE_VLAN_DISABLE;
+               } else {
+                       PMD_INIT_LOG(ERR, "failed to get port based VLAN state,"
+                               " ret = %d", ret);
+                       return ret;
+               }
+       }
+       hw->port_base_vlan_cfg.state = resp_msg ?
+               HNS3_PORT_BASE_VLAN_ENABLE : HNS3_PORT_BASE_VLAN_DISABLE;
+       return 0;
+}
 
 static int
 hns3vf_get_queue_info(struct hns3_hw *hw)
@@ -1095,7 +1262,6 @@ hns3vf_get_queue_info(struct hns3_hw *hw)
 
        memcpy(&hw->tqps_num, &resp_msg[0], sizeof(uint16_t));
        memcpy(&hw->rss_size_max, &resp_msg[2], sizeof(uint16_t));
-       memcpy(&hw->rx_buf_len, &resp_msg[4], sizeof(uint16_t));
 
        return hns3vf_check_tqp_info(hw);
 }
@@ -1166,6 +1332,13 @@ hns3vf_get_configuration(struct hns3_hw *hw)
        hw->mac.media_type = HNS3_MEDIA_TYPE_NONE;
        hw->rss_dis_flag = false;
 
+       /* Get device capability */
+       ret = hns3vf_get_capability(hw);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "failed to get device capability: %d.", ret);
+               return ret;
+       }
+
        /* Get queue configuration from PF */
        ret = hns3vf_get_queue_info(hw);
        if (ret)
@@ -1181,6 +1354,10 @@ hns3vf_get_configuration(struct hns3_hw *hw)
        if (ret)
                return ret;
 
+       ret = hns3vf_get_port_base_vlan_filter_state(hw);
+       if (ret)
+               return ret;
+
        /* Get tc configuration from PF */
        return hns3vf_get_tc_info(hw);
 }
@@ -1476,7 +1653,7 @@ hns3_query_vf_resource(struct hns3_hw *hw)
 
        req = (struct hns3_vf_res_cmd *)desc.data;
        num_msi = hns3_get_field(rte_le_to_cpu_16(req->vf_intr_vector_number),
-                                HNS3_VEC_NUM_M, HNS3_VEC_NUM_S);
+                                HNS3_VF_VEC_NUM_M, HNS3_VF_VEC_NUM_S);
        if (num_msi < HNS3_MIN_VECTOR_NUM) {
                hns3_err(hw, "Just %u msi resources, not enough for vf(min:%d)",
                         num_msi, HNS3_MIN_VECTOR_NUM);
@@ -1603,21 +1780,6 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev)
                goto err_get_config;
        }
 
-       /*
-        * The hns3 PF ethdev driver in kernel support setting VF MAC address
-        * on the host by "ip link set ..." command. To avoid some incorrect
-        * scenes, for example, hns3 VF PMD driver fails to receive and send
-        * packets after user configure the MAC address by using the
-        * "ip link set ..." command, hns3 VF PMD driver keep the same MAC
-        * address strategy as the hns3 kernel ethdev driver in the
-        * initialization. If user configure a MAC address by the ip command
-        * for VF device, then hns3 VF PMD driver will start with it, otherwise
-        * start with a random MAC address in the initialization.
-        */
-       ret = rte_is_zero_ether_addr((struct rte_ether_addr *)hw->mac.mac_addr);
-       if (ret)
-               rte_eth_random_addr(hw->mac.mac_addr);
-
        ret = hns3vf_clear_vport_list(hw);
        if (ret) {
                PMD_INIT_LOG(ERR, "Failed to clear tbl list: %d", ret);
@@ -1743,6 +1905,7 @@ hns3vf_dev_stop(struct rte_eth_dev *dev)
                hns3_dev_release_mbufs(hns);
                hw->adapter_state = HNS3_NIC_CONFIGURED;
        }
+       hns3_rx_scattered_reset(dev);
        rte_eal_alarm_cancel(hns3vf_service_handler, dev);
        rte_spinlock_unlock(&hw->lock);
 }
@@ -1818,6 +1981,7 @@ hns3vf_dev_link_update(struct rte_eth_dev *eth_dev,
        case ETH_SPEED_NUM_40G:
        case ETH_SPEED_NUM_50G:
        case ETH_SPEED_NUM_100G:
+       case ETH_SPEED_NUM_200G:
                new_link.link_speed = mac->link_speed;
                break;
        default:
@@ -1978,6 +2142,7 @@ hns3vf_dev_start(struct rte_eth_dev *dev)
        hw->adapter_state = HNS3_NIC_STARTED;
        rte_spinlock_unlock(&hw->lock);
 
+       hns3_rx_scattered_calc(dev);
        hns3_set_rxtx_function(dev);
        hns3_mp_req_start_rxtx(dev);
        rte_eal_alarm_set(HNS3VF_SERVICE_INTERVAL, hns3vf_service_handler, dev);
@@ -2225,6 +2390,10 @@ hns3vf_restore_conf(struct hns3_adapter *hns)
        if (ret)
                goto err_vlan_table;
 
+       ret = hns3vf_get_port_base_vlan_filter_state(hw);
+       if (ret)
+               goto err_vlan_table;
+
        ret = hns3vf_restore_rx_interrupt(hw);
        if (ret)
                goto err_vlan_table;
@@ -2346,8 +2515,8 @@ hns3vf_reinit_dev(struct hns3_adapter *hns)
                 * UIO enables msix by writing the pcie configuration space
                 * vfio_pci enables msix in rte_intr_enable.
                 */
-               if (pci_dev->kdrv == RTE_KDRV_IGB_UIO ||
-                   pci_dev->kdrv == RTE_KDRV_UIO_GENERIC) {
+               if (pci_dev->kdrv == RTE_PCI_KDRV_IGB_UIO ||
+                   pci_dev->kdrv == RTE_PCI_KDRV_UIO_GENERIC) {
                        if (hns3vf_enable_msix(pci_dev, true))
                                hns3_err(hw, "Failed to enable msix");
                }
@@ -2371,6 +2540,7 @@ hns3vf_reinit_dev(struct hns3_adapter *hns)
 }
 
 static const struct eth_dev_ops hns3vf_eth_dev_ops = {
+       .dev_configure      = hns3vf_dev_configure,
        .dev_start          = hns3vf_dev_start,
        .dev_stop           = hns3vf_dev_stop,
        .dev_close          = hns3vf_dev_close,
@@ -2394,7 +2564,10 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = {
        .tx_queue_release   = hns3_dev_tx_queue_release,
        .rx_queue_intr_enable   = hns3_dev_rx_queue_intr_enable,
        .rx_queue_intr_disable  = hns3_dev_rx_queue_intr_disable,
-       .dev_configure      = hns3vf_dev_configure,
+       .rxq_info_get       = hns3_rxq_info_get,
+       .txq_info_get       = hns3_txq_info_get,
+       .rx_burst_mode_get  = hns3_rx_burst_mode_get,
+       .tx_burst_mode_get  = hns3_tx_burst_mode_get,
        .mac_addr_add       = hns3vf_add_mac_addr,
        .mac_addr_remove    = hns3vf_remove_mac_addr,
        .mac_addr_set       = hns3vf_set_default_mac_addr,
@@ -2424,25 +2597,12 @@ static const struct hns3_reset_ops hns3vf_reset_ops = {
 static int
 hns3vf_dev_init(struct rte_eth_dev *eth_dev)
 {
-       struct rte_device *dev = eth_dev->device;
-       struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
        struct hns3_adapter *hns = eth_dev->data->dev_private;
        struct hns3_hw *hw = &hns->hw;
-       uint8_t revision;
        int ret;
 
        PMD_INIT_FUNC_TRACE();
 
-       /* Get PCI revision id */
-       ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN,
-                                 HNS3_PCI_REVISION_ID);
-       if (ret != HNS3_PCI_REVISION_ID_LEN) {
-               PMD_INIT_LOG(ERR, "Failed to read pci revision id, ret = %d",
-                            ret);
-               return -EIO;
-       }
-       hw->revision = revision;
-
        eth_dev->process_private = (struct hns3_process_private *)
            rte_zmalloc_socket("hns3_filter_list",
                               sizeof(struct hns3_process_private),
@@ -2458,12 +2618,24 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev)
        hns3_set_rxtx_function(eth_dev);
        eth_dev->dev_ops = &hns3vf_eth_dev_ops;
        if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
-               hns3_mp_init_secondary();
+               ret = hns3_mp_init_secondary();
+               if (ret) {
+                       PMD_INIT_LOG(ERR, "Failed to init for secondary "
+                                         "process, ret = %d", ret);
+                       goto err_mp_init_secondary;
+               }
+
                hw->secondary_cnt++;
                return 0;
        }
 
-       hns3_mp_init_primary();
+       ret = hns3_mp_init_primary();
+       if (ret) {
+               PMD_INIT_LOG(ERR,
+                            "Failed to init for primary process, ret = %d",
+                            ret);
+               goto err_mp_init_primary;
+       }
 
        hw->adapter_state = HNS3_NIC_UNINITIALIZED;
        hns->is_vf = true;
@@ -2493,8 +2665,22 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev)
                goto err_rte_zmalloc;
        }
 
+       /*
+        * The hns3 PF ethdev driver in kernel support setting VF MAC address
+        * on the host by "ip link set ..." command. To avoid some incorrect
+        * scenes, for example, hns3 VF PMD driver fails to receive and send
+        * packets after user configure the MAC address by using the
+        * "ip link set ..." command, hns3 VF PMD driver keep the same MAC
+        * address strategy as the hns3 kernel ethdev driver in the
+        * initialization. If user configure a MAC address by the ip command
+        * for VF device, then hns3 VF PMD driver will start with it, otherwise
+        * start with a random MAC address in the initialization.
+        */
+       if (rte_is_zero_ether_addr((struct rte_ether_addr *)hw->mac.mac_addr))
+               rte_eth_random_addr(hw->mac.mac_addr);
        rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr,
                            &eth_dev->data->mac_addrs[0]);
+
        hw->adapter_state = HNS3_NIC_INITIALIZED;
        /*
         * Pass the information to the rte_eth_dev_close() that it should also
@@ -2520,6 +2706,10 @@ err_init_vf:
        rte_free(hw->reset.wait_data);
 
 err_init_reset:
+       hns3_mp_uninit_primary();
+
+err_mp_init_primary:
+err_mp_init_secondary:
        eth_dev->dev_ops = NULL;
        eth_dev->rx_pkt_burst = NULL;
        eth_dev->tx_pkt_burst = NULL;