blob: d04bf56f67855b5c8fa88ce1f8b818c4ac35176e [file] [log] [blame]
Eric Andersen3443bd72003-07-22 07:30:36 +00001/* vi: set sw=4 ts=4: */
2/*
3 * hdparm implementation for busybox
4 *
5 *
Glenn L McGrath5be6a202003-11-28 22:55:03 +00006 * Copyright (C) [2003] by [Matteo Croce] <3297627799@wind.it>
Glenn L McGrath07085852003-10-09 07:28:22 +00007 *
8 * Hacked by Tito <farmatito@tiscali.it> for size optimization.
Eric Andersen3443bd72003-07-22 07:30:36 +00009 *
Bernhard Reutner-Fischer061fd0a2006-04-05 16:37:25 +000010 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersen3443bd72003-07-22 07:30:36 +000011 *
12 * This program is based on the source code of hdparm: see below...
13 * hdparm.c - Command line interface to get/set hard disk parameters
14 * - by Mark Lord (C) 1994-2002 -- freely distributable
15 */
Glenn L McGrath07085852003-10-09 07:28:22 +000016
Eric Andersen3443bd72003-07-22 07:30:36 +000017#include <unistd.h>
18#include <string.h>
19#include <stdlib.h>
20#include <fcntl.h>
21#include <errno.h>
22#include <ctype.h>
23#include <endian.h>
24#include <sys/ioctl.h>
25#include <sys/shm.h>
26#include <sys/sysmacros.h>
27#include <sys/time.h>
28#include <sys/times.h>
29#include <sys/mount.h>
30#include "busybox.h"
31#include <linux/types.h>
32#include <linux/hdreg.h>
33#include <linux/major.h>
34#include <asm/byteorder.h>
35
36
Rob Landley688ed0d2006-03-04 22:40:25 +000037#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
38# define __USE_XOPEN
Eric Andersen3443bd72003-07-22 07:30:36 +000039#endif
40
41/* device types */
42/* ------------ */
43#define NO_DEV 0xffff
44#define ATA_DEV 0x0000
45#define ATAPI_DEV 0x0001
46
47/* word definitions */
48/* ---------------- */
49#define GEN_CONFIG 0 /* general configuration */
50#define LCYLS 1 /* number of logical cylinders */
51#define CONFIG 2 /* specific configuration */
52#define LHEADS 3 /* number of logical heads */
53#define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */
54#define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */
55#define LSECTS 6 /* number of logical sectors/track */
56#define START_SERIAL 10 /* ASCII serial number */
57#define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */
58#define BUF_TYPE 20 /* buffer type (ATA-1) */
59#define BUFFER__SIZE 21 /* buffer size (ATA-1) */
60#define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/
61#define START_FW_REV 23 /* ASCII firmware revision */
62#define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000063#define START_MODEL 27 /* ASCII model number */
64#define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */
Eric Andersen3443bd72003-07-22 07:30:36 +000065#define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */
66#define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */
67#define CAPAB_0 49 /* capabilities */
68#define CAPAB_1 50
69#define PIO_MODE 51 /* max PIO mode supported (obsolete)*/
70#define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/
71#define WHATS_VALID 53 /* what fields are valid */
72#define LCYLS_CUR 54 /* current logical cylinders */
73#define LHEADS_CUR 55 /* current logical heads */
74#define LSECTS_CUR 56 /* current logical sectors/track */
75#define CAPACITY_LSB 57 /* current capacity in sectors */
76#define CAPACITY_MSB 58
77#define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */
78#define LBA_SECTS_LSB 60 /* LBA: total number of user */
79#define LBA_SECTS_MSB 61 /* addressable sectors */
80#define SINGLE_DMA 62 /* singleword DMA modes */
81#define MULTI_DMA 63 /* multiword DMA modes */
82#define ADV_PIO_MODES 64 /* advanced PIO modes supported */
83 /* multiword DMA xfer cycle time: */
84#define DMA_TIME_MIN 65 /* - minimum */
85#define DMA_TIME_NORM 66 /* - manufacturer's recommended */
86 /* minimum PIO xfer cycle time: */
87#define PIO_NO_FLOW 67 /* - without flow control */
88#define PIO_FLOW 68 /* - with IORDY flow control */
89#define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */
90#define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */
91#define CDR_MAJOR 73 /* CD ROM: major version number */
92#define CDR_MINOR 74 /* CD ROM: minor version number */
93#define QUEUE_DEPTH 75 /* queue depth */
94#define MAJOR 80 /* major version number */
95#define MINOR 81 /* minor version number */
96#define CMDS_SUPP_0 82 /* command/feature set(s) supported */
97#define CMDS_SUPP_1 83
98#define CMDS_SUPP_2 84
99#define CMDS_EN_0 85 /* command/feature set(s) enabled */
100#define CMDS_EN_1 86
101#define CMDS_EN_2 87
102#define ULTRA_DMA 88 /* ultra DMA modes */
103 /* time to complete security erase */
104#define ERASE_TIME 89 /* - ordinary */
105#define ENH_ERASE_TIME 90 /* - enhanced */
106#define ADV_PWR 91 /* current advanced power management level
Glenn L McGrath07085852003-10-09 07:28:22 +0000107 in low byte, 0x40 in high byte. */
Eric Andersen3443bd72003-07-22 07:30:36 +0000108#define PSWD_CODE 92 /* master password revision code */
109#define HWRST_RSLT 93 /* hardware reset result */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000110#define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000111#define LBA_LSB 100 /* LBA: maximum. Currently only 48 */
112#define LBA_MID 101 /* bits are used, but addr 103 */
113#define LBA_48_MSB 102 /* has been reserved for LBA in */
114#define LBA_64_MSB 103 /* the future. */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000115#define RM_STAT 127 /* removable media status notification feature set support */
Eric Andersen3443bd72003-07-22 07:30:36 +0000116#define SECU_STATUS 128 /* security status */
117#define CFA_PWR_MODE 160 /* CFA power mode 1 */
118#define START_MEDIA 176 /* media serial number */
119#define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/
120#define START_MANUF 196 /* media manufacturer I.D. */
121#define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */
122#define INTEGRITY 255 /* integrity word */
123
124/* bit definitions within the words */
125/* -------------------------------- */
126
127/* many words are considered valid if bit 15 is 0 and bit 14 is 1 */
128#define VALID 0xc000
129#define VALID_VAL 0x4000
130/* many words are considered invalid if they are either all-0 or all-1 */
131#define NOVAL_0 0x0000
132#define NOVAL_1 0xffff
133
134/* word 0: gen_config */
Glenn L McGrath07085852003-10-09 07:28:22 +0000135#define NOT_ATA 0x8000
Eric Andersen3443bd72003-07-22 07:30:36 +0000136#define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */
137#define MEDIA_REMOVABLE 0x0080
138#define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */
139#define INCOMPLETE 0x0004
140#define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */
141#define DRQ_RESPONSE_TIME 0x0060
142#define DRQ_3MS_VAL 0x0000
143#define DRQ_INTR_VAL 0x0020
144#define DRQ_50US_VAL 0x0040
145#define PKT_SIZE_SUPPORTED 0x0003
146#define PKT_SIZE_12_VAL 0x0000
147#define PKT_SIZE_16_VAL 0x0001
148#define EQPT_TYPE 0x1f00
149#define SHIFT_EQPT 8
150
151#define CDROM 0x0005
152
153#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000154static const char * const pkt_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000155 "Direct-access device", /* word 0, bits 12-8 = 00 */
156 "Sequential-access device", /* word 0, bits 12-8 = 01 */
157 "Printer", /* word 0, bits 12-8 = 02 */
158 "Processor", /* word 0, bits 12-8 = 03 */
159 "Write-once device", /* word 0, bits 12-8 = 04 */
160 "CD-ROM", /* word 0, bits 12-8 = 05 */
161 "Scanner", /* word 0, bits 12-8 = 06 */
162 "Optical memory", /* word 0, bits 12-8 = 07 */
163 "Medium changer", /* word 0, bits 12-8 = 08 */
164 "Communications device", /* word 0, bits 12-8 = 09 */
165 "ACS-IT8 device", /* word 0, bits 12-8 = 0a */
166 "ACS-IT8 device", /* word 0, bits 12-8 = 0b */
167 "Array controller", /* word 0, bits 12-8 = 0c */
168 "Enclosure services", /* word 0, bits 12-8 = 0d */
169 "Reduced block command device", /* word 0, bits 12-8 = 0e */
170 "Optical card reader/writer", /* word 0, bits 12-8 = 0f */
171 "", /* word 0, bits 12-8 = 10 */
172 "", /* word 0, bits 12-8 = 11 */
173 "", /* word 0, bits 12-8 = 12 */
174 "", /* word 0, bits 12-8 = 13 */
175 "", /* word 0, bits 12-8 = 14 */
176 "", /* word 0, bits 12-8 = 15 */
177 "", /* word 0, bits 12-8 = 16 */
178 "", /* word 0, bits 12-8 = 17 */
179 "", /* word 0, bits 12-8 = 18 */
180 "", /* word 0, bits 12-8 = 19 */
181 "", /* word 0, bits 12-8 = 1a */
182 "", /* word 0, bits 12-8 = 1b */
183 "", /* word 0, bits 12-8 = 1c */
184 "", /* word 0, bits 12-8 = 1d */
185 "", /* word 0, bits 12-8 = 1e */
186 "Unknown", /* word 0, bits 12-8 = 1f */
187};
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000188
189static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */
Eric Andersen3443bd72003-07-22 07:30:36 +0000190 "reserved", /* bit 0 */
191 "hard sectored", /* bit 1 */
192 "soft sectored", /* bit 2 */
193 "not MFM encoded ", /* bit 3 */
194 "head switch time > 15us", /* bit 4 */
195 "spindle motor control option", /* bit 5 */
196 "fixed drive", /* bit 6 */
197 "removable drive", /* bit 7 */
198 "disk xfer rate <= 5Mbs", /* bit 8 */
199 "disk xfer rate > 5Mbs, <= 10Mbs", /* bit 9 */
200 "disk xfer rate > 5Mbs", /* bit 10 */
201 "rotational speed tol.", /* bit 11 */
202 "data strobe offset option", /* bit 12 */
203 "track offset option", /* bit 13 */
204 "format speed tolerance gap reqd", /* bit 14 */
205 "ATAPI" /* bit 14 */
206};
207#endif
208
209/* word 1: number of logical cylinders */
210#define LCYLS_MAX 0x3fff /* maximum allowable value */
211
Eric Andersenaff114c2004-04-14 17:51:38 +0000212/* word 2: specific configuration
Eric Andersen3443bd72003-07-22 07:30:36 +0000213 * (a) require SET FEATURES to spin-up
214 * (b) require spin-up to fully reply to IDENTIFY DEVICE
215 */
216#define STBY_NID_VAL 0x37c8 /* (a) and (b) */
217#define STBY_ID_VAL 0x738c /* (a) and not (b) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000218#define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000219#define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */
220
221/* words 47 & 59: sector_xfer_max & sector_xfer_cur */
222#define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/
223#define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */
224
225/* word 49: capabilities 0 */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000226#define STD_STBY 0x2000 /* 1=standard values supported (ATA);
Eric Andersen3443bd72003-07-22 07:30:36 +0000227 0=vendor specific values */
228#define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */
229#define IORDY_OFF 0x0400 /* 1=may be disabled */
230#define LBA_SUP 0x0200 /* 1=Logical Block Address support */
231#define DMA_SUP 0x0100 /* 1=Direct Memory Access support */
232#define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */
233#define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */
234#define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */
235#define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */
236
237/* word 50: capabilities 1 */
238#define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */
239
240/* words 51 & 52: PIO & DMA cycle times */
241#define MODE 0xff00 /* the mode is in the MSBs */
242
243/* word 53: whats_valid */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000244#define OK_W88 0x0004 /* the ultra_dma info is valid */
Eric Andersen3443bd72003-07-22 07:30:36 +0000245#define OK_W64_70 0x0002 /* see above for word descriptions */
246#define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */
247
248/*word 63,88: dma_mode, ultra_dma_mode*/
249#define MODE_MAX 7 /* bit definitions force udma <=7 (when
250 * udma >=8 comes out it'll have to be
251 * defined in a new dma_mode word!) */
252
253/* word 64: PIO transfer modes */
254#define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */
255#define PIO_MODE_MAX 8 /* but all 8 bits are defined */
256
257/* word 75: queue_depth */
258#define DEPTH_BITS 0x001f /* bits used for queue depth */
259
260/* words 80-81: version numbers */
261/* NOVAL_0 or NOVAL_1 means device does not report version */
262
263/* word 81: minor version number */
264#define MINOR_MAX 0x1C
265#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000266static const char * const minor_str[] = { /* word 81 value: */
Eric Andersen3443bd72003-07-22 07:30:36 +0000267 "device does not report version", /* 0x0000 */
268 "ATA-1 X3T9.2 781D prior to revision 4", /* 0x0001 */
269 "ATA-1 published, ANSI X3.221-1994", /* 0x0002 */
270 "ATA-1 X3T9.2 781D revision 4", /* 0x0003 */
271 "ATA-2 published, ANSI X3.279-1996", /* 0x0004 */
272 "ATA-2 X3T10 948D prior to revision 2k", /* 0x0005 */
273 "ATA-3 X3T10 2008D revision 1", /* 0x0006 */
274 "ATA-2 X3T10 948D revision 2k", /* 0x0007 */
275 "ATA-3 X3T10 2008D revision 0", /* 0x0008 */
276 "ATA-2 X3T10 948D revision 3", /* 0x0009 */
277 "ATA-3 published, ANSI X3.298-199x", /* 0x000a */
278 "ATA-3 X3T10 2008D revision 6", /* 0x000b */
279 "ATA-3 X3T13 2008D revision 7 and 7a", /* 0x000c */
280 "ATA/ATAPI-4 X3T13 1153D revision 6", /* 0x000d */
281 "ATA/ATAPI-4 T13 1153D revision 13", /* 0x000e */
282 "ATA/ATAPI-4 X3T13 1153D revision 7", /* 0x000f */
283 "ATA/ATAPI-4 T13 1153D revision 18", /* 0x0010 */
284 "ATA/ATAPI-4 T13 1153D revision 15", /* 0x0011 */
285 "ATA/ATAPI-4 published, ANSI NCITS 317-1998", /* 0x0012 */
286 "ATA/ATAPI-5 T13 1321D revision 3",
287 "ATA/ATAPI-4 T13 1153D revision 14", /* 0x0014 */
288 "ATA/ATAPI-5 T13 1321D revision 1", /* 0x0015 */
289 "ATA/ATAPI-5 published, ANSI NCITS 340-2000", /* 0x0016 */
290 "ATA/ATAPI-4 T13 1153D revision 17", /* 0x0017 */
291 "ATA/ATAPI-6 T13 1410D revision 0", /* 0x0018 */
292 "ATA/ATAPI-6 T13 1410D revision 3a", /* 0x0019 */
293 "Reserved", /* 0x001a */
294 "ATA/ATAPI-6 T13 1410D revision 2", /* 0x001b */
295 "ATA/ATAPI-6 T13 1410D revision 1", /* 0x001c */
296 "reserved" /* 0x001d */
297 "reserved" /* 0x001e */
298 "reserved" /* 0x001f-0xfffe*/
299};
300#endif
Glenn L McGrath07085852003-10-09 07:28:22 +0000301static const char actual_ver[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000302 /* word 81 value: */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000303 0, /* 0x0000 WARNING: */
304 1, /* 0x0001 WARNING: */
305 1, /* 0x0002 WARNING: */
306 1, /* 0x0003 WARNING: */
307 2, /* 0x0004 WARNING: This array */
308 2, /* 0x0005 WARNING: corresponds */
Eric Andersen3443bd72003-07-22 07:30:36 +0000309 3, /* 0x0006 WARNING: *exactly* */
310 2, /* 0x0007 WARNING: to the ATA/ */
311 3, /* 0x0008 WARNING: ATAPI version */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000312 2, /* 0x0009 WARNING: listed in */
313 3, /* 0x000a WARNING: the */
314 3, /* 0x000b WARNING: minor_str */
Eric Andersen3443bd72003-07-22 07:30:36 +0000315 3, /* 0x000c WARNING: array */
316 4, /* 0x000d WARNING: above. */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000317 4, /* 0x000e WARNING: */
318 4, /* 0x000f WARNING: if you change */
319 4, /* 0x0010 WARNING: that one, */
Eric Andersen3443bd72003-07-22 07:30:36 +0000320 4, /* 0x0011 WARNING: change this one */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000321 4, /* 0x0012 WARNING: too!!! */
Eric Andersen3443bd72003-07-22 07:30:36 +0000322 5, /* 0x0013 WARNING: */
323 4, /* 0x0014 WARNING: */
324 5, /* 0x0015 WARNING: */
325 5, /* 0x0016 WARNING: */
326 4, /* 0x0017 WARNING: */
327 6, /* 0x0018 WARNING: */
328 6, /* 0x0019 WARNING: */
329 0, /* 0x001a WARNING: */
330 6, /* 0x001b WARNING: */
331 6, /* 0x001c WARNING: */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000332 0 /* 0x001d-0xfffe */
Eric Andersen3443bd72003-07-22 07:30:36 +0000333};
334
335/* words 82-84: cmds/feats supported */
336#define CMDS_W82 0x77ff /* word 82: defined command locations*/
337#define CMDS_W83 0x3fff /* word 83: defined command locations*/
338#define CMDS_W84 0x002f /* word 83: defined command locations*/
Glenn L McGrath07085852003-10-09 07:28:22 +0000339#define SUPPORT_48_BIT 0x0400
Eric Andersen3443bd72003-07-22 07:30:36 +0000340#define NUM_CMD_FEAT_STR 48
341
342#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000343static const char * const cmd_feat_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000344 "", /* word 82 bit 15: obsolete */
345 "NOP cmd", /* word 82 bit 14 */
346 "READ BUFFER cmd", /* word 82 bit 13 */
347 "WRITE BUFFER cmd", /* word 82 bit 12 */
348 "", /* word 82 bit 11: obsolete */
349 "Host Protected Area feature set", /* word 82 bit 10 */
350 "DEVICE RESET cmd", /* word 82 bit 9 */
351 "SERVICE interrupt", /* word 82 bit 8 */
352 "Release interrupt", /* word 82 bit 7 */
353 "Look-ahead", /* word 82 bit 6 */
354 "Write cache", /* word 82 bit 5 */
355 "PACKET command feature set", /* word 82 bit 4 */
356 "Power Management feature set", /* word 82 bit 3 */
357 "Removable Media feature set", /* word 82 bit 2 */
358 "Security Mode feature set", /* word 82 bit 1 */
359 "SMART feature set", /* word 82 bit 0 */
360 /* --------------*/
361 "", /* word 83 bit 15: !valid bit */
362 "", /* word 83 bit 14: valid bit */
363 "FLUSH CACHE EXT command", /* word 83 bit 13 */
364 "Mandatory FLUSH CACHE command ", /* word 83 bit 12 */
365 "Device Configuration Overlay feature set ",
366 "48-bit Address feature set ", /* word 83 bit 10 */
367 "",
368 "SET MAX security extension", /* word 83 bit 8 */
369 "Address Offset Reserved Area Boot", /* word 83 bit 7 */
370 "SET FEATURES subcommand required to spinup after power up",
371 "Power-Up In Standby feature set", /* word 83 bit 5 */
372 "Removable Media Status Notification feature set",
Eric Andersen06d4ec22004-03-19 10:53:52 +0000373 "Adv. Power Management feature set",/* word 83 bit 3 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000374 "CFA feature set", /* word 83 bit 2 */
375 "READ/WRITE DMA QUEUED", /* word 83 bit 1 */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000376 "DOWNLOAD MICROCODE cmd", /* word 83 bit 0 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000377 /* --------------*/
378 "", /* word 84 bit 15: !valid bit */
379 "", /* word 84 bit 14: valid bit */
380 "", /* word 84 bit 13: reserved */
381 "", /* word 84 bit 12: reserved */
382 "", /* word 84 bit 11: reserved */
383 "", /* word 84 bit 10: reserved */
384 "", /* word 84 bit 9: reserved */
385 "", /* word 84 bit 8: reserved */
386 "", /* word 84 bit 7: reserved */
387 "", /* word 84 bit 6: reserved */
388 "General Purpose Logging feature set", /* word 84 bit 5 */
389 "", /* word 84 bit 4: reserved */
390 "Media Card Pass Through Command feature set ",
391 "Media serial number ", /* word 84 bit 2 */
392 "SMART self-test ", /* word 84 bit 1 */
393 "SMART error logging " /* word 84 bit 0 */
394};
395#endif
396
397
398/* words 85-87: cmds/feats enabled */
399/* use cmd_feat_str[] to display what commands and features have
Glenn L McGrath07085852003-10-09 07:28:22 +0000400 * been enabled with words 85-87
Eric Andersen3443bd72003-07-22 07:30:36 +0000401 */
402
403/* words 89, 90, SECU ERASE TIME */
404#define ERASE_BITS 0x00ff
405
406/* word 92: master password revision */
407/* NOVAL_0 or NOVAL_1 means no support for master password revision */
408
409/* word 93: hw reset result */
410#define CBLID 0x2000 /* CBLID status */
411#define RST0 0x0001 /* 1=reset to device #0 */
412#define DEV_DET 0x0006 /* how device num determined */
413#define JUMPER_VAL 0x0002 /* device num determined by jumper */
414#define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */
415
416/* word 127: removable media status notification feature set support */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000417#define RM_STAT_BITS 0x0003
Eric Andersen3443bd72003-07-22 07:30:36 +0000418#define RM_STAT_SUP 0x0001
Glenn L McGrath07085852003-10-09 07:28:22 +0000419
Eric Andersen3443bd72003-07-22 07:30:36 +0000420/* word 128: security */
421#define SECU_ENABLED 0x0002
422#define SECU_LEVEL 0x0010
423#define NUM_SECU_STR 6
424#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000425static const char * const secu_str[] = {
Eric Andersen3443bd72003-07-22 07:30:36 +0000426 "supported", /* word 128, bit 0 */
427 "enabled", /* word 128, bit 1 */
428 "locked", /* word 128, bit 2 */
429 "frozen", /* word 128, bit 3 */
430 "expired: security count", /* word 128, bit 4 */
431 "supported: enhanced erase" /* word 128, bit 5 */
432};
433#endif
434
435/* word 160: CFA power mode */
436#define VALID_W160 0x8000 /* 1=word valid */
437#define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/
438#define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */
439#define MAX_AMPS 0x0fff /* value = max current in ma */
440
441/* word 255: integrity */
442#define SIG 0x00ff /* signature location */
443#define SIG_VAL 0x00A5 /* signature value */
444
Glenn L McGrath07085852003-10-09 07:28:22 +0000445#define VERSION "v5.4"
446
447#define TIMING_MB 64
448#define TIMING_BUF_MB 1
449#define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024)
450#define TIMING_BUF_COUNT (timing_MB / TIMING_BUF_MB)
451#define BUFCACHE_FACTOR 2
452
453#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
454
455/* Busybox messages and functions */
456
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +0000457static const char bb_msg_shared_mem[] = "could not %s sharedmem buf";
458static const char bb_msg_op_not_supp[] = " operation not supported on %s disks";
Glenn L McGrath07085852003-10-09 07:28:22 +0000459
460static void bb_ioctl(int fd, int request, void *argp, const char *string)
461{
462 if (ioctl (fd, request, argp) != 0)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000463 bb_perror_msg(" %s", string);
Glenn L McGrath07085852003-10-09 07:28:22 +0000464}
465
466static void if_printf(unsigned long i, char *fmt, ... )
467{
468 va_list ap;
469 va_start(ap, fmt);
470 if (i)
471 vprintf(fmt, ap);
472 va_end(ap);
473}
474
475static void on_off (unsigned int value);
476
477static void if_printf_on_off(unsigned long get_arg,const char *fmt, unsigned long arg)
478{
479 if (get_arg)
480 {
481 printf(fmt, arg);
482 on_off(arg);
483 }
484}
485
486static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string,
487 const char * fmt)
488{
489 if (ioctl (fd, request, &argp) != 0)
Eric Andersen06d4ec22004-03-19 10:53:52 +0000490 bb_perror_msg(" %s", string);
Glenn L McGrath07085852003-10-09 07:28:22 +0000491 else
492 {
493 printf(fmt, (unsigned long) argp);
494 on_off((unsigned long) argp);
495 }
496}
Eric Andersen416c2422003-12-12 00:08:57 +0000497
498#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000499static void if_else_printf(unsigned long i, char *fmt1, char *fmt2, ... )
500{
501 va_list ap;
502 va_start(ap, fmt2);
503 if (i)
504 vprintf(fmt1, ap);
505 else
506 vprintf(fmt2, ap);
507 va_end(ap);
508}
509
510static void print_ascii(uint16_t *p, uint8_t length);
511
512static void xprint_ascii(uint16_t *val ,int i, char * string, int n)
513{
514 if(val[i])
515 {
516 printf("\t%-20s",string);
517 print_ascii(&val[i], n);
518 }
519}
520
Eric Andersen416c2422003-12-12 00:08:57 +0000521static void if_strcat(unsigned long test, char *modes, char *string)
522{
523 if (test)
524 strcat(modes,string);
525}
526#endif
527
Glenn L McGrath07085852003-10-09 07:28:22 +0000528static void sync_and_sleep(int i)
529{
530 sync();
531 sleep(i);
532}
533
Eric Andersenb2aa7762004-04-05 13:08:08 +0000534static uint16_t check_if_min_and_set_val(uint16_t a, uint16_t b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000535{
536 if( a < b)
537 a = b;
Eric Andersenb2aa7762004-04-05 13:08:08 +0000538 return a;
Glenn L McGrath07085852003-10-09 07:28:22 +0000539}
540
Eric Andersenb2aa7762004-04-05 13:08:08 +0000541static uint16_t check_if_maj_and_set_val(uint16_t a, uint16_t b)
Glenn L McGrath07085852003-10-09 07:28:22 +0000542{
543 if( a > b)
544 a = b;
Eric Andersenb2aa7762004-04-05 13:08:08 +0000545 return a;
Glenn L McGrath07085852003-10-09 07:28:22 +0000546}
547
Eric Andersenb2aa7762004-04-05 13:08:08 +0000548static unsigned long int set_flag(char *p, char max)
Glenn L McGrath07085852003-10-09 07:28:22 +0000549{
550 if (*p >= '0' && *p <= max )
551 return 1;
552 return 0;
553}
554
Glenn L McGrath07085852003-10-09 07:28:22 +0000555/* end of busybox specific stuff */
556
Eric Andersen3443bd72003-07-22 07:30:36 +0000557#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +0000558static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
559{
Eric Andersen3443bd72003-07-22 07:30:36 +0000560 uint16_t ii;
561 uint8_t err_dma = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000562
563 for(ii = 0; ii <= MODE_MAX; ii++)
564 {
565 if(mode_sel & 0x0001)
566 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000567 printf("*%cdma%u ",cc,ii);
Glenn L McGrath07085852003-10-09 07:28:22 +0000568 if(*have_mode)
569 err_dma = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000570 *have_mode = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000571 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000572 else if(mode_sup & 0x0001)
573 printf("%cdma%u ",cc,ii);
574
575 mode_sup >>=1;
576 mode_sel >>=1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000577 }
578 return err_dma;
579}
Glenn L McGrath07085852003-10-09 07:28:22 +0000580
Eric Andersen3443bd72003-07-22 07:30:36 +0000581static void print_ascii(uint16_t *p, uint8_t length) {
582 uint8_t ii;
583 char cl;
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000584
Eric Andersen3443bd72003-07-22 07:30:36 +0000585 /* find first non-space & print it */
Glenn L McGrath07085852003-10-09 07:28:22 +0000586 for(ii = 0; ii< length; ii++)
587 {
588 if(((char) 0x00ff&((*p)>>8)) != ' ')
589 break;
590 if((cl = (char) 0x00ff&(*p)) != ' ')
591 {
592 if_printf((cl != '\0'),"%c",cl);
593 p++;
594 ii++;
Eric Andersen3443bd72003-07-22 07:30:36 +0000595 break;
596 }
597 p++;
598 }
599 /* print the rest */
Glenn L McGrath07085852003-10-09 07:28:22 +0000600 for(; ii< length; ii++)
601 {
602 if(!(*p))
603 break; /* some older devices have NULLs */
Eric Andersen3443bd72003-07-22 07:30:36 +0000604 printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff);
605 p++;
606 }
607 printf("\n");
608}
609
610/* identify() is the only extern function used across two source files. The
611 others, though, were declared in hdparm.c with global scope; since other
612 functions in that file have static (file) scope, I assume the difference is
613 intentional. */
614static void identify (uint16_t *id_supplied, const char *devname)
615{
616
Glenn L McGrath07085852003-10-09 07:28:22 +0000617 char *id_file = NULL;
Eric Andersen3443bd72003-07-22 07:30:36 +0000618 FILE *fl;
619 uint16_t val[256], ii, jj, kk;
620 uint16_t like_std = 1, std = 0, min_std = 0xffff;
621 uint16_t dev = NO_DEV, eqpt = NO_DEV;
622 uint8_t have_mode = 0, err_dma = 0;
623 uint8_t chksum = 0;
624 uint32_t ll, mm, nn, oo;
625 __u64 bbbig; /* (:) */
626
Glenn L McGrath07085852003-10-09 07:28:22 +0000627 if (id_supplied)
628 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000629#if __BYTE_ORDER == __BIG_ENDIAN
630 swab(id_supplied, val, sizeof(val));
631#else
632 memcpy(val, id_supplied, sizeof(val));
633#endif
Glenn L McGrath07085852003-10-09 07:28:22 +0000634 }
635 else
636 {
637 id_file = xcalloc(1, strlen(devname)+22);
638 sprintf(id_file, "/proc/ide/%s/identify", devname);
Eric Andersen3443bd72003-07-22 07:30:36 +0000639 /* open the file, read in all the info and close it */
Glenn L McGrath07085852003-10-09 07:28:22 +0000640 if (id_file == NULL)
Eric Andersen3443bd72003-07-22 07:30:36 +0000641 fl = stdin;
Glenn L McGrath07085852003-10-09 07:28:22 +0000642 else
643 fl = bb_xfopen(id_file, "r");
644
Eric Andersen3443bd72003-07-22 07:30:36 +0000645 /* calculate checksum over all bytes */
Glenn L McGrath07085852003-10-09 07:28:22 +0000646 for(ii = GEN_CONFIG; ii<=INTEGRITY; ii++)
647 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000648 unsigned int scratch;
Glenn L McGrath07085852003-10-09 07:28:22 +0000649 if(1 != fscanf(fl,"%04x",&scratch))
650 break;
Eric Andersen3443bd72003-07-22 07:30:36 +0000651 val[ii] = (uint16_t)scratch;
652 chksum += val[ii] + (val[ii] >> 8);
653 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000654 fclose(fl);
655 /*bb_fclose_nonstdin(fl);*/
Eric Andersen3443bd72003-07-22 07:30:36 +0000656 if(ii < (INTEGRITY+1))
657 bb_error_msg_and_die("Input file wrong format or length");
658 }
659 chksum &= 0xff;
660
661 /* check if we recognise the device type */
662 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000663 if(!(val[GEN_CONFIG] & NOT_ATA))
664 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000665 dev = ATA_DEV;
666 printf("ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000667 }
668 else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL)
669 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000670 dev = ATA_DEV;
671 like_std = 4;
672 printf("CompactFlash ATA device, with ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000673 }
674 else if(!(val[GEN_CONFIG] & NOT_ATAPI))
675 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000676 dev = ATAPI_DEV;
677 eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
678 printf("ATAPI %s, with ", pkt_str[eqpt]);
679 like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000680 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000681 else
682 /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/
683 bb_error_msg_and_die("Unknown device type");
Eric Andersen3443bd72003-07-22 07:30:36 +0000684
Glenn L McGrath07085852003-10-09 07:28:22 +0000685 if_printf(!(val[GEN_CONFIG] & MEDIA_REMOVABLE),"non-");
686 printf("removable media\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000687
688 /* Info from the specific configuration word says whether or not the
689 * ID command completed correctly. It is only defined, however in
Glenn L McGrath07085852003-10-09 07:28:22 +0000690 * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior
Eric Andersen3443bd72003-07-22 07:30:36 +0000691 * standards. Since the values allowed for this word are extremely
692 * specific, it should be safe to check it now, even though we don't
693 * know yet what standard this device is using.
694 */
695 if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000696 (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) )
697 {
698 like_std = 5;
699 if_printf(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)),
700 "powers-up in standby; SET FEATURES subcmd spins-up.\n");
701 if_printf((((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)),
702 "\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000703 }
704
705 /* output the model and serial numbers and the fw revision */
Glenn L McGrath07085852003-10-09 07:28:22 +0000706 xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL);
707 xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL);
708 xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV);
709 xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA);
710 xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF);
Eric Andersen3443bd72003-07-22 07:30:36 +0000711
712 /* major & minor standards version number (Note: these words were not
713 * defined until ATA-3 & the CDROM std uses different words.) */
714 printf("Standards:");
Glenn L McGrath07085852003-10-09 07:28:22 +0000715 if(eqpt != CDROM)
716 {
717 if(val[MINOR] && (val[MINOR] <= MINOR_MAX))
718 {
Eric Andersenb2aa7762004-04-05 13:08:08 +0000719 like_std=check_if_min_and_set_val(like_std, 3);
Eric Andersen3443bd72003-07-22 07:30:36 +0000720 std = actual_ver[val[MINOR]];
Glenn L McGrath07085852003-10-09 07:28:22 +0000721 if_printf(std,"\n\tUsed: %s ",minor_str[val[MINOR]]);
722
Eric Andersen3443bd72003-07-22 07:30:36 +0000723 }
724 /* looks like when they up-issue the std, they obsolete one;
Glenn L McGrath07085852003-10-09 07:28:22 +0000725 * thus, only the newest 4 issues need be supported. (That's
Eric Andersen3443bd72003-07-22 07:30:36 +0000726 * what "kk" and "min_std" are all about.) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000727 if(val[MAJOR] && (val[MAJOR] !=NOVAL_1))
728 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000729 printf("\n\tSupported: ");
730 jj = val[MAJOR] << 1;
731 kk = like_std >4 ? like_std-4: 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000732 for(ii = 14; (ii >0)&&(ii>kk); ii--)
733 {
734 if(jj & 0x8000)
735 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000736 printf("%u ", ii);
Glenn L McGrath07085852003-10-09 07:28:22 +0000737 if(like_std < ii)
738 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000739 like_std = ii;
740 kk = like_std >4 ? like_std-4: 0;
741 }
Eric Andersenb2aa7762004-04-05 13:08:08 +0000742 min_std=check_if_maj_and_set_val(min_std, ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000743 }
744 jj <<= 1;
745 }
Eric Andersenb2aa7762004-04-05 13:08:08 +0000746 like_std=check_if_min_and_set_val(like_std, 3);
Eric Andersen3443bd72003-07-22 07:30:36 +0000747 }
748 /* Figure out what standard the device is using if it hasn't told
749 * us. If we know the std, check if the device is using any of
750 * the words from the next level up. It happens.
751 */
Eric Andersenb2aa7762004-04-05 13:08:08 +0000752 like_std=check_if_min_and_set_val(like_std, std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000753
Eric Andersen3443bd72003-07-22 07:30:36 +0000754 if(((std == 5) || (!std && (like_std < 6))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000755 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
756 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) ||
757 ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) &&
758 ( val[CMDS_SUPP_2] & CMDS_W84) ) ) )
759 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000760 like_std = 6;
Glenn L McGrath07085852003-10-09 07:28:22 +0000761 }
762 else if(((std == 4) || (!std && (like_std < 5))) &&
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000763 ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000764 (( val[HWRST_RSLT] & VALID) == VALID_VAL) ||
765 ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
766 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) )
767 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000768 like_std = 5;
Glenn L McGrath07085852003-10-09 07:28:22 +0000769 }
770 else if(((std == 3) || (!std && (like_std < 4))) &&
771 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
772 ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) ||
773 (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) ||
774 (( val[CAPAB_1] & VALID) == VALID_VAL) ||
775 (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) ||
776 (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) )
777 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000778 like_std = 4;
Glenn L McGrath07085852003-10-09 07:28:22 +0000779 }
780 else if(((std == 2) || (!std && (like_std < 3))) &&
781 ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) )
782 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000783 like_std = 3;
Glenn L McGrath07085852003-10-09 07:28:22 +0000784 }
785 else if(((std == 1) || (!std && (like_std < 2))) &&
786 ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) ||
787 (val[WHATS_VALID] & OK_W64_70)) )
788 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000789 like_std = 2;
790 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000791 if(!std)
Eric Andersen3443bd72003-07-22 07:30:36 +0000792 printf("\n\tLikely used: %u\n",like_std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000793 else if(like_std > std)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000794 printf("& some of %u\n",like_std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000795 else
796 printf("\n");
797 }
798 else
799 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000800 /* TBD: do CDROM stuff more thoroughly. For now... */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000801 kk = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000802 if(val[CDR_MINOR] == 9)
803 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000804 kk = 1;
805 printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5");
806 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000807 if(val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1))
808 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000809 kk = 1;
810 printf("\n\tSupported: CD-ROM ATAPI");
811 jj = val[CDR_MAJOR] >> 1;
Glenn L McGrath07085852003-10-09 07:28:22 +0000812 for(ii = 1; ii <15; ii++)
813 {
814 if_printf((jj & 0x0001),"-%u ", ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000815 jj >>= 1;
816 }
817 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000818 if_else_printf((!kk),"\n\tLikely used CD-ROM ATAPI-1\n","\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000819 /* the cdrom stuff is more like ATA-2 than anything else, so: */
820 like_std = 2;
821 }
822
Glenn L McGrath07085852003-10-09 07:28:22 +0000823 if(min_std == 0xffff)
824 min_std = like_std > 4 ? like_std - 3 : 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000825
826 printf("Configuration:\n");
827 /* more info from the general configuration word */
Glenn L McGrath07085852003-10-09 07:28:22 +0000828 if((eqpt != CDROM) && (like_std == 1))
829 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000830 jj = val[GEN_CONFIG] >> 1;
Glenn L McGrath07085852003-10-09 07:28:22 +0000831 for(ii = 1; ii < 15; ii++)
832 {
833 if_printf((jj & 0x0001),"\t%s\n",ata1_cfg_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000834 jj >>=1;
835 }
836 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000837 if(dev == ATAPI_DEV)
838 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000839 printf("\tDRQ response: "); /* Data Request (DRQ) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000840 switch(val[GEN_CONFIG] & DRQ_RESPONSE_TIME)
841 {
842 case DRQ_3MS_VAL :
843 printf("3ms.\n");
844 break;
845 case DRQ_INTR_VAL :
846 printf("<=10ms with INTRQ\n");
847 break;
848 case DRQ_50US_VAL :
849 printf("50us.\n");
850 break;
851 default :
852 printf("unknown.\n");
853 break;
Eric Andersen3443bd72003-07-22 07:30:36 +0000854 }
855 printf("\tPacket size: ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000856 switch(val[GEN_CONFIG] & PKT_SIZE_SUPPORTED)
857 {
858 case PKT_SIZE_12_VAL :
859 printf("12 bytes\n");
860 break;
861 case PKT_SIZE_16_VAL :
862 printf("16 bytes\n");
863 break;
864 default :
865 printf("Unknown\n");
866 break;
Eric Andersen3443bd72003-07-22 07:30:36 +0000867 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000868 }
869 else
870 {
871 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000872 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
873 mm = 0; bbbig = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000874 if ( (ll > 0x00FBFC10) && (!val[LCYLS]))
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000875 printf("\tCHS addressing not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000876 else
877 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000878 jj = val[WHATS_VALID] & OK_W54_58;
Glenn L McGrath07085852003-10-09 07:28:22 +0000879 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",
880 val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0);
881
882 if_printf(((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])),
883 "\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]);
884
885 if(jj)
886 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000887 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
Glenn L McGrath07085852003-10-09 07:28:22 +0000888 if(like_std < 3)
889 {
890 /* check Endian of capacity bytes */
Eric Andersen3443bd72003-07-22 07:30:36 +0000891 nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR];
892 oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB];
893 if(abs(mm - nn) > abs(oo - nn))
894 mm = oo;
895 }
896 printf("\tCHS current addressable sectors:%11u\n",mm);
Glenn L McGrath07085852003-10-09 07:28:22 +0000897 }
Eric Andersen3443bd72003-07-22 07:30:36 +0000898 }
899 /* LBA addressing */
900 printf("\tLBA user addressable sectors:%11u\n",ll);
901 if( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000902 (val[CMDS_SUPP_1] & SUPPORT_48_BIT) )
903 {
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000904 bbbig = (__u64)val[LBA_64_MSB] << 48 |
905 (__u64)val[LBA_48_MSB] << 32 |
906 (__u64)val[LBA_MID] << 16 |
Glenn L McGrath07085852003-10-09 07:28:22 +0000907 val[LBA_LSB] ;
Eric Andersen3443bd72003-07-22 07:30:36 +0000908 printf("\tLBA48 user addressable sectors:%11llu\n",bbbig);
909 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000910
911 if (!bbbig)
912 bbbig = (__u64)(ll>mm ? ll : mm); /* # 512 byte blocks */
Eric Andersen3443bd72003-07-22 07:30:36 +0000913 printf("\tdevice size with M = 1024*1024: %11llu MBytes\n",bbbig>>11);
914 bbbig = (bbbig<<9)/1000000;
915 printf("\tdevice size with M = 1000*1000: %11llu MBytes ",bbbig);
Glenn L McGrath07085852003-10-09 07:28:22 +0000916
917 if_else_printf((bbbig > 1000),"(%llu GB)\n","\n",bbbig/1000);
Eric Andersen3443bd72003-07-22 07:30:36 +0000918
919 }
920
921 /* hw support of commands (capabilities) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000922 printf("Capabilities:\n\t");
923
924 if(dev == ATAPI_DEV)
925 {
926 if(eqpt != CDROM)
927 if_printf((val[CAPAB_0] & CMD_Q_SUP),"Cmd queuing, ");
928
929 if_printf((val[CAPAB_0] & OVLP_SUP),"Cmd overlap, ");
Eric Andersen3443bd72003-07-22 07:30:36 +0000930 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000931 if_printf((val[CAPAB_0] & LBA_SUP),"LBA, ");
932
933 if(like_std != 1)
934 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000935 printf("IORDY");
Glenn L McGrath07085852003-10-09 07:28:22 +0000936 if_printf((!(val[CAPAB_0] & IORDY_SUP)),"(may be)");
937 if_else_printf((val[CAPAB_0] & IORDY_OFF),"(can","(cannot");
938 printf(" be disabled)\n");
939 }
940 else
941 printf("no IORDY\n");
942
943 if((like_std == 1) && val[BUF_TYPE])
944 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000945 kk = val[BUF_TYPE];
946 printf("\tBuffer type: %04x: ",kk);
Glenn L McGrath07085852003-10-09 07:28:22 +0000947 if_else_printf((kk < 2),"single port, single-sector","dual port, multi-sector");
948 if_printf((kk > 2)," with read caching ability");
Eric Andersen3443bd72003-07-22 07:30:36 +0000949 printf("\n");
950 }
951 jj = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000952 if((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1)))
953 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000954 printf("\tBuffer size: %.1fkB",(float)val[BUFFER__SIZE]/2);
955 jj = 1;
956 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000957 if((min_std < 4) && (val[RW_LONG]))
958 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000959 printf("\tbytes avail on r/w long: %u",val[RW_LONG]);
960 jj = 1;
961 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000962 if((eqpt != CDROM) && (like_std > 3))
963 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000964 printf("\tQueue depth: %u",(val[QUEUE_DEPTH] & DEPTH_BITS)+1);
965 jj = 1;
966 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000967 if_printf(jj,"\n");
968
969 if(dev == ATA_DEV)
970 {
971 if(like_std == 1)
972 printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":"");
973 else
974 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000975 printf("\tStandby timer values: spec'd by ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000976 if_else_printf((val[CAPAB_0] & STD_STBY),"Standard","Vendor");
977 if((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
978 printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no");
979 else
980 printf("\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000981 }
982 printf("\tR/W multiple sector transfer: ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000983 if((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
Eric Andersen3443bd72003-07-22 07:30:36 +0000984 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +0000985 else
986 {
987 printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER);
988 if_else_printf((val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID),
989 "%u\n","?\n",val[SECTOR_XFER_CUR] & SECTOR_XFER);
Eric Andersen3443bd72003-07-22 07:30:36 +0000990 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000991 if((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008))
992 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000993 /* We print out elsewhere whether the APM feature is enabled or
994 not. If it's not enabled, let's not repeat the info; just print
995 nothing here. */
Glenn L McGrath07085852003-10-09 07:28:22 +0000996 printf("\tAdvancedPM level: ");
997 if ( (val[ADV_PWR] & 0xFF00) == 0x4000 )
998 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000999 uint8_t apm_level = val[ADV_PWR] & 0x00FF;
Eric Andersen3443bd72003-07-22 07:30:36 +00001000 printf("%u (0x%x)\n", apm_level, apm_level);
Glenn L McGrath07085852003-10-09 07:28:22 +00001001 }
1002 else
Eric Andersen3443bd72003-07-22 07:30:36 +00001003 printf("unknown setting (0x%04x)\n", val[ADV_PWR]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001004 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001005 if(like_std > 5)
1006 {
1007 if_printf(val[ACOUSTIC],"\tRecommended acoustic management value: %u, current value: %u\n",
1008 (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff);
Eric Andersen3443bd72003-07-22 07:30:36 +00001009 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001010 }
1011 else
1012 {
1013 /* ATAPI */
1014 if(eqpt != CDROM)
1015 if_printf((val[CAPAB_0] & SWRST_REQ),"\tATA sw reset required\n");
1016
1017 if(val[PKT_REL] || val[SVC_NBSY])
1018 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001019 printf("\tOverlap support:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001020 if_printf(val[PKT_REL]," %uus to release bus.",val[PKT_REL]);
1021 if_printf(val[SVC_NBSY]," %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001022 printf("\n");
1023 }
1024 }
1025
1026 /* DMA stuff. Check that only one DMA mode is selected. */
1027 printf("\tDMA: ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001028 if(!(val[CAPAB_0] & DMA_SUP))
Eric Andersen3443bd72003-07-22 07:30:36 +00001029 printf("not supported\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001030 else
1031 {
1032 if_printf((val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]),
1033 " sdma%u\n",(val[DMA_MODE] & MODE) >> 8);
1034 if(val[SINGLE_DMA])
1035 {
1036 jj = val[SINGLE_DMA];
1037 kk = val[SINGLE_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001038 err_dma += mode_loop(jj,kk,'s',&have_mode);
1039 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001040 if(val[MULTI_DMA])
1041 {
1042 jj = val[MULTI_DMA];
1043 kk = val[MULTI_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001044 err_dma += mode_loop(jj,kk,'m',&have_mode);
1045 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001046 if((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA])
1047 {
1048 jj = val[ULTRA_DMA];
1049 kk = val[ULTRA_DMA] >> 8;
Eric Andersen3443bd72003-07-22 07:30:36 +00001050 err_dma += mode_loop(jj,kk,'u',&have_mode);
1051 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001052 if_printf((err_dma || !have_mode),"(?)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001053 printf("\n");
1054
Glenn L McGrath07085852003-10-09 07:28:22 +00001055 if_printf(((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)),
1056 "\t Interleaved DMA support\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001057
Eric Andersenc7bda1c2004-03-15 08:29:22 +00001058 if((val[WHATS_VALID] & OK_W64_70) &&
Glenn L McGrath07085852003-10-09 07:28:22 +00001059 (val[DMA_TIME_MIN] || val[DMA_TIME_NORM]))
1060 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001061 printf("\t Cycle time:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001062 if_printf(val[DMA_TIME_MIN]," min=%uns",val[DMA_TIME_MIN]);
1063 if_printf(val[DMA_TIME_NORM]," recommended=%uns",val[DMA_TIME_NORM]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001064 printf("\n");
1065 }
1066 }
1067
1068 /* Programmed IO stuff */
1069 printf("\tPIO: ");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001070 /* If a drive supports mode n (e.g. 3), it also supports all modes less
Eric Andersen3443bd72003-07-22 07:30:36 +00001071 * than n (e.g. 3, 2, 1 and 0). Print all the modes. */
Glenn L McGrath07085852003-10-09 07:28:22 +00001072 if((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP))
1073 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001074 jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007;
Glenn L McGrath07085852003-10-09 07:28:22 +00001075 for(ii = 0; ii <= PIO_MODE_MAX ; ii++)
1076 {
1077 if_printf((jj & 0x0001),"pio%d ",ii);
Eric Andersen3443bd72003-07-22 07:30:36 +00001078 jj >>=1;
1079 }
1080 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001081 }
1082 else if(((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) )
1083 {
1084 for(ii = 0; ii <= val[PIO_MODE]>>8; ii++)
Eric Andersen3443bd72003-07-22 07:30:36 +00001085 printf("pio%d ",ii);
Eric Andersen3443bd72003-07-22 07:30:36 +00001086 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001087 }
1088 else
1089 printf("unknown\n");
1090
1091 if(val[WHATS_VALID] & OK_W64_70)
1092 {
1093 if(val[PIO_NO_FLOW] || val[PIO_FLOW])
1094 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001095 printf("\t Cycle time:");
Glenn L McGrath07085852003-10-09 07:28:22 +00001096 if_printf(val[PIO_NO_FLOW]," no flow control=%uns", val[PIO_NO_FLOW]);
1097 if_printf(val[PIO_FLOW]," IORDY flow control=%uns", val[PIO_FLOW]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001098 printf("\n");
1099 }
1100 }
1101
Glenn L McGrath07085852003-10-09 07:28:22 +00001102 if((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
1103 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001104 printf("Commands/features:\n\tEnabled\tSupported:\n");
1105 jj = val[CMDS_SUPP_0];
1106 kk = val[CMDS_EN_0];
Glenn L McGrath07085852003-10-09 07:28:22 +00001107 for(ii = 0; ii < NUM_CMD_FEAT_STR; ii++)
1108 {
1109 if((jj & 0x8000) && (*cmd_feat_str[ii] != '\0'))
1110 {
1111 if_else_printf((kk & 0x8000),"\t *","\t");
Eric Andersen3443bd72003-07-22 07:30:36 +00001112 printf("\t%s\n",cmd_feat_str[ii]);
1113 }
1114 jj <<=1; kk<<=1;
Glenn L McGrath07085852003-10-09 07:28:22 +00001115 if(ii%16 == 15)
1116 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001117 jj = val[CMDS_SUPP_0+1+(ii/16)];
1118 kk = val[CMDS_EN_0+1+(ii/16)];
1119 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001120 if(ii == 31)
1121 {
1122 if((val[CMDS_SUPP_2] & VALID) != VALID_VAL)
1123 ii +=16;
Eric Andersen3443bd72003-07-22 07:30:36 +00001124 }
1125 }
1126 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001127 if_printf(((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP),
1128 "\tRemovable Media Status Notification feature set supported\n");
1129
1130
Eric Andersen3443bd72003-07-22 07:30:36 +00001131 /* security */
Glenn L McGrath07085852003-10-09 07:28:22 +00001132 if((eqpt != CDROM) && (like_std > 3) &&
1133 (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME]))
1134 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001135 printf("Security: \n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001136 if_printf((val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)),
1137 "\tMaster password revision code = %u\n",val[PSWD_CODE]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001138 jj = val[SECU_STATUS];
Glenn L McGrath07085852003-10-09 07:28:22 +00001139 if(jj)
1140 {
1141 for(ii = 0; ii < NUM_SECU_STR; ii++)
1142 {
1143 if_else_printf((!(jj & 0x0001)),"\tnot\t%s\n", "\t\t%s\n", secu_str[ii]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001144 jj >>=1;
1145 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001146 if(val[SECU_STATUS] & SECU_ENABLED)
1147 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001148 printf("\tSecurity level ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001149 if_else_printf((val[SECU_STATUS] & SECU_LEVEL),"maximum\n","high\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001150 }
1151 }
1152 jj = val[ERASE_TIME] & ERASE_BITS;
1153 kk = val[ENH_ERASE_TIME] & ERASE_BITS;
Glenn L McGrath07085852003-10-09 07:28:22 +00001154 if(jj || kk)
1155 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001156 printf("\t");
Glenn L McGrath07085852003-10-09 07:28:22 +00001157 if_printf(jj,"%umin for SECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1);
1158 if_printf(kk,"%umin for ENHANCED SECURITY ERASE UNIT.", kk==ERASE_BITS ? 508 : kk<<1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001159 printf("\n");
1160 }
1161 }
1162
1163 /* reset result */
Glenn L McGrath07085852003-10-09 07:28:22 +00001164 if((val[HWRST_RSLT] & VALID) == VALID_VAL)
1165 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001166 printf("HW reset results:\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001167 if_else_printf((val[HWRST_RSLT] & CBLID),"\tCBLID- above Vih\n","\tCBLID- below Vih\n");
1168
1169 if(val[HWRST_RSLT] & RST0)
1170 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001171 printf("\tDevice num = 0");
1172 jj = val[HWRST_RSLT];
Glenn L McGrath07085852003-10-09 07:28:22 +00001173 }
1174 else
1175 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001176 printf("\tDevice num = 1");
1177 jj = val[HWRST_RSLT] >> 8;
1178 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001179
1180 if((jj & DEV_DET) == JUMPER_VAL)
Eric Andersen3443bd72003-07-22 07:30:36 +00001181 printf(" determined by the jumper");
1182 else if((jj & DEV_DET) == CSEL_VAL)
1183 printf(" determined by CSEL");
1184 printf("\n");
1185 }
1186
1187 /* more stuff from std 5 */
Glenn L McGrath07085852003-10-09 07:28:22 +00001188 if((like_std > 4) && (eqpt != CDROM))
1189 {
1190 if(val[CFA_PWR_MODE] & VALID_W160)
1191 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001192 printf("CFA power mode 1:\n\t");
Glenn L McGrath07085852003-10-09 07:28:22 +00001193 if_else_printf((val[CFA_PWR_MODE] & PWR_MODE_OFF),"disabled","enabled");
1194
1195 if_printf((val[CFA_PWR_MODE] & PWR_MODE_REQ)," and required by some commands");
Eric Andersen3443bd72003-07-22 07:30:36 +00001196 printf("\n");
Glenn L McGrath07085852003-10-09 07:28:22 +00001197
1198 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 +00001199 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001200 if((val[INTEGRITY] & SIG) == SIG_VAL)
1201 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001202 printf("Checksum: ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001203 if_printf(chksum,"in");
Eric Andersen3443bd72003-07-22 07:30:36 +00001204 printf("correct\n");
1205 }
1206 }
1207
1208 exit(0);
1209}
1210#endif
1211
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001212static int verbose, get_identity, get_geom, noisy = 1, quiet;
1213static int flagcount, do_flush, is_scsi_hd, is_xt_hd;
1214static int do_ctimings, do_timings;
Eric Andersen3443bd72003-07-22 07:30:36 +00001215
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001216static unsigned long set_readahead, get_readahead, Xreadahead;
1217static unsigned long set_readonly, get_readonly, readonly;
1218static unsigned long set_unmask, get_unmask, unmask;
1219static unsigned long set_mult, get_mult, mult;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001220#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001221static unsigned long set_dma, get_dma, dma;
Eric Andersenf1c56a92003-08-08 22:13:41 +00001222#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001223static unsigned long set_dma_q, get_dma_q, dma_q;
1224static unsigned long set_nowerr, get_nowerr, nowerr;
1225static unsigned long set_keep, get_keep, keep;
1226static unsigned long set_io32bit, get_io32bit, io32bit;
1227static unsigned long set_piomode, noisy_piomode;
1228static int piomode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001229#ifdef HDIO_DRIVE_CMD
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001230static unsigned long set_dkeep, get_dkeep, dkeep;
1231static unsigned long set_standby, get_standby, standby_requested;
1232static unsigned long set_xfermode, get_xfermode;
1233static int xfermode_requested;
1234static unsigned long set_lookahead, get_lookahead, lookahead;
1235static unsigned long set_prefetch, get_prefetch, prefetch;
1236static unsigned long set_defects, get_defects, defects;
1237static unsigned long set_wcache, get_wcache, wcache;
1238static unsigned long set_doorlock, get_doorlock, doorlock;
1239static unsigned long set_seagate, get_seagate;
1240static unsigned long set_standbynow, get_standbynow;
1241static unsigned long set_sleepnow, get_sleepnow;
1242static unsigned long get_powermode;
1243static unsigned long set_apmmode, get_apmmode, apmmode;
Eric Andersen3443bd72003-07-22 07:30:36 +00001244#endif
1245#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001246static int get_IDentity;
Eric Andersen3443bd72003-07-22 07:30:36 +00001247#endif
1248#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001249static int unregister_hwif;
1250static int hwif;
Eric Andersen3443bd72003-07-22 07:30:36 +00001251#endif
1252#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001253static int scan_hwif;
1254static int hwif_data;
1255static int hwif_ctrl;
1256static int hwif_irq;
Eric Andersen3443bd72003-07-22 07:30:36 +00001257#endif
1258#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001259static int set_busstate, get_busstate, busstate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001260#endif
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001261static int reread_partn;
Eric Andersen3443bd72003-07-22 07:30:36 +00001262
1263#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001264static int perform_reset;
Eric Andersen3443bd72003-07-22 07:30:36 +00001265#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
1266#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001267static int perform_tristate, tristate;
Eric Andersen3443bd72003-07-22 07:30:36 +00001268#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
1269
1270// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then
1271// then the HDIO_GET_IDENTITY only returned 142 bytes.
1272// Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes,
1273// and HDIO_GET_IDENTITY returns 512 bytes. But the latest
1274// 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY
1275// (which they should, but they should just return -EINVAL).
1276//
1277// So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes.
1278// On a really old system, it will not, and we will be confused.
1279// Too bad, really.
1280
1281#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001282static const char * const cfg_str[] =
Eric Andersen3443bd72003-07-22 07:30:36 +00001283{ "", " HardSect", " SoftSect", " NotMFM",
1284 " HdSw>15uSec", " SpinMotCtl", " Fixed", " Removeable",
1285 " DTR<=5Mbs", " DTR>5Mbs", " DTR>10Mbs", " RotSpdTol>.5%",
1286 " dStbOff", " TrkOff", " FmtGapReq", " nonMagnetic"
1287};
1288
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001289static const char * const BuffType[] = {"unknown", "1Sect", "DualPort", "DualPortCache"};
Eric Andersen3443bd72003-07-22 07:30:36 +00001290
Eric Andersen3443bd72003-07-22 07:30:36 +00001291static void dump_identity (const struct hd_driveid *id)
1292{
1293 int i;
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001294 char pmodes[64], dmodes[128], umodes[128];
Eric Andersen3443bd72003-07-22 07:30:36 +00001295 const unsigned short int *id_regs= (const void*) id;
1296 unsigned long capacity;
1297
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001298 pmodes[0] = dmodes[0] = umodes[0] = '\0';
1299
Glenn L McGrath07085852003-10-09 07:28:22 +00001300 printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={",
1301 id->model, id->fw_rev, id->serial_no);
1302 for (i=0; i<=15; i++)
1303 if_printf((id->config & (1<<i)),"%s", cfg_str[i]);
1304
1305 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n",
1306 id->cyls, id->heads, id->sectors, id->track_bytes,
1307 id->sector_bytes, id->ecc_bytes);
1308
1309 if (id->buf_type > 3)
1310 printf("%s%u", " BuffType=", id->buf_type);
1311 else
1312 printf("%s%s", " BuffType=", BuffType[id->buf_type]);
1313
Eric Andersen3443bd72003-07-22 07:30:36 +00001314 printf(", BuffSize=%ukB, MaxMultSect=%u", id->buf_size/2, id->max_multsect);
Glenn L McGrath07085852003-10-09 07:28:22 +00001315 if (id->max_multsect)
1316 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001317 printf(", MultSect=");
1318 if (!(id->multsect_valid&1))
1319 printf("?%u?", id->multsect);
1320 else if (id->multsect)
1321 printf("%u", id->multsect);
1322 else
1323 printf("off");
1324 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001325 printf("\n");
1326 if (id->tPIO <= 5)
1327 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001328 strcat(pmodes, "pio0 ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001329 if_strcat((id->tPIO >= 1), pmodes, "pio1 ");
1330 if_strcat((id->tPIO >= 2), pmodes, "pio2 ");
1331
Eric Andersen3443bd72003-07-22 07:30:36 +00001332 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001333 if_printf((!(id->field_valid&1))," (maybe):");
Eric Andersen3443bd72003-07-22 07:30:36 +00001334#if __BYTE_ORDER == __BIG_ENDIAN
1335 capacity = (id->cur_capacity0 << 16) | id->cur_capacity1;
1336#else
1337 capacity = (id->cur_capacity1 << 16) | id->cur_capacity0;
1338#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001339 printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001340 id->cur_sectors, capacity ,
1341 ((id->capability&2)==0)?"no":"yes");
Eric Andersen3443bd72003-07-22 07:30:36 +00001342
Glenn L McGrath07085852003-10-09 07:28:22 +00001343 if_printf((id->capability&2),", LBAsects=%u", id->lba_capacity);
1344
1345 if (id->capability&1)
1346 {
1347 if (id->dma_1word | id->dma_mword)
1348 {
1349 if_strcat((id->dma_1word & 0x100), dmodes, "*");
1350 if_strcat((id->dma_1word & 1), dmodes, "sdma0 ");
1351 if_strcat((id->dma_1word & 0x200), dmodes, "*");
1352 if_strcat((id->dma_1word & 2), dmodes, "sdma1 ");
1353 if_strcat((id->dma_1word & 0x400), dmodes, "*");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001354 if_strcat((id->dma_1word & 4), dmodes, "sdma2 ");
Glenn L McGrath07085852003-10-09 07:28:22 +00001355 if_strcat((id->dma_1word & 0xf800), dmodes, "*");
1356 if_strcat((id->dma_1word & 0xf8), dmodes, "sdma? ");
1357 if_strcat((id->dma_mword & 0x100), dmodes, "*");
1358 if_strcat((id->dma_mword & 1), dmodes, "mdma0 ");
1359 if_strcat((id->dma_mword & 0x200), dmodes, "*");
1360 if_strcat((id->dma_mword & 2), dmodes, "mdma1 ");
1361 if_strcat((id->dma_mword & 0x400), dmodes, "*");
1362 if_strcat((id->dma_mword & 4), dmodes, "mdma2 ");
1363 if_strcat((id->dma_mword & 0xf800), dmodes, "*");
1364 if_strcat((id->dma_mword & 0xf8), dmodes, "mdma? ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001365 }
1366 }
1367 printf("\n IORDY=");
1368 if (id->capability&8)
1369 printf((id->capability&4) ? "on/off" : "yes");
1370 else
1371 printf("no");
Eric Andersen3443bd72003-07-22 07:30:36 +00001372
Glenn L McGrath07085852003-10-09 07:28:22 +00001373 if ((id->capability&8) || (id->field_valid&2))
1374 {
1375 if (id->field_valid&2)
1376 {
1377 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
1378 if_strcat((id->eide_pio_modes & 1), pmodes, "pio3 ");
1379 if_strcat((id->eide_pio_modes & 2), pmodes, "pio4 ");
1380 if_strcat((id->eide_pio_modes &~3), pmodes, "pio? ");
1381 }
1382 if (id->field_valid&4)
1383 {
1384 if_strcat((id->dma_ultra & 0x100),umodes,"*");
1385 if_strcat((id->dma_ultra & 0x001),umodes,"udma0 ");
1386 if_strcat((id->dma_ultra & 0x200),umodes,"*");
1387 if_strcat((id->dma_ultra & 0x002),umodes,"udma1 ");
1388 if_strcat((id->dma_ultra & 0x400),umodes,"*");
1389 if_strcat((id->dma_ultra & 0x004),umodes,"udma2 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001390#ifdef __NEW_HD_DRIVE_ID
Glenn L McGrath07085852003-10-09 07:28:22 +00001391 if (id->hw_config & 0x2000)
1392 {
1393#else /* !__NEW_HD_DRIVE_ID */
1394 if (id->word93 & 0x2000)
1395 {
1396#endif /* __NEW_HD_DRIVE_ID */
1397 if_strcat((id->dma_ultra & 0x0800),umodes,"*");
1398 if_strcat((id->dma_ultra & 0x0008),umodes,"udma3 ");
1399 if_strcat((id->dma_ultra & 0x1000),umodes,"*");
1400 if_strcat((id->dma_ultra & 0x0010),umodes,"udma4 ");
1401 if_strcat((id->dma_ultra & 0x2000),umodes,"*");
1402 if_strcat((id->dma_ultra & 0x0020),umodes,"udma5 ");
1403 if_strcat((id->dma_ultra & 0x4000),umodes,"*");
1404 if_strcat((id->dma_ultra & 0x0040),umodes,"udma6 ");
1405 if_strcat((id->dma_ultra & 0x8000),umodes,"*");
1406 if_strcat((id->dma_ultra & 0x0080),umodes,"udma7 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001407 }
1408 }
1409 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001410 if_printf(((id->capability&1) && (id->field_valid&2)),
1411 ", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time);
1412 printf("\n PIO modes: %s", pmodes);
1413 if_printf((*dmodes),"\n DMA modes: %s", dmodes);
1414 if_printf((*umodes),"\n UDMA modes: %s", umodes);
1415
1416 printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes");
1417 if (id_regs[83] & 8)
1418 {
1419 if (!(id_regs[86]&8))
1420 printf(": disabled (255)");
1421 else if ((id_regs[91]&0xFF00)!=0x4000)
1422 printf(": unknown setting");
1423 else
1424 printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF);
1425 }
1426 if_printf( (id_regs[82]&0x20)," WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled");
1427#ifdef __NEW_HD_DRIVE_ID
1428 if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31))
1429 {
1430 printf("\n Drive conforms to: ");
1431 if_else_printf((id->minor_rev_num <= 31),"%s: ","unknown: ", minor_str[id->minor_rev_num]);
1432 if (id->major_rev_num < 31)
1433 {
1434 for (i=0; i <= 15; i++)
1435 if_printf((id->major_rev_num & (1<<i))," %u", i);
1436 }
1437 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001438#endif /* __NEW_HD_DRIVE_ID */
Glenn L McGrath07085852003-10-09 07:28:22 +00001439 printf("\n\n * signifies the current active mode\n\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001440}
1441#endif
1442
1443static void flush_buffer_cache (int fd)
1444{
1445 fsync (fd); /* flush buffers */
Glenn L McGrath07085852003-10-09 07:28:22 +00001446 bb_ioctl(fd, BLKFLSBUF, NULL,"BLKFLSBUF" ) ;/* do it again, big time */
Eric Andersen3443bd72003-07-22 07:30:36 +00001447#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001448 sleep(1);
1449 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */
Eric Andersen06d4ec22004-03-19 10:53:52 +00001450 bb_perror_msg("HDIO_DRIVE_CMD");
Eric Andersen3443bd72003-07-22 07:30:36 +00001451#endif
1452}
1453
1454static int seek_to_zero (int fd)
1455{
Glenn L McGrath07085852003-10-09 07:28:22 +00001456 if (lseek(fd, (off_t) 0, SEEK_SET))
Eric Andersen3443bd72003-07-22 07:30:36 +00001457 return 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001458 return 0;
1459}
1460
1461static int read_big_block (int fd, char *buf)
1462{
Glenn L McGrath07085852003-10-09 07:28:22 +00001463
1464 const char *string;
Eric Andersen3443bd72003-07-22 07:30:36 +00001465 int i, rc;
Glenn L McGrath07085852003-10-09 07:28:22 +00001466 if ((rc = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES)
1467 {
1468 switch(rc)
1469 {
1470 case -1:
1471 string = "read()";
1472 break;
1473 case 0:
1474 string = "read() hit EOF - device too small";
1475 break;
1476 default:
1477 string = "read(%u) returned %u bytes";
Eric Andersen3443bd72003-07-22 07:30:36 +00001478 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001479 bb_error_msg(string, TIMING_BUF_BYTES, rc);
Eric Andersen3443bd72003-07-22 07:30:36 +00001480 return 1;
1481 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001482
Eric Andersen3443bd72003-07-22 07:30:36 +00001483 /* access all sectors of buf to ensure the read fully completed */
1484 for (i = 0; i < TIMING_BUF_BYTES; i += 512)
1485 buf[i] &= 1;
1486 return 0;
1487}
1488
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00001489static double correction;
Eric Andersen50af12d2003-08-06 08:47:59 +00001490
Eric Andersen06d4ec22004-03-19 10:53:52 +00001491static void do_time (int flag, int fd)
Glenn L McGrath07085852003-10-09 07:28:22 +00001492/*
1493 flag = 0 time_cache
1494 flag = 1 time_device
1495*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001496{
Eric Andersen50af12d2003-08-06 08:47:59 +00001497 int i;
Eric Andersen3443bd72003-07-22 07:30:36 +00001498 char *buf;
1499 double elapsed;
1500 struct itimerval e1, e2;
1501 int shmid;
Eric Andersen50af12d2003-08-06 08:47:59 +00001502 int timing_MB = TIMING_MB;
Eric Andersen3443bd72003-07-22 07:30:36 +00001503
Glenn L McGrath07085852003-10-09 07:28:22 +00001504 if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1)
1505 {
1506 bb_error_msg (bb_msg_shared_mem,"allocate"); /*"could not allocate sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001507 return;
1508 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001509 if (shmctl(shmid, SHM_LOCK, NULL) == -1)
1510 {
1511 bb_error_msg (bb_msg_shared_mem,"lock"); /*"could not lock sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001512 (void) shmctl(shmid, IPC_RMID, NULL);
1513 return;
1514 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001515 if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1)
1516 {
1517 bb_error_msg (bb_msg_shared_mem,"attach"); /*"could not attach sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001518 (void) shmctl(shmid, IPC_RMID, NULL);
1519 return;
1520 }
1521 if (shmctl(shmid, IPC_RMID, NULL) == -1)
Glenn L McGrath07085852003-10-09 07:28:22 +00001522 bb_error_msg ("shmctl(,IPC_RMID,)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001523
1524 /* Clear out the device request queues & give them time to complete */
Glenn L McGrath07085852003-10-09 07:28:22 +00001525 sync_and_sleep(3);
Eric Andersen3443bd72003-07-22 07:30:36 +00001526
Glenn L McGrath07085852003-10-09 07:28:22 +00001527 if(flag == 0) /* Time cache */
1528 {
1529 /* Calculate a correction factor for the basic
1530 * overhead of doing a read() from the buffer cache.
1531 * To do this, we read the data once to "cache it" and
1532 * to force full preallocation of our timing buffer,
1533 * and then we re-read it 10 times while timing it.
1534 *
1535 * getitimer() is used rather than gettimeofday() because
1536 * it is much more consistent (on my machine, at least).
1537 */
1538 setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
1539 if (seek_to_zero (fd))
1540 return;
1541 if (read_big_block (fd, buf))
1542 return;
1543 printf(" Timing buffer-cache reads: ");
1544 fflush(stdout);
Eric Andersen3443bd72003-07-22 07:30:36 +00001545
Glenn L McGrath07085852003-10-09 07:28:22 +00001546 /* Clear out the device request queues & give them time to complete */
1547 sync_and_sleep(1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001548
Glenn L McGrath07085852003-10-09 07:28:22 +00001549 /* Time re-reading from the buffer-cache */
1550 getitimer(ITIMER_REAL, &e1);
1551 for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i)
1552 {
1553 if (seek_to_zero (fd))
1554 goto quit;
1555 if (read_big_block (fd, buf))
1556 goto quit;
1557 }
1558 getitimer(ITIMER_REAL, &e2);
1559 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 +00001560
Glenn L McGrath07085852003-10-09 07:28:22 +00001561 /* Now remove the lseek() from the correction factor */
1562 getitimer(ITIMER_REAL, &e1);
1563 for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i)
1564 {
1565 if (seek_to_zero (fd))
1566 goto quit;
1567 }
1568 getitimer(ITIMER_REAL, &e2);
1569 correction -= (e1.it_value.tv_sec - e2.it_value.tv_sec)
1570 + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
Eric Andersen50af12d2003-08-06 08:47:59 +00001571
Glenn L McGrath07085852003-10-09 07:28:22 +00001572 if ((BUFCACHE_FACTOR * timing_MB) >= correction) /* more than 1MB/s */
Eric Andersen50af12d2003-08-06 08:47:59 +00001573 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",
Glenn L McGrath07085852003-10-09 07:28:22 +00001574 (BUFCACHE_FACTOR * timing_MB), correction,
1575 (BUFCACHE_FACTOR * timing_MB) / correction);
Eric Andersen50af12d2003-08-06 08:47:59 +00001576 else
1577 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",
Glenn L McGrath07085852003-10-09 07:28:22 +00001578 (BUFCACHE_FACTOR * timing_MB), correction,
1579 (BUFCACHE_FACTOR * timing_MB) / correction * 1024);
1580 correction /= BUFCACHE_FACTOR;
1581
1582 flush_buffer_cache(fd);
1583 sleep(1);
Eric Andersen50af12d2003-08-06 08:47:59 +00001584 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001585 else /* Time device */
1586 {
1587 printf(" Timing buffered disk reads: ");
1588 fflush(stdout);
1589
1590 /*
1591 * getitimer() is used rather than gettimeofday() because
1592 * it is much more consistent (on my machine, at least).
1593 */
1594 setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL);
1595
1596 /* Now do the timings for real */
1597 getitimer(ITIMER_REAL, &e1);
1598 for (i = TIMING_BUF_COUNT; i > 0; --i)
1599 {
1600 if (read_big_block (fd, buf))
1601 goto quit;
1602 }
1603 getitimer(ITIMER_REAL, &e2);
1604
1605 elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0);
1606
1607 if (timing_MB >= elapsed) /* more than 1MB/s */
1608 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",timing_MB, elapsed, timing_MB / elapsed);
1609 else
1610 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",timing_MB, elapsed, timing_MB / elapsed * 1024);
1611
1612 /*"Hmm.. suspicious results: probably not enough free memory for a proper test.");*/
1613 if (elapsed <= (correction * 2))
1614 bb_error_msg(bb_msg_memory_exhausted);
1615
1616#if 0 /* the "estimate" is just plain wrong for many systems.. */
1617 else if (correction != 0.0) {
1618 printf(" Estimating raw driver speed: ");
1619 elapsed -= correction;
1620 if (timing_MB >= elapsed) /* more than 1MB/s */
1621 printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",
1622 timing_MB, elapsed, timing_MB / elapsed);
1623 else
1624 printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",
1625 timing_MB, elapsed, timing_MB / elapsed * 1024);
1626 }
Eric Andersen50af12d2003-08-06 08:47:59 +00001627#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001628 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001629quit:
1630 if (-1 == shmdt(buf))
Glenn L McGrath07085852003-10-09 07:28:22 +00001631 bb_error_msg (bb_msg_shared_mem,"detach"); /*"could not detach sharedmem buf"*/
Eric Andersen3443bd72003-07-22 07:30:36 +00001632}
1633
Glenn L McGrath07085852003-10-09 07:28:22 +00001634
Eric Andersen3443bd72003-07-22 07:30:36 +00001635static void no_scsi (void)
1636{
Glenn L McGrath07085852003-10-09 07:28:22 +00001637 /*" operation not supported on SCSI disks"*/
1638 if (is_scsi_hd)
1639 bb_error_msg_and_die(bb_msg_op_not_supp,"SCSI");
Eric Andersen3443bd72003-07-22 07:30:36 +00001640}
1641
1642static void no_xt (void)
1643{
Glenn L McGrath07085852003-10-09 07:28:22 +00001644 if (is_xt_hd)
1645 bb_error_msg_and_die(bb_msg_op_not_supp,"XT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001646}
1647
1648static void on_off (unsigned int value)
1649{
1650 printf(value ? " (on)\n" : " (off)\n");
1651}
1652
1653#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
1654static void bus_state_value (unsigned int value)
1655{
1656 const char *string;
1657
Glenn L McGrath07085852003-10-09 07:28:22 +00001658 switch (value)
1659 {
1660 case BUSSTATE_ON:
1661 string = " (on)\n";
1662 break;
1663 case BUSSTATE_OFF:
1664 string = " (off)\n";
1665 break;
1666 case BUSSTATE_TRISTATE:
1667 string = " (tristate)\n";
1668 break;
1669 default:
1670 string = " (unknown: %d)\n";
1671 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001672 }
1673 printf(string, value);
1674}
1675#endif
1676
1677#ifdef HDIO_DRIVE_CMD
1678static void interpret_standby (unsigned int standby)
1679{
1680 printf(" (");
Glenn L McGrath07085852003-10-09 07:28:22 +00001681 switch(standby)
1682 {
1683 case 0:
1684 printf("off");
1685 break;
1686 case 252:
1687 printf("21 minutes");
1688 break;
1689 case 253:
1690 printf("vendor-specific");
1691 break;
1692 case 254:
1693 printf("?reserved");
1694 break;
1695 case 255:
1696 printf("21 minutes + 15 seconds");
1697 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001698 default:
Glenn L McGrath07085852003-10-09 07:28:22 +00001699 if (standby <= 240)
1700 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001701 unsigned int secs = standby * 5;
1702 unsigned int mins = secs / 60;
1703 secs %= 60;
Glenn L McGrath07085852003-10-09 07:28:22 +00001704 if_printf(mins,"%u minutes", mins);
1705 if_printf((mins && secs)," + ");
1706 if_printf(secs,"%u seconds", secs);
1707 }
1708 else if (standby <= 251)
1709 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001710 unsigned int mins = (standby - 240) * 30;
1711 unsigned int hrs = mins / 60;
1712 mins %= 60;
Glenn L McGrath07085852003-10-09 07:28:22 +00001713 if_printf(hrs,"%u hours", hrs);
1714 if_printf((hrs && mins)," + ");
1715 if_printf(mins,"%u minutes", mins);
1716 }
1717 else
Eric Andersen3443bd72003-07-22 07:30:36 +00001718 printf("illegal value");
1719 break;
1720 }
1721 printf(")\n");
1722}
1723
1724struct xfermode_entry {
1725 int val;
1726 const char *name;
1727};
1728
1729static const struct xfermode_entry xfermode_table[] = {
1730 { 8, "pio0" },
1731 { 9, "pio1" },
1732 { 10, "pio2" },
1733 { 11, "pio3" },
1734 { 12, "pio4" },
1735 { 13, "pio5" },
1736 { 14, "pio6" },
1737 { 15, "pio7" },
1738 { 16, "sdma0" },
1739 { 17, "sdma1" },
1740 { 18, "sdma2" },
1741 { 19, "sdma3" },
1742 { 20, "sdma4" },
1743 { 21, "sdma5" },
1744 { 22, "sdma6" },
1745 { 23, "sdma7" },
1746 { 32, "mdma0" },
1747 { 33, "mdma1" },
1748 { 34, "mdma2" },
1749 { 35, "mdma3" },
1750 { 36, "mdma4" },
1751 { 37, "mdma5" },
1752 { 38, "mdma6" },
1753 { 39, "mdma7" },
1754 { 64, "udma0" },
1755 { 65, "udma1" },
1756 { 66, "udma2" },
1757 { 67, "udma3" },
1758 { 68, "udma4" },
1759 { 69, "udma5" },
1760 { 70, "udma6" },
1761 { 71, "udma7" },
1762 { 0, NULL }
1763};
1764
1765static int translate_xfermode(char * name)
1766{
Glenn L McGrath07085852003-10-09 07:28:22 +00001767 const struct xfermode_entry *tmp;
1768 char *endptr;
1769 int val = -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001770
1771
Glenn L McGrath07085852003-10-09 07:28:22 +00001772 for (tmp = xfermode_table; tmp->name != NULL; ++tmp)
1773 {
1774 if (!strcmp(name, tmp->name))
1775 return tmp->val;
Eric Andersen3443bd72003-07-22 07:30:36 +00001776
Glenn L McGrath07085852003-10-09 07:28:22 +00001777 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001778
Glenn L McGrath07085852003-10-09 07:28:22 +00001779 val = strtol(name, &endptr, 10);
1780 if (*endptr == '\0')
1781 return val;
1782
1783 return -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001784}
1785
1786static void interpret_xfermode (unsigned int xfermode)
1787{
1788 printf(" (");
1789 switch(xfermode) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001790 case 0:
1791 printf("default PIO mode");
1792 break;
1793 case 1:
1794 printf("default PIO mode, disable IORDY");
1795 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001796 case 8:
1797 case 9:
1798 case 10:
1799 case 11:
1800 case 12:
1801 case 13:
1802 case 14:
Glenn L McGrath07085852003-10-09 07:28:22 +00001803 case 15:
1804 printf("PIO flow control mode%u", xfermode-8);
1805 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001806 case 16:
1807 case 17:
1808 case 18:
1809 case 19:
1810 case 20:
1811 case 21:
1812 case 22:
Glenn L McGrath07085852003-10-09 07:28:22 +00001813 case 23:
1814 printf("singleword DMA mode%u", xfermode-16);
1815 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001816 case 32:
1817 case 33:
1818 case 34:
1819 case 35:
1820 case 36:
1821 case 37:
1822 case 38:
Glenn L McGrath07085852003-10-09 07:28:22 +00001823 case 39:
1824 printf("multiword DMA mode%u", xfermode-32);
1825 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001826 case 64:
1827 case 65:
1828 case 66:
1829 case 67:
1830 case 68:
1831 case 69:
1832 case 70:
Glenn L McGrath07085852003-10-09 07:28:22 +00001833 case 71:
1834 printf("UltraDMA mode%u", xfermode-64);
1835 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001836 default:
Glenn L McGrath07085852003-10-09 07:28:22 +00001837 printf("unknown, probably not valid");
1838 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001839 }
1840 printf(")\n");
1841}
1842#endif /* HDIO_DRIVE_CMD */
1843
1844#ifndef VXVM_MAJOR
1845#define VXVM_MAJOR 199
1846#endif
1847
1848#ifndef CCISS_MAJOR
1849#define CCISS_MAJOR 104
1850#endif
1851
1852static void process_dev (char *devname)
1853{
1854 int fd;
1855 static long parm, multcount;
1856 struct stat stat_buf;
1857#ifndef HDIO_DRIVE_CMD
1858 int force_operation = 0;
1859#endif
Rob Landleyc5b1d4d2006-03-13 15:45:16 +00001860 xstat(devname,&stat_buf);
Eric Andersen3443bd72003-07-22 07:30:36 +00001861
Glenn L McGrath07085852003-10-09 07:28:22 +00001862 switch(major(stat_buf.st_rdev))
1863 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001864#ifdef SCSI_DISK0_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001865 case (SCSI_DISK0_MAJOR):
1866 case (SCSI_DISK1_MAJOR):
1867 case (SCSI_DISK2_MAJOR):
1868 case (SCSI_DISK3_MAJOR):
1869 case (SCSI_DISK4_MAJOR):
1870 case (SCSI_DISK5_MAJOR):
1871 case (SCSI_DISK6_MAJOR):
1872 case (SCSI_DISK7_MAJOR):
Eric Andersen3443bd72003-07-22 07:30:36 +00001873#else
Glenn L McGrath07085852003-10-09 07:28:22 +00001874 case (SCSI_DISK_MAJOR):
Eric Andersen3443bd72003-07-22 07:30:36 +00001875#endif
1876#ifdef MD_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001877 case (MD_MAJOR):
Eric Andersen3443bd72003-07-22 07:30:36 +00001878#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001879 case (VXVM_MAJOR):
Eric Andersen3443bd72003-07-22 07:30:36 +00001880#ifdef LVM_BLK_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001881 case (LVM_BLK_MAJOR):
Eric Andersen3443bd72003-07-22 07:30:36 +00001882#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001883 case (CCISS_MAJOR):
1884 is_scsi_hd = 1;
1885 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001886#ifdef XT_DISK_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001887 case (XT_DISK_MAJOR):
1888 is_xt_hd = 1;
1889 break;
Eric Andersen3443bd72003-07-22 07:30:36 +00001890#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001891 case IDE0_MAJOR:
1892 case IDE1_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001893#ifdef IDE2_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001894 case IDE2_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001895#endif
1896#ifdef IDE3_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001897 case IDE3_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001898#endif
1899#ifdef IDE4_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001900 case IDE4_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001901#endif
1902#ifdef IDE5_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001903 case IDE5_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001904#endif
1905#ifdef IDE6_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001906 case IDE6_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001907#endif
1908#ifdef IDE7_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001909 case IDE7_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001910#endif
1911#ifdef IDE8_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001912 case IDE8_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001913#endif
1914#ifdef IDE9_MAJOR
Glenn L McGrath07085852003-10-09 07:28:22 +00001915 case IDE9_MAJOR:
Eric Andersen3443bd72003-07-22 07:30:36 +00001916#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001917 break; /* do nothing */
1918 default:
1919 bb_error_msg_and_die("%s not supported",devname);
Eric Andersen3443bd72003-07-22 07:30:36 +00001920 }
1921
Glenn L McGrath07085852003-10-09 07:28:22 +00001922 fd = bb_xopen (devname, O_RDONLY|O_NONBLOCK);
1923 if_printf( (!quiet),"\n%s:\n", devname);
Eric Andersen3443bd72003-07-22 07:30:36 +00001924
Glenn L McGrath07085852003-10-09 07:28:22 +00001925 if (set_readahead)
1926 {
Eric Andersenf828da02004-07-20 22:53:59 +00001927 if_printf(get_readahead," setting fs readahead to %ld\n", Xreadahead);
1928 bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001929 }
1930#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001931 if (unregister_hwif)
1932 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001933 no_scsi();
1934 printf(" attempting to unregister hwif#%u\n", hwif);
Eric Andersena68ea1c2006-01-30 22:48:39 +00001935 bb_ioctl(fd, HDIO_UNREGISTER_HWIF,(int *)(unsigned long)hwif,"HDIO_UNREGISTER_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001936 }
1937#endif
1938#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00001939 if (scan_hwif)
1940 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001941 int args[3];
1942 no_scsi();
1943 printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq);
1944 args[0] = hwif_data;
1945 args[1] = hwif_ctrl;
1946 args[2] = hwif_irq;
Glenn L McGrath07085852003-10-09 07:28:22 +00001947 bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00001948 }
1949#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001950 if (set_piomode)
1951 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001952 no_scsi();
1953 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00001954
1955 if (noisy_piomode)
1956 {
1957 printf(" attempting to ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001958 if (piomode == 255)
Glenn L McGrath07085852003-10-09 07:28:22 +00001959 printf("auto-tune PIO mode\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001960 else if (piomode < 100)
Glenn L McGrath07085852003-10-09 07:28:22 +00001961 printf("set PIO mode to %d\n", piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001962 else if (piomode < 200)
Glenn L McGrath07085852003-10-09 07:28:22 +00001963 printf("set MDMA mode to %d\n", (piomode-100));
Eric Andersen3443bd72003-07-22 07:30:36 +00001964 else
Glenn L McGrath07085852003-10-09 07:28:22 +00001965 printf("set UDMA mode to %d\n", (piomode-200));
Eric Andersen3443bd72003-07-22 07:30:36 +00001966 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00001967 bb_ioctl(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode, "HDIO_SET_PIO_MODE");
Eric Andersen3443bd72003-07-22 07:30:36 +00001968 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001969 if (set_io32bit)
1970 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001971 no_scsi();
1972 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00001973 if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit);
1974 bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001975 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001976 if (set_mult)
1977 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001978 no_scsi();
1979 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00001980 if_printf(get_mult, " setting multcount to %ld\n", mult);
1981 if(ioctl(fd, HDIO_SET_MULTCOUNT, mult))
Eric Andersen06d4ec22004-03-19 10:53:52 +00001982 bb_perror_msg("HDIO_SET_MULTCOUNT");
Eric Andersen3443bd72003-07-22 07:30:36 +00001983#ifndef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001984 else
1985 force_operation = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001986#endif
1987 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001988 if (set_readonly)
1989 {
1990 if_printf_on_off(get_readonly," setting readonly to %ld", readonly);
1991 bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET");
Eric Andersen3443bd72003-07-22 07:30:36 +00001992 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001993 if (set_unmask)
1994 {
Eric Andersen3443bd72003-07-22 07:30:36 +00001995 no_scsi();
1996 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00001997 if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask);
1998 bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR");
Eric Andersen3443bd72003-07-22 07:30:36 +00001999 }
Eric Andersen0a57a792003-08-06 08:57:35 +00002000#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Glenn L McGrath07085852003-10-09 07:28:22 +00002001 if (set_dma)
2002 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002003 no_scsi();
Glenn L McGrath07085852003-10-09 07:28:22 +00002004 if_printf_on_off(get_dma," setting using_dma to %ld", dma);
2005 bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00002006 }
Eric Andersen0a57a792003-08-06 08:57:35 +00002007#endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
Glenn L McGrath07085852003-10-09 07:28:22 +00002008 if (set_dma_q)
2009 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002010 no_scsi();
Glenn L McGrath07085852003-10-09 07:28:22 +00002011 if_printf_on_off(get_dma_q," setting DMA queue_depth to %ld", dma_q);
2012 bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA");
Eric Andersen3443bd72003-07-22 07:30:36 +00002013 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002014 if (set_nowerr)
2015 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002016 no_scsi();
2017 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002018 if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr);
2019 bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR");
Eric Andersen3443bd72003-07-22 07:30:36 +00002020 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002021 if (set_keep)
2022 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002023 no_scsi();
2024 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002025 if_printf_on_off(get_keep," setting keep_settings to %ld", keep);
2026 bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS");
Eric Andersen3443bd72003-07-22 07:30:36 +00002027 }
2028#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00002029 if (set_doorlock)
2030 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002031 unsigned char args[4] = {0,0,0,0};
2032 no_scsi();
2033 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002034
Eric Andersen3443bd72003-07-22 07:30:36 +00002035 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
Glenn L McGrath07085852003-10-09 07:28:22 +00002036 if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock);
2037 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002038 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002039 if (set_dkeep)
2040 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002041 /* lock/unlock the drive's "feature" settings */
2042 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
2043 no_scsi();
2044 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002045
2046 if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep);
Eric Andersen3443bd72003-07-22 07:30:36 +00002047 args[2] = dkeep ? 0x66 : 0xcc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002048 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002049 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002050 if (set_defects)
2051 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002052 unsigned char args[4] = {WIN_SETFEATURES,0,0x04,0};
2053 no_scsi();
2054 args[2] = defects ? 0x04 : 0x84;
Glenn L McGrath07085852003-10-09 07:28:22 +00002055 if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects);
2056 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002057 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002058 if (set_prefetch)
2059 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002060 unsigned char args[4] = {WIN_SETFEATURES,0,0xab,0};
2061 no_scsi();
2062 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002063
Eric Andersen3443bd72003-07-22 07:30:36 +00002064 args[1] = prefetch;
Glenn L McGrath07085852003-10-09 07:28:22 +00002065 if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch);
2066 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002067 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002068 if (set_xfermode)
2069 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002070 unsigned char args[4] = {WIN_SETFEATURES,0,3,0};
2071 no_scsi();
2072 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002073
Eric Andersen3443bd72003-07-22 07:30:36 +00002074 args[1] = xfermode_requested;
Glenn L McGrath07085852003-10-09 07:28:22 +00002075 if (get_xfermode)
2076 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002077 printf(" setting xfermode to %d", xfermode_requested);
2078 interpret_xfermode(xfermode_requested);
2079 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002080 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002081 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002082 if (set_lookahead)
2083 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002084 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
2085 no_scsi();
2086 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002087
Eric Andersen3443bd72003-07-22 07:30:36 +00002088 args[2] = lookahead ? 0xaa : 0x55;
Glenn L McGrath07085852003-10-09 07:28:22 +00002089 if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead);
2090 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002091 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002092 if (set_apmmode)
2093 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002094 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
2095 no_scsi();
Eric Andersenb2aa7762004-04-05 13:08:08 +00002096 apmmode=check_if_min_and_set_val(apmmode,1);
2097 apmmode=check_if_maj_and_set_val(apmmode,255);
Glenn L McGrath07085852003-10-09 07:28:22 +00002098 if_printf(get_apmmode," setting APM level to");
2099 if (apmmode==255)
2100 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002101 /* disable Advanced Power Management */
Glenn L McGrath07085852003-10-09 07:28:22 +00002102 args[2] = 0x85; /* feature register */
2103 if_printf(get_apmmode," disabled\n");
2104 }
2105 else
2106 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002107 /* set Advanced Power Management mode */
Glenn L McGrath07085852003-10-09 07:28:22 +00002108 args[2] = 0x05; /* feature register */
Eric Andersen3443bd72003-07-22 07:30:36 +00002109 args[1] = apmmode; /* sector count register */
Glenn L McGrath07085852003-10-09 07:28:22 +00002110 if_printf(get_apmmode," 0x%02lX (%ld)\n",apmmode,apmmode);
2111 }
2112 bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD");
Eric Andersen3443bd72003-07-22 07:30:36 +00002113 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002114 if (set_wcache)
2115 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002116#ifdef DO_FLUSHCACHE
2117#ifndef WIN_FLUSHCACHE
2118#define WIN_FLUSHCACHE 0xe7
2119#endif
2120 unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0};
2121#endif /* DO_FLUSHCACHE */
2122 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
2123 no_scsi();
2124 no_xt();
2125 args[2] = wcache ? 0x02 : 0x82;
Glenn L McGrath07085852003-10-09 07:28:22 +00002126 if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache);
Eric Andersen3443bd72003-07-22 07:30:36 +00002127#ifdef DO_FLUSHCACHE
2128 if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002129 bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002130#endif /* DO_FLUSHCACHE */
Glenn L McGrath07085852003-10-09 07:28:22 +00002131 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002132#ifdef DO_FLUSHCACHE
2133 if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002134 bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002135#endif /* DO_FLUSHCACHE */
2136 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002137 if (set_standbynow)
2138 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002139#ifndef WIN_STANDBYNOW1
2140#define WIN_STANDBYNOW1 0xE0
2141#endif
2142#ifndef WIN_STANDBYNOW2
2143#define WIN_STANDBYNOW2 0x94
2144#endif
2145 unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0};
2146 unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0};
2147 no_scsi();
Glenn L McGrath07085852003-10-09 07:28:22 +00002148 if_printf(get_standbynow," issuing standby command\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002149 if (ioctl(fd, HDIO_DRIVE_CMD, &args1)
2150 && ioctl(fd, HDIO_DRIVE_CMD, &args2))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002151 bb_perror_msg("HDIO_DRIVE_CMD(standby)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002152 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002153 if (set_sleepnow)
2154 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002155#ifndef WIN_SLEEPNOW1
2156#define WIN_SLEEPNOW1 0xE6
2157#endif
2158#ifndef WIN_SLEEPNOW2
2159#define WIN_SLEEPNOW2 0x99
2160#endif
2161 unsigned char args1[4] = {WIN_SLEEPNOW1,0,0,0};
2162 unsigned char args2[4] = {WIN_SLEEPNOW2,0,0,0};
2163 no_scsi();
Glenn L McGrath07085852003-10-09 07:28:22 +00002164 if_printf(get_sleepnow," issuing sleep command\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002165 if (ioctl(fd, HDIO_DRIVE_CMD, &args1)
2166 && ioctl(fd, HDIO_DRIVE_CMD, &args2))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002167 bb_perror_msg("HDIO_DRIVE_CMD(sleep)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002168 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002169 if (set_seagate)
2170 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002171 unsigned char args[4] = {0xfb,0,0,0};
2172 no_scsi();
2173 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002174 if_printf(get_seagate," disabling Seagate auto powersaving mode\n");
2175 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002176 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002177 if (set_standby)
2178 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002179 unsigned char args[4] = {WIN_SETIDLE1,standby_requested,0,0};
2180 no_scsi();
2181 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002182 if (get_standby)
2183 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002184 printf(" setting standby to %lu", standby_requested);
2185 interpret_standby(standby_requested);
2186 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002187 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002188 }
2189#else /* HDIO_DRIVE_CMD */
Glenn L McGrath07085852003-10-09 07:28:22 +00002190 if (force_operation)
2191 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002192 char buf[512];
2193 flush_buffer_cache(fd);
2194 if (-1 == read(fd, buf, sizeof(buf)))
Glenn L McGrath07085852003-10-09 07:28:22 +00002195 bb_error_msg("access failed");
Eric Andersen3443bd72003-07-22 07:30:36 +00002196 }
2197#endif /* HDIO_DRIVE_CMD */
2198
2199 if (!flagcount)
2200 verbose = 1;
2201
Glenn L McGrath07085852003-10-09 07:28:22 +00002202 if ((verbose && !is_scsi_hd && !is_xt_hd) || get_mult || get_identity)
2203 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002204 no_scsi();
2205 multcount = -1;
Glenn L McGrath07085852003-10-09 07:28:22 +00002206 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount))
2207 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002208 if ((verbose && !is_xt_hd) || get_mult)
Eric Andersen06d4ec22004-03-19 10:53:52 +00002209 bb_perror_msg("HDIO_GET_MULTCOUNT");
Glenn L McGrath07085852003-10-09 07:28:22 +00002210 }
2211 else if (verbose | get_mult)
2212 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002213 printf(" multcount = %2ld", multcount);
2214 on_off(multcount);
2215 }
2216 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002217 if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit)
2218 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002219 no_scsi();
2220 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002221 if(ioctl(fd, HDIO_GET_32BIT, &parm))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002222 bb_perror_msg("HDIO_GET_32BIT");
Glenn L McGrath07085852003-10-09 07:28:22 +00002223 else
2224 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002225 printf(" IO_support =%3ld (", parm);
Glenn L McGrath07085852003-10-09 07:28:22 +00002226 switch (parm)
2227 {
2228 case 0:
2229 printf("default ");
2230 case 2:
2231 printf("16-bit)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002232 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002233 case 1:
2234 printf("32-bit)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002235 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002236 case 3:
2237 printf("32-bit w/sync)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002238 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002239 case 8:
2240 printf("Request-Queue-Bypass)\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00002241 break;
Glenn L McGrath07085852003-10-09 07:28:22 +00002242 default:
2243 printf("\?\?\?)\n");
2244 /*esac*/
Eric Andersen3443bd72003-07-22 07:30:36 +00002245 }
2246 }
2247 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002248 if ((verbose && !is_scsi_hd && !is_xt_hd) || get_unmask)
2249 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002250 no_scsi();
2251 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002252 bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm,
2253 "HDIO_GET_UNMASKINTR"," unmaskirq = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002254 }
2255
Glenn L McGrath07085852003-10-09 07:28:22 +00002256
Eric Andersen0a57a792003-08-06 08:57:35 +00002257#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Eric Andersen3443bd72003-07-22 07:30:36 +00002258 if ((verbose && !is_scsi_hd) || get_dma) {
2259 no_scsi();
Glenn L McGrath07085852003-10-09 07:28:22 +00002260 if(ioctl(fd, HDIO_GET_DMA, &parm))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002261 bb_perror_msg("HDIO_GET_DMA");
Glenn L McGrath07085852003-10-09 07:28:22 +00002262 else
2263 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002264 printf(" using_dma = %2ld", parm);
2265 if (parm == 8)
2266 printf(" (DMA-Assisted-PIO)\n");
2267 else
2268 on_off(parm);
2269 }
2270 }
2271#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002272 if (get_dma_q)
2273 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002274 no_scsi();
Glenn L McGrath07085852003-10-09 07:28:22 +00002275 bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm,
2276 "HDIO_GET_QDMA"," queue_depth = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002277 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002278 if ((verbose && !is_scsi_hd && !is_xt_hd) || get_keep)
2279 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002280 no_scsi();
2281 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002282 bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm,
2283 "HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002284 }
2285
Glenn L McGrath07085852003-10-09 07:28:22 +00002286 if (get_nowerr)
2287 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002288 no_scsi();
2289 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002290 bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm,
2291 " HDIO_GET_NOWERR"," nowerr = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002292 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002293 if (verbose || get_readonly)
2294 {
2295 bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm,
2296 " BLKROGET"," readonly = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002297 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002298 if ((verbose && !is_scsi_hd) || get_readahead)
2299 {
2300 bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm,
2301 " BLKRAGET"," readahead = %2ld");
Eric Andersen3443bd72003-07-22 07:30:36 +00002302 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002303 if (verbose || get_geom)
2304 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002305 static const char msg[] = " geometry = %u/%u/%u, sectors = %ld, start = %ld\n";
2306 static struct hd_geometry g;
2307#ifdef HDIO_GETGEO_BIG
2308 static struct hd_big_geometry bg;
2309#endif
2310
2311 if (ioctl(fd, BLKGETSIZE, &parm))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002312 bb_perror_msg("BLKGETSIZE");
Eric Andersen3443bd72003-07-22 07:30:36 +00002313#ifdef HDIO_GETGEO_BIG
2314 else if (!ioctl(fd, HDIO_GETGEO_BIG, &bg))
2315 printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start);
2316#endif
2317 else if (ioctl(fd, HDIO_GETGEO, &g))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002318 bb_perror_msg("HDIO_GETGEO");
Glenn L McGrath07085852003-10-09 07:28:22 +00002319 else
2320 printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start);
Eric Andersen3443bd72003-07-22 07:30:36 +00002321 }
2322#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00002323 if (get_powermode)
2324 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002325#ifndef WIN_CHECKPOWERMODE1
2326#define WIN_CHECKPOWERMODE1 0xE5
2327#endif
2328#ifndef WIN_CHECKPOWERMODE2
2329#define WIN_CHECKPOWERMODE2 0x98
2330#endif
2331 unsigned char args[4] = {WIN_CHECKPOWERMODE1,0,0,0};
2332 const char *state;
2333 no_scsi();
2334 if (ioctl(fd, HDIO_DRIVE_CMD, &args)
Glenn L McGrath07085852003-10-09 07:28:22 +00002335 && (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00002336 && ioctl(fd, HDIO_DRIVE_CMD, &args))
Glenn L McGrath07085852003-10-09 07:28:22 +00002337 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002338 if (errno != EIO || args[0] != 0 || args[1] != 0)
2339 state = "unknown";
2340 else
2341 state = "sleeping";
Eric Andersen3443bd72003-07-22 07:30:36 +00002342 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002343 else
2344 state = (args[2] == 255) ? "active/idle" : "standby";
2345
Eric Andersen3443bd72003-07-22 07:30:36 +00002346 printf(" drive state is: %s\n", state);
2347 }
2348#endif
2349#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
Glenn L McGrath07085852003-10-09 07:28:22 +00002350 if (perform_reset)
2351 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002352 no_scsi();
2353 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002354 bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET");
Eric Andersen3443bd72003-07-22 07:30:36 +00002355 }
2356#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
2357#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002358 if (perform_tristate)
2359 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002360 unsigned char args[4] = {0,tristate,0,0};
2361 no_scsi();
2362 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002363 bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF");
Eric Andersen3443bd72003-07-22 07:30:36 +00002364 }
2365#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
2366#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +00002367 if (get_identity)
2368 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002369 static struct hd_driveid id;
2370
2371 no_scsi();
2372 no_xt();
2373
Glenn L McGrath07085852003-10-09 07:28:22 +00002374 if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
2375 {
2376 if (multcount != -1)
2377 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002378 id.multsect = multcount;
2379 id.multsect_valid |= 1;
Glenn L McGrath07085852003-10-09 07:28:22 +00002380 }
2381 else
Eric Andersen3443bd72003-07-22 07:30:36 +00002382 id.multsect_valid &= ~1;
2383 dump_identity(&id);
Glenn L McGrath07085852003-10-09 07:28:22 +00002384 }
2385 else if (errno == -ENOMSG)
Eric Andersen3443bd72003-07-22 07:30:36 +00002386 printf(" no identification info available\n");
2387 else
Eric Andersen06d4ec22004-03-19 10:53:52 +00002388 bb_perror_msg("HDIO_GET_IDENTITY");
Eric Andersen3443bd72003-07-22 07:30:36 +00002389 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002390
2391 if (get_IDentity)
2392 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002393 unsigned char args[4+512] = {WIN_IDENTIFY,0,0,1,};
2394 unsigned i;
Glenn L McGrath07085852003-10-09 07:28:22 +00002395
Eric Andersen3443bd72003-07-22 07:30:36 +00002396 no_scsi();
2397 no_xt();
Glenn L McGrath07085852003-10-09 07:28:22 +00002398
2399 if (ioctl(fd, HDIO_DRIVE_CMD, &args))
2400 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002401 args[0] = WIN_PIDENTIFY;
Glenn L McGrath07085852003-10-09 07:28:22 +00002402 if (ioctl(fd, HDIO_DRIVE_CMD, &args))
2403 {
Eric Andersen06d4ec22004-03-19 10:53:52 +00002404 bb_perror_msg("HDIO_DRIVE_CMD(identify)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002405 goto identify_abort;
2406 }
2407 }
Glenn L McGrath07085852003-10-09 07:28:22 +00002408 for(i=0; i<(sizeof args)/2; i+=2)
Eric Andersen3443bd72003-07-22 07:30:36 +00002409 __le16_to_cpus((uint16_t *)(&args[i]));
Glenn L McGrath07085852003-10-09 07:28:22 +00002410
Eric Andersen3443bd72003-07-22 07:30:36 +00002411 identify((void *)&args[4], NULL);
Glenn L McGrath07085852003-10-09 07:28:22 +00002412identify_abort:
2413 /* VOID */;
Eric Andersen3443bd72003-07-22 07:30:36 +00002414 }
2415#endif
2416#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002417 if (set_busstate)
2418 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002419 no_scsi();
Glenn L McGrath07085852003-10-09 07:28:22 +00002420 if (get_busstate)
2421 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002422 printf(" setting bus state to %d", busstate);
2423 bus_state_value(busstate);
2424 }
Eric Andersena68ea1c2006-01-30 22:48:39 +00002425 bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE");
Eric Andersen3443bd72003-07-22 07:30:36 +00002426 }
2427#endif
2428#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Glenn L McGrath07085852003-10-09 07:28:22 +00002429 if (get_busstate)
2430 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002431 no_scsi();
2432 if (ioctl(fd, HDIO_GET_BUSSTATE, &parm))
Eric Andersen06d4ec22004-03-19 10:53:52 +00002433 bb_perror_msg("HDIO_GET_BUSSTATE");
Glenn L McGrath07085852003-10-09 07:28:22 +00002434 else
2435 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002436 printf(" busstate = %2ld", parm);
2437 bus_state_value(parm);
2438 }
2439 }
2440#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00002441 if (reread_partn)
2442 bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART");
2443
Eric Andersen3443bd72003-07-22 07:30:36 +00002444
2445 if (do_ctimings)
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00002446 do_time(0,fd); /*time cache */
Eric Andersen3443bd72003-07-22 07:30:36 +00002447 if (do_timings)
Glenn L McGrath07085852003-10-09 07:28:22 +00002448 do_time(1,fd); /*time device */
Eric Andersen3443bd72003-07-22 07:30:36 +00002449 if (do_flush)
2450 flush_buffer_cache (fd);
2451 close (fd);
2452}
2453
Eric Andersen06d4ec22004-03-19 10:53:52 +00002454static char * GET_NUMBER(char *p, unsigned long *flag, unsigned long *num)
2455{
2456 *num = 0;
2457 while (isdigit(*p)) {
2458 *flag = 1;
2459 *num = (*num * 10) + (*p++ - '0');
2460 }
2461 return p;
2462}
2463
2464static char * GET_STRING(char *p, unsigned long *flag, int *num)
2465{
2466 char *tmpstr;
2467 char name[32];
2468 tmpstr = name;
2469 tmpstr[0] = '\0';
2470 while (isalnum(*p) && (tmpstr - name) < 31) {
2471 tmpstr[0] = *p++;
2472 tmpstr[1] = '\0';
2473 ++tmpstr;
2474 }
2475 *num = translate_xfermode(name);
2476 if (*num == -1)
2477 *flag = 0;
2478 else
2479 *flag = 1;
2480 return p;
2481}
2482
Eric Andersen3443bd72003-07-22 07:30:36 +00002483#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
2484static int fromhex (unsigned char c)
2485{
2486 if (c >= 'a' && c <= 'f')
2487 return 10 + (c - 'a');
2488 if (c >= '0' && c <= '9')
2489 return (c - '0');
2490 bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
2491}
2492
2493static int identify_from_stdin (void)
2494{
2495 unsigned short sbuf[800];
2496 unsigned char buf[1600], *b = (unsigned char *)buf;
2497 int i, count = read(0, buf, 1280);
2498
2499 if (count != 1280)
2500 bb_error_msg_and_die("read(1280 bytes) failed (rc=%d)", count);
Glenn L McGrath07085852003-10-09 07:28:22 +00002501 for (i = 0; count >= 4; ++i)
2502 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002503 sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]);
2504 __le16_to_cpus((uint16_t *)(&sbuf[i]));
2505 b += 5;
2506 count -= 5;
2507 }
2508 identify(sbuf, NULL);
2509 return 0;
2510}
2511#endif
2512
Eric Andersenb2aa7762004-04-05 13:08:08 +00002513static void missing_arg(int arg, char c, char* add)
2514{
2515 if (!arg)
2516 bb_error_msg("-%c: missing value %s", c, (add!=NULL)? add :"");
2517}
2518
Eric Andersen3443bd72003-07-22 07:30:36 +00002519/* our main() routine: */
2520int hdparm_main(int argc, char **argv)
2521{
2522 char c, *p;
Eric Andersen3443bd72003-07-22 07:30:36 +00002523
2524 ++argv;
2525 if (!--argc)
2526 bb_show_usage();
Glenn L McGrath07085852003-10-09 07:28:22 +00002527
2528 while (argc--)
2529 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002530#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
Glenn L McGrath07085852003-10-09 07:28:22 +00002531 if (!strcmp("-Istdin", *argv))
2532 {
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00002533 return identify_from_stdin();
Eric Andersen3443bd72003-07-22 07:30:36 +00002534 }
2535#endif
2536 p = *argv++;
Glenn L McGrath07085852003-10-09 07:28:22 +00002537 if (*p == '-')
2538 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002539 if (!*++p)
2540 bb_show_usage();
Glenn L McGrath07085852003-10-09 07:28:22 +00002541 while ((c = *p++))
2542 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002543 ++flagcount;
Glenn L McGrath07085852003-10-09 07:28:22 +00002544 switch (c)
2545 {
Eric Andersen3443bd72003-07-22 07:30:36 +00002546 case 'V':
Glenn L McGrath07085852003-10-09 07:28:22 +00002547 /*bb_error_msg_and_die("%s", VERSION);*/
2548 /* We have to return 0 here and not 1 */
2549 printf("%s %s\n",bb_applet_name, VERSION);
"Vladimir N. Oleynik"b4b6d262005-10-15 14:10:36 +00002550 return EXIT_SUCCESS;
Eric Andersen3443bd72003-07-22 07:30:36 +00002551 case 'v':
2552 verbose = 1;
2553 break;
2554#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY
2555 case 'I':
2556 get_IDentity = 1;
2557 break;
2558 case 'i':
2559 get_identity = 1;
2560 break;
2561#endif
2562 case 'g':
2563 get_geom = 1;
2564 break;
2565 case 'f':
2566 do_flush = 1;
2567 break;
2568 case 'q':
2569 quiet = 1;
2570 noisy = 0;
2571 break;
2572 case 'u':
2573 get_unmask = noisy;
2574 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002575 if (!*p && argc && isdigit(**argv))
2576 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002577 if((set_unmask = set_flag(p,'1'))==1)
2578 unmask = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002579 break;
Eric Andersen0a57a792003-08-06 08:57:35 +00002580#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA
Eric Andersen3443bd72003-07-22 07:30:36 +00002581 case 'd':
2582 get_dma = noisy;
2583 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002584 if (!*p && argc && isdigit(**argv))
2585 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002586 if((set_dma = set_flag(p,'9'))==1)
Eric Andersen3443bd72003-07-22 07:30:36 +00002587 dma = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002588 break;
Eric Andersen0a57a792003-08-06 08:57:35 +00002589#endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */
Eric Andersen3443bd72003-07-22 07:30:36 +00002590 case 'n':
2591 get_nowerr = noisy;
2592 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002593 if (!*p && argc && isdigit(**argv))
2594 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002595 if((set_nowerr = set_flag(p,'1'))==1)
2596 nowerr = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002597 break;
2598 case 'p':
2599 noisy_piomode = noisy;
2600 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002601 if (!*p && argc && isalnum(**argv))
2602 p = *argv++, --argc;
2603 p=GET_STRING(p,&set_piomode,&piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00002604 break;
2605 case 'r':
2606 get_readonly = noisy;
2607 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002608 if (!*p && argc && isdigit(**argv))
2609 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002610 if((set_readonly = set_flag(p,'1'))==1)
2611 readonly = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002612 break;
2613 case 'm':
2614 get_mult = noisy;
2615 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002616 if (!*p && argc && isalnum(**argv))
2617 p = *argv++, --argc;
2618 p=GET_NUMBER(p,&set_mult,&mult);
Eric Andersen3443bd72003-07-22 07:30:36 +00002619 break;
2620 case 'c':
2621 get_io32bit = noisy;
2622 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002623 if (!*p && argc && isalnum(**argv))
2624 p = *argv++, --argc;
2625 p=GET_NUMBER(p,&set_io32bit,&io32bit);
Eric Andersen3443bd72003-07-22 07:30:36 +00002626 break;
2627#ifdef HDIO_DRIVE_CMD
2628 case 'S':
2629 get_standby = noisy;
2630 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002631 if (!*p && argc && isalnum(**argv))
2632 p = *argv++, --argc;
2633 p=GET_NUMBER(p,&set_standby,&standby_requested);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002634 missing_arg(set_standby, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002635 break;
2636
2637 case 'D':
2638 get_defects = noisy;
2639 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002640 if (!*p && argc && isalnum(**argv))
2641 p = *argv++, --argc;
2642 p=GET_NUMBER(p,&set_defects,&defects);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002643 missing_arg(set_defects, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002644 break;
2645 case 'P':
2646 get_prefetch = noisy;
2647 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002648 if (!*p && argc && isalnum(**argv))
2649 p = *argv++, --argc;
2650 p=GET_NUMBER(p,&set_prefetch,&prefetch);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002651 missing_arg(set_prefetch, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002652 break;
2653
2654 case 'X':
2655 get_xfermode = noisy;
2656 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002657 if (!*p && argc && isalnum(**argv))
2658 p = *argv++, --argc;
2659 p=GET_STRING(p,&set_xfermode,&xfermode_requested);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002660 missing_arg(set_xfermode, c, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00002661 break;
2662
2663 case 'K':
2664 get_dkeep = noisy;
2665 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002666 if (!*p && argc && isdigit(**argv))
2667 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002668 if((set_dkeep = set_flag(p,'1'))==1)
2669 dkeep = *p++ - '0';
2670 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002671 goto missing_arg_error;
Eric Andersen3443bd72003-07-22 07:30:36 +00002672 break;
2673
2674 case 'A':
2675 get_lookahead = noisy;
2676 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002677 if (!*p && argc && isdigit(**argv))
2678 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002679 if((set_lookahead = set_flag(p,'1'))==1)
2680 lookahead = *p++ - '0';
2681 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002682 goto missing_arg_error;
Eric Andersen3443bd72003-07-22 07:30:36 +00002683 break;
2684
2685 case 'L':
2686 get_doorlock = noisy;
2687 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002688 if (!*p && argc && isdigit(**argv))
2689 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002690 if((set_doorlock = set_flag(p,'1'))==1)
2691 doorlock = *p++ - '0';
2692 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002693 goto missing_arg_error;
Eric Andersen3443bd72003-07-22 07:30:36 +00002694 break;
2695
2696 case 'W':
2697 get_wcache = noisy;
2698 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002699 if (!*p && argc && isdigit(**argv))
2700 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002701 if((set_wcache = set_flag(p,'1'))==1)
2702 wcache = *p++ - '0';
2703 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002704missing_arg_error:
2705 missing_arg(1, c, "(0/1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002706 break;
2707
2708 case 'C':
2709 get_powermode = noisy;
2710 noisy = 1;
2711 break;
2712
2713 case 'y':
2714 get_standbynow = noisy;
2715 noisy = 1;
2716 set_standbynow = 1;
2717 break;
2718
2719 case 'Y':
2720 get_sleepnow = noisy;
2721 noisy = 1;
2722 set_sleepnow = 1;
2723 break;
2724
2725 case 'z':
2726 reread_partn = 1;
2727 break;
2728
2729 case 'Z':
2730 get_seagate = noisy;
2731 noisy = 1;
2732 set_seagate = 1;
2733 break;
2734#endif /* HDIO_DRIVE_CMD */
2735 case 'k':
2736 get_keep = noisy;
2737 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002738 if (!*p && argc && isdigit(**argv))
2739 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002740 if((set_keep = set_flag(p,'1'))==1)
2741 keep = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002742 break;
2743#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
2744 case 'U':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002745 if (!*p && argc && isdigit(**argv))
2746 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002747 if(! p)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002748 goto expected_hwif_error; /* "expected hwif_nr" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002749
2750 sscanf(p++, "%i", &hwif);
2751
2752 unregister_hwif = 1;
2753 break;
2754#endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF */
2755#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
2756 case 'R':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002757 if (!*p && argc && isdigit(**argv))
2758 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002759 if(! p)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002760 goto expected_hwif_error; /* "expected hwif_data" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002761
2762 sscanf(p++, "%i", &hwif_data);
2763
2764 if (argc && isdigit(**argv))
2765 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002766 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002767 goto expected_hwif_error; /* "expected hwif_ctrl" */
Eric Andersen3443bd72003-07-22 07:30:36 +00002768
2769 sscanf(p, "%i", &hwif_ctrl);
2770
2771 if (argc && isdigit(**argv))
2772 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002773 else
Bernhard Reutner-Fischer061fd0a2006-04-05 16:37:25 +00002774#endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
Bernhard Reutner-Fischer9460f662006-04-11 08:01:29 +00002775#if defined CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF || defined CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Eric Andersenb2aa7762004-04-05 13:08:08 +00002776expected_hwif_error:
Glenn L McGrath07085852003-10-09 07:28:22 +00002777 bb_error_msg_and_die("expected hwif value"); /* "expected hwif_irq" */
Bernhard Reutner-Fischer9460f662006-04-11 08:01:29 +00002778#endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF || CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
Bernhard Reutner-Fischer061fd0a2006-04-05 16:37:25 +00002779#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF
Eric Andersen3443bd72003-07-22 07:30:36 +00002780
2781 sscanf(p, "%i", &hwif_irq);
2782
2783 *p = '\0';
2784
2785 scan_hwif = 1;
2786 break;
2787#endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */
2788 case 'Q':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002789#ifdef HDIO_GET_QDMA
Eric Andersen3443bd72003-07-22 07:30:36 +00002790 get_dma_q = noisy;
2791 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002792#ifdef HDIO_SET_QDMA
2793 if (!*p && argc && isalnum(**argv))
2794 p = *argv++, --argc;
2795 p=GET_NUMBER(p,&set_dma_q,&dma_q);
2796#ifdef HDIO_GET_QDMA
2797 dma_q = -dma_q;
2798#endif
2799#endif
2800#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00002801 break;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002802
Eric Andersen3443bd72003-07-22 07:30:36 +00002803#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET
2804 case 'w':
2805 perform_reset = 1;
2806 break;
2807#endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */
2808#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
2809 case 'x':
Eric Andersen06d4ec22004-03-19 10:53:52 +00002810 if (!*p && argc && isdigit(**argv))
2811 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002812 if((perform_tristate = set_flag(p,'1'))==1)
2813 tristate = *p++ - '0';
2814 else
Eric Andersenb2aa7762004-04-05 13:08:08 +00002815 missing_arg(1, c, "(0/1)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002816 break;
2817
2818#endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
2819 case 'a':
2820 get_readahead = noisy;
2821 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002822 if (!*p && argc && isalnum(**argv))
2823 p = *argv++, --argc;
Eric Andersenf828da02004-07-20 22:53:59 +00002824 p=GET_NUMBER(p,&set_readahead,&Xreadahead);
Eric Andersen3443bd72003-07-22 07:30:36 +00002825 break;
2826 case 'B':
2827 get_apmmode = noisy;
2828 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002829 if (!*p && argc && isalnum(**argv))
2830 p = *argv++, --argc;
2831 p=GET_NUMBER(p,&set_apmmode,&apmmode);
Eric Andersenb2aa7762004-04-05 13:08:08 +00002832 missing_arg(set_apmmode, c, "(1-255)");
Eric Andersen3443bd72003-07-22 07:30:36 +00002833 break;
2834 case 't':
2835 do_timings = 1;
2836 do_flush = 1;
2837 break;
2838 case 'T':
2839 do_ctimings = 1;
2840 do_flush = 1;
2841 break;
2842#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
2843 case 'b':
2844 get_busstate = noisy;
2845 noisy = 1;
Eric Andersen06d4ec22004-03-19 10:53:52 +00002846 if (!*p && argc && isdigit(**argv))
2847 p = *argv++, --argc;
Glenn L McGrath07085852003-10-09 07:28:22 +00002848 if((set_busstate = set_flag(p,'2'))==1)
2849 busstate = *p++ - '0';
Eric Andersen3443bd72003-07-22 07:30:36 +00002850 break;
2851#endif
2852 case 'h':
2853 default:
2854 bb_show_usage();
2855 }
2856 }
2857 if (!argc)
2858 bb_show_usage();
Eric Andersen06d4ec22004-03-19 10:53:52 +00002859 } else {
Glenn L McGrath07085852003-10-09 07:28:22 +00002860 process_dev (p);
Eric Andersen06d4ec22004-03-19 10:53:52 +00002861 }
Eric Andersen3443bd72003-07-22 07:30:36 +00002862 }
2863 return 0 ;
2864}