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