#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
+#include <linux/completion.h>
#include <linux/suspend.h>
+#include <linux/workqueue.h>
#include <scsi/scsi.h>
#include "scsi.h"
-#include "hosts.h"
+#include <scsi/scsi_host.h>
#include <linux/libata.h>
#include <asm/io.h>
#include <asm/semaphore.h>
#include "libata.h"
-static void atapi_cdb_send(struct ata_port *ap);
static unsigned int ata_busy_sleep (struct ata_port *ap,
unsigned long tmout_pat,
unsigned long tmout);
static void __ata_dev_select (struct ata_port *ap, unsigned int device);
-#if 0 /* to be used eventually */
-static void ata_qc_push (struct ata_queued_cmd *qc, unsigned int append);
-#endif
-static void ata_dma_complete(struct ata_port *ap, u8 host_stat,
- unsigned int done_late);
+static void ata_dma_complete(struct ata_queued_cmd *qc, u8 host_stat);
static void ata_host_set_pio(struct ata_port *ap);
static void ata_host_set_udma(struct ata_port *ap);
static void ata_dev_set_pio(struct ata_port *ap, unsigned int device);
static void ata_dev_set_udma(struct ata_port *ap, unsigned int device);
static void ata_set_mode(struct ata_port *ap);
+static int ata_qc_issue_prot(struct ata_queued_cmd *qc);
static unsigned int ata_unique_id = 1;
+static struct workqueue_struct *ata_wq;
MODULE_AUTHOR("Jeff Garzik");
MODULE_DESCRIPTION("Library module for ATA devices");
"THR_IDLE",
"THR_PROBE_SUCCESS",
"THR_PROBE_START",
- "THR_PIO_POLL",
- "THR_PIO_TMOUT",
- "THR_PIO",
- "THR_PIO_LAST",
- "THR_PIO_LAST_POLL",
- "THR_PIO_ERR",
- "THR_PACKET",
};
/**
return "<invalid THR_xxx state>";
}
-/**
- * msleep - sleep for a number of milliseconds
- * @msecs: number of milliseconds to sleep
- *
- * Issues schedule_timeout call for the specified number
- * of milliseconds.
- *
- * LOCKING:
- * None.
- */
-
-static void msleep(unsigned long msecs)
-{
- set_current_state(TASK_UNINTERRUPTIBLE);
- schedule_timeout(msecs_to_jiffies(msecs) + 1);
-}
-
/**
* ata_tf_load_pio - send taskfile registers to host controller
- * @ioaddr: set of IO ports to which output is sent
+ * @ap: Port to which output is sent
* @tf: ATA taskfile register set
*
* Outputs ATA taskfile to standard ATA host controller using PIO.
/**
* ata_tf_load_mmio - send taskfile registers to host controller
- * @ioaddr: set of IO ports to which output is sent
+ * @ap: Port to which output is sent
* @tf: ATA taskfile register set
*
* Outputs ATA taskfile to standard ATA host controller using MMIO.
static void ata_tf_to_host(struct ata_port *ap, struct ata_taskfile *tf)
{
- init_MUTEX_LOCKED(&ap->sem);
-
ap->ops->tf_load(ap, tf);
ata_exec(ap, tf);
void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf)
{
- init_MUTEX_LOCKED(&ap->sem);
-
ap->ops->tf_load(ap, tf);
ap->ops->exec_command(ap, tf);
}
/**
* ata_tf_read_pio - input device's ATA taskfile shadow registers
- * @ioaddr: set of IO ports from which input is read
+ * @ap: Port from which input is read
* @tf: ATA taskfile register set for storing input
*
* Reads ATA taskfile registers for currently-selected device
/**
* ata_tf_read_mmio - input device's ATA taskfile shadow registers
- * @ioaddr: set of IO ports from which input is read
+ * @ap: Port from which input is read
* @tf: ATA taskfile register set for storing input
*
* Reads ATA taskfile registers for currently-selected device
return readb((void *) ap->ioaddr.status_addr);
}
+/**
+ * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
+ * @tf: Taskfile to convert
+ * @fis: Buffer into which data will output
+ * @pmp: Port multiplier port
+ *
+ * Converts a standard ATA taskfile to a Serial ATA
+ * FIS structure (Register - Host to Device).
+ *
+ * LOCKING:
+ * Inherited from caller.
+ */
+
+void ata_tf_to_fis(struct ata_taskfile *tf, u8 *fis, u8 pmp)
+{
+ fis[0] = 0x27; /* Register - Host to Device FIS */
+ fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number,
+ bit 7 indicates Command FIS */
+ fis[2] = tf->command;
+ fis[3] = tf->feature;
+
+ fis[4] = tf->lbal;
+ fis[5] = tf->lbam;
+ fis[6] = tf->lbah;
+ fis[7] = tf->device;
+
+ fis[8] = tf->hob_lbal;
+ fis[9] = tf->hob_lbam;
+ fis[10] = tf->hob_lbah;
+ fis[11] = tf->hob_feature;
+
+ fis[12] = tf->nsect;
+ fis[13] = tf->hob_nsect;
+ fis[14] = 0;
+ fis[15] = tf->ctl;
+
+ fis[16] = 0;
+ fis[17] = 0;
+ fis[18] = 0;
+ fis[19] = 0;
+}
+
+/**
+ * ata_tf_from_fis - Convert SATA FIS to ATA taskfile
+ * @fis: Buffer from which data will be input
+ * @tf: Taskfile to output
+ *
+ * Converts a standard ATA taskfile to a Serial ATA
+ * FIS structure (Register - Host to Device).
+ *
+ * LOCKING:
+ * Inherited from caller.
+ */
+
+void ata_tf_from_fis(u8 *fis, struct ata_taskfile *tf)
+{
+ tf->command = fis[2]; /* status */
+ tf->feature = fis[3]; /* error */
+
+ tf->lbal = fis[4];
+ tf->lbam = fis[5];
+ tf->lbah = fis[6];
+ tf->device = fis[7];
+
+ tf->hob_lbal = fis[8];
+ tf->hob_lbam = fis[9];
+ tf->hob_lbah = fis[10];
+
+ tf->nsect = fis[12];
+ tf->hob_nsect = fis[13];
+}
+
/**
* ata_prot_to_cmd - determine which read/write opcodes to use
* @protocol: ATA_PROT_xxx taskfile protocol
* @dev: Device whose IDENTIFY DEVICE results we will examine
* @s: string into which data is output
* @ofs: offset into identify device page
- * @len: length of string to return
+ * @len: length of string to return. must be an even number.
*
* The strings in the IDENTIFY DEVICE page are broken up into
* 16-bit chunks. Run through the string, and output each
}
}
-/**
- * ata_dev_parse_strings - Store useful IDENTIFY DEVICE page strings
- * @dev: Device whose IDENTIFY DEVICE page info we use
- *
- * We store 'vendor' and 'product' strings read from the device,
- * for later use in the SCSI simulator's INQUIRY data.
- *
- * Set these strings here, in the case of 'product', using
- * data read from the ATA IDENTIFY DEVICE page.
- *
- * LOCKING:
- * caller.
- */
-
-static void ata_dev_parse_strings(struct ata_device *dev)
-{
- assert (dev->class == ATA_DEV_ATA);
- memcpy(dev->vendor, "ATA ", 8);
-
- ata_dev_id_string(dev, dev->product, ATA_ID_PROD_OFS,
- sizeof(dev->product));
-}
-
/**
* __ata_dev_select - Select device 0/1 on ATA bus
* @ap: ATA channel to manipulate
ata_dump_id(dev);
- ata_dev_parse_strings(dev);
-
/* ATA-specific feature tests */
if (dev->class == ATA_DEV_ATA) {
if (!ata_id_is_ata(dev)) /* sanity check */
ap->host->max_cmd_len = 16;
/* print device info to dmesg */
- printk(KERN_INFO "ata%u: dev %u ATA, max %s, %Lu sectors%s\n",
+ printk(KERN_INFO "ata%u: dev %u ATA, max %s, %Lu sectors:%s\n",
ap->id, device,
ata_udma_string(udma_modes),
(unsigned long long)dev->n_sectors,
- dev->flags & ATA_DFLAG_LBA48 ? " (lba48)" : "");
+ dev->flags & ATA_DFLAG_LBA48 ? " lba48" : "");
}
/* ATAPI-specific feature tests */
}
/**
- * ata_dev_set_xfermode -
- * @ap:
- * @dev:
+ * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
+ * @ap: Port associated with device @dev
+ * @dev: Device to which command will be sent
*
* LOCKING:
*/
}
/**
- * ata_dev_set_udma -
- * @ap:
- * @device:
+ * ata_dev_set_udma - Set ATA device's transfer mode to Ultra DMA
+ * @ap: Port associated with device @dev
+ * @device: Device whose mode will be set
*
* LOCKING:
*/
}
/**
- * ata_dev_set_pio -
- * @ap:
- * @device:
+ * ata_dev_set_pio - Set ATA device's transfer mode to PIO
+ * @ap: Port associated with device @dev
+ * @device: Device whose mode will be set
*
* LOCKING:
*/
static unsigned long ata_pio_poll(struct ata_port *ap)
{
u8 status;
- unsigned int poll_state = THR_UNKNOWN;
- unsigned int reg_state = THR_UNKNOWN;
- const unsigned int tmout_state = THR_PIO_TMOUT;
-
- switch (ap->thr_state) {
- case THR_PIO:
- case THR_PIO_POLL:
- poll_state = THR_PIO_POLL;
- reg_state = THR_PIO;
+ unsigned int poll_state = PIO_ST_UNKNOWN;
+ unsigned int reg_state = PIO_ST_UNKNOWN;
+ const unsigned int tmout_state = PIO_ST_TMOUT;
+
+ switch (ap->pio_task_state) {
+ case PIO_ST:
+ case PIO_ST_POLL:
+ poll_state = PIO_ST_POLL;
+ reg_state = PIO_ST;
break;
- case THR_PIO_LAST:
- case THR_PIO_LAST_POLL:
- poll_state = THR_PIO_LAST_POLL;
- reg_state = THR_PIO_LAST;
+ case PIO_ST_LAST:
+ case PIO_ST_LAST_POLL:
+ poll_state = PIO_ST_LAST_POLL;
+ reg_state = PIO_ST_LAST;
break;
default:
BUG();
status = ata_chk_status(ap);
if (status & ATA_BUSY) {
- if (time_after(jiffies, ap->thr_timeout)) {
- ap->thr_state = tmout_state;
+ if (time_after(jiffies, ap->pio_task_timeout)) {
+ ap->pio_task_state = tmout_state;
return 0;
}
- ap->thr_state = poll_state;
+ ap->pio_task_state = poll_state;
return ATA_SHORT_PAUSE;
}
- ap->thr_state = reg_state;
+ ap->pio_task_state = reg_state;
return 0;
}
-/**
- * ata_pio_start -
- * @qc:
- *
- * LOCKING:
- * spin_lock_irqsave(host_set lock)
- */
-
-static void ata_pio_start (struct ata_queued_cmd *qc)
-{
- struct ata_port *ap = qc->ap;
-
- assert(qc->tf.protocol == ATA_PROT_PIO);
-
- qc->flags |= ATA_QCFLAG_POLL;
- qc->tf.ctl |= ATA_NIEN; /* disable interrupts */
- ata_tf_to_host_nolock(ap, &qc->tf);
- ata_thread_wake(ap, THR_PIO);
-}
-
/**
* ata_pio_complete -
* @ap:
static void ata_pio_complete (struct ata_port *ap)
{
struct ata_queued_cmd *qc;
- unsigned long flags;
u8 drv_stat;
/*
* a chk-status or two. If not, the drive is probably seeking
* or something. Snooze for a couple msecs, then
* chk-status again. If still busy, fall back to
- * THR_PIO_POLL state.
+ * PIO_ST_POLL state.
*/
drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10);
if (drv_stat & (ATA_BUSY | ATA_DRQ)) {
msleep(2);
drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10);
if (drv_stat & (ATA_BUSY | ATA_DRQ)) {
- ap->thr_state = THR_PIO_LAST_POLL;
- ap->thr_timeout = jiffies + ATA_TMOUT_PIO;
+ ap->pio_task_state = PIO_ST_LAST_POLL;
+ ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
return;
}
}
drv_stat = ata_wait_idle(ap);
if (drv_stat & (ATA_BUSY | ATA_DRQ)) {
- ap->thr_state = THR_PIO_ERR;
+ ap->pio_task_state = PIO_ST_ERR;
return;
}
qc = ata_qc_from_tag(ap, ap->active_tag);
assert(qc != NULL);
- spin_lock_irqsave(&ap->host_set->lock, flags);
- ap->thr_state = THR_IDLE;
- spin_unlock_irqrestore(&ap->host_set->lock, flags);
+ ap->pio_task_state = PIO_ST_IDLE;
ata_irq_on(ap);
- ata_qc_complete(qc, drv_stat, 0);
+ ata_qc_complete(qc, drv_stat);
}
/**
* a chk-status or two. If not, the drive is probably seeking
* or something. Snooze for a couple msecs, then
* chk-status again. If still busy, fall back to
- * THR_PIO_POLL state.
+ * PIO_ST_POLL state.
*/
status = ata_busy_wait(ap, ATA_BUSY, 5);
if (status & ATA_BUSY) {
msleep(2);
status = ata_busy_wait(ap, ATA_BUSY, 10);
if (status & ATA_BUSY) {
- ap->thr_state = THR_PIO_POLL;
- ap->thr_timeout = jiffies + ATA_TMOUT_PIO;
+ ap->pio_task_state = PIO_ST_POLL;
+ ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
return;
}
}
/* handle BSY=0, DRQ=0 as error */
if ((status & ATA_DRQ) == 0) {
- ap->thr_state = THR_PIO_ERR;
+ ap->pio_task_state = PIO_ST_ERR;
return;
}
sg = qc->sg;
if (qc->cursect == (qc->nsect - 1))
- ap->thr_state = THR_PIO_LAST;
+ ap->pio_task_state = PIO_ST_LAST;
buf = kmap(sg[qc->cursg].page) +
sg[qc->cursg].offset + (qc->cursg_ofs * ATA_SECT_SIZE);
kunmap(sg[qc->cursg].page);
}
-#if 0 /* to be used eventually */
-/**
- * ata_eng_schedule - run an iteration of the pio/dma/whatever engine
- * @ap: port on which activity will occur
- * @eng: instance of engine
- *
- * LOCKING:
- * spin_lock_irqsave(host_set lock)
- */
-static void ata_eng_schedule (struct ata_port *ap, struct ata_engine *eng)
+static void ata_pio_task(void *_data)
{
- /* FIXME */
+ struct ata_port *ap = _data;
+ unsigned long timeout = 0;
+
+ switch (ap->pio_task_state) {
+ case PIO_ST:
+ ata_pio_sector(ap);
+ break;
+
+ case PIO_ST_LAST:
+ ata_pio_complete(ap);
+ break;
+
+ case PIO_ST_POLL:
+ case PIO_ST_LAST_POLL:
+ timeout = ata_pio_poll(ap);
+ break;
+
+ case PIO_ST_TMOUT:
+ printk(KERN_ERR "ata%d: FIXME: PIO_ST_TMOUT\n", /* FIXME */
+ ap->id);
+ timeout = 11 * HZ;
+ break;
+
+ case PIO_ST_ERR:
+ printk(KERN_ERR "ata%d: FIXME: PIO_ST_ERR\n", /* FIXME */
+ ap->id);
+ timeout = 11 * HZ;
+ break;
+ }
+
+ if ((ap->pio_task_state != PIO_ST_IDLE) &&
+ (ap->pio_task_state != PIO_ST_TMOUT) &&
+ (ap->pio_task_state != PIO_ST_ERR)) {
+ if (timeout)
+ queue_delayed_work(ata_wq, &ap->pio_task,
+ timeout);
+ else
+ queue_work(ata_wq, &ap->pio_task);
+ }
}
-#endif
/**
* ata_eng_timeout - Handle timeout of queued command
printk(KERN_ERR "ata%u: DMA timeout, stat 0x%x\n",
ap->id, host_stat);
- ata_dma_complete(ap, host_stat, 1);
+ ata_dma_complete(qc, host_stat);
break;
case ATA_PROT_NODATA:
printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x\n",
ap->id, qc->tf.command, drv_stat);
- ata_qc_complete(qc, drv_stat, 1);
+ ata_qc_complete(qc, drv_stat);
break;
default:
printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
ap->id, qc->tf.command, drv_stat);
- ata_qc_complete(qc, drv_stat, 1);
+ ata_qc_complete(qc, drv_stat);
break;
}
}
/**
- * ata_qc_new -
- * @ap:
- * @dev:
+ * ata_qc_new - Request an available ATA command, for queueing
+ * @ap: Port associated with device @dev
+ * @dev: Device from whom we request an available command structure
*
* LOCKING:
*/
}
/**
- * ata_qc_new_init -
- * @ap:
- * @dev:
+ * ata_qc_new_init - Request an available ATA command, and initialize it
+ * @ap: Port associated with device @dev
+ * @dev: Device from whom we request an available command structure
*
* LOCKING:
*/
qc->ap = ap;
qc->dev = dev;
qc->cursect = qc->cursg = qc->cursg_ofs = 0;
- INIT_LIST_HEAD(&qc->node);
- init_MUTEX_LOCKED(&qc->sem);
+ qc->nsect = 0;
ata_tf_init(ap, &qc->tf, dev->devno);
}
/**
- * ata_qc_complete -
- * @qc:
- * @drv_stat:
- * @done_late:
+ * ata_qc_complete - Complete an active ATA command
+ * @qc: Command to complete
+ * @drv_stat: ATA status register contents
*
* LOCKING:
*
*/
-void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat, unsigned int done_late)
+void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
{
struct ata_port *ap = qc->ap;
struct scsi_cmnd *cmd = qc->scsicmd;
if (cmd) {
if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) {
- if (qc->flags & ATA_QCFLAG_ATAPI)
+ if (is_atapi_taskfile(&qc->tf))
cmd->result = SAM_STAT_CHECK_CONDITION;
else
ata_to_sense_error(qc);
do_clear = 1;
}
- up(&qc->sem);
+ if (qc->waiting)
+ complete(qc->waiting);
if (likely(do_clear))
clear_bit(tag, &ap->qactive);
}
-#if 0 /* to be used eventually */
/**
- * ata_qc_push -
- * @qc:
- * @append:
+ * ata_qc_issue - issue taskfile to device
+ * @qc: command to issue to device
+ *
+ * Prepare an ATA command to submission to device.
+ * This includes mapping the data into a DMA-able
+ * area, filling in the S/G table, and finally
+ * writing the taskfile to hardware, starting the command.
*
* LOCKING:
* spin_lock_irqsave(host_set lock)
+ *
+ * RETURNS:
+ * Zero on success, negative on error.
*/
-static void ata_qc_push (struct ata_queued_cmd *qc, unsigned int append)
+
+int ata_qc_issue(struct ata_queued_cmd *qc)
{
struct ata_port *ap = qc->ap;
- struct ata_engine *eng = &ap->eng;
+ struct scsi_cmnd *cmd = qc->scsicmd;
- if (likely(append))
- list_add_tail(&qc->node, &eng->q);
- else
- list_add(&qc->node, &eng->q);
+ if (qc->flags & ATA_QCFLAG_SG) {
+ /* set up SG table */
+ if (cmd->use_sg) {
+ if (ata_sg_setup(qc))
+ goto err_out;
+ } else {
+ if (ata_sg_setup_one(qc))
+ goto err_out;
+ }
- if (!test_and_set_bit(ATA_EFLG_ACTIVE, &eng->flags))
- ata_eng_schedule(ap, eng);
+ ap->ops->fill_sg(qc);
+ }
+
+ qc->ap->active_tag = qc->tag;
+ qc->flags |= ATA_QCFLAG_ACTIVE;
+
+ return ata_qc_issue_prot(qc);
+
+err_out:
+ return -1;
}
-#endif
/**
- * ata_qc_issue -
- * @qc:
+ * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
+ * @qc: command to issue to device
+ *
+ * Using various libata functions and hooks, this function
+ * starts an ATA command. ATA commands are grouped into
+ * classes called "protocols", and issuing each type of protocol
+ * is slightly different.
*
* LOCKING:
+ * spin_lock_irqsave(host_set lock)
*
* RETURNS:
- *
+ * Zero on success, negative on error.
*/
-int ata_qc_issue(struct ata_queued_cmd *qc)
+
+static int ata_qc_issue_prot(struct ata_queued_cmd *qc)
{
struct ata_port *ap = qc->ap;
- struct scsi_cmnd *cmd = qc->scsicmd;
- unsigned int dma = qc->flags & ATA_QCFLAG_DMA;
ata_dev_select(ap, qc->dev->devno, 1, 0);
- /* set up SG table */
- if (cmd->use_sg) {
- if (ata_sg_setup(qc))
- goto err_out;
- } else {
- if (ata_sg_setup_one(qc))
- goto err_out;
- }
+ switch (qc->tf.protocol) {
+ case ATA_PROT_NODATA:
+ ata_tf_to_host_nolock(ap, &qc->tf);
+ break;
- ap->ops->fill_sg(qc);
+ case ATA_PROT_DMA:
+ ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
+ ap->ops->bmdma_setup(qc); /* set up bmdma */
+ ap->ops->bmdma_start(qc); /* initiate bmdma */
+ break;
- qc->ap->active_tag = qc->tag;
- qc->flags |= ATA_QCFLAG_ACTIVE;
+ case ATA_PROT_PIO: /* load tf registers, initiate polling pio */
+ ata_qc_set_polling(qc);
+ ata_tf_to_host_nolock(ap, &qc->tf);
+ ap->pio_task_state = PIO_ST;
+ queue_work(ata_wq, &ap->pio_task);
+ break;
- if (likely(dma)) {
- ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
- ap->ops->bmdma_start(qc); /* initiate bmdma */
- } else
- /* load tf registers, initiate polling pio */
- ata_pio_start(qc);
+ case ATA_PROT_ATAPI:
+ ata_tf_to_host_nolock(ap, &qc->tf);
+ queue_work(ata_wq, &ap->packet_task);
+ break;
- return 0;
+ case ATA_PROT_ATAPI_DMA:
+ ap->ops->tf_load(ap, &qc->tf); /* load tf registers */
+ ap->ops->bmdma_setup(qc); /* set up bmdma */
+ queue_work(ata_wq, &ap->packet_task);
+ break;
-err_out:
- return -1;
+ default:
+ WARN_ON(1);
+ return -1;
+ }
+
+ return 0;
}
/**
- * ata_bmdma_start_mmio -
- * @qc:
+ * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction (MMIO)
+ * @qc: Info associated with this ATA transaction.
*
* LOCKING:
* spin_lock_irqsave(host_set lock)
*/
-void ata_bmdma_start_mmio (struct ata_queued_cmd *qc)
+void ata_bmdma_setup_mmio (struct ata_queued_cmd *qc)
{
struct ata_port *ap = qc->ap;
unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
/* issue r/w command */
ap->ops->exec_command(ap, &qc->tf);
+}
+
+/**
+ * ata_bmdma_start_mmio - Start a PCI IDE BMDMA transaction (MMIO)
+ * @qc: Info associated with this ATA transaction.
+ *
+ * LOCKING:
+ * spin_lock_irqsave(host_set lock)
+ */
+
+void ata_bmdma_start_mmio (struct ata_queued_cmd *qc)
+{
+ struct ata_port *ap = qc->ap;
+ void *mmio = (void *) ap->ioaddr.bmdma_addr;
+ u8 dmactl;
/* start host DMA transaction */
+ dmactl = readb(mmio + ATA_DMA_CMD);
writeb(dmactl | ATA_DMA_START, mmio + ATA_DMA_CMD);
/* Strictly, one may wish to issue a readb() here, to
}
/**
- * ata_bmdma_start_pio -
- * @qc:
+ * ata_bmdma_setup_pio - Set up PCI IDE BMDMA transaction (PIO)
+ * @qc: Info associated with this ATA transaction.
*
* LOCKING:
* spin_lock_irqsave(host_set lock)
*/
-void ata_bmdma_start_pio (struct ata_queued_cmd *qc)
+void ata_bmdma_setup_pio (struct ata_queued_cmd *qc)
{
struct ata_port *ap = qc->ap;
unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
/* issue r/w command */
ap->ops->exec_command(ap, &qc->tf);
+}
+
+/**
+ * ata_bmdma_start_pio - Start a PCI IDE BMDMA transaction (PIO)
+ * @qc: Info associated with this ATA transaction.
+ *
+ * LOCKING:
+ * spin_lock_irqsave(host_set lock)
+ */
+
+void ata_bmdma_start_pio (struct ata_queued_cmd *qc)
+{
+ struct ata_port *ap = qc->ap;
+ u8 dmactl;
/* start host DMA transaction */
+ dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
outb(dmactl | ATA_DMA_START,
ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
}
/**
- * ata_dma_complete -
- * @ap:
- * @host_stat:
- * @done_late:
+ * ata_dma_complete - Complete an active ATA BMDMA command
+ * @qc: Command to complete
+ * @host_stat: BMDMA status register contents
*
* LOCKING:
*/
-static void ata_dma_complete(struct ata_port *ap, u8 host_stat,
- unsigned int done_late)
+static void ata_dma_complete(struct ata_queued_cmd *qc, u8 host_stat)
{
+ struct ata_port *ap = qc->ap;
VPRINTK("ENTER\n");
if (ap->flags & ATA_FLAG_MMIO) {
ap->id, (u32) host_stat, (u32) ata_chk_status(ap));
/* get drive status; clear intr; complete txn */
- ata_qc_complete(ata_qc_from_tag(ap, ap->active_tag),
- ata_wait_idle(ap), done_late);
+ ata_qc_complete(qc, ata_wait_idle(ap));
}
/**
unsigned int handled = 0;
switch (qc->tf.protocol) {
+
+ /* BMDMA completion */
case ATA_PROT_DMA:
+ case ATA_PROT_ATAPI_DMA:
if (ap->flags & ATA_FLAG_MMIO) {
void *mmio = (void *) ap->ioaddr.bmdma_addr;
host_stat = readb(mmio + ATA_DMA_STATUS);
break;
}
- ata_dma_complete(ap, host_stat, 0);
+ ata_dma_complete(qc, host_stat);
handled = 1;
break;
- case ATA_PROT_NODATA: /* command completion, but no data xfer */
+ /* command completion, but no data xfer */
+ /* FIXME: a shared interrupt _will_ cause a non-data command
+ * to be completed prematurely, with an error.
+ *
+ * This doesn't matter right now, since we aren't sending
+ * non-data commands down this pipe except in development
+ * situations.
+ */
+ case ATA_PROT_ATAPI:
+ case ATA_PROT_NODATA:
status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status);
- ata_qc_complete(qc, status, 0);
+ ata_qc_complete(qc, status);
handled = 1;
break;
}
/**
- * ata_interrupt -
- * @irq:
- * @dev_instance:
- * @regs:
+ * ata_interrupt - Default ATA host interrupt handler
+ * @irq: irq line
+ * @dev_instance: pointer to our host information structure
+ * @regs: unused
*
* LOCKING:
*
struct ata_queued_cmd *qc;
qc = ata_qc_from_tag(ap, ap->active_tag);
- if (qc && ((qc->flags & ATA_QCFLAG_POLL) == 0))
+ if (qc && (!(qc->tf.ctl & ATA_NIEN)))
handled += ata_host_intr(ap, qc);
}
}
return IRQ_RETVAL(handled);
}
-/**
- * ata_thread_wake -
- * @ap:
- * @thr_state:
- *
- * LOCKING:
- * spin_lock_irqsave(host_set lock)
- */
-
-void ata_thread_wake(struct ata_port *ap, unsigned int thr_state)
-{
- assert(ap->thr_state == THR_IDLE);
- ap->thr_state = thr_state;
- up(&ap->thr_sem);
-}
-
-/**
- * ata_thread_timer -
- * @opaque:
- *
- * LOCKING:
- */
-
-static void ata_thread_timer(unsigned long opaque)
-{
- struct ata_port *ap = (struct ata_port *) opaque;
-
- up(&ap->thr_sem);
-}
-
/**
* ata_thread_iter -
* @ap:
break;
case THR_PROBE_START:
- down(&ap->sem);
ap->thr_state = THR_PORT_RESET;
break;
break;
case THR_AWAIT_DEATH:
- timeout = -1;
- break;
-
case THR_IDLE:
- timeout = 30 * HZ;
- break;
-
- case THR_PIO:
- ata_pio_sector(ap);
- break;
-
- case THR_PIO_LAST:
- ata_pio_complete(ap);
- break;
-
- case THR_PIO_POLL:
- case THR_PIO_LAST_POLL:
- timeout = ata_pio_poll(ap);
- break;
-
- case THR_PIO_TMOUT:
- printk(KERN_ERR "ata%d: FIXME: THR_PIO_TMOUT\n", /* FIXME */
- ap->id);
- timeout = 11 * HZ;
- break;
-
- case THR_PIO_ERR:
- printk(KERN_ERR "ata%d: FIXME: THR_PIO_ERR\n", /* FIXME */
- ap->id);
- timeout = 11 * HZ;
- break;
-
- case THR_PACKET:
- atapi_cdb_send(ap);
+ timeout = -1;
break;
default:
}
/**
- * ata_thread -
- * @data:
- *
- * LOCKING:
- *
- * RETURNS:
- *
- */
-
-static int ata_thread (void *data)
-{
- struct ata_port *ap = data;
- long timeout;
-
- daemonize ("katad-%u", ap->id);
- allow_signal(SIGTERM);
-
- while (1) {
- cond_resched();
-
- timeout = ata_thread_iter(ap);
-
- if (signal_pending (current))
- flush_signals(current);
-
- if (current->flags & PF_FREEZE)
- refrigerator(PF_FREEZE);
-
-
- if ((timeout < 0) || (ap->time_to_die))
- break;
-
- /* note sleeping for full timeout not guaranteed (that's ok) */
- if (timeout) {
- mod_timer(&ap->thr_timer, jiffies + timeout);
- down_interruptible(&ap->thr_sem);
-
- if (signal_pending (current))
- flush_signals(current);
-
- if (ap->time_to_die)
- break;
- }
- }
-
- printk(KERN_DEBUG "ata%u: thread exiting\n", ap->id);
- ap->thr_pid = -1;
- del_timer_sync(&ap->thr_timer);
- complete_and_exit (&ap->thr_exited, 0);
-}
-
-/**
- * ata_thread_kill - kill per-port kernel thread
- * @ap: port those thread is to be killed
- *
- * LOCKING:
- *
- */
-
-static int ata_thread_kill(struct ata_port *ap)
-{
- int ret = 0;
-
- if (ap->thr_pid >= 0) {
- ap->time_to_die = 1;
- wmb();
- ret = kill_proc(ap->thr_pid, SIGTERM, 1);
- if (ret)
- printk(KERN_ERR "ata%d: unable to kill kernel thread\n",
- ap->id);
- else
- wait_for_completion(&ap->thr_exited);
- }
-
- return ret;
-}
-
-/**
- * atapi_cdb_send - Write CDB bytes to hardware
- * @ap: Port to which ATAPI device is attached.
+ * atapi_packet_task - Write CDB bytes to hardware
+ * @_data: Port to which ATAPI device is attached.
*
* When device has indicated its readiness to accept
* a CDB, this function is called. Send the CDB.
* Kernel thread context (may sleep)
*/
-static void atapi_cdb_send(struct ata_port *ap)
+static void atapi_packet_task(void *_data)
{
+ struct ata_port *ap = _data;
struct ata_queued_cmd *qc;
u8 status;
qc->scsicmd->cmnd, ap->host->max_cmd_len / 4);
/* if we are DMA'ing, irq handler takes over from here */
- if (qc->tf.feature == ATAPI_PKT_DMA)
- goto out;
-
- /* sleep-wait for BSY to clear */
- DPRINTK("busy wait 2\n");
- if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB))
- goto err_out;
+ if (qc->tf.protocol == ATA_PROT_ATAPI_DMA)
+ ap->ops->bmdma_start(qc); /* initiate bmdma */
- /* wait for BSY,DRQ to clear */
- status = ata_wait_idle(ap);
- if (status & (ATA_BUSY | ATA_DRQ))
- goto err_out;
+ /* non-data commands are also handled via irq */
+ else if (qc->scsicmd->sc_data_direction == SCSI_DATA_NONE) {
+ /* do nothing */
+ }
- /* transaction completed, indicate such to scsi stack */
- ata_qc_complete(qc, status, 0);
- ata_irq_on(ap);
+ /* PIO commands are handled by polling */
+ else {
+ ap->pio_task_state = PIO_ST;
+ queue_work(ata_wq, &ap->pio_task);
+ }
-out:
- ap->thr_state = THR_IDLE;
return;
err_out:
- ata_qc_complete(qc, ATA_ERR, 0);
- goto out;
+ ata_qc_complete(qc, ATA_ERR);
}
int ata_port_start (struct ata_port *ap)
ap->prd = pci_alloc_consistent(pdev, ATA_PRD_TBL_SZ, &ap->prd_dma);
if (!ap->prd)
return -ENOMEM;
-
+
DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd, (unsigned long long) ap->prd_dma);
return 0;
pci_free_consistent(pdev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
}
+static void ata_probe_task(void *_data)
+{
+ struct ata_port *ap = _data;
+ long timeout;
+
+ timeout = ata_thread_iter(ap);
+ if (timeout < 0)
+ return;
+
+ if (timeout > 0)
+ queue_delayed_work(ata_wq, &ap->probe_task, timeout);
+ else
+ queue_work(ata_wq, &ap->probe_task);
+}
+
/**
- * ata_host_remove -
- * @ap:
- * @do_unregister:
+ * ata_host_remove - Unregister SCSI host structure with upper layers
+ * @ap: Port to unregister
+ * @do_unregister: 1 if we fully unregister, 0 to just stop the port
*
* LOCKING:
*/
if (do_unregister)
scsi_remove_host(sh);
- ata_thread_kill(ap); /* FIXME: check return val */
-
ap->ops->port_stop(ap);
}
/**
- * ata_host_init -
- * @host:
- * @ent:
- * @port_no:
+ * ata_host_init - Initialize an ata_port structure
+ * @ap: Structure to initialize
+ * @host: associated SCSI mid-layer structure
+ * @host_set: Collection of hosts to which @ap belongs
+ * @ent: Probe information provided by low-level driver
+ * @port_no: Port number associated with this ata_port
*
* LOCKING:
*
ap->active_tag = ATA_TAG_POISON;
ap->last_ctl = 0xFF;
- /* ata_engine init */
- ap->eng.flags = 0;
- INIT_LIST_HEAD(&ap->eng.q);
+ INIT_WORK(&ap->packet_task, atapi_packet_task, ap);
+ INIT_WORK(&ap->pio_task, ata_pio_task, ap);
+ INIT_WORK(&ap->probe_task, ata_probe_task, ap);
for (i = 0; i < ATA_MAX_DEVICES; i++)
ap->device[i].devno = i;
- init_completion(&ap->thr_exited);
init_MUTEX_LOCKED(&ap->probe_sem);
- init_MUTEX_LOCKED(&ap->sem);
- init_MUTEX_LOCKED(&ap->thr_sem);
-
- init_timer(&ap->thr_timer);
- ap->thr_timer.function = ata_thread_timer;
- ap->thr_timer.data = (unsigned long) ap;
#ifdef ATA_IRQ_TRAP
ap->stats.unhandled_irq = 1;
}
/**
- * ata_host_add -
- * @ent:
- * @host_set:
- * @port_no:
+ * ata_host_add - Attach low-level ATA driver to system
+ * @ent: Information provided by low-level driver
+ * @host_set: Collections of ports to which we add
+ * @port_no: Port number associated with this host
*
* LOCKING:
*
if (rc)
goto err_out;
- ap->thr_pid = kernel_thread(ata_thread, ap, CLONE_FS | CLONE_FILES);
- if (ap->thr_pid < 0) {
- printk(KERN_ERR "ata%d: unable to start kernel thread\n",
- ap->id);
- goto err_out_free;
- }
-
return ap;
-err_out_free:
- ap->ops->port_stop(ap);
-
err_out:
scsi_host_put(host);
return NULL;
ap = host_set->ports[i];
DPRINTK("ata%u: probe begin\n", ap->id);
- up(&ap->sem); /* start probe */
+ queue_work(ata_wq, &ap->probe_task); /* start probe */
DPRINTK("ata%u: probe-wait begin\n", ap->id);
down(&ap->probe_sem); /* wait for end */
* ata_scsi_release - SCSI layer callback hook for host unload
* @host: libata host to be unloaded
*
- * Performs all duties necessary to shut down a libata port:
+ * Performs all duties necessary to shut down a libata port...
* Kill port kthread, disable port, and release resources.
*
* LOCKING:
/**
* ata_std_ports - initialize ioaddr with standard port offsets.
- * @ioaddr:
+ * @ioaddr: IO address structure to be initialized
*/
void ata_std_ports(struct ata_ioports *ioaddr)
{
}
/**
- * ata_pci_init_one -
- * @pdev:
- * @port_info:
- * @n_ports:
+ * ata_pci_init_one - Initialize/register PCI IDE host controller
+ * @pdev: Controller to be initialized
+ * @port_info: Information from low-level host driver
+ * @n_ports: Number of ports attached to host controller
*
* LOCKING:
* Inherited from PCI layer (may sleep).
static int __init ata_init(void)
{
+ ata_wq = create_workqueue("ata");
+ if (!ata_wq)
+ return -ENOMEM;
+
printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n");
return 0;
}
+static void __exit ata_exit(void)
+{
+ destroy_workqueue(ata_wq);
+}
+
module_init(ata_init);
+module_exit(ata_exit);
/*
* libata is essentially a library of internal helper functions for
EXPORT_SYMBOL_GPL(ata_tf_load_mmio);
EXPORT_SYMBOL_GPL(ata_tf_read_pio);
EXPORT_SYMBOL_GPL(ata_tf_read_mmio);
+EXPORT_SYMBOL_GPL(ata_tf_to_fis);
+EXPORT_SYMBOL_GPL(ata_tf_from_fis);
EXPORT_SYMBOL_GPL(ata_check_status_pio);
EXPORT_SYMBOL_GPL(ata_check_status_mmio);
EXPORT_SYMBOL_GPL(ata_exec_command_pio);
EXPORT_SYMBOL_GPL(ata_port_stop);
EXPORT_SYMBOL_GPL(ata_interrupt);
EXPORT_SYMBOL_GPL(ata_fill_sg);
+EXPORT_SYMBOL_GPL(ata_bmdma_setup_pio);
EXPORT_SYMBOL_GPL(ata_bmdma_start_pio);
+EXPORT_SYMBOL_GPL(ata_bmdma_setup_mmio);
EXPORT_SYMBOL_GPL(ata_bmdma_start_mmio);
EXPORT_SYMBOL_GPL(ata_port_probe);
EXPORT_SYMBOL_GPL(sata_phy_reset);
EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
EXPORT_SYMBOL_GPL(ata_scsi_release);
EXPORT_SYMBOL_GPL(ata_host_intr);
+EXPORT_SYMBOL_GPL(ata_dev_id_string);