net/qede/base: add new chain API
authorRasesh Mody <rasesh.mody@cavium.com>
Mon, 9 Apr 2018 04:48:02 +0000 (21:48 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 13 Apr 2018 22:41:44 +0000 (00:41 +0200)
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 <rasesh.mody@cavium.com>
drivers/net/qede/base/ecore_chain.h

index d8f69ad..f8c932b 100644 (file)
@@ -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 @@ out:
 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
@@ -733,6 +748,38 @@ static OSAL_INLINE void ecore_chain_set_prod(struct ecore_chain *p_chain,
        p_chain->p_prod_elem = p_prod_elem;
 }
 
+/**
+ * @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
  *