[205] | 1 | /**
|
---|
[63] | 2 | * atapi.h - ATAPI structures and macros 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>
|
---|
[87] | 7 | *
|
---|
| 8 | * Authors: Christian Mueller, Markus Thielen
|
---|
| 9 | *
|
---|
| 10 | * Parts copied from/inspired by the Linux AHCI driver;
|
---|
[63] | 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 |
|
---|
[65] | 28 | #define ATAPI_MIN_CDB_LEN 12 /* minimum ATAPI CDB len acc to AHCI spec */
|
---|
| 29 | #define ATAPI_MAX_CDB_LEN 16
|
---|
| 30 |
|
---|
[63] | 31 | /******************************************************************************
|
---|
| 32 | * macros to fill in ATAPI CDB values
|
---|
| 33 | */
|
---|
[112] | 34 | #define SET_CDB_16(_t, _v) (_t)[0] = (u8) ((_v) >> 8); \
|
---|
[63] | 35 | (_t)[1] = (u8) (_v)
|
---|
[112] | 36 | #define SET_CDB_24(_t, _v) (_t)[0] = (u8) ((_v) >> 16) \
|
---|
| 37 | (_t)[1] = (u8) ((_v) >> 8); \
|
---|
[63] | 38 | (_t)[2] = (u8) (_v)
|
---|
[112] | 39 | #define SET_CDB_32(_t, _v) (_t)[0] = (u8) ((_v) >> 24);\
|
---|
| 40 | (_t)[1] = (u8) ((_v) >> 16);\
|
---|
| 41 | (_t)[2] = (u8) ((_v) >> 8); \
|
---|
[63] | 42 | (_t)[3] = (u8) (_v)
|
---|
| 43 |
|
---|
| 44 | #define GET_CDB_16(_f) ((u16) (_f)[0] << 8 | \
|
---|
| 45 | (u16) (_f)[1])
|
---|
| 46 | #define GET_CDB_24(_f) ((u32) (_f)[0] << 16 | \
|
---|
| 47 | (u32) (_f)[1] << 8 | \
|
---|
| 48 | (u32) (_f)[2])
|
---|
| 49 | #define GET_CDB_32(_f) ((u32) (_f)[0] << 24 | \
|
---|
| 50 | (u32) (_f)[1] << 16 | \
|
---|
| 51 | (u32) (_f)[2] << 24 | \
|
---|
| 52 | (u32) (_f)[3])
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | /******************************************************************************
|
---|
| 56 | * ATAPI/MMC command codes (as far as relevant for us)
|
---|
| 57 | */
|
---|
| 58 | #define ATAPI_CMD_READ_6 0x08
|
---|
| 59 | #define ATAPI_CMD_READ_10 0x28
|
---|
| 60 | #define ATAPI_CMD_READ_12 0xa8
|
---|
| 61 | #define ATAPI_CMD_READ_16 0x88
|
---|
| 62 | #define ATAPI_CMD_WRITE_6 0x0a
|
---|
| 63 | #define ATAPI_CMD_WRITE_10 0x2a
|
---|
| 64 | #define ATAPI_CMD_WRITE_12 0xaa
|
---|
| 65 | #define ATAPI_CMD_WRITE_16 0x8a
|
---|
| 66 | #define ATAPI_CMD_REQUEST_SENSE 0x03
|
---|
| 67 |
|
---|
| 68 | /******************************************************************************
|
---|
| 69 | * ATAPI command flag bits
|
---|
| 70 | */
|
---|
| 71 | #define ATAPI_FLAG_FUA 0x80
|
---|
| 72 | #define ATAPI_FLAG_DPO 0x10
|
---|
| 73 |
|
---|
[64] | 74 | #define ATAPI_FEAT_DMA 0x0001
|
---|
| 75 | #define ATAPI_FEAT_DMA_TO_HOST 0x0004
|
---|
| 76 |
|
---|
[63] | 77 | /******************************************************************************
|
---|
| 78 | * ATAPI sense data
|
---|
| 79 | */
|
---|
[64] | 80 | #define ATAPI_SENSE_LEN 96
|
---|
[63] | 81 |
|
---|
| 82 | #define ASENSE_NO_SENSE 0x00 /* no sense -> success */
|
---|
| 83 | #define ASENSE_RECOVERED_ERROR 0x01 /* recovered error -> success */
|
---|
| 84 | #define ASENSE_NOT_READY 0x02 /* device not ready */
|
---|
| 85 | #define ASENSE_MEDIUM_ERROR 0x03 /* medium/CRC error */
|
---|
| 86 | #define ASENSE_HARDWARE_ERROR 0x04 /* device error */
|
---|
| 87 | #define ASENSE_ILLEGAL_REQUEST 0x05 /* invalid command/parameters issued */
|
---|
| 88 | #define ASENSE_UNIT_ATTENTION 0x06 /* new medium */
|
---|
| 89 | #define ASENSE_DATA_PROTECT 0x07 /* protected LBA */
|
---|
| 90 | #define ASENSE_BLANK_CHECK 0x08 /* unformatted or write protected */
|
---|
| 91 | #define ASENSE_VENDOR_SPECIFIC 0x09 /* vendor specific sense data */
|
---|
| 92 | #define ASENSE_COPY_ABORTED 0x0a /* copy, ...command aborted */
|
---|
| 93 | #define ASENSE_ABORTED_COMMAND 0x0b /* command has been aborted */
|
---|
| 94 | #define ASENSE_EQUAL 0x0c
|
---|
| 95 | #define ASENSE_VOLUME_OVERFLOW 0x0d /* out of space */
|
---|
| 96 | #define ASENSE_MISCOMPARE 0x0e /* verification failed */
|
---|
| 97 | #define ASENSE_RESERVED 0x0f
|
---|
| 98 |
|
---|
| 99 | /******************************************************************************
|
---|
| 100 | * macro to get sense key from ATAPI_SENSE_DATA pointer
|
---|
| 101 | */
|
---|
| 102 | #define ATAPI_GET_SENSE(p_) (u8)(p_->sense.sense_key & 0x0f)
|
---|
| 103 |
|
---|
| 104 | /******************************************************************************
|
---|
| 105 | * ATAPI_SENSE_DATA - define layout of ATAPI sense data
|
---|
| 106 | */
|
---|
| 107 | typedef union _ATAPI_SENSE_DATA {
|
---|
| 108 | struct {
|
---|
| 109 | u8 valid_respc; /* valid bit (bit 7), response code (bits 6:0) */
|
---|
| 110 | u8 segment; /* segment number (obsolete) */
|
---|
| 111 | u8 sense_key; /* some flags (bits 7:4), sense key (bits 3:0) */
|
---|
| 112 | u8 info[4]; /* information (?) */
|
---|
| 113 | u8 adl_len; /* additional sense info length */
|
---|
| 114 | u8 cmd_specific[4]; /* command specific stuff (ignored) */
|
---|
| 115 | u8 asc; /* additional sense code */
|
---|
| 116 | u8 ascq; /* additional sense code qualifier */
|
---|
| 117 | u8 fruc; /* field replaceable unit code */
|
---|
| 118 | u8 flags; /* vendor-specific flags */
|
---|
| 119 | u8 field_off[2]; /* offset to invalid field in parm list */
|
---|
| 120 | } sense;
|
---|
| 121 |
|
---|
| 122 | u8 padding[ATAPI_SENSE_LEN]; /* pad to 64 bytes */
|
---|
| 123 |
|
---|
| 124 | } ATAPI_SENSE_DATA;
|
---|
| 125 |
|
---|
[68] | 126 | /******************************************************************************Ã
|
---|
| 127 | * ATAPI_CDB_6 - describes 6 byte ATAPI command
|
---|
| 128 | */
|
---|
| 129 | typedef struct _ATAPI_CDB_6 {
|
---|
| 130 | u8 cmd; /* command code */
|
---|
| 131 | u8 lun; /* SCSI lun (ignored) */
|
---|
| 132 | u8 resvd[2];
|
---|
| 133 | u8 trans_len; /* transfer length */
|
---|
| 134 | u8 control;
|
---|
| 135 | } ATAPI_CDB_6;
|
---|
| 136 |
|
---|
[63] | 137 | /******************************************************************************
|
---|
| 138 | * ATAPI_CDB_10 - describes layout of generic 10 byte ATAPI command
|
---|
| 139 | */
|
---|
| 140 | typedef struct _ATAPI_CDB_10 {
|
---|
| 141 | u8 cmd; /* SCSI/ATAPI command code */
|
---|
| 142 | u8 flags; /* flags (DPO, FUA) */
|
---|
| 143 | u8 lba[4]; /* logical block address */
|
---|
| 144 | u8 trans_len[2]; /* number of blocks to transfer */
|
---|
| 145 | u8 control; /* (nothing much) */
|
---|
| 146 | } ATAPI_CDB_10;
|
---|
| 147 |
|
---|
| 148 | /******************************************************************************
|
---|
| 149 | * ATAPI_CDB_12 - describes layout of generic 12 byte ATAPI command
|
---|
| 150 | */
|
---|
| 151 | typedef struct _ATAPI_CDB_12 {
|
---|
| 152 | u8 cmd; /* SCSI/ATAPI command code */
|
---|
| 153 | u8 flags; /* flags (DPO, FUA) */
|
---|
| 154 | u8 lba[4]; /* logical block address */
|
---|
| 155 | u8 trans_len[4]; /* number of blocks to transfer */
|
---|
| 156 | u8 reserved;
|
---|
| 157 | u8 control; /* (nothing much) */
|
---|
| 158 | } ATAPI_CDB_12;
|
---|
| 159 |
|
---|
| 160 |
|
---|
[178] | 161 | extern int atapi_get_geometry(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot);
|
---|
| 162 | extern int atapi_unit_ready(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot);
|
---|
| 163 | extern int atapi_read(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot);
|
---|
| 164 | extern int atapi_read_unaligned(IORBH *pIorb, int slot);
|
---|
| 165 | extern int atapi_verify(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot);
|
---|
| 166 | extern int atapi_write(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot);
|
---|
| 167 | extern int atapi_execute_cdb(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot);
|
---|
| 168 | extern int atapi_req_sense(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot);
|
---|
[63] | 169 |
|
---|