blob: 7913ad5d4979807da9621b4c86ff27c1b3336516 [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/ide.h>
6#include <linux/bitops.h>
7
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +01008static const char *udma_str[] =
9 { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44",
10 "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" };
11static const char *mwdma_str[] =
12 { "MWDMA0", "MWDMA1", "MWDMA2" };
13static const char *swdma_str[] =
14 { "SWDMA0", "SWDMA1", "SWDMA2" };
15static const char *pio_str[] =
16 { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5" };
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/**
19 * ide_xfer_verbose - return IDE mode names
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +010020 * @mode: transfer mode
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 * Returns a constant string giving the name of the mode
23 * requested.
24 */
25
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +010026const char *ide_xfer_verbose(u8 mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Bartlomiej Zolnierkiewicz3ab7efe2007-12-12 23:31:58 +010028 const char *s;
29 u8 i = mode & 0xf;
30
31 if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7)
32 s = udma_str[i];
33 else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_2)
34 s = mwdma_str[i];
35 else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2)
36 s = swdma_str[i];
37 else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_5)
38 s = pio_str[i & 0x7];
39 else if (mode == XFER_PIO_SLOW)
40 s = "PIO SLOW";
41 else
42 s = "XFER ERROR";
43
44 return s;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
Linus Torvalds1da177e2005-04-16 15:20:36 -070046EXPORT_SYMBOL(ide_xfer_verbose);
47
48/**
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020049 * ide_rate_filter - filter transfer mode
50 * @drive: IDE device
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 * @speed: desired speed
52 *
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020053 * Given the available transfer modes this function returns
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * the best available speed at or below the speed requested.
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020055 *
Bartlomiej Zolnierkiewicz7670df72007-10-11 23:53:59 +020056 * TODO: check device PIO capabilities
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
58
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +020059static u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020061 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewicz7670df72007-10-11 23:53:59 +020062 u8 mode = ide_find_dma_mode(drive, speed);
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020063
Bartlomiej Zolnierkiewicz7670df72007-10-11 23:53:59 +020064 if (mode == 0) {
65 if (hwif->pio_mask)
66 mode = fls(hwif->pio_mask) - 1 + XFER_PIO_0;
67 else
68 mode = XFER_PIO_4;
Bartlomiej Zolnierkiewicz7f8f48a2007-05-10 00:01:10 +020069 }
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020070
Harvey Harrisoneb639632008-04-26 22:25:20 +020071/* printk("%s: mode 0x%02x, speed 0x%02x\n", __func__, mode, speed); */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Bartlomiej Zolnierkiewicz2d5eaa62007-05-10 00:01:08 +020073 return min(speed, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/**
77 * ide_get_best_pio_mode - get PIO mode from drive
Sergei Shtylyov81d368e2007-03-03 17:48:53 +010078 * @drive: drive to consider
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 * @mode_wanted: preferred mode
Sergei Shtylyov81d368e2007-03-03 17:48:53 +010080 * @max_mode: highest allowed mode
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 *
82 * This routine returns the recommended PIO settings for a given drive,
83 * based on the drive->id information and the ide_pio_blacklist[].
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 *
Sergei Shtylyov81d368e2007-03-03 17:48:53 +010085 * Drive PIO mode is auto-selected if 255 is passed as mode_wanted.
86 * This is used by most chipset support modules when "auto-tuning".
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 */
88
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010089u8 ide_get_best_pio_mode(ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +020091 u16 *id = drive->id;
92 int pio_mode = -1, overridden = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Bartlomiej Zolnierkiewicz6a824c92007-07-20 01:11:58 +020094 if (mode_wanted != 255)
95 return min_t(u8, mode_wanted, max_mode);
96
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +020097 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0)
98 pio_mode = ide_scan_pio_blacklist((char *)&id[ATA_ID_PROD]);
99
100 if (pio_mode != -1) {
Bartlomiej Zolnierkiewicz342cdb62007-07-20 01:11:55 +0200101 printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 } else {
Bartlomiej Zolnierkiewicz48fb2682008-10-10 22:39:19 +0200103 pio_mode = id[ATA_ID_OLD_PIO_MODES] >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
105 pio_mode = 2;
106 overridden = 1;
107 }
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +0200108
109 if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */
Bartlomiej Zolnierkiewicz48fb2682008-10-10 22:39:19 +0200110 if (ata_id_has_iordy(id)) {
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +0200111 if (id[ATA_ID_PIO_MODES] & 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 overridden = 0;
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +0200113 if (id[ATA_ID_PIO_MODES] & 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 pio_mode = 5;
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +0200115 else if (id[ATA_ID_PIO_MODES] & 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 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}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
134
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200135/* req_pio == "255" for auto-tune */
136void ide_set_pio(ide_drive_t *drive, u8 req_pio)
137{
138 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200139 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200140 u8 host_pio, pio;
141
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200142 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200143 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200144 return;
145
146 BUG_ON(hwif->pio_mask == 0x00);
147
148 host_pio = fls(hwif->pio_mask) - 1;
149
150 pio = ide_get_best_pio_mode(drive, req_pio, host_pio);
151
152 /*
153 * TODO:
154 * - report device max PIO mode
155 * - check req_pio != 255 against device max PIO mode
156 */
157 printk(KERN_DEBUG "%s: host max PIO%d wanted PIO%d%s selected PIO%d\n",
158 drive->name, host_pio, req_pio,
159 req_pio == 255 ? "(auto-tune)" : "", pio);
160
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200161 (void)ide_set_pio_mode(drive, XFER_PIO_0 + pio);
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200162}
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200163EXPORT_SYMBOL_GPL(ide_set_pio);
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/**
166 * ide_toggle_bounce - handle bounce buffering
167 * @drive: drive to update
168 * @on: on/off boolean
169 *
170 * Enable or disable bounce buffering for the device. Drives move
171 * between PIO and DMA and that changes the rules we need.
172 */
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174void ide_toggle_bounce(ide_drive_t *drive, int on)
175{
176 u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */
177
James Bottomley65931782005-11-18 23:13:33 +0100178 if (!PCI_DMA_BUS_IS_PHYS) {
179 addr = BLK_BOUNCE_ANY;
180 } else if (on && drive->media == ide_disk) {
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +0100181 struct device *dev = drive->hwif->dev;
182
183 if (dev && dev->dma_mask)
184 addr = *dev->dma_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 }
186
187 if (drive->queue)
188 blk_queue_bounce_limit(drive->queue, addr);
189}
190
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200191int ide_set_pio_mode(ide_drive_t *drive, const u8 mode)
192{
193 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200194 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200195
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200196 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
197 return 0;
198
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200199 if (port_ops == NULL || port_ops->set_pio_mode == NULL)
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200200 return -1;
201
202 /*
203 * TODO: temporary hack for some legacy host drivers that didn't
204 * set transfer mode on the device in ->set_pio_mode method...
205 */
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200206 if (port_ops->set_dma_mode == NULL) {
207 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200208 return 0;
209 }
210
211 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
212 if (ide_config_drive_speed(drive, mode))
213 return -1;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200214 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200215 return 0;
216 } else {
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200217 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200218 return ide_config_drive_speed(drive, mode);
219 }
220}
221
222int ide_set_dma_mode(ide_drive_t *drive, const u8 mode)
223{
224 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200225 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200226
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200227 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
228 return 0;
229
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200230 if (port_ops == NULL || port_ops->set_dma_mode == NULL)
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200231 return -1;
232
233 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
234 if (ide_config_drive_speed(drive, mode))
235 return -1;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200236 port_ops->set_dma_mode(drive, mode);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200237 return 0;
238 } else {
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200239 port_ops->set_dma_mode(drive, mode);
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200240 return ide_config_drive_speed(drive, mode);
241 }
242}
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200243EXPORT_SYMBOL_GPL(ide_set_dma_mode);
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/**
246 * ide_set_xfer_rate - set transfer rate
247 * @drive: drive to set
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200248 * @rate: speed to attempt to set
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100249 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 * General helper for setting the speed of an IDE device. This
251 * function knows about user enforced limits from the configuration
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200252 * which ->set_pio_mode/->set_dma_mode does not.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 */
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
256{
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +0200257 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200258 const struct ide_port_ops *port_ops = hwif->port_ops;
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +0200259
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200260 if (port_ops == NULL || port_ops->set_dma_mode == NULL ||
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200261 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return -1;
Bartlomiej Zolnierkiewiczf212ff22007-10-11 23:53:59 +0200263
264 rate = ide_rate_filter(drive, rate);
265
Bartlomiej Zolnierkiewicz3b2a5c72008-07-23 19:55:56 +0200266 BUG_ON(rate < XFER_PIO_0);
267
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200268 if (rate >= XFER_PIO_0 && rate <= XFER_PIO_5)
269 return ide_set_pio_mode(drive, rate);
Bartlomiej Zolnierkiewicz8f4dd2e2007-10-11 23:54:02 +0200270
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200271 return ide_set_dma_mode(drive, rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272}
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274static void ide_dump_opcode(ide_drive_t *drive)
275{
Bartlomiej Zolnierkiewicz1d0bf582008-12-29 20:27:30 +0100276 struct request *rq = drive->hwif->hwgroup->rq;
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100277 ide_task_t *task = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (!rq)
280 return;
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100281
282 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
283 task = rq->special;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100285 printk(KERN_ERR "ide: failed opcode was: ");
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100286 if (task == NULL)
287 printk(KERN_CONT "unknown\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 else
Bartlomiej Zolnierkiewicz7267c332008-01-26 20:13:13 +0100289 printk(KERN_CONT "0x%02x\n", task->tf.command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Bartlomiej Zolnierkiewicza5016332008-01-25 22:17:17 +0100292u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48)
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100293{
294 u32 high, low;
295
296 if (lba48)
297 high = (tf->hob_lbah << 16) | (tf->hob_lbam << 8) |
298 tf->hob_lbal;
299 else
300 high = tf->device & 0xf;
301 low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
302
303 return ((u64)high << 24) | low;
304}
Bartlomiej Zolnierkiewicza5016332008-01-25 22:17:17 +0100305EXPORT_SYMBOL_GPL(ide_get_lba_addr);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100306
307static void ide_dump_sector(ide_drive_t *drive)
308{
309 ide_task_t task;
310 struct ide_taskfile *tf = &task.tf;
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200311 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100312
313 memset(&task, 0, sizeof(task));
314 if (lba48)
315 task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA |
316 IDE_TFLAG_LBA48;
317 else
318 task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE;
319
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200320 drive->hwif->tp_ops->tf_read(drive, &task);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100321
322 if (lba48 || (tf->device & ATA_LBA))
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100323 printk(KERN_CONT ", LBAsect=%llu",
Andrew Morton1c904fc2008-01-25 22:17:17 +0100324 (unsigned long long)ide_get_lba_addr(tf, lba48));
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100325 else
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100326 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
327 tf->device & 0xf, tf->lbal);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +0100328}
329
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100330static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100332 printk(KERN_ERR "{ ");
333 if (err & ATA_ABORTED)
334 printk(KERN_CONT "DriveStatusError ");
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200335 if (err & ATA_ICRC)
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100336 printk(KERN_CONT "%s",
337 (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
338 if (err & ATA_UNC)
339 printk(KERN_CONT "UncorrectableError ");
340 if (err & ATA_IDNF)
341 printk(KERN_CONT "SectorIdNotFound ");
342 if (err & ATA_TRK0NF)
343 printk(KERN_CONT "TrackZeroNotFound ");
344 if (err & ATA_AMNF)
345 printk(KERN_CONT "AddrMarkNotFound ");
346 printk(KERN_CONT "}");
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200347 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
348 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100349 ide_dump_sector(drive);
350 if (HWGROUP(drive) && HWGROUP(drive)->rq)
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100351 printk(KERN_CONT ", sector=%llu",
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100352 (unsigned long long)HWGROUP(drive)->rq->sector);
353 }
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100354 printk(KERN_CONT "\n");
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100355}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100357static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
358{
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100359 printk(KERN_ERR "{ ");
360 if (err & ATAPI_ILI)
361 printk(KERN_CONT "IllegalLengthIndication ");
362 if (err & ATAPI_EOM)
363 printk(KERN_CONT "EndOfMedia ");
364 if (err & ATA_ABORTED)
365 printk(KERN_CONT "AbortedCommand ");
366 if (err & ATA_MCR)
367 printk(KERN_CONT "MediaChangeRequested ");
368 if (err & ATAPI_LFS)
369 printk(KERN_CONT "LastFailedSense=0x%02x ",
370 (err & ATAPI_LFS) >> 4);
371 printk(KERN_CONT "}\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
374/**
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100375 * ide_dump_status - translate ATA/ATAPI error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 * @drive: drive that status applies to
377 * @msg: text message to print
378 * @stat: status byte to decode
379 *
380 * Error reporting, in human readable form (luxurious, but a memory hog).
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100381 * Combines the drive name, message and status byte to provide a
382 * user understandable explanation of the device error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 */
384
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100385u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
387 unsigned long flags;
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100388 u8 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Ingo Molnar3d1c1cc2006-06-26 00:26:17 -0700390 local_irq_save(flags);
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100391 printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200392 if (stat & ATA_BUSY)
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100393 printk(KERN_CONT "Busy ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 else {
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100395 if (stat & ATA_DRDY)
396 printk(KERN_CONT "DriveReady ");
397 if (stat & ATA_DF)
398 printk(KERN_CONT "DeviceFault ");
399 if (stat & ATA_DSC)
400 printk(KERN_CONT "SeekComplete ");
401 if (stat & ATA_DRQ)
402 printk(KERN_CONT "DataRequest ");
403 if (stat & ATA_CORR)
404 printk(KERN_CONT "CorrectedError ");
405 if (stat & ATA_IDX)
406 printk(KERN_CONT "Index ");
407 if (stat & ATA_ERR)
408 printk(KERN_CONT "Error ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100410 printk(KERN_CONT "}\n");
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200411 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
Bartlomiej Zolnierkiewicz64a57fe2008-02-06 02:57:51 +0100412 err = ide_read_error(drive);
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100413 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100414 if (drive->media == ide_disk)
415 ide_dump_ata_error(drive, err);
416 else
417 ide_dump_atapi_error(drive, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419 ide_dump_opcode(drive);
420 local_irq_restore(flags);
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100421 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423EXPORT_SYMBOL(ide_dump_status);