2 * Copyright (c) 2017-2018 Cavium, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __ECORE_CHAIN_H__
32 #define __ECORE_CHAIN_H__
34 #include "common_hsi.h"
35 #include "ecore_utils.h"
39 /* Each Page contains a next pointer at its end */
40 ECORE_CHAIN_MODE_NEXT_PTR,
42 /* Chain is a single page (next ptr) is unrequired */
43 ECORE_CHAIN_MODE_SINGLE,
45 /* Page pointers are located in a side list */
49 enum ecore_chain_use_mode
51 ECORE_CHAIN_USE_TO_PRODUCE, /* Chain starts empty */
52 ECORE_CHAIN_USE_TO_CONSUME, /* Chain starts full */
53 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE, /* Chain starts empty */
56 enum ecore_chain_cnt_type {
57 /* The chain's size/prod/cons are kept in 16-bit variables */
58 ECORE_CHAIN_CNT_TYPE_U16,
60 /* The chain's size/prod/cons are kept in 32-bit variables */
61 ECORE_CHAIN_CNT_TYPE_U32,
64 struct ecore_chain_next
66 struct regpair next_phys;
70 struct ecore_chain_pbl_u16 {
75 struct ecore_chain_pbl_u32 {
80 struct ecore_chain_ext_pbl
82 dma_addr_t p_pbl_phys;
86 struct ecore_chain_u16 {
87 /* Cyclic index of next element to produce/consme */
92 struct ecore_chain_u32 {
93 /* Cyclic index of next element to produce/consme */
100 /* fastpath portion of the chain - required for commands such
101 * as produce / consume.
103 /* Point to next element to produce/consume */
107 /* Fastpath portions of the PBL [if exists] */
110 /* Table for keeping the virtual addresses of the chain pages,
111 * respectively to the physical addresses in the pbl table.
113 void **pp_virt_addr_tbl;
116 struct ecore_chain_pbl_u16 pbl_u16;
117 struct ecore_chain_pbl_u32 pbl_u32;
122 struct ecore_chain_u16 chain16;
123 struct ecore_chain_u32 chain32;
126 /* Capacity counts only usable elements */
130 /* A u8 would suffice for mode, but it would save as a lot of headaches
131 * on castings & defaults.
133 enum ecore_chain_mode mode;
135 /* Elements information for fast calculations */
137 u16 elem_per_page_mask;
145 /* Slowpath of the chain - required for initialization and destruction,
146 * but isn't involved in regular functionality.
149 /* Base address of a pre-allocated buffer for pbl */
151 dma_addr_t p_phys_table;
155 /* Address of first page of the chain - the address is required
156 * for fastpath operation [consume/produce] but only for the the SINGLE
157 * flavour which isn't considered fastpath [== SPQ].
160 dma_addr_t p_phys_addr;
162 /* Total number of elements [for entire chain] */
167 /* TBD - do we really need this? Couldn't find usage for it */
173 #define ECORE_CHAIN_PBL_ENTRY_SIZE (8)
174 #define ECORE_CHAIN_PAGE_SIZE (0x1000)
175 #define ELEMS_PER_PAGE(elem_size) (ECORE_CHAIN_PAGE_SIZE/(elem_size))
177 #define UNUSABLE_ELEMS_PER_PAGE(elem_size, mode) \
178 ((mode == ECORE_CHAIN_MODE_NEXT_PTR) ? \
179 (u8)(1 + ((sizeof(struct ecore_chain_next)-1) / \
182 #define USABLE_ELEMS_PER_PAGE(elem_size, mode) \
183 ((u32) (ELEMS_PER_PAGE(elem_size) - \
184 UNUSABLE_ELEMS_PER_PAGE(elem_size, mode)))
186 #define ECORE_CHAIN_PAGE_CNT(elem_cnt, elem_size, mode) \
187 DIV_ROUND_UP(elem_cnt, USABLE_ELEMS_PER_PAGE(elem_size, mode))
189 #define is_chain_u16(p) ((p)->cnt_type == ECORE_CHAIN_CNT_TYPE_U16)
190 #define is_chain_u32(p) ((p)->cnt_type == ECORE_CHAIN_CNT_TYPE_U32)
193 static OSAL_INLINE u16 ecore_chain_get_prod_idx(struct ecore_chain *p_chain)
195 OSAL_ASSERT(is_chain_u16(p_chain));
196 return p_chain->u.chain16.prod_idx;
200 static OSAL_INLINE u32 ecore_chain_get_prod_idx_u32(struct ecore_chain *p_chain)
202 OSAL_ASSERT(is_chain_u32(p_chain));
203 return p_chain->u.chain32.prod_idx;
207 static OSAL_INLINE u16 ecore_chain_get_cons_idx(struct ecore_chain *p_chain)
209 OSAL_ASSERT(is_chain_u16(p_chain));
210 return p_chain->u.chain16.cons_idx;
213 static OSAL_INLINE u32 ecore_chain_get_cons_idx_u32(struct ecore_chain *p_chain)
215 OSAL_ASSERT(is_chain_u32(p_chain));
216 return p_chain->u.chain32.cons_idx;
220 * Should create OSALs for the below definitions.
221 * For Linux, replace them with the existing U16_MAX and U32_MAX, and handle
222 * kernel versions that lack them.
224 #define ECORE_U16_MAX ((u16)~0U)
225 #define ECORE_U32_MAX ((u32)~0U)
227 static OSAL_INLINE u16 ecore_chain_get_elem_left(struct ecore_chain *p_chain)
231 OSAL_ASSERT(is_chain_u16(p_chain));
233 used = (u16)(((u32)ECORE_U16_MAX + 1 +
234 (u32)(p_chain->u.chain16.prod_idx)) -
235 (u32)p_chain->u.chain16.cons_idx);
236 if (p_chain->mode == ECORE_CHAIN_MODE_NEXT_PTR)
237 used -= (((u32)ECORE_U16_MAX + 1) / p_chain->elem_per_page +
238 p_chain->u.chain16.prod_idx / p_chain->elem_per_page -
239 p_chain->u.chain16.cons_idx / p_chain->elem_per_page) %
242 return (u16)(p_chain->capacity - used);
245 static OSAL_INLINE u32
246 ecore_chain_get_elem_left_u32(struct ecore_chain *p_chain)
250 OSAL_ASSERT(is_chain_u32(p_chain));
252 used = (u32)(((u64)ECORE_U32_MAX + 1 +
253 (u64)(p_chain->u.chain32.prod_idx)) -
254 (u64)p_chain->u.chain32.cons_idx);
255 if (p_chain->mode == ECORE_CHAIN_MODE_NEXT_PTR)
256 used -= (((u64)ECORE_U32_MAX + 1) / p_chain->elem_per_page +
257 p_chain->u.chain32.prod_idx / p_chain->elem_per_page -
258 p_chain->u.chain32.cons_idx / p_chain->elem_per_page) %
261 return p_chain->capacity - used;
265 static OSAL_INLINE u8 ecore_chain_is_full(struct ecore_chain *p_chain)
267 if (is_chain_u16(p_chain))
268 return (ecore_chain_get_elem_left(p_chain) ==
271 return (ecore_chain_get_elem_left_u32(p_chain) ==
275 static OSAL_INLINE u8 ecore_chain_is_empty(struct ecore_chain *p_chain)
277 if (is_chain_u16(p_chain))
278 return (ecore_chain_get_elem_left(p_chain) == 0);
280 return (ecore_chain_get_elem_left_u32(p_chain) == 0);
284 u16 ecore_chain_get_elem_per_page(struct ecore_chain *p_chain)
286 return p_chain->elem_per_page;
291 u16 ecore_chain_get_usable_per_page(struct ecore_chain *p_chain)
293 return p_chain->usable_per_page;
297 u8 ecore_chain_get_unusable_per_page(struct ecore_chain *p_chain)
299 return p_chain->elem_unusable;
303 static OSAL_INLINE u32 ecore_chain_get_size(struct ecore_chain *p_chain)
305 return p_chain->size;
309 static OSAL_INLINE u32 ecore_chain_get_page_cnt(struct ecore_chain *p_chain)
311 return p_chain->page_cnt;
315 dma_addr_t ecore_chain_get_pbl_phys(struct ecore_chain *p_chain)
317 return p_chain->pbl_sp.p_phys_table;
321 * @brief ecore_chain_advance_page -
323 * Advance the next element accros pages for a linked chain
330 static OSAL_INLINE void
331 ecore_chain_advance_page(struct ecore_chain *p_chain, void **p_next_elem,
332 void *idx_to_inc, void *page_to_inc)
334 struct ecore_chain_next *p_next = OSAL_NULL;
337 switch(p_chain->mode) {
338 case ECORE_CHAIN_MODE_NEXT_PTR:
339 p_next = (struct ecore_chain_next *)(*p_next_elem);
340 *p_next_elem = p_next->next_virt;
341 if (is_chain_u16(p_chain))
342 *(u16 *)idx_to_inc += (u16)p_chain->elem_unusable;
344 *(u32 *)idx_to_inc += (u16)p_chain->elem_unusable;
346 case ECORE_CHAIN_MODE_SINGLE:
347 *p_next_elem = p_chain->p_virt_addr;
349 case ECORE_CHAIN_MODE_PBL:
350 if (is_chain_u16(p_chain)) {
351 if (++(*(u16 *)page_to_inc) == p_chain->page_cnt)
352 *(u16 *)page_to_inc = 0;
353 page_index = *(u16 *)page_to_inc;
355 if (++(*(u32 *)page_to_inc) == p_chain->page_cnt)
356 *(u32 *)page_to_inc = 0;
357 page_index = *(u32 *)page_to_inc;
359 *p_next_elem = p_chain->pbl.pp_virt_addr_tbl[page_index];
363 #define is_unusable_idx(p, idx) \
364 (((p)->u.chain16.idx & (p)->elem_per_page_mask) == (p)->usable_per_page)
366 #define is_unusable_idx_u32(p, idx) \
367 (((p)->u.chain32.idx & (p)->elem_per_page_mask) == (p)->usable_per_page)
369 #define is_unusable_next_idx(p, idx) \
370 ((((p)->u.chain16.idx + 1) & (p)->elem_per_page_mask) == (p)->usable_per_page)
372 #define is_unusable_next_idx_u32(p, idx) \
373 ((((p)->u.chain32.idx + 1) & (p)->elem_per_page_mask) == (p)->usable_per_page)
375 #define test_and_skip(p, idx) \
377 if (is_chain_u16(p)) { \
378 if (is_unusable_idx(p, idx)) \
379 (p)->u.chain16.idx += (p)->elem_unusable; \
381 if (is_unusable_idx_u32(p, idx)) \
382 (p)->u.chain32.idx += (p)->elem_unusable; \
388 * @brief ecore_chain_return_multi_produced -
390 * A chain in which the driver "Produces" elements should use this API
391 * to indicate previous produced elements are now consumed.
397 void ecore_chain_return_multi_produced(struct ecore_chain *p_chain, u32 num)
399 if (is_chain_u16(p_chain))
400 p_chain->u.chain16.cons_idx += (u16)num;
402 p_chain->u.chain32.cons_idx += num;
403 test_and_skip(p_chain, cons_idx);
408 * @brief ecore_chain_return_produced -
410 * A chain in which the driver "Produces" elements should use this API
411 * to indicate previous produced elements are now consumed.
415 static OSAL_INLINE void ecore_chain_return_produced(struct ecore_chain *p_chain)
417 if (is_chain_u16(p_chain))
418 p_chain->u.chain16.cons_idx++;
420 p_chain->u.chain32.cons_idx++;
421 test_and_skip(p_chain, cons_idx);
425 * @brief ecore_chain_produce -
427 * A chain in which the driver "Produces" elements should use this to get
428 * a pointer to the next element which can be "Produced". It's driver
429 * responsibility to validate that the chain has room for new element.
433 * @return void*, a pointer to next element
435 static OSAL_INLINE void *ecore_chain_produce(struct ecore_chain *p_chain)
437 void *p_ret = OSAL_NULL, *p_prod_idx, *p_prod_page_idx;
439 if (is_chain_u16(p_chain)) {
440 if ((p_chain->u.chain16.prod_idx &
441 p_chain->elem_per_page_mask) ==
442 p_chain->next_page_mask) {
443 p_prod_idx = &p_chain->u.chain16.prod_idx;
444 p_prod_page_idx = &p_chain->pbl.c.pbl_u16.prod_page_idx;
445 ecore_chain_advance_page(p_chain, &p_chain->p_prod_elem,
446 p_prod_idx, p_prod_page_idx);
448 p_chain->u.chain16.prod_idx++;
450 if ((p_chain->u.chain32.prod_idx &
451 p_chain->elem_per_page_mask) ==
452 p_chain->next_page_mask) {
453 p_prod_idx = &p_chain->u.chain32.prod_idx;
454 p_prod_page_idx = &p_chain->pbl.c.pbl_u32.prod_page_idx;
455 ecore_chain_advance_page(p_chain, &p_chain->p_prod_elem,
456 p_prod_idx, p_prod_page_idx);
458 p_chain->u.chain32.prod_idx++;
461 p_ret = p_chain->p_prod_elem;
462 p_chain->p_prod_elem = (void*)(((u8*)p_chain->p_prod_elem) +
469 * @brief ecore_chain_get_capacity -
471 * Get the maximum number of BDs in chain
476 * @return number of unusable BDs
478 static OSAL_INLINE u32 ecore_chain_get_capacity(struct ecore_chain *p_chain)
480 return p_chain->capacity;
484 * @brief ecore_chain_recycle_consumed -
486 * Returns an element which was previously consumed;
487 * Increments producers so they could be written to FW.
492 void ecore_chain_recycle_consumed(struct ecore_chain *p_chain)
494 test_and_skip(p_chain, prod_idx);
495 if (is_chain_u16(p_chain))
496 p_chain->u.chain16.prod_idx++;
498 p_chain->u.chain32.prod_idx++;
502 * @brief ecore_chain_consume -
504 * A Chain in which the driver utilizes data written by a different source
505 * (i.e., FW) should use this to access passed buffers.
509 * @return void*, a pointer to the next buffer written
511 static OSAL_INLINE void *ecore_chain_consume(struct ecore_chain *p_chain)
513 void *p_ret = OSAL_NULL, *p_cons_idx, *p_cons_page_idx;
515 if (is_chain_u16(p_chain)) {
516 if ((p_chain->u.chain16.cons_idx &
517 p_chain->elem_per_page_mask) ==
518 p_chain->next_page_mask) {
519 p_cons_idx = &p_chain->u.chain16.cons_idx;
520 p_cons_page_idx = &p_chain->pbl.c.pbl_u16.cons_page_idx;
521 ecore_chain_advance_page(p_chain, &p_chain->p_cons_elem,
522 p_cons_idx, p_cons_page_idx);
524 p_chain->u.chain16.cons_idx++;
526 if ((p_chain->u.chain32.cons_idx &
527 p_chain->elem_per_page_mask) ==
528 p_chain->next_page_mask) {
529 p_cons_idx = &p_chain->u.chain32.cons_idx;
530 p_cons_page_idx = &p_chain->pbl.c.pbl_u32.cons_page_idx;
531 ecore_chain_advance_page(p_chain, &p_chain->p_cons_elem,
532 p_cons_idx, p_cons_page_idx);
534 p_chain->u.chain32.cons_idx++;
537 p_ret = p_chain->p_cons_elem;
538 p_chain->p_cons_elem = (void*)(((u8*)p_chain->p_cons_elem) +
545 * @brief ecore_chain_reset -
547 * Resets the chain to its start state
549 * @param p_chain pointer to a previously allocted chain
551 static OSAL_INLINE void ecore_chain_reset(struct ecore_chain *p_chain)
555 if (is_chain_u16(p_chain)) {
556 p_chain->u.chain16.prod_idx = 0;
557 p_chain->u.chain16.cons_idx = 0;
559 p_chain->u.chain32.prod_idx = 0;
560 p_chain->u.chain32.cons_idx = 0;
562 p_chain->p_cons_elem = p_chain->p_virt_addr;
563 p_chain->p_prod_elem = p_chain->p_virt_addr;
565 if (p_chain->mode == ECORE_CHAIN_MODE_PBL) {
566 /* Use "page_cnt-1" as a reset value for the prod/cons page's
567 * indices, to avoid unnecessary page advancing on the first
568 * call to ecore_chain_produce/consume. Instead, the indices
569 * will be advanced to page_cnt and then will be wrapped to 0.
571 u32 reset_val = p_chain->page_cnt - 1;
573 if (is_chain_u16(p_chain)) {
574 p_chain->pbl.c.pbl_u16.prod_page_idx = (u16)reset_val;
575 p_chain->pbl.c.pbl_u16.cons_page_idx = (u16)reset_val;
577 p_chain->pbl.c.pbl_u32.prod_page_idx = reset_val;
578 p_chain->pbl.c.pbl_u32.cons_page_idx = reset_val;
582 switch (p_chain->intended_use) {
583 case ECORE_CHAIN_USE_TO_CONSUME:
584 /* produce empty elements */
585 for (i = 0; i < p_chain->capacity; i++)
586 ecore_chain_recycle_consumed(p_chain);
589 case ECORE_CHAIN_USE_TO_CONSUME_PRODUCE:
590 case ECORE_CHAIN_USE_TO_PRODUCE:
598 * @brief ecore_chain_init_params -
600 * Initalizes a basic chain struct
603 * @param page_cnt number of pages in the allocated buffer
604 * @param elem_size size of each element in the chain
605 * @param intended_use
610 static OSAL_INLINE void
611 ecore_chain_init_params(struct ecore_chain *p_chain, u32 page_cnt, u8 elem_size,
612 enum ecore_chain_use_mode intended_use,
613 enum ecore_chain_mode mode,
614 enum ecore_chain_cnt_type cnt_type, void *dp_ctx)
616 /* chain fixed parameters */
617 p_chain->p_virt_addr = OSAL_NULL;
618 p_chain->p_phys_addr = 0;
619 p_chain->elem_size = elem_size;
620 p_chain->intended_use = (u8)intended_use;
621 p_chain->mode = mode;
622 p_chain->cnt_type = (u8)cnt_type;
624 p_chain->elem_per_page = ELEMS_PER_PAGE(elem_size);
625 p_chain->usable_per_page = USABLE_ELEMS_PER_PAGE(elem_size, mode);
626 p_chain->elem_per_page_mask = p_chain->elem_per_page - 1;
627 p_chain->elem_unusable = UNUSABLE_ELEMS_PER_PAGE(elem_size, mode);
628 p_chain->next_page_mask = (p_chain->usable_per_page &
629 p_chain->elem_per_page_mask);
631 p_chain->page_cnt = page_cnt;
632 p_chain->capacity = p_chain->usable_per_page * page_cnt;
633 p_chain->size = p_chain->elem_per_page * page_cnt;
634 p_chain->b_external_pbl = false;
635 p_chain->pbl_sp.p_phys_table = 0;
636 p_chain->pbl_sp.p_virt_table = OSAL_NULL;
637 p_chain->pbl.pp_virt_addr_tbl = OSAL_NULL;
639 p_chain->dp_ctx = dp_ctx;
643 * @brief ecore_chain_init_mem -
645 * Initalizes a basic chain struct with its chain buffers
648 * @param p_virt_addr virtual address of allocated buffer's beginning
649 * @param p_phys_addr physical address of allocated buffer's beginning
652 static OSAL_INLINE void ecore_chain_init_mem(struct ecore_chain *p_chain,
654 dma_addr_t p_phys_addr)
656 p_chain->p_virt_addr = p_virt_addr;
657 p_chain->p_phys_addr = p_phys_addr;
661 * @brief ecore_chain_init_pbl_mem -
663 * Initalizes a basic chain struct with its pbl buffers
666 * @param p_virt_pbl pointer to a pre allocated side table which will hold
667 * virtual page addresses.
668 * @param p_phys_pbl pointer to a pre-allocated side table which will hold
669 * physical page addresses.
670 * @param pp_virt_addr_tbl
671 * pointer to a pre-allocated side table which will hold
672 * the virtual addresses of the chain pages.
675 static OSAL_INLINE void ecore_chain_init_pbl_mem(struct ecore_chain *p_chain,
677 dma_addr_t p_phys_pbl,
678 void **pp_virt_addr_tbl)
680 p_chain->pbl_sp.p_phys_table = p_phys_pbl;
681 p_chain->pbl_sp.p_virt_table = p_virt_pbl;
682 p_chain->pbl.pp_virt_addr_tbl = pp_virt_addr_tbl;
686 * @brief ecore_chain_init_next_ptr_elem -
688 * Initalizes a next pointer element
691 * @param p_virt_curr virtual address of a chain page of which the next
692 * pointer element is initialized
693 * @param p_virt_next virtual address of the next chain page
694 * @param p_phys_next physical address of the next chain page
697 static OSAL_INLINE void
698 ecore_chain_init_next_ptr_elem(struct ecore_chain *p_chain, void *p_virt_curr,
699 void *p_virt_next, dma_addr_t p_phys_next)
701 struct ecore_chain_next *p_next;
704 size = p_chain->elem_size * p_chain->usable_per_page;
705 p_next = (struct ecore_chain_next *)((u8 *)p_virt_curr + size);
707 DMA_REGPAIR_LE(p_next->next_phys, p_phys_next);
709 p_next->next_virt = p_virt_next;
713 * @brief ecore_chain_get_last_elem -
715 * Returns a pointer to the last element of the chain
721 static OSAL_INLINE void *ecore_chain_get_last_elem(struct ecore_chain *p_chain)
723 struct ecore_chain_next *p_next = OSAL_NULL;
724 void *p_virt_addr = OSAL_NULL;
725 u32 size, last_page_idx;
727 if (!p_chain->p_virt_addr)
730 switch (p_chain->mode) {
731 case ECORE_CHAIN_MODE_NEXT_PTR:
732 size = p_chain->elem_size * p_chain->usable_per_page;
733 p_virt_addr = p_chain->p_virt_addr;
734 p_next = (struct ecore_chain_next *)((u8 *)p_virt_addr + size);
735 while (p_next->next_virt != p_chain->p_virt_addr) {
736 p_virt_addr = p_next->next_virt;
737 p_next = (struct ecore_chain_next *)((u8 *)p_virt_addr +
741 case ECORE_CHAIN_MODE_SINGLE:
742 p_virt_addr = p_chain->p_virt_addr;
744 case ECORE_CHAIN_MODE_PBL:
745 last_page_idx = p_chain->page_cnt - 1;
746 p_virt_addr = p_chain->pbl.pp_virt_addr_tbl[last_page_idx];
749 /* p_virt_addr points at this stage to the last page of the chain */
750 size = p_chain->elem_size * (p_chain->usable_per_page - 1);
751 p_virt_addr = (u8 *)p_virt_addr + size;
757 * @brief ecore_chain_set_prod - sets the prod to the given value
762 static OSAL_INLINE void ecore_chain_set_prod(struct ecore_chain *p_chain,
763 u32 prod_idx, void *p_prod_elem)
765 if (p_chain->mode == ECORE_CHAIN_MODE_PBL) {
766 /* Use "prod_idx-1" since ecore_chain_produce() advances the
767 * page index before the producer index when getting to
771 (prod_idx - 1 + p_chain->capacity) % p_chain->capacity;
772 u32 page_idx = elem_idx / p_chain->elem_per_page;
774 if (is_chain_u16(p_chain))
775 p_chain->pbl.c.pbl_u16.prod_page_idx = (u16)page_idx;
777 p_chain->pbl.c.pbl_u32.prod_page_idx = page_idx;
780 if (is_chain_u16(p_chain))
781 p_chain->u.chain16.prod_idx = (u16)prod_idx;
783 p_chain->u.chain32.prod_idx = prod_idx;
784 p_chain->p_prod_elem = p_prod_elem;
788 * @brief ecore_chain_set_cons - sets the cons to the given value
793 static OSAL_INLINE void ecore_chain_set_cons(struct ecore_chain *p_chain,
794 u32 cons_idx, void *p_cons_elem)
796 if (p_chain->mode == ECORE_CHAIN_MODE_PBL) {
797 /* Use "cons_idx-1" since ecore_chain_consume() advances the
798 * page index before the consumer index when getting to
802 (cons_idx - 1 + p_chain->capacity) % p_chain->capacity;
803 u32 page_idx = elem_idx / p_chain->elem_per_page;
805 if (is_chain_u16(p_chain))
806 p_chain->pbl.c.pbl_u16.cons_page_idx = (u16)page_idx;
808 p_chain->pbl.c.pbl_u32.cons_page_idx = page_idx;
811 if (is_chain_u16(p_chain))
812 p_chain->u.chain16.cons_idx = (u16)cons_idx;
814 p_chain->u.chain32.cons_idx = cons_idx;
816 p_chain->p_cons_elem = p_cons_elem;
820 * @brief ecore_chain_pbl_zero_mem - set chain memory to 0
824 static OSAL_INLINE void ecore_chain_pbl_zero_mem(struct ecore_chain *p_chain)
828 if (p_chain->mode != ECORE_CHAIN_MODE_PBL)
831 page_cnt = ecore_chain_get_page_cnt(p_chain);
833 for (i = 0; i < page_cnt; i++)
834 OSAL_MEM_ZERO(p_chain->pbl.pp_virt_addr_tbl[i],
835 ECORE_CHAIN_PAGE_SIZE);
838 int ecore_chain_print(struct ecore_chain *p_chain, char *buffer,
839 u32 buffer_size, u32 *element_indx, u32 stop_indx,
841 int (*func_ptr_print_element)(struct ecore_chain *p_chain,
844 int (*func_ptr_print_metadata)(struct ecore_chain *p_chain,
847 #endif /* __ECORE_CHAIN_H__ */