blob: b2a66432b865bcc4c1ed0ac39890b2aee98955cc [file] [log] [blame]
Eli Cohene126ba92013-07-07 17:25:49 +03001/*
Saeed Mahameed6cf0a152015-04-02 17:07:30 +03002 * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
Eli Cohene126ba92013-07-07 17:25:49 +03003 *
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 MLX5_IB_H
34#define MLX5_IB_H
35
36#include <linux/kernel.h>
37#include <linux/sched.h>
38#include <rdma/ib_verbs.h>
39#include <rdma/ib_smi.h>
40#include <linux/mlx5/driver.h>
41#include <linux/mlx5/cq.h>
42#include <linux/mlx5/qp.h>
43#include <linux/mlx5/srq.h>
44#include <linux/types.h>
45
46#define mlx5_ib_dbg(dev, format, arg...) \
47pr_debug("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
48 __LINE__, current->pid, ##arg)
49
50#define mlx5_ib_err(dev, format, arg...) \
51pr_err("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
52 __LINE__, current->pid, ##arg)
53
54#define mlx5_ib_warn(dev, format, arg...) \
55pr_warn("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \
56 __LINE__, current->pid, ##arg)
57
Matan Barakb368d7c2015-12-15 20:30:12 +020058#define field_avail(type, fld, sz) (offsetof(type, fld) + \
59 sizeof(((type *)0)->fld) <= (sz))
60
Eli Cohene126ba92013-07-07 17:25:49 +030061enum {
62 MLX5_IB_MMAP_CMD_SHIFT = 8,
63 MLX5_IB_MMAP_CMD_MASK = 0xff,
64};
65
66enum mlx5_ib_mmap_cmd {
67 MLX5_IB_MMAP_REGULAR_PAGE = 0,
68 MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES = 1, /* always last */
69};
70
71enum {
72 MLX5_RES_SCAT_DATA32_CQE = 0x1,
73 MLX5_RES_SCAT_DATA64_CQE = 0x2,
74 MLX5_REQ_SCAT_DATA32_CQE = 0x11,
75 MLX5_REQ_SCAT_DATA64_CQE = 0x22,
76};
77
78enum mlx5_ib_latency_class {
79 MLX5_IB_LATENCY_CLASS_LOW,
80 MLX5_IB_LATENCY_CLASS_MEDIUM,
81 MLX5_IB_LATENCY_CLASS_HIGH,
82 MLX5_IB_LATENCY_CLASS_FAST_PATH
83};
84
85enum mlx5_ib_mad_ifc_flags {
86 MLX5_MAD_IFC_IGNORE_MKEY = 1,
87 MLX5_MAD_IFC_IGNORE_BKEY = 2,
88 MLX5_MAD_IFC_NET_VIEW = 4,
89};
90
91struct mlx5_ib_ucontext {
92 struct ib_ucontext ibucontext;
93 struct list_head db_page_list;
94
95 /* protect doorbell record alloc/free
96 */
97 struct mutex db_page_mutex;
98 struct mlx5_uuar_info uuari;
99};
100
101static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
102{
103 return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
104}
105
106struct mlx5_ib_pd {
107 struct ib_pd ibpd;
108 u32 pdn;
Eli Cohene126ba92013-07-07 17:25:49 +0300109};
110
111/* Use macros here so that don't have to duplicate
112 * enum ib_send_flags and enum ib_qp_type for low-level driver
113 */
114
115#define MLX5_IB_SEND_UMR_UNREG IB_SEND_RESERVED_START
Haggai Eran968e78d2014-12-11 17:04:11 +0200116#define MLX5_IB_SEND_UMR_FAIL_IF_FREE (IB_SEND_RESERVED_START << 1)
117#define MLX5_IB_SEND_UMR_UPDATE_MTT (IB_SEND_RESERVED_START << 2)
Eli Cohene126ba92013-07-07 17:25:49 +0300118#define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1
119#define MLX5_IB_WR_UMR IB_WR_RESERVED1
120
121struct wr_list {
122 u16 opcode;
123 u16 next;
124};
125
126struct mlx5_ib_wq {
127 u64 *wrid;
128 u32 *wr_data;
129 struct wr_list *w_list;
130 unsigned *wqe_head;
131 u16 unsig_count;
132
133 /* serialize post to the work queue
134 */
135 spinlock_t lock;
136 int wqe_cnt;
137 int max_post;
138 int max_gs;
139 int offset;
140 int wqe_shift;
141 unsigned head;
142 unsigned tail;
143 u16 cur_post;
144 u16 last_poll;
145 void *qend;
146};
147
148enum {
149 MLX5_QP_USER,
150 MLX5_QP_KERNEL,
151 MLX5_QP_EMPTY
152};
153
Haggai Eran6aec21f2014-12-11 17:04:23 +0200154/*
155 * Connect-IB can trigger up to four concurrent pagefaults
156 * per-QP.
157 */
158enum mlx5_ib_pagefault_context {
159 MLX5_IB_PAGEFAULT_RESPONDER_READ,
160 MLX5_IB_PAGEFAULT_REQUESTOR_READ,
161 MLX5_IB_PAGEFAULT_RESPONDER_WRITE,
162 MLX5_IB_PAGEFAULT_REQUESTOR_WRITE,
163 MLX5_IB_PAGEFAULT_CONTEXTS
164};
165
166static inline enum mlx5_ib_pagefault_context
167 mlx5_ib_get_pagefault_context(struct mlx5_pagefault *pagefault)
168{
169 return pagefault->flags & (MLX5_PFAULT_REQUESTOR | MLX5_PFAULT_WRITE);
170}
171
172struct mlx5_ib_pfault {
173 struct work_struct work;
174 struct mlx5_pagefault mpfault;
175};
176
Eli Cohene126ba92013-07-07 17:25:49 +0300177struct mlx5_ib_qp {
178 struct ib_qp ibqp;
179 struct mlx5_core_qp mqp;
180 struct mlx5_buf buf;
181
182 struct mlx5_db db;
183 struct mlx5_ib_wq rq;
184
185 u32 doorbell_qpn;
186 u8 sq_signal_bits;
187 u8 fm_cache;
188 int sq_max_wqes_per_wr;
189 int sq_spare_wqes;
190 struct mlx5_ib_wq sq;
191
192 struct ib_umem *umem;
193 int buf_size;
194
195 /* serialize qp state modifications
196 */
197 struct mutex mutex;
198 u16 xrcdn;
199 u32 flags;
200 u8 port;
201 u8 alt_port;
202 u8 atomic_rd_en;
203 u8 resp_depth;
204 u8 state;
205 int mlx_type;
206 int wq_sig;
207 int scat_cqe;
208 int max_inline_data;
209 struct mlx5_bf *bf;
210 int has_rq;
211
212 /* only for user space QPs. For kernel
213 * we have it from the bf object
214 */
215 int uuarn;
216
217 int create_type;
Sagi Grimberge1e66cc2014-02-23 14:19:07 +0200218
219 /* Store signature errors */
220 bool signature_en;
Haggai Eran6aec21f2014-12-11 17:04:23 +0200221
222#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
223 /*
224 * A flag that is true for QP's that are in a state that doesn't
225 * allow page faults, and shouldn't schedule any more faults.
226 */
227 int disable_page_faults;
228 /*
229 * The disable_page_faults_lock protects a QP's disable_page_faults
230 * field, allowing for a thread to atomically check whether the QP
231 * allows page faults, and if so schedule a page fault.
232 */
233 spinlock_t disable_page_faults_lock;
234 struct mlx5_ib_pfault pagefaults[MLX5_IB_PAGEFAULT_CONTEXTS];
235#endif
Eli Cohene126ba92013-07-07 17:25:49 +0300236};
237
238struct mlx5_ib_cq_buf {
239 struct mlx5_buf buf;
240 struct ib_umem *umem;
241 int cqe_size;
Eli Cohenbde51582014-01-14 17:45:18 +0200242 int nent;
Eli Cohene126ba92013-07-07 17:25:49 +0300243};
244
245enum mlx5_ib_qp_flags {
246 MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 0,
247 MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 1,
248};
249
Haggai Eran968e78d2014-12-11 17:04:11 +0200250struct mlx5_umr_wr {
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100251 struct ib_send_wr wr;
Haggai Eran968e78d2014-12-11 17:04:11 +0200252 union {
253 u64 virt_addr;
254 u64 offset;
255 } target;
256 struct ib_pd *pd;
257 unsigned int page_shift;
258 unsigned int npages;
259 u32 length;
260 int access_flags;
261 u32 mkey;
262};
263
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100264static inline struct mlx5_umr_wr *umr_wr(struct ib_send_wr *wr)
265{
266 return container_of(wr, struct mlx5_umr_wr, wr);
267}
268
Eli Cohene126ba92013-07-07 17:25:49 +0300269struct mlx5_shared_mr_info {
270 int mr_id;
271 struct ib_umem *umem;
272};
273
274struct mlx5_ib_cq {
275 struct ib_cq ibcq;
276 struct mlx5_core_cq mcq;
277 struct mlx5_ib_cq_buf buf;
278 struct mlx5_db db;
279
280 /* serialize access to the CQ
281 */
282 spinlock_t lock;
283
284 /* protect resize cq
285 */
286 struct mutex resize_mutex;
Eli Cohenbde51582014-01-14 17:45:18 +0200287 struct mlx5_ib_cq_buf *resize_buf;
Eli Cohene126ba92013-07-07 17:25:49 +0300288 struct ib_umem *resize_umem;
289 int cqe_size;
290};
291
292struct mlx5_ib_srq {
293 struct ib_srq ibsrq;
294 struct mlx5_core_srq msrq;
295 struct mlx5_buf buf;
296 struct mlx5_db db;
297 u64 *wrid;
298 /* protect SRQ hanlding
299 */
300 spinlock_t lock;
301 int head;
302 int tail;
303 u16 wqe_ctr;
304 struct ib_umem *umem;
305 /* serialize arming a SRQ
306 */
307 struct mutex mutex;
308 int wq_sig;
309};
310
311struct mlx5_ib_xrcd {
312 struct ib_xrcd ibxrcd;
313 u32 xrcdn;
314};
315
Haggai Erancc149f752014-12-11 17:04:21 +0200316enum mlx5_ib_mtt_access_flags {
317 MLX5_IB_MTT_READ = (1 << 0),
318 MLX5_IB_MTT_WRITE = (1 << 1),
319};
320
321#define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
322
Eli Cohene126ba92013-07-07 17:25:49 +0300323struct mlx5_ib_mr {
324 struct ib_mr ibmr;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300325 void *descs;
326 dma_addr_t desc_map;
327 int ndescs;
328 int max_descs;
329 int desc_size;
Eli Cohene126ba92013-07-07 17:25:49 +0300330 struct mlx5_core_mr mmr;
331 struct ib_umem *umem;
332 struct mlx5_shared_mr_info *smr_info;
333 struct list_head list;
334 int order;
335 int umred;
Eli Cohene126ba92013-07-07 17:25:49 +0300336 int npages;
Eli Cohen746b5582013-10-23 09:53:14 +0300337 struct mlx5_ib_dev *dev;
338 struct mlx5_create_mkey_mbox_out out;
Sagi Grimberg3121e3c2014-02-23 14:19:06 +0200339 struct mlx5_core_sig_ctx *sig;
Haggai Eranb4cfe442014-12-11 17:04:26 +0200340 int live;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300341 void *descs_alloc;
Eli Cohene126ba92013-07-07 17:25:49 +0300342};
343
Shachar Raindela74d2412014-05-22 14:50:12 +0300344struct mlx5_ib_umr_context {
345 enum ib_wc_status status;
346 struct completion done;
347};
348
349static inline void mlx5_ib_init_umr_context(struct mlx5_ib_umr_context *context)
350{
351 context->status = -1;
352 init_completion(&context->done);
353}
354
Eli Cohene126ba92013-07-07 17:25:49 +0300355struct umr_common {
356 struct ib_pd *pd;
357 struct ib_cq *cq;
358 struct ib_qp *qp;
Eli Cohene126ba92013-07-07 17:25:49 +0300359 /* control access to UMR QP
360 */
361 struct semaphore sem;
362};
363
364enum {
365 MLX5_FMR_INVALID,
366 MLX5_FMR_VALID,
367 MLX5_FMR_BUSY,
368};
369
Eli Cohene126ba92013-07-07 17:25:49 +0300370struct mlx5_cache_ent {
371 struct list_head head;
372 /* sync access to the cahce entry
373 */
374 spinlock_t lock;
375
376
377 struct dentry *dir;
378 char name[4];
379 u32 order;
380 u32 size;
381 u32 cur;
382 u32 miss;
383 u32 limit;
384
385 struct dentry *fsize;
386 struct dentry *fcur;
387 struct dentry *fmiss;
388 struct dentry *flimit;
389
390 struct mlx5_ib_dev *dev;
391 struct work_struct work;
392 struct delayed_work dwork;
Eli Cohen746b5582013-10-23 09:53:14 +0300393 int pending;
Eli Cohene126ba92013-07-07 17:25:49 +0300394};
395
396struct mlx5_mr_cache {
397 struct workqueue_struct *wq;
398 struct mlx5_cache_ent ent[MAX_MR_CACHE_ENTRIES];
399 int stopped;
400 struct dentry *root;
401 unsigned long last_add;
402};
403
404struct mlx5_ib_resources {
405 struct ib_cq *c0;
406 struct ib_xrcd *x0;
407 struct ib_xrcd *x1;
408 struct ib_pd *p0;
409 struct ib_srq *s0;
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +0300410 struct ib_srq *s1;
Eli Cohene126ba92013-07-07 17:25:49 +0300411};
412
Achiad Shochatfc24fc52015-12-23 18:47:17 +0200413struct mlx5_roce {
414 /* Protect mlx5_ib_get_netdev from invoking dev_hold() with a NULL
415 * netdev pointer
416 */
417 rwlock_t netdev_lock;
418 struct net_device *netdev;
419 struct notifier_block nb;
420};
421
Eli Cohene126ba92013-07-07 17:25:49 +0300422struct mlx5_ib_dev {
423 struct ib_device ib_dev;
Jack Morgenstein9603b612014-07-28 23:30:22 +0300424 struct mlx5_core_dev *mdev;
Achiad Shochatfc24fc52015-12-23 18:47:17 +0200425 struct mlx5_roce roce;
Eli Cohene126ba92013-07-07 17:25:49 +0300426 MLX5_DECLARE_DOORBELL_LOCK(uar_lock);
Eli Cohene126ba92013-07-07 17:25:49 +0300427 int num_ports;
Eli Cohene126ba92013-07-07 17:25:49 +0300428 /* serialize update of capability mask
429 */
430 struct mutex cap_mask_mutex;
431 bool ib_active;
432 struct umr_common umrc;
433 /* sync used page count stats
434 */
Eli Cohene126ba92013-07-07 17:25:49 +0300435 struct mlx5_ib_resources devr;
436 struct mlx5_mr_cache cache;
Eli Cohen746b5582013-10-23 09:53:14 +0300437 struct timer_list delay_timer;
438 int fill_delay;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200439#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
440 struct ib_odp_caps odp_caps;
Haggai Eran6aec21f2014-12-11 17:04:23 +0200441 /*
442 * Sleepable RCU that prevents destruction of MRs while they are still
443 * being used by a page fault handler.
444 */
445 struct srcu_struct mr_srcu;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200446#endif
Eli Cohene126ba92013-07-07 17:25:49 +0300447};
448
449static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
450{
451 return container_of(mcq, struct mlx5_ib_cq, mcq);
452}
453
454static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
455{
456 return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
457}
458
459static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
460{
461 return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
462}
463
Eli Cohene126ba92013-07-07 17:25:49 +0300464static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
465{
466 return container_of(ibcq, struct mlx5_ib_cq, ibcq);
467}
468
469static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
470{
471 return container_of(mqp, struct mlx5_ib_qp, mqp);
472}
473
Sagi Grimbergd5436ba2014-02-23 14:19:12 +0200474static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mr *mmr)
475{
476 return container_of(mmr, struct mlx5_ib_mr, mmr);
477}
478
Eli Cohene126ba92013-07-07 17:25:49 +0300479static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
480{
481 return container_of(ibpd, struct mlx5_ib_pd, ibpd);
482}
483
484static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
485{
486 return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
487}
488
489static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
490{
491 return container_of(ibqp, struct mlx5_ib_qp, ibqp);
492}
493
494static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
495{
496 return container_of(msrq, struct mlx5_ib_srq, msrq);
497}
498
499static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
500{
501 return container_of(ibmr, struct mlx5_ib_mr, ibmr);
502}
503
Eli Cohene126ba92013-07-07 17:25:49 +0300504struct mlx5_ib_ah {
505 struct ib_ah ibah;
506 struct mlx5_av av;
507};
508
509static inline struct mlx5_ib_ah *to_mah(struct ib_ah *ibah)
510{
511 return container_of(ibah, struct mlx5_ib_ah, ibah);
512}
513
Eli Cohene126ba92013-07-07 17:25:49 +0300514int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
515 struct mlx5_db *db);
516void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
517void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
518void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
519void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
520int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
Ira Weinya97e2d82015-05-31 17:15:30 -0400521 u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
522 const void *in_mad, void *response_mad);
Eli Cohene126ba92013-07-07 17:25:49 +0300523struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
524int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
525int mlx5_ib_destroy_ah(struct ib_ah *ah);
526struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
527 struct ib_srq_init_attr *init_attr,
528 struct ib_udata *udata);
529int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
530 enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
531int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
532int mlx5_ib_destroy_srq(struct ib_srq *srq);
533int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
534 struct ib_recv_wr **bad_wr);
535struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
536 struct ib_qp_init_attr *init_attr,
537 struct ib_udata *udata);
538int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
539 int attr_mask, struct ib_udata *udata);
540int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
541 struct ib_qp_init_attr *qp_init_attr);
542int mlx5_ib_destroy_qp(struct ib_qp *qp);
543int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
544 struct ib_send_wr **bad_wr);
545int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
546 struct ib_recv_wr **bad_wr);
547void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
Haggai Eranc1395a22014-12-11 17:04:14 +0200548int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
549 void *buffer, u32 length);
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300550struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
551 const struct ib_cq_init_attr *attr,
552 struct ib_ucontext *context,
Eli Cohene126ba92013-07-07 17:25:49 +0300553 struct ib_udata *udata);
554int mlx5_ib_destroy_cq(struct ib_cq *cq);
555int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
556int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
557int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
558int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
559struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
560struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
561 u64 virt_addr, int access_flags,
562 struct ib_udata *udata);
Haggai Eran832a6b02014-12-11 17:04:22 +0200563int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index,
564 int npages, int zap);
Eli Cohene126ba92013-07-07 17:25:49 +0300565int mlx5_ib_dereg_mr(struct ib_mr *ibmr);
Sagi Grimberg9bee1782015-07-30 10:32:35 +0300566struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd,
567 enum ib_mr_type mr_type,
568 u32 max_num_sg);
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300569int mlx5_ib_map_mr_sg(struct ib_mr *ibmr,
570 struct scatterlist *sg,
571 int sg_nents);
Eli Cohene126ba92013-07-07 17:25:49 +0300572int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -0400573 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -0400574 const struct ib_mad_hdr *in, size_t in_mad_size,
575 struct ib_mad_hdr *out, size_t *out_mad_size,
576 u16 *out_mad_pkey_index);
Eli Cohene126ba92013-07-07 17:25:49 +0300577struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
578 struct ib_ucontext *context,
579 struct ib_udata *udata);
580int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd);
Eli Cohene126ba92013-07-07 17:25:49 +0300581int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
582int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300583int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
584 struct ib_smp *out_mad);
585int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
586 __be64 *sys_image_guid);
587int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
588 u16 *max_pkeys);
589int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
590 u32 *vendor_id);
591int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
592int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
593int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
594 u16 *pkey);
595int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
596 union ib_gid *gid);
597int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
598 struct ib_port_attr *props);
Eli Cohene126ba92013-07-07 17:25:49 +0300599int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
600 struct ib_port_attr *props);
601int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
602void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
603void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
604 int *ncont, int *order);
Haggai Eran832a6b02014-12-11 17:04:22 +0200605void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
606 int page_shift, size_t offset, size_t num_pages,
607 __be64 *pas, int access_flags);
Eli Cohene126ba92013-07-07 17:25:49 +0300608void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
Haggai Erancc149f752014-12-11 17:04:21 +0200609 int page_shift, __be64 *pas, int access_flags);
Eli Cohene126ba92013-07-07 17:25:49 +0300610void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
611int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
612int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
613int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
614int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift);
615void mlx5_umr_cq_handler(struct ib_cq *cq, void *cq_context);
Sagi Grimbergd5436ba2014-02-23 14:19:12 +0200616int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
617 struct ib_mr_status *mr_status);
Eli Cohene126ba92013-07-07 17:25:49 +0300618
Haggai Eran8cdd3122014-12-11 17:04:20 +0200619#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
Haggai Eran6aec21f2014-12-11 17:04:23 +0200620extern struct workqueue_struct *mlx5_ib_page_fault_wq;
621
Saeed Mahameed938fe832015-05-28 22:28:41 +0300622void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
Haggai Eran6aec21f2014-12-11 17:04:23 +0200623void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
624 struct mlx5_ib_pfault *pfault);
625void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
626int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
627void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev);
628int __init mlx5_ib_odp_init(void);
629void mlx5_ib_odp_cleanup(void);
630void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
631void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
Haggai Eranb4cfe442014-12-11 17:04:26 +0200632void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
633 unsigned long end);
Haggai Eran6aec21f2014-12-11 17:04:23 +0200634
635#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
Saeed Mahameed938fe832015-05-28 22:28:41 +0300636static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
Haggai Eran8cdd3122014-12-11 17:04:20 +0200637{
Saeed Mahameed938fe832015-05-28 22:28:41 +0300638 return;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200639}
Haggai Eran6aec21f2014-12-11 17:04:23 +0200640
641static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {}
642static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
643static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {}
644static inline int mlx5_ib_odp_init(void) { return 0; }
645static inline void mlx5_ib_odp_cleanup(void) {}
646static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {}
647static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {}
648
Haggai Eran8cdd3122014-12-11 17:04:20 +0200649#endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
650
Achiad Shochat2811ba52015-12-23 18:47:24 +0200651__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
652 int index);
653
Eli Cohene126ba92013-07-07 17:25:49 +0300654static inline void init_query_mad(struct ib_smp *mad)
655{
656 mad->base_version = 1;
657 mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
658 mad->class_version = 1;
659 mad->method = IB_MGMT_METHOD_GET;
660}
661
662static inline u8 convert_access(int acc)
663{
664 return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) |
665 (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) |
666 (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) |
667 (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) |
668 MLX5_PERM_LOCAL_READ;
669}
670
Sagi Grimbergb6364012015-09-02 22:23:04 +0300671static inline int is_qp1(enum ib_qp_type qp_type)
672{
673 return qp_type == IB_QPT_GSI;
674}
675
Haggai Erancc149f752014-12-11 17:04:21 +0200676#define MLX5_MAX_UMR_SHIFT 16
677#define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
678
Eli Cohene126ba92013-07-07 17:25:49 +0300679#endif /* MLX5_IB_H */