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