Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver
From: mika.westerberg@xxxxxxxxxxxxxxx
Date: Tue Nov 17 2026 - 07:52:59 EST
Hi,
On Tue, Nov 17, 2026 at 12:14:29PM +0000, Chunfeng Yun (云春峰) wrote:
> On 二, 2026-11-10 at 15:37 +0100, Mika Westerberg wrote:
> > On Tue, Nov 10, 2026 at 07:48:52PM +0800, Chunfeng Yun wrote:
> > >
> > > -void nhi_enable_int_throttling(struct tb_nhi *nhi);
> > > void nhi_disable_interrupts(struct tb_nhi *nhi);
> > > irqreturn_t tb_nhi_isr(int irq, void *data);
> > > irqreturn_t tb_ring_msix(int irq, void *data);
> > > diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c
> > > index 9379c598a221..698f47ec63da 100644
> > > --- a/drivers/thunderbolt/pci.c
> > > +++ b/drivers/thunderbolt/pci.c
> > > @@ -736,4 +736,5 @@ static struct pci_driver nhi_driver = {
> > > .shutdown = nhi_pci_shutdown,
> > > .driver.pm = &tb_nhi_pm_ops,
> > > };
> > > +
> >
> > I guess this is unintented change?
> >
> will drop it
>
> > > module_pci_driver(nhi_driver);
> > > diff --git a/drivers/thunderbolt/platform.c
> > > b/drivers/thunderbolt/platform.c
> > > new file mode 100644
> > > index 000000000000..3562b6c7ea7d
> > > --- /dev/null
> > > +++ b/drivers/thunderbolt/platform.c
> > > @@ -0,0 +1,172 @@
> > > +// SPDX-License-Identifier: GPL-2.0-only
> > > +/*
> > > + * Thunderbolt driver - NHI driver (Platform bus specific
> > > implementation)
> > > + *
> > > + * Author: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
> > > + */
> > > +
> > > +#include <linux/acpi.h>
> > > +#include <linux/interrupt.h>
> > > +#include <linux/errno.h>
> > > +#include <linux/of.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/pm_runtime.h>
> > > +#include <linux/pm_wakeirq.h>
> > > +#include <linux/slab.h>
> > > +
> > > +#include "nhi.h"
> > > +#include "tb.h"
> > > +
> > > +static int nhi_platform_init(struct tb_nhi *nhi)
> > > +{
> > > + /* avoid device link fail for pcie tunnel */
> >
> > Do you have the ACPI _DSD there in place?
> Yes, we use the same uefi as WoA which pass Windows HLK and usb-if
> certitfication
>
> > Then I don't think you need
> > these. And "pcie" -> "PCIe" everywhere (except in code).
> ACK
>
> >
> > > + pm_runtime_set_active(nhi->dev);
> > > + pm_runtime_get_noresume(nhi->dev);
> > > + pm_runtime_enable(nhi->dev);
> > > +
> > > + device_set_wakeup_capable(nhi->dev, true);
> > > + device_enable_async_suspend(nhi->dev);
> >
> > I also suggest not to enable all the fancy power management until you
> > have
> > the basic stuff like tunneling fully functional.
> I'm not sure understand what you mean.
>
> if you mean the function test:
> I already test usb4net, usb3 tunnel, PCIe tunnel and dp tunnel data
> transfers, and also runtime suspend/resume and system suspend/resume.
>
> if you mean when to enable pm:
> do you mean enable pm at the enable of tb_nhi_probe()?
>
> + pm_runtime_set_active(nhi->dev);
> + pm_runtime_get_noresume(nhi->dev);
> + pm_runtime_enable(nhi->dev);
>
> these three line shall be put before nhi_select_cm(), otherwise, it
> fail to link PCIe devices, and I will check it again.
>
> + device_set_wakeup_capable(nhi->dev, true);
> + device_enable_async_suspend(nhi->dev);
>
> these two line can be put at the end of probe.
I meant device_enable_async_suspend() it's not stricly required and we
don't do it elsewhere so I would leave it out now and then add it
everywhere later.
>
> if you have any suggestions, please describe more details, I will try
> it.
>
> >
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static void nhi_platform_clear_wake_irq(void *dev)
> > > +{
> > > + dev_pm_clear_wake_irq(dev);
> > > +}
> > > +
> > > +static int nhi_platform_init_irq(struct tb_nhi *nhi)
> > > +{
> > > + struct device *dev = nhi->dev;
> > > + int ret;
> > > +
> > > + ret = devm_request_irq(dev, nhi->irq, tb_nhi_isr,
> > > IRQF_NO_SUSPEND,
> > > + dev_name(dev), nhi);
> > > + if (ret)
> > > + return dev_err_probe(dev, ret, "request irq
> > > failed\n");
> >
> > failed to request interrupt
> >
> > Please be consistent with the rest of the driver.
> ACK
> >
> > > +
> > > + if (nhi->wake_irq) {
> > > + ret = dev_pm_set_dedicated_wake_irq(dev, nhi-
> > > >wake_irq);
> > > + if (ret) {
> > > + return dev_err_probe(dev, ret, "set wake
> > > irq %d failed\n", nhi->wake_irq);
> >
> > Split this into 2 lines.
> ACK
> >
> > > + }
> > > +
> > > + dev_info(dev, "wake irq %d\n", nhi->wake_irq);
> >
> > Remove this. The driver should be silent when it works. You can add
> > debug
> > but I don't think this is useful.
> ACK
> >
> > > +
> > > + ret = devm_add_action_or_reset(dev,
> > > nhi_platform_clear_wake_irq, dev);
> >
> > Can you pass dev_pm_clear_wake_irq directly here?
>
> the parameter type do not match which cause build warning
>
> kernel/mediatek/drivers/thunderbolt/platform.c:8:
> kernel/mediatek/drivers/thunderbolt/platform.c: In function
> 'nhi_platform_init_irq':
> kernel/mediatek/drivers/thunderbolt/platform.c:53:53: error: passing
> argument 2 of '__devm_add_action_or_reset' from incompatible pointer
> type [-Werror=incompatible-pointer-types]
> 53 | ret = devm_add_action_or_reset(dev,
> dev_pm_clear_wake_irq, dev);
> |
> ^~~~~~~~~~~~~~~~~~~~~
> | |
> | void
> (*)(struct device *)
> upstream/k7/kernel/mediatek/include/linux/device/devres.h:283:41: note:
> in definition of macro 'devm_add_action_or_reset'
> 283 | __devm_add_action_or_reset(dev, action, data, #action)
> | ^~~~~~
> upstream/k7/kernel/mediatek/include/linux/device/devres.h:271:73: note:
> expected 'void (*)(void *)' but argument is of type 'void (*)(struct
> device *)'
> 271 | static inline int __devm_add_action_or_reset(struct device
> *dev, void (*action)(void *),
Oh right it has different prototyp so you need the wrapper. Then it's okay.