Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * hdparm implementation for busybox |
| 4 | * |
Glenn L McGrath | 5be6a20 | 2003-11-28 22:55:03 +0000 | [diff] [blame] | 5 | * Copyright (C) [2003] by [Matteo Croce] <3297627799@wind.it> |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 6 | * Hacked by Tito <farmatito@tiscali.it> for size optimization. |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 9 | * |
| 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 | */ |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 14 | //config:config HDPARM |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 15 | //config: bool "hdparm (25 kb)" |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 16 | //config: default y |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 17 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 18 | //config: Get/Set hard drive parameters. Primarily intended for ATA |
| 19 | //config: drives. |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 20 | //config: |
| 21 | //config:config FEATURE_HDPARM_GET_IDENTITY |
| 22 | //config: bool "Support obtaining detailed information directly from drives" |
| 23 | //config: default y |
| 24 | //config: depends on HDPARM |
| 25 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 26 | //config: Enable the -I and -i options to obtain detailed information |
| 27 | //config: directly from drives about their capabilities and supported ATA |
| 28 | //config: feature set. If no device name is specified, hdparm will read |
| 29 | //config: identify data from stdin. Enabling this option will add about 16k... |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 30 | //config: |
| 31 | //config:config FEATURE_HDPARM_HDIO_SCAN_HWIF |
| 32 | //config: bool "Register an IDE interface (DANGEROUS)" |
| 33 | //config: default y |
| 34 | //config: depends on HDPARM |
| 35 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 36 | //config: Enable the 'hdparm -R' option to register an IDE interface. |
| 37 | //config: This is dangerous stuff, so you should probably say N. |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 38 | //config: |
| 39 | //config:config FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
| 40 | //config: bool "Un-register an IDE interface (DANGEROUS)" |
| 41 | //config: default y |
| 42 | //config: depends on HDPARM |
| 43 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 44 | //config: Enable the 'hdparm -U' option to un-register an IDE interface. |
| 45 | //config: This is dangerous stuff, so you should probably say N. |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 46 | //config: |
| 47 | //config:config FEATURE_HDPARM_HDIO_DRIVE_RESET |
| 48 | //config: bool "Perform device reset (DANGEROUS)" |
| 49 | //config: default y |
| 50 | //config: depends on HDPARM |
| 51 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 52 | //config: Enable the 'hdparm -w' option to perform a device reset. |
| 53 | //config: This is dangerous stuff, so you should probably say N. |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 54 | //config: |
| 55 | //config:config FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
| 56 | //config: bool "Tristate device for hotswap (DANGEROUS)" |
| 57 | //config: default y |
| 58 | //config: depends on HDPARM |
| 59 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 60 | //config: Enable the 'hdparm -x' option to tristate device for hotswap, |
| 61 | //config: and the '-b' option to get/set bus state. This is dangerous |
| 62 | //config: stuff, so you should probably say N. |
Denys Vlasenko | fb4da16 | 2016-11-22 23:14:24 +0100 | [diff] [blame] | 63 | //config: |
| 64 | //config:config FEATURE_HDPARM_HDIO_GETSET_DMA |
| 65 | //config: bool "Get/set using_dma flag" |
| 66 | //config: default y |
| 67 | //config: depends on HDPARM |
| 68 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 69 | //config: Enable the 'hdparm -d' option to get/set using_dma flag. |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 70 | |
Denys Vlasenko | f88e3bf | 2016-11-22 23:54:17 +0100 | [diff] [blame] | 71 | //applet:IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP)) |
| 72 | |
| 73 | //kbuild:lib-$(CONFIG_HDPARM) += hdparm.o |
| 74 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 75 | //usage:#define hdparm_trivial_usage |
| 76 | //usage: "[OPTIONS] [DEVICE]" |
| 77 | //usage:#define hdparm_full_usage "\n\n" |
Denys Vlasenko | 6642676 | 2011-06-05 03:58:28 +0200 | [diff] [blame] | 78 | //usage: " -a Get/set fs readahead" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 79 | //usage: "\n -A Set drive read-lookahead flag (0/1)" |
| 80 | //usage: "\n -b Get/set bus state (0 == off, 1 == on, 2 == tristate)" |
| 81 | //usage: "\n -B Set Advanced Power Management setting (1-255)" |
| 82 | //usage: "\n -c Get/set IDE 32-bit IO setting" |
| 83 | //usage: "\n -C Check IDE power mode status" |
| 84 | //usage: IF_FEATURE_HDPARM_HDIO_GETSET_DMA( |
| 85 | //usage: "\n -d Get/set using_dma flag") |
| 86 | //usage: "\n -D Enable/disable drive defect-mgmt" |
| 87 | //usage: "\n -f Flush buffer cache for device on exit" |
| 88 | //usage: "\n -g Display drive geometry" |
| 89 | //usage: "\n -h Display terse usage information" |
| 90 | //usage: IF_FEATURE_HDPARM_GET_IDENTITY( |
| 91 | //usage: "\n -i Display drive identification") |
| 92 | //usage: IF_FEATURE_HDPARM_GET_IDENTITY( |
| 93 | //usage: "\n -I Detailed/current information directly from drive") |
| 94 | //usage: "\n -k Get/set keep_settings_over_reset flag (0/1)" |
| 95 | //usage: "\n -K Set drive keep_features_over_reset flag (0/1)" |
| 96 | //usage: "\n -L Set drive doorlock (0/1) (removable harddisks only)" |
| 97 | //usage: "\n -m Get/set multiple sector count" |
| 98 | //usage: "\n -n Get/set ignore-write-errors flag (0/1)" |
| 99 | //usage: "\n -p Set PIO mode on IDE interface chipset (0,1,2,3,4,...)" |
| 100 | //usage: "\n -P Set drive prefetch count" |
| 101 | /* //usage: "\n -q Change next setting quietly" - not supported ib bbox */ |
| 102 | //usage: "\n -Q Get/set DMA tagged-queuing depth (if supported)" |
| 103 | //usage: "\n -r Get/set readonly flag (DANGEROUS to set)" |
| 104 | //usage: IF_FEATURE_HDPARM_HDIO_SCAN_HWIF( |
| 105 | //usage: "\n -R Register an IDE interface (DANGEROUS)") |
| 106 | //usage: "\n -S Set standby (spindown) timeout" |
| 107 | //usage: "\n -t Perform device read timings" |
| 108 | //usage: "\n -T Perform cache read timings" |
| 109 | //usage: "\n -u Get/set unmaskirq flag (0/1)" |
| 110 | //usage: IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF( |
| 111 | //usage: "\n -U Unregister an IDE interface (DANGEROUS)") |
| 112 | //usage: "\n -v Defaults; same as -mcudkrag for IDE drives" |
| 113 | //usage: "\n -V Display program version and exit immediately" |
| 114 | //usage: IF_FEATURE_HDPARM_HDIO_DRIVE_RESET( |
| 115 | //usage: "\n -w Perform device reset (DANGEROUS)") |
| 116 | //usage: "\n -W Set drive write-caching flag (0/1) (DANGEROUS)" |
| 117 | //usage: IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( |
| 118 | //usage: "\n -x Tristate device for hotswap (0/1) (DANGEROUS)") |
| 119 | //usage: "\n -X Set IDE xfer mode (DANGEROUS)" |
| 120 | //usage: "\n -y Put IDE drive in standby mode" |
| 121 | //usage: "\n -Y Put IDE drive to sleep" |
| 122 | //usage: "\n -Z Disable Seagate auto-powersaving mode" |
| 123 | //usage: "\n -z Reread partition table" |
| 124 | |
Denys Vlasenko | 860d2bb | 2009-07-10 18:37:06 +0200 | [diff] [blame] | 125 | #include "libbb.h" |
Denys Vlasenko | e6a2f4c | 2016-04-21 16:26:30 +0200 | [diff] [blame] | 126 | #include "common_bufsiz.h" |
Denys Vlasenko | 860d2bb | 2009-07-10 18:37:06 +0200 | [diff] [blame] | 127 | /* must be _after_ libbb.h: */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 128 | #include <linux/hdreg.h> |
Denys Vlasenko | da49f58 | 2009-07-08 02:58:38 +0200 | [diff] [blame] | 129 | #include <sys/mount.h> |
Denys Vlasenko | af3fd14 | 2009-09-22 23:16:39 +0200 | [diff] [blame] | 130 | #if !defined(BLKGETSIZE64) |
| 131 | # define BLKGETSIZE64 _IOR(0x12,114,size_t) |
| 132 | #endif |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 133 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 134 | /* device types */ |
| 135 | /* ------------ */ |
| 136 | #define NO_DEV 0xffff |
| 137 | #define ATA_DEV 0x0000 |
| 138 | #define ATAPI_DEV 0x0001 |
| 139 | |
| 140 | /* word definitions */ |
| 141 | /* ---------------- */ |
| 142 | #define GEN_CONFIG 0 /* general configuration */ |
| 143 | #define LCYLS 1 /* number of logical cylinders */ |
| 144 | #define CONFIG 2 /* specific configuration */ |
| 145 | #define LHEADS 3 /* number of logical heads */ |
| 146 | #define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */ |
| 147 | #define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */ |
| 148 | #define LSECTS 6 /* number of logical sectors/track */ |
| 149 | #define START_SERIAL 10 /* ASCII serial number */ |
| 150 | #define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */ |
| 151 | #define BUF_TYPE 20 /* buffer type (ATA-1) */ |
| 152 | #define BUFFER__SIZE 21 /* buffer size (ATA-1) */ |
| 153 | #define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/ |
| 154 | #define START_FW_REV 23 /* ASCII firmware revision */ |
| 155 | #define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 156 | #define START_MODEL 27 /* ASCII model number */ |
| 157 | #define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */ |
Denis Vlasenko | 4b924f3 | 2007-05-30 00:29:55 +0000 | [diff] [blame] | 158 | #define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 159 | #define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */ |
| 160 | #define CAPAB_0 49 /* capabilities */ |
| 161 | #define CAPAB_1 50 |
| 162 | #define PIO_MODE 51 /* max PIO mode supported (obsolete)*/ |
| 163 | #define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/ |
| 164 | #define WHATS_VALID 53 /* what fields are valid */ |
| 165 | #define LCYLS_CUR 54 /* current logical cylinders */ |
| 166 | #define LHEADS_CUR 55 /* current logical heads */ |
Denis Vlasenko | 4b924f3 | 2007-05-30 00:29:55 +0000 | [diff] [blame] | 167 | #define LSECTS_CUR 56 /* current logical sectors/track */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 168 | #define CAPACITY_LSB 57 /* current capacity in sectors */ |
| 169 | #define CAPACITY_MSB 58 |
| 170 | #define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */ |
| 171 | #define LBA_SECTS_LSB 60 /* LBA: total number of user */ |
| 172 | #define LBA_SECTS_MSB 61 /* addressable sectors */ |
| 173 | #define SINGLE_DMA 62 /* singleword DMA modes */ |
| 174 | #define MULTI_DMA 63 /* multiword DMA modes */ |
| 175 | #define ADV_PIO_MODES 64 /* advanced PIO modes supported */ |
| 176 | /* multiword DMA xfer cycle time: */ |
| 177 | #define DMA_TIME_MIN 65 /* - minimum */ |
Denis Vlasenko | 551ffdc | 2009-04-01 19:48:05 +0000 | [diff] [blame] | 178 | #define DMA_TIME_NORM 66 /* - manufacturer's recommended */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 179 | /* minimum PIO xfer cycle time: */ |
| 180 | #define PIO_NO_FLOW 67 /* - without flow control */ |
| 181 | #define PIO_FLOW 68 /* - with IORDY flow control */ |
| 182 | #define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */ |
| 183 | #define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */ |
| 184 | #define CDR_MAJOR 73 /* CD ROM: major version number */ |
| 185 | #define CDR_MINOR 74 /* CD ROM: minor version number */ |
| 186 | #define QUEUE_DEPTH 75 /* queue depth */ |
| 187 | #define MAJOR 80 /* major version number */ |
| 188 | #define MINOR 81 /* minor version number */ |
| 189 | #define CMDS_SUPP_0 82 /* command/feature set(s) supported */ |
| 190 | #define CMDS_SUPP_1 83 |
| 191 | #define CMDS_SUPP_2 84 |
| 192 | #define CMDS_EN_0 85 /* command/feature set(s) enabled */ |
| 193 | #define CMDS_EN_1 86 |
| 194 | #define CMDS_EN_2 87 |
| 195 | #define ULTRA_DMA 88 /* ultra DMA modes */ |
| 196 | /* time to complete security erase */ |
| 197 | #define ERASE_TIME 89 /* - ordinary */ |
| 198 | #define ENH_ERASE_TIME 90 /* - enhanced */ |
| 199 | #define ADV_PWR 91 /* current advanced power management level |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 200 | in low byte, 0x40 in high byte. */ |
Denis Vlasenko | 551ffdc | 2009-04-01 19:48:05 +0000 | [diff] [blame] | 201 | #define PSWD_CODE 92 /* master password revision code */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 202 | #define HWRST_RSLT 93 /* hardware reset result */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 203 | #define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 204 | #define LBA_LSB 100 /* LBA: maximum. Currently only 48 */ |
| 205 | #define LBA_MID 101 /* bits are used, but addr 103 */ |
| 206 | #define LBA_48_MSB 102 /* has been reserved for LBA in */ |
| 207 | #define LBA_64_MSB 103 /* the future. */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 208 | #define RM_STAT 127 /* removable media status notification feature set support */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 209 | #define SECU_STATUS 128 /* security status */ |
| 210 | #define CFA_PWR_MODE 160 /* CFA power mode 1 */ |
| 211 | #define START_MEDIA 176 /* media serial number */ |
| 212 | #define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/ |
| 213 | #define START_MANUF 196 /* media manufacturer I.D. */ |
| 214 | #define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */ |
| 215 | #define INTEGRITY 255 /* integrity word */ |
| 216 | |
| 217 | /* bit definitions within the words */ |
| 218 | /* -------------------------------- */ |
| 219 | |
| 220 | /* many words are considered valid if bit 15 is 0 and bit 14 is 1 */ |
| 221 | #define VALID 0xc000 |
| 222 | #define VALID_VAL 0x4000 |
| 223 | /* many words are considered invalid if they are either all-0 or all-1 */ |
| 224 | #define NOVAL_0 0x0000 |
| 225 | #define NOVAL_1 0xffff |
| 226 | |
| 227 | /* word 0: gen_config */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 228 | #define NOT_ATA 0x8000 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 229 | #define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */ |
| 230 | #define MEDIA_REMOVABLE 0x0080 |
| 231 | #define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */ |
| 232 | #define INCOMPLETE 0x0004 |
| 233 | #define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */ |
| 234 | #define DRQ_RESPONSE_TIME 0x0060 |
| 235 | #define DRQ_3MS_VAL 0x0000 |
| 236 | #define DRQ_INTR_VAL 0x0020 |
| 237 | #define DRQ_50US_VAL 0x0040 |
| 238 | #define PKT_SIZE_SUPPORTED 0x0003 |
| 239 | #define PKT_SIZE_12_VAL 0x0000 |
| 240 | #define PKT_SIZE_16_VAL 0x0001 |
| 241 | #define EQPT_TYPE 0x1f00 |
| 242 | #define SHIFT_EQPT 8 |
| 243 | |
| 244 | #define CDROM 0x0005 |
| 245 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 246 | /* word 1: number of logical cylinders */ |
| 247 | #define LCYLS_MAX 0x3fff /* maximum allowable value */ |
| 248 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 249 | /* word 2: specific configuration |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 250 | * (a) require SET FEATURES to spin-up |
| 251 | * (b) require spin-up to fully reply to IDENTIFY DEVICE |
| 252 | */ |
| 253 | #define STBY_NID_VAL 0x37c8 /* (a) and (b) */ |
| 254 | #define STBY_ID_VAL 0x738c /* (a) and not (b) */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 255 | #define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 256 | #define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */ |
| 257 | |
| 258 | /* words 47 & 59: sector_xfer_max & sector_xfer_cur */ |
| 259 | #define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/ |
| 260 | #define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */ |
| 261 | |
| 262 | /* word 49: capabilities 0 */ |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 263 | #define STD_STBY 0x2000 /* 1=standard values supported (ATA); 0=vendor specific values */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 264 | #define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */ |
| 265 | #define IORDY_OFF 0x0400 /* 1=may be disabled */ |
| 266 | #define LBA_SUP 0x0200 /* 1=Logical Block Address support */ |
| 267 | #define DMA_SUP 0x0100 /* 1=Direct Memory Access support */ |
| 268 | #define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */ |
| 269 | #define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */ |
| 270 | #define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */ |
| 271 | #define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */ |
| 272 | |
| 273 | /* word 50: capabilities 1 */ |
| 274 | #define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */ |
| 275 | |
| 276 | /* words 51 & 52: PIO & DMA cycle times */ |
| 277 | #define MODE 0xff00 /* the mode is in the MSBs */ |
| 278 | |
| 279 | /* word 53: whats_valid */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 280 | #define OK_W88 0x0004 /* the ultra_dma info is valid */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 281 | #define OK_W64_70 0x0002 /* see above for word descriptions */ |
| 282 | #define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */ |
| 283 | |
| 284 | /*word 63,88: dma_mode, ultra_dma_mode*/ |
| 285 | #define MODE_MAX 7 /* bit definitions force udma <=7 (when |
| 286 | * udma >=8 comes out it'll have to be |
| 287 | * defined in a new dma_mode word!) */ |
| 288 | |
| 289 | /* word 64: PIO transfer modes */ |
| 290 | #define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */ |
| 291 | #define PIO_MODE_MAX 8 /* but all 8 bits are defined */ |
| 292 | |
| 293 | /* word 75: queue_depth */ |
| 294 | #define DEPTH_BITS 0x001f /* bits used for queue depth */ |
| 295 | |
| 296 | /* words 80-81: version numbers */ |
| 297 | /* NOVAL_0 or NOVAL_1 means device does not report version */ |
| 298 | |
| 299 | /* word 81: minor version number */ |
Rob Landley | 0e6a3e1 | 2006-04-28 01:33:30 +0000 | [diff] [blame] | 300 | #define MINOR_MAX 0x22 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 301 | /* words 82-84: cmds/feats supported */ |
| 302 | #define CMDS_W82 0x77ff /* word 82: defined command locations*/ |
| 303 | #define CMDS_W83 0x3fff /* word 83: defined command locations*/ |
| 304 | #define CMDS_W84 0x002f /* word 83: defined command locations*/ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 305 | #define SUPPORT_48_BIT 0x0400 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 306 | #define NUM_CMD_FEAT_STR 48 |
| 307 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 308 | /* words 85-87: cmds/feats enabled */ |
| 309 | /* use cmd_feat_str[] to display what commands and features have |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 310 | * been enabled with words 85-87 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 311 | */ |
| 312 | |
| 313 | /* words 89, 90, SECU ERASE TIME */ |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 314 | #define ERASE_BITS 0x00ff |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 315 | |
| 316 | /* word 92: master password revision */ |
| 317 | /* NOVAL_0 or NOVAL_1 means no support for master password revision */ |
| 318 | |
| 319 | /* word 93: hw reset result */ |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 320 | #define CBLID 0x2000 /* CBLID status */ |
| 321 | #define RST0 0x0001 /* 1=reset to device #0 */ |
| 322 | #define DEV_DET 0x0006 /* how device num determined */ |
| 323 | #define JUMPER_VAL 0x0002 /* device num determined by jumper */ |
| 324 | #define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 325 | |
| 326 | /* word 127: removable media status notification feature set support */ |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 327 | #define RM_STAT_BITS 0x0003 |
| 328 | #define RM_STAT_SUP 0x0001 |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 329 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 330 | /* word 128: security */ |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 331 | #define SECU_ENABLED 0x0002 |
| 332 | #define SECU_LEVEL 0x0010 |
| 333 | #define NUM_SECU_STR 6 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 334 | |
| 335 | /* word 160: CFA power mode */ |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 336 | #define VALID_W160 0x8000 /* 1=word valid */ |
| 337 | #define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/ |
| 338 | #define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */ |
| 339 | #define MAX_AMPS 0x0fff /* value = max current in ma */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 340 | |
| 341 | /* word 255: integrity */ |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 342 | #define SIG 0x00ff /* signature location */ |
| 343 | #define SIG_VAL 0x00a5 /* signature value */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 344 | |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 345 | #define TIMING_BUF_MB 1 |
| 346 | #define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 347 | |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 348 | #undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 349 | |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 350 | |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 351 | #define IS_GET 1 |
| 352 | #define IS_SET 2 |
| 353 | |
| 354 | |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 355 | enum { fd = 3 }; |
| 356 | |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 357 | |
| 358 | struct globals { |
| 359 | smallint get_identity, get_geom; |
| 360 | smallint do_flush; |
| 361 | smallint do_ctimings, do_timings; |
| 362 | smallint reread_partn; |
| 363 | smallint set_piomode, noisy_piomode; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 364 | smallint getset_readahead; |
| 365 | smallint getset_readonly; |
| 366 | smallint getset_unmask; |
| 367 | smallint getset_mult; |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 368 | #ifdef HDIO_GET_QDMA |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 369 | smallint getset_dma_q; |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 370 | #endif |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 371 | smallint getset_nowerr; |
| 372 | smallint getset_keep; |
| 373 | smallint getset_io32bit; |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 374 | int piomode; |
| 375 | unsigned long Xreadahead; |
| 376 | unsigned long readonly; |
| 377 | unsigned long unmask; |
| 378 | unsigned long mult; |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 379 | #ifdef HDIO_SET_QDMA |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 380 | unsigned long dma_q; |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 381 | #endif |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 382 | unsigned long nowerr; |
| 383 | unsigned long keep; |
| 384 | unsigned long io32bit; |
| 385 | #if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
| 386 | unsigned long dma; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 387 | smallint getset_dma; |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 388 | #endif |
| 389 | #ifdef HDIO_DRIVE_CMD |
| 390 | smallint set_xfermode, get_xfermode; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 391 | smallint getset_dkeep; |
| 392 | smallint getset_standby; |
| 393 | smallint getset_lookahead; |
| 394 | smallint getset_prefetch; |
| 395 | smallint getset_defects; |
| 396 | smallint getset_wcache; |
| 397 | smallint getset_doorlock; |
| 398 | smallint set_seagate; |
| 399 | smallint set_standbynow; |
| 400 | smallint set_sleepnow; |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 401 | smallint get_powermode; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 402 | smallint getset_apmmode; |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 403 | int xfermode_requested; |
| 404 | unsigned long dkeep; |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 405 | unsigned long standby_requested; /* 0..255 */ |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 406 | unsigned long lookahead; |
| 407 | unsigned long prefetch; |
| 408 | unsigned long defects; |
| 409 | unsigned long wcache; |
| 410 | unsigned long doorlock; |
| 411 | unsigned long apmmode; |
| 412 | #endif |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 413 | IF_FEATURE_HDPARM_GET_IDENTITY( smallint get_IDentity;) |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 414 | IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint getset_busstate;) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 415 | IF_FEATURE_HDPARM_HDIO_DRIVE_RESET( smallint perform_reset;) |
| 416 | IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( smallint perform_tristate;) |
| 417 | IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(smallint unregister_hwif;) |
| 418 | IF_FEATURE_HDPARM_HDIO_SCAN_HWIF( smallint scan_hwif;) |
| 419 | IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long busstate;) |
| 420 | IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF( unsigned long tristate;) |
| 421 | IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(unsigned long hwif;) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 422 | #if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
| 423 | unsigned long hwif_data; |
| 424 | unsigned long hwif_ctrl; |
| 425 | unsigned long hwif_irq; |
| 426 | #endif |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 427 | #ifdef DO_FLUSHCACHE |
| 428 | unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 }; |
| 429 | #endif |
Denys Vlasenko | 98a4c7c | 2010-02-04 15:00:15 +0100 | [diff] [blame] | 430 | } FIX_ALIASING; |
Denys Vlasenko | e6a2f4c | 2016-04-21 16:26:30 +0200 | [diff] [blame] | 431 | #define G (*(struct globals*)bb_common_bufsiz1) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 432 | #define get_identity (G.get_identity ) |
| 433 | #define get_geom (G.get_geom ) |
| 434 | #define do_flush (G.do_flush ) |
| 435 | #define do_ctimings (G.do_ctimings ) |
| 436 | #define do_timings (G.do_timings ) |
| 437 | #define reread_partn (G.reread_partn ) |
| 438 | #define set_piomode (G.set_piomode ) |
| 439 | #define noisy_piomode (G.noisy_piomode ) |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 440 | #define getset_readahead (G.getset_readahead ) |
| 441 | #define getset_readonly (G.getset_readonly ) |
| 442 | #define getset_unmask (G.getset_unmask ) |
| 443 | #define getset_mult (G.getset_mult ) |
| 444 | #define getset_dma_q (G.getset_dma_q ) |
| 445 | #define getset_nowerr (G.getset_nowerr ) |
| 446 | #define getset_keep (G.getset_keep ) |
| 447 | #define getset_io32bit (G.getset_io32bit ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 448 | #define piomode (G.piomode ) |
| 449 | #define Xreadahead (G.Xreadahead ) |
| 450 | #define readonly (G.readonly ) |
| 451 | #define unmask (G.unmask ) |
| 452 | #define mult (G.mult ) |
| 453 | #define dma_q (G.dma_q ) |
| 454 | #define nowerr (G.nowerr ) |
| 455 | #define keep (G.keep ) |
| 456 | #define io32bit (G.io32bit ) |
| 457 | #define dma (G.dma ) |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 458 | #define getset_dma (G.getset_dma ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 459 | #define set_xfermode (G.set_xfermode ) |
| 460 | #define get_xfermode (G.get_xfermode ) |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 461 | #define getset_dkeep (G.getset_dkeep ) |
| 462 | #define getset_standby (G.getset_standby ) |
| 463 | #define getset_lookahead (G.getset_lookahead ) |
| 464 | #define getset_prefetch (G.getset_prefetch ) |
| 465 | #define getset_defects (G.getset_defects ) |
| 466 | #define getset_wcache (G.getset_wcache ) |
| 467 | #define getset_doorlock (G.getset_doorlock ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 468 | #define set_seagate (G.set_seagate ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 469 | #define set_standbynow (G.set_standbynow ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 470 | #define set_sleepnow (G.set_sleepnow ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 471 | #define get_powermode (G.get_powermode ) |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 472 | #define getset_apmmode (G.getset_apmmode ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 473 | #define xfermode_requested (G.xfermode_requested ) |
| 474 | #define dkeep (G.dkeep ) |
| 475 | #define standby_requested (G.standby_requested ) |
| 476 | #define lookahead (G.lookahead ) |
| 477 | #define prefetch (G.prefetch ) |
| 478 | #define defects (G.defects ) |
| 479 | #define wcache (G.wcache ) |
| 480 | #define doorlock (G.doorlock ) |
| 481 | #define apmmode (G.apmmode ) |
| 482 | #define get_IDentity (G.get_IDentity ) |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 483 | #define getset_busstate (G.getset_busstate ) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 484 | #define perform_reset (G.perform_reset ) |
| 485 | #define perform_tristate (G.perform_tristate ) |
| 486 | #define unregister_hwif (G.unregister_hwif ) |
| 487 | #define scan_hwif (G.scan_hwif ) |
| 488 | #define busstate (G.busstate ) |
| 489 | #define tristate (G.tristate ) |
| 490 | #define hwif (G.hwif ) |
| 491 | #define hwif_data (G.hwif_data ) |
| 492 | #define hwif_ctrl (G.hwif_ctrl ) |
| 493 | #define hwif_irq (G.hwif_irq ) |
Denys Vlasenko | 7b85ec3 | 2015-10-13 17:17:34 +0200 | [diff] [blame] | 494 | #define INIT_G() do { \ |
Denys Vlasenko | 47cfbf3 | 2016-04-21 18:18:48 +0200 | [diff] [blame] | 495 | setup_common_bufsiz(); \ |
Denys Vlasenko | 7b85ec3 | 2015-10-13 17:17:34 +0200 | [diff] [blame] | 496 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
| 497 | } while (0) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 498 | |
| 499 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 500 | /* Busybox messages and functions */ |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 501 | #if ENABLE_IOCTL_HEX2STR_ERROR |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 502 | static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt, const char *string) |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 503 | { |
| 504 | if (!ioctl(fd, cmd, args)) |
| 505 | return 0; |
| 506 | args[0] = alt; |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 507 | return bb_ioctl_or_warn(fd, cmd, args, string); |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 508 | } |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 509 | #define ioctl_alt_or_warn(cmd,args,alt) ioctl_alt_func(cmd,args,alt,#cmd) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 510 | #else |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 511 | static int ioctl_alt_func(/*int fd,*/ int cmd, unsigned char *args, int alt) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 512 | { |
| 513 | if (!ioctl(fd, cmd, args)) |
| 514 | return 0; |
| 515 | args[0] = alt; |
| 516 | return bb_ioctl_or_warn(fd, cmd, args); |
| 517 | } |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 518 | #define ioctl_alt_or_warn(cmd,args,alt) ioctl_alt_func(cmd,args,alt) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 519 | #endif |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 520 | |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 521 | static void on_off(int value) |
| 522 | { |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 523 | puts(value ? " (on)" : " (off)"); |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 524 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 525 | |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 526 | static void print_flag_on_off(int get_arg, const char *s, unsigned long arg) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 527 | { |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 528 | if (get_arg) { |
Denys Vlasenko | 327f550 | 2013-11-29 16:45:45 +0100 | [diff] [blame] | 529 | printf(" setting %s to %lu", s, arg); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 530 | on_off(arg); |
| 531 | } |
| 532 | } |
| 533 | |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 534 | static void print_value_on_off(const char *str, unsigned long argp) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 535 | { |
Denys Vlasenko | 327f550 | 2013-11-29 16:45:45 +0100 | [diff] [blame] | 536 | printf(" %s\t= %2lu", str, argp); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 537 | on_off(argp != 0); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 538 | } |
Eric Andersen | 416c242 | 2003-12-12 00:08:57 +0000 | [diff] [blame] | 539 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 540 | #if ENABLE_FEATURE_HDPARM_GET_IDENTITY |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 541 | static void print_ascii(const char *p, int length) |
| 542 | { |
| 543 | #if BB_BIG_ENDIAN |
| 544 | #define LE_ONLY(x) |
| 545 | enum { ofs = 0 }; |
| 546 | #else |
| 547 | #define LE_ONLY(x) x |
| 548 | /* every 16bit word is big-endian (i.e. inverted) */ |
| 549 | /* accessing bytes in 1,0, 3,2, 5,4... sequence */ |
| 550 | int ofs = 1; |
| 551 | #endif |
| 552 | |
| 553 | length *= 2; |
| 554 | /* find first non-space & print it */ |
| 555 | while (length && p[ofs] != ' ') { |
| 556 | p++; |
| 557 | LE_ONLY(ofs = -ofs;) |
| 558 | length--; |
| 559 | } |
| 560 | while (length && p[ofs]) { |
| 561 | bb_putchar(p[ofs]); |
| 562 | p++; |
| 563 | LE_ONLY(ofs = -ofs;) |
| 564 | length--; |
| 565 | } |
| 566 | bb_putchar('\n'); |
| 567 | #undef LE_ONLY |
| 568 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 569 | |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 570 | static void xprint_ascii(uint16_t *val, int i, const char *string, int n) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 571 | { |
Denis Vlasenko | b6aae0f | 2007-01-29 22:51:25 +0000 | [diff] [blame] | 572 | if (val[i]) { |
| 573 | printf("\t%-20s", string); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 574 | print_ascii((void*)&val[i], n); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 577 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 578 | static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode) |
| 579 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 580 | uint16_t ii; |
| 581 | uint8_t err_dma = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 582 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 583 | for (ii = 0; ii <= MODE_MAX; ii++) { |
| 584 | if (mode_sel & 0x0001) { |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 585 | printf("*%cdma%u ", cc, ii); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 586 | if (*have_mode) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 587 | err_dma = 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 588 | *have_mode = 1; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 589 | } else if (mode_sup & 0x0001) |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 590 | printf("%cdma%u ", cc, ii); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 591 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 592 | mode_sup >>= 1; |
| 593 | mode_sel >>= 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 594 | } |
| 595 | return err_dma; |
| 596 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 597 | |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 598 | static const char pkt_str[] ALIGN1 = |
| 599 | "Direct-access device" "\0" /* word 0, bits 12-8 = 00 */ |
| 600 | "Sequential-access device" "\0" /* word 0, bits 12-8 = 01 */ |
| 601 | "Printer" "\0" /* word 0, bits 12-8 = 02 */ |
| 602 | "Processor" "\0" /* word 0, bits 12-8 = 03 */ |
| 603 | "Write-once device" "\0" /* word 0, bits 12-8 = 04 */ |
| 604 | "CD-ROM" "\0" /* word 0, bits 12-8 = 05 */ |
| 605 | "Scanner" "\0" /* word 0, bits 12-8 = 06 */ |
| 606 | "Optical memory" "\0" /* word 0, bits 12-8 = 07 */ |
| 607 | "Medium changer" "\0" /* word 0, bits 12-8 = 08 */ |
| 608 | "Communications device" "\0" /* word 0, bits 12-8 = 09 */ |
| 609 | "ACS-IT8 device" "\0" /* word 0, bits 12-8 = 0a */ |
| 610 | "ACS-IT8 device" "\0" /* word 0, bits 12-8 = 0b */ |
| 611 | "Array controller" "\0" /* word 0, bits 12-8 = 0c */ |
| 612 | "Enclosure services" "\0" /* word 0, bits 12-8 = 0d */ |
| 613 | "Reduced block command device" "\0" /* word 0, bits 12-8 = 0e */ |
| 614 | "Optical card reader/writer" "\0" /* word 0, bits 12-8 = 0f */ |
| 615 | ; |
| 616 | |
| 617 | static const char ata1_cfg_str[] ALIGN1 = /* word 0 in ATA-1 mode */ |
| 618 | "reserved" "\0" /* bit 0 */ |
| 619 | "hard sectored" "\0" /* bit 1 */ |
| 620 | "soft sectored" "\0" /* bit 2 */ |
| 621 | "not MFM encoded " "\0" /* bit 3 */ |
| 622 | "head switch time > 15us" "\0" /* bit 4 */ |
| 623 | "spindle motor control option" "\0" /* bit 5 */ |
| 624 | "fixed drive" "\0" /* bit 6 */ |
| 625 | "removable drive" "\0" /* bit 7 */ |
| 626 | "disk xfer rate <= 5Mbs" "\0" /* bit 8 */ |
| 627 | "disk xfer rate > 5Mbs, <= 10Mbs" "\0" /* bit 9 */ |
| 628 | "disk xfer rate > 5Mbs" "\0" /* bit 10 */ |
| 629 | "rotational speed tol." "\0" /* bit 11 */ |
| 630 | "data strobe offset option" "\0" /* bit 12 */ |
| 631 | "track offset option" "\0" /* bit 13 */ |
| 632 | "format speed tolerance gap reqd" "\0" /* bit 14 */ |
| 633 | "ATAPI" /* bit 14 */ |
| 634 | ; |
| 635 | |
| 636 | static const char minor_str[] ALIGN1 = |
| 637 | /* word 81 value: */ |
| 638 | "Unspecified" "\0" /* 0x0000 */ |
| 639 | "ATA-1 X3T9.2 781D prior to rev.4" "\0" /* 0x0001 */ |
| 640 | "ATA-1 published, ANSI X3.221-1994" "\0" /* 0x0002 */ |
| 641 | "ATA-1 X3T9.2 781D rev.4" "\0" /* 0x0003 */ |
| 642 | "ATA-2 published, ANSI X3.279-1996" "\0" /* 0x0004 */ |
| 643 | "ATA-2 X3T10 948D prior to rev.2k" "\0" /* 0x0005 */ |
| 644 | "ATA-3 X3T10 2008D rev.1" "\0" /* 0x0006 */ |
| 645 | "ATA-2 X3T10 948D rev.2k" "\0" /* 0x0007 */ |
| 646 | "ATA-3 X3T10 2008D rev.0" "\0" /* 0x0008 */ |
| 647 | "ATA-2 X3T10 948D rev.3" "\0" /* 0x0009 */ |
| 648 | "ATA-3 published, ANSI X3.298-199x" "\0" /* 0x000a */ |
| 649 | "ATA-3 X3T10 2008D rev.6" "\0" /* 0x000b */ |
| 650 | "ATA-3 X3T13 2008D rev.7 and 7a" "\0" /* 0x000c */ |
| 651 | "ATA/ATAPI-4 X3T13 1153D rev.6" "\0" /* 0x000d */ |
| 652 | "ATA/ATAPI-4 T13 1153D rev.13" "\0" /* 0x000e */ |
| 653 | "ATA/ATAPI-4 X3T13 1153D rev.7" "\0" /* 0x000f */ |
| 654 | "ATA/ATAPI-4 T13 1153D rev.18" "\0" /* 0x0010 */ |
| 655 | "ATA/ATAPI-4 T13 1153D rev.15" "\0" /* 0x0011 */ |
| 656 | "ATA/ATAPI-4 published, ANSI INCITS 317-1998" "\0" /* 0x0012 */ |
| 657 | "ATA/ATAPI-5 T13 1321D rev.3" "\0" /* 0x0013 */ |
| 658 | "ATA/ATAPI-4 T13 1153D rev.14" "\0" /* 0x0014 */ |
| 659 | "ATA/ATAPI-5 T13 1321D rev.1" "\0" /* 0x0015 */ |
| 660 | "ATA/ATAPI-5 published, ANSI INCITS 340-2000" "\0" /* 0x0016 */ |
| 661 | "ATA/ATAPI-4 T13 1153D rev.17" "\0" /* 0x0017 */ |
| 662 | "ATA/ATAPI-6 T13 1410D rev.0" "\0" /* 0x0018 */ |
| 663 | "ATA/ATAPI-6 T13 1410D rev.3a" "\0" /* 0x0019 */ |
| 664 | "ATA/ATAPI-7 T13 1532D rev.1" "\0" /* 0x001a */ |
| 665 | "ATA/ATAPI-6 T13 1410D rev.2" "\0" /* 0x001b */ |
| 666 | "ATA/ATAPI-6 T13 1410D rev.1" "\0" /* 0x001c */ |
| 667 | "ATA/ATAPI-7 published, ANSI INCITS 397-2005" "\0" /* 0x001d */ |
| 668 | "ATA/ATAPI-7 T13 1532D rev.0" "\0" /* 0x001e */ |
| 669 | "reserved" "\0" /* 0x001f */ |
| 670 | "reserved" "\0" /* 0x0020 */ |
| 671 | "ATA/ATAPI-7 T13 1532D rev.4a" "\0" /* 0x0021 */ |
| 672 | "ATA/ATAPI-6 published, ANSI INCITS 361-2002" "\0" /* 0x0022 */ |
| 673 | "reserved" /* 0x0023-0xfffe */ |
| 674 | ; |
| 675 | static const char actual_ver[MINOR_MAX + 2] ALIGN1 = { |
| 676 | /* word 81 value: */ |
| 677 | 0, /* 0x0000 WARNING: actual_ver[] array */ |
| 678 | 1, /* 0x0001 WARNING: corresponds */ |
| 679 | 1, /* 0x0002 WARNING: *exactly* */ |
| 680 | 1, /* 0x0003 WARNING: to the ATA/ */ |
| 681 | 2, /* 0x0004 WARNING: ATAPI version */ |
| 682 | 2, /* 0x0005 WARNING: listed in */ |
| 683 | 3, /* 0x0006 WARNING: the */ |
| 684 | 2, /* 0x0007 WARNING: minor_str */ |
| 685 | 3, /* 0x0008 WARNING: array */ |
| 686 | 2, /* 0x0009 WARNING: above. */ |
| 687 | 3, /* 0x000a WARNING: */ |
| 688 | 3, /* 0x000b WARNING: If you change */ |
| 689 | 3, /* 0x000c WARNING: that one, */ |
| 690 | 4, /* 0x000d WARNING: change this one */ |
| 691 | 4, /* 0x000e WARNING: too!!! */ |
| 692 | 4, /* 0x000f */ |
| 693 | 4, /* 0x0010 */ |
| 694 | 4, /* 0x0011 */ |
| 695 | 4, /* 0x0012 */ |
| 696 | 5, /* 0x0013 */ |
| 697 | 4, /* 0x0014 */ |
| 698 | 5, /* 0x0015 */ |
| 699 | 5, /* 0x0016 */ |
| 700 | 4, /* 0x0017 */ |
| 701 | 6, /* 0x0018 */ |
| 702 | 6, /* 0x0019 */ |
| 703 | 7, /* 0x001a */ |
| 704 | 6, /* 0x001b */ |
| 705 | 6, /* 0x001c */ |
| 706 | 7, /* 0x001d */ |
| 707 | 7, /* 0x001e */ |
| 708 | 0, /* 0x001f */ |
| 709 | 0, /* 0x0020 */ |
| 710 | 7, /* 0x0021 */ |
| 711 | 6, /* 0x0022 */ |
| 712 | 0 /* 0x0023-0xfffe */ |
| 713 | }; |
| 714 | |
| 715 | static const char cmd_feat_str[] ALIGN1 = |
| 716 | "" "\0" /* word 82 bit 15: obsolete */ |
| 717 | "NOP cmd" "\0" /* word 82 bit 14 */ |
| 718 | "READ BUFFER cmd" "\0" /* word 82 bit 13 */ |
| 719 | "WRITE BUFFER cmd" "\0" /* word 82 bit 12 */ |
| 720 | "" "\0" /* word 82 bit 11: obsolete */ |
| 721 | "Host Protected Area feature set" "\0" /* word 82 bit 10 */ |
| 722 | "DEVICE RESET cmd" "\0" /* word 82 bit 9 */ |
| 723 | "SERVICE interrupt" "\0" /* word 82 bit 8 */ |
| 724 | "Release interrupt" "\0" /* word 82 bit 7 */ |
| 725 | "Look-ahead" "\0" /* word 82 bit 6 */ |
| 726 | "Write cache" "\0" /* word 82 bit 5 */ |
| 727 | "PACKET command feature set" "\0" /* word 82 bit 4 */ |
| 728 | "Power Management feature set" "\0" /* word 82 bit 3 */ |
| 729 | "Removable Media feature set" "\0" /* word 82 bit 2 */ |
| 730 | "Security Mode feature set" "\0" /* word 82 bit 1 */ |
| 731 | "SMART feature set" "\0" /* word 82 bit 0 */ |
| 732 | /* -------------- */ |
| 733 | "" "\0" /* word 83 bit 15: !valid bit */ |
| 734 | "" "\0" /* word 83 bit 14: valid bit */ |
| 735 | "FLUSH CACHE EXT cmd" "\0" /* word 83 bit 13 */ |
| 736 | "Mandatory FLUSH CACHE cmd " "\0" /* word 83 bit 12 */ |
| 737 | "Device Configuration Overlay feature set " "\0" |
| 738 | "48-bit Address feature set " "\0" /* word 83 bit 10 */ |
| 739 | "" "\0" |
| 740 | "SET MAX security extension" "\0" /* word 83 bit 8 */ |
| 741 | "Address Offset Reserved Area Boot" "\0" /* word 83 bit 7 */ |
| 742 | "SET FEATURES subcommand required to spinup after power up" "\0" |
| 743 | "Power-Up In Standby feature set" "\0" /* word 83 bit 5 */ |
| 744 | "Removable Media Status Notification feature set" "\0" |
| 745 | "Adv. Power Management feature set" "\0" /* word 83 bit 3 */ |
| 746 | "CFA feature set" "\0" /* word 83 bit 2 */ |
| 747 | "READ/WRITE DMA QUEUED" "\0" /* word 83 bit 1 */ |
| 748 | "DOWNLOAD MICROCODE cmd" "\0" /* word 83 bit 0 */ |
| 749 | /* -------------- */ |
| 750 | "" "\0" /* word 84 bit 15: !valid bit */ |
| 751 | "" "\0" /* word 84 bit 14: valid bit */ |
| 752 | "" "\0" /* word 84 bit 13: reserved */ |
| 753 | "" "\0" /* word 84 bit 12: reserved */ |
| 754 | "" "\0" /* word 84 bit 11: reserved */ |
| 755 | "" "\0" /* word 84 bit 10: reserved */ |
| 756 | "" "\0" /* word 84 bit 9: reserved */ |
| 757 | "" "\0" /* word 84 bit 8: reserved */ |
| 758 | "" "\0" /* word 84 bit 7: reserved */ |
| 759 | "" "\0" /* word 84 bit 6: reserved */ |
| 760 | "General Purpose Logging feature set" "\0" /* word 84 bit 5 */ |
| 761 | "" "\0" /* word 84 bit 4: reserved */ |
| 762 | "Media Card Pass Through Command feature set " "\0" |
| 763 | "Media serial number " "\0" /* word 84 bit 2 */ |
| 764 | "SMART self-test " "\0" /* word 84 bit 1 */ |
| 765 | "SMART error logging " /* word 84 bit 0 */ |
| 766 | ; |
| 767 | |
| 768 | static const char secu_str[] ALIGN1 = |
| 769 | "supported" "\0" /* word 128, bit 0 */ |
| 770 | "enabled" "\0" /* word 128, bit 1 */ |
| 771 | "locked" "\0" /* word 128, bit 2 */ |
| 772 | "frozen" "\0" /* word 128, bit 3 */ |
| 773 | "expired: security count" "\0" /* word 128, bit 4 */ |
| 774 | "supported: enhanced erase" /* word 128, bit 5 */ |
| 775 | ; |
| 776 | |
| 777 | // Parse 512 byte disk identification block and print much crap. |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 778 | static void identify(uint16_t *val) NORETURN; |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 779 | static void identify(uint16_t *val) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 780 | { |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 781 | uint16_t ii, jj, kk; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 782 | uint16_t like_std = 1, std = 0, min_std = 0xffff; |
| 783 | uint16_t dev = NO_DEV, eqpt = NO_DEV; |
| 784 | uint8_t have_mode = 0, err_dma = 0; |
| 785 | uint8_t chksum = 0; |
| 786 | uint32_t ll, mm, nn, oo; |
Rob Landley | 2e2d752 | 2006-04-29 15:23:33 +0000 | [diff] [blame] | 787 | uint64_t bbbig; /* (:) */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 788 | const char *strng; |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 789 | #if BB_BIG_ENDIAN |
| 790 | uint16_t buf[256]; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 791 | |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 792 | // Adjust for endianness |
| 793 | swab(val, buf, sizeof(buf)); |
| 794 | val = buf; |
| 795 | #endif |
Denys Vlasenko | b22bbff | 2009-07-04 16:50:43 +0200 | [diff] [blame] | 796 | /* check if we recognize the device type */ |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 797 | bb_putchar('\n'); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 798 | if (!(val[GEN_CONFIG] & NOT_ATA)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 799 | dev = ATA_DEV; |
| 800 | printf("ATA device, with "); |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 801 | } else if (val[GEN_CONFIG] == CFA_SUPPORT_VAL) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 802 | dev = ATA_DEV; |
| 803 | like_std = 4; |
| 804 | printf("CompactFlash ATA device, with "); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 805 | } else if (!(val[GEN_CONFIG] & NOT_ATAPI)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 806 | dev = ATAPI_DEV; |
| 807 | eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT; |
Denis Vlasenko | bfc3d82 | 2007-11-04 04:10:17 +0000 | [diff] [blame] | 808 | printf("ATAPI %s, with ", eqpt <= 0xf ? nth_string(pkt_str, eqpt) : "unknown"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 809 | like_std = 3; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 810 | } else |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 811 | /* "Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n" */ |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 812 | bb_simple_error_msg_and_die("unknown device type"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 813 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 814 | printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : ""); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 815 | /* Info from the specific configuration word says whether or not the |
| 816 | * ID command completed correctly. It is only defined, however in |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 817 | * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 818 | * standards. Since the values allowed for this word are extremely |
| 819 | * specific, it should be safe to check it now, even though we don't |
| 820 | * know yet what standard this device is using. |
| 821 | */ |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 822 | if ((val[CONFIG] == STBY_NID_VAL) || (val[CONFIG] == STBY_ID_VAL) |
| 823 | || (val[CONFIG] == PWRD_NID_VAL) || (val[CONFIG] == PWRD_ID_VAL) |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 824 | ) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 825 | like_std = 5; |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 826 | if ((val[CONFIG] == STBY_NID_VAL) || (val[CONFIG] == STBY_ID_VAL)) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 827 | puts("powers-up in standby; SET FEATURES subcmd spins-up."); |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 828 | if (((val[CONFIG] == STBY_NID_VAL) || (val[CONFIG] == PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 829 | puts("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /* output the model and serial numbers and the fw revision */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 833 | xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL); |
| 834 | xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL); |
| 835 | xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV); |
| 836 | xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA); |
| 837 | xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 838 | |
| 839 | /* major & minor standards version number (Note: these words were not |
| 840 | * defined until ATA-3 & the CDROM std uses different words.) */ |
| 841 | printf("Standards:"); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 842 | if (eqpt != CDROM) { |
| 843 | if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) { |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 844 | if (like_std < 3) like_std = 3; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 845 | std = actual_ver[val[MINOR]]; |
Denys Vlasenko | f3ea792 | 2010-07-26 01:06:14 +0200 | [diff] [blame] | 846 | if (std) |
| 847 | printf("\n\tUsed: %s ", nth_string(minor_str, val[MINOR])); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 848 | } |
| 849 | /* looks like when they up-issue the std, they obsolete one; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 850 | * thus, only the newest 4 issues need be supported. (That's |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 851 | * what "kk" and "min_std" are all about.) */ |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 852 | if (val[MAJOR] && (val[MAJOR] != NOVAL_1)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 853 | printf("\n\tSupported: "); |
| 854 | jj = val[MAJOR] << 1; |
| 855 | kk = like_std >4 ? like_std-4: 0; |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 856 | for (ii = 14; (ii > 0) && (ii > kk); ii--) { |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 857 | if (jj & 0x8000) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 858 | printf("%u ", ii); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 859 | if (like_std < ii) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 860 | like_std = ii; |
| 861 | kk = like_std >4 ? like_std-4: 0; |
| 862 | } |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 863 | if (min_std > ii) min_std = ii; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 864 | } |
| 865 | jj <<= 1; |
| 866 | } |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 867 | if (like_std < 3) like_std = 3; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 868 | } |
| 869 | /* Figure out what standard the device is using if it hasn't told |
| 870 | * us. If we know the std, check if the device is using any of |
| 871 | * the words from the next level up. It happens. |
| 872 | */ |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 873 | if (like_std < std) like_std = std; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 874 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 875 | if (((std == 5) || (!std && (like_std < 6))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 876 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 877 | (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) || |
| 878 | ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) && |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 879 | ( val[CMDS_SUPP_2] & CMDS_W84) ) ) |
| 880 | ) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 881 | like_std = 6; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 882 | } else if (((std == 4) || (!std && (like_std < 5))) && |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 883 | ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) || |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 884 | (( val[HWRST_RSLT] & VALID) == VALID_VAL) || |
| 885 | ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 886 | (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) ) |
| 887 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 888 | like_std = 5; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 889 | } else if (((std == 3) || (!std && (like_std < 4))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 890 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 891 | ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) || |
| 892 | (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) || |
| 893 | (( val[CAPAB_1] & VALID) == VALID_VAL) || |
| 894 | (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) || |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 895 | (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) |
| 896 | ) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 897 | like_std = 4; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 898 | } else if (((std == 2) || (!std && (like_std < 3))) |
| 899 | && ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) |
| 900 | ) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 901 | like_std = 3; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 902 | } else if (((std == 1) || (!std && (like_std < 2))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 903 | ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) || |
| 904 | (val[WHATS_VALID] & OK_W64_70)) ) |
| 905 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 906 | like_std = 2; |
| 907 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 908 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 909 | if (!std) |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 910 | printf("\n\tLikely used: %u\n", like_std); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 911 | else if (like_std > std) |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 912 | printf("& some of %u\n", like_std); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 913 | else |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 914 | bb_putchar('\n'); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 915 | } else { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 916 | /* TBD: do CDROM stuff more thoroughly. For now... */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 917 | kk = 0; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 918 | if (val[CDR_MINOR] == 9) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 919 | kk = 1; |
| 920 | printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5"); |
| 921 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 922 | if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 923 | kk = 1; |
| 924 | printf("\n\tSupported: CD-ROM ATAPI"); |
| 925 | jj = val[CDR_MAJOR] >> 1; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 926 | for (ii = 1; ii < 15; ii++) { |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 927 | if (jj & 0x0001) printf("-%u ", ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 928 | jj >>= 1; |
| 929 | } |
| 930 | } |
Denis Vlasenko | feb7ae7 | 2007-10-01 12:05:12 +0000 | [diff] [blame] | 931 | puts(kk ? "" : "\n\tLikely used CD-ROM ATAPI-1"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 932 | /* the cdrom stuff is more like ATA-2 than anything else, so: */ |
| 933 | like_std = 2; |
| 934 | } |
| 935 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 936 | if (min_std == 0xffff) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 937 | min_std = like_std > 4 ? like_std - 3 : 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 938 | |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 939 | puts("Configuration:"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 940 | /* more info from the general configuration word */ |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 941 | if ((eqpt != CDROM) && (like_std == 1)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 942 | jj = val[GEN_CONFIG] >> 1; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 943 | for (ii = 1; ii < 15; ii++) { |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 944 | if (jj & 0x0001) |
Denis Vlasenko | bfc3d82 | 2007-11-04 04:10:17 +0000 | [diff] [blame] | 945 | printf("\t%s\n", nth_string(ata1_cfg_str, ii)); |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 946 | jj >>= 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 947 | } |
| 948 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 949 | if (dev == ATAPI_DEV) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 950 | if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_3MS_VAL) |
| 951 | strng = "3ms"; |
| 952 | else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_INTR_VAL) |
| 953 | strng = "<=10ms with INTRQ"; |
| 954 | else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_50US_VAL) |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 955 | strng = "50us"; |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 956 | else |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 957 | strng = "unknown"; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 958 | printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */ |
| 959 | |
| 960 | if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_12_VAL) |
| 961 | strng = "12 bytes"; |
| 962 | else if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_16_VAL) |
| 963 | strng = "16 bytes"; |
| 964 | else |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 965 | strng = "unknown"; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 966 | puts(strng); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 967 | } else { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 968 | /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 969 | ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB]; |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 970 | mm = 0; |
| 971 | bbbig = 0; |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 972 | if ((ll > 0x00FBFC10) && (!val[LCYLS])) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 973 | puts("\tCHS addressing not supported"); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 974 | else { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 975 | jj = val[WHATS_VALID] & OK_W54_58; |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 976 | printf("\tLogical\t\tmax\tcurrent\n" |
| 977 | "\tcylinders\t%u\t%u\n" |
| 978 | "\theads\t\t%u\t%u\n" |
| 979 | "\tsectors/track\t%u\t%u\n" |
| 980 | "\t--\n", |
| 981 | val[LCYLS], |
| 982 | jj ? val[LCYLS_CUR] : 0, |
| 983 | val[LHEADS], |
| 984 | jj ? val[LHEADS_CUR] : 0, |
| 985 | val[LSECTS], |
| 986 | jj ? val[LSECTS_CUR] : 0); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 987 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 988 | if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 989 | printf("\tbytes/track: %u\tbytes/sector: %u\n", |
| 990 | val[TRACK_BYTES], val[SECT_BYTES]); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 991 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 992 | if (jj) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 993 | mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 994 | if (like_std < 3) { |
| 995 | /* check Endian of capacity bytes */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 996 | nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR]; |
| 997 | oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB]; |
Denys Vlasenko | 122a8cb | 2019-10-25 17:47:22 +0200 | [diff] [blame] | 998 | if (abs((int)(mm - nn)) > abs((int)(oo - nn))) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 999 | mm = oo; |
| 1000 | } |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1001 | printf("\tCHS current addressable sectors:%11u\n", mm); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1002 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1003 | } |
| 1004 | /* LBA addressing */ |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1005 | printf("\tLBA user addressable sectors:%11u\n", ll); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1006 | if (((val[CMDS_SUPP_1] & VALID) == VALID_VAL) |
| 1007 | && (val[CMDS_SUPP_1] & SUPPORT_48_BIT) |
| 1008 | ) { |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1009 | bbbig = (uint64_t)val[LBA_64_MSB] << 48 | |
| 1010 | (uint64_t)val[LBA_48_MSB] << 32 | |
| 1011 | (uint64_t)val[LBA_MID] << 16 | |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1012 | val[LBA_LSB]; |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1013 | printf("\tLBA48 user addressable sectors:%11"PRIu64"\n", bbbig); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1014 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1015 | |
| 1016 | if (!bbbig) |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 1017 | bbbig = (uint64_t)(ll > mm ? ll : mm); /* # 512 byte blocks */ |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1018 | printf("\tdevice size with M = 1024*1024: %11"PRIu64" MBytes\n", bbbig>>11); |
| 1019 | bbbig = (bbbig << 9) / 1000000; |
| 1020 | printf("\tdevice size with M = 1000*1000: %11"PRIu64" MBytes ", bbbig); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1021 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1022 | if (bbbig > 1000) |
Rob Landley | 81dab2c | 2006-05-28 01:56:08 +0000 | [diff] [blame] | 1023 | printf("(%"PRIu64" GB)\n", bbbig/1000); |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 1024 | else |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1025 | bb_putchar('\n'); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | /* hw support of commands (capabilities) */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1029 | printf("Capabilities:\n\t"); |
| 1030 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1031 | if (dev == ATAPI_DEV) { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1032 | if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) |
| 1033 | printf("Cmd queuing, "); |
| 1034 | if (val[CAPAB_0] & OVLP_SUP) |
| 1035 | printf("Cmd overlap, "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1036 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1037 | if (val[CAPAB_0] & LBA_SUP) printf("LBA, "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1038 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1039 | if (like_std != 1) { |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 1040 | printf("IORDY%s(can%s be disabled)\n", |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1041 | !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "", |
| 1042 | (val[CAPAB_0] & IORDY_OFF) ? "" :"not"); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1043 | } else |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1044 | puts("no IORDY"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1045 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1046 | if ((like_std == 1) && val[BUF_TYPE]) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1047 | printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE], |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1048 | (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", |
| 1049 | (val[BUF_TYPE] > 2) ? " with read caching ability" : ""); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1050 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1051 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1052 | if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) { |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1053 | printf("\tBuffer size: %.1fkB\n", (float)val[BUFFER__SIZE]/2); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1054 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1055 | if ((min_std < 4) && (val[RW_LONG])) { |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1056 | printf("\tbytes avail on r/w long: %u\n", val[RW_LONG]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1057 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1058 | if ((eqpt != CDROM) && (like_std > 3)) { |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1059 | printf("\tQueue depth: %u\n", (val[QUEUE_DEPTH] & DEPTH_BITS) + 1); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1060 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1061 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1062 | if (dev == ATA_DEV) { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1063 | if (like_std == 1) |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1064 | printf("\tCan%s perform double-word IO\n", (!val[DWORD_IO]) ? "not" : ""); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1065 | else { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1066 | printf("\tStandby timer values: spec'd by %s", |
| 1067 | (val[CAPAB_0] & STD_STBY) ? "standard" : "vendor"); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1068 | if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1069 | printf(", %s device specific minimum\n", |
| 1070 | (val[CAPAB_1] & MIN_STANDBY_TIMER) ? "with" : "no"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1071 | else |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1072 | bb_putchar('\n'); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1073 | } |
| 1074 | printf("\tR/W multiple sector transfer: "); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1075 | if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER)) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1076 | puts("not supported"); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1077 | else { |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1078 | printf("Max = %u\tCurrent = ", val[SECTOR_XFER_MAX] & SECTOR_XFER); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1079 | if (val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID) |
| 1080 | printf("%u\n", val[SECTOR_XFER_CUR] & SECTOR_XFER); |
| 1081 | else |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1082 | puts("?"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1083 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1084 | if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1085 | /* We print out elsewhere whether the APM feature is enabled or |
Denys Vlasenko | 60cb48c | 2013-01-14 15:57:44 +0100 | [diff] [blame] | 1086 | * not. If it's not enabled, let's not repeat the info; just print |
| 1087 | * nothing here. */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1088 | printf("\tAdvancedPM level: "); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1089 | if ((val[ADV_PWR] & 0xFF00) == 0x4000) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1090 | uint8_t apm_level = val[ADV_PWR] & 0x00FF; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1091 | printf("%u (0x%x)\n", apm_level, apm_level); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1092 | } |
| 1093 | else |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1094 | printf("unknown setting (0x%04x)\n", val[ADV_PWR]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1095 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1096 | if (like_std > 5 && val[ACOUSTIC]) { |
| 1097 | printf("\tRecommended acoustic management value: %u, current value: %u\n", |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1098 | (val[ACOUSTIC] >> 8) & 0x00ff, |
| 1099 | val[ACOUSTIC] & 0x00ff); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1100 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1101 | } else { |
Denys Vlasenko | 6830ade | 2013-01-15 13:58:01 +0100 | [diff] [blame] | 1102 | /* ATAPI */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1103 | if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ)) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1104 | puts("\tATA sw reset required"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1105 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1106 | if (val[PKT_REL] || val[SVC_NBSY]) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1107 | printf("\tOverlap support:"); |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1108 | if (val[PKT_REL]) |
| 1109 | printf(" %uus to release bus.", val[PKT_REL]); |
| 1110 | if (val[SVC_NBSY]) |
| 1111 | printf(" %uus to clear BSY after SERVICE cmd.", |
| 1112 | val[SVC_NBSY]); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1113 | bb_putchar('\n'); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | /* DMA stuff. Check that only one DMA mode is selected. */ |
| 1118 | printf("\tDMA: "); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1119 | if (!(val[CAPAB_0] & DMA_SUP)) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1120 | puts("not supported"); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1121 | else { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1122 | if (val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]) |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1123 | printf(" sdma%u\n", (val[DMA_MODE] & MODE) >> 8); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1124 | if (val[SINGLE_DMA]) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1125 | jj = val[SINGLE_DMA]; |
| 1126 | kk = val[SINGLE_DMA] >> 8; |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1127 | err_dma += mode_loop(jj, kk, 's', &have_mode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1128 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1129 | if (val[MULTI_DMA]) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1130 | jj = val[MULTI_DMA]; |
| 1131 | kk = val[MULTI_DMA] >> 8; |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1132 | err_dma += mode_loop(jj, kk, 'm', &have_mode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1133 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1134 | if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1135 | jj = val[ULTRA_DMA]; |
| 1136 | kk = val[ULTRA_DMA] >> 8; |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1137 | err_dma += mode_loop(jj, kk, 'u', &have_mode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1138 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1139 | if (err_dma || !have_mode) printf("(?)"); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1140 | bb_putchar('\n'); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1141 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1142 | if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1143 | puts("\t\tInterleaved DMA support"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1144 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1145 | if ((val[WHATS_VALID] & OK_W64_70) |
| 1146 | && (val[DMA_TIME_MIN] || val[DMA_TIME_NORM]) |
| 1147 | ) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1148 | printf("\t\tCycle time:"); |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1149 | if (val[DMA_TIME_MIN]) printf(" min=%uns", val[DMA_TIME_MIN]); |
| 1150 | if (val[DMA_TIME_NORM]) printf(" recommended=%uns", val[DMA_TIME_NORM]); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1151 | bb_putchar('\n'); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | /* Programmed IO stuff */ |
| 1156 | printf("\tPIO: "); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1157 | /* If a drive supports mode n (e.g. 3), it also supports all modes less |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1158 | * than n (e.g. 3, 2, 1 and 0). Print all the modes. */ |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1159 | if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1160 | jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007; |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1161 | for (ii = 0; ii <= PIO_MODE_MAX; ii++) { |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1162 | if (jj & 0x0001) printf("pio%d ", ii); |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 1163 | jj >>= 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1164 | } |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1165 | bb_putchar('\n'); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1166 | } else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE)) { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1167 | for (ii = 0; ii <= val[PIO_MODE]>>8; ii++) |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1168 | printf("pio%d ", ii); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1169 | bb_putchar('\n'); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1170 | } else |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 1171 | puts("unknown"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1172 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1173 | if (val[WHATS_VALID] & OK_W64_70) { |
| 1174 | if (val[PIO_NO_FLOW] || val[PIO_FLOW]) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1175 | printf("\t\tCycle time:"); |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1176 | if (val[PIO_NO_FLOW]) |
| 1177 | printf(" no flow control=%uns", val[PIO_NO_FLOW]); |
| 1178 | if (val[PIO_FLOW]) |
| 1179 | printf(" IORDY flow control=%uns", val[PIO_FLOW]); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1180 | bb_putchar('\n'); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1184 | if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) { |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1185 | puts("Commands/features:\n" |
| 1186 | "\tEnabled\tSupported:"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1187 | jj = val[CMDS_SUPP_0]; |
| 1188 | kk = val[CMDS_EN_0]; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1189 | for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) { |
Denis Vlasenko | bfc3d82 | 2007-11-04 04:10:17 +0000 | [diff] [blame] | 1190 | const char *feat_str = nth_string(cmd_feat_str, ii); |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 1191 | if ((jj & 0x8000) && (*feat_str != '\0')) { |
| 1192 | printf("\t%s\t%s\n", (kk & 0x8000) ? " *" : "", feat_str); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1193 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1194 | jj <<= 1; |
| 1195 | kk <<= 1; |
| 1196 | if (ii % 16 == 15) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1197 | jj = val[CMDS_SUPP_0+1+(ii/16)]; |
| 1198 | kk = val[CMDS_EN_0+1+(ii/16)]; |
| 1199 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1200 | if (ii == 31) { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1201 | if ((val[CMDS_SUPP_2] & VALID) != VALID_VAL) |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 1202 | ii += 16; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1203 | } |
| 1204 | } |
| 1205 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1206 | /* Removable Media Status Notification feature set */ |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 1207 | if ((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) |
Denis Vlasenko | bfc3d82 | 2007-11-04 04:10:17 +0000 | [diff] [blame] | 1208 | printf("\t%s supported\n", nth_string(cmd_feat_str, 27)); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1209 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1210 | /* security */ |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1211 | if ((eqpt != CDROM) && (like_std > 3) |
| 1212 | && (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME]) |
| 1213 | ) { |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1214 | puts("Security:"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1215 | if (val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)) |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1216 | printf("\tMaster password revision code = %u\n", val[PSWD_CODE]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1217 | jj = val[SECU_STATUS]; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1218 | if (jj) { |
| 1219 | for (ii = 0; ii < NUM_SECU_STR; ii++) { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1220 | printf("\t%s\t%s\n", |
| 1221 | (!(jj & 0x0001)) ? "not" : "", |
| 1222 | nth_string(secu_str, ii)); |
Denys Vlasenko | fe73c8d | 2022-08-30 16:41:17 +0200 | [diff] [blame] | 1223 | jj >>= 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1224 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1225 | if (val[SECU_STATUS] & SECU_ENABLED) { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1226 | printf("\tSecurity level %s\n", |
| 1227 | (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | jj = val[ERASE_TIME] & ERASE_BITS; |
| 1231 | kk = val[ENH_ERASE_TIME] & ERASE_BITS; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1232 | if (jj || kk) { |
Denis Vlasenko | 7d60fc1 | 2008-06-05 06:51:06 +0000 | [diff] [blame] | 1233 | bb_putchar('\t'); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1234 | if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, ""); |
| 1235 | if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED "); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1236 | bb_putchar('\n'); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | /* reset result */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1241 | jj = val[HWRST_RSLT]; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1242 | if ((jj & VALID) == VALID_VAL) { |
Denis Vlasenko | 6bef3d1 | 2007-11-06 03:05:54 +0000 | [diff] [blame] | 1243 | oo = (jj & RST0); |
| 1244 | if (!oo) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1245 | jj >>= 8; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1246 | if ((jj & DEV_DET) == JUMPER_VAL) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1247 | strng = " determined by the jumper"; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1248 | else if ((jj & DEV_DET) == CSEL_VAL) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1249 | strng = " determined by CSEL"; |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 1250 | else |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1251 | strng = ""; |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1252 | printf("HW reset results:\n" |
| 1253 | "\tCBLID- %s Vih\n" |
| 1254 | "\tDevice num = %i%s\n", |
| 1255 | (val[HWRST_RSLT] & CBLID) ? "above" : "below", |
| 1256 | !(oo), strng); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | /* more stuff from std 5 */ |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1260 | if ((like_std > 4) && (eqpt != CDROM)) { |
| 1261 | if (val[CFA_PWR_MODE] & VALID_W160) { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1262 | printf("CFA power mode 1:\n" |
| 1263 | "\t%s%s\n", |
| 1264 | (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled", |
| 1265 | (val[CFA_PWR_MODE] & PWR_MODE_REQ) ? " and required by some commands" : ""); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1266 | if (val[CFA_PWR_MODE] & MAX_AMPS) |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1267 | printf("\tMaximum current = %uma\n", val[CFA_PWR_MODE] & MAX_AMPS); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1268 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1269 | if ((val[INTEGRITY] & SIG) == SIG_VAL) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1270 | printf("Checksum: %scorrect\n", chksum ? "in" : ""); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
Denys Vlasenko | db5546c | 2022-01-05 22:16:06 +0100 | [diff] [blame] | 1274 | exit_SUCCESS(); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1275 | } |
| 1276 | #endif |
| 1277 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1278 | // Historically, if there was no HDIO_OBSOLETE_IDENTITY, then |
| 1279 | // then the HDIO_GET_IDENTITY only returned 142 bytes. |
| 1280 | // Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes, |
| 1281 | // and HDIO_GET_IDENTITY returns 512 bytes. But the latest |
| 1282 | // 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY |
| 1283 | // (which they should, but they should just return -EINVAL). |
| 1284 | // |
| 1285 | // So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes. |
| 1286 | // On a really old system, it will not, and we will be confused. |
| 1287 | // Too bad, really. |
| 1288 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1289 | #if ENABLE_FEATURE_HDPARM_GET_IDENTITY |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 1290 | static const char cfg_str[] ALIGN1 = |
Denis Vlasenko | 6b40443 | 2008-01-07 16:13:14 +0000 | [diff] [blame] | 1291 | """\0" "HardSect""\0" "SoftSect""\0" "NotMFM""\0" |
| 1292 | "HdSw>15uSec""\0" "SpinMotCtl""\0" "Fixed""\0" "Removeable""\0" |
| 1293 | "DTR<=5Mbs""\0" "DTR>5Mbs""\0" "DTR>10Mbs""\0" "RotSpdTol>.5%""\0" |
| 1294 | "dStbOff""\0" "TrkOff""\0" "FmtGapReq""\0" "nonMagnetic" |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 1295 | ; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1296 | |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 1297 | static const char BuffType[] ALIGN1 = |
| 1298 | "unknown""\0" "1Sect""\0" "DualPort""\0" "DualPortCache" |
| 1299 | ; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1300 | |
Denys Vlasenko | a7bb3c1 | 2009-10-08 12:28:08 +0200 | [diff] [blame] | 1301 | static NOINLINE void dump_identity(const struct hd_driveid *id) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1302 | { |
| 1303 | int i; |
Denis Vlasenko | 284d0fa | 2008-02-16 13:18:17 +0000 | [diff] [blame] | 1304 | const unsigned short *id_regs = (const void*) id; |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 1305 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1306 | printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={", |
| 1307 | id->model, id->fw_rev, id->serial_no); |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1308 | for (i = 0; i <= 15; i++) { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1309 | if (id->config & (1<<i)) |
Denis Vlasenko | bfc3d82 | 2007-11-04 04:10:17 +0000 | [diff] [blame] | 1310 | printf(" %s", nth_string(cfg_str, i)); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1311 | } |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1312 | printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n" |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1313 | " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u", |
| 1314 | id->cyls, id->heads, id->sectors, id->track_bytes, |
| 1315 | id->sector_bytes, id->ecc_bytes, |
| 1316 | id->buf_type, |
| 1317 | nth_string(BuffType, (id->buf_type > 3) ? 0 : id->buf_type), |
| 1318 | id->buf_size/2, id->max_multsect); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1319 | if (id->max_multsect) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1320 | printf(", MultSect="); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1321 | if (!(id->multsect_valid & 1)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1322 | printf("?%u?", id->multsect); |
| 1323 | else if (id->multsect) |
| 1324 | printf("%u", id->multsect); |
| 1325 | else |
| 1326 | printf("off"); |
| 1327 | } |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1328 | bb_putchar('\n'); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1329 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1330 | if (!(id->field_valid & 1)) |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1331 | printf(" (maybe):"); |
| 1332 | |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1333 | printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s", id->cur_cyls, id->cur_heads, |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1334 | id->cur_sectors, |
| 1335 | (BB_BIG_ENDIAN) ? |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1336 | (unsigned long)(id->cur_capacity0 << 16) | id->cur_capacity1 : |
| 1337 | (unsigned long)(id->cur_capacity1 << 16) | id->cur_capacity0, |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1338 | ((id->capability&2) == 0) ? "no" : "yes"); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1339 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1340 | if (id->capability & 2) |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1341 | printf(", LBAsects=%u", id->lba_capacity); |
| 1342 | |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1343 | printf("\n IORDY=%s", |
| 1344 | (id->capability & 8) |
| 1345 | ? ((id->capability & 4) ? "on/off" : "yes") |
| 1346 | : "no"); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1347 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1348 | if (((id->capability & 8) || (id->field_valid & 2)) && (id->field_valid & 2)) |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1349 | printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy); |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 1350 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1351 | if ((id->capability & 1) && (id->field_valid & 2)) |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1352 | printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time); |
| 1353 | |
| 1354 | printf("\n PIO modes: "); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1355 | if (id->tPIO <= 5) { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1356 | printf("pio0 "); |
| 1357 | if (id->tPIO >= 1) printf("pio1 "); |
| 1358 | if (id->tPIO >= 2) printf("pio2 "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1359 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1360 | if (id->field_valid & 2) { |
Denis Vlasenko | 53354ac | 2008-06-07 15:10:29 +0000 | [diff] [blame] | 1361 | static const masks_labels_t pio_modes = { |
| 1362 | .masks = { 1, 2, ~3 }, |
| 1363 | .labels = "pio3 \0""pio4 \0""pio? \0", |
| 1364 | }; |
| 1365 | print_flags(&pio_modes, id->eide_pio_modes); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1366 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1367 | if (id->capability & 1) { |
| 1368 | if (id->dma_1word | id->dma_mword) { |
Denys Vlasenko | 965b795 | 2020-11-30 13:03:03 +0100 | [diff] [blame] | 1369 | static const int dma_wmode_masks[] ALIGN4 = { 0x100, 1, 0x200, 2, 0x400, 4, 0xf800, 0xf8 }; |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1370 | printf("\n DMA modes: "); |
Denis Vlasenko | 53354ac | 2008-06-07 15:10:29 +0000 | [diff] [blame] | 1371 | print_flags_separated(dma_wmode_masks, |
| 1372 | "*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0", |
| 1373 | id->dma_1word, NULL); |
| 1374 | print_flags_separated(dma_wmode_masks, |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1375 | "*\0""mdma0 \0""*\0""mdma1 \0""*\0""mdma2 \0""*\0""mdma? \0", |
Denis Vlasenko | 53354ac | 2008-06-07 15:10:29 +0000 | [diff] [blame] | 1376 | id->dma_mword, NULL); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1377 | } |
| 1378 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1379 | if (((id->capability & 8) || (id->field_valid & 2)) && id->field_valid & 4) { |
Denis Vlasenko | 53354ac | 2008-06-07 15:10:29 +0000 | [diff] [blame] | 1380 | static const masks_labels_t ultra_modes1 = { |
| 1381 | .masks = { 0x100, 0x001, 0x200, 0x002, 0x400, 0x004 }, |
| 1382 | .labels = "*\0""udma0 \0""*\0""udma1 \0""*\0""udma2 \0", |
| 1383 | }; |
Denis Vlasenko | 7049ff8 | 2008-06-25 09:53:17 +0000 | [diff] [blame] | 1384 | |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1385 | printf("\n UDMA modes: "); |
Denis Vlasenko | 53354ac | 2008-06-07 15:10:29 +0000 | [diff] [blame] | 1386 | print_flags(&ultra_modes1, id->dma_ultra); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1387 | #ifdef __NEW_HD_DRIVE_ID |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1388 | if (id->hw_config & 0x2000) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1389 | #else /* !__NEW_HD_DRIVE_ID */ |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1390 | if (id->word93 & 0x2000) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1391 | #endif /* __NEW_HD_DRIVE_ID */ |
Denis Vlasenko | 53354ac | 2008-06-07 15:10:29 +0000 | [diff] [blame] | 1392 | static const masks_labels_t ultra_modes2 = { |
| 1393 | .masks = { 0x0800, 0x0008, 0x1000, 0x0010, |
| 1394 | 0x2000, 0x0020, 0x4000, 0x0040, |
| 1395 | 0x8000, 0x0080 }, |
| 1396 | .labels = "*\0""udma3 \0""*\0""udma4 \0" |
| 1397 | "*\0""udma5 \0""*\0""udma6 \0" |
| 1398 | "*\0""udma7 \0" |
| 1399 | }; |
| 1400 | print_flags(&ultra_modes2, id->dma_ultra); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1401 | } |
| 1402 | } |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1403 | printf("\n AdvancedPM=%s", (!(id_regs[83] & 8)) ? "no" : "yes"); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1404 | if (id_regs[83] & 8) { |
| 1405 | if (!(id_regs[86] & 8)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1406 | printf(": disabled (255)"); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1407 | else if ((id_regs[91] & 0xFF00) != 0x4000) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1408 | printf(": unknown setting"); |
| 1409 | else |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1410 | printf(": mode=0x%02X (%u)", id_regs[91] & 0xFF, id_regs[91] & 0xFF); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1411 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1412 | if (id_regs[82] & 0x20) |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1413 | printf(" WriteCache=%s", (id_regs[85] & 0x20) ? "enabled" : "disabled"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1414 | #ifdef __NEW_HD_DRIVE_ID |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1415 | if ((id->minor_rev_num && id->minor_rev_num <= 31) |
| 1416 | || (id->major_rev_num && id->minor_rev_num <= 31) |
| 1417 | ) { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1418 | printf("\n Drive conforms to: %s: ", |
| 1419 | (id->minor_rev_num <= 31) ? nth_string(minor_str, id->minor_rev_num) : "unknown"); |
| 1420 | if (id->major_rev_num != 0x0000 /* NOVAL_0 */ |
| 1421 | && id->major_rev_num != 0xFFFF /* NOVAL_1 */ |
| 1422 | ) { |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1423 | for (i = 0; i <= 15; i++) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1424 | if (id->major_rev_num & (1<<i)) |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1425 | printf(" ATA/ATAPI-%u", i); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1426 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1427 | } |
| 1428 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1429 | #endif /* __NEW_HD_DRIVE_ID */ |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1430 | puts("\n\n * current active mode\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1431 | } |
| 1432 | #endif |
| 1433 | |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1434 | static void flush_buffer_cache(/*int fd*/ void) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1435 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1436 | fsync(fd); /* flush buffers */ |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1437 | ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1438 | #ifdef HDIO_DRIVE_CMD |
Denys Vlasenko | ec16c03 | 2020-11-29 11:37:34 +0100 | [diff] [blame] | 1439 | sleep1(); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1440 | if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) { /* await completion */ |
| 1441 | if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */ |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 1442 | bb_simple_perror_msg("HDIO_DRIVE_CMD"); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1443 | else |
| 1444 | bb_perror_msg("ioctl %#x failed", HDIO_DRIVE_CMD); |
| 1445 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1446 | #endif |
| 1447 | } |
| 1448 | |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1449 | static void seek_to_zero(/*int fd*/ void) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1450 | { |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1451 | xlseek(fd, (off_t) 0, SEEK_SET); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1454 | static void read_big_block(/*int fd,*/ char *buf) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1455 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1456 | int i; |
| 1457 | |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1458 | xread(fd, buf, TIMING_BUF_BYTES); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1459 | /* access all sectors of buf to ensure the read fully completed */ |
| 1460 | for (i = 0; i < TIMING_BUF_BYTES; i += 512) |
| 1461 | buf[i] &= 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1464 | static unsigned dev_size_mb(/*int fd*/ void) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1465 | { |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1466 | union { |
| 1467 | unsigned long long blksize64; |
| 1468 | unsigned blksize32; |
| 1469 | } u; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1470 | |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1471 | if (0 == ioctl(fd, BLKGETSIZE64, &u.blksize64)) { // bytes |
| 1472 | u.blksize64 /= (1024 * 1024); |
| 1473 | } else { |
| 1474 | xioctl(fd, BLKGETSIZE, &u.blksize32); // sectors |
| 1475 | u.blksize64 = u.blksize32 / (2 * 1024); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1476 | } |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1477 | if (u.blksize64 > UINT_MAX) |
| 1478 | return UINT_MAX; |
| 1479 | return u.blksize64; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1480 | } |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1481 | |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1482 | static void print_timing(unsigned m, unsigned elapsed_us) |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1483 | { |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1484 | unsigned sec = elapsed_us / 1000000; |
| 1485 | unsigned hs = (elapsed_us % 1000000) / 10000; |
| 1486 | |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1487 | printf("%5u MB in %u.%02u seconds = %u kB/s\n", |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1488 | m, sec, hs, |
Denis Vlasenko | 0afdfdf | 2007-09-28 13:41:41 +0000 | [diff] [blame] | 1489 | /* "| 1" prevents div-by-0 */ |
| 1490 | (unsigned) ((unsigned long long)m * (1024 * 1000000) / (elapsed_us | 1)) |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1491 | // ~= (m * 1024) / (elapsed_us / 1000000) |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1492 | // = kb / elapsed_sec |
| 1493 | ); |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1496 | static void do_time(int cache /*,int fd*/) |
| 1497 | /* cache=1: time cache: repeatedly read N MB at offset 0 |
| 1498 | * cache=0: time device: linear read, starting at offset 0 |
| 1499 | */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1500 | { |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1501 | unsigned max_iterations, iterations; |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1502 | unsigned start; /* doesn't need to be long long */ |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1503 | unsigned elapsed, elapsed2; |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1504 | unsigned total_MB; |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1505 | char *buf = xmalloc(TIMING_BUF_BYTES); |
Rob Landley | 4ae2f51 | 2006-05-19 17:24:26 +0000 | [diff] [blame] | 1506 | |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1507 | if (mlock(buf, TIMING_BUF_BYTES)) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 1508 | bb_simple_perror_msg_and_die("mlock"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1509 | |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1510 | /* Clear out the device request queues & give them time to complete. |
| 1511 | * NB: *small* delay. User is expected to have a clue and to not run |
| 1512 | * heavy io in parallel with measurements. */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1513 | sync(); |
Denys Vlasenko | ec16c03 | 2020-11-29 11:37:34 +0100 | [diff] [blame] | 1514 | sleep1(); |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1515 | if (cache) { /* Time cache */ |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1516 | seek_to_zero(); |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1517 | read_big_block(buf); |
| 1518 | printf("Timing buffer-cache reads: "); |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1519 | } else { /* Time device */ |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1520 | printf("Timing buffered disk reads:"); |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1521 | } |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 1522 | fflush_all(); |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1523 | |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1524 | /* Now do the timing */ |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1525 | iterations = 0; |
Denis Vlasenko | a7bc9ac | 2007-09-28 11:21:47 +0000 | [diff] [blame] | 1526 | /* Max time to run (small for cache, avoids getting |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1527 | * huge total_MB which can overlow unsigned type) */ |
Denis Vlasenko | a7bc9ac | 2007-09-28 11:21:47 +0000 | [diff] [blame] | 1528 | elapsed2 = 510000; /* cache */ |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1529 | max_iterations = UINT_MAX; |
| 1530 | if (!cache) { |
Denis Vlasenko | a7bc9ac | 2007-09-28 11:21:47 +0000 | [diff] [blame] | 1531 | elapsed2 = 3000000; /* not cache */ |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1532 | /* Don't want to read past the end! */ |
| 1533 | max_iterations = dev_size_mb() / TIMING_BUF_MB; |
| 1534 | } |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1535 | start = monotonic_us(); |
Denis Vlasenko | 6963eb5 | 2007-05-22 21:46:11 +0000 | [diff] [blame] | 1536 | do { |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1537 | if (cache) |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1538 | seek_to_zero(); |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1539 | read_big_block(buf); |
| 1540 | elapsed = (unsigned)monotonic_us() - start; |
| 1541 | ++iterations; |
Denis Vlasenko | a7bc9ac | 2007-09-28 11:21:47 +0000 | [diff] [blame] | 1542 | } while (elapsed < elapsed2 && iterations < max_iterations); |
Denis Vlasenko | 920c52a | 2007-09-28 13:38:08 +0000 | [diff] [blame] | 1543 | total_MB = iterations * TIMING_BUF_MB; |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1544 | //printf(" elapsed:%u iterations:%u ", elapsed, iterations); |
| 1545 | if (cache) { |
Denis Vlasenko | a7bc9ac | 2007-09-28 11:21:47 +0000 | [diff] [blame] | 1546 | /* Cache: remove lseek() and monotonic_us() overheads |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1547 | * from elapsed */ |
| 1548 | start = monotonic_us(); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1549 | do { |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1550 | seek_to_zero(); |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1551 | elapsed2 = (unsigned)monotonic_us() - start; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1552 | } while (--iterations); |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1553 | //printf(" elapsed2:%u ", elapsed2); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1554 | elapsed -= elapsed2; |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1555 | total_MB *= 2; // BUFCACHE_FACTOR (why?) |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1556 | flush_buffer_cache(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1557 | } |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 1558 | print_timing(total_MB, elapsed); |
Rob Landley | 4ae2f51 | 2006-05-19 17:24:26 +0000 | [diff] [blame] | 1559 | munlock(buf, TIMING_BUF_BYTES); |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 1560 | free(buf); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1563 | #if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1564 | static void bus_state_value(unsigned value) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1565 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1566 | if (value == BUSSTATE_ON) |
| 1567 | on_off(1); |
| 1568 | else if (value == BUSSTATE_OFF) |
| 1569 | on_off(0); |
| 1570 | else if (value == BUSSTATE_TRISTATE) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1571 | puts(" (tristate)"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1572 | else |
Denys Vlasenko | 327f550 | 2013-11-29 16:45:45 +0100 | [diff] [blame] | 1573 | printf(" (unknown: %u)\n", value); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1574 | } |
| 1575 | #endif |
| 1576 | |
| 1577 | #ifdef HDIO_DRIVE_CMD |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1578 | static void interpret_standby(uint8_t standby) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1579 | { |
Rob Landley | 403777f | 2006-08-03 20:22:37 +0000 | [diff] [blame] | 1580 | printf(" ("); |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1581 | if (standby == 0) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1582 | printf("off"); |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1583 | } else if (standby <= 240 || standby == 252 || standby == 255) { |
| 1584 | /* standby is in 5 sec units */ |
Denys Vlasenko | 2b132e5 | 2009-05-20 23:21:42 +0200 | [diff] [blame] | 1585 | unsigned t = standby * 5; |
| 1586 | printf("%u minutes %u seconds", t / 60, t % 60); |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1587 | } else if (standby <= 251) { |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1588 | unsigned t = (standby - 240); /* t is in 30 min units */; |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1589 | printf("%u.%c hours", t / 2, (t & 1) ? '5' : '0'); |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1590 | } |
| 1591 | if (standby == 253) |
| 1592 | printf("vendor-specific"); |
| 1593 | if (standby == 254) |
| 1594 | printf("reserved"); |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1595 | puts(")"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1598 | static const uint8_t xfermode_val[] ALIGN1 = { |
| 1599 | 8, 9, 10, 11, 12, 13, 14, 15, |
| 1600 | 16, 17, 18, 19, 20, 21, 22, 23, |
| 1601 | 32, 33, 34, 35, 36, 37, 38, 39, |
| 1602 | 64, 65, 66, 67, 68, 69, 70, 71 |
| 1603 | }; |
| 1604 | /* NB: we save size by _not_ storing terninating NUL! */ |
| 1605 | static const char xfermode_name[][5] ALIGN1 = { |
| 1606 | "pio0", "pio1", "pio2", "pio3", "pio4", "pio5", "pio6", "pio7", |
| 1607 | "sdma0","sdma1","sdma2","sdma3","sdma4","sdma5","sdma6","sdma7", |
| 1608 | "mdma0","mdma1","mdma2","mdma3","mdma4","mdma5","mdma6","mdma7", |
| 1609 | "udma0","udma1","udma2","udma3","udma4","udma5","udma6","udma7" |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1610 | }; |
| 1611 | |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1612 | static int translate_xfermode(const char *name) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1613 | { |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 1614 | int val; |
| 1615 | unsigned i; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1616 | |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1617 | for (i = 0; i < ARRAY_SIZE(xfermode_val); i++) { |
| 1618 | if (!strncmp(name, xfermode_name[i], 5)) |
| 1619 | if (strlen(name) <= 5) |
| 1620 | return xfermode_val[i]; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1621 | } |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1622 | /* Negative numbers are invalid and are caught later */ |
| 1623 | val = bb_strtoi(name, NULL, 10); |
| 1624 | if (!errno) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1625 | return val; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1626 | return -1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1629 | static void interpret_xfermode(unsigned xfermode) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1630 | { |
| 1631 | printf(" ("); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1632 | if (xfermode == 0) |
| 1633 | printf("default PIO mode"); |
| 1634 | else if (xfermode == 1) |
| 1635 | printf("default PIO mode, disable IORDY"); |
| 1636 | else if (xfermode >= 8 && xfermode <= 15) |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1637 | printf("PIO flow control mode%u", xfermode - 8); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1638 | else if (xfermode >= 16 && xfermode <= 23) |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1639 | printf("singleword DMA mode%u", xfermode - 16); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1640 | else if (xfermode >= 32 && xfermode <= 39) |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1641 | printf("multiword DMA mode%u", xfermode - 32); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1642 | else if (xfermode >= 64 && xfermode <= 71) |
Denis Vlasenko | a0319ba | 2007-08-16 10:37:49 +0000 | [diff] [blame] | 1643 | printf("UltraDMA mode%u", xfermode - 64); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1644 | else |
Denis Vlasenko | 9130340 | 2007-10-30 19:36:54 +0000 | [diff] [blame] | 1645 | printf("unknown"); |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1646 | puts(")"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1647 | } |
| 1648 | #endif /* HDIO_DRIVE_CMD */ |
| 1649 | |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1650 | static void print_flag(int flag, const char *s, unsigned long value) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1651 | { |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 1652 | if (flag) |
Denys Vlasenko | 327f550 | 2013-11-29 16:45:45 +0100 | [diff] [blame] | 1653 | printf(" setting %s to %lu\n", s, value); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1656 | static void process_dev(char *devname) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1657 | { |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1658 | /*int fd;*/ |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1659 | long parm, multcount; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1660 | #ifndef HDIO_DRIVE_CMD |
| 1661 | int force_operation = 0; |
| 1662 | #endif |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1663 | /* Please restore args[n] to these values after each ioctl |
| 1664 | except for args[2] */ |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 1665 | unsigned char args[4] = { WIN_SETFEATURES, 0, 0, 0 }; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1666 | const char *fmt = " %s\t= %2ld"; |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1667 | |
Bernhard Reutner-Fischer | a483087 | 2009-10-26 23:27:08 +0100 | [diff] [blame] | 1668 | /*fd = xopen_nonblocking(devname);*/ |
| 1669 | xmove_fd(xopen_nonblocking(devname), fd); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1670 | printf("\n%s:\n", devname); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1671 | |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1672 | if (getset_readahead == IS_SET) { |
| 1673 | print_flag(getset_readahead, "fs readahead", Xreadahead); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1674 | ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1675 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1676 | #if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
| 1677 | if (unregister_hwif) { |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1678 | printf(" attempting to unregister hwif#%lu\n", hwif); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1679 | ioctl_or_warn(fd, HDIO_UNREGISTER_HWIF, (int *)(unsigned long)hwif); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1680 | } |
| 1681 | #endif |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1682 | #if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1683 | if (scan_hwif == IS_SET) { |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1684 | printf(" attempting to scan hwif (0x%lx, 0x%lx, %lu)\n", hwif_data, hwif_ctrl, hwif_irq); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1685 | args[0] = hwif_data; |
| 1686 | args[1] = hwif_ctrl; |
| 1687 | args[2] = hwif_irq; |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1688 | ioctl_or_warn(fd, HDIO_SCAN_HWIF, args); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1689 | args[0] = WIN_SETFEATURES; |
| 1690 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1691 | } |
| 1692 | #endif |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1693 | if (set_piomode) { |
| 1694 | if (noisy_piomode) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1695 | printf(" attempting to "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1696 | if (piomode == 255) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1697 | puts("auto-tune PIO mode"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1698 | else if (piomode < 100) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1699 | printf("set PIO mode to %d\n", piomode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1700 | else if (piomode < 200) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1701 | printf("set MDMA mode to %d\n", (piomode-100)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1702 | else |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1703 | printf("set UDMA mode to %d\n", (piomode-200)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1704 | } |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1705 | ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1706 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1707 | if (getset_io32bit == IS_SET) { |
| 1708 | print_flag(getset_io32bit, "32-bit IO_support flag", io32bit); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1709 | ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1710 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1711 | if (getset_mult == IS_SET) { |
| 1712 | print_flag(getset_mult, "multcount", mult); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1713 | #ifdef HDIO_DRIVE_CMD |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1714 | ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1715 | #else |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1716 | force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1717 | #endif |
| 1718 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1719 | if (getset_readonly == IS_SET) { |
| 1720 | print_flag_on_off(getset_readonly, "readonly", readonly); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1721 | ioctl_or_warn(fd, BLKROSET, &readonly); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1722 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1723 | if (getset_unmask == IS_SET) { |
| 1724 | print_flag_on_off(getset_unmask, "unmaskirq", unmask); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1725 | ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1726 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1727 | #if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1728 | if (getset_dma == IS_SET) { |
| 1729 | print_flag_on_off(getset_dma, "using_dma", dma); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1730 | ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1731 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1732 | #endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */ |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1733 | #ifdef HDIO_SET_QDMA |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1734 | if (getset_dma_q == IS_SET) { |
| 1735 | print_flag_on_off(getset_dma_q, "DMA queue_depth", dma_q); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1736 | ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1737 | } |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1738 | #endif |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1739 | if (getset_nowerr == IS_SET) { |
| 1740 | print_flag_on_off(getset_nowerr, "nowerr", nowerr); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1741 | ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1742 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1743 | if (getset_keep == IS_SET) { |
| 1744 | print_flag_on_off(getset_keep, "keep_settings", keep); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1745 | ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1746 | } |
| 1747 | #ifdef HDIO_DRIVE_CMD |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1748 | if (getset_doorlock == IS_SET) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1749 | args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1750 | args[2] = 0; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1751 | print_flag_on_off(getset_doorlock, "drive doorlock", doorlock); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1752 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1753 | args[0] = WIN_SETFEATURES; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1754 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1755 | if (getset_dkeep == IS_SET) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1756 | /* lock/unlock the drive's "feature" settings */ |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1757 | print_flag_on_off(getset_dkeep, "drive keep features", dkeep); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1758 | args[2] = dkeep ? 0x66 : 0xcc; |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1759 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1760 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1761 | if (getset_defects == IS_SET) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1762 | args[2] = defects ? 0x04 : 0x84; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1763 | print_flag(getset_defects, "drive defect-mgmt", defects); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1764 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1765 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1766 | if (getset_prefetch == IS_SET) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1767 | args[1] = prefetch; |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1768 | args[2] = 0xab; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1769 | print_flag(getset_prefetch, "drive prefetch", prefetch); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1770 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1771 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1772 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1773 | if (set_xfermode) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1774 | args[1] = xfermode_requested; |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1775 | args[2] = 3; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1776 | print_flag(1, "xfermode", xfermode_requested); |
| 1777 | interpret_xfermode(xfermode_requested); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1778 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1779 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1780 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1781 | if (getset_lookahead == IS_SET) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1782 | args[2] = lookahead ? 0xaa : 0x55; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1783 | print_flag_on_off(getset_lookahead, "drive read-lookahead", lookahead); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1784 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1785 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1786 | if (getset_apmmode == IS_SET) { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1787 | /* feature register */ |
| 1788 | args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1789 | args[1] = apmmode; /* sector count register 1-255 */ |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1790 | printf(" setting APM level to %s 0x%02lX (%ld)\n", |
| 1791 | (apmmode == 255) ? "disabled" : "", |
| 1792 | apmmode, apmmode); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1793 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1794 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1795 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1796 | if (getset_wcache == IS_SET) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1797 | #ifdef DO_FLUSHCACHE |
| 1798 | #ifndef WIN_FLUSHCACHE |
| 1799 | #define WIN_FLUSHCACHE 0xe7 |
| 1800 | #endif |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1801 | #endif /* DO_FLUSHCACHE */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1802 | args[2] = wcache ? 0x02 : 0x82; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1803 | print_flag_on_off(getset_wcache, "drive write-caching", wcache); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1804 | #ifdef DO_FLUSHCACHE |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1805 | if (!wcache) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1806 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1807 | #endif /* DO_FLUSHCACHE */ |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1808 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1809 | #ifdef DO_FLUSHCACHE |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1810 | if (!wcache) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1811 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1812 | #endif /* DO_FLUSHCACHE */ |
| 1813 | } |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1814 | |
| 1815 | /* In code below, we do not preserve args[0], but the rest |
| 1816 | is preserved, including args[2] */ |
| 1817 | args[2] = 0; |
| 1818 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1819 | if (set_standbynow) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1820 | #ifndef WIN_STANDBYNOW1 |
| 1821 | #define WIN_STANDBYNOW1 0xE0 |
| 1822 | #endif |
| 1823 | #ifndef WIN_STANDBYNOW2 |
| 1824 | #define WIN_STANDBYNOW2 0x94 |
| 1825 | #endif |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1826 | puts(" issuing standby command"); |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1827 | args[0] = WIN_STANDBYNOW1; |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1828 | ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1829 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1830 | if (set_sleepnow) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1831 | #ifndef WIN_SLEEPNOW1 |
| 1832 | #define WIN_SLEEPNOW1 0xE6 |
| 1833 | #endif |
| 1834 | #ifndef WIN_SLEEPNOW2 |
| 1835 | #define WIN_SLEEPNOW2 0x99 |
| 1836 | #endif |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1837 | puts(" issuing sleep command"); |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1838 | args[0] = WIN_SLEEPNOW1; |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1839 | ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1840 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1841 | if (set_seagate) { |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1842 | args[0] = 0xfb; |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1843 | puts(" disabling Seagate auto powersaving mode"); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1844 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1845 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1846 | if (getset_standby == IS_SET) { |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1847 | args[0] = WIN_SETIDLE1; |
| 1848 | args[1] = standby_requested; |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1849 | print_flag(1, "standby", standby_requested); |
| 1850 | interpret_standby(standby_requested); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1851 | ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1852 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1853 | } |
| 1854 | #else /* HDIO_DRIVE_CMD */ |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1855 | if (force_operation) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1856 | char buf[512]; |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1857 | flush_buffer_cache(); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1858 | if (-1 == read(fd, buf, sizeof(buf))) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 1859 | bb_simple_perror_msg("read of 512 bytes failed"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1860 | } |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 1861 | #endif /* HDIO_DRIVE_CMD */ |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1862 | if (getset_mult || get_identity) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1863 | multcount = -1; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1864 | if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) { |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1865 | /* To be coherent with ioctl_or_warn. */ |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1866 | if (getset_mult && ENABLE_IOCTL_HEX2STR_ERROR) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 1867 | bb_simple_perror_msg("HDIO_GET_MULTCOUNT"); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1868 | else |
| 1869 | bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1870 | } else if (getset_mult) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1871 | printf(fmt, "multcount", multcount); |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1872 | on_off(multcount != 0); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1873 | } |
| 1874 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1875 | if (getset_io32bit) { |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1876 | if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1877 | printf(" IO_support\t=%3ld (", parm); |
| 1878 | if (parm == 0) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1879 | puts("default 16-bit)"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1880 | else if (parm == 2) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1881 | puts("16-bit)"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1882 | else if (parm == 1) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1883 | puts("32-bit)"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1884 | else if (parm == 3) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1885 | puts("32-bit w/sync)"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1886 | else if (parm == 8) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1887 | puts("Request-Queue-Bypass)"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1888 | else |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1889 | puts("\?\?\?)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1890 | } |
| 1891 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1892 | if (getset_unmask) { |
Denis Vlasenko | d6855d1 | 2008-09-27 14:03:25 +0000 | [diff] [blame] | 1893 | if (!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm)) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1894 | print_value_on_off("unmaskirq", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1895 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1896 | #if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1897 | if (getset_dma) { |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1898 | if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1899 | printf(fmt, "using_dma", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1900 | if (parm == 8) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1901 | puts(" (DMA-Assisted-PIO)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1902 | else |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1903 | on_off(parm != 0); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1904 | } |
| 1905 | } |
| 1906 | #endif |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1907 | #ifdef HDIO_GET_QDMA |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1908 | if (getset_dma_q) { |
Denis Vlasenko | d6855d1 | 2008-09-27 14:03:25 +0000 | [diff] [blame] | 1909 | if (!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm)) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1910 | print_value_on_off("queue_depth", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1911 | } |
Denis Vlasenko | 3c96d02 | 2008-03-20 13:44:50 +0000 | [diff] [blame] | 1912 | #endif |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1913 | if (getset_keep) { |
Denis Vlasenko | d6855d1 | 2008-09-27 14:03:25 +0000 | [diff] [blame] | 1914 | if (!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm)) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1915 | print_value_on_off("keepsettings", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1916 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1917 | if (getset_nowerr) { |
Denis Vlasenko | d6855d1 | 2008-09-27 14:03:25 +0000 | [diff] [blame] | 1918 | if (!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm)) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1919 | print_value_on_off("nowerr", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1920 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1921 | if (getset_readonly) { |
Denis Vlasenko | d6855d1 | 2008-09-27 14:03:25 +0000 | [diff] [blame] | 1922 | if (!ioctl_or_warn(fd, BLKROGET, &parm)) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1923 | print_value_on_off("readonly", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1924 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 1925 | if (getset_readahead) { |
Denis Vlasenko | d6855d1 | 2008-09-27 14:03:25 +0000 | [diff] [blame] | 1926 | if (!ioctl_or_warn(fd, BLKRAGET, &parm)) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1927 | print_value_on_off("readahead", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1928 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1929 | if (get_geom) { |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1930 | if (!ioctl_or_warn(fd, BLKGETSIZE, &parm)) { |
Rob Landley | 2584e9b | 2006-05-03 20:00:00 +0000 | [diff] [blame] | 1931 | struct hd_geometry g; |
| 1932 | |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1933 | if (!ioctl_or_warn(fd, HDIO_GETGEO, &g)) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1934 | printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", |
Denys Vlasenko | 6d335be | 2009-05-20 14:48:03 +0200 | [diff] [blame] | 1935 | g.cylinders, g.heads, g.sectors, parm, g.start); |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1936 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1937 | } |
| 1938 | #ifdef HDIO_DRIVE_CMD |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1939 | if (get_powermode) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1940 | #ifndef WIN_CHECKPOWERMODE1 |
| 1941 | #define WIN_CHECKPOWERMODE1 0xE5 |
| 1942 | #endif |
| 1943 | #ifndef WIN_CHECKPOWERMODE2 |
| 1944 | #define WIN_CHECKPOWERMODE2 0x98 |
| 1945 | #endif |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1946 | const char *state; |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1947 | |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1948 | args[0] = WIN_CHECKPOWERMODE1; |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1949 | if (ioctl_alt_or_warn(HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2)) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1950 | if (errno != EIO || args[0] != 0 || args[1] != 0) |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 1951 | state = "unknown"; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1952 | else |
| 1953 | state = "sleeping"; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1954 | } else |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1955 | state = (args[2] == 255) ? "active/idle" : "standby"; |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1956 | args[1] = args[2] = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1957 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1958 | printf(" drive state is: %s\n", state); |
| 1959 | } |
| 1960 | #endif |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1961 | #if ENABLE_FEATURE_HDPARM_HDIO_DRIVE_RESET |
| 1962 | if (perform_reset) { |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1963 | ioctl_or_warn(fd, HDIO_DRIVE_RESET, NULL); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1964 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1965 | #endif /* FEATURE_HDPARM_HDIO_DRIVE_RESET */ |
| 1966 | #if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
| 1967 | if (perform_tristate) { |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1968 | args[0] = 0; |
| 1969 | args[1] = tristate; |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1970 | ioctl_or_warn(fd, HDIO_TRISTATE_HWIF, &args); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1971 | } |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1972 | #endif /* FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ |
| 1973 | #if ENABLE_FEATURE_HDPARM_GET_IDENTITY |
| 1974 | if (get_identity) { |
Denis Vlasenko | 7c282a2 | 2007-03-28 00:14:54 +0000 | [diff] [blame] | 1975 | struct hd_driveid id; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1976 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1977 | if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) { |
| 1978 | if (multcount != -1) { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1979 | id.multsect = multcount; |
| 1980 | id.multsect_valid |= 1; |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1981 | } else |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1982 | id.multsect_valid &= ~1; |
| 1983 | dump_identity(&id); |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1984 | } else if (errno == -ENOMSG) |
Denys Vlasenko | d60752f | 2015-10-07 22:42:45 +0200 | [diff] [blame] | 1985 | puts(" no identification info available"); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1986 | else if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */ |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 1987 | bb_simple_perror_msg("HDIO_GET_IDENTITY"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1988 | else |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 1989 | bb_perror_msg("ioctl %#x failed", HDIO_GET_IDENTITY); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1990 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1991 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 1992 | if (get_IDentity) { |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1993 | unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1994 | |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1995 | memset(args1, 0, sizeof(args1)); |
| 1996 | args1[0] = WIN_IDENTIFY; |
| 1997 | args1[3] = 1; |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 1998 | if (!ioctl_alt_or_warn(HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY)) |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 1999 | identify((void *)(args1 + 4)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2000 | } |
| 2001 | #endif |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 2002 | #if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2003 | if (getset_busstate == IS_SET) { |
| 2004 | print_flag(1, "bus state", busstate); |
| 2005 | bus_state_value(busstate); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 2006 | ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2007 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2008 | if (getset_busstate) { |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 2009 | if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2010 | printf(fmt, "bus state", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2011 | bus_state_value(parm); |
| 2012 | } |
| 2013 | } |
| 2014 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2015 | if (reread_partn) |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 2016 | ioctl_or_warn(fd, BLKRRPART, NULL); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2017 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2018 | if (do_ctimings) |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 2019 | do_time(1 /*,fd*/); /* time cache */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2020 | if (do_timings) |
Denis Vlasenko | c3122bc | 2007-09-28 10:28:03 +0000 | [diff] [blame] | 2021 | do_time(0 /*,fd*/); /* time device */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2022 | if (do_flush) |
Denis Vlasenko | 892536f | 2007-09-27 10:23:34 +0000 | [diff] [blame] | 2023 | flush_buffer_cache(); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 2024 | close(fd); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 2027 | #if ENABLE_FEATURE_HDPARM_GET_IDENTITY |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 2028 | static int fromhex(unsigned char c) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2029 | { |
Denis Vlasenko | 3a34d0c | 2007-01-12 22:10:34 +0000 | [diff] [blame] | 2030 | if (isdigit(c)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2031 | return (c - '0'); |
Denis Vlasenko | 3a34d0c | 2007-01-12 22:10:34 +0000 | [diff] [blame] | 2032 | if (c >= 'a' && c <= 'f') |
| 2033 | return (c - ('a' - 10)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2034 | bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c); |
| 2035 | } |
| 2036 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 2037 | static void identify_from_stdin(void) NORETURN; |
Rob Landley | 0f0b645 | 2006-05-03 18:28:06 +0000 | [diff] [blame] | 2038 | static void identify_from_stdin(void) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2039 | { |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2040 | uint16_t sbuf[256]; |
Denis Vlasenko | 3a34d0c | 2007-01-12 22:10:34 +0000 | [diff] [blame] | 2041 | unsigned char buf[1280]; |
| 2042 | unsigned char *b = (unsigned char *)buf; |
| 2043 | int i; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2044 | |
Bernhard Reutner-Fischer | 5e25ddb | 2008-05-19 09:48:17 +0000 | [diff] [blame] | 2045 | xread(STDIN_FILENO, buf, 1280); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2046 | |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2047 | // Convert the newline-separated hex data into an identify block. |
| 2048 | |
Denis Vlasenko | 3bf0020 | 2007-02-18 13:36:04 +0000 | [diff] [blame] | 2049 | for (i = 0; i < 256; i++) { |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2050 | int j; |
Denis Vlasenko | bf0a201 | 2006-12-26 10:42:51 +0000 | [diff] [blame] | 2051 | for (j = 0; j < 4; j++) |
Denis Vlasenko | 3a34d0c | 2007-01-12 22:10:34 +0000 | [diff] [blame] | 2052 | sbuf[i] = (sbuf[i] << 4) + fromhex(*(b++)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2053 | } |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2054 | |
| 2055 | // Parse the data. |
| 2056 | |
Rob Landley | 6389ff1 | 2006-05-01 19:28:53 +0000 | [diff] [blame] | 2057 | identify(sbuf); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2058 | } |
Denis Vlasenko | 0d3c6af | 2007-09-28 10:25:32 +0000 | [diff] [blame] | 2059 | #else |
| 2060 | void identify_from_stdin(void); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2061 | #endif |
| 2062 | |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2063 | /* busybox specific stuff */ |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2064 | static int parse_opts(unsigned long *value, int min, int max) |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2065 | { |
Denis Vlasenko | 6429aab | 2006-09-23 12:22:11 +0000 | [diff] [blame] | 2066 | if (optarg) { |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 2067 | *value = xatol_range(optarg, min, max); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2068 | return IS_SET; |
Denis Vlasenko | 6429aab | 2006-09-23 12:22:11 +0000 | [diff] [blame] | 2069 | } |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2070 | return IS_GET; |
| 2071 | } |
| 2072 | static int parse_opts_0_max(unsigned long *value, int max) |
| 2073 | { |
| 2074 | return parse_opts(value, 0, max); |
| 2075 | } |
| 2076 | static int parse_opts_0_1(unsigned long *value) |
| 2077 | { |
| 2078 | return parse_opts(value, 0, 1); |
| 2079 | } |
| 2080 | static int parse_opts_0_INTMAX(unsigned long *value) |
| 2081 | { |
| 2082 | return parse_opts(value, 0, INT_MAX); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
Denis Vlasenko | 0eec4ab | 2007-03-28 01:00:45 +0000 | [diff] [blame] | 2085 | static void parse_xfermode(int flag, smallint *get, smallint *set, int *value) |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2086 | { |
| 2087 | if (flag) { |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2088 | *get = IS_GET; |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2089 | if (optarg) { |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 2090 | *value = translate_xfermode(optarg); |
| 2091 | *set = (*value > -1); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | |
Rob Landley | 0620841 | 2006-05-31 22:52:57 +0000 | [diff] [blame] | 2096 | /*------- getopt short options --------*/ |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 2097 | static const char hdparm_options[] ALIGN1 = |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 2098 | "gfu::n::p:r::m::c::k::a::B:tT" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 2099 | IF_FEATURE_HDPARM_GET_IDENTITY("iI") |
| 2100 | IF_FEATURE_HDPARM_HDIO_GETSET_DMA("d::") |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2101 | #ifdef HDIO_DRIVE_CMD |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 2102 | "S:D:P:X:K:A:L:W:CyYzZ" |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2103 | #endif |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 2104 | IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:") |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2105 | #ifdef HDIO_GET_QDMA |
| 2106 | #ifdef HDIO_SET_QDMA |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 2107 | "Q:" |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2108 | #else |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 2109 | "Q" |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2110 | #endif |
| 2111 | #endif |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 2112 | IF_FEATURE_HDPARM_HDIO_DRIVE_RESET("w") |
| 2113 | IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF("x::b:") |
| 2114 | IF_FEATURE_HDPARM_HDIO_SCAN_HWIF("R:"); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2115 | /*-------------------------------------*/ |
| 2116 | |
| 2117 | /* our main() routine: */ |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 2118 | int hdparm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2119 | int hdparm_main(int argc, char **argv) |
| 2120 | { |
| 2121 | int c; |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2122 | int flagcount = 0; |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2123 | |
Denys Vlasenko | 1671424 | 2011-09-21 01:59:15 +0200 | [diff] [blame] | 2124 | INIT_G(); |
| 2125 | |
Rob Landley | 0620841 | 2006-05-31 22:52:57 +0000 | [diff] [blame] | 2126 | while ((c = getopt(argc, argv, hdparm_options)) >= 0) { |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2127 | flagcount++; |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 2128 | IF_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I')); |
| 2129 | IF_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i')); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2130 | get_geom |= (c == 'g'); |
| 2131 | do_flush |= (c == 'f'); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2132 | if (c == 'u') getset_unmask = parse_opts_0_1(&unmask); |
| 2133 | IF_FEATURE_HDPARM_HDIO_GETSET_DMA( |
| 2134 | if (c == 'd') getset_dma = parse_opts_0_max(&dma, 9); |
| 2135 | ) |
| 2136 | if (c == 'n') getset_nowerr = parse_opts_0_1(&nowerr); |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 2137 | parse_xfermode((c == 'p'), &noisy_piomode, &set_piomode, &piomode); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2138 | if (c == 'r') getset_readonly = parse_opts_0_1(&readonly); |
| 2139 | if (c == 'm') getset_mult = parse_opts_0_INTMAX(&mult /*32*/); |
| 2140 | if (c == 'c') getset_io32bit = parse_opts_0_INTMAX(&io32bit /*8*/); |
| 2141 | if (c == 'k') getset_keep = parse_opts_0_1(&keep); |
| 2142 | if (c == 'a') getset_readahead = parse_opts_0_INTMAX(&Xreadahead); |
| 2143 | if (c == 'B') getset_apmmode = parse_opts(&apmmode, 1, 255); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2144 | do_flush |= do_timings |= (c == 't'); |
| 2145 | do_flush |= do_ctimings |= (c == 'T'); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2146 | #ifdef HDIO_DRIVE_CMD |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2147 | if (c == 'S') getset_standby = parse_opts_0_max(&standby_requested, 255); |
| 2148 | if (c == 'D') getset_defects = parse_opts_0_INTMAX(&defects); |
| 2149 | if (c == 'P') getset_prefetch = parse_opts_0_INTMAX(&prefetch); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2150 | parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2151 | if (c == 'K') getset_dkeep = parse_opts_0_1(&prefetch); |
| 2152 | if (c == 'A') getset_lookahead = parse_opts_0_1(&lookahead); |
| 2153 | if (c == 'L') getset_doorlock = parse_opts_0_1(&doorlock); |
| 2154 | if (c == 'W') getset_wcache = parse_opts_0_1(&wcache); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2155 | get_powermode |= (c == 'C'); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2156 | set_standbynow |= (c == 'y'); |
| 2157 | set_sleepnow |= (c == 'Y'); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2158 | reread_partn |= (c == 'z'); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2159 | set_seagate |= (c == 'Z'); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2160 | #endif |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2161 | IF_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF(if (c == 'U') unregister_hwif = parse_opts_0_INTMAX(&hwif)); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2162 | #ifdef HDIO_GET_QDMA |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2163 | if (c == 'Q') { |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2164 | getset_dma_q = parse_opts_0_INTMAX(&dma_q); |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2165 | } |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 2166 | #endif |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 2167 | IF_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r')); |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2168 | IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') perform_tristate = parse_opts_0_1(&tristate)); |
| 2169 | IF_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'b') getset_busstate = parse_opts_0_max(&busstate, 2)); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2170 | #if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
| 2171 | if (c == 'R') { |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2172 | scan_hwif = parse_opts_0_INTMAX(&hwif_data); |
Denys Vlasenko | 7783248 | 2010-08-12 14:14:45 +0200 | [diff] [blame] | 2173 | hwif_ctrl = xatoi_positive((argv[optind]) ? argv[optind] : ""); |
| 2174 | hwif_irq = xatoi_positive((argv[optind+1]) ? argv[optind+1] : ""); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2175 | /* Move past the 2 additional arguments */ |
| 2176 | argv += 2; |
| 2177 | argc -= 2; |
| 2178 | } |
| 2179 | #endif |
| 2180 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2181 | /* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */ |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 2182 | if (!flagcount) { |
Denys Vlasenko | c706845 | 2009-05-20 16:11:41 +0200 | [diff] [blame] | 2183 | getset_mult = getset_io32bit = getset_unmask = getset_keep = getset_readonly = getset_readahead = get_geom = IS_GET; |
| 2184 | IF_FEATURE_HDPARM_HDIO_GETSET_DMA(getset_dma = IS_GET); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2185 | } |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2186 | argv += optind; |
| 2187 | |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 2188 | if (!*argv) { |
Rob Landley | 6d8ce17 | 2006-06-07 21:22:42 +0000 | [diff] [blame] | 2189 | if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO)) |
| 2190 | identify_from_stdin(); /* EXIT */ |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 2191 | bb_show_usage(); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2192 | } |
| 2193 | |
Denis Vlasenko | f1ba749 | 2007-03-28 00:14:01 +0000 | [diff] [blame] | 2194 | do { |
| 2195 | process_dev(*argv++); |
| 2196 | } while (*argv); |
| 2197 | |
| 2198 | return EXIT_SUCCESS; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2199 | } |