From nobody Wed Jan 14 03:15:22 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4drWTC2X1Lz6P4vy for ; Wed, 14 Jan 2026 03:15:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4drWTC1dYwz3tWx for ; Wed, 14 Jan 2026 03:15:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768360527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=elaWg4hS2JxPR5+Ff9tfAHLUdyb/DdcLfcfuFEjc3LA=; b=g88G4PdKGRj5+AcInpPDWsOcf9dIk6xOWZgI38S1ZKa8TW7x9LMzUuSKwaTrXczD7Wz4PS XAjfekBAm6r/Vz7BLMgoo+gyADxTaYZH3YreEzs4X323Ed9Y3gemWSnFnZET1BoQs5MGwa UWMuVSOjjbMFxKfR1Sta15s/I41s9uwpa4v/xbLBS/+PTbBW8TKFh4f2qb4xUrsVz0BwxR dlzRpBoye3nokxGKffQ91feeYOFsIt9LQr5kapSxSzX29CUC8BemjtqtceAwj0uGiXLFF6 YNoQS/e1ui6Z/8RjVunc0X4LubNF76wM9IyWmP9RSBqEsg1BJh5LBfyuTfqGww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768360527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=elaWg4hS2JxPR5+Ff9tfAHLUdyb/DdcLfcfuFEjc3LA=; b=ciQCozkOAHdPckMXKWe4wVmOlfGYo8Zws8jJLtlyz8JikVEWHqJskBgHBTnVx2p76E4tBD DeD2RveY1EMRDkUX9hT4ECcTXWSvF9qY38iA9OZqNlTxJIzSfiM7eH4lFdQDmkVNoqwN4C 0O/LOrjgB3h33HiVD2ycvifFIvryYBXkHORm7y08Evnb5QWTQelpnFmK4lkNzuAP4IKnZr TdPwdeaUEpEHoNVtjfzjfH1SXTBTpuFcaO8onL4knuLV81eXkN1pzufxNmlVdKmQ5TztqB bEWMikjo1F7up4ZY6+BPUbvFAJbyVGf9yvHUbu1OecJB1uElovIf6cEpJWXt4w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768360527; a=rsa-sha256; cv=none; b=xD+lzfUHmGbDiYq2C/oay6mzeqMRnDzOL/z4iitViAJdXj/Gv4zklq1cGunG6xda7IfVX3 fFWlCVA/IybraAbmLClOQ2hWREOJjw2NL+UOxMa+FwWhwGG3/WMi4c2CYFMT48UiiU5Geu lfBuk0ZNnaGPKwmAa/HM9jjLgIDih4q5DKgZuVi/4XFkbhMZJ28ViM9OggM5ImyF4N58xK pQyGemzqfUe7JMJni6u3/MXrq0h+ePEGsAlZVWwPJ5uR19r4iYnjvXJPgNy6iLg7zQ5THE zALUk3OVCuO8+M9UapUq5FAy5unRsXf8vwWij5JddlpSytqIK4k0oM7tIHys5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4drWTC12SnzhR1 for ; Wed, 14 Jan 2026 03:15:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id e065 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 14 Jan 2026 03:15:22 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Abdelkader Boudih From: Adrian Chadd Subject: git: a24166d23d2e - main - mtw(4): Fix warm reboot initialization failures for MT7601U List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: adrian X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a24166d23d2e93e787165064fac75215d4383c65 Auto-Submitted: auto-generated Date: Wed, 14 Jan 2026 03:15:22 +0000 Message-Id: <69670a4a.e065.547d973@gitrepo.freebsd.org> The branch main has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=a24166d23d2e93e787165064fac75215d4383c65 commit a24166d23d2e93e787165064fac75215d4383c65 Author: Abdelkader Boudih AuthorDate: 2026-01-14 02:35:53 +0000 Commit: Adrian Chadd CommitDate: 2026-01-14 02:40:20 +0000 mtw(4): Fix warm reboot initialization failures for MT7601U The mtw(4) driver works correctly on initial boot, but fails to initialize the MT7601U WiFi adapter after a warm reboot. Users must either physically unplug and replug the USB adapter, or perform a full power cycle to restore functionality, if usb power is always powered (only a replug works) The root cause is that warm reboot does not power-cycle USB devices, leaving the MT7601U in a stale state from the previous session. The MCU retains its ready flag and the device ignores initialization commands, resulting in timeout waiting for MCU to initialize errors. At the OS Level, pinging 1.1.1.1 will work, but the speed will be very slow. In addition in debug mode, we see thousand of error logs. This patch addresses the issue by: * Performing USB re-enumeration on attach to reset the device state * Detecting when the MCU is already marked ready (stale from previous session) and forcing a reset of the MCU before loading firmware * Increasing the firmware load timeout from 3s to 10s to accommodate slower initialization after reset * Increasing MCU ready poll attempts from 100 to 300 with longer delays to handle devices that take longer to become ready after reset Note: The increase was random, lower value might work. Test Plan: Tested on MacBook Pro (late-2015) and a MacMini with MediaTek MT7601U USB adapter across multiple warm reboot cycles. With the mac-mini and a another desktop, the issue happens only if connected via an always powered usb hub port in the monitor. The laptop don't power cycle it power. Differential Revision: https://reviews.freebsd.org/D54659 Reviewed by: adrian --- sys/dev/usb/wlan/if_mtw.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/sys/dev/usb/wlan/if_mtw.c b/sys/dev/usb/wlan/if_mtw.c index 8384c0a2d9fc..9d256056f6b2 100644 --- a/sys/dev/usb/wlan/if_mtw.c +++ b/sys/dev/usb/wlan/if_mtw.c @@ -64,6 +64,7 @@ #include #include +#include #include "usbdevs.h" @@ -525,6 +526,15 @@ mtw_attach(device_t self) sc->sc_dev = self; sc->sc_sent = 0; + /* + * Reset the device to clear any stale state left over from + * a previous warm reboot. Some MT7601U devices fail otherwise. + */ + error = usbd_req_re_enumerate(uaa->device, NULL); + if (error != 0) + device_printf(self, "USB re-enumerate failed, continuing\n"); + DELAY(100000); /* 100ms settle time */ + mtx_init(&sc->sc_mtx, device_get_nameunit(sc->sc_dev), MTX_NETWORK_LOCK, MTX_DEF); @@ -585,7 +595,7 @@ mtw_attach(device_t self) sc->mac_rev = tmp & 0xffff; mtw_load_microcode(sc); - ret = msleep(&sc->fwloading, &sc->sc_mtx, 0, "fwload", 3 * hz); + ret = msleep(&sc->fwloading, &sc->sc_mtx, 0, "fwload", 10 * hz); if (ret == EWOULDBLOCK || sc->fwloading != 1) { device_printf(sc->sc_dev, "timeout waiting for MCU to initialize\n"); @@ -1105,11 +1115,22 @@ mtw_load_microcode(void *arg) // int ntries; int dlen, ilen; device_printf(sc->sc_dev, "version:0x%hx\n", sc->asic_ver); - /* is firmware already running? */ + /* + * Firmware may still be running from a previous warm reboot. + * Force a reset of the MCU to ensure a clean state. + */ mtw_read_cfg(sc, MTW_MCU_DMA_ADDR, &tmp); if (tmp == MTW_MCU_READY) { - return; + device_printf(sc->sc_dev, "MCU already running, resetting\n"); + mtw_write(sc, MTW_MCU_RESET_CTL, MTW_RESET); + DELAY(10000); + mtw_write(sc, MTW_MCU_RESET_CTL, 0); + DELAY(10000); + /* Clear ready flag */ + mtw_write_cfg(sc, MTW_MCU_DMA_ADDR, 0); + DELAY(1000); } + if (sc->asic_ver == 0x7612) { fwname = "mtw-mt7662u_rom_patch"; @@ -2856,7 +2877,7 @@ mtw_fw_callback(struct usb_xfer *xfer, usb_error_t error) } mtw_delay(sc, 10); - for (ntries = 0; ntries < 100; ntries++) { + for (ntries = 0; ntries < 300; ntries++) { if ((error = mtw_read_cfg(sc, MTW_MCU_DMA_ADDR, &tmp)) != 0) { device_printf(sc->sc_dev, @@ -2870,9 +2891,9 @@ mtw_fw_callback(struct usb_xfer *xfer, usb_error_t error) break; } - mtw_delay(sc, 10); + mtw_delay(sc, 30); } - if (ntries == 100) + if (ntries == 300) sc->fwloading = 0; wakeup(&sc->fwloading); return;