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 | |
| 130 | #ifdef CONFIG_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 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 242 | #ifdef CONFIG_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 | |
| 329 | #ifdef CONFIG_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 |
| 416 | #ifdef CONFIG_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 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 462 | static void on_off(unsigned int value); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 463 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 464 | static void print_flag_on_off(unsigned long get_arg, const char *s, unsigned long arg) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 465 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 466 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 467 | if (get_arg) |
| 468 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 469 | printf(" setting %s to %ld", s, arg); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 470 | on_off(arg); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | 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] | 475 | const char * str) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 476 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 477 | if (ioctl(fd, request, &argp) != 0) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 478 | bb_perror_msg(" %s", string); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 479 | else |
| 480 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 481 | printf(" %s\t= %2ld", str, (unsigned long) argp); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 482 | on_off((unsigned long) argp); |
| 483 | } |
| 484 | } |
Eric Andersen | 416c242 | 2003-12-12 00:08:57 +0000 | [diff] [blame] | 485 | |
| 486 | #ifdef CONFIG_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 | |
| 489 | static void xprint_ascii(uint16_t *val ,int i, char * string, int n) |
| 490 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 491 | if (val[i]) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 492 | { |
| 493 | printf("\t%-20s",string); |
| 494 | print_ascii(&val[i], n); |
| 495 | } |
| 496 | } |
Eric Andersen | 416c242 | 2003-12-12 00:08:57 +0000 | [diff] [blame] | 497 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 498 | /* end of busybox specific stuff */ |
| 499 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 500 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 501 | static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode) |
| 502 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 503 | uint16_t ii; |
| 504 | uint8_t err_dma = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 505 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 506 | for (ii = 0; ii <= MODE_MAX; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 507 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 508 | if (mode_sel & 0x0001) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 509 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 510 | printf("*%cdma%u ",cc,ii); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 511 | if (*have_mode) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 512 | err_dma = 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 513 | *have_mode = 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 514 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 515 | else if (mode_sup & 0x0001) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 516 | printf("%cdma%u ",cc,ii); |
| 517 | |
| 518 | mode_sup >>=1; |
| 519 | mode_sel >>=1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 520 | } |
| 521 | return err_dma; |
| 522 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 523 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 524 | static void print_ascii(uint16_t *p, uint8_t length) { |
| 525 | uint8_t ii; |
| 526 | char cl; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 527 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 528 | /* find first non-space & print it */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 529 | for (ii = 0; ii< length; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 530 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 531 | if (((char) 0x00ff&((*p)>>8)) != ' ') |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 532 | break; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 533 | if ((cl = (char) 0x00ff&(*p)) != ' ') |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 534 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 535 | if (cl != '\0') printf("%c",cl); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 536 | p++; |
| 537 | ii++; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 538 | break; |
| 539 | } |
| 540 | p++; |
| 541 | } |
| 542 | /* print the rest */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 543 | for (; ii< length; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 544 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 545 | if (!(*p)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 546 | break; /* some older devices have NULLs */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 547 | printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff); |
| 548 | p++; |
| 549 | } |
| 550 | printf("\n"); |
| 551 | } |
| 552 | |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 553 | // Parse 512 byte disk identification block and print much crap. |
| 554 | |
Rob Landley | 6389ff1 | 2006-05-01 19:28:53 +0000 | [diff] [blame] | 555 | static void identify(uint16_t *id_supplied) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 556 | { |
Rob Landley | 5bc3f05 | 2006-04-29 19:11:24 +0000 | [diff] [blame] | 557 | uint16_t buf[256]; |
| 558 | uint16_t *val, ii, jj, kk; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 559 | uint16_t like_std = 1, std = 0, min_std = 0xffff; |
| 560 | uint16_t dev = NO_DEV, eqpt = NO_DEV; |
| 561 | uint8_t have_mode = 0, err_dma = 0; |
| 562 | uint8_t chksum = 0; |
| 563 | uint32_t ll, mm, nn, oo; |
Rob Landley | 2e2d752 | 2006-04-29 15:23:33 +0000 | [diff] [blame] | 564 | uint64_t bbbig; /* (:) */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 565 | const char *strng; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 566 | |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 567 | // Adjust for endianness if necessary. |
| 568 | |
Rob Landley | 5bc3f05 | 2006-04-29 19:11:24 +0000 | [diff] [blame] | 569 | if (BB_BIG_ENDIAN) { |
| 570 | swab(id_supplied, buf, sizeof(buf)); |
| 571 | val = buf; |
| 572 | } else val = id_supplied; |
| 573 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 574 | chksum &= 0xff; |
| 575 | |
| 576 | /* check if we recognise the device type */ |
| 577 | printf("\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 578 | if(!(val[GEN_CONFIG] & NOT_ATA)) |
| 579 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 580 | dev = ATA_DEV; |
| 581 | printf("ATA device, with "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 582 | } |
| 583 | else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL) |
| 584 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 585 | dev = ATA_DEV; |
| 586 | like_std = 4; |
| 587 | printf("CompactFlash ATA device, with "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 588 | } |
| 589 | else if(!(val[GEN_CONFIG] & NOT_ATAPI)) |
| 590 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 591 | dev = ATAPI_DEV; |
| 592 | eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT; |
| 593 | printf("ATAPI %s, with ", pkt_str[eqpt]); |
| 594 | like_std = 3; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 595 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 596 | else |
| 597 | /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/ |
| 598 | bb_error_msg_and_die("Unknown device type"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 599 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 600 | printf("%sremovable media\n", !(val[GEN_CONFIG] & MEDIA_REMOVABLE) ? "non-" : ""); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 601 | /* Info from the specific configuration word says whether or not the |
| 602 | * ID command completed correctly. It is only defined, however in |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 603 | * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 604 | * standards. Since the values allowed for this word are extremely |
| 605 | * specific, it should be safe to check it now, even though we don't |
| 606 | * know yet what standard this device is using. |
| 607 | */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 608 | if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) || |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 609 | (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) ) |
| 610 | { |
| 611 | like_std = 5; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 612 | if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)) |
| 613 | printf("powers-up in standby; SET FEATURES subcmd spins-up.\n"); |
| 614 | if(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)) |
| 615 | 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] | 616 | } |
| 617 | |
| 618 | /* output the model and serial numbers and the fw revision */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 619 | xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL); |
| 620 | xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL); |
| 621 | xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV); |
| 622 | xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA); |
| 623 | xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 624 | |
| 625 | /* major & minor standards version number (Note: these words were not |
| 626 | * defined until ATA-3 & the CDROM std uses different words.) */ |
| 627 | printf("Standards:"); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 628 | if (eqpt != CDROM) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 629 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 630 | if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 631 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 632 | if(like_std < 3) like_std = 3; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 633 | std = actual_ver[val[MINOR]]; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 634 | if(std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 635 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 636 | } |
| 637 | /* looks like when they up-issue the std, they obsolete one; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 638 | * thus, only the newest 4 issues need be supported. (That's |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 639 | * what "kk" and "min_std" are all about.) */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 640 | if (val[MAJOR] && (val[MAJOR] !=NOVAL_1)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 641 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 642 | printf("\n\tSupported: "); |
| 643 | jj = val[MAJOR] << 1; |
| 644 | kk = like_std >4 ? like_std-4: 0; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 645 | for (ii = 14; (ii >0)&&(ii>kk); ii--) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 646 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 647 | if (jj & 0x8000) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 648 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 649 | printf("%u ", ii); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 650 | if (like_std < ii) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 651 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 652 | like_std = ii; |
| 653 | kk = like_std >4 ? like_std-4: 0; |
| 654 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 655 | if(min_std > ii) min_std = ii; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 656 | } |
| 657 | jj <<= 1; |
| 658 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 659 | if(like_std < 3) like_std = 3; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 660 | } |
| 661 | /* Figure out what standard the device is using if it hasn't told |
| 662 | * us. If we know the std, check if the device is using any of |
| 663 | * the words from the next level up. It happens. |
| 664 | */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 665 | if(like_std < std) like_std = std; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 666 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 667 | if (((std == 5) || (!std && (like_std < 6))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 668 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 669 | (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) || |
| 670 | ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) && |
| 671 | ( val[CMDS_SUPP_2] & CMDS_W84) ) ) ) |
| 672 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 673 | like_std = 6; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 674 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 675 | else if (((std == 4) || (!std && (like_std < 5))) && |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 676 | ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) || |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 677 | (( val[HWRST_RSLT] & VALID) == VALID_VAL) || |
| 678 | ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 679 | (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) ) |
| 680 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 681 | like_std = 5; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 682 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 683 | else if (((std == 3) || (!std && (like_std < 4))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 684 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 685 | ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) || |
| 686 | (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) || |
| 687 | (( val[CAPAB_1] & VALID) == VALID_VAL) || |
| 688 | (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) || |
| 689 | (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) ) |
| 690 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 691 | like_std = 4; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 692 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 693 | else if (((std == 2) || (!std && (like_std < 3))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 694 | ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) ) |
| 695 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 696 | like_std = 3; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 697 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 698 | else if (((std == 1) || (!std && (like_std < 2))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 699 | ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) || |
| 700 | (val[WHATS_VALID] & OK_W64_70)) ) |
| 701 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 702 | like_std = 2; |
| 703 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 704 | if (!std) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 705 | printf("\n\tLikely used: %u\n",like_std); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 706 | else if (like_std > std) |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 707 | printf("& some of %u\n",like_std); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 708 | else |
| 709 | printf("\n"); |
| 710 | } |
| 711 | else |
| 712 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 713 | /* TBD: do CDROM stuff more thoroughly. For now... */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 714 | kk = 0; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 715 | if (val[CDR_MINOR] == 9) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 716 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 717 | kk = 1; |
| 718 | printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5"); |
| 719 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 720 | if (val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 721 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 722 | kk = 1; |
| 723 | printf("\n\tSupported: CD-ROM ATAPI"); |
| 724 | jj = val[CDR_MAJOR] >> 1; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 725 | for (ii = 1; ii <15; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 726 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 727 | if(jj & 0x0001) printf("-%u ", ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 728 | jj >>= 1; |
| 729 | } |
| 730 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 731 | printf("%s\n", (!kk) ? "\n\tLikely used CD-ROM ATAPI-1" : "" ); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 732 | /* the cdrom stuff is more like ATA-2 than anything else, so: */ |
| 733 | like_std = 2; |
| 734 | } |
| 735 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 736 | if (min_std == 0xffff) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 737 | min_std = like_std > 4 ? like_std - 3 : 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 738 | |
| 739 | printf("Configuration:\n"); |
| 740 | /* more info from the general configuration word */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 741 | if ((eqpt != CDROM) && (like_std == 1)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 742 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 743 | jj = val[GEN_CONFIG] >> 1; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 744 | for (ii = 1; ii < 15; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 745 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 746 | if(jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 747 | jj >>=1; |
| 748 | } |
| 749 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 750 | if (dev == ATAPI_DEV) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 751 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 752 | if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_3MS_VAL) |
| 753 | strng = "3ms"; |
| 754 | else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_INTR_VAL) |
| 755 | strng = "<=10ms with INTRQ"; |
| 756 | else if ((val[GEN_CONFIG] & DRQ_RESPONSE_TIME) == DRQ_50US_VAL) |
| 757 | strng ="50us"; |
| 758 | else |
| 759 | strng = "Unknown"; |
| 760 | printf("\tDRQ response: %s\n\tPacket size: ", strng); /* Data Request (DRQ) */ |
| 761 | |
| 762 | if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_12_VAL) |
| 763 | strng = "12 bytes"; |
| 764 | else if ((val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) == PKT_SIZE_16_VAL) |
| 765 | strng = "16 bytes"; |
| 766 | else |
| 767 | strng = "Unknown"; |
| 768 | puts(strng); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 769 | } |
| 770 | else |
| 771 | { |
| 772 | /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 773 | ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB]; |
| 774 | mm = 0; bbbig = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 775 | if ( (ll > 0x00FBFC10) && (!val[LCYLS])) |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 776 | printf("\tCHS addressing not supported\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 777 | else |
| 778 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 779 | jj = val[WHATS_VALID] & OK_W54_58; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 780 | 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", |
| 781 | val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0); |
| 782 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 783 | if ((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])) |
| 784 | 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] | 785 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 786 | if (jj) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 787 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 788 | mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 789 | if (like_std < 3) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 790 | { |
| 791 | /* check Endian of capacity bytes */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 792 | nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR]; |
| 793 | oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB]; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 794 | if (abs(mm - nn) > abs(oo - nn)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 795 | mm = oo; |
| 796 | } |
| 797 | printf("\tCHS current addressable sectors:%11u\n",mm); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 798 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 799 | } |
| 800 | /* LBA addressing */ |
| 801 | printf("\tLBA user addressable sectors:%11u\n",ll); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 802 | if ( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 803 | (val[CMDS_SUPP_1] & SUPPORT_48_BIT) ) |
| 804 | { |
Rob Landley | 2e2d752 | 2006-04-29 15:23:33 +0000 | [diff] [blame] | 805 | bbbig = (uint64_t)val[LBA_64_MSB] << 48 | |
| 806 | (uint64_t)val[LBA_48_MSB] << 32 | |
| 807 | (uint64_t)val[LBA_MID] << 16 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 808 | val[LBA_LSB] ; |
Rob Landley | 81dab2c | 2006-05-28 01:56:08 +0000 | [diff] [blame] | 809 | printf("\tLBA48 user addressable sectors:%11"PRIu64"\n",bbbig); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 810 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 811 | |
| 812 | if (!bbbig) |
Rob Landley | 2e2d752 | 2006-04-29 15:23:33 +0000 | [diff] [blame] | 813 | bbbig = (uint64_t)(ll>mm ? ll : mm); /* # 512 byte blocks */ |
Rob Landley | 81dab2c | 2006-05-28 01:56:08 +0000 | [diff] [blame] | 814 | printf("\tdevice size with M = 1024*1024: %11"PRIu64" MBytes\n",bbbig>>11); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 815 | bbbig = (bbbig<<9)/1000000; |
Rob Landley | 81dab2c | 2006-05-28 01:56:08 +0000 | [diff] [blame] | 816 | printf("\tdevice size with M = 1000*1000: %11"PRIu64" MBytes ",bbbig); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 817 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 818 | if (bbbig > 1000) |
Rob Landley | 81dab2c | 2006-05-28 01:56:08 +0000 | [diff] [blame] | 819 | printf("(%"PRIu64" GB)\n", bbbig/1000); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 820 | else |
| 821 | printf("\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /* hw support of commands (capabilities) */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 825 | printf("Capabilities:\n\t"); |
| 826 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 827 | if (dev == ATAPI_DEV) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 828 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 829 | if (eqpt != CDROM && (val[CAPAB_0] & CMD_Q_SUP)) printf("Cmd queuing, "); |
| 830 | if (val[CAPAB_0] & OVLP_SUP) printf("Cmd overlap, "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 831 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 832 | if (val[CAPAB_0] & LBA_SUP) printf("LBA, "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 833 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 834 | if (like_std != 1) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 835 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 836 | printf("IORDY%s(can%s be disabled)\n", |
| 837 | !(val[CAPAB_0] & IORDY_SUP) ? "(may be)" : "", |
| 838 | (val[CAPAB_0] & IORDY_OFF) ? "" :"not"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 839 | } |
| 840 | else |
| 841 | printf("no IORDY\n"); |
| 842 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 843 | if ((like_std == 1) && val[BUF_TYPE]) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 844 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 845 | printf("\tBuffer type: %04x: %s%s\n", val[BUF_TYPE], |
| 846 | (val[BUF_TYPE] < 2) ? "single port, single-sector" : "dual port, multi-sector", |
| 847 | (val[BUF_TYPE] > 2) ? " with read caching ability" : ""); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 848 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 849 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 850 | if ((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 851 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 852 | printf("\tBuffer size: %.1fkB\n",(float)val[BUFFER__SIZE]/2); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 853 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 854 | if ((min_std < 4) && (val[RW_LONG])) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 855 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 856 | printf("\tbytes avail on r/w long: %u\n",val[RW_LONG]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 857 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 858 | if ((eqpt != CDROM) && (like_std > 3)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 859 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 860 | printf("\tQueue depth: %u\n",(val[QUEUE_DEPTH] & DEPTH_BITS)+1); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 861 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 862 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 863 | if (dev == ATA_DEV) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 864 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 865 | if (like_std == 1) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 866 | printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":""); |
| 867 | else |
| 868 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 869 | 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] | 870 | if ((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 871 | printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no"); |
| 872 | else |
| 873 | printf("\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 874 | } |
| 875 | printf("\tR/W multiple sector transfer: "); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 876 | if ((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 877 | printf("not supported\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 878 | else |
| 879 | { |
| 880 | printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 881 | if (val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID) |
| 882 | printf("%u\n", val[SECTOR_XFER_CUR] & SECTOR_XFER); |
| 883 | else |
| 884 | printf("?\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 885 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 886 | if ((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 887 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 888 | /* We print out elsewhere whether the APM feature is enabled or |
| 889 | not. If it's not enabled, let's not repeat the info; just print |
| 890 | nothing here. */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 891 | printf("\tAdvancedPM level: "); |
| 892 | if ( (val[ADV_PWR] & 0xFF00) == 0x4000 ) |
| 893 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 894 | uint8_t apm_level = val[ADV_PWR] & 0x00FF; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 895 | printf("%u (0x%x)\n", apm_level, apm_level); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 896 | } |
| 897 | else |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 898 | printf("unknown setting (0x%04x)\n", val[ADV_PWR]); |
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 (like_std > 5 && val[ACOUSTIC]) { |
| 901 | printf("\tRecommended acoustic management value: %u, current value: %u\n", |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 902 | (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 903 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 904 | } |
| 905 | else |
| 906 | { |
| 907 | /* ATAPI */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 908 | if (eqpt != CDROM && (val[CAPAB_0] & SWRST_REQ)) |
| 909 | printf("\tATA sw reset required\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 910 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 911 | if (val[PKT_REL] || val[SVC_NBSY]) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 912 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 913 | printf("\tOverlap support:"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 914 | if (val[PKT_REL]) printf(" %uus to release bus.",val[PKT_REL]); |
| 915 | if (val[SVC_NBSY]) printf(" %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 916 | printf("\n"); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | /* DMA stuff. Check that only one DMA mode is selected. */ |
| 921 | printf("\tDMA: "); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 922 | if (!(val[CAPAB_0] & DMA_SUP)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 923 | printf("not supported\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 924 | else |
| 925 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 926 | if (val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]) |
| 927 | printf(" sdma%u\n",(val[DMA_MODE] & MODE) >> 8); |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 928 | if (val[SINGLE_DMA]) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 929 | { |
| 930 | jj = val[SINGLE_DMA]; |
| 931 | kk = val[SINGLE_DMA] >> 8; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 932 | err_dma += mode_loop(jj,kk,'s',&have_mode); |
| 933 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 934 | if (val[MULTI_DMA]) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 935 | { |
| 936 | jj = val[MULTI_DMA]; |
| 937 | kk = val[MULTI_DMA] >> 8; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 938 | err_dma += mode_loop(jj,kk,'m',&have_mode); |
| 939 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 940 | if ((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 941 | { |
| 942 | jj = val[ULTRA_DMA]; |
| 943 | kk = val[ULTRA_DMA] >> 8; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 944 | err_dma += mode_loop(jj,kk,'u',&have_mode); |
| 945 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 946 | if (err_dma || !have_mode) printf("(?)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 947 | printf("\n"); |
| 948 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 949 | if ((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)) |
| 950 | printf("\t\tInterleaved DMA support\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 951 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 952 | if ((val[WHATS_VALID] & OK_W64_70) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 953 | (val[DMA_TIME_MIN] || val[DMA_TIME_NORM])) |
| 954 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 955 | printf("\t\tCycle time:"); |
| 956 | if (val[DMA_TIME_MIN]) printf(" min=%uns",val[DMA_TIME_MIN]); |
| 957 | if (val[DMA_TIME_NORM]) printf(" recommended=%uns",val[DMA_TIME_NORM]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 958 | printf("\n"); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | /* Programmed IO stuff */ |
| 963 | printf("\tPIO: "); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 964 | /* 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] | 965 | * than n (e.g. 3, 2, 1 and 0). Print all the modes. */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 966 | if ((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 967 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 968 | jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 969 | for (ii = 0; ii <= PIO_MODE_MAX ; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 970 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 971 | if (jj & 0x0001) printf("pio%d ",ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 972 | jj >>=1; |
| 973 | } |
| 974 | printf("\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 975 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 976 | else if (((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) ) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 977 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 978 | for (ii = 0; ii <= val[PIO_MODE]>>8; ii++) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 979 | printf("pio%d ",ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 980 | printf("\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 981 | } |
| 982 | else |
| 983 | printf("unknown\n"); |
| 984 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 985 | if (val[WHATS_VALID] & OK_W64_70) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 986 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 987 | if (val[PIO_NO_FLOW] || val[PIO_FLOW]) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 988 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 989 | printf("\t\tCycle time:"); |
| 990 | if (val[PIO_NO_FLOW]) printf(" no flow control=%uns", val[PIO_NO_FLOW]); |
| 991 | if (val[PIO_FLOW]) printf(" IORDY flow control=%uns", val[PIO_FLOW]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 992 | printf("\n"); |
| 993 | } |
| 994 | } |
| 995 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 996 | if ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 997 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 998 | printf("Commands/features:\n\tEnabled\tSupported:\n"); |
| 999 | jj = val[CMDS_SUPP_0]; |
| 1000 | kk = val[CMDS_EN_0]; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1001 | for (ii = 0; ii < NUM_CMD_FEAT_STR; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1002 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1003 | if ((jj & 0x8000) && (*cmd_feat_str[ii] != '\0')) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1004 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1005 | printf("\t%s\t%s\n", (kk & 0x8000) ? " *" : "", cmd_feat_str[ii]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1006 | } |
| 1007 | jj <<=1; kk<<=1; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1008 | if (ii%16 == 15) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1009 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1010 | jj = val[CMDS_SUPP_0+1+(ii/16)]; |
| 1011 | kk = val[CMDS_EN_0+1+(ii/16)]; |
| 1012 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1013 | if (ii == 31) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1014 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1015 | if ((val[CMDS_SUPP_2] & VALID) != VALID_VAL) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1016 | ii +=16; |
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 | /* Removable Media Status Notification feature set */ |
| 1021 | if((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) |
| 1022 | printf("\t%s supported\n", cmd_feat_str[27]); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1023 | |
| 1024 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1025 | /* security */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1026 | if ((eqpt != CDROM) && (like_std > 3) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1027 | (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME])) |
| 1028 | { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1029 | printf("Security:\n"); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1030 | if (val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)) |
| 1031 | printf("\tMaster password revision code = %u\n",val[PSWD_CODE]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1032 | jj = val[SECU_STATUS]; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1033 | if (jj) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1034 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1035 | for (ii = 0; ii < NUM_SECU_STR; ii++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1036 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1037 | printf("\t%s\t%s\n", (!(jj & 0x0001)) ? "not" : "", secu_str[ii]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1038 | jj >>=1; |
| 1039 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1040 | if (val[SECU_STATUS] & SECU_ENABLED) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1041 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1042 | printf("\tSecurity level %s\n", (val[SECU_STATUS] & SECU_LEVEL) ? "maximum" : "high"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | jj = val[ERASE_TIME] & ERASE_BITS; |
| 1046 | kk = val[ENH_ERASE_TIME] & ERASE_BITS; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1047 | if (jj || kk) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1048 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1049 | printf("\t"); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1050 | if (jj) printf("%umin for %sSECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1, ""); |
| 1051 | if (kk) printf("%umin for %sSECURITY ERASE UNIT. ", kk==ERASE_BITS ? 508 : kk<<1, "ENHANCED "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1052 | printf("\n"); |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /* reset result */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1057 | jj = val[HWRST_RSLT]; |
| 1058 | if ((jj & VALID) == VALID_VAL) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1059 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1060 | if (!(oo = (jj & RST0))) |
| 1061 | jj >>= 8; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1062 | if ((jj & DEV_DET) == JUMPER_VAL) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1063 | strng = " determined by the jumper"; |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1064 | else if ((jj & DEV_DET) == CSEL_VAL) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1065 | strng = " determined by CSEL"; |
| 1066 | else |
| 1067 | strng = ""; |
| 1068 | printf("HW reset results:\n\tCBLID- %s Vih\n\tDevice num = %i%s\n", |
| 1069 | (val[HWRST_RSLT] & CBLID) ? "above" : "below", !(oo), strng); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | /* more stuff from std 5 */ |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1073 | if ((like_std > 4) && (eqpt != CDROM)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1074 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1075 | if (val[CFA_PWR_MODE] & VALID_W160) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1076 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1077 | printf("CFA power mode 1:\n\t%s%s\n", (val[CFA_PWR_MODE] & PWR_MODE_OFF) ? "disabled" : "enabled", |
| 1078 | (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] | 1079 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1080 | if (val[CFA_PWR_MODE] & MAX_AMPS) printf("\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1081 | } |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1082 | if ((val[INTEGRITY] & SIG) == SIG_VAL) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1083 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1084 | printf("Checksum: %scorrect\n", chksum ? "in" : ""); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1088 | exit(EXIT_SUCCESS); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1089 | } |
| 1090 | #endif |
| 1091 | |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1092 | static int get_identity, get_geom; |
| 1093 | static int do_flush; |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1094 | static int do_ctimings, do_timings; |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1095 | static unsigned long set_readahead, get_readahead, Xreadahead; |
| 1096 | static unsigned long set_readonly, get_readonly, readonly; |
| 1097 | static unsigned long set_unmask, get_unmask, unmask; |
| 1098 | static unsigned long set_mult, get_mult, mult; |
Eric Andersen | f1c56a9 | 2003-08-08 22:13:41 +0000 | [diff] [blame] | 1099 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1100 | static unsigned long set_dma, get_dma, dma; |
Eric Andersen | f1c56a9 | 2003-08-08 22:13:41 +0000 | [diff] [blame] | 1101 | #endif |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1102 | static unsigned long set_dma_q, get_dma_q, dma_q; |
| 1103 | static unsigned long set_nowerr, get_nowerr, nowerr; |
| 1104 | static unsigned long set_keep, get_keep, keep; |
| 1105 | static unsigned long set_io32bit, get_io32bit, io32bit; |
| 1106 | static unsigned long set_piomode, noisy_piomode; |
| 1107 | static int piomode; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1108 | #ifdef HDIO_DRIVE_CMD |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1109 | static unsigned long set_dkeep, get_dkeep, dkeep; |
| 1110 | static unsigned long set_standby, get_standby, standby_requested; |
| 1111 | static unsigned long set_xfermode, get_xfermode; |
| 1112 | static int xfermode_requested; |
| 1113 | static unsigned long set_lookahead, get_lookahead, lookahead; |
| 1114 | static unsigned long set_prefetch, get_prefetch, prefetch; |
| 1115 | static unsigned long set_defects, get_defects, defects; |
| 1116 | static unsigned long set_wcache, get_wcache, wcache; |
| 1117 | static unsigned long set_doorlock, get_doorlock, doorlock; |
| 1118 | static unsigned long set_seagate, get_seagate; |
| 1119 | static unsigned long set_standbynow, get_standbynow; |
| 1120 | static unsigned long set_sleepnow, get_sleepnow; |
| 1121 | static unsigned long get_powermode; |
| 1122 | static unsigned long set_apmmode, get_apmmode, apmmode; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1123 | #endif |
| 1124 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1125 | static int get_IDentity; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1126 | #endif |
| 1127 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1128 | static unsigned long unregister_hwif; |
| 1129 | static unsigned long hwif; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1130 | #endif |
| 1131 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1132 | static unsigned long scan_hwif; |
| 1133 | static unsigned long hwif_data; |
| 1134 | static unsigned long hwif_ctrl; |
| 1135 | static unsigned long hwif_irq; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1136 | #endif |
| 1137 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1138 | static unsigned long set_busstate, get_busstate, busstate; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1139 | #endif |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1140 | static int reread_partn; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1141 | |
| 1142 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1143 | static int perform_reset; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1144 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ |
| 1145 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1146 | static unsigned long perform_tristate, tristate; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1147 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ |
| 1148 | |
| 1149 | // Historically, if there was no HDIO_OBSOLETE_IDENTITY, then |
| 1150 | // then the HDIO_GET_IDENTITY only returned 142 bytes. |
| 1151 | // Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes, |
| 1152 | // and HDIO_GET_IDENTITY returns 512 bytes. But the latest |
| 1153 | // 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY |
| 1154 | // (which they should, but they should just return -EINVAL). |
| 1155 | // |
| 1156 | // So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes. |
| 1157 | // On a really old system, it will not, and we will be confused. |
| 1158 | // Too bad, really. |
| 1159 | |
| 1160 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1161 | static const char * const cfg_str[] = |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1162 | { "", "HardSect", "SoftSect", "NotMFM", |
| 1163 | "HdSw>15uSec", "SpinMotCtl", "Fixed", "Removeable", |
| 1164 | "DTR<=5Mbs", "DTR>5Mbs", "DTR>10Mbs", "RotSpdTol>.5%", |
| 1165 | "dStbOff", "TrkOff", "FmtGapReq", "nonMagnetic" |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1166 | }; |
| 1167 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1168 | static const char * const BuffType[] = {"Unknown", "1Sect", "DualPort", "DualPortCache"}; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1169 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1170 | static void dump_identity(const struct hd_driveid *id) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1171 | { |
| 1172 | int i; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1173 | const unsigned short int *id_regs= (const void*) id; |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 1174 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1175 | printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={", |
| 1176 | id->model, id->fw_rev, id->serial_no); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1177 | for (i=0; i<=15; i++) { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1178 | if (id->config & (1<<i)) |
| 1179 | printf(" %s", cfg_str[i]); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1180 | } |
| 1181 | printf( " }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n" |
| 1182 | " BuffType=(%u) %s, BuffSize=%ukB, MaxMultSect=%u", |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1183 | id->cyls, id->heads, id->sectors, id->track_bytes, |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1184 | id->sector_bytes, id->ecc_bytes, |
| 1185 | id->buf_type, BuffType[(id->buf_type > 3) ? 0 : id->buf_type], |
| 1186 | id->buf_size/2, id->max_multsect); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1187 | if (id->max_multsect) |
| 1188 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1189 | printf(", MultSect="); |
| 1190 | if (!(id->multsect_valid&1)) |
| 1191 | printf("?%u?", id->multsect); |
| 1192 | else if (id->multsect) |
| 1193 | printf("%u", id->multsect); |
| 1194 | else |
| 1195 | printf("off"); |
| 1196 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1197 | printf("\n"); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1198 | |
| 1199 | if(!(id->field_valid&1)) |
| 1200 | printf(" (maybe):"); |
| 1201 | |
| 1202 | printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads, |
| 1203 | id->cur_sectors, |
| 1204 | (BB_BIG_ENDIAN) ? |
| 1205 | (long unsigned int)(id->cur_capacity0 << 16) | id->cur_capacity1 : |
| 1206 | (long unsigned int)(id->cur_capacity1 << 16) | id->cur_capacity0, |
| 1207 | ((id->capability&2) == 0) ? "no" : "yes"); |
| 1208 | |
| 1209 | if (id->capability&2) |
| 1210 | printf(", LBAsects=%u", id->lba_capacity); |
| 1211 | |
| 1212 | printf("\n IORDY=%s", (id->capability&8) ? (id->capability&4) ? "on/off" : "yes" : "no"); |
| 1213 | |
| 1214 | if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&2) |
| 1215 | printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy); |
| 1216 | |
| 1217 | if ((id->capability&1) && (id->field_valid&2)) |
| 1218 | printf(", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time); |
| 1219 | |
| 1220 | printf("\n PIO modes: "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1221 | if (id->tPIO <= 5) |
| 1222 | { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1223 | printf("pio0 "); |
| 1224 | if (id->tPIO >= 1) printf("pio1 "); |
| 1225 | if (id->tPIO >= 2) printf("pio2 "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1226 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1227 | if (id->field_valid&2) |
| 1228 | { |
| 1229 | if (id->eide_pio_modes & 1) printf("pio3 "); |
| 1230 | if (id->eide_pio_modes & 2) printf("pio4 "); |
| 1231 | if (id->eide_pio_modes &~3) printf("pio? "); |
| 1232 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1233 | if (id->capability&1) |
| 1234 | { |
| 1235 | if (id->dma_1word | id->dma_mword) |
| 1236 | { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1237 | printf("\n DMA modes: "); |
| 1238 | if (id->dma_1word & 0x100) printf("*"); |
| 1239 | if (id->dma_1word & 1) printf("sdma0 "); |
| 1240 | if (id->dma_1word & 0x200) printf("*"); |
| 1241 | if (id->dma_1word & 2) printf("sdma1 "); |
| 1242 | if (id->dma_1word & 0x400) printf("*"); |
| 1243 | if (id->dma_1word & 4) printf("sdma2 "); |
| 1244 | if (id->dma_1word & 0xf800) printf("*"); |
| 1245 | if (id->dma_1word & 0xf8) printf("sdma? "); |
| 1246 | if (id->dma_mword & 0x100) printf("*"); |
| 1247 | if (id->dma_mword & 1) printf("mdma0 "); |
| 1248 | if (id->dma_mword & 0x200) printf("*"); |
| 1249 | if (id->dma_mword & 2) printf("mdma1 "); |
| 1250 | if (id->dma_mword & 0x400) printf("*"); |
| 1251 | if (id->dma_mword & 4) printf("mdma2 "); |
| 1252 | if (id->dma_mword & 0xf800) printf("*"); |
| 1253 | if (id->dma_mword & 0xf8) printf("mdma? "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1256 | if (((id->capability&8) || (id->field_valid&2)) && id->field_valid&4) |
| 1257 | { |
| 1258 | printf("\n UDMA modes: "); |
| 1259 | if (id->dma_ultra & 0x100) printf("*"); |
| 1260 | if (id->dma_ultra & 0x001) printf("udma0 "); |
| 1261 | if (id->dma_ultra & 0x200) printf("*"); |
| 1262 | if (id->dma_ultra & 0x002) printf("udma1 "); |
| 1263 | if (id->dma_ultra & 0x400) printf("*"); |
| 1264 | if (id->dma_ultra & 0x004) printf("udma2 "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1265 | #ifdef __NEW_HD_DRIVE_ID |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1266 | if (id->hw_config & 0x2000) |
| 1267 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1268 | #else /* !__NEW_HD_DRIVE_ID */ |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1269 | if (id->word93 & 0x2000) |
| 1270 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1271 | #endif /* __NEW_HD_DRIVE_ID */ |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1272 | if (id->dma_ultra & 0x0800) printf("*"); |
| 1273 | if (id->dma_ultra & 0x0008) printf("udma3 "); |
| 1274 | if (id->dma_ultra & 0x1000) printf("*"); |
| 1275 | if (id->dma_ultra & 0x0010) printf("udma4 "); |
| 1276 | if (id->dma_ultra & 0x2000) printf("*"); |
| 1277 | if (id->dma_ultra & 0x0020) printf("udma5 "); |
| 1278 | if (id->dma_ultra & 0x4000) printf("*"); |
| 1279 | if (id->dma_ultra & 0x0040) printf("udma6 "); |
| 1280 | if (id->dma_ultra & 0x8000) printf("*"); |
| 1281 | if (id->dma_ultra & 0x0080) printf("udma7 "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1282 | } |
| 1283 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1284 | printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes"); |
| 1285 | if (id_regs[83] & 8) |
| 1286 | { |
| 1287 | if (!(id_regs[86]&8)) |
| 1288 | printf(": disabled (255)"); |
| 1289 | else if ((id_regs[91]&0xFF00)!=0x4000) |
| 1290 | printf(": unknown setting"); |
| 1291 | else |
| 1292 | printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF); |
| 1293 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1294 | if (id_regs[82]&0x20) |
| 1295 | printf(" WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1296 | #ifdef __NEW_HD_DRIVE_ID |
| 1297 | if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31)) |
| 1298 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1299 | 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] | 1300 | if (id->major_rev_num != 0x0000 && /* NOVAL_0 */ |
| 1301 | id->major_rev_num != 0xFFFF) { /* NOVAL_1 */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1302 | for (i=0; i <= 15; i++) { |
| 1303 | if (id->major_rev_num & (1<<i)) |
| 1304 | printf(" ATA/ATAPI-%u", i); |
| 1305 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1306 | } |
| 1307 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1308 | #endif /* __NEW_HD_DRIVE_ID */ |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1309 | printf("\n\n * current active mode\n\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1310 | } |
| 1311 | #endif |
| 1312 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1313 | static void flush_buffer_cache(int fd) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1314 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1315 | fsync(fd); /* flush buffers */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1316 | bb_ioctl(fd, BLKFLSBUF, NULL,"BLKFLSBUF" ) ;/* do it again, big time */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1317 | #ifdef HDIO_DRIVE_CMD |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1318 | sleep(1); |
| 1319 | if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1320 | bb_perror_msg("HDIO_DRIVE_CMD"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1321 | #endif |
| 1322 | } |
| 1323 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1324 | static int seek_to_zero(int fd) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1325 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1326 | if (lseek(fd, (off_t) 0, SEEK_SET)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1327 | return 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1328 | return 0; |
| 1329 | } |
| 1330 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1331 | static int read_big_block(int fd, char *buf) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1332 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1333 | int i; |
| 1334 | |
| 1335 | if ((i = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES) { |
| 1336 | 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] | 1337 | return 1; |
| 1338 | } |
| 1339 | /* access all sectors of buf to ensure the read fully completed */ |
| 1340 | for (i = 0; i < TIMING_BUF_BYTES; i += 512) |
| 1341 | buf[i] &= 1; |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1345 | static void print_timing(int t, double e) |
| 1346 | { |
| 1347 | if (t >= e) /* more than 1MB/s */ |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1348 | 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] | 1349 | else |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1350 | 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] | 1351 | } |
| 1352 | |
| 1353 | static int do_blkgetsize (int fd, unsigned long long *blksize64) |
| 1354 | { |
| 1355 | int rc; |
| 1356 | unsigned int blksize32 = 0; |
| 1357 | |
| 1358 | if (0 == ioctl(fd, BLKGETSIZE64, blksize64)) { // returns bytes |
| 1359 | *blksize64 /= 512; |
| 1360 | return 0; |
| 1361 | } |
| 1362 | rc = ioctl(fd, BLKGETSIZE, &blksize32); // returns sectors |
| 1363 | if (rc) |
| 1364 | bb_perror_msg("BLKGETSIZE"); |
| 1365 | *blksize64 = blksize32; |
| 1366 | return rc; |
| 1367 | } |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1368 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1369 | static void do_time(int flag, int fd) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1370 | /* |
| 1371 | flag = 0 time_cache |
| 1372 | flag = 1 time_device |
| 1373 | */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1374 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1375 | struct itimerval e1, e2; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1376 | double elapsed, elapsed2; |
| 1377 | unsigned int max_iterations = 1024, total_MB, iterations; |
| 1378 | unsigned long long blksize; |
Rob Landley | 4ae2f51 | 2006-05-19 17:24:26 +0000 | [diff] [blame] | 1379 | RESERVE_CONFIG_BUFFER(buf, TIMING_BUF_BYTES); |
| 1380 | |
| 1381 | if (mlock(buf, TIMING_BUF_BYTES)) { |
| 1382 | bb_perror_msg("mlock"); |
| 1383 | goto quit2; |
| 1384 | } |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1385 | |
| 1386 | if (0 == do_blkgetsize(fd, &blksize)) { |
| 1387 | max_iterations = blksize / (2 * 1024) / TIMING_BUF_MB; |
| 1388 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1389 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1390 | /* Clear out the device request queues & give them time to complete */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1391 | sync(); |
| 1392 | sleep(3); |
| 1393 | |
| 1394 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1395 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1396 | if (flag == 0) /* Time cache */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1397 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1398 | if (seek_to_zero (fd)) return; |
| 1399 | if (read_big_block (fd, buf)) return; |
| 1400 | printf(" Timing cached reads: "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1401 | fflush(stdout); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1402 | |
| 1403 | /* Now do the timing */ |
| 1404 | iterations = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1405 | getitimer(ITIMER_REAL, &e1); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1406 | do { |
| 1407 | ++iterations; |
| 1408 | if (seek_to_zero (fd) || read_big_block (fd, buf)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1409 | goto quit; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1410 | getitimer(ITIMER_REAL, &e2); |
| 1411 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1412 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
| 1413 | } while (elapsed < 2.0); |
| 1414 | total_MB = iterations * TIMING_BUF_MB; |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1415 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1416 | /* Now remove the lseek() and getitimer() overheads from the elapsed time */ |
| 1417 | getitimer(ITIMER_REAL, &e1); |
| 1418 | do { |
| 1419 | if (seek_to_zero (fd)) |
| 1420 | goto quit; |
| 1421 | getitimer(ITIMER_REAL, &e2); |
| 1422 | elapsed2 = (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1423 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
| 1424 | } while (--iterations); |
| 1425 | |
| 1426 | elapsed -= elapsed2; |
| 1427 | print_timing(BUFCACHE_FACTOR * total_MB, elapsed); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1428 | flush_buffer_cache(fd); |
| 1429 | sleep(1); |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1430 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1431 | else /* Time device */ |
| 1432 | { |
| 1433 | printf(" Timing buffered disk reads: "); |
| 1434 | fflush(stdout); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1435 | /* |
| 1436 | * getitimer() is used rather than gettimeofday() because |
| 1437 | * it is much more consistent (on my machine, at least). |
| 1438 | */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1439 | /* Now do the timings for real */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1440 | iterations = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1441 | getitimer(ITIMER_REAL, &e1); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1442 | do { |
| 1443 | ++iterations; |
| 1444 | if (read_big_block (fd, buf)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1445 | goto quit; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1446 | getitimer(ITIMER_REAL, &e2); |
| 1447 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1448 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
| 1449 | } while (elapsed < 3.0 && iterations < max_iterations); |
| 1450 | |
| 1451 | total_MB = iterations * TIMING_BUF_MB; |
| 1452 | print_timing(total_MB, elapsed); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1453 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1454 | quit: |
Rob Landley | 4ae2f51 | 2006-05-19 17:24:26 +0000 | [diff] [blame] | 1455 | munlock(buf, TIMING_BUF_BYTES); |
| 1456 | quit2: |
| 1457 | RELEASE_CONFIG_BUFFER(buf); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1460 | static void on_off (unsigned int value) |
| 1461 | { |
| 1462 | printf(value ? " (on)\n" : " (off)\n"); |
| 1463 | } |
| 1464 | |
| 1465 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1466 | static void bus_state_value(unsigned int value) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1467 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1468 | if (value == BUSSTATE_ON) |
| 1469 | on_off(1); |
| 1470 | else if (value == BUSSTATE_OFF) |
| 1471 | on_off(0); |
| 1472 | else if (value == BUSSTATE_TRISTATE) |
| 1473 | printf(" (tristate)\n"); |
| 1474 | else |
| 1475 | printf(" (unknown: %d)\n", value); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1476 | } |
| 1477 | #endif |
| 1478 | |
| 1479 | #ifdef HDIO_DRIVE_CMD |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1480 | static void interpret_standby(unsigned int standby) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1481 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1482 | unsigned int t; |
| 1483 | |
Rob Landley | 403777f | 2006-08-03 20:22:37 +0000 | [diff] [blame] | 1484 | printf(" ("); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1485 | if (standby == 0) |
| 1486 | printf("off"); |
| 1487 | else if (standby == 252) |
| 1488 | printf("21 minutes"); |
| 1489 | else if (standby == 253) |
| 1490 | printf("vendor-specific"); |
| 1491 | else if (standby == 254) |
| 1492 | printf("Reserved"); |
| 1493 | else if (standby == 255) |
| 1494 | printf("21 minutes + 15 seconds"); |
| 1495 | else { |
| 1496 | if (standby <= 240) { |
| 1497 | t = standby * 5; |
| 1498 | printf("%u minutes + %u seconds", t / 60, t % 60); |
| 1499 | } else if (standby <= 251) { |
| 1500 | t = (standby - 240) * 30; |
| 1501 | printf("%u hours + %u minutes", t / 60, t % 60); |
| 1502 | } else |
| 1503 | printf("illegal value"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1504 | } |
| 1505 | printf(")\n"); |
| 1506 | } |
| 1507 | |
| 1508 | struct xfermode_entry { |
| 1509 | int val; |
| 1510 | const char *name; |
| 1511 | }; |
| 1512 | |
| 1513 | static const struct xfermode_entry xfermode_table[] = { |
| 1514 | { 8, "pio0" }, |
| 1515 | { 9, "pio1" }, |
| 1516 | { 10, "pio2" }, |
| 1517 | { 11, "pio3" }, |
| 1518 | { 12, "pio4" }, |
| 1519 | { 13, "pio5" }, |
| 1520 | { 14, "pio6" }, |
| 1521 | { 15, "pio7" }, |
| 1522 | { 16, "sdma0" }, |
| 1523 | { 17, "sdma1" }, |
| 1524 | { 18, "sdma2" }, |
| 1525 | { 19, "sdma3" }, |
| 1526 | { 20, "sdma4" }, |
| 1527 | { 21, "sdma5" }, |
| 1528 | { 22, "sdma6" }, |
| 1529 | { 23, "sdma7" }, |
| 1530 | { 32, "mdma0" }, |
| 1531 | { 33, "mdma1" }, |
| 1532 | { 34, "mdma2" }, |
| 1533 | { 35, "mdma3" }, |
| 1534 | { 36, "mdma4" }, |
| 1535 | { 37, "mdma5" }, |
| 1536 | { 38, "mdma6" }, |
| 1537 | { 39, "mdma7" }, |
| 1538 | { 64, "udma0" }, |
| 1539 | { 65, "udma1" }, |
| 1540 | { 66, "udma2" }, |
| 1541 | { 67, "udma3" }, |
| 1542 | { 68, "udma4" }, |
| 1543 | { 69, "udma5" }, |
| 1544 | { 70, "udma6" }, |
| 1545 | { 71, "udma7" }, |
| 1546 | { 0, NULL } |
| 1547 | }; |
| 1548 | |
| 1549 | static int translate_xfermode(char * name) |
| 1550 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1551 | const struct xfermode_entry *tmp; |
| 1552 | char *endptr; |
| 1553 | int val = -1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1554 | |
| 1555 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1556 | for (tmp = xfermode_table; tmp->name != NULL; ++tmp) |
| 1557 | { |
| 1558 | if (!strcmp(name, tmp->name)) |
| 1559 | return tmp->val; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1560 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1561 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1562 | val = strtol(name, &endptr, 10); |
| 1563 | if (*endptr == '\0') |
| 1564 | return val; |
| 1565 | |
| 1566 | return -1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1569 | static void interpret_xfermode(unsigned int xfermode) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1570 | { |
| 1571 | printf(" ("); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1572 | if (xfermode == 0) |
| 1573 | printf("default PIO mode"); |
| 1574 | else if (xfermode == 1) |
| 1575 | printf("default PIO mode, disable IORDY"); |
| 1576 | else if (xfermode >= 8 && xfermode <= 15) |
| 1577 | printf("PIO flow control mode%u", xfermode-8); |
| 1578 | else if (xfermode >= 16 && xfermode <= 23) |
| 1579 | printf("singleword DMA mode%u", xfermode-16); |
| 1580 | else if (xfermode >= 32 && xfermode <= 39) |
| 1581 | printf("multiword DMA mode%u", xfermode-32); |
| 1582 | else if (xfermode >= 64 && xfermode <= 71) |
| 1583 | printf("UltraDMA mode%u", xfermode-64); |
| 1584 | else |
| 1585 | printf("Unknown"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1586 | printf(")\n"); |
| 1587 | } |
| 1588 | #endif /* HDIO_DRIVE_CMD */ |
| 1589 | |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1590 | static void print_flag(unsigned long flag, char *s, unsigned long value) |
| 1591 | { |
| 1592 | if(flag) |
| 1593 | printf(" setting %s to %ld\n", s, value); |
| 1594 | } |
| 1595 | |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1596 | static void process_dev(char *devname) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1597 | { |
| 1598 | int fd; |
| 1599 | static long parm, multcount; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1600 | #ifndef HDIO_DRIVE_CMD |
| 1601 | int force_operation = 0; |
| 1602 | #endif |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1603 | /* Please restore args[n] to these values after each ioctl |
| 1604 | except for args[2] */ |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1605 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1606 | const char *fmt = " %s\t= %2ld"; |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1607 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 1608 | fd = xopen(devname, O_RDONLY|O_NONBLOCK); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1609 | printf("\n%s:\n", devname); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1610 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1611 | if (set_readahead) |
| 1612 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1613 | print_flag(get_readahead,"fs readahead", Xreadahead); |
Eric Andersen | f828da0 | 2004-07-20 22:53:59 +0000 | [diff] [blame] | 1614 | bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1615 | } |
| 1616 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1617 | if (unregister_hwif) |
| 1618 | { |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1619 | printf(" attempting to unregister hwif#%lu\n", hwif); |
Eric Andersen | a68ea1c | 2006-01-30 22:48:39 +0000 | [diff] [blame] | 1620 | 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] | 1621 | } |
| 1622 | #endif |
| 1623 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1624 | if (scan_hwif) |
| 1625 | { |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 1626 | 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] | 1627 | args[0] = hwif_data; |
| 1628 | args[1] = hwif_ctrl; |
| 1629 | args[2] = hwif_irq; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1630 | bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF"); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1631 | args[0] = WIN_SETFEATURES; |
| 1632 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1633 | } |
| 1634 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1635 | if (set_piomode) |
| 1636 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1637 | if (noisy_piomode) |
| 1638 | { |
| 1639 | printf(" attempting to "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1640 | if (piomode == 255) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1641 | printf("auto-tune PIO mode\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1642 | else if (piomode < 100) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1643 | printf("set PIO mode to %d\n", piomode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1644 | else if (piomode < 200) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1645 | printf("set MDMA mode to %d\n", (piomode-100)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1646 | else |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1647 | printf("set UDMA mode to %d\n", (piomode-200)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1648 | } |
Eric Andersen | a68ea1c | 2006-01-30 22:48:39 +0000 | [diff] [blame] | 1649 | 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] | 1650 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1651 | if (set_io32bit) |
| 1652 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1653 | print_flag(get_io32bit,"32-bit IO_support flag", io32bit); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1654 | bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1655 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1656 | if (set_mult) |
| 1657 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1658 | print_flag(get_mult, "multcount", mult); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1659 | #ifdef HDIO_DRIVE_CMD |
| 1660 | bb_ioctl(fd, HDIO_SET_MULTCOUNT, &mult, "HDIO_SET_MULTCOUNT"); |
| 1661 | #else |
| 1662 | force_operation |= (!bb_ioctl(fd, HDIO_SET_MULTCOUNT, &mult, "HDIO_SET_MULTCOUNT")); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1663 | #endif |
| 1664 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1665 | if (set_readonly) |
| 1666 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1667 | print_flag_on_off(get_readonly,"readonly", readonly); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1668 | bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1669 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1670 | if (set_unmask) |
| 1671 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1672 | print_flag_on_off(get_unmask,"unmaskirq", unmask); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1673 | bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1674 | } |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 1675 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1676 | if (set_dma) |
| 1677 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1678 | print_flag_on_off(get_dma, "using_dma", dma); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1679 | bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1680 | } |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 1681 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1682 | if (set_dma_q) |
| 1683 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1684 | 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] | 1685 | bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1686 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1687 | if (set_nowerr) |
| 1688 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1689 | print_flag_on_off(get_nowerr,"nowerr", nowerr); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1690 | bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1691 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1692 | if (set_keep) |
| 1693 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1694 | print_flag_on_off(get_keep,"keep_settings", keep); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1695 | bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1696 | } |
| 1697 | #ifdef HDIO_DRIVE_CMD |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1698 | if (set_doorlock) |
| 1699 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1700 | args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1701 | args[2] = 0; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1702 | print_flag_on_off(get_doorlock,"drive doorlock", doorlock); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1703 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)"); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1704 | args[0] = WIN_SETFEATURES; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1705 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1706 | if (set_dkeep) |
| 1707 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1708 | /* lock/unlock the drive's "feature" settings */ |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1709 | print_flag_on_off(get_dkeep,"drive keep features", dkeep); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1710 | args[2] = dkeep ? 0x66 : 0xcc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1711 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1712 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1713 | if (set_defects) |
| 1714 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1715 | args[2] = defects ? 0x04 : 0x84; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1716 | print_flag(get_defects,"drive defect-mgmt", defects); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1717 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1718 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1719 | if (set_prefetch) |
| 1720 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1721 | args[1] = prefetch; |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1722 | args[2] = 0xab; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1723 | print_flag(get_prefetch,"drive prefetch", prefetch); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1724 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)"); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1725 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1726 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1727 | if (set_xfermode) |
| 1728 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1729 | args[1] = xfermode_requested; |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1730 | args[2] = 3; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1731 | if (get_xfermode) |
| 1732 | { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1733 | print_flag(1,"xfermode", xfermode_requested); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1734 | interpret_xfermode(xfermode_requested); |
| 1735 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1736 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)"); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1737 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1738 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1739 | if (set_lookahead) |
| 1740 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1741 | args[2] = lookahead ? 0xaa : 0x55; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1742 | print_flag_on_off(get_lookahead,"drive read-lookahead", lookahead); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1743 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1744 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1745 | if (set_apmmode) |
| 1746 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1747 | args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */ |
| 1748 | args[1] = apmmode; /* sector count register 1-255 */ |
| 1749 | if (get_apmmode) |
| 1750 | printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1751 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD"); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1752 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1753 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1754 | if (set_wcache) |
| 1755 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1756 | #ifdef DO_FLUSHCACHE |
| 1757 | #ifndef WIN_FLUSHCACHE |
| 1758 | #define WIN_FLUSHCACHE 0xe7 |
| 1759 | #endif |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1760 | static unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0}; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1761 | #endif /* DO_FLUSHCACHE */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1762 | args[2] = wcache ? 0x02 : 0x82; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1763 | print_flag_on_off(get_wcache,"drive write-caching", wcache); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1764 | #ifdef DO_FLUSHCACHE |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1765 | if (!wcache) |
| 1766 | bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1767 | #endif /* DO_FLUSHCACHE */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1768 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1769 | #ifdef DO_FLUSHCACHE |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1770 | if (!wcache) |
| 1771 | bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1772 | #endif /* DO_FLUSHCACHE */ |
| 1773 | } |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1774 | |
| 1775 | /* In code below, we do not preserve args[0], but the rest |
| 1776 | is preserved, including args[2] */ |
| 1777 | args[2] = 0; |
| 1778 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1779 | if (set_standbynow) |
| 1780 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1781 | #ifndef WIN_STANDBYNOW1 |
| 1782 | #define WIN_STANDBYNOW1 0xE0 |
| 1783 | #endif |
| 1784 | #ifndef WIN_STANDBYNOW2 |
| 1785 | #define WIN_STANDBYNOW2 0x94 |
| 1786 | #endif |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1787 | if (get_standbynow) printf(" issuing standby command\n"); |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1788 | args[0] = WIN_STANDBYNOW1; |
| 1789 | 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] | 1790 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1791 | if (set_sleepnow) |
| 1792 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1793 | #ifndef WIN_SLEEPNOW1 |
| 1794 | #define WIN_SLEEPNOW1 0xE6 |
| 1795 | #endif |
| 1796 | #ifndef WIN_SLEEPNOW2 |
| 1797 | #define WIN_SLEEPNOW2 0x99 |
| 1798 | #endif |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1799 | if (get_sleepnow) printf(" issuing sleep command\n"); |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1800 | args[0] = WIN_SLEEPNOW1; |
| 1801 | 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] | 1802 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1803 | if (set_seagate) |
| 1804 | { |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1805 | args[0] = 0xfb; |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1806 | if (get_seagate) printf(" disabling Seagate auto powersaving mode\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1807 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1808 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1809 | if (set_standby) |
| 1810 | { |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1811 | args[0] = WIN_SETIDLE1; |
| 1812 | args[1] = standby_requested; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1813 | if (get_standby) |
| 1814 | { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1815 | print_flag(1,"standby", standby_requested); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1816 | interpret_standby(standby_requested); |
| 1817 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1818 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)"); |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1819 | args[1] = 0; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1820 | } |
| 1821 | #else /* HDIO_DRIVE_CMD */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1822 | if (force_operation) |
| 1823 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1824 | char buf[512]; |
| 1825 | flush_buffer_cache(fd); |
| 1826 | if (-1 == read(fd, buf, sizeof(buf))) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1827 | bb_perror_msg("read(%d bytes) failed (rc=%d)", sizeof(buf), -1); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1828 | } |
| 1829 | #endif /* HDIO_DRIVE_CMD */ |
| 1830 | |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1831 | if (get_mult || get_identity) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1832 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1833 | multcount = -1; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1834 | if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) |
| 1835 | { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1836 | if (get_mult) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 1837 | bb_perror_msg("HDIO_GET_MULTCOUNT"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1838 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1839 | else if (get_mult) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1840 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1841 | printf(fmt, "multcount", multcount); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1842 | on_off(multcount); |
| 1843 | } |
| 1844 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1845 | if (get_io32bit) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1846 | { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1847 | if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT")) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1848 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1849 | printf(" IO_support\t=%3ld (", parm); |
| 1850 | if (parm == 0) |
| 1851 | printf("default 16-bit)\n"); |
| 1852 | else if (parm == 2) |
| 1853 | printf("16-bit)\n"); |
| 1854 | else if (parm == 1) |
| 1855 | printf("32-bit)\n"); |
| 1856 | else if (parm == 3) |
| 1857 | printf("32-bit w/sync)\n"); |
| 1858 | else if (parm == 8) |
| 1859 | printf("Request-Queue-Bypass)\n"); |
| 1860 | else |
| 1861 | printf("\?\?\?)\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1862 | } |
| 1863 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1864 | if (get_unmask) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1865 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1866 | bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm, |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1867 | "HDIO_GET_UNMASKINTR","unmaskirq"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1868 | } |
| 1869 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1870 | |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 1871 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1872 | if (get_dma) { |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 1873 | if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA")) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1874 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1875 | printf(fmt, "using_dma", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1876 | if (parm == 8) |
| 1877 | printf(" (DMA-Assisted-PIO)\n"); |
| 1878 | else |
| 1879 | on_off(parm); |
| 1880 | } |
| 1881 | } |
| 1882 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1883 | if (get_dma_q) |
| 1884 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1885 | bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm, |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1886 | "HDIO_GET_QDMA","queue_depth"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1887 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1888 | if (get_keep) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1889 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1890 | bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm, |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1891 | "HDIO_GET_KEEPSETTINGS","keepsettings"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1894 | if (get_nowerr) |
| 1895 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1896 | bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm, |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1897 | "HDIO_GET_NOWERR","nowerr"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1898 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1899 | if (get_readonly) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1900 | { |
| 1901 | bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm, |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1902 | "BLKROGET","readonly"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1903 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1904 | if (get_readahead) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1905 | { |
| 1906 | bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm, |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1907 | "BLKRAGET","readahead"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1908 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 1909 | if (get_geom) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1910 | { |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1911 | if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE")) |
| 1912 | { |
Rob Landley | 2584e9b | 2006-05-03 20:00:00 +0000 | [diff] [blame] | 1913 | struct hd_geometry g; |
| 1914 | |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1915 | if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO")) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1916 | printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", |
Rob Landley | 2584e9b | 2006-05-03 20:00:00 +0000 | [diff] [blame] | 1917 | g.cylinders, g.heads, g.sectors, parm, g.start); |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1918 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1919 | } |
| 1920 | #ifdef HDIO_DRIVE_CMD |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1921 | if (get_powermode) |
| 1922 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1923 | #ifndef WIN_CHECKPOWERMODE1 |
| 1924 | #define WIN_CHECKPOWERMODE1 0xE5 |
| 1925 | #endif |
| 1926 | #ifndef WIN_CHECKPOWERMODE2 |
| 1927 | #define WIN_CHECKPOWERMODE2 0x98 |
| 1928 | #endif |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1929 | const char *state; |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1930 | |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1931 | args[0] = WIN_CHECKPOWERMODE1; |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1932 | if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1933 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1934 | if (errno != EIO || args[0] != 0 || args[1] != 0) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1935 | state = "Unknown"; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1936 | else |
| 1937 | state = "sleeping"; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1938 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1939 | else |
| 1940 | state = (args[2] == 255) ? "active/idle" : "standby"; |
Rob Landley | 39cf645 | 2006-05-05 16:52:28 +0000 | [diff] [blame] | 1941 | args[1] = args[2] = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1942 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1943 | printf(" drive state is: %s\n", state); |
| 1944 | } |
| 1945 | #endif |
| 1946 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1947 | if (perform_reset) |
| 1948 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1949 | bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1950 | } |
| 1951 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ |
| 1952 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1953 | if (perform_tristate) |
| 1954 | { |
Rob Landley | e5b281f | 2006-04-29 15:49:18 +0000 | [diff] [blame] | 1955 | args[0] = 0; |
| 1956 | args[1] = tristate; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1957 | bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1958 | } |
| 1959 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ |
| 1960 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1961 | if (get_identity) |
| 1962 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1963 | static struct hd_driveid id; |
| 1964 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1965 | if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) |
| 1966 | { |
| 1967 | if (multcount != -1) |
| 1968 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1969 | id.multsect = multcount; |
| 1970 | id.multsect_valid |= 1; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1971 | } |
| 1972 | else |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1973 | id.multsect_valid &= ~1; |
| 1974 | dump_identity(&id); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1975 | } |
| 1976 | else if (errno == -ENOMSG) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1977 | printf(" no identification info available\n"); |
| 1978 | else |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 1979 | bb_perror_msg("HDIO_GET_IDENTITY"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1980 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1981 | |
| 1982 | if (get_IDentity) |
| 1983 | { |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1984 | unsigned char args1[4+512]; /* = { ... } will eat 0.5k of rodata! */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1985 | |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 1986 | memset(args1, 0, sizeof(args1)); |
| 1987 | args1[0] = WIN_IDENTIFY; |
| 1988 | args1[3] = 1; |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 1989 | if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) |
| 1990 | identify((void *)(args1 + 4)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1991 | } |
| 1992 | #endif |
| 1993 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1994 | if (set_busstate) |
| 1995 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1996 | if (get_busstate) |
| 1997 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 1998 | print_flag(1, "bus state", busstate); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1999 | bus_state_value(busstate); |
| 2000 | } |
Eric Andersen | a68ea1c | 2006-01-30 22:48:39 +0000 | [diff] [blame] | 2001 | 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] | 2002 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2003 | if (get_busstate) |
| 2004 | { |
Rob Landley | 5f8b5ec | 2006-04-29 16:03:40 +0000 | [diff] [blame] | 2005 | if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE")) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2006 | { |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2007 | printf(fmt, "bus state", parm); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2008 | bus_state_value(parm); |
| 2009 | } |
| 2010 | } |
| 2011 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2012 | if (reread_partn) |
| 2013 | bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART"); |
| 2014 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2015 | |
| 2016 | if (do_ctimings) |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 2017 | do_time(0,fd); /*time cache */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2018 | if (do_timings) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2019 | do_time(1,fd); /*time device */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2020 | if (do_flush) |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 2021 | flush_buffer_cache(fd); |
| 2022 | close(fd); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2025 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
Rob Landley | a3e4f38 | 2006-04-29 16:06:31 +0000 | [diff] [blame] | 2026 | static int fromhex(unsigned char c) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2027 | { |
| 2028 | if (c >= 'a' && c <= 'f') |
| 2029 | return 10 + (c - 'a'); |
| 2030 | if (c >= '0' && c <= '9') |
| 2031 | return (c - '0'); |
| 2032 | bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c); |
| 2033 | } |
| 2034 | |
Rob Landley | 0f0b645 | 2006-05-03 18:28:06 +0000 | [diff] [blame] | 2035 | static void identify_from_stdin(void) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2036 | { |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2037 | uint16_t sbuf[256]; |
| 2038 | unsigned char buf[1280], *b = (unsigned char *)buf; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2039 | int i, count = read(0, buf, 1280); |
| 2040 | |
| 2041 | if (count != 1280) |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2042 | bb_error_msg_and_die("read(%d bytes) failed (rc=%d)", 1280, count); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2043 | |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2044 | // Convert the newline-separated hex data into an identify block. |
| 2045 | |
| 2046 | for (i = 0; i<256; i++) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2047 | { |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2048 | int j; |
| 2049 | for(j=0;j<4;j++) sbuf[i] = (sbuf[i] <<4) + fromhex(*(b++)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2050 | } |
Rob Landley | 0753f4a | 2006-06-07 00:27:25 +0000 | [diff] [blame] | 2051 | |
| 2052 | // Parse the data. |
| 2053 | |
Rob Landley | 6389ff1 | 2006-05-01 19:28:53 +0000 | [diff] [blame] | 2054 | identify(sbuf); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2055 | } |
| 2056 | #endif |
| 2057 | |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2058 | /* busybox specific stuff */ |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2059 | static void parse_opts(unsigned long *get, unsigned long *set, unsigned long *value, int min, int max) |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2060 | { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2061 | if (get) { |
| 2062 | *get = 1; |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2063 | } |
| 2064 | if (optarg) { |
| 2065 | *set = 1; |
| 2066 | *value = bb_xgetlarg(optarg, 10, min, max); |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2067 | } |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2070 | static void parse_xfermode(int flag, unsigned long *get, unsigned long *set, int *value) |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2071 | { |
| 2072 | if (flag) { |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2073 | *get = 1; |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2074 | if (optarg) { |
| 2075 | *set = ((*value = translate_xfermode(optarg)) > -1); |
| 2076 | } |
| 2077 | } |
| 2078 | } |
| 2079 | |
Rob Landley | 0620841 | 2006-05-31 22:52:57 +0000 | [diff] [blame] | 2080 | /*------- getopt short options --------*/ |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2081 | 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] | 2082 | USE_FEATURE_HDPARM_GET_IDENTITY("iI") |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2083 | USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::") |
| 2084 | #ifdef HDIO_DRIVE_CMD |
Rob Landley | 403777f | 2006-08-03 20:22:37 +0000 | [diff] [blame] | 2085 | "S:D:P:X:K:A:L:W:CyYzZ" |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2086 | #endif |
| 2087 | USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:") |
| 2088 | #ifdef HDIO_GET_QDMA |
| 2089 | #ifdef HDIO_SET_QDMA |
| 2090 | "Q:" |
| 2091 | #else |
| 2092 | "Q" |
| 2093 | #endif |
| 2094 | #endif |
| 2095 | USE_FEATURE_HDPARM_HDIO_DRIVE_RESET("w") |
| 2096 | USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF("x::b:") |
| 2097 | USE_FEATURE_HDPARM_HDIO_SCAN_HWIF("R:"); |
| 2098 | /*-------------------------------------*/ |
| 2099 | |
| 2100 | /* our main() routine: */ |
| 2101 | int hdparm_main(int argc, char **argv) ATTRIBUTE_NORETURN; |
| 2102 | int hdparm_main(int argc, char **argv) |
| 2103 | { |
| 2104 | int c; |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2105 | int flagcount = 0; |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2106 | |
Rob Landley | 0620841 | 2006-05-31 22:52:57 +0000 | [diff] [blame] | 2107 | while ((c = getopt(argc, argv, hdparm_options)) >= 0) { |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2108 | flagcount++; |
Rob Landley | 0620841 | 2006-05-31 22:52:57 +0000 | [diff] [blame] | 2109 | if (c == 'h') bb_show_usage(); /* EXIT */ |
Mike Frysinger | ea93f8a | 2006-06-07 14:25:22 +0000 | [diff] [blame] | 2110 | USE_FEATURE_HDPARM_GET_IDENTITY(get_IDentity |= (c == 'I')); |
| 2111 | USE_FEATURE_HDPARM_GET_IDENTITY(get_identity |= (c == 'i')); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2112 | get_geom |= (c == 'g'); |
| 2113 | do_flush |= (c == 'f'); |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2114 | if (c == 'u') parse_opts(&get_unmask, &set_unmask, &unmask, 0, 1); |
| 2115 | USE_FEATURE_HDPARM_HDIO_GETSET_DMA(if (c == 'd') parse_opts(&get_dma, &set_dma, &dma, 0, 9)); |
| 2116 | if (c == 'n') parse_opts(&get_nowerr, &set_nowerr, &nowerr, 0, 1); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2117 | parse_xfermode((c == 'p'),&noisy_piomode, &set_piomode, &piomode); |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2118 | if (c == 'r') parse_opts(&get_readonly, &set_readonly, &readonly, 0, 1); |
| 2119 | if (c == 'm') parse_opts(&get_mult, &set_mult, &mult, 0, INT_MAX /*32*/); |
| 2120 | if (c == 'c') parse_opts(&get_io32bit, &set_io32bit, &io32bit, 0, INT_MAX /*8*/); |
| 2121 | if (c == 'k') parse_opts(&get_keep, &set_keep, &keep, 0, 1); |
| 2122 | if (c == 'a') parse_opts(&get_readahead, &set_readahead, &Xreadahead, 0, INT_MAX); |
| 2123 | if (c == 'B') parse_opts(&get_apmmode, &set_apmmode, &apmmode, 1, 255); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2124 | do_flush |= do_timings |= (c == 't'); |
| 2125 | do_flush |= do_ctimings |= (c == 'T'); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2126 | #ifdef HDIO_DRIVE_CMD |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2127 | if (c == 'S') parse_opts(&get_standby, &set_standby, &standby_requested, 0, INT_MAX); |
| 2128 | if (c == 'D') parse_opts(&get_defects, &set_defects, &defects, 0, INT_MAX); |
| 2129 | 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] | 2130 | parse_xfermode((c == 'X'), &get_xfermode, &set_xfermode, &xfermode_requested); |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2131 | if (c == 'K') parse_opts(&get_dkeep, &set_dkeep, &prefetch, 0, 1); |
| 2132 | if (c == 'A') parse_opts(&get_lookahead, &set_lookahead, &lookahead, 0, 1); |
| 2133 | if (c == 'L') parse_opts(&get_doorlock, &set_doorlock, &doorlock, 0, 1); |
| 2134 | if (c == 'W') parse_opts(&get_wcache, &set_wcache, &wcache, 0, 1); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2135 | get_powermode |= (c == 'C'); |
| 2136 | get_standbynow = set_standbynow |= (c == 'y'); |
| 2137 | get_sleepnow = set_sleepnow |= (c == 'Y'); |
Rob Landley | adde798 | 2006-05-16 15:32:30 +0000 | [diff] [blame] | 2138 | reread_partn |= (c == 'z'); |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2139 | get_seagate = set_seagate |= (c == 'Z'); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2140 | #endif |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2141 | 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] | 2142 | #ifdef HDIO_GET_QDMA |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2143 | if (c == 'Q') { |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2144 | #ifdef HDIO_SET_QDMA |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2145 | 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] | 2146 | #else |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2147 | parse_opts(&get_dma_q, NULL, NULL, 0, 0); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2148 | #endif |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2149 | } |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2150 | #endif |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2151 | USE_FEATURE_HDPARM_HDIO_DRIVE_RESET(perform_reset = (c == 'r')); |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2152 | USE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF(if (c == 'x') parse_opts(NULL, &perform_tristate, &tristate, 0, 1)); |
| 2153 | 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] | 2154 | #if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF |
| 2155 | if (c == 'R') { |
Rob Landley | 1980256 | 2006-05-08 15:35:46 +0000 | [diff] [blame] | 2156 | parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2157 | hwif_ctrl = bb_xgetlarg((argv[optind]) ? argv[optind] : "", 10, 0, INT_MAX); |
| 2158 | hwif_irq = bb_xgetlarg((argv[optind+1]) ? argv[optind+1] : "", 10, 0, INT_MAX); |
| 2159 | /* Move past the 2 additional arguments */ |
| 2160 | argv += 2; |
| 2161 | argc -= 2; |
| 2162 | } |
| 2163 | #endif |
| 2164 | } |
Rob Landley | ade7f95 | 2006-05-25 18:53:06 +0000 | [diff] [blame] | 2165 | /* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */ |
| 2166 | if (!flagcount){ |
| 2167 | get_mult = get_io32bit = get_unmask = get_keep = get_readonly = get_readahead = get_geom = 1; |
| 2168 | USE_FEATURE_HDPARM_HDIO_GETSET_DMA(get_dma = 1); |
| 2169 | } |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2170 | argc -= optind; |
| 2171 | argv += optind; |
| 2172 | |
| 2173 | if (argc < 1) { |
Rob Landley | 6d8ce17 | 2006-06-07 21:22:42 +0000 | [diff] [blame] | 2174 | if (ENABLE_FEATURE_HDPARM_GET_IDENTITY && !isatty(STDIN_FILENO)) |
| 2175 | identify_from_stdin(); /* EXIT */ |
| 2176 | else bb_show_usage(); |
Rob Landley | 20deab0 | 2006-05-07 23:34:15 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | while (argc--) { |
| 2180 | process_dev(*argv); |
| 2181 | argv++; |
| 2182 | } |
| 2183 | exit(EXIT_SUCCESS); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2184 | } |