Linux PARISC architecture development
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: linux-ide <linux-ide@vger.kernel.org>
Cc: Parisc List <linux-parisc@vger.kernel.org>
Subject: [PATCH 2/2] pata_cmd64x: fix crash on boot with disabled secondary port
Date: Mon, 18 Apr 2011 13:45:23 -0500	[thread overview]
Message-ID: <1303152323.7167.16.camel@mulgrave.site> (raw)
In-Reply-To: <1303152147.7167.12.camel@mulgrave.site>

On non-x86 systems, probing a port which is listed as disabled can
cause an immediate crash.  Fix the driver not to do this by porting
the enablebits check from the IDE driver and setting the
ATA_HOST_SFF_SINGLE_PORT flag if only the primary is enabled.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 drivers/ata/pata_cmd64x.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 905ff76..aa71a13 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -41,6 +41,9 @@
 enum {
 	CFR 		= 0x50,
 		CFR_INTR_CH0  = 0x04,
+	ENPORT		= 0x51,
+		ENPORT_PRIMARY   = 0x04,
+		ENPORT_SECONDARY = 0x08,
 	CMDTIM 		= 0x52,
 	ARTTIM0 	= 0x53,
 	DRWTIM0 	= 0x54,
@@ -329,8 +332,8 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 		}
 	};
 	const struct ata_port_info *ppi[] = { &cmd_info[id->driver_data], NULL };
-	u8 mrdmode;
-	int rc;
+	u8 mrdmode, reg;
+	int rc, hflags = 0;
 
 	rc = pcim_enable_device(pdev);
 	if (rc)
@@ -354,6 +357,19 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	mrdmode |= 0x02;	/* Memory read line enable */
 	pci_write_config_byte(pdev, MRDMODE, mrdmode);
 
+	/* check for enabled ports */
+	pci_read_config_byte(pdev, ENPORT, &reg);
+	/* the cm643 primary port is always enabled */
+	if (id->driver_data != 0 && !(reg & ENPORT_PRIMARY)) {
+		dev_printk(KERN_ERR, &pdev->dev, "Primary port is disabled; detaching\n");
+		return -ENODEV;
+		
+	}
+	if (!(reg & ENPORT_SECONDARY)) {
+		dev_printk(KERN_NOTICE, &pdev->dev, "Secondary port is disabled\n");
+		hflags |= ATA_HOST_SFF_SINGLE_PORT;
+	}
+
 	/* Force PIO 0 here.. */
 
 	/* PPC specific fixup copied from old driver */
@@ -361,7 +377,7 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_write_config_byte(pdev, UDIDETCR0, 0xF0);
 #endif
 
-	return ata_pci_bmdma_init_one(pdev, ppi, &cmd64x_sht, NULL, 0);
+	return ata_pci_bmdma_init_one(pdev, ppi, &cmd64x_sht, NULL, hflags);
 }
 
 #ifdef CONFIG_PM
-- 
1.7.4.1




  parent reply	other threads:[~2011-04-18 18:45 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-18 18:42 [PATCH 0/2] fix libata-sff and pata_cmd64x to not crash on boot on parisc James Bottomley
2011-04-18 18:44 ` [PATCH 1/2] libata-sff: remove hardcoded requirement for two ports James Bottomley
2011-04-18 18:45 ` James Bottomley [this message]
2011-04-19 20:48   ` [PATCH 2/2] pata_cmd64x: fix crash on boot with disabled secondary port Sergei Shtylyov
2011-04-18 19:52 ` [PATCH 0/2] fix libata-sff and pata_cmd64x to not crash on boot on parisc Alan Cox
2011-04-18 20:08   ` James Bottomley
2011-04-18 20:14     ` David Miller
2011-04-18 21:09     ` Alan Cox
2011-04-18 20:50   ` James Bottomley
2011-04-18 21:20     ` Alan Cox
2011-04-19 13:54       ` James Bottomley
2011-04-19 14:36         ` Alan Cox
2011-04-19 15:02           ` James Bottomley
2011-04-19 15:58             ` Alan Cox
2011-04-19 20:59       ` Sergei Shtylyov
2011-04-19 21:19         ` Alan Cox
2011-04-19 21:22           ` Sergei Shtylyov
2011-04-19 21:28             ` Alan Cox
2011-04-19 23:11               ` James Bottomley
2011-04-20  9:35                 ` Alan Cox
2011-04-20 10:04                 ` Sergei Shtylyov
2011-04-20 14:28                   ` James Bottomley
2011-04-20 14:52                     ` James Bottomley
2011-04-20 14:54                     ` Sergei Shtylyov
2011-04-20 14:56                   ` Matthew Wilcox
2011-04-21 14:24                     ` Jeff Garzik
2011-04-19 20:53     ` Sergei Shtylyov

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=1303152323.7167.16.camel@mulgrave.site \
    --to=james.bottomley@hansenpartnership.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-parisc@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