Commit 6d937acf authored by Mintz, Yuval's avatar Mintz, Yuval Committed by David S. Miller

qed: Optimize qed_chain datapath usage

The chain structure and functions are widely used by the qed* modules,
both for configuration and datapath.
E.g., qede's Tx has one such chain and its Rx has two.

Currently, the strucutre's fields which are required for datapath
related functions [produce/consume] are intertwined with fields which
are required only for configuration purposes [init/destroy/etc.].

This patch re-arranges the chain structure so that all the fields which
are required for datapath usage could reside in a single cacheline instead
of the two which are required today.
Signed-off-by: default avatarYuval Mintz <Yuval.Mintz@cavium.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 01e23015
...@@ -2283,12 +2283,12 @@ static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain) ...@@ -2283,12 +2283,12 @@ static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
{ {
void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl; void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
u32 page_cnt = p_chain->page_cnt, i, pbl_size; u32 page_cnt = p_chain->page_cnt, i, pbl_size;
u8 *p_pbl_virt = p_chain->pbl.p_virt_table; u8 *p_pbl_virt = p_chain->pbl_sp.p_virt_table;
if (!pp_virt_addr_tbl) if (!pp_virt_addr_tbl)
return; return;
if (!p_chain->pbl.p_virt_table) if (!p_pbl_virt)
goto out; goto out;
for (i = 0; i < page_cnt; i++) { for (i = 0; i < page_cnt; i++) {
...@@ -2306,7 +2306,8 @@ static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain) ...@@ -2306,7 +2306,8 @@ static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE; pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
dma_free_coherent(&cdev->pdev->dev, dma_free_coherent(&cdev->pdev->dev,
pbl_size, pbl_size,
p_chain->pbl.p_virt_table, p_chain->pbl.p_phys_table); p_chain->pbl_sp.p_virt_table,
p_chain->pbl_sp.p_phys_table);
out: out:
vfree(p_chain->pbl.pp_virt_addr_tbl); vfree(p_chain->pbl.pp_virt_addr_tbl);
} }
......
...@@ -347,11 +347,11 @@ int qed_sp_pf_start(struct qed_hwfn *p_hwfn, ...@@ -347,11 +347,11 @@ int qed_sp_pf_start(struct qed_hwfn *p_hwfn,
/* Place EQ address in RAMROD */ /* Place EQ address in RAMROD */
DMA_REGPAIR_LE(p_ramrod->event_ring_pbl_addr, DMA_REGPAIR_LE(p_ramrod->event_ring_pbl_addr,
p_hwfn->p_eq->chain.pbl.p_phys_table); p_hwfn->p_eq->chain.pbl_sp.p_phys_table);
page_cnt = (u8)qed_chain_get_page_cnt(&p_hwfn->p_eq->chain); page_cnt = (u8)qed_chain_get_page_cnt(&p_hwfn->p_eq->chain);
p_ramrod->event_ring_num_pages = page_cnt; p_ramrod->event_ring_num_pages = page_cnt;
DMA_REGPAIR_LE(p_ramrod->consolid_q_pbl_addr, DMA_REGPAIR_LE(p_ramrod->consolid_q_pbl_addr,
p_hwfn->p_consq->chain.pbl.p_phys_table); p_hwfn->p_consq->chain.pbl_sp.p_phys_table);
qed_tunn_set_pf_start_params(p_hwfn, p_tunn, &p_ramrod->tunnel_config); qed_tunn_set_pf_start_params(p_hwfn, p_tunn, &p_ramrod->tunnel_config);
......
...@@ -56,23 +56,6 @@ struct qed_chain_pbl_u32 { ...@@ -56,23 +56,6 @@ struct qed_chain_pbl_u32 {
u32 cons_page_idx; u32 cons_page_idx;
}; };
struct qed_chain_pbl {
/* Base address of a pre-allocated buffer for pbl */
dma_addr_t p_phys_table;
void *p_virt_table;
/* Table for keeping the virtual addresses of the chain pages,
* respectively to the physical addresses in the pbl table.
*/
void **pp_virt_addr_tbl;
/* Index to current used page by producer/consumer */
union {
struct qed_chain_pbl_u16 pbl16;
struct qed_chain_pbl_u32 pbl32;
} u;
};
struct qed_chain_u16 { struct qed_chain_u16 {
/* Cyclic index of next element to produce/consme */ /* Cyclic index of next element to produce/consme */
u16 prod_idx; u16 prod_idx;
...@@ -86,46 +69,78 @@ struct qed_chain_u32 { ...@@ -86,46 +69,78 @@ struct qed_chain_u32 {
}; };
struct qed_chain { struct qed_chain {
void *p_virt_addr; /* fastpath portion of the chain - required for commands such
dma_addr_t p_phys_addr; * as produce / consume.
void *p_prod_elem; */
void *p_cons_elem; /* Point to next element to produce/consume */
void *p_prod_elem;
void *p_cons_elem;
/* Fastpath portions of the PBL [if exists] */
struct {
/* Table for keeping the virtual addresses of the chain pages,
* respectively to the physical addresses in the pbl table.
*/
void **pp_virt_addr_tbl;
enum qed_chain_mode mode; union {
enum qed_chain_use_mode intended_use; /* used to produce/consume */ struct qed_chain_pbl_u16 u16;
enum qed_chain_cnt_type cnt_type; struct qed_chain_pbl_u32 u32;
} c;
} pbl;
union { union {
struct qed_chain_u16 chain16; struct qed_chain_u16 chain16;
struct qed_chain_u32 chain32; struct qed_chain_u32 chain32;
} u; } u;
/* Capacity counts only usable elements */
u32 capacity;
u32 page_cnt; u32 page_cnt;
/* Number of elements - capacity is for usable elements only, enum qed_chain_mode mode;
* while size will contain total number of elements [for entire chain].
/* Elements information for fast calculations */
u16 elem_per_page;
u16 elem_per_page_mask;
u16 elem_size;
u16 next_page_mask;
u16 usable_per_page;
u8 elem_unusable;
u8 cnt_type;
/* Slowpath of the chain - required for initialization and destruction,
* but isn't involved in regular functionality.
*/ */
u32 capacity;
/* Base address of a pre-allocated buffer for pbl */
struct {
dma_addr_t p_phys_table;
void *p_virt_table;
} pbl_sp;
/* Address of first page of the chain - the address is required
* for fastpath operation [consume/produce] but only for the the SINGLE
* flavour which isn't considered fastpath [== SPQ].
*/
void *p_virt_addr;
dma_addr_t p_phys_addr;
/* Total number of elements [for entire chain] */
u32 size; u32 size;
/* Elements information for fast calculations */ u8 intended_use;
u16 elem_per_page;
u16 elem_per_page_mask;
u16 elem_unusable;
u16 usable_per_page;
u16 elem_size;
u16 next_page_mask;
struct qed_chain_pbl pbl;
}; };
#define QED_CHAIN_PBL_ENTRY_SIZE (8) #define QED_CHAIN_PBL_ENTRY_SIZE (8)
#define QED_CHAIN_PAGE_SIZE (0x1000) #define QED_CHAIN_PAGE_SIZE (0x1000)
#define ELEMS_PER_PAGE(elem_size) (QED_CHAIN_PAGE_SIZE / (elem_size)) #define ELEMS_PER_PAGE(elem_size) (QED_CHAIN_PAGE_SIZE / (elem_size))
#define UNUSABLE_ELEMS_PER_PAGE(elem_size, mode) \ #define UNUSABLE_ELEMS_PER_PAGE(elem_size, mode) \
((mode == QED_CHAIN_MODE_NEXT_PTR) ? \ (((mode) == QED_CHAIN_MODE_NEXT_PTR) ? \
(1 + ((sizeof(struct qed_chain_next) - 1) / \ (u8)(1 + ((sizeof(struct qed_chain_next) - 1) / \
(elem_size))) : 0) (elem_size))) : 0)
#define USABLE_ELEMS_PER_PAGE(elem_size, mode) \ #define USABLE_ELEMS_PER_PAGE(elem_size, mode) \
((u32)(ELEMS_PER_PAGE(elem_size) - \ ((u32)(ELEMS_PER_PAGE(elem_size) - \
...@@ -186,7 +201,7 @@ static inline u16 qed_chain_get_usable_per_page(struct qed_chain *p_chain) ...@@ -186,7 +201,7 @@ static inline u16 qed_chain_get_usable_per_page(struct qed_chain *p_chain)
return p_chain->usable_per_page; return p_chain->usable_per_page;
} }
static inline u16 qed_chain_get_unusable_per_page(struct qed_chain *p_chain) static inline u8 qed_chain_get_unusable_per_page(struct qed_chain *p_chain)
{ {
return p_chain->elem_unusable; return p_chain->elem_unusable;
} }
...@@ -198,7 +213,7 @@ static inline u32 qed_chain_get_page_cnt(struct qed_chain *p_chain) ...@@ -198,7 +213,7 @@ static inline u32 qed_chain_get_page_cnt(struct qed_chain *p_chain)
static inline dma_addr_t qed_chain_get_pbl_phys(struct qed_chain *p_chain) static inline dma_addr_t qed_chain_get_pbl_phys(struct qed_chain *p_chain)
{ {
return p_chain->pbl.p_phys_table; return p_chain->pbl_sp.p_phys_table;
} }
/** /**
...@@ -214,10 +229,10 @@ static inline dma_addr_t qed_chain_get_pbl_phys(struct qed_chain *p_chain) ...@@ -214,10 +229,10 @@ static inline dma_addr_t qed_chain_get_pbl_phys(struct qed_chain *p_chain)
static inline void static inline void
qed_chain_advance_page(struct qed_chain *p_chain, qed_chain_advance_page(struct qed_chain *p_chain,
void **p_next_elem, void *idx_to_inc, void *page_to_inc) void **p_next_elem, void *idx_to_inc, void *page_to_inc)
{ {
struct qed_chain_next *p_next = NULL; struct qed_chain_next *p_next = NULL;
u32 page_index = 0; u32 page_index = 0;
switch (p_chain->mode) { switch (p_chain->mode) {
case QED_CHAIN_MODE_NEXT_PTR: case QED_CHAIN_MODE_NEXT_PTR:
p_next = *p_next_elem; p_next = *p_next_elem;
...@@ -305,7 +320,7 @@ static inline void *qed_chain_produce(struct qed_chain *p_chain) ...@@ -305,7 +320,7 @@ static inline void *qed_chain_produce(struct qed_chain *p_chain)
if ((p_chain->u.chain16.prod_idx & if ((p_chain->u.chain16.prod_idx &
p_chain->elem_per_page_mask) == p_chain->next_page_mask) { p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
p_prod_idx = &p_chain->u.chain16.prod_idx; p_prod_idx = &p_chain->u.chain16.prod_idx;
p_prod_page_idx = &p_chain->pbl.u.pbl16.prod_page_idx; p_prod_page_idx = &p_chain->pbl.c.u16.prod_page_idx;
qed_chain_advance_page(p_chain, &p_chain->p_prod_elem, qed_chain_advance_page(p_chain, &p_chain->p_prod_elem,
p_prod_idx, p_prod_page_idx); p_prod_idx, p_prod_page_idx);
} }
...@@ -314,7 +329,7 @@ static inline void *qed_chain_produce(struct qed_chain *p_chain) ...@@ -314,7 +329,7 @@ static inline void *qed_chain_produce(struct qed_chain *p_chain)
if ((p_chain->u.chain32.prod_idx & if ((p_chain->u.chain32.prod_idx &
p_chain->elem_per_page_mask) == p_chain->next_page_mask) { p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
p_prod_idx = &p_chain->u.chain32.prod_idx; p_prod_idx = &p_chain->u.chain32.prod_idx;
p_prod_page_idx = &p_chain->pbl.u.pbl32.prod_page_idx; p_prod_page_idx = &p_chain->pbl.c.u32.prod_page_idx;
qed_chain_advance_page(p_chain, &p_chain->p_prod_elem, qed_chain_advance_page(p_chain, &p_chain->p_prod_elem,
p_prod_idx, p_prod_page_idx); p_prod_idx, p_prod_page_idx);
} }
...@@ -378,7 +393,7 @@ static inline void *qed_chain_consume(struct qed_chain *p_chain) ...@@ -378,7 +393,7 @@ static inline void *qed_chain_consume(struct qed_chain *p_chain)
if ((p_chain->u.chain16.cons_idx & if ((p_chain->u.chain16.cons_idx &
p_chain->elem_per_page_mask) == p_chain->next_page_mask) { p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
p_cons_idx = &p_chain->u.chain16.cons_idx; p_cons_idx = &p_chain->u.chain16.cons_idx;
p_cons_page_idx = &p_chain->pbl.u.pbl16.cons_page_idx; p_cons_page_idx = &p_chain->pbl.c.u16.cons_page_idx;
qed_chain_advance_page(p_chain, &p_chain->p_cons_elem, qed_chain_advance_page(p_chain, &p_chain->p_cons_elem,
p_cons_idx, p_cons_page_idx); p_cons_idx, p_cons_page_idx);
} }
...@@ -387,8 +402,8 @@ static inline void *qed_chain_consume(struct qed_chain *p_chain) ...@@ -387,8 +402,8 @@ static inline void *qed_chain_consume(struct qed_chain *p_chain)
if ((p_chain->u.chain32.cons_idx & if ((p_chain->u.chain32.cons_idx &
p_chain->elem_per_page_mask) == p_chain->next_page_mask) { p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
p_cons_idx = &p_chain->u.chain32.cons_idx; p_cons_idx = &p_chain->u.chain32.cons_idx;
p_cons_page_idx = &p_chain->pbl.u.pbl32.cons_page_idx; p_cons_page_idx = &p_chain->pbl.c.u32.cons_page_idx;
qed_chain_advance_page(p_chain, &p_chain->p_cons_elem, qed_chain_advance_page(p_chain, &p_chain->p_cons_elem,
p_cons_idx, p_cons_page_idx); p_cons_idx, p_cons_page_idx);
} }
p_chain->u.chain32.cons_idx++; p_chain->u.chain32.cons_idx++;
...@@ -429,25 +444,26 @@ static inline void qed_chain_reset(struct qed_chain *p_chain) ...@@ -429,25 +444,26 @@ static inline void qed_chain_reset(struct qed_chain *p_chain)
u32 reset_val = p_chain->page_cnt - 1; u32 reset_val = p_chain->page_cnt - 1;
if (is_chain_u16(p_chain)) { if (is_chain_u16(p_chain)) {
p_chain->pbl.u.pbl16.prod_page_idx = (u16)reset_val; p_chain->pbl.c.u16.prod_page_idx = (u16)reset_val;
p_chain->pbl.u.pbl16.cons_page_idx = (u16)reset_val; p_chain->pbl.c.u16.cons_page_idx = (u16)reset_val;
} else { } else {
p_chain->pbl.u.pbl32.prod_page_idx = reset_val; p_chain->pbl.c.u32.prod_page_idx = reset_val;
p_chain->pbl.u.pbl32.cons_page_idx = reset_val; p_chain->pbl.c.u32.cons_page_idx = reset_val;
} }
} }
switch (p_chain->intended_use) { switch (p_chain->intended_use) {
case QED_CHAIN_USE_TO_CONSUME_PRODUCE:
case QED_CHAIN_USE_TO_PRODUCE:
/* Do nothing */
break;
case QED_CHAIN_USE_TO_CONSUME: case QED_CHAIN_USE_TO_CONSUME:
/* produce empty elements */ /* produce empty elements */
for (i = 0; i < p_chain->capacity; i++) for (i = 0; i < p_chain->capacity; i++)
qed_chain_recycle_consumed(p_chain); qed_chain_recycle_consumed(p_chain);
break; break;
case QED_CHAIN_USE_TO_CONSUME_PRODUCE:
case QED_CHAIN_USE_TO_PRODUCE:
default:
/* Do nothing */
break;
} }
} }
...@@ -473,13 +489,13 @@ static inline void qed_chain_init_params(struct qed_chain *p_chain, ...@@ -473,13 +489,13 @@ static inline void qed_chain_init_params(struct qed_chain *p_chain,
p_chain->p_virt_addr = NULL; p_chain->p_virt_addr = NULL;
p_chain->p_phys_addr = 0; p_chain->p_phys_addr = 0;
p_chain->elem_size = elem_size; p_chain->elem_size = elem_size;
p_chain->intended_use = intended_use; p_chain->intended_use = (u8)intended_use;
p_chain->mode = mode; p_chain->mode = mode;
p_chain->cnt_type = cnt_type; p_chain->cnt_type = (u8)cnt_type;
p_chain->elem_per_page = ELEMS_PER_PAGE(elem_size); p_chain->elem_per_page = ELEMS_PER_PAGE(elem_size);
p_chain->usable_per_page = USABLE_ELEMS_PER_PAGE(elem_size, mode); p_chain->usable_per_page = USABLE_ELEMS_PER_PAGE(elem_size, mode);
p_chain->elem_per_page_mask = p_chain->elem_per_page - 1; p_chain->elem_per_page_mask = p_chain->elem_per_page - 1;
p_chain->elem_unusable = UNUSABLE_ELEMS_PER_PAGE(elem_size, mode); p_chain->elem_unusable = UNUSABLE_ELEMS_PER_PAGE(elem_size, mode);
p_chain->next_page_mask = (p_chain->usable_per_page & p_chain->next_page_mask = (p_chain->usable_per_page &
p_chain->elem_per_page_mask); p_chain->elem_per_page_mask);
...@@ -488,8 +504,8 @@ static inline void qed_chain_init_params(struct qed_chain *p_chain, ...@@ -488,8 +504,8 @@ static inline void qed_chain_init_params(struct qed_chain *p_chain,
p_chain->capacity = p_chain->usable_per_page * page_cnt; p_chain->capacity = p_chain->usable_per_page * page_cnt;
p_chain->size = p_chain->elem_per_page * page_cnt; p_chain->size = p_chain->elem_per_page * page_cnt;
p_chain->pbl.p_phys_table = 0; p_chain->pbl_sp.p_phys_table = 0;
p_chain->pbl.p_virt_table = NULL; p_chain->pbl_sp.p_virt_table = NULL;
p_chain->pbl.pp_virt_addr_tbl = NULL; p_chain->pbl.pp_virt_addr_tbl = NULL;
} }
...@@ -530,8 +546,8 @@ static inline void qed_chain_init_pbl_mem(struct qed_chain *p_chain, ...@@ -530,8 +546,8 @@ static inline void qed_chain_init_pbl_mem(struct qed_chain *p_chain,
dma_addr_t p_phys_pbl, dma_addr_t p_phys_pbl,
void **pp_virt_addr_tbl) void **pp_virt_addr_tbl)
{ {
p_chain->pbl.p_phys_table = p_phys_pbl; p_chain->pbl_sp.p_phys_table = p_phys_pbl;
p_chain->pbl.p_virt_table = p_virt_pbl; p_chain->pbl_sp.p_virt_table = p_virt_pbl;
p_chain->pbl.pp_virt_addr_tbl = pp_virt_addr_tbl; p_chain->pbl.pp_virt_addr_tbl = pp_virt_addr_tbl;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment