2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2004 Intel Corporation. All rights reserved.
4 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #ifndef INFINIBAND_VERBS_H
37 #define INFINIBAND_VERBS_H
43 # define BEGIN_C_DECLS extern "C" {
44 # define END_C_DECLS }
45 #else /* !__cplusplus */
46 # define BEGIN_C_DECLS
48 #endif /* __cplusplus */
51 # define __attribute_const __attribute__((const))
53 # define __attribute_const
61 uint64_t subnet_prefix;
62 uint64_t interface_id;
67 IBV_NODE_UNKNOWN = -1,
74 enum ibv_transport_type {
75 IBV_TRANSPORT_UNKNOWN = -1,
80 enum ibv_device_cap_flags {
81 IBV_DEVICE_RESIZE_MAX_WR = 1,
82 IBV_DEVICE_BAD_PKEY_CNTR = 1 << 1,
83 IBV_DEVICE_BAD_QKEY_CNTR = 1 << 2,
84 IBV_DEVICE_RAW_MULTI = 1 << 3,
85 IBV_DEVICE_AUTO_PATH_MIG = 1 << 4,
86 IBV_DEVICE_CHANGE_PHY_PORT = 1 << 5,
87 IBV_DEVICE_UD_AV_PORT_ENFORCE = 1 << 6,
88 IBV_DEVICE_CURR_QP_STATE_MOD = 1 << 7,
89 IBV_DEVICE_SHUTDOWN_PORT = 1 << 8,
90 IBV_DEVICE_INIT_TYPE = 1 << 9,
91 IBV_DEVICE_PORT_ACTIVE_EVENT = 1 << 10,
92 IBV_DEVICE_SYS_IMAGE_GUID = 1 << 11,
93 IBV_DEVICE_RC_RNR_NAK_GEN = 1 << 12,
94 IBV_DEVICE_SRQ_RESIZE = 1 << 13,
95 IBV_DEVICE_N_NOTIFY_CQ = 1 << 14,
96 IBV_DEVICE_XRC = 1 << 20
105 struct ibv_device_attr {
108 uint64_t sys_image_guid;
109 uint64_t max_mr_size;
110 uint64_t page_size_cap;
112 uint32_t vendor_part_id;
116 int device_cap_flags;
126 int max_qp_init_rd_atom;
127 int max_ee_init_rd_atom;
128 enum ibv_atomic_cap atomic_cap;
135 int max_mcast_qp_attach;
136 int max_total_mcast_qp_attach;
144 uint8_t local_ca_ack_delay;
145 uint8_t phys_port_cnt;
156 enum ibv_port_state {
162 IBV_PORT_ACTIVE_DEFER = 5
166 IBV_LINK_LAYER_UNSPECIFIED,
167 IBV_LINK_LAYER_INFINIBAND,
168 IBV_LINK_LAYER_ETHERNET,
171 struct ibv_port_attr {
172 enum ibv_port_state state;
173 enum ibv_mtu max_mtu;
174 enum ibv_mtu active_mtu;
176 uint32_t port_cap_flags;
178 uint32_t bad_pkey_cntr;
179 uint32_t qkey_viol_cntr;
180 uint16_t pkey_tbl_len;
186 uint8_t subnet_timeout;
187 uint8_t init_type_reply;
188 uint8_t active_width;
189 uint8_t active_speed;
195 enum ibv_event_type {
198 IBV_EVENT_QP_REQ_ERR,
199 IBV_EVENT_QP_ACCESS_ERR,
201 IBV_EVENT_SQ_DRAINED,
203 IBV_EVENT_PATH_MIG_ERR,
204 IBV_EVENT_DEVICE_FATAL,
205 IBV_EVENT_PORT_ACTIVE,
207 IBV_EVENT_LID_CHANGE,
208 IBV_EVENT_PKEY_CHANGE,
211 IBV_EVENT_SRQ_LIMIT_REACHED,
212 IBV_EVENT_QP_LAST_WQE_REACHED,
213 IBV_EVENT_CLIENT_REREGISTER,
214 IBV_EVENT_GID_CHANGE,
217 enum ibv_event_flags {
218 IBV_XRC_QP_EVENT_FLAG = 0x80000000,
221 struct ibv_async_event {
229 enum ibv_event_type event_type;
235 IBV_WC_LOC_QP_OP_ERR,
236 IBV_WC_LOC_EEC_OP_ERR,
241 IBV_WC_LOC_ACCESS_ERR,
242 IBV_WC_REM_INV_REQ_ERR,
243 IBV_WC_REM_ACCESS_ERR,
245 IBV_WC_RETRY_EXC_ERR,
246 IBV_WC_RNR_RETRY_EXC_ERR,
247 IBV_WC_LOC_RDD_VIOL_ERR,
248 IBV_WC_REM_INV_RD_REQ_ERR,
249 IBV_WC_REM_ABORT_ERR,
251 IBV_WC_INV_EEC_STATE_ERR,
253 IBV_WC_RESP_TIMEOUT_ERR,
256 const char *ibv_wc_status_str(enum ibv_wc_status status);
266 * Set value of IBV_WC_RECV so consumers can test if a completion is a
267 * receive by testing (opcode & IBV_WC_RECV).
269 IBV_WC_RECV = 1 << 7,
270 IBV_WC_RECV_RDMA_WITH_IMM
275 IBV_WC_WITH_IMM = 1 << 1
280 enum ibv_wc_status status;
281 enum ibv_wc_opcode opcode;
284 uint32_t imm_data; /* in network byte order */
291 uint8_t dlid_path_bits;
294 enum ibv_access_flags {
295 IBV_ACCESS_LOCAL_WRITE = 1,
296 IBV_ACCESS_REMOTE_WRITE = (1<<1),
297 IBV_ACCESS_REMOTE_READ = (1<<2),
298 IBV_ACCESS_REMOTE_ATOMIC = (1<<3),
299 IBV_ACCESS_MW_BIND = (1<<4)
303 struct ibv_context *context;
307 enum ibv_rereg_mr_flags {
308 IBV_REREG_MR_CHANGE_TRANSLATION = (1 << 0),
309 IBV_REREG_MR_CHANGE_PD = (1 << 1),
310 IBV_REREG_MR_CHANGE_ACCESS = (1 << 2),
311 IBV_REREG_MR_KEEP_VALID = (1 << 3)
315 struct ibv_context *context;
330 struct ibv_context *context;
335 struct ibv_global_route {
340 uint8_t traffic_class;
344 uint32_t version_tclass_flow;
354 IBV_RATE_2_5_GBPS = 2,
356 IBV_RATE_10_GBPS = 3,
357 IBV_RATE_20_GBPS = 6,
358 IBV_RATE_30_GBPS = 4,
359 IBV_RATE_40_GBPS = 7,
360 IBV_RATE_60_GBPS = 8,
361 IBV_RATE_80_GBPS = 9,
362 IBV_RATE_120_GBPS = 10
366 * ibv_rate_to_mult - Convert the IB rate enum to a multiple of the
367 * base rate of 2.5 Gbit/sec. For example, IBV_RATE_5_GBPS will be
368 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
369 * @rate: rate to convert.
371 int ibv_rate_to_mult(enum ibv_rate rate) __attribute_const;
374 * mult_to_ibv_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate enum.
375 * @mult: multiple to convert.
377 enum ibv_rate mult_to_ibv_rate(int mult) __attribute_const;
380 struct ibv_global_route grh;
383 uint8_t src_path_bits;
389 struct ibv_xrc_domain {
390 struct ibv_context *context;
394 enum ibv_srq_attr_mask {
395 IBV_SRQ_MAX_WR = 1 << 0,
396 IBV_SRQ_LIMIT = 1 << 1
399 struct ibv_srq_attr {
405 struct ibv_srq_init_attr {
407 struct ibv_srq_attr attr;
419 uint32_t max_send_wr;
420 uint32_t max_recv_wr;
421 uint32_t max_send_sge;
422 uint32_t max_recv_sge;
423 uint32_t max_inline_data;
426 struct ibv_qp_init_attr {
428 struct ibv_cq *send_cq;
429 struct ibv_cq *recv_cq;
431 struct ibv_qp_cap cap;
432 enum ibv_qp_type qp_type;
434 struct ibv_xrc_domain *xrc_domain;
437 enum ibv_qp_attr_mask {
438 IBV_QP_STATE = 1 << 0,
439 IBV_QP_CUR_STATE = 1 << 1,
440 IBV_QP_EN_SQD_ASYNC_NOTIFY = 1 << 2,
441 IBV_QP_ACCESS_FLAGS = 1 << 3,
442 IBV_QP_PKEY_INDEX = 1 << 4,
443 IBV_QP_PORT = 1 << 5,
444 IBV_QP_QKEY = 1 << 6,
446 IBV_QP_PATH_MTU = 1 << 8,
447 IBV_QP_TIMEOUT = 1 << 9,
448 IBV_QP_RETRY_CNT = 1 << 10,
449 IBV_QP_RNR_RETRY = 1 << 11,
450 IBV_QP_RQ_PSN = 1 << 12,
451 IBV_QP_MAX_QP_RD_ATOMIC = 1 << 13,
452 IBV_QP_ALT_PATH = 1 << 14,
453 IBV_QP_MIN_RNR_TIMER = 1 << 15,
454 IBV_QP_SQ_PSN = 1 << 16,
455 IBV_QP_MAX_DEST_RD_ATOMIC = 1 << 17,
456 IBV_QP_PATH_MIG_STATE = 1 << 18,
457 IBV_QP_CAP = 1 << 19,
458 IBV_QP_DEST_QPN = 1 << 20
478 enum ibv_qp_state qp_state;
479 enum ibv_qp_state cur_qp_state;
480 enum ibv_mtu path_mtu;
481 enum ibv_mig_state path_mig_state;
485 uint32_t dest_qp_num;
487 struct ibv_qp_cap cap;
488 struct ibv_ah_attr ah_attr;
489 struct ibv_ah_attr alt_ah_attr;
491 uint16_t alt_pkey_index;
492 uint8_t en_sqd_async_notify;
494 uint8_t max_rd_atomic;
495 uint8_t max_dest_rd_atomic;
496 uint8_t min_rnr_timer;
501 uint8_t alt_port_num;
507 IBV_WR_RDMA_WRITE_WITH_IMM,
509 IBV_WR_SEND_WITH_IMM,
511 IBV_WR_ATOMIC_CMP_AND_SWP,
512 IBV_WR_ATOMIC_FETCH_AND_ADD
515 enum ibv_send_flags {
516 IBV_SEND_FENCE = 1 << 0,
517 IBV_SEND_SIGNALED = 1 << 1,
518 IBV_SEND_SOLICITED = 1 << 2,
519 IBV_SEND_INLINE = 1 << 3
530 struct ibv_send_wr *next;
531 struct ibv_sge *sg_list;
533 enum ibv_wr_opcode opcode;
535 uint32_t imm_data; /* in network byte order */
538 uint64_t remote_addr;
542 uint64_t remote_addr;
543 uint64_t compare_add;
550 uint32_t remote_qkey;
553 uint32_t xrc_remote_srq_num;
558 struct ibv_recv_wr *next;
559 struct ibv_sge *sg_list;
573 struct ibv_context *context;
578 uint32_t events_completed;
580 uint32_t xrc_srq_num;
581 struct ibv_xrc_domain *xrc_domain;
582 struct ibv_cq *xrc_cq;
584 pthread_mutex_t mutex;
589 struct ibv_context *context;
592 struct ibv_cq *send_cq;
593 struct ibv_cq *recv_cq;
597 enum ibv_qp_state state;
598 enum ibv_qp_type qp_type;
600 uint32_t events_completed;
602 struct ibv_xrc_domain *xrc_domain;
604 pthread_mutex_t mutex;
608 struct ibv_comp_channel {
609 struct ibv_context *context;
615 struct ibv_context *context;
616 struct ibv_comp_channel *channel;
621 uint32_t comp_events_completed;
622 uint32_t async_events_completed;
624 pthread_mutex_t mutex;
629 struct ibv_context *context;
637 struct ibv_device_ops {
638 struct ibv_context * (*alloc_context)(struct ibv_device *device, int cmd_fd);
639 void (*free_context)(struct ibv_context *context);
643 IBV_SYSFS_NAME_MAX = 64,
644 IBV_SYSFS_PATH_MAX = 256
648 struct ibv_device_ops ops;
649 enum ibv_node_type node_type;
650 enum ibv_transport_type transport_type;
651 /* Name of underlying kernel IB device, eg "mthca0" */
652 char name[IBV_SYSFS_NAME_MAX];
653 /* Name of uverbs device, eg "uverbs0" */
654 char dev_name[IBV_SYSFS_NAME_MAX];
655 /* Path to infiniband_verbs class device in sysfs */
656 char dev_path[IBV_SYSFS_PATH_MAX];
657 /* Path to infiniband class device in sysfs */
658 char ibdev_path[IBV_SYSFS_PATH_MAX];
661 struct ibv_more_ops {
662 struct ibv_srq * (*create_xrc_srq)(struct ibv_pd *pd,
663 struct ibv_xrc_domain *xrc_domain,
664 struct ibv_cq *xrc_cq,
665 struct ibv_srq_init_attr *srq_init_attr);
666 struct ibv_xrc_domain * (*open_xrc_domain)(struct ibv_context *context,
668 int (*close_xrc_domain)(struct ibv_xrc_domain *d);
669 int (*create_xrc_rcv_qp)(struct ibv_qp_init_attr *init_attr,
670 uint32_t *xrc_qp_num);
671 int (*modify_xrc_rcv_qp)(struct ibv_xrc_domain *xrc_domain,
673 struct ibv_qp_attr *attr,
675 int (*query_xrc_rcv_qp)(struct ibv_xrc_domain *xrc_domain,
677 struct ibv_qp_attr *attr,
679 struct ibv_qp_init_attr *init_attr);
680 int (*reg_xrc_rcv_qp)(struct ibv_xrc_domain *xrc_domain,
681 uint32_t xrc_qp_num);
682 int (*unreg_xrc_rcv_qp)(struct ibv_xrc_domain *xrc_domain,
683 uint32_t xrc_qp_num);
687 struct ibv_context_ops {
688 int (*query_device)(struct ibv_context *context,
689 struct ibv_device_attr *device_attr);
690 int (*query_port)(struct ibv_context *context, uint8_t port_num,
691 struct ibv_port_attr *port_attr);
692 struct ibv_pd * (*alloc_pd)(struct ibv_context *context);
693 int (*dealloc_pd)(struct ibv_pd *pd);
694 struct ibv_mr * (*reg_mr)(struct ibv_pd *pd, void *addr, size_t length,
696 struct ibv_mr * (*rereg_mr)(struct ibv_mr *mr,
698 struct ibv_pd *pd, void *addr,
701 int (*dereg_mr)(struct ibv_mr *mr);
702 struct ibv_mw * (*alloc_mw)(struct ibv_pd *pd, enum ibv_mw_type type);
703 int (*bind_mw)(struct ibv_qp *qp, struct ibv_mw *mw,
704 struct ibv_mw_bind *mw_bind);
705 int (*dealloc_mw)(struct ibv_mw *mw);
706 struct ibv_cq * (*create_cq)(struct ibv_context *context, int cqe,
707 struct ibv_comp_channel *channel,
709 int (*poll_cq)(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc);
710 int (*req_notify_cq)(struct ibv_cq *cq, int solicited_only);
711 void (*cq_event)(struct ibv_cq *cq);
712 int (*resize_cq)(struct ibv_cq *cq, int cqe);
713 int (*destroy_cq)(struct ibv_cq *cq);
714 struct ibv_srq * (*create_srq)(struct ibv_pd *pd,
715 struct ibv_srq_init_attr *srq_init_attr);
716 int (*modify_srq)(struct ibv_srq *srq,
717 struct ibv_srq_attr *srq_attr,
719 int (*query_srq)(struct ibv_srq *srq,
720 struct ibv_srq_attr *srq_attr);
721 int (*destroy_srq)(struct ibv_srq *srq);
722 int (*post_srq_recv)(struct ibv_srq *srq,
723 struct ibv_recv_wr *recv_wr,
724 struct ibv_recv_wr **bad_recv_wr);
725 struct ibv_qp * (*create_qp)(struct ibv_pd *pd, struct ibv_qp_init_attr *attr);
726 int (*query_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
728 struct ibv_qp_init_attr *init_attr);
729 int (*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
731 int (*destroy_qp)(struct ibv_qp *qp);
732 int (*post_send)(struct ibv_qp *qp, struct ibv_send_wr *wr,
733 struct ibv_send_wr **bad_wr);
734 int (*post_recv)(struct ibv_qp *qp, struct ibv_recv_wr *wr,
735 struct ibv_recv_wr **bad_wr);
736 struct ibv_ah * (*create_ah)(struct ibv_pd *pd, struct ibv_ah_attr *attr);
737 int (*destroy_ah)(struct ibv_ah *ah);
738 int (*attach_mcast)(struct ibv_qp *qp, const union ibv_gid *gid,
740 int (*detach_mcast)(struct ibv_qp *qp, const union ibv_gid *gid,
742 void (*async_event)(struct ibv_async_event *event);
746 struct ibv_device *device;
747 struct ibv_context_ops ops;
750 int num_comp_vectors;
751 pthread_mutex_t mutex;
753 struct ibv_more_ops *more_ops;
756 static inline int ___ibv_query_port(struct ibv_context *context,
758 struct ibv_port_attr *port_attr)
760 port_attr->link_layer = IBV_LINK_LAYER_UNSPECIFIED;
763 return context->ops.query_port(context, port_num, port_attr);
767 * ibv_get_device_list - Get list of IB devices currently available
768 * @num_devices: optional. if non-NULL, set to the number of devices
769 * returned in the array.
771 * Return a NULL-terminated array of IB devices. The array can be
772 * released with ibv_free_device_list().
774 struct ibv_device **ibv_get_device_list(int *num_devices);
777 * ibv_free_device_list - Free list from ibv_get_device_list()
779 * Free an array of devices returned from ibv_get_device_list(). Once
780 * the array is freed, pointers to devices that were not opened with
781 * ibv_open_device() are no longer valid. Client code must open all
782 * devices it intends to use before calling ibv_free_device_list().
784 void ibv_free_device_list(struct ibv_device **list);
787 * ibv_get_device_name - Return kernel device name
789 const char *ibv_get_device_name(struct ibv_device *device);
792 * ibv_get_device_guid - Return device's node GUID
794 uint64_t ibv_get_device_guid(struct ibv_device *device);
797 * ibv_open_device - Initialize device for use
799 struct ibv_context *ibv_open_device(struct ibv_device *device);
802 * ibv_close_device - Release device
804 int ibv_close_device(struct ibv_context *context);
807 * ibv_get_async_event - Get next async event
808 * @event: Pointer to use to return async event
810 * All async events returned by ibv_get_async_event() must eventually
811 * be acknowledged with ibv_ack_async_event().
813 int ibv_get_async_event(struct ibv_context *context,
814 struct ibv_async_event *event);
817 * ibv_ack_async_event - Acknowledge an async event
818 * @event: Event to be acknowledged.
820 * All async events which are returned by ibv_get_async_event() must
821 * be acknowledged. To avoid races, destroying an object (CQ, SRQ or
822 * QP) will wait for all affiliated events to be acknowledged, so
823 * there should be a one-to-one correspondence between acks and
826 void ibv_ack_async_event(struct ibv_async_event *event);
829 * ibv_query_device - Get device properties
831 int ibv_query_device(struct ibv_context *context,
832 struct ibv_device_attr *device_attr);
835 * ibv_query_port - Get port properties
837 int ibv_query_port(struct ibv_context *context, uint8_t port_num,
838 struct ibv_port_attr *port_attr);
841 * ibv_query_gid - Get a GID table entry
843 int ibv_query_gid(struct ibv_context *context, uint8_t port_num,
844 int index, union ibv_gid *gid);
847 * ibv_query_pkey - Get a P_Key table entry
849 int ibv_query_pkey(struct ibv_context *context, uint8_t port_num,
850 int index, uint16_t *pkey);
853 * ibv_alloc_pd - Allocate a protection domain
855 struct ibv_pd *ibv_alloc_pd(struct ibv_context *context);
858 * ibv_dealloc_pd - Free a protection domain
860 int ibv_dealloc_pd(struct ibv_pd *pd);
863 * ibv_reg_mr - Register a memory region
865 struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, void *addr,
866 size_t length, int access);
869 * ibv_dereg_mr - Deregister a memory region
871 int ibv_dereg_mr(struct ibv_mr *mr);
874 * ibv_create_comp_channel - Create a completion event channel
876 struct ibv_comp_channel *ibv_create_comp_channel(struct ibv_context *context);
879 * ibv_destroy_comp_channel - Destroy a completion event channel
881 int ibv_destroy_comp_channel(struct ibv_comp_channel *channel);
884 * ibv_create_cq - Create a completion queue
885 * @context - Context CQ will be attached to
886 * @cqe - Minimum number of entries required for CQ
887 * @cq_context - Consumer-supplied context returned for completion events
888 * @channel - Completion channel where completion events will be queued.
889 * May be NULL if completion events will not be used.
890 * @comp_vector - Completion vector used to signal completion events.
891 * Must be >= 0 and < context->num_comp_vectors.
893 struct ibv_cq *ibv_create_cq(struct ibv_context *context, int cqe,
895 struct ibv_comp_channel *channel,
899 * ibv_resize_cq - Modifies the capacity of the CQ.
900 * @cq: The CQ to resize.
901 * @cqe: The minimum size of the CQ.
903 * Users can examine the cq structure to determine the actual CQ size.
905 int ibv_resize_cq(struct ibv_cq *cq, int cqe);
908 * ibv_destroy_cq - Destroy a completion queue
910 int ibv_destroy_cq(struct ibv_cq *cq);
913 * ibv_get_cq_event - Read next CQ event
914 * @channel: Channel to get next event from.
915 * @cq: Used to return pointer to CQ.
916 * @cq_context: Used to return consumer-supplied CQ context.
918 * All completion events returned by ibv_get_cq_event() must
919 * eventually be acknowledged with ibv_ack_cq_events().
921 int ibv_get_cq_event(struct ibv_comp_channel *channel,
922 struct ibv_cq **cq, void **cq_context);
925 * ibv_ack_cq_events - Acknowledge CQ completion events
926 * @cq: CQ to acknowledge events for
927 * @nevents: Number of events to acknowledge.
929 * All completion events which are returned by ibv_get_cq_event() must
930 * be acknowledged. To avoid races, ibv_destroy_cq() will wait for
931 * all completion events to be acknowledged, so there should be a
932 * one-to-one correspondence between acks and successful gets. An
933 * application may accumulate multiple completion events and
934 * acknowledge them in a single call to ibv_ack_cq_events() by passing
935 * the number of events to ack in @nevents.
937 void ibv_ack_cq_events(struct ibv_cq *cq, unsigned int nevents);
940 * ibv_poll_cq - Poll a CQ for work completions
941 * @cq:the CQ being polled
942 * @num_entries:maximum number of completions to return
943 * @wc:array of at least @num_entries of &struct ibv_wc where completions
946 * Poll a CQ for (possibly multiple) completions. If the return value
947 * is < 0, an error occurred. If the return value is >= 0, it is the
948 * number of completions returned. If the return value is
949 * non-negative and strictly less than num_entries, then the CQ was
952 static inline int ibv_poll_cq(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc)
954 return cq->context->ops.poll_cq(cq, num_entries, wc);
958 * ibv_req_notify_cq - Request completion notification on a CQ. An
959 * event will be added to the completion channel associated with the
960 * CQ when an entry is added to the CQ.
961 * @cq: The completion queue to request notification for.
962 * @solicited_only: If non-zero, an event will be generated only for
963 * the next solicited CQ entry. If zero, any CQ entry, solicited or
964 * not, will generate an event.
966 static inline int ibv_req_notify_cq(struct ibv_cq *cq, int solicited_only)
968 return cq->context->ops.req_notify_cq(cq, solicited_only);
972 * ibv_create_srq - Creates a SRQ associated with the specified protection
974 * @pd: The protection domain associated with the SRQ.
975 * @srq_init_attr: A list of initial attributes required to create the SRQ.
977 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
978 * requested size of the SRQ, and set to the actual values allocated
979 * on return. If ibv_create_srq() succeeds, then max_wr and max_sge
980 * will always be at least as large as the requested values.
982 struct ibv_srq *ibv_create_srq(struct ibv_pd *pd,
983 struct ibv_srq_init_attr *srq_init_attr);
986 * ibv_create_xrc_srq - Creates a SRQ associated with the specified protection
987 * domain and xrc domain.
988 * @pd: The protection domain associated with the SRQ.
989 * @xrc_domain: The XRC domain associated with the SRQ.
990 * @xrc_cq: CQ to report completions for XRC packets on.
992 * @srq_init_attr: A list of initial attributes required to create the SRQ.
994 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
995 * requested size of the SRQ, and set to the actual values allocated
996 * on return. If ibv_create_srq() succeeds, then max_wr and max_sge
997 * will always be at least as large as the requested values.
999 struct ibv_srq *ibv_create_xrc_srq(struct ibv_pd *pd,
1000 struct ibv_xrc_domain *xrc_domain,
1001 struct ibv_cq *xrc_cq,
1002 struct ibv_srq_init_attr *srq_init_attr);
1005 * ibv_modify_srq - Modifies the attributes for the specified SRQ.
1006 * @srq: The SRQ to modify.
1007 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1008 * the current values of selected SRQ attributes are returned.
1009 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1010 * are being modified.
1012 * The mask may contain IBV_SRQ_MAX_WR to resize the SRQ and/or
1013 * IBV_SRQ_LIMIT to set the SRQ's limit and request notification when
1014 * the number of receives queued drops below the limit.
1016 int ibv_modify_srq(struct ibv_srq *srq,
1017 struct ibv_srq_attr *srq_attr,
1021 * ibv_query_srq - Returns the attribute list and current values for the
1023 * @srq: The SRQ to query.
1024 * @srq_attr: The attributes of the specified SRQ.
1026 int ibv_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr);
1029 * ibv_destroy_srq - Destroys the specified SRQ.
1030 * @srq: The SRQ to destroy.
1032 int ibv_destroy_srq(struct ibv_srq *srq);
1035 * ibv_post_srq_recv - Posts a list of work requests to the specified SRQ.
1036 * @srq: The SRQ to post the work request on.
1037 * @recv_wr: A list of work requests to post on the receive queue.
1038 * @bad_recv_wr: On an immediate failure, this parameter will reference
1039 * the work request that failed to be posted on the QP.
1041 static inline int ibv_post_srq_recv(struct ibv_srq *srq,
1042 struct ibv_recv_wr *recv_wr,
1043 struct ibv_recv_wr **bad_recv_wr)
1045 return srq->context->ops.post_srq_recv(srq, recv_wr, bad_recv_wr);
1049 * ibv_create_qp - Create a queue pair.
1051 struct ibv_qp *ibv_create_qp(struct ibv_pd *pd,
1052 struct ibv_qp_init_attr *qp_init_attr);
1055 * ibv_modify_qp - Modify a queue pair.
1057 int ibv_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
1061 * ibv_query_qp - Returns the attribute list and current values for the
1063 * @qp: The QP to query.
1064 * @attr: The attributes of the specified QP.
1065 * @attr_mask: A bit-mask used to select specific attributes to query.
1066 * @init_attr: Additional attributes of the selected QP.
1068 * The qp_attr_mask may be used to limit the query to gathering only the
1069 * selected attributes.
1071 int ibv_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
1073 struct ibv_qp_init_attr *init_attr);
1076 * ibv_destroy_qp - Destroy a queue pair.
1078 int ibv_destroy_qp(struct ibv_qp *qp);
1081 * ibv_post_send - Post a list of work requests to a send queue.
1083 * If IBV_SEND_INLINE flag is set, the data buffers can be reused
1084 * immediately after the call returns.
1086 static inline int ibv_post_send(struct ibv_qp *qp, struct ibv_send_wr *wr,
1087 struct ibv_send_wr **bad_wr)
1089 return qp->context->ops.post_send(qp, wr, bad_wr);
1093 * ibv_post_recv - Post a list of work requests to a receive queue.
1095 static inline int ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr,
1096 struct ibv_recv_wr **bad_wr)
1098 return qp->context->ops.post_recv(qp, wr, bad_wr);
1102 * ibv_create_ah - Create an address handle.
1104 struct ibv_ah *ibv_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr);
1107 * ibv_init_ah_from_wc - Initializes address handle attributes from a
1109 * @context: Device context on which the received message arrived.
1110 * @port_num: Port on which the received message arrived.
1111 * @wc: Work completion associated with the received message.
1112 * @grh: References the received global route header. This parameter is
1113 * ignored unless the work completion indicates that the GRH is valid.
1114 * @ah_attr: Returned attributes that can be used when creating an address
1115 * handle for replying to the message.
1117 int ibv_init_ah_from_wc(struct ibv_context *context, uint8_t port_num,
1118 struct ibv_wc *wc, struct ibv_grh *grh,
1119 struct ibv_ah_attr *ah_attr);
1122 * ibv_create_ah_from_wc - Creates an address handle associated with the
1123 * sender of the specified work completion.
1124 * @pd: The protection domain associated with the address handle.
1125 * @wc: Work completion information associated with a received message.
1126 * @grh: References the received global route header. This parameter is
1127 * ignored unless the work completion indicates that the GRH is valid.
1128 * @port_num: The outbound port number to associate with the address.
1130 * The address handle is used to reference a local or global destination
1131 * in all UD QP post sends.
1133 struct ibv_ah *ibv_create_ah_from_wc(struct ibv_pd *pd, struct ibv_wc *wc,
1134 struct ibv_grh *grh, uint8_t port_num);
1137 * ibv_destroy_ah - Destroy an address handle.
1139 int ibv_destroy_ah(struct ibv_ah *ah);
1142 * ibv_attach_mcast - Attaches the specified QP to a multicast group.
1143 * @qp: QP to attach to the multicast group. The QP must be a UD QP.
1144 * @gid: Multicast group GID.
1145 * @lid: Multicast group LID in host byte order.
1147 * In order to route multicast packets correctly, subnet
1148 * administration must have created the multicast group and configured
1149 * the fabric appropriately. The port associated with the specified
1150 * QP must also be a member of the multicast group.
1152 int ibv_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
1155 * ibv_detach_mcast - Detaches the specified QP from a multicast group.
1156 * @qp: QP to detach from the multicast group.
1157 * @gid: Multicast group GID.
1158 * @lid: Multicast group LID in host byte order.
1160 int ibv_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
1163 * ibv_fork_init - Prepare data structures so that fork() may be used
1164 * safely. If this function is not called or returns a non-zero
1165 * status, then libibverbs data structures are not fork()-safe and the
1166 * effect of an application calling fork() is undefined.
1168 int ibv_fork_init(void);
1171 * ibv_node_type_str - Return string describing node_type enum value
1173 const char *ibv_node_type_str(enum ibv_node_type node_type);
1176 * ibv_port_state_str - Return string describing port_state enum value
1178 const char *ibv_port_state_str(enum ibv_port_state port_state);
1181 * ibv_event_type_str - Return string describing event_type enum value
1183 const char *ibv_event_type_str(enum ibv_event_type event);
1186 * ibv_open_xrc_domain - open an XRC domain
1187 * Returns a reference to an XRC domain.
1189 * @context: Device context
1190 * @fd: descriptor for inode associated with the domain
1191 * If fd == -1, no inode is associated with the domain; in this ca= se,
1192 * the only legal value for oflag is O_CREAT
1194 * @oflag: oflag values are constructed by OR-ing flags from the following list
1197 * If a domain belonging to device named by context is already associated
1198 * with the inode, this flag has no effect, except as noted under O_EXCL
1199 * below. Otherwise, a new XRC domain is created and is associated with
1200 * inode specified by fd.
1203 * If O_EXCL and O_CREAT are set, open will fail if a domain associated with
1204 * the inode exists. The check for the existence of the domain and creation
1205 * of the domain if it does not exist is atomic with respect to other
1206 * processes executing open with fd naming the same inode.
1208 struct ibv_xrc_domain *ibv_open_xrc_domain(struct ibv_context *context,
1212 * ibv_close_xrc_domain - close an XRC domain
1213 * If this is the last reference, destroys the domain.
1215 * @d: reference to XRC domain to close
1217 * close is implicitly performed at process exit.
1219 int ibv_close_xrc_domain(struct ibv_xrc_domain *d);
1222 * ibv_create_xrc_rcv_qp - creates an XRC QP for serving as a receive-side-only QP,
1224 * This QP is created in kernel space, and persists until the last process
1225 * registered for the QP calls ibv_unreg_xrc_rcv_qp() (at which time the QP
1228 * @init_attr: init attributes to use for QP. xrc domain MUST be included here.
1229 * All other fields are ignored.
1231 * @xrc_rcv_qpn: qp_num of created QP (if success). To be passed to the
1232 * remote node (sender). The remote node will use xrc_rcv_qpn
1233 * in ibv_post_send when sending to XRC SRQ's on this host
1234 * in the same xrc domain.
1236 * RETURNS: success (0), or a (negative) error value.
1238 * NOTE: this verb also registers the calling user-process with the QP at its
1239 * creation time (implicit call to ibv_reg_xrc_rcv_qp), to avoid race
1240 * conditions. The creating process will need to call ibv_unreg_xrc_qp()
1241 * for the QP to release it from this process.
1243 int ibv_create_xrc_rcv_qp(struct ibv_qp_init_attr *init_attr,
1244 uint32_t *xrc_rcv_qpn);
1247 * ibv_modify_xrc_rcv_qp - modifies an xrc_rcv qp.
1249 * @xrc_domain: xrc domain the QP belongs to (for verification).
1250 * @xrc_qp_num: The (24 bit) number of the XRC QP.
1251 * @attr: modify-qp attributes. The following fields must be specified:
1252 * for RESET_2_INIT: qp_state, pkey_index , port, qp_access_flags
1253 * for INIT_2_RTR: qp_state, path_mtu, dest_qp_num, rq_psn,
1254 * max_dest_rd_atomic, min_rnr_timer, ah_attr
1255 * The QP need not be brought to RTS for the QP to operate as a
1257 * @attr_mask: bitmap indicating which attributes are provided in the attr
1258 * struct. Used for validity checking.
1259 * The following bits must be set:
1260 * for RESET_2_INIT: IBV_QP_PKEY_INDEX, IBV_QP_PORT,
1261 * IBV_QP_ACCESS_FLAGS, IBV_QP_STATE
1262 * for INIT_2_RTR: IBV_QP_AV, IBV_QP_PATH_MTU, IBV_QP_DEST_QPN,
1263 * IBV_QP_RQ_PSN, IBV_QP_MAX_DEST_RD_ATOMIC,
1264 * IBV_QP_MIN_RNR_TIMER, IBV_QP_STATE
1266 * RETURNS: success (0), or a (positive) error value.
1269 int ibv_modify_xrc_rcv_qp(struct ibv_xrc_domain *xrc_domain,
1270 uint32_t xrc_qp_num,
1271 struct ibv_qp_attr *attr, int attr_mask);
1274 * ibv_query_xrc_rcv_qp - queries an xrc_rcv qp.
1276 * @xrc_domain: xrc domain the QP belongs to (for verification).
1277 * @xrc_qp_num: The (24 bit) number of the XRC QP.
1278 * @attr: for returning qp attributes.
1279 * @attr_mask: bitmap indicating which attributes to return.
1280 * @init_attr: for returning the init attributes
1282 * RETURNS: success (0), or a (positive) error value.
1285 int ibv_query_xrc_rcv_qp(struct ibv_xrc_domain *xrc_domain, uint32_t xrc_qp_num,
1286 struct ibv_qp_attr *attr, int attr_mask,
1287 struct ibv_qp_init_attr *init_attr);
1290 * ibv_reg_xrc_rcv_qp: registers a user process with an XRC QP which serves as
1291 * a receive-side only QP.
1293 * @xrc_domain: xrc domain the QP belongs to (for verification).
1294 * @xrc_qp_num: The (24 bit) number of the XRC QP.
1296 * RETURNS: success (0),
1297 * or error (EINVAL), if:
1298 * 1. There is no such QP_num allocated.
1299 * 2. The QP is allocated, but is not an receive XRC QP
1300 * 3. The XRC QP does not belong to the given domain.
1302 int ibv_reg_xrc_rcv_qp(struct ibv_xrc_domain *xrc_domain, uint32_t xrc_qp_num);
1305 * ibv_unreg_xrc_rcv_qp: detaches a user process from an XRC QP serving as
1306 * a receive-side only QP. If as a result, there are no remaining
1307 * userspace processes registered for this XRC QP, it is destroyed.
1309 * @xrc_domain: xrc domain the QP belongs to (for verification).
1310 * @xrc_qp_num: The (24 bit) number of the XRC QP.
1312 * RETURNS: success (0),
1313 * or error (EINVAL), if:
1314 * 1. There is no such QP_num allocated.
1315 * 2. The QP is allocated, but is not an XRC QP
1316 * 3. The XRC QP does not belong to the given domain.
1317 * NOTE: There is no reason to return a special code if the QP is destroyed.
1318 * The unregister simply succeeds.
1320 int ibv_unreg_xrc_rcv_qp(struct ibv_xrc_domain *xrc_domain,
1321 uint32_t xrc_qp_num);
1325 # undef __attribute_const
1327 #define ibv_query_port(context, port_num, port_attr) \
1328 ___ibv_query_port(context, port_num, port_attr)
1330 #endif /* INFINIBAND_VERBS_H */