[PATCH/RFC 4/5] libata-dev: Convert ata_pio_task() to use the new ata_hsm_move()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Convert ata_pio_task() to use the new ata_hsm_move().

Signed-off-by: Albert Lee <albertcc@xxxxxxxxxx>
---
Changes:
- initialize ap->pio_task_timeout() in ata_queue_pio_task()
- refactor ata_pio_task() to poll device status register and call the new ata_hsm_move()
  when device indicates it is not BSY.

--- 03_support_wq/drivers/scsi/libata-core.c	2006-03-09 15:14:00.000000000 +0800
+++ 04_pio_task/drivers/scsi/libata-core.c	2006-03-09 15:14:41.000000000 +0800
@@ -725,6 +725,8 @@ static unsigned int ata_pio_modes(const 
 static inline void
 ata_queue_pio_task(struct ata_port *ap)
 {
+	ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
+
 	if (!(ap->flags & ATA_FLAG_FLUSH_PIO_TASK))
 		queue_work(ata_wq, &ap->pio_task);
 }
@@ -3804,44 +3806,55 @@ fsm_start:
 static void ata_pio_task(void *_data)
 {
 	struct ata_port *ap = _data;
-	unsigned long timeout;
-	int has_next;
+	struct ata_queued_cmd *qc;
+	u8 status;
+	int poll_next;
 
 fsm_start:
-	timeout = 0;
-	has_next = 1;
+	WARN_ON(ap->hsm_task_state == HSM_ST_IDLE);
 
-	switch (ap->hsm_task_state) {
-	case HSM_ST_FIRST:
-		has_next = ata_pio_first_block(ap);
-		break;
+	qc = ata_qc_from_tag(ap, ap->active_tag);
+	WARN_ON(qc == NULL);
 
-	case HSM_ST:
-		ata_pio_block(ap);
-		break;
+	/*
+	 * This is purely heuristic.  This is a fast path.
+	 * Sometimes when we enter, BSY will be cleared in
+	 * 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, timeout or queue delayed work.
+	 */
+	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) {
+			if (time_before(jiffies, ap->pio_task_timeout)) {
+				ata_queue_delayed_pio_task(ap, ATA_SHORT_PAUSE);
+				return;
+			}
 
-	case HSM_ST_LAST:
-		has_next = ata_pio_complete(ap);
-		break;
+			/* timeout. Let EH handle it later. 
+			 * FIXME: should we remove ap->pio_task_timeout?
+			 */
+			printk(KERN_ERR "ata%u: polling time out\n", ap->id);
+			qc->err_mask |= AC_ERR_TIMEOUT;
+			ap->hsm_task_state = HSM_ST_TMOUT;
+			return; 
+		}
+	}
 
-	case HSM_ST_POLL:
-	case HSM_ST_LAST_POLL:
-		timeout = ata_pio_poll(ap);
-		break;
+	/* FIXME: check if EH is active */
 
-	case HSM_ST_TMOUT:
-	case HSM_ST_ERR:
-		ata_pio_error(ap);
-		return;
+	/* reset the pio task timeout */
+	ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
 
-	default:
-		BUG();
-		return;
-	}
+	/* move the HSM */
+	poll_next = ata_hsm_move(ap, qc, status, 1);
 
-	if (timeout)
-		ata_queue_delayed_pio_task(ap, timeout);
-	else if (has_next)
+	/* another command or interrupt handler
+	 * may be running at this point.
+	 */
+	if (poll_next)
 		goto fsm_start;
 }
 


-
: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystems]     [Linux SCSI]     [Linux RAID]     [Git]     [Kernel Newbies]     [Linux Newbie]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Samba]     [Device Mapper]

  Powered by Linux