]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/rdma/ib_verbs.h
RDMA/core: Add SRQ type field
[mirror_ubuntu-bionic-kernel.git] / include / rdma / ib_verbs.h
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
2a1d9b7f 7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
f7c6a7b5 8 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
1da177e4
LT
9 *
10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU
12 * General Public License (GPL) Version 2, available from the file
13 * COPYING in the main directory of this source tree, or the
14 * OpenIB.org BSD license below:
15 *
16 * Redistribution and use in source and binary forms, with or
17 * without modification, are permitted provided that the following
18 * conditions are met:
19 *
20 * - Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer.
23 *
24 * - Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials
27 * provided with the distribution.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 * SOFTWARE.
1da177e4
LT
37 */
38
39#if !defined(IB_VERBS_H)
40#define IB_VERBS_H
41
42#include <linux/types.h>
43#include <linux/device.h>
9b513090
RC
44#include <linux/mm.h>
45#include <linux/dma-mapping.h>
459d6e2a 46#include <linux/kref.h>
bfb3ea12
DB
47#include <linux/list.h>
48#include <linux/rwsem.h>
87ae9afd 49#include <linux/scatterlist.h>
f0626710 50#include <linux/workqueue.h>
e2773c06 51
60063497 52#include <linux/atomic.h>
e2773c06 53#include <asm/uaccess.h>
1da177e4 54
f0626710
TH
55extern struct workqueue_struct *ib_wq;
56
1da177e4
LT
57union ib_gid {
58 u8 raw[16];
59 struct {
97f52eb4
SH
60 __be64 subnet_prefix;
61 __be64 interface_id;
1da177e4
LT
62 } global;
63};
64
07ebafba
TT
65enum rdma_node_type {
66 /* IB values map to NodeInfo:NodeType. */
67 RDMA_NODE_IB_CA = 1,
68 RDMA_NODE_IB_SWITCH,
69 RDMA_NODE_IB_ROUTER,
70 RDMA_NODE_RNIC
1da177e4
LT
71};
72
07ebafba
TT
73enum rdma_transport_type {
74 RDMA_TRANSPORT_IB,
75 RDMA_TRANSPORT_IWARP
76};
77
78enum rdma_transport_type
79rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
80
a3f5adaf
EC
81enum rdma_link_layer {
82 IB_LINK_LAYER_UNSPECIFIED,
83 IB_LINK_LAYER_INFINIBAND,
84 IB_LINK_LAYER_ETHERNET,
85};
86
1da177e4
LT
87enum 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),
96f15c03 103 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
0f39cf3d 104 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
e0605d91
EC
105 IB_DEVICE_MEM_WINDOW = (1<<17),
106 /*
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.
112 */
113 IB_DEVICE_UD_IP_CSUM = (1<<18),
c93570f2 114 IB_DEVICE_UD_TSO = (1<<19),
59991f94 115 IB_DEVICE_XRC = (1<<20),
00f7ec36 116 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
47ee1b9f 117 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
1da177e4
LT
118};
119
120enum ib_atomic_cap {
121 IB_ATOMIC_NONE,
122 IB_ATOMIC_HCA,
123 IB_ATOMIC_GLOB
124};
125
126struct ib_device_attr {
127 u64 fw_ver;
97f52eb4 128 __be64 sys_image_guid;
1da177e4
LT
129 u64 max_mr_size;
130 u64 page_size_cap;
131 u32 vendor_id;
132 u32 vendor_part_id;
133 u32 hw_ver;
134 int max_qp;
135 int max_qp_wr;
136 int device_cap_flags;
137 int max_sge;
138 int max_sge_rd;
139 int max_cq;
140 int max_cqe;
141 int max_mr;
142 int max_pd;
143 int max_qp_rd_atom;
144 int max_ee_rd_atom;
145 int max_res_rd_atom;
146 int max_qp_init_rd_atom;
147 int max_ee_init_rd_atom;
148 enum ib_atomic_cap atomic_cap;
5e80ba8f 149 enum ib_atomic_cap masked_atomic_cap;
1da177e4
LT
150 int max_ee;
151 int max_rdd;
152 int max_mw;
153 int max_raw_ipv6_qp;
154 int max_raw_ethy_qp;
155 int max_mcast_grp;
156 int max_mcast_qp_attach;
157 int max_total_mcast_qp_attach;
158 int max_ah;
159 int max_fmr;
160 int max_map_per_fmr;
161 int max_srq;
162 int max_srq_wr;
163 int max_srq_sge;
00f7ec36 164 unsigned int max_fast_reg_page_list_len;
1da177e4
LT
165 u16 max_pkeys;
166 u8 local_ca_ack_delay;
167};
168
169enum ib_mtu {
170 IB_MTU_256 = 1,
171 IB_MTU_512 = 2,
172 IB_MTU_1024 = 3,
173 IB_MTU_2048 = 4,
174 IB_MTU_4096 = 5
175};
176
177static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
178{
179 switch (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;
185 default: return -1;
186 }
187}
188
189enum ib_port_state {
190 IB_PORT_NOP = 0,
191 IB_PORT_DOWN = 1,
192 IB_PORT_INIT = 2,
193 IB_PORT_ARMED = 3,
194 IB_PORT_ACTIVE = 4,
195 IB_PORT_ACTIVE_DEFER = 5
196};
197
198enum ib_port_cap_flags {
199 IB_PORT_SM = 1 << 1,
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
221};
222
223enum ib_port_width {
224 IB_WIDTH_1X = 1,
225 IB_WIDTH_4X = 2,
226 IB_WIDTH_8X = 4,
227 IB_WIDTH_12X = 8
228};
229
230static inline int ib_width_enum_to_int(enum ib_port_width width)
231{
232 switch (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;
237 default: return -1;
238 }
239}
240
7f624d02
SW
241struct ib_protocol_stats {
242 /* TBD... */
243};
244
245struct iw_protocol_stats {
246 u64 ipInReceives;
247 u64 ipInHdrErrors;
248 u64 ipInTooBigErrors;
249 u64 ipInNoRoutes;
250 u64 ipInAddrErrors;
251 u64 ipInUnknownProtos;
252 u64 ipInTruncatedPkts;
253 u64 ipInDiscards;
254 u64 ipInDelivers;
255 u64 ipOutForwDatagrams;
256 u64 ipOutRequests;
257 u64 ipOutDiscards;
258 u64 ipOutNoRoutes;
259 u64 ipReasmTimeout;
260 u64 ipReasmReqds;
261 u64 ipReasmOKs;
262 u64 ipReasmFails;
263 u64 ipFragOKs;
264 u64 ipFragFails;
265 u64 ipFragCreates;
266 u64 ipInMcastPkts;
267 u64 ipOutMcastPkts;
268 u64 ipInBcastPkts;
269 u64 ipOutBcastPkts;
270
271 u64 tcpRtoAlgorithm;
272 u64 tcpRtoMin;
273 u64 tcpRtoMax;
274 u64 tcpMaxConn;
275 u64 tcpActiveOpens;
276 u64 tcpPassiveOpens;
277 u64 tcpAttemptFails;
278 u64 tcpEstabResets;
279 u64 tcpCurrEstab;
280 u64 tcpInSegs;
281 u64 tcpOutSegs;
282 u64 tcpRetransSegs;
283 u64 tcpInErrs;
284 u64 tcpOutRsts;
285};
286
287union rdma_protocol_stats {
288 struct ib_protocol_stats ib;
289 struct iw_protocol_stats iw;
290};
291
1da177e4
LT
292struct ib_port_attr {
293 enum ib_port_state state;
294 enum ib_mtu max_mtu;
295 enum ib_mtu active_mtu;
296 int gid_tbl_len;
297 u32 port_cap_flags;
298 u32 max_msg_sz;
299 u32 bad_pkey_cntr;
300 u32 qkey_viol_cntr;
301 u16 pkey_tbl_len;
302 u16 lid;
303 u16 sm_lid;
304 u8 lmc;
305 u8 max_vl_num;
306 u8 sm_sl;
307 u8 subnet_timeout;
308 u8 init_type_reply;
309 u8 active_width;
310 u8 active_speed;
311 u8 phys_state;
312};
313
314enum ib_device_modify_flags {
c5bcbbb9
RD
315 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
316 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
1da177e4
LT
317};
318
319struct ib_device_modify {
320 u64 sys_image_guid;
c5bcbbb9 321 char node_desc[64];
1da177e4
LT
322};
323
324enum ib_port_modify_flags {
325 IB_PORT_SHUTDOWN = 1,
326 IB_PORT_INIT_TYPE = (1<<2),
327 IB_PORT_RESET_QKEY_CNTR = (1<<3)
328};
329
330struct ib_port_modify {
331 u32 set_port_cap_mask;
332 u32 clr_port_cap_mask;
333 u8 init_type;
334};
335
336enum ib_event_type {
337 IB_EVENT_CQ_ERR,
338 IB_EVENT_QP_FATAL,
339 IB_EVENT_QP_REQ_ERR,
340 IB_EVENT_QP_ACCESS_ERR,
341 IB_EVENT_COMM_EST,
342 IB_EVENT_SQ_DRAINED,
343 IB_EVENT_PATH_MIG,
344 IB_EVENT_PATH_MIG_ERR,
345 IB_EVENT_DEVICE_FATAL,
346 IB_EVENT_PORT_ACTIVE,
347 IB_EVENT_PORT_ERR,
348 IB_EVENT_LID_CHANGE,
349 IB_EVENT_PKEY_CHANGE,
d41fcc67
RD
350 IB_EVENT_SM_CHANGE,
351 IB_EVENT_SRQ_ERR,
352 IB_EVENT_SRQ_LIMIT_REACHED,
63942c9a 353 IB_EVENT_QP_LAST_WQE_REACHED,
761d90ed
OG
354 IB_EVENT_CLIENT_REREGISTER,
355 IB_EVENT_GID_CHANGE,
1da177e4
LT
356};
357
358struct ib_event {
359 struct ib_device *device;
360 union {
361 struct ib_cq *cq;
362 struct ib_qp *qp;
d41fcc67 363 struct ib_srq *srq;
1da177e4
LT
364 u8 port_num;
365 } element;
366 enum ib_event_type event;
367};
368
369struct ib_event_handler {
370 struct ib_device *device;
371 void (*handler)(struct ib_event_handler *, struct ib_event *);
372 struct list_head list;
373};
374
375#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
376 do { \
377 (_ptr)->device = _device; \
378 (_ptr)->handler = _handler; \
379 INIT_LIST_HEAD(&(_ptr)->list); \
380 } while (0)
381
382struct ib_global_route {
383 union ib_gid dgid;
384 u32 flow_label;
385 u8 sgid_index;
386 u8 hop_limit;
387 u8 traffic_class;
388};
389
513789ed 390struct ib_grh {
97f52eb4
SH
391 __be32 version_tclass_flow;
392 __be16 paylen;
513789ed
HR
393 u8 next_hdr;
394 u8 hop_limit;
395 union ib_gid sgid;
396 union ib_gid dgid;
397};
398
1da177e4
LT
399enum {
400 IB_MULTICAST_QPN = 0xffffff
401};
402
f3a7c66b 403#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
97f52eb4 404
1da177e4
LT
405enum ib_ah_flags {
406 IB_AH_GRH = 1
407};
408
bf6a9e31
JM
409enum ib_rate {
410 IB_RATE_PORT_CURRENT = 0,
411 IB_RATE_2_5_GBPS = 2,
412 IB_RATE_5_GBPS = 5,
413 IB_RATE_10_GBPS = 3,
414 IB_RATE_20_GBPS = 6,
415 IB_RATE_30_GBPS = 4,
416 IB_RATE_40_GBPS = 7,
417 IB_RATE_60_GBPS = 8,
418 IB_RATE_80_GBPS = 9,
419 IB_RATE_120_GBPS = 10
420};
421
422/**
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.
427 */
428int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
429
430/**
431 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
432 * enum.
433 * @mult: multiple to convert.
434 */
435enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
436
1da177e4
LT
437struct ib_ah_attr {
438 struct ib_global_route grh;
439 u16 dlid;
440 u8 sl;
441 u8 src_path_bits;
442 u8 static_rate;
443 u8 ah_flags;
444 u8 port_num;
445};
446
447enum ib_wc_status {
448 IB_WC_SUCCESS,
449 IB_WC_LOC_LEN_ERR,
450 IB_WC_LOC_QP_OP_ERR,
451 IB_WC_LOC_EEC_OP_ERR,
452 IB_WC_LOC_PROT_ERR,
453 IB_WC_WR_FLUSH_ERR,
454 IB_WC_MW_BIND_ERR,
455 IB_WC_BAD_RESP_ERR,
456 IB_WC_LOC_ACCESS_ERR,
457 IB_WC_REM_INV_REQ_ERR,
458 IB_WC_REM_ACCESS_ERR,
459 IB_WC_REM_OP_ERR,
460 IB_WC_RETRY_EXC_ERR,
461 IB_WC_RNR_RETRY_EXC_ERR,
462 IB_WC_LOC_RDD_VIOL_ERR,
463 IB_WC_REM_INV_RD_REQ_ERR,
464 IB_WC_REM_ABORT_ERR,
465 IB_WC_INV_EECN_ERR,
466 IB_WC_INV_EEC_STATE_ERR,
467 IB_WC_FATAL_ERR,
468 IB_WC_RESP_TIMEOUT_ERR,
469 IB_WC_GENERAL_ERR
470};
471
472enum ib_wc_opcode {
473 IB_WC_SEND,
474 IB_WC_RDMA_WRITE,
475 IB_WC_RDMA_READ,
476 IB_WC_COMP_SWAP,
477 IB_WC_FETCH_ADD,
478 IB_WC_BIND_MW,
c93570f2 479 IB_WC_LSO,
00f7ec36
SW
480 IB_WC_LOCAL_INV,
481 IB_WC_FAST_REG_MR,
5e80ba8f
VS
482 IB_WC_MASKED_COMP_SWAP,
483 IB_WC_MASKED_FETCH_ADD,
1da177e4
LT
484/*
485 * Set value of IB_WC_RECV so consumers can test if a completion is a
486 * receive by testing (opcode & IB_WC_RECV).
487 */
488 IB_WC_RECV = 1 << 7,
489 IB_WC_RECV_RDMA_WITH_IMM
490};
491
492enum ib_wc_flags {
493 IB_WC_GRH = 1,
00f7ec36
SW
494 IB_WC_WITH_IMM = (1<<1),
495 IB_WC_WITH_INVALIDATE = (1<<2),
1da177e4
LT
496};
497
498struct ib_wc {
499 u64 wr_id;
500 enum ib_wc_status status;
501 enum ib_wc_opcode opcode;
502 u32 vendor_err;
503 u32 byte_len;
062dbb69 504 struct ib_qp *qp;
00f7ec36
SW
505 union {
506 __be32 imm_data;
507 u32 invalidate_rkey;
508 } ex;
1da177e4
LT
509 u32 src_qp;
510 int wc_flags;
511 u16 pkey_index;
512 u16 slid;
513 u8 sl;
514 u8 dlid_path_bits;
515 u8 port_num; /* valid only for DR SMPs on switches */
e0605d91 516 int csum_ok;
1da177e4
LT
517};
518
ed23a727
RD
519enum 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,
1da177e4
LT
524};
525
96104eda
SH
526enum ib_srq_type {
527 IB_SRQT_BASIC
528};
529
d41fcc67
RD
530enum ib_srq_attr_mask {
531 IB_SRQ_MAX_WR = 1 << 0,
532 IB_SRQ_LIMIT = 1 << 1,
533};
534
535struct ib_srq_attr {
536 u32 max_wr;
537 u32 max_sge;
538 u32 srq_limit;
539};
540
541struct ib_srq_init_attr {
542 void (*event_handler)(struct ib_event *, void *);
543 void *srq_context;
544 struct ib_srq_attr attr;
96104eda 545 enum ib_srq_type srq_type;
d41fcc67
RD
546};
547
1da177e4
LT
548struct ib_qp_cap {
549 u32 max_send_wr;
550 u32 max_recv_wr;
551 u32 max_send_sge;
552 u32 max_recv_sge;
553 u32 max_inline_data;
554};
555
556enum ib_sig_type {
557 IB_SIGNAL_ALL_WR,
558 IB_SIGNAL_REQ_WR
559};
560
561enum ib_qp_type {
562 /*
563 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
564 * here (and in that order) since the MAD layer uses them as
565 * indices into a 2-entry table.
566 */
567 IB_QPT_SMI,
568 IB_QPT_GSI,
569
570 IB_QPT_RC,
571 IB_QPT_UC,
572 IB_QPT_UD,
573 IB_QPT_RAW_IPV6,
a2ebf07a 574 IB_QPT_RAW_ETHERTYPE
1da177e4
LT
575};
576
b846f25a 577enum ib_qp_create_flags {
47ee1b9f
RL
578 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
579 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
b846f25a
EC
580};
581
1da177e4
LT
582struct ib_qp_init_attr {
583 void (*event_handler)(struct ib_event *, void *);
584 void *qp_context;
585 struct ib_cq *send_cq;
586 struct ib_cq *recv_cq;
587 struct ib_srq *srq;
588 struct ib_qp_cap cap;
589 enum ib_sig_type sq_sig_type;
590 enum ib_qp_type qp_type;
b846f25a 591 enum ib_qp_create_flags create_flags;
1da177e4
LT
592 u8 port_num; /* special QP types only */
593};
594
595enum ib_rnr_timeout {
596 IB_RNR_TIMER_655_36 = 0,
597 IB_RNR_TIMER_000_01 = 1,
598 IB_RNR_TIMER_000_02 = 2,
599 IB_RNR_TIMER_000_03 = 3,
600 IB_RNR_TIMER_000_04 = 4,
601 IB_RNR_TIMER_000_06 = 5,
602 IB_RNR_TIMER_000_08 = 6,
603 IB_RNR_TIMER_000_12 = 7,
604 IB_RNR_TIMER_000_16 = 8,
605 IB_RNR_TIMER_000_24 = 9,
606 IB_RNR_TIMER_000_32 = 10,
607 IB_RNR_TIMER_000_48 = 11,
608 IB_RNR_TIMER_000_64 = 12,
609 IB_RNR_TIMER_000_96 = 13,
610 IB_RNR_TIMER_001_28 = 14,
611 IB_RNR_TIMER_001_92 = 15,
612 IB_RNR_TIMER_002_56 = 16,
613 IB_RNR_TIMER_003_84 = 17,
614 IB_RNR_TIMER_005_12 = 18,
615 IB_RNR_TIMER_007_68 = 19,
616 IB_RNR_TIMER_010_24 = 20,
617 IB_RNR_TIMER_015_36 = 21,
618 IB_RNR_TIMER_020_48 = 22,
619 IB_RNR_TIMER_030_72 = 23,
620 IB_RNR_TIMER_040_96 = 24,
621 IB_RNR_TIMER_061_44 = 25,
622 IB_RNR_TIMER_081_92 = 26,
623 IB_RNR_TIMER_122_88 = 27,
624 IB_RNR_TIMER_163_84 = 28,
625 IB_RNR_TIMER_245_76 = 29,
626 IB_RNR_TIMER_327_68 = 30,
627 IB_RNR_TIMER_491_52 = 31
628};
629
630enum ib_qp_attr_mask {
631 IB_QP_STATE = 1,
632 IB_QP_CUR_STATE = (1<<1),
633 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
634 IB_QP_ACCESS_FLAGS = (1<<3),
635 IB_QP_PKEY_INDEX = (1<<4),
636 IB_QP_PORT = (1<<5),
637 IB_QP_QKEY = (1<<6),
638 IB_QP_AV = (1<<7),
639 IB_QP_PATH_MTU = (1<<8),
640 IB_QP_TIMEOUT = (1<<9),
641 IB_QP_RETRY_CNT = (1<<10),
642 IB_QP_RNR_RETRY = (1<<11),
643 IB_QP_RQ_PSN = (1<<12),
644 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
645 IB_QP_ALT_PATH = (1<<14),
646 IB_QP_MIN_RNR_TIMER = (1<<15),
647 IB_QP_SQ_PSN = (1<<16),
648 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
649 IB_QP_PATH_MIG_STATE = (1<<18),
650 IB_QP_CAP = (1<<19),
651 IB_QP_DEST_QPN = (1<<20)
652};
653
654enum ib_qp_state {
655 IB_QPS_RESET,
656 IB_QPS_INIT,
657 IB_QPS_RTR,
658 IB_QPS_RTS,
659 IB_QPS_SQD,
660 IB_QPS_SQE,
661 IB_QPS_ERR
662};
663
664enum ib_mig_state {
665 IB_MIG_MIGRATED,
666 IB_MIG_REARM,
667 IB_MIG_ARMED
668};
669
670struct ib_qp_attr {
671 enum ib_qp_state qp_state;
672 enum ib_qp_state cur_qp_state;
673 enum ib_mtu path_mtu;
674 enum ib_mig_state path_mig_state;
675 u32 qkey;
676 u32 rq_psn;
677 u32 sq_psn;
678 u32 dest_qp_num;
679 int qp_access_flags;
680 struct ib_qp_cap cap;
681 struct ib_ah_attr ah_attr;
682 struct ib_ah_attr alt_ah_attr;
683 u16 pkey_index;
684 u16 alt_pkey_index;
685 u8 en_sqd_async_notify;
686 u8 sq_draining;
687 u8 max_rd_atomic;
688 u8 max_dest_rd_atomic;
689 u8 min_rnr_timer;
690 u8 port_num;
691 u8 timeout;
692 u8 retry_cnt;
693 u8 rnr_retry;
694 u8 alt_port_num;
695 u8 alt_timeout;
696};
697
698enum ib_wr_opcode {
699 IB_WR_RDMA_WRITE,
700 IB_WR_RDMA_WRITE_WITH_IMM,
701 IB_WR_SEND,
702 IB_WR_SEND_WITH_IMM,
703 IB_WR_RDMA_READ,
704 IB_WR_ATOMIC_CMP_AND_SWP,
c93570f2 705 IB_WR_ATOMIC_FETCH_AND_ADD,
0f39cf3d
RD
706 IB_WR_LSO,
707 IB_WR_SEND_WITH_INV,
00f7ec36
SW
708 IB_WR_RDMA_READ_WITH_INV,
709 IB_WR_LOCAL_INV,
710 IB_WR_FAST_REG_MR,
5e80ba8f
VS
711 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
712 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
1da177e4
LT
713};
714
715enum ib_send_flags {
716 IB_SEND_FENCE = 1,
717 IB_SEND_SIGNALED = (1<<1),
718 IB_SEND_SOLICITED = (1<<2),
e0605d91
EC
719 IB_SEND_INLINE = (1<<3),
720 IB_SEND_IP_CSUM = (1<<4)
1da177e4
LT
721};
722
723struct ib_sge {
724 u64 addr;
725 u32 length;
726 u32 lkey;
727};
728
00f7ec36
SW
729struct ib_fast_reg_page_list {
730 struct ib_device *device;
731 u64 *page_list;
732 unsigned int max_page_list_len;
733};
734
1da177e4
LT
735struct ib_send_wr {
736 struct ib_send_wr *next;
737 u64 wr_id;
738 struct ib_sge *sg_list;
739 int num_sge;
740 enum ib_wr_opcode opcode;
741 int send_flags;
0f39cf3d
RD
742 union {
743 __be32 imm_data;
744 u32 invalidate_rkey;
745 } ex;
1da177e4
LT
746 union {
747 struct {
748 u64 remote_addr;
749 u32 rkey;
750 } rdma;
751 struct {
752 u64 remote_addr;
753 u64 compare_add;
754 u64 swap;
5e80ba8f
VS
755 u64 compare_add_mask;
756 u64 swap_mask;
1da177e4
LT
757 u32 rkey;
758 } atomic;
759 struct {
760 struct ib_ah *ah;
c93570f2
EC
761 void *header;
762 int hlen;
763 int mss;
1da177e4
LT
764 u32 remote_qpn;
765 u32 remote_qkey;
1da177e4
LT
766 u16 pkey_index; /* valid for GSI only */
767 u8 port_num; /* valid for DR SMPs on switch only */
768 } ud;
00f7ec36
SW
769 struct {
770 u64 iova_start;
771 struct ib_fast_reg_page_list *page_list;
772 unsigned int page_shift;
773 unsigned int page_list_len;
774 u32 length;
775 int access_flags;
776 u32 rkey;
777 } fast_reg;
1da177e4
LT
778 } wr;
779};
780
781struct ib_recv_wr {
782 struct ib_recv_wr *next;
783 u64 wr_id;
784 struct ib_sge *sg_list;
785 int num_sge;
786};
787
788enum ib_access_flags {
789 IB_ACCESS_LOCAL_WRITE = 1,
790 IB_ACCESS_REMOTE_WRITE = (1<<1),
791 IB_ACCESS_REMOTE_READ = (1<<2),
792 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
793 IB_ACCESS_MW_BIND = (1<<4)
794};
795
796struct ib_phys_buf {
797 u64 addr;
798 u64 size;
799};
800
801struct ib_mr_attr {
802 struct ib_pd *pd;
803 u64 device_virt_addr;
804 u64 size;
805 int mr_access_flags;
806 u32 lkey;
807 u32 rkey;
808};
809
810enum ib_mr_rereg_flags {
811 IB_MR_REREG_TRANS = 1,
812 IB_MR_REREG_PD = (1<<1),
813 IB_MR_REREG_ACCESS = (1<<2)
814};
815
816struct ib_mw_bind {
817 struct ib_mr *mr;
818 u64 wr_id;
819 u64 addr;
820 u32 length;
821 int send_flags;
822 int mw_access_flags;
823};
824
825struct ib_fmr_attr {
826 int max_pages;
827 int max_maps;
d36f34aa 828 u8 page_shift;
1da177e4
LT
829};
830
e2773c06
RD
831struct ib_ucontext {
832 struct ib_device *device;
833 struct list_head pd_list;
834 struct list_head mr_list;
835 struct list_head mw_list;
836 struct list_head cq_list;
837 struct list_head qp_list;
838 struct list_head srq_list;
839 struct list_head ah_list;
f7c6a7b5 840 int closing;
e2773c06
RD
841};
842
843struct ib_uobject {
844 u64 user_handle; /* handle given to us by userspace */
845 struct ib_ucontext *context; /* associated user context */
9ead190b 846 void *object; /* containing object */
e2773c06 847 struct list_head list; /* link to context's list */
b3d636b0 848 int id; /* index into kernel idr */
9ead190b
RD
849 struct kref ref;
850 struct rw_semaphore mutex; /* protects .live */
851 int live;
e2773c06
RD
852};
853
e2773c06
RD
854struct ib_udata {
855 void __user *inbuf;
856 void __user *outbuf;
857 size_t inlen;
858 size_t outlen;
859};
860
1da177e4 861struct ib_pd {
e2773c06
RD
862 struct ib_device *device;
863 struct ib_uobject *uobject;
864 atomic_t usecnt; /* count all resources */
1da177e4
LT
865};
866
59991f94
SH
867struct ib_xrcd {
868 struct ib_device *device;
869 atomic_t usecnt; /* count all resources */
870};
871
1da177e4
LT
872struct ib_ah {
873 struct ib_device *device;
874 struct ib_pd *pd;
e2773c06 875 struct ib_uobject *uobject;
1da177e4
LT
876};
877
878typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
879
880struct ib_cq {
e2773c06
RD
881 struct ib_device *device;
882 struct ib_uobject *uobject;
883 ib_comp_handler comp_handler;
884 void (*event_handler)(struct ib_event *, void *);
4deccd6d 885 void *cq_context;
e2773c06
RD
886 int cqe;
887 atomic_t usecnt; /* count number of work queues */
1da177e4
LT
888};
889
890struct ib_srq {
d41fcc67
RD
891 struct ib_device *device;
892 struct ib_pd *pd;
893 struct ib_uobject *uobject;
894 void (*event_handler)(struct ib_event *, void *);
895 void *srq_context;
96104eda 896 enum ib_srq_type srq_type;
1da177e4
LT
897 atomic_t usecnt;
898};
899
900struct ib_qp {
901 struct ib_device *device;
902 struct ib_pd *pd;
903 struct ib_cq *send_cq;
904 struct ib_cq *recv_cq;
905 struct ib_srq *srq;
e2773c06 906 struct ib_uobject *uobject;
1da177e4
LT
907 void (*event_handler)(struct ib_event *, void *);
908 void *qp_context;
909 u32 qp_num;
910 enum ib_qp_type qp_type;
911};
912
913struct ib_mr {
e2773c06
RD
914 struct ib_device *device;
915 struct ib_pd *pd;
916 struct ib_uobject *uobject;
917 u32 lkey;
918 u32 rkey;
919 atomic_t usecnt; /* count number of MWs */
1da177e4
LT
920};
921
922struct ib_mw {
923 struct ib_device *device;
924 struct ib_pd *pd;
e2773c06 925 struct ib_uobject *uobject;
1da177e4
LT
926 u32 rkey;
927};
928
929struct ib_fmr {
930 struct ib_device *device;
931 struct ib_pd *pd;
932 struct list_head list;
933 u32 lkey;
934 u32 rkey;
935};
936
937struct ib_mad;
938struct ib_grh;
939
940enum ib_process_mad_flags {
941 IB_MAD_IGNORE_MKEY = 1,
942 IB_MAD_IGNORE_BKEY = 2,
943 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
944};
945
946enum ib_mad_result {
947 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
948 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
949 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
950 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
951};
952
953#define IB_DEVICE_NAME_MAX 64
954
955struct ib_cache {
956 rwlock_t lock;
957 struct ib_event_handler event_handler;
958 struct ib_pkey_cache **pkey_cache;
959 struct ib_gid_cache **gid_cache;
6fb9cdbf 960 u8 *lmc_cache;
1da177e4
LT
961};
962
9b513090
RC
963struct ib_dma_mapping_ops {
964 int (*mapping_error)(struct ib_device *dev,
965 u64 dma_addr);
966 u64 (*map_single)(struct ib_device *dev,
967 void *ptr, size_t size,
968 enum dma_data_direction direction);
969 void (*unmap_single)(struct ib_device *dev,
970 u64 addr, size_t size,
971 enum dma_data_direction direction);
972 u64 (*map_page)(struct ib_device *dev,
973 struct page *page, unsigned long offset,
974 size_t size,
975 enum dma_data_direction direction);
976 void (*unmap_page)(struct ib_device *dev,
977 u64 addr, size_t size,
978 enum dma_data_direction direction);
979 int (*map_sg)(struct ib_device *dev,
980 struct scatterlist *sg, int nents,
981 enum dma_data_direction direction);
982 void (*unmap_sg)(struct ib_device *dev,
983 struct scatterlist *sg, int nents,
984 enum dma_data_direction direction);
985 u64 (*dma_address)(struct ib_device *dev,
986 struct scatterlist *sg);
987 unsigned int (*dma_len)(struct ib_device *dev,
988 struct scatterlist *sg);
989 void (*sync_single_for_cpu)(struct ib_device *dev,
990 u64 dma_handle,
991 size_t size,
4deccd6d 992 enum dma_data_direction dir);
9b513090
RC
993 void (*sync_single_for_device)(struct ib_device *dev,
994 u64 dma_handle,
995 size_t size,
996 enum dma_data_direction dir);
997 void *(*alloc_coherent)(struct ib_device *dev,
998 size_t size,
999 u64 *dma_handle,
1000 gfp_t flag);
1001 void (*free_coherent)(struct ib_device *dev,
1002 size_t size, void *cpu_addr,
1003 u64 dma_handle);
1004};
1005
07ebafba
TT
1006struct iw_cm_verbs;
1007
1da177e4
LT
1008struct ib_device {
1009 struct device *dma_device;
1010
1011 char name[IB_DEVICE_NAME_MAX];
1012
1013 struct list_head event_handler_list;
1014 spinlock_t event_handler_lock;
1015
17a55f79 1016 spinlock_t client_data_lock;
1da177e4
LT
1017 struct list_head core_list;
1018 struct list_head client_data_list;
1da177e4
LT
1019
1020 struct ib_cache cache;
5eb620c8
YE
1021 int *pkey_tbl_len;
1022 int *gid_tbl_len;
1da177e4 1023
f4fd0b22
MT
1024 int num_comp_vectors;
1025
07ebafba
TT
1026 struct iw_cm_verbs *iwcm;
1027
7f624d02
SW
1028 int (*get_protocol_stats)(struct ib_device *device,
1029 union rdma_protocol_stats *stats);
1da177e4
LT
1030 int (*query_device)(struct ib_device *device,
1031 struct ib_device_attr *device_attr);
1032 int (*query_port)(struct ib_device *device,
1033 u8 port_num,
1034 struct ib_port_attr *port_attr);
a3f5adaf
EC
1035 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1036 u8 port_num);
1da177e4
LT
1037 int (*query_gid)(struct ib_device *device,
1038 u8 port_num, int index,
1039 union ib_gid *gid);
1040 int (*query_pkey)(struct ib_device *device,
1041 u8 port_num, u16 index, u16 *pkey);
1042 int (*modify_device)(struct ib_device *device,
1043 int device_modify_mask,
1044 struct ib_device_modify *device_modify);
1045 int (*modify_port)(struct ib_device *device,
1046 u8 port_num, int port_modify_mask,
1047 struct ib_port_modify *port_modify);
e2773c06
RD
1048 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1049 struct ib_udata *udata);
1050 int (*dealloc_ucontext)(struct ib_ucontext *context);
1051 int (*mmap)(struct ib_ucontext *context,
1052 struct vm_area_struct *vma);
1053 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1054 struct ib_ucontext *context,
1055 struct ib_udata *udata);
1da177e4
LT
1056 int (*dealloc_pd)(struct ib_pd *pd);
1057 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1058 struct ib_ah_attr *ah_attr);
1059 int (*modify_ah)(struct ib_ah *ah,
1060 struct ib_ah_attr *ah_attr);
1061 int (*query_ah)(struct ib_ah *ah,
1062 struct ib_ah_attr *ah_attr);
1063 int (*destroy_ah)(struct ib_ah *ah);
d41fcc67
RD
1064 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1065 struct ib_srq_init_attr *srq_init_attr,
1066 struct ib_udata *udata);
1067 int (*modify_srq)(struct ib_srq *srq,
1068 struct ib_srq_attr *srq_attr,
9bc57e2d
RC
1069 enum ib_srq_attr_mask srq_attr_mask,
1070 struct ib_udata *udata);
d41fcc67
RD
1071 int (*query_srq)(struct ib_srq *srq,
1072 struct ib_srq_attr *srq_attr);
1073 int (*destroy_srq)(struct ib_srq *srq);
1074 int (*post_srq_recv)(struct ib_srq *srq,
1075 struct ib_recv_wr *recv_wr,
1076 struct ib_recv_wr **bad_recv_wr);
1da177e4 1077 struct ib_qp * (*create_qp)(struct ib_pd *pd,
e2773c06
RD
1078 struct ib_qp_init_attr *qp_init_attr,
1079 struct ib_udata *udata);
1da177e4
LT
1080 int (*modify_qp)(struct ib_qp *qp,
1081 struct ib_qp_attr *qp_attr,
9bc57e2d
RC
1082 int qp_attr_mask,
1083 struct ib_udata *udata);
1da177e4
LT
1084 int (*query_qp)(struct ib_qp *qp,
1085 struct ib_qp_attr *qp_attr,
1086 int qp_attr_mask,
1087 struct ib_qp_init_attr *qp_init_attr);
1088 int (*destroy_qp)(struct ib_qp *qp);
1089 int (*post_send)(struct ib_qp *qp,
1090 struct ib_send_wr *send_wr,
1091 struct ib_send_wr **bad_send_wr);
1092 int (*post_recv)(struct ib_qp *qp,
1093 struct ib_recv_wr *recv_wr,
1094 struct ib_recv_wr **bad_recv_wr);
e2773c06 1095 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
f4fd0b22 1096 int comp_vector,
e2773c06
RD
1097 struct ib_ucontext *context,
1098 struct ib_udata *udata);
2dd57162
EC
1099 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1100 u16 cq_period);
1da177e4 1101 int (*destroy_cq)(struct ib_cq *cq);
33b9b3ee
RD
1102 int (*resize_cq)(struct ib_cq *cq, int cqe,
1103 struct ib_udata *udata);
1da177e4
LT
1104 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1105 struct ib_wc *wc);
1106 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1107 int (*req_notify_cq)(struct ib_cq *cq,
ed23a727 1108 enum ib_cq_notify_flags flags);
1da177e4
LT
1109 int (*req_ncomp_notif)(struct ib_cq *cq,
1110 int wc_cnt);
1111 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1112 int mr_access_flags);
1113 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1114 struct ib_phys_buf *phys_buf_array,
1115 int num_phys_buf,
1116 int mr_access_flags,
1117 u64 *iova_start);
e2773c06 1118 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
f7c6a7b5
RD
1119 u64 start, u64 length,
1120 u64 virt_addr,
e2773c06
RD
1121 int mr_access_flags,
1122 struct ib_udata *udata);
1da177e4
LT
1123 int (*query_mr)(struct ib_mr *mr,
1124 struct ib_mr_attr *mr_attr);
1125 int (*dereg_mr)(struct ib_mr *mr);
00f7ec36
SW
1126 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1127 int max_page_list_len);
1128 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1129 int page_list_len);
1130 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
1da177e4
LT
1131 int (*rereg_phys_mr)(struct ib_mr *mr,
1132 int mr_rereg_mask,
1133 struct ib_pd *pd,
1134 struct ib_phys_buf *phys_buf_array,
1135 int num_phys_buf,
1136 int mr_access_flags,
1137 u64 *iova_start);
1138 struct ib_mw * (*alloc_mw)(struct ib_pd *pd);
1139 int (*bind_mw)(struct ib_qp *qp,
1140 struct ib_mw *mw,
1141 struct ib_mw_bind *mw_bind);
1142 int (*dealloc_mw)(struct ib_mw *mw);
1143 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1144 int mr_access_flags,
1145 struct ib_fmr_attr *fmr_attr);
1146 int (*map_phys_fmr)(struct ib_fmr *fmr,
1147 u64 *page_list, int list_len,
1148 u64 iova);
1149 int (*unmap_fmr)(struct list_head *fmr_list);
1150 int (*dealloc_fmr)(struct ib_fmr *fmr);
1151 int (*attach_mcast)(struct ib_qp *qp,
1152 union ib_gid *gid,
1153 u16 lid);
1154 int (*detach_mcast)(struct ib_qp *qp,
1155 union ib_gid *gid,
1156 u16 lid);
1157 int (*process_mad)(struct ib_device *device,
1158 int process_mad_flags,
1159 u8 port_num,
1160 struct ib_wc *in_wc,
1161 struct ib_grh *in_grh,
1162 struct ib_mad *in_mad,
1163 struct ib_mad *out_mad);
59991f94
SH
1164 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1165 struct ib_ucontext *ucontext,
1166 struct ib_udata *udata);
1167 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
1da177e4 1168
9b513090
RC
1169 struct ib_dma_mapping_ops *dma_ops;
1170
e2773c06 1171 struct module *owner;
f4e91eb4 1172 struct device dev;
35be0681 1173 struct kobject *ports_parent;
1da177e4
LT
1174 struct list_head port_list;
1175
1176 enum {
1177 IB_DEV_UNINITIALIZED,
1178 IB_DEV_REGISTERED,
1179 IB_DEV_UNREGISTERED
1180 } reg_state;
1181
274c0891 1182 int uverbs_abi_ver;
17a55f79 1183 u64 uverbs_cmd_mask;
274c0891 1184
c5bcbbb9 1185 char node_desc[64];
cf311cd4 1186 __be64 node_guid;
96f15c03 1187 u32 local_dma_lkey;
1da177e4
LT
1188 u8 node_type;
1189 u8 phys_port_cnt;
1190};
1191
1192struct ib_client {
1193 char *name;
1194 void (*add) (struct ib_device *);
1195 void (*remove)(struct ib_device *);
1196
1197 struct list_head list;
1198};
1199
1200struct ib_device *ib_alloc_device(size_t size);
1201void ib_dealloc_device(struct ib_device *device);
1202
9a6edb60
RC
1203int ib_register_device(struct ib_device *device,
1204 int (*port_callback)(struct ib_device *,
1205 u8, struct kobject *));
1da177e4
LT
1206void ib_unregister_device(struct ib_device *device);
1207
1208int ib_register_client (struct ib_client *client);
1209void ib_unregister_client(struct ib_client *client);
1210
1211void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1212void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1213 void *data);
1214
e2773c06
RD
1215static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1216{
1217 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1218}
1219
1220static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1221{
1222 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1223}
1224
8a51866f
RD
1225/**
1226 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1227 * contains all required attributes and no attributes not allowed for
1228 * the given QP state transition.
1229 * @cur_state: Current QP state
1230 * @next_state: Next QP state
1231 * @type: QP type
1232 * @mask: Mask of supplied QP attributes
1233 *
1234 * This function is a helper function that a low-level driver's
1235 * modify_qp method can use to validate the consumer's input. It
1236 * checks that cur_state and next_state are valid QP states, that a
1237 * transition from cur_state to next_state is allowed by the IB spec,
1238 * and that the attribute mask supplied is allowed for the transition.
1239 */
1240int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1241 enum ib_qp_type type, enum ib_qp_attr_mask mask);
1242
1da177e4
LT
1243int ib_register_event_handler (struct ib_event_handler *event_handler);
1244int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1245void ib_dispatch_event(struct ib_event *event);
1246
1247int ib_query_device(struct ib_device *device,
1248 struct ib_device_attr *device_attr);
1249
1250int ib_query_port(struct ib_device *device,
1251 u8 port_num, struct ib_port_attr *port_attr);
1252
a3f5adaf
EC
1253enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1254 u8 port_num);
1255
1da177e4
LT
1256int ib_query_gid(struct ib_device *device,
1257 u8 port_num, int index, union ib_gid *gid);
1258
1259int ib_query_pkey(struct ib_device *device,
1260 u8 port_num, u16 index, u16 *pkey);
1261
1262int ib_modify_device(struct ib_device *device,
1263 int device_modify_mask,
1264 struct ib_device_modify *device_modify);
1265
1266int ib_modify_port(struct ib_device *device,
1267 u8 port_num, int port_modify_mask,
1268 struct ib_port_modify *port_modify);
1269
5eb620c8
YE
1270int ib_find_gid(struct ib_device *device, union ib_gid *gid,
1271 u8 *port_num, u16 *index);
1272
1273int ib_find_pkey(struct ib_device *device,
1274 u8 port_num, u16 pkey, u16 *index);
1275
1da177e4
LT
1276/**
1277 * ib_alloc_pd - Allocates an unused protection domain.
1278 * @device: The device on which to allocate the protection domain.
1279 *
1280 * A protection domain object provides an association between QPs, shared
1281 * receive queues, address handles, memory regions, and memory windows.
1282 */
1283struct ib_pd *ib_alloc_pd(struct ib_device *device);
1284
1285/**
1286 * ib_dealloc_pd - Deallocates a protection domain.
1287 * @pd: The protection domain to deallocate.
1288 */
1289int ib_dealloc_pd(struct ib_pd *pd);
1290
1291/**
1292 * ib_create_ah - Creates an address handle for the given address vector.
1293 * @pd: The protection domain associated with the address handle.
1294 * @ah_attr: The attributes of the address vector.
1295 *
1296 * The address handle is used to reference a local or global destination
1297 * in all UD QP post sends.
1298 */
1299struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1300
4e00d694
SH
1301/**
1302 * ib_init_ah_from_wc - Initializes address handle attributes from a
1303 * work completion.
1304 * @device: Device on which the received message arrived.
1305 * @port_num: Port on which the received message arrived.
1306 * @wc: Work completion associated with the received message.
1307 * @grh: References the received global route header. This parameter is
1308 * ignored unless the work completion indicates that the GRH is valid.
1309 * @ah_attr: Returned attributes that can be used when creating an address
1310 * handle for replying to the message.
1311 */
1312int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1313 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1314
513789ed
HR
1315/**
1316 * ib_create_ah_from_wc - Creates an address handle associated with the
1317 * sender of the specified work completion.
1318 * @pd: The protection domain associated with the address handle.
1319 * @wc: Work completion information associated with a received message.
1320 * @grh: References the received global route header. This parameter is
1321 * ignored unless the work completion indicates that the GRH is valid.
1322 * @port_num: The outbound port number to associate with the address.
1323 *
1324 * The address handle is used to reference a local or global destination
1325 * in all UD QP post sends.
1326 */
1327struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1328 struct ib_grh *grh, u8 port_num);
1329
1da177e4
LT
1330/**
1331 * ib_modify_ah - Modifies the address vector associated with an address
1332 * handle.
1333 * @ah: The address handle to modify.
1334 * @ah_attr: The new address vector attributes to associate with the
1335 * address handle.
1336 */
1337int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1338
1339/**
1340 * ib_query_ah - Queries the address vector associated with an address
1341 * handle.
1342 * @ah: The address handle to query.
1343 * @ah_attr: The address vector attributes associated with the address
1344 * handle.
1345 */
1346int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1347
1348/**
1349 * ib_destroy_ah - Destroys an address handle.
1350 * @ah: The address handle to destroy.
1351 */
1352int ib_destroy_ah(struct ib_ah *ah);
1353
d41fcc67
RD
1354/**
1355 * ib_create_srq - Creates a SRQ associated with the specified protection
1356 * domain.
1357 * @pd: The protection domain associated with the SRQ.
abb6e9ba
DB
1358 * @srq_init_attr: A list of initial attributes required to create the
1359 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1360 * the actual capabilities of the created SRQ.
d41fcc67
RD
1361 *
1362 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1363 * requested size of the SRQ, and set to the actual values allocated
1364 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1365 * will always be at least as large as the requested values.
1366 */
1367struct ib_srq *ib_create_srq(struct ib_pd *pd,
1368 struct ib_srq_init_attr *srq_init_attr);
1369
1370/**
1371 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1372 * @srq: The SRQ to modify.
1373 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1374 * the current values of selected SRQ attributes are returned.
1375 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1376 * are being modified.
1377 *
1378 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1379 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1380 * the number of receives queued drops below the limit.
1381 */
1382int ib_modify_srq(struct ib_srq *srq,
1383 struct ib_srq_attr *srq_attr,
1384 enum ib_srq_attr_mask srq_attr_mask);
1385
1386/**
1387 * ib_query_srq - Returns the attribute list and current values for the
1388 * specified SRQ.
1389 * @srq: The SRQ to query.
1390 * @srq_attr: The attributes of the specified SRQ.
1391 */
1392int ib_query_srq(struct ib_srq *srq,
1393 struct ib_srq_attr *srq_attr);
1394
1395/**
1396 * ib_destroy_srq - Destroys the specified SRQ.
1397 * @srq: The SRQ to destroy.
1398 */
1399int ib_destroy_srq(struct ib_srq *srq);
1400
1401/**
1402 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1403 * @srq: The SRQ to post the work request on.
1404 * @recv_wr: A list of work requests to post on the receive queue.
1405 * @bad_recv_wr: On an immediate failure, this parameter will reference
1406 * the work request that failed to be posted on the QP.
1407 */
1408static inline int ib_post_srq_recv(struct ib_srq *srq,
1409 struct ib_recv_wr *recv_wr,
1410 struct ib_recv_wr **bad_recv_wr)
1411{
1412 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1413}
1414
1da177e4
LT
1415/**
1416 * ib_create_qp - Creates a QP associated with the specified protection
1417 * domain.
1418 * @pd: The protection domain associated with the QP.
abb6e9ba
DB
1419 * @qp_init_attr: A list of initial attributes required to create the
1420 * QP. If QP creation succeeds, then the attributes are updated to
1421 * the actual capabilities of the created QP.
1da177e4
LT
1422 */
1423struct ib_qp *ib_create_qp(struct ib_pd *pd,
1424 struct ib_qp_init_attr *qp_init_attr);
1425
1426/**
1427 * ib_modify_qp - Modifies the attributes for the specified QP and then
1428 * transitions the QP to the given state.
1429 * @qp: The QP to modify.
1430 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1431 * the current values of selected QP attributes are returned.
1432 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1433 * are being modified.
1434 */
1435int ib_modify_qp(struct ib_qp *qp,
1436 struct ib_qp_attr *qp_attr,
1437 int qp_attr_mask);
1438
1439/**
1440 * ib_query_qp - Returns the attribute list and current values for the
1441 * specified QP.
1442 * @qp: The QP to query.
1443 * @qp_attr: The attributes of the specified QP.
1444 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1445 * @qp_init_attr: Additional attributes of the selected QP.
1446 *
1447 * The qp_attr_mask may be used to limit the query to gathering only the
1448 * selected attributes.
1449 */
1450int ib_query_qp(struct ib_qp *qp,
1451 struct ib_qp_attr *qp_attr,
1452 int qp_attr_mask,
1453 struct ib_qp_init_attr *qp_init_attr);
1454
1455/**
1456 * ib_destroy_qp - Destroys the specified QP.
1457 * @qp: The QP to destroy.
1458 */
1459int ib_destroy_qp(struct ib_qp *qp);
1460
1461/**
1462 * ib_post_send - Posts a list of work requests to the send queue of
1463 * the specified QP.
1464 * @qp: The QP to post the work request on.
1465 * @send_wr: A list of work requests to post on the send queue.
1466 * @bad_send_wr: On an immediate failure, this parameter will reference
1467 * the work request that failed to be posted on the QP.
55464d46
BVA
1468 *
1469 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1470 * error is returned, the QP state shall not be affected,
1471 * ib_post_send() will return an immediate error after queueing any
1472 * earlier work requests in the list.
1da177e4
LT
1473 */
1474static inline int ib_post_send(struct ib_qp *qp,
1475 struct ib_send_wr *send_wr,
1476 struct ib_send_wr **bad_send_wr)
1477{
1478 return qp->device->post_send(qp, send_wr, bad_send_wr);
1479}
1480
1481/**
1482 * ib_post_recv - Posts a list of work requests to the receive queue of
1483 * the specified QP.
1484 * @qp: The QP to post the work request on.
1485 * @recv_wr: A list of work requests to post on the receive queue.
1486 * @bad_recv_wr: On an immediate failure, this parameter will reference
1487 * the work request that failed to be posted on the QP.
1488 */
1489static inline int ib_post_recv(struct ib_qp *qp,
1490 struct ib_recv_wr *recv_wr,
1491 struct ib_recv_wr **bad_recv_wr)
1492{
1493 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1494}
1495
1496/**
1497 * ib_create_cq - Creates a CQ on the specified device.
1498 * @device: The device on which to create the CQ.
1499 * @comp_handler: A user-specified callback that is invoked when a
1500 * completion event occurs on the CQ.
1501 * @event_handler: A user-specified callback that is invoked when an
1502 * asynchronous event not associated with a completion occurs on the CQ.
1503 * @cq_context: Context associated with the CQ returned to the user via
1504 * the associated completion and event handlers.
1505 * @cqe: The minimum size of the CQ.
f4fd0b22
MT
1506 * @comp_vector - Completion vector used to signal completion events.
1507 * Must be >= 0 and < context->num_comp_vectors.
1da177e4
LT
1508 *
1509 * Users can examine the cq structure to determine the actual CQ size.
1510 */
1511struct ib_cq *ib_create_cq(struct ib_device *device,
1512 ib_comp_handler comp_handler,
1513 void (*event_handler)(struct ib_event *, void *),
f4fd0b22 1514 void *cq_context, int cqe, int comp_vector);
1da177e4
LT
1515
1516/**
1517 * ib_resize_cq - Modifies the capacity of the CQ.
1518 * @cq: The CQ to resize.
1519 * @cqe: The minimum size of the CQ.
1520 *
1521 * Users can examine the cq structure to determine the actual CQ size.
1522 */
1523int ib_resize_cq(struct ib_cq *cq, int cqe);
1524
2dd57162
EC
1525/**
1526 * ib_modify_cq - Modifies moderation params of the CQ
1527 * @cq: The CQ to modify.
1528 * @cq_count: number of CQEs that will trigger an event
1529 * @cq_period: max period of time in usec before triggering an event
1530 *
1531 */
1532int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
1533
1da177e4
LT
1534/**
1535 * ib_destroy_cq - Destroys the specified CQ.
1536 * @cq: The CQ to destroy.
1537 */
1538int ib_destroy_cq(struct ib_cq *cq);
1539
1540/**
1541 * ib_poll_cq - poll a CQ for completion(s)
1542 * @cq:the CQ being polled
1543 * @num_entries:maximum number of completions to return
1544 * @wc:array of at least @num_entries &struct ib_wc where completions
1545 * will be returned
1546 *
1547 * Poll a CQ for (possibly multiple) completions. If the return value
1548 * is < 0, an error occurred. If the return value is >= 0, it is the
1549 * number of completions returned. If the return value is
1550 * non-negative and < num_entries, then the CQ was emptied.
1551 */
1552static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1553 struct ib_wc *wc)
1554{
1555 return cq->device->poll_cq(cq, num_entries, wc);
1556}
1557
1558/**
1559 * ib_peek_cq - Returns the number of unreaped completions currently
1560 * on the specified CQ.
1561 * @cq: The CQ to peek.
1562 * @wc_cnt: A minimum number of unreaped completions to check for.
1563 *
1564 * If the number of unreaped completions is greater than or equal to wc_cnt,
1565 * this function returns wc_cnt, otherwise, it returns the actual number of
1566 * unreaped completions.
1567 */
1568int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1569
1570/**
1571 * ib_req_notify_cq - Request completion notification on a CQ.
1572 * @cq: The CQ to generate an event for.
ed23a727
RD
1573 * @flags:
1574 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1575 * to request an event on the next solicited event or next work
1576 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1577 * may also be |ed in to request a hint about missed events, as
1578 * described below.
1579 *
1580 * Return Value:
1581 * < 0 means an error occurred while requesting notification
1582 * == 0 means notification was requested successfully, and if
1583 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1584 * were missed and it is safe to wait for another event. In
1585 * this case is it guaranteed that any work completions added
1586 * to the CQ since the last CQ poll will trigger a completion
1587 * notification event.
1588 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1589 * in. It means that the consumer must poll the CQ again to
1590 * make sure it is empty to avoid missing an event because of a
1591 * race between requesting notification and an entry being
1592 * added to the CQ. This return value means it is possible
1593 * (but not guaranteed) that a work completion has been added
1594 * to the CQ since the last poll without triggering a
1595 * completion notification event.
1da177e4
LT
1596 */
1597static inline int ib_req_notify_cq(struct ib_cq *cq,
ed23a727 1598 enum ib_cq_notify_flags flags)
1da177e4 1599{
ed23a727 1600 return cq->device->req_notify_cq(cq, flags);
1da177e4
LT
1601}
1602
1603/**
1604 * ib_req_ncomp_notif - Request completion notification when there are
1605 * at least the specified number of unreaped completions on the CQ.
1606 * @cq: The CQ to generate an event for.
1607 * @wc_cnt: The number of unreaped completions that should be on the
1608 * CQ before an event is generated.
1609 */
1610static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1611{
1612 return cq->device->req_ncomp_notif ?
1613 cq->device->req_ncomp_notif(cq, wc_cnt) :
1614 -ENOSYS;
1615}
1616
1617/**
1618 * ib_get_dma_mr - Returns a memory region for system memory that is
1619 * usable for DMA.
1620 * @pd: The protection domain associated with the memory region.
1621 * @mr_access_flags: Specifies the memory access rights.
9b513090
RC
1622 *
1623 * Note that the ib_dma_*() functions defined below must be used
1624 * to create/destroy addresses used with the Lkey or Rkey returned
1625 * by ib_get_dma_mr().
1da177e4
LT
1626 */
1627struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1628
9b513090
RC
1629/**
1630 * ib_dma_mapping_error - check a DMA addr for error
1631 * @dev: The device for which the dma_addr was created
1632 * @dma_addr: The DMA address to check
1633 */
1634static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1635{
d1998ef3
BC
1636 if (dev->dma_ops)
1637 return dev->dma_ops->mapping_error(dev, dma_addr);
8d8bb39b 1638 return dma_mapping_error(dev->dma_device, dma_addr);
9b513090
RC
1639}
1640
1641/**
1642 * ib_dma_map_single - Map a kernel virtual address to DMA address
1643 * @dev: The device for which the dma_addr is to be created
1644 * @cpu_addr: The kernel virtual address
1645 * @size: The size of the region in bytes
1646 * @direction: The direction of the DMA
1647 */
1648static inline u64 ib_dma_map_single(struct ib_device *dev,
1649 void *cpu_addr, size_t size,
1650 enum dma_data_direction direction)
1651{
d1998ef3
BC
1652 if (dev->dma_ops)
1653 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
1654 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
9b513090
RC
1655}
1656
1657/**
1658 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1659 * @dev: The device for which the DMA address was created
1660 * @addr: The DMA address
1661 * @size: The size of the region in bytes
1662 * @direction: The direction of the DMA
1663 */
1664static inline void ib_dma_unmap_single(struct ib_device *dev,
1665 u64 addr, size_t size,
1666 enum dma_data_direction direction)
1667{
d1998ef3
BC
1668 if (dev->dma_ops)
1669 dev->dma_ops->unmap_single(dev, addr, size, direction);
1670 else
9b513090
RC
1671 dma_unmap_single(dev->dma_device, addr, size, direction);
1672}
1673
cb9fbc5c
AK
1674static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
1675 void *cpu_addr, size_t size,
1676 enum dma_data_direction direction,
1677 struct dma_attrs *attrs)
1678{
1679 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
1680 direction, attrs);
1681}
1682
1683static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
1684 u64 addr, size_t size,
1685 enum dma_data_direction direction,
1686 struct dma_attrs *attrs)
1687{
1688 return dma_unmap_single_attrs(dev->dma_device, addr, size,
1689 direction, attrs);
1690}
1691
9b513090
RC
1692/**
1693 * ib_dma_map_page - Map a physical page to DMA address
1694 * @dev: The device for which the dma_addr is to be created
1695 * @page: The page to be mapped
1696 * @offset: The offset within the page
1697 * @size: The size of the region in bytes
1698 * @direction: The direction of the DMA
1699 */
1700static inline u64 ib_dma_map_page(struct ib_device *dev,
1701 struct page *page,
1702 unsigned long offset,
1703 size_t size,
1704 enum dma_data_direction direction)
1705{
d1998ef3
BC
1706 if (dev->dma_ops)
1707 return dev->dma_ops->map_page(dev, page, offset, size, direction);
1708 return dma_map_page(dev->dma_device, page, offset, size, direction);
9b513090
RC
1709}
1710
1711/**
1712 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
1713 * @dev: The device for which the DMA address was created
1714 * @addr: The DMA address
1715 * @size: The size of the region in bytes
1716 * @direction: The direction of the DMA
1717 */
1718static inline void ib_dma_unmap_page(struct ib_device *dev,
1719 u64 addr, size_t size,
1720 enum dma_data_direction direction)
1721{
d1998ef3
BC
1722 if (dev->dma_ops)
1723 dev->dma_ops->unmap_page(dev, addr, size, direction);
1724 else
9b513090
RC
1725 dma_unmap_page(dev->dma_device, addr, size, direction);
1726}
1727
1728/**
1729 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
1730 * @dev: The device for which the DMA addresses are to be created
1731 * @sg: The array of scatter/gather entries
1732 * @nents: The number of scatter/gather entries
1733 * @direction: The direction of the DMA
1734 */
1735static inline int ib_dma_map_sg(struct ib_device *dev,
1736 struct scatterlist *sg, int nents,
1737 enum dma_data_direction direction)
1738{
d1998ef3
BC
1739 if (dev->dma_ops)
1740 return dev->dma_ops->map_sg(dev, sg, nents, direction);
1741 return dma_map_sg(dev->dma_device, sg, nents, direction);
9b513090
RC
1742}
1743
1744/**
1745 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
1746 * @dev: The device for which the DMA addresses were created
1747 * @sg: The array of scatter/gather entries
1748 * @nents: The number of scatter/gather entries
1749 * @direction: The direction of the DMA
1750 */
1751static inline void ib_dma_unmap_sg(struct ib_device *dev,
1752 struct scatterlist *sg, int nents,
1753 enum dma_data_direction direction)
1754{
d1998ef3
BC
1755 if (dev->dma_ops)
1756 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
1757 else
9b513090
RC
1758 dma_unmap_sg(dev->dma_device, sg, nents, direction);
1759}
1760
cb9fbc5c
AK
1761static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
1762 struct scatterlist *sg, int nents,
1763 enum dma_data_direction direction,
1764 struct dma_attrs *attrs)
1765{
1766 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1767}
1768
1769static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
1770 struct scatterlist *sg, int nents,
1771 enum dma_data_direction direction,
1772 struct dma_attrs *attrs)
1773{
1774 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1775}
9b513090
RC
1776/**
1777 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
1778 * @dev: The device for which the DMA addresses were created
1779 * @sg: The scatter/gather entry
1780 */
1781static inline u64 ib_sg_dma_address(struct ib_device *dev,
1782 struct scatterlist *sg)
1783{
d1998ef3
BC
1784 if (dev->dma_ops)
1785 return dev->dma_ops->dma_address(dev, sg);
1786 return sg_dma_address(sg);
9b513090
RC
1787}
1788
1789/**
1790 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
1791 * @dev: The device for which the DMA addresses were created
1792 * @sg: The scatter/gather entry
1793 */
1794static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
1795 struct scatterlist *sg)
1796{
d1998ef3
BC
1797 if (dev->dma_ops)
1798 return dev->dma_ops->dma_len(dev, sg);
1799 return sg_dma_len(sg);
9b513090
RC
1800}
1801
1802/**
1803 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
1804 * @dev: The device for which the DMA address was created
1805 * @addr: The DMA address
1806 * @size: The size of the region in bytes
1807 * @dir: The direction of the DMA
1808 */
1809static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
1810 u64 addr,
1811 size_t size,
1812 enum dma_data_direction dir)
1813{
d1998ef3
BC
1814 if (dev->dma_ops)
1815 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
1816 else
9b513090
RC
1817 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
1818}
1819
1820/**
1821 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
1822 * @dev: The device for which the DMA address was created
1823 * @addr: The DMA address
1824 * @size: The size of the region in bytes
1825 * @dir: The direction of the DMA
1826 */
1827static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
1828 u64 addr,
1829 size_t size,
1830 enum dma_data_direction dir)
1831{
d1998ef3
BC
1832 if (dev->dma_ops)
1833 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
1834 else
9b513090
RC
1835 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
1836}
1837
1838/**
1839 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
1840 * @dev: The device for which the DMA address is requested
1841 * @size: The size of the region to allocate in bytes
1842 * @dma_handle: A pointer for returning the DMA address of the region
1843 * @flag: memory allocator flags
1844 */
1845static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
1846 size_t size,
1847 u64 *dma_handle,
1848 gfp_t flag)
1849{
d1998ef3
BC
1850 if (dev->dma_ops)
1851 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
c59a3da1
RD
1852 else {
1853 dma_addr_t handle;
1854 void *ret;
1855
1856 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
1857 *dma_handle = handle;
1858 return ret;
1859 }
9b513090
RC
1860}
1861
1862/**
1863 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
1864 * @dev: The device for which the DMA addresses were allocated
1865 * @size: The size of the region
1866 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
1867 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
1868 */
1869static inline void ib_dma_free_coherent(struct ib_device *dev,
1870 size_t size, void *cpu_addr,
1871 u64 dma_handle)
1872{
d1998ef3
BC
1873 if (dev->dma_ops)
1874 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
1875 else
9b513090
RC
1876 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
1877}
1878
1da177e4
LT
1879/**
1880 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
1881 * by an HCA.
1882 * @pd: The protection domain associated assigned to the registered region.
1883 * @phys_buf_array: Specifies a list of physical buffers to use in the
1884 * memory region.
1885 * @num_phys_buf: Specifies the size of the phys_buf_array.
1886 * @mr_access_flags: Specifies the memory access rights.
1887 * @iova_start: The offset of the region's starting I/O virtual address.
1888 */
1889struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
1890 struct ib_phys_buf *phys_buf_array,
1891 int num_phys_buf,
1892 int mr_access_flags,
1893 u64 *iova_start);
1894
1895/**
1896 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
1897 * Conceptually, this call performs the functions deregister memory region
1898 * followed by register physical memory region. Where possible,
1899 * resources are reused instead of deallocated and reallocated.
1900 * @mr: The memory region to modify.
1901 * @mr_rereg_mask: A bit-mask used to indicate which of the following
1902 * properties of the memory region are being modified.
1903 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
1904 * the new protection domain to associated with the memory region,
1905 * otherwise, this parameter is ignored.
1906 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1907 * field specifies a list of physical buffers to use in the new
1908 * translation, otherwise, this parameter is ignored.
1909 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1910 * field specifies the size of the phys_buf_array, otherwise, this
1911 * parameter is ignored.
1912 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
1913 * field specifies the new memory access rights, otherwise, this
1914 * parameter is ignored.
1915 * @iova_start: The offset of the region's starting I/O virtual address.
1916 */
1917int ib_rereg_phys_mr(struct ib_mr *mr,
1918 int mr_rereg_mask,
1919 struct ib_pd *pd,
1920 struct ib_phys_buf *phys_buf_array,
1921 int num_phys_buf,
1922 int mr_access_flags,
1923 u64 *iova_start);
1924
1925/**
1926 * ib_query_mr - Retrieves information about a specific memory region.
1927 * @mr: The memory region to retrieve information about.
1928 * @mr_attr: The attributes of the specified memory region.
1929 */
1930int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
1931
1932/**
1933 * ib_dereg_mr - Deregisters a memory region and removes it from the
1934 * HCA translation table.
1935 * @mr: The memory region to deregister.
1936 */
1937int ib_dereg_mr(struct ib_mr *mr);
1938
00f7ec36
SW
1939/**
1940 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
1941 * IB_WR_FAST_REG_MR send work request.
1942 * @pd: The protection domain associated with the region.
1943 * @max_page_list_len: requested max physical buffer list length to be
1944 * used with fast register work requests for this MR.
1945 */
1946struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
1947
1948/**
1949 * ib_alloc_fast_reg_page_list - Allocates a page list array
1950 * @device - ib device pointer.
1951 * @page_list_len - size of the page list array to be allocated.
1952 *
1953 * This allocates and returns a struct ib_fast_reg_page_list * and a
1954 * page_list array that is at least page_list_len in size. The actual
1955 * size is returned in max_page_list_len. The caller is responsible
1956 * for initializing the contents of the page_list array before posting
1957 * a send work request with the IB_WC_FAST_REG_MR opcode.
1958 *
1959 * The page_list array entries must be translated using one of the
1960 * ib_dma_*() functions just like the addresses passed to
1961 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
1962 * ib_fast_reg_page_list must not be modified by the caller until the
1963 * IB_WC_FAST_REG_MR work request completes.
1964 */
1965struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
1966 struct ib_device *device, int page_list_len);
1967
1968/**
1969 * ib_free_fast_reg_page_list - Deallocates a previously allocated
1970 * page list array.
1971 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
1972 */
1973void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
1974
1975/**
1976 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
1977 * R_Key and L_Key.
1978 * @mr - struct ib_mr pointer to be updated.
1979 * @newkey - new key to be used.
1980 */
1981static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
1982{
1983 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
1984 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
1985}
1986
1da177e4
LT
1987/**
1988 * ib_alloc_mw - Allocates a memory window.
1989 * @pd: The protection domain associated with the memory window.
1990 */
1991struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
1992
1993/**
1994 * ib_bind_mw - Posts a work request to the send queue of the specified
1995 * QP, which binds the memory window to the given address range and
1996 * remote access attributes.
1997 * @qp: QP to post the bind work request on.
1998 * @mw: The memory window to bind.
1999 * @mw_bind: Specifies information about the memory window, including
2000 * its address range, remote access rights, and associated memory region.
2001 */
2002static inline int ib_bind_mw(struct ib_qp *qp,
2003 struct ib_mw *mw,
2004 struct ib_mw_bind *mw_bind)
2005{
2006 /* XXX reference counting in corresponding MR? */
2007 return mw->device->bind_mw ?
2008 mw->device->bind_mw(qp, mw, mw_bind) :
2009 -ENOSYS;
2010}
2011
2012/**
2013 * ib_dealloc_mw - Deallocates a memory window.
2014 * @mw: The memory window to deallocate.
2015 */
2016int ib_dealloc_mw(struct ib_mw *mw);
2017
2018/**
2019 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2020 * @pd: The protection domain associated with the unmapped region.
2021 * @mr_access_flags: Specifies the memory access rights.
2022 * @fmr_attr: Attributes of the unmapped region.
2023 *
2024 * A fast memory region must be mapped before it can be used as part of
2025 * a work request.
2026 */
2027struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2028 int mr_access_flags,
2029 struct ib_fmr_attr *fmr_attr);
2030
2031/**
2032 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2033 * @fmr: The fast memory region to associate with the pages.
2034 * @page_list: An array of physical pages to map to the fast memory region.
2035 * @list_len: The number of pages in page_list.
2036 * @iova: The I/O virtual address to use with the mapped region.
2037 */
2038static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2039 u64 *page_list, int list_len,
2040 u64 iova)
2041{
2042 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2043}
2044
2045/**
2046 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2047 * @fmr_list: A linked list of fast memory regions to unmap.
2048 */
2049int ib_unmap_fmr(struct list_head *fmr_list);
2050
2051/**
2052 * ib_dealloc_fmr - Deallocates a fast memory region.
2053 * @fmr: The fast memory region to deallocate.
2054 */
2055int ib_dealloc_fmr(struct ib_fmr *fmr);
2056
2057/**
2058 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2059 * @qp: QP to attach to the multicast group. The QP must be type
2060 * IB_QPT_UD.
2061 * @gid: Multicast group GID.
2062 * @lid: Multicast group LID in host byte order.
2063 *
2064 * In order to send and receive multicast packets, subnet
2065 * administration must have created the multicast group and configured
2066 * the fabric appropriately. The port associated with the specified
2067 * QP must also be a member of the multicast group.
2068 */
2069int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2070
2071/**
2072 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2073 * @qp: QP to detach from the multicast group.
2074 * @gid: Multicast group GID.
2075 * @lid: Multicast group LID in host byte order.
2076 */
2077int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2078
59991f94
SH
2079/**
2080 * ib_alloc_xrcd - Allocates an XRC domain.
2081 * @device: The device on which to allocate the XRC domain.
2082 */
2083struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2084
2085/**
2086 * ib_dealloc_xrcd - Deallocates an XRC domain.
2087 * @xrcd: The XRC domain to deallocate.
2088 */
2089int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2090
1da177e4 2091#endif /* IB_VERBS_H */