Loading...
1/*
2 * Copyright (c) 2016-2017 Hisilicon Limited.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _HNS_ROCE_HW_V2_H
34#define _HNS_ROCE_HW_V2_H
35
36#include <linux/bitops.h>
37
38#define HNS_ROCE_V2_MAX_RC_INL_INN_SZ 32
39#define HNS_ROCE_V2_MTT_ENTRY_SZ 64
40#define HNS_ROCE_V2_AEQE_VEC_NUM 1
41#define HNS_ROCE_V2_ABNORMAL_VEC_NUM 1
42#define HNS_ROCE_V2_MAX_SRQWQE_SEGS 0x1000000
43#define HNS_ROCE_V2_MAX_IDX_SEGS 0x1000000
44#define HNS_ROCE_V2_MAX_XRCD_NUM 0x1000000
45
46#define HNS_ROCE_V2_QP_ACK_TIMEOUT_OFS_HIP08 10
47
48#define HNS_ROCE_V3_SCCC_SZ 64
49#define HNS_ROCE_V3_GMV_ENTRY_SZ 32
50
51#define HNS_ROCE_V2_EXT_LLM_ENTRY_SZ 8
52#define HNS_ROCE_V2_EXT_LLM_MAX_DEPTH 4096
53
54#define HNS_ROCE_V2_QPC_TIMER_ENTRY_SZ PAGE_SIZE
55#define HNS_ROCE_V2_CQC_TIMER_ENTRY_SZ PAGE_SIZE
56#define HNS_ROCE_V2_PAGE_SIZE_SUPPORTED 0xFFFF000
57#define HNS_ROCE_V2_MAX_INNER_MTPT_NUM 2
58#define HNS_ROCE_INVALID_LKEY 0x0
59#define HNS_ROCE_INVALID_SGE_LENGTH 0x80000000
60#define HNS_ROCE_CMQ_TX_TIMEOUT 30000
61#define HNS_ROCE_V2_RSV_QPS 8
62
63#define HNS_ROCE_V2_HW_RST_TIMEOUT 1000
64#define HNS_ROCE_V2_HW_RST_UNINT_DELAY 100
65
66#define HNS_ROCE_V2_HW_RST_COMPLETION_WAIT 20
67
68#define HNS_ROCE_CONTEXT_HOP_NUM 1
69#define HNS_ROCE_SCCC_HOP_NUM 1
70#define HNS_ROCE_MTT_HOP_NUM 1
71#define HNS_ROCE_CQE_HOP_NUM 1
72#define HNS_ROCE_SRQWQE_HOP_NUM 1
73#define HNS_ROCE_PBL_HOP_NUM 2
74#define HNS_ROCE_IDX_HOP_NUM 1
75#define HNS_ROCE_SQWQE_HOP_NUM 2
76#define HNS_ROCE_EXT_SGE_HOP_NUM 1
77#define HNS_ROCE_RQWQE_HOP_NUM 2
78
79#define HNS_ROCE_V2_EQE_HOP_NUM 2
80#define HNS_ROCE_V3_EQE_HOP_NUM 1
81
82#define HNS_ROCE_BA_PG_SZ_SUPPORTED_256K 6
83#define HNS_ROCE_BA_PG_SZ_SUPPORTED_16K 2
84#define HNS_ROCE_V2_GID_INDEX_NUM 16
85
86#define HNS_ROCE_V2_TABLE_CHUNK_SIZE (1 << 18)
87
88enum {
89 HNS_ROCE_CMD_FLAG_IN = BIT(0),
90 HNS_ROCE_CMD_FLAG_OUT = BIT(1),
91 HNS_ROCE_CMD_FLAG_NEXT = BIT(2),
92 HNS_ROCE_CMD_FLAG_WR = BIT(3),
93 HNS_ROCE_CMD_FLAG_ERR_INTR = BIT(5),
94};
95
96#define HNS_ROCE_CMQ_DESC_NUM_S 3
97
98#define HNS_ROCE_CMQ_SCC_CLR_DONE_CNT 5
99
100#define HNS_ROCE_CONG_SIZE 64
101
102#define check_whether_last_step(hop_num, step_idx) \
103 ((step_idx == 0 && hop_num == HNS_ROCE_HOP_NUM_0) || \
104 (step_idx == 1 && hop_num == 1) || \
105 (step_idx == 2 && hop_num == 2))
106#define HNS_ICL_SWITCH_CMD_ROCEE_SEL_SHIFT 0
107#define HNS_ICL_SWITCH_CMD_ROCEE_SEL BIT(HNS_ICL_SWITCH_CMD_ROCEE_SEL_SHIFT)
108
109#define CMD_CSQ_DESC_NUM 1024
110#define CMD_CRQ_DESC_NUM 1024
111
112/* Free mr used parameters */
113#define HNS_ROCE_FREE_MR_USED_CQE_NUM 128
114#define HNS_ROCE_FREE_MR_USED_QP_NUM 0x8
115#define HNS_ROCE_FREE_MR_USED_PSN 0x0808
116#define HNS_ROCE_FREE_MR_USED_QP_RETRY_CNT 0x7
117#define HNS_ROCE_FREE_MR_USED_QP_TIMEOUT 0x12
118#define HNS_ROCE_FREE_MR_USED_SQWQE_NUM 128
119#define HNS_ROCE_FREE_MR_USED_SQSGE_NUM 0x2
120#define HNS_ROCE_FREE_MR_USED_RQWQE_NUM 128
121#define HNS_ROCE_FREE_MR_USED_RQSGE_NUM 0x2
122#define HNS_ROCE_V2_FREE_MR_TIMEOUT 4500
123
124enum {
125 NO_ARMED = 0x0,
126 REG_NXT_CEQE = 0x2,
127 REG_NXT_SE_CEQE = 0x3
128};
129
130enum {
131 CQE_SIZE_32B = 0x0,
132 CQE_SIZE_64B = 0x1
133};
134
135#define V2_CQ_DB_REQ_NOT_SOL 0
136#define V2_CQ_DB_REQ_NOT 1
137
138#define V2_CQ_STATE_VALID 1
139#define V2_QKEY_VAL 0x80010000
140
141#define GID_LEN_V2 16
142
143enum {
144 HNS_ROCE_V2_WQE_OP_SEND = 0x0,
145 HNS_ROCE_V2_WQE_OP_SEND_WITH_INV = 0x1,
146 HNS_ROCE_V2_WQE_OP_SEND_WITH_IMM = 0x2,
147 HNS_ROCE_V2_WQE_OP_RDMA_WRITE = 0x3,
148 HNS_ROCE_V2_WQE_OP_RDMA_WRITE_WITH_IMM = 0x4,
149 HNS_ROCE_V2_WQE_OP_RDMA_READ = 0x5,
150 HNS_ROCE_V2_WQE_OP_ATOM_CMP_AND_SWAP = 0x6,
151 HNS_ROCE_V2_WQE_OP_ATOM_FETCH_AND_ADD = 0x7,
152 HNS_ROCE_V2_WQE_OP_ATOM_MSK_CMP_AND_SWAP = 0x8,
153 HNS_ROCE_V2_WQE_OP_ATOM_MSK_FETCH_AND_ADD = 0x9,
154 HNS_ROCE_V2_WQE_OP_FAST_REG_PMR = 0xa,
155 HNS_ROCE_V2_WQE_OP_BIND_MW = 0xc,
156 HNS_ROCE_V2_WQE_OP_MASK = 0x1f,
157};
158
159enum {
160 /* rq operations */
161 HNS_ROCE_V2_OPCODE_RDMA_WRITE_IMM = 0x0,
162 HNS_ROCE_V2_OPCODE_SEND = 0x1,
163 HNS_ROCE_V2_OPCODE_SEND_WITH_IMM = 0x2,
164 HNS_ROCE_V2_OPCODE_SEND_WITH_INV = 0x3,
165};
166
167enum {
168 HNS_ROCE_V2_SQ_DB,
169 HNS_ROCE_V2_RQ_DB,
170 HNS_ROCE_V2_SRQ_DB,
171 HNS_ROCE_V2_CQ_DB,
172 HNS_ROCE_V2_CQ_DB_NOTIFY
173};
174
175enum {
176 HNS_ROCE_CQE_V2_SUCCESS = 0x00,
177 HNS_ROCE_CQE_V2_LOCAL_LENGTH_ERR = 0x01,
178 HNS_ROCE_CQE_V2_LOCAL_QP_OP_ERR = 0x02,
179 HNS_ROCE_CQE_V2_LOCAL_PROT_ERR = 0x04,
180 HNS_ROCE_CQE_V2_WR_FLUSH_ERR = 0x05,
181 HNS_ROCE_CQE_V2_MW_BIND_ERR = 0x06,
182 HNS_ROCE_CQE_V2_BAD_RESP_ERR = 0x10,
183 HNS_ROCE_CQE_V2_LOCAL_ACCESS_ERR = 0x11,
184 HNS_ROCE_CQE_V2_REMOTE_INVAL_REQ_ERR = 0x12,
185 HNS_ROCE_CQE_V2_REMOTE_ACCESS_ERR = 0x13,
186 HNS_ROCE_CQE_V2_REMOTE_OP_ERR = 0x14,
187 HNS_ROCE_CQE_V2_TRANSPORT_RETRY_EXC_ERR = 0x15,
188 HNS_ROCE_CQE_V2_RNR_RETRY_EXC_ERR = 0x16,
189 HNS_ROCE_CQE_V2_REMOTE_ABORT_ERR = 0x22,
190 HNS_ROCE_CQE_V2_GENERAL_ERR = 0x23,
191
192 HNS_ROCE_V2_CQE_STATUS_MASK = 0xff,
193};
194
195/* CMQ command */
196enum hns_roce_opcode_type {
197 HNS_QUERY_FW_VER = 0x0001,
198 HNS_ROCE_OPC_QUERY_HW_VER = 0x8000,
199 HNS_ROCE_OPC_CFG_GLOBAL_PARAM = 0x8001,
200 HNS_ROCE_OPC_ALLOC_PF_RES = 0x8004,
201 HNS_ROCE_OPC_QUERY_COUNTER = 0x8206,
202 HNS_ROCE_OPC_QUERY_PF_RES = 0x8400,
203 HNS_ROCE_OPC_ALLOC_VF_RES = 0x8401,
204 HNS_ROCE_OPC_CFG_EXT_LLM = 0x8403,
205 HNS_ROCE_OPC_QUERY_PF_TIMER_RES = 0x8406,
206 HNS_ROCE_OPC_QUERY_FUNC_INFO = 0x8407,
207 HNS_ROCE_OPC_QUERY_PF_CAPS_NUM = 0x8408,
208 HNS_ROCE_OPC_CFG_ENTRY_SIZE = 0x8409,
209 HNS_ROCE_OPC_QUERY_VF_CAPS_NUM = 0x8410,
210 HNS_ROCE_OPC_CFG_SGID_TB = 0x8500,
211 HNS_ROCE_OPC_CFG_SMAC_TB = 0x8501,
212 HNS_ROCE_OPC_POST_MB = 0x8504,
213 HNS_ROCE_OPC_QUERY_MB_ST = 0x8505,
214 HNS_ROCE_OPC_CFG_BT_ATTR = 0x8506,
215 HNS_ROCE_OPC_FUNC_CLEAR = 0x8508,
216 HNS_ROCE_OPC_CLR_SCCC = 0x8509,
217 HNS_ROCE_OPC_QUERY_SCCC = 0x850a,
218 HNS_ROCE_OPC_RESET_SCCC = 0x850b,
219 HNS_ROCE_OPC_CLEAR_EXTDB_LIST_INFO = 0x850d,
220 HNS_ROCE_OPC_QUERY_VF_RES = 0x850e,
221 HNS_ROCE_OPC_CFG_GMV_TBL = 0x850f,
222 HNS_ROCE_OPC_CFG_GMV_BT = 0x8510,
223 HNS_ROCE_QUERY_RAM_ECC = 0x8513,
224 HNS_SWITCH_PARAMETER_CFG = 0x1033,
225};
226
227enum {
228 TYPE_CRQ,
229 TYPE_CSQ,
230};
231
232enum hns_roce_cmd_return_status {
233 CMD_EXEC_SUCCESS,
234 CMD_NO_AUTH,
235 CMD_NOT_EXIST,
236 CMD_CRQ_FULL,
237 CMD_NEXT_ERR,
238 CMD_NOT_EXEC,
239 CMD_PARA_ERR,
240 CMD_RESULT_ERR,
241 CMD_TIMEOUT,
242 CMD_HILINK_ERR,
243 CMD_INFO_ILLEGAL,
244 CMD_INVALID,
245 CMD_ROH_CHECK_FAIL,
246 CMD_OTHER_ERR = 0xff
247};
248
249struct hns_roce_cmd_errcode {
250 enum hns_roce_cmd_return_status return_status;
251 int errno;
252};
253
254enum hns_roce_sgid_type {
255 GID_TYPE_FLAG_ROCE_V1 = 0,
256 GID_TYPE_FLAG_ROCE_V2_IPV4,
257 GID_TYPE_FLAG_ROCE_V2_IPV6,
258};
259
260struct hns_roce_v2_cq_context {
261 __le32 byte_4_pg_ceqn;
262 __le32 byte_8_cqn;
263 __le32 cqe_cur_blk_addr;
264 __le32 byte_16_hop_addr;
265 __le32 cqe_nxt_blk_addr;
266 __le32 byte_24_pgsz_addr;
267 __le32 byte_28_cq_pi;
268 __le32 byte_32_cq_ci;
269 __le32 cqe_ba;
270 __le32 byte_40_cqe_ba;
271 __le32 byte_44_db_record;
272 __le32 db_record_addr;
273 __le32 byte_52_cqe_cnt;
274 __le32 byte_56_cqe_period_maxcnt;
275 __le32 cqe_report_timer;
276 __le32 byte_64_se_cqe_idx;
277};
278
279#define HNS_ROCE_V2_CQ_DEFAULT_BURST_NUM 0x0
280#define HNS_ROCE_V2_CQ_DEFAULT_INTERVAL 0x0
281
282#define CQC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_cq_context, h, l)
283
284#define CQC_CQ_ST CQC_FIELD_LOC(1, 0)
285#define CQC_POLL CQC_FIELD_LOC(2, 2)
286#define CQC_SE CQC_FIELD_LOC(3, 3)
287#define CQC_OVER_IGNORE CQC_FIELD_LOC(4, 4)
288#define CQC_ARM_ST CQC_FIELD_LOC(7, 6)
289#define CQC_SHIFT CQC_FIELD_LOC(12, 8)
290#define CQC_CMD_SN CQC_FIELD_LOC(14, 13)
291#define CQC_CEQN CQC_FIELD_LOC(23, 15)
292#define CQC_CQN CQC_FIELD_LOC(55, 32)
293#define CQC_POE_EN CQC_FIELD_LOC(56, 56)
294#define CQC_POE_NUM CQC_FIELD_LOC(58, 57)
295#define CQC_CQE_SIZE CQC_FIELD_LOC(60, 59)
296#define CQC_CQ_CNT_MODE CQC_FIELD_LOC(61, 61)
297#define CQC_STASH CQC_FIELD_LOC(63, 63)
298#define CQC_CQE_CUR_BLK_ADDR_L CQC_FIELD_LOC(95, 64)
299#define CQC_CQE_CUR_BLK_ADDR_H CQC_FIELD_LOC(115, 96)
300#define CQC_POE_QID CQC_FIELD_LOC(125, 116)
301#define CQC_CQE_HOP_NUM CQC_FIELD_LOC(127, 126)
302#define CQC_CQE_NEX_BLK_ADDR_L CQC_FIELD_LOC(159, 128)
303#define CQC_CQE_NEX_BLK_ADDR_H CQC_FIELD_LOC(179, 160)
304#define CQC_CQE_BAR_PG_SZ CQC_FIELD_LOC(187, 184)
305#define CQC_CQE_BUF_PG_SZ CQC_FIELD_LOC(191, 188)
306#define CQC_CQ_PRODUCER_IDX CQC_FIELD_LOC(215, 192)
307#define CQC_CQ_CONSUMER_IDX CQC_FIELD_LOC(247, 224)
308#define CQC_CQE_BA_L CQC_FIELD_LOC(287, 256)
309#define CQC_CQE_BA_H CQC_FIELD_LOC(316, 288)
310#define CQC_POE_QID_H_0 CQC_FIELD_LOC(319, 317)
311#define CQC_DB_RECORD_EN CQC_FIELD_LOC(320, 320)
312#define CQC_CQE_DB_RECORD_ADDR_L CQC_FIELD_LOC(351, 321)
313#define CQC_CQE_DB_RECORD_ADDR_H CQC_FIELD_LOC(383, 352)
314#define CQC_CQE_CNT CQC_FIELD_LOC(407, 384)
315#define CQC_CQ_MAX_CNT CQC_FIELD_LOC(431, 416)
316#define CQC_CQ_PERIOD CQC_FIELD_LOC(447, 432)
317#define CQC_CQE_REPORT_TIMER CQC_FIELD_LOC(471, 448)
318#define CQC_WR_CQE_IDX CQC_FIELD_LOC(479, 472)
319#define CQC_SE_CQE_IDX CQC_FIELD_LOC(503, 480)
320#define CQC_POE_QID_H_1 CQC_FIELD_LOC(511, 511)
321
322struct hns_roce_srq_context {
323 __le32 data[16];
324};
325
326#define SRQC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_srq_context, h, l)
327
328#define SRQC_SRQ_ST SRQC_FIELD_LOC(1, 0)
329#define SRQC_WQE_HOP_NUM SRQC_FIELD_LOC(3, 2)
330#define SRQC_SHIFT SRQC_FIELD_LOC(7, 4)
331#define SRQC_SRQN SRQC_FIELD_LOC(31, 8)
332#define SRQC_LIMIT_WL SRQC_FIELD_LOC(47, 32)
333#define SRQC_RSV0 SRQC_FIELD_LOC(63, 48)
334#define SRQC_XRCD SRQC_FIELD_LOC(87, 64)
335#define SRQC_RSV1 SRQC_FIELD_LOC(95, 88)
336#define SRQC_PRODUCER_IDX SRQC_FIELD_LOC(111, 96)
337#define SRQC_CONSUMER_IDX SRQC_FIELD_LOC(127, 112)
338#define SRQC_WQE_BT_BA_L SRQC_FIELD_LOC(159, 128)
339#define SRQC_WQE_BT_BA_H SRQC_FIELD_LOC(188, 160)
340#define SRQC_RSV2 SRQC_FIELD_LOC(190, 189)
341#define SRQC_SRQ_TYPE SRQC_FIELD_LOC(191, 191)
342#define SRQC_PD SRQC_FIELD_LOC(215, 192)
343#define SRQC_RQWS SRQC_FIELD_LOC(219, 216)
344#define SRQC_RSV3 SRQC_FIELD_LOC(223, 220)
345#define SRQC_IDX_BT_BA_L SRQC_FIELD_LOC(255, 224)
346#define SRQC_IDX_BT_BA_H SRQC_FIELD_LOC(284, 256)
347#define SRQC_RSV4 SRQC_FIELD_LOC(287, 285)
348#define SRQC_IDX_CUR_BLK_ADDR_L SRQC_FIELD_LOC(319, 288)
349#define SRQC_IDX_CUR_BLK_ADDR_H SRQC_FIELD_LOC(339, 320)
350#define SRQC_RSV5 SRQC_FIELD_LOC(341, 340)
351#define SRQC_IDX_HOP_NUM SRQC_FIELD_LOC(343, 342)
352#define SRQC_IDX_BA_PG_SZ SRQC_FIELD_LOC(347, 344)
353#define SRQC_IDX_BUF_PG_SZ SRQC_FIELD_LOC(351, 348)
354#define SRQC_IDX_NXT_BLK_ADDR_L SRQC_FIELD_LOC(383, 352)
355#define SRQC_IDX_NXT_BLK_ADDR_H SRQC_FIELD_LOC(403, 384)
356#define SRQC_RSV6 SRQC_FIELD_LOC(415, 404)
357#define SRQC_XRC_CQN SRQC_FIELD_LOC(439, 416)
358#define SRQC_WQE_BA_PG_SZ SRQC_FIELD_LOC(443, 440)
359#define SRQC_WQE_BUF_PG_SZ SRQC_FIELD_LOC(447, 444)
360#define SRQC_DB_RECORD_EN SRQC_FIELD_LOC(448, 448)
361#define SRQC_DB_RECORD_ADDR_L SRQC_FIELD_LOC(479, 449)
362#define SRQC_DB_RECORD_ADDR_H SRQC_FIELD_LOC(511, 480)
363
364enum {
365 V2_MPT_ST_VALID = 0x1,
366 V2_MPT_ST_FREE = 0x2,
367};
368
369enum hns_roce_v2_qp_state {
370 HNS_ROCE_QP_ST_RST,
371 HNS_ROCE_QP_ST_INIT,
372 HNS_ROCE_QP_ST_RTR,
373 HNS_ROCE_QP_ST_RTS,
374 HNS_ROCE_QP_ST_SQD,
375 HNS_ROCE_QP_ST_SQER,
376 HNS_ROCE_QP_ST_ERR,
377 HNS_ROCE_QP_ST_SQ_DRAINING,
378 HNS_ROCE_QP_NUM_ST
379};
380
381struct hns_roce_v2_qp_context_ex {
382 __le32 data[64];
383};
384
385struct hns_roce_v2_qp_context {
386 __le32 byte_4_sqpn_tst;
387 __le32 wqe_sge_ba;
388 __le32 byte_12_sq_hop;
389 __le32 byte_16_buf_ba_pg_sz;
390 __le32 byte_20_smac_sgid_idx;
391 __le32 byte_24_mtu_tc;
392 __le32 byte_28_at_fl;
393 u8 dgid[GID_LEN_V2];
394 __le32 dmac;
395 __le32 byte_52_udpspn_dmac;
396 __le32 byte_56_dqpn_err;
397 __le32 byte_60_qpst_tempid;
398 __le32 qkey_xrcd;
399 __le32 byte_68_rq_db;
400 __le32 rq_db_record_addr;
401 __le32 byte_76_srqn_op_en;
402 __le32 byte_80_rnr_rx_cqn;
403 __le32 byte_84_rq_ci_pi;
404 __le32 rq_cur_blk_addr;
405 __le32 byte_92_srq_info;
406 __le32 byte_96_rx_reqmsn;
407 __le32 rq_nxt_blk_addr;
408 __le32 byte_104_rq_sge;
409 __le32 byte_108_rx_reqepsn;
410 __le32 rq_rnr_timer;
411 __le32 rx_msg_len;
412 __le32 rx_rkey_pkt_info;
413 __le64 rx_va;
414 __le32 byte_132_trrl;
415 __le32 trrl_ba;
416 __le32 byte_140_raq;
417 __le32 byte_144_raq;
418 __le32 byte_148_raq;
419 __le32 byte_152_raq;
420 __le32 byte_156_raq;
421 __le32 byte_160_sq_ci_pi;
422 __le32 sq_cur_blk_addr;
423 __le32 byte_168_irrl_idx;
424 __le32 byte_172_sq_psn;
425 __le32 byte_176_msg_pktn;
426 __le32 sq_cur_sge_blk_addr;
427 __le32 byte_184_irrl_idx;
428 __le32 cur_sge_offset;
429 __le32 byte_192_ext_sge;
430 __le32 byte_196_sq_psn;
431 __le32 byte_200_sq_max;
432 __le32 irrl_ba;
433 __le32 byte_208_irrl;
434 __le32 byte_212_lsn;
435 __le32 sq_timer;
436 __le32 byte_220_retry_psn_msn;
437 __le32 byte_224_retry_msg;
438 __le32 rx_sq_cur_blk_addr;
439 __le32 byte_232_irrl_sge;
440 __le32 irrl_cur_sge_offset;
441 __le32 byte_240_irrl_tail;
442 __le32 byte_244_rnr_rxack;
443 __le32 byte_248_ack_psn;
444 __le32 byte_252_err_txcqn;
445 __le32 byte_256_sqflush_rqcqe;
446
447 struct hns_roce_v2_qp_context_ex ext;
448};
449
450#define QPC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_qp_context, h, l)
451
452#define QPC_TST QPC_FIELD_LOC(2, 0)
453#define QPC_SGE_SHIFT QPC_FIELD_LOC(7, 3)
454#define QPC_CNP_TIMER QPC_FIELD_LOC(31, 8)
455#define QPC_WQE_SGE_BA_L QPC_FIELD_LOC(63, 32)
456#define QPC_WQE_SGE_BA_H QPC_FIELD_LOC(92, 64)
457#define QPC_SQ_HOP_NUM QPC_FIELD_LOC(94, 93)
458#define QPC_CIRE_EN QPC_FIELD_LOC(95, 95)
459#define QPC_WQE_SGE_BA_PG_SZ QPC_FIELD_LOC(99, 96)
460#define QPC_WQE_SGE_BUF_PG_SZ QPC_FIELD_LOC(103, 100)
461#define QPC_PD QPC_FIELD_LOC(127, 104)
462#define QPC_RQ_HOP_NUM QPC_FIELD_LOC(129, 128)
463#define QPC_SGE_HOP_NUM QPC_FIELD_LOC(131, 130)
464#define QPC_RQWS QPC_FIELD_LOC(135, 132)
465#define QPC_SQ_SHIFT QPC_FIELD_LOC(139, 136)
466#define QPC_RQ_SHIFT QPC_FIELD_LOC(143, 140)
467#define QPC_GMV_IDX QPC_FIELD_LOC(159, 144)
468#define QPC_HOPLIMIT QPC_FIELD_LOC(167, 160)
469#define QPC_TC QPC_FIELD_LOC(175, 168)
470#define QPC_VLAN_ID QPC_FIELD_LOC(187, 176)
471#define QPC_MTU QPC_FIELD_LOC(191, 188)
472#define QPC_FL QPC_FIELD_LOC(211, 192)
473#define QPC_SL QPC_FIELD_LOC(215, 212)
474#define QPC_CNP_TX_FLAG QPC_FIELD_LOC(216, 216)
475#define QPC_CE_FLAG QPC_FIELD_LOC(217, 217)
476#define QPC_LBI QPC_FIELD_LOC(218, 218)
477#define QPC_AT QPC_FIELD_LOC(223, 219)
478#define QPC_DGID QPC_FIELD_LOC(351, 224)
479#define QPC_DMAC_L QPC_FIELD_LOC(383, 352)
480#define QPC_DMAC_H QPC_FIELD_LOC(399, 384)
481#define QPC_UDPSPN QPC_FIELD_LOC(415, 400)
482#define QPC_DQPN QPC_FIELD_LOC(439, 416)
483#define QPC_SQ_TX_ERR QPC_FIELD_LOC(440, 440)
484#define QPC_SQ_RX_ERR QPC_FIELD_LOC(441, 441)
485#define QPC_RQ_TX_ERR QPC_FIELD_LOC(442, 442)
486#define QPC_RQ_RX_ERR QPC_FIELD_LOC(443, 443)
487#define QPC_LP_PKTN_INI QPC_FIELD_LOC(447, 444)
488#define QPC_CONG_ALGO_TMPL_ID QPC_FIELD_LOC(455, 448)
489#define QPC_SCC_TOKEN QPC_FIELD_LOC(474, 456)
490#define QPC_SQ_DB_DOING QPC_FIELD_LOC(475, 475)
491#define QPC_RQ_DB_DOING QPC_FIELD_LOC(476, 476)
492#define QPC_QP_ST QPC_FIELD_LOC(479, 477)
493#define QPC_QKEY_XRCD QPC_FIELD_LOC(511, 480)
494#define QPC_RQ_RECORD_EN QPC_FIELD_LOC(512, 512)
495#define QPC_RQ_DB_RECORD_ADDR_L QPC_FIELD_LOC(543, 513)
496#define QPC_RQ_DB_RECORD_ADDR_H QPC_FIELD_LOC(575, 544)
497#define QPC_SRQN QPC_FIELD_LOC(599, 576)
498#define QPC_SRQ_EN QPC_FIELD_LOC(600, 600)
499#define QPC_RRE QPC_FIELD_LOC(601, 601)
500#define QPC_RWE QPC_FIELD_LOC(602, 602)
501#define QPC_ATE QPC_FIELD_LOC(603, 603)
502#define QPC_RQIE QPC_FIELD_LOC(604, 604)
503#define QPC_EXT_ATE QPC_FIELD_LOC(605, 605)
504#define QPC_RQ_VLAN_EN QPC_FIELD_LOC(606, 606)
505#define QPC_RQ_RTY_TX_ERR QPC_FIELD_LOC(607, 607)
506#define QPC_RX_CQN QPC_FIELD_LOC(631, 608)
507#define QPC_XRC_QP_TYPE QPC_FIELD_LOC(632, 632)
508#define QPC_CQEIE QPC_FIELD_LOC(633, 633)
509#define QPC_CQEIS QPC_FIELD_LOC(634, 634)
510#define QPC_MIN_RNR_TIME QPC_FIELD_LOC(639, 635)
511#define QPC_RQ_PRODUCER_IDX QPC_FIELD_LOC(655, 640)
512#define QPC_RQ_CONSUMER_IDX QPC_FIELD_LOC(671, 656)
513#define QPC_RQ_CUR_BLK_ADDR_L QPC_FIELD_LOC(703, 672)
514#define QPC_RQ_CUR_BLK_ADDR_H QPC_FIELD_LOC(723, 704)
515#define QPC_SRQ_INFO QPC_FIELD_LOC(735, 724)
516#define QPC_RX_REQ_MSN QPC_FIELD_LOC(759, 736)
517#define QPC_REDUCE_CODE QPC_FIELD_LOC(766, 760)
518#define QPC_RX_XRC_PKT_CQE_FLG QPC_FIELD_LOC(767, 767)
519#define QPC_RQ_NXT_BLK_ADDR_L QPC_FIELD_LOC(799, 768)
520#define QPC_RQ_NXT_BLK_ADDR_H QPC_FIELD_LOC(819, 800)
521#define QPC_REDUCE_EN QPC_FIELD_LOC(820, 820)
522#define QPC_FLUSH_EN QPC_FIELD_LOC(821, 821)
523#define QPC_AW_EN QPC_FIELD_LOC(822, 822)
524#define QPC_WN_EN QPC_FIELD_LOC(823, 823)
525#define QPC_RQ_CUR_WQE_SGE_NUM QPC_FIELD_LOC(831, 824)
526#define QPC_INV_CREDIT QPC_FIELD_LOC(832, 832)
527#define QPC_LAST_WRITE_TYPE QPC_FIELD_LOC(834, 833)
528#define QPC_RX_REQ_PSN_ERR QPC_FIELD_LOC(835, 835)
529#define QPC_RX_REQ_LAST_OPTYPE QPC_FIELD_LOC(838, 836)
530#define QPC_RX_REQ_RNR QPC_FIELD_LOC(839, 839)
531#define QPC_RX_REQ_EPSN QPC_FIELD_LOC(863, 840)
532#define QPC_RQ_RNR_TIMER QPC_FIELD_LOC(895, 864)
533#define QPC_RX_MSG_LEN QPC_FIELD_LOC(927, 896)
534#define QPC_RX_RKEY_PKT_INFO QPC_FIELD_LOC(959, 928)
535#define QPC_RX_VA QPC_FIELD_LOC(1023, 960)
536#define QPC_TRRL_HEAD_MAX QPC_FIELD_LOC(1031, 1024)
537#define QPC_TRRL_TAIL_MAX QPC_FIELD_LOC(1039, 1032)
538#define QPC_TRRL_BA_L QPC_FIELD_LOC(1055, 1040)
539#define QPC_TRRL_BA_M QPC_FIELD_LOC(1087, 1056)
540#define QPC_TRRL_BA_H QPC_FIELD_LOC(1099, 1088)
541#define QPC_RR_MAX QPC_FIELD_LOC(1102, 1100)
542#define QPC_RQ_RTY_WAIT_DO QPC_FIELD_LOC(1103, 1103)
543#define QPC_RAQ_TRRL_HEAD QPC_FIELD_LOC(1111, 1104)
544#define QPC_RAQ_TRRL_TAIL QPC_FIELD_LOC(1119, 1112)
545#define QPC_RAQ_RTY_INI_PSN QPC_FIELD_LOC(1143, 1120)
546#define QPC_CIRE_SLV_RQ_EN QPC_FIELD_LOC(1144, 1144)
547#define QPC_RAQ_CREDIT QPC_FIELD_LOC(1149, 1145)
548#define QPC_RQ_DB_IN_EXT QPC_FIELD_LOC(1150, 1150)
549#define QPC_RESP_RTY_FLG QPC_FIELD_LOC(1151, 1151)
550#define QPC_RAQ_MSN QPC_FIELD_LOC(1175, 1152)
551#define QPC_RAQ_SYNDROME QPC_FIELD_LOC(1183, 1176)
552#define QPC_RAQ_PSN QPC_FIELD_LOC(1207, 1184)
553#define QPC_RAQ_TRRL_RTY_HEAD QPC_FIELD_LOC(1215, 1208)
554#define QPC_RAQ_USE_PKTN QPC_FIELD_LOC(1239, 1216)
555#define QPC_RQ_SCC_TOKEN QPC_FIELD_LOC(1245, 1240)
556#define QPC_RVD10 QPC_FIELD_LOC(1247, 1246)
557#define QPC_SQ_PRODUCER_IDX QPC_FIELD_LOC(1263, 1248)
558#define QPC_SQ_CONSUMER_IDX QPC_FIELD_LOC(1279, 1264)
559#define QPC_SQ_CUR_BLK_ADDR_L QPC_FIELD_LOC(1311, 1280)
560#define QPC_SQ_CUR_BLK_ADDR_H QPC_FIELD_LOC(1331, 1312)
561#define QPC_MSG_RTY_LP_FLG QPC_FIELD_LOC(1332, 1332)
562#define QPC_SQ_INVLD_FLG QPC_FIELD_LOC(1333, 1333)
563#define QPC_LP_SGEN_INI QPC_FIELD_LOC(1335, 1334)
564#define QPC_SQ_VLAN_EN QPC_FIELD_LOC(1336, 1336)
565#define QPC_POLL_DB_WAIT_DO QPC_FIELD_LOC(1337, 1337)
566#define QPC_SCC_TOKEN_FORBID_SQ_DEQ QPC_FIELD_LOC(1338, 1338)
567#define QPC_WAIT_ACK_TIMEOUT QPC_FIELD_LOC(1339, 1339)
568#define QPC_IRRL_IDX_LSB QPC_FIELD_LOC(1343, 1340)
569#define QPC_ACK_REQ_FREQ QPC_FIELD_LOC(1349, 1344)
570#define QPC_MSG_RNR_FLG QPC_FIELD_LOC(1350, 1350)
571#define QPC_FRE QPC_FIELD_LOC(1351, 1351)
572#define QPC_SQ_CUR_PSN QPC_FIELD_LOC(1375, 1352)
573#define QPC_MSG_USE_PKTN QPC_FIELD_LOC(1399, 1376)
574#define QPC_IRRL_HEAD_PRE QPC_FIELD_LOC(1407, 1400)
575#define QPC_SQ_CUR_SGE_BLK_ADDR_L QPC_FIELD_LOC(1439, 1408)
576#define QPC_SQ_CUR_SGE_BLK_ADDR_H QPC_FIELD_LOC(1459, 1440)
577#define QPC_IRRL_IDX_MSB QPC_FIELD_LOC(1471, 1460)
578#define QPC_CUR_SGE_OFFSET QPC_FIELD_LOC(1503, 1472)
579#define QPC_CUR_SGE_IDX QPC_FIELD_LOC(1527, 1504)
580#define QPC_EXT_SGE_NUM_LEFT QPC_FIELD_LOC(1535, 1528)
581#define QPC_OWNER_MODE QPC_FIELD_LOC(1536, 1536)
582#define QPC_CIRE_SLV_SQ_EN QPC_FIELD_LOC(1537, 1537)
583#define QPC_CIRE_DOING QPC_FIELD_LOC(1538, 1538)
584#define QPC_CIRE_RESULT QPC_FIELD_LOC(1539, 1539)
585#define QPC_OWNER_DB_WAIT_DO QPC_FIELD_LOC(1540, 1540)
586#define QPC_SQ_WQE_INVLD QPC_FIELD_LOC(1541, 1541)
587#define QPC_DCA_MODE QPC_FIELD_LOC(1542, 1542)
588#define QPC_RTY_OWNER_NOCHK QPC_FIELD_LOC(1543, 1543)
589#define QPC_V2_IRRL_HEAD QPC_FIELD_LOC(1543, 1536)
590#define QPC_SQ_MAX_PSN QPC_FIELD_LOC(1567, 1544)
591#define QPC_SQ_MAX_IDX QPC_FIELD_LOC(1583, 1568)
592#define QPC_LCL_OPERATED_CNT QPC_FIELD_LOC(1599, 1584)
593#define QPC_IRRL_BA_L QPC_FIELD_LOC(1631, 1600)
594#define QPC_IRRL_BA_H QPC_FIELD_LOC(1657, 1632)
595#define QPC_PKT_RNR_FLG QPC_FIELD_LOC(1658, 1658)
596#define QPC_PKT_RTY_FLG QPC_FIELD_LOC(1659, 1659)
597#define QPC_RMT_E2E QPC_FIELD_LOC(1660, 1660)
598#define QPC_SR_MAX QPC_FIELD_LOC(1663, 1661)
599#define QPC_LSN QPC_FIELD_LOC(1687, 1664)
600#define QPC_RETRY_NUM_INIT QPC_FIELD_LOC(1690, 1688)
601#define QPC_CHECK_FLG QPC_FIELD_LOC(1692, 1691)
602#define QPC_RETRY_CNT QPC_FIELD_LOC(1695, 1693)
603#define QPC_SQ_TIMER QPC_FIELD_LOC(1727, 1696)
604#define QPC_RETRY_MSG_MSN QPC_FIELD_LOC(1743, 1728)
605#define QPC_RETRY_MSG_PSN_L QPC_FIELD_LOC(1759, 1744)
606#define QPC_RETRY_MSG_PSN_H QPC_FIELD_LOC(1767, 1760)
607#define QPC_RETRY_MSG_FPKT_PSN QPC_FIELD_LOC(1791, 1768)
608#define QPC_RX_SQ_CUR_BLK_ADDR_L QPC_FIELD_LOC(1823, 1792)
609#define QPC_RX_SQ_CUR_BLK_ADDR_H QPC_FIELD_LOC(1843, 1824)
610#define QPC_IRRL_SGE_IDX QPC_FIELD_LOC(1851, 1844)
611#define QPC_LSAN_EN QPC_FIELD_LOC(1852, 1852)
612#define QPC_SO_LP_VLD QPC_FIELD_LOC(1853, 1853)
613#define QPC_FENCE_LP_VLD QPC_FIELD_LOC(1854, 1854)
614#define QPC_IRRL_LP_VLD QPC_FIELD_LOC(1855, 1855)
615#define QPC_IRRL_CUR_SGE_OFFSET QPC_FIELD_LOC(1887, 1856)
616#define QPC_IRRL_TAIL_REAL QPC_FIELD_LOC(1895, 1888)
617#define QPC_IRRL_TAIL_RD QPC_FIELD_LOC(1903, 1896)
618#define QPC_RX_ACK_MSN QPC_FIELD_LOC(1919, 1904)
619#define QPC_RX_ACK_EPSN QPC_FIELD_LOC(1943, 1920)
620#define QPC_RNR_NUM_INIT QPC_FIELD_LOC(1946, 1944)
621#define QPC_RNR_CNT QPC_FIELD_LOC(1949, 1947)
622#define QPC_LCL_OP_FLG QPC_FIELD_LOC(1950, 1950)
623#define QPC_IRRL_RD_FLG QPC_FIELD_LOC(1951, 1951)
624#define QPC_IRRL_PSN QPC_FIELD_LOC(1975, 1952)
625#define QPC_ACK_PSN_ERR QPC_FIELD_LOC(1976, 1976)
626#define QPC_ACK_LAST_OPTYPE QPC_FIELD_LOC(1978, 1977)
627#define QPC_IRRL_PSN_VLD QPC_FIELD_LOC(1979, 1979)
628#define QPC_RNR_RETRY_FLAG QPC_FIELD_LOC(1980, 1980)
629#define QPC_SQ_RTY_TX_ERR QPC_FIELD_LOC(1981, 1981)
630#define QPC_LAST_IND QPC_FIELD_LOC(1982, 1982)
631#define QPC_CQ_ERR_IND QPC_FIELD_LOC(1983, 1983)
632#define QPC_TX_CQN QPC_FIELD_LOC(2007, 1984)
633#define QPC_SIG_TYPE QPC_FIELD_LOC(2008, 2008)
634#define QPC_ERR_TYPE QPC_FIELD_LOC(2015, 2009)
635#define QPC_RQ_CQE_IDX QPC_FIELD_LOC(2031, 2016)
636#define QPC_SQ_FLUSH_IDX QPC_FIELD_LOC(2047, 2032)
637
638#define RETRY_MSG_PSN_SHIFT 16
639
640#define QPCEX_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_qp_context_ex, h, l)
641
642#define QPCEX_CONG_ALG_SEL QPCEX_FIELD_LOC(0, 0)
643#define QPCEX_CONG_ALG_SUB_SEL QPCEX_FIELD_LOC(1, 1)
644#define QPCEX_DIP_CTX_IDX_VLD QPCEX_FIELD_LOC(2, 2)
645#define QPCEX_DIP_CTX_IDX QPCEX_FIELD_LOC(22, 3)
646#define QPCEX_SQ_RQ_NOT_FORBID_EN QPCEX_FIELD_LOC(23, 23)
647#define QPCEX_STASH QPCEX_FIELD_LOC(82, 82)
648
649#define V2_QP_RWE_S 1 /* rdma write enable */
650#define V2_QP_RRE_S 2 /* rdma read enable */
651#define V2_QP_ATE_S 3 /* rdma atomic enable */
652
653struct hns_roce_v2_cqe {
654 __le32 byte_4;
655 union {
656 __le32 rkey;
657 __le32 immtdata;
658 };
659 __le32 byte_12;
660 __le32 byte_16;
661 __le32 byte_cnt;
662 u8 smac[4];
663 __le32 byte_28;
664 __le32 byte_32;
665 __le32 rsv[8];
666};
667
668#define CQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_cqe, h, l)
669
670#define CQE_OPCODE CQE_FIELD_LOC(4, 0)
671#define CQE_RQ_INLINE CQE_FIELD_LOC(5, 5)
672#define CQE_S_R CQE_FIELD_LOC(6, 6)
673#define CQE_OWNER CQE_FIELD_LOC(7, 7)
674#define CQE_STATUS CQE_FIELD_LOC(15, 8)
675#define CQE_WQE_IDX CQE_FIELD_LOC(31, 16)
676#define CQE_RKEY_IMMTDATA CQE_FIELD_LOC(63, 32)
677#define CQE_XRC_SRQN CQE_FIELD_LOC(87, 64)
678#define CQE_RSV0 CQE_FIELD_LOC(95, 88)
679#define CQE_LCL_QPN CQE_FIELD_LOC(119, 96)
680#define CQE_SUB_STATUS CQE_FIELD_LOC(127, 120)
681#define CQE_BYTE_CNT CQE_FIELD_LOC(159, 128)
682#define CQE_SMAC CQE_FIELD_LOC(207, 160)
683#define CQE_PORT_TYPE CQE_FIELD_LOC(209, 208)
684#define CQE_VID CQE_FIELD_LOC(221, 210)
685#define CQE_VID_VLD CQE_FIELD_LOC(222, 222)
686#define CQE_RSV2 CQE_FIELD_LOC(223, 223)
687#define CQE_RMT_QPN CQE_FIELD_LOC(247, 224)
688#define CQE_SL CQE_FIELD_LOC(250, 248)
689#define CQE_PORTN CQE_FIELD_LOC(253, 251)
690#define CQE_GRH CQE_FIELD_LOC(254, 254)
691#define CQE_LPK CQE_FIELD_LOC(255, 255)
692#define CQE_RSV3 CQE_FIELD_LOC(511, 256)
693
694struct hns_roce_v2_mpt_entry {
695 __le32 byte_4_pd_hop_st;
696 __le32 byte_8_mw_cnt_en;
697 __le32 byte_12_mw_pa;
698 __le32 bound_lkey;
699 __le32 len_l;
700 __le32 len_h;
701 __le32 lkey;
702 __le32 va_l;
703 __le32 va_h;
704 __le32 pbl_size;
705 __le32 pbl_ba_l;
706 __le32 byte_48_mode_ba;
707 __le32 pa0_l;
708 __le32 byte_56_pa0_h;
709 __le32 pa1_l;
710 __le32 byte_64_buf_pa1;
711};
712
713#define MPT_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_mpt_entry, h, l)
714
715#define MPT_ST MPT_FIELD_LOC(1, 0)
716#define MPT_PBL_HOP_NUM MPT_FIELD_LOC(3, 2)
717#define MPT_PBL_BA_PG_SZ MPT_FIELD_LOC(7, 4)
718#define MPT_PD MPT_FIELD_LOC(31, 8)
719#define MPT_RA_EN MPT_FIELD_LOC(32, 32)
720#define MPT_R_INV_EN MPT_FIELD_LOC(33, 33)
721#define MPT_L_INV_EN MPT_FIELD_LOC(34, 34)
722#define MPT_BIND_EN MPT_FIELD_LOC(35, 35)
723#define MPT_ATOMIC_EN MPT_FIELD_LOC(36, 36)
724#define MPT_RR_EN MPT_FIELD_LOC(37, 37)
725#define MPT_RW_EN MPT_FIELD_LOC(38, 38)
726#define MPT_LW_EN MPT_FIELD_LOC(39, 39)
727#define MPT_MW_CNT MPT_FIELD_LOC(63, 40)
728#define MPT_FRE MPT_FIELD_LOC(64, 64)
729#define MPT_PA MPT_FIELD_LOC(65, 65)
730#define MPT_ZBVA MPT_FIELD_LOC(66, 66)
731#define MPT_SHARE MPT_FIELD_LOC(67, 67)
732#define MPT_MR_MW MPT_FIELD_LOC(68, 68)
733#define MPT_BPD MPT_FIELD_LOC(69, 69)
734#define MPT_BQP MPT_FIELD_LOC(70, 70)
735#define MPT_INNER_PA_VLD MPT_FIELD_LOC(71, 71)
736#define MPT_MW_BIND_QPN MPT_FIELD_LOC(95, 72)
737#define MPT_BOUND_LKEY MPT_FIELD_LOC(127, 96)
738#define MPT_LEN_L MPT_FIELD_LOC(159, 128)
739#define MPT_LEN_H MPT_FIELD_LOC(191, 160)
740#define MPT_LKEY MPT_FIELD_LOC(223, 192)
741#define MPT_VA MPT_FIELD_LOC(287, 224)
742#define MPT_PBL_SIZE MPT_FIELD_LOC(319, 288)
743#define MPT_PBL_BA_L MPT_FIELD_LOC(351, 320)
744#define MPT_PBL_BA_H MPT_FIELD_LOC(380, 352)
745#define MPT_BLK_MODE MPT_FIELD_LOC(381, 381)
746#define MPT_RSV0 MPT_FIELD_LOC(383, 382)
747#define MPT_PA0_L MPT_FIELD_LOC(415, 384)
748#define MPT_PA0_H MPT_FIELD_LOC(441, 416)
749#define MPT_BOUND_VA MPT_FIELD_LOC(447, 442)
750#define MPT_PA1_L MPT_FIELD_LOC(479, 448)
751#define MPT_PA1_H MPT_FIELD_LOC(505, 480)
752#define MPT_PERSIST_EN MPT_FIELD_LOC(506, 506)
753#define MPT_RSV2 MPT_FIELD_LOC(507, 507)
754#define MPT_PBL_BUF_PG_SZ MPT_FIELD_LOC(511, 508)
755
756#define V2_MPT_BYTE_4_MPT_ST_S 0
757#define V2_MPT_BYTE_4_MPT_ST_M GENMASK(1, 0)
758
759#define V2_MPT_BYTE_4_PBL_HOP_NUM_S 2
760#define V2_MPT_BYTE_4_PBL_HOP_NUM_M GENMASK(3, 2)
761
762#define V2_MPT_BYTE_4_PBL_BA_PG_SZ_S 4
763#define V2_MPT_BYTE_4_PBL_BA_PG_SZ_M GENMASK(7, 4)
764
765#define V2_MPT_BYTE_4_PD_S 8
766#define V2_MPT_BYTE_4_PD_M GENMASK(31, 8)
767
768#define V2_MPT_BYTE_8_RA_EN_S 0
769
770#define V2_MPT_BYTE_8_R_INV_EN_S 1
771
772#define V2_MPT_BYTE_8_L_INV_EN_S 2
773
774#define V2_MPT_BYTE_8_BIND_EN_S 3
775
776#define V2_MPT_BYTE_8_ATOMIC_EN_S 4
777
778#define V2_MPT_BYTE_8_RR_EN_S 5
779
780#define V2_MPT_BYTE_8_RW_EN_S 6
781
782#define V2_MPT_BYTE_8_LW_EN_S 7
783
784#define V2_MPT_BYTE_8_MW_CNT_S 8
785#define V2_MPT_BYTE_8_MW_CNT_M GENMASK(31, 8)
786
787#define V2_MPT_BYTE_12_FRE_S 0
788
789#define V2_MPT_BYTE_12_PA_S 1
790
791#define V2_MPT_BYTE_12_MR_MW_S 4
792
793#define V2_MPT_BYTE_12_BPD_S 5
794
795#define V2_MPT_BYTE_12_BQP_S 6
796
797#define V2_MPT_BYTE_12_INNER_PA_VLD_S 7
798
799#define V2_MPT_BYTE_12_MW_BIND_QPN_S 8
800#define V2_MPT_BYTE_12_MW_BIND_QPN_M GENMASK(31, 8)
801
802#define V2_MPT_BYTE_48_PBL_BA_H_S 0
803#define V2_MPT_BYTE_48_PBL_BA_H_M GENMASK(28, 0)
804
805#define V2_MPT_BYTE_48_BLK_MODE_S 29
806
807#define V2_MPT_BYTE_56_PA0_H_S 0
808#define V2_MPT_BYTE_56_PA0_H_M GENMASK(25, 0)
809
810#define V2_MPT_BYTE_64_PA1_H_S 0
811#define V2_MPT_BYTE_64_PA1_H_M GENMASK(25, 0)
812
813#define V2_MPT_BYTE_64_PBL_BUF_PG_SZ_S 28
814#define V2_MPT_BYTE_64_PBL_BUF_PG_SZ_M GENMASK(31, 28)
815
816struct hns_roce_v2_db {
817 __le32 data[2];
818};
819
820#define DB_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_db, h, l)
821
822#define DB_TAG DB_FIELD_LOC(23, 0)
823#define DB_CMD DB_FIELD_LOC(27, 24)
824#define DB_FLAG DB_FIELD_LOC(31, 31)
825#define DB_PI DB_FIELD_LOC(47, 32)
826#define DB_SL DB_FIELD_LOC(50, 48)
827#define DB_CQ_CI DB_FIELD_LOC(55, 32)
828#define DB_CQ_NOTIFY DB_FIELD_LOC(56, 56)
829#define DB_CQ_CMD_SN DB_FIELD_LOC(58, 57)
830#define EQ_DB_TAG DB_FIELD_LOC(7, 0)
831#define EQ_DB_CMD DB_FIELD_LOC(17, 16)
832#define EQ_DB_CI DB_FIELD_LOC(55, 32)
833
834#define V2_DB_PRODUCER_IDX_S 0
835#define V2_DB_PRODUCER_IDX_M GENMASK(15, 0)
836
837#define V2_CQ_DB_CONS_IDX_S 0
838#define V2_CQ_DB_CONS_IDX_M GENMASK(23, 0)
839
840struct hns_roce_v2_ud_send_wqe {
841 __le32 byte_4;
842 __le32 msg_len;
843 __le32 immtdata;
844 __le32 byte_16;
845 __le32 byte_20;
846 __le32 byte_24;
847 __le32 qkey;
848 __le32 byte_32;
849 __le32 byte_36;
850 __le32 byte_40;
851 u8 dmac[ETH_ALEN];
852 u8 sgid_index;
853 u8 smac_index;
854 u8 dgid[GID_LEN_V2];
855};
856
857#define UD_SEND_WQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_ud_send_wqe, h, l)
858
859#define UD_SEND_WQE_OPCODE UD_SEND_WQE_FIELD_LOC(4, 0)
860#define UD_SEND_WQE_OWNER UD_SEND_WQE_FIELD_LOC(7, 7)
861#define UD_SEND_WQE_CQE UD_SEND_WQE_FIELD_LOC(8, 8)
862#define UD_SEND_WQE_SE UD_SEND_WQE_FIELD_LOC(11, 11)
863#define UD_SEND_WQE_PD UD_SEND_WQE_FIELD_LOC(119, 96)
864#define UD_SEND_WQE_SGE_NUM UD_SEND_WQE_FIELD_LOC(127, 120)
865#define UD_SEND_WQE_MSG_START_SGE_IDX UD_SEND_WQE_FIELD_LOC(151, 128)
866#define UD_SEND_WQE_UDPSPN UD_SEND_WQE_FIELD_LOC(191, 176)
867#define UD_SEND_WQE_DQPN UD_SEND_WQE_FIELD_LOC(247, 224)
868#define UD_SEND_WQE_VLAN UD_SEND_WQE_FIELD_LOC(271, 256)
869#define UD_SEND_WQE_HOPLIMIT UD_SEND_WQE_FIELD_LOC(279, 272)
870#define UD_SEND_WQE_TCLASS UD_SEND_WQE_FIELD_LOC(287, 280)
871#define UD_SEND_WQE_FLOW_LABEL UD_SEND_WQE_FIELD_LOC(307, 288)
872#define UD_SEND_WQE_SL UD_SEND_WQE_FIELD_LOC(311, 308)
873#define UD_SEND_WQE_VLAN_EN UD_SEND_WQE_FIELD_LOC(318, 318)
874#define UD_SEND_WQE_LBI UD_SEND_WQE_FIELD_LOC(319, 319)
875
876struct hns_roce_v2_rc_send_wqe {
877 __le32 byte_4;
878 __le32 msg_len;
879 union {
880 __le32 inv_key;
881 __le32 immtdata;
882 };
883 __le32 byte_16;
884 __le32 byte_20;
885 __le32 rkey;
886 __le64 va;
887};
888
889#define RC_SEND_WQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_rc_send_wqe, h, l)
890
891#define RC_SEND_WQE_OPCODE RC_SEND_WQE_FIELD_LOC(4, 0)
892#define RC_SEND_WQE_DB_SL_L RC_SEND_WQE_FIELD_LOC(6, 5)
893#define RC_SEND_WQE_DB_SL_H RC_SEND_WQE_FIELD_LOC(14, 13)
894#define RC_SEND_WQE_OWNER RC_SEND_WQE_FIELD_LOC(7, 7)
895#define RC_SEND_WQE_CQE RC_SEND_WQE_FIELD_LOC(8, 8)
896#define RC_SEND_WQE_FENCE RC_SEND_WQE_FIELD_LOC(9, 9)
897#define RC_SEND_WQE_SE RC_SEND_WQE_FIELD_LOC(11, 11)
898#define RC_SEND_WQE_INLINE RC_SEND_WQE_FIELD_LOC(12, 12)
899#define RC_SEND_WQE_WQE_INDEX RC_SEND_WQE_FIELD_LOC(30, 15)
900#define RC_SEND_WQE_FLAG RC_SEND_WQE_FIELD_LOC(31, 31)
901#define RC_SEND_WQE_XRC_SRQN RC_SEND_WQE_FIELD_LOC(119, 96)
902#define RC_SEND_WQE_SGE_NUM RC_SEND_WQE_FIELD_LOC(127, 120)
903#define RC_SEND_WQE_MSG_START_SGE_IDX RC_SEND_WQE_FIELD_LOC(151, 128)
904#define RC_SEND_WQE_INL_TYPE RC_SEND_WQE_FIELD_LOC(159, 159)
905
906struct hns_roce_wqe_frmr_seg {
907 __le32 pbl_size;
908 __le32 byte_40;
909};
910
911#define FRMR_WQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_wqe_frmr_seg, h, l)
912
913#define FRMR_PBL_SIZE FRMR_WQE_FIELD_LOC(31, 0)
914#define FRMR_BLOCK_SIZE FRMR_WQE_FIELD_LOC(35, 32)
915#define FRMR_PBL_BUF_PG_SZ FRMR_WQE_FIELD_LOC(39, 36)
916#define FRMR_BLK_MODE FRMR_WQE_FIELD_LOC(40, 40)
917#define FRMR_ZBVA FRMR_WQE_FIELD_LOC(41, 41)
918#define FRMR_BIND_EN FRMR_WQE_FIELD_LOC(42, 42)
919#define FRMR_ATOMIC FRMR_WQE_FIELD_LOC(43, 43)
920#define FRMR_RR FRMR_WQE_FIELD_LOC(44, 44)
921#define FRMR_RW FRMR_WQE_FIELD_LOC(45, 45)
922#define FRMR_LW FRMR_WQE_FIELD_LOC(46, 46)
923
924struct hns_roce_v2_wqe_data_seg {
925 __le32 len;
926 __le32 lkey;
927 __le64 addr;
928};
929
930struct hns_roce_query_version {
931 __le16 rocee_vendor_id;
932 __le16 rocee_hw_version;
933 __le32 rsv[5];
934};
935
936struct hns_roce_query_fw_info {
937 __le32 fw_ver;
938 __le32 rsv[5];
939};
940
941struct hns_roce_func_clear {
942 __le32 rst_funcid_en;
943 __le32 func_done;
944 __le32 rsv[4];
945};
946
947#define FUNC_CLEAR_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_func_clear, h, l)
948
949#define FUNC_CLEAR_RST_FUN_DONE FUNC_CLEAR_FIELD_LOC(32, 32)
950
951/* Each physical function manages up to 248 virtual functions, it takes up to
952 * 100ms for each function to execute clear. If an abnormal reset occurs, it is
953 * executed twice at most, so it takes up to 249 * 2 * 100ms.
954 */
955#define HNS_ROCE_V2_FUNC_CLEAR_TIMEOUT_MSECS (249 * 2 * 100)
956#define HNS_ROCE_V2_READ_FUNC_CLEAR_FLAG_INTERVAL 40
957#define HNS_ROCE_V2_READ_FUNC_CLEAR_FLAG_FAIL_WAIT 20
958
959#define CFG_LLM_A_BA_L CMQ_REQ_FIELD_LOC(31, 0)
960#define CFG_LLM_A_BA_H CMQ_REQ_FIELD_LOC(63, 32)
961#define CFG_LLM_A_DEPTH CMQ_REQ_FIELD_LOC(76, 64)
962#define CFG_LLM_A_PGSZ CMQ_REQ_FIELD_LOC(83, 80)
963#define CFG_LLM_A_INIT_EN CMQ_REQ_FIELD_LOC(84, 84)
964#define CFG_LLM_A_HEAD_BA_L CMQ_REQ_FIELD_LOC(127, 96)
965#define CFG_LLM_A_HEAD_BA_H CMQ_REQ_FIELD_LOC(147, 128)
966#define CFG_LLM_A_HEAD_NXTPTR CMQ_REQ_FIELD_LOC(159, 148)
967#define CFG_LLM_A_HEAD_PTR CMQ_REQ_FIELD_LOC(171, 160)
968#define CFG_LLM_B_TAIL_BA_L CMQ_REQ_FIELD_LOC(31, 0)
969#define CFG_LLM_B_TAIL_BA_H CMQ_REQ_FIELD_LOC(63, 32)
970#define CFG_LLM_B_TAIL_PTR CMQ_REQ_FIELD_LOC(75, 64)
971
972/* Fields of HNS_ROCE_OPC_CFG_GLOBAL_PARAM */
973#define CFG_GLOBAL_PARAM_1US_CYCLES CMQ_REQ_FIELD_LOC(9, 0)
974#define CFG_GLOBAL_PARAM_UDP_PORT CMQ_REQ_FIELD_LOC(31, 16)
975
976/*
977 * Fields of HNS_ROCE_OPC_QUERY_PF_RES, HNS_ROCE_OPC_QUERY_VF_RES
978 * and HNS_ROCE_OPC_ALLOC_VF_RES
979 */
980#define FUNC_RES_A_VF_ID CMQ_REQ_FIELD_LOC(7, 0)
981#define FUNC_RES_A_QPC_BT_IDX CMQ_REQ_FIELD_LOC(42, 32)
982#define FUNC_RES_A_QPC_BT_NUM CMQ_REQ_FIELD_LOC(59, 48)
983#define FUNC_RES_A_SRQC_BT_IDX CMQ_REQ_FIELD_LOC(72, 64)
984#define FUNC_RES_A_SRQC_BT_NUM CMQ_REQ_FIELD_LOC(89, 80)
985#define FUNC_RES_A_CQC_BT_IDX CMQ_REQ_FIELD_LOC(104, 96)
986#define FUNC_RES_A_CQC_BT_NUM CMQ_REQ_FIELD_LOC(121, 112)
987#define FUNC_RES_A_MPT_BT_IDX CMQ_REQ_FIELD_LOC(136, 128)
988#define FUNC_RES_A_MPT_BT_NUM CMQ_REQ_FIELD_LOC(153, 144)
989#define FUNC_RES_A_EQC_BT_IDX CMQ_REQ_FIELD_LOC(168, 160)
990#define FUNC_RES_A_EQC_BT_NUM CMQ_REQ_FIELD_LOC(185, 176)
991#define FUNC_RES_B_SMAC_IDX CMQ_REQ_FIELD_LOC(39, 32)
992#define FUNC_RES_B_SMAC_NUM CMQ_REQ_FIELD_LOC(48, 40)
993#define FUNC_RES_B_SGID_IDX CMQ_REQ_FIELD_LOC(71, 64)
994#define FUNC_RES_B_SGID_NUM CMQ_REQ_FIELD_LOC(80, 72)
995#define FUNC_RES_B_QID_IDX CMQ_REQ_FIELD_LOC(105, 96)
996#define FUNC_RES_B_QID_NUM CMQ_REQ_FIELD_LOC(122, 112)
997#define FUNC_RES_V_QID_NUM CMQ_REQ_FIELD_LOC(115, 112)
998
999#define FUNC_RES_B_SCCC_BT_IDX CMQ_REQ_FIELD_LOC(136, 128)
1000#define FUNC_RES_B_SCCC_BT_NUM CMQ_REQ_FIELD_LOC(145, 137)
1001#define FUNC_RES_B_GMV_BT_IDX CMQ_REQ_FIELD_LOC(167, 160)
1002#define FUNC_RES_B_GMV_BT_NUM CMQ_REQ_FIELD_LOC(176, 168)
1003#define FUNC_RES_V_GMV_BT_NUM CMQ_REQ_FIELD_LOC(184, 176)
1004
1005/* Fields of HNS_ROCE_OPC_QUERY_PF_TIMER_RES */
1006#define PF_TIMER_RES_QPC_ITEM_IDX CMQ_REQ_FIELD_LOC(43, 32)
1007#define PF_TIMER_RES_QPC_ITEM_NUM CMQ_REQ_FIELD_LOC(60, 48)
1008#define PF_TIMER_RES_CQC_ITEM_IDX CMQ_REQ_FIELD_LOC(74, 64)
1009#define PF_TIMER_RES_CQC_ITEM_NUM CMQ_REQ_FIELD_LOC(91, 80)
1010
1011struct hns_roce_vf_switch {
1012 __le32 rocee_sel;
1013 __le32 fun_id;
1014 __le32 cfg;
1015 __le32 resv1;
1016 __le32 resv2;
1017 __le32 resv3;
1018};
1019
1020#define VF_SWITCH_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_vf_switch, h, l)
1021
1022#define VF_SWITCH_VF_ID VF_SWITCH_FIELD_LOC(42, 35)
1023#define VF_SWITCH_ALW_LPBK VF_SWITCH_FIELD_LOC(65, 65)
1024#define VF_SWITCH_ALW_LCL_LPBK VF_SWITCH_FIELD_LOC(66, 66)
1025#define VF_SWITCH_ALW_DST_OVRD VF_SWITCH_FIELD_LOC(67, 67)
1026
1027struct hns_roce_post_mbox {
1028 __le32 in_param_l;
1029 __le32 in_param_h;
1030 __le32 out_param_l;
1031 __le32 out_param_h;
1032 __le32 cmd_tag;
1033 __le32 token_event_en;
1034};
1035
1036struct hns_roce_mbox_status {
1037 __le32 mb_status_hw_run;
1038 __le32 rsv[5];
1039};
1040
1041#define HNS_ROCE_V2_GO_BIT_TIMEOUT_MSECS 10000
1042
1043#define MB_ST_HW_RUN_M BIT(31)
1044#define MB_ST_COMPLETE_M GENMASK(7, 0)
1045
1046#define MB_ST_COMPLETE_SUCC 1
1047
1048/* Fields of HNS_ROCE_OPC_CFG_BT_ATTR */
1049#define CFG_BT_ATTR_QPC_BA_PGSZ CMQ_REQ_FIELD_LOC(3, 0)
1050#define CFG_BT_ATTR_QPC_BUF_PGSZ CMQ_REQ_FIELD_LOC(7, 4)
1051#define CFG_BT_ATTR_QPC_HOPNUM CMQ_REQ_FIELD_LOC(9, 8)
1052#define CFG_BT_ATTR_SRQC_BA_PGSZ CMQ_REQ_FIELD_LOC(35, 32)
1053#define CFG_BT_ATTR_SRQC_BUF_PGSZ CMQ_REQ_FIELD_LOC(39, 36)
1054#define CFG_BT_ATTR_SRQC_HOPNUM CMQ_REQ_FIELD_LOC(41, 40)
1055#define CFG_BT_ATTR_CQC_BA_PGSZ CMQ_REQ_FIELD_LOC(67, 64)
1056#define CFG_BT_ATTR_CQC_BUF_PGSZ CMQ_REQ_FIELD_LOC(71, 68)
1057#define CFG_BT_ATTR_CQC_HOPNUM CMQ_REQ_FIELD_LOC(73, 72)
1058#define CFG_BT_ATTR_MPT_BA_PGSZ CMQ_REQ_FIELD_LOC(99, 96)
1059#define CFG_BT_ATTR_MPT_BUF_PGSZ CMQ_REQ_FIELD_LOC(103, 100)
1060#define CFG_BT_ATTR_MPT_HOPNUM CMQ_REQ_FIELD_LOC(105, 104)
1061#define CFG_BT_ATTR_SCCC_BA_PGSZ CMQ_REQ_FIELD_LOC(131, 128)
1062#define CFG_BT_ATTR_SCCC_BUF_PGSZ CMQ_REQ_FIELD_LOC(135, 132)
1063#define CFG_BT_ATTR_SCCC_HOPNUM CMQ_REQ_FIELD_LOC(137, 136)
1064
1065/* Fields of HNS_ROCE_OPC_CFG_ENTRY_SIZE */
1066#define CFG_HEM_ENTRY_SIZE_TYPE CMQ_REQ_FIELD_LOC(31, 0)
1067enum {
1068 HNS_ROCE_CFG_QPC_SIZE = BIT(0),
1069 HNS_ROCE_CFG_SCCC_SIZE = BIT(1),
1070};
1071
1072#define CFG_HEM_ENTRY_SIZE_VALUE CMQ_REQ_FIELD_LOC(191, 160)
1073
1074/* Fields of HNS_ROCE_OPC_CFG_GMV_BT */
1075#define CFG_GMV_BT_BA_L CMQ_REQ_FIELD_LOC(31, 0)
1076#define CFG_GMV_BT_BA_H CMQ_REQ_FIELD_LOC(51, 32)
1077#define CFG_GMV_BT_IDX CMQ_REQ_FIELD_LOC(95, 64)
1078
1079/* Fields of HNS_ROCE_QUERY_RAM_ECC */
1080#define QUERY_RAM_ECC_1BIT_ERR CMQ_REQ_FIELD_LOC(31, 0)
1081#define QUERY_RAM_ECC_RES_TYPE CMQ_REQ_FIELD_LOC(63, 32)
1082#define QUERY_RAM_ECC_TAG CMQ_REQ_FIELD_LOC(95, 64)
1083
1084struct hns_roce_cfg_sgid_tb {
1085 __le32 table_idx_rsv;
1086 __le32 vf_sgid_l;
1087 __le32 vf_sgid_ml;
1088 __le32 vf_sgid_mh;
1089 __le32 vf_sgid_h;
1090 __le32 vf_sgid_type_rsv;
1091};
1092
1093#define SGID_TB_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_sgid_tb, h, l)
1094
1095#define CFG_SGID_TB_TABLE_IDX SGID_TB_FIELD_LOC(7, 0)
1096#define CFG_SGID_TB_VF_SGID_TYPE SGID_TB_FIELD_LOC(161, 160)
1097
1098struct hns_roce_cfg_smac_tb {
1099 __le32 tb_idx_rsv;
1100 __le32 vf_smac_l;
1101 __le32 vf_smac_h_rsv;
1102 __le32 rsv[3];
1103};
1104
1105#define SMAC_TB_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_smac_tb, h, l)
1106
1107#define CFG_SMAC_TB_IDX SMAC_TB_FIELD_LOC(7, 0)
1108#define CFG_SMAC_TB_VF_SMAC_H SMAC_TB_FIELD_LOC(79, 64)
1109
1110struct hns_roce_cfg_gmv_tb_a {
1111 __le32 vf_sgid_l;
1112 __le32 vf_sgid_ml;
1113 __le32 vf_sgid_mh;
1114 __le32 vf_sgid_h;
1115 __le32 vf_sgid_type_vlan;
1116 __le32 resv;
1117};
1118
1119#define GMV_TB_A_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_gmv_tb_a, h, l)
1120
1121#define GMV_TB_A_VF_SGID_TYPE GMV_TB_A_FIELD_LOC(129, 128)
1122#define GMV_TB_A_VF_VLAN_EN GMV_TB_A_FIELD_LOC(130, 130)
1123#define GMV_TB_A_VF_VLAN_ID GMV_TB_A_FIELD_LOC(155, 144)
1124
1125struct hns_roce_cfg_gmv_tb_b {
1126 __le32 vf_smac_l;
1127 __le32 vf_smac_h;
1128 __le32 table_idx_rsv;
1129 __le32 resv[3];
1130};
1131
1132#define GMV_TB_B_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_gmv_tb_b, h, l)
1133
1134#define GMV_TB_B_SMAC_H GMV_TB_B_FIELD_LOC(47, 32)
1135#define GMV_TB_B_SGID_IDX GMV_TB_B_FIELD_LOC(71, 64)
1136
1137#define HNS_ROCE_QUERY_PF_CAPS_CMD_NUM 5
1138struct hns_roce_query_pf_caps_a {
1139 u8 number_ports;
1140 u8 local_ca_ack_delay;
1141 __le16 max_sq_sg;
1142 __le16 max_sq_inline;
1143 __le16 max_rq_sg;
1144 __le32 rsv0;
1145 __le16 num_qpc_timer;
1146 __le16 num_cqc_timer;
1147 __le16 max_srq_sges;
1148 u8 num_aeq_vectors;
1149 u8 num_other_vectors;
1150 u8 max_sq_desc_sz;
1151 u8 max_rq_desc_sz;
1152 u8 rsv1;
1153 u8 cqe_sz;
1154};
1155
1156struct hns_roce_query_pf_caps_b {
1157 u8 mtpt_entry_sz;
1158 u8 irrl_entry_sz;
1159 u8 trrl_entry_sz;
1160 u8 cqc_entry_sz;
1161 u8 srqc_entry_sz;
1162 u8 idx_entry_sz;
1163 u8 sccc_sz;
1164 u8 max_mtu;
1165 __le16 qpc_sz;
1166 __le16 qpc_timer_entry_sz;
1167 __le16 cqc_timer_entry_sz;
1168 u8 min_cqes;
1169 u8 min_wqes;
1170 __le32 page_size_cap;
1171 u8 pkey_table_len;
1172 u8 phy_num_uars;
1173 u8 ctx_hop_num;
1174 u8 pbl_hop_num;
1175};
1176
1177struct hns_roce_query_pf_caps_c {
1178 __le32 cap_flags_num_pds;
1179 __le32 max_gid_num_cqs;
1180 __le32 cq_depth;
1181 __le32 num_mrws;
1182 __le32 ord_num_qps;
1183 __le16 sq_depth;
1184 __le16 rq_depth;
1185};
1186
1187#define PF_CAPS_C_FIELD_LOC(h, l) \
1188 FIELD_LOC(struct hns_roce_query_pf_caps_c, h, l)
1189
1190#define PF_CAPS_C_NUM_PDS PF_CAPS_C_FIELD_LOC(19, 0)
1191#define PF_CAPS_C_CAP_FLAGS PF_CAPS_C_FIELD_LOC(31, 20)
1192#define PF_CAPS_C_NUM_CQS PF_CAPS_C_FIELD_LOC(51, 32)
1193#define PF_CAPS_C_MAX_GID PF_CAPS_C_FIELD_LOC(60, 52)
1194#define PF_CAPS_C_CQ_DEPTH PF_CAPS_C_FIELD_LOC(86, 64)
1195#define PF_CAPS_C_NUM_XRCDS PF_CAPS_C_FIELD_LOC(91, 87)
1196#define PF_CAPS_C_NUM_MRWS PF_CAPS_C_FIELD_LOC(115, 96)
1197#define PF_CAPS_C_NUM_QPS PF_CAPS_C_FIELD_LOC(147, 128)
1198#define PF_CAPS_C_MAX_ORD PF_CAPS_C_FIELD_LOC(155, 148)
1199
1200struct hns_roce_query_pf_caps_d {
1201 __le32 wq_hop_num_max_srqs;
1202 __le16 srq_depth;
1203 __le16 cap_flags_ex;
1204 __le32 num_ceqs_ceq_depth;
1205 __le32 arm_st_aeq_depth;
1206 __le32 num_uars_rsv_pds;
1207 __le32 rsv_uars_rsv_qps;
1208};
1209
1210#define PF_CAPS_D_FIELD_LOC(h, l) \
1211 FIELD_LOC(struct hns_roce_query_pf_caps_d, h, l)
1212
1213#define PF_CAPS_D_NUM_SRQS PF_CAPS_D_FIELD_LOC(19, 0)
1214#define PF_CAPS_D_RQWQE_HOP_NUM PF_CAPS_D_FIELD_LOC(21, 20)
1215#define PF_CAPS_D_EX_SGE_HOP_NUM PF_CAPS_D_FIELD_LOC(23, 22)
1216#define PF_CAPS_D_SQWQE_HOP_NUM PF_CAPS_D_FIELD_LOC(25, 24)
1217#define PF_CAPS_D_CONG_TYPE PF_CAPS_D_FIELD_LOC(29, 26)
1218#define PF_CAPS_D_CEQ_DEPTH PF_CAPS_D_FIELD_LOC(85, 64)
1219#define PF_CAPS_D_NUM_CEQS PF_CAPS_D_FIELD_LOC(95, 86)
1220#define PF_CAPS_D_AEQ_DEPTH PF_CAPS_D_FIELD_LOC(117, 96)
1221#define PF_CAPS_D_AEQ_ARM_ST PF_CAPS_D_FIELD_LOC(119, 118)
1222#define PF_CAPS_D_CEQ_ARM_ST PF_CAPS_D_FIELD_LOC(121, 120)
1223#define PF_CAPS_D_RSV_PDS PF_CAPS_D_FIELD_LOC(147, 128)
1224#define PF_CAPS_D_NUM_UARS PF_CAPS_D_FIELD_LOC(155, 148)
1225#define PF_CAPS_D_RSV_QPS PF_CAPS_D_FIELD_LOC(179, 160)
1226#define PF_CAPS_D_RSV_UARS PF_CAPS_D_FIELD_LOC(187, 180)
1227
1228#define HNS_ROCE_CAP_FLAGS_EX_SHIFT 12
1229
1230struct hns_roce_congestion_algorithm {
1231 u8 alg_sel;
1232 u8 alg_sub_sel;
1233 u8 dip_vld;
1234 u8 wnd_mode_sel;
1235};
1236
1237struct hns_roce_query_pf_caps_e {
1238 __le32 chunk_size_shift_rsv_mrws;
1239 __le32 rsv_cqs;
1240 __le32 rsv_srqs;
1241 __le32 rsv_lkey;
1242 __le16 ceq_max_cnt;
1243 __le16 ceq_period;
1244 __le16 aeq_max_cnt;
1245 __le16 aeq_period;
1246};
1247
1248#define PF_CAPS_E_FIELD_LOC(h, l) \
1249 FIELD_LOC(struct hns_roce_query_pf_caps_e, h, l)
1250
1251#define PF_CAPS_E_RSV_MRWS PF_CAPS_E_FIELD_LOC(19, 0)
1252#define PF_CAPS_E_CHUNK_SIZE_SHIFT PF_CAPS_E_FIELD_LOC(31, 20)
1253#define PF_CAPS_E_RSV_CQS PF_CAPS_E_FIELD_LOC(51, 32)
1254#define PF_CAPS_E_RSV_XRCDS PF_CAPS_E_FIELD_LOC(63, 52)
1255#define PF_CAPS_E_RSV_SRQS PF_CAPS_E_FIELD_LOC(83, 64)
1256#define PF_CAPS_E_RSV_LKEYS PF_CAPS_E_FIELD_LOC(115, 96)
1257
1258struct hns_roce_cmq_req {
1259 __le32 data[6];
1260};
1261
1262#define CMQ_REQ_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cmq_req, h, l)
1263
1264struct hns_roce_cmq_desc {
1265 __le16 opcode;
1266 __le16 flag;
1267 __le16 retval;
1268 __le16 rsv;
1269 union {
1270 __le32 data[6];
1271 struct {
1272 __le32 own_func_num;
1273 __le32 own_mac_id;
1274 __le32 rsv[4];
1275 } func_info;
1276 };
1277};
1278
1279struct hns_roce_v2_cmq_ring {
1280 dma_addr_t desc_dma_addr;
1281 struct hns_roce_cmq_desc *desc;
1282 u32 head;
1283 u16 buf_size;
1284 u16 desc_num;
1285 u8 flag;
1286 spinlock_t lock; /* command queue lock */
1287};
1288
1289struct hns_roce_v2_cmq {
1290 struct hns_roce_v2_cmq_ring csq;
1291 u16 tx_timeout;
1292};
1293
1294struct hns_roce_link_table {
1295 struct hns_roce_buf_list table;
1296 struct hns_roce_buf *buf;
1297};
1298
1299#define HNS_ROCE_EXT_LLM_ENTRY(addr, id) (((id) << (64 - 12)) | ((addr) >> 12))
1300#define HNS_ROCE_EXT_LLM_MIN_PAGES(que_num) ((que_num) * 4 + 2)
1301
1302struct hns_roce_v2_free_mr {
1303 struct hns_roce_qp *rsv_qp[HNS_ROCE_FREE_MR_USED_QP_NUM];
1304 struct hns_roce_cq *rsv_cq;
1305 struct hns_roce_pd *rsv_pd;
1306 struct mutex mutex;
1307};
1308
1309struct hns_roce_v2_priv {
1310 struct hnae3_handle *handle;
1311 struct hns_roce_v2_cmq cmq;
1312 struct hns_roce_link_table ext_llm;
1313 struct hns_roce_v2_free_mr free_mr;
1314};
1315
1316struct hns_roce_dip {
1317 u8 dgid[GID_LEN_V2];
1318 u32 dip_idx;
1319 struct list_head node; /* all dips are on a list */
1320};
1321
1322struct fmea_ram_ecc {
1323 u32 is_ecc_err;
1324 u32 res_type;
1325 u32 index;
1326};
1327
1328/* only for RNR timeout issue of HIP08 */
1329#define HNS_ROCE_CLOCK_ADJUST 1000
1330#define HNS_ROCE_MAX_CQ_PERIOD 65
1331#define HNS_ROCE_MAX_EQ_PERIOD 65
1332#define HNS_ROCE_RNR_TIMER_10NS 1
1333#define HNS_ROCE_1US_CFG 999
1334#define HNS_ROCE_1NS_CFG 0
1335
1336#define HNS_ROCE_AEQ_DEFAULT_BURST_NUM 0x0
1337#define HNS_ROCE_AEQ_DEFAULT_INTERVAL 0x0
1338#define HNS_ROCE_CEQ_DEFAULT_BURST_NUM 0x0
1339#define HNS_ROCE_CEQ_DEFAULT_INTERVAL 0x0
1340
1341#define HNS_ROCE_V2_EQ_STATE_INVALID 0
1342#define HNS_ROCE_V2_EQ_STATE_VALID 1
1343#define HNS_ROCE_V2_EQ_STATE_OVERFLOW 2
1344#define HNS_ROCE_V2_EQ_STATE_FAILURE 3
1345
1346#define HNS_ROCE_V2_EQ_OVER_IGNORE_0 0
1347#define HNS_ROCE_V2_EQ_OVER_IGNORE_1 1
1348
1349#define HNS_ROCE_V2_EQ_COALESCE_0 0
1350#define HNS_ROCE_V2_EQ_COALESCE_1 1
1351
1352#define HNS_ROCE_V2_EQ_FIRED 0
1353#define HNS_ROCE_V2_EQ_ARMED 1
1354#define HNS_ROCE_V2_EQ_ALWAYS_ARMED 3
1355
1356#define HNS_ROCE_EQ_INIT_EQE_CNT 0
1357#define HNS_ROCE_EQ_INIT_PROD_IDX 0
1358#define HNS_ROCE_EQ_INIT_REPORT_TIMER 0
1359#define HNS_ROCE_EQ_INIT_MSI_IDX 0
1360#define HNS_ROCE_EQ_INIT_CONS_IDX 0
1361#define HNS_ROCE_EQ_INIT_NXT_EQE_BA 0
1362
1363#define HNS_ROCE_V2_COMP_EQE_NUM 0x1000
1364#define HNS_ROCE_V2_ASYNC_EQE_NUM 0x1000
1365
1366#define HNS_ROCE_V2_VF_INT_ST_AEQ_OVERFLOW_S 0
1367
1368#define HNS_ROCE_EQ_DB_CMD_AEQ 0x0
1369#define HNS_ROCE_EQ_DB_CMD_AEQ_ARMED 0x1
1370#define HNS_ROCE_EQ_DB_CMD_CEQ 0x2
1371#define HNS_ROCE_EQ_DB_CMD_CEQ_ARMED 0x3
1372
1373#define EQ_ENABLE 1
1374#define EQ_DISABLE 0
1375
1376#define EQ_REG_OFFSET 0x4
1377
1378#define HNS_ROCE_INT_NAME_LEN 32
1379#define HNS_ROCE_V2_EQN_M GENMASK(23, 0)
1380
1381#define HNS_ROCE_V2_VF_ABN_INT_EN_S 0
1382#define HNS_ROCE_V2_VF_ABN_INT_EN_M GENMASK(0, 0)
1383#define HNS_ROCE_V2_VF_ABN_INT_ST_M GENMASK(2, 0)
1384#define HNS_ROCE_V2_VF_ABN_INT_CFG_M GENMASK(2, 0)
1385#define HNS_ROCE_V2_VF_EVENT_INT_EN_M GENMASK(0, 0)
1386
1387struct hns_roce_eq_context {
1388 __le32 data[16];
1389};
1390
1391#define EQC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_eq_context, h, l)
1392
1393#define EQC_EQ_ST EQC_FIELD_LOC(1, 0)
1394#define EQC_EQE_HOP_NUM EQC_FIELD_LOC(3, 2)
1395#define EQC_OVER_IGNORE EQC_FIELD_LOC(4, 4)
1396#define EQC_COALESCE EQC_FIELD_LOC(5, 5)
1397#define EQC_ARM_ST EQC_FIELD_LOC(7, 6)
1398#define EQC_EQN EQC_FIELD_LOC(15, 8)
1399#define EQC_EQE_CNT EQC_FIELD_LOC(31, 16)
1400#define EQC_EQE_BA_PG_SZ EQC_FIELD_LOC(35, 32)
1401#define EQC_EQE_BUF_PG_SZ EQC_FIELD_LOC(39, 36)
1402#define EQC_EQ_PROD_INDX EQC_FIELD_LOC(63, 40)
1403#define EQC_EQ_MAX_CNT EQC_FIELD_LOC(79, 64)
1404#define EQC_EQ_PERIOD EQC_FIELD_LOC(95, 80)
1405#define EQC_EQE_REPORT_TIMER EQC_FIELD_LOC(127, 96)
1406#define EQC_EQE_BA_L EQC_FIELD_LOC(159, 128)
1407#define EQC_EQE_BA_H EQC_FIELD_LOC(188, 160)
1408#define EQC_SHIFT EQC_FIELD_LOC(199, 192)
1409#define EQC_MSI_INDX EQC_FIELD_LOC(207, 200)
1410#define EQC_CUR_EQE_BA_L EQC_FIELD_LOC(223, 208)
1411#define EQC_CUR_EQE_BA_M EQC_FIELD_LOC(255, 224)
1412#define EQC_CUR_EQE_BA_H EQC_FIELD_LOC(259, 256)
1413#define EQC_EQ_CONS_INDX EQC_FIELD_LOC(287, 264)
1414#define EQC_NEX_EQE_BA_L EQC_FIELD_LOC(319, 288)
1415#define EQC_NEX_EQE_BA_H EQC_FIELD_LOC(339, 320)
1416#define EQC_EQE_SIZE EQC_FIELD_LOC(341, 340)
1417
1418#define MAX_SERVICE_LEVEL 0x7
1419
1420struct hns_roce_wqe_atomic_seg {
1421 __le64 fetchadd_swap_data;
1422 __le64 cmp_data;
1423};
1424
1425struct hns_roce_sccc_clr {
1426 __le32 qpn;
1427 __le32 rsv[5];
1428};
1429
1430struct hns_roce_sccc_clr_done {
1431 __le32 clr_done;
1432 __le32 rsv[5];
1433};
1434
1435int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
1436
1437static inline void hns_roce_write64(struct hns_roce_dev *hr_dev, __le32 val[2],
1438 void __iomem *dest)
1439{
1440 struct hns_roce_v2_priv *priv = hr_dev->priv;
1441 struct hnae3_handle *handle = priv->handle;
1442 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1443
1444 if (!hr_dev->dis_db && !ops->get_hw_reset_stat(handle))
1445 hns_roce_write64_k(val, dest);
1446}
1447
1448#endif
1/*
2 * Copyright (c) 2016-2017 Hisilicon Limited.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _HNS_ROCE_HW_V2_H
34#define _HNS_ROCE_HW_V2_H
35
36#include <linux/bitops.h>
37
38#define HNS_ROCE_V2_MAX_QP_NUM 0x1000
39#define HNS_ROCE_V2_MAX_WQE_NUM 0x8000
40#define HNS_ROCE_V2_MAX_SRQ_WR 0x8000
41#define HNS_ROCE_V2_MAX_SRQ_SGE 64
42#define HNS_ROCE_V2_MAX_CQ_NUM 0x100000
43#define HNS_ROCE_V2_MAX_QPC_TIMER_BT_NUM 0x100
44#define HNS_ROCE_V2_MAX_CQC_TIMER_BT_NUM 0x100
45#define HNS_ROCE_V2_MAX_SRQ_NUM 0x100000
46#define HNS_ROCE_V2_MAX_CQE_NUM 0x400000
47#define HNS_ROCE_V2_MAX_RQ_SGE_NUM 64
48#define HNS_ROCE_V2_MAX_SQ_SGE_NUM 64
49#define HNS_ROCE_V2_MAX_SQ_INLINE 0x20
50#define HNS_ROCE_V3_MAX_SQ_INLINE 0x400
51#define HNS_ROCE_V2_MAX_RC_INL_INN_SZ 32
52#define HNS_ROCE_V2_UAR_NUM 256
53#define HNS_ROCE_V2_PHY_UAR_NUM 1
54#define HNS_ROCE_V2_AEQE_VEC_NUM 1
55#define HNS_ROCE_V2_ABNORMAL_VEC_NUM 1
56#define HNS_ROCE_V2_MAX_MTPT_NUM 0x100000
57#define HNS_ROCE_V2_MAX_SRQWQE_SEGS 0x1000000
58#define HNS_ROCE_V2_MAX_IDX_SEGS 0x1000000
59#define HNS_ROCE_V2_MAX_PD_NUM 0x1000000
60#define HNS_ROCE_V2_MAX_XRCD_NUM 0x1000000
61#define HNS_ROCE_V2_RSV_XRCD_NUM 0
62#define HNS_ROCE_V2_MAX_QP_INIT_RDMA 128
63#define HNS_ROCE_V2_MAX_QP_DEST_RDMA 128
64#define HNS_ROCE_V2_MAX_SQ_DESC_SZ 64
65#define HNS_ROCE_V2_MAX_RQ_DESC_SZ 16
66#define HNS_ROCE_V2_IRRL_ENTRY_SZ 64
67#define HNS_ROCE_V2_EXT_ATOMIC_TRRL_ENTRY_SZ 100
68#define HNS_ROCE_V2_CQC_ENTRY_SZ 64
69#define HNS_ROCE_V2_SRQC_ENTRY_SZ 64
70#define HNS_ROCE_V2_MTPT_ENTRY_SZ 64
71#define HNS_ROCE_V2_MTT_ENTRY_SZ 64
72#define HNS_ROCE_V2_IDX_ENTRY_SZ 4
73
74#define HNS_ROCE_V2_SCCC_SZ 32
75#define HNS_ROCE_V3_SCCC_SZ 64
76#define HNS_ROCE_V3_GMV_ENTRY_SZ 32
77
78#define HNS_ROCE_V2_EXT_LLM_ENTRY_SZ 8
79#define HNS_ROCE_V2_EXT_LLM_MAX_DEPTH 4096
80
81#define HNS_ROCE_V2_QPC_TIMER_ENTRY_SZ PAGE_SIZE
82#define HNS_ROCE_V2_CQC_TIMER_ENTRY_SZ PAGE_SIZE
83#define HNS_ROCE_V2_PAGE_SIZE_SUPPORTED 0xFFFF000
84#define HNS_ROCE_V2_MAX_INNER_MTPT_NUM 2
85#define HNS_ROCE_INVALID_LKEY 0x0
86#define HNS_ROCE_INVALID_SGE_LENGTH 0x80000000
87#define HNS_ROCE_CMQ_TX_TIMEOUT 30000
88#define HNS_ROCE_V2_RSV_QPS 8
89
90#define HNS_ROCE_V2_HW_RST_TIMEOUT 1000
91#define HNS_ROCE_V2_HW_RST_UNINT_DELAY 100
92
93#define HNS_ROCE_V2_HW_RST_COMPLETION_WAIT 20
94
95#define HNS_ROCE_CONTEXT_HOP_NUM 1
96#define HNS_ROCE_SCCC_HOP_NUM 1
97#define HNS_ROCE_MTT_HOP_NUM 1
98#define HNS_ROCE_CQE_HOP_NUM 1
99#define HNS_ROCE_SRQWQE_HOP_NUM 1
100#define HNS_ROCE_PBL_HOP_NUM 2
101#define HNS_ROCE_IDX_HOP_NUM 1
102#define HNS_ROCE_SQWQE_HOP_NUM 2
103#define HNS_ROCE_EXT_SGE_HOP_NUM 1
104#define HNS_ROCE_RQWQE_HOP_NUM 2
105
106#define HNS_ROCE_V2_EQE_HOP_NUM 2
107#define HNS_ROCE_V3_EQE_HOP_NUM 1
108
109#define HNS_ROCE_BA_PG_SZ_SUPPORTED_256K 6
110#define HNS_ROCE_BA_PG_SZ_SUPPORTED_16K 2
111#define HNS_ROCE_V2_GID_INDEX_NUM 16
112
113#define HNS_ROCE_V2_TABLE_CHUNK_SIZE (1 << 18)
114
115enum {
116 HNS_ROCE_CMD_FLAG_IN = BIT(0),
117 HNS_ROCE_CMD_FLAG_OUT = BIT(1),
118 HNS_ROCE_CMD_FLAG_NEXT = BIT(2),
119 HNS_ROCE_CMD_FLAG_WR = BIT(3),
120 HNS_ROCE_CMD_FLAG_ERR_INTR = BIT(5),
121};
122
123#define HNS_ROCE_CMQ_DESC_NUM_S 3
124
125#define HNS_ROCE_CMQ_SCC_CLR_DONE_CNT 5
126
127#define HNS_ROCE_CONG_SIZE 64
128
129#define check_whether_last_step(hop_num, step_idx) \
130 ((step_idx == 0 && hop_num == HNS_ROCE_HOP_NUM_0) || \
131 (step_idx == 1 && hop_num == 1) || \
132 (step_idx == 2 && hop_num == 2))
133#define HNS_ICL_SWITCH_CMD_ROCEE_SEL_SHIFT 0
134#define HNS_ICL_SWITCH_CMD_ROCEE_SEL BIT(HNS_ICL_SWITCH_CMD_ROCEE_SEL_SHIFT)
135
136#define CMD_CSQ_DESC_NUM 1024
137#define CMD_CRQ_DESC_NUM 1024
138
139/* Free mr used parameters */
140#define HNS_ROCE_FREE_MR_USED_CQE_NUM 128
141#define HNS_ROCE_FREE_MR_USED_QP_NUM 0x8
142#define HNS_ROCE_FREE_MR_USED_PSN 0x0808
143#define HNS_ROCE_FREE_MR_USED_QP_RETRY_CNT 0x7
144#define HNS_ROCE_FREE_MR_USED_QP_TIMEOUT 0x12
145#define HNS_ROCE_FREE_MR_USED_SQWQE_NUM 128
146#define HNS_ROCE_FREE_MR_USED_SQSGE_NUM 0x2
147#define HNS_ROCE_FREE_MR_USED_RQWQE_NUM 128
148#define HNS_ROCE_FREE_MR_USED_RQSGE_NUM 0x2
149#define HNS_ROCE_V2_FREE_MR_TIMEOUT 4500
150
151enum {
152 NO_ARMED = 0x0,
153 REG_NXT_CEQE = 0x2,
154 REG_NXT_SE_CEQE = 0x3
155};
156
157enum {
158 CQE_SIZE_32B = 0x0,
159 CQE_SIZE_64B = 0x1
160};
161
162#define V2_CQ_DB_REQ_NOT_SOL 0
163#define V2_CQ_DB_REQ_NOT 1
164
165#define V2_CQ_STATE_VALID 1
166#define V2_QKEY_VAL 0x80010000
167
168#define GID_LEN_V2 16
169
170enum {
171 HNS_ROCE_V2_WQE_OP_SEND = 0x0,
172 HNS_ROCE_V2_WQE_OP_SEND_WITH_INV = 0x1,
173 HNS_ROCE_V2_WQE_OP_SEND_WITH_IMM = 0x2,
174 HNS_ROCE_V2_WQE_OP_RDMA_WRITE = 0x3,
175 HNS_ROCE_V2_WQE_OP_RDMA_WRITE_WITH_IMM = 0x4,
176 HNS_ROCE_V2_WQE_OP_RDMA_READ = 0x5,
177 HNS_ROCE_V2_WQE_OP_ATOM_CMP_AND_SWAP = 0x6,
178 HNS_ROCE_V2_WQE_OP_ATOM_FETCH_AND_ADD = 0x7,
179 HNS_ROCE_V2_WQE_OP_ATOM_MSK_CMP_AND_SWAP = 0x8,
180 HNS_ROCE_V2_WQE_OP_ATOM_MSK_FETCH_AND_ADD = 0x9,
181 HNS_ROCE_V2_WQE_OP_FAST_REG_PMR = 0xa,
182 HNS_ROCE_V2_WQE_OP_BIND_MW = 0xc,
183 HNS_ROCE_V2_WQE_OP_MASK = 0x1f,
184};
185
186enum {
187 /* rq operations */
188 HNS_ROCE_V2_OPCODE_RDMA_WRITE_IMM = 0x0,
189 HNS_ROCE_V2_OPCODE_SEND = 0x1,
190 HNS_ROCE_V2_OPCODE_SEND_WITH_IMM = 0x2,
191 HNS_ROCE_V2_OPCODE_SEND_WITH_INV = 0x3,
192};
193
194enum {
195 HNS_ROCE_V2_SQ_DB,
196 HNS_ROCE_V2_RQ_DB,
197 HNS_ROCE_V2_SRQ_DB,
198 HNS_ROCE_V2_CQ_DB,
199 HNS_ROCE_V2_CQ_DB_NOTIFY
200};
201
202enum {
203 HNS_ROCE_CQE_V2_SUCCESS = 0x00,
204 HNS_ROCE_CQE_V2_LOCAL_LENGTH_ERR = 0x01,
205 HNS_ROCE_CQE_V2_LOCAL_QP_OP_ERR = 0x02,
206 HNS_ROCE_CQE_V2_LOCAL_PROT_ERR = 0x04,
207 HNS_ROCE_CQE_V2_WR_FLUSH_ERR = 0x05,
208 HNS_ROCE_CQE_V2_MW_BIND_ERR = 0x06,
209 HNS_ROCE_CQE_V2_BAD_RESP_ERR = 0x10,
210 HNS_ROCE_CQE_V2_LOCAL_ACCESS_ERR = 0x11,
211 HNS_ROCE_CQE_V2_REMOTE_INVAL_REQ_ERR = 0x12,
212 HNS_ROCE_CQE_V2_REMOTE_ACCESS_ERR = 0x13,
213 HNS_ROCE_CQE_V2_REMOTE_OP_ERR = 0x14,
214 HNS_ROCE_CQE_V2_TRANSPORT_RETRY_EXC_ERR = 0x15,
215 HNS_ROCE_CQE_V2_RNR_RETRY_EXC_ERR = 0x16,
216 HNS_ROCE_CQE_V2_REMOTE_ABORT_ERR = 0x22,
217 HNS_ROCE_CQE_V2_GENERAL_ERR = 0x23,
218
219 HNS_ROCE_V2_CQE_STATUS_MASK = 0xff,
220};
221
222/* CMQ command */
223enum hns_roce_opcode_type {
224 HNS_QUERY_FW_VER = 0x0001,
225 HNS_ROCE_OPC_QUERY_HW_VER = 0x8000,
226 HNS_ROCE_OPC_CFG_GLOBAL_PARAM = 0x8001,
227 HNS_ROCE_OPC_ALLOC_PF_RES = 0x8004,
228 HNS_ROCE_OPC_QUERY_PF_RES = 0x8400,
229 HNS_ROCE_OPC_ALLOC_VF_RES = 0x8401,
230 HNS_ROCE_OPC_CFG_EXT_LLM = 0x8403,
231 HNS_ROCE_OPC_QUERY_PF_TIMER_RES = 0x8406,
232 HNS_ROCE_OPC_QUERY_FUNC_INFO = 0x8407,
233 HNS_ROCE_OPC_QUERY_PF_CAPS_NUM = 0x8408,
234 HNS_ROCE_OPC_CFG_ENTRY_SIZE = 0x8409,
235 HNS_ROCE_OPC_CFG_SGID_TB = 0x8500,
236 HNS_ROCE_OPC_CFG_SMAC_TB = 0x8501,
237 HNS_ROCE_OPC_POST_MB = 0x8504,
238 HNS_ROCE_OPC_QUERY_MB_ST = 0x8505,
239 HNS_ROCE_OPC_CFG_BT_ATTR = 0x8506,
240 HNS_ROCE_OPC_FUNC_CLEAR = 0x8508,
241 HNS_ROCE_OPC_CLR_SCCC = 0x8509,
242 HNS_ROCE_OPC_QUERY_SCCC = 0x850a,
243 HNS_ROCE_OPC_RESET_SCCC = 0x850b,
244 HNS_ROCE_OPC_CLEAR_EXTDB_LIST_INFO = 0x850d,
245 HNS_ROCE_OPC_QUERY_VF_RES = 0x850e,
246 HNS_ROCE_OPC_CFG_GMV_TBL = 0x850f,
247 HNS_ROCE_OPC_CFG_GMV_BT = 0x8510,
248 HNS_ROCE_OPC_EXT_CFG = 0x8512,
249 HNS_ROCE_QUERY_RAM_ECC = 0x8513,
250 HNS_SWITCH_PARAMETER_CFG = 0x1033,
251};
252
253enum {
254 TYPE_CRQ,
255 TYPE_CSQ,
256};
257
258enum hns_roce_cmd_return_status {
259 CMD_EXEC_SUCCESS,
260 CMD_NO_AUTH,
261 CMD_NOT_EXIST,
262 CMD_CRQ_FULL,
263 CMD_NEXT_ERR,
264 CMD_NOT_EXEC,
265 CMD_PARA_ERR,
266 CMD_RESULT_ERR,
267 CMD_TIMEOUT,
268 CMD_HILINK_ERR,
269 CMD_INFO_ILLEGAL,
270 CMD_INVALID,
271 CMD_ROH_CHECK_FAIL,
272 CMD_OTHER_ERR = 0xff
273};
274
275struct hns_roce_cmd_errcode {
276 enum hns_roce_cmd_return_status return_status;
277 int errno;
278};
279
280enum hns_roce_sgid_type {
281 GID_TYPE_FLAG_ROCE_V1 = 0,
282 GID_TYPE_FLAG_ROCE_V2_IPV4,
283 GID_TYPE_FLAG_ROCE_V2_IPV6,
284};
285
286struct hns_roce_v2_cq_context {
287 __le32 byte_4_pg_ceqn;
288 __le32 byte_8_cqn;
289 __le32 cqe_cur_blk_addr;
290 __le32 byte_16_hop_addr;
291 __le32 cqe_nxt_blk_addr;
292 __le32 byte_24_pgsz_addr;
293 __le32 byte_28_cq_pi;
294 __le32 byte_32_cq_ci;
295 __le32 cqe_ba;
296 __le32 byte_40_cqe_ba;
297 __le32 byte_44_db_record;
298 __le32 db_record_addr;
299 __le32 byte_52_cqe_cnt;
300 __le32 byte_56_cqe_period_maxcnt;
301 __le32 cqe_report_timer;
302 __le32 byte_64_se_cqe_idx;
303};
304
305#define HNS_ROCE_V2_CQ_DEFAULT_BURST_NUM 0x0
306#define HNS_ROCE_V2_CQ_DEFAULT_INTERVAL 0x0
307
308#define CQC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_cq_context, h, l)
309
310#define CQC_CQ_ST CQC_FIELD_LOC(1, 0)
311#define CQC_POLL CQC_FIELD_LOC(2, 2)
312#define CQC_SE CQC_FIELD_LOC(3, 3)
313#define CQC_OVER_IGNORE CQC_FIELD_LOC(4, 4)
314#define CQC_ARM_ST CQC_FIELD_LOC(7, 6)
315#define CQC_SHIFT CQC_FIELD_LOC(12, 8)
316#define CQC_CMD_SN CQC_FIELD_LOC(14, 13)
317#define CQC_CEQN CQC_FIELD_LOC(23, 15)
318#define CQC_CQN CQC_FIELD_LOC(55, 32)
319#define CQC_POE_EN CQC_FIELD_LOC(56, 56)
320#define CQC_POE_NUM CQC_FIELD_LOC(58, 57)
321#define CQC_CQE_SIZE CQC_FIELD_LOC(60, 59)
322#define CQC_CQ_CNT_MODE CQC_FIELD_LOC(61, 61)
323#define CQC_STASH CQC_FIELD_LOC(63, 63)
324#define CQC_CQE_CUR_BLK_ADDR_L CQC_FIELD_LOC(95, 64)
325#define CQC_CQE_CUR_BLK_ADDR_H CQC_FIELD_LOC(115, 96)
326#define CQC_POE_QID CQC_FIELD_LOC(125, 116)
327#define CQC_CQE_HOP_NUM CQC_FIELD_LOC(127, 126)
328#define CQC_CQE_NEX_BLK_ADDR_L CQC_FIELD_LOC(159, 128)
329#define CQC_CQE_NEX_BLK_ADDR_H CQC_FIELD_LOC(179, 160)
330#define CQC_CQE_BAR_PG_SZ CQC_FIELD_LOC(187, 184)
331#define CQC_CQE_BUF_PG_SZ CQC_FIELD_LOC(191, 188)
332#define CQC_CQ_PRODUCER_IDX CQC_FIELD_LOC(215, 192)
333#define CQC_CQ_CONSUMER_IDX CQC_FIELD_LOC(247, 224)
334#define CQC_CQE_BA_L CQC_FIELD_LOC(287, 256)
335#define CQC_CQE_BA_H CQC_FIELD_LOC(316, 288)
336#define CQC_POE_QID_H_0 CQC_FIELD_LOC(319, 317)
337#define CQC_DB_RECORD_EN CQC_FIELD_LOC(320, 320)
338#define CQC_CQE_DB_RECORD_ADDR_L CQC_FIELD_LOC(351, 321)
339#define CQC_CQE_DB_RECORD_ADDR_H CQC_FIELD_LOC(383, 352)
340#define CQC_CQE_CNT CQC_FIELD_LOC(407, 384)
341#define CQC_CQ_MAX_CNT CQC_FIELD_LOC(431, 416)
342#define CQC_CQ_PERIOD CQC_FIELD_LOC(447, 432)
343#define CQC_CQE_REPORT_TIMER CQC_FIELD_LOC(471, 448)
344#define CQC_WR_CQE_IDX CQC_FIELD_LOC(479, 472)
345#define CQC_SE_CQE_IDX CQC_FIELD_LOC(503, 480)
346#define CQC_POE_QID_H_1 CQC_FIELD_LOC(511, 511)
347
348struct hns_roce_srq_context {
349 __le32 data[16];
350};
351
352#define SRQC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_srq_context, h, l)
353
354#define SRQC_SRQ_ST SRQC_FIELD_LOC(1, 0)
355#define SRQC_WQE_HOP_NUM SRQC_FIELD_LOC(3, 2)
356#define SRQC_SHIFT SRQC_FIELD_LOC(7, 4)
357#define SRQC_SRQN SRQC_FIELD_LOC(31, 8)
358#define SRQC_LIMIT_WL SRQC_FIELD_LOC(47, 32)
359#define SRQC_RSV0 SRQC_FIELD_LOC(63, 48)
360#define SRQC_XRCD SRQC_FIELD_LOC(87, 64)
361#define SRQC_RSV1 SRQC_FIELD_LOC(95, 88)
362#define SRQC_PRODUCER_IDX SRQC_FIELD_LOC(111, 96)
363#define SRQC_CONSUMER_IDX SRQC_FIELD_LOC(127, 112)
364#define SRQC_WQE_BT_BA_L SRQC_FIELD_LOC(159, 128)
365#define SRQC_WQE_BT_BA_H SRQC_FIELD_LOC(188, 160)
366#define SRQC_RSV2 SRQC_FIELD_LOC(190, 189)
367#define SRQC_SRQ_TYPE SRQC_FIELD_LOC(191, 191)
368#define SRQC_PD SRQC_FIELD_LOC(215, 192)
369#define SRQC_RQWS SRQC_FIELD_LOC(219, 216)
370#define SRQC_RSV3 SRQC_FIELD_LOC(223, 220)
371#define SRQC_IDX_BT_BA_L SRQC_FIELD_LOC(255, 224)
372#define SRQC_IDX_BT_BA_H SRQC_FIELD_LOC(284, 256)
373#define SRQC_RSV4 SRQC_FIELD_LOC(287, 285)
374#define SRQC_IDX_CUR_BLK_ADDR_L SRQC_FIELD_LOC(319, 288)
375#define SRQC_IDX_CUR_BLK_ADDR_H SRQC_FIELD_LOC(339, 320)
376#define SRQC_RSV5 SRQC_FIELD_LOC(341, 340)
377#define SRQC_IDX_HOP_NUM SRQC_FIELD_LOC(343, 342)
378#define SRQC_IDX_BA_PG_SZ SRQC_FIELD_LOC(347, 344)
379#define SRQC_IDX_BUF_PG_SZ SRQC_FIELD_LOC(351, 348)
380#define SRQC_IDX_NXT_BLK_ADDR_L SRQC_FIELD_LOC(383, 352)
381#define SRQC_IDX_NXT_BLK_ADDR_H SRQC_FIELD_LOC(403, 384)
382#define SRQC_RSV6 SRQC_FIELD_LOC(415, 404)
383#define SRQC_XRC_CQN SRQC_FIELD_LOC(439, 416)
384#define SRQC_WQE_BA_PG_SZ SRQC_FIELD_LOC(443, 440)
385#define SRQC_WQE_BUF_PG_SZ SRQC_FIELD_LOC(447, 444)
386#define SRQC_DB_RECORD_EN SRQC_FIELD_LOC(448, 448)
387#define SRQC_DB_RECORD_ADDR_L SRQC_FIELD_LOC(479, 449)
388#define SRQC_DB_RECORD_ADDR_H SRQC_FIELD_LOC(511, 480)
389
390enum {
391 V2_MPT_ST_VALID = 0x1,
392 V2_MPT_ST_FREE = 0x2,
393};
394
395enum hns_roce_v2_qp_state {
396 HNS_ROCE_QP_ST_RST,
397 HNS_ROCE_QP_ST_INIT,
398 HNS_ROCE_QP_ST_RTR,
399 HNS_ROCE_QP_ST_RTS,
400 HNS_ROCE_QP_ST_SQD,
401 HNS_ROCE_QP_ST_SQER,
402 HNS_ROCE_QP_ST_ERR,
403 HNS_ROCE_QP_ST_SQ_DRAINING,
404 HNS_ROCE_QP_NUM_ST
405};
406
407struct hns_roce_v2_qp_context_ex {
408 __le32 data[64];
409};
410
411struct hns_roce_v2_qp_context {
412 __le32 byte_4_sqpn_tst;
413 __le32 wqe_sge_ba;
414 __le32 byte_12_sq_hop;
415 __le32 byte_16_buf_ba_pg_sz;
416 __le32 byte_20_smac_sgid_idx;
417 __le32 byte_24_mtu_tc;
418 __le32 byte_28_at_fl;
419 u8 dgid[GID_LEN_V2];
420 __le32 dmac;
421 __le32 byte_52_udpspn_dmac;
422 __le32 byte_56_dqpn_err;
423 __le32 byte_60_qpst_tempid;
424 __le32 qkey_xrcd;
425 __le32 byte_68_rq_db;
426 __le32 rq_db_record_addr;
427 __le32 byte_76_srqn_op_en;
428 __le32 byte_80_rnr_rx_cqn;
429 __le32 byte_84_rq_ci_pi;
430 __le32 rq_cur_blk_addr;
431 __le32 byte_92_srq_info;
432 __le32 byte_96_rx_reqmsn;
433 __le32 rq_nxt_blk_addr;
434 __le32 byte_104_rq_sge;
435 __le32 byte_108_rx_reqepsn;
436 __le32 rq_rnr_timer;
437 __le32 rx_msg_len;
438 __le32 rx_rkey_pkt_info;
439 __le64 rx_va;
440 __le32 byte_132_trrl;
441 __le32 trrl_ba;
442 __le32 byte_140_raq;
443 __le32 byte_144_raq;
444 __le32 byte_148_raq;
445 __le32 byte_152_raq;
446 __le32 byte_156_raq;
447 __le32 byte_160_sq_ci_pi;
448 __le32 sq_cur_blk_addr;
449 __le32 byte_168_irrl_idx;
450 __le32 byte_172_sq_psn;
451 __le32 byte_176_msg_pktn;
452 __le32 sq_cur_sge_blk_addr;
453 __le32 byte_184_irrl_idx;
454 __le32 cur_sge_offset;
455 __le32 byte_192_ext_sge;
456 __le32 byte_196_sq_psn;
457 __le32 byte_200_sq_max;
458 __le32 irrl_ba;
459 __le32 byte_208_irrl;
460 __le32 byte_212_lsn;
461 __le32 sq_timer;
462 __le32 byte_220_retry_psn_msn;
463 __le32 byte_224_retry_msg;
464 __le32 rx_sq_cur_blk_addr;
465 __le32 byte_232_irrl_sge;
466 __le32 irrl_cur_sge_offset;
467 __le32 byte_240_irrl_tail;
468 __le32 byte_244_rnr_rxack;
469 __le32 byte_248_ack_psn;
470 __le32 byte_252_err_txcqn;
471 __le32 byte_256_sqflush_rqcqe;
472
473 struct hns_roce_v2_qp_context_ex ext;
474};
475
476#define QPC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_qp_context, h, l)
477
478#define QPC_TST QPC_FIELD_LOC(2, 0)
479#define QPC_SGE_SHIFT QPC_FIELD_LOC(7, 3)
480#define QPC_CNP_TIMER QPC_FIELD_LOC(31, 8)
481#define QPC_WQE_SGE_BA_L QPC_FIELD_LOC(63, 32)
482#define QPC_WQE_SGE_BA_H QPC_FIELD_LOC(92, 64)
483#define QPC_SQ_HOP_NUM QPC_FIELD_LOC(94, 93)
484#define QPC_CIRE_EN QPC_FIELD_LOC(95, 95)
485#define QPC_WQE_SGE_BA_PG_SZ QPC_FIELD_LOC(99, 96)
486#define QPC_WQE_SGE_BUF_PG_SZ QPC_FIELD_LOC(103, 100)
487#define QPC_PD QPC_FIELD_LOC(127, 104)
488#define QPC_RQ_HOP_NUM QPC_FIELD_LOC(129, 128)
489#define QPC_SGE_HOP_NUM QPC_FIELD_LOC(131, 130)
490#define QPC_RQWS QPC_FIELD_LOC(135, 132)
491#define QPC_SQ_SHIFT QPC_FIELD_LOC(139, 136)
492#define QPC_RQ_SHIFT QPC_FIELD_LOC(143, 140)
493#define QPC_GMV_IDX QPC_FIELD_LOC(159, 144)
494#define QPC_HOPLIMIT QPC_FIELD_LOC(167, 160)
495#define QPC_TC QPC_FIELD_LOC(175, 168)
496#define QPC_VLAN_ID QPC_FIELD_LOC(187, 176)
497#define QPC_MTU QPC_FIELD_LOC(191, 188)
498#define QPC_FL QPC_FIELD_LOC(211, 192)
499#define QPC_SL QPC_FIELD_LOC(215, 212)
500#define QPC_CNP_TX_FLAG QPC_FIELD_LOC(216, 216)
501#define QPC_CE_FLAG QPC_FIELD_LOC(217, 217)
502#define QPC_LBI QPC_FIELD_LOC(218, 218)
503#define QPC_AT QPC_FIELD_LOC(223, 219)
504#define QPC_DGID QPC_FIELD_LOC(351, 224)
505#define QPC_DMAC_L QPC_FIELD_LOC(383, 352)
506#define QPC_DMAC_H QPC_FIELD_LOC(399, 384)
507#define QPC_UDPSPN QPC_FIELD_LOC(415, 400)
508#define QPC_DQPN QPC_FIELD_LOC(439, 416)
509#define QPC_SQ_TX_ERR QPC_FIELD_LOC(440, 440)
510#define QPC_SQ_RX_ERR QPC_FIELD_LOC(441, 441)
511#define QPC_RQ_TX_ERR QPC_FIELD_LOC(442, 442)
512#define QPC_RQ_RX_ERR QPC_FIELD_LOC(443, 443)
513#define QPC_LP_PKTN_INI QPC_FIELD_LOC(447, 444)
514#define QPC_CONG_ALGO_TMPL_ID QPC_FIELD_LOC(455, 448)
515#define QPC_SCC_TOKEN QPC_FIELD_LOC(474, 456)
516#define QPC_SQ_DB_DOING QPC_FIELD_LOC(475, 475)
517#define QPC_RQ_DB_DOING QPC_FIELD_LOC(476, 476)
518#define QPC_QP_ST QPC_FIELD_LOC(479, 477)
519#define QPC_QKEY_XRCD QPC_FIELD_LOC(511, 480)
520#define QPC_RQ_RECORD_EN QPC_FIELD_LOC(512, 512)
521#define QPC_RQ_DB_RECORD_ADDR_L QPC_FIELD_LOC(543, 513)
522#define QPC_RQ_DB_RECORD_ADDR_H QPC_FIELD_LOC(575, 544)
523#define QPC_SRQN QPC_FIELD_LOC(599, 576)
524#define QPC_SRQ_EN QPC_FIELD_LOC(600, 600)
525#define QPC_RRE QPC_FIELD_LOC(601, 601)
526#define QPC_RWE QPC_FIELD_LOC(602, 602)
527#define QPC_ATE QPC_FIELD_LOC(603, 603)
528#define QPC_RQIE QPC_FIELD_LOC(604, 604)
529#define QPC_EXT_ATE QPC_FIELD_LOC(605, 605)
530#define QPC_RQ_VLAN_EN QPC_FIELD_LOC(606, 606)
531#define QPC_RQ_RTY_TX_ERR QPC_FIELD_LOC(607, 607)
532#define QPC_RX_CQN QPC_FIELD_LOC(631, 608)
533#define QPC_XRC_QP_TYPE QPC_FIELD_LOC(632, 632)
534#define QPC_RSV3 QPC_FIELD_LOC(634, 633)
535#define QPC_MIN_RNR_TIME QPC_FIELD_LOC(639, 635)
536#define QPC_RQ_PRODUCER_IDX QPC_FIELD_LOC(655, 640)
537#define QPC_RQ_CONSUMER_IDX QPC_FIELD_LOC(671, 656)
538#define QPC_RQ_CUR_BLK_ADDR_L QPC_FIELD_LOC(703, 672)
539#define QPC_RQ_CUR_BLK_ADDR_H QPC_FIELD_LOC(723, 704)
540#define QPC_SRQ_INFO QPC_FIELD_LOC(735, 724)
541#define QPC_RX_REQ_MSN QPC_FIELD_LOC(759, 736)
542#define QPC_REDUCE_CODE QPC_FIELD_LOC(766, 760)
543#define QPC_RX_XRC_PKT_CQE_FLG QPC_FIELD_LOC(767, 767)
544#define QPC_RQ_NXT_BLK_ADDR_L QPC_FIELD_LOC(799, 768)
545#define QPC_RQ_NXT_BLK_ADDR_H QPC_FIELD_LOC(819, 800)
546#define QPC_REDUCE_EN QPC_FIELD_LOC(820, 820)
547#define QPC_FLUSH_EN QPC_FIELD_LOC(821, 821)
548#define QPC_AW_EN QPC_FIELD_LOC(822, 822)
549#define QPC_WN_EN QPC_FIELD_LOC(823, 823)
550#define QPC_RQ_CUR_WQE_SGE_NUM QPC_FIELD_LOC(831, 824)
551#define QPC_INV_CREDIT QPC_FIELD_LOC(832, 832)
552#define QPC_LAST_WRITE_TYPE QPC_FIELD_LOC(834, 833)
553#define QPC_RX_REQ_PSN_ERR QPC_FIELD_LOC(835, 835)
554#define QPC_RX_REQ_LAST_OPTYPE QPC_FIELD_LOC(838, 836)
555#define QPC_RX_REQ_RNR QPC_FIELD_LOC(839, 839)
556#define QPC_RX_REQ_EPSN QPC_FIELD_LOC(863, 840)
557#define QPC_RQ_RNR_TIMER QPC_FIELD_LOC(895, 864)
558#define QPC_RX_MSG_LEN QPC_FIELD_LOC(927, 896)
559#define QPC_RX_RKEY_PKT_INFO QPC_FIELD_LOC(959, 928)
560#define QPC_RX_VA QPC_FIELD_LOC(1023, 960)
561#define QPC_TRRL_HEAD_MAX QPC_FIELD_LOC(1031, 1024)
562#define QPC_TRRL_TAIL_MAX QPC_FIELD_LOC(1039, 1032)
563#define QPC_TRRL_BA_L QPC_FIELD_LOC(1055, 1040)
564#define QPC_TRRL_BA_M QPC_FIELD_LOC(1087, 1056)
565#define QPC_TRRL_BA_H QPC_FIELD_LOC(1099, 1088)
566#define QPC_RR_MAX QPC_FIELD_LOC(1102, 1100)
567#define QPC_RQ_RTY_WAIT_DO QPC_FIELD_LOC(1103, 1103)
568#define QPC_RAQ_TRRL_HEAD QPC_FIELD_LOC(1111, 1104)
569#define QPC_RAQ_TRRL_TAIL QPC_FIELD_LOC(1119, 1112)
570#define QPC_RAQ_RTY_INI_PSN QPC_FIELD_LOC(1143, 1120)
571#define QPC_CIRE_SLV_RQ_EN QPC_FIELD_LOC(1144, 1144)
572#define QPC_RAQ_CREDIT QPC_FIELD_LOC(1149, 1145)
573#define QPC_RQ_DB_IN_EXT QPC_FIELD_LOC(1150, 1150)
574#define QPC_RESP_RTY_FLG QPC_FIELD_LOC(1151, 1151)
575#define QPC_RAQ_MSN QPC_FIELD_LOC(1175, 1152)
576#define QPC_RAQ_SYNDROME QPC_FIELD_LOC(1183, 1176)
577#define QPC_RAQ_PSN QPC_FIELD_LOC(1207, 1184)
578#define QPC_RAQ_TRRL_RTY_HEAD QPC_FIELD_LOC(1215, 1208)
579#define QPC_RAQ_USE_PKTN QPC_FIELD_LOC(1239, 1216)
580#define QPC_RQ_SCC_TOKEN QPC_FIELD_LOC(1245, 1240)
581#define QPC_RVD10 QPC_FIELD_LOC(1247, 1246)
582#define QPC_SQ_PRODUCER_IDX QPC_FIELD_LOC(1263, 1248)
583#define QPC_SQ_CONSUMER_IDX QPC_FIELD_LOC(1279, 1264)
584#define QPC_SQ_CUR_BLK_ADDR_L QPC_FIELD_LOC(1311, 1280)
585#define QPC_SQ_CUR_BLK_ADDR_H QPC_FIELD_LOC(1331, 1312)
586#define QPC_MSG_RTY_LP_FLG QPC_FIELD_LOC(1332, 1332)
587#define QPC_SQ_INVLD_FLG QPC_FIELD_LOC(1333, 1333)
588#define QPC_LP_SGEN_INI QPC_FIELD_LOC(1335, 1334)
589#define QPC_SQ_VLAN_EN QPC_FIELD_LOC(1336, 1336)
590#define QPC_POLL_DB_WAIT_DO QPC_FIELD_LOC(1337, 1337)
591#define QPC_SCC_TOKEN_FORBID_SQ_DEQ QPC_FIELD_LOC(1338, 1338)
592#define QPC_WAIT_ACK_TIMEOUT QPC_FIELD_LOC(1339, 1339)
593#define QPC_IRRL_IDX_LSB QPC_FIELD_LOC(1343, 1340)
594#define QPC_ACK_REQ_FREQ QPC_FIELD_LOC(1349, 1344)
595#define QPC_MSG_RNR_FLG QPC_FIELD_LOC(1350, 1350)
596#define QPC_FRE QPC_FIELD_LOC(1351, 1351)
597#define QPC_SQ_CUR_PSN QPC_FIELD_LOC(1375, 1352)
598#define QPC_MSG_USE_PKTN QPC_FIELD_LOC(1399, 1376)
599#define QPC_IRRL_HEAD_PRE QPC_FIELD_LOC(1407, 1400)
600#define QPC_SQ_CUR_SGE_BLK_ADDR_L QPC_FIELD_LOC(1439, 1408)
601#define QPC_SQ_CUR_SGE_BLK_ADDR_H QPC_FIELD_LOC(1459, 1440)
602#define QPC_IRRL_IDX_MSB QPC_FIELD_LOC(1471, 1460)
603#define QPC_CUR_SGE_OFFSET QPC_FIELD_LOC(1503, 1472)
604#define QPC_CUR_SGE_IDX QPC_FIELD_LOC(1527, 1504)
605#define QPC_EXT_SGE_NUM_LEFT QPC_FIELD_LOC(1535, 1528)
606#define QPC_OWNER_MODE QPC_FIELD_LOC(1536, 1536)
607#define QPC_CIRE_SLV_SQ_EN QPC_FIELD_LOC(1537, 1537)
608#define QPC_CIRE_DOING QPC_FIELD_LOC(1538, 1538)
609#define QPC_CIRE_RESULT QPC_FIELD_LOC(1539, 1539)
610#define QPC_OWNER_DB_WAIT_DO QPC_FIELD_LOC(1540, 1540)
611#define QPC_SQ_WQE_INVLD QPC_FIELD_LOC(1541, 1541)
612#define QPC_DCA_MODE QPC_FIELD_LOC(1542, 1542)
613#define QPC_RTY_OWNER_NOCHK QPC_FIELD_LOC(1543, 1543)
614#define QPC_V2_IRRL_HEAD QPC_FIELD_LOC(1543, 1536)
615#define QPC_SQ_MAX_PSN QPC_FIELD_LOC(1567, 1544)
616#define QPC_SQ_MAX_IDX QPC_FIELD_LOC(1583, 1568)
617#define QPC_LCL_OPERATED_CNT QPC_FIELD_LOC(1599, 1584)
618#define QPC_IRRL_BA_L QPC_FIELD_LOC(1631, 1600)
619#define QPC_IRRL_BA_H QPC_FIELD_LOC(1657, 1632)
620#define QPC_PKT_RNR_FLG QPC_FIELD_LOC(1658, 1658)
621#define QPC_PKT_RTY_FLG QPC_FIELD_LOC(1659, 1659)
622#define QPC_RMT_E2E QPC_FIELD_LOC(1660, 1660)
623#define QPC_SR_MAX QPC_FIELD_LOC(1663, 1661)
624#define QPC_LSN QPC_FIELD_LOC(1687, 1664)
625#define QPC_RETRY_NUM_INIT QPC_FIELD_LOC(1690, 1688)
626#define QPC_CHECK_FLG QPC_FIELD_LOC(1692, 1691)
627#define QPC_RETRY_CNT QPC_FIELD_LOC(1695, 1693)
628#define QPC_SQ_TIMER QPC_FIELD_LOC(1727, 1696)
629#define QPC_RETRY_MSG_MSN QPC_FIELD_LOC(1743, 1728)
630#define QPC_RETRY_MSG_PSN_L QPC_FIELD_LOC(1759, 1744)
631#define QPC_RETRY_MSG_PSN_H QPC_FIELD_LOC(1767, 1760)
632#define QPC_RETRY_MSG_FPKT_PSN QPC_FIELD_LOC(1791, 1768)
633#define QPC_RX_SQ_CUR_BLK_ADDR_L QPC_FIELD_LOC(1823, 1792)
634#define QPC_RX_SQ_CUR_BLK_ADDR_H QPC_FIELD_LOC(1843, 1824)
635#define QPC_IRRL_SGE_IDX QPC_FIELD_LOC(1851, 1844)
636#define QPC_LSAN_EN QPC_FIELD_LOC(1852, 1852)
637#define QPC_SO_LP_VLD QPC_FIELD_LOC(1853, 1853)
638#define QPC_FENCE_LP_VLD QPC_FIELD_LOC(1854, 1854)
639#define QPC_IRRL_LP_VLD QPC_FIELD_LOC(1855, 1855)
640#define QPC_IRRL_CUR_SGE_OFFSET QPC_FIELD_LOC(1887, 1856)
641#define QPC_IRRL_TAIL_REAL QPC_FIELD_LOC(1895, 1888)
642#define QPC_IRRL_TAIL_RD QPC_FIELD_LOC(1903, 1896)
643#define QPC_RX_ACK_MSN QPC_FIELD_LOC(1919, 1904)
644#define QPC_RX_ACK_EPSN QPC_FIELD_LOC(1943, 1920)
645#define QPC_RNR_NUM_INIT QPC_FIELD_LOC(1946, 1944)
646#define QPC_RNR_CNT QPC_FIELD_LOC(1949, 1947)
647#define QPC_LCL_OP_FLG QPC_FIELD_LOC(1950, 1950)
648#define QPC_IRRL_RD_FLG QPC_FIELD_LOC(1951, 1951)
649#define QPC_IRRL_PSN QPC_FIELD_LOC(1975, 1952)
650#define QPC_ACK_PSN_ERR QPC_FIELD_LOC(1976, 1976)
651#define QPC_ACK_LAST_OPTYPE QPC_FIELD_LOC(1978, 1977)
652#define QPC_IRRL_PSN_VLD QPC_FIELD_LOC(1979, 1979)
653#define QPC_RNR_RETRY_FLAG QPC_FIELD_LOC(1980, 1980)
654#define QPC_SQ_RTY_TX_ERR QPC_FIELD_LOC(1981, 1981)
655#define QPC_LAST_IND QPC_FIELD_LOC(1982, 1982)
656#define QPC_CQ_ERR_IND QPC_FIELD_LOC(1983, 1983)
657#define QPC_TX_CQN QPC_FIELD_LOC(2007, 1984)
658#define QPC_SIG_TYPE QPC_FIELD_LOC(2008, 2008)
659#define QPC_ERR_TYPE QPC_FIELD_LOC(2015, 2009)
660#define QPC_RQ_CQE_IDX QPC_FIELD_LOC(2031, 2016)
661#define QPC_SQ_FLUSH_IDX QPC_FIELD_LOC(2047, 2032)
662
663#define RETRY_MSG_PSN_SHIFT 16
664
665#define QPCEX_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_qp_context_ex, h, l)
666
667#define QPCEX_CONG_ALG_SEL QPCEX_FIELD_LOC(0, 0)
668#define QPCEX_CONG_ALG_SUB_SEL QPCEX_FIELD_LOC(1, 1)
669#define QPCEX_DIP_CTX_IDX_VLD QPCEX_FIELD_LOC(2, 2)
670#define QPCEX_DIP_CTX_IDX QPCEX_FIELD_LOC(22, 3)
671#define QPCEX_SQ_RQ_NOT_FORBID_EN QPCEX_FIELD_LOC(23, 23)
672#define QPCEX_STASH QPCEX_FIELD_LOC(82, 82)
673
674#define V2_QP_RWE_S 1 /* rdma write enable */
675#define V2_QP_RRE_S 2 /* rdma read enable */
676#define V2_QP_ATE_S 3 /* rdma atomic enable */
677
678struct hns_roce_v2_cqe {
679 __le32 byte_4;
680 union {
681 __le32 rkey;
682 __le32 immtdata;
683 };
684 __le32 byte_12;
685 __le32 byte_16;
686 __le32 byte_cnt;
687 u8 smac[4];
688 __le32 byte_28;
689 __le32 byte_32;
690 __le32 rsv[8];
691};
692
693#define CQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_cqe, h, l)
694
695#define CQE_OPCODE CQE_FIELD_LOC(4, 0)
696#define CQE_RQ_INLINE CQE_FIELD_LOC(5, 5)
697#define CQE_S_R CQE_FIELD_LOC(6, 6)
698#define CQE_OWNER CQE_FIELD_LOC(7, 7)
699#define CQE_STATUS CQE_FIELD_LOC(15, 8)
700#define CQE_WQE_IDX CQE_FIELD_LOC(31, 16)
701#define CQE_RKEY_IMMTDATA CQE_FIELD_LOC(63, 32)
702#define CQE_XRC_SRQN CQE_FIELD_LOC(87, 64)
703#define CQE_RSV0 CQE_FIELD_LOC(95, 88)
704#define CQE_LCL_QPN CQE_FIELD_LOC(119, 96)
705#define CQE_SUB_STATUS CQE_FIELD_LOC(127, 120)
706#define CQE_BYTE_CNT CQE_FIELD_LOC(159, 128)
707#define CQE_SMAC CQE_FIELD_LOC(207, 160)
708#define CQE_PORT_TYPE CQE_FIELD_LOC(209, 208)
709#define CQE_VID CQE_FIELD_LOC(221, 210)
710#define CQE_VID_VLD CQE_FIELD_LOC(222, 222)
711#define CQE_RSV2 CQE_FIELD_LOC(223, 223)
712#define CQE_RMT_QPN CQE_FIELD_LOC(247, 224)
713#define CQE_SL CQE_FIELD_LOC(250, 248)
714#define CQE_PORTN CQE_FIELD_LOC(253, 251)
715#define CQE_GRH CQE_FIELD_LOC(254, 254)
716#define CQE_LPK CQE_FIELD_LOC(255, 255)
717#define CQE_RSV3 CQE_FIELD_LOC(511, 256)
718
719struct hns_roce_v2_mpt_entry {
720 __le32 byte_4_pd_hop_st;
721 __le32 byte_8_mw_cnt_en;
722 __le32 byte_12_mw_pa;
723 __le32 bound_lkey;
724 __le32 len_l;
725 __le32 len_h;
726 __le32 lkey;
727 __le32 va_l;
728 __le32 va_h;
729 __le32 pbl_size;
730 __le32 pbl_ba_l;
731 __le32 byte_48_mode_ba;
732 __le32 pa0_l;
733 __le32 byte_56_pa0_h;
734 __le32 pa1_l;
735 __le32 byte_64_buf_pa1;
736};
737
738#define MPT_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_mpt_entry, h, l)
739
740#define MPT_ST MPT_FIELD_LOC(1, 0)
741#define MPT_PBL_HOP_NUM MPT_FIELD_LOC(3, 2)
742#define MPT_PBL_BA_PG_SZ MPT_FIELD_LOC(7, 4)
743#define MPT_PD MPT_FIELD_LOC(31, 8)
744#define MPT_RA_EN MPT_FIELD_LOC(32, 32)
745#define MPT_R_INV_EN MPT_FIELD_LOC(33, 33)
746#define MPT_L_INV_EN MPT_FIELD_LOC(34, 34)
747#define MPT_BIND_EN MPT_FIELD_LOC(35, 35)
748#define MPT_ATOMIC_EN MPT_FIELD_LOC(36, 36)
749#define MPT_RR_EN MPT_FIELD_LOC(37, 37)
750#define MPT_RW_EN MPT_FIELD_LOC(38, 38)
751#define MPT_LW_EN MPT_FIELD_LOC(39, 39)
752#define MPT_MW_CNT MPT_FIELD_LOC(63, 40)
753#define MPT_FRE MPT_FIELD_LOC(64, 64)
754#define MPT_PA MPT_FIELD_LOC(65, 65)
755#define MPT_ZBVA MPT_FIELD_LOC(66, 66)
756#define MPT_SHARE MPT_FIELD_LOC(67, 67)
757#define MPT_MR_MW MPT_FIELD_LOC(68, 68)
758#define MPT_BPD MPT_FIELD_LOC(69, 69)
759#define MPT_BQP MPT_FIELD_LOC(70, 70)
760#define MPT_INNER_PA_VLD MPT_FIELD_LOC(71, 71)
761#define MPT_MW_BIND_QPN MPT_FIELD_LOC(95, 72)
762#define MPT_BOUND_LKEY MPT_FIELD_LOC(127, 96)
763#define MPT_LEN_L MPT_FIELD_LOC(159, 128)
764#define MPT_LEN_H MPT_FIELD_LOC(191, 160)
765#define MPT_LKEY MPT_FIELD_LOC(223, 192)
766#define MPT_VA MPT_FIELD_LOC(287, 224)
767#define MPT_PBL_SIZE MPT_FIELD_LOC(319, 288)
768#define MPT_PBL_BA_L MPT_FIELD_LOC(351, 320)
769#define MPT_PBL_BA_H MPT_FIELD_LOC(380, 352)
770#define MPT_BLK_MODE MPT_FIELD_LOC(381, 381)
771#define MPT_RSV0 MPT_FIELD_LOC(383, 382)
772#define MPT_PA0_L MPT_FIELD_LOC(415, 384)
773#define MPT_PA0_H MPT_FIELD_LOC(441, 416)
774#define MPT_BOUND_VA MPT_FIELD_LOC(447, 442)
775#define MPT_PA1_L MPT_FIELD_LOC(479, 448)
776#define MPT_PA1_H MPT_FIELD_LOC(505, 480)
777#define MPT_PERSIST_EN MPT_FIELD_LOC(506, 506)
778#define MPT_RSV2 MPT_FIELD_LOC(507, 507)
779#define MPT_PBL_BUF_PG_SZ MPT_FIELD_LOC(511, 508)
780
781#define V2_MPT_BYTE_4_MPT_ST_S 0
782#define V2_MPT_BYTE_4_MPT_ST_M GENMASK(1, 0)
783
784#define V2_MPT_BYTE_4_PBL_HOP_NUM_S 2
785#define V2_MPT_BYTE_4_PBL_HOP_NUM_M GENMASK(3, 2)
786
787#define V2_MPT_BYTE_4_PBL_BA_PG_SZ_S 4
788#define V2_MPT_BYTE_4_PBL_BA_PG_SZ_M GENMASK(7, 4)
789
790#define V2_MPT_BYTE_4_PD_S 8
791#define V2_MPT_BYTE_4_PD_M GENMASK(31, 8)
792
793#define V2_MPT_BYTE_8_RA_EN_S 0
794
795#define V2_MPT_BYTE_8_R_INV_EN_S 1
796
797#define V2_MPT_BYTE_8_L_INV_EN_S 2
798
799#define V2_MPT_BYTE_8_BIND_EN_S 3
800
801#define V2_MPT_BYTE_8_ATOMIC_EN_S 4
802
803#define V2_MPT_BYTE_8_RR_EN_S 5
804
805#define V2_MPT_BYTE_8_RW_EN_S 6
806
807#define V2_MPT_BYTE_8_LW_EN_S 7
808
809#define V2_MPT_BYTE_8_MW_CNT_S 8
810#define V2_MPT_BYTE_8_MW_CNT_M GENMASK(31, 8)
811
812#define V2_MPT_BYTE_12_FRE_S 0
813
814#define V2_MPT_BYTE_12_PA_S 1
815
816#define V2_MPT_BYTE_12_MR_MW_S 4
817
818#define V2_MPT_BYTE_12_BPD_S 5
819
820#define V2_MPT_BYTE_12_BQP_S 6
821
822#define V2_MPT_BYTE_12_INNER_PA_VLD_S 7
823
824#define V2_MPT_BYTE_12_MW_BIND_QPN_S 8
825#define V2_MPT_BYTE_12_MW_BIND_QPN_M GENMASK(31, 8)
826
827#define V2_MPT_BYTE_48_PBL_BA_H_S 0
828#define V2_MPT_BYTE_48_PBL_BA_H_M GENMASK(28, 0)
829
830#define V2_MPT_BYTE_48_BLK_MODE_S 29
831
832#define V2_MPT_BYTE_56_PA0_H_S 0
833#define V2_MPT_BYTE_56_PA0_H_M GENMASK(25, 0)
834
835#define V2_MPT_BYTE_64_PA1_H_S 0
836#define V2_MPT_BYTE_64_PA1_H_M GENMASK(25, 0)
837
838#define V2_MPT_BYTE_64_PBL_BUF_PG_SZ_S 28
839#define V2_MPT_BYTE_64_PBL_BUF_PG_SZ_M GENMASK(31, 28)
840
841struct hns_roce_v2_db {
842 __le32 data[2];
843};
844
845#define DB_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_db, h, l)
846
847#define DB_TAG DB_FIELD_LOC(23, 0)
848#define DB_CMD DB_FIELD_LOC(27, 24)
849#define DB_FLAG DB_FIELD_LOC(31, 31)
850#define DB_PI DB_FIELD_LOC(47, 32)
851#define DB_SL DB_FIELD_LOC(50, 48)
852#define DB_CQ_CI DB_FIELD_LOC(55, 32)
853#define DB_CQ_NOTIFY DB_FIELD_LOC(56, 56)
854#define DB_CQ_CMD_SN DB_FIELD_LOC(58, 57)
855#define EQ_DB_TAG DB_FIELD_LOC(7, 0)
856#define EQ_DB_CMD DB_FIELD_LOC(17, 16)
857#define EQ_DB_CI DB_FIELD_LOC(55, 32)
858
859#define V2_DB_PRODUCER_IDX_S 0
860#define V2_DB_PRODUCER_IDX_M GENMASK(15, 0)
861
862#define V2_CQ_DB_CONS_IDX_S 0
863#define V2_CQ_DB_CONS_IDX_M GENMASK(23, 0)
864
865struct hns_roce_v2_ud_send_wqe {
866 __le32 byte_4;
867 __le32 msg_len;
868 __le32 immtdata;
869 __le32 byte_16;
870 __le32 byte_20;
871 __le32 byte_24;
872 __le32 qkey;
873 __le32 byte_32;
874 __le32 byte_36;
875 __le32 byte_40;
876 u8 dmac[ETH_ALEN];
877 u8 sgid_index;
878 u8 smac_index;
879 u8 dgid[GID_LEN_V2];
880};
881
882#define UD_SEND_WQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_ud_send_wqe, h, l)
883
884#define UD_SEND_WQE_OPCODE UD_SEND_WQE_FIELD_LOC(4, 0)
885#define UD_SEND_WQE_OWNER UD_SEND_WQE_FIELD_LOC(7, 7)
886#define UD_SEND_WQE_CQE UD_SEND_WQE_FIELD_LOC(8, 8)
887#define UD_SEND_WQE_SE UD_SEND_WQE_FIELD_LOC(11, 11)
888#define UD_SEND_WQE_PD UD_SEND_WQE_FIELD_LOC(119, 96)
889#define UD_SEND_WQE_SGE_NUM UD_SEND_WQE_FIELD_LOC(127, 120)
890#define UD_SEND_WQE_MSG_START_SGE_IDX UD_SEND_WQE_FIELD_LOC(151, 128)
891#define UD_SEND_WQE_UDPSPN UD_SEND_WQE_FIELD_LOC(191, 176)
892#define UD_SEND_WQE_DQPN UD_SEND_WQE_FIELD_LOC(247, 224)
893#define UD_SEND_WQE_VLAN UD_SEND_WQE_FIELD_LOC(271, 256)
894#define UD_SEND_WQE_HOPLIMIT UD_SEND_WQE_FIELD_LOC(279, 272)
895#define UD_SEND_WQE_TCLASS UD_SEND_WQE_FIELD_LOC(287, 280)
896#define UD_SEND_WQE_FLOW_LABEL UD_SEND_WQE_FIELD_LOC(307, 288)
897#define UD_SEND_WQE_SL UD_SEND_WQE_FIELD_LOC(311, 308)
898#define UD_SEND_WQE_VLAN_EN UD_SEND_WQE_FIELD_LOC(318, 318)
899#define UD_SEND_WQE_LBI UD_SEND_WQE_FIELD_LOC(319, 319)
900
901struct hns_roce_v2_rc_send_wqe {
902 __le32 byte_4;
903 __le32 msg_len;
904 union {
905 __le32 inv_key;
906 __le32 immtdata;
907 };
908 __le32 byte_16;
909 __le32 byte_20;
910 __le32 rkey;
911 __le64 va;
912};
913
914#define RC_SEND_WQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_v2_rc_send_wqe, h, l)
915
916#define RC_SEND_WQE_OPCODE RC_SEND_WQE_FIELD_LOC(4, 0)
917#define RC_SEND_WQE_DB_SL_L RC_SEND_WQE_FIELD_LOC(6, 5)
918#define RC_SEND_WQE_DB_SL_H RC_SEND_WQE_FIELD_LOC(14, 13)
919#define RC_SEND_WQE_OWNER RC_SEND_WQE_FIELD_LOC(7, 7)
920#define RC_SEND_WQE_CQE RC_SEND_WQE_FIELD_LOC(8, 8)
921#define RC_SEND_WQE_FENCE RC_SEND_WQE_FIELD_LOC(9, 9)
922#define RC_SEND_WQE_SE RC_SEND_WQE_FIELD_LOC(11, 11)
923#define RC_SEND_WQE_INLINE RC_SEND_WQE_FIELD_LOC(12, 12)
924#define RC_SEND_WQE_WQE_INDEX RC_SEND_WQE_FIELD_LOC(30, 15)
925#define RC_SEND_WQE_FLAG RC_SEND_WQE_FIELD_LOC(31, 31)
926#define RC_SEND_WQE_XRC_SRQN RC_SEND_WQE_FIELD_LOC(119, 96)
927#define RC_SEND_WQE_SGE_NUM RC_SEND_WQE_FIELD_LOC(127, 120)
928#define RC_SEND_WQE_MSG_START_SGE_IDX RC_SEND_WQE_FIELD_LOC(151, 128)
929#define RC_SEND_WQE_INL_TYPE RC_SEND_WQE_FIELD_LOC(159, 159)
930
931struct hns_roce_wqe_frmr_seg {
932 __le32 pbl_size;
933 __le32 byte_40;
934};
935
936#define FRMR_WQE_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_wqe_frmr_seg, h, l)
937
938#define FRMR_PBL_SIZE FRMR_WQE_FIELD_LOC(31, 0)
939#define FRMR_BLOCK_SIZE FRMR_WQE_FIELD_LOC(35, 32)
940#define FRMR_PBL_BUF_PG_SZ FRMR_WQE_FIELD_LOC(39, 36)
941#define FRMR_BLK_MODE FRMR_WQE_FIELD_LOC(40, 40)
942#define FRMR_ZBVA FRMR_WQE_FIELD_LOC(41, 41)
943#define FRMR_BIND_EN FRMR_WQE_FIELD_LOC(42, 42)
944#define FRMR_ATOMIC FRMR_WQE_FIELD_LOC(43, 43)
945#define FRMR_RR FRMR_WQE_FIELD_LOC(44, 44)
946#define FRMR_RW FRMR_WQE_FIELD_LOC(45, 45)
947#define FRMR_LW FRMR_WQE_FIELD_LOC(46, 46)
948
949struct hns_roce_v2_wqe_data_seg {
950 __le32 len;
951 __le32 lkey;
952 __le64 addr;
953};
954
955struct hns_roce_query_version {
956 __le16 rocee_vendor_id;
957 __le16 rocee_hw_version;
958 __le32 rsv[5];
959};
960
961struct hns_roce_query_fw_info {
962 __le32 fw_ver;
963 __le32 rsv[5];
964};
965
966struct hns_roce_func_clear {
967 __le32 rst_funcid_en;
968 __le32 func_done;
969 __le32 rsv[4];
970};
971
972#define FUNC_CLEAR_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_func_clear, h, l)
973
974#define FUNC_CLEAR_RST_FUN_DONE FUNC_CLEAR_FIELD_LOC(32, 32)
975
976/* Each physical function manages up to 248 virtual functions, it takes up to
977 * 100ms for each function to execute clear. If an abnormal reset occurs, it is
978 * executed twice at most, so it takes up to 249 * 2 * 100ms.
979 */
980#define HNS_ROCE_V2_FUNC_CLEAR_TIMEOUT_MSECS (249 * 2 * 100)
981#define HNS_ROCE_V2_READ_FUNC_CLEAR_FLAG_INTERVAL 40
982#define HNS_ROCE_V2_READ_FUNC_CLEAR_FLAG_FAIL_WAIT 20
983
984/* Fields of HNS_ROCE_OPC_EXT_CFG */
985#define EXT_CFG_VF_ID CMQ_REQ_FIELD_LOC(31, 0)
986#define EXT_CFG_QP_PI_IDX CMQ_REQ_FIELD_LOC(45, 32)
987#define EXT_CFG_QP_PI_NUM CMQ_REQ_FIELD_LOC(63, 48)
988#define EXT_CFG_QP_NUM CMQ_REQ_FIELD_LOC(87, 64)
989#define EXT_CFG_QP_IDX CMQ_REQ_FIELD_LOC(119, 96)
990#define EXT_CFG_LLM_IDX CMQ_REQ_FIELD_LOC(139, 128)
991#define EXT_CFG_LLM_NUM CMQ_REQ_FIELD_LOC(156, 144)
992
993#define CFG_LLM_A_BA_L CMQ_REQ_FIELD_LOC(31, 0)
994#define CFG_LLM_A_BA_H CMQ_REQ_FIELD_LOC(63, 32)
995#define CFG_LLM_A_DEPTH CMQ_REQ_FIELD_LOC(76, 64)
996#define CFG_LLM_A_PGSZ CMQ_REQ_FIELD_LOC(83, 80)
997#define CFG_LLM_A_INIT_EN CMQ_REQ_FIELD_LOC(84, 84)
998#define CFG_LLM_A_HEAD_BA_L CMQ_REQ_FIELD_LOC(127, 96)
999#define CFG_LLM_A_HEAD_BA_H CMQ_REQ_FIELD_LOC(147, 128)
1000#define CFG_LLM_A_HEAD_NXTPTR CMQ_REQ_FIELD_LOC(159, 148)
1001#define CFG_LLM_A_HEAD_PTR CMQ_REQ_FIELD_LOC(171, 160)
1002#define CFG_LLM_B_TAIL_BA_L CMQ_REQ_FIELD_LOC(31, 0)
1003#define CFG_LLM_B_TAIL_BA_H CMQ_REQ_FIELD_LOC(63, 32)
1004#define CFG_LLM_B_TAIL_PTR CMQ_REQ_FIELD_LOC(75, 64)
1005
1006/* Fields of HNS_ROCE_OPC_CFG_GLOBAL_PARAM */
1007#define CFG_GLOBAL_PARAM_1US_CYCLES CMQ_REQ_FIELD_LOC(9, 0)
1008#define CFG_GLOBAL_PARAM_UDP_PORT CMQ_REQ_FIELD_LOC(31, 16)
1009
1010/*
1011 * Fields of HNS_ROCE_OPC_QUERY_PF_RES, HNS_ROCE_OPC_QUERY_VF_RES
1012 * and HNS_ROCE_OPC_ALLOC_VF_RES
1013 */
1014#define FUNC_RES_A_VF_ID CMQ_REQ_FIELD_LOC(7, 0)
1015#define FUNC_RES_A_QPC_BT_IDX CMQ_REQ_FIELD_LOC(42, 32)
1016#define FUNC_RES_A_QPC_BT_NUM CMQ_REQ_FIELD_LOC(59, 48)
1017#define FUNC_RES_A_SRQC_BT_IDX CMQ_REQ_FIELD_LOC(72, 64)
1018#define FUNC_RES_A_SRQC_BT_NUM CMQ_REQ_FIELD_LOC(89, 80)
1019#define FUNC_RES_A_CQC_BT_IDX CMQ_REQ_FIELD_LOC(104, 96)
1020#define FUNC_RES_A_CQC_BT_NUM CMQ_REQ_FIELD_LOC(121, 112)
1021#define FUNC_RES_A_MPT_BT_IDX CMQ_REQ_FIELD_LOC(136, 128)
1022#define FUNC_RES_A_MPT_BT_NUM CMQ_REQ_FIELD_LOC(153, 144)
1023#define FUNC_RES_A_EQC_BT_IDX CMQ_REQ_FIELD_LOC(168, 160)
1024#define FUNC_RES_A_EQC_BT_NUM CMQ_REQ_FIELD_LOC(185, 176)
1025#define FUNC_RES_B_SMAC_IDX CMQ_REQ_FIELD_LOC(39, 32)
1026#define FUNC_RES_B_SMAC_NUM CMQ_REQ_FIELD_LOC(48, 40)
1027#define FUNC_RES_B_SGID_IDX CMQ_REQ_FIELD_LOC(71, 64)
1028#define FUNC_RES_B_SGID_NUM CMQ_REQ_FIELD_LOC(80, 72)
1029#define FUNC_RES_B_QID_IDX CMQ_REQ_FIELD_LOC(105, 96)
1030#define FUNC_RES_B_QID_NUM CMQ_REQ_FIELD_LOC(122, 112)
1031#define FUNC_RES_V_QID_NUM CMQ_REQ_FIELD_LOC(115, 112)
1032
1033#define FUNC_RES_B_SCCC_BT_IDX CMQ_REQ_FIELD_LOC(136, 128)
1034#define FUNC_RES_B_SCCC_BT_NUM CMQ_REQ_FIELD_LOC(145, 137)
1035#define FUNC_RES_B_GMV_BT_IDX CMQ_REQ_FIELD_LOC(167, 160)
1036#define FUNC_RES_B_GMV_BT_NUM CMQ_REQ_FIELD_LOC(176, 168)
1037#define FUNC_RES_V_GMV_BT_NUM CMQ_REQ_FIELD_LOC(184, 176)
1038
1039/* Fields of HNS_ROCE_OPC_QUERY_PF_TIMER_RES */
1040#define PF_TIMER_RES_QPC_ITEM_IDX CMQ_REQ_FIELD_LOC(43, 32)
1041#define PF_TIMER_RES_QPC_ITEM_NUM CMQ_REQ_FIELD_LOC(60, 48)
1042#define PF_TIMER_RES_CQC_ITEM_IDX CMQ_REQ_FIELD_LOC(74, 64)
1043#define PF_TIMER_RES_CQC_ITEM_NUM CMQ_REQ_FIELD_LOC(91, 80)
1044
1045struct hns_roce_vf_switch {
1046 __le32 rocee_sel;
1047 __le32 fun_id;
1048 __le32 cfg;
1049 __le32 resv1;
1050 __le32 resv2;
1051 __le32 resv3;
1052};
1053
1054#define VF_SWITCH_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_vf_switch, h, l)
1055
1056#define VF_SWITCH_VF_ID VF_SWITCH_FIELD_LOC(42, 35)
1057#define VF_SWITCH_ALW_LPBK VF_SWITCH_FIELD_LOC(65, 65)
1058#define VF_SWITCH_ALW_LCL_LPBK VF_SWITCH_FIELD_LOC(66, 66)
1059#define VF_SWITCH_ALW_DST_OVRD VF_SWITCH_FIELD_LOC(67, 67)
1060
1061struct hns_roce_post_mbox {
1062 __le32 in_param_l;
1063 __le32 in_param_h;
1064 __le32 out_param_l;
1065 __le32 out_param_h;
1066 __le32 cmd_tag;
1067 __le32 token_event_en;
1068};
1069
1070struct hns_roce_mbox_status {
1071 __le32 mb_status_hw_run;
1072 __le32 rsv[5];
1073};
1074
1075#define HNS_ROCE_V2_GO_BIT_TIMEOUT_MSECS 10000
1076
1077#define MB_ST_HW_RUN_M BIT(31)
1078#define MB_ST_COMPLETE_M GENMASK(7, 0)
1079
1080#define MB_ST_COMPLETE_SUCC 1
1081
1082/* Fields of HNS_ROCE_OPC_CFG_BT_ATTR */
1083#define CFG_BT_ATTR_QPC_BA_PGSZ CMQ_REQ_FIELD_LOC(3, 0)
1084#define CFG_BT_ATTR_QPC_BUF_PGSZ CMQ_REQ_FIELD_LOC(7, 4)
1085#define CFG_BT_ATTR_QPC_HOPNUM CMQ_REQ_FIELD_LOC(9, 8)
1086#define CFG_BT_ATTR_SRQC_BA_PGSZ CMQ_REQ_FIELD_LOC(35, 32)
1087#define CFG_BT_ATTR_SRQC_BUF_PGSZ CMQ_REQ_FIELD_LOC(39, 36)
1088#define CFG_BT_ATTR_SRQC_HOPNUM CMQ_REQ_FIELD_LOC(41, 40)
1089#define CFG_BT_ATTR_CQC_BA_PGSZ CMQ_REQ_FIELD_LOC(67, 64)
1090#define CFG_BT_ATTR_CQC_BUF_PGSZ CMQ_REQ_FIELD_LOC(71, 68)
1091#define CFG_BT_ATTR_CQC_HOPNUM CMQ_REQ_FIELD_LOC(73, 72)
1092#define CFG_BT_ATTR_MPT_BA_PGSZ CMQ_REQ_FIELD_LOC(99, 96)
1093#define CFG_BT_ATTR_MPT_BUF_PGSZ CMQ_REQ_FIELD_LOC(103, 100)
1094#define CFG_BT_ATTR_MPT_HOPNUM CMQ_REQ_FIELD_LOC(105, 104)
1095#define CFG_BT_ATTR_SCCC_BA_PGSZ CMQ_REQ_FIELD_LOC(131, 128)
1096#define CFG_BT_ATTR_SCCC_BUF_PGSZ CMQ_REQ_FIELD_LOC(135, 132)
1097#define CFG_BT_ATTR_SCCC_HOPNUM CMQ_REQ_FIELD_LOC(137, 136)
1098
1099/* Fields of HNS_ROCE_OPC_CFG_ENTRY_SIZE */
1100#define CFG_HEM_ENTRY_SIZE_TYPE CMQ_REQ_FIELD_LOC(31, 0)
1101enum {
1102 HNS_ROCE_CFG_QPC_SIZE = BIT(0),
1103 HNS_ROCE_CFG_SCCC_SIZE = BIT(1),
1104};
1105
1106#define CFG_HEM_ENTRY_SIZE_VALUE CMQ_REQ_FIELD_LOC(191, 160)
1107
1108/* Fields of HNS_ROCE_OPC_CFG_GMV_BT */
1109#define CFG_GMV_BT_BA_L CMQ_REQ_FIELD_LOC(31, 0)
1110#define CFG_GMV_BT_BA_H CMQ_REQ_FIELD_LOC(51, 32)
1111#define CFG_GMV_BT_IDX CMQ_REQ_FIELD_LOC(95, 64)
1112
1113/* Fields of HNS_ROCE_QUERY_RAM_ECC */
1114#define QUERY_RAM_ECC_1BIT_ERR CMQ_REQ_FIELD_LOC(31, 0)
1115#define QUERY_RAM_ECC_RES_TYPE CMQ_REQ_FIELD_LOC(63, 32)
1116#define QUERY_RAM_ECC_TAG CMQ_REQ_FIELD_LOC(95, 64)
1117
1118struct hns_roce_cfg_sgid_tb {
1119 __le32 table_idx_rsv;
1120 __le32 vf_sgid_l;
1121 __le32 vf_sgid_ml;
1122 __le32 vf_sgid_mh;
1123 __le32 vf_sgid_h;
1124 __le32 vf_sgid_type_rsv;
1125};
1126
1127#define SGID_TB_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_sgid_tb, h, l)
1128
1129#define CFG_SGID_TB_TABLE_IDX SGID_TB_FIELD_LOC(7, 0)
1130#define CFG_SGID_TB_VF_SGID_TYPE SGID_TB_FIELD_LOC(161, 160)
1131
1132struct hns_roce_cfg_smac_tb {
1133 __le32 tb_idx_rsv;
1134 __le32 vf_smac_l;
1135 __le32 vf_smac_h_rsv;
1136 __le32 rsv[3];
1137};
1138
1139#define SMAC_TB_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_smac_tb, h, l)
1140
1141#define CFG_SMAC_TB_IDX SMAC_TB_FIELD_LOC(7, 0)
1142#define CFG_SMAC_TB_VF_SMAC_H SMAC_TB_FIELD_LOC(79, 64)
1143
1144struct hns_roce_cfg_gmv_tb_a {
1145 __le32 vf_sgid_l;
1146 __le32 vf_sgid_ml;
1147 __le32 vf_sgid_mh;
1148 __le32 vf_sgid_h;
1149 __le32 vf_sgid_type_vlan;
1150 __le32 resv;
1151};
1152
1153#define GMV_TB_A_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_gmv_tb_a, h, l)
1154
1155#define GMV_TB_A_VF_SGID_TYPE GMV_TB_A_FIELD_LOC(129, 128)
1156#define GMV_TB_A_VF_VLAN_EN GMV_TB_A_FIELD_LOC(130, 130)
1157#define GMV_TB_A_VF_VLAN_ID GMV_TB_A_FIELD_LOC(155, 144)
1158
1159struct hns_roce_cfg_gmv_tb_b {
1160 __le32 vf_smac_l;
1161 __le32 vf_smac_h;
1162 __le32 table_idx_rsv;
1163 __le32 resv[3];
1164};
1165
1166#define GMV_TB_B_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cfg_gmv_tb_b, h, l)
1167
1168#define GMV_TB_B_SMAC_H GMV_TB_B_FIELD_LOC(47, 32)
1169#define GMV_TB_B_SGID_IDX GMV_TB_B_FIELD_LOC(71, 64)
1170
1171#define HNS_ROCE_QUERY_PF_CAPS_CMD_NUM 5
1172struct hns_roce_query_pf_caps_a {
1173 u8 number_ports;
1174 u8 local_ca_ack_delay;
1175 __le16 max_sq_sg;
1176 __le16 max_sq_inline;
1177 __le16 max_rq_sg;
1178 __le32 rsv0;
1179 __le16 num_qpc_timer;
1180 __le16 num_cqc_timer;
1181 __le16 max_srq_sges;
1182 u8 num_aeq_vectors;
1183 u8 num_other_vectors;
1184 u8 max_sq_desc_sz;
1185 u8 max_rq_desc_sz;
1186 u8 rsv1;
1187 u8 cqe_sz;
1188};
1189
1190struct hns_roce_query_pf_caps_b {
1191 u8 mtpt_entry_sz;
1192 u8 irrl_entry_sz;
1193 u8 trrl_entry_sz;
1194 u8 cqc_entry_sz;
1195 u8 srqc_entry_sz;
1196 u8 idx_entry_sz;
1197 u8 sccc_sz;
1198 u8 max_mtu;
1199 __le16 qpc_sz;
1200 __le16 qpc_timer_entry_sz;
1201 __le16 cqc_timer_entry_sz;
1202 u8 min_cqes;
1203 u8 min_wqes;
1204 __le32 page_size_cap;
1205 u8 pkey_table_len;
1206 u8 phy_num_uars;
1207 u8 ctx_hop_num;
1208 u8 pbl_hop_num;
1209};
1210
1211struct hns_roce_query_pf_caps_c {
1212 __le32 cap_flags_num_pds;
1213 __le32 max_gid_num_cqs;
1214 __le32 cq_depth;
1215 __le32 num_mrws;
1216 __le32 ord_num_qps;
1217 __le16 sq_depth;
1218 __le16 rq_depth;
1219};
1220
1221#define PF_CAPS_C_FIELD_LOC(h, l) \
1222 FIELD_LOC(struct hns_roce_query_pf_caps_c, h, l)
1223
1224#define PF_CAPS_C_NUM_PDS PF_CAPS_C_FIELD_LOC(19, 0)
1225#define PF_CAPS_C_CAP_FLAGS PF_CAPS_C_FIELD_LOC(31, 20)
1226#define PF_CAPS_C_NUM_CQS PF_CAPS_C_FIELD_LOC(51, 32)
1227#define PF_CAPS_C_MAX_GID PF_CAPS_C_FIELD_LOC(60, 52)
1228#define PF_CAPS_C_CQ_DEPTH PF_CAPS_C_FIELD_LOC(86, 64)
1229#define PF_CAPS_C_NUM_MRWS PF_CAPS_C_FIELD_LOC(115, 96)
1230#define PF_CAPS_C_NUM_QPS PF_CAPS_C_FIELD_LOC(147, 128)
1231#define PF_CAPS_C_MAX_ORD PF_CAPS_C_FIELD_LOC(155, 148)
1232
1233struct hns_roce_query_pf_caps_d {
1234 __le32 wq_hop_num_max_srqs;
1235 __le16 srq_depth;
1236 __le16 cap_flags_ex;
1237 __le32 num_ceqs_ceq_depth;
1238 __le32 arm_st_aeq_depth;
1239 __le32 num_uars_rsv_pds;
1240 __le32 rsv_uars_rsv_qps;
1241};
1242
1243#define PF_CAPS_D_FIELD_LOC(h, l) \
1244 FIELD_LOC(struct hns_roce_query_pf_caps_d, h, l)
1245
1246#define PF_CAPS_D_NUM_SRQS PF_CAPS_D_FIELD_LOC(19, 0)
1247#define PF_CAPS_D_RQWQE_HOP_NUM PF_CAPS_D_FIELD_LOC(21, 20)
1248#define PF_CAPS_D_EX_SGE_HOP_NUM PF_CAPS_D_FIELD_LOC(23, 22)
1249#define PF_CAPS_D_SQWQE_HOP_NUM PF_CAPS_D_FIELD_LOC(25, 24)
1250#define PF_CAPS_D_CONG_TYPE PF_CAPS_D_FIELD_LOC(29, 26)
1251#define PF_CAPS_D_CEQ_DEPTH PF_CAPS_D_FIELD_LOC(85, 64)
1252#define PF_CAPS_D_NUM_CEQS PF_CAPS_D_FIELD_LOC(95, 86)
1253#define PF_CAPS_D_AEQ_DEPTH PF_CAPS_D_FIELD_LOC(117, 96)
1254#define PF_CAPS_D_AEQ_ARM_ST PF_CAPS_D_FIELD_LOC(119, 118)
1255#define PF_CAPS_D_CEQ_ARM_ST PF_CAPS_D_FIELD_LOC(121, 120)
1256#define PF_CAPS_D_RSV_PDS PF_CAPS_D_FIELD_LOC(147, 128)
1257#define PF_CAPS_D_NUM_UARS PF_CAPS_D_FIELD_LOC(155, 148)
1258#define PF_CAPS_D_RSV_QPS PF_CAPS_D_FIELD_LOC(179, 160)
1259#define PF_CAPS_D_RSV_UARS PF_CAPS_D_FIELD_LOC(187, 180)
1260
1261#define HNS_ROCE_CAP_FLAGS_EX_SHIFT 12
1262
1263struct hns_roce_congestion_algorithm {
1264 u8 alg_sel;
1265 u8 alg_sub_sel;
1266 u8 dip_vld;
1267 u8 wnd_mode_sel;
1268};
1269
1270struct hns_roce_query_pf_caps_e {
1271 __le32 chunk_size_shift_rsv_mrws;
1272 __le32 rsv_cqs;
1273 __le32 rsv_srqs;
1274 __le32 rsv_lkey;
1275 __le16 ceq_max_cnt;
1276 __le16 ceq_period;
1277 __le16 aeq_max_cnt;
1278 __le16 aeq_period;
1279};
1280
1281#define PF_CAPS_E_FIELD_LOC(h, l) \
1282 FIELD_LOC(struct hns_roce_query_pf_caps_e, h, l)
1283
1284#define PF_CAPS_E_RSV_MRWS PF_CAPS_E_FIELD_LOC(19, 0)
1285#define PF_CAPS_E_CHUNK_SIZE_SHIFT PF_CAPS_E_FIELD_LOC(31, 20)
1286#define PF_CAPS_E_RSV_CQS PF_CAPS_E_FIELD_LOC(51, 32)
1287#define PF_CAPS_E_RSV_SRQS PF_CAPS_E_FIELD_LOC(83, 64)
1288#define PF_CAPS_E_RSV_LKEYS PF_CAPS_E_FIELD_LOC(115, 96)
1289
1290struct hns_roce_cmq_req {
1291 __le32 data[6];
1292};
1293
1294#define CMQ_REQ_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_cmq_req, h, l)
1295
1296struct hns_roce_cmq_desc {
1297 __le16 opcode;
1298 __le16 flag;
1299 __le16 retval;
1300 __le16 rsv;
1301 union {
1302 __le32 data[6];
1303 struct {
1304 __le32 own_func_num;
1305 __le32 own_mac_id;
1306 __le32 rsv[4];
1307 } func_info;
1308 };
1309};
1310
1311struct hns_roce_v2_cmq_ring {
1312 dma_addr_t desc_dma_addr;
1313 struct hns_roce_cmq_desc *desc;
1314 u32 head;
1315 u16 buf_size;
1316 u16 desc_num;
1317 u8 flag;
1318 spinlock_t lock; /* command queue lock */
1319};
1320
1321struct hns_roce_v2_cmq {
1322 struct hns_roce_v2_cmq_ring csq;
1323 u16 tx_timeout;
1324};
1325
1326struct hns_roce_link_table {
1327 struct hns_roce_buf_list table;
1328 struct hns_roce_buf *buf;
1329};
1330
1331#define HNS_ROCE_EXT_LLM_ENTRY(addr, id) (((id) << (64 - 12)) | ((addr) >> 12))
1332#define HNS_ROCE_EXT_LLM_MIN_PAGES(que_num) ((que_num) * 4 + 2)
1333
1334struct hns_roce_v2_free_mr {
1335 struct hns_roce_qp *rsv_qp[HNS_ROCE_FREE_MR_USED_QP_NUM];
1336 struct hns_roce_cq *rsv_cq;
1337 struct hns_roce_pd *rsv_pd;
1338 struct mutex mutex;
1339};
1340
1341struct hns_roce_v2_priv {
1342 struct hnae3_handle *handle;
1343 struct hns_roce_v2_cmq cmq;
1344 struct hns_roce_link_table ext_llm;
1345 struct hns_roce_v2_free_mr free_mr;
1346};
1347
1348struct hns_roce_dip {
1349 u8 dgid[GID_LEN_V2];
1350 u32 dip_idx;
1351 struct list_head node; /* all dips are on a list */
1352};
1353
1354struct fmea_ram_ecc {
1355 u32 is_ecc_err;
1356 u32 res_type;
1357 u32 index;
1358};
1359
1360/* only for RNR timeout issue of HIP08 */
1361#define HNS_ROCE_CLOCK_ADJUST 1000
1362#define HNS_ROCE_MAX_CQ_PERIOD 65
1363#define HNS_ROCE_MAX_EQ_PERIOD 65
1364#define HNS_ROCE_RNR_TIMER_10NS 1
1365#define HNS_ROCE_1US_CFG 999
1366#define HNS_ROCE_1NS_CFG 0
1367
1368#define HNS_ROCE_AEQ_DEFAULT_BURST_NUM 0x0
1369#define HNS_ROCE_AEQ_DEFAULT_INTERVAL 0x0
1370#define HNS_ROCE_CEQ_DEFAULT_BURST_NUM 0x0
1371#define HNS_ROCE_CEQ_DEFAULT_INTERVAL 0x0
1372
1373#define HNS_ROCE_V2_EQ_STATE_INVALID 0
1374#define HNS_ROCE_V2_EQ_STATE_VALID 1
1375#define HNS_ROCE_V2_EQ_STATE_OVERFLOW 2
1376#define HNS_ROCE_V2_EQ_STATE_FAILURE 3
1377
1378#define HNS_ROCE_V2_EQ_OVER_IGNORE_0 0
1379#define HNS_ROCE_V2_EQ_OVER_IGNORE_1 1
1380
1381#define HNS_ROCE_V2_EQ_COALESCE_0 0
1382#define HNS_ROCE_V2_EQ_COALESCE_1 1
1383
1384#define HNS_ROCE_V2_EQ_FIRED 0
1385#define HNS_ROCE_V2_EQ_ARMED 1
1386#define HNS_ROCE_V2_EQ_ALWAYS_ARMED 3
1387
1388#define HNS_ROCE_EQ_INIT_EQE_CNT 0
1389#define HNS_ROCE_EQ_INIT_PROD_IDX 0
1390#define HNS_ROCE_EQ_INIT_REPORT_TIMER 0
1391#define HNS_ROCE_EQ_INIT_MSI_IDX 0
1392#define HNS_ROCE_EQ_INIT_CONS_IDX 0
1393#define HNS_ROCE_EQ_INIT_NXT_EQE_BA 0
1394
1395#define HNS_ROCE_V2_COMP_EQE_NUM 0x1000
1396#define HNS_ROCE_V2_ASYNC_EQE_NUM 0x1000
1397
1398#define HNS_ROCE_V2_VF_INT_ST_AEQ_OVERFLOW_S 0
1399
1400#define HNS_ROCE_EQ_DB_CMD_AEQ 0x0
1401#define HNS_ROCE_EQ_DB_CMD_AEQ_ARMED 0x1
1402#define HNS_ROCE_EQ_DB_CMD_CEQ 0x2
1403#define HNS_ROCE_EQ_DB_CMD_CEQ_ARMED 0x3
1404
1405#define EQ_ENABLE 1
1406#define EQ_DISABLE 0
1407
1408#define EQ_REG_OFFSET 0x4
1409
1410#define HNS_ROCE_INT_NAME_LEN 32
1411#define HNS_ROCE_V2_EQN_M GENMASK(23, 0)
1412
1413#define HNS_ROCE_V2_VF_ABN_INT_EN_S 0
1414#define HNS_ROCE_V2_VF_ABN_INT_EN_M GENMASK(0, 0)
1415#define HNS_ROCE_V2_VF_ABN_INT_ST_M GENMASK(2, 0)
1416#define HNS_ROCE_V2_VF_ABN_INT_CFG_M GENMASK(2, 0)
1417#define HNS_ROCE_V2_VF_EVENT_INT_EN_M GENMASK(0, 0)
1418
1419struct hns_roce_eq_context {
1420 __le32 data[16];
1421};
1422
1423#define EQC_FIELD_LOC(h, l) FIELD_LOC(struct hns_roce_eq_context, h, l)
1424
1425#define EQC_EQ_ST EQC_FIELD_LOC(1, 0)
1426#define EQC_EQE_HOP_NUM EQC_FIELD_LOC(3, 2)
1427#define EQC_OVER_IGNORE EQC_FIELD_LOC(4, 4)
1428#define EQC_COALESCE EQC_FIELD_LOC(5, 5)
1429#define EQC_ARM_ST EQC_FIELD_LOC(7, 6)
1430#define EQC_EQN EQC_FIELD_LOC(15, 8)
1431#define EQC_EQE_CNT EQC_FIELD_LOC(31, 16)
1432#define EQC_EQE_BA_PG_SZ EQC_FIELD_LOC(35, 32)
1433#define EQC_EQE_BUF_PG_SZ EQC_FIELD_LOC(39, 36)
1434#define EQC_EQ_PROD_INDX EQC_FIELD_LOC(63, 40)
1435#define EQC_EQ_MAX_CNT EQC_FIELD_LOC(79, 64)
1436#define EQC_EQ_PERIOD EQC_FIELD_LOC(95, 80)
1437#define EQC_EQE_REPORT_TIMER EQC_FIELD_LOC(127, 96)
1438#define EQC_EQE_BA_L EQC_FIELD_LOC(159, 128)
1439#define EQC_EQE_BA_H EQC_FIELD_LOC(188, 160)
1440#define EQC_SHIFT EQC_FIELD_LOC(199, 192)
1441#define EQC_MSI_INDX EQC_FIELD_LOC(207, 200)
1442#define EQC_CUR_EQE_BA_L EQC_FIELD_LOC(223, 208)
1443#define EQC_CUR_EQE_BA_M EQC_FIELD_LOC(255, 224)
1444#define EQC_CUR_EQE_BA_H EQC_FIELD_LOC(259, 256)
1445#define EQC_EQ_CONS_INDX EQC_FIELD_LOC(287, 264)
1446#define EQC_NEX_EQE_BA_L EQC_FIELD_LOC(319, 288)
1447#define EQC_NEX_EQE_BA_H EQC_FIELD_LOC(339, 320)
1448#define EQC_EQE_SIZE EQC_FIELD_LOC(341, 340)
1449
1450#define MAX_SERVICE_LEVEL 0x7
1451
1452struct hns_roce_wqe_atomic_seg {
1453 __le64 fetchadd_swap_data;
1454 __le64 cmp_data;
1455};
1456
1457struct hns_roce_sccc_clr {
1458 __le32 qpn;
1459 __le32 rsv[5];
1460};
1461
1462struct hns_roce_sccc_clr_done {
1463 __le32 clr_done;
1464 __le32 rsv[5];
1465};
1466
1467int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
1468
1469static inline void hns_roce_write64(struct hns_roce_dev *hr_dev, __le32 val[2],
1470 void __iomem *dest)
1471{
1472 struct hns_roce_v2_priv *priv = hr_dev->priv;
1473 struct hnae3_handle *handle = priv->handle;
1474 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1475
1476 if (!hr_dev->dis_db && !ops->get_hw_reset_stat(handle))
1477 hns_roce_write64_k(val, dest);
1478}
1479
1480#endif