2020-06-29 19:05:08 +08:00
|
|
|
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
|
2015-10-26 17:02:25 +08:00
|
|
|
/* QLogic qed NIC Driver
|
2017-01-01 19:57:00 +08:00
|
|
|
* Copyright (c) 2015-2017 QLogic Corporation
|
2020-06-29 19:05:09 +08:00
|
|
|
* Copyright (c) 2019-2020 Marvell International Ltd.
|
2015-10-26 17:02:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _QED_CHAIN_H
|
|
|
|
#define _QED_CHAIN_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/list.h>
|
2020-07-23 06:10:39 +08:00
|
|
|
#include <linux/sizes.h>
|
2015-10-26 17:02:25 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/qed/common_hsi.h>
|
|
|
|
|
|
|
|
enum qed_chain_mode {
|
|
|
|
/* Each Page contains a next pointer at its end */
|
|
|
|
QED_CHAIN_MODE_NEXT_PTR,
|
|
|
|
|
|
|
|
/* Chain is a single page (next ptr) is unrequired */
|
|
|
|
QED_CHAIN_MODE_SINGLE,
|
|
|
|
|
|
|
|
/* Page pointers are located in a side list */
|
|
|
|
QED_CHAIN_MODE_PBL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum qed_chain_use_mode {
|
2020-07-23 06:10:31 +08:00
|
|
|
QED_CHAIN_USE_TO_PRODUCE, /* Chain starts empty */
|
|
|
|
QED_CHAIN_USE_TO_CONSUME, /* Chain starts full */
|
|
|
|
QED_CHAIN_USE_TO_CONSUME_PRODUCE, /* Chain starts empty */
|
2015-10-26 17:02:25 +08:00
|
|
|
};
|
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
enum qed_chain_cnt_type {
|
|
|
|
/* The chain's size/prod/cons are kept in 16-bit variables */
|
|
|
|
QED_CHAIN_CNT_TYPE_U16,
|
|
|
|
|
|
|
|
/* The chain's size/prod/cons are kept in 32-bit variables */
|
|
|
|
QED_CHAIN_CNT_TYPE_U32,
|
|
|
|
};
|
|
|
|
|
2015-10-26 17:02:25 +08:00
|
|
|
struct qed_chain_next {
|
2020-07-23 06:10:31 +08:00
|
|
|
struct regpair next_phys;
|
|
|
|
void *next_virt;
|
2015-10-26 17:02:25 +08:00
|
|
|
};
|
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
struct qed_chain_pbl_u16 {
|
2020-07-23 06:10:31 +08:00
|
|
|
u16 prod_page_idx;
|
|
|
|
u16 cons_page_idx;
|
2016-06-03 19:35:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct qed_chain_pbl_u32 {
|
2020-07-23 06:10:31 +08:00
|
|
|
u32 prod_page_idx;
|
|
|
|
u32 cons_page_idx;
|
2016-06-03 19:35:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct qed_chain_u16 {
|
|
|
|
/* Cyclic index of next element to produce/consme */
|
2020-07-23 06:10:31 +08:00
|
|
|
u16 prod_idx;
|
|
|
|
u16 cons_idx;
|
2016-06-03 19:35:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct qed_chain_u32 {
|
|
|
|
/* Cyclic index of next element to produce/consme */
|
2020-07-23 06:10:31 +08:00
|
|
|
u32 prod_idx;
|
|
|
|
u32 cons_idx;
|
2015-10-26 17:02:25 +08:00
|
|
|
};
|
|
|
|
|
2020-03-30 01:32:49 +08:00
|
|
|
struct addr_tbl_entry {
|
2020-07-23 06:10:31 +08:00
|
|
|
void *virt_addr;
|
|
|
|
dma_addr_t dma_map;
|
2020-03-30 01:32:49 +08:00
|
|
|
};
|
|
|
|
|
2015-10-26 17:02:25 +08:00
|
|
|
struct qed_chain {
|
2020-07-23 06:10:31 +08:00
|
|
|
/* Fastpath portion of the chain - required for commands such
|
2016-11-29 22:47:01 +08:00
|
|
|
* as produce / consume.
|
|
|
|
*/
|
2020-07-23 06:10:31 +08:00
|
|
|
|
2016-11-29 22:47:01 +08:00
|
|
|
/* Point to next element to produce/consume */
|
2020-07-23 06:10:31 +08:00
|
|
|
void *p_prod_elem;
|
|
|
|
void *p_cons_elem;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
|
|
|
/* Fastpath portions of the PBL [if exists] */
|
2020-07-23 06:10:31 +08:00
|
|
|
|
2016-11-29 22:47:01 +08:00
|
|
|
struct {
|
2020-03-30 01:32:49 +08:00
|
|
|
/* Table for keeping the virtual and physical addresses of the
|
|
|
|
* chain pages, respectively to the physical addresses
|
|
|
|
* in the pbl table.
|
2016-11-29 22:47:01 +08:00
|
|
|
*/
|
2020-07-23 06:10:31 +08:00
|
|
|
struct addr_tbl_entry *pp_addr_tbl;
|
2016-06-03 19:35:32 +08:00
|
|
|
|
2016-11-29 22:47:01 +08:00
|
|
|
union {
|
2020-07-23 06:10:31 +08:00
|
|
|
struct qed_chain_pbl_u16 u16;
|
|
|
|
struct qed_chain_pbl_u32 u32;
|
|
|
|
} c;
|
|
|
|
} pbl;
|
2016-06-03 19:35:32 +08:00
|
|
|
|
|
|
|
union {
|
2020-07-23 06:10:31 +08:00
|
|
|
struct qed_chain_u16 chain16;
|
|
|
|
struct qed_chain_u32 chain32;
|
|
|
|
} u;
|
2016-06-03 19:35:32 +08:00
|
|
|
|
2016-11-29 22:47:01 +08:00
|
|
|
/* Capacity counts only usable elements */
|
2020-07-23 06:10:31 +08:00
|
|
|
u32 capacity;
|
|
|
|
u32 page_cnt;
|
2016-06-03 19:35:32 +08:00
|
|
|
|
2020-07-23 06:10:31 +08:00
|
|
|
enum qed_chain_mode mode;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
|
|
|
/* Elements information for fast calculations */
|
2020-07-23 06:10:31 +08:00
|
|
|
u16 elem_per_page;
|
|
|
|
u16 elem_per_page_mask;
|
|
|
|
u16 elem_size;
|
|
|
|
u16 next_page_mask;
|
|
|
|
u16 usable_per_page;
|
|
|
|
u8 elem_unusable;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
2020-07-23 06:10:38 +08:00
|
|
|
enum qed_chain_cnt_type cnt_type;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
|
|
|
/* Slowpath of the chain - required for initialization and destruction,
|
|
|
|
* but isn't involved in regular functionality.
|
2016-06-03 19:35:32 +08:00
|
|
|
*/
|
2016-11-29 22:47:01 +08:00
|
|
|
|
2020-07-23 06:10:39 +08:00
|
|
|
u32 page_size;
|
|
|
|
|
2016-11-29 22:47:01 +08:00
|
|
|
/* Base address of a pre-allocated buffer for pbl */
|
|
|
|
struct {
|
2020-07-23 06:10:35 +08:00
|
|
|
__le64 *table_virt;
|
|
|
|
dma_addr_t table_phys;
|
|
|
|
size_t table_size;
|
2020-07-23 06:10:31 +08:00
|
|
|
} pbl_sp;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
|
|
|
/* Address of first page of the chain - the address is required
|
2020-07-16 00:42:38 +08:00
|
|
|
* for fastpath operation [consume/produce] but only for the SINGLE
|
2016-11-29 22:47:01 +08:00
|
|
|
* flavour which isn't considered fastpath [== SPQ].
|
|
|
|
*/
|
2020-07-23 06:10:31 +08:00
|
|
|
void *p_virt_addr;
|
|
|
|
dma_addr_t p_phys_addr;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
|
|
|
/* Total number of elements [for entire chain] */
|
2020-07-23 06:10:31 +08:00
|
|
|
u32 size;
|
2016-06-03 19:35:32 +08:00
|
|
|
|
2020-07-23 06:10:38 +08:00
|
|
|
enum qed_chain_use_mode intended_use;
|
2017-06-20 21:00:00 +08:00
|
|
|
|
2020-07-23 06:10:31 +08:00
|
|
|
bool b_external_pbl;
|
2015-10-26 17:02:25 +08:00
|
|
|
};
|
|
|
|
|
2020-07-23 06:10:38 +08:00
|
|
|
struct qed_chain_init_params {
|
|
|
|
enum qed_chain_mode mode;
|
|
|
|
enum qed_chain_use_mode intended_use;
|
|
|
|
enum qed_chain_cnt_type cnt_type;
|
|
|
|
|
2020-07-23 06:10:39 +08:00
|
|
|
u32 page_size;
|
2020-07-23 06:10:38 +08:00
|
|
|
u32 num_elems;
|
|
|
|
size_t elem_size;
|
|
|
|
|
|
|
|
void *ext_pbl_virt;
|
|
|
|
dma_addr_t ext_pbl_phys;
|
|
|
|
};
|
|
|
|
|
2020-07-23 06:10:39 +08:00
|
|
|
#define QED_CHAIN_PAGE_SIZE SZ_4K
|
2020-07-23 06:10:31 +08:00
|
|
|
|
2020-07-23 06:10:39 +08:00
|
|
|
#define ELEMS_PER_PAGE(elem_size, page_size) \
|
|
|
|
((page_size) / (elem_size))
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2020-07-23 06:10:31 +08:00
|
|
|
#define UNUSABLE_ELEMS_PER_PAGE(elem_size, mode) \
|
|
|
|
(((mode) == QED_CHAIN_MODE_NEXT_PTR) ? \
|
|
|
|
(u8)(1 + ((sizeof(struct qed_chain_next) - 1) / (elem_size))) : \
|
|
|
|
0)
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2020-07-23 06:10:39 +08:00
|
|
|
#define USABLE_ELEMS_PER_PAGE(elem_size, page_size, mode) \
|
|
|
|
((u32)(ELEMS_PER_PAGE((elem_size), (page_size)) - \
|
2020-07-23 06:10:31 +08:00
|
|
|
UNUSABLE_ELEMS_PER_PAGE((elem_size), (mode))))
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2020-07-23 06:10:39 +08:00
|
|
|
#define QED_CHAIN_PAGE_CNT(elem_cnt, elem_size, page_size, mode) \
|
|
|
|
DIV_ROUND_UP((elem_cnt), \
|
|
|
|
USABLE_ELEMS_PER_PAGE((elem_size), (page_size), (mode)))
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2020-07-23 06:10:31 +08:00
|
|
|
#define is_chain_u16(p) \
|
|
|
|
((p)->cnt_type == QED_CHAIN_CNT_TYPE_U16)
|
|
|
|
#define is_chain_u32(p) \
|
|
|
|
((p)->cnt_type == QED_CHAIN_CNT_TYPE_U32)
|
2016-06-03 19:35:32 +08:00
|
|
|
|
2015-10-26 17:02:25 +08:00
|
|
|
/* Accessors */
|
2020-07-23 06:10:40 +08:00
|
|
|
|
|
|
|
static inline u16 qed_chain_get_prod_idx(const struct qed_chain *chain)
|
|
|
|
{
|
|
|
|
return chain->u.chain16.prod_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u16 qed_chain_get_cons_idx(const struct qed_chain *chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
return chain->u.chain16.cons_idx;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:40 +08:00
|
|
|
static inline u32 qed_chain_get_prod_idx_u32(const struct qed_chain *chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
return chain->u.chain32.prod_idx;
|
2016-06-03 19:35:32 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:40 +08:00
|
|
|
static inline u32 qed_chain_get_cons_idx_u32(const struct qed_chain *chain)
|
2016-06-03 19:35:32 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
return chain->u.chain32.cons_idx;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:41 +08:00
|
|
|
static inline u16 qed_chain_get_elem_used(const struct qed_chain *chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
u32 prod = qed_chain_get_prod_idx(chain);
|
|
|
|
u32 cons = qed_chain_get_cons_idx(chain);
|
|
|
|
u16 elem_per_page = chain->elem_per_page;
|
2015-10-26 17:02:25 +08:00
|
|
|
u16 used;
|
|
|
|
|
2020-06-23 21:51:29 +08:00
|
|
|
if (prod < cons)
|
|
|
|
prod += (u32)U16_MAX + 1;
|
|
|
|
|
|
|
|
used = (u16)(prod - cons);
|
2020-07-23 06:10:40 +08:00
|
|
|
if (chain->mode == QED_CHAIN_MODE_NEXT_PTR)
|
|
|
|
used -= (u16)(prod / elem_per_page - cons / elem_per_page);
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2020-07-23 06:10:41 +08:00
|
|
|
return used;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:41 +08:00
|
|
|
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)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
u64 prod = qed_chain_get_prod_idx_u32(chain);
|
|
|
|
u64 cons = qed_chain_get_cons_idx_u32(chain);
|
|
|
|
u16 elem_per_page = chain->elem_per_page;
|
2016-06-03 19:35:32 +08:00
|
|
|
u32 used;
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2020-06-23 21:51:29 +08:00
|
|
|
if (prod < cons)
|
|
|
|
prod += (u64)U32_MAX + 1;
|
|
|
|
|
|
|
|
used = (u32)(prod - cons);
|
2020-07-23 06:10:40 +08:00
|
|
|
if (chain->mode == QED_CHAIN_MODE_NEXT_PTR)
|
2020-06-23 21:51:29 +08:00
|
|
|
used -= (u32)(prod / elem_per_page - cons / elem_per_page);
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2020-07-23 06:10:41 +08:00
|
|
|
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);
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:40 +08:00
|
|
|
static inline u16 qed_chain_get_usable_per_page(const struct qed_chain *chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
return chain->usable_per_page;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:40 +08:00
|
|
|
static inline u8 qed_chain_get_unusable_per_page(const struct qed_chain *chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
return chain->elem_unusable;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:40 +08:00
|
|
|
static inline u32 qed_chain_get_page_cnt(const struct qed_chain *chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
return chain->page_cnt;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2020-07-23 06:10:40 +08:00
|
|
|
static inline dma_addr_t qed_chain_get_pbl_phys(const struct qed_chain *chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2020-07-23 06:10:40 +08:00
|
|
|
return chain->pbl_sp.table_phys;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_advance_page -
|
|
|
|
*
|
|
|
|
* Advance the next element accros pages for a linked chain
|
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
* @param p_next_elem
|
|
|
|
* @param idx_to_inc
|
|
|
|
* @param page_to_inc
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
qed_chain_advance_page(struct qed_chain *p_chain,
|
2016-06-03 19:35:32 +08:00
|
|
|
void **p_next_elem, void *idx_to_inc, void *page_to_inc)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
struct qed_chain_next *p_next = NULL;
|
|
|
|
u32 page_index = 0;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
2015-10-26 17:02:25 +08:00
|
|
|
switch (p_chain->mode) {
|
|
|
|
case QED_CHAIN_MODE_NEXT_PTR:
|
2016-06-03 19:35:32 +08:00
|
|
|
p_next = *p_next_elem;
|
2015-10-26 17:02:25 +08:00
|
|
|
*p_next_elem = p_next->next_virt;
|
2016-06-03 19:35:32 +08:00
|
|
|
if (is_chain_u16(p_chain))
|
|
|
|
*(u16 *)idx_to_inc += p_chain->elem_unusable;
|
|
|
|
else
|
|
|
|
*(u32 *)idx_to_inc += p_chain->elem_unusable;
|
2015-10-26 17:02:25 +08:00
|
|
|
break;
|
|
|
|
case QED_CHAIN_MODE_SINGLE:
|
|
|
|
*p_next_elem = p_chain->p_virt_addr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QED_CHAIN_MODE_PBL:
|
2016-06-03 19:35:32 +08:00
|
|
|
if (is_chain_u16(p_chain)) {
|
|
|
|
if (++(*(u16 *)page_to_inc) == p_chain->page_cnt)
|
|
|
|
*(u16 *)page_to_inc = 0;
|
|
|
|
page_index = *(u16 *)page_to_inc;
|
|
|
|
} else {
|
|
|
|
if (++(*(u32 *)page_to_inc) == p_chain->page_cnt)
|
|
|
|
*(u32 *)page_to_inc = 0;
|
|
|
|
page_index = *(u32 *)page_to_inc;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
2020-03-30 01:32:49 +08:00
|
|
|
*p_next_elem = p_chain->pbl.pp_addr_tbl[page_index].virt_addr;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define is_unusable_idx(p, idx) \
|
2016-06-03 19:35:32 +08:00
|
|
|
(((p)->u.chain16.idx & (p)->elem_per_page_mask) == (p)->usable_per_page)
|
|
|
|
|
|
|
|
#define is_unusable_idx_u32(p, idx) \
|
|
|
|
(((p)->u.chain32.idx & (p)->elem_per_page_mask) == (p)->usable_per_page)
|
|
|
|
#define is_unusable_next_idx(p, idx) \
|
|
|
|
((((p)->u.chain16.idx + 1) & (p)->elem_per_page_mask) == \
|
|
|
|
(p)->usable_per_page)
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
#define is_unusable_next_idx_u32(p, idx) \
|
|
|
|
((((p)->u.chain32.idx + 1) & (p)->elem_per_page_mask) == \
|
|
|
|
(p)->usable_per_page)
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
#define test_and_skip(p, idx) \
|
2015-10-26 17:02:25 +08:00
|
|
|
do { \
|
2016-06-03 19:35:32 +08:00
|
|
|
if (is_chain_u16(p)) { \
|
|
|
|
if (is_unusable_idx(p, idx)) \
|
|
|
|
(p)->u.chain16.idx += (p)->elem_unusable; \
|
|
|
|
} else { \
|
|
|
|
if (is_unusable_idx_u32(p, idx)) \
|
|
|
|
(p)->u.chain32.idx += (p)->elem_unusable; \
|
2015-10-26 17:02:25 +08:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_return_produced -
|
|
|
|
*
|
|
|
|
* A chain in which the driver "Produces" elements should use this API
|
|
|
|
* to indicate previous produced elements are now consumed.
|
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
*/
|
|
|
|
static inline void qed_chain_return_produced(struct qed_chain *p_chain)
|
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
if (is_chain_u16(p_chain))
|
|
|
|
p_chain->u.chain16.cons_idx++;
|
|
|
|
else
|
|
|
|
p_chain->u.chain32.cons_idx++;
|
|
|
|
test_and_skip(p_chain, cons_idx);
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_produce -
|
|
|
|
*
|
|
|
|
* A chain in which the driver "Produces" elements should use this to get
|
|
|
|
* a pointer to the next element which can be "Produced". It's driver
|
|
|
|
* responsibility to validate that the chain has room for new element.
|
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
*
|
|
|
|
* @return void*, a pointer to next element
|
|
|
|
*/
|
|
|
|
static inline void *qed_chain_produce(struct qed_chain *p_chain)
|
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
void *p_ret = NULL, *p_prod_idx, *p_prod_page_idx;
|
|
|
|
|
|
|
|
if (is_chain_u16(p_chain)) {
|
|
|
|
if ((p_chain->u.chain16.prod_idx &
|
|
|
|
p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
|
|
|
|
p_prod_idx = &p_chain->u.chain16.prod_idx;
|
2016-11-29 22:47:01 +08:00
|
|
|
p_prod_page_idx = &p_chain->pbl.c.u16.prod_page_idx;
|
2016-06-03 19:35:32 +08:00
|
|
|
qed_chain_advance_page(p_chain, &p_chain->p_prod_elem,
|
|
|
|
p_prod_idx, p_prod_page_idx);
|
|
|
|
}
|
|
|
|
p_chain->u.chain16.prod_idx++;
|
|
|
|
} else {
|
|
|
|
if ((p_chain->u.chain32.prod_idx &
|
|
|
|
p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
|
|
|
|
p_prod_idx = &p_chain->u.chain32.prod_idx;
|
2016-11-29 22:47:01 +08:00
|
|
|
p_prod_page_idx = &p_chain->pbl.c.u32.prod_page_idx;
|
2016-06-03 19:35:32 +08:00
|
|
|
qed_chain_advance_page(p_chain, &p_chain->p_prod_elem,
|
|
|
|
p_prod_idx, p_prod_page_idx);
|
|
|
|
}
|
|
|
|
p_chain->u.chain32.prod_idx++;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
p_ret = p_chain->p_prod_elem;
|
2015-10-26 17:02:25 +08:00
|
|
|
p_chain->p_prod_elem = (void *)(((u8 *)p_chain->p_prod_elem) +
|
|
|
|
p_chain->elem_size);
|
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
return p_ret;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_get_capacity -
|
|
|
|
*
|
|
|
|
* Get the maximum number of BDs in chain
|
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
* @param num
|
|
|
|
*
|
2016-06-03 19:35:32 +08:00
|
|
|
* @return number of unusable BDs
|
2015-10-26 17:02:25 +08:00
|
|
|
*/
|
2016-06-03 19:35:32 +08:00
|
|
|
static inline u32 qed_chain_get_capacity(struct qed_chain *p_chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
|
|
|
return p_chain->capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_recycle_consumed -
|
|
|
|
*
|
|
|
|
* Returns an element which was previously consumed;
|
|
|
|
* Increments producers so they could be written to FW.
|
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
*/
|
2016-06-03 19:35:32 +08:00
|
|
|
static inline void qed_chain_recycle_consumed(struct qed_chain *p_chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
test_and_skip(p_chain, prod_idx);
|
|
|
|
if (is_chain_u16(p_chain))
|
|
|
|
p_chain->u.chain16.prod_idx++;
|
|
|
|
else
|
|
|
|
p_chain->u.chain32.prod_idx++;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_consume -
|
|
|
|
*
|
|
|
|
* A Chain in which the driver utilizes data written by a different source
|
|
|
|
* (i.e., FW) should use this to access passed buffers.
|
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
*
|
|
|
|
* @return void*, a pointer to the next buffer written
|
|
|
|
*/
|
|
|
|
static inline void *qed_chain_consume(struct qed_chain *p_chain)
|
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
void *p_ret = NULL, *p_cons_idx, *p_cons_page_idx;
|
|
|
|
|
|
|
|
if (is_chain_u16(p_chain)) {
|
|
|
|
if ((p_chain->u.chain16.cons_idx &
|
|
|
|
p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
|
|
|
|
p_cons_idx = &p_chain->u.chain16.cons_idx;
|
2016-11-29 22:47:01 +08:00
|
|
|
p_cons_page_idx = &p_chain->pbl.c.u16.cons_page_idx;
|
2016-06-03 19:35:32 +08:00
|
|
|
qed_chain_advance_page(p_chain, &p_chain->p_cons_elem,
|
|
|
|
p_cons_idx, p_cons_page_idx);
|
|
|
|
}
|
|
|
|
p_chain->u.chain16.cons_idx++;
|
|
|
|
} else {
|
|
|
|
if ((p_chain->u.chain32.cons_idx &
|
|
|
|
p_chain->elem_per_page_mask) == p_chain->next_page_mask) {
|
|
|
|
p_cons_idx = &p_chain->u.chain32.cons_idx;
|
2016-11-29 22:47:01 +08:00
|
|
|
p_cons_page_idx = &p_chain->pbl.c.u32.cons_page_idx;
|
|
|
|
qed_chain_advance_page(p_chain, &p_chain->p_cons_elem,
|
2016-06-03 19:35:32 +08:00
|
|
|
p_cons_idx, p_cons_page_idx);
|
|
|
|
}
|
|
|
|
p_chain->u.chain32.cons_idx++;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
p_ret = p_chain->p_cons_elem;
|
2015-10-26 17:02:25 +08:00
|
|
|
p_chain->p_cons_elem = (void *)(((u8 *)p_chain->p_cons_elem) +
|
|
|
|
p_chain->elem_size);
|
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
return p_ret;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_reset - Resets the chain to its start state
|
|
|
|
*
|
2021-01-27 10:28:01 +08:00
|
|
|
* @param p_chain pointer to a previously allocated chain
|
2015-10-26 17:02:25 +08:00
|
|
|
*/
|
|
|
|
static inline void qed_chain_reset(struct qed_chain *p_chain)
|
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
u32 i;
|
|
|
|
|
|
|
|
if (is_chain_u16(p_chain)) {
|
|
|
|
p_chain->u.chain16.prod_idx = 0;
|
|
|
|
p_chain->u.chain16.cons_idx = 0;
|
|
|
|
} else {
|
|
|
|
p_chain->u.chain32.prod_idx = 0;
|
|
|
|
p_chain->u.chain32.cons_idx = 0;
|
|
|
|
}
|
|
|
|
p_chain->p_cons_elem = p_chain->p_virt_addr;
|
|
|
|
p_chain->p_prod_elem = p_chain->p_virt_addr;
|
2015-10-26 17:02:25 +08:00
|
|
|
|
|
|
|
if (p_chain->mode == QED_CHAIN_MODE_PBL) {
|
2016-06-03 19:35:32 +08:00
|
|
|
/* Use (page_cnt - 1) as a reset value for the prod/cons page's
|
|
|
|
* indices, to avoid unnecessary page advancing on the first
|
|
|
|
* call to qed_chain_produce/consume. Instead, the indices
|
|
|
|
* will be advanced to page_cnt and then will be wrapped to 0.
|
|
|
|
*/
|
|
|
|
u32 reset_val = p_chain->page_cnt - 1;
|
|
|
|
|
|
|
|
if (is_chain_u16(p_chain)) {
|
2016-11-29 22:47:01 +08:00
|
|
|
p_chain->pbl.c.u16.prod_page_idx = (u16)reset_val;
|
|
|
|
p_chain->pbl.c.u16.cons_page_idx = (u16)reset_val;
|
2016-06-03 19:35:32 +08:00
|
|
|
} else {
|
2016-11-29 22:47:01 +08:00
|
|
|
p_chain->pbl.c.u32.prod_page_idx = reset_val;
|
|
|
|
p_chain->pbl.c.u32.cons_page_idx = reset_val;
|
2016-06-03 19:35:32 +08:00
|
|
|
}
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (p_chain->intended_use) {
|
|
|
|
case QED_CHAIN_USE_TO_CONSUME:
|
|
|
|
/* produce empty elements */
|
|
|
|
for (i = 0; i < p_chain->capacity; i++)
|
|
|
|
qed_chain_recycle_consumed(p_chain);
|
|
|
|
break;
|
2016-11-29 22:47:01 +08:00
|
|
|
|
|
|
|
case QED_CHAIN_USE_TO_CONSUME_PRODUCE:
|
|
|
|
case QED_CHAIN_USE_TO_PRODUCE:
|
|
|
|
default:
|
|
|
|
/* Do nothing */
|
|
|
|
break;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-03 19:35:32 +08:00
|
|
|
* @brief qed_chain_get_last_elem -
|
2015-10-26 17:02:25 +08:00
|
|
|
*
|
2016-06-03 19:35:32 +08:00
|
|
|
* Returns a pointer to the last element of the chain
|
2015-10-26 17:02:25 +08:00
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
*
|
2016-06-03 19:35:32 +08:00
|
|
|
* @return void*
|
2015-10-26 17:02:25 +08:00
|
|
|
*/
|
2016-06-03 19:35:32 +08:00
|
|
|
static inline void *qed_chain_get_last_elem(struct qed_chain *p_chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
struct qed_chain_next *p_next = NULL;
|
|
|
|
void *p_virt_addr = NULL;
|
|
|
|
u32 size, last_page_idx;
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
if (!p_chain->p_virt_addr)
|
|
|
|
goto out;
|
2015-10-26 17:02:25 +08:00
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
switch (p_chain->mode) {
|
|
|
|
case QED_CHAIN_MODE_NEXT_PTR:
|
|
|
|
size = p_chain->elem_size * p_chain->usable_per_page;
|
|
|
|
p_virt_addr = p_chain->p_virt_addr;
|
|
|
|
p_next = (struct qed_chain_next *)((u8 *)p_virt_addr + size);
|
|
|
|
while (p_next->next_virt != p_chain->p_virt_addr) {
|
|
|
|
p_virt_addr = p_next->next_virt;
|
|
|
|
p_next = (struct qed_chain_next *)((u8 *)p_virt_addr +
|
|
|
|
size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QED_CHAIN_MODE_SINGLE:
|
|
|
|
p_virt_addr = p_chain->p_virt_addr;
|
|
|
|
break;
|
|
|
|
case QED_CHAIN_MODE_PBL:
|
|
|
|
last_page_idx = p_chain->page_cnt - 1;
|
2020-03-30 01:32:49 +08:00
|
|
|
p_virt_addr = p_chain->pbl.pp_addr_tbl[last_page_idx].virt_addr;
|
2016-06-03 19:35:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* p_virt_addr points at this stage to the last page of the chain */
|
|
|
|
size = p_chain->elem_size * (p_chain->usable_per_page - 1);
|
|
|
|
p_virt_addr = (u8 *)p_virt_addr + size;
|
|
|
|
out:
|
|
|
|
return p_virt_addr;
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-03 19:35:32 +08:00
|
|
|
* @brief qed_chain_set_prod - sets the prod to the given value
|
2015-10-26 17:02:25 +08:00
|
|
|
*
|
2016-06-03 19:35:32 +08:00
|
|
|
* @param prod_idx
|
|
|
|
* @param p_prod_elem
|
|
|
|
*/
|
|
|
|
static inline void qed_chain_set_prod(struct qed_chain *p_chain,
|
|
|
|
u32 prod_idx, void *p_prod_elem)
|
|
|
|
{
|
2019-01-03 18:02:39 +08:00
|
|
|
if (p_chain->mode == QED_CHAIN_MODE_PBL) {
|
|
|
|
u32 cur_prod, page_mask, page_cnt, page_diff;
|
|
|
|
|
|
|
|
cur_prod = is_chain_u16(p_chain) ? p_chain->u.chain16.prod_idx :
|
|
|
|
p_chain->u.chain32.prod_idx;
|
|
|
|
|
|
|
|
/* Assume that number of elements in a page is power of 2 */
|
|
|
|
page_mask = ~p_chain->elem_per_page_mask;
|
|
|
|
|
|
|
|
/* Use "cur_prod - 1" and "prod_idx - 1" since producer index
|
|
|
|
* reaches the first element of next page before the page index
|
|
|
|
* is incremented. See qed_chain_produce().
|
|
|
|
* Index wrap around is not a problem because the difference
|
|
|
|
* between current and given producer indices is always
|
|
|
|
* positive and lower than the chain's capacity.
|
|
|
|
*/
|
|
|
|
page_diff = (((cur_prod - 1) & page_mask) -
|
|
|
|
((prod_idx - 1) & page_mask)) /
|
|
|
|
p_chain->elem_per_page;
|
|
|
|
|
|
|
|
page_cnt = qed_chain_get_page_cnt(p_chain);
|
|
|
|
if (is_chain_u16(p_chain))
|
|
|
|
p_chain->pbl.c.u16.prod_page_idx =
|
|
|
|
(p_chain->pbl.c.u16.prod_page_idx -
|
|
|
|
page_diff + page_cnt) % page_cnt;
|
|
|
|
else
|
|
|
|
p_chain->pbl.c.u32.prod_page_idx =
|
|
|
|
(p_chain->pbl.c.u32.prod_page_idx -
|
|
|
|
page_diff + page_cnt) % page_cnt;
|
|
|
|
}
|
|
|
|
|
2016-06-03 19:35:32 +08:00
|
|
|
if (is_chain_u16(p_chain))
|
|
|
|
p_chain->u.chain16.prod_idx = (u16) prod_idx;
|
|
|
|
else
|
|
|
|
p_chain->u.chain32.prod_idx = prod_idx;
|
|
|
|
p_chain->p_prod_elem = p_prod_elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief qed_chain_pbl_zero_mem - set chain memory to 0
|
2015-10-26 17:02:25 +08:00
|
|
|
*
|
|
|
|
* @param p_chain
|
|
|
|
*/
|
2016-06-03 19:35:32 +08:00
|
|
|
static inline void qed_chain_pbl_zero_mem(struct qed_chain *p_chain)
|
2015-10-26 17:02:25 +08:00
|
|
|
{
|
2016-06-03 19:35:32 +08:00
|
|
|
u32 i, page_cnt;
|
|
|
|
|
|
|
|
if (p_chain->mode != QED_CHAIN_MODE_PBL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
page_cnt = qed_chain_get_page_cnt(p_chain);
|
|
|
|
|
|
|
|
for (i = 0; i < page_cnt; i++)
|
2020-03-30 01:32:49 +08:00
|
|
|
memset(p_chain->pbl.pp_addr_tbl[i].virt_addr, 0,
|
2020-07-23 06:10:39 +08:00
|
|
|
p_chain->page_size);
|
2015-10-26 17:02:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|