[205] | 1 | /**
|
---|
[84] | 2 | * ioctl.h - IOCTL structures and constants for os2ahci driver
|
---|
| 3 | *
|
---|
[87] | 4 | * Copyright (c) 2011 thi.guten Software Development
|
---|
| 5 | * Copyright (c) 2011 Mensys B.V.
|
---|
[211] | 6 | * Copyright (c) 2013-2023 David Azarewicz <david@88watts.net>
|
---|
[84] | 7 | *
|
---|
[87] | 8 | * Authors: Christian Mueller, Markus Thielen
|
---|
| 9 | *
|
---|
| 10 | * Parts copied from/inspired by the Linux AHCI driver;
|
---|
| 11 | * those parts are (c) Linux AHCI/ATA maintainers
|
---|
| 12 | *
|
---|
[84] | 13 | * This program is free software; you can redistribute it and/or modify
|
---|
| 14 | * it under the terms of the GNU General Public License as published by
|
---|
| 15 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 16 | * (at your option) any later version.
|
---|
| 17 | *
|
---|
| 18 | * This program is distributed in the hope that it will be useful,
|
---|
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 21 | * GNU General Public License for more details.
|
---|
| 22 | *
|
---|
| 23 | * You should have received a copy of the GNU General Public License
|
---|
| 24 | * along with this program; if not, write to the Free Software
|
---|
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 | /* IOCTL categories and functions */
|
---|
[125] | 29 | #define OS2AHCI_IOCTL_CATEGORY 0x87
|
---|
[84] | 30 | #define OS2AHCI_IOCTL_GET_DEVLIST 0x01
|
---|
| 31 | #define OS2AHCI_IOCTL_PASSTHROUGH 0x02
|
---|
[211] | 32 | #define OS2AHCI_IOCTL_DEBUG 0xd1
|
---|
[84] | 33 |
|
---|
[125] | 34 | /* IOCTL definitions from s506oem.h (primarily required for SMART calls) */
|
---|
| 35 | #define DSKSP_CAT_SMART 0x80 /* SMART IOCTL category */
|
---|
| 36 | #define DSKSP_SMART_ONOFF 0x20 /* turn SMART on or off */
|
---|
| 37 | #define DSKSP_SMART_AUTOSAVE_ONOFF 0x21 /* turn SMART autosave on or off */
|
---|
| 38 | #define DSKSP_SMART_SAVE 0x22 /* force save of SMART data */
|
---|
| 39 | #define DSKSP_SMART_GETSTATUS 0x23 /* get SMART status (pass/fail) */
|
---|
| 40 | #define DSKSP_SMART_GET_ATTRIBUTES 0x24 /* get SMART attributes table */
|
---|
| 41 | #define DSKSP_SMART_GET_THRESHOLDS 0x25 /* get SMART thresholds table */
|
---|
| 42 | #define DSKSP_SMART_GET_LOG 0x26 /* get SMART log table */
|
---|
| 43 | #define DSKSP_SMART_AUTO_OFFLINE 0x27 /* set SMART offline autosave timer */
|
---|
| 44 | #define DSKSP_SMART_EXEC_OFFLINE 0x28 /* execute SMART immediate offline */
|
---|
| 45 |
|
---|
| 46 | #define SMART_CMD_ON 1 /* on value for related SMART functions */
|
---|
| 47 | #define SMART_CMD_OFF 0 /* off value for related SMART functions */
|
---|
| 48 |
|
---|
| 49 | #define DSKSP_CAT_GENERIC 0x90 /* generic IOCTL category */
|
---|
| 50 | #define DSKSP_GEN_GET_COUNTERS 0x40 /* get general counter values table */
|
---|
| 51 | #define DSKSP_GET_UNIT_INFORMATION 0x41 /* get unit configuration and BM DMA counters */
|
---|
| 52 | #define DSKSP_GET_INQUIRY_DATA 0x42 /* get ATA/ATAPI inquiry data */
|
---|
| 53 |
|
---|
| 54 | /* unit information structure flags from s506oem.h */
|
---|
| 55 | #define UIF_VALID 0x8000U /* unit information valid */
|
---|
| 56 | #define UIF_TIMINGS_VALID 0x4000U /* timing information valid */
|
---|
| 57 | #define UIF_RUNNING_BMDMA 0x2000U /* running Bus Master DMA on unit */
|
---|
| 58 | #define UIF_RUNNING_DMA 0x1000U /* running slave DMA on unit */
|
---|
| 59 | #define UIF_SATA 0x0004U /* SATA */
|
---|
| 60 | #define UIF_SLAVE 0x0002U /* slave on channel */
|
---|
| 61 | #define UIF_ATAPI 0x0001U /* ATAPI device if 1, ATA otherwise */
|
---|
| 62 |
|
---|
[84] | 63 | /* device flags */
|
---|
| 64 | #define DF_LBA48 0x0001U
|
---|
| 65 | #define DF_ATAPI 0x0002U
|
---|
| 66 | #define DF_ATAPI_16 0x0004U
|
---|
| 67 | #define DF_REMOVABLE 0x0008U
|
---|
| 68 |
|
---|
| 69 | /* passthrough flags */
|
---|
| 70 | #define PT_WRITE 0x0001U /* transfer direction host -> device */
|
---|
| 71 | #define PT_ATAPI 0x0002U /* ATAPI command (ATA if not set) */
|
---|
| 72 |
|
---|
| 73 | #ifndef VMDHL_WRITE
|
---|
| 74 | typedef void *LIN;
|
---|
| 75 | #endif
|
---|
| 76 |
|
---|
| 77 | #pragma pack(1)
|
---|
| 78 |
|
---|
| 79 | /******************************************************************************
|
---|
| 80 | * Generic ATA-8 command structure. This is loosely based on ATA-8, i.e. we
|
---|
| 81 | * don't have to deal with shadow registers and map them to the low bytes of
|
---|
| 82 | * adjecent words, etc. but there are still some oddities which need to be
|
---|
| 83 | * taken into consideration. For example, ATA-8 says LBA-28 sector addresses
|
---|
| 84 | * are simply the lower 28 bits in the LBA field. However, the underlying
|
---|
| 85 | * transport (SATA in our case) only looks at the three lower bytes of the
|
---|
| 86 | * LBA field, much like an IDE device would do. This means that only 3 bytes
|
---|
| 87 | * of the LBA field are processed and this yields only 24 bits. The remaining
|
---|
| 88 | * 4 bits need to be stored in the "device" register....
|
---|
| 89 | *
|
---|
| 90 | * Everything else seems to behave normally, as far as this term can be
|
---|
| 91 | * applied to IDE/ATA. Further details can be found in section 7.1.5.1 of the
|
---|
| 92 | * ATA-8 spec (Inputs for 28-bit Read/Write Commands).
|
---|
| 93 | */
|
---|
| 94 | typedef struct {
|
---|
| 95 | USHORT features; /* feature bits */
|
---|
| 96 | USHORT count; /* count register (e.g. number of sectors) */
|
---|
| 97 | ULONG lba_l; /* low 24 bits of LBA-28 (32 bits for 48-bit devices) */
|
---|
| 98 | USHORT lba_h; /* high 16 bits of LBA for 48-bit devices */
|
---|
| 99 | UCHAR cmd; /* ATA command field */
|
---|
| 100 | UCHAR device; /* ATA device field and upper 4 bits of LBA-28 */
|
---|
| 101 | } ATACMD;
|
---|
| 102 |
|
---|
| 103 | /******************************************************************************
|
---|
| 104 | * Data structure for OS2AHCI_IOCTL_GET_DEVLIST; the parameter for this IOCTL
|
---|
| 105 | * is a USHORT with the number of entries in 'devs'.
|
---|
| 106 | */
|
---|
| 107 | typedef struct {
|
---|
| 108 | USHORT cnt; /* number of entries in 'devs' */
|
---|
| 109 | struct {
|
---|
| 110 | USHORT adapter; /* adapter */
|
---|
| 111 | USHORT port; /* port */
|
---|
| 112 | USHORT device; /* device (port multiplier) */
|
---|
| 113 | USHORT type; /* device type; see UIB_TYPE_* in iorb.h */
|
---|
| 114 | USHORT ncq_max; /* maximum number of queued commands */
|
---|
| 115 | USHORT flags; /* device flags; see DF_* above */
|
---|
| 116 | } devs[1];
|
---|
| 117 | } OS2AHCI_DEVLIST;
|
---|
| 118 |
|
---|
| 119 | /******************************************************************************
|
---|
| 120 | * Parameter structure for OS2AHCI_IOCTL_PASSTHROUGH; the data structure for
|
---|
| 121 | * this IOCTL is a buffer for sense data in case of errors.
|
---|
| 122 | */
|
---|
| 123 | typedef struct {
|
---|
| 124 | USHORT adapter; /* adapter */
|
---|
| 125 | USHORT port; /* port */
|
---|
| 126 | USHORT device; /* device (port multiplier) */
|
---|
| 127 | USHORT flags; /* request flags; see PT_* above */
|
---|
| 128 | ULONG timeout; /* timeout in seconds (0 = default of 30s) */
|
---|
| 129 |
|
---|
| 130 | USHORT cmdlen; /* length of ATA or ATAPI command */
|
---|
| 131 | union {
|
---|
| 132 | ATACMD ata; /* ATA command */
|
---|
| 133 | UCHAR cdb[20]; /* ATAPI command */
|
---|
| 134 | } cmd;
|
---|
| 135 |
|
---|
| 136 | ULONG buflen; /* length of buffer for data transfers */
|
---|
[178] | 137 | void *buf; /* buffer for data transfers (32-bit linear address) */
|
---|
[84] | 138 | USHORT sense_len; /* length of sense data in IOCTL DataPacket */
|
---|
| 139 | } OS2AHCI_PASSTHROUGH;
|
---|
| 140 |
|
---|
[125] | 141 | /******************************************************************************
|
---|
| 142 | * DSKSP command parameters; copied from s506oem.h
|
---|
| 143 | */
|
---|
| 144 | typedef struct _DSKSP_CommandParameters
|
---|
| 145 | {
|
---|
| 146 | BYTE byPhysicalUnit; /* physical unit number 0-n */
|
---|
| 147 | /* 0 = Pri/Mas, 1=Pri/Sla, 2=Sec/Mas, etc. */
|
---|
| 148 | } DSKSP_CommandParameters;
|
---|
| 149 |
|
---|
| 150 | /******************************************************************************
|
---|
| 151 | * DSKSP device counters data; copied from s506oem.h
|
---|
| 152 | */
|
---|
| 153 | typedef struct _DeviceCountersData
|
---|
| 154 | {
|
---|
| 155 | USHORT wRevisionNumber; /* counter structure revision */
|
---|
| 156 | ULONG TotalReadOperations; /* total read operations performed */
|
---|
| 157 | ULONG TotalWriteOperations; /* total write operations performed */
|
---|
| 158 | ULONG TotalWriteErrors; /* total write errors encountered */
|
---|
| 159 | ULONG TotalReadErrors; /* total read errors encountered */
|
---|
| 160 | ULONG TotalSeekErrors; /* total seek errors encountered */
|
---|
| 161 | ULONG TotalSectorsRead; /* total number of sectors read */
|
---|
| 162 | ULONG TotalSectorsWritten; /* total number of sectors written */
|
---|
| 163 |
|
---|
| 164 | ULONG TotalBMReadOperations; /* total bus master DMA read operations */
|
---|
| 165 | ULONG TotalBMWriteOperations; /* total bus master DMA write operations */
|
---|
| 166 | ULONG ByteMisalignedBuffers; /* total buffers on odd byte boundary */
|
---|
| 167 | ULONG TransfersAcross64K; /* total buffers crossing a 64K page boundary */
|
---|
| 168 | USHORT TotalBMStatus; /* total bad busmaster status */
|
---|
| 169 | USHORT TotalBMErrors; /* total bad busmaster error */
|
---|
| 170 | ULONG TotalIRQsLost; /* total lost interrupts */
|
---|
| 171 | USHORT TotalDRQsLost; /* total lost data transfer requests */
|
---|
| 172 | USHORT TotalBusyErrors; /* total device busy timeouts */
|
---|
| 173 | USHORT TotalBMStatus2; /* total bad busmaster status */
|
---|
| 174 | USHORT TotalChipStatus; /* total bad chip status */
|
---|
| 175 | USHORT ReadErrors[4];
|
---|
| 176 | USHORT WriteErrors[2];
|
---|
| 177 | USHORT SeekErrors[2];
|
---|
| 178 | USHORT SATAErrors;
|
---|
[129] | 179 | } DeviceCountersData;
|
---|
[125] | 180 |
|
---|
| 181 | /******************************************************************************
|
---|
| 182 | * DSKSP unit information data; copied from s506oem.h
|
---|
| 183 | */
|
---|
| 184 | typedef struct _UnitInformationData
|
---|
| 185 | {
|
---|
| 186 | USHORT wRevisionNumber; /* structure revision number */
|
---|
| 187 | union {
|
---|
| 188 | struct {
|
---|
| 189 | USHORT wTFBase; /* task file register base addr */
|
---|
| 190 | USHORT wDevCtl; /* device control register addr */
|
---|
| 191 | } rev0;
|
---|
| 192 | ULONG dTFBase; /* task file register base addr */
|
---|
| 193 | };
|
---|
| 194 | USHORT wIRQ; /* interrupt request level */
|
---|
| 195 | USHORT wFlags; /* flags */
|
---|
| 196 | UCHAR byPIO_Mode; /* PIO transfer mode programmed */
|
---|
| 197 | UCHAR byDMA_Mode; /* DMA transfer mode programmed */
|
---|
| 198 | ULONG UnitFlags1;
|
---|
| 199 | USHORT UnitFlags2;
|
---|
[129] | 200 | } UnitInformationData;
|
---|
[125] | 201 |
|
---|
[84] | 202 | #pragma pack()
|
---|
| 203 |
|
---|