xref: /titanic_51/usr/src/uts/common/sys/cmlb.h (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_CMLB_H
28 #define	_SYS_CMLB_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/dktp/fdisk.h>
37 
38 /*
39  * structure used for getting phygeom and virtgeom from target driver
40  */
41 typedef struct cmlb_geom {
42 	unsigned int    g_ncyl;
43 	unsigned short  g_acyl;
44 	unsigned short  g_nhead;
45 	unsigned short  g_nsect;
46 	unsigned short  g_secsize;
47 	diskaddr_t	g_capacity;
48 	unsigned short  g_intrlv;
49 	unsigned short  g_rpm;
50 } cmlb_geom_t;
51 
52 
53 typedef struct tg_attribute {
54 	int media_is_writable;
55 } tg_attribute_t;
56 
57 #define	TG_READ		0
58 #define	TG_WRITE	1
59 
60 #define	TG_DK_OPS_VERSION_0	0x0
61 
62 /* flag definitions for alter_behavior arg on attach */
63 
64 #define	CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT	0x00000001
65 #define	CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8		0x00000002
66 
67 /*
68  * Ops vector including utility functions into target driver that cmlb uses.
69  */
70 typedef struct cmlb_tg_ops {
71 	int	version;
72 	/*
73 	 * tg_rdwr:
74 	 *	perform read/write on target device associated with devi.
75 	 * Arguments:
76 	 *	devi:		pointer to device's dev_info structure.
77 	 *	cmd:		operation to perform.
78 	 *			Possible values: TG_READ, TG_WRITE
79 	 *	bufp:		pointer to allocated buffer for transfer
80 	 *	start_block:	starting block number to read/write (based on
81 	 *			system blocksize, DEV_BSIZE)
82 	 *
83 	 *	reqlength:	requested transfer length (in bytes)
84 	 *
85 	 * Note: It is the responsibility of caller to make sure
86 	 *	length of buffer pointed to by bufp is at least equal to
87 	 *	requested transfer length
88 	 *
89 	 * Return values:
90 	 *	0		success
91 	 *	ENOMEM		can not allocate memory
92 	 *	EACCESS  	reservation conflict
93 	 *	EIO		I/O error
94 	 *	EFAULT		copyin/copyout error
95 	 *	ENXIO		internal error/ invalid devi
96 	 *	EINVAL		invalid command value.
97 	 */
98 	int (*tg_rdwr)(dev_info_t *devi, uchar_t cmd, void *bufp,
99 	    diskaddr_t start_block, size_t reqlength);
100 
101 	/*
102 	 * tg_getphygeom:
103 	 *	Obtain raw physical geometry from target, and store in structure
104 	 *	pointed to by phygeomp
105 	 *
106 	 * Arguments:
107 	 *	devi:		pointer to device's dev_info structure.
108 	 *	phygeomp	pointer to allocated structure for
109 	 *			physical geometry info.
110 	 * Return values:
111 	 *	0		success
112 	 * 	EACCESS		reservation conflict
113 	 *	EINVAL		not applicable
114 	 *	EIO		other errors occurred.
115 	 *	ENXIO		internal error/ invalid devi
116 	 */
117 	int (*tg_getphygeom)(dev_info_t *devi, cmlb_geom_t *phygeomp);
118 
119 	/*
120 	 * tg_getvirtgeom:
121 	 *	obtain HBA geometry for the target and store in struct pointed
122 	 *	to by virtgeomp
123 	 * Arguments:
124 	 *	devi:		pointer to device's dev_info structure.
125 	 *	virtgeomp	pointer to allocated structure for
126 	 *			virtual geometry info.
127 	 * Return values:
128 	 *	0		success
129 	 * 	EACCESS		reservation conflict
130 	 *	EINVAL		not applicable or HBA does not provide info.
131 	 *	EIO		other errors occured.
132 	 *	ENXIO		internal error/ invalid devi
133 	 *
134 	 */
135 	int (*tg_getvirtgeom)(dev_info_t *devi, cmlb_geom_t *virtgeomp);
136 
137 	/*
138 	 * tg_getcapacity
139 	 *	Report the capacity of the target (in system blocksize,
140 	 *	DEV_BSIZE) and store the value where capp is pointing to.
141 	 *
142 	 * Arguments:
143 	 *	devi:		pointer to device's dev_info structure.
144 	 *	capp		pointer to capacity value.
145 	 *
146 	 * Return values:
147 	 *	0		success
148 	 * 	EINVAL		no media in drive
149 	 *	EIO		error occured.
150 	 *	ENOTSUP		target does not support getting capacity info.
151 	 *	EACCESS		reservation conflict
152 	 *	ENXIO		internal error/ invalid devi
153 	 */
154 	int (*tg_getcapacity)(dev_info_t *devi, diskaddr_t *capp);
155 
156 	/*
157 	 * tg_getattribute:
158 	 * 	Report the information requested on device/media and
159 	 *	store in area pointed to by tgdevmediainfop
160 	 *
161 	 * Arguments:
162 	 *	devi:		pointer to device's dev_info structure.
163 	 *	tgattribute	pointer to area for attribute info
164 	 *
165 	 * Return values:
166 	 *	0		success
167 	 * 	EINVAL		no media in drive
168 	 *	EIO		error occured.
169 	 *	ENOTSUP		target does not support getting capacity info.
170 	 *	EACCESS		reservation conflict
171 	 *
172 	 * Return values:
173 	 *	ENXIO		internal error/ invalid devi
174 	 *	EACCESS		reservation conflict
175 	 * 	EINVAL		not applicable
176 	 * 	EIO		I/O failed
177 	 */
178 	int (*tg_getattribute)(dev_info_t *devi, tg_attribute_t
179 	    *tgattribute);
180 } cmlb_tg_ops_t;
181 
182 
183 typedef struct __cmlb_handle *cmlb_handle_t;
184 
185 /*
186  *
187  * Functions exported from cmlb
188  *
189  * Note: Most these functions can callback to target driver through the
190  * tg_ops functions. Target driver should consider this for synchronization.
191  * Any functions that may adjust minor nodes should be called when
192  * the target driver ensures it is safe to do so.
193  */
194 
195 /*
196  * cmlb_alloc_handle:
197  *
198  *	Allocates a handle.
199  *
200  * Arguments:
201  *	cmlbhandlep	pointer to handle
202  *
203  * Notes:
204  *	Allocates a handle and stores the allocated handle in the area
205  *	pointed to by cmlbhandlep
206  *
207  * Context:
208  *	Kernel thread only (can sleep).
209  */
210 void
211 cmlb_alloc_handle(cmlb_handle_t *cmlbhandlep);
212 
213 
214 /*
215  * cmlb_attach:
216  *
217  *	Attach handle to device, create minor nodes for device.
218  *
219  *
220  * Arguments:
221  * 	devi		pointer to device's dev_info structure.
222  * 	tgopsp		pointer to array of functions cmlb can use to callback
223  *			to target driver.
224  *
225  *	device_type	Peripheral device type as defined in
226  *			scsi/generic/inquiry.h
227  *
228  *	is_removable	whether or not device is removable.
229  *			0 non-removable, 1 removable.
230  *
231  *	node_type	minor node type (as used by ddi_create_minor_node)
232  *
233  *	alter_behavior
234  *			bit flags:
235  *
236  *			CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT: create
237  *			an alternate slice for the default label, if
238  *			device type is DTYPE_DIRECT an architectures default
239  *			label type is VTOC16.
240  *			Otherwise alternate slice will no be created.
241  *
242  *
243  *			CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8: report a default
244  *			geometry and label for DKIOCGGEOM and DKIOCGVTOC
245  *			on architecture with VTOC 8 label types.
246  *
247  *
248  *	cmlbhandle	cmlb handle associated with device
249  *
250  * Notes:
251  *	Assumes a default label based on capacity for non-removable devices.
252  *	If capacity > 1TB, EFI is assumed otherwise VTOC (default VTOC
253  *	for the architecture).
254  *	For removable devices, default label type is assumed to be VTOC
255  *	type. Create minor nodes based on a default label type.
256  *	Label on the media is not validated.
257  *	minor number consists of:
258  *		if _SUNOS_VTOC_8 is defined
259  *			lowest 3 bits is taken as partition number
260  *			the rest is instance number
261  *		if _SUNOS_VTOC_16 is defined
262  *			lowest 6 bits is taken as partition number
263  *			the rest is instance number
264  *
265  *
266  * Return values:
267  *	0 	Success
268  * 	ENXIO 	creating minor nodes failed.
269  *
270  */
271 int
272 cmlb_attach(dev_info_t *devi, cmlb_tg_ops_t *tgopsp, int device_type,
273     int is_removable, char *node_type, int alter_behavior, cmlb_handle_t
274     cmlbhandle);
275 
276 
277 /*
278  * cmlb_validate:
279  *
280  *	Validates label.
281  *
282  * Arguments
283  *	cmlbhandle	cmlb handle associated with device.
284  *
285  * Notes:
286  *	If new label type is different from the current, adjust minor nodes
287  *	accordingly.
288  *
289  * Return values:
290  *	0		success
291  *			Note: having fdisk but no solaris partition is assumed
292  *			success.
293  *
294  *	ENOMEM		memory allocation failed
295  *	EIO		i/o errors during read or get capacity
296  * 	EACCESS		reservation conflicts
297  * 	EINVAL		label was corrupt, or no default label was assumed
298  *	ENXIO		invalid handle
299  *
300  */
301 int
302 cmlb_validate(cmlb_handle_t cmlbhandle);
303 
304 /*
305  * cmlb_invalidate:
306  *	Invalidate in core label data
307  *
308  * Arguments:
309  *	cmlbhandle	cmlb handle associated with device.
310  */
311 void
312 cmlb_invalidate(cmlb_handle_t cmlbhandle);
313 
314 
315 /*
316  * cmlb_partinfo:
317  *	Get partition info for specified partition number.
318  *
319  * Arguments:
320  *	cmlbhandle	cmlb handle associated with device.
321  *	part		partition number
322  *	nblocksp	pointer to number of blocks
323  *	startblockp	pointer to starting block
324  *	partnamep	pointer to name of partition
325  *	tagp		pointer to tag info
326  *
327  *
328  * Notes:
329  *	If in-core label is not valid, this functions tries to revalidate
330  *	the label. If label is valid, it stores the total number of blocks
331  *	in this partition in the area pointed to by nblocksp, starting
332  *	block number in area pointed to by startblockp,  pointer to partition
333  *	name in area pointed to by partnamep, and tag value in area
334  *	pointed by tagp.
335  *	For EFI labels, tag value will be set to 0.
336  *
337  *	For all nblocksp, startblockp and partnamep, tagp, a value of NULL
338  *	indicates the corresponding info is not requested.
339  *
340  *
341  * Return values:
342  *	0	success
343  *	EINVAL  no valid label or requested partition number is invalid.
344  *
345  */
346 int
347 cmlb_partinfo(cmlb_handle_t cmlbhandle, int part, diskaddr_t *nblocksp,
348     diskaddr_t *startblockp, char **partnamep, uint16_t *tagp);
349 
350 
351 /*
352  * cmlb_ioctl:
353  * Ioctls for label handling will be handled by this function.
354  * These are:
355  *	DKIOCGGEOM
356  *	DKIOCSGEOM
357  *	DKIOCGAPART
358  *	DKIOCSAPART
359  *	DKIOCGVTOC
360  *	DKIOCGETEFI
361  *	DKIOCPARTITION
362  *	DKIOCSVTOC
363  * 	DKIOCSETEFI
364  *	DKIOCGMBOOT
365  *	DKIOCSMBOOT
366  *	DKIOCG_PHYGEOM
367  *	DKIOCG_VIRTGEOM
368  *	DKIOCPARTINFO
369  *
370  *
371  *   Arguments:
372  *	cmlbhandle 	handle associated with device.
373  *      cmd     	ioctl operation to be performed
374  *      arg     	user argument, contains data to be set or reference
375  *                      parameter for get
376  *	flag    	bit flag, indicating open settings, 32/64 bit type
377  *      cred_p  	user credential pointer (not currently used)
378  *	rval_p  	not currently used
379  *
380  *
381  * Return values:
382  *	0
383  *	EINVAL
384  *	ENOTTY
385  *	ENXIO
386  *	EIO
387  *	EFAULT
388  *	ENOTSUP
389  *	EPERM
390  */
391 int
392 cmlb_ioctl(cmlb_handle_t cmlbhandle, dev_t dev, int cmd, intptr_t arg,
393     int flag, cred_t *cred_p, int *rval_p);
394 
395 /*
396  * cmlb_get_devid_block:
397  *	 get the block number where device id is stored.
398  *
399  * Arguments:
400  *	cmlbhandle	cmlb handle associated with device.
401  *	devidblockp	pointer to block number.
402  *
403  * Notes:
404  *	It stores the block number of device id in the area pointed to
405  *	by devidblockp.
406  * 	with the block number of device id.
407  *
408  * Return values:
409  *	0	success
410  *	EINVAL 	device id does not apply to current label type.
411  */
412 int
413 cmlb_get_devid_block(cmlb_handle_t cmlbhandle, diskaddr_t *devidblockp);
414 
415 
416 /*
417  * cmlb_close:
418  *
419  * Close the device, revert to a default label minor node for the device,
420  * if it is removable.
421  *
422  * Arguments:
423  *	cmlbhandle	cmlb handle associated with device.
424  *
425  * Return values:
426  *	0	Success
427  * 	ENXIO	Re-creating minor node failed.
428  */
429 int
430 cmlb_close(cmlb_handle_t cmlbhandle);
431 
432 /*
433  * cmlb_detach:
434  *
435  * Invalidate in-core labeling data and remove all minor nodes for
436  * the device associate with handle.
437  *
438  * Arguments:
439  *	cmlbhandle	cmlb handle associated with device.
440  *
441  */
442 void
443 cmlb_detach(cmlb_handle_t cmlbhandle);
444 
445 /*
446  * cmlb_free_handle
447  *
448  *	Frees handle.
449  *
450  * Arguments:
451  *	cmlbhandlep	pointer to handle
452  *
453  */
454 void
455 cmlb_free_handle(cmlb_handle_t *cmlbhandlep);
456 
457 #ifdef	__cplusplus
458 }
459 #endif
460 
461 #endif /* _SYS_CMLB_H */
462