blob: a6a57de278b494f82634cea92c89529868511731 [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))
Haggai Abramovskycfb5e082016-01-14 19:12:57 +020060#define MLX5_IB_DEFAULT_UIDX 0xffffff
61#define MLX5_USER_ASSIGNED_UIDX_MASK __mlx5_mask(qpc, user_index)
Matan Barakb368d7c2015-12-15 20:30:12 +020062
Eli Cohene126ba92013-07-07 17:25:49 +030063enum {
64 MLX5_IB_MMAP_CMD_SHIFT = 8,
65 MLX5_IB_MMAP_CMD_MASK = 0xff,
66};
67
68enum mlx5_ib_mmap_cmd {
69 MLX5_IB_MMAP_REGULAR_PAGE = 0,
Matan Barakd69e3bc2015-12-15 20:30:13 +020070 MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES = 1,
71 /* 5 is chosen in order to be compatible with old versions of libmlx5 */
72 MLX5_IB_MMAP_CORE_CLOCK = 5,
Eli Cohene126ba92013-07-07 17:25:49 +030073};
74
75enum {
76 MLX5_RES_SCAT_DATA32_CQE = 0x1,
77 MLX5_RES_SCAT_DATA64_CQE = 0x2,
78 MLX5_REQ_SCAT_DATA32_CQE = 0x11,
79 MLX5_REQ_SCAT_DATA64_CQE = 0x22,
80};
81
82enum mlx5_ib_latency_class {
83 MLX5_IB_LATENCY_CLASS_LOW,
84 MLX5_IB_LATENCY_CLASS_MEDIUM,
85 MLX5_IB_LATENCY_CLASS_HIGH,
86 MLX5_IB_LATENCY_CLASS_FAST_PATH
87};
88
89enum mlx5_ib_mad_ifc_flags {
90 MLX5_MAD_IFC_IGNORE_MKEY = 1,
91 MLX5_MAD_IFC_IGNORE_BKEY = 2,
92 MLX5_MAD_IFC_NET_VIEW = 4,
93};
94
Leon Romanovsky051f2632015-12-20 12:16:11 +020095enum {
96 MLX5_CROSS_CHANNEL_UUAR = 0,
97};
98
Haggai Abramovskycfb5e082016-01-14 19:12:57 +020099enum {
100 MLX5_CQE_VERSION_V0,
101 MLX5_CQE_VERSION_V1,
102};
103
Eli Cohene126ba92013-07-07 17:25:49 +0300104struct mlx5_ib_ucontext {
105 struct ib_ucontext ibucontext;
106 struct list_head db_page_list;
107
108 /* protect doorbell record alloc/free
109 */
110 struct mutex db_page_mutex;
111 struct mlx5_uuar_info uuari;
Haggai Abramovskycfb5e082016-01-14 19:12:57 +0200112 u8 cqe_version;
Eli Cohene126ba92013-07-07 17:25:49 +0300113};
114
115static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
116{
117 return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
118}
119
120struct mlx5_ib_pd {
121 struct ib_pd ibpd;
122 u32 pdn;
Eli Cohene126ba92013-07-07 17:25:49 +0300123};
124
125/* Use macros here so that don't have to duplicate
126 * enum ib_send_flags and enum ib_qp_type for low-level driver
127 */
128
129#define MLX5_IB_SEND_UMR_UNREG IB_SEND_RESERVED_START
Haggai Eran968e78d2014-12-11 17:04:11 +0200130#define MLX5_IB_SEND_UMR_FAIL_IF_FREE (IB_SEND_RESERVED_START << 1)
131#define MLX5_IB_SEND_UMR_UPDATE_MTT (IB_SEND_RESERVED_START << 2)
Eli Cohene126ba92013-07-07 17:25:49 +0300132#define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1
133#define MLX5_IB_WR_UMR IB_WR_RESERVED1
134
135struct wr_list {
136 u16 opcode;
137 u16 next;
138};
139
140struct mlx5_ib_wq {
141 u64 *wrid;
142 u32 *wr_data;
143 struct wr_list *w_list;
144 unsigned *wqe_head;
145 u16 unsig_count;
146
147 /* serialize post to the work queue
148 */
149 spinlock_t lock;
150 int wqe_cnt;
151 int max_post;
152 int max_gs;
153 int offset;
154 int wqe_shift;
155 unsigned head;
156 unsigned tail;
157 u16 cur_post;
158 u16 last_poll;
159 void *qend;
160};
161
162enum {
163 MLX5_QP_USER,
164 MLX5_QP_KERNEL,
165 MLX5_QP_EMPTY
166};
167
Haggai Eran6aec21f2014-12-11 17:04:23 +0200168/*
169 * Connect-IB can trigger up to four concurrent pagefaults
170 * per-QP.
171 */
172enum mlx5_ib_pagefault_context {
173 MLX5_IB_PAGEFAULT_RESPONDER_READ,
174 MLX5_IB_PAGEFAULT_REQUESTOR_READ,
175 MLX5_IB_PAGEFAULT_RESPONDER_WRITE,
176 MLX5_IB_PAGEFAULT_REQUESTOR_WRITE,
177 MLX5_IB_PAGEFAULT_CONTEXTS
178};
179
180static inline enum mlx5_ib_pagefault_context
181 mlx5_ib_get_pagefault_context(struct mlx5_pagefault *pagefault)
182{
183 return pagefault->flags & (MLX5_PFAULT_REQUESTOR | MLX5_PFAULT_WRITE);
184}
185
186struct mlx5_ib_pfault {
187 struct work_struct work;
188 struct mlx5_pagefault mpfault;
189};
190
Eli Cohene126ba92013-07-07 17:25:49 +0300191struct mlx5_ib_qp {
192 struct ib_qp ibqp;
193 struct mlx5_core_qp mqp;
194 struct mlx5_buf buf;
195
196 struct mlx5_db db;
197 struct mlx5_ib_wq rq;
198
199 u32 doorbell_qpn;
200 u8 sq_signal_bits;
201 u8 fm_cache;
202 int sq_max_wqes_per_wr;
203 int sq_spare_wqes;
204 struct mlx5_ib_wq sq;
205
206 struct ib_umem *umem;
207 int buf_size;
208
209 /* serialize qp state modifications
210 */
211 struct mutex mutex;
212 u16 xrcdn;
213 u32 flags;
214 u8 port;
215 u8 alt_port;
216 u8 atomic_rd_en;
217 u8 resp_depth;
218 u8 state;
219 int mlx_type;
220 int wq_sig;
221 int scat_cqe;
222 int max_inline_data;
223 struct mlx5_bf *bf;
224 int has_rq;
225
226 /* only for user space QPs. For kernel
227 * we have it from the bf object
228 */
229 int uuarn;
230
231 int create_type;
Sagi Grimberge1e66cc2014-02-23 14:19:07 +0200232
233 /* Store signature errors */
234 bool signature_en;
Haggai Eran6aec21f2014-12-11 17:04:23 +0200235
236#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
237 /*
238 * A flag that is true for QP's that are in a state that doesn't
239 * allow page faults, and shouldn't schedule any more faults.
240 */
241 int disable_page_faults;
242 /*
243 * The disable_page_faults_lock protects a QP's disable_page_faults
244 * field, allowing for a thread to atomically check whether the QP
245 * allows page faults, and if so schedule a page fault.
246 */
247 spinlock_t disable_page_faults_lock;
248 struct mlx5_ib_pfault pagefaults[MLX5_IB_PAGEFAULT_CONTEXTS];
249#endif
Eli Cohene126ba92013-07-07 17:25:49 +0300250};
251
252struct mlx5_ib_cq_buf {
253 struct mlx5_buf buf;
254 struct ib_umem *umem;
255 int cqe_size;
Eli Cohenbde51582014-01-14 17:45:18 +0200256 int nent;
Eli Cohene126ba92013-07-07 17:25:49 +0300257};
258
259enum mlx5_ib_qp_flags {
260 MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 0,
261 MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 1,
Leon Romanovsky051f2632015-12-20 12:16:11 +0200262 MLX5_IB_QP_CROSS_CHANNEL = 1 << 2,
263 MLX5_IB_QP_MANAGED_SEND = 1 << 3,
264 MLX5_IB_QP_MANAGED_RECV = 1 << 4,
Eli Cohene126ba92013-07-07 17:25:49 +0300265};
266
Haggai Eran968e78d2014-12-11 17:04:11 +0200267struct mlx5_umr_wr {
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100268 struct ib_send_wr wr;
Haggai Eran968e78d2014-12-11 17:04:11 +0200269 union {
270 u64 virt_addr;
271 u64 offset;
272 } target;
273 struct ib_pd *pd;
274 unsigned int page_shift;
275 unsigned int npages;
276 u32 length;
277 int access_flags;
278 u32 mkey;
279};
280
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100281static inline struct mlx5_umr_wr *umr_wr(struct ib_send_wr *wr)
282{
283 return container_of(wr, struct mlx5_umr_wr, wr);
284}
285
Eli Cohene126ba92013-07-07 17:25:49 +0300286struct mlx5_shared_mr_info {
287 int mr_id;
288 struct ib_umem *umem;
289};
290
291struct mlx5_ib_cq {
292 struct ib_cq ibcq;
293 struct mlx5_core_cq mcq;
294 struct mlx5_ib_cq_buf buf;
295 struct mlx5_db db;
296
297 /* serialize access to the CQ
298 */
299 spinlock_t lock;
300
301 /* protect resize cq
302 */
303 struct mutex resize_mutex;
Eli Cohenbde51582014-01-14 17:45:18 +0200304 struct mlx5_ib_cq_buf *resize_buf;
Eli Cohene126ba92013-07-07 17:25:49 +0300305 struct ib_umem *resize_umem;
306 int cqe_size;
Leon Romanovsky051f2632015-12-20 12:16:11 +0200307 u32 create_flags;
Eli Cohene126ba92013-07-07 17:25:49 +0300308};
309
310struct mlx5_ib_srq {
311 struct ib_srq ibsrq;
312 struct mlx5_core_srq msrq;
313 struct mlx5_buf buf;
314 struct mlx5_db db;
315 u64 *wrid;
316 /* protect SRQ hanlding
317 */
318 spinlock_t lock;
319 int head;
320 int tail;
321 u16 wqe_ctr;
322 struct ib_umem *umem;
323 /* serialize arming a SRQ
324 */
325 struct mutex mutex;
326 int wq_sig;
327};
328
329struct mlx5_ib_xrcd {
330 struct ib_xrcd ibxrcd;
331 u32 xrcdn;
332};
333
Haggai Erancc149f752014-12-11 17:04:21 +0200334enum mlx5_ib_mtt_access_flags {
335 MLX5_IB_MTT_READ = (1 << 0),
336 MLX5_IB_MTT_WRITE = (1 << 1),
337};
338
339#define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
340
Eli Cohene126ba92013-07-07 17:25:49 +0300341struct mlx5_ib_mr {
342 struct ib_mr ibmr;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300343 void *descs;
344 dma_addr_t desc_map;
345 int ndescs;
346 int max_descs;
347 int desc_size;
Eli Cohene126ba92013-07-07 17:25:49 +0300348 struct mlx5_core_mr mmr;
349 struct ib_umem *umem;
350 struct mlx5_shared_mr_info *smr_info;
351 struct list_head list;
352 int order;
353 int umred;
Eli Cohene126ba92013-07-07 17:25:49 +0300354 int npages;
Eli Cohen746b5582013-10-23 09:53:14 +0300355 struct mlx5_ib_dev *dev;
356 struct mlx5_create_mkey_mbox_out out;
Sagi Grimberg3121e3c2014-02-23 14:19:06 +0200357 struct mlx5_core_sig_ctx *sig;
Haggai Eranb4cfe442014-12-11 17:04:26 +0200358 int live;
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300359 void *descs_alloc;
Eli Cohene126ba92013-07-07 17:25:49 +0300360};
361
Shachar Raindela74d2412014-05-22 14:50:12 +0300362struct mlx5_ib_umr_context {
363 enum ib_wc_status status;
364 struct completion done;
365};
366
367static inline void mlx5_ib_init_umr_context(struct mlx5_ib_umr_context *context)
368{
369 context->status = -1;
370 init_completion(&context->done);
371}
372
Eli Cohene126ba92013-07-07 17:25:49 +0300373struct umr_common {
374 struct ib_pd *pd;
375 struct ib_cq *cq;
376 struct ib_qp *qp;
Eli Cohene126ba92013-07-07 17:25:49 +0300377 /* control access to UMR QP
378 */
379 struct semaphore sem;
380};
381
382enum {
383 MLX5_FMR_INVALID,
384 MLX5_FMR_VALID,
385 MLX5_FMR_BUSY,
386};
387
Eli Cohene126ba92013-07-07 17:25:49 +0300388struct mlx5_cache_ent {
389 struct list_head head;
390 /* sync access to the cahce entry
391 */
392 spinlock_t lock;
393
394
395 struct dentry *dir;
396 char name[4];
397 u32 order;
398 u32 size;
399 u32 cur;
400 u32 miss;
401 u32 limit;
402
403 struct dentry *fsize;
404 struct dentry *fcur;
405 struct dentry *fmiss;
406 struct dentry *flimit;
407
408 struct mlx5_ib_dev *dev;
409 struct work_struct work;
410 struct delayed_work dwork;
Eli Cohen746b5582013-10-23 09:53:14 +0300411 int pending;
Eli Cohene126ba92013-07-07 17:25:49 +0300412};
413
414struct mlx5_mr_cache {
415 struct workqueue_struct *wq;
416 struct mlx5_cache_ent ent[MAX_MR_CACHE_ENTRIES];
417 int stopped;
418 struct dentry *root;
419 unsigned long last_add;
420};
421
422struct mlx5_ib_resources {
423 struct ib_cq *c0;
424 struct ib_xrcd *x0;
425 struct ib_xrcd *x1;
426 struct ib_pd *p0;
427 struct ib_srq *s0;
Haggai Abramonvsky4aa17b22015-06-04 19:30:48 +0300428 struct ib_srq *s1;
Eli Cohene126ba92013-07-07 17:25:49 +0300429};
430
Achiad Shochatfc24fc52015-12-23 18:47:17 +0200431struct mlx5_roce {
432 /* Protect mlx5_ib_get_netdev from invoking dev_hold() with a NULL
433 * netdev pointer
434 */
435 rwlock_t netdev_lock;
436 struct net_device *netdev;
437 struct notifier_block nb;
438};
439
Eli Cohene126ba92013-07-07 17:25:49 +0300440struct mlx5_ib_dev {
441 struct ib_device ib_dev;
Jack Morgenstein9603b612014-07-28 23:30:22 +0300442 struct mlx5_core_dev *mdev;
Achiad Shochatfc24fc52015-12-23 18:47:17 +0200443 struct mlx5_roce roce;
Eli Cohene126ba92013-07-07 17:25:49 +0300444 MLX5_DECLARE_DOORBELL_LOCK(uar_lock);
Eli Cohene126ba92013-07-07 17:25:49 +0300445 int num_ports;
Eli Cohene126ba92013-07-07 17:25:49 +0300446 /* serialize update of capability mask
447 */
448 struct mutex cap_mask_mutex;
449 bool ib_active;
450 struct umr_common umrc;
451 /* sync used page count stats
452 */
Eli Cohene126ba92013-07-07 17:25:49 +0300453 struct mlx5_ib_resources devr;
454 struct mlx5_mr_cache cache;
Eli Cohen746b5582013-10-23 09:53:14 +0300455 struct timer_list delay_timer;
456 int fill_delay;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200457#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
458 struct ib_odp_caps odp_caps;
Haggai Eran6aec21f2014-12-11 17:04:23 +0200459 /*
460 * Sleepable RCU that prevents destruction of MRs while they are still
461 * being used by a page fault handler.
462 */
463 struct srcu_struct mr_srcu;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200464#endif
Eli Cohene126ba92013-07-07 17:25:49 +0300465};
466
467static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
468{
469 return container_of(mcq, struct mlx5_ib_cq, mcq);
470}
471
472static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
473{
474 return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
475}
476
477static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
478{
479 return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
480}
481
Eli Cohene126ba92013-07-07 17:25:49 +0300482static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
483{
484 return container_of(ibcq, struct mlx5_ib_cq, ibcq);
485}
486
487static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
488{
489 return container_of(mqp, struct mlx5_ib_qp, mqp);
490}
491
Sagi Grimbergd5436ba2014-02-23 14:19:12 +0200492static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mr *mmr)
493{
494 return container_of(mmr, struct mlx5_ib_mr, mmr);
495}
496
Eli Cohene126ba92013-07-07 17:25:49 +0300497static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
498{
499 return container_of(ibpd, struct mlx5_ib_pd, ibpd);
500}
501
502static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
503{
504 return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
505}
506
507static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
508{
509 return container_of(ibqp, struct mlx5_ib_qp, ibqp);
510}
511
512static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
513{
514 return container_of(msrq, struct mlx5_ib_srq, msrq);
515}
516
517static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
518{
519 return container_of(ibmr, struct mlx5_ib_mr, ibmr);
520}
521
Eli Cohene126ba92013-07-07 17:25:49 +0300522struct mlx5_ib_ah {
523 struct ib_ah ibah;
524 struct mlx5_av av;
525};
526
527static inline struct mlx5_ib_ah *to_mah(struct ib_ah *ibah)
528{
529 return container_of(ibah, struct mlx5_ib_ah, ibah);
530}
531
Eli Cohene126ba92013-07-07 17:25:49 +0300532int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
533 struct mlx5_db *db);
534void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
535void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
536void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
537void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
538int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
Ira Weinya97e2d82015-05-31 17:15:30 -0400539 u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
540 const void *in_mad, void *response_mad);
Eli Cohene126ba92013-07-07 17:25:49 +0300541struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
542int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
543int mlx5_ib_destroy_ah(struct ib_ah *ah);
544struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
545 struct ib_srq_init_attr *init_attr,
546 struct ib_udata *udata);
547int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
548 enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
549int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
550int mlx5_ib_destroy_srq(struct ib_srq *srq);
551int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
552 struct ib_recv_wr **bad_wr);
553struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
554 struct ib_qp_init_attr *init_attr,
555 struct ib_udata *udata);
556int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
557 int attr_mask, struct ib_udata *udata);
558int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
559 struct ib_qp_init_attr *qp_init_attr);
560int mlx5_ib_destroy_qp(struct ib_qp *qp);
561int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
562 struct ib_send_wr **bad_wr);
563int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
564 struct ib_recv_wr **bad_wr);
565void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
Haggai Eranc1395a22014-12-11 17:04:14 +0200566int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
567 void *buffer, u32 length);
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300568struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
569 const struct ib_cq_init_attr *attr,
570 struct ib_ucontext *context,
Eli Cohene126ba92013-07-07 17:25:49 +0300571 struct ib_udata *udata);
572int mlx5_ib_destroy_cq(struct ib_cq *cq);
573int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
574int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
575int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
576int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
577struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
578struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
579 u64 virt_addr, int access_flags,
580 struct ib_udata *udata);
Haggai Eran832a6b02014-12-11 17:04:22 +0200581int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index,
582 int npages, int zap);
Eli Cohene126ba92013-07-07 17:25:49 +0300583int mlx5_ib_dereg_mr(struct ib_mr *ibmr);
Sagi Grimberg9bee1782015-07-30 10:32:35 +0300584struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd,
585 enum ib_mr_type mr_type,
586 u32 max_num_sg);
Sagi Grimberg8a187ee2015-10-13 19:11:26 +0300587int mlx5_ib_map_mr_sg(struct ib_mr *ibmr,
588 struct scatterlist *sg,
589 int sg_nents);
Eli Cohene126ba92013-07-07 17:25:49 +0300590int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -0400591 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -0400592 const struct ib_mad_hdr *in, size_t in_mad_size,
593 struct ib_mad_hdr *out, size_t *out_mad_size,
594 u16 *out_mad_pkey_index);
Eli Cohene126ba92013-07-07 17:25:49 +0300595struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
596 struct ib_ucontext *context,
597 struct ib_udata *udata);
598int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd);
Eli Cohene126ba92013-07-07 17:25:49 +0300599int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
600int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
Majd Dibbiny1b5daf12015-06-04 19:30:46 +0300601int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
602 struct ib_smp *out_mad);
603int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
604 __be64 *sys_image_guid);
605int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
606 u16 *max_pkeys);
607int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
608 u32 *vendor_id);
609int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
610int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
611int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
612 u16 *pkey);
613int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
614 union ib_gid *gid);
615int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
616 struct ib_port_attr *props);
Eli Cohene126ba92013-07-07 17:25:49 +0300617int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
618 struct ib_port_attr *props);
619int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
620void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
621void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift,
622 int *ncont, int *order);
Haggai Eran832a6b02014-12-11 17:04:22 +0200623void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
624 int page_shift, size_t offset, size_t num_pages,
625 __be64 *pas, int access_flags);
Eli Cohene126ba92013-07-07 17:25:49 +0300626void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
Haggai Erancc149f752014-12-11 17:04:21 +0200627 int page_shift, __be64 *pas, int access_flags);
Eli Cohene126ba92013-07-07 17:25:49 +0300628void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
629int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
630int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
631int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
632int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift);
633void mlx5_umr_cq_handler(struct ib_cq *cq, void *cq_context);
Sagi Grimbergd5436ba2014-02-23 14:19:12 +0200634int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
635 struct ib_mr_status *mr_status);
Eli Cohene126ba92013-07-07 17:25:49 +0300636
Haggai Eran8cdd3122014-12-11 17:04:20 +0200637#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
Haggai Eran6aec21f2014-12-11 17:04:23 +0200638extern struct workqueue_struct *mlx5_ib_page_fault_wq;
639
Saeed Mahameed938fe832015-05-28 22:28:41 +0300640void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
Haggai Eran6aec21f2014-12-11 17:04:23 +0200641void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
642 struct mlx5_ib_pfault *pfault);
643void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
644int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
645void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev);
646int __init mlx5_ib_odp_init(void);
647void mlx5_ib_odp_cleanup(void);
648void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
649void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
Haggai Eranb4cfe442014-12-11 17:04:26 +0200650void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
651 unsigned long end);
Haggai Eran6aec21f2014-12-11 17:04:23 +0200652
653#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
Saeed Mahameed938fe832015-05-28 22:28:41 +0300654static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
Haggai Eran8cdd3122014-12-11 17:04:20 +0200655{
Saeed Mahameed938fe832015-05-28 22:28:41 +0300656 return;
Haggai Eran8cdd3122014-12-11 17:04:20 +0200657}
Haggai Eran6aec21f2014-12-11 17:04:23 +0200658
659static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {}
660static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
661static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {}
662static inline int mlx5_ib_odp_init(void) { return 0; }
663static inline void mlx5_ib_odp_cleanup(void) {}
664static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {}
665static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {}
666
Haggai Eran8cdd3122014-12-11 17:04:20 +0200667#endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
668
Achiad Shochat2811ba52015-12-23 18:47:24 +0200669__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
670 int index);
671
Eli Cohene126ba92013-07-07 17:25:49 +0300672static inline void init_query_mad(struct ib_smp *mad)
673{
674 mad->base_version = 1;
675 mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
676 mad->class_version = 1;
677 mad->method = IB_MGMT_METHOD_GET;
678}
679
680static inline u8 convert_access(int acc)
681{
682 return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) |
683 (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) |
684 (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) |
685 (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) |
686 MLX5_PERM_LOCAL_READ;
687}
688
Sagi Grimbergb6364012015-09-02 22:23:04 +0300689static inline int is_qp1(enum ib_qp_type qp_type)
690{
691 return qp_type == IB_QPT_GSI;
692}
693
Haggai Erancc149f752014-12-11 17:04:21 +0200694#define MLX5_MAX_UMR_SHIFT 16
695#define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
696
Leon Romanovsky051f2632015-12-20 12:16:11 +0200697static inline u32 check_cq_create_flags(u32 flags)
698{
699 /*
700 * It returns non-zero value for unsupported CQ
701 * create flags, otherwise it returns zero.
702 */
703 return (flags & ~IB_CQ_FLAGS_IGNORE_OVERRUN);
704}
Haggai Abramovskycfb5e082016-01-14 19:12:57 +0200705
706static inline int verify_assign_uidx(u8 cqe_version, u32 cmd_uidx,
707 u32 *user_index)
708{
709 if (cqe_version) {
710 if ((cmd_uidx == MLX5_IB_DEFAULT_UIDX) ||
711 (cmd_uidx & ~MLX5_USER_ASSIGNED_UIDX_MASK))
712 return -EINVAL;
713 *user_index = cmd_uidx;
714 } else {
715 *user_index = MLX5_IB_DEFAULT_UIDX;
716 }
717
718 return 0;
719}
Eli Cohene126ba92013-07-07 17:25:49 +0300720#endif /* MLX5_IB_H */