A new NIC is introduced with different configuration
BAR size other than 32K, and this is distinguished by
the application firmware's class version ABI.

Signed-off-by: Chaoyong He <chaoyong...@corigine.com>
Reviewed-by: Long Wu <long...@corigine.com>
---
 drivers/common/nfp/nfp_common_ctrl.h | 10 +++++++++-
 drivers/net/nfp/flower/nfp_flower.c  |  4 ++--
 drivers/net/nfp/nfp_ethdev.c         | 24 ++++++++++++++----------
 drivers/net/nfp/nfp_ethdev_vf.c      |  3 +++
 drivers/net/nfp/nfp_net_common.c     | 25 +++++++++++++++++++++++++
 drivers/net/nfp/nfp_net_common.h     |  3 +++
 drivers/net/nfp/nfp_net_ctrl.c       |  4 +++-
 7 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/drivers/common/nfp/nfp_common_ctrl.h 
b/drivers/common/nfp/nfp_common_ctrl.h
index 69596dd6f5..711577dc76 100644
--- a/drivers/common/nfp/nfp_common_ctrl.h
+++ b/drivers/common/nfp/nfp_common_ctrl.h
@@ -11,7 +11,9 @@
  *
  * On the NFP6000, due to THB-350, the configuration BAR is 32K in size.
  */
-#define NFP_NET_CFG_BAR_SZ              (32 * 1024)
+#define NFP_NET_CFG_BAR_SZ_32K          (32 * 1024)
+#define NFP_NET_CFG_BAR_SZ_8K           (8 * 1024)
+#define NFP_NET_CFG_BAR_SZ_MIN          NFP_NET_CFG_BAR_SZ_8K
 
 /*
  * Configuration sriov VF.
@@ -121,6 +123,10 @@
 struct nfp_net_fw_ver {
        uint8_t minor;
        uint8_t major;
+       /**
+        * BIT0: class, refer NFP_NET_CFG_VERSION_CLASS_*
+        * BIT[7:1]: reserved
+        */
        uint8_t class;
        /**
         * This byte can be extended for more use.
@@ -147,6 +153,8 @@ struct nfp_net_fw_ver {
 #define NFP_NET_CFG_VERSION             0x0030
 #define   NFP_NET_CFG_VERSION_DP_NFD3   0
 #define   NFP_NET_CFG_VERSION_DP_NFDK   1
+#define   NFP_NET_CFG_VERSION_CLASS_GENERIC    0
+#define   NFP_NET_CFG_VERSION_CLASS_NO_EMEM    1
 #define NFP_NET_CFG_STS                 0x0034
 #define   NFP_NET_CFG_STS_LINK            (0x1 << 0) /* Link up or down */
 /* Link rate */
diff --git a/drivers/net/nfp/flower/nfp_flower.c 
b/drivers/net/nfp/flower/nfp_flower.c
index 4d91d548f7..c1a3532c11 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -692,7 +692,7 @@ nfp_init_app_fw_flower(struct nfp_net_hw_priv *hw_priv)
        /* Map the PF ctrl bar */
        snprintf(bar_name, sizeof(bar_name), "_pf%u_net_bar0", id);
        pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, bar_name,
-                       NFP_NET_CFG_BAR_SZ, &pf_dev->ctrl_area);
+                       pf_dev->ctrl_bar_size, &pf_dev->ctrl_area);
        if (pf_dev->ctrl_bar == NULL) {
                PMD_INIT_LOG(ERR, "Cloud not map the PF vNIC ctrl bar");
                ret = -ENODEV;
@@ -737,7 +737,7 @@ nfp_init_app_fw_flower(struct nfp_net_hw_priv *hw_priv)
        /* Map the ctrl vNIC ctrl bar */
        snprintf(ctrl_name, sizeof(ctrl_name), "_pf%u_net_ctrl_bar", id);
        ctrl_hw->super.ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, ctrl_name,
-                       NFP_NET_CFG_BAR_SZ, &ctrl_hw->ctrl_area);
+                       pf_dev->ctrl_bar_size, &ctrl_hw->ctrl_area);
        if (ctrl_hw->super.ctrl_bar == NULL) {
                PMD_INIT_LOG(ERR, "Cloud not map the ctrl vNIC ctrl bar");
                ret = -ENODEV;
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index d85993f70c..a09bbe52ca 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -1022,7 +1022,7 @@ nfp_net_init(struct rte_eth_dev *eth_dev,
        if (pf_dev->multi_pf.enabled)
                hw->ctrl_bar = pf_dev->ctrl_bar;
        else
-               hw->ctrl_bar = pf_dev->ctrl_bar + (port * NFP_NET_CFG_BAR_SZ);
+               hw->ctrl_bar = pf_dev->ctrl_bar + (port * 
pf_dev->ctrl_bar_size);
 
        net_hw->mac_stats = pf_dev->mac_stats_bar +
                                (net_hw->nfp_idx * NFP_MAC_STATS_SIZE);
@@ -1555,9 +1555,10 @@ nfp_enable_multi_pf(struct nfp_pf_dev *pf_dev)
        memset(&net_hw, 0, sizeof(struct nfp_net_hw));
 
        /* Map the symbol table */
+       pf_dev->ctrl_bar_size = NFP_NET_CFG_BAR_SZ_MIN;
        snprintf(name, sizeof(name), "_pf%u_net_bar0",
                        pf_dev->multi_pf.function_id);
-       ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, name, NFP_NET_CFG_BAR_SZ,
+       ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, name, pf_dev->ctrl_bar_size,
                        &area);
        if (ctrl_bar == NULL) {
                PMD_INIT_LOG(ERR, "Failed to find data vNIC memory symbol");
@@ -1574,6 +1575,9 @@ nfp_enable_multi_pf(struct nfp_pf_dev *pf_dev)
                goto end;
        }
 
+       /* Set the ctrl bar size */
+       nfp_net_ctrl_bar_size_set(pf_dev);
+
        if (!pf_dev->multi_pf.enabled)
                goto end;
 
@@ -1670,7 +1674,7 @@ nfp_init_app_fw_nic(struct nfp_net_hw_priv *hw_priv)
        /* 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,
-                       pf_dev->total_phyports * NFP_NET_CFG_BAR_SZ,
+                       pf_dev->total_phyports * pf_dev->ctrl_bar_size,
                        &pf_dev->ctrl_area);
        if (pf_dev->ctrl_bar == NULL) {
                PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for %s", bar_name);
@@ -2065,11 +2069,11 @@ nfp_net_vf_config_init(struct nfp_pf_dev *pf_dev)
        if (pf_dev->sriov_vf == 0)
                return 0;
 
-       min_size = NFP_NET_CFG_BAR_SZ * pf_dev->sriov_vf;
+       min_size = pf_dev->ctrl_bar_size * pf_dev->sriov_vf;
        snprintf(vf_bar_name, sizeof(vf_bar_name), "_pf%d_net_vf_bar",
                        pf_dev->multi_pf.function_id);
        pf_dev->vf_bar = nfp_rtsym_map_offset(pf_dev->sym_tbl, vf_bar_name,
-                       NFP_NET_CFG_BAR_SZ * pf_dev->vf_base_id,
+                       pf_dev->ctrl_bar_size * pf_dev->vf_base_id,
                        min_size, &pf_dev->vf_area);
        if (pf_dev->vf_bar == NULL) {
                PMD_INIT_LOG(ERR, "Failed to get vf cfg.");
@@ -2295,15 +2299,15 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
                goto hwqueues_cleanup;
        }
 
+       ret = nfp_enable_multi_pf(pf_dev);
+       if (ret != 0)
+               goto mac_stats_cleanup;
+
        ret = nfp_net_vf_config_init(pf_dev);
        if (ret != 0) {
                PMD_INIT_LOG(ERR, "Failed to init VF config.");
-               goto mac_stats_cleanup;
-       }
-
-       ret = nfp_enable_multi_pf(pf_dev);
-       if (ret != 0)
                goto vf_cfg_tbl_cleanup;
+       }
 
        hw_priv->is_pf = true;
        hw_priv->pf_dev = pf_dev;
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index 2e581c7e45..ab413a2c5a 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -295,6 +295,9 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
                goto pf_dev_free;
        }
 
+       /* Set the ctrl bar size */
+       nfp_net_ctrl_bar_size_set(pf_dev);
+
        PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
 
        err = nfp_net_common_init(pf_dev, net_hw);
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index e4e01d8c79..5f92c2c31d 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -2184,6 +2184,9 @@ nfp_net_version_check(struct nfp_hw *hw,
        if (!nfp_net_is_valid_nfd_version(pf_dev->ver))
                return false;
 
+       if (!nfp_net_is_valid_version_class(pf_dev->ver))
+               return false;
+
        return true;
 }
 
@@ -2325,6 +2328,28 @@ nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver 
version)
        return false;
 }
 
+bool
+nfp_net_is_valid_version_class(struct nfp_net_fw_ver version)
+{
+       switch (version.class) {
+       case NFP_NET_CFG_VERSION_CLASS_GENERIC:
+               return true;
+       case NFP_NET_CFG_VERSION_CLASS_NO_EMEM:
+               return true;
+       default:
+               return false;
+       }
+}
+
+void
+nfp_net_ctrl_bar_size_set(struct nfp_pf_dev *pf_dev)
+{
+       if (pf_dev->ver.class == NFP_NET_CFG_VERSION_CLASS_GENERIC)
+               pf_dev->ctrl_bar_size = NFP_NET_CFG_BAR_SZ_32K;
+       else
+               pf_dev->ctrl_bar_size = NFP_NET_CFG_BAR_SZ_8K;
+}
+
 /* Disable rx and tx functions to allow for reconfiguring. */
 int
 nfp_net_stop(struct rte_eth_dev *dev)
diff --git a/drivers/net/nfp/nfp_net_common.h b/drivers/net/nfp/nfp_net_common.h
index 8d0922d48c..2c54815fc9 100644
--- a/drivers/net/nfp/nfp_net_common.h
+++ b/drivers/net/nfp/nfp_net_common.h
@@ -117,6 +117,7 @@ struct nfp_pf_dev {
        struct nfp_eth_table *nfp_eth_table;
 
        uint8_t *ctrl_bar;
+       uint32_t ctrl_bar_size;
 
        struct nfp_cpp *cpp;
        struct nfp_cpp_area *ctrl_area;
@@ -353,6 +354,7 @@ void nfp_net_tx_desc_limits(struct nfp_net_hw_priv *hw_priv,
 int nfp_net_check_dma_mask(struct nfp_pf_dev *pf_dev, char *name);
 int nfp_net_firmware_version_get(struct rte_eth_dev *dev, char *fw_version, 
size_t fw_size);
 bool nfp_net_is_valid_nfd_version(struct nfp_net_fw_ver version);
+bool nfp_net_is_valid_version_class(struct nfp_net_fw_ver version);
 struct nfp_net_hw *nfp_net_get_hw(const struct rte_eth_dev *dev);
 int nfp_net_stop(struct rte_eth_dev *dev);
 int nfp_net_flow_ctrl_get(struct rte_eth_dev *dev,
@@ -379,6 +381,7 @@ int nfp_net_vf_config_app_init(struct nfp_net_hw *net_hw,
                struct nfp_pf_dev *pf_dev);
 bool nfp_net_version_check(struct nfp_hw *hw,
                struct nfp_pf_dev *pf_dev);
+void nfp_net_ctrl_bar_size_set(struct nfp_pf_dev *pf_dev);
 
 #define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
        ((struct nfp_app_fw_nic *)app_fw_priv)
diff --git a/drivers/net/nfp/nfp_net_ctrl.c b/drivers/net/nfp/nfp_net_ctrl.c
index ea14b98924..b34d8f140f 100644
--- a/drivers/net/nfp/nfp_net_ctrl.c
+++ b/drivers/net/nfp/nfp_net_ctrl.c
@@ -30,13 +30,15 @@ nfp_net_tlv_caps_parse(struct rte_eth_dev *dev)
        uint32_t tlv_type;
        struct nfp_net_hw *net_hw;
        struct nfp_net_tlv_caps *caps;
+       struct nfp_net_hw_priv *hw_priv;
 
        net_hw = dev->data->dev_private;
+       hw_priv = dev->process_private;
        caps = &net_hw->tlv_caps;
        nfp_net_tlv_caps_reset(caps);
 
        data = net_hw->super.ctrl_bar + NFP_NET_CFG_TLV_BASE;
-       end = net_hw->super.ctrl_bar + NFP_NET_CFG_BAR_SZ;
+       end = net_hw->super.ctrl_bar + hw_priv->pf_dev->ctrl_bar_size;
 
        hdr = rte_read32(data);
        if (hdr == 0) {
-- 
2.39.1

Reply via email to