From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=60.244.123.138 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459650; b=sLSy8Je+a3VZWLxmh3lIsZPyVcc0DA+oeQGNx+eGGN4f4vsQ8oP7+qLyZCsoqqF3f21L fFjlMVzQT+PXTB+1I2MhrHTJ5kmPIJr0sqrmt9ex8xmRGNrG9rXzonnqeV8YO4Fpcn+Tn 0t5qMa5aDr5O0nQCGiSGBF6aAj/4Jk3x/3RLjNG/5F00Ur5R0iPu3NFby86D6TnPSC1S1 AApLKVt0ErqWfIzNsgcoAYV14DqZ1ky6uB4+UG9LwrBA7RmJMgC0eGZd8S83tbIx5wmkV 2I60lN3yrrj6BLBGRUXi7sBqA9hx4oL6IopjvYmTmRmuyN5wkvGrmUmiV5yv/iDAd9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459650; 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=JksfpE13V3Sortvk9JpWMHRYuHEFSkJ6p2+r/QxRmdk=; b=mk0AJjUYHf2MCprhDUsCOIV1NwEKngU1LnP7znUokyr3UZgdYsMGS+NBSLGm27+jKF8E xt0SSRUoII8Xgq0TS/z1xoc45eeP5SIG5xg0rjFLnCUTZzLyclNZH/MPNGivZWfbZhT6m R22YhJfS3170pHtsccD0HX2I7kHhTtd40MrRmFyE85o1bLbF6wVP4B244+CJRDRWIq7Nl OPDr6ojtwNpHVctHgzCRQ/oPBVVEYkUmPYqCCkKH64mJ2mhV7k13UI9v2cSxEVjqEr+Iv DjGaCBRLelQ5FzB02CUKXNtUYp2LpDZ68NYxtQKJAA4mrjje4xWJUCZ/sHyOtT5OfYQ== 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=B9aismIz; arc=none smtp.remote-ip=60.244.123.138 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 A0B29606A333; Sat, 5 Dec 2026 08:34:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A0B29606A333 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=B9aismIz X-UUID: a10d579ef08611f1b9cf3d4034dccee2-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=JksfpE13V3Sortvk9JpWMHRYuHEFSkJ6p2+r/QxRmdk=; b=B9aismIzoak4Of2gf1PDWKEpq9PHJ233j+ZrxzAyrrUZDcldr4thJfiVO0KKmZtxwqAn2HmfomoER2sOefVdnSk3XmeZzLd5EOjeMNaO+tdEqwRY6IxWpmT4QygpzMN2QgjDZs3PNswXs9MZv/vtvpY7RWj5/ODEGchFPasYoKo=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.22,REQID:9eb6f119-a826-4930-a988-24e75a439a95,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:f3017e1a-ae4c-4a2b-b1c4-72e411efd0c9,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: a10d579ef08611f1b9cf3d4034dccee2-20261205 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1804172892; Sat, 05 Dec 2026 16:34:04 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs10n1.mediatek.inc (172.21.101.34) 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:03 +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:02 +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 07/14] thunderbolt: Move ICM mailbox functions to icm.c Date: Sat, 5 Dec 2026 16:33:32 +0800 Message-ID: <20261205083342.4009278-8-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 In preparation for modularizing PCIe NHI and ICM support as a separate driver, clean up internal helper functions so that they do not need to be exported: nhi_mailbox_cmd() and nhi_mailbox_mode() are only used by the Intel firmware Connection Manager (icm.c) to exchange mailbox commands with firmware running on Intel PCIe NHIs. The Thunderbolt core framework, software connection manager, and non-PCIe platform controllers do not use this mailbox interface. Move both functions into icm.c and mark them static. Signed-off-by: Chunfeng Yun --- v4: drop &nhi->interrupt_work init which moved into the patch 03/14 in this series v3: fix a indent v2: new patch --- drivers/thunderbolt/icm.c | 59 ++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/nhi.c | 60 --------------------------------------- drivers/thunderbolt/nhi.h | 2 -- 3 files changed, 59 insertions(+), 62 deletions(-) diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c index f2c387d226f0..b01638b9f51d 100644 --- a/drivers/thunderbolt/icm.c +++ b/drivers/thunderbolt/icm.c @@ -45,6 +45,7 @@ #define ICM_RETRIES 3 #define ICM_APPROVE_TIMEOUT 10000 /* ms */ #define ICM_MAX_LINK 4 +#define ICM_MAILBOX_TIMEOUT 500 /* ms */ static bool start_icm; module_param(start_icm, bool, 0444); @@ -269,6 +270,64 @@ static int pcie2cio_write(struct icm *icm, enum tb_cfg_space cs, return pci2cio_wait_completion(icm, 5000); } +/** + * nhi_mailbox_cmd() - Send a command through NHI mailbox + * @nhi: Pointer to the NHI structure + * @cmd: Command to send + * @data: Data to be send with the command + * + * Sends mailbox command to the firmware running on NHI. + * + * Return: %0 on success, negative errno otherwise. + */ +static int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data) +{ + ktime_t timeout; + u32 val; + + iowrite32(data, nhi->iobase + REG_INMAIL_DATA); + + val = ioread32(nhi->iobase + REG_INMAIL_CMD); + val &= ~(REG_INMAIL_CMD_MASK | REG_INMAIL_ERROR); + val |= REG_INMAIL_OP_REQUEST | cmd; + iowrite32(val, nhi->iobase + REG_INMAIL_CMD); + + timeout = ktime_add_ms(ktime_get(), ICM_MAILBOX_TIMEOUT); + do { + val = ioread32(nhi->iobase + REG_INMAIL_CMD); + if (!(val & REG_INMAIL_OP_REQUEST)) + break; + usleep_range(10, 20); + } while (ktime_before(ktime_get(), timeout)); + + if (val & REG_INMAIL_OP_REQUEST) + return -ETIMEDOUT; + if (val & REG_INMAIL_ERROR) + return -EIO; + + return 0; +} + +/** + * nhi_mailbox_mode() - Return current firmware operation mode + * @nhi: Pointer to the NHI structure + * + * The function reads current firmware operation mode using NHI mailbox + * registers and returns it to the caller. + * + * Return: &enum nhi_fw_mode. + */ +static enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi) +{ + u32 val; + + val = ioread32(nhi->iobase + REG_OUTMAIL_CMD); + val &= REG_OUTMAIL_CMD_OPMODE_MASK; + val >>= REG_OUTMAIL_CMD_OPMODE_SHIFT; + + return (enum nhi_fw_mode)val; +} + static bool icm_match(const struct tb_cfg_request *req, const struct ctl_pkg *pkg) { diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c index d55e1f03b68a..0b13ddf6c99d 100644 --- a/drivers/thunderbolt/nhi.c +++ b/drivers/thunderbolt/nhi.c @@ -35,8 +35,6 @@ */ #define RING_E2E_RESERVED_HOPID RING_FIRST_USABLE_HOPID -#define NHI_MAILBOX_TIMEOUT 500 /* ms */ - static bool host_reset = true; module_param(host_reset, bool, 0444); MODULE_PARM_DESC(host_reset, "reset USB4 host router (default: true)"); @@ -964,64 +962,6 @@ int tb_ring_throttling(struct tb_ring *ring, unsigned int interval_nsec) } EXPORT_SYMBOL_GPL(tb_ring_throttling); -/** - * nhi_mailbox_cmd() - Send a command through NHI mailbox - * @nhi: Pointer to the NHI structure - * @cmd: Command to send - * @data: Data to be send with the command - * - * Sends mailbox command to the firmware running on NHI. - * - * Return: %0 on success, negative errno otherwise. - */ -int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data) -{ - ktime_t timeout; - u32 val; - - iowrite32(data, nhi->iobase + REG_INMAIL_DATA); - - val = ioread32(nhi->iobase + REG_INMAIL_CMD); - val &= ~(REG_INMAIL_CMD_MASK | REG_INMAIL_ERROR); - val |= REG_INMAIL_OP_REQUEST | cmd; - iowrite32(val, nhi->iobase + REG_INMAIL_CMD); - - timeout = ktime_add_ms(ktime_get(), NHI_MAILBOX_TIMEOUT); - do { - val = ioread32(nhi->iobase + REG_INMAIL_CMD); - if (!(val & REG_INMAIL_OP_REQUEST)) - break; - usleep_range(10, 20); - } while (ktime_before(ktime_get(), timeout)); - - if (val & REG_INMAIL_OP_REQUEST) - return -ETIMEDOUT; - if (val & REG_INMAIL_ERROR) - return -EIO; - - return 0; -} - -/** - * nhi_mailbox_mode() - Return current firmware operation mode - * @nhi: Pointer to the NHI structure - * - * The function reads current firmware operation mode using NHI mailbox - * registers and returns it to the caller. - * - * Return: &enum nhi_fw_mode. - */ -enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi) -{ - u32 val; - - val = ioread32(nhi->iobase + REG_OUTMAIL_CMD); - val &= REG_OUTMAIL_CMD_OPMODE_MASK; - val >>= REG_OUTMAIL_CMD_OPMODE_SHIFT; - - return (enum nhi_fw_mode)val; -} - static void nhi_interrupt_work(struct work_struct *work) { struct tb_nhi *nhi = container_of(work, typeof(*nhi), interrupt_work); diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h index 9aa167321cfe..e3f19e63f2ba 100644 --- a/drivers/thunderbolt/nhi.h +++ b/drivers/thunderbolt/nhi.h @@ -27,8 +27,6 @@ enum nhi_mailbox_cmd { NHI_MAILBOX_ALLOW_ALL_DEVS = 0x23, }; -int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data); -enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi); irqreturn_t tb_ring_msix(int irq, void *data); int tb_nhi_probe(struct tb_nhi *nhi); void tb_nhi_remove(struct tb_nhi *nhi, bool reset); -- 2.45.2