From: Chunfeng Yun <chunfeng.yun@mediatek.com>
To: Mika Westerberg <westeri@kernel.org>
Cc: Andreas Noever <andreas.noever@gmail.com>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Sven Peter <sven@kernel.org>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
<linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
Chunfeng Yun <chunfeng.yun@mediatek.com>
Subject: [PATCH v4 10/14] thunderbolt: Make nhi->ops optional
Date: Sat, 5 Dec 2026 16:33:35 +0800 [thread overview]
Message-ID: <20261205083342.4009278-11-chunfeng.yun@mediatek.com> (raw)
In-Reply-To: <20261205083342.4009278-1-chunfeng.yun@mediatek.com>
Commit dd60fb487e55 ("thunderbolt: Require nhi->ops be valid")
previously added a mandatory sanity-check in tb_nhi_probe() because
ops->init_interrupts() was required for all drivers.
Now that non-MSI-X interrupt handling has been internalized into
the NHI core, simple platform NHI drivers that use native software
Connection Manager may not need to supply any custom callbacks,
leaving nhi->ops as NULL. So make struct tb_nhi_ops optional again.
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
new patch
---
drivers/thunderbolt/nhi.c | 27 ++++++++++++---------------
drivers/thunderbolt/nhi.h | 2 ++
drivers/thunderbolt/switch.c | 6 +++---
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index a2d5a5b13b9b..d8acc934a318 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -669,7 +669,7 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,
if (!ring->descriptors)
goto err_free_ring;
- if (!(flags & RING_FLAG_NO_INTERRUPT) && nhi->ops->request_ring_irq) {
+ if (!(flags & RING_FLAG_NO_INTERRUPT) && TB_NHI_HAS_OP(nhi, request_ring_irq)) {
if (nhi->ops->request_ring_irq(ring, flags & RING_FLAG_NO_SUSPEND))
goto err_free_descs;
}
@@ -680,7 +680,7 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,
return ring;
err_release_msix:
- if (nhi->ops->release_ring_irq)
+ if (TB_NHI_HAS_OP(nhi, release_ring_irq))
nhi->ops->release_ring_irq(ring);
err_free_descs:
dma_free_coherent(ring->nhi->dev,
@@ -918,7 +918,7 @@ void tb_ring_free(struct tb_ring *ring)
}
spin_unlock_irq(&ring->nhi->lock);
- if (nhi->ops->release_ring_irq)
+ if (TB_NHI_HAS_OP(nhi, release_ring_irq))
nhi->ops->release_ring_irq(ring);
dma_free_coherent(ring->nhi->dev,
@@ -1030,7 +1030,7 @@ static int __nhi_suspend_noirq(struct device *dev, bool wakeup)
if (ret)
return ret;
- if (nhi->ops->suspend_noirq) {
+ if (TB_NHI_HAS_OP(nhi, suspend_noirq)) {
ret = nhi->ops->suspend_noirq(tb->nhi, wakeup);
if (ret)
return ret;
@@ -1091,9 +1091,9 @@ static int nhi_resume_noirq(struct device *dev)
* unplugged last device which causes the host controller to go
* away on PCs.
*/
- if ((nhi->ops->is_present && !nhi->ops->is_present(nhi))) {
+ if (TB_NHI_HAS_OP(nhi, is_present) && !nhi->ops->is_present(nhi)) {
nhi->going_away = true;
- } else if (nhi->ops->resume_noirq) {
+ } else if (TB_NHI_HAS_OP(nhi, resume_noirq)) {
ret = nhi->ops->resume_noirq(nhi);
if (ret)
return ret;
@@ -1134,7 +1134,7 @@ static int nhi_runtime_suspend(struct device *dev)
if (ret)
return ret;
- if (nhi->ops->runtime_suspend) {
+ if (TB_NHI_HAS_OP(nhi, runtime_suspend)) {
ret = nhi->ops->runtime_suspend(tb->nhi);
if (ret)
return ret;
@@ -1148,7 +1148,7 @@ static int nhi_runtime_resume(struct device *dev)
struct tb_nhi *nhi = tb->nhi;
int ret;
- if (nhi->ops->runtime_resume) {
+ if (TB_NHI_HAS_OP(nhi, runtime_resume)) {
ret = nhi->ops->runtime_resume(nhi);
if (ret)
return ret;
@@ -1182,7 +1182,7 @@ static void nhi_shutdown(struct tb_nhi *nhi)
flush_work(&nhi->interrupt_work);
}
- if (nhi->ops->shutdown)
+ if (TB_NHI_HAS_OP(nhi, shutdown))
nhi->ops->shutdown(nhi);
}
@@ -1226,7 +1226,7 @@ static struct tb *nhi_select_cm(struct tb_nhi *nhi)
* USB4 case is simple. If we got control of any of the
* capabilities, we use software CM.
*/
- if (!tb_acpi_is_native() && nhi->ops->select_cm) {
+ if (!tb_acpi_is_native() && TB_NHI_HAS_OP(nhi, select_cm)) {
tb = nhi->ops->select_cm(nhi);
if (tb)
return tb;
@@ -1236,7 +1236,7 @@ static struct tb *nhi_select_cm(struct tb_nhi *nhi)
if (!tb)
return NULL;
- if (nhi->ops->add_links)
+ if (TB_NHI_HAS_OP(nhi, add_links))
linked = nhi->ops->add_links(nhi);
if (!linked)
linked = tb_acpi_add_links(nhi);
@@ -1257,9 +1257,6 @@ int tb_nhi_probe(struct tb_nhi *nhi)
struct tb *tb;
int res;
- if (!nhi->ops)
- return dev_err_probe(dev, -EINVAL, "NHI ops not set\n");
-
res = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
if (res)
return dev_err_probe(dev, res, "failed to set DMA mask\n");
@@ -1295,7 +1292,7 @@ int tb_nhi_probe(struct tb_nhi *nhi)
}
}
- if (nhi->ops->init) {
+ if (TB_NHI_HAS_OP(nhi, init)) {
res = nhi->ops->init(nhi);
if (res) {
dev_err_probe(dev, res, "NHI specific init failed\n");
diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h
index 837bbc87c63f..a858d57b4d19 100644
--- a/drivers/thunderbolt/nhi.h
+++ b/drivers/thunderbolt/nhi.h
@@ -64,6 +64,8 @@ struct tb_nhi_ops {
struct tb *(*select_cm)(struct tb_nhi *nhi);
};
+#define TB_NHI_HAS_OP(nhi, op) ((nhi)->ops && (nhi)->ops->op)
+
/*
* PCI IDs used in this driver from Win Ridge forward. There is no
* need for the PCI quirk anymore as we will use ICM also on Apple
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 63ffc48738c9..760da4f5ebec 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -254,7 +254,7 @@ static int nvm_authenticate(struct tb_switch *sw, bool auth_only)
sw->nvm->authenticating = true;
if (!tb_route(sw)) {
- if (nhi->ops->pre_nvm_auth)
+ if (TB_NHI_HAS_OP(nhi, pre_nvm_auth))
nhi->ops->pre_nvm_auth(nhi);
ret = nvm_authenticate_host_dma_port(sw);
} else {
@@ -2819,7 +2819,7 @@ static int tb_switch_add_dma_port(struct tb_switch *sw)
nvm_get_auth_status(sw, &status);
if (status) {
if (!tb_route(sw)) {
- if (nhi->ops->post_nvm_auth)
+ if (TB_NHI_HAS_OP(nhi, post_nvm_auth))
nhi->ops->post_nvm_auth(nhi);
}
return 0;
@@ -2836,7 +2836,7 @@ static int tb_switch_add_dma_port(struct tb_switch *sw)
/* Now we can allow root port to suspend again */
if (!tb_route(sw)) {
- if (nhi->ops->post_nvm_auth)
+ if (TB_NHI_HAS_OP(nhi, post_nvm_auth))
nhi->ops->post_nvm_auth(nhi);
}
--
2.45.2
next prev parent reply other threads:[~2026-12-05 8:34 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 8:33 [PATCH v4 00/14] thunderbolt: Add platform NHI driver and modularize PCIe NHI Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 01/14] thunderbolt: Fix error handling and unwind paths in nhi_probe() Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 02/14] thunderbolt: Prefix NHI core symbols with tb_ and tb_ring_ Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 03/14] thunderbolt: Internalize non-MSI-X interrupt request and work in NHI core Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 04/14] thunderbolt: Encapsulate router device type checks in switch.c Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 05/14] thunderbolt: Move rpm_complete bus walk to domain.c Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 06/14] thunderbolt: Consolidate domain and NHI teardown into tb_nhi_remove() Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 07/14] thunderbolt: Move ICM mailbox functions to icm.c Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 08/14] thunderbolt: Decouple ICM probe from NHI core via .select_cm hook Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 09/14] thunderbolt: Make PCIe NHI support opt-in Chunfeng Yun
2026-12-05 8:33 ` Chunfeng Yun [this message]
2026-12-05 8:33 ` [PATCH v4 11/14] thunderbolt: Add platform NHI driver Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 12/14] thunderbolt: Increase the lane adapter link-up timeout value Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 13/14] thunderbolt: Decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP Chunfeng Yun
2026-12-05 8:33 ` [PATCH v4 14/14] thunderbolt: Drop WARN_ON() in tb_disconnect_pci() 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=20261205083342.4009278-11-chunfeng.yun@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=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
all inboxes | Powered by JetHome®