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