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 IB_WR_DUMMY = -1, /* force enum type signed */ 1141 }; 1142 1143 enum ib_send_flags { 1144 IB_SEND_FENCE = 1, 1145 IB_SEND_SIGNALED = (1<<1), 1146 IB_SEND_SOLICITED = (1<<2), 1147 IB_SEND_INLINE = (1<<3), 1148 IB_SEND_IP_CSUM = (1<<4), 1149 1150 /* reserve bits 26-31 for low level drivers' internal use */ 1151 IB_SEND_RESERVED_START = (1 << 26), 1152 IB_SEND_RESERVED_END = (1 << 31), 1153 IB_SEND_UMR_UNREG = (1<<5) 1154 }; 1155 1156 struct ib_sge { 1157 u64 addr; 1158 u32 length; 1159 u32 lkey; 1160 }; 1161 1162 struct ib_fast_reg_page_list { 1163 struct ib_device *device; 1164 u64 *page_list; 1165 unsigned int max_page_list_len; 1166 }; 1167 1168 /** 1169 * struct ib_mw_bind_info - Parameters for a memory window bind operation. 1170 * @mr: A memory region to bind the memory window to. 1171 * @addr: The address where the memory window should begin. 1172 * @length: The length of the memory window, in bytes. 1173 * @mw_access_flags: Access flags from enum ib_access_flags for the window. 1174 * 1175 * This struct contains the shared parameters for type 1 and type 2 1176 * memory window bind operations. 1177 */ 1178 struct ib_mw_bind_info { 1179 struct ib_mr *mr; 1180 u64 addr; 1181 u64 length; 1182 int mw_access_flags; 1183 }; 1184 1185 struct ib_send_wr { 1186 struct ib_send_wr *next; 1187 u64 wr_id; 1188 struct ib_sge *sg_list; 1189 int num_sge; 1190 enum ib_wr_opcode opcode; 1191 int send_flags; 1192 union { 1193 __be32 imm_data; 1194 u32 invalidate_rkey; 1195 } ex; 1196 union { 1197 struct { 1198 u64 remote_addr; 1199 u32 rkey; 1200 } rdma; 1201 struct { 1202 u64 remote_addr; 1203 u64 compare_add; 1204 u64 swap; 1205 u64 compare_add_mask; 1206 u64 swap_mask; 1207 u32 rkey; 1208 } atomic; 1209 struct { 1210 struct ib_ah *ah; 1211 void *header; 1212 int hlen; 1213 int mss; 1214 u32 remote_qpn; 1215 u32 remote_qkey; 1216 u16 pkey_index; /* valid for GSI only */ 1217 u8 port_num; /* valid for DR SMPs on switch only */ 1218 } ud; 1219 struct { 1220 u64 iova_start; 1221 struct ib_fast_reg_page_list *page_list; 1222 unsigned int page_shift; 1223 unsigned int page_list_len; 1224 u32 length; 1225 int access_flags; 1226 u32 rkey; 1227 } fast_reg; 1228 struct { 1229 int npages; 1230 int access_flags; 1231 u32 mkey; 1232 struct ib_pd *pd; 1233 u64 virt_addr; 1234 u64 length; 1235 int page_shift; 1236 } umr; 1237 struct { 1238 struct ib_mw *mw; 1239 /* The new rkey for the memory window. */ 1240 u32 rkey; 1241 struct ib_mw_bind_info bind_info; 1242 } bind_mw; 1243 struct { 1244 struct ib_sig_attrs *sig_attrs; 1245 struct ib_mr *sig_mr; 1246 int access_flags; 1247 struct ib_sge *prot; 1248 } sig_handover; 1249 } wr; 1250 u32 xrc_remote_srq_num; /* XRC TGT QPs only */ 1251 }; 1252 1253 struct ib_recv_wr { 1254 struct ib_recv_wr *next; 1255 u64 wr_id; 1256 struct ib_sge *sg_list; 1257 int num_sge; 1258 }; 1259 1260 enum ib_access_flags { 1261 IB_ACCESS_LOCAL_WRITE = 1, 1262 IB_ACCESS_REMOTE_WRITE = (1<<1), 1263 IB_ACCESS_REMOTE_READ = (1<<2), 1264 IB_ACCESS_REMOTE_ATOMIC = (1<<3), 1265 IB_ACCESS_MW_BIND = (1<<4), 1266 IB_ACCESS_ALLOCATE_MR = (1<<5), 1267 IB_ZERO_BASED = (1<<13) 1268 }; 1269 1270 struct ib_phys_buf { 1271 u64 addr; 1272 u64 size; 1273 }; 1274 1275 struct ib_mr_attr { 1276 struct ib_pd *pd; 1277 u64 device_virt_addr; 1278 u64 size; 1279 int mr_access_flags; 1280 u32 lkey; 1281 u32 rkey; 1282 }; 1283 1284 enum ib_mr_rereg_flags { 1285 IB_MR_REREG_TRANS = 1, 1286 IB_MR_REREG_PD = (1<<1), 1287 IB_MR_REREG_ACCESS = (1<<2) 1288 }; 1289 1290 /** 1291 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation. 1292 * @wr_id: Work request id. 1293 * @send_flags: Flags from ib_send_flags enum. 1294 * @bind_info: More parameters of the bind operation. 1295 */ 1296 struct ib_mw_bind { 1297 u64 wr_id; 1298 int send_flags; 1299 struct ib_mw_bind_info bind_info; 1300 }; 1301 1302 struct ib_fmr_attr { 1303 int max_pages; 1304 int max_maps; 1305 u8 page_shift; 1306 }; 1307 1308 struct ib_ucontext { 1309 struct ib_device *device; 1310 struct list_head pd_list; 1311 struct list_head mr_list; 1312 struct list_head mw_list; 1313 struct list_head cq_list; 1314 struct list_head qp_list; 1315 struct list_head srq_list; 1316 struct list_head ah_list; 1317 struct list_head xrcd_list; 1318 struct list_head rule_list; 1319 struct list_head dct_list; 1320 int closing; 1321 void *peer_mem_private_data; 1322 char *peer_mem_name; 1323 }; 1324 1325 struct ib_uobject { 1326 u64 user_handle; /* handle given to us by userspace */ 1327 struct ib_ucontext *context; /* associated user context */ 1328 void *object; /* containing object */ 1329 struct list_head list; /* link to context's list */ 1330 int id; /* index into kernel idr */ 1331 struct kref ref; 1332 struct rw_semaphore mutex; /* protects .live */ 1333 int live; 1334 }; 1335 1336 struct ib_udata; 1337 struct ib_udata_ops { 1338 int (*copy_from)(void *dest, struct ib_udata *udata, 1339 size_t len); 1340 int (*copy_to)(struct ib_udata *udata, void *src, 1341 size_t len); 1342 }; 1343 1344 struct ib_udata { 1345 struct ib_udata_ops *ops; 1346 void __user *inbuf; 1347 void __user *outbuf; 1348 size_t inlen; 1349 size_t outlen; 1350 }; 1351 1352 struct ib_pd { 1353 struct ib_device *device; 1354 struct ib_uobject *uobject; 1355 atomic_t usecnt; /* count all resources */ 1356 }; 1357 1358 struct ib_xrcd { 1359 struct ib_device *device; 1360 atomic_t usecnt; /* count all exposed resources */ 1361 struct inode *inode; 1362 1363 struct mutex tgt_qp_mutex; 1364 struct list_head tgt_qp_list; 1365 }; 1366 1367 struct ib_ah { 1368 struct ib_device *device; 1369 struct ib_pd *pd; 1370 struct ib_uobject *uobject; 1371 }; 1372 1373 enum ib_cq_attr_mask { 1374 IB_CQ_MODERATION = (1 << 0), 1375 IB_CQ_CAP_FLAGS = (1 << 1) 1376 }; 1377 1378 enum ib_cq_cap_flags { 1379 IB_CQ_IGNORE_OVERRUN = (1 << 0) 1380 }; 1381 1382 struct ib_cq_attr { 1383 struct { 1384 u16 cq_count; 1385 u16 cq_period; 1386 } moderation; 1387 u32 cq_cap_flags; 1388 }; 1389 1390 typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context); 1391 1392 struct ib_cq { 1393 struct ib_device *device; 1394 struct ib_uobject *uobject; 1395 ib_comp_handler comp_handler; 1396 void (*event_handler)(struct ib_event *, void *); 1397 void *cq_context; 1398 int cqe; 1399 atomic_t usecnt; /* count number of work queues */ 1400 }; 1401 1402 struct ib_srq { 1403 struct ib_device *device; 1404 struct ib_pd *pd; 1405 struct ib_uobject *uobject; 1406 void (*event_handler)(struct ib_event *, void *); 1407 void *srq_context; 1408 enum ib_srq_type srq_type; 1409 atomic_t usecnt; 1410 1411 union { 1412 struct { 1413 struct ib_xrcd *xrcd; 1414 struct ib_cq *cq; 1415 u32 srq_num; 1416 } xrc; 1417 } ext; 1418 }; 1419 1420 struct ib_qp { 1421 struct ib_device *device; 1422 struct ib_pd *pd; 1423 struct ib_cq *send_cq; 1424 struct ib_cq *recv_cq; 1425 struct ib_srq *srq; 1426 struct ib_xrcd *xrcd; /* XRC TGT QPs only */ 1427 struct list_head xrcd_list; 1428 /* count times opened, mcast attaches, flow attaches */ 1429 atomic_t usecnt; 1430 struct list_head open_list; 1431 struct ib_qp *real_qp; 1432 struct ib_uobject *uobject; 1433 void (*event_handler)(struct ib_event *, void *); 1434 void *qp_context; 1435 u32 qp_num; 1436 enum ib_qp_type qp_type; 1437 enum ib_qpg_type qpg_type; 1438 u8 port_num; 1439 }; 1440 1441 struct ib_dct { 1442 struct ib_device *device; 1443 struct ib_uobject *uobject; 1444 struct ib_pd *pd; 1445 struct ib_cq *cq; 1446 struct ib_srq *srq; 1447 u32 dct_num; 1448 }; 1449 1450 struct ib_mr { 1451 struct ib_device *device; 1452 struct ib_pd *pd; 1453 struct ib_uobject *uobject; 1454 u32 lkey; 1455 u32 rkey; 1456 atomic_t usecnt; /* count number of MWs */ 1457 }; 1458 1459 struct ib_mw { 1460 struct ib_device *device; 1461 struct ib_pd *pd; 1462 struct ib_uobject *uobject; 1463 u32 rkey; 1464 enum ib_mw_type type; 1465 }; 1466 1467 struct ib_fmr { 1468 struct ib_device *device; 1469 struct ib_pd *pd; 1470 struct list_head list; 1471 u32 lkey; 1472 u32 rkey; 1473 }; 1474 1475 /* Supported steering options */ 1476 enum ib_flow_attr_type { 1477 /* steering according to rule specifications */ 1478 IB_FLOW_ATTR_NORMAL = 0x0, 1479 /* default unicast and multicast rule - 1480 * receive all Eth traffic which isn't steered to any QP 1481 */ 1482 IB_FLOW_ATTR_ALL_DEFAULT = 0x1, 1483 /* default multicast rule - 1484 * receive all Eth multicast traffic which isn't steered to any QP 1485 */ 1486 IB_FLOW_ATTR_MC_DEFAULT = 0x2, 1487 /* sniffer rule - receive all port traffic */ 1488 IB_FLOW_ATTR_SNIFFER = 0x3 1489 }; 1490 1491 /* Supported steering header types */ 1492 enum ib_flow_spec_type { 1493 /* L2 headers*/ 1494 IB_FLOW_SPEC_ETH = 0x20, 1495 IB_FLOW_SPEC_IB = 0x21, 1496 /* L3 header*/ 1497 IB_FLOW_SPEC_IPV4 = 0x30, 1498 /* L4 headers*/ 1499 IB_FLOW_SPEC_TCP = 0x40, 1500 IB_FLOW_SPEC_UDP = 0x41 1501 }; 1502 1503 #define IB_FLOW_SPEC_SUPPORT_LAYERS 4 1504 1505 /* Flow steering rule priority is set according to it's domain. 1506 * Lower domain value means higher priority. 1507 */ 1508 enum ib_flow_domain { 1509 IB_FLOW_DOMAIN_USER, 1510 IB_FLOW_DOMAIN_ETHTOOL, 1511 IB_FLOW_DOMAIN_RFS, 1512 IB_FLOW_DOMAIN_NIC, 1513 IB_FLOW_DOMAIN_NUM /* Must be last */ 1514 }; 1515 1516 enum ib_flow_flags { 1517 IB_FLOW_ATTR_FLAGS_ALLOW_LOOP_BACK = 1 1518 }; 1519 1520 struct ib_flow_eth_filter { 1521 u8 dst_mac[6]; 1522 u8 src_mac[6]; 1523 __be16 ether_type; 1524 __be16 vlan_tag; 1525 }; 1526 1527 struct ib_flow_spec_eth { 1528 enum ib_flow_spec_type type; 1529 u16 size; 1530 struct ib_flow_eth_filter val; 1531 struct ib_flow_eth_filter mask; 1532 }; 1533 1534 struct ib_flow_ib_filter { 1535 __be32 l3_type_qpn; 1536 u8 dst_gid[16]; 1537 }; 1538 1539 struct ib_flow_spec_ib { 1540 enum ib_flow_spec_type type; 1541 u16 size; 1542 struct ib_flow_ib_filter val; 1543 struct ib_flow_ib_filter mask; 1544 }; 1545 1546 struct ib_flow_ipv4_filter { 1547 __be32 src_ip; 1548 __be32 dst_ip; 1549 }; 1550 1551 struct ib_flow_spec_ipv4 { 1552 enum ib_flow_spec_type type; 1553 u16 size; 1554 struct ib_flow_ipv4_filter val; 1555 struct ib_flow_ipv4_filter mask; 1556 }; 1557 1558 struct ib_flow_tcp_udp_filter { 1559 __be16 dst_port; 1560 __be16 src_port; 1561 }; 1562 1563 struct ib_flow_spec_tcp_udp { 1564 enum ib_flow_spec_type type; 1565 u16 size; 1566 struct ib_flow_tcp_udp_filter val; 1567 struct ib_flow_tcp_udp_filter mask; 1568 }; 1569 1570 union ib_flow_spec { 1571 struct { 1572 enum ib_flow_spec_type type; 1573 u16 size; 1574 }; 1575 struct ib_flow_spec_ib ib; 1576 struct ib_flow_spec_eth eth; 1577 struct ib_flow_spec_ipv4 ipv4; 1578 struct ib_flow_spec_tcp_udp tcp_udp; 1579 }; 1580 1581 struct ib_flow_attr { 1582 enum ib_flow_attr_type type; 1583 u16 size; 1584 u16 priority; 1585 u8 num_of_specs; 1586 u8 port; 1587 u32 flags; 1588 /* Following are the optional layers according to user request 1589 * struct ib_flow_spec_xxx 1590 * struct ib_flow_spec_yyy 1591 */ 1592 }; 1593 1594 struct ib_flow { 1595 struct ib_qp *qp; 1596 struct ib_uobject *uobject; 1597 }; 1598 1599 struct ib_mad; 1600 struct ib_grh; 1601 1602 enum ib_process_mad_flags { 1603 IB_MAD_IGNORE_MKEY = 1, 1604 IB_MAD_IGNORE_BKEY = 2, 1605 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY 1606 }; 1607 1608 enum ib_mad_result { 1609 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */ 1610 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */ 1611 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */ 1612 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */ 1613 }; 1614 1615 #define IB_DEVICE_NAME_MAX 64 1616 1617 struct ib_cache { 1618 rwlock_t lock; 1619 struct ib_event_handler event_handler; 1620 struct ib_pkey_cache **pkey_cache; 1621 struct ib_gid_cache **gid_cache; 1622 u8 *lmc_cache; 1623 }; 1624 1625 enum verbs_values_mask { 1626 IBV_VALUES_HW_CLOCK = 1 << 0 1627 }; 1628 1629 struct ib_device_values { 1630 int values_mask; 1631 uint64_t hwclock; 1632 }; 1633 1634 struct ib_dma_mapping_ops { 1635 int (*mapping_error)(struct ib_device *dev, 1636 u64 dma_addr); 1637 u64 (*map_single)(struct ib_device *dev, 1638 void *ptr, size_t size, 1639 enum dma_data_direction direction); 1640 void (*unmap_single)(struct ib_device *dev, 1641 u64 addr, size_t size, 1642 enum dma_data_direction direction); 1643 u64 (*map_page)(struct ib_device *dev, 1644 struct page *page, unsigned long offset, 1645 size_t size, 1646 enum dma_data_direction direction); 1647 void (*unmap_page)(struct ib_device *dev, 1648 u64 addr, size_t size, 1649 enum dma_data_direction direction); 1650 int (*map_sg)(struct ib_device *dev, 1651 struct scatterlist *sg, int nents, 1652 enum dma_data_direction direction); 1653 void (*unmap_sg)(struct ib_device *dev, 1654 struct scatterlist *sg, int nents, 1655 enum dma_data_direction direction); 1656 u64 (*dma_address)(struct ib_device *dev, 1657 struct scatterlist *sg); 1658 unsigned int (*dma_len)(struct ib_device *dev, 1659 struct scatterlist *sg); 1660 void (*sync_single_for_cpu)(struct ib_device *dev, 1661 u64 dma_handle, 1662 size_t size, 1663 enum dma_data_direction dir); 1664 void (*sync_single_for_device)(struct ib_device *dev, 1665 u64 dma_handle, 1666 size_t size, 1667 enum dma_data_direction dir); 1668 void *(*alloc_coherent)(struct ib_device *dev, 1669 size_t size, 1670 u64 *dma_handle, 1671 gfp_t flag); 1672 void (*free_coherent)(struct ib_device *dev, 1673 size_t size, void *cpu_addr, 1674 u64 dma_handle); 1675 }; 1676 1677 struct iw_cm_verbs; 1678 1679 struct ib_port_immutable { 1680 int pkey_tbl_len; 1681 int gid_tbl_len; 1682 u32 core_cap_flags; 1683 u32 max_mad_size; 1684 }; 1685 1686 struct ib_exp_device_attr; 1687 struct ib_exp_qp_init_attr; 1688 1689 struct ib_device { 1690 struct device *dma_device; 1691 1692 char name[IB_DEVICE_NAME_MAX]; 1693 1694 struct list_head event_handler_list; 1695 spinlock_t event_handler_lock; 1696 1697 spinlock_t client_data_lock; 1698 struct list_head core_list; 1699 struct list_head client_data_list; 1700 1701 struct ib_cache cache; 1702 /** 1703 * port_immutable is indexed by port number 1704 */ 1705 struct ib_port_immutable *port_immutable; 1706 1707 int num_comp_vectors; 1708 1709 struct iw_cm_verbs *iwcm; 1710 1711 int (*get_protocol_stats)(struct ib_device *device, 1712 union rdma_protocol_stats *stats); 1713 int (*query_device)(struct ib_device *device, 1714 struct ib_device_attr *device_attr); 1715 int (*query_port)(struct ib_device *device, 1716 u8 port_num, 1717 struct ib_port_attr *port_attr); 1718 enum rdma_link_layer (*get_link_layer)(struct ib_device *device, 1719 u8 port_num); 1720 /* When calling get_netdev, the HW vendor's driver should return the 1721 * net device of device @device at port @port_num. The function 1722 * is called in rtnl_lock. The HW vendor's device driver must guarantee 1723 * to return NULL before the net device has reached 1724 * NETDEV_UNREGISTER_FINAL state. 1725 */ 1726 struct net_device *(*get_netdev)(struct ib_device *device, 1727 u8 port_num); 1728 int (*query_gid)(struct ib_device *device, 1729 u8 port_num, int index, 1730 union ib_gid *gid); 1731 int (*query_pkey)(struct ib_device *device, 1732 u8 port_num, u16 index, u16 *pkey); 1733 int (*modify_device)(struct ib_device *device, 1734 int device_modify_mask, 1735 struct ib_device_modify *device_modify); 1736 int (*modify_port)(struct ib_device *device, 1737 u8 port_num, int port_modify_mask, 1738 struct ib_port_modify *port_modify); 1739 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device, 1740 struct ib_udata *udata); 1741 int (*dealloc_ucontext)(struct ib_ucontext *context); 1742 int (*mmap)(struct ib_ucontext *context, 1743 struct vm_area_struct *vma); 1744 struct ib_pd * (*alloc_pd)(struct ib_device *device, 1745 struct ib_ucontext *context, 1746 struct ib_udata *udata); 1747 int (*dealloc_pd)(struct ib_pd *pd); 1748 struct ib_ah * (*create_ah)(struct ib_pd *pd, 1749 struct ib_ah_attr *ah_attr); 1750 int (*modify_ah)(struct ib_ah *ah, 1751 struct ib_ah_attr *ah_attr); 1752 int (*query_ah)(struct ib_ah *ah, 1753 struct ib_ah_attr *ah_attr); 1754 int (*destroy_ah)(struct ib_ah *ah); 1755 struct ib_srq * (*create_srq)(struct ib_pd *pd, 1756 struct ib_srq_init_attr *srq_init_attr, 1757 struct ib_udata *udata); 1758 int (*modify_srq)(struct ib_srq *srq, 1759 struct ib_srq_attr *srq_attr, 1760 enum ib_srq_attr_mask srq_attr_mask, 1761 struct ib_udata *udata); 1762 int (*query_srq)(struct ib_srq *srq, 1763 struct ib_srq_attr *srq_attr); 1764 int (*destroy_srq)(struct ib_srq *srq); 1765 int (*post_srq_recv)(struct ib_srq *srq, 1766 struct ib_recv_wr *recv_wr, 1767 struct ib_recv_wr **bad_recv_wr); 1768 struct ib_qp * (*create_qp)(struct ib_pd *pd, 1769 struct ib_qp_init_attr *qp_init_attr, 1770 struct ib_udata *udata); 1771 int (*modify_qp)(struct ib_qp *qp, 1772 struct ib_qp_attr *qp_attr, 1773 int qp_attr_mask, 1774 struct ib_udata *udata); 1775 int (*query_qp)(struct ib_qp *qp, 1776 struct ib_qp_attr *qp_attr, 1777 int qp_attr_mask, 1778 struct ib_qp_init_attr *qp_init_attr); 1779 int (*destroy_qp)(struct ib_qp *qp); 1780 int (*post_send)(struct ib_qp *qp, 1781 struct ib_send_wr *send_wr, 1782 struct ib_send_wr **bad_send_wr); 1783 int (*post_recv)(struct ib_qp *qp, 1784 struct ib_recv_wr *recv_wr, 1785 struct ib_recv_wr **bad_recv_wr); 1786 struct ib_cq * (*create_cq)(struct ib_device *device, 1787 struct ib_cq_init_attr *attr, 1788 struct ib_ucontext *context, 1789 struct ib_udata *udata); 1790 int (*modify_cq)(struct ib_cq *cq, 1791 struct ib_cq_attr *cq_attr, 1792 int cq_attr_mask); 1793 int (*destroy_cq)(struct ib_cq *cq); 1794 int (*resize_cq)(struct ib_cq *cq, int cqe, 1795 struct ib_udata *udata); 1796 int (*poll_cq)(struct ib_cq *cq, int num_entries, 1797 struct ib_wc *wc); 1798 int (*peek_cq)(struct ib_cq *cq, int wc_cnt); 1799 int (*req_notify_cq)(struct ib_cq *cq, 1800 enum ib_cq_notify_flags flags); 1801 int (*req_ncomp_notif)(struct ib_cq *cq, 1802 int wc_cnt); 1803 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd, 1804 int mr_access_flags); 1805 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd, 1806 struct ib_phys_buf *phys_buf_array, 1807 int num_phys_buf, 1808 int mr_access_flags, 1809 u64 *iova_start); 1810 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd, 1811 u64 start, u64 length, 1812 u64 virt_addr, 1813 int mr_access_flags, 1814 struct ib_udata *udata, 1815 int mr_id); 1816 int (*query_mr)(struct ib_mr *mr, 1817 struct ib_mr_attr *mr_attr); 1818 int (*dereg_mr)(struct ib_mr *mr); 1819 int (*destroy_mr)(struct ib_mr *mr); 1820 struct ib_mr * (*create_mr)(struct ib_pd *pd, 1821 struct ib_mr_init_attr *mr_init_attr); 1822 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd, 1823 int max_page_list_len); 1824 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device, 1825 int page_list_len); 1826 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list); 1827 int (*rereg_phys_mr)(struct ib_mr *mr, 1828 int mr_rereg_mask, 1829 struct ib_pd *pd, 1830 struct ib_phys_buf *phys_buf_array, 1831 int num_phys_buf, 1832 int mr_access_flags, 1833 u64 *iova_start); 1834 struct ib_mw * (*alloc_mw)(struct ib_pd *pd, 1835 enum ib_mw_type type); 1836 int (*bind_mw)(struct ib_qp *qp, 1837 struct ib_mw *mw, 1838 struct ib_mw_bind *mw_bind); 1839 int (*dealloc_mw)(struct ib_mw *mw); 1840 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd, 1841 int mr_access_flags, 1842 struct ib_fmr_attr *fmr_attr); 1843 int (*map_phys_fmr)(struct ib_fmr *fmr, 1844 u64 *page_list, int list_len, 1845 u64 iova); 1846 int (*unmap_fmr)(struct list_head *fmr_list); 1847 int (*dealloc_fmr)(struct ib_fmr *fmr); 1848 int (*attach_mcast)(struct ib_qp *qp, 1849 union ib_gid *gid, 1850 u16 lid); 1851 int (*detach_mcast)(struct ib_qp *qp, 1852 union ib_gid *gid, 1853 u16 lid); 1854 int (*process_mad)(struct ib_device *device, 1855 int process_mad_flags, 1856 u8 port_num, 1857 struct ib_wc *in_wc, 1858 struct ib_grh *in_grh, 1859 struct ib_mad *in_mad, 1860 struct ib_mad *out_mad); 1861 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device, 1862 struct ib_ucontext *ucontext, 1863 struct ib_udata *udata); 1864 int (*dealloc_xrcd)(struct ib_xrcd *xrcd); 1865 struct ib_flow * (*create_flow)(struct ib_qp *qp, 1866 struct ib_flow_attr 1867 *flow_attr, 1868 int domain); 1869 int (*destroy_flow)(struct ib_flow *flow_id); 1870 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask, 1871 struct ib_mr_status *mr_status); 1872 1873 unsigned long (*get_unmapped_area)(struct file *file, 1874 unsigned long addr, 1875 unsigned long len, unsigned long pgoff, 1876 unsigned long flags); 1877 int (*ioctl)(struct ib_ucontext *context, 1878 unsigned int cmd, 1879 unsigned long arg); 1880 int (*query_values)(struct ib_device *device, 1881 int q_values, 1882 struct ib_device_values *values); 1883 struct ib_dma_mapping_ops *dma_ops; 1884 1885 struct module *owner; 1886 struct device dev; 1887 struct kobject *ports_parent; 1888 struct list_head port_list; 1889 1890 enum { 1891 IB_DEV_UNINITIALIZED, 1892 IB_DEV_REGISTERED, 1893 IB_DEV_UNREGISTERED 1894 } reg_state; 1895 1896 int uverbs_abi_ver; 1897 u64 uverbs_cmd_mask; 1898 u64 uverbs_ex_cmd_mask; 1899 1900 char node_desc[64]; 1901 __be64 node_guid; 1902 u32 local_dma_lkey; 1903 u8 node_type; 1904 u8 phys_port_cnt; 1905 int cmd_perf; 1906 u64 cmd_avg; 1907 u32 cmd_n; 1908 spinlock_t cmd_perf_lock; 1909 1910 1911 /** 1912 * The following mandatory functions are used only at device 1913 * registration. Keep functions such as these at the end of this 1914 * structure to avoid cache line misses when accessing struct ib_device 1915 * in fast paths. 1916 */ 1917 int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *); 1918 1919 /* 1920 * Experimental data and functions 1921 */ 1922 int (*exp_query_device)(struct ib_device *device, 1923 struct ib_exp_device_attr *device_attr); 1924 struct ib_qp * (*exp_create_qp)(struct ib_pd *pd, 1925 struct ib_exp_qp_init_attr *qp_init_attr, 1926 struct ib_udata *udata); 1927 struct ib_dct * (*exp_create_dct)(struct ib_pd *pd, 1928 struct ib_dct_init_attr *attr, 1929 struct ib_udata *udata); 1930 int (*exp_destroy_dct)(struct ib_dct *dct); 1931 int (*exp_query_dct)(struct ib_dct *dct, struct ib_dct_attr *attr); 1932 1933 u64 uverbs_exp_cmd_mask; 1934 }; 1935 1936 struct ib_client { 1937 char *name; 1938 void (*add) (struct ib_device *); 1939 void (*remove)(struct ib_device *); 1940 1941 struct list_head list; 1942 }; 1943 1944 struct ib_device *ib_alloc_device(size_t size); 1945 void ib_dealloc_device(struct ib_device *device); 1946 1947 int ib_register_device(struct ib_device *device, 1948 int (*port_callback)(struct ib_device *, 1949 u8, struct kobject *)); 1950 void ib_unregister_device(struct ib_device *device); 1951 1952 int ib_register_client (struct ib_client *client); 1953 void ib_unregister_client(struct ib_client *client); 1954 1955 void *ib_get_client_data(struct ib_device *device, struct ib_client *client); 1956 void ib_set_client_data(struct ib_device *device, struct ib_client *client, 1957 void *data); 1958 1959 static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len) 1960 { 1961 return udata->ops->copy_from(dest, udata, len); 1962 } 1963 1964 static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len) 1965 { 1966 return udata->ops->copy_to(udata, src, len); 1967 } 1968 1969 /** 1970 * ib_modify_qp_is_ok - Check that the supplied attribute mask 1971 * contains all required attributes and no attributes not allowed for 1972 * the given QP state transition. 1973 * @cur_state: Current QP state 1974 * @next_state: Next QP state 1975 * @type: QP type 1976 * @mask: Mask of supplied QP attributes 1977 * @ll : link layer of port 1978 * 1979 * This function is a helper function that a low-level driver's 1980 * modify_qp method can use to validate the consumer's input. It 1981 * checks that cur_state and next_state are valid QP states, that a 1982 * transition from cur_state to next_state is allowed by the IB spec, 1983 * and that the attribute mask supplied is allowed for the transition. 1984 */ 1985 int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state, 1986 enum ib_qp_type type, enum ib_qp_attr_mask mask, 1987 enum rdma_link_layer ll); 1988 1989 int ib_register_event_handler (struct ib_event_handler *event_handler); 1990 int ib_unregister_event_handler(struct ib_event_handler *event_handler); 1991 void ib_dispatch_event(struct ib_event *event); 1992 1993 int ib_query_device(struct ib_device *device, 1994 struct ib_device_attr *device_attr); 1995 1996 int ib_query_port(struct ib_device *device, 1997 u8 port_num, struct ib_port_attr *port_attr); 1998 1999 enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, 2000 u8 port_num); 2001 2002 static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num) 2003 { 2004 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB; 2005 } 2006 2007 static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num) 2008 { 2009 return device->port_immutable[port_num].core_cap_flags & 2010 (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP); 2011 } 2012 2013 static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num) 2014 { 2015 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP; 2016 } 2017 2018 static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num) 2019 { 2020 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE; 2021 } 2022 2023 static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num) 2024 { 2025 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP; 2026 } 2027 2028 static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num) 2029 { 2030 return rdma_protocol_ib(device, port_num) || 2031 rdma_protocol_roce(device, port_num); 2032 } 2033 2034 /** 2035 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband 2036 * Management Datagrams. 2037 * @device: Device to check 2038 * @port_num: Port number to check 2039 * 2040 * Management Datagrams (MAD) are a required part of the InfiniBand 2041 * specification and are supported on all InfiniBand devices. A slightly 2042 * extended version are also supported on OPA interfaces. 2043 * 2044 * Return: true if the port supports sending/receiving of MAD packets. 2045 */ 2046 static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num) 2047 { 2048 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD; 2049 } 2050 2051 /** 2052 * rdma_cap_opa_mad - Check if the port of device provides support for OPA 2053 * Management Datagrams. 2054 * @device: Device to check 2055 * @port_num: Port number to check 2056 * 2057 * Intel OmniPath devices extend and/or replace the InfiniBand Management 2058 * datagrams with their own versions. These OPA MADs share many but not all of 2059 * the characteristics of InfiniBand MADs. 2060 * 2061 * OPA MADs differ in the following ways: 2062 * 2063 * 1) MADs are variable size up to 2K 2064 * IBTA defined MADs remain fixed at 256 bytes 2065 * 2) OPA SMPs must carry valid PKeys 2066 * 3) OPA SMP packets are a different format 2067 * 2068 * Return: true if the port supports OPA MAD packet formats. 2069 */ 2070 static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num) 2071 { 2072 return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD) 2073 == RDMA_CORE_CAP_OPA_MAD; 2074 } 2075 2076 /** 2077 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband 2078 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI). 2079 * @device: Device to check 2080 * @port_num: Port number to check 2081 * 2082 * Each InfiniBand node is required to provide a Subnet Management Agent 2083 * that the subnet manager can access. Prior to the fabric being fully 2084 * configured by the subnet manager, the SMA is accessed via a well known 2085 * interface called the Subnet Management Interface (SMI). This interface 2086 * uses directed route packets to communicate with the SM to get around the 2087 * chicken and egg problem of the SM needing to know what's on the fabric 2088 * in order to configure the fabric, and needing to configure the fabric in 2089 * order to send packets to the devices on the fabric. These directed 2090 * route packets do not need the fabric fully configured in order to reach 2091 * their destination. The SMI is the only method allowed to send 2092 * directed route packets on an InfiniBand fabric. 2093 * 2094 * Return: true if the port provides an SMI. 2095 */ 2096 static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num) 2097 { 2098 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI; 2099 } 2100 2101 /** 2102 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband 2103 * Communication Manager. 2104 * @device: Device to check 2105 * @port_num: Port number to check 2106 * 2107 * The InfiniBand Communication Manager is one of many pre-defined General 2108 * Service Agents (GSA) that are accessed via the General Service 2109 * Interface (GSI). It's role is to facilitate establishment of connections 2110 * between nodes as well as other management related tasks for established 2111 * connections. 2112 * 2113 * Return: true if the port supports an IB CM (this does not guarantee that 2114 * a CM is actually running however). 2115 */ 2116 static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num) 2117 { 2118 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM; 2119 } 2120 2121 /** 2122 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP 2123 * Communication Manager. 2124 * @device: Device to check 2125 * @port_num: Port number to check 2126 * 2127 * Similar to above, but specific to iWARP connections which have a different 2128 * managment protocol than InfiniBand. 2129 * 2130 * Return: true if the port supports an iWARP CM (this does not guarantee that 2131 * a CM is actually running however). 2132 */ 2133 static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num) 2134 { 2135 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM; 2136 } 2137 2138 /** 2139 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband 2140 * Subnet Administration. 2141 * @device: Device to check 2142 * @port_num: Port number to check 2143 * 2144 * An InfiniBand Subnet Administration (SA) service is a pre-defined General 2145 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand 2146 * fabrics, devices should resolve routes to other hosts by contacting the 2147 * SA to query the proper route. 2148 * 2149 * Return: true if the port should act as a client to the fabric Subnet 2150 * Administration interface. This does not imply that the SA service is 2151 * running locally. 2152 */ 2153 static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num) 2154 { 2155 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA; 2156 } 2157 2158 /** 2159 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband 2160 * Multicast. 2161 * @device: Device to check 2162 * @port_num: Port number to check 2163 * 2164 * InfiniBand multicast registration is more complex than normal IPv4 or 2165 * IPv6 multicast registration. Each Host Channel Adapter must register 2166 * with the Subnet Manager when it wishes to join a multicast group. It 2167 * should do so only once regardless of how many queue pairs it subscribes 2168 * to this group. And it should leave the group only after all queue pairs 2169 * attached to the group have been detached. 2170 * 2171 * Return: true if the port must undertake the additional adminstrative 2172 * overhead of registering/unregistering with the SM and tracking of the 2173 * total number of queue pairs attached to the multicast group. 2174 */ 2175 static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num) 2176 { 2177 return rdma_cap_ib_sa(device, port_num); 2178 } 2179 2180 /** 2181 * rdma_cap_af_ib - Check if the port of device has the capability 2182 * Native Infiniband Address. 2183 * @device: Device to check 2184 * @port_num: Port number to check 2185 * 2186 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default 2187 * GID. RoCE uses a different mechanism, but still generates a GID via 2188 * a prescribed mechanism and port specific data. 2189 * 2190 * Return: true if the port uses a GID address to identify devices on the 2191 * network. 2192 */ 2193 static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num) 2194 { 2195 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB; 2196 } 2197 2198 /** 2199 * rdma_cap_eth_ah - Check if the port of device has the capability 2200 * Ethernet Address Handle. 2201 * @device: Device to check 2202 * @port_num: Port number to check 2203 * 2204 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique 2205 * to fabricate GIDs over Ethernet/IP specific addresses native to the 2206 * port. Normally, packet headers are generated by the sending host 2207 * adapter, but when sending connectionless datagrams, we must manually 2208 * inject the proper headers for the fabric we are communicating over. 2209 * 2210 * Return: true if we are running as a RoCE port and must force the 2211 * addition of a Global Route Header built from our Ethernet Address 2212 * Handle into our header list for connectionless packets. 2213 */ 2214 static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num) 2215 { 2216 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH; 2217 } 2218 2219 /** 2220 * rdma_max_mad_size - Return the max MAD size required by this RDMA Port. 2221 * 2222 * @device: Device 2223 * @port_num: Port number 2224 * 2225 * This MAD size includes the MAD headers and MAD payload. No other headers 2226 * are included. 2227 * 2228 * Return the max MAD size required by the Port. Will return 0 if the port 2229 * does not support MADs 2230 */ 2231 static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num) 2232 { 2233 return device->port_immutable[port_num].max_mad_size; 2234 } 2235 2236 /* 2237 * Check if the device supports READ W/ INVALIDATE. 2238 */ 2239 static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num) 2240 { 2241 /* 2242 * iWarp drivers must support READ W/ INVALIDATE. No other protocol 2243 * has support for it yet. 2244 */ 2245 return rdma_protocol_iwarp(dev, port_num); 2246 } 2247 2248 int ib_query_gid(struct ib_device *device, 2249 u8 port_num, int index, union ib_gid *gid); 2250 2251 int ib_query_pkey(struct ib_device *device, 2252 u8 port_num, u16 index, u16 *pkey); 2253 2254 int ib_modify_device(struct ib_device *device, 2255 int device_modify_mask, 2256 struct ib_device_modify *device_modify); 2257 2258 int ib_modify_port(struct ib_device *device, 2259 u8 port_num, int port_modify_mask, 2260 struct ib_port_modify *port_modify); 2261 2262 int ib_find_gid(struct ib_device *device, union ib_gid *gid, 2263 u8 *port_num, u16 *index); 2264 2265 int ib_find_pkey(struct ib_device *device, 2266 u8 port_num, u16 pkey, u16 *index); 2267 2268 /** 2269 * ib_alloc_pd - Allocates an unused protection domain. 2270 * @device: The device on which to allocate the protection domain. 2271 * 2272 * A protection domain object provides an association between QPs, shared 2273 * receive queues, address handles, memory regions, and memory windows. 2274 */ 2275 struct ib_pd *ib_alloc_pd(struct ib_device *device); 2276 2277 /** 2278 * ib_dealloc_pd - Deallocates a protection domain. 2279 * @pd: The protection domain to deallocate. 2280 */ 2281 int ib_dealloc_pd(struct ib_pd *pd); 2282 2283 /** 2284 * ib_create_ah - Creates an address handle for the given address vector. 2285 * @pd: The protection domain associated with the address handle. 2286 * @ah_attr: The attributes of the address vector. 2287 * 2288 * The address handle is used to reference a local or global destination 2289 * in all UD QP post sends. 2290 */ 2291 struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr); 2292 2293 /** 2294 * ib_init_ah_from_wc - Initializes address handle attributes from a 2295 * work completion. 2296 * @device: Device on which the received message arrived. 2297 * @port_num: Port on which the received message arrived. 2298 * @wc: Work completion associated with the received message. 2299 * @grh: References the received global route header. This parameter is 2300 * ignored unless the work completion indicates that the GRH is valid. 2301 * @ah_attr: Returned attributes that can be used when creating an address 2302 * handle for replying to the message. 2303 */ 2304 int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc, 2305 struct ib_grh *grh, struct ib_ah_attr *ah_attr); 2306 2307 /** 2308 * ib_create_ah_from_wc - Creates an address handle associated with the 2309 * sender of the specified work completion. 2310 * @pd: The protection domain associated with the address handle. 2311 * @wc: Work completion information associated with a received message. 2312 * @grh: References the received global route header. This parameter is 2313 * ignored unless the work completion indicates that the GRH is valid. 2314 * @port_num: The outbound port number to associate with the address. 2315 * 2316 * The address handle is used to reference a local or global destination 2317 * in all UD QP post sends. 2318 */ 2319 struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc, 2320 struct ib_grh *grh, u8 port_num); 2321 2322 /** 2323 * ib_modify_ah - Modifies the address vector associated with an address 2324 * handle. 2325 * @ah: The address handle to modify. 2326 * @ah_attr: The new address vector attributes to associate with the 2327 * address handle. 2328 */ 2329 int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr); 2330 2331 /** 2332 * ib_query_ah - Queries the address vector associated with an address 2333 * handle. 2334 * @ah: The address handle to query. 2335 * @ah_attr: The address vector attributes associated with the address 2336 * handle. 2337 */ 2338 int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr); 2339 2340 /** 2341 * ib_destroy_ah - Destroys an address handle. 2342 * @ah: The address handle to destroy. 2343 */ 2344 int ib_destroy_ah(struct ib_ah *ah); 2345 2346 /** 2347 * ib_create_srq - Creates a SRQ associated with the specified protection 2348 * domain. 2349 * @pd: The protection domain associated with the SRQ. 2350 * @srq_init_attr: A list of initial attributes required to create the 2351 * SRQ. If SRQ creation succeeds, then the attributes are updated to 2352 * the actual capabilities of the created SRQ. 2353 * 2354 * srq_attr->max_wr and srq_attr->max_sge are read the determine the 2355 * requested size of the SRQ, and set to the actual values allocated 2356 * on return. If ib_create_srq() succeeds, then max_wr and max_sge 2357 * will always be at least as large as the requested values. 2358 */ 2359 struct ib_srq *ib_create_srq(struct ib_pd *pd, 2360 struct ib_srq_init_attr *srq_init_attr); 2361 2362 /** 2363 * ib_modify_srq - Modifies the attributes for the specified SRQ. 2364 * @srq: The SRQ to modify. 2365 * @srq_attr: On input, specifies the SRQ attributes to modify. On output, 2366 * the current values of selected SRQ attributes are returned. 2367 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ 2368 * are being modified. 2369 * 2370 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or 2371 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when 2372 * the number of receives queued drops below the limit. 2373 */ 2374 int ib_modify_srq(struct ib_srq *srq, 2375 struct ib_srq_attr *srq_attr, 2376 enum ib_srq_attr_mask srq_attr_mask); 2377 2378 /** 2379 * ib_query_srq - Returns the attribute list and current values for the 2380 * specified SRQ. 2381 * @srq: The SRQ to query. 2382 * @srq_attr: The attributes of the specified SRQ. 2383 */ 2384 int ib_query_srq(struct ib_srq *srq, 2385 struct ib_srq_attr *srq_attr); 2386 2387 /** 2388 * ib_destroy_srq - Destroys the specified SRQ. 2389 * @srq: The SRQ to destroy. 2390 */ 2391 int ib_destroy_srq(struct ib_srq *srq); 2392 2393 /** 2394 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ. 2395 * @srq: The SRQ to post the work request on. 2396 * @recv_wr: A list of work requests to post on the receive queue. 2397 * @bad_recv_wr: On an immediate failure, this parameter will reference 2398 * the work request that failed to be posted on the QP. 2399 */ 2400 static inline int ib_post_srq_recv(struct ib_srq *srq, 2401 struct ib_recv_wr *recv_wr, 2402 struct ib_recv_wr **bad_recv_wr) 2403 { 2404 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr); 2405 } 2406 2407 /** 2408 * ib_create_qp - Creates a QP associated with the specified protection 2409 * domain. 2410 * @pd: The protection domain associated with the QP. 2411 * @qp_init_attr: A list of initial attributes required to create the 2412 * QP. If QP creation succeeds, then the attributes are updated to 2413 * the actual capabilities of the created QP. 2414 */ 2415 struct ib_qp *ib_create_qp(struct ib_pd *pd, 2416 struct ib_qp_init_attr *qp_init_attr); 2417 2418 /** 2419 * ib_modify_qp - Modifies the attributes for the specified QP and then 2420 * transitions the QP to the given state. 2421 * @qp: The QP to modify. 2422 * @qp_attr: On input, specifies the QP attributes to modify. On output, 2423 * the current values of selected QP attributes are returned. 2424 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP 2425 * are being modified. 2426 */ 2427 int ib_modify_qp(struct ib_qp *qp, 2428 struct ib_qp_attr *qp_attr, 2429 int qp_attr_mask); 2430 2431 /** 2432 * ib_query_qp - Returns the attribute list and current values for the 2433 * specified QP. 2434 * @qp: The QP to query. 2435 * @qp_attr: The attributes of the specified QP. 2436 * @qp_attr_mask: A bit-mask used to select specific attributes to query. 2437 * @qp_init_attr: Additional attributes of the selected QP. 2438 * 2439 * The qp_attr_mask may be used to limit the query to gathering only the 2440 * selected attributes. 2441 */ 2442 int ib_query_qp(struct ib_qp *qp, 2443 struct ib_qp_attr *qp_attr, 2444 int qp_attr_mask, 2445 struct ib_qp_init_attr *qp_init_attr); 2446 2447 /** 2448 * ib_destroy_qp - Destroys the specified QP. 2449 * @qp: The QP to destroy. 2450 */ 2451 int ib_destroy_qp(struct ib_qp *qp); 2452 2453 /** 2454 * ib_open_qp - Obtain a reference to an existing sharable QP. 2455 * @xrcd - XRC domain 2456 * @qp_open_attr: Attributes identifying the QP to open. 2457 * 2458 * Returns a reference to a sharable QP. 2459 */ 2460 struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd, 2461 struct ib_qp_open_attr *qp_open_attr); 2462 2463 /** 2464 * ib_close_qp - Release an external reference to a QP. 2465 * @qp: The QP handle to release 2466 * 2467 * The opened QP handle is released by the caller. The underlying 2468 * shared QP is not destroyed until all internal references are released. 2469 */ 2470 int ib_close_qp(struct ib_qp *qp); 2471 2472 /** 2473 * ib_post_send - Posts a list of work requests to the send queue of 2474 * the specified QP. 2475 * @qp: The QP to post the work request on. 2476 * @send_wr: A list of work requests to post on the send queue. 2477 * @bad_send_wr: On an immediate failure, this parameter will reference 2478 * the work request that failed to be posted on the QP. 2479 * 2480 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate 2481 * error is returned, the QP state shall not be affected, 2482 * ib_post_send() will return an immediate error after queueing any 2483 * earlier work requests in the list. 2484 */ 2485 static inline int ib_post_send(struct ib_qp *qp, 2486 struct ib_send_wr *send_wr, 2487 struct ib_send_wr **bad_send_wr) 2488 { 2489 return qp->device->post_send(qp, send_wr, bad_send_wr); 2490 } 2491 2492 /** 2493 * ib_post_recv - Posts a list of work requests to the receive queue of 2494 * the specified QP. 2495 * @qp: The QP to post the work request on. 2496 * @recv_wr: A list of work requests to post on the receive queue. 2497 * @bad_recv_wr: On an immediate failure, this parameter will reference 2498 * the work request that failed to be posted on the QP. 2499 */ 2500 static inline int ib_post_recv(struct ib_qp *qp, 2501 struct ib_recv_wr *recv_wr, 2502 struct ib_recv_wr **bad_recv_wr) 2503 { 2504 return qp->device->post_recv(qp, recv_wr, bad_recv_wr); 2505 } 2506 2507 /** 2508 * ib_create_cq - Creates a CQ on the specified device. 2509 * @device: The device on which to create the CQ. 2510 * @comp_handler: A user-specified callback that is invoked when a 2511 * completion event occurs on the CQ. 2512 * @event_handler: A user-specified callback that is invoked when an 2513 * asynchronous event not associated with a completion occurs on the CQ. 2514 * @cq_context: Context associated with the CQ returned to the user via 2515 * the associated completion and event handlers. 2516 * @cqe: The minimum size of the CQ. 2517 * @comp_vector - Completion vector used to signal completion events. 2518 * Must be >= 0 and < context->num_comp_vectors. 2519 * 2520 * Users can examine the cq structure to determine the actual CQ size. 2521 */ 2522 struct ib_cq *ib_create_cq(struct ib_device *device, 2523 ib_comp_handler comp_handler, 2524 void (*event_handler)(struct ib_event *, void *), 2525 void *cq_context, int cqe, int comp_vector); 2526 2527 /** 2528 * ib_resize_cq - Modifies the capacity of the CQ. 2529 * @cq: The CQ to resize. 2530 * @cqe: The minimum size of the CQ. 2531 * 2532 * Users can examine the cq structure to determine the actual CQ size. 2533 */ 2534 int ib_resize_cq(struct ib_cq *cq, int cqe); 2535 2536 /** 2537 * ib_modify_cq - Modifies the attributes for the specified CQ and then 2538 * transitions the CQ to the given state. 2539 * @cq: The CQ to modify. 2540 * @cq_attr: specifies the CQ attributes to modify. 2541 * @cq_attr_mask: A bit-mask used to specify which attributes of the CQ 2542 * are being modified. 2543 */ 2544 int ib_modify_cq(struct ib_cq *cq, 2545 struct ib_cq_attr *cq_attr, 2546 int cq_attr_mask); 2547 2548 /** 2549 * ib_destroy_cq - Destroys the specified CQ. 2550 * @cq: The CQ to destroy. 2551 */ 2552 int ib_destroy_cq(struct ib_cq *cq); 2553 2554 /** 2555 * ib_poll_cq - poll a CQ for completion(s) 2556 * @cq:the CQ being polled 2557 * @num_entries:maximum number of completions to return 2558 * @wc:array of at least @num_entries &struct ib_wc where completions 2559 * will be returned 2560 * 2561 * Poll a CQ for (possibly multiple) completions. If the return value 2562 * is < 0, an error occurred. If the return value is >= 0, it is the 2563 * number of completions returned. If the return value is 2564 * non-negative and < num_entries, then the CQ was emptied. 2565 */ 2566 static inline int ib_poll_cq(struct ib_cq *cq, int num_entries, 2567 struct ib_wc *wc) 2568 { 2569 return cq->device->poll_cq(cq, num_entries, wc); 2570 } 2571 2572 /** 2573 * ib_peek_cq - Returns the number of unreaped completions currently 2574 * on the specified CQ. 2575 * @cq: The CQ to peek. 2576 * @wc_cnt: A minimum number of unreaped completions to check for. 2577 * 2578 * If the number of unreaped completions is greater than or equal to wc_cnt, 2579 * this function returns wc_cnt, otherwise, it returns the actual number of 2580 * unreaped completions. 2581 */ 2582 int ib_peek_cq(struct ib_cq *cq, int wc_cnt); 2583 2584 /** 2585 * ib_req_notify_cq - Request completion notification on a CQ. 2586 * @cq: The CQ to generate an event for. 2587 * @flags: 2588 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP 2589 * to request an event on the next solicited event or next work 2590 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS 2591 * may also be |ed in to request a hint about missed events, as 2592 * described below. 2593 * 2594 * Return Value: 2595 * < 0 means an error occurred while requesting notification 2596 * == 0 means notification was requested successfully, and if 2597 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events 2598 * were missed and it is safe to wait for another event. In 2599 * this case is it guaranteed that any work completions added 2600 * to the CQ since the last CQ poll will trigger a completion 2601 * notification event. 2602 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed 2603 * in. It means that the consumer must poll the CQ again to 2604 * make sure it is empty to avoid missing an event because of a 2605 * race between requesting notification and an entry being 2606 * added to the CQ. This return value means it is possible 2607 * (but not guaranteed) that a work completion has been added 2608 * to the CQ since the last poll without triggering a 2609 * completion notification event. 2610 */ 2611 static inline int ib_req_notify_cq(struct ib_cq *cq, 2612 enum ib_cq_notify_flags flags) 2613 { 2614 return cq->device->req_notify_cq(cq, flags); 2615 } 2616 2617 /** 2618 * ib_req_ncomp_notif - Request completion notification when there are 2619 * at least the specified number of unreaped completions on the CQ. 2620 * @cq: The CQ to generate an event for. 2621 * @wc_cnt: The number of unreaped completions that should be on the 2622 * CQ before an event is generated. 2623 */ 2624 static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt) 2625 { 2626 return cq->device->req_ncomp_notif ? 2627 cq->device->req_ncomp_notif(cq, wc_cnt) : 2628 -ENOSYS; 2629 } 2630 2631 /** 2632 * ib_get_dma_mr - Returns a memory region for system memory that is 2633 * usable for DMA. 2634 * @pd: The protection domain associated with the memory region. 2635 * @mr_access_flags: Specifies the memory access rights. 2636 * 2637 * Note that the ib_dma_*() functions defined below must be used 2638 * to create/destroy addresses used with the Lkey or Rkey returned 2639 * by ib_get_dma_mr(). 2640 */ 2641 struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags); 2642 2643 /** 2644 * ib_dma_mapping_error - check a DMA addr for error 2645 * @dev: The device for which the dma_addr was created 2646 * @dma_addr: The DMA address to check 2647 */ 2648 static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr) 2649 { 2650 if (dev->dma_ops) 2651 return dev->dma_ops->mapping_error(dev, dma_addr); 2652 return dma_mapping_error(dev->dma_device, dma_addr); 2653 } 2654 2655 /** 2656 * ib_dma_map_single - Map a kernel virtual address to DMA address 2657 * @dev: The device for which the dma_addr is to be created 2658 * @cpu_addr: The kernel virtual address 2659 * @size: The size of the region in bytes 2660 * @direction: The direction of the DMA 2661 */ 2662 static inline u64 ib_dma_map_single(struct ib_device *dev, 2663 void *cpu_addr, size_t size, 2664 enum dma_data_direction direction) 2665 { 2666 if (dev->dma_ops) 2667 return dev->dma_ops->map_single(dev, cpu_addr, size, direction); 2668 return dma_map_single(dev->dma_device, cpu_addr, size, direction); 2669 } 2670 2671 /** 2672 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single() 2673 * @dev: The device for which the DMA address was created 2674 * @addr: The DMA address 2675 * @size: The size of the region in bytes 2676 * @direction: The direction of the DMA 2677 */ 2678 static inline void ib_dma_unmap_single(struct ib_device *dev, 2679 u64 addr, size_t size, 2680 enum dma_data_direction direction) 2681 { 2682 if (dev->dma_ops) 2683 dev->dma_ops->unmap_single(dev, addr, size, direction); 2684 else 2685 dma_unmap_single(dev->dma_device, addr, size, direction); 2686 } 2687 2688 static inline u64 ib_dma_map_single_attrs(struct ib_device *dev, 2689 void *cpu_addr, size_t size, 2690 enum dma_data_direction direction, 2691 struct dma_attrs *attrs) 2692 { 2693 return dma_map_single_attrs(dev->dma_device, cpu_addr, size, 2694 direction, attrs); 2695 } 2696 2697 static inline void ib_dma_unmap_single_attrs(struct ib_device *dev, 2698 u64 addr, size_t size, 2699 enum dma_data_direction direction, 2700 struct dma_attrs *attrs) 2701 { 2702 return dma_unmap_single_attrs(dev->dma_device, addr, size, 2703 direction, attrs); 2704 } 2705 2706 /** 2707 * ib_dma_map_page - Map a physical page to DMA address 2708 * @dev: The device for which the dma_addr is to be created 2709 * @page: The page to be mapped 2710 * @offset: The offset within the page 2711 * @size: The size of the region in bytes 2712 * @direction: The direction of the DMA 2713 */ 2714 static inline u64 ib_dma_map_page(struct ib_device *dev, 2715 struct page *page, 2716 unsigned long offset, 2717 size_t size, 2718 enum dma_data_direction direction) 2719 { 2720 if (dev->dma_ops) 2721 return dev->dma_ops->map_page(dev, page, offset, size, direction); 2722 return dma_map_page(dev->dma_device, page, offset, size, direction); 2723 } 2724 2725 /** 2726 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page() 2727 * @dev: The device for which the DMA address was created 2728 * @addr: The DMA address 2729 * @size: The size of the region in bytes 2730 * @direction: The direction of the DMA 2731 */ 2732 static inline void ib_dma_unmap_page(struct ib_device *dev, 2733 u64 addr, size_t size, 2734 enum dma_data_direction direction) 2735 { 2736 if (dev->dma_ops) 2737 dev->dma_ops->unmap_page(dev, addr, size, direction); 2738 else 2739 dma_unmap_page(dev->dma_device, addr, size, direction); 2740 } 2741 2742 /** 2743 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses 2744 * @dev: The device for which the DMA addresses are to be created 2745 * @sg: The array of scatter/gather entries 2746 * @nents: The number of scatter/gather entries 2747 * @direction: The direction of the DMA 2748 */ 2749 static inline int ib_dma_map_sg(struct ib_device *dev, 2750 struct scatterlist *sg, int nents, 2751 enum dma_data_direction direction) 2752 { 2753 if (dev->dma_ops) 2754 return dev->dma_ops->map_sg(dev, sg, nents, direction); 2755 return dma_map_sg(dev->dma_device, sg, nents, direction); 2756 } 2757 2758 /** 2759 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses 2760 * @dev: The device for which the DMA addresses were created 2761 * @sg: The array of scatter/gather entries 2762 * @nents: The number of scatter/gather entries 2763 * @direction: The direction of the DMA 2764 */ 2765 static inline void ib_dma_unmap_sg(struct ib_device *dev, 2766 struct scatterlist *sg, int nents, 2767 enum dma_data_direction direction) 2768 { 2769 if (dev->dma_ops) 2770 dev->dma_ops->unmap_sg(dev, sg, nents, direction); 2771 else 2772 dma_unmap_sg(dev->dma_device, sg, nents, direction); 2773 } 2774 2775 static inline int ib_dma_map_sg_attrs(struct ib_device *dev, 2776 struct scatterlist *sg, int nents, 2777 enum dma_data_direction direction, 2778 struct dma_attrs *attrs) 2779 { 2780 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs); 2781 } 2782 2783 static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev, 2784 struct scatterlist *sg, int nents, 2785 enum dma_data_direction direction, 2786 struct dma_attrs *attrs) 2787 { 2788 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs); 2789 } 2790 /** 2791 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry 2792 * @dev: The device for which the DMA addresses were created 2793 * @sg: The scatter/gather entry 2794 */ 2795 static inline u64 ib_sg_dma_address(struct ib_device *dev, 2796 struct scatterlist *sg) 2797 { 2798 if (dev->dma_ops) 2799 return dev->dma_ops->dma_address(dev, sg); 2800 return sg_dma_address(sg); 2801 } 2802 2803 /** 2804 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry 2805 * @dev: The device for which the DMA addresses were created 2806 * @sg: The scatter/gather entry 2807 */ 2808 static inline unsigned int ib_sg_dma_len(struct ib_device *dev, 2809 struct scatterlist *sg) 2810 { 2811 if (dev->dma_ops) 2812 return dev->dma_ops->dma_len(dev, sg); 2813 return sg_dma_len(sg); 2814 } 2815 2816 /** 2817 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU 2818 * @dev: The device for which the DMA address was created 2819 * @addr: The DMA address 2820 * @size: The size of the region in bytes 2821 * @dir: The direction of the DMA 2822 */ 2823 static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev, 2824 u64 addr, 2825 size_t size, 2826 enum dma_data_direction dir) 2827 { 2828 if (dev->dma_ops) 2829 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir); 2830 else 2831 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir); 2832 } 2833 2834 /** 2835 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device 2836 * @dev: The device for which the DMA address was created 2837 * @addr: The DMA address 2838 * @size: The size of the region in bytes 2839 * @dir: The direction of the DMA 2840 */ 2841 static inline void ib_dma_sync_single_for_device(struct ib_device *dev, 2842 u64 addr, 2843 size_t size, 2844 enum dma_data_direction dir) 2845 { 2846 if (dev->dma_ops) 2847 dev->dma_ops->sync_single_for_device(dev, addr, size, dir); 2848 else 2849 dma_sync_single_for_device(dev->dma_device, addr, size, dir); 2850 } 2851 2852 /** 2853 * ib_dma_alloc_coherent - Allocate memory and map it for DMA 2854 * @dev: The device for which the DMA address is requested 2855 * @size: The size of the region to allocate in bytes 2856 * @dma_handle: A pointer for returning the DMA address of the region 2857 * @flag: memory allocator flags 2858 */ 2859 static inline void *ib_dma_alloc_coherent(struct ib_device *dev, 2860 size_t size, 2861 u64 *dma_handle, 2862 gfp_t flag) 2863 { 2864 if (dev->dma_ops) 2865 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag); 2866 else { 2867 dma_addr_t handle; 2868 void *ret; 2869 2870 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag); 2871 *dma_handle = handle; 2872 return ret; 2873 } 2874 } 2875 2876 /** 2877 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent() 2878 * @dev: The device for which the DMA addresses were allocated 2879 * @size: The size of the region 2880 * @cpu_addr: the address returned by ib_dma_alloc_coherent() 2881 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent() 2882 */ 2883 static inline void ib_dma_free_coherent(struct ib_device *dev, 2884 size_t size, void *cpu_addr, 2885 u64 dma_handle) 2886 { 2887 if (dev->dma_ops) 2888 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle); 2889 else 2890 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle); 2891 } 2892 2893 /** 2894 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use 2895 * by an HCA. 2896 * @pd: The protection domain associated assigned to the registered region. 2897 * @phys_buf_array: Specifies a list of physical buffers to use in the 2898 * memory region. 2899 * @num_phys_buf: Specifies the size of the phys_buf_array. 2900 * @mr_access_flags: Specifies the memory access rights. 2901 * @iova_start: The offset of the region's starting I/O virtual address. 2902 */ 2903 struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd, 2904 struct ib_phys_buf *phys_buf_array, 2905 int num_phys_buf, 2906 int mr_access_flags, 2907 u64 *iova_start); 2908 2909 /** 2910 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region. 2911 * Conceptually, this call performs the functions deregister memory region 2912 * followed by register physical memory region. Where possible, 2913 * resources are reused instead of deallocated and reallocated. 2914 * @mr: The memory region to modify. 2915 * @mr_rereg_mask: A bit-mask used to indicate which of the following 2916 * properties of the memory region are being modified. 2917 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies 2918 * the new protection domain to associated with the memory region, 2919 * otherwise, this parameter is ignored. 2920 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this 2921 * field specifies a list of physical buffers to use in the new 2922 * translation, otherwise, this parameter is ignored. 2923 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this 2924 * field specifies the size of the phys_buf_array, otherwise, this 2925 * parameter is ignored. 2926 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this 2927 * field specifies the new memory access rights, otherwise, this 2928 * parameter is ignored. 2929 * @iova_start: The offset of the region's starting I/O virtual address. 2930 */ 2931 int ib_rereg_phys_mr(struct ib_mr *mr, 2932 int mr_rereg_mask, 2933 struct ib_pd *pd, 2934 struct ib_phys_buf *phys_buf_array, 2935 int num_phys_buf, 2936 int mr_access_flags, 2937 u64 *iova_start); 2938 2939 /** 2940 * ib_query_mr - Retrieves information about a specific memory region. 2941 * @mr: The memory region to retrieve information about. 2942 * @mr_attr: The attributes of the specified memory region. 2943 */ 2944 int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr); 2945 2946 /** 2947 * ib_dereg_mr - Deregisters a memory region and removes it from the 2948 * HCA translation table. 2949 * @mr: The memory region to deregister. 2950 * 2951 * This function can fail, if the memory region has memory windows bound to it. 2952 */ 2953 int ib_dereg_mr(struct ib_mr *mr); 2954 2955 2956 /** 2957 * ib_create_mr - Allocates a memory region that may be used for 2958 * signature handover operations. 2959 * @pd: The protection domain associated with the region. 2960 * @mr_init_attr: memory region init attributes. 2961 */ 2962 struct ib_mr *ib_create_mr(struct ib_pd *pd, 2963 struct ib_mr_init_attr *mr_init_attr); 2964 2965 /** 2966 * ib_destroy_mr - Destroys a memory region that was created using 2967 * ib_create_mr and removes it from HW translation tables. 2968 * @mr: The memory region to destroy. 2969 * 2970 * This function can fail, if the memory region has memory windows bound to it. 2971 */ 2972 int ib_destroy_mr(struct ib_mr *mr); 2973 2974 /** 2975 * ib_alloc_fast_reg_mr - Allocates memory region usable with the 2976 * IB_WR_FAST_REG_MR send work request. 2977 * @pd: The protection domain associated with the region. 2978 * @max_page_list_len: requested max physical buffer list length to be 2979 * used with fast register work requests for this MR. 2980 */ 2981 struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len); 2982 2983 /** 2984 * ib_alloc_fast_reg_page_list - Allocates a page list array 2985 * @device - ib device pointer. 2986 * @page_list_len - size of the page list array to be allocated. 2987 * 2988 * This allocates and returns a struct ib_fast_reg_page_list * and a 2989 * page_list array that is at least page_list_len in size. The actual 2990 * size is returned in max_page_list_len. The caller is responsible 2991 * for initializing the contents of the page_list array before posting 2992 * a send work request with the IB_WC_FAST_REG_MR opcode. 2993 * 2994 * The page_list array entries must be translated using one of the 2995 * ib_dma_*() functions just like the addresses passed to 2996 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct 2997 * ib_fast_reg_page_list must not be modified by the caller until the 2998 * IB_WC_FAST_REG_MR work request completes. 2999 */ 3000 struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list( 3001 struct ib_device *device, int page_list_len); 3002 3003 /** 3004 * ib_free_fast_reg_page_list - Deallocates a previously allocated 3005 * page list array. 3006 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated. 3007 */ 3008 void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list); 3009 3010 /** 3011 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR 3012 * R_Key and L_Key. 3013 * @mr - struct ib_mr pointer to be updated. 3014 * @newkey - new key to be used. 3015 */ 3016 static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey) 3017 { 3018 mr->lkey = (mr->lkey & 0xffffff00) | newkey; 3019 mr->rkey = (mr->rkey & 0xffffff00) | newkey; 3020 } 3021 3022 /** 3023 * ib_inc_rkey - increments the key portion of the given rkey. Can be used 3024 * for calculating a new rkey for type 2 memory windows. 3025 * @rkey - the rkey to increment. 3026 */ 3027 static inline u32 ib_inc_rkey(u32 rkey) 3028 { 3029 const u32 mask = 0x000000ff; 3030 return ((rkey + 1) & mask) | (rkey & ~mask); 3031 } 3032 3033 /** 3034 * ib_alloc_mw - Allocates a memory window. 3035 * @pd: The protection domain associated with the memory window. 3036 * @type: The type of the memory window (1 or 2). 3037 */ 3038 struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type); 3039 3040 /** 3041 * ib_bind_mw - Posts a work request to the send queue of the specified 3042 * QP, which binds the memory window to the given address range and 3043 * remote access attributes. 3044 * @qp: QP to post the bind work request on. 3045 * @mw: The memory window to bind. 3046 * @mw_bind: Specifies information about the memory window, including 3047 * its address range, remote access rights, and associated memory region. 3048 * 3049 * If there is no immediate error, the function will update the rkey member 3050 * of the mw parameter to its new value. The bind operation can still fail 3051 * asynchronously. 3052 */ 3053 static inline int ib_bind_mw(struct ib_qp *qp, 3054 struct ib_mw *mw, 3055 struct ib_mw_bind *mw_bind) 3056 { 3057 /* XXX reference counting in corresponding MR? */ 3058 return mw->device->bind_mw ? 3059 mw->device->bind_mw(qp, mw, mw_bind) : 3060 -ENOSYS; 3061 } 3062 3063 /** 3064 * ib_dealloc_mw - Deallocates a memory window. 3065 * @mw: The memory window to deallocate. 3066 */ 3067 int ib_dealloc_mw(struct ib_mw *mw); 3068 3069 /** 3070 * ib_alloc_fmr - Allocates a unmapped fast memory region. 3071 * @pd: The protection domain associated with the unmapped region. 3072 * @mr_access_flags: Specifies the memory access rights. 3073 * @fmr_attr: Attributes of the unmapped region. 3074 * 3075 * A fast memory region must be mapped before it can be used as part of 3076 * a work request. 3077 */ 3078 struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd, 3079 int mr_access_flags, 3080 struct ib_fmr_attr *fmr_attr); 3081 3082 /** 3083 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region. 3084 * @fmr: The fast memory region to associate with the pages. 3085 * @page_list: An array of physical pages to map to the fast memory region. 3086 * @list_len: The number of pages in page_list. 3087 * @iova: The I/O virtual address to use with the mapped region. 3088 */ 3089 static inline int ib_map_phys_fmr(struct ib_fmr *fmr, 3090 u64 *page_list, int list_len, 3091 u64 iova) 3092 { 3093 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova); 3094 } 3095 3096 /** 3097 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions. 3098 * @fmr_list: A linked list of fast memory regions to unmap. 3099 */ 3100 int ib_unmap_fmr(struct list_head *fmr_list); 3101 3102 /** 3103 * ib_dealloc_fmr - Deallocates a fast memory region. 3104 * @fmr: The fast memory region to deallocate. 3105 */ 3106 int ib_dealloc_fmr(struct ib_fmr *fmr); 3107 3108 /** 3109 * ib_attach_mcast - Attaches the specified QP to a multicast group. 3110 * @qp: QP to attach to the multicast group. The QP must be type 3111 * IB_QPT_UD. 3112 * @gid: Multicast group GID. 3113 * @lid: Multicast group LID in host byte order. 3114 * 3115 * In order to send and receive multicast packets, subnet 3116 * administration must have created the multicast group and configured 3117 * the fabric appropriately. The port associated with the specified 3118 * QP must also be a member of the multicast group. 3119 */ 3120 int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); 3121 3122 /** 3123 * ib_detach_mcast - Detaches the specified QP from a multicast group. 3124 * @qp: QP to detach from the multicast group. 3125 * @gid: Multicast group GID. 3126 * @lid: Multicast group LID in host byte order. 3127 */ 3128 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); 3129 3130 /** 3131 * ib_alloc_xrcd - Allocates an XRC domain. 3132 * @device: The device on which to allocate the XRC domain. 3133 */ 3134 struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device); 3135 3136 /** 3137 * ib_dealloc_xrcd - Deallocates an XRC domain. 3138 * @xrcd: The XRC domain to deallocate. 3139 */ 3140 int ib_dealloc_xrcd(struct ib_xrcd *xrcd); 3141 3142 struct ib_flow *ib_create_flow(struct ib_qp *qp, 3143 struct ib_flow_attr *flow_attr, int domain); 3144 int ib_destroy_flow(struct ib_flow *flow_id); 3145 3146 struct ib_dct *ib_create_dct(struct ib_pd *pd, struct ib_dct_init_attr *attr, 3147 struct ib_udata *udata); 3148 int ib_destroy_dct(struct ib_dct *dct); 3149 int ib_query_dct(struct ib_dct *dct, struct ib_dct_attr *attr); 3150 3151 int ib_query_values(struct ib_device *device, 3152 int q_values, struct ib_device_values *values); 3153 3154 static inline void ib_active_speed_enum_to_rate(u8 active_speed, 3155 int *rate, 3156 char **speed) 3157 { 3158 switch (active_speed) { 3159 case IB_SPEED_DDR: 3160 *speed = " DDR"; 3161 *rate = 50; 3162 break; 3163 case IB_SPEED_QDR: 3164 *speed = " QDR"; 3165 *rate = 100; 3166 break; 3167 case IB_SPEED_FDR10: 3168 *speed = " FDR10"; 3169 *rate = 100; 3170 break; 3171 case IB_SPEED_FDR: 3172 *speed = " FDR"; 3173 *rate = 140; 3174 break; 3175 case IB_SPEED_EDR: 3176 *speed = " EDR"; 3177 *rate = 250; 3178 break; 3179 case IB_SPEED_SDR: 3180 default: /* default to SDR for invalid rates */ 3181 *rate = 25; 3182 break; 3183 } 3184 3185 } 3186 3187 static inline int ib_check_mr_access(int flags) 3188 { 3189 /* 3190 * Local write permission is required if remote write or 3191 * remote atomic permission is also requested. 3192 */ 3193 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) && 3194 !(flags & IB_ACCESS_LOCAL_WRITE)) 3195 return -EINVAL; 3196 3197 return 0; 3198 } 3199 3200 /** 3201 * ib_check_mr_status: lightweight check of MR status. 3202 * This routine may provide status checks on a selected 3203 * ib_mr. first use is for signature status check. 3204 * 3205 * @mr: A memory region. 3206 * @check_mask: Bitmask of which checks to perform from 3207 * ib_mr_status_check enumeration. 3208 * @mr_status: The container of relevant status checks. 3209 * failed checks will be indicated in the status bitmask 3210 * and the relevant info shall be in the error item. 3211 */ 3212 int ib_check_mr_status(struct ib_mr *mr, u32 check_mask, 3213 struct ib_mr_status *mr_status); 3214 3215 #endif /* IB_VERBS_H */ 3216