f8ac3b7
Path: news.gmane.org!not-for-mail
f8ac3b7
From: Lin Ming <ming.m.lin@intel.com>
f8ac3b7
Newsgroups: gmane.linux.ide,gmane.linux.kernel
f8ac3b7
Subject: [PATCH v2] libata: disable runtime pm for hotpluggable port
f8ac3b7
Date: Tue, 13 Mar 2012 09:57:37 +0800
f8ac3b7
Lines: 131
f8ac3b7
Approved: news@gmane.org
f8ac3b7
Message-ID: <1331603857.3436.24.camel@minggr>
f8ac3b7
NNTP-Posting-Host: plane.gmane.org
f8ac3b7
Mime-Version: 1.0
f8ac3b7
Content-Type: text/plain; charset="UTF-8"
f8ac3b7
Content-Transfer-Encoding: 7bit
f8ac3b7
X-Trace: dough.gmane.org 1331603865 12388 80.91.229.3 (13 Mar 2012 01:57:45 GMT)
f8ac3b7
X-Complaints-To: usenet@dough.gmane.org
f8ac3b7
NNTP-Posting-Date: Tue, 13 Mar 2012 01:57:45 +0000 (UTC)
f8ac3b7
Cc: linux-ide@vger.kernel.org, lkml <linux-kernel@vger.kernel.org>,
f8ac3b7
	jslaby@suse.cz, cwillu@cwillu.com, jackdachef@gmail.com,
f8ac3b7
	Sergei Shtylyov <sshtylyov@mvista.com>
f8ac3b7
To: Jeff Garzik <jgarzik@pobox.com>
f8ac3b7
Original-X-From: linux-ide-owner@vger.kernel.org Tue Mar 13 02:57:43 2012
f8ac3b7
Return-path: <linux-ide-owner@vger.kernel.org>
f8ac3b7
Envelope-to: lnx-linux-ide@plane.gmane.org
f8ac3b7
Original-Received: from vger.kernel.org ([209.132.180.67])
f8ac3b7
	by plane.gmane.org with esmtp (Exim 4.69)
f8ac3b7
	(envelope-from <linux-ide-owner@vger.kernel.org>)
f8ac3b7
	id 1S7Gze-0005pE-Sg
f8ac3b7
	for lnx-linux-ide@plane.gmane.org; Tue, 13 Mar 2012 02:57:43 +0100
f8ac3b7
Original-Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
f8ac3b7
	id S1754650Ab2CMB5l (ORCPT <rfc822;lnx-linux-ide@m.gmane.org>);
f8ac3b7
	Mon, 12 Mar 2012 21:57:41 -0400
f8ac3b7
Original-Received: from mga14.intel.com ([143.182.124.37]:15186 "EHLO mga14.intel.com"
f8ac3b7
	rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
f8ac3b7
	id S1754582Ab2CMB5k (ORCPT <rfc822;linux-ide@vger.kernel.org>);
f8ac3b7
	Mon, 12 Mar 2012 21:57:40 -0400
f8ac3b7
Original-Received: from azsmga002.ch.intel.com ([10.2.17.35])
f8ac3b7
  by azsmga102.ch.intel.com with ESMTP; 12 Mar 2012 18:57:39 -0700
f8ac3b7
X-ExtLoop1: 1
f8ac3b7
X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; 
f8ac3b7
   d="scan'208";a="76719701"
f8ac3b7
Original-Received: from minggr.sh.intel.com (HELO [10.239.36.45]) ([10.239.36.45])
f8ac3b7
  by AZSMGA002.ch.intel.com with ESMTP; 12 Mar 2012 18:57:38 -0700
f8ac3b7
X-Mailer: Evolution 2.30.3 
f8ac3b7
Original-Sender: linux-ide-owner@vger.kernel.org
f8ac3b7
Precedence: bulk
f8ac3b7
List-ID: <linux-ide.vger.kernel.org>
f8ac3b7
X-Mailing-List: linux-ide@vger.kernel.org
f8ac3b7
Xref: news.gmane.org gmane.linux.ide:51560 gmane.linux.kernel:1266262
f8ac3b7
Archived-At: <http://permalink.gmane.org/gmane.linux.ide/51560>
f8ac3b7
f8ac3b7
Currently, hotplug doesn't work if port is already runtime suspended.
f8ac3b7
For now, we simply disable runtime pm for hotpluggable port.
f8ac3b7
Later, we should add runtime pm support for hotpluggable port too.
f8ac3b7
f8ac3b7
Bug report:
f8ac3b7
https://lkml.org/lkml/2012/2/19/70
f8ac3b7
f8ac3b7
v2:
f8ac3b7
- Use bit 2 and 3 for flags ATA_FLAG_EXTERNAL and ATA_FLAG_PLUGGABLE.
f8ac3b7
f8ac3b7
TODO: add similar hotpluggable port check for controllers other than
f8ac3b7
AHCI.
f8ac3b7
f8ac3b7
Reported-and-tested-by: Jiri Slaby <jslaby@suse.cz>
f8ac3b7
Reported-and-tested-by: cwillu@cwillu.com
f8ac3b7
Reported-and-tested-by: jackdachef@gmail.com
f8ac3b7
Signed-off-by: Lin Ming <ming.m.lin@intel.com>
f8ac3b7
---
f8ac3b7
 drivers/ata/ahci.c             |    3 +++
f8ac3b7
 drivers/ata/ahci.h             |    3 +++
f8ac3b7
 drivers/ata/libahci.c          |   20 ++++++++++++++++++++
f8ac3b7
 drivers/ata/libata-transport.c |    6 ++++--
f8ac3b7
 include/linux/libata.h         |    2 ++
f8ac3b7
 5 files changed, 32 insertions(+), 2 deletions(-)
f8ac3b7
f8ac3b7
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
f8ac3b7
index d07bf03..02e93ff 100644
f8ac3b7
--- a/drivers/ata/ahci.c
f8ac3b7
+++ b/drivers/ata/ahci.c
f8ac3b7
@@ -1145,6 +1145,9 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
f8ac3b7
 	if (hpriv->cap & HOST_CAP_PMP)
f8ac3b7
 		pi.flags |= ATA_FLAG_PMP;
f8ac3b7
 
f8ac3b7
+	if (hpriv->cap & HOST_CAP_SXS)
f8ac3b7
+		pi.flags |= ATA_FLAG_EXTERNAL;
f8ac3b7
+
f8ac3b7
 	ahci_set_em_messages(hpriv, &pi);
f8ac3b7
 
f8ac3b7
 	if (ahci_broken_system_poweroff(pdev)) {
f8ac3b7
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
f8ac3b7
index b175000..92f7172 100644
f8ac3b7
--- a/drivers/ata/ahci.h
f8ac3b7
+++ b/drivers/ata/ahci.h
f8ac3b7
@@ -172,6 +172,9 @@ enum {
f8ac3b7
 	PORT_CMD_ALPE		= (1 << 26), /* Aggressive Link PM enable */
f8ac3b7
 	PORT_CMD_ATAPI		= (1 << 24), /* Device is ATAPI */
f8ac3b7
 	PORT_CMD_FBSCP		= (1 << 22), /* FBS Capable Port */
f8ac3b7
+	PORT_CMD_ESP		= (1 << 21), /* External SATA Port */
f8ac3b7
+	PORT_CMD_MPSP		= (1 << 19), /* Mechanical Presence Switch Attached to Port */
f8ac3b7
+	PORT_CMD_HPCP		= (1 << 18), /* Hot Plug Capable Port */
f8ac3b7
 	PORT_CMD_PMP		= (1 << 17), /* PMP attached */
f8ac3b7
 	PORT_CMD_LIST_ON	= (1 << 15), /* cmd list DMA engine running */
f8ac3b7
 	PORT_CMD_FIS_ON		= (1 << 14), /* FIS DMA engine running */
f8ac3b7
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
f8ac3b7
index a72bfd0..7d72d3c 100644
f8ac3b7
--- a/drivers/ata/libahci.c
f8ac3b7
+++ b/drivers/ata/libahci.c
f8ac3b7
@@ -1097,6 +1097,23 @@ static void ahci_port_init(struct device *dev, struct ata_port *ap,
f8ac3b7
 	writel(1 << port_no, mmio + HOST_IRQ_STAT);
f8ac3b7
 }
f8ac3b7
 
f8ac3b7
+static bool ahci_port_pluggable(struct ata_port *ap)
f8ac3b7
+{
f8ac3b7
+	void __iomem *port_mmio = ahci_port_base(ap);
f8ac3b7
+	u32 cmd;
f8ac3b7
+
f8ac3b7
+	cmd = readl(port_mmio + PORT_CMD);
f8ac3b7
+
f8ac3b7
+	if ((ap->flags & ATA_FLAG_EXTERNAL) &&
f8ac3b7
+	    (cmd & PORT_CMD_ESP))
f8ac3b7
+		return true;
f8ac3b7
+
f8ac3b7
+	if (cmd & (PORT_CMD_MPSP | PORT_CMD_HPCP))
f8ac3b7
+		return true;
f8ac3b7
+
f8ac3b7
+	return false;
f8ac3b7
+}
f8ac3b7
+
f8ac3b7
 void ahci_init_controller(struct ata_host *host)
f8ac3b7
 {
f8ac3b7
 	struct ahci_host_priv *hpriv = host->private_data;
f8ac3b7
@@ -1112,6 +1129,9 @@ void ahci_init_controller(struct ata_host *host)
f8ac3b7
 		if (ata_port_is_dummy(ap))
f8ac3b7
 			continue;
f8ac3b7
 
f8ac3b7
+		if (ahci_port_pluggable(ap))
f8ac3b7
+			ap->flags |= ATA_FLAG_PLUGGABLE;
f8ac3b7
+
f8ac3b7
 		ahci_port_init(host->dev, ap, i, mmio, port_mmio);
f8ac3b7
 	}
f8ac3b7
 
f8ac3b7
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
f8ac3b7
index 74aaee3..a7166b9 100644
f8ac3b7
--- a/drivers/ata/libata-transport.c
f8ac3b7
+++ b/drivers/ata/libata-transport.c
f8ac3b7
@@ -292,8 +292,10 @@ int ata_tport_add(struct device *parent,
f8ac3b7
 	}
f8ac3b7
 
f8ac3b7
 	device_enable_async_suspend(dev);
f8ac3b7
-	pm_runtime_set_active(dev);
f8ac3b7
-	pm_runtime_enable(dev);
f8ac3b7
+	if (!(ap->flags & ATA_FLAG_PLUGGABLE)) {
f8ac3b7
+		pm_runtime_set_active(dev);
f8ac3b7
+		pm_runtime_enable(dev);
f8ac3b7
+	}
f8ac3b7
 
f8ac3b7
 	transport_add_device(dev);
f8ac3b7
 	transport_configure_device(dev);
f8ac3b7
diff --git a/include/linux/libata.h b/include/linux/libata.h
f8ac3b7
index cafc09a..f46961d 100644
f8ac3b7
--- a/include/linux/libata.h
f8ac3b7
+++ b/include/linux/libata.h
f8ac3b7
@@ -187,6 +187,8 @@ enum {
f8ac3b7
 	ATA_FLAG_SLAVE_POSS	= (1 << 0), /* host supports slave dev */
f8ac3b7
 					    /* (doesn't imply presence) */
f8ac3b7
 	ATA_FLAG_SATA		= (1 << 1),
f8ac3b7
+	ATA_FLAG_EXTERNAL	= (1 << 2), /* Controller supports external SATA */
f8ac3b7
+	ATA_FLAG_PLUGGABLE	= (1 << 3), /* Port is hotpluggable */
f8ac3b7
 	ATA_FLAG_NO_ATAPI	= (1 << 6), /* No ATAPI support */
f8ac3b7
 	ATA_FLAG_PIO_DMA	= (1 << 7), /* PIO cmds via DMA */
f8ac3b7
 	ATA_FLAG_PIO_LBA48	= (1 << 8), /* Host DMA engine is LBA28 only */
f8ac3b7
-- 
f8ac3b7
1.7.2.5
f8ac3b7
f8ac3b7
f8ac3b7
f8ac3b7
--
f8ac3b7
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
f8ac3b7
the body of a message to majordomo@vger.kernel.org
f8ac3b7
More majordomo info at  http://vger.kernel.org/majordomo-info.html
f8ac3b7