blob: f237d32f58123f6e83d3d5b7abd2e4e8abca77ae [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};
Rob Landley0f0b6452006-05-03 18:28:06 +0000402
403static void identify(uint16_t *id_supplied) ATTRIBUTE_NORETURN;
404static void identify_from_stdin(void) ATTRIBUTE_NORETURN;
405
Eric Andersen3443bd72003-07-22 07:30:36 +0000406#endif
407
408
409/* words 85-87: cmds/feats enabled */
410/* use cmd_feat_str[] to display what commands and features have
Glenn L McGrath07085852003-10-09 07:28:22 +0000411 * been enabled with words 85-87
Eric Andersen3443bd72003-07-22 07:30:36 +0000412 */
413
414/* words 89, 90, SECU ERASE TIME */
415#define ERASE_BITS 0x00ff
416
417/* word 92: master password revision */
418/* NOVAL_0 or NOVAL_1 means no support for master password revision */
419
420/* word 93: hw reset result */
421#define CBLID 0x2000 /* CBLID status */
422#define RST0 0x0001 /* 1=reset to device #0 */
423#define DEV_DET 0x0006 /* how device num determined */
424#define JUMPER_VAL 0x0002 /* device num determined by jumper */
425#define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */
426
427/* word 127: removable media status notification feature set support */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000428#define RM_STAT_BITS 0x0003
Eric Andersen3443bd72003-07-22 07:30:36 +0000429#define RM_STAT_SUP 0x0001
Glenn L McGrath07085852003-10-09 07:28:22 +0000430
Eric Andersen3443bd72003-07-22 07:30:36 +0000431/* word 128: security */
432#define SECU_ENABLED 0x0002
433#define SECU_LEVEL 0x0010
434#define NUM_SECU_STR 6
435#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000436static const char * const secu_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000437 "supported", /* word 128, bit 0 */
438 "enabled", /* word 128, bit 1 */
439 "locked", /* word 128, bit 2 */
440 "frozen", /* word 128, bit 3 */
441 "expired: security count", /* word 128, bit 4 */
442 "supported: enhanced erase" /* word 128, bit 5 */
443};
444#endif
445
446/* word 160: CFA power mode */
447#define VALID_W160 0x8000 /* 1=word valid */
448#define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/
449#define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */
450#define MAX_AMPS 0x0fff /* value = max current in ma */
451
452/* word 255: integrity */
453#define SIG 0x00ff /* signature location */
454#define SIG_VAL 0x00A5 /* signature value */
455
Glenn L McGrath07085852003-10-09 07:28:22 +0000456#define VERSION "v5.4"
457
458#define TIMING_MB 64
459#define TIMING_BUF_MB 1
460#define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024)
461#define TIMING_BUF_COUNT (timing_MB / TIMING_BUF_MB)
462#define BUFCACHE_FACTOR 2
463
464#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
465
466/* Busybox messages and functions */
467
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000468static const char bb_msg_shared_mem[] = "could not %s sharedmem buf";
469static const char bb_msg_op_not_supp[] = " operation not supported on %s disks";
Glenn L McGrath07085852003-10-09 07:28:22 +0000470
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000471static int bb_ioctl(int fd, int request, void *argp, const char *string)
Glenn L McGrath07085852003-10-09 07:28:22 +0000472{
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000473 int e = ioctl(fd, request, argp);
474 if (e && string)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000475 bb_perror_msg(" %s", string);
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000476 return e;
Glenn L McGrath07085852003-10-09 07:28:22 +0000477}
478
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000479static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const char *string)
480{
481 if (!ioctl(fd, cmd, args))
482 return 0;
483 args[0] = alt;
484 return bb_ioctl(fd, cmd, args, string);
485}
486
487
Glenn L McGrath07085852003-10-09 07:28:22 +0000488static void if_printf(unsigned long i, char *fmt, ... )
489{
Rob Landleya3e4f382006-04-29 16:06:31 +0000490 va_list ap;
491 va_start(ap, fmt);
492 if (i)
493 vprintf(fmt, ap);
494 va_end(ap);
Glenn L McGrath07085852003-10-09 07:28:22 +0000495}
496
Rob Landleya3e4f382006-04-29 16:06:31 +0000497static void on_off(unsigned int value);
Glenn L McGrath07085852003-10-09 07:28:22 +0000498
499static void if_printf_on_off(unsigned long get_arg,const char *fmt, unsigned long arg)
500{
501 if (get_arg)
502 {
503 printf(fmt, arg);
504 on_off(arg);
505 }
506}
507
508static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string,
509 const char * fmt)
510{
Rob Landleya3e4f382006-04-29 16:06:31 +0000511 if (ioctl(fd, request, &argp) != 0)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000512 bb_perror_msg(" %s", string);
Glenn L McGrath07085852003-10-09 07:28:22 +0000513 else
514 {
515 printf(fmt, (unsigned long) argp);
516 on_off((unsigned long) argp);
517 }
518}
Eric Andersen416c2422003-12-12 00:08:57 +0000519
520#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000521static void if_else_printf(unsigned long i, char *fmt1, char *fmt2, ... )
522{
Rob Landleya3e4f382006-04-29 16:06:31 +0000523 va_list ap;
524 va_start(ap, fmt2);
525 if (i)
526 vprintf(fmt1, ap);
527 else
528 vprintf(fmt2, ap);
529 va_end(ap);
Glenn L McGrath07085852003-10-09 07:28:22 +0000530}
531
532static void print_ascii(uint16_t *p, uint8_t length);
533
534static void xprint_ascii(uint16_t *val ,int i, char * string, int n)
535{
Rob Landleya3e4f382006-04-29 16:06:31 +0000536 if (val[i])
Glenn L McGrath07085852003-10-09 07:28:22 +0000537 {
538 printf("\t%-20s",string);
539 print_ascii(&val[i], n);
540 }
541}
542
Eric Andersen416c2422003-12-12 00:08:57 +0000543static void if_strcat(unsigned long test, char *modes, char *string)
544{
545 if (test)
546 strcat(modes,string);
547}
548#endif
549
Glenn L McGrath07085852003-10-09 07:28:22 +0000550static void sync_and_sleep(int i)
551{
552 sync();
553 sleep(i);
554}
555
Eric Andersenb2aa7762004-04-05 13:08:08 +0000556static uint16_t check_if_min_and_set_val(uint16_t a, uint16_t b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000557{
Rob Landleya3e4f382006-04-29 16:06:31 +0000558 if ( a < b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000559 a = b;
Eric Andersenb2aa7762004-04-05 13:08:08 +0000560 return a;
Glenn L McGrath07085852003-10-09 07:28:22 +0000561}
562
Eric Andersenb2aa7762004-04-05 13:08:08 +0000563static uint16_t check_if_maj_and_set_val(uint16_t a, uint16_t b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000564{
Rob Landleya3e4f382006-04-29 16:06:31 +0000565 if ( a > b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000566 a = b;
Eric Andersenb2aa7762004-04-05 13:08:08 +0000567 return a;
Glenn L McGrath07085852003-10-09 07:28:22 +0000568}
569
Eric Andersenb2aa7762004-04-05 13:08:08 +0000570static unsigned long int set_flag(char *p, char max)
Glenn L McGrath07085852003-10-09 07:28:22 +0000571{
572 if (*p >= '0' && *p <= max )
573 return 1;
574 return 0;
575}
576
Glenn L McGrath07085852003-10-09 07:28:22 +0000577/* end of busybox specific stuff */
578
Eric Andersen3443bd72003-07-22 07:30:36 +0000579#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000580static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
581{
Eric Andersen3443bd72003-07-22 07:30:36 +0000582 uint16_t ii;
583 uint8_t err_dma = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000584
Rob Landleya3e4f382006-04-29 16:06:31 +0000585 for (ii = 0; ii <= MODE_MAX; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000586 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000587 if (mode_sel & 0x0001)
Glenn L McGrath07085852003-10-09 07:28:22 +0000588 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000589 printf("*%cdma%u ",cc,ii);
Rob Landleya3e4f382006-04-29 16:06:31 +0000590 if (*have_mode)
Glenn L McGrath07085852003-10-09 07:28:22 +0000591 err_dma = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000592 *have_mode = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000593 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000594 else if (mode_sup & 0x0001)
Glenn L McGrath07085852003-10-09 07:28:22 +0000595 printf("%cdma%u ",cc,ii);
596
597 mode_sup >>=1;
598 mode_sel >>=1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000599 }
600 return err_dma;
601}
Glenn L McGrath07085852003-10-09 07:28:22 +0000602
Eric Andersen3443bd72003-07-22 07:30:36 +0000603static void print_ascii(uint16_t *p, uint8_t length) {
604 uint8_t ii;
605 char cl;
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000606
Eric Andersen3443bd72003-07-22 07:30:36 +0000607 /* find first non-space & print it */
Rob Landleya3e4f382006-04-29 16:06:31 +0000608 for (ii = 0; ii< length; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000609 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000610 if (((char) 0x00ff&((*p)>>8)) != ' ')
Glenn L McGrath07085852003-10-09 07:28:22 +0000611 break;
Rob Landleya3e4f382006-04-29 16:06:31 +0000612 if ((cl = (char) 0x00ff&(*p)) != ' ')
Glenn L McGrath07085852003-10-09 07:28:22 +0000613 {
614 if_printf((cl != '\0'),"%c",cl);
615 p++;
616 ii++;
Eric Andersen3443bd72003-07-22 07:30:36 +0000617 break;
618 }
619 p++;
620 }
621 /* print the rest */
Rob Landleya3e4f382006-04-29 16:06:31 +0000622 for (; ii< length; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000623 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000624 if (!(*p))
Glenn L McGrath07085852003-10-09 07:28:22 +0000625 break; /* some older devices have NULLs */
Eric Andersen3443bd72003-07-22 07:30:36 +0000626 printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff);
627 p++;
628 }
629 printf("\n");
630}
631
632/* identify() is the only extern function used across two source files. The
633 others, though, were declared in hdparm.c with global scope; since other
634 functions in that file have static (file) scope, I assume the difference is
635 intentional. */
Rob Landley0f0b6452006-05-03 18:28:06 +0000636
Rob Landley6389ff12006-05-01 19:28:53 +0000637static void identify(uint16_t *id_supplied)
Eric Andersen3443bd72003-07-22 07:30:36 +0000638{
Rob Landley5bc3f052006-04-29 19:11:24 +0000639 uint16_t buf[256];
640 uint16_t *val, ii, jj, kk;
Eric Andersen3443bd72003-07-22 07:30:36 +0000641 uint16_t like_std = 1, std = 0, min_std = 0xffff;
642 uint16_t dev = NO_DEV, eqpt = NO_DEV;
643 uint8_t have_mode = 0, err_dma = 0;
644 uint8_t chksum = 0;
645 uint32_t ll, mm, nn, oo;
Rob Landley2e2d7522006-04-29 15:23:33 +0000646 uint64_t bbbig; /* (:) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000647
Rob Landley5bc3f052006-04-29 19:11:24 +0000648 if (BB_BIG_ENDIAN) {
649 swab(id_supplied, buf, sizeof(buf));
650 val = buf;
651 } else val = id_supplied;
652
Eric Andersen3443bd72003-07-22 07:30:36 +0000653 chksum &= 0xff;
654
655 /* check if we recognise the device type */
656 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000657 if(!(val[GEN_CONFIG] & NOT_ATA))
658 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000659 dev = ATA_DEV;
660 printf("ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000661 }
662 else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL)
663 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000664 dev = ATA_DEV;
665 like_std = 4;
666 printf("CompactFlash ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000667 }
668 else if(!(val[GEN_CONFIG] & NOT_ATAPI))
669 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000670 dev = ATAPI_DEV;
671 eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
672 printf("ATAPI %s, with ", pkt_str[eqpt]);
673 like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000674 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000675 else
676 /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/
677 bb_error_msg_and_die("Unknown device type");
Eric Andersen3443bd72003-07-22 07:30:36 +0000678
Glenn L McGrath07085852003-10-09 07:28:22 +0000679 if_printf(!(val[GEN_CONFIG] & MEDIA_REMOVABLE),"non-");
680 printf("removable media\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000681
682 /* Info from the specific configuration word says whether or not the
683 * ID command completed correctly. It is only defined, however in
Glenn L McGrath07085852003-10-09 07:28:22 +0000684 * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior
Eric Andersen3443bd72003-07-22 07:30:36 +0000685 * standards. Since the values allowed for this word are extremely
686 * specific, it should be safe to check it now, even though we don't
687 * know yet what standard this device is using.
688 */
Rob Landleya3e4f382006-04-29 16:06:31 +0000689 if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000690 (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) )
691 {
692 like_std = 5;
693 if_printf(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)),
694 "powers-up in standby; SET FEATURES subcmd spins-up.\n");
695 if_printf((((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)),
696 "\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000697 }
698
699 /* output the model and serial numbers and the fw revision */
Glenn L McGrath07085852003-10-09 07:28:22 +0000700 xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL);
701 xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL);
702 xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV);
703 xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA);
704 xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF);
Eric Andersen3443bd72003-07-22 07:30:36 +0000705
706 /* major & minor standards version number (Note: these words were not
707 * defined until ATA-3 & the CDROM std uses different words.) */
708 printf("Standards:");
Rob Landleya3e4f382006-04-29 16:06:31 +0000709 if (eqpt != CDROM)
Glenn L McGrath07085852003-10-09 07:28:22 +0000710 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000711 if (val[MINOR] && (val[MINOR] <= MINOR_MAX))
Glenn L McGrath07085852003-10-09 07:28:22 +0000712 {
Eric Andersenb2aa7762004-04-05 13:08:08 +0000713 like_std=check_if_min_and_set_val(like_std, 3);
Eric Andersen3443bd72003-07-22 07:30:36 +0000714 std = actual_ver[val[MINOR]];
Glenn L McGrath07085852003-10-09 07:28:22 +0000715 if_printf(std,"\n\tUsed: %s ",minor_str[val[MINOR]]);
716
Eric Andersen3443bd72003-07-22 07:30:36 +0000717 }
718 /* looks like when they up-issue the std, they obsolete one;
Glenn L McGrath07085852003-10-09 07:28:22 +0000719 * thus, only the newest 4 issues need be supported. (That's
Eric Andersen3443bd72003-07-22 07:30:36 +0000720 * what "kk" and "min_std" are all about.) */
Rob Landleya3e4f382006-04-29 16:06:31 +0000721 if (val[MAJOR] && (val[MAJOR] !=NOVAL_1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000722 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000723 printf("\n\tSupported: ");
724 jj = val[MAJOR] << 1;
725 kk = like_std >4 ? like_std-4: 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000726 for (ii = 14; (ii >0)&&(ii>kk); ii--)
Glenn L McGrath07085852003-10-09 07:28:22 +0000727 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000728 if (jj & 0x8000)
Glenn L McGrath07085852003-10-09 07:28:22 +0000729 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000730 printf("%u ", ii);
Rob Landleya3e4f382006-04-29 16:06:31 +0000731 if (like_std < ii)
Glenn L McGrath07085852003-10-09 07:28:22 +0000732 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000733 like_std = ii;
734 kk = like_std >4 ? like_std-4: 0;
735 }
Eric Andersenb2aa7762004-04-05 13:08:08 +0000736 min_std=check_if_maj_and_set_val(min_std, ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000737 }
738 jj <<= 1;
739 }
Eric Andersenb2aa7762004-04-05 13:08:08 +0000740 like_std=check_if_min_and_set_val(like_std, 3);
Eric Andersen3443bd72003-07-22 07:30:36 +0000741 }
742 /* Figure out what standard the device is using if it hasn't told
743 * us. If we know the std, check if the device is using any of
744 * the words from the next level up. It happens.
745 */
Eric Andersenb2aa7762004-04-05 13:08:08 +0000746 like_std=check_if_min_and_set_val(like_std, std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000747
Rob Landleya3e4f382006-04-29 16:06:31 +0000748 if (((std == 5) || (!std && (like_std < 6))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000749 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
750 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) ||
751 ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) &&
752 ( val[CMDS_SUPP_2] & CMDS_W84) ) ) )
753 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000754 like_std = 6;
Glenn L McGrath07085852003-10-09 07:28:22 +0000755 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000756 else if (((std == 4) || (!std && (like_std < 5))) &&
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000757 ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000758 (( val[HWRST_RSLT] & VALID) == VALID_VAL) ||
759 ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
760 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) )
761 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000762 like_std = 5;
Glenn L McGrath07085852003-10-09 07:28:22 +0000763 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000764 else if (((std == 3) || (!std && (like_std < 4))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000765 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
766 ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) ||
767 (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) ||
768 (( val[CAPAB_1] & VALID) == VALID_VAL) ||
769 (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) ||
770 (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) )
771 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000772 like_std = 4;
Glenn L McGrath07085852003-10-09 07:28:22 +0000773 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000774 else if (((std == 2) || (!std && (like_std < 3))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000775 ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) )
776 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000777 like_std = 3;
Glenn L McGrath07085852003-10-09 07:28:22 +0000778 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000779 else if (((std == 1) || (!std && (like_std < 2))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000780 ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) ||
781 (val[WHATS_VALID] & OK_W64_70)) )
782 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000783 like_std = 2;
784 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000785 if (!std)
Eric Andersen3443bd72003-07-22 07:30:36 +0000786 printf("\n\tLikely used: %u\n",like_std);
Rob Landleya3e4f382006-04-29 16:06:31 +0000787 else if (like_std > std)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000788 printf("& some of %u\n",like_std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000789 else
790 printf("\n");
791 }
792 else
793 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000794 /* TBD: do CDROM stuff more thoroughly. For now... */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000795 kk = 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000796 if (val[CDR_MINOR] == 9)
Glenn L McGrath07085852003-10-09 07:28:22 +0000797 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000798 kk = 1;
799 printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5");
800 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000801 if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000802 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000803 kk = 1;
804 printf("\n\tSupported: CD-ROM ATAPI");
805 jj = val[CDR_MAJOR] >> 1;
Rob Landleya3e4f382006-04-29 16:06:31 +0000806 for (ii = 1; ii <15; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000807 {
808 if_printf((jj & 0x0001),"-%u ", ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000809 jj >>= 1;
810 }
811 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000812 if_else_printf((!kk),"\n\tLikely used CD-ROM ATAPI-1\n","\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000813 /* the cdrom stuff is more like ATA-2 than anything else, so: */
814 like_std = 2;
815 }
816
Rob Landleya3e4f382006-04-29 16:06:31 +0000817 if (min_std == 0xffff)
Glenn L McGrath07085852003-10-09 07:28:22 +0000818 min_std = like_std > 4 ? like_std - 3 : 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000819
820 printf("Configuration:\n");
821 /* more info from the general configuration word */
Rob Landleya3e4f382006-04-29 16:06:31 +0000822 if ((eqpt != CDROM) && (like_std == 1))
Glenn L McGrath07085852003-10-09 07:28:22 +0000823 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000824 jj = val[GEN_CONFIG] >> 1;
Rob Landleya3e4f382006-04-29 16:06:31 +0000825 for (ii = 1; ii < 15; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +0000826 {
827 if_printf((jj & 0x0001),"\t%s\n",ata1_cfg_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000828 jj >>=1;
829 }
830 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000831 if (dev == ATAPI_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000832 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000833 printf("\tDRQ response: "); /* Data Request (DRQ) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000834 switch(val[GEN_CONFIG] & DRQ_RESPONSE_TIME)
835 {
836 case DRQ_3MS_VAL :
837 printf("3ms.\n");
838 break;
839 case DRQ_INTR_VAL :
840 printf("<=10ms with INTRQ\n");
841 break;
842 case DRQ_50US_VAL :
843 printf("50us.\n");
844 break;
845 default :
846 printf("unknown.\n");
847 break;
Eric Andersen3443bd72003-07-22 07:30:36 +0000848 }
849 printf("\tPacket size: ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000850 switch(val[GEN_CONFIG] & PKT_SIZE_SUPPORTED)
851 {
852 case PKT_SIZE_12_VAL :
853 printf("12 bytes\n");
854 break;
855 case PKT_SIZE_16_VAL :
856 printf("16 bytes\n");
857 break;
858 default :
859 printf("Unknown\n");
860 break;
Eric Andersen3443bd72003-07-22 07:30:36 +0000861 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000862 }
863 else
864 {
865 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000866 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
867 mm = 0; bbbig = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000868 if ( (ll > 0x00FBFC10) && (!val[LCYLS]))
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000869 printf("\tCHS addressing not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000870 else
871 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000872 jj = val[WHATS_VALID] & OK_W54_58;
Glenn L McGrath07085852003-10-09 07:28:22 +0000873 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",
874 val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0);
875
876 if_printf(((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])),
877 "\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]);
878
Rob Landleya3e4f382006-04-29 16:06:31 +0000879 if (jj)
Glenn L McGrath07085852003-10-09 07:28:22 +0000880 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000881 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
Rob Landleya3e4f382006-04-29 16:06:31 +0000882 if (like_std < 3)
Glenn L McGrath07085852003-10-09 07:28:22 +0000883 {
884 /* check Endian of capacity bytes */
Eric Andersen3443bd72003-07-22 07:30:36 +0000885 nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR];
886 oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB];
Rob Landleya3e4f382006-04-29 16:06:31 +0000887 if (abs(mm - nn) > abs(oo - nn))
Eric Andersen3443bd72003-07-22 07:30:36 +0000888 mm = oo;
889 }
890 printf("\tCHS current addressable sectors:%11u\n",mm);
Glenn L McGrath07085852003-10-09 07:28:22 +0000891 }
Eric Andersen3443bd72003-07-22 07:30:36 +0000892 }
893 /* LBA addressing */
894 printf("\tLBA user addressable sectors:%11u\n",ll);
Rob Landleya3e4f382006-04-29 16:06:31 +0000895 if ( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000896 (val[CMDS_SUPP_1] & SUPPORT_48_BIT) )
897 {
Rob Landley2e2d7522006-04-29 15:23:33 +0000898 bbbig = (uint64_t)val[LBA_64_MSB] << 48 |
899 (uint64_t)val[LBA_48_MSB] << 32 |
900 (uint64_t)val[LBA_MID] << 16 |
Glenn L McGrath07085852003-10-09 07:28:22 +0000901 val[LBA_LSB] ;
Eric Andersen3443bd72003-07-22 07:30:36 +0000902 printf("\tLBA48 user addressable sectors:%11llu\n",bbbig);
903 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000904
905 if (!bbbig)
Rob Landley2e2d7522006-04-29 15:23:33 +0000906 bbbig = (uint64_t)(ll>mm ? ll : mm); /* # 512 byte blocks */
Eric Andersen3443bd72003-07-22 07:30:36 +0000907 printf("\tdevice size with M = 1024*1024: %11llu MBytes\n",bbbig>>11);
908 bbbig = (bbbig<<9)/1000000;
909 printf("\tdevice size with M = 1000*1000: %11llu MBytes ",bbbig);
Glenn L McGrath07085852003-10-09 07:28:22 +0000910
911 if_else_printf((bbbig > 1000),"(%llu GB)\n","\n",bbbig/1000);
Eric Andersen3443bd72003-07-22 07:30:36 +0000912
913 }
914
915 /* hw support of commands (capabilities) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000916 printf("Capabilities:\n\t");
917
Rob Landleya3e4f382006-04-29 16:06:31 +0000918 if (dev == ATAPI_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000919 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000920 if (eqpt != CDROM)
Glenn L McGrath07085852003-10-09 07:28:22 +0000921 if_printf((val[CAPAB_0] & CMD_Q_SUP),"Cmd queuing, ");
922
923 if_printf((val[CAPAB_0] & OVLP_SUP),"Cmd overlap, ");
Eric Andersen3443bd72003-07-22 07:30:36 +0000924 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000925 if_printf((val[CAPAB_0] & LBA_SUP),"LBA, ");
926
Rob Landleya3e4f382006-04-29 16:06:31 +0000927 if (like_std != 1)
Glenn L McGrath07085852003-10-09 07:28:22 +0000928 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000929 printf("IORDY");
Glenn L McGrath07085852003-10-09 07:28:22 +0000930 if_printf((!(val[CAPAB_0] & IORDY_SUP)),"(may be)");
931 if_else_printf((val[CAPAB_0] & IORDY_OFF),"(can","(cannot");
932 printf(" be disabled)\n");
933 }
934 else
935 printf("no IORDY\n");
936
Rob Landleya3e4f382006-04-29 16:06:31 +0000937 if ((like_std == 1) && val[BUF_TYPE])
Glenn L McGrath07085852003-10-09 07:28:22 +0000938 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000939 kk = val[BUF_TYPE];
940 printf("\tBuffer type: %04x: ",kk);
Glenn L McGrath07085852003-10-09 07:28:22 +0000941 if_else_printf((kk < 2),"single port, single-sector","dual port, multi-sector");
942 if_printf((kk > 2)," with read caching ability");
Eric Andersen3443bd72003-07-22 07:30:36 +0000943 printf("\n");
944 }
945 jj = 0;
Rob Landleya3e4f382006-04-29 16:06:31 +0000946 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1)))
Glenn L McGrath07085852003-10-09 07:28:22 +0000947 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000948 printf("\tBuffer size: %.1fkB",(float)val[BUFFER__SIZE]/2);
949 jj = 1;
950 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000951 if ((min_std < 4) && (val[RW_LONG]))
Glenn L McGrath07085852003-10-09 07:28:22 +0000952 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000953 printf("\tbytes avail on r/w long: %u",val[RW_LONG]);
954 jj = 1;
955 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000956 if ((eqpt != CDROM) && (like_std > 3))
Glenn L McGrath07085852003-10-09 07:28:22 +0000957 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000958 printf("\tQueue depth: %u",(val[QUEUE_DEPTH] & DEPTH_BITS)+1);
959 jj = 1;
960 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000961 if_printf(jj,"\n");
962
Rob Landleya3e4f382006-04-29 16:06:31 +0000963 if (dev == ATA_DEV)
Glenn L McGrath07085852003-10-09 07:28:22 +0000964 {
Rob Landleya3e4f382006-04-29 16:06:31 +0000965 if (like_std == 1)
Glenn L McGrath07085852003-10-09 07:28:22 +0000966 printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":"");
967 else
968 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000969 printf("\tStandby timer values: spec'd by ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000970 if_else_printf((val[CAPAB_0] & STD_STBY),"Standard","Vendor");
Rob Landleya3e4f382006-04-29 16:06:31 +0000971 if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
Glenn L McGrath07085852003-10-09 07:28:22 +0000972 printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no");
973 else
974 printf("\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000975 }
976 printf("\tR/W multiple sector transfer: ");
Rob Landleya3e4f382006-04-29 16:06:31 +0000977 if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
Eric Andersen3443bd72003-07-22 07:30:36 +0000978 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000979 else
980 {
981 printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER);
982 if_else_printf((val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID),
983 "%u\n","?\n",val[SECTOR_XFER_CUR] & SECTOR_XFER);
Eric Andersen3443bd72003-07-22 07:30:36 +0000984 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000985 if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008))
Glenn L McGrath07085852003-10-09 07:28:22 +0000986 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000987 /* We print out elsewhere whether the APM feature is enabled or
988 not. If it's not enabled, let's not repeat the info; just print
989 nothing here. */
Glenn L McGrath07085852003-10-09 07:28:22 +0000990 printf("\tAdvancedPM level: ");
991 if ( (val[ADV_PWR] & 0xFF00) == 0x4000 )
992 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000993 uint8_t apm_level = val[ADV_PWR] & 0x00FF;
Eric Andersen3443bd72003-07-22 07:30:36 +0000994 printf("%u (0x%x)\n", apm_level, apm_level);
Glenn L McGrath07085852003-10-09 07:28:22 +0000995 }
996 else
Eric Andersen3443bd72003-07-22 07:30:36 +0000997 printf("unknown setting (0x%04x)\n", val[ADV_PWR]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000998 }
Rob Landleya3e4f382006-04-29 16:06:31 +0000999 if (like_std > 5)
Glenn L McGrath07085852003-10-09 07:28:22 +00001000 {
1001 if_printf(val[ACOUSTIC],"\tRecommended acoustic management value: %u, current value: %u\n",
1002 (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff);
Eric Andersen3443bd72003-07-22 07:30:36 +00001003 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001004 }
1005 else
1006 {
1007 /* ATAPI */
Rob Landleya3e4f382006-04-29 16:06:31 +00001008 if (eqpt != CDROM)
Glenn L McGrath07085852003-10-09 07:28:22 +00001009 if_printf((val[CAPAB_0] & SWRST_REQ),"\tATA sw reset required\n");
1010
Rob Landleya3e4f382006-04-29 16:06:31 +00001011 if (val[PKT_REL] || val[SVC_NBSY])
Glenn L McGrath07085852003-10-09 07:28:22 +00001012 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001013 printf("\tOverlap support:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001014 if_printf(val[PKT_REL]," %uus to release bus.",val[PKT_REL]);
1015 if_printf(val[SVC_NBSY]," %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001016 printf("\n");
1017 }
1018 }
1019
1020 /* DMA stuff. Check that only one DMA mode is selected. */
1021 printf("\tDMA: ");
Rob Landleya3e4f382006-04-29 16:06:31 +00001022 if (!(val[CAPAB_0] & DMA_SUP))
Eric Andersen3443bd72003-07-22 07:30:36 +00001023 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001024 else
1025 {
1026 if_printf((val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]),
1027 " sdma%u\n",(val[DMA_MODE] & MODE) >> 8);
Rob Landleya3e4f382006-04-29 16:06:31 +00001028 if (val[SINGLE_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +00001029 {
1030 jj = val[SINGLE_DMA];
1031 kk = val[SINGLE_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001032 err_dma += mode_loop(jj,kk,'s',&have_mode);
1033 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001034 if (val[MULTI_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +00001035 {
1036 jj = val[MULTI_DMA];
1037 kk = val[MULTI_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001038 err_dma += mode_loop(jj,kk,'m',&have_mode);
1039 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001040 if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA])
Glenn L McGrath07085852003-10-09 07:28:22 +00001041 {
1042 jj = val[ULTRA_DMA];
1043 kk = val[ULTRA_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001044 err_dma += mode_loop(jj,kk,'u',&have_mode);
1045 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001046 if_printf((err_dma || !have_mode),"(?)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001047 printf("\n");
1048
Glenn L McGrath07085852003-10-09 07:28:22 +00001049 if_printf(((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)),
1050 "\t Interleaved DMA support\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001051
Rob Landleya3e4f382006-04-29 16:06:31 +00001052 if ((val[WHATS_VALID] & OK_W64_70) &&
Glenn L McGrath07085852003-10-09 07:28:22 +00001053 (val[DMA_TIME_MIN] || val[DMA_TIME_NORM]))
1054 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001055 printf("\t Cycle time:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001056 if_printf(val[DMA_TIME_MIN]," min=%uns",val[DMA_TIME_MIN]);
1057 if_printf(val[DMA_TIME_NORM]," recommended=%uns",val[DMA_TIME_NORM]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001058 printf("\n");
1059 }
1060 }
1061
1062 /* Programmed IO stuff */
1063 printf("\tPIO: ");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001064 /* If a drive supports mode n (e.g. 3), it also supports all modes less
Eric Andersen3443bd72003-07-22 07:30:36 +00001065 * than n (e.g. 3, 2, 1 and 0). Print all the modes. */
Rob Landleya3e4f382006-04-29 16:06:31 +00001066 if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP))
Glenn L McGrath07085852003-10-09 07:28:22 +00001067 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001068 jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007;
Rob Landleya3e4f382006-04-29 16:06:31 +00001069 for (ii = 0; ii <= PIO_MODE_MAX ; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +00001070 {
1071 if_printf((jj & 0x0001),"pio%d ",ii);
Eric Andersen3443bd72003-07-22 07:30:36 +00001072 jj >>=1;
1073 }
1074 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001075 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001076 else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) )
Glenn L McGrath07085852003-10-09 07:28:22 +00001077 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001078 for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
Eric Andersen3443bd72003-07-22 07:30:36 +00001079 printf("pio%d ",ii);
Eric Andersen3443bd72003-07-22 07:30:36 +00001080 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001081 }
1082 else
1083 printf("unknown\n");
1084
Rob Landleya3e4f382006-04-29 16:06:31 +00001085 if (val[WHATS_VALID] & OK_W64_70)
Glenn L McGrath07085852003-10-09 07:28:22 +00001086 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001087 if (val[PIO_NO_FLOW] || val[PIO_FLOW])
Glenn L McGrath07085852003-10-09 07:28:22 +00001088 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001089 printf("\t Cycle time:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001090 if_printf(val[PIO_NO_FLOW]," no flow control=%uns", val[PIO_NO_FLOW]);
1091 if_printf(val[PIO_FLOW]," IORDY flow control=%uns", val[PIO_FLOW]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001092 printf("\n");
1093 }
1094 }
1095
Rob Landleya3e4f382006-04-29 16:06:31 +00001096 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001097 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001098 printf("Commands/features:\n\tEnabled\tSupported:\n");
1099 jj = val[CMDS_SUPP_0];
1100 kk = val[CMDS_EN_0];
Rob Landleya3e4f382006-04-29 16:06:31 +00001101 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +00001102 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001103 if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0'))
Glenn L McGrath07085852003-10-09 07:28:22 +00001104 {
1105 if_else_printf((kk & 0x8000),"\t *","\t");
Eric Andersen3443bd72003-07-22 07:30:36 +00001106 printf("\t%s\n",cmd_feat_str[ii]);
1107 }
1108 jj <<=1; kk<<=1;
Rob Landleya3e4f382006-04-29 16:06:31 +00001109 if (ii%16 == 15)
Glenn L McGrath07085852003-10-09 07:28:22 +00001110 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001111 jj = val[CMDS_SUPP_0+1+(ii/16)];
1112 kk = val[CMDS_EN_0+1+(ii/16)];
1113 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001114 if (ii == 31)
Glenn L McGrath07085852003-10-09 07:28:22 +00001115 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001116 if ((val[CMDS_SUPP_2] & VALID) != VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001117 ii +=16;
Eric Andersen3443bd72003-07-22 07:30:36 +00001118 }
1119 }
1120 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001121 if_printf(((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP),
1122 "\tRemovable Media Status Notification feature set supported\n");
1123
1124
Eric Andersen3443bd72003-07-22 07:30:36 +00001125 /* security */
Rob Landleya3e4f382006-04-29 16:06:31 +00001126 if ((eqpt != CDROM) && (like_std > 3) &&
Glenn L McGrath07085852003-10-09 07:28:22 +00001127 (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME]))
1128 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001129 printf("Security: \n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001130 if_printf((val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)),
1131 "\tMaster password revision code = %u\n",val[PSWD_CODE]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001132 jj = val[SECU_STATUS];
Rob Landleya3e4f382006-04-29 16:06:31 +00001133 if (jj)
Glenn L McGrath07085852003-10-09 07:28:22 +00001134 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001135 for (ii = 0; ii < NUM_SECU_STR; ii++)
Glenn L McGrath07085852003-10-09 07:28:22 +00001136 {
1137 if_else_printf((!(jj & 0x0001)),"\tnot\t%s\n", "\t\t%s\n", secu_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001138 jj >>=1;
1139 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001140 if (val[SECU_STATUS] & SECU_ENABLED)
Glenn L McGrath07085852003-10-09 07:28:22 +00001141 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001142 printf("\tSecurity level ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001143 if_else_printf((val[SECU_STATUS] & SECU_LEVEL),"maximum\n","high\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001144 }
1145 }
1146 jj = val[ERASE_TIME] & ERASE_BITS;
1147 kk = val[ENH_ERASE_TIME] & ERASE_BITS;
Rob Landleya3e4f382006-04-29 16:06:31 +00001148 if (jj || kk)
Glenn L McGrath07085852003-10-09 07:28:22 +00001149 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001150 printf("\t");
Glenn L McGrath07085852003-10-09 07:28:22 +00001151 if_printf(jj,"%umin for SECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1);
1152 if_printf(kk,"%umin for ENHANCED SECURITY ERASE UNIT.", kk==ERASE_BITS ? 508 : kk<<1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001153 printf("\n");
1154 }
1155 }
1156
1157 /* reset result */
Rob Landleya3e4f382006-04-29 16:06:31 +00001158 if ((val[HWRST_RSLT] & VALID) == VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001159 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001160 printf("HW reset results:\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001161 if_else_printf((val[HWRST_RSLT] & CBLID),"\tCBLID- above Vih\n","\tCBLID- below Vih\n");
1162
Rob Landleya3e4f382006-04-29 16:06:31 +00001163 if (val[HWRST_RSLT] & RST0)
Glenn L McGrath07085852003-10-09 07:28:22 +00001164 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001165 printf("\tDevice num = 0");
1166 jj = val[HWRST_RSLT];
Glenn L McGrath07085852003-10-09 07:28:22 +00001167 }
1168 else
1169 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001170 printf("\tDevice num = 1");
1171 jj = val[HWRST_RSLT] >> 8;
1172 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001173
Rob Landleya3e4f382006-04-29 16:06:31 +00001174 if ((jj & DEV_DET) == JUMPER_VAL)
Eric Andersen3443bd72003-07-22 07:30:36 +00001175 printf(" determined by the jumper");
Rob Landleya3e4f382006-04-29 16:06:31 +00001176 else if ((jj & DEV_DET) == CSEL_VAL)
Eric Andersen3443bd72003-07-22 07:30:36 +00001177 printf(" determined by CSEL");
1178 printf("\n");
1179 }
1180
1181 /* more stuff from std 5 */
Rob Landleya3e4f382006-04-29 16:06:31 +00001182 if ((like_std > 4) && (eqpt != CDROM))
Glenn L McGrath07085852003-10-09 07:28:22 +00001183 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001184 if (val[CFA_PWR_MODE] & VALID_W160)
Glenn L McGrath07085852003-10-09 07:28:22 +00001185 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001186 printf("CFA power mode 1:\n\t");
Glenn L McGrath07085852003-10-09 07:28:22 +00001187 if_else_printf((val[CFA_PWR_MODE] & PWR_MODE_OFF),"disabled","enabled");
1188
1189 if_printf((val[CFA_PWR_MODE] & PWR_MODE_REQ)," and required by some commands");
Eric Andersen3443bd72003-07-22 07:30:36 +00001190 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001191
1192 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 +00001193 }
Rob Landleya3e4f382006-04-29 16:06:31 +00001194 if ((val[INTEGRITY] & SIG) == SIG_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001195 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001196 printf("Checksum: ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001197 if_printf(chksum,"in");
Eric Andersen3443bd72003-07-22 07:30:36 +00001198 printf("correct\n");
1199 }
1200 }
1201
1202 exit(0);
1203}
1204#endif
1205
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001206static int verbose, get_identity, get_geom, noisy = 1, quiet;
Rob Landley6389ff12006-05-01 19:28:53 +00001207static int flagcount, do_flush;
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001208static int do_ctimings, do_timings;
Eric Andersen3443bd72003-07-22 07:30:36 +00001209
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001210static unsigned long set_readahead, get_readahead, Xreadahead;
1211static unsigned long set_readonly, get_readonly, readonly;
1212static unsigned long set_unmask, get_unmask, unmask;
1213static unsigned long set_mult, get_mult, mult;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001214#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001215static unsigned long set_dma, get_dma, dma;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001216#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001217static unsigned long set_dma_q, get_dma_q, dma_q;
1218static unsigned long set_nowerr, get_nowerr, nowerr;
1219static unsigned long set_keep, get_keep, keep;
1220static unsigned long set_io32bit, get_io32bit, io32bit;
1221static unsigned long set_piomode, noisy_piomode;
1222static int piomode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001223#ifdef HDIO_DRIVE_CMD
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001224static unsigned long set_dkeep, get_dkeep, dkeep;
1225static unsigned long set_standby, get_standby, standby_requested;
1226static unsigned long set_xfermode, get_xfermode;
1227static int xfermode_requested;
1228static unsigned long set_lookahead, get_lookahead, lookahead;
1229static unsigned long set_prefetch, get_prefetch, prefetch;
1230static unsigned long set_defects, get_defects, defects;
1231static unsigned long set_wcache, get_wcache, wcache;
1232static unsigned long set_doorlock, get_doorlock, doorlock;
1233static unsigned long set_seagate, get_seagate;
1234static unsigned long set_standbynow, get_standbynow;
1235static unsigned long set_sleepnow, get_sleepnow;
1236static unsigned long get_powermode;
1237static unsigned long set_apmmode, get_apmmode, apmmode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001238#endif
1239#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001240static int get_IDentity;
Eric Andersen3443bd72003-07-22 07:30:36 +00001241#endif
1242#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001243static int unregister_hwif;
1244static int hwif;
Eric Andersen3443bd72003-07-22 07:30:36 +00001245#endif
1246#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001247static int scan_hwif;
1248static int hwif_data;
1249static int hwif_ctrl;
1250static int hwif_irq;
Eric Andersen3443bd72003-07-22 07:30:36 +00001251#endif
1252#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001253static int set_busstate, get_busstate, busstate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001254#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001255static int reread_partn;
Eric Andersen3443bd72003-07-22 07:30:36 +00001256
1257#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001258static int perform_reset;
Eric Andersen3443bd72003-07-22 07:30:36 +00001259#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
1260#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001261static int perform_tristate, tristate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001262#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
1263
1264// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then
1265// then the HDIO_GET_IDENTITY only returned 142 bytes.
1266// Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes,
1267// and HDIO_GET_IDENTITY returns 512 bytes. But the latest
1268// 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY
1269// (which they should, but they should just return -EINVAL).
1270//
1271// So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes.
1272// On a really old system, it will not, and we will be confused.
1273// Too bad, really.
1274
1275#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001276static const char * const cfg_str[] =
Eric Andersen3443bd72003-07-22 07:30:36 +00001277{ "", " HardSect", " SoftSect", " NotMFM",
1278 " HdSw>15uSec", " SpinMotCtl", " Fixed", " Removeable",
1279 " DTR<=5Mbs", " DTR>5Mbs", " DTR>10Mbs", " RotSpdTol>.5%",
1280 " dStbOff", " TrkOff", " FmtGapReq", " nonMagnetic"
1281};
1282
Rob Landleya3e4f382006-04-29 16:06:31 +00001283static const char * const BuffType[] = {"unknown", "1Sect", "DualPort", "DualPortCache"};
Eric Andersen3443bd72003-07-22 07:30:36 +00001284
Rob Landleya3e4f382006-04-29 16:06:31 +00001285static void dump_identity(const struct hd_driveid *id)
Eric Andersen3443bd72003-07-22 07:30:36 +00001286{
1287 int i;
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001288 char pmodes[64], dmodes[128], umodes[128];
Eric Andersen3443bd72003-07-22 07:30:36 +00001289 const unsigned short int *id_regs= (const void*) id;
1290 unsigned long capacity;
1291
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001292 pmodes[0] = dmodes[0] = umodes[0] = '\0';
1293
Glenn L McGrath07085852003-10-09 07:28:22 +00001294 printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={",
1295 id->model, id->fw_rev, id->serial_no);
1296 for (i=0; i<=15; i++)
1297 if_printf((id->config & (1<<i)),"%s", cfg_str[i]);
1298
1299 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n",
1300 id->cyls, id->heads, id->sectors, id->track_bytes,
1301 id->sector_bytes, id->ecc_bytes);
1302
1303 if (id->buf_type > 3)
1304 printf("%s%u", " BuffType=", id->buf_type);
1305 else
1306 printf("%s%s", " BuffType=", BuffType[id->buf_type]);
1307
Eric Andersen3443bd72003-07-22 07:30:36 +00001308 printf(", BuffSize=%ukB, MaxMultSect=%u", id->buf_size/2, id->max_multsect);
Glenn L McGrath07085852003-10-09 07:28:22 +00001309 if (id->max_multsect)
1310 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001311 printf(", MultSect=");
1312 if (!(id->multsect_valid&1))
1313 printf("?%u?", id->multsect);
1314 else if (id->multsect)
1315 printf("%u", id->multsect);
1316 else
1317 printf("off");
1318 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001319 printf("\n");
1320 if (id->tPIO <= 5)
1321 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001322 strcat(pmodes, "pio0 ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001323 if_strcat((id->tPIO >= 1), pmodes, "pio1 ");
1324 if_strcat((id->tPIO >= 2), pmodes, "pio2 ");
1325
Eric Andersen3443bd72003-07-22 07:30:36 +00001326 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001327 if_printf((!(id->field_valid&1))," (maybe):");
Eric Andersen3443bd72003-07-22 07:30:36 +00001328#if __BYTE_ORDER == __BIG_ENDIAN
1329 capacity = (id->cur_capacity0 << 16) | id->cur_capacity1;
1330#else
1331 capacity = (id->cur_capacity1 << 16) | id->cur_capacity0;
1332#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001333 printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001334 id->cur_sectors, capacity ,
1335 ((id->capability&2)==0)?"no":"yes");
Eric Andersen3443bd72003-07-22 07:30:36 +00001336
Glenn L McGrath07085852003-10-09 07:28:22 +00001337 if_printf((id->capability&2),", LBAsects=%u", id->lba_capacity);
1338
1339 if (id->capability&1)
1340 {
1341 if (id->dma_1word | id->dma_mword)
1342 {
1343 if_strcat((id->dma_1word & 0x100), dmodes, "*");
1344 if_strcat((id->dma_1word & 1), dmodes, "sdma0 ");
1345 if_strcat((id->dma_1word & 0x200), dmodes, "*");
1346 if_strcat((id->dma_1word & 2), dmodes, "sdma1 ");
1347 if_strcat((id->dma_1word & 0x400), dmodes, "*");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001348 if_strcat((id->dma_1word & 4), dmodes, "sdma2 ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001349 if_strcat((id->dma_1word & 0xf800), dmodes, "*");
1350 if_strcat((id->dma_1word & 0xf8), dmodes, "sdma? ");
1351 if_strcat((id->dma_mword & 0x100), dmodes, "*");
1352 if_strcat((id->dma_mword & 1), dmodes, "mdma0 ");
1353 if_strcat((id->dma_mword & 0x200), dmodes, "*");
1354 if_strcat((id->dma_mword & 2), dmodes, "mdma1 ");
1355 if_strcat((id->dma_mword & 0x400), dmodes, "*");
1356 if_strcat((id->dma_mword & 4), dmodes, "mdma2 ");
1357 if_strcat((id->dma_mword & 0xf800), dmodes, "*");
1358 if_strcat((id->dma_mword & 0xf8), dmodes, "mdma? ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001359 }
1360 }
1361 printf("\n IORDY=");
1362 if (id->capability&8)
1363 printf((id->capability&4) ? "on/off" : "yes");
1364 else
1365 printf("no");
Eric Andersen3443bd72003-07-22 07:30:36 +00001366
Glenn L McGrath07085852003-10-09 07:28:22 +00001367 if ((id->capability&8) || (id->field_valid&2))
1368 {
1369 if (id->field_valid&2)
1370 {
1371 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
1372 if_strcat((id->eide_pio_modes & 1), pmodes, "pio3 ");
1373 if_strcat((id->eide_pio_modes & 2), pmodes, "pio4 ");
1374 if_strcat((id->eide_pio_modes &~3), pmodes, "pio? ");
1375 }
1376 if (id->field_valid&4)
1377 {
1378 if_strcat((id->dma_ultra & 0x100),umodes,"*");
1379 if_strcat((id->dma_ultra & 0x001),umodes,"udma0 ");
1380 if_strcat((id->dma_ultra & 0x200),umodes,"*");
1381 if_strcat((id->dma_ultra & 0x002),umodes,"udma1 ");
1382 if_strcat((id->dma_ultra & 0x400),umodes,"*");
1383 if_strcat((id->dma_ultra & 0x004),umodes,"udma2 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001384#ifdef __NEW_HD_DRIVE_ID
Glenn L McGrath07085852003-10-09 07:28:22 +00001385 if (id->hw_config & 0x2000)
1386 {
1387#else /* !__NEW_HD_DRIVE_ID */
1388 if (id->word93 & 0x2000)
1389 {
1390#endif /* __NEW_HD_DRIVE_ID */
1391 if_strcat((id->dma_ultra & 0x0800),umodes,"*");
1392 if_strcat((id->dma_ultra & 0x0008),umodes,"udma3 ");
1393 if_strcat((id->dma_ultra & 0x1000),umodes,"*");
1394 if_strcat((id->dma_ultra & 0x0010),umodes,"udma4 ");
1395 if_strcat((id->dma_ultra & 0x2000),umodes,"*");
1396 if_strcat((id->dma_ultra & 0x0020),umodes,"udma5 ");
1397 if_strcat((id->dma_ultra & 0x4000),umodes,"*");
1398 if_strcat((id->dma_ultra & 0x0040),umodes,"udma6 ");
1399 if_strcat((id->dma_ultra & 0x8000),umodes,"*");
1400 if_strcat((id->dma_ultra & 0x0080),umodes,"udma7 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001401 }
1402 }
1403 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001404 if_printf(((id->capability&1) && (id->field_valid&2)),
1405 ", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time);
1406 printf("\n PIO modes: %s", pmodes);
1407 if_printf((*dmodes),"\n DMA modes: %s", dmodes);
1408 if_printf((*umodes),"\n UDMA modes: %s", umodes);
1409
1410 printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes");
1411 if (id_regs[83] & 8)
1412 {
1413 if (!(id_regs[86]&8))
1414 printf(": disabled (255)");
1415 else if ((id_regs[91]&0xFF00)!=0x4000)
1416 printf(": unknown setting");
1417 else
1418 printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF);
1419 }
1420 if_printf( (id_regs[82]&0x20)," WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled");
1421#ifdef __NEW_HD_DRIVE_ID
1422 if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31))
1423 {
1424 printf("\n Drive conforms to: ");
1425 if_else_printf((id->minor_rev_num <= 31),"%s: ","unknown: ", minor_str[id->minor_rev_num]);
Rob Landley026147a2006-04-17 22:29:13 +00001426 if (id->major_rev_num != 0x0000 && /* NOVAL_0 */
1427 id->major_rev_num != 0xFFFF) { /* NOVAL_1 */
Glenn L McGrath07085852003-10-09 07:28:22 +00001428 for (i=0; i <= 15; i++)
Rob Landley026147a2006-04-17 22:29:13 +00001429 if_printf((id->major_rev_num & (1<<i))," ATA/ATAPI-%u", i);
Glenn L McGrath07085852003-10-09 07:28:22 +00001430 }
1431 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001432#endif /* __NEW_HD_DRIVE_ID */
Glenn L McGrath07085852003-10-09 07:28:22 +00001433 printf("\n\n * signifies the current active mode\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001434}
1435#endif
1436
Rob Landleya3e4f382006-04-29 16:06:31 +00001437static void flush_buffer_cache(int fd)
Eric Andersen3443bd72003-07-22 07:30:36 +00001438{
Rob Landleya3e4f382006-04-29 16:06:31 +00001439 fsync(fd); /* flush buffers */
Glenn L McGrath07085852003-10-09 07:28:22 +00001440 bb_ioctl(fd, BLKFLSBUF, NULL,"BLKFLSBUF" ) ;/* do it again, big time */
Eric Andersen3443bd72003-07-22 07:30:36 +00001441#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001442 sleep(1);
1443 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001444 bb_perror_msg("HDIO_DRIVE_CMD");
Eric Andersen3443bd72003-07-22 07:30:36 +00001445#endif
1446}
1447
Rob Landleya3e4f382006-04-29 16:06:31 +00001448static int seek_to_zero(int fd)
Eric Andersen3443bd72003-07-22 07:30:36 +00001449{
Glenn L McGrath07085852003-10-09 07:28:22 +00001450 if (lseek(fd, (off_t) 0, SEEK_SET))
Eric Andersen3443bd72003-07-22 07:30:36 +00001451 return 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001452 return 0;
1453}
1454
Rob Landleya3e4f382006-04-29 16:06:31 +00001455static int read_big_block(int fd, char *buf)
Eric Andersen3443bd72003-07-22 07:30:36 +00001456{
Glenn L McGrath07085852003-10-09 07:28:22 +00001457 const char *string;
Eric Andersen3443bd72003-07-22 07:30:36 +00001458 int i, rc;
Glenn L McGrath07085852003-10-09 07:28:22 +00001459 if ((rc = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES)
1460 {
1461 switch(rc)
1462 {
1463 case -1:
1464 string = "read()";
1465 break;
1466 case 0:
1467 string = "read() hit EOF - device too small";
1468 break;
1469 default:
1470 string = "read(%u) returned %u bytes";
Eric Andersen3443bd72003-07-22 07:30:36 +00001471 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001472 bb_error_msg(string, TIMING_BUF_BYTES, rc);
Eric Andersen3443bd72003-07-22 07:30:36 +00001473 return 1;
1474 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001475
Eric Andersen3443bd72003-07-22 07:30:36 +00001476 /* access all sectors of buf to ensure the read fully completed */
1477 for (i = 0; i < TIMING_BUF_BYTES; i += 512)
1478 buf[i] &= 1;
1479 return 0;
1480}
1481
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001482static double correction;
Eric Andersen50af12d2003-08-06 08:47:59 +00001483
Rob Landleya3e4f382006-04-29 16:06:31 +00001484static void do_time(int flag, int fd)
Glenn L McGrath07085852003-10-09 07:28:22 +00001485/*
1486 flag = 0 time_cache
1487 flag = 1 time_device
1488*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001489{
Eric Andersen50af12d2003-08-06 08:47:59 +00001490 int i;
Eric Andersen3443bd72003-07-22 07:30:36 +00001491 char *buf;
1492 double elapsed;
1493 struct itimerval e1, e2;
1494 int shmid;
Eric Andersen50af12d2003-08-06 08:47:59 +00001495 int timing_MB = TIMING_MB;
Eric Andersen3443bd72003-07-22 07:30:36 +00001496
Glenn L McGrath07085852003-10-09 07:28:22 +00001497 if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1)
1498 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001499 bb_error_msg(bb_msg_shared_mem,"allocate"); /*"could not allocate sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001500 return;
1501 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001502 if (shmctl(shmid, SHM_LOCK, NULL) == -1)
1503 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001504 bb_error_msg(bb_msg_shared_mem,"lock"); /*"could not lock sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001505 (void) shmctl(shmid, IPC_RMID, NULL);
1506 return;
1507 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001508 if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1)
1509 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001510 bb_error_msg(bb_msg_shared_mem,"attach"); /*"could not attach sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001511 (void) shmctl(shmid, IPC_RMID, NULL);
1512 return;
1513 }
1514 if (shmctl(shmid, IPC_RMID, NULL) == -1)
Rob Landleya3e4f382006-04-29 16:06:31 +00001515 bb_error_msg("shmctl(,IPC_RMID,)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001516
1517 /* Clear out the device request queues & give them time to complete */
Glenn L McGrath07085852003-10-09 07:28:22 +00001518 sync_and_sleep(3);
Eric Andersen3443bd72003-07-22 07:30:36 +00001519
Rob Landleya3e4f382006-04-29 16:06:31 +00001520 if (flag == 0) /* Time cache */
Glenn L McGrath07085852003-10-09 07:28:22 +00001521 {
1522 /* Calculate a correction factor for the basic
1523 * overhead of doing a read() from the buffer cache.
1524 * To do this, we read the data once to "cache it" and
1525 * to force full preallocation of our timing buffer,
1526 * and then we re-read it 10 times while timing it.
1527 *
1528 * getitimer() is used rather than gettimeofday() because
1529 * it is much more consistent (on my machine, at least).
1530 */
1531 setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
Rob Landleya3e4f382006-04-29 16:06:31 +00001532 if (seek_to_zero(fd))
Glenn L McGrath07085852003-10-09 07:28:22 +00001533 return;
Rob Landleya3e4f382006-04-29 16:06:31 +00001534 if (read_big_block(fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001535 return;
1536 printf(" Timing buffer-cache reads: ");
1537 fflush(stdout);
Eric Andersen3443bd72003-07-22 07:30:36 +00001538
Glenn L McGrath07085852003-10-09 07:28:22 +00001539 /* Clear out the device request queues & give them time to complete */
1540 sync_and_sleep(1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001541
Glenn L McGrath07085852003-10-09 07:28:22 +00001542 /* Time re-reading from the buffer-cache */
1543 getitimer(ITIMER_REAL, &e1);
1544 for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i)
1545 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001546 if (seek_to_zero(fd))
Glenn L McGrath07085852003-10-09 07:28:22 +00001547 goto quit;
Rob Landleya3e4f382006-04-29 16:06:31 +00001548 if (read_big_block(fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001549 goto quit;
1550 }
1551 getitimer(ITIMER_REAL, &e2);
1552 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 +00001553
Glenn L McGrath07085852003-10-09 07:28:22 +00001554 /* Now remove the lseek() from the correction factor */
1555 getitimer(ITIMER_REAL, &e1);
1556 for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i)
1557 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001558 if (seek_to_zero(fd))
Glenn L McGrath07085852003-10-09 07:28:22 +00001559 goto quit;
1560 }
1561 getitimer(ITIMER_REAL, &e2);
1562 correction -= (e1.it_value.tv_sec - e2.it_value.tv_sec)
1563 + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
Eric Andersen50af12d2003-08-06 08:47:59 +00001564
Glenn L McGrath07085852003-10-09 07:28:22 +00001565 if ((BUFCACHE_FACTOR * timing_MB) >= correction) /* more than 1MB/s */
Eric Andersen50af12d2003-08-06 08:47:59 +00001566 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",
Glenn L McGrath07085852003-10-09 07:28:22 +00001567 (BUFCACHE_FACTOR * timing_MB), correction,
1568 (BUFCACHE_FACTOR * timing_MB) / correction);
Eric Andersen50af12d2003-08-06 08:47:59 +00001569 else
1570 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",
Glenn L McGrath07085852003-10-09 07:28:22 +00001571 (BUFCACHE_FACTOR * timing_MB), correction,
1572 (BUFCACHE_FACTOR * timing_MB) / correction * 1024);
1573 correction /= BUFCACHE_FACTOR;
1574
1575 flush_buffer_cache(fd);
1576 sleep(1);
Eric Andersen50af12d2003-08-06 08:47:59 +00001577 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001578 else /* Time device */
1579 {
1580 printf(" Timing buffered disk reads: ");
1581 fflush(stdout);
1582
1583 /*
1584 * getitimer() is used rather than gettimeofday() because
1585 * it is much more consistent (on my machine, at least).
1586 */
1587 setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
1588
1589 /* Now do the timings for real */
1590 getitimer(ITIMER_REAL, &e1);
1591 for (i = TIMING_BUF_COUNT; i > 0; --i)
1592 {
Rob Landleya3e4f382006-04-29 16:06:31 +00001593 if (read_big_block(fd, buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001594 goto quit;
1595 }
1596 getitimer(ITIMER_REAL, &e2);
1597
1598 elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
1599
1600 if (timing_MB >= elapsed) /* more than 1MB/s */
1601 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",timing_MB, elapsed, timing_MB / elapsed);
1602 else
1603 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",timing_MB, elapsed, timing_MB / elapsed * 1024);
1604
1605 /*"Hmm.. suspicious results: probably not enough free memory for a proper test.");*/
1606 if (elapsed <= (correction * 2))
1607 bb_error_msg(bb_msg_memory_exhausted);
1608
1609#if 0 /* the "estimate" is just plain wrong for many systems.. */
1610 else if (correction != 0.0) {
1611 printf(" Estimating raw driver speed: ");
1612 elapsed -= correction;
1613 if (timing_MB >= elapsed) /* more than 1MB/s */
1614 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",
1615 timing_MB, elapsed, timing_MB / elapsed);
1616 else
1617 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",
1618 timing_MB, elapsed, timing_MB / elapsed * 1024);
1619 }
Eric Andersen50af12d2003-08-06 08:47:59 +00001620#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001621 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001622quit:
1623 if (-1 == shmdt(buf))
Rob Landleya3e4f382006-04-29 16:06:31 +00001624 bb_error_msg(bb_msg_shared_mem,"detach"); /*"could not detach sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001625}
1626
Eric Andersen3443bd72003-07-22 07:30:36 +00001627static void on_off (unsigned int value)
1628{
1629 printf(value ? " (on)\n" : " (off)\n");
1630}
1631
1632#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Rob Landleya3e4f382006-04-29 16:06:31 +00001633static void bus_state_value(unsigned int value)
Eric Andersen3443bd72003-07-22 07:30:36 +00001634{
1635 const char *string;
1636
Glenn L McGrath07085852003-10-09 07:28:22 +00001637 switch (value)
1638 {
1639 case BUSSTATE_ON:
1640 string = " (on)\n";
1641 break;
1642 case BUSSTATE_OFF:
1643 string = " (off)\n";
1644 break;
1645 case BUSSTATE_TRISTATE:
1646 string = " (tristate)\n";
1647 break;
1648 default:
1649 string = " (unknown: %d)\n";
1650 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001651 }
1652 printf(string, value);
1653}
1654#endif
1655
1656#ifdef HDIO_DRIVE_CMD
Rob Landleya3e4f382006-04-29 16:06:31 +00001657static void interpret_standby(unsigned int standby)
Eric Andersen3443bd72003-07-22 07:30:36 +00001658{
1659 printf(" (");
Glenn L McGrath07085852003-10-09 07:28:22 +00001660 switch(standby)
1661 {
1662 case 0:
1663 printf("off");
1664 break;
1665 case 252:
1666 printf("21 minutes");
1667 break;
1668 case 253:
1669 printf("vendor-specific");
1670 break;
1671 case 254:
1672 printf("?reserved");
1673 break;
1674 case 255:
1675 printf("21 minutes + 15 seconds");
1676 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001677 default:
Glenn L McGrath07085852003-10-09 07:28:22 +00001678 if (standby <= 240)
1679 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001680 unsigned int secs = standby * 5;
1681 unsigned int mins = secs / 60;
1682 secs %= 60;
Glenn L McGrath07085852003-10-09 07:28:22 +00001683 if_printf(mins,"%u minutes", mins);
1684 if_printf((mins && secs)," + ");
1685 if_printf(secs,"%u seconds", secs);
1686 }
1687 else if (standby <= 251)
1688 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001689 unsigned int mins = (standby - 240) * 30;
1690 unsigned int hrs = mins / 60;
1691 mins %= 60;
Glenn L McGrath07085852003-10-09 07:28:22 +00001692 if_printf(hrs,"%u hours", hrs);
1693 if_printf((hrs && mins)," + ");
1694 if_printf(mins,"%u minutes", mins);
1695 }
1696 else
Eric Andersen3443bd72003-07-22 07:30:36 +00001697 printf("illegal value");
1698 break;
1699 }
1700 printf(")\n");
1701}
1702
1703struct xfermode_entry {
1704 int val;
1705 const char *name;
1706};
1707
1708static const struct xfermode_entry xfermode_table[] = {
1709 { 8, "pio0" },
1710 { 9, "pio1" },
1711 { 10, "pio2" },
1712 { 11, "pio3" },
1713 { 12, "pio4" },
1714 { 13, "pio5" },
1715 { 14, "pio6" },
1716 { 15, "pio7" },
1717 { 16, "sdma0" },
1718 { 17, "sdma1" },
1719 { 18, "sdma2" },
1720 { 19, "sdma3" },
1721 { 20, "sdma4" },
1722 { 21, "sdma5" },
1723 { 22, "sdma6" },
1724 { 23, "sdma7" },
1725 { 32, "mdma0" },
1726 { 33, "mdma1" },
1727 { 34, "mdma2" },
1728 { 35, "mdma3" },
1729 { 36, "mdma4" },
1730 { 37, "mdma5" },
1731 { 38, "mdma6" },
1732 { 39, "mdma7" },
1733 { 64, "udma0" },
1734 { 65, "udma1" },
1735 { 66, "udma2" },
1736 { 67, "udma3" },
1737 { 68, "udma4" },
1738 { 69, "udma5" },
1739 { 70, "udma6" },
1740 { 71, "udma7" },
1741 { 0, NULL }
1742};
1743
1744static int translate_xfermode(char * name)
1745{
Glenn L McGrath07085852003-10-09 07:28:22 +00001746 const struct xfermode_entry *tmp;
1747 char *endptr;
1748 int val = -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001749
1750
Glenn L McGrath07085852003-10-09 07:28:22 +00001751 for (tmp = xfermode_table; tmp->name != NULL; ++tmp)
1752 {
1753 if (!strcmp(name, tmp->name))
1754 return tmp->val;
Eric Andersen3443bd72003-07-22 07:30:36 +00001755
Glenn L McGrath07085852003-10-09 07:28:22 +00001756 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001757
Glenn L McGrath07085852003-10-09 07:28:22 +00001758 val = strtol(name, &endptr, 10);
1759 if (*endptr == '\0')
1760 return val;
1761
1762 return -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001763}
1764
Rob Landleya3e4f382006-04-29 16:06:31 +00001765static void interpret_xfermode(unsigned int xfermode)
Eric Andersen3443bd72003-07-22 07:30:36 +00001766{
1767 printf(" (");
1768 switch(xfermode) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001769 case 0:
1770 printf("default PIO mode");
1771 break;
1772 case 1:
1773 printf("default PIO mode, disable IORDY");
1774 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001775 case 8:
1776 case 9:
1777 case 10:
1778 case 11:
1779 case 12:
1780 case 13:
1781 case 14:
Glenn L McGrath07085852003-10-09 07:28:22 +00001782 case 15:
1783 printf("PIO flow control mode%u", xfermode-8);
1784 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001785 case 16:
1786 case 17:
1787 case 18:
1788 case 19:
1789 case 20:
1790 case 21:
1791 case 22:
Glenn L McGrath07085852003-10-09 07:28:22 +00001792 case 23:
1793 printf("singleword DMA mode%u", xfermode-16);
1794 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001795 case 32:
1796 case 33:
1797 case 34:
1798 case 35:
1799 case 36:
1800 case 37:
1801 case 38:
Glenn L McGrath07085852003-10-09 07:28:22 +00001802 case 39:
1803 printf("multiword DMA mode%u", xfermode-32);
1804 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001805 case 64:
1806 case 65:
1807 case 66:
1808 case 67:
1809 case 68:
1810 case 69:
1811 case 70:
Glenn L McGrath07085852003-10-09 07:28:22 +00001812 case 71:
1813 printf("UltraDMA mode%u", xfermode-64);
1814 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001815 default:
Glenn L McGrath07085852003-10-09 07:28:22 +00001816 printf("unknown, probably not valid");
1817 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001818 }
1819 printf(")\n");
1820}
1821#endif /* HDIO_DRIVE_CMD */
1822
Rob Landleya3e4f382006-04-29 16:06:31 +00001823static void process_dev(char *devname)
Eric Andersen3443bd72003-07-22 07:30:36 +00001824{
1825 int fd;
1826 static long parm, multcount;
Eric Andersen3443bd72003-07-22 07:30:36 +00001827#ifndef HDIO_DRIVE_CMD
1828 int force_operation = 0;
1829#endif
Rob Landleye5b281f2006-04-29 15:49:18 +00001830 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
1831
Rob Landleya3e4f382006-04-29 16:06:31 +00001832 fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK);
1833 if_printf(!quiet, "\n%s:\n", devname);
Eric Andersen3443bd72003-07-22 07:30:36 +00001834
Glenn L McGrath07085852003-10-09 07:28:22 +00001835 if (set_readahead)
1836 {
Eric Andersenf828da02004-07-20 22:53:59 +00001837 if_printf(get_readahead," setting fs readahead to %ld\n", Xreadahead);
1838 bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001839 }
1840#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001841 if (unregister_hwif)
1842 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001843 printf(" attempting to unregister hwif#%u\n", hwif);
Eric Andersena68ea1c2006-01-30 22:48:39 +00001844 bb_ioctl(fd, HDIO_UNREGISTER_HWIF,(int *)(unsigned long)hwif,"HDIO_UNREGISTER_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001845 }
1846#endif
1847#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001848 if (scan_hwif)
1849 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001850 printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq);
1851 args[0] = hwif_data;
1852 args[1] = hwif_ctrl;
1853 args[2] = hwif_irq;
Glenn L McGrath07085852003-10-09 07:28:22 +00001854 bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001855 }
1856#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001857 if (set_piomode)
1858 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001859 if (noisy_piomode)
1860 {
1861 printf(" attempting to ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001862 if (piomode == 255)
Glenn L McGrath07085852003-10-09 07:28:22 +00001863 printf("auto-tune PIO mode\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001864 else if (piomode < 100)
Glenn L McGrath07085852003-10-09 07:28:22 +00001865 printf("set PIO mode to %d\n", piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001866 else if (piomode < 200)
Glenn L McGrath07085852003-10-09 07:28:22 +00001867 printf("set MDMA mode to %d\n", (piomode-100));
Eric Andersen3443bd72003-07-22 07:30:36 +00001868 else
Glenn L McGrath07085852003-10-09 07:28:22 +00001869 printf("set UDMA mode to %d\n", (piomode-200));
Eric Andersen3443bd72003-07-22 07:30:36 +00001870 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00001871 bb_ioctl(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode, "HDIO_SET_PIO_MODE");
Eric Andersen3443bd72003-07-22 07:30:36 +00001872 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001873 if (set_io32bit)
1874 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001875 if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit);
1876 bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001877 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001878 if (set_mult)
1879 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001880 if_printf(get_mult, " setting multcount to %ld\n", mult);
Rob Landleya3e4f382006-04-29 16:06:31 +00001881 if (ioctl(fd, HDIO_SET_MULTCOUNT, mult))
Eric Andersen06d4ec22004-03-19 10:53:52 +00001882 bb_perror_msg("HDIO_SET_MULTCOUNT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001883#ifndef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001884 else
1885 force_operation = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001886#endif
1887 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001888 if (set_readonly)
1889 {
1890 if_printf_on_off(get_readonly," setting readonly to %ld", readonly);
1891 bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001892 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001893 if (set_unmask)
1894 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001895 if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask);
1896 bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR");
Eric Andersen3443bd72003-07-22 07:30:36 +00001897 }
Eric Andersen0a57a792003-08-06 08:57:35 +00001898#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Glenn L McGrath07085852003-10-09 07:28:22 +00001899 if (set_dma)
1900 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001901 if_printf_on_off(get_dma," setting using_dma to %ld", dma);
1902 bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00001903 }
Eric Andersen0a57a792003-08-06 08:57:35 +00001904#endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
Glenn L McGrath07085852003-10-09 07:28:22 +00001905 if (set_dma_q)
1906 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001907 if_printf_on_off(get_dma_q," setting DMA queue_depth to %ld", dma_q);
1908 bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00001909 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001910 if (set_nowerr)
1911 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001912 if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr);
1913 bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR");
Eric Andersen3443bd72003-07-22 07:30:36 +00001914 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001915 if (set_keep)
1916 {
Glenn L McGrath07085852003-10-09 07:28:22 +00001917 if_printf_on_off(get_keep," setting keep_settings to %ld", keep);
1918 bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS");
Eric Andersen3443bd72003-07-22 07:30:36 +00001919 }
1920#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001921 if (set_doorlock)
1922 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001923 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
Glenn L McGrath07085852003-10-09 07:28:22 +00001924 if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock);
1925 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001926 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001927 if (set_dkeep)
1928 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001929 /* lock/unlock the drive's "feature" settings */
Glenn L McGrath07085852003-10-09 07:28:22 +00001930 if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep);
Eric Andersen3443bd72003-07-22 07:30:36 +00001931 args[2] = dkeep ? 0x66 : 0xcc;
Glenn L McGrath07085852003-10-09 07:28:22 +00001932 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001933 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001934 if (set_defects)
1935 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001936 args[2] = defects ? 0x04 : 0x84;
Glenn L McGrath07085852003-10-09 07:28:22 +00001937 if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects);
1938 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001939 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001940 if (set_prefetch)
1941 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001942 args[1] = prefetch;
Rob Landleye5b281f2006-04-29 15:49:18 +00001943 args[2] = 0xab;
Glenn L McGrath07085852003-10-09 07:28:22 +00001944 if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch);
1945 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001946 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001947 if (set_xfermode)
1948 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001949 args[1] = xfermode_requested;
Rob Landleye5b281f2006-04-29 15:49:18 +00001950 args[2] = 3;
Glenn L McGrath07085852003-10-09 07:28:22 +00001951 if (get_xfermode)
1952 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001953 printf(" setting xfermode to %d", xfermode_requested);
1954 interpret_xfermode(xfermode_requested);
1955 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001956 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001957 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001958 if (set_lookahead)
1959 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001960 args[2] = lookahead ? 0xaa : 0x55;
Glenn L McGrath07085852003-10-09 07:28:22 +00001961 if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead);
1962 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001963 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001964 if (set_apmmode)
1965 {
Eric Andersenb2aa7762004-04-05 13:08:08 +00001966 apmmode=check_if_min_and_set_val(apmmode,1);
1967 apmmode=check_if_maj_and_set_val(apmmode,255);
Glenn L McGrath07085852003-10-09 07:28:22 +00001968 if_printf(get_apmmode," setting APM level to");
1969 if (apmmode==255)
1970 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001971 /* disable Advanced Power Management */
Glenn L McGrath07085852003-10-09 07:28:22 +00001972 args[2] = 0x85; /* feature register */
1973 if_printf(get_apmmode," disabled\n");
1974 }
1975 else
1976 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001977 /* set Advanced Power Management mode */
Glenn L McGrath07085852003-10-09 07:28:22 +00001978 args[2] = 0x05; /* feature register */
Eric Andersen3443bd72003-07-22 07:30:36 +00001979 args[1] = apmmode; /* sector count register */
Glenn L McGrath07085852003-10-09 07:28:22 +00001980 if_printf(get_apmmode," 0x%02lX (%ld)\n",apmmode,apmmode);
1981 }
1982 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD");
Eric Andersen3443bd72003-07-22 07:30:36 +00001983 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001984 if (set_wcache)
1985 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001986#ifdef DO_FLUSHCACHE
1987#ifndef WIN_FLUSHCACHE
1988#define WIN_FLUSHCACHE 0xe7
1989#endif
Rob Landleye5b281f2006-04-29 15:49:18 +00001990 static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0};
Eric Andersen3443bd72003-07-22 07:30:36 +00001991#endif /* DO_FLUSHCACHE */
Eric Andersen3443bd72003-07-22 07:30:36 +00001992 args[2] = wcache ? 0x02 : 0x82;
Glenn L McGrath07085852003-10-09 07:28:22 +00001993 if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache);
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 */
Glenn L McGrath07085852003-10-09 07:28:22 +00001998 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001999#ifdef DO_FLUSHCACHE
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002000 if (!wcache)
2001 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002002#endif /* DO_FLUSHCACHE */
2003 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002004 if (set_standbynow)
2005 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002006#ifndef WIN_STANDBYNOW1
2007#define WIN_STANDBYNOW1 0xE0
2008#endif
2009#ifndef WIN_STANDBYNOW2
2010#define WIN_STANDBYNOW2 0x94
2011#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002012 if_printf(get_standbynow," issuing standby command\n");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002013 args[0] = WIN_STANDBYNOW1;
2014 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002015 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002016 if (set_sleepnow)
2017 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002018#ifndef WIN_SLEEPNOW1
2019#define WIN_SLEEPNOW1 0xE6
2020#endif
2021#ifndef WIN_SLEEPNOW2
2022#define WIN_SLEEPNOW2 0x99
2023#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002024 if_printf(get_sleepnow," issuing sleep command\n");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002025 args[0] = WIN_SLEEPNOW1;
2026 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002027 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002028 if (set_seagate)
2029 {
Rob Landleye5b281f2006-04-29 15:49:18 +00002030 args[0] = 0xfb;
Glenn L McGrath07085852003-10-09 07:28:22 +00002031 if_printf(get_seagate," disabling Seagate auto powersaving mode\n");
2032 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002033 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002034 if (set_standby)
2035 {
Rob Landleye5b281f2006-04-29 15:49:18 +00002036 args[0] = WIN_SETIDLE1;
2037 args[1] = standby_requested;
Glenn L McGrath07085852003-10-09 07:28:22 +00002038 if (get_standby)
2039 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002040 printf(" setting standby to %lu", standby_requested);
2041 interpret_standby(standby_requested);
2042 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002043 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002044 }
2045#else /* HDIO_DRIVE_CMD */
Glenn L McGrath07085852003-10-09 07:28:22 +00002046 if (force_operation)
2047 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002048 char buf[512];
2049 flush_buffer_cache(fd);
2050 if (-1 == read(fd, buf, sizeof(buf)))
Glenn L McGrath07085852003-10-09 07:28:22 +00002051 bb_error_msg("access failed");
Eric Andersen3443bd72003-07-22 07:30:36 +00002052 }
2053#endif /* HDIO_DRIVE_CMD */
2054
2055 if (!flagcount)
2056 verbose = 1;
2057
Rob Landley6389ff12006-05-01 19:28:53 +00002058 if (verbose || get_mult || get_identity)
Glenn L McGrath07085852003-10-09 07:28:22 +00002059 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002060 multcount = -1;
Glenn L McGrath07085852003-10-09 07:28:22 +00002061 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount))
2062 {
Rob Landley6389ff12006-05-01 19:28:53 +00002063 if (verbose || get_mult)
Eric Andersen06d4ec22004-03-19 10:53:52 +00002064 bb_perror_msg("HDIO_GET_MULTCOUNT");
Glenn L McGrath07085852003-10-09 07:28:22 +00002065 }
2066 else if (verbose | get_mult)
2067 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002068 printf(" multcount = %2ld", multcount);
2069 on_off(multcount);
2070 }
2071 }
Rob Landley6389ff12006-05-01 19:28:53 +00002072 if (verbose || get_io32bit)
Glenn L McGrath07085852003-10-09 07:28:22 +00002073 {
Rob Landleya3e4f382006-04-29 16:06:31 +00002074 if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT"))
Glenn L McGrath07085852003-10-09 07:28:22 +00002075 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002076 printf(" IO_support =%3ld (", parm);
Glenn L McGrath07085852003-10-09 07:28:22 +00002077 switch (parm)
2078 {
2079 case 0:
2080 printf("default ");
2081 case 2:
2082 printf("16-bit)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002083 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002084 case 1:
2085 printf("32-bit)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002086 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002087 case 3:
2088 printf("32-bit w/sync)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002089 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002090 case 8:
2091 printf("Request-Queue-Bypass)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002092 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002093 default:
2094 printf("\?\?\?)\n");
2095 /*esac*/
Eric Andersen3443bd72003-07-22 07:30:36 +00002096 }
2097 }
2098 }
Rob Landley6389ff12006-05-01 19:28:53 +00002099 if (verbose || get_unmask)
Glenn L McGrath07085852003-10-09 07:28:22 +00002100 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002101 bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm,
2102 "HDIO_GET_UNMASKINTR"," unmaskirq = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002103 }
2104
Glenn L McGrath07085852003-10-09 07:28:22 +00002105
Eric Andersen0a57a792003-08-06 08:57:35 +00002106#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Rob Landley6389ff12006-05-01 19:28:53 +00002107 if (verbose || get_dma) {
Rob Landleya3e4f382006-04-29 16:06:31 +00002108 if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA"))
Glenn L McGrath07085852003-10-09 07:28:22 +00002109 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002110 printf(" using_dma = %2ld", parm);
2111 if (parm == 8)
2112 printf(" (DMA-Assisted-PIO)\n");
2113 else
2114 on_off(parm);
2115 }
2116 }
2117#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002118 if (get_dma_q)
2119 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002120 bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm,
2121 "HDIO_GET_QDMA"," queue_depth = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002122 }
Rob Landley6389ff12006-05-01 19:28:53 +00002123 if (verbose || get_keep)
Glenn L McGrath07085852003-10-09 07:28:22 +00002124 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002125 bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm,
2126 "HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002127 }
2128
Glenn L McGrath07085852003-10-09 07:28:22 +00002129 if (get_nowerr)
2130 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002131 bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm,
2132 " HDIO_GET_NOWERR"," nowerr = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002133 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002134 if (verbose || get_readonly)
2135 {
2136 bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm,
2137 " BLKROGET"," readonly = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002138 }
Rob Landley6389ff12006-05-01 19:28:53 +00002139 if (verbose || get_readahead)
Glenn L McGrath07085852003-10-09 07:28:22 +00002140 {
2141 bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm,
2142 " BLKRAGET"," readahead = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002143 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002144 if (verbose || get_geom)
2145 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002146 if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE"))
2147 {
Rob Landley2584e9b2006-05-03 20:00:00 +00002148 struct hd_geometry g;
2149
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002150 if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO"))
Rob Landley2584e9b2006-05-03 20:00:00 +00002151 printf(" geometry = %u/%u/%u, sectors = %ld, start = %ld\n",
2152 g.cylinders, g.heads, g.sectors, parm, g.start);
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002153 }
Eric Andersen3443bd72003-07-22 07:30:36 +00002154 }
2155#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00002156 if (get_powermode)
2157 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002158#ifndef WIN_CHECKPOWERMODE1
2159#define WIN_CHECKPOWERMODE1 0xE5
2160#endif
2161#ifndef WIN_CHECKPOWERMODE2
2162#define WIN_CHECKPOWERMODE2 0x98
2163#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00002164 const char *state;
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002165
Rob Landleye5b281f2006-04-29 15:49:18 +00002166 args[0] = WIN_CHECKPOWERMODE1;
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002167 if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0))
Glenn L McGrath07085852003-10-09 07:28:22 +00002168 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002169 if (errno != EIO || args[0] != 0 || args[1] != 0)
2170 state = "unknown";
2171 else
2172 state = "sleeping";
Eric Andersen3443bd72003-07-22 07:30:36 +00002173 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002174 else
2175 state = (args[2] == 255) ? "active/idle" : "standby";
2176
Eric Andersen3443bd72003-07-22 07:30:36 +00002177 printf(" drive state is: %s\n", state);
2178 }
2179#endif
2180#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
Glenn L McGrath07085852003-10-09 07:28:22 +00002181 if (perform_reset)
2182 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002183 bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET");
Eric Andersen3443bd72003-07-22 07:30:36 +00002184 }
2185#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
2186#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002187 if (perform_tristate)
2188 {
Rob Landleye5b281f2006-04-29 15:49:18 +00002189 args[0] = 0;
2190 args[1] = tristate;
Glenn L McGrath07085852003-10-09 07:28:22 +00002191 bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00002192 }
2193#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
2194#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +00002195 if (get_identity)
2196 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002197 static struct hd_driveid id;
2198
Glenn L McGrath07085852003-10-09 07:28:22 +00002199 if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
2200 {
2201 if (multcount != -1)
2202 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002203 id.multsect = multcount;
2204 id.multsect_valid |= 1;
Glenn L McGrath07085852003-10-09 07:28:22 +00002205 }
2206 else
Eric Andersen3443bd72003-07-22 07:30:36 +00002207 id.multsect_valid &= ~1;
2208 dump_identity(&id);
Glenn L McGrath07085852003-10-09 07:28:22 +00002209 }
2210 else if (errno == -ENOMSG)
Eric Andersen3443bd72003-07-22 07:30:36 +00002211 printf(" no identification info available\n");
2212 else
Eric Andersen06d4ec22004-03-19 10:53:52 +00002213 bb_perror_msg("HDIO_GET_IDENTITY");
Eric Andersen3443bd72003-07-22 07:30:36 +00002214 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002215
2216 if (get_IDentity)
2217 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002218 unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */
Eric Andersen3443bd72003-07-22 07:30:36 +00002219 unsigned i;
Glenn L McGrath07085852003-10-09 07:28:22 +00002220
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002221 memset(args1, 0, sizeof(args1));
2222 args1[0] = WIN_IDENTIFY;
2223 args1[3] = 1;
Rob Landley0f0b6452006-05-03 18:28:06 +00002224 if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) {
2225 for (i=0; i<(sizeof args1)/2; i+=2)
2226 __le16_to_cpus((uint16_t *)(&args1[i]));
2227 identify((void *)&args1[4]);
2228 }
Eric Andersen3443bd72003-07-22 07:30:36 +00002229 }
2230#endif
2231#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002232 if (set_busstate)
2233 {
Glenn L McGrath07085852003-10-09 07:28:22 +00002234 if (get_busstate)
2235 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002236 printf(" setting bus state to %d", busstate);
2237 bus_state_value(busstate);
2238 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00002239 bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE");
Eric Andersen3443bd72003-07-22 07:30:36 +00002240 }
2241#endif
2242#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002243 if (get_busstate)
2244 {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00002245 if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE"))
Glenn L McGrath07085852003-10-09 07:28:22 +00002246 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002247 printf(" busstate = %2ld", parm);
2248 bus_state_value(parm);
2249 }
2250 }
2251#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002252 if (reread_partn)
2253 bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART");
2254
Eric Andersen3443bd72003-07-22 07:30:36 +00002255
2256 if (do_ctimings)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00002257 do_time(0,fd); /*time cache */
Eric Andersen3443bd72003-07-22 07:30:36 +00002258 if (do_timings)
Glenn L McGrath07085852003-10-09 07:28:22 +00002259 do_time(1,fd); /*time device */
Eric Andersen3443bd72003-07-22 07:30:36 +00002260 if (do_flush)
Rob Landleya3e4f382006-04-29 16:06:31 +00002261 flush_buffer_cache(fd);
2262 close(fd);
Eric Andersen3443bd72003-07-22 07:30:36 +00002263}
2264
Eric Andersen06d4ec22004-03-19 10:53:52 +00002265static char * GET_NUMBER(char *p, unsigned long *flag, unsigned long *num)
2266{
2267 *num = 0;
2268 while (isdigit(*p)) {
2269 *flag = 1;
2270 *num = (*num * 10) + (*p++ - '0');
2271 }
2272 return p;
2273}
2274
2275static char * GET_STRING(char *p, unsigned long *flag, int *num)
2276{
2277 char *tmpstr;
2278 char name[32];
2279 tmpstr = name;
2280 tmpstr[0] = '\0';
2281 while (isalnum(*p) && (tmpstr - name) < 31) {
2282 tmpstr[0] = *p++;
2283 tmpstr[1] = '\0';
2284 ++tmpstr;
2285 }
2286 *num = translate_xfermode(name);
2287 if (*num == -1)
2288 *flag = 0;
2289 else
2290 *flag = 1;
2291 return p;
2292}
2293
Eric Andersen3443bd72003-07-22 07:30:36 +00002294#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Rob Landleya3e4f382006-04-29 16:06:31 +00002295static int fromhex(unsigned char c)
Eric Andersen3443bd72003-07-22 07:30:36 +00002296{
2297 if (c >= 'a' && c <= 'f')
2298 return 10 + (c - 'a');
2299 if (c >= '0' && c <= '9')
2300 return (c - '0');
2301 bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
2302}
2303
Rob Landley0f0b6452006-05-03 18:28:06 +00002304static void identify_from_stdin(void)
Eric Andersen3443bd72003-07-22 07:30:36 +00002305{
2306 unsigned short sbuf[800];
2307 unsigned char buf[1600], *b = (unsigned char *)buf;
2308 int i, count = read(0, buf, 1280);
2309
2310 if (count != 1280)
2311 bb_error_msg_and_die("read(1280 bytes) failed (rc=%d)", count);
Glenn L McGrath07085852003-10-09 07:28:22 +00002312 for (i = 0; count >= 4; ++i)
2313 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002314 sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]);
2315 __le16_to_cpus((uint16_t *)(&sbuf[i]));
2316 b += 5;
2317 count -= 5;
2318 }
Rob Landley6389ff12006-05-01 19:28:53 +00002319 identify(sbuf);
Eric Andersen3443bd72003-07-22 07:30:36 +00002320}
2321#endif
2322
Eric Andersenb2aa7762004-04-05 13:08:08 +00002323static void missing_arg(int arg, char c, char* add)
2324{
2325 if (!arg)
2326 bb_error_msg("-%c: missing value %s", c, (add!=NULL)? add :"");
2327}
2328
Eric Andersen3443bd72003-07-22 07:30:36 +00002329/* our main() routine: */
2330int hdparm_main(int argc, char **argv)
2331{
2332 char c, *p;
Eric Andersen3443bd72003-07-22 07:30:36 +00002333
2334 ++argv;
2335 if (!--argc)
2336 bb_show_usage();
Glenn L McGrath07085852003-10-09 07:28:22 +00002337
2338 while (argc--)
2339 {
Rob Landley0f0b6452006-05-03 18:28:06 +00002340 if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !strcmp("-Istdin", *argv))
2341 identify_from_stdin();
Eric Andersen3443bd72003-07-22 07:30:36 +00002342 p = *argv++;
Glenn L McGrath07085852003-10-09 07:28:22 +00002343 if (*p == '-')
2344 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002345 if (!*++p)
2346 bb_show_usage();
Glenn L McGrath07085852003-10-09 07:28:22 +00002347 while ((c = *p++))
2348 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002349 ++flagcount;
Glenn L McGrath07085852003-10-09 07:28:22 +00002350 switch (c)
2351 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002352 case 'V':
Glenn L McGrath07085852003-10-09 07:28:22 +00002353 /*bb_error_msg_and_die("%s", VERSION);*/
2354 /* We have to return 0 here and not 1 */
2355 printf("%s %s\n",bb_applet_name, VERSION);
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00002356 return EXIT_SUCCESS;
Eric Andersen3443bd72003-07-22 07:30:36 +00002357 case 'v':
2358 verbose = 1;
2359 break;
2360#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
2361 case 'I':
2362 get_IDentity = 1;
2363 break;
2364 case 'i':
2365 get_identity = 1;
2366 break;
2367#endif
2368 case 'g':
2369 get_geom = 1;
2370 break;
2371 case 'f':
2372 do_flush = 1;
2373 break;
2374 case 'q':
2375 quiet = 1;
2376 noisy = 0;
2377 break;
2378 case 'u':
2379 get_unmask = noisy;
2380 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002381 if (!*p && argc && isdigit(**argv))
2382 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002383 if ((set_unmask = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002384 unmask = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002385 break;
Eric Andersen0a57a792003-08-06 08:57:35 +00002386#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Eric Andersen3443bd72003-07-22 07:30:36 +00002387 case 'd':
2388 get_dma = noisy;
2389 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002390 if (!*p && argc && isdigit(**argv))
2391 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002392 if ((set_dma = set_flag(p,'9'))==1)
Eric Andersen3443bd72003-07-22 07:30:36 +00002393 dma = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002394 break;
Eric Andersen0a57a792003-08-06 08:57:35 +00002395#endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
Eric Andersen3443bd72003-07-22 07:30:36 +00002396 case 'n':
2397 get_nowerr = noisy;
2398 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002399 if (!*p && argc && isdigit(**argv))
2400 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002401 if ((set_nowerr = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002402 nowerr = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002403 break;
2404 case 'p':
2405 noisy_piomode = noisy;
2406 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002407 if (!*p && argc && isalnum(**argv))
2408 p = *argv++, --argc;
2409 p=GET_STRING(p,&set_piomode,&piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00002410 break;
2411 case 'r':
2412 get_readonly = noisy;
2413 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002414 if (!*p && argc && isdigit(**argv))
2415 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002416 if ((set_readonly = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002417 readonly = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002418 break;
2419 case 'm':
2420 get_mult = noisy;
2421 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002422 if (!*p && argc && isalnum(**argv))
2423 p = *argv++, --argc;
2424 p=GET_NUMBER(p,&set_mult,&mult);
Eric Andersen3443bd72003-07-22 07:30:36 +00002425 break;
2426 case 'c':
2427 get_io32bit = noisy;
2428 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002429 if (!*p && argc && isalnum(**argv))
2430 p = *argv++, --argc;
2431 p=GET_NUMBER(p,&set_io32bit,&io32bit);
Eric Andersen3443bd72003-07-22 07:30:36 +00002432 break;
2433#ifdef HDIO_DRIVE_CMD
2434 case 'S':
2435 get_standby = noisy;
2436 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002437 if (!*p && argc && isalnum(**argv))
2438 p = *argv++, --argc;
2439 p=GET_NUMBER(p,&set_standby,&standby_requested);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002440 missing_arg(set_standby, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002441 break;
2442
2443 case 'D':
2444 get_defects = noisy;
2445 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002446 if (!*p && argc && isalnum(**argv))
2447 p = *argv++, --argc;
2448 p=GET_NUMBER(p,&set_defects,&defects);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002449 missing_arg(set_defects, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002450 break;
2451 case 'P':
2452 get_prefetch = noisy;
2453 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002454 if (!*p && argc && isalnum(**argv))
2455 p = *argv++, --argc;
2456 p=GET_NUMBER(p,&set_prefetch,&prefetch);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002457 missing_arg(set_prefetch, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002458 break;
2459
2460 case 'X':
2461 get_xfermode = noisy;
2462 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002463 if (!*p && argc && isalnum(**argv))
2464 p = *argv++, --argc;
2465 p=GET_STRING(p,&set_xfermode,&xfermode_requested);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002466 missing_arg(set_xfermode, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002467 break;
2468
2469 case 'K':
2470 get_dkeep = noisy;
2471 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002472 if (!*p && argc && isdigit(**argv))
2473 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002474 if ((set_dkeep = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002475 dkeep = *p++ - '0';
2476 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002477 goto missing_arg_error;
Eric Andersen3443bd72003-07-22 07:30:36 +00002478 break;
2479
2480 case 'A':
2481 get_lookahead = 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_lookahead = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002486 lookahead = *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 'L':
2492 get_doorlock = 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_doorlock = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002497 doorlock = *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 'W':
2503 get_wcache = 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_wcache = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002508 wcache = *p++ - '0';
2509 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002510missing_arg_error:
2511 missing_arg(1, c, "(0/1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002512 break;
2513
2514 case 'C':
2515 get_powermode = noisy;
2516 noisy = 1;
2517 break;
2518
2519 case 'y':
2520 get_standbynow = noisy;
2521 noisy = 1;
2522 set_standbynow = 1;
2523 break;
2524
2525 case 'Y':
2526 get_sleepnow = noisy;
2527 noisy = 1;
2528 set_sleepnow = 1;
2529 break;
2530
2531 case 'z':
2532 reread_partn = 1;
2533 break;
2534
2535 case 'Z':
2536 get_seagate = noisy;
2537 noisy = 1;
2538 set_seagate = 1;
2539 break;
2540#endif /* HDIO_DRIVE_CMD */
2541 case 'k':
2542 get_keep = noisy;
2543 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002544 if (!*p && argc && isdigit(**argv))
2545 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002546 if ((set_keep = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002547 keep = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002548 break;
2549#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
2550 case 'U':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002551 if (!*p && argc && isdigit(**argv))
2552 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002553 if (! p)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002554 goto expected_hwif_error; /* "expected hwif_nr" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002555
2556 sscanf(p++, "%i", &hwif);
2557
2558 unregister_hwif = 1;
2559 break;
2560#endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF */
2561#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
2562 case 'R':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002563 if (!*p && argc && isdigit(**argv))
2564 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002565 if (! p)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002566 goto expected_hwif_error; /* "expected hwif_data" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002567
2568 sscanf(p++, "%i", &hwif_data);
2569
2570 if (argc && isdigit(**argv))
2571 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002572 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002573 goto expected_hwif_error; /* "expected hwif_ctrl" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002574
2575 sscanf(p, "%i", &hwif_ctrl);
2576
2577 if (argc && isdigit(**argv))
2578 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002579 else
Bernhard Reutner-Fischer061fd0a2006-04-05 16:37:25 +00002580#endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
Bernhard Reutner-Fischer9460f662006-04-11 08:01:29 +00002581#if defined CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF || defined CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Eric Andersenb2aa7762004-04-05 13:08:08 +00002582expected_hwif_error:
Glenn L McGrath07085852003-10-09 07:28:22 +00002583 bb_error_msg_and_die("expected hwif value"); /* "expected hwif_irq" */
Bernhard Reutner-Fischer9460f662006-04-11 08:01:29 +00002584#endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF || CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
Bernhard Reutner-Fischer061fd0a2006-04-05 16:37:25 +00002585#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Eric Andersen3443bd72003-07-22 07:30:36 +00002586
2587 sscanf(p, "%i", &hwif_irq);
2588
2589 *p = '\0';
2590
2591 scan_hwif = 1;
2592 break;
2593#endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
2594 case 'Q':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002595#ifdef HDIO_GET_QDMA
Eric Andersen3443bd72003-07-22 07:30:36 +00002596 get_dma_q = noisy;
2597 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002598#ifdef HDIO_SET_QDMA
2599 if (!*p && argc && isalnum(**argv))
2600 p = *argv++, --argc;
2601 p=GET_NUMBER(p,&set_dma_q,&dma_q);
2602#ifdef HDIO_GET_QDMA
2603 dma_q = -dma_q;
2604#endif
2605#endif
2606#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00002607 break;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002608
Eric Andersen3443bd72003-07-22 07:30:36 +00002609#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
2610 case 'w':
2611 perform_reset = 1;
2612 break;
2613#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
2614#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
2615 case 'x':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002616 if (!*p && argc && isdigit(**argv))
2617 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002618 if ((perform_tristate = set_flag(p,'1'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002619 tristate = *p++ - '0';
2620 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002621 missing_arg(1, c, "(0/1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002622 break;
2623
2624#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
2625 case 'a':
2626 get_readahead = noisy;
2627 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002628 if (!*p && argc && isalnum(**argv))
2629 p = *argv++, --argc;
Eric Andersenf828da02004-07-20 22:53:59 +00002630 p=GET_NUMBER(p,&set_readahead,&Xreadahead);
Eric Andersen3443bd72003-07-22 07:30:36 +00002631 break;
2632 case 'B':
2633 get_apmmode = noisy;
2634 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002635 if (!*p && argc && isalnum(**argv))
2636 p = *argv++, --argc;
2637 p=GET_NUMBER(p,&set_apmmode,&apmmode);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002638 missing_arg(set_apmmode, c, "(1-255)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002639 break;
2640 case 't':
2641 do_timings = 1;
2642 do_flush = 1;
2643 break;
2644 case 'T':
2645 do_ctimings = 1;
2646 do_flush = 1;
2647 break;
2648#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
2649 case 'b':
2650 get_busstate = noisy;
2651 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002652 if (!*p && argc && isdigit(**argv))
2653 p = *argv++, --argc;
Rob Landleya3e4f382006-04-29 16:06:31 +00002654 if ((set_busstate = set_flag(p,'2'))==1)
Glenn L McGrath07085852003-10-09 07:28:22 +00002655 busstate = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002656 break;
2657#endif
2658 case 'h':
2659 default:
2660 bb_show_usage();
2661 }
2662 }
2663 if (!argc)
2664 bb_show_usage();
Eric Andersen06d4ec22004-03-19 10:53:52 +00002665 } else {
Rob Landleya3e4f382006-04-29 16:06:31 +00002666 process_dev(p);
Eric Andersen06d4ec22004-03-19 10:53:52 +00002667 }
Eric Andersen3443bd72003-07-22 07:30:36 +00002668 }
2669 return 0 ;
2670}