Skip to content

Commit

Permalink
qed: introduce qed_chain_get_elem_used{,u32}()
Browse files Browse the repository at this point in the history
Add reverse-variants of qed_chain_get_elem_left{,u32}() to be able to
know current chain occupation. They will be used in the upcoming qede
XDP_REDIRECT code.
They share most of the logics with the mentioned ones, so were reused
to collapse the latters.

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>
  • Loading branch information
Alexander Lobakin authored and David S. Miller committed Jul 23, 2020
1 parent f2aefd2 commit be0cec6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions include/linux/qed/qed_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static inline u32 qed_chain_get_cons_idx_u32(const struct qed_chain *chain)
return chain->u.chain32.cons_idx;
}

static inline u16 qed_chain_get_elem_left(const struct qed_chain *chain)
static inline u16 qed_chain_get_elem_used(const struct qed_chain *chain)
{
u32 prod = qed_chain_get_prod_idx(chain);
u32 cons = qed_chain_get_cons_idx(chain);
Expand All @@ -217,10 +217,15 @@ static inline u16 qed_chain_get_elem_left(const struct qed_chain *chain)
if (chain->mode == QED_CHAIN_MODE_NEXT_PTR)
used -= (u16)(prod / elem_per_page - cons / elem_per_page);

return (u16)(chain->capacity - used);
return used;
}

static inline u32 qed_chain_get_elem_left_u32(const struct qed_chain *chain)
static inline u16 qed_chain_get_elem_left(const struct qed_chain *chain)
{
return (u16)(chain->capacity - qed_chain_get_elem_used(chain));
}

static inline u32 qed_chain_get_elem_used_u32(const struct qed_chain *chain)
{
u64 prod = qed_chain_get_prod_idx_u32(chain);
u64 cons = qed_chain_get_cons_idx_u32(chain);
Expand All @@ -234,7 +239,12 @@ static inline u32 qed_chain_get_elem_left_u32(const struct qed_chain *chain)
if (chain->mode == QED_CHAIN_MODE_NEXT_PTR)
used -= (u32)(prod / elem_per_page - cons / elem_per_page);

return chain->capacity - used;
return used;
}

static inline u32 qed_chain_get_elem_left_u32(const struct qed_chain *chain)
{
return chain->capacity - qed_chain_get_elem_used_u32(chain);
}

static inline u16 qed_chain_get_usable_per_page(const struct qed_chain *chain)
Expand Down

0 comments on commit be0cec6

Please sign in to comment.