SATA Hotplug not working? [AMD R9 5950x + ASUS PRIME X570-P]

Hi all,

Is it expected behaviour that when you plug/unplug a SATA drive, you then have to manually explain to Linux that “hey, I just unplugged/plugged in a drive, please rescan the SCSI bus”? Is it possible to have Linux auto-enumerate (and possibly even auto-mount) a SATA drive when I plug it into a SATA port?

I’ve got Ubuntu 22.04 Desktop installed on a PRIME X570-P based system. I’ve been wanting to play with SATA hotplug, but when I try to plug in a SATA drive while the system is running, nothing seems to happen (not even in dmesg.)

I’ve updated my mobo to the latest BIOS version (“Revision 4403”).

If I boot the system with my drive plugged in to one of the SATA ports, then the system can see it. If I then un-plug it, I see no changes (the system still insists the drive is there) until someone or something tries to access it (e.g. I try to mount one of the partitions), at which point Linux ‘wakes up’ to the fact that there’s nothing on the end of the SATA cable and spits out the following into dmesg:

[  280.531703] ata6: SATA link down (SStatus 0 SControl 300)
[  285.905936] ata6.00: disabled
[  285.905974] ata6.00: detaching (SCSI 5:0:0:0)
[  285.937622] sd 5:0:0:0: [sda] Stopping disk
[  285.937636] sd 5:0:0:0: [sda] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK

I can also manually invoke Linux to rescan the scsi bus with

$ echo "- - -" > /sys/class/scsi_host/host9/scan

Then the result is more “graceful”, and I only see the following in dmesg:

[   69.651916] ata10: SATA link down (SStatus 0 SControl 300)

If I then plug my drive back in, again nothing happens until I tell Linux to re-scan the right bus with the same command:

$ echo "- - -" > /sys/class/scsi_host/host9/scan

P.S. I did enable “Hot Plug” on all the SATA ports in the BIOS.

Did you enable SATA hotplug in the BIOS? Linux automagically recognises a hotplug event, at least on my B550-based system, once hotplugging SATA ports is enabled.

HTH!

Yep, triple and quadruple checked

Here’s what I’m staring at in the BIOS screen:

That’s strange. Both my X370 and B550 (both Gigabyte) don’t even have an explicit SATA hotplug option in their BIOS, but as long as the SATA ports are set to AHCI my Linux desktop (plasma) has no problem recognizing the drive when plugged in or safely unmounting it.

I haven’t used gnome in years, but it should have options to set device mounting behavior.

Anecdotally I ran into a very subtle bug/issue on my B450 chipset’s SATA controllers recently. It’s so subtle that I haven’t realized it for years until very recently.

B450 chipset was by ASMedia. X570 chipset was actually reuse of the client I/O die by AMD. So less likely the same SATA controller. Though I won’t rule out both source from the same IP block and share similar quirks during integration.

Its not that my desktop doesn’t automount it, but rather that the Linux kernel itself doesn’t detect that a SATA drive has been plugged in. So the problem seems to be beyond the desktop.

In the meantime I’ve opened a support case on ASUS’s website (first time I’ve ever opened a support case!) so it should be interesting to see what they say (if anything.)

The problem is the SATA power management! This Gentoo forum post of someone having very similar issues tipped me off.

This google groups post enumerates the possible states that a given SATA host controller can be in (Copied below for posterity):

On Fri, Apr 06, 2018 at 07:05:00PM +0200, basti wrote:

Hello,
is there a way to disable LPM for mv_sata driver by commandline?

per-disk, not per-driver:

echo STATE > /sys/class/scsi_host/host0/link_power_management_policy

where STATE can be:

max_performance
medium_power
med_power_with_dipm
min_power WARNING: possible data loss

med_power_with_dipm appears in kernel 4.15.

When I inquired what powermanagement mode my particular SATA host is at, I discovered the following:

$ cat /sys/class/scsi_host/host5/link_power_management_policy
med_power_with_dipm

Ok, fine. So I then try to set it to max_performance:

# echo 'max_performance' | tee /sys/class/scsi_host/host5/link_power_management_policy
max_performance

Ok, great - Now I unplug my drive, and sure enough, Linux immediately responds in dmesg:

[ 7259.981207] ata6: SATA link down (SStatus 0 SControl 300)
[ 7265.340535] ata6: SATA link down (SStatus 0 SControl 300)
[ 7270.715522] ata6: SATA link down (SStatus 0 SControl 300)
[ 7270.715533] ata6.00: disabled
[ 7270.725619] ata6.00: detaching (SCSI 5:0:0:0)
[ 7270.761356] sd 5:0:0:0: [sdc] Synchronizing SCSI cache
[ 7270.761374] sd 5:0:0:0: [sdc] Synchronize Cache(10) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 7270.761375] sd 5:0:0:0: [sdc] Stopping disk
[ 7270.761378] sd 5:0:0:0: [sdc] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK

(p.s. I am curious why the SATA link down line gets repeated more than once - physical contact bounce on the SATA cable?)

If I plug it back in, Linux also immediately responds:

[ 7282.696978] ata6: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
[ 7282.885970] ata6.00: ATA-9: WDC WD20EZRZ-22Z5HB0, 80.00A80, max UDMA/133
[ 7282.886222] ata6.00: ATA Identify Device Log not supported
[ 7282.886224] ata6.00: 3907029168 sectors, multi 0: LBA48 NCQ (depth 32), AA
[ 7282.886937] ata6.00: ATA Identify Device Log not supported
[ 7282.886939] ata6.00: configured for UDMA/133
[ 7282.897107] scsi 5:0:0:0: Direct-Access     ATA      WDC WD20EZRZ-22Z 0A80 PQ: 0 ANSI: 5
[ 7282.897230] sd 5:0:0:0: Attached scsi generic sg2 type 0
[ 7282.897296] sd 5:0:0:0: [sdc] 3907029168 512-byte logical blocks: (2.00 TB/1.82 TiB)
[ 7282.897299] sd 5:0:0:0: [sdc] 4096-byte physical blocks
[ 7282.897307] sd 5:0:0:0: [sdc] Write Protect is off
[ 7282.897309] sd 5:0:0:0: [sdc] Mode Sense: 00 3a 00 00
[ 7282.897321] sd 5:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 7283.013040]  sdc: sdc1
[ 7283.037034] sd 5:0:0:0: [sdc] Attached SCSI removable disk
[ 7283.532048] ntfs3: Unknown parameter 'windows_names'

Now, I suppose I just need to figure out how to tell Ubuntu in a “nice way” to not try to be clever with the SATA link power management…

To add to my previous post, others who have also encountered this issue solved it for their distributions by editing a file called /etc/tlp.conf, and adding a line like

SATA_LINKPWR_ON_AC="max_performance"

However on Ubuntu this file doesn’t seem to exist, and I don’t think that Ubuntu uses the tlp package for power management.

Look for a BIOS option like Aggressive Link Power Management and try disabling it.

You can add a new rule file to ‘/etc/udev/rules.d’ with content:

ACTION=="add", SUBSYSTEM=="scsi_host", TEST=="link_power_management_policy", KERNEL=="host*", ATTR{link_power_management_policy}="max_performance"

This will set all your SATA ports to “max_performance” when the kernel boots.

As an aside, worth checking if “medium_power” solves your problem. That’ll save you ~1W to 1.5W per SATA port. Real profit if it also works for your hot plugs.

1 Like

This topic was automatically closed 273 days after the last reply. New replies are no longer allowed.