1 /* 2 * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved. 3 * Copyright (c) 2004 Infinicon Corporation. All rights reserved. 4 * Copyright (c) 2004 Intel Corporation. All rights reserved. 5 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 8 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved. 9 * 10 * This software is available to you under a choice of one of two 11 * licenses. You may choose to be licensed under the terms of the GNU 12 * General Public License (GPL) Version 2, available from the file 13 * COPYING in the main directory of this source tree, or the 14 * OpenIB.org BSD license below: 15 * 16 * Redistribution and use in source and binary forms, with or 17 * without modification, are permitted provided that the following 18 * conditions are met: 19 * 20 * - Redistributions of source code must retain the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer. 23 * 24 * - Redistributions in binary form must reproduce the above 25 * copyright notice, this list of conditions and the following 26 * disclaimer in the documentation and/or other materials 27 * provided with the distribution. 28 * 29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 33 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 34 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 * SOFTWARE. 37 */ 38 39 #if !defined(IB_VERBS_H) 40 #define IB_VERBS_H 41 42 #include <linux/types.h> 43 #include <linux/device.h> 44 #include <linux/mm.h> 45 #include <linux/dma-mapping.h> 46 #include <linux/kref.h> 47 #include <linux/list.h> 48 #include <linux/rwsem.h> 49 #include <linux/scatterlist.h> 50 #include <linux/workqueue.h> 51 #include <linux/if_ether.h> 52 #include <linux/mutex.h> 53 54 #include <asm/uaccess.h> 55 56 extern struct workqueue_struct *ib_wq; 57 58 union ib_gid { 59 u8 raw[16]; 60 struct { 61 __be64 subnet_prefix; 62 __be64 interface_id; 63 } global; 64 }; 65 66 enum rdma_node_type { 67 /* IB values map to NodeInfo:NodeType. */ 68 RDMA_NODE_IB_CA = 1, 69 RDMA_NODE_IB_SWITCH, 70 RDMA_NODE_IB_ROUTER, 71 RDMA_NODE_RNIC, 72 RDMA_NODE_MIC 73 }; 74 75 enum rdma_transport_type { 76 RDMA_TRANSPORT_IB, 77 RDMA_TRANSPORT_IWARP, 78 RDMA_TRANSPORT_SCIF 79 }; 80 81 enum rdma_transport_type 82 rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__; 83 84 enum rdma_link_layer { 85 IB_LINK_LAYER_UNSPECIFIED, 86 IB_LINK_LAYER_INFINIBAND, 87 IB_LINK_LAYER_ETHERNET, 88 IB_LINK_LAYER_SCIF 89 }; 90 91 enum ib_device_cap_flags { 92 IB_DEVICE_RESIZE_MAX_WR = 1, 93 IB_DEVICE_BAD_PKEY_CNTR = (1<<1), 94 IB_DEVICE_BAD_QKEY_CNTR = (1<<2), 95 IB_DEVICE_RAW_MULTI = (1<<3), 96 IB_DEVICE_AUTO_PATH_MIG = (1<<4), 97 IB_DEVICE_CHANGE_PHY_PORT = (1<<5), 98 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6), 99 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7), 100 IB_DEVICE_SHUTDOWN_PORT = (1<<8), 101 IB_DEVICE_INIT_TYPE = (1<<9), 102 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10), 103 IB_DEVICE_SYS_IMAGE_GUID = (1<<11), 104 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12), 105 IB_DEVICE_SRQ_RESIZE = (1<<13), 106 IB_DEVICE_N_NOTIFY_CQ = (1<<14), 107 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15), 108 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */ 109 IB_DEVICE_MEM_WINDOW = (1<<17), 110 /* 111 * Devices should set IB_DEVICE_UD_IP_SUM if they support 112 * insertion of UDP and TCP checksum on outgoing UD IPoIB 113 * messages and can verify the validity of checksum for 114 * incoming messages. Setting this flag implies that the 115 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode. 116 */ 117 IB_DEVICE_UD_IP_CSUM = (1<<18), 118 IB_DEVICE_UD_TSO = (1<<19), 119 IB_DEVICE_XRC = (1<<20), 120 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21), 121 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22), 122 IB_DEVICE_MR_ALLOCATE = (1<<23), 123 IB_DEVICE_SHARED_MR = (1<<24), 124 IB_DEVICE_QPG = (1<<25), 125 IB_DEVICE_UD_RSS = (1<<26), 126 IB_DEVICE_UD_TSS = (1<<27), 127 IB_DEVICE_CROSS_CHANNEL = (1<<28), 128 IB_DEVICE_MANAGED_FLOW_STEERING = (1<<29), 129 /* 130 * Devices can set either IB_DEVICE_MEM_WINDOW_TYPE_2A or 131 * IB_DEVICE_MEM_WINDOW_TYPE_2B if it supports type 2A or type 2B 132 * memory windows. It can set neither to indicate it doesn't support 133 * type 2 windows at all. 134 */ 135 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1<<30), 136 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1<<31), 137 IB_DEVICE_SIGNATURE_HANDOVER = (1LL<<32) 138 }; 139 140 enum ib_signature_prot_cap { 141 IB_PROT_T10DIF_TYPE_1 = 1, 142 IB_PROT_T10DIF_TYPE_2 = 1 << 1, 143 IB_PROT_T10DIF_TYPE_3 = 1 << 2, 144 }; 145 146 enum ib_signature_guard_cap { 147 IB_GUARD_T10DIF_CRC = 1, 148 IB_GUARD_T10DIF_CSUM = 1 << 1, 149 }; 150 151 enum ib_atomic_cap { 152 IB_ATOMIC_NONE, 153 IB_ATOMIC_HCA, 154 IB_ATOMIC_GLOB 155 }; 156 157 enum ib_cq_create_flags { 158 IB_CQ_CREATE_CROSS_CHANNEL = 1 << 0, 159 IB_CQ_TIMESTAMP = 1 << 1, 160 IB_CQ_TIMESTAMP_TO_SYS_TIME = 1 << 2 161 }; 162 163 struct ib_device_attr { 164 u64 fw_ver; 165 __be64 sys_image_guid; 166 u64 max_mr_size; 167 u64 page_size_cap; 168 u32 vendor_id; 169 u32 vendor_part_id; 170 u32 hw_ver; 171 int max_qp; 172 int max_qp_wr; 173 u64 device_cap_flags; 174 int max_sge; 175 int max_sge_rd; 176 int max_cq; 177 int max_cqe; 178 int max_mr; 179 int max_pd; 180 int max_qp_rd_atom; 181 int max_ee_rd_atom; 182 int max_res_rd_atom; 183 int max_qp_init_rd_atom; 184 int max_ee_init_rd_atom; 185 enum ib_atomic_cap atomic_cap; 186 enum ib_atomic_cap masked_atomic_cap; 187 int max_ee; 188 int max_rdd; 189 int max_mw; 190 int max_raw_ipv6_qp; 191 int max_raw_ethy_qp; 192 int max_mcast_grp; 193 int max_mcast_qp_attach; 194 int max_total_mcast_qp_attach; 195 int max_ah; 196 int max_fmr; 197 int max_map_per_fmr; 198 int max_srq; 199 int max_srq_wr; 200 int max_srq_sge; 201 unsigned int max_fast_reg_page_list_len; 202 int max_rss_tbl_sz; 203 u16 max_pkeys; 204 u8 local_ca_ack_delay; 205 int comp_mask; 206 uint64_t timestamp_mask; 207 uint64_t hca_core_clock; 208 unsigned int sig_prot_cap; 209 unsigned int sig_guard_cap; 210 }; 211 212 enum ib_device_attr_comp_mask { 213 IB_DEVICE_ATTR_WITH_TIMESTAMP_MASK = 1ULL << 1, 214 IB_DEVICE_ATTR_WITH_HCA_CORE_CLOCK = 1ULL << 2 215 }; 216 217 enum ib_mtu { 218 IB_MTU_256 = 1, 219 IB_MTU_512 = 2, 220 IB_MTU_1024 = 3, 221 IB_MTU_2048 = 4, 222 IB_MTU_4096 = 5 223 }; 224 225 static inline int ib_mtu_enum_to_int(enum ib_mtu mtu) 226 { 227 switch (mtu) { 228 case IB_MTU_256: return 256; 229 case IB_MTU_512: return 512; 230 case IB_MTU_1024: return 1024; 231 case IB_MTU_2048: return 2048; 232 case IB_MTU_4096: return 4096; 233 default: return -1; 234 } 235 } 236 237 enum ib_port_state { 238 IB_PORT_NOP = 0, 239 IB_PORT_DOWN = 1, 240 IB_PORT_INIT = 2, 241 IB_PORT_ARMED = 3, 242 IB_PORT_ACTIVE = 4, 243 IB_PORT_ACTIVE_DEFER = 5, 244 IB_PORT_DUMMY = -1 /* force enum signed */ 245 }; 246 247 enum ib_port_cap_flags { 248 IB_PORT_SM = 1 << 1, 249 IB_PORT_NOTICE_SUP = 1 << 2, 250 IB_PORT_TRAP_SUP = 1 << 3, 251 IB_PORT_OPT_IPD_SUP = 1 << 4, 252 IB_PORT_AUTO_MIGR_SUP = 1 << 5, 253 IB_PORT_SL_MAP_SUP = 1 << 6, 254 IB_PORT_MKEY_NVRAM = 1 << 7, 255 IB_PORT_PKEY_NVRAM = 1 << 8, 256 IB_PORT_LED_INFO_SUP = 1 << 9, 257 IB_PORT_SM_DISABLED = 1 << 10, 258 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11, 259 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12, 260 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14, 261 IB_PORT_CM_SUP = 1 << 16, 262 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17, 263 IB_PORT_REINIT_SUP = 1 << 18, 264 IB_PORT_DEVICE_MGMT_SUP = 1 << 19, 265 IB_PORT_VENDOR_CLASS_SUP = 1 << 20, 266 IB_PORT_DR_NOTICE_SUP = 1 << 21, 267 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22, 268 IB_PORT_BOOT_MGMT_SUP = 1 << 23, 269 IB_PORT_LINK_LATENCY_SUP = 1 << 24, 270 IB_PORT_CLIENT_REG_SUP = 1 << 25 271 }; 272 273 enum ib_port_width { 274 IB_WIDTH_1X = 1, 275 IB_WIDTH_4X = 2, 276 IB_WIDTH_8X = 4, 277 IB_WIDTH_12X = 8 278 }; 279 280 static inline int ib_width_enum_to_int(enum ib_port_width width) 281 { 282 switch (width) { 283 case IB_WIDTH_1X: return 1; 284 case IB_WIDTH_4X: return 4; 285 case IB_WIDTH_8X: return 8; 286 case IB_WIDTH_12X: return 12; 287 default: return -1; 288 } 289 } 290 291 enum ib_port_speed { 292 IB_SPEED_SDR = 1, 293 IB_SPEED_DDR = 2, 294 IB_SPEED_QDR = 4, 295 IB_SPEED_FDR10 = 8, 296 IB_SPEED_FDR = 16, 297 IB_SPEED_EDR = 32 298 }; 299 300 struct ib_protocol_stats { 301 /* TBD... */ 302 }; 303 304 struct iw_protocol_stats { 305 u64 ipInReceives; 306 u64 ipInHdrErrors; 307 u64 ipInTooBigErrors; 308 u64 ipInNoRoutes; 309 u64 ipInAddrErrors; 310 u64 ipInUnknownProtos; 311 u64 ipInTruncatedPkts; 312 u64 ipInDiscards; 313 u64 ipInDelivers; 314 u64 ipOutForwDatagrams; 315 u64 ipOutRequests; 316 u64 ipOutDiscards; 317 u64 ipOutNoRoutes; 318 u64 ipReasmTimeout; 319 u64 ipReasmReqds; 320 u64 ipReasmOKs; 321 u64 ipReasmFails; 322 u64 ipFragOKs; 323 u64 ipFragFails; 324 u64 ipFragCreates; 325 u64 ipInMcastPkts; 326 u64 ipOutMcastPkts; 327 u64 ipInBcastPkts; 328 u64 ipOutBcastPkts; 329 330 u64 tcpRtoAlgorithm; 331 u64 tcpRtoMin; 332 u64 tcpRtoMax; 333 u64 tcpMaxConn; 334 u64 tcpActiveOpens; 335 u64 tcpPassiveOpens; 336 u64 tcpAttemptFails; 337 u64 tcpEstabResets; 338 u64 tcpCurrEstab; 339 u64 tcpInSegs; 340 u64 tcpOutSegs; 341 u64 tcpRetransSegs; 342 u64 tcpInErrs; 343 u64 tcpOutRsts; 344 }; 345 346 union rdma_protocol_stats { 347 struct ib_protocol_stats ib; 348 struct iw_protocol_stats iw; 349 }; 350 351 /* Define bits for the various functionality this port needs to be supported by 352 * the core. 353 */ 354 /* Management 0x00000FFF */ 355 #define RDMA_CORE_CAP_IB_MAD 0x00000001 356 #define RDMA_CORE_CAP_IB_SMI 0x00000002 357 #define RDMA_CORE_CAP_IB_CM 0x00000004 358 #define RDMA_CORE_CAP_IW_CM 0x00000008 359 #define RDMA_CORE_CAP_IB_SA 0x00000010 360 #define RDMA_CORE_CAP_OPA_MAD 0x00000020 361 362 /* Address format 0x000FF000 */ 363 #define RDMA_CORE_CAP_AF_IB 0x00001000 364 #define RDMA_CORE_CAP_ETH_AH 0x00002000 365 #define RDMA_CORE_CAP_OPA_AH 0x00004000 366 367 /* Protocol 0xFFF00000 */ 368 #define RDMA_CORE_CAP_PROT_IB 0x00100000 369 #define RDMA_CORE_CAP_PROT_ROCE 0x00200000 370 #define RDMA_CORE_CAP_PROT_IWARP 0x00400000 371 #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000 372 #define RDMA_CORE_CAP_PROT_RAW_PACKET 0x01000000 373 #define RDMA_CORE_CAP_PROT_USNIC 0x02000000 374 375 #define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \ 376 | RDMA_CORE_CAP_IB_MAD \ 377 | RDMA_CORE_CAP_IB_SMI \ 378 | RDMA_CORE_CAP_IB_CM \ 379 | RDMA_CORE_CAP_IB_SA \ 380 | RDMA_CORE_CAP_AF_IB) 381 #define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \ 382 | RDMA_CORE_CAP_IB_MAD \ 383 | RDMA_CORE_CAP_IB_CM \ 384 | RDMA_CORE_CAP_AF_IB \ 385 | RDMA_CORE_CAP_ETH_AH) 386 #define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \ 387 (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \ 388 | RDMA_CORE_CAP_IB_MAD \ 389 | RDMA_CORE_CAP_IB_CM \ 390 | RDMA_CORE_CAP_AF_IB \ 391 | RDMA_CORE_CAP_ETH_AH) 392 #define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \ 393 | RDMA_CORE_CAP_IW_CM) 394 #define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \ 395 | RDMA_CORE_CAP_OPA_MAD) 396 397 #define RDMA_CORE_PORT_RAW_PACKET (RDMA_CORE_CAP_PROT_RAW_PACKET) 398 399 #define RDMA_CORE_PORT_USNIC (RDMA_CORE_CAP_PROT_USNIC) 400 401 struct ib_port_attr { 402 enum ib_port_state state; 403 enum ib_mtu max_mtu; 404 enum ib_mtu active_mtu; 405 int gid_tbl_len; 406 u32 port_cap_flags; 407 u32 max_msg_sz; 408 u32 bad_pkey_cntr; 409 u32 qkey_viol_cntr; 410 u16 pkey_tbl_len; 411 u16 lid; 412 u16 sm_lid; 413 u8 lmc; 414 u8 max_vl_num; 415 u8 sm_sl; 416 u8 subnet_timeout; 417 u8 init_type_reply; 418 u8 active_width; 419 u8 active_speed; 420 u8 phys_state; 421 }; 422 423 enum ib_device_modify_flags { 424 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0, 425 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1 426 }; 427 428 struct ib_device_modify { 429 u64 sys_image_guid; 430 char node_desc[64]; 431 }; 432 433 enum ib_port_modify_flags { 434 IB_PORT_SHUTDOWN = 1, 435 IB_PORT_INIT_TYPE = (1<<2), 436 IB_PORT_RESET_QKEY_CNTR = (1<<3) 437 }; 438 439 struct ib_port_modify { 440 u32 set_port_cap_mask; 441 u32 clr_port_cap_mask; 442 u8 init_type; 443 }; 444 445 enum ib_event_type { 446 IB_EVENT_CQ_ERR, 447 IB_EVENT_QP_FATAL, 448 IB_EVENT_QP_REQ_ERR, 449 IB_EVENT_QP_ACCESS_ERR, 450 IB_EVENT_COMM_EST, 451 IB_EVENT_SQ_DRAINED, 452 IB_EVENT_PATH_MIG, 453 IB_EVENT_PATH_MIG_ERR, 454 IB_EVENT_DEVICE_FATAL, 455 IB_EVENT_PORT_ACTIVE, 456 IB_EVENT_PORT_ERR, 457 IB_EVENT_LID_CHANGE, 458 IB_EVENT_PKEY_CHANGE, 459 IB_EVENT_SM_CHANGE, 460 IB_EVENT_SRQ_ERR, 461 IB_EVENT_SRQ_LIMIT_REACHED, 462 IB_EVENT_QP_LAST_WQE_REACHED, 463 IB_EVENT_CLIENT_REREGISTER, 464 IB_EVENT_GID_CHANGE, 465 }; 466 467 struct ib_event { 468 struct ib_device *device; 469 union { 470 struct ib_cq *cq; 471 struct ib_qp *qp; 472 struct ib_srq *srq; 473 u8 port_num; 474 } element; 475 enum ib_event_type event; 476 }; 477 478 struct ib_event_handler { 479 struct ib_device *device; 480 void (*handler)(struct ib_event_handler *, struct ib_event *); 481 struct list_head list; 482 }; 483 484 #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \ 485 do { \ 486 (_ptr)->device = _device; \ 487 (_ptr)->handler = _handler; \ 488 INIT_LIST_HEAD(&(_ptr)->list); \ 489 } while (0) 490 491 struct ib_global_route { 492 union ib_gid dgid; 493 u32 flow_label; 494 u8 sgid_index; 495 u8 hop_limit; 496 u8 traffic_class; 497 }; 498 499 struct ib_grh { 500 __be32 version_tclass_flow; 501 __be16 paylen; 502 u8 next_hdr; 503 u8 hop_limit; 504 union ib_gid sgid; 505 union ib_gid dgid; 506 }; 507 508 enum { 509 IB_MULTICAST_QPN = 0xffffff 510 }; 511 512 #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF) 513 514 enum ib_ah_flags { 515 IB_AH_GRH = 1 516 }; 517 518 enum ib_rate { 519 IB_RATE_PORT_CURRENT = 0, 520 IB_RATE_2_5_GBPS = 2, 521 IB_RATE_5_GBPS = 5, 522 IB_RATE_10_GBPS = 3, 523 IB_RATE_20_GBPS = 6, 524 IB_RATE_30_GBPS = 4, 525 IB_RATE_40_GBPS = 7, 526 IB_RATE_60_GBPS = 8, 527 IB_RATE_80_GBPS = 9, 528 IB_RATE_120_GBPS = 10, 529 IB_RATE_14_GBPS = 11, 530 IB_RATE_56_GBPS = 12, 531 IB_RATE_112_GBPS = 13, 532 IB_RATE_168_GBPS = 14, 533 IB_RATE_25_GBPS = 15, 534 IB_RATE_100_GBPS = 16, 535 IB_RATE_200_GBPS = 17, 536 IB_RATE_300_GBPS = 18 537 }; 538 539 enum ib_mr_create_flags { 540 IB_MR_SIGNATURE_EN = 1, 541 }; 542 543 /** 544 * ib_mr_init_attr - Memory region init attributes passed to routine 545 * ib_create_mr. 546 * @max_reg_descriptors: max number of registration descriptors that 547 * may be used with registration work requests. 548 * @flags: MR creation flags bit mask. 549 */ 550 struct ib_mr_init_attr { 551 int max_reg_descriptors; 552 u32 flags; 553 }; 554 555 /** 556 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the 557 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be 558 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec. 559 * @rate: rate to convert. 560 */ 561 int ib_rate_to_mult(enum ib_rate rate) __attribute_const__; 562 563 /** 564 * ib_rate_to_mbps - Convert the IB rate enum to Mbps. 565 * For example, IB_RATE_2_5_GBPS will be converted to 2500. 566 * @rate: rate to convert. 567 */ 568 int ib_rate_to_mbps(enum ib_rate rate) __attribute_const__; 569 570 struct ib_cq_init_attr { 571 int cqe; 572 int comp_vector; 573 u32 flags; 574 }; 575 576 enum ib_signature_type { 577 IB_SIG_TYPE_T10_DIF, 578 }; 579 580 /** 581 * T10-DIF Signature types 582 * T10-DIF types are defined by SCSI 583 * specifications. 584 */ 585 enum ib_t10_dif_type { 586 IB_T10DIF_NONE, 587 IB_T10DIF_TYPE1, 588 IB_T10DIF_TYPE2, 589 IB_T10DIF_TYPE3 590 }; 591 592 /** 593 * Signature T10-DIF block-guard types 594 * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules. 595 * IB_T10DIF_CSUM: Corresponds to IP checksum rules. 596 */ 597 enum ib_t10_dif_bg_type { 598 IB_T10DIF_CRC, 599 IB_T10DIF_CSUM 600 }; 601 602 /** 603 * struct ib_t10_dif_domain - Parameters specific for T10-DIF 604 * domain. 605 * @type: T10-DIF type (0|1|2|3) 606 * @bg_type: T10-DIF block guard type (CRC|CSUM) 607 * @pi_interval: protection information interval. 608 * @bg: seed of guard computation. 609 * @app_tag: application tag of guard block 610 * @ref_tag: initial guard block reference tag. 611 * @type3_inc_reftag: T10-DIF type 3 does not state 612 * about the reference tag, it is the user 613 * choice to increment it or not. 614 */ 615 struct ib_t10_dif_domain { 616 enum ib_t10_dif_type type; 617 enum ib_t10_dif_bg_type bg_type; 618 u32 pi_interval; 619 u16 bg; 620 u16 app_tag; 621 u32 ref_tag; 622 bool type3_inc_reftag; 623 }; 624 625 /** 626 * struct ib_sig_domain - Parameters for signature domain 627 * @sig_type: specific signauture type 628 * @sig: union of all signature domain attributes that may 629 * be used to set domain layout. 630 */ 631 struct ib_sig_domain { 632 enum ib_signature_type sig_type; 633 union { 634 struct ib_t10_dif_domain dif; 635 } sig; 636 }; 637 638 /** 639 * struct ib_sig_attrs - Parameters for signature handover operation 640 * @check_mask: bitmask for signature byte check (8 bytes) 641 * @mem: memory domain layout desciptor. 642 * @wire: wire domain layout desciptor. 643 */ 644 struct ib_sig_attrs { 645 u8 check_mask; 646 struct ib_sig_domain mem; 647 struct ib_sig_domain wire; 648 }; 649 650 enum ib_sig_err_type { 651 IB_SIG_BAD_GUARD, 652 IB_SIG_BAD_REFTAG, 653 IB_SIG_BAD_APPTAG, 654 }; 655 656 /** 657 * struct ib_sig_err - signature error descriptor 658 */ 659 struct ib_sig_err { 660 enum ib_sig_err_type err_type; 661 u32 expected; 662 u32 actual; 663 u64 sig_err_offset; 664 u32 key; 665 }; 666 667 enum ib_mr_status_check { 668 IB_MR_CHECK_SIG_STATUS = 1, 669 }; 670 671 /** 672 * struct ib_mr_status - Memory region status container 673 * 674 * @fail_status: Bitmask of MR checks status. For each 675 * failed check a corresponding status bit is set. 676 * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS 677 * failure. 678 */ 679 struct ib_mr_status { 680 u32 fail_status; 681 struct ib_sig_err sig_err; 682 }; 683 684 /** 685 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate 686 * enum. 687 * @mult: multiple to convert. 688 */ 689 enum ib_rate mult_to_ib_rate(int mult) __attribute_const__; 690 691 struct ib_ah_attr { 692 struct ib_global_route grh; 693 u16 dlid; 694 u8 sl; 695 u8 src_path_bits; 696 u8 static_rate; 697 u8 ah_flags; 698 u8 port_num; 699 u8 dmac[6]; 700 u16 vlan_id; 701 }; 702 703 enum ib_wc_status { 704 IB_WC_SUCCESS, 705 IB_WC_LOC_LEN_ERR, 706 IB_WC_LOC_QP_OP_ERR, 707 IB_WC_LOC_EEC_OP_ERR, 708 IB_WC_LOC_PROT_ERR, 709 IB_WC_WR_FLUSH_ERR, 710 IB_WC_MW_BIND_ERR, 711 IB_WC_BAD_RESP_ERR, 712 IB_WC_LOC_ACCESS_ERR, 713 IB_WC_REM_INV_REQ_ERR, 714 IB_WC_REM_ACCESS_ERR, 715 IB_WC_REM_OP_ERR, 716 IB_WC_RETRY_EXC_ERR, 717 IB_WC_RNR_RETRY_EXC_ERR, 718 IB_WC_LOC_RDD_VIOL_ERR, 719 IB_WC_REM_INV_RD_REQ_ERR, 720 IB_WC_REM_ABORT_ERR, 721 IB_WC_INV_EECN_ERR, 722 IB_WC_INV_EEC_STATE_ERR, 723 IB_WC_FATAL_ERR, 724 IB_WC_RESP_TIMEOUT_ERR, 725 IB_WC_GENERAL_ERR 726 }; 727 728 enum ib_wc_opcode { 729 IB_WC_SEND, 730 IB_WC_RDMA_WRITE, 731 IB_WC_RDMA_READ, 732 IB_WC_COMP_SWAP, 733 IB_WC_FETCH_ADD, 734 IB_WC_BIND_MW, 735 IB_WC_LSO, 736 IB_WC_LOCAL_INV, 737 IB_WC_FAST_REG_MR, 738 IB_WC_MASKED_COMP_SWAP, 739 IB_WC_MASKED_FETCH_ADD, 740 /* 741 * Set value of IB_WC_RECV so consumers can test if a completion is a 742 * receive by testing (opcode & IB_WC_RECV). 743 */ 744 IB_WC_RECV = 1 << 7, 745 IB_WC_RECV_RDMA_WITH_IMM 746 }; 747 748 enum ib_wc_flags { 749 IB_WC_GRH = 1, 750 IB_WC_WITH_IMM = (1<<1), 751 IB_WC_WITH_INVALIDATE = (1<<2), 752 IB_WC_IP_CSUM_OK = (1<<3), 753 IB_WC_WITH_SL = (1<<4), 754 IB_WC_WITH_SLID = (1<<5), 755 IB_WC_WITH_TIMESTAMP = (1<<6), 756 IB_WC_WITH_SMAC = (1<<7), 757 IB_WC_WITH_VLAN = (1<<8), 758 }; 759 760 struct ib_wc { 761 u64 wr_id; 762 enum ib_wc_status status; 763 enum ib_wc_opcode opcode; 764 u32 vendor_err; 765 u32 byte_len; 766 struct ib_qp *qp; 767 union { 768 __be32 imm_data; 769 u32 invalidate_rkey; 770 } ex; 771 u32 src_qp; 772 int wc_flags; 773 u16 pkey_index; 774 u16 slid; 775 u8 sl; 776 u8 dlid_path_bits; 777 u8 port_num; /* valid only for DR SMPs on switches */ 778 int csum_ok; 779 struct { 780 uint64_t timestamp; /* timestamp = 0 indicates error*/ 781 } ts; 782 u8 smac[6]; 783 u16 vlan_id; 784 }; 785 786 enum ib_cq_notify_flags { 787 IB_CQ_SOLICITED = 1 << 0, 788 IB_CQ_NEXT_COMP = 1 << 1, 789 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP, 790 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2, 791 }; 792 793 enum ib_srq_type { 794 IB_SRQT_BASIC, 795 IB_SRQT_XRC 796 }; 797 798 enum ib_srq_attr_mask { 799 IB_SRQ_MAX_WR = 1 << 0, 800 IB_SRQ_LIMIT = 1 << 1, 801 }; 802 803 struct ib_srq_attr { 804 u32 max_wr; 805 u32 max_sge; 806 u32 srq_limit; 807 }; 808 809 struct ib_srq_init_attr { 810 void (*event_handler)(struct ib_event *, void *); 811 void *srq_context; 812 struct ib_srq_attr attr; 813 enum ib_srq_type srq_type; 814 815 union { 816 struct { 817 struct ib_xrcd *xrcd; 818 struct ib_cq *cq; 819 } xrc; 820 } ext; 821 }; 822 823 struct ib_qp_cap { 824 u32 max_send_wr; 825 u32 max_recv_wr; 826 u32 max_send_sge; 827 u32 max_recv_sge; 828 u32 max_inline_data; 829 u32 qpg_tss_mask_sz; 830 }; 831 832 enum ib_sig_type { 833 IB_SIGNAL_ALL_WR, 834 IB_SIGNAL_REQ_WR 835 }; 836 837 enum ib_qp_type { 838 /* 839 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries 840 * here (and in that order) since the MAD layer uses them as 841 * indices into a 2-entry table. 842 */ 843 IB_QPT_SMI, 844 IB_QPT_GSI, 845 846 IB_QPT_RC, 847 IB_QPT_UC, 848 IB_QPT_UD, 849 IB_QPT_RAW_IPV6, 850 IB_QPT_RAW_ETHERTYPE, 851 IB_QPT_RAW_PACKET = 8, 852 IB_QPT_XRC_INI = 9, 853 IB_QPT_XRC_TGT, 854 IB_QPT_DC_INI, 855 IB_QPT_MAX, 856 /* Reserve a range for qp types internal to the low level driver. 857 * These qp types will not be visible at the IB core layer, so the 858 * IB_QPT_MAX usages should not be affected in the core layer 859 */ 860 IB_QPT_RESERVED1 = 0x1000, 861 IB_QPT_RESERVED2, 862 IB_QPT_RESERVED3, 863 IB_QPT_RESERVED4, 864 IB_QPT_RESERVED5, 865 IB_QPT_RESERVED6, 866 IB_QPT_RESERVED7, 867 IB_QPT_RESERVED8, 868 IB_QPT_RESERVED9, 869 IB_QPT_RESERVED10, 870 }; 871 872 enum ib_qp_create_flags { 873 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0, 874 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1, 875 IB_QP_CREATE_CROSS_CHANNEL = 1 << 2, 876 IB_QP_CREATE_MANAGED_SEND = 1 << 3, 877 IB_QP_CREATE_MANAGED_RECV = 1 << 4, 878 IB_QP_CREATE_NETIF_QP = 1 << 5, 879 IB_QP_CREATE_SIGNATURE_EN = 1 << 6, 880 /* reserve bits 26-31 for low level drivers' internal use */ 881 IB_QP_CREATE_RESERVED_START = 1 << 26, 882 IB_QP_CREATE_RESERVED_END = 1 << 31, 883 }; 884 885 enum ib_qpg_type { 886 IB_QPG_NONE = 0, 887 IB_QPG_PARENT = (1<<0), 888 IB_QPG_CHILD_RX = (1<<1), 889 IB_QPG_CHILD_TX = (1<<2) 890 }; 891 892 struct ib_qpg_init_attrib { 893 u32 tss_child_count; 894 u32 rss_child_count; 895 }; 896 897 struct ib_qp_init_attr { 898 void (*event_handler)(struct ib_event *, void *); 899 void *qp_context; 900 struct ib_cq *send_cq; 901 struct ib_cq *recv_cq; 902 struct ib_srq *srq; 903 struct ib_xrcd *xrcd; /* XRC TGT QPs only */ 904 struct ib_qp_cap cap; 905 union { 906 struct ib_qp *qpg_parent; /* see qpg_type */ 907 struct ib_qpg_init_attrib parent_attrib; 908 }; 909 enum ib_sig_type sq_sig_type; 910 enum ib_qp_type qp_type; 911 enum ib_qp_create_flags create_flags; 912 enum ib_qpg_type qpg_type; 913 u8 port_num; /* special QP types only */ 914 }; 915 916 enum { 917 IB_DCT_CREATE_FLAG_RCV_INLINE = 1 << 0, 918 IB_DCT_CREATE_FLAGS_MASK = IB_DCT_CREATE_FLAG_RCV_INLINE, 919 }; 920 921 struct ib_dct_init_attr { 922 struct ib_pd *pd; 923 struct ib_cq *cq; 924 struct ib_srq *srq; 925 u64 dc_key; 926 u8 port; 927 u32 access_flags; 928 u8 min_rnr_timer; 929 u8 tclass; 930 u32 flow_label; 931 enum ib_mtu mtu; 932 u8 pkey_index; 933 u8 gid_index; 934 u8 hop_limit; 935 u32 create_flags; 936 }; 937 938 struct ib_dct_attr { 939 u64 dc_key; 940 u8 port; 941 u32 access_flags; 942 u8 min_rnr_timer; 943 u8 tclass; 944 u32 flow_label; 945 enum ib_mtu mtu; 946 u8 pkey_index; 947 u8 gid_index; 948 u8 hop_limit; 949 u32 key_violations; 950 u8 state; 951 }; 952 953 struct ib_qp_open_attr { 954 void (*event_handler)(struct ib_event *, void *); 955 void *qp_context; 956 u32 qp_num; 957 enum ib_qp_type qp_type; 958 }; 959 960 enum ib_rnr_timeout { 961 IB_RNR_TIMER_655_36 = 0, 962 IB_RNR_TIMER_000_01 = 1, 963 IB_RNR_TIMER_000_02 = 2, 964 IB_RNR_TIMER_000_03 = 3, 965 IB_RNR_TIMER_000_04 = 4, 966 IB_RNR_TIMER_000_06 = 5, 967 IB_RNR_TIMER_000_08 = 6, 968 IB_RNR_TIMER_000_12 = 7, 969 IB_RNR_TIMER_000_16 = 8, 970 IB_RNR_TIMER_000_24 = 9, 971 IB_RNR_TIMER_000_32 = 10, 972 IB_RNR_TIMER_000_48 = 11, 973 IB_RNR_TIMER_000_64 = 12, 974 IB_RNR_TIMER_000_96 = 13, 975 IB_RNR_TIMER_001_28 = 14, 976 IB_RNR_TIMER_001_92 = 15, 977 IB_RNR_TIMER_002_56 = 16, 978 IB_RNR_TIMER_003_84 = 17, 979 IB_RNR_TIMER_005_12 = 18, 980 IB_RNR_TIMER_007_68 = 19, 981 IB_RNR_TIMER_010_24 = 20, 982 IB_RNR_TIMER_015_36 = 21, 983 IB_RNR_TIMER_020_48 = 22, 984 IB_RNR_TIMER_030_72 = 23, 985 IB_RNR_TIMER_040_96 = 24, 986 IB_RNR_TIMER_061_44 = 25, 987 IB_RNR_TIMER_081_92 = 26, 988 IB_RNR_TIMER_122_88 = 27, 989 IB_RNR_TIMER_163_84 = 28, 990 IB_RNR_TIMER_245_76 = 29, 991 IB_RNR_TIMER_327_68 = 30, 992 IB_RNR_TIMER_491_52 = 31 993 }; 994 995 enum ib_qp_attr_mask { 996 IB_QP_STATE = 1, 997 IB_QP_CUR_STATE = (1<<1), 998 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2), 999 IB_QP_ACCESS_FLAGS = (1<<3), 1000 IB_QP_PKEY_INDEX = (1<<4), 1001 IB_QP_PORT = (1<<5), 1002 IB_QP_QKEY = (1<<6), 1003 IB_QP_AV = (1<<7), 1004 IB_QP_PATH_MTU = (1<<8), 1005 IB_QP_TIMEOUT = (1<<9), 1006 IB_QP_RETRY_CNT = (1<<10), 1007 IB_QP_RNR_RETRY = (1<<11), 1008 IB_QP_RQ_PSN = (1<<12), 1009 IB_QP_MAX_QP_RD_ATOMIC = (1<<13), 1010 IB_QP_ALT_PATH = (1<<14), 1011 IB_QP_MIN_RNR_TIMER = (1<<15), 1012 IB_QP_SQ_PSN = (1<<16), 1013 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17), 1014 IB_QP_PATH_MIG_STATE = (1<<18), 1015 IB_QP_CAP = (1<<19), 1016 IB_QP_DEST_QPN = (1<<20), 1017 IB_QP_GROUP_RSS = (1<<21), 1018 IB_QP_DC_KEY = (1<<22), 1019 IB_QP_SMAC = (1<<23), 1020 IB_QP_ALT_SMAC = (1<<24), 1021 IB_QP_VID = (1<<25), 1022 IB_QP_ALT_VID = (1<<26) 1023 }; 1024 1025 enum ib_qp_state { 1026 IB_QPS_RESET, 1027 IB_QPS_INIT, 1028 IB_QPS_RTR, 1029 IB_QPS_RTS, 1030 IB_QPS_SQD, 1031 IB_QPS_SQE, 1032 IB_QPS_ERR, 1033 IB_QPS_DUMMY = -1 /* force enum signed */ 1034 }; 1035 1036 enum ib_mig_state { 1037 IB_MIG_MIGRATED, 1038 IB_MIG_REARM, 1039 IB_MIG_ARMED 1040 }; 1041 1042 enum ib_mw_type { 1043 IB_MW_TYPE_1 = 1, 1044 IB_MW_TYPE_2 = 2 1045 }; 1046 1047 struct ib_qp_attr { 1048 enum ib_qp_state qp_state; 1049 enum ib_qp_state cur_qp_state; 1050 enum ib_mtu path_mtu; 1051 enum ib_mig_state path_mig_state; 1052 u32 qkey; 1053 u32 rq_psn; 1054 u32 sq_psn; 1055 u32 dest_qp_num; 1056 int qp_access_flags; 1057 struct ib_qp_cap cap; 1058 struct ib_ah_attr ah_attr; 1059 struct ib_ah_attr alt_ah_attr; 1060 u16 pkey_index; 1061 u16 alt_pkey_index; 1062 u8 en_sqd_async_notify; 1063 u8 sq_draining; 1064 u8 max_rd_atomic; 1065 u8 max_dest_rd_atomic; 1066 u8 min_rnr_timer; 1067 u8 port_num; 1068 u8 timeout; 1069 u8 retry_cnt; 1070 u8 rnr_retry; 1071 u8 alt_port_num; 1072 u8 alt_timeout; 1073 u8 smac[ETH_ALEN]; 1074 u8 alt_smac[ETH_ALEN]; 1075 u16 vlan_id; 1076 u16 alt_vlan_id; 1077 1078 }; 1079 1080 struct ib_qp_attr_ex { 1081 enum ib_qp_state qp_state; 1082 enum ib_qp_state cur_qp_state; 1083 enum ib_mtu path_mtu; 1084 enum ib_mig_state path_mig_state; 1085 u32 qkey; 1086 u32 rq_psn; 1087 u32 sq_psn; 1088 u32 dest_qp_num; 1089 int qp_access_flags; 1090 struct ib_qp_cap cap; 1091 struct ib_ah_attr ah_attr; 1092 struct ib_ah_attr alt_ah_attr; 1093 u16 pkey_index; 1094 u16 alt_pkey_index; 1095 u8 en_sqd_async_notify; 1096 u8 sq_draining; 1097 u8 max_rd_atomic; 1098 u8 max_dest_rd_atomic; 1099 u8 min_rnr_timer; 1100 u8 port_num; 1101 u8 timeout; 1102 u8 retry_cnt; 1103 u8 rnr_retry; 1104 u8 alt_port_num; 1105 u8 alt_timeout; 1106 u64 dct_key; 1107 }; 1108 1109 enum ib_wr_opcode { 1110 IB_WR_RDMA_WRITE, 1111 IB_WR_RDMA_WRITE_WITH_IMM, 1112 IB_WR_SEND, 1113 IB_WR_SEND_WITH_IMM, 1114 IB_WR_RDMA_READ, 1115 IB_WR_ATOMIC_CMP_AND_SWP, 1116 IB_WR_ATOMIC_FETCH_AND_ADD, 1117 IB_WR_LSO, 1118 IB_WR_SEND_WITH_INV, 1119 IB_WR_RDMA_READ_WITH_INV, 1120 IB_WR_LOCAL_INV, 1121 IB_WR_FAST_REG_MR, 1122 IB_WR_MASKED_ATOMIC_CMP_AND_SWP, 1123 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD, 1124 IB_WR_BIND_MW, 1125 IB_WR_REG_SIG_MR, 1126 /* reserve values for low level drivers' internal use. 1127 * These values will not be used at all in the ib core layer. 1128 */ 1129 IB_WR_RESERVED1 = 0xf0, 1130 IB_WR_RESERVED2, 1131 IB_WR_RESERVED3, 1132 IB_WR_RESERVED4, 1133 IB_WR_RESERVED5, 1134 IB_WR_RESERVED6, 1135 IB_WR_RESERVED7, 1136 IB_WR_RESERVED8, 1137 IB_WR_RESERVED9, 1138 IB_WR_RESERVED10, 1139 }; 1140 1141 enum ib_send_flags { 1142 IB_SEND_FENCE = 1, 1143 IB_SEND_SIGNALED = (1<<1), 1144 IB_SEND_SOLICITED = (1<<2), 1145 IB_SEND_INLINE = (1<<3), 1146 IB_SEND_IP_CSUM = (1<<4), 1147 1148 /* reserve bits 26-31 for low level drivers' internal use */ 1149 IB_SEND_RESERVED_START = (1 << 26), 1150 IB_SEND_RESERVED_END = (1 << 31), 1151 IB_SEND_UMR_UNREG = (1<<5) 1152 }; 1153 1154 struct ib_sge { 1155 u64 addr; 1156 u32 length; 1157 u32 lkey; 1158 }; 1159 1160 struct ib_fast_reg_page_list { 1161 struct ib_device *device; 1162 u64 *page_list; 1163 unsigned int max_page_list_len; 1164 }; 1165 1166 /** 1167 * struct ib_mw_bind_info - Parameters for a memory window bind operation. 1168 * @mr: A memory region to bind the memory window to. 1169 * @addr: The address where the memory window should begin. 1170 * @length: The length of the memory window, in bytes. 1171 * @mw_access_flags: Access flags from enum ib_access_flags for the window. 1172 * 1173 * This struct contains the shared parameters for type 1 and type 2 1174 * memory window bind operations. 1175 */ 1176 struct ib_mw_bind_info { 1177 struct ib_mr *mr; 1178 u64 addr; 1179 u64 length; 1180 int mw_access_flags; 1181 }; 1182 1183 struct ib_send_wr { 1184 struct ib_send_wr *next; 1185 u64 wr_id; 1186 struct ib_sge *sg_list; 1187 int num_sge; 1188 enum ib_wr_opcode opcode; 1189 int send_flags; 1190 union { 1191 __be32 imm_data; 1192 u32 invalidate_rkey; 1193 } ex; 1194 union { 1195 struct { 1196 u64 remote_addr; 1197 u32 rkey; 1198 } rdma; 1199 struct { 1200 u64 remote_addr; 1201 u64 compare_add; 1202 u64 swap; 1203 u64 compare_add_mask; 1204 u64 swap_mask; 1205 u32 rkey; 1206 } atomic; 1207 struct { 1208 struct ib_ah *ah; 1209 void *header; 1210 int hlen; 1211 int mss; 1212 u32 remote_qpn; 1213 u32 remote_qkey; 1214 u16 pkey_index; /* valid for GSI only */ 1215 u8 port_num; /* valid for DR SMPs on switch only */ 1216 } ud; 1217 struct { 1218 u64 iova_start; 1219 struct ib_fast_reg_page_list *page_list; 1220 unsigned int page_shift; 1221 unsigned int page_list_len; 1222 u32 length; 1223 int access_flags; 1224 u32 rkey; 1225 } fast_reg; 1226 struct { 1227 int npages; 1228 int access_flags; 1229 u32 mkey; 1230 struct ib_pd *pd; 1231 u64 virt_addr; 1232 u64 length; 1233 int page_shift; 1234 } umr; 1235 struct { 1236 struct ib_mw *mw; 1237 /* The new rkey for the memory window. */ 1238 u32 rkey; 1239 struct ib_mw_bind_info bind_info; 1240 } bind_mw; 1241 struct { 1242 struct ib_sig_attrs *sig_attrs; 1243 struct ib_mr *sig_mr; 1244 int access_flags; 1245 struct ib_sge *prot; 1246 } sig_handover; 1247 } wr; 1248 u32 xrc_remote_srq_num; /* XRC TGT QPs only */ 1249 }; 1250 1251 struct ib_recv_wr { 1252 struct ib_recv_wr *next; 1253 u64 wr_id; 1254 struct ib_sge *sg_list; 1255 int num_sge; 1256 }; 1257 1258 enum ib_access_flags { 1259 IB_ACCESS_LOCAL_WRITE = 1, 1260 IB_ACCESS_REMOTE_WRITE = (1<<1), 1261 IB_ACCESS_REMOTE_READ = (1<<2), 1262 IB_ACCESS_REMOTE_ATOMIC = (1<<3), 1263 IB_ACCESS_MW_BIND = (1<<4), 1264 IB_ACCESS_ALLOCATE_MR = (1<<5), 1265 IB_ZERO_BASED = (1<<13) 1266 }; 1267 1268 struct ib_phys_buf { 1269 u64 addr; 1270 u64 size; 1271 }; 1272 1273 struct ib_mr_attr { 1274 struct ib_pd *pd; 1275 u64 device_virt_addr; 1276 u64 size; 1277 int mr_access_flags; 1278 u32 lkey; 1279 u32 rkey; 1280 }; 1281 1282 enum ib_mr_rereg_flags { 1283 IB_MR_REREG_TRANS = 1, 1284 IB_MR_REREG_PD = (1<<1), 1285 IB_MR_REREG_ACCESS = (1<<2) 1286 }; 1287 1288 /** 1289 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation. 1290 * @wr_id: Work request id. 1291 * @send_flags: Flags from ib_send_flags enum. 1292 * @bind_info: More parameters of the bind operation. 1293 */ 1294 struct ib_mw_bind { 1295 u64 wr_id; 1296 int send_flags; 1297 struct ib_mw_bind_info bind_info; 1298 }; 1299 1300 struct ib_fmr_attr { 1301 int max_pages; 1302 int max_maps; 1303 u8 page_shift; 1304 }; 1305 1306 struct ib_ucontext { 1307 struct ib_device *device; 1308 struct list_head pd_list; 1309 struct list_head mr_list; 1310 struct list_head mw_list; 1311 struct list_head cq_list; 1312 struct list_head qp_list; 1313 struct list_head srq_list; 1314 struct list_head ah_list; 1315 struct list_head xrcd_list; 1316 struct list_head rule_list; 1317 struct list_head dct_list; 1318 int closing; 1319 void *peer_mem_private_data; 1320 char *peer_mem_name; 1321 }; 1322 1323 struct ib_uobject { 1324 u64 user_handle; /* handle given to us by userspace */ 1325 struct ib_ucontext *context; /* associated user context */ 1326 void *object; /* containing object */ 1327 struct list_head list; /* link to context's list */ 1328 int id; /* index into kernel idr */ 1329 struct kref ref; 1330 struct rw_semaphore mutex; /* protects .live */ 1331 int live; 1332 }; 1333 1334 struct ib_udata; 1335 struct ib_udata_ops { 1336 int (*copy_from)(void *dest, struct ib_udata *udata, 1337 size_t len); 1338 int (*copy_to)(struct ib_udata *udata, void *src, 1339 size_t len); 1340 }; 1341 1342 struct ib_udata { 1343 struct ib_udata_ops *ops; 1344 void __user *inbuf; 1345 void __user *outbuf; 1346 size_t inlen; 1347 size_t outlen; 1348 }; 1349 1350 struct ib_pd { 1351 struct ib_device *device; 1352 struct ib_uobject *uobject; 1353 atomic_t usecnt; /* count all resources */ 1354 }; 1355 1356 struct ib_xrcd { 1357 struct ib_device *device; 1358 atomic_t usecnt; /* count all exposed resources */ 1359 struct inode *inode; 1360 1361 struct mutex tgt_qp_mutex; 1362 struct list_head tgt_qp_list; 1363 }; 1364 1365 struct ib_ah { 1366 struct ib_device *device; 1367 struct ib_pd *pd; 1368 struct ib_uobject *uobject; 1369 }; 1370 1371 enum ib_cq_attr_mask { 1372 IB_CQ_MODERATION = (1 << 0), 1373 IB_CQ_CAP_FLAGS = (1 << 1) 1374 }; 1375 1376 enum ib_cq_cap_flags { 1377 IB_CQ_IGNORE_OVERRUN = (1 << 0) 1378 }; 1379 1380 struct ib_cq_attr { 1381 struct { 1382 u16 cq_count; 1383 u16 cq_period; 1384 } moderation; 1385 u32 cq_cap_flags; 1386 }; 1387 1388 typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context); 1389 1390 struct ib_cq { 1391 struct ib_device *device; 1392 struct ib_uobject *uobject; 1393 ib_comp_handler comp_handler; 1394 void (*event_handler)(struct ib_event *, void *); 1395 void *cq_context; 1396 int cqe; 1397 atomic_t usecnt; /* count number of work queues */ 1398 }; 1399 1400 struct ib_srq { 1401 struct ib_device *device; 1402 struct ib_pd *pd; 1403 struct ib_uobject *uobject; 1404 void (*event_handler)(struct ib_event *, void *); 1405 void *srq_context; 1406 enum ib_srq_type srq_type; 1407 atomic_t usecnt; 1408 1409 union { 1410 struct { 1411 struct ib_xrcd *xrcd; 1412 struct ib_cq *cq; 1413 u32 srq_num; 1414 } xrc; 1415 } ext; 1416 }; 1417 1418 struct ib_qp { 1419 struct ib_device *device; 1420 struct ib_pd *pd; 1421 struct ib_cq *send_cq; 1422 struct ib_cq *recv_cq; 1423 struct ib_srq *srq; 1424 struct ib_xrcd *xrcd; /* XRC TGT QPs only */ 1425 struct list_head xrcd_list; 1426 /* count times opened, mcast attaches, flow attaches */ 1427 atomic_t usecnt; 1428 struct list_head open_list; 1429 struct ib_qp *real_qp; 1430 struct ib_uobject *uobject; 1431 void (*event_handler)(struct ib_event *, void *); 1432 void *qp_context; 1433 u32 qp_num; 1434 enum ib_qp_type qp_type; 1435 enum ib_qpg_type qpg_type; 1436 u8 port_num; 1437 }; 1438 1439 struct ib_dct { 1440 struct ib_device *device; 1441 struct ib_uobject *uobject; 1442 struct ib_pd *pd; 1443 struct ib_cq *cq; 1444 struct ib_srq *srq; 1445 u32 dct_num; 1446 }; 1447 1448 struct ib_mr { 1449 struct ib_device *device; 1450 struct ib_pd *pd; 1451 struct ib_uobject *uobject; 1452 u32 lkey; 1453 u32 rkey; 1454 atomic_t usecnt; /* count number of MWs */ 1455 }; 1456 1457 struct ib_mw { 1458 struct ib_device *device; 1459 struct ib_pd *pd; 1460 struct ib_uobject *uobject; 1461 u32 rkey; 1462 enum ib_mw_type type; 1463 }; 1464 1465 struct ib_fmr { 1466 struct ib_device *device; 1467 struct ib_pd *pd; 1468 struct list_head list; 1469 u32 lkey; 1470 u32 rkey; 1471 }; 1472 1473 /* Supported steering options */ 1474 enum ib_flow_attr_type { 1475 /* steering according to rule specifications */ 1476 IB_FLOW_ATTR_NORMAL = 0x0, 1477 /* default unicast and multicast rule - 1478 * receive all Eth traffic which isn't steered to any QP 1479 */ 1480 IB_FLOW_ATTR_ALL_DEFAULT = 0x1, 1481 /* default multicast rule - 1482 * receive all Eth multicast traffic which isn't steered to any QP 1483 */ 1484 IB_FLOW_ATTR_MC_DEFAULT = 0x2, 1485 /* sniffer rule - receive all port traffic */ 1486 IB_FLOW_ATTR_SNIFFER = 0x3 1487 }; 1488 1489 /* Supported steering header types */ 1490 enum ib_flow_spec_type { 1491 /* L2 headers*/ 1492 IB_FLOW_SPEC_ETH = 0x20, 1493 IB_FLOW_SPEC_IB = 0x21, 1494 /* L3 header*/ 1495 IB_FLOW_SPEC_IPV4 = 0x30, 1496 /* L4 headers*/ 1497 IB_FLOW_SPEC_TCP = 0x40, 1498 IB_FLOW_SPEC_UDP = 0x41 1499 }; 1500 1501 #define IB_FLOW_SPEC_SUPPORT_LAYERS 4 1502 1503 /* Flow steering rule priority is set according to it's domain. 1504 * Lower domain value means higher priority. 1505 */ 1506 enum ib_flow_domain { 1507 IB_FLOW_DOMAIN_USER, 1508 IB_FLOW_DOMAIN_ETHTOOL, 1509 IB_FLOW_DOMAIN_RFS, 1510 IB_FLOW_DOMAIN_NIC, 1511 IB_FLOW_DOMAIN_NUM /* Must be last */ 1512 }; 1513 1514 enum ib_flow_flags { 1515 IB_FLOW_ATTR_FLAGS_ALLOW_LOOP_BACK = 1 1516 }; 1517 1518 struct ib_flow_eth_filter { 1519 u8 dst_mac[6]; 1520 u8 src_mac[6]; 1521 __be16 ether_type; 1522 __be16 vlan_tag; 1523 }; 1524 1525 struct ib_flow_spec_eth { 1526 enum ib_flow_spec_type type; 1527 u16 size; 1528 struct ib_flow_eth_filter val; 1529 struct ib_flow_eth_filter mask; 1530 }; 1531 1532 struct ib_flow_ib_filter { 1533 __be32 l3_type_qpn; 1534 u8 dst_gid[16]; 1535 }; 1536 1537 struct ib_flow_spec_ib { 1538 enum ib_flow_spec_type type; 1539 u16 size; 1540 struct ib_flow_ib_filter val; 1541 struct ib_flow_ib_filter mask; 1542 }; 1543 1544 struct ib_flow_ipv4_filter { 1545 __be32 src_ip; 1546 __be32 dst_ip; 1547 }; 1548 1549 struct ib_flow_spec_ipv4 { 1550 enum ib_flow_spec_type type; 1551 u16 size; 1552 struct ib_flow_ipv4_filter val; 1553 struct ib_flow_ipv4_filter mask; 1554 }; 1555 1556 struct ib_flow_tcp_udp_filter { 1557 __be16 dst_port; 1558 __be16 src_port; 1559 }; 1560 1561 struct ib_flow_spec_tcp_udp { 1562 enum ib_flow_spec_type type; 1563 u16 size; 1564 struct ib_flow_tcp_udp_filter val; 1565 struct ib_flow_tcp_udp_filter mask; 1566 }; 1567 1568 union ib_flow_spec { 1569 struct { 1570 enum ib_flow_spec_type type; 1571 u16 size; 1572 }; 1573 struct ib_flow_spec_ib ib; 1574 struct ib_flow_spec_eth eth; 1575 struct ib_flow_spec_ipv4 ipv4; 1576 struct ib_flow_spec_tcp_udp tcp_udp; 1577 }; 1578 1579 struct ib_flow_attr { 1580 enum ib_flow_attr_type type; 1581 u16 size; 1582 u16 priority; 1583 u8 num_of_specs; 1584 u8 port; 1585 u32 flags; 1586 /* Following are the optional layers according to user request 1587 * struct ib_flow_spec_xxx 1588 * struct ib_flow_spec_yyy 1589 */ 1590 }; 1591 1592 struct ib_flow { 1593 struct ib_qp *qp; 1594 struct ib_uobject *uobject; 1595 }; 1596 1597 struct ib_mad; 1598 struct ib_grh; 1599 1600 enum ib_process_mad_flags { 1601 IB_MAD_IGNORE_MKEY = 1, 1602 IB_MAD_IGNORE_BKEY = 2, 1603 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY 1604 }; 1605 1606 enum ib_mad_result { 1607 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */ 1608 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */ 1609 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */ 1610 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */ 1611 }; 1612 1613 #define IB_DEVICE_NAME_MAX 64 1614 1615 struct ib_cache { 1616 rwlock_t lock; 1617 struct ib_event_handler event_handler; 1618 struct ib_pkey_cache **pkey_cache; 1619 struct ib_gid_cache **gid_cache; 1620 u8 *lmc_cache; 1621 }; 1622 1623 enum verbs_values_mask { 1624 IBV_VALUES_HW_CLOCK = 1 << 0 1625 }; 1626 1627 struct ib_device_values { 1628 int values_mask; 1629 uint64_t hwclock; 1630 }; 1631 1632 struct ib_dma_mapping_ops { 1633 int (*mapping_error)(struct ib_device *dev, 1634 u64 dma_addr); 1635 u64 (*map_single)(struct ib_device *dev, 1636 void *ptr, size_t size, 1637 enum dma_data_direction direction); 1638 void (*unmap_single)(struct ib_device *dev, 1639 u64 addr, size_t size, 1640 enum dma_data_direction direction); 1641 u64 (*map_page)(struct ib_device *dev, 1642 struct page *page, unsigned long offset, 1643 size_t size, 1644 enum dma_data_direction direction); 1645 void (*unmap_page)(struct ib_device *dev, 1646 u64 addr, size_t size, 1647 enum dma_data_direction direction); 1648 int (*map_sg)(struct ib_device *dev, 1649 struct scatterlist *sg, int nents, 1650 enum dma_data_direction direction); 1651 void (*unmap_sg)(struct ib_device *dev, 1652 struct scatterlist *sg, int nents, 1653 enum dma_data_direction direction); 1654 u64 (*dma_address)(struct ib_device *dev, 1655 struct scatterlist *sg); 1656 unsigned int (*dma_len)(struct ib_device *dev, 1657 struct scatterlist *sg); 1658 void (*sync_single_for_cpu)(struct ib_device *dev, 1659 u64 dma_handle, 1660 size_t size, 1661 enum dma_data_direction dir); 1662 void (*sync_single_for_device)(struct ib_device *dev, 1663 u64 dma_handle, 1664 size_t size, 1665 enum dma_data_direction dir); 1666 void *(*alloc_coherent)(struct ib_device *dev, 1667 size_t size, 1668 u64 *dma_handle, 1669 gfp_t flag); 1670 void (*free_coherent)(struct ib_device *dev, 1671 size_t size, void *cpu_addr, 1672 u64 dma_handle); 1673 }; 1674 1675 struct iw_cm_verbs; 1676 1677 struct ib_port_immutable { 1678 int pkey_tbl_len; 1679 int gid_tbl_len; 1680 u32 core_cap_flags; 1681 u32 max_mad_size; 1682 }; 1683 1684 struct ib_exp_device_attr; 1685 struct ib_exp_qp_init_attr; 1686 1687 struct ib_device { 1688 struct device *dma_device; 1689 1690 char name[IB_DEVICE_NAME_MAX]; 1691 1692 struct list_head event_handler_list; 1693 spinlock_t event_handler_lock; 1694 1695 spinlock_t client_data_lock; 1696 struct list_head core_list; 1697 struct list_head client_data_list; 1698 1699 struct ib_cache cache; 1700 /** 1701 * port_immutable is indexed by port number 1702 */ 1703 struct ib_port_immutable *port_immutable; 1704 1705 int num_comp_vectors; 1706 1707 struct iw_cm_verbs *iwcm; 1708 1709 int (*get_protocol_stats)(struct ib_device *device, 1710 union rdma_protocol_stats *stats); 1711 int (*query_device)(struct ib_device *device, 1712 struct ib_device_attr *device_attr); 1713 int (*query_port)(struct ib_device *device, 1714 u8 port_num, 1715 struct ib_port_attr *port_attr); 1716 enum rdma_link_layer (*get_link_layer)(struct ib_device *device, 1717 u8 port_num); 1718 /* When calling get_netdev, the HW vendor's driver should return the 1719 * net device of device @device at port @port_num. The function 1720 * is called in rtnl_lock. The HW vendor's device driver must guarantee 1721 * to return NULL before the net device has reached 1722 * NETDEV_UNREGISTER_FINAL state. 1723 */ 1724 struct net_device *(*get_netdev)(struct ib_device *device, 1725 u8 port_num); 1726 int (*query_gid)(struct ib_device *device, 1727 u8 port_num, int index, 1728 union ib_gid *gid); 1729 int (*query_pkey)(struct ib_device *device, 1730 u8 port_num, u16 index, u16 *pkey); 1731 int (*modify_device)(struct ib_device *device, 1732 int device_modify_mask, 1733 struct ib_device_modify *device_modify); 1734 int (*modify_port)(struct ib_device *device, 1735 u8 port_num, int port_modify_mask, 1736 struct ib_port_modify *port_modify); 1737 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device, 1738 struct ib_udata *udata); 1739 int (*dealloc_ucontext)(struct ib_ucontext *context); 1740 int (*mmap)(struct ib_ucontext *context, 1741 struct vm_area_struct *vma); 1742 struct ib_pd * (*alloc_pd)(struct ib_device *device, 1743 struct ib_ucontext *context, 1744 struct ib_udata *udata); 1745 int (*dealloc_pd)(struct ib_pd *pd); 1746 struct ib_ah * (*create_ah)(struct ib_pd *pd, 1747 struct ib_ah_attr *ah_attr); 1748 int (*modify_ah)(struct ib_ah *ah, 1749 struct ib_ah_attr *ah_attr); 1750 int (*query_ah)(struct ib_ah *ah, 1751 struct ib_ah_attr *ah_attr); 1752 int (*destroy_ah)(struct ib_ah *ah); 1753 struct ib_srq * (*create_srq)(struct ib_pd *pd, 1754 struct ib_srq_init_attr *srq_init_attr, 1755 struct ib_udata *udata); 1756 int (*modify_srq)(struct ib_srq *srq, 1757 struct ib_srq_attr *srq_attr, 1758 enum ib_srq_attr_mask srq_attr_mask, 1759 struct ib_udata *udata); 1760 int (*query_srq)(struct ib_srq *srq, 1761 struct ib_srq_attr *srq_attr); 1762 int (*destroy_srq)(struct ib_srq *srq); 1763 int (*post_srq_recv)(struct ib_srq *srq, 1764 struct ib_recv_wr *recv_wr, 1765 struct ib_recv_wr **bad_recv_wr); 1766 struct ib_qp * (*create_qp)(struct ib_pd *pd, 1767 struct ib_qp_init_attr *qp_init_attr, 1768 struct ib_udata *udata); 1769 int (*modify_qp)(struct ib_qp *qp, 1770 struct ib_qp_attr *qp_attr, 1771 int qp_attr_mask, 1772 struct ib_udata *udata); 1773 int (*query_qp)(struct ib_qp *qp, 1774 struct ib_qp_attr *qp_attr, 1775 int qp_attr_mask, 1776 struct ib_qp_init_attr *qp_init_attr); 1777 int (*destroy_qp)(struct ib_qp *qp); 1778 int (*post_send)(struct ib_qp *qp, 1779 struct ib_send_wr *send_wr, 1780 struct ib_send_wr **bad_send_wr); 1781 int (*post_recv)(struct ib_qp *qp, 1782 struct ib_recv_wr *recv_wr, 1783 struct ib_recv_wr **bad_recv_wr); 1784 struct ib_cq * (*create_cq)(struct ib_device *device, 1785 struct ib_cq_init_attr *attr, 1786 struct ib_ucontext *context, 1787 struct ib_udata *udata); 1788 int (*modify_cq)(struct ib_cq *cq, 1789 struct ib_cq_attr *cq_attr, 1790 int cq_attr_mask); 1791 int (*destroy_cq)(struct ib_cq *cq); 1792 int (*resize_cq)(struct ib_cq *cq, int cqe, 1793 struct ib_udata *udata); 1794 int (*poll_cq)(struct ib_cq *cq, int num_entries, 1795 struct ib_wc *wc); 1796 int (*peek_cq)(struct ib_cq *cq, int wc_cnt); 1797 int (*req_notify_cq)(struct ib_cq *cq, 1798 enum ib_cq_notify_flags flags); 1799 int (*req_ncomp_notif)(struct ib_cq *cq, 1800 int wc_cnt); 1801 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd, 1802 int mr_access_flags); 1803 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd, 1804 struct ib_phys_buf *phys_buf_array, 1805 int num_phys_buf, 1806 int mr_access_flags, 1807 u64 *iova_start); 1808 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd, 1809 u64 start, u64 length, 1810 u64 virt_addr, 1811 int mr_access_flags, 1812 struct ib_udata *udata, 1813 int mr_id); 1814 int (*query_mr)(struct ib_mr *mr, 1815 struct ib_mr_attr *mr_attr); 1816 int (*dereg_mr)(struct ib_mr *mr); 1817 int (*destroy_mr)(struct ib_mr *mr); 1818 struct ib_mr * (*create_mr)(struct ib_pd *pd, 1819 struct ib_mr_init_attr *mr_init_attr); 1820 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd, 1821 int max_page_list_len); 1822 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device, 1823 int page_list_len); 1824 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list); 1825 int (*rereg_phys_mr)(struct ib_mr *mr, 1826 int mr_rereg_mask, 1827 struct ib_pd *pd, 1828 struct ib_phys_buf *phys_buf_array, 1829 int num_phys_buf, 1830 int mr_access_flags, 1831 u64 *iova_start); 1832 struct ib_mw * (*alloc_mw)(struct ib_pd *pd, 1833 enum ib_mw_type type); 1834 int (*bind_mw)(struct ib_qp *qp, 1835 struct ib_mw *mw, 1836 struct ib_mw_bind *mw_bind); 1837 int (*dealloc_mw)(struct ib_mw *mw); 1838 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd, 1839 int mr_access_flags, 1840 struct ib_fmr_attr *fmr_attr); 1841 int (*map_phys_fmr)(struct ib_fmr *fmr, 1842 u64 *page_list, int list_len, 1843 u64 iova); 1844 int (*unmap_fmr)(struct list_head *fmr_list); 1845 int (*dealloc_fmr)(struct ib_fmr *fmr); 1846 int (*attach_mcast)(struct ib_qp *qp, 1847 union ib_gid *gid, 1848 u16 lid); 1849 int (*detach_mcast)(struct ib_qp *qp, 1850 union ib_gid *gid, 1851 u16 lid); 1852 int (*process_mad)(struct ib_device *device, 1853 int process_mad_flags, 1854 u8 port_num, 1855 struct ib_wc *in_wc, 1856 struct ib_grh *in_grh, 1857 struct ib_mad *in_mad, 1858 struct ib_mad *out_mad); 1859 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device, 1860 struct ib_ucontext *ucontext, 1861 struct ib_udata *udata); 1862 int (*dealloc_xrcd)(struct ib_xrcd *xrcd); 1863 struct ib_flow * (*create_flow)(struct ib_qp *qp, 1864 struct ib_flow_attr 1865 *flow_attr, 1866 int domain); 1867 int (*destroy_flow)(struct ib_flow *flow_id); 1868 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask, 1869 struct ib_mr_status *mr_status); 1870 1871 unsigned long (*get_unmapped_area)(struct file *file, 1872 unsigned long addr, 1873 unsigned long len, unsigned long pgoff, 1874 unsigned long flags); 1875 int (*ioctl)(struct ib_ucontext *context, 1876 unsigned int cmd, 1877 unsigned long arg); 1878 int (*query_values)(struct ib_device *device, 1879 int q_values, 1880 struct ib_device_values *values); 1881 struct ib_dma_mapping_ops *dma_ops; 1882 1883 struct module *owner; 1884 struct device dev; 1885 struct kobject *ports_parent; 1886 struct list_head port_list; 1887 1888 enum { 1889 IB_DEV_UNINITIALIZED, 1890 IB_DEV_REGISTERED, 1891 IB_DEV_UNREGISTERED 1892 } reg_state; 1893 1894 int uverbs_abi_ver; 1895 u64 uverbs_cmd_mask; 1896 u64 uverbs_ex_cmd_mask; 1897 1898 char node_desc[64]; 1899 __be64 node_guid; 1900 u32 local_dma_lkey; 1901 u8 node_type; 1902 u8 phys_port_cnt; 1903 int cmd_perf; 1904 u64 cmd_avg; 1905 u32 cmd_n; 1906 spinlock_t cmd_perf_lock; 1907 1908 1909 /** 1910 * The following mandatory functions are used only at device 1911 * registration. Keep functions such as these at the end of this 1912 * structure to avoid cache line misses when accessing struct ib_device 1913 * in fast paths. 1914 */ 1915 int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *); 1916 1917 /* 1918 * Experimental data and functions 1919 */ 1920 int (*exp_query_device)(struct ib_device *device, 1921 struct ib_exp_device_attr *device_attr); 1922 struct ib_qp * (*exp_create_qp)(struct ib_pd *pd, 1923 struct ib_exp_qp_init_attr *qp_init_attr, 1924 struct ib_udata *udata); 1925 struct ib_dct * (*exp_create_dct)(struct ib_pd *pd, 1926 struct ib_dct_init_attr *attr, 1927 struct ib_udata *udata); 1928 int (*exp_destroy_dct)(struct ib_dct *dct); 1929 int (*exp_query_dct)(struct ib_dct *dct, struct ib_dct_attr *attr); 1930 1931 u64 uverbs_exp_cmd_mask; 1932 }; 1933 1934 struct ib_client { 1935 char *name; 1936 void (*add) (struct ib_device *); 1937 void (*remove)(struct ib_device *); 1938 1939 struct list_head list; 1940 }; 1941 1942 struct ib_device *ib_alloc_device(size_t size); 1943 void ib_dealloc_device(struct ib_device *device); 1944 1945 int ib_register_device(struct ib_device *device, 1946 int (*port_callback)(struct ib_device *, 1947 u8, struct kobject *)); 1948 void ib_unregister_device(struct ib_device *device); 1949 1950 int ib_register_client (struct ib_client *client); 1951 void ib_unregister_client(struct ib_client *client); 1952 1953 void *ib_get_client_data(struct ib_device *device, struct ib_client *client); 1954 void ib_set_client_data(struct ib_device *device, struct ib_client *client, 1955 void *data); 1956 1957 static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len) 1958 { 1959 return udata->ops->copy_from(dest, udata, len); 1960 } 1961 1962 static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len) 1963 { 1964 return udata->ops->copy_to(udata, src, len); 1965 } 1966 1967 /** 1968 * ib_modify_qp_is_ok - Check that the supplied attribute mask 1969 * contains all required attributes and no attributes not allowed for 1970 * the given QP state transition. 1971 * @cur_state: Current QP state 1972 * @next_state: Next QP state 1973 * @type: QP type 1974 * @mask: Mask of supplied QP attributes 1975 * @ll : link layer of port 1976 * 1977 * This function is a helper function that a low-level driver's 1978 * modify_qp method can use to validate the consumer's input. It 1979 * checks that cur_state and next_state are valid QP states, that a 1980 * transition from cur_state to next_state is allowed by the IB spec, 1981 * and that the attribute mask supplied is allowed for the transition. 1982 */ 1983 int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state, 1984 enum ib_qp_type type, enum ib_qp_attr_mask mask, 1985 enum rdma_link_layer ll); 1986 1987 int ib_register_event_handler (struct ib_event_handler *event_handler); 1988 int ib_unregister_event_handler(struct ib_event_handler *event_handler); 1989 void ib_dispatch_event(struct ib_event *event); 1990 1991 int ib_query_device(struct ib_device *device, 1992 struct ib_device_attr *device_attr); 1993 1994 int ib_query_port(struct ib_device *device, 1995 u8 port_num, struct ib_port_attr *port_attr); 1996 1997 enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, 1998 u8 port_num); 1999 2000 static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num) 2001 { 2002 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB; 2003 } 2004 2005 static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num) 2006 { 2007 return device->port_immutable[port_num].core_cap_flags & 2008 (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP); 2009 } 2010 2011 static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num) 2012 { 2013 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP; 2014 } 2015 2016 static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num) 2017 { 2018 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE; 2019 } 2020 2021 static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num) 2022 { 2023 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP; 2024 } 2025 2026 static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num) 2027 { 2028 return rdma_protocol_ib(device, port_num) || 2029 rdma_protocol_roce(device, port_num); 2030 } 2031 2032 /** 2033 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband 2034 * Management Datagrams. 2035 * @device: Device to check 2036 * @port_num: Port number to check 2037 * 2038 * Management Datagrams (MAD) are a required part of the InfiniBand 2039 * specification and are supported on all InfiniBand devices. A slightly 2040 * extended version are also supported on OPA interfaces. 2041 * 2042 * Return: true if the port supports sending/receiving of MAD packets. 2043 */ 2044 static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num) 2045 { 2046 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD; 2047 } 2048 2049 /** 2050 * rdma_cap_opa_mad - Check if the port of device provides support for OPA 2051 * Management Datagrams. 2052 * @device: Device to check 2053 * @port_num: Port number to check 2054 * 2055 * Intel OmniPath devices extend and/or replace the InfiniBand Management 2056 * datagrams with their own versions. These OPA MADs share many but not all of 2057 * the characteristics of InfiniBand MADs. 2058 * 2059 * OPA MADs differ in the following ways: 2060 * 2061 * 1) MADs are variable size up to 2K 2062 * IBTA defined MADs remain fixed at 256 bytes 2063 * 2) OPA SMPs must carry valid PKeys 2064 * 3) OPA SMP packets are a different format 2065 * 2066 * Return: true if the port supports OPA MAD packet formats. 2067 */ 2068 static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num) 2069 { 2070 return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD) 2071 == RDMA_CORE_CAP_OPA_MAD; 2072 } 2073 2074 /** 2075 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband 2076 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI). 2077 * @device: Device to check 2078 * @port_num: Port number to check 2079 * 2080 * Each InfiniBand node is required to provide a Subnet Management Agent 2081 * that the subnet manager can access. Prior to the fabric being fully 2082 * configured by the subnet manager, the SMA is accessed via a well known 2083 * interface called the Subnet Management Interface (SMI). This interface 2084 * uses directed route packets to communicate with the SM to get around the 2085 * chicken and egg problem of the SM needing to know what's on the fabric 2086 * in order to configure the fabric, and needing to configure the fabric in 2087 * order to send packets to the devices on the fabric. These directed 2088 * route packets do not need the fabric fully configured in order to reach 2089 * their destination. The SMI is the only method allowed to send 2090 * directed route packets on an InfiniBand fabric. 2091 * 2092 * Return: true if the port provides an SMI. 2093 */ 2094 static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num) 2095 { 2096 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI; 2097 } 2098 2099 /** 2100 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband 2101 * Communication Manager. 2102 * @device: Device to check 2103 * @port_num: Port number to check 2104 * 2105 * The InfiniBand Communication Manager is one of many pre-defined General 2106 * Service Agents (GSA) that are accessed via the General Service 2107 * Interface (GSI). It's role is to facilitate establishment of connections 2108 * between nodes as well as other management related tasks for established 2109 * connections. 2110 * 2111 * Return: true if the port supports an IB CM (this does not guarantee that 2112 * a CM is actually running however). 2113 */ 2114 static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num) 2115 { 2116 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM; 2117 } 2118 2119 /** 2120 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP 2121 * Communication Manager. 2122 * @device: Device to check 2123 * @port_num: Port number to check 2124 * 2125 * Similar to above, but specific to iWARP connections which have a different 2126 * managment protocol than InfiniBand. 2127 * 2128 * Return: true if the port supports an iWARP CM (this does not guarantee that 2129 * a CM is actually running however). 2130 */ 2131 static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num) 2132 { 2133 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM; 2134 } 2135 2136 /** 2137 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband 2138 * Subnet Administration. 2139 * @device: Device to check 2140 * @port_num: Port number to check 2141 * 2142 * An InfiniBand Subnet Administration (SA) service is a pre-defined General 2143 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand 2144 * fabrics, devices should resolve routes to other hosts by contacting the 2145 * SA to query the proper route. 2146 * 2147 * Return: true if the port should act as a client to the fabric Subnet 2148 * Administration interface. This does not imply that the SA service is 2149 * running locally. 2150 */ 2151 static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num) 2152 { 2153 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA; 2154 } 2155 2156 /** 2157 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband 2158 * Multicast. 2159 * @device: Device to check 2160 * @port_num: Port number to check 2161 * 2162 * InfiniBand multicast registration is more complex than normal IPv4 or 2163 * IPv6 multicast registration. Each Host Channel Adapter must register 2164 * with the Subnet Manager when it wishes to join a multicast group. It 2165 * should do so only once regardless of how many queue pairs it subscribes 2166 * to this group. And it should leave the group only after all queue pairs 2167 * attached to the group have been detached. 2168 * 2169 * Return: true if the port must undertake the additional adminstrative 2170 * overhead of registering/unregistering with the SM and tracking of the 2171 * total number of queue pairs attached to the multicast group. 2172 */ 2173 static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num) 2174 { 2175 return rdma_cap_ib_sa(device, port_num); 2176 } 2177 2178 /** 2179 * rdma_cap_af_ib - Check if the port of device has the capability 2180 * Native Infiniband Address. 2181 * @device: Device to check 2182 * @port_num: Port number to check 2183 * 2184 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default 2185 * GID. RoCE uses a different mechanism, but still generates a GID via 2186 * a prescribed mechanism and port specific data. 2187 * 2188 * Return: true if the port uses a GID address to identify devices on the 2189 * network. 2190 */ 2191 static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num) 2192 { 2193 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB; 2194 } 2195 2196 /** 2197 * rdma_cap_eth_ah - Check if the port of device has the capability 2198 * Ethernet Address Handle. 2199 * @device: Device to check 2200 * @port_num: Port number to check 2201 * 2202 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique 2203 * to fabricate GIDs over Ethernet/IP specific addresses native to the 2204 * port. Normally, packet headers are generated by the sending host 2205 * adapter, but when sending connectionless datagrams, we must manually 2206 * inject the proper headers for the fabric we are communicating over. 2207 * 2208 * Return: true if we are running as a RoCE port and must force the 2209 * addition of a Global Route Header built from our Ethernet Address 2210 * Handle into our header list for connectionless packets. 2211 */ 2212 static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num) 2213 { 2214 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH; 2215 } 2216 2217 /** 2218 * rdma_max_mad_size - Return the max MAD size required by this RDMA Port. 2219 * 2220 * @device: Device 2221 * @port_num: Port number 2222 * 2223 * This MAD size includes the MAD headers and MAD payload. No other headers 2224 * are included. 2225 * 2226 * Return the max MAD size required by the Port. Will return 0 if the port 2227 * does not support MADs 2228 */ 2229 static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num) 2230 { 2231 return device->port_immutable[port_num].max_mad_size; 2232 } 2233 2234 /* 2235 * Check if the device supports READ W/ INVALIDATE. 2236 */ 2237 static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num) 2238 { 2239 /* 2240 * iWarp drivers must support READ W/ INVALIDATE. No other protocol 2241 * has support for it yet. 2242 */ 2243 return rdma_protocol_iwarp(dev, port_num); 2244 } 2245 2246 int ib_query_gid(struct ib_device *device, 2247 u8 port_num, int index, union ib_gid *gid); 2248 2249 int ib_query_pkey(struct ib_device *device, 2250 u8 port_num, u16 index, u16 *pkey); 2251 2252 int ib_modify_device(struct ib_device *device, 2253 int device_modify_mask, 2254 struct ib_device_modify *device_modify); 2255 2256 int ib_modify_port(struct ib_device *device, 2257 u8 port_num, int port_modify_mask, 2258 struct ib_port_modify *port_modify); 2259 2260 int ib_find_gid(struct ib_device *device, union ib_gid *gid, 2261 u8 *port_num, u16 *index); 2262 2263 int ib_find_pkey(struct ib_device *device, 2264 u8 port_num, u16 pkey, u16 *index); 2265 2266 /** 2267 * ib_alloc_pd - Allocates an unused protection domain. 2268 * @device: The device on which to allocate the protection domain. 2269 * 2270 * A protection domain object provides an association between QPs, shared 2271 * receive queues, address handles, memory regions, and memory windows. 2272 */ 2273 struct ib_pd *ib_alloc_pd(struct ib_device *device); 2274 2275 /** 2276 * ib_dealloc_pd - Deallocates a protection domain. 2277 * @pd: The protection domain to deallocate. 2278 */ 2279 int ib_dealloc_pd(struct ib_pd *pd); 2280 2281 /** 2282 * ib_create_ah - Creates an address handle for the given address vector. 2283 * @pd: The protection domain associated with the address handle. 2284 * @ah_attr: The attributes of the address vector. 2285 * 2286 * The address handle is used to reference a local or global destination 2287 * in all UD QP post sends. 2288 */ 2289 struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr); 2290 2291 /** 2292 * ib_init_ah_from_wc - Initializes address handle attributes from a 2293 * work completion. 2294 * @device: Device on which the received message arrived. 2295 * @port_num: Port on which the received message arrived. 2296 * @wc: Work completion associated with the received message. 2297 * @grh: References the received global route header. This parameter is 2298 * ignored unless the work completion indicates that the GRH is valid. 2299 * @ah_attr: Returned attributes that can be used when creating an address 2300 * handle for replying to the message. 2301 */ 2302 int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc, 2303 struct ib_grh *grh, struct ib_ah_attr *ah_attr); 2304 2305 /** 2306 * ib_create_ah_from_wc - Creates an address handle associated with the 2307 * sender of the specified work completion. 2308 * @pd: The protection domain associated with the address handle. 2309 * @wc: Work completion information associated with a received message. 2310 * @grh: References the received global route header. This parameter is 2311 * ignored unless the work completion indicates that the GRH is valid. 2312 * @port_num: The outbound port number to associate with the address. 2313 * 2314 * The address handle is used to reference a local or global destination 2315 * in all UD QP post sends. 2316 */ 2317 struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc, 2318 struct ib_grh *grh, u8 port_num); 2319 2320 /** 2321 * ib_modify_ah - Modifies the address vector associated with an address 2322 * handle. 2323 * @ah: The address handle to modify. 2324 * @ah_attr: The new address vector attributes to associate with the 2325 * address handle. 2326 */ 2327 int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr); 2328 2329 /** 2330 * ib_query_ah - Queries the address vector associated with an address 2331 * handle. 2332 * @ah: The address handle to query. 2333 * @ah_attr: The address vector attributes associated with the address 2334 * handle. 2335 */ 2336 int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr); 2337 2338 /** 2339 * ib_destroy_ah - Destroys an address handle. 2340 * @ah: The address handle to destroy. 2341 */ 2342 int ib_destroy_ah(struct ib_ah *ah); 2343 2344 /** 2345 * ib_create_srq - Creates a SRQ associated with the specified protection 2346 * domain. 2347 * @pd: The protection domain associated with the SRQ. 2348 * @srq_init_attr: A list of initial attributes required to create the 2349 * SRQ. If SRQ creation succeeds, then the attributes are updated to 2350 * the actual capabilities of the created SRQ. 2351 * 2352 * srq_attr->max_wr and srq_attr->max_sge are read the determine the 2353 * requested size of the SRQ, and set to the actual values allocated 2354 * on return. If ib_create_srq() succeeds, then max_wr and max_sge 2355 * will always be at least as large as the requested values. 2356 */ 2357 struct ib_srq *ib_create_srq(struct ib_pd *pd, 2358 struct ib_srq_init_attr *srq_init_attr); 2359 2360 /** 2361 * ib_modify_srq - Modifies the attributes for the specified SRQ. 2362 * @srq: The SRQ to modify. 2363 * @srq_attr: On input, specifies the SRQ attributes to modify. On output, 2364 * the current values of selected SRQ attributes are returned. 2365 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ 2366 * are being modified. 2367 * 2368 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or 2369 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when 2370 * the number of receives queued drops below the limit. 2371 */ 2372 int ib_modify_srq(struct ib_srq *srq, 2373 struct ib_srq_attr *srq_attr, 2374 enum ib_srq_attr_mask srq_attr_mask); 2375 2376 /** 2377 * ib_query_srq - Returns the attribute list and current values for the 2378 * specified SRQ. 2379 * @srq: The SRQ to query. 2380 * @srq_attr: The attributes of the specified SRQ. 2381 */ 2382 int ib_query_srq(struct ib_srq *srq, 2383 struct ib_srq_attr *srq_attr); 2384 2385 /** 2386 * ib_destroy_srq - Destroys the specified SRQ. 2387 * @srq: The SRQ to destroy. 2388 */ 2389 int ib_destroy_srq(struct ib_srq *srq); 2390 2391 /** 2392 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ. 2393 * @srq: The SRQ to post the work request on. 2394 * @recv_wr: A list of work requests to post on the receive queue. 2395 * @bad_recv_wr: On an immediate failure, this parameter will reference 2396 * the work request that failed to be posted on the QP. 2397 */ 2398 static inline int ib_post_srq_recv(struct ib_srq *srq, 2399 struct ib_recv_wr *recv_wr, 2400 struct ib_recv_wr **bad_recv_wr) 2401 { 2402 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr); 2403 } 2404 2405 /** 2406 * ib_create_qp - Creates a QP associated with the specified protection 2407 * domain. 2408 * @pd: The protection domain associated with the QP. 2409 * @qp_init_attr: A list of initial attributes required to create the 2410 * QP. If QP creation succeeds, then the attributes are updated to 2411 * the actual capabilities of the created QP. 2412 */ 2413 struct ib_qp *ib_create_qp(struct ib_pd *pd, 2414 struct ib_qp_init_attr *qp_init_attr); 2415 2416 /** 2417 * ib_modify_qp - Modifies the attributes for the specified QP and then 2418 * transitions the QP to the given state. 2419 * @qp: The QP to modify. 2420 * @qp_attr: On input, specifies the QP attributes to modify. On output, 2421 * the current values of selected QP attributes are returned. 2422 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP 2423 * are being modified. 2424 */ 2425 int ib_modify_qp(struct ib_qp *qp, 2426 struct ib_qp_attr *qp_attr, 2427 int qp_attr_mask); 2428 2429 /** 2430 * ib_query_qp - Returns the attribute list and current values for the 2431 * specified QP. 2432 * @qp: The QP to query. 2433 * @qp_attr: The attributes of the specified QP. 2434 * @qp_attr_mask: A bit-mask used to select specific attributes to query. 2435 * @qp_init_attr: Additional attributes of the selected QP. 2436 * 2437 * The qp_attr_mask may be used to limit the query to gathering only the 2438 * selected attributes. 2439 */ 2440 int ib_query_qp(struct ib_qp *qp, 2441 struct ib_qp_attr *qp_attr, 2442 int qp_attr_mask, 2443 struct ib_qp_init_attr *qp_init_attr); 2444 2445 /** 2446 * ib_destroy_qp - Destroys the specified QP. 2447 * @qp: The QP to destroy. 2448 */ 2449 int ib_destroy_qp(struct ib_qp *qp); 2450 2451 /** 2452 * ib_open_qp - Obtain a reference to an existing sharable QP. 2453 * @xrcd - XRC domain 2454 * @qp_open_attr: Attributes identifying the QP to open. 2455 * 2456 * Returns a reference to a sharable QP. 2457 */ 2458 struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd, 2459 struct ib_qp_open_attr *qp_open_attr); 2460 2461 /** 2462 * ib_close_qp - Release an external reference to a QP. 2463 * @qp: The QP handle to release 2464 * 2465 * The opened QP handle is released by the caller. The underlying 2466 * shared QP is not destroyed until all internal references are released. 2467 */ 2468 int ib_close_qp(struct ib_qp *qp); 2469 2470 /** 2471 * ib_post_send - Posts a list of work requests to the send queue of 2472 * the specified QP. 2473 * @qp: The QP to post the work request on. 2474 * @send_wr: A list of work requests to post on the send queue. 2475 * @bad_send_wr: On an immediate failure, this parameter will reference 2476 * the work request that failed to be posted on the QP. 2477 * 2478 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate 2479 * error is returned, the QP state shall not be affected, 2480 * ib_post_send() will return an immediate error after queueing any 2481 * earlier work requests in the list. 2482 */ 2483 static inline int ib_post_send(struct ib_qp *qp, 2484 struct ib_send_wr *send_wr, 2485 struct ib_send_wr **bad_send_wr) 2486 { 2487 return qp->device->post_send(qp, send_wr, bad_send_wr); 2488 } 2489 2490 /** 2491 * ib_post_recv - Posts a list of work requests to the receive queue of 2492 * the specified QP. 2493 * @qp: The QP to post the work request on. 2494 * @recv_wr: A list of work requests to post on the receive queue. 2495 * @bad_recv_wr: On an immediate failure, this parameter will reference 2496 * the work request that failed to be posted on the QP. 2497 */ 2498 static inline int ib_post_recv(struct ib_qp *qp, 2499 struct ib_recv_wr *recv_wr, 2500 struct ib_recv_wr **bad_recv_wr) 2501 { 2502 return qp->device->post_recv(qp, recv_wr, bad_recv_wr); 2503 } 2504 2505 /** 2506 * ib_create_cq - Creates a CQ on the specified device. 2507 * @device: The device on which to create the CQ. 2508 * @comp_handler: A user-specified callback that is invoked when a 2509 * completion event occurs on the CQ. 2510 * @event_handler: A user-specified callback that is invoked when an 2511 * asynchronous event not associated with a completion occurs on the CQ. 2512 * @cq_context: Context associated with the CQ returned to the user via 2513 * the associated completion and event handlers. 2514 * @cqe: The minimum size of the CQ. 2515 * @comp_vector - Completion vector used to signal completion events. 2516 * Must be >= 0 and < context->num_comp_vectors. 2517 * 2518 * Users can examine the cq structure to determine the actual CQ size. 2519 */ 2520 struct ib_cq *ib_create_cq(struct ib_device *device, 2521 ib_comp_handler comp_handler, 2522 void (*event_handler)(struct ib_event *, void *), 2523 void *cq_context, int cqe, int comp_vector); 2524 2525 /** 2526 * ib_resize_cq - Modifies the capacity of the CQ. 2527 * @cq: The CQ to resize. 2528 * @cqe: The minimum size of the CQ. 2529 * 2530 * Users can examine the cq structure to determine the actual CQ size. 2531 */ 2532 int ib_resize_cq(struct ib_cq *cq, int cqe); 2533 2534 /** 2535 * ib_modify_cq - Modifies the attributes for the specified CQ and then 2536 * transitions the CQ to the given state. 2537 * @cq: The CQ to modify. 2538 * @cq_attr: specifies the CQ attributes to modify. 2539 * @cq_attr_mask: A bit-mask used to specify which attributes of the CQ 2540 * are being modified. 2541 */ 2542 int ib_modify_cq(struct ib_cq *cq, 2543 struct ib_cq_attr *cq_attr, 2544 int cq_attr_mask); 2545 2546 /** 2547 * ib_destroy_cq - Destroys the specified CQ. 2548 * @cq: The CQ to destroy. 2549 */ 2550 int ib_destroy_cq(struct ib_cq *cq); 2551 2552 /** 2553 * ib_poll_cq - poll a CQ for completion(s) 2554 * @cq:the CQ being polled 2555 * @num_entries:maximum number of completions to return 2556 * @wc:array of at least @num_entries &struct ib_wc where completions 2557 * will be returned 2558 * 2559 * Poll a CQ for (possibly multiple) completions. If the return value 2560 * is < 0, an error occurred. If the return value is >= 0, it is the 2561 * number of completions returned. If the return value is 2562 * non-negative and < num_entries, then the CQ was emptied. 2563 */ 2564 static inline int ib_poll_cq(struct ib_cq *cq, int num_entries, 2565 struct ib_wc *wc) 2566 { 2567 return cq->device->poll_cq(cq, num_entries, wc); 2568 } 2569 2570 /** 2571 * ib_peek_cq - Returns the number of unreaped completions currently 2572 * on the specified CQ. 2573 * @cq: The CQ to peek. 2574 * @wc_cnt: A minimum number of unreaped completions to check for. 2575 * 2576 * If the number of unreaped completions is greater than or equal to wc_cnt, 2577 * this function returns wc_cnt, otherwise, it returns the actual number of 2578 * unreaped completions. 2579 */ 2580 int ib_peek_cq(struct ib_cq *cq, int wc_cnt); 2581 2582 /** 2583 * ib_req_notify_cq - Request completion notification on a CQ. 2584 * @cq: The CQ to generate an event for. 2585 * @flags: 2586 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP 2587 * to request an event on the next solicited event or next work 2588 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS 2589 * may also be |ed in to request a hint about missed events, as 2590 * described below. 2591 * 2592 * Return Value: 2593 * < 0 means an error occurred while requesting notification 2594 * == 0 means notification was requested successfully, and if 2595 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events 2596 * were missed and it is safe to wait for another event. In 2597 * this case is it guaranteed that any work completions added 2598 * to the CQ since the last CQ poll will trigger a completion 2599 * notification event. 2600 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed 2601 * in. It means that the consumer must poll the CQ again to 2602 * make sure it is empty to avoid missing an event because of a 2603 * race between requesting notification and an entry being 2604 * added to the CQ. This return value means it is possible 2605 * (but not guaranteed) that a work completion has been added 2606 * to the CQ since the last poll without triggering a 2607 * completion notification event. 2608 */ 2609 static inline int ib_req_notify_cq(struct ib_cq *cq, 2610 enum ib_cq_notify_flags flags) 2611 { 2612 return cq->device->req_notify_cq(cq, flags); 2613 } 2614 2615 /** 2616 * ib_req_ncomp_notif - Request completion notification when there are 2617 * at least the specified number of unreaped completions on the CQ. 2618 * @cq: The CQ to generate an event for. 2619 * @wc_cnt: The number of unreaped completions that should be on the 2620 * CQ before an event is generated. 2621 */ 2622 static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt) 2623 { 2624 return cq->device->req_ncomp_notif ? 2625 cq->device->req_ncomp_notif(cq, wc_cnt) : 2626 -ENOSYS; 2627 } 2628 2629 /** 2630 * ib_get_dma_mr - Returns a memory region for system memory that is 2631 * usable for DMA. 2632 * @pd: The protection domain associated with the memory region. 2633 * @mr_access_flags: Specifies the memory access rights. 2634 * 2635 * Note that the ib_dma_*() functions defined below must be used 2636 * to create/destroy addresses used with the Lkey or Rkey returned 2637 * by ib_get_dma_mr(). 2638 */ 2639 struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags); 2640 2641 /** 2642 * ib_dma_mapping_error - check a DMA addr for error 2643 * @dev: The device for which the dma_addr was created 2644 * @dma_addr: The DMA address to check 2645 */ 2646 static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr) 2647 { 2648 if (dev->dma_ops) 2649 return dev->dma_ops->mapping_error(dev, dma_addr); 2650 return dma_mapping_error(dev->dma_device, dma_addr); 2651 } 2652 2653 /** 2654 * ib_dma_map_single - Map a kernel virtual address to DMA address 2655 * @dev: The device for which the dma_addr is to be created 2656 * @cpu_addr: The kernel virtual address 2657 * @size: The size of the region in bytes 2658 * @direction: The direction of the DMA 2659 */ 2660 static inline u64 ib_dma_map_single(struct ib_device *dev, 2661 void *cpu_addr, size_t size, 2662 enum dma_data_direction direction) 2663 { 2664 if (dev->dma_ops) 2665 return dev->dma_ops->map_single(dev, cpu_addr, size, direction); 2666 return dma_map_single(dev->dma_device, cpu_addr, size, direction); 2667 } 2668 2669 /** 2670 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single() 2671 * @dev: The device for which the DMA address was created 2672 * @addr: The DMA address 2673 * @size: The size of the region in bytes 2674 * @direction: The direction of the DMA 2675 */ 2676 static inline void ib_dma_unmap_single(struct ib_device *dev, 2677 u64 addr, size_t size, 2678 enum dma_data_direction direction) 2679 { 2680 if (dev->dma_ops) 2681 dev->dma_ops->unmap_single(dev, addr, size, direction); 2682 else 2683 dma_unmap_single(dev->dma_device, addr, size, direction); 2684 } 2685 2686 static inline u64 ib_dma_map_single_attrs(struct ib_device *dev, 2687 void *cpu_addr, size_t size, 2688 enum dma_data_direction direction, 2689 struct dma_attrs *attrs) 2690 { 2691 return dma_map_single_attrs(dev->dma_device, cpu_addr, size, 2692 direction, attrs); 2693 } 2694 2695 static inline void ib_dma_unmap_single_attrs(struct ib_device *dev, 2696 u64 addr, size_t size, 2697 enum dma_data_direction direction, 2698 struct dma_attrs *attrs) 2699 { 2700 return dma_unmap_single_attrs(dev->dma_device, addr, size, 2701 direction, attrs); 2702 } 2703 2704 /** 2705 * ib_dma_map_page - Map a physical page to DMA address 2706 * @dev: The device for which the dma_addr is to be created 2707 * @page: The page to be mapped 2708 * @offset: The offset within the page 2709 * @size: The size of the region in bytes 2710 * @direction: The direction of the DMA 2711 */ 2712 static inline u64 ib_dma_map_page(struct ib_device *dev, 2713 struct page *page, 2714 unsigned long offset, 2715 size_t size, 2716 enum dma_data_direction direction) 2717 { 2718 if (dev->dma_ops) 2719 return dev->dma_ops->map_page(dev, page, offset, size, direction); 2720 return dma_map_page(dev->dma_device, page, offset, size, direction); 2721 } 2722 2723 /** 2724 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page() 2725 * @dev: The device for which the DMA address was created 2726 * @addr: The DMA address 2727 * @size: The size of the region in bytes 2728 * @direction: The direction of the DMA 2729 */ 2730 static inline void ib_dma_unmap_page(struct ib_device *dev, 2731 u64 addr, size_t size, 2732 enum dma_data_direction direction) 2733 { 2734 if (dev->dma_ops) 2735 dev->dma_ops->unmap_page(dev, addr, size, direction); 2736 else 2737 dma_unmap_page(dev->dma_device, addr, size, direction); 2738 } 2739 2740 /** 2741 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses 2742 * @dev: The device for which the DMA addresses are to be created 2743 * @sg: The array of scatter/gather entries 2744 * @nents: The number of scatter/gather entries 2745 * @direction: The direction of the DMA 2746 */ 2747 static inline int ib_dma_map_sg(struct ib_device *dev, 2748 struct scatterlist *sg, int nents, 2749 enum dma_data_direction direction) 2750 { 2751 if (dev->dma_ops) 2752 return dev->dma_ops->map_sg(dev, sg, nents, direction); 2753 return dma_map_sg(dev->dma_device, sg, nents, direction); 2754 } 2755 2756 /** 2757 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses 2758 * @dev: The device for which the DMA addresses were created 2759 * @sg: The array of scatter/gather entries 2760 * @nents: The number of scatter/gather entries 2761 * @direction: The direction of the DMA 2762 */ 2763 static inline void ib_dma_unmap_sg(struct ib_device *dev, 2764 struct scatterlist *sg, int nents, 2765 enum dma_data_direction direction) 2766 { 2767 if (dev->dma_ops) 2768 dev->dma_ops->unmap_sg(dev, sg, nents, direction); 2769 else 2770 dma_unmap_sg(dev->dma_device, sg, nents, direction); 2771 } 2772 2773 static inline int ib_dma_map_sg_attrs(struct ib_device *dev, 2774 struct scatterlist *sg, int nents, 2775 enum dma_data_direction direction, 2776 struct dma_attrs *attrs) 2777 { 2778 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs); 2779 } 2780 2781 static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev, 2782 struct scatterlist *sg, int nents, 2783 enum dma_data_direction direction, 2784 struct dma_attrs *attrs) 2785 { 2786 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs); 2787 } 2788 /** 2789 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry 2790 * @dev: The device for which the DMA addresses were created 2791 * @sg: The scatter/gather entry 2792 */ 2793 static inline u64 ib_sg_dma_address(struct ib_device *dev, 2794 struct scatterlist *sg) 2795 { 2796 if (dev->dma_ops) 2797 return dev->dma_ops->dma_address(dev, sg); 2798 return sg_dma_address(sg); 2799 } 2800 2801 /** 2802 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry 2803 * @dev: The device for which the DMA addresses were created 2804 * @sg: The scatter/gather entry 2805 */ 2806 static inline unsigned int ib_sg_dma_len(struct ib_device *dev, 2807 struct scatterlist *sg) 2808 { 2809 if (dev->dma_ops) 2810 return dev->dma_ops->dma_len(dev, sg); 2811 return sg_dma_len(sg); 2812 } 2813 2814 /** 2815 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU 2816 * @dev: The device for which the DMA address was created 2817 * @addr: The DMA address 2818 * @size: The size of the region in bytes 2819 * @dir: The direction of the DMA 2820 */ 2821 static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev, 2822 u64 addr, 2823 size_t size, 2824 enum dma_data_direction dir) 2825 { 2826 if (dev->dma_ops) 2827 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir); 2828 else 2829 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir); 2830 } 2831 2832 /** 2833 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device 2834 * @dev: The device for which the DMA address was created 2835 * @addr: The DMA address 2836 * @size: The size of the region in bytes 2837 * @dir: The direction of the DMA 2838 */ 2839 static inline void ib_dma_sync_single_for_device(struct ib_device *dev, 2840 u64 addr, 2841 size_t size, 2842 enum dma_data_direction dir) 2843 { 2844 if (dev->dma_ops) 2845 dev->dma_ops->sync_single_for_device(dev, addr, size, dir); 2846 else 2847 dma_sync_single_for_device(dev->dma_device, addr, size, dir); 2848 } 2849 2850 /** 2851 * ib_dma_alloc_coherent - Allocate memory and map it for DMA 2852 * @dev: The device for which the DMA address is requested 2853 * @size: The size of the region to allocate in bytes 2854 * @dma_handle: A pointer for returning the DMA address of the region 2855 * @flag: memory allocator flags 2856 */ 2857 static inline void *ib_dma_alloc_coherent(struct ib_device *dev, 2858 size_t size, 2859 u64 *dma_handle, 2860 gfp_t flag) 2861 { 2862 if (dev->dma_ops) 2863 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag); 2864 else { 2865 dma_addr_t handle; 2866 void *ret; 2867 2868 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag); 2869 *dma_handle = handle; 2870 return ret; 2871 } 2872 } 2873 2874 /** 2875 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent() 2876 * @dev: The device for which the DMA addresses were allocated 2877 * @size: The size of the region 2878 * @cpu_addr: the address returned by ib_dma_alloc_coherent() 2879 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent() 2880 */ 2881 static inline void ib_dma_free_coherent(struct ib_device *dev, 2882 size_t size, void *cpu_addr, 2883 u64 dma_handle) 2884 { 2885 if (dev->dma_ops) 2886 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle); 2887 else 2888 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle); 2889 } 2890 2891 /** 2892 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use 2893 * by an HCA. 2894 * @pd: The protection domain associated assigned to the registered region. 2895 * @phys_buf_array: Specifies a list of physical buffers to use in the 2896 * memory region. 2897 * @num_phys_buf: Specifies the size of the phys_buf_array. 2898 * @mr_access_flags: Specifies the memory access rights. 2899 * @iova_start: The offset of the region's starting I/O virtual address. 2900 */ 2901 struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd, 2902 struct ib_phys_buf *phys_buf_array, 2903 int num_phys_buf, 2904 int mr_access_flags, 2905 u64 *iova_start); 2906 2907 /** 2908 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region. 2909 * Conceptually, this call performs the functions deregister memory region 2910 * followed by register physical memory region. Where possible, 2911 * resources are reused instead of deallocated and reallocated. 2912 * @mr: The memory region to modify. 2913 * @mr_rereg_mask: A bit-mask used to indicate which of the following 2914 * properties of the memory region are being modified. 2915 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies 2916 * the new protection domain to associated with the memory region, 2917 * otherwise, this parameter is ignored. 2918 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this 2919 * field specifies a list of physical buffers to use in the new 2920 * translation, otherwise, this parameter is ignored. 2921 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this 2922 * field specifies the size of the phys_buf_array, otherwise, this 2923 * parameter is ignored. 2924 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this 2925 * field specifies the new memory access rights, otherwise, this 2926 * parameter is ignored. 2927 * @iova_start: The offset of the region's starting I/O virtual address. 2928 */ 2929 int ib_rereg_phys_mr(struct ib_mr *mr, 2930 int mr_rereg_mask, 2931 struct ib_pd *pd, 2932 struct ib_phys_buf *phys_buf_array, 2933 int num_phys_buf, 2934 int mr_access_flags, 2935 u64 *iova_start); 2936 2937 /** 2938 * ib_query_mr - Retrieves information about a specific memory region. 2939 * @mr: The memory region to retrieve information about. 2940 * @mr_attr: The attributes of the specified memory region. 2941 */ 2942 int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr); 2943 2944 /** 2945 * ib_dereg_mr - Deregisters a memory region and removes it from the 2946 * HCA translation table. 2947 * @mr: The memory region to deregister. 2948 * 2949 * This function can fail, if the memory region has memory windows bound to it. 2950 */ 2951 int ib_dereg_mr(struct ib_mr *mr); 2952 2953 2954 /** 2955 * ib_create_mr - Allocates a memory region that may be used for 2956 * signature handover operations. 2957 * @pd: The protection domain associated with the region. 2958 * @mr_init_attr: memory region init attributes. 2959 */ 2960 struct ib_mr *ib_create_mr(struct ib_pd *pd, 2961 struct ib_mr_init_attr *mr_init_attr); 2962 2963 /** 2964 * ib_destroy_mr - Destroys a memory region that was created using 2965 * ib_create_mr and removes it from HW translation tables. 2966 * @mr: The memory region to destroy. 2967 * 2968 * This function can fail, if the memory region has memory windows bound to it. 2969 */ 2970 int ib_destroy_mr(struct ib_mr *mr); 2971 2972 /** 2973 * ib_alloc_fast_reg_mr - Allocates memory region usable with the 2974 * IB_WR_FAST_REG_MR send work request. 2975 * @pd: The protection domain associated with the region. 2976 * @max_page_list_len: requested max physical buffer list length to be 2977 * used with fast register work requests for this MR. 2978 */ 2979 struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len); 2980 2981 /** 2982 * ib_alloc_fast_reg_page_list - Allocates a page list array 2983 * @device - ib device pointer. 2984 * @page_list_len - size of the page list array to be allocated. 2985 * 2986 * This allocates and returns a struct ib_fast_reg_page_list * and a 2987 * page_list array that is at least page_list_len in size. The actual 2988 * size is returned in max_page_list_len. The caller is responsible 2989 * for initializing the contents of the page_list array before posting 2990 * a send work request with the IB_WC_FAST_REG_MR opcode. 2991 * 2992 * The page_list array entries must be translated using one of the 2993 * ib_dma_*() functions just like the addresses passed to 2994 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct 2995 * ib_fast_reg_page_list must not be modified by the caller until the 2996 * IB_WC_FAST_REG_MR work request completes. 2997 */ 2998 struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list( 2999 struct ib_device *device, int page_list_len); 3000 3001 /** 3002 * ib_free_fast_reg_page_list - Deallocates a previously allocated 3003 * page list array. 3004 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated. 3005 */ 3006 void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list); 3007 3008 /** 3009 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR 3010 * R_Key and L_Key. 3011 * @mr - struct ib_mr pointer to be updated. 3012 * @newkey - new key to be used. 3013 */ 3014 static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey) 3015 { 3016 mr->lkey = (mr->lkey & 0xffffff00) | newkey; 3017 mr->rkey = (mr->rkey & 0xffffff00) | newkey; 3018 } 3019 3020 /** 3021 * ib_inc_rkey - increments the key portion of the given rkey. Can be used 3022 * for calculating a new rkey for type 2 memory windows. 3023 * @rkey - the rkey to increment. 3024 */ 3025 static inline u32 ib_inc_rkey(u32 rkey) 3026 { 3027 const u32 mask = 0x000000ff; 3028 return ((rkey + 1) & mask) | (rkey & ~mask); 3029 } 3030 3031 /** 3032 * ib_alloc_mw - Allocates a memory window. 3033 * @pd: The protection domain associated with the memory window. 3034 * @type: The type of the memory window (1 or 2). 3035 */ 3036 struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type); 3037 3038 /** 3039 * ib_bind_mw - Posts a work request to the send queue of the specified 3040 * QP, which binds the memory window to the given address range and 3041 * remote access attributes. 3042 * @qp: QP to post the bind work request on. 3043 * @mw: The memory window to bind. 3044 * @mw_bind: Specifies information about the memory window, including 3045 * its address range, remote access rights, and associated memory region. 3046 * 3047 * If there is no immediate error, the function will update the rkey member 3048 * of the mw parameter to its new value. The bind operation can still fail 3049 * asynchronously. 3050 */ 3051 static inline int ib_bind_mw(struct ib_qp *qp, 3052 struct ib_mw *mw, 3053 struct ib_mw_bind *mw_bind) 3054 { 3055 /* XXX reference counting in corresponding MR? */ 3056 return mw->device->bind_mw ? 3057 mw->device->bind_mw(qp, mw, mw_bind) : 3058 -ENOSYS; 3059 } 3060 3061 /** 3062 * ib_dealloc_mw - Deallocates a memory window. 3063 * @mw: The memory window to deallocate. 3064 */ 3065 int ib_dealloc_mw(struct ib_mw *mw); 3066 3067 /** 3068 * ib_alloc_fmr - Allocates a unmapped fast memory region. 3069 * @pd: The protection domain associated with the unmapped region. 3070 * @mr_access_flags: Specifies the memory access rights. 3071 * @fmr_attr: Attributes of the unmapped region. 3072 * 3073 * A fast memory region must be mapped before it can be used as part of 3074 * a work request. 3075 */ 3076 struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd, 3077 int mr_access_flags, 3078 struct ib_fmr_attr *fmr_attr); 3079 3080 /** 3081 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region. 3082 * @fmr: The fast memory region to associate with the pages. 3083 * @page_list: An array of physical pages to map to the fast memory region. 3084 * @list_len: The number of pages in page_list. 3085 * @iova: The I/O virtual address to use with the mapped region. 3086 */ 3087 static inline int ib_map_phys_fmr(struct ib_fmr *fmr, 3088 u64 *page_list, int list_len, 3089 u64 iova) 3090 { 3091 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova); 3092 } 3093 3094 /** 3095 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions. 3096 * @fmr_list: A linked list of fast memory regions to unmap. 3097 */ 3098 int ib_unmap_fmr(struct list_head *fmr_list); 3099 3100 /** 3101 * ib_dealloc_fmr - Deallocates a fast memory region. 3102 * @fmr: The fast memory region to deallocate. 3103 */ 3104 int ib_dealloc_fmr(struct ib_fmr *fmr); 3105 3106 /** 3107 * ib_attach_mcast - Attaches the specified QP to a multicast group. 3108 * @qp: QP to attach to the multicast group. The QP must be type 3109 * IB_QPT_UD. 3110 * @gid: Multicast group GID. 3111 * @lid: Multicast group LID in host byte order. 3112 * 3113 * In order to send and receive multicast packets, subnet 3114 * administration must have created the multicast group and configured 3115 * the fabric appropriately. The port associated with the specified 3116 * QP must also be a member of the multicast group. 3117 */ 3118 int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); 3119 3120 /** 3121 * ib_detach_mcast - Detaches the specified QP from a multicast group. 3122 * @qp: QP to detach from the multicast group. 3123 * @gid: Multicast group GID. 3124 * @lid: Multicast group LID in host byte order. 3125 */ 3126 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); 3127 3128 /** 3129 * ib_alloc_xrcd - Allocates an XRC domain. 3130 * @device: The device on which to allocate the XRC domain. 3131 */ 3132 struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device); 3133 3134 /** 3135 * ib_dealloc_xrcd - Deallocates an XRC domain. 3136 * @xrcd: The XRC domain to deallocate. 3137 */ 3138 int ib_dealloc_xrcd(struct ib_xrcd *xrcd); 3139 3140 struct ib_flow *ib_create_flow(struct ib_qp *qp, 3141 struct ib_flow_attr *flow_attr, int domain); 3142 int ib_destroy_flow(struct ib_flow *flow_id); 3143 3144 struct ib_dct *ib_create_dct(struct ib_pd *pd, struct ib_dct_init_attr *attr, 3145 struct ib_udata *udata); 3146 int ib_destroy_dct(struct ib_dct *dct); 3147 int ib_query_dct(struct ib_dct *dct, struct ib_dct_attr *attr); 3148 3149 int ib_query_values(struct ib_device *device, 3150 int q_values, struct ib_device_values *values); 3151 3152 static inline void ib_active_speed_enum_to_rate(u8 active_speed, 3153 int *rate, 3154 char **speed) 3155 { 3156 switch (active_speed) { 3157 case IB_SPEED_DDR: 3158 *speed = " DDR"; 3159 *rate = 50; 3160 break; 3161 case IB_SPEED_QDR: 3162 *speed = " QDR"; 3163 *rate = 100; 3164 break; 3165 case IB_SPEED_FDR10: 3166 *speed = " FDR10"; 3167 *rate = 100; 3168 break; 3169 case IB_SPEED_FDR: 3170 *speed = " FDR"; 3171 *rate = 140; 3172 break; 3173 case IB_SPEED_EDR: 3174 *speed = " EDR"; 3175 *rate = 250; 3176 break; 3177 case IB_SPEED_SDR: 3178 default: /* default to SDR for invalid rates */ 3179 *rate = 25; 3180 break; 3181 } 3182 3183 } 3184 3185 static inline int ib_check_mr_access(int flags) 3186 { 3187 /* 3188 * Local write permission is required if remote write or 3189 * remote atomic permission is also requested. 3190 */ 3191 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) && 3192 !(flags & IB_ACCESS_LOCAL_WRITE)) 3193 return -EINVAL; 3194 3195 return 0; 3196 } 3197 3198 /** 3199 * ib_check_mr_status: lightweight check of MR status. 3200 * This routine may provide status checks on a selected 3201 * ib_mr. first use is for signature status check. 3202 * 3203 * @mr: A memory region. 3204 * @check_mask: Bitmask of which checks to perform from 3205 * ib_mr_status_check enumeration. 3206 * @mr_status: The container of relevant status checks. 3207 * failed checks will be indicated in the status bitmask 3208 * and the relevant info shall be in the error item. 3209 */ 3210 int ib_check_mr_status(struct ib_mr *mr, u32 check_mask, 3211 struct ib_mr_status *mr_status); 3212 3213 #endif /* IB_VERBS_H */ 3214