From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE57A606A684 for ; Sun, 29 Nov 2026 07:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DlTO6mc9; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=brjAjyGs DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-ID:Date :Cc:To:From:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=eUbsxHDyQdh8xTg/d9500aJTpsb+XFpv903p8R6mt/U=; b=DlTO6mc9j0iGl5rfIruRV8nEjc uCSkL1/7/9Kjs8l7GvupjUbxoyV/pTegDOvGjmbFOLE1c7cPHfqNo6AfOgcDBjcRWdVTrXHELcDPP 8wOq//XJyUaQXe7RvtC+DEQi/ywYYajbnOTm6IHA1CXWowrQddgEuQ2PhkU37wUTpnafaphj/aPl5 DnRX3fsjZR1z88EVUNmbYqoRUphKbW/d7aN6bjAnyaVFV5qmf22VnalEHWoohALdbBGUK6DuoeVhX G88K7RFoCHG5zeVNZfQTQ1Xx06tOWomhEomUph2h6UPZt6xrzpIgXSrVvt2qftcXhijrwioDecSyw QrH616AA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXZVO-00000001fUT-38kK; Sun, 29 Nov 2026 07:39:26 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXZVN-00000001fU9-1Xxw; Sun, 29 Nov 2026 07:39:25 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 724F2601EA; Sun, 29 Nov 2026 07:39:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9EA01F000C1; Sun, 29 Nov 2026 07:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795937964; bh=eUbsxHDyQdh8xTg/d9500aJTpsb+XFpv903p8R6mt/U=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=brjAjyGsKGLEFD6YwGjZlLmOwrGTT5RoMT3TNxl5l990REcG+kmR8rt0hSqUK0H+z PsN+0jQzbYAx/9qp8TazWaKvC46E9UfMj0WBZ4zFKxN/UEsbZ7fQp7WQdijiGQPrSG O2jn4QShksjV1cjaRdeXHb2lTeCbiq3tdYj1eyMeXlVPMVJIQZqFXBfd1fs3JydQdd Dt2K1wVQswrFVW0QAE/G2JjtBdD+7guYAkrhWwb5w9rOdv9rqCV/Ja/BuJtwU73hEC XrWifHqP3YFL6114UjRJK4PtKpTV8+x5D3A2RWke3uW8fKpaUuQ3e1t56NT6JIVDPZ wKS9rVKj4Ye4A== Subject: Re: [PATCH net-next v13 1/6] net: wwan: t9xx: Add PCIe core From: netdev-bot+sashiko@kernel.org To: jackbb_wu@compal.com Cc: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, johannes@sipsolutions.net, andrew+netdev@lunn.ch, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, wen-zhi.huang@mediatek.com, shi-wei.yeh@mediatek.com, Minano.tseng@mediatek.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org, robert_yu@compal.com, Jeff_Chang@compal.com, edumazet@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-doc@vger.kernel.org Date: Sun, 29 Nov 2026 07:39:22 +0000 Message-ID: <179593796217.3146.12932735833019291995@kernel.org> In-Reply-To: <20261125-t9xx_driver_v1-v13-1-92d9be5fb51e@compal.com> References: <20261125-t9xx_driver_v1-v13-1-92d9be5fb51e@compal.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Archived-By: MIME-Version: 1.0 X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 5 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] mtk_pci_drv sets no .driver.pm, so the PCI core uses its default handling for suspend/resume: it saves and restores config… - [Medium] mtk_pci_remove() never confirms that the modem actually went through reset before it calls pci_restore_state() (line 1001). - [Low] On kexec, mtk_pci_shutdown() (drivers/net/wwan/t9xx/pcie/mtk_pci.c:1008) calls mtk_pci_remove()… - [Low] The kernel-doc of mtk_pci_pldr() says that -EIO means "MRST._RST failed. - [Low] mtk_pci_remove() calls mtk_pci_pldr() (line 963) without first checking whether the device has already been marked disconnected. - [Low] mtk_pci_error_detected() (line 1014) only logs and returns PCI_ERS_RESULT_DISCONNECT, with the comment 'disconnect the device'. - [Low] mtk_pci_request_irq() (line 822) allocates 32 MSI-X vectors but deliberately never writes the MAC's MSI-X configuration register. -- net: wwan: t9xx: Add PCIe core This adds the PCIe core of the MediaTek T9xx 5G WWAN modem driver: probe/remove, MSI-X setup, ATR programming, the MHCCIF event channels, and the modem reset done on removal and on kexec shutdown. It also adds the Kconfig, Makefile and MAINTAINERS entries. > diff --git a/drivers/net/wwan/t9xx/pcie/mtk_pci.c b/drivers/net/wwan/t9xx/pcie/mtk_pci.c > new file mode 100644 > index 0000000000000..72b8e7043bd17 > --- /dev/null > +++ b/drivers/net/wwan/t9xx/pcie/mtk_pci.c > @@ -0,0 +1,1041 @@ [ ... ] > +/** > + * mtk_pci_pldr() - Reset the modem via its ACPI MRST._RST method > + * @mdev: MTK MD device > + * > + * Return: > + * * 0 - Success, device was reset. > + * * -ENODEV - No ACPI, no handle or no MRST._RST method. Device > + * untouched. > + * * -EIO - MRST._RST failed. Device untouched, still running; > + * a different reset may be attempted. > + */ > +static int mtk_pci_pldr(struct mtk_md_dev *mdev) > +{ [ ... ] > + acpi_ret = acpi_evaluate_object(handle, "MRST._RST", NULL, NULL); > + if (ACPI_FAILURE(acpi_ret)) { > + dev_err(mdev->dev, "Failed to execute MRST._RST method: %s\n", > + acpi_format_exception(acpi_ret)); > + return -EIO; > + } [Severity: Low] Can mtk_pci_pldr() actually promise "Device untouched, still running" on -EIO? The only check is ACPI_FAILURE() on the acpi_evaluate_object() status. A failure status doesn't say whether the AML had already toggled a reset GPIO or power rail before it failed. mtk_pci_remove() relies on this promise. On -EIO with pci_device_is_present() still true, it rings the DEV_EVT_H2D_DEVICE_RESET doorbell through BAR2/3 and then sleeps 2 seconds. A device that is part way through a reset can still answer the Vendor ID config read. Should the kernel-doc be relaxed, or should the MHCCIF fallback be skipped on -EIO? [ ... ] > +static int mtk_pci_request_irq(struct mtk_md_dev *mdev) > +{ > + struct pci_dev *pdev = to_pci_dev(mdev->dev); > + int ret; > + > + /* 32 vectors map 1:1 at the MAC's power-on default and the driver > + * never merges them, so the MSI-X config register is left alone. > + */ > + ret = pci_alloc_irq_vectors(pdev, MTK_IRQ_CNT_MAX, > + MTK_IRQ_CNT_MAX, PCI_IRQ_MSIX); [Severity: Low] Is it safe to rely on the power-on default here? mtk_pci_irq_msix() limits each vector to its own bit: irq_state &= irq_desc->msix_bits; /* scope to this vector */ if (unlikely(!irq_state)) return IRQ_NONE; So delivery depends on ISTATUS bit N being routed to vector N. Probe doesn't reset the modem. The commit message says the device can arrive un-reset, for example in a kdump capture kernel or after a failed removal reset. If something earlier changed the MAC MSI-X mapping (for example a vendor driver in the kexec'ing kernel that merged vectors), the MHCCIF event (bit 28) could arrive on a vector whose msix_bits doesn't include bit 28. In that case the handler returns IRQ_NONE without masking or dispatching the event. The boot handshake would never complete, and genirq may eventually disable the vector. The t7xx driver treats this register as host-owned. It programs it with t7xx_pcie_set_mac_msix_cfg() at probe and again in t7xx_pcie_interrupt_reinit(). Would programming it explicitly here be more robust? [ ... ] > +static void mtk_pci_remove(struct pci_dev *pdev) > +{ [ ... ] > + /* Reset last: the endpoint comes back at power-on defaults, so no MMIO > + * and no MSI-X teardown may follow it. > + */ > + ret = mtk_pci_pldr(mdev); > + if (!ret) { > + /* MRST._RST may return before the link has retrained, and a > + * config write the device does not take is simply lost. > + */ > + for (i = 0; i < MTK_PLDR_READY_POLLS && !mtk_pci_link_check(mdev); i++) > + msleep(MTK_PLDR_READY_POLL_MS); > + if (!mtk_pci_link_check(mdev)) > + dev_warn(dev, "device not back %d ms after reset, its config space may not be restored\n", > + MTK_PLDR_READY_POLLS * MTK_PLDR_READY_POLL_MS); [Severity: Low] What happens here on a surprise removal? With presence == false, pciehp_unconfigure_device() calls pci_dev_set_disconnected() before the driver is unbound. After that, pci_device_is_present() always returns false: drivers/pci/pci.c:pci_device_is_present() { ... if (pci_dev_is_disconnected(pdev)) return false; ... } If MRST._RST succeeds in that case, this loop always runs all 50 x 20 ms iterations and always prints the "device not back" warning. Then pci_restore_state() runs on a disconnected device. The platform reset is also issued for a slot that pciehp has already declared gone. Should mtk_pci_remove() check pci_dev_is_disconnected() before it attempts the reset? > + } else if (!mtk_pci_link_check(mdev)) { > + dev_warn(dev, "PLDR failed (%d) and link is down, modem not reset\n", ret); > + } else { > + if (ret == -ENODEV) > + dev_info(dev, "no MRST._RST, trying MHCCIF reset\n"); > + else > + dev_warn(dev, "PLDR failed (%d), trying MHCCIF reset\n", ret); > + if (mtk_pci_send_ext_evt(mdev, DEV_EVT_H2D_DEVICE_RESET)) { > + dev_err(dev, "MHCCIF reset failed\n"); > + } else { > + /* Unlike MRST._RST the doorbell returns before the device > + * has reset, and whether the link drops is up to the > + * firmware: wait a fixed time, then for a link that is > + * still down to come back, before the restore below. > + */ > + msleep(MTK_MHCCIF_RESET_DELAY_MS); > + for (i = 0; i < MTK_PLDR_READY_POLLS && !mtk_pci_link_check(mdev); i++) > + msleep(MTK_PLDR_READY_POLL_MS); > + if (!mtk_pci_link_check(mdev)) > + dev_warn(dev, "device not back %d ms after MHCCIF reset, its config space may not be restored\n", > + MTK_MHCCIF_RESET_DELAY_MS + > + MTK_PLDR_READY_POLLS * MTK_PLDR_READY_POLL_MS); > + } > + } > + > + /* The reset returned the endpoint to its power-on defaults: put back > + * the saved config space for the next driver that binds. > + */ > + pci_restore_state(pdev); > +} [Severity: Medium] Does a link that is up after the fixed delay show that the reset has actually happened? mtk_pci_send_ext_evt() posts the doorbell writes and returns 0 straight away: mtk_pci_write32(mdev, rc_base + MHCCIF_RC2EP_SW_BSY, hw_bits); mtk_pci_write32(mdev, rc_base + MHCCIF_RC2EP_SW_TCHNUM, ffs(hw_bits) - 1); return 0; mtk_pci_link_check() is only a Vendor ID config read. It can't tell "not reset yet, link still up" apart from "reset and back". Suppose the firmware carries out the reset after the 2 second window. Then pci_restore_state() writes to the device before the reset, and the late reset wipes it, with no warning. The BARs and PCI_COMMAND would be left at power-on defaults. The next probe's pcim_enable_device() doesn't reprogram the BAR registers, so pcim_iomap_region() would map addresses the device no longer decodes. The MRST._RST path seems to have the same gap if _RST returns before the link has dropped, since the first presence check then passes at once. The comment above that loop says _RST "may return before the link has retrained", which suggests it can be asynchronous. Is there a positive sign of reset completion that could be waited for before the restore? For example, a device state register returning to its reset value, or the link going down first. > +/* A kexec reboot neither resets nor powers down the slot, and the boot > + * notification the next kernel waits for is one-shot, so reset the modem > + * on the way down the same way remove() does. > + */ > +static void mtk_pci_shutdown(struct pci_dev *pdev) > +{ > + if (kexec_is_in_progress()) > + mtk_pci_remove(pdev); > +} [Severity: Low] Can mtk_pci_remove() end up running twice on a kexec reboot? The driver core doesn't know that shutdown already ran remove, so the driver stays bound. Below a hotplug-capable port the reset drops the link. As the commit message says, pciehp then removes the modem: device_shutdown() mtk_pci_shutdown() mtk_pci_remove() mtk_pci_pldr() <- link drops pciehp IRQ thread pciehp_disable_slot() pciehp_unconfigure_device() pci_stop_and_remove_bus_device() mtk_pci_remove() <- second time On the second run, mtk_mhccif_exit()->mtk_pci_unregister_irq() finds the MHCCIF callback already NULL and logs "irq_id=%d has not been registered". The IRQ masks are written over MMIO again. MRST._RST is evaluated again, or the doorbell is rung again with another 2 second sleep. The readiness poll also runs again, and it can never succeed if pciehp has marked the device disconnected. Later in the series, mtk_pci_dev_exit() gets a comment saying "remove() can follow a kexec shutdown that already ran this". That guard only covers the FSM and transport teardown. It doesn't cover the IRQ and MHCCIF teardown or the reset here. Could mtk_pci_remove() record that its teardown has already run and skip it the second time? > +static pci_ers_result_t mtk_pci_error_detected(struct pci_dev *pdev, > + pci_channel_state_t state) > +{ > + struct mtk_md_dev *mdev = pci_get_drvdata(pdev); > + > + dev_err(mdev->dev, "AER detected: pci_channel_state_t=%u\n", state); > + > + /* AER recovery not supported, disconnect the device */ > + return PCI_ERS_RESULT_DISCONNECT; > +} [Severity: Low] Does returning PCI_ERS_RESULT_DISCONNECT actually disconnect the device? For frozen channels, pcie_do_recovery() resets the link whatever the driver returns: drivers/pci/pcie/err.c:pcie_do_recovery() { ... if (status == PCI_ERS_RESULT_NEED_RESET || state == pci_channel_io_frozen) { if (reset_subordinates(bridge) != PCI_ERS_RESULT_RECOVERED) { ... } When recovery fails, the core only calls report_perm_failure_detected(), and the driver stays bound. After the secondary bus reset or DPC, the ATR tables, IMASK and MHCCIF EAP masks are back at their defaults. Nothing here quiesces the device (masking IMASK, cancelling mhccif_work, pci_clear_master()), and nothing reprograms those registers. A later mtk_pci_remove() then rings the DEV_EVT_H2D_DEVICE_RESET doorbell through an unprogrammed BAR2/3 window and still waits 2 seconds. Should mtk_pci_error_detected() at least quiesce the device? The "disconnect the device" comment could also be reworded, since the core doesn't disconnect it. > +static const struct pci_error_handlers mtk_pci_err_handler = { > + .error_detected = mtk_pci_error_detected, > +}; > + > +static struct pci_driver mtk_pci_drv = { > + .name = KBUILD_MODNAME, > + .id_table = t9xx_pci_table, > + .probe = mtk_pci_probe, > + .remove = mtk_pci_remove, > + .shutdown = mtk_pci_shutdown, > + .err_handler = &mtk_pci_err_handler > +}; [Severity: Medium] There's no .driver.pm in mtk_pci_drv, so across system suspend the PCI core only saves and restores config space. The commit message says "system suspend is not supported". However, nothing refuses or detects a suspend/resume cycle, and MODULE_DEVICE_TABLE autoloads the driver on laptops that have this modem. If the slot loses power in S3 or D3cold, the state programmed at probe returns to reset defaults, and config space restore doesn't bring it back. That state is: - the ATR tables from mtk_pci_atr_init() - the MAC IMASK state - the MHCCIF EP2RC mask written through the BAR2/3 window mtk_mhccif_isr_work() and the DEV_EVT_H2D_DEVICE_RESET doorbell in mtk_pci_remove() would then go through an unprogrammed ATR window, and the modem would fail silently after resume. Could the driver either reprogram this state on resume, or fail the suspend while the modem is bound? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-t9xx_driver_v1-v13-0-92d9be5fb51e%40compal.com