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 | * |
| 5 | * |
Glenn L McGrath | 5be6a20 | 2003-11-28 22:55:03 +0000 | [diff] [blame] | 6 | * Copyright (C) [2003] by [Matteo Croce] <3297627799@wind.it> |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 7 | * |
| 8 | * Hacked by Tito <farmatito@tiscali.it> for size optimization. |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 9 | * |
Bernhard Reutner-Fischer | 061fd0a | 2006-04-05 16:37:25 +0000 | [diff] [blame^] | 10 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 11 | * |
| 12 | * This program is based on the source code of hdparm: see below... |
| 13 | * hdparm.c - Command line interface to get/set hard disk parameters |
| 14 | * - by Mark Lord (C) 1994-2002 -- freely distributable |
| 15 | */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 16 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 17 | #include <unistd.h> |
| 18 | #include <string.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <errno.h> |
| 22 | #include <ctype.h> |
| 23 | #include <endian.h> |
| 24 | #include <sys/ioctl.h> |
| 25 | #include <sys/shm.h> |
| 26 | #include <sys/sysmacros.h> |
| 27 | #include <sys/time.h> |
| 28 | #include <sys/times.h> |
| 29 | #include <sys/mount.h> |
| 30 | #include "busybox.h" |
| 31 | #include <linux/types.h> |
| 32 | #include <linux/hdreg.h> |
| 33 | #include <linux/major.h> |
| 34 | #include <asm/byteorder.h> |
| 35 | |
| 36 | |
Rob Landley | 688ed0d | 2006-03-04 22:40:25 +0000 | [diff] [blame] | 37 | #if BB_BIG_ENDIAN && !defined(__USE_XOPEN) |
| 38 | # define __USE_XOPEN |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
| 41 | /* device types */ |
| 42 | /* ------------ */ |
| 43 | #define NO_DEV 0xffff |
| 44 | #define ATA_DEV 0x0000 |
| 45 | #define ATAPI_DEV 0x0001 |
| 46 | |
| 47 | /* word definitions */ |
| 48 | /* ---------------- */ |
| 49 | #define GEN_CONFIG 0 /* general configuration */ |
| 50 | #define LCYLS 1 /* number of logical cylinders */ |
| 51 | #define CONFIG 2 /* specific configuration */ |
| 52 | #define LHEADS 3 /* number of logical heads */ |
| 53 | #define TRACK_BYTES 4 /* number of bytes/track (ATA-1) */ |
| 54 | #define SECT_BYTES 5 /* number of bytes/sector (ATA-1) */ |
| 55 | #define LSECTS 6 /* number of logical sectors/track */ |
| 56 | #define START_SERIAL 10 /* ASCII serial number */ |
| 57 | #define LENGTH_SERIAL 10 /* 10 words (20 bytes or characters) */ |
| 58 | #define BUF_TYPE 20 /* buffer type (ATA-1) */ |
| 59 | #define BUFFER__SIZE 21 /* buffer size (ATA-1) */ |
| 60 | #define RW_LONG 22 /* extra bytes in R/W LONG cmd ( < ATA-4)*/ |
| 61 | #define START_FW_REV 23 /* ASCII firmware revision */ |
| 62 | #define LENGTH_FW_REV 4 /* 4 words (8 bytes or characters) */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 63 | #define START_MODEL 27 /* ASCII model number */ |
| 64 | #define LENGTH_MODEL 20 /* 20 words (40 bytes or characters) */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 65 | #define SECTOR_XFER_MAX 47 /* r/w multiple: max sectors xfered */ |
| 66 | #define DWORD_IO 48 /* can do double-word IO (ATA-1 only) */ |
| 67 | #define CAPAB_0 49 /* capabilities */ |
| 68 | #define CAPAB_1 50 |
| 69 | #define PIO_MODE 51 /* max PIO mode supported (obsolete)*/ |
| 70 | #define DMA_MODE 52 /* max Singleword DMA mode supported (obs)*/ |
| 71 | #define WHATS_VALID 53 /* what fields are valid */ |
| 72 | #define LCYLS_CUR 54 /* current logical cylinders */ |
| 73 | #define LHEADS_CUR 55 /* current logical heads */ |
| 74 | #define LSECTS_CUR 56 /* current logical sectors/track */ |
| 75 | #define CAPACITY_LSB 57 /* current capacity in sectors */ |
| 76 | #define CAPACITY_MSB 58 |
| 77 | #define SECTOR_XFER_CUR 59 /* r/w multiple: current sectors xfered */ |
| 78 | #define LBA_SECTS_LSB 60 /* LBA: total number of user */ |
| 79 | #define LBA_SECTS_MSB 61 /* addressable sectors */ |
| 80 | #define SINGLE_DMA 62 /* singleword DMA modes */ |
| 81 | #define MULTI_DMA 63 /* multiword DMA modes */ |
| 82 | #define ADV_PIO_MODES 64 /* advanced PIO modes supported */ |
| 83 | /* multiword DMA xfer cycle time: */ |
| 84 | #define DMA_TIME_MIN 65 /* - minimum */ |
| 85 | #define DMA_TIME_NORM 66 /* - manufacturer's recommended */ |
| 86 | /* minimum PIO xfer cycle time: */ |
| 87 | #define PIO_NO_FLOW 67 /* - without flow control */ |
| 88 | #define PIO_FLOW 68 /* - with IORDY flow control */ |
| 89 | #define PKT_REL 71 /* typical #ns from PKT cmd to bus rel */ |
| 90 | #define SVC_NBSY 72 /* typical #ns from SERVICE cmd to !BSY */ |
| 91 | #define CDR_MAJOR 73 /* CD ROM: major version number */ |
| 92 | #define CDR_MINOR 74 /* CD ROM: minor version number */ |
| 93 | #define QUEUE_DEPTH 75 /* queue depth */ |
| 94 | #define MAJOR 80 /* major version number */ |
| 95 | #define MINOR 81 /* minor version number */ |
| 96 | #define CMDS_SUPP_0 82 /* command/feature set(s) supported */ |
| 97 | #define CMDS_SUPP_1 83 |
| 98 | #define CMDS_SUPP_2 84 |
| 99 | #define CMDS_EN_0 85 /* command/feature set(s) enabled */ |
| 100 | #define CMDS_EN_1 86 |
| 101 | #define CMDS_EN_2 87 |
| 102 | #define ULTRA_DMA 88 /* ultra DMA modes */ |
| 103 | /* time to complete security erase */ |
| 104 | #define ERASE_TIME 89 /* - ordinary */ |
| 105 | #define ENH_ERASE_TIME 90 /* - enhanced */ |
| 106 | #define ADV_PWR 91 /* current advanced power management level |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 107 | in low byte, 0x40 in high byte. */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 108 | #define PSWD_CODE 92 /* master password revision code */ |
| 109 | #define HWRST_RSLT 93 /* hardware reset result */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 110 | #define ACOUSTIC 94 /* acoustic mgmt values ( >= ATA-6) */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 111 | #define LBA_LSB 100 /* LBA: maximum. Currently only 48 */ |
| 112 | #define LBA_MID 101 /* bits are used, but addr 103 */ |
| 113 | #define LBA_48_MSB 102 /* has been reserved for LBA in */ |
| 114 | #define LBA_64_MSB 103 /* the future. */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 115 | #define RM_STAT 127 /* removable media status notification feature set support */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 116 | #define SECU_STATUS 128 /* security status */ |
| 117 | #define CFA_PWR_MODE 160 /* CFA power mode 1 */ |
| 118 | #define START_MEDIA 176 /* media serial number */ |
| 119 | #define LENGTH_MEDIA 20 /* 20 words (40 bytes or characters)*/ |
| 120 | #define START_MANUF 196 /* media manufacturer I.D. */ |
| 121 | #define LENGTH_MANUF 10 /* 10 words (20 bytes or characters) */ |
| 122 | #define INTEGRITY 255 /* integrity word */ |
| 123 | |
| 124 | /* bit definitions within the words */ |
| 125 | /* -------------------------------- */ |
| 126 | |
| 127 | /* many words are considered valid if bit 15 is 0 and bit 14 is 1 */ |
| 128 | #define VALID 0xc000 |
| 129 | #define VALID_VAL 0x4000 |
| 130 | /* many words are considered invalid if they are either all-0 or all-1 */ |
| 131 | #define NOVAL_0 0x0000 |
| 132 | #define NOVAL_1 0xffff |
| 133 | |
| 134 | /* word 0: gen_config */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 135 | #define NOT_ATA 0x8000 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 136 | #define NOT_ATAPI 0x4000 /* (check only if bit 15 == 1) */ |
| 137 | #define MEDIA_REMOVABLE 0x0080 |
| 138 | #define DRIVE_NOT_REMOVABLE 0x0040 /* bit obsoleted in ATA 6 */ |
| 139 | #define INCOMPLETE 0x0004 |
| 140 | #define CFA_SUPPORT_VAL 0x848a /* 848a=CFA feature set support */ |
| 141 | #define DRQ_RESPONSE_TIME 0x0060 |
| 142 | #define DRQ_3MS_VAL 0x0000 |
| 143 | #define DRQ_INTR_VAL 0x0020 |
| 144 | #define DRQ_50US_VAL 0x0040 |
| 145 | #define PKT_SIZE_SUPPORTED 0x0003 |
| 146 | #define PKT_SIZE_12_VAL 0x0000 |
| 147 | #define PKT_SIZE_16_VAL 0x0001 |
| 148 | #define EQPT_TYPE 0x1f00 |
| 149 | #define SHIFT_EQPT 8 |
| 150 | |
| 151 | #define CDROM 0x0005 |
| 152 | |
| 153 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 154 | static const char * const pkt_str[] = { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 155 | "Direct-access device", /* word 0, bits 12-8 = 00 */ |
| 156 | "Sequential-access device", /* word 0, bits 12-8 = 01 */ |
| 157 | "Printer", /* word 0, bits 12-8 = 02 */ |
| 158 | "Processor", /* word 0, bits 12-8 = 03 */ |
| 159 | "Write-once device", /* word 0, bits 12-8 = 04 */ |
| 160 | "CD-ROM", /* word 0, bits 12-8 = 05 */ |
| 161 | "Scanner", /* word 0, bits 12-8 = 06 */ |
| 162 | "Optical memory", /* word 0, bits 12-8 = 07 */ |
| 163 | "Medium changer", /* word 0, bits 12-8 = 08 */ |
| 164 | "Communications device", /* word 0, bits 12-8 = 09 */ |
| 165 | "ACS-IT8 device", /* word 0, bits 12-8 = 0a */ |
| 166 | "ACS-IT8 device", /* word 0, bits 12-8 = 0b */ |
| 167 | "Array controller", /* word 0, bits 12-8 = 0c */ |
| 168 | "Enclosure services", /* word 0, bits 12-8 = 0d */ |
| 169 | "Reduced block command device", /* word 0, bits 12-8 = 0e */ |
| 170 | "Optical card reader/writer", /* word 0, bits 12-8 = 0f */ |
| 171 | "", /* word 0, bits 12-8 = 10 */ |
| 172 | "", /* word 0, bits 12-8 = 11 */ |
| 173 | "", /* word 0, bits 12-8 = 12 */ |
| 174 | "", /* word 0, bits 12-8 = 13 */ |
| 175 | "", /* word 0, bits 12-8 = 14 */ |
| 176 | "", /* word 0, bits 12-8 = 15 */ |
| 177 | "", /* word 0, bits 12-8 = 16 */ |
| 178 | "", /* word 0, bits 12-8 = 17 */ |
| 179 | "", /* word 0, bits 12-8 = 18 */ |
| 180 | "", /* word 0, bits 12-8 = 19 */ |
| 181 | "", /* word 0, bits 12-8 = 1a */ |
| 182 | "", /* word 0, bits 12-8 = 1b */ |
| 183 | "", /* word 0, bits 12-8 = 1c */ |
| 184 | "", /* word 0, bits 12-8 = 1d */ |
| 185 | "", /* word 0, bits 12-8 = 1e */ |
| 186 | "Unknown", /* word 0, bits 12-8 = 1f */ |
| 187 | }; |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 188 | |
| 189 | static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 190 | "reserved", /* bit 0 */ |
| 191 | "hard sectored", /* bit 1 */ |
| 192 | "soft sectored", /* bit 2 */ |
| 193 | "not MFM encoded ", /* bit 3 */ |
| 194 | "head switch time > 15us", /* bit 4 */ |
| 195 | "spindle motor control option", /* bit 5 */ |
| 196 | "fixed drive", /* bit 6 */ |
| 197 | "removable drive", /* bit 7 */ |
| 198 | "disk xfer rate <= 5Mbs", /* bit 8 */ |
| 199 | "disk xfer rate > 5Mbs, <= 10Mbs", /* bit 9 */ |
| 200 | "disk xfer rate > 5Mbs", /* bit 10 */ |
| 201 | "rotational speed tol.", /* bit 11 */ |
| 202 | "data strobe offset option", /* bit 12 */ |
| 203 | "track offset option", /* bit 13 */ |
| 204 | "format speed tolerance gap reqd", /* bit 14 */ |
| 205 | "ATAPI" /* bit 14 */ |
| 206 | }; |
| 207 | #endif |
| 208 | |
| 209 | /* word 1: number of logical cylinders */ |
| 210 | #define LCYLS_MAX 0x3fff /* maximum allowable value */ |
| 211 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 212 | /* word 2: specific configuration |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 213 | * (a) require SET FEATURES to spin-up |
| 214 | * (b) require spin-up to fully reply to IDENTIFY DEVICE |
| 215 | */ |
| 216 | #define STBY_NID_VAL 0x37c8 /* (a) and (b) */ |
| 217 | #define STBY_ID_VAL 0x738c /* (a) and not (b) */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 218 | #define PWRD_NID_VAL 0x8c73 /* not (a) and (b) */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 219 | #define PWRD_ID_VAL 0xc837 /* not (a) and not (b) */ |
| 220 | |
| 221 | /* words 47 & 59: sector_xfer_max & sector_xfer_cur */ |
| 222 | #define SECTOR_XFER 0x00ff /* sectors xfered on r/w multiple cmds*/ |
| 223 | #define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */ |
| 224 | |
| 225 | /* word 49: capabilities 0 */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 226 | #define STD_STBY 0x2000 /* 1=standard values supported (ATA); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 227 | 0=vendor specific values */ |
| 228 | #define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */ |
| 229 | #define IORDY_OFF 0x0400 /* 1=may be disabled */ |
| 230 | #define LBA_SUP 0x0200 /* 1=Logical Block Address support */ |
| 231 | #define DMA_SUP 0x0100 /* 1=Direct Memory Access support */ |
| 232 | #define DMA_IL_SUP 0x8000 /* 1=interleaved DMA support (ATAPI) */ |
| 233 | #define CMD_Q_SUP 0x4000 /* 1=command queuing support (ATAPI) */ |
| 234 | #define OVLP_SUP 0x2000 /* 1=overlap operation support (ATAPI) */ |
| 235 | #define SWRST_REQ 0x1000 /* 1=ATA SW reset required (ATAPI, obsolete */ |
| 236 | |
| 237 | /* word 50: capabilities 1 */ |
| 238 | #define MIN_STANDBY_TIMER 0x0001 /* 1=device specific standby timer value minimum */ |
| 239 | |
| 240 | /* words 51 & 52: PIO & DMA cycle times */ |
| 241 | #define MODE 0xff00 /* the mode is in the MSBs */ |
| 242 | |
| 243 | /* word 53: whats_valid */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 244 | #define OK_W88 0x0004 /* the ultra_dma info is valid */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 245 | #define OK_W64_70 0x0002 /* see above for word descriptions */ |
| 246 | #define OK_W54_58 0x0001 /* current cyl, head, sector, cap. info valid */ |
| 247 | |
| 248 | /*word 63,88: dma_mode, ultra_dma_mode*/ |
| 249 | #define MODE_MAX 7 /* bit definitions force udma <=7 (when |
| 250 | * udma >=8 comes out it'll have to be |
| 251 | * defined in a new dma_mode word!) */ |
| 252 | |
| 253 | /* word 64: PIO transfer modes */ |
| 254 | #define PIO_SUP 0x00ff /* only bits 0 & 1 are used so far, */ |
| 255 | #define PIO_MODE_MAX 8 /* but all 8 bits are defined */ |
| 256 | |
| 257 | /* word 75: queue_depth */ |
| 258 | #define DEPTH_BITS 0x001f /* bits used for queue depth */ |
| 259 | |
| 260 | /* words 80-81: version numbers */ |
| 261 | /* NOVAL_0 or NOVAL_1 means device does not report version */ |
| 262 | |
| 263 | /* word 81: minor version number */ |
| 264 | #define MINOR_MAX 0x1C |
| 265 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 266 | static const char * const minor_str[] = { /* word 81 value: */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 267 | "device does not report version", /* 0x0000 */ |
| 268 | "ATA-1 X3T9.2 781D prior to revision 4", /* 0x0001 */ |
| 269 | "ATA-1 published, ANSI X3.221-1994", /* 0x0002 */ |
| 270 | "ATA-1 X3T9.2 781D revision 4", /* 0x0003 */ |
| 271 | "ATA-2 published, ANSI X3.279-1996", /* 0x0004 */ |
| 272 | "ATA-2 X3T10 948D prior to revision 2k", /* 0x0005 */ |
| 273 | "ATA-3 X3T10 2008D revision 1", /* 0x0006 */ |
| 274 | "ATA-2 X3T10 948D revision 2k", /* 0x0007 */ |
| 275 | "ATA-3 X3T10 2008D revision 0", /* 0x0008 */ |
| 276 | "ATA-2 X3T10 948D revision 3", /* 0x0009 */ |
| 277 | "ATA-3 published, ANSI X3.298-199x", /* 0x000a */ |
| 278 | "ATA-3 X3T10 2008D revision 6", /* 0x000b */ |
| 279 | "ATA-3 X3T13 2008D revision 7 and 7a", /* 0x000c */ |
| 280 | "ATA/ATAPI-4 X3T13 1153D revision 6", /* 0x000d */ |
| 281 | "ATA/ATAPI-4 T13 1153D revision 13", /* 0x000e */ |
| 282 | "ATA/ATAPI-4 X3T13 1153D revision 7", /* 0x000f */ |
| 283 | "ATA/ATAPI-4 T13 1153D revision 18", /* 0x0010 */ |
| 284 | "ATA/ATAPI-4 T13 1153D revision 15", /* 0x0011 */ |
| 285 | "ATA/ATAPI-4 published, ANSI NCITS 317-1998", /* 0x0012 */ |
| 286 | "ATA/ATAPI-5 T13 1321D revision 3", |
| 287 | "ATA/ATAPI-4 T13 1153D revision 14", /* 0x0014 */ |
| 288 | "ATA/ATAPI-5 T13 1321D revision 1", /* 0x0015 */ |
| 289 | "ATA/ATAPI-5 published, ANSI NCITS 340-2000", /* 0x0016 */ |
| 290 | "ATA/ATAPI-4 T13 1153D revision 17", /* 0x0017 */ |
| 291 | "ATA/ATAPI-6 T13 1410D revision 0", /* 0x0018 */ |
| 292 | "ATA/ATAPI-6 T13 1410D revision 3a", /* 0x0019 */ |
| 293 | "Reserved", /* 0x001a */ |
| 294 | "ATA/ATAPI-6 T13 1410D revision 2", /* 0x001b */ |
| 295 | "ATA/ATAPI-6 T13 1410D revision 1", /* 0x001c */ |
| 296 | "reserved" /* 0x001d */ |
| 297 | "reserved" /* 0x001e */ |
| 298 | "reserved" /* 0x001f-0xfffe*/ |
| 299 | }; |
| 300 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 301 | static const char actual_ver[] = { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 302 | /* word 81 value: */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 303 | 0, /* 0x0000 WARNING: */ |
| 304 | 1, /* 0x0001 WARNING: */ |
| 305 | 1, /* 0x0002 WARNING: */ |
| 306 | 1, /* 0x0003 WARNING: */ |
| 307 | 2, /* 0x0004 WARNING: This array */ |
| 308 | 2, /* 0x0005 WARNING: corresponds */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 309 | 3, /* 0x0006 WARNING: *exactly* */ |
| 310 | 2, /* 0x0007 WARNING: to the ATA/ */ |
| 311 | 3, /* 0x0008 WARNING: ATAPI version */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 312 | 2, /* 0x0009 WARNING: listed in */ |
| 313 | 3, /* 0x000a WARNING: the */ |
| 314 | 3, /* 0x000b WARNING: minor_str */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 315 | 3, /* 0x000c WARNING: array */ |
| 316 | 4, /* 0x000d WARNING: above. */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 317 | 4, /* 0x000e WARNING: */ |
| 318 | 4, /* 0x000f WARNING: if you change */ |
| 319 | 4, /* 0x0010 WARNING: that one, */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 320 | 4, /* 0x0011 WARNING: change this one */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 321 | 4, /* 0x0012 WARNING: too!!! */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 322 | 5, /* 0x0013 WARNING: */ |
| 323 | 4, /* 0x0014 WARNING: */ |
| 324 | 5, /* 0x0015 WARNING: */ |
| 325 | 5, /* 0x0016 WARNING: */ |
| 326 | 4, /* 0x0017 WARNING: */ |
| 327 | 6, /* 0x0018 WARNING: */ |
| 328 | 6, /* 0x0019 WARNING: */ |
| 329 | 0, /* 0x001a WARNING: */ |
| 330 | 6, /* 0x001b WARNING: */ |
| 331 | 6, /* 0x001c WARNING: */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 332 | 0 /* 0x001d-0xfffe */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | /* words 82-84: cmds/feats supported */ |
| 336 | #define CMDS_W82 0x77ff /* word 82: defined command locations*/ |
| 337 | #define CMDS_W83 0x3fff /* word 83: defined command locations*/ |
| 338 | #define CMDS_W84 0x002f /* word 83: defined command locations*/ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 339 | #define SUPPORT_48_BIT 0x0400 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 340 | #define NUM_CMD_FEAT_STR 48 |
| 341 | |
| 342 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 343 | static const char * const cmd_feat_str[] = { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 344 | "", /* word 82 bit 15: obsolete */ |
| 345 | "NOP cmd", /* word 82 bit 14 */ |
| 346 | "READ BUFFER cmd", /* word 82 bit 13 */ |
| 347 | "WRITE BUFFER cmd", /* word 82 bit 12 */ |
| 348 | "", /* word 82 bit 11: obsolete */ |
| 349 | "Host Protected Area feature set", /* word 82 bit 10 */ |
| 350 | "DEVICE RESET cmd", /* word 82 bit 9 */ |
| 351 | "SERVICE interrupt", /* word 82 bit 8 */ |
| 352 | "Release interrupt", /* word 82 bit 7 */ |
| 353 | "Look-ahead", /* word 82 bit 6 */ |
| 354 | "Write cache", /* word 82 bit 5 */ |
| 355 | "PACKET command feature set", /* word 82 bit 4 */ |
| 356 | "Power Management feature set", /* word 82 bit 3 */ |
| 357 | "Removable Media feature set", /* word 82 bit 2 */ |
| 358 | "Security Mode feature set", /* word 82 bit 1 */ |
| 359 | "SMART feature set", /* word 82 bit 0 */ |
| 360 | /* --------------*/ |
| 361 | "", /* word 83 bit 15: !valid bit */ |
| 362 | "", /* word 83 bit 14: valid bit */ |
| 363 | "FLUSH CACHE EXT command", /* word 83 bit 13 */ |
| 364 | "Mandatory FLUSH CACHE command ", /* word 83 bit 12 */ |
| 365 | "Device Configuration Overlay feature set ", |
| 366 | "48-bit Address feature set ", /* word 83 bit 10 */ |
| 367 | "", |
| 368 | "SET MAX security extension", /* word 83 bit 8 */ |
| 369 | "Address Offset Reserved Area Boot", /* word 83 bit 7 */ |
| 370 | "SET FEATURES subcommand required to spinup after power up", |
| 371 | "Power-Up In Standby feature set", /* word 83 bit 5 */ |
| 372 | "Removable Media Status Notification feature set", |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 373 | "Adv. Power Management feature set",/* word 83 bit 3 */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 374 | "CFA feature set", /* word 83 bit 2 */ |
| 375 | "READ/WRITE DMA QUEUED", /* word 83 bit 1 */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 376 | "DOWNLOAD MICROCODE cmd", /* word 83 bit 0 */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 377 | /* --------------*/ |
| 378 | "", /* word 84 bit 15: !valid bit */ |
| 379 | "", /* word 84 bit 14: valid bit */ |
| 380 | "", /* word 84 bit 13: reserved */ |
| 381 | "", /* word 84 bit 12: reserved */ |
| 382 | "", /* word 84 bit 11: reserved */ |
| 383 | "", /* word 84 bit 10: reserved */ |
| 384 | "", /* word 84 bit 9: reserved */ |
| 385 | "", /* word 84 bit 8: reserved */ |
| 386 | "", /* word 84 bit 7: reserved */ |
| 387 | "", /* word 84 bit 6: reserved */ |
| 388 | "General Purpose Logging feature set", /* word 84 bit 5 */ |
| 389 | "", /* word 84 bit 4: reserved */ |
| 390 | "Media Card Pass Through Command feature set ", |
| 391 | "Media serial number ", /* word 84 bit 2 */ |
| 392 | "SMART self-test ", /* word 84 bit 1 */ |
| 393 | "SMART error logging " /* word 84 bit 0 */ |
| 394 | }; |
| 395 | #endif |
| 396 | |
| 397 | |
| 398 | /* words 85-87: cmds/feats enabled */ |
| 399 | /* use cmd_feat_str[] to display what commands and features have |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 400 | * been enabled with words 85-87 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 401 | */ |
| 402 | |
| 403 | /* words 89, 90, SECU ERASE TIME */ |
| 404 | #define ERASE_BITS 0x00ff |
| 405 | |
| 406 | /* word 92: master password revision */ |
| 407 | /* NOVAL_0 or NOVAL_1 means no support for master password revision */ |
| 408 | |
| 409 | /* word 93: hw reset result */ |
| 410 | #define CBLID 0x2000 /* CBLID status */ |
| 411 | #define RST0 0x0001 /* 1=reset to device #0 */ |
| 412 | #define DEV_DET 0x0006 /* how device num determined */ |
| 413 | #define JUMPER_VAL 0x0002 /* device num determined by jumper */ |
| 414 | #define CSEL_VAL 0x0004 /* device num determined by CSEL_VAL */ |
| 415 | |
| 416 | /* word 127: removable media status notification feature set support */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 417 | #define RM_STAT_BITS 0x0003 |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 418 | #define RM_STAT_SUP 0x0001 |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 419 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 420 | /* word 128: security */ |
| 421 | #define SECU_ENABLED 0x0002 |
| 422 | #define SECU_LEVEL 0x0010 |
| 423 | #define NUM_SECU_STR 6 |
| 424 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 425 | static const char * const secu_str[] = { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 426 | "supported", /* word 128, bit 0 */ |
| 427 | "enabled", /* word 128, bit 1 */ |
| 428 | "locked", /* word 128, bit 2 */ |
| 429 | "frozen", /* word 128, bit 3 */ |
| 430 | "expired: security count", /* word 128, bit 4 */ |
| 431 | "supported: enhanced erase" /* word 128, bit 5 */ |
| 432 | }; |
| 433 | #endif |
| 434 | |
| 435 | /* word 160: CFA power mode */ |
| 436 | #define VALID_W160 0x8000 /* 1=word valid */ |
| 437 | #define PWR_MODE_REQ 0x2000 /* 1=CFA power mode req'd by some cmds*/ |
| 438 | #define PWR_MODE_OFF 0x1000 /* 1=CFA power moded disabled */ |
| 439 | #define MAX_AMPS 0x0fff /* value = max current in ma */ |
| 440 | |
| 441 | /* word 255: integrity */ |
| 442 | #define SIG 0x00ff /* signature location */ |
| 443 | #define SIG_VAL 0x00A5 /* signature value */ |
| 444 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 445 | #define VERSION "v5.4" |
| 446 | |
| 447 | #define TIMING_MB 64 |
| 448 | #define TIMING_BUF_MB 1 |
| 449 | #define TIMING_BUF_BYTES (TIMING_BUF_MB * 1024 * 1024) |
| 450 | #define TIMING_BUF_COUNT (timing_MB / TIMING_BUF_MB) |
| 451 | #define BUFCACHE_FACTOR 2 |
| 452 | |
| 453 | #undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ |
| 454 | |
| 455 | /* Busybox messages and functions */ |
| 456 | |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 457 | static const char bb_msg_shared_mem[] = "could not %s sharedmem buf"; |
| 458 | static const char bb_msg_op_not_supp[] = " operation not supported on %s disks"; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 459 | |
| 460 | static void bb_ioctl(int fd, int request, void *argp, const char *string) |
| 461 | { |
| 462 | if (ioctl (fd, request, argp) != 0) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 463 | bb_perror_msg(" %s", string); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void if_printf(unsigned long i, char *fmt, ... ) |
| 467 | { |
| 468 | va_list ap; |
| 469 | va_start(ap, fmt); |
| 470 | if (i) |
| 471 | vprintf(fmt, ap); |
| 472 | va_end(ap); |
| 473 | } |
| 474 | |
| 475 | static void on_off (unsigned int value); |
| 476 | |
| 477 | static void if_printf_on_off(unsigned long get_arg,const char *fmt, unsigned long arg) |
| 478 | { |
| 479 | if (get_arg) |
| 480 | { |
| 481 | printf(fmt, arg); |
| 482 | on_off(arg); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string, |
| 487 | const char * fmt) |
| 488 | { |
| 489 | if (ioctl (fd, request, &argp) != 0) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 490 | bb_perror_msg(" %s", string); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 491 | else |
| 492 | { |
| 493 | printf(fmt, (unsigned long) argp); |
| 494 | on_off((unsigned long) argp); |
| 495 | } |
| 496 | } |
Eric Andersen | 416c242 | 2003-12-12 00:08:57 +0000 | [diff] [blame] | 497 | |
| 498 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 499 | static void if_else_printf(unsigned long i, char *fmt1, char *fmt2, ... ) |
| 500 | { |
| 501 | va_list ap; |
| 502 | va_start(ap, fmt2); |
| 503 | if (i) |
| 504 | vprintf(fmt1, ap); |
| 505 | else |
| 506 | vprintf(fmt2, ap); |
| 507 | va_end(ap); |
| 508 | } |
| 509 | |
| 510 | static void print_ascii(uint16_t *p, uint8_t length); |
| 511 | |
| 512 | static void xprint_ascii(uint16_t *val ,int i, char * string, int n) |
| 513 | { |
| 514 | if(val[i]) |
| 515 | { |
| 516 | printf("\t%-20s",string); |
| 517 | print_ascii(&val[i], n); |
| 518 | } |
| 519 | } |
| 520 | |
Eric Andersen | 416c242 | 2003-12-12 00:08:57 +0000 | [diff] [blame] | 521 | static void if_strcat(unsigned long test, char *modes, char *string) |
| 522 | { |
| 523 | if (test) |
| 524 | strcat(modes,string); |
| 525 | } |
| 526 | #endif |
| 527 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 528 | static void sync_and_sleep(int i) |
| 529 | { |
| 530 | sync(); |
| 531 | sleep(i); |
| 532 | } |
| 533 | |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 534 | static uint16_t check_if_min_and_set_val(uint16_t a, uint16_t b) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 535 | { |
| 536 | if( a < b) |
| 537 | a = b; |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 538 | return a; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 541 | static uint16_t check_if_maj_and_set_val(uint16_t a, uint16_t b) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 542 | { |
| 543 | if( a > b) |
| 544 | a = b; |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 545 | return a; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 548 | static unsigned long int set_flag(char *p, char max) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 549 | { |
| 550 | if (*p >= '0' && *p <= max ) |
| 551 | return 1; |
| 552 | return 0; |
| 553 | } |
| 554 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 555 | /* end of busybox specific stuff */ |
| 556 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 557 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 558 | static uint8_t mode_loop(uint16_t mode_sup, uint16_t mode_sel, int cc, uint8_t *have_mode) |
| 559 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 560 | uint16_t ii; |
| 561 | uint8_t err_dma = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 562 | |
| 563 | for(ii = 0; ii <= MODE_MAX; ii++) |
| 564 | { |
| 565 | if(mode_sel & 0x0001) |
| 566 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 567 | printf("*%cdma%u ",cc,ii); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 568 | if(*have_mode) |
| 569 | err_dma = 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 570 | *have_mode = 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 571 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 572 | else if(mode_sup & 0x0001) |
| 573 | printf("%cdma%u ",cc,ii); |
| 574 | |
| 575 | mode_sup >>=1; |
| 576 | mode_sel >>=1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 577 | } |
| 578 | return err_dma; |
| 579 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 580 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 581 | static void print_ascii(uint16_t *p, uint8_t length) { |
| 582 | uint8_t ii; |
| 583 | char cl; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 584 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 585 | /* find first non-space & print it */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 586 | for(ii = 0; ii< length; ii++) |
| 587 | { |
| 588 | if(((char) 0x00ff&((*p)>>8)) != ' ') |
| 589 | break; |
| 590 | if((cl = (char) 0x00ff&(*p)) != ' ') |
| 591 | { |
| 592 | if_printf((cl != '\0'),"%c",cl); |
| 593 | p++; |
| 594 | ii++; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 595 | break; |
| 596 | } |
| 597 | p++; |
| 598 | } |
| 599 | /* print the rest */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 600 | for(; ii< length; ii++) |
| 601 | { |
| 602 | if(!(*p)) |
| 603 | break; /* some older devices have NULLs */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 604 | printf("%c%c",(char)0x00ff&((*p)>>8),(char)(*p)&0x00ff); |
| 605 | p++; |
| 606 | } |
| 607 | printf("\n"); |
| 608 | } |
| 609 | |
| 610 | /* identify() is the only extern function used across two source files. The |
| 611 | others, though, were declared in hdparm.c with global scope; since other |
| 612 | functions in that file have static (file) scope, I assume the difference is |
| 613 | intentional. */ |
| 614 | static void identify (uint16_t *id_supplied, const char *devname) |
| 615 | { |
| 616 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 617 | char *id_file = NULL; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 618 | FILE *fl; |
| 619 | uint16_t val[256], ii, jj, kk; |
| 620 | uint16_t like_std = 1, std = 0, min_std = 0xffff; |
| 621 | uint16_t dev = NO_DEV, eqpt = NO_DEV; |
| 622 | uint8_t have_mode = 0, err_dma = 0; |
| 623 | uint8_t chksum = 0; |
| 624 | uint32_t ll, mm, nn, oo; |
| 625 | __u64 bbbig; /* (:) */ |
| 626 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 627 | if (id_supplied) |
| 628 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 629 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 630 | swab(id_supplied, val, sizeof(val)); |
| 631 | #else |
| 632 | memcpy(val, id_supplied, sizeof(val)); |
| 633 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 634 | } |
| 635 | else |
| 636 | { |
| 637 | id_file = xcalloc(1, strlen(devname)+22); |
| 638 | sprintf(id_file, "/proc/ide/%s/identify", devname); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 639 | /* open the file, read in all the info and close it */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 640 | if (id_file == NULL) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 641 | fl = stdin; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 642 | else |
| 643 | fl = bb_xfopen(id_file, "r"); |
| 644 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 645 | /* calculate checksum over all bytes */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 646 | for(ii = GEN_CONFIG; ii<=INTEGRITY; ii++) |
| 647 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 648 | unsigned int scratch; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 649 | if(1 != fscanf(fl,"%04x",&scratch)) |
| 650 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 651 | val[ii] = (uint16_t)scratch; |
| 652 | chksum += val[ii] + (val[ii] >> 8); |
| 653 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 654 | fclose(fl); |
| 655 | /*bb_fclose_nonstdin(fl);*/ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 656 | if(ii < (INTEGRITY+1)) |
| 657 | bb_error_msg_and_die("Input file wrong format or length"); |
| 658 | } |
| 659 | chksum &= 0xff; |
| 660 | |
| 661 | /* check if we recognise the device type */ |
| 662 | printf("\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 663 | if(!(val[GEN_CONFIG] & NOT_ATA)) |
| 664 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 665 | dev = ATA_DEV; |
| 666 | printf("ATA device, with "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 667 | } |
| 668 | else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL) |
| 669 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 670 | dev = ATA_DEV; |
| 671 | like_std = 4; |
| 672 | printf("CompactFlash ATA device, with "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 673 | } |
| 674 | else if(!(val[GEN_CONFIG] & NOT_ATAPI)) |
| 675 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 676 | dev = ATAPI_DEV; |
| 677 | eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT; |
| 678 | printf("ATAPI %s, with ", pkt_str[eqpt]); |
| 679 | like_std = 3; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 680 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 681 | else |
| 682 | /*"Unknown device type:\n\tbits 15&14 of general configuration word 0 both set to 1.\n"*/ |
| 683 | bb_error_msg_and_die("Unknown device type"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 684 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 685 | if_printf(!(val[GEN_CONFIG] & MEDIA_REMOVABLE),"non-"); |
| 686 | printf("removable media\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 687 | |
| 688 | /* Info from the specific configuration word says whether or not the |
| 689 | * ID command completed correctly. It is only defined, however in |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 690 | * ATA/ATAPI-5 & 6; it is reserved (value theoretically 0) in prior |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 691 | * standards. Since the values allowed for this word are extremely |
| 692 | * specific, it should be safe to check it now, even though we don't |
| 693 | * know yet what standard this device is using. |
| 694 | */ |
| 695 | if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL) || |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 696 | (val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) ) |
| 697 | { |
| 698 | like_std = 5; |
| 699 | if_printf(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL)), |
| 700 | "powers-up in standby; SET FEATURES subcmd spins-up.\n"); |
| 701 | if_printf((((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE)), |
| 702 | "\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] | 703 | } |
| 704 | |
| 705 | /* output the model and serial numbers and the fw revision */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 706 | xprint_ascii(val, START_MODEL, "Model Number:", LENGTH_MODEL); |
| 707 | xprint_ascii(val, START_SERIAL, "Serial Number:", LENGTH_SERIAL); |
| 708 | xprint_ascii(val, START_FW_REV, "Firmware Revision:", LENGTH_FW_REV); |
| 709 | xprint_ascii(val, START_MEDIA, "Media Serial Num:", LENGTH_MEDIA); |
| 710 | xprint_ascii(val, START_MANUF, "Media Manufacturer:", LENGTH_MANUF); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 711 | |
| 712 | /* major & minor standards version number (Note: these words were not |
| 713 | * defined until ATA-3 & the CDROM std uses different words.) */ |
| 714 | printf("Standards:"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 715 | if(eqpt != CDROM) |
| 716 | { |
| 717 | if(val[MINOR] && (val[MINOR] <= MINOR_MAX)) |
| 718 | { |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 719 | like_std=check_if_min_and_set_val(like_std, 3); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 720 | std = actual_ver[val[MINOR]]; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 721 | if_printf(std,"\n\tUsed: %s ",minor_str[val[MINOR]]); |
| 722 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 723 | } |
| 724 | /* looks like when they up-issue the std, they obsolete one; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 725 | * thus, only the newest 4 issues need be supported. (That's |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 726 | * what "kk" and "min_std" are all about.) */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 727 | if(val[MAJOR] && (val[MAJOR] !=NOVAL_1)) |
| 728 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 729 | printf("\n\tSupported: "); |
| 730 | jj = val[MAJOR] << 1; |
| 731 | kk = like_std >4 ? like_std-4: 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 732 | for(ii = 14; (ii >0)&&(ii>kk); ii--) |
| 733 | { |
| 734 | if(jj & 0x8000) |
| 735 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 736 | printf("%u ", ii); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 737 | if(like_std < ii) |
| 738 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 739 | like_std = ii; |
| 740 | kk = like_std >4 ? like_std-4: 0; |
| 741 | } |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 742 | min_std=check_if_maj_and_set_val(min_std, ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 743 | } |
| 744 | jj <<= 1; |
| 745 | } |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 746 | like_std=check_if_min_and_set_val(like_std, 3); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 747 | } |
| 748 | /* Figure out what standard the device is using if it hasn't told |
| 749 | * us. If we know the std, check if the device is using any of |
| 750 | * the words from the next level up. It happens. |
| 751 | */ |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 752 | like_std=check_if_min_and_set_val(like_std, std); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 753 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 754 | if(((std == 5) || (!std && (like_std < 6))) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 755 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 756 | (( val[CMDS_SUPP_1] & CMDS_W83) > 0x00ff)) || |
| 757 | ((( val[CMDS_SUPP_2] & VALID) == VALID_VAL) && |
| 758 | ( val[CMDS_SUPP_2] & CMDS_W84) ) ) ) |
| 759 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 760 | like_std = 6; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 761 | } |
| 762 | else if(((std == 4) || (!std && (like_std < 5))) && |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 763 | ((((val[INTEGRITY] & SIG) == SIG_VAL) && !chksum) || |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 764 | (( val[HWRST_RSLT] & VALID) == VALID_VAL) || |
| 765 | ((( val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 766 | (( val[CMDS_SUPP_1] & CMDS_W83) > 0x001f)) ) ) |
| 767 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 768 | like_std = 5; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 769 | } |
| 770 | else if(((std == 3) || (!std && (like_std < 4))) && |
| 771 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| 772 | ((( val[CMDS_SUPP_1] & CMDS_W83) > 0x0000) || |
| 773 | (( val[CMDS_SUPP_0] & CMDS_W82) > 0x000f))) || |
| 774 | (( val[CAPAB_1] & VALID) == VALID_VAL) || |
| 775 | (( val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) || |
| 776 | (( val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP) ) ) |
| 777 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 778 | like_std = 4; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 779 | } |
| 780 | else if(((std == 2) || (!std && (like_std < 3))) && |
| 781 | ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) ) |
| 782 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 783 | like_std = 3; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 784 | } |
| 785 | else if(((std == 1) || (!std && (like_std < 2))) && |
| 786 | ((val[CAPAB_0] & (IORDY_SUP | IORDY_OFF)) || |
| 787 | (val[WHATS_VALID] & OK_W64_70)) ) |
| 788 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 789 | like_std = 2; |
| 790 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 791 | if(!std) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 792 | printf("\n\tLikely used: %u\n",like_std); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 793 | else if(like_std > std) |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 794 | printf("& some of %u\n",like_std); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 795 | else |
| 796 | printf("\n"); |
| 797 | } |
| 798 | else |
| 799 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 800 | /* TBD: do CDROM stuff more thoroughly. For now... */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 801 | kk = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 802 | if(val[CDR_MINOR] == 9) |
| 803 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 804 | kk = 1; |
| 805 | printf("\n\tUsed: ATAPI for CD-ROMs, SFF-8020i, r2.5"); |
| 806 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 807 | if(val[CDR_MAJOR] && (val[CDR_MAJOR] !=NOVAL_1)) |
| 808 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 809 | kk = 1; |
| 810 | printf("\n\tSupported: CD-ROM ATAPI"); |
| 811 | jj = val[CDR_MAJOR] >> 1; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 812 | for(ii = 1; ii <15; ii++) |
| 813 | { |
| 814 | if_printf((jj & 0x0001),"-%u ", ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 815 | jj >>= 1; |
| 816 | } |
| 817 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 818 | if_else_printf((!kk),"\n\tLikely used CD-ROM ATAPI-1\n","\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 819 | /* the cdrom stuff is more like ATA-2 than anything else, so: */ |
| 820 | like_std = 2; |
| 821 | } |
| 822 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 823 | if(min_std == 0xffff) |
| 824 | min_std = like_std > 4 ? like_std - 3 : 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 825 | |
| 826 | printf("Configuration:\n"); |
| 827 | /* more info from the general configuration word */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 828 | if((eqpt != CDROM) && (like_std == 1)) |
| 829 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 830 | jj = val[GEN_CONFIG] >> 1; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 831 | for(ii = 1; ii < 15; ii++) |
| 832 | { |
| 833 | if_printf((jj & 0x0001),"\t%s\n",ata1_cfg_str[ii]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 834 | jj >>=1; |
| 835 | } |
| 836 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 837 | if(dev == ATAPI_DEV) |
| 838 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 839 | printf("\tDRQ response: "); /* Data Request (DRQ) */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 840 | switch(val[GEN_CONFIG] & DRQ_RESPONSE_TIME) |
| 841 | { |
| 842 | case DRQ_3MS_VAL : |
| 843 | printf("3ms.\n"); |
| 844 | break; |
| 845 | case DRQ_INTR_VAL : |
| 846 | printf("<=10ms with INTRQ\n"); |
| 847 | break; |
| 848 | case DRQ_50US_VAL : |
| 849 | printf("50us.\n"); |
| 850 | break; |
| 851 | default : |
| 852 | printf("unknown.\n"); |
| 853 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 854 | } |
| 855 | printf("\tPacket size: "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 856 | switch(val[GEN_CONFIG] & PKT_SIZE_SUPPORTED) |
| 857 | { |
| 858 | case PKT_SIZE_12_VAL : |
| 859 | printf("12 bytes\n"); |
| 860 | break; |
| 861 | case PKT_SIZE_16_VAL : |
| 862 | printf("16 bytes\n"); |
| 863 | break; |
| 864 | default : |
| 865 | printf("Unknown\n"); |
| 866 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 867 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 868 | } |
| 869 | else |
| 870 | { |
| 871 | /* addressing...CHS? See section 6.2 of ATA specs 4 or 5 */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 872 | ll = (uint32_t)val[LBA_SECTS_MSB] << 16 | val[LBA_SECTS_LSB]; |
| 873 | mm = 0; bbbig = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 874 | if ( (ll > 0x00FBFC10) && (!val[LCYLS])) |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 875 | printf("\tCHS addressing not supported\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 876 | else |
| 877 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 878 | jj = val[WHATS_VALID] & OK_W54_58; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 879 | 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", |
| 880 | val[LCYLS],jj?val[LCYLS_CUR]:0, val[LHEADS],jj?val[LHEADS_CUR]:0, val[LSECTS],jj?val[LSECTS_CUR]:0); |
| 881 | |
| 882 | if_printf(((min_std == 1) && (val[TRACK_BYTES] || val[SECT_BYTES])), |
| 883 | "\tbytes/track: %u\tbytes/sector: %u\n",val[TRACK_BYTES], val[SECT_BYTES]); |
| 884 | |
| 885 | if(jj) |
| 886 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 887 | mm = (uint32_t)val[CAPACITY_MSB] << 16 | val[CAPACITY_LSB]; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 888 | if(like_std < 3) |
| 889 | { |
| 890 | /* check Endian of capacity bytes */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 891 | nn = val[LCYLS_CUR] * val[LHEADS_CUR] * val[LSECTS_CUR]; |
| 892 | oo = (uint32_t)val[CAPACITY_LSB] << 16 | val[CAPACITY_MSB]; |
| 893 | if(abs(mm - nn) > abs(oo - nn)) |
| 894 | mm = oo; |
| 895 | } |
| 896 | printf("\tCHS current addressable sectors:%11u\n",mm); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 897 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 898 | } |
| 899 | /* LBA addressing */ |
| 900 | printf("\tLBA user addressable sectors:%11u\n",ll); |
| 901 | if( ((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 902 | (val[CMDS_SUPP_1] & SUPPORT_48_BIT) ) |
| 903 | { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 904 | bbbig = (__u64)val[LBA_64_MSB] << 48 | |
| 905 | (__u64)val[LBA_48_MSB] << 32 | |
| 906 | (__u64)val[LBA_MID] << 16 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 907 | val[LBA_LSB] ; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 908 | printf("\tLBA48 user addressable sectors:%11llu\n",bbbig); |
| 909 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 910 | |
| 911 | if (!bbbig) |
| 912 | bbbig = (__u64)(ll>mm ? ll : mm); /* # 512 byte blocks */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 913 | printf("\tdevice size with M = 1024*1024: %11llu MBytes\n",bbbig>>11); |
| 914 | bbbig = (bbbig<<9)/1000000; |
| 915 | printf("\tdevice size with M = 1000*1000: %11llu MBytes ",bbbig); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 916 | |
| 917 | if_else_printf((bbbig > 1000),"(%llu GB)\n","\n",bbbig/1000); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 918 | |
| 919 | } |
| 920 | |
| 921 | /* hw support of commands (capabilities) */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 922 | printf("Capabilities:\n\t"); |
| 923 | |
| 924 | if(dev == ATAPI_DEV) |
| 925 | { |
| 926 | if(eqpt != CDROM) |
| 927 | if_printf((val[CAPAB_0] & CMD_Q_SUP),"Cmd queuing, "); |
| 928 | |
| 929 | if_printf((val[CAPAB_0] & OVLP_SUP),"Cmd overlap, "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 930 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 931 | if_printf((val[CAPAB_0] & LBA_SUP),"LBA, "); |
| 932 | |
| 933 | if(like_std != 1) |
| 934 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 935 | printf("IORDY"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 936 | if_printf((!(val[CAPAB_0] & IORDY_SUP)),"(may be)"); |
| 937 | if_else_printf((val[CAPAB_0] & IORDY_OFF),"(can","(cannot"); |
| 938 | printf(" be disabled)\n"); |
| 939 | } |
| 940 | else |
| 941 | printf("no IORDY\n"); |
| 942 | |
| 943 | if((like_std == 1) && val[BUF_TYPE]) |
| 944 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 945 | kk = val[BUF_TYPE]; |
| 946 | printf("\tBuffer type: %04x: ",kk); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 947 | if_else_printf((kk < 2),"single port, single-sector","dual port, multi-sector"); |
| 948 | if_printf((kk > 2)," with read caching ability"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 949 | printf("\n"); |
| 950 | } |
| 951 | jj = 0; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 952 | if((min_std == 1) && (val[BUFFER__SIZE] && (val[BUFFER__SIZE] != NOVAL_1))) |
| 953 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 954 | printf("\tBuffer size: %.1fkB",(float)val[BUFFER__SIZE]/2); |
| 955 | jj = 1; |
| 956 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 957 | if((min_std < 4) && (val[RW_LONG])) |
| 958 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 959 | printf("\tbytes avail on r/w long: %u",val[RW_LONG]); |
| 960 | jj = 1; |
| 961 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 962 | if((eqpt != CDROM) && (like_std > 3)) |
| 963 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 964 | printf("\tQueue depth: %u",(val[QUEUE_DEPTH] & DEPTH_BITS)+1); |
| 965 | jj = 1; |
| 966 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 967 | if_printf(jj,"\n"); |
| 968 | |
| 969 | if(dev == ATA_DEV) |
| 970 | { |
| 971 | if(like_std == 1) |
| 972 | printf("\tCan%s perform double-word IO\n",(!val[DWORD_IO]) ?"not":""); |
| 973 | else |
| 974 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 975 | printf("\tStandby timer values: spec'd by "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 976 | if_else_printf((val[CAPAB_0] & STD_STBY),"Standard","Vendor"); |
| 977 | if((like_std > 3) && ((val[CAPAB_1] & VALID) == VALID_VAL)) |
| 978 | printf(", %s device specific minimum\n",(val[CAPAB_1] & MIN_STANDBY_TIMER)?"with":"no"); |
| 979 | else |
| 980 | printf("\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 981 | } |
| 982 | printf("\tR/W multiple sector transfer: "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 983 | if((like_std < 3) && !(val[SECTOR_XFER_MAX] & SECTOR_XFER)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 984 | printf("not supported\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 985 | else |
| 986 | { |
| 987 | printf("Max = %u\tCurrent = ",val[SECTOR_XFER_MAX] & SECTOR_XFER); |
| 988 | if_else_printf((val[SECTOR_XFER_CUR] & MULTIPLE_SETTING_VALID), |
| 989 | "%u\n","?\n",val[SECTOR_XFER_CUR] & SECTOR_XFER); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 990 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 991 | if((like_std > 3) && (val[CMDS_SUPP_1] & 0x0008)) |
| 992 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 993 | /* We print out elsewhere whether the APM feature is enabled or |
| 994 | not. If it's not enabled, let's not repeat the info; just print |
| 995 | nothing here. */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 996 | printf("\tAdvancedPM level: "); |
| 997 | if ( (val[ADV_PWR] & 0xFF00) == 0x4000 ) |
| 998 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 999 | uint8_t apm_level = val[ADV_PWR] & 0x00FF; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1000 | printf("%u (0x%x)\n", apm_level, apm_level); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1001 | } |
| 1002 | else |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1003 | printf("unknown setting (0x%04x)\n", val[ADV_PWR]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1004 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1005 | if(like_std > 5) |
| 1006 | { |
| 1007 | if_printf(val[ACOUSTIC],"\tRecommended acoustic management value: %u, current value: %u\n", |
| 1008 | (val[ACOUSTIC] >> 8) & 0x00ff, val[ACOUSTIC] & 0x00ff); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1009 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1010 | } |
| 1011 | else |
| 1012 | { |
| 1013 | /* ATAPI */ |
| 1014 | if(eqpt != CDROM) |
| 1015 | if_printf((val[CAPAB_0] & SWRST_REQ),"\tATA sw reset required\n"); |
| 1016 | |
| 1017 | if(val[PKT_REL] || val[SVC_NBSY]) |
| 1018 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1019 | printf("\tOverlap support:"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1020 | if_printf(val[PKT_REL]," %uus to release bus.",val[PKT_REL]); |
| 1021 | if_printf(val[SVC_NBSY]," %uus to clear BSY after SERVICE cmd.",val[SVC_NBSY]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1022 | printf("\n"); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | /* DMA stuff. Check that only one DMA mode is selected. */ |
| 1027 | printf("\tDMA: "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1028 | if(!(val[CAPAB_0] & DMA_SUP)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1029 | printf("not supported\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1030 | else |
| 1031 | { |
| 1032 | if_printf((val[DMA_MODE] && !val[SINGLE_DMA] && !val[MULTI_DMA]), |
| 1033 | " sdma%u\n",(val[DMA_MODE] & MODE) >> 8); |
| 1034 | if(val[SINGLE_DMA]) |
| 1035 | { |
| 1036 | jj = val[SINGLE_DMA]; |
| 1037 | kk = val[SINGLE_DMA] >> 8; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1038 | err_dma += mode_loop(jj,kk,'s',&have_mode); |
| 1039 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1040 | if(val[MULTI_DMA]) |
| 1041 | { |
| 1042 | jj = val[MULTI_DMA]; |
| 1043 | kk = val[MULTI_DMA] >> 8; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1044 | err_dma += mode_loop(jj,kk,'m',&have_mode); |
| 1045 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1046 | if((val[WHATS_VALID] & OK_W88) && val[ULTRA_DMA]) |
| 1047 | { |
| 1048 | jj = val[ULTRA_DMA]; |
| 1049 | kk = val[ULTRA_DMA] >> 8; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1050 | err_dma += mode_loop(jj,kk,'u',&have_mode); |
| 1051 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1052 | if_printf((err_dma || !have_mode),"(?)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1053 | printf("\n"); |
| 1054 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1055 | if_printf(((dev == ATAPI_DEV) && (eqpt != CDROM) && (val[CAPAB_0] & DMA_IL_SUP)), |
| 1056 | "\t Interleaved DMA support\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1057 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1058 | if((val[WHATS_VALID] & OK_W64_70) && |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1059 | (val[DMA_TIME_MIN] || val[DMA_TIME_NORM])) |
| 1060 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1061 | printf("\t Cycle time:"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1062 | if_printf(val[DMA_TIME_MIN]," min=%uns",val[DMA_TIME_MIN]); |
| 1063 | if_printf(val[DMA_TIME_NORM]," recommended=%uns",val[DMA_TIME_NORM]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1064 | printf("\n"); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | /* Programmed IO stuff */ |
| 1069 | printf("\tPIO: "); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1070 | /* 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] | 1071 | * than n (e.g. 3, 2, 1 and 0). Print all the modes. */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1072 | if((val[WHATS_VALID] & OK_W64_70) && (val[ADV_PIO_MODES] & PIO_SUP)) |
| 1073 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1074 | jj = ((val[ADV_PIO_MODES] & PIO_SUP) << 3) | 0x0007; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1075 | for(ii = 0; ii <= PIO_MODE_MAX ; ii++) |
| 1076 | { |
| 1077 | if_printf((jj & 0x0001),"pio%d ",ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1078 | jj >>=1; |
| 1079 | } |
| 1080 | printf("\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1081 | } |
| 1082 | else if(((min_std < 5) || (eqpt == CDROM)) && (val[PIO_MODE] & MODE) ) |
| 1083 | { |
| 1084 | for(ii = 0; ii <= val[PIO_MODE]>>8; ii++) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1085 | printf("pio%d ",ii); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1086 | printf("\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1087 | } |
| 1088 | else |
| 1089 | printf("unknown\n"); |
| 1090 | |
| 1091 | if(val[WHATS_VALID] & OK_W64_70) |
| 1092 | { |
| 1093 | if(val[PIO_NO_FLOW] || val[PIO_FLOW]) |
| 1094 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1095 | printf("\t Cycle time:"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1096 | if_printf(val[PIO_NO_FLOW]," no flow control=%uns", val[PIO_NO_FLOW]); |
| 1097 | if_printf(val[PIO_FLOW]," IORDY flow control=%uns", val[PIO_FLOW]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1098 | printf("\n"); |
| 1099 | } |
| 1100 | } |
| 1101 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1102 | if((val[CMDS_SUPP_1] & VALID) == VALID_VAL) |
| 1103 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1104 | printf("Commands/features:\n\tEnabled\tSupported:\n"); |
| 1105 | jj = val[CMDS_SUPP_0]; |
| 1106 | kk = val[CMDS_EN_0]; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1107 | for(ii = 0; ii < NUM_CMD_FEAT_STR; ii++) |
| 1108 | { |
| 1109 | if((jj & 0x8000) && (*cmd_feat_str[ii] != '\0')) |
| 1110 | { |
| 1111 | if_else_printf((kk & 0x8000),"\t *","\t"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1112 | printf("\t%s\n",cmd_feat_str[ii]); |
| 1113 | } |
| 1114 | jj <<=1; kk<<=1; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1115 | if(ii%16 == 15) |
| 1116 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1117 | jj = val[CMDS_SUPP_0+1+(ii/16)]; |
| 1118 | kk = val[CMDS_EN_0+1+(ii/16)]; |
| 1119 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1120 | if(ii == 31) |
| 1121 | { |
| 1122 | if((val[CMDS_SUPP_2] & VALID) != VALID_VAL) |
| 1123 | ii +=16; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1124 | } |
| 1125 | } |
| 1126 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1127 | if_printf(((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP), |
| 1128 | "\tRemovable Media Status Notification feature set supported\n"); |
| 1129 | |
| 1130 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1131 | /* security */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1132 | if((eqpt != CDROM) && (like_std > 3) && |
| 1133 | (val[SECU_STATUS] || val[ERASE_TIME] || val[ENH_ERASE_TIME])) |
| 1134 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1135 | printf("Security: \n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1136 | if_printf((val[PSWD_CODE] && (val[PSWD_CODE] != NOVAL_1)), |
| 1137 | "\tMaster password revision code = %u\n",val[PSWD_CODE]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1138 | jj = val[SECU_STATUS]; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1139 | if(jj) |
| 1140 | { |
| 1141 | for(ii = 0; ii < NUM_SECU_STR; ii++) |
| 1142 | { |
| 1143 | if_else_printf((!(jj & 0x0001)),"\tnot\t%s\n", "\t\t%s\n", secu_str[ii]); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1144 | jj >>=1; |
| 1145 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1146 | if(val[SECU_STATUS] & SECU_ENABLED) |
| 1147 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1148 | printf("\tSecurity level "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1149 | if_else_printf((val[SECU_STATUS] & SECU_LEVEL),"maximum\n","high\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | jj = val[ERASE_TIME] & ERASE_BITS; |
| 1153 | kk = val[ENH_ERASE_TIME] & ERASE_BITS; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1154 | if(jj || kk) |
| 1155 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1156 | printf("\t"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1157 | if_printf(jj,"%umin for SECURITY ERASE UNIT. ", jj==ERASE_BITS ? 508 : jj<<1); |
| 1158 | if_printf(kk,"%umin for ENHANCED SECURITY ERASE UNIT.", kk==ERASE_BITS ? 508 : kk<<1); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1159 | printf("\n"); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | /* reset result */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1164 | if((val[HWRST_RSLT] & VALID) == VALID_VAL) |
| 1165 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1166 | printf("HW reset results:\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1167 | if_else_printf((val[HWRST_RSLT] & CBLID),"\tCBLID- above Vih\n","\tCBLID- below Vih\n"); |
| 1168 | |
| 1169 | if(val[HWRST_RSLT] & RST0) |
| 1170 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1171 | printf("\tDevice num = 0"); |
| 1172 | jj = val[HWRST_RSLT]; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1173 | } |
| 1174 | else |
| 1175 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1176 | printf("\tDevice num = 1"); |
| 1177 | jj = val[HWRST_RSLT] >> 8; |
| 1178 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1179 | |
| 1180 | if((jj & DEV_DET) == JUMPER_VAL) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1181 | printf(" determined by the jumper"); |
| 1182 | else if((jj & DEV_DET) == CSEL_VAL) |
| 1183 | printf(" determined by CSEL"); |
| 1184 | printf("\n"); |
| 1185 | } |
| 1186 | |
| 1187 | /* more stuff from std 5 */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1188 | if((like_std > 4) && (eqpt != CDROM)) |
| 1189 | { |
| 1190 | if(val[CFA_PWR_MODE] & VALID_W160) |
| 1191 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1192 | printf("CFA power mode 1:\n\t"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1193 | if_else_printf((val[CFA_PWR_MODE] & PWR_MODE_OFF),"disabled","enabled"); |
| 1194 | |
| 1195 | if_printf((val[CFA_PWR_MODE] & PWR_MODE_REQ)," and required by some commands"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1196 | printf("\n"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1197 | |
| 1198 | if_printf((val[CFA_PWR_MODE] & MAX_AMPS),"\tMaximum current = %uma\n",val[CFA_PWR_MODE] & MAX_AMPS); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1199 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1200 | if((val[INTEGRITY] & SIG) == SIG_VAL) |
| 1201 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1202 | printf("Checksum: "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1203 | if_printf(chksum,"in"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1204 | printf("correct\n"); |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | exit(0); |
| 1209 | } |
| 1210 | #endif |
| 1211 | |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1212 | static int verbose, get_identity, get_geom, noisy = 1, quiet; |
| 1213 | static int flagcount, do_flush, is_scsi_hd, is_xt_hd; |
| 1214 | static int do_ctimings, do_timings; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1215 | |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1216 | static unsigned long set_readahead, get_readahead, Xreadahead; |
| 1217 | static unsigned long set_readonly, get_readonly, readonly; |
| 1218 | static unsigned long set_unmask, get_unmask, unmask; |
| 1219 | static unsigned long set_mult, get_mult, mult; |
Eric Andersen | f1c56a9 | 2003-08-08 22:13:41 +0000 | [diff] [blame] | 1220 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1221 | static unsigned long set_dma, get_dma, dma; |
Eric Andersen | f1c56a9 | 2003-08-08 22:13:41 +0000 | [diff] [blame] | 1222 | #endif |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1223 | static unsigned long set_dma_q, get_dma_q, dma_q; |
| 1224 | static unsigned long set_nowerr, get_nowerr, nowerr; |
| 1225 | static unsigned long set_keep, get_keep, keep; |
| 1226 | static unsigned long set_io32bit, get_io32bit, io32bit; |
| 1227 | static unsigned long set_piomode, noisy_piomode; |
| 1228 | static int piomode; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1229 | #ifdef HDIO_DRIVE_CMD |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1230 | static unsigned long set_dkeep, get_dkeep, dkeep; |
| 1231 | static unsigned long set_standby, get_standby, standby_requested; |
| 1232 | static unsigned long set_xfermode, get_xfermode; |
| 1233 | static int xfermode_requested; |
| 1234 | static unsigned long set_lookahead, get_lookahead, lookahead; |
| 1235 | static unsigned long set_prefetch, get_prefetch, prefetch; |
| 1236 | static unsigned long set_defects, get_defects, defects; |
| 1237 | static unsigned long set_wcache, get_wcache, wcache; |
| 1238 | static unsigned long set_doorlock, get_doorlock, doorlock; |
| 1239 | static unsigned long set_seagate, get_seagate; |
| 1240 | static unsigned long set_standbynow, get_standbynow; |
| 1241 | static unsigned long set_sleepnow, get_sleepnow; |
| 1242 | static unsigned long get_powermode; |
| 1243 | static unsigned long set_apmmode, get_apmmode, apmmode; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1244 | #endif |
| 1245 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1246 | static int get_IDentity; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1247 | #endif |
| 1248 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1249 | static int unregister_hwif; |
| 1250 | static int hwif; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1251 | #endif |
| 1252 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1253 | static int scan_hwif; |
| 1254 | static int hwif_data; |
| 1255 | static int hwif_ctrl; |
| 1256 | static int hwif_irq; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1257 | #endif |
| 1258 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1259 | static int set_busstate, get_busstate, busstate; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1260 | #endif |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1261 | static int reread_partn; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1262 | |
| 1263 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1264 | static int perform_reset; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1265 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ |
| 1266 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1267 | static int perform_tristate, tristate; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1268 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ |
| 1269 | |
| 1270 | // Historically, if there was no HDIO_OBSOLETE_IDENTITY, then |
| 1271 | // then the HDIO_GET_IDENTITY only returned 142 bytes. |
| 1272 | // Otherwise, HDIO_OBSOLETE_IDENTITY returns 142 bytes, |
| 1273 | // and HDIO_GET_IDENTITY returns 512 bytes. But the latest |
| 1274 | // 2.5.xx kernels no longer define HDIO_OBSOLETE_IDENTITY |
| 1275 | // (which they should, but they should just return -EINVAL). |
| 1276 | // |
| 1277 | // So.. we must now assume that HDIO_GET_IDENTITY returns 512 bytes. |
| 1278 | // On a really old system, it will not, and we will be confused. |
| 1279 | // Too bad, really. |
| 1280 | |
| 1281 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1282 | static const char * const cfg_str[] = |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1283 | { "", " HardSect", " SoftSect", " NotMFM", |
| 1284 | " HdSw>15uSec", " SpinMotCtl", " Fixed", " Removeable", |
| 1285 | " DTR<=5Mbs", " DTR>5Mbs", " DTR>10Mbs", " RotSpdTol>.5%", |
| 1286 | " dStbOff", " TrkOff", " FmtGapReq", " nonMagnetic" |
| 1287 | }; |
| 1288 | |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1289 | static const char * const BuffType[] = {"unknown", "1Sect", "DualPort", "DualPortCache"}; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1290 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1291 | static void dump_identity (const struct hd_driveid *id) |
| 1292 | { |
| 1293 | int i; |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 1294 | char pmodes[64], dmodes[128], umodes[128]; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1295 | const unsigned short int *id_regs= (const void*) id; |
| 1296 | unsigned long capacity; |
| 1297 | |
Rob Landley | 0a7c8ef | 2006-02-22 17:01:00 +0000 | [diff] [blame] | 1298 | pmodes[0] = dmodes[0] = umodes[0] = '\0'; |
| 1299 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1300 | printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={", |
| 1301 | id->model, id->fw_rev, id->serial_no); |
| 1302 | for (i=0; i<=15; i++) |
| 1303 | if_printf((id->config & (1<<i)),"%s", cfg_str[i]); |
| 1304 | |
| 1305 | printf(" }\n RawCHS=%u/%u/%u, TrkSize=%u, SectSize=%u, ECCbytes=%u\n", |
| 1306 | id->cyls, id->heads, id->sectors, id->track_bytes, |
| 1307 | id->sector_bytes, id->ecc_bytes); |
| 1308 | |
| 1309 | if (id->buf_type > 3) |
| 1310 | printf("%s%u", " BuffType=", id->buf_type); |
| 1311 | else |
| 1312 | printf("%s%s", " BuffType=", BuffType[id->buf_type]); |
| 1313 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1314 | printf(", BuffSize=%ukB, MaxMultSect=%u", id->buf_size/2, id->max_multsect); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1315 | if (id->max_multsect) |
| 1316 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1317 | printf(", MultSect="); |
| 1318 | if (!(id->multsect_valid&1)) |
| 1319 | printf("?%u?", id->multsect); |
| 1320 | else if (id->multsect) |
| 1321 | printf("%u", id->multsect); |
| 1322 | else |
| 1323 | printf("off"); |
| 1324 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1325 | printf("\n"); |
| 1326 | if (id->tPIO <= 5) |
| 1327 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1328 | strcat(pmodes, "pio0 "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1329 | if_strcat((id->tPIO >= 1), pmodes, "pio1 "); |
| 1330 | if_strcat((id->tPIO >= 2), pmodes, "pio2 "); |
| 1331 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1332 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1333 | if_printf((!(id->field_valid&1))," (maybe):"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1334 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 1335 | capacity = (id->cur_capacity0 << 16) | id->cur_capacity1; |
| 1336 | #else |
| 1337 | capacity = (id->cur_capacity1 << 16) | id->cur_capacity0; |
| 1338 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1339 | printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1340 | id->cur_sectors, capacity , |
| 1341 | ((id->capability&2)==0)?"no":"yes"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1342 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1343 | if_printf((id->capability&2),", LBAsects=%u", id->lba_capacity); |
| 1344 | |
| 1345 | if (id->capability&1) |
| 1346 | { |
| 1347 | if (id->dma_1word | id->dma_mword) |
| 1348 | { |
| 1349 | if_strcat((id->dma_1word & 0x100), dmodes, "*"); |
| 1350 | if_strcat((id->dma_1word & 1), dmodes, "sdma0 "); |
| 1351 | if_strcat((id->dma_1word & 0x200), dmodes, "*"); |
| 1352 | if_strcat((id->dma_1word & 2), dmodes, "sdma1 "); |
| 1353 | if_strcat((id->dma_1word & 0x400), dmodes, "*"); |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 1354 | if_strcat((id->dma_1word & 4), dmodes, "sdma2 "); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1355 | if_strcat((id->dma_1word & 0xf800), dmodes, "*"); |
| 1356 | if_strcat((id->dma_1word & 0xf8), dmodes, "sdma? "); |
| 1357 | if_strcat((id->dma_mword & 0x100), dmodes, "*"); |
| 1358 | if_strcat((id->dma_mword & 1), dmodes, "mdma0 "); |
| 1359 | if_strcat((id->dma_mword & 0x200), dmodes, "*"); |
| 1360 | if_strcat((id->dma_mword & 2), dmodes, "mdma1 "); |
| 1361 | if_strcat((id->dma_mword & 0x400), dmodes, "*"); |
| 1362 | if_strcat((id->dma_mword & 4), dmodes, "mdma2 "); |
| 1363 | if_strcat((id->dma_mword & 0xf800), dmodes, "*"); |
| 1364 | if_strcat((id->dma_mword & 0xf8), dmodes, "mdma? "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | printf("\n IORDY="); |
| 1368 | if (id->capability&8) |
| 1369 | printf((id->capability&4) ? "on/off" : "yes"); |
| 1370 | else |
| 1371 | printf("no"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1372 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1373 | if ((id->capability&8) || (id->field_valid&2)) |
| 1374 | { |
| 1375 | if (id->field_valid&2) |
| 1376 | { |
| 1377 | printf(", tPIO={min:%u,w/IORDY:%u}", id->eide_pio, id->eide_pio_iordy); |
| 1378 | if_strcat((id->eide_pio_modes & 1), pmodes, "pio3 "); |
| 1379 | if_strcat((id->eide_pio_modes & 2), pmodes, "pio4 "); |
| 1380 | if_strcat((id->eide_pio_modes &~3), pmodes, "pio? "); |
| 1381 | } |
| 1382 | if (id->field_valid&4) |
| 1383 | { |
| 1384 | if_strcat((id->dma_ultra & 0x100),umodes,"*"); |
| 1385 | if_strcat((id->dma_ultra & 0x001),umodes,"udma0 "); |
| 1386 | if_strcat((id->dma_ultra & 0x200),umodes,"*"); |
| 1387 | if_strcat((id->dma_ultra & 0x002),umodes,"udma1 "); |
| 1388 | if_strcat((id->dma_ultra & 0x400),umodes,"*"); |
| 1389 | if_strcat((id->dma_ultra & 0x004),umodes,"udma2 "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1390 | #ifdef __NEW_HD_DRIVE_ID |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1391 | if (id->hw_config & 0x2000) |
| 1392 | { |
| 1393 | #else /* !__NEW_HD_DRIVE_ID */ |
| 1394 | if (id->word93 & 0x2000) |
| 1395 | { |
| 1396 | #endif /* __NEW_HD_DRIVE_ID */ |
| 1397 | if_strcat((id->dma_ultra & 0x0800),umodes,"*"); |
| 1398 | if_strcat((id->dma_ultra & 0x0008),umodes,"udma3 "); |
| 1399 | if_strcat((id->dma_ultra & 0x1000),umodes,"*"); |
| 1400 | if_strcat((id->dma_ultra & 0x0010),umodes,"udma4 "); |
| 1401 | if_strcat((id->dma_ultra & 0x2000),umodes,"*"); |
| 1402 | if_strcat((id->dma_ultra & 0x0020),umodes,"udma5 "); |
| 1403 | if_strcat((id->dma_ultra & 0x4000),umodes,"*"); |
| 1404 | if_strcat((id->dma_ultra & 0x0040),umodes,"udma6 "); |
| 1405 | if_strcat((id->dma_ultra & 0x8000),umodes,"*"); |
| 1406 | if_strcat((id->dma_ultra & 0x0080),umodes,"udma7 "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1407 | } |
| 1408 | } |
| 1409 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1410 | if_printf(((id->capability&1) && (id->field_valid&2)), |
| 1411 | ", tDMA={min:%u,rec:%u}", id->eide_dma_min, id->eide_dma_time); |
| 1412 | printf("\n PIO modes: %s", pmodes); |
| 1413 | if_printf((*dmodes),"\n DMA modes: %s", dmodes); |
| 1414 | if_printf((*umodes),"\n UDMA modes: %s", umodes); |
| 1415 | |
| 1416 | printf("\n AdvancedPM=%s",((id_regs[83]&8)==0)?"no":"yes"); |
| 1417 | if (id_regs[83] & 8) |
| 1418 | { |
| 1419 | if (!(id_regs[86]&8)) |
| 1420 | printf(": disabled (255)"); |
| 1421 | else if ((id_regs[91]&0xFF00)!=0x4000) |
| 1422 | printf(": unknown setting"); |
| 1423 | else |
| 1424 | printf(": mode=0x%02X (%u)",id_regs[91]&0xFF,id_regs[91]&0xFF); |
| 1425 | } |
| 1426 | if_printf( (id_regs[82]&0x20)," WriteCache=%s",(id_regs[85]&0x20) ? "enabled" : "disabled"); |
| 1427 | #ifdef __NEW_HD_DRIVE_ID |
| 1428 | if ((id->minor_rev_num && id->minor_rev_num <= 31) || (id->major_rev_num && id->minor_rev_num <= 31)) |
| 1429 | { |
| 1430 | printf("\n Drive conforms to: "); |
| 1431 | if_else_printf((id->minor_rev_num <= 31),"%s: ","unknown: ", minor_str[id->minor_rev_num]); |
| 1432 | if (id->major_rev_num < 31) |
| 1433 | { |
| 1434 | for (i=0; i <= 15; i++) |
| 1435 | if_printf((id->major_rev_num & (1<<i))," %u", i); |
| 1436 | } |
| 1437 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1438 | #endif /* __NEW_HD_DRIVE_ID */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1439 | printf("\n\n * signifies the current active mode\n\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1440 | } |
| 1441 | #endif |
| 1442 | |
| 1443 | static void flush_buffer_cache (int fd) |
| 1444 | { |
| 1445 | fsync (fd); /* flush buffers */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1446 | bb_ioctl(fd, BLKFLSBUF, NULL,"BLKFLSBUF" ) ;/* do it again, big time */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1447 | #ifdef HDIO_DRIVE_CMD |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1448 | sleep(1); |
| 1449 | if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 1450 | bb_perror_msg("HDIO_DRIVE_CMD"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1451 | #endif |
| 1452 | } |
| 1453 | |
| 1454 | static int seek_to_zero (int fd) |
| 1455 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1456 | if (lseek(fd, (off_t) 0, SEEK_SET)) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1457 | return 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1458 | return 0; |
| 1459 | } |
| 1460 | |
| 1461 | static int read_big_block (int fd, char *buf) |
| 1462 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1463 | |
| 1464 | const char *string; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1465 | int i, rc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1466 | if ((rc = read(fd, buf, TIMING_BUF_BYTES)) != TIMING_BUF_BYTES) |
| 1467 | { |
| 1468 | switch(rc) |
| 1469 | { |
| 1470 | case -1: |
| 1471 | string = "read()"; |
| 1472 | break; |
| 1473 | case 0: |
| 1474 | string = "read() hit EOF - device too small"; |
| 1475 | break; |
| 1476 | default: |
| 1477 | string = "read(%u) returned %u bytes"; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1478 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1479 | bb_error_msg(string, TIMING_BUF_BYTES, rc); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1480 | return 1; |
| 1481 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1482 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1483 | /* access all sectors of buf to ensure the read fully completed */ |
| 1484 | for (i = 0; i < TIMING_BUF_BYTES; i += 512) |
| 1485 | buf[i] &= 1; |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 1489 | static double correction; |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1490 | |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 1491 | static void do_time (int flag, int fd) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1492 | /* |
| 1493 | flag = 0 time_cache |
| 1494 | flag = 1 time_device |
| 1495 | */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1496 | { |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1497 | int i; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1498 | char *buf; |
| 1499 | double elapsed; |
| 1500 | struct itimerval e1, e2; |
| 1501 | int shmid; |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1502 | int timing_MB = TIMING_MB; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1503 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1504 | if ((shmid = shmget(IPC_PRIVATE, TIMING_BUF_BYTES, 0600)) == -1) |
| 1505 | { |
| 1506 | bb_error_msg (bb_msg_shared_mem,"allocate"); /*"could not allocate sharedmem buf"*/ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1507 | return; |
| 1508 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1509 | if (shmctl(shmid, SHM_LOCK, NULL) == -1) |
| 1510 | { |
| 1511 | bb_error_msg (bb_msg_shared_mem,"lock"); /*"could not lock sharedmem buf"*/ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1512 | (void) shmctl(shmid, IPC_RMID, NULL); |
| 1513 | return; |
| 1514 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1515 | if ((buf = shmat(shmid, (char *) 0, 0)) == (char *) -1) |
| 1516 | { |
| 1517 | bb_error_msg (bb_msg_shared_mem,"attach"); /*"could not attach sharedmem buf"*/ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1518 | (void) shmctl(shmid, IPC_RMID, NULL); |
| 1519 | return; |
| 1520 | } |
| 1521 | if (shmctl(shmid, IPC_RMID, NULL) == -1) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1522 | bb_error_msg ("shmctl(,IPC_RMID,)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1523 | |
| 1524 | /* Clear out the device request queues & give them time to complete */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1525 | sync_and_sleep(3); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1526 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1527 | if(flag == 0) /* Time cache */ |
| 1528 | { |
| 1529 | /* Calculate a correction factor for the basic |
| 1530 | * overhead of doing a read() from the buffer cache. |
| 1531 | * To do this, we read the data once to "cache it" and |
| 1532 | * to force full preallocation of our timing buffer, |
| 1533 | * and then we re-read it 10 times while timing it. |
| 1534 | * |
| 1535 | * getitimer() is used rather than gettimeofday() because |
| 1536 | * it is much more consistent (on my machine, at least). |
| 1537 | */ |
| 1538 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); |
| 1539 | if (seek_to_zero (fd)) |
| 1540 | return; |
| 1541 | if (read_big_block (fd, buf)) |
| 1542 | return; |
| 1543 | printf(" Timing buffer-cache reads: "); |
| 1544 | fflush(stdout); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1545 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1546 | /* Clear out the device request queues & give them time to complete */ |
| 1547 | sync_and_sleep(1); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1548 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1549 | /* Time re-reading from the buffer-cache */ |
| 1550 | getitimer(ITIMER_REAL, &e1); |
| 1551 | for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i) |
| 1552 | { |
| 1553 | if (seek_to_zero (fd)) |
| 1554 | goto quit; |
| 1555 | if (read_big_block (fd, buf)) |
| 1556 | goto quit; |
| 1557 | } |
| 1558 | getitimer(ITIMER_REAL, &e2); |
| 1559 | correction = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1560 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1561 | /* Now remove the lseek() from the correction factor */ |
| 1562 | getitimer(ITIMER_REAL, &e1); |
| 1563 | for (i = (BUFCACHE_FACTOR * TIMING_BUF_COUNT) ; i > 0; --i) |
| 1564 | { |
| 1565 | if (seek_to_zero (fd)) |
| 1566 | goto quit; |
| 1567 | } |
| 1568 | getitimer(ITIMER_REAL, &e2); |
| 1569 | correction -= (e1.it_value.tv_sec - e2.it_value.tv_sec) |
| 1570 | + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1571 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1572 | if ((BUFCACHE_FACTOR * timing_MB) >= correction) /* more than 1MB/s */ |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1573 | printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n", |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1574 | (BUFCACHE_FACTOR * timing_MB), correction, |
| 1575 | (BUFCACHE_FACTOR * timing_MB) / correction); |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1576 | else |
| 1577 | printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n", |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1578 | (BUFCACHE_FACTOR * timing_MB), correction, |
| 1579 | (BUFCACHE_FACTOR * timing_MB) / correction * 1024); |
| 1580 | correction /= BUFCACHE_FACTOR; |
| 1581 | |
| 1582 | flush_buffer_cache(fd); |
| 1583 | sleep(1); |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1584 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1585 | else /* Time device */ |
| 1586 | { |
| 1587 | printf(" Timing buffered disk reads: "); |
| 1588 | fflush(stdout); |
| 1589 | |
| 1590 | /* |
| 1591 | * getitimer() is used rather than gettimeofday() because |
| 1592 | * it is much more consistent (on my machine, at least). |
| 1593 | */ |
| 1594 | setitimer(ITIMER_REAL, &(struct itimerval){{1000,0},{1000,0}}, NULL); |
| 1595 | |
| 1596 | /* Now do the timings for real */ |
| 1597 | getitimer(ITIMER_REAL, &e1); |
| 1598 | for (i = TIMING_BUF_COUNT; i > 0; --i) |
| 1599 | { |
| 1600 | if (read_big_block (fd, buf)) |
| 1601 | goto quit; |
| 1602 | } |
| 1603 | getitimer(ITIMER_REAL, &e2); |
| 1604 | |
| 1605 | elapsed = (e1.it_value.tv_sec - e2.it_value.tv_sec) + ((e1.it_value.tv_usec - e2.it_value.tv_usec) / 1000000.0); |
| 1606 | |
| 1607 | if (timing_MB >= elapsed) /* more than 1MB/s */ |
| 1608 | printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n",timing_MB, elapsed, timing_MB / elapsed); |
| 1609 | else |
| 1610 | printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n",timing_MB, elapsed, timing_MB / elapsed * 1024); |
| 1611 | |
| 1612 | /*"Hmm.. suspicious results: probably not enough free memory for a proper test.");*/ |
| 1613 | if (elapsed <= (correction * 2)) |
| 1614 | bb_error_msg(bb_msg_memory_exhausted); |
| 1615 | |
| 1616 | #if 0 /* the "estimate" is just plain wrong for many systems.. */ |
| 1617 | else if (correction != 0.0) { |
| 1618 | printf(" Estimating raw driver speed: "); |
| 1619 | elapsed -= correction; |
| 1620 | if (timing_MB >= elapsed) /* more than 1MB/s */ |
| 1621 | printf("%2d MB in %5.2f seconds =%6.2f MB/sec\n", |
| 1622 | timing_MB, elapsed, timing_MB / elapsed); |
| 1623 | else |
| 1624 | printf("%2d MB in %5.2f seconds =%6.2f kB/sec\n", |
| 1625 | timing_MB, elapsed, timing_MB / elapsed * 1024); |
| 1626 | } |
Eric Andersen | 50af12d | 2003-08-06 08:47:59 +0000 | [diff] [blame] | 1627 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1628 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1629 | quit: |
| 1630 | if (-1 == shmdt(buf)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1631 | bb_error_msg (bb_msg_shared_mem,"detach"); /*"could not detach sharedmem buf"*/ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1634 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1635 | static void no_scsi (void) |
| 1636 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1637 | /*" operation not supported on SCSI disks"*/ |
| 1638 | if (is_scsi_hd) |
| 1639 | bb_error_msg_and_die(bb_msg_op_not_supp,"SCSI"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | static void no_xt (void) |
| 1643 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1644 | if (is_xt_hd) |
| 1645 | bb_error_msg_and_die(bb_msg_op_not_supp,"XT"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | static void on_off (unsigned int value) |
| 1649 | { |
| 1650 | printf(value ? " (on)\n" : " (off)\n"); |
| 1651 | } |
| 1652 | |
| 1653 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
| 1654 | static void bus_state_value (unsigned int value) |
| 1655 | { |
| 1656 | const char *string; |
| 1657 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1658 | switch (value) |
| 1659 | { |
| 1660 | case BUSSTATE_ON: |
| 1661 | string = " (on)\n"; |
| 1662 | break; |
| 1663 | case BUSSTATE_OFF: |
| 1664 | string = " (off)\n"; |
| 1665 | break; |
| 1666 | case BUSSTATE_TRISTATE: |
| 1667 | string = " (tristate)\n"; |
| 1668 | break; |
| 1669 | default: |
| 1670 | string = " (unknown: %d)\n"; |
| 1671 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1672 | } |
| 1673 | printf(string, value); |
| 1674 | } |
| 1675 | #endif |
| 1676 | |
| 1677 | #ifdef HDIO_DRIVE_CMD |
| 1678 | static void interpret_standby (unsigned int standby) |
| 1679 | { |
| 1680 | printf(" ("); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1681 | switch(standby) |
| 1682 | { |
| 1683 | case 0: |
| 1684 | printf("off"); |
| 1685 | break; |
| 1686 | case 252: |
| 1687 | printf("21 minutes"); |
| 1688 | break; |
| 1689 | case 253: |
| 1690 | printf("vendor-specific"); |
| 1691 | break; |
| 1692 | case 254: |
| 1693 | printf("?reserved"); |
| 1694 | break; |
| 1695 | case 255: |
| 1696 | printf("21 minutes + 15 seconds"); |
| 1697 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1698 | default: |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1699 | if (standby <= 240) |
| 1700 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1701 | unsigned int secs = standby * 5; |
| 1702 | unsigned int mins = secs / 60; |
| 1703 | secs %= 60; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1704 | if_printf(mins,"%u minutes", mins); |
| 1705 | if_printf((mins && secs)," + "); |
| 1706 | if_printf(secs,"%u seconds", secs); |
| 1707 | } |
| 1708 | else if (standby <= 251) |
| 1709 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1710 | unsigned int mins = (standby - 240) * 30; |
| 1711 | unsigned int hrs = mins / 60; |
| 1712 | mins %= 60; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1713 | if_printf(hrs,"%u hours", hrs); |
| 1714 | if_printf((hrs && mins)," + "); |
| 1715 | if_printf(mins,"%u minutes", mins); |
| 1716 | } |
| 1717 | else |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1718 | printf("illegal value"); |
| 1719 | break; |
| 1720 | } |
| 1721 | printf(")\n"); |
| 1722 | } |
| 1723 | |
| 1724 | struct xfermode_entry { |
| 1725 | int val; |
| 1726 | const char *name; |
| 1727 | }; |
| 1728 | |
| 1729 | static const struct xfermode_entry xfermode_table[] = { |
| 1730 | { 8, "pio0" }, |
| 1731 | { 9, "pio1" }, |
| 1732 | { 10, "pio2" }, |
| 1733 | { 11, "pio3" }, |
| 1734 | { 12, "pio4" }, |
| 1735 | { 13, "pio5" }, |
| 1736 | { 14, "pio6" }, |
| 1737 | { 15, "pio7" }, |
| 1738 | { 16, "sdma0" }, |
| 1739 | { 17, "sdma1" }, |
| 1740 | { 18, "sdma2" }, |
| 1741 | { 19, "sdma3" }, |
| 1742 | { 20, "sdma4" }, |
| 1743 | { 21, "sdma5" }, |
| 1744 | { 22, "sdma6" }, |
| 1745 | { 23, "sdma7" }, |
| 1746 | { 32, "mdma0" }, |
| 1747 | { 33, "mdma1" }, |
| 1748 | { 34, "mdma2" }, |
| 1749 | { 35, "mdma3" }, |
| 1750 | { 36, "mdma4" }, |
| 1751 | { 37, "mdma5" }, |
| 1752 | { 38, "mdma6" }, |
| 1753 | { 39, "mdma7" }, |
| 1754 | { 64, "udma0" }, |
| 1755 | { 65, "udma1" }, |
| 1756 | { 66, "udma2" }, |
| 1757 | { 67, "udma3" }, |
| 1758 | { 68, "udma4" }, |
| 1759 | { 69, "udma5" }, |
| 1760 | { 70, "udma6" }, |
| 1761 | { 71, "udma7" }, |
| 1762 | { 0, NULL } |
| 1763 | }; |
| 1764 | |
| 1765 | static int translate_xfermode(char * name) |
| 1766 | { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1767 | const struct xfermode_entry *tmp; |
| 1768 | char *endptr; |
| 1769 | int val = -1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1770 | |
| 1771 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1772 | for (tmp = xfermode_table; tmp->name != NULL; ++tmp) |
| 1773 | { |
| 1774 | if (!strcmp(name, tmp->name)) |
| 1775 | return tmp->val; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1776 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1777 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1778 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1779 | val = strtol(name, &endptr, 10); |
| 1780 | if (*endptr == '\0') |
| 1781 | return val; |
| 1782 | |
| 1783 | return -1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | static void interpret_xfermode (unsigned int xfermode) |
| 1787 | { |
| 1788 | printf(" ("); |
| 1789 | switch(xfermode) { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1790 | case 0: |
| 1791 | printf("default PIO mode"); |
| 1792 | break; |
| 1793 | case 1: |
| 1794 | printf("default PIO mode, disable IORDY"); |
| 1795 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1796 | case 8: |
| 1797 | case 9: |
| 1798 | case 10: |
| 1799 | case 11: |
| 1800 | case 12: |
| 1801 | case 13: |
| 1802 | case 14: |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1803 | case 15: |
| 1804 | printf("PIO flow control mode%u", xfermode-8); |
| 1805 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1806 | case 16: |
| 1807 | case 17: |
| 1808 | case 18: |
| 1809 | case 19: |
| 1810 | case 20: |
| 1811 | case 21: |
| 1812 | case 22: |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1813 | case 23: |
| 1814 | printf("singleword DMA mode%u", xfermode-16); |
| 1815 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1816 | case 32: |
| 1817 | case 33: |
| 1818 | case 34: |
| 1819 | case 35: |
| 1820 | case 36: |
| 1821 | case 37: |
| 1822 | case 38: |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1823 | case 39: |
| 1824 | printf("multiword DMA mode%u", xfermode-32); |
| 1825 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1826 | case 64: |
| 1827 | case 65: |
| 1828 | case 66: |
| 1829 | case 67: |
| 1830 | case 68: |
| 1831 | case 69: |
| 1832 | case 70: |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1833 | case 71: |
| 1834 | printf("UltraDMA mode%u", xfermode-64); |
| 1835 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1836 | default: |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1837 | printf("unknown, probably not valid"); |
| 1838 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1839 | } |
| 1840 | printf(")\n"); |
| 1841 | } |
| 1842 | #endif /* HDIO_DRIVE_CMD */ |
| 1843 | |
| 1844 | #ifndef VXVM_MAJOR |
| 1845 | #define VXVM_MAJOR 199 |
| 1846 | #endif |
| 1847 | |
| 1848 | #ifndef CCISS_MAJOR |
| 1849 | #define CCISS_MAJOR 104 |
| 1850 | #endif |
| 1851 | |
| 1852 | static void process_dev (char *devname) |
| 1853 | { |
| 1854 | int fd; |
| 1855 | static long parm, multcount; |
| 1856 | struct stat stat_buf; |
| 1857 | #ifndef HDIO_DRIVE_CMD |
| 1858 | int force_operation = 0; |
| 1859 | #endif |
Rob Landley | c5b1d4d | 2006-03-13 15:45:16 +0000 | [diff] [blame] | 1860 | xstat(devname,&stat_buf); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1861 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1862 | switch(major(stat_buf.st_rdev)) |
| 1863 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1864 | #ifdef SCSI_DISK0_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1865 | case (SCSI_DISK0_MAJOR): |
| 1866 | case (SCSI_DISK1_MAJOR): |
| 1867 | case (SCSI_DISK2_MAJOR): |
| 1868 | case (SCSI_DISK3_MAJOR): |
| 1869 | case (SCSI_DISK4_MAJOR): |
| 1870 | case (SCSI_DISK5_MAJOR): |
| 1871 | case (SCSI_DISK6_MAJOR): |
| 1872 | case (SCSI_DISK7_MAJOR): |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1873 | #else |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1874 | case (SCSI_DISK_MAJOR): |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1875 | #endif |
| 1876 | #ifdef MD_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1877 | case (MD_MAJOR): |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1878 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1879 | case (VXVM_MAJOR): |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1880 | #ifdef LVM_BLK_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1881 | case (LVM_BLK_MAJOR): |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1882 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1883 | case (CCISS_MAJOR): |
| 1884 | is_scsi_hd = 1; |
| 1885 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1886 | #ifdef XT_DISK_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1887 | case (XT_DISK_MAJOR): |
| 1888 | is_xt_hd = 1; |
| 1889 | break; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1890 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1891 | case IDE0_MAJOR: |
| 1892 | case IDE1_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1893 | #ifdef IDE2_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1894 | case IDE2_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1895 | #endif |
| 1896 | #ifdef IDE3_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1897 | case IDE3_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1898 | #endif |
| 1899 | #ifdef IDE4_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1900 | case IDE4_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1901 | #endif |
| 1902 | #ifdef IDE5_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1903 | case IDE5_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1904 | #endif |
| 1905 | #ifdef IDE6_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1906 | case IDE6_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1907 | #endif |
| 1908 | #ifdef IDE7_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1909 | case IDE7_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1910 | #endif |
| 1911 | #ifdef IDE8_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1912 | case IDE8_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1913 | #endif |
| 1914 | #ifdef IDE9_MAJOR |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1915 | case IDE9_MAJOR: |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1916 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1917 | break; /* do nothing */ |
| 1918 | default: |
| 1919 | bb_error_msg_and_die("%s not supported",devname); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1922 | fd = bb_xopen (devname, O_RDONLY|O_NONBLOCK); |
| 1923 | if_printf( (!quiet),"\n%s:\n", devname); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1924 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1925 | if (set_readahead) |
| 1926 | { |
Eric Andersen | f828da0 | 2004-07-20 22:53:59 +0000 | [diff] [blame] | 1927 | if_printf(get_readahead," setting fs readahead to %ld\n", Xreadahead); |
| 1928 | bb_ioctl(fd, BLKRASET,(int *)Xreadahead,"BLKRASET"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1929 | } |
| 1930 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1931 | if (unregister_hwif) |
| 1932 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1933 | no_scsi(); |
| 1934 | printf(" attempting to unregister hwif#%u\n", hwif); |
Eric Andersen | a68ea1c | 2006-01-30 22:48:39 +0000 | [diff] [blame] | 1935 | 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] | 1936 | } |
| 1937 | #endif |
| 1938 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1939 | if (scan_hwif) |
| 1940 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1941 | int args[3]; |
| 1942 | no_scsi(); |
| 1943 | printf(" attempting to scan hwif (0x%x, 0x%x, %u)\n", hwif_data, hwif_ctrl, hwif_irq); |
| 1944 | args[0] = hwif_data; |
| 1945 | args[1] = hwif_ctrl; |
| 1946 | args[2] = hwif_irq; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1947 | bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1948 | } |
| 1949 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1950 | if (set_piomode) |
| 1951 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1952 | no_scsi(); |
| 1953 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1954 | |
| 1955 | if (noisy_piomode) |
| 1956 | { |
| 1957 | printf(" attempting to "); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1958 | if (piomode == 255) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1959 | printf("auto-tune PIO mode\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1960 | else if (piomode < 100) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1961 | printf("set PIO mode to %d\n", piomode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1962 | else if (piomode < 200) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1963 | printf("set MDMA mode to %d\n", (piomode-100)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1964 | else |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1965 | printf("set UDMA mode to %d\n", (piomode-200)); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1966 | } |
Eric Andersen | a68ea1c | 2006-01-30 22:48:39 +0000 | [diff] [blame] | 1967 | 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] | 1968 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1969 | if (set_io32bit) |
| 1970 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1971 | no_scsi(); |
| 1972 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1973 | if_printf(get_io32bit," setting 32-bit IO_support flag to %ld\n", io32bit); |
| 1974 | bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1975 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1976 | if (set_mult) |
| 1977 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1978 | no_scsi(); |
| 1979 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1980 | if_printf(get_mult, " setting multcount to %ld\n", mult); |
| 1981 | if(ioctl(fd, HDIO_SET_MULTCOUNT, mult)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 1982 | bb_perror_msg("HDIO_SET_MULTCOUNT"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1983 | #ifndef HDIO_DRIVE_CMD |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1984 | else |
| 1985 | force_operation = 1; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1986 | #endif |
| 1987 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1988 | if (set_readonly) |
| 1989 | { |
| 1990 | if_printf_on_off(get_readonly," setting readonly to %ld", readonly); |
| 1991 | bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1992 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1993 | if (set_unmask) |
| 1994 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1995 | no_scsi(); |
| 1996 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 1997 | if_printf_on_off(get_unmask," setting unmaskirq to %ld", unmask); |
| 1998 | bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 1999 | } |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 2000 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2001 | if (set_dma) |
| 2002 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2003 | no_scsi(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2004 | if_printf_on_off(get_dma," setting using_dma to %ld", dma); |
| 2005 | bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2006 | } |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 2007 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2008 | if (set_dma_q) |
| 2009 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2010 | no_scsi(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2011 | if_printf_on_off(get_dma_q," setting DMA queue_depth to %ld", dma_q); |
| 2012 | bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2013 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2014 | if (set_nowerr) |
| 2015 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2016 | no_scsi(); |
| 2017 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2018 | if_printf_on_off(get_nowerr," setting nowerr to %ld", nowerr); |
| 2019 | bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr,"HDIO_SET_NOWERR"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2020 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2021 | if (set_keep) |
| 2022 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2023 | no_scsi(); |
| 2024 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2025 | if_printf_on_off(get_keep," setting keep_settings to %ld", keep); |
| 2026 | bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep,"HDIO_SET_KEEPSETTINGS"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2027 | } |
| 2028 | #ifdef HDIO_DRIVE_CMD |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2029 | if (set_doorlock) |
| 2030 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2031 | unsigned char args[4] = {0,0,0,0}; |
| 2032 | no_scsi(); |
| 2033 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2034 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2035 | args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2036 | if_printf_on_off(get_doorlock," setting drive doorlock to %ld", doorlock); |
| 2037 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(doorlock)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2038 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2039 | if (set_dkeep) |
| 2040 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2041 | /* lock/unlock the drive's "feature" settings */ |
| 2042 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; |
| 2043 | no_scsi(); |
| 2044 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2045 | |
| 2046 | if_printf_on_off(get_dkeep," setting drive keep features to %ld", dkeep); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2047 | args[2] = dkeep ? 0x66 : 0xcc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2048 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(keepsettings)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2049 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2050 | if (set_defects) |
| 2051 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2052 | unsigned char args[4] = {WIN_SETFEATURES,0,0x04,0}; |
| 2053 | no_scsi(); |
| 2054 | args[2] = defects ? 0x04 : 0x84; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2055 | if_printf(get_defects," setting drive defect-mgmt to %ld\n", defects); |
| 2056 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(defectmgmt)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2057 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2058 | if (set_prefetch) |
| 2059 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2060 | unsigned char args[4] = {WIN_SETFEATURES,0,0xab,0}; |
| 2061 | no_scsi(); |
| 2062 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2063 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2064 | args[1] = prefetch; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2065 | if_printf(get_prefetch," setting drive prefetch to %ld\n", prefetch); |
| 2066 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2067 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2068 | if (set_xfermode) |
| 2069 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2070 | unsigned char args[4] = {WIN_SETFEATURES,0,3,0}; |
| 2071 | no_scsi(); |
| 2072 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2073 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2074 | args[1] = xfermode_requested; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2075 | if (get_xfermode) |
| 2076 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2077 | printf(" setting xfermode to %d", xfermode_requested); |
| 2078 | interpret_xfermode(xfermode_requested); |
| 2079 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2080 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD(setxfermode)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2081 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2082 | if (set_lookahead) |
| 2083 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2084 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; |
| 2085 | no_scsi(); |
| 2086 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2087 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2088 | args[2] = lookahead ? 0xaa : 0x55; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2089 | if_printf_on_off(get_lookahead," setting drive read-lookahead to %ld", lookahead); |
| 2090 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2091 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2092 | if (set_apmmode) |
| 2093 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2094 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; |
| 2095 | no_scsi(); |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2096 | apmmode=check_if_min_and_set_val(apmmode,1); |
| 2097 | apmmode=check_if_maj_and_set_val(apmmode,255); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2098 | if_printf(get_apmmode," setting APM level to"); |
| 2099 | if (apmmode==255) |
| 2100 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2101 | /* disable Advanced Power Management */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2102 | args[2] = 0x85; /* feature register */ |
| 2103 | if_printf(get_apmmode," disabled\n"); |
| 2104 | } |
| 2105 | else |
| 2106 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2107 | /* set Advanced Power Management mode */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2108 | args[2] = 0x05; /* feature register */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2109 | args[1] = apmmode; /* sector count register */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2110 | if_printf(get_apmmode," 0x%02lX (%ld)\n",apmmode,apmmode); |
| 2111 | } |
| 2112 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args,"HDIO_DRIVE_CMD"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2113 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2114 | if (set_wcache) |
| 2115 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2116 | #ifdef DO_FLUSHCACHE |
| 2117 | #ifndef WIN_FLUSHCACHE |
| 2118 | #define WIN_FLUSHCACHE 0xe7 |
| 2119 | #endif |
| 2120 | unsigned char flushcache[4] = {WIN_FLUSHCACHE,0,0,0}; |
| 2121 | #endif /* DO_FLUSHCACHE */ |
| 2122 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; |
| 2123 | no_scsi(); |
| 2124 | no_xt(); |
| 2125 | args[2] = wcache ? 0x02 : 0x82; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2126 | if_printf_on_off(get_wcache," setting drive write-caching to %ld", wcache); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2127 | #ifdef DO_FLUSHCACHE |
| 2128 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2129 | bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2130 | #endif /* DO_FLUSHCACHE */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2131 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2132 | #ifdef DO_FLUSHCACHE |
| 2133 | if (!wcache && ioctl(fd, HDIO_DRIVE_CMD, &flushcache)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2134 | bb_perror_msg ("HDIO_DRIVE_CMD(flushcache)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2135 | #endif /* DO_FLUSHCACHE */ |
| 2136 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2137 | if (set_standbynow) |
| 2138 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2139 | #ifndef WIN_STANDBYNOW1 |
| 2140 | #define WIN_STANDBYNOW1 0xE0 |
| 2141 | #endif |
| 2142 | #ifndef WIN_STANDBYNOW2 |
| 2143 | #define WIN_STANDBYNOW2 0x94 |
| 2144 | #endif |
| 2145 | unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0}; |
| 2146 | unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0}; |
| 2147 | no_scsi(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2148 | if_printf(get_standbynow," issuing standby command\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2149 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) |
| 2150 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2151 | bb_perror_msg("HDIO_DRIVE_CMD(standby)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2152 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2153 | if (set_sleepnow) |
| 2154 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2155 | #ifndef WIN_SLEEPNOW1 |
| 2156 | #define WIN_SLEEPNOW1 0xE6 |
| 2157 | #endif |
| 2158 | #ifndef WIN_SLEEPNOW2 |
| 2159 | #define WIN_SLEEPNOW2 0x99 |
| 2160 | #endif |
| 2161 | unsigned char args1[4] = {WIN_SLEEPNOW1,0,0,0}; |
| 2162 | unsigned char args2[4] = {WIN_SLEEPNOW2,0,0,0}; |
| 2163 | no_scsi(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2164 | if_printf(get_sleepnow," issuing sleep command\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2165 | if (ioctl(fd, HDIO_DRIVE_CMD, &args1) |
| 2166 | && ioctl(fd, HDIO_DRIVE_CMD, &args2)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2167 | bb_perror_msg("HDIO_DRIVE_CMD(sleep)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2168 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2169 | if (set_seagate) |
| 2170 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2171 | unsigned char args[4] = {0xfb,0,0,0}; |
| 2172 | no_scsi(); |
| 2173 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2174 | if_printf(get_seagate," disabling Seagate auto powersaving mode\n"); |
| 2175 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2176 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2177 | if (set_standby) |
| 2178 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2179 | unsigned char args[4] = {WIN_SETIDLE1,standby_requested,0,0}; |
| 2180 | no_scsi(); |
| 2181 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2182 | if (get_standby) |
| 2183 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2184 | printf(" setting standby to %lu", standby_requested); |
| 2185 | interpret_standby(standby_requested); |
| 2186 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2187 | bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2188 | } |
| 2189 | #else /* HDIO_DRIVE_CMD */ |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2190 | if (force_operation) |
| 2191 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2192 | char buf[512]; |
| 2193 | flush_buffer_cache(fd); |
| 2194 | if (-1 == read(fd, buf, sizeof(buf))) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2195 | bb_error_msg("access failed"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2196 | } |
| 2197 | #endif /* HDIO_DRIVE_CMD */ |
| 2198 | |
| 2199 | if (!flagcount) |
| 2200 | verbose = 1; |
| 2201 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2202 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_mult || get_identity) |
| 2203 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2204 | no_scsi(); |
| 2205 | multcount = -1; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2206 | if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) |
| 2207 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2208 | if ((verbose && !is_xt_hd) || get_mult) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2209 | bb_perror_msg("HDIO_GET_MULTCOUNT"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2210 | } |
| 2211 | else if (verbose | get_mult) |
| 2212 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2213 | printf(" multcount = %2ld", multcount); |
| 2214 | on_off(multcount); |
| 2215 | } |
| 2216 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2217 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_io32bit) |
| 2218 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2219 | no_scsi(); |
| 2220 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2221 | if(ioctl(fd, HDIO_GET_32BIT, &parm)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2222 | bb_perror_msg("HDIO_GET_32BIT"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2223 | else |
| 2224 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2225 | printf(" IO_support =%3ld (", parm); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2226 | switch (parm) |
| 2227 | { |
| 2228 | case 0: |
| 2229 | printf("default "); |
| 2230 | case 2: |
| 2231 | printf("16-bit)\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2232 | break; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2233 | case 1: |
| 2234 | printf("32-bit)\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2235 | break; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2236 | case 3: |
| 2237 | printf("32-bit w/sync)\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2238 | break; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2239 | case 8: |
| 2240 | printf("Request-Queue-Bypass)\n"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2241 | break; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2242 | default: |
| 2243 | printf("\?\?\?)\n"); |
| 2244 | /*esac*/ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2245 | } |
| 2246 | } |
| 2247 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2248 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_unmask) |
| 2249 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2250 | no_scsi(); |
| 2251 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2252 | bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR,(unsigned long *)parm, |
| 2253 | "HDIO_GET_UNMASKINTR"," unmaskirq = %2ld"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2256 | |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 2257 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2258 | if ((verbose && !is_scsi_hd) || get_dma) { |
| 2259 | no_scsi(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2260 | if(ioctl(fd, HDIO_GET_DMA, &parm)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2261 | bb_perror_msg("HDIO_GET_DMA"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2262 | else |
| 2263 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2264 | printf(" using_dma = %2ld", parm); |
| 2265 | if (parm == 8) |
| 2266 | printf(" (DMA-Assisted-PIO)\n"); |
| 2267 | else |
| 2268 | on_off(parm); |
| 2269 | } |
| 2270 | } |
| 2271 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2272 | if (get_dma_q) |
| 2273 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2274 | no_scsi(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2275 | bb_ioctl_on_off (fd, HDIO_GET_QDMA,(unsigned long *)parm, |
| 2276 | "HDIO_GET_QDMA"," queue_depth = %2ld"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2277 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2278 | if ((verbose && !is_scsi_hd && !is_xt_hd) || get_keep) |
| 2279 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2280 | no_scsi(); |
| 2281 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2282 | bb_ioctl_on_off (fd, HDIO_GET_KEEPSETTINGS,(unsigned long *)parm, |
| 2283 | "HDIO_GET_KEEPSETTINGS"," keepsettings = %2ld"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2286 | if (get_nowerr) |
| 2287 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2288 | no_scsi(); |
| 2289 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2290 | bb_ioctl_on_off (fd, HDIO_GET_NOWERR,(unsigned long *)&parm, |
| 2291 | " HDIO_GET_NOWERR"," nowerr = %2ld"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2292 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2293 | if (verbose || get_readonly) |
| 2294 | { |
| 2295 | bb_ioctl_on_off(fd, BLKROGET,(unsigned long *)parm, |
| 2296 | " BLKROGET"," readonly = %2ld"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2297 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2298 | if ((verbose && !is_scsi_hd) || get_readahead) |
| 2299 | { |
| 2300 | bb_ioctl_on_off (fd, BLKRAGET, (unsigned long *) parm, |
| 2301 | " BLKRAGET"," readahead = %2ld"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2302 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2303 | if (verbose || get_geom) |
| 2304 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2305 | static const char msg[] = " geometry = %u/%u/%u, sectors = %ld, start = %ld\n"; |
| 2306 | static struct hd_geometry g; |
| 2307 | #ifdef HDIO_GETGEO_BIG |
| 2308 | static struct hd_big_geometry bg; |
| 2309 | #endif |
| 2310 | |
| 2311 | if (ioctl(fd, BLKGETSIZE, &parm)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2312 | bb_perror_msg("BLKGETSIZE"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2313 | #ifdef HDIO_GETGEO_BIG |
| 2314 | else if (!ioctl(fd, HDIO_GETGEO_BIG, &bg)) |
| 2315 | printf(msg, bg.cylinders, bg.heads, bg.sectors, parm, bg.start); |
| 2316 | #endif |
| 2317 | else if (ioctl(fd, HDIO_GETGEO, &g)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2318 | bb_perror_msg("HDIO_GETGEO"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2319 | else |
| 2320 | printf(msg, g.cylinders, g.heads, g.sectors, parm, g.start); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2321 | } |
| 2322 | #ifdef HDIO_DRIVE_CMD |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2323 | if (get_powermode) |
| 2324 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2325 | #ifndef WIN_CHECKPOWERMODE1 |
| 2326 | #define WIN_CHECKPOWERMODE1 0xE5 |
| 2327 | #endif |
| 2328 | #ifndef WIN_CHECKPOWERMODE2 |
| 2329 | #define WIN_CHECKPOWERMODE2 0x98 |
| 2330 | #endif |
| 2331 | unsigned char args[4] = {WIN_CHECKPOWERMODE1,0,0,0}; |
| 2332 | const char *state; |
| 2333 | no_scsi(); |
| 2334 | if (ioctl(fd, HDIO_DRIVE_CMD, &args) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2335 | && (args[0] = WIN_CHECKPOWERMODE2) /* try again with 0x98 */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 2336 | && ioctl(fd, HDIO_DRIVE_CMD, &args)) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2337 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2338 | if (errno != EIO || args[0] != 0 || args[1] != 0) |
| 2339 | state = "unknown"; |
| 2340 | else |
| 2341 | state = "sleeping"; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2342 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2343 | else |
| 2344 | state = (args[2] == 255) ? "active/idle" : "standby"; |
| 2345 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2346 | printf(" drive state is: %s\n", state); |
| 2347 | } |
| 2348 | #endif |
| 2349 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2350 | if (perform_reset) |
| 2351 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2352 | no_scsi(); |
| 2353 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2354 | bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2355 | } |
| 2356 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ |
| 2357 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2358 | if (perform_tristate) |
| 2359 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2360 | unsigned char args[4] = {0,tristate,0,0}; |
| 2361 | no_scsi(); |
| 2362 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2363 | bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2364 | } |
| 2365 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ |
| 2366 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2367 | if (get_identity) |
| 2368 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2369 | static struct hd_driveid id; |
| 2370 | |
| 2371 | no_scsi(); |
| 2372 | no_xt(); |
| 2373 | |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2374 | if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) |
| 2375 | { |
| 2376 | if (multcount != -1) |
| 2377 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2378 | id.multsect = multcount; |
| 2379 | id.multsect_valid |= 1; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2380 | } |
| 2381 | else |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2382 | id.multsect_valid &= ~1; |
| 2383 | dump_identity(&id); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2384 | } |
| 2385 | else if (errno == -ENOMSG) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2386 | printf(" no identification info available\n"); |
| 2387 | else |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2388 | bb_perror_msg("HDIO_GET_IDENTITY"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2389 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2390 | |
| 2391 | if (get_IDentity) |
| 2392 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2393 | unsigned char args[4+512] = {WIN_IDENTIFY,0,0,1,}; |
| 2394 | unsigned i; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2395 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2396 | no_scsi(); |
| 2397 | no_xt(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2398 | |
| 2399 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) |
| 2400 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2401 | args[0] = WIN_PIDENTIFY; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2402 | if (ioctl(fd, HDIO_DRIVE_CMD, &args)) |
| 2403 | { |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2404 | bb_perror_msg("HDIO_DRIVE_CMD(identify)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2405 | goto identify_abort; |
| 2406 | } |
| 2407 | } |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2408 | for(i=0; i<(sizeof args)/2; i+=2) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2409 | __le16_to_cpus((uint16_t *)(&args[i])); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2410 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2411 | identify((void *)&args[4], NULL); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2412 | identify_abort: |
| 2413 | /* VOID */; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2414 | } |
| 2415 | #endif |
| 2416 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2417 | if (set_busstate) |
| 2418 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2419 | no_scsi(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2420 | if (get_busstate) |
| 2421 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2422 | printf(" setting bus state to %d", busstate); |
| 2423 | bus_state_value(busstate); |
| 2424 | } |
Eric Andersen | a68ea1c | 2006-01-30 22:48:39 +0000 | [diff] [blame] | 2425 | 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] | 2426 | } |
| 2427 | #endif |
| 2428 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2429 | if (get_busstate) |
| 2430 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2431 | no_scsi(); |
| 2432 | if (ioctl(fd, HDIO_GET_BUSSTATE, &parm)) |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2433 | bb_perror_msg("HDIO_GET_BUSSTATE"); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2434 | else |
| 2435 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2436 | printf(" busstate = %2ld", parm); |
| 2437 | bus_state_value(parm); |
| 2438 | } |
| 2439 | } |
| 2440 | #endif |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2441 | if (reread_partn) |
| 2442 | bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART"); |
| 2443 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2444 | |
| 2445 | if (do_ctimings) |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 2446 | do_time(0,fd); /*time cache */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2447 | if (do_timings) |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2448 | do_time(1,fd); /*time device */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2449 | if (do_flush) |
| 2450 | flush_buffer_cache (fd); |
| 2451 | close (fd); |
| 2452 | } |
| 2453 | |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2454 | static char * GET_NUMBER(char *p, unsigned long *flag, unsigned long *num) |
| 2455 | { |
| 2456 | *num = 0; |
| 2457 | while (isdigit(*p)) { |
| 2458 | *flag = 1; |
| 2459 | *num = (*num * 10) + (*p++ - '0'); |
| 2460 | } |
| 2461 | return p; |
| 2462 | } |
| 2463 | |
| 2464 | static char * GET_STRING(char *p, unsigned long *flag, int *num) |
| 2465 | { |
| 2466 | char *tmpstr; |
| 2467 | char name[32]; |
| 2468 | tmpstr = name; |
| 2469 | tmpstr[0] = '\0'; |
| 2470 | while (isalnum(*p) && (tmpstr - name) < 31) { |
| 2471 | tmpstr[0] = *p++; |
| 2472 | tmpstr[1] = '\0'; |
| 2473 | ++tmpstr; |
| 2474 | } |
| 2475 | *num = translate_xfermode(name); |
| 2476 | if (*num == -1) |
| 2477 | *flag = 0; |
| 2478 | else |
| 2479 | *flag = 1; |
| 2480 | return p; |
| 2481 | } |
| 2482 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2483 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
| 2484 | static int fromhex (unsigned char c) |
| 2485 | { |
| 2486 | if (c >= 'a' && c <= 'f') |
| 2487 | return 10 + (c - 'a'); |
| 2488 | if (c >= '0' && c <= '9') |
| 2489 | return (c - '0'); |
| 2490 | bb_error_msg_and_die("bad char: '%c' 0x%02x", c, c); |
| 2491 | } |
| 2492 | |
| 2493 | static int identify_from_stdin (void) |
| 2494 | { |
| 2495 | unsigned short sbuf[800]; |
| 2496 | unsigned char buf[1600], *b = (unsigned char *)buf; |
| 2497 | int i, count = read(0, buf, 1280); |
| 2498 | |
| 2499 | if (count != 1280) |
| 2500 | bb_error_msg_and_die("read(1280 bytes) failed (rc=%d)", count); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2501 | for (i = 0; count >= 4; ++i) |
| 2502 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2503 | sbuf[i] = (fromhex(b[0]) << 12) | (fromhex(b[1]) << 8) | (fromhex(b[2]) << 4) | fromhex(b[3]); |
| 2504 | __le16_to_cpus((uint16_t *)(&sbuf[i])); |
| 2505 | b += 5; |
| 2506 | count -= 5; |
| 2507 | } |
| 2508 | identify(sbuf, NULL); |
| 2509 | return 0; |
| 2510 | } |
| 2511 | #endif |
| 2512 | |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2513 | static void missing_arg(int arg, char c, char* add) |
| 2514 | { |
| 2515 | if (!arg) |
| 2516 | bb_error_msg("-%c: missing value %s", c, (add!=NULL)? add :""); |
| 2517 | } |
| 2518 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2519 | /* our main() routine: */ |
| 2520 | int hdparm_main(int argc, char **argv) |
| 2521 | { |
| 2522 | char c, *p; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2523 | |
| 2524 | ++argv; |
| 2525 | if (!--argc) |
| 2526 | bb_show_usage(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2527 | |
| 2528 | while (argc--) |
| 2529 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2530 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2531 | if (!strcmp("-Istdin", *argv)) |
| 2532 | { |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 2533 | return identify_from_stdin(); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2534 | } |
| 2535 | #endif |
| 2536 | p = *argv++; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2537 | if (*p == '-') |
| 2538 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2539 | if (!*++p) |
| 2540 | bb_show_usage(); |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2541 | while ((c = *p++)) |
| 2542 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2543 | ++flagcount; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2544 | switch (c) |
| 2545 | { |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2546 | case 'V': |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2547 | /*bb_error_msg_and_die("%s", VERSION);*/ |
| 2548 | /* We have to return 0 here and not 1 */ |
| 2549 | printf("%s %s\n",bb_applet_name, VERSION); |
"Vladimir N. Oleynik" | b4b6d26 | 2005-10-15 14:10:36 +0000 | [diff] [blame] | 2550 | return EXIT_SUCCESS; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2551 | case 'v': |
| 2552 | verbose = 1; |
| 2553 | break; |
| 2554 | #ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY |
| 2555 | case 'I': |
| 2556 | get_IDentity = 1; |
| 2557 | break; |
| 2558 | case 'i': |
| 2559 | get_identity = 1; |
| 2560 | break; |
| 2561 | #endif |
| 2562 | case 'g': |
| 2563 | get_geom = 1; |
| 2564 | break; |
| 2565 | case 'f': |
| 2566 | do_flush = 1; |
| 2567 | break; |
| 2568 | case 'q': |
| 2569 | quiet = 1; |
| 2570 | noisy = 0; |
| 2571 | break; |
| 2572 | case 'u': |
| 2573 | get_unmask = noisy; |
| 2574 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2575 | if (!*p && argc && isdigit(**argv)) |
| 2576 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2577 | if((set_unmask = set_flag(p,'1'))==1) |
| 2578 | unmask = *p++ - '0'; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2579 | break; |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 2580 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2581 | case 'd': |
| 2582 | get_dma = noisy; |
| 2583 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2584 | if (!*p && argc && isdigit(**argv)) |
| 2585 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2586 | if((set_dma = set_flag(p,'9'))==1) |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2587 | dma = *p++ - '0'; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2588 | break; |
Eric Andersen | 0a57a79 | 2003-08-06 08:57:35 +0000 | [diff] [blame] | 2589 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2590 | case 'n': |
| 2591 | get_nowerr = noisy; |
| 2592 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2593 | if (!*p && argc && isdigit(**argv)) |
| 2594 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2595 | if((set_nowerr = set_flag(p,'1'))==1) |
| 2596 | nowerr = *p++ - '0'; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | case 'p': |
| 2599 | noisy_piomode = noisy; |
| 2600 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2601 | if (!*p && argc && isalnum(**argv)) |
| 2602 | p = *argv++, --argc; |
| 2603 | p=GET_STRING(p,&set_piomode,&piomode); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2604 | break; |
| 2605 | case 'r': |
| 2606 | get_readonly = noisy; |
| 2607 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2608 | if (!*p && argc && isdigit(**argv)) |
| 2609 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2610 | if((set_readonly = set_flag(p,'1'))==1) |
| 2611 | readonly = *p++ - '0'; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | case 'm': |
| 2614 | get_mult = noisy; |
| 2615 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2616 | if (!*p && argc && isalnum(**argv)) |
| 2617 | p = *argv++, --argc; |
| 2618 | p=GET_NUMBER(p,&set_mult,&mult); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2619 | break; |
| 2620 | case 'c': |
| 2621 | get_io32bit = noisy; |
| 2622 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2623 | if (!*p && argc && isalnum(**argv)) |
| 2624 | p = *argv++, --argc; |
| 2625 | p=GET_NUMBER(p,&set_io32bit,&io32bit); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | #ifdef HDIO_DRIVE_CMD |
| 2628 | case 'S': |
| 2629 | get_standby = noisy; |
| 2630 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2631 | if (!*p && argc && isalnum(**argv)) |
| 2632 | p = *argv++, --argc; |
| 2633 | p=GET_NUMBER(p,&set_standby,&standby_requested); |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2634 | missing_arg(set_standby, c, NULL); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2635 | break; |
| 2636 | |
| 2637 | case 'D': |
| 2638 | get_defects = noisy; |
| 2639 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2640 | if (!*p && argc && isalnum(**argv)) |
| 2641 | p = *argv++, --argc; |
| 2642 | p=GET_NUMBER(p,&set_defects,&defects); |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2643 | missing_arg(set_defects, c, NULL); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2644 | break; |
| 2645 | case 'P': |
| 2646 | get_prefetch = noisy; |
| 2647 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2648 | if (!*p && argc && isalnum(**argv)) |
| 2649 | p = *argv++, --argc; |
| 2650 | p=GET_NUMBER(p,&set_prefetch,&prefetch); |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2651 | missing_arg(set_prefetch, c, NULL); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2652 | break; |
| 2653 | |
| 2654 | case 'X': |
| 2655 | get_xfermode = noisy; |
| 2656 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2657 | if (!*p && argc && isalnum(**argv)) |
| 2658 | p = *argv++, --argc; |
| 2659 | p=GET_STRING(p,&set_xfermode,&xfermode_requested); |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2660 | missing_arg(set_xfermode, c, NULL); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2661 | break; |
| 2662 | |
| 2663 | case 'K': |
| 2664 | get_dkeep = noisy; |
| 2665 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2666 | if (!*p && argc && isdigit(**argv)) |
| 2667 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2668 | if((set_dkeep = set_flag(p,'1'))==1) |
| 2669 | dkeep = *p++ - '0'; |
| 2670 | else |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2671 | goto missing_arg_error; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2672 | break; |
| 2673 | |
| 2674 | case 'A': |
| 2675 | get_lookahead = noisy; |
| 2676 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2677 | if (!*p && argc && isdigit(**argv)) |
| 2678 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2679 | if((set_lookahead = set_flag(p,'1'))==1) |
| 2680 | lookahead = *p++ - '0'; |
| 2681 | else |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2682 | goto missing_arg_error; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2683 | break; |
| 2684 | |
| 2685 | case 'L': |
| 2686 | get_doorlock = noisy; |
| 2687 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2688 | if (!*p && argc && isdigit(**argv)) |
| 2689 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2690 | if((set_doorlock = set_flag(p,'1'))==1) |
| 2691 | doorlock = *p++ - '0'; |
| 2692 | else |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2693 | goto missing_arg_error; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2694 | break; |
| 2695 | |
| 2696 | case 'W': |
| 2697 | get_wcache = noisy; |
| 2698 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2699 | if (!*p && argc && isdigit(**argv)) |
| 2700 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2701 | if((set_wcache = set_flag(p,'1'))==1) |
| 2702 | wcache = *p++ - '0'; |
| 2703 | else |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2704 | missing_arg_error: |
| 2705 | missing_arg(1, c, "(0/1)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2706 | break; |
| 2707 | |
| 2708 | case 'C': |
| 2709 | get_powermode = noisy; |
| 2710 | noisy = 1; |
| 2711 | break; |
| 2712 | |
| 2713 | case 'y': |
| 2714 | get_standbynow = noisy; |
| 2715 | noisy = 1; |
| 2716 | set_standbynow = 1; |
| 2717 | break; |
| 2718 | |
| 2719 | case 'Y': |
| 2720 | get_sleepnow = noisy; |
| 2721 | noisy = 1; |
| 2722 | set_sleepnow = 1; |
| 2723 | break; |
| 2724 | |
| 2725 | case 'z': |
| 2726 | reread_partn = 1; |
| 2727 | break; |
| 2728 | |
| 2729 | case 'Z': |
| 2730 | get_seagate = noisy; |
| 2731 | noisy = 1; |
| 2732 | set_seagate = 1; |
| 2733 | break; |
| 2734 | #endif /* HDIO_DRIVE_CMD */ |
| 2735 | case 'k': |
| 2736 | get_keep = noisy; |
| 2737 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2738 | if (!*p && argc && isdigit(**argv)) |
| 2739 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2740 | if((set_keep = set_flag(p,'1'))==1) |
| 2741 | keep = *p++ - '0'; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2742 | break; |
| 2743 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF |
| 2744 | case 'U': |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2745 | if (!*p && argc && isdigit(**argv)) |
| 2746 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2747 | if(! p) |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2748 | goto expected_hwif_error; /* "expected hwif_nr" */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2749 | |
| 2750 | sscanf(p++, "%i", &hwif); |
| 2751 | |
| 2752 | unregister_hwif = 1; |
| 2753 | break; |
| 2754 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF */ |
| 2755 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF |
| 2756 | case 'R': |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2757 | if (!*p && argc && isdigit(**argv)) |
| 2758 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2759 | if(! p) |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2760 | goto expected_hwif_error; /* "expected hwif_data" */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2761 | |
| 2762 | sscanf(p++, "%i", &hwif_data); |
| 2763 | |
| 2764 | if (argc && isdigit(**argv)) |
| 2765 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2766 | else |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2767 | goto expected_hwif_error; /* "expected hwif_ctrl" */ |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2768 | |
| 2769 | sscanf(p, "%i", &hwif_ctrl); |
| 2770 | |
| 2771 | if (argc && isdigit(**argv)) |
| 2772 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2773 | else |
Bernhard Reutner-Fischer | 061fd0a | 2006-04-05 16:37:25 +0000 | [diff] [blame^] | 2774 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */ |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2775 | expected_hwif_error: |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2776 | bb_error_msg_and_die("expected hwif value"); /* "expected hwif_irq" */ |
Bernhard Reutner-Fischer | 061fd0a | 2006-04-05 16:37:25 +0000 | [diff] [blame^] | 2777 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2778 | |
| 2779 | sscanf(p, "%i", &hwif_irq); |
| 2780 | |
| 2781 | *p = '\0'; |
| 2782 | |
| 2783 | scan_hwif = 1; |
| 2784 | break; |
| 2785 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF */ |
| 2786 | case 'Q': |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2787 | #ifdef HDIO_GET_QDMA |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2788 | get_dma_q = noisy; |
| 2789 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2790 | #ifdef HDIO_SET_QDMA |
| 2791 | if (!*p && argc && isalnum(**argv)) |
| 2792 | p = *argv++, --argc; |
| 2793 | p=GET_NUMBER(p,&set_dma_q,&dma_q); |
| 2794 | #ifdef HDIO_GET_QDMA |
| 2795 | dma_q = -dma_q; |
| 2796 | #endif |
| 2797 | #endif |
| 2798 | #endif |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2799 | break; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2800 | |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2801 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET |
| 2802 | case 'w': |
| 2803 | perform_reset = 1; |
| 2804 | break; |
| 2805 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET */ |
| 2806 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
| 2807 | case 'x': |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2808 | if (!*p && argc && isdigit(**argv)) |
| 2809 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2810 | if((perform_tristate = set_flag(p,'1'))==1) |
| 2811 | tristate = *p++ - '0'; |
| 2812 | else |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2813 | missing_arg(1, c, "(0/1)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2814 | break; |
| 2815 | |
| 2816 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ |
| 2817 | case 'a': |
| 2818 | get_readahead = noisy; |
| 2819 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2820 | if (!*p && argc && isalnum(**argv)) |
| 2821 | p = *argv++, --argc; |
Eric Andersen | f828da0 | 2004-07-20 22:53:59 +0000 | [diff] [blame] | 2822 | p=GET_NUMBER(p,&set_readahead,&Xreadahead); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2823 | break; |
| 2824 | case 'B': |
| 2825 | get_apmmode = noisy; |
| 2826 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2827 | if (!*p && argc && isalnum(**argv)) |
| 2828 | p = *argv++, --argc; |
| 2829 | p=GET_NUMBER(p,&set_apmmode,&apmmode); |
Eric Andersen | b2aa776 | 2004-04-05 13:08:08 +0000 | [diff] [blame] | 2830 | missing_arg(set_apmmode, c, "(1-255)"); |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | case 't': |
| 2833 | do_timings = 1; |
| 2834 | do_flush = 1; |
| 2835 | break; |
| 2836 | case 'T': |
| 2837 | do_ctimings = 1; |
| 2838 | do_flush = 1; |
| 2839 | break; |
| 2840 | #ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF |
| 2841 | case 'b': |
| 2842 | get_busstate = noisy; |
| 2843 | noisy = 1; |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2844 | if (!*p && argc && isdigit(**argv)) |
| 2845 | p = *argv++, --argc; |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2846 | if((set_busstate = set_flag(p,'2'))==1) |
| 2847 | busstate = *p++ - '0'; |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2848 | break; |
| 2849 | #endif |
| 2850 | case 'h': |
| 2851 | default: |
| 2852 | bb_show_usage(); |
| 2853 | } |
| 2854 | } |
| 2855 | if (!argc) |
| 2856 | bb_show_usage(); |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2857 | } else { |
Glenn L McGrath | 0708585 | 2003-10-09 07:28:22 +0000 | [diff] [blame] | 2858 | process_dev (p); |
Eric Andersen | 06d4ec2 | 2004-03-19 10:53:52 +0000 | [diff] [blame] | 2859 | } |
Eric Andersen | 3443bd7 | 2003-07-22 07:30:36 +0000 | [diff] [blame] | 2860 | } |
| 2861 | return 0 ; |
| 2862 | } |