xref: /onnv-gate/usr/src/uts/common/sys/cmlb_impl.h (revision 11748:ef9e12e5c5c9)
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*11748SShidokht.Yadegari@Sun.COM  * Copyright 2010 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 
3810021SSheshadri.Vasudevan@Sun.COM /*
3910021SSheshadri.Vasudevan@Sun.COM  * FDISK partitions - 4 primary and MAX_EXT_PARTS number of Extended
4010021SSheshadri.Vasudevan@Sun.COM  * Partitions.
4110021SSheshadri.Vasudevan@Sun.COM  */
4210021SSheshadri.Vasudevan@Sun.COM #define	FDISK_PARTS		(FD_NUMPART + MAX_EXT_PARTS)
4310021SSheshadri.Vasudevan@Sun.COM 
44786Slclee #if defined(_SUNOS_VTOC_8)
45786Slclee #define	NSDMAP			NDKMAP
46786Slclee #elif defined(_SUNOS_VTOC_16)
4710021SSheshadri.Vasudevan@Sun.COM #define	NSDMAP			(NDKMAP + FDISK_PARTS + 1)
48786Slclee #else
49786Slclee #error "No VTOC format defined."
50786Slclee #endif
51786Slclee 
52786Slclee #define	MAXPART			(NSDMAP + 1)
53786Slclee #define	WD_NODE			7
54786Slclee 
55786Slclee 
56786Slclee #if defined(__i386) || defined(__amd64)
57786Slclee 
58786Slclee #define	P0_RAW_DISK		(NDKMAP)
59786Slclee #define	FDISK_P1		(NDKMAP+1)
60786Slclee #define	FDISK_P2		(NDKMAP+2)
61786Slclee #define	FDISK_P3		(NDKMAP+3)
62786Slclee #define	FDISK_P4		(NDKMAP+4)
63786Slclee 
64786Slclee #endif  /* __i386 || __amd64 */
65786Slclee 
66786Slclee /* Driver Logging Levels */
67786Slclee #define	CMLB_LOGMASK_ERROR	0x00000001
68786Slclee #define	CMLB_LOGMASK_INFO	0x00000002
69786Slclee #define	CMLB_LOGMASK_TRACE	0x00000004
70786Slclee 
71786Slclee #define	CMLB_TRACE		0x00000001
72786Slclee #define	CMLB_INFO		0x00000002
73786Slclee #define	CMLB_ERROR		0x00000004
74786Slclee 
75786Slclee 
763525Sshidokht #define	CMLB_MUTEX(cl)		(&((cl)->cl_mutex))
773525Sshidokht #define	CMLB_DEVINFO(cl)	((cl)->cl_devi)
78*11748SShidokht.Yadegari@Sun.COM #define	CMLB_LABEL(cl)		(ddi_driver_name((cl->cl_devi)))
79786Slclee 
80786Slclee 
818863SEdward.Pilatowicz@Sun.COM #define	ISREMOVABLE(cl)		(cl->cl_is_removable)
823525Sshidokht #define	ISCD(cl)		(cl->cl_device_type == DTYPE_RODIRECT)
838863SEdward.Pilatowicz@Sun.COM #define	ISHOTPLUGGABLE(cl)	(cl->cl_is_hotpluggable)
84786Slclee 
85786Slclee #if defined(_SUNOS_VTOC_8)
86786Slclee 
87786Slclee #define	CMLBUNIT_SHIFT		3
88786Slclee #define	CMLBPART_MASK		7
89786Slclee 
90786Slclee #elif defined(_SUNOS_VTOC_16)
91786Slclee 
92786Slclee #define	CMLBUNIT_SHIFT		6
93786Slclee #define	CMLBPART_MASK		63
94786Slclee 
95786Slclee #else
96786Slclee #error "No VTOC format defined."
97786Slclee #endif
98786Slclee 
99786Slclee #define	CMLBUNIT(dev)		(getminor((dev)) >> CMLBUNIT_SHIFT)
100786Slclee #define	CMLBPART(dev)		(getminor((dev)) &  CMLBPART_MASK)
101786Slclee 
102786Slclee /*
103786Slclee  * Return codes of cmlb_uselabel().
104786Slclee  */
105786Slclee #define	CMLB_LABEL_IS_VALID	0
106786Slclee #define	CMLB_LABEL_IS_INVALID	1
107786Slclee 
1087563SPrasad.Singamsetty@Sun.COM #define	CMLB_2TB_BLOCKS		0xffffffff
1097563SPrasad.Singamsetty@Sun.COM #define	CMLB_1TB_BLOCKS		0x7fffffff
1107563SPrasad.Singamsetty@Sun.COM 
1117563SPrasad.Singamsetty@Sun.COM #define	CMLB_EXTVTOC_LIMIT	CMLB_2TB_BLOCKS
1127563SPrasad.Singamsetty@Sun.COM #define	CMLB_OLDVTOC_LIMIT	CMLB_1TB_BLOCKS
1137563SPrasad.Singamsetty@Sun.COM 
114786Slclee /*
115786Slclee  * fdisk partition mapping structure
116786Slclee  */
117786Slclee struct fmap {
1187563SPrasad.Singamsetty@Sun.COM 	ulong_t fmap_start;	/* starting block number */
1197563SPrasad.Singamsetty@Sun.COM 	ulong_t fmap_nblk;	/* number of blocks */
12010021SSheshadri.Vasudevan@Sun.COM 	uchar_t fmap_systid;		/* systid of the partition */
121786Slclee };
122786Slclee 
123786Slclee /* for cm_state */
124786Slclee typedef enum  {
125786Slclee 	CMLB_INITED = 0,
126786Slclee 	CMLB_ATTACHED
127786Slclee } cmlb_state_t;
128786Slclee 
129786Slclee typedef enum
130786Slclee {
131786Slclee 	CMLB_LABEL_UNDEF = 0,
132786Slclee 	CMLB_LABEL_VTOC,
133786Slclee 	CMLB_LABEL_EFI
134786Slclee } cmlb_label_t;
135786Slclee 
1367563SPrasad.Singamsetty@Sun.COM #define	CMLB_ALLOW_2TB_WARN 0x1
1377563SPrasad.Singamsetty@Sun.COM 
138786Slclee 
139786Slclee typedef struct cmlb_lun {
1403525Sshidokht 	dev_info_t	*cl_devi;		/* pointer to devinfo */
1413525Sshidokht 	struct dk_vtoc	cl_vtoc;	/* disk VTOC */
1423525Sshidokht 	struct dk_geom	cl_g;		/* disk geometry */
143786Slclee 
1443525Sshidokht 	diskaddr_t	cl_blockcount;		/* capacity */
1453525Sshidokht 	uint32_t	cl_tgt_blocksize;	/* blocksize */
146786Slclee 
1473525Sshidokht 	diskaddr_t	cl_solaris_size;	/* size of Solaris partition */
1483525Sshidokht 	uint_t		cl_solaris_offset;	/* offset to Solaris part. */
149786Slclee 
1503525Sshidokht 	struct  dk_map  cl_map[MAXPART];	/* logical partitions */
1517563SPrasad.Singamsetty@Sun.COM 						/* cylno is overloaded. used */
1527563SPrasad.Singamsetty@Sun.COM 						/* for starting block for EFI */
1537563SPrasad.Singamsetty@Sun.COM 
1543525Sshidokht 	diskaddr_t	cl_offset[MAXPART];	/* partition start blocks */
155786Slclee 
15610021SSheshadri.Vasudevan@Sun.COM 	struct fmap	cl_fmap[FDISK_PARTS];	/* fdisk partitions */
157786Slclee 
1583525Sshidokht 	uchar_t		cl_asciilabel[LEN_DKL_ASCII];	/* Disk ASCII label */
159786Slclee 
160786Slclee 	/*
161786Slclee 	 * This is the HBAs current notion of the geometry of the drive,
162786Slclee 	 * for HBAs that support the "geometry" property.
163786Slclee 	 */
1643525Sshidokht 	struct cmlb_geom	cl_lgeom;
165786Slclee 
166786Slclee 	/*
167786Slclee 	 * This is the geometry of the device as reported by the MODE SENSE,
168786Slclee 	 * command, Page 3 (Format Device Page) and Page 4 (Rigid Disk Drive
169786Slclee 	 * Geometry Page), assuming MODE SENSE is supported by the target.
170786Slclee 	 */
1713525Sshidokht 	struct cmlb_geom	cl_pgeom;
172786Slclee 
1733525Sshidokht 	ushort_t	cl_dkg_skew;		/* skew */
174786Slclee 
1753525Sshidokht 	cmlb_label_t	cl_def_labeltype;	/* default label type */
176786Slclee 
177786Slclee 	/* label type based on which minor nodes were created last */
1783525Sshidokht 	cmlb_label_t	cl_last_labeltype;
179786Slclee 
1803525Sshidokht 	cmlb_label_t	cl_cur_labeltype;	/* current label type */
181786Slclee 
182786Slclee 	/* indicates whether vtoc label is read from media */
1837563SPrasad.Singamsetty@Sun.COM 	cmlb_label_t		cl_label_from_media;
184786Slclee 
1853525Sshidokht 	cmlb_state_t	cl_state;		/* state of handle */
186786Slclee 
1878863SEdward.Pilatowicz@Sun.COM 	boolean_t	cl_f_geometry_is_valid;
1883525Sshidokht 	int		cl_sys_blocksize;
189786Slclee 
1903525Sshidokht 	kmutex_t	cl_mutex;
191786Slclee 
192786Slclee 	/* the following are passed in at attach time */
1938863SEdward.Pilatowicz@Sun.COM 	boolean_t	cl_is_removable;	/* is removable */
1948863SEdward.Pilatowicz@Sun.COM 	boolean_t	cl_is_hotpluggable;	/* is hotpluggable */
1953525Sshidokht 	int		cl_alter_behavior;
1963525Sshidokht 	char 		*cl_node_type;		/* DDI_NT_... */
1973525Sshidokht 	int		cl_device_type;		/* DTYPE_DIRECT,.. */
1983525Sshidokht 	int		cl_reserved;		/* reserved efi partition # */
199786Slclee 	cmlb_tg_ops_t 	*cmlb_tg_ops;
20010021SSheshadri.Vasudevan@Sun.COM #if defined(__i386) || defined(__amd64)
20110021SSheshadri.Vasudevan@Sun.COM 	/*
20210021SSheshadri.Vasudevan@Sun.COM 	 * Flag indicating whether extended partition nodes should be created
20310021SSheshadri.Vasudevan@Sun.COM 	 * or not. Is set in cmlb_attach. After creating nodes in
20410021SSheshadri.Vasudevan@Sun.COM 	 * cmlb_read_fdisk, it will be unset.
20510021SSheshadri.Vasudevan@Sun.COM 	 */
20610021SSheshadri.Vasudevan@Sun.COM 	int		cl_update_ext_minor_nodes;
20710021SSheshadri.Vasudevan@Sun.COM 	int		cl_logical_drive_count;
20810021SSheshadri.Vasudevan@Sun.COM #endif  /* __i386 || __amd64 */
2097563SPrasad.Singamsetty@Sun.COM 	uint8_t		cl_msglog_flag;		/* used to enable/suppress */
2107563SPrasad.Singamsetty@Sun.COM 						/* certain log messages */
211786Slclee } cmlb_lun_t;
212786Slclee 
213786Slclee _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cmlb_tg_ops))
2143525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_devi))
2153525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_removable))
2163525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_hotpluggable))
2173525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_node_type))
2183525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_sys_blocksize))
2193525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_alter_behavior))
220786Slclee _NOTE(SCHEME_PROTECTS_DATA("private data", cmlb_geom))
2213525Sshidokht _NOTE(SCHEME_PROTECTS_DATA("safe sharing", cmlb_lun::cl_f_geometry_is_valid))
2223525Sshidokht 
2237909SXiao.L@Sun.COM _NOTE(MUTEX_PROTECTS_DATA(cmlb_lun::cl_mutex, cmlb_lun::cl_vtoc))
224786Slclee 
225786Slclee 
2263525Sshidokht #define	DK_TG_READ(ihdlp, bufaddr, start_block, reqlength, tg_cookie)\
2273525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_READ, \
2283525Sshidokht 	bufaddr, start_block, reqlength, tg_cookie)
229786Slclee 
2303525Sshidokht #define	DK_TG_WRITE(ihdlp,  bufaddr, start_block, reqlength, tg_cookie)\
2313525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_WRITE,\
2323525Sshidokht 	bufaddr, start_block, reqlength, tg_cookie)
2333525Sshidokht 
2343525Sshidokht #define	DK_TG_GETPHYGEOM(ihdlp, phygeomp, tg_cookie) \
2353525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETPHYGEOM,\
2363525Sshidokht 	    (void *)phygeomp, tg_cookie)
237786Slclee 
2383525Sshidokht #define	DK_TG_GETVIRTGEOM(ihdlp, virtgeomp, tg_cookie) \
2393525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETVIRTGEOM,\
2403525Sshidokht 	    (void *)virtgeomp, tg_cookie)
2413525Sshidokht 
2423525Sshidokht #define	DK_TG_GETCAP(ihdlp, capp, tg_cookie) \
2433525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETCAPACITY,\
2443525Sshidokht 	capp, tg_cookie)
245786Slclee 
2463525Sshidokht #define	DK_TG_GETBLOCKSIZE(ihdlp, lbap, tg_cookie) \
2473525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp),\
2483525Sshidokht 	TG_GETBLOCKSIZE, lbap, tg_cookie)
249786Slclee 
2503525Sshidokht #define	DK_TG_GETATTRIBUTE(ihdlp, attributep, tg_cookie) \
2513525Sshidokht 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETATTR,\
2523525Sshidokht 	    attributep, tg_cookie)
253786Slclee 
254786Slclee #ifdef __cplusplus
255786Slclee }
256786Slclee #endif
257786Slclee 
258786Slclee #endif	/* _SYS_CMLB_IMPL_H */
259