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