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
;
58 /* bit definitions for alter_behavior passed to cmlb_attach */
60 #define CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT 0x00000001
61 #define CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8 0x00000002
62 #define CMLB_OFF_BY_ONE 0x00000004
63 #define CMLB_FAKE_LABEL_ONE_PARTITION 0x00000008
64 #define CMLB_INTERNAL_MINOR_NODES 0x00000010
65 #define CMLB_CREATE_P0_MINOR_NODE 0x00000020
67 /* bit definitions of flag passed to cmlb_validate */
68 #define CMLB_SILENT 0x00000001
70 /* version for tg_ops */
71 #define TG_DK_OPS_VERSION_0 0
72 #define TG_DK_OPS_VERSION_1 1
74 /* definitions for cmd passed to tg_rdwr */
78 /* definitions for cmd passed to tg_getinfo */
79 #define TG_GETPHYGEOM 1
80 #define TG_GETVIRTGEOM 2
81 #define TG_GETCAPACITY 3
82 #define TG_GETBLOCKSIZE 4
85 #if defined(_SUNOS_VTOC_8)
87 #define CMLBUNIT_DFT_SHIFT 3
88 /* This will support p0 node on sparc */
89 #define CMLBUNIT_FORCE_P0_SHIFT (CMLBUNIT_DFT_SHIFT + 1)
91 #elif defined(_SUNOS_VTOC_16)
93 #define CMLBUNIT_DFT_SHIFT 6
94 #define CMLBUNIT_FORCE_P0_SHIFT (CMLBUNIT_DFT_SHIFT)
96 #else /* defined(_SUNOS_VTOC_16) */
98 #error "No VTOC format defined."
100 #endif /* defined(_SUNOS_VTOC_8) */
103 * Ops vector including utility functions into target driver that cmlb uses.
105 typedef struct cmlb_tg_ops
{
110 * perform read/write on target device associated with devi.
114 * devi: pointer to device's dev_info structure.
116 * cmd: operation to perform.
117 * Possible values: TG_READ, TG_WRITE
119 * bufp: pointer to allocated buffer for transfer
121 * start_block: starting block number to read/write (based on
122 * system blocksize, DEV_BSIZE)
124 * reqlength: requested transfer length (in bytes)
126 * tg_cookie cookie from target driver to be passed back to
127 * target driver when we call back to it through
130 * Note: It is the responsibility of caller to make sure
131 * length of buffer pointed to by bufp is at least equal to
132 * requested transfer length
136 * ENOMEM can not allocate memory
137 * EACCESS reservation conflict
139 * EFAULT copyin/copyout error
140 * ENXIO internal error/ invalid devi
141 * EINVAL invalid command value.
143 int (*tg_rdwr
)(dev_info_t
*devi
, uchar_t cmd
, void *bufp
,
144 diskaddr_t start_block
, size_t reqlength
, void *tg_cookie
);
148 * Report the information requested on device/media and
149 * store the requested info in area pointed to by arg.
152 * devi: pointer to device's dev_info structure.
154 * cmd: operation to perform
156 * arg: arg for the operation for result.
158 * tg_cookie cookie from target driver to be passed back to
159 * target driver when we call back to it through
162 * Possible commands and the interpretation of arg:
166 * Obtain raw physical geometry from target,
167 * and store in structure pointed to by arg,
168 * a cmlb_geom_t structure.
171 * Obtain HBA geometry for the target and
172 * store in struct pointed to by arg,
173 * a cmlb_geom_t structure.
176 * Report the capacity of the target (in system
177 * blocksize (DEV_BSIZE) and store in the
178 * space pointed to by arg, a diskaddr_t.
181 * Report the block size of the target
182 * in the space pointed to by arg, a uint32_t.
185 * Report the information requested on
186 * device/media and store in area pointed to by
187 * arg, a tg_attribute_t structure.
193 * EACCESS reservation conflict
195 * ENXIO internal error/invalid devi
197 * EINVAL When command is TG_GETPHYGEOM or
198 * TG_GETVIRTGEOM, or TG_GETATTR, this return code
199 * indicates the operation is not applicable to
201 * In case of TG_GETCAP, this return code
202 * indicates no media in the drive.
204 * EIO An error occurred during obtaining info
207 * ENOTSUP In case of TG_GETCAP, target does not
208 * support getting capacity info.
210 * ENOTTY Unknown command.
214 int (*tg_getinfo
)(dev_info_t
*devi
, int cmd
, void *arg
,
220 typedef struct __cmlb_handle
*cmlb_handle_t
;
224 * Functions exported from cmlb
226 * Note: Most these functions can callback to target driver through the
227 * tg_ops functions. Target driver should consider this for synchronization.
228 * Any functions that may adjust minor nodes should be called when
229 * the target driver ensures it is safe to do so.
235 * Allocates a handle.
238 * cmlbhandlep pointer to handle
241 * Allocates a handle and stores the allocated handle in the area
242 * pointed to by cmlbhandlep
245 * Kernel thread only (can sleep).
248 cmlb_alloc_handle(cmlb_handle_t
*cmlbhandlep
);
254 * Attach handle to device, create minor nodes for device.
258 * devi pointer to device's dev_info structure.
259 * tgopsp pointer to array of functions cmlb can use to callback
262 * device_type Peripheral device type as defined in
263 * scsi/generic/inquiry.h
265 * is_removable whether or not device is removable.
267 * is_hotpluggable whether or not device is hotpluggable.
269 * node_type minor node type (as used by ddi_create_minor_node)
274 * CMLB_CREATE_ALTSLICE_VTOC_16_DTYPE_DIRECT: create
275 * an alternate slice for the default label, if
276 * device type is DTYPE_DIRECT an architectures default
277 * label type is VTOC16.
278 * Otherwise alternate slice will no be created.
281 * CMLB_FAKE_GEOM_LABEL_IOCTLS_VTOC8: report a default
282 * geometry and label for DKIOCGGEOM and DKIOCGVTOC
283 * on architecture with VTOC 8 label types.
285 * CMLB_OFF_BY_ONE: do the workaround for legacy off-by-
286 * one bug in obtaining capacity (used for sd).
289 * cmlbhandle cmlb handle associated with device
291 * tg_cookie cookie from target driver to be passed back to target
292 * driver when we call back to it through tg_ops.
294 * cmlb does not interpret the values. It is currently
295 * used for sd to indicate whether retries are allowed
296 * on commands or not. e.g when cmlb entries are called
297 * from interrupt context on removable media, sd rather
298 * not have retries done.
303 * Assumes a default label based on capacity for non-removable devices.
304 * If capacity > 1TB, EFI is assumed otherwise VTOC (default VTOC
305 * for the architecture).
306 * For removable devices, default label type is assumed to be VTOC
307 * type. Create minor nodes based on a default label type.
308 * Label on the media is not validated.
309 * minor number consists of:
310 * if _SUNOS_VTOC_8 is defined
311 * lowest 3 bits is taken as partition number
312 * the rest is instance number
313 * if _SUNOS_VTOC_16 is defined
314 * lowest 6 bits is taken as partition number
315 * the rest is instance number
320 * ENXIO creating minor nodes failed.
321 * EINVAL invalid arg, unsupported tg_ops version
325 cmlb_attach(dev_info_t
*devi
, cmlb_tg_ops_t
*tgopsp
, int device_type
,
326 boolean_t is_removable
, boolean_t is_hotpluggable
, char *node_type
,
327 int alter_behavior
, cmlb_handle_t cmlbhandle
, void *tg_cookie
);
336 * cmlbhandle cmlb handle associated with device.
339 * currently used for verbosity control.
340 * CMLB_SILENT is the only current definition for it
341 * tg_cookie cookie from target driver to be passed back to target
342 * driver when we call back to it through tg_ops.
344 * If new label type is different from the current, adjust minor nodes
349 * Note: having fdisk but no solaris partition is assumed
352 * ENOMEM memory allocation failed
353 * EIO i/o errors during read or get capacity
354 * EACCESS reservation conflicts
355 * EINVAL label was corrupt, or no default label was assumed
356 * ENXIO invalid handle
360 cmlb_validate(cmlb_handle_t cmlbhandle
, int flags
, void *tg_cookie
);
364 * Invalidate in core label data
367 * cmlbhandle cmlb handle associated with device.
368 * tg_cookie cookie from target driver to be passed back to target
369 * driver when we call back to it through tg_ops.
372 cmlb_invalidate(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
378 * Get status on whether the incore label/geom data is valid
381 * cmlbhandle cmlb handle associated with device.
389 cmlb_is_valid(cmlb_handle_t cmlbhandle
);
393 * Get partition info for specified partition number.
396 * cmlbhandle cmlb handle associated with device.
397 * part partition number
398 * driver when we call back to it through tg_ops.
399 * nblocksp pointer to number of blocks
400 * startblockp pointer to starting block
401 * partnamep pointer to name of partition
402 * tagp pointer to tag info
403 * tg_cookie cookie from target driver to be passed back to target
406 * If in-core label is not valid, this functions tries to revalidate
407 * the label. If label is valid, it stores the total number of blocks
408 * in this partition in the area pointed to by nblocksp, starting
409 * block number in area pointed to by startblockp, pointer to partition
410 * name in area pointed to by partnamep, and tag value in area
412 * For EFI labels, tag value will be set to 0.
414 * For all nblocksp, startblockp and partnamep, tagp, a value of NULL
415 * indicates the corresponding info is not requested.
420 * EINVAL no valid label or requested partition number is invalid.
424 cmlb_partinfo(cmlb_handle_t cmlbhandle
, int part
, diskaddr_t
*nblocksp
,
425 diskaddr_t
*startblockp
, char **partnamep
, uint16_t *tagp
, void *tg_cookie
);
428 * cmlb_efi_label_capacity:
429 * Get capacity stored in EFI disk label.
432 * cmlbhandle cmlb handle associated with device.
433 * capacity pointer to capacity stored in EFI disk label.
434 * tg_cookie cookie from target driver to be passed back to target
435 * driver when we call back to it through tg_ops.
439 * If in-core label is not valid, this functions tries to revalidate
440 * the label. If label is valid and is an EFI label, it stores the capacity
441 * in disk label in the area pointed to by capacity.
446 * EINVAL no valid EFI label or capacity is NULL.
450 cmlb_efi_label_capacity(cmlb_handle_t cmlbhandle
, diskaddr_t
*capacity
,
455 * Ioctls for label handling will be handled by this function.
474 * cmlbhandle handle associated with device.
475 * cmd ioctl operation to be performed
476 * arg user argument, contains data to be set or reference
478 * flag bit flag, indicating open settings, 32/64 bit type
479 * cred_p user credential pointer (not currently used)
480 * rval_p not currently used
481 * tg_cookie cookie from target driver to be passed back to target
482 * driver when we call back to it through tg_ops.
497 cmlb_ioctl(cmlb_handle_t cmlbhandle
, dev_t dev
, int cmd
,
498 intptr_t arg
, int flag
, cred_t
*cred_p
, int *rval_p
, void *tg_cookie
);
502 * provide common label prop_op(9E) implementation that understands the
503 * size(9p) properties.
506 * cmlbhandle cmlb handle associated with device.
507 * dev See prop_op(9E)
514 * part partition number
515 * tg_cookie cookie from target driver to be passed back to target
518 cmlb_prop_op(cmlb_handle_t cmlbhandle
,
519 dev_t dev
, dev_info_t
*dip
, ddi_prop_op_t prop_op
, int mod_flags
,
520 char *name
, caddr_t valuep
, int *lengthp
, int part
, void *tg_cookie
);
523 * cmlb_get_devid_block:
524 * get the block number where device id is stored.
527 * cmlbhandle cmlb handle associated with device.
528 * devidblockp pointer to block number.
529 * tg_cookie cookie from target driver to be passed back to target
530 * driver when we call back to it through tg_ops.
533 * It stores the block number of device id in the area pointed to
538 * EINVAL device id does not apply to current label type.
541 cmlb_get_devid_block(cmlb_handle_t cmlbhandle
, diskaddr_t
*devidblockp
,
548 * Close the device, revert to a default label minor node for the device,
549 * if it is removable.
552 * cmlbhandle cmlb handle associated with device.
554 * tg_cookie cookie from target driver to be passed back to target
555 * driver when we call back to it through tg_ops.
558 * ENXIO Re-creating minor node failed.
561 cmlb_close(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
566 * Invalidate in-core labeling data and remove all minor nodes for
567 * the device associate with handle.
570 * cmlbhandle cmlb handle associated with device.
571 * tg_cookie cookie from target driver to be passed back to target
572 * driver when we call back to it through tg_ops.
576 cmlb_detach(cmlb_handle_t cmlbhandle
, void *tg_cookie
);
584 * cmlbhandlep pointer to handle
588 cmlb_free_handle(cmlb_handle_t
*cmlbhandlep
);
594 #endif /* _SYS_CMLB_H */