xref: /illumos-gate/usr/src/uts/common/sys/rsm/rsm.h (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_RSM_RSM_H
28 #define	_SYS_RSM_RSM_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/rsm/rsm_common.h>
35 #include <sys/rsm/rsmapi_common.h>
36 
37 #define	RSM_IOCTL_CONTROLLER	0x00
38 #define	RSM_IOCTL_EXPORT_SEG	0x10
39 #define	RSM_IOCTL_IMPORT_SEG	0x20
40 #define	RSM_IOCTL_QUEUE		0x30
41 #define	RSM_IOCTL_TOPOLOGY	0x40
42 #define	RSM_IOCTL_BAR		0x50
43 #define	RSM_IOCTL_ERRCNT	0x60
44 #define	RSM_IOCTL_BELL		0x70
45 #define	RSM_IOCTL_IOVEC		0x80
46 #define	RSM_IOCTL_MAP_ADDR	0x90
47 
48 #define	RSM_IOCTL_ATTR	RSM_IOCTL_CONTROLLER + 0x0 /* get device attribute */
49 #define	RSM_IOCTL_BAR_INFO RSM_IOCTL_CONTROLLER + 0x1 /* get barrier info */
50 
51 #define	RSM_IOCTL_CREATE	RSM_IOCTL_EXPORT_SEG + 0x1
52 #define	RSM_IOCTL_BIND		RSM_IOCTL_EXPORT_SEG + 0x3
53 #define	RSM_IOCTL_REBIND	RSM_IOCTL_EXPORT_SEG + 0x4
54 #define	RSM_IOCTL_UNBIND	RSM_IOCTL_EXPORT_SEG + 0x5
55 #define	RSM_IOCTL_PUBLISH	RSM_IOCTL_EXPORT_SEG + 0x6
56 #define	RSM_IOCTL_REPUBLISH	RSM_IOCTL_EXPORT_SEG + 0x7
57 #define	RSM_IOCTL_UNPUBLISH	RSM_IOCTL_EXPORT_SEG + 0x8
58 
59 #define	RSM_IOCTL_CONNECT	RSM_IOCTL_IMPORT_SEG + 0x0
60 #define	RSM_IOCTL_DISCONNECT	RSM_IOCTL_IMPORT_SEG + 0x1
61 
62 #define	RSM_IOCTL_TOPOLOGY_SIZE	RSM_IOCTL_TOPOLOGY + 0x1
63 #define	RSM_IOCTL_TOPOLOGY_DATA	RSM_IOCTL_TOPOLOGY + 0x2
64 
65 #define	RSM_IOCTL_GETV		RSM_IOCTL_IOVEC	+ 0x1
66 #define	RSM_IOCTL_PUTV		RSM_IOCTL_IOVEC	+ 0x2
67 
68 #define	RSM_IOCTL_BAR_OPEN	RSM_IOCTL_BAR + 0x1
69 #define	RSM_IOCTL_BAR_ORDER	RSM_IOCTL_BAR + 0x2
70 #define	RSM_IOCTL_BAR_CLOSE	RSM_IOCTL_BAR + 0x3
71 #define	RSM_IOCTL_BAR_CHECK	RSM_IOCTL_BAR + 0x4
72 
73 #define	RSM_IOCTL_RING_BELL	RSM_IOCTL_BELL + 0x1
74 #define	RSM_IOCTL_CONSUMEEVENT	RSM_IOCTL_BELL + 0x2
75 
76 #define	RSM_IOCTL_MAP_TO_ADDR		RSM_IOCTL_MAP_ADDR + 0x1
77 #define	RSM_IOCTL_MAP_TO_NODEID	RSM_IOCTL_MAP_ADDR + 0x2
78 
79 #define	RSM_IOCTL_CMDGRP(cmd)	((cmd) & 0xfffffff0)
80 
81 #define	BETWEEN(x, lo, hi)	(((x) >= (lo)) && ((x) <= (hi)))
82 
83 #define	RSM_MAX_IOVLEN	4
84 /*
85  * DEBUG message categories
86  * 0xABCD:  A=module, B=functionality C=operation D=misc
87  *
88  */
89 #define	RSM_KERNEL_AGENT	0x1000  /* kernel agent messages	*/
90 #define	RSM_LIBRARY		0x2000  /* rsmapi library messages	*/
91 #define	RSM_OPS			0x4000	/* rsmops module messages	*/
92 #define	RSM_PATH_MANAGER	0x8000	/* path manager messages	*/
93 #define	RSM_MODULE_ALL		0xF000
94 
95 #define	RSM_IMPORT		0x0100  /* import operations		*/
96 #define	RSM_EXPORT		0x0200	/* export operations		*/
97 #define	RSM_LOOPBACK		0x0400	/* loopback mode		*/
98 #define	RSM_FUNC_ALL		0x0F00
99 
100 #define	RSM_DDI			0x0010	/* dev driver infrastructure    */
101 #define	RSM_IO_ROUTINES		0x0020	/* put/get processing		*/
102 #define	RSM_IOCTL		0x0040	/* ioctl processing		*/
103 #define	RSM_INTR_CALLBACK	0x0080	/* interrupt processing		*/
104 #define	RSM_OPER_ALL		0x00F0
105 
106 #define	RSM_FLOWCONTROL		0x0001	/* flow control related		*/
107 
108 #define	RSM_KERNEL_ALL		(RSM_KERNEL_AGENT | RSM_PATH_MANAGER | 0x0FFF)
109 #define	RSM_ALL			0xFFFF  /* All of the above		*/
110 
111 /*
112  * DEBUG message levels
113  */
114 #define	RSM_DEBUG_VERBOSE	6
115 #define	RSM_DEBUG_LVL2		5
116 #define	RSM_DEBUG_LVL1		4
117 #define	RSM_DEBUG		3
118 #define	RSM_NOTICE		2
119 #define	RSM_WARNING		1
120 #define	RSM_ERR			0
121 
122 #ifdef	DEBUG
123 extern void dbg_printf(int category, int level, char *fmt, ...);
124 #define	DBG_DEFINE(var, value) int var = (value)
125 #define	DBG_DEFINE_STR(var, value) char *var = (value)
126 #define	DBG_ADDCATEGORY(var, category) (var |= (category))
127 #define	DBG_PRINTF(message) dbg_printf message
128 #else
129 #define	DBG_DEFINE(var, value)
130 #define	DBG_DEFINE_STR(var, value)
131 #define	DBG_ADDCATEGORY(var, category)
132 #define	DBG_PRINTF(message)
133 #endif /* DEBUG */
134 
135 typedef	uint16_t	rsm_gnum_t;
136 
137 /*
138  * data struct used between rsm base library and kernel agent for IOCTLS
139  */
140 typedef struct {
141 	/* following fields should be identical to rsmapi_controller_attr_t */
142 	uint_t		attr_direct_access_sizes;
143 	uint_t		attr_atomic_sizes;
144 	size_t		attr_page_size;
145 	size_t		attr_max_export_segment_size;
146 	size_t		attr_tot_export_segment_size;
147 	ulong_t		attr_max_export_segments;
148 	size_t		attr_max_import_map_size;
149 	size_t		attr_tot_import_map_size;
150 	ulong_t		attr_max_import_segments;
151 	/* following fields are for internal use */
152 	rsm_addr_t	attr_controller_addr;
153 } rsmka_int_controller_attr_t;
154 
155 #ifdef _SYSCALL32
156 typedef struct {
157 	/* following fields should be identical to rsmapi_controller_attr_t */
158 	uint32_t	attr_direct_access_sizes;
159 	uint32_t	attr_atomic_sizes;
160 	uint32_t	attr_page_size;
161 	uint32_t	attr_max_export_segment_size;
162 	uint32_t	attr_tot_export_segment_size;
163 	uint32_t	attr_max_export_segments;
164 	uint32_t	attr_max_import_map_size;
165 	uint32_t	attr_tot_import_map_size;
166 	uint32_t	attr_max_import_segments;
167 	/* the following fields are for internal use */
168 	rsm_addr_t	attr_controller_addr;
169 } rsmka_int_controller_attr32_t;
170 #endif
171 
172 /* kernel agent equivalents of rsm_iovec_t and rsm_scat_gath_t */
173 typedef struct {
174 	int					io_type;
175 	union {
176 		rsm_localmemory_handle_t	handle;
177 		rsm_memseg_id_t			segid;
178 		caddr_t				vaddr;
179 	} local;
180 	size_t					local_offset;
181 	size_t					remote_offset;
182 	size_t					transfer_len;
183 } rsmka_iovec_t;
184 
185 #ifdef _SYSCALL32
186 typedef struct {
187 	int32_t					io_type;
188 	uint32_t				local;
189 	uint32_t				local_offset;
190 	uint32_t				remote_offset;
191 	uint32_t				transfer_len;
192 } rsmka_iovec32_t;
193 #endif
194 
195 /*
196  * The following 2 structures represent the scatter-gather structures used
197  * within the kernel agent. Note that the io_residual_count and the flags fields
198  * fields must be contiguous within these structures due to this assumption
199  * made by the kernel agent when updating them in ddi_copyout.
200  */
201 typedef struct {
202 	rsm_node_id_t			local_nodeid;
203 	ulong_t				io_request_count;
204 	ulong_t				io_residual_count;
205 	uint_t				flags;
206 	rsm_memseg_import_handle_t	remote_handle;
207 	rsmka_iovec_t			*iovec;
208 } rsmka_scat_gath_t;
209 
210 #ifdef _SYSCALL32
211 typedef struct {
212 	rsm_node_id_t		local_nodeid;
213 	uint32_t		io_request_count;
214 	uint32_t		io_residual_count;
215 	uint32_t		flags;
216 	caddr32_t		remote_handle;
217 	caddr32_t		iovec;
218 } rsmka_scat_gath32_t;
219 #endif
220 
221 /*
222  * Define the number of pollfds upto which we don't allocate memory on heap
223  *
224  */
225 #define	RSM_MAX_POLLFDS	4
226 
227 typedef struct {
228 	minor_t		rnum;	/* segment's resource number */
229 	int		fdsidx; /* index of the fd in the pollfd array */
230 	int		revent; /* returned event */
231 } rsm_poll_event_t;
232 
233 #ifdef _SYSCALL32
234 typedef struct {
235 	minor_t		rnum;
236 	int32_t		fdsidx;
237 	int32_t		revent;
238 } rsm_poll_event32_t;
239 #endif
240 
241 typedef struct {
242 	caddr_t		seglist; /* array of rsm_poll_event_t */
243 	uint32_t	numents;
244 } rsm_consume_event_msg_t;
245 
246 #ifdef _SYSCALL32
247 typedef struct {
248 	caddr32_t	seglist; /* array of rsm_poll_event32_t */
249 	uint32_t	numents;
250 } rsm_consume_event_msg32_t;
251 #endif
252 
253 typedef struct {
254 	int			cnum;
255 	caddr_t			cname;
256 	int			cname_len;
257 	caddr_t			arg;
258 	int			len;	/* size as well */
259 	caddr_t			vaddr;
260 	int			off;
261 	rsm_memseg_id_t		key;
262 	int			acl_len;
263 	rsmapi_access_entry_t	*acl;
264 	rsm_node_id_t		nodeid;
265 	rsm_addr_t		hwaddr;
266 	rsm_permission_t	perm;
267 	rsm_barrier_t		bar;
268 	rsm_gnum_t		gnum; /* segment generation number */
269 	minor_t			rnum; /* segment resource number */
270 } rsm_ioctlmsg_t;
271 
272 #ifdef _SYSCALL32
273 typedef struct {
274 	int32_t			cnum;
275 	caddr32_t		cname;
276 	int32_t			cname_len;
277 	caddr32_t		arg;
278 	int32_t			len;	/* size as well */
279 	caddr32_t		vaddr;
280 	int32_t			off;
281 	rsm_memseg_id_t		key;
282 	int32_t			acl_len;
283 	caddr32_t		acl;
284 	rsm_node_id_t		nodeid;
285 	rsm_addr_t		hwaddr;
286 	rsm_permission_t	perm;
287 	rsm_barrier_t		bar;
288 	rsm_gnum_t		gnum; /* segment generation number */
289 	minor_t			rnum; /* segment resource number */
290 } rsm_ioctlmsg32_t;
291 #endif
292 
293 /*
294  * Remote messaging structures
295  */
296 
297 /* cookie to exchange between sender and receiver */
298 typedef union {
299 	struct {
300 		uint_t		index : 8;		/* slot number */
301 		uint_t		sequence : 24;		/* seq. number */
302 	} ic;
303 	uint_t			value;
304 }rsmipc_cookie_t;
305 
306 /*  IPC msg types */
307 #define	RSMIPC_MSG_SEGCONNECT	0	/* connect seg	    */
308 #define	RSMIPC_MSG_DISCONNECT	1	/* disconnect seg   */
309 #define	RSMIPC_MSG_IMPORTING	2
310 #define	RSMIPC_MSG_NOTIMPORTING	3
311 #define	RSMIPC_MSG_REPLY	4	/* reply msg	    */
312 #define	RSMIPC_MSG_BELL		5	/* post an event    */
313 #define	RSMIPC_MSG_REPUBLISH	6	/* seg republished  */
314 #define	RSMIPC_MSG_SUSPEND	7	/* tell importers to SUSPEND	*/
315 #define	RSMIPC_MSG_SUSPEND_DONE	8	/* tell exporters - SUSPEND done */
316 #define	RSMIPC_MSG_RESUME	9	/* tell importers to RESUME	*/
317 #define	RSMIPC_MSG_SQREADY	10	/* sendq ready = I am up	*/
318 #define	RSMIPC_MSG_SQREADY_ACK	11	/* sendq ready ack = I am up too */
319 #define	RSMIPC_MSG_CREDIT	12	/* credits to sender	*/
320 
321 /*
322  * Dummy message header
323  */
324 typedef struct rsmipc_msg {
325 	int		rsmipc_version;
326 	rsm_node_id_t	rsmipc_src;
327 	int		rsmipc_type;
328 	rsmipc_cookie_t	rsmipc_cookie;
329 	int64_t		rsmipc_incn;
330 }rsmipc_msghdr_t;
331 
332 
333 #define	RSM_NO_REPLY	0	/* for rsmipc_send when no reply is expected */
334 
335 /*
336  * Request message of connect operation
337  */
338 typedef struct rsmipc_request {
339 	rsmipc_msghdr_t		rsmipc_hdr;
340 	rsm_memseg_id_t		rsmipc_key;	/* user key or segid */
341 	rsm_permission_t	rsmipc_perm;
342 	rsm_addr_t		rsmipc_adapter_hwaddr;
343 	void			*rsmipc_segment_cookie;
344 }rsmipc_request_t;
345 
346 /*
347  * Message format of the flow control messages
348  */
349 typedef struct rsmipc_controlmsg {
350 	rsmipc_msghdr_t		rsmipc_hdr;
351 	int64_t			rsmipc_local_incn;
352 	rsm_addr_t		rsmipc_adapter_hwaddr;
353 	int32_t			rsmipc_credits;	/* credits */
354 }rsmipc_controlmsg_t;
355 
356 /*
357  * Reply message for connect operation
358  */
359 typedef struct rsmipc_reply {
360 	rsmipc_msghdr_t	rsmipc_hdr;
361 	short		rsmipc_status;	/* error code of remote call */
362 	uint16_t	rsmipc_cnum;	/* exported controller addr */
363 	rsm_memseg_id_t	rsmipc_segid;	/* segid from remote node */
364 	size_t		rsmipc_seglen;	/* exporter segment size */
365 	mode_t		rsmipc_mode;
366 	uid_t		rsmipc_uid;
367 	gid_t		rsmipc_gid;
368 }rsmipc_reply_t;
369 
370 #ifdef	__cplusplus
371 }
372 #endif
373 
374 
375 #endif	/* _SYS_RSM_RSM_H */
376