8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / librsm / inc / rsmndi.h
blob328a94cf6805b9e0ae2d81dbb485727d4476e4f6
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _SYS_RSM_RSMNDI_H
28 #define _SYS_RSM_RSMNDI_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
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>
46 * This structure defines the functions implemented in rsmlib
47 * that the NDI library can call.
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;
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;
68 /* The opaque barrier handle used by the RSMNDI plugin for the barrier calls */
69 typedef struct rsm_barrier *rsm_barrier_handle_t;
71 typedef struct {
74 * structure revision number:
76 int rsm_version;
79 * import side memory segment operations
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);
91 * import side memory segment operations (read access functions):
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);
124 * import side memory segment operations (read access functions):
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);
157 * import side memory segment operations (barriers):
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);
164 int (* rsm_memseg_import_open_barrier)(rsm_barrier_handle_t barrier);
166 int (* rsm_memseg_import_order_barrier)(rsm_barrier_handle_t barrier);
168 int (* rsm_memseg_import_close_barrier)(rsm_barrier_handle_t barrier);
170 int (* rsm_memseg_import_destroy_barrier)(rsm_barrier_handle_t barrier);
172 int (* rsm_memseg_import_get_mode)
173 (rsm_memseg_import_handle_t im_memseg,
174 rsm_barrier_mode_t *mode);
176 int (* rsm_memseg_import_set_mode)
177 (rsm_memseg_import_handle_t im_memseg,
178 rsm_barrier_mode_t mode);
182 * import side memory segment data transfer operations.
184 int (* rsm_memseg_import_putv)(rsm_scat_gath_t *sg_io);
185 int (* rsm_memseg_import_getv)(rsm_scat_gath_t *sg_io);
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);
192 int (* rsm_free_localmemory_handle)
193 (rsm_localmemory_handle_t local_handle);
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;
203 #define RSM_LIB_VERSION 1
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;
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;
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;
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;
273 * defines for rsmseg_flags
275 #define RSM_IMPLICIT_MAP 0x00000001 /* segment mapped implicitly */
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;
285 * These macros set and get the private data pointer in the opaque barrier
286 * structure for Network plugins.
288 #define RSMNDI_BARRIER_SETPRIV(HANDLE, ADDR) \
289 ((rsmbar_handle_t *)HANDLE)->rsmbar_privdata = (void *)ADDR;
291 #define RSMNDI_BARRIER_GETPRIV(HANDLE) \
292 ((rsmbar_handle_t *)HANDLE)->rsmbar_privdata
294 #define RSMNDI_BARRIER_GETSEG(HANDLE) \
295 ((rsmbar_handle_t *)HANDLE)->rsmbar_seg
297 #define RSMNDI_BARRIER_GETUNIT(HANDLE) \
298 ((rsmbar_handle_t *)HANDLE)->rsmbar_seg->rsmseg_controller->cntr_unit
301 * These macros set and get the private data pointer in the opaque segment
302 * structure for Network plugins.
304 #define RSMNDI_SEG_SETPRIV(HANDLE, ADDR) \
305 ((rsmseg_handle_t *)HANDLE)->rsmseg_privdata = (void *)ADDR;
307 #define RSMNDI_SEG_GETPRIV(HANDLE) \
308 ((rsmseg_handle_t *)HANDLE)->rsmseg_privdata
311 * Get the controller unit number from a opaque segment structure.
314 #define RSMNDI_SEG_GETUNIT(HANDLE) \
315 ((rsmseg_handle_t *)HANDLE)->rsmseg_controller->cntr_unit
318 * These macros set and get the private data pointer in the opaque controller
319 * structure for Network plugins.
321 #define RSMNDI_CNTRLR_SETPRIV(HANDLE, ADDR) \
322 ((rsm_controller_t *)HANDLE)->cntr_privdata = (void *)ADDR;
324 #define RSMNDI_CNTRLR_GETPRIV(HANDLE) \
325 ((rsm_controller_t *)HANDLE)->cntr_privdata
328 * Get the controller unit number from a opaque controller structure.
330 #define RSMNDI_CNTRLR_GETUNIT(HANDLE) \
331 ((rsm_controller_t *)HANDLE)->cntr_unit
334 * This macro returns an address inside a segment given the segment handle
335 * and a byte offset.
337 #define RSMNDI_GET_MAPADDR(HANDLE, OFFSET) \
338 (((rsmseg_handle_t *)HANDLE)->rsmseg_vaddr + OFFSET)
340 #ifdef __cplusplus
342 #endif
344 #endif /* _SYS_RSM_RSMNDI_H */