📄 ide-io.c
字号:
/* * end current dma transaction */ if (error < 0) { printk(KERN_WARNING "%s: DMA timeout error\n", drive->name); (void)HWIF(drive)->ide_dma_end(drive); ret = ide_error(drive, "dma timeout error", hwif->INB(IDE_STATUS_REG)); } else { printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name); hwif->dma_timeout(drive); } /* * disable dma for now, but remember that we did so because of * a timeout -- we'll reenable after we finish this next request * (or rather the first chunk of it) in pio. */ drive->retry_pio++; drive->state = DMA_PIO_RETRY; hwif->dma_off_quietly(drive); /* * un-busy drive etc (hwgroup->busy is cleared on return) and * make sure request is sane */ rq = HWGROUP(drive)->rq; if (!rq) goto out; HWGROUP(drive)->rq = NULL; rq->errors = 0; if (!rq->bio) goto out; rq->sector = rq->bio->bi_sector; rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9; rq->hard_cur_sectors = rq->current_nr_sectors; rq->buffer = bio_data(rq->bio);out: return ret;}/** * ide_timer_expiry - handle lack of an IDE interrupt * @data: timer callback magic (hwgroup) * * An IDE command has timed out before the expected drive return * occurred. At this point we attempt to clean up the current * mess. If the current handler includes an expiry handler then * we invoke the expiry handler, and providing it is happy the * work is done. If that fails we apply generic recovery rules * invoking the handler and checking the drive DMA status. We * have an excessively incestuous relationship with the DMA * logic that wants cleaning up. */ void ide_timer_expiry (unsigned long data){ ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data; ide_handler_t *handler; ide_expiry_t *expiry; unsigned long flags; unsigned long wait = -1; spin_lock_irqsave(&ide_lock, flags); if (((handler = hwgroup->handler) == NULL) || (hwgroup->req_gen != hwgroup->req_gen_timer)) { /* * Either a marginal timeout occurred * (got the interrupt just as timer expired), * or we were "sleeping" to give other devices a chance. * Either way, we don't really want to complain about anything. */ if (hwgroup->sleeping) { hwgroup->sleeping = 0; hwgroup->busy = 0; } } else { ide_drive_t *drive = hwgroup->drive; if (!drive) { printk(KERN_ERR "ide_timer_expiry: hwgroup->drive was NULL\n"); hwgroup->handler = NULL; } else { ide_hwif_t *hwif; ide_startstop_t startstop = ide_stopped; if (!hwgroup->busy) { hwgroup->busy = 1; /* paranoia */ printk(KERN_ERR "%s: ide_timer_expiry: hwgroup->busy was 0 ??\n", drive->name); } if ((expiry = hwgroup->expiry) != NULL) { /* continue */ if ((wait = expiry(drive)) > 0) { /* reset timer */ hwgroup->timer.expires = jiffies + wait; hwgroup->req_gen_timer = hwgroup->req_gen; add_timer(&hwgroup->timer); spin_unlock_irqrestore(&ide_lock, flags); return; } } hwgroup->handler = NULL; /* * We need to simulate a real interrupt when invoking * the handler() function, which means we need to * globally mask the specific IRQ: */ spin_unlock(&ide_lock); hwif = HWIF(drive);#if DISABLE_IRQ_NOSYNC disable_irq_nosync(hwif->irq);#else /* disable_irq_nosync ?? */ disable_irq(hwif->irq);#endif /* DISABLE_IRQ_NOSYNC */ /* local CPU only, * as if we were handling an interrupt */ local_irq_disable(); if (hwgroup->polling) { startstop = handler(drive); } else if (drive_is_ready(drive)) { if (drive->waiting_for_dma) hwgroup->hwif->dma_lost_irq(drive); (void)ide_ack_intr(hwif); printk(KERN_WARNING "%s: lost interrupt\n", drive->name); startstop = handler(drive); } else { if (drive->waiting_for_dma) { startstop = ide_dma_timeout_retry(drive, wait); } else startstop = ide_error(drive, "irq timeout", hwif->INB(IDE_STATUS_REG)); } drive->service_time = jiffies - drive->service_start; spin_lock_irq(&ide_lock); enable_irq(hwif->irq); if (startstop == ide_stopped) hwgroup->busy = 0; } } ide_do_request(hwgroup, IDE_NO_IRQ); spin_unlock_irqrestore(&ide_lock, flags);}/** * unexpected_intr - handle an unexpected IDE interrupt * @irq: interrupt line * @hwgroup: hwgroup being processed * * There's nothing really useful we can do with an unexpected interrupt, * other than reading the status register (to clear it), and logging it. * There should be no way that an irq can happen before we're ready for it, * so we needn't worry much about losing an "important" interrupt here. * * On laptops (and "green" PCs), an unexpected interrupt occurs whenever * the drive enters "idle", "standby", or "sleep" mode, so if the status * looks "good", we just ignore the interrupt completely. * * This routine assumes __cli() is in effect when called. * * If an unexpected interrupt happens on irq15 while we are handling irq14 * and if the two interfaces are "serialized" (CMD640), then it looks like * we could screw up by interfering with a new request being set up for * irq15. * * In reality, this is a non-issue. The new command is not sent unless * the drive is ready to accept one, in which case we know the drive is * not trying to interrupt us. And ide_set_handler() is always invoked * before completing the issuance of any new drive command, so we will not * be accidentally invoked as a result of any valid command completion * interrupt. * * Note that we must walk the entire hwgroup here. We know which hwif * is doing the current command, but we don't know which hwif burped * mysteriously. */ static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup){ u8 stat; ide_hwif_t *hwif = hwgroup->hwif; /* * handle the unexpected interrupt */ do { if (hwif->irq == irq) { stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); if (!OK_STAT(stat, READY_STAT, BAD_STAT)) { /* Try to not flood the console with msgs */ static unsigned long last_msgtime, count; ++count; if (time_after(jiffies, last_msgtime + HZ)) { last_msgtime = jiffies; printk(KERN_ERR "%s%s: unexpected interrupt, " "status=0x%02x, count=%ld\n", hwif->name, (hwif->next==hwgroup->hwif) ? "" : "(?)", stat, count); } } } } while ((hwif = hwif->next) != hwgroup->hwif);}/** * ide_intr - default IDE interrupt handler * @irq: interrupt number * @dev_id: hwif group * @regs: unused weirdness from the kernel irq layer * * This is the default IRQ handler for the IDE layer. You should * not need to override it. If you do be aware it is subtle in * places * * hwgroup->hwif is the interface in the group currently performing * a command. hwgroup->drive is the drive and hwgroup->handler is * the IRQ handler to call. As we issue a command the handlers * step through multiple states, reassigning the handler to the * next step in the process. Unlike a smart SCSI controller IDE * expects the main processor to sequence the various transfer * stages. We also manage a poll timer to catch up with most * timeout situations. There are still a few where the handlers * don't ever decide to give up. * * The handler eventually returns ide_stopped to indicate the * request completed. At this point we issue the next request * on the hwgroup and the process begins again. */ irqreturn_t ide_intr (int irq, void *dev_id){ unsigned long flags; ide_hwgroup_t *hwgroup = (ide_hwgroup_t *)dev_id; ide_hwif_t *hwif; ide_drive_t *drive; ide_handler_t *handler; ide_startstop_t startstop; spin_lock_irqsave(&ide_lock, flags); hwif = hwgroup->hwif; if (!ide_ack_intr(hwif)) { spin_unlock_irqrestore(&ide_lock, flags); return IRQ_NONE; } if ((handler = hwgroup->handler) == NULL || hwgroup->polling) { /* * Not expecting an interrupt from this drive. * That means this could be: * (1) an interrupt from another PCI device * sharing the same PCI INT# as us. * or (2) a drive just entered sleep or standby mode, * and is interrupting to let us know. * or (3) a spurious interrupt of unknown origin. * * For PCI, we cannot tell the difference, * so in that case we just ignore it and hope it goes away. * * FIXME: unexpected_intr should be hwif-> then we can * remove all the ifdef PCI crap */#ifdef CONFIG_BLK_DEV_IDEPCI if (hwif->pci_dev && !hwif->pci_dev->vendor)#endif /* CONFIG_BLK_DEV_IDEPCI */ { /* * Probably not a shared PCI interrupt, * so we can safely try to do something about it: */ unexpected_intr(irq, hwgroup);#ifdef CONFIG_BLK_DEV_IDEPCI } else { /* * Whack the status register, just in case * we have a leftover pending IRQ. */ (void) hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);#endif /* CONFIG_BLK_DEV_IDEPCI */ } spin_unlock_irqrestore(&ide_lock, flags); return IRQ_NONE; } drive = hwgroup->drive; if (!drive) { /* * This should NEVER happen, and there isn't much * we could do about it here. * * [Note - this can occur if the drive is hot unplugged] */ spin_unlock_irqrestore(&ide_lock, flags); return IRQ_HANDLED; } if (!drive_is_ready(drive)) { /* * This happens regularly when we share a PCI IRQ with * another device. Unfortunately, it can also happen * with some buggy drives that trigger the IRQ before * their status register is up to date. Hopefully we have * enough advance overhead that the latter isn't a problem. */ spin_unlock_irqrestore(&ide_lock, flags); return IRQ_NONE; } if (!hwgroup->busy) { hwgroup->busy = 1; /* paranoia */ printk(KERN_ERR "%s: ide_intr: hwgroup->busy was 0 ??\n", drive->name); } hwgroup->handler = NULL; hwgroup->req_gen++; del_timer(&hwgroup->timer); spin_unlock(&ide_lock); /* Some controllers might set DMA INTR no matter DMA or PIO; * bmdma status might need to be cleared even for * PIO interrupts to prevent spurious/lost irq. */ if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma)) /* ide_dma_end() needs bmdma status for error checking. * So, skip clearing bmdma status here and leave it * to ide_dma_end() if this is dma interrupt. */ hwif->ide_dma_clear_irq(drive); if (drive->unmask) local_irq_enable_in_hardirq(); /* service this interrupt, may set handler for next interrupt */ startstop = handler(drive); spin_lock_irq(&ide_lock); /* * Note that handler() may have set things up for another * interrupt to occur soon, but it cannot happen until * we exit from this routine, because it will be the * same irq as is currently being serviced here, and Linux * won't allow another of the same (on any CPU) until we return. */ drive->service_time = jiffies - drive->service_start; if (startstop == ide_stopped) { if (hwgroup->handler == NULL) { /* paranoia */ hwgroup->busy = 0; ide_do_request(hwgroup, hwif->irq); } else { printk(KERN_ERR "%s: ide_intr: huh? expected NULL handler " "on exit\n", drive->name); } } spin_unlock_irqrestore(&ide_lock, flags); return IRQ_HANDLED;}/** * ide_init_drive_cmd - initialize a drive command request * @rq: request object * * Initialize a request before we fill it in and send it down to * ide_do_drive_cmd. Commands must be set up by this function. Right * now it doesn't do a lot, but if that changes abusers will have a * nasty surprise. */void ide_init_drive_cmd (struct request *rq){ memset(rq, 0, sizeof(*rq)); rq->cmd_type = REQ_TYPE_ATA_CMD; rq->ref_count = 1;}EXPORT_SYMBOL(ide_init_drive_cmd);/** * ide_do_drive_cmd - issue IDE special command * @drive: device to issue command * @rq: request to issue * @action: action for processing * * This function issues a special IDE device request * onto the request queue. * * If action is ide_wait, then the rq is queued at the end of the * request queue, and the function sleeps until it has been processed. * This is for use when invoked from an ioctl handler. * * If action is ide_preempt, then the rq is queued at the head of * the request queue, displacing the currently-being-processed * request and this function returns immediately without waiting * for the new rq to be completed. This is VERY DANGEROUS, and is * intended for careful use by the ATAPI tape/cdrom driver code. * * If action is ide_end, then the rq is queued at the end of the * request queue, and the function returns immediately without waiting * for the new rq to be completed. This is again intended for careful * use by the ATAPI tape/cdrom driver code. */ int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action){ unsigned long flags; ide_hwgroup_t *hwgroup = HWGROUP(drive); DECLARE_COMPLETION_ONSTACK(wait); int where = ELEVATOR_INSERT_BACK, err; int must_wait = (action == ide_wait || action == ide_head_wait); rq->errors = 0; /* * we need to hold an extra reference to request for safe inspection * after completion */ if (must_wait) { rq->ref_count++; rq->end_io_data = &wait; rq->end_io = blk_end_sync_rq; } spin_lock_irqsave(&ide_lock, flags); if (action == ide_preempt) hwgroup->rq = NULL; if (action == ide_preempt || action == ide_head_wait) { where = ELEVATOR_INSERT_FRONT; rq->cmd_flags |= REQ_PREEMPT; } __elv_add_request(drive->queue, rq, where, 0); ide_do_request(hwgroup, IDE_NO_IRQ); spin_unlock_irqrestore(&ide_lock, flags); err = 0; if (must_wait) { wait_for_completion(&wait); if (rq->errors) err = -EIO; blk_put_request(rq); } return err;}EXPORT_SYMBOL(ide_do_drive_cmd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -