net/mlx5: add header reformat HW steering action
[dpdk.git] / drivers / net / hns3 / hns3_ethdev_vf.c
index d8a9969..06ddf64 100644 (file)
@@ -6,7 +6,6 @@
 #include <rte_alarm.h>
 #include <ethdev_pci.h>
 #include <rte_io.h>
-#include <rte_pci.h>
 #include <rte_vfio.h>
 
 #include "hns3_ethdev.h"
@@ -232,7 +231,7 @@ hns3vf_set_default_mac_addr(struct rte_eth_dev *dev,
                                HNS3_TWO_ETHER_ADDR_LEN, true, NULL, 0);
        if (ret) {
                /*
-                * The hns3 VF PMD driver depends on the hns3 PF kernel ethdev
+                * The hns3 VF PMD depends on the hns3 PF kernel ethdev
                 * driver. When user has configured a MAC address for VF device
                 * by "ip link set ..." command based on the PF device, the hns3
                 * PF kernel ethdev driver does not allow VF driver to request
@@ -242,7 +241,7 @@ hns3vf_set_default_mac_addr(struct rte_eth_dev *dev,
                if (ret == -EPERM) {
                        hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              old_addr);
-                       hns3_warn(hw, "Has permanet mac addr(%s) for vf",
+                       hns3_warn(hw, "Has permanent mac addr(%s) for vf",
                                  mac_str);
                } else {
                        hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
@@ -312,25 +311,25 @@ hns3vf_set_promisc_mode(struct hns3_hw *hw, bool en_bc_pmc,
        req = (struct hns3_mbx_vf_to_pf_cmd *)desc.data;
 
        /*
-        * The hns3 VF PMD driver depends on the hns3 PF kernel ethdev driver,
+        * The hns3 VF PMD depends on the hns3 PF kernel ethdev driver,
         * so there are some features for promiscuous/allmulticast mode in hns3
-        * VF PMD driver as below:
+        * VF PMD as below:
         * 1. The promiscuous/allmulticast mode can be configured successfully
         *    only based on the trusted VF device. If based on the non trusted
         *    VF device, configuring promiscuous/allmulticast mode will fail.
-        *    The hns3 VF device can be confiruged as trusted device by hns3 PF
+        *    The hns3 VF device can be configured as trusted device by hns3 PF
         *    kernel ethdev driver on the host by the following command:
         *      "ip link set <eth num> vf <vf id> turst on"
         * 2. After the promiscuous mode is configured successfully, hns3 VF PMD
-        *    driver can receive the ingress and outgoing traffic. In the words,
+        *    can receive the ingress and outgoing traffic. This includes
         *    all the ingress packets, all the packets sent from the PF and
         *    other VFs on the same physical port.
         * 3. Note: Because of the hardware constraints, By default vlan filter
         *    is enabled and couldn't be turned off based on VF device, so vlan
         *    filter is still effective even in promiscuous mode. If upper
         *    applications don't call rte_eth_dev_vlan_filter API function to
-        *    set vlan based on VF device, hns3 VF PMD driver will can't receive
-        *    the packets with vlan tag in promiscuoue mode.
+        *    set vlan based on VF device, hns3 VF PMD will can't receive
+        *    the packets with vlan tag in promiscuous mode.
         */
        hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_MBX_VF_TO_PF, false);
        req->msg[0] = HNS3_MBX_SET_PROMISC_MODE;
@@ -553,9 +552,9 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        /*
         * The hns3 PF/VF devices on the same port share the hardware MTU
         * configuration. Currently, we send mailbox to inform hns3 PF kernel
-        * ethdev driver to finish hardware MTU configuration in hns3 VF PMD
-        * driver, there is no need to stop the port for hns3 VF device, and the
-        * MTU value issued by hns3 VF PMD driver must be less than or equal to
+        * ethdev driver to finish hardware MTU configuration in hns3 VF PMD,
+        * there is no need to stop the port for hns3 VF device, and the
+        * MTU value issued by hns3 VF PMD must be less than or equal to
         * PF's MTU.
         */
        if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) {
@@ -565,8 +564,8 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
        /*
         * 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
+        * using vector Rx process function or simple Rx functions in hns3 PMD.
+        * 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
@@ -810,25 +809,13 @@ hns3vf_get_push_lsc_cap(struct hns3_hw *hw)
 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;
+       ret = hns3_get_pci_revision_id(hw, &hw->revision);
+       if (ret)
+               return ret;
 
-       if (revision < PCI_REVISION_ID_HIP09_A) {
+       if (hw->revision < PCI_REVISION_ID_HIP09_A) {
                hns3vf_set_default_dev_specifications(hw);
                hw->intr.mapping_mode = HNS3_INTR_MAPPING_VEC_RSV_ONE;
                hw->intr.gl_unit = HNS3_INTR_COALESCE_GL_UINT_2US;
@@ -941,27 +928,6 @@ hns3vf_get_queue_info(struct hns3_hw *hw)
        return hns3vf_check_tqp_info(hw);
 }
 
-static int
-hns3vf_get_queue_depth(struct hns3_hw *hw)
-{
-#define HNS3VF_TQPS_DEPTH_INFO_LEN     4
-       uint8_t resp_msg[HNS3VF_TQPS_DEPTH_INFO_LEN];
-       int ret;
-
-       ret = hns3_send_mbx_msg(hw, HNS3_MBX_GET_QDEPTH, 0, NULL, 0, true,
-                               resp_msg, HNS3VF_TQPS_DEPTH_INFO_LEN);
-       if (ret) {
-               PMD_INIT_LOG(ERR, "Failed to get tqp depth info from PF: %d",
-                            ret);
-               return ret;
-       }
-
-       memcpy(&hw->num_tx_desc, &resp_msg[0], sizeof(uint16_t));
-       memcpy(&hw->num_rx_desc, &resp_msg[2], sizeof(uint16_t));
-
-       return 0;
-}
-
 static void
 hns3vf_update_caps(struct hns3_hw *hw, uint32_t caps)
 {
@@ -1052,11 +1018,6 @@ hns3vf_get_configuration(struct hns3_hw *hw)
        if (ret)
                return ret;
 
-       /* Get queue depth info from PF */
-       ret = hns3vf_get_queue_depth(hw);
-       if (ret)
-               return ret;
-
        /* Get user defined VF MAC addr from PF */
        ret = hns3vf_get_host_mac_addr(hw);
        if (ret)
@@ -1065,15 +1026,6 @@ hns3vf_get_configuration(struct hns3_hw *hw)
        return hns3vf_get_port_base_vlan_filter_state(hw);
 }
 
-static int
-hns3vf_set_tc_queue_mapping(struct hns3_adapter *hns, uint16_t nb_rx_q,
-                           uint16_t nb_tx_q)
-{
-       struct hns3_hw *hw = &hns->hw;
-
-       return hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q);
-}
-
 static void
 hns3vf_request_link_info(struct hns3_hw *hw)
 {
@@ -1569,7 +1521,7 @@ hns3vf_init_vf(struct rte_eth_dev *eth_dev)
                goto err_set_tc_queue;
        }
 
-       ret = hns3vf_set_tc_queue_mapping(hns, hw->tqps_num, hw->tqps_num);
+       ret = hns3_queue_to_tc_mapping(hw, hw->tqps_num, hw->tqps_num);
        if (ret) {
                PMD_INIT_LOG(ERR, "failed to set tc info, ret = %d.", ret);
                goto err_set_tc_queue;
@@ -1778,7 +1730,7 @@ hns3vf_do_start(struct hns3_adapter *hns, bool reset_queue)
        uint16_t nb_tx_q = hw->data->nb_tx_queues;
        int ret;
 
-       ret = hns3vf_set_tc_queue_mapping(hns, nb_rx_q, nb_tx_q);
+       ret = hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q);
        if (ret)
                return ret;
 
@@ -2075,7 +2027,7 @@ hns3vf_check_default_mac_change(struct hns3_hw *hw)
         * ethdev driver sets the MAC address for VF device after the
         * initialization of the related VF device, the PF driver will notify
         * VF driver to reset VF device to make the new MAC address effective
-        * immediately. The hns3 VF PMD driver should check whether the MAC
+        * immediately. The hns3 VF PMD should check whether the MAC
         * address has been changed by the PF kernel ethdev driver, if changed
         * VF driver should configure hardware using the new MAC address in the
         * recovering hardware configuration stage of the reset process.
@@ -2338,6 +2290,7 @@ static const struct eth_dev_ops hns3vf_eth_dev_ops = {
        .get_reg            = hns3_get_regs,
        .dev_supported_ptypes_get = hns3_dev_supported_ptypes_get,
        .tx_done_cleanup    = hns3_tx_done_cleanup,
+       .eth_dev_priv_dump  = hns3_eth_dev_priv_dump,
 };
 
 static const struct hns3_reset_ops hns3vf_reset_ops = {
@@ -2400,34 +2353,9 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev)
                goto err_init_vf;
        }
 
-       /* Allocate memory for storing MAC addresses */
-       eth_dev->data->mac_addrs = rte_zmalloc("hns3vf-mac",
-                                              sizeof(struct rte_ether_addr) *
-                                              HNS3_VF_UC_MACADDR_NUM, 0);
-       if (eth_dev->data->mac_addrs == NULL) {
-               PMD_INIT_LOG(ERR, "Failed to allocate %zx bytes needed "
-                            "to store MAC addresses",
-                            sizeof(struct rte_ether_addr) *
-                            HNS3_VF_UC_MACADDR_NUM);
-               ret = -ENOMEM;
-               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]);
+       ret = hns3_init_mac_addrs(eth_dev);
+       if (ret != 0)
+               goto err_init_mac_addrs;
 
        hw->adapter_state = HNS3_NIC_INITIALIZED;
 
@@ -2443,7 +2371,7 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev)
                          eth_dev);
        return 0;
 
-err_rte_zmalloc:
+err_init_mac_addrs:
        hns3vf_uninit_vf(eth_dev);
 
 err_init_vf:
@@ -2472,7 +2400,6 @@ hns3vf_dev_uninit(struct rte_eth_dev *eth_dev)
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
-               __atomic_fetch_sub(&hw->secondary_cnt, 1, __ATOMIC_RELAXED);
                hns3_mp_uninit(eth_dev);
                return 0;
        }