kernel-module-nxp-wlan: rebind mmc node if wlan load failed

Occassionally, the loading the WiFi driver might fail, because of the
MMC node was not correctly initialized.
Fix that by rebinding the MMC node. This fix implements a similar workaround
as in c30b947408.

https://onedigi.atlassian.net/browse/DEL-9083

Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
This commit is contained in:
Isaac Hermida 2024-06-24 12:44:23 +02:00
parent e0be8c3a1f
commit b4f48a6361
1 changed files with 41 additions and 8 deletions

View File

@ -26,21 +26,54 @@ init_hostcmd_cfg=nxp/rutxpower_US.bin \
fw_name=nxp/sd_w61x_v1.bin.se \ fw_name=nxp/sd_w61x_v1.bin.se \
" "
MMC_NODE="428b0000.mmc"
# Lock file to track and prevent to re-run the script when rebinding the MMC node.
LOCKFILE="/tmp/iw61x.lock"
log() { log() {
printf "<3>iw612-wifi: $1\n" >/dev/kmsg printf "<3>iw61x-wifi: $1\n" >/dev/kmsg
} }
if test -f "$LOCKFILE"; then
# Script called due to rebinding of mmc. Ignore it and remove the lock file.
rm $LOCKFILE
exit 1
fi
if ! [ -e "/proc/device-tree/wireless/mac-address" ]; then if ! [ -e "/proc/device-tree/wireless/mac-address" ]; then
log "[ERROR] wireless mac-address not found" log "[ERROR] wireless mac-address not found"
exit 1 exit 1
fi fi
WLANADDR=$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/wireless/mac-address 2>/dev/null | sed 's/:$//g') WLANADDR=$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/wireless/mac-address 2>/dev/null | sed 's/:$//g')
# Force re-detection of the mmc node
rebind_mmc_node() {
DRIVER_NODE=$(find /sys/bus/platform/drivers -name ${MMC_NODE} | xargs dirname 2> /dev/null) || return 1
echo ${MMC_NODE} > ${DRIVER_NODE}/unbind
# Give some time to the mmc driver to re-detect the MMC node in order to re-initialize it.
sleep 2
echo ${MMC_NODE} > ${DRIVER_NODE}/bind
}
load_and_check() {
iw reg set US && \ iw reg set US && \
modprobe mlan && \ modprobe mlan && \
modprobe moal ${MOAL_PARAMS} mac_addr=${WLANADDR} && \ modprobe moal ${MOAL_PARAMS} mac_addr=${WLANADDR} && \
[ -d "/sys/class/net/wlan0" ] && log "Wi-Fi activated" && exit 0 sleep $1 && [ -d "/sys/class/net/wlan0" ]
}
log "[ERROR] cannot load Wi-Fi driver" load_and_check 0 && log "Wi-Fi activated" && exit 0
# If we are here, the load has failed. Unload (unconditionally) the driver in case it was loaded and retry.
log "[WARN] Loading moal module failed, retrying..."
modprobe -r moal
# Create a lock file, as rebinding the mmc node will trigger the udev rules
# Do not remove the file at the end, it will be called by the script in the rebind call
touch $LOCKFILE
# Rebind and load the driver. Use a custom sleep to give enough time to the driver load.
rebind_mmc_node && load_and_check 2 && log "Wi-Fi activated" && exit 0
log "[ERROR] Cannot activate Wi-Fi"
exit 1 exit 1