xref: /freebsd/contrib/ofed/libibverbs/ibverbs.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*
2  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3  * Copyright (c) 2007 Cisco Systems, Inc.  All rights reserved.
4  *
5  * This software is available to you under a choice of one of two
6  * licenses.  You may choose to be licensed under the terms of the GNU
7  * General Public License (GPL) Version 2, available from the file
8  * COPYING in the main directory of this source tree, or the
9  * OpenIB.org BSD license below:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      - Redistributions of source code must retain the above
16  *        copyright notice, this list of conditions and the following
17  *        disclaimer.
18  *
19  *      - Redistributions in binary form must reproduce the above
20  *        copyright notice, this list of conditions and the following
21  *        disclaimer in the documentation and/or other materials
22  *        provided with the distribution.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31  * SOFTWARE.
32  */
33 
34 #ifndef IB_VERBS_H
35 #define IB_VERBS_H
36 
37 #include <pthread.h>
38 
39 #include <infiniband/driver.h>
40 
41 #define INIT		__attribute__((constructor))
42 
43 #define DEFAULT_ABI	"IBVERBS_1.1"
44 
45 #define symver(name, api, ver) asm(".symver " #name "," #api "@" #ver)
46 #define default_symver(name, api)                                              \
47 	asm(".symver " #name "," #api "@@" DEFAULT_ABI)
48 #define private_symver(name, api)                                              \
49 	asm(".symver " #name "," #api "@@IBVERBS_PRIVATE_14")
50 
51 #define PFX		"libibverbs: "
52 
53 struct ibv_abi_compat_v2 {
54 	struct ibv_comp_channel	channel;
55 	pthread_mutex_t		in_use;
56 };
57 
58 extern int abi_ver;
59 
60 int ibverbs_init(struct ibv_device ***list);
61 
62 struct verbs_ex_private {
63 	struct ibv_cq_ex *(*create_cq_ex)(struct ibv_context *context,
64 					  struct ibv_cq_init_attr_ex *init_attr);
65 };
66 
67 #define IBV_INIT_CMD(cmd, size, opcode)					\
68 	do {								\
69 		if (abi_ver > 2)					\
70 			(cmd)->command = IB_USER_VERBS_CMD_##opcode;	\
71 		else							\
72 			(cmd)->command = IB_USER_VERBS_CMD_##opcode##_V2; \
73 		(cmd)->in_words  = (size) / 4;				\
74 		(cmd)->out_words = 0;					\
75 	} while (0)
76 
77 #define IBV_INIT_CMD_RESP(cmd, size, opcode, out, outsize)		\
78 	do {								\
79 		if (abi_ver > 2)					\
80 			(cmd)->command = IB_USER_VERBS_CMD_##opcode;	\
81 		else							\
82 			(cmd)->command = IB_USER_VERBS_CMD_##opcode##_V2; \
83 		(cmd)->in_words  = (size) / 4;				\
84 		(cmd)->out_words = (outsize) / 4;			\
85 		(cmd)->response  = (uintptr_t) (out);			\
86 	} while (0)
87 
88 #define IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, size, opcode, out, resp_size,\
89 		outsize)						   \
90 	do {                                                               \
91 		size_t c_size = cmd_size - sizeof(struct ex_hdr);	   \
92 		if (abi_ver > 2)					   \
93 			(cmd)->hdr.command = IB_USER_VERBS_CMD_##opcode;   \
94 		else							   \
95 			(cmd)->hdr.command =				   \
96 				IB_USER_VERBS_CMD_##opcode##_V2;	   \
97 		(cmd)->hdr.in_words  = ((c_size) / 8);                     \
98 		(cmd)->hdr.out_words = ((resp_size) / 8);                  \
99 		(cmd)->hdr.provider_in_words   = (((size) - (cmd_size))/8);\
100 		(cmd)->hdr.provider_out_words  =			   \
101 			     (((outsize) - (resp_size)) / 8);              \
102 		(cmd)->hdr.response  = (uintptr_t) (out);                  \
103 		(cmd)->hdr.reserved = 0;				   \
104 	} while (0)
105 
106 #define IBV_INIT_CMD_RESP_EX_VCMD(cmd, cmd_size, size, opcode, out, outsize) \
107 	IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, size, opcode, out,	     \
108 			sizeof(*(out)), outsize)
109 
110 #define IBV_INIT_CMD_RESP_EX(cmd, size, opcode, out, outsize)		     \
111 	IBV_INIT_CMD_RESP_EX_V(cmd, sizeof(*(cmd)), size, opcode, out,    \
112 			sizeof(*(out)), outsize)
113 
114 #define IBV_INIT_CMD_EX(cmd, size, opcode)				     \
115 	IBV_INIT_CMD_RESP_EX_V(cmd, sizeof(*(cmd)), size, opcode, NULL, 0, 0)
116 
117 #endif /* IB_VERBS_H */
118