Skip to contentSkip to conversation

ata: ahci: find eSATA ports and flag them as removable

PATCH Applied Manuel Lauss 3 participants 5 messages Sep 30, 2015 – Oct 19, 2015 libata

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ata: ahci: find eSATA ports and flag them as removable

If the AHCI ports' HPCP or ESP bits are set, the port should be considered external (e.g. eSATA) and is marked as removable. Userspace tools like udisks then treat it like an usb drive.

With this patch applied, when I plug a drive into the esata port, KDE pops up a window asking what to do with the drives(s), just like it does for any random USB stick.

Removability is indicated to the upper layers by way of the SCSI RMB bit, as I haven't found another way to signal userspace to treat a sata disk like any usb stick.

---
 drivers/ata/ahci.h        | 2 ++
 drivers/ata/libahci.c     | 7 +++++++
 drivers/ata/libata-scsi.c | 7 +++++--
 include/linux/libata.h    | 1 +
 4 files changed, 15 insertions(+), 2 deletions(-)
drivers/ata/ahci.h +2 -0
index 5b8e8a0..45586c1 100644
@@ -181,6 +181,8 @@ enum {
 	PORT_CMD_ALPE		= (1 << 26), /* Aggressive Link PM enable */
 	PORT_CMD_ATAPI		= (1 << 24), /* Device is ATAPI */
 	PORT_CMD_FBSCP		= (1 << 22), /* FBS Capable Port */
+	PORT_CMD_ESP		= (1 << 21), /* External Sata Port */
+	PORT_CMD_HPCP		= (1 << 18), /* HotPlug Capable Port */
 	PORT_CMD_PMP		= (1 << 17), /* PMP attached */
 	PORT_CMD_LIST_ON	= (1 << 15), /* cmd list DMA engine running */
 	PORT_CMD_FIS_ON		= (1 << 14), /* FIS DMA engine running */
drivers/ata/libahci.c +7 -0
index d256a66..2fa551a 100644
@@ -1117,6 +1117,7 @@ static void ahci_port_init(struct device *dev, struct ata_port *ap,
 			   int port_no, void __iomem *mmio,
 			   void __iomem *port_mmio)
 {
+	struct ahci_host_priv *hpriv = ap->host->private_data;
 	const char *emsg = NULL;
 	int rc;
 	u32 tmp;
@@ -1138,6 +1139,12 @@ static void ahci_port_init(struct device *dev, struct ata_port *ap,
 		writel(tmp, port_mmio + PORT_IRQ_STAT);
 
 	writel(1 << port_no, mmio + HOST_IRQ_STAT);
+
+	/* mark esata ports */
+	tmp = readl(port_mmio + PORT_CMD);
+	if ((tmp & PORT_CMD_HPCP) ||
+	    ((tmp & PORT_CMD_ESP) && (hpriv->cap & HOST_CAP_SXS)))
+		ap->pflags |= ATA_PFLAG_EXTERNAL;
 }
 
 void ahci_init_controller(struct ata_host *host)
drivers/ata/libata-scsi.c +5 -2
index 0d7f0da..183a57b 100644
@@ -2015,8 +2015,11 @@ static unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf)
 
 	VPRINTK("ENTER\n");
 
-	/* set scsi removable (RMB) bit per ata bit */
-	if (ata_id_removable(args->id))
+	/* set scsi removable (RMB) bit per ata bit, or if the
+	 * AHCI port says it's external (Hotplug-capable, eSATA).
+	 */
+	if (ata_id_removable(args->id) ||
+	    (args->dev->link->ap->pflags & ATA_PFLAG_EXTERNAL))
 		hdr[1] |= (1 << 7);
 
 	if (args->dev->class == ATA_DEV_ZAC) {
include/linux/libata.h +1 -0
index c9cfbcd..83577f8 100644
@@ -254,6 +254,7 @@ enum {
 
 	ATA_PFLAG_PIO32		= (1 << 20),  /* 32bit PIO */
 	ATA_PFLAG_PIO32CHANGE	= (1 << 21),  /* 32bit PIO can be turned on/off */
+	ATA_PFLAG_EXTERNAL	= (1 << 22),  /* eSATA/external port */
 
 	/* struct ata_queued_cmd flags */
 	ATA_QCFLAG_ACTIVE	= (1 << 0), /* cmd not yet ack'd to scsi lyer */
Signature · 1 line
2.5.3
Applied
#1 lore raw
Quoted 9 lines · Manuel Lauss

If the AHCI ports' HPCP or ESP bits are set, the port should be considered external (e.g. eSATA) and is marked as removable. Userspace tools like udisks then treat it like an usb drive.

With this patch applied, when I plug a drive into the esata port, KDE pops up a window asking what to do with the drives(s), just like it does for any random USB stick.

Quoted 5 lines

Removability is indicated to the upper layers by way of the SCSI RMB bit, as I haven't found another way to signal userspace to treat a sata disk like any usb stick.

Applied to libata/for-4.4. Let's see what happens.

Thanks.

Signature · 1 line
tejun
#2 lore raw
Quoted 10 lines · Tejun Heo
Quoted 9 lines · Manuel Lauss

If the AHCI ports' HPCP or ESP bits are set, the port should be considered external (e.g. eSATA) and is marked as removable. Userspace tools like udisks then treat it like an usb drive.

With this patch applied, when I plug a drive into the esata port, KDE pops up a window asking what to do with the drives(s), just like it does for any random USB stick.

Quoted 7 lines
Quoted 5 lines

Removability is indicated to the upper layers by way of the SCSI RMB bit, as I haven't found another way to signal userspace to treat a sata disk like any usb stick.

Applied to libata/for-4.4. Let's see what happens.

Ugh. Yet another revert to include in my own builds, I guess.

eSATA is used for permanent storage expansion with port-multipliers, and having to stop command queuing frequently for useless polling is gonna be a performance drain.

-ml

#3 lore raw

Hello, Mark.

Quoted 3 lines · Mark Lord
Quoted 1 line

Applied to libata/for-4.4. Let's see what happens.

Ugh. Yet another revert to include in my own builds, I guess.

Hmmm... what other patches are you reverting?

Quoted 3 lines

eSATA is used for permanent storage expansion with port-multipliers, and having to stop command queuing frequently for useless polling is gonna be a performance drain.

What would poll it regularly?

Thanks.

Signature · 1 line
tejun
#4 lore raw
Quoted 8 lines · Tejun Heo

Hello, Mark.

Quoted 3 lines · Mark Lord
Quoted 1 line

Applied to libata/for-4.4. Let's see what happens.

Ugh. Yet another revert to include in my own builds, I guess.

Hmmm... what other patches are you reverting?

For libata, other than this one, I only disable SATA LPM. But something is wrong with the Seagate 8TB drives in
the latest kernels, so I'll have to figure that one out too at some point. The drives keep dropping offline, requiring a system power cycle to recover. Cause unknown. Nothing in S.M.A.R.T.

Quoted 5 lines
Quoted 3 lines

eSATA is used for permanent storage expansion with port-multipliers, and having to stop command queuing frequently for useless polling is gonna be a performance drain.

What would poll it regularly?

I though your own earlier post suggested something there, but I no longer have it to re-read.

I'm expecting that "removable" will imply different elevator scheduling and more frequent journal flushing etc.

But perhaps it's a bit unfair to just presume that just yet, so you have my apologies!

But I'm still reverting/disabling this one locally.

Cheers
Mark