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