net: qed: fix left elements count calculation

qed_chain_get_element_left{,_u32} returned 0 when the difference
between producer and consumer page count was equal to the total
page count.
Fix this by conditional expanding of producer value (vs
unconditional). This allowed to eliminate normalizaton against
total page count, which was the cause of this bug.

Misc: replace open-coded constants with common defines.

Fixes: a91eb52abb ("qed: Revisit chain implementation")
Signed-off-by: Alexander Lobakin <alobakin@marvell.com>
Signed-off-by: Igor Russkikh <irusskikh@marvell.com>
Signed-off-by: Michal Kalderon <michal.kalderon@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Alexander Lobakin 2020-06-23 16:51:29 +03:00 committed by David S. Miller
parent b4730ae6a4
commit 97dd1abd02
1 changed files with 16 additions and 10 deletions

View File

@ -207,28 +207,34 @@ static inline u32 qed_chain_get_cons_idx_u32(struct qed_chain *p_chain)
static inline u16 qed_chain_get_elem_left(struct qed_chain *p_chain)
{
u16 elem_per_page = p_chain->elem_per_page;
u32 prod = p_chain->u.chain16.prod_idx;
u32 cons = p_chain->u.chain16.cons_idx;
u16 used;
used = (u16) (((u32)0x10000 +
(u32)p_chain->u.chain16.prod_idx) -
(u32)p_chain->u.chain16.cons_idx);
if (prod < cons)
prod += (u32)U16_MAX + 1;
used = (u16)(prod - cons);
if (p_chain->mode == QED_CHAIN_MODE_NEXT_PTR)
used -= p_chain->u.chain16.prod_idx / p_chain->elem_per_page -
p_chain->u.chain16.cons_idx / p_chain->elem_per_page;
used -= prod / elem_per_page - cons / elem_per_page;
return (u16)(p_chain->capacity - used);
}
static inline u32 qed_chain_get_elem_left_u32(struct qed_chain *p_chain)
{
u16 elem_per_page = p_chain->elem_per_page;
u64 prod = p_chain->u.chain32.prod_idx;
u64 cons = p_chain->u.chain32.cons_idx;
u32 used;
used = (u32) (((u64)0x100000000ULL +
(u64)p_chain->u.chain32.prod_idx) -
(u64)p_chain->u.chain32.cons_idx);
if (prod < cons)
prod += (u64)U32_MAX + 1;
used = (u32)(prod - cons);
if (p_chain->mode == QED_CHAIN_MODE_NEXT_PTR)
used -= p_chain->u.chain32.prod_idx / p_chain->elem_per_page -
p_chain->u.chain32.cons_idx / p_chain->elem_per_page;
used -= (u32)(prod / elem_per_page - cons / elem_per_page);
return p_chain->capacity - used;
}