ata: ahci: find eSATA ports and flag them as removable
RFC PATCH 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.
--
This is a crude hack, but works fine on my laptop. If I plug something in on the eSATA port, KDE pops up a windows asking me what to do with the new drive(s), just like it does for any random usb stick.
I didn't know how else to communicate to userspace that the drive is removable other than adding it to the removable-bit-test of ATA IDENTIFY data.
drivers/ata/ahci.h | 2 ++ drivers/ata/libahci.c | 6 ++++++ drivers/ata/libata-scsi.c | 7 +++++-- include/linux/libata.h | 1 + 4 files changed, 14 insertions(+), 2 deletions(-)
drivers/ata/ahci.h +2 -0
@@ -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 +6 -0
@@ -1469,6 +1469,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,static void ahci_postreset (struct ata_link *link,unsigned int *class) {struct ata_port *ap = link->ap; +struct ahci_host_priv *hpriv = ap->host->private_data;void __iomem *port_mmio =ahci_port_base (ap);u32 new_tmp, tmp;
@@ -1484,6 +1485,11 @@ static void ahci_postreset(struct ata_link *link, unsigned int *class)writel (new_tmp, port_mmio +PORT_CMD );readl (port_mmio +PORT_CMD );/* flush */ } + +/* mark esata ports */ +if ((tmp &PORT_CMD_HPCP ) || + ((tmp &PORT_CMD_ESP ) && (hpriv->cap &HOST_CAP_SXS ))) + ap->pflags |=ATA_PFLAG_EXTERNAL ; }static unsigned int ahci_fill_sg (struct ata_queued_cmd *qc,void *cmd_tbl)
drivers/ata/libata-scsi.c +5 -2
@@ -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
@@ -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
Hello, Manuel.
Quoted 5 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.
Quoted 8 lines
Signed-off-by Manuel Lauss <[email protected]>--
This is a crude hack, but works fine on my laptop. If I plug something in on the eSATA port, KDE pops up a windows asking me what to do with the new drive(s), just like it does for any random usb stick.I didn't know how else to communicate to userspace that the drive is removable other than adding it to the removable-bit-test of ATA IDENTIFY data.
It'd probably be better if you include the above two paragraphs in the patch description proper.
Heh, does a port being marked external indicate that it should be treated as a removable device? Hmmm... maybe. I'm not sure either way. The other thing is that marking a device removeable cause internal behavior changes in the SCSI layer. It constantly checks to detect media change events which should be fine but noteworthy.
drivers/ata/libahci.c static void ahci_postreset(struct ata_link *link, unsigned int *class) · line 1492
Quoted 9 lines
drivers/ata/libahci.c +5
-0@@ -1484,6 +1485,11 @@ static void ahci_postreset(struct ata_link *link, unsigned int *class)writel (new_tmp, port_mmio +PORT_CMD );readl (port_mmio +PORT_CMD );/* flush */ } + +/* mark esata ports */ +if ((tmp &PORT_CMD_HPCP ) || + ((tmp &PORT_CMD_ESP ) && (hpriv->cap &HOST_CAP_SXS ))) + ap->pflags |=ATA_PFLAG_EXTERNAL ;
We probably should do this during port initialization rather than in the reset path.
Thanks.
Signature · 1 line
tejun
Hi Tejun,
Quoted 17 lines · Tejun Heo
Hello, Manuel.
Quoted 5 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.
Quoted 8 lines
Signed-off-by Manuel Lauss <[email protected]>--
This is a crude hack, but works fine on my laptop. If I plug something in on the eSATA port, KDE pops up a windows asking me what to do with the new drive(s), just like it does for any random usb stick.I didn't know how else to communicate to userspace that the drive is removable other than adding it to the removable-bit-test of ATA IDENTIFY data.
Quoted 8 lines
It'd probably be better if you include the above two paragraphs in the patch description proper.
Heh, does a port being marked external indicate that it should be treated as a removable device? Hmmm... maybe. I'm not sure either way. The other thing is that marking a device removeable cause internal behavior changes in the SCSI layer. It constantly checks to detect media change events which should be fine but noteworthy.
I'm not sure either, but this is also how windows decides whether a sata port should be treated as removable, i.e. add a "Safely remove device" Icon on the taskbar for devices attached to it. As I wrote, I haven't found another way to signal userspace (mainly udisks) that everything attached to this port should be treated like an USB stick.
Quoted 4 lines
Quoted 4 lines
drivers/ata/libahci.c +0
-0@@ -1484,6 +1485,11 @@ static void ahci_postreset(struct ata_link *link, unsigned int *class)writel (new_tmp, port_mmio +PORT_CMD );readl (port_mmio +PORT_CMD );/* flush */ }
Quoted 8 lines
drivers/ata/libahci.c static void ahci_postreset(struct ata_link *link, unsigned int *class) · line 1492
Quoted 5 lines
drivers/ata/libahci.c +5
-0+ +/* mark esata ports */ +if ((tmp &PORT_CMD_HPCP ) || + ((tmp &PORT_CMD_ESP ) && (hpriv->cap &HOST_CAP_SXS ))) + ap->pflags |=ATA_PFLAG_EXTERNAL ;We probably should do this during port initialization rather than in the reset path.
I'll update the patch.
Thank you!
Manuel