1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * https://opensource.org/license/CDDL-1.0. 11 */ 12 /* 13 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 14 * Use is subject to license terms. 15 */ 16 17 #ifndef _SYS_DKIO_H 18 #define _SYS_DKIO_H 19 20 21 22 #include <sys/dklabel.h> /* Needed for NDKMAP define */ 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* 29 * Structures and definitions for disk io control commands 30 */ 31 32 /* 33 * Structures used as data by ioctl calls. 34 */ 35 36 #define DK_DEVLEN 16 /* device name max length, including */ 37 /* unit # & NULL (ie - "xyc1") */ 38 39 /* 40 * Used for controller info 41 */ 42 struct dk_cinfo { 43 char dki_cname[DK_DEVLEN]; /* controller name (no unit #) */ 44 ushort_t dki_ctype; /* controller type */ 45 ushort_t dki_flags; /* flags */ 46 ushort_t dki_cnum; /* controller number */ 47 uint_t dki_addr; /* controller address */ 48 uint_t dki_space; /* controller bus type */ 49 uint_t dki_prio; /* interrupt priority */ 50 uint_t dki_vec; /* interrupt vector */ 51 char dki_dname[DK_DEVLEN]; /* drive name (no unit #) */ 52 uint_t dki_unit; /* unit number */ 53 ushort_t dki_partition; /* partition number */ 54 ushort_t dki_maxtransfer; /* max. transfer size in DEV_BSIZE */ 55 }; 56 57 /* 58 * Controller types 59 */ 60 #define DKC_UNKNOWN 0 61 #define DKC_CDROM 1 /* CD-ROM, SCSI or otherwise */ 62 #define DKC_WDC2880 2 63 #define DKC_XXX_0 3 /* unassigned */ 64 #define DKC_XXX_1 4 /* unassigned */ 65 #define DKC_DSD5215 5 66 #define DKC_ACB4000 7 67 #define DKC_MD21 8 68 #define DKC_XXX_2 9 /* unassigned */ 69 #define DKC_NCRFLOPPY 10 70 #define DKC_SMSFLOPPY 12 71 #define DKC_SCSI_CCS 13 /* SCSI CCS compatible */ 72 #define DKC_INTEL82072 14 /* native floppy chip */ 73 #define DKC_MD 16 /* meta-disk (virtual-disk) driver */ 74 #define DKC_INTEL82077 19 /* 82077 floppy disk controller */ 75 #define DKC_DIRECT 20 /* Intel direct attached device i.e. IDE */ 76 #define DKC_PCMCIA_MEM 21 /* PCMCIA memory disk-like type */ 77 #define DKC_PCMCIA_ATA 22 /* PCMCIA AT Attached type */ 78 #define DKC_VBD 23 /* virtual block device */ 79 80 /* 81 * Sun reserves up through 1023 82 */ 83 84 #define DKC_CUSTOMER_BASE 1024 85 86 /* 87 * Flags 88 */ 89 #define DKI_BAD144 0x01 /* use DEC std 144 bad sector fwding */ 90 #define DKI_MAPTRK 0x02 /* controller does track mapping */ 91 #define DKI_FMTTRK 0x04 /* formats only full track at a time */ 92 #define DKI_FMTVOL 0x08 /* formats only full volume at a time */ 93 #define DKI_FMTCYL 0x10 /* formats only full cylinders at a time */ 94 #define DKI_HEXUNIT 0x20 /* unit number is printed as 3 hex digits */ 95 #define DKI_PCMCIA_PFD 0x40 /* PCMCIA pseudo-floppy memory card */ 96 97 /* 98 * Used for all partitions 99 */ 100 struct dk_allmap { 101 struct dk_map dka_map[NDKMAP]; 102 }; 103 104 #if defined(_SYSCALL32) 105 struct dk_allmap32 { 106 struct dk_map32 dka_map[NDKMAP]; 107 }; 108 #endif /* _SYSCALL32 */ 109 110 /* 111 * Definition of a disk's geometry 112 */ 113 struct dk_geom { 114 unsigned short dkg_ncyl; /* # of data cylinders */ 115 unsigned short dkg_acyl; /* # of alternate cylinders */ 116 unsigned short dkg_bcyl; /* cyl offset (for fixed head area) */ 117 unsigned short dkg_nhead; /* # of heads */ 118 unsigned short dkg_obs1; /* obsolete */ 119 unsigned short dkg_nsect; /* # of data sectors per track */ 120 unsigned short dkg_intrlv; /* interleave factor */ 121 unsigned short dkg_obs2; /* obsolete */ 122 unsigned short dkg_obs3; /* obsolete */ 123 unsigned short dkg_apc; /* alternates per cyl (SCSI only) */ 124 unsigned short dkg_rpm; /* revolutions per minute */ 125 unsigned short dkg_pcyl; /* # of physical cylinders */ 126 unsigned short dkg_write_reinstruct; /* # sectors to skip, writes */ 127 unsigned short dkg_read_reinstruct; /* # sectors to skip, reads */ 128 unsigned short dkg_extra[7]; /* for compatible expansion */ 129 }; 130 131 /* 132 * These defines are for historic compatibility with old drivers. 133 */ 134 #define dkg_bhead dkg_obs1 /* used to be head offset */ 135 #define dkg_gap1 dkg_obs2 /* used to be gap1 */ 136 #define dkg_gap2 dkg_obs3 /* used to be gap2 */ 137 138 /* 139 * Disk io control commands 140 * Warning: some other ioctls with the DIOC prefix exist elsewhere. 141 * The Generic DKIOC numbers are from 0 - 50. 142 * The Floppy Driver uses 51 - 100. 143 * The Hard Disk (except SCSI) 101 - 106. (these are obsolete) 144 * The CDROM Driver 151 - 200. 145 * The USCSI ioctl 201 - 250. 146 */ 147 #define DKIOC (0x04 << 8) 148 149 /* 150 * The following ioctls are generic in nature and need to be 151 * supported as appropriate by all disk drivers 152 */ 153 #define DKIOCGGEOM (DKIOC|1) /* Get geometry */ 154 #define DKIOCINFO (DKIOC|3) /* Get info */ 155 #define DKIOCEJECT (DKIOC|6) /* Generic 'eject' */ 156 #define DKIOCGVTOC (DKIOC|11) /* Get VTOC */ 157 #define DKIOCSVTOC (DKIOC|12) /* Set VTOC & Write to Disk */ 158 159 /* 160 * Disk Cache Controls. These ioctls should be supported by 161 * all disk drivers. 162 * 163 * DKIOCFLUSHWRITECACHE when used from user-mode ignores the ioctl 164 * argument, but it should be passed as NULL to allow for future 165 * reinterpretation. From user-mode, this ioctl request is synchronous. 166 * 167 * When invoked from within the kernel, the arg can be NULL to indicate 168 * a synchronous request or can be the address of a struct dk_callback 169 * to request an asynchronous callback when the flush request is complete. 170 * In this case, the flag to the ioctl must include FKIOCTL and the 171 * dkc_callback field of the pointed to struct must be non-null or the 172 * request is made synchronously. 173 * 174 * In the callback case: if the ioctl returns 0, a callback WILL be performed. 175 * If the ioctl returns non-zero, a callback will NOT be performed. 176 * NOTE: In some cases, the callback may be done BEFORE the ioctl call 177 * returns. The caller's locking strategy should be prepared for this case. 178 */ 179 #define DKIOCFLUSHWRITECACHE (DKIOC|34) /* flush cache to phys medium */ 180 181 struct dk_callback { 182 void (*dkc_callback)(void *dkc_cookie, int error); 183 void *dkc_cookie; 184 int dkc_flag; 185 }; 186 187 /* bit flag definitions for dkc_flag */ 188 #define FLUSH_VOLATILE 0x1 /* Bit 0: if set, only flush */ 189 /* volatile cache; otherwise, flush */ 190 /* volatile and non-volatile cache */ 191 192 #define DKIOCGETWCE (DKIOC|36) /* Get current write cache */ 193 /* enablement status */ 194 #define DKIOCSETWCE (DKIOC|37) /* Enable/Disable write cache */ 195 196 /* 197 * The following ioctls are used by Sun drivers to communicate 198 * with their associated format routines. Support of these ioctls 199 * is not required of foreign drivers 200 */ 201 #define DKIOCSGEOM (DKIOC|2) /* Set geometry */ 202 #define DKIOCSAPART (DKIOC|4) /* Set all partitions */ 203 #define DKIOCGAPART (DKIOC|5) /* Get all partitions */ 204 #define DKIOCG_PHYGEOM (DKIOC|32) /* get physical geometry */ 205 #define DKIOCG_VIRTGEOM (DKIOC|33) /* get virtual geometry */ 206 207 /* 208 * The following ioctl's are removable media support 209 */ 210 #define DKIOCLOCK (DKIOC|7) /* Generic 'lock' */ 211 #define DKIOCUNLOCK (DKIOC|8) /* Generic 'unlock' */ 212 #define DKIOCSTATE (DKIOC|13) /* Inquire insert/eject state */ 213 #define DKIOCREMOVABLE (DKIOC|16) /* is media removable */ 214 215 216 /* 217 * ioctl for hotpluggable devices 218 */ 219 #define DKIOCHOTPLUGGABLE (DKIOC|35) /* is hotpluggable */ 220 221 /* 222 * Ioctl to force driver to re-read the alternate partition and rebuild 223 * the internal defect map. 224 */ 225 #define DKIOCADDBAD (DKIOC|20) /* Re-read the alternate map (IDE) */ 226 #define DKIOCGETDEF (DKIOC|21) /* read defect list (IDE) */ 227 228 /* 229 * Used by applications to get disk defect information from IDE 230 * drives. 231 */ 232 #ifdef _SYSCALL32 233 struct defect_header32 { 234 int head; 235 caddr32_t buffer; 236 }; 237 #endif /* _SYSCALL32 */ 238 239 struct defect_header { 240 int head; 241 caddr_t buffer; 242 }; 243 244 #define DKIOCPARTINFO (DKIOC|22) /* Get partition or slice parameters */ 245 246 /* 247 * Used by applications to get partition or slice information 248 */ 249 #ifdef _SYSCALL32 250 struct part_info32 { 251 uint32_t p_start; 252 int p_length; 253 }; 254 #endif /* _SYSCALL32 */ 255 256 struct part_info { 257 uint64_t p_start; 258 int p_length; 259 }; 260 261 /* The following ioctls are for Optical Memory Device */ 262 #define DKIOC_EBP_ENABLE (DKIOC|40) /* enable by pass erase on write */ 263 #define DKIOC_EBP_DISABLE (DKIOC|41) /* disable by pass erase on write */ 264 265 /* 266 * This state enum is the argument passed to the DKIOCSTATE ioctl. 267 */ 268 enum dkio_state { DKIO_NONE, DKIO_EJECTED, DKIO_INSERTED, DKIO_DEV_GONE }; 269 270 #define DKIOCGMEDIAINFO (DKIOC|42) /* get information about the media */ 271 272 /* 273 * ioctls to read/write mboot info. 274 */ 275 #define DKIOCGMBOOT (DKIOC|43) /* get mboot info */ 276 #define DKIOCSMBOOT (DKIOC|44) /* set mboot info */ 277 278 /* 279 * ioctl to get the device temperature. 280 */ 281 #define DKIOCGTEMPERATURE (DKIOC|45) /* get temperature */ 282 283 /* 284 * Used for providing the temperature. 285 */ 286 287 struct dk_temperature { 288 uint_t dkt_flags; /* Flags */ 289 short dkt_cur_temp; /* Current disk temperature */ 290 short dkt_ref_temp; /* reference disk temperature */ 291 }; 292 293 #define DKT_BYPASS_PM 0x1 294 #define DKT_INVALID_TEMP 0xFFFF 295 296 297 /* 298 * Used for Media info or the current profile info 299 */ 300 struct dk_minfo { 301 uint_t dki_media_type; /* Media type or profile info */ 302 uint_t dki_lbsize; /* Logical blocksize of media */ 303 diskaddr_t dki_capacity; /* Capacity as # of dki_lbsize blks */ 304 }; 305 306 /* 307 * Media types or profiles known 308 */ 309 #define DK_UNKNOWN 0x00 /* Media inserted - type unknown */ 310 311 312 /* 313 * SFF 8090 Specification Version 3, media types 0x01 - 0xfffe are retained to 314 * maintain compatibility with SFF8090. The following define the 315 * optical media type. 316 */ 317 #define DK_REMOVABLE_DISK 0x02 /* Removable Disk */ 318 #define DK_MO_ERASABLE 0x03 /* MO Erasable */ 319 #define DK_MO_WRITEONCE 0x04 /* MO Write once */ 320 #define DK_AS_MO 0x05 /* AS MO */ 321 #define DK_CDROM 0x08 /* CDROM */ 322 #define DK_CDR 0x09 /* CD-R */ 323 #define DK_CDRW 0x0A /* CD-RW */ 324 #define DK_DVDROM 0x10 /* DVD-ROM */ 325 #define DK_DVDR 0x11 /* DVD-R */ 326 #define DK_DVDRAM 0x12 /* DVD_RAM or DVD-RW */ 327 328 /* 329 * Media types for other rewritable magnetic media 330 */ 331 #define DK_FIXED_DISK 0x10001 /* Fixed disk SCSI or otherwise */ 332 #define DK_FLOPPY 0x10002 /* Floppy media */ 333 #define DK_ZIP 0x10003 /* IOMEGA ZIP media */ 334 #define DK_JAZ 0x10004 /* IOMEGA JAZ media */ 335 336 #define DKIOCSETEFI (DKIOC|17) /* Set EFI info */ 337 #define DKIOCGETEFI (DKIOC|18) /* Get EFI info */ 338 339 #define DKIOCPARTITION (DKIOC|9) /* Get partition info */ 340 341 /* 342 * Ioctls to get/set volume capabilities related to Logical Volume Managers. 343 * They include the ability to get/set capabilities and to issue a read to a 344 * specific underlying device of a replicated device. 345 */ 346 347 #define DKIOCGETVOLCAP (DKIOC | 25) /* Get volume capabilities */ 348 #define DKIOCSETVOLCAP (DKIOC | 26) /* Set volume capabilities */ 349 #define DKIOCDMR (DKIOC | 27) /* Issue a directed read */ 350 351 typedef uint_t volcapinfo_t; 352 353 typedef uint_t volcapset_t; 354 355 #define DKV_ABR_CAP 0x00000001 /* Support Appl.Based Recovery */ 356 #define DKV_DMR_CAP 0x00000002 /* Support Directed Mirror Read */ 357 358 typedef struct volcap { 359 volcapinfo_t vc_info; /* Capabilities available */ 360 volcapset_t vc_set; /* Capabilities set */ 361 } volcap_t; 362 363 #define VOL_SIDENAME 256 364 365 typedef struct vol_directed_rd { 366 int vdr_flags; 367 offset_t vdr_offset; 368 size_t vdr_nbytes; 369 size_t vdr_bytesread; 370 void *vdr_data; 371 int vdr_side; 372 char vdr_side_name[VOL_SIDENAME]; 373 } vol_directed_rd_t; 374 375 #define DKV_SIDE_INIT (-1) 376 #define DKV_DMR_NEXT_SIDE 0x00000001 377 #define DKV_DMR_DONE 0x00000002 378 #define DKV_DMR_ERROR 0x00000004 379 #define DKV_DMR_SUCCESS 0x00000008 380 #define DKV_DMR_SHORT 0x00000010 381 382 #ifdef _MULTI_DATAMODEL 383 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 384 #pragma pack(4) 385 #endif 386 typedef struct vol_directed_rd32 { 387 int32_t vdr_flags; 388 offset_t vdr_offset; /* 64-bit element on 32-bit alignment */ 389 size32_t vdr_nbytes; 390 size32_t vdr_bytesread; 391 caddr32_t vdr_data; 392 int32_t vdr_side; 393 char vdr_side_name[VOL_SIDENAME]; 394 } vol_directed_rd32_t; 395 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 396 #pragma pack() 397 #endif 398 #endif /* _MULTI_DATAMODEL */ 399 400 /* 401 * The ioctl is used to fetch disk's device type, vendor ID, 402 * model number/product ID, firmware revision and serial number together. 403 * 404 * Currently there are two device types - DKD_ATA_TYPE which means the 405 * disk is driven by cmdk/ata or dad/uata driver, and DKD_SCSI_TYPE 406 * which means the disk is driven by sd/scsi hba driver. 407 */ 408 #define DKIOC_GETDISKID (DKIOC|46) 409 410 /* These two labels are for dkd_dtype of dk_disk_id_t */ 411 #define DKD_ATA_TYPE 0x01 /* ATA disk or legacy mode SATA disk */ 412 #define DKD_SCSI_TYPE 0x02 /* SCSI disk or native mode SATA disk */ 413 414 #define DKD_ATA_MODEL 40 /* model number length */ 415 #define DKD_ATA_FWVER 8 /* firmware revision length */ 416 #define DKD_ATA_SERIAL 20 /* serial number length */ 417 418 #define DKD_SCSI_VENDOR 8 /* vendor ID length */ 419 #define DKD_SCSI_PRODUCT 16 /* product ID length */ 420 #define DKD_SCSI_REVLEVEL 4 /* revision level length */ 421 #define DKD_SCSI_SERIAL 12 /* serial number length */ 422 423 /* 424 * The argument type for DKIOC_GETDISKID ioctl. 425 */ 426 typedef struct dk_disk_id { 427 uint_t dkd_dtype; 428 union { 429 struct { 430 char dkd_amodel[DKD_ATA_MODEL]; /* 40 bytes */ 431 char dkd_afwver[DKD_ATA_FWVER]; /* 8 bytes */ 432 char dkd_aserial[DKD_ATA_SERIAL]; /* 20 bytes */ 433 } ata_disk_id; 434 struct { 435 char dkd_svendor[DKD_SCSI_VENDOR]; /* 8 bytes */ 436 char dkd_sproduct[DKD_SCSI_PRODUCT]; /* 16 bytes */ 437 char dkd_sfwver[DKD_SCSI_REVLEVEL]; /* 4 bytes */ 438 char dkd_sserial[DKD_SCSI_SERIAL]; /* 12 bytes */ 439 } scsi_disk_id; 440 } disk_id; 441 } dk_disk_id_t; 442 443 /* 444 * The ioctl is used to update the firmware of device. 445 */ 446 #define DKIOC_UPDATEFW (DKIOC|47) 447 448 /* The argument type for DKIOC_UPDATEFW ioctl */ 449 typedef struct dk_updatefw { 450 caddr_t dku_ptrbuf; /* pointer to firmware buf */ 451 uint_t dku_size; /* firmware buf length */ 452 uint8_t dku_type; /* firmware update type */ 453 } dk_updatefw_t; 454 455 #ifdef _SYSCALL32 456 typedef struct dk_updatefw_32 { 457 caddr32_t dku_ptrbuf; /* pointer to firmware buf */ 458 uint_t dku_size; /* firmware buf length */ 459 uint8_t dku_type; /* firmware update type */ 460 } dk_updatefw_32_t; 461 #endif /* _SYSCALL32 */ 462 463 /* 464 * firmware update type - temporary or permanent use 465 */ 466 #define FW_TYPE_TEMP 0x0 /* temporary use */ 467 #define FW_TYPE_PERM 0x1 /* permanent use */ 468 469 470 #ifdef __cplusplus 471 } 472 #endif 473 474 #endif /* _SYS_DKIO_H */ 475