From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.61.82.184 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459653; b=d3rRABnIzITMZJGxABKb4di7J5knAwMY0h3Vbo0dHlOXmHEM/cO6m0UxUx44QeCDmWA5 zzmT9O3AohKGF4dLJhqQ8xQgl8N3PFwhOc2YwjdY43KNZDIWy8EBq795QQI9x2fwOEHrZ 3ppBfS5War9xW/hu2QEqe0hdbJYJwtZF+nLbYnmNty/08QVlp+GZUColF2vtsuyQQzcwO lpfnIPQuTMhiKm9EVJXv2tbRDKnUtYVLrWYG7AYzuR3t5Bn37dqQEYisYbXerfl9xkPaM P5HPz6DLnog7xV9RohND3WY2jWBJDBBUflwjQjsqS0ASt87X1YZL0J4k0PSC2spkT5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459653; h=DMARC-Filter:X-UUID:DKIM-Signature:X-CID-P-RULE:X-CID-O-INFO: X-CID-META:X-CID-BVR:X-CID-BAS:X-CID-FACTOR:X-CID-RHF:X-UUID:Received: Received:Received:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: Content-Type:X-MTK; bh=vFFbNc8x25wDZuaNapct+ltoP/vtp5LPA0Az6Il3T4U=; b=2jjkIBsxBlOKL5JhJGGghZmScXIjLHkifN0EAGU5kdyYCDDgUMZEJARASPhdscCn22/Z x7x+NR/OiGy+hKlBSrlOBFVWeByykqfRbILN8s2F2AUyyTT9ceUbZ91WaRdb5W5pvHaAa R+PirZqMiLQwFOGcBpLpBVzIFEynSQUOZQgHwNg7xs2rFkMePNLWFwRu7Ot010iyzTr/M Jh+oglWu4KZZKtvEcrouy3UOey5U95JHuDfj0egS1V9dXUgjQRFx6LqJhzzQMnYTQY/ZI pkR5KokKZQW+eGVEvCq4ahvHEDu79+2W+POxHukaSqmVP9cRouEHt/4ySIAqw1yM9kA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=EZnY6M6+; arc=none smtp.remote-ip=210.61.82.184 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (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 2C96760A2610; Sat, 5 Dec 2026 08:34:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2C96760A2610 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=EZnY6M6+ X-UUID: a2915b6af08611f1a7aecdb2598be72c-20261205 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=vFFbNc8x25wDZuaNapct+ltoP/vtp5LPA0Az6Il3T4U=; b=EZnY6M6+uR1rrBozIdF3MKTViwzVZA4Ye+PpAdIXJOns5jmY4Kg97+SBFv7sGWWhuzQITT3rxrrT/OOH+HM6XcHed1BgS0c1y8GnXqh51cSUkTIXyvGdRz0ppUAJ8ekXfc/9ruzmzfoIBDbCAgxWv4scvTrOVf2LbzIeWByVarM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.22,REQID:49af7110-a55b-438d-bd60-9f2484fad72e,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:d36851b,CLOUDID:a863c631-f289-4656-bb36-27baf4489f11,B ulkID:nil,BulkQuantity:0,SF:81|82|102|836|865|888|898,TC:-5,Content:0|15|5 0|99,EDM:-3,IP:nil,URL:0,File:130,RT:0,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0 ,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: a2915b6af08611f1a7aecdb2598be72c-20261205 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1214254397; Sat, 05 Dec 2026 16:34:06 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS09N1.mediatek.inc (172.21.101.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Sat, 5 Dec 2026 16:34:05 +0800 Received: from gcnsap21.gcn.mediatek.inc (10.17.81.22) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.56 via Frontend Transport; Sat, 5 Dec 2026 16:34:04 +0800 From: Chunfeng Yun To: Mika Westerberg CC: Andreas Noever , Konrad Dybcio , Sven Peter , Yehezkel Bernat , Matthias Brugger , Greg Kroah-Hartman , AngeloGioacchino Del Regno , , , , , Chunfeng Yun Subject: [PATCH v4 10/14] thunderbolt: Make nhi->ops optional Date: Sat, 5 Dec 2026 16:33:35 +0800 Message-ID: <20261205083342.4009278-11-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> References: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N 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 --- 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