smartmontools  SVN Rev 4092
Utility to control and monitor storage systems with "S.M.A.R.T."
os_linux.h
Go to the documentation of this file.
1 /*
2  * os_linux.h
3  *
4  * Home page of code is: http://smartmontools.sourceforge.net
5  *
6  * Copyright (C) 2003-8 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7  *
8  * Derived from code that was
9  *
10  * Written By: Adam Radford <linux@3ware.com>
11  * Modifications By: Joel Jacobson <linux@3ware.com>
12  * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
13  * Brad Strand <linux@3ware.com>
14  *
15  * Copyright (C) 1999-2003 3ware Inc.
16  *
17  * Kernel compatablity By: Andre Hedrick <andre@suse.com>
18  * Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
19  *
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2, or (at your option)
24  * any later version.
25  *
26  * You should have received a copy of the GNU General Public License
27  * (for example COPYING); if not, write to the Free Software Foundation,
28  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29  *
30  * This code was originally developed as a Senior Thesis by Michael Cornwell
31  * at the Concurrent Systems Laboratory (now part of the Storage Systems
32  * Research Center), Jack Baskin School of Engineering, University of
33  * California, Santa Cruz. http://ssrc.soe.ucsc.edu/
34  *
35  */
36 
37 
38 #ifndef OS_LINUX_H_
39 #define OS_LINUX_H_
40 
41 #define OS_LINUX_H_CVSID "$Id: os_linux.h 3728 2012-12-13 17:57:50Z chrfranke $\n"
42 
43 /*
44  The following definitions/macros/prototypes are used for three
45  different interfaces, referred to as "the three cases" below.
46  CONTROLLER_3WARE_678K -- 6000, 7000, and 8000 controllers via /dev/sd?
47  CONTROLLER_3WARE_678K_CHAR -- 6000, 7000, and 8000 controllers via /dev/twe?
48  CONTROLLER_3WARE_9000_CHAR -- 9000 controllers via /dev/twa?
49 */
50 
51 // USED FOR ALL THREE CASES
52 
53 #define u32 unsigned int
54 #define TW_OP_ATA_PASSTHRU 0x11
55 #define MAX(x,y) ( (x)>(y)?(x):(y) )
56 
57 #pragma pack(1)
58 /* Scatter gather list entry */
59 typedef struct TAG_TW_SG_Entry {
60  unsigned int address;
61  unsigned int length;
62 } TW_SG_Entry;
63 
64 /* Command header for ATA pass-thru. Note that for different
65  drivers/interfaces the length of sg_list (here TW_ATA_PASS_SGL_MAX)
66  is different. But it can be taken as same for all three cases
67  because it's never used to define any other structures, and we
68  never use anything in the sg_list or beyond! */
69 
70 #define TW_ATA_PASS_SGL_MAX 60
71 
72 typedef struct TAG_TW_Passthru {
73  struct {
74  unsigned char opcode:5;
75  unsigned char sgloff:3;
76  } byte0;
77  unsigned char size;
78  unsigned char request_id;
79  unsigned char unit;
80  unsigned char status; // On return, contains 3ware STATUS register
81  unsigned char flags;
82  unsigned short param;
83  unsigned short features; // On return, contains ATA ERROR register
84  unsigned short sector_count;
85  unsigned short sector_num;
86  unsigned short cylinder_lo;
87  unsigned short cylinder_hi;
88  unsigned char drive_head;
89  unsigned char command; // On return, contains ATA STATUS register
91  unsigned char padding[12];
92 } TW_Passthru;
93 
94 // the following are for the SCSI interface only
95 
96 // Ioctl buffer: Note that this defn has changed in kernel tree...
97 // Total size is 1041 bytes -- this is really weird
98 
99 #define TW_IOCTL 0x80
100 #define TW_ATA_PASSTHRU 0x1e
101 
102 // Adam -- should this be #pramga packed? Otherwise table_id gets
103 // moved for byte alignment. Without packing, input passthru for SCSI
104 // ioctl is 31 bytes in. With packing it is 30 bytes in.
105 typedef struct TAG_TW_Ioctl {
108  unsigned char cdb[16];
109  unsigned char opcode;
110  // This one byte of padding is missing from the typedefs in the
111  // kernel code, but it is indeed present. We put it explicitly
112  // here, so that the structure can be packed. Adam agrees with
113  // this.
114  unsigned char packing;
115  unsigned short table_id;
116  unsigned char parameter_id;
117  unsigned char parameter_size_bytes;
118  unsigned char unit_index;
119  // Size up to here is 30 bytes + 1 padding!
120  unsigned char input_data[499];
121  // Reserve lots of extra space for commands that set Sector Count
122  // register to large values
123  unsigned char output_data[512]; // starts 530 bytes in!
124  // two more padding bytes here if structure NOT packed.
125 } TW_Ioctl;
126 
127 /* Ioctl buffer output -- SCSI interface only! */
128 typedef struct TAG_TW_Output {
129  int padding[2];
130  char output_data[512];
131 } TW_Output;
132 
133 // What follows is needed for 9000 char interface only
134 
135 #define TW_IOCTL_FIRMWARE_PASS_THROUGH 0x108
136 #define TW_MAX_SGL_LENGTH_9000 61
137 
139  unsigned int control_code;
140  unsigned int status;
141  unsigned int unique_id;
142  unsigned int sequence_id;
143  unsigned int os_specific;
144  unsigned int buffer_length;
146 
147 /* Command Packet */
148 typedef struct TW_Command_9000 {
149  /* First DWORD */
150  struct {
151  unsigned char opcode:5;
152  unsigned char sgl_offset:3;
153  } byte0;
154  unsigned char size;
155  unsigned char request_id;
156  struct {
157  unsigned char unit:4;
158  unsigned char host_id:4;
159  } byte3;
160  /* Second DWORD */
161  unsigned char status;
162  unsigned char flags;
163  union {
164  unsigned short block_count;
165  unsigned short parameter_count;
166  unsigned short message_credits;
167  } byte6;
168  union {
169  struct {
173  } io;
174  struct {
176  u32 padding[2];
177  } param;
178  struct {
180  u32 padding[125]; /* pad entire structure to 512 bytes */
181  } init_connection;
182  struct {
183  char version[504];
185  } byte8;
187 
188 /* Command Packet for 9000+ controllers */
189 typedef struct TAG_TW_Command_Apache {
190  struct {
191  unsigned char opcode:5;
192  unsigned char reserved:3;
193  } command;
194  unsigned char unit;
195  unsigned short request_id;
196  unsigned char sense_length;
197  unsigned char sgl_offset;
198  unsigned short sgl_entries;
199  unsigned char cdb[16];
202 
203 /* New command packet header */
205  unsigned char sense_data[18];
206  struct {
207  char reserved[4];
208  unsigned short error;
209  unsigned char status;
210  struct {
211  unsigned char severity:3;
212  unsigned char reserved:5;
213  } substatus_block;
214  } status_block;
215  unsigned char err_specific_desc[102];
217 
218 /* This struct is a union of the 2 command packets */
219 typedef struct TAG_TW_Command_Full_9000 {
221  union {
224  } command;
225  unsigned char padding[384]; /* Pad to 1024 bytes */
227 
228 typedef struct TAG_TW_Ioctl_Apache {
230  char padding[488];
232  char data_buffer[1];
233  // three bytes of padding here if structure not packed!
235 
236 
237 
238 // START OF DEFINITIONS FOR THE CHARACTER INTERFACE TO THE
239 // 6000/7000/8000 drivers
240 
241 #define TW_MAX_SGL_LENGTH 62
242 #define TW_CMD_PACKET_WITH_DATA 0x1f
243 
244 /* Command Packet */
245 typedef struct TW_Command {
246  /* First DWORD */
247  struct {
248  unsigned char opcode:5;
249  unsigned char sgl_offset:3;
250  } byte0;
251  unsigned char size;
252  unsigned char request_id;
253  struct {
254  unsigned char unit:4;
255  unsigned char host_id:4;
256  } byte3;
257  /* Second DWORD */
258  unsigned char status;
259  unsigned char flags;
260  union {
261  unsigned short block_count;
262  unsigned short parameter_count;
263  unsigned short message_credits;
264  } byte6;
265  union {
266  struct {
269  u32 padding; /* pad to 512 bytes */
270  } io;
271  struct {
273  u32 padding[2];
274  } param;
275  struct {
277  u32 padding[125];
278  } init_connection;
279  struct {
280  char version[504];
282  } byte8;
283 } TW_Command;
284 
285 typedef struct TAG_TW_New_Ioctl {
286  unsigned int data_buffer_length;
287  unsigned char padding [508];
289  char data_buffer[1];
290  // three bytes of padding here
291 } TW_New_Ioctl;
292 #pragma pack()
293 
294 #if 0
295 // Useful for checking/understanding packing of 3ware data structures
296 // above.
297 void my(int x, char *y){
298  printf("The size of %30s is: %5d\n",y, x);
299  return;
300 }
301 
302 int main() {
303  TW_Ioctl tmp;
304  my(sizeof(TW_SG_Entry),"TW_SG_Entry");
305  my(sizeof(TW_Passthru),"TW_Passthru");
306  my(sizeof(TW_Ioctl),"TW_Ioctl");
307  my(sizeof(TW_Output),"TW_Output");
308  my(sizeof(TW_Ioctl_Driver_Command_9000),"TW_Ioctl_Driver_Command_9000");
309  my(sizeof(TW_Command_9000),"TW_Command_9000");
310  my(sizeof(TW_Command_Apache),"TW_Command_Apache");
311  my(sizeof(TW_Command_Apache_Header),"TW_Command_Apache_Header");
312  my(sizeof(TW_Command_Full_9000),"TW_Command_Full_9000");
313  my(sizeof(TW_Ioctl_Buf_Apache),"TW_Ioctl_Buf_Apache");
314  my(sizeof(TW_Command),"TW_Command");
315  my(sizeof(TW_New_Ioctl),"TW_New_Ioctl");
316  printf("TW_Ioctl.table_id - start = %d (irrelevant)\n",
317  (void *)&tmp.table_id - (void *)&tmp);
318  printf("TW_Ioctl.input_data - start = %d (input passthru location)\n",
319  (void *)&tmp.input_data - (void *)&tmp);
320  printf("TW_Ioctl.output_data - start = %d (irrelevant)\n",
321  (void *)&tmp.output_data - (void *)&tmp);
322  return 0;
323 }
324 #endif
325 
326 // The following definitions are from hdreg.h in the kernel source
327 // tree. They don't carry any Copyright statements, but I think they
328 // are primarily from Mark Lord and Andre Hedrick.
329 typedef unsigned char task_ioreg_t;
330 
331 typedef struct hd_drive_task_hdr {
332  task_ioreg_t data;
333  task_ioreg_t feature;
334  task_ioreg_t sector_count;
335  task_ioreg_t sector_number;
336  task_ioreg_t low_cylinder;
337  task_ioreg_t high_cylinder;
338  task_ioreg_t device_head;
339  task_ioreg_t command;
340 } task_struct_t;
341 
342 typedef union ide_reg_valid_s {
343  unsigned all : 16;
344  struct {
345  unsigned data : 1;
346  unsigned error_feature : 1;
347  unsigned sector : 1;
348  unsigned nsector : 1;
349  unsigned lcyl : 1;
350  unsigned hcyl : 1;
351  unsigned select : 1;
352  unsigned status_command : 1;
353  unsigned data_hob : 1;
354  unsigned error_feature_hob : 1;
355  unsigned sector_hob : 1;
356  unsigned nsector_hob : 1;
357  unsigned lcyl_hob : 1;
358  unsigned hcyl_hob : 1;
359  unsigned select_hob : 1;
360  unsigned control_hob : 1;
361  } b;
363 
364 typedef struct ide_task_request_s {
365  task_ioreg_t io_ports[8];
366  task_ioreg_t hob_ports[8];
370  int req_cmd;
371  unsigned long out_size;
372  unsigned long in_size;
374 
375 #define TASKFILE_NO_DATA 0x0000
376 #define TASKFILE_IN 0x0001
377 #define TASKFILE_OUT 0x0004
378 #define HDIO_DRIVE_TASK_HDR_SIZE 8*sizeof(task_ioreg_t)
379 #define IDE_DRIVE_TASK_NO_DATA 0
380 #define IDE_DRIVE_TASK_IN 2
381 #define IDE_DRIVE_TASK_OUT 3
382 #define HDIO_DRIVE_CMD 0x031f
383 #define HDIO_DRIVE_TASK 0x031e
384 #define HDIO_DRIVE_TASKFILE 0x031d
385 #define HDIO_GET_IDENTITY 0x030d
386 
387 #define HPTIO_CTL 0x03ff // ioctl interface for HighPoint raid device
388 
389 #endif /* OS_LINUX_H_ */
unsigned char cdb[16]
Definition: os_linux.h:199
unsigned nsector_hob
Definition: os_linux.h:356
int main(int argc, char **argv)
Definition: smartctl.cpp:1302
unsigned data
Definition: os_linux.h:345
unsigned short sector_count
Definition: os_linux.h:84
unsigned char task_ioreg_t
Definition: os_linux.h:329
unsigned char padding[12]
Definition: os_linux.h:91
unsigned short table_id
Definition: os_linux.h:115
unsigned char opcode
Definition: os_linux.h:191
unsigned char sgl_offset
Definition: os_linux.h:197
unsigned char host_id
Definition: os_linux.h:158
TW_SG_Entry sg_list[TW_MAX_SGL_LENGTH_9000]
Definition: os_linux.h:200
unsigned short message_credits
Definition: os_linux.h:166
unsigned sector_hob
Definition: os_linux.h:355
TW_SG_Entry sgl[TW_MAX_SGL_LENGTH]
Definition: os_linux.h:268
struct TW_Command_9000::@49::@53 ioctl_miniport_version
struct TW_Command_9000::@49::@51 param
unsigned char unit
Definition: os_linux.h:254
unsigned long out_size
Definition: os_linux.h:371
unsigned char parameter_id
Definition: os_linux.h:116
unsigned char parameter_size_bytes
Definition: os_linux.h:117
Definition: os_linux.h:59
unsigned char status
Definition: os_linux.h:80
struct TAG_TW_Command_Apache TW_Command_Apache
struct ide_reg_valid_s::@66 b
struct TW_Command::@61::@62 io
unsigned int data_buffer_length
Definition: os_linux.h:286
task_ioreg_t sector_count
Definition: os_linux.h:334
unsigned hcyl
Definition: os_linux.h:350
int padding[2]
Definition: os_linux.h:129
task_ioreg_t command
Definition: os_linux.h:339
unsigned char flags
Definition: os_linux.h:259
struct TAG_TW_Command_Apache_Header::@55::@56 substatus_block
struct TW_Command_9000::@46 byte0
task_ioreg_t hob_ports[8]
Definition: os_linux.h:366
struct TAG_TW_Passthru TW_Passthru
struct TW_Command_9000::@49::@52 init_connection
struct TW_Command::@61::@64 init_connection
struct TAG_TW_Output TW_Output
unsigned sector
Definition: os_linux.h:347
unsigned char sgl_offset
Definition: os_linux.h:152
struct TAG_TW_Command_Apache_Header TW_Command_Apache_Header
TW_Command firmware_command
Definition: os_linux.h:288
union ide_reg_valid_s ide_reg_valid_t
unsigned nsector
Definition: os_linux.h:348
unsigned control_hob
Definition: os_linux.h:360
unsigned char status
Definition: os_linux.h:161
unsigned char size
Definition: os_linux.h:154
unsigned char err_specific_desc[102]
Definition: os_linux.h:215
unsigned short cylinder_hi
Definition: os_linux.h:87
unsigned lcyl
Definition: os_linux.h:349
unsigned hcyl_hob
Definition: os_linux.h:358
union TW_Command_9000::@48 byte6
unsigned select_hob
Definition: os_linux.h:359
unsigned char packing
Definition: os_linux.h:114
unsigned status_command
Definition: os_linux.h:352
struct TW_Command_9000 TW_Command_9000
struct TAG_TW_Command_Full_9000 TW_Command_Full_9000
unsigned char reserved
Definition: os_linux.h:192
unsigned int address
Definition: os_linux.h:60
struct TAG_TW_Ioctl_Driver_Command_9000 TW_Ioctl_Driver_Command_9000
struct TAG_TW_Command_Apache::@54 command
struct TAG_TW_Ioctl TW_Ioctl
unsigned char unit_index
Definition: os_linux.h:118
#define u32
Definition: os_linux.h:53
unsigned short message_credits
Definition: os_linux.h:263
struct TW_Command::@61::@63 param
unsigned all
Definition: os_linux.h:343
#define TW_MAX_SGL_LENGTH_9000
Definition: os_linux.h:136
unsigned char flags
Definition: os_linux.h:162
unsigned int length
Definition: os_linux.h:61
unsigned error_feature
Definition: os_linux.h:346
char padding[488]
Definition: os_linux.h:230
unsigned char request_id
Definition: os_linux.h:78
unsigned char unit
Definition: os_linux.h:79
unsigned char unit
Definition: os_linux.h:157
unsigned char opcode
Definition: os_linux.h:248
unsigned short sgl_entries
Definition: os_linux.h:198
TW_Command_Apache_Header header
Definition: os_linux.h:220
unsigned char sgloff
Definition: os_linux.h:75
struct TAG_TW_Command_Apache_Header::@55 status_block
struct TAG_TW_SG_Entry TW_SG_Entry
char version[504]
Definition: os_linux.h:183
unsigned char padding[508]
Definition: os_linux.h:287
task_ioreg_t low_cylinder
Definition: os_linux.h:336
unsigned short parameter_count
Definition: os_linux.h:165
unsigned char sense_length
Definition: os_linux.h:196
unsigned short parameter_count
Definition: os_linux.h:262
unsigned char drive_head
Definition: os_linux.h:88
unsigned long in_size
Definition: os_linux.h:372
unsigned char unit
Definition: os_linux.h:194
char version[504]
Definition: os_linux.h:280
task_ioreg_t io_ports[8]
Definition: os_linux.h:365
#define TW_MAX_SGL_LENGTH
Definition: os_linux.h:241
int output_length
Definition: os_linux.h:107
unsigned char padding[384]
Definition: os_linux.h:225
struct TW_Command TW_Command
struct TW_Command::@61::@65 ioctl_miniport_version
union TW_Command::@60 byte6
ide_reg_valid_t in_flags
Definition: os_linux.h:368
TW_Command_Full_9000 firmware_command
Definition: os_linux.h:231
unsigned char request_id
Definition: os_linux.h:252
u32 response_queue_pointer
Definition: os_linux.h:179
TW_Command_Apache newcommand
Definition: os_linux.h:223
unsigned char cdb[16]
Definition: os_linux.h:108
struct TAG_TW_Ioctl_Apache TW_Ioctl_Buf_Apache
unsigned char opcode
Definition: os_linux.h:151
union TW_Command::@61 byte8
unsigned error_feature_hob
Definition: os_linux.h:354
unsigned char output_data[512]
Definition: os_linux.h:123
unsigned short cylinder_lo
Definition: os_linux.h:86
unsigned short features
Definition: os_linux.h:83
unsigned char opcode
Definition: os_linux.h:74
task_ioreg_t feature
Definition: os_linux.h:333
struct TW_Command::@59 byte3
unsigned short block_count
Definition: os_linux.h:261
unsigned short block_count
Definition: os_linux.h:164
struct TAG_TW_New_Ioctl TW_New_Ioctl
struct TW_Command_9000::@47 byte3
struct TW_Command_9000::@49::@50 io
unsigned char command
Definition: os_linux.h:89
task_ioreg_t sector_number
Definition: os_linux.h:335
task_ioreg_t device_head
Definition: os_linux.h:338
task_ioreg_t data
Definition: os_linux.h:332
unsigned char status
Definition: os_linux.h:258
struct ide_task_request_s ide_task_request_t
unsigned char sgl_offset
Definition: os_linux.h:249
u32 padding
Definition: os_linux.h:269
char data_buffer[1]
Definition: os_linux.h:289
unsigned char host_id
Definition: os_linux.h:255
union TAG_TW_Command_Full_9000::@57 command
char data_buffer[1]
Definition: os_linux.h:232
unsigned short sector_num
Definition: os_linux.h:85
int input_length
Definition: os_linux.h:106
unsigned char size
Definition: os_linux.h:251
unsigned char sense_data[18]
Definition: os_linux.h:205
unsigned char request_id
Definition: os_linux.h:155
unsigned char size
Definition: os_linux.h:77
unsigned select
Definition: os_linux.h:351
TW_SG_Entry sg_list[TW_ATA_PASS_SGL_MAX]
Definition: os_linux.h:90
unsigned short param
Definition: os_linux.h:82
ide_reg_valid_t out_flags
Definition: os_linux.h:367
TW_Ioctl_Driver_Command_9000 driver_command
Definition: os_linux.h:229
union TW_Command_9000::@49 byte8
struct TW_Command::@58 byte0
#define TW_ATA_PASS_SGL_MAX
Definition: os_linux.h:70
task_ioreg_t high_cylinder
Definition: os_linux.h:337
char output_data[512]
Definition: os_linux.h:130
TW_Command_9000 oldcommand
Definition: os_linux.h:222
TW_SG_Entry sgl[TW_MAX_SGL_LENGTH_9000]
Definition: os_linux.h:171
unsigned short request_id
Definition: os_linux.h:195
unsigned data_hob
Definition: os_linux.h:353
unsigned char input_data[499]
Definition: os_linux.h:120
unsigned lcyl_hob
Definition: os_linux.h:357
struct hd_drive_task_hdr task_struct_t
struct TAG_TW_Passthru::@45 byte0
unsigned char flags
Definition: os_linux.h:81
unsigned char opcode
Definition: os_linux.h:109
u32 response_queue_pointer
Definition: os_linux.h:276