ethdev: return diagnostic when setting MAC address
[dpdk.git] / drivers / net / i40e / i40e_ethdev.c
index 8580331..180ac74 100644 (file)
@@ -369,7 +369,7 @@ static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
 static int i40e_get_eeprom(struct rte_eth_dev *dev,
                           struct rte_dev_eeprom_info *eeprom);
 
-static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
+static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
                                      struct ether_addr *mac_addr);
 
 static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
@@ -3212,7 +3212,6 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        struct i40e_vsi *vsi = pf->main_vsi;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 
-       dev_info->pci_dev = pci_dev;
        dev_info->max_rx_queues = vsi->nb_qps;
        dev_info->max_tx_queues = vsi->nb_qps;
        dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
@@ -3297,15 +3296,42 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
                dev_info->max_tx_queues += dev_info->vmdq_queue_num;
        }
 
-       if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types))
+       if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
                /* For XL710 */
                dev_info->speed_capa = ETH_LINK_SPEED_40G;
-       else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types))
+               dev_info->default_rxportconf.nb_queues = 2;
+               dev_info->default_txportconf.nb_queues = 2;
+               if (dev->data->nb_rx_queues == 1)
+                       dev_info->default_rxportconf.ring_size = 2048;
+               else
+                       dev_info->default_rxportconf.ring_size = 1024;
+               if (dev->data->nb_tx_queues == 1)
+                       dev_info->default_txportconf.ring_size = 1024;
+               else
+                       dev_info->default_txportconf.ring_size = 512;
+
+       } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
                /* For XXV710 */
                dev_info->speed_capa = ETH_LINK_SPEED_25G;
-       else
+               dev_info->default_rxportconf.nb_queues = 1;
+               dev_info->default_txportconf.nb_queues = 1;
+               dev_info->default_rxportconf.ring_size = 256;
+               dev_info->default_txportconf.ring_size = 256;
+       } else {
                /* For X710 */
                dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
+               dev_info->default_rxportconf.nb_queues = 1;
+               dev_info->default_txportconf.nb_queues = 1;
+               if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_10G) {
+                       dev_info->default_rxportconf.ring_size = 512;
+                       dev_info->default_txportconf.ring_size = 256;
+               } else {
+                       dev_info->default_rxportconf.ring_size = 256;
+                       dev_info->default_txportconf.ring_size = 256;
+               }
+       }
+       dev_info->default_rxportconf.burst_size = 32;
+       dev_info->default_txportconf.burst_size = 32;
 }
 
 static int
@@ -11301,8 +11327,8 @@ static int i40e_get_eeprom(struct rte_eth_dev *dev,
        return 0;
 }
 
-static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
-                                     struct ether_addr *mac_addr)
+static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
+                                    struct ether_addr *mac_addr)
 {
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
@@ -11313,7 +11339,7 @@ static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 
        if (!is_valid_assigned_ether_addr(mac_addr)) {
                PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
-               return;
+               return -EINVAL;
        }
 
        TAILQ_FOREACH(f, &vsi->mac_list, next) {
@@ -11323,25 +11349,31 @@ static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 
        if (f == NULL) {
                PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
-               return;
+               return -EIO;
        }
 
        mac_filter = f->mac_info;
        ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
        if (ret != I40E_SUCCESS) {
                PMD_DRV_LOG(ERR, "Failed to delete mac filter");
-               return;
+               return -EIO;
        }
        memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
        ret = i40e_vsi_add_mac(vsi, &mac_filter);
        if (ret != I40E_SUCCESS) {
                PMD_DRV_LOG(ERR, "Failed to add mac filter");
-               return;
+               return -EIO;
        }
        memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
 
-       i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
-                                 mac_addr->addr_bytes, NULL);
+       ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
+                                       mac_addr->addr_bytes, NULL);
+       if (ret != I40E_SUCCESS) {
+               PMD_DRV_LOG(ERR, "Failed to change mac");
+               return -EIO;
+       }
+
+       return 0;
 }
 
 static int
@@ -11510,7 +11542,8 @@ i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
 static int
 i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
                              uint32_t pkg_size, uint32_t proto_num,
-                             struct rte_pmd_i40e_proto_info *proto)
+                             struct rte_pmd_i40e_proto_info *proto,
+                             enum rte_pmd_i40e_package_op op)
 {
        struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
        uint32_t pctype_num;
@@ -11523,6 +11556,12 @@ i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
        uint32_t i, j, n;
        int ret;
 
+       if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
+           op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
+               PMD_DRV_LOG(ERR, "Unsupported operation.");
+               return -1;
+       }
+
        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
                                (uint8_t *)&pctype_num, sizeof(pctype_num),
                                RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
@@ -11585,8 +11624,13 @@ i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
                                i40e_find_customized_pctype(pf,
                                                      I40E_CUSTOMIZED_GTPU);
                if (new_pctype) {
-                       new_pctype->pctype = pctype_value;
-                       new_pctype->valid = true;
+                       if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
+                               new_pctype->pctype = pctype_value;
+                               new_pctype->valid = true;
+                       } else {
+                               new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
+                               new_pctype->valid = false;
+                       }
                }
        }
 
@@ -11596,8 +11640,9 @@ i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
 
 static int
 i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
-                              uint32_t pkg_size, uint32_t proto_num,
-                              struct rte_pmd_i40e_proto_info *proto)
+                            uint32_t pkg_size, uint32_t proto_num,
+                            struct rte_pmd_i40e_proto_info *proto,
+                            enum rte_pmd_i40e_package_op op)
 {
        struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
        uint16_t port_id = dev->data->port_id;
@@ -11610,6 +11655,17 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
        bool in_tunnel;
        int ret;
 
+       if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
+           op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
+               PMD_DRV_LOG(ERR, "Unsupported operation.");
+               return -1;
+       }
+
+       if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
+               rte_pmd_i40e_ptype_mapping_reset(port_id);
+               return 0;
+       }
+
        /* get information about new ptype num */
        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
                                (uint8_t *)&ptype_num, sizeof(ptype_num),
@@ -11782,7 +11838,7 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
 
 void
 i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
-                             uint32_t pkg_size)
+                           uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
 {
        struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
        uint32_t proto_num;
@@ -11791,6 +11847,12 @@ i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
        uint32_t i;
        int ret;
 
+       if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
+           op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
+               PMD_DRV_LOG(ERR, "Unsupported operation.");
+               return;
+       }
+
        /* get information about protocol number */
        ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
                                       (uint8_t *)&proto_num, sizeof(proto_num),
@@ -11824,20 +11886,23 @@ i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
        /* Check if GTP is supported. */
        for (i = 0; i < proto_num; i++) {
                if (!strncmp(proto[i].name, "GTP", 3)) {
-                       pf->gtp_support = true;
+                       if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
+                               pf->gtp_support = true;
+                       else
+                               pf->gtp_support = false;
                        break;
                }
        }
 
        /* Update customized pctype info */
        ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
-                                           proto_num, proto);
+                                           proto_num, proto, op);
        if (ret)
                PMD_DRV_LOG(INFO, "No pctype is updated.");
 
        /* Update customized ptype info */
        ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
-                                          proto_num, proto);
+                                          proto_num, proto, op);
        if (ret)
                PMD_DRV_LOG(INFO, "No ptype is updated.");