blob: eafb0789898817ed9602af38f7e830668f227163 [file] [log] [blame]
Eric Andersen3443bd72003-07-22 07:30:36 +00001/* vi: set sw=4 ts=4: */
2/*
3 * hdparm implementation for busybox
4 *
Glenn L McGrath5be6a202003-11-28 22:55:03 +00005 * Copyright (C) [2003] by [Matteo Croce] <3297627799@wind.it>
Glenn L McGrath07085852003-10-09 07:28:22 +00006 * Hacked by Tito <farmatito@tiscali.it> for size optimization.
Eric Andersen3443bd72003-07-22 07:30:36 +00007 *
Mike Frysingerf284c762006-04-16 20:38:26 +00008 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
Eric Andersen3443bd72003-07-22 07:30:36 +00009 *
10 * This program is based on the source code of hdparm: see below...
11 * hdparm.c - Command line interface to get/set hard disk parameters
12 * - by Mark Lord (C) 1994-2002 -- freely distributable
13 */
Glenn L McGrath07085852003-10-09 07:28:22 +000014
Bernhard Reutner-Fischerc89982d2006-06-03 19:49:21 +000015#include "busybox.h"
Eric Andersen3443bd72003-07-22 07:30:36 +000016#include <linux/hdreg.h>
Eric Andersen3443bd72003-07-22 07:30:36 +000017
Eric Andersen3443bd72003-07-22 07:30:36 +000018/* device types */
19/* ------------ */
20#define NO_DEV 0xffff
21#define ATA_DEV 0x0000
22#define ATAPI_DEV 0x0001
23
24/* word definitions */
25/* ---------------- */
26#define GEN_CONFIG 0 /* general configuration */
27#define LCYLS 1 /* number of logical cylinders */
28#define CONFIG 2 /* specific configuration */
29#define LHEADS 3 /* number of logical heads */
30#define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */
31#define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */
32#define LSECTS 6 /* number of logical sectors/track */
33#define START_SERIAL 10 /* ASCII serial number */
34#define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */
35#define BUF_TYPE 20 /* buffer type (ATA-1) */
36#define BUFFER__SIZE 21 /* buffer size (ATA-1) */
37#define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/
38#define START_FW_REV 23 /* ASCII firmware revision */
39#define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000040#define START_MODEL 27 /* ASCII model number */
41#define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */
Eric Andersen3443bd72003-07-22 07:30:36 +000042#define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */
43#define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */
44#define CAPAB_0 49 /* capabilities */
45#define CAPAB_1 50
46#define PIO_MODE 51 /* max PIO mode supported (obsolete)*/
47#define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/
48#define WHATS_VALID 53 /* what fields are valid */
49#define LCYLS_CUR 54 /* current logical cylinders */
50#define LHEADS_CUR 55 /* current logical heads */
51#define LSECTS_CUR 56 /* current logical sectors/track */
52#define CAPACITY_LSB 57 /* current capacity in sectors */
53#define CAPACITY_MSB 58
54#define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */
55#define LBA_SECTS_LSB 60 /* LBA: total number of user */
56#define LBA_SECTS_MSB 61 /* addressable sectors */
57#define SINGLE_DMA 62 /* singleword DMA modes */
58#define MULTI_DMA 63 /* multiword DMA modes */
59#define ADV_PIO_MODES 64 /* advanced PIO modes supported */
60 /* multiword DMA xfer cycle time: */
61#define DMA_TIME_MIN 65 /* - minimum */
62#define DMA_TIME_NORM 66 /* - manufacturer's recommended */
63 /* minimum PIO xfer cycle time: */
64#define PIO_NO_FLOW 67 /* - without flow control */
65#define PIO_FLOW 68 /* - with IORDY flow control */
66#define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */
67#define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */
68#define CDR_MAJOR 73 /* CD ROM: major version number */
69#define CDR_MINOR 74 /* CD ROM: minor version number */
70#define QUEUE_DEPTH 75 /* queue depth */
71#define MAJOR 80 /* major version number */
72#define MINOR 81 /* minor version number */
73#define CMDS_SUPP_0 82 /* command/feature set(s) supported */
74#define CMDS_SUPP_1 83
75#define CMDS_SUPP_2 84
76#define CMDS_EN_0 85 /* command/feature set(s) enabled */
77#define CMDS_EN_1 86
78#define CMDS_EN_2 87
79#define ULTRA_DMA 88 /* ultra DMA modes */
80 /* time to complete security erase */
81#define ERASE_TIME 89 /* - ordinary */
82#define ENH_ERASE_TIME 90 /* - enhanced */
83#define ADV_PWR 91 /* current advanced power management level
Glenn L McGrath07085852003-10-09 07:28:22 +000084 in low byte, 0x40 in high byte. */
Eric Andersen3443bd72003-07-22 07:30:36 +000085#define PSWD_CODE 92 /* master password revision code */
86#define HWRST_RSLT 93 /* hardware reset result */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000087#define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */
Eric Andersen3443bd72003-07-22 07:30:36 +000088#define LBA_LSB 100 /* LBA: maximum. Currently only 48 */
89#define LBA_MID 101 /* bits are used, but addr 103 */
90#define LBA_48_MSB 102 /* has been reserved for LBA in */
91#define LBA_64_MSB 103 /* the future. */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000092#define RM_STAT 127 /* removable media status notification feature set support */
Eric Andersen3443bd72003-07-22 07:30:36 +000093#define SECU_STATUS 128 /* security status */
94#define CFA_PWR_MODE 160 /* CFA power mode 1 */
95#define START_MEDIA 176 /* media serial number */
96#define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/
97#define START_MANUF 196 /* media manufacturer I.D. */
98#define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */
99#define INTEGRITY 255 /* integrity word */
100
101/* bit definitions within the words */
102/* -------------------------------- */
103
104/* many words are considered valid if bit 15 is 0 and bit 14 is 1 */
105#define VALID 0xc000
106#define VALID_VAL 0x4000
107/* many words are considered invalid if they are either all-0 or all-1 */
108#define NOVAL_0 0x0000
109#define NOVAL_1 0xffff
110
111/* word 0: gen_config */
Glenn L McGrath07085852003-10-09 07:28:22 +0000112#define NOT_ATA 0x8000
Eric Andersen3443bd72003-07-22 07:30:36 +0000113#define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */
114#define MEDIA_REMOVABLE 0x0080
115#define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */
116#define INCOMPLETE 0x0004
117#define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */
118#define DRQ_RESPONSE_TIME 0x0060
119#define DRQ_3MS_VAL 0x0000
120#define DRQ_INTR_VAL 0x0020
121#define DRQ_50US_VAL 0x0040
122#define PKT_SIZE_SUPPORTED 0x0003
123#define PKT_SIZE_12_VAL 0x0000
124#define PKT_SIZE_16_VAL 0x0001
125#define EQPT_TYPE 0x1f00
126#define SHIFT_EQPT 8
127
128#define CDROM 0x0005
129
130#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000131static const char * const pkt_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000132 "Direct-access device", /* word 0, bits 12-8 = 00 */
133 "Sequential-access device", /* word 0, bits 12-8 = 01 */
134 "Printer", /* word 0, bits 12-8 = 02 */
135 "Processor", /* word 0, bits 12-8 = 03 */
136 "Write-once device", /* word 0, bits 12-8 = 04 */
137 "CD-ROM", /* word 0, bits 12-8 = 05 */
138 "Scanner", /* word 0, bits 12-8 = 06 */
139 "Optical memory", /* word 0, bits 12-8 = 07 */
140 "Medium changer", /* word 0, bits 12-8 = 08 */
141 "Communications device", /* word 0, bits 12-8 = 09 */
142 "ACS-IT8 device", /* word 0, bits 12-8 = 0a */
143 "ACS-IT8 device", /* word 0, bits 12-8 = 0b */
144 "Array controller", /* word 0, bits 12-8 = 0c */
145 "Enclosure services", /* word 0, bits 12-8 = 0d */
146 "Reduced block command device", /* word 0, bits 12-8 = 0e */
147 "Optical card reader/writer", /* word 0, bits 12-8 = 0f */
148 "", /* word 0, bits 12-8 = 10 */
149 "", /* word 0, bits 12-8 = 11 */
150 "", /* word 0, bits 12-8 = 12 */
151 "", /* word 0, bits 12-8 = 13 */
152 "", /* word 0, bits 12-8 = 14 */
153 "", /* word 0, bits 12-8 = 15 */
154 "", /* word 0, bits 12-8 = 16 */
155 "", /* word 0, bits 12-8 = 17 */
156 "", /* word 0, bits 12-8 = 18 */
157 "", /* word 0, bits 12-8 = 19 */
158 "", /* word 0, bits 12-8 = 1a */
159 "", /* word 0, bits 12-8 = 1b */
160 "", /* word 0, bits 12-8 = 1c */
161 "", /* word 0, bits 12-8 = 1d */
162 "", /* word 0, bits 12-8 = 1e */
Rob Landleyadde7982006-05-16 15:32:30 +0000163 "Unknown", /* word 0, bits 12-8 = 1f */
Eric Andersen3443bd72003-07-22 07:30:36 +0000164};
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000165
166static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */
Rob Landleyadde7982006-05-16 15:32:30 +0000167 "Reserved", /* bit 0 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000168 "hard sectored", /* bit 1 */
169 "soft sectored", /* bit 2 */
170 "not MFM encoded ", /* bit 3 */
171 "head switch time > 15us", /* bit 4 */
172 "spindle motor control option", /* bit 5 */
173 "fixed drive", /* bit 6 */
174 "removable drive", /* bit 7 */
175 "disk xfer rate <= 5Mbs", /* bit 8 */
176 "disk xfer rate > 5Mbs, <= 10Mbs", /* bit 9 */
177 "disk xfer rate > 5Mbs", /* bit 10 */
178 "rotational speed tol.", /* bit 11 */
179 "data strobe offset option", /* bit 12 */
180 "track offset option", /* bit 13 */
181 "format speed tolerance gap reqd", /* bit 14 */
182 "ATAPI" /* bit 14 */
183};
184#endif
185
186/* word 1: number of logical cylinders */
187#define LCYLS_MAX 0x3fff /* maximum allowable value */
188
Eric Andersenaff114c2004-04-14 17:51:38 +0000189/* word 2: specific configuration
Eric Andersen3443bd72003-07-22 07:30:36 +0000190 * (a) require SET FEATURES to spin-up
191 * (b) require spin-up to fully reply to IDENTIFY DEVICE
192 */
193#define STBY_NID_VAL 0x37c8 /* (a) and (b) */
194#define STBY_ID_VAL 0x738c /* (a) and not (b) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000195#define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000196#define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */
197
198/* words 47 & 59: sector_xfer_max & sector_xfer_cur */
199#define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/
200#define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */
201
202/* word 49: capabilities 0 */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000203#define STD_STBY 0x2000 /* 1=standard values supported (ATA);
Eric Andersen3443bd72003-07-22 07:30:36 +0000204 0=vendor specific values */
205#define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */
206#define IORDY_OFF 0x0400 /* 1=may be disabled */
207#define LBA_SUP 0x0200 /* 1=Logical Block Address support */
208#define DMA_SUP 0x0100 /* 1=Direct Memory Access support */
209#define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */
210#define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */
211#define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */
212#define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */
213
214/* word 50: capabilities 1 */
215#define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */
216
217/* words 51 & 52: PIO & DMA cycle times */
218#define MODE 0xff00 /* the mode is in the MSBs */
219
220/* word 53: whats_valid */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000221#define OK_W88 0x0004 /* the ultra_dma info is valid */
Eric Andersen3443bd72003-07-22 07:30:36 +0000222#define OK_W64_70 0x0002 /* see above for word descriptions */
223#define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */
224
225/*word 63,88: dma_mode, ultra_dma_mode*/
226#define MODE_MAX 7 /* bit definitions force udma <=7 (when
227 * udma >=8 comes out it'll have to be
228 * defined in a new dma_mode word!) */
229
230/* word 64: PIO transfer modes */
231#define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */
232#define PIO_MODE_MAX 8 /* but all 8 bits are defined */
233
234/* word 75: queue_depth */
235#define DEPTH_BITS 0x001f /* bits used for queue depth */
236
237/* words 80-81: version numbers */
238/* NOVAL_0 or NOVAL_1 means device does not report version */
239
240/* word 81: minor version number */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000241#define MINOR_MAX 0x22
Eric Andersen3443bd72003-07-22 07:30:36 +0000242#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Rob Landley0e6a3e12006-04-28 01:33:30 +0000243static const char *minor_str[MINOR_MAX+2] = { /* word 81 value: */
244 "Unspecified", /* 0x0000 */
Rob Landleyadde7982006-05-16 15:32:30 +0000245 "ATA-1 X3T9.2 781D prior to rev.4", /* 0x0001 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000246 "ATA-1 published, ANSI X3.221-1994", /* 0x0002 */
Rob Landleyadde7982006-05-16 15:32:30 +0000247 "ATA-1 X3T9.2 781D rev.4", /* 0x0003 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000248 "ATA-2 published, ANSI X3.279-1996", /* 0x0004 */
Rob Landleyadde7982006-05-16 15:32:30 +0000249 "ATA-2 X3T10 948D prior to rev.2k", /* 0x0005 */
250 "ATA-3 X3T10 2008D rev.1", /* 0x0006 */
251 "ATA-2 X3T10 948D rev.2k", /* 0x0007 */
252 "ATA-3 X3T10 2008D rev.0", /* 0x0008 */
253 "ATA-2 X3T10 948D rev.3", /* 0x0009 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000254 "ATA-3 published, ANSI X3.298-199x", /* 0x000a */
Rob Landleyadde7982006-05-16 15:32:30 +0000255 "ATA-3 X3T10 2008D rev.6", /* 0x000b */
256 "ATA-3 X3T13 2008D rev.7 and 7a", /* 0x000c */
257 "ATA/ATAPI-4 X3T13 1153D rev.6", /* 0x000d */
258 "ATA/ATAPI-4 T13 1153D rev.13", /* 0x000e */
259 "ATA/ATAPI-4 X3T13 1153D rev.7", /* 0x000f */
260 "ATA/ATAPI-4 T13 1153D rev.18", /* 0x0010 */
261 "ATA/ATAPI-4 T13 1153D rev.15", /* 0x0011 */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000262 "ATA/ATAPI-4 published, ANSI INCITS 317-1998", /* 0x0012 */
Rob Landleyadde7982006-05-16 15:32:30 +0000263 "ATA/ATAPI-5 T13 1321D rev.3",
264 "ATA/ATAPI-4 T13 1153D rev.14", /* 0x0014 */
265 "ATA/ATAPI-5 T13 1321D rev.1", /* 0x0015 */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000266 "ATA/ATAPI-5 published, ANSI INCITS 340-2000", /* 0x0016 */
Rob Landleyadde7982006-05-16 15:32:30 +0000267 "ATA/ATAPI-4 T13 1153D rev.17", /* 0x0017 */
268 "ATA/ATAPI-6 T13 1410D rev.0", /* 0x0018 */
269 "ATA/ATAPI-6 T13 1410D rev.3a", /* 0x0019 */
270 "ATA/ATAPI-7 T13 1532D rev.1", /* 0x001a */
271 "ATA/ATAPI-6 T13 1410D rev.2", /* 0x001b */
272 "ATA/ATAPI-6 T13 1410D rev.1", /* 0x001c */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000273 "ATA/ATAPI-7 published, ANSI INCITS 397-2005", /* 0x001d */
Rob Landleyadde7982006-05-16 15:32:30 +0000274 "ATA/ATAPI-7 T13 1532D rev.0", /* 0x001e */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000275 "Reserved" /* 0x001f */
276 "Reserved" /* 0x0020 */
Rob Landleyadde7982006-05-16 15:32:30 +0000277 "ATA/ATAPI-7 T13 1532D rev.4a", /* 0x0021 */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000278 "ATA/ATAPI-6 published, ANSI INCITS 361-2002", /* 0x0022 */
279 "Reserved" /* 0x0023-0xfffe*/
Eric Andersen3443bd72003-07-22 07:30:36 +0000280};
281#endif
Rob Landley0e6a3e12006-04-28 01:33:30 +0000282static const char actual_ver[MINOR_MAX+2] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000283 /* word 81 value: */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000284 0, /* 0x0000 WARNING: */
285 1, /* 0x0001 WARNING: */
286 1, /* 0x0002 WARNING: */
287 1, /* 0x0003 WARNING: */
288 2, /* 0x0004 WARNING: This array */
289 2, /* 0x0005 WARNING: corresponds */
Eric Andersen3443bd72003-07-22 07:30:36 +0000290 3, /* 0x0006 WARNING: *exactly* */
291 2, /* 0x0007 WARNING: to the ATA/ */
292 3, /* 0x0008 WARNING: ATAPI version */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000293 2, /* 0x0009 WARNING: listed in */
294 3, /* 0x000a WARNING: the */
295 3, /* 0x000b WARNING: minor_str */
Eric Andersen3443bd72003-07-22 07:30:36 +0000296 3, /* 0x000c WARNING: array */
297 4, /* 0x000d WARNING: above. */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000298 4, /* 0x000e WARNING: */
299 4, /* 0x000f WARNING: if you change */
300 4, /* 0x0010 WARNING: that one, */
Eric Andersen3443bd72003-07-22 07:30:36 +0000301 4, /* 0x0011 WARNING: change this one */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000302 4, /* 0x0012 WARNING: too!!! */
Eric Andersen3443bd72003-07-22 07:30:36 +0000303 5, /* 0x0013 WARNING: */
304 4, /* 0x0014 WARNING: */
305 5, /* 0x0015 WARNING: */
306 5, /* 0x0016 WARNING: */
307 4, /* 0x0017 WARNING: */
308 6, /* 0x0018 WARNING: */
309 6, /* 0x0019 WARNING: */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000310 7, /* 0x001a WARNING: */
Eric Andersen3443bd72003-07-22 07:30:36 +0000311 6, /* 0x001b WARNING: */
312 6, /* 0x001c WARNING: */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000313 7, /* 0x001d WARNING: */
314 7, /* 0x001e WARNING: */
315 0, /* 0x001f WARNING: */
316 0, /* 0x0020 WARNING: */
317 7, /* 0x0021 WARNING: */
318 6, /* 0x0022 WARNING: */
319 0 /* 0x0023-0xfffe */
Eric Andersen3443bd72003-07-22 07:30:36 +0000320};
321
322/* words 82-84: cmds/feats supported */
323#define CMDS_W82 0x77ff /* word 82: defined command locations*/
324#define CMDS_W83 0x3fff /* word 83: defined command locations*/
325#define CMDS_W84 0x002f /* word 83: defined command locations*/
Glenn L McGrath07085852003-10-09 07:28:22 +0000326#define SUPPORT_48_BIT 0x0400
Eric Andersen3443bd72003-07-22 07:30:36 +0000327#define NUM_CMD_FEAT_STR 48
328
329#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000330static const char * const cmd_feat_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000331 "", /* word 82 bit 15: obsolete */
332 "NOP cmd", /* word 82 bit 14 */
333 "READ BUFFER cmd", /* word 82 bit 13 */
334 "WRITE BUFFER cmd", /* word 82 bit 12 */
335 "", /* word 82 bit 11: obsolete */
336 "Host Protected Area feature set", /* word 82 bit 10 */
337 "DEVICE RESET cmd", /* word 82 bit 9 */
338 "SERVICE interrupt", /* word 82 bit 8 */
339 "Release interrupt", /* word 82 bit 7 */
340 "Look-ahead", /* word 82 bit 6 */
341 "Write cache", /* word 82 bit 5 */
342 "PACKET command feature set", /* word 82 bit 4 */
343 "Power Management feature set", /* word 82 bit 3 */
344 "Removable Media feature set", /* word 82 bit 2 */
345 "Security Mode feature set", /* word 82 bit 1 */
346 "SMART feature set", /* word 82 bit 0 */
347 /* --------------*/
348 "", /* word 83 bit 15: !valid bit */
349 "", /* word 83 bit 14: valid bit */
Rob Landleyadde7982006-05-16 15:32:30 +0000350 "FLUSH CACHE EXT cmd", /* word 83 bit 13 */
351 "Mandatory FLUSH CACHE cmd ", /* word 83 bit 12 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000352 "Device Configuration Overlay feature set ",
353 "48-bit Address feature set ", /* word 83 bit 10 */
354 "",
355 "SET MAX security extension", /* word 83 bit 8 */
356 "Address Offset Reserved Area Boot", /* word 83 bit 7 */
357 "SET FEATURES subcommand required to spinup after power up",
358 "Power-Up In Standby feature set", /* word 83 bit 5 */
359 "Removable Media Status Notification feature set",
Eric Andersen06d4ec22004-03-19 10:53:52 +0000360 "Adv. Power Management feature set",/* word 83 bit 3 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000361 "CFA feature set", /* word 83 bit 2 */
362 "READ/WRITE DMA QUEUED", /* word 83 bit 1 */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000363 "DOWNLOAD MICROCODE cmd", /* word 83 bit 0 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000364 /* --------------*/
365 "", /* word 84 bit 15: !valid bit */
366 "", /* word 84 bit 14: valid bit */
367 "", /* word 84 bit 13: reserved */
368 "", /* word 84 bit 12: reserved */
369 "", /* word 84 bit 11: reserved */
370 "", /* word 84 bit 10: reserved */
371 "", /* word 84 bit 9: reserved */
372 "", /* word 84 bit 8: reserved */
373 "", /* word 84 bit 7: reserved */
374 "", /* word 84 bit 6: reserved */
375 "General Purpose Logging feature set", /* word 84 bit 5 */
376 "", /* word 84 bit 4: reserved */
377 "Media Card Pass Through Command feature set ",
378 "Media serial number ", /* word 84 bit 2 */
379 "SMART self-test ", /* word 84 bit 1 */
380 "SMART error logging " /* word 84 bit 0 */
381};
Rob Landley0f0b6452006-05-03 18:28:06 +0000382
383static void identify(uint16_t *id_supplied) ATTRIBUTE_NORETURN;
384static void identify_from_stdin(void) ATTRIBUTE_NORETURN;
Rob Landley9c6f9552006-06-08 14:11:36 +0000385#else
386void identify_from_stdin(void);
Eric Andersen3443bd72003-07-22 07:30:36 +0000387#endif
388
389
390/* words 85-87: cmds/feats enabled */
391/* use cmd_feat_str[] to display what commands and features have
Glenn L McGrath07085852003-10-09 07:28:22 +0000392 * been enabled with words 85-87
Eric Andersen3443bd72003-07-22 07:30:36 +0000393 */
394
395/* words 89, 90, SECU ERASE TIME */
396#define ERASE_BITS 0x00ff
397
398/* word 92: master password revision */
399/* NOVAL_0 or NOVAL_1 means no support for master password revision */
400
401/* word 93: hw reset result */
402#define CBLID 0x2000 /* CBLID status */
403#define RST0 0x0001 /* 1=reset to device #0 */
404#define DEV_DET 0x0006 /* how device num determined */
405#define JUMPER_VAL 0x0002 /* device num determined by jumper */
406#define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */
407
408/* word 127: removable media status notification feature set support */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000409#define RM_STAT_BITS 0x0003
Eric Andersen3443bd72003-07-22 07:30:36 +0000410#define RM_STAT_SUP 0x0001
Glenn L McGrath07085852003-10-09 07:28:22 +0000411
Eric Andersen3443bd72003-07-22 07:30:36 +0000412/* word 128: security */
413#define SECU_ENABLED 0x0002
414#define SECU_LEVEL 0x0010
415#define NUM_SECU_STR 6
416#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000417static const char * const secu_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000418 "supported", /* word 128, bit 0 */
419 "enabled", /* word 128, bit 1 */
420 "locked", /* word 128, bit 2 */
421 "frozen", /* word 128, bit 3 */
422 "expired: security count", /* word 128, bit 4 */
423 "supported: enhanced erase" /* word 128, bit 5 */
424};
425#endif
426
427/* word 160: CFA power mode */
428#define VALID_W160 0x8000 /* 1=word valid */
429#define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/
430#define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */
431#define MAX_AMPS 0x0fff /* value = max current in ma */
432
433/* word 255: integrity */
434#define SIG 0x00ff /* signature location */
435#define SIG_VAL 0x00A5 /* signature value */
436
Glenn L McGrath07085852003-10-09 07:28:22 +0000437#define TIMING_MB 64
438#define TIMING_BUF_MB 1
439#define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024)
440#define TIMING_BUF_COUNT (timing_MB / TIMING_BUF_MB)
441#define BUFCACHE_FACTOR 2
442
443#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
444
445/* Busybox messages and functions */
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000446static int bb_ioctl(int fd, int request, void *argp, const char *string)
Glenn L McGrath07085852003-10-09 07:28:22 +0000447{
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000448 int e = ioctl(fd, request, argp);
449 if (e && string)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000450 bb_perror_msg(" %s", string);
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000451 return e;
Glenn L McGrath07085852003-10-09 07:28:22 +0000452}
453
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000454static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const char *string)
455{
456 if (!ioctl(fd, cmd, args))
457 return 0;
458 args[0] = alt;
459 return bb_ioctl(fd, cmd, args, string);
460}
461
Rob Landleya3e4f382006-04-29 16:06:31 +0000462static void on_off(unsigned int value);
Glenn L McGrath07085852003-10-09 07:28:22 +0000463
Rob Landleyadde7982006-05-16 15:32:30 +0000464static void print_flag_on_off(unsigned long get_arg, const char *s, unsigned long arg)
Glenn L McGrath07085852003-10-09 07:28:22 +0000465{
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000466 if (get_arg) {
Rob Landleyadde7982006-05-16 15:32:30 +0000467 printf(" setting %s to %ld", s, arg);
Glenn L McGrath07085852003-10-09 07:28:22 +0000468 on_off(arg);
469 }
470}
471
472static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string,
Rob Landleyadde7982006-05-16 15:32:30 +0000473 const char * str)
Glenn L McGrath07085852003-10-09 07:28:22 +0000474{
Rob Landleya3e4f382006-04-29 16:06:31 +0000475 if (ioctl(fd, request, &argp) != 0)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000476 bb_perror_msg(" %s", string);
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000477 else {
Rob Landleyadde7982006-05-16 15:32:30 +0000478 printf(" %s\t= %2ld", str, (unsigned long) argp);
Glenn L McGrath07085852003-10-09 07:28:22 +0000479 on_off((unsigned long) argp);
480 }
481}
Eric Andersen416c2422003-12-12 00:08:57 +0000482
483#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000484static void print_ascii(uint16_t *p, uint8_t length);
485
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000486static void xprint_ascii(uint16_t *val ,int i, const char *string, int n)
Glenn L McGrath07085852003-10-09 07:28:22 +0000487{
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000488 if (val[i]) {
489 printf("\t%-20s", string);
Glenn L McGrath07085852003-10-09 07:28:22 +0000490 print_ascii(&val[i], n);
491 }
492}
Eric Andersen416c2422003-12-12 00:08:57 +0000493#endif
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000494/* end of busybox specific stuff */
Glenn L McGrath07085852003-10-09 07:28:22 +0000495
Eric Andersen3443bd72003-07-22 07:30:36 +0000496#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000497static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
498{
Eric Andersen3443bd72003-07-22 07:30:36 +0000499 uint16_t ii;
500 uint8_t err_dma = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000501
Rob Landleya3e4f382006-04-29 16:06:31 +0000502 for (ii = 0; ii <= MODE_MAX; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000503 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000504 if (mode_sel & 0x0001)
Glenn L McGrath07085852003-10-09 07:28:22 +0000505 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000506 printf("*%cdma%u ",cc,ii);
Rob Landleya3e4f382006-04-29 16:06:31 +0000507 if (*have_mode)
Glenn L McGrath07085852003-10-09 07:28:22 +0000508 err_dma = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000509 *have_mode = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000510 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000511 else if (mode_sup & 0x0001)
Glenn L McGrath07085852003-10-09 07:28:22 +0000512 printf("%cdma%u ",cc,ii);
513
514 mode_sup >>=1;
515 mode_sel >>=1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000516 }
517 return err_dma;
518}
Glenn L McGrath07085852003-10-09 07:28:22 +0000519
Eric Andersen3443bd72003-07-22 07:30:36 +0000520static void print_ascii(uint16_t *p, uint8_t length) {
521 uint8_t ii;
522 char cl;
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000523
Eric Andersen3443bd72003-07-22 07:30:36 +0000524 /* find first non-space & print it */
Rob Landleya3e4f382006-04-29 16:06:31 +0000525 for (ii = 0; ii< length; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000526 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000527 if (((char) 0x00ff&((*p)>>8)) != ' ')
Glenn L McGrath07085852003-10-09 07:28:22 +0000528 break;
Rob Landleya3e4f382006-04-29 16:06:31 +0000529 if ((cl = (char) 0x00ff&(*p)) != ' ')
Glenn L McGrath07085852003-10-09 07:28:22 +0000530 {
Rob Landleyadde7982006-05-16 15:32:30 +0000531 if (cl != '\0') printf("%c",cl);
Glenn L McGrath07085852003-10-09 07:28:22 +0000532 p++;
533 ii++;
Eric Andersen3443bd72003-07-22 07:30:36 +0000534 break;
535 }
536 p++;
537 }
538 /* print the rest */
Rob Landleya3e4f382006-04-29 16:06:31 +0000539 for (; ii< length; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000540 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000541 if (!(*p))
Glenn L McGrath07085852003-10-09 07:28:22 +0000542 break; /* some older devices have NULLs */
Eric Andersen3443bd72003-07-22 07:30:36 +0000543 printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff);
544 p++;
545 }
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000546 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +0000547}
548
Rob Landley0753f4a2006-06-07 00:27:25 +0000549// Parse 512 byte disk identification block and print much crap.
550
Rob Landley6389ff12006-05-01 19:28:53 +0000551static void identify(uint16_t *id_supplied)
Eric Andersen3443bd72003-07-22 07:30:36 +0000552{
Rob Landley5bc3f052006-04-29 19:11:24 +0000553 uint16_t buf[256];
554 uint16_t *val, ii, jj, kk;
Eric Andersen3443bd72003-07-22 07:30:36 +0000555 uint16_t like_std = 1, std = 0, min_std = 0xffff;
556 uint16_t dev = NO_DEV, eqpt = NO_DEV;
557 uint8_t have_mode = 0, err_dma = 0;
558 uint8_t chksum = 0;
559 uint32_t ll, mm, nn, oo;
Rob Landley2e2d7522006-04-29 15:23:33 +0000560 uint64_t bbbig; /* (:) */
Rob Landleyadde7982006-05-16 15:32:30 +0000561 const char *strng;
Eric Andersen3443bd72003-07-22 07:30:36 +0000562
Rob Landley0753f4a2006-06-07 00:27:25 +0000563 // Adjust for endianness if necessary.
564
Rob Landley5bc3f052006-04-29 19:11:24 +0000565 if (BB_BIG_ENDIAN) {
566 swab(id_supplied, buf, sizeof(buf));
567 val = buf;
568 } else val = id_supplied;
569
Eric Andersen3443bd72003-07-22 07:30:36 +0000570 chksum &= 0xff;
571
572 /* check if we recognise the device type */
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000573 puts("");
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000574 if (!(val[GEN_CONFIG] & NOT_ATA))
Glenn L McGrath07085852003-10-09 07:28:22 +0000575 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000576 dev = ATA_DEV;
577 printf("ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000578 }
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000579 else if (val[GEN_CONFIG]==CFA_SUPPORT_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +0000580 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000581 dev = ATA_DEV;
582 like_std = 4;
583 printf("CompactFlash ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000584 }
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000585 else if (!(val[GEN_CONFIG] & NOT_ATAPI))
Glenn L McGrath07085852003-10-09 07:28:22 +0000586 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000587 dev = ATAPI_DEV;
588 eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
589 printf("ATAPI %s, with ", pkt_str[eqpt]);
590 like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000591 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000592 else
593 /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +0000594 bb_error_msg_and_die("unknown device type");
Eric Andersen3443bd72003-07-22 07:30:36 +0000595
Rob Landleyadde7982006-05-16 15:32:30 +0000596 printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : "");
Eric Andersen3443bd72003-07-22 07:30:36 +0000597 /* Info from the specific configuration word says whether or not the
598 * ID command completed correctly. It is only defined, however in
Glenn L McGrath07085852003-10-09 07:28:22 +0000599 * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior
Eric Andersen3443bd72003-07-22 07:30:36 +0000600 * standards. Since the values allowed for this word are extremely
601 * specific, it should be safe to check it now, even though we don't
602 * know yet what standard this device is using.
603 */
Rob Landleya3e4f382006-04-29 16:06:31 +0000604 if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000605 (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) )
606 {
607 like_std = 5;
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000608 if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
Rob Landleyadde7982006-05-16 15:32:30 +0000609 printf("powers-up in standby; SET FEATURES subcmd spins-up.\n");
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000610 if (((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
Rob Landleyadde7982006-05-16 15:32:30 +0000611 printf("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000612 }
613
614 /* output the model and serial numbers and the fw revision */
Glenn L McGrath07085852003-10-09 07:28:22 +0000615 xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL);
616 xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL);
617 xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV);
618 xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA);
619 xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF);
Eric Andersen3443bd72003-07-22 07:30:36 +0000620
621 /* major & minor standards version number (Note: these words were not
622 * defined until ATA-3 & the CDROM std uses different words.) */
623 printf("Standards:");
Rob Landleya3e4f382006-04-29 16:06:31 +0000624 if (eqpt != CDROM)
Glenn L McGrath07085852003-10-09 07:28:22 +0000625 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000626 if (val[MINOR] && (val[MINOR] <= MINOR_MAX))
Glenn L McGrath07085852003-10-09 07:28:22 +0000627 {
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000628 if (like_std < 3) like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000629 std = actual_ver[val[MINOR]];
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000630 if (std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]);
Glenn L McGrath07085852003-10-09 07:28:22 +0000631
Eric Andersen3443bd72003-07-22 07:30:36 +0000632 }
633 /* looks like when they up-issue the std, they obsolete one;
Glenn L McGrath07085852003-10-09 07:28:22 +0000634 * thus, only the newest 4 issues need be supported. (That's
Eric Andersen3443bd72003-07-22 07:30:36 +0000635 * what "kk" and "min_std" are all about.) */
Rob Landleya3e4f382006-04-29 16:06:31 +0000636 if (val[MAJOR] && (val[MAJOR] !=NOVAL_1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000637 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000638 printf("\n\tSupported: ");
639 jj = val[MAJOR] << 1;
640 kk = like_std >4 ? like_std-4: 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000641 for (ii = 14; (ii >0)&&(ii>kk); ii--)
Glenn L McGrath07085852003-10-09 07:28:22 +0000642 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000643 if (jj & 0x8000)
Glenn L McGrath07085852003-10-09 07:28:22 +0000644 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000645 printf("%u ", ii);
Rob Landleya3e4f382006-04-29 16:06:31 +0000646 if (like_std < ii)
Glenn L McGrath07085852003-10-09 07:28:22 +0000647 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000648 like_std = ii;
649 kk = like_std >4 ? like_std-4: 0;
650 }
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000651 if (min_std > ii) min_std = ii;
Eric Andersen3443bd72003-07-22 07:30:36 +0000652 }
653 jj <<= 1;
654 }
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000655 if (like_std < 3) like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000656 }
657 /* Figure out what standard the device is using if it hasn't told
658 * us. If we know the std, check if the device is using any of
659 * the words from the next level up. It happens.
660 */
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000661 if (like_std < std) like_std = std;
Glenn L McGrath07085852003-10-09 07:28:22 +0000662
Rob Landleya3e4f382006-04-29 16:06:31 +0000663 if (((std == 5) || (!std && (like_std < 6))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000664 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
665 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) ||
666 ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) &&
667 ( val[CMDS_SUPP_2] & CMDS_W84) ) ) )
668 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000669 like_std = 6;
Glenn L McGrath07085852003-10-09 07:28:22 +0000670 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000671 else if (((std == 4) || (!std && (like_std < 5))) &&
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000672 ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000673 (( val[HWRST_RSLT] & VALID) == VALID_VAL) ||
674 ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
675 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) )
676 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000677 like_std = 5;
Glenn L McGrath07085852003-10-09 07:28:22 +0000678 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000679 else if (((std == 3) || (!std && (like_std < 4))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000680 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
681 ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) ||
682 (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) ||
683 (( val[CAPAB_1] & VALID) == VALID_VAL) ||
684 (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) ||
685 (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) )
686 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000687 like_std = 4;
Glenn L McGrath07085852003-10-09 07:28:22 +0000688 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000689 else if (((std == 2) || (!std && (like_std < 3))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000690 ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) )
691 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000692 like_std = 3;
Glenn L McGrath07085852003-10-09 07:28:22 +0000693 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000694 else if (((std == 1) || (!std && (like_std < 2))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000695 ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) ||
696 (val[WHATS_VALID] & OK_W64_70)) )
697 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000698 like_std = 2;
699 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000700 if (!std)
Eric Andersen3443bd72003-07-22 07:30:36 +0000701 printf("\n\tLikely used: %u\n",like_std);
Rob Landleya3e4f382006-04-29 16:06:31 +0000702 else if (like_std > std)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000703 printf("& some of %u\n",like_std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000704 else
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000705 puts("");
Glenn L McGrath07085852003-10-09 07:28:22 +0000706 }
707 else
708 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000709 /* TBD: do CDROM stuff more thoroughly. For now... */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000710 kk = 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000711 if (val[CDR_MINOR] == 9)
Glenn L McGrath07085852003-10-09 07:28:22 +0000712 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000713 kk = 1;
714 printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5");
715 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000716 if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000717 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000718 kk = 1;
719 printf("\n\tSupported: CD-ROM ATAPI");
720 jj = val[CDR_MAJOR] >> 1;
Rob Landleya3e4f382006-04-29 16:06:31 +0000721 for (ii = 1; ii <15; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000722 {
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000723 if (jj & 0x0001) printf("-%u ", ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000724 jj >>= 1;
725 }
726 }
Rob Landleyadde7982006-05-16 15:32:30 +0000727 printf("%s\n", (!kk) ? "\n\tLikely used CD-ROM ATAPI-1" : "" );
Eric Andersen3443bd72003-07-22 07:30:36 +0000728 /* the cdrom stuff is more like ATA-2 than anything else, so: */
729 like_std = 2;
730 }
731
Rob Landleya3e4f382006-04-29 16:06:31 +0000732 if (min_std == 0xffff)
Glenn L McGrath07085852003-10-09 07:28:22 +0000733 min_std = like_std > 4 ? like_std - 3 : 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000734
735 printf("Configuration:\n");
736 /* more info from the general configuration word */
Rob Landleya3e4f382006-04-29 16:06:31 +0000737 if ((eqpt != CDROM) && (like_std == 1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000738 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000739 jj = val[GEN_CONFIG] >> 1;
Rob Landleya3e4f382006-04-29 16:06:31 +0000740 for (ii = 1; ii < 15; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000741 {
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000742 if (jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000743 jj >>=1;
744 }
745 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000746 if (dev == ATAPI_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000747 {
Rob Landleyadde7982006-05-16 15:32:30 +0000748 if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_3MS_VAL)
749 strng = "3ms";
750 else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_INTR_VAL)
751 strng = "<=10ms with INTRQ";
752 else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_50US_VAL)
753 strng ="50us";
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000754 else
Rob Landleyadde7982006-05-16 15:32:30 +0000755 strng = "Unknown";
756 printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */
757
758 if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_12_VAL)
759 strng = "12 bytes";
760 else if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_16_VAL)
761 strng = "16 bytes";
762 else
763 strng = "Unknown";
764 puts(strng);
Glenn L McGrath07085852003-10-09 07:28:22 +0000765 }
766 else
767 {
768 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000769 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
770 mm = 0; bbbig = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000771 if ( (ll > 0x00FBFC10) && (!val[LCYLS]))
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000772 printf("\tCHS addressing not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000773 else
774 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000775 jj = val[WHATS_VALID] & OK_W54_58;
Glenn L McGrath07085852003-10-09 07:28:22 +0000776 printf("\tLogical\t\tmax\tcurrent\n\tcylinders\t%u\t%u\n\theads\t\t%u\t%u\n\tsectors/track\t%u\t%u\n\t--\n",
777 val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0);
778
Rob Landleyadde7982006-05-16 15:32:30 +0000779 if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES]))
780 printf("\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]);
Glenn L McGrath07085852003-10-09 07:28:22 +0000781
Rob Landleya3e4f382006-04-29 16:06:31 +0000782 if (jj)
Glenn L McGrath07085852003-10-09 07:28:22 +0000783 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000784 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
Rob Landleya3e4f382006-04-29 16:06:31 +0000785 if (like_std < 3)
Glenn L McGrath07085852003-10-09 07:28:22 +0000786 {
787 /* check Endian of capacity bytes */
Eric Andersen3443bd72003-07-22 07:30:36 +0000788 nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR];
789 oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB];
Rob Landleya3e4f382006-04-29 16:06:31 +0000790 if (abs(mm - nn) > abs(oo - nn))
Eric Andersen3443bd72003-07-22 07:30:36 +0000791 mm = oo;
792 }
793 printf("\tCHS current addressable sectors:%11u\n",mm);
Glenn L McGrath07085852003-10-09 07:28:22 +0000794 }
Eric Andersen3443bd72003-07-22 07:30:36 +0000795 }
796 /* LBA addressing */
797 printf("\tLBA user addressable sectors:%11u\n",ll);
Rob Landleya3e4f382006-04-29 16:06:31 +0000798 if ( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000799 (val[CMDS_SUPP_1] & SUPPORT_48_BIT) )
800 {
Rob Landley2e2d7522006-04-29 15:23:33 +0000801 bbbig = (uint64_t)val[LBA_64_MSB] << 48 |
802 (uint64_t)val[LBA_48_MSB] << 32 |
803 (uint64_t)val[LBA_MID] << 16 |
Glenn L McGrath07085852003-10-09 07:28:22 +0000804 val[LBA_LSB] ;
Rob Landley81dab2c2006-05-28 01:56:08 +0000805 printf("\tLBA48 user addressable sectors:%11"PRIu64"\n",bbbig);
Eric Andersen3443bd72003-07-22 07:30:36 +0000806 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000807
808 if (!bbbig)
Rob Landley2e2d7522006-04-29 15:23:33 +0000809 bbbig = (uint64_t)(ll>mm ? ll : mm); /* # 512 byte blocks */
Rob Landley81dab2c2006-05-28 01:56:08 +0000810 printf("\tdevice size with M = 1024*1024: %11"PRIu64" MBytes\n",bbbig>>11);
Eric Andersen3443bd72003-07-22 07:30:36 +0000811 bbbig = (bbbig<<9)/1000000;
Rob Landley81dab2c2006-05-28 01:56:08 +0000812 printf("\tdevice size with M = 1000*1000: %11"PRIu64" MBytes ",bbbig);
Glenn L McGrath07085852003-10-09 07:28:22 +0000813
Rob Landleyadde7982006-05-16 15:32:30 +0000814 if (bbbig > 1000)
Rob Landley81dab2c2006-05-28 01:56:08 +0000815 printf("(%"PRIu64" GB)\n", bbbig/1000);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000816 else
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000817 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +0000818 }
819
820 /* hw support of commands (capabilities) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000821 printf("Capabilities:\n\t");
822
Rob Landleya3e4f382006-04-29 16:06:31 +0000823 if (dev == ATAPI_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000824 {
Rob Landleyadde7982006-05-16 15:32:30 +0000825 if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) printf("Cmd queuing, ");
826 if (val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, ");
Eric Andersen3443bd72003-07-22 07:30:36 +0000827 }
Rob Landleyadde7982006-05-16 15:32:30 +0000828 if (val[CAPAB_0] & LBA_SUP) printf("LBA, ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000829
Rob Landleya3e4f382006-04-29 16:06:31 +0000830 if (like_std != 1)
Glenn L McGrath07085852003-10-09 07:28:22 +0000831 {
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000832 printf("IORDY%s(can%s be disabled)\n",
833 !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
Rob Landleyadde7982006-05-16 15:32:30 +0000834 (val[CAPAB_0] & IORDY_OFF) ? "" :"not");
Glenn L McGrath07085852003-10-09 07:28:22 +0000835 }
836 else
837 printf("no IORDY\n");
838
Rob Landleya3e4f382006-04-29 16:06:31 +0000839 if ((like_std == 1) && val[BUF_TYPE])
Glenn L McGrath07085852003-10-09 07:28:22 +0000840 {
Rob Landleyadde7982006-05-16 15:32:30 +0000841 printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE],
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000842 (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector",
Rob Landleyadde7982006-05-16 15:32:30 +0000843 (val[BUF_TYPE] > 2) ? " with read caching ability" : "");
Eric Andersen3443bd72003-07-22 07:30:36 +0000844 }
Rob Landleyadde7982006-05-16 15:32:30 +0000845
Rob Landleya3e4f382006-04-29 16:06:31 +0000846 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1)))
Glenn L McGrath07085852003-10-09 07:28:22 +0000847 {
Rob Landleyadde7982006-05-16 15:32:30 +0000848 printf("\tBuffer size: %.1fkB\n",(float)val[BUFFER__SIZE]/2);
Eric Andersen3443bd72003-07-22 07:30:36 +0000849 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000850 if ((min_std < 4) && (val[RW_LONG]))
Glenn L McGrath07085852003-10-09 07:28:22 +0000851 {
Rob Landleyadde7982006-05-16 15:32:30 +0000852 printf("\tbytes avail on r/w long: %u\n",val[RW_LONG]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000853 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000854 if ((eqpt != CDROM) && (like_std > 3))
Glenn L McGrath07085852003-10-09 07:28:22 +0000855 {
Rob Landleyadde7982006-05-16 15:32:30 +0000856 printf("\tQueue depth: %u\n",(val[QUEUE_DEPTH] & DEPTH_BITS)+1);
Eric Andersen3443bd72003-07-22 07:30:36 +0000857 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000858
Rob Landleya3e4f382006-04-29 16:06:31 +0000859 if (dev == ATA_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000860 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000861 if (like_std == 1)
Glenn L McGrath07085852003-10-09 07:28:22 +0000862 printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":"");
863 else
864 {
Rob Landleyadde7982006-05-16 15:32:30 +0000865 printf("\tStandby timer values: spec'd by %s", (val[CAPAB_0] & STD_STBY) ? "Standard" : "Vendor");
Rob Landleya3e4f382006-04-29 16:06:31 +0000866 if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
Glenn L McGrath07085852003-10-09 07:28:22 +0000867 printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no");
868 else
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000869 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +0000870 }
871 printf("\tR/W multiple sector transfer: ");
Rob Landleya3e4f382006-04-29 16:06:31 +0000872 if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
Eric Andersen3443bd72003-07-22 07:30:36 +0000873 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000874 else
875 {
876 printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER);
Rob Landleyadde7982006-05-16 15:32:30 +0000877 if (val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID)
878 printf("%u\n", val[SECTOR_XFER_CUR] & SECTOR_XFER);
879 else
880 printf("?\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000881 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000882 if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008))
Glenn L McGrath07085852003-10-09 07:28:22 +0000883 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000884 /* We print out elsewhere whether the APM feature is enabled or
885 not. If it's not enabled, let's not repeat the info; just print
886 nothing here. */
Glenn L McGrath07085852003-10-09 07:28:22 +0000887 printf("\tAdvancedPM level: ");
888 if ( (val[ADV_PWR] & 0xFF00) == 0x4000 )
889 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000890 uint8_t apm_level = val[ADV_PWR] & 0x00FF;
Eric Andersen3443bd72003-07-22 07:30:36 +0000891 printf("%u (0x%x)\n", apm_level, apm_level);
Glenn L McGrath07085852003-10-09 07:28:22 +0000892 }
893 else
Eric Andersen3443bd72003-07-22 07:30:36 +0000894 printf("unknown setting (0x%04x)\n", val[ADV_PWR]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000895 }
Rob Landleyadde7982006-05-16 15:32:30 +0000896 if (like_std > 5 && val[ACOUSTIC]) {
897 printf("\tRecommended acoustic management value: %u, current value: %u\n",
Glenn L McGrath07085852003-10-09 07:28:22 +0000898 (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff);
Eric Andersen3443bd72003-07-22 07:30:36 +0000899 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000900 }
901 else
902 {
903 /* ATAPI */
Rob Landleyadde7982006-05-16 15:32:30 +0000904 if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ))
905 printf("\tATA sw reset required\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000906
Rob Landleya3e4f382006-04-29 16:06:31 +0000907 if (val[PKT_REL] || val[SVC_NBSY])
Glenn L McGrath07085852003-10-09 07:28:22 +0000908 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000909 printf("\tOverlap support:");
Rob Landleyadde7982006-05-16 15:32:30 +0000910 if (val[PKT_REL]) printf(" %uus to release bus.",val[PKT_REL]);
911 if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]);
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000912 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +0000913 }
914 }
915
916 /* DMA stuff. Check that only one DMA mode is selected. */
917 printf("\tDMA: ");
Rob Landleya3e4f382006-04-29 16:06:31 +0000918 if (!(val[CAPAB_0] & DMA_SUP))
Eric Andersen3443bd72003-07-22 07:30:36 +0000919 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000920 else
921 {
Rob Landleyadde7982006-05-16 15:32:30 +0000922 if (val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA])
923 printf(" sdma%u\n",(val[DMA_MODE] & MODE) >> 8);
Rob Landleya3e4f382006-04-29 16:06:31 +0000924 if (val[SINGLE_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +0000925 {
926 jj = val[SINGLE_DMA];
927 kk = val[SINGLE_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +0000928 err_dma += mode_loop(jj,kk,'s',&have_mode);
929 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000930 if (val[MULTI_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +0000931 {
932 jj = val[MULTI_DMA];
933 kk = val[MULTI_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +0000934 err_dma += mode_loop(jj,kk,'m',&have_mode);
935 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000936 if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +0000937 {
938 jj = val[ULTRA_DMA];
939 kk = val[ULTRA_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +0000940 err_dma += mode_loop(jj,kk,'u',&have_mode);
941 }
Rob Landleyadde7982006-05-16 15:32:30 +0000942 if (err_dma || !have_mode) printf("(?)");
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000943 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +0000944
Rob Landleyadde7982006-05-16 15:32:30 +0000945 if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP))
946 printf("\t\tInterleaved DMA support\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000947
Rob Landleya3e4f382006-04-29 16:06:31 +0000948 if ((val[WHATS_VALID] & OK_W64_70) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000949 (val[DMA_TIME_MIN] || val[DMA_TIME_NORM]))
950 {
Rob Landleyadde7982006-05-16 15:32:30 +0000951 printf("\t\tCycle time:");
952 if (val[DMA_TIME_MIN]) printf(" min=%uns",val[DMA_TIME_MIN]);
953 if (val[DMA_TIME_NORM]) printf(" recommended=%uns",val[DMA_TIME_NORM]);
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000954 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +0000955 }
956 }
957
958 /* Programmed IO stuff */
959 printf("\tPIO: ");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000960 /* If a drive supports mode n (e.g. 3), it also supports all modes less
Eric Andersen3443bd72003-07-22 07:30:36 +0000961 * than n (e.g. 3, 2, 1 and 0). Print all the modes. */
Rob Landleya3e4f382006-04-29 16:06:31 +0000962 if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP))
Glenn L McGrath07085852003-10-09 07:28:22 +0000963 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000964 jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007;
Rob Landleya3e4f382006-04-29 16:06:31 +0000965 for (ii = 0; ii <= PIO_MODE_MAX ; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000966 {
Rob Landleyadde7982006-05-16 15:32:30 +0000967 if (jj & 0x0001) printf("pio%d ",ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000968 jj >>=1;
969 }
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000970 puts("");
Glenn L McGrath07085852003-10-09 07:28:22 +0000971 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000972 else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) )
Glenn L McGrath07085852003-10-09 07:28:22 +0000973 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000974 for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
Eric Andersen3443bd72003-07-22 07:30:36 +0000975 printf("pio%d ",ii);
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000976 puts("");
Glenn L McGrath07085852003-10-09 07:28:22 +0000977 }
978 else
979 printf("unknown\n");
980
Rob Landleya3e4f382006-04-29 16:06:31 +0000981 if (val[WHATS_VALID] & OK_W64_70)
Glenn L McGrath07085852003-10-09 07:28:22 +0000982 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000983 if (val[PIO_NO_FLOW] || val[PIO_FLOW])
Glenn L McGrath07085852003-10-09 07:28:22 +0000984 {
Rob Landleyadde7982006-05-16 15:32:30 +0000985 printf("\t\tCycle time:");
986 if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]);
987 if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]);
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +0000988 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +0000989 }
990 }
991
Rob Landleya3e4f382006-04-29 16:06:31 +0000992 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +0000993 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000994 printf("Commands/features:\n\tEnabled\tSupported:\n");
995 jj = val[CMDS_SUPP_0];
996 kk = val[CMDS_EN_0];
Rob Landleya3e4f382006-04-29 16:06:31 +0000997 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000998 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000999 if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0'))
Glenn L McGrath07085852003-10-09 07:28:22 +00001000 {
Rob Landleyadde7982006-05-16 15:32:30 +00001001 printf("\t%s\t%s\n", (kk & 0x8000) ? " *" : "", cmd_feat_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001002 }
1003 jj <<=1; kk<<=1;
Rob Landleya3e4f382006-04-29 16:06:31 +00001004 if (ii%16 == 15)
Glenn L McGrath07085852003-10-09 07:28:22 +00001005 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001006 jj = val[CMDS_SUPP_0+1+(ii/16)];
1007 kk = val[CMDS_EN_0+1+(ii/16)];
1008 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001009 if (ii == 31)
Glenn L McGrath07085852003-10-09 07:28:22 +00001010 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001011 if ((val[CMDS_SUPP_2] & VALID) != VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001012 ii +=16;
Eric Andersen3443bd72003-07-22 07:30:36 +00001013 }
1014 }
1015 }
Rob Landleyadde7982006-05-16 15:32:30 +00001016 /* Removable Media Status Notification feature set */
Denis Vlasenko67b23e62006-10-03 21:00:06 +00001017 if ((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
Rob Landleyadde7982006-05-16 15:32:30 +00001018 printf("\t%s supported\n", cmd_feat_str[27]);
Glenn L McGrath07085852003-10-09 07:28:22 +00001019
1020
Eric Andersen3443bd72003-07-22 07:30:36 +00001021 /* security */
Rob Landleya3e4f382006-04-29 16:06:31 +00001022 if ((eqpt != CDROM) && (like_std > 3) &&
Glenn L McGrath07085852003-10-09 07:28:22 +00001023 (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME]))
1024 {
Rob Landleyade7f952006-05-25 18:53:06 +00001025 printf("Security:\n");
Rob Landleyadde7982006-05-16 15:32:30 +00001026 if (val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1))
1027 printf("\tMaster password revision code = %u\n",val[PSWD_CODE]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001028 jj = val[SECU_STATUS];
Rob Landleya3e4f382006-04-29 16:06:31 +00001029 if (jj)
Glenn L McGrath07085852003-10-09 07:28:22 +00001030 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001031 for (ii = 0; ii < NUM_SECU_STR; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +00001032 {
Rob Landleyadde7982006-05-16 15:32:30 +00001033 printf("\t%s\t%s\n", (!(jj & 0x0001)) ? "not" : "", secu_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001034 jj >>=1;
1035 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001036 if (val[SECU_STATUS] & SECU_ENABLED)
Glenn L McGrath07085852003-10-09 07:28:22 +00001037 {
Rob Landleyadde7982006-05-16 15:32:30 +00001038 printf("\tSecurity level %s\n", (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high");
Eric Andersen3443bd72003-07-22 07:30:36 +00001039 }
1040 }
1041 jj = val[ERASE_TIME] & ERASE_BITS;
1042 kk = val[ENH_ERASE_TIME] & ERASE_BITS;
Rob Landleya3e4f382006-04-29 16:06:31 +00001043 if (jj || kk)
Glenn L McGrath07085852003-10-09 07:28:22 +00001044 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001045 printf("\t");
Rob Landleyade7f952006-05-25 18:53:06 +00001046 if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, "");
1047 if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED ");
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +00001048 puts("");
Eric Andersen3443bd72003-07-22 07:30:36 +00001049 }
1050 }
1051
1052 /* reset result */
Rob Landleyadde7982006-05-16 15:32:30 +00001053 jj = val[HWRST_RSLT];
1054 if ((jj & VALID) == VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001055 {
Rob Landleyadde7982006-05-16 15:32:30 +00001056 if (!(oo = (jj & RST0)))
1057 jj >>= 8;
Rob Landleya3e4f382006-04-29 16:06:31 +00001058 if ((jj & DEV_DET) == JUMPER_VAL)
Rob Landleyadde7982006-05-16 15:32:30 +00001059 strng = " determined by the jumper";
Rob Landleya3e4f382006-04-29 16:06:31 +00001060 else if ((jj & DEV_DET) == CSEL_VAL)
Rob Landleyadde7982006-05-16 15:32:30 +00001061 strng = " determined by CSEL";
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001062 else
Rob Landleyadde7982006-05-16 15:32:30 +00001063 strng = "";
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001064 printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n",
Rob Landleyadde7982006-05-16 15:32:30 +00001065 (val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng);
Eric Andersen3443bd72003-07-22 07:30:36 +00001066 }
1067
1068 /* more stuff from std 5 */
Rob Landleya3e4f382006-04-29 16:06:31 +00001069 if ((like_std > 4) && (eqpt != CDROM))
Glenn L McGrath07085852003-10-09 07:28:22 +00001070 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001071 if (val[CFA_PWR_MODE] & VALID_W160)
Glenn L McGrath07085852003-10-09 07:28:22 +00001072 {
Rob Landleyadde7982006-05-16 15:32:30 +00001073 printf("CFA power mode 1:\n\t%s%s\n", (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled",
1074 (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : "");
Glenn L McGrath07085852003-10-09 07:28:22 +00001075
Rob Landleyadde7982006-05-16 15:32:30 +00001076 if (val[CFA_PWR_MODE] & MAX_AMPS) printf("\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS);
Eric Andersen3443bd72003-07-22 07:30:36 +00001077 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001078 if ((val[INTEGRITY] & SIG) == SIG_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001079 {
Rob Landleyadde7982006-05-16 15:32:30 +00001080 printf("Checksum: %scorrect\n", chksum ? "in" : "");
Eric Andersen3443bd72003-07-22 07:30:36 +00001081 }
1082 }
1083
Rob Landleyadde7982006-05-16 15:32:30 +00001084 exit(EXIT_SUCCESS);
Eric Andersen3443bd72003-07-22 07:30:36 +00001085}
1086#endif
1087
Rob Landleyade7f952006-05-25 18:53:06 +00001088static int get_identity, get_geom;
1089static int do_flush;
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001090static int do_ctimings, do_timings;
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001091static unsigned long set_readahead, get_readahead, Xreadahead;
1092static unsigned long set_readonly, get_readonly, readonly;
1093static unsigned long set_unmask, get_unmask, unmask;
1094static unsigned long set_mult, get_mult, mult;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001095#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001096static unsigned long set_dma, get_dma, dma;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001097#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001098static unsigned long set_dma_q, get_dma_q, dma_q;
1099static unsigned long set_nowerr, get_nowerr, nowerr;
1100static unsigned long set_keep, get_keep, keep;
1101static unsigned long set_io32bit, get_io32bit, io32bit;
1102static unsigned long set_piomode, noisy_piomode;
1103static int piomode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001104#ifdef HDIO_DRIVE_CMD
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001105static unsigned long set_dkeep, get_dkeep, dkeep;
1106static unsigned long set_standby, get_standby, standby_requested;
1107static unsigned long set_xfermode, get_xfermode;
1108static int xfermode_requested;
1109static unsigned long set_lookahead, get_lookahead, lookahead;
1110static unsigned long set_prefetch, get_prefetch, prefetch;
1111static unsigned long set_defects, get_defects, defects;
1112static unsigned long set_wcache, get_wcache, wcache;
1113static unsigned long set_doorlock, get_doorlock, doorlock;
1114static unsigned long set_seagate, get_seagate;
1115static unsigned long set_standbynow, get_standbynow;
1116static unsigned long set_sleepnow, get_sleepnow;
1117static unsigned long get_powermode;
1118static unsigned long set_apmmode, get_apmmode, apmmode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001119#endif
1120#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001121static int get_IDentity;
Eric Andersen3443bd72003-07-22 07:30:36 +00001122#endif
1123#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
Rob Landley20deab02006-05-07 23:34:15 +00001124static unsigned long unregister_hwif;
1125static unsigned long hwif;
Eric Andersen3443bd72003-07-22 07:30:36 +00001126#endif
1127#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Rob Landley20deab02006-05-07 23:34:15 +00001128static unsigned long scan_hwif;
1129static unsigned long hwif_data;
1130static unsigned long hwif_ctrl;
1131static unsigned long hwif_irq;
Eric Andersen3443bd72003-07-22 07:30:36 +00001132#endif
1133#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Rob Landley20deab02006-05-07 23:34:15 +00001134static unsigned long set_busstate, get_busstate, busstate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001135#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001136static int reread_partn;
Eric Andersen3443bd72003-07-22 07:30:36 +00001137
1138#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001139static int perform_reset;
Eric Andersen3443bd72003-07-22 07:30:36 +00001140#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
1141#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Rob Landley20deab02006-05-07 23:34:15 +00001142static unsigned long perform_tristate, tristate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001143#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
1144
1145// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then
1146// then the HDIO_GET_IDENTITY only returned 142 bytes.
1147// Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes,
1148// and HDIO_GET_IDENTITY returns 512 bytes. But the latest
1149// 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY
1150// (which they should, but they should just return -EINVAL).
1151//
1152// So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes.
1153// On a really old system, it will not, and we will be confused.
1154// Too bad, really.
1155
1156#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001157static const char * const cfg_str[] =
Rob Landleyadde7982006-05-16 15:32:30 +00001158{ "", "HardSect", "SoftSect", "NotMFM",
1159 "HdSw>15uSec", "SpinMotCtl", "Fixed", "Removeable",
1160 "DTR<=5Mbs", "DTR>5Mbs", "DTR>10Mbs", "RotSpdTol>.5%",
1161 "dStbOff", "TrkOff", "FmtGapReq", "nonMagnetic"
Eric Andersen3443bd72003-07-22 07:30:36 +00001162};
1163
Rob Landleyadde7982006-05-16 15:32:30 +00001164static const char * const BuffType[] = {"Unknown", "1Sect", "DualPort", "DualPortCache"};
Eric Andersen3443bd72003-07-22 07:30:36 +00001165
Rob Landleya3e4f382006-04-29 16:06:31 +00001166static void dump_identity(const struct hd_driveid *id)
Eric Andersen3443bd72003-07-22 07:30:36 +00001167{
1168 int i;
Eric Andersen3443bd72003-07-22 07:30:36 +00001169 const unsigned short int *id_regs= (const void*) id;
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001170
Glenn L McGrath07085852003-10-09 07:28:22 +00001171 printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={",
1172 id->model, id->fw_rev, id->serial_no);
Rob Landleyadde7982006-05-16 15:32:30 +00001173 for (i=0; i<=15; i++) {
Rob Landleyade7f952006-05-25 18:53:06 +00001174 if (id->config & (1<<i))
1175 printf(" %s", cfg_str[i]);
Rob Landleyadde7982006-05-16 15:32:30 +00001176 }
1177 printf( " }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n"
1178 " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u",
Glenn L McGrath07085852003-10-09 07:28:22 +00001179 id->cyls, id->heads, id->sectors, id->track_bytes,
Rob Landleyadde7982006-05-16 15:32:30 +00001180 id->sector_bytes, id->ecc_bytes,
1181 id->buf_type, BuffType[(id->buf_type > 3) ? 0 : id->buf_type],
1182 id->buf_size/2, id->max_multsect);
Glenn L McGrath07085852003-10-09 07:28:22 +00001183 if (id->max_multsect)
1184 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001185 printf(", MultSect=");
1186 if (!(id->multsect_valid&1))
1187 printf("?%u?", id->multsect);
1188 else if (id->multsect)
1189 printf("%u", id->multsect);
1190 else
1191 printf("off");
1192 }
Denis Vlasenkoc6f188d2006-10-26 00:37:00 +00001193 puts("");
Rob Landleyade7f952006-05-25 18:53:06 +00001194
Denis Vlasenko67b23e62006-10-03 21:00:06 +00001195 if (!(id->field_valid&1))
Rob Landleyade7f952006-05-25 18:53:06 +00001196 printf(" (maybe):");
1197
1198 printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001199 id->cur_sectors,
1200 (BB_BIG_ENDIAN) ?
Rob Landleyade7f952006-05-25 18:53:06 +00001201 (long unsigned int)(id->cur_capacity0 << 16) | id->cur_capacity1 :
1202 (long unsigned int)(id->cur_capacity1 << 16) | id->cur_capacity0,
1203 ((id->capability&2) == 0) ? "no" : "yes");
1204
1205 if (id->capability&2)
1206 printf(", LBAsects=%u", id->lba_capacity);
1207
1208 printf("\n IORDY=%s", (id->capability&8) ? (id->capability&4) ? "on/off" : "yes" : "no");
1209
1210 if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&2)
1211 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001212
Rob Landleyade7f952006-05-25 18:53:06 +00001213 if ((id->capability&1) && (id->field_valid&2))
1214 printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time);
1215
1216 printf("\n PIO modes: ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001217 if (id->tPIO <= 5)
1218 {
Rob Landleyade7f952006-05-25 18:53:06 +00001219 printf("pio0 ");
1220 if (id->tPIO >= 1) printf("pio1 ");
1221 if (id->tPIO >= 2) printf("pio2 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001222 }
Rob Landleyade7f952006-05-25 18:53:06 +00001223 if (id->field_valid&2)
1224 {
1225 if (id->eide_pio_modes & 1) printf("pio3 ");
1226 if (id->eide_pio_modes & 2) printf("pio4 ");
1227 if (id->eide_pio_modes &~3) printf("pio? ");
1228 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001229 if (id->capability&1)
1230 {
1231 if (id->dma_1word | id->dma_mword)
1232 {
Rob Landleyade7f952006-05-25 18:53:06 +00001233 printf("\n DMA modes: ");
1234 if (id->dma_1word & 0x100) printf("*");
1235 if (id->dma_1word & 1) printf("sdma0 ");
1236 if (id->dma_1word & 0x200) printf("*");
1237 if (id->dma_1word & 2) printf("sdma1 ");
1238 if (id->dma_1word & 0x400) printf("*");
1239 if (id->dma_1word & 4) printf("sdma2 ");
1240 if (id->dma_1word & 0xf800) printf("*");
1241 if (id->dma_1word & 0xf8) printf("sdma? ");
1242 if (id->dma_mword & 0x100) printf("*");
1243 if (id->dma_mword & 1) printf("mdma0 ");
1244 if (id->dma_mword & 0x200) printf("*");
1245 if (id->dma_mword & 2) printf("mdma1 ");
1246 if (id->dma_mword & 0x400) printf("*");
1247 if (id->dma_mword & 4) printf("mdma2 ");
1248 if (id->dma_mword & 0xf800) printf("*");
1249 if (id->dma_mword & 0xf8) printf("mdma? ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001250 }
1251 }
Rob Landleyade7f952006-05-25 18:53:06 +00001252 if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&4)
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001253 {
Rob Landleyade7f952006-05-25 18:53:06 +00001254 printf("\n UDMA modes: ");
1255 if (id->dma_ultra & 0x100) printf("*");
1256 if (id->dma_ultra & 0x001) printf("udma0 ");
1257 if (id->dma_ultra & 0x200) printf("*");
1258 if (id->dma_ultra & 0x002) printf("udma1 ");
1259 if (id->dma_ultra & 0x400) printf("*");
1260 if (id->dma_ultra & 0x004) printf("udma2 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001261#ifdef __NEW_HD_DRIVE_ID
Rob Landleyade7f952006-05-25 18:53:06 +00001262 if (id->hw_config & 0x2000)
1263 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001264#else /* !__NEW_HD_DRIVE_ID */
Rob Landleyade7f952006-05-25 18:53:06 +00001265 if (id->word93 & 0x2000)
1266 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001267#endif /* __NEW_HD_DRIVE_ID */
Rob Landleyade7f952006-05-25 18:53:06 +00001268 if (id->dma_ultra & 0x0800) printf("*");
1269 if (id->dma_ultra & 0x0008) printf("udma3 ");
1270 if (id->dma_ultra & 0x1000) printf("*");
1271 if (id->dma_ultra & 0x0010) printf("udma4 ");
1272 if (id->dma_ultra & 0x2000) printf("*");
1273 if (id->dma_ultra & 0x0020) printf("udma5 ");
1274 if (id->dma_ultra & 0x4000) printf("*");
1275 if (id->dma_ultra & 0x0040) printf("udma6 ");
1276 if (id->dma_ultra & 0x8000) printf("*");
1277 if (id->dma_ultra & 0x0080) printf("udma7 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001278 }
1279 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001280 printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes");
1281 if (id_regs[83] & 8)
1282 {
1283 if (!(id_regs[86]&8))
1284 printf(": disabled (255)");
1285 else if ((id_regs[91]&0xFF00)!=0x4000)
1286 printf(": unknown setting");
1287 else
1288 printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF);
1289 }
Rob Landleyade7f952006-05-25 18:53:06 +00001290 if (id_regs[82]&0x20)
1291 printf(" WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled");
Glenn L McGrath07085852003-10-09 07:28:22 +00001292#ifdef __NEW_HD_DRIVE_ID
1293 if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31))
1294 {
Rob Landleyadde7982006-05-16 15:32:30 +00001295 printf("\n Drive conforms to: %s: ", (id->minor_rev_num <= 31) ? minor_str[id->minor_rev_num] : "Unknown");
Rob Landley026147a2006-04-17 22:29:13 +00001296 if (id->major_rev_num != 0x0000 && /* NOVAL_0 */
1297 id->major_rev_num != 0xFFFF) { /* NOVAL_1 */
Rob Landleyadde7982006-05-16 15:32:30 +00001298 for (i=0; i <= 15; i++) {
1299 if (id->major_rev_num & (1<<i))
1300 printf(" ATA/ATAPI-%u", i);
1301 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001302 }
1303 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001304#endif /* __NEW_HD_DRIVE_ID */
Rob Landleyade7f952006-05-25 18:53:06 +00001305 printf("\n\n * current active mode\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001306}
1307#endif
1308
Rob Landleya3e4f382006-04-29 16:06:31 +00001309static void flush_buffer_cache(int fd)
Eric Andersen3443bd72003-07-22 07:30:36 +00001310{
Rob Landleya3e4f382006-04-29 16:06:31 +00001311 fsync(fd); /* flush buffers */
Glenn L McGrath07085852003-10-09 07:28:22 +00001312 bb_ioctl(fd, BLKFLSBUF, NULL,"BLKFLSBUF" ) ;/* do it again, big time */
Eric Andersen3443bd72003-07-22 07:30:36 +00001313#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001314 sleep(1);
1315 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001316 bb_perror_msg("HDIO_DRIVE_CMD");
Eric Andersen3443bd72003-07-22 07:30:36 +00001317#endif
1318}
1319
Rob Landleya3e4f382006-04-29 16:06:31 +00001320static int seek_to_zero(int fd)
Eric Andersen3443bd72003-07-22 07:30:36 +00001321{
Glenn L McGrath07085852003-10-09 07:28:22 +00001322 if (lseek(fd, (off_t) 0, SEEK_SET))
Eric Andersen3443bd72003-07-22 07:30:36 +00001323 return 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001324 return 0;
1325}
1326
Rob Landleya3e4f382006-04-29 16:06:31 +00001327static int read_big_block(int fd, char *buf)
Eric Andersen3443bd72003-07-22 07:30:36 +00001328{
Rob Landleyadde7982006-05-16 15:32:30 +00001329 int i;
1330
1331 if ((i = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES) {
1332 bb_error_msg("read(%d bytes) failed (rc=%d)", TIMING_BUF_BYTES, i);
Eric Andersen3443bd72003-07-22 07:30:36 +00001333 return 1;
1334 }
1335 /* access all sectors of buf to ensure the read fully completed */
1336 for (i = 0; i < TIMING_BUF_BYTES; i += 512)
1337 buf[i] &= 1;
1338 return 0;
1339}
1340
Rob Landleyadde7982006-05-16 15:32:30 +00001341static void print_timing(int t, double e)
1342{
1343 if (t >= e) /* more than 1MB/s */
Rob Landleyade7f952006-05-25 18:53:06 +00001344 printf("%2d MB in %5.2f seconds =%6.2f %cB/sec\n", t, e, t / e, 'M');
Rob Landleyadde7982006-05-16 15:32:30 +00001345 else
Rob Landleyade7f952006-05-25 18:53:06 +00001346 printf("%2d MB in %5.2f seconds =%6.2f %cB/sec\n", t, e, t / e * 1024, 'k');
Rob Landleyadde7982006-05-16 15:32:30 +00001347}
1348
1349static int do_blkgetsize (int fd, unsigned long long *blksize64)
1350{
1351 int rc;
1352 unsigned int blksize32 = 0;
1353
1354 if (0 == ioctl(fd, BLKGETSIZE64, blksize64)) { // returns bytes
1355 *blksize64 /= 512;
1356 return 0;
1357 }
1358 rc = ioctl(fd, BLKGETSIZE, &blksize32); // returns sectors
1359 if (rc)
1360 bb_perror_msg("BLKGETSIZE");
1361 *blksize64 = blksize32;
1362 return rc;
1363}
Eric Andersen50af12d2003-08-06 08:47:59 +00001364
Rob Landleya3e4f382006-04-29 16:06:31 +00001365static void do_time(int flag, int fd)
Glenn L McGrath07085852003-10-09 07:28:22 +00001366/*
1367 flag = 0 time_cache
1368 flag = 1 time_device
1369*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001370{
Eric Andersen3443bd72003-07-22 07:30:36 +00001371 struct itimerval e1, e2;
Rob Landleyadde7982006-05-16 15:32:30 +00001372 double elapsed, elapsed2;
1373 unsigned int max_iterations = 1024, total_MB, iterations;
1374 unsigned long long blksize;
Rob Landley4ae2f512006-05-19 17:24:26 +00001375 RESERVE_CONFIG_BUFFER(buf, TIMING_BUF_BYTES);
1376
1377 if (mlock(buf, TIMING_BUF_BYTES)) {
1378 bb_perror_msg("mlock");
1379 goto quit2;
1380 }
Rob Landleyadde7982006-05-16 15:32:30 +00001381
1382 if (0 == do_blkgetsize(fd, &blksize)) {
1383 max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB;
1384 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001385
Eric Andersen3443bd72003-07-22 07:30:36 +00001386 /* Clear out the device request queues & give them time to complete */
Rob Landleyadde7982006-05-16 15:32:30 +00001387 sync();
1388 sleep(3);
1389
1390 setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00001391
Rob Landleya3e4f382006-04-29 16:06:31 +00001392 if (flag == 0) /* Time cache */
Glenn L McGrath07085852003-10-09 07:28:22 +00001393 {
Rob Landleyadde7982006-05-16 15:32:30 +00001394 if (seek_to_zero (fd)) return;
1395 if (read_big_block (fd, buf)) return;
1396 printf(" Timing cached reads: ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001397 fflush(stdout);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001398
Rob Landleyadde7982006-05-16 15:32:30 +00001399 /* Now do the timing */
1400 iterations = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +00001401 getitimer(ITIMER_REAL, &e1);
Rob Landleyadde7982006-05-16 15:32:30 +00001402 do {
1403 ++iterations;
1404 if (seek_to_zero (fd) || read_big_block (fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001405 goto quit;
Rob Landleyadde7982006-05-16 15:32:30 +00001406 getitimer(ITIMER_REAL, &e2);
1407 elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec)
1408 + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
1409 } while (elapsed < 2.0);
1410 total_MB = iterations * TIMING_BUF_MB;
Rob Landleyade7f952006-05-25 18:53:06 +00001411
Rob Landleyadde7982006-05-16 15:32:30 +00001412 /* Now remove the lseek() and getitimer() overheads from the elapsed time */
1413 getitimer(ITIMER_REAL, &e1);
1414 do {
1415 if (seek_to_zero (fd))
1416 goto quit;
1417 getitimer(ITIMER_REAL, &e2);
1418 elapsed2 = (e1.it_value.tv_sec - e2.it_value.tv_sec)
1419 + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
1420 } while (--iterations);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001421
Rob Landleyadde7982006-05-16 15:32:30 +00001422 elapsed -= elapsed2;
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001423 print_timing(BUFCACHE_FACTOR * total_MB, elapsed);
Glenn L McGrath07085852003-10-09 07:28:22 +00001424 flush_buffer_cache(fd);
1425 sleep(1);
Eric Andersen50af12d2003-08-06 08:47:59 +00001426 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001427 else /* Time device */
1428 {
1429 printf(" Timing buffered disk reads: ");
1430 fflush(stdout);
Glenn L McGrath07085852003-10-09 07:28:22 +00001431 /*
1432 * getitimer() is used rather than gettimeofday() because
1433 * it is much more consistent (on my machine, at least).
1434 */
Glenn L McGrath07085852003-10-09 07:28:22 +00001435 /* Now do the timings for real */
Rob Landleyadde7982006-05-16 15:32:30 +00001436 iterations = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +00001437 getitimer(ITIMER_REAL, &e1);
Rob Landleyadde7982006-05-16 15:32:30 +00001438 do {
1439 ++iterations;
1440 if (read_big_block (fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001441 goto quit;
Rob Landleyadde7982006-05-16 15:32:30 +00001442 getitimer(ITIMER_REAL, &e2);
1443 elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec)
1444 + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
1445 } while (elapsed < 3.0 && iterations < max_iterations);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001446
Rob Landleyadde7982006-05-16 15:32:30 +00001447 total_MB = iterations * TIMING_BUF_MB;
1448 print_timing(total_MB, elapsed);
Glenn L McGrath07085852003-10-09 07:28:22 +00001449 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001450quit:
Rob Landley4ae2f512006-05-19 17:24:26 +00001451 munlock(buf, TIMING_BUF_BYTES);
1452quit2:
1453 RELEASE_CONFIG_BUFFER(buf);
Eric Andersen3443bd72003-07-22 07:30:36 +00001454}
1455
Eric Andersen3443bd72003-07-22 07:30:36 +00001456static void on_off (unsigned int value)
1457{
1458 printf(value ? " (on)\n" : " (off)\n");
1459}
1460
1461#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Rob Landleya3e4f382006-04-29 16:06:31 +00001462static void bus_state_value(unsigned int value)
Eric Andersen3443bd72003-07-22 07:30:36 +00001463{
Rob Landleyadde7982006-05-16 15:32:30 +00001464 if (value == BUSSTATE_ON)
1465 on_off(1);
1466 else if (value == BUSSTATE_OFF)
1467 on_off(0);
1468 else if (value == BUSSTATE_TRISTATE)
1469 printf(" (tristate)\n");
1470 else
1471 printf(" (unknown: %d)\n", value);
Eric Andersen3443bd72003-07-22 07:30:36 +00001472}
1473#endif
1474
1475#ifdef HDIO_DRIVE_CMD
Rob Landleya3e4f382006-04-29 16:06:31 +00001476static void interpret_standby(unsigned int standby)
Eric Andersen3443bd72003-07-22 07:30:36 +00001477{
Rob Landleyadde7982006-05-16 15:32:30 +00001478 unsigned int t;
1479
Rob Landley403777f2006-08-03 20:22:37 +00001480 printf(" (");
Rob Landleyadde7982006-05-16 15:32:30 +00001481 if (standby == 0)
1482 printf("off");
1483 else if (standby == 252)
1484 printf("21 minutes");
1485 else if (standby == 253)
1486 printf("vendor-specific");
1487 else if (standby == 254)
1488 printf("Reserved");
1489 else if (standby == 255)
1490 printf("21 minutes + 15 seconds");
1491 else {
1492 if (standby <= 240) {
1493 t = standby * 5;
1494 printf("%u minutes + %u seconds", t / 60, t % 60);
1495 } else if (standby <= 251) {
1496 t = (standby - 240) * 30;
1497 printf("%u hours + %u minutes", t / 60, t % 60);
1498 } else
1499 printf("illegal value");
Eric Andersen3443bd72003-07-22 07:30:36 +00001500 }
1501 printf(")\n");
1502}
1503
1504struct xfermode_entry {
1505 int val;
1506 const char *name;
1507};
1508
1509static const struct xfermode_entry xfermode_table[] = {
1510 { 8, "pio0" },
1511 { 9, "pio1" },
1512 { 10, "pio2" },
1513 { 11, "pio3" },
1514 { 12, "pio4" },
1515 { 13, "pio5" },
1516 { 14, "pio6" },
1517 { 15, "pio7" },
1518 { 16, "sdma0" },
1519 { 17, "sdma1" },
1520 { 18, "sdma2" },
1521 { 19, "sdma3" },
1522 { 20, "sdma4" },
1523 { 21, "sdma5" },
1524 { 22, "sdma6" },
1525 { 23, "sdma7" },
1526 { 32, "mdma0" },
1527 { 33, "mdma1" },
1528 { 34, "mdma2" },
1529 { 35, "mdma3" },
1530 { 36, "mdma4" },
1531 { 37, "mdma5" },
1532 { 38, "mdma6" },
1533 { 39, "mdma7" },
1534 { 64, "udma0" },
1535 { 65, "udma1" },
1536 { 66, "udma2" },
1537 { 67, "udma3" },
1538 { 68, "udma4" },
1539 { 69, "udma5" },
1540 { 70, "udma6" },
1541 { 71, "udma7" },
1542 { 0, NULL }
1543};
1544
1545static int translate_xfermode(char * name)
1546{
Glenn L McGrath07085852003-10-09 07:28:22 +00001547 const struct xfermode_entry *tmp;
1548 char *endptr;
1549 int val = -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001550
1551
Glenn L McGrath07085852003-10-09 07:28:22 +00001552 for (tmp = xfermode_table; tmp->name != NULL; ++tmp)
1553 {
1554 if (!strcmp(name, tmp->name))
1555 return tmp->val;
Glenn L McGrath07085852003-10-09 07:28:22 +00001556 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001557
Glenn L McGrath07085852003-10-09 07:28:22 +00001558 val = strtol(name, &endptr, 10);
1559 if (*endptr == '\0')
1560 return val;
1561
1562 return -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001563}
1564
Rob Landleya3e4f382006-04-29 16:06:31 +00001565static void interpret_xfermode(unsigned int xfermode)
Eric Andersen3443bd72003-07-22 07:30:36 +00001566{
1567 printf(" (");
Rob Landleyadde7982006-05-16 15:32:30 +00001568 if (xfermode == 0)
1569 printf("default PIO mode");
1570 else if (xfermode == 1)
1571 printf("default PIO mode, disable IORDY");
1572 else if (xfermode >= 8 && xfermode <= 15)
1573 printf("PIO flow control mode%u", xfermode-8);
1574 else if (xfermode >= 16 && xfermode <= 23)
1575 printf("singleword DMA mode%u", xfermode-16);
1576 else if (xfermode >= 32 && xfermode <= 39)
1577 printf("multiword DMA mode%u", xfermode-32);
1578 else if (xfermode >= 64 && xfermode <= 71)
1579 printf("UltraDMA mode%u", xfermode-64);
1580 else
1581 printf("Unknown");
Eric Andersen3443bd72003-07-22 07:30:36 +00001582 printf(")\n");
1583}
1584#endif /* HDIO_DRIVE_CMD */
1585
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +00001586static void print_flag(unsigned long flag, const char *s, unsigned long value)
Rob Landleyadde7982006-05-16 15:32:30 +00001587{
Denis Vlasenko67b23e62006-10-03 21:00:06 +00001588 if (flag)
Rob Landleyadde7982006-05-16 15:32:30 +00001589 printf(" setting %s to %ld\n", s, value);
1590}
1591
Rob Landleya3e4f382006-04-29 16:06:31 +00001592static void process_dev(char *devname)
Eric Andersen3443bd72003-07-22 07:30:36 +00001593{
1594 int fd;
1595 static long parm, multcount;
Eric Andersen3443bd72003-07-22 07:30:36 +00001596#ifndef HDIO_DRIVE_CMD
1597 int force_operation = 0;
1598#endif
Rob Landley39cf6452006-05-05 16:52:28 +00001599 /* Please restore args[n] to these values after each ioctl
1600 except for args[2] */
Rob Landleye5b281f2006-04-29 15:49:18 +00001601 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
Rob Landleyadde7982006-05-16 15:32:30 +00001602 const char *fmt = " %s\t= %2ld";
Rob Landleye5b281f2006-04-29 15:49:18 +00001603
Rob Landleyd921b2e2006-08-03 15:41:12 +00001604 fd = xopen(devname, O_RDONLY|O_NONBLOCK);
Rob Landleyade7f952006-05-25 18:53:06 +00001605 printf("\n%s:\n", devname);
Eric Andersen3443bd72003-07-22 07:30:36 +00001606
Glenn L McGrath07085852003-10-09 07:28:22 +00001607 if (set_readahead)
1608 {
Rob Landleyadde7982006-05-16 15:32:30 +00001609 print_flag(get_readahead,"fs readahead", Xreadahead);
Eric Andersenf828da02004-07-20 22:53:59 +00001610 bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001611 }
1612#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001613 if (unregister_hwif)
1614 {
Rob Landley20deab02006-05-07 23:34:15 +00001615 printf(" attempting to unregister hwif#%lu\n", hwif);
Eric Andersena68ea1c2006-01-30 22:48:39 +00001616 bb_ioctl(fd, HDIO_UNREGISTER_HWIF,(int *)(unsigned long)hwif,"HDIO_UNREGISTER_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001617 }
1618#endif
1619#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001620 if (scan_hwif)
1621 {
Rob Landley20deab02006-05-07 23:34:15 +00001622 printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq);
Eric Andersen3443bd72003-07-22 07:30:36 +00001623 args[0] = hwif_data;
1624 args[1] = hwif_ctrl;
1625 args[2] = hwif_irq;
Glenn L McGrath07085852003-10-09 07:28:22 +00001626 bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF");
Rob Landley39cf6452006-05-05 16:52:28 +00001627 args[0] = WIN_SETFEATURES;
1628 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001629 }
1630#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001631 if (set_piomode)
1632 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001633 if (noisy_piomode)
1634 {
1635 printf(" attempting to ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001636 if (piomode == 255)
Glenn L McGrath07085852003-10-09 07:28:22 +00001637 printf("auto-tune PIO mode\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001638 else if (piomode < 100)
Glenn L McGrath07085852003-10-09 07:28:22 +00001639 printf("set PIO mode to %d\n", piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001640 else if (piomode < 200)
Glenn L McGrath07085852003-10-09 07:28:22 +00001641 printf("set MDMA mode to %d\n", (piomode-100));
Eric Andersen3443bd72003-07-22 07:30:36 +00001642 else
Glenn L McGrath07085852003-10-09 07:28:22 +00001643 printf("set UDMA mode to %d\n", (piomode-200));
Eric Andersen3443bd72003-07-22 07:30:36 +00001644 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00001645 bb_ioctl(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode, "HDIO_SET_PIO_MODE");
Eric Andersen3443bd72003-07-22 07:30:36 +00001646 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001647 if (set_io32bit)
1648 {
Rob Landleyadde7982006-05-16 15:32:30 +00001649 print_flag(get_io32bit,"32-bit IO_support flag", io32bit);
Glenn L McGrath07085852003-10-09 07:28:22 +00001650 bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001651 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001652 if (set_mult)
1653 {
Rob Landleyadde7982006-05-16 15:32:30 +00001654 print_flag(get_mult, "multcount", mult);
Rob Landleyade7f952006-05-25 18:53:06 +00001655#ifdef HDIO_DRIVE_CMD
1656 bb_ioctl(fd, HDIO_SET_MULTCOUNT, &mult, "HDIO_SET_MULTCOUNT");
1657#else
1658 force_operation |= (!bb_ioctl(fd, HDIO_SET_MULTCOUNT, &mult, "HDIO_SET_MULTCOUNT"));
Eric Andersen3443bd72003-07-22 07:30:36 +00001659#endif
1660 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001661 if (set_readonly)
1662 {
Rob Landleyadde7982006-05-16 15:32:30 +00001663 print_flag_on_off(get_readonly,"readonly", readonly);
Glenn L McGrath07085852003-10-09 07:28:22 +00001664 bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001665 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001666 if (set_unmask)
1667 {
Rob Landleyadde7982006-05-16 15:32:30 +00001668 print_flag_on_off(get_unmask,"unmaskirq", unmask);
Glenn L McGrath07085852003-10-09 07:28:22 +00001669 bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR");
Eric Andersen3443bd72003-07-22 07:30:36 +00001670 }
Eric Andersen0a57a792003-08-06 08:57:35 +00001671#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Glenn L McGrath07085852003-10-09 07:28:22 +00001672 if (set_dma)
1673 {
Rob Landleyadde7982006-05-16 15:32:30 +00001674 print_flag_on_off(get_dma, "using_dma", dma);
Glenn L McGrath07085852003-10-09 07:28:22 +00001675 bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00001676 }
Eric Andersen0a57a792003-08-06 08:57:35 +00001677#endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
Glenn L McGrath07085852003-10-09 07:28:22 +00001678 if (set_dma_q)
1679 {
Rob Landleyadde7982006-05-16 15:32:30 +00001680 print_flag_on_off(get_dma_q,"DMA queue_depth", dma_q);
Glenn L McGrath07085852003-10-09 07:28:22 +00001681 bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00001682 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001683 if (set_nowerr)
1684 {
Rob Landleyadde7982006-05-16 15:32:30 +00001685 print_flag_on_off(get_nowerr,"nowerr", nowerr);
Glenn L McGrath07085852003-10-09 07:28:22 +00001686 bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR");
Eric Andersen3443bd72003-07-22 07:30:36 +00001687 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001688 if (set_keep)
1689 {
Rob Landleyadde7982006-05-16 15:32:30 +00001690 print_flag_on_off(get_keep,"keep_settings", keep);
Glenn L McGrath07085852003-10-09 07:28:22 +00001691 bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS");
Eric Andersen3443bd72003-07-22 07:30:36 +00001692 }
1693#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001694 if (set_doorlock)
1695 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001696 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
Rob Landley39cf6452006-05-05 16:52:28 +00001697 args[2] = 0;
Rob Landleyadde7982006-05-16 15:32:30 +00001698 print_flag_on_off(get_doorlock,"drive doorlock", doorlock);
Glenn L McGrath07085852003-10-09 07:28:22 +00001699 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)");
Rob Landley39cf6452006-05-05 16:52:28 +00001700 args[0] = WIN_SETFEATURES;
Eric Andersen3443bd72003-07-22 07:30:36 +00001701 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001702 if (set_dkeep)
1703 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001704 /* lock/unlock the drive's "feature" settings */
Rob Landleyadde7982006-05-16 15:32:30 +00001705 print_flag_on_off(get_dkeep,"drive keep features", dkeep);
Eric Andersen3443bd72003-07-22 07:30:36 +00001706 args[2] = dkeep ? 0x66 : 0xcc;
Glenn L McGrath07085852003-10-09 07:28:22 +00001707 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001708 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001709 if (set_defects)
1710 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001711 args[2] = defects ? 0x04 : 0x84;
Rob Landleyadde7982006-05-16 15:32:30 +00001712 print_flag(get_defects,"drive defect-mgmt", defects);
Glenn L McGrath07085852003-10-09 07:28:22 +00001713 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001714 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001715 if (set_prefetch)
1716 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001717 args[1] = prefetch;
Rob Landleye5b281f2006-04-29 15:49:18 +00001718 args[2] = 0xab;
Rob Landleyadde7982006-05-16 15:32:30 +00001719 print_flag(get_prefetch,"drive prefetch", prefetch);
Glenn L McGrath07085852003-10-09 07:28:22 +00001720 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)");
Rob Landley39cf6452006-05-05 16:52:28 +00001721 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001722 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001723 if (set_xfermode)
1724 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001725 args[1] = xfermode_requested;
Rob Landleye5b281f2006-04-29 15:49:18 +00001726 args[2] = 3;
Glenn L McGrath07085852003-10-09 07:28:22 +00001727 if (get_xfermode)
1728 {
Rob Landleyade7f952006-05-25 18:53:06 +00001729 print_flag(1,"xfermode", xfermode_requested);
Eric Andersen3443bd72003-07-22 07:30:36 +00001730 interpret_xfermode(xfermode_requested);
1731 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001732 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)");
Rob Landley39cf6452006-05-05 16:52:28 +00001733 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001734 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001735 if (set_lookahead)
1736 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001737 args[2] = lookahead ? 0xaa : 0x55;
Rob Landleyadde7982006-05-16 15:32:30 +00001738 print_flag_on_off(get_lookahead,"drive read-lookahead", lookahead);
Glenn L McGrath07085852003-10-09 07:28:22 +00001739 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001740 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001741 if (set_apmmode)
1742 {
Rob Landleyadde7982006-05-16 15:32:30 +00001743 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */
1744 args[1] = apmmode; /* sector count register 1-255 */
1745 if (get_apmmode)
1746 printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode);
Glenn L McGrath07085852003-10-09 07:28:22 +00001747 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD");
Rob Landley39cf6452006-05-05 16:52:28 +00001748 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001749 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001750 if (set_wcache)
1751 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001752#ifdef DO_FLUSHCACHE
1753#ifndef WIN_FLUSHCACHE
1754#define WIN_FLUSHCACHE 0xe7
1755#endif
Rob Landleye5b281f2006-04-29 15:49:18 +00001756 static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0};
Eric Andersen3443bd72003-07-22 07:30:36 +00001757#endif /* DO_FLUSHCACHE */
Eric Andersen3443bd72003-07-22 07:30:36 +00001758 args[2] = wcache ? 0x02 : 0x82;
Rob Landleyadde7982006-05-16 15:32:30 +00001759 print_flag_on_off(get_wcache,"drive write-caching", wcache);
Eric Andersen3443bd72003-07-22 07:30:36 +00001760#ifdef DO_FLUSHCACHE
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001761 if (!wcache)
1762 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001763#endif /* DO_FLUSHCACHE */
Glenn L McGrath07085852003-10-09 07:28:22 +00001764 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001765#ifdef DO_FLUSHCACHE
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001766 if (!wcache)
1767 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001768#endif /* DO_FLUSHCACHE */
1769 }
Rob Landley39cf6452006-05-05 16:52:28 +00001770
1771 /* In code below, we do not preserve args[0], but the rest
1772 is preserved, including args[2] */
1773 args[2] = 0;
1774
Glenn L McGrath07085852003-10-09 07:28:22 +00001775 if (set_standbynow)
1776 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001777#ifndef WIN_STANDBYNOW1
1778#define WIN_STANDBYNOW1 0xE0
1779#endif
1780#ifndef WIN_STANDBYNOW2
1781#define WIN_STANDBYNOW2 0x94
1782#endif
Rob Landleyadde7982006-05-16 15:32:30 +00001783 if (get_standbynow) printf(" issuing standby command\n");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001784 args[0] = WIN_STANDBYNOW1;
1785 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001786 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001787 if (set_sleepnow)
1788 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001789#ifndef WIN_SLEEPNOW1
1790#define WIN_SLEEPNOW1 0xE6
1791#endif
1792#ifndef WIN_SLEEPNOW2
1793#define WIN_SLEEPNOW2 0x99
1794#endif
Rob Landleyadde7982006-05-16 15:32:30 +00001795 if (get_sleepnow) printf(" issuing sleep command\n");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001796 args[0] = WIN_SLEEPNOW1;
1797 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001798 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001799 if (set_seagate)
1800 {
Rob Landleye5b281f2006-04-29 15:49:18 +00001801 args[0] = 0xfb;
Rob Landleyadde7982006-05-16 15:32:30 +00001802 if (get_seagate) printf(" disabling Seagate auto powersaving mode\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001803 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001804 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001805 if (set_standby)
1806 {
Rob Landleye5b281f2006-04-29 15:49:18 +00001807 args[0] = WIN_SETIDLE1;
1808 args[1] = standby_requested;
Glenn L McGrath07085852003-10-09 07:28:22 +00001809 if (get_standby)
1810 {
Rob Landleyade7f952006-05-25 18:53:06 +00001811 print_flag(1,"standby", standby_requested);
Eric Andersen3443bd72003-07-22 07:30:36 +00001812 interpret_standby(standby_requested);
1813 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001814 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)");
Rob Landley39cf6452006-05-05 16:52:28 +00001815 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001816 }
1817#else /* HDIO_DRIVE_CMD */
Glenn L McGrath07085852003-10-09 07:28:22 +00001818 if (force_operation)
1819 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001820 char buf[512];
1821 flush_buffer_cache(fd);
1822 if (-1 == read(fd, buf, sizeof(buf)))
Rob Landleyadde7982006-05-16 15:32:30 +00001823 bb_perror_msg("read(%d bytes) failed (rc=%d)", sizeof(buf), -1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001824 }
1825#endif /* HDIO_DRIVE_CMD */
1826
Rob Landleyade7f952006-05-25 18:53:06 +00001827 if (get_mult || get_identity)
Glenn L McGrath07085852003-10-09 07:28:22 +00001828 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001829 multcount = -1;
Glenn L McGrath07085852003-10-09 07:28:22 +00001830 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount))
1831 {
Rob Landleyade7f952006-05-25 18:53:06 +00001832 if (get_mult)
Eric Andersen06d4ec22004-03-19 10:53:52 +00001833 bb_perror_msg("HDIO_GET_MULTCOUNT");
Glenn L McGrath07085852003-10-09 07:28:22 +00001834 }
Rob Landleyade7f952006-05-25 18:53:06 +00001835 else if (get_mult)
Glenn L McGrath07085852003-10-09 07:28:22 +00001836 {
Rob Landleyadde7982006-05-16 15:32:30 +00001837 printf(fmt, "multcount", multcount);
Eric Andersen3443bd72003-07-22 07:30:36 +00001838 on_off(multcount);
1839 }
1840 }
Rob Landleyade7f952006-05-25 18:53:06 +00001841 if (get_io32bit)
Glenn L McGrath07085852003-10-09 07:28:22 +00001842 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001843 if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT"))
Glenn L McGrath07085852003-10-09 07:28:22 +00001844 {
Rob Landleyadde7982006-05-16 15:32:30 +00001845 printf(" IO_support\t=%3ld (", parm);
1846 if (parm == 0)
1847 printf("default 16-bit)\n");
1848 else if (parm == 2)
1849 printf("16-bit)\n");
1850 else if (parm == 1)
1851 printf("32-bit)\n");
1852 else if (parm == 3)
1853 printf("32-bit w/sync)\n");
1854 else if (parm == 8)
1855 printf("Request-Queue-Bypass)\n");
1856 else
1857 printf("\?\?\?)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001858 }
1859 }
Rob Landleyade7f952006-05-25 18:53:06 +00001860 if (get_unmask)
Glenn L McGrath07085852003-10-09 07:28:22 +00001861 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001862 bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm,
Rob Landleyadde7982006-05-16 15:32:30 +00001863 "HDIO_GET_UNMASKINTR","unmaskirq");
Eric Andersen3443bd72003-07-22 07:30:36 +00001864 }
1865
Glenn L McGrath07085852003-10-09 07:28:22 +00001866
Eric Andersen0a57a792003-08-06 08:57:35 +00001867#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Rob Landleyade7f952006-05-25 18:53:06 +00001868 if (get_dma) {
Rob Landleya3e4f382006-04-29 16:06:31 +00001869 if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA"))
Glenn L McGrath07085852003-10-09 07:28:22 +00001870 {
Rob Landleyadde7982006-05-16 15:32:30 +00001871 printf(fmt, "using_dma", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001872 if (parm == 8)
1873 printf(" (DMA-Assisted-PIO)\n");
1874 else
1875 on_off(parm);
1876 }
1877 }
1878#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001879 if (get_dma_q)
1880 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001881 bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm,
Rob Landleyadde7982006-05-16 15:32:30 +00001882 "HDIO_GET_QDMA","queue_depth");
Eric Andersen3443bd72003-07-22 07:30:36 +00001883 }
Rob Landleyade7f952006-05-25 18:53:06 +00001884 if (get_keep)
Glenn L McGrath07085852003-10-09 07:28:22 +00001885 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001886 bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm,
Rob Landleyadde7982006-05-16 15:32:30 +00001887 "HDIO_GET_KEEPSETTINGS","keepsettings");
Eric Andersen3443bd72003-07-22 07:30:36 +00001888 }
1889
Glenn L McGrath07085852003-10-09 07:28:22 +00001890 if (get_nowerr)
1891 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001892 bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm,
Rob Landleyadde7982006-05-16 15:32:30 +00001893 "HDIO_GET_NOWERR","nowerr");
Eric Andersen3443bd72003-07-22 07:30:36 +00001894 }
Rob Landleyade7f952006-05-25 18:53:06 +00001895 if (get_readonly)
Glenn L McGrath07085852003-10-09 07:28:22 +00001896 {
1897 bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm,
Rob Landleyadde7982006-05-16 15:32:30 +00001898 "BLKROGET","readonly");
Eric Andersen3443bd72003-07-22 07:30:36 +00001899 }
Rob Landleyade7f952006-05-25 18:53:06 +00001900 if (get_readahead)
Glenn L McGrath07085852003-10-09 07:28:22 +00001901 {
1902 bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm,
Rob Landleyadde7982006-05-16 15:32:30 +00001903 "BLKRAGET","readahead");
Eric Andersen3443bd72003-07-22 07:30:36 +00001904 }
Rob Landleyade7f952006-05-25 18:53:06 +00001905 if (get_geom)
Glenn L McGrath07085852003-10-09 07:28:22 +00001906 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001907 if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE"))
1908 {
Rob Landley2584e9b2006-05-03 20:00:00 +00001909 struct hd_geometry g;
1910
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001911 if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO"))
Rob Landleyadde7982006-05-16 15:32:30 +00001912 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n",
Rob Landley2584e9b2006-05-03 20:00:00 +00001913 g.cylinders, g.heads, g.sectors, parm, g.start);
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001914 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001915 }
1916#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001917 if (get_powermode)
1918 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001919#ifndef WIN_CHECKPOWERMODE1
1920#define WIN_CHECKPOWERMODE1 0xE5
1921#endif
1922#ifndef WIN_CHECKPOWERMODE2
1923#define WIN_CHECKPOWERMODE2 0x98
1924#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00001925 const char *state;
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001926
Rob Landleye5b281f2006-04-29 15:49:18 +00001927 args[0] = WIN_CHECKPOWERMODE1;
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001928 if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0))
Glenn L McGrath07085852003-10-09 07:28:22 +00001929 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001930 if (errno != EIO || args[0] != 0 || args[1] != 0)
Rob Landleyadde7982006-05-16 15:32:30 +00001931 state = "Unknown";
Eric Andersen3443bd72003-07-22 07:30:36 +00001932 else
1933 state = "sleeping";
Eric Andersen3443bd72003-07-22 07:30:36 +00001934 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001935 else
1936 state = (args[2] == 255) ? "active/idle" : "standby";
Rob Landley39cf6452006-05-05 16:52:28 +00001937 args[1] = args[2] = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +00001938
Eric Andersen3443bd72003-07-22 07:30:36 +00001939 printf(" drive state is: %s\n", state);
1940 }
1941#endif
1942#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
Glenn L McGrath07085852003-10-09 07:28:22 +00001943 if (perform_reset)
1944 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001945 bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001946 }
1947#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
1948#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001949 if (perform_tristate)
1950 {
Rob Landleye5b281f2006-04-29 15:49:18 +00001951 args[0] = 0;
1952 args[1] = tristate;
Glenn L McGrath07085852003-10-09 07:28:22 +00001953 bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001954 }
1955#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
1956#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +00001957 if (get_identity)
1958 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001959 static struct hd_driveid id;
1960
Glenn L McGrath07085852003-10-09 07:28:22 +00001961 if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
1962 {
1963 if (multcount != -1)
1964 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001965 id.multsect = multcount;
1966 id.multsect_valid |= 1;
Glenn L McGrath07085852003-10-09 07:28:22 +00001967 }
1968 else
Eric Andersen3443bd72003-07-22 07:30:36 +00001969 id.multsect_valid &= ~1;
1970 dump_identity(&id);
Glenn L McGrath07085852003-10-09 07:28:22 +00001971 }
1972 else if (errno == -ENOMSG)
Eric Andersen3443bd72003-07-22 07:30:36 +00001973 printf(" no identification info available\n");
1974 else
Eric Andersen06d4ec22004-03-19 10:53:52 +00001975 bb_perror_msg("HDIO_GET_IDENTITY");
Eric Andersen3443bd72003-07-22 07:30:36 +00001976 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001977
1978 if (get_IDentity)
1979 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001980 unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */
Glenn L McGrath07085852003-10-09 07:28:22 +00001981
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001982 memset(args1, 0, sizeof(args1));
1983 args1[0] = WIN_IDENTIFY;
1984 args1[3] = 1;
Rob Landley0753f4a2006-06-07 00:27:25 +00001985 if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)"))
1986 identify((void *)(args1 + 4));
Eric Andersen3443bd72003-07-22 07:30:36 +00001987 }
1988#endif
1989#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001990 if (set_busstate)
1991 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001992 if (get_busstate)
1993 {
Rob Landleyadde7982006-05-16 15:32:30 +00001994 print_flag(1, "bus state", busstate);
Eric Andersen3443bd72003-07-22 07:30:36 +00001995 bus_state_value(busstate);
1996 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00001997 bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE");
Eric Andersen3443bd72003-07-22 07:30:36 +00001998 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001999 if (get_busstate)
2000 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002001 if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE"))
Glenn L McGrath07085852003-10-09 07:28:22 +00002002 {
Rob Landleyadde7982006-05-16 15:32:30 +00002003 printf(fmt, "bus state", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00002004 bus_state_value(parm);
2005 }
2006 }
2007#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002008 if (reread_partn)
2009 bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART");
2010
Eric Andersen3443bd72003-07-22 07:30:36 +00002011
2012 if (do_ctimings)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00002013 do_time(0,fd); /*time cache */
Eric Andersen3443bd72003-07-22 07:30:36 +00002014 if (do_timings)
Glenn L McGrath07085852003-10-09 07:28:22 +00002015 do_time(1,fd); /*time device */
Eric Andersen3443bd72003-07-22 07:30:36 +00002016 if (do_flush)
Rob Landleya3e4f382006-04-29 16:06:31 +00002017 flush_buffer_cache(fd);
2018 close(fd);
Eric Andersen3443bd72003-07-22 07:30:36 +00002019}
2020
Eric Andersen3443bd72003-07-22 07:30:36 +00002021#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Rob Landleya3e4f382006-04-29 16:06:31 +00002022static int fromhex(unsigned char c)
Eric Andersen3443bd72003-07-22 07:30:36 +00002023{
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00002024 if (isdigit(c))
Eric Andersen3443bd72003-07-22 07:30:36 +00002025 return (c - '0');
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00002026 if (c >= 'a' && c <= 'f')
2027 return (c - ('a' - 10));
Eric Andersen3443bd72003-07-22 07:30:36 +00002028 bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
2029}
2030
Rob Landley0f0b6452006-05-03 18:28:06 +00002031static void identify_from_stdin(void)
Eric Andersen3443bd72003-07-22 07:30:36 +00002032{
Rob Landley0753f4a2006-06-07 00:27:25 +00002033 uint16_t sbuf[256];
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00002034 unsigned char buf[1280];
2035 unsigned char *b = (unsigned char *)buf;
2036 int i;
Eric Andersen3443bd72003-07-22 07:30:36 +00002037
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00002038 xread(0, buf, 1280);
Rob Landleyade7f952006-05-25 18:53:06 +00002039
Rob Landley0753f4a2006-06-07 00:27:25 +00002040 // Convert the newline-separated hex data into an identify block.
2041
Denis Vlasenkobf0a2012006-12-26 10:42:51 +00002042 for (i = 0; i<256; i++) {
Rob Landley0753f4a2006-06-07 00:27:25 +00002043 int j;
Denis Vlasenkobf0a2012006-12-26 10:42:51 +00002044 for (j = 0; j < 4; j++)
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00002045 sbuf[i] = (sbuf[i] << 4) + fromhex(*(b++));
Eric Andersen3443bd72003-07-22 07:30:36 +00002046 }
Rob Landley0753f4a2006-06-07 00:27:25 +00002047
2048 // Parse the data.
2049
Rob Landley6389ff12006-05-01 19:28:53 +00002050 identify(sbuf);
Eric Andersen3443bd72003-07-22 07:30:36 +00002051}
2052#endif
2053
Rob Landley20deab02006-05-07 23:34:15 +00002054/* busybox specific stuff */
Rob Landley19802562006-05-08 15:35:46 +00002055static void parse_opts(unsigned long *get, unsigned long *set, unsigned long *value, int min, int max)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002056{
Denis Vlasenko6429aab2006-09-23 12:22:11 +00002057 if (get) {
2058 *get = 1;
2059 }
2060 if (optarg) {
2061 *set = 1;
Denis Vlasenko13858992006-10-08 12:49:22 +00002062 *value = xatol_range(optarg, min, max);
Denis Vlasenko6429aab2006-09-23 12:22:11 +00002063 }
Rob Landley20deab02006-05-07 23:34:15 +00002064}
2065
Rob Landleyade7f952006-05-25 18:53:06 +00002066static void parse_xfermode(int flag, unsigned long *get, unsigned long *set, int *value)
Rob Landley20deab02006-05-07 23:34:15 +00002067{
2068 if (flag) {
Rob Landleyade7f952006-05-25 18:53:06 +00002069 *get = 1;
Rob Landley20deab02006-05-07 23:34:15 +00002070 if (optarg) {
2071 *set = ((*value = translate_xfermode(optarg)) > -1);
2072 }
2073 }
2074}
2075
Rob Landley06208412006-05-31 22:52:57 +00002076/*------- getopt short options --------*/
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002077static const char hdparm_options[] = "gfu::n::p:r::m::c::k::a::B:tTh"
Rob Landley06208412006-05-31 22:52:57 +00002078 USE_FEATURE_HDPARM_GET_IDENTITY("iI")
Rob Landley20deab02006-05-07 23:34:15 +00002079 USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::")
2080#ifdef HDIO_DRIVE_CMD
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002081 "S:D:P:X:K:A:L:W:CyYzZ"
Rob Landley20deab02006-05-07 23:34:15 +00002082#endif
2083 USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:")
2084#ifdef HDIO_GET_QDMA
2085#ifdef HDIO_SET_QDMA
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002086 "Q:"
Rob Landley20deab02006-05-07 23:34:15 +00002087#else
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002088 "Q"
Rob Landley20deab02006-05-07 23:34:15 +00002089#endif
2090#endif
2091 USE_FEATURE_HDPARM_HDIO_DRIVE_RESET("w")
2092 USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF("x::b:")
2093 USE_FEATURE_HDPARM_HDIO_SCAN_HWIF("R:");
2094/*-------------------------------------*/
2095
2096/* our main() routine: */
Denis Vlasenko06af2162007-02-03 17:28:39 +00002097int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN;;
Rob Landley20deab02006-05-07 23:34:15 +00002098int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN;
Denis Vlasenko06af2162007-02-03 17:28:39 +00002099int hdparm_main(int argc, char **argv);
Rob Landley20deab02006-05-07 23:34:15 +00002100int hdparm_main(int argc, char **argv)
2101{
2102 int c;
Rob Landleyade7f952006-05-25 18:53:06 +00002103 int flagcount = 0;
Rob Landley20deab02006-05-07 23:34:15 +00002104
Rob Landley06208412006-05-31 22:52:57 +00002105 while ((c = getopt(argc, argv, hdparm_options)) >= 0) {
Rob Landley20deab02006-05-07 23:34:15 +00002106 flagcount++;
Rob Landley06208412006-05-31 22:52:57 +00002107 if (c == 'h') bb_show_usage(); /* EXIT */
Mike Frysingerea93f8a2006-06-07 14:25:22 +00002108 USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I'));
2109 USE_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i'));
Rob Landleyadde7982006-05-16 15:32:30 +00002110 get_geom |= (c == 'g');
2111 do_flush |= (c == 'f');
Rob Landley19802562006-05-08 15:35:46 +00002112 if (c == 'u') parse_opts(&get_unmask, &set_unmask, &unmask, 0, 1);
2113 USE_FEATURE_HDPARM_HDIO_GETSET_DMA(if (c == 'd') parse_opts(&get_dma, &set_dma, &dma, 0, 9));
2114 if (c == 'n') parse_opts(&get_nowerr, &set_nowerr, &nowerr, 0, 1);
Rob Landleyade7f952006-05-25 18:53:06 +00002115 parse_xfermode((c == 'p'),&noisy_piomode, &set_piomode, &piomode);
Rob Landley19802562006-05-08 15:35:46 +00002116 if (c == 'r') parse_opts(&get_readonly, &set_readonly, &readonly, 0, 1);
2117 if (c == 'm') parse_opts(&get_mult, &set_mult, &mult, 0, INT_MAX /*32*/);
2118 if (c == 'c') parse_opts(&get_io32bit, &set_io32bit, &io32bit, 0, INT_MAX /*8*/);
2119 if (c == 'k') parse_opts(&get_keep, &set_keep, &keep, 0, 1);
2120 if (c == 'a') parse_opts(&get_readahead, &set_readahead, &Xreadahead, 0, INT_MAX);
2121 if (c == 'B') parse_opts(&get_apmmode, &set_apmmode, &apmmode, 1, 255);
Rob Landleyadde7982006-05-16 15:32:30 +00002122 do_flush |= do_timings |= (c == 't');
2123 do_flush |= do_ctimings |= (c == 'T');
Rob Landley20deab02006-05-07 23:34:15 +00002124#ifdef HDIO_DRIVE_CMD
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00002125 if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX);
Rob Landley19802562006-05-08 15:35:46 +00002126 if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX);
2127 if (c == 'P') parse_opts(&get_prefetch, &set_prefetch, &prefetch, 0, INT_MAX);
Rob Landleyade7f952006-05-25 18:53:06 +00002128 parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested);
Rob Landley19802562006-05-08 15:35:46 +00002129 if (c == 'K') parse_opts(&get_dkeep, &set_dkeep, &prefetch, 0, 1);
2130 if (c == 'A') parse_opts(&get_lookahead, &set_lookahead, &lookahead, 0, 1);
2131 if (c == 'L') parse_opts(&get_doorlock, &set_doorlock, &doorlock, 0, 1);
2132 if (c == 'W') parse_opts(&get_wcache, &set_wcache, &wcache, 0, 1);
Rob Landleyade7f952006-05-25 18:53:06 +00002133 get_powermode |= (c == 'C');
2134 get_standbynow = set_standbynow |= (c == 'y');
2135 get_sleepnow = set_sleepnow |= (c == 'Y');
Rob Landleyadde7982006-05-16 15:32:30 +00002136 reread_partn |= (c == 'z');
Rob Landleyade7f952006-05-25 18:53:06 +00002137 get_seagate = set_seagate |= (c == 'Z');
Rob Landley20deab02006-05-07 23:34:15 +00002138#endif
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00002139 USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') parse_opts(NULL, &unregister_hwif, &hwif, 0, INT_MAX));
Rob Landley20deab02006-05-07 23:34:15 +00002140#ifdef HDIO_GET_QDMA
Rob Landley19802562006-05-08 15:35:46 +00002141 if (c == 'Q') {
Rob Landley20deab02006-05-07 23:34:15 +00002142#ifdef HDIO_SET_QDMA
Rob Landley19802562006-05-08 15:35:46 +00002143 parse_opts(&get_dma_q, &set_dma_q, &dma_q, 0, INT_MAX);
Rob Landley20deab02006-05-07 23:34:15 +00002144#else
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00002145 parse_opts(&get_dma_q, NULL, NULL, 0, 0);
Rob Landley20deab02006-05-07 23:34:15 +00002146#endif
Rob Landley19802562006-05-08 15:35:46 +00002147 }
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00002148#endif
Rob Landleyade7f952006-05-25 18:53:06 +00002149 USE_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r'));
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00002150 USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1));
2151 USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') parse_opts(&get_busstate, &set_busstate, &busstate, 0, 2));
Rob Landley20deab02006-05-07 23:34:15 +00002152#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
2153 if (c == 'R') {
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00002154 parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX);
Denis Vlasenko13858992006-10-08 12:49:22 +00002155 hwif_ctrl = xatoi_u((argv[optind]) ? argv[optind] : "");
2156 hwif_irq = xatoi_u((argv[optind+1]) ? argv[optind+1] : "");
Rob Landley20deab02006-05-07 23:34:15 +00002157 /* Move past the 2 additional arguments */
2158 argv += 2;
2159 argc -= 2;
2160 }
2161#endif
2162 }
Rob Landleyade7f952006-05-25 18:53:06 +00002163 /* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002164 if (!flagcount) {
Rob Landleyade7f952006-05-25 18:53:06 +00002165 get_mult = get_io32bit = get_unmask = get_keep = get_readonly = get_readahead = get_geom = 1;
2166 USE_FEATURE_HDPARM_HDIO_GETSET_DMA(get_dma = 1);
2167 }
Rob Landley20deab02006-05-07 23:34:15 +00002168 argc -= optind;
2169 argv += optind;
2170
2171 if (argc < 1) {
Rob Landley6d8ce172006-06-07 21:22:42 +00002172 if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO))
2173 identify_from_stdin(); /* EXIT */
2174 else bb_show_usage();
Rob Landley20deab02006-05-07 23:34:15 +00002175 }
2176
2177 while (argc--) {
2178 process_dev(*argv);
2179 argv++;
2180 }
2181 exit(EXIT_SUCCESS);
Eric Andersen3443bd72003-07-22 07:30:36 +00002182}