| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. */ |
| 3 |
|
| 4 |
#ifndef _HINIC3_WQ_H_ |
| 5 |
#define _HINIC3_WQ_H_ |
| 6 |
|
| 7 |
#include <linux/io.h> |
| 8 |
|
| 9 |
#include "hinic3_queue_common.h" |
| 10 |
|
| 11 |
struct hinic3_sq_bufdesc { |
| 12 |
/* 31-bits Length, L2NIC only uses length[17:0] */ |
| 13 |
__le32 len; |
| 14 |
__le32 rsvd; |
| 15 |
__le32 hi_addr; |
| 16 |
__le32 lo_addr; |
| 17 |
}; |
| 18 |
|
| 19 |
/* Work queue is used to submit elements (tx, rx, cmd) to hw. |
| 20 |
* Driver is the producer that advances prod_idx. cons_idx is advanced when |
| 21 |
* HW reports completions of previously submitted elements. |
| 22 |
*/ |
| 23 |
struct hinic3_wq { |
| 24 |
struct hinic3_queue_pages qpages; |
| 25 |
/* Unmasked producer/consumer indices that are advanced to natural |
| 26 |
* integer overflow regardless of queue depth. |
| 27 |
*/ |
| 28 |
u16 cons_idx; |
| 29 |
u16 prod_idx; |
| 30 |
|
| 31 |
u32 q_depth; |
| 32 |
u16 idx_mask; |
| 33 |
|
| 34 |
/* Work Queue (logical WQEBB array) is mapped to hw via Chip Logical |
| 35 |
* Address (CLA) using 1 of 2 levels: |
| 36 |
* level 0 - direct mapping of single wq page |
| 37 |
* level 1 - indirect mapping of multiple pages via additional page |
| 38 |
* table. |
| 39 |
* When wq uses level 1, wq_block will hold the allocated indirection |
| 40 |
* table. |
| 41 |
*/ |
| 42 |
dma_addr_t wq_block_paddr; |
| 43 |
__be64 *wq_block_vaddr; |
| 44 |
} ____cacheline_aligned; |
| 45 |
|
| 46 |
/* Get number of elements in work queue that are in-use. */ |
| 47 |
static inline u16 hinic3_wq_get_used(const struct hinic3_wq *wq) |
| 48 |
{ |
| 49 |
return READ_ONCE(wq->prod_idx) - READ_ONCE(wq->cons_idx); |
| 50 |
} |
| 51 |
|
| 52 |
static inline u16 hinic3_wq_free_wqebbs(struct hinic3_wq *wq) |
| 53 |
{ |
| 54 |
/* Don't allow queue to become completely full, report (free - 1). */ |
| 55 |
return wq->q_depth - hinic3_wq_get_used(wq) - 1; |
| 56 |
} |
| 57 |
|
| 58 |
static inline void *hinic3_wq_get_one_wqebb(struct hinic3_wq *wq, u16 *pi) |
| 59 |
{ |
| 60 |
*pi = wq->prod_idx & wq->idx_mask; |
| 61 |
wq->prod_idx++; |
| 62 |
|
| 63 |
return get_q_element(&wq->qpages, *pi, NULL); |
| 64 |
} |
| 65 |
|
| 66 |
static inline void hinic3_wq_put_wqebbs(struct hinic3_wq *wq, u16 num_wqebbs) |
| 67 |
{ |
| 68 |
wq->cons_idx += num_wqebbs; |
| 69 |
} |
| 70 |
|
| 71 |
static inline u64 hinic3_wq_get_first_wqe_page_addr(const struct hinic3_wq *wq) |
| 72 |
{ |
| 73 |
return wq->qpages.pages[0].align_paddr; |
| 74 |
} |
| 75 |
|
| 76 |
int hinic3_wq_create(struct hinic3_hwdev *hwdev, struct hinic3_wq *wq, |
| 77 |
u32 q_depth, u16 wqebb_size); |
| 78 |
void hinic3_wq_destroy(struct hinic3_hwdev *hwdev, struct hinic3_wq *wq); |
| 79 |
void hinic3_wq_reset(struct hinic3_wq *wq); |
| 80 |
void hinic3_wq_get_multi_wqebbs(struct hinic3_wq *wq, |
| 81 |
u16 num_wqebbs, u16 *prod_idx, |
| 82 |
struct hinic3_sq_bufdesc **first_part_wqebbs, |
| 83 |
struct hinic3_sq_bufdesc **second_part_wqebbs, |
| 84 |
u16 *first_part_wqebbs_num); |
| 85 |
bool hinic3_wq_is_0_level_cla(const struct hinic3_wq *wq); |
| 86 |
|
| 87 |
#endif |