patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: stable@dpdk.org
Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com,
	Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH 21.11] net/nfp: fix offloading flows
Date: Tue, 25 Jul 2023 14:51:42 +0800	[thread overview]
Message-ID: <20230725065143.425037-1-chaoyong.he@corigine.com> (raw)

[ upstream commit 925c27ec8de92efe69f4cb56e3fc0e413354c739 ]

The symbol '_abi_flower_extra_features' is in IMEM for NFP4000,
but in EMU_CACHE for NFP3800 because which does not have IMEM.

The original logic can't read symbol from EMU_CACHE, so the probe
process will fail when we try to offload flows use NFP3800.

Modify the related data structure and logics to support read symbol
from EMU_CACHE.

Fixes: c7e9729da6b5 ("net/nfp: support CPP")
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c          |   4 +-
 drivers/net/nfp/nfpcore/nfp_cpp.h     |   7 +-
 drivers/net/nfp/nfpcore/nfp_cppcore.c |  52 +++++++++---
 drivers/net/nfp/nfpcore/nfp_rtsym.c   | 117 ++++++++++++++++++++++++--
 4 files changed, 158 insertions(+), 22 deletions(-)

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 748bacff07..37593fd216 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -800,6 +800,7 @@ static int nfp_pf_init(struct rte_pci_device *pci_dev)
 {
 	struct nfp_pf_dev *pf_dev = NULL;
 	struct nfp_cpp *cpp;
+	uint32_t cpp_id;
 	struct nfp_hwinfo *hwinfo;
 	struct nfp_rtsym_table *sym_tbl;
 	struct nfp_eth_table *nfp_eth_table = NULL;
@@ -904,7 +905,8 @@ static int nfp_pf_init(struct rte_pci_device *pci_dev)
 	PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar);
 
 	/* configure access to tx/rx vNIC BARs */
-	pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, 0, 0,
+	cpp_id = NFP_CPP_ISLAND_ID(0, NFP_CPP_ACTION_RW, 0, 0);
+	pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, cpp_id,
 					      NFP_PCIE_QUEUE(0),
 					      NFP_QCP_QUEUE_AREA_SZ,
 					      &pf_dev->hwqueues_area);
diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h
index 720d3989e6..61d36047e1 100644
--- a/drivers/net/nfp/nfpcore/nfp_cpp.h
+++ b/drivers/net/nfp/nfpcore/nfp_cpp.h
@@ -34,6 +34,9 @@ struct nfp_cpp {
 	 */
 	uint32_t imb_cat_table[16];
 
+	/* MU access type bit offset */
+	uint32_t mu_locality_lsb;
+
 	int driver_lock_needed;
 };
 
@@ -363,7 +366,7 @@ struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp,
  */
 void nfp_cpp_area_release_free(struct nfp_cpp_area *area);
 
-uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, int domain, int target,
+uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id,
 			   uint64_t addr, unsigned long size,
 			   struct nfp_cpp_area **area);
 /*
@@ -778,4 +781,6 @@ int nfp_cpp_mutex_unlock(struct nfp_cpp_mutex *mutex);
  */
 int nfp_cpp_mutex_trylock(struct nfp_cpp_mutex *mutex);
 
+uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp);
+
 #endif /* !__NFP_CPP_H__ */
diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c
index 37799af558..13d979633d 100644
--- a/drivers/net/nfp/nfpcore/nfp_cppcore.c
+++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c
@@ -118,6 +118,36 @@ nfp_cpp_area_name(struct nfp_cpp_area *cpp_area)
 	return cpp_area->name;
 }
 
+#define NFP_IMB_TGTADDRESSMODECFG_MODE_of(_x)       (((_x) >> 13) & 0x7)
+#define NFP_IMB_TGTADDRESSMODECFG_ADDRMODE          RTE_BIT32(12)
+
+static int
+nfp_cpp_set_mu_locality_lsb(struct nfp_cpp *cpp)
+{
+	int ret;
+	int mode;
+	int addr40;
+	uint32_t imbcppat;
+
+	imbcppat = cpp->imb_cat_table[NFP_CPP_TARGET_MU];
+	mode = NFP_IMB_TGTADDRESSMODECFG_MODE_of(imbcppat);
+	addr40 = imbcppat & NFP_IMB_TGTADDRESSMODECFG_ADDRMODE;
+
+	ret = nfp_cppat_mu_locality_lsb(mode, addr40);
+	if (ret < 0)
+		return ret;
+
+	cpp->mu_locality_lsb = ret;
+
+	return 0;
+}
+
+uint32_t
+nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp)
+{
+	return cpp->mu_locality_lsb;
+}
+
 /*
  * nfp_cpp_area_alloc - allocate a new CPP area
  * @cpp:    CPP handle
@@ -142,10 +172,6 @@ nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp, uint32_t dest,
 	if (!cpp)
 		return NULL;
 
-	/* CPP bus uses only a 40-bit address */
-	if ((address + size) > (1ULL << 40))
-		return NFP_ERRPTR(EFAULT);
-
 	/* Remap from cpp_island to cpp_target */
 	err = nfp_target_cpp(dest, tmp64, &dest, &tmp64, cpp->imb_cat_table);
 	if (err < 0)
@@ -588,6 +614,12 @@ nfp_cpp_alloc(struct rte_pci_device *dev, int driver_lock_needed)
 		}
 	}
 
+	err = nfp_cpp_set_mu_locality_lsb(cpp);
+	if (err < 0) {
+		free(cpp);
+		return NULL;
+	}
+
 	return cpp;
 }
 
@@ -819,8 +851,7 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model)
 /*
  * nfp_cpp_map_area() - Helper function to map an area
  * @cpp:    NFP CPP handler
- * @domain: CPP domain
- * @target: CPP target
+ * @cpp_id: CPP ID
  * @addr:   CPP address
  * @size:   Size of the area
  * @area:   Area handle (output)
@@ -831,16 +862,13 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model)
  * Return: Pointer to memory mapped area or ERR_PTR
  */
 uint8_t *
-nfp_cpp_map_area(struct nfp_cpp *cpp, int domain, int target, uint64_t addr,
+nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr,
 		 unsigned long size, struct nfp_cpp_area **area)
 {
 	uint8_t *res;
-	uint32_t dest;
-
-	dest = NFP_CPP_ISLAND_ID(target, NFP_CPP_ACTION_RW, 0, domain);
 
-	*area = nfp_cpp_area_alloc_acquire(cpp, dest, addr, size);
-	if (!*area)
+	*area = nfp_cpp_area_alloc_acquire(cpp, cpp_id, addr, size);
+	if (*area == NULL)
 		goto err_eio;
 
 	res = nfp_cpp_area_iomem(*area);
diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c
index 2feca2ed81..2c6c639367 100644
--- a/drivers/net/nfp/nfpcore/nfp_rtsym.c
+++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c
@@ -232,6 +232,102 @@ nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name)
 	return NULL;
 }
 
+static uint64_t
+nfp_rtsym_size(const struct nfp_rtsym *sym)
+{
+	switch (sym->type) {
+	case NFP_RTSYM_TYPE_NONE:
+		return 0;
+	case NFP_RTSYM_TYPE_OBJECT:    /* Fall through */
+	case NFP_RTSYM_TYPE_FUNCTION:
+		return sym->size;
+	case NFP_RTSYM_TYPE_ABS:
+		return sizeof(uint64_t);
+	default:
+		return 0;
+	}
+}
+
+static int
+nfp_rtsym_to_dest(struct nfp_cpp *cpp,
+		const struct nfp_rtsym *sym,
+		uint8_t action,
+		uint8_t token,
+		uint64_t offset,
+		uint32_t *cpp_id,
+		uint64_t *addr)
+{
+	if (sym->type != NFP_RTSYM_TYPE_OBJECT)
+		return -EINVAL;
+
+	*addr = sym->addr + offset;
+
+	if (sym->target >= 0) {
+		*cpp_id = NFP_CPP_ISLAND_ID(sym->target, action, token, sym->domain);
+	} else if (sym->target == NFP_RTSYM_TARGET_EMU_CACHE) {
+		int locality_off = nfp_cpp_mu_locality_lsb(cpp);
+
+		*addr &= ~(NFP_MU_ADDR_ACCESS_TYPE_MASK << locality_off);
+		*addr |= NFP_MU_ADDR_ACCESS_TYPE_DIRECT << locality_off;
+
+		*cpp_id = NFP_CPP_ISLAND_ID(NFP_CPP_TARGET_MU, action, token,
+				sym->domain);
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+nfp_rtsym_readl(struct nfp_cpp *cpp,
+		const struct nfp_rtsym *sym,
+		uint8_t action,
+		uint8_t token,
+		uint64_t offset,
+		uint32_t *value)
+{
+	int ret;
+	uint64_t addr;
+	uint32_t cpp_id;
+
+	if (offset + 4 > nfp_rtsym_size(sym))
+		return -ENXIO;
+
+	ret = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr);
+	if (ret != 0)
+		return ret;
+
+	return nfp_cpp_readl(cpp, cpp_id, addr, value);
+}
+
+static int
+nfp_rtsym_readq(struct nfp_cpp *cpp,
+		const struct nfp_rtsym *sym,
+		uint8_t action,
+		uint8_t token,
+		uint64_t offset,
+		uint64_t *value)
+{
+	int ret;
+	uint64_t addr;
+	uint32_t cpp_id;
+
+	if (offset + 8 > nfp_rtsym_size(sym))
+		return -ENXIO;
+
+	if (sym->type == NFP_RTSYM_TYPE_ABS) {
+		*value = sym->addr;
+		return 0;
+	}
+
+	ret = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr);
+	if (ret != 0)
+		return ret;
+
+	return nfp_cpp_readq(cpp, cpp_id, addr, value);
+}
+
 /*
  * nfp_rtsym_read_le() - Read a simple unsigned scalar value from symbol
  * @rtbl:	NFP RTsym table
@@ -248,7 +344,7 @@ uint64_t
 nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error)
 {
 	const struct nfp_rtsym *sym;
-	uint32_t val32, id;
+	uint32_t val32;
 	uint64_t val;
 	int err;
 
@@ -258,19 +354,17 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error)
 		goto exit;
 	}
 
-	id = NFP_CPP_ISLAND_ID(sym->target, NFP_CPP_ACTION_RW, 0, sym->domain);
-
 #ifdef DEBUG
 	printf("Reading symbol %s with size %" PRIu64 " at %" PRIx64 "\n",
 		name, sym->size, sym->addr);
 #endif
 	switch (sym->size) {
 	case 4:
-		err = nfp_cpp_readl(rtbl->cpp, id, sym->addr, &val32);
+		err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32);
 		val = val32;
 		break;
 	case 8:
-		err = nfp_cpp_readq(rtbl->cpp, id, sym->addr, &val);
+		err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val);
 		break;
 	default:
 		printf("rtsym '%s' unsupported size: %" PRId64 "\n",
@@ -295,8 +389,11 @@ uint8_t *
 nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name,
 	      unsigned int min_size, struct nfp_cpp_area **area)
 {
-	const struct nfp_rtsym *sym;
+	int ret;
 	uint8_t *mem;
+	uint64_t addr;
+	uint32_t cpp_id;
+	const struct nfp_rtsym *sym;
 
 #ifdef DEBUG
 	printf("mapping symbol %s\n", name);
@@ -307,14 +404,18 @@ nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name,
 		return NULL;
 	}
 
+	ret = nfp_rtsym_to_dest(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0,
+			&cpp_id, &addr);
+	if (ret != 0)
+		return NULL;
+
 	if (sym->size < min_size) {
 		printf("Symbol %s too small (%" PRIu64 " < %u)\n", name,
 			sym->size, min_size);
 		return NULL;
 	}
 
-	mem = nfp_cpp_map_area(rtbl->cpp, sym->domain, sym->target, sym->addr,
-			       sym->size, area);
+	mem = nfp_cpp_map_area(rtbl->cpp, cpp_id, addr, sym->size, area);
 	if (!mem) {
 		printf("Failed to map symbol %s\n", name);
 		return NULL;
-- 
2.39.1


             reply	other threads:[~2023-07-25  6:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25  6:51 Chaoyong He [this message]
2023-07-25  6:51 ` [PATCH 21.11] net/nfp: fix Tx descriptor free logic of NFD3 Chaoyong He
2023-07-25  9:17 ` [PATCH 21.11] net/nfp: fix offloading flows Kevin Traynor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230725065143.425037-1-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=niklas.soderlund@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).