net/iavf: fix port start during configuration restore
[dpdk.git] / drivers / net / hns3 / hns3_ethdev_vf.c
index 3c5998a..1d8eef7 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);
@@ -913,7 +909,6 @@ 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 |
@@ -948,6 +943,15 @@ hns3vf_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *info)
                .nb_mtu_seg_max = HNS3_MAX_NON_TSO_BD_PER_PKT,
        };
 
+       info->default_rxconf = (struct rte_eth_rxconf) {
+               /*
+                * If there are no available Rx buffer descriptors, incoming
+                * packets are always dropped by hardware based on hns3 network
+                * engine.
+                */
+               .rx_drop_en = 1,
+       };
+
        info->vmdq_queue_num = 0;
 
        info->reta_size = HNS3_RSS_IND_TBL_SIZE;
@@ -1060,6 +1064,49 @@ 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)
 {
@@ -1075,11 +1122,34 @@ hns3vf_get_capability(struct hns3_hw *hw)
        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: %d", ret);
+               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;
 }
 
@@ -1551,7 +1621,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);
@@ -1678,21 +1748,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);
@@ -1893,6 +1948,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:
@@ -2425,8 +2481,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");
                }
@@ -2473,6 +2529,8 @@ 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,
+       .rxq_info_get       = hns3_rxq_info_get,
+       .txq_info_get       = hns3_txq_info_get,
        .dev_configure      = hns3vf_dev_configure,
        .mac_addr_add       = hns3vf_add_mac_addr,
        .mac_addr_remove    = hns3vf_remove_mac_addr,
@@ -2524,12 +2582,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;
@@ -2559,8 +2629,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
@@ -2586,6 +2670,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;