SATA support as a loadable kernel module


#1

I’m trying to compile the SATA support for the BPI-W2 as a loadable kernel module. I’ve modified the kconfig file to build the SATA mdoules (libata) and Realteck AHCI module (ahci_rtk) as loadable kernel modules. I’ve built the kernel and run it on my banana pi board, and when it boots, I can see that the modules have loaded with the lsmod command. When I power the attached SATA drives, though, they do not show up as block devices. Issuing the lsblk command does not return and SATA drives.

If I compile the kernel with those modules built in, everything seems to work, and I can see attached SATA drives have been enumerated as block devices when they are powered. If anyone has a possible solution for this, I would greatly appreciate it, before I have to get elbow deep in some kernel code.

Also, for the project I’m using the banana pi for, I do need to be able to unload and load the SATA support modules, so I can’t always have them built into the kernel.


#2

ok, i think i might have found a solution, but it lacks sufficient testing so far.

within libata-core.c file, in the sata_link_resume() function, there is a call to rtk_sata_phy_poweron() if the realtek ahci driver is being built into the kernel. that function calls phy_power_on(), which i think registers some drive presence interrupts, or something (i haven’t dug too much into that function yet). but that function does not appear to be called in a similar manner when compiling loadable kernel modules.

in the ahci_rtk_probe() function in the ahci_rtk.c file, i’ve added a call to phy_power_on() after the phy_init() function calls, and that seems to do all the proper behind the scenes registering of interrupts so that the drive now shows up as a block device after i’ve loaded the loadable kernel modules. i need to do some more testing to make sure that the drives are being accessed properly, and see what happens when powering down the drive, but i think this might be a little work around for this issue.