Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Chunfeng Yun (云春峰)" <Chunfeng.Yun@mediatek.com>
To: "mika.westerberg@linux.intel.com" <mika.westerberg@linux.intel.com>
Cc: "konrad.dybcio@oss.qualcomm.com" <konrad.dybcio@oss.qualcomm.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"westeri@kernel.org" <westeri@kernel.org>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	"YehezkelShB@gmail.com" <YehezkelShB@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"sven@kernel.org" <sven@kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"andreas.noever@gmail.com" <andreas.noever@gmail.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>
Subject: Re: [PATCH v2 4/7] thunderbolt: add platform NHI driver
Date: Tue, 17 Nov 2026 12:14:29 +0000	[thread overview]
Message-ID: <2807832e631dca98846d201b571f623210820268.camel@mediatek.com> (raw)
In-Reply-To: <20261110143758.GC259790@black.igk.intel.com>

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@mediatek.com>
> > + */
> > +
> > +#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.

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 *),

> 
> > +	}
> > +
> > +	return ret;
> > +}
> > +
> > +static void nhi_platform_exit(struct tb_nhi *nhi)
> > +{
> > +	devm_free_irq(nhi->dev, nhi->irq, nhi);
> 
> Isn't it released automatically?
refer to nhi_pci_exit() which give the reason that avoid queuing the
interrupt_work again, I will add a common in next version.

> 
> > +	flush_work(&nhi->interrupt_work);
> > +
> > +	pm_runtime_put_noidle(nhi->dev);
> > +	pm_runtime_disable(nhi->dev);
> > +	pm_runtime_set_suspended(nhi->dev);
> > +}
> > +
> > +static const struct tb_nhi_ops nhi_platform_default_ops = {
> > +	.init = nhi_platform_init,
> > +	.shutdown = nhi_platform_exit,
> > +	.init_interrupts = nhi_platform_init_irq,
> > +};
> > +
> > +static int nhi_platform_probe(struct platform_device *pdev)
> > +{
> > +	struct device *dev = &pdev->dev;
> > +	struct tb_nhi *nhi;
> > +
> > +	nhi = devm_kzalloc(dev, sizeof(*nhi), GFP_KERNEL);
> 
> devm_kzalloc_obj()
ACK
> 
> > +	if (!nhi)
> > +		return -ENOMEM;
> > +
> > +	nhi->dev = dev;
> > +	nhi->ops = &nhi_platform_default_ops;
> > +
> > +	nhi->iobase = devm_platform_ioremap_resource(pdev, 0);
> > +	if (IS_ERR(nhi->iobase))
> > +		return PTR_ERR(nhi->iobase);
> > +
> > +	nhi->irq = platform_get_irq(pdev, 0);
> > +	if (nhi->irq < 0)
> > +		return nhi->irq;
> > +
> > +	/* ignore error */
> 
> This should explain why it's okay to ignore the error.
ACK, it is implementation specific, so make it optional

> 
> > +	nhi->wake_irq = platform_get_irq_optional(pdev, 1);
> > +	if (nhi->wake_irq == -EPROBE_DEFER)
> > +		return nhi->wake_irq;
> > +	else if (nhi->wake_irq < 0)
> > +		nhi->wake_irq = 0;
> > +
> > +	return tb_nhi_probe(nhi);
> > +}
> > +
> > +static void nhi_platform_do_remove(struct platform_device *pdev,
> > bool reset)
> > +{
> > +	struct device *dev = &pdev->dev;
> > +	struct tb *tb = platform_get_drvdata(pdev);
> > +	struct tb_nhi *nhi = tb->nhi;
> 
> Reverse-christmas tree if possible:
ACK
> 
> 	struct tb *tb = platform_get_drvdata(pdev);
> 	struct device *dev = &pdev->dev;
> 	struct tb_nhi *nhi = tb->nhi;
> 
> > +
> > +	/*
> > +	 * On system shutdown/reboot force a host router reset so
> > the
> > +	 * CM asserts DPR on connected tbt3 devices before the
> > router tree
> 
> Thunderbolt 3
ACK
> 
> > +	 * is removed (see tb_stop()).
> > +	 */
> > +	if (reset)
> > +		nhi->host_reset = true;
> > +
> > +	pm_runtime_get_sync(dev);
> > +	pm_runtime_dont_use_autosuspend(dev);
> > +
> > +	tb_domain_remove(tb);
> > +	wait_for_completion(&nhi->domain_released);
> > +	tb_nhi_shutdown(nhi);
> > +}
> > +
> > +static void nhi_platform_remove(struct platform_device *pdev)
> > +{
> > +	nhi_platform_do_remove(pdev, false);
> > +}
> > +
> > +static void nhi_platform_shutdown(struct platform_device *pdev)
> > +{
> > +	nhi_platform_do_remove(pdev, true);
> > +}
> > +
> > +
> > +#ifdef CONFIG_OF
> > +static const struct of_device_id nhi_platform_of_match[] = {
> > +	{ .compatible = "usb4-nhi-platform" },
> > +	{ }
> > +};
> 
> I think this was agreed to be dropped for now.

will drop it

Thanks
> 
> > +MODULE_DEVICE_TABLE(of, nhi_platform_of_match);
> > +#endif
> > +
> > +#ifdef CONFIG_ACPI
> > +static const struct acpi_device_id nhi_platform_acpi_match[] = {
> > +	{ "ACPI0015", 0 },
> > +	{ }
> > +};
> > +MODULE_DEVICE_TABLE(acpi, nhi_platform_acpi_match);
> > +#endif
> > +
> > +static struct platform_driver nhi_platform_driver = {
> > +	.probe = nhi_platform_probe,
> > +	.remove = nhi_platform_remove,
> > +	.shutdown = nhi_platform_shutdown,
> > +	.driver = {
> > +		.name = "thunderbolt",
> > +		.of_match_table =
> > of_match_ptr(nhi_platform_of_match),
> > +		.acpi_match_table =
> > ACPI_PTR(nhi_platform_acpi_match),
> > +		.pm = &tb_nhi_pm_ops,
> > +	},
> > +};
> > +
> > +module_platform_driver(nhi_platform_driver);
> > +MODULE_ALIAS("platform:thunderbolt");
> > +MODULE_DESCRIPTION("Thunderbolt/USB4 platform host interface
> > driver");
> > +MODULE_LICENSE("GPL v2");
> > diff --git a/include/linux/thunderbolt.h
> > b/include/linux/thunderbolt.h
> > index 57502da29080..72497acac254 100644
> > --- a/include/linux/thunderbolt.h
> > +++ b/include/linux/thunderbolt.h
> > @@ -511,6 +511,8 @@ void tb_service_properties_changed(struct
> > tb_service *svc);
> >   * @going_away: The host controller device is about to disappear
> > so when
> >   *		this flag is set, avoid touching the hardware
> > anymore.
> >   * @iommu_dma_protection: An IOMMU will isolate external-facing
> > ports.
> > + * @irq: interrupt number of NHI.
> > + * @wake_irq: optional dedicated wakeup interrupt.
> >   * @interrupt_work: Work scheduled to handle ring interrupt when
> > no
> >   *		    MSI-X is used.
> >   * @hop_count: Number of rings (end point hops) supported by NHI.
> > @@ -532,6 +534,8 @@ struct tb_nhi {
> >  	u32 *interrupt_mask;
> >  	bool going_away;
> >  	bool iommu_dma_protection;
> > +	int irq;
> > +	int wake_irq;
> >  	struct work_struct interrupt_work;
> >  	u32 hop_count;
> >  	unsigned long quirks;
> > -- 
> > 2.45.2


  reply	other threads:[~2026-11-17 12:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 11:48 [PATCH 0/7] thunderbolt: Add support platform NHI driver Chunfeng Yun
2026-11-10 11:48 ` [PATCH v2 1/7] thunderbolt: Prefix NHI core functions with tb_ and tb_ring_ Chunfeng Yun
2026-11-10 12:42   ` Konrad Dybcio
2026-11-11  2:26     ` Chunfeng Yun (云春峰)
2026-11-10 11:48 ` [PATCH v2 2/7] thunderbolt: Move ICM mailbox functions to icm.c and internalize interrupt work Chunfeng Yun
2026-11-10 14:24   ` Mika Westerberg
2026-11-11  2:37     ` Chunfeng Yun (云春峰)
2026-11-10 11:48 ` [PATCH v2 3/7] thunderbolt: Make PCIe NHI support opt-in Chunfeng Yun
2026-11-10 11:48 ` [PATCH v2 4/7] thunderbolt: add platform NHI driver Chunfeng Yun
2026-11-10 12:43   ` Konrad Dybcio
2026-11-11 13:29     ` Chunfeng Yun (云春峰)
2026-11-10 14:37   ` Mika Westerberg
2026-11-17 12:14     ` Chunfeng Yun (云春峰) [this message]
2026-11-17 12:52       ` mika.westerberg
2026-11-10 11:48 ` [PATCH v2 5/7] thunderbolt: increase the lane adapter link-up timeout value Chunfeng Yun
2026-11-10 14:39   ` Mika Westerberg
2026-11-12  7:24     ` Chunfeng Yun (云春峰)
2026-11-10 11:48 ` [PATCH v2 6/7] thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP Chunfeng Yun
2026-11-10 14:40   ` Mika Westerberg
2026-11-12  8:00     ` Chunfeng Yun (云春峰)
2026-11-10 11:48 ` [PATCH v2 7/7] thunderbolt: prevent pcie tunnel activation/teardown warnings Chunfeng Yun
2026-11-10 14:50   ` Mika Westerberg
2026-11-16  3:17     ` Chunfeng Yun (云春峰)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2807832e631dca98846d201b571f623210820268.camel@mediatek.com \
    --to=chunfeng.yun@mediatek.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=sven@kernel.org \
    --cc=westeri@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox