blob: 13af72f09ec499571d0125ce3784cc8b26baabdd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/types.h>
2#include <linux/string.h>
3#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/hdreg.h>
6#include <linux/ide.h>
7#include <linux/bitops.h>
8
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +01009static const char *udma_str[] =
10 { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44",
11 "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" };
12static const char *mwdma_str[] =
13 { "MWDMA0", "MWDMA1", "MWDMA2" };
14static const char *swdma_str[] =
15 { "SWDMA0", "SWDMA1", "SWDMA2" };
16static const char *pio_str[] =
17 { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5" };
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/**
20 * ide_xfer_verbose - return IDE mode names
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +010021 * @mode: transfer mode
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * Returns a constant string giving the name of the mode
24 * requested.
25 */
26
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +010027const char *ide_xfer_verbose(u8 mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +010029 const char *s;
30 u8 i = mode & 0xf;
31
32 if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7)
33 s = udma_str[i];
34 else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_2)
35 s = mwdma_str[i];
36 else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2)
37 s = swdma_str[i];
38 else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_5)
39 s = pio_str[i & 0x7];
40 else if (mode == XFER_PIO_SLOW)
41 s = "PIO SLOW";
42 else
43 s = "XFER ERROR";
44
45 return s;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
48EXPORT_SYMBOL(ide_xfer_verbose);
49
50/**
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020051 * ide_rate_filter - filter transfer mode
52 * @drive: IDE device
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * @speed: desired speed
54 *
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020055 * Given the available transfer modes this function returns
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 * the best available speed at or below the speed requested.
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020057 *
Bartlomiej Zolnierkiewicz7670df72007-10-11 23:53:59 +020058 * TODO: check device PIO capabilities
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
60
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +020061static u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020063 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewicz7670df72007-10-11 23:53:59 +020064 u8 mode = ide_find_dma_mode(drive, speed);
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020065
Bartlomiej Zolnierkiewicz7670df72007-10-11 23:53:59 +020066 if (mode == 0) {
67 if (hwif->pio_mask)
68 mode = fls(hwif->pio_mask) - 1 + XFER_PIO_0;
69 else
70 mode = XFER_PIO_4;
Bartlomiej Zolnierkiewicz7f8f48a2007-05-10 00:01:10 +020071 }
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020072
Harvey Harrisoneb639632008-04-26 22:25:20 +020073/* printk("%s: mode 0x%02x, speed 0x%02x\n", __func__, mode, speed); */
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020075 return min(speed, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078/**
79 * ide_get_best_pio_mode - get PIO mode from drive
Sergei Shtylyov81d368e2007-03-03 17:48:53 +010080 * @drive: drive to consider
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 * @mode_wanted: preferred mode
Sergei Shtylyov81d368e2007-03-03 17:48:53 +010082 * @max_mode: highest allowed mode
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 *
84 * This routine returns the recommended PIO settings for a given drive,
85 * based on the drive->id information and the ide_pio_blacklist[].
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 *
Sergei Shtylyov81d368e2007-03-03 17:48:53 +010087 * Drive PIO mode is auto-selected if 255 is passed as mode_wanted.
88 * This is used by most chipset support modules when "auto-tuning".
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 */
90
Bartlomiej Zolnierkiewicz21347582007-07-20 01:11:58 +020091u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 int pio_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 struct hd_driveid* id = drive->id;
95 int overridden = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Bartlomiej Zolnierkiewicz6a824c92007-07-20 01:11:58 +020097 if (mode_wanted != 255)
98 return min_t(u8, mode_wanted, max_mode);
99
100 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0 &&
101 (pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
Bartlomiej Zolnierkiewicz342cdb62007-07-20 01:11:55 +0200102 printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 } else {
104 pio_mode = id->tPIO;
105 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
106 pio_mode = 2;
107 overridden = 1;
108 }
109 if (id->field_valid & 2) { /* drive implements ATA2? */
Bartlomiej Zolnierkiewicz22298332007-07-20 01:11:55 +0200110 if (id->capability & 8) { /* IORDY supported? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (id->eide_pio_modes & 7) {
112 overridden = 0;
113 if (id->eide_pio_modes & 4)
114 pio_mode = 5;
115 else if (id->eide_pio_modes & 2)
116 pio_mode = 4;
117 else
118 pio_mode = 3;
119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121 }
122
Bartlomiej Zolnierkiewicz342cdb62007-07-20 01:11:55 +0200123 if (overridden)
124 printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n",
125 drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
Bartlomiej Zolnierkiewicz7dd00082007-07-20 01:11:56 +0200127
128 if (pio_mode > max_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 pio_mode = max_mode;
Bartlomiej Zolnierkiewicz7dd00082007-07-20 01:11:56 +0200130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return pio_mode;
132}
133
134EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
135
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200136/* req_pio == "255" for auto-tune */
137void ide_set_pio(ide_drive_t *drive, u8 req_pio)
138{
139 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200140 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200141 u8 host_pio, pio;
142
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200143 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200144 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200145 return;
146
147 BUG_ON(hwif->pio_mask == 0x00);
148
149 host_pio = fls(hwif->pio_mask) - 1;
150
151 pio = ide_get_best_pio_mode(drive, req_pio, host_pio);
152
153 /*
154 * TODO:
155 * - report device max PIO mode
156 * - check req_pio != 255 against device max PIO mode
157 */
158 printk(KERN_DEBUG "%s: host max PIO%d wanted PIO%d%s selected PIO%d\n",
159 drive->name, host_pio, req_pio,
160 req_pio == 255 ? "(auto-tune)" : "", pio);
161
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200162 (void)ide_set_pio_mode(drive, XFER_PIO_0 + pio);
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200163}
164
165EXPORT_SYMBOL_GPL(ide_set_pio);
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/**
168 * ide_toggle_bounce - handle bounce buffering
169 * @drive: drive to update
170 * @on: on/off boolean
171 *
172 * Enable or disable bounce buffering for the device. Drives move
173 * between PIO and DMA and that changes the rules we need.
174 */
175
176void ide_toggle_bounce(ide_drive_t *drive, int on)
177{
178 u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */
179
James Bottomley65931782005-11-18 23:13:33 +0100180 if (!PCI_DMA_BUS_IS_PHYS) {
181 addr = BLK_BOUNCE_ANY;
182 } else if (on && drive->media == ide_disk) {
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +0100183 struct device *dev = drive->hwif->dev;
184
185 if (dev && dev->dma_mask)
186 addr = *dev->dma_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 if (drive->queue)
190 blk_queue_bounce_limit(drive->queue, addr);
191}
192
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200193int ide_set_pio_mode(ide_drive_t *drive, const u8 mode)
194{
195 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200196 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200197
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200198 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
199 return 0;
200
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200201 if (port_ops == NULL || port_ops->set_pio_mode == NULL)
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200202 return -1;
203
204 /*
205 * TODO: temporary hack for some legacy host drivers that didn't
206 * set transfer mode on the device in ->set_pio_mode method...
207 */
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200208 if (port_ops->set_dma_mode == NULL) {
209 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200210 return 0;
211 }
212
213 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
214 if (ide_config_drive_speed(drive, mode))
215 return -1;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200216 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200217 return 0;
218 } else {
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200219 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200220 return ide_config_drive_speed(drive, mode);
221 }
222}
223
224int ide_set_dma_mode(ide_drive_t *drive, const u8 mode)
225{
226 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200227 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200228
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200229 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
230 return 0;
231
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200232 if (port_ops == NULL || port_ops->set_dma_mode == NULL)
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200233 return -1;
234
235 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
236 if (ide_config_drive_speed(drive, mode))
237 return -1;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200238 port_ops->set_dma_mode(drive, mode);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200239 return 0;
240 } else {
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200241 port_ops->set_dma_mode(drive, mode);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200242 return ide_config_drive_speed(drive, mode);
243 }
244}
245
246EXPORT_SYMBOL_GPL(ide_set_dma_mode);
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/**
249 * ide_set_xfer_rate - set transfer rate
250 * @drive: drive to set
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200251 * @rate: speed to attempt to set
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 *
253 * General helper for setting the speed of an IDE device. This
254 * function knows about user enforced limits from the configuration
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200255 * which ->set_pio_mode/->set_dma_mode does not.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 */
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
259{
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +0200260 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200261 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +0200262
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200263 if (port_ops == NULL || port_ops->set_dma_mode == NULL ||
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200264 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return -1;
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +0200266
267 rate = ide_rate_filter(drive, rate);
268
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200269 if (rate >= XFER_PIO_0 && rate <= XFER_PIO_5)
270 return ide_set_pio_mode(drive, rate);
Bartlomiej Zolnierkiewicz8f4dd2e2007-10-11 23:54:02 +0200271
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200272 /*
273 * TODO: transfer modes 0x00-0x07 passed from the user-space are
274 * currently handled here which needs fixing (please note that such
275 * case could happen iff the transfer mode has already been set on
276 * the device by ide-proc.c::set_xfer_rate()).
277 */
Bartlomiej Zolnierkiewicz4db90a12008-01-25 22:17:18 +0100278 if (rate < XFER_PIO_0) {
279 if (hwif->host_flags & IDE_HFLAG_ABUSE_SET_DMA_MODE)
280 return ide_set_dma_mode(drive, rate);
281 else
282 return ide_config_drive_speed(drive, rate);
283 }
Bartlomiej Zolnierkiewicz8f4dd2e2007-10-11 23:54:02 +0200284
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200285 return ide_set_dma_mode(drive, rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288static void ide_dump_opcode(ide_drive_t *drive)
289{
290 struct request *rq;
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100291 ide_task_t *task = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 spin_lock(&ide_lock);
294 rq = NULL;
295 if (HWGROUP(drive))
296 rq = HWGROUP(drive)->rq;
297 spin_unlock(&ide_lock);
298 if (!rq)
299 return;
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100300
301 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
302 task = rq->special;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 printk("ide: failed opcode was: ");
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100305 if (task == NULL)
306 printk(KERN_CONT "unknown\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 else
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100308 printk(KERN_CONT "0x%02x\n", task->tf.command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Bartlomiej Zolnierkiewicza5016332008-01-25 22:17:17 +0100311u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48)
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100312{
313 u32 high, low;
314
315 if (lba48)
316 high = (tf->hob_lbah << 16) | (tf->hob_lbam << 8) |
317 tf->hob_lbal;
318 else
319 high = tf->device & 0xf;
320 low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
321
322 return ((u64)high << 24) | low;
323}
Bartlomiej Zolnierkiewicza5016332008-01-25 22:17:17 +0100324EXPORT_SYMBOL_GPL(ide_get_lba_addr);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100325
326static void ide_dump_sector(ide_drive_t *drive)
327{
328 ide_task_t task;
329 struct ide_taskfile *tf = &task.tf;
330 int lba48 = (drive->addressing == 1) ? 1 : 0;
331
332 memset(&task, 0, sizeof(task));
333 if (lba48)
334 task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA |
335 IDE_TFLAG_LBA48;
336 else
337 task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE;
338
Bartlomiej Zolnierkiewicz94cd5b62008-04-28 23:44:40 +0200339 drive->hwif->tf_read(drive, &task);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100340
341 if (lba48 || (tf->device & ATA_LBA))
Andrew Morton1c904fc2008-01-25 22:17:17 +0100342 printk(", LBAsect=%llu",
343 (unsigned long long)ide_get_lba_addr(tf, lba48));
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100344 else
345 printk(", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
346 tf->device & 0xf, tf->lbal);
347}
348
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100349static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100351 printk("{ ");
352 if (err & ABRT_ERR) printk("DriveStatusError ");
353 if (err & ICRC_ERR)
354 printk((err & ABRT_ERR) ? "BadCRC " : "BadSector ");
355 if (err & ECC_ERR) printk("UncorrectableError ");
356 if (err & ID_ERR) printk("SectorIdNotFound ");
357 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
358 if (err & MARK_ERR) printk("AddrMarkNotFound ");
359 printk("}");
360 if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR ||
361 (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
362 ide_dump_sector(drive);
363 if (HWGROUP(drive) && HWGROUP(drive)->rq)
364 printk(", sector=%llu",
365 (unsigned long long)HWGROUP(drive)->rq->sector);
366 }
367 printk("\n");
368}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100370static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
371{
372 printk("{ ");
373 if (err & ILI_ERR) printk("IllegalLengthIndication ");
374 if (err & EOM_ERR) printk("EndOfMedia ");
375 if (err & ABRT_ERR) printk("AbortedCommand ");
376 if (err & MCR_ERR) printk("MediaChangeRequested ");
377 if (err & LFS_ERR) printk("LastFailedSense=0x%02x ",
378 (err & LFS_ERR) >> 4);
Denis Vlasenko13bbbf22005-07-03 17:09:13 +0200379 printk("}\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
382/**
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100383 * ide_dump_status - translate ATA/ATAPI error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 * @drive: drive that status applies to
385 * @msg: text message to print
386 * @stat: status byte to decode
387 *
388 * Error reporting, in human readable form (luxurious, but a memory hog).
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100389 * Combines the drive name, message and status byte to provide a
390 * user understandable explanation of the device error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 */
392
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100393u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
395 unsigned long flags;
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100396 u8 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Ingo Molnar3d1c1cc2006-06-26 00:26:17 -0700398 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100400 if (stat & BUSY_STAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 printk("Busy ");
402 else {
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100403 if (stat & READY_STAT) printk("DriveReady ");
404 if (stat & WRERR_STAT) printk("DeviceFault ");
405 if (stat & SEEK_STAT) printk("SeekComplete ");
406 if (stat & DRQ_STAT) printk("DataRequest ");
407 if (stat & ECC_STAT) printk("CorrectedError ");
408 if (stat & INDEX_STAT) printk("Index ");
409 if (stat & ERR_STAT) printk("Error ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411 printk("}\n");
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100412 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
Bartlomiej Zolnierkiewicz64a57fe2008-02-06 02:57:51 +0100413 err = ide_read_error(drive);
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100414 printk("%s: %s: error=0x%02x ", drive->name, msg, err);
415 if (drive->media == ide_disk)
416 ide_dump_ata_error(drive, err);
417 else
418 ide_dump_atapi_error(drive, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420 ide_dump_opcode(drive);
421 local_irq_restore(flags);
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100422 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425EXPORT_SYMBOL(ide_dump_status);