xref: /illumos-gate/usr/src/uts/common/sys/cmlb.h (revision acb450dd)
13ccda647Slclee /*
23ccda647Slclee  * CDDL HEADER START
33ccda647Slclee  *
43ccda647Slclee  * The contents of this file are subject to the terms of the
5e8fb11a1Sshidokht  * Common Development and Distribution License (the "License").
6e8fb11a1Sshidokht  * You may not use this file except in compliance with the License.
73ccda647Slclee  *
83ccda647Slclee  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93ccda647Slclee  * or http://www.opensolaris.org/os/licensing.
103ccda647Slclee  * See the License for the specific language governing permissions
113ccda647Slclee  * and limitations under the License.
123ccda647Slclee  *
133ccda647Slclee  * When distributing Covered Code, include this CDDL HEADER in each
143ccda647Slclee  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153ccda647Slclee  * If applicable, add the following below this CDDL HEADER, with the
163ccda647Slclee  * fields enclosed by brackets "[]" replaced with your own identifying
173ccda647Slclee  * information: Portions Copyright [yyyy] [name of copyright owner]
183ccda647Slclee  *
193ccda647Slclee  * CDDL HEADER END
203ccda647Slclee  */
213ccda647Slclee /*
22406fc510SToomas Soome  * Copyright 2016 Toomas Soome <tsoome@me.com>
237f0b8309SEdward Pilatowicz  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
243ccda647Slclee  * Use is subject to license terms.
253ccda647Slclee  */
263ccda647Slclee 
273ccda647Slclee #ifndef _SYS_CMLB_H
283ccda647Slclee #define	_SYS_CMLB_H
293ccda647Slclee 
303ccda647Slclee #ifdef	__cplusplus
313ccda647Slclee extern "C" {
323ccda647Slclee #endif
333ccda647Slclee 
343ccda647Slclee #include <sys/dktp/fdisk.h>
353ccda647Slclee 
363ccda647Slclee /*
373ccda647Slclee  * structure used for getting phygeom and virtgeom from target driver
383ccda647Slclee  */
393ccda647Slclee typedef struct cmlb_geom {
403ccda647Slclee 	unsigned int    g_ncyl;
413ccda647Slclee 	unsigned short  g_acyl;
423ccda647Slclee 	unsigned short  g_nhead;
433ccda647Slclee 	unsigned short  g_nsect;
443ccda647Slclee 	unsigned short  g_secsize;
453ccda647Slclee 	diskaddr_t	g_capacity;
463ccda647Slclee 	unsigned short  g_intrlv;
473ccda647Slclee 	unsigned short  g_rpm;
483ccda647Slclee } cmlb_geom_t;
493ccda647Slclee 
503ccda647Slclee 
513ccda647Slclee typedef struct tg_attribute {
523ccda647Slclee 	int media_is_writable;
53b081f1c4Syu, larry liu - Sun Microsystems - Beijing China 	int media_is_solid_state;
54*acb450ddSYuri Pankov 	int media_is_rotational;
553ccda647Slclee } tg_attribute_t;
563ccda647Slclee 
573ccda647Slclee 
583ccda647Slclee 
59e8fb11a1Sshidokht /* bit definitions for alter_behavior passed to cmlb_attach */
603ccda647Slclee 
613ccda647Slclee #define	CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT	0x00000001
623ccda647Slclee #define	CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8		0x00000002
63e8fb11a1Sshidokht #define	CMLB_OFF_BY_ONE					0x00000004
64843e1988Sjohnlev #define	CMLB_FAKE_LABEL_ONE_PARTITION			0x00000008
6506bbe1e0Sedp #define	CMLB_INTERNAL_MINOR_NODES			0x00000010
66406fc510SToomas Soome #define	CMLB_CREATE_P0_MINOR_NODE			0x00000020
67e8fb11a1Sshidokht 
68e8fb11a1Sshidokht /* bit definitions of flag passed to cmlb_validate */
69e8fb11a1Sshidokht #define	CMLB_SILENT					0x00000001
70e8fb11a1Sshidokht 
71e8fb11a1Sshidokht /* version for tg_ops */
72e8fb11a1Sshidokht #define	TG_DK_OPS_VERSION_0	0
73e8fb11a1Sshidokht #define	TG_DK_OPS_VERSION_1	1
74e8fb11a1Sshidokht 
75e8fb11a1Sshidokht /* definitions for cmd passed to tg_rdwr */
76e8fb11a1Sshidokht #define	TG_READ			0
77e8fb11a1Sshidokht #define	TG_WRITE		1
78e8fb11a1Sshidokht 
79e8fb11a1Sshidokht /* definitions for cmd passed to tg_getinfo */
80e8fb11a1Sshidokht #define	TG_GETPHYGEOM		1
81e8fb11a1Sshidokht #define	TG_GETVIRTGEOM		2
82e8fb11a1Sshidokht #define	TG_GETCAPACITY		3
83e8fb11a1Sshidokht #define	TG_GETBLOCKSIZE		4
84e8fb11a1Sshidokht #define	TG_GETATTR		5
85e8fb11a1Sshidokht 
86406fc510SToomas Soome #if defined(_SUNOS_VTOC_8)
87406fc510SToomas Soome 
88406fc510SToomas Soome #define	CMLBUNIT_DFT_SHIFT	3
89406fc510SToomas Soome /* This will support p0 node on sparc */
90406fc510SToomas Soome #define	CMLBUNIT_FORCE_P0_SHIFT	(CMLBUNIT_DFT_SHIFT + 1)
91406fc510SToomas Soome 
92406fc510SToomas Soome #elif defined(_SUNOS_VTOC_16)
93406fc510SToomas Soome 
94406fc510SToomas Soome #define	CMLBUNIT_DFT_SHIFT	6
95406fc510SToomas Soome #define	CMLBUNIT_FORCE_P0_SHIFT	(CMLBUNIT_DFT_SHIFT)
96406fc510SToomas Soome 
97406fc510SToomas Soome #else	/* defined(_SUNOS_VTOC_16) */
98406fc510SToomas Soome 
99406fc510SToomas Soome #error "No VTOC format defined."
100406fc510SToomas Soome 
101406fc510SToomas Soome #endif	/* defined(_SUNOS_VTOC_8) */
1023ccda647Slclee 
1033ccda647Slclee /*
1043ccda647Slclee  * Ops vector including utility functions into target driver that cmlb uses.
1053ccda647Slclee  */
1063ccda647Slclee typedef struct cmlb_tg_ops {
107e8fb11a1Sshidokht 	int	tg_version;
108e8fb11a1Sshidokht 
1093ccda647Slclee 	/*
1103ccda647Slclee 	 * tg_rdwr:
1113ccda647Slclee 	 *	perform read/write on target device associated with devi.
112e8fb11a1Sshidokht 	 *
1133ccda647Slclee 	 * Arguments:
114e8fb11a1Sshidokht 	 *
1153ccda647Slclee 	 *	devi:		pointer to device's dev_info structure.
116e8fb11a1Sshidokht 	 *
1173ccda647Slclee 	 *	cmd:		operation to perform.
1183ccda647Slclee 	 *			Possible values: TG_READ, TG_WRITE
119e8fb11a1Sshidokht 	 *
1203ccda647Slclee 	 *	bufp:		pointer to allocated buffer for transfer
121e8fb11a1Sshidokht 	 *
1223ccda647Slclee 	 *	start_block:	starting block number to read/write (based on
1233ccda647Slclee 	 *			system blocksize, DEV_BSIZE)
1243ccda647Slclee 	 *
1253ccda647Slclee 	 *	reqlength:	requested transfer length (in bytes)
1263ccda647Slclee 	 *
127e8fb11a1Sshidokht 	 *	tg_cookie 	cookie from target driver to be passed back to
128e8fb11a1Sshidokht 	 *			target driver when we call back to it through
129e8fb11a1Sshidokht 	 *			tg_ops.
130e8fb11a1Sshidokht 	 *
1313ccda647Slclee 	 * Note: It is the responsibility of caller to make sure
1323ccda647Slclee 	 *	length of buffer pointed to by bufp is at least equal to
1333ccda647Slclee 	 *	requested transfer length
1343ccda647Slclee 	 *
1353ccda647Slclee 	 * Return values:
1363ccda647Slclee 	 *	0		success
1373ccda647Slclee 	 *	ENOMEM		can not allocate memory
1383ccda647Slclee 	 *	EACCESS  	reservation conflict
1393ccda647Slclee 	 *	EIO		I/O error
1403ccda647Slclee 	 *	EFAULT		copyin/copyout error
1413ccda647Slclee 	 *	ENXIO		internal error/ invalid devi
1423ccda647Slclee 	 *	EINVAL		invalid command value.
1433ccda647Slclee 	 */
1443ccda647Slclee 	int (*tg_rdwr)(dev_info_t *devi, uchar_t cmd, void *bufp,
145e8fb11a1Sshidokht 	    diskaddr_t start_block, size_t reqlength, void *tg_cookie);
1463ccda647Slclee 
1473ccda647Slclee 	/*
148e8fb11a1Sshidokht 	 * tg_getinfo:
1493ccda647Slclee 	 * 	Report the information requested on device/media and
150e8fb11a1Sshidokht 	 *	store the requested info in area pointed to by arg.
1513ccda647Slclee 	 *
1523ccda647Slclee 	 * Arguments:
1533ccda647Slclee 	 *	devi:		pointer to device's dev_info structure.
154e8fb11a1Sshidokht 	 *
155e8fb11a1Sshidokht 	 *	cmd:		operation to perform
156e8fb11a1Sshidokht 	 *
157e8fb11a1Sshidokht 	 *	arg:		arg for the operation for result.
158e8fb11a1Sshidokht 	 *
159e8fb11a1Sshidokht 	 *	tg_cookie 	cookie from target driver to be passed back to
160e8fb11a1Sshidokht 	 *			target driver when we call back to it through
161e8fb11a1Sshidokht 	 *			tg_ops.
162e8fb11a1Sshidokht 	 *
163e8fb11a1Sshidokht 	 * 	Possible commands and the interpretation of arg:
164e8fb11a1Sshidokht 	 *
165e8fb11a1Sshidokht 	 *	cmd:
166e8fb11a1Sshidokht 	 *		TG_GETPHYGEOM
167e8fb11a1Sshidokht 	 *			Obtain raw physical geometry from target,
168e8fb11a1Sshidokht 	 *			and store in structure pointed to by arg,
169e8fb11a1Sshidokht 	 *			a cmlb_geom_t structure.
170e8fb11a1Sshidokht 	 *
171e8fb11a1Sshidokht 	 * 		TG_GETVIRTGEOM:
172e8fb11a1Sshidokht 	 *			Obtain HBA geometry for the target and
173e8fb11a1Sshidokht 	 *			store in struct pointed to by arg,
174e8fb11a1Sshidokht 	 *			a cmlb_geom_t structure.
175e8fb11a1Sshidokht 	 *
176e8fb11a1Sshidokht 	 *		TG_GETCAPACITY:
177e8fb11a1Sshidokht 	 *			Report the capacity of the target (in system
178e8fb11a1Sshidokht 	 *			blocksize (DEV_BSIZE) and store in the
179e8fb11a1Sshidokht 	 *			space pointed to by arg, a diskaddr_t.
180e8fb11a1Sshidokht 	 *
181e8fb11a1Sshidokht 	 *		TG_GETBLOCKSIZE:
182e8fb11a1Sshidokht 	 *			Report the block size of the target
183e8fb11a1Sshidokht 	 *			in the space pointed to by arg, a uint32_t.
184e8fb11a1Sshidokht 	 *
185e8fb11a1Sshidokht 	 *		TG_GETATTR:
186e8fb11a1Sshidokht 	 * 			Report the information requested on
187e8fb11a1Sshidokht 	 *			device/media and store in area pointed to by
188e8fb11a1Sshidokht 	 *			arg, a tg_attribute_t structure.
189e8fb11a1Sshidokht 	 *			Return values:
1903ccda647Slclee 	 *
1913ccda647Slclee 	 * Return values:
1923ccda647Slclee 	 *	0		success
193e8fb11a1Sshidokht 	 *
1943ccda647Slclee 	 *	EACCESS		reservation conflict
1953ccda647Slclee 	 *
1963ccda647Slclee 	 *	ENXIO		internal error/invalid devi
197e8fb11a1Sshidokht 	 *
198e8fb11a1Sshidokht 	 *	EINVAL		When command is TG_GETPHYGEOM or
199e8fb11a1Sshidokht 	 *			TG_GETVIRTGEOM, or TG_GETATTR, this return code
200e8fb11a1Sshidokht 	 *			indicates the operation is not applicable to
201e8fb11a1Sshidokht 	 *			target.
202e8fb11a1Sshidokht 	 *			In case of TG_GETCAP, this return code
203e8fb11a1Sshidokht 	 *			indicates no media in the drive.
204e8fb11a1Sshidokht 	 *
205b9ccdc5aScth 	 *	EIO		An error occurred during obtaining info
206e8fb11a1Sshidokht 	 *			from device/media.
207e8fb11a1Sshidokht 	 *
208e8fb11a1Sshidokht 	 *	ENOTSUP		In case of TG_GETCAP, target does not
209e8fb11a1Sshidokht 	 *			support getting capacity info.
210e8fb11a1Sshidokht 	 *
211e8fb11a1Sshidokht 	 *	ENOTTY		Unknown command.
212e8fb11a1Sshidokht 	 *
213e8fb11a1Sshidokht 	 *
2143ccda647Slclee 	 */
215e8fb11a1Sshidokht 	int (*tg_getinfo)(dev_info_t *devi, int cmd, void *arg,
216e8fb11a1Sshidokht 	    void *tg_cookie);
217e8fb11a1Sshidokht 
2183ccda647Slclee } cmlb_tg_ops_t;
2193ccda647Slclee 
2203ccda647Slclee 
2213ccda647Slclee typedef struct __cmlb_handle *cmlb_handle_t;
2223ccda647Slclee 
2233ccda647Slclee /*
2243ccda647Slclee  *
2253ccda647Slclee  * Functions exported from cmlb
2263ccda647Slclee  *
2273ccda647Slclee  * Note: Most these functions can callback to target driver through the
2283ccda647Slclee  * tg_ops functions. Target driver should consider this for synchronization.
2293ccda647Slclee  * Any functions that may adjust minor nodes should be called when
2303ccda647Slclee  * the target driver ensures it is safe to do so.
2313ccda647Slclee  */
2323ccda647Slclee 
2333ccda647Slclee /*
2343ccda647Slclee  * cmlb_alloc_handle:
2353ccda647Slclee  *
2363ccda647Slclee  *	Allocates a handle.
2373ccda647Slclee  *
2383ccda647Slclee  * Arguments:
2393ccda647Slclee  *	cmlbhandlep	pointer to handle
2403ccda647Slclee  *
2413ccda647Slclee  * Notes:
2423ccda647Slclee  *	Allocates a handle and stores the allocated handle in the area
2433ccda647Slclee  *	pointed to by cmlbhandlep
2443ccda647Slclee  *
2453ccda647Slclee  * Context:
2463ccda647Slclee  *	Kernel thread only (can sleep).
2473ccda647Slclee  */
2483ccda647Slclee void
2493ccda647Slclee cmlb_alloc_handle(cmlb_handle_t *cmlbhandlep);
2503ccda647Slclee 
2513ccda647Slclee 
2523ccda647Slclee /*
2533ccda647Slclee  * cmlb_attach:
2543ccda647Slclee  *
2553ccda647Slclee  *	Attach handle to device, create minor nodes for device.
2563ccda647Slclee  *
2573ccda647Slclee  *
2583ccda647Slclee  * Arguments:
2593ccda647Slclee  * 	devi		pointer to device's dev_info structure.
2603ccda647Slclee  * 	tgopsp		pointer to array of functions cmlb can use to callback
2613ccda647Slclee  *			to target driver.
2623ccda647Slclee  *
2633ccda647Slclee  *	device_type	Peripheral device type as defined in
2643ccda647Slclee  *			scsi/generic/inquiry.h
2653ccda647Slclee  *
2663ccda647Slclee  *	is_removable	whether or not device is removable.
2673ccda647Slclee  *
268e8fb11a1Sshidokht  *	is_hotpluggable	whether or not device is hotpluggable.
269e8fb11a1Sshidokht  *
2703ccda647Slclee  *	node_type	minor node type (as used by ddi_create_minor_node)
2713ccda647Slclee  *
2723ccda647Slclee  *	alter_behavior
2733ccda647Slclee  *			bit flags:
2743ccda647Slclee  *
2753ccda647Slclee  *			CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT: create
2763ccda647Slclee  *			an alternate slice for the default label, if
2773ccda647Slclee  *			device type is DTYPE_DIRECT an architectures default
2783ccda647Slclee  *			label type is VTOC16.
2793ccda647Slclee  *			Otherwise alternate slice will no be created.
2803ccda647Slclee  *
2813ccda647Slclee  *
2823ccda647Slclee  *			CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8: report a default
2833ccda647Slclee  *			geometry and label for DKIOCGGEOM and DKIOCGVTOC
2843ccda647Slclee  *			on architecture with VTOC 8 label types.
2853ccda647Slclee  *
286e8fb11a1Sshidokht  * 			CMLB_OFF_BY_ONE: do the workaround for legacy off-by-
287e8fb11a1Sshidokht  *			one bug in obtaining capacity (used for sd).
288e8fb11a1Sshidokht  *
2893ccda647Slclee  *
2903ccda647Slclee  *	cmlbhandle	cmlb handle associated with device
2913ccda647Slclee  *
292e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
293e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
294e8fb11a1Sshidokht  *
295e8fb11a1Sshidokht  *			cmlb does not interpret the values. It is currently
296e8fb11a1Sshidokht  *			used for sd to indicate whether retries are allowed
297e8fb11a1Sshidokht  *			on commands or not. e.g when cmlb entries are called
298e8fb11a1Sshidokht  *			from interrupt context on removable media, sd rather
299e8fb11a1Sshidokht  *			not have retries done.
300e8fb11a1Sshidokht  *
301e8fb11a1Sshidokht  *
302e8fb11a1Sshidokht  *
3033ccda647Slclee  * Notes:
3043ccda647Slclee  *	Assumes a default label based on capacity for non-removable devices.
3053ccda647Slclee  *	If capacity > 1TB, EFI is assumed otherwise VTOC (default VTOC
3063ccda647Slclee  *	for the architecture).
3073ccda647Slclee  *	For removable devices, default label type is assumed to be VTOC
3083ccda647Slclee  *	type. Create minor nodes based on a default label type.
3093ccda647Slclee  *	Label on the media is not validated.
3103ccda647Slclee  *	minor number consists of:
3113ccda647Slclee  *		if _SUNOS_VTOC_8 is defined
3123ccda647Slclee  *			lowest 3 bits is taken as partition number
3133ccda647Slclee  *			the rest is instance number
3143ccda647Slclee  *		if _SUNOS_VTOC_16 is defined
3153ccda647Slclee  *			lowest 6 bits is taken as partition number
3163ccda647Slclee  *			the rest is instance number
3173ccda647Slclee  *
3183ccda647Slclee  *
3193ccda647Slclee  * Return values:
3203ccda647Slclee  *	0 	Success
3213ccda647Slclee  * 	ENXIO 	creating minor nodes failed.
322e8fb11a1Sshidokht  *	EINVAL	invalid arg, unsupported tg_ops version
3233ccda647Slclee  *
3243ccda647Slclee  */
3253ccda647Slclee int
3263ccda647Slclee cmlb_attach(dev_info_t *devi, cmlb_tg_ops_t *tgopsp, int device_type,
3277f0b8309SEdward Pilatowicz     boolean_t is_removable, boolean_t is_hotpluggable, char *node_type,
328e8fb11a1Sshidokht     int alter_behavior, cmlb_handle_t cmlbhandle, void *tg_cookie);
3293ccda647Slclee 
3303ccda647Slclee 
3313ccda647Slclee /*
3323ccda647Slclee  * cmlb_validate:
3333ccda647Slclee  *
3343ccda647Slclee  *	Validates label.
3353ccda647Slclee  *
3363ccda647Slclee  * Arguments
3373ccda647Slclee  *	cmlbhandle	cmlb handle associated with device.
3383ccda647Slclee  *
339e8fb11a1Sshidokht  * 	int 		flags
340e8fb11a1Sshidokht  *			currently used for verbosity control.
341e8fb11a1Sshidokht  *			CMLB_SILENT is the only current definition for it
342e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
343e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
3443ccda647Slclee  * Notes:
3453ccda647Slclee  *	If new label type is different from the current, adjust minor nodes
3463ccda647Slclee  *	accordingly.
3473ccda647Slclee  *
3483ccda647Slclee  * Return values:
3493ccda647Slclee  *	0		success
3503ccda647Slclee  *			Note: having fdisk but no solaris partition is assumed
3513ccda647Slclee  *			success.
3523ccda647Slclee  *
3533ccda647Slclee  *	ENOMEM		memory allocation failed
3543ccda647Slclee  *	EIO		i/o errors during read or get capacity
3553ccda647Slclee  * 	EACCESS		reservation conflicts
3563ccda647Slclee  * 	EINVAL		label was corrupt, or no default label was assumed
3573ccda647Slclee  *	ENXIO		invalid handle
3583ccda647Slclee  *
3593ccda647Slclee  */
3603ccda647Slclee int
361e8fb11a1Sshidokht cmlb_validate(cmlb_handle_t cmlbhandle, int flags, void *tg_cookie);
3623ccda647Slclee 
3633ccda647Slclee /*
3643ccda647Slclee  * cmlb_invalidate:
3653ccda647Slclee  *	Invalidate in core label data
3663ccda647Slclee  *
3673ccda647Slclee  * Arguments:
3683ccda647Slclee  *	cmlbhandle	cmlb handle associated with device.
369e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
370e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
3713ccda647Slclee  */
3723ccda647Slclee void
373e8fb11a1Sshidokht cmlb_invalidate(cmlb_handle_t cmlbhandle, void *tg_cookie);
3743ccda647Slclee 
3753ccda647Slclee 
376e8fb11a1Sshidokht 
377e8fb11a1Sshidokht /*
378e8fb11a1Sshidokht  * cmlb_is_valid
379e8fb11a1Sshidokht  *	 Get status on whether the incore label/geom data is valid
380e8fb11a1Sshidokht  *
381e8fb11a1Sshidokht  * Arguments:
382e8fb11a1Sshidokht  *      cmlbhandle      cmlb handle associated with device.
383e8fb11a1Sshidokht  *
384e8fb11a1Sshidokht  * Return values:
385e8fb11a1Sshidokht  *      TRUE if valid
386e8fb11a1Sshidokht  *      FALSE otherwise.
387e8fb11a1Sshidokht  *
388e8fb11a1Sshidokht  */
3897f0b8309SEdward Pilatowicz boolean_t
390e8fb11a1Sshidokht cmlb_is_valid(cmlb_handle_t cmlbhandle);
391e8fb11a1Sshidokht 
3923ccda647Slclee /*
3933ccda647Slclee  * cmlb_partinfo:
3943ccda647Slclee  *	Get partition info for specified partition number.
3953ccda647Slclee  *
3963ccda647Slclee  * Arguments:
3973ccda647Slclee  *	cmlbhandle	cmlb handle associated with device.
3983ccda647Slclee  *	part		partition number
399e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
4003ccda647Slclee  *	nblocksp	pointer to number of blocks
4013ccda647Slclee  *	startblockp	pointer to starting block
4023ccda647Slclee  *	partnamep	pointer to name of partition
4033ccda647Slclee  *	tagp		pointer to tag info
404e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
4053ccda647Slclee  *
4063ccda647Slclee  * Notes:
4073ccda647Slclee  *	If in-core label is not valid, this functions tries to revalidate
4083ccda647Slclee  *	the label. If label is valid, it stores the total number of blocks
4093ccda647Slclee  *	in this partition in the area pointed to by nblocksp, starting
4103ccda647Slclee  *	block number in area pointed to by startblockp,  pointer to partition
4113ccda647Slclee  *	name in area pointed to by partnamep, and tag value in area
4123ccda647Slclee  *	pointed by tagp.
4133ccda647Slclee  *	For EFI labels, tag value will be set to 0.
4143ccda647Slclee  *
4153ccda647Slclee  *	For all nblocksp, startblockp and partnamep, tagp, a value of NULL
4163ccda647Slclee  *	indicates the corresponding info is not requested.
4173ccda647Slclee  *
4183ccda647Slclee  *
4193ccda647Slclee  * Return values:
4203ccda647Slclee  *	0	success
4213ccda647Slclee  *	EINVAL  no valid label or requested partition number is invalid.
4223ccda647Slclee  *
4233ccda647Slclee  */
4243ccda647Slclee int
4253ccda647Slclee cmlb_partinfo(cmlb_handle_t cmlbhandle, int part, diskaddr_t *nblocksp,
426e8fb11a1Sshidokht     diskaddr_t *startblockp, char **partnamep, uint16_t *tagp, void *tg_cookie);
4273ccda647Slclee 
428af007057Syl194034 /*
429af007057Syl194034  * cmlb_efi_label_capacity:
430af007057Syl194034  *	Get capacity stored in EFI disk label.
431af007057Syl194034  *
432af007057Syl194034  * Arguments:
433af007057Syl194034  *	cmlbhandle	cmlb handle associated with device.
434af007057Syl194034  *	capacity	pointer to capacity stored in EFI disk label.
435af007057Syl194034  *	tg_cookie	cookie from target driver to be passed back to target
436af007057Syl194034  *			driver when we call back to it through tg_ops.
437af007057Syl194034  *
438af007057Syl194034  *
439af007057Syl194034  * Notes:
440af007057Syl194034  *	If in-core label is not valid, this functions tries to revalidate
441af007057Syl194034  *	the label. If label is valid and is an EFI label, it stores the capacity
442af007057Syl194034  *      in disk label in the area pointed to by capacity.
443af007057Syl194034  *
444af007057Syl194034  *
445af007057Syl194034  * Return values:
446af007057Syl194034  *	0	success
447af007057Syl194034  *	EINVAL  no valid EFI label or capacity is NULL.
448af007057Syl194034  *
449af007057Syl194034  */
450af007057Syl194034 int
451af007057Syl194034 cmlb_efi_label_capacity(cmlb_handle_t cmlbhandle, diskaddr_t *capacity,
452af007057Syl194034     void *tg_cookie);
4533ccda647Slclee 
4543ccda647Slclee /*
4553ccda647Slclee  * cmlb_ioctl:
4563ccda647Slclee  * Ioctls for label handling will be handled by this function.
4573ccda647Slclee  * These are:
4583ccda647Slclee  *	DKIOCGGEOM
4593ccda647Slclee  *	DKIOCSGEOM
4603ccda647Slclee  *	DKIOCGAPART
4613ccda647Slclee  *	DKIOCSAPART
4623ccda647Slclee  *	DKIOCGVTOC
4633ccda647Slclee  *	DKIOCGETEFI
4643ccda647Slclee  *	DKIOCPARTITION
4653ccda647Slclee  *	DKIOCSVTOC
4663ccda647Slclee  * 	DKIOCSETEFI
4673ccda647Slclee  *	DKIOCGMBOOT
4683ccda647Slclee  *	DKIOCSMBOOT
4693ccda647Slclee  *	DKIOCG_PHYGEOM
4703ccda647Slclee  *	DKIOCG_VIRTGEOM
4713ccda647Slclee  *	DKIOCPARTINFO
4723ccda647Slclee  *
4733ccda647Slclee  *
4743ccda647Slclee  *   Arguments:
4753ccda647Slclee  *	cmlbhandle 	handle associated with device.
4763ccda647Slclee  *      cmd     	ioctl operation to be performed
4773ccda647Slclee  *      arg     	user argument, contains data to be set or reference
4783ccda647Slclee  *                      parameter for get
4793ccda647Slclee  *	flag    	bit flag, indicating open settings, 32/64 bit type
4803ccda647Slclee  *      cred_p  	user credential pointer (not currently used)
4813ccda647Slclee  *	rval_p  	not currently used
482e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
483e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
484e8fb11a1Sshidokht  *
4853ccda647Slclee  *
4863ccda647Slclee  *
4873ccda647Slclee  * Return values:
4883ccda647Slclee  *	0
4893ccda647Slclee  *	EINVAL
4903ccda647Slclee  *	ENOTTY
4913ccda647Slclee  *	ENXIO
4923ccda647Slclee  *	EIO
4933ccda647Slclee  *	EFAULT
4943ccda647Slclee  *	ENOTSUP
4953ccda647Slclee  *	EPERM
4963ccda647Slclee  */
4973ccda647Slclee int
498e8fb11a1Sshidokht cmlb_ioctl(cmlb_handle_t cmlbhandle, dev_t dev, int cmd,
499e8fb11a1Sshidokht     intptr_t arg, int flag, cred_t *cred_p, int *rval_p, void *tg_cookie);
5003ccda647Slclee 
5013ccda647Slclee /*
502b9ccdc5aScth  * cmlb_prop_op:
503b9ccdc5aScth  *	provide common label prop_op(9E) implementation that understands the
504b9ccdc5aScth  *	size(9p) properties.
505b9ccdc5aScth  *
506b9ccdc5aScth  * Arguments:
507b9ccdc5aScth  *	cmlbhandle	cmlb handle associated with device.
508b9ccdc5aScth  *	dev		See prop_op(9E)
509b9ccdc5aScth  *	dip		"
510b9ccdc5aScth  *	prop_op		"
511b9ccdc5aScth  *	mod_flags	"
512b9ccdc5aScth  *	name		"
513b9ccdc5aScth  *	valuep		"
514b9ccdc5aScth  *	lengthp		"
515b9ccdc5aScth  *	part		partition number
516b9ccdc5aScth  *	tg_cookie 	cookie from target driver to be passed back to target
517b9ccdc5aScth  */
518b9ccdc5aScth int
519b9ccdc5aScth cmlb_prop_op(cmlb_handle_t cmlbhandle,
520b9ccdc5aScth     dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int mod_flags,
521b9ccdc5aScth     char *name, caddr_t valuep, int *lengthp, int part, void *tg_cookie);
522b9ccdc5aScth 
523b9ccdc5aScth /*
5243ccda647Slclee  * cmlb_get_devid_block:
5253ccda647Slclee  *	 get the block number where device id is stored.
5263ccda647Slclee  *
5273ccda647Slclee  * Arguments:
5283ccda647Slclee  *	cmlbhandle	cmlb handle associated with device.
5293ccda647Slclee  *	devidblockp	pointer to block number.
530e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
531e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
5323ccda647Slclee  *
5333ccda647Slclee  * Notes:
5343ccda647Slclee  *	It stores the block number of device id in the area pointed to
5353ccda647Slclee  *	by devidblockp.
5363ccda647Slclee  *
5373ccda647Slclee  * Return values:
5383ccda647Slclee  *	0	success
5393ccda647Slclee  *	EINVAL 	device id does not apply to current label type.
5403ccda647Slclee  */
5413ccda647Slclee int
542e8fb11a1Sshidokht cmlb_get_devid_block(cmlb_handle_t cmlbhandle, diskaddr_t *devidblockp,
543e8fb11a1Sshidokht     void *tg_cookie);
5443ccda647Slclee 
5453ccda647Slclee 
5463ccda647Slclee /*
5473ccda647Slclee  * cmlb_close:
5483ccda647Slclee  *
5493ccda647Slclee  * Close the device, revert to a default label minor node for the device,
5503ccda647Slclee  * if it is removable.
5513ccda647Slclee  *
5523ccda647Slclee  * Arguments:
5533ccda647Slclee  *	cmlbhandle	cmlb handle associated with device.
5543ccda647Slclee  *
555e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
556e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
5573ccda647Slclee  * Return values:
5583ccda647Slclee  *	0	Success
5593ccda647Slclee  * 	ENXIO	Re-creating minor node failed.
5603ccda647Slclee  */
5613ccda647Slclee int
562e8fb11a1Sshidokht cmlb_close(cmlb_handle_t cmlbhandle, void *tg_cookie);
5633ccda647Slclee 
5643ccda647Slclee /*
5653ccda647Slclee  * cmlb_detach:
5663ccda647Slclee  *
5673ccda647Slclee  * Invalidate in-core labeling data and remove all minor nodes for
5683ccda647Slclee  * the device associate with handle.
5693ccda647Slclee  *
5703ccda647Slclee  * Arguments:
5713ccda647Slclee  *	cmlbhandle	cmlb handle associated with device.
572e8fb11a1Sshidokht  *	tg_cookie 	cookie from target driver to be passed back to target
573e8fb11a1Sshidokht  *			driver when we call back to it through tg_ops.
5743ccda647Slclee  *
5753ccda647Slclee  */
5763ccda647Slclee void
577e8fb11a1Sshidokht cmlb_detach(cmlb_handle_t cmlbhandle, void *tg_cookie);
5783ccda647Slclee 
5793ccda647Slclee /*
5803ccda647Slclee  * cmlb_free_handle
5813ccda647Slclee  *
5823ccda647Slclee  *	Frees handle.
5833ccda647Slclee  *
5843ccda647Slclee  * Arguments:
5853ccda647Slclee  *	cmlbhandlep	pointer to handle
5863ccda647Slclee  *
5873ccda647Slclee  */
5883ccda647Slclee void
5893ccda647Slclee cmlb_free_handle(cmlb_handle_t *cmlbhandlep);
5903ccda647Slclee 
5913ccda647Slclee #ifdef	__cplusplus
5923ccda647Slclee }
5933ccda647Slclee #endif
5943ccda647Slclee 
5953ccda647Slclee #endif /* _SYS_CMLB_H */
596