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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
33 #include <sys/dktp/fdisk.h>
36 * structure used for getting phygeom and virtgeom from target driver
38 typedef struct cmlb_geom
{
40 unsigned short g_acyl
;
41 unsigned short g_nhead
;
42 unsigned short g_nsect
;
43 unsigned short g_secsize
;
44 diskaddr_t g_capacity
;
45 unsigned short g_intrlv
;
50 typedef struct tg_attribute
{
51 int media_is_writable
;
52 int media_is_solid_state
;
57 /* bit definitions for alter_behavior passed to cmlb_attach */
59 #define CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT 0x00000001
60 #define CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8 0x00000002
61 #define CMLB_OFF_BY_ONE 0x00000004
62 #define CMLB_FAKE_LABEL_ONE_PARTITION 0x00000008
63 #define CMLB_INTERNAL_MINOR_NODES 0x00000010
65 /* bit definitions of flag passed to cmlb_validate */
66 #define CMLB_SILENT 0x00000001
68 /* version for tg_ops */
69 #define TG_DK_OPS_VERSION_0 0
70 #define TG_DK_OPS_VERSION_1 1
72 /* definitions for cmd passed to tg_rdwr */
76 /* definitions for cmd passed to tg_getinfo */
77 #define TG_GETPHYGEOM 1
78 #define TG_GETVIRTGEOM 2
79 #define TG_GETCAPACITY 3
80 #define TG_GETBLOCKSIZE 4
85 * Ops vector including utility functions into target driver that cmlb uses.
87 typedef struct cmlb_tg_ops
{
92 * perform read/write on target device associated with devi.
96 * devi: pointer to device's dev_info structure.
98 * cmd: operation to perform.
99 * Possible values: TG_READ, TG_WRITE
101 * bufp: pointer to allocated buffer for transfer
103 * start_block: starting block number to read/write (based on
104 * system blocksize, DEV_BSIZE)
106 * reqlength: requested transfer length (in bytes)
108 * tg_cookie cookie from target driver to be passed back to
109 * target driver when we call back to it through
112 * Note: It is the responsibility of caller to make sure
113 * length of buffer pointed to by bufp is at least equal to
114 * requested transfer length
118 * ENOMEM can not allocate memory
119 * EACCESS reservation conflict
121 * EFAULT copyin/copyout error
122 * ENXIO internal error/ invalid devi
123 * EINVAL invalid command value.
125 int (*tg_rdwr
)(dev_info_t
*devi
, uchar_t cmd
, void *bufp
,
126 diskaddr_t start_block
, size_t reqlength
, void *tg_cookie
);
130 * Report the information requested on device/media and
131 * store the requested info in area pointed to by arg.
134 * devi: pointer to device's dev_info structure.
136 * cmd: operation to perform
138 * arg: arg for the operation for result.
140 * tg_cookie cookie from target driver to be passed back to
141 * target driver when we call back to it through
144 * Possible commands and the interpretation of arg:
148 * Obtain raw physical geometry from target,
149 * and store in structure pointed to by arg,
150 * a cmlb_geom_t structure.
153 * Obtain HBA geometry for the target and
154 * store in struct pointed to by arg,
155 * a cmlb_geom_t structure.
158 * Report the capacity of the target (in system
159 * blocksize (DEV_BSIZE) and store in the
160 * space pointed to by arg, a diskaddr_t.
163 * Report the block size of the target
164 * in the space pointed to by arg, a uint32_t.
167 * Report the information requested on
168 * device/media and store in area pointed to by
169 * arg, a tg_attribute_t structure.
175 * EACCESS reservation conflict
177 * ENXIO internal error/invalid devi
179 * EINVAL When command is TG_GETPHYGEOM or
180 * TG_GETVIRTGEOM, or TG_GETATTR, this return code
181 * indicates the operation is not applicable to
183 * In case of TG_GETCAP, this return code
184 * indicates no media in the drive.
186 * EIO An error occurred during obtaining info
189 * ENOTSUP In case of TG_GETCAP, target does not
190 * support getting capacity info.
192 * ENOTTY Unknown command.
196 int (*tg_getinfo
)(dev_info_t
*devi
, int cmd
, void *arg
,
202 typedef struct __cmlb_handle
*cmlb_handle_t
;
206 * Functions exported from cmlb
208 * Note: Most these functions can callback to target driver through the
209 * tg_ops functions. Target driver should consider this for synchronization.
210 * Any functions that may adjust minor nodes should be called when
211 * the target driver ensures it is safe to do so.
217 * Allocates a handle.
220 * cmlbhandlep pointer to handle
223 * Allocates a handle and stores the allocated handle in the area
224 * pointed to by cmlbhandlep
227 * Kernel thread only (can sleep).
230 cmlb_alloc_handle(cmlb_handle_t
*cmlbhandlep
);
236 * Attach handle to device, create minor nodes for device.
240 * devi pointer to device's dev_info structure.
241 * tgopsp pointer to array of functions cmlb can use to callback
244 * device_type Peripheral device type as defined in
245 * scsi/generic/inquiry.h
247 * is_removable whether or not device is removable.
249 * is_hotpluggable whether or not device is hotpluggable.
251 * node_type minor node type (as used by ddi_create_minor_node)
256 * CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT: create
257 * an alternate slice for the default label, if
258 * device type is DTYPE_DIRECT an architectures default
259 * label type is VTOC16.
260 * Otherwise alternate slice will no be created.
263 * CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8: report a default
264 * geometry and label for DKIOCGGEOM and DKIOCGVTOC
265 * on architecture with VTOC 8 label types.
267 * CMLB_OFF_BY_ONE: do the workaround for legacy off-by-
268 * one bug in obtaining capacity (used for sd).
271 * cmlbhandle cmlb handle associated with device
273 * tg_cookie cookie from target driver to be passed back to target
274 * driver when we call back to it through tg_ops.
276 * cmlb does not interpret the values. It is currently
277 * used for sd to indicate whether retries are allowed
278 * on commands or not. e.g when cmlb entries are called
279 * from interrupt context on removable media, sd rather
280 * not have retries done.
285 * Assumes a default label based on capacity for non-removable devices.
286 * If capacity > 1TB, EFI is assumed otherwise VTOC (default VTOC
287 * for the architecture).
288 * For removable devices, default label type is assumed to be VTOC
289 * type. Create minor nodes based on a default label type.
290 * Label on the media is not validated.
291 * minor number consists of:
292 * if _SUNOS_VTOC_8 is defined
293 * lowest 3 bits is taken as partition number
294 * the rest is instance number
295 * if _SUNOS_VTOC_16 is defined
296 * lowest 6 bits is taken as partition number
297 * the rest is instance number
302 * ENXIO creating minor nodes failed.
303 * EINVAL invalid arg, unsupported tg_ops version
307 cmlb_attach(dev_info_t
*devi
, cmlb_tg_ops_t
*tgopsp
, int device_type
,
308 boolean_t is_removable
, boolean_t is_hotpluggable
, char *node_type
,
309 int alter_behavior
, cmlb_handle_t cmlbhandle
, void *tg_cookie
);
318 * cmlbhandle cmlb handle associated with device.
321 * currently used for verbosity control.
322 * CMLB_SILENT is the only current definition for it
323 * tg_cookie cookie from target driver to be passed back to target
324 * driver when we call back to it through tg_ops.
326 * If new label type is different from the current, adjust minor nodes
331 * Note: having fdisk but no solaris partition is assumed
334 * ENOMEM memory allocation failed
335 * EIO i/o errors during read or get capacity
336 * EACCESS reservation conflicts
337 * EINVAL label was corrupt, or no default label was assumed
338 * ENXIO invalid handle
342 cmlb_validate(cmlb_handle_t cmlbhandle
, int flags
, void *tg_cookie
);
346 * Invalidate in core label data
349 * cmlbhandle cmlb handle associated with device.
350 * tg_cookie cookie from target driver to be passed back to target
351 * driver when we call back to it through tg_ops.
354 cmlb_invalidate(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
360 * Get status on whether the incore label/geom data is valid
363 * cmlbhandle cmlb handle associated with device.
371 cmlb_is_valid(cmlb_handle_t cmlbhandle
);
375 * Get partition info for specified partition number.
378 * cmlbhandle cmlb handle associated with device.
379 * part partition number
380 * driver when we call back to it through tg_ops.
381 * nblocksp pointer to number of blocks
382 * startblockp pointer to starting block
383 * partnamep pointer to name of partition
384 * tagp pointer to tag info
385 * tg_cookie cookie from target driver to be passed back to target
388 * If in-core label is not valid, this functions tries to revalidate
389 * the label. If label is valid, it stores the total number of blocks
390 * in this partition in the area pointed to by nblocksp, starting
391 * block number in area pointed to by startblockp, pointer to partition
392 * name in area pointed to by partnamep, and tag value in area
394 * For EFI labels, tag value will be set to 0.
396 * For all nblocksp, startblockp and partnamep, tagp, a value of NULL
397 * indicates the corresponding info is not requested.
402 * EINVAL no valid label or requested partition number is invalid.
406 cmlb_partinfo(cmlb_handle_t cmlbhandle
, int part
, diskaddr_t
*nblocksp
,
407 diskaddr_t
*startblockp
, char **partnamep
, uint16_t *tagp
, void *tg_cookie
);
410 * cmlb_efi_label_capacity:
411 * Get capacity stored in EFI disk label.
414 * cmlbhandle cmlb handle associated with device.
415 * capacity pointer to capacity stored in EFI disk label.
416 * tg_cookie cookie from target driver to be passed back to target
417 * driver when we call back to it through tg_ops.
421 * If in-core label is not valid, this functions tries to revalidate
422 * the label. If label is valid and is an EFI label, it stores the capacity
423 * in disk label in the area pointed to by capacity.
428 * EINVAL no valid EFI label or capacity is NULL.
432 cmlb_efi_label_capacity(cmlb_handle_t cmlbhandle
, diskaddr_t
*capacity
,
437 * Ioctls for label handling will be handled by this function.
456 * cmlbhandle handle associated with device.
457 * cmd ioctl operation to be performed
458 * arg user argument, contains data to be set or reference
460 * flag bit flag, indicating open settings, 32/64 bit type
461 * cred_p user credential pointer (not currently used)
462 * rval_p not currently used
463 * tg_cookie cookie from target driver to be passed back to target
464 * driver when we call back to it through tg_ops.
479 cmlb_ioctl(cmlb_handle_t cmlbhandle
, dev_t dev
, int cmd
,
480 intptr_t arg
, int flag
, cred_t
*cred_p
, int *rval_p
, void *tg_cookie
);
484 * provide common label prop_op(9E) implementation that understands the
485 * size(9p) properties.
488 * cmlbhandle cmlb handle associated with device.
489 * dev See prop_op(9E)
496 * part partition number
497 * tg_cookie cookie from target driver to be passed back to target
500 cmlb_prop_op(cmlb_handle_t cmlbhandle
,
501 dev_t dev
, dev_info_t
*dip
, ddi_prop_op_t prop_op
, int mod_flags
,
502 char *name
, caddr_t valuep
, int *lengthp
, int part
, void *tg_cookie
);
505 * cmlb_get_devid_block:
506 * get the block number where device id is stored.
509 * cmlbhandle cmlb handle associated with device.
510 * devidblockp pointer to block number.
511 * tg_cookie cookie from target driver to be passed back to target
512 * driver when we call back to it through tg_ops.
515 * It stores the block number of device id in the area pointed to
520 * EINVAL device id does not apply to current label type.
523 cmlb_get_devid_block(cmlb_handle_t cmlbhandle
, diskaddr_t
*devidblockp
,
530 * Close the device, revert to a default label minor node for the device,
531 * if it is removable.
534 * cmlbhandle cmlb handle associated with device.
536 * tg_cookie cookie from target driver to be passed back to target
537 * driver when we call back to it through tg_ops.
540 * ENXIO Re-creating minor node failed.
543 cmlb_close(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
548 * Invalidate in-core labeling data and remove all minor nodes for
549 * the device associate with handle.
552 * cmlbhandle cmlb handle associated with device.
553 * tg_cookie cookie from target driver to be passed back to target
554 * driver when we call back to it through tg_ops.
558 cmlb_detach(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
566 * cmlbhandlep pointer to handle
570 cmlb_free_handle(cmlb_handle_t
*cmlbhandlep
);
576 #endif /* _SYS_CMLB_H */