blob: 896dcbc2dd2d6204b3aaf2992d11ae47db522cd6 [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
Eric Andersen3443bd72003-07-22 07:30:36 +000015#include <unistd.h>
16#include <string.h>
17#include <stdlib.h>
18#include <fcntl.h>
19#include <errno.h>
20#include <ctype.h>
21#include <endian.h>
22#include <sys/ioctl.h>
23#include <sys/shm.h>
24#include <sys/sysmacros.h>
25#include <sys/time.h>
26#include <sys/times.h>
27#include <sys/mount.h>
28#include "busybox.h"
29#include <linux/types.h>
30#include <linux/hdreg.h>
Eric Andersen3443bd72003-07-22 07:30:36 +000031#include <asm/byteorder.h>
32
33
Rob Landley688ed0d2006-03-04 22:40:25 +000034#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
35# define __USE_XOPEN
Eric Andersen3443bd72003-07-22 07:30:36 +000036#endif
37
38/* device types */
39/* ------------ */
40#define NO_DEV 0xffff
41#define ATA_DEV 0x0000
42#define ATAPI_DEV 0x0001
43
44/* word definitions */
45/* ---------------- */
46#define GEN_CONFIG 0 /* general configuration */
47#define LCYLS 1 /* number of logical cylinders */
48#define CONFIG 2 /* specific configuration */
49#define LHEADS 3 /* number of logical heads */
50#define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */
51#define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */
52#define LSECTS 6 /* number of logical sectors/track */
53#define START_SERIAL 10 /* ASCII serial number */
54#define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */
55#define BUF_TYPE 20 /* buffer type (ATA-1) */
56#define BUFFER__SIZE 21 /* buffer size (ATA-1) */
57#define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/
58#define START_FW_REV 23 /* ASCII firmware revision */
59#define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000060#define START_MODEL 27 /* ASCII model number */
61#define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */
Eric Andersen3443bd72003-07-22 07:30:36 +000062#define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */
63#define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */
64#define CAPAB_0 49 /* capabilities */
65#define CAPAB_1 50
66#define PIO_MODE 51 /* max PIO mode supported (obsolete)*/
67#define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/
68#define WHATS_VALID 53 /* what fields are valid */
69#define LCYLS_CUR 54 /* current logical cylinders */
70#define LHEADS_CUR 55 /* current logical heads */
71#define LSECTS_CUR 56 /* current logical sectors/track */
72#define CAPACITY_LSB 57 /* current capacity in sectors */
73#define CAPACITY_MSB 58
74#define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */
75#define LBA_SECTS_LSB 60 /* LBA: total number of user */
76#define LBA_SECTS_MSB 61 /* addressable sectors */
77#define SINGLE_DMA 62 /* singleword DMA modes */
78#define MULTI_DMA 63 /* multiword DMA modes */
79#define ADV_PIO_MODES 64 /* advanced PIO modes supported */
80 /* multiword DMA xfer cycle time: */
81#define DMA_TIME_MIN 65 /* - minimum */
82#define DMA_TIME_NORM 66 /* - manufacturer's recommended */
83 /* minimum PIO xfer cycle time: */
84#define PIO_NO_FLOW 67 /* - without flow control */
85#define PIO_FLOW 68 /* - with IORDY flow control */
86#define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */
87#define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */
88#define CDR_MAJOR 73 /* CD ROM: major version number */
89#define CDR_MINOR 74 /* CD ROM: minor version number */
90#define QUEUE_DEPTH 75 /* queue depth */
91#define MAJOR 80 /* major version number */
92#define MINOR 81 /* minor version number */
93#define CMDS_SUPP_0 82 /* command/feature set(s) supported */
94#define CMDS_SUPP_1 83
95#define CMDS_SUPP_2 84
96#define CMDS_EN_0 85 /* command/feature set(s) enabled */
97#define CMDS_EN_1 86
98#define CMDS_EN_2 87
99#define ULTRA_DMA 88 /* ultra DMA modes */
100 /* time to complete security erase */
101#define ERASE_TIME 89 /* - ordinary */
102#define ENH_ERASE_TIME 90 /* - enhanced */
103#define ADV_PWR 91 /* current advanced power management level
Glenn L McGrath07085852003-10-09 07:28:22 +0000104 in low byte, 0x40 in high byte. */
Eric Andersen3443bd72003-07-22 07:30:36 +0000105#define PSWD_CODE 92 /* master password revision code */
106#define HWRST_RSLT 93 /* hardware reset result */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000107#define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000108#define LBA_LSB 100 /* LBA: maximum. Currently only 48 */
109#define LBA_MID 101 /* bits are used, but addr 103 */
110#define LBA_48_MSB 102 /* has been reserved for LBA in */
111#define LBA_64_MSB 103 /* the future. */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000112#define RM_STAT 127 /* removable media status notification feature set support */
Eric Andersen3443bd72003-07-22 07:30:36 +0000113#define SECU_STATUS 128 /* security status */
114#define CFA_PWR_MODE 160 /* CFA power mode 1 */
115#define START_MEDIA 176 /* media serial number */
116#define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/
117#define START_MANUF 196 /* media manufacturer I.D. */
118#define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */
119#define INTEGRITY 255 /* integrity word */
120
121/* bit definitions within the words */
122/* -------------------------------- */
123
124/* many words are considered valid if bit 15 is 0 and bit 14 is 1 */
125#define VALID 0xc000
126#define VALID_VAL 0x4000
127/* many words are considered invalid if they are either all-0 or all-1 */
128#define NOVAL_0 0x0000
129#define NOVAL_1 0xffff
130
131/* word 0: gen_config */
Glenn L McGrath07085852003-10-09 07:28:22 +0000132#define NOT_ATA 0x8000
Eric Andersen3443bd72003-07-22 07:30:36 +0000133#define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */
134#define MEDIA_REMOVABLE 0x0080
135#define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */
136#define INCOMPLETE 0x0004
137#define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */
138#define DRQ_RESPONSE_TIME 0x0060
139#define DRQ_3MS_VAL 0x0000
140#define DRQ_INTR_VAL 0x0020
141#define DRQ_50US_VAL 0x0040
142#define PKT_SIZE_SUPPORTED 0x0003
143#define PKT_SIZE_12_VAL 0x0000
144#define PKT_SIZE_16_VAL 0x0001
145#define EQPT_TYPE 0x1f00
146#define SHIFT_EQPT 8
147
148#define CDROM 0x0005
149
150#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000151static const char * const pkt_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000152 "Direct-access device", /* word 0, bits 12-8 = 00 */
153 "Sequential-access device", /* word 0, bits 12-8 = 01 */
154 "Printer", /* word 0, bits 12-8 = 02 */
155 "Processor", /* word 0, bits 12-8 = 03 */
156 "Write-once device", /* word 0, bits 12-8 = 04 */
157 "CD-ROM", /* word 0, bits 12-8 = 05 */
158 "Scanner", /* word 0, bits 12-8 = 06 */
159 "Optical memory", /* word 0, bits 12-8 = 07 */
160 "Medium changer", /* word 0, bits 12-8 = 08 */
161 "Communications device", /* word 0, bits 12-8 = 09 */
162 "ACS-IT8 device", /* word 0, bits 12-8 = 0a */
163 "ACS-IT8 device", /* word 0, bits 12-8 = 0b */
164 "Array controller", /* word 0, bits 12-8 = 0c */
165 "Enclosure services", /* word 0, bits 12-8 = 0d */
166 "Reduced block command device", /* word 0, bits 12-8 = 0e */
167 "Optical card reader/writer", /* word 0, bits 12-8 = 0f */
168 "", /* word 0, bits 12-8 = 10 */
169 "", /* word 0, bits 12-8 = 11 */
170 "", /* word 0, bits 12-8 = 12 */
171 "", /* word 0, bits 12-8 = 13 */
172 "", /* word 0, bits 12-8 = 14 */
173 "", /* word 0, bits 12-8 = 15 */
174 "", /* word 0, bits 12-8 = 16 */
175 "", /* word 0, bits 12-8 = 17 */
176 "", /* word 0, bits 12-8 = 18 */
177 "", /* word 0, bits 12-8 = 19 */
178 "", /* word 0, bits 12-8 = 1a */
179 "", /* word 0, bits 12-8 = 1b */
180 "", /* word 0, bits 12-8 = 1c */
181 "", /* word 0, bits 12-8 = 1d */
182 "", /* word 0, bits 12-8 = 1e */
183 "Unknown", /* word 0, bits 12-8 = 1f */
184};
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000185
186static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */
Eric Andersen3443bd72003-07-22 07:30:36 +0000187 "reserved", /* bit 0 */
188 "hard sectored", /* bit 1 */
189 "soft sectored", /* bit 2 */
190 "not MFM encoded ", /* bit 3 */
191 "head switch time > 15us", /* bit 4 */
192 "spindle motor control option", /* bit 5 */
193 "fixed drive", /* bit 6 */
194 "removable drive", /* bit 7 */
195 "disk xfer rate <= 5Mbs", /* bit 8 */
196 "disk xfer rate > 5Mbs, <= 10Mbs", /* bit 9 */
197 "disk xfer rate > 5Mbs", /* bit 10 */
198 "rotational speed tol.", /* bit 11 */
199 "data strobe offset option", /* bit 12 */
200 "track offset option", /* bit 13 */
201 "format speed tolerance gap reqd", /* bit 14 */
202 "ATAPI" /* bit 14 */
203};
204#endif
205
206/* word 1: number of logical cylinders */
207#define LCYLS_MAX 0x3fff /* maximum allowable value */
208
Eric Andersenaff114c2004-04-14 17:51:38 +0000209/* word 2: specific configuration
Eric Andersen3443bd72003-07-22 07:30:36 +0000210 * (a) require SET FEATURES to spin-up
211 * (b) require spin-up to fully reply to IDENTIFY DEVICE
212 */
213#define STBY_NID_VAL 0x37c8 /* (a) and (b) */
214#define STBY_ID_VAL 0x738c /* (a) and not (b) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000215#define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000216#define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */
217
218/* words 47 & 59: sector_xfer_max & sector_xfer_cur */
219#define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/
220#define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */
221
222/* word 49: capabilities 0 */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000223#define STD_STBY 0x2000 /* 1=standard values supported (ATA);
Eric Andersen3443bd72003-07-22 07:30:36 +0000224 0=vendor specific values */
225#define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */
226#define IORDY_OFF 0x0400 /* 1=may be disabled */
227#define LBA_SUP 0x0200 /* 1=Logical Block Address support */
228#define DMA_SUP 0x0100 /* 1=Direct Memory Access support */
229#define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */
230#define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */
231#define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */
232#define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */
233
234/* word 50: capabilities 1 */
235#define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */
236
237/* words 51 & 52: PIO & DMA cycle times */
238#define MODE 0xff00 /* the mode is in the MSBs */
239
240/* word 53: whats_valid */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000241#define OK_W88 0x0004 /* the ultra_dma info is valid */
Eric Andersen3443bd72003-07-22 07:30:36 +0000242#define OK_W64_70 0x0002 /* see above for word descriptions */
243#define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */
244
245/*word 63,88: dma_mode, ultra_dma_mode*/
246#define MODE_MAX 7 /* bit definitions force udma <=7 (when
247 * udma >=8 comes out it'll have to be
248 * defined in a new dma_mode word!) */
249
250/* word 64: PIO transfer modes */
251#define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */
252#define PIO_MODE_MAX 8 /* but all 8 bits are defined */
253
254/* word 75: queue_depth */
255#define DEPTH_BITS 0x001f /* bits used for queue depth */
256
257/* words 80-81: version numbers */
258/* NOVAL_0 or NOVAL_1 means device does not report version */
259
260/* word 81: minor version number */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000261#define MINOR_MAX 0x22
Eric Andersen3443bd72003-07-22 07:30:36 +0000262#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Rob Landley0e6a3e12006-04-28 01:33:30 +0000263static const char *minor_str[MINOR_MAX+2] = { /* word 81 value: */
264 "Unspecified", /* 0x0000 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000265 "ATA-1 X3T9.2 781D prior to revision 4", /* 0x0001 */
266 "ATA-1 published, ANSI X3.221-1994", /* 0x0002 */
267 "ATA-1 X3T9.2 781D revision 4", /* 0x0003 */
268 "ATA-2 published, ANSI X3.279-1996", /* 0x0004 */
269 "ATA-2 X3T10 948D prior to revision 2k", /* 0x0005 */
270 "ATA-3 X3T10 2008D revision 1", /* 0x0006 */
271 "ATA-2 X3T10 948D revision 2k", /* 0x0007 */
272 "ATA-3 X3T10 2008D revision 0", /* 0x0008 */
273 "ATA-2 X3T10 948D revision 3", /* 0x0009 */
274 "ATA-3 published, ANSI X3.298-199x", /* 0x000a */
275 "ATA-3 X3T10 2008D revision 6", /* 0x000b */
276 "ATA-3 X3T13 2008D revision 7 and 7a", /* 0x000c */
277 "ATA/ATAPI-4 X3T13 1153D revision 6", /* 0x000d */
278 "ATA/ATAPI-4 T13 1153D revision 13", /* 0x000e */
279 "ATA/ATAPI-4 X3T13 1153D revision 7", /* 0x000f */
280 "ATA/ATAPI-4 T13 1153D revision 18", /* 0x0010 */
281 "ATA/ATAPI-4 T13 1153D revision 15", /* 0x0011 */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000282 "ATA/ATAPI-4 published, ANSI INCITS 317-1998", /* 0x0012 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000283 "ATA/ATAPI-5 T13 1321D revision 3",
284 "ATA/ATAPI-4 T13 1153D revision 14", /* 0x0014 */
285 "ATA/ATAPI-5 T13 1321D revision 1", /* 0x0015 */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000286 "ATA/ATAPI-5 published, ANSI INCITS 340-2000", /* 0x0016 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000287 "ATA/ATAPI-4 T13 1153D revision 17", /* 0x0017 */
288 "ATA/ATAPI-6 T13 1410D revision 0", /* 0x0018 */
289 "ATA/ATAPI-6 T13 1410D revision 3a", /* 0x0019 */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000290 "ATA/ATAPI-7 T13 1532D revision 1", /* 0x001a */
Eric Andersen3443bd72003-07-22 07:30:36 +0000291 "ATA/ATAPI-6 T13 1410D revision 2", /* 0x001b */
292 "ATA/ATAPI-6 T13 1410D revision 1", /* 0x001c */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000293 "ATA/ATAPI-7 published, ANSI INCITS 397-2005", /* 0x001d */
294 "ATA/ATAPI-7 T13 1532D revision 0", /* 0x001e */
295 "Reserved" /* 0x001f */
296 "Reserved" /* 0x0020 */
297 "ATA/ATAPI-7 T13 1532D revision 4a", /* 0x0021 */
298 "ATA/ATAPI-6 published, ANSI INCITS 361-2002", /* 0x0022 */
299 "Reserved" /* 0x0023-0xfffe*/
Eric Andersen3443bd72003-07-22 07:30:36 +0000300};
301#endif
Rob Landley0e6a3e12006-04-28 01:33:30 +0000302static const char actual_ver[MINOR_MAX+2] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000303 /* word 81 value: */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000304 0, /* 0x0000 WARNING: */
305 1, /* 0x0001 WARNING: */
306 1, /* 0x0002 WARNING: */
307 1, /* 0x0003 WARNING: */
308 2, /* 0x0004 WARNING: This array */
309 2, /* 0x0005 WARNING: corresponds */
Eric Andersen3443bd72003-07-22 07:30:36 +0000310 3, /* 0x0006 WARNING: *exactly* */
311 2, /* 0x0007 WARNING: to the ATA/ */
312 3, /* 0x0008 WARNING: ATAPI version */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000313 2, /* 0x0009 WARNING: listed in */
314 3, /* 0x000a WARNING: the */
315 3, /* 0x000b WARNING: minor_str */
Eric Andersen3443bd72003-07-22 07:30:36 +0000316 3, /* 0x000c WARNING: array */
317 4, /* 0x000d WARNING: above. */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000318 4, /* 0x000e WARNING: */
319 4, /* 0x000f WARNING: if you change */
320 4, /* 0x0010 WARNING: that one, */
Eric Andersen3443bd72003-07-22 07:30:36 +0000321 4, /* 0x0011 WARNING: change this one */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000322 4, /* 0x0012 WARNING: too!!! */
Eric Andersen3443bd72003-07-22 07:30:36 +0000323 5, /* 0x0013 WARNING: */
324 4, /* 0x0014 WARNING: */
325 5, /* 0x0015 WARNING: */
326 5, /* 0x0016 WARNING: */
327 4, /* 0x0017 WARNING: */
328 6, /* 0x0018 WARNING: */
329 6, /* 0x0019 WARNING: */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000330 7, /* 0x001a WARNING: */
Eric Andersen3443bd72003-07-22 07:30:36 +0000331 6, /* 0x001b WARNING: */
332 6, /* 0x001c WARNING: */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000333 7, /* 0x001d WARNING: */
334 7, /* 0x001e WARNING: */
335 0, /* 0x001f WARNING: */
336 0, /* 0x0020 WARNING: */
337 7, /* 0x0021 WARNING: */
338 6, /* 0x0022 WARNING: */
339 0 /* 0x0023-0xfffe */
Eric Andersen3443bd72003-07-22 07:30:36 +0000340};
341
342/* words 82-84: cmds/feats supported */
343#define CMDS_W82 0x77ff /* word 82: defined command locations*/
344#define CMDS_W83 0x3fff /* word 83: defined command locations*/
345#define CMDS_W84 0x002f /* word 83: defined command locations*/
Glenn L McGrath07085852003-10-09 07:28:22 +0000346#define SUPPORT_48_BIT 0x0400
Eric Andersen3443bd72003-07-22 07:30:36 +0000347#define NUM_CMD_FEAT_STR 48
348
349#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000350static const char * const cmd_feat_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000351 "", /* word 82 bit 15: obsolete */
352 "NOP cmd", /* word 82 bit 14 */
353 "READ BUFFER cmd", /* word 82 bit 13 */
354 "WRITE BUFFER cmd", /* word 82 bit 12 */
355 "", /* word 82 bit 11: obsolete */
356 "Host Protected Area feature set", /* word 82 bit 10 */
357 "DEVICE RESET cmd", /* word 82 bit 9 */
358 "SERVICE interrupt", /* word 82 bit 8 */
359 "Release interrupt", /* word 82 bit 7 */
360 "Look-ahead", /* word 82 bit 6 */
361 "Write cache", /* word 82 bit 5 */
362 "PACKET command feature set", /* word 82 bit 4 */
363 "Power Management feature set", /* word 82 bit 3 */
364 "Removable Media feature set", /* word 82 bit 2 */
365 "Security Mode feature set", /* word 82 bit 1 */
366 "SMART feature set", /* word 82 bit 0 */
367 /* --------------*/
368 "", /* word 83 bit 15: !valid bit */
369 "", /* word 83 bit 14: valid bit */
370 "FLUSH CACHE EXT command", /* word 83 bit 13 */
371 "Mandatory FLUSH CACHE command ", /* word 83 bit 12 */
372 "Device Configuration Overlay feature set ",
373 "48-bit Address feature set ", /* word 83 bit 10 */
374 "",
375 "SET MAX security extension", /* word 83 bit 8 */
376 "Address Offset Reserved Area Boot", /* word 83 bit 7 */
377 "SET FEATURES subcommand required to spinup after power up",
378 "Power-Up In Standby feature set", /* word 83 bit 5 */
379 "Removable Media Status Notification feature set",
Eric Andersen06d4ec22004-03-19 10:53:52 +0000380 "Adv. Power Management feature set",/* word 83 bit 3 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000381 "CFA feature set", /* word 83 bit 2 */
382 "READ/WRITE DMA QUEUED", /* word 83 bit 1 */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000383 "DOWNLOAD MICROCODE cmd", /* word 83 bit 0 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000384 /* --------------*/
385 "", /* word 84 bit 15: !valid bit */
386 "", /* word 84 bit 14: valid bit */
387 "", /* word 84 bit 13: reserved */
388 "", /* word 84 bit 12: reserved */
389 "", /* word 84 bit 11: reserved */
390 "", /* word 84 bit 10: reserved */
391 "", /* word 84 bit 9: reserved */
392 "", /* word 84 bit 8: reserved */
393 "", /* word 84 bit 7: reserved */
394 "", /* word 84 bit 6: reserved */
395 "General Purpose Logging feature set", /* word 84 bit 5 */
396 "", /* word 84 bit 4: reserved */
397 "Media Card Pass Through Command feature set ",
398 "Media serial number ", /* word 84 bit 2 */
399 "SMART self-test ", /* word 84 bit 1 */
400 "SMART error logging " /* word 84 bit 0 */
401};
402#endif
403
404
405/* words 85-87: cmds/feats enabled */
406/* use cmd_feat_str[] to display what commands and features have
Glenn L McGrath07085852003-10-09 07:28:22 +0000407 * been enabled with words 85-87
Eric Andersen3443bd72003-07-22 07:30:36 +0000408 */
409
410/* words 89, 90, SECU ERASE TIME */
411#define ERASE_BITS 0x00ff
412
413/* word 92: master password revision */
414/* NOVAL_0 or NOVAL_1 means no support for master password revision */
415
416/* word 93: hw reset result */
417#define CBLID 0x2000 /* CBLID status */
418#define RST0 0x0001 /* 1=reset to device #0 */
419#define DEV_DET 0x0006 /* how device num determined */
420#define JUMPER_VAL 0x0002 /* device num determined by jumper */
421#define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */
422
423/* word 127: removable media status notification feature set support */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000424#define RM_STAT_BITS 0x0003
Eric Andersen3443bd72003-07-22 07:30:36 +0000425#define RM_STAT_SUP 0x0001
Glenn L McGrath07085852003-10-09 07:28:22 +0000426
Eric Andersen3443bd72003-07-22 07:30:36 +0000427/* word 128: security */
428#define SECU_ENABLED 0x0002
429#define SECU_LEVEL 0x0010
430#define NUM_SECU_STR 6
431#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000432static const char * const secu_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000433 "supported", /* word 128, bit 0 */
434 "enabled", /* word 128, bit 1 */
435 "locked", /* word 128, bit 2 */
436 "frozen", /* word 128, bit 3 */
437 "expired: security count", /* word 128, bit 4 */
438 "supported: enhanced erase" /* word 128, bit 5 */
439};
440#endif
441
442/* word 160: CFA power mode */
443#define VALID_W160 0x8000 /* 1=word valid */
444#define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/
445#define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */
446#define MAX_AMPS 0x0fff /* value = max current in ma */
447
448/* word 255: integrity */
449#define SIG 0x00ff /* signature location */
450#define SIG_VAL 0x00A5 /* signature value */
451
Glenn L McGrath07085852003-10-09 07:28:22 +0000452#define VERSION "v5.4"
453
454#define TIMING_MB 64
455#define TIMING_BUF_MB 1
456#define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024)
457#define TIMING_BUF_COUNT (timing_MB / TIMING_BUF_MB)
458#define BUFCACHE_FACTOR 2
459
460#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
461
462/* Busybox messages and functions */
463
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000464static const char bb_msg_shared_mem[] = "could not %s sharedmem buf";
465static const char bb_msg_op_not_supp[] = " operation not supported on %s disks";
Glenn L McGrath07085852003-10-09 07:28:22 +0000466
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000467static int bb_ioctl(int fd, int request, void *argp, const char *string)
Glenn L McGrath07085852003-10-09 07:28:22 +0000468{
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000469 int e = ioctl(fd, request, argp);
470 if (e && string)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000471 bb_perror_msg(" %s", string);
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000472 return e;
Glenn L McGrath07085852003-10-09 07:28:22 +0000473}
474
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000475static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const char *string)
476{
477 if (!ioctl(fd, cmd, args))
478 return 0;
479 args[0] = alt;
480 return bb_ioctl(fd, cmd, args, string);
481}
482
483
Glenn L McGrath07085852003-10-09 07:28:22 +0000484static void if_printf(unsigned long i, char *fmt, ... )
485{
Rob Landleya3e4f382006-04-29 16:06:31 +0000486 va_list ap;
487 va_start(ap, fmt);
488 if (i)
489 vprintf(fmt, ap);
490 va_end(ap);
Glenn L McGrath07085852003-10-09 07:28:22 +0000491}
492
Rob Landleya3e4f382006-04-29 16:06:31 +0000493static void on_off(unsigned int value);
Glenn L McGrath07085852003-10-09 07:28:22 +0000494
495static void if_printf_on_off(unsigned long get_arg,const char *fmt, unsigned long arg)
496{
497 if (get_arg)
498 {
499 printf(fmt, arg);
500 on_off(arg);
501 }
502}
503
504static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string,
505 const char * fmt)
506{
Rob Landleya3e4f382006-04-29 16:06:31 +0000507 if (ioctl(fd, request, &argp) != 0)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000508 bb_perror_msg(" %s", string);
Glenn L McGrath07085852003-10-09 07:28:22 +0000509 else
510 {
511 printf(fmt, (unsigned long) argp);
512 on_off((unsigned long) argp);
513 }
514}
Eric Andersen416c2422003-12-12 00:08:57 +0000515
516#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000517static void if_else_printf(unsigned long i, char *fmt1, char *fmt2, ... )
518{
Rob Landleya3e4f382006-04-29 16:06:31 +0000519 va_list ap;
520 va_start(ap, fmt2);
521 if (i)
522 vprintf(fmt1, ap);
523 else
524 vprintf(fmt2, ap);
525 va_end(ap);
Glenn L McGrath07085852003-10-09 07:28:22 +0000526}
527
528static void print_ascii(uint16_t *p, uint8_t length);
529
530static void xprint_ascii(uint16_t *val ,int i, char * string, int n)
531{
Rob Landleya3e4f382006-04-29 16:06:31 +0000532 if (val[i])
Glenn L McGrath07085852003-10-09 07:28:22 +0000533 {
534 printf("\t%-20s",string);
535 print_ascii(&val[i], n);
536 }
537}
538
Eric Andersen416c2422003-12-12 00:08:57 +0000539static void if_strcat(unsigned long test, char *modes, char *string)
540{
541 if (test)
542 strcat(modes,string);
543}
544#endif
545
Glenn L McGrath07085852003-10-09 07:28:22 +0000546static void sync_and_sleep(int i)
547{
548 sync();
549 sleep(i);
550}
551
Eric Andersenb2aa7762004-04-05 13:08:08 +0000552static uint16_t check_if_min_and_set_val(uint16_t a, uint16_t b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000553{
Rob Landleya3e4f382006-04-29 16:06:31 +0000554 if ( a < b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000555 a = b;
Eric Andersenb2aa7762004-04-05 13:08:08 +0000556 return a;
Glenn L McGrath07085852003-10-09 07:28:22 +0000557}
558
Eric Andersenb2aa7762004-04-05 13:08:08 +0000559static uint16_t check_if_maj_and_set_val(uint16_t a, uint16_t b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000560{
Rob Landleya3e4f382006-04-29 16:06:31 +0000561 if ( a > b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000562 a = b;
Eric Andersenb2aa7762004-04-05 13:08:08 +0000563 return a;
Glenn L McGrath07085852003-10-09 07:28:22 +0000564}
565
Eric Andersenb2aa7762004-04-05 13:08:08 +0000566static unsigned long int set_flag(char *p, char max)
Glenn L McGrath07085852003-10-09 07:28:22 +0000567{
568 if (*p >= '0' && *p <= max )
569 return 1;
570 return 0;
571}
572
Glenn L McGrath07085852003-10-09 07:28:22 +0000573/* end of busybox specific stuff */
574
Eric Andersen3443bd72003-07-22 07:30:36 +0000575#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000576static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
577{
Eric Andersen3443bd72003-07-22 07:30:36 +0000578 uint16_t ii;
579 uint8_t err_dma = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000580
Rob Landleya3e4f382006-04-29 16:06:31 +0000581 for (ii = 0; ii <= MODE_MAX; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000582 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000583 if (mode_sel & 0x0001)
Glenn L McGrath07085852003-10-09 07:28:22 +0000584 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000585 printf("*%cdma%u ",cc,ii);
Rob Landleya3e4f382006-04-29 16:06:31 +0000586 if (*have_mode)
Glenn L McGrath07085852003-10-09 07:28:22 +0000587 err_dma = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000588 *have_mode = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000589 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000590 else if (mode_sup & 0x0001)
Glenn L McGrath07085852003-10-09 07:28:22 +0000591 printf("%cdma%u ",cc,ii);
592
593 mode_sup >>=1;
594 mode_sel >>=1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000595 }
596 return err_dma;
597}
Glenn L McGrath07085852003-10-09 07:28:22 +0000598
Eric Andersen3443bd72003-07-22 07:30:36 +0000599static void print_ascii(uint16_t *p, uint8_t length) {
600 uint8_t ii;
601 char cl;
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000602
Eric Andersen3443bd72003-07-22 07:30:36 +0000603 /* find first non-space & print it */
Rob Landleya3e4f382006-04-29 16:06:31 +0000604 for (ii = 0; ii< length; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000605 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000606 if (((char) 0x00ff&((*p)>>8)) != ' ')
Glenn L McGrath07085852003-10-09 07:28:22 +0000607 break;
Rob Landleya3e4f382006-04-29 16:06:31 +0000608 if ((cl = (char) 0x00ff&(*p)) != ' ')
Glenn L McGrath07085852003-10-09 07:28:22 +0000609 {
610 if_printf((cl != '\0'),"%c",cl);
611 p++;
612 ii++;
Eric Andersen3443bd72003-07-22 07:30:36 +0000613 break;
614 }
615 p++;
616 }
617 /* print the rest */
Rob Landleya3e4f382006-04-29 16:06:31 +0000618 for (; ii< length; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000619 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000620 if (!(*p))
Glenn L McGrath07085852003-10-09 07:28:22 +0000621 break; /* some older devices have NULLs */
Eric Andersen3443bd72003-07-22 07:30:36 +0000622 printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff);
623 p++;
624 }
625 printf("\n");
626}
627
628/* identify() is the only extern function used across two source files. The
629 others, though, were declared in hdparm.c with global scope; since other
630 functions in that file have static (file) scope, I assume the difference is
631 intentional. */
Rob Landley6389ff12006-05-01 19:28:53 +0000632static void identify(uint16_t *id_supplied)
Eric Andersen3443bd72003-07-22 07:30:36 +0000633{
Rob Landley5bc3f052006-04-29 19:11:24 +0000634 uint16_t buf[256];
635 uint16_t *val, ii, jj, kk;
Eric Andersen3443bd72003-07-22 07:30:36 +0000636 uint16_t like_std = 1, std = 0, min_std = 0xffff;
637 uint16_t dev = NO_DEV, eqpt = NO_DEV;
638 uint8_t have_mode = 0, err_dma = 0;
639 uint8_t chksum = 0;
640 uint32_t ll, mm, nn, oo;
Rob Landley2e2d7522006-04-29 15:23:33 +0000641 uint64_t bbbig; /* (:) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000642
Rob Landley5bc3f052006-04-29 19:11:24 +0000643 if (BB_BIG_ENDIAN) {
644 swab(id_supplied, buf, sizeof(buf));
645 val = buf;
646 } else val = id_supplied;
647
Eric Andersen3443bd72003-07-22 07:30:36 +0000648 chksum &= 0xff;
649
650 /* check if we recognise the device type */
651 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000652 if(!(val[GEN_CONFIG] & NOT_ATA))
653 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000654 dev = ATA_DEV;
655 printf("ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000656 }
657 else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL)
658 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000659 dev = ATA_DEV;
660 like_std = 4;
661 printf("CompactFlash ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000662 }
663 else if(!(val[GEN_CONFIG] & NOT_ATAPI))
664 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000665 dev = ATAPI_DEV;
666 eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
667 printf("ATAPI %s, with ", pkt_str[eqpt]);
668 like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000669 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000670 else
671 /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/
672 bb_error_msg_and_die("Unknown device type");
Eric Andersen3443bd72003-07-22 07:30:36 +0000673
Glenn L McGrath07085852003-10-09 07:28:22 +0000674 if_printf(!(val[GEN_CONFIG] & MEDIA_REMOVABLE),"non-");
675 printf("removable media\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000676
677 /* Info from the specific configuration word says whether or not the
678 * ID command completed correctly. It is only defined, however in
Glenn L McGrath07085852003-10-09 07:28:22 +0000679 * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior
Eric Andersen3443bd72003-07-22 07:30:36 +0000680 * standards. Since the values allowed for this word are extremely
681 * specific, it should be safe to check it now, even though we don't
682 * know yet what standard this device is using.
683 */
Rob Landleya3e4f382006-04-29 16:06:31 +0000684 if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000685 (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) )
686 {
687 like_std = 5;
688 if_printf(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)),
689 "powers-up in standby; SET FEATURES subcmd spins-up.\n");
690 if_printf((((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)),
691 "\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000692 }
693
694 /* output the model and serial numbers and the fw revision */
Glenn L McGrath07085852003-10-09 07:28:22 +0000695 xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL);
696 xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL);
697 xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV);
698 xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA);
699 xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF);
Eric Andersen3443bd72003-07-22 07:30:36 +0000700
701 /* major & minor standards version number (Note: these words were not
702 * defined until ATA-3 & the CDROM std uses different words.) */
703 printf("Standards:");
Rob Landleya3e4f382006-04-29 16:06:31 +0000704 if (eqpt != CDROM)
Glenn L McGrath07085852003-10-09 07:28:22 +0000705 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000706 if (val[MINOR] && (val[MINOR] <= MINOR_MAX))
Glenn L McGrath07085852003-10-09 07:28:22 +0000707 {
Eric Andersenb2aa7762004-04-05 13:08:08 +0000708 like_std=check_if_min_and_set_val(like_std, 3);
Eric Andersen3443bd72003-07-22 07:30:36 +0000709 std = actual_ver[val[MINOR]];
Glenn L McGrath07085852003-10-09 07:28:22 +0000710 if_printf(std,"\n\tUsed: %s ",minor_str[val[MINOR]]);
711
Eric Andersen3443bd72003-07-22 07:30:36 +0000712 }
713 /* looks like when they up-issue the std, they obsolete one;
Glenn L McGrath07085852003-10-09 07:28:22 +0000714 * thus, only the newest 4 issues need be supported. (That's
Eric Andersen3443bd72003-07-22 07:30:36 +0000715 * what "kk" and "min_std" are all about.) */
Rob Landleya3e4f382006-04-29 16:06:31 +0000716 if (val[MAJOR] && (val[MAJOR] !=NOVAL_1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000717 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000718 printf("\n\tSupported: ");
719 jj = val[MAJOR] << 1;
720 kk = like_std >4 ? like_std-4: 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000721 for (ii = 14; (ii >0)&&(ii>kk); ii--)
Glenn L McGrath07085852003-10-09 07:28:22 +0000722 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000723 if (jj & 0x8000)
Glenn L McGrath07085852003-10-09 07:28:22 +0000724 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000725 printf("%u ", ii);
Rob Landleya3e4f382006-04-29 16:06:31 +0000726 if (like_std < ii)
Glenn L McGrath07085852003-10-09 07:28:22 +0000727 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000728 like_std = ii;
729 kk = like_std >4 ? like_std-4: 0;
730 }
Eric Andersenb2aa7762004-04-05 13:08:08 +0000731 min_std=check_if_maj_and_set_val(min_std, ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000732 }
733 jj <<= 1;
734 }
Eric Andersenb2aa7762004-04-05 13:08:08 +0000735 like_std=check_if_min_and_set_val(like_std, 3);
Eric Andersen3443bd72003-07-22 07:30:36 +0000736 }
737 /* Figure out what standard the device is using if it hasn't told
738 * us. If we know the std, check if the device is using any of
739 * the words from the next level up. It happens.
740 */
Eric Andersenb2aa7762004-04-05 13:08:08 +0000741 like_std=check_if_min_and_set_val(like_std, std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000742
Rob Landleya3e4f382006-04-29 16:06:31 +0000743 if (((std == 5) || (!std && (like_std < 6))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000744 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
745 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) ||
746 ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) &&
747 ( val[CMDS_SUPP_2] & CMDS_W84) ) ) )
748 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000749 like_std = 6;
Glenn L McGrath07085852003-10-09 07:28:22 +0000750 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000751 else if (((std == 4) || (!std && (like_std < 5))) &&
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000752 ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000753 (( val[HWRST_RSLT] & VALID) == VALID_VAL) ||
754 ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
755 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) )
756 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000757 like_std = 5;
Glenn L McGrath07085852003-10-09 07:28:22 +0000758 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000759 else if (((std == 3) || (!std && (like_std < 4))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000760 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
761 ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) ||
762 (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) ||
763 (( val[CAPAB_1] & VALID) == VALID_VAL) ||
764 (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) ||
765 (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) )
766 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000767 like_std = 4;
Glenn L McGrath07085852003-10-09 07:28:22 +0000768 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000769 else if (((std == 2) || (!std && (like_std < 3))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000770 ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) )
771 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000772 like_std = 3;
Glenn L McGrath07085852003-10-09 07:28:22 +0000773 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000774 else if (((std == 1) || (!std && (like_std < 2))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000775 ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) ||
776 (val[WHATS_VALID] & OK_W64_70)) )
777 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000778 like_std = 2;
779 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000780 if (!std)
Eric Andersen3443bd72003-07-22 07:30:36 +0000781 printf("\n\tLikely used: %u\n",like_std);
Rob Landleya3e4f382006-04-29 16:06:31 +0000782 else if (like_std > std)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000783 printf("& some of %u\n",like_std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000784 else
785 printf("\n");
786 }
787 else
788 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000789 /* TBD: do CDROM stuff more thoroughly. For now... */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000790 kk = 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000791 if (val[CDR_MINOR] == 9)
Glenn L McGrath07085852003-10-09 07:28:22 +0000792 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000793 kk = 1;
794 printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5");
795 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000796 if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000797 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000798 kk = 1;
799 printf("\n\tSupported: CD-ROM ATAPI");
800 jj = val[CDR_MAJOR] >> 1;
Rob Landleya3e4f382006-04-29 16:06:31 +0000801 for (ii = 1; ii <15; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000802 {
803 if_printf((jj & 0x0001),"-%u ", ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000804 jj >>= 1;
805 }
806 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000807 if_else_printf((!kk),"\n\tLikely used CD-ROM ATAPI-1\n","\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000808 /* the cdrom stuff is more like ATA-2 than anything else, so: */
809 like_std = 2;
810 }
811
Rob Landleya3e4f382006-04-29 16:06:31 +0000812 if (min_std == 0xffff)
Glenn L McGrath07085852003-10-09 07:28:22 +0000813 min_std = like_std > 4 ? like_std - 3 : 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000814
815 printf("Configuration:\n");
816 /* more info from the general configuration word */
Rob Landleya3e4f382006-04-29 16:06:31 +0000817 if ((eqpt != CDROM) && (like_std == 1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000818 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000819 jj = val[GEN_CONFIG] >> 1;
Rob Landleya3e4f382006-04-29 16:06:31 +0000820 for (ii = 1; ii < 15; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000821 {
822 if_printf((jj & 0x0001),"\t%s\n",ata1_cfg_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000823 jj >>=1;
824 }
825 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000826 if (dev == ATAPI_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000827 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000828 printf("\tDRQ response: "); /* Data Request (DRQ) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000829 switch(val[GEN_CONFIG] & DRQ_RESPONSE_TIME)
830 {
831 case DRQ_3MS_VAL :
832 printf("3ms.\n");
833 break;
834 case DRQ_INTR_VAL :
835 printf("<=10ms with INTRQ\n");
836 break;
837 case DRQ_50US_VAL :
838 printf("50us.\n");
839 break;
840 default :
841 printf("unknown.\n");
842 break;
Eric Andersen3443bd72003-07-22 07:30:36 +0000843 }
844 printf("\tPacket size: ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000845 switch(val[GEN_CONFIG] & PKT_SIZE_SUPPORTED)
846 {
847 case PKT_SIZE_12_VAL :
848 printf("12 bytes\n");
849 break;
850 case PKT_SIZE_16_VAL :
851 printf("16 bytes\n");
852 break;
853 default :
854 printf("Unknown\n");
855 break;
Eric Andersen3443bd72003-07-22 07:30:36 +0000856 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000857 }
858 else
859 {
860 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000861 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
862 mm = 0; bbbig = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000863 if ( (ll > 0x00FBFC10) && (!val[LCYLS]))
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000864 printf("\tCHS addressing not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000865 else
866 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000867 jj = val[WHATS_VALID] & OK_W54_58;
Glenn L McGrath07085852003-10-09 07:28:22 +0000868 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",
869 val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0);
870
871 if_printf(((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])),
872 "\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]);
873
Rob Landleya3e4f382006-04-29 16:06:31 +0000874 if (jj)
Glenn L McGrath07085852003-10-09 07:28:22 +0000875 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000876 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
Rob Landleya3e4f382006-04-29 16:06:31 +0000877 if (like_std < 3)
Glenn L McGrath07085852003-10-09 07:28:22 +0000878 {
879 /* check Endian of capacity bytes */
Eric Andersen3443bd72003-07-22 07:30:36 +0000880 nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR];
881 oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB];
Rob Landleya3e4f382006-04-29 16:06:31 +0000882 if (abs(mm - nn) > abs(oo - nn))
Eric Andersen3443bd72003-07-22 07:30:36 +0000883 mm = oo;
884 }
885 printf("\tCHS current addressable sectors:%11u\n",mm);
Glenn L McGrath07085852003-10-09 07:28:22 +0000886 }
Eric Andersen3443bd72003-07-22 07:30:36 +0000887 }
888 /* LBA addressing */
889 printf("\tLBA user addressable sectors:%11u\n",ll);
Rob Landleya3e4f382006-04-29 16:06:31 +0000890 if ( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000891 (val[CMDS_SUPP_1] & SUPPORT_48_BIT) )
892 {
Rob Landley2e2d7522006-04-29 15:23:33 +0000893 bbbig = (uint64_t)val[LBA_64_MSB] << 48 |
894 (uint64_t)val[LBA_48_MSB] << 32 |
895 (uint64_t)val[LBA_MID] << 16 |
Glenn L McGrath07085852003-10-09 07:28:22 +0000896 val[LBA_LSB] ;
Eric Andersen3443bd72003-07-22 07:30:36 +0000897 printf("\tLBA48 user addressable sectors:%11llu\n",bbbig);
898 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000899
900 if (!bbbig)
Rob Landley2e2d7522006-04-29 15:23:33 +0000901 bbbig = (uint64_t)(ll>mm ? ll : mm); /* # 512 byte blocks */
Eric Andersen3443bd72003-07-22 07:30:36 +0000902 printf("\tdevice size with M = 1024*1024: %11llu MBytes\n",bbbig>>11);
903 bbbig = (bbbig<<9)/1000000;
904 printf("\tdevice size with M = 1000*1000: %11llu MBytes ",bbbig);
Glenn L McGrath07085852003-10-09 07:28:22 +0000905
906 if_else_printf((bbbig > 1000),"(%llu GB)\n","\n",bbbig/1000);
Eric Andersen3443bd72003-07-22 07:30:36 +0000907
908 }
909
910 /* hw support of commands (capabilities) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000911 printf("Capabilities:\n\t");
912
Rob Landleya3e4f382006-04-29 16:06:31 +0000913 if (dev == ATAPI_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000914 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000915 if (eqpt != CDROM)
Glenn L McGrath07085852003-10-09 07:28:22 +0000916 if_printf((val[CAPAB_0] & CMD_Q_SUP),"Cmd queuing, ");
917
918 if_printf((val[CAPAB_0] & OVLP_SUP),"Cmd overlap, ");
Eric Andersen3443bd72003-07-22 07:30:36 +0000919 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000920 if_printf((val[CAPAB_0] & LBA_SUP),"LBA, ");
921
Rob Landleya3e4f382006-04-29 16:06:31 +0000922 if (like_std != 1)
Glenn L McGrath07085852003-10-09 07:28:22 +0000923 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000924 printf("IORDY");
Glenn L McGrath07085852003-10-09 07:28:22 +0000925 if_printf((!(val[CAPAB_0] & IORDY_SUP)),"(may be)");
926 if_else_printf((val[CAPAB_0] & IORDY_OFF),"(can","(cannot");
927 printf(" be disabled)\n");
928 }
929 else
930 printf("no IORDY\n");
931
Rob Landleya3e4f382006-04-29 16:06:31 +0000932 if ((like_std == 1) && val[BUF_TYPE])
Glenn L McGrath07085852003-10-09 07:28:22 +0000933 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000934 kk = val[BUF_TYPE];
935 printf("\tBuffer type: %04x: ",kk);
Glenn L McGrath07085852003-10-09 07:28:22 +0000936 if_else_printf((kk < 2),"single port, single-sector","dual port, multi-sector");
937 if_printf((kk > 2)," with read caching ability");
Eric Andersen3443bd72003-07-22 07:30:36 +0000938 printf("\n");
939 }
940 jj = 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000941 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1)))
Glenn L McGrath07085852003-10-09 07:28:22 +0000942 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000943 printf("\tBuffer size: %.1fkB",(float)val[BUFFER__SIZE]/2);
944 jj = 1;
945 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000946 if ((min_std < 4) && (val[RW_LONG]))
Glenn L McGrath07085852003-10-09 07:28:22 +0000947 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000948 printf("\tbytes avail on r/w long: %u",val[RW_LONG]);
949 jj = 1;
950 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000951 if ((eqpt != CDROM) && (like_std > 3))
Glenn L McGrath07085852003-10-09 07:28:22 +0000952 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000953 printf("\tQueue depth: %u",(val[QUEUE_DEPTH] & DEPTH_BITS)+1);
954 jj = 1;
955 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000956 if_printf(jj,"\n");
957
Rob Landleya3e4f382006-04-29 16:06:31 +0000958 if (dev == ATA_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000959 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000960 if (like_std == 1)
Glenn L McGrath07085852003-10-09 07:28:22 +0000961 printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":"");
962 else
963 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000964 printf("\tStandby timer values: spec'd by ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000965 if_else_printf((val[CAPAB_0] & STD_STBY),"Standard","Vendor");
Rob Landleya3e4f382006-04-29 16:06:31 +0000966 if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
Glenn L McGrath07085852003-10-09 07:28:22 +0000967 printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no");
968 else
969 printf("\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000970 }
971 printf("\tR/W multiple sector transfer: ");
Rob Landleya3e4f382006-04-29 16:06:31 +0000972 if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
Eric Andersen3443bd72003-07-22 07:30:36 +0000973 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000974 else
975 {
976 printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER);
977 if_else_printf((val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID),
978 "%u\n","?\n",val[SECTOR_XFER_CUR] & SECTOR_XFER);
Eric Andersen3443bd72003-07-22 07:30:36 +0000979 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000980 if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008))
Glenn L McGrath07085852003-10-09 07:28:22 +0000981 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000982 /* We print out elsewhere whether the APM feature is enabled or
983 not. If it's not enabled, let's not repeat the info; just print
984 nothing here. */
Glenn L McGrath07085852003-10-09 07:28:22 +0000985 printf("\tAdvancedPM level: ");
986 if ( (val[ADV_PWR] & 0xFF00) == 0x4000 )
987 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000988 uint8_t apm_level = val[ADV_PWR] & 0x00FF;
Eric Andersen3443bd72003-07-22 07:30:36 +0000989 printf("%u (0x%x)\n", apm_level, apm_level);
Glenn L McGrath07085852003-10-09 07:28:22 +0000990 }
991 else
Eric Andersen3443bd72003-07-22 07:30:36 +0000992 printf("unknown setting (0x%04x)\n", val[ADV_PWR]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000993 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000994 if (like_std > 5)
Glenn L McGrath07085852003-10-09 07:28:22 +0000995 {
996 if_printf(val[ACOUSTIC],"\tRecommended acoustic management value: %u, current value: %u\n",
997 (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff);
Eric Andersen3443bd72003-07-22 07:30:36 +0000998 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000999 }
1000 else
1001 {
1002 /* ATAPI */
Rob Landleya3e4f382006-04-29 16:06:31 +00001003 if (eqpt != CDROM)
Glenn L McGrath07085852003-10-09 07:28:22 +00001004 if_printf((val[CAPAB_0] & SWRST_REQ),"\tATA sw reset required\n");
1005
Rob Landleya3e4f382006-04-29 16:06:31 +00001006 if (val[PKT_REL] || val[SVC_NBSY])
Glenn L McGrath07085852003-10-09 07:28:22 +00001007 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001008 printf("\tOverlap support:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001009 if_printf(val[PKT_REL]," %uus to release bus.",val[PKT_REL]);
1010 if_printf(val[SVC_NBSY]," %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001011 printf("\n");
1012 }
1013 }
1014
1015 /* DMA stuff. Check that only one DMA mode is selected. */
1016 printf("\tDMA: ");
Rob Landleya3e4f382006-04-29 16:06:31 +00001017 if (!(val[CAPAB_0] & DMA_SUP))
Eric Andersen3443bd72003-07-22 07:30:36 +00001018 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001019 else
1020 {
1021 if_printf((val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]),
1022 " sdma%u\n",(val[DMA_MODE] & MODE) >> 8);
Rob Landleya3e4f382006-04-29 16:06:31 +00001023 if (val[SINGLE_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +00001024 {
1025 jj = val[SINGLE_DMA];
1026 kk = val[SINGLE_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001027 err_dma += mode_loop(jj,kk,'s',&have_mode);
1028 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001029 if (val[MULTI_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +00001030 {
1031 jj = val[MULTI_DMA];
1032 kk = val[MULTI_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001033 err_dma += mode_loop(jj,kk,'m',&have_mode);
1034 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001035 if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +00001036 {
1037 jj = val[ULTRA_DMA];
1038 kk = val[ULTRA_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001039 err_dma += mode_loop(jj,kk,'u',&have_mode);
1040 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001041 if_printf((err_dma || !have_mode),"(?)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001042 printf("\n");
1043
Glenn L McGrath07085852003-10-09 07:28:22 +00001044 if_printf(((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)),
1045 "\t Interleaved DMA support\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001046
Rob Landleya3e4f382006-04-29 16:06:31 +00001047 if ((val[WHATS_VALID] & OK_W64_70) &&
Glenn L McGrath07085852003-10-09 07:28:22 +00001048 (val[DMA_TIME_MIN] || val[DMA_TIME_NORM]))
1049 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001050 printf("\t Cycle time:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001051 if_printf(val[DMA_TIME_MIN]," min=%uns",val[DMA_TIME_MIN]);
1052 if_printf(val[DMA_TIME_NORM]," recommended=%uns",val[DMA_TIME_NORM]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001053 printf("\n");
1054 }
1055 }
1056
1057 /* Programmed IO stuff */
1058 printf("\tPIO: ");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001059 /* If a drive supports mode n (e.g. 3), it also supports all modes less
Eric Andersen3443bd72003-07-22 07:30:36 +00001060 * than n (e.g. 3, 2, 1 and 0). Print all the modes. */
Rob Landleya3e4f382006-04-29 16:06:31 +00001061 if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP))
Glenn L McGrath07085852003-10-09 07:28:22 +00001062 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001063 jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007;
Rob Landleya3e4f382006-04-29 16:06:31 +00001064 for (ii = 0; ii <= PIO_MODE_MAX ; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +00001065 {
1066 if_printf((jj & 0x0001),"pio%d ",ii);
Eric Andersen3443bd72003-07-22 07:30:36 +00001067 jj >>=1;
1068 }
1069 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001070 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001071 else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) )
Glenn L McGrath07085852003-10-09 07:28:22 +00001072 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001073 for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
Eric Andersen3443bd72003-07-22 07:30:36 +00001074 printf("pio%d ",ii);
Eric Andersen3443bd72003-07-22 07:30:36 +00001075 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001076 }
1077 else
1078 printf("unknown\n");
1079
Rob Landleya3e4f382006-04-29 16:06:31 +00001080 if (val[WHATS_VALID] & OK_W64_70)
Glenn L McGrath07085852003-10-09 07:28:22 +00001081 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001082 if (val[PIO_NO_FLOW] || val[PIO_FLOW])
Glenn L McGrath07085852003-10-09 07:28:22 +00001083 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001084 printf("\t Cycle time:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001085 if_printf(val[PIO_NO_FLOW]," no flow control=%uns", val[PIO_NO_FLOW]);
1086 if_printf(val[PIO_FLOW]," IORDY flow control=%uns", val[PIO_FLOW]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001087 printf("\n");
1088 }
1089 }
1090
Rob Landleya3e4f382006-04-29 16:06:31 +00001091 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001092 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001093 printf("Commands/features:\n\tEnabled\tSupported:\n");
1094 jj = val[CMDS_SUPP_0];
1095 kk = val[CMDS_EN_0];
Rob Landleya3e4f382006-04-29 16:06:31 +00001096 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +00001097 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001098 if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0'))
Glenn L McGrath07085852003-10-09 07:28:22 +00001099 {
1100 if_else_printf((kk & 0x8000),"\t *","\t");
Eric Andersen3443bd72003-07-22 07:30:36 +00001101 printf("\t%s\n",cmd_feat_str[ii]);
1102 }
1103 jj <<=1; kk<<=1;
Rob Landleya3e4f382006-04-29 16:06:31 +00001104 if (ii%16 == 15)
Glenn L McGrath07085852003-10-09 07:28:22 +00001105 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001106 jj = val[CMDS_SUPP_0+1+(ii/16)];
1107 kk = val[CMDS_EN_0+1+(ii/16)];
1108 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001109 if (ii == 31)
Glenn L McGrath07085852003-10-09 07:28:22 +00001110 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001111 if ((val[CMDS_SUPP_2] & VALID) != VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001112 ii +=16;
Eric Andersen3443bd72003-07-22 07:30:36 +00001113 }
1114 }
1115 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001116 if_printf(((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP),
1117 "\tRemovable Media Status Notification feature set supported\n");
1118
1119
Eric Andersen3443bd72003-07-22 07:30:36 +00001120 /* security */
Rob Landleya3e4f382006-04-29 16:06:31 +00001121 if ((eqpt != CDROM) && (like_std > 3) &&
Glenn L McGrath07085852003-10-09 07:28:22 +00001122 (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME]))
1123 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001124 printf("Security: \n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001125 if_printf((val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)),
1126 "\tMaster password revision code = %u\n",val[PSWD_CODE]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001127 jj = val[SECU_STATUS];
Rob Landleya3e4f382006-04-29 16:06:31 +00001128 if (jj)
Glenn L McGrath07085852003-10-09 07:28:22 +00001129 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001130 for (ii = 0; ii < NUM_SECU_STR; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +00001131 {
1132 if_else_printf((!(jj & 0x0001)),"\tnot\t%s\n", "\t\t%s\n", secu_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001133 jj >>=1;
1134 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001135 if (val[SECU_STATUS] & SECU_ENABLED)
Glenn L McGrath07085852003-10-09 07:28:22 +00001136 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001137 printf("\tSecurity level ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001138 if_else_printf((val[SECU_STATUS] & SECU_LEVEL),"maximum\n","high\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001139 }
1140 }
1141 jj = val[ERASE_TIME] & ERASE_BITS;
1142 kk = val[ENH_ERASE_TIME] & ERASE_BITS;
Rob Landleya3e4f382006-04-29 16:06:31 +00001143 if (jj || kk)
Glenn L McGrath07085852003-10-09 07:28:22 +00001144 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001145 printf("\t");
Glenn L McGrath07085852003-10-09 07:28:22 +00001146 if_printf(jj,"%umin for SECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1);
1147 if_printf(kk,"%umin for ENHANCED SECURITY ERASE UNIT.", kk==ERASE_BITS ? 508 : kk<<1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001148 printf("\n");
1149 }
1150 }
1151
1152 /* reset result */
Rob Landleya3e4f382006-04-29 16:06:31 +00001153 if ((val[HWRST_RSLT] & VALID) == VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001154 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001155 printf("HW reset results:\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001156 if_else_printf((val[HWRST_RSLT] & CBLID),"\tCBLID- above Vih\n","\tCBLID- below Vih\n");
1157
Rob Landleya3e4f382006-04-29 16:06:31 +00001158 if (val[HWRST_RSLT] & RST0)
Glenn L McGrath07085852003-10-09 07:28:22 +00001159 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001160 printf("\tDevice num = 0");
1161 jj = val[HWRST_RSLT];
Glenn L McGrath07085852003-10-09 07:28:22 +00001162 }
1163 else
1164 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001165 printf("\tDevice num = 1");
1166 jj = val[HWRST_RSLT] >> 8;
1167 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001168
Rob Landleya3e4f382006-04-29 16:06:31 +00001169 if ((jj & DEV_DET) == JUMPER_VAL)
Eric Andersen3443bd72003-07-22 07:30:36 +00001170 printf(" determined by the jumper");
Rob Landleya3e4f382006-04-29 16:06:31 +00001171 else if ((jj & DEV_DET) == CSEL_VAL)
Eric Andersen3443bd72003-07-22 07:30:36 +00001172 printf(" determined by CSEL");
1173 printf("\n");
1174 }
1175
1176 /* more stuff from std 5 */
Rob Landleya3e4f382006-04-29 16:06:31 +00001177 if ((like_std > 4) && (eqpt != CDROM))
Glenn L McGrath07085852003-10-09 07:28:22 +00001178 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001179 if (val[CFA_PWR_MODE] & VALID_W160)
Glenn L McGrath07085852003-10-09 07:28:22 +00001180 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001181 printf("CFA power mode 1:\n\t");
Glenn L McGrath07085852003-10-09 07:28:22 +00001182 if_else_printf((val[CFA_PWR_MODE] & PWR_MODE_OFF),"disabled","enabled");
1183
1184 if_printf((val[CFA_PWR_MODE] & PWR_MODE_REQ)," and required by some commands");
Eric Andersen3443bd72003-07-22 07:30:36 +00001185 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001186
1187 if_printf((val[CFA_PWR_MODE] & MAX_AMPS),"\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS);
Eric Andersen3443bd72003-07-22 07:30:36 +00001188 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001189 if ((val[INTEGRITY] & SIG) == SIG_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001190 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001191 printf("Checksum: ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001192 if_printf(chksum,"in");
Eric Andersen3443bd72003-07-22 07:30:36 +00001193 printf("correct\n");
1194 }
1195 }
1196
1197 exit(0);
1198}
1199#endif
1200
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001201static int verbose, get_identity, get_geom, noisy = 1, quiet;
Rob Landley6389ff12006-05-01 19:28:53 +00001202static int flagcount, do_flush;
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001203static int do_ctimings, do_timings;
Eric Andersen3443bd72003-07-22 07:30:36 +00001204
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001205static unsigned long set_readahead, get_readahead, Xreadahead;
1206static unsigned long set_readonly, get_readonly, readonly;
1207static unsigned long set_unmask, get_unmask, unmask;
1208static unsigned long set_mult, get_mult, mult;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001209#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001210static unsigned long set_dma, get_dma, dma;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001211#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001212static unsigned long set_dma_q, get_dma_q, dma_q;
1213static unsigned long set_nowerr, get_nowerr, nowerr;
1214static unsigned long set_keep, get_keep, keep;
1215static unsigned long set_io32bit, get_io32bit, io32bit;
1216static unsigned long set_piomode, noisy_piomode;
1217static int piomode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001218#ifdef HDIO_DRIVE_CMD
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001219static unsigned long set_dkeep, get_dkeep, dkeep;
1220static unsigned long set_standby, get_standby, standby_requested;
1221static unsigned long set_xfermode, get_xfermode;
1222static int xfermode_requested;
1223static unsigned long set_lookahead, get_lookahead, lookahead;
1224static unsigned long set_prefetch, get_prefetch, prefetch;
1225static unsigned long set_defects, get_defects, defects;
1226static unsigned long set_wcache, get_wcache, wcache;
1227static unsigned long set_doorlock, get_doorlock, doorlock;
1228static unsigned long set_seagate, get_seagate;
1229static unsigned long set_standbynow, get_standbynow;
1230static unsigned long set_sleepnow, get_sleepnow;
1231static unsigned long get_powermode;
1232static unsigned long set_apmmode, get_apmmode, apmmode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001233#endif
1234#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001235static int get_IDentity;
Eric Andersen3443bd72003-07-22 07:30:36 +00001236#endif
1237#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001238static int unregister_hwif;
1239static int hwif;
Eric Andersen3443bd72003-07-22 07:30:36 +00001240#endif
1241#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001242static int scan_hwif;
1243static int hwif_data;
1244static int hwif_ctrl;
1245static int hwif_irq;
Eric Andersen3443bd72003-07-22 07:30:36 +00001246#endif
1247#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001248static int set_busstate, get_busstate, busstate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001249#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001250static int reread_partn;
Eric Andersen3443bd72003-07-22 07:30:36 +00001251
1252#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001253static int perform_reset;
Eric Andersen3443bd72003-07-22 07:30:36 +00001254#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
1255#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001256static int perform_tristate, tristate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001257#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
1258
1259// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then
1260// then the HDIO_GET_IDENTITY only returned 142 bytes.
1261// Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes,
1262// and HDIO_GET_IDENTITY returns 512 bytes. But the latest
1263// 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY
1264// (which they should, but they should just return -EINVAL).
1265//
1266// So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes.
1267// On a really old system, it will not, and we will be confused.
1268// Too bad, really.
1269
1270#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001271static const char * const cfg_str[] =
Eric Andersen3443bd72003-07-22 07:30:36 +00001272{ "", " HardSect", " SoftSect", " NotMFM",
1273 " HdSw>15uSec", " SpinMotCtl", " Fixed", " Removeable",
1274 " DTR<=5Mbs", " DTR>5Mbs", " DTR>10Mbs", " RotSpdTol>.5%",
1275 " dStbOff", " TrkOff", " FmtGapReq", " nonMagnetic"
1276};
1277
Rob Landleya3e4f382006-04-29 16:06:31 +00001278static const char * const BuffType[] = {"unknown", "1Sect", "DualPort", "DualPortCache"};
Eric Andersen3443bd72003-07-22 07:30:36 +00001279
Rob Landleya3e4f382006-04-29 16:06:31 +00001280static void dump_identity(const struct hd_driveid *id)
Eric Andersen3443bd72003-07-22 07:30:36 +00001281{
1282 int i;
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001283 char pmodes[64], dmodes[128], umodes[128];
Eric Andersen3443bd72003-07-22 07:30:36 +00001284 const unsigned short int *id_regs= (const void*) id;
1285 unsigned long capacity;
1286
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001287 pmodes[0] = dmodes[0] = umodes[0] = '\0';
1288
Glenn L McGrath07085852003-10-09 07:28:22 +00001289 printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={",
1290 id->model, id->fw_rev, id->serial_no);
1291 for (i=0; i<=15; i++)
1292 if_printf((id->config & (1<<i)),"%s", cfg_str[i]);
1293
1294 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n",
1295 id->cyls, id->heads, id->sectors, id->track_bytes,
1296 id->sector_bytes, id->ecc_bytes);
1297
1298 if (id->buf_type > 3)
1299 printf("%s%u", " BuffType=", id->buf_type);
1300 else
1301 printf("%s%s", " BuffType=", BuffType[id->buf_type]);
1302
Eric Andersen3443bd72003-07-22 07:30:36 +00001303 printf(", BuffSize=%ukB, MaxMultSect=%u", id->buf_size/2, id->max_multsect);
Glenn L McGrath07085852003-10-09 07:28:22 +00001304 if (id->max_multsect)
1305 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001306 printf(", MultSect=");
1307 if (!(id->multsect_valid&1))
1308 printf("?%u?", id->multsect);
1309 else if (id->multsect)
1310 printf("%u", id->multsect);
1311 else
1312 printf("off");
1313 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001314 printf("\n");
1315 if (id->tPIO <= 5)
1316 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001317 strcat(pmodes, "pio0 ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001318 if_strcat((id->tPIO >= 1), pmodes, "pio1 ");
1319 if_strcat((id->tPIO >= 2), pmodes, "pio2 ");
1320
Eric Andersen3443bd72003-07-22 07:30:36 +00001321 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001322 if_printf((!(id->field_valid&1))," (maybe):");
Eric Andersen3443bd72003-07-22 07:30:36 +00001323#if __BYTE_ORDER == __BIG_ENDIAN
1324 capacity = (id->cur_capacity0 << 16) | id->cur_capacity1;
1325#else
1326 capacity = (id->cur_capacity1 << 16) | id->cur_capacity0;
1327#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001328 printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001329 id->cur_sectors, capacity ,
1330 ((id->capability&2)==0)?"no":"yes");
Eric Andersen3443bd72003-07-22 07:30:36 +00001331
Glenn L McGrath07085852003-10-09 07:28:22 +00001332 if_printf((id->capability&2),", LBAsects=%u", id->lba_capacity);
1333
1334 if (id->capability&1)
1335 {
1336 if (id->dma_1word | id->dma_mword)
1337 {
1338 if_strcat((id->dma_1word & 0x100), dmodes, "*");
1339 if_strcat((id->dma_1word & 1), dmodes, "sdma0 ");
1340 if_strcat((id->dma_1word & 0x200), dmodes, "*");
1341 if_strcat((id->dma_1word & 2), dmodes, "sdma1 ");
1342 if_strcat((id->dma_1word & 0x400), dmodes, "*");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001343 if_strcat((id->dma_1word & 4), dmodes, "sdma2 ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001344 if_strcat((id->dma_1word & 0xf800), dmodes, "*");
1345 if_strcat((id->dma_1word & 0xf8), dmodes, "sdma? ");
1346 if_strcat((id->dma_mword & 0x100), dmodes, "*");
1347 if_strcat((id->dma_mword & 1), dmodes, "mdma0 ");
1348 if_strcat((id->dma_mword & 0x200), dmodes, "*");
1349 if_strcat((id->dma_mword & 2), dmodes, "mdma1 ");
1350 if_strcat((id->dma_mword & 0x400), dmodes, "*");
1351 if_strcat((id->dma_mword & 4), dmodes, "mdma2 ");
1352 if_strcat((id->dma_mword & 0xf800), dmodes, "*");
1353 if_strcat((id->dma_mword & 0xf8), dmodes, "mdma? ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001354 }
1355 }
1356 printf("\n IORDY=");
1357 if (id->capability&8)
1358 printf((id->capability&4) ? "on/off" : "yes");
1359 else
1360 printf("no");
Eric Andersen3443bd72003-07-22 07:30:36 +00001361
Glenn L McGrath07085852003-10-09 07:28:22 +00001362 if ((id->capability&8) || (id->field_valid&2))
1363 {
1364 if (id->field_valid&2)
1365 {
1366 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
1367 if_strcat((id->eide_pio_modes & 1), pmodes, "pio3 ");
1368 if_strcat((id->eide_pio_modes & 2), pmodes, "pio4 ");
1369 if_strcat((id->eide_pio_modes &~3), pmodes, "pio? ");
1370 }
1371 if (id->field_valid&4)
1372 {
1373 if_strcat((id->dma_ultra & 0x100),umodes,"*");
1374 if_strcat((id->dma_ultra & 0x001),umodes,"udma0 ");
1375 if_strcat((id->dma_ultra & 0x200),umodes,"*");
1376 if_strcat((id->dma_ultra & 0x002),umodes,"udma1 ");
1377 if_strcat((id->dma_ultra & 0x400),umodes,"*");
1378 if_strcat((id->dma_ultra & 0x004),umodes,"udma2 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001379#ifdef __NEW_HD_DRIVE_ID
Glenn L McGrath07085852003-10-09 07:28:22 +00001380 if (id->hw_config & 0x2000)
1381 {
1382#else /* !__NEW_HD_DRIVE_ID */
1383 if (id->word93 & 0x2000)
1384 {
1385#endif /* __NEW_HD_DRIVE_ID */
1386 if_strcat((id->dma_ultra & 0x0800),umodes,"*");
1387 if_strcat((id->dma_ultra & 0x0008),umodes,"udma3 ");
1388 if_strcat((id->dma_ultra & 0x1000),umodes,"*");
1389 if_strcat((id->dma_ultra & 0x0010),umodes,"udma4 ");
1390 if_strcat((id->dma_ultra & 0x2000),umodes,"*");
1391 if_strcat((id->dma_ultra & 0x0020),umodes,"udma5 ");
1392 if_strcat((id->dma_ultra & 0x4000),umodes,"*");
1393 if_strcat((id->dma_ultra & 0x0040),umodes,"udma6 ");
1394 if_strcat((id->dma_ultra & 0x8000),umodes,"*");
1395 if_strcat((id->dma_ultra & 0x0080),umodes,"udma7 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001396 }
1397 }
1398 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001399 if_printf(((id->capability&1) && (id->field_valid&2)),
1400 ", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time);
1401 printf("\n PIO modes: %s", pmodes);
1402 if_printf((*dmodes),"\n DMA modes: %s", dmodes);
1403 if_printf((*umodes),"\n UDMA modes: %s", umodes);
1404
1405 printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes");
1406 if (id_regs[83] & 8)
1407 {
1408 if (!(id_regs[86]&8))
1409 printf(": disabled (255)");
1410 else if ((id_regs[91]&0xFF00)!=0x4000)
1411 printf(": unknown setting");
1412 else
1413 printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF);
1414 }
1415 if_printf( (id_regs[82]&0x20)," WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled");
1416#ifdef __NEW_HD_DRIVE_ID
1417 if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31))
1418 {
1419 printf("\n Drive conforms to: ");
1420 if_else_printf((id->minor_rev_num <= 31),"%s: ","unknown: ", minor_str[id->minor_rev_num]);
Rob Landley026147a2006-04-17 22:29:13 +00001421 if (id->major_rev_num != 0x0000 && /* NOVAL_0 */
1422 id->major_rev_num != 0xFFFF) { /* NOVAL_1 */
Glenn L McGrath07085852003-10-09 07:28:22 +00001423 for (i=0; i <= 15; i++)
Rob Landley026147a2006-04-17 22:29:13 +00001424 if_printf((id->major_rev_num & (1<<i))," ATA/ATAPI-%u", i);
Glenn L McGrath07085852003-10-09 07:28:22 +00001425 }
1426 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001427#endif /* __NEW_HD_DRIVE_ID */
Glenn L McGrath07085852003-10-09 07:28:22 +00001428 printf("\n\n * signifies the current active mode\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001429}
1430#endif
1431
Rob Landleya3e4f382006-04-29 16:06:31 +00001432static void flush_buffer_cache(int fd)
Eric Andersen3443bd72003-07-22 07:30:36 +00001433{
Rob Landleya3e4f382006-04-29 16:06:31 +00001434 fsync(fd); /* flush buffers */
Glenn L McGrath07085852003-10-09 07:28:22 +00001435 bb_ioctl(fd, BLKFLSBUF, NULL,"BLKFLSBUF" ) ;/* do it again, big time */
Eric Andersen3443bd72003-07-22 07:30:36 +00001436#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001437 sleep(1);
1438 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001439 bb_perror_msg("HDIO_DRIVE_CMD");
Eric Andersen3443bd72003-07-22 07:30:36 +00001440#endif
1441}
1442
Rob Landleya3e4f382006-04-29 16:06:31 +00001443static int seek_to_zero(int fd)
Eric Andersen3443bd72003-07-22 07:30:36 +00001444{
Glenn L McGrath07085852003-10-09 07:28:22 +00001445 if (lseek(fd, (off_t) 0, SEEK_SET))
Eric Andersen3443bd72003-07-22 07:30:36 +00001446 return 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001447 return 0;
1448}
1449
Rob Landleya3e4f382006-04-29 16:06:31 +00001450static int read_big_block(int fd, char *buf)
Eric Andersen3443bd72003-07-22 07:30:36 +00001451{
Glenn L McGrath07085852003-10-09 07:28:22 +00001452 const char *string;
Eric Andersen3443bd72003-07-22 07:30:36 +00001453 int i, rc;
Glenn L McGrath07085852003-10-09 07:28:22 +00001454 if ((rc = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES)
1455 {
1456 switch(rc)
1457 {
1458 case -1:
1459 string = "read()";
1460 break;
1461 case 0:
1462 string = "read() hit EOF - device too small";
1463 break;
1464 default:
1465 string = "read(%u) returned %u bytes";
Eric Andersen3443bd72003-07-22 07:30:36 +00001466 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001467 bb_error_msg(string, TIMING_BUF_BYTES, rc);
Eric Andersen3443bd72003-07-22 07:30:36 +00001468 return 1;
1469 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001470
Eric Andersen3443bd72003-07-22 07:30:36 +00001471 /* access all sectors of buf to ensure the read fully completed */
1472 for (i = 0; i < TIMING_BUF_BYTES; i += 512)
1473 buf[i] &= 1;
1474 return 0;
1475}
1476
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001477static double correction;
Eric Andersen50af12d2003-08-06 08:47:59 +00001478
Rob Landleya3e4f382006-04-29 16:06:31 +00001479static void do_time(int flag, int fd)
Glenn L McGrath07085852003-10-09 07:28:22 +00001480/*
1481 flag = 0 time_cache
1482 flag = 1 time_device
1483*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001484{
Eric Andersen50af12d2003-08-06 08:47:59 +00001485 int i;
Eric Andersen3443bd72003-07-22 07:30:36 +00001486 char *buf;
1487 double elapsed;
1488 struct itimerval e1, e2;
1489 int shmid;
Eric Andersen50af12d2003-08-06 08:47:59 +00001490 int timing_MB = TIMING_MB;
Eric Andersen3443bd72003-07-22 07:30:36 +00001491
Glenn L McGrath07085852003-10-09 07:28:22 +00001492 if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1)
1493 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001494 bb_error_msg(bb_msg_shared_mem,"allocate"); /*"could not allocate sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001495 return;
1496 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001497 if (shmctl(shmid, SHM_LOCK, NULL) == -1)
1498 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001499 bb_error_msg(bb_msg_shared_mem,"lock"); /*"could not lock sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001500 (void) shmctl(shmid, IPC_RMID, NULL);
1501 return;
1502 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001503 if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1)
1504 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001505 bb_error_msg(bb_msg_shared_mem,"attach"); /*"could not attach sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001506 (void) shmctl(shmid, IPC_RMID, NULL);
1507 return;
1508 }
1509 if (shmctl(shmid, IPC_RMID, NULL) == -1)
Rob Landleya3e4f382006-04-29 16:06:31 +00001510 bb_error_msg("shmctl(,IPC_RMID,)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001511
1512 /* Clear out the device request queues & give them time to complete */
Glenn L McGrath07085852003-10-09 07:28:22 +00001513 sync_and_sleep(3);
Eric Andersen3443bd72003-07-22 07:30:36 +00001514
Rob Landleya3e4f382006-04-29 16:06:31 +00001515 if (flag == 0) /* Time cache */
Glenn L McGrath07085852003-10-09 07:28:22 +00001516 {
1517 /* Calculate a correction factor for the basic
1518 * overhead of doing a read() from the buffer cache.
1519 * To do this, we read the data once to "cache it" and
1520 * to force full preallocation of our timing buffer,
1521 * and then we re-read it 10 times while timing it.
1522 *
1523 * getitimer() is used rather than gettimeofday() because
1524 * it is much more consistent (on my machine, at least).
1525 */
1526 setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
Rob Landleya3e4f382006-04-29 16:06:31 +00001527 if (seek_to_zero(fd))
Glenn L McGrath07085852003-10-09 07:28:22 +00001528 return;
Rob Landleya3e4f382006-04-29 16:06:31 +00001529 if (read_big_block(fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001530 return;
1531 printf(" Timing buffer-cache reads: ");
1532 fflush(stdout);
Eric Andersen3443bd72003-07-22 07:30:36 +00001533
Glenn L McGrath07085852003-10-09 07:28:22 +00001534 /* Clear out the device request queues & give them time to complete */
1535 sync_and_sleep(1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001536
Glenn L McGrath07085852003-10-09 07:28:22 +00001537 /* Time re-reading from the buffer-cache */
1538 getitimer(ITIMER_REAL, &e1);
1539 for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i)
1540 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001541 if (seek_to_zero(fd))
Glenn L McGrath07085852003-10-09 07:28:22 +00001542 goto quit;
Rob Landleya3e4f382006-04-29 16:06:31 +00001543 if (read_big_block(fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001544 goto quit;
1545 }
1546 getitimer(ITIMER_REAL, &e2);
1547 correction = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
Eric Andersen3443bd72003-07-22 07:30:36 +00001548
Glenn L McGrath07085852003-10-09 07:28:22 +00001549 /* Now remove the lseek() from the correction factor */
1550 getitimer(ITIMER_REAL, &e1);
1551 for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i)
1552 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001553 if (seek_to_zero(fd))
Glenn L McGrath07085852003-10-09 07:28:22 +00001554 goto quit;
1555 }
1556 getitimer(ITIMER_REAL, &e2);
1557 correction -= (e1.it_value.tv_sec - e2.it_value.tv_sec)
1558 + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
Eric Andersen50af12d2003-08-06 08:47:59 +00001559
Glenn L McGrath07085852003-10-09 07:28:22 +00001560 if ((BUFCACHE_FACTOR * timing_MB) >= correction) /* more than 1MB/s */
Eric Andersen50af12d2003-08-06 08:47:59 +00001561 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",
Glenn L McGrath07085852003-10-09 07:28:22 +00001562 (BUFCACHE_FACTOR * timing_MB), correction,
1563 (BUFCACHE_FACTOR * timing_MB) / correction);
Eric Andersen50af12d2003-08-06 08:47:59 +00001564 else
1565 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",
Glenn L McGrath07085852003-10-09 07:28:22 +00001566 (BUFCACHE_FACTOR * timing_MB), correction,
1567 (BUFCACHE_FACTOR * timing_MB) / correction * 1024);
1568 correction /= BUFCACHE_FACTOR;
1569
1570 flush_buffer_cache(fd);
1571 sleep(1);
Eric Andersen50af12d2003-08-06 08:47:59 +00001572 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001573 else /* Time device */
1574 {
1575 printf(" Timing buffered disk reads: ");
1576 fflush(stdout);
1577
1578 /*
1579 * getitimer() is used rather than gettimeofday() because
1580 * it is much more consistent (on my machine, at least).
1581 */
1582 setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
1583
1584 /* Now do the timings for real */
1585 getitimer(ITIMER_REAL, &e1);
1586 for (i = TIMING_BUF_COUNT; i > 0; --i)
1587 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001588 if (read_big_block(fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001589 goto quit;
1590 }
1591 getitimer(ITIMER_REAL, &e2);
1592
1593 elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
1594
1595 if (timing_MB >= elapsed) /* more than 1MB/s */
1596 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",timing_MB, elapsed, timing_MB / elapsed);
1597 else
1598 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",timing_MB, elapsed, timing_MB / elapsed * 1024);
1599
1600 /*"Hmm.. suspicious results: probably not enough free memory for a proper test.");*/
1601 if (elapsed <= (correction * 2))
1602 bb_error_msg(bb_msg_memory_exhausted);
1603
1604#if 0 /* the "estimate" is just plain wrong for many systems.. */
1605 else if (correction != 0.0) {
1606 printf(" Estimating raw driver speed: ");
1607 elapsed -= correction;
1608 if (timing_MB >= elapsed) /* more than 1MB/s */
1609 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",
1610 timing_MB, elapsed, timing_MB / elapsed);
1611 else
1612 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",
1613 timing_MB, elapsed, timing_MB / elapsed * 1024);
1614 }
Eric Andersen50af12d2003-08-06 08:47:59 +00001615#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001616 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001617quit:
1618 if (-1 == shmdt(buf))
Rob Landleya3e4f382006-04-29 16:06:31 +00001619 bb_error_msg(bb_msg_shared_mem,"detach"); /*"could not detach sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001620}
1621
Eric Andersen3443bd72003-07-22 07:30:36 +00001622static void on_off (unsigned int value)
1623{
1624 printf(value ? " (on)\n" : " (off)\n");
1625}
1626
1627#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Rob Landleya3e4f382006-04-29 16:06:31 +00001628static void bus_state_value(unsigned int value)
Eric Andersen3443bd72003-07-22 07:30:36 +00001629{
1630 const char *string;
1631
Glenn L McGrath07085852003-10-09 07:28:22 +00001632 switch (value)
1633 {
1634 case BUSSTATE_ON:
1635 string = " (on)\n";
1636 break;
1637 case BUSSTATE_OFF:
1638 string = " (off)\n";
1639 break;
1640 case BUSSTATE_TRISTATE:
1641 string = " (tristate)\n";
1642 break;
1643 default:
1644 string = " (unknown: %d)\n";
1645 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001646 }
1647 printf(string, value);
1648}
1649#endif
1650
1651#ifdef HDIO_DRIVE_CMD
Rob Landleya3e4f382006-04-29 16:06:31 +00001652static void interpret_standby(unsigned int standby)
Eric Andersen3443bd72003-07-22 07:30:36 +00001653{
1654 printf(" (");
Glenn L McGrath07085852003-10-09 07:28:22 +00001655 switch(standby)
1656 {
1657 case 0:
1658 printf("off");
1659 break;
1660 case 252:
1661 printf("21 minutes");
1662 break;
1663 case 253:
1664 printf("vendor-specific");
1665 break;
1666 case 254:
1667 printf("?reserved");
1668 break;
1669 case 255:
1670 printf("21 minutes + 15 seconds");
1671 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001672 default:
Glenn L McGrath07085852003-10-09 07:28:22 +00001673 if (standby <= 240)
1674 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001675 unsigned int secs = standby * 5;
1676 unsigned int mins = secs / 60;
1677 secs %= 60;
Glenn L McGrath07085852003-10-09 07:28:22 +00001678 if_printf(mins,"%u minutes", mins);
1679 if_printf((mins && secs)," + ");
1680 if_printf(secs,"%u seconds", secs);
1681 }
1682 else if (standby <= 251)
1683 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001684 unsigned int mins = (standby - 240) * 30;
1685 unsigned int hrs = mins / 60;
1686 mins %= 60;
Glenn L McGrath07085852003-10-09 07:28:22 +00001687 if_printf(hrs,"%u hours", hrs);
1688 if_printf((hrs && mins)," + ");
1689 if_printf(mins,"%u minutes", mins);
1690 }
1691 else
Eric Andersen3443bd72003-07-22 07:30:36 +00001692 printf("illegal value");
1693 break;
1694 }
1695 printf(")\n");
1696}
1697
1698struct xfermode_entry {
1699 int val;
1700 const char *name;
1701};
1702
1703static const struct xfermode_entry xfermode_table[] = {
1704 { 8, "pio0" },
1705 { 9, "pio1" },
1706 { 10, "pio2" },
1707 { 11, "pio3" },
1708 { 12, "pio4" },
1709 { 13, "pio5" },
1710 { 14, "pio6" },
1711 { 15, "pio7" },
1712 { 16, "sdma0" },
1713 { 17, "sdma1" },
1714 { 18, "sdma2" },
1715 { 19, "sdma3" },
1716 { 20, "sdma4" },
1717 { 21, "sdma5" },
1718 { 22, "sdma6" },
1719 { 23, "sdma7" },
1720 { 32, "mdma0" },
1721 { 33, "mdma1" },
1722 { 34, "mdma2" },
1723 { 35, "mdma3" },
1724 { 36, "mdma4" },
1725 { 37, "mdma5" },
1726 { 38, "mdma6" },
1727 { 39, "mdma7" },
1728 { 64, "udma0" },
1729 { 65, "udma1" },
1730 { 66, "udma2" },
1731 { 67, "udma3" },
1732 { 68, "udma4" },
1733 { 69, "udma5" },
1734 { 70, "udma6" },
1735 { 71, "udma7" },
1736 { 0, NULL }
1737};
1738
1739static int translate_xfermode(char * name)
1740{
Glenn L McGrath07085852003-10-09 07:28:22 +00001741 const struct xfermode_entry *tmp;
1742 char *endptr;
1743 int val = -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001744
1745
Glenn L McGrath07085852003-10-09 07:28:22 +00001746 for (tmp = xfermode_table; tmp->name != NULL; ++tmp)
1747 {
1748 if (!strcmp(name, tmp->name))
1749 return tmp->val;
Eric Andersen3443bd72003-07-22 07:30:36 +00001750
Glenn L McGrath07085852003-10-09 07:28:22 +00001751 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001752
Glenn L McGrath07085852003-10-09 07:28:22 +00001753 val = strtol(name, &endptr, 10);
1754 if (*endptr == '\0')
1755 return val;
1756
1757 return -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001758}
1759
Rob Landleya3e4f382006-04-29 16:06:31 +00001760static void interpret_xfermode(unsigned int xfermode)
Eric Andersen3443bd72003-07-22 07:30:36 +00001761{
1762 printf(" (");
1763 switch(xfermode) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001764 case 0:
1765 printf("default PIO mode");
1766 break;
1767 case 1:
1768 printf("default PIO mode, disable IORDY");
1769 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001770 case 8:
1771 case 9:
1772 case 10:
1773 case 11:
1774 case 12:
1775 case 13:
1776 case 14:
Glenn L McGrath07085852003-10-09 07:28:22 +00001777 case 15:
1778 printf("PIO flow control mode%u", xfermode-8);
1779 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001780 case 16:
1781 case 17:
1782 case 18:
1783 case 19:
1784 case 20:
1785 case 21:
1786 case 22:
Glenn L McGrath07085852003-10-09 07:28:22 +00001787 case 23:
1788 printf("singleword DMA mode%u", xfermode-16);
1789 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001790 case 32:
1791 case 33:
1792 case 34:
1793 case 35:
1794 case 36:
1795 case 37:
1796 case 38:
Glenn L McGrath07085852003-10-09 07:28:22 +00001797 case 39:
1798 printf("multiword DMA mode%u", xfermode-32);
1799 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001800 case 64:
1801 case 65:
1802 case 66:
1803 case 67:
1804 case 68:
1805 case 69:
1806 case 70:
Glenn L McGrath07085852003-10-09 07:28:22 +00001807 case 71:
1808 printf("UltraDMA mode%u", xfermode-64);
1809 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001810 default:
Glenn L McGrath07085852003-10-09 07:28:22 +00001811 printf("unknown, probably not valid");
1812 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001813 }
1814 printf(")\n");
1815}
1816#endif /* HDIO_DRIVE_CMD */
1817
Rob Landleya3e4f382006-04-29 16:06:31 +00001818static void process_dev(char *devname)
Eric Andersen3443bd72003-07-22 07:30:36 +00001819{
1820 int fd;
1821 static long parm, multcount;
Eric Andersen3443bd72003-07-22 07:30:36 +00001822#ifndef HDIO_DRIVE_CMD
1823 int force_operation = 0;
1824#endif
Rob Landleye5b281f2006-04-29 15:49:18 +00001825 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
1826
Rob Landleya3e4f382006-04-29 16:06:31 +00001827 fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK);
1828 if_printf(!quiet, "\n%s:\n", devname);
Eric Andersen3443bd72003-07-22 07:30:36 +00001829
Glenn L McGrath07085852003-10-09 07:28:22 +00001830 if (set_readahead)
1831 {
Eric Andersenf828da02004-07-20 22:53:59 +00001832 if_printf(get_readahead," setting fs readahead to %ld\n", Xreadahead);
1833 bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001834 }
1835#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001836 if (unregister_hwif)
1837 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001838 printf(" attempting to unregister hwif#%u\n", hwif);
Eric Andersena68ea1c2006-01-30 22:48:39 +00001839 bb_ioctl(fd, HDIO_UNREGISTER_HWIF,(int *)(unsigned long)hwif,"HDIO_UNREGISTER_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001840 }
1841#endif
1842#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001843 if (scan_hwif)
1844 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001845 printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq);
1846 args[0] = hwif_data;
1847 args[1] = hwif_ctrl;
1848 args[2] = hwif_irq;
Glenn L McGrath07085852003-10-09 07:28:22 +00001849 bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001850 }
1851#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001852 if (set_piomode)
1853 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001854 if (noisy_piomode)
1855 {
1856 printf(" attempting to ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001857 if (piomode == 255)
Glenn L McGrath07085852003-10-09 07:28:22 +00001858 printf("auto-tune PIO mode\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001859 else if (piomode < 100)
Glenn L McGrath07085852003-10-09 07:28:22 +00001860 printf("set PIO mode to %d\n", piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001861 else if (piomode < 200)
Glenn L McGrath07085852003-10-09 07:28:22 +00001862 printf("set MDMA mode to %d\n", (piomode-100));
Eric Andersen3443bd72003-07-22 07:30:36 +00001863 else
Glenn L McGrath07085852003-10-09 07:28:22 +00001864 printf("set UDMA mode to %d\n", (piomode-200));
Eric Andersen3443bd72003-07-22 07:30:36 +00001865 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00001866 bb_ioctl(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode, "HDIO_SET_PIO_MODE");
Eric Andersen3443bd72003-07-22 07:30:36 +00001867 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001868 if (set_io32bit)
1869 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001870 if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit);
1871 bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001872 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001873 if (set_mult)
1874 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001875 if_printf(get_mult, " setting multcount to %ld\n", mult);
Rob Landleya3e4f382006-04-29 16:06:31 +00001876 if (ioctl(fd, HDIO_SET_MULTCOUNT, mult))
Eric Andersen06d4ec22004-03-19 10:53:52 +00001877 bb_perror_msg("HDIO_SET_MULTCOUNT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001878#ifndef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001879 else
1880 force_operation = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001881#endif
1882 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001883 if (set_readonly)
1884 {
1885 if_printf_on_off(get_readonly," setting readonly to %ld", readonly);
1886 bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001887 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001888 if (set_unmask)
1889 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001890 if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask);
1891 bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR");
Eric Andersen3443bd72003-07-22 07:30:36 +00001892 }
Eric Andersen0a57a792003-08-06 08:57:35 +00001893#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Glenn L McGrath07085852003-10-09 07:28:22 +00001894 if (set_dma)
1895 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001896 if_printf_on_off(get_dma," setting using_dma to %ld", dma);
1897 bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00001898 }
Eric Andersen0a57a792003-08-06 08:57:35 +00001899#endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
Glenn L McGrath07085852003-10-09 07:28:22 +00001900 if (set_dma_q)
1901 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001902 if_printf_on_off(get_dma_q," setting DMA queue_depth to %ld", dma_q);
1903 bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00001904 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001905 if (set_nowerr)
1906 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001907 if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr);
1908 bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR");
Eric Andersen3443bd72003-07-22 07:30:36 +00001909 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001910 if (set_keep)
1911 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001912 if_printf_on_off(get_keep," setting keep_settings to %ld", keep);
1913 bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS");
Eric Andersen3443bd72003-07-22 07:30:36 +00001914 }
1915#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001916 if (set_doorlock)
1917 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001918 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
Glenn L McGrath07085852003-10-09 07:28:22 +00001919 if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock);
1920 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001921 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001922 if (set_dkeep)
1923 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001924 /* lock/unlock the drive's "feature" settings */
Glenn L McGrath07085852003-10-09 07:28:22 +00001925 if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep);
Eric Andersen3443bd72003-07-22 07:30:36 +00001926 args[2] = dkeep ? 0x66 : 0xcc;
Glenn L McGrath07085852003-10-09 07:28:22 +00001927 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001928 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001929 if (set_defects)
1930 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001931 args[2] = defects ? 0x04 : 0x84;
Glenn L McGrath07085852003-10-09 07:28:22 +00001932 if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects);
1933 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001934 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001935 if (set_prefetch)
1936 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001937 args[1] = prefetch;
Rob Landleye5b281f2006-04-29 15:49:18 +00001938 args[2] = 0xab;
Glenn L McGrath07085852003-10-09 07:28:22 +00001939 if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch);
1940 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001941 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001942 if (set_xfermode)
1943 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001944 args[1] = xfermode_requested;
Rob Landleye5b281f2006-04-29 15:49:18 +00001945 args[2] = 3;
Glenn L McGrath07085852003-10-09 07:28:22 +00001946 if (get_xfermode)
1947 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001948 printf(" setting xfermode to %d", xfermode_requested);
1949 interpret_xfermode(xfermode_requested);
1950 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001951 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001952 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001953 if (set_lookahead)
1954 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001955 args[2] = lookahead ? 0xaa : 0x55;
Glenn L McGrath07085852003-10-09 07:28:22 +00001956 if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead);
1957 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001958 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001959 if (set_apmmode)
1960 {
Eric Andersenb2aa7762004-04-05 13:08:08 +00001961 apmmode=check_if_min_and_set_val(apmmode,1);
1962 apmmode=check_if_maj_and_set_val(apmmode,255);
Glenn L McGrath07085852003-10-09 07:28:22 +00001963 if_printf(get_apmmode," setting APM level to");
1964 if (apmmode==255)
1965 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001966 /* disable Advanced Power Management */
Glenn L McGrath07085852003-10-09 07:28:22 +00001967 args[2] = 0x85; /* feature register */
1968 if_printf(get_apmmode," disabled\n");
1969 }
1970 else
1971 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001972 /* set Advanced Power Management mode */
Glenn L McGrath07085852003-10-09 07:28:22 +00001973 args[2] = 0x05; /* feature register */
Eric Andersen3443bd72003-07-22 07:30:36 +00001974 args[1] = apmmode; /* sector count register */
Glenn L McGrath07085852003-10-09 07:28:22 +00001975 if_printf(get_apmmode," 0x%02lX (%ld)\n",apmmode,apmmode);
1976 }
1977 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD");
Eric Andersen3443bd72003-07-22 07:30:36 +00001978 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001979 if (set_wcache)
1980 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001981#ifdef DO_FLUSHCACHE
1982#ifndef WIN_FLUSHCACHE
1983#define WIN_FLUSHCACHE 0xe7
1984#endif
Rob Landleye5b281f2006-04-29 15:49:18 +00001985 static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0};
Eric Andersen3443bd72003-07-22 07:30:36 +00001986#endif /* DO_FLUSHCACHE */
Eric Andersen3443bd72003-07-22 07:30:36 +00001987 args[2] = wcache ? 0x02 : 0x82;
Glenn L McGrath07085852003-10-09 07:28:22 +00001988 if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache);
Eric Andersen3443bd72003-07-22 07:30:36 +00001989#ifdef DO_FLUSHCACHE
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001990 if (!wcache)
1991 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001992#endif /* DO_FLUSHCACHE */
Glenn L McGrath07085852003-10-09 07:28:22 +00001993 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001994#ifdef DO_FLUSHCACHE
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001995 if (!wcache)
1996 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001997#endif /* DO_FLUSHCACHE */
1998 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001999 if (set_standbynow)
2000 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002001#ifndef WIN_STANDBYNOW1
2002#define WIN_STANDBYNOW1 0xE0
2003#endif
2004#ifndef WIN_STANDBYNOW2
2005#define WIN_STANDBYNOW2 0x94
2006#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002007 if_printf(get_standbynow," issuing standby command\n");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002008 args[0] = WIN_STANDBYNOW1;
2009 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002010 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002011 if (set_sleepnow)
2012 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002013#ifndef WIN_SLEEPNOW1
2014#define WIN_SLEEPNOW1 0xE6
2015#endif
2016#ifndef WIN_SLEEPNOW2
2017#define WIN_SLEEPNOW2 0x99
2018#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002019 if_printf(get_sleepnow," issuing sleep command\n");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002020 args[0] = WIN_SLEEPNOW1;
2021 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002022 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002023 if (set_seagate)
2024 {
Rob Landleye5b281f2006-04-29 15:49:18 +00002025 args[0] = 0xfb;
Glenn L McGrath07085852003-10-09 07:28:22 +00002026 if_printf(get_seagate," disabling Seagate auto powersaving mode\n");
2027 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002028 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002029 if (set_standby)
2030 {
Rob Landleye5b281f2006-04-29 15:49:18 +00002031 args[0] = WIN_SETIDLE1;
2032 args[1] = standby_requested;
Glenn L McGrath07085852003-10-09 07:28:22 +00002033 if (get_standby)
2034 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002035 printf(" setting standby to %lu", standby_requested);
2036 interpret_standby(standby_requested);
2037 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002038 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002039 }
2040#else /* HDIO_DRIVE_CMD */
Glenn L McGrath07085852003-10-09 07:28:22 +00002041 if (force_operation)
2042 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002043 char buf[512];
2044 flush_buffer_cache(fd);
2045 if (-1 == read(fd, buf, sizeof(buf)))
Glenn L McGrath07085852003-10-09 07:28:22 +00002046 bb_error_msg("access failed");
Eric Andersen3443bd72003-07-22 07:30:36 +00002047 }
2048#endif /* HDIO_DRIVE_CMD */
2049
2050 if (!flagcount)
2051 verbose = 1;
2052
Rob Landley6389ff12006-05-01 19:28:53 +00002053 if (verbose || get_mult || get_identity)
Glenn L McGrath07085852003-10-09 07:28:22 +00002054 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002055 multcount = -1;
Glenn L McGrath07085852003-10-09 07:28:22 +00002056 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount))
2057 {
Rob Landley6389ff12006-05-01 19:28:53 +00002058 if (verbose || get_mult)
Eric Andersen06d4ec22004-03-19 10:53:52 +00002059 bb_perror_msg("HDIO_GET_MULTCOUNT");
Glenn L McGrath07085852003-10-09 07:28:22 +00002060 }
2061 else if (verbose | get_mult)
2062 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002063 printf(" multcount = %2ld", multcount);
2064 on_off(multcount);
2065 }
2066 }
Rob Landley6389ff12006-05-01 19:28:53 +00002067 if (verbose || get_io32bit)
Glenn L McGrath07085852003-10-09 07:28:22 +00002068 {
Rob Landleya3e4f382006-04-29 16:06:31 +00002069 if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT"))
Glenn L McGrath07085852003-10-09 07:28:22 +00002070 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002071 printf(" IO_support =%3ld (", parm);
Glenn L McGrath07085852003-10-09 07:28:22 +00002072 switch (parm)
2073 {
2074 case 0:
2075 printf("default ");
2076 case 2:
2077 printf("16-bit)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002078 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002079 case 1:
2080 printf("32-bit)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002081 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002082 case 3:
2083 printf("32-bit w/sync)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002084 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002085 case 8:
2086 printf("Request-Queue-Bypass)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002087 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002088 default:
2089 printf("\?\?\?)\n");
2090 /*esac*/
Eric Andersen3443bd72003-07-22 07:30:36 +00002091 }
2092 }
2093 }
Rob Landley6389ff12006-05-01 19:28:53 +00002094 if (verbose || get_unmask)
Glenn L McGrath07085852003-10-09 07:28:22 +00002095 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002096 bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm,
2097 "HDIO_GET_UNMASKINTR"," unmaskirq = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002098 }
2099
Glenn L McGrath07085852003-10-09 07:28:22 +00002100
Eric Andersen0a57a792003-08-06 08:57:35 +00002101#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Rob Landley6389ff12006-05-01 19:28:53 +00002102 if (verbose || get_dma) {
Rob Landleya3e4f382006-04-29 16:06:31 +00002103 if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA"))
Glenn L McGrath07085852003-10-09 07:28:22 +00002104 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002105 printf(" using_dma = %2ld", parm);
2106 if (parm == 8)
2107 printf(" (DMA-Assisted-PIO)\n");
2108 else
2109 on_off(parm);
2110 }
2111 }
2112#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002113 if (get_dma_q)
2114 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002115 bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm,
2116 "HDIO_GET_QDMA"," queue_depth = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002117 }
Rob Landley6389ff12006-05-01 19:28:53 +00002118 if (verbose || get_keep)
Glenn L McGrath07085852003-10-09 07:28:22 +00002119 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002120 bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm,
2121 "HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002122 }
2123
Glenn L McGrath07085852003-10-09 07:28:22 +00002124 if (get_nowerr)
2125 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002126 bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm,
2127 " HDIO_GET_NOWERR"," nowerr = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002128 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002129 if (verbose || get_readonly)
2130 {
2131 bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm,
2132 " BLKROGET"," readonly = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002133 }
Rob Landley6389ff12006-05-01 19:28:53 +00002134 if (verbose || get_readahead)
Glenn L McGrath07085852003-10-09 07:28:22 +00002135 {
2136 bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm,
2137 " BLKRAGET"," readahead = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002138 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002139 if (verbose || get_geom)
2140 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002141 static const char msg[] = " geometry = %u/%u/%u, sectors = %ld, start = %ld\n";
2142 static struct hd_geometry g;
2143#ifdef HDIO_GETGEO_BIG
2144 static struct hd_big_geometry bg;
2145#endif
2146
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002147 if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE"))
2148 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002149#ifdef HDIO_GETGEO_BIG
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002150 if (!bb_ioctl(fd, HDIO_GETGEO_BIG, &bg, "HDIO_GETGEO_BIG"))
2151 printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start);
2152 else
Eric Andersen3443bd72003-07-22 07:30:36 +00002153#endif
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002154 if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO"))
2155 printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start);
2156 }
Eric Andersen3443bd72003-07-22 07:30:36 +00002157 }
2158#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00002159 if (get_powermode)
2160 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002161#ifndef WIN_CHECKPOWERMODE1
2162#define WIN_CHECKPOWERMODE1 0xE5
2163#endif
2164#ifndef WIN_CHECKPOWERMODE2
2165#define WIN_CHECKPOWERMODE2 0x98
2166#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00002167 const char *state;
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002168
Rob Landleye5b281f2006-04-29 15:49:18 +00002169 args[0] = WIN_CHECKPOWERMODE1;
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002170 if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0))
Glenn L McGrath07085852003-10-09 07:28:22 +00002171 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002172 if (errno != EIO || args[0] != 0 || args[1] != 0)
2173 state = "unknown";
2174 else
2175 state = "sleeping";
Eric Andersen3443bd72003-07-22 07:30:36 +00002176 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002177 else
2178 state = (args[2] == 255) ? "active/idle" : "standby";
2179
Eric Andersen3443bd72003-07-22 07:30:36 +00002180 printf(" drive state is: %s\n", state);
2181 }
2182#endif
2183#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
Glenn L McGrath07085852003-10-09 07:28:22 +00002184 if (perform_reset)
2185 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002186 bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET");
Eric Andersen3443bd72003-07-22 07:30:36 +00002187 }
2188#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
2189#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002190 if (perform_tristate)
2191 {
Rob Landleye5b281f2006-04-29 15:49:18 +00002192 args[0] = 0;
2193 args[1] = tristate;
Glenn L McGrath07085852003-10-09 07:28:22 +00002194 bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00002195 }
2196#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
2197#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +00002198 if (get_identity)
2199 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002200 static struct hd_driveid id;
2201
Glenn L McGrath07085852003-10-09 07:28:22 +00002202 if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
2203 {
2204 if (multcount != -1)
2205 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002206 id.multsect = multcount;
2207 id.multsect_valid |= 1;
Glenn L McGrath07085852003-10-09 07:28:22 +00002208 }
2209 else
Eric Andersen3443bd72003-07-22 07:30:36 +00002210 id.multsect_valid &= ~1;
2211 dump_identity(&id);
Glenn L McGrath07085852003-10-09 07:28:22 +00002212 }
2213 else if (errno == -ENOMSG)
Eric Andersen3443bd72003-07-22 07:30:36 +00002214 printf(" no identification info available\n");
2215 else
Eric Andersen06d4ec22004-03-19 10:53:52 +00002216 bb_perror_msg("HDIO_GET_IDENTITY");
Eric Andersen3443bd72003-07-22 07:30:36 +00002217 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002218
2219 if (get_IDentity)
2220 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002221 unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */
Eric Andersen3443bd72003-07-22 07:30:36 +00002222 unsigned i;
Glenn L McGrath07085852003-10-09 07:28:22 +00002223
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002224 memset(args1, 0, sizeof(args1));
2225 args1[0] = WIN_IDENTIFY;
2226 args1[3] = 1;
2227 if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)"))
2228 goto identify_abort;
2229
Rob Landleya3e4f382006-04-29 16:06:31 +00002230 for (i=0; i<(sizeof args1)/2; i+=2)
Rob Landleye5b281f2006-04-29 15:49:18 +00002231 __le16_to_cpus((uint16_t *)(&args1[i]));
Rob Landley6389ff12006-05-01 19:28:53 +00002232 identify((void *)&args1[4]);
Glenn L McGrath07085852003-10-09 07:28:22 +00002233identify_abort:
2234 /* VOID */;
Eric Andersen3443bd72003-07-22 07:30:36 +00002235 }
2236#endif
2237#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002238 if (set_busstate)
2239 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002240 if (get_busstate)
2241 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002242 printf(" setting bus state to %d", busstate);
2243 bus_state_value(busstate);
2244 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00002245 bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE");
Eric Andersen3443bd72003-07-22 07:30:36 +00002246 }
2247#endif
2248#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002249 if (get_busstate)
2250 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002251 if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE"))
Glenn L McGrath07085852003-10-09 07:28:22 +00002252 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002253 printf(" busstate = %2ld", parm);
2254 bus_state_value(parm);
2255 }
2256 }
2257#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002258 if (reread_partn)
2259 bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART");
2260
Eric Andersen3443bd72003-07-22 07:30:36 +00002261
2262 if (do_ctimings)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00002263 do_time(0,fd); /*time cache */
Eric Andersen3443bd72003-07-22 07:30:36 +00002264 if (do_timings)
Glenn L McGrath07085852003-10-09 07:28:22 +00002265 do_time(1,fd); /*time device */
Eric Andersen3443bd72003-07-22 07:30:36 +00002266 if (do_flush)
Rob Landleya3e4f382006-04-29 16:06:31 +00002267 flush_buffer_cache(fd);
2268 close(fd);
Eric Andersen3443bd72003-07-22 07:30:36 +00002269}
2270
Eric Andersen06d4ec22004-03-19 10:53:52 +00002271static char * GET_NUMBER(char *p, unsigned long *flag, unsigned long *num)
2272{
2273 *num = 0;
2274 while (isdigit(*p)) {
2275 *flag = 1;
2276 *num = (*num * 10) + (*p++ - '0');
2277 }
2278 return p;
2279}
2280
2281static char * GET_STRING(char *p, unsigned long *flag, int *num)
2282{
2283 char *tmpstr;
2284 char name[32];
2285 tmpstr = name;
2286 tmpstr[0] = '\0';
2287 while (isalnum(*p) && (tmpstr - name) < 31) {
2288 tmpstr[0] = *p++;
2289 tmpstr[1] = '\0';
2290 ++tmpstr;
2291 }
2292 *num = translate_xfermode(name);
2293 if (*num == -1)
2294 *flag = 0;
2295 else
2296 *flag = 1;
2297 return p;
2298}
2299
Eric Andersen3443bd72003-07-22 07:30:36 +00002300#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Rob Landleya3e4f382006-04-29 16:06:31 +00002301static int fromhex(unsigned char c)
Eric Andersen3443bd72003-07-22 07:30:36 +00002302{
2303 if (c >= 'a' && c <= 'f')
2304 return 10 + (c - 'a');
2305 if (c >= '0' && c <= '9')
2306 return (c - '0');
2307 bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
2308}
2309
Rob Landleya3e4f382006-04-29 16:06:31 +00002310static int identify_from_stdin(void)
Eric Andersen3443bd72003-07-22 07:30:36 +00002311{
2312 unsigned short sbuf[800];
2313 unsigned char buf[1600], *b = (unsigned char *)buf;
2314 int i, count = read(0, buf, 1280);
2315
2316 if (count != 1280)
2317 bb_error_msg_and_die("read(1280 bytes) failed (rc=%d)", count);
Glenn L McGrath07085852003-10-09 07:28:22 +00002318 for (i = 0; count >= 4; ++i)
2319 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002320 sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]);
2321 __le16_to_cpus((uint16_t *)(&sbuf[i]));
2322 b += 5;
2323 count -= 5;
2324 }
Rob Landley6389ff12006-05-01 19:28:53 +00002325 identify(sbuf);
Eric Andersen3443bd72003-07-22 07:30:36 +00002326 return 0;
2327}
2328#endif
2329
Eric Andersenb2aa7762004-04-05 13:08:08 +00002330static void missing_arg(int arg, char c, char* add)
2331{
2332 if (!arg)
2333 bb_error_msg("-%c: missing value %s", c, (add!=NULL)? add :"");
2334}
2335
Eric Andersen3443bd72003-07-22 07:30:36 +00002336/* our main() routine: */
2337int hdparm_main(int argc, char **argv)
2338{
2339 char c, *p;
Eric Andersen3443bd72003-07-22 07:30:36 +00002340
2341 ++argv;
2342 if (!--argc)
2343 bb_show_usage();
Glenn L McGrath07085852003-10-09 07:28:22 +00002344
2345 while (argc--)
2346 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002347#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +00002348 if (!strcmp("-Istdin", *argv))
2349 {
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00002350 return identify_from_stdin();
Eric Andersen3443bd72003-07-22 07:30:36 +00002351 }
2352#endif
2353 p = *argv++;
Glenn L McGrath07085852003-10-09 07:28:22 +00002354 if (*p == '-')
2355 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002356 if (!*++p)
2357 bb_show_usage();
Glenn L McGrath07085852003-10-09 07:28:22 +00002358 while ((c = *p++))
2359 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002360 ++flagcount;
Glenn L McGrath07085852003-10-09 07:28:22 +00002361 switch (c)
2362 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002363 case 'V':
Glenn L McGrath07085852003-10-09 07:28:22 +00002364 /*bb_error_msg_and_die("%s", VERSION);*/
2365 /* We have to return 0 here and not 1 */
2366 printf("%s %s\n",bb_applet_name, VERSION);
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00002367 return EXIT_SUCCESS;
Eric Andersen3443bd72003-07-22 07:30:36 +00002368 case 'v':
2369 verbose = 1;
2370 break;
2371#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
2372 case 'I':
2373 get_IDentity = 1;
2374 break;
2375 case 'i':
2376 get_identity = 1;
2377 break;
2378#endif
2379 case 'g':
2380 get_geom = 1;
2381 break;
2382 case 'f':
2383 do_flush = 1;
2384 break;
2385 case 'q':
2386 quiet = 1;
2387 noisy = 0;
2388 break;
2389 case 'u':
2390 get_unmask = noisy;
2391 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002392 if (!*p && argc && isdigit(**argv))
2393 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002394 if ((set_unmask = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002395 unmask = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002396 break;
Eric Andersen0a57a792003-08-06 08:57:35 +00002397#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Eric Andersen3443bd72003-07-22 07:30:36 +00002398 case 'd':
2399 get_dma = noisy;
2400 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002401 if (!*p && argc && isdigit(**argv))
2402 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002403 if ((set_dma = set_flag(p,'9'))==1)
Eric Andersen3443bd72003-07-22 07:30:36 +00002404 dma = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002405 break;
Eric Andersen0a57a792003-08-06 08:57:35 +00002406#endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
Eric Andersen3443bd72003-07-22 07:30:36 +00002407 case 'n':
2408 get_nowerr = noisy;
2409 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002410 if (!*p && argc && isdigit(**argv))
2411 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002412 if ((set_nowerr = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002413 nowerr = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002414 break;
2415 case 'p':
2416 noisy_piomode = noisy;
2417 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002418 if (!*p && argc && isalnum(**argv))
2419 p = *argv++, --argc;
2420 p=GET_STRING(p,&set_piomode,&piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00002421 break;
2422 case 'r':
2423 get_readonly = noisy;
2424 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002425 if (!*p && argc && isdigit(**argv))
2426 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002427 if ((set_readonly = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002428 readonly = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002429 break;
2430 case 'm':
2431 get_mult = noisy;
2432 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002433 if (!*p && argc && isalnum(**argv))
2434 p = *argv++, --argc;
2435 p=GET_NUMBER(p,&set_mult,&mult);
Eric Andersen3443bd72003-07-22 07:30:36 +00002436 break;
2437 case 'c':
2438 get_io32bit = noisy;
2439 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002440 if (!*p && argc && isalnum(**argv))
2441 p = *argv++, --argc;
2442 p=GET_NUMBER(p,&set_io32bit,&io32bit);
Eric Andersen3443bd72003-07-22 07:30:36 +00002443 break;
2444#ifdef HDIO_DRIVE_CMD
2445 case 'S':
2446 get_standby = noisy;
2447 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002448 if (!*p && argc && isalnum(**argv))
2449 p = *argv++, --argc;
2450 p=GET_NUMBER(p,&set_standby,&standby_requested);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002451 missing_arg(set_standby, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002452 break;
2453
2454 case 'D':
2455 get_defects = noisy;
2456 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002457 if (!*p && argc && isalnum(**argv))
2458 p = *argv++, --argc;
2459 p=GET_NUMBER(p,&set_defects,&defects);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002460 missing_arg(set_defects, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002461 break;
2462 case 'P':
2463 get_prefetch = noisy;
2464 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002465 if (!*p && argc && isalnum(**argv))
2466 p = *argv++, --argc;
2467 p=GET_NUMBER(p,&set_prefetch,&prefetch);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002468 missing_arg(set_prefetch, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002469 break;
2470
2471 case 'X':
2472 get_xfermode = noisy;
2473 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002474 if (!*p && argc && isalnum(**argv))
2475 p = *argv++, --argc;
2476 p=GET_STRING(p,&set_xfermode,&xfermode_requested);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002477 missing_arg(set_xfermode, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002478 break;
2479
2480 case 'K':
2481 get_dkeep = noisy;
2482 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002483 if (!*p && argc && isdigit(**argv))
2484 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002485 if ((set_dkeep = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002486 dkeep = *p++ - '0';
2487 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002488 goto missing_arg_error;
Eric Andersen3443bd72003-07-22 07:30:36 +00002489 break;
2490
2491 case 'A':
2492 get_lookahead = noisy;
2493 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002494 if (!*p && argc && isdigit(**argv))
2495 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002496 if ((set_lookahead = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002497 lookahead = *p++ - '0';
2498 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002499 goto missing_arg_error;
Eric Andersen3443bd72003-07-22 07:30:36 +00002500 break;
2501
2502 case 'L':
2503 get_doorlock = noisy;
2504 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002505 if (!*p && argc && isdigit(**argv))
2506 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002507 if ((set_doorlock = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002508 doorlock = *p++ - '0';
2509 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002510 goto missing_arg_error;
Eric Andersen3443bd72003-07-22 07:30:36 +00002511 break;
2512
2513 case 'W':
2514 get_wcache = noisy;
2515 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002516 if (!*p && argc && isdigit(**argv))
2517 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002518 if ((set_wcache = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002519 wcache = *p++ - '0';
2520 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002521missing_arg_error:
2522 missing_arg(1, c, "(0/1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002523 break;
2524
2525 case 'C':
2526 get_powermode = noisy;
2527 noisy = 1;
2528 break;
2529
2530 case 'y':
2531 get_standbynow = noisy;
2532 noisy = 1;
2533 set_standbynow = 1;
2534 break;
2535
2536 case 'Y':
2537 get_sleepnow = noisy;
2538 noisy = 1;
2539 set_sleepnow = 1;
2540 break;
2541
2542 case 'z':
2543 reread_partn = 1;
2544 break;
2545
2546 case 'Z':
2547 get_seagate = noisy;
2548 noisy = 1;
2549 set_seagate = 1;
2550 break;
2551#endif /* HDIO_DRIVE_CMD */
2552 case 'k':
2553 get_keep = noisy;
2554 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002555 if (!*p && argc && isdigit(**argv))
2556 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002557 if ((set_keep = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002558 keep = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002559 break;
2560#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
2561 case 'U':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002562 if (!*p && argc && isdigit(**argv))
2563 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002564 if (! p)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002565 goto expected_hwif_error; /* "expected hwif_nr" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002566
2567 sscanf(p++, "%i", &hwif);
2568
2569 unregister_hwif = 1;
2570 break;
2571#endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF */
2572#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
2573 case 'R':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002574 if (!*p && argc && isdigit(**argv))
2575 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002576 if (! p)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002577 goto expected_hwif_error; /* "expected hwif_data" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002578
2579 sscanf(p++, "%i", &hwif_data);
2580
2581 if (argc && isdigit(**argv))
2582 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002583 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002584 goto expected_hwif_error; /* "expected hwif_ctrl" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002585
2586 sscanf(p, "%i", &hwif_ctrl);
2587
2588 if (argc && isdigit(**argv))
2589 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002590 else
Bernhard Reutner-Fischer061fd0a2006-04-05 16:37:25 +00002591#endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
Bernhard Reutner-Fischer9460f662006-04-11 08:01:29 +00002592#if defined CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF || defined CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Eric Andersenb2aa7762004-04-05 13:08:08 +00002593expected_hwif_error:
Glenn L McGrath07085852003-10-09 07:28:22 +00002594 bb_error_msg_and_die("expected hwif value"); /* "expected hwif_irq" */
Bernhard Reutner-Fischer9460f662006-04-11 08:01:29 +00002595#endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF || CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
Bernhard Reutner-Fischer061fd0a2006-04-05 16:37:25 +00002596#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Eric Andersen3443bd72003-07-22 07:30:36 +00002597
2598 sscanf(p, "%i", &hwif_irq);
2599
2600 *p = '\0';
2601
2602 scan_hwif = 1;
2603 break;
2604#endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
2605 case 'Q':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002606#ifdef HDIO_GET_QDMA
Eric Andersen3443bd72003-07-22 07:30:36 +00002607 get_dma_q = noisy;
2608 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002609#ifdef HDIO_SET_QDMA
2610 if (!*p && argc && isalnum(**argv))
2611 p = *argv++, --argc;
2612 p=GET_NUMBER(p,&set_dma_q,&dma_q);
2613#ifdef HDIO_GET_QDMA
2614 dma_q = -dma_q;
2615#endif
2616#endif
2617#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00002618 break;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002619
Eric Andersen3443bd72003-07-22 07:30:36 +00002620#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
2621 case 'w':
2622 perform_reset = 1;
2623 break;
2624#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
2625#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
2626 case 'x':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002627 if (!*p && argc && isdigit(**argv))
2628 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002629 if ((perform_tristate = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002630 tristate = *p++ - '0';
2631 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002632 missing_arg(1, c, "(0/1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002633 break;
2634
2635#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
2636 case 'a':
2637 get_readahead = noisy;
2638 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002639 if (!*p && argc && isalnum(**argv))
2640 p = *argv++, --argc;
Eric Andersenf828da02004-07-20 22:53:59 +00002641 p=GET_NUMBER(p,&set_readahead,&Xreadahead);
Eric Andersen3443bd72003-07-22 07:30:36 +00002642 break;
2643 case 'B':
2644 get_apmmode = noisy;
2645 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002646 if (!*p && argc && isalnum(**argv))
2647 p = *argv++, --argc;
2648 p=GET_NUMBER(p,&set_apmmode,&apmmode);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002649 missing_arg(set_apmmode, c, "(1-255)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002650 break;
2651 case 't':
2652 do_timings = 1;
2653 do_flush = 1;
2654 break;
2655 case 'T':
2656 do_ctimings = 1;
2657 do_flush = 1;
2658 break;
2659#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
2660 case 'b':
2661 get_busstate = noisy;
2662 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002663 if (!*p && argc && isdigit(**argv))
2664 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002665 if ((set_busstate = set_flag(p,'2'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002666 busstate = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002667 break;
2668#endif
2669 case 'h':
2670 default:
2671 bb_show_usage();
2672 }
2673 }
2674 if (!argc)
2675 bb_show_usage();
Eric Andersen06d4ec22004-03-19 10:53:52 +00002676 } else {
Rob Landleya3e4f382006-04-29 16:06:31 +00002677 process_dev(p);
Eric Andersen06d4ec22004-03-19 10:53:52 +00002678 }
Eric Andersen3443bd72003-07-22 07:30:36 +00002679 }
2680 return 0 ;
2681}