1/* prototypes and stuff for ATA command ioctls */ 2 3#include <linux/types.h> 4 5enum { 6 ATA_OP_DSM = 0x06, // Data Set Management (TRIM) 7 ATA_OP_READ_PIO = 0x20, 8 ATA_OP_READ_PIO_ONCE = 0x21, 9 ATA_OP_READ_LONG = 0x22, 10 ATA_OP_READ_LONG_ONCE = 0x23, 11 ATA_OP_READ_PIO_EXT = 0x24, 12 ATA_OP_READ_DMA_EXT = 0x25, 13 ATA_OP_READ_FPDMA = 0x60, // NCQ 14 ATA_OP_WRITE_PIO = 0x30, 15 ATA_OP_WRITE_LONG = 0x32, 16 ATA_OP_WRITE_LONG_ONCE = 0x33, 17 ATA_OP_WRITE_PIO_EXT = 0x34, 18 ATA_OP_WRITE_DMA_EXT = 0x35, 19 ATA_OP_WRITE_FPDMA = 0x61, // NCQ 20 ATA_OP_READ_VERIFY = 0x40, 21 ATA_OP_READ_VERIFY_ONCE = 0x41, 22 ATA_OP_READ_VERIFY_EXT = 0x42, 23 ATA_OP_WRITE_UNC_EXT = 0x45, // lba48, no data, uses feat reg 24 ATA_OP_FORMAT_TRACK = 0x50, 25 ATA_OP_DOWNLOAD_MICROCODE = 0x92, 26 ATA_OP_STANDBYNOW2 = 0x94, 27 ATA_OP_CHECKPOWERMODE2 = 0x98, 28 ATA_OP_SLEEPNOW2 = 0x99, 29 ATA_OP_PIDENTIFY = 0xa1, 30 ATA_OP_READ_NATIVE_MAX = 0xf8, 31 ATA_OP_READ_NATIVE_MAX_EXT = 0x27, 32 ATA_OP_SMART = 0xb0, 33 ATA_OP_DCO = 0xb1, 34 ATA_OP_ERASE_SECTORS = 0xc0, 35 ATA_OP_READ_DMA = 0xc8, 36 ATA_OP_WRITE_DMA = 0xca, 37 ATA_OP_DOORLOCK = 0xde, 38 ATA_OP_DOORUNLOCK = 0xdf, 39 ATA_OP_STANDBYNOW1 = 0xe0, 40 ATA_OP_IDLEIMMEDIATE = 0xe1, 41 ATA_OP_SETIDLE = 0xe3, 42 ATA_OP_SET_MAX = 0xf9, 43 ATA_OP_SET_MAX_EXT = 0x37, 44 ATA_OP_SET_MULTIPLE = 0xc6, 45 ATA_OP_CHECKPOWERMODE1 = 0xe5, 46 ATA_OP_SLEEPNOW1 = 0xe6, 47 ATA_OP_FLUSHCACHE = 0xe7, 48 ATA_OP_FLUSHCACHE_EXT = 0xea, 49 ATA_OP_IDENTIFY = 0xec, 50 ATA_OP_SETFEATURES = 0xef, 51 ATA_OP_SECURITY_SET_PASS = 0xf1, 52 ATA_OP_SECURITY_UNLOCK = 0xf2, 53 ATA_OP_SECURITY_ERASE_PREPARE = 0xf3, 54 ATA_OP_SECURITY_ERASE_UNIT = 0xf4, 55 ATA_OP_SECURITY_FREEZE_LOCK = 0xf5, 56 ATA_OP_SECURITY_DISABLE = 0xf6, 57 ATA_OP_VENDOR_SPECIFIC_0x80 = 0x80, 58}; 59 60/* 61 * Some useful ATA register bits 62 */ 63enum { 64 ATA_USING_LBA = (1 << 6), 65 ATA_STAT_DRQ = (1 << 3), 66 ATA_STAT_ERR = (1 << 0), 67}; 68 69/* 70 * Useful parameters for init_hdio_taskfile(): 71 */ 72enum { RW_READ = 0, 73 RW_WRITE = 1, 74 LBA28_OK = 0, 75 LBA48_FORCE = 1, 76}; 77 78/* 79 * Definitions and structures for use with SG_IO + ATA_16: 80 */ 81struct ata_lba_regs { 82 __u8 feat; 83 __u8 nsect; 84 __u8 lbal; 85 __u8 lbam; 86 __u8 lbah; 87}; 88struct ata_tf { 89 __u8 dev; 90 __u8 command; 91 __u8 error; 92 __u8 status; 93 __u8 is_lba48; 94 struct ata_lba_regs lob; 95 struct ata_lba_regs hob; 96}; 97 98/* 99 * Definitions and structures for use with HDIO_DRIVE_TASKFILE: 100 */ 101 102enum { 103 /* 104 * These (redundantly) specify the category of the request 105 */ 106 TASKFILE_CMD_REQ_NODATA = 0, /* ide: IDE_DRIVE_TASK_NO_DATA */ 107 TASKFILE_CMD_REQ_IN = 2, /* ide: IDE_DRIVE_TASK_IN */ 108 TASKFILE_CMD_REQ_OUT = 3, /* ide: IDE_DRIVE_TASK_OUT */ 109 TASKFILE_CMD_REQ_RAW_OUT= 4, /* ide: IDE_DRIVE_TASK_RAW_WRITE */ 110 /* 111 * These specify the method of transfer (pio, dma, multi, ..) 112 */ 113 TASKFILE_DPHASE_NONE = 0, /* ide: TASKFILE_IN */ 114 TASKFILE_DPHASE_PIO_IN = 1, /* ide: TASKFILE_IN */ 115 TASKFILE_DPHASE_PIO_OUT = 4, /* ide: TASKFILE_OUT */ 116}; 117 118union reg_flags { 119 unsigned all :16; 120 union { 121 unsigned lob_all : 8; 122 struct { 123 unsigned data : 1; 124 unsigned feat : 1; 125 unsigned lbal : 1; 126 unsigned nsect : 1; 127 unsigned lbam : 1; 128 unsigned lbah : 1; 129 unsigned dev : 1; 130 unsigned command : 1; 131 } lob; 132 }; 133 union { 134 unsigned hob_all : 8; 135 struct { 136 unsigned data : 1; 137 unsigned feat : 1; 138 unsigned lbal : 1; 139 unsigned nsect : 1; 140 unsigned lbam : 1; 141 unsigned lbah : 1; 142 unsigned dev : 1; 143 unsigned command : 1; 144 } hob; 145 }; 146} __attribute__((packed)); 147 148struct taskfile_regs { 149 __u8 data; 150 __u8 feat; 151 __u8 nsect; 152 __u8 lbal; 153 __u8 lbam; 154 __u8 lbah; 155 __u8 dev; 156 __u8 command; 157}; 158 159struct hdio_taskfile { 160 struct taskfile_regs lob; 161 struct taskfile_regs hob; 162 union reg_flags oflags; 163 union reg_flags iflags; 164 int dphase; 165 int cmd_req; /* IDE command_type */ 166 unsigned long obytes; 167 unsigned long ibytes; 168 __u16 data[0]; 169}; 170 171struct scsi_sg_io_hdr { 172 int interface_id; 173 int dxfer_direction; 174 unsigned char cmd_len; 175 unsigned char mx_sb_len; 176 unsigned short iovec_count; 177 unsigned int dxfer_len; 178 void * dxferp; 179 unsigned char * cmdp; 180 void * sbp; 181 unsigned int timeout; 182 unsigned int flags; 183 int pack_id; 184 void * usr_ptr; 185 unsigned char status; 186 unsigned char masked_status; 187 unsigned char msg_status; 188 unsigned char sb_len_wr; 189 unsigned short host_status; 190 unsigned short driver_status; 191 int resid; 192 unsigned int duration; 193 unsigned int info; 194}; 195 196#ifndef SG_DXFER_NONE 197 #define SG_DXFER_NONE -1 198 #define SG_DXFER_TO_DEV -2 199 #define SG_DXFER_FROM_DEV -3 200 #define SG_DXFER_TO_FROM_DEV -4 201#endif 202 203#define SG_READ 0 204#define SG_WRITE 1 205 206#define SG_PIO 0 207#define SG_DMA 1 208 209#define SG_CHECK_CONDITION 0x02 210#define SG_DRIVER_SENSE 0x08 211 212#define SG_ATA_16 0x85 213#define SG_ATA_16_LEN 16 214 215#define SG_ATA_12 0xa1 216#define SG_ATA_12_LEN 12 217 218#define SG_ATA_LBA48 1 219#define SG_ATA_PROTO_NON_DATA ( 3 << 1) 220#define SG_ATA_PROTO_PIO_IN ( 4 << 1) 221#define SG_ATA_PROTO_PIO_OUT ( 5 << 1) 222#define SG_ATA_PROTO_DMA ( 6 << 1) 223#define SG_ATA_PROTO_UDMA_IN (11 << 1) /* not yet supported in libata */ 224#define SG_ATA_PROTO_UDMA_OUT (12 << 1) /* not yet supported in libata */ 225 226void tf_init (struct ata_tf *tf, __u8 ata_op, __u64 lba, unsigned int nsect); 227__u64 tf_to_lba (struct ata_tf *tf); 228int sg16 (int fd, int rw, int dma, struct ata_tf *tf, void *data, unsigned int data_bytes, unsigned int timeout_secs); 229int do_drive_cmd (int fd, unsigned char *args, unsigned int timeout); 230int do_taskfile_cmd (int fd, struct hdio_taskfile *r, unsigned int timeout_secs); 231int dev_has_sgio (int fd); 232void init_hdio_taskfile (struct hdio_taskfile *r, __u8 ata_op, int rw, int force_lba48, 233 __u64 lba, unsigned int nsect, int data_bytes); 234