1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
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 {
23 struct hinic_hwif *hwif;
32 u16 num_wqebbs_per_page;
33 u16 wqebbs_per_page_shift;
35 /* The addresses are 64 bit in the HW */
37 void **shadow_block_vaddr;
51 struct hinic_hwif *hwif;
54 /* The addresses are 64 bit in the HW */
57 void ***shadow_page_vaddr;
59 struct hinic_free_block *free_blocks;
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 */
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, u16 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, u16 wq_page_size, u16 q_depth,
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,
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,
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);