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 2016 Toomas Soome <tsoome@me.com>
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
34 #include <sys/dktp/fdisk.h>
37 * structure used for getting phygeom and virtgeom from target driver
39 typedef struct cmlb_geom
{
41 unsigned short g_acyl
;
42 unsigned short g_nhead
;
43 unsigned short g_nsect
;
44 unsigned short g_secsize
;
45 diskaddr_t g_capacity
;
46 unsigned short g_intrlv
;
51 typedef struct tg_attribute
{
52 int media_is_writable
;
53 int media_is_solid_state
;
54 int media_is_rotational
;
59 /* bit definitions for alter_behavior passed to cmlb_attach */
61 #define CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT 0x00000001
62 #define CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8 0x00000002
63 #define CMLB_OFF_BY_ONE 0x00000004
64 #define CMLB_FAKE_LABEL_ONE_PARTITION 0x00000008
65 #define CMLB_INTERNAL_MINOR_NODES 0x00000010
66 #define CMLB_CREATE_P0_MINOR_NODE 0x00000020
68 /* bit definitions of flag passed to cmlb_validate */
69 #define CMLB_SILENT 0x00000001
71 /* version for tg_ops */
72 #define TG_DK_OPS_VERSION_0 0
73 #define TG_DK_OPS_VERSION_1 1
75 /* definitions for cmd passed to tg_rdwr */
79 /* definitions for cmd passed to tg_getinfo */
80 #define TG_GETPHYGEOM 1
81 #define TG_GETVIRTGEOM 2
82 #define TG_GETCAPACITY 3
83 #define TG_GETBLOCKSIZE 4
86 #if defined(_SUNOS_VTOC_8)
88 #define CMLBUNIT_DFT_SHIFT 3
89 /* This will support p0 node on sparc */
90 #define CMLBUNIT_FORCE_P0_SHIFT (CMLBUNIT_DFT_SHIFT + 1)
92 #elif defined(_SUNOS_VTOC_16)
94 #define CMLBUNIT_DFT_SHIFT 6
95 #define CMLBUNIT_FORCE_P0_SHIFT (CMLBUNIT_DFT_SHIFT)
97 #else /* defined(_SUNOS_VTOC_16) */
99 #error "No VTOC format defined."
101 #endif /* defined(_SUNOS_VTOC_8) */
104 * Ops vector including utility functions into target driver that cmlb uses.
106 typedef struct cmlb_tg_ops
{
111 * perform read/write on target device associated with devi.
115 * devi: pointer to device's dev_info structure.
117 * cmd: operation to perform.
118 * Possible values: TG_READ, TG_WRITE
120 * bufp: pointer to allocated buffer for transfer
122 * start_block: starting block number to read/write (based on
123 * system blocksize, DEV_BSIZE)
125 * reqlength: requested transfer length (in bytes)
127 * tg_cookie cookie from target driver to be passed back to
128 * target driver when we call back to it through
131 * Note: It is the responsibility of caller to make sure
132 * length of buffer pointed to by bufp is at least equal to
133 * requested transfer length
137 * ENOMEM can not allocate memory
138 * EACCESS reservation conflict
140 * EFAULT copyin/copyout error
141 * ENXIO internal error/ invalid devi
142 * EINVAL invalid command value.
144 int (*tg_rdwr
)(dev_info_t
*devi
, uchar_t cmd
, void *bufp
,
145 diskaddr_t start_block
, size_t reqlength
, void *tg_cookie
);
149 * Report the information requested on device/media and
150 * store the requested info in area pointed to by arg.
153 * devi: pointer to device's dev_info structure.
155 * cmd: operation to perform
157 * arg: arg for the operation for result.
159 * tg_cookie cookie from target driver to be passed back to
160 * target driver when we call back to it through
163 * Possible commands and the interpretation of arg:
167 * Obtain raw physical geometry from target,
168 * and store in structure pointed to by arg,
169 * a cmlb_geom_t structure.
172 * Obtain HBA geometry for the target and
173 * store in struct pointed to by arg,
174 * a cmlb_geom_t structure.
177 * Report the capacity of the target (in system
178 * blocksize (DEV_BSIZE) and store in the
179 * space pointed to by arg, a diskaddr_t.
182 * Report the block size of the target
183 * in the space pointed to by arg, a uint32_t.
186 * Report the information requested on
187 * device/media and store in area pointed to by
188 * arg, a tg_attribute_t structure.
194 * EACCESS reservation conflict
196 * ENXIO internal error/invalid devi
198 * EINVAL When command is TG_GETPHYGEOM or
199 * TG_GETVIRTGEOM, or TG_GETATTR, this return code
200 * indicates the operation is not applicable to
202 * In case of TG_GETCAP, this return code
203 * indicates no media in the drive.
205 * EIO An error occurred during obtaining info
208 * ENOTSUP In case of TG_GETCAP, target does not
209 * support getting capacity info.
211 * ENOTTY Unknown command.
215 int (*tg_getinfo
)(dev_info_t
*devi
, int cmd
, void *arg
,
221 typedef struct __cmlb_handle
*cmlb_handle_t
;
225 * Functions exported from cmlb
227 * Note: Most these functions can callback to target driver through the
228 * tg_ops functions. Target driver should consider this for synchronization.
229 * Any functions that may adjust minor nodes should be called when
230 * the target driver ensures it is safe to do so.
236 * Allocates a handle.
239 * cmlbhandlep pointer to handle
242 * Allocates a handle and stores the allocated handle in the area
243 * pointed to by cmlbhandlep
246 * Kernel thread only (can sleep).
249 cmlb_alloc_handle(cmlb_handle_t
*cmlbhandlep
);
255 * Attach handle to device, create minor nodes for device.
259 * devi pointer to device's dev_info structure.
260 * tgopsp pointer to array of functions cmlb can use to callback
263 * device_type Peripheral device type as defined in
264 * scsi/generic/inquiry.h
266 * is_removable whether or not device is removable.
268 * is_hotpluggable whether or not device is hotpluggable.
270 * node_type minor node type (as used by ddi_create_minor_node)
275 * CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT: create
276 * an alternate slice for the default label, if
277 * device type is DTYPE_DIRECT an architectures default
278 * label type is VTOC16.
279 * Otherwise alternate slice will no be created.
282 * CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8: report a default
283 * geometry and label for DKIOCGGEOM and DKIOCGVTOC
284 * on architecture with VTOC 8 label types.
286 * CMLB_OFF_BY_ONE: do the workaround for legacy off-by-
287 * one bug in obtaining capacity (used for sd).
290 * cmlbhandle cmlb handle associated with device
292 * tg_cookie cookie from target driver to be passed back to target
293 * driver when we call back to it through tg_ops.
295 * cmlb does not interpret the values. It is currently
296 * used for sd to indicate whether retries are allowed
297 * on commands or not. e.g when cmlb entries are called
298 * from interrupt context on removable media, sd rather
299 * not have retries done.
304 * Assumes a default label based on capacity for non-removable devices.
305 * If capacity > 1TB, EFI is assumed otherwise VTOC (default VTOC
306 * for the architecture).
307 * For removable devices, default label type is assumed to be VTOC
308 * type. Create minor nodes based on a default label type.
309 * Label on the media is not validated.
310 * minor number consists of:
311 * if _SUNOS_VTOC_8 is defined
312 * lowest 3 bits is taken as partition number
313 * the rest is instance number
314 * if _SUNOS_VTOC_16 is defined
315 * lowest 6 bits is taken as partition number
316 * the rest is instance number
321 * ENXIO creating minor nodes failed.
322 * EINVAL invalid arg, unsupported tg_ops version
326 cmlb_attach(dev_info_t
*devi
, cmlb_tg_ops_t
*tgopsp
, int device_type
,
327 boolean_t is_removable
, boolean_t is_hotpluggable
, char *node_type
,
328 int alter_behavior
, cmlb_handle_t cmlbhandle
, void *tg_cookie
);
337 * cmlbhandle cmlb handle associated with device.
340 * currently used for verbosity control.
341 * CMLB_SILENT is the only current definition for it
342 * tg_cookie cookie from target driver to be passed back to target
343 * driver when we call back to it through tg_ops.
345 * If new label type is different from the current, adjust minor nodes
350 * Note: having fdisk but no solaris partition is assumed
353 * ENOMEM memory allocation failed
354 * EIO i/o errors during read or get capacity
355 * EACCESS reservation conflicts
356 * EINVAL label was corrupt, or no default label was assumed
357 * ENXIO invalid handle
361 cmlb_validate(cmlb_handle_t cmlbhandle
, int flags
, void *tg_cookie
);
365 * Invalidate in core label data
368 * cmlbhandle cmlb handle associated with device.
369 * tg_cookie cookie from target driver to be passed back to target
370 * driver when we call back to it through tg_ops.
373 cmlb_invalidate(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
379 * Get status on whether the incore label/geom data is valid
382 * cmlbhandle cmlb handle associated with device.
390 cmlb_is_valid(cmlb_handle_t cmlbhandle
);
394 * Get partition info for specified partition number.
397 * cmlbhandle cmlb handle associated with device.
398 * part partition number
399 * driver when we call back to it through tg_ops.
400 * nblocksp pointer to number of blocks
401 * startblockp pointer to starting block
402 * partnamep pointer to name of partition
403 * tagp pointer to tag info
404 * tg_cookie cookie from target driver to be passed back to target
407 * If in-core label is not valid, this functions tries to revalidate
408 * the label. If label is valid, it stores the total number of blocks
409 * in this partition in the area pointed to by nblocksp, starting
410 * block number in area pointed to by startblockp, pointer to partition
411 * name in area pointed to by partnamep, and tag value in area
413 * For EFI labels, tag value will be set to 0.
415 * For all nblocksp, startblockp and partnamep, tagp, a value of NULL
416 * indicates the corresponding info is not requested.
421 * EINVAL no valid label or requested partition number is invalid.
425 cmlb_partinfo(cmlb_handle_t cmlbhandle
, int part
, diskaddr_t
*nblocksp
,
426 diskaddr_t
*startblockp
, char **partnamep
, uint16_t *tagp
, void *tg_cookie
);
429 * cmlb_efi_label_capacity:
430 * Get capacity stored in EFI disk label.
433 * cmlbhandle cmlb handle associated with device.
434 * capacity pointer to capacity stored in EFI disk label.
435 * tg_cookie cookie from target driver to be passed back to target
436 * driver when we call back to it through tg_ops.
440 * If in-core label is not valid, this functions tries to revalidate
441 * the label. If label is valid and is an EFI label, it stores the capacity
442 * in disk label in the area pointed to by capacity.
447 * EINVAL no valid EFI label or capacity is NULL.
451 cmlb_efi_label_capacity(cmlb_handle_t cmlbhandle
, diskaddr_t
*capacity
,
456 * Ioctls for label handling will be handled by this function.
475 * cmlbhandle handle associated with device.
476 * cmd ioctl operation to be performed
477 * arg user argument, contains data to be set or reference
479 * flag bit flag, indicating open settings, 32/64 bit type
480 * cred_p user credential pointer (not currently used)
481 * rval_p not currently used
482 * tg_cookie cookie from target driver to be passed back to target
483 * driver when we call back to it through tg_ops.
498 cmlb_ioctl(cmlb_handle_t cmlbhandle
, dev_t dev
, int cmd
,
499 intptr_t arg
, int flag
, cred_t
*cred_p
, int *rval_p
, void *tg_cookie
);
503 * provide common label prop_op(9E) implementation that understands the
504 * size(9p) properties.
507 * cmlbhandle cmlb handle associated with device.
508 * dev See prop_op(9E)
515 * part partition number
516 * tg_cookie cookie from target driver to be passed back to target
519 cmlb_prop_op(cmlb_handle_t cmlbhandle
,
520 dev_t dev
, dev_info_t
*dip
, ddi_prop_op_t prop_op
, int mod_flags
,
521 char *name
, caddr_t valuep
, int *lengthp
, int part
, void *tg_cookie
);
524 * cmlb_get_devid_block:
525 * get the block number where device id is stored.
528 * cmlbhandle cmlb handle associated with device.
529 * devidblockp pointer to block number.
530 * tg_cookie cookie from target driver to be passed back to target
531 * driver when we call back to it through tg_ops.
534 * It stores the block number of device id in the area pointed to
539 * EINVAL device id does not apply to current label type.
542 cmlb_get_devid_block(cmlb_handle_t cmlbhandle
, diskaddr_t
*devidblockp
,
549 * Close the device, revert to a default label minor node for the device,
550 * if it is removable.
553 * cmlbhandle cmlb handle associated with device.
555 * tg_cookie cookie from target driver to be passed back to target
556 * driver when we call back to it through tg_ops.
559 * ENXIO Re-creating minor node failed.
562 cmlb_close(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
567 * Invalidate in-core labeling data and remove all minor nodes for
568 * the device associate with handle.
571 * cmlbhandle cmlb handle associated with device.
572 * tg_cookie cookie from target driver to be passed back to target
573 * driver when we call back to it through tg_ops.
577 cmlb_detach(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
585 * cmlbhandlep pointer to handle
589 cmlb_free_handle(cmlb_handle_t
*cmlbhandlep
);
595 #endif /* _SYS_CMLB_H */