#include <linux/delay.h>
#include <linux/hdreg.h>
#include <linux/ide.h>
+#include <linux/bitops.h>
#include <asm/byteorder.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <asm/io.h>
-#include <asm/bitops.h>
/*
* Conventional PIO operations for ATA devices
static void ide_insw (unsigned long port, void *addr, u32 count)
{
- return insw(port, addr, count);
+ insw(port, addr, count);
}
static u32 ide_inl (unsigned long port)
static u8 ide_mm_inb (unsigned long port)
{
- return (u8) readb(port);
+ return (u8) readb((void __iomem *) port);
}
static u16 ide_mm_inw (unsigned long port)
{
- return (u16) readw(port);
+ return (u16) readw((void __iomem *) port);
}
static void ide_mm_insw (unsigned long port, void *addr, u32 count)
{
- __ide_mm_insw(port, addr, count);
+ __ide_mm_insw((void __iomem *) port, addr, count);
}
static u32 ide_mm_inl (unsigned long port)
{
- return (u32) readl(port);
+ return (u32) readl((void __iomem *) port);
}
static void ide_mm_insl (unsigned long port, void *addr, u32 count)
{
- __ide_mm_insl(port, addr, count);
+ __ide_mm_insl((void __iomem *) port, addr, count);
}
static void ide_mm_outb (u8 value, unsigned long port)
{
- writeb(value, port);
+ writeb(value, (void __iomem *) port);
}
static void ide_mm_outbsync (ide_drive_t *drive, u8 value, unsigned long port)
{
- writeb(value, port);
+ writeb(value, (void __iomem *) port);
}
static void ide_mm_outw (u16 value, unsigned long port)
{
- writew(value, port);
+ writew(value, (void __iomem *) port);
}
static void ide_mm_outsw (unsigned long port, void *addr, u32 count)
{
- __ide_mm_outsw(port, addr, count);
+ __ide_mm_outsw((void __iomem *) port, addr, count);
}
static void ide_mm_outl (u32 value, unsigned long port)
{
- writel(value, port);
+ writel(value, (void __iomem *) port);
}
static void ide_mm_outsl (unsigned long port, void *addr, u32 count)
{
- __ide_mm_outsl(port, addr, count);
+ __ide_mm_outsl((void __iomem *) port, addr, count);
}
void default_hwif_mmiops (ide_hwif_t *hwif)
EXPORT_SYMBOL(default_hwif_mmiops);
-void default_hwif_transport (ide_hwif_t *hwif)
-{
- hwif->ata_input_data = ata_input_data;
- hwif->ata_output_data = ata_output_data;
- hwif->atapi_input_bytes = atapi_input_bytes;
- hwif->atapi_output_bytes = atapi_output_bytes;
-}
-
-EXPORT_SYMBOL(default_hwif_transport);
-
u32 ide_read_24 (ide_drive_t *drive)
{
u8 hcyl = HWIF(drive)->INB(IDE_HCYL_REG);
return (hcyl<<16)|(lcyl<<8)|sect;
}
-EXPORT_SYMBOL(ide_read_24);
-
void SELECT_DRIVE (ide_drive_t *drive)
{
if (HWIF(drive)->selectproc)
HWIF(drive)->OUTB(drive->ctl|2, IDE_CONTROL_REG);
}
-EXPORT_SYMBOL(SELECT_INTERRUPT);
-
void SELECT_MASK (ide_drive_t *drive, int mask)
{
if (HWIF(drive)->maskproc)
HWIF(drive)->maskproc(drive, mask);
}
-EXPORT_SYMBOL(SELECT_MASK);
-
void QUIRK_LIST (ide_drive_t *drive)
{
if (HWIF(drive)->quirkproc)
drive->quirk_list = HWIF(drive)->quirkproc(drive);
}
-EXPORT_SYMBOL(QUIRK_LIST);
-
/*
* Some localbus EIDE interfaces require a special access sequence
* when using 32-bit I/O instructions to transfer data. We call this
* of the sector count register location, with interrupts disabled
* to ensure that the reads all happen together.
*/
-void ata_vlb_sync (ide_drive_t *drive, unsigned long port)
+static void ata_vlb_sync(ide_drive_t *drive, unsigned long port)
{
(void) HWIF(drive)->INB(port);
(void) HWIF(drive)->INB(port);
(void) HWIF(drive)->INB(port);
}
-EXPORT_SYMBOL(ata_vlb_sync);
-
/*
* This is used for most PIO data transfers *from* the IDE interface
*/
-void ata_input_data (ide_drive_t *drive, void *buffer, u32 wcount)
+static void ata_input_data(ide_drive_t *drive, void *buffer, u32 wcount)
{
ide_hwif_t *hwif = HWIF(drive);
u8 io_32bit = drive->io_32bit;
}
}
-EXPORT_SYMBOL(ata_input_data);
-
/*
* This is used for most PIO data transfers *to* the IDE interface
*/
-void ata_output_data (ide_drive_t *drive, void *buffer, u32 wcount)
+static void ata_output_data(ide_drive_t *drive, void *buffer, u32 wcount)
{
ide_hwif_t *hwif = HWIF(drive);
u8 io_32bit = drive->io_32bit;
}
}
-EXPORT_SYMBOL(ata_output_data);
-
/*
* The following routines are mainly used by the ATAPI drivers.
*
* extra byte allocated for the buffer.
*/
-void atapi_input_bytes (ide_drive_t *drive, void *buffer, u32 bytecount)
+static void atapi_input_bytes(ide_drive_t *drive, void *buffer, u32 bytecount)
{
ide_hwif_t *hwif = HWIF(drive);
hwif->INSW(IDE_DATA_REG, ((u8 *)buffer)+(bytecount & ~0x03), 1);
}
-EXPORT_SYMBOL(atapi_input_bytes);
-
-void atapi_output_bytes (ide_drive_t *drive, void *buffer, u32 bytecount)
+static void atapi_output_bytes(ide_drive_t *drive, void *buffer, u32 bytecount)
{
ide_hwif_t *hwif = HWIF(drive);
hwif->OUTSW(IDE_DATA_REG, ((u8*)buffer)+(bytecount & ~0x03), 1);
}
-EXPORT_SYMBOL(atapi_output_bytes);
+void default_hwif_transport(ide_hwif_t *hwif)
+{
+ hwif->ata_input_data = ata_input_data;
+ hwif->ata_output_data = ata_output_data;
+ hwif->atapi_input_bytes = atapi_input_bytes;
+ hwif->atapi_output_bytes = atapi_output_bytes;
+}
+
+EXPORT_SYMBOL(default_hwif_transport);
/*
* Beginning of Taskfile OPCODE Library and feature sets.
#endif
}
+/* FIXME: exported for use by the USB storage (isd200.c) code only */
EXPORT_SYMBOL(ide_fix_driveid);
void ide_fixstring (u8 *s, const int bytecount, const int byteswap)
break;
local_irq_restore(flags);
- *startstop = DRIVER(drive)->error(drive, "status timeout", stat);
+ *startstop = ide_error(drive, "status timeout", stat);
return 1;
}
}
if (OK_STAT((stat = hwif->INB(IDE_STATUS_REG)), good, bad))
return 0;
}
- *startstop = DRIVER(drive)->error(drive, "status error", stat);
+ *startstop = ide_error(drive, "status error", stat);
return 1;
}
*/
u8 eighty_ninty_three (ide_drive_t *drive)
{
-#if 0
- if (!HWIF(drive)->udma_four)
+ if(HWIF(drive)->udma_four == 0)
+ return 0;
+ if (!(drive->id->hw_config & 0x6000))
return 0;
-
- if (drive->id->major_rev_num) {
- int hssbd = 0;
- int i;
- /*
- * Determine highest Supported SPEC
- */
- for (i=1; i<=15; i++)
- if (drive->id->major_rev_num & (1<<i))
- hssbd++;
-
- switch (hssbd) {
- case 7:
- case 6:
- case 5:
- /* ATA-4 and older do not support above Ultra 33 */
- default:
- return 0;
- }
- }
-
- return ((u8) (
-#ifndef CONFIG_IDEDMA_IVB
- (drive->id->hw_config & 0x4000) &&
-#endif /* CONFIG_IDEDMA_IVB */
- (drive->id->hw_config & 0x6000)) ? 1 : 0);
-
-#else
-
- return ((u8) ((HWIF(drive)->udma_four) &&
#ifndef CONFIG_IDEDMA_IVB
- (drive->id->hw_config & 0x4000) &&
+ if(!(drive->id->hw_config & 0x4000))
+ return 0;
#endif /* CONFIG_IDEDMA_IVB */
- (drive->id->hw_config & 0x6000)) ? 1 : 0);
-#endif
+ return 1;
}
EXPORT_SYMBOL(eighty_ninty_three);
return 0;
}
-EXPORT_SYMBOL(ide_ata66_check);
-
/*
* Backside of HDIO_DRIVE_CMD call of SETFEATURES_XFER.
* 1 : Safe to update drive->id DMA registers.
return 0;
}
-EXPORT_SYMBOL(set_transfer);
-
-u8 ide_auto_reduce_xfer (ide_drive_t *drive)
+#ifdef CONFIG_BLK_DEV_IDEDMA
+static u8 ide_auto_reduce_xfer (ide_drive_t *drive)
{
if (!drive->crc_count)
return drive->current_speed;
default: return XFER_PIO_4;
}
}
-
-EXPORT_SYMBOL(ide_auto_reduce_xfer);
+#endif /* CONFIG_BLK_DEV_IDEDMA */
/*
* Update the
SELECT_MASK(drive, 1);
if (IDE_CONTROL_REG)
hwif->OUTB(drive->ctl,IDE_CONTROL_REG);
- ide_delay_50ms();
+ msleep(50);
hwif->OUTB(WIN_IDENTIFY, IDE_COMMAND_REG);
timeout = jiffies + WAIT_WORSTCASE;
do {
SELECT_MASK(drive, 0);
return 0; /* drive timed-out */
}
- ide_delay_50ms(); /* give drive a breather */
+ msleep(50); /* give drive a breather */
} while (hwif->INB(IDE_ALTSTATUS_REG) & BUSY_STAT);
- ide_delay_50ms(); /* wait for IRQ and DRQ_STAT */
+ msleep(50); /* wait for IRQ and DRQ_STAT */
if (!OK_STAT(hwif->INB(IDE_STATUS_REG),DRQ_STAT,BAD_R_STAT)) {
SELECT_MASK(drive, 0);
printk("%s: CHECK for good STATUS\n", drive->name);
#endif
}
-EXPORT_SYMBOL(ide_driveid_update);
-
/*
* Similar to ide_wait_stat(), except it never calls ide_error internally.
* This is a kludge to handle the new ide_config_drive_speed() function,
* It is gone..........
*
* const char *msg == consider adding for verbose errors.
+ *
+ * Beware. If we timed out from a series of CRC errors and the timer
+ * expiry caused a switch to PIO mode and we take an IRQ as the drive times
+ * out about the same moment we may be entering this function with a
+ * pending interrupt.
*/
int ide_config_drive_speed (ide_drive_t *drive, u8 speed)
{
u8 stat;
// while (HWGROUP(drive)->busy)
-// ide_delay_50ms();
+// msleep(50);
#ifdef CONFIG_BLK_DEV_IDEDMA
if (hwif->ide_dma_check) /* check if host supports DMA */
/*
* Don't use ide_wait_cmd here - it will
- * attempt to set_geometry and recalibrate,
- * but for some reason these don't work at
- * this point (lost interrupt).
- */
- /*
- * Select the drive, and issue the SETFEATURES command
+ * attempt to set_geometry and recalibrate, We can't
+ * do that here as we may be in the IRQ handler already
+ *
+ * Select the drive, and issue the SETFEATURES command in
+ * polled mode.
*/
disable_irq_nosync(hwif->irq);
/*
- * FIXME: we race against the running IRQ here if
+ * We race against the running IRQ here if
* this is called from non IRQ context. If we use
- * disable_irq() we hang on the error path. Work
- * is needed.
+ * disable_irq() we hang on the error path. Instead we
+ * must let the core code know the hwif is doing a polling
+ * recovery.
*/
udelay(1);
hwif->OUTB(drive->ctl | 2, IDE_CONTROL_REG);
hwif->OUTB(speed, IDE_NSECTOR_REG);
hwif->OUTB(SETFEATURES_XFER, IDE_FEATURE_REG);
- hwif->OUTB(WIN_SETFEATURES, IDE_COMMAND_REG);
- if ((IDE_CONTROL_REG) && (drive->quirk_list == 2))
+ hwif->OUTBSYNC(drive, WIN_SETFEATURES, IDE_COMMAND_REG);
+ /* The status bits are not valid for 400nS */
+ udelay(1);
+
+ /* Drive status is now valid which means we can allow interrupts
+ to occur as they will see the drive as busy and will not
+ interfere erroneously. IRQ's for this drive will also be off
+ providing control and quirks allow for it */
+
+ if ((IDE_CONTROL_REG) && drive->quirk_list == 2)
hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
udelay(1);
+
+ /*
+ * Tell the interrupt layer that we are doing polled recovery.
+ * Eventually this should use the same mechanism do_reset does
+ * internally.
+ */
+
+ hwif->polling = 1;
+
/*
* Wait for drive to become non-BUSY
*/
if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) {
- unsigned long flags, timeout;
- local_irq_set(flags);
+ unsigned long timeout;
+ /* FIXME */
+/* spin_unlock_irq(&ide_lock); */
timeout = jiffies + WAIT_CMD;
while ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) {
if (time_after(jiffies, timeout))
break;
}
- local_irq_restore(flags);
+/* spin_lock_irq(&ide_lock); */
}
+
+ hwif->polling = 0;
/*
* Allow status to settle, then read it again.
*
* See also ide_execute_command
*/
-void __ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
+static void __ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
unsigned int timeout, ide_expiry_t *expiry)
{
ide_hwgroup_t *hwgroup = HWGROUP(drive);
add_timer(&hwgroup->timer);
}
-EXPORT_SYMBOL(__ide_set_handler);
-
void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
unsigned int timeout, ide_expiry_t *expiry)
{
return ide_started;
}
/* end of polling */
- hwgroup->poll_timeout = 0;
+ hwgroup->polling = 0;
printk("%s: ATAPI reset timed-out, status=0x%02x\n",
drive->name, stat);
/* do it the old fashioned way */
return do_reset1(drive, 1);
}
/* done polling */
- hwgroup->poll_timeout = 0;
+ hwgroup->polling = 0;
return ide_stopped;
}
drive->failures = 0;
} else {
drive->failures++;
-#if FANCY_STATUS_DUMPS
printk("master: ");
switch (tmp & 0x7f) {
case 1: printk("passed");
if (tmp & 0x80)
printk("; slave: failed");
printk("\n");
-#else
- printk("failed\n");
-#endif /* FANCY_STATUS_DUMPS */
}
}
- hwgroup->poll_timeout = 0; /* done polling */
+ hwgroup->polling = 0; /* done polling */
return ide_stopped;
}
#endif
}
-void pre_reset (ide_drive_t *drive)
+static void ide_disk_pre_reset(ide_drive_t *drive)
{
- DRIVER(drive)->pre_reset(drive);
+ int legacy = (drive->id->cfs_enable_2 & 0x0400) ? 0 : 1;
+
+ drive->special.all = 0;
+ drive->special.b.set_geometry = legacy;
+ drive->special.b.recalibrate = legacy;
+ if (OK_TO_RESET_CONTROLLER)
+ drive->mult_count = 0;
+ if (!drive->keep_settings && !drive->using_dma)
+ drive->mult_req = 0;
+ if (drive->mult_req != drive->mult_count)
+ drive->special.b.set_multmode = 1;
+}
+
+static void pre_reset(ide_drive_t *drive)
+{
+ if (drive->media == ide_disk)
+ ide_disk_pre_reset(drive);
+ else
+ drive->post_reset = 1;
if (!drive->keep_settings) {
if (drive->using_dma) {
pre_reset(drive);
SELECT_DRIVE(drive);
udelay (20);
- hwif->OUTB(WIN_SRST, IDE_COMMAND_REG);
+ hwif->OUTBSYNC(drive, WIN_SRST, IDE_COMMAND_REG);
+ ndelay(400);
hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
+ hwgroup->polling = 1;
__ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
spin_unlock_irqrestore(&ide_lock, flags);
return ide_started;
/* more than enough time */
udelay(10);
hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
+ hwgroup->polling = 1;
__ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
/*