blob: 7242b14388733f8ee0a521d7273afe4de9b41dc5 [file] [log] [blame]
oulijun9a443532016-07-21 19:06:38 +08001/*
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
Wei Hu (Xavier)8f3e9f32016-11-23 19:41:00 +000040#define HNS_ROCE_HW_VER1 ('h' << 24 | 'i' << 16 | '0' << 8 | '6')
41
oulijun9a443532016-07-21 19:06:38 +080042#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
59#define HNS_ROCE_MAX_IRQ_NUM 34
60
61#define HNS_ROCE_COMP_VEC_NUM 32
62
63#define HNS_ROCE_AEQE_VEC_NUM 1
64#define HNS_ROCE_AEQE_OF_VEC_NUM 1
65
66/* 4G/4K = 1M */
Lijun Ouac111252016-09-15 23:48:13 +010067#define HNS_ROCE_SL_SHIFT 28
oulijun9a443532016-07-21 19:06:38 +080068#define HNS_ROCE_TCLASS_SHIFT 20
69#define HNS_ROCE_FLOW_LABLE_MASK 0xfffff
70
71#define HNS_ROCE_MAX_PORTS 6
72#define HNS_ROCE_MAX_GID_NUM 16
73#define HNS_ROCE_GID_SIZE 16
74
75#define MR_TYPE_MR 0x00
76#define MR_TYPE_DMA 0x03
77
78#define PKEY_ID 0xffff
Lijun Ou31644662016-09-15 23:48:07 +010079#define GUID_LEN 8
oulijun9a443532016-07-21 19:06:38 +080080#define NODE_DESC_SIZE 64
Lijun Ou509bf0c2016-09-15 23:48:12 +010081#define DB_REG_OFFSET 0x1000
oulijun9a443532016-07-21 19:06:38 +080082
83#define SERV_TYPE_RC 0
84#define SERV_TYPE_RD 1
85#define SERV_TYPE_UC 2
86#define SERV_TYPE_UD 3
87
88#define PAGES_SHIFT_8 8
89#define PAGES_SHIFT_16 16
90#define PAGES_SHIFT_24 24
91#define PAGES_SHIFT_32 32
92
93enum hns_roce_qp_state {
94 HNS_ROCE_QP_STATE_RST,
95 HNS_ROCE_QP_STATE_INIT,
96 HNS_ROCE_QP_STATE_RTR,
97 HNS_ROCE_QP_STATE_RTS,
98 HNS_ROCE_QP_STATE_SQD,
99 HNS_ROCE_QP_STATE_ERR,
100 HNS_ROCE_QP_NUM_STATE,
101};
102
103enum hns_roce_event {
104 HNS_ROCE_EVENT_TYPE_PATH_MIG = 0x01,
105 HNS_ROCE_EVENT_TYPE_PATH_MIG_FAILED = 0x02,
106 HNS_ROCE_EVENT_TYPE_COMM_EST = 0x03,
107 HNS_ROCE_EVENT_TYPE_SQ_DRAINED = 0x04,
108 HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
109 HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR = 0x06,
110 HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR = 0x07,
111 HNS_ROCE_EVENT_TYPE_SRQ_LIMIT_REACH = 0x08,
112 HNS_ROCE_EVENT_TYPE_SRQ_LAST_WQE_REACH = 0x09,
113 HNS_ROCE_EVENT_TYPE_SRQ_CATAS_ERROR = 0x0a,
114 HNS_ROCE_EVENT_TYPE_CQ_ACCESS_ERROR = 0x0b,
115 HNS_ROCE_EVENT_TYPE_CQ_OVERFLOW = 0x0c,
116 HNS_ROCE_EVENT_TYPE_CQ_ID_INVALID = 0x0d,
117 HNS_ROCE_EVENT_TYPE_PORT_CHANGE = 0x0f,
118 /* 0x10 and 0x11 is unused in currently application case */
119 HNS_ROCE_EVENT_TYPE_DB_OVERFLOW = 0x12,
120 HNS_ROCE_EVENT_TYPE_MB = 0x13,
121 HNS_ROCE_EVENT_TYPE_CEQ_OVERFLOW = 0x14,
122};
123
124/* Local Work Queue Catastrophic Error,SUBTYPE 0x5 */
125enum {
126 HNS_ROCE_LWQCE_QPC_ERROR = 1,
127 HNS_ROCE_LWQCE_MTU_ERROR = 2,
128 HNS_ROCE_LWQCE_WQE_BA_ADDR_ERROR = 3,
129 HNS_ROCE_LWQCE_WQE_ADDR_ERROR = 4,
130 HNS_ROCE_LWQCE_SQ_WQE_SHIFT_ERROR = 5,
131 HNS_ROCE_LWQCE_SL_ERROR = 6,
132 HNS_ROCE_LWQCE_PORT_ERROR = 7,
133};
134
135/* Local Access Violation Work Queue Error,SUBTYPE 0x7 */
136enum {
137 HNS_ROCE_LAVWQE_R_KEY_VIOLATION = 1,
138 HNS_ROCE_LAVWQE_LENGTH_ERROR = 2,
139 HNS_ROCE_LAVWQE_VA_ERROR = 3,
140 HNS_ROCE_LAVWQE_PD_ERROR = 4,
141 HNS_ROCE_LAVWQE_RW_ACC_ERROR = 5,
142 HNS_ROCE_LAVWQE_KEY_STATE_ERROR = 6,
143 HNS_ROCE_LAVWQE_MR_OPERATION_ERROR = 7,
144};
145
146/* DOORBELL overflow subtype */
147enum {
148 HNS_ROCE_DB_SUBTYPE_SDB_OVF = 1,
149 HNS_ROCE_DB_SUBTYPE_SDB_ALM_OVF = 2,
150 HNS_ROCE_DB_SUBTYPE_ODB_OVF = 3,
151 HNS_ROCE_DB_SUBTYPE_ODB_ALM_OVF = 4,
152 HNS_ROCE_DB_SUBTYPE_SDB_ALM_EMP = 5,
153 HNS_ROCE_DB_SUBTYPE_ODB_ALM_EMP = 6,
154};
155
156enum {
157 /* RQ&SRQ related operations */
158 HNS_ROCE_OPCODE_SEND_DATA_RECEIVE = 0x06,
159 HNS_ROCE_OPCODE_RDMA_WITH_IMM_RECEIVE = 0x07,
160};
161
162#define HNS_ROCE_CMD_SUCCESS 1
163
164#define HNS_ROCE_PORT_DOWN 0
165#define HNS_ROCE_PORT_UP 1
166
167#define HNS_ROCE_MTT_ENTRY_PER_SEG 8
168
169#define PAGE_ADDR_SHIFT 12
170
171struct hns_roce_uar {
172 u64 pfn;
173 unsigned long index;
174};
175
176struct hns_roce_ucontext {
177 struct ib_ucontext ibucontext;
178 struct hns_roce_uar uar;
179};
180
181struct hns_roce_pd {
182 struct ib_pd ibpd;
183 unsigned long pdn;
184};
185
186struct hns_roce_bitmap {
187 /* Bitmap Traversal last a bit which is 1 */
188 unsigned long last;
189 unsigned long top;
190 unsigned long max;
191 unsigned long reserved_top;
192 unsigned long mask;
193 spinlock_t lock;
194 unsigned long *table;
195};
196
197/* Order bitmap length -- bit num compute formula: 1 << (max_order - order) */
198/* Order = 0: bitmap is biggest, order = max bitmap is least (only a bit) */
199/* Every bit repesent to a partner free/used status in bitmap */
200/*
201* Initial, bits of other bitmap are all 0 except that a bit of max_order is 1
202* Bit = 1 represent to idle and available; bit = 0: not available
203*/
204struct hns_roce_buddy {
205 /* Members point to every order level bitmap */
206 unsigned long **bits;
207 /* Represent to avail bits of the order level bitmap */
208 u32 *num_free;
209 int max_order;
210 spinlock_t lock;
211};
212
213/* For Hardware Entry Memory */
214struct hns_roce_hem_table {
215 /* HEM type: 0 = qpc, 1 = mtt, 2 = cqc, 3 = srq, 4 = other */
216 u32 type;
217 /* HEM array elment num */
218 unsigned long num_hem;
219 /* HEM entry record obj total num */
220 unsigned long num_obj;
221 /*Single obj size */
222 unsigned long obj_size;
223 int lowmem;
224 struct mutex mutex;
225 struct hns_roce_hem **hem;
226};
227
228struct hns_roce_mtt {
229 unsigned long first_seg;
230 int order;
231 int page_shift;
232};
233
234/* Only support 4K page size for mr register */
235#define MR_SIZE_4K 0
236
237struct hns_roce_mr {
238 struct ib_mr ibmr;
239 struct ib_umem *umem;
240 u64 iova; /* MR's virtual orignal addr */
241 u64 size; /* Address range of MR */
242 u32 key; /* Key of MR */
243 u32 pd; /* PD num of MR */
244 u32 access;/* Access permission of MR */
245 int enabled; /* MR's active status */
246 int type; /* MR's register type */
247 u64 *pbl_buf;/* MR's PBL space */
248 dma_addr_t pbl_dma_addr; /* MR's PBL space PA */
249};
250
251struct hns_roce_mr_table {
252 struct hns_roce_bitmap mtpt_bitmap;
253 struct hns_roce_buddy mtt_buddy;
254 struct hns_roce_hem_table mtt_table;
255 struct hns_roce_hem_table mtpt_table;
256};
257
258struct hns_roce_wq {
259 u64 *wrid; /* Work request ID */
260 spinlock_t lock;
261 int wqe_cnt; /* WQE num */
262 u32 max_post;
263 int max_gs;
264 int offset;
265 int wqe_shift;/* WQE size */
266 u32 head;
267 u32 tail;
268 void __iomem *db_reg_l;
269};
270
271struct hns_roce_buf_list {
272 void *buf;
273 dma_addr_t map;
274};
275
276struct hns_roce_buf {
277 struct hns_roce_buf_list direct;
278 struct hns_roce_buf_list *page_list;
279 int nbufs;
280 u32 npages;
281 int page_shift;
282};
283
284struct hns_roce_cq_buf {
285 struct hns_roce_buf hr_buf;
286 struct hns_roce_mtt hr_mtt;
287};
288
oulijun9a443532016-07-21 19:06:38 +0800289struct hns_roce_cq {
290 struct ib_cq ib_cq;
291 struct hns_roce_cq_buf hr_buf;
oulijun9a443532016-07-21 19:06:38 +0800292 spinlock_t lock;
oulijun9a443532016-07-21 19:06:38 +0800293 struct ib_umem *umem;
oulijun9a443532016-07-21 19:06:38 +0800294 void (*comp)(struct hns_roce_cq *);
295 void (*event)(struct hns_roce_cq *, enum hns_roce_event);
296
297 struct hns_roce_uar *uar;
298 u32 cq_depth;
299 u32 cons_index;
300 void __iomem *cq_db_l;
Wei Hu (Xavier)8f3e9f32016-11-23 19:41:00 +0000301 u16 *tptr_addr;
oulijun9a443532016-07-21 19:06:38 +0800302 unsigned long cqn;
303 u32 vector;
304 atomic_t refcount;
305 struct completion free;
306};
307
308struct hns_roce_srq {
309 struct ib_srq ibsrq;
310 int srqn;
311};
312
313struct hns_roce_uar_table {
314 struct hns_roce_bitmap bitmap;
315};
316
317struct hns_roce_qp_table {
318 struct hns_roce_bitmap bitmap;
319 spinlock_t lock;
320 struct hns_roce_hem_table qp_table;
321 struct hns_roce_hem_table irrl_table;
322};
323
324struct hns_roce_cq_table {
325 struct hns_roce_bitmap bitmap;
326 spinlock_t lock;
327 struct radix_tree_root tree;
328 struct hns_roce_hem_table table;
329};
330
331struct hns_roce_raq_table {
332 struct hns_roce_buf_list *e_raq_buf;
333};
334
335struct hns_roce_av {
336 __le32 port_pd;
337 u8 gid_index;
338 u8 stat_rate;
339 u8 hop_limit;
340 __le32 sl_tclass_flowlabel;
341 u8 dgid[HNS_ROCE_GID_SIZE];
342 u8 mac[6];
343 __le16 vlan;
344};
345
346struct hns_roce_ah {
347 struct ib_ah ibah;
348 struct hns_roce_av av;
349};
350
351struct hns_roce_cmd_context {
352 struct completion done;
353 int result;
354 int next;
355 u64 out_param;
356 u16 token;
357};
358
359struct hns_roce_cmdq {
360 struct dma_pool *pool;
361 u8 __iomem *hcr;
362 struct mutex hcr_mutex;
363 struct semaphore poll_sem;
364 /*
365 * Event mode: cmd register mutex protection,
366 * ensure to not exceed max_cmds and user use limit region
367 */
368 struct semaphore event_sem;
369 int max_cmds;
370 spinlock_t context_lock;
371 int free_head;
372 struct hns_roce_cmd_context *context;
373 /*
374 * Result of get integer part
375 * which max_comds compute according a power of 2
376 */
377 u16 token_mask;
378 /*
379 * Process whether use event mode, init default non-zero
380 * After the event queue of cmd event ready,
381 * can switch into event mode
382 * close device, switch into poll mode(non event mode)
383 */
384 u8 use_events;
385 u8 toggle;
386};
387
388struct hns_roce_dev;
389
390struct hns_roce_qp {
391 struct ib_qp ibqp;
392 struct hns_roce_buf hr_buf;
393 struct hns_roce_wq rq;
394 __le64 doorbell_qpn;
395 __le32 sq_signal_bits;
396 u32 sq_next_wqe;
397 int sq_max_wqes_per_wr;
398 int sq_spare_wqes;
399 struct hns_roce_wq sq;
400
401 struct ib_umem *umem;
402 struct hns_roce_mtt mtt;
403 u32 buff_size;
404 struct mutex mutex;
405 u8 port;
Lijun Ou77168092016-09-15 23:48:10 +0100406 u8 phy_port;
oulijun9a443532016-07-21 19:06:38 +0800407 u8 sl;
408 u8 resp_depth;
409 u8 state;
410 u32 access_flags;
411 u32 pkey_index;
412 void (*event)(struct hns_roce_qp *,
413 enum hns_roce_event);
414 unsigned long qpn;
415
416 atomic_t refcount;
417 struct completion free;
418};
419
420struct hns_roce_sqp {
421 struct hns_roce_qp hr_qp;
422};
423
424struct hns_roce_ib_iboe {
425 spinlock_t lock;
426 struct net_device *netdevs[HNS_ROCE_MAX_PORTS];
427 struct notifier_block nb;
428 struct notifier_block nb_inet;
429 /* 16 GID is shared by 6 port in v1 engine. */
430 union ib_gid gid_table[HNS_ROCE_MAX_GID_NUM];
431 u8 phy_port[HNS_ROCE_MAX_PORTS];
432};
433
434struct hns_roce_eq {
435 struct hns_roce_dev *hr_dev;
436 void __iomem *doorbell;
437
438 int type_flag;/* Aeq:1 ceq:0 */
439 int eqn;
440 u32 entries;
441 int log_entries;
442 int eqe_size;
443 int irq;
444 int log_page_size;
445 int cons_index;
446 struct hns_roce_buf_list *buf_list;
447};
448
449struct hns_roce_eq_table {
450 struct hns_roce_eq *eq;
451 void __iomem **eqc_base;
452};
453
454struct hns_roce_caps {
455 u8 num_ports;
456 int gid_table_len[HNS_ROCE_MAX_PORTS];
457 int pkey_table_len[HNS_ROCE_MAX_PORTS];
458 int local_ca_ack_delay;
459 int num_uars;
460 u32 phy_num_uars;
461 u32 max_sq_sg; /* 2 */
462 u32 max_sq_inline; /* 32 */
463 u32 max_rq_sg; /* 2 */
464 int num_qps; /* 256k */
465 u32 max_wqes; /* 16k */
466 u32 max_sq_desc_sz; /* 64 */
467 u32 max_rq_desc_sz; /* 64 */
468 int max_qp_init_rdma;
469 int max_qp_dest_rdma;
oulijun9a443532016-07-21 19:06:38 +0800470 int num_cqs;
471 int max_cqes;
472 int reserved_cqs;
473 int num_aeq_vectors; /* 1 */
474 int num_comp_vectors; /* 32 ceq */
475 int num_other_vectors;
476 int num_mtpts;
477 u32 num_mtt_segs;
478 int reserved_mrws;
479 int reserved_uars;
480 int num_pds;
481 int reserved_pds;
482 u32 mtt_entry_sz;
483 u32 cq_entry_sz;
484 u32 page_size_cap;
485 u32 reserved_lkey;
486 int mtpt_entry_sz;
487 int qpc_entry_sz;
488 int irrl_entry_sz;
489 int cqc_entry_sz;
490 int aeqe_depth;
491 int ceqe_depth[HNS_ROCE_COMP_VEC_NUM];
492 enum ib_mtu max_mtu;
493};
494
495struct hns_roce_hw {
496 int (*reset)(struct hns_roce_dev *hr_dev, bool enable);
497 void (*hw_profile)(struct hns_roce_dev *hr_dev);
498 int (*hw_init)(struct hns_roce_dev *hr_dev);
499 void (*hw_exit)(struct hns_roce_dev *hr_dev);
500 void (*set_gid)(struct hns_roce_dev *hr_dev, u8 port, int gid_index,
501 union ib_gid *gid);
502 void (*set_mac)(struct hns_roce_dev *hr_dev, u8 phy_port, u8 *addr);
503 void (*set_mtu)(struct hns_roce_dev *hr_dev, u8 phy_port,
504 enum ib_mtu mtu);
505 int (*write_mtpt)(void *mb_buf, struct hns_roce_mr *mr,
506 unsigned long mtpt_idx);
507 void (*write_cqc)(struct hns_roce_dev *hr_dev,
508 struct hns_roce_cq *hr_cq, void *mb_buf, u64 *mtts,
509 dma_addr_t dma_handle, int nent, u32 vector);
Wei Hu (Xavier)97f0e392016-09-20 17:06:59 +0100510 int (*clear_hem)(struct hns_roce_dev *hr_dev,
511 struct hns_roce_hem_table *table, int obj);
oulijun9a443532016-07-21 19:06:38 +0800512 int (*query_qp)(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
513 int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
514 int (*modify_qp)(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
515 int attr_mask, enum ib_qp_state cur_state,
516 enum ib_qp_state new_state);
517 int (*destroy_qp)(struct ib_qp *ibqp);
518 int (*post_send)(struct ib_qp *ibqp, struct ib_send_wr *wr,
519 struct ib_send_wr **bad_wr);
520 int (*post_recv)(struct ib_qp *qp, struct ib_recv_wr *recv_wr,
521 struct ib_recv_wr **bad_recv_wr);
522 int (*req_notify_cq)(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
523 int (*poll_cq)(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
524 void *priv;
525};
526
527struct hns_roce_dev {
528 struct ib_device ib_dev;
529 struct platform_device *pdev;
530 struct hns_roce_uar priv_uar;
Salil528f1de2016-08-24 04:44:50 +0800531 const char *irq_names[HNS_ROCE_MAX_IRQ_NUM];
oulijun9a443532016-07-21 19:06:38 +0800532 spinlock_t sm_lock;
oulijun9a443532016-07-21 19:06:38 +0800533 spinlock_t bt_cmd_lock;
534 struct hns_roce_ib_iboe iboe;
535
536 int irq[HNS_ROCE_MAX_IRQ_NUM];
537 u8 __iomem *reg_base;
538 struct hns_roce_caps caps;
539 struct radix_tree_root qp_table_tree;
540
541 unsigned char dev_addr[HNS_ROCE_MAX_PORTS][MAC_ADDR_OCTET_NUM];
542 u64 sys_image_guid;
543 u32 vendor_id;
544 u32 vendor_part_id;
545 u32 hw_rev;
546 void __iomem *priv_addr;
547
548 struct hns_roce_cmdq cmd;
549 struct hns_roce_bitmap pd_bitmap;
550 struct hns_roce_uar_table uar_table;
551 struct hns_roce_mr_table mr_table;
552 struct hns_roce_cq_table cq_table;
553 struct hns_roce_qp_table qp_table;
554 struct hns_roce_eq_table eq_table;
555
556 int cmd_mod;
557 int loop_idc;
Wei Hu (Xavier)8f3e9f32016-11-23 19:41:00 +0000558 dma_addr_t tptr_dma_addr; /*only for hw v1*/
559 u32 tptr_size; /*only for hw v1*/
oulijun9a443532016-07-21 19:06:38 +0800560 struct hns_roce_hw *hw;
561};
562
563static inline struct hns_roce_dev *to_hr_dev(struct ib_device *ib_dev)
564{
565 return container_of(ib_dev, struct hns_roce_dev, ib_dev);
566}
567
568static inline struct hns_roce_ucontext
569 *to_hr_ucontext(struct ib_ucontext *ibucontext)
570{
571 return container_of(ibucontext, struct hns_roce_ucontext, ibucontext);
572}
573
574static inline struct hns_roce_pd *to_hr_pd(struct ib_pd *ibpd)
575{
576 return container_of(ibpd, struct hns_roce_pd, ibpd);
577}
578
579static inline struct hns_roce_ah *to_hr_ah(struct ib_ah *ibah)
580{
581 return container_of(ibah, struct hns_roce_ah, ibah);
582}
583
584static inline struct hns_roce_mr *to_hr_mr(struct ib_mr *ibmr)
585{
586 return container_of(ibmr, struct hns_roce_mr, ibmr);
587}
588
589static inline struct hns_roce_qp *to_hr_qp(struct ib_qp *ibqp)
590{
591 return container_of(ibqp, struct hns_roce_qp, ibqp);
592}
593
594static inline struct hns_roce_cq *to_hr_cq(struct ib_cq *ib_cq)
595{
596 return container_of(ib_cq, struct hns_roce_cq, ib_cq);
597}
598
599static inline struct hns_roce_srq *to_hr_srq(struct ib_srq *ibsrq)
600{
601 return container_of(ibsrq, struct hns_roce_srq, ibsrq);
602}
603
604static inline struct hns_roce_sqp *hr_to_hr_sqp(struct hns_roce_qp *hr_qp)
605{
606 return container_of(hr_qp, struct hns_roce_sqp, hr_qp);
607}
608
609static inline void hns_roce_write64_k(__be32 val[2], void __iomem *dest)
610{
611 __raw_writeq(*(u64 *) val, dest);
612}
613
614static inline struct hns_roce_qp
615 *__hns_roce_qp_lookup(struct hns_roce_dev *hr_dev, u32 qpn)
616{
617 return radix_tree_lookup(&hr_dev->qp_table_tree,
618 qpn & (hr_dev->caps.num_qps - 1));
619}
620
621static inline void *hns_roce_buf_offset(struct hns_roce_buf *buf, int offset)
622{
623 u32 bits_per_long_val = BITS_PER_LONG;
624
625 if (bits_per_long_val == 64 || buf->nbufs == 1)
626 return (char *)(buf->direct.buf) + offset;
627 else
628 return (char *)(buf->page_list[offset >> PAGE_SHIFT].buf) +
629 (offset & (PAGE_SIZE - 1));
630}
631
632int hns_roce_init_uar_table(struct hns_roce_dev *dev);
633int hns_roce_uar_alloc(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
634void hns_roce_uar_free(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
635void hns_roce_cleanup_uar_table(struct hns_roce_dev *dev);
636
637int hns_roce_cmd_init(struct hns_roce_dev *hr_dev);
638void hns_roce_cmd_cleanup(struct hns_roce_dev *hr_dev);
639void hns_roce_cmd_event(struct hns_roce_dev *hr_dev, u16 token, u8 status,
640 u64 out_param);
641int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev);
642void hns_roce_cmd_use_polling(struct hns_roce_dev *hr_dev);
643
644int hns_roce_mtt_init(struct hns_roce_dev *hr_dev, int npages, int page_shift,
645 struct hns_roce_mtt *mtt);
646void hns_roce_mtt_cleanup(struct hns_roce_dev *hr_dev,
647 struct hns_roce_mtt *mtt);
648int hns_roce_buf_write_mtt(struct hns_roce_dev *hr_dev,
649 struct hns_roce_mtt *mtt, struct hns_roce_buf *buf);
650
651int hns_roce_init_pd_table(struct hns_roce_dev *hr_dev);
652int hns_roce_init_mr_table(struct hns_roce_dev *hr_dev);
653int hns_roce_init_eq_table(struct hns_roce_dev *hr_dev);
654int hns_roce_init_cq_table(struct hns_roce_dev *hr_dev);
655int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev);
656
657void hns_roce_cleanup_pd_table(struct hns_roce_dev *hr_dev);
658void hns_roce_cleanup_mr_table(struct hns_roce_dev *hr_dev);
659void hns_roce_cleanup_eq_table(struct hns_roce_dev *hr_dev);
660void hns_roce_cleanup_cq_table(struct hns_roce_dev *hr_dev);
661void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev);
662
663int hns_roce_bitmap_alloc(struct hns_roce_bitmap *bitmap, unsigned long *obj);
664void hns_roce_bitmap_free(struct hns_roce_bitmap *bitmap, unsigned long obj);
665int hns_roce_bitmap_init(struct hns_roce_bitmap *bitmap, u32 num, u32 mask,
666 u32 reserved_bot, u32 resetrved_top);
667void hns_roce_bitmap_cleanup(struct hns_roce_bitmap *bitmap);
668void hns_roce_cleanup_bitmap(struct hns_roce_dev *hr_dev);
669int hns_roce_bitmap_alloc_range(struct hns_roce_bitmap *bitmap, int cnt,
670 int align, unsigned long *obj);
671void hns_roce_bitmap_free_range(struct hns_roce_bitmap *bitmap,
672 unsigned long obj, int cnt);
673
674struct ib_ah *hns_roce_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
675int hns_roce_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
676int hns_roce_destroy_ah(struct ib_ah *ah);
677
678struct ib_pd *hns_roce_alloc_pd(struct ib_device *ib_dev,
679 struct ib_ucontext *context,
680 struct ib_udata *udata);
681int hns_roce_dealloc_pd(struct ib_pd *pd);
682
683struct ib_mr *hns_roce_get_dma_mr(struct ib_pd *pd, int acc);
684struct ib_mr *hns_roce_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
685 u64 virt_addr, int access_flags,
686 struct ib_udata *udata);
687int hns_roce_dereg_mr(struct ib_mr *ibmr);
688
689void hns_roce_buf_free(struct hns_roce_dev *hr_dev, u32 size,
690 struct hns_roce_buf *buf);
691int hns_roce_buf_alloc(struct hns_roce_dev *hr_dev, u32 size, u32 max_direct,
692 struct hns_roce_buf *buf);
693
694int hns_roce_ib_umem_write_mtt(struct hns_roce_dev *hr_dev,
695 struct hns_roce_mtt *mtt, struct ib_umem *umem);
696
697struct ib_qp *hns_roce_create_qp(struct ib_pd *ib_pd,
698 struct ib_qp_init_attr *init_attr,
699 struct ib_udata *udata);
700int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
701 int attr_mask, struct ib_udata *udata);
702void *get_recv_wqe(struct hns_roce_qp *hr_qp, int n);
703void *get_send_wqe(struct hns_roce_qp *hr_qp, int n);
704bool hns_roce_wq_overflow(struct hns_roce_wq *hr_wq, int nreq,
705 struct ib_cq *ib_cq);
706enum hns_roce_qp_state to_hns_roce_state(enum ib_qp_state state);
707void hns_roce_lock_cqs(struct hns_roce_cq *send_cq,
708 struct hns_roce_cq *recv_cq);
709void hns_roce_unlock_cqs(struct hns_roce_cq *send_cq,
710 struct hns_roce_cq *recv_cq);
711void hns_roce_qp_remove(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp);
712void hns_roce_qp_free(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp);
713void hns_roce_release_range_qp(struct hns_roce_dev *hr_dev, int base_qpn,
714 int cnt);
715__be32 send_ieth(struct ib_send_wr *wr);
716int to_hr_qp_type(int qp_type);
717
718struct ib_cq *hns_roce_ib_create_cq(struct ib_device *ib_dev,
719 const struct ib_cq_init_attr *attr,
720 struct ib_ucontext *context,
721 struct ib_udata *udata);
722
723int hns_roce_ib_destroy_cq(struct ib_cq *ib_cq);
724
725void hns_roce_cq_completion(struct hns_roce_dev *hr_dev, u32 cqn);
726void hns_roce_cq_event(struct hns_roce_dev *hr_dev, u32 cqn, int event_type);
727void hns_roce_qp_event(struct hns_roce_dev *hr_dev, u32 qpn, int event_type);
728int hns_get_gid_index(struct hns_roce_dev *hr_dev, u8 port, int gid_index);
729
730extern struct hns_roce_hw hns_roce_hw_v1;
731
732#endif /* _HNS_ROCE_DEVICE_H */