Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1 | /* |
Saeed Mahameed | 6cf0a15 | 2015-04-02 17:07:30 +0300 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 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 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...) \ |
| 47 | pr_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...) \ |
| 51 | pr_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...) \ |
| 55 | pr_warn("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__, \ |
| 56 | __LINE__, current->pid, ##arg) |
| 57 | |
Matan Barak | b368d7c | 2015-12-15 20:30:12 +0200 | [diff] [blame^] | 58 | #define field_avail(type, fld, sz) (offsetof(type, fld) + \ |
| 59 | sizeof(((type *)0)->fld) <= (sz)) |
| 60 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 61 | enum { |
| 62 | MLX5_IB_MMAP_CMD_SHIFT = 8, |
| 63 | MLX5_IB_MMAP_CMD_MASK = 0xff, |
| 64 | }; |
| 65 | |
| 66 | enum mlx5_ib_mmap_cmd { |
| 67 | MLX5_IB_MMAP_REGULAR_PAGE = 0, |
| 68 | MLX5_IB_MMAP_GET_CONTIGUOUS_PAGES = 1, /* always last */ |
| 69 | }; |
| 70 | |
| 71 | enum { |
| 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 | |
| 78 | enum 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 | |
| 85 | enum 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 | |
| 91 | struct 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 | |
| 101 | static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext) |
| 102 | { |
| 103 | return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext); |
| 104 | } |
| 105 | |
| 106 | struct mlx5_ib_pd { |
| 107 | struct ib_pd ibpd; |
| 108 | u32 pdn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 109 | }; |
| 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 Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 116 | #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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 118 | #define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1 |
| 119 | #define MLX5_IB_WR_UMR IB_WR_RESERVED1 |
| 120 | |
| 121 | struct wr_list { |
| 122 | u16 opcode; |
| 123 | u16 next; |
| 124 | }; |
| 125 | |
| 126 | struct 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 | |
| 148 | enum { |
| 149 | MLX5_QP_USER, |
| 150 | MLX5_QP_KERNEL, |
| 151 | MLX5_QP_EMPTY |
| 152 | }; |
| 153 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 154 | /* |
| 155 | * Connect-IB can trigger up to four concurrent pagefaults |
| 156 | * per-QP. |
| 157 | */ |
| 158 | enum 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 | |
| 166 | static 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 | |
| 172 | struct mlx5_ib_pfault { |
| 173 | struct work_struct work; |
| 174 | struct mlx5_pagefault mpfault; |
| 175 | }; |
| 176 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 177 | struct 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 Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 218 | |
| 219 | /* Store signature errors */ |
| 220 | bool signature_en; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 221 | |
| 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | struct mlx5_ib_cq_buf { |
| 239 | struct mlx5_buf buf; |
| 240 | struct ib_umem *umem; |
| 241 | int cqe_size; |
Eli Cohen | bde5158 | 2014-01-14 17:45:18 +0200 | [diff] [blame] | 242 | int nent; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | enum mlx5_ib_qp_flags { |
| 246 | MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 0, |
| 247 | MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 1, |
| 248 | }; |
| 249 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 250 | struct mlx5_umr_wr { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 251 | struct ib_send_wr wr; |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 252 | 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 Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 264 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 269 | struct mlx5_shared_mr_info { |
| 270 | int mr_id; |
| 271 | struct ib_umem *umem; |
| 272 | }; |
| 273 | |
| 274 | struct 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 Cohen | bde5158 | 2014-01-14 17:45:18 +0200 | [diff] [blame] | 287 | struct mlx5_ib_cq_buf *resize_buf; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 288 | struct ib_umem *resize_umem; |
| 289 | int cqe_size; |
| 290 | }; |
| 291 | |
| 292 | struct 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 | |
| 311 | struct mlx5_ib_xrcd { |
| 312 | struct ib_xrcd ibxrcd; |
| 313 | u32 xrcdn; |
| 314 | }; |
| 315 | |
Haggai Eran | cc149f75 | 2014-12-11 17:04:21 +0200 | [diff] [blame] | 316 | enum 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 323 | struct mlx5_ib_mr { |
| 324 | struct ib_mr ibmr; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 325 | void *descs; |
| 326 | dma_addr_t desc_map; |
| 327 | int ndescs; |
| 328 | int max_descs; |
| 329 | int desc_size; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 330 | 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 336 | int npages; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 337 | struct mlx5_ib_dev *dev; |
| 338 | struct mlx5_create_mkey_mbox_out out; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 339 | struct mlx5_core_sig_ctx *sig; |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 340 | int live; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 341 | void *descs_alloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 342 | }; |
| 343 | |
Shachar Raindel | a74d241 | 2014-05-22 14:50:12 +0300 | [diff] [blame] | 344 | struct mlx5_ib_umr_context { |
| 345 | enum ib_wc_status status; |
| 346 | struct completion done; |
| 347 | }; |
| 348 | |
| 349 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 355 | struct umr_common { |
| 356 | struct ib_pd *pd; |
| 357 | struct ib_cq *cq; |
| 358 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 359 | /* control access to UMR QP |
| 360 | */ |
| 361 | struct semaphore sem; |
| 362 | }; |
| 363 | |
| 364 | enum { |
| 365 | MLX5_FMR_INVALID, |
| 366 | MLX5_FMR_VALID, |
| 367 | MLX5_FMR_BUSY, |
| 368 | }; |
| 369 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 370 | struct 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 Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 393 | int pending; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 394 | }; |
| 395 | |
| 396 | struct 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 | |
| 404 | struct 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 Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 410 | struct ib_srq *s1; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 411 | }; |
| 412 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 413 | struct 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 422 | struct mlx5_ib_dev { |
| 423 | struct ib_device ib_dev; |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 424 | struct mlx5_core_dev *mdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 425 | struct mlx5_roce roce; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 426 | MLX5_DECLARE_DOORBELL_LOCK(uar_lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 427 | int num_ports; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 428 | /* 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 435 | struct mlx5_ib_resources devr; |
| 436 | struct mlx5_mr_cache cache; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 437 | struct timer_list delay_timer; |
| 438 | int fill_delay; |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 439 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 440 | struct ib_odp_caps odp_caps; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 441 | /* |
| 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 Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 446 | #endif |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 447 | }; |
| 448 | |
| 449 | static 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 | |
| 454 | static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd) |
| 455 | { |
| 456 | return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd); |
| 457 | } |
| 458 | |
| 459 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 464 | static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq) |
| 465 | { |
| 466 | return container_of(ibcq, struct mlx5_ib_cq, ibcq); |
| 467 | } |
| 468 | |
| 469 | static 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 Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 474 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 479 | static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd) |
| 480 | { |
| 481 | return container_of(ibpd, struct mlx5_ib_pd, ibpd); |
| 482 | } |
| 483 | |
| 484 | static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq) |
| 485 | { |
| 486 | return container_of(ibsrq, struct mlx5_ib_srq, ibsrq); |
| 487 | } |
| 488 | |
| 489 | static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp) |
| 490 | { |
| 491 | return container_of(ibqp, struct mlx5_ib_qp, ibqp); |
| 492 | } |
| 493 | |
| 494 | static 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 | |
| 499 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 504 | struct mlx5_ib_ah { |
| 505 | struct ib_ah ibah; |
| 506 | struct mlx5_av av; |
| 507 | }; |
| 508 | |
| 509 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 514 | int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt, |
| 515 | struct mlx5_db *db); |
| 516 | void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db); |
| 517 | void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq); |
| 518 | void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq); |
| 519 | void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index); |
| 520 | int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey, |
Ira Weiny | a97e2d8 | 2015-05-31 17:15:30 -0400 | [diff] [blame] | 521 | u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh, |
| 522 | const void *in_mad, void *response_mad); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 523 | struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr); |
| 524 | int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr); |
| 525 | int mlx5_ib_destroy_ah(struct ib_ah *ah); |
| 526 | struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd, |
| 527 | struct ib_srq_init_attr *init_attr, |
| 528 | struct ib_udata *udata); |
| 529 | int 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); |
| 531 | int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr); |
| 532 | int mlx5_ib_destroy_srq(struct ib_srq *srq); |
| 533 | int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr, |
| 534 | struct ib_recv_wr **bad_wr); |
| 535 | struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd, |
| 536 | struct ib_qp_init_attr *init_attr, |
| 537 | struct ib_udata *udata); |
| 538 | int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 539 | int attr_mask, struct ib_udata *udata); |
| 540 | int 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); |
| 542 | int mlx5_ib_destroy_qp(struct ib_qp *qp); |
| 543 | int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, |
| 544 | struct ib_send_wr **bad_wr); |
| 545 | int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr, |
| 546 | struct ib_recv_wr **bad_wr); |
| 547 | void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 548 | int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index, |
| 549 | void *buffer, u32 length); |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 550 | struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev, |
| 551 | const struct ib_cq_init_attr *attr, |
| 552 | struct ib_ucontext *context, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 553 | struct ib_udata *udata); |
| 554 | int mlx5_ib_destroy_cq(struct ib_cq *cq); |
| 555 | int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc); |
| 556 | int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags); |
| 557 | int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period); |
| 558 | int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata); |
| 559 | struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc); |
| 560 | struct 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 Eran | 832a6b0 | 2014-12-11 17:04:22 +0200 | [diff] [blame] | 563 | int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index, |
| 564 | int npages, int zap); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 565 | int mlx5_ib_dereg_mr(struct ib_mr *ibmr); |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 566 | struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd, |
| 567 | enum ib_mr_type mr_type, |
| 568 | u32 max_num_sg); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 569 | int mlx5_ib_map_mr_sg(struct ib_mr *ibmr, |
| 570 | struct scatterlist *sg, |
| 571 | int sg_nents); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 572 | int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num, |
Ira Weiny | a97e2d8 | 2015-05-31 17:15:30 -0400 | [diff] [blame] | 573 | const struct ib_wc *in_wc, const struct ib_grh *in_grh, |
Ira Weiny | 4cd7c94 | 2015-06-06 14:38:31 -0400 | [diff] [blame] | 574 | 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 577 | struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev, |
| 578 | struct ib_ucontext *context, |
| 579 | struct ib_udata *udata); |
| 580 | int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 581 | int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset); |
| 582 | int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port); |
Majd Dibbiny | 1b5daf1 | 2015-06-04 19:30:46 +0300 | [diff] [blame] | 583 | int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev, |
| 584 | struct ib_smp *out_mad); |
| 585 | int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev, |
| 586 | __be64 *sys_image_guid); |
| 587 | int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev, |
| 588 | u16 *max_pkeys); |
| 589 | int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev, |
| 590 | u32 *vendor_id); |
| 591 | int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc); |
| 592 | int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid); |
| 593 | int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 594 | u16 *pkey); |
| 595 | int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index, |
| 596 | union ib_gid *gid); |
| 597 | int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port, |
| 598 | struct ib_port_attr *props); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 599 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 600 | struct ib_port_attr *props); |
| 601 | int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev); |
| 602 | void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev); |
| 603 | void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift, |
| 604 | int *ncont, int *order); |
Haggai Eran | 832a6b0 | 2014-12-11 17:04:22 +0200 | [diff] [blame] | 605 | void __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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 608 | void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem, |
Haggai Eran | cc149f75 | 2014-12-11 17:04:21 +0200 | [diff] [blame] | 609 | int page_shift, __be64 *pas, int access_flags); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 610 | void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num); |
| 611 | int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq); |
| 612 | int mlx5_mr_cache_init(struct mlx5_ib_dev *dev); |
| 613 | int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev); |
| 614 | int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift); |
| 615 | void mlx5_umr_cq_handler(struct ib_cq *cq, void *cq_context); |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 616 | int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask, |
| 617 | struct ib_mr_status *mr_status); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 618 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 619 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 620 | extern struct workqueue_struct *mlx5_ib_page_fault_wq; |
| 621 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 622 | void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 623 | void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp, |
| 624 | struct mlx5_ib_pfault *pfault); |
| 625 | void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp); |
| 626 | int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev); |
| 627 | void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev); |
| 628 | int __init mlx5_ib_odp_init(void); |
| 629 | void mlx5_ib_odp_cleanup(void); |
| 630 | void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp); |
| 631 | void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp); |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 632 | void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, |
| 633 | unsigned long end); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 634 | |
| 635 | #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */ |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 636 | static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev) |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 637 | { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 638 | return; |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 639 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 640 | |
| 641 | static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {} |
| 642 | static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; } |
| 643 | static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {} |
| 644 | static inline int mlx5_ib_odp_init(void) { return 0; } |
| 645 | static inline void mlx5_ib_odp_cleanup(void) {} |
| 646 | static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {} |
| 647 | static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {} |
| 648 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 649 | #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */ |
| 650 | |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 651 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num, |
| 652 | int index); |
| 653 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 654 | static 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 | |
| 662 | static 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 Grimberg | b636401 | 2015-09-02 22:23:04 +0300 | [diff] [blame] | 671 | static inline int is_qp1(enum ib_qp_type qp_type) |
| 672 | { |
| 673 | return qp_type == IB_QPT_GSI; |
| 674 | } |
| 675 | |
Haggai Eran | cc149f75 | 2014-12-11 17:04:21 +0200 | [diff] [blame] | 676 | #define MLX5_MAX_UMR_SHIFT 16 |
| 677 | #define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT) |
| 678 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 679 | #endif /* MLX5_IB_H */ |