blob: b4c5876d468ca0b5817a6d4c2689cb2e9bdeb080 [file] [log] [blame]
Eric Andersen3443bd72003-07-22 07:30:36 +00001/* vi: set sw=4 ts=4: */
2/*
3 * hdparm implementation for busybox
4 *
Glenn L McGrath5be6a202003-11-28 22:55:03 +00005 * Copyright (C) [2003] by [Matteo Croce] <3297627799@wind.it>
Glenn L McGrath07085852003-10-09 07:28:22 +00006 * Hacked by Tito <farmatito@tiscali.it> for size optimization.
Eric Andersen3443bd72003-07-22 07:30:36 +00007 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02008 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersen3443bd72003-07-22 07:30:36 +00009 *
10 * This program is based on the source code of hdparm: see below...
11 * hdparm.c - Command line interface to get/set hard disk parameters
12 * - by Mark Lord (C) 1994-2002 -- freely distributable
13 */
Pere Orga5bc8c002011-04-11 03:29:49 +020014
15//usage:#define hdparm_trivial_usage
16//usage: "[OPTIONS] [DEVICE]"
17//usage:#define hdparm_full_usage "\n\n"
Denys Vlasenko66426762011-06-05 03:58:28 +020018//usage: " -a Get/set fs readahead"
Pere Orga5bc8c002011-04-11 03:29:49 +020019//usage: "\n -A Set drive read-lookahead flag (0/1)"
20//usage: "\n -b Get/set bus state (0 == off, 1 == on, 2 == tristate)"
21//usage: "\n -B Set Advanced Power Management setting (1-255)"
22//usage: "\n -c Get/set IDE 32-bit IO setting"
23//usage: "\n -C Check IDE power mode status"
24//usage: IF_FEATURE_HDPARM_HDIO_GETSET_DMA(
25//usage: "\n -d Get/set using_dma flag")
26//usage: "\n -D Enable/disable drive defect-mgmt"
27//usage: "\n -f Flush buffer cache for device on exit"
28//usage: "\n -g Display drive geometry"
29//usage: "\n -h Display terse usage information"
30//usage: IF_FEATURE_HDPARM_GET_IDENTITY(
31//usage: "\n -i Display drive identification")
32//usage: IF_FEATURE_HDPARM_GET_IDENTITY(
33//usage: "\n -I Detailed/current information directly from drive")
34//usage: "\n -k Get/set keep_settings_over_reset flag (0/1)"
35//usage: "\n -K Set drive keep_features_over_reset flag (0/1)"
36//usage: "\n -L Set drive doorlock (0/1) (removable harddisks only)"
37//usage: "\n -m Get/set multiple sector count"
38//usage: "\n -n Get/set ignore-write-errors flag (0/1)"
39//usage: "\n -p Set PIO mode on IDE interface chipset (0,1,2,3,4,...)"
40//usage: "\n -P Set drive prefetch count"
41/* //usage: "\n -q Change next setting quietly" - not supported ib bbox */
42//usage: "\n -Q Get/set DMA tagged-queuing depth (if supported)"
43//usage: "\n -r Get/set readonly flag (DANGEROUS to set)"
44//usage: IF_FEATURE_HDPARM_HDIO_SCAN_HWIF(
45//usage: "\n -R Register an IDE interface (DANGEROUS)")
46//usage: "\n -S Set standby (spindown) timeout"
47//usage: "\n -t Perform device read timings"
48//usage: "\n -T Perform cache read timings"
49//usage: "\n -u Get/set unmaskirq flag (0/1)"
50//usage: IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(
51//usage: "\n -U Unregister an IDE interface (DANGEROUS)")
52//usage: "\n -v Defaults; same as -mcudkrag for IDE drives"
53//usage: "\n -V Display program version and exit immediately"
54//usage: IF_FEATURE_HDPARM_HDIO_DRIVE_RESET(
55//usage: "\n -w Perform device reset (DANGEROUS)")
56//usage: "\n -W Set drive write-caching flag (0/1) (DANGEROUS)"
57//usage: IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(
58//usage: "\n -x Tristate device for hotswap (0/1) (DANGEROUS)")
59//usage: "\n -X Set IDE xfer mode (DANGEROUS)"
60//usage: "\n -y Put IDE drive in standby mode"
61//usage: "\n -Y Put IDE drive to sleep"
62//usage: "\n -Z Disable Seagate auto-powersaving mode"
63//usage: "\n -z Reread partition table"
64
Denys Vlasenko860d2bb2009-07-10 18:37:06 +020065#include "libbb.h"
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +020066#include "common_bufsiz.h"
Denys Vlasenko860d2bb2009-07-10 18:37:06 +020067/* must be _after_ libbb.h: */
Eric Andersen3443bd72003-07-22 07:30:36 +000068#include <linux/hdreg.h>
Denys Vlasenkoda49f582009-07-08 02:58:38 +020069#include <sys/mount.h>
Denys Vlasenkoaf3fd142009-09-22 23:16:39 +020070#if !defined(BLKGETSIZE64)
71# define BLKGETSIZE64 _IOR(0x12,114,size_t)
72#endif
Eric Andersen3443bd72003-07-22 07:30:36 +000073
Eric Andersen3443bd72003-07-22 07:30:36 +000074/* device types */
75/* ------------ */
76#define NO_DEV 0xffff
77#define ATA_DEV 0x0000
78#define ATAPI_DEV 0x0001
79
80/* word definitions */
81/* ---------------- */
82#define GEN_CONFIG 0 /* general configuration */
83#define LCYLS 1 /* number of logical cylinders */
84#define CONFIG 2 /* specific configuration */
85#define LHEADS 3 /* number of logical heads */
86#define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */
87#define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */
88#define LSECTS 6 /* number of logical sectors/track */
89#define START_SERIAL 10 /* ASCII serial number */
90#define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */
91#define BUF_TYPE 20 /* buffer type (ATA-1) */
92#define BUFFER__SIZE 21 /* buffer size (ATA-1) */
93#define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/
94#define START_FW_REV 23 /* ASCII firmware revision */
95#define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000096#define START_MODEL 27 /* ASCII model number */
97#define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */
Denis Vlasenko4b924f32007-05-30 00:29:55 +000098#define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */
Eric Andersen3443bd72003-07-22 07:30:36 +000099#define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */
100#define CAPAB_0 49 /* capabilities */
101#define CAPAB_1 50
102#define PIO_MODE 51 /* max PIO mode supported (obsolete)*/
103#define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/
104#define WHATS_VALID 53 /* what fields are valid */
105#define LCYLS_CUR 54 /* current logical cylinders */
106#define LHEADS_CUR 55 /* current logical heads */
Denis Vlasenko4b924f32007-05-30 00:29:55 +0000107#define LSECTS_CUR 56 /* current logical sectors/track */
Eric Andersen3443bd72003-07-22 07:30:36 +0000108#define CAPACITY_LSB 57 /* current capacity in sectors */
109#define CAPACITY_MSB 58
110#define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */
111#define LBA_SECTS_LSB 60 /* LBA: total number of user */
112#define LBA_SECTS_MSB 61 /* addressable sectors */
113#define SINGLE_DMA 62 /* singleword DMA modes */
114#define MULTI_DMA 63 /* multiword DMA modes */
115#define ADV_PIO_MODES 64 /* advanced PIO modes supported */
116 /* multiword DMA xfer cycle time: */
117#define DMA_TIME_MIN 65 /* - minimum */
Denis Vlasenko551ffdc2009-04-01 19:48:05 +0000118#define DMA_TIME_NORM 66 /* - manufacturer's recommended */
Eric Andersen3443bd72003-07-22 07:30:36 +0000119 /* minimum PIO xfer cycle time: */
120#define PIO_NO_FLOW 67 /* - without flow control */
121#define PIO_FLOW 68 /* - with IORDY flow control */
122#define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */
123#define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */
124#define CDR_MAJOR 73 /* CD ROM: major version number */
125#define CDR_MINOR 74 /* CD ROM: minor version number */
126#define QUEUE_DEPTH 75 /* queue depth */
127#define MAJOR 80 /* major version number */
128#define MINOR 81 /* minor version number */
129#define CMDS_SUPP_0 82 /* command/feature set(s) supported */
130#define CMDS_SUPP_1 83
131#define CMDS_SUPP_2 84
132#define CMDS_EN_0 85 /* command/feature set(s) enabled */
133#define CMDS_EN_1 86
134#define CMDS_EN_2 87
135#define ULTRA_DMA 88 /* ultra DMA modes */
136 /* time to complete security erase */
137#define ERASE_TIME 89 /* - ordinary */
138#define ENH_ERASE_TIME 90 /* - enhanced */
139#define ADV_PWR 91 /* current advanced power management level
Glenn L McGrath07085852003-10-09 07:28:22 +0000140 in low byte, 0x40 in high byte. */
Denis Vlasenko551ffdc2009-04-01 19:48:05 +0000141#define PSWD_CODE 92 /* master password revision code */
Eric Andersen3443bd72003-07-22 07:30:36 +0000142#define HWRST_RSLT 93 /* hardware reset result */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000143#define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000144#define LBA_LSB 100 /* LBA: maximum. Currently only 48 */
145#define LBA_MID 101 /* bits are used, but addr 103 */
146#define LBA_48_MSB 102 /* has been reserved for LBA in */
147#define LBA_64_MSB 103 /* the future. */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000148#define RM_STAT 127 /* removable media status notification feature set support */
Eric Andersen3443bd72003-07-22 07:30:36 +0000149#define SECU_STATUS 128 /* security status */
150#define CFA_PWR_MODE 160 /* CFA power mode 1 */
151#define START_MEDIA 176 /* media serial number */
152#define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/
153#define START_MANUF 196 /* media manufacturer I.D. */
154#define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */
155#define INTEGRITY 255 /* integrity word */
156
157/* bit definitions within the words */
158/* -------------------------------- */
159
160/* many words are considered valid if bit 15 is 0 and bit 14 is 1 */
161#define VALID 0xc000
162#define VALID_VAL 0x4000
163/* many words are considered invalid if they are either all-0 or all-1 */
164#define NOVAL_0 0x0000
165#define NOVAL_1 0xffff
166
167/* word 0: gen_config */
Glenn L McGrath07085852003-10-09 07:28:22 +0000168#define NOT_ATA 0x8000
Eric Andersen3443bd72003-07-22 07:30:36 +0000169#define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */
170#define MEDIA_REMOVABLE 0x0080
171#define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */
172#define INCOMPLETE 0x0004
173#define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */
174#define DRQ_RESPONSE_TIME 0x0060
175#define DRQ_3MS_VAL 0x0000
176#define DRQ_INTR_VAL 0x0020
177#define DRQ_50US_VAL 0x0040
178#define PKT_SIZE_SUPPORTED 0x0003
179#define PKT_SIZE_12_VAL 0x0000
180#define PKT_SIZE_16_VAL 0x0001
181#define EQPT_TYPE 0x1f00
182#define SHIFT_EQPT 8
183
184#define CDROM 0x0005
185
Eric Andersen3443bd72003-07-22 07:30:36 +0000186/* word 1: number of logical cylinders */
187#define LCYLS_MAX 0x3fff /* maximum allowable value */
188
Eric Andersenaff114c2004-04-14 17:51:38 +0000189/* word 2: specific configuration
Eric Andersen3443bd72003-07-22 07:30:36 +0000190 * (a) require SET FEATURES to spin-up
191 * (b) require spin-up to fully reply to IDENTIFY DEVICE
192 */
193#define STBY_NID_VAL 0x37c8 /* (a) and (b) */
194#define STBY_ID_VAL 0x738c /* (a) and not (b) */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000195#define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */
Eric Andersen3443bd72003-07-22 07:30:36 +0000196#define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */
197
198/* words 47 & 59: sector_xfer_max & sector_xfer_cur */
199#define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/
200#define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */
201
202/* word 49: capabilities 0 */
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000203#define STD_STBY 0x2000 /* 1=standard values supported (ATA); 0=vendor specific values */
Eric Andersen3443bd72003-07-22 07:30:36 +0000204#define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */
205#define IORDY_OFF 0x0400 /* 1=may be disabled */
206#define LBA_SUP 0x0200 /* 1=Logical Block Address support */
207#define DMA_SUP 0x0100 /* 1=Direct Memory Access support */
208#define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */
209#define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */
210#define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */
211#define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */
212
213/* word 50: capabilities 1 */
214#define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */
215
216/* words 51 & 52: PIO & DMA cycle times */
217#define MODE 0xff00 /* the mode is in the MSBs */
218
219/* word 53: whats_valid */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000220#define OK_W88 0x0004 /* the ultra_dma info is valid */
Eric Andersen3443bd72003-07-22 07:30:36 +0000221#define OK_W64_70 0x0002 /* see above for word descriptions */
222#define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */
223
224/*word 63,88: dma_mode, ultra_dma_mode*/
225#define MODE_MAX 7 /* bit definitions force udma <=7 (when
226 * udma >=8 comes out it'll have to be
227 * defined in a new dma_mode word!) */
228
229/* word 64: PIO transfer modes */
230#define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */
231#define PIO_MODE_MAX 8 /* but all 8 bits are defined */
232
233/* word 75: queue_depth */
234#define DEPTH_BITS 0x001f /* bits used for queue depth */
235
236/* words 80-81: version numbers */
237/* NOVAL_0 or NOVAL_1 means device does not report version */
238
239/* word 81: minor version number */
Rob Landley0e6a3e12006-04-28 01:33:30 +0000240#define MINOR_MAX 0x22
Eric Andersen3443bd72003-07-22 07:30:36 +0000241/* words 82-84: cmds/feats supported */
242#define CMDS_W82 0x77ff /* word 82: defined command locations*/
243#define CMDS_W83 0x3fff /* word 83: defined command locations*/
244#define CMDS_W84 0x002f /* word 83: defined command locations*/
Glenn L McGrath07085852003-10-09 07:28:22 +0000245#define SUPPORT_48_BIT 0x0400
Eric Andersen3443bd72003-07-22 07:30:36 +0000246#define NUM_CMD_FEAT_STR 48
247
Eric Andersen3443bd72003-07-22 07:30:36 +0000248/* words 85-87: cmds/feats enabled */
249/* use cmd_feat_str[] to display what commands and features have
Glenn L McGrath07085852003-10-09 07:28:22 +0000250 * been enabled with words 85-87
Eric Andersen3443bd72003-07-22 07:30:36 +0000251 */
252
253/* words 89, 90, SECU ERASE TIME */
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000254#define ERASE_BITS 0x00ff
Eric Andersen3443bd72003-07-22 07:30:36 +0000255
256/* word 92: master password revision */
257/* NOVAL_0 or NOVAL_1 means no support for master password revision */
258
259/* word 93: hw reset result */
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000260#define CBLID 0x2000 /* CBLID status */
261#define RST0 0x0001 /* 1=reset to device #0 */
262#define DEV_DET 0x0006 /* how device num determined */
263#define JUMPER_VAL 0x0002 /* device num determined by jumper */
264#define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */
Eric Andersen3443bd72003-07-22 07:30:36 +0000265
266/* word 127: removable media status notification feature set support */
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000267#define RM_STAT_BITS 0x0003
268#define RM_STAT_SUP 0x0001
Glenn L McGrath07085852003-10-09 07:28:22 +0000269
Eric Andersen3443bd72003-07-22 07:30:36 +0000270/* word 128: security */
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000271#define SECU_ENABLED 0x0002
272#define SECU_LEVEL 0x0010
273#define NUM_SECU_STR 6
Eric Andersen3443bd72003-07-22 07:30:36 +0000274
275/* word 160: CFA power mode */
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000276#define VALID_W160 0x8000 /* 1=word valid */
277#define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/
278#define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */
279#define MAX_AMPS 0x0fff /* value = max current in ma */
Eric Andersen3443bd72003-07-22 07:30:36 +0000280
281/* word 255: integrity */
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000282#define SIG 0x00ff /* signature location */
283#define SIG_VAL 0x00a5 /* signature value */
Eric Andersen3443bd72003-07-22 07:30:36 +0000284
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000285#define TIMING_BUF_MB 1
286#define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024)
Glenn L McGrath07085852003-10-09 07:28:22 +0000287
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000288#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
Glenn L McGrath07085852003-10-09 07:28:22 +0000289
Denis Vlasenko892536f2007-09-27 10:23:34 +0000290
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200291#define IS_GET 1
292#define IS_SET 2
293
294
Denis Vlasenko892536f2007-09-27 10:23:34 +0000295enum { fd = 3 };
296
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000297
298struct globals {
299 smallint get_identity, get_geom;
300 smallint do_flush;
301 smallint do_ctimings, do_timings;
302 smallint reread_partn;
303 smallint set_piomode, noisy_piomode;
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200304 smallint getset_readahead;
305 smallint getset_readonly;
306 smallint getset_unmask;
307 smallint getset_mult;
Denis Vlasenko3c96d022008-03-20 13:44:50 +0000308#ifdef HDIO_GET_QDMA
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200309 smallint getset_dma_q;
Denis Vlasenko3c96d022008-03-20 13:44:50 +0000310#endif
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200311 smallint getset_nowerr;
312 smallint getset_keep;
313 smallint getset_io32bit;
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000314 int piomode;
315 unsigned long Xreadahead;
316 unsigned long readonly;
317 unsigned long unmask;
318 unsigned long mult;
Denis Vlasenko3c96d022008-03-20 13:44:50 +0000319#ifdef HDIO_SET_QDMA
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000320 unsigned long dma_q;
Denis Vlasenko3c96d022008-03-20 13:44:50 +0000321#endif
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000322 unsigned long nowerr;
323 unsigned long keep;
324 unsigned long io32bit;
325#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
326 unsigned long dma;
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200327 smallint getset_dma;
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000328#endif
329#ifdef HDIO_DRIVE_CMD
330 smallint set_xfermode, get_xfermode;
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200331 smallint getset_dkeep;
332 smallint getset_standby;
333 smallint getset_lookahead;
334 smallint getset_prefetch;
335 smallint getset_defects;
336 smallint getset_wcache;
337 smallint getset_doorlock;
338 smallint set_seagate;
339 smallint set_standbynow;
340 smallint set_sleepnow;
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000341 smallint get_powermode;
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200342 smallint getset_apmmode;
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000343 int xfermode_requested;
344 unsigned long dkeep;
Denis Vlasenko3c96d022008-03-20 13:44:50 +0000345 unsigned long standby_requested; /* 0..255 */
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000346 unsigned long lookahead;
347 unsigned long prefetch;
348 unsigned long defects;
349 unsigned long wcache;
350 unsigned long doorlock;
351 unsigned long apmmode;
352#endif
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000353 IF_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;)
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200354 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint getset_busstate;)
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000355 IF_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;)
356 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;)
357 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;)
358 IF_FEATURE_HDPARM_HDIO_SCAN_HWIF( smallint scan_hwif;)
359 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long busstate;)
360 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long tristate;)
361 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(unsigned long hwif;)
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000362#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
363 unsigned long hwif_data;
364 unsigned long hwif_ctrl;
365 unsigned long hwif_irq;
366#endif
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +0000367#ifdef DO_FLUSHCACHE
368 unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 };
369#endif
Denys Vlasenko98a4c7c2010-02-04 15:00:15 +0100370} FIX_ALIASING;
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +0200371#define G (*(struct globals*)bb_common_bufsiz1)
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000372#define get_identity (G.get_identity )
373#define get_geom (G.get_geom )
374#define do_flush (G.do_flush )
375#define do_ctimings (G.do_ctimings )
376#define do_timings (G.do_timings )
377#define reread_partn (G.reread_partn )
378#define set_piomode (G.set_piomode )
379#define noisy_piomode (G.noisy_piomode )
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200380#define getset_readahead (G.getset_readahead )
381#define getset_readonly (G.getset_readonly )
382#define getset_unmask (G.getset_unmask )
383#define getset_mult (G.getset_mult )
384#define getset_dma_q (G.getset_dma_q )
385#define getset_nowerr (G.getset_nowerr )
386#define getset_keep (G.getset_keep )
387#define getset_io32bit (G.getset_io32bit )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000388#define piomode (G.piomode )
389#define Xreadahead (G.Xreadahead )
390#define readonly (G.readonly )
391#define unmask (G.unmask )
392#define mult (G.mult )
393#define dma_q (G.dma_q )
394#define nowerr (G.nowerr )
395#define keep (G.keep )
396#define io32bit (G.io32bit )
397#define dma (G.dma )
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200398#define getset_dma (G.getset_dma )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000399#define set_xfermode (G.set_xfermode )
400#define get_xfermode (G.get_xfermode )
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200401#define getset_dkeep (G.getset_dkeep )
402#define getset_standby (G.getset_standby )
403#define getset_lookahead (G.getset_lookahead )
404#define getset_prefetch (G.getset_prefetch )
405#define getset_defects (G.getset_defects )
406#define getset_wcache (G.getset_wcache )
407#define getset_doorlock (G.getset_doorlock )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000408#define set_seagate (G.set_seagate )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000409#define set_standbynow (G.set_standbynow )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000410#define set_sleepnow (G.set_sleepnow )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000411#define get_powermode (G.get_powermode )
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200412#define getset_apmmode (G.getset_apmmode )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000413#define xfermode_requested (G.xfermode_requested )
414#define dkeep (G.dkeep )
415#define standby_requested (G.standby_requested )
416#define lookahead (G.lookahead )
417#define prefetch (G.prefetch )
418#define defects (G.defects )
419#define wcache (G.wcache )
420#define doorlock (G.doorlock )
421#define apmmode (G.apmmode )
422#define get_IDentity (G.get_IDentity )
Denys Vlasenkoc7068452009-05-20 16:11:41 +0200423#define getset_busstate (G.getset_busstate )
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000424#define perform_reset (G.perform_reset )
425#define perform_tristate (G.perform_tristate )
426#define unregister_hwif (G.unregister_hwif )
427#define scan_hwif (G.scan_hwif )
428#define busstate (G.busstate )
429#define tristate (G.tristate )
430#define hwif (G.hwif )
431#define hwif_data (G.hwif_data )
432#define hwif_ctrl (G.hwif_ctrl )
433#define hwif_irq (G.hwif_irq )
Denys Vlasenko7b85ec32015-10-13 17:17:34 +0200434#define INIT_G() do { \
Denys Vlasenko47cfbf32016-04-21 18:18:48 +0200435 setup_common_bufsiz(); \
Denys Vlasenko7b85ec32015-10-13 17:17:34 +0200436 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
437} while (0)
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +0000438
439
Glenn L McGrath07085852003-10-09 07:28:22 +0000440/* Busybox messages and functions */
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000441#if ENABLE_IOCTL_HEX2STR_ERROR
Denis Vlasenko892536f2007-09-27 10:23:34 +0000442static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt, const char *string)
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000443{
444 if (!ioctl(fd, cmd, args))
445 return 0;
446 args[0] = alt;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000447 return bb_ioctl_or_warn(fd, cmd, args, string);
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000448}
Denis Vlasenko892536f2007-09-27 10:23:34 +0000449#define ioctl_alt_or_warn(cmd,args,alt) ioctl_alt_func(cmd,args,alt,#cmd)
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000450#else
Denis Vlasenko892536f2007-09-27 10:23:34 +0000451static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt)
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000452{
453 if (!ioctl(fd, cmd, args))
454 return 0;
455 args[0] = alt;
456 return bb_ioctl_or_warn(fd, cmd, args);
457}
Denis Vlasenko892536f2007-09-27 10:23:34 +0000458#define ioctl_alt_or_warn(cmd,args,alt) ioctl_alt_func(cmd,args,alt)
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000459#endif
Rob Landley5f8b5ec2006-04-29 16:03:40 +0000460
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +0000461static void on_off(int value)
462{
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000463 puts(value ? " (on)" : " (off)");
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +0000464}
Glenn L McGrath07085852003-10-09 07:28:22 +0000465
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +0000466static void print_flag_on_off(int get_arg, const char *s, unsigned long arg)
Glenn L McGrath07085852003-10-09 07:28:22 +0000467{
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000468 if (get_arg) {
Denys Vlasenko327f5502013-11-29 16:45:45 +0100469 printf(" setting %s to %lu", s, arg);
Glenn L McGrath07085852003-10-09 07:28:22 +0000470 on_off(arg);
471 }
472}
473
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000474static void print_value_on_off(const char *str, unsigned long argp)
Glenn L McGrath07085852003-10-09 07:28:22 +0000475{
Denys Vlasenko327f5502013-11-29 16:45:45 +0100476 printf(" %s\t= %2lu", str, argp);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +0000477 on_off(argp != 0);
Glenn L McGrath07085852003-10-09 07:28:22 +0000478}
Eric Andersen416c2422003-12-12 00:08:57 +0000479
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000480#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
Denis Vlasenko4daad902007-09-27 10:20:47 +0000481static void print_ascii(const char *p, int length)
482{
483#if BB_BIG_ENDIAN
484#define LE_ONLY(x)
485 enum { ofs = 0 };
486#else
487#define LE_ONLY(x) x
488 /* every 16bit word is big-endian (i.e. inverted) */
489 /* accessing bytes in 1,0, 3,2, 5,4... sequence */
490 int ofs = 1;
491#endif
492
493 length *= 2;
494 /* find first non-space & print it */
495 while (length && p[ofs] != ' ') {
496 p++;
497 LE_ONLY(ofs = -ofs;)
498 length--;
499 }
500 while (length && p[ofs]) {
501 bb_putchar(p[ofs]);
502 p++;
503 LE_ONLY(ofs = -ofs;)
504 length--;
505 }
506 bb_putchar('\n');
507#undef LE_ONLY
508}
Glenn L McGrath07085852003-10-09 07:28:22 +0000509
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000510static void xprint_ascii(uint16_t *val, int i, const char *string, int n)
Glenn L McGrath07085852003-10-09 07:28:22 +0000511{
Denis Vlasenkob6aae0f2007-01-29 22:51:25 +0000512 if (val[i]) {
513 printf("\t%-20s", string);
Denis Vlasenko4daad902007-09-27 10:20:47 +0000514 print_ascii((void*)&val[i], n);
Glenn L McGrath07085852003-10-09 07:28:22 +0000515 }
516}
Glenn L McGrath07085852003-10-09 07:28:22 +0000517
Glenn L McGrath07085852003-10-09 07:28:22 +0000518static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode)
519{
Eric Andersen3443bd72003-07-22 07:30:36 +0000520 uint16_t ii;
521 uint8_t err_dma = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +0000522
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000523 for (ii = 0; ii <= MODE_MAX; ii++) {
524 if (mode_sel & 0x0001) {
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000525 printf("*%cdma%u ", cc, ii);
Rob Landleya3e4f382006-04-29 16:06:31 +0000526 if (*have_mode)
Glenn L McGrath07085852003-10-09 07:28:22 +0000527 err_dma = 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000528 *have_mode = 1;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000529 } else if (mode_sup & 0x0001)
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000530 printf("%cdma%u ", cc, ii);
Glenn L McGrath07085852003-10-09 07:28:22 +0000531
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000532 mode_sup >>= 1;
533 mode_sel >>= 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000534 }
535 return err_dma;
536}
Glenn L McGrath07085852003-10-09 07:28:22 +0000537
Denis Vlasenko91303402007-10-30 19:36:54 +0000538static const char pkt_str[] ALIGN1 =
539 "Direct-access device" "\0" /* word 0, bits 12-8 = 00 */
540 "Sequential-access device" "\0" /* word 0, bits 12-8 = 01 */
541 "Printer" "\0" /* word 0, bits 12-8 = 02 */
542 "Processor" "\0" /* word 0, bits 12-8 = 03 */
543 "Write-once device" "\0" /* word 0, bits 12-8 = 04 */
544 "CD-ROM" "\0" /* word 0, bits 12-8 = 05 */
545 "Scanner" "\0" /* word 0, bits 12-8 = 06 */
546 "Optical memory" "\0" /* word 0, bits 12-8 = 07 */
547 "Medium changer" "\0" /* word 0, bits 12-8 = 08 */
548 "Communications device" "\0" /* word 0, bits 12-8 = 09 */
549 "ACS-IT8 device" "\0" /* word 0, bits 12-8 = 0a */
550 "ACS-IT8 device" "\0" /* word 0, bits 12-8 = 0b */
551 "Array controller" "\0" /* word 0, bits 12-8 = 0c */
552 "Enclosure services" "\0" /* word 0, bits 12-8 = 0d */
553 "Reduced block command device" "\0" /* word 0, bits 12-8 = 0e */
554 "Optical card reader/writer" "\0" /* word 0, bits 12-8 = 0f */
555;
556
557static const char ata1_cfg_str[] ALIGN1 = /* word 0 in ATA-1 mode */
558 "reserved" "\0" /* bit 0 */
559 "hard sectored" "\0" /* bit 1 */
560 "soft sectored" "\0" /* bit 2 */
561 "not MFM encoded " "\0" /* bit 3 */
562 "head switch time > 15us" "\0" /* bit 4 */
563 "spindle motor control option" "\0" /* bit 5 */
564 "fixed drive" "\0" /* bit 6 */
565 "removable drive" "\0" /* bit 7 */
566 "disk xfer rate <= 5Mbs" "\0" /* bit 8 */
567 "disk xfer rate > 5Mbs, <= 10Mbs" "\0" /* bit 9 */
568 "disk xfer rate > 5Mbs" "\0" /* bit 10 */
569 "rotational speed tol." "\0" /* bit 11 */
570 "data strobe offset option" "\0" /* bit 12 */
571 "track offset option" "\0" /* bit 13 */
572 "format speed tolerance gap reqd" "\0" /* bit 14 */
573 "ATAPI" /* bit 14 */
574;
575
576static const char minor_str[] ALIGN1 =
577 /* word 81 value: */
578 "Unspecified" "\0" /* 0x0000 */
579 "ATA-1 X3T9.2 781D prior to rev.4" "\0" /* 0x0001 */
580 "ATA-1 published, ANSI X3.221-1994" "\0" /* 0x0002 */
581 "ATA-1 X3T9.2 781D rev.4" "\0" /* 0x0003 */
582 "ATA-2 published, ANSI X3.279-1996" "\0" /* 0x0004 */
583 "ATA-2 X3T10 948D prior to rev.2k" "\0" /* 0x0005 */
584 "ATA-3 X3T10 2008D rev.1" "\0" /* 0x0006 */
585 "ATA-2 X3T10 948D rev.2k" "\0" /* 0x0007 */
586 "ATA-3 X3T10 2008D rev.0" "\0" /* 0x0008 */
587 "ATA-2 X3T10 948D rev.3" "\0" /* 0x0009 */
588 "ATA-3 published, ANSI X3.298-199x" "\0" /* 0x000a */
589 "ATA-3 X3T10 2008D rev.6" "\0" /* 0x000b */
590 "ATA-3 X3T13 2008D rev.7 and 7a" "\0" /* 0x000c */
591 "ATA/ATAPI-4 X3T13 1153D rev.6" "\0" /* 0x000d */
592 "ATA/ATAPI-4 T13 1153D rev.13" "\0" /* 0x000e */
593 "ATA/ATAPI-4 X3T13 1153D rev.7" "\0" /* 0x000f */
594 "ATA/ATAPI-4 T13 1153D rev.18" "\0" /* 0x0010 */
595 "ATA/ATAPI-4 T13 1153D rev.15" "\0" /* 0x0011 */
596 "ATA/ATAPI-4 published, ANSI INCITS 317-1998" "\0" /* 0x0012 */
597 "ATA/ATAPI-5 T13 1321D rev.3" "\0" /* 0x0013 */
598 "ATA/ATAPI-4 T13 1153D rev.14" "\0" /* 0x0014 */
599 "ATA/ATAPI-5 T13 1321D rev.1" "\0" /* 0x0015 */
600 "ATA/ATAPI-5 published, ANSI INCITS 340-2000" "\0" /* 0x0016 */
601 "ATA/ATAPI-4 T13 1153D rev.17" "\0" /* 0x0017 */
602 "ATA/ATAPI-6 T13 1410D rev.0" "\0" /* 0x0018 */
603 "ATA/ATAPI-6 T13 1410D rev.3a" "\0" /* 0x0019 */
604 "ATA/ATAPI-7 T13 1532D rev.1" "\0" /* 0x001a */
605 "ATA/ATAPI-6 T13 1410D rev.2" "\0" /* 0x001b */
606 "ATA/ATAPI-6 T13 1410D rev.1" "\0" /* 0x001c */
607 "ATA/ATAPI-7 published, ANSI INCITS 397-2005" "\0" /* 0x001d */
608 "ATA/ATAPI-7 T13 1532D rev.0" "\0" /* 0x001e */
609 "reserved" "\0" /* 0x001f */
610 "reserved" "\0" /* 0x0020 */
611 "ATA/ATAPI-7 T13 1532D rev.4a" "\0" /* 0x0021 */
612 "ATA/ATAPI-6 published, ANSI INCITS 361-2002" "\0" /* 0x0022 */
613 "reserved" /* 0x0023-0xfffe */
614;
615static const char actual_ver[MINOR_MAX + 2] ALIGN1 = {
616 /* word 81 value: */
617 0, /* 0x0000 WARNING: actual_ver[] array */
618 1, /* 0x0001 WARNING: corresponds */
619 1, /* 0x0002 WARNING: *exactly* */
620 1, /* 0x0003 WARNING: to the ATA/ */
621 2, /* 0x0004 WARNING: ATAPI version */
622 2, /* 0x0005 WARNING: listed in */
623 3, /* 0x0006 WARNING: the */
624 2, /* 0x0007 WARNING: minor_str */
625 3, /* 0x0008 WARNING: array */
626 2, /* 0x0009 WARNING: above. */
627 3, /* 0x000a WARNING: */
628 3, /* 0x000b WARNING: If you change */
629 3, /* 0x000c WARNING: that one, */
630 4, /* 0x000d WARNING: change this one */
631 4, /* 0x000e WARNING: too!!! */
632 4, /* 0x000f */
633 4, /* 0x0010 */
634 4, /* 0x0011 */
635 4, /* 0x0012 */
636 5, /* 0x0013 */
637 4, /* 0x0014 */
638 5, /* 0x0015 */
639 5, /* 0x0016 */
640 4, /* 0x0017 */
641 6, /* 0x0018 */
642 6, /* 0x0019 */
643 7, /* 0x001a */
644 6, /* 0x001b */
645 6, /* 0x001c */
646 7, /* 0x001d */
647 7, /* 0x001e */
648 0, /* 0x001f */
649 0, /* 0x0020 */
650 7, /* 0x0021 */
651 6, /* 0x0022 */
652 0 /* 0x0023-0xfffe */
653};
654
655static const char cmd_feat_str[] ALIGN1 =
656 "" "\0" /* word 82 bit 15: obsolete */
657 "NOP cmd" "\0" /* word 82 bit 14 */
658 "READ BUFFER cmd" "\0" /* word 82 bit 13 */
659 "WRITE BUFFER cmd" "\0" /* word 82 bit 12 */
660 "" "\0" /* word 82 bit 11: obsolete */
661 "Host Protected Area feature set" "\0" /* word 82 bit 10 */
662 "DEVICE RESET cmd" "\0" /* word 82 bit 9 */
663 "SERVICE interrupt" "\0" /* word 82 bit 8 */
664 "Release interrupt" "\0" /* word 82 bit 7 */
665 "Look-ahead" "\0" /* word 82 bit 6 */
666 "Write cache" "\0" /* word 82 bit 5 */
667 "PACKET command feature set" "\0" /* word 82 bit 4 */
668 "Power Management feature set" "\0" /* word 82 bit 3 */
669 "Removable Media feature set" "\0" /* word 82 bit 2 */
670 "Security Mode feature set" "\0" /* word 82 bit 1 */
671 "SMART feature set" "\0" /* word 82 bit 0 */
672 /* -------------- */
673 "" "\0" /* word 83 bit 15: !valid bit */
674 "" "\0" /* word 83 bit 14: valid bit */
675 "FLUSH CACHE EXT cmd" "\0" /* word 83 bit 13 */
676 "Mandatory FLUSH CACHE cmd " "\0" /* word 83 bit 12 */
677 "Device Configuration Overlay feature set " "\0"
678 "48-bit Address feature set " "\0" /* word 83 bit 10 */
679 "" "\0"
680 "SET MAX security extension" "\0" /* word 83 bit 8 */
681 "Address Offset Reserved Area Boot" "\0" /* word 83 bit 7 */
682 "SET FEATURES subcommand required to spinup after power up" "\0"
683 "Power-Up In Standby feature set" "\0" /* word 83 bit 5 */
684 "Removable Media Status Notification feature set" "\0"
685 "Adv. Power Management feature set" "\0" /* word 83 bit 3 */
686 "CFA feature set" "\0" /* word 83 bit 2 */
687 "READ/WRITE DMA QUEUED" "\0" /* word 83 bit 1 */
688 "DOWNLOAD MICROCODE cmd" "\0" /* word 83 bit 0 */
689 /* -------------- */
690 "" "\0" /* word 84 bit 15: !valid bit */
691 "" "\0" /* word 84 bit 14: valid bit */
692 "" "\0" /* word 84 bit 13: reserved */
693 "" "\0" /* word 84 bit 12: reserved */
694 "" "\0" /* word 84 bit 11: reserved */
695 "" "\0" /* word 84 bit 10: reserved */
696 "" "\0" /* word 84 bit 9: reserved */
697 "" "\0" /* word 84 bit 8: reserved */
698 "" "\0" /* word 84 bit 7: reserved */
699 "" "\0" /* word 84 bit 6: reserved */
700 "General Purpose Logging feature set" "\0" /* word 84 bit 5 */
701 "" "\0" /* word 84 bit 4: reserved */
702 "Media Card Pass Through Command feature set " "\0"
703 "Media serial number " "\0" /* word 84 bit 2 */
704 "SMART self-test " "\0" /* word 84 bit 1 */
705 "SMART error logging " /* word 84 bit 0 */
706;
707
708static const char secu_str[] ALIGN1 =
709 "supported" "\0" /* word 128, bit 0 */
710 "enabled" "\0" /* word 128, bit 1 */
711 "locked" "\0" /* word 128, bit 2 */
712 "frozen" "\0" /* word 128, bit 3 */
713 "expired: security count" "\0" /* word 128, bit 4 */
714 "supported: enhanced erase" /* word 128, bit 5 */
715;
716
717// Parse 512 byte disk identification block and print much crap.
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000718static void identify(uint16_t *val) NORETURN;
Denis Vlasenko4daad902007-09-27 10:20:47 +0000719static void identify(uint16_t *val)
Eric Andersen3443bd72003-07-22 07:30:36 +0000720{
Denis Vlasenko4daad902007-09-27 10:20:47 +0000721 uint16_t ii, jj, kk;
Eric Andersen3443bd72003-07-22 07:30:36 +0000722 uint16_t like_std = 1, std = 0, min_std = 0xffff;
723 uint16_t dev = NO_DEV, eqpt = NO_DEV;
724 uint8_t have_mode = 0, err_dma = 0;
725 uint8_t chksum = 0;
726 uint32_t ll, mm, nn, oo;
Rob Landley2e2d7522006-04-29 15:23:33 +0000727 uint64_t bbbig; /* (:) */
Rob Landleyadde7982006-05-16 15:32:30 +0000728 const char *strng;
Denis Vlasenko4daad902007-09-27 10:20:47 +0000729#if BB_BIG_ENDIAN
730 uint16_t buf[256];
Eric Andersen3443bd72003-07-22 07:30:36 +0000731
Denis Vlasenko4daad902007-09-27 10:20:47 +0000732 // Adjust for endianness
733 swab(val, buf, sizeof(buf));
734 val = buf;
735#endif
Denys Vlasenkob22bbff2009-07-04 16:50:43 +0200736 /* check if we recognize the device type */
Denis Vlasenko4daad902007-09-27 10:20:47 +0000737 bb_putchar('\n');
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000738 if (!(val[GEN_CONFIG] & NOT_ATA)) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000739 dev = ATA_DEV;
740 printf("ATA device, with ");
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000741 } else if (val[GEN_CONFIG]==CFA_SUPPORT_VAL) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000742 dev = ATA_DEV;
743 like_std = 4;
744 printf("CompactFlash ATA device, with ");
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000745 } else if (!(val[GEN_CONFIG] & NOT_ATAPI)) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000746 dev = ATAPI_DEV;
747 eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
Denis Vlasenkobfc3d822007-11-04 04:10:17 +0000748 printf("ATAPI %s, with ", eqpt <= 0xf ? nth_string(pkt_str, eqpt) : "unknown");
Eric Andersen3443bd72003-07-22 07:30:36 +0000749 like_std = 3;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000750 } else
Denis Vlasenko91303402007-10-30 19:36:54 +0000751 /* "Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n" */
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +0000752 bb_error_msg_and_die("unknown device type");
Eric Andersen3443bd72003-07-22 07:30:36 +0000753
Rob Landleyadde7982006-05-16 15:32:30 +0000754 printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : "");
Eric Andersen3443bd72003-07-22 07:30:36 +0000755 /* Info from the specific configuration word says whether or not the
756 * ID command completed correctly. It is only defined, however in
Glenn L McGrath07085852003-10-09 07:28:22 +0000757 * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior
Eric Andersen3443bd72003-07-22 07:30:36 +0000758 * standards. Since the values allowed for this word are extremely
759 * specific, it should be safe to check it now, even though we don't
760 * know yet what standard this device is using.
761 */
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000762 if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)
763 || (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL)
764 ) {
Glenn L McGrath07085852003-10-09 07:28:22 +0000765 like_std = 5;
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000766 if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
Denys Vlasenkod60752f2015-10-07 22:42:45 +0200767 puts("powers-up in standby; SET FEATURES subcmd spins-up.");
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000768 if (((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
Denys Vlasenkod60752f2015-10-07 22:42:45 +0200769 puts("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n");
Eric Andersen3443bd72003-07-22 07:30:36 +0000770 }
771
772 /* output the model and serial numbers and the fw revision */
Glenn L McGrath07085852003-10-09 07:28:22 +0000773 xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL);
774 xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL);
775 xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV);
776 xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA);
777 xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF);
Eric Andersen3443bd72003-07-22 07:30:36 +0000778
779 /* major & minor standards version number (Note: these words were not
780 * defined until ATA-3 & the CDROM std uses different words.) */
781 printf("Standards:");
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000782 if (eqpt != CDROM) {
783 if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) {
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000784 if (like_std < 3) like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000785 std = actual_ver[val[MINOR]];
Denys Vlasenkof3ea7922010-07-26 01:06:14 +0200786 if (std)
787 printf("\n\tUsed: %s ", nth_string(minor_str, val[MINOR]));
Eric Andersen3443bd72003-07-22 07:30:36 +0000788 }
789 /* looks like when they up-issue the std, they obsolete one;
Glenn L McGrath07085852003-10-09 07:28:22 +0000790 * thus, only the newest 4 issues need be supported. (That's
Eric Andersen3443bd72003-07-22 07:30:36 +0000791 * what "kk" and "min_std" are all about.) */
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000792 if (val[MAJOR] && (val[MAJOR] != NOVAL_1)) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000793 printf("\n\tSupported: ");
794 jj = val[MAJOR] << 1;
795 kk = like_std >4 ? like_std-4: 0;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000796 for (ii = 14; (ii >0)&&(ii>kk); ii--) {
797 if (jj & 0x8000) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000798 printf("%u ", ii);
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000799 if (like_std < ii) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000800 like_std = ii;
801 kk = like_std >4 ? like_std-4: 0;
802 }
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000803 if (min_std > ii) min_std = ii;
Eric Andersen3443bd72003-07-22 07:30:36 +0000804 }
805 jj <<= 1;
806 }
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000807 if (like_std < 3) like_std = 3;
Eric Andersen3443bd72003-07-22 07:30:36 +0000808 }
809 /* Figure out what standard the device is using if it hasn't told
810 * us. If we know the std, check if the device is using any of
811 * the words from the next level up. It happens.
812 */
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000813 if (like_std < std) like_std = std;
Glenn L McGrath07085852003-10-09 07:28:22 +0000814
Rob Landleya3e4f382006-04-29 16:06:31 +0000815 if (((std == 5) || (!std && (like_std < 6))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000816 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
817 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) ||
818 ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) &&
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000819 ( val[CMDS_SUPP_2] & CMDS_W84) ) )
820 ) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000821 like_std = 6;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000822 } else if (((std == 4) || (!std && (like_std < 5))) &&
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000823 ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) ||
Glenn L McGrath07085852003-10-09 07:28:22 +0000824 (( val[HWRST_RSLT] & VALID) == VALID_VAL) ||
825 ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
826 (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) )
827 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000828 like_std = 5;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000829 } else if (((std == 3) || (!std && (like_std < 4))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000830 ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
831 ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) ||
832 (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) ||
833 (( val[CAPAB_1] & VALID) == VALID_VAL) ||
834 (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) ||
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000835 (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) )
836 ) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000837 like_std = 4;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000838 } else if (((std == 2) || (!std && (like_std < 3)))
839 && ((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
840 ) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000841 like_std = 3;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000842 } else if (((std == 1) || (!std && (like_std < 2))) &&
Glenn L McGrath07085852003-10-09 07:28:22 +0000843 ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) ||
844 (val[WHATS_VALID] & OK_W64_70)) )
845 {
Eric Andersen3443bd72003-07-22 07:30:36 +0000846 like_std = 2;
847 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000848
Rob Landleya3e4f382006-04-29 16:06:31 +0000849 if (!std)
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000850 printf("\n\tLikely used: %u\n", like_std);
Rob Landleya3e4f382006-04-29 16:06:31 +0000851 else if (like_std > std)
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000852 printf("& some of %u\n", like_std);
Glenn L McGrath07085852003-10-09 07:28:22 +0000853 else
Denis Vlasenko4daad902007-09-27 10:20:47 +0000854 bb_putchar('\n');
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000855 } else {
Eric Andersen3443bd72003-07-22 07:30:36 +0000856 /* TBD: do CDROM stuff more thoroughly. For now... */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000857 kk = 0;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000858 if (val[CDR_MINOR] == 9) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000859 kk = 1;
860 printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5");
861 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000862 if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1)) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000863 kk = 1;
864 printf("\n\tSupported: CD-ROM ATAPI");
865 jj = val[CDR_MAJOR] >> 1;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000866 for (ii = 1; ii < 15; ii++) {
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000867 if (jj & 0x0001) printf("-%u ", ii);
Eric Andersen3443bd72003-07-22 07:30:36 +0000868 jj >>= 1;
869 }
870 }
Denis Vlasenkofeb7ae72007-10-01 12:05:12 +0000871 puts(kk ? "" : "\n\tLikely used CD-ROM ATAPI-1");
Eric Andersen3443bd72003-07-22 07:30:36 +0000872 /* the cdrom stuff is more like ATA-2 than anything else, so: */
873 like_std = 2;
874 }
875
Rob Landleya3e4f382006-04-29 16:06:31 +0000876 if (min_std == 0xffff)
Glenn L McGrath07085852003-10-09 07:28:22 +0000877 min_std = like_std > 4 ? like_std - 3 : 1;
Eric Andersen3443bd72003-07-22 07:30:36 +0000878
Denys Vlasenkod60752f2015-10-07 22:42:45 +0200879 puts("Configuration:");
Eric Andersen3443bd72003-07-22 07:30:36 +0000880 /* more info from the general configuration word */
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000881 if ((eqpt != CDROM) && (like_std == 1)) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000882 jj = val[GEN_CONFIG] >> 1;
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000883 for (ii = 1; ii < 15; ii++) {
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +0000884 if (jj & 0x0001)
Denis Vlasenkobfc3d822007-11-04 04:10:17 +0000885 printf("\t%s\n", nth_string(ata1_cfg_str, ii));
Eric Andersen3443bd72003-07-22 07:30:36 +0000886 jj >>=1;
887 }
888 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000889 if (dev == ATAPI_DEV) {
Rob Landleyadde7982006-05-16 15:32:30 +0000890 if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_3MS_VAL)
891 strng = "3ms";
892 else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_INTR_VAL)
893 strng = "<=10ms with INTRQ";
894 else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_50US_VAL)
895 strng ="50us";
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000896 else
Denis Vlasenko91303402007-10-30 19:36:54 +0000897 strng = "unknown";
Rob Landleyadde7982006-05-16 15:32:30 +0000898 printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */
899
900 if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_12_VAL)
901 strng = "12 bytes";
902 else if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_16_VAL)
903 strng = "16 bytes";
904 else
Denis Vlasenko91303402007-10-30 19:36:54 +0000905 strng = "unknown";
Rob Landleyadde7982006-05-16 15:32:30 +0000906 puts(strng);
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000907 } else {
Glenn L McGrath07085852003-10-09 07:28:22 +0000908 /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */
Eric Andersen3443bd72003-07-22 07:30:36 +0000909 ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB];
Denys Vlasenko6d335be2009-05-20 14:48:03 +0200910 mm = 0;
911 bbbig = 0;
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +0000912 if ((ll > 0x00FBFC10) && (!val[LCYLS]))
Denys Vlasenkod60752f2015-10-07 22:42:45 +0200913 puts("\tCHS addressing not supported");
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000914 else {
Eric Andersen3443bd72003-07-22 07:30:36 +0000915 jj = val[WHATS_VALID] & OK_W54_58;
Denys Vlasenko6d335be2009-05-20 14:48:03 +0200916 printf("\tLogical\t\tmax\tcurrent\n"
917 "\tcylinders\t%u\t%u\n"
918 "\theads\t\t%u\t%u\n"
919 "\tsectors/track\t%u\t%u\n"
920 "\t--\n",
921 val[LCYLS],
922 jj ? val[LCYLS_CUR] : 0,
923 val[LHEADS],
924 jj ? val[LHEADS_CUR] : 0,
925 val[LSECTS],
926 jj ? val[LSECTS_CUR] : 0);
Glenn L McGrath07085852003-10-09 07:28:22 +0000927
Rob Landleyadde7982006-05-16 15:32:30 +0000928 if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES]))
Denys Vlasenko6d335be2009-05-20 14:48:03 +0200929 printf("\tbytes/track: %u\tbytes/sector: %u\n",
930 val[TRACK_BYTES], val[SECT_BYTES]);
Glenn L McGrath07085852003-10-09 07:28:22 +0000931
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000932 if (jj) {
Eric Andersen3443bd72003-07-22 07:30:36 +0000933 mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB];
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000934 if (like_std < 3) {
935 /* check Endian of capacity bytes */
Eric Andersen3443bd72003-07-22 07:30:36 +0000936 nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR];
937 oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB];
Rob Landleya3e4f382006-04-29 16:06:31 +0000938 if (abs(mm - nn) > abs(oo - nn))
Eric Andersen3443bd72003-07-22 07:30:36 +0000939 mm = oo;
940 }
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000941 printf("\tCHS current addressable sectors:%11u\n", mm);
Glenn L McGrath07085852003-10-09 07:28:22 +0000942 }
Eric Andersen3443bd72003-07-22 07:30:36 +0000943 }
944 /* LBA addressing */
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000945 printf("\tLBA user addressable sectors:%11u\n", ll);
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000946 if (((val[CMDS_SUPP_1] & VALID) == VALID_VAL)
947 && (val[CMDS_SUPP_1] & SUPPORT_48_BIT)
948 ) {
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +0000949 bbbig = (uint64_t)val[LBA_64_MSB] << 48 |
950 (uint64_t)val[LBA_48_MSB] << 32 |
951 (uint64_t)val[LBA_MID] << 16 |
Denis Vlasenko6963eb52007-05-22 21:46:11 +0000952 val[LBA_LSB];
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000953 printf("\tLBA48 user addressable sectors:%11"PRIu64"\n", bbbig);
Eric Andersen3443bd72003-07-22 07:30:36 +0000954 }
Glenn L McGrath07085852003-10-09 07:28:22 +0000955
956 if (!bbbig)
Rob Landley2e2d7522006-04-29 15:23:33 +0000957 bbbig = (uint64_t)(ll>mm ? ll : mm); /* # 512 byte blocks */
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000958 printf("\tdevice size with M = 1024*1024: %11"PRIu64" MBytes\n", bbbig>>11);
959 bbbig = (bbbig << 9) / 1000000;
960 printf("\tdevice size with M = 1000*1000: %11"PRIu64" MBytes ", bbbig);
Glenn L McGrath07085852003-10-09 07:28:22 +0000961
Rob Landleyadde7982006-05-16 15:32:30 +0000962 if (bbbig > 1000)
Rob Landley81dab2c2006-05-28 01:56:08 +0000963 printf("(%"PRIu64" GB)\n", bbbig/1000);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000964 else
Denis Vlasenko4daad902007-09-27 10:20:47 +0000965 bb_putchar('\n');
Eric Andersen3443bd72003-07-22 07:30:36 +0000966 }
967
968 /* hw support of commands (capabilities) */
Glenn L McGrath07085852003-10-09 07:28:22 +0000969 printf("Capabilities:\n\t");
970
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000971 if (dev == ATAPI_DEV) {
Denys Vlasenko6d335be2009-05-20 14:48:03 +0200972 if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP))
973 printf("Cmd queuing, ");
974 if (val[CAPAB_0] & OVLP_SUP)
975 printf("Cmd overlap, ");
Eric Andersen3443bd72003-07-22 07:30:36 +0000976 }
Rob Landleyadde7982006-05-16 15:32:30 +0000977 if (val[CAPAB_0] & LBA_SUP) printf("LBA, ");
Glenn L McGrath07085852003-10-09 07:28:22 +0000978
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000979 if (like_std != 1) {
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000980 printf("IORDY%s(can%s be disabled)\n",
Denys Vlasenko6d335be2009-05-20 14:48:03 +0200981 !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "",
982 (val[CAPAB_0] & IORDY_OFF) ? "" :"not");
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000983 } else
Denys Vlasenkod60752f2015-10-07 22:42:45 +0200984 puts("no IORDY");
Glenn L McGrath07085852003-10-09 07:28:22 +0000985
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000986 if ((like_std == 1) && val[BUF_TYPE]) {
Rob Landleyadde7982006-05-16 15:32:30 +0000987 printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE],
Denys Vlasenko6d335be2009-05-20 14:48:03 +0200988 (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector",
989 (val[BUF_TYPE] > 2) ? " with read caching ability" : "");
Eric Andersen3443bd72003-07-22 07:30:36 +0000990 }
Rob Landleyadde7982006-05-16 15:32:30 +0000991
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000992 if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) {
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000993 printf("\tBuffer size: %.1fkB\n", (float)val[BUFFER__SIZE]/2);
Eric Andersen3443bd72003-07-22 07:30:36 +0000994 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000995 if ((min_std < 4) && (val[RW_LONG])) {
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000996 printf("\tbytes avail on r/w long: %u\n", val[RW_LONG]);
Eric Andersen3443bd72003-07-22 07:30:36 +0000997 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +0000998 if ((eqpt != CDROM) && (like_std > 3)) {
Denis Vlasenkof1ba7492007-03-28 00:14:01 +0000999 printf("\tQueue depth: %u\n", (val[QUEUE_DEPTH] & DEPTH_BITS) + 1);
Eric Andersen3443bd72003-07-22 07:30:36 +00001000 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001001
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001002 if (dev == ATA_DEV) {
Rob Landleya3e4f382006-04-29 16:06:31 +00001003 if (like_std == 1)
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001004 printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : "");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001005 else {
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001006 printf("\tStandby timer values: spec'd by %s",
1007 (val[CAPAB_0] & STD_STBY) ? "standard" : "vendor");
Rob Landleya3e4f382006-04-29 16:06:31 +00001008 if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL))
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001009 printf(", %s device specific minimum\n",
1010 (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no");
Glenn L McGrath07085852003-10-09 07:28:22 +00001011 else
Denis Vlasenko4daad902007-09-27 10:20:47 +00001012 bb_putchar('\n');
Eric Andersen3443bd72003-07-22 07:30:36 +00001013 }
1014 printf("\tR/W multiple sector transfer: ");
Rob Landleya3e4f382006-04-29 16:06:31 +00001015 if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER))
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001016 puts("not supported");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001017 else {
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001018 printf("Max = %u\tCurrent = ", val[SECTOR_XFER_MAX] & SECTOR_XFER);
Rob Landleyadde7982006-05-16 15:32:30 +00001019 if (val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID)
1020 printf("%u\n", val[SECTOR_XFER_CUR] & SECTOR_XFER);
1021 else
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001022 puts("?");
Eric Andersen3443bd72003-07-22 07:30:36 +00001023 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001024 if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001025 /* We print out elsewhere whether the APM feature is enabled or
Denys Vlasenko60cb48c2013-01-14 15:57:44 +01001026 * not. If it's not enabled, let's not repeat the info; just print
1027 * nothing here. */
Glenn L McGrath07085852003-10-09 07:28:22 +00001028 printf("\tAdvancedPM level: ");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001029 if ((val[ADV_PWR] & 0xFF00) == 0x4000) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001030 uint8_t apm_level = val[ADV_PWR] & 0x00FF;
Eric Andersen3443bd72003-07-22 07:30:36 +00001031 printf("%u (0x%x)\n", apm_level, apm_level);
Glenn L McGrath07085852003-10-09 07:28:22 +00001032 }
1033 else
Eric Andersen3443bd72003-07-22 07:30:36 +00001034 printf("unknown setting (0x%04x)\n", val[ADV_PWR]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001035 }
Rob Landleyadde7982006-05-16 15:32:30 +00001036 if (like_std > 5 && val[ACOUSTIC]) {
1037 printf("\tRecommended acoustic management value: %u, current value: %u\n",
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001038 (val[ACOUSTIC] >> 8) & 0x00ff,
1039 val[ACOUSTIC] & 0x00ff);
Eric Andersen3443bd72003-07-22 07:30:36 +00001040 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001041 } else {
Denys Vlasenko6830ade2013-01-15 13:58:01 +01001042 /* ATAPI */
Rob Landleyadde7982006-05-16 15:32:30 +00001043 if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ))
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001044 puts("\tATA sw reset required");
Glenn L McGrath07085852003-10-09 07:28:22 +00001045
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001046 if (val[PKT_REL] || val[SVC_NBSY]) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001047 printf("\tOverlap support:");
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001048 if (val[PKT_REL])
1049 printf(" %uus to release bus.", val[PKT_REL]);
1050 if (val[SVC_NBSY])
1051 printf(" %uus to clear BSY after SERVICE cmd.",
1052 val[SVC_NBSY]);
Denis Vlasenko4daad902007-09-27 10:20:47 +00001053 bb_putchar('\n');
Eric Andersen3443bd72003-07-22 07:30:36 +00001054 }
1055 }
1056
1057 /* DMA stuff. Check that only one DMA mode is selected. */
1058 printf("\tDMA: ");
Rob Landleya3e4f382006-04-29 16:06:31 +00001059 if (!(val[CAPAB_0] & DMA_SUP))
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001060 puts("not supported");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001061 else {
Rob Landleyadde7982006-05-16 15:32:30 +00001062 if (val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA])
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001063 printf(" sdma%u\n", (val[DMA_MODE] & MODE) >> 8);
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001064 if (val[SINGLE_DMA]) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001065 jj = val[SINGLE_DMA];
1066 kk = val[SINGLE_DMA] >> 8;
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001067 err_dma += mode_loop(jj, kk, 's', &have_mode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001068 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001069 if (val[MULTI_DMA]) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001070 jj = val[MULTI_DMA];
1071 kk = val[MULTI_DMA] >> 8;
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001072 err_dma += mode_loop(jj, kk, 'm', &have_mode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001073 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001074 if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001075 jj = val[ULTRA_DMA];
1076 kk = val[ULTRA_DMA] >> 8;
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001077 err_dma += mode_loop(jj, kk, 'u', &have_mode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001078 }
Rob Landleyadde7982006-05-16 15:32:30 +00001079 if (err_dma || !have_mode) printf("(?)");
Denis Vlasenko4daad902007-09-27 10:20:47 +00001080 bb_putchar('\n');
Eric Andersen3443bd72003-07-22 07:30:36 +00001081
Rob Landleyadde7982006-05-16 15:32:30 +00001082 if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP))
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001083 puts("\t\tInterleaved DMA support");
Eric Andersen3443bd72003-07-22 07:30:36 +00001084
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001085 if ((val[WHATS_VALID] & OK_W64_70)
1086 && (val[DMA_TIME_MIN] || val[DMA_TIME_NORM])
1087 ) {
Rob Landleyadde7982006-05-16 15:32:30 +00001088 printf("\t\tCycle time:");
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001089 if (val[DMA_TIME_MIN]) printf(" min=%uns", val[DMA_TIME_MIN]);
1090 if (val[DMA_TIME_NORM]) printf(" recommended=%uns", val[DMA_TIME_NORM]);
Denis Vlasenko4daad902007-09-27 10:20:47 +00001091 bb_putchar('\n');
Eric Andersen3443bd72003-07-22 07:30:36 +00001092 }
1093 }
1094
1095 /* Programmed IO stuff */
1096 printf("\tPIO: ");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00001097 /* If a drive supports mode n (e.g. 3), it also supports all modes less
Eric Andersen3443bd72003-07-22 07:30:36 +00001098 * than n (e.g. 3, 2, 1 and 0). Print all the modes. */
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001099 if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP)) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001100 jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007;
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001101 for (ii = 0; ii <= PIO_MODE_MAX; ii++) {
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001102 if (jj & 0x0001) printf("pio%d ", ii);
Eric Andersen3443bd72003-07-22 07:30:36 +00001103 jj >>=1;
1104 }
Denis Vlasenko4daad902007-09-27 10:20:47 +00001105 bb_putchar('\n');
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001106 } else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE)) {
Rob Landleya3e4f382006-04-29 16:06:31 +00001107 for (ii = 0; ii <= val[PIO_MODE]>>8; ii++)
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001108 printf("pio%d ", ii);
Denis Vlasenko4daad902007-09-27 10:20:47 +00001109 bb_putchar('\n');
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001110 } else
Denis Vlasenko91303402007-10-30 19:36:54 +00001111 puts("unknown");
Glenn L McGrath07085852003-10-09 07:28:22 +00001112
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001113 if (val[WHATS_VALID] & OK_W64_70) {
1114 if (val[PIO_NO_FLOW] || val[PIO_FLOW]) {
Rob Landleyadde7982006-05-16 15:32:30 +00001115 printf("\t\tCycle time:");
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001116 if (val[PIO_NO_FLOW])
1117 printf(" no flow control=%uns", val[PIO_NO_FLOW]);
1118 if (val[PIO_FLOW])
1119 printf(" IORDY flow control=%uns", val[PIO_FLOW]);
Denis Vlasenko4daad902007-09-27 10:20:47 +00001120 bb_putchar('\n');
Eric Andersen3443bd72003-07-22 07:30:36 +00001121 }
1122 }
1123
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001124 if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) {
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001125 puts("Commands/features:\n"
1126 "\tEnabled\tSupported:");
Eric Andersen3443bd72003-07-22 07:30:36 +00001127 jj = val[CMDS_SUPP_0];
1128 kk = val[CMDS_EN_0];
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001129 for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) {
Denis Vlasenkobfc3d822007-11-04 04:10:17 +00001130 const char *feat_str = nth_string(cmd_feat_str, ii);
Denis Vlasenko91303402007-10-30 19:36:54 +00001131 if ((jj & 0x8000) && (*feat_str != '\0')) {
1132 printf("\t%s\t%s\n", (kk & 0x8000) ? " *" : "", feat_str);
Eric Andersen3443bd72003-07-22 07:30:36 +00001133 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001134 jj <<= 1;
1135 kk <<= 1;
1136 if (ii % 16 == 15) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001137 jj = val[CMDS_SUPP_0+1+(ii/16)];
1138 kk = val[CMDS_EN_0+1+(ii/16)];
1139 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001140 if (ii == 31) {
Rob Landleya3e4f382006-04-29 16:06:31 +00001141 if ((val[CMDS_SUPP_2] & VALID) != VALID_VAL)
Glenn L McGrath07085852003-10-09 07:28:22 +00001142 ii +=16;
Eric Andersen3443bd72003-07-22 07:30:36 +00001143 }
1144 }
1145 }
Rob Landleyadde7982006-05-16 15:32:30 +00001146 /* Removable Media Status Notification feature set */
Denis Vlasenko67b23e62006-10-03 21:00:06 +00001147 if ((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
Denis Vlasenkobfc3d822007-11-04 04:10:17 +00001148 printf("\t%s supported\n", nth_string(cmd_feat_str, 27));
Glenn L McGrath07085852003-10-09 07:28:22 +00001149
Eric Andersen3443bd72003-07-22 07:30:36 +00001150 /* security */
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001151 if ((eqpt != CDROM) && (like_std > 3)
1152 && (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME])
1153 ) {
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001154 puts("Security:");
Rob Landleyadde7982006-05-16 15:32:30 +00001155 if (val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1))
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001156 printf("\tMaster password revision code = %u\n", val[PSWD_CODE]);
Eric Andersen3443bd72003-07-22 07:30:36 +00001157 jj = val[SECU_STATUS];
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001158 if (jj) {
1159 for (ii = 0; ii < NUM_SECU_STR; ii++) {
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001160 printf("\t%s\t%s\n",
1161 (!(jj & 0x0001)) ? "not" : "",
1162 nth_string(secu_str, ii));
Eric Andersen3443bd72003-07-22 07:30:36 +00001163 jj >>=1;
1164 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001165 if (val[SECU_STATUS] & SECU_ENABLED) {
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001166 printf("\tSecurity level %s\n",
1167 (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high");
Eric Andersen3443bd72003-07-22 07:30:36 +00001168 }
1169 }
1170 jj = val[ERASE_TIME] & ERASE_BITS;
1171 kk = val[ENH_ERASE_TIME] & ERASE_BITS;
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001172 if (jj || kk) {
Denis Vlasenko7d60fc12008-06-05 06:51:06 +00001173 bb_putchar('\t');
Rob Landleyade7f952006-05-25 18:53:06 +00001174 if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, "");
1175 if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED ");
Denis Vlasenko4daad902007-09-27 10:20:47 +00001176 bb_putchar('\n');
Eric Andersen3443bd72003-07-22 07:30:36 +00001177 }
1178 }
1179
1180 /* reset result */
Rob Landleyadde7982006-05-16 15:32:30 +00001181 jj = val[HWRST_RSLT];
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001182 if ((jj & VALID) == VALID_VAL) {
Denis Vlasenko6bef3d12007-11-06 03:05:54 +00001183 oo = (jj & RST0);
1184 if (!oo)
Rob Landleyadde7982006-05-16 15:32:30 +00001185 jj >>= 8;
Rob Landleya3e4f382006-04-29 16:06:31 +00001186 if ((jj & DEV_DET) == JUMPER_VAL)
Rob Landleyadde7982006-05-16 15:32:30 +00001187 strng = " determined by the jumper";
Rob Landleya3e4f382006-04-29 16:06:31 +00001188 else if ((jj & DEV_DET) == CSEL_VAL)
Rob Landleyadde7982006-05-16 15:32:30 +00001189 strng = " determined by CSEL";
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001190 else
Rob Landleyadde7982006-05-16 15:32:30 +00001191 strng = "";
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001192 printf("HW reset results:\n"
1193 "\tCBLID- %s Vih\n"
1194 "\tDevice num = %i%s\n",
1195 (val[HWRST_RSLT] & CBLID) ? "above" : "below",
1196 !(oo), strng);
Eric Andersen3443bd72003-07-22 07:30:36 +00001197 }
1198
1199 /* more stuff from std 5 */
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001200 if ((like_std > 4) && (eqpt != CDROM)) {
1201 if (val[CFA_PWR_MODE] & VALID_W160) {
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001202 printf("CFA power mode 1:\n"
1203 "\t%s%s\n",
1204 (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled",
1205 (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : "");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001206 if (val[CFA_PWR_MODE] & MAX_AMPS)
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001207 printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS);
Eric Andersen3443bd72003-07-22 07:30:36 +00001208 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001209 if ((val[INTEGRITY] & SIG) == SIG_VAL) {
Rob Landleyadde7982006-05-16 15:32:30 +00001210 printf("Checksum: %scorrect\n", chksum ? "in" : "");
Eric Andersen3443bd72003-07-22 07:30:36 +00001211 }
1212 }
1213
Rob Landleyadde7982006-05-16 15:32:30 +00001214 exit(EXIT_SUCCESS);
Eric Andersen3443bd72003-07-22 07:30:36 +00001215}
1216#endif
1217
Eric Andersen3443bd72003-07-22 07:30:36 +00001218// Historically, if there was no HDIO_OBSOLETE_IDENTITY, then
1219// then the HDIO_GET_IDENTITY only returned 142 bytes.
1220// Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes,
1221// and HDIO_GET_IDENTITY returns 512 bytes. But the latest
1222// 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY
1223// (which they should, but they should just return -EINVAL).
1224//
1225// So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes.
1226// On a really old system, it will not, and we will be confused.
1227// Too bad, really.
1228
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001229#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
Denis Vlasenko91303402007-10-30 19:36:54 +00001230static const char cfg_str[] ALIGN1 =
Denis Vlasenko6b404432008-01-07 16:13:14 +00001231 """\0" "HardSect""\0" "SoftSect""\0" "NotMFM""\0"
1232 "HdSw>15uSec""\0" "SpinMotCtl""\0" "Fixed""\0" "Removeable""\0"
1233 "DTR<=5Mbs""\0" "DTR>5Mbs""\0" "DTR>10Mbs""\0" "RotSpdTol>.5%""\0"
1234 "dStbOff""\0" "TrkOff""\0" "FmtGapReq""\0" "nonMagnetic"
Denis Vlasenko91303402007-10-30 19:36:54 +00001235;
Eric Andersen3443bd72003-07-22 07:30:36 +00001236
Denis Vlasenko91303402007-10-30 19:36:54 +00001237static const char BuffType[] ALIGN1 =
1238 "unknown""\0" "1Sect""\0" "DualPort""\0" "DualPortCache"
1239;
Eric Andersen3443bd72003-07-22 07:30:36 +00001240
Denys Vlasenkoa7bb3c12009-10-08 12:28:08 +02001241static NOINLINE void dump_identity(const struct hd_driveid *id)
Eric Andersen3443bd72003-07-22 07:30:36 +00001242{
1243 int i;
Denis Vlasenko284d0fa2008-02-16 13:18:17 +00001244 const unsigned short *id_regs = (const void*) id;
Rob Landley0a7c8ef2006-02-22 17:01:00 +00001245
Glenn L McGrath07085852003-10-09 07:28:22 +00001246 printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={",
1247 id->model, id->fw_rev, id->serial_no);
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001248 for (i = 0; i <= 15; i++) {
Rob Landleyade7f952006-05-25 18:53:06 +00001249 if (id->config & (1<<i))
Denis Vlasenkobfc3d822007-11-04 04:10:17 +00001250 printf(" %s", nth_string(cfg_str, i));
Rob Landleyadde7982006-05-16 15:32:30 +00001251 }
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001252 printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n"
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001253 " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u",
1254 id->cyls, id->heads, id->sectors, id->track_bytes,
1255 id->sector_bytes, id->ecc_bytes,
1256 id->buf_type,
1257 nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type),
1258 id->buf_size/2, id->max_multsect);
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001259 if (id->max_multsect) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001260 printf(", MultSect=");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001261 if (!(id->multsect_valid & 1))
Eric Andersen3443bd72003-07-22 07:30:36 +00001262 printf("?%u?", id->multsect);
1263 else if (id->multsect)
1264 printf("%u", id->multsect);
1265 else
1266 printf("off");
1267 }
Denis Vlasenko4daad902007-09-27 10:20:47 +00001268 bb_putchar('\n');
Rob Landleyade7f952006-05-25 18:53:06 +00001269
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001270 if (!(id->field_valid & 1))
Rob Landleyade7f952006-05-25 18:53:06 +00001271 printf(" (maybe):");
1272
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001273 printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s", id->cur_cyls, id->cur_heads,
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001274 id->cur_sectors,
1275 (BB_BIG_ENDIAN) ?
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001276 (unsigned long)(id->cur_capacity0 << 16) | id->cur_capacity1 :
1277 (unsigned long)(id->cur_capacity1 << 16) | id->cur_capacity0,
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001278 ((id->capability&2) == 0) ? "no" : "yes");
Rob Landleyade7f952006-05-25 18:53:06 +00001279
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001280 if (id->capability & 2)
Rob Landleyade7f952006-05-25 18:53:06 +00001281 printf(", LBAsects=%u", id->lba_capacity);
1282
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001283 printf("\n IORDY=%s",
1284 (id->capability & 8)
1285 ? ((id->capability & 4) ? "on/off" : "yes")
1286 : "no");
Rob Landleyade7f952006-05-25 18:53:06 +00001287
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001288 if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2))
Rob Landleyade7f952006-05-25 18:53:06 +00001289 printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy);
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00001290
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001291 if ((id->capability & 1) && (id->field_valid & 2))
Rob Landleyade7f952006-05-25 18:53:06 +00001292 printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time);
1293
1294 printf("\n PIO modes: ");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001295 if (id->tPIO <= 5) {
Rob Landleyade7f952006-05-25 18:53:06 +00001296 printf("pio0 ");
1297 if (id->tPIO >= 1) printf("pio1 ");
1298 if (id->tPIO >= 2) printf("pio2 ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001299 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001300 if (id->field_valid & 2) {
Denis Vlasenko53354ac2008-06-07 15:10:29 +00001301 static const masks_labels_t pio_modes = {
1302 .masks = { 1, 2, ~3 },
1303 .labels = "pio3 \0""pio4 \0""pio? \0",
1304 };
1305 print_flags(&pio_modes, id->eide_pio_modes);
Rob Landleyade7f952006-05-25 18:53:06 +00001306 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001307 if (id->capability & 1) {
1308 if (id->dma_1word | id->dma_mword) {
Denis Vlasenko53354ac2008-06-07 15:10:29 +00001309 static const int dma_wmode_masks[] = { 0x100, 1, 0x200, 2, 0x400, 4, 0xf800, 0xf8 };
Rob Landleyade7f952006-05-25 18:53:06 +00001310 printf("\n DMA modes: ");
Denis Vlasenko53354ac2008-06-07 15:10:29 +00001311 print_flags_separated(dma_wmode_masks,
1312 "*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0",
1313 id->dma_1word, NULL);
1314 print_flags_separated(dma_wmode_masks,
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001315 "*\0""mdma0 \0""*\0""mdma1 \0""*\0""mdma2 \0""*\0""mdma? \0",
Denis Vlasenko53354ac2008-06-07 15:10:29 +00001316 id->dma_mword, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00001317 }
1318 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001319 if (((id->capability & 8) || (id->field_valid & 2)) && id->field_valid & 4) {
Denis Vlasenko53354ac2008-06-07 15:10:29 +00001320 static const masks_labels_t ultra_modes1 = {
1321 .masks = { 0x100, 0x001, 0x200, 0x002, 0x400, 0x004 },
1322 .labels = "*\0""udma0 \0""*\0""udma1 \0""*\0""udma2 \0",
1323 };
Denis Vlasenko7049ff82008-06-25 09:53:17 +00001324
Rob Landleyade7f952006-05-25 18:53:06 +00001325 printf("\n UDMA modes: ");
Denis Vlasenko53354ac2008-06-07 15:10:29 +00001326 print_flags(&ultra_modes1, id->dma_ultra);
Eric Andersen3443bd72003-07-22 07:30:36 +00001327#ifdef __NEW_HD_DRIVE_ID
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001328 if (id->hw_config & 0x2000) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001329#else /* !__NEW_HD_DRIVE_ID */
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001330 if (id->word93 & 0x2000) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001331#endif /* __NEW_HD_DRIVE_ID */
Denis Vlasenko53354ac2008-06-07 15:10:29 +00001332 static const masks_labels_t ultra_modes2 = {
1333 .masks = { 0x0800, 0x0008, 0x1000, 0x0010,
1334 0x2000, 0x0020, 0x4000, 0x0040,
1335 0x8000, 0x0080 },
1336 .labels = "*\0""udma3 \0""*\0""udma4 \0"
1337 "*\0""udma5 \0""*\0""udma6 \0"
1338 "*\0""udma7 \0"
1339 };
1340 print_flags(&ultra_modes2, id->dma_ultra);
Eric Andersen3443bd72003-07-22 07:30:36 +00001341 }
1342 }
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001343 printf("\n AdvancedPM=%s", (!(id_regs[83] & 8)) ? "no" : "yes");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001344 if (id_regs[83] & 8) {
1345 if (!(id_regs[86] & 8))
Glenn L McGrath07085852003-10-09 07:28:22 +00001346 printf(": disabled (255)");
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001347 else if ((id_regs[91] & 0xFF00) != 0x4000)
Glenn L McGrath07085852003-10-09 07:28:22 +00001348 printf(": unknown setting");
1349 else
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001350 printf(": mode=0x%02X (%u)", id_regs[91] & 0xFF, id_regs[91] & 0xFF);
Glenn L McGrath07085852003-10-09 07:28:22 +00001351 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001352 if (id_regs[82] & 0x20)
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001353 printf(" WriteCache=%s", (id_regs[85] & 0x20) ? "enabled" : "disabled");
Glenn L McGrath07085852003-10-09 07:28:22 +00001354#ifdef __NEW_HD_DRIVE_ID
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001355 if ((id->minor_rev_num && id->minor_rev_num <= 31)
1356 || (id->major_rev_num && id->minor_rev_num <= 31)
1357 ) {
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001358 printf("\n Drive conforms to: %s: ",
1359 (id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown");
1360 if (id->major_rev_num != 0x0000 /* NOVAL_0 */
1361 && id->major_rev_num != 0xFFFF /* NOVAL_1 */
1362 ) {
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001363 for (i = 0; i <= 15; i++) {
Rob Landleyadde7982006-05-16 15:32:30 +00001364 if (id->major_rev_num & (1<<i))
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001365 printf(" ATA/ATAPI-%u", i);
Rob Landleyadde7982006-05-16 15:32:30 +00001366 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001367 }
1368 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001369#endif /* __NEW_HD_DRIVE_ID */
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001370 puts("\n\n * current active mode\n");
Eric Andersen3443bd72003-07-22 07:30:36 +00001371}
1372#endif
1373
Denis Vlasenko892536f2007-09-27 10:23:34 +00001374static void flush_buffer_cache(/*int fd*/ void)
Eric Andersen3443bd72003-07-22 07:30:36 +00001375{
Rob Landleya3e4f382006-04-29 16:06:31 +00001376 fsync(fd); /* flush buffers */
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001377 ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */
Eric Andersen3443bd72003-07-22 07:30:36 +00001378#ifdef HDIO_DRIVE_CMD
Glenn L McGrath07085852003-10-09 07:28:22 +00001379 sleep(1);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001380 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) { /* await completion */
1381 if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
1382 bb_perror_msg("HDIO_DRIVE_CMD");
1383 else
1384 bb_perror_msg("ioctl %#x failed", HDIO_DRIVE_CMD);
1385 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001386#endif
1387}
1388
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001389static void seek_to_zero(/*int fd*/ void)
Eric Andersen3443bd72003-07-22 07:30:36 +00001390{
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001391 xlseek(fd, (off_t) 0, SEEK_SET);
Eric Andersen3443bd72003-07-22 07:30:36 +00001392}
1393
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001394static void read_big_block(/*int fd,*/ char *buf)
Eric Andersen3443bd72003-07-22 07:30:36 +00001395{
Rob Landleyadde7982006-05-16 15:32:30 +00001396 int i;
1397
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001398 xread(fd, buf, TIMING_BUF_BYTES);
Eric Andersen3443bd72003-07-22 07:30:36 +00001399 /* access all sectors of buf to ensure the read fully completed */
1400 for (i = 0; i < TIMING_BUF_BYTES; i += 512)
1401 buf[i] &= 1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001402}
1403
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001404static unsigned dev_size_mb(/*int fd*/ void)
Rob Landleyadde7982006-05-16 15:32:30 +00001405{
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001406 union {
1407 unsigned long long blksize64;
1408 unsigned blksize32;
1409 } u;
Rob Landleyadde7982006-05-16 15:32:30 +00001410
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001411 if (0 == ioctl(fd, BLKGETSIZE64, &u.blksize64)) { // bytes
1412 u.blksize64 /= (1024 * 1024);
1413 } else {
1414 xioctl(fd, BLKGETSIZE, &u.blksize32); // sectors
1415 u.blksize64 = u.blksize32 / (2 * 1024);
Rob Landleyadde7982006-05-16 15:32:30 +00001416 }
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001417 if (u.blksize64 > UINT_MAX)
1418 return UINT_MAX;
1419 return u.blksize64;
Rob Landleyadde7982006-05-16 15:32:30 +00001420}
Eric Andersen50af12d2003-08-06 08:47:59 +00001421
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001422static void print_timing(unsigned m, unsigned elapsed_us)
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001423{
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001424 unsigned sec = elapsed_us / 1000000;
1425 unsigned hs = (elapsed_us % 1000000) / 10000;
1426
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001427 printf("%5u MB in %u.%02u seconds = %u kB/s\n",
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001428 m, sec, hs,
Denis Vlasenko0afdfdf2007-09-28 13:41:41 +00001429 /* "| 1" prevents div-by-0 */
1430 (unsigned) ((unsigned long long)m * (1024 * 1000000) / (elapsed_us | 1))
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001431 // ~= (m * 1024) / (elapsed_us / 1000000)
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001432 // = kb / elapsed_sec
1433 );
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001434}
1435
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001436static void do_time(int cache /*,int fd*/)
1437/* cache=1: time cache: repeatedly read N MB at offset 0
1438 * cache=0: time device: linear read, starting at offset 0
1439 */
Eric Andersen3443bd72003-07-22 07:30:36 +00001440{
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001441 unsigned max_iterations, iterations;
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001442 unsigned start; /* doesn't need to be long long */
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001443 unsigned elapsed, elapsed2;
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001444 unsigned total_MB;
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001445 char *buf = xmalloc(TIMING_BUF_BYTES);
Rob Landley4ae2f512006-05-19 17:24:26 +00001446
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001447 if (mlock(buf, TIMING_BUF_BYTES))
1448 bb_perror_msg_and_die("mlock");
Rob Landleyadde7982006-05-16 15:32:30 +00001449
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001450 /* Clear out the device request queues & give them time to complete.
1451 * NB: *small* delay. User is expected to have a clue and to not run
1452 * heavy io in parallel with measurements. */
Rob Landleyadde7982006-05-16 15:32:30 +00001453 sync();
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001454 sleep(1);
1455 if (cache) { /* Time cache */
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001456 seek_to_zero();
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001457 read_big_block(buf);
1458 printf("Timing buffer-cache reads: ");
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001459 } else { /* Time device */
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001460 printf("Timing buffered disk reads:");
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001461 }
Denys Vlasenko8131eea2009-11-02 14:19:51 +01001462 fflush_all();
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001463
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001464 /* Now do the timing */
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001465 iterations = 0;
Denis Vlasenkoa7bc9ac2007-09-28 11:21:47 +00001466 /* Max time to run (small for cache, avoids getting
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001467 * huge total_MB which can overlow unsigned type) */
Denis Vlasenkoa7bc9ac2007-09-28 11:21:47 +00001468 elapsed2 = 510000; /* cache */
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001469 max_iterations = UINT_MAX;
1470 if (!cache) {
Denis Vlasenkoa7bc9ac2007-09-28 11:21:47 +00001471 elapsed2 = 3000000; /* not cache */
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001472 /* Don't want to read past the end! */
1473 max_iterations = dev_size_mb() / TIMING_BUF_MB;
1474 }
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001475 start = monotonic_us();
Denis Vlasenko6963eb52007-05-22 21:46:11 +00001476 do {
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001477 if (cache)
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001478 seek_to_zero();
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001479 read_big_block(buf);
1480 elapsed = (unsigned)monotonic_us() - start;
1481 ++iterations;
Denis Vlasenkoa7bc9ac2007-09-28 11:21:47 +00001482 } while (elapsed < elapsed2 && iterations < max_iterations);
Denis Vlasenko920c52a2007-09-28 13:38:08 +00001483 total_MB = iterations * TIMING_BUF_MB;
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001484 //printf(" elapsed:%u iterations:%u ", elapsed, iterations);
1485 if (cache) {
Denis Vlasenkoa7bc9ac2007-09-28 11:21:47 +00001486 /* Cache: remove lseek() and monotonic_us() overheads
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001487 * from elapsed */
1488 start = monotonic_us();
Rob Landleyadde7982006-05-16 15:32:30 +00001489 do {
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001490 seek_to_zero();
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001491 elapsed2 = (unsigned)monotonic_us() - start;
Rob Landleyadde7982006-05-16 15:32:30 +00001492 } while (--iterations);
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001493 //printf(" elapsed2:%u ", elapsed2);
Rob Landleyadde7982006-05-16 15:32:30 +00001494 elapsed -= elapsed2;
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001495 total_MB *= 2; // BUFCACHE_FACTOR (why?)
Denis Vlasenko892536f2007-09-27 10:23:34 +00001496 flush_buffer_cache();
Glenn L McGrath07085852003-10-09 07:28:22 +00001497 }
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001498 print_timing(total_MB, elapsed);
Rob Landley4ae2f512006-05-19 17:24:26 +00001499 munlock(buf, TIMING_BUF_BYTES);
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001500 free(buf);
Eric Andersen3443bd72003-07-22 07:30:36 +00001501}
1502
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001503#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001504static void bus_state_value(unsigned value)
Eric Andersen3443bd72003-07-22 07:30:36 +00001505{
Rob Landleyadde7982006-05-16 15:32:30 +00001506 if (value == BUSSTATE_ON)
1507 on_off(1);
1508 else if (value == BUSSTATE_OFF)
1509 on_off(0);
1510 else if (value == BUSSTATE_TRISTATE)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001511 puts(" (tristate)");
Rob Landleyadde7982006-05-16 15:32:30 +00001512 else
Denys Vlasenko327f5502013-11-29 16:45:45 +01001513 printf(" (unknown: %u)\n", value);
Eric Andersen3443bd72003-07-22 07:30:36 +00001514}
1515#endif
1516
1517#ifdef HDIO_DRIVE_CMD
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001518static void interpret_standby(uint8_t standby)
Eric Andersen3443bd72003-07-22 07:30:36 +00001519{
Rob Landley403777f2006-08-03 20:22:37 +00001520 printf(" (");
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001521 if (standby == 0) {
Rob Landleyadde7982006-05-16 15:32:30 +00001522 printf("off");
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001523 } else if (standby <= 240 || standby == 252 || standby == 255) {
1524 /* standby is in 5 sec units */
Denys Vlasenko2b132e52009-05-20 23:21:42 +02001525 unsigned t = standby * 5;
1526 printf("%u minutes %u seconds", t / 60, t % 60);
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001527 } else if (standby <= 251) {
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001528 unsigned t = (standby - 240); /* t is in 30 min units */;
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001529 printf("%u.%c hours", t / 2, (t & 1) ? '5' : '0');
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001530 }
1531 if (standby == 253)
1532 printf("vendor-specific");
1533 if (standby == 254)
1534 printf("reserved");
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001535 puts(")");
Eric Andersen3443bd72003-07-22 07:30:36 +00001536}
1537
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001538static const uint8_t xfermode_val[] ALIGN1 = {
1539 8, 9, 10, 11, 12, 13, 14, 15,
1540 16, 17, 18, 19, 20, 21, 22, 23,
1541 32, 33, 34, 35, 36, 37, 38, 39,
1542 64, 65, 66, 67, 68, 69, 70, 71
1543};
1544/* NB: we save size by _not_ storing terninating NUL! */
1545static const char xfermode_name[][5] ALIGN1 = {
1546 "pio0", "pio1", "pio2", "pio3", "pio4", "pio5", "pio6", "pio7",
1547 "sdma0","sdma1","sdma2","sdma3","sdma4","sdma5","sdma6","sdma7",
1548 "mdma0","mdma1","mdma2","mdma3","mdma4","mdma5","mdma6","mdma7",
1549 "udma0","udma1","udma2","udma3","udma4","udma5","udma6","udma7"
Eric Andersen3443bd72003-07-22 07:30:36 +00001550};
1551
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001552static int translate_xfermode(const char *name)
Eric Andersen3443bd72003-07-22 07:30:36 +00001553{
Denis Vlasenko6b06cb82008-05-15 21:30:45 +00001554 int val;
1555 unsigned i;
Eric Andersen3443bd72003-07-22 07:30:36 +00001556
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001557 for (i = 0; i < ARRAY_SIZE(xfermode_val); i++) {
1558 if (!strncmp(name, xfermode_name[i], 5))
1559 if (strlen(name) <= 5)
1560 return xfermode_val[i];
Glenn L McGrath07085852003-10-09 07:28:22 +00001561 }
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001562 /* Negative numbers are invalid and are caught later */
1563 val = bb_strtoi(name, NULL, 10);
1564 if (!errno)
Glenn L McGrath07085852003-10-09 07:28:22 +00001565 return val;
Glenn L McGrath07085852003-10-09 07:28:22 +00001566 return -1;
Eric Andersen3443bd72003-07-22 07:30:36 +00001567}
1568
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001569static void interpret_xfermode(unsigned xfermode)
Eric Andersen3443bd72003-07-22 07:30:36 +00001570{
1571 printf(" (");
Rob Landleyadde7982006-05-16 15:32:30 +00001572 if (xfermode == 0)
1573 printf("default PIO mode");
1574 else if (xfermode == 1)
1575 printf("default PIO mode, disable IORDY");
1576 else if (xfermode >= 8 && xfermode <= 15)
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001577 printf("PIO flow control mode%u", xfermode - 8);
Rob Landleyadde7982006-05-16 15:32:30 +00001578 else if (xfermode >= 16 && xfermode <= 23)
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001579 printf("singleword DMA mode%u", xfermode - 16);
Rob Landleyadde7982006-05-16 15:32:30 +00001580 else if (xfermode >= 32 && xfermode <= 39)
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001581 printf("multiword DMA mode%u", xfermode - 32);
Rob Landleyadde7982006-05-16 15:32:30 +00001582 else if (xfermode >= 64 && xfermode <= 71)
Denis Vlasenkoa0319ba2007-08-16 10:37:49 +00001583 printf("UltraDMA mode%u", xfermode - 64);
Rob Landleyadde7982006-05-16 15:32:30 +00001584 else
Denis Vlasenko91303402007-10-30 19:36:54 +00001585 printf("unknown");
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001586 puts(")");
Eric Andersen3443bd72003-07-22 07:30:36 +00001587}
1588#endif /* HDIO_DRIVE_CMD */
1589
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001590static void print_flag(int flag, const char *s, unsigned long value)
Rob Landleyadde7982006-05-16 15:32:30 +00001591{
Denis Vlasenko67b23e62006-10-03 21:00:06 +00001592 if (flag)
Denys Vlasenko327f5502013-11-29 16:45:45 +01001593 printf(" setting %s to %lu\n", s, value);
Rob Landleyadde7982006-05-16 15:32:30 +00001594}
1595
Rob Landleya3e4f382006-04-29 16:06:31 +00001596static void process_dev(char *devname)
Eric Andersen3443bd72003-07-22 07:30:36 +00001597{
Denis Vlasenko892536f2007-09-27 10:23:34 +00001598 /*int fd;*/
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001599 long parm, multcount;
Eric Andersen3443bd72003-07-22 07:30:36 +00001600#ifndef HDIO_DRIVE_CMD
1601 int force_operation = 0;
1602#endif
Rob Landley39cf6452006-05-05 16:52:28 +00001603 /* Please restore args[n] to these values after each ioctl
1604 except for args[2] */
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00001605 unsigned char args[4] = { WIN_SETFEATURES, 0, 0, 0 };
Rob Landleyadde7982006-05-16 15:32:30 +00001606 const char *fmt = " %s\t= %2ld";
Rob Landleye5b281f2006-04-29 15:49:18 +00001607
Bernhard Reutner-Fischera4830872009-10-26 23:27:08 +01001608 /*fd = xopen_nonblocking(devname);*/
1609 xmove_fd(xopen_nonblocking(devname), fd);
Rob Landleyade7f952006-05-25 18:53:06 +00001610 printf("\n%s:\n", devname);
Eric Andersen3443bd72003-07-22 07:30:36 +00001611
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001612 if (getset_readahead == IS_SET) {
1613 print_flag(getset_readahead, "fs readahead", Xreadahead);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001614 ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead);
Eric Andersen3443bd72003-07-22 07:30:36 +00001615 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001616#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
1617 if (unregister_hwif) {
Rob Landley20deab02006-05-07 23:34:15 +00001618 printf(" attempting to unregister hwif#%lu\n", hwif);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001619 ioctl_or_warn(fd, HDIO_UNREGISTER_HWIF, (int *)(unsigned long)hwif);
Eric Andersen3443bd72003-07-22 07:30:36 +00001620 }
1621#endif
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001622#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001623 if (scan_hwif == IS_SET) {
Rob Landley20deab02006-05-07 23:34:15 +00001624 printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq);
Eric Andersen3443bd72003-07-22 07:30:36 +00001625 args[0] = hwif_data;
1626 args[1] = hwif_ctrl;
1627 args[2] = hwif_irq;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001628 ioctl_or_warn(fd, HDIO_SCAN_HWIF, args);
Rob Landley39cf6452006-05-05 16:52:28 +00001629 args[0] = WIN_SETFEATURES;
1630 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001631 }
1632#endif
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001633 if (set_piomode) {
1634 if (noisy_piomode) {
Glenn L McGrath07085852003-10-09 07:28:22 +00001635 printf(" attempting to ");
Eric Andersen3443bd72003-07-22 07:30:36 +00001636 if (piomode == 255)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001637 puts("auto-tune PIO mode");
Eric Andersen3443bd72003-07-22 07:30:36 +00001638 else if (piomode < 100)
Glenn L McGrath07085852003-10-09 07:28:22 +00001639 printf("set PIO mode to %d\n", piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001640 else if (piomode < 200)
Glenn L McGrath07085852003-10-09 07:28:22 +00001641 printf("set MDMA mode to %d\n", (piomode-100));
Eric Andersen3443bd72003-07-22 07:30:36 +00001642 else
Glenn L McGrath07085852003-10-09 07:28:22 +00001643 printf("set UDMA mode to %d\n", (piomode-200));
Eric Andersen3443bd72003-07-22 07:30:36 +00001644 }
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001645 ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode);
Eric Andersen3443bd72003-07-22 07:30:36 +00001646 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001647 if (getset_io32bit == IS_SET) {
1648 print_flag(getset_io32bit, "32-bit IO_support flag", io32bit);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001649 ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit);
Eric Andersen3443bd72003-07-22 07:30:36 +00001650 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001651 if (getset_mult == IS_SET) {
1652 print_flag(getset_mult, "multcount", mult);
Rob Landleyade7f952006-05-25 18:53:06 +00001653#ifdef HDIO_DRIVE_CMD
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001654 ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult);
Rob Landleyade7f952006-05-25 18:53:06 +00001655#else
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001656 force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult));
Eric Andersen3443bd72003-07-22 07:30:36 +00001657#endif
1658 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001659 if (getset_readonly == IS_SET) {
1660 print_flag_on_off(getset_readonly, "readonly", readonly);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001661 ioctl_or_warn(fd, BLKROSET, &readonly);
Eric Andersen3443bd72003-07-22 07:30:36 +00001662 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001663 if (getset_unmask == IS_SET) {
1664 print_flag_on_off(getset_unmask, "unmaskirq", unmask);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001665 ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask);
Eric Andersen3443bd72003-07-22 07:30:36 +00001666 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001667#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001668 if (getset_dma == IS_SET) {
1669 print_flag_on_off(getset_dma, "using_dma", dma);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001670 ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma);
Eric Andersen3443bd72003-07-22 07:30:36 +00001671 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001672#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001673#ifdef HDIO_SET_QDMA
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001674 if (getset_dma_q == IS_SET) {
1675 print_flag_on_off(getset_dma_q, "DMA queue_depth", dma_q);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001676 ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q);
Eric Andersen3443bd72003-07-22 07:30:36 +00001677 }
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001678#endif
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001679 if (getset_nowerr == IS_SET) {
1680 print_flag_on_off(getset_nowerr, "nowerr", nowerr);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001681 ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr);
Eric Andersen3443bd72003-07-22 07:30:36 +00001682 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001683 if (getset_keep == IS_SET) {
1684 print_flag_on_off(getset_keep, "keep_settings", keep);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001685 ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep);
Eric Andersen3443bd72003-07-22 07:30:36 +00001686 }
1687#ifdef HDIO_DRIVE_CMD
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001688 if (getset_doorlock == IS_SET) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001689 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
Rob Landley39cf6452006-05-05 16:52:28 +00001690 args[2] = 0;
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001691 print_flag_on_off(getset_doorlock, "drive doorlock", doorlock);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001692 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Rob Landley39cf6452006-05-05 16:52:28 +00001693 args[0] = WIN_SETFEATURES;
Eric Andersen3443bd72003-07-22 07:30:36 +00001694 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001695 if (getset_dkeep == IS_SET) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001696 /* lock/unlock the drive's "feature" settings */
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001697 print_flag_on_off(getset_dkeep, "drive keep features", dkeep);
Eric Andersen3443bd72003-07-22 07:30:36 +00001698 args[2] = dkeep ? 0x66 : 0xcc;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001699 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Eric Andersen3443bd72003-07-22 07:30:36 +00001700 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001701 if (getset_defects == IS_SET) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001702 args[2] = defects ? 0x04 : 0x84;
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001703 print_flag(getset_defects, "drive defect-mgmt", defects);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001704 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Eric Andersen3443bd72003-07-22 07:30:36 +00001705 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001706 if (getset_prefetch == IS_SET) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001707 args[1] = prefetch;
Rob Landleye5b281f2006-04-29 15:49:18 +00001708 args[2] = 0xab;
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001709 print_flag(getset_prefetch, "drive prefetch", prefetch);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001710 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Rob Landley39cf6452006-05-05 16:52:28 +00001711 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001712 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001713 if (set_xfermode) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001714 args[1] = xfermode_requested;
Rob Landleye5b281f2006-04-29 15:49:18 +00001715 args[2] = 3;
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001716 print_flag(1, "xfermode", xfermode_requested);
1717 interpret_xfermode(xfermode_requested);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001718 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Rob Landley39cf6452006-05-05 16:52:28 +00001719 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001720 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001721 if (getset_lookahead == IS_SET) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001722 args[2] = lookahead ? 0xaa : 0x55;
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001723 print_flag_on_off(getset_lookahead, "drive read-lookahead", lookahead);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001724 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Eric Andersen3443bd72003-07-22 07:30:36 +00001725 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001726 if (getset_apmmode == IS_SET) {
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001727 /* feature register */
1728 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */;
Rob Landleyadde7982006-05-16 15:32:30 +00001729 args[1] = apmmode; /* sector count register 1-255 */
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001730 printf(" setting APM level to %s 0x%02lX (%ld)\n",
1731 (apmmode == 255) ? "disabled" : "",
1732 apmmode, apmmode);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001733 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Rob Landley39cf6452006-05-05 16:52:28 +00001734 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001735 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001736 if (getset_wcache == IS_SET) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001737#ifdef DO_FLUSHCACHE
1738#ifndef WIN_FLUSHCACHE
1739#define WIN_FLUSHCACHE 0xe7
1740#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00001741#endif /* DO_FLUSHCACHE */
Eric Andersen3443bd72003-07-22 07:30:36 +00001742 args[2] = wcache ? 0x02 : 0x82;
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001743 print_flag_on_off(getset_wcache, "drive write-caching", wcache);
Eric Andersen3443bd72003-07-22 07:30:36 +00001744#ifdef DO_FLUSHCACHE
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001745 if (!wcache)
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001746 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache);
Eric Andersen3443bd72003-07-22 07:30:36 +00001747#endif /* DO_FLUSHCACHE */
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001748 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Eric Andersen3443bd72003-07-22 07:30:36 +00001749#ifdef DO_FLUSHCACHE
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001750 if (!wcache)
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001751 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache);
Eric Andersen3443bd72003-07-22 07:30:36 +00001752#endif /* DO_FLUSHCACHE */
1753 }
Rob Landley39cf6452006-05-05 16:52:28 +00001754
1755 /* In code below, we do not preserve args[0], but the rest
1756 is preserved, including args[2] */
1757 args[2] = 0;
1758
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001759 if (set_standbynow) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001760#ifndef WIN_STANDBYNOW1
1761#define WIN_STANDBYNOW1 0xE0
1762#endif
1763#ifndef WIN_STANDBYNOW2
1764#define WIN_STANDBYNOW2 0x94
1765#endif
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001766 puts(" issuing standby command");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001767 args[0] = WIN_STANDBYNOW1;
Denis Vlasenko892536f2007-09-27 10:23:34 +00001768 ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2);
Eric Andersen3443bd72003-07-22 07:30:36 +00001769 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001770 if (set_sleepnow) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001771#ifndef WIN_SLEEPNOW1
1772#define WIN_SLEEPNOW1 0xE6
1773#endif
1774#ifndef WIN_SLEEPNOW2
1775#define WIN_SLEEPNOW2 0x99
1776#endif
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001777 puts(" issuing sleep command");
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001778 args[0] = WIN_SLEEPNOW1;
Denis Vlasenko892536f2007-09-27 10:23:34 +00001779 ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2);
Eric Andersen3443bd72003-07-22 07:30:36 +00001780 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001781 if (set_seagate) {
Rob Landleye5b281f2006-04-29 15:49:18 +00001782 args[0] = 0xfb;
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001783 puts(" disabling Seagate auto powersaving mode");
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001784 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Eric Andersen3443bd72003-07-22 07:30:36 +00001785 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001786 if (getset_standby == IS_SET) {
Rob Landleye5b281f2006-04-29 15:49:18 +00001787 args[0] = WIN_SETIDLE1;
1788 args[1] = standby_requested;
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001789 print_flag(1, "standby", standby_requested);
1790 interpret_standby(standby_requested);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001791 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
Rob Landley39cf6452006-05-05 16:52:28 +00001792 args[1] = 0;
Eric Andersen3443bd72003-07-22 07:30:36 +00001793 }
1794#else /* HDIO_DRIVE_CMD */
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001795 if (force_operation) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001796 char buf[512];
Denis Vlasenko892536f2007-09-27 10:23:34 +00001797 flush_buffer_cache();
Eric Andersen3443bd72003-07-22 07:30:36 +00001798 if (-1 == read(fd, buf, sizeof(buf)))
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001799 bb_perror_msg("read of 512 bytes failed");
Eric Andersen3443bd72003-07-22 07:30:36 +00001800 }
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +02001801#endif /* HDIO_DRIVE_CMD */
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001802 if (getset_mult || get_identity) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001803 multcount = -1;
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001804 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) {
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001805 /* To be coherent with ioctl_or_warn. */
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001806 if (getset_mult && ENABLE_IOCTL_HEX2STR_ERROR)
Eric Andersen06d4ec22004-03-19 10:53:52 +00001807 bb_perror_msg("HDIO_GET_MULTCOUNT");
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001808 else
1809 bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT);
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001810 } else if (getset_mult) {
Rob Landleyadde7982006-05-16 15:32:30 +00001811 printf(fmt, "multcount", multcount);
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001812 on_off(multcount != 0);
Eric Andersen3443bd72003-07-22 07:30:36 +00001813 }
1814 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001815 if (getset_io32bit) {
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001816 if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) {
Rob Landleyadde7982006-05-16 15:32:30 +00001817 printf(" IO_support\t=%3ld (", parm);
1818 if (parm == 0)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001819 puts("default 16-bit)");
Rob Landleyadde7982006-05-16 15:32:30 +00001820 else if (parm == 2)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001821 puts("16-bit)");
Rob Landleyadde7982006-05-16 15:32:30 +00001822 else if (parm == 1)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001823 puts("32-bit)");
Rob Landleyadde7982006-05-16 15:32:30 +00001824 else if (parm == 3)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001825 puts("32-bit w/sync)");
Rob Landleyadde7982006-05-16 15:32:30 +00001826 else if (parm == 8)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001827 puts("Request-Queue-Bypass)");
Rob Landleyadde7982006-05-16 15:32:30 +00001828 else
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001829 puts("\?\?\?)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001830 }
1831 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001832 if (getset_unmask) {
Denis Vlasenkod6855d12008-09-27 14:03:25 +00001833 if (!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm))
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001834 print_value_on_off("unmaskirq", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001835 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001836#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001837 if (getset_dma) {
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001838 if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) {
Rob Landleyadde7982006-05-16 15:32:30 +00001839 printf(fmt, "using_dma", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001840 if (parm == 8)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001841 puts(" (DMA-Assisted-PIO)");
Eric Andersen3443bd72003-07-22 07:30:36 +00001842 else
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001843 on_off(parm != 0);
Eric Andersen3443bd72003-07-22 07:30:36 +00001844 }
1845 }
1846#endif
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001847#ifdef HDIO_GET_QDMA
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001848 if (getset_dma_q) {
Denis Vlasenkod6855d12008-09-27 14:03:25 +00001849 if (!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm))
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001850 print_value_on_off("queue_depth", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001851 }
Denis Vlasenko3c96d022008-03-20 13:44:50 +00001852#endif
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001853 if (getset_keep) {
Denis Vlasenkod6855d12008-09-27 14:03:25 +00001854 if (!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm))
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001855 print_value_on_off("keepsettings", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001856 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001857 if (getset_nowerr) {
Denis Vlasenkod6855d12008-09-27 14:03:25 +00001858 if (!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm))
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001859 print_value_on_off("nowerr", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001860 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001861 if (getset_readonly) {
Denis Vlasenkod6855d12008-09-27 14:03:25 +00001862 if (!ioctl_or_warn(fd, BLKROGET, &parm))
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001863 print_value_on_off("readonly", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001864 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001865 if (getset_readahead) {
Denis Vlasenkod6855d12008-09-27 14:03:25 +00001866 if (!ioctl_or_warn(fd, BLKRAGET, &parm))
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001867 print_value_on_off("readahead", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001868 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001869 if (get_geom) {
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001870 if (!ioctl_or_warn(fd, BLKGETSIZE, &parm)) {
Rob Landley2584e9b2006-05-03 20:00:00 +00001871 struct hd_geometry g;
1872
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001873 if (!ioctl_or_warn(fd, HDIO_GETGEO, &g))
Rob Landleyadde7982006-05-16 15:32:30 +00001874 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n",
Denys Vlasenko6d335be2009-05-20 14:48:03 +02001875 g.cylinders, g.heads, g.sectors, parm, g.start);
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001876 }
Eric Andersen3443bd72003-07-22 07:30:36 +00001877 }
1878#ifdef HDIO_DRIVE_CMD
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001879 if (get_powermode) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001880#ifndef WIN_CHECKPOWERMODE1
1881#define WIN_CHECKPOWERMODE1 0xE5
1882#endif
1883#ifndef WIN_CHECKPOWERMODE2
1884#define WIN_CHECKPOWERMODE2 0x98
1885#endif
Eric Andersen3443bd72003-07-22 07:30:36 +00001886 const char *state;
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001887
Rob Landleye5b281f2006-04-29 15:49:18 +00001888 args[0] = WIN_CHECKPOWERMODE1;
Denis Vlasenko892536f2007-09-27 10:23:34 +00001889 if (ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2)) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001890 if (errno != EIO || args[0] != 0 || args[1] != 0)
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00001891 state = "unknown";
Eric Andersen3443bd72003-07-22 07:30:36 +00001892 else
1893 state = "sleeping";
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001894 } else
Glenn L McGrath07085852003-10-09 07:28:22 +00001895 state = (args[2] == 255) ? "active/idle" : "standby";
Rob Landley39cf6452006-05-05 16:52:28 +00001896 args[1] = args[2] = 0;
Glenn L McGrath07085852003-10-09 07:28:22 +00001897
Eric Andersen3443bd72003-07-22 07:30:36 +00001898 printf(" drive state is: %s\n", state);
1899 }
1900#endif
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001901#if ENABLE_FEATURE_HDPARM_HDIO_DRIVE_RESET
1902 if (perform_reset) {
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001903 ioctl_or_warn(fd, HDIO_DRIVE_RESET, NULL);
Eric Andersen3443bd72003-07-22 07:30:36 +00001904 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001905#endif /* FEATURE_HDPARM_HDIO_DRIVE_RESET */
1906#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
1907 if (perform_tristate) {
Rob Landleye5b281f2006-04-29 15:49:18 +00001908 args[0] = 0;
1909 args[1] = tristate;
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001910 ioctl_or_warn(fd, HDIO_TRISTATE_HWIF, &args);
Eric Andersen3443bd72003-07-22 07:30:36 +00001911 }
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001912#endif /* FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
1913#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
1914 if (get_identity) {
Denis Vlasenko7c282a22007-03-28 00:14:54 +00001915 struct hd_driveid id;
Eric Andersen3443bd72003-07-22 07:30:36 +00001916
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001917 if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) {
1918 if (multcount != -1) {
Eric Andersen3443bd72003-07-22 07:30:36 +00001919 id.multsect = multcount;
1920 id.multsect_valid |= 1;
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001921 } else
Eric Andersen3443bd72003-07-22 07:30:36 +00001922 id.multsect_valid &= ~1;
1923 dump_identity(&id);
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001924 } else if (errno == -ENOMSG)
Denys Vlasenkod60752f2015-10-07 22:42:45 +02001925 puts(" no identification info available");
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001926 else if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
Denis Vlasenko49a128a2007-07-17 21:42:59 +00001927 bb_perror_msg("HDIO_GET_IDENTITY");
Eric Andersen3443bd72003-07-22 07:30:36 +00001928 else
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001929 bb_perror_msg("ioctl %#x failed", HDIO_GET_IDENTITY);
Eric Andersen3443bd72003-07-22 07:30:36 +00001930 }
Glenn L McGrath07085852003-10-09 07:28:22 +00001931
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001932 if (get_IDentity) {
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001933 unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */
Glenn L McGrath07085852003-10-09 07:28:22 +00001934
Rob Landley5f8b5ec2006-04-29 16:03:40 +00001935 memset(args1, 0, sizeof(args1));
1936 args1[0] = WIN_IDENTIFY;
1937 args1[3] = 1;
Denis Vlasenko892536f2007-09-27 10:23:34 +00001938 if (!ioctl_alt_or_warn(HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY))
Rob Landley0753f4a2006-06-07 00:27:25 +00001939 identify((void *)(args1 + 4));
Eric Andersen3443bd72003-07-22 07:30:36 +00001940 }
1941#endif
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001942#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001943 if (getset_busstate == IS_SET) {
1944 print_flag(1, "bus state", busstate);
1945 bus_state_value(busstate);
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001946 ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate);
Eric Andersen3443bd72003-07-22 07:30:36 +00001947 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02001948 if (getset_busstate) {
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001949 if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) {
Rob Landleyadde7982006-05-16 15:32:30 +00001950 printf(fmt, "bus state", parm);
Eric Andersen3443bd72003-07-22 07:30:36 +00001951 bus_state_value(parm);
1952 }
1953 }
1954#endif
Glenn L McGrath07085852003-10-09 07:28:22 +00001955 if (reread_partn)
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +00001956 ioctl_or_warn(fd, BLKRRPART, NULL);
Glenn L McGrath07085852003-10-09 07:28:22 +00001957
Eric Andersen3443bd72003-07-22 07:30:36 +00001958 if (do_ctimings)
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001959 do_time(1 /*,fd*/); /* time cache */
Eric Andersen3443bd72003-07-22 07:30:36 +00001960 if (do_timings)
Denis Vlasenkoc3122bc2007-09-28 10:28:03 +00001961 do_time(0 /*,fd*/); /* time device */
Eric Andersen3443bd72003-07-22 07:30:36 +00001962 if (do_flush)
Denis Vlasenko892536f2007-09-27 10:23:34 +00001963 flush_buffer_cache();
Rob Landleya3e4f382006-04-29 16:06:31 +00001964 close(fd);
Eric Andersen3443bd72003-07-22 07:30:36 +00001965}
1966
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001967#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
Rob Landleya3e4f382006-04-29 16:06:31 +00001968static int fromhex(unsigned char c)
Eric Andersen3443bd72003-07-22 07:30:36 +00001969{
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00001970 if (isdigit(c))
Eric Andersen3443bd72003-07-22 07:30:36 +00001971 return (c - '0');
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00001972 if (c >= 'a' && c <= 'f')
1973 return (c - ('a' - 10));
Eric Andersen3443bd72003-07-22 07:30:36 +00001974 bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c);
1975}
1976
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +00001977static void identify_from_stdin(void) NORETURN;
Rob Landley0f0b6452006-05-03 18:28:06 +00001978static void identify_from_stdin(void)
Eric Andersen3443bd72003-07-22 07:30:36 +00001979{
Rob Landley0753f4a2006-06-07 00:27:25 +00001980 uint16_t sbuf[256];
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00001981 unsigned char buf[1280];
1982 unsigned char *b = (unsigned char *)buf;
1983 int i;
Eric Andersen3443bd72003-07-22 07:30:36 +00001984
Bernhard Reutner-Fischer5e25ddb2008-05-19 09:48:17 +00001985 xread(STDIN_FILENO, buf, 1280);
Rob Landleyade7f952006-05-25 18:53:06 +00001986
Rob Landley0753f4a2006-06-07 00:27:25 +00001987 // Convert the newline-separated hex data into an identify block.
1988
Denis Vlasenko3bf00202007-02-18 13:36:04 +00001989 for (i = 0; i < 256; i++) {
Rob Landley0753f4a2006-06-07 00:27:25 +00001990 int j;
Denis Vlasenkobf0a2012006-12-26 10:42:51 +00001991 for (j = 0; j < 4; j++)
Denis Vlasenko3a34d0c2007-01-12 22:10:34 +00001992 sbuf[i] = (sbuf[i] << 4) + fromhex(*(b++));
Eric Andersen3443bd72003-07-22 07:30:36 +00001993 }
Rob Landley0753f4a2006-06-07 00:27:25 +00001994
1995 // Parse the data.
1996
Rob Landley6389ff12006-05-01 19:28:53 +00001997 identify(sbuf);
Eric Andersen3443bd72003-07-22 07:30:36 +00001998}
Denis Vlasenko0d3c6af2007-09-28 10:25:32 +00001999#else
2000void identify_from_stdin(void);
Eric Andersen3443bd72003-07-22 07:30:36 +00002001#endif
2002
Rob Landley20deab02006-05-07 23:34:15 +00002003/* busybox specific stuff */
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002004static int parse_opts(unsigned long *value, int min, int max)
Eric Andersenb2aa7762004-04-05 13:08:08 +00002005{
Denis Vlasenko6429aab2006-09-23 12:22:11 +00002006 if (optarg) {
Denis Vlasenko13858992006-10-08 12:49:22 +00002007 *value = xatol_range(optarg, min, max);
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002008 return IS_SET;
Denis Vlasenko6429aab2006-09-23 12:22:11 +00002009 }
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002010 return IS_GET;
2011}
2012static int parse_opts_0_max(unsigned long *value, int max)
2013{
2014 return parse_opts(value, 0, max);
2015}
2016static int parse_opts_0_1(unsigned long *value)
2017{
2018 return parse_opts(value, 0, 1);
2019}
2020static int parse_opts_0_INTMAX(unsigned long *value)
2021{
2022 return parse_opts(value, 0, INT_MAX);
Rob Landley20deab02006-05-07 23:34:15 +00002023}
2024
Denis Vlasenko0eec4ab2007-03-28 01:00:45 +00002025static void parse_xfermode(int flag, smallint *get, smallint *set, int *value)
Rob Landley20deab02006-05-07 23:34:15 +00002026{
2027 if (flag) {
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002028 *get = IS_GET;
Rob Landley20deab02006-05-07 23:34:15 +00002029 if (optarg) {
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00002030 *value = translate_xfermode(optarg);
2031 *set = (*value > -1);
Rob Landley20deab02006-05-07 23:34:15 +00002032 }
2033 }
2034}
2035
Rob Landley06208412006-05-31 22:52:57 +00002036/*------- getopt short options --------*/
Denis Vlasenko6ca409e2007-08-12 20:58:27 +00002037static const char hdparm_options[] ALIGN1 =
Denis Vlasenko4daad902007-09-27 10:20:47 +00002038 "gfu::n::p:r::m::c::k::a::B:tT"
Denis Vlasenko5e34ff22009-04-21 11:09:40 +00002039 IF_FEATURE_HDPARM_GET_IDENTITY("iI")
2040 IF_FEATURE_HDPARM_HDIO_GETSET_DMA("d::")
Rob Landley20deab02006-05-07 23:34:15 +00002041#ifdef HDIO_DRIVE_CMD
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002042 "S:D:P:X:K:A:L:W:CyYzZ"
Rob Landley20deab02006-05-07 23:34:15 +00002043#endif
Denis Vlasenko5e34ff22009-04-21 11:09:40 +00002044 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:")
Rob Landley20deab02006-05-07 23:34:15 +00002045#ifdef HDIO_GET_QDMA
2046#ifdef HDIO_SET_QDMA
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002047 "Q:"
Rob Landley20deab02006-05-07 23:34:15 +00002048#else
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002049 "Q"
Rob Landley20deab02006-05-07 23:34:15 +00002050#endif
2051#endif
Denis Vlasenko5e34ff22009-04-21 11:09:40 +00002052 IF_FEATURE_HDPARM_HDIO_DRIVE_RESET("w")
2053 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF("x::b:")
2054 IF_FEATURE_HDPARM_HDIO_SCAN_HWIF("R:");
Rob Landley20deab02006-05-07 23:34:15 +00002055/*-------------------------------------*/
2056
2057/* our main() routine: */
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +00002058int hdparm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Rob Landley20deab02006-05-07 23:34:15 +00002059int hdparm_main(int argc, char **argv)
2060{
2061 int c;
Rob Landleyade7f952006-05-25 18:53:06 +00002062 int flagcount = 0;
Rob Landley20deab02006-05-07 23:34:15 +00002063
Denys Vlasenko16714242011-09-21 01:59:15 +02002064 INIT_G();
2065
Rob Landley06208412006-05-31 22:52:57 +00002066 while ((c = getopt(argc, argv, hdparm_options)) >= 0) {
Rob Landley20deab02006-05-07 23:34:15 +00002067 flagcount++;
Denis Vlasenko5e34ff22009-04-21 11:09:40 +00002068 IF_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I'));
2069 IF_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i'));
Rob Landleyadde7982006-05-16 15:32:30 +00002070 get_geom |= (c == 'g');
2071 do_flush |= (c == 'f');
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002072 if (c == 'u') getset_unmask = parse_opts_0_1(&unmask);
2073 IF_FEATURE_HDPARM_HDIO_GETSET_DMA(
2074 if (c == 'd') getset_dma = parse_opts_0_max(&dma, 9);
2075 )
2076 if (c == 'n') getset_nowerr = parse_opts_0_1(&nowerr);
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00002077 parse_xfermode((c == 'p'), &noisy_piomode, &set_piomode, &piomode);
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002078 if (c == 'r') getset_readonly = parse_opts_0_1(&readonly);
2079 if (c == 'm') getset_mult = parse_opts_0_INTMAX(&mult /*32*/);
2080 if (c == 'c') getset_io32bit = parse_opts_0_INTMAX(&io32bit /*8*/);
2081 if (c == 'k') getset_keep = parse_opts_0_1(&keep);
2082 if (c == 'a') getset_readahead = parse_opts_0_INTMAX(&Xreadahead);
2083 if (c == 'B') getset_apmmode = parse_opts(&apmmode, 1, 255);
Rob Landleyadde7982006-05-16 15:32:30 +00002084 do_flush |= do_timings |= (c == 't');
2085 do_flush |= do_ctimings |= (c == 'T');
Rob Landley20deab02006-05-07 23:34:15 +00002086#ifdef HDIO_DRIVE_CMD
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002087 if (c == 'S') getset_standby = parse_opts_0_max(&standby_requested, 255);
2088 if (c == 'D') getset_defects = parse_opts_0_INTMAX(&defects);
2089 if (c == 'P') getset_prefetch = parse_opts_0_INTMAX(&prefetch);
Rob Landleyade7f952006-05-25 18:53:06 +00002090 parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested);
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002091 if (c == 'K') getset_dkeep = parse_opts_0_1(&prefetch);
2092 if (c == 'A') getset_lookahead = parse_opts_0_1(&lookahead);
2093 if (c == 'L') getset_doorlock = parse_opts_0_1(&doorlock);
2094 if (c == 'W') getset_wcache = parse_opts_0_1(&wcache);
Rob Landleyade7f952006-05-25 18:53:06 +00002095 get_powermode |= (c == 'C');
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002096 set_standbynow |= (c == 'y');
2097 set_sleepnow |= (c == 'Y');
Rob Landleyadde7982006-05-16 15:32:30 +00002098 reread_partn |= (c == 'z');
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002099 set_seagate |= (c == 'Z');
Rob Landley20deab02006-05-07 23:34:15 +00002100#endif
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002101 IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') unregister_hwif = parse_opts_0_INTMAX(&hwif));
Rob Landley20deab02006-05-07 23:34:15 +00002102#ifdef HDIO_GET_QDMA
Rob Landley19802562006-05-08 15:35:46 +00002103 if (c == 'Q') {
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002104 getset_dma_q = parse_opts_0_INTMAX(&dma_q);
Rob Landley19802562006-05-08 15:35:46 +00002105 }
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00002106#endif
Denis Vlasenko5e34ff22009-04-21 11:09:40 +00002107 IF_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r'));
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002108 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') perform_tristate = parse_opts_0_1(&tristate));
2109 IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') getset_busstate = parse_opts_0_max(&busstate, 2));
Rob Landley20deab02006-05-07 23:34:15 +00002110#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
2111 if (c == 'R') {
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002112 scan_hwif = parse_opts_0_INTMAX(&hwif_data);
Denys Vlasenko77832482010-08-12 14:14:45 +02002113 hwif_ctrl = xatoi_positive((argv[optind]) ? argv[optind] : "");
2114 hwif_irq = xatoi_positive((argv[optind+1]) ? argv[optind+1] : "");
Rob Landley20deab02006-05-07 23:34:15 +00002115 /* Move past the 2 additional arguments */
2116 argv += 2;
2117 argc -= 2;
2118 }
2119#endif
2120 }
Rob Landleyade7f952006-05-25 18:53:06 +00002121 /* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */
Denis Vlasenko67b23e62006-10-03 21:00:06 +00002122 if (!flagcount) {
Denys Vlasenkoc7068452009-05-20 16:11:41 +02002123 getset_mult = getset_io32bit = getset_unmask = getset_keep = getset_readonly = getset_readahead = get_geom = IS_GET;
2124 IF_FEATURE_HDPARM_HDIO_GETSET_DMA(getset_dma = IS_GET);
Rob Landleyade7f952006-05-25 18:53:06 +00002125 }
Rob Landley20deab02006-05-07 23:34:15 +00002126 argv += optind;
2127
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00002128 if (!*argv) {
Rob Landley6d8ce172006-06-07 21:22:42 +00002129 if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO))
2130 identify_from_stdin(); /* EXIT */
Denis Vlasenko4daad902007-09-27 10:20:47 +00002131 bb_show_usage();
Rob Landley20deab02006-05-07 23:34:15 +00002132 }
2133
Denis Vlasenkof1ba7492007-03-28 00:14:01 +00002134 do {
2135 process_dev(*argv++);
2136 } while (*argv);
2137
2138 return EXIT_SUCCESS;
Eric Andersen3443bd72003-07-22 07:30:36 +00002139}