From: Peng Zhang <peng.zh...@corigine.com> Extract the 'total_phyports' data field into the 'pf_dev' structure, make it also valid for the flower firmware.
Signed-off-by: Peng Zhang <peng.zh...@corigine.com> Reviewed-by: Chaoyong He <chaoyong...@corigine.com> Reviewed-by: Long Wu <long...@corigine.com> --- .../net/nfp/flower/nfp_flower_representor.c | 8 +- drivers/net/nfp/nfp_ethdev.c | 75 +++++++++++-------- drivers/net/nfp/nfp_net_common.h | 3 +- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c index 1f34c4c263..a845253b01 100644 --- a/drivers/net/nfp/flower/nfp_flower_representor.c +++ b/drivers/net/nfp/flower/nfp_flower_representor.c @@ -917,7 +917,6 @@ nfp_flower_repr_create(struct nfp_app_fw_flower *app_fw_flower, int ret; struct nfp_pf_dev *pf_dev; struct rte_pci_device *pci_dev; - struct nfp_eth_table *nfp_eth_table; struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 }; @@ -945,8 +944,7 @@ nfp_flower_repr_create(struct nfp_app_fw_flower *app_fw_flower, } /* There always exist phy repr */ - nfp_eth_table = pf_dev->nfp_eth_table; - if (eth_da.nb_representor_ports < nfp_eth_table->count + 1) { + if (eth_da.nb_representor_ports < pf_dev->total_phyports + 1) { PMD_INIT_LOG(ERR, "Should also create repr port for phy port and PF vNIC."); return -ERANGE; } @@ -958,9 +956,9 @@ nfp_flower_repr_create(struct nfp_app_fw_flower *app_fw_flower, } /* Fill in flower app with repr counts */ - app_fw_flower->num_phyport_reprs = (uint8_t)nfp_eth_table->count; + app_fw_flower->num_phyport_reprs = pf_dev->total_phyports; app_fw_flower->num_vf_reprs = eth_da.nb_representor_ports - - nfp_eth_table->count - 1; + pf_dev->total_phyports - 1; PMD_INIT_LOG(INFO, "%d number of VF reprs", app_fw_flower->num_vf_reprs); PMD_INIT_LOG(INFO, "%d number of phyport reprs", app_fw_flower->num_phyport_reprs); diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c index 469fa4602e..06811c7673 100644 --- a/drivers/net/nfp/nfp_ethdev.c +++ b/drivers/net/nfp/nfp_ethdev.c @@ -724,7 +724,7 @@ nfp_net_close(struct rte_eth_dev *dev) nfp_cleanup_port_app_fw_nic(pf_dev, hw->idx, dev); - for (i = 0; i < app_fw_nic->total_phyports; i++) { + for (i = 0; i < pf_dev->total_phyports; i++) { id = nfp_function_id_get(pf_dev, i); /* Check to see if ports are still in use */ @@ -1492,18 +1492,52 @@ nfp_enable_multi_pf(struct nfp_pf_dev *pf_dev) return err; } +static bool +nfp_app_fw_nic_total_phyports_check(struct nfp_pf_dev *pf_dev) +{ + int ret; + uint8_t id; + uint8_t total_phyports; + char vnic_name[RTE_ETH_NAME_MAX_LEN]; + + /* Read the number of vNIC's created for the PF */ + id = nfp_function_id_get(pf_dev, 0); + snprintf(vnic_name, sizeof(vnic_name), "nfd_cfg_pf%u_num_ports", id); + total_phyports = nfp_rtsym_read_le(pf_dev->sym_tbl, vnic_name, &ret); + if (ret != 0 || total_phyports == 0 || total_phyports > 8) { + PMD_INIT_LOG(ERR, "%s symbol with wrong value", vnic_name); + return false; + } + + if (pf_dev->multi_pf.enabled) { + if (!nfp_check_multi_pf_from_fw(total_phyports)) { + PMD_INIT_LOG(ERR, "NSP report multipf, but FW report not multipf"); + return false; + } + } else { + /* + * For single PF the number of vNICs exposed should be the same as the + * number of physical ports. + */ + if (total_phyports != pf_dev->nfp_eth_table->count) { + PMD_INIT_LOG(ERR, "Total physical ports do not match number of vNICs"); + return false; + } + } + + return true; +} + static int nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv) { uint8_t i; uint8_t id; int ret = 0; - uint32_t total_vnics; struct nfp_app_fw_nic *app_fw_nic; struct nfp_eth_table *nfp_eth_table; char bar_name[RTE_ETH_NAME_MAX_LEN]; char port_name[RTE_ETH_NAME_MAX_LEN]; - char vnic_name[RTE_ETH_NAME_MAX_LEN]; struct nfp_pf_dev *pf_dev = hw_priv->pf_dev; struct nfp_net_init hw_init = { .hw_priv = hw_priv, @@ -1521,42 +1555,20 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv) /* Point the app_fw_priv pointer in the PF to the coreNIC app */ pf_dev->app_fw_priv = app_fw_nic; - /* Read the number of vNIC's created for the PF */ - snprintf(vnic_name, sizeof(vnic_name), "nfd_cfg_pf%u_num_ports", id); - total_vnics = nfp_rtsym_read_le(pf_dev->sym_tbl, vnic_name, &ret); - if (ret != 0 || total_vnics == 0 || total_vnics > 8) { - PMD_INIT_LOG(ERR, "%s symbol with wrong value", vnic_name); + /* Check the number of vNIC's created for the PF */ + if (!nfp_app_fw_nic_total_phyports_check(pf_dev)) { ret = -ENODEV; goto app_cleanup; } - if (pf_dev->multi_pf.enabled) { - if (!nfp_check_multi_pf_from_fw(total_vnics)) { - PMD_INIT_LOG(ERR, "NSP report multipf, but FW report not multipf"); - ret = -ENODEV; - goto app_cleanup; - } - } else { - /* - * For coreNIC the number of vNICs exposed should be the same as the - * number of physical ports. - */ - if (total_vnics != nfp_eth_table->count) { - PMD_INIT_LOG(ERR, "Total physical ports do not match number of vNICs"); - ret = -ENODEV; - goto app_cleanup; - } - } - /* Populate coreNIC app properties */ - app_fw_nic->total_phyports = total_vnics; - if (total_vnics > 1) + if (pf_dev->total_phyports > 1) app_fw_nic->multiport = true; /* Map the symbol table */ snprintf(bar_name, sizeof(bar_name), "_pf%u_net_bar0", id); pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, bar_name, - app_fw_nic->total_phyports * NFP_NET_CFG_BAR_SZ, + pf_dev->total_phyports * NFP_NET_CFG_BAR_SZ, &pf_dev->ctrl_area); if (pf_dev->ctrl_bar == NULL) { PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for %s", bar_name); @@ -1567,7 +1579,7 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv) PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar); /* Loop through all physical ports on PF */ - for (i = 0; i < app_fw_nic->total_phyports; i++) { + for (i = 0; i < pf_dev->total_phyports; i++) { if (pf_dev->multi_pf.enabled) snprintf(port_name, sizeof(port_name), "%s", pf_dev->pci_dev->device.name); @@ -1589,7 +1601,7 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv) return 0; port_cleanup: - for (i = 0; i < app_fw_nic->total_phyports; i++) { + for (i = 0; i < pf_dev->total_phyports; i++) { struct rte_eth_dev *eth_dev; if (pf_dev->multi_pf.enabled) @@ -1961,6 +1973,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev) pf_dev->pci_dev = pci_dev; pf_dev->nfp_eth_table = nfp_eth_table; pf_dev->sync = sync; + pf_dev->total_phyports = nfp_net_get_port_num(pf_dev, nfp_eth_table); ret = nfp_net_speed_cap_get(pf_dev); if (ret != 0) { diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h index cbf96e5ab5..5c48b94d38 100644 --- a/drivers/net/nfp/nfp_net_common.h +++ b/drivers/net/nfp/nfp_net_common.h @@ -140,6 +140,8 @@ struct nfp_pf_dev { /** NFP devarg param */ struct nfp_devargs devargs; + + uint8_t total_phyports; }; #define NFP_NET_FLOW_LIMIT 1024 @@ -159,7 +161,6 @@ struct nfp_app_fw_nic { struct nfp_net_hw *ports[NFP_MAX_PHYPORTS]; bool multiport; - uint8_t total_phyports; }; struct nfp_net_hw_priv { -- 2.39.1