Blame view

drivers/ide/ide-lib.c 4.38 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  #include <linux/types.h>
  #include <linux/string.h>
  #include <linux/kernel.h>
38789fda2   Paul Gortmaker   ide/ata: Add expo...
4
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
  #include <linux/interrupt.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
  #include <linux/ide.h>
  #include <linux/bitops.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
12
13
14
15
  /**
   *	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...
16

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

22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
53
  	memset(&cmd, 0, sizeof(cmd));
60f85019c   Sergei Shtylyov   ide: replace IDE_...
54
55
56
57
58
59
  	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...
60

3153c26b5   Sergei Shtylyov   ide: refactor tf_...
61
  	ide_tf_readback(drive, &cmd);
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
62
63
  
  	if (lba48 || (tf->device & ATA_LBA))
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
64
  		printk(KERN_CONT ", LBAsect=%llu",
745483f10   Sergei Shtylyov   ide: simplify 'st...
65
  			(unsigned long long)ide_get_lba_addr(&cmd, lba48));
c2b57cdc1   Bartlomiej Zolnierkiewicz   ide: add ide_tf_r...
66
  	else
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
67
68
  		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...
69
  }
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
70
  static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
  {
26bfcf21e   Bartlomiej Zolnierkiewicz   ide: fix printk()...
72
  	printk(KERN_CONT "{ ");
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
73
74
  	if (err & ATA_ABORTED)
  		printk(KERN_CONT "DriveStatusError ");
3a7d24841   Bartlomiej Zolnierkiewicz   ide: use ATA_* de...
75
  	if (err & ATA_ICRC)
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
76
77
78
79
80
81
82
83
84
85
86
  		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...
87
88
  	if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
  	    (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
b65fac32c   Bartlomiej Zolnierkiewicz   ide: merge ide_hw...
89
  		struct request *rq = drive->hwif->rq;
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
90
  		ide_dump_sector(drive);
b65fac32c   Bartlomiej Zolnierkiewicz   ide: merge ide_hw...
91
92
  
  		if (rq)
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
93
  			printk(KERN_CONT ", sector=%llu",
9780e2dd8   Tejun Heo   ide: convert to r...
94
  			       (unsigned long long)blk_rq_pos(rq));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
  	}
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
96
97
  	printk(KERN_CONT "
  ");
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
98
99
100
101
  }
  
  static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
  {
26bfcf21e   Bartlomiej Zolnierkiewicz   ide: fix printk()...
102
  	printk(KERN_CONT "{ ");
2f996acb6   Bartlomiej Zolnierkiewicz   ide: checkpatch.p...
103
104
105
106
107
108
109
110
111
112
113
114
115
  	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
116
117
118
  }
  
  /**
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
119
   *	ide_dump_status		-	translate ATA/ATAPI error
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
121
122
123
124
   *	@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...
125
126
   *	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
127
   */
e62925dd2   Bartlomiej Zolnierkiewicz   ide: kill duplica...
128
  u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
  {
0e38a66a1   Bartlomiej Zolnierkiewicz   ide: remove atapi...
130
  	u8 err = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131

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