RDMA/hns: Add SCC context clr support for hip08
[linux-block.git] / drivers / infiniband / hw / hns / hns_roce_device.h
CommitLineData
9a443537 1/*
2 * Copyright (c) 2016 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_DEVICE_H
34#define _HNS_ROCE_DEVICE_H
35
36#include <rdma/ib_verbs.h>
37
38#define DRV_NAME "hns_roce"
39
8f3e9f3e
WHX
40#define HNS_ROCE_HW_VER1 ('h' << 24 | 'i' << 16 | '0' << 8 | '6')
41
9a443537 42#define MAC_ADDR_OCTET_NUM 6
43#define HNS_ROCE_MAX_MSG_LEN 0x80000000
44
45#define HNS_ROCE_ALOGN_UP(a, b) ((((a) + (b) - 1) / (b)) * (b))
46
47#define HNS_ROCE_IB_MIN_SQ_STRIDE 6
48
49#define HNS_ROCE_BA_SIZE (32 * 4096)
50
51/* Hardware specification only for v1 engine */
52#define HNS_ROCE_MIN_CQE_NUM 0x40
53#define HNS_ROCE_MIN_WQE_NUM 0x20
54
55/* Hardware specification only for v1 engine */
56#define HNS_ROCE_MAX_INNER_MTPT_NUM 0x7
57#define HNS_ROCE_MAX_MTPT_PBL_NUM 0x100000
58
afb6b092
SX
59#define HNS_ROCE_EACH_FREE_CQ_WAIT_MSECS 20
60#define HNS_ROCE_MAX_FREE_CQ_WAIT_CNT \
61 (5000 / HNS_ROCE_EACH_FREE_CQ_WAIT_MSECS)
62#define HNS_ROCE_CQE_WCMD_EMPTY_BIT 0x2
63#define HNS_ROCE_MIN_CQE_CNT 16
64
b16f8188 65#define HNS_ROCE_MAX_IRQ_NUM 128
9a443537 66
b16f8188
YL
67#define EQ_ENABLE 1
68#define EQ_DISABLE 0
9a443537 69
b16f8188
YL
70#define HNS_ROCE_CEQ 0
71#define HNS_ROCE_AEQ 1
72
73#define HNS_ROCE_CEQ_ENTRY_SIZE 0x4
74#define HNS_ROCE_AEQ_ENTRY_SIZE 0x10
9a443537 75
76/* 4G/4K = 1M */
ac11125b 77#define HNS_ROCE_SL_SHIFT 28
9a443537 78#define HNS_ROCE_TCLASS_SHIFT 20
cdfa4ad5 79#define HNS_ROCE_FLOW_LABEL_MASK 0xfffff
9a443537 80
81#define HNS_ROCE_MAX_PORTS 6
82#define HNS_ROCE_MAX_GID_NUM 16
83#define HNS_ROCE_GID_SIZE 16
84
a25d13cb
SX
85#define HNS_ROCE_HOP_NUM_0 0xff
86
5e6ff78a
WHX
87#define BITMAP_NO_RR 0
88#define BITMAP_RR 1
89
9a443537 90#define MR_TYPE_MR 0x00
68a997c5 91#define MR_TYPE_FRMR 0x01
9a443537 92#define MR_TYPE_DMA 0x03
93
68a997c5
YL
94#define HNS_ROCE_FRMR_MAX_PA 512
95
9a443537 96#define PKEY_ID 0xffff
31644665 97#define GUID_LEN 8
9a443537 98#define NODE_DESC_SIZE 64
509bf0c2 99#define DB_REG_OFFSET 0x1000
9a443537 100
101#define SERV_TYPE_RC 0
102#define SERV_TYPE_RD 1
103#define SERV_TYPE_UC 2
104#define SERV_TYPE_UD 3
105
5e6e78db
YL
106/* Configure to HW for PAGE_SIZE larger than 4KB */
107#define PG_SHIFT_OFFSET (PAGE_SHIFT - 12)
108
9a443537 109#define PAGES_SHIFT_8 8
110#define PAGES_SHIFT_16 16
111#define PAGES_SHIFT_24 24
112#define PAGES_SHIFT_32 32
113
c7bcb134
LO
114#define HNS_ROCE_IDX_QUE_ENTRY_SZ 4
115#define SRQ_DB_REG 0x230
116
e088a685
YL
117enum {
118 HNS_ROCE_SUPPORT_RQ_RECORD_DB = 1 << 0,
0425e3e6 119 HNS_ROCE_SUPPORT_SQ_RECORD_DB = 1 << 1,
e088a685
YL
120};
121
9b44703d
YL
122enum {
123 HNS_ROCE_SUPPORT_CQ_RECORD_DB = 1 << 0,
124};
125
9a443537 126enum hns_roce_qp_state {
127 HNS_ROCE_QP_STATE_RST,
128 HNS_ROCE_QP_STATE_INIT,
129 HNS_ROCE_QP_STATE_RTR,
130 HNS_ROCE_QP_STATE_RTS,
131 HNS_ROCE_QP_STATE_SQD,
132 HNS_ROCE_QP_STATE_ERR,
133 HNS_ROCE_QP_NUM_STATE,
134};
135
136enum hns_roce_event {
137 HNS_ROCE_EVENT_TYPE_PATH_MIG = 0x01,
138 HNS_ROCE_EVENT_TYPE_PATH_MIG_FAILED = 0x02,
139 HNS_ROCE_EVENT_TYPE_COMM_EST = 0x03,
140 HNS_ROCE_EVENT_TYPE_SQ_DRAINED = 0x04,
141 HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
142 HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR = 0x06,
143 HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR = 0x07,
144 HNS_ROCE_EVENT_TYPE_SRQ_LIMIT_REACH = 0x08,
145 HNS_ROCE_EVENT_TYPE_SRQ_LAST_WQE_REACH = 0x09,
146 HNS_ROCE_EVENT_TYPE_SRQ_CATAS_ERROR = 0x0a,
147 HNS_ROCE_EVENT_TYPE_CQ_ACCESS_ERROR = 0x0b,
148 HNS_ROCE_EVENT_TYPE_CQ_OVERFLOW = 0x0c,
149 HNS_ROCE_EVENT_TYPE_CQ_ID_INVALID = 0x0d,
150 HNS_ROCE_EVENT_TYPE_PORT_CHANGE = 0x0f,
151 /* 0x10 and 0x11 is unused in currently application case */
152 HNS_ROCE_EVENT_TYPE_DB_OVERFLOW = 0x12,
153 HNS_ROCE_EVENT_TYPE_MB = 0x13,
154 HNS_ROCE_EVENT_TYPE_CEQ_OVERFLOW = 0x14,
a5073d60 155 HNS_ROCE_EVENT_TYPE_FLR = 0x15,
9a443537 156};
157
158/* Local Work Queue Catastrophic Error,SUBTYPE 0x5 */
159enum {
160 HNS_ROCE_LWQCE_QPC_ERROR = 1,
161 HNS_ROCE_LWQCE_MTU_ERROR = 2,
162 HNS_ROCE_LWQCE_WQE_BA_ADDR_ERROR = 3,
163 HNS_ROCE_LWQCE_WQE_ADDR_ERROR = 4,
164 HNS_ROCE_LWQCE_SQ_WQE_SHIFT_ERROR = 5,
165 HNS_ROCE_LWQCE_SL_ERROR = 6,
166 HNS_ROCE_LWQCE_PORT_ERROR = 7,
167};
168
169/* Local Access Violation Work Queue Error,SUBTYPE 0x7 */
170enum {
171 HNS_ROCE_LAVWQE_R_KEY_VIOLATION = 1,
172 HNS_ROCE_LAVWQE_LENGTH_ERROR = 2,
173 HNS_ROCE_LAVWQE_VA_ERROR = 3,
174 HNS_ROCE_LAVWQE_PD_ERROR = 4,
175 HNS_ROCE_LAVWQE_RW_ACC_ERROR = 5,
176 HNS_ROCE_LAVWQE_KEY_STATE_ERROR = 6,
177 HNS_ROCE_LAVWQE_MR_OPERATION_ERROR = 7,
178};
179
180/* DOORBELL overflow subtype */
181enum {
182 HNS_ROCE_DB_SUBTYPE_SDB_OVF = 1,
183 HNS_ROCE_DB_SUBTYPE_SDB_ALM_OVF = 2,
184 HNS_ROCE_DB_SUBTYPE_ODB_OVF = 3,
185 HNS_ROCE_DB_SUBTYPE_ODB_ALM_OVF = 4,
186 HNS_ROCE_DB_SUBTYPE_SDB_ALM_EMP = 5,
187 HNS_ROCE_DB_SUBTYPE_ODB_ALM_EMP = 6,
188};
189
190enum {
191 /* RQ&SRQ related operations */
192 HNS_ROCE_OPCODE_SEND_DATA_RECEIVE = 0x06,
193 HNS_ROCE_OPCODE_RDMA_WITH_IMM_RECEIVE = 0x07,
194};
195
a2c80b7b
WHX
196enum {
197 HNS_ROCE_CAP_FLAG_REREG_MR = BIT(0),
023c1477 198 HNS_ROCE_CAP_FLAG_ROCE_V1_V2 = BIT(1),
e088a685 199 HNS_ROCE_CAP_FLAG_RQ_INLINE = BIT(2),
0425e3e6
YL
200 HNS_ROCE_CAP_FLAG_RECORD_DB = BIT(3),
201 HNS_ROCE_CAP_FLAG_SQ_RECORD_DB = BIT(4),
d16da119 202 HNS_ROCE_CAP_FLAG_SRQ = BIT(5),
c7c28191 203 HNS_ROCE_CAP_FLAG_MW = BIT(7),
68a997c5 204 HNS_ROCE_CAP_FLAG_FRMR = BIT(8),
aa84fa18 205 HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL = BIT(9),
384f8818 206 HNS_ROCE_CAP_FLAG_ATOMIC = BIT(10),
a2c80b7b
WHX
207};
208
9766edc3 209enum hns_roce_mtt_type {
400d324a 210 MTT_TYPE_WQE,
9766edc3 211 MTT_TYPE_CQE,
5c1f167a
LO
212 MTT_TYPE_SRQWQE,
213 MTT_TYPE_IDX
9766edc3
SX
214};
215
e088a685
YL
216enum {
217 HNS_ROCE_DB_PER_PAGE = PAGE_SIZE / 4
218};
219
9a443537 220#define HNS_ROCE_CMD_SUCCESS 1
221
222#define HNS_ROCE_PORT_DOWN 0
223#define HNS_ROCE_PORT_UP 1
224
225#define HNS_ROCE_MTT_ENTRY_PER_SEG 8
226
227#define PAGE_ADDR_SHIFT 12
228
229struct hns_roce_uar {
230 u64 pfn;
231 unsigned long index;
5b6eb54f 232 unsigned long logic_idx;
9a443537 233};
234
235struct hns_roce_ucontext {
236 struct ib_ucontext ibucontext;
237 struct hns_roce_uar uar;
e088a685
YL
238 struct list_head page_list;
239 struct mutex page_mutex;
9a443537 240};
241
242struct hns_roce_pd {
243 struct ib_pd ibpd;
244 unsigned long pdn;
245};
246
247struct hns_roce_bitmap {
248 /* Bitmap Traversal last a bit which is 1 */
249 unsigned long last;
250 unsigned long top;
251 unsigned long max;
252 unsigned long reserved_top;
253 unsigned long mask;
254 spinlock_t lock;
255 unsigned long *table;
256};
257
258/* Order bitmap length -- bit num compute formula: 1 << (max_order - order) */
259/* Order = 0: bitmap is biggest, order = max bitmap is least (only a bit) */
260/* Every bit repesent to a partner free/used status in bitmap */
261/*
e84e40be
S
262 * Initial, bits of other bitmap are all 0 except that a bit of max_order is 1
263 * Bit = 1 represent to idle and available; bit = 0: not available
264 */
9a443537 265struct hns_roce_buddy {
266 /* Members point to every order level bitmap */
267 unsigned long **bits;
268 /* Represent to avail bits of the order level bitmap */
269 u32 *num_free;
270 int max_order;
271 spinlock_t lock;
272};
273
274/* For Hardware Entry Memory */
275struct hns_roce_hem_table {
276 /* HEM type: 0 = qpc, 1 = mtt, 2 = cqc, 3 = srq, 4 = other */
277 u32 type;
278 /* HEM array elment num */
279 unsigned long num_hem;
280 /* HEM entry record obj total num */
281 unsigned long num_obj;
282 /*Single obj size */
283 unsigned long obj_size;
29a1fe5d 284 unsigned long table_chunk_size;
9a443537 285 int lowmem;
286 struct mutex mutex;
287 struct hns_roce_hem **hem;
a25d13cb
SX
288 u64 **bt_l1;
289 dma_addr_t *bt_l1_dma_addr;
290 u64 **bt_l0;
291 dma_addr_t *bt_l0_dma_addr;
9a443537 292};
293
294struct hns_roce_mtt {
9766edc3
SX
295 unsigned long first_seg;
296 int order;
297 int page_shift;
298 enum hns_roce_mtt_type mtt_type;
9a443537 299};
300
c7c28191
YL
301struct hns_roce_mw {
302 struct ib_mw ibmw;
303 u32 pdn;
304 u32 rkey;
305 int enabled; /* MW's active status */
306 u32 pbl_hop_num;
307 u32 pbl_ba_pg_sz;
308 u32 pbl_buf_pg_sz;
309};
310
9a443537 311/* Only support 4K page size for mr register */
312#define MR_SIZE_4K 0
313
314struct hns_roce_mr {
315 struct ib_mr ibmr;
316 struct ib_umem *umem;
317 u64 iova; /* MR's virtual orignal addr */
318 u64 size; /* Address range of MR */
319 u32 key; /* Key of MR */
320 u32 pd; /* PD num of MR */
321 u32 access;/* Access permission of MR */
68a997c5 322 u32 npages;
9a443537 323 int enabled; /* MR's active status */
324 int type; /* MR's register type */
325 u64 *pbl_buf;/* MR's PBL space */
326 dma_addr_t pbl_dma_addr; /* MR's PBL space PA */
ff795f71
WHX
327 u32 pbl_size;/* PA number in the PBL */
328 u64 pbl_ba;/* page table address */
329 u32 l0_chunk_last_num;/* L0 last number */
330 u32 l1_chunk_last_num;/* L1 last number */
331 u64 **pbl_bt_l2;/* PBL BT L2 */
332 u64 **pbl_bt_l1;/* PBL BT L1 */
333 u64 *pbl_bt_l0;/* PBL BT L0 */
334 dma_addr_t *pbl_l2_dma_addr;/* PBL BT L2 dma addr */
335 dma_addr_t *pbl_l1_dma_addr;/* PBL BT L1 dma addr */
336 dma_addr_t pbl_l0_dma_addr;/* PBL BT L0 dma addr */
337 u32 pbl_ba_pg_sz;/* BT chunk page size */
338 u32 pbl_buf_pg_sz;/* buf chunk page size */
339 u32 pbl_hop_num;/* multi-hop number */
9a443537 340};
341
342struct hns_roce_mr_table {
343 struct hns_roce_bitmap mtpt_bitmap;
344 struct hns_roce_buddy mtt_buddy;
345 struct hns_roce_hem_table mtt_table;
346 struct hns_roce_hem_table mtpt_table;
9766edc3
SX
347 struct hns_roce_buddy mtt_cqe_buddy;
348 struct hns_roce_hem_table mtt_cqe_table;
5c1f167a
LO
349 struct hns_roce_buddy mtt_srqwqe_buddy;
350 struct hns_roce_hem_table mtt_srqwqe_table;
351 struct hns_roce_buddy mtt_idx_buddy;
352 struct hns_roce_hem_table mtt_idx_table;
9a443537 353};
354
355struct hns_roce_wq {
356 u64 *wrid; /* Work request ID */
357 spinlock_t lock;
358 int wqe_cnt; /* WQE num */
359 u32 max_post;
360 int max_gs;
361 int offset;
362 int wqe_shift;/* WQE size */
363 u32 head;
364 u32 tail;
365 void __iomem *db_reg_l;
366};
367
926a01dc
WHX
368struct hns_roce_sge {
369 int sge_cnt; /* SGE num */
370 int offset;
371 int sge_shift;/* SGE size */
372};
373
9a443537 374struct hns_roce_buf_list {
375 void *buf;
376 dma_addr_t map;
377};
378
379struct hns_roce_buf {
380 struct hns_roce_buf_list direct;
381 struct hns_roce_buf_list *page_list;
382 int nbufs;
383 u32 npages;
384 int page_shift;
385};
386
e088a685
YL
387struct hns_roce_db_pgdir {
388 struct list_head list;
389 DECLARE_BITMAP(order0, HNS_ROCE_DB_PER_PAGE);
390 DECLARE_BITMAP(order1, HNS_ROCE_DB_PER_PAGE / 2);
391 unsigned long *bits[2];
392 u32 *page;
393 dma_addr_t db_dma;
394};
395
396struct hns_roce_user_db_page {
397 struct list_head list;
398 struct ib_umem *umem;
399 unsigned long user_virt;
400 refcount_t refcount;
401};
402
403struct hns_roce_db {
404 u32 *db_record;
405 union {
406 struct hns_roce_db_pgdir *pgdir;
407 struct hns_roce_user_db_page *user_page;
408 } u;
409 dma_addr_t dma;
0425e3e6 410 void *virt_addr;
e088a685
YL
411 int index;
412 int order;
413};
414
9a443537 415struct hns_roce_cq_buf {
416 struct hns_roce_buf hr_buf;
417 struct hns_roce_mtt hr_mtt;
418};
419
9a443537 420struct hns_roce_cq {
421 struct ib_cq ib_cq;
422 struct hns_roce_cq_buf hr_buf;
9b44703d
YL
423 struct hns_roce_db db;
424 u8 db_en;
9a443537 425 spinlock_t lock;
9a443537 426 struct ib_umem *umem;
fd012f1c 427 void (*comp)(struct hns_roce_cq *cq);
428 void (*event)(struct hns_roce_cq *cq, enum hns_roce_event event_type);
9a443537 429
430 struct hns_roce_uar *uar;
431 u32 cq_depth;
432 u32 cons_index;
86188a88 433 u32 *set_ci_db;
9a443537 434 void __iomem *cq_db_l;
8f3e9f3e 435 u16 *tptr_addr;
26beb85f 436 int arm_sn;
9a443537 437 unsigned long cqn;
438 u32 vector;
439 atomic_t refcount;
440 struct completion free;
441};
442
c7bcb134
LO
443struct hns_roce_idx_que {
444 struct hns_roce_buf idx_buf;
445 int entry_sz;
446 u32 buf_size;
447 struct ib_umem *umem;
448 struct hns_roce_mtt mtt;
449 u64 *bitmap;
450};
451
9a443537 452struct hns_roce_srq {
453 struct ib_srq ibsrq;
c7bcb134
LO
454 void (*event)(struct hns_roce_srq *srq, enum hns_roce_event event);
455 unsigned long srqn;
456 int max;
457 int max_gs;
458 int wqe_shift;
459 void __iomem *db_reg_l;
460
461 atomic_t refcount;
462 struct completion free;
463
464 struct hns_roce_buf buf;
465 u64 *wrid;
466 struct ib_umem *umem;
467 struct hns_roce_mtt mtt;
468 struct hns_roce_idx_que idx_que;
469 spinlock_t lock;
470 int head;
471 int tail;
472 u16 wqe_ctr;
473 struct mutex mutex;
9a443537 474};
475
476struct hns_roce_uar_table {
477 struct hns_roce_bitmap bitmap;
478};
479
480struct hns_roce_qp_table {
481 struct hns_roce_bitmap bitmap;
482 spinlock_t lock;
483 struct hns_roce_hem_table qp_table;
484 struct hns_roce_hem_table irrl_table;
e92f2c18 485 struct hns_roce_hem_table trrl_table;
6a157f7d 486 struct hns_roce_hem_table sccc_table;
aa84fa18 487 struct mutex scc_mutex;
9a443537 488};
489
490struct hns_roce_cq_table {
491 struct hns_roce_bitmap bitmap;
492 spinlock_t lock;
493 struct radix_tree_root tree;
494 struct hns_roce_hem_table table;
495};
496
5c1f167a
LO
497struct hns_roce_srq_table {
498 struct hns_roce_bitmap bitmap;
499 struct xarray xa;
500 struct hns_roce_hem_table table;
501};
502
9a443537 503struct hns_roce_raq_table {
504 struct hns_roce_buf_list *e_raq_buf;
505};
506
507struct hns_roce_av {
508 __le32 port_pd;
509 u8 gid_index;
510 u8 stat_rate;
511 u8 hop_limit;
512 __le32 sl_tclass_flowlabel;
513 u8 dgid[HNS_ROCE_GID_SIZE];
514 u8 mac[6];
515 __le16 vlan;
8320deb8 516 bool vlan_en;
9a443537 517};
518
519struct hns_roce_ah {
520 struct ib_ah ibah;
521 struct hns_roce_av av;
522};
523
524struct hns_roce_cmd_context {
525 struct completion done;
526 int result;
527 int next;
528 u64 out_param;
529 u16 token;
530};
531
532struct hns_roce_cmdq {
533 struct dma_pool *pool;
9a443537 534 struct mutex hcr_mutex;
535 struct semaphore poll_sem;
536 /*
e84e40be
S
537 * Event mode: cmd register mutex protection,
538 * ensure to not exceed max_cmds and user use limit region
539 */
9a443537 540 struct semaphore event_sem;
541 int max_cmds;
542 spinlock_t context_lock;
543 int free_head;
544 struct hns_roce_cmd_context *context;
545 /*
e84e40be
S
546 * Result of get integer part
547 * which max_comds compute according a power of 2
548 */
9a443537 549 u16 token_mask;
550 /*
e84e40be
S
551 * Process whether use event mode, init default non-zero
552 * After the event queue of cmd event ready,
553 * can switch into event mode
554 * close device, switch into poll mode(non event mode)
555 */
9a443537 556 u8 use_events;
557 u8 toggle;
558};
559
bfcc681b
SX
560struct hns_roce_cmd_mailbox {
561 void *buf;
562 dma_addr_t dma;
563};
564
9a443537 565struct hns_roce_dev;
566
0009c2db 567struct hns_roce_rinl_sge {
568 void *addr;
569 u32 len;
570};
571
572struct hns_roce_rinl_wqe {
573 struct hns_roce_rinl_sge *sg_list;
574 u32 sge_cnt;
575};
576
577struct hns_roce_rinl_buf {
578 struct hns_roce_rinl_wqe *wqe_list;
579 u32 wqe_cnt;
580};
581
9a443537 582struct hns_roce_qp {
583 struct ib_qp ibqp;
584 struct hns_roce_buf hr_buf;
585 struct hns_roce_wq rq;
e088a685 586 struct hns_roce_db rdb;
0425e3e6 587 struct hns_roce_db sdb;
e088a685 588 u8 rdb_en;
0425e3e6 589 u8 sdb_en;
8b9b8d14 590 u32 doorbell_qpn;
9a443537 591 __le32 sq_signal_bits;
592 u32 sq_next_wqe;
593 int sq_max_wqes_per_wr;
594 int sq_spare_wqes;
595 struct hns_roce_wq sq;
596
597 struct ib_umem *umem;
598 struct hns_roce_mtt mtt;
599 u32 buff_size;
600 struct mutex mutex;
601 u8 port;
7716809e 602 u8 phy_port;
9a443537 603 u8 sl;
604 u8 resp_depth;
605 u8 state;
606 u32 access_flags;
ace1c541 607 u32 atomic_rd_en;
9a443537 608 u32 pkey_index;
0fa95a9a 609 u32 qkey;
fd012f1c 610 void (*event)(struct hns_roce_qp *qp,
611 enum hns_roce_event event_type);
9a443537 612 unsigned long qpn;
613
614 atomic_t refcount;
615 struct completion free;
926a01dc
WHX
616
617 struct hns_roce_sge sge;
618 u32 next_sge;
0009c2db 619
620 struct hns_roce_rinl_buf rq_inl_buf;
9a443537 621};
622
623struct hns_roce_sqp {
624 struct hns_roce_qp hr_qp;
625};
626
627struct hns_roce_ib_iboe {
628 spinlock_t lock;
629 struct net_device *netdevs[HNS_ROCE_MAX_PORTS];
630 struct notifier_block nb;
9a443537 631 u8 phy_port[HNS_ROCE_MAX_PORTS];
632};
633
b16f8188
YL
634enum {
635 HNS_ROCE_EQ_STAT_INVALID = 0,
636 HNS_ROCE_EQ_STAT_VALID = 2,
637};
638
639struct hns_roce_ceqe {
640 u32 comp;
641};
642
643struct hns_roce_aeqe {
0576cbde 644 __le32 asyn;
b16f8188
YL
645 union {
646 struct {
0576cbde 647 __le32 qp;
b16f8188
YL
648 u32 rsv0;
649 u32 rsv1;
650 } qp_event;
651
81fce629
LO
652 struct {
653 __le32 srq;
654 u32 rsv0;
655 u32 rsv1;
656 } srq_event;
657
b16f8188 658 struct {
0576cbde 659 __le32 cq;
b16f8188
YL
660 u32 rsv0;
661 u32 rsv1;
662 } cq_event;
663
664 struct {
0576cbde 665 __le32 ceqe;
b16f8188
YL
666 u32 rsv0;
667 u32 rsv1;
668 } ce_event;
669
670 struct {
671 __le64 out_param;
672 __le16 token;
673 u8 status;
674 u8 rsv0;
675 } __packed cmd;
676 } event;
677};
678
9a443537 679struct hns_roce_eq {
680 struct hns_roce_dev *hr_dev;
681 void __iomem *doorbell;
682
683 int type_flag;/* Aeq:1 ceq:0 */
684 int eqn;
685 u32 entries;
686 int log_entries;
687 int eqe_size;
688 int irq;
689 int log_page_size;
690 int cons_index;
691 struct hns_roce_buf_list *buf_list;
a5073d60
YL
692 int over_ignore;
693 int coalesce;
694 int arm_st;
695 u64 eqe_ba;
696 int eqe_ba_pg_sz;
697 int eqe_buf_pg_sz;
698 int hop_num;
699 u64 *bt_l0; /* Base address table for L0 */
700 u64 **bt_l1; /* Base address table for L1 */
701 u64 **buf;
702 dma_addr_t l0_dma;
703 dma_addr_t *l1_dma;
704 dma_addr_t *buf_dma;
705 u32 l0_last_num; /* L0 last chunk num */
706 u32 l1_last_num; /* L1 last chunk num */
707 int eq_max_cnt;
708 int eq_period;
709 int shift;
710 dma_addr_t cur_eqe_ba;
711 dma_addr_t nxt_eqe_ba;
0425e3e6
YL
712 int event_type;
713 int sub_type;
9a443537 714};
715
716struct hns_roce_eq_table {
717 struct hns_roce_eq *eq;
b16f8188 718 void __iomem **eqc_base; /* only for hw v1 */
9a443537 719};
720
721struct hns_roce_caps {
3a63c964 722 u64 fw_ver;
9a443537 723 u8 num_ports;
724 int gid_table_len[HNS_ROCE_MAX_PORTS];
725 int pkey_table_len[HNS_ROCE_MAX_PORTS];
726 int local_ca_ack_delay;
727 int num_uars;
728 u32 phy_num_uars;
729 u32 max_sq_sg; /* 2 */
730 u32 max_sq_inline; /* 32 */
731 u32 max_rq_sg; /* 2 */
05ad5482 732 u32 max_extend_sg;
9a443537 733 int num_qps; /* 256k */
06ef0ee4 734 int reserved_qps;
5c1f167a
LO
735 u32 max_srq_sg;
736 int num_srqs;
9a443537 737 u32 max_wqes; /* 16k */
d16da119
LO
738 u32 max_srqs;
739 u32 max_srq_wrs;
740 u32 max_srq_sges;
9a443537 741 u32 max_sq_desc_sz; /* 64 */
742 u32 max_rq_desc_sz; /* 64 */
cfc85f3e 743 u32 max_srq_desc_sz;
9a443537 744 int max_qp_init_rdma;
745 int max_qp_dest_rdma;
9a443537 746 int num_cqs;
747 int max_cqes;
93aa2187 748 int min_cqes;
926a01dc 749 u32 min_wqes;
9a443537 750 int reserved_cqs;
5c1f167a
LO
751 int reserved_srqs;
752 u32 max_srqwqes;
9a443537 753 int num_aeq_vectors; /* 1 */
a5073d60 754 int num_comp_vectors;
9a443537 755 int num_other_vectors;
756 int num_mtpts;
757 u32 num_mtt_segs;
cfc85f3e 758 u32 num_cqe_segs;
5c1f167a
LO
759 u32 num_srqwqe_segs;
760 u32 num_idx_segs;
9a443537 761 int reserved_mrws;
762 int reserved_uars;
763 int num_pds;
764 int reserved_pds;
765 u32 mtt_entry_sz;
766 u32 cq_entry_sz;
767 u32 page_size_cap;
768 u32 reserved_lkey;
769 int mtpt_entry_sz;
770 int qpc_entry_sz;
771 int irrl_entry_sz;
e92f2c18 772 int trrl_entry_sz;
9a443537 773 int cqc_entry_sz;
6a157f7d 774 int sccc_entry_sz;
5c1f167a
LO
775 int srqc_entry_sz;
776 int idx_entry_sz;
ff795f71
WHX
777 u32 pbl_ba_pg_sz;
778 u32 pbl_buf_pg_sz;
779 u32 pbl_hop_num;
9a443537 780 int aeqe_depth;
b16f8188 781 int ceqe_depth;
9a443537 782 enum ib_mtu max_mtu;
cfc85f3e
WHX
783 u32 qpc_bt_num;
784 u32 srqc_bt_num;
785 u32 cqc_bt_num;
786 u32 mpt_bt_num;
6a157f7d 787 u32 sccc_bt_num;
a25d13cb
SX
788 u32 qpc_ba_pg_sz;
789 u32 qpc_buf_pg_sz;
790 u32 qpc_hop_num;
791 u32 srqc_ba_pg_sz;
792 u32 srqc_buf_pg_sz;
793 u32 srqc_hop_num;
794 u32 cqc_ba_pg_sz;
795 u32 cqc_buf_pg_sz;
796 u32 cqc_hop_num;
797 u32 mpt_ba_pg_sz;
798 u32 mpt_buf_pg_sz;
799 u32 mpt_hop_num;
6a93c77a
SX
800 u32 mtt_ba_pg_sz;
801 u32 mtt_buf_pg_sz;
802 u32 mtt_hop_num;
6a157f7d
YL
803 u32 sccc_ba_pg_sz;
804 u32 sccc_buf_pg_sz;
805 u32 sccc_hop_num;
6a93c77a
SX
806 u32 cqe_ba_pg_sz;
807 u32 cqe_buf_pg_sz;
808 u32 cqe_hop_num;
c7bcb134
LO
809 u32 srqwqe_ba_pg_sz;
810 u32 srqwqe_buf_pg_sz;
811 u32 srqwqe_hop_num;
812 u32 idx_ba_pg_sz;
813 u32 idx_buf_pg_sz;
814 u32 idx_hop_num;
a5073d60
YL
815 u32 eqe_ba_pg_sz;
816 u32 eqe_buf_pg_sz;
817 u32 eqe_hop_num;
6b63597d 818 u32 sl_num;
819 u32 tsq_buf_pg_sz;
ded58ff9 820 u32 tpq_buf_pg_sz;
29a1fe5d 821 u32 chunk_sz; /* chunk size in non multihop mode*/
a2c80b7b 822 u64 flags;
9a443537 823};
824
0425e3e6
YL
825struct hns_roce_work {
826 struct hns_roce_dev *hr_dev;
827 struct work_struct work;
828 u32 qpn;
b00a92c8 829 u32 cqn;
0425e3e6
YL
830 int event_type;
831 int sub_type;
832};
833
9a443537 834struct hns_roce_hw {
835 int (*reset)(struct hns_roce_dev *hr_dev, bool enable);
a04ff739
WHX
836 int (*cmq_init)(struct hns_roce_dev *hr_dev);
837 void (*cmq_exit)(struct hns_roce_dev *hr_dev);
cfc85f3e 838 int (*hw_profile)(struct hns_roce_dev *hr_dev);
9a443537 839 int (*hw_init)(struct hns_roce_dev *hr_dev);
840 void (*hw_exit)(struct hns_roce_dev *hr_dev);
a680f2f3
WHX
841 int (*post_mbox)(struct hns_roce_dev *hr_dev, u64 in_param,
842 u64 out_param, u32 in_modifier, u8 op_modifier, u16 op,
843 u16 token, int event);
844 int (*chk_mbox)(struct hns_roce_dev *hr_dev, unsigned long timeout);
b5ff0f61 845 int (*set_gid)(struct hns_roce_dev *hr_dev, u8 port, int gid_index,
f4df9a7c 846 const union ib_gid *gid, const struct ib_gid_attr *attr);
a74dc41d 847 int (*set_mac)(struct hns_roce_dev *hr_dev, u8 phy_port, u8 *addr);
9a443537 848 void (*set_mtu)(struct hns_roce_dev *hr_dev, u8 phy_port,
849 enum ib_mtu mtu);
850 int (*write_mtpt)(void *mb_buf, struct hns_roce_mr *mr,
851 unsigned long mtpt_idx);
a2c80b7b
WHX
852 int (*rereg_write_mtpt)(struct hns_roce_dev *hr_dev,
853 struct hns_roce_mr *mr, int flags, u32 pdn,
854 int mr_access_flags, u64 iova, u64 size,
855 void *mb_buf);
68a997c5 856 int (*frmr_write_mtpt)(void *mb_buf, struct hns_roce_mr *mr);
c7c28191 857 int (*mw_write_mtpt)(void *mb_buf, struct hns_roce_mw *mw);
9a443537 858 void (*write_cqc)(struct hns_roce_dev *hr_dev,
859 struct hns_roce_cq *hr_cq, void *mb_buf, u64 *mtts,
860 dma_addr_t dma_handle, int nent, u32 vector);
a25d13cb
SX
861 int (*set_hem)(struct hns_roce_dev *hr_dev,
862 struct hns_roce_hem_table *table, int obj, int step_idx);
97f0e39f 863 int (*clear_hem)(struct hns_roce_dev *hr_dev,
a25d13cb
SX
864 struct hns_roce_hem_table *table, int obj,
865 int step_idx);
9a443537 866 int (*query_qp)(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
867 int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
868 int (*modify_qp)(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
869 int attr_mask, enum ib_qp_state cur_state,
870 enum ib_qp_state new_state);
871 int (*destroy_qp)(struct ib_qp *ibqp);
aa84fa18
YL
872 int (*qp_flow_control_init)(struct hns_roce_dev *hr_dev,
873 struct hns_roce_qp *hr_qp);
d34ac5cd
BVA
874 int (*post_send)(struct ib_qp *ibqp, const struct ib_send_wr *wr,
875 const struct ib_send_wr **bad_wr);
876 int (*post_recv)(struct ib_qp *qp, const struct ib_recv_wr *recv_wr,
877 const struct ib_recv_wr **bad_recv_wr);
9a443537 878 int (*req_notify_cq)(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
879 int (*poll_cq)(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
bfcc681b 880 int (*dereg_mr)(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr);
afb6b092 881 int (*destroy_cq)(struct ib_cq *ibcq);
b156269d 882 int (*modify_cq)(struct ib_cq *cq, u16 cq_count, u16 cq_period);
b16f8188
YL
883 int (*init_eq)(struct hns_roce_dev *hr_dev);
884 void (*cleanup_eq)(struct hns_roce_dev *hr_dev);
c7bcb134
LO
885 void (*write_srqc)(struct hns_roce_dev *hr_dev,
886 struct hns_roce_srq *srq, u32 pdn, u16 xrcd, u32 cqn,
887 void *mb_buf, u64 *mtts_wqe, u64 *mtts_idx,
888 dma_addr_t dma_handle_wqe,
889 dma_addr_t dma_handle_idx);
890 int (*modify_srq)(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr,
891 enum ib_srq_attr_mask srq_attr_mask,
892 struct ib_udata *udata);
893 int (*query_srq)(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
894 int (*post_srq_recv)(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
895 const struct ib_recv_wr **bad_wr);
7f645a58
KH
896 const struct ib_device_ops *hns_roce_dev_ops;
897 const struct ib_device_ops *hns_roce_dev_srq_ops;
9a443537 898};
899
900struct hns_roce_dev {
901 struct ib_device ib_dev;
902 struct platform_device *pdev;
dd74282d
WHX
903 struct pci_dev *pci_dev;
904 struct device *dev;
9a443537 905 struct hns_roce_uar priv_uar;
528f1deb 906 const char *irq_names[HNS_ROCE_MAX_IRQ_NUM];
9a443537 907 spinlock_t sm_lock;
9a443537 908 spinlock_t bt_cmd_lock;
cb7a94c9
WHX
909 bool active;
910 bool is_reset;
9a443537 911 struct hns_roce_ib_iboe iboe;
912
472bc0fb
YL
913 struct list_head pgdir_list;
914 struct mutex pgdir_mutex;
9a443537 915 int irq[HNS_ROCE_MAX_IRQ_NUM];
916 u8 __iomem *reg_base;
917 struct hns_roce_caps caps;
918 struct radix_tree_root qp_table_tree;
919
920 unsigned char dev_addr[HNS_ROCE_MAX_PORTS][MAC_ADDR_OCTET_NUM];
921 u64 sys_image_guid;
922 u32 vendor_id;
923 u32 vendor_part_id;
924 u32 hw_rev;
925 void __iomem *priv_addr;
926
927 struct hns_roce_cmdq cmd;
928 struct hns_roce_bitmap pd_bitmap;
929 struct hns_roce_uar_table uar_table;
930 struct hns_roce_mr_table mr_table;
931 struct hns_roce_cq_table cq_table;
5c1f167a 932 struct hns_roce_srq_table srq_table;
9a443537 933 struct hns_roce_qp_table qp_table;
934 struct hns_roce_eq_table eq_table;
935
936 int cmd_mod;
937 int loop_idc;
2d407888
WHX
938 u32 sdb_offset;
939 u32 odb_offset;
8f3e9f3e
WHX
940 dma_addr_t tptr_dma_addr; /*only for hw v1*/
941 u32 tptr_size; /*only for hw v1*/
08805fdb 942 const struct hns_roce_hw *hw;
016a0059 943 void *priv;
0425e3e6 944 struct workqueue_struct *irq_workq;
9a443537 945};
946
947static inline struct hns_roce_dev *to_hr_dev(struct ib_device *ib_dev)
948{
949 return container_of(ib_dev, struct hns_roce_dev, ib_dev);
950}
951
952static inline struct hns_roce_ucontext
953 *to_hr_ucontext(struct ib_ucontext *ibucontext)
954{
955 return container_of(ibucontext, struct hns_roce_ucontext, ibucontext);
956}
957
958static inline struct hns_roce_pd *to_hr_pd(struct ib_pd *ibpd)
959{
960 return container_of(ibpd, struct hns_roce_pd, ibpd);
961}
962
963static inline struct hns_roce_ah *to_hr_ah(struct ib_ah *ibah)
964{
965 return container_of(ibah, struct hns_roce_ah, ibah);
966}
967
968static inline struct hns_roce_mr *to_hr_mr(struct ib_mr *ibmr)
969{
970 return container_of(ibmr, struct hns_roce_mr, ibmr);
971}
972
c7c28191
YL
973static inline struct hns_roce_mw *to_hr_mw(struct ib_mw *ibmw)
974{
975 return container_of(ibmw, struct hns_roce_mw, ibmw);
976}
977
9a443537 978static inline struct hns_roce_qp *to_hr_qp(struct ib_qp *ibqp)
979{
980 return container_of(ibqp, struct hns_roce_qp, ibqp);
981}
982
983static inline struct hns_roce_cq *to_hr_cq(struct ib_cq *ib_cq)
984{
985 return container_of(ib_cq, struct hns_roce_cq, ib_cq);
986}
987
988static inline struct hns_roce_srq *to_hr_srq(struct ib_srq *ibsrq)
989{
990 return container_of(ibsrq, struct hns_roce_srq, ibsrq);
991}
992
993static inline struct hns_roce_sqp *hr_to_hr_sqp(struct hns_roce_qp *hr_qp)
994{
995 return container_of(hr_qp, struct hns_roce_sqp, hr_qp);
996}
997
0576cbde 998static inline void hns_roce_write64_k(__le32 val[2], void __iomem *dest)
9a443537 999{
1000 __raw_writeq(*(u64 *) val, dest);
1001}
1002
1003static inline struct hns_roce_qp
1004 *__hns_roce_qp_lookup(struct hns_roce_dev *hr_dev, u32 qpn)
1005{
1006 return radix_tree_lookup(&hr_dev->qp_table_tree,
1007 qpn & (hr_dev->caps.num_qps - 1));
1008}
1009
1010static inline void *hns_roce_buf_offset(struct hns_roce_buf *buf, int offset)
1011{
9a8982dc 1012 u32 page_size = 1 << buf->page_shift;
9a443537 1013
b1c15835 1014 if (buf->nbufs == 1)
9a443537 1015 return (char *)(buf->direct.buf) + offset;
1016 else
9a8982dc
WHX
1017 return (char *)(buf->page_list[offset >> buf->page_shift].buf) +
1018 (offset & (page_size - 1));
9a443537 1019}
1020
1021int hns_roce_init_uar_table(struct hns_roce_dev *dev);
1022int hns_roce_uar_alloc(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
1023void hns_roce_uar_free(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
1024void hns_roce_cleanup_uar_table(struct hns_roce_dev *dev);
1025
1026int hns_roce_cmd_init(struct hns_roce_dev *hr_dev);
1027void hns_roce_cmd_cleanup(struct hns_roce_dev *hr_dev);
1028void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status,
1029 u64 out_param);
1030int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev);
1031void hns_roce_cmd_use_polling(struct hns_roce_dev *hr_dev);
1032
1033int hns_roce_mtt_init(struct hns_roce_dev *hr_dev, int npages, int page_shift,
1034 struct hns_roce_mtt *mtt);
1035void hns_roce_mtt_cleanup(struct hns_roce_dev *hr_dev,
1036 struct hns_roce_mtt *mtt);
1037int hns_roce_buf_write_mtt(struct hns_roce_dev *hr_dev,
1038 struct hns_roce_mtt *mtt, struct hns_roce_buf *buf);
1039
1040int hns_roce_init_pd_table(struct hns_roce_dev *hr_dev);
1041int hns_roce_init_mr_table(struct hns_roce_dev *hr_dev);
1042int hns_roce_init_eq_table(struct hns_roce_dev *hr_dev);
1043int hns_roce_init_cq_table(struct hns_roce_dev *hr_dev);
1044int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev);
5c1f167a 1045int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev);
9a443537 1046
1047void hns_roce_cleanup_pd_table(struct hns_roce_dev *hr_dev);
1048void hns_roce_cleanup_mr_table(struct hns_roce_dev *hr_dev);
1049void hns_roce_cleanup_eq_table(struct hns_roce_dev *hr_dev);
1050void hns_roce_cleanup_cq_table(struct hns_roce_dev *hr_dev);
1051void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev);
5c1f167a 1052void hns_roce_cleanup_srq_table(struct hns_roce_dev *hr_dev);
9a443537 1053
1054int hns_roce_bitmap_alloc(struct hns_roce_bitmap *bitmap, unsigned long *obj);
5e6ff78a
WHX
1055void hns_roce_bitmap_free(struct hns_roce_bitmap *bitmap, unsigned long obj,
1056 int rr);
9a443537 1057int hns_roce_bitmap_init(struct hns_roce_bitmap *bitmap, u32 num, u32 mask,
1058 u32 reserved_bot, u32 resetrved_top);
1059void hns_roce_bitmap_cleanup(struct hns_roce_bitmap *bitmap);
1060void hns_roce_cleanup_bitmap(struct hns_roce_dev *hr_dev);
1061int hns_roce_bitmap_alloc_range(struct hns_roce_bitmap *bitmap, int cnt,
1062 int align, unsigned long *obj);
1063void hns_roce_bitmap_free_range(struct hns_roce_bitmap *bitmap,
5e6ff78a
WHX
1064 unsigned long obj, int cnt,
1065 int rr);
9a443537 1066
90898850
DC
1067struct ib_ah *hns_roce_create_ah(struct ib_pd *pd,
1068 struct rdma_ah_attr *ah_attr,
b090c4e3 1069 u32 flags,
477864c8 1070 struct ib_udata *udata);
90898850 1071int hns_roce_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr);
2553ba21 1072int hns_roce_destroy_ah(struct ib_ah *ah, u32 flags);
9a443537 1073
1074struct ib_pd *hns_roce_alloc_pd(struct ib_device *ib_dev,
1075 struct ib_ucontext *context,
1076 struct ib_udata *udata);
1077int hns_roce_dealloc_pd(struct ib_pd *pd);
1078
1079struct ib_mr *hns_roce_get_dma_mr(struct ib_pd *pd, int acc);
1080struct ib_mr *hns_roce_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1081 u64 virt_addr, int access_flags,
1082 struct ib_udata *udata);
a2c80b7b
WHX
1083int hns_roce_rereg_user_mr(struct ib_mr *mr, int flags, u64 start, u64 length,
1084 u64 virt_addr, int mr_access_flags, struct ib_pd *pd,
1085 struct ib_udata *udata);
68a997c5
YL
1086struct ib_mr *hns_roce_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
1087 u32 max_num_sg);
1088int hns_roce_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents,
1089 unsigned int *sg_offset);
9a443537 1090int hns_roce_dereg_mr(struct ib_mr *ibmr);
bfcc681b
SX
1091int hns_roce_hw2sw_mpt(struct hns_roce_dev *hr_dev,
1092 struct hns_roce_cmd_mailbox *mailbox,
1093 unsigned long mpt_index);
1094unsigned long key_to_hw_index(u32 key);
9a443537 1095
c7c28191
YL
1096struct ib_mw *hns_roce_alloc_mw(struct ib_pd *pd, enum ib_mw_type,
1097 struct ib_udata *udata);
1098int hns_roce_dealloc_mw(struct ib_mw *ibmw);
1099
9a443537 1100void hns_roce_buf_free(struct hns_roce_dev *hr_dev, u32 size,
1101 struct hns_roce_buf *buf);
1102int hns_roce_buf_alloc(struct hns_roce_dev *hr_dev, u32 size, u32 max_direct,
9a8982dc 1103 struct hns_roce_buf *buf, u32 page_shift);
9a443537 1104
1105int hns_roce_ib_umem_write_mtt(struct hns_roce_dev *hr_dev,
1106 struct hns_roce_mtt *mtt, struct ib_umem *umem);
1107
c7bcb134
LO
1108struct ib_srq *hns_roce_create_srq(struct ib_pd *pd,
1109 struct ib_srq_init_attr *srq_init_attr,
1110 struct ib_udata *udata);
1111int hns_roce_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr,
1112 enum ib_srq_attr_mask srq_attr_mask,
1113 struct ib_udata *udata);
1114int hns_roce_destroy_srq(struct ib_srq *ibsrq);
1115
9a443537 1116struct ib_qp *hns_roce_create_qp(struct ib_pd *ib_pd,
1117 struct ib_qp_init_attr *init_attr,
1118 struct ib_udata *udata);
1119int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
1120 int attr_mask, struct ib_udata *udata);
1121void *get_recv_wqe(struct hns_roce_qp *hr_qp, int n);
1122void *get_send_wqe(struct hns_roce_qp *hr_qp, int n);
926a01dc 1123void *get_send_extend_sge(struct hns_roce_qp *hr_qp, int n);
9a443537 1124bool hns_roce_wq_overflow(struct hns_roce_wq *hr_wq, int nreq,
1125 struct ib_cq *ib_cq);
1126enum hns_roce_qp_state to_hns_roce_state(enum ib_qp_state state);
1127void hns_roce_lock_cqs(struct hns_roce_cq *send_cq,
1128 struct hns_roce_cq *recv_cq);
1129void hns_roce_unlock_cqs(struct hns_roce_cq *send_cq,
1130 struct hns_roce_cq *recv_cq);
1131void hns_roce_qp_remove(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp);
1132void hns_roce_qp_free(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp);
1133void hns_roce_release_range_qp(struct hns_roce_dev *hr_dev, int base_qpn,
1134 int cnt);
f696bf6d 1135__be32 send_ieth(const struct ib_send_wr *wr);
9a443537 1136int to_hr_qp_type(int qp_type);
1137
1138struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev,
1139 const struct ib_cq_init_attr *attr,
1140 struct ib_ucontext *context,
1141 struct ib_udata *udata);
1142
1143int hns_roce_ib_destroy_cq(struct ib_cq *ib_cq);
afb6b092 1144void hns_roce_free_cq(struct hns_roce_dev *hr_dev, struct hns_roce_cq *hr_cq);
9a443537 1145
b0ea0fa5
JG
1146int hns_roce_db_map_user(struct hns_roce_ucontext *context,
1147 struct ib_udata *udata, unsigned long virt,
e088a685
YL
1148 struct hns_roce_db *db);
1149void hns_roce_db_unmap_user(struct hns_roce_ucontext *context,
1150 struct hns_roce_db *db);
472bc0fb
YL
1151int hns_roce_alloc_db(struct hns_roce_dev *hr_dev, struct hns_roce_db *db,
1152 int order);
1153void hns_roce_free_db(struct hns_roce_dev *hr_dev, struct hns_roce_db *db);
1154
9a443537 1155void hns_roce_cq_completion(struct hns_roce_dev *hr_dev, u32 cqn);
1156void hns_roce_cq_event(struct hns_roce_dev *hr_dev, u32 cqn, int event_type);
1157void hns_roce_qp_event(struct hns_roce_dev *hr_dev, u32 qpn, int event_type);
81fce629 1158void hns_roce_srq_event(struct hns_roce_dev *hr_dev, u32 srqn, int event_type);
9a443537 1159int hns_get_gid_index(struct hns_roce_dev *hr_dev, u8 port, int gid_index);
08805fdb
WHX
1160int hns_roce_init(struct hns_roce_dev *hr_dev);
1161void hns_roce_exit(struct hns_roce_dev *hr_dev);
9a443537 1162
1163#endif /* _HNS_ROCE_DEVICE_H */