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, |
Matan Barak | d69e3bc | 2015-12-15 20:30:13 +0200 | [diff] [blame] | 68 | 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | enum { |
| 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 | |
| 80 | enum 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 | |
| 87 | enum 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 Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame^] | 93 | enum { |
| 94 | MLX5_CROSS_CHANNEL_UUAR = 0, |
| 95 | }; |
| 96 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 97 | struct 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 | |
| 107 | static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext) |
| 108 | { |
| 109 | return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext); |
| 110 | } |
| 111 | |
| 112 | struct mlx5_ib_pd { |
| 113 | struct ib_pd ibpd; |
| 114 | u32 pdn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 115 | }; |
| 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 Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 122 | #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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 124 | #define MLX5_IB_QPT_REG_UMR IB_QPT_RESERVED1 |
| 125 | #define MLX5_IB_WR_UMR IB_WR_RESERVED1 |
| 126 | |
| 127 | struct wr_list { |
| 128 | u16 opcode; |
| 129 | u16 next; |
| 130 | }; |
| 131 | |
| 132 | struct 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 | |
| 154 | enum { |
| 155 | MLX5_QP_USER, |
| 156 | MLX5_QP_KERNEL, |
| 157 | MLX5_QP_EMPTY |
| 158 | }; |
| 159 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 160 | /* |
| 161 | * Connect-IB can trigger up to four concurrent pagefaults |
| 162 | * per-QP. |
| 163 | */ |
| 164 | enum 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 | |
| 172 | static 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 | |
| 178 | struct mlx5_ib_pfault { |
| 179 | struct work_struct work; |
| 180 | struct mlx5_pagefault mpfault; |
| 181 | }; |
| 182 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 183 | struct 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 Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 224 | |
| 225 | /* Store signature errors */ |
| 226 | bool signature_en; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 227 | |
| 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | struct mlx5_ib_cq_buf { |
| 245 | struct mlx5_buf buf; |
| 246 | struct ib_umem *umem; |
| 247 | int cqe_size; |
Eli Cohen | bde5158 | 2014-01-14 17:45:18 +0200 | [diff] [blame] | 248 | int nent; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | enum mlx5_ib_qp_flags { |
| 252 | MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 0, |
| 253 | MLX5_IB_QP_SIGNATURE_HANDLING = 1 << 1, |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame^] | 254 | MLX5_IB_QP_CROSS_CHANNEL = 1 << 2, |
| 255 | MLX5_IB_QP_MANAGED_SEND = 1 << 3, |
| 256 | MLX5_IB_QP_MANAGED_RECV = 1 << 4, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 257 | }; |
| 258 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 259 | struct mlx5_umr_wr { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 260 | struct ib_send_wr wr; |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 261 | 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 Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 273 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 278 | struct mlx5_shared_mr_info { |
| 279 | int mr_id; |
| 280 | struct ib_umem *umem; |
| 281 | }; |
| 282 | |
| 283 | struct 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 Cohen | bde5158 | 2014-01-14 17:45:18 +0200 | [diff] [blame] | 296 | struct mlx5_ib_cq_buf *resize_buf; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 297 | struct ib_umem *resize_umem; |
| 298 | int cqe_size; |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame^] | 299 | u32 create_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | struct 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 | |
| 321 | struct mlx5_ib_xrcd { |
| 322 | struct ib_xrcd ibxrcd; |
| 323 | u32 xrcdn; |
| 324 | }; |
| 325 | |
Haggai Eran | cc149f75 | 2014-12-11 17:04:21 +0200 | [diff] [blame] | 326 | enum 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 333 | struct mlx5_ib_mr { |
| 334 | struct ib_mr ibmr; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 335 | void *descs; |
| 336 | dma_addr_t desc_map; |
| 337 | int ndescs; |
| 338 | int max_descs; |
| 339 | int desc_size; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 340 | 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 346 | int npages; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 347 | struct mlx5_ib_dev *dev; |
| 348 | struct mlx5_create_mkey_mbox_out out; |
Sagi Grimberg | 3121e3c | 2014-02-23 14:19:06 +0200 | [diff] [blame] | 349 | struct mlx5_core_sig_ctx *sig; |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 350 | int live; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 351 | void *descs_alloc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 352 | }; |
| 353 | |
Shachar Raindel | a74d241 | 2014-05-22 14:50:12 +0300 | [diff] [blame] | 354 | struct mlx5_ib_umr_context { |
| 355 | enum ib_wc_status status; |
| 356 | struct completion done; |
| 357 | }; |
| 358 | |
| 359 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 365 | struct umr_common { |
| 366 | struct ib_pd *pd; |
| 367 | struct ib_cq *cq; |
| 368 | struct ib_qp *qp; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 369 | /* control access to UMR QP |
| 370 | */ |
| 371 | struct semaphore sem; |
| 372 | }; |
| 373 | |
| 374 | enum { |
| 375 | MLX5_FMR_INVALID, |
| 376 | MLX5_FMR_VALID, |
| 377 | MLX5_FMR_BUSY, |
| 378 | }; |
| 379 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 380 | struct 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 Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 403 | int pending; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | struct 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 | |
| 414 | struct 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 Abramonvsky | 4aa17b2 | 2015-06-04 19:30:48 +0300 | [diff] [blame] | 420 | struct ib_srq *s1; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 421 | }; |
| 422 | |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 423 | struct 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 432 | struct mlx5_ib_dev { |
| 433 | struct ib_device ib_dev; |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 434 | struct mlx5_core_dev *mdev; |
Achiad Shochat | fc24fc5 | 2015-12-23 18:47:17 +0200 | [diff] [blame] | 435 | struct mlx5_roce roce; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 436 | MLX5_DECLARE_DOORBELL_LOCK(uar_lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 437 | int num_ports; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 438 | /* 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 445 | struct mlx5_ib_resources devr; |
| 446 | struct mlx5_mr_cache cache; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 447 | struct timer_list delay_timer; |
| 448 | int fill_delay; |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 449 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
| 450 | struct ib_odp_caps odp_caps; |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 451 | /* |
| 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 Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 456 | #endif |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | static 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 | |
| 464 | static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd) |
| 465 | { |
| 466 | return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd); |
| 467 | } |
| 468 | |
| 469 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 474 | static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq) |
| 475 | { |
| 476 | return container_of(ibcq, struct mlx5_ib_cq, ibcq); |
| 477 | } |
| 478 | |
| 479 | static 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 Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 484 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 489 | static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd) |
| 490 | { |
| 491 | return container_of(ibpd, struct mlx5_ib_pd, ibpd); |
| 492 | } |
| 493 | |
| 494 | static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq) |
| 495 | { |
| 496 | return container_of(ibsrq, struct mlx5_ib_srq, ibsrq); |
| 497 | } |
| 498 | |
| 499 | static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp) |
| 500 | { |
| 501 | return container_of(ibqp, struct mlx5_ib_qp, ibqp); |
| 502 | } |
| 503 | |
| 504 | static 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 | |
| 509 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 514 | struct mlx5_ib_ah { |
| 515 | struct ib_ah ibah; |
| 516 | struct mlx5_av av; |
| 517 | }; |
| 518 | |
| 519 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 524 | int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt, |
| 525 | struct mlx5_db *db); |
| 526 | void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db); |
| 527 | void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq); |
| 528 | void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq); |
| 529 | void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index); |
| 530 | 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] | 531 | u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh, |
| 532 | const void *in_mad, void *response_mad); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 533 | struct ib_ah *mlx5_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr); |
| 534 | int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr); |
| 535 | int mlx5_ib_destroy_ah(struct ib_ah *ah); |
| 536 | struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd, |
| 537 | struct ib_srq_init_attr *init_attr, |
| 538 | struct ib_udata *udata); |
| 539 | int 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); |
| 541 | int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr); |
| 542 | int mlx5_ib_destroy_srq(struct ib_srq *srq); |
| 543 | int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr, |
| 544 | struct ib_recv_wr **bad_wr); |
| 545 | struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd, |
| 546 | struct ib_qp_init_attr *init_attr, |
| 547 | struct ib_udata *udata); |
| 548 | int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 549 | int attr_mask, struct ib_udata *udata); |
| 550 | int 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); |
| 552 | int mlx5_ib_destroy_qp(struct ib_qp *qp); |
| 553 | int mlx5_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, |
| 554 | struct ib_send_wr **bad_wr); |
| 555 | int mlx5_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr, |
| 556 | struct ib_recv_wr **bad_wr); |
| 557 | void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 558 | int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index, |
| 559 | void *buffer, u32 length); |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 560 | struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev, |
| 561 | const struct ib_cq_init_attr *attr, |
| 562 | struct ib_ucontext *context, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 563 | struct ib_udata *udata); |
| 564 | int mlx5_ib_destroy_cq(struct ib_cq *cq); |
| 565 | int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc); |
| 566 | int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags); |
| 567 | int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period); |
| 568 | int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata); |
| 569 | struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc); |
| 570 | struct 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 Eran | 832a6b0 | 2014-12-11 17:04:22 +0200 | [diff] [blame] | 573 | int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index, |
| 574 | int npages, int zap); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 575 | int mlx5_ib_dereg_mr(struct ib_mr *ibmr); |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 576 | struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd, |
| 577 | enum ib_mr_type mr_type, |
| 578 | u32 max_num_sg); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 579 | int mlx5_ib_map_mr_sg(struct ib_mr *ibmr, |
| 580 | struct scatterlist *sg, |
| 581 | int sg_nents); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 582 | 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] | 583 | const struct ib_wc *in_wc, const struct ib_grh *in_grh, |
Ira Weiny | 4cd7c94 | 2015-06-06 14:38:31 -0400 | [diff] [blame] | 584 | 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 587 | struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev, |
| 588 | struct ib_ucontext *context, |
| 589 | struct ib_udata *udata); |
| 590 | int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 591 | int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset); |
| 592 | 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] | 593 | int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev, |
| 594 | struct ib_smp *out_mad); |
| 595 | int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev, |
| 596 | __be64 *sys_image_guid); |
| 597 | int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev, |
| 598 | u16 *max_pkeys); |
| 599 | int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev, |
| 600 | u32 *vendor_id); |
| 601 | int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc); |
| 602 | int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid); |
| 603 | int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 604 | u16 *pkey); |
| 605 | int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index, |
| 606 | union ib_gid *gid); |
| 607 | int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port, |
| 608 | struct ib_port_attr *props); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 609 | int mlx5_ib_query_port(struct ib_device *ibdev, u8 port, |
| 610 | struct ib_port_attr *props); |
| 611 | int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev); |
| 612 | void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev); |
| 613 | void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift, |
| 614 | int *ncont, int *order); |
Haggai Eran | 832a6b0 | 2014-12-11 17:04:22 +0200 | [diff] [blame] | 615 | void __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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 618 | 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] | 619 | int page_shift, __be64 *pas, int access_flags); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 620 | void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num); |
| 621 | int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq); |
| 622 | int mlx5_mr_cache_init(struct mlx5_ib_dev *dev); |
| 623 | int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev); |
| 624 | int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift); |
| 625 | void mlx5_umr_cq_handler(struct ib_cq *cq, void *cq_context); |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 626 | int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask, |
| 627 | struct ib_mr_status *mr_status); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 628 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 629 | #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 630 | extern struct workqueue_struct *mlx5_ib_page_fault_wq; |
| 631 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 632 | void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 633 | void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp, |
| 634 | struct mlx5_ib_pfault *pfault); |
| 635 | void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp); |
| 636 | int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev); |
| 637 | void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev); |
| 638 | int __init mlx5_ib_odp_init(void); |
| 639 | void mlx5_ib_odp_cleanup(void); |
| 640 | void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp); |
| 641 | void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp); |
Haggai Eran | b4cfe44 | 2014-12-11 17:04:26 +0200 | [diff] [blame] | 642 | void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start, |
| 643 | unsigned long end); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 644 | |
| 645 | #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */ |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 646 | 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] | 647 | { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 648 | return; |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 649 | } |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 650 | |
| 651 | static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp) {} |
| 652 | static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; } |
| 653 | static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev) {} |
| 654 | static inline int mlx5_ib_odp_init(void) { return 0; } |
| 655 | static inline void mlx5_ib_odp_cleanup(void) {} |
| 656 | static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {} |
| 657 | static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp) {} |
| 658 | |
Haggai Eran | 8cdd312 | 2014-12-11 17:04:20 +0200 | [diff] [blame] | 659 | #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */ |
| 660 | |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 661 | __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num, |
| 662 | int index); |
| 663 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 664 | static 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 | |
| 672 | static 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 Grimberg | b636401 | 2015-09-02 22:23:04 +0300 | [diff] [blame] | 681 | static inline int is_qp1(enum ib_qp_type qp_type) |
| 682 | { |
| 683 | return qp_type == IB_QPT_GSI; |
| 684 | } |
| 685 | |
Haggai Eran | cc149f75 | 2014-12-11 17:04:21 +0200 | [diff] [blame] | 686 | #define MLX5_MAX_UMR_SHIFT 16 |
| 687 | #define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT) |
| 688 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame^] | 689 | static 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 Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 697 | #endif /* MLX5_IB_H */ |