xref: /titanic_44/usr/src/uts/common/sys/cmlb_impl.h (revision 24fe0b3bf671e123467ce1df0b67cadd3614c8e4)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_CMLB_IMPL_H
28 #define	_SYS_CMLB_IMPL_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/cmlb.h>
35 #include <sys/ddi.h>
36 #include <sys/sunddi.h>
37 
38 /*
39  * FDISK partitions - 4 primary and MAX_EXT_PARTS number of Extended
40  * Partitions.
41  */
42 #define	FDISK_PARTS		(FD_NUMPART + MAX_EXT_PARTS)
43 
44 #if defined(_SUNOS_VTOC_8)
45 #define	NSDMAP			NDKMAP
46 #elif defined(_SUNOS_VTOC_16)
47 #define	NSDMAP			(NDKMAP + FDISK_PARTS + 1)
48 #else
49 #error "No VTOC format defined."
50 #endif
51 
52 #define	MAXPART			(NSDMAP + 1)
53 #define	WD_NODE			7
54 
55 
56 #if defined(__i386) || defined(__amd64)
57 
58 #define	P0_RAW_DISK		(NDKMAP)
59 #define	FDISK_P1		(NDKMAP+1)
60 #define	FDISK_P2		(NDKMAP+2)
61 #define	FDISK_P3		(NDKMAP+3)
62 #define	FDISK_P4		(NDKMAP+4)
63 
64 #endif  /* __i386 || __amd64 */
65 
66 /* Driver Logging Levels */
67 #define	CMLB_LOGMASK_ERROR	0x00000001
68 #define	CMLB_LOGMASK_INFO	0x00000002
69 #define	CMLB_LOGMASK_TRACE	0x00000004
70 
71 #define	CMLB_TRACE		0x00000001
72 #define	CMLB_INFO		0x00000002
73 #define	CMLB_ERROR		0x00000004
74 
75 
76 #define	CMLB_MUTEX(cl)		(&((cl)->cl_mutex))
77 #define	CMLB_DEVINFO(cl)	((cl)->cl_devi)
78 #define	CMLB_LABEL(cl)		(DEVI(((cl)->cl_devi))->devi_binding_name)
79 
80 
81 #define	ISREMOVABLE(cl)		(cl->cl_is_removable)
82 #define	ISCD(cl)		(cl->cl_device_type == DTYPE_RODIRECT)
83 #define	ISHOTPLUGGABLE(cl)	(cl->cl_is_hotpluggable)
84 
85 #if defined(_SUNOS_VTOC_8)
86 
87 #define	CMLBUNIT_SHIFT		3
88 #define	CMLBPART_MASK		7
89 
90 #elif defined(_SUNOS_VTOC_16)
91 
92 #define	CMLBUNIT_SHIFT		6
93 #define	CMLBPART_MASK		63
94 
95 #else
96 #error "No VTOC format defined."
97 #endif
98 
99 #define	CMLBUNIT(dev)		(getminor((dev)) >> CMLBUNIT_SHIFT)
100 #define	CMLBPART(dev)		(getminor((dev)) &  CMLBPART_MASK)
101 
102 /*
103  * Return codes of cmlb_uselabel().
104  */
105 #define	CMLB_LABEL_IS_VALID	0
106 #define	CMLB_LABEL_IS_INVALID	1
107 
108 #define	CMLB_2TB_BLOCKS		0xffffffff
109 #define	CMLB_1TB_BLOCKS		0x7fffffff
110 
111 #define	CMLB_EXTVTOC_LIMIT	CMLB_2TB_BLOCKS
112 #define	CMLB_OLDVTOC_LIMIT	CMLB_1TB_BLOCKS
113 
114 /*
115  * fdisk partition mapping structure
116  */
117 struct fmap {
118 	ulong_t fmap_start;	/* starting block number */
119 	ulong_t fmap_nblk;	/* number of blocks */
120 	uchar_t fmap_systid;		/* systid of the partition */
121 };
122 
123 /* for cm_state */
124 typedef enum  {
125 	CMLB_INITED = 0,
126 	CMLB_ATTACHED
127 } cmlb_state_t;
128 
129 typedef enum
130 {
131 	CMLB_LABEL_UNDEF = 0,
132 	CMLB_LABEL_VTOC,
133 	CMLB_LABEL_EFI
134 } cmlb_label_t;
135 
136 #define	CMLB_ALLOW_2TB_WARN 0x1
137 
138 
139 typedef struct cmlb_lun {
140 	dev_info_t	*cl_devi;		/* pointer to devinfo */
141 	struct dk_vtoc	cl_vtoc;	/* disk VTOC */
142 	struct dk_geom	cl_g;		/* disk geometry */
143 
144 	diskaddr_t	cl_blockcount;		/* capacity */
145 	uint32_t	cl_tgt_blocksize;	/* blocksize */
146 
147 	diskaddr_t	cl_solaris_size;	/* size of Solaris partition */
148 	uint_t		cl_solaris_offset;	/* offset to Solaris part. */
149 
150 	struct  dk_map  cl_map[MAXPART];	/* logical partitions */
151 						/* cylno is overloaded. used */
152 						/* for starting block for EFI */
153 
154 	diskaddr_t	cl_offset[MAXPART];	/* partition start blocks */
155 
156 	struct fmap	cl_fmap[FDISK_PARTS];	/* fdisk partitions */
157 
158 	uchar_t		cl_asciilabel[LEN_DKL_ASCII];	/* Disk ASCII label */
159 
160 	/*
161 	 * This is the HBAs current notion of the geometry of the drive,
162 	 * for HBAs that support the "geometry" property.
163 	 */
164 	struct cmlb_geom	cl_lgeom;
165 
166 	/*
167 	 * This is the geometry of the device as reported by the MODE SENSE,
168 	 * command, Page 3 (Format Device Page) and Page 4 (Rigid Disk Drive
169 	 * Geometry Page), assuming MODE SENSE is supported by the target.
170 	 */
171 	struct cmlb_geom	cl_pgeom;
172 
173 	ushort_t	cl_dkg_skew;		/* skew */
174 
175 	cmlb_label_t	cl_def_labeltype;	/* default label type */
176 
177 	/* label type based on which minor nodes were created last */
178 	cmlb_label_t	cl_last_labeltype;
179 
180 	cmlb_label_t	cl_cur_labeltype;	/* current label type */
181 
182 	/* indicates whether vtoc label is read from media */
183 	cmlb_label_t		cl_label_from_media;
184 
185 	cmlb_state_t	cl_state;		/* state of handle */
186 
187 	boolean_t	cl_f_geometry_is_valid;
188 	int		cl_sys_blocksize;
189 
190 	kmutex_t	cl_mutex;
191 
192 	/* the following are passed in at attach time */
193 	boolean_t	cl_is_removable;	/* is removable */
194 	boolean_t	cl_is_hotpluggable;	/* is hotpluggable */
195 	int		cl_alter_behavior;
196 	char 		*cl_node_type;		/* DDI_NT_... */
197 	int		cl_device_type;		/* DTYPE_DIRECT,.. */
198 	int		cl_reserved;		/* reserved efi partition # */
199 	cmlb_tg_ops_t 	*cmlb_tg_ops;
200 #if defined(__i386) || defined(__amd64)
201 	/*
202 	 * Flag indicating whether extended partition nodes should be created
203 	 * or not. Is set in cmlb_attach. After creating nodes in
204 	 * cmlb_read_fdisk, it will be unset.
205 	 */
206 	int		cl_update_ext_minor_nodes;
207 	int		cl_logical_drive_count;
208 #endif  /* __i386 || __amd64 */
209 	uint8_t		cl_msglog_flag;		/* used to enable/suppress */
210 						/* certain log messages */
211 } cmlb_lun_t;
212 
213 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cmlb_tg_ops))
214 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_devi))
215 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_removable))
216 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_hotpluggable))
217 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_node_type))
218 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_sys_blocksize))
219 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_alter_behavior))
220 _NOTE(SCHEME_PROTECTS_DATA("private data", cmlb_geom))
221 _NOTE(SCHEME_PROTECTS_DATA("safe sharing", cmlb_lun::cl_f_geometry_is_valid))
222 
223 _NOTE(MUTEX_PROTECTS_DATA(cmlb_lun::cl_mutex, cmlb_lun::cl_vtoc))
224 
225 
226 #define	DK_TG_READ(ihdlp, bufaddr, start_block, reqlength, tg_cookie)\
227 	(ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_READ, \
228 	bufaddr, start_block, reqlength, tg_cookie)
229 
230 #define	DK_TG_WRITE(ihdlp,  bufaddr, start_block, reqlength, tg_cookie)\
231 	(ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_WRITE,\
232 	bufaddr, start_block, reqlength, tg_cookie)
233 
234 #define	DK_TG_GETPHYGEOM(ihdlp, phygeomp, tg_cookie) \
235 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETPHYGEOM,\
236 	    (void *)phygeomp, tg_cookie)
237 
238 #define	DK_TG_GETVIRTGEOM(ihdlp, virtgeomp, tg_cookie) \
239 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETVIRTGEOM,\
240 	    (void *)virtgeomp, tg_cookie)
241 
242 #define	DK_TG_GETCAP(ihdlp, capp, tg_cookie) \
243 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETCAPACITY,\
244 	capp, tg_cookie)
245 
246 #define	DK_TG_GETBLOCKSIZE(ihdlp, lbap, tg_cookie) \
247 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp),\
248 	TG_GETBLOCKSIZE, lbap, tg_cookie)
249 
250 #define	DK_TG_GETATTRIBUTE(ihdlp, attributep, tg_cookie) \
251 	(ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETATTR,\
252 	    attributep, tg_cookie)
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif	/* _SYS_CMLB_IMPL_H */
259