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