From b4f48a6361ed25c17b1f5ba83aae91cd852bea2f Mon Sep 17 00:00:00 2001 From: Isaac Hermida Date: Mon, 24 Jun 2024 12:44:23 +0200 Subject: [PATCH] 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 c30b9474088da05d99c4b7b33347facf84f97596. https://onedigi.atlassian.net/browse/DEL-9083 Signed-off-by: Isaac Hermida --- .../kernel-module-nxp-wlan/load_iw612.sh | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/meta-digi-arm/recipes-kernel/kernel-modules/kernel-module-nxp-wlan/load_iw612.sh b/meta-digi-arm/recipes-kernel/kernel-modules/kernel-module-nxp-wlan/load_iw612.sh index 4aeb58f26..d3526cdff 100644 --- a/meta-digi-arm/recipes-kernel/kernel-modules/kernel-module-nxp-wlan/load_iw612.sh +++ b/meta-digi-arm/recipes-kernel/kernel-modules/kernel-module-nxp-wlan/load_iw612.sh @@ -23,24 +23,57 @@ sta_name=wlan \ country_ie_ignore=1 \ txpwrlimit_cfg=nxp/txpower_US.bin \ 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() { - 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 log "[ERROR] wireless mac-address not found" exit 1 fi - WLANADDR=$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/wireless/mac-address 2>/dev/null | sed 's/:$//g') -iw reg set US && \ -modprobe mlan && \ -modprobe moal ${MOAL_PARAMS} mac_addr=${WLANADDR} && \ -[ -d "/sys/class/net/wlan0" ] && log "Wi-Fi activated" && exit 0 +# 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 +} -log "[ERROR] cannot load Wi-Fi driver" +load_and_check() { + iw reg set US && \ + modprobe mlan && \ + modprobe moal ${MOAL_PARAMS} mac_addr=${WLANADDR} && \ + sleep $1 && [ -d "/sys/class/net/wlan0" ] +} + +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