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