Merge branch 'core-objtool-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / drivers / net / ethernet / huawei / hinic / hinic_hw_qp.h
CommitLineData
2025cf9e 1/* SPDX-License-Identifier: GPL-2.0-only */
c3e79baf
AK
2/*
3 * Huawei HiNIC PCI Express Linux driver
4 * Copyright(c) 2017 Huawei Technologies Co., Ltd
c3e79baf
AK
5 */
6
7#ifndef HINIC_HW_QP_H
8#define HINIC_HW_QP_H
9
00e57a6d 10#include <linux/kernel.h>
b15a9f37
AK
11#include <linux/types.h>
12#include <linux/sizes.h>
f91090f7
AK
13#include <linux/pci.h>
14#include <linux/skbuff.h>
15
e2585ea7 16#include "hinic_common.h"
f91090f7
AK
17#include "hinic_hw_if.h"
18#include "hinic_hw_wqe.h"
19#include "hinic_hw_wq.h"
53e7d6fe 20#include "hinic_hw_qp_ctxt.h"
b15a9f37 21
00e57a6d
AK
22#define HINIC_SQ_DB_INFO_PI_HI_SHIFT 0
23#define HINIC_SQ_DB_INFO_QID_SHIFT 8
24#define HINIC_SQ_DB_INFO_PATH_SHIFT 23
25#define HINIC_SQ_DB_INFO_COS_SHIFT 24
26#define HINIC_SQ_DB_INFO_TYPE_SHIFT 27
27
28#define HINIC_SQ_DB_INFO_PI_HI_MASK 0xFF
29#define HINIC_SQ_DB_INFO_QID_MASK 0x3FF
30#define HINIC_SQ_DB_INFO_PATH_MASK 0x1
31#define HINIC_SQ_DB_INFO_COS_MASK 0x7
32#define HINIC_SQ_DB_INFO_TYPE_MASK 0x1F
33
34#define HINIC_SQ_DB_INFO_SET(val, member) \
35 (((u32)(val) & HINIC_SQ_DB_INFO_##member##_MASK) \
36 << HINIC_SQ_DB_INFO_##member##_SHIFT)
37
b15a9f37
AK
38#define HINIC_SQ_WQEBB_SIZE 64
39#define HINIC_RQ_WQEBB_SIZE 32
40
41#define HINIC_SQ_PAGE_SIZE SZ_4K
42#define HINIC_RQ_PAGE_SIZE SZ_4K
43
44#define HINIC_SQ_DEPTH SZ_4K
45#define HINIC_RQ_DEPTH SZ_4K
46
cde66f24 47/* In any change to HINIC_RX_BUF_SZ, HINIC_RX_BUF_SZ_IDX must be changed */
f91090f7 48#define HINIC_RX_BUF_SZ 2048
cde66f24 49#define HINIC_RX_BUF_SZ_IDX HINIC_RX_BUF_SZ_2048_IDX
f91090f7 50
00e57a6d
AK
51#define HINIC_MIN_TX_WQE_SIZE(wq) \
52 ALIGN(HINIC_SQ_WQE_SIZE(1), (wq)->wqebb_size)
53
54#define HINIC_MIN_TX_NUM_WQEBBS(sq) \
55 (HINIC_MIN_TX_WQE_SIZE((sq)->wq) / (sq)->wq->wqebb_size)
56
cde66f24
AK
57enum hinic_rx_buf_sz_idx {
58 HINIC_RX_BUF_SZ_32_IDX,
59 HINIC_RX_BUF_SZ_64_IDX,
60 HINIC_RX_BUF_SZ_96_IDX,
61 HINIC_RX_BUF_SZ_128_IDX,
62 HINIC_RX_BUF_SZ_192_IDX,
63 HINIC_RX_BUF_SZ_256_IDX,
64 HINIC_RX_BUF_SZ_384_IDX,
65 HINIC_RX_BUF_SZ_512_IDX,
66 HINIC_RX_BUF_SZ_768_IDX,
67 HINIC_RX_BUF_SZ_1024_IDX,
68 HINIC_RX_BUF_SZ_1536_IDX,
69 HINIC_RX_BUF_SZ_2048_IDX,
70 HINIC_RX_BUF_SZ_3072_IDX,
71 HINIC_RX_BUF_SZ_4096_IDX,
72 HINIC_RX_BUF_SZ_8192_IDX,
73 HINIC_RX_BUF_SZ_16384_IDX,
74};
75
c3e79baf 76struct hinic_sq {
f91090f7
AK
77 struct hinic_hwif *hwif;
78
79 struct hinic_wq *wq;
80
81 u32 irq;
82 u16 msix_entry;
83
84 void *hw_ci_addr;
85 dma_addr_t hw_ci_dma_addr;
86
87 void __iomem *db_base;
88
89 struct sk_buff **saved_skb;
c3e79baf
AK
90};
91
92struct hinic_rq {
f91090f7
AK
93 struct hinic_hwif *hwif;
94
95 struct hinic_wq *wq;
96
0bff777b 97 struct cpumask affinity_mask;
f91090f7
AK
98 u32 irq;
99 u16 msix_entry;
100
101 size_t buf_sz;
102
103 struct sk_buff **saved_skb;
104
105 struct hinic_rq_cqe **cqe;
106 dma_addr_t *cqe_dma;
107
108 u16 *pi_virt_addr;
109 dma_addr_t pi_dma_addr;
c3e79baf
AK
110};
111
112struct hinic_qp {
113 struct hinic_sq sq;
114 struct hinic_rq rq;
b15a9f37
AK
115
116 u16 q_id;
c3e79baf
AK
117};
118
53e7d6fe
AK
119void hinic_qp_prepare_header(struct hinic_qp_ctxt_header *qp_ctxt_hdr,
120 enum hinic_qp_ctxt_type ctxt_type,
121 u16 num_queues, u16 max_queues);
122
123void hinic_sq_prepare_ctxt(struct hinic_sq_ctxt *sq_ctxt,
124 struct hinic_sq *sq, u16 global_qid);
125
126void hinic_rq_prepare_ctxt(struct hinic_rq_ctxt *rq_ctxt,
127 struct hinic_rq *rq, u16 global_qid);
128
f91090f7
AK
129int hinic_init_sq(struct hinic_sq *sq, struct hinic_hwif *hwif,
130 struct hinic_wq *wq, struct msix_entry *entry, void *ci_addr,
131 dma_addr_t ci_dma_addr, void __iomem *db_base);
132
133void hinic_clean_sq(struct hinic_sq *sq);
134
135int hinic_init_rq(struct hinic_rq *rq, struct hinic_hwif *hwif,
136 struct hinic_wq *wq, struct msix_entry *entry);
137
138void hinic_clean_rq(struct hinic_rq *rq);
139
00e57a6d
AK
140int hinic_get_sq_free_wqebbs(struct hinic_sq *sq);
141
e2585ea7
AK
142int hinic_get_rq_free_wqebbs(struct hinic_rq *rq);
143
cc18a754
ZC
144void hinic_task_set_l2hdr(struct hinic_sq_task *task, u32 len);
145
146void hinic_task_set_outter_l3(struct hinic_sq_task *task,
147 enum hinic_l3_offload_type l3_type,
148 u32 network_len);
149
150void hinic_task_set_inner_l3(struct hinic_sq_task *task,
151 enum hinic_l3_offload_type l3_type,
152 u32 network_len);
153
154void hinic_task_set_tunnel_l4(struct hinic_sq_task *task,
6e29464b 155 enum hinic_l4_tunnel_type l4_type,
cc18a754
ZC
156 u32 tunnel_len);
157
158void hinic_set_cs_inner_l4(struct hinic_sq_task *task,
159 u32 *queue_info,
160 enum hinic_l4_offload_type l4_offload,
161 u32 l4_len, u32 offset);
162
163void hinic_set_tso_inner_l4(struct hinic_sq_task *task,
164 u32 *queue_info,
165 enum hinic_l4_offload_type l4_offload,
166 u32 l4_len,
167 u32 offset, u32 ip_ident, u32 mss);
168
00e57a6d
AK
169void hinic_sq_prepare_wqe(struct hinic_sq *sq, u16 prod_idx,
170 struct hinic_sq_wqe *wqe, struct hinic_sge *sges,
171 int nr_sges);
172
173void hinic_sq_write_db(struct hinic_sq *sq, u16 prod_idx, unsigned int wqe_size,
174 unsigned int cos);
175
176struct hinic_sq_wqe *hinic_sq_get_wqe(struct hinic_sq *sq,
177 unsigned int wqe_size, u16 *prod_idx);
178
cc18a754
ZC
179void hinic_sq_return_wqe(struct hinic_sq *sq, unsigned int wqe_size);
180
00e57a6d
AK
181void hinic_sq_write_wqe(struct hinic_sq *sq, u16 prod_idx,
182 struct hinic_sq_wqe *wqe, struct sk_buff *skb,
183 unsigned int wqe_size);
184
185struct hinic_sq_wqe *hinic_sq_read_wqe(struct hinic_sq *sq,
186 struct sk_buff **skb,
9c2956d2
ZC
187 unsigned int wqe_size, u16 *cons_idx);
188
189struct hinic_sq_wqe *hinic_sq_read_wqebb(struct hinic_sq *sq,
190 struct sk_buff **skb,
191 unsigned int *wqe_size, u16 *cons_idx);
00e57a6d
AK
192
193void hinic_sq_put_wqe(struct hinic_sq *sq, unsigned int wqe_size);
194
195void hinic_sq_get_sges(struct hinic_sq_wqe *wqe, struct hinic_sge *sges,
196 int nr_sges);
197
e2585ea7
AK
198struct hinic_rq_wqe *hinic_rq_get_wqe(struct hinic_rq *rq,
199 unsigned int wqe_size, u16 *prod_idx);
200
201void hinic_rq_write_wqe(struct hinic_rq *rq, u16 prod_idx,
202 struct hinic_rq_wqe *wqe, struct sk_buff *skb);
203
204struct hinic_rq_wqe *hinic_rq_read_wqe(struct hinic_rq *rq,
205 unsigned int wqe_size,
206 struct sk_buff **skb, u16 *cons_idx);
207
208struct hinic_rq_wqe *hinic_rq_read_next_wqe(struct hinic_rq *rq,
209 unsigned int wqe_size,
210 struct sk_buff **skb,
211 u16 *cons_idx);
212
213void hinic_rq_put_wqe(struct hinic_rq *rq, u16 cons_idx,
214 unsigned int wqe_size);
215
216void hinic_rq_get_sge(struct hinic_rq *rq, struct hinic_rq_wqe *wqe,
217 u16 cons_idx, struct hinic_sge *sge);
218
219void hinic_rq_prepare_wqe(struct hinic_rq *rq, u16 prod_idx,
220 struct hinic_rq_wqe *wqe, struct hinic_sge *sge);
221
222void hinic_rq_update(struct hinic_rq *rq, u16 prod_idx);
223
c3e79baf 224#endif