WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / ethernet / huawei / hinic / hinic_hw_wq.h
blobb06f8c0255de624c21d2197917ab03431f8dbdb5
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
5 */
7 #ifndef HINIC_HW_WQ_H
8 #define HINIC_HW_WQ_H
10 #include <linux/types.h>
11 #include <linux/semaphore.h>
12 #include <linux/atomic.h>
14 #include "hinic_hw_if.h"
15 #include "hinic_hw_wqe.h"
17 struct hinic_free_block {
18 int page_idx;
19 int block_idx;
22 struct hinic_wq {
23 struct hinic_hwif *hwif;
25 int page_idx;
26 int block_idx;
28 u16 wqebb_size;
29 u32 wq_page_size;
30 u16 q_depth;
31 u16 max_wqe_size;
32 u16 num_wqebbs_per_page;
33 u16 wqebbs_per_page_shift;
34 u16 wqebb_size_shift;
35 /* The addresses are 64 bit in the HW */
36 u64 block_paddr;
37 void **shadow_block_vaddr;
38 u64 *block_vaddr;
40 int num_q_pages;
41 u8 *shadow_wqe;
42 u16 *shadow_idx;
44 atomic_t cons_idx;
45 atomic_t prod_idx;
46 atomic_t delta;
47 u16 mask;
50 struct hinic_wqs {
51 struct hinic_hwif *hwif;
52 int num_pages;
54 /* The addresses are 64 bit in the HW */
55 u64 *page_paddr;
56 u64 **page_vaddr;
57 void ***shadow_page_vaddr;
59 struct hinic_free_block *free_blocks;
60 int alloc_blk_pos;
61 int return_blk_pos;
62 int num_free_blks;
64 /* Lock for getting a free block from the WQ set */
65 struct semaphore alloc_blocks_lock;
68 struct hinic_cmdq_pages {
69 /* The addresses are 64 bit in the HW */
70 u64 page_paddr;
71 u64 *page_vaddr;
72 void **shadow_page_vaddr;
74 struct hinic_hwif *hwif;
77 int hinic_wqs_cmdq_alloc(struct hinic_cmdq_pages *cmdq_pages,
78 struct hinic_wq *wq, struct hinic_hwif *hwif,
79 int cmdq_blocks, u16 wqebb_size, u32 wq_page_size,
80 u16 q_depth, u16 max_wqe_size);
82 void hinic_wqs_cmdq_free(struct hinic_cmdq_pages *cmdq_pages,
83 struct hinic_wq *wq, int cmdq_blocks);
85 int hinic_wqs_alloc(struct hinic_wqs *wqs, int num_wqs,
86 struct hinic_hwif *hwif);
88 void hinic_wqs_free(struct hinic_wqs *wqs);
90 int hinic_wq_allocate(struct hinic_wqs *wqs, struct hinic_wq *wq,
91 u16 wqebb_size, u32 wq_page_size, u16 q_depth,
92 u16 max_wqe_size);
94 void hinic_wq_free(struct hinic_wqs *wqs, struct hinic_wq *wq);
96 struct hinic_hw_wqe *hinic_get_wqe(struct hinic_wq *wq, unsigned int wqe_size,
97 u16 *prod_idx);
99 void hinic_return_wqe(struct hinic_wq *wq, unsigned int wqe_size);
101 void hinic_put_wqe(struct hinic_wq *wq, unsigned int wqe_size);
103 struct hinic_hw_wqe *hinic_read_wqe(struct hinic_wq *wq, unsigned int wqe_size,
104 u16 *cons_idx);
106 struct hinic_hw_wqe *hinic_read_wqe_direct(struct hinic_wq *wq, u16 cons_idx);
108 void hinic_write_wqe(struct hinic_wq *wq, struct hinic_hw_wqe *wqe,
109 unsigned int wqe_size);
111 #endif