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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 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 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <sys/cmlb.h> 37 #include <sys/ddi.h> 38 #include <sys/sunddi.h> 39 40 #if defined(_SUNOS_VTOC_8) 41 #define NSDMAP NDKMAP 42 #elif defined(_SUNOS_VTOC_16) 43 #define NSDMAP (NDKMAP + FD_NUMPART + 1) 44 #else 45 #error "No VTOC format defined." 46 #endif 47 48 #define MAXPART (NSDMAP + 1) 49 #define WD_NODE 7 50 51 52 #if defined(__i386) || defined(__amd64) 53 54 #define P0_RAW_DISK (NDKMAP) 55 #define FDISK_P1 (NDKMAP+1) 56 #define FDISK_P2 (NDKMAP+2) 57 #define FDISK_P3 (NDKMAP+3) 58 #define FDISK_P4 (NDKMAP+4) 59 60 #endif /* __i386 || __amd64 */ 61 62 /* Driver Logging Levels */ 63 #define CMLB_LOGMASK_ERROR 0x00000001 64 #define CMLB_LOGMASK_INFO 0x00000002 65 #define CMLB_LOGMASK_TRACE 0x00000004 66 67 #define CMLB_TRACE 0x00000001 68 #define CMLB_INFO 0x00000002 69 #define CMLB_ERROR 0x00000004 70 71 72 #define CMLB_MUTEX(un) (&((un)->un_mutex)) 73 #define CMLB_DEVINFO(un) ((un)->un_devi) 74 #define CMLB_LABEL(un) (DEVI(((un)->un_devi))->devi_binding_name) 75 76 77 #define ISREMOVABLE(un) (un->un_is_removable == 1) 78 #define ISCD(un) (un->un_device_type == DTYPE_RODIRECT) 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 *un_devi; /* pointer to devinfo */ 131 struct dk_vtoc un_vtoc; /* disk VTOC */ 132 struct dk_geom un_g; /* disk geometry */ 133 134 diskaddr_t un_blockcount; /* capacity */ 135 136 diskaddr_t un_solaris_size; /* size of Solaris partition */ 137 uint_t un_solaris_offset; /* offset to Solaris part. */ 138 139 struct dk_map un_map[MAXPART]; /* logical partitions */ 140 diskaddr_t un_offset[MAXPART]; /* partition start blocks */ 141 142 struct fmap un_fmap[FD_NUMPART]; /* fdisk partitions */ 143 144 uchar_t un_asciilabel[LEN_DKL_ASCII]; /* Disk ASCII label */ 145 146 /* 147 * This is the HBAs current notion of the geometry of the drive, 148 * for HBAs that support the "geometry" property. 149 */ 150 struct cmlb_geom un_lgeom; 151 152 /* 153 * This is the geometry of the device as reported by the MODE SENSE, 154 * command, Page 3 (Format Device Page) and Page 4 (Rigid Disk Drive 155 * Geometry Page), assuming MODE SENSE is supported by the target. 156 */ 157 struct cmlb_geom un_pgeom; 158 159 ushort_t un_dkg_skew; /* skew */ 160 161 cmlb_label_t un_def_labeltype; /* default label type */ 162 163 /* label type based on which minor nodes were created last */ 164 cmlb_label_t un_last_labeltype; 165 166 cmlb_label_t un_cur_labeltype; /* current label type */ 167 168 /* indicates whether vtoc label is read from media */ 169 uchar_t un_vtoc_label_is_from_media; 170 171 cmlb_state_t un_state; /* state of handle */ 172 173 int un_f_geometry_is_valid; 174 int un_sys_blocksize; 175 176 kmutex_t un_mutex; 177 178 /* the following are passed in at attach time */ 179 int un_is_removable; /* 1 is removable */ 180 181 int un_alter_behavior; 182 char *un_node_type; /* DDI_NT_... */ 183 int un_device_type; /* DTYPE_DIRECT,.. */ 184 cmlb_tg_ops_t *cmlb_tg_ops; 185 186 187 } cmlb_lun_t; 188 189 _NOTE(MUTEX_PROTECTS_DATA(cmlb_lun::un_mutex, cmlb_lun)) 190 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cmlb_tg_ops)) 191 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::un_devi)) 192 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::un_is_removable)) 193 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::un_node_type)) 194 _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::un_sys_blocksize)) 195 _NOTE(SCHEME_PROTECTS_DATA("private data", cmlb_geom)) 196 197 198 #define DK_TG_READ(ihdlp, bufaddr, start_block, reqlength)\ 199 (ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_READ, bufaddr,\ 200 start_block, reqlength) 201 202 #define DK_TG_WRITE(ihdlp, bufaddr, start_block, reqlength)\ 203 (ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_WRITE, bufaddr,\ 204 start_block, reqlength) 205 206 #define DK_TG_GETPHYGEOM(ihdlp, phygeomp) \ 207 (ihdlp->cmlb_tg_ops->tg_getphygeom)(CMLB_DEVINFO(ihdlp), \ 208 (cmlb_geom_t *)phygeomp) 209 210 #define DK_TG_GETVIRTGEOM(ihdlp, virtgeomp) \ 211 (ihdlp->cmlb_tg_ops->tg_getvirtgeom)(CMLB_DEVINFO(ihdlp),\ 212 (cmlb_geom_t *)virtgeomp) 213 214 #define DK_TG_GETCAP(ihdlp, capp) \ 215 (ihdlp->cmlb_tg_ops->tg_getcapacity)(CMLB_DEVINFO(ihdlp), capp) 216 217 #define DK_TG_GETATTRIBUTE(ihdlp, attributep) \ 218 (ihdlp->cmlb_tg_ops->tg_getattribute)(CMLB_DEVINFO(ihdlp), \ 219 attributep) 220 221 #ifdef __cplusplus 222 } 223 #endif 224 225 #endif /* _SYS_CMLB_IMPL_H */ 226