xref: /onnv-gate/usr/src/uts/common/avs/ns/nsctl/nsc_dev.h (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM  * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM  *
4*7836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM  *
8*7836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM  * and limitations under the License.
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM  *
19*7836SJohn.Forte@Sun.COM  * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM  */
21*7836SJohn.Forte@Sun.COM /*
22*7836SJohn.Forte@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7836SJohn.Forte@Sun.COM  * Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM  */
25*7836SJohn.Forte@Sun.COM 
26*7836SJohn.Forte@Sun.COM #ifndef _NSC_DEV_H
27*7836SJohn.Forte@Sun.COM #define	_NSC_DEV_H
28*7836SJohn.Forte@Sun.COM 
29*7836SJohn.Forte@Sun.COM #ifdef __cplusplus
30*7836SJohn.Forte@Sun.COM extern "C" {
31*7836SJohn.Forte@Sun.COM #endif
32*7836SJohn.Forte@Sun.COM 
33*7836SJohn.Forte@Sun.COM #ifndef __NSC_GEN__
34*7836SJohn.Forte@Sun.COM Error: Illegal #include - private file.
35*7836SJohn.Forte@Sun.COM #endif
36*7836SJohn.Forte@Sun.COM 
37*7836SJohn.Forte@Sun.COM 
38*7836SJohn.Forte@Sun.COM #include <sys/nsctl/nsc_gen.h>
39*7836SJohn.Forte@Sun.COM #include <sys/nsc_ddi.h>
40*7836SJohn.Forte@Sun.COM 
41*7836SJohn.Forte@Sun.COM /*
42*7836SJohn.Forte@Sun.COM  * Interface to I/O module.
43*7836SJohn.Forte@Sun.COM  */
44*7836SJohn.Forte@Sun.COM 
45*7836SJohn.Forte@Sun.COM typedef struct nsc_io_s {
46*7836SJohn.Forte@Sun.COM 	struct nsc_io_s *next;		/* Link to next I/O module */
47*7836SJohn.Forte@Sun.COM 	kcondvar_t	cv;		/* Blocking variable */
48*7836SJohn.Forte@Sun.COM 	int	id;			/* Module id */
49*7836SJohn.Forte@Sun.COM 	int	flag;			/* Flags */
50*7836SJohn.Forte@Sun.COM 	char	*name;			/* Module name */
51*7836SJohn.Forte@Sun.COM 	int	refcnt;			/* Reference count */
52*7836SJohn.Forte@Sun.COM 	int	abufcnt;		/* # of allocated anonymous buffers */
53*7836SJohn.Forte@Sun.COM 	int	pend;			/* Unregister pending */
54*7836SJohn.Forte@Sun.COM 	int	(*open)();		/* Open device */
55*7836SJohn.Forte@Sun.COM 	int	(*close)();		/* Close device */
56*7836SJohn.Forte@Sun.COM 	int	(*attach)();		/* Attach device */
57*7836SJohn.Forte@Sun.COM 	int	(*detach)();		/* Detach device */
58*7836SJohn.Forte@Sun.COM 	int	(*flush)();		/* Flush device */
59*7836SJohn.Forte@Sun.COM 	int	(*alloc_buf)();		/* Allocate buffer */
60*7836SJohn.Forte@Sun.COM 	int	(*free_buf)();		/* Free buffer */
61*7836SJohn.Forte@Sun.COM 	int	(*read)();		/* Read buffer */
62*7836SJohn.Forte@Sun.COM 	int	(*write)();		/* Write buffer */
63*7836SJohn.Forte@Sun.COM 	int	(*zero)();		/* Zero buffer */
64*7836SJohn.Forte@Sun.COM 	int	(*copy)();		/* Copy buffer between handles */
65*7836SJohn.Forte@Sun.COM 	int	(*copy_direct)();	/* Copy buffer between handle & disk */
66*7836SJohn.Forte@Sun.COM 	int	(*uncommit)();		/* Uncommit buffer */
67*7836SJohn.Forte@Sun.COM 	struct nsc_buf_s *(*alloc_h)();	/* Allocate handle */
68*7836SJohn.Forte@Sun.COM 	int	(*free_h)();		/* Free handle */
69*7836SJohn.Forte@Sun.COM 	int	(*uread)();		/* User read */
70*7836SJohn.Forte@Sun.COM 	int	(*uwrite)();		/* User write */
71*7836SJohn.Forte@Sun.COM 	int	(*trksize)();		/* Set track size */
72*7836SJohn.Forte@Sun.COM 	int	(*discard)();		/* Discard pinned data */
73*7836SJohn.Forte@Sun.COM 	int	(*sizes)();		/* Return size of cache */
74*7836SJohn.Forte@Sun.COM 	int	(*getpin)();		/* Get pinned info */
75*7836SJohn.Forte@Sun.COM 	int	(*nodehints)();		/* Return current node hints */
76*7836SJohn.Forte@Sun.COM 	int	(*partsize)();		/* Partition size */
77*7836SJohn.Forte@Sun.COM 	int	(*maxfbas)();		/* Maximum I/O size */
78*7836SJohn.Forte@Sun.COM 	int	(*control)();		/* Module control function */
79*7836SJohn.Forte@Sun.COM 	long	provide;		/* Interface provided */
80*7836SJohn.Forte@Sun.COM } nsc_io_t;
81*7836SJohn.Forte@Sun.COM 
82*7836SJohn.Forte@Sun.COM 
83*7836SJohn.Forte@Sun.COM typedef struct nsc_path_s {
84*7836SJohn.Forte@Sun.COM 	struct nsc_path_s *sp_next;	/* Link to next path */
85*7836SJohn.Forte@Sun.COM 	char	*sp_path;		/* Pathname */
86*7836SJohn.Forte@Sun.COM 	int	sp_type;		/* Open type */
87*7836SJohn.Forte@Sun.COM 	nsc_io_t	*sp_io;			/* I/O module */
88*7836SJohn.Forte@Sun.COM 	int	sp_pend;		/* Unregister pending */
89*7836SJohn.Forte@Sun.COM } nsc_path_t;
90*7836SJohn.Forte@Sun.COM 
91*7836SJohn.Forte@Sun.COM 
92*7836SJohn.Forte@Sun.COM /*
93*7836SJohn.Forte@Sun.COM  * Note: NSC_MAXPATH currently defined here and in nsctl.h
94*7836SJohn.Forte@Sun.COM  */
95*7836SJohn.Forte@Sun.COM #if !defined(NSC_MAXPATH)
96*7836SJohn.Forte@Sun.COM #define	NSC_MAXPATH	64
97*7836SJohn.Forte@Sun.COM #endif
98*7836SJohn.Forte@Sun.COM 
99*7836SJohn.Forte@Sun.COM 
100*7836SJohn.Forte@Sun.COM #define	NSC_SETVAL_MAX	32
101*7836SJohn.Forte@Sun.COM 
102*7836SJohn.Forte@Sun.COM typedef struct nsc_val_s {
103*7836SJohn.Forte@Sun.COM 	struct nsc_val_s *sv_next;	/* Link to next value */
104*7836SJohn.Forte@Sun.COM 	char	sv_name[NSC_SETVAL_MAX]; /* Name of value */
105*7836SJohn.Forte@Sun.COM 	int	sv_value;		/* Value of name */
106*7836SJohn.Forte@Sun.COM } nsc_val_t;
107*7836SJohn.Forte@Sun.COM 
108*7836SJohn.Forte@Sun.COM 
109*7836SJohn.Forte@Sun.COM typedef struct nsc_devval_s {
110*7836SJohn.Forte@Sun.COM 	struct nsc_devval_s *dv_next;		/* Next dev/val header */
111*7836SJohn.Forte@Sun.COM 	nsc_val_t 	*dv_values;		/* The values */
112*7836SJohn.Forte@Sun.COM 	char		dv_path[NSC_MAXPATH];	/* Path name of device */
113*7836SJohn.Forte@Sun.COM 	uint64_t	dv_phash;		/* Hash of pathname */
114*7836SJohn.Forte@Sun.COM } nsc_devval_t;
115*7836SJohn.Forte@Sun.COM 
116*7836SJohn.Forte@Sun.COM 
117*7836SJohn.Forte@Sun.COM /* used for ncall */
118*7836SJohn.Forte@Sun.COM typedef struct nsc_rval_s {
119*7836SJohn.Forte@Sun.COM 	char	path[NSC_MAXPATH];	/* Path name of dev */
120*7836SJohn.Forte@Sun.COM 	char	name[NSC_SETVAL_MAX];	/* Name of value */
121*7836SJohn.Forte@Sun.COM 	int	value;			/* Value of name */
122*7836SJohn.Forte@Sun.COM } nsc_rval_t;
123*7836SJohn.Forte@Sun.COM 
124*7836SJohn.Forte@Sun.COM 
125*7836SJohn.Forte@Sun.COM extern int _nsc_maxdev;
126*7836SJohn.Forte@Sun.COM 
127*7836SJohn.Forte@Sun.COM #define	_NSC_OPEN	0x0004		/* Open in progress */
128*7836SJohn.Forte@Sun.COM #define	_NSC_CLOSE	0x0008		/* Close in progress */
129*7836SJohn.Forte@Sun.COM #define	_NSC_PINNED	0x0010		/* Pinned data reported */
130*7836SJohn.Forte@Sun.COM #define	_NSC_ATTACH	0x0020		/* Available for I/O */
131*7836SJohn.Forte@Sun.COM #define	_NSC_DETACH	0x0040		/* Detach in progress */
132*7836SJohn.Forte@Sun.COM #define	_NSC_OWNER	0x0080		/* Owner detach in progress */
133*7836SJohn.Forte@Sun.COM 
134*7836SJohn.Forte@Sun.COM 
135*7836SJohn.Forte@Sun.COM typedef struct nsc_iodev_s {
136*7836SJohn.Forte@Sun.COM 	struct nsc_iodev_s *si_next;	/* Link to next I/O device */
137*7836SJohn.Forte@Sun.COM 	struct nsc_fd_s *si_open;	/* Open file descriptors */
138*7836SJohn.Forte@Sun.COM 	kmutex_t	si_lock;	/* Lock to protect I/O chain */
139*7836SJohn.Forte@Sun.COM 	kcondvar_t	si_cv;		/* Blocking variable */
140*7836SJohn.Forte@Sun.COM 	int	si_refcnt;		/* Reference count */
141*7836SJohn.Forte@Sun.COM 	int	si_busy;		/* Callback in progress */
142*7836SJohn.Forte@Sun.COM 	int	si_pend;		/* Operation is pending */
143*7836SJohn.Forte@Sun.COM 	int	si_rpend;		/* Reserve is pending */
144*7836SJohn.Forte@Sun.COM 	int	si_avail;		/* Available for I/O */
145*7836SJohn.Forte@Sun.COM 	nsc_io_t *si_io;			/* Interface to I/O module */
146*7836SJohn.Forte@Sun.COM 	void	*si_active;		/* Active I/O chain */
147*7836SJohn.Forte@Sun.COM 	struct nsc_dev_s *si_dev;	/* Device structure */
148*7836SJohn.Forte@Sun.COM } nsc_iodev_t;
149*7836SJohn.Forte@Sun.COM 
150*7836SJohn.Forte@Sun.COM 
151*7836SJohn.Forte@Sun.COM typedef struct nsc_dev_s {
152*7836SJohn.Forte@Sun.COM 	struct nsc_dev_s *nsc_next;	/* Link to next device */
153*7836SJohn.Forte@Sun.COM 	struct nsc_fd_s *nsc_close;	/* Closed file descriptors */
154*7836SJohn.Forte@Sun.COM 	nsc_iodev_t *nsc_list;		/* Active I/O modules */
155*7836SJohn.Forte@Sun.COM 	char	*nsc_path;		/* Pathname */
156*7836SJohn.Forte@Sun.COM 	uint64_t	nsc_phash;	/* Pathname hash */
157*7836SJohn.Forte@Sun.COM 	kmutex_t	nsc_lock;	/* Lock to protect state */
158*7836SJohn.Forte@Sun.COM 	int	nsc_refcnt;		/* Reference count */
159*7836SJohn.Forte@Sun.COM 	kcondvar_t	nsc_cv;		/* Blocking variable */
160*7836SJohn.Forte@Sun.COM 	int	nsc_wait;		/* Count of waiters */
161*7836SJohn.Forte@Sun.COM 	int	nsc_pend;		/* Operation is pending */
162*7836SJohn.Forte@Sun.COM 	int	nsc_rpend;		/* Reserve is pending */
163*7836SJohn.Forte@Sun.COM 	int	nsc_drop;		/* Detach on release */
164*7836SJohn.Forte@Sun.COM 	int	nsc_reopen;		/* Doing reopen */
165*7836SJohn.Forte@Sun.COM 	nsc_devval_t *nsc_values;	/* Values - see nsc_setval() */
166*7836SJohn.Forte@Sun.COM } nsc_dev_t;
167*7836SJohn.Forte@Sun.COM 
168*7836SJohn.Forte@Sun.COM 
169*7836SJohn.Forte@Sun.COM /*
170*7836SJohn.Forte@Sun.COM  * Storage file descriptor.
171*7836SJohn.Forte@Sun.COM  */
172*7836SJohn.Forte@Sun.COM 
173*7836SJohn.Forte@Sun.COM typedef struct nsc_fd_s {
174*7836SJohn.Forte@Sun.COM 	struct nsc_fd_s *sf_next;	/* Link to next descriptor */
175*7836SJohn.Forte@Sun.COM 	nsc_iodev_t *sf_iodev;		/* I/O device structure */
176*7836SJohn.Forte@Sun.COM 	nsc_iodev_t *sf_owner;		/* Parent I/O device */
177*7836SJohn.Forte@Sun.COM 	nsc_dev_t *sf_dev;		/* Device structure */
178*7836SJohn.Forte@Sun.COM 	nsc_io_t *sf_aio;		/* Active I/O module */
179*7836SJohn.Forte@Sun.COM 	int	sf_avail;		/* Availability for I/O */
180*7836SJohn.Forte@Sun.COM 	int	sf_pend;		/* Operation is pending */
181*7836SJohn.Forte@Sun.COM 	int	sf_type;		/* Open type */
182*7836SJohn.Forte@Sun.COM 	int	sf_flag;		/* Open flags */
183*7836SJohn.Forte@Sun.COM 	clock_t sf_lbolt;		/* Open timestamp */
184*7836SJohn.Forte@Sun.COM 	int	sf_reopen;		/* Re-open required */
185*7836SJohn.Forte@Sun.COM 	blind_t	sf_cd;			/* Underlying I/O descriptor */
186*7836SJohn.Forte@Sun.COM 	blind_t	sf_arg;			/* Argument for callbacks */
187*7836SJohn.Forte@Sun.COM 	int	sf_reserve;		/* Device is reserved */
188*7836SJohn.Forte@Sun.COM 	int	sf_mode;		/* Type of reserve */
189*7836SJohn.Forte@Sun.COM 	void	(*sf_pinned)();		/* Callback - Data pinned */
190*7836SJohn.Forte@Sun.COM 	void	(*sf_unpinned)();	/* Callback - Data unpinned */
191*7836SJohn.Forte@Sun.COM 	int	(*sf_attach)();		/* Callback - Attach */
192*7836SJohn.Forte@Sun.COM 	int	(*sf_detach)();		/* Callback - Detach */
193*7836SJohn.Forte@Sun.COM 	int	(*sf_flush)();		/* Callback - Flush */
194*7836SJohn.Forte@Sun.COM } nsc_fd_t;
195*7836SJohn.Forte@Sun.COM 
196*7836SJohn.Forte@Sun.COM 
197*7836SJohn.Forte@Sun.COM /*
198*7836SJohn.Forte@Sun.COM  * External definitions.
199*7836SJohn.Forte@Sun.COM  */
200*7836SJohn.Forte@Sun.COM 
201*7836SJohn.Forte@Sun.COM extern nsc_io_t *_nsc_null_io;
202*7836SJohn.Forte@Sun.COM 
203*7836SJohn.Forte@Sun.COM #ifdef _KERNEL
204*7836SJohn.Forte@Sun.COM extern int _nsc_open_fd(nsc_fd_t *, int);
205*7836SJohn.Forte@Sun.COM extern int _nsc_close_fd(nsc_fd_t *, int);
206*7836SJohn.Forte@Sun.COM extern int _nsc_detach_fd(nsc_fd_t *, int);
207*7836SJohn.Forte@Sun.COM extern int _nsc_detach_iodev(nsc_iodev_t *, nsc_fd_t *, int);
208*7836SJohn.Forte@Sun.COM extern int _nsc_detach_dev(nsc_dev_t *, nsc_iodev_t *, int);
209*7836SJohn.Forte@Sun.COM extern int _nsc_call_io(long, blind_t, blind_t, blind_t);
210*7836SJohn.Forte@Sun.COM extern int _nsc_wait_dev(nsc_dev_t *, int);
211*7836SJohn.Forte@Sun.COM extern void _nsc_wake_dev(nsc_dev_t *, int *);
212*7836SJohn.Forte@Sun.COM #endif /* _KERNEL */
213*7836SJohn.Forte@Sun.COM 
214*7836SJohn.Forte@Sun.COM #ifdef __cplusplus
215*7836SJohn.Forte@Sun.COM }
216*7836SJohn.Forte@Sun.COM #endif
217*7836SJohn.Forte@Sun.COM 
218*7836SJohn.Forte@Sun.COM #endif /* _NSC_DEV_H */
219