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