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.
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
39 #if !defined(IB_VERBS_H)
42 #include <linux/types.h>
43 #include <linux/device.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>
52 #include <linux/atomic.h>
53 #include <asm/uaccess.h>
55 extern struct workqueue_struct
*ib_wq
;
66 /* IB values map to NodeInfo:NodeType. */
73 enum rdma_transport_type
{
78 enum rdma_transport_type
79 rdma_node_get_transport(enum rdma_node_type node_type
) __attribute_const__
;
81 enum rdma_link_layer
{
82 IB_LINK_LAYER_UNSPECIFIED
,
83 IB_LINK_LAYER_INFINIBAND
,
84 IB_LINK_LAYER_ETHERNET
,
87 enum ib_device_cap_flags
{
88 IB_DEVICE_RESIZE_MAX_WR
= 1,
89 IB_DEVICE_BAD_PKEY_CNTR
= (1<<1),
90 IB_DEVICE_BAD_QKEY_CNTR
= (1<<2),
91 IB_DEVICE_RAW_MULTI
= (1<<3),
92 IB_DEVICE_AUTO_PATH_MIG
= (1<<4),
93 IB_DEVICE_CHANGE_PHY_PORT
= (1<<5),
94 IB_DEVICE_UD_AV_PORT_ENFORCE
= (1<<6),
95 IB_DEVICE_CURR_QP_STATE_MOD
= (1<<7),
96 IB_DEVICE_SHUTDOWN_PORT
= (1<<8),
97 IB_DEVICE_INIT_TYPE
= (1<<9),
98 IB_DEVICE_PORT_ACTIVE_EVENT
= (1<<10),
99 IB_DEVICE_SYS_IMAGE_GUID
= (1<<11),
100 IB_DEVICE_RC_RNR_NAK_GEN
= (1<<12),
101 IB_DEVICE_SRQ_RESIZE
= (1<<13),
102 IB_DEVICE_N_NOTIFY_CQ
= (1<<14),
103 IB_DEVICE_LOCAL_DMA_LKEY
= (1<<15),
104 IB_DEVICE_RESERVED
= (1<<16), /* old SEND_W_INV */
105 IB_DEVICE_MEM_WINDOW
= (1<<17),
107 * Devices should set IB_DEVICE_UD_IP_SUM if they support
108 * insertion of UDP and TCP checksum on outgoing UD IPoIB
109 * messages and can verify the validity of checksum for
110 * incoming messages. Setting this flag implies that the
111 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
113 IB_DEVICE_UD_IP_CSUM
= (1<<18),
114 IB_DEVICE_UD_TSO
= (1<<19),
115 IB_DEVICE_XRC
= (1<<20),
116 IB_DEVICE_MEM_MGT_EXTENSIONS
= (1<<21),
117 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK
= (1<<22),
126 struct ib_device_attr
{
128 __be64 sys_image_guid
;
136 int device_cap_flags
;
146 int max_qp_init_rd_atom
;
147 int max_ee_init_rd_atom
;
148 enum ib_atomic_cap atomic_cap
;
149 enum ib_atomic_cap masked_atomic_cap
;
156 int max_mcast_qp_attach
;
157 int max_total_mcast_qp_attach
;
164 unsigned int max_fast_reg_page_list_len
;
166 u8 local_ca_ack_delay
;
177 static inline int ib_mtu_enum_to_int(enum ib_mtu mtu
)
180 case IB_MTU_256
: return 256;
181 case IB_MTU_512
: return 512;
182 case IB_MTU_1024
: return 1024;
183 case IB_MTU_2048
: return 2048;
184 case IB_MTU_4096
: return 4096;
195 IB_PORT_ACTIVE_DEFER
= 5
198 enum ib_port_cap_flags
{
200 IB_PORT_NOTICE_SUP
= 1 << 2,
201 IB_PORT_TRAP_SUP
= 1 << 3,
202 IB_PORT_OPT_IPD_SUP
= 1 << 4,
203 IB_PORT_AUTO_MIGR_SUP
= 1 << 5,
204 IB_PORT_SL_MAP_SUP
= 1 << 6,
205 IB_PORT_MKEY_NVRAM
= 1 << 7,
206 IB_PORT_PKEY_NVRAM
= 1 << 8,
207 IB_PORT_LED_INFO_SUP
= 1 << 9,
208 IB_PORT_SM_DISABLED
= 1 << 10,
209 IB_PORT_SYS_IMAGE_GUID_SUP
= 1 << 11,
210 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP
= 1 << 12,
211 IB_PORT_CM_SUP
= 1 << 16,
212 IB_PORT_SNMP_TUNNEL_SUP
= 1 << 17,
213 IB_PORT_REINIT_SUP
= 1 << 18,
214 IB_PORT_DEVICE_MGMT_SUP
= 1 << 19,
215 IB_PORT_VENDOR_CLASS_SUP
= 1 << 20,
216 IB_PORT_DR_NOTICE_SUP
= 1 << 21,
217 IB_PORT_CAP_MASK_NOTICE_SUP
= 1 << 22,
218 IB_PORT_BOOT_MGMT_SUP
= 1 << 23,
219 IB_PORT_LINK_LATENCY_SUP
= 1 << 24,
220 IB_PORT_CLIENT_REG_SUP
= 1 << 25
230 static inline int ib_width_enum_to_int(enum ib_port_width width
)
233 case IB_WIDTH_1X
: return 1;
234 case IB_WIDTH_4X
: return 4;
235 case IB_WIDTH_8X
: return 8;
236 case IB_WIDTH_12X
: return 12;
241 struct ib_protocol_stats
{
245 struct iw_protocol_stats
{
248 u64 ipInTooBigErrors
;
251 u64 ipInUnknownProtos
;
252 u64 ipInTruncatedPkts
;
255 u64 ipOutForwDatagrams
;
287 union rdma_protocol_stats
{
288 struct ib_protocol_stats ib
;
289 struct iw_protocol_stats iw
;
292 struct ib_port_attr
{
293 enum ib_port_state state
;
295 enum ib_mtu active_mtu
;
314 enum ib_device_modify_flags
{
315 IB_DEVICE_MODIFY_SYS_IMAGE_GUID
= 1 << 0,
316 IB_DEVICE_MODIFY_NODE_DESC
= 1 << 1
319 struct ib_device_modify
{
324 enum ib_port_modify_flags
{
325 IB_PORT_SHUTDOWN
= 1,
326 IB_PORT_INIT_TYPE
= (1<<2),
327 IB_PORT_RESET_QKEY_CNTR
= (1<<3)
330 struct ib_port_modify
{
331 u32 set_port_cap_mask
;
332 u32 clr_port_cap_mask
;
340 IB_EVENT_QP_ACCESS_ERR
,
344 IB_EVENT_PATH_MIG_ERR
,
345 IB_EVENT_DEVICE_FATAL
,
346 IB_EVENT_PORT_ACTIVE
,
349 IB_EVENT_PKEY_CHANGE
,
352 IB_EVENT_SRQ_LIMIT_REACHED
,
353 IB_EVENT_QP_LAST_WQE_REACHED
,
354 IB_EVENT_CLIENT_REREGISTER
,
359 struct ib_device
*device
;
366 enum ib_event_type event
;
369 struct ib_event_handler
{
370 struct ib_device
*device
;
371 void (*handler
)(struct ib_event_handler
*, struct ib_event
*);
372 struct list_head list
;
375 #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
377 (_ptr)->device = _device; \
378 (_ptr)->handler = _handler; \
379 INIT_LIST_HEAD(&(_ptr)->list); \
382 struct ib_global_route
{
391 __be32 version_tclass_flow
;
400 IB_MULTICAST_QPN
= 0xffffff
403 #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
410 IB_RATE_PORT_CURRENT
= 0,
411 IB_RATE_2_5_GBPS
= 2,
419 IB_RATE_120_GBPS
= 10
423 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
424 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
425 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
426 * @rate: rate to convert.
428 int ib_rate_to_mult(enum ib_rate rate
) __attribute_const__
;
431 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
433 * @mult: multiple to convert.
435 enum ib_rate
mult_to_ib_rate(int mult
) __attribute_const__
;
438 struct ib_global_route grh
;
451 IB_WC_LOC_EEC_OP_ERR
,
456 IB_WC_LOC_ACCESS_ERR
,
457 IB_WC_REM_INV_REQ_ERR
,
458 IB_WC_REM_ACCESS_ERR
,
461 IB_WC_RNR_RETRY_EXC_ERR
,
462 IB_WC_LOC_RDD_VIOL_ERR
,
463 IB_WC_REM_INV_RD_REQ_ERR
,
466 IB_WC_INV_EEC_STATE_ERR
,
468 IB_WC_RESP_TIMEOUT_ERR
,
482 IB_WC_MASKED_COMP_SWAP
,
483 IB_WC_MASKED_FETCH_ADD
,
485 * Set value of IB_WC_RECV so consumers can test if a completion is a
486 * receive by testing (opcode & IB_WC_RECV).
489 IB_WC_RECV_RDMA_WITH_IMM
494 IB_WC_WITH_IMM
= (1<<1),
495 IB_WC_WITH_INVALIDATE
= (1<<2),
500 enum ib_wc_status status
;
501 enum ib_wc_opcode opcode
;
515 u8 port_num
; /* valid only for DR SMPs on switches */
519 enum ib_cq_notify_flags
{
520 IB_CQ_SOLICITED
= 1 << 0,
521 IB_CQ_NEXT_COMP
= 1 << 1,
522 IB_CQ_SOLICITED_MASK
= IB_CQ_SOLICITED
| IB_CQ_NEXT_COMP
,
523 IB_CQ_REPORT_MISSED_EVENTS
= 1 << 2,
526 enum ib_srq_attr_mask
{
527 IB_SRQ_MAX_WR
= 1 << 0,
528 IB_SRQ_LIMIT
= 1 << 1,
537 struct ib_srq_init_attr
{
538 void (*event_handler
)(struct ib_event
*, void *);
540 struct ib_srq_attr attr
;
558 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
559 * here (and in that order) since the MAD layer uses them as
560 * indices into a 2-entry table.
572 enum ib_qp_create_flags
{
573 IB_QP_CREATE_IPOIB_UD_LSO
= 1 << 0,
574 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK
= 1 << 1,
577 struct ib_qp_init_attr
{
578 void (*event_handler
)(struct ib_event
*, void *);
580 struct ib_cq
*send_cq
;
581 struct ib_cq
*recv_cq
;
583 struct ib_qp_cap cap
;
584 enum ib_sig_type sq_sig_type
;
585 enum ib_qp_type qp_type
;
586 enum ib_qp_create_flags create_flags
;
587 u8 port_num
; /* special QP types only */
590 enum ib_rnr_timeout
{
591 IB_RNR_TIMER_655_36
= 0,
592 IB_RNR_TIMER_000_01
= 1,
593 IB_RNR_TIMER_000_02
= 2,
594 IB_RNR_TIMER_000_03
= 3,
595 IB_RNR_TIMER_000_04
= 4,
596 IB_RNR_TIMER_000_06
= 5,
597 IB_RNR_TIMER_000_08
= 6,
598 IB_RNR_TIMER_000_12
= 7,
599 IB_RNR_TIMER_000_16
= 8,
600 IB_RNR_TIMER_000_24
= 9,
601 IB_RNR_TIMER_000_32
= 10,
602 IB_RNR_TIMER_000_48
= 11,
603 IB_RNR_TIMER_000_64
= 12,
604 IB_RNR_TIMER_000_96
= 13,
605 IB_RNR_TIMER_001_28
= 14,
606 IB_RNR_TIMER_001_92
= 15,
607 IB_RNR_TIMER_002_56
= 16,
608 IB_RNR_TIMER_003_84
= 17,
609 IB_RNR_TIMER_005_12
= 18,
610 IB_RNR_TIMER_007_68
= 19,
611 IB_RNR_TIMER_010_24
= 20,
612 IB_RNR_TIMER_015_36
= 21,
613 IB_RNR_TIMER_020_48
= 22,
614 IB_RNR_TIMER_030_72
= 23,
615 IB_RNR_TIMER_040_96
= 24,
616 IB_RNR_TIMER_061_44
= 25,
617 IB_RNR_TIMER_081_92
= 26,
618 IB_RNR_TIMER_122_88
= 27,
619 IB_RNR_TIMER_163_84
= 28,
620 IB_RNR_TIMER_245_76
= 29,
621 IB_RNR_TIMER_327_68
= 30,
622 IB_RNR_TIMER_491_52
= 31
625 enum ib_qp_attr_mask
{
627 IB_QP_CUR_STATE
= (1<<1),
628 IB_QP_EN_SQD_ASYNC_NOTIFY
= (1<<2),
629 IB_QP_ACCESS_FLAGS
= (1<<3),
630 IB_QP_PKEY_INDEX
= (1<<4),
634 IB_QP_PATH_MTU
= (1<<8),
635 IB_QP_TIMEOUT
= (1<<9),
636 IB_QP_RETRY_CNT
= (1<<10),
637 IB_QP_RNR_RETRY
= (1<<11),
638 IB_QP_RQ_PSN
= (1<<12),
639 IB_QP_MAX_QP_RD_ATOMIC
= (1<<13),
640 IB_QP_ALT_PATH
= (1<<14),
641 IB_QP_MIN_RNR_TIMER
= (1<<15),
642 IB_QP_SQ_PSN
= (1<<16),
643 IB_QP_MAX_DEST_RD_ATOMIC
= (1<<17),
644 IB_QP_PATH_MIG_STATE
= (1<<18),
646 IB_QP_DEST_QPN
= (1<<20)
666 enum ib_qp_state qp_state
;
667 enum ib_qp_state cur_qp_state
;
668 enum ib_mtu path_mtu
;
669 enum ib_mig_state path_mig_state
;
675 struct ib_qp_cap cap
;
676 struct ib_ah_attr ah_attr
;
677 struct ib_ah_attr alt_ah_attr
;
680 u8 en_sqd_async_notify
;
683 u8 max_dest_rd_atomic
;
695 IB_WR_RDMA_WRITE_WITH_IMM
,
699 IB_WR_ATOMIC_CMP_AND_SWP
,
700 IB_WR_ATOMIC_FETCH_AND_ADD
,
703 IB_WR_RDMA_READ_WITH_INV
,
706 IB_WR_MASKED_ATOMIC_CMP_AND_SWP
,
707 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD
,
712 IB_SEND_SIGNALED
= (1<<1),
713 IB_SEND_SOLICITED
= (1<<2),
714 IB_SEND_INLINE
= (1<<3),
715 IB_SEND_IP_CSUM
= (1<<4)
724 struct ib_fast_reg_page_list
{
725 struct ib_device
*device
;
727 unsigned int max_page_list_len
;
731 struct ib_send_wr
*next
;
733 struct ib_sge
*sg_list
;
735 enum ib_wr_opcode opcode
;
750 u64 compare_add_mask
;
761 u16 pkey_index
; /* valid for GSI only */
762 u8 port_num
; /* valid for DR SMPs on switch only */
766 struct ib_fast_reg_page_list
*page_list
;
767 unsigned int page_shift
;
768 unsigned int page_list_len
;
777 struct ib_recv_wr
*next
;
779 struct ib_sge
*sg_list
;
783 enum ib_access_flags
{
784 IB_ACCESS_LOCAL_WRITE
= 1,
785 IB_ACCESS_REMOTE_WRITE
= (1<<1),
786 IB_ACCESS_REMOTE_READ
= (1<<2),
787 IB_ACCESS_REMOTE_ATOMIC
= (1<<3),
788 IB_ACCESS_MW_BIND
= (1<<4)
798 u64 device_virt_addr
;
805 enum ib_mr_rereg_flags
{
806 IB_MR_REREG_TRANS
= 1,
807 IB_MR_REREG_PD
= (1<<1),
808 IB_MR_REREG_ACCESS
= (1<<2)
827 struct ib_device
*device
;
828 struct list_head pd_list
;
829 struct list_head mr_list
;
830 struct list_head mw_list
;
831 struct list_head cq_list
;
832 struct list_head qp_list
;
833 struct list_head srq_list
;
834 struct list_head ah_list
;
839 u64 user_handle
; /* handle given to us by userspace */
840 struct ib_ucontext
*context
; /* associated user context */
841 void *object
; /* containing object */
842 struct list_head list
; /* link to context's list */
843 int id
; /* index into kernel idr */
845 struct rw_semaphore mutex
; /* protects .live */
857 struct ib_device
*device
;
858 struct ib_uobject
*uobject
;
859 atomic_t usecnt
; /* count all resources */
863 struct ib_device
*device
;
864 atomic_t usecnt
; /* count all resources */
868 struct ib_device
*device
;
870 struct ib_uobject
*uobject
;
873 typedef void (*ib_comp_handler
)(struct ib_cq
*cq
, void *cq_context
);
876 struct ib_device
*device
;
877 struct ib_uobject
*uobject
;
878 ib_comp_handler comp_handler
;
879 void (*event_handler
)(struct ib_event
*, void *);
882 atomic_t usecnt
; /* count number of work queues */
886 struct ib_device
*device
;
888 struct ib_uobject
*uobject
;
889 void (*event_handler
)(struct ib_event
*, void *);
895 struct ib_device
*device
;
897 struct ib_cq
*send_cq
;
898 struct ib_cq
*recv_cq
;
900 struct ib_uobject
*uobject
;
901 void (*event_handler
)(struct ib_event
*, void *);
904 enum ib_qp_type qp_type
;
908 struct ib_device
*device
;
910 struct ib_uobject
*uobject
;
913 atomic_t usecnt
; /* count number of MWs */
917 struct ib_device
*device
;
919 struct ib_uobject
*uobject
;
924 struct ib_device
*device
;
926 struct list_head list
;
934 enum ib_process_mad_flags
{
935 IB_MAD_IGNORE_MKEY
= 1,
936 IB_MAD_IGNORE_BKEY
= 2,
937 IB_MAD_IGNORE_ALL
= IB_MAD_IGNORE_MKEY
| IB_MAD_IGNORE_BKEY
941 IB_MAD_RESULT_FAILURE
= 0, /* (!SUCCESS is the important flag) */
942 IB_MAD_RESULT_SUCCESS
= 1 << 0, /* MAD was successfully processed */
943 IB_MAD_RESULT_REPLY
= 1 << 1, /* Reply packet needs to be sent */
944 IB_MAD_RESULT_CONSUMED
= 1 << 2 /* Packet consumed: stop processing */
947 #define IB_DEVICE_NAME_MAX 64
951 struct ib_event_handler event_handler
;
952 struct ib_pkey_cache
**pkey_cache
;
953 struct ib_gid_cache
**gid_cache
;
957 struct ib_dma_mapping_ops
{
958 int (*mapping_error
)(struct ib_device
*dev
,
960 u64 (*map_single
)(struct ib_device
*dev
,
961 void *ptr
, size_t size
,
962 enum dma_data_direction direction
);
963 void (*unmap_single
)(struct ib_device
*dev
,
964 u64 addr
, size_t size
,
965 enum dma_data_direction direction
);
966 u64 (*map_page
)(struct ib_device
*dev
,
967 struct page
*page
, unsigned long offset
,
969 enum dma_data_direction direction
);
970 void (*unmap_page
)(struct ib_device
*dev
,
971 u64 addr
, size_t size
,
972 enum dma_data_direction direction
);
973 int (*map_sg
)(struct ib_device
*dev
,
974 struct scatterlist
*sg
, int nents
,
975 enum dma_data_direction direction
);
976 void (*unmap_sg
)(struct ib_device
*dev
,
977 struct scatterlist
*sg
, int nents
,
978 enum dma_data_direction direction
);
979 u64 (*dma_address
)(struct ib_device
*dev
,
980 struct scatterlist
*sg
);
981 unsigned int (*dma_len
)(struct ib_device
*dev
,
982 struct scatterlist
*sg
);
983 void (*sync_single_for_cpu
)(struct ib_device
*dev
,
986 enum dma_data_direction dir
);
987 void (*sync_single_for_device
)(struct ib_device
*dev
,
990 enum dma_data_direction dir
);
991 void *(*alloc_coherent
)(struct ib_device
*dev
,
995 void (*free_coherent
)(struct ib_device
*dev
,
996 size_t size
, void *cpu_addr
,
1003 struct device
*dma_device
;
1005 char name
[IB_DEVICE_NAME_MAX
];
1007 struct list_head event_handler_list
;
1008 spinlock_t event_handler_lock
;
1010 spinlock_t client_data_lock
;
1011 struct list_head core_list
;
1012 struct list_head client_data_list
;
1014 struct ib_cache cache
;
1018 int num_comp_vectors
;
1020 struct iw_cm_verbs
*iwcm
;
1022 int (*get_protocol_stats
)(struct ib_device
*device
,
1023 union rdma_protocol_stats
*stats
);
1024 int (*query_device
)(struct ib_device
*device
,
1025 struct ib_device_attr
*device_attr
);
1026 int (*query_port
)(struct ib_device
*device
,
1028 struct ib_port_attr
*port_attr
);
1029 enum rdma_link_layer (*get_link_layer
)(struct ib_device
*device
,
1031 int (*query_gid
)(struct ib_device
*device
,
1032 u8 port_num
, int index
,
1034 int (*query_pkey
)(struct ib_device
*device
,
1035 u8 port_num
, u16 index
, u16
*pkey
);
1036 int (*modify_device
)(struct ib_device
*device
,
1037 int device_modify_mask
,
1038 struct ib_device_modify
*device_modify
);
1039 int (*modify_port
)(struct ib_device
*device
,
1040 u8 port_num
, int port_modify_mask
,
1041 struct ib_port_modify
*port_modify
);
1042 struct ib_ucontext
* (*alloc_ucontext
)(struct ib_device
*device
,
1043 struct ib_udata
*udata
);
1044 int (*dealloc_ucontext
)(struct ib_ucontext
*context
);
1045 int (*mmap
)(struct ib_ucontext
*context
,
1046 struct vm_area_struct
*vma
);
1047 struct ib_pd
* (*alloc_pd
)(struct ib_device
*device
,
1048 struct ib_ucontext
*context
,
1049 struct ib_udata
*udata
);
1050 int (*dealloc_pd
)(struct ib_pd
*pd
);
1051 struct ib_ah
* (*create_ah
)(struct ib_pd
*pd
,
1052 struct ib_ah_attr
*ah_attr
);
1053 int (*modify_ah
)(struct ib_ah
*ah
,
1054 struct ib_ah_attr
*ah_attr
);
1055 int (*query_ah
)(struct ib_ah
*ah
,
1056 struct ib_ah_attr
*ah_attr
);
1057 int (*destroy_ah
)(struct ib_ah
*ah
);
1058 struct ib_srq
* (*create_srq
)(struct ib_pd
*pd
,
1059 struct ib_srq_init_attr
*srq_init_attr
,
1060 struct ib_udata
*udata
);
1061 int (*modify_srq
)(struct ib_srq
*srq
,
1062 struct ib_srq_attr
*srq_attr
,
1063 enum ib_srq_attr_mask srq_attr_mask
,
1064 struct ib_udata
*udata
);
1065 int (*query_srq
)(struct ib_srq
*srq
,
1066 struct ib_srq_attr
*srq_attr
);
1067 int (*destroy_srq
)(struct ib_srq
*srq
);
1068 int (*post_srq_recv
)(struct ib_srq
*srq
,
1069 struct ib_recv_wr
*recv_wr
,
1070 struct ib_recv_wr
**bad_recv_wr
);
1071 struct ib_qp
* (*create_qp
)(struct ib_pd
*pd
,
1072 struct ib_qp_init_attr
*qp_init_attr
,
1073 struct ib_udata
*udata
);
1074 int (*modify_qp
)(struct ib_qp
*qp
,
1075 struct ib_qp_attr
*qp_attr
,
1077 struct ib_udata
*udata
);
1078 int (*query_qp
)(struct ib_qp
*qp
,
1079 struct ib_qp_attr
*qp_attr
,
1081 struct ib_qp_init_attr
*qp_init_attr
);
1082 int (*destroy_qp
)(struct ib_qp
*qp
);
1083 int (*post_send
)(struct ib_qp
*qp
,
1084 struct ib_send_wr
*send_wr
,
1085 struct ib_send_wr
**bad_send_wr
);
1086 int (*post_recv
)(struct ib_qp
*qp
,
1087 struct ib_recv_wr
*recv_wr
,
1088 struct ib_recv_wr
**bad_recv_wr
);
1089 struct ib_cq
* (*create_cq
)(struct ib_device
*device
, int cqe
,
1091 struct ib_ucontext
*context
,
1092 struct ib_udata
*udata
);
1093 int (*modify_cq
)(struct ib_cq
*cq
, u16 cq_count
,
1095 int (*destroy_cq
)(struct ib_cq
*cq
);
1096 int (*resize_cq
)(struct ib_cq
*cq
, int cqe
,
1097 struct ib_udata
*udata
);
1098 int (*poll_cq
)(struct ib_cq
*cq
, int num_entries
,
1100 int (*peek_cq
)(struct ib_cq
*cq
, int wc_cnt
);
1101 int (*req_notify_cq
)(struct ib_cq
*cq
,
1102 enum ib_cq_notify_flags flags
);
1103 int (*req_ncomp_notif
)(struct ib_cq
*cq
,
1105 struct ib_mr
* (*get_dma_mr
)(struct ib_pd
*pd
,
1106 int mr_access_flags
);
1107 struct ib_mr
* (*reg_phys_mr
)(struct ib_pd
*pd
,
1108 struct ib_phys_buf
*phys_buf_array
,
1110 int mr_access_flags
,
1112 struct ib_mr
* (*reg_user_mr
)(struct ib_pd
*pd
,
1113 u64 start
, u64 length
,
1115 int mr_access_flags
,
1116 struct ib_udata
*udata
);
1117 int (*query_mr
)(struct ib_mr
*mr
,
1118 struct ib_mr_attr
*mr_attr
);
1119 int (*dereg_mr
)(struct ib_mr
*mr
);
1120 struct ib_mr
* (*alloc_fast_reg_mr
)(struct ib_pd
*pd
,
1121 int max_page_list_len
);
1122 struct ib_fast_reg_page_list
* (*alloc_fast_reg_page_list
)(struct ib_device
*device
,
1124 void (*free_fast_reg_page_list
)(struct ib_fast_reg_page_list
*page_list
);
1125 int (*rereg_phys_mr
)(struct ib_mr
*mr
,
1128 struct ib_phys_buf
*phys_buf_array
,
1130 int mr_access_flags
,
1132 struct ib_mw
* (*alloc_mw
)(struct ib_pd
*pd
);
1133 int (*bind_mw
)(struct ib_qp
*qp
,
1135 struct ib_mw_bind
*mw_bind
);
1136 int (*dealloc_mw
)(struct ib_mw
*mw
);
1137 struct ib_fmr
* (*alloc_fmr
)(struct ib_pd
*pd
,
1138 int mr_access_flags
,
1139 struct ib_fmr_attr
*fmr_attr
);
1140 int (*map_phys_fmr
)(struct ib_fmr
*fmr
,
1141 u64
*page_list
, int list_len
,
1143 int (*unmap_fmr
)(struct list_head
*fmr_list
);
1144 int (*dealloc_fmr
)(struct ib_fmr
*fmr
);
1145 int (*attach_mcast
)(struct ib_qp
*qp
,
1148 int (*detach_mcast
)(struct ib_qp
*qp
,
1151 int (*process_mad
)(struct ib_device
*device
,
1152 int process_mad_flags
,
1154 struct ib_wc
*in_wc
,
1155 struct ib_grh
*in_grh
,
1156 struct ib_mad
*in_mad
,
1157 struct ib_mad
*out_mad
);
1158 struct ib_xrcd
* (*alloc_xrcd
)(struct ib_device
*device
,
1159 struct ib_ucontext
*ucontext
,
1160 struct ib_udata
*udata
);
1161 int (*dealloc_xrcd
)(struct ib_xrcd
*xrcd
);
1163 struct ib_dma_mapping_ops
*dma_ops
;
1165 struct module
*owner
;
1167 struct kobject
*ports_parent
;
1168 struct list_head port_list
;
1171 IB_DEV_UNINITIALIZED
,
1177 u64 uverbs_cmd_mask
;
1188 void (*add
) (struct ib_device
*);
1189 void (*remove
)(struct ib_device
*);
1191 struct list_head list
;
1194 struct ib_device
*ib_alloc_device(size_t size
);
1195 void ib_dealloc_device(struct ib_device
*device
);
1197 int ib_register_device(struct ib_device
*device
,
1198 int (*port_callback
)(struct ib_device
*,
1199 u8
, struct kobject
*));
1200 void ib_unregister_device(struct ib_device
*device
);
1202 int ib_register_client (struct ib_client
*client
);
1203 void ib_unregister_client(struct ib_client
*client
);
1205 void *ib_get_client_data(struct ib_device
*device
, struct ib_client
*client
);
1206 void ib_set_client_data(struct ib_device
*device
, struct ib_client
*client
,
1209 static inline int ib_copy_from_udata(void *dest
, struct ib_udata
*udata
, size_t len
)
1211 return copy_from_user(dest
, udata
->inbuf
, len
) ? -EFAULT
: 0;
1214 static inline int ib_copy_to_udata(struct ib_udata
*udata
, void *src
, size_t len
)
1216 return copy_to_user(udata
->outbuf
, src
, len
) ? -EFAULT
: 0;
1220 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1221 * contains all required attributes and no attributes not allowed for
1222 * the given QP state transition.
1223 * @cur_state: Current QP state
1224 * @next_state: Next QP state
1226 * @mask: Mask of supplied QP attributes
1228 * This function is a helper function that a low-level driver's
1229 * modify_qp method can use to validate the consumer's input. It
1230 * checks that cur_state and next_state are valid QP states, that a
1231 * transition from cur_state to next_state is allowed by the IB spec,
1232 * and that the attribute mask supplied is allowed for the transition.
1234 int ib_modify_qp_is_ok(enum ib_qp_state cur_state
, enum ib_qp_state next_state
,
1235 enum ib_qp_type type
, enum ib_qp_attr_mask mask
);
1237 int ib_register_event_handler (struct ib_event_handler
*event_handler
);
1238 int ib_unregister_event_handler(struct ib_event_handler
*event_handler
);
1239 void ib_dispatch_event(struct ib_event
*event
);
1241 int ib_query_device(struct ib_device
*device
,
1242 struct ib_device_attr
*device_attr
);
1244 int ib_query_port(struct ib_device
*device
,
1245 u8 port_num
, struct ib_port_attr
*port_attr
);
1247 enum rdma_link_layer
rdma_port_get_link_layer(struct ib_device
*device
,
1250 int ib_query_gid(struct ib_device
*device
,
1251 u8 port_num
, int index
, union ib_gid
*gid
);
1253 int ib_query_pkey(struct ib_device
*device
,
1254 u8 port_num
, u16 index
, u16
*pkey
);
1256 int ib_modify_device(struct ib_device
*device
,
1257 int device_modify_mask
,
1258 struct ib_device_modify
*device_modify
);
1260 int ib_modify_port(struct ib_device
*device
,
1261 u8 port_num
, int port_modify_mask
,
1262 struct ib_port_modify
*port_modify
);
1264 int ib_find_gid(struct ib_device
*device
, union ib_gid
*gid
,
1265 u8
*port_num
, u16
*index
);
1267 int ib_find_pkey(struct ib_device
*device
,
1268 u8 port_num
, u16 pkey
, u16
*index
);
1271 * ib_alloc_pd - Allocates an unused protection domain.
1272 * @device: The device on which to allocate the protection domain.
1274 * A protection domain object provides an association between QPs, shared
1275 * receive queues, address handles, memory regions, and memory windows.
1277 struct ib_pd
*ib_alloc_pd(struct ib_device
*device
);
1280 * ib_dealloc_pd - Deallocates a protection domain.
1281 * @pd: The protection domain to deallocate.
1283 int ib_dealloc_pd(struct ib_pd
*pd
);
1286 * ib_create_ah - Creates an address handle for the given address vector.
1287 * @pd: The protection domain associated with the address handle.
1288 * @ah_attr: The attributes of the address vector.
1290 * The address handle is used to reference a local or global destination
1291 * in all UD QP post sends.
1293 struct ib_ah
*ib_create_ah(struct ib_pd
*pd
, struct ib_ah_attr
*ah_attr
);
1296 * ib_init_ah_from_wc - Initializes address handle attributes from a
1298 * @device: Device on which the received message arrived.
1299 * @port_num: Port on which the received message arrived.
1300 * @wc: Work completion associated with the received message.
1301 * @grh: References the received global route header. This parameter is
1302 * ignored unless the work completion indicates that the GRH is valid.
1303 * @ah_attr: Returned attributes that can be used when creating an address
1304 * handle for replying to the message.
1306 int ib_init_ah_from_wc(struct ib_device
*device
, u8 port_num
, struct ib_wc
*wc
,
1307 struct ib_grh
*grh
, struct ib_ah_attr
*ah_attr
);
1310 * ib_create_ah_from_wc - Creates an address handle associated with the
1311 * sender of the specified work completion.
1312 * @pd: The protection domain associated with the address handle.
1313 * @wc: Work completion information associated with a received message.
1314 * @grh: References the received global route header. This parameter is
1315 * ignored unless the work completion indicates that the GRH is valid.
1316 * @port_num: The outbound port number to associate with the address.
1318 * The address handle is used to reference a local or global destination
1319 * in all UD QP post sends.
1321 struct ib_ah
*ib_create_ah_from_wc(struct ib_pd
*pd
, struct ib_wc
*wc
,
1322 struct ib_grh
*grh
, u8 port_num
);
1325 * ib_modify_ah - Modifies the address vector associated with an address
1327 * @ah: The address handle to modify.
1328 * @ah_attr: The new address vector attributes to associate with the
1331 int ib_modify_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
);
1334 * ib_query_ah - Queries the address vector associated with an address
1336 * @ah: The address handle to query.
1337 * @ah_attr: The address vector attributes associated with the address
1340 int ib_query_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
);
1343 * ib_destroy_ah - Destroys an address handle.
1344 * @ah: The address handle to destroy.
1346 int ib_destroy_ah(struct ib_ah
*ah
);
1349 * ib_create_srq - Creates a SRQ associated with the specified protection
1351 * @pd: The protection domain associated with the SRQ.
1352 * @srq_init_attr: A list of initial attributes required to create the
1353 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1354 * the actual capabilities of the created SRQ.
1356 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1357 * requested size of the SRQ, and set to the actual values allocated
1358 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1359 * will always be at least as large as the requested values.
1361 struct ib_srq
*ib_create_srq(struct ib_pd
*pd
,
1362 struct ib_srq_init_attr
*srq_init_attr
);
1365 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1366 * @srq: The SRQ to modify.
1367 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1368 * the current values of selected SRQ attributes are returned.
1369 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1370 * are being modified.
1372 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1373 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1374 * the number of receives queued drops below the limit.
1376 int ib_modify_srq(struct ib_srq
*srq
,
1377 struct ib_srq_attr
*srq_attr
,
1378 enum ib_srq_attr_mask srq_attr_mask
);
1381 * ib_query_srq - Returns the attribute list and current values for the
1383 * @srq: The SRQ to query.
1384 * @srq_attr: The attributes of the specified SRQ.
1386 int ib_query_srq(struct ib_srq
*srq
,
1387 struct ib_srq_attr
*srq_attr
);
1390 * ib_destroy_srq - Destroys the specified SRQ.
1391 * @srq: The SRQ to destroy.
1393 int ib_destroy_srq(struct ib_srq
*srq
);
1396 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1397 * @srq: The SRQ to post the work request on.
1398 * @recv_wr: A list of work requests to post on the receive queue.
1399 * @bad_recv_wr: On an immediate failure, this parameter will reference
1400 * the work request that failed to be posted on the QP.
1402 static inline int ib_post_srq_recv(struct ib_srq
*srq
,
1403 struct ib_recv_wr
*recv_wr
,
1404 struct ib_recv_wr
**bad_recv_wr
)
1406 return srq
->device
->post_srq_recv(srq
, recv_wr
, bad_recv_wr
);
1410 * ib_create_qp - Creates a QP associated with the specified protection
1412 * @pd: The protection domain associated with the QP.
1413 * @qp_init_attr: A list of initial attributes required to create the
1414 * QP. If QP creation succeeds, then the attributes are updated to
1415 * the actual capabilities of the created QP.
1417 struct ib_qp
*ib_create_qp(struct ib_pd
*pd
,
1418 struct ib_qp_init_attr
*qp_init_attr
);
1421 * ib_modify_qp - Modifies the attributes for the specified QP and then
1422 * transitions the QP to the given state.
1423 * @qp: The QP to modify.
1424 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1425 * the current values of selected QP attributes are returned.
1426 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1427 * are being modified.
1429 int ib_modify_qp(struct ib_qp
*qp
,
1430 struct ib_qp_attr
*qp_attr
,
1434 * ib_query_qp - Returns the attribute list and current values for the
1436 * @qp: The QP to query.
1437 * @qp_attr: The attributes of the specified QP.
1438 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1439 * @qp_init_attr: Additional attributes of the selected QP.
1441 * The qp_attr_mask may be used to limit the query to gathering only the
1442 * selected attributes.
1444 int ib_query_qp(struct ib_qp
*qp
,
1445 struct ib_qp_attr
*qp_attr
,
1447 struct ib_qp_init_attr
*qp_init_attr
);
1450 * ib_destroy_qp - Destroys the specified QP.
1451 * @qp: The QP to destroy.
1453 int ib_destroy_qp(struct ib_qp
*qp
);
1456 * ib_post_send - Posts a list of work requests to the send queue of
1458 * @qp: The QP to post the work request on.
1459 * @send_wr: A list of work requests to post on the send queue.
1460 * @bad_send_wr: On an immediate failure, this parameter will reference
1461 * the work request that failed to be posted on the QP.
1463 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1464 * error is returned, the QP state shall not be affected,
1465 * ib_post_send() will return an immediate error after queueing any
1466 * earlier work requests in the list.
1468 static inline int ib_post_send(struct ib_qp
*qp
,
1469 struct ib_send_wr
*send_wr
,
1470 struct ib_send_wr
**bad_send_wr
)
1472 return qp
->device
->post_send(qp
, send_wr
, bad_send_wr
);
1476 * ib_post_recv - Posts a list of work requests to the receive queue of
1478 * @qp: The QP to post the work request on.
1479 * @recv_wr: A list of work requests to post on the receive queue.
1480 * @bad_recv_wr: On an immediate failure, this parameter will reference
1481 * the work request that failed to be posted on the QP.
1483 static inline int ib_post_recv(struct ib_qp
*qp
,
1484 struct ib_recv_wr
*recv_wr
,
1485 struct ib_recv_wr
**bad_recv_wr
)
1487 return qp
->device
->post_recv(qp
, recv_wr
, bad_recv_wr
);
1491 * ib_create_cq - Creates a CQ on the specified device.
1492 * @device: The device on which to create the CQ.
1493 * @comp_handler: A user-specified callback that is invoked when a
1494 * completion event occurs on the CQ.
1495 * @event_handler: A user-specified callback that is invoked when an
1496 * asynchronous event not associated with a completion occurs on the CQ.
1497 * @cq_context: Context associated with the CQ returned to the user via
1498 * the associated completion and event handlers.
1499 * @cqe: The minimum size of the CQ.
1500 * @comp_vector - Completion vector used to signal completion events.
1501 * Must be >= 0 and < context->num_comp_vectors.
1503 * Users can examine the cq structure to determine the actual CQ size.
1505 struct ib_cq
*ib_create_cq(struct ib_device
*device
,
1506 ib_comp_handler comp_handler
,
1507 void (*event_handler
)(struct ib_event
*, void *),
1508 void *cq_context
, int cqe
, int comp_vector
);
1511 * ib_resize_cq - Modifies the capacity of the CQ.
1512 * @cq: The CQ to resize.
1513 * @cqe: The minimum size of the CQ.
1515 * Users can examine the cq structure to determine the actual CQ size.
1517 int ib_resize_cq(struct ib_cq
*cq
, int cqe
);
1520 * ib_modify_cq - Modifies moderation params of the CQ
1521 * @cq: The CQ to modify.
1522 * @cq_count: number of CQEs that will trigger an event
1523 * @cq_period: max period of time in usec before triggering an event
1526 int ib_modify_cq(struct ib_cq
*cq
, u16 cq_count
, u16 cq_period
);
1529 * ib_destroy_cq - Destroys the specified CQ.
1530 * @cq: The CQ to destroy.
1532 int ib_destroy_cq(struct ib_cq
*cq
);
1535 * ib_poll_cq - poll a CQ for completion(s)
1536 * @cq:the CQ being polled
1537 * @num_entries:maximum number of completions to return
1538 * @wc:array of at least @num_entries &struct ib_wc where completions
1541 * Poll a CQ for (possibly multiple) completions. If the return value
1542 * is < 0, an error occurred. If the return value is >= 0, it is the
1543 * number of completions returned. If the return value is
1544 * non-negative and < num_entries, then the CQ was emptied.
1546 static inline int ib_poll_cq(struct ib_cq
*cq
, int num_entries
,
1549 return cq
->device
->poll_cq(cq
, num_entries
, wc
);
1553 * ib_peek_cq - Returns the number of unreaped completions currently
1554 * on the specified CQ.
1555 * @cq: The CQ to peek.
1556 * @wc_cnt: A minimum number of unreaped completions to check for.
1558 * If the number of unreaped completions is greater than or equal to wc_cnt,
1559 * this function returns wc_cnt, otherwise, it returns the actual number of
1560 * unreaped completions.
1562 int ib_peek_cq(struct ib_cq
*cq
, int wc_cnt
);
1565 * ib_req_notify_cq - Request completion notification on a CQ.
1566 * @cq: The CQ to generate an event for.
1568 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1569 * to request an event on the next solicited event or next work
1570 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1571 * may also be |ed in to request a hint about missed events, as
1575 * < 0 means an error occurred while requesting notification
1576 * == 0 means notification was requested successfully, and if
1577 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1578 * were missed and it is safe to wait for another event. In
1579 * this case is it guaranteed that any work completions added
1580 * to the CQ since the last CQ poll will trigger a completion
1581 * notification event.
1582 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1583 * in. It means that the consumer must poll the CQ again to
1584 * make sure it is empty to avoid missing an event because of a
1585 * race between requesting notification and an entry being
1586 * added to the CQ. This return value means it is possible
1587 * (but not guaranteed) that a work completion has been added
1588 * to the CQ since the last poll without triggering a
1589 * completion notification event.
1591 static inline int ib_req_notify_cq(struct ib_cq
*cq
,
1592 enum ib_cq_notify_flags flags
)
1594 return cq
->device
->req_notify_cq(cq
, flags
);
1598 * ib_req_ncomp_notif - Request completion notification when there are
1599 * at least the specified number of unreaped completions on the CQ.
1600 * @cq: The CQ to generate an event for.
1601 * @wc_cnt: The number of unreaped completions that should be on the
1602 * CQ before an event is generated.
1604 static inline int ib_req_ncomp_notif(struct ib_cq
*cq
, int wc_cnt
)
1606 return cq
->device
->req_ncomp_notif
?
1607 cq
->device
->req_ncomp_notif(cq
, wc_cnt
) :
1612 * ib_get_dma_mr - Returns a memory region for system memory that is
1614 * @pd: The protection domain associated with the memory region.
1615 * @mr_access_flags: Specifies the memory access rights.
1617 * Note that the ib_dma_*() functions defined below must be used
1618 * to create/destroy addresses used with the Lkey or Rkey returned
1619 * by ib_get_dma_mr().
1621 struct ib_mr
*ib_get_dma_mr(struct ib_pd
*pd
, int mr_access_flags
);
1624 * ib_dma_mapping_error - check a DMA addr for error
1625 * @dev: The device for which the dma_addr was created
1626 * @dma_addr: The DMA address to check
1628 static inline int ib_dma_mapping_error(struct ib_device
*dev
, u64 dma_addr
)
1631 return dev
->dma_ops
->mapping_error(dev
, dma_addr
);
1632 return dma_mapping_error(dev
->dma_device
, dma_addr
);
1636 * ib_dma_map_single - Map a kernel virtual address to DMA address
1637 * @dev: The device for which the dma_addr is to be created
1638 * @cpu_addr: The kernel virtual address
1639 * @size: The size of the region in bytes
1640 * @direction: The direction of the DMA
1642 static inline u64
ib_dma_map_single(struct ib_device
*dev
,
1643 void *cpu_addr
, size_t size
,
1644 enum dma_data_direction direction
)
1647 return dev
->dma_ops
->map_single(dev
, cpu_addr
, size
, direction
);
1648 return dma_map_single(dev
->dma_device
, cpu_addr
, size
, direction
);
1652 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1653 * @dev: The device for which the DMA address was created
1654 * @addr: The DMA address
1655 * @size: The size of the region in bytes
1656 * @direction: The direction of the DMA
1658 static inline void ib_dma_unmap_single(struct ib_device
*dev
,
1659 u64 addr
, size_t size
,
1660 enum dma_data_direction direction
)
1663 dev
->dma_ops
->unmap_single(dev
, addr
, size
, direction
);
1665 dma_unmap_single(dev
->dma_device
, addr
, size
, direction
);
1668 static inline u64
ib_dma_map_single_attrs(struct ib_device
*dev
,
1669 void *cpu_addr
, size_t size
,
1670 enum dma_data_direction direction
,
1671 struct dma_attrs
*attrs
)
1673 return dma_map_single_attrs(dev
->dma_device
, cpu_addr
, size
,
1677 static inline void ib_dma_unmap_single_attrs(struct ib_device
*dev
,
1678 u64 addr
, size_t size
,
1679 enum dma_data_direction direction
,
1680 struct dma_attrs
*attrs
)
1682 return dma_unmap_single_attrs(dev
->dma_device
, addr
, size
,
1687 * ib_dma_map_page - Map a physical page to DMA address
1688 * @dev: The device for which the dma_addr is to be created
1689 * @page: The page to be mapped
1690 * @offset: The offset within the page
1691 * @size: The size of the region in bytes
1692 * @direction: The direction of the DMA
1694 static inline u64
ib_dma_map_page(struct ib_device
*dev
,
1696 unsigned long offset
,
1698 enum dma_data_direction direction
)
1701 return dev
->dma_ops
->map_page(dev
, page
, offset
, size
, direction
);
1702 return dma_map_page(dev
->dma_device
, page
, offset
, size
, direction
);
1706 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
1707 * @dev: The device for which the DMA address was created
1708 * @addr: The DMA address
1709 * @size: The size of the region in bytes
1710 * @direction: The direction of the DMA
1712 static inline void ib_dma_unmap_page(struct ib_device
*dev
,
1713 u64 addr
, size_t size
,
1714 enum dma_data_direction direction
)
1717 dev
->dma_ops
->unmap_page(dev
, addr
, size
, direction
);
1719 dma_unmap_page(dev
->dma_device
, addr
, size
, direction
);
1723 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
1724 * @dev: The device for which the DMA addresses are to be created
1725 * @sg: The array of scatter/gather entries
1726 * @nents: The number of scatter/gather entries
1727 * @direction: The direction of the DMA
1729 static inline int ib_dma_map_sg(struct ib_device
*dev
,
1730 struct scatterlist
*sg
, int nents
,
1731 enum dma_data_direction direction
)
1734 return dev
->dma_ops
->map_sg(dev
, sg
, nents
, direction
);
1735 return dma_map_sg(dev
->dma_device
, sg
, nents
, direction
);
1739 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
1740 * @dev: The device for which the DMA addresses were created
1741 * @sg: The array of scatter/gather entries
1742 * @nents: The number of scatter/gather entries
1743 * @direction: The direction of the DMA
1745 static inline void ib_dma_unmap_sg(struct ib_device
*dev
,
1746 struct scatterlist
*sg
, int nents
,
1747 enum dma_data_direction direction
)
1750 dev
->dma_ops
->unmap_sg(dev
, sg
, nents
, direction
);
1752 dma_unmap_sg(dev
->dma_device
, sg
, nents
, direction
);
1755 static inline int ib_dma_map_sg_attrs(struct ib_device
*dev
,
1756 struct scatterlist
*sg
, int nents
,
1757 enum dma_data_direction direction
,
1758 struct dma_attrs
*attrs
)
1760 return dma_map_sg_attrs(dev
->dma_device
, sg
, nents
, direction
, attrs
);
1763 static inline void ib_dma_unmap_sg_attrs(struct ib_device
*dev
,
1764 struct scatterlist
*sg
, int nents
,
1765 enum dma_data_direction direction
,
1766 struct dma_attrs
*attrs
)
1768 dma_unmap_sg_attrs(dev
->dma_device
, sg
, nents
, direction
, attrs
);
1771 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
1772 * @dev: The device for which the DMA addresses were created
1773 * @sg: The scatter/gather entry
1775 static inline u64
ib_sg_dma_address(struct ib_device
*dev
,
1776 struct scatterlist
*sg
)
1779 return dev
->dma_ops
->dma_address(dev
, sg
);
1780 return sg_dma_address(sg
);
1784 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
1785 * @dev: The device for which the DMA addresses were created
1786 * @sg: The scatter/gather entry
1788 static inline unsigned int ib_sg_dma_len(struct ib_device
*dev
,
1789 struct scatterlist
*sg
)
1792 return dev
->dma_ops
->dma_len(dev
, sg
);
1793 return sg_dma_len(sg
);
1797 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
1798 * @dev: The device for which the DMA address was created
1799 * @addr: The DMA address
1800 * @size: The size of the region in bytes
1801 * @dir: The direction of the DMA
1803 static inline void ib_dma_sync_single_for_cpu(struct ib_device
*dev
,
1806 enum dma_data_direction dir
)
1809 dev
->dma_ops
->sync_single_for_cpu(dev
, addr
, size
, dir
);
1811 dma_sync_single_for_cpu(dev
->dma_device
, addr
, size
, dir
);
1815 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
1816 * @dev: The device for which the DMA address was created
1817 * @addr: The DMA address
1818 * @size: The size of the region in bytes
1819 * @dir: The direction of the DMA
1821 static inline void ib_dma_sync_single_for_device(struct ib_device
*dev
,
1824 enum dma_data_direction dir
)
1827 dev
->dma_ops
->sync_single_for_device(dev
, addr
, size
, dir
);
1829 dma_sync_single_for_device(dev
->dma_device
, addr
, size
, dir
);
1833 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
1834 * @dev: The device for which the DMA address is requested
1835 * @size: The size of the region to allocate in bytes
1836 * @dma_handle: A pointer for returning the DMA address of the region
1837 * @flag: memory allocator flags
1839 static inline void *ib_dma_alloc_coherent(struct ib_device
*dev
,
1845 return dev
->dma_ops
->alloc_coherent(dev
, size
, dma_handle
, flag
);
1850 ret
= dma_alloc_coherent(dev
->dma_device
, size
, &handle
, flag
);
1851 *dma_handle
= handle
;
1857 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
1858 * @dev: The device for which the DMA addresses were allocated
1859 * @size: The size of the region
1860 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
1861 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
1863 static inline void ib_dma_free_coherent(struct ib_device
*dev
,
1864 size_t size
, void *cpu_addr
,
1868 dev
->dma_ops
->free_coherent(dev
, size
, cpu_addr
, dma_handle
);
1870 dma_free_coherent(dev
->dma_device
, size
, cpu_addr
, dma_handle
);
1874 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
1876 * @pd: The protection domain associated assigned to the registered region.
1877 * @phys_buf_array: Specifies a list of physical buffers to use in the
1879 * @num_phys_buf: Specifies the size of the phys_buf_array.
1880 * @mr_access_flags: Specifies the memory access rights.
1881 * @iova_start: The offset of the region's starting I/O virtual address.
1883 struct ib_mr
*ib_reg_phys_mr(struct ib_pd
*pd
,
1884 struct ib_phys_buf
*phys_buf_array
,
1886 int mr_access_flags
,
1890 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
1891 * Conceptually, this call performs the functions deregister memory region
1892 * followed by register physical memory region. Where possible,
1893 * resources are reused instead of deallocated and reallocated.
1894 * @mr: The memory region to modify.
1895 * @mr_rereg_mask: A bit-mask used to indicate which of the following
1896 * properties of the memory region are being modified.
1897 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
1898 * the new protection domain to associated with the memory region,
1899 * otherwise, this parameter is ignored.
1900 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1901 * field specifies a list of physical buffers to use in the new
1902 * translation, otherwise, this parameter is ignored.
1903 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1904 * field specifies the size of the phys_buf_array, otherwise, this
1905 * parameter is ignored.
1906 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
1907 * field specifies the new memory access rights, otherwise, this
1908 * parameter is ignored.
1909 * @iova_start: The offset of the region's starting I/O virtual address.
1911 int ib_rereg_phys_mr(struct ib_mr
*mr
,
1914 struct ib_phys_buf
*phys_buf_array
,
1916 int mr_access_flags
,
1920 * ib_query_mr - Retrieves information about a specific memory region.
1921 * @mr: The memory region to retrieve information about.
1922 * @mr_attr: The attributes of the specified memory region.
1924 int ib_query_mr(struct ib_mr
*mr
, struct ib_mr_attr
*mr_attr
);
1927 * ib_dereg_mr - Deregisters a memory region and removes it from the
1928 * HCA translation table.
1929 * @mr: The memory region to deregister.
1931 int ib_dereg_mr(struct ib_mr
*mr
);
1934 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
1935 * IB_WR_FAST_REG_MR send work request.
1936 * @pd: The protection domain associated with the region.
1937 * @max_page_list_len: requested max physical buffer list length to be
1938 * used with fast register work requests for this MR.
1940 struct ib_mr
*ib_alloc_fast_reg_mr(struct ib_pd
*pd
, int max_page_list_len
);
1943 * ib_alloc_fast_reg_page_list - Allocates a page list array
1944 * @device - ib device pointer.
1945 * @page_list_len - size of the page list array to be allocated.
1947 * This allocates and returns a struct ib_fast_reg_page_list * and a
1948 * page_list array that is at least page_list_len in size. The actual
1949 * size is returned in max_page_list_len. The caller is responsible
1950 * for initializing the contents of the page_list array before posting
1951 * a send work request with the IB_WC_FAST_REG_MR opcode.
1953 * The page_list array entries must be translated using one of the
1954 * ib_dma_*() functions just like the addresses passed to
1955 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
1956 * ib_fast_reg_page_list must not be modified by the caller until the
1957 * IB_WC_FAST_REG_MR work request completes.
1959 struct ib_fast_reg_page_list
*ib_alloc_fast_reg_page_list(
1960 struct ib_device
*device
, int page_list_len
);
1963 * ib_free_fast_reg_page_list - Deallocates a previously allocated
1965 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
1967 void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list
*page_list
);
1970 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
1972 * @mr - struct ib_mr pointer to be updated.
1973 * @newkey - new key to be used.
1975 static inline void ib_update_fast_reg_key(struct ib_mr
*mr
, u8 newkey
)
1977 mr
->lkey
= (mr
->lkey
& 0xffffff00) | newkey
;
1978 mr
->rkey
= (mr
->rkey
& 0xffffff00) | newkey
;
1982 * ib_alloc_mw - Allocates a memory window.
1983 * @pd: The protection domain associated with the memory window.
1985 struct ib_mw
*ib_alloc_mw(struct ib_pd
*pd
);
1988 * ib_bind_mw - Posts a work request to the send queue of the specified
1989 * QP, which binds the memory window to the given address range and
1990 * remote access attributes.
1991 * @qp: QP to post the bind work request on.
1992 * @mw: The memory window to bind.
1993 * @mw_bind: Specifies information about the memory window, including
1994 * its address range, remote access rights, and associated memory region.
1996 static inline int ib_bind_mw(struct ib_qp
*qp
,
1998 struct ib_mw_bind
*mw_bind
)
2000 /* XXX reference counting in corresponding MR? */
2001 return mw
->device
->bind_mw
?
2002 mw
->device
->bind_mw(qp
, mw
, mw_bind
) :
2007 * ib_dealloc_mw - Deallocates a memory window.
2008 * @mw: The memory window to deallocate.
2010 int ib_dealloc_mw(struct ib_mw
*mw
);
2013 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2014 * @pd: The protection domain associated with the unmapped region.
2015 * @mr_access_flags: Specifies the memory access rights.
2016 * @fmr_attr: Attributes of the unmapped region.
2018 * A fast memory region must be mapped before it can be used as part of
2021 struct ib_fmr
*ib_alloc_fmr(struct ib_pd
*pd
,
2022 int mr_access_flags
,
2023 struct ib_fmr_attr
*fmr_attr
);
2026 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2027 * @fmr: The fast memory region to associate with the pages.
2028 * @page_list: An array of physical pages to map to the fast memory region.
2029 * @list_len: The number of pages in page_list.
2030 * @iova: The I/O virtual address to use with the mapped region.
2032 static inline int ib_map_phys_fmr(struct ib_fmr
*fmr
,
2033 u64
*page_list
, int list_len
,
2036 return fmr
->device
->map_phys_fmr(fmr
, page_list
, list_len
, iova
);
2040 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2041 * @fmr_list: A linked list of fast memory regions to unmap.
2043 int ib_unmap_fmr(struct list_head
*fmr_list
);
2046 * ib_dealloc_fmr - Deallocates a fast memory region.
2047 * @fmr: The fast memory region to deallocate.
2049 int ib_dealloc_fmr(struct ib_fmr
*fmr
);
2052 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2053 * @qp: QP to attach to the multicast group. The QP must be type
2055 * @gid: Multicast group GID.
2056 * @lid: Multicast group LID in host byte order.
2058 * In order to send and receive multicast packets, subnet
2059 * administration must have created the multicast group and configured
2060 * the fabric appropriately. The port associated with the specified
2061 * QP must also be a member of the multicast group.
2063 int ib_attach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
);
2066 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2067 * @qp: QP to detach from the multicast group.
2068 * @gid: Multicast group GID.
2069 * @lid: Multicast group LID in host byte order.
2071 int ib_detach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
);
2074 * ib_alloc_xrcd - Allocates an XRC domain.
2075 * @device: The device on which to allocate the XRC domain.
2077 struct ib_xrcd
*ib_alloc_xrcd(struct ib_device
*device
);
2080 * ib_dealloc_xrcd - Deallocates an XRC domain.
2081 * @xrcd: The XRC domain to deallocate.
2083 int ib_dealloc_xrcd(struct ib_xrcd
*xrcd
);
2085 #endif /* IB_VERBS_H */