linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: jgarzik@pobox.com, alan@lxorguk.ukuu.org.uk, albertcc@tw.ibm.com,
	linux-ide@vger.kernel.org
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 08/15] libata: don't disable devices from ata_set_mode()
Date: Sat, 1 Apr 2006 01:38:18 +0900	[thread overview]
Message-ID: <11438230982787-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <1143823097579-git-send-email-htejun@gmail.com>

When ata_set_mode() fails on a device, make ata_set_mode() return
error code and pointer to the device instead of disabling it directly.
This gives more control to higher level driving logic.

This patch does not change the end result (configured transfer mode)
although it may make libata repeat mode configuration to the peer of a
failing device.  Later ata_bus_probe() rewrite will make full use of
this change.

Signed-off-by: Tejun Heo <htejun@gmail.com>

---

 drivers/scsi/libata-core.c |   66 +++++++++++++++++++++++++++-----------------
 1 files changed, 40 insertions(+), 26 deletions(-)

0a8249272a7bb4114c8c535ad9c09f6c98fbccf2
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index f04561a..061b0b6 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -65,7 +65,7 @@ static unsigned int ata_dev_init_params(
 					struct ata_device *dev,
 					u16 heads,
 					u16 sectors);
-static void ata_set_mode(struct ata_port *ap);
+static int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev);
 static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
 					 struct ata_device *dev);
 static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev);
@@ -1368,6 +1368,7 @@ static int ata_bus_probe(struct ata_port
 {
 	unsigned int classes[ATA_MAX_DEVICES];
 	int i, rc, found = 0;
+	struct ata_device *dev;
 
 	ata_port_probe(ap);
 
@@ -1397,8 +1398,7 @@ static int ata_bus_probe(struct ata_port
 
 	/* read IDENTIFY page and configure devices */
 	for (i = 0; i < ATA_MAX_DEVICES; i++) {
-		struct ata_device *dev = &ap->device[i];
-
+		dev = &ap->device[i];
 		dev->class = classes[i];
 
 		if (!ata_dev_enabled(dev))
@@ -1418,20 +1418,26 @@ static int ata_bus_probe(struct ata_port
 		found = 1;
 	}
 
-	if (!found)
-		goto err_out_disable;
-
-	if (ap->ops->set_mode)
-		ap->ops->set_mode(ap);
-	else
-		ata_set_mode(ap);
-
-	if (ap->flags & ATA_FLAG_PORT_DISABLED)
-		goto err_out_disable;
+	/* configure transfer mode */
+	if (ap->ops->set_mode) {
+		/* FIXME: make ->set_mode handle no device case and
+		 * return error code and failing device on failure as
+		 * ata_set_mode() does.
+		 */
+		if (found)
+			ap->ops->set_mode(ap);
+		rc = 0;
+	} else {
+		while (ata_set_mode(ap, &dev))
+			ata_dev_disable(ap, dev);
+	}
 
-	return 0;
+	for (i = 0; i < ATA_MAX_DEVICES; i++)
+		if (ata_dev_enabled(&ap->device[i]))
+			return 0;
 
-err_out_disable:
+	/* no device present, disable port */
+	ata_port_disable(ap);
 	ap->ops->port_disable(ap);
 	return -ENODEV;
 }
@@ -1774,16 +1780,22 @@ static int ata_dev_set_mode(struct ata_p
 /**
  *	ata_set_mode - Program timings and issue SET FEATURES - XFER
  *	@ap: port on which timings will be programmed
+ *	@r_failed_dev: out paramter for failed device
  *
- *	Set ATA device disk transfer mode (PIO3, UDMA6, etc.).
+ *	Set ATA device disk transfer mode (PIO3, UDMA6, etc.).  If
+ *	ata_set_mode() fails, pointer to the failing device is
+ *	returned in @r_failed_dev.
  *
  *	LOCKING:
  *	PCI/etc. bus probe sem.
+ *
+ *	RETURNS:
+ *	0 on success, negative errno otherwise
  */
-static void ata_set_mode(struct ata_port *ap)
+static int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
 {
 	struct ata_device *dev;
-	int i, rc, used_dma = 0, found = 0;
+	int i, rc = 0, used_dma = 0, found = 0;
 
 	/* step 1: calculate xfer_mask */
 	for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -1806,7 +1818,7 @@ static void ata_set_mode(struct ata_port
 			used_dma = 1;
 	}
 	if (!found)
-		return;
+		goto out;
 
 	/* step 2: always set host PIO timings */
 	for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -1818,7 +1830,7 @@ static void ata_set_mode(struct ata_port
 			printk(KERN_WARNING "ata%u: dev %u no PIO support\n",
 			       ap->id, dev->devno);
 			rc = -EINVAL;
-			goto err_out;
+			goto out;
 		}
 
 		dev->xfer_mode = dev->pio_mode;
@@ -1849,7 +1861,7 @@ static void ata_set_mode(struct ata_port
 
 		rc = ata_dev_set_mode(ap, dev);
 		if (rc)
-			goto err_out;
+			goto out;
 	}
 
 	/* Record simplex status. If we selected DMA then the other
@@ -1862,10 +1874,10 @@ static void ata_set_mode(struct ata_port
 	if (ap->ops->post_set_mode)
 		ap->ops->post_set_mode(ap);
 
-	return;
-
-err_out:
-	ata_port_disable(ap);
+ out:
+	if (rc)
+		*r_failed_dev = dev;
+	return rc;
 }
 
 /**
@@ -4278,8 +4290,10 @@ static int ata_start_drive(struct ata_po
 int ata_device_resume(struct ata_port *ap, struct ata_device *dev)
 {
 	if (ap->flags & ATA_FLAG_SUSPENDED) {
+		struct ata_device *failed_dev;
 		ap->flags &= ~ATA_FLAG_SUSPENDED;
-		ata_set_mode(ap);
+		while (ata_set_mode(ap, &failed_dev))
+			ata_dev_disable(ap, failed_dev);
 	}
 	if (!ata_dev_enabled(dev))
 		return 0;
-- 
1.2.4



  parent reply	other threads:[~2006-03-31 16:38 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-31 16:38 [PATCHSET] libata: improve ata_bus_probe failure handling Tejun Heo
2006-03-31 16:38 ` [PATCH 04/15] libata: convert do_probe_reset() to ata_do_reset() Tejun Heo
2006-03-31 16:38 ` [PATCH 01/15] libata: fix ata_set_mode() return value Tejun Heo
2006-04-01 17:34   ` Jeff Garzik
2006-03-31 16:38 ` [PATCH 03/15] libata: separate out ata_spd_string() Tejun Heo
2006-03-31 16:38 ` [PATCH 02/15] libata: make ata_bus_probe() return negative errno on failure Tejun Heo
2006-03-31 16:38 ` [PATCH 09/15] libata: implement ata_down_xfermask_limit() Tejun Heo
2006-03-31 22:31   ` Alan Cox
2006-04-01  0:11     ` Tejun Heo
2006-04-01 19:47   ` Jeff Garzik
2006-04-02  0:55     ` Tejun Heo
2006-04-02  6:58       ` Tejun Heo
2006-04-02  8:07         ` Jeff Garzik
2006-03-31 16:38 ` [PATCH 07/15] libata: reorganize ata_set_mode() Tejun Heo
2006-03-31 16:38 ` [PATCH 11/15] libata: preserve SATA SPD setting over hard resets Tejun Heo
2006-04-01 19:52   ` Jeff Garzik
2006-03-31 16:38 ` [PATCH 10/15] libata: add dev->sata_spd_limit and helpers Tejun Heo
2006-04-01 19:51   ` Jeff Garzik
2006-04-02  1:00     ` Tejun Heo
2006-04-02  8:12       ` Jeff Garzik
2006-03-31 16:38 ` Tejun Heo [this message]
2006-04-01 19:46   ` [PATCH 08/15] libata: don't disable devices from ata_set_mode() Jeff Garzik
2006-03-31 16:38 ` [PATCH 06/15] libata: make ata_set_mode() handle no-device case properly Tejun Heo
2006-03-31 16:38 ` [PATCH 05/15] libata: implement ata_dev_enabled and disabled() Tejun Heo
2006-04-01 17:29   ` Jeff Garzik
2006-04-02  0:54     ` Tejun Heo
2006-03-31 16:38 ` [PATCH 12/15] libata: use SATA speeding down in ata_drive_probe_reset() Tejun Heo
2006-04-01 19:56   ` Jeff Garzik
2006-04-02  1:05     ` Tejun Heo
2006-03-31 16:38 ` [PATCH 14/15] libata: improve ata_bus_probe() Tejun Heo
2006-04-01 19:58   ` Jeff Garzik
2006-03-31 16:38 ` [PATCH 15/15] libata: consider disabled devices in ata_dev_xfermask() Tejun Heo
2006-04-01 20:00   ` Jeff Garzik
2006-04-02  1:09     ` Tejun Heo
2006-03-31 16:38 ` [PATCH 13/15] libata: add 1s sleep between resets Tejun Heo
2006-04-01 19:57   ` Jeff Garzik
2006-04-02  1:07     ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11438230982787-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=albertcc@tw.ibm.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).