Removable SD Card support for MM6108

I’m attempting to use an SDIO module with the MM6108 on a removable SD card. Is this supported with the morse_sdio driver?

When I remove the device, I see the following output:

morse_sdio mmc2:0001:1: sdio removed func 1 vendor 0x325b device 0x306
WARNING: driver morse_sdio did not remove its interrupt handler!
morse_sdio mmc2:0001:2: sdio removed func 2 vendor 0x325b device 0x306
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_read failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_read failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_read failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_read failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_read failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
morse_sdio mmc2:0001:2: morse_sdio_set_func_address_base -123
morse_sdio mmc2:0001:2: morse_sdio_get_func failed
morse_sdio mmc2:0001:2: morse_sdio_reg32_write failed 18446744073709551611
mmc mmc2:0001: Runtime PM usage count underflow!
Failed to acquire reset gpio. Skipping reset.
mmc2: tried to HW reset card, got error -123
mmc2: card 0001 removed

Strictly speaking, no the Morse Micro driver has not been developed to support hot removal. Primarily this is because the device driver “requires” gpios to be defined in device tree for proper function (power save and reset on removal of the driver).

That being said, the power-gpios are only used for power save, and while good to have, the reset-gpio is only really needed if you rmmod morse.
These errors look like they might be caused by driver work queues being flushed during morse_sdio_remove.

It may not be super straightforward to add support for hot removal of SDIO, as there are some things to clean up. But I’m curious, does it hotplug correctly after this removal?

Yes, the driver appears to reload correctly after a hotplug. I have not done extensive testing, but I am able to remove and insert the device several times successfully initializing each time.

I’m not sure there’s a straightforward solution here. You could try to replace flush_workqueue with cancel_work_sync in morse_sdio_remove. I can’t stand by this as an official recommendation though, and given the nature of the bus and driver, I don’t think we can guarantee no in-flight messages will not error on on hot-removal. Network interfaces can be quite busy.