+/**
+ * @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) {
+ 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.
+ */
+ 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.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.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))
+ 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;
+}
+