Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2#include <linux/types.h>
  3#include <linux/string.h>
  4#include <linux/kernel.h>
  5#include <linux/export.h>
  6#include <linux/interrupt.h>
  7#include <linux/ide.h>
  8#include <linux/bitops.h>
  9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
 11{
 12	struct ide_taskfile *tf = &cmd->tf;
 13	u32 high, low;
 14
 15	low  = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
 16	if (lba48) {
 17		tf = &cmd->hob;
 18		high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
 19	} else
 20		high = tf->device & 0xf;
 21
 22	return ((u64)high << 24) | low;
 23}
 24EXPORT_SYMBOL_GPL(ide_get_lba_addr);
 25
 26static void ide_dump_sector(ide_drive_t *drive)
 27{
 28	struct ide_cmd cmd;
 29	struct ide_taskfile *tf = &cmd.tf;
 30	u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
 31
 32	memset(&cmd, 0, sizeof(cmd));
 33	if (lba48) {
 34		cmd.valid.in.tf  = IDE_VALID_LBA;
 35		cmd.valid.in.hob = IDE_VALID_LBA;
 36		cmd.tf_flags = IDE_TFLAG_LBA48;
 37	} else
 38		cmd.valid.in.tf  = IDE_VALID_LBA | IDE_VALID_DEVICE;
 39
 40	ide_tf_readback(drive, &cmd);
 41
 42	if (lba48 || (tf->device & ATA_LBA))
 43		printk(KERN_CONT ", LBAsect=%llu",
 44			(unsigned long long)ide_get_lba_addr(&cmd, lba48));
 45	else
 46		printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
 47			tf->device & 0xf, tf->lbal);
 48}
 49
 50static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
 51{
 52	printk(KERN_CONT "{ ");
 53	if (err & ATA_ABORTED)
 54		printk(KERN_CONT "DriveStatusError ");
 55	if (err & ATA_ICRC)
 56		printk(KERN_CONT "%s",
 57			(err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
 58	if (err & ATA_UNC)
 59		printk(KERN_CONT "UncorrectableError ");
 60	if (err & ATA_IDNF)
 61		printk(KERN_CONT "SectorIdNotFound ");
 62	if (err & ATA_TRK0NF)
 63		printk(KERN_CONT "TrackZeroNotFound ");
 64	if (err & ATA_AMNF)
 65		printk(KERN_CONT "AddrMarkNotFound ");
 66	printk(KERN_CONT "}");
 67	if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
 68	    (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
 69		struct request *rq = drive->hwif->rq;
 70
 71		ide_dump_sector(drive);
 72
 73		if (rq)
 74			printk(KERN_CONT ", sector=%llu",
 75			       (unsigned long long)blk_rq_pos(rq));
 76	}
 77	printk(KERN_CONT "\n");
 78}
 79
 80static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
 81{
 82	printk(KERN_CONT "{ ");
 83	if (err & ATAPI_ILI)
 84		printk(KERN_CONT "IllegalLengthIndication ");
 85	if (err & ATAPI_EOM)
 86		printk(KERN_CONT "EndOfMedia ");
 87	if (err & ATA_ABORTED)
 88		printk(KERN_CONT "AbortedCommand ");
 89	if (err & ATA_MCR)
 90		printk(KERN_CONT "MediaChangeRequested ");
 91	if (err & ATAPI_LFS)
 92		printk(KERN_CONT "LastFailedSense=0x%02x ",
 93			(err & ATAPI_LFS) >> 4);
 94	printk(KERN_CONT "}\n");
 95}
 96
 97/**
 98 *	ide_dump_status		-	translate ATA/ATAPI error
 99 *	@drive: drive that status applies to
100 *	@msg: text message to print
101 *	@stat: status byte to decode
102 *
103 *	Error reporting, in human readable form (luxurious, but a memory hog).
104 *	Combines the drive name, message and status byte to provide a
105 *	user understandable explanation of the device error.
106 */
107
108u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
109{
110	u8 err = 0;
111
112	printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
113	if (stat & ATA_BUSY)
114		printk(KERN_CONT "Busy ");
115	else {
116		if (stat & ATA_DRDY)
117			printk(KERN_CONT "DriveReady ");
118		if (stat & ATA_DF)
119			printk(KERN_CONT "DeviceFault ");
120		if (stat & ATA_DSC)
121			printk(KERN_CONT "SeekComplete ");
122		if (stat & ATA_DRQ)
123			printk(KERN_CONT "DataRequest ");
124		if (stat & ATA_CORR)
125			printk(KERN_CONT "CorrectedError ");
126		if (stat & ATA_SENSE)
127			printk(KERN_CONT "Sense ");
128		if (stat & ATA_ERR)
129			printk(KERN_CONT "Error ");
130	}
131	printk(KERN_CONT "}\n");
132	if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
133		err = ide_read_error(drive);
134		printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
135		if (drive->media == ide_disk)
136			ide_dump_ata_error(drive, err);
137		else
138			ide_dump_atapi_error(drive, err);
139	}
140
141	printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
142		drive->name, drive->hwif->cmd.tf.command);
143
144	return err;
145}
146EXPORT_SYMBOL(ide_dump_status);
v3.1
 
  1#include <linux/types.h>
  2#include <linux/string.h>
  3#include <linux/kernel.h>
 
  4#include <linux/interrupt.h>
  5#include <linux/ide.h>
  6#include <linux/bitops.h>
  7
  8/**
  9 *	ide_toggle_bounce	-	handle bounce buffering
 10 *	@drive: drive to update
 11 *	@on: on/off boolean
 12 *
 13 *	Enable or disable bounce buffering for the device. Drives move
 14 *	between PIO and DMA and that changes the rules we need.
 15 */
 16
 17void ide_toggle_bounce(ide_drive_t *drive, int on)
 18{
 19	u64 addr = BLK_BOUNCE_HIGH;	/* dma64_addr_t */
 20
 21	if (!PCI_DMA_BUS_IS_PHYS) {
 22		addr = BLK_BOUNCE_ANY;
 23	} else if (on && drive->media == ide_disk) {
 24		struct device *dev = drive->hwif->dev;
 25
 26		if (dev && dev->dma_mask)
 27			addr = *dev->dma_mask;
 28	}
 29
 30	if (drive->queue)
 31		blk_queue_bounce_limit(drive->queue, addr);
 32}
 33
 34u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
 35{
 36	struct ide_taskfile *tf = &cmd->tf;
 37	u32 high, low;
 38
 39	low  = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
 40	if (lba48) {
 41		tf = &cmd->hob;
 42		high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
 43	} else
 44		high = tf->device & 0xf;
 45
 46	return ((u64)high << 24) | low;
 47}
 48EXPORT_SYMBOL_GPL(ide_get_lba_addr);
 49
 50static void ide_dump_sector(ide_drive_t *drive)
 51{
 52	struct ide_cmd cmd;
 53	struct ide_taskfile *tf = &cmd.tf;
 54	u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
 55
 56	memset(&cmd, 0, sizeof(cmd));
 57	if (lba48) {
 58		cmd.valid.in.tf  = IDE_VALID_LBA;
 59		cmd.valid.in.hob = IDE_VALID_LBA;
 60		cmd.tf_flags = IDE_TFLAG_LBA48;
 61	} else
 62		cmd.valid.in.tf  = IDE_VALID_LBA | IDE_VALID_DEVICE;
 63
 64	ide_tf_readback(drive, &cmd);
 65
 66	if (lba48 || (tf->device & ATA_LBA))
 67		printk(KERN_CONT ", LBAsect=%llu",
 68			(unsigned long long)ide_get_lba_addr(&cmd, lba48));
 69	else
 70		printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
 71			tf->device & 0xf, tf->lbal);
 72}
 73
 74static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
 75{
 76	printk(KERN_CONT "{ ");
 77	if (err & ATA_ABORTED)
 78		printk(KERN_CONT "DriveStatusError ");
 79	if (err & ATA_ICRC)
 80		printk(KERN_CONT "%s",
 81			(err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
 82	if (err & ATA_UNC)
 83		printk(KERN_CONT "UncorrectableError ");
 84	if (err & ATA_IDNF)
 85		printk(KERN_CONT "SectorIdNotFound ");
 86	if (err & ATA_TRK0NF)
 87		printk(KERN_CONT "TrackZeroNotFound ");
 88	if (err & ATA_AMNF)
 89		printk(KERN_CONT "AddrMarkNotFound ");
 90	printk(KERN_CONT "}");
 91	if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
 92	    (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
 93		struct request *rq = drive->hwif->rq;
 94
 95		ide_dump_sector(drive);
 96
 97		if (rq)
 98			printk(KERN_CONT ", sector=%llu",
 99			       (unsigned long long)blk_rq_pos(rq));
100	}
101	printk(KERN_CONT "\n");
102}
103
104static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
105{
106	printk(KERN_CONT "{ ");
107	if (err & ATAPI_ILI)
108		printk(KERN_CONT "IllegalLengthIndication ");
109	if (err & ATAPI_EOM)
110		printk(KERN_CONT "EndOfMedia ");
111	if (err & ATA_ABORTED)
112		printk(KERN_CONT "AbortedCommand ");
113	if (err & ATA_MCR)
114		printk(KERN_CONT "MediaChangeRequested ");
115	if (err & ATAPI_LFS)
116		printk(KERN_CONT "LastFailedSense=0x%02x ",
117			(err & ATAPI_LFS) >> 4);
118	printk(KERN_CONT "}\n");
119}
120
121/**
122 *	ide_dump_status		-	translate ATA/ATAPI error
123 *	@drive: drive that status applies to
124 *	@msg: text message to print
125 *	@stat: status byte to decode
126 *
127 *	Error reporting, in human readable form (luxurious, but a memory hog).
128 *	Combines the drive name, message and status byte to provide a
129 *	user understandable explanation of the device error.
130 */
131
132u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
133{
134	u8 err = 0;
135
136	printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
137	if (stat & ATA_BUSY)
138		printk(KERN_CONT "Busy ");
139	else {
140		if (stat & ATA_DRDY)
141			printk(KERN_CONT "DriveReady ");
142		if (stat & ATA_DF)
143			printk(KERN_CONT "DeviceFault ");
144		if (stat & ATA_DSC)
145			printk(KERN_CONT "SeekComplete ");
146		if (stat & ATA_DRQ)
147			printk(KERN_CONT "DataRequest ");
148		if (stat & ATA_CORR)
149			printk(KERN_CONT "CorrectedError ");
150		if (stat & ATA_IDX)
151			printk(KERN_CONT "Index ");
152		if (stat & ATA_ERR)
153			printk(KERN_CONT "Error ");
154	}
155	printk(KERN_CONT "}\n");
156	if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
157		err = ide_read_error(drive);
158		printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
159		if (drive->media == ide_disk)
160			ide_dump_ata_error(drive, err);
161		else
162			ide_dump_atapi_error(drive, err);
163	}
164
165	printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
166		drive->name, drive->hwif->cmd.tf.command);
167
168	return err;
169}
170EXPORT_SYMBOL(ide_dump_status);