13ccda647Slclee /* 23ccda647Slclee * CDDL HEADER START 33ccda647Slclee * 43ccda647Slclee * The contents of this file are subject to the terms of the 5e8fb11a1Sshidokht * Common Development and Distribution License (the "License"). 6e8fb11a1Sshidokht * You may not use this file except in compliance with the License. 73ccda647Slclee * 83ccda647Slclee * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93ccda647Slclee * or http://www.opensolaris.org/os/licensing. 103ccda647Slclee * See the License for the specific language governing permissions 113ccda647Slclee * and limitations under the License. 123ccda647Slclee * 133ccda647Slclee * When distributing Covered Code, include this CDDL HEADER in each 143ccda647Slclee * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153ccda647Slclee * If applicable, add the following below this CDDL HEADER, with the 163ccda647Slclee * fields enclosed by brackets "[]" replaced with your own identifying 173ccda647Slclee * information: Portions Copyright [yyyy] [name of copyright owner] 183ccda647Slclee * 193ccda647Slclee * CDDL HEADER END 203ccda647Slclee */ 21342440ecSPrasad Singamsetty 223ccda647Slclee /* 23*a29e56d9SToomas Soome * Copyright 2016 Toomas Soome <tsoome@me.com> 24c31fac72SShidokht Yadegari * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 253ccda647Slclee * Use is subject to license terms. 263ccda647Slclee */ 273ccda647Slclee 283ccda647Slclee #ifndef _SYS_CMLB_IMPL_H 293ccda647Slclee #define _SYS_CMLB_IMPL_H 303ccda647Slclee 313ccda647Slclee #ifdef __cplusplus 323ccda647Slclee extern "C" { 333ccda647Slclee #endif 343ccda647Slclee 353ccda647Slclee #include <sys/cmlb.h> 363ccda647Slclee #include <sys/ddi.h> 373ccda647Slclee #include <sys/sunddi.h> 383ccda647Slclee 39aa1b14e7SSheshadri Vasudevan /* 40aa1b14e7SSheshadri Vasudevan * FDISK partitions - 4 primary and MAX_EXT_PARTS number of Extended 41aa1b14e7SSheshadri Vasudevan * Partitions. 42aa1b14e7SSheshadri Vasudevan */ 43aa1b14e7SSheshadri Vasudevan #define FDISK_PARTS (FD_NUMPART + MAX_EXT_PARTS) 44aa1b14e7SSheshadri Vasudevan 453ccda647Slclee #if defined(_SUNOS_VTOC_8) 46*a29e56d9SToomas Soome /* 47*a29e56d9SToomas Soome * As lofi needs to support p0 on sparc in case of labeled virtual disks, 48*a29e56d9SToomas Soome * define NDSMAP to support one extra entrie. 49*a29e56d9SToomas Soome */ 50*a29e56d9SToomas Soome #define NSDMAP (NDKMAP + 1) 513ccda647Slclee #elif defined(_SUNOS_VTOC_16) 52aa1b14e7SSheshadri Vasudevan #define NSDMAP (NDKMAP + FDISK_PARTS + 1) 533ccda647Slclee #else 543ccda647Slclee #error "No VTOC format defined." 553ccda647Slclee #endif 563ccda647Slclee 573ccda647Slclee #define MAXPART (NSDMAP + 1) 583ccda647Slclee #define WD_NODE 7 59*a29e56d9SToomas Soome #define P0_RAW_DISK (NDKMAP) 603ccda647Slclee 613ccda647Slclee #if defined(__i386) || defined(__amd64) 623ccda647Slclee 633ccda647Slclee #define FDISK_P1 (NDKMAP+1) 643ccda647Slclee #define FDISK_P2 (NDKMAP+2) 653ccda647Slclee #define FDISK_P3 (NDKMAP+3) 663ccda647Slclee #define FDISK_P4 (NDKMAP+4) 673ccda647Slclee 683ccda647Slclee #endif /* __i386 || __amd64 */ 693ccda647Slclee 703ccda647Slclee /* Driver Logging Levels */ 713ccda647Slclee #define CMLB_LOGMASK_ERROR 0x00000001 723ccda647Slclee #define CMLB_LOGMASK_INFO 0x00000002 733ccda647Slclee #define CMLB_LOGMASK_TRACE 0x00000004 743ccda647Slclee 753ccda647Slclee #define CMLB_TRACE 0x00000001 763ccda647Slclee #define CMLB_INFO 0x00000002 773ccda647Slclee #define CMLB_ERROR 0x00000004 783ccda647Slclee 793ccda647Slclee 80e8fb11a1Sshidokht #define CMLB_MUTEX(cl) (&((cl)->cl_mutex)) 81e8fb11a1Sshidokht #define CMLB_DEVINFO(cl) ((cl)->cl_devi) 82c31fac72SShidokht Yadegari #define CMLB_LABEL(cl) (ddi_driver_name((cl->cl_devi))) 833ccda647Slclee 843ccda647Slclee 857f0b8309SEdward Pilatowicz #define ISREMOVABLE(cl) (cl->cl_is_removable) 86e8fb11a1Sshidokht #define ISCD(cl) (cl->cl_device_type == DTYPE_RODIRECT) 877f0b8309SEdward Pilatowicz #define ISHOTPLUGGABLE(cl) (cl->cl_is_hotpluggable) 883ccda647Slclee 89*a29e56d9SToomas Soome #define CMLBUNIT_SHIFT (CMLBUNIT_DFT_SHIFT) 90*a29e56d9SToomas Soome #define CMLBPART_MASK ((1 << CMLBUNIT_SHIFT) - 1) 913ccda647Slclee 92*a29e56d9SToomas Soome #define CMLBUNIT(dev, shift) (getminor((dev)) >> (shift)) 933ccda647Slclee #define CMLBPART(dev) (getminor((dev)) & CMLBPART_MASK) 943ccda647Slclee 953ccda647Slclee /* 963ccda647Slclee * Return codes of cmlb_uselabel(). 973ccda647Slclee */ 983ccda647Slclee #define CMLB_LABEL_IS_VALID 0 993ccda647Slclee #define CMLB_LABEL_IS_INVALID 1 1003ccda647Slclee 101342440ecSPrasad Singamsetty #define CMLB_2TB_BLOCKS 0xffffffff 102342440ecSPrasad Singamsetty #define CMLB_1TB_BLOCKS 0x7fffffff 103342440ecSPrasad Singamsetty 104342440ecSPrasad Singamsetty #define CMLB_EXTVTOC_LIMIT CMLB_2TB_BLOCKS 105342440ecSPrasad Singamsetty #define CMLB_OLDVTOC_LIMIT CMLB_1TB_BLOCKS 106342440ecSPrasad Singamsetty 1073ccda647Slclee /* 1083ccda647Slclee * fdisk partition mapping structure 1093ccda647Slclee */ 1103ccda647Slclee struct fmap { 111342440ecSPrasad Singamsetty ulong_t fmap_start; /* starting block number */ 112342440ecSPrasad Singamsetty ulong_t fmap_nblk; /* number of blocks */ 113aa1b14e7SSheshadri Vasudevan uchar_t fmap_systid; /* systid of the partition */ 1143ccda647Slclee }; 1153ccda647Slclee 1163ccda647Slclee /* for cm_state */ 1173ccda647Slclee typedef enum { 1183ccda647Slclee CMLB_INITED = 0, 1193ccda647Slclee CMLB_ATTACHED 1203ccda647Slclee } cmlb_state_t; 1213ccda647Slclee 1223ccda647Slclee typedef enum 1233ccda647Slclee { 1243ccda647Slclee CMLB_LABEL_UNDEF = 0, 1253ccda647Slclee CMLB_LABEL_VTOC, 1263ccda647Slclee CMLB_LABEL_EFI 1273ccda647Slclee } cmlb_label_t; 1283ccda647Slclee 129342440ecSPrasad Singamsetty #define CMLB_ALLOW_2TB_WARN 0x1 130342440ecSPrasad Singamsetty 1313ccda647Slclee 1323ccda647Slclee typedef struct cmlb_lun { 133e8fb11a1Sshidokht dev_info_t *cl_devi; /* pointer to devinfo */ 134e8fb11a1Sshidokht struct dk_vtoc cl_vtoc; /* disk VTOC */ 135e8fb11a1Sshidokht struct dk_geom cl_g; /* disk geometry */ 1363ccda647Slclee 137e8fb11a1Sshidokht diskaddr_t cl_blockcount; /* capacity */ 138e8fb11a1Sshidokht uint32_t cl_tgt_blocksize; /* blocksize */ 1393ccda647Slclee 140e8fb11a1Sshidokht diskaddr_t cl_solaris_size; /* size of Solaris partition */ 141e8fb11a1Sshidokht uint_t cl_solaris_offset; /* offset to Solaris part. */ 1423ccda647Slclee 143e8fb11a1Sshidokht struct dk_map cl_map[MAXPART]; /* logical partitions */ 144342440ecSPrasad Singamsetty /* cylno is overloaded. used */ 145342440ecSPrasad Singamsetty /* for starting block for EFI */ 146342440ecSPrasad Singamsetty 147e8fb11a1Sshidokht diskaddr_t cl_offset[MAXPART]; /* partition start blocks */ 1483ccda647Slclee 149aa1b14e7SSheshadri Vasudevan struct fmap cl_fmap[FDISK_PARTS]; /* fdisk partitions */ 1503ccda647Slclee 151e8fb11a1Sshidokht uchar_t cl_asciilabel[LEN_DKL_ASCII]; /* Disk ASCII label */ 1523ccda647Slclee 1533ccda647Slclee /* 1543ccda647Slclee * This is the HBAs current notion of the geometry of the drive, 1553ccda647Slclee * for HBAs that support the "geometry" property. 1563ccda647Slclee */ 157e8fb11a1Sshidokht struct cmlb_geom cl_lgeom; 1583ccda647Slclee 1593ccda647Slclee /* 1603ccda647Slclee * This is the geometry of the device as reported by the MODE SENSE, 1613ccda647Slclee * command, Page 3 (Format Device Page) and Page 4 (Rigid Disk Drive 1623ccda647Slclee * Geometry Page), assuming MODE SENSE is supported by the target. 1633ccda647Slclee */ 164e8fb11a1Sshidokht struct cmlb_geom cl_pgeom; 1653ccda647Slclee 166e8fb11a1Sshidokht ushort_t cl_dkg_skew; /* skew */ 1673ccda647Slclee 168e8fb11a1Sshidokht cmlb_label_t cl_def_labeltype; /* default label type */ 1693ccda647Slclee 1703ccda647Slclee /* label type based on which minor nodes were created last */ 171e8fb11a1Sshidokht cmlb_label_t cl_last_labeltype; 1723ccda647Slclee 173e8fb11a1Sshidokht cmlb_label_t cl_cur_labeltype; /* current label type */ 1743ccda647Slclee 1753ccda647Slclee /* indicates whether vtoc label is read from media */ 176342440ecSPrasad Singamsetty cmlb_label_t cl_label_from_media; 1773ccda647Slclee 178e8fb11a1Sshidokht cmlb_state_t cl_state; /* state of handle */ 1793ccda647Slclee 1807f0b8309SEdward Pilatowicz boolean_t cl_f_geometry_is_valid; 181e8fb11a1Sshidokht int cl_sys_blocksize; 1823ccda647Slclee 183e8fb11a1Sshidokht kmutex_t cl_mutex; 1843ccda647Slclee 1853ccda647Slclee /* the following are passed in at attach time */ 1867f0b8309SEdward Pilatowicz boolean_t cl_is_removable; /* is removable */ 1877f0b8309SEdward Pilatowicz boolean_t cl_is_hotpluggable; /* is hotpluggable */ 188e8fb11a1Sshidokht int cl_alter_behavior; 189e8fb11a1Sshidokht char *cl_node_type; /* DDI_NT_... */ 190e8fb11a1Sshidokht int cl_device_type; /* DTYPE_DIRECT,.. */ 191e8fb11a1Sshidokht int cl_reserved; /* reserved efi partition # */ 1923ccda647Slclee cmlb_tg_ops_t *cmlb_tg_ops; 193aa1b14e7SSheshadri Vasudevan #if defined(__i386) || defined(__amd64) 194aa1b14e7SSheshadri Vasudevan /* 195aa1b14e7SSheshadri Vasudevan * Flag indicating whether extended partition nodes should be created 196aa1b14e7SSheshadri Vasudevan * or not. Is set in cmlb_attach. After creating nodes in 197aa1b14e7SSheshadri Vasudevan * cmlb_read_fdisk, it will be unset. 198aa1b14e7SSheshadri Vasudevan */ 199aa1b14e7SSheshadri Vasudevan int cl_update_ext_minor_nodes; 200aa1b14e7SSheshadri Vasudevan int cl_logical_drive_count; 201aa1b14e7SSheshadri Vasudevan #endif /* __i386 || __amd64 */ 202342440ecSPrasad Singamsetty uint8_t cl_msglog_flag; /* used to enable/suppress */ 203342440ecSPrasad Singamsetty /* certain log messages */ 2043ccda647Slclee } cmlb_lun_t; 2053ccda647Slclee 2063ccda647Slclee _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cmlb_tg_ops)) 207e8fb11a1Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_devi)) 208e8fb11a1Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_removable)) 209e8fb11a1Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_is_hotpluggable)) 210e8fb11a1Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_node_type)) 211e8fb11a1Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_sys_blocksize)) 212e8fb11a1Sshidokht _NOTE(SCHEME_PROTECTS_DATA("stable data", cmlb_lun::cl_alter_behavior)) 2133ccda647Slclee _NOTE(SCHEME_PROTECTS_DATA("private data", cmlb_geom)) 214e8fb11a1Sshidokht _NOTE(SCHEME_PROTECTS_DATA("safe sharing", cmlb_lun::cl_f_geometry_is_valid)) 2153ccda647Slclee 2161fad2c0eSXiao Raymond Li _NOTE(MUTEX_PROTECTS_DATA(cmlb_lun::cl_mutex, cmlb_lun::cl_vtoc)) 2173ccda647Slclee 2183ccda647Slclee 219e8fb11a1Sshidokht #define DK_TG_READ(ihdlp, bufaddr, start_block, reqlength, tg_cookie)\ 220e8fb11a1Sshidokht (ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_READ, \ 221e8fb11a1Sshidokht bufaddr, start_block, reqlength, tg_cookie) 2223ccda647Slclee 223e8fb11a1Sshidokht #define DK_TG_WRITE(ihdlp, bufaddr, start_block, reqlength, tg_cookie)\ 224e8fb11a1Sshidokht (ihdlp->cmlb_tg_ops->tg_rdwr)(CMLB_DEVINFO(ihdlp), TG_WRITE,\ 225e8fb11a1Sshidokht bufaddr, start_block, reqlength, tg_cookie) 2263ccda647Slclee 227e8fb11a1Sshidokht #define DK_TG_GETPHYGEOM(ihdlp, phygeomp, tg_cookie) \ 228e8fb11a1Sshidokht (ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETPHYGEOM,\ 229e8fb11a1Sshidokht (void *)phygeomp, tg_cookie) 2303ccda647Slclee 231e8fb11a1Sshidokht #define DK_TG_GETVIRTGEOM(ihdlp, virtgeomp, tg_cookie) \ 232e8fb11a1Sshidokht (ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETVIRTGEOM,\ 233e8fb11a1Sshidokht (void *)virtgeomp, tg_cookie) 2343ccda647Slclee 235e8fb11a1Sshidokht #define DK_TG_GETCAP(ihdlp, capp, tg_cookie) \ 236e8fb11a1Sshidokht (ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETCAPACITY,\ 237e8fb11a1Sshidokht capp, tg_cookie) 238e8fb11a1Sshidokht 239e8fb11a1Sshidokht #define DK_TG_GETBLOCKSIZE(ihdlp, lbap, tg_cookie) \ 240e8fb11a1Sshidokht (ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp),\ 241e8fb11a1Sshidokht TG_GETBLOCKSIZE, lbap, tg_cookie) 242e8fb11a1Sshidokht 243e8fb11a1Sshidokht #define DK_TG_GETATTRIBUTE(ihdlp, attributep, tg_cookie) \ 244e8fb11a1Sshidokht (ihdlp->cmlb_tg_ops->tg_getinfo)(CMLB_DEVINFO(ihdlp), TG_GETATTR,\ 245e8fb11a1Sshidokht attributep, tg_cookie) 2463ccda647Slclee 2473ccda647Slclee #ifdef __cplusplus 2483ccda647Slclee } 2493ccda647Slclee #endif 2503ccda647Slclee 2513ccda647Slclee #endif /* _SYS_CMLB_IMPL_H */ 252