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