SATA hotplug on TX2

I am trying to get at least a manually assisted hotplug with use of rmmod/modprobe as the platform does not seem to recognize a hotplugged SATA drive. We compiled the TEGRA AHCI as module and it uses these modules:

ahci_tegra             23015  0
libahci_platform       11118  1 ahci_tegra
libahci                37180  2 libahci_platform,ahci_tegra

After doing rmmod, the /dev/sda node disappears - correctly and dmesg contains:

[  910.445930] ata1.00: disabled
[  910.449287] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[  910.454490] sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x04 driverbyte=0x00
[  910.463421] sd 0:0:0:0: [sda] Stopping disk
[  910.467792] sd 0:0:0:0: [sda] Start/Stop Unit failed: Result: hostbyte=0x04 driverbyte=0x00

When doing a modprobe ahci_tegra it crashes:

[  958.328408] ------------[ cut here ]------------
[  958.333023] WARNING: at ffffffbffc02ceb0 [verbose debug info unavailable]
[  958.339795] Modules linked in: ahci_tegra(+) libahci_platform libahci snd_soc_spdif_tx snd_soc_core snd_compress snd_pcm snd_timer snd bcmdhd mttcan soundcore can_dev [last unloaded: libahci]

[  958.339821] CPU: 3 PID: 2211 Comm: modprobe Not tainted 4.4.15+ #19
[  958.339824] Hardware name: quill (DT)
[  958.339828] task: ffffffc1c60ebe80 ti: ffffffc1e8228000 task.ti: ffffffc1e8228000
[  958.339842] PC is at ahci_enable_ahci+0x70/0x88 [libahci]
[  958.339851] LR is at ahci_enable_ahci+0x68/0x88 [libahci]
[  958.339854] pc : [<ffffffbffc02ceb0>] lr : [<ffffffbffc02cea8>] pstate: 60000045
[  958.339856] sp : ffffffc1e822b950
[  958.339858] x29: ffffffc1e822b950 x28: ffffffc1cba46c18
[  958.339863] x27: ffffffc1cba46d18 x26: ffffffc00136c4a0
[  958.339867] x25: ffffffc1f5c7fc10 x24: ffffffbffc00c158
[  958.339870] x23: 0000000080000001 x22: ffffff8000d3c004
[  958.339874] x21: 0000000000000000 x20: ffffff8000d3c004
[  958.339877] x19: 0000000000000000 x18: 0000000000000000
[  958.339881] x17: 0000007f95799f18 x16: ffffffc0001e9028
[  958.339884] x15: 001dcd6500000000 x14: 001cfa426c000000
[  958.339887] x13: ffffffffa64f7e33 x12: ffffffc000c25b50
[  958.339890] x11: 0000000000000070 x10: 0000000000000880
[  958.339894] x9 : ffffffc1e822b7f0 x8 : ffffffc1c60ec760
[  958.339897] x7 : 0000000000000400 x6 : 0000000000000000
[  958.339900] x5 : 00000000005d0a9a x4 : 0000000000000000
[  958.339903] x3 : 0000000000000040 x2 : 0000000000005027
[  958.339907] x1 : ffffffc1e8228000 x0 : 0000000000000000
[  958.339912] ---[ end trace 764187ed4e724b98 ]---
[  958.344516] Call trace:
[  958.346962] [<ffffffbffc02ceb0>] ahci_enable_ahci+0x70/0x88 [libahci]
[  958.346971] [<ffffffbffc02dfc4>] ahci_reset_controller+0x7c/0x190 [libahci]
[  958.346977] [<ffffffbffc00b47c>] ahci_platform_init_host+0x1ac/0x480 [libahci_platform]
[  958.346987] [<ffffffbffc0438f0>] tegra_ahci_probe+0x3a8/0x818 [ahci_tegra]
[  958.346994] [<ffffffc00060ce60>] platform_drv_probe+0x50/0xb8
[  958.346998] [<ffffffc00060a9dc>] driver_probe_device+0xcc/0x428
[  958.347001] [<ffffffc00060add4>] __driver_attach+0x9c/0xa0
[  958.347005] [<ffffffc0006088f8>] bus_for_each_dev+0x60/0xa0
[  958.347009] [<ffffffc00060a2f8>] driver_attach+0x20/0x28
[  958.347012] [<ffffffc000609e68>] bus_add_driver+0x210/0x298
[  958.347015] [<ffffffc00060bb18>] driver_register+0x60/0xf8
[  958.347019] [<ffffffc00060cd5c>] __platform_driver_register+0x4c/0x58
[  958.347026] [<ffffffbffc048018>] tegra_ahci_driver_init+0x18/0x30 [ahci_tegra]
[  958.347031] [<ffffffc000081ad8>] do_one_initcall+0xd0/0x1d8
[  958.347037] [<ffffffc000171070>] do_init_module+0x64/0x1c4
[  958.347041] [<ffffffc000121234>] load_module+0xf44/0x1220
[  958.347044] [<ffffffc0001217d8>] SyS_finit_module+0xe0/0x110
[  958.347047] [<ffffffc000084e70>] el0_svc_naked+0x24/0x28
[  958.347106] tegra-ahci 3507000.ahci-sata: AHCI 0001.0301 32 slots 2 ports 3 Gbps 0x1 impl platform mode
[  958.356506] tegra-ahci 3507000.ahci-sata: flags: 64bit ncq sntf pm led pmp pio slum part deso sadm apst
[  958.366640] scsi host2: tegra_ahci
[  958.374688] scsi host3: tegra_ahci
[  958.378268] ata3: SATA max UDMA/133 mmio [mem 0x03507000-0x03508fff] port 0x100 irq 24
[  958.386676] ata4: DUMMY
[  959.416379] ata3: failed to resume link (SControl 0)
[  959.421370] ata3: SATA link down (SStatus 0 SControl 0)

I can’t answer, but I would assume this is using a hotplug carrier and not directly plugging into and unplugging from the SATA connector of the Jetson dev carrier. Is this correct? If not, then you probably can’t succeed since the hardware on that connector is itself not capable of hotplug (you’d have to add a carrier with that capability). If you are using a hotplug carrier, then it is still possible software is not set up for hotplug.

Another bug: when there is no drive attached from the start, one can not do rmmod ahci_tegra, as the rmmod will stay forever in uninterruptible call.

A hotplug carier does not feature any electronics so that is not the case. We are hotplugging the drive with a cable on an ASMedia PCIe controller fine (on the same TX2), the process involves an automatic SATA link reset, see this dmesg:

Unplug:

[  478.607918] ata4: exception Emask 0x10 SAct 0x0 SErr 0x90002 action 0xe frozen
[  478.615154] ata4: irq_stat 0x00400000, PHY RDY changed
[  478.620314] ata4: SError: { RecovComm PHYRdyChg 10B8B }
[  478.625653] ata4: hard resetting link
[  479.352277] ata4: SATA link down (SStatus 0 SControl 300)
[  484.356255] ata4: hard resetting link
[  484.676276] ata4: SATA link down (SStatus 0 SControl 300)
[  484.681680] ata4: limiting SATA link speed to 1.5 Gbps
[  489.680260] ata4: hard resetting link
[  490.000280] ata4: SATA link down (SStatus 0 SControl 310)
[  490.005689] ata4.00: disabled
[  490.008679] ata4: EH complete
[  490.011698] ata4.00: detaching (SCSI 3:0:0:0)
[  490.016692] sd 3:0:0:0: [sda] Synchronizing SCSI cache
[  490.021897] sd 3:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x04 driverbyte=0x00
[  490.030838] sd 3:0:0:0: [sda] Stopping disk
[  490.035149] sd 3:0:0:0: [sda] Start/Stop Unit failed: Result: hostbyte=0x04 driverbyte=0x00

Plug:

[  491.322464] ata4: exception Emask 0x10 SAct 0x0 SErr 0x4040000 action 0xe frozen
[  491.329857] ata4: irq_stat 0x00000040, connection status changed
[  491.335869] ata4: SError: { CommWake DevExch }
[  491.340323] ata4: hard resetting link
[  494.644271] ata4: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
[  494.650668] ata4.00: supports DRM functions and may not be fully accessible
[  494.658051] ata4.00: disabling queued TRIM support
[  494.658056] ata4.00: ATA-9: Samsung SSD 850 EVO 500GB, EMT02B6Q, max UDMA/133
[  494.665238] ata4.00: 976773168 sectors, multi 1: LBA48 NCQ (depth 31/32), AA
[  494.672902] ata4.00: supports DRM functions and may not be fully accessible
[  494.680072] ata4.00: disabling queued TRIM support
[  494.680417] ata4.00: configured for UDMA/133
[  494.684689] ata4: EH complete
[  494.691851] scsi 3:0:0:0: Direct-Access     ATA      Samsung SSD 850  2B6Q PQ: 0 ANSI: 5
[  494.700263] sd 3:0:0:0: [sda] 976773168 512-byte logical blocks: (500 GB/466 GiB)
[  494.707883] sd 3:0:0:0: [sda] Write Protect is off
[  494.712687] sd 3:0:0:0: [sda] Mode Sense: 00 3a 00 00
[  494.712732] sd 3:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[  494.722612]  sda: sda1 sda2 < sda5 >
[  494.726750] sd 3:0:0:0: [sda] Attached SCSI disk

So far as I know a hot-plug carrier provides the equivalent of a power switch which cuts power without surge prior to actually pulling the data cable (electronics modifying the connect/disconnect sequence). Unlocking the drive for removal provides a surge-free unpower prior to pulling the drive/data cable out. Possibly something in the host system can detect power connect/disconnect as well. I believe the connector on the dev board does not directly support connecting/disconnecting on a powered live system.

It does seem you should be able to rmmod ahci_tegra if nothing depends on it, but I’m wondering (just speculating) if module format is fully supported (it could be that you are able to select this in module format, but if there is a bug in this then it might work only when integrated into the kernel). By default this is integrated, not a module. Someone at NVIDIA may be able to verify if CONFIG_SATA_AHCI_TEGRA fully supports kernel module format before trying to debug further.

Please stop dealing with hardware issues we could have. This is not the case - the tests with ASMedia controller are done with the drive powered from the Jetson SATA power port. Yes - the Jetson baseboard lacks two 10-20 ohm pre-charge resistors which would be needed for proper hot plug support, but there are obviously no spikes as the ASMedia controller works. The system does not recognize that the drive is disconnected and lost as it happens with the ASmedia PCIe controller (logs above) - there are absolutely no messages, until the drive is connected back again:

Unplug:

-nothing-

Replug:

[  153.346506] ata1: exception Emask 0x10 SAct 0x0 SErr 0x59c0000 action 0xe frozen
[  153.353904] ata1: irq_stat 0x00000040, connection status changed
[  153.359941] ata1: SError: { CommWake 10B8B Dispar LinkSeq TrStaTrns DevExch }
[  153.367100] ata1: hard resetting link
[  157.232776] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[  157.239222] ata1.00: supports DRM functions and may not be fully accessible
[  157.247124] ata1.00: supports DRM functions and may not be fully accessible
[  157.254526] ata1.00: configured for UDMA/133
[  157.272764] ata1: EH complete

If there was no drive at all during boot, there wont be anything detected afterwards.

There is not much about hotplug support in the Parker TRM, but the support of eSATA shall imply that the port will be hotplugged!

Yes, we got the same result trying to hot-swap sata by using insmod/rmmod, we think the hardware controller of TX2 does not implement hot-swap function or the driver code is incomplete.

Hi danieel,

We are not support SATA hot plug function. Thanks!