?? ide-taskfile.c
字號:
/* * linux/drivers/ide/ide-taskfile.c Version 0.38 March 05, 2003 * * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org> * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> * Copyright (C) 2001-2002 Klaus Smolin * IBM Storage Technology Division * * The big the bad and the ugly. * * Problems to be fixed because of BH interface or the lack therefore. * * Fill me in stupid !!! * * HOST: * General refers to the Controller and Driver "pair". * DATA HANDLER: * Under the context of Linux it generally refers to an interrupt handler. * However, it correctly describes the 'HOST' * DATA BLOCK: * The amount of data needed to be transfered as predefined in the * setup of the device. * STORAGE ATOMIC: * The 'DATA BLOCK' associated to the 'DATA HANDLER', and can be as * small as a single sector or as large as the entire command block * request. */#include <linux/config.h>#define __NO_VERSION__#include <linux/module.h>#include <linux/types.h>#include <linux/string.h>#include <linux/kernel.h>#include <linux/timer.h>#include <linux/mm.h>#include <linux/interrupt.h>#include <linux/major.h>#include <linux/errno.h>#include <linux/genhd.h>#include <linux/blkpg.h>#include <linux/slab.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/hdreg.h>#include <linux/ide.h>#include <asm/byteorder.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/bitops.h>#define DEBUG_TASKFILE 0 /* unset when fixed */#if DEBUG_TASKFILE#define DTF(x...) printk(x)#else#define DTF(x...)#endif/* * */#define task_rq_offset(rq) \ (((rq)->nr_sectors - (rq)->current_nr_sectors) * SECTOR_SIZE)/* * for now, taskfile requests are special :/ * * However, upon the creation of the atapi version of packet_command * data-phase ISR plus it own diagnostics and extensions for direct access * (ioctl,read,write,rip,stream -- atapi), the kmap/kunmap for PIO will * come localized. */inline char *task_map_rq (struct request *rq, unsigned long *flags){ if (rq->bh) return ide_map_buffer(rq, flags); return rq->buffer + task_rq_offset(rq);}inline void task_unmap_rq (struct request *rq, char *buf, unsigned long *flags){ if (rq->bh) ide_unmap_buffer(buf, flags);}inline u32 task_read_24 (ide_drive_t *drive){ return (HWIF(drive)->INB(IDE_HCYL_REG)<<16) | (HWIF(drive)->INB(IDE_LCYL_REG)<<8) | HWIF(drive)->INB(IDE_SECTOR_REG);}EXPORT_SYMBOL(task_read_24);static void ata_bswap_data (void *buffer, int wcount){ u16 *p = buffer; while (wcount--) { *p = *p << 8 | *p >> 8; p++; *p = *p << 8 | *p >> 8; p++; }}void taskfile_input_data (ide_drive_t *drive, void *buffer, u32 wcount){ HWIF(drive)->ata_input_data(drive, buffer, wcount); if (drive->bswap) ata_bswap_data(buffer, wcount);}EXPORT_SYMBOL(taskfile_input_data);void taskfile_output_data (ide_drive_t *drive, void *buffer, u32 wcount){ if (drive->bswap) { ata_bswap_data(buffer, wcount); HWIF(drive)->ata_output_data(drive, buffer, wcount); ata_bswap_data(buffer, wcount); } else { HWIF(drive)->ata_output_data(drive, buffer, wcount); }}EXPORT_SYMBOL(taskfile_output_data);int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf){ ide_task_t args; memset(&args, 0, sizeof(ide_task_t)); args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01; if (drive->media == ide_disk) args.tfRegister[IDE_COMMAND_OFFSET] = WIN_IDENTIFY; else args.tfRegister[IDE_COMMAND_OFFSET] = WIN_PIDENTIFY; args.command_type = ide_cmd_type_parser(&args); return ide_raw_taskfile(drive, &args, buf);}EXPORT_SYMBOL(taskfile_lib_get_identify);#ifdef CONFIG_IDE_TASK_IOCTL_DEBUGvoid debug_taskfile (ide_drive_t *drive, ide_task_t *args){ printk(KERN_INFO "%s: ", drive->name);// printk("TF.0=x%02x ", args->tfRegister[IDE_DATA_OFFSET]); printk("TF.1=x%02x ", args->tfRegister[IDE_FEATURE_OFFSET]); printk("TF.2=x%02x ", args->tfRegister[IDE_NSECTOR_OFFSET]); printk("TF.3=x%02x ", args->tfRegister[IDE_SECTOR_OFFSET]); printk("TF.4=x%02x ", args->tfRegister[IDE_LCYL_OFFSET]); printk("TF.5=x%02x ", args->tfRegister[IDE_HCYL_OFFSET]); printk("TF.6=x%02x ", args->tfRegister[IDE_SELECT_OFFSET]); printk("TF.7=x%02x\n", args->tfRegister[IDE_COMMAND_OFFSET]); printk(KERN_INFO "%s: ", drive->name);// printk("HTF.0=x%02x ", args->hobRegister[IDE_DATA_OFFSET_HOB]); printk("HTF.1=x%02x ", args->hobRegister[IDE_FEATURE_OFFSET_HOB]); printk("HTF.2=x%02x ", args->hobRegister[IDE_NSECTOR_OFFSET_HOB]); printk("HTF.3=x%02x ", args->hobRegister[IDE_SECTOR_OFFSET_HOB]); printk("HTF.4=x%02x ", args->hobRegister[IDE_LCYL_OFFSET_HOB]); printk("HTF.5=x%02x ", args->hobRegister[IDE_HCYL_OFFSET_HOB]); printk("HTF.6=x%02x ", args->hobRegister[IDE_SELECT_OFFSET_HOB]); printk("HTF.7=x%02x\n", args->hobRegister[IDE_CONTROL_OFFSET_HOB]);}#endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task){ ide_hwif_t *hwif = HWIF(drive); task_struct_t *taskfile = (task_struct_t *) task->tfRegister; hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister; u8 HIHI = (drive->addressing == 1) ? 0xE0 : 0xEF;#ifdef CONFIG_IDE_TASK_IOCTL_DEBUG void debug_taskfile(drive, task);#endif /* CONFIG_IDE_TASK_IOCTL_DEBUG */ /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */ if (IDE_CONTROL_REG) { /* clear nIEN */ hwif->OUTB(drive->ctl, IDE_CONTROL_REG); } SELECT_MASK(drive, 0); if (drive->addressing == 1) { hwif->OUTB(hobfile->feature, IDE_FEATURE_REG); hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG); hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG); hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG); hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG); } hwif->OUTB(taskfile->feature, IDE_FEATURE_REG); hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG); hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG); hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG); hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG); hwif->OUTB((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG); if (task->handler != NULL) { ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL); if (task->prehandler != NULL) return task->prehandler(drive, task->rq); return ide_started; } /* for dma commands we down set the handler */#if 0 if (blk_fs_request(task->rq) && drive->using_dma) { if (rq_data_dir(task->rq) == READ) { if (hwif->ide_dma_read(drive)) return ide_stopped; } else { if (hwif->ide_dma_write(drive)) return ide_stopped; } } else { if (!drive->using_dma && (task->handler == NULL)) return ide_stopped; switch(taskfile->command) { case WIN_WRITEDMA_ONCE: case WIN_WRITEDMA: case WIN_WRITEDMA_EXT: hwif->ide_dma_write(drive); break; case WIN_READDMA_ONCE: case WIN_READDMA: case WIN_READDMA_EXT: case WIN_IDENTIFY_DMA: hwif->ide_dma_read(drive); break; default: if (task->handler == NULL) return ide_stopped; } } return ide_started;#else switch(taskfile->command) { case WIN_WRITEDMA_ONCE: case WIN_WRITEDMA: case WIN_WRITEDMA_EXT: if (drive->using_dma && !(hwif->ide_dma_write(drive))) return ide_started; case WIN_READDMA_ONCE: case WIN_READDMA: case WIN_READDMA_EXT: case WIN_IDENTIFY_DMA: if (drive->using_dma && !(hwif->ide_dma_read(drive))) return ide_started; default: break; } return ide_stopped;#endif}EXPORT_SYMBOL(do_rw_taskfile);/* * Error reporting, in human readable form (luxurious, but a memory hog). */u8 taskfile_dump_status (ide_drive_t *drive, const char *msg, u8 stat){ ide_hwif_t *hwif = HWIF(drive); unsigned long flags; u8 err = 0; local_irq_set(flags); printk("%s: %s: status=0x%02x", drive->name, msg, stat);#if FANCY_STATUS_DUMPS printk(" { "); if (stat & BUSY_STAT) { printk("Busy "); } else { if (stat & READY_STAT) printk("DriveReady "); if (stat & WRERR_STAT) printk("DeviceFault "); if (stat & SEEK_STAT) printk("SeekComplete "); if (stat & DRQ_STAT) printk("DataRequest "); if (stat & ECC_STAT) printk("CorrectedError "); if (stat & INDEX_STAT) printk("Index "); if (stat & ERR_STAT) printk("Error "); } printk("}");#endif /* FANCY_STATUS_DUMPS */ printk("\n"); if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) { err = hwif->INB(IDE_ERROR_REG); printk("%s: %s: error=0x%02x", drive->name, msg, err);#if FANCY_STATUS_DUMPS if (drive->media == ide_disk) goto media_out; printk(" { "); if (err & ABRT_ERR) printk("DriveStatusError "); if (err & ICRC_ERR) printk("Bad%s", (err & ABRT_ERR) ? "CRC " : "Sector "); if (err & ECC_ERR) printk("UncorrectableError "); if (err & ID_ERR) printk("SectorIdNotFound "); if (err & TRK0_ERR) printk("TrackZeroNotFound "); if (err & MARK_ERR) printk("AddrMarkNotFound "); printk("}"); if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || (err & (ECC_ERR|ID_ERR|MARK_ERR))) { if (drive->addressing == 1) { u64 sectors = 0; u32 high = 0; u32 low = task_read_24(drive); hwif->OUTB(0x80, IDE_CONTROL_REG); high = task_read_24(drive); sectors = ((u64)high << 24) | low; printk(", LBAsect=%lld", sectors); } else { u8 cur = hwif->INB(IDE_SELECT_REG); u8 low = hwif->INB(IDE_LCYL_REG); u8 high = hwif->INB(IDE_HCYL_REG); u8 sect = hwif->INB(IDE_SECTOR_REG); /* using LBA? */ if (cur & 0x40) { printk(", LBAsect=%d", (u32) ((cur&0xf)<<24)|(high<<16)| (low<<8)|sect); } else { printk(", CHS=%d/%d/%d", ((high<<8) + low), (cur & 0xf), sect); } } if (HWGROUP(drive)->rq) printk(", sector=%lu", HWGROUP(drive)->rq->sector); }media_out:#endif /* FANCY_STATUS_DUMPS */ printk("\n"); } local_irq_restore(flags); return err;}EXPORT_SYMBOL(taskfile_dump_status);/* * Clean up after success/failure of an explicit taskfile operation. */void ide_end_taskfile (ide_drive_t *drive, u8 stat, u8 err){ ide_hwif_t *hwif = HWIF(drive); unsigned long flags; struct request *rq; ide_task_t *args; task_ioreg_t command; spin_lock_irqsave(&io_request_lock, flags); rq = HWGROUP(drive)->rq; spin_unlock_irqrestore(&io_request_lock, flags); args = (ide_task_t *) rq->special; command = args->tfRegister[IDE_COMMAND_OFFSET]; if (rq->errors == 0) rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT); if (args->tf_in_flags.b.data) { u16 data = hwif->INW(IDE_DATA_REG); args->tfRegister[IDE_DATA_OFFSET] = (data) & 0xFF; args->hobRegister[IDE_DATA_OFFSET_HOB] = (data >> 8) & 0xFF; } args->tfRegister[IDE_ERROR_OFFSET] = err; args->tfRegister[IDE_NSECTOR_OFFSET] = hwif->INB(IDE_NSECTOR_REG); args->tfRegister[IDE_SECTOR_OFFSET] = hwif->INB(IDE_SECTOR_REG); args->tfRegister[IDE_LCYL_OFFSET] = hwif->INB(IDE_LCYL_REG); args->tfRegister[IDE_HCYL_OFFSET] = hwif->INB(IDE_HCYL_REG); args->tfRegister[IDE_SELECT_OFFSET] = hwif->INB(IDE_SELECT_REG); args->tfRegister[IDE_STATUS_OFFSET] = stat; if ((drive->id->command_set_2 & 0x0400) && (drive->id->cfs_enable_2 & 0x0400) && (drive->addressing == 1)) { hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG_HOB); args->hobRegister[IDE_FEATURE_OFFSET_HOB] = hwif->INB(IDE_FEATURE_REG); args->hobRegister[IDE_NSECTOR_OFFSET_HOB] = hwif->INB(IDE_NSECTOR_REG); args->hobRegister[IDE_SECTOR_OFFSET_HOB] = hwif->INB(IDE_SECTOR_REG); args->hobRegister[IDE_LCYL_OFFSET_HOB] = hwif->INB(IDE_LCYL_REG); args->hobRegister[IDE_HCYL_OFFSET_HOB] = hwif->INB(IDE_HCYL_REG); }#if 0/* taskfile_settings_update(drive, args, command); */ if (args->posthandler != NULL) args->posthandler(drive, args);#endif spin_lock_irqsave(&io_request_lock, flags); blkdev_dequeue_request(rq); HWGROUP(drive)->rq = NULL; end_that_request_last(rq); spin_unlock_irqrestore(&io_request_lock, flags);}EXPORT_SYMBOL(ide_end_taskfile);/* * try_to_flush_leftover_data() is invoked in response to a drive * unexpectedly having its DRQ_STAT bit set. As an alternative to * resetting the drive, this routine tries to clear the condition * by read a sector's worth of data from the drive. Of course, * this may not help if the drive is *waiting* for data from *us*. */void task_try_to_flush_leftover_data (ide_drive_t *drive){ int i = (drive->mult_count ? drive->mult_count : 1) * SECTOR_WORDS; if (drive->media != ide_disk) return; while (i > 0) { u32 buffer[16]; unsigned int wcount = (i > 16) ? 16 : i; i -= wcount; taskfile_input_data(drive, buffer, wcount); }}EXPORT_SYMBOL(task_try_to_flush_leftover_data);/* * taskfile_error() takes action based on the error returned by the drive. */ide_startstop_t taskfile_error (ide_drive_t *drive, const char *msg, u8 stat){ ide_hwif_t *hwif; struct request *rq; u8 err; err = taskfile_dump_status(drive, msg, stat); if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL) return ide_stopped; hwif = HWIF(drive); /* retry only "normal" I/O: */ if (rq->cmd == IDE_DRIVE_TASKFILE) { rq->errors = 1; ide_end_taskfile(drive, stat, err); return ide_stopped; } if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { /* other bits are useless when BUSY */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -