net/atlantic: fix reported flow control mode
[dpdk.git] / drivers / net / atlantic / atl_ethdev.c
index 4e6124a..d5c2ec5 100644 (file)
@@ -24,10 +24,10 @@ static int  atl_dev_set_link_up(struct rte_eth_dev *dev);
 static int  atl_dev_set_link_down(struct rte_eth_dev *dev);
 static void atl_dev_close(struct rte_eth_dev *dev);
 static int  atl_dev_reset(struct rte_eth_dev *dev);
-static void atl_dev_promiscuous_enable(struct rte_eth_dev *dev);
-static void atl_dev_promiscuous_disable(struct rte_eth_dev *dev);
-static void atl_dev_allmulticast_enable(struct rte_eth_dev *dev);
-static void atl_dev_allmulticast_disable(struct rte_eth_dev *dev);
+static int  atl_dev_promiscuous_enable(struct rte_eth_dev *dev);
+static int  atl_dev_promiscuous_disable(struct rte_eth_dev *dev);
+static int atl_dev_allmulticast_enable(struct rte_eth_dev *dev);
+static int atl_dev_allmulticast_disable(struct rte_eth_dev *dev);
 static int  atl_dev_link_update(struct rte_eth_dev *dev, int wait);
 
 static int atl_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
@@ -40,14 +40,11 @@ static int atl_dev_stats_get(struct rte_eth_dev *dev,
 static int atl_dev_xstats_get(struct rte_eth_dev *dev,
                              struct rte_eth_xstat *stats, unsigned int n);
 
-static void atl_dev_stats_reset(struct rte_eth_dev *dev);
+static int atl_dev_stats_reset(struct rte_eth_dev *dev);
 
 static int atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
                              size_t fw_size);
 
-static void atl_dev_info_get(struct rte_eth_dev *dev,
-                              struct rte_eth_dev_info *dev_info);
-
 static const uint32_t *atl_dev_supported_ptypes_get(struct rte_eth_dev *dev);
 
 static int atl_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
@@ -93,14 +90,14 @@ static void atl_dev_interrupt_handler(void *param);
 
 
 static int atl_add_mac_addr(struct rte_eth_dev *dev,
-                           struct ether_addr *mac_addr,
+                           struct rte_ether_addr *mac_addr,
                            uint32_t index, uint32_t pool);
 static void atl_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
 static int atl_set_default_mac_addr(struct rte_eth_dev *dev,
-                                          struct ether_addr *mac_addr);
+                                          struct rte_ether_addr *mac_addr);
 
 static int atl_dev_set_mc_addr_list(struct rte_eth_dev *dev,
-                                   struct ether_addr *mc_addr_set,
+                                   struct rte_ether_addr *mc_addr_set,
                                    uint32_t nb_mc_addr);
 
 /* RSS */
@@ -120,7 +117,7 @@ static int eth_atl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        struct rte_pci_device *pci_dev);
 static int eth_atl_pci_remove(struct rte_pci_device *pci_dev);
 
-static void atl_dev_info_get(struct rte_eth_dev *dev,
+static int atl_dev_info_get(struct rte_eth_dev *dev,
                                struct rte_eth_dev_info *dev_info);
 
 int atl_logtype_init;
@@ -157,8 +154,7 @@ static const struct rte_pci_id pci_id_atl_map[] = {
 
 static struct rte_pci_driver rte_atl_pmd = {
        .id_table = pci_id_atl_map,
-       .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
-                    RTE_PCI_DRV_IOVA_AS_VA,
+       .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
        .probe = eth_atl_pci_probe,
        .remove = eth_atl_pci_remove,
 };
@@ -179,6 +175,8 @@ static struct rte_pci_driver rte_atl_pmd = {
                        | DEV_TX_OFFLOAD_MACSEC_INSERT \
                        | DEV_TX_OFFLOAD_MULTI_SEGS)
 
+#define SFP_EEPROM_SIZE 0x100
+
 static const struct rte_eth_desc_lim rx_desc_lim = {
        .nb_max = ATL_MAX_RING_DESC,
        .nb_min = ATL_MIN_RING_DESC,
@@ -369,8 +367,7 @@ atl_disable_intr(struct aq_hw_s *hw)
 static int
 eth_atl_dev_init(struct rte_eth_dev *eth_dev)
 {
-       struct atl_adapter *adapter =
-               (struct atl_adapter *)eth_dev->data->dev_private;
+       struct atl_adapter *adapter = eth_dev->data->dev_private;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
@@ -414,7 +411,8 @@ eth_atl_dev_init(struct rte_eth_dev *eth_dev)
        atl_disable_intr(hw);
 
        /* Allocate memory for storing MAC addresses */
-       eth_dev->data->mac_addrs = rte_zmalloc("atlantic", ETHER_ADDR_LEN, 0);
+       eth_dev->data->mac_addrs = rte_zmalloc("atlantic",
+                                       RTE_ETHER_ADDR_LEN, 0);
        if (eth_dev->data->mac_addrs == NULL) {
                PMD_INIT_LOG(ERR, "MAC Malloc failed");
                return -ENOMEM;
@@ -600,9 +598,6 @@ atl_dev_start(struct rte_eth_dev *dev)
 
        dev->data->dev_link.link_status = hw->aq_link_status.mbps != 0;
 
-       if (err)
-               goto error;
-
        if (rte_intr_allow_others(intr_handle)) {
                /* check if lsc interrupt is enabled */
                if (dev->data->dev_conf.intr_conf.lsc != 0)
@@ -898,7 +893,8 @@ int atl_macsec_config_txsc(struct rte_eth_dev *dev, uint8_t *mac)
                ATL_DEV_PRIVATE_TO_CFG(dev->data->dev_private);
 
        memset(&cfg->aq_macsec.txsc.mac, 0, sizeof(cfg->aq_macsec.txsc.mac));
-       memcpy((uint8_t *)&cfg->aq_macsec.txsc.mac + 2, mac, ETHER_ADDR_LEN);
+       memcpy((uint8_t *)&cfg->aq_macsec.txsc.mac + 2, mac,
+               RTE_ETHER_ADDR_LEN);
 
        return 0;
 }
@@ -910,7 +906,8 @@ int atl_macsec_config_rxsc(struct rte_eth_dev *dev,
                ATL_DEV_PRIVATE_TO_CFG(dev->data->dev_private);
 
        memset(&cfg->aq_macsec.rxsc.mac, 0, sizeof(cfg->aq_macsec.rxsc.mac));
-       memcpy((uint8_t *)&cfg->aq_macsec.rxsc.mac + 2, mac, ETHER_ADDR_LEN);
+       memcpy((uint8_t *)&cfg->aq_macsec.rxsc.mac + 2, mac,
+               RTE_ETHER_ADDR_LEN);
        cfg->aq_macsec.rxsc.pi = pi;
 
        return 0;
@@ -978,7 +975,7 @@ atl_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
        return 0;
 }
 
-static void
+static int
 atl_dev_stats_reset(struct rte_eth_dev *dev)
 {
        struct atl_adapter *adapter = ATL_DEV_TO_ADAPTER(dev);
@@ -990,6 +987,28 @@ atl_dev_stats_reset(struct rte_eth_dev *dev)
        memset(&hw->curr_stats, 0, sizeof(hw->curr_stats));
 
        memset(&adapter->sw_stats, 0, sizeof(adapter->sw_stats));
+
+       return 0;
+}
+
+static int
+atl_dev_xstats_get_count(struct rte_eth_dev *dev)
+{
+       struct atl_adapter *adapter =
+               (struct atl_adapter *)dev->data->dev_private;
+
+       struct aq_hw_s *hw = &adapter->hw;
+       unsigned int i, count = 0;
+
+       for (i = 0; i < RTE_DIM(atl_xstats_tbl); i++) {
+               if (atl_xstats_tbl[i].type == XSTATS_TYPE_MACSEC &&
+                       ((hw->caps_lo & BIT(CAPS_LO_MACSEC)) == 0))
+                       continue;
+
+               count++;
+       }
+
+       return count;
 }
 
 static int
@@ -998,32 +1017,34 @@ atl_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
                         unsigned int size)
 {
        unsigned int i;
+       unsigned int count = atl_dev_xstats_get_count(dev);
 
-       if (!xstats_names)
-               return RTE_DIM(atl_xstats_tbl);
-
-       for (i = 0; i < size && i < RTE_DIM(atl_xstats_tbl); i++)
-               strlcpy(xstats_names[i].name, atl_xstats_tbl[i].name,
-                       RTE_ETH_XSTATS_NAME_SIZE);
+       if (xstats_names) {
+               for (i = 0; i < size && i < count; i++) {
+                       snprintf(xstats_names[i].name,
+                               RTE_ETH_XSTATS_NAME_SIZE, "%s",
+                               atl_xstats_tbl[i].name);
+               }
+       }
 
-       return i;
+       return count;
 }
 
 static int
 atl_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
                   unsigned int n)
 {
-       struct atl_adapter *adapter =
-       (struct atl_adapter *)dev->data->dev_private;
+       struct atl_adapter *adapter = dev->data->dev_private;
        struct aq_hw_s *hw = &adapter->hw;
        struct get_stats req = { 0 };
        struct macsec_msg_fw_request msg = { 0 };
        struct macsec_msg_fw_response resp = { 0 };
        int err = -1;
        unsigned int i;
+       unsigned int count = atl_dev_xstats_get_count(dev);
 
        if (!stats)
-               return 0;
+               return count;
 
        if (hw->aq_fw_ops->send_macsec_req != NULL) {
                req.ingress_sa_index = 0xff;
@@ -1036,7 +1057,7 @@ atl_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
                err = hw->aq_fw_ops->send_macsec_req(hw, &msg, &resp);
        }
 
-       for (i = 0; i < n && i < RTE_DIM(atl_xstats_tbl); i++) {
+       for (i = 0; i < n && i < count; i++) {
                stats[i].id = i;
 
                switch (atl_xstats_tbl[i].type) {
@@ -1045,14 +1066,15 @@ atl_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
                                         atl_xstats_tbl[i].offset);
                        break;
                case XSTATS_TYPE_MACSEC:
-                       if (err)
-                               goto done;
-                       stats[i].value = *(u64 *)((uint8_t *)&resp.stats +
-                                        atl_xstats_tbl[i].offset);
+                       if (!err) {
+                               stats[i].value =
+                                       *(u64 *)((uint8_t *)&resp.stats +
+                                       atl_xstats_tbl[i].offset);
+                       }
                        break;
                }
        }
-done:
+
        return i;
 }
 
@@ -1078,7 +1100,7 @@ atl_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
        return 0;
 }
 
-static void
+static int
 atl_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
@@ -1119,6 +1141,8 @@ atl_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->speed_capa |= ETH_LINK_SPEED_100M;
        dev_info->speed_capa |= ETH_LINK_SPEED_2_5G;
        dev_info->speed_capa |= ETH_LINK_SPEED_5G;
+
+       return 0;
 }
 
 static const uint32_t *
@@ -1158,6 +1182,7 @@ atl_dev_link_update(struct rte_eth_dev *dev, int wait __rte_unused)
 {
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct rte_eth_link link, old;
+       u32 fc = AQ_NIC_FC_OFF;
        int err = 0;
 
        link.link_status = ETH_LINK_DOWN;
@@ -1192,6 +1217,15 @@ atl_dev_link_update(struct rte_eth_dev *dev, int wait __rte_unused)
        if (link.link_status == old.link_status)
                return -1;
 
+       /* Driver has to update flow control settings on RX block
+        * on any link event.
+        * We should query FW whether it negotiated FC.
+        */
+       if (hw->aq_fw_ops->get_flow_control) {
+               hw->aq_fw_ops->get_flow_control(hw, &fc);
+               hw_atl_b0_set_fc(hw, fc, 0U);
+       }
+
        if (rte_eal_alarm_set(1000 * 1000,
                              atl_dev_delayed_handler, (void *)dev) < 0)
                PMD_DRV_LOG(ERR, "rte_eal_alarm_set fail");
@@ -1199,39 +1233,47 @@ atl_dev_link_update(struct rte_eth_dev *dev, int wait __rte_unused)
        return 0;
 }
 
-static void
+static int
 atl_dev_promiscuous_enable(struct rte_eth_dev *dev)
 {
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        hw_atl_rpfl2promiscuous_mode_en_set(hw, true);
+
+       return 0;
 }
 
-static void
+static int
 atl_dev_promiscuous_disable(struct rte_eth_dev *dev)
 {
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        hw_atl_rpfl2promiscuous_mode_en_set(hw, false);
+
+       return 0;
 }
 
-static void
+static int
 atl_dev_allmulticast_enable(struct rte_eth_dev *dev)
 {
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        hw_atl_rpfl2_accept_all_mc_packets_set(hw, true);
+
+       return 0;
 }
 
-static void
+static int
 atl_dev_allmulticast_disable(struct rte_eth_dev *dev)
 {
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
        if (dev->data->promiscuous == 1)
-               return; /* must remain in all_multicast mode */
+               return 0; /* must remain in all_multicast mode */
 
        hw_atl_rpfl2_accept_all_mc_packets_set(hw, false);
+
+       return 0;
 }
 
 /**
@@ -1340,8 +1382,7 @@ atl_dev_interrupt_action(struct rte_eth_dev *dev,
 {
        struct atl_interrupt *intr =
                ATL_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
-       struct atl_adapter *adapter =
-               (struct atl_adapter *)dev->data->dev_private;
+       struct atl_adapter *adapter = dev->data->dev_private;
        struct aq_hw_s *hw = &adapter->hw;
 
        if (!(intr->flags & ATL_FLAG_NEED_LINK_UPDATE))
@@ -1385,7 +1426,7 @@ atl_dev_interrupt_action(struct rte_eth_dev *dev,
        }
 done:
        atl_enable_intr(dev);
-       rte_intr_enable(intr_handle);
+       rte_intr_ack(intr_handle);
 
        return 0;
 }
@@ -1411,7 +1452,6 @@ atl_dev_interrupt_handler(void *param)
        atl_dev_interrupt_action(dev, dev->intr_handle);
 }
 
-#define SFP_EEPROM_SIZE 0xff
 
 static int
 atl_dev_get_eeprom_length(struct rte_eth_dev *dev __rte_unused)
@@ -1432,6 +1472,9 @@ int atl_dev_get_eeprom(struct rte_eth_dev *dev,
            eeprom->data == NULL)
                return -EINVAL;
 
+       if (eeprom->magic > 0x7F)
+               return -EINVAL;
+
        if (eeprom->magic)
                dev_addr = eeprom->magic;
 
@@ -1448,14 +1491,18 @@ int atl_dev_set_eeprom(struct rte_eth_dev *dev,
        if (hw->aq_fw_ops->set_eeprom == NULL)
                return -ENOTSUP;
 
-       if (eeprom->length != SFP_EEPROM_SIZE || eeprom->data == NULL)
+       if (eeprom->length + eeprom->offset > SFP_EEPROM_SIZE ||
+           eeprom->data == NULL)
+               return -EINVAL;
+
+       if (eeprom->magic > 0x7F)
                return -EINVAL;
 
        if (eeprom->magic)
                dev_addr = eeprom->magic;
 
-       return hw->aq_fw_ops->set_eeprom(hw, dev_addr,
-                                        eeprom->data, eeprom->length);
+       return hw->aq_fw_ops->set_eeprom(hw, dev_addr, eeprom->data,
+                                        eeprom->length, eeprom->offset);
 }
 
 static int
@@ -1488,14 +1535,20 @@ static int
 atl_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
 {
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       u32 fc = AQ_NIC_FC_OFF;
+
+       if (hw->aq_fw_ops->get_flow_control == NULL)
+               return -ENOTSUP;
 
-       if (hw->aq_nic_cfg->flow_control == AQ_NIC_FC_OFF)
+       hw->aq_fw_ops->get_flow_control(hw, &fc);
+
+       if (fc == AQ_NIC_FC_OFF)
                fc_conf->mode = RTE_FC_NONE;
-       else if (hw->aq_nic_cfg->flow_control & (AQ_NIC_FC_RX | AQ_NIC_FC_TX))
+       else if ((fc & AQ_NIC_FC_RX) && (fc & AQ_NIC_FC_TX))
                fc_conf->mode = RTE_FC_FULL;
-       else if (hw->aq_nic_cfg->flow_control & AQ_NIC_FC_RX)
+       else if (fc & AQ_NIC_FC_RX)
                fc_conf->mode = RTE_FC_RX_PAUSE;
-       else if (hw->aq_nic_cfg->flow_control & AQ_NIC_FC_RX)
+       else if (fc & AQ_NIC_FC_TX)
                fc_conf->mode = RTE_FC_TX_PAUSE;
 
        return 0;
@@ -1554,10 +1607,10 @@ atl_update_mac_addr(struct rte_eth_dev *dev, uint32_t index,
 }
 
 static int
-atl_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
+atl_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
                        uint32_t index __rte_unused, uint32_t pool __rte_unused)
 {
-       if (is_zero_ether_addr(mac_addr)) {
+       if (rte_is_zero_ether_addr(mac_addr)) {
                PMD_DRV_LOG(ERR, "Invalid Ethernet Address");
                return -EINVAL;
        }
@@ -1572,7 +1625,7 @@ atl_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
 }
 
 static int
-atl_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
+atl_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
 {
        atl_remove_mac_addr(dev, 0);
        atl_add_mac_addr(dev, addr, 0, 0);
@@ -1583,11 +1636,14 @@ static int
 atl_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 {
        struct rte_eth_dev_info dev_info;
-       uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
+       int ret;
+       uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
 
-       atl_dev_info_get(dev, &dev_info);
+       ret = atl_dev_info_get(dev, &dev_info);
+       if (ret != 0)
+               return ret;
 
-       if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
+       if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
                return -EINVAL;
 
        /* update max frame size */
@@ -1739,7 +1795,7 @@ atl_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue_id, int on)
 
 static int
 atl_dev_set_mc_addr_list(struct rte_eth_dev *dev,
-                         struct ether_addr *mc_addr_set,
+                         struct rte_ether_addr *mc_addr_set,
                          uint32_t nb_mc_addr)
 {
        struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -1879,4 +1935,3 @@ RTE_INIT(atl_init_log)
        if (atl_logtype_driver >= 0)
                rte_log_set_level(atl_logtype_driver, RTE_LOG_NOTICE);
 }
-