blob: d4b227126265ea50d346787676b4458b7be1e956 [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,
Matan Barakd69e3bc2015-12-15 20:30:13 +020068 MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES = 1,
69 /* 5 is chosen in order to be compatible with old versions of libmlx5 */
70 MLX5_IB_MMAP_CORE_CLOCK = 5,
Eli Cohene126ba92013-07-07 17:25:49 +030071};
72
73enum {
74 MLX5_RES_SCAT_DATA32_CQE = 0x1,
75 MLX5_RES_SCAT_DATA64_CQE = 0x2,
76 MLX5_REQ_SCAT_DATA32_CQE = 0x11,
77 MLX5_REQ_SCAT_DATA64_CQE = 0x22,
78};
79
80enum mlx5_ib_latency_class {
81 MLX5_IB_LATENCY_CLASS_LOW,
82 MLX5_IB_LATENCY_CLASS_MEDIUM,
83 MLX5_IB_LATENCY_CLASS_HIGH,
84 MLX5_IB_LATENCY_CLASS_FAST_PATH
85};
86
87enum mlx5_ib_mad_ifc_flags {
88 MLX5_MAD_IFC_IGNORE_MKEY = 1,
89 MLX5_MAD_IFC_IGNORE_BKEY = 2,
90 MLX5_MAD_IFC_NET_VIEW = 4,
91};
92
Leon Romanovsky051f2632015-12-20 12:16:11 +020093enum {
94 MLX5_CROSS_CHANNEL_UUAR = 0,
95};
96
Eli Cohene126ba92013-07-07 17:25:49 +030097struct mlx5_ib_ucontext {
98 struct ib_ucontext ibucontext;
99 struct list_head db_page_list;
100
101 /* protect doorbell record alloc/free
102 */
103 struct mutex db_page_mutex;
104 struct mlx5_uuar_info uuari;
105};
106
107static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
108{
109 return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
110}
111
112struct mlx5_ib_pd {
113 struct ib_pd ibpd;
114 u32 pdn;
Eli Cohene126ba92013-07-07 17:25:49 +0300115};
116
117/* Use macros here so that don't have to duplicate
118 * enum ib_send_flags and enum ib_qp_type for low-level driver
119 */
120
121#define MLX5_IB_SEND_UMR_UNREG IB_SEND_RESERVED_START
Haggai Eran968e78d2014-12-11 17:04:11 +0200122#define MLX5_IB_SEND_UMR_FAIL_IF_FREE (IB_SEND_RESERVED_START << 1)
123#define MLX5_IB_SEND_UMR_UPDATE_MTT (IB_SEND_RESERVED_START << 2)
Eli Cohene126ba92013-07-07 17:25:49 +0300124#define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1
125#define MLX5_IB_WR_UMR IB_WR_RESERVED1
126
127struct wr_list {
128 u16 opcode;
129 u16 next;
130};
131
132struct mlx5_ib_wq {
133 u64 *wrid;
134 u32 *wr_data;
135 struct wr_list *w_list;
136 unsigned *wqe_head;
137 u16 unsig_count;
138
139 /* serialize post to the work queue
140 */
141 spinlock_t lock;
142 int wqe_cnt;
143 int max_post;
144 int max_gs;
145 int offset;
146 int wqe_shift;
147 unsigned head;
148 unsigned tail;
149 u16 cur_post;
150 u16 last_poll;
151 void *qend;
152};
153
154enum {
155 MLX5_QP_USER,
156 MLX5_QP_KERNEL,
157 MLX5_QP_EMPTY
158};
159
Haggai Eran6aec21f2014-12-11 17:04:23 +0200160/*
161 * Connect-IB can trigger up to four concurrent pagefaults
162 * per-QP.
163 */
164enum mlx5_ib_pagefault_context {
165 MLX5_IB_PAGEFAULT_RESPONDER_READ,
166 MLX5_IB_PAGEFAULT_REQUESTOR_READ,
167 MLX5_IB_PAGEFAULT_RESPONDER_WRITE,
168 MLX5_IB_PAGEFAULT_REQUESTOR_WRITE,
169 MLX5_IB_PAGEFAULT_CONTEXTS
170};
171
172static inline enum mlx5_ib_pagefault_context
173 mlx5_ib_get_pagefault_context(struct mlx5_pagefault *pagefault)
174{
175 return pagefault->flags & (MLX5_PFAULT_REQUESTOR | MLX5_PFAULT_WRITE);
176}
177
178struct mlx5_ib_pfault {
179 struct work_struct work;
180 struct mlx5_pagefault mpfault;
181};
182
Eli Cohene126ba92013-07-07 17:25:49 +0300183struct mlx5_ib_qp {
184 struct ib_qp ibqp;
185 struct mlx5_core_qp mqp;
186 struct mlx5_buf buf;
187
188 struct mlx5_db db;
189 struct mlx5_ib_wq rq;
190
191 u32 doorbell_qpn;
192 u8 sq_signal_bits;
193 u8 fm_cache;
194 int sq_max_wqes_per_wr;
195 int sq_spare_wqes;
196 struct mlx5_ib_wq sq;
197
198 struct ib_umem *umem;
199 int buf_size;
200
201 /* serialize qp state modifications
202 */
203 struct mutex mutex;
204 u16 xrcdn;
205 u32 flags;
206 u8 port;
207 u8 alt_port;
208 u8 atomic_rd_en;
209 u8 resp_depth;
210 u8 state;
211 int mlx_type;
212 int wq_sig;
213 int scat_cqe;
214 int max_inline_data;
215 struct mlx5_bf *bf;
216 int has_rq;
217
218 /* only for user space QPs. For kernel
219 * we have it from the bf object
220 */
221 int uuarn;
222
223 int create_type;
Sagi Grimberge1e66cc2014-02-23 14:19:07 +0200224
225 /* Store signature errors */
226 bool signature_en;
Haggai Eran6aec21f2014-12-11 17:04:23 +0200227
228#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
229 /*
230 * A flag that is true for QP's that are in a state that doesn't
231 * allow page faults, and shouldn't schedule any more faults.
232 */
233 int disable_page_faults;
234 /*
235 * The disable_page_faults_lock protects a QP's disable_page_faults
236 * field, allowing for a thread to atomically check whether the QP
237 * allows page faults, and if so schedule a page fault.
238 */
239 spinlock_t disable_page_faults_lock;
240 struct mlx5_ib_pfault pagefaults[MLX5_IB_PAGEFAULT_CONTEXTS];
241#endif
Eli Cohene126ba92013-07-07 17:25:49 +0300242};
243
244struct mlx5_ib_cq_buf {
245 struct mlx5_buf buf;
246 struct ib_umem *umem;
247 int cqe_size;
Eli Cohenbde51582014-01-14 17:45:18 +0200248 int nent;
Eli Cohene126ba92013-07-07 17:25:49 +0300249};
250
251enum mlx5_ib_qp_flags {
252 MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 0,
253 MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 1,
Leon Romanovsky051f2632015-12-20 12:16:11 +0200254 MLX5_IB_QP_CROSS_CHANNEL = 1 << 2,
255 MLX5_IB_QP_MANAGED_SEND = 1 << 3,
256 MLX5_IB_QP_MANAGED_RECV = 1 << 4,
Eli Cohene126ba92013-07-07 17:25:49 +0300257};
258
Haggai Eran968e78d2014-12-11 17:04:11 +0200259struct mlx5_umr_wr {
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100260 struct ib_send_wr wr;
Haggai Eran968e78d2014-12-11 17:04:11 +0200261 union {
262 u64 virt_addr;
263 u64 offset;
264 } target;
265 struct ib_pd *pd;
266 unsigned int page_shift;
267 unsigned int npages;
268 u32 length;
269 int access_flags;
270 u32 mkey;
271};
272
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100273static inline struct mlx5_umr_wr *umr_wr(struct ib_send_wr *wr)
274{
275 return container_of(wr, struct mlx5_umr_wr, wr);
276}
277
Eli Cohene126ba92013-07-07 17:25:49 +0300278struct mlx5_shared_mr_info {
279 int mr_id;
280 struct ib_umem *umem;
281};
282
283struct mlx5_ib_cq {
284 struct ib_cq ibcq;
285 struct mlx5_core_cq mcq;
286 struct mlx5_ib_cq_buf buf;
287 struct mlx5_db db;
288
289 /* serialize access to the CQ
290 */
291 spinlock_t lock;
292
293 /* protect resize cq
294 */
295 struct mutex resize_mutex;
Eli Cohenbde51582014-01-14 17:45:18 +0200296 struct mlx5_ib_cq_buf *resize_buf;
Eli Cohene126ba92013-07-07 17:25:49 +0300297 struct ib_umem *resize_umem;
298 int cqe_size;
Leon Romanovsky051f2632015-12-20 12:16:11 +0200299 u32 create_flags;
Eli Cohene126ba92013-07-07 17:25:49 +0300300};
301
302struct mlx5_ib_srq {
303 struct ib_srq ibsrq;
304 struct mlx5_core_srq msrq;
305 struct mlx5_buf buf;
306 struct mlx5_db db;
307 u64 *wrid;
308 /* protect SRQ hanlding
309 */
310 spinlock_t lock;
311 int head;
312 int tail;
313 u16 wqe_ctr;
314 struct ib_umem *umem;
315 /* serialize arming a SRQ
316 */
317 struct mutex mutex;
318 int wq_sig;
319};
320
321struct mlx5_ib_xrcd {
322 struct ib_xrcd ibxrcd;
323 u32 xrcdn;
324};
325
Haggai Erancc149f752014-12-11 17:04:21 +0200326enum mlx5_ib_mtt_access_flags {
327 MLX5_IB_MTT_READ = (1 << 0),
328 MLX5_IB_MTT_WRITE = (1 << 1),
329};
330
331#define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
332
Eli Cohene126ba92013-07-07 17:25:49 +0300333struct mlx5_ib_mr {
334 struct ib_mr ibmr;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300335 void *descs;
336 dma_addr_t desc_map;
337 int ndescs;
338 int max_descs;
339 int desc_size;
Eli Cohene126ba92013-07-07 17:25:49 +0300340 struct mlx5_core_mr mmr;
341 struct ib_umem *umem;
342 struct mlx5_shared_mr_info *smr_info;
343 struct list_head list;
344 int order;
345 int umred;
Eli Cohene126ba92013-07-07 17:25:49 +0300346 int npages;
Eli Cohen746b5582013-10-23 09:53:14 +0300347 struct mlx5_ib_dev *dev;
348 struct mlx5_create_mkey_mbox_out out;
Sagi Grimberg3121e3c2014-02-23 14:19:06 +0200349 struct mlx5_core_sig_ctx *sig;
Haggai Eranb4cfe442014-12-11 17:04:26 +0200350 int live;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300351 void *descs_alloc;
Eli Cohene126ba92013-07-07 17:25:49 +0300352};
353
Shachar Raindela74d2412014-05-22 14:50:12 +0300354struct mlx5_ib_umr_context {
355 enum ib_wc_status status;
356 struct completion done;
357};
358
359static inline void mlx5_ib_init_umr_context(struct mlx5_ib_umr_context *context)
360{
361 context->status = -1;
362 init_completion(&context->done);
363}
364
Eli Cohene126ba92013-07-07 17:25:49 +0300365struct umr_common {
366 struct ib_pd *pd;
367 struct ib_cq *cq;
368 struct ib_qp *qp;
Eli Cohene126ba92013-07-07 17:25:49 +0300369 /* control access to UMR QP
370 */
371 struct semaphore sem;
372};
373
374enum {
375 MLX5_FMR_INVALID,
376 MLX5_FMR_VALID,
377 MLX5_FMR_BUSY,
378};
379
Eli Cohene126ba92013-07-07 17:25:49 +0300380struct mlx5_cache_ent {
381 struct list_head head;
382 /* sync access to the cahce entry
383 */
384 spinlock_t lock;
385
386
387 struct dentry *dir;
388 char name[4];
389 u32 order;
390 u32 size;
391 u32 cur;
392 u32 miss;
393 u32 limit;
394
395 struct dentry *fsize;
396 struct dentry *fcur;
397 struct dentry *fmiss;
398 struct dentry *flimit;
399
400 struct mlx5_ib_dev *dev;
401 struct work_struct work;
402 struct delayed_work dwork;
Eli Cohen746b5582013-10-23 09:53:14 +0300403 int pending;
Eli Cohene126ba92013-07-07 17:25:49 +0300404};
405
406struct mlx5_mr_cache {
407 struct workqueue_struct *wq;
408 struct mlx5_cache_ent ent[MAX_MR_CACHE_ENTRIES];
409 int stopped;
410 struct dentry *root;
411 unsigned long last_add;
412};
413
414struct mlx5_ib_resources {
415 struct ib_cq *c0;
416 struct ib_xrcd *x0;
417 struct ib_xrcd *x1;
418 struct ib_pd *p0;
419 struct ib_srq *s0;
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +0300420 struct ib_srq *s1;
Eli Cohene126ba92013-07-07 17:25:49 +0300421};
422
Achiad Shochatfc24fc52015-12-23 18:47:17 +0200423struct mlx5_roce {
424 /* Protect mlx5_ib_get_netdev from invoking dev_hold() with a NULL
425 * netdev pointer
426 */
427 rwlock_t netdev_lock;
428 struct net_device *netdev;
429 struct notifier_block nb;
430};
431
Eli Cohene126ba92013-07-07 17:25:49 +0300432struct mlx5_ib_dev {
433 struct ib_device ib_dev;
Jack Morgenstein9603b612014-07-28 23:30:22 +0300434 struct mlx5_core_dev *mdev;
Achiad Shochatfc24fc52015-12-23 18:47:17 +0200435 struct mlx5_roce roce;
Eli Cohene126ba92013-07-07 17:25:49 +0300436 MLX5_DECLARE_DOORBELL_LOCK(uar_lock);
Eli Cohene126ba92013-07-07 17:25:49 +0300437 int num_ports;
Eli Cohene126ba92013-07-07 17:25:49 +0300438 /* serialize update of capability mask
439 */
440 struct mutex cap_mask_mutex;
441 bool ib_active;
442 struct umr_common umrc;
443 /* sync used page count stats
444 */
Eli Cohene126ba92013-07-07 17:25:49 +0300445 struct mlx5_ib_resources devr;
446 struct mlx5_mr_cache cache;
Eli Cohen746b5582013-10-23 09:53:14 +0300447 struct timer_list delay_timer;
448 int fill_delay;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200449#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
450 struct ib_odp_caps odp_caps;
Haggai Eran6aec21f2014-12-11 17:04:23 +0200451 /*
452 * Sleepable RCU that prevents destruction of MRs while they are still
453 * being used by a page fault handler.
454 */
455 struct srcu_struct mr_srcu;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200456#endif
Eli Cohene126ba92013-07-07 17:25:49 +0300457};
458
459static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
460{
461 return container_of(mcq, struct mlx5_ib_cq, mcq);
462}
463
464static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
465{
466 return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
467}
468
469static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
470{
471 return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
472}
473
Eli Cohene126ba92013-07-07 17:25:49 +0300474static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
475{
476 return container_of(ibcq, struct mlx5_ib_cq, ibcq);
477}
478
479static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
480{
481 return container_of(mqp, struct mlx5_ib_qp, mqp);
482}
483
Sagi Grimbergd5436ba2014-02-23 14:19:12 +0200484static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mr *mmr)
485{
486 return container_of(mmr, struct mlx5_ib_mr, mmr);
487}
488
Eli Cohene126ba92013-07-07 17:25:49 +0300489static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
490{
491 return container_of(ibpd, struct mlx5_ib_pd, ibpd);
492}
493
494static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
495{
496 return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
497}
498
499static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
500{
501 return container_of(ibqp, struct mlx5_ib_qp, ibqp);
502}
503
504static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
505{
506 return container_of(msrq, struct mlx5_ib_srq, msrq);
507}
508
509static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
510{
511 return container_of(ibmr, struct mlx5_ib_mr, ibmr);
512}
513
Eli Cohene126ba92013-07-07 17:25:49 +0300514struct mlx5_ib_ah {
515 struct ib_ah ibah;
516 struct mlx5_av av;
517};
518
519static inline struct mlx5_ib_ah *to_mah(struct ib_ah *ibah)
520{
521 return container_of(ibah, struct mlx5_ib_ah, ibah);
522}
523
Eli Cohene126ba92013-07-07 17:25:49 +0300524int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
525 struct mlx5_db *db);
526void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
527void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
528void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
529void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
530int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
Ira Weinya97e2d82015-05-31 17:15:30 -0400531 u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
532 const void *in_mad, void *response_mad);
Eli Cohene126ba92013-07-07 17:25:49 +0300533struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
534int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
535int mlx5_ib_destroy_ah(struct ib_ah *ah);
536struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
537 struct ib_srq_init_attr *init_attr,
538 struct ib_udata *udata);
539int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
540 enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
541int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
542int mlx5_ib_destroy_srq(struct ib_srq *srq);
543int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
544 struct ib_recv_wr **bad_wr);
545struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
546 struct ib_qp_init_attr *init_attr,
547 struct ib_udata *udata);
548int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
549 int attr_mask, struct ib_udata *udata);
550int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
551 struct ib_qp_init_attr *qp_init_attr);
552int mlx5_ib_destroy_qp(struct ib_qp *qp);
553int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
554 struct ib_send_wr **bad_wr);
555int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
556 struct ib_recv_wr **bad_wr);
557void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
Haggai Eranc1395a22014-12-11 17:04:14 +0200558int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
559 void *buffer, u32 length);
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300560struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
561 const struct ib_cq_init_attr *attr,
562 struct ib_ucontext *context,
Eli Cohene126ba92013-07-07 17:25:49 +0300563 struct ib_udata *udata);
564int mlx5_ib_destroy_cq(struct ib_cq *cq);
565int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
566int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
567int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
568int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
569struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
570struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
571 u64 virt_addr, int access_flags,
572 struct ib_udata *udata);
Haggai Eran832a6b02014-12-11 17:04:22 +0200573int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index,
574 int npages, int zap);
Eli Cohene126ba92013-07-07 17:25:49 +0300575int mlx5_ib_dereg_mr(struct ib_mr *ibmr);
Sagi Grimberg9bee1782015-07-30 10:32:35 +0300576struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd,
577 enum ib_mr_type mr_type,
578 u32 max_num_sg);
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300579int mlx5_ib_map_mr_sg(struct ib_mr *ibmr,
580 struct scatterlist *sg,
581 int sg_nents);
Eli Cohene126ba92013-07-07 17:25:49 +0300582int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -0400583 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -0400584 const struct ib_mad_hdr *in, size_t in_mad_size,
585 struct ib_mad_hdr *out, size_t *out_mad_size,
586 u16 *out_mad_pkey_index);
Eli Cohene126ba92013-07-07 17:25:49 +0300587struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
588 struct ib_ucontext *context,
589 struct ib_udata *udata);
590int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd);
Eli Cohene126ba92013-07-07 17:25:49 +0300591int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
592int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300593int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
594 struct ib_smp *out_mad);
595int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
596 __be64 *sys_image_guid);
597int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
598 u16 *max_pkeys);
599int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
600 u32 *vendor_id);
601int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
602int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
603int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
604 u16 *pkey);
605int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
606 union ib_gid *gid);
607int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
608 struct ib_port_attr *props);
Eli Cohene126ba92013-07-07 17:25:49 +0300609int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
610 struct ib_port_attr *props);
611int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
612void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
613void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
614 int *ncont, int *order);
Haggai Eran832a6b02014-12-11 17:04:22 +0200615void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
616 int page_shift, size_t offset, size_t num_pages,
617 __be64 *pas, int access_flags);
Eli Cohene126ba92013-07-07 17:25:49 +0300618void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
Haggai Erancc149f752014-12-11 17:04:21 +0200619 int page_shift, __be64 *pas, int access_flags);
Eli Cohene126ba92013-07-07 17:25:49 +0300620void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
621int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
622int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
623int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
624int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift);
625void mlx5_umr_cq_handler(struct ib_cq *cq, void *cq_context);
Sagi Grimbergd5436ba2014-02-23 14:19:12 +0200626int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
627 struct ib_mr_status *mr_status);
Eli Cohene126ba92013-07-07 17:25:49 +0300628
Haggai Eran8cdd3122014-12-11 17:04:20 +0200629#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
Haggai Eran6aec21f2014-12-11 17:04:23 +0200630extern struct workqueue_struct *mlx5_ib_page_fault_wq;
631
Saeed Mahameed938fe832015-05-28 22:28:41 +0300632void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
Haggai Eran6aec21f2014-12-11 17:04:23 +0200633void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
634 struct mlx5_ib_pfault *pfault);
635void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
636int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
637void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev);
638int __init mlx5_ib_odp_init(void);
639void mlx5_ib_odp_cleanup(void);
640void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
641void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
Haggai Eranb4cfe442014-12-11 17:04:26 +0200642void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
643 unsigned long end);
Haggai Eran6aec21f2014-12-11 17:04:23 +0200644
645#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
Saeed Mahameed938fe832015-05-28 22:28:41 +0300646static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
Haggai Eran8cdd3122014-12-11 17:04:20 +0200647{
Saeed Mahameed938fe832015-05-28 22:28:41 +0300648 return;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200649}
Haggai Eran6aec21f2014-12-11 17:04:23 +0200650
651static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {}
652static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
653static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {}
654static inline int mlx5_ib_odp_init(void) { return 0; }
655static inline void mlx5_ib_odp_cleanup(void) {}
656static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {}
657static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {}
658
Haggai Eran8cdd3122014-12-11 17:04:20 +0200659#endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
660
Achiad Shochat2811ba52015-12-23 18:47:24 +0200661__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
662 int index);
663
Eli Cohene126ba92013-07-07 17:25:49 +0300664static inline void init_query_mad(struct ib_smp *mad)
665{
666 mad->base_version = 1;
667 mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
668 mad->class_version = 1;
669 mad->method = IB_MGMT_METHOD_GET;
670}
671
672static inline u8 convert_access(int acc)
673{
674 return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) |
675 (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) |
676 (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) |
677 (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) |
678 MLX5_PERM_LOCAL_READ;
679}
680
Sagi Grimbergb6364012015-09-02 22:23:04 +0300681static inline int is_qp1(enum ib_qp_type qp_type)
682{
683 return qp_type == IB_QPT_GSI;
684}
685
Haggai Erancc149f752014-12-11 17:04:21 +0200686#define MLX5_MAX_UMR_SHIFT 16
687#define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
688
Leon Romanovsky051f2632015-12-20 12:16:11 +0200689static inline u32 check_cq_create_flags(u32 flags)
690{
691 /*
692 * It returns non-zero value for unsupported CQ
693 * create flags, otherwise it returns zero.
694 */
695 return (flags & ~IB_CQ_FLAGS_IGNORE_OVERRUN);
696}
Eli Cohene126ba92013-07-07 17:25:49 +0300697#endif /* MLX5_IB_H */