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 Cisco Systems. All rights reserved.
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:
16 * Redistribution and use in source and binary forms, with or
17 * without modification, are permitted provided that the following
20 * - Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
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.
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
38 * $Id: ib_verbs.h 1349 2004-12-16 21:09:43Z roland $
41 #if !defined(IB_VERBS_H)
44 #include <linux/types.h>
45 #include <linux/device.h>
47 #include <asm/atomic.h>
48 #include <asm/scatterlist.h>
49 #include <asm/uaccess.h>
65 enum ib_device_cap_flags {
66 IB_DEVICE_RESIZE_MAX_WR = 1,
67 IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
68 IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
69 IB_DEVICE_RAW_MULTI = (1<<3),
70 IB_DEVICE_AUTO_PATH_MIG = (1<<4),
71 IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
72 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
73 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
74 IB_DEVICE_SHUTDOWN_PORT = (1<<8),
75 IB_DEVICE_INIT_TYPE = (1<<9),
76 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
77 IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
78 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
79 IB_DEVICE_SRQ_RESIZE = (1<<13),
80 IB_DEVICE_N_NOTIFY_CQ = (1<<14),
89 struct ib_device_attr {
91 __be64 sys_image_guid;
109 int max_qp_init_rd_atom;
110 int max_ee_init_rd_atom;
111 enum ib_atomic_cap atomic_cap;
118 int max_mcast_qp_attach;
119 int max_total_mcast_qp_attach;
127 u8 local_ca_ack_delay;
138 static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
141 case IB_MTU_256: return 256;
142 case IB_MTU_512: return 512;
143 case IB_MTU_1024: return 1024;
144 case IB_MTU_2048: return 2048;
145 case IB_MTU_4096: return 4096;
156 IB_PORT_ACTIVE_DEFER = 5
159 enum ib_port_cap_flags {
161 IB_PORT_NOTICE_SUP = 1 << 2,
162 IB_PORT_TRAP_SUP = 1 << 3,
163 IB_PORT_OPT_IPD_SUP = 1 << 4,
164 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
165 IB_PORT_SL_MAP_SUP = 1 << 6,
166 IB_PORT_MKEY_NVRAM = 1 << 7,
167 IB_PORT_PKEY_NVRAM = 1 << 8,
168 IB_PORT_LED_INFO_SUP = 1 << 9,
169 IB_PORT_SM_DISABLED = 1 << 10,
170 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
171 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
172 IB_PORT_CM_SUP = 1 << 16,
173 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
174 IB_PORT_REINIT_SUP = 1 << 18,
175 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
176 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
177 IB_PORT_DR_NOTICE_SUP = 1 << 21,
178 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
179 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
180 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
181 IB_PORT_CLIENT_REG_SUP = 1 << 25
191 static inline int ib_width_enum_to_int(enum ib_port_width width)
194 case IB_WIDTH_1X: return 1;
195 case IB_WIDTH_4X: return 4;
196 case IB_WIDTH_8X: return 8;
197 case IB_WIDTH_12X: return 12;
202 struct ib_port_attr {
203 enum ib_port_state state;
205 enum ib_mtu active_mtu;
224 enum ib_device_modify_flags {
225 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
226 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
229 struct ib_device_modify {
234 enum ib_port_modify_flags {
235 IB_PORT_SHUTDOWN = 1,
236 IB_PORT_INIT_TYPE = (1<<2),
237 IB_PORT_RESET_QKEY_CNTR = (1<<3)
240 struct ib_port_modify {
241 u32 set_port_cap_mask;
242 u32 clr_port_cap_mask;
250 IB_EVENT_QP_ACCESS_ERR,
254 IB_EVENT_PATH_MIG_ERR,
255 IB_EVENT_DEVICE_FATAL,
256 IB_EVENT_PORT_ACTIVE,
259 IB_EVENT_PKEY_CHANGE,
262 IB_EVENT_SRQ_LIMIT_REACHED,
263 IB_EVENT_QP_LAST_WQE_REACHED,
264 IB_EVENT_CLIENT_REREGISTER
268 struct ib_device *device;
275 enum ib_event_type event;
278 struct ib_event_handler {
279 struct ib_device *device;
280 void (*handler)(struct ib_event_handler *, struct ib_event *);
281 struct list_head list;
284 #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
286 (_ptr)->device = _device; \
287 (_ptr)->handler = _handler; \
288 INIT_LIST_HEAD(&(_ptr)->list); \
291 struct ib_global_route {
300 __be32 version_tclass_flow;
309 IB_MULTICAST_QPN = 0xffffff
312 #define IB_LID_PERMISSIVE __constant_htons(0xFFFF)
319 IB_RATE_PORT_CURRENT = 0,
320 IB_RATE_2_5_GBPS = 2,
328 IB_RATE_120_GBPS = 10
332 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
333 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
334 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
335 * @rate: rate to convert.
337 int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
340 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
342 * @mult: multiple to convert.
344 enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
347 struct ib_global_route grh;
360 IB_WC_LOC_EEC_OP_ERR,
365 IB_WC_LOC_ACCESS_ERR,
366 IB_WC_REM_INV_REQ_ERR,
367 IB_WC_REM_ACCESS_ERR,
370 IB_WC_RNR_RETRY_EXC_ERR,
371 IB_WC_LOC_RDD_VIOL_ERR,
372 IB_WC_REM_INV_RD_REQ_ERR,
375 IB_WC_INV_EEC_STATE_ERR,
377 IB_WC_RESP_TIMEOUT_ERR,
389 * Set value of IB_WC_RECV so consumers can test if a completion is a
390 * receive by testing (opcode & IB_WC_RECV).
393 IB_WC_RECV_RDMA_WITH_IMM
398 IB_WC_WITH_IMM = (1<<1)
403 enum ib_wc_status status;
404 enum ib_wc_opcode opcode;
415 u8 port_num; /* valid only for DR SMPs on switches */
423 enum ib_srq_attr_mask {
424 IB_SRQ_MAX_WR = 1 << 0,
425 IB_SRQ_LIMIT = 1 << 1,
434 struct ib_srq_init_attr {
435 void (*event_handler)(struct ib_event *, void *);
437 struct ib_srq_attr attr;
455 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
456 * here (and in that order) since the MAD layer uses them as
457 * indices into a 2-entry table.
469 struct ib_qp_init_attr {
470 void (*event_handler)(struct ib_event *, void *);
472 struct ib_cq *send_cq;
473 struct ib_cq *recv_cq;
475 struct ib_qp_cap cap;
476 enum ib_sig_type sq_sig_type;
477 enum ib_qp_type qp_type;
478 u8 port_num; /* special QP types only */
481 enum ib_rnr_timeout {
482 IB_RNR_TIMER_655_36 = 0,
483 IB_RNR_TIMER_000_01 = 1,
484 IB_RNR_TIMER_000_02 = 2,
485 IB_RNR_TIMER_000_03 = 3,
486 IB_RNR_TIMER_000_04 = 4,
487 IB_RNR_TIMER_000_06 = 5,
488 IB_RNR_TIMER_000_08 = 6,
489 IB_RNR_TIMER_000_12 = 7,
490 IB_RNR_TIMER_000_16 = 8,
491 IB_RNR_TIMER_000_24 = 9,
492 IB_RNR_TIMER_000_32 = 10,
493 IB_RNR_TIMER_000_48 = 11,
494 IB_RNR_TIMER_000_64 = 12,
495 IB_RNR_TIMER_000_96 = 13,
496 IB_RNR_TIMER_001_28 = 14,
497 IB_RNR_TIMER_001_92 = 15,
498 IB_RNR_TIMER_002_56 = 16,
499 IB_RNR_TIMER_003_84 = 17,
500 IB_RNR_TIMER_005_12 = 18,
501 IB_RNR_TIMER_007_68 = 19,
502 IB_RNR_TIMER_010_24 = 20,
503 IB_RNR_TIMER_015_36 = 21,
504 IB_RNR_TIMER_020_48 = 22,
505 IB_RNR_TIMER_030_72 = 23,
506 IB_RNR_TIMER_040_96 = 24,
507 IB_RNR_TIMER_061_44 = 25,
508 IB_RNR_TIMER_081_92 = 26,
509 IB_RNR_TIMER_122_88 = 27,
510 IB_RNR_TIMER_163_84 = 28,
511 IB_RNR_TIMER_245_76 = 29,
512 IB_RNR_TIMER_327_68 = 30,
513 IB_RNR_TIMER_491_52 = 31
516 enum ib_qp_attr_mask {
518 IB_QP_CUR_STATE = (1<<1),
519 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
520 IB_QP_ACCESS_FLAGS = (1<<3),
521 IB_QP_PKEY_INDEX = (1<<4),
525 IB_QP_PATH_MTU = (1<<8),
526 IB_QP_TIMEOUT = (1<<9),
527 IB_QP_RETRY_CNT = (1<<10),
528 IB_QP_RNR_RETRY = (1<<11),
529 IB_QP_RQ_PSN = (1<<12),
530 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
531 IB_QP_ALT_PATH = (1<<14),
532 IB_QP_MIN_RNR_TIMER = (1<<15),
533 IB_QP_SQ_PSN = (1<<16),
534 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
535 IB_QP_PATH_MIG_STATE = (1<<18),
537 IB_QP_DEST_QPN = (1<<20)
557 enum ib_qp_state qp_state;
558 enum ib_qp_state cur_qp_state;
559 enum ib_mtu path_mtu;
560 enum ib_mig_state path_mig_state;
566 struct ib_qp_cap cap;
567 struct ib_ah_attr ah_attr;
568 struct ib_ah_attr alt_ah_attr;
571 u8 en_sqd_async_notify;
574 u8 max_dest_rd_atomic;
586 IB_WR_RDMA_WRITE_WITH_IMM,
590 IB_WR_ATOMIC_CMP_AND_SWP,
591 IB_WR_ATOMIC_FETCH_AND_ADD
596 IB_SEND_SIGNALED = (1<<1),
597 IB_SEND_SOLICITED = (1<<2),
598 IB_SEND_INLINE = (1<<3)
608 struct ib_send_wr *next;
610 struct ib_sge *sg_list;
612 enum ib_wr_opcode opcode;
630 u16 pkey_index; /* valid for GSI only */
631 u8 port_num; /* valid for DR SMPs on switch only */
637 struct ib_recv_wr *next;
639 struct ib_sge *sg_list;
643 enum ib_access_flags {
644 IB_ACCESS_LOCAL_WRITE = 1,
645 IB_ACCESS_REMOTE_WRITE = (1<<1),
646 IB_ACCESS_REMOTE_READ = (1<<2),
647 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
648 IB_ACCESS_MW_BIND = (1<<4)
658 u64 device_virt_addr;
665 enum ib_mr_rereg_flags {
666 IB_MR_REREG_TRANS = 1,
667 IB_MR_REREG_PD = (1<<1),
668 IB_MR_REREG_ACCESS = (1<<2)
687 struct ib_device *device;
688 struct list_head pd_list;
689 struct list_head mr_list;
690 struct list_head mw_list;
691 struct list_head cq_list;
692 struct list_head qp_list;
693 struct list_head srq_list;
694 struct list_head ah_list;
698 u64 user_handle; /* handle given to us by userspace */
699 struct ib_ucontext *context; /* associated user context */
700 struct list_head list; /* link to context's list */
701 u32 id; /* index into kernel idr */
705 unsigned long user_base;
706 unsigned long virt_base;
711 struct list_head chunk_list;
714 struct ib_umem_chunk {
715 struct list_head list;
718 struct scatterlist page_list[0];
728 #define IB_UMEM_MAX_PAGE_CHUNK \
729 ((PAGE_SIZE - offsetof(struct ib_umem_chunk, page_list)) / \
730 ((void *) &((struct ib_umem_chunk *) 0)->page_list[1] - \
731 (void *) &((struct ib_umem_chunk *) 0)->page_list[0]))
733 struct ib_umem_object {
734 struct ib_uobject uobject;
739 struct ib_device *device;
740 struct ib_uobject *uobject;
741 atomic_t usecnt; /* count all resources */
745 struct ib_device *device;
747 struct ib_uobject *uobject;
750 typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
753 struct ib_device *device;
754 struct ib_uobject *uobject;
755 ib_comp_handler comp_handler;
756 void (*event_handler)(struct ib_event *, void *);
759 atomic_t usecnt; /* count number of work queues */
763 struct ib_device *device;
765 struct ib_uobject *uobject;
766 void (*event_handler)(struct ib_event *, void *);
772 struct ib_device *device;
774 struct ib_cq *send_cq;
775 struct ib_cq *recv_cq;
777 struct ib_uobject *uobject;
778 void (*event_handler)(struct ib_event *, void *);
781 enum ib_qp_type qp_type;
785 struct ib_device *device;
787 struct ib_uobject *uobject;
790 atomic_t usecnt; /* count number of MWs */
794 struct ib_device *device;
796 struct ib_uobject *uobject;
801 struct ib_device *device;
803 struct list_head list;
811 enum ib_process_mad_flags {
812 IB_MAD_IGNORE_MKEY = 1,
813 IB_MAD_IGNORE_BKEY = 2,
814 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
818 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
819 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
820 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
821 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
824 #define IB_DEVICE_NAME_MAX 64
828 struct ib_event_handler event_handler;
829 struct ib_pkey_cache **pkey_cache;
830 struct ib_gid_cache **gid_cache;
835 struct device *dma_device;
837 char name[IB_DEVICE_NAME_MAX];
839 struct list_head event_handler_list;
840 spinlock_t event_handler_lock;
842 struct list_head core_list;
843 struct list_head client_data_list;
844 spinlock_t client_data_lock;
846 struct ib_cache cache;
850 int (*query_device)(struct ib_device *device,
851 struct ib_device_attr *device_attr);
852 int (*query_port)(struct ib_device *device,
854 struct ib_port_attr *port_attr);
855 int (*query_gid)(struct ib_device *device,
856 u8 port_num, int index,
858 int (*query_pkey)(struct ib_device *device,
859 u8 port_num, u16 index, u16 *pkey);
860 int (*modify_device)(struct ib_device *device,
861 int device_modify_mask,
862 struct ib_device_modify *device_modify);
863 int (*modify_port)(struct ib_device *device,
864 u8 port_num, int port_modify_mask,
865 struct ib_port_modify *port_modify);
866 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
867 struct ib_udata *udata);
868 int (*dealloc_ucontext)(struct ib_ucontext *context);
869 int (*mmap)(struct ib_ucontext *context,
870 struct vm_area_struct *vma);
871 struct ib_pd * (*alloc_pd)(struct ib_device *device,
872 struct ib_ucontext *context,
873 struct ib_udata *udata);
874 int (*dealloc_pd)(struct ib_pd *pd);
875 struct ib_ah * (*create_ah)(struct ib_pd *pd,
876 struct ib_ah_attr *ah_attr);
877 int (*modify_ah)(struct ib_ah *ah,
878 struct ib_ah_attr *ah_attr);
879 int (*query_ah)(struct ib_ah *ah,
880 struct ib_ah_attr *ah_attr);
881 int (*destroy_ah)(struct ib_ah *ah);
882 struct ib_srq * (*create_srq)(struct ib_pd *pd,
883 struct ib_srq_init_attr *srq_init_attr,
884 struct ib_udata *udata);
885 int (*modify_srq)(struct ib_srq *srq,
886 struct ib_srq_attr *srq_attr,
887 enum ib_srq_attr_mask srq_attr_mask);
888 int (*query_srq)(struct ib_srq *srq,
889 struct ib_srq_attr *srq_attr);
890 int (*destroy_srq)(struct ib_srq *srq);
891 int (*post_srq_recv)(struct ib_srq *srq,
892 struct ib_recv_wr *recv_wr,
893 struct ib_recv_wr **bad_recv_wr);
894 struct ib_qp * (*create_qp)(struct ib_pd *pd,
895 struct ib_qp_init_attr *qp_init_attr,
896 struct ib_udata *udata);
897 int (*modify_qp)(struct ib_qp *qp,
898 struct ib_qp_attr *qp_attr,
900 int (*query_qp)(struct ib_qp *qp,
901 struct ib_qp_attr *qp_attr,
903 struct ib_qp_init_attr *qp_init_attr);
904 int (*destroy_qp)(struct ib_qp *qp);
905 int (*post_send)(struct ib_qp *qp,
906 struct ib_send_wr *send_wr,
907 struct ib_send_wr **bad_send_wr);
908 int (*post_recv)(struct ib_qp *qp,
909 struct ib_recv_wr *recv_wr,
910 struct ib_recv_wr **bad_recv_wr);
911 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
912 struct ib_ucontext *context,
913 struct ib_udata *udata);
914 int (*destroy_cq)(struct ib_cq *cq);
915 int (*resize_cq)(struct ib_cq *cq, int cqe,
916 struct ib_udata *udata);
917 int (*poll_cq)(struct ib_cq *cq, int num_entries,
919 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
920 int (*req_notify_cq)(struct ib_cq *cq,
921 enum ib_cq_notify cq_notify);
922 int (*req_ncomp_notif)(struct ib_cq *cq,
924 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
925 int mr_access_flags);
926 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
927 struct ib_phys_buf *phys_buf_array,
931 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
932 struct ib_umem *region,
934 struct ib_udata *udata);
935 int (*query_mr)(struct ib_mr *mr,
936 struct ib_mr_attr *mr_attr);
937 int (*dereg_mr)(struct ib_mr *mr);
938 int (*rereg_phys_mr)(struct ib_mr *mr,
941 struct ib_phys_buf *phys_buf_array,
945 struct ib_mw * (*alloc_mw)(struct ib_pd *pd);
946 int (*bind_mw)(struct ib_qp *qp,
948 struct ib_mw_bind *mw_bind);
949 int (*dealloc_mw)(struct ib_mw *mw);
950 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
952 struct ib_fmr_attr *fmr_attr);
953 int (*map_phys_fmr)(struct ib_fmr *fmr,
954 u64 *page_list, int list_len,
956 int (*unmap_fmr)(struct list_head *fmr_list);
957 int (*dealloc_fmr)(struct ib_fmr *fmr);
958 int (*attach_mcast)(struct ib_qp *qp,
961 int (*detach_mcast)(struct ib_qp *qp,
964 int (*process_mad)(struct ib_device *device,
965 int process_mad_flags,
968 struct ib_grh *in_grh,
969 struct ib_mad *in_mad,
970 struct ib_mad *out_mad);
972 struct module *owner;
973 struct class_device class_dev;
974 struct kobject ports_parent;
975 struct list_head port_list;
978 IB_DEV_UNINITIALIZED,
994 void (*add) (struct ib_device *);
995 void (*remove)(struct ib_device *);
997 struct list_head list;
1000 struct ib_device *ib_alloc_device(size_t size);
1001 void ib_dealloc_device(struct ib_device *device);
1003 int ib_register_device (struct ib_device *device);
1004 void ib_unregister_device(struct ib_device *device);
1006 int ib_register_client (struct ib_client *client);
1007 void ib_unregister_client(struct ib_client *client);
1009 void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1010 void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1013 static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1015 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1018 static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1020 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1024 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1025 * contains all required attributes and no attributes not allowed for
1026 * the given QP state transition.
1027 * @cur_state: Current QP state
1028 * @next_state: Next QP state
1030 * @mask: Mask of supplied QP attributes
1032 * This function is a helper function that a low-level driver's
1033 * modify_qp method can use to validate the consumer's input. It
1034 * checks that cur_state and next_state are valid QP states, that a
1035 * transition from cur_state to next_state is allowed by the IB spec,
1036 * and that the attribute mask supplied is allowed for the transition.
1038 int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1039 enum ib_qp_type type, enum ib_qp_attr_mask mask);
1041 int ib_register_event_handler (struct ib_event_handler *event_handler);
1042 int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1043 void ib_dispatch_event(struct ib_event *event);
1045 int ib_query_device(struct ib_device *device,
1046 struct ib_device_attr *device_attr);
1048 int ib_query_port(struct ib_device *device,
1049 u8 port_num, struct ib_port_attr *port_attr);
1051 int ib_query_gid(struct ib_device *device,
1052 u8 port_num, int index, union ib_gid *gid);
1054 int ib_query_pkey(struct ib_device *device,
1055 u8 port_num, u16 index, u16 *pkey);
1057 int ib_modify_device(struct ib_device *device,
1058 int device_modify_mask,
1059 struct ib_device_modify *device_modify);
1061 int ib_modify_port(struct ib_device *device,
1062 u8 port_num, int port_modify_mask,
1063 struct ib_port_modify *port_modify);
1066 * ib_alloc_pd - Allocates an unused protection domain.
1067 * @device: The device on which to allocate the protection domain.
1069 * A protection domain object provides an association between QPs, shared
1070 * receive queues, address handles, memory regions, and memory windows.
1072 struct ib_pd *ib_alloc_pd(struct ib_device *device);
1075 * ib_dealloc_pd - Deallocates a protection domain.
1076 * @pd: The protection domain to deallocate.
1078 int ib_dealloc_pd(struct ib_pd *pd);
1081 * ib_create_ah - Creates an address handle for the given address vector.
1082 * @pd: The protection domain associated with the address handle.
1083 * @ah_attr: The attributes of the address vector.
1085 * The address handle is used to reference a local or global destination
1086 * in all UD QP post sends.
1088 struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1091 * ib_init_ah_from_wc - Initializes address handle attributes from a
1093 * @device: Device on which the received message arrived.
1094 * @port_num: Port on which the received message arrived.
1095 * @wc: Work completion associated with the received message.
1096 * @grh: References the received global route header. This parameter is
1097 * ignored unless the work completion indicates that the GRH is valid.
1098 * @ah_attr: Returned attributes that can be used when creating an address
1099 * handle for replying to the message.
1101 int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1102 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1105 * ib_create_ah_from_wc - Creates an address handle associated with the
1106 * sender of the specified work completion.
1107 * @pd: The protection domain associated with the address handle.
1108 * @wc: Work completion information associated with a received message.
1109 * @grh: References the received global route header. This parameter is
1110 * ignored unless the work completion indicates that the GRH is valid.
1111 * @port_num: The outbound port number to associate with the address.
1113 * The address handle is used to reference a local or global destination
1114 * in all UD QP post sends.
1116 struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1117 struct ib_grh *grh, u8 port_num);
1120 * ib_modify_ah - Modifies the address vector associated with an address
1122 * @ah: The address handle to modify.
1123 * @ah_attr: The new address vector attributes to associate with the
1126 int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1129 * ib_query_ah - Queries the address vector associated with an address
1131 * @ah: The address handle to query.
1132 * @ah_attr: The address vector attributes associated with the address
1135 int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1138 * ib_destroy_ah - Destroys an address handle.
1139 * @ah: The address handle to destroy.
1141 int ib_destroy_ah(struct ib_ah *ah);
1144 * ib_create_srq - Creates a SRQ associated with the specified protection
1146 * @pd: The protection domain associated with the SRQ.
1147 * @srq_init_attr: A list of initial attributes required to create the
1148 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1149 * the actual capabilities of the created SRQ.
1151 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1152 * requested size of the SRQ, and set to the actual values allocated
1153 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1154 * will always be at least as large as the requested values.
1156 struct ib_srq *ib_create_srq(struct ib_pd *pd,
1157 struct ib_srq_init_attr *srq_init_attr);
1160 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1161 * @srq: The SRQ to modify.
1162 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1163 * the current values of selected SRQ attributes are returned.
1164 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1165 * are being modified.
1167 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1168 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1169 * the number of receives queued drops below the limit.
1171 int ib_modify_srq(struct ib_srq *srq,
1172 struct ib_srq_attr *srq_attr,
1173 enum ib_srq_attr_mask srq_attr_mask);
1176 * ib_query_srq - Returns the attribute list and current values for the
1178 * @srq: The SRQ to query.
1179 * @srq_attr: The attributes of the specified SRQ.
1181 int ib_query_srq(struct ib_srq *srq,
1182 struct ib_srq_attr *srq_attr);
1185 * ib_destroy_srq - Destroys the specified SRQ.
1186 * @srq: The SRQ to destroy.
1188 int ib_destroy_srq(struct ib_srq *srq);
1191 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1192 * @srq: The SRQ to post the work request on.
1193 * @recv_wr: A list of work requests to post on the receive queue.
1194 * @bad_recv_wr: On an immediate failure, this parameter will reference
1195 * the work request that failed to be posted on the QP.
1197 static inline int ib_post_srq_recv(struct ib_srq *srq,
1198 struct ib_recv_wr *recv_wr,
1199 struct ib_recv_wr **bad_recv_wr)
1201 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1205 * ib_create_qp - Creates a QP associated with the specified protection
1207 * @pd: The protection domain associated with the QP.
1208 * @qp_init_attr: A list of initial attributes required to create the
1209 * QP. If QP creation succeeds, then the attributes are updated to
1210 * the actual capabilities of the created QP.
1212 struct ib_qp *ib_create_qp(struct ib_pd *pd,
1213 struct ib_qp_init_attr *qp_init_attr);
1216 * ib_modify_qp - Modifies the attributes for the specified QP and then
1217 * transitions the QP to the given state.
1218 * @qp: The QP to modify.
1219 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1220 * the current values of selected QP attributes are returned.
1221 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1222 * are being modified.
1224 int ib_modify_qp(struct ib_qp *qp,
1225 struct ib_qp_attr *qp_attr,
1229 * ib_query_qp - Returns the attribute list and current values for the
1231 * @qp: The QP to query.
1232 * @qp_attr: The attributes of the specified QP.
1233 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1234 * @qp_init_attr: Additional attributes of the selected QP.
1236 * The qp_attr_mask may be used to limit the query to gathering only the
1237 * selected attributes.
1239 int ib_query_qp(struct ib_qp *qp,
1240 struct ib_qp_attr *qp_attr,
1242 struct ib_qp_init_attr *qp_init_attr);
1245 * ib_destroy_qp - Destroys the specified QP.
1246 * @qp: The QP to destroy.
1248 int ib_destroy_qp(struct ib_qp *qp);
1251 * ib_post_send - Posts a list of work requests to the send queue of
1253 * @qp: The QP to post the work request on.
1254 * @send_wr: A list of work requests to post on the send queue.
1255 * @bad_send_wr: On an immediate failure, this parameter will reference
1256 * the work request that failed to be posted on the QP.
1258 static inline int ib_post_send(struct ib_qp *qp,
1259 struct ib_send_wr *send_wr,
1260 struct ib_send_wr **bad_send_wr)
1262 return qp->device->post_send(qp, send_wr, bad_send_wr);
1266 * ib_post_recv - Posts a list of work requests to the receive queue of
1268 * @qp: The QP to post the work request on.
1269 * @recv_wr: A list of work requests to post on the receive queue.
1270 * @bad_recv_wr: On an immediate failure, this parameter will reference
1271 * the work request that failed to be posted on the QP.
1273 static inline int ib_post_recv(struct ib_qp *qp,
1274 struct ib_recv_wr *recv_wr,
1275 struct ib_recv_wr **bad_recv_wr)
1277 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1281 * ib_create_cq - Creates a CQ on the specified device.
1282 * @device: The device on which to create the CQ.
1283 * @comp_handler: A user-specified callback that is invoked when a
1284 * completion event occurs on the CQ.
1285 * @event_handler: A user-specified callback that is invoked when an
1286 * asynchronous event not associated with a completion occurs on the CQ.
1287 * @cq_context: Context associated with the CQ returned to the user via
1288 * the associated completion and event handlers.
1289 * @cqe: The minimum size of the CQ.
1291 * Users can examine the cq structure to determine the actual CQ size.
1293 struct ib_cq *ib_create_cq(struct ib_device *device,
1294 ib_comp_handler comp_handler,
1295 void (*event_handler)(struct ib_event *, void *),
1296 void *cq_context, int cqe);
1299 * ib_resize_cq - Modifies the capacity of the CQ.
1300 * @cq: The CQ to resize.
1301 * @cqe: The minimum size of the CQ.
1303 * Users can examine the cq structure to determine the actual CQ size.
1305 int ib_resize_cq(struct ib_cq *cq, int cqe);
1308 * ib_destroy_cq - Destroys the specified CQ.
1309 * @cq: The CQ to destroy.
1311 int ib_destroy_cq(struct ib_cq *cq);
1314 * ib_poll_cq - poll a CQ for completion(s)
1315 * @cq:the CQ being polled
1316 * @num_entries:maximum number of completions to return
1317 * @wc:array of at least @num_entries &struct ib_wc where completions
1320 * Poll a CQ for (possibly multiple) completions. If the return value
1321 * is < 0, an error occurred. If the return value is >= 0, it is the
1322 * number of completions returned. If the return value is
1323 * non-negative and < num_entries, then the CQ was emptied.
1325 static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1328 return cq->device->poll_cq(cq, num_entries, wc);
1332 * ib_peek_cq - Returns the number of unreaped completions currently
1333 * on the specified CQ.
1334 * @cq: The CQ to peek.
1335 * @wc_cnt: A minimum number of unreaped completions to check for.
1337 * If the number of unreaped completions is greater than or equal to wc_cnt,
1338 * this function returns wc_cnt, otherwise, it returns the actual number of
1339 * unreaped completions.
1341 int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1344 * ib_req_notify_cq - Request completion notification on a CQ.
1345 * @cq: The CQ to generate an event for.
1346 * @cq_notify: If set to %IB_CQ_SOLICITED, completion notification will
1347 * occur on the next solicited event. If set to %IB_CQ_NEXT_COMP,
1348 * notification will occur on the next completion.
1350 static inline int ib_req_notify_cq(struct ib_cq *cq,
1351 enum ib_cq_notify cq_notify)
1353 return cq->device->req_notify_cq(cq, cq_notify);
1357 * ib_req_ncomp_notif - Request completion notification when there are
1358 * at least the specified number of unreaped completions on the CQ.
1359 * @cq: The CQ to generate an event for.
1360 * @wc_cnt: The number of unreaped completions that should be on the
1361 * CQ before an event is generated.
1363 static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1365 return cq->device->req_ncomp_notif ?
1366 cq->device->req_ncomp_notif(cq, wc_cnt) :
1371 * ib_get_dma_mr - Returns a memory region for system memory that is
1373 * @pd: The protection domain associated with the memory region.
1374 * @mr_access_flags: Specifies the memory access rights.
1376 struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1379 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
1381 * @pd: The protection domain associated assigned to the registered region.
1382 * @phys_buf_array: Specifies a list of physical buffers to use in the
1384 * @num_phys_buf: Specifies the size of the phys_buf_array.
1385 * @mr_access_flags: Specifies the memory access rights.
1386 * @iova_start: The offset of the region's starting I/O virtual address.
1388 struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
1389 struct ib_phys_buf *phys_buf_array,
1391 int mr_access_flags,
1395 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
1396 * Conceptually, this call performs the functions deregister memory region
1397 * followed by register physical memory region. Where possible,
1398 * resources are reused instead of deallocated and reallocated.
1399 * @mr: The memory region to modify.
1400 * @mr_rereg_mask: A bit-mask used to indicate which of the following
1401 * properties of the memory region are being modified.
1402 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
1403 * the new protection domain to associated with the memory region,
1404 * otherwise, this parameter is ignored.
1405 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1406 * field specifies a list of physical buffers to use in the new
1407 * translation, otherwise, this parameter is ignored.
1408 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1409 * field specifies the size of the phys_buf_array, otherwise, this
1410 * parameter is ignored.
1411 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
1412 * field specifies the new memory access rights, otherwise, this
1413 * parameter is ignored.
1414 * @iova_start: The offset of the region's starting I/O virtual address.
1416 int ib_rereg_phys_mr(struct ib_mr *mr,
1419 struct ib_phys_buf *phys_buf_array,
1421 int mr_access_flags,
1425 * ib_query_mr - Retrieves information about a specific memory region.
1426 * @mr: The memory region to retrieve information about.
1427 * @mr_attr: The attributes of the specified memory region.
1429 int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
1432 * ib_dereg_mr - Deregisters a memory region and removes it from the
1433 * HCA translation table.
1434 * @mr: The memory region to deregister.
1436 int ib_dereg_mr(struct ib_mr *mr);
1439 * ib_alloc_mw - Allocates a memory window.
1440 * @pd: The protection domain associated with the memory window.
1442 struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
1445 * ib_bind_mw - Posts a work request to the send queue of the specified
1446 * QP, which binds the memory window to the given address range and
1447 * remote access attributes.
1448 * @qp: QP to post the bind work request on.
1449 * @mw: The memory window to bind.
1450 * @mw_bind: Specifies information about the memory window, including
1451 * its address range, remote access rights, and associated memory region.
1453 static inline int ib_bind_mw(struct ib_qp *qp,
1455 struct ib_mw_bind *mw_bind)
1457 /* XXX reference counting in corresponding MR? */
1458 return mw->device->bind_mw ?
1459 mw->device->bind_mw(qp, mw, mw_bind) :
1464 * ib_dealloc_mw - Deallocates a memory window.
1465 * @mw: The memory window to deallocate.
1467 int ib_dealloc_mw(struct ib_mw *mw);
1470 * ib_alloc_fmr - Allocates a unmapped fast memory region.
1471 * @pd: The protection domain associated with the unmapped region.
1472 * @mr_access_flags: Specifies the memory access rights.
1473 * @fmr_attr: Attributes of the unmapped region.
1475 * A fast memory region must be mapped before it can be used as part of
1478 struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
1479 int mr_access_flags,
1480 struct ib_fmr_attr *fmr_attr);
1483 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
1484 * @fmr: The fast memory region to associate with the pages.
1485 * @page_list: An array of physical pages to map to the fast memory region.
1486 * @list_len: The number of pages in page_list.
1487 * @iova: The I/O virtual address to use with the mapped region.
1489 static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
1490 u64 *page_list, int list_len,
1493 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
1497 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
1498 * @fmr_list: A linked list of fast memory regions to unmap.
1500 int ib_unmap_fmr(struct list_head *fmr_list);
1503 * ib_dealloc_fmr - Deallocates a fast memory region.
1504 * @fmr: The fast memory region to deallocate.
1506 int ib_dealloc_fmr(struct ib_fmr *fmr);
1509 * ib_attach_mcast - Attaches the specified QP to a multicast group.
1510 * @qp: QP to attach to the multicast group. The QP must be type
1512 * @gid: Multicast group GID.
1513 * @lid: Multicast group LID in host byte order.
1515 * In order to send and receive multicast packets, subnet
1516 * administration must have created the multicast group and configured
1517 * the fabric appropriately. The port associated with the specified
1518 * QP must also be a member of the multicast group.
1520 int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
1523 * ib_detach_mcast - Detaches the specified QP from a multicast group.
1524 * @qp: QP to detach from the multicast group.
1525 * @gid: Multicast group GID.
1526 * @lid: Multicast group LID in host byte order.
1528 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
1530 #endif /* IB_VERBS_H */