From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasesh Mody Subject: [PATCH v2 06/14] net/qede/base: add new chain API Date: Sun, 8 Apr 2018 21:48:02 -0700 Message-ID: <1523249290-7444-7-git-send-email-rasesh.mody@cavium.com> References: <1522561624-15817-1-git-send-email-rasesh.mody@cavium.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Rasesh Mody , ferruh.yigit@intel.com, Dept-EngDPDKDev@cavium.com To: dev@dpdk.org Return-path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0081.outbound.protection.outlook.com [104.47.34.81]) by dpdk.org (Postfix) with ESMTP id 44B851B719 for ; Mon, 9 Apr 2018 06:49:08 +0200 (CEST) In-Reply-To: <1522561624-15817-1-git-send-email-rasesh.mody@cavium.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add new API ecore_chain_set_cons() and fix page index setting in ecore_chain_set_prod(). The new API is for future use. Signed-off-by: Rasesh Mody --- drivers/net/qede/base/ecore_chain.h | 49 ++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/net/qede/base/ecore_chain.h b/drivers/net/qede/base/ecore_chain.h index d8f69ad..f8c932b 100644 --- a/drivers/net/qede/base/ecore_chain.h +++ b/drivers/net/qede/base/ecore_chain.h @@ -526,7 +526,7 @@ static OSAL_INLINE void ecore_chain_reset(struct ecore_chain *p_chain) p_chain->p_prod_elem = p_chain->p_virt_addr; if (p_chain->mode == ECORE_CHAIN_MODE_PBL) { - /* Use (page_cnt - 1) as a reset value for the prod/cons page's + /* Use "page_cnt-1" as a reset value for the prod/cons page's * indices, to avoid unnecessary page advancing on the first * call to ecore_chain_produce/consume. Instead, the indices * will be advanced to page_cnt and then will be wrapped to 0. @@ -726,6 +726,21 @@ static OSAL_INLINE void *ecore_chain_get_last_elem(struct ecore_chain *p_chain) 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 elem_idx = + (prod_idx - 1 + p_chain->capacity) % p_chain->capacity; + u32 page_idx = elem_idx / p_chain->elem_per_page; + + if (is_chain_u16(p_chain)) + p_chain->pbl.c.u16.prod_page_idx = (u16)page_idx; + else + p_chain->pbl.c.u32.prod_page_idx = page_idx; + } + if (is_chain_u16(p_chain)) p_chain->u.chain16.prod_idx = (u16)prod_idx; else @@ -734,6 +749,38 @@ static OSAL_INLINE void ecore_chain_set_prod(struct ecore_chain *p_chain, } /** + * @brief ecore_chain_set_cons - sets the cons to the given value + * + * @param cons_idx + * @param p_cons_elem + */ +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 elem_idx = + (cons_idx - 1 + p_chain->capacity) % p_chain->capacity; + u32 page_idx = elem_idx / p_chain->elem_per_page; + + if (is_chain_u16(p_chain)) + p_chain->pbl.c.u16.cons_page_idx = (u16)page_idx; + else + p_chain->pbl.c.u32.cons_page_idx = page_idx; + } + + if (is_chain_u16(p_chain)) + p_chain->u.chain16.cons_idx = (u16)cons_idx; + else + p_chain->u.chain32.cons_idx = cons_idx; + + p_chain->p_cons_elem = p_cons_elem; +} + +/** * @brief ecore_chain_pbl_zero_mem - set chain memory to 0 * * @param p_chain -- 1.7.10.3