DPDK patches and discussions
 help / color / mirror / Atom feed
From: Rasesh Mody <rmody@marvell.com>
To: <dev@dpdk.org>, <jerinj@marvell.com>, <ferruh.yigit@intel.com>
Cc: Rasesh Mody <rmody@marvell.com>, <GR-Everest-DPDK-Dev@marvell.com>
Subject: [dpdk-dev] [PATCH v2 1/9] net/qede/base: calculate right page index for PBL chains
Date: Sun, 6 Oct 2019 13:14:01 -0700	[thread overview]
Message-ID: <20191006201409.8770-2-rmody@marvell.com> (raw)
In-Reply-To: <20190930024921.21818-1-rmody@marvell.com>

ecore_chain_set_prod/cons() sets the wrong page index in chains with
non-power of 2 page count. Fix ecore_chain_set_prod/cons() for PBL
chains with non power of 2 page count.
Calculate the right page index according to current indexes.

Signed-off-by: Rasesh Mody <rmody@marvell.com>
---
 drivers/net/qede/base/ecore_chain.h | 84 ++++++++++++++++++++---------
 1 file changed, 58 insertions(+), 26 deletions(-)

diff --git a/drivers/net/qede/base/ecore_chain.h b/drivers/net/qede/base/ecore_chain.h
index 6d0382d3a..c69920be5 100644
--- a/drivers/net/qede/base/ecore_chain.h
+++ b/drivers/net/qede/base/ecore_chain.h
@@ -86,8 +86,8 @@ struct ecore_chain {
 		void		**pp_virt_addr_tbl;
 
 		union {
-			struct ecore_chain_pbl_u16	u16;
-			struct ecore_chain_pbl_u32	u32;
+			struct ecore_chain_pbl_u16	pbl_u16;
+			struct ecore_chain_pbl_u32	pbl_u32;
 		} c;
 	} pbl;
 
@@ -405,7 +405,7 @@ static OSAL_INLINE void *ecore_chain_produce(struct ecore_chain *p_chain)
 		if ((p_chain->u.chain16.prod_idx &
 		     p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
 			p_prod_idx = &p_chain->u.chain16.prod_idx;
-			p_prod_page_idx = &p_chain->pbl.c.u16.prod_page_idx;
+			p_prod_page_idx = &p_chain->pbl.c.pbl_u16.prod_page_idx;
 			ecore_chain_advance_page(p_chain, &p_chain->p_prod_elem,
 						 p_prod_idx, p_prod_page_idx);
 		}
@@ -414,7 +414,7 @@ static OSAL_INLINE void *ecore_chain_produce(struct ecore_chain *p_chain)
 		if ((p_chain->u.chain32.prod_idx &
 		     p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
 			p_prod_idx = &p_chain->u.chain32.prod_idx;
-			p_prod_page_idx = &p_chain->pbl.c.u32.prod_page_idx;
+			p_prod_page_idx = &p_chain->pbl.c.pbl_u32.prod_page_idx;
 			ecore_chain_advance_page(p_chain, &p_chain->p_prod_elem,
 						 p_prod_idx, p_prod_page_idx);
 		}
@@ -479,7 +479,7 @@ static OSAL_INLINE void *ecore_chain_consume(struct ecore_chain *p_chain)
 		if ((p_chain->u.chain16.cons_idx &
 		     p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
 			p_cons_idx = &p_chain->u.chain16.cons_idx;
-			p_cons_page_idx = &p_chain->pbl.c.u16.cons_page_idx;
+			p_cons_page_idx = &p_chain->pbl.c.pbl_u16.cons_page_idx;
 			ecore_chain_advance_page(p_chain, &p_chain->p_cons_elem,
 						 p_cons_idx, p_cons_page_idx);
 		}
@@ -488,7 +488,7 @@ static OSAL_INLINE void *ecore_chain_consume(struct ecore_chain *p_chain)
 		if ((p_chain->u.chain32.cons_idx &
 		     p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
 			p_cons_idx = &p_chain->u.chain32.cons_idx;
-			p_cons_page_idx = &p_chain->pbl.c.u32.cons_page_idx;
+			p_cons_page_idx = &p_chain->pbl.c.pbl_u32.cons_page_idx;
 			ecore_chain_advance_page(p_chain, &p_chain->p_cons_elem,
 						 p_cons_idx, p_cons_page_idx);
 		}
@@ -532,11 +532,11 @@ static OSAL_INLINE void ecore_chain_reset(struct ecore_chain *p_chain)
 		u32 reset_val = p_chain->page_cnt - 1;
 
 		if (is_chain_u16(p_chain)) {
-			p_chain->pbl.c.u16.prod_page_idx = (u16)reset_val;
-			p_chain->pbl.c.u16.cons_page_idx = (u16)reset_val;
+			p_chain->pbl.c.pbl_u16.prod_page_idx = (u16)reset_val;
+			p_chain->pbl.c.pbl_u16.cons_page_idx = (u16)reset_val;
 		} else {
-			p_chain->pbl.c.u32.prod_page_idx = reset_val;
-			p_chain->pbl.c.u32.cons_page_idx = reset_val;
+			p_chain->pbl.c.pbl_u32.prod_page_idx = reset_val;
+			p_chain->pbl.c.pbl_u32.cons_page_idx = reset_val;
 		}
 	}
 
@@ -725,18 +725,34 @@ static OSAL_INLINE void ecore_chain_set_prod(struct ecore_chain *p_chain,
 					     u32 prod_idx, void *p_prod_elem)
 {
 	if (p_chain->mode == ECORE_CHAIN_MODE_PBL) {
-		/* Use "prod_idx-1" since ecore_chain_produce() advances the
-		 * page index before the producer index when getting to
-		 * "next_page_mask".
+		u32 cur_prod, page_mask, page_cnt, page_diff;
+
+		cur_prod = is_chain_u16(p_chain) ? p_chain->u.chain16.prod_idx
+						 : p_chain->u.chain32.prod_idx;
+
+		/* Assume that number of elements in a page is power of 2 */
+		page_mask = ~p_chain->elem_per_page_mask;
+
+		/* Use "cur_prod - 1" and "prod_idx - 1" since producer index
+		 * reaches the first element of next page before the page index
+		 * is incremented. See ecore_chain_produce().
+		 * Index wrap around is not a problem because the difference
+		 * between current and given producer indexes is always
+		 * positive and lower than the chain's capacity.
 		 */
-		u32 elem_idx =
-			(prod_idx - 1 + p_chain->capacity) % p_chain->capacity;
-		u32 page_idx = elem_idx / p_chain->elem_per_page;
+		page_diff = (((cur_prod - 1) & page_mask) -
+			     ((prod_idx - 1) & page_mask)) /
+			    p_chain->elem_per_page;
 
+		page_cnt = ecore_chain_get_page_cnt(p_chain);
 		if (is_chain_u16(p_chain))
-			p_chain->pbl.c.u16.prod_page_idx = (u16)page_idx;
+			p_chain->pbl.c.pbl_u16.prod_page_idx =
+				(p_chain->pbl.c.pbl_u16.prod_page_idx -
+				 page_diff + page_cnt) % page_cnt;
 		else
-			p_chain->pbl.c.u32.prod_page_idx = page_idx;
+			p_chain->pbl.c.pbl_u32.prod_page_idx =
+				(p_chain->pbl.c.pbl_u32.prod_page_idx -
+				 page_diff + page_cnt) % page_cnt;
 	}
 
 	if (is_chain_u16(p_chain))
@@ -756,18 +772,34 @@ static OSAL_INLINE void ecore_chain_set_cons(struct ecore_chain *p_chain,
 					     u32 cons_idx, void *p_cons_elem)
 {
 	if (p_chain->mode == ECORE_CHAIN_MODE_PBL) {
-		/* Use "cons_idx-1" since ecore_chain_consume() advances the
-		 * page index before the consumer index when getting to
-		 * "next_page_mask".
+		u32 cur_cons, page_mask, page_cnt, page_diff;
+
+		cur_cons = is_chain_u16(p_chain) ? p_chain->u.chain16.cons_idx
+						 : p_chain->u.chain32.cons_idx;
+
+		/* Assume that number of elements in a page is power of 2 */
+		page_mask = ~p_chain->elem_per_page_mask;
+
+		/* Use "cur_cons - 1" and "cons_idx - 1" since consumer index
+		 * reaches the first element of next page before the page index
+		 * is incremented. See ecore_chain_consume().
+		 * Index wrap around is not a problem because the difference
+		 * between current and given consumer indexes is always
+		 * positive and lower than the chain's capacity.
 		 */
-		u32 elem_idx =
-			(cons_idx - 1 + p_chain->capacity) % p_chain->capacity;
-		u32 page_idx = elem_idx / p_chain->elem_per_page;
+		page_diff = (((cur_cons - 1) & page_mask) -
+			     ((cons_idx - 1) & page_mask)) /
+			    p_chain->elem_per_page;
 
+		page_cnt = ecore_chain_get_page_cnt(p_chain);
 		if (is_chain_u16(p_chain))
-			p_chain->pbl.c.u16.cons_page_idx = (u16)page_idx;
+			p_chain->pbl.c.pbl_u16.cons_page_idx =
+				(p_chain->pbl.c.pbl_u16.cons_page_idx -
+				 page_diff + page_cnt) % page_cnt;
 		else
-			p_chain->pbl.c.u32.cons_page_idx = page_idx;
+			p_chain->pbl.c.pbl_u32.cons_page_idx =
+				(p_chain->pbl.c.pbl_u32.cons_page_idx -
+				 page_diff + page_cnt) % page_cnt;
 	}
 
 	if (is_chain_u16(p_chain))
-- 
2.18.0


  parent reply	other threads:[~2019-10-06 20:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30  2:49 [dpdk-dev] [PATCH 0/9] net/qede/base: update FW to 8.40.25.0 Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 1/9] net/qede/base: calculate right page index for PBL chains Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 2/9] net/qede/base: change MFW mailbox command log verbosity Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 3/9] net/qede/base: lock entire QM reconfiguration flow Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 4/9] net/qede/base: rename HSI datatypes and funcs Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 5/9] net/qede/base: update rt defs NVM cfg and mcp code Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 6/9] net/qede/base: move dmae code to HSI Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 7/9] net/qede/base: update HSI code Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 8/9] net/qede/base: update the FW to 8.40.25.0 Rasesh Mody
2019-09-30  2:49 ` [dpdk-dev] [PATCH 9/9] net/qede: print adapter info during init failure Rasesh Mody
2019-10-03  5:06 ` [dpdk-dev] [PATCH 0/9] net/qede/base: update FW to 8.40.25.0 Jerin Jacob
2019-10-03  5:59   ` Rasesh Mody
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 " Rasesh Mody
2019-10-11  7:57   ` Jerin Jacob
2019-10-06 20:14 ` Rasesh Mody [this message]
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 2/9] net/qede/base: change MFW mailbox command log verbosity Rasesh Mody
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 3/9] net/qede/base: lock entire QM reconfiguration flow Rasesh Mody
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 4/9] net/qede/base: rename HSI datatypes and funcs Rasesh Mody
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 5/9] net/qede/base: update rt defs NVM cfg and mcp code Rasesh Mody
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 6/9] net/qede/base: move dmae code to HSI Rasesh Mody
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 7/9] net/qede/base: update HSI code Rasesh Mody
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 8/9] net/qede/base: update the FW to 8.40.25.0 Rasesh Mody
2019-10-11 16:13   ` Ferruh Yigit
2019-10-06 20:14 ` [dpdk-dev] [PATCH v2 9/9] net/qede: print adapter info during init failure Rasesh Mody

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=20191006201409.8770-2-rmody@marvell.com \
    --to=rmody@marvell.com \
    --cc=GR-Everest-DPDK-Dev@marvell.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jerinj@marvell.com \
    /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).