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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_NSCTL_H 27 #define _SYS_NSCTL_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #if (defined(lint) || defined(OSDEBUG)) && defined(_KERNEL) 34 #define __NSC_GEN__ 35 #include <sys/ksynch.h> 36 #include <sys/nsctl/nsc_dev.h> 37 #include <sys/nsctl/nsc_gen.h> 38 #include <sys/nsctl/nsc_mem.h> 39 #include <sys/nsctl/nsc_rmspin.h> 40 #endif 41 42 43 /* 44 * nsctl multi-terabyte volume support 45 * 46 * To build a multi-terabyte stack, '#define NSC_MULTI_TERABYTE'. 47 */ 48 49 #ifdef NSC_MULTI_TERABYTE 50 typedef uint64_t nsc_off_t; /* positions, offsets */ 51 typedef uint64_t nsc_size_t; /* lengths, sizes */ 52 #ifdef _LP64 53 #define NSC_SZFMT "lu" 54 #define NSC_XSZFMT "lx" 55 #else 56 #define NSC_SZFMT "llu" 57 #define NSC_XSZFMT "llx" 58 #endif 59 60 #else /* max 1TB volume size */ 61 typedef int nsc_off_t; 62 typedef int nsc_size_t; 63 #define NSC_SZFMT "u" 64 #define NSC_XSZFMT "x" 65 #endif 66 67 68 #ifdef _KERNEL 69 70 #ifdef sun 71 #include <sys/nsc_ddi.h> 72 #endif 73 74 /* 75 * Generic parameter definition. 76 */ 77 78 typedef struct nsc_def_s { 79 char *name; /* Parameter name */ 80 uintptr_t value; /* Parameter value */ 81 int offset; /* Structure offset */ 82 } nsc_def_t; 83 84 extern int nsc_inval(), nsc_ioerr(); 85 extern int nsc_fatal(), nsc_null(), nsc_true(); 86 extern void nsc_decode_param(nsc_def_t *, nsc_def_t *, long *); 87 #endif /* _KERNEL */ 88 89 90 /* ID and Type flags */ 91 92 #define NSC_ID 0x40000000 /* Module ID */ 93 #define NSC_NULL 0x00000100 /* No I/O possible */ 94 #define NSC_DEVICE 0x00000200 /* Device interface */ 95 #define NSC_FILE 0x00000400 /* File vnode interface */ 96 #define NSC_CACHE 0x00000800 /* Cache interface */ 97 #define NSC_ANON 0x00001000 /* Supports anonymous buffers */ 98 #define NSC_VCHR 0x00002000 /* VCHR vnode device */ 99 #define NSC_NCALL 0x00004000 /* ncall-io interface */ 100 101 #define NSC_IDS 0x7ff00000 /* ID mask */ 102 #define NSC_TYPES 0x7fffff00 /* Type mask */ 103 104 #define NSC_MKID(x) (NSC_ID | ((x) << 20)) 105 106 #define NSC_RAW_ID NSC_MKID(39) /* Raw device */ 107 #define NSC_FILE_ID NSC_MKID(40) /* File vnode device */ 108 #define NSC_FREEZE_ID NSC_MKID(41) /* Frozen raw device */ 109 #define NSC_VCHR_ID NSC_MKID(42) /* VCHR vnode device */ 110 #define NSC_NCALL_ID NSC_MKID(43) /* ncall-io */ 111 #define NSC_SDBC_ID NSC_MKID(80) /* Block based cache */ 112 #define NSC_RDCLR_ID NSC_MKID(94) /* RDC (low, raw) */ 113 #define NSC_RDCL_ID NSC_MKID(95) /* RDC (low, cache) */ 114 #define NSC_IIR_ID NSC_MKID(96) /* Instant Image (raw) */ 115 #define NSC_II_ID NSC_MKID(98) /* Instant Image */ 116 #define NSC_RDCHR_ID NSC_MKID(99) /* RDC (high, raw) */ 117 #define NSC_RDCH_ID NSC_MKID(100) /* RDC (high, cache) */ 118 119 typedef enum nsc_power_ops_e { 120 Power_Lost, /* Power Failing initial warning */ 121 /* with timeleft (rideout) minutes */ 122 123 Power_OK, /* Power OK or restored before death */ 124 125 Power_Down /* that's all folks machine will */ 126 /* be shutdown, save any state */ 127 } nsc_power_ops_t; 128 129 #ifdef _KERNEL 130 131 /* Module Flags */ 132 133 #define NSC_REFCNT 0x00000001 /* Counts references */ 134 #define NSC_FILTER 0x00000002 /* Uses lower level driver */ 135 136 137 #ifndef _NSC_DEV_H 138 typedef struct nsc_io_s { int x; } nsc_io_t; 139 typedef struct nsc_path_s { int x; } nsc_path_t; 140 #endif 141 142 extern nsc_io_t *nsc_register_io(char *, int, nsc_def_t *); 143 extern int nsc_unregister_io(nsc_io_t *, int); 144 extern nsc_path_t *nsc_register_path(char *, int, nsc_io_t *); 145 extern int nsc_unregister_path(nsc_path_t *, int); 146 extern int nsc_cache_sizes(int *, int *); 147 extern int nsc_node_hints(unsigned int *); 148 extern int nsc_node_hints_set(unsigned int); 149 extern blind_t nsc_register_power(char *, nsc_def_t *); 150 extern int nsc_unregister_power(blind_t); 151 152 /* 153 * Strategy function interface 154 */ 155 #ifndef DS_DDICT 156 typedef int (*strategy_fn_t)(struct buf *); 157 #endif 158 extern strategy_fn_t nsc_get_strategy(major_t); 159 160 extern void *nsc_get_devops(major_t); 161 162 #endif /* _KERNEL */ 163 164 165 /* Block sizes */ 166 167 #define FBA_SHFT 9 168 #define FBA_MASK 0x1ff 169 #define FBA_SIZE(x) ((x) << FBA_SHFT) /* fba to bytes */ 170 #define FBA_OFF(x) ((x) & FBA_MASK) /* byte offset */ 171 #define FBA_LEN(x) FBA_NUM((x) + FBA_MASK) /* len to fba */ 172 #define FBA_NUM(x) ((nsc_size_t)((uint64_t)(x) >> FBA_SHFT)) 173 /* bytes to fba */ 174 175 176 /* Return values */ 177 178 #define NSC_DONE (0) 179 #define NSC_PENDING (-1) 180 #define NSC_HIT (-2) 181 182 183 #if defined(_KERNEL) || defined(_KMEMUSER) 184 185 /* 186 * External file descriptor. 187 */ 188 189 #ifndef _NSC_DEV_H 190 typedef struct nsc_fd_s { int x; } nsc_fd_t; 191 #endif 192 193 #endif /* _KERNEL || _KMEMUSER */ 194 195 196 #ifdef _KERNEL 197 198 #define NSC_TRY (1<<24) /* Conditional operation */ 199 #define NSC_PCATCH (1<<25) /* Catch signals */ 200 #define NSC_DEFER (1<<26) /* Defer if busy */ 201 #define NSC_MULTI (1<<27) /* Multiple reserves */ 202 #define NSC_NOWAIT (1<<28) /* Don't wait if busy */ 203 204 extern nsc_fd_t *nsc_open(char *, int, nsc_def_t *, blind_t, int *); 205 extern int nsc_close(nsc_fd_t *); 206 extern char *nsc_pathname(nsc_fd_t *); 207 extern int nsc_fdpathcmp(nsc_fd_t *, uint64_t, char *); 208 extern int nsc_shared(nsc_fd_t *); 209 extern int nsc_setval(nsc_fd_t *, char *, int); 210 extern int nsc_getval(nsc_fd_t *, char *, int *); 211 extern int nsc_set_trksize(nsc_fd_t *, nsc_size_t); 212 extern int nsc_discard_pinned(nsc_fd_t *, nsc_off_t, nsc_size_t); 213 extern kmutex_t *nsc_lock_addr(nsc_fd_t *); 214 extern int nsc_attach(nsc_fd_t *, int); 215 extern int nsc_reserve(nsc_fd_t *, int); 216 extern void nsc_reserve_lk(nsc_fd_t *); 217 extern void nsc_release(nsc_fd_t *); 218 extern int nsc_release_lk(nsc_fd_t *); 219 extern int nsc_detach(nsc_fd_t *, int); 220 extern int nsc_avail(nsc_fd_t *); 221 extern int nsc_held(nsc_fd_t *); 222 extern int nsc_waiting(nsc_fd_t *); 223 extern int nsc_partsize(nsc_fd_t *, nsc_size_t *); 224 extern int nsc_maxfbas(nsc_fd_t *, int, nsc_size_t *); 225 extern int nsc_get_pinned(nsc_fd_t *); 226 extern int nsc_max_devices(void); 227 extern int nsc_control(nsc_fd_t *, int, void *, int); 228 229 #endif /* _KERNEL */ 230 231 232 #if defined(_KERNEL) || defined(_KMEMUSER) 233 234 /* 235 * I/O device structure. 236 */ 237 238 #ifndef _NSC_DEV_H 239 typedef struct nsc_iodev_s { int x; } nsc_iodev_t; 240 #endif 241 242 #ifdef _KERNEL 243 extern void nsc_set_owner(nsc_fd_t *, nsc_iodev_t *); 244 extern void nsc_pinned_data(nsc_iodev_t *, nsc_off_t, nsc_size_t); 245 extern void nsc_unpinned_data(nsc_iodev_t *, nsc_off_t, nsc_size_t); 246 #endif 247 248 249 /* 250 * Data structures used by I/O interface. 251 */ 252 253 typedef struct nsc_vec_s { /* Scatter gather element */ 254 unsigned char *sv_addr; /* Virtual address of data */ 255 unsigned long sv_vme; /* VME address of data */ 256 int sv_len; /* Data length in bytes */ 257 } nsc_vec_t; 258 259 260 typedef struct nsc_buf_s { /* Buffer structure */ 261 nsc_fd_t *sb_fd; /* File descriptor */ 262 nsc_off_t sb_pos; /* Block offset of data */ 263 nsc_size_t sb_len; /* Length of data in blocks */ 264 volatile int sb_flag; /* Buffer flags */ 265 int sb_error; /* Error code */ 266 uintptr_t sb_user; /* User definable */ 267 nsc_vec_t *sb_vec; /* Scatter gather list */ 268 } nsc_buf_t; 269 270 #endif /* _KERNEL || _KMEMUSER */ 271 272 273 /* Allocate flags */ 274 275 #define NSC_RDBUF 0x0001 276 #define NSC_WRBUF 0x0002 277 #define NSC_PINNABLE 0x0004 278 #define NSC_NOBLOCK 0x0008 279 280 #define NSC_READ (NSC_RDBUF) 281 #define NSC_WRITE (NSC_WRBUF) 282 #define NSC_RDWR (NSC_RDBUF | NSC_WRBUF) 283 #define NSC_RDWRBUF (NSC_RDBUF | NSC_WRBUF) 284 285 286 /* Other flags */ 287 288 #define NSC_CACHEBLK 0x0008 /* nsc_maxfbas: size of cache block in fbas */ 289 #define NSC_HALLOCATED 0x0010 /* handle allocated (IO provider internals) */ 290 #define NSC_HACTIVE 0x0020 /* handle active (IO provider internals) */ 291 #define NSC_BCOPY 0x0040 /* bcopy, don't DMA when moving data */ 292 #define NSC_PAGEIO 0x0080 /* client will use handle for pageio */ 293 #define NSC_ABUF 0x0100 /* anonymous buffer handle */ 294 #define NSC_MIXED 0x0200 /* data from 2 devs is mixed in this buffer */ 295 #define NSC_NODATA 0x0400 /* allocate without data buffer (sb_vec) */ 296 297 298 #define NSC_FLAGS 0xffff 299 300 #ifdef _KERNEL 301 302 #define NSC_ANON_CD ((blind_t)(-1)) /* used for IO provider alloc buf */ 303 304 extern int nsc_alloc_buf(nsc_fd_t *, nsc_off_t, nsc_size_t, int, nsc_buf_t **); 305 extern int nsc_alloc_abuf(nsc_off_t, nsc_size_t, int, nsc_buf_t **); 306 extern int nsc_read(nsc_buf_t *, nsc_off_t, nsc_size_t, int); 307 extern int nsc_write(nsc_buf_t *, nsc_off_t, nsc_size_t, int); 308 extern int nsc_zero(nsc_buf_t *, nsc_off_t, nsc_size_t, int); 309 extern int nsc_copy(nsc_buf_t *, nsc_buf_t *, nsc_off_t, nsc_off_t, nsc_size_t); 310 extern int nsc_copy_direct(nsc_buf_t *, nsc_buf_t *, nsc_off_t, 311 nsc_off_t, nsc_size_t); 312 extern int nsc_uncommit(nsc_buf_t *, nsc_off_t, nsc_size_t, int); 313 extern int nsc_free_buf(nsc_buf_t *); 314 extern nsc_buf_t *nsc_alloc_handle(nsc_fd_t *, 315 void (*)(), void (*)(), void (*)()); 316 extern int nsc_free_handle(nsc_buf_t *); 317 extern int nsc_uread(nsc_fd_t *, void *, void *); 318 extern int nsc_uwrite(nsc_fd_t *, void *, void *); 319 320 #endif /* _KERNEL */ 321 322 323 /* 324 * Performance hints. 325 */ 326 327 #define NSC_WRTHRU 0x00010000 328 #define NSC_FORCED_WRTHRU 0x00020000 329 #define NSC_NOCACHE 0x00040000 330 #define NSC_QUEUE 0x00080000 331 #define NSC_RDAHEAD 0x00100000 332 #define NSC_NO_FORCED_WRTHRU 0x00200000 333 #define NSC_METADATA 0x00400000 334 #define NSC_SEQ_IO 0x00800000 335 336 #define NSC_HINTS 0x00ff0000 337 338 339 #ifdef _KERNEL 340 /* 341 * node hint actions 342 */ 343 344 #define NSC_GET_NODE_HINT 0 345 #define NSC_SET_NODE_HINT 1 346 #define NSC_CLEAR_NODE_HINT 2 347 348 /* 349 * Reflective memory spinlocks. 350 */ 351 352 353 #ifndef _NSC_RMSPIN_H 354 typedef struct nsc_rmlock_s { int x; } nsc_rmlock_t; 355 #endif 356 357 358 extern nsc_rmlock_t *nsc_rm_lock_alloc(char *, int, void *); 359 extern void nsc_rm_lock_dealloc(nsc_rmlock_t *); 360 extern int nsc_rm_lock(nsc_rmlock_t *); 361 extern void nsc_rm_unlock(nsc_rmlock_t *); 362 363 #endif /* _KERNEL */ 364 365 366 /* 367 * Memory allocation routines. 368 */ 369 370 #define NSC_MEM_LOCAL 0x1 371 #define NSC_MEM_GLOBAL 0x4 372 373 #define NSC_MEM_RESIZE 0x100 374 #define NSC_MEM_NVDIRTY 0x400 375 376 377 #ifdef _KERNEL 378 379 #ifndef _NSC_MEM_H 380 typedef struct nsc_mem_s { int x; } nsc_mem_t; 381 #endif 382 383 384 extern nsc_mem_t *nsc_register_mem(char *, int, int); 385 extern void nsc_unregister_mem(nsc_mem_t *); 386 extern void *nsc_kmem_alloc(size_t, int, nsc_mem_t *); 387 extern void *nsc_kmem_zalloc(size_t, int, nsc_mem_t *); 388 extern void nsc_kmem_free(void *, size_t); 389 extern void nsc_mem_sizes(nsc_mem_t *, size_t *, size_t *, size_t *); 390 extern size_t nsc_mem_avail(nsc_mem_t *); 391 392 /* nvmem suppport */ 393 typedef void (*nsc_mem_err_cb) (void *, void *, size_t, int); 394 extern int nsc_commit_mem(void *, void *, size_t, nsc_mem_err_cb); 395 396 extern void nsc_cm_errhdlr(void *, void *, size_t, int); 397 398 #endif /* _KERNEL */ 399 400 401 /* 402 * Max pathname 403 * Note: Currently defined both here and in nsc_dev.h 404 */ 405 #if !defined(NSC_MAXPATH) 406 #define NSC_MAXPATH 64 407 #endif 408 409 #ifdef _KERNEL 410 411 /* 412 * Inter-module function (callback) services 413 */ 414 415 #ifndef _NSC_GEN_H 416 typedef struct nsc_svc_s { int x; } nsc_svc_t; 417 #endif 418 419 extern nsc_svc_t *nsc_register_svc(char *, void (*)(intptr_t)); 420 extern int nsc_unregister_svc(nsc_svc_t *); 421 extern int nsc_call_svc(nsc_svc_t *, intptr_t); 422 423 424 /* 425 * String manipulation functions. 426 */ 427 428 #ifndef sun 429 #define sprintf nsc_sprintf 430 #endif /* sun */ 431 432 extern char *nsc_strdup(char *); 433 extern void nsc_strfree(char *); 434 extern int nsc_strmatch(char *, char *); 435 extern void nsc_sprintf(char *, char *, ...); 436 extern uint64_t nsc_strhash(char *); 437 438 439 /* 440 * Macro definitions. 441 */ 442 443 #define NSC_HIER 1 444 445 #ifndef NULL 446 #define NULL 0 447 #endif 448 449 450 /* 451 * External definitions. 452 */ 453 454 #undef HZ 455 extern clock_t HZ; 456 extern int nsc_max_nodeid, nsc_min_nodeid; 457 458 extern int nsc_node_id(void); 459 extern char *nsc_node_name(void); 460 extern int nsc_node_up(int); 461 extern time_t nsc_time(void); 462 extern clock_t nsc_lbolt(void); 463 extern int nsc_delay_sig(clock_t); 464 extern clock_t nsc_usec(void); 465 extern void nsc_yield(void); 466 467 extern void nsc_membar_stld(void); 468 extern uint8_t nsc_ldstub(uint8_t *); 469 extern caddr_t nsc_caller(void); 470 extern caddr_t nsc_callee(void); 471 472 extern int nsc_create_process(void (*)(void *), void *, boolean_t); 473 474 extern int nsc_power_init(void); 475 extern void nsc_power_deinit(void); 476 extern int nsc_nodeid_data(void); 477 478 #define NSC_ALERT_INFO 0 /* Information alert */ 479 #define NSC_ALERT_WARNING 1 /* Warning alert */ 480 #define NSC_ALERT_ERROR 2 /* Error alert */ 481 #define NSC_ALERT_DOWN 3 /* System or Module down */ 482 483 extern void nsc_do_sysevent(char *, char *, int, int, char *, dev_info_t *); 484 485 486 /* 487 * Missing DDI/DKI definition. 488 */ 489 490 #if defined(_SYS_CONF_H) 491 #ifndef D_MP 492 #define D_MP 0 493 #endif 494 #endif 495 496 extern void *nsc_threadp(void); 497 498 #endif /* _KERNEL */ 499 500 501 /* 502 * Common defines 503 */ 504 505 #ifndef TRUE 506 #define TRUE 1 507 #endif 508 509 #ifndef FALSE 510 #define FALSE 0 511 #endif 512 513 #ifndef NBBY 514 #define NBBY 8 /* number of bits per byte */ 515 #endif 516 517 /* 518 * kstat definition 519 */ 520 #define KSTAT_DATA_CHAR_LEN (sizeof (((kstat_named_t *)0)->value.c)) 521 522 #ifdef __cplusplus 523 } 524 #endif 525 526 #endif /* _SYS_NSCTL_H */ 527