xref: /titanic_52/usr/src/lib/librsm/inc/rsmndi.h (revision 0eb822a1c0c2bea495647510b75f77f0e57633eb)
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 2001-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_RSM_RSMNDI_H
28 #define	_SYS_RSM_RSMNDI_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/mman.h>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include <thread.h>
41 #include <synch.h>
42 #include <sys/rsm/rsm_common.h>
43 #include <sys/rsm/rsmapi_common.h>
44 
45 /*
46  * This structure defines the functions implemented in rsmlib
47  * that the NDI library can call.
48  */
49 typedef struct {
50 	int	version;
51 #define	RSM_LIB_FUNCS_VERSION	1
52 	int	(* rsm_get_hwaddr)(
53 	    rsmapi_controller_handle_t handle,
54 	    rsm_node_id_t nodeid,
55 	    rsm_addr_t *hwaddrp);
56 	int	(* rsm_get_nodeid)(
57 	    rsmapi_controller_handle_t handle,
58 	    rsm_addr_t hwaddr,
59 	    rsm_node_id_t *nodeidp);
60 } rsm_lib_funcs_t;
61 
62 /* Library attributes - set by specific NDI libraries */
63 typedef struct {
64 	boolean_t	rsm_putget_map_reqd;	/* put/get require mapping */
65 	boolean_t	rsm_scatgath_map_reqd;	/* putv/getv require mapping */
66 } rsm_ndlib_attr_t;
67 
68 /* The opaque barrier handle used by the RSMNDI plugin for the barrier calls */
69 typedef struct rsm_barrier *rsm_barrier_handle_t;
70 
71 typedef struct {
72 
73 	/*
74 	 * structure revision number:
75 	 */
76 	int rsm_version;
77 
78 	/*
79 	 * import side memory segment operations
80 	 */
81 	int (* rsm_memseg_import_connect)
82 	    (rsmapi_controller_handle_t controller,
83 	    rsm_node_id_t node_id,
84 	    rsm_memseg_id_t segment_id,
85 	    rsm_permission_t perm,
86 	    rsm_memseg_import_handle_t *im_memseg);
87 	int (* rsm_memseg_import_disconnect)
88 	    (rsm_memseg_import_handle_t im_memseg);
89 
90 	/*
91 	 * import side memory segment operations (read access functions):
92 	 */
93 	int (* rsm_memseg_import_get8)
94 	    (rsm_memseg_import_handle_t im_memseg,
95 	    off_t offset,
96 	    uint8_t *datap,
97 	    ulong_t rep_cnt,
98 	    boolean_t swap);
99 	int (* rsm_memseg_import_get16)
100 	    (rsm_memseg_import_handle_t im_memseg,
101 	    off_t offset,
102 	    uint16_t *datap,
103 	    ulong_t rep_cnt,
104 	    boolean_t swap);
105 	int (* rsm_memseg_import_get32)
106 	    (rsm_memseg_import_handle_t im_memseg,
107 	    off_t offset,
108 	    uint32_t *datap,
109 	    ulong_t rep_cnt,
110 	    boolean_t swap);
111 	int (* rsm_memseg_import_get64)
112 	    (rsm_memseg_import_handle_t im_memseg,
113 	    off_t offset,
114 	    uint64_t *datap,
115 	    ulong_t rep_cnt,
116 	    boolean_t swap);
117 	int (* rsm_memseg_import_get)
118 	    (rsm_memseg_import_handle_t im_memseg,
119 	    off_t offset,
120 	    void *dst_addr,
121 	    size_t length);
122 
123 	/*
124 	 * import side memory segment operations (read access functions):
125 	 */
126 	int (* rsm_memseg_import_put8)
127 	    (rsm_memseg_import_handle_t im_memseg,
128 	    off_t offset,
129 	    uint8_t *datap,
130 	    ulong_t rep_cnt,
131 	    boolean_t swap);
132 	int (* rsm_memseg_import_put16)
133 	    (rsm_memseg_import_handle_t im_memseg,
134 	    off_t offset,
135 	    uint16_t *datap,
136 	    ulong_t rep_cnt,
137 	    boolean_t swap);
138 	int (* rsm_memseg_import_put32)
139 	    (rsm_memseg_import_handle_t im_memseg,
140 	    off_t offset,
141 	    uint32_t *datap,
142 	    ulong_t rep_cnt,
143 	    boolean_t swap);
144 	int (* rsm_memseg_import_put64)
145 	    (rsm_memseg_import_handle_t im_memseg,
146 	    off_t offset,
147 	    uint64_t *datap,
148 	    ulong_t rep_cnt,
149 	    boolean_t swap);
150 	int (* rsm_memseg_import_put)
151 	    (rsm_memseg_import_handle_t im_memseg,
152 	    off_t offset,
153 	    void *src_addr,
154 	    size_t length);
155 
156 	/*
157 	 * import side memory segment operations (barriers):
158 	 */
159 	int (* rsm_memseg_import_init_barrier)
160 	    (rsm_memseg_import_handle_t im_memseg,
161 	    rsm_barrier_type_t type,
162 	    rsm_barrier_handle_t barrier);
163 
164 	int (* rsm_memseg_import_open_barrier)(rsm_barrier_handle_t barrier);
165 
166 	int (* rsm_memseg_import_order_barrier)(rsm_barrier_handle_t barrier);
167 
168 	int (* rsm_memseg_import_close_barrier)(rsm_barrier_handle_t barrier);
169 
170 	int (* rsm_memseg_import_destroy_barrier)(rsm_barrier_handle_t barrier);
171 
172 	int (* rsm_memseg_import_get_mode)
173 	    (rsm_memseg_import_handle_t im_memseg,
174 	    rsm_barrier_mode_t *mode);
175 
176 	int (* rsm_memseg_import_set_mode)
177 	    (rsm_memseg_import_handle_t im_memseg,
178 	    rsm_barrier_mode_t mode);
179 
180 
181 	/*
182 	 * import side memory segment data transfer operations.
183 	 */
184 	int (* rsm_memseg_import_putv)(rsm_scat_gath_t *sg_io);
185 	int (* rsm_memseg_import_getv)(rsm_scat_gath_t *sg_io);
186 
187 	int (* rsm_create_localmemory_handle)
188 	    (rsmapi_controller_handle_t controller,
189 	    rsm_localmemory_handle_t *local_handle_p,
190 	    caddr_t local_vaddr, size_t len);
191 
192 	int (* rsm_free_localmemory_handle)
193 	    (rsm_localmemory_handle_t local_handle);
194 
195 	int (* rsm_register_lib_funcs)
196 	    (rsm_lib_funcs_t *libfuncs);
197 	int (* rsm_get_lib_attr)
198 	    (rsm_ndlib_attr_t **libattr);
199 	int (* rsm_closedevice)
200 	    (rsmapi_controller_handle_t controller);
201 } rsm_segops_t;
202 
203 #define	RSM_LIB_VERSION	1
204 
205 /* library internal controller attribute structure */
206 typedef struct {
207 	/* following fields should be identical to rsmapi_controller_attr_t */
208 	uint_t		attr_direct_access_sizes;
209 	uint_t		attr_atomic_sizes;
210 	size_t		attr_page_size;
211 	size_t		attr_max_export_segment_size;
212 	size_t		attr_tot_export_segment_size;
213 	ulong_t		attr_max_export_segments;
214 	size_t		attr_max_import_map_size;
215 	size_t		attr_tot_import_map_size;
216 	ulong_t		attr_max_import_segments;
217 	/* following fields are for internal use */
218 	rsm_addr_t	attr_controller_addr;
219 } rsm_int_controller_attr_t;
220 
221 typedef struct rsm_controller {
222 	void			*cntr_privdata;
223 	struct rsm_controller	*cntr_next;
224 	int			cntr_fd;
225 	int			cntr_refcnt;
226 	int			cntr_unit;
227 	char			*cntr_name;	/* generic type eg. sci   */
228 	rsm_segops_t		*cntr_segops;
229 	struct rsmqueue		*cntr_rqlist;	/* list of receive queues */
230 	rsm_int_controller_attr_t	cntr_attr;
231 	rsm_ndlib_attr_t	*cntr_lib_attr;
232 	mutex_t			cntr_lock;
233 	cond_t			cntr_cv;
234 } rsm_controller_t;
235 
236 
237 typedef enum {
238 	EXPORT_CREATE = 0x1,
239 	EXPORT_BIND,
240 	EXPORT_PUBLISH,
241 	IMPORT_CONNECT,
242 	IMPORT_DISCONNECT,
243 	IMPORT_MAP,
244 	IMPORT_UNMAP
245 } rsm_seg_state_t;
246 
247 typedef struct {
248 	void		*rsmseg_privdata;
249 	rsm_segops_t	*rsmseg_ops;
250 	rsm_seg_state_t	rsmseg_state;
251 	caddr_t		rsmseg_vaddr;	/* base address of segment */
252 	size_t		rsmseg_size;	/* size of segment */
253 	size_t		rsmseg_maplen;	/* length of mapped region */
254 	rsm_node_id_t	rsmseg_nodeid;
255 	rsm_memseg_id_t	rsmseg_keyid;
256 	int		rsmseg_fd;
257 	int		rsmseg_pollfd_refcnt;
258 	rsm_permission_t rsmseg_perm;
259 	rsm_controller_t *rsmseg_controller;
260 	rsm_barrier_mode_t rsmseg_barmode;
261 	void		*rsmseg_data;
262 	uint16_t	*rsmseg_bar;
263 	uint16_t	rsmseg_gnum;	/* generation number */
264 	int		rsmseg_type;
265 	mutex_t		rsmseg_lock;
266 	rsmapi_barrier_t	*rsmseg_barrier; /* used in put/get routines */
267 	offset_t	rsmseg_mapoffset; /* seg offset where mmapped */
268 	uint32_t	rsmseg_flags;
269 	minor_t		rsmseg_rnum; /* resource number of the segment */
270 } rsmseg_handle_t;
271 
272 /*
273  * defines for rsmseg_flags
274  */
275 #define	RSM_IMPLICIT_MAP	0x00000001	/* segment mapped implicitly */
276 
277 /* This is a template for all barrier implementations */
278 typedef struct {
279 	rsmseg_handle_t	*rsmbar_seg;
280 	uint16_t	rsmbar_gen; /* generation number */
281 	void		*rsmbar_privdata;
282 } rsmbar_handle_t;
283 
284 /*
285  * These macros set and get the private data pointer in the opaque barrier
286  * structure for Network plugins.
287  */
288 #define	RSMNDI_BARRIER_SETPRIV(HANDLE, ADDR) \
289 		((rsmbar_handle_t *)HANDLE)->rsmbar_privdata = (void *)ADDR;
290 
291 #define	RSMNDI_BARRIER_GETPRIV(HANDLE) \
292 		((rsmbar_handle_t *)HANDLE)->rsmbar_privdata
293 
294 #define	RSMNDI_BARRIER_GETSEG(HANDLE)	\
295 		((rsmbar_handle_t *)HANDLE)->rsmbar_seg
296 
297 #define	RSMNDI_BARRIER_GETUNIT(HANDLE)	\
298 	((rsmbar_handle_t *)HANDLE)->rsmbar_seg->rsmseg_controller->cntr_unit
299 
300 /*
301  * These macros set and get the private data pointer in the opaque segment
302  * structure for Network plugins.
303  */
304 #define	RSMNDI_SEG_SETPRIV(HANDLE, ADDR) \
305 		((rsmseg_handle_t *)HANDLE)->rsmseg_privdata = (void *)ADDR;
306 
307 #define	RSMNDI_SEG_GETPRIV(HANDLE) \
308 		((rsmseg_handle_t *)HANDLE)->rsmseg_privdata
309 
310 /*
311  * Get the controller unit number from a opaque segment structure.
312  */
313 
314 #define	RSMNDI_SEG_GETUNIT(HANDLE) \
315 		((rsmseg_handle_t *)HANDLE)->rsmseg_controller->cntr_unit
316 
317 /*
318  * These macros set and get the private data pointer in the opaque controller
319  * structure for Network plugins.
320  */
321 #define	RSMNDI_CNTRLR_SETPRIV(HANDLE, ADDR) \
322 		((rsm_controller_t *)HANDLE)->cntr_privdata = (void *)ADDR;
323 
324 #define	RSMNDI_CNTRLR_GETPRIV(HANDLE) \
325 		((rsm_controller_t *)HANDLE)->cntr_privdata
326 
327 /*
328  * Get the controller unit number from a opaque controller structure.
329  */
330 #define	RSMNDI_CNTRLR_GETUNIT(HANDLE) \
331 		((rsm_controller_t *)HANDLE)->cntr_unit
332 
333 /*
334  * This macro returns an address inside a segment given the segment handle
335  * and a byte offset.
336  */
337 #define	RSMNDI_GET_MAPADDR(HANDLE, OFFSET) \
338 		(((rsmseg_handle_t *)HANDLE)->rsmseg_vaddr + OFFSET)
339 
340 #ifdef	__cplusplus
341 }
342 #endif
343 
344 #endif	/* _SYS_RSM_RSMNDI_H */
345