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