Blame view

drivers/ide/ide-lib.c 4.36 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  #include <linux/types.h>
  #include <linux/string.h>
  #include <linux/kernel.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
  #include <linux/interrupt.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
  #include <linux/ide.h>
  #include <linux/bitops.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
10
11
12
13
14
  /**
   *	ide_toggle_bounce	-	handle bounce buffering
   *	@drive: drive to update
   *	@on: on/off boolean
   *
   *	Enable or disable bounce buffering for the device. Drives move
   *	between PIO and DMA and that changes the rules we need.
   */
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
15

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
  void ide_toggle_bounce(ide_drive_t *drive, int on)
  {
  	u64 addr = BLK_BOUNCE_HIGH;	/* dma64_addr_t */
6593178dd   James Bottomley   [PATCH] ide: fix ...
19
20
21
  	if (!PCI_DMA_BUS_IS_PHYS) {
  		addr = BLK_BOUNCE_ANY;
  	} else if (on && drive->media == ide_disk) {
36501650e   Bartlomiej Zolnierkiewicz   ide: keep pointer...
22
23
24
25
  		struct device *dev = drive->hwif->dev;
  
  		if (dev && dev->dma_mask)
  			addr = *dev->dma_mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
28
29
30
  	}
  
  	if (drive->queue)
  		blk_queue_bounce_limit(drive->queue, addr);
  }
745483f10   Sergei Shtylyov   ide: simplify 'st...
31
  u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
32
  {
745483f10   Sergei Shtylyov   ide: simplify 'st...
33
  	struct ide_taskfile *tf = &cmd->tf;
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
34
  	u32 high, low;
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
35
  	low  = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
745483f10   Sergei Shtylyov   ide: simplify 'st...
36
37
38
39
40
  	if (lba48) {
  		tf = &cmd->hob;
  		high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
  	} else
  		high = tf->device & 0xf;
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
41
42
43
  
  	return ((u64)high << 24) | low;
  }
a501633c7   Bartlomiej Zolnierkiewicz   ide-disk: use ide...
44
  EXPORT_SYMBOL_GPL(ide_get_lba_addr);
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
45
46
47
  
  static void ide_dump_sector(ide_drive_t *drive)
  {
22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
48
49
  	struct ide_cmd cmd;
  	struct ide_taskfile *tf = &cmd.tf;
97100fc81   Bartlomiej Zolnierkiewicz   ide: add device f...
50
  	u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
51

22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
52
  	memset(&cmd, 0, sizeof(cmd));
60f85019c   Sergei Shtylyov   ide: replace IDE_...
53
54
55
56
57
58
  	if (lba48) {
  		cmd.valid.in.tf  = IDE_VALID_LBA;
  		cmd.valid.in.hob = IDE_VALID_LBA;
  		cmd.tf_flags = IDE_TFLAG_LBA48;
  	} else
  		cmd.valid.in.tf  = IDE_VALID_LBA | IDE_VALID_DEVICE;
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
59

3153c26b5   Sergei Shtylyov   ide: refactor tf_...
60
  	ide_tf_readback(drive, &cmd);
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
61
62
  
  	if (lba48 || (tf->device & ATA_LBA))
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
63
  		printk(KERN_CONT ", LBAsect=%llu",
745483f10   Sergei Shtylyov   ide: simplify 'st...
64
  			(unsigned long long)ide_get_lba_addr(&cmd, lba48));
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
65
  	else
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
66
67
  		printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
  			tf->device & 0xf, tf->lbal);
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
68
  }
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
69
  static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
  {
26bfcf21e   Bartlomiej Zolnierkiewicz   ide: fix printk()...
71
  	printk(KERN_CONT "{ ");
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
72
73
  	if (err & ATA_ABORTED)
  		printk(KERN_CONT "DriveStatusError ");
3a7d24841   Bartlomiej Zolnierkiewicz   ide: use ATA_* de...
74
  	if (err & ATA_ICRC)
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
75
76
77
78
79
80
81
82
83
84
85
  		printk(KERN_CONT "%s",
  			(err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
  	if (err & ATA_UNC)
  		printk(KERN_CONT "UncorrectableError ");
  	if (err & ATA_IDNF)
  		printk(KERN_CONT "SectorIdNotFound ");
  	if (err & ATA_TRK0NF)
  		printk(KERN_CONT "TrackZeroNotFound ");
  	if (err & ATA_AMNF)
  		printk(KERN_CONT "AddrMarkNotFound ");
  	printk(KERN_CONT "}");
3a7d24841   Bartlomiej Zolnierkiewicz   ide: use ATA_* de...
86
87
  	if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
  	    (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
b65fac32c   Bartlomiej Zolnierkiewicz   ide: merge ide_hw...
88
  		struct request *rq = drive->hwif->rq;
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
89
  		ide_dump_sector(drive);
b65fac32c   Bartlomiej Zolnierkiewicz   ide: merge ide_hw...
90
91
  
  		if (rq)
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
92
  			printk(KERN_CONT ", sector=%llu",
9780e2dd8   Tejun Heo   ide: convert to r...
93
  			       (unsigned long long)blk_rq_pos(rq));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  	}
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
95
96
  	printk(KERN_CONT "
  ");
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
97
98
99
100
  }
  
  static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
  {
26bfcf21e   Bartlomiej Zolnierkiewicz   ide: fix printk()...
101
  	printk(KERN_CONT "{ ");
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
102
103
104
105
106
107
108
109
110
111
112
113
114
  	if (err & ATAPI_ILI)
  		printk(KERN_CONT "IllegalLengthIndication ");
  	if (err & ATAPI_EOM)
  		printk(KERN_CONT "EndOfMedia ");
  	if (err & ATA_ABORTED)
  		printk(KERN_CONT "AbortedCommand ");
  	if (err & ATA_MCR)
  		printk(KERN_CONT "MediaChangeRequested ");
  	if (err & ATAPI_LFS)
  		printk(KERN_CONT "LastFailedSense=0x%02x ",
  			(err & ATAPI_LFS) >> 4);
  	printk(KERN_CONT "}
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
117
  }
  
  /**
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
118
   *	ide_dump_status		-	translate ATA/ATAPI error
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
123
   *	@drive: drive that status applies to
   *	@msg: text message to print
   *	@stat: status byte to decode
   *
   *	Error reporting, in human readable form (luxurious, but a memory hog).
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
124
125
   *	Combines the drive name, message and status byte to provide a
   *	user understandable explanation of the device error.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
   */
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
127
  u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
  {
0e38a66a1   Bartlomiej Zolnierkiewicz   ide: remove atapi...
129
  	u8 err = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130

2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
131
  	printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
3a7d24841   Bartlomiej Zolnierkiewicz   ide: use ATA_* de...
132
  	if (stat & ATA_BUSY)
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
133
  		printk(KERN_CONT "Busy ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
  	else {
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  		if (stat & ATA_DRDY)
  			printk(KERN_CONT "DriveReady ");
  		if (stat & ATA_DF)
  			printk(KERN_CONT "DeviceFault ");
  		if (stat & ATA_DSC)
  			printk(KERN_CONT "SeekComplete ");
  		if (stat & ATA_DRQ)
  			printk(KERN_CONT "DataRequest ");
  		if (stat & ATA_CORR)
  			printk(KERN_CONT "CorrectedError ");
  		if (stat & ATA_IDX)
  			printk(KERN_CONT "Index ");
  		if (stat & ATA_ERR)
  			printk(KERN_CONT "Error ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
  	}
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
150
151
  	printk(KERN_CONT "}
  ");
3a7d24841   Bartlomiej Zolnierkiewicz   ide: use ATA_* de...
152
  	if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
64a57fe43   Bartlomiej Zolnierkiewicz   ide: add ide_read...
153
  		err = ide_read_error(drive);
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
154
  		printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
155
156
157
158
  		if (drive->media == ide_disk)
  			ide_dump_ata_error(drive, err);
  		else
  			ide_dump_atapi_error(drive, err);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
  	}
cc30137a2   Bartlomiej Zolnierkiewicz   ide: improve fail...
160
161
162
163
  
  	printk(KERN_ERR "%s: possibly failed opcode: 0x%02x
  ",
  		drive->name, drive->hwif->cmd.tf.command);
0e38a66a1   Bartlomiej Zolnierkiewicz   ide: remove atapi...
164
  	return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
166
  EXPORT_SYMBOL(ide_dump_status);