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 52#include <asm/uaccess.h> 53#include <linux/rbtree.h> 54#include <linux/mutex.h> 55 56extern struct workqueue_struct *ib_wq; 57 58union ib_gid { 59 u8 raw[16]; 60 struct { 61 __be64 subnet_prefix; 62 __be64 interface_id; 63 } global; 64}; 65 66enum 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}; 73 74enum rdma_transport_type { 75 RDMA_TRANSPORT_IB, 76 RDMA_TRANSPORT_IWARP 77}; 78 79enum rdma_transport_type 80rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__; 81 82enum rdma_link_layer { 83 IB_LINK_LAYER_UNSPECIFIED, 84 IB_LINK_LAYER_INFINIBAND, 85 IB_LINK_LAYER_ETHERNET, 86}; 87 88enum ib_device_cap_flags { 89 IB_DEVICE_RESIZE_MAX_WR = 1, 90 IB_DEVICE_BAD_PKEY_CNTR = (1<<1), 91 IB_DEVICE_BAD_QKEY_CNTR = (1<<2), 92 IB_DEVICE_RAW_MULTI = (1<<3), 93 IB_DEVICE_AUTO_PATH_MIG = (1<<4), 94 IB_DEVICE_CHANGE_PHY_PORT = (1<<5), 95 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6), 96 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7), 97 IB_DEVICE_SHUTDOWN_PORT = (1<<8), 98 IB_DEVICE_INIT_TYPE = (1<<9), 99 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10), 100 IB_DEVICE_SYS_IMAGE_GUID = (1<<11), 101 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12), 102 IB_DEVICE_SRQ_RESIZE = (1<<13), 103 IB_DEVICE_N_NOTIFY_CQ = (1<<14), 104 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15), 105 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */ 106 IB_DEVICE_MEM_WINDOW = (1<<17), 107 /* 108 * Devices should set IB_DEVICE_UD_IP_SUM if they support 109 * insertion of UDP and TCP checksum on outgoing UD IPoIB 110 * messages and can verify the validity of checksum for 111 * incoming messages. Setting this flag implies that the 112 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode. 113 */ 114 IB_DEVICE_UD_IP_CSUM = (1<<18), 115 IB_DEVICE_UD_TSO = (1<<19), 116 IB_DEVICE_XRC = (1<<20), 117 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21), 118 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22), 119 IB_DEVICE_MR_ALLOCATE = (1<<23), 120 IB_DEVICE_SHARED_MR = (1<<24), 121 IB_DEVICE_QPG = (1<<25), 122 IB_DEVICE_UD_RSS = (1<<26), 123 IB_DEVICE_UD_TSS = (1<<27) 124}; 125 126enum ib_atomic_cap { 127 IB_ATOMIC_NONE, 128 IB_ATOMIC_HCA, 129 IB_ATOMIC_GLOB 130}; 131 132struct ib_device_attr { 133 u64 fw_ver; 134 __be64 sys_image_guid; 135 u64 max_mr_size; 136 u64 page_size_cap; 137 u32 vendor_id; 138 u32 vendor_part_id; 139 u32 hw_ver; 140 int max_qp; 141 int max_qp_wr; 142 int device_cap_flags; 143 int max_sge; 144 int max_sge_rd; 145 int max_cq; 146 int max_cqe; 147 int max_mr; 148 int max_pd; 149 int max_qp_rd_atom; 150 int max_ee_rd_atom; 151 int max_res_rd_atom; 152 int max_qp_init_rd_atom; 153 int max_ee_init_rd_atom; 154 enum ib_atomic_cap atomic_cap; 155 enum ib_atomic_cap masked_atomic_cap; 156 int max_ee; 157 int max_rdd; 158 int max_mw; 159 int max_raw_ipv6_qp; 160 int max_raw_ethy_qp; 161 int max_mcast_grp; 162 int max_mcast_qp_attach; 163 int max_total_mcast_qp_attach; 164 int max_ah; 165 int max_fmr; 166 int max_map_per_fmr; 167 int max_srq; 168 int max_srq_wr; 169 int max_srq_sge; 170 unsigned int max_fast_reg_page_list_len; 171 int max_rss_tbl_sz; 172 u16 max_pkeys; 173 u8 local_ca_ack_delay; 174}; 175 176enum ib_mtu { 177 IB_MTU_256 = 1, 178 IB_MTU_512 = 2, 179 IB_MTU_1024 = 3, 180 IB_MTU_2048 = 4, 181 IB_MTU_4096 = 5 182}; 183 184static inline int ib_mtu_enum_to_int(enum ib_mtu mtu) 185{ 186 switch (mtu) { 187 case IB_MTU_256: return 256; 188 case IB_MTU_512: return 512; 189 case IB_MTU_1024: return 1024; 190 case IB_MTU_2048: return 2048; 191 case IB_MTU_4096: return 4096; 192 default: return -1; 193 } 194} 195 196enum ib_port_state { 197 IB_PORT_NOP = 0, 198 IB_PORT_DOWN = 1, 199 IB_PORT_INIT = 2, 200 IB_PORT_ARMED = 3, 201 IB_PORT_ACTIVE = 4, 202 IB_PORT_ACTIVE_DEFER = 5 203}; 204 205enum ib_port_cap_flags { 206 IB_PORT_SM = 1 << 1, 207 IB_PORT_NOTICE_SUP = 1 << 2, 208 IB_PORT_TRAP_SUP = 1 << 3, 209 IB_PORT_OPT_IPD_SUP = 1 << 4, 210 IB_PORT_AUTO_MIGR_SUP = 1 << 5, 211 IB_PORT_SL_MAP_SUP = 1 << 6, 212 IB_PORT_MKEY_NVRAM = 1 << 7, 213 IB_PORT_PKEY_NVRAM = 1 << 8, 214 IB_PORT_LED_INFO_SUP = 1 << 9, 215 IB_PORT_SM_DISABLED = 1 << 10, 216 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11, 217 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12, 218 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14, 219 IB_PORT_CM_SUP = 1 << 16, 220 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17, 221 IB_PORT_REINIT_SUP = 1 << 18, 222 IB_PORT_DEVICE_MGMT_SUP = 1 << 19, 223 IB_PORT_VENDOR_CLASS_SUP = 1 << 20, 224 IB_PORT_DR_NOTICE_SUP = 1 << 21, 225 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22, 226 IB_PORT_BOOT_MGMT_SUP = 1 << 23, 227 IB_PORT_LINK_LATENCY_SUP = 1 << 24, 228 IB_PORT_CLIENT_REG_SUP = 1 << 25 229}; 230 231enum ib_port_width { 232 IB_WIDTH_1X = 1, 233 IB_WIDTH_4X = 2, 234 IB_WIDTH_8X = 4, 235 IB_WIDTH_12X = 8 236}; 237 238static inline int ib_width_enum_to_int(enum ib_port_width width) 239{ 240 switch (width) { 241 case IB_WIDTH_1X: return 1; 242 case IB_WIDTH_4X: return 4; 243 case IB_WIDTH_8X: return 8; 244 case IB_WIDTH_12X: return 12; 245 default: return -1; 246 } 247} 248 249enum ib_port_speed { 250 IB_SPEED_SDR = 1, 251 IB_SPEED_DDR = 2, 252 IB_SPEED_QDR = 4, 253 IB_SPEED_FDR10 = 8, 254 IB_SPEED_FDR = 16, 255 IB_SPEED_EDR = 32 256}; 257 258struct ib_protocol_stats { 259 /* TBD... */ 260}; 261 262struct iw_protocol_stats { 263 u64 ipInReceives; 264 u64 ipInHdrErrors; 265 u64 ipInTooBigErrors; 266 u64 ipInNoRoutes; 267 u64 ipInAddrErrors; 268 u64 ipInUnknownProtos; 269 u64 ipInTruncatedPkts; 270 u64 ipInDiscards; 271 u64 ipInDelivers; 272 u64 ipOutForwDatagrams; 273 u64 ipOutRequests; 274 u64 ipOutDiscards; 275 u64 ipOutNoRoutes; 276 u64 ipReasmTimeout; 277 u64 ipReasmReqds; 278 u64 ipReasmOKs; 279 u64 ipReasmFails; 280 u64 ipFragOKs; 281 u64 ipFragFails; 282 u64 ipFragCreates; 283 u64 ipInMcastPkts; 284 u64 ipOutMcastPkts; 285 u64 ipInBcastPkts; 286 u64 ipOutBcastPkts; 287 288 u64 tcpRtoAlgorithm; 289 u64 tcpRtoMin; 290 u64 tcpRtoMax; 291 u64 tcpMaxConn; 292 u64 tcpActiveOpens; 293 u64 tcpPassiveOpens; 294 u64 tcpAttemptFails; 295 u64 tcpEstabResets; 296 u64 tcpCurrEstab; 297 u64 tcpInSegs; 298 u64 tcpOutSegs; 299 u64 tcpRetransSegs; 300 u64 tcpInErrs; 301 u64 tcpOutRsts; 302}; 303 304union rdma_protocol_stats { 305 struct ib_protocol_stats ib; 306 struct iw_protocol_stats iw; 307}; 308 309/* Define bits for the various functionality this port needs to be supported by 310 * the core. 311 */ 312/* Management 0x00000FFF */ 313#define RDMA_CORE_CAP_IB_MAD 0x00000001 314#define RDMA_CORE_CAP_IB_SMI 0x00000002 315#define RDMA_CORE_CAP_IB_CM 0x00000004 316#define RDMA_CORE_CAP_IW_CM 0x00000008 317#define RDMA_CORE_CAP_IB_SA 0x00000010 318#define RDMA_CORE_CAP_OPA_MAD 0x00000020 319 320/* Address format 0x000FF000 */ 321#define RDMA_CORE_CAP_AF_IB 0x00001000 322#define RDMA_CORE_CAP_ETH_AH 0x00002000 323#define RDMA_CORE_CAP_OPA_AH 0x00004000 324 325/* Protocol 0xFFF00000 */ 326#define RDMA_CORE_CAP_PROT_IB 0x00100000 327#define RDMA_CORE_CAP_PROT_ROCE 0x00200000 328#define RDMA_CORE_CAP_PROT_IWARP 0x00400000 329#define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000 330#define RDMA_CORE_CAP_PROT_RAW_PACKET 0x01000000 331#define RDMA_CORE_CAP_PROT_USNIC 0x02000000 332 333#define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \ 334 | RDMA_CORE_CAP_IB_MAD \ 335 | RDMA_CORE_CAP_IB_SMI \ 336 | RDMA_CORE_CAP_IB_CM \ 337 | RDMA_CORE_CAP_IB_SA \ 338 | RDMA_CORE_CAP_AF_IB) 339#define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \ 340 | RDMA_CORE_CAP_IB_MAD \ 341 | RDMA_CORE_CAP_IB_CM \ 342 | RDMA_CORE_CAP_AF_IB \ 343 | RDMA_CORE_CAP_ETH_AH) 344#define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \ 345 (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \ 346 | RDMA_CORE_CAP_IB_MAD \ 347 | RDMA_CORE_CAP_IB_CM \ 348 | RDMA_CORE_CAP_AF_IB \ 349 | RDMA_CORE_CAP_ETH_AH) 350#define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \ 351 | RDMA_CORE_CAP_IW_CM) 352#define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \ 353 | RDMA_CORE_CAP_OPA_MAD) 354 355#define RDMA_CORE_PORT_RAW_PACKET (RDMA_CORE_CAP_PROT_RAW_PACKET) 356 357#define RDMA_CORE_PORT_USNIC (RDMA_CORE_CAP_PROT_USNIC) 358 359struct ib_port_attr { 360 enum ib_port_state state; 361 enum ib_mtu max_mtu; 362 enum ib_mtu active_mtu; 363 int gid_tbl_len; 364 u32 port_cap_flags; 365 u32 max_msg_sz; 366 u32 bad_pkey_cntr; 367 u32 qkey_viol_cntr; 368 u16 pkey_tbl_len; 369 u16 lid; 370 u16 sm_lid; 371 u8 lmc; 372 u8 max_vl_num; 373 u8 sm_sl; 374 u8 subnet_timeout; 375 u8 init_type_reply; 376 u8 active_width; 377 u8 active_speed; 378 u8 phys_state; 379 enum rdma_link_layer link_layer; 380}; 381 382enum ib_device_modify_flags { 383 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0, 384 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1 385}; 386 387struct ib_device_modify { 388 u64 sys_image_guid; 389 char node_desc[64]; 390}; 391 392enum ib_port_modify_flags { 393 IB_PORT_SHUTDOWN = 1, 394 IB_PORT_INIT_TYPE = (1<<2), 395 IB_PORT_RESET_QKEY_CNTR = (1<<3) 396}; 397 398struct ib_port_modify { 399 u32 set_port_cap_mask; 400 u32 clr_port_cap_mask; 401 u8 init_type; 402}; 403 404enum ib_event_type { 405 IB_EVENT_CQ_ERR, 406 IB_EVENT_QP_FATAL, 407 IB_EVENT_QP_REQ_ERR, 408 IB_EVENT_QP_ACCESS_ERR, 409 IB_EVENT_COMM_EST, 410 IB_EVENT_SQ_DRAINED, 411 IB_EVENT_PATH_MIG, 412 IB_EVENT_PATH_MIG_ERR, 413 IB_EVENT_DEVICE_FATAL, 414 IB_EVENT_PORT_ACTIVE, 415 IB_EVENT_PORT_ERR, 416 IB_EVENT_LID_CHANGE, 417 IB_EVENT_PKEY_CHANGE, 418 IB_EVENT_SM_CHANGE, 419 IB_EVENT_SRQ_ERR, 420 IB_EVENT_SRQ_LIMIT_REACHED, 421 IB_EVENT_QP_LAST_WQE_REACHED, 422 IB_EVENT_CLIENT_REREGISTER, 423 IB_EVENT_GID_CHANGE, 424}; 425 426enum ib_event_flags { 427 IB_XRC_QP_EVENT_FLAG = 0x80000000, 428}; 429 430struct ib_event { 431 struct ib_device *device; 432 union { 433 struct ib_cq *cq; 434 struct ib_qp *qp; 435 struct ib_srq *srq; 436 u8 port_num; 437 u32 xrc_qp_num; 438 } element; 439 enum ib_event_type event; 440}; 441 442struct ib_event_handler { 443 struct ib_device *device; 444 void (*handler)(struct ib_event_handler *, struct ib_event *); 445 struct list_head list; 446}; 447 448#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \ 449 do { \ 450 (_ptr)->device = _device; \ 451 (_ptr)->handler = _handler; \ 452 INIT_LIST_HEAD(&(_ptr)->list); \ 453 } while (0) 454 455struct ib_global_route { 456 union ib_gid dgid; 457 u32 flow_label; 458 u8 sgid_index; 459 u8 hop_limit; 460 u8 traffic_class; 461}; 462 463struct ib_grh { 464 __be32 version_tclass_flow; 465 __be16 paylen; 466 u8 next_hdr; 467 u8 hop_limit; 468 union ib_gid sgid; 469 union ib_gid dgid; 470}; 471 472enum { 473 IB_MULTICAST_QPN = 0xffffff 474}; 475 476#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF) 477 478enum ib_ah_flags { 479 IB_AH_GRH = 1 480}; 481 482enum ib_rate { 483 IB_RATE_PORT_CURRENT = 0, 484 IB_RATE_2_5_GBPS = 2, 485 IB_RATE_5_GBPS = 5, 486 IB_RATE_10_GBPS = 3, 487 IB_RATE_20_GBPS = 6, 488 IB_RATE_30_GBPS = 4, 489 IB_RATE_40_GBPS = 7, 490 IB_RATE_60_GBPS = 8, 491 IB_RATE_80_GBPS = 9, 492 IB_RATE_120_GBPS = 10, 493 IB_RATE_14_GBPS = 11, 494 IB_RATE_56_GBPS = 12, 495 IB_RATE_112_GBPS = 13, 496 IB_RATE_168_GBPS = 14, 497 IB_RATE_25_GBPS = 15, 498 IB_RATE_100_GBPS = 16, 499 IB_RATE_200_GBPS = 17, 500 IB_RATE_300_GBPS = 18 501}; 502 503/** 504 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the 505 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be 506 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec. 507 * @rate: rate to convert. 508 */ 509int ib_rate_to_mult(enum ib_rate rate) __attribute_const__; 510 511/** 512 * ib_rate_to_mbps - Convert the IB rate enum to Mbps. 513 * For example, IB_RATE_2_5_GBPS will be converted to 2500. 514 * @rate: rate to convert. 515 */ 516int ib_rate_to_mbps(enum ib_rate rate) __attribute_const__; 517 518/** 519 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate 520 * enum. 521 * @mult: multiple to convert. 522 */ 523enum ib_rate mult_to_ib_rate(int mult) __attribute_const__; 524 525struct ib_ah_attr { 526 struct ib_global_route grh; 527 u16 dlid; 528 u8 sl; 529 u8 src_path_bits; 530 u8 static_rate; 531 u8 ah_flags; 532 u8 port_num; 533}; 534 535enum ib_wc_status { 536 IB_WC_SUCCESS, 537 IB_WC_LOC_LEN_ERR, 538 IB_WC_LOC_QP_OP_ERR, 539 IB_WC_LOC_EEC_OP_ERR, 540 IB_WC_LOC_PROT_ERR, 541 IB_WC_WR_FLUSH_ERR, 542 IB_WC_MW_BIND_ERR, 543 IB_WC_BAD_RESP_ERR, 544 IB_WC_LOC_ACCESS_ERR, 545 IB_WC_REM_INV_REQ_ERR, 546 IB_WC_REM_ACCESS_ERR, 547 IB_WC_REM_OP_ERR, 548 IB_WC_RETRY_EXC_ERR, 549 IB_WC_RNR_RETRY_EXC_ERR, 550 IB_WC_LOC_RDD_VIOL_ERR, 551 IB_WC_REM_INV_RD_REQ_ERR, 552 IB_WC_REM_ABORT_ERR, 553 IB_WC_INV_EECN_ERR, 554 IB_WC_INV_EEC_STATE_ERR, 555 IB_WC_FATAL_ERR, 556 IB_WC_RESP_TIMEOUT_ERR, 557 IB_WC_GENERAL_ERR 558}; 559 560enum ib_wc_opcode { 561 IB_WC_SEND, 562 IB_WC_RDMA_WRITE, 563 IB_WC_RDMA_READ, 564 IB_WC_COMP_SWAP, 565 IB_WC_FETCH_ADD, 566 IB_WC_BIND_MW, 567 IB_WC_LSO, 568 IB_WC_LOCAL_INV, 569 IB_WC_FAST_REG_MR, 570 IB_WC_MASKED_COMP_SWAP, 571 IB_WC_MASKED_FETCH_ADD, 572/* 573 * Set value of IB_WC_RECV so consumers can test if a completion is a 574 * receive by testing (opcode & IB_WC_RECV). 575 */ 576 IB_WC_RECV = 1 << 7, 577 IB_WC_RECV_RDMA_WITH_IMM 578}; 579 580enum ib_wc_flags { 581 IB_WC_GRH = 1, 582 IB_WC_WITH_IMM = (1<<1), 583 IB_WC_WITH_INVALIDATE = (1<<2), 584 IB_WC_IP_CSUM_OK = (1<<3), 585}; 586 587struct ib_wc { 588 u64 wr_id; 589 enum ib_wc_status status; 590 enum ib_wc_opcode opcode; 591 u32 vendor_err; 592 u32 byte_len; 593 struct ib_qp *qp; 594 union { 595 __be32 imm_data; 596 u32 invalidate_rkey; 597 } ex; 598 u32 src_qp; 599 int wc_flags; 600 u16 pkey_index; 601 u16 slid; 602 u8 sl; 603 u8 dlid_path_bits; 604 u8 port_num; /* valid only for DR SMPs on switches */ 605 int csum_ok; 606}; 607 608enum ib_cq_notify_flags { 609 IB_CQ_SOLICITED = 1 << 0, 610 IB_CQ_NEXT_COMP = 1 << 1, 611 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP, 612 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2, 613}; 614 615enum ib_srq_type { 616 IB_SRQT_BASIC, 617 IB_SRQT_XRC 618}; 619 620enum ib_srq_attr_mask { 621 IB_SRQ_MAX_WR = 1 << 0, 622 IB_SRQ_LIMIT = 1 << 1, 623}; 624 625struct ib_srq_attr { 626 u32 max_wr; 627 u32 max_sge; 628 u32 srq_limit; 629}; 630 631struct ib_srq_init_attr { 632 void (*event_handler)(struct ib_event *, void *); 633 void *srq_context; 634 struct ib_srq_attr attr; 635 enum ib_srq_type srq_type; 636 637 union { 638 struct { 639 struct ib_xrcd *xrcd; 640 struct ib_cq *cq; 641 } xrc; 642 } ext; 643}; 644 645struct ib_qp_cap { 646 u32 max_send_wr; 647 u32 max_recv_wr; 648 u32 max_send_sge; 649 u32 max_recv_sge; 650 u32 max_inline_data; 651 u32 qpg_tss_mask_sz; 652}; 653 654enum ib_sig_type { 655 IB_SIGNAL_ALL_WR, 656 IB_SIGNAL_REQ_WR 657}; 658 659enum ib_qp_type { 660 /* 661 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries 662 * here (and in that order) since the MAD layer uses them as 663 * indices into a 2-entry table. 664 */ 665 IB_QPT_SMI, 666 IB_QPT_GSI, 667 668 IB_QPT_RC, 669 IB_QPT_UC, 670 IB_QPT_UD, 671 IB_QPT_XRC, 672 IB_QPT_RAW_IPV6, 673 IB_QPT_RAW_ETHERTYPE, 674 IB_QPT_RAW_PACKET = 8, 675 IB_QPT_XRC_INI = 9, 676 IB_QPT_XRC_TGT, 677 IB_QPT_MAX, 678}; 679 680enum ib_qp_create_flags { 681 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0, 682 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1, 683 IB_QP_CREATE_NETIF_QP = 1 << 2, 684 /* reserve bits 26-31 for low level drivers' internal use */ 685 IB_QP_CREATE_RESERVED_START = 1 << 26, 686 IB_QP_CREATE_RESERVED_END = 1 << 31, 687}; 688 689enum ib_qpg_type { 690 IB_QPG_NONE = 0, 691 IB_QPG_PARENT = (1<<0), 692 IB_QPG_CHILD_RX = (1<<1), 693 IB_QPG_CHILD_TX = (1<<2) 694}; 695 696struct ib_qpg_init_attrib { 697 u32 tss_child_count; 698 u32 rss_child_count; 699}; 700 701struct ib_qp_init_attr { 702 void (*event_handler)(struct ib_event *, void *); 703 void *qp_context; 704 struct ib_cq *send_cq; 705 struct ib_cq *recv_cq; 706 struct ib_srq *srq; 707 struct ib_xrcd *xrcd; /* XRC TGT QPs only */ 708 struct ib_qp_cap cap; 709 union { 710 struct ib_qp *qpg_parent; /* see qpg_type */ 711 struct ib_qpg_init_attrib parent_attrib; 712 } pp; 713 enum ib_sig_type sq_sig_type; 714 enum ib_qp_type qp_type; 715 enum ib_qp_create_flags create_flags; 716 enum ib_qpg_type qpg_type; 717 u8 port_num; /* special QP types only */ 718}; 719 720struct ib_qp_open_attr { 721 void (*event_handler)(struct ib_event *, void *); 722 void *qp_context; 723 u32 qp_num; 724 enum ib_qp_type qp_type; 725}; 726 727enum ib_rnr_timeout { 728 IB_RNR_TIMER_655_36 = 0, 729 IB_RNR_TIMER_000_01 = 1, 730 IB_RNR_TIMER_000_02 = 2, 731 IB_RNR_TIMER_000_03 = 3, 732 IB_RNR_TIMER_000_04 = 4, 733 IB_RNR_TIMER_000_06 = 5, 734 IB_RNR_TIMER_000_08 = 6, 735 IB_RNR_TIMER_000_12 = 7, 736 IB_RNR_TIMER_000_16 = 8, 737 IB_RNR_TIMER_000_24 = 9, 738 IB_RNR_TIMER_000_32 = 10, 739 IB_RNR_TIMER_000_48 = 11, 740 IB_RNR_TIMER_000_64 = 12, 741 IB_RNR_TIMER_000_96 = 13, 742 IB_RNR_TIMER_001_28 = 14, 743 IB_RNR_TIMER_001_92 = 15, 744 IB_RNR_TIMER_002_56 = 16, 745 IB_RNR_TIMER_003_84 = 17, 746 IB_RNR_TIMER_005_12 = 18, 747 IB_RNR_TIMER_007_68 = 19, 748 IB_RNR_TIMER_010_24 = 20, 749 IB_RNR_TIMER_015_36 = 21, 750 IB_RNR_TIMER_020_48 = 22, 751 IB_RNR_TIMER_030_72 = 23, 752 IB_RNR_TIMER_040_96 = 24, 753 IB_RNR_TIMER_061_44 = 25, 754 IB_RNR_TIMER_081_92 = 26, 755 IB_RNR_TIMER_122_88 = 27, 756 IB_RNR_TIMER_163_84 = 28, 757 IB_RNR_TIMER_245_76 = 29, 758 IB_RNR_TIMER_327_68 = 30, 759 IB_RNR_TIMER_491_52 = 31 760}; 761 762enum ib_qp_attr_mask { 763 IB_QP_STATE = 1, 764 IB_QP_CUR_STATE = (1<<1), 765 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2), 766 IB_QP_ACCESS_FLAGS = (1<<3), 767 IB_QP_PKEY_INDEX = (1<<4), 768 IB_QP_PORT = (1<<5), 769 IB_QP_QKEY = (1<<6), 770 IB_QP_AV = (1<<7), 771 IB_QP_PATH_MTU = (1<<8), 772 IB_QP_TIMEOUT = (1<<9), 773 IB_QP_RETRY_CNT = (1<<10), 774 IB_QP_RNR_RETRY = (1<<11), 775 IB_QP_RQ_PSN = (1<<12), 776 IB_QP_MAX_QP_RD_ATOMIC = (1<<13), 777 IB_QP_ALT_PATH = (1<<14), 778 IB_QP_MIN_RNR_TIMER = (1<<15), 779 IB_QP_SQ_PSN = (1<<16), 780 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17), 781 IB_QP_PATH_MIG_STATE = (1<<18), 782 IB_QP_CAP = (1<<19), 783 IB_QP_DEST_QPN = (1<<20), 784 IB_QP_GROUP_RSS = (1<<21) 785}; 786 787enum ib_qp_state { 788 IB_QPS_RESET, 789 IB_QPS_INIT, 790 IB_QPS_RTR, 791 IB_QPS_RTS, 792 IB_QPS_SQD, 793 IB_QPS_SQE, 794 IB_QPS_ERR 795}; 796 797enum ib_mig_state { 798 IB_MIG_MIGRATED, 799 IB_MIG_REARM, 800 IB_MIG_ARMED 801}; 802 803struct ib_qp_attr { 804 enum ib_qp_state qp_state; 805 enum ib_qp_state cur_qp_state; 806 enum ib_mtu path_mtu; 807 enum ib_mig_state path_mig_state; 808 u32 qkey; 809 u32 rq_psn; 810 u32 sq_psn; 811 u32 dest_qp_num; 812 int qp_access_flags; 813 struct ib_qp_cap cap; 814 struct ib_ah_attr ah_attr; 815 struct ib_ah_attr alt_ah_attr; 816 u16 pkey_index; 817 u16 alt_pkey_index; 818 u8 en_sqd_async_notify; 819 u8 sq_draining; 820 u8 max_rd_atomic; 821 u8 max_dest_rd_atomic; 822 u8 min_rnr_timer; 823 u8 port_num; 824 u8 timeout; 825 u8 retry_cnt; 826 u8 rnr_retry; 827 u8 alt_port_num; 828 u8 alt_timeout; 829}; 830 831enum ib_wr_opcode { 832 IB_WR_RDMA_WRITE, 833 IB_WR_RDMA_WRITE_WITH_IMM, 834 IB_WR_SEND, 835 IB_WR_SEND_WITH_IMM, 836 IB_WR_RDMA_READ, 837 IB_WR_ATOMIC_CMP_AND_SWP, 838 IB_WR_ATOMIC_FETCH_AND_ADD, 839 IB_WR_LSO, 840 IB_WR_BIG_LSO, 841 IB_WR_SEND_WITH_INV, 842 IB_WR_RDMA_READ_WITH_INV, 843 IB_WR_LOCAL_INV, 844 IB_WR_FAST_REG_MR, 845 IB_WR_MASKED_ATOMIC_CMP_AND_SWP, 846 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD, 847}; 848 849enum ib_send_flags { 850 IB_SEND_FENCE = 1, 851 IB_SEND_SIGNALED = (1<<1), 852 IB_SEND_SOLICITED = (1<<2), 853 IB_SEND_INLINE = (1<<3), 854 IB_SEND_IP_CSUM = (1<<4) 855}; 856 857enum ib_flow_types { 858 IB_FLOW_ETH = 0, 859 IB_FLOW_IB_UC = 1, 860 IB_FLOW_IB_MC_IPV4 = 2, 861 IB_FLOW_IB_MC_IPV6 = 3 862}; 863 864enum { 865 IB_FLOW_L4_NONE = 0, 866 IB_FLOW_L4_OTHER = 3, 867 IB_FLOW_L4_UDP = 5, 868 IB_FLOW_L4_TCP = 6 869}; 870 871struct ib_sge { 872 u64 addr; 873 u32 length; 874 u32 lkey; 875}; 876 877struct ib_fast_reg_page_list { 878 struct ib_device *device; 879 u64 *page_list; 880 unsigned int max_page_list_len; 881}; 882 883struct ib_send_wr { 884 struct ib_send_wr *next; 885 u64 wr_id; 886 struct ib_sge *sg_list; 887 int num_sge; 888 enum ib_wr_opcode opcode; 889 int send_flags; 890 union { 891 __be32 imm_data; 892 u32 invalidate_rkey; 893 } ex; 894 union { 895 struct { 896 u64 remote_addr; 897 u32 rkey; 898 } rdma; 899 struct { 900 u64 remote_addr; 901 u64 compare_add; 902 u64 swap; 903 u64 compare_add_mask; 904 u64 swap_mask; 905 u32 rkey; 906 } atomic; 907 struct { 908 struct ib_ah *ah; 909 void *header; 910 int hlen; 911 int mss; 912 u32 remote_qpn; 913 u32 remote_qkey; 914 u16 pkey_index; /* valid for GSI only */ 915 u8 port_num; /* valid for DR SMPs on switch only */ 916 } ud; 917 struct { 918 u64 iova_start; 919 struct ib_fast_reg_page_list *page_list; 920 unsigned int page_shift; 921 unsigned int page_list_len; 922 u32 length; 923 int access_flags; 924 u32 rkey; 925 } fast_reg; 926 struct { 927 struct ib_unpacked_lrh *lrh; 928 u32 eth_type; 929 u8 static_rate; 930 } raw_ety; 931 } wr; 932 u32 xrc_remote_srq_num; /* XRC TGT QPs only */ 933}; 934 935struct ib_recv_wr { 936 struct ib_recv_wr *next; 937 u64 wr_id; 938 struct ib_sge *sg_list; 939 int num_sge; 940}; 941 942enum ib_access_flags { 943 IB_ACCESS_LOCAL_WRITE = 1, 944 IB_ACCESS_REMOTE_WRITE = (1<<1), 945 IB_ACCESS_REMOTE_READ = (1<<2), 946 IB_ACCESS_REMOTE_ATOMIC = (1<<3), 947 IB_ACCESS_MW_BIND = (1<<4), 948 IB_ACCESS_ALLOCATE_MR = (1<<5), 949 IB_ACCESS_SHARED_MR_USER_READ = (1<<6), 950 IB_ACCESS_SHARED_MR_USER_WRITE = (1<<7), 951 IB_ACCESS_SHARED_MR_GROUP_READ = (1<<8), 952 IB_ACCESS_SHARED_MR_GROUP_WRITE = (1<<9), 953 IB_ACCESS_SHARED_MR_OTHER_READ = (1<<10), 954 IB_ACCESS_SHARED_MR_OTHER_WRITE = (1<<11) 955 956}; 957 958struct ib_phys_buf { 959 u64 addr; 960 u64 size; 961}; 962 963struct ib_mr_attr { 964 struct ib_pd *pd; 965 u64 device_virt_addr; 966 u64 size; 967 int mr_access_flags; 968 u32 lkey; 969 u32 rkey; 970}; 971 972enum ib_mr_rereg_flags { 973 IB_MR_REREG_TRANS = 1, 974 IB_MR_REREG_PD = (1<<1), 975 IB_MR_REREG_ACCESS = (1<<2) 976}; 977 978struct ib_mw_bind { 979 struct ib_mr *mr; 980 u64 wr_id; 981 u64 addr; 982 u32 length; 983 int send_flags; 984 int mw_access_flags; 985}; 986 987struct ib_fmr_attr { 988 int max_pages; 989 int max_maps; 990 u8 page_shift; 991}; 992 993struct ib_ucontext { 994 struct ib_device *device; 995 struct list_head pd_list; 996 struct list_head mr_list; 997 struct list_head mw_list; 998 struct list_head cq_list; 999 struct list_head qp_list; 1000 struct list_head srq_list; 1001 struct list_head ah_list; 1002 struct list_head xrcd_list; 1003 int closing; 1004}; 1005 1006struct ib_uobject { 1007 u64 user_handle; /* handle given to us by userspace */ 1008 struct ib_ucontext *context; /* associated user context */ 1009 void *object; /* containing object */ 1010 struct list_head list; /* link to context's list */ 1011 int id; /* index into kernel idr */ 1012 struct kref ref; 1013 struct rw_semaphore mutex; /* protects .live */ 1014 int live; 1015}; 1016 1017struct ib_udata { 1018 void __user *inbuf; 1019 void __user *outbuf; 1020 size_t inlen; 1021 size_t outlen; 1022}; 1023 1024struct ib_uxrc_rcv_object { 1025 struct list_head list; /* link to context's list */ 1026 u32 qp_num; 1027 u32 domain_handle; 1028}; 1029 1030struct ib_pd { 1031 struct ib_device *device; 1032 struct ib_uobject *uobject; 1033 atomic_t usecnt; /* count all resources */ 1034}; 1035 1036struct ib_xrcd { 1037 struct ib_device *device; 1038 struct ib_uobject *uobject; 1039 atomic_t usecnt; /* count all exposed resources */ 1040 struct inode *inode; 1041 struct rb_node node; 1042 1043 struct mutex tgt_qp_mutex; 1044 struct list_head tgt_qp_list; 1045}; 1046 1047struct ib_ah { 1048 struct ib_device *device; 1049 struct ib_pd *pd; 1050 struct ib_uobject *uobject; 1051}; 1052 1053typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context); 1054 1055struct ib_cq { 1056 struct ib_device *device; 1057 struct ib_uobject *uobject; 1058 ib_comp_handler comp_handler; 1059 void (*event_handler)(struct ib_event *, void *); 1060 void *cq_context; 1061 int cqe; 1062 atomic_t usecnt; /* count number of work queues */ 1063}; 1064 1065struct ib_srq { 1066 struct ib_device *device; 1067 struct ib_pd *pd; 1068 struct ib_uobject *uobject; 1069 void (*event_handler)(struct ib_event *, void *); 1070 void *srq_context; 1071 enum ib_srq_type srq_type; 1072 atomic_t usecnt; 1073 1074 union { 1075 struct { 1076 struct ib_xrcd *xrcd; 1077 struct ib_cq *cq; 1078 u32 srq_num; 1079 } xrc; 1080 } ext; 1081}; 1082 1083struct ib_qp { 1084 struct ib_device *device; 1085 struct ib_pd *pd; 1086 struct ib_cq *send_cq; 1087 struct ib_cq *recv_cq; 1088 struct ib_srq *srq; 1089 struct ib_xrcd *xrcd; /* XRC TGT QPs only */ 1090 struct list_head xrcd_list; 1091 atomic_t usecnt; /* count times opened, mcast attaches */ 1092 struct list_head open_list; 1093 struct ib_qp *real_qp; 1094 struct ib_uobject *uobject; 1095 void (*event_handler)(struct ib_event *, void *); 1096 void *qp_context; 1097 u32 qp_num; 1098 enum ib_qp_type qp_type; 1099 enum ib_qpg_type qpg_type; 1100}; 1101 1102struct ib_mr { 1103 struct ib_device *device; 1104 struct ib_pd *pd; 1105 struct ib_uobject *uobject; 1106 u32 lkey; 1107 u32 rkey; 1108 atomic_t usecnt; /* count number of MWs */ 1109}; 1110 1111struct ib_mw { 1112 struct ib_device *device; 1113 struct ib_pd *pd; 1114 struct ib_uobject *uobject; 1115 u32 rkey; 1116}; 1117 1118struct ib_fmr { 1119 struct ib_device *device; 1120 struct ib_pd *pd; 1121 struct list_head list; 1122 u32 lkey; 1123 u32 rkey; 1124}; 1125 1126struct ib_flow_spec { 1127 enum ib_flow_types type; 1128 union { 1129 struct { 1130 __be16 ethertype; 1131 __be16 vlan; 1132 u8 vlan_present; 1133 u8 mac[6]; 1134 u8 port; 1135 } eth; 1136 struct { 1137 __be32 qpn; 1138 } ib_uc; 1139 struct { 1140 u8 mgid[16]; 1141 } ib_mc; 1142 } l2_id; 1143 __be32 src_ip; 1144 __be32 dst_ip; 1145 __be16 src_port; 1146 __be16 dst_port; 1147 u8 l4_protocol; 1148 u8 block_mc_loopback; 1149 u8 rule_type; 1150}; 1151 1152struct ib_mad; 1153struct ib_grh; 1154 1155enum ib_process_mad_flags { 1156 IB_MAD_IGNORE_MKEY = 1, 1157 IB_MAD_IGNORE_BKEY = 2, 1158 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY 1159}; 1160 1161enum ib_mad_result { 1162 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */ 1163 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */ 1164 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */ 1165 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */ 1166}; 1167 1168#define IB_DEVICE_NAME_MAX 64 1169 1170struct ib_cache { 1171 rwlock_t lock; 1172 struct ib_event_handler event_handler; 1173 struct ib_pkey_cache **pkey_cache; 1174 struct ib_gid_cache **gid_cache; 1175 u8 *lmc_cache; 1176}; 1177 1178struct ib_dma_mapping_ops { 1179 int (*mapping_error)(struct ib_device *dev, 1180 u64 dma_addr); 1181 u64 (*map_single)(struct ib_device *dev, 1182 void *ptr, size_t size, 1183 enum dma_data_direction direction); 1184 void (*unmap_single)(struct ib_device *dev, 1185 u64 addr, size_t size, 1186 enum dma_data_direction direction); 1187 u64 (*map_page)(struct ib_device *dev, 1188 struct page *page, unsigned long offset, 1189 size_t size, 1190 enum dma_data_direction direction); 1191 void (*unmap_page)(struct ib_device *dev, 1192 u64 addr, size_t size, 1193 enum dma_data_direction direction); 1194 int (*map_sg)(struct ib_device *dev, 1195 struct scatterlist *sg, int nents, 1196 enum dma_data_direction direction); 1197 void (*unmap_sg)(struct ib_device *dev, 1198 struct scatterlist *sg, int nents, 1199 enum dma_data_direction direction); 1200 u64 (*dma_address)(struct ib_device *dev, 1201 struct scatterlist *sg); 1202 unsigned int (*dma_len)(struct ib_device *dev, 1203 struct scatterlist *sg); 1204 void (*sync_single_for_cpu)(struct ib_device *dev, 1205 u64 dma_handle, 1206 size_t size, 1207 enum dma_data_direction dir); 1208 void (*sync_single_for_device)(struct ib_device *dev, 1209 u64 dma_handle, 1210 size_t size, 1211 enum dma_data_direction dir); 1212 void *(*alloc_coherent)(struct ib_device *dev, 1213 size_t size, 1214 u64 *dma_handle, 1215 gfp_t flag); 1216 void (*free_coherent)(struct ib_device *dev, 1217 size_t size, void *cpu_addr, 1218 u64 dma_handle); 1219}; 1220 1221struct iw_cm_verbs; 1222 1223struct ib_port_immutable { 1224 int pkey_tbl_len; 1225 int gid_tbl_len; 1226 u32 core_cap_flags; 1227 u32 max_mad_size; 1228}; 1229 1230struct ib_device { 1231 struct device *dma_device; 1232 1233 char name[IB_DEVICE_NAME_MAX]; 1234 1235 struct list_head event_handler_list; 1236 spinlock_t event_handler_lock; 1237 1238 spinlock_t client_data_lock; 1239 struct list_head core_list; 1240 struct list_head client_data_list; 1241 1242 struct ib_cache cache; 1243 /** 1244 * port_immutable is indexed by port number 1245 */ 1246 struct ib_port_immutable *port_immutable; 1247 1248 int num_comp_vectors; 1249 1250 struct iw_cm_verbs *iwcm; 1251 1252 int (*get_protocol_stats)(struct ib_device *device, 1253 union rdma_protocol_stats *stats); 1254 int (*query_device)(struct ib_device *device, 1255 struct ib_device_attr *device_attr); 1256 int (*query_port)(struct ib_device *device, 1257 u8 port_num, 1258 struct ib_port_attr *port_attr); 1259 enum rdma_link_layer (*get_link_layer)(struct ib_device *device, 1260 u8 port_num); 1261 int (*query_gid)(struct ib_device *device, 1262 u8 port_num, int index, 1263 union ib_gid *gid); 1264 int (*query_pkey)(struct ib_device *device, 1265 u8 port_num, u16 index, u16 *pkey); 1266 int (*modify_device)(struct ib_device *device, 1267 int device_modify_mask, 1268 struct ib_device_modify *device_modify); 1269 int (*modify_port)(struct ib_device *device, 1270 u8 port_num, int port_modify_mask, 1271 struct ib_port_modify *port_modify); 1272 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device, 1273 struct ib_udata *udata); 1274 int (*dealloc_ucontext)(struct ib_ucontext *context); 1275 int (*mmap)(struct ib_ucontext *context, 1276 struct vm_area_struct *vma); 1277 struct ib_pd * (*alloc_pd)(struct ib_device *device, 1278 struct ib_ucontext *context, 1279 struct ib_udata *udata); 1280 int (*dealloc_pd)(struct ib_pd *pd); 1281 struct ib_ah * (*create_ah)(struct ib_pd *pd, 1282 struct ib_ah_attr *ah_attr); 1283 int (*modify_ah)(struct ib_ah *ah, 1284 struct ib_ah_attr *ah_attr); 1285 int (*query_ah)(struct ib_ah *ah, 1286 struct ib_ah_attr *ah_attr); 1287 int (*destroy_ah)(struct ib_ah *ah); 1288 struct ib_srq * (*create_srq)(struct ib_pd *pd, 1289 struct ib_srq_init_attr *srq_init_attr, 1290 struct ib_udata *udata); 1291 int (*modify_srq)(struct ib_srq *srq, 1292 struct ib_srq_attr *srq_attr, 1293 enum ib_srq_attr_mask srq_attr_mask, 1294 struct ib_udata *udata); 1295 int (*query_srq)(struct ib_srq *srq, 1296 struct ib_srq_attr *srq_attr); 1297 int (*destroy_srq)(struct ib_srq *srq); 1298 int (*post_srq_recv)(struct ib_srq *srq, 1299 struct ib_recv_wr *recv_wr, 1300 struct ib_recv_wr **bad_recv_wr); 1301 struct ib_qp * (*create_qp)(struct ib_pd *pd, 1302 struct ib_qp_init_attr *qp_init_attr, 1303 struct ib_udata *udata); 1304 int (*modify_qp)(struct ib_qp *qp, 1305 struct ib_qp_attr *qp_attr, 1306 int qp_attr_mask, 1307 struct ib_udata *udata); 1308 int (*query_qp)(struct ib_qp *qp, 1309 struct ib_qp_attr *qp_attr, 1310 int qp_attr_mask, 1311 struct ib_qp_init_attr *qp_init_attr); 1312 int (*destroy_qp)(struct ib_qp *qp); 1313 int (*post_send)(struct ib_qp *qp, 1314 struct ib_send_wr *send_wr, 1315 struct ib_send_wr **bad_send_wr); 1316 int (*post_recv)(struct ib_qp *qp, 1317 struct ib_recv_wr *recv_wr, 1318 struct ib_recv_wr **bad_recv_wr); 1319 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe, 1320 int comp_vector, 1321 struct ib_ucontext *context, 1322 struct ib_udata *udata); 1323 int (*modify_cq)(struct ib_cq *cq, u16 cq_count, 1324 u16 cq_period); 1325 int (*destroy_cq)(struct ib_cq *cq); 1326 int (*resize_cq)(struct ib_cq *cq, int cqe, 1327 struct ib_udata *udata); 1328 int (*poll_cq)(struct ib_cq *cq, int num_entries, 1329 struct ib_wc *wc); 1330 int (*peek_cq)(struct ib_cq *cq, int wc_cnt); 1331 int (*req_notify_cq)(struct ib_cq *cq, 1332 enum ib_cq_notify_flags flags); 1333 int (*req_ncomp_notif)(struct ib_cq *cq, 1334 int wc_cnt); 1335 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd, 1336 int mr_access_flags); 1337 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd, 1338 struct ib_phys_buf *phys_buf_array, 1339 int num_phys_buf, 1340 int mr_access_flags, 1341 u64 *iova_start); 1342 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd, 1343 u64 start, u64 length, 1344 u64 virt_addr, 1345 int mr_access_flags, 1346 struct ib_udata *udata, 1347 int mr_id); 1348 int (*query_mr)(struct ib_mr *mr, 1349 struct ib_mr_attr *mr_attr); 1350 int (*dereg_mr)(struct ib_mr *mr); 1351 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd, 1352 int max_page_list_len); 1353 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device, 1354 int page_list_len); 1355 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list); 1356 int (*rereg_phys_mr)(struct ib_mr *mr, 1357 int mr_rereg_mask, 1358 struct ib_pd *pd, 1359 struct ib_phys_buf *phys_buf_array, 1360 int num_phys_buf, 1361 int mr_access_flags, 1362 u64 *iova_start); 1363 struct ib_mw * (*alloc_mw)(struct ib_pd *pd); 1364 int (*bind_mw)(struct ib_qp *qp, 1365 struct ib_mw *mw, 1366 struct ib_mw_bind *mw_bind); 1367 int (*dealloc_mw)(struct ib_mw *mw); 1368 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd, 1369 int mr_access_flags, 1370 struct ib_fmr_attr *fmr_attr); 1371 int (*map_phys_fmr)(struct ib_fmr *fmr, 1372 u64 *page_list, int list_len, 1373 u64 iova); 1374 int (*unmap_fmr)(struct list_head *fmr_list); 1375 int (*dealloc_fmr)(struct ib_fmr *fmr); 1376 int (*attach_mcast)(struct ib_qp *qp, 1377 union ib_gid *gid, 1378 u16 lid); 1379 int (*detach_mcast)(struct ib_qp *qp, 1380 union ib_gid *gid, 1381 u16 lid); 1382 int (*process_mad)(struct ib_device *device, 1383 int process_mad_flags, 1384 u8 port_num, 1385 struct ib_wc *in_wc, 1386 struct ib_grh *in_grh, 1387 struct ib_mad *in_mad, 1388 struct ib_mad *out_mad); 1389 struct ib_srq * (*create_xrc_srq)(struct ib_pd *pd, 1390 struct ib_cq *xrc_cq, 1391 struct ib_xrcd *xrcd, 1392 struct ib_srq_init_attr *srq_init_attr, 1393 struct ib_udata *udata); 1394 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device, 1395 struct ib_ucontext *ucontext, 1396 struct ib_udata *udata); 1397 int (*dealloc_xrcd)(struct ib_xrcd *xrcd); 1398 int (*create_xrc_rcv_qp)(struct ib_qp_init_attr *init_attr, 1399 u32 *qp_num); 1400 int (*modify_xrc_rcv_qp)(struct ib_xrcd *xrcd, 1401 u32 qp_num, 1402 struct ib_qp_attr *attr, 1403 int attr_mask); 1404 int (*query_xrc_rcv_qp)(struct ib_xrcd *xrcd, 1405 u32 qp_num, 1406 struct ib_qp_attr *attr, 1407 int attr_mask, 1408 struct ib_qp_init_attr *init_attr); 1409 int (*reg_xrc_rcv_qp)(struct ib_xrcd *xrcd, 1410 void *context, 1411 u32 qp_num); 1412 int (*unreg_xrc_rcv_qp)(struct ib_xrcd *xrcd, 1413 void *context, 1414 u32 qp_num); 1415 int (*attach_flow)(struct ib_qp *qp, 1416 struct ib_flow_spec *spec, 1417 int priority); 1418 int (*detach_flow)(struct ib_qp *qp, 1419 struct ib_flow_spec *spec, 1420 int priority); 1421 1422 unsigned long (*get_unmapped_area)(struct file *file, 1423 unsigned long addr, 1424 unsigned long len, unsigned long pgoff, 1425 unsigned long flags); 1426 struct ib_dma_mapping_ops *dma_ops; 1427 1428 struct module *owner; 1429 struct device dev; 1430 struct kobject *ports_parent; 1431 struct list_head port_list; 1432 1433 enum { 1434 IB_DEV_UNINITIALIZED, 1435 IB_DEV_REGISTERED, 1436 IB_DEV_UNREGISTERED 1437 } reg_state; 1438 1439 int uverbs_abi_ver; 1440 u64 uverbs_cmd_mask; 1441 1442 char node_desc[64]; 1443 __be64 node_guid; 1444 u32 local_dma_lkey; 1445 u8 node_type; 1446 u8 phys_port_cnt; 1447 struct rb_root ib_uverbs_xrcd_table; 1448 struct mutex xrcd_table_mutex; 1449 1450 /** 1451 * The following mandatory functions are used only at device 1452 * registration. Keep functions such as these at the end of this 1453 * structure to avoid cache line misses when accessing struct ib_device 1454 * in fast paths. 1455 */ 1456 int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *); 1457}; 1458 1459struct ib_client { 1460 char *name; 1461 void (*add) (struct ib_device *); 1462 void (*remove)(struct ib_device *); 1463 1464 struct list_head list; 1465}; 1466 1467struct ib_device *ib_alloc_device(size_t size); 1468void ib_dealloc_device(struct ib_device *device); 1469 1470int ib_register_device(struct ib_device *device, 1471 int (*port_callback)(struct ib_device *, 1472 u8, struct kobject *)); 1473void ib_unregister_device(struct ib_device *device); 1474 1475int ib_register_client (struct ib_client *client); 1476void ib_unregister_client(struct ib_client *client); 1477 1478void *ib_get_client_data(struct ib_device *device, struct ib_client *client); 1479void ib_set_client_data(struct ib_device *device, struct ib_client *client, 1480 void *data); 1481 1482static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len) 1483{ 1484 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0; 1485} 1486 1487static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len) 1488{ 1489 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0; 1490} 1491 1492/** 1493 * ib_modify_qp_is_ok - Check that the supplied attribute mask 1494 * contains all required attributes and no attributes not allowed for 1495 * the given QP state transition. 1496 * @cur_state: Current QP state 1497 * @next_state: Next QP state 1498 * @type: QP type 1499 * @mask: Mask of supplied QP attributes 1500 * 1501 * This function is a helper function that a low-level driver's 1502 * modify_qp method can use to validate the consumer's input. It 1503 * checks that cur_state and next_state are valid QP states, that a 1504 * transition from cur_state to next_state is allowed by the IB spec, 1505 * and that the attribute mask supplied is allowed for the transition. 1506 */ 1507int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state, 1508 enum ib_qp_type type, enum ib_qp_attr_mask mask); 1509 1510int ib_register_event_handler (struct ib_event_handler *event_handler); 1511int ib_unregister_event_handler(struct ib_event_handler *event_handler); 1512void ib_dispatch_event(struct ib_event *event); 1513 1514int ib_query_device(struct ib_device *device, 1515 struct ib_device_attr *device_attr); 1516 1517int ib_query_port(struct ib_device *device, 1518 u8 port_num, struct ib_port_attr *port_attr); 1519 1520enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, 1521 u8 port_num); 1522 1523static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num) 1524{ 1525 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB; 1526} 1527 1528static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num) 1529{ 1530 return device->port_immutable[port_num].core_cap_flags & 1531 (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP); 1532} 1533 1534static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num) 1535{ 1536 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP; 1537} 1538 1539static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num) 1540{ 1541 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE; 1542} 1543 1544static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num) 1545{ 1546 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP; 1547} 1548 1549static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num) 1550{ 1551 return rdma_protocol_ib(device, port_num) || 1552 rdma_protocol_roce(device, port_num); 1553} 1554 1555/** 1556 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband 1557 * Management Datagrams. 1558 * @device: Device to check 1559 * @port_num: Port number to check 1560 * 1561 * Management Datagrams (MAD) are a required part of the InfiniBand 1562 * specification and are supported on all InfiniBand devices. A slightly 1563 * extended version are also supported on OPA interfaces. 1564 * 1565 * Return: true if the port supports sending/receiving of MAD packets. 1566 */ 1567static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num) 1568{ 1569 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD; 1570} 1571 1572/** 1573 * rdma_cap_opa_mad - Check if the port of device provides support for OPA 1574 * Management Datagrams. 1575 * @device: Device to check 1576 * @port_num: Port number to check 1577 * 1578 * Intel OmniPath devices extend and/or replace the InfiniBand Management 1579 * datagrams with their own versions. These OPA MADs share many but not all of 1580 * the characteristics of InfiniBand MADs. 1581 * 1582 * OPA MADs differ in the following ways: 1583 * 1584 * 1) MADs are variable size up to 2K 1585 * IBTA defined MADs remain fixed at 256 bytes 1586 * 2) OPA SMPs must carry valid PKeys 1587 * 3) OPA SMP packets are a different format 1588 * 1589 * Return: true if the port supports OPA MAD packet formats. 1590 */ 1591static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num) 1592{ 1593 return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD) 1594 == RDMA_CORE_CAP_OPA_MAD; 1595} 1596 1597/** 1598 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband 1599 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI). 1600 * @device: Device to check 1601 * @port_num: Port number to check 1602 * 1603 * Each InfiniBand node is required to provide a Subnet Management Agent 1604 * that the subnet manager can access. Prior to the fabric being fully 1605 * configured by the subnet manager, the SMA is accessed via a well known 1606 * interface called the Subnet Management Interface (SMI). This interface 1607 * uses directed route packets to communicate with the SM to get around the 1608 * chicken and egg problem of the SM needing to know what's on the fabric 1609 * in order to configure the fabric, and needing to configure the fabric in 1610 * order to send packets to the devices on the fabric. These directed 1611 * route packets do not need the fabric fully configured in order to reach 1612 * their destination. The SMI is the only method allowed to send 1613 * directed route packets on an InfiniBand fabric. 1614 * 1615 * Return: true if the port provides an SMI. 1616 */ 1617static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num) 1618{ 1619 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI; 1620} 1621 1622/** 1623 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband 1624 * Communication Manager. 1625 * @device: Device to check 1626 * @port_num: Port number to check 1627 * 1628 * The InfiniBand Communication Manager is one of many pre-defined General 1629 * Service Agents (GSA) that are accessed via the General Service 1630 * Interface (GSI). It's role is to facilitate establishment of connections 1631 * between nodes as well as other management related tasks for established 1632 * connections. 1633 * 1634 * Return: true if the port supports an IB CM (this does not guarantee that 1635 * a CM is actually running however). 1636 */ 1637static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num) 1638{ 1639 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM; 1640} 1641 1642/** 1643 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP 1644 * Communication Manager. 1645 * @device: Device to check 1646 * @port_num: Port number to check 1647 * 1648 * Similar to above, but specific to iWARP connections which have a different 1649 * managment protocol than InfiniBand. 1650 * 1651 * Return: true if the port supports an iWARP CM (this does not guarantee that 1652 * a CM is actually running however). 1653 */ 1654static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num) 1655{ 1656 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM; 1657} 1658 1659/** 1660 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband 1661 * Subnet Administration. 1662 * @device: Device to check 1663 * @port_num: Port number to check 1664 * 1665 * An InfiniBand Subnet Administration (SA) service is a pre-defined General 1666 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand 1667 * fabrics, devices should resolve routes to other hosts by contacting the 1668 * SA to query the proper route. 1669 * 1670 * Return: true if the port should act as a client to the fabric Subnet 1671 * Administration interface. This does not imply that the SA service is 1672 * running locally. 1673 */ 1674static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num) 1675{ 1676 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA; 1677} 1678 1679/** 1680 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband 1681 * Multicast. 1682 * @device: Device to check 1683 * @port_num: Port number to check 1684 * 1685 * InfiniBand multicast registration is more complex than normal IPv4 or 1686 * IPv6 multicast registration. Each Host Channel Adapter must register 1687 * with the Subnet Manager when it wishes to join a multicast group. It 1688 * should do so only once regardless of how many queue pairs it subscribes 1689 * to this group. And it should leave the group only after all queue pairs 1690 * attached to the group have been detached. 1691 * 1692 * Return: true if the port must undertake the additional adminstrative 1693 * overhead of registering/unregistering with the SM and tracking of the 1694 * total number of queue pairs attached to the multicast group. 1695 */ 1696static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num) 1697{ 1698 return rdma_cap_ib_sa(device, port_num); 1699} 1700 1701/** 1702 * rdma_cap_af_ib - Check if the port of device has the capability 1703 * Native Infiniband Address. 1704 * @device: Device to check 1705 * @port_num: Port number to check 1706 * 1707 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default 1708 * GID. RoCE uses a different mechanism, but still generates a GID via 1709 * a prescribed mechanism and port specific data. 1710 * 1711 * Return: true if the port uses a GID address to identify devices on the 1712 * network. 1713 */ 1714static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num) 1715{ 1716 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB; 1717} 1718 1719/** 1720 * rdma_cap_eth_ah - Check if the port of device has the capability 1721 * Ethernet Address Handle. 1722 * @device: Device to check 1723 * @port_num: Port number to check 1724 * 1725 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique 1726 * to fabricate GIDs over Ethernet/IP specific addresses native to the 1727 * port. Normally, packet headers are generated by the sending host 1728 * adapter, but when sending connectionless datagrams, we must manually 1729 * inject the proper headers for the fabric we are communicating over. 1730 * 1731 * Return: true if we are running as a RoCE port and must force the 1732 * addition of a Global Route Header built from our Ethernet Address 1733 * Handle into our header list for connectionless packets. 1734 */ 1735static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num) 1736{ 1737 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH; 1738} 1739 1740/** 1741 * rdma_max_mad_size - Return the max MAD size required by this RDMA Port. 1742 * 1743 * @device: Device 1744 * @port_num: Port number 1745 * 1746 * This MAD size includes the MAD headers and MAD payload. No other headers 1747 * are included. 1748 * 1749 * Return the max MAD size required by the Port. Will return 0 if the port 1750 * does not support MADs 1751 */ 1752static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num) 1753{ 1754 return device->port_immutable[port_num].max_mad_size; 1755} 1756 1757/* 1758 * Check if the device supports READ W/ INVALIDATE. 1759 */ 1760static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num) 1761{ 1762 /* 1763 * iWarp drivers must support READ W/ INVALIDATE. No other protocol 1764 * has support for it yet. 1765 */ 1766 return rdma_protocol_iwarp(dev, port_num); 1767} 1768 1769int ib_query_gid(struct ib_device *device, 1770 u8 port_num, int index, union ib_gid *gid); 1771 1772int ib_query_pkey(struct ib_device *device, 1773 u8 port_num, u16 index, u16 *pkey); 1774 1775int ib_modify_device(struct ib_device *device, 1776 int device_modify_mask, 1777 struct ib_device_modify *device_modify); 1778 1779int ib_modify_port(struct ib_device *device, 1780 u8 port_num, int port_modify_mask, 1781 struct ib_port_modify *port_modify); 1782 1783int ib_find_gid(struct ib_device *device, union ib_gid *gid, 1784 u8 *port_num, u16 *index); 1785 1786int ib_find_pkey(struct ib_device *device, 1787 u8 port_num, u16 pkey, u16 *index); 1788 1789/** 1790 * ib_alloc_pd - Allocates an unused protection domain. 1791 * @device: The device on which to allocate the protection domain. 1792 * 1793 * A protection domain object provides an association between QPs, shared 1794 * receive queues, address handles, memory regions, and memory windows. 1795 */ 1796struct ib_pd *ib_alloc_pd(struct ib_device *device); 1797 1798/** 1799 * ib_dealloc_pd - Deallocates a protection domain. 1800 * @pd: The protection domain to deallocate. 1801 */ 1802int ib_dealloc_pd(struct ib_pd *pd); 1803 1804/** 1805 * ib_create_ah - Creates an address handle for the given address vector. 1806 * @pd: The protection domain associated with the address handle. 1807 * @ah_attr: The attributes of the address vector. 1808 * 1809 * The address handle is used to reference a local or global destination 1810 * in all UD QP post sends. 1811 */ 1812struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr); 1813 1814/** 1815 * ib_init_ah_from_wc - Initializes address handle attributes from a 1816 * work completion. 1817 * @device: Device on which the received message arrived. 1818 * @port_num: Port on which the received message arrived. 1819 * @wc: Work completion associated with the received message. 1820 * @grh: References the received global route header. This parameter is 1821 * ignored unless the work completion indicates that the GRH is valid. 1822 * @ah_attr: Returned attributes that can be used when creating an address 1823 * handle for replying to the message. 1824 */ 1825int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc, 1826 struct ib_grh *grh, struct ib_ah_attr *ah_attr); 1827 1828/** 1829 * ib_create_ah_from_wc - Creates an address handle associated with the 1830 * sender of the specified work completion. 1831 * @pd: The protection domain associated with the address handle. 1832 * @wc: Work completion information associated with a received message. 1833 * @grh: References the received global route header. This parameter is 1834 * ignored unless the work completion indicates that the GRH is valid. 1835 * @port_num: The outbound port number to associate with the address. 1836 * 1837 * The address handle is used to reference a local or global destination 1838 * in all UD QP post sends. 1839 */ 1840struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc, 1841 struct ib_grh *grh, u8 port_num); 1842 1843/** 1844 * ib_modify_ah - Modifies the address vector associated with an address 1845 * handle. 1846 * @ah: The address handle to modify. 1847 * @ah_attr: The new address vector attributes to associate with the 1848 * address handle. 1849 */ 1850int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr); 1851 1852/** 1853 * ib_query_ah - Queries the address vector associated with an address 1854 * handle. 1855 * @ah: The address handle to query. 1856 * @ah_attr: The address vector attributes associated with the address 1857 * handle. 1858 */ 1859int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr); 1860 1861/** 1862 * ib_destroy_ah - Destroys an address handle. 1863 * @ah: The address handle to destroy. 1864 */ 1865int ib_destroy_ah(struct ib_ah *ah); 1866 1867/** 1868 * ib_create_xrc_srq - Creates an XRC SRQ associated with the specified 1869 * protection domain, cq, and xrc domain. 1870 * @pd: The protection domain associated with the SRQ. 1871 * @xrc_cq: The cq to be associated with the XRC SRQ. 1872 * @xrcd: The XRC domain to be associated with the XRC SRQ. 1873 * @srq_init_attr: A list of initial attributes required to create the 1874 * XRC SRQ. If XRC SRQ creation succeeds, then the attributes are updated 1875 * to the actual capabilities of the created XRC SRQ. 1876 * 1877 * srq_attr->max_wr and srq_attr->max_sge are read the determine the 1878 * requested size of the XRC SRQ, and set to the actual values allocated 1879 * on return. If ib_create_xrc_srq() succeeds, then max_wr and max_sge 1880 * will always be at least as large as the requested values. 1881 */ 1882struct ib_srq *ib_create_xrc_srq(struct ib_pd *pd, 1883 struct ib_cq *xrc_cq, 1884 struct ib_xrcd *xrcd, 1885 struct ib_srq_init_attr *srq_init_attr); 1886 1887/** 1888 * ib_create_srq - Creates a SRQ associated with the specified protection 1889 * domain. 1890 * @pd: The protection domain associated with the SRQ. 1891 * @srq_init_attr: A list of initial attributes required to create the 1892 * SRQ. If SRQ creation succeeds, then the attributes are updated to 1893 * the actual capabilities of the created SRQ. 1894 * 1895 * srq_attr->max_wr and srq_attr->max_sge are read the determine the 1896 * requested size of the SRQ, and set to the actual values allocated 1897 * on return. If ib_create_srq() succeeds, then max_wr and max_sge 1898 * will always be at least as large as the requested values. 1899 */ 1900struct ib_srq *ib_create_srq(struct ib_pd *pd, 1901 struct ib_srq_init_attr *srq_init_attr); 1902 1903/** 1904 * ib_modify_srq - Modifies the attributes for the specified SRQ. 1905 * @srq: The SRQ to modify. 1906 * @srq_attr: On input, specifies the SRQ attributes to modify. On output, 1907 * the current values of selected SRQ attributes are returned. 1908 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ 1909 * are being modified. 1910 * 1911 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or 1912 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when 1913 * the number of receives queued drops below the limit. 1914 */ 1915int ib_modify_srq(struct ib_srq *srq, 1916 struct ib_srq_attr *srq_attr, 1917 enum ib_srq_attr_mask srq_attr_mask); 1918 1919/** 1920 * ib_query_srq - Returns the attribute list and current values for the 1921 * specified SRQ. 1922 * @srq: The SRQ to query. 1923 * @srq_attr: The attributes of the specified SRQ. 1924 */ 1925int ib_query_srq(struct ib_srq *srq, 1926 struct ib_srq_attr *srq_attr); 1927 1928/** 1929 * ib_destroy_srq - Destroys the specified SRQ. 1930 * @srq: The SRQ to destroy. 1931 */ 1932int ib_destroy_srq(struct ib_srq *srq); 1933 1934/** 1935 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ. 1936 * @srq: The SRQ to post the work request on. 1937 * @recv_wr: A list of work requests to post on the receive queue. 1938 * @bad_recv_wr: On an immediate failure, this parameter will reference 1939 * the work request that failed to be posted on the QP. 1940 */ 1941static inline int ib_post_srq_recv(struct ib_srq *srq, 1942 struct ib_recv_wr *recv_wr, 1943 struct ib_recv_wr **bad_recv_wr) 1944{ 1945 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr); 1946} 1947 1948/** 1949 * ib_create_qp - Creates a QP associated with the specified protection 1950 * domain. 1951 * @pd: The protection domain associated with the QP. 1952 * @qp_init_attr: A list of initial attributes required to create the 1953 * QP. If QP creation succeeds, then the attributes are updated to 1954 * the actual capabilities of the created QP. 1955 */ 1956struct ib_qp *ib_create_qp(struct ib_pd *pd, 1957 struct ib_qp_init_attr *qp_init_attr); 1958 1959/** 1960 * ib_modify_qp - Modifies the attributes for the specified QP and then 1961 * transitions the QP to the given state. 1962 * @qp: The QP to modify. 1963 * @qp_attr: On input, specifies the QP attributes to modify. On output, 1964 * the current values of selected QP attributes are returned. 1965 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP 1966 * are being modified. 1967 */ 1968int ib_modify_qp(struct ib_qp *qp, 1969 struct ib_qp_attr *qp_attr, 1970 int qp_attr_mask); 1971 1972/** 1973 * ib_query_qp - Returns the attribute list and current values for the 1974 * specified QP. 1975 * @qp: The QP to query. 1976 * @qp_attr: The attributes of the specified QP. 1977 * @qp_attr_mask: A bit-mask used to select specific attributes to query. 1978 * @qp_init_attr: Additional attributes of the selected QP. 1979 * 1980 * The qp_attr_mask may be used to limit the query to gathering only the 1981 * selected attributes. 1982 */ 1983int ib_query_qp(struct ib_qp *qp, 1984 struct ib_qp_attr *qp_attr, 1985 int qp_attr_mask, 1986 struct ib_qp_init_attr *qp_init_attr); 1987 1988/** 1989 * ib_destroy_qp - Destroys the specified QP. 1990 * @qp: The QP to destroy. 1991 */ 1992int ib_destroy_qp(struct ib_qp *qp); 1993 1994/** 1995 * ib_open_qp - Obtain a reference to an existing sharable QP. 1996 * @xrcd - XRC domain 1997 * @qp_open_attr: Attributes identifying the QP to open. 1998 * 1999 * Returns a reference to a sharable QP. 2000 */ 2001struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd, 2002 struct ib_qp_open_attr *qp_open_attr); 2003 2004/** 2005 * ib_close_qp - Release an external reference to a QP. 2006 * @qp: The QP handle to release 2007 * 2008 * The opened QP handle is released by the caller. The underlying 2009 * shared QP is not destroyed until all internal references are released. 2010 */ 2011int ib_close_qp(struct ib_qp *qp); 2012 2013/** 2014 * ib_post_send - Posts a list of work requests to the send queue of 2015 * the specified QP. 2016 * @qp: The QP to post the work request on. 2017 * @send_wr: A list of work requests to post on the send queue. 2018 * @bad_send_wr: On an immediate failure, this parameter will reference 2019 * the work request that failed to be posted on the QP. 2020 * 2021 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate 2022 * error is returned, the QP state shall not be affected, 2023 * ib_post_send() will return an immediate error after queueing any 2024 * earlier work requests in the list. 2025 */ 2026static inline int ib_post_send(struct ib_qp *qp, 2027 struct ib_send_wr *send_wr, 2028 struct ib_send_wr **bad_send_wr) 2029{ 2030 return qp->device->post_send(qp, send_wr, bad_send_wr); 2031} 2032 2033/** 2034 * ib_post_recv - Posts a list of work requests to the receive queue of 2035 * the specified QP. 2036 * @qp: The QP to post the work request on. 2037 * @recv_wr: A list of work requests to post on the receive queue. 2038 * @bad_recv_wr: On an immediate failure, this parameter will reference 2039 * the work request that failed to be posted on the QP. 2040 */ 2041static inline int ib_post_recv(struct ib_qp *qp, 2042 struct ib_recv_wr *recv_wr, 2043 struct ib_recv_wr **bad_recv_wr) 2044{ 2045 return qp->device->post_recv(qp, recv_wr, bad_recv_wr); 2046} 2047 2048/* 2049 * IB_CQ_VECTOR_LEAST_ATTACHED: The constant specifies that 2050 * the CQ will be attached to the completion vector that has 2051 * the least number of CQs already attached to it. 2052 */ 2053#define IB_CQ_VECTOR_LEAST_ATTACHED 0xffffffff 2054 2055/** 2056 * ib_create_cq - Creates a CQ on the specified device. 2057 * @device: The device on which to create the CQ. 2058 * @comp_handler: A user-specified callback that is invoked when a 2059 * completion event occurs on the CQ. 2060 * @event_handler: A user-specified callback that is invoked when an 2061 * asynchronous event not associated with a completion occurs on the CQ. 2062 * @cq_context: Context associated with the CQ returned to the user via 2063 * the associated completion and event handlers. 2064 * @cqe: The minimum size of the CQ. 2065 * @comp_vector - Completion vector used to signal completion events. 2066 * Must be >= 0 and < context->num_comp_vectors. 2067 * 2068 * Users can examine the cq structure to determine the actual CQ size. 2069 */ 2070struct ib_cq *ib_create_cq(struct ib_device *device, 2071 ib_comp_handler comp_handler, 2072 void (*event_handler)(struct ib_event *, void *), 2073 void *cq_context, int cqe, int comp_vector); 2074 2075/** 2076 * ib_resize_cq - Modifies the capacity of the CQ. 2077 * @cq: The CQ to resize. 2078 * @cqe: The minimum size of the CQ. 2079 * 2080 * Users can examine the cq structure to determine the actual CQ size. 2081 */ 2082int ib_resize_cq(struct ib_cq *cq, int cqe); 2083 2084/** 2085 * ib_modify_cq - Modifies moderation params of the CQ 2086 * @cq: The CQ to modify. 2087 * @cq_count: number of CQEs that will trigger an event 2088 * @cq_period: max period of time in usec before triggering an event 2089 * 2090 */ 2091int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period); 2092 2093/** 2094 * ib_destroy_cq - Destroys the specified CQ. 2095 * @cq: The CQ to destroy. 2096 */ 2097int ib_destroy_cq(struct ib_cq *cq); 2098 2099/** 2100 * ib_poll_cq - poll a CQ for completion(s) 2101 * @cq:the CQ being polled 2102 * @num_entries:maximum number of completions to return 2103 * @wc:array of at least @num_entries &struct ib_wc where completions 2104 * will be returned 2105 * 2106 * Poll a CQ for (possibly multiple) completions. If the return value 2107 * is < 0, an error occurred. If the return value is >= 0, it is the 2108 * number of completions returned. If the return value is 2109 * non-negative and < num_entries, then the CQ was emptied. 2110 */ 2111static inline int ib_poll_cq(struct ib_cq *cq, int num_entries, 2112 struct ib_wc *wc) 2113{ 2114 return cq->device->poll_cq(cq, num_entries, wc); 2115} 2116 2117/** 2118 * ib_peek_cq - Returns the number of unreaped completions currently 2119 * on the specified CQ. 2120 * @cq: The CQ to peek. 2121 * @wc_cnt: A minimum number of unreaped completions to check for. 2122 * 2123 * If the number of unreaped completions is greater than or equal to wc_cnt, 2124 * this function returns wc_cnt, otherwise, it returns the actual number of 2125 * unreaped completions. 2126 */ 2127int ib_peek_cq(struct ib_cq *cq, int wc_cnt); 2128 2129/** 2130 * ib_req_notify_cq - Request completion notification on a CQ. 2131 * @cq: The CQ to generate an event for. 2132 * @flags: 2133 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP 2134 * to request an event on the next solicited event or next work 2135 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS 2136 * may also be |ed in to request a hint about missed events, as 2137 * described below. 2138 * 2139 * Return Value: 2140 * < 0 means an error occurred while requesting notification 2141 * == 0 means notification was requested successfully, and if 2142 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events 2143 * were missed and it is safe to wait for another event. In 2144 * this case is it guaranteed that any work completions added 2145 * to the CQ since the last CQ poll will trigger a completion 2146 * notification event. 2147 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed 2148 * in. It means that the consumer must poll the CQ again to 2149 * make sure it is empty to avoid missing an event because of a 2150 * race between requesting notification and an entry being 2151 * added to the CQ. This return value means it is possible 2152 * (but not guaranteed) that a work completion has been added 2153 * to the CQ since the last poll without triggering a 2154 * completion notification event. 2155 */ 2156static inline int ib_req_notify_cq(struct ib_cq *cq, 2157 enum ib_cq_notify_flags flags) 2158{ 2159 return cq->device->req_notify_cq(cq, flags); 2160} 2161 2162/** 2163 * ib_req_ncomp_notif - Request completion notification when there are 2164 * at least the specified number of unreaped completions on the CQ. 2165 * @cq: The CQ to generate an event for. 2166 * @wc_cnt: The number of unreaped completions that should be on the 2167 * CQ before an event is generated. 2168 */ 2169static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt) 2170{ 2171 return cq->device->req_ncomp_notif ? 2172 cq->device->req_ncomp_notif(cq, wc_cnt) : 2173 -ENOSYS; 2174} 2175 2176/** 2177 * ib_get_dma_mr - Returns a memory region for system memory that is 2178 * usable for DMA. 2179 * @pd: The protection domain associated with the memory region. 2180 * @mr_access_flags: Specifies the memory access rights. 2181 * 2182 * Note that the ib_dma_*() functions defined below must be used 2183 * to create/destroy addresses used with the Lkey or Rkey returned 2184 * by ib_get_dma_mr(). 2185 */ 2186struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags); 2187 2188/** 2189 * ib_dma_mapping_error - check a DMA addr for error 2190 * @dev: The device for which the dma_addr was created 2191 * @dma_addr: The DMA address to check 2192 */ 2193static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr) 2194{ 2195 if (dev->dma_ops) 2196 return dev->dma_ops->mapping_error(dev, dma_addr); 2197 return dma_mapping_error(dev->dma_device, dma_addr); 2198} 2199 2200/** 2201 * ib_dma_map_single - Map a kernel virtual address to DMA address 2202 * @dev: The device for which the dma_addr is to be created 2203 * @cpu_addr: The kernel virtual address 2204 * @size: The size of the region in bytes 2205 * @direction: The direction of the DMA 2206 */ 2207static inline u64 ib_dma_map_single(struct ib_device *dev, 2208 void *cpu_addr, size_t size, 2209 enum dma_data_direction direction) 2210{ 2211 if (dev->dma_ops) 2212 return dev->dma_ops->map_single(dev, cpu_addr, size, direction); 2213 return dma_map_single(dev->dma_device, cpu_addr, size, direction); 2214} 2215 2216/** 2217 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single() 2218 * @dev: The device for which the DMA address was created 2219 * @addr: The DMA address 2220 * @size: The size of the region in bytes 2221 * @direction: The direction of the DMA 2222 */ 2223static inline void ib_dma_unmap_single(struct ib_device *dev, 2224 u64 addr, size_t size, 2225 enum dma_data_direction direction) 2226{ 2227 if (dev->dma_ops) 2228 dev->dma_ops->unmap_single(dev, addr, size, direction); 2229 else 2230 dma_unmap_single(dev->dma_device, addr, size, direction); 2231} 2232 2233static inline u64 ib_dma_map_single_attrs(struct ib_device *dev, 2234 void *cpu_addr, size_t size, 2235 enum dma_data_direction direction, 2236 struct dma_attrs *attrs) 2237{ 2238 return dma_map_single_attrs(dev->dma_device, cpu_addr, size, 2239 direction, attrs); 2240} 2241 2242static inline void ib_dma_unmap_single_attrs(struct ib_device *dev, 2243 u64 addr, size_t size, 2244 enum dma_data_direction direction, 2245 struct dma_attrs *attrs) 2246{ 2247 return dma_unmap_single_attrs(dev->dma_device, addr, size, 2248 direction, attrs); 2249} 2250 2251/** 2252 * ib_dma_map_page - Map a physical page to DMA address 2253 * @dev: The device for which the dma_addr is to be created 2254 * @page: The page to be mapped 2255 * @offset: The offset within the page 2256 * @size: The size of the region in bytes 2257 * @direction: The direction of the DMA 2258 */ 2259static inline u64 ib_dma_map_page(struct ib_device *dev, 2260 struct page *page, 2261 unsigned long offset, 2262 size_t size, 2263 enum dma_data_direction direction) 2264{ 2265 if (dev->dma_ops) 2266 return dev->dma_ops->map_page(dev, page, offset, size, direction); 2267 return dma_map_page(dev->dma_device, page, offset, size, direction); 2268} 2269 2270/** 2271 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page() 2272 * @dev: The device for which the DMA address was created 2273 * @addr: The DMA address 2274 * @size: The size of the region in bytes 2275 * @direction: The direction of the DMA 2276 */ 2277static inline void ib_dma_unmap_page(struct ib_device *dev, 2278 u64 addr, size_t size, 2279 enum dma_data_direction direction) 2280{ 2281 if (dev->dma_ops) 2282 dev->dma_ops->unmap_page(dev, addr, size, direction); 2283 else 2284 dma_unmap_page(dev->dma_device, addr, size, direction); 2285} 2286 2287/** 2288 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses 2289 * @dev: The device for which the DMA addresses are to be created 2290 * @sg: The array of scatter/gather entries 2291 * @nents: The number of scatter/gather entries 2292 * @direction: The direction of the DMA 2293 */ 2294static inline int ib_dma_map_sg(struct ib_device *dev, 2295 struct scatterlist *sg, int nents, 2296 enum dma_data_direction direction) 2297{ 2298 if (dev->dma_ops) 2299 return dev->dma_ops->map_sg(dev, sg, nents, direction); 2300 return dma_map_sg(dev->dma_device, sg, nents, direction); 2301} 2302 2303/** 2304 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses 2305 * @dev: The device for which the DMA addresses were created 2306 * @sg: The array of scatter/gather entries 2307 * @nents: The number of scatter/gather entries 2308 * @direction: The direction of the DMA 2309 */ 2310static inline void ib_dma_unmap_sg(struct ib_device *dev, 2311 struct scatterlist *sg, int nents, 2312 enum dma_data_direction direction) 2313{ 2314 if (dev->dma_ops) 2315 dev->dma_ops->unmap_sg(dev, sg, nents, direction); 2316 else 2317 dma_unmap_sg(dev->dma_device, sg, nents, direction); 2318} 2319 2320static inline int ib_dma_map_sg_attrs(struct ib_device *dev, 2321 struct scatterlist *sg, int nents, 2322 enum dma_data_direction direction, 2323 struct dma_attrs *attrs) 2324{ 2325 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs); 2326} 2327 2328static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev, 2329 struct scatterlist *sg, int nents, 2330 enum dma_data_direction direction, 2331 struct dma_attrs *attrs) 2332{ 2333 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs); 2334} 2335/** 2336 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry 2337 * @dev: The device for which the DMA addresses were created 2338 * @sg: The scatter/gather entry 2339 */ 2340static inline u64 ib_sg_dma_address(struct ib_device *dev, 2341 struct scatterlist *sg) 2342{ 2343 if (dev->dma_ops) 2344 return dev->dma_ops->dma_address(dev, sg); 2345 return sg_dma_address(sg); 2346} 2347 2348/** 2349 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry 2350 * @dev: The device for which the DMA addresses were created 2351 * @sg: The scatter/gather entry 2352 */ 2353static inline unsigned int ib_sg_dma_len(struct ib_device *dev, 2354 struct scatterlist *sg) 2355{ 2356 if (dev->dma_ops) 2357 return dev->dma_ops->dma_len(dev, sg); 2358 return sg_dma_len(sg); 2359} 2360 2361/** 2362 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU 2363 * @dev: The device for which the DMA address was created 2364 * @addr: The DMA address 2365 * @size: The size of the region in bytes 2366 * @dir: The direction of the DMA 2367 */ 2368static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev, 2369 u64 addr, 2370 size_t size, 2371 enum dma_data_direction dir) 2372{ 2373 if (dev->dma_ops) 2374 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir); 2375 else 2376 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir); 2377} 2378 2379/** 2380 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device 2381 * @dev: The device for which the DMA address was created 2382 * @addr: The DMA address 2383 * @size: The size of the region in bytes 2384 * @dir: The direction of the DMA 2385 */ 2386static inline void ib_dma_sync_single_for_device(struct ib_device *dev, 2387 u64 addr, 2388 size_t size, 2389 enum dma_data_direction dir) 2390{ 2391 if (dev->dma_ops) 2392 dev->dma_ops->sync_single_for_device(dev, addr, size, dir); 2393 else 2394 dma_sync_single_for_device(dev->dma_device, addr, size, dir); 2395} 2396 2397/** 2398 * ib_dma_alloc_coherent - Allocate memory and map it for DMA 2399 * @dev: The device for which the DMA address is requested 2400 * @size: The size of the region to allocate in bytes 2401 * @dma_handle: A pointer for returning the DMA address of the region 2402 * @flag: memory allocator flags 2403 */ 2404static inline void *ib_dma_alloc_coherent(struct ib_device *dev, 2405 size_t size, 2406 u64 *dma_handle, 2407 gfp_t flag) 2408{ 2409 if (dev->dma_ops) 2410 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag); 2411 else { 2412 dma_addr_t handle; 2413 void *ret; 2414 2415 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag); 2416 *dma_handle = handle; 2417 return ret; 2418 } 2419} 2420 2421/** 2422 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent() 2423 * @dev: The device for which the DMA addresses were allocated 2424 * @size: The size of the region 2425 * @cpu_addr: the address returned by ib_dma_alloc_coherent() 2426 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent() 2427 */ 2428static inline void ib_dma_free_coherent(struct ib_device *dev, 2429 size_t size, void *cpu_addr, 2430 u64 dma_handle) 2431{ 2432 if (dev->dma_ops) 2433 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle); 2434 else 2435 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle); 2436} 2437 2438/** 2439 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use 2440 * by an HCA. 2441 * @pd: The protection domain associated assigned to the registered region. 2442 * @phys_buf_array: Specifies a list of physical buffers to use in the 2443 * memory region. 2444 * @num_phys_buf: Specifies the size of the phys_buf_array. 2445 * @mr_access_flags: Specifies the memory access rights. 2446 * @iova_start: The offset of the region's starting I/O virtual address. 2447 */ 2448struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd, 2449 struct ib_phys_buf *phys_buf_array, 2450 int num_phys_buf, 2451 int mr_access_flags, 2452 u64 *iova_start); 2453 2454/** 2455 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region. 2456 * Conceptually, this call performs the functions deregister memory region 2457 * followed by register physical memory region. Where possible, 2458 * resources are reused instead of deallocated and reallocated. 2459 * @mr: The memory region to modify. 2460 * @mr_rereg_mask: A bit-mask used to indicate which of the following 2461 * properties of the memory region are being modified. 2462 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies 2463 * the new protection domain to associated with the memory region, 2464 * otherwise, this parameter is ignored. 2465 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this 2466 * field specifies a list of physical buffers to use in the new 2467 * translation, otherwise, this parameter is ignored. 2468 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this 2469 * field specifies the size of the phys_buf_array, otherwise, this 2470 * parameter is ignored. 2471 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this 2472 * field specifies the new memory access rights, otherwise, this 2473 * parameter is ignored. 2474 * @iova_start: The offset of the region's starting I/O virtual address. 2475 */ 2476int ib_rereg_phys_mr(struct ib_mr *mr, 2477 int mr_rereg_mask, 2478 struct ib_pd *pd, 2479 struct ib_phys_buf *phys_buf_array, 2480 int num_phys_buf, 2481 int mr_access_flags, 2482 u64 *iova_start); 2483 2484/** 2485 * ib_query_mr - Retrieves information about a specific memory region. 2486 * @mr: The memory region to retrieve information about. 2487 * @mr_attr: The attributes of the specified memory region. 2488 */ 2489int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr); 2490 2491/** 2492 * ib_dereg_mr - Deregisters a memory region and removes it from the 2493 * HCA translation table. 2494 * @mr: The memory region to deregister. 2495 */ 2496int ib_dereg_mr(struct ib_mr *mr); 2497 2498/** 2499 * ib_alloc_fast_reg_mr - Allocates memory region usable with the 2500 * IB_WR_FAST_REG_MR send work request. 2501 * @pd: The protection domain associated with the region. 2502 * @max_page_list_len: requested max physical buffer list length to be 2503 * used with fast register work requests for this MR. 2504 */ 2505struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len); 2506 2507/** 2508 * ib_alloc_fast_reg_page_list - Allocates a page list array 2509 * @device - ib device pointer. 2510 * @page_list_len - size of the page list array to be allocated. 2511 * 2512 * This allocates and returns a struct ib_fast_reg_page_list * and a 2513 * page_list array that is at least page_list_len in size. The actual 2514 * size is returned in max_page_list_len. The caller is responsible 2515 * for initializing the contents of the page_list array before posting 2516 * a send work request with the IB_WC_FAST_REG_MR opcode. 2517 * 2518 * The page_list array entries must be translated using one of the 2519 * ib_dma_*() functions just like the addresses passed to 2520 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct 2521 * ib_fast_reg_page_list must not be modified by the caller until the 2522 * IB_WC_FAST_REG_MR work request completes. 2523 */ 2524struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list( 2525 struct ib_device *device, int page_list_len); 2526 2527/** 2528 * ib_free_fast_reg_page_list - Deallocates a previously allocated 2529 * page list array. 2530 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated. 2531 */ 2532void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list); 2533 2534/** 2535 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR 2536 * R_Key and L_Key. 2537 * @mr - struct ib_mr pointer to be updated. 2538 * @newkey - new key to be used. 2539 */ 2540static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey) 2541{ 2542 mr->lkey = (mr->lkey & 0xffffff00) | newkey; 2543 mr->rkey = (mr->rkey & 0xffffff00) | newkey; 2544} 2545 2546/** 2547 * ib_alloc_mw - Allocates a memory window. 2548 * @pd: The protection domain associated with the memory window. 2549 */ 2550struct ib_mw *ib_alloc_mw(struct ib_pd *pd); 2551 2552/** 2553 * ib_bind_mw - Posts a work request to the send queue of the specified 2554 * QP, which binds the memory window to the given address range and 2555 * remote access attributes. 2556 * @qp: QP to post the bind work request on. 2557 * @mw: The memory window to bind. 2558 * @mw_bind: Specifies information about the memory window, including 2559 * its address range, remote access rights, and associated memory region. 2560 */ 2561static inline int ib_bind_mw(struct ib_qp *qp, 2562 struct ib_mw *mw, 2563 struct ib_mw_bind *mw_bind) 2564{ 2565 /* XXX reference counting in corresponding MR? */ 2566 return mw->device->bind_mw ? 2567 mw->device->bind_mw(qp, mw, mw_bind) : 2568 -ENOSYS; 2569} 2570 2571/** 2572 * ib_dealloc_mw - Deallocates a memory window. 2573 * @mw: The memory window to deallocate. 2574 */ 2575int ib_dealloc_mw(struct ib_mw *mw); 2576 2577/** 2578 * ib_alloc_fmr - Allocates a unmapped fast memory region. 2579 * @pd: The protection domain associated with the unmapped region. 2580 * @mr_access_flags: Specifies the memory access rights. 2581 * @fmr_attr: Attributes of the unmapped region. 2582 * 2583 * A fast memory region must be mapped before it can be used as part of 2584 * a work request. 2585 */ 2586struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd, 2587 int mr_access_flags, 2588 struct ib_fmr_attr *fmr_attr); 2589 2590/** 2591 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region. 2592 * @fmr: The fast memory region to associate with the pages. 2593 * @page_list: An array of physical pages to map to the fast memory region. 2594 * @list_len: The number of pages in page_list. 2595 * @iova: The I/O virtual address to use with the mapped region. 2596 */ 2597static inline int ib_map_phys_fmr(struct ib_fmr *fmr, 2598 u64 *page_list, int list_len, 2599 u64 iova) 2600{ 2601 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova); 2602} 2603 2604/** 2605 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions. 2606 * @fmr_list: A linked list of fast memory regions to unmap. 2607 */ 2608int ib_unmap_fmr(struct list_head *fmr_list); 2609 2610/** 2611 * ib_dealloc_fmr - Deallocates a fast memory region. 2612 * @fmr: The fast memory region to deallocate. 2613 */ 2614int ib_dealloc_fmr(struct ib_fmr *fmr); 2615 2616/** 2617 * ib_attach_mcast - Attaches the specified QP to a multicast group. 2618 * @qp: QP to attach to the multicast group. The QP must be type 2619 * IB_QPT_UD. 2620 * @gid: Multicast group GID. 2621 * @lid: Multicast group LID in host byte order. 2622 * 2623 * In order to send and receive multicast packets, subnet 2624 * administration must have created the multicast group and configured 2625 * the fabric appropriately. The port associated with the specified 2626 * QP must also be a member of the multicast group. 2627 */ 2628int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); 2629 2630/** 2631 * ib_detach_mcast - Detaches the specified QP from a multicast group. 2632 * @qp: QP to detach from the multicast group. 2633 * @gid: Multicast group GID. 2634 * @lid: Multicast group LID in host byte order. 2635 */ 2636int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); 2637 2638/** 2639 * ib_alloc_xrcd - Allocates an XRC domain. 2640 * @device: The device on which to allocate the XRC domain. 2641 */ 2642struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device); 2643 2644/** 2645 * ib_dealloc_xrcd - Deallocates an XRC domain. 2646 * @xrcd: The XRC domain to deallocate. 2647 */ 2648int ib_dealloc_xrcd(struct ib_xrcd *xrcd); 2649 2650int ib_attach_flow(struct ib_qp *qp, struct ib_flow_spec *spec, int priority); 2651int ib_detach_flow(struct ib_qp *qp, struct ib_flow_spec *spec, int priority); 2652 2653#endif /* IB_VERBS_H */ 2654