net/hns3: move queue stats to xstats
[dpdk.git] / drivers / net / hns3 / hns3_ethdev_vf.c
index 088a46f..1af947a 100644 (file)
@@ -2,29 +2,10 @@
  * Copyright(c) 2018-2019 Hisilicon Limited.
  */
 
-#include <errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <arpa/inet.h>
 #include <linux/pci_regs.h>
-
 #include <rte_alarm.h>
-#include <rte_atomic.h>
-#include <rte_bus_pci.h>
-#include <rte_byteorder.h>
-#include <rte_common.h>
-#include <rte_cycles.h>
-#include <rte_dev.h>
-#include <rte_eal.h>
-#include <rte_ether.h>
-#include <rte_ethdev_driver.h>
-#include <rte_ethdev_pci.h>
-#include <rte_interrupts.h>
+#include <ethdev_pci.h>
 #include <rte_io.h>
-#include <rte_log.h>
 #include <rte_pci.h>
 #include <rte_vfio.h>
 
@@ -167,8 +148,12 @@ hns3vf_enable_msix(const struct rte_pci_device *device, bool op)
                        control |= PCI_MSIX_FLAGS_ENABLE;
                else
                        control &= ~PCI_MSIX_FLAGS_ENABLE;
-               rte_pci_write_config(device, &control, sizeof(control),
-                                    (pos + PCI_MSIX_FLAGS));
+               ret = rte_pci_write_config(device, &control, sizeof(control),
+                                         (pos + PCI_MSIX_FLAGS));
+               if (ret < 0) {
+                       PMD_INIT_LOG(ERR, "failed to write PCI offset 0x%x",
+                                   (pos + PCI_MSIX_FLAGS));
+               }
                return 0;
        }
        return -ENXIO;
@@ -185,7 +170,7 @@ hns3vf_add_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
                                HNS3_MBX_MAC_VLAN_UC_ADD, mac_addr->addr_bytes,
                                RTE_ETHER_ADDR_LEN, false, NULL, 0);
        if (ret) {
-               rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+               hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                      mac_addr);
                hns3_err(hw, "failed to add uc mac addr(%s), ret = %d",
                         mac_str, ret);
@@ -205,7 +190,7 @@ hns3vf_remove_uc_mac_addr(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
                                mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN,
                                false, NULL, 0);
        if (ret) {
-               rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+               hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                      mac_addr);
                hns3_err(hw, "failed to add uc mac addr(%s), ret = %d",
                         mac_str, ret);
@@ -225,7 +210,7 @@ hns3vf_add_mc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
                addr = &hw->mc_addrs[i];
                /* Check if there are duplicate addresses */
                if (rte_is_same_ether_addr(addr, mac_addr)) {
-                       rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              addr);
                        hns3_err(hw, "failed to add mc mac addr, same addrs"
                                 "(%s) is added by the set_mc_mac_addr_list "
@@ -236,7 +221,7 @@ hns3vf_add_mc_addr_common(struct hns3_hw *hw, struct rte_ether_addr *mac_addr)
 
        ret = hns3vf_add_mc_mac_addr(hw, mac_addr);
        if (ret) {
-               rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+               hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                      mac_addr);
                hns3_err(hw, "failed to add mc mac addr(%s), ret = %d",
                         mac_str, ret);
@@ -271,7 +256,7 @@ hns3vf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
 
        rte_spinlock_unlock(&hw->lock);
        if (ret) {
-               rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+               hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                      mac_addr);
                hns3_err(hw, "failed to add mac addr(%s), ret = %d", mac_str,
                         ret);
@@ -298,7 +283,7 @@ hns3vf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t idx)
 
        rte_spinlock_unlock(&hw->lock);
        if (ret) {
-               rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+               hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                      mac_addr);
                hns3_err(hw, "failed to remove mac addr(%s), ret = %d",
                         mac_str, ret);
@@ -339,12 +324,12 @@ hns3vf_set_default_mac_addr(struct rte_eth_dev *dev,
                 * -EPREM to VF driver through mailbox.
                 */
                if (ret == -EPERM) {
-                       rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              old_addr);
                        hns3_warn(hw, "Has permanet mac addr(%s) for vf",
                                  mac_str);
                } else {
-                       rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              mac_addr);
                        hns3_err(hw, "Failed to set mac addr(%s) for vf: %d",
                                 mac_str, ret);
@@ -381,7 +366,7 @@ hns3vf_configure_mac_addr(struct hns3_adapter *hns, bool del)
 
                if (ret) {
                        err = ret;
-                       rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              addr);
                        hns3_err(hw, "failed to %s mac addr(%s) index:%d "
                                 "ret = %d.", del ? "remove" : "restore",
@@ -403,7 +388,7 @@ hns3vf_add_mc_mac_addr(struct hns3_hw *hw,
                                mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN, false,
                                NULL, 0);
        if (ret) {
-               rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+               hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                      mac_addr);
                hns3_err(hw, "Failed to add mc mac addr(%s) for vf: %d",
                         mac_str, ret);
@@ -424,7 +409,7 @@ hns3vf_remove_mc_mac_addr(struct hns3_hw *hw,
                                mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN, false,
                                NULL, 0);
        if (ret) {
-               rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+               hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                      mac_addr);
                hns3_err(hw, "Failed to remove mc mac addr(%s) for vf: %d",
                         mac_str, ret);
@@ -444,7 +429,7 @@ hns3vf_set_mc_addr_chk_param(struct hns3_hw *hw,
        uint32_t j;
 
        if (nb_mc_addr > HNS3_MC_MACADDR_NUM) {
-               hns3_err(hw, "failed to set mc mac addr, nb_mc_addr(%d) "
+               hns3_err(hw, "failed to set mc mac addr, nb_mc_addr(%u) "
                         "invalid. valid range: 0~%d",
                         nb_mc_addr, HNS3_MC_MACADDR_NUM);
                return -EINVAL;
@@ -454,7 +439,7 @@ hns3vf_set_mc_addr_chk_param(struct hns3_hw *hw,
        for (i = 0; i < nb_mc_addr; i++) {
                addr = &mc_addr_set[i];
                if (!rte_is_multicast_ether_addr(addr)) {
-                       rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              addr);
                        hns3_err(hw,
                                 "failed to set mc mac addr, addr(%s) invalid.",
@@ -465,7 +450,7 @@ hns3vf_set_mc_addr_chk_param(struct hns3_hw *hw,
                /* Check if there are duplicate addresses */
                for (j = i + 1; j < nb_mc_addr; j++) {
                        if (rte_is_same_ether_addr(addr, &mc_addr_set[j])) {
-                               rte_ether_format_addr(mac_str,
+                               hns3_ether_format_addr(mac_str,
                                                      RTE_ETHER_ADDR_FMT_SIZE,
                                                      addr);
                                hns3_err(hw, "failed to set mc mac addr, "
@@ -482,7 +467,7 @@ hns3vf_set_mc_addr_chk_param(struct hns3_hw *hw,
                for (j = 0; j < HNS3_VF_UC_MACADDR_NUM; j++) {
                        if (rte_is_same_ether_addr(addr,
                                                   &hw->data->mac_addrs[j])) {
-                               rte_ether_format_addr(mac_str,
+                               hns3_ether_format_addr(mac_str,
                                                      RTE_ETHER_ADDR_FMT_SIZE,
                                                      addr);
                                hns3_err(hw, "failed to set mc mac addr, "
@@ -565,7 +550,7 @@ hns3vf_configure_all_mc_mac_addr(struct hns3_adapter *hns, bool del)
                        ret = hns3vf_add_mc_mac_addr(hw, addr);
                if (ret) {
                        err = ret;
-                       rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              addr);
                        hns3_err(hw, "Failed to %s mc mac addr: %s for vf: %d",
                                 del ? "Remove" : "Restore", mac_str, ret);
@@ -721,7 +706,7 @@ hns3vf_bind_ring_with_vector(struct hns3_hw *hw, uint8_t vector_id,
        ret = hns3_send_mbx_msg(hw, code, 0, (uint8_t *)&bind_msg,
                                sizeof(bind_msg), false, NULL, 0);
        if (ret)
-               hns3_err(hw, "%s TQP %d fail, vector_id is %d, ret is %d.",
+               hns3_err(hw, "%s TQP %u fail, vector_id is %u, ret is %d.",
                         op_str, queue_id, bind_msg.vector_id, ret);
 
        return ret;
@@ -767,7 +752,7 @@ hns3vf_init_ring_with_vector(struct hns3_hw *hw)
                                                   HNS3_RING_TYPE_TX, i);
                if (ret) {
                        PMD_INIT_LOG(ERR, "VF fail to unbind TX ring(%d) with "
-                                         "vector: %d, ret=%d", i, vec, ret);
+                                         "vector: %u, ret=%d", i, vec, ret);
                        return ret;
                }
 
@@ -775,7 +760,7 @@ hns3vf_init_ring_with_vector(struct hns3_hw *hw)
                                                   HNS3_RING_TYPE_RX, i);
                if (ret) {
                        PMD_INIT_LOG(ERR, "VF fail to unbind RX ring(%d) with "
-                                         "vector: %d, ret=%d", i, vec, ret);
+                                         "vector: %u, ret=%d", i, vec, ret);
                        return ret;
                }
        }
@@ -788,7 +773,6 @@ hns3vf_dev_configure(struct rte_eth_dev *dev)
 {
        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;
        uint16_t nb_rx_q = dev->data->nb_rx_queues;
@@ -831,11 +815,6 @@ hns3vf_dev_configure(struct rte_eth_dev *dev)
                conf->rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
                hw->rss_dis_flag = false;
                rss_conf = conf->rx_adv_conf.rss_conf;
-               if (rss_conf.rss_key == NULL) {
-                       rss_conf.rss_key = rss_cfg->key;
-                       rss_conf.rss_key_len = HNS3_RSS_KEY_SIZE;
-               }
-
                ret = hns3_dev_rss_hash_update(dev, &rss_conf);
                if (ret)
                        goto cfg_err;
@@ -913,7 +892,7 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
         * MTU value issued by hns3 VF PMD driver must be less than or equal to
         * PF's MTU.
         */
-       if (rte_atomic16_read(&hw->reset.resetting)) {
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) {
                hns3_err(hw, "Failed to set mtu during resetting");
                return -EIO;
        }
@@ -943,7 +922,7 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
                rte_spinlock_unlock(&hw->lock);
                return ret;
        }
-       if (frame_size > RTE_ETHER_MAX_LEN)
+       if (mtu > RTE_ETHER_MTU)
                dev->data->dev_conf.rxmode.offloads |=
                                                DEV_RX_OFFLOAD_JUMBO_FRAME;
        else
@@ -1350,7 +1329,7 @@ hns3vf_get_tc_info(struct hns3_hw *hw)
 {
        uint8_t resp_msg;
        int ret;
-       int i;
+       uint32_t i;
 
        ret = hns3_send_mbx_msg(hw, HNS3_MBX_GET_TCINFO, 0, NULL, 0,
                                true, &resp_msg, sizeof(resp_msg));
@@ -1433,13 +1412,13 @@ hns3vf_set_tc_queue_mapping(struct hns3_adapter *hns, uint16_t nb_rx_q,
        struct hns3_hw *hw = &hns->hw;
 
        if (nb_rx_q < hw->num_tc) {
-               hns3_err(hw, "number of Rx queues(%d) is less than tcs(%d).",
+               hns3_err(hw, "number of Rx queues(%u) is less than tcs(%u).",
                         nb_rx_q, hw->num_tc);
                return -EINVAL;
        }
 
        if (nb_tx_q < hw->num_tc) {
-               hns3_err(hw, "number of Tx queues(%d) is less than tcs(%d).",
+               hns3_err(hw, "number of Tx queues(%u) is less than tcs(%u).",
                         nb_tx_q, hw->num_tc);
                return -EINVAL;
        }
@@ -1453,7 +1432,7 @@ hns3vf_request_link_info(struct hns3_hw *hw)
        uint8_t resp_msg;
        int ret;
 
-       if (rte_atomic16_read(&hw->reset.resetting))
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED))
                return;
        ret = hns3_send_mbx_msg(hw, HNS3_MBX_GET_LINK_STATUS, 0, NULL, 0, false,
                                &resp_msg, sizeof(resp_msg));
@@ -1486,7 +1465,7 @@ hns3vf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
        struct hns3_hw *hw = &hns->hw;
        int ret;
 
-       if (rte_atomic16_read(&hw->reset.resetting)) {
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) {
                hns3_err(hw,
                         "vf set vlan id failed during resetting, vlan_id =%u",
                         vlan_id);
@@ -1525,7 +1504,7 @@ hns3vf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
        unsigned int tmp_mask;
        int ret = 0;
 
-       if (rte_atomic16_read(&hw->reset.resetting)) {
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) {
                hns3_err(hw, "vf set vlan offload failed during resetting, "
                             "mask = 0x%x", mask);
                return -EIO;
@@ -1764,7 +1743,6 @@ hns3vf_init_hardware(struct hns3_adapter *hns)
                goto err_init_hardware;
        }
 
-       hns3vf_request_link_info(hw);
        return 0;
 
 err_init_hardware:
@@ -1972,7 +1950,7 @@ hns3vf_dev_stop(struct rte_eth_dev *dev)
        rte_delay_ms(hw->tqps_num);
 
        rte_spinlock_lock(&hw->lock);
-       if (rte_atomic16_read(&hw->reset.resetting) == 0) {
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED) == 0) {
                hns3_stop_tqps(hw);
                hns3vf_do_stop(hns);
                hns3vf_unmap_rx_interrupt(dev);
@@ -2011,7 +1989,7 @@ hns3vf_dev_close(struct rte_eth_dev *eth_dev)
        rte_free(eth_dev->process_private);
        eth_dev->process_private = NULL;
        hns3_mp_uninit_primary();
-       hns3_warn(hw, "Close port %d finished", hw->data->port_id);
+       hns3_warn(hw, "Close port %u finished", hw->data->port_id);
 
        return ret;
 }
@@ -2126,7 +2104,7 @@ hns3vf_map_rx_interrupt(struct rte_eth_dev *dev)
                        rte_zmalloc("intr_vec",
                                    hw->used_rx_queues * sizeof(int), 0);
                if (intr_handle->intr_vec == NULL) {
-                       hns3_err(hw, "Failed to allocate %d rx_queues"
+                       hns3_err(hw, "Failed to allocate %u rx_queues"
                                     " intr_vec", hw->used_rx_queues);
                        ret = -ENOMEM;
                        goto vf_alloc_intr_vec_error;
@@ -2203,7 +2181,7 @@ hns3vf_dev_start(struct rte_eth_dev *dev)
        int ret;
 
        PMD_INIT_FUNC_TRACE();
-       if (rte_atomic16_read(&hw->reset.resetting))
+       if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED))
                return -EBUSY;
 
        rte_spinlock_lock(&hw->lock);
@@ -2253,7 +2231,7 @@ hns3vf_dev_start(struct rte_eth_dev *dev)
        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);
+       hns3vf_service_handler(dev);
 
        hns3vf_restore_filter(dev);
 
@@ -2438,6 +2416,11 @@ hns3vf_start_service(struct hns3_adapter *hns)
 
                /* Enable interrupt of all rx queues before enabling queues */
                hns3_dev_all_rx_queue_intr_enable(hw, true);
+               /*
+                * Enable state of each rxq and txq will be recovered after
+                * reset, so we need to restore them before enable all tqps;
+                */
+               hns3_restore_tqp_enable_state(hw);
                /*
                 * When finished the initialization, enable queues to receive
                 * and transmit packets.
@@ -2478,7 +2461,7 @@ hns3vf_check_default_mac_change(struct hns3_hw *hw)
                ret = rte_is_same_ether_addr(&hw->data->mac_addrs[0], hw_mac);
                if (!ret) {
                        rte_ether_addr_copy(hw_mac, &hw->data->mac_addrs[0]);
-                       rte_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
                                              &hw->data->mac_addrs[0]);
                        hns3_warn(hw, "Default MAC address has been changed to:"
                                  " %s by the host PF kernel ethdev driver",
@@ -2763,8 +2746,6 @@ hns3vf_dev_init(struct rte_eth_dev *eth_dev)
                return 0;
        }
 
-       eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-
        ret = hns3_mp_init_primary();
        if (ret) {
                PMD_INIT_LOG(ERR,
@@ -2887,7 +2868,7 @@ eth_hns3vf_pci_remove(struct rte_pci_device *pci_dev)
 static const struct rte_pci_id pci_id_hns3vf_map[] = {
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_100G_VF) },
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_HUAWEI, HNS3_DEV_ID_100G_RDMA_PFC_VF) },
-       { .vendor_id = 0, /* sentinel */ },
+       { .vendor_id = 0, }, /* sentinel */
 };
 
 static struct rte_pci_driver rte_hns3vf_pmd = {