xref: /onnv-gate/usr/src/uts/common/sys/cmlb_impl.h (revision 8863:94039d51dda4)
1786Slclee /*
2786Slclee  * CDDL HEADER START
3786Slclee  *
4786Slclee  * The contents of this file are subject to the terms of the
53525Sshidokht  * Common Development and Distribution License (the "License").
63525Sshidokht  * You may not use this file except in compliance with the License.
7786Slclee  *
8786Slclee  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9786Slclee  * or http://www.opensolaris.org/os/licensing.
10786Slclee  * See the License for the specific language governing permissions
11786Slclee  * and limitations under the License.
12786Slclee  *
13786Slclee  * When distributing Covered Code, include this CDDL HEADER in each
14786Slclee  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15786Slclee  * If applicable, add the following below this CDDL HEADER, with the
16786Slclee  * fields enclosed by brackets "[]" replaced with your own identifying
17786Slclee  * information: Portions Copyright [yyyy] [name of copyright owner]
18786Slclee  *
19786Slclee  * CDDL HEADER END
20786Slclee  */
217563SPrasad.Singamsetty@Sun.COM 
22786Slclee /*
23*8863SEdward.Pilatowicz@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24786Slclee  * Use is subject to license terms.
25786Slclee  */
26786Slclee 
27786Slclee #ifndef _SYS_CMLB_IMPL_H
28786Slclee #define	_SYS_CMLB_IMPL_H
29786Slclee 
30786Slclee #ifdef	__cplusplus
31786Slclee extern "C" {
32786Slclee #endif
33786Slclee 
34786Slclee #include <sys/cmlb.h>
35786Slclee #include <sys/ddi.h>
36786Slclee #include <sys/sunddi.h>
37786Slclee 
38786Slclee #if defined(_SUNOS_VTOC_8)
39786Slclee #define	NSDMAP			NDKMAP
40786Slclee #elif defined(_SUNOS_VTOC_16)
418333SSuhasini.Peddada@Sun.COM #define	NSDMAP			(NDKMAP + FD_NUMPART + 1)
42786Slclee #else
43786Slclee #error "No VTOC format defined."
44786Slclee #endif
45786Slclee 
46786Slclee #define	MAXPART			(NSDMAP + 1)
47786Slclee #define	WD_NODE			7
48786Slclee 
49786Slclee 
50786Slclee #if defined(__i386) || defined(__amd64)
51786Slclee 
52786Slclee #define	P0_RAW_DISK		(NDKMAP)
53786Slclee #define	FDISK_P1		(NDKMAP+1)
54786Slclee #define	FDISK_P2		(NDKMAP+2)
55786Slclee #define	FDISK_P3		(NDKMAP+3)
56786Slclee #define	FDISK_P4		(NDKMAP+4)
57786Slclee 
58786Slclee #endif  /* __i386 || __amd64 */
59786Slclee 
60786Slclee /* Driver Logging Levels */
61786Slclee #define	CMLB_LOGMASK_ERROR	0x00000001
62786Slclee #define	CMLB_LOGMASK_INFO	0x00000002
63786Slclee #define	CMLB_LOGMASK_TRACE	0x00000004
64786Slclee 
65786Slclee #define	CMLB_TRACE		0x00000001
66786Slclee #define	CMLB_INFO		0x00000002
67786Slclee #define	CMLB_ERROR		0x00000004
68786Slclee 
69786Slclee 
703525Sshidokht #define	CMLB_MUTEX(cl)		(&((cl)->cl_mutex))
713525Sshidokht #define	CMLB_DEVINFO(cl)	((cl)->cl_devi)
723525Sshidokht #define	CMLB_LABEL(cl)		(DEVI(((cl)->cl_devi))->devi_binding_name)
73786Slclee 
74786Slclee 
75*8863SEdward.Pilatowicz@Sun.COM #define	ISREMOVABLE(cl)		(cl->cl_is_removable)
763525Sshidokht #define	ISCD(cl)		(cl->cl_device_type == DTYPE_RODIRECT)
77*8863SEdward.Pilatowicz@Sun.COM #define	ISHOTPLUGGABLE(cl)	(cl->cl_is_hotpluggable)
78786Slclee 
79786Slclee #if defined(_SUNOS_VTOC_8)
80786Slclee 
81786Slclee #define	CMLBUNIT_SHIFT		3
82786Slclee #define	CMLBPART_MASK		7
83786Slclee 
84786Slclee #elif defined(_SUNOS_VTOC_16)
85786Slclee 
86786Slclee #define	CMLBUNIT_SHIFT		6
87786Slclee #define	CMLBPART_MASK		63
88786Slclee 
89786Slclee #else
90786Slclee #error "No VTOC format defined."
91786Slclee #endif
92786Slclee 
93786Slclee #define	CMLBUNIT(dev)		(getminor((dev)) >> CMLBUNIT_SHIFT)
94786Slclee #define	CMLBPART(dev)		(getminor((dev)) &  CMLBPART_MASK)
95786Slclee 
96786Slclee /*
97786Slclee  * Return codes of cmlb_uselabel().
98786Slclee  */
99786Slclee #define	CMLB_LABEL_IS_VALID	0
100786Slclee #define	CMLB_LABEL_IS_INVALID	1
101786Slclee 
1027563SPrasad.Singamsetty@Sun.COM #define	CMLB_2TB_BLOCKS		0xffffffff
1037563SPrasad.Singamsetty@Sun.COM #define	CMLB_1TB_BLOCKS		0x7fffffff
1047563SPrasad.Singamsetty@Sun.COM 
1057563SPrasad.Singamsetty@Sun.COM #define	CMLB_EXTVTOC_LIMIT	CMLB_2TB_BLOCKS
1067563SPrasad.Singamsetty@Sun.COM #define	CMLB_OLDVTOC_LIMIT	CMLB_1TB_BLOCKS
1077563SPrasad.Singamsetty@Sun.COM 
108786Slclee /*
109786Slclee  * fdisk partition mapping structure
110786Slclee  */
111786Slclee struct fmap {
1127563SPrasad.Singamsetty@Sun.COM 	ulong_t fmap_start;	/* starting block number */
1137563SPrasad.Singamsetty@Sun.COM 	ulong_t fmap_nblk;	/* number of blocks */
114786Slclee };
115786Slclee 
116786Slclee /* for cm_state */
117786Slclee typedef enum  {
118786Slclee 	CMLB_INITED = 0,
119786Slclee 	CMLB_ATTACHED
120786Slclee } cmlb_state_t;
121786Slclee 
122786Slclee typedef enum
123786Slclee {
124786Slclee 	CMLB_LABEL_UNDEF = 0,
125786Slclee 	CMLB_LABEL_VTOC,
126786Slclee 	CMLB_LABEL_EFI
127786Slclee } cmlb_label_t;
128786Slclee 
1297563SPrasad.Singamsetty@Sun.COM #define	CMLB_ALLOW_2TB_WARN 0x1
1307563SPrasad.Singamsetty@Sun.COM 
131786Slclee 
132786Slclee typedef struct cmlb_lun {
1333525Sshidokht 	dev_info_t	*cl_devi;		/* pointer to devinfo */
1343525Sshidokht 	struct dk_vtoc	cl_vtoc;	/* disk VTOC */
1353525Sshidokht 	struct dk_geom	cl_g;		/* disk geometry */
136786Slclee 
1373525Sshidokht 	diskaddr_t	cl_blockcount;		/* capacity */
1383525Sshidokht 	uint32_t	cl_tgt_blocksize;	/* blocksize */
139786Slclee 
1403525Sshidokht 	diskaddr_t	cl_solaris_size;	/* size of Solaris partition */
1413525Sshidokht 	uint_t		cl_solaris_offset;	/* offset to Solaris part. */
142786Slclee 
1433525Sshidokht 	struct  dk_map  cl_map[MAXPART];	/* logical partitions */
1447563SPrasad.Singamsetty@Sun.COM 						/* cylno is overloaded. used */
1457563SPrasad.Singamsetty@Sun.COM 						/* for starting block for EFI */
1467563SPrasad.Singamsetty@Sun.COM 
1473525Sshidokht 	diskaddr_t	cl_offset[MAXPART];	/* partition start blocks */
148786Slclee 
1498333SSuhasini.Peddada@Sun.COM 	struct fmap	cl_fmap[FD_NUMPART];	/* fdisk partitions */
150786Slclee 
1513525Sshidokht 	uchar_t		cl_asciilabel[LEN_DKL_ASCII];	/* Disk ASCII label */
152786Slclee 
153786Slclee 	/*
154786Slclee 	 * This is the HBAs current notion of the geometry of the drive,
155786Slclee 	 * for HBAs that support the "geometry" property.
156786Slclee 	 */
1573525Sshidokht 	struct cmlb_geom	cl_lgeom;
158786Slclee 
159786Slclee 	/*
160786Slclee 	 * This is the geometry of the device as reported by the MODE SENSE,
161786Slclee 	 * command, Page 3 (Format Device Page) and Page 4 (Rigid Disk Drive
162786Slclee 	 * Geometry Page), assuming MODE SENSE is supported by the target.
163786Slclee 	 */
1643525Sshidokht 	struct cmlb_geom	cl_pgeom;
165786Slclee 
1663525Sshidokht 	ushort_t	cl_dkg_skew;		/* skew */
167786Slclee 
1683525Sshidokht 	cmlb_label_t	cl_def_labeltype;	/* default label type */
169786Slclee 
170786Slclee 	/* label type based on which minor nodes were created last */
1713525Sshidokht 	cmlb_label_t	cl_last_labeltype;
172786Slclee 
1733525Sshidokht 	cmlb_label_t	cl_cur_labeltype;	/* current label type */
174786Slclee 
175786Slclee 	/* indicates whether vtoc label is read from media */
1767563SPrasad.Singamsetty@Sun.COM 	cmlb_label_t		cl_label_from_media;
177786Slclee 
1783525Sshidokht 	cmlb_state_t	cl_state;		/* state of handle */
179786Slclee 
180*8863SEdward.Pilatowicz@Sun.COM 	boolean_t	cl_f_geometry_is_valid;
1813525Sshidokht 	int		cl_sys_blocksize;
182786Slclee 
1833525Sshidokht 	kmutex_t	cl_mutex;
184786Slclee 
185786Slclee 	/* the following are passed in at attach time */
186*8863SEdward.Pilatowicz@Sun.COM 	boolean_t	cl_is_removable;	/* is removable */
187*8863SEdward.Pilatowicz@Sun.COM 	boolean_t	cl_is_hotpluggable;	/* is hotpluggable */
1883525Sshidokht 	int		cl_alter_behavior;
1893525Sshidokht 	char 		*cl_node_type;		/* DDI_NT_... */
1903525Sshidokht 	int		cl_device_type;		/* DTYPE_DIRECT,.. */
1913525Sshidokht 	int		cl_reserved;		/* reserved efi partition # */
192786Slclee 	cmlb_tg_ops_t 	*cmlb_tg_ops;
1937563SPrasad.Singamsetty@Sun.COM 	uint8_t		cl_msglog_flag;		/* used to enable/suppress */
1947563SPrasad.Singamsetty@Sun.COM 						/* certain log messages */
195786Slclee } cmlb_lun_t;
196786Slclee 
197786Slclee _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cmlb_tg_ops))
1983525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_devi))
1993525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_removable))
2003525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_hotpluggable))
2013525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_node_type))
2023525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_sys_blocksize))
2033525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_alter_behavior))
204786Slclee _NOTE(SCHEME_PROTECTS_DATA("private data", cmlb_geom))
2053525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("safe sharing", cmlb_lun::cl_f_geometry_is_valid))
2063525Sshidokht 
2077909SXiao.L@Sun.COM _NOTE(MUTEX_PROTECTS_DATA(cmlb_lun::cl_mutex, cmlb_lun::cl_vtoc))
208786Slclee 
209786Slclee 
2103525Sshidokht #define	DK_TG_READ(ihdlp, bufaddr, start_block, reqlength, tg_cookie)\
2113525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_READ, \
2123525Sshidokht 	bufaddr, start_block, reqlength, tg_cookie)
213786Slclee 
2143525Sshidokht #define	DK_TG_WRITE(ihdlp,  bufaddr, start_block, reqlength, tg_cookie)\
2153525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_WRITE,\
2163525Sshidokht 	bufaddr, start_block, reqlength, tg_cookie)
2173525Sshidokht 
2183525Sshidokht #define	DK_TG_GETPHYGEOM(ihdlp, phygeomp, tg_cookie) \
2193525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETPHYGEOM,\
2203525Sshidokht 	    (void *)phygeomp, tg_cookie)
221786Slclee 
2223525Sshidokht #define	DK_TG_GETVIRTGEOM(ihdlp, virtgeomp, tg_cookie) \
2233525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETVIRTGEOM,\
2243525Sshidokht 	    (void *)virtgeomp, tg_cookie)
2253525Sshidokht 
2263525Sshidokht #define	DK_TG_GETCAP(ihdlp, capp, tg_cookie) \
2273525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETCAPACITY,\
2283525Sshidokht 	capp, tg_cookie)
229786Slclee 
2303525Sshidokht #define	DK_TG_GETBLOCKSIZE(ihdlp, lbap, tg_cookie) \
2313525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp),\
2323525Sshidokht 	TG_GETBLOCKSIZE, lbap, tg_cookie)
233786Slclee 
2343525Sshidokht #define	DK_TG_GETATTRIBUTE(ihdlp, attributep, tg_cookie) \
2353525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETATTR,\
2363525Sshidokht 	    attributep, tg_cookie)
237786Slclee 
238786Slclee #ifdef __cplusplus
239786Slclee }
240786Slclee #endif
241786Slclee 
242786Slclee #endif	/* _SYS_CMLB_IMPL_H */
243