common/cnxk: convert warning to debug print
[dpdk.git] / drivers / net / hns3 / hns3_common.c
index eac2aa1..dcdc609 100644 (file)
@@ -216,7 +216,7 @@ hns3_parse_mbx_time_limit(const char *key, const char *value, void *extra_args)
 
        /*
         * 500ms is empirical value in process of mailbox communication. If
-        * the delay value is set to one lower thanthe empirical value, mailbox
+        * the delay value is set to one lower than the empirical value, mailbox
         * communication may fail.
         */
        if (val > HNS3_MBX_DEF_TIME_LIMIT_MS && val <= UINT16_MAX)
@@ -236,6 +236,12 @@ hns3_parse_devargs(struct rte_eth_dev *dev)
        uint64_t dev_caps_mask = 0;
        struct rte_kvargs *kvlist;
 
+       /* Set default value of runtime config parameters. */
+       hns->rx_func_hint = HNS3_IO_FUNC_HINT_NONE;
+       hns->tx_func_hint = HNS3_IO_FUNC_HINT_NONE;
+       hns->dev_caps_mask = 0;
+       hns->mbx_time_limit_ms = HNS3_MBX_DEF_TIME_LIMIT_MS;
+
        if (dev->device->devargs == NULL)
                return;
 
@@ -581,6 +587,60 @@ hns3_remove_mac_addr(struct rte_eth_dev *dev, uint32_t idx)
        }
 }
 
+int
+hns3_init_mac_addrs(struct rte_eth_dev *dev)
+{
+       struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
+       const char *memory_name = hns->is_vf ? "hns3vf-mac" : "hns3-mac";
+       uint16_t mac_addrs_capa = hns->is_vf ? HNS3_VF_UC_MACADDR_NUM :
+                                               HNS3_UC_MACADDR_NUM;
+       char mac_str[RTE_ETHER_ADDR_FMT_SIZE];
+       struct rte_ether_addr *eth_addr;
+
+       /* Allocate memory for storing MAC addresses */
+       dev->data->mac_addrs = rte_zmalloc(memory_name,
+                               sizeof(struct rte_ether_addr) * mac_addrs_capa,
+                               0);
+       if (dev->data->mac_addrs == NULL) {
+               hns3_err(hw, "failed to allocate %zx bytes needed to store MAC addresses",
+                            sizeof(struct rte_ether_addr) * mac_addrs_capa);
+               return -ENOMEM;
+       }
+
+       eth_addr = (struct rte_ether_addr *)hw->mac.mac_addr;
+       if (!hns->is_vf) {
+               if (!rte_is_valid_assigned_ether_addr(eth_addr)) {
+                       rte_eth_random_addr(hw->mac.mac_addr);
+                       hns3_ether_format_addr(mac_str, RTE_ETHER_ADDR_FMT_SIZE,
+                               (struct rte_ether_addr *)hw->mac.mac_addr);
+                       hns3_warn(hw, "default mac_addr from firmware is an invalid "
+                                 "unicast address, using random MAC address %s",
+                                 mac_str);
+               }
+       } else {
+               /*
+                * 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(eth_addr))
+                       rte_eth_random_addr(hw->mac.mac_addr);
+       }
+
+       rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.mac_addr,
+                           &dev->data->mac_addrs[0]);
+
+       return 0;
+}
+
 int
 hns3_init_ring_with_vector(struct hns3_hw *hw)
 {
@@ -603,7 +663,7 @@ hns3_init_ring_with_vector(struct hns3_hw *hw)
        hw->intr_tqps_num = RTE_MIN(vec, hw->tqps_num);
        for (i = 0; i < hw->intr_tqps_num; i++) {
                /*
-                * Set gap limiter/rate limiter/quanity limiter algorithm
+                * Set gap limiter/rate limiter/quantity limiter algorithm
                 * configuration for interrupt coalesce of queue's interrupt.
                 */
                hns3_set_queue_intr_gl(hw, i, HNS3_RING_GL_RX,
@@ -761,3 +821,25 @@ hns3_restore_rx_interrupt(struct hns3_hw *hw)
 
        return 0;
 }
+
+int
+hns3_get_pci_revision_id(struct hns3_hw *hw, uint8_t *revision_id)
+{
+       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);
+       ret = rte_pci_read_config(pci_dev, &revision, HNS3_PCI_REVISION_ID_LEN,
+                                 HNS3_PCI_REVISION_ID);
+       if (ret != HNS3_PCI_REVISION_ID_LEN) {
+               hns3_err(hw, "failed to read pci revision id, ret = %d", ret);
+               return -EIO;
+       }
+
+       *revision_id = revision;
+
+       return 0;
+}