Skip to content

Commit 23a18b9

Browse files
sreekanthbrcmkuba-moo
authored andcommitted
bnxt_en: Add functions to copy host context memory
Host context memory is used by the newer chips to store context information for various L2 and RoCE states and FW logs. This information will be useful for debugging. This patch adds the functions to copy all pages of a context memory type to a contiguous buffer. The next patches will include the context memory dump during ethtool -w coredump. Reviewed-by: Pavan Chebbi <[email protected]> Reviewed-by: Hongguang Gao <[email protected]> Co-developed-by: Shruti Parab <[email protected]> Signed-off-by: Shruti Parab <[email protected]> Signed-off-by: Sreekanth Reddy <[email protected]> Signed-off-by: Michael Chan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent de99936 commit 23a18b9

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,6 +3493,35 @@ static void bnxt_init_ctx_mem(struct bnxt_ctx_mem_type *ctxm, void *p, int len)
34933493
*(p2 + i + offset) = init_val;
34943494
}
34953495

3496+
static size_t __bnxt_copy_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem,
3497+
void *buf, size_t offset, size_t head,
3498+
size_t tail)
3499+
{
3500+
int i, head_page, start_idx, source_offset;
3501+
size_t len, rem_len, total_len, max_bytes;
3502+
3503+
head_page = head / rmem->page_size;
3504+
source_offset = head % rmem->page_size;
3505+
total_len = (tail - head) & MAX_CTX_BYTES_MASK;
3506+
if (!total_len)
3507+
total_len = MAX_CTX_BYTES;
3508+
start_idx = head_page % MAX_CTX_PAGES;
3509+
max_bytes = (rmem->nr_pages - start_idx) * rmem->page_size -
3510+
source_offset;
3511+
total_len = min(total_len, max_bytes);
3512+
rem_len = total_len;
3513+
3514+
for (i = start_idx; rem_len; i++, source_offset = 0) {
3515+
len = min((size_t)(rmem->page_size - source_offset), rem_len);
3516+
if (buf)
3517+
memcpy(buf + offset, rmem->pg_arr[i] + source_offset,
3518+
len);
3519+
offset += len;
3520+
rem_len -= len;
3521+
}
3522+
return total_len;
3523+
}
3524+
34963525
static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
34973526
{
34983527
struct pci_dev *pdev = bp->pdev;
@@ -8728,6 +8757,36 @@ static int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp,
87288757
return rc;
87298758
}
87308759

8760+
static size_t bnxt_copy_ctx_pg_tbls(struct bnxt *bp,
8761+
struct bnxt_ctx_pg_info *ctx_pg,
8762+
void *buf, size_t offset, size_t head,
8763+
size_t tail)
8764+
{
8765+
struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
8766+
size_t nr_pages = ctx_pg->nr_pages;
8767+
int page_size = rmem->page_size;
8768+
size_t len = 0, total_len = 0;
8769+
u16 depth = rmem->depth;
8770+
8771+
tail %= nr_pages * page_size;
8772+
do {
8773+
if (depth > 1) {
8774+
int i = head / (page_size * MAX_CTX_PAGES);
8775+
struct bnxt_ctx_pg_info *pg_tbl;
8776+
8777+
pg_tbl = ctx_pg->ctx_pg_tbl[i];
8778+
rmem = &pg_tbl->ring_mem;
8779+
}
8780+
len = __bnxt_copy_ring(bp, rmem, buf, offset, head, tail);
8781+
head += len;
8782+
offset += len;
8783+
total_len += len;
8784+
if (head >= nr_pages * page_size)
8785+
head = 0;
8786+
} while (head != tail);
8787+
return total_len;
8788+
}
8789+
87318790
static void bnxt_free_ctx_pg_tbls(struct bnxt *bp,
87328791
struct bnxt_ctx_pg_info *ctx_pg)
87338792
{
@@ -8888,6 +8947,50 @@ static int bnxt_backing_store_cfg_v2(struct bnxt *bp, u32 ena)
88888947
return 0;
88898948
}
88908949

8950+
/**
8951+
* __bnxt_copy_ctx_mem - copy host context memory
8952+
* @bp: The driver context
8953+
* @ctxm: The pointer to the context memory type
8954+
* @buf: The destination buffer or NULL to just obtain the length
8955+
* @offset: The buffer offset to copy the data to
8956+
* @head: The head offset of context memory to copy from
8957+
* @tail: The tail offset (last byte + 1) of context memory to end the copy
8958+
*
8959+
* This function is called for debugging purposes to dump the host context
8960+
* used by the chip.
8961+
*
8962+
* Return: Length of memory copied
8963+
*/
8964+
static size_t __bnxt_copy_ctx_mem(struct bnxt *bp,
8965+
struct bnxt_ctx_mem_type *ctxm, void *buf,
8966+
size_t offset, size_t head, size_t tail)
8967+
{
8968+
struct bnxt_ctx_pg_info *ctx_pg = ctxm->pg_info;
8969+
size_t len = 0, total_len = 0;
8970+
int i, n = 1;
8971+
8972+
if (!ctx_pg)
8973+
return 0;
8974+
8975+
if (ctxm->instance_bmap)
8976+
n = hweight32(ctxm->instance_bmap);
8977+
for (i = 0; i < n; i++) {
8978+
len = bnxt_copy_ctx_pg_tbls(bp, &ctx_pg[i], buf, offset, head,
8979+
tail);
8980+
offset += len;
8981+
total_len += len;
8982+
}
8983+
return total_len;
8984+
}
8985+
8986+
size_t bnxt_copy_ctx_mem(struct bnxt *bp, struct bnxt_ctx_mem_type *ctxm,
8987+
void *buf, size_t offset)
8988+
{
8989+
size_t tail = ctxm->max_entries * ctxm->entry_size;
8990+
8991+
return __bnxt_copy_ctx_mem(bp, ctxm, buf, offset, 0, tail);
8992+
}
8993+
88918994
static void bnxt_free_one_ctx_mem(struct bnxt *bp,
88928995
struct bnxt_ctx_mem_type *ctxm, bool force)
88938996
{

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,8 @@ struct bnxt_vf_rep {
18491849

18501850
#define MAX_CTX_PAGES (BNXT_PAGE_SIZE / 8)
18511851
#define MAX_CTX_TOTAL_PAGES (MAX_CTX_PAGES * MAX_CTX_PAGES)
1852+
#define MAX_CTX_BYTES ((size_t)MAX_CTX_TOTAL_PAGES * BNXT_PAGE_SIZE)
1853+
#define MAX_CTX_BYTES_MASK (MAX_CTX_BYTES - 1)
18521854

18531855
struct bnxt_ctx_pg_info {
18541856
u32 entries;
@@ -2863,6 +2865,8 @@ int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic,
28632865
int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings);
28642866
int bnxt_nq_rings_in_use(struct bnxt *bp);
28652867
int bnxt_hwrm_set_coal(struct bnxt *);
2868+
size_t bnxt_copy_ctx_mem(struct bnxt *bp, struct bnxt_ctx_mem_type *ctxm,
2869+
void *buf, size_t offset);
28662870
void bnxt_free_ctx_mem(struct bnxt *bp, bool force);
28672871
int bnxt_num_tx_to_cp(struct bnxt *bp, int tx);
28682872
unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);

0 commit comments

Comments
 (0)