From nobody Fri Apr 17 07:58:58 2026 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012003.outbound.protection.outlook.com [52.101.43.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2109519D8AC for ; Mon, 23 Feb 2026 07:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.3 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771830403; cv=fail; b=Z2zpXztooJJWtCAAPIMAlB19Z49lreg2hWYZBQAFFyscsFz6B8UAYo9rFS+9kpm/ZgeVEOZaadMKTvSmS3hgKAI02VpP8161dn0Dlqje4F1HJoKn6tQc+j+MkzOALGMvAYMtFr+ioB8H9PEblo88SV+JMqYq9LlUqEYCx9nah9k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771830403; c=relaxed/simple; bh=0RruCIDSV1YsqwRJNBwI7SwuBMOOWHK1wc9cgiOSF1o=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=LQu6eC3sNmQGmdZUZTOqnWbnVQ9g4LpkeF2Y4e0mdUAYu3wk3hJ7+JNekh3pYremT0EAXXD2dKC3eiEd+1NeBefRdflMbbMmFqW+NSGj/kN4GP1UvWJz+7xr9AyMBEGDrGhyoOgLWXQ940CyUO5xo0UZjdZZG8eqjs0u9b7sTdI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=altera.com; spf=pass smtp.mailfrom=altera.com; dkim=pass (2048-bit key) header.d=altera.com header.i=@altera.com header.b=kvly49/8; arc=fail smtp.client-ip=52.101.43.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=altera.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altera.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=altera.com header.i=@altera.com header.b="kvly49/8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qU8v2WO8gnxC+xs2JX0coGlNm1hneKvxpZU6nMKqv/eIXwTxhc5XHkEGf0865HbXe+DNiVSMfGKfJMvPOBeG2dyiDDTv38S6/WmSLKLn7+bbpi3N6Hc6ODdJHXcp56/hY9X+eB3pmMnuGI+HBtltAezIqd8oyNUmeEOiNIYP4gNutqBj8LHISfaGgPV82I4vJAlMbmyieJJv9C/bOwXYZlWl3FRt30wK6PmbFYYlpXpo0laJ54VXE/fGyP1h4MG6Zq6SV+7gTdnn7FGKUatCHMgudLGceKRtqKjoNNSNQZSTFPkqMyWmIRoTImnuQN9Pxrp0bg2D5CA7Nozm9ErF5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dIahgDLyfK6+DBM6G+azYff17JbP8Ynf/KPDgiDWzNg=; b=HQwJs6vLfakt6rwD2ezg12NeirUVBDWZo7lIsloTO5CtYuRX7/TF85OxgAdStfXjLIzANgrA837A0apMA4xAn5bKFMgZOQOzCa1hw3U78fjkRTq4pV701zLyvQhEip7Swvef2dqfgFQubWx74AmrlMBdelRDpGCsYIdAWKBlvSwVo44erVrGl/q4rhT/NYTH8NGx3sjWyQvHh6/m2JXjHZzZH1krmDiucCj+P/NjIgzOIexWfgAuxNkPdp+S89JP72Vahk6NZyBXpjzwQEIi7LPwNe9EAwHS4o3TC2cxm/881fxZpPvvmoC1Gwd5lD8jon3A3BVgm10K+cKTXuidHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=altera.com; dmarc=pass action=none header.from=altera.com; dkim=pass header.d=altera.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=altera.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dIahgDLyfK6+DBM6G+azYff17JbP8Ynf/KPDgiDWzNg=; b=kvly49/8vpfd2iwST9ovxsx99ns5M2PbPB1lrCGRYHAIRobd8hR49XUu063zPTVbZ883Ob8VjUeJQMyP4W0qvaNO1f0tP5rpmg6ubyh9KRAfs7LHG89k0v3FNQcd2VCdDZz0/v06HQJE+eJxqnuWs9nsKdi9f4TVP343xBnhKjfHZDvqFrE41zfXGcJFrpJXW+OhI460Je9cgUpLaowMGSgq+FIGZmvjsKlAr1IWTPhOwkhfSlUYLtZtMdkLkz/nODEaF7IV+IPEATVF23TQeBHSMmG7wlqDfZg6QGzvtGzZB1iAlopDcDI+wOQshHiOe92rT5ipGV5KOmY7ahUiZw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=altera.com; Received: from BLAPR03MB5458.namprd03.prod.outlook.com (2603:10b6:208:29d::17) by PH0PR03MB5767.namprd03.prod.outlook.com (2603:10b6:510:42::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9632.21; Mon, 23 Feb 2026 07:06:39 +0000 Received: from BLAPR03MB5458.namprd03.prod.outlook.com ([fe80::7eda:fa34:15f9:e656]) by BLAPR03MB5458.namprd03.prod.outlook.com ([fe80::7eda:fa34:15f9:e656%5]) with mapi id 15.20.9632.017; Mon, 23 Feb 2026 07:06:39 +0000 From: Muhammad Amirul Asyraf Mohamad Jamian To: Dinh Nguyen , linux-kernel@vger.kernel.org, Ang Tien Sung Cc: Markus Elfring Subject: [v4] firmware: stratix10-svc: Add Multi SVC clients support Date: Sun, 22 Feb 2026 23:05:30 -0800 Message-Id: <20260223070530.19187-1-muhammadamirulasyraf.mohamadjamian@altera.com> X-Mailer: git-send-email 2.26.2 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR03CA0178.namprd03.prod.outlook.com (2603:10b6:a03:338::33) To BLAPR03MB5458.namprd03.prod.outlook.com (2603:10b6:208:29d::17) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BLAPR03MB5458:EE_|PH0PR03MB5767:EE_ X-MS-Office365-Filtering-Correlation-Id: 60079dca-eac4-4756-6997-08de72aa1726 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?WwUo78hpvW8dUvTgYCUO90VI97aYtOCaBJOmU544EXwVf13q3uAEXYe5QznE?= =?us-ascii?Q?S0U5OKmeoERTDbxzEJM9WRYPkcbZu6D3wWwwZ0znk+DJgwOxV5xdJdzYxMcf?= =?us-ascii?Q?uwvyfieBTy7/xfVJYCQlYaZYrirjlXsALkC8QKF/SeQ4ja5eTOOGiaaG/kbF?= =?us-ascii?Q?8DOugBiU6hGrBZnaDE04Q3BGNgyDRtdkKD8pPL04f1A5zPnA4aEJUKKxvcn7?= =?us-ascii?Q?hXCCJJmvnGhyH9MiYeErmjkBXdB8L1UcCyYgkXlQ57rhbEenLM8AD5YVdmH1?= =?us-ascii?Q?dIg4SF1XX0Yzj8xQCHg4PPMvqWDinlVEbzjkF7V/mQFumEkG0UcbPM5DBBle?= =?us-ascii?Q?qASuOOaoYWxTINO8dixxk2JEP6D/5xw5HtxE+Z169RUr7mJnAS2Pw4YYFC6m?= =?us-ascii?Q?uINYh+oK4DBTNHD3aVGjA7PeKMcY4gSjS+I2s46lrqFoLAxawcePF0T0FwOR?= =?us-ascii?Q?MSVfdYzYTyClnRmZsYRxZv706FjFWOkbl40hO9uElqch98S3iJOrpbCu3mXV?= =?us-ascii?Q?sSWJBGbadL7s93xgEjD+0HK8FRpmmlxEEX04K5LFG0GQXxJsL5b4FdmyshEy?= =?us-ascii?Q?e7eOUTKs/L5bjsdMlz3HXTPXpkJSujE8tY5jO0sptTzYT76WnVXaxeSeJij5?= =?us-ascii?Q?SYTvtouGpzKtr/DKcxs73clR+3ngnL+85JIie/2jo0HC+JVYRQP6kOsEp9ya?= =?us-ascii?Q?a7rVwNRu81SgHuamG+sooudOO3T+PC8t+y+yL78/+wn06sUqKNd2K/ZdGHdg?= =?us-ascii?Q?FQvj8ARy8+DenM3PJRGPLJE2bDoamwUJ01rCSe2i04J/QniDkiPDVAV/J2F1?= =?us-ascii?Q?7gH+KrbqvnGQYnwj1/e77sXxBOXmCKfyYwxiOQ6C69pEUo1i7v31GnsZEq2d?= =?us-ascii?Q?IPH5BgTIajK6NZFPDb46izRbMMZnW/D0XWa8lMCeMP0TiHrZKFdmhkyUezZX?= =?us-ascii?Q?eQtZxLJGck7mHpXBY/Osul9q6pry/8UE1aR5cuZCK3w8mGk4mMhqEo7BaIvN?= =?us-ascii?Q?m/bYi4eWVYDODPHXeqqdw85HAjjSqSCT8zA4aQ9Dh2wclmLcZt7ktlcQ3WQS?= =?us-ascii?Q?U4dB66vJpdhep4MVTzIxRQLRX+CCkyeZzLbfRGshv1lg0OiALoPL4pDxusfB?= =?us-ascii?Q?GQHscGpDUSjWn78LQzqiD6/qurHOdbzv1iTEch9qNR7C1RAAzjNN8NPFqosO?= =?us-ascii?Q?//kROs/YsW/vzmnrD3gE4pItLywLzwGV4pGi3CEoKnQFkZWgARWYAlX/HKad?= =?us-ascii?Q?4n1QM5GlbFUI+UfWdkE4W+RkZDgdW+Oos2CWenIMdMQOcpAK+ibF38j/KUzL?= =?us-ascii?Q?Ktt45mAksi4QOmDxH4lLSzOWUL6p26esI4+V/ZDyTLyNgltrbih+NWRh/gEV?= =?us-ascii?Q?k9Ow6UGvSs3VcA1qtsedKwUZM832eUnaTMeaq7PNcAJragpdviCNqf2Le1FW?= =?us-ascii?Q?btUl0E0mcfXVUm3V/Q7ev7doQ9zDkbTeKIPh4CRq1q7zq817xUX/6FmZPp4c?= =?us-ascii?Q?AYvcZHr9Ywj05jdJlvMFjsQEqA0gP7MfrBG0gjcEh5uvYlvr4VuZVzXO5oG/?= =?us-ascii?Q?z7blB6omBZ16Aov8fxw=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR03MB5458.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Vm+qPZKnv4QCcdrBCG6PPuXJBjYg0lhIcwlKaKscIpuespIRfpY9jOHf4LtL?= =?us-ascii?Q?+ftqfWD1koz7jThRtFM7c6X7dDUdDYheL91GCv5qXCjVFYkfZkW9UoMDld5m?= =?us-ascii?Q?KCb3jAm95+wyLkgBml8uqtjLZP1gJtg8oHRGKV5H1TGxw+sb66XHDdYuDV8g?= =?us-ascii?Q?vNgs0TyNtXLymU+RXseBOfn7g69i5nDKRsPD7sO2diQo5hK3gsA94HJS9VM4?= =?us-ascii?Q?57VbSgx6ffQg1WI7XnT46l1sjfHyLQDPVhTVivYOGVKuss3A8H1aGsi1NAu3?= =?us-ascii?Q?crrJPiBBblWRpCyxf6ftPcWfhT8iuvvRdHV6/vVmJZUCud4aL2rBO7EeamfV?= =?us-ascii?Q?/RGuxR/MWAJzG6TWIr/mxk6rUIu2QozCPsDHPH7KbswvvQkAPrHBHidFKyku?= =?us-ascii?Q?Y0HFbdRJiNe7rdi4YZ2Pa3ndD/iId0kHgASvMFnWoaHNVshzYCY+BNAMFa91?= =?us-ascii?Q?yRtCisw+L8EA5wP4nF/kK3EMR+rIq9vvSyxSILcb0kAkEdh2AML9X/O4CsMC?= =?us-ascii?Q?5y7ddBe7dKLoo/CRV5rWODaTq0oyOddgAVcdFiSEGZZHZG6xg+0vrzs1GU7J?= =?us-ascii?Q?B5wMnpNMY8b2PlwxHp5t/Ekl+XwU5I1+47TviGgAPA/Pz7od10A9QOB4R5XU?= =?us-ascii?Q?4hG97bBfKu3ldUY/wdfMOhM4vIa23sdXG8sAJS4Q2BeM7i7PbTfQMw8559Dk?= =?us-ascii?Q?TWM9x30zP4l2AUamLSdrqDhJP8wkthFX/pM7+1DOZE0q3kt2CHwrt0fgsJK1?= =?us-ascii?Q?WKe2e0b8icV+nXsfjOc6g7bvkxYc537RQhzezsu0KbTQuaWELVzUt40pnVlc?= =?us-ascii?Q?llcgioX5v1sTzfAB8otMpBJdJ2tgyT+s6FQNff5Itnpl77X5/zJdLQHmpr4V?= =?us-ascii?Q?HE8QPPphonH1TAhOWA12a1vUrjsVyPfV59cIyaq4gL7EP02NSCLPY3OcXYnH?= =?us-ascii?Q?GbRQg/M74dFpbsmHKTaifvAESef5UKLgdHvLNpzVL7uE47g4DZzHL7HFoQMC?= =?us-ascii?Q?EH5KSwEGtMpevw+MgcZ71anope7SQxgFZiyaWnmEzuE0Ktw8hApTHwnbe4QU?= =?us-ascii?Q?UfVwar5jCnhroed+BC30urzWXKt7lYKJSLe/xKgX8nxJJ78Q4gTDma4SNn1A?= =?us-ascii?Q?As0yLHdB+wae3RWw3t19WyzqcxYVYPG644iraTjVkC1VrDTn5u3/frk5YUtN?= =?us-ascii?Q?PkzZj+7cW4dDFI6pGhUnRZBQeZXZ67OzWjLogPucks9nhwhDv0m4yKUNdCau?= =?us-ascii?Q?onrfzVflAD3IajYGpgXDol/Q6NjwWo+h460kEkhfYfe/b6Brs7AUKgH9ZrKT?= =?us-ascii?Q?Ph2Y5irPN2ZLSzBAXC+C7IqcQcoJEMppwoh9eu5tQAIV26UjNmslqTrSjW19?= =?us-ascii?Q?cNr9QOPve+w76sS9GeExZFlKTgJ/MK2/CNZl58JOsLPlc66c6A7oXDg3xCpW?= =?us-ascii?Q?zfMPcSo7v6uT3DHDLyAYYfqJmZtqdk8dFHjEqlGhlAnlouU44gR2R2vopdWr?= =?us-ascii?Q?POpnFFHOviV4+AWtrEegBFspKI1EnDzZPp+pWBTpSUeSy9bKpRf1v+vrc4MF?= =?us-ascii?Q?0y0WpbVXUUI/01Nad4AdV4CybQYvd544c5f/gPOYUpxRPVSs123o6pkEBz4x?= =?us-ascii?Q?Einp2PySH/Vj84PSsIWdZKLKnwegCr731E/L2dEMdX0E62Kgt+UoOAFR/FMy?= =?us-ascii?Q?KqiNMUF7d1epwMzyA0b62Waa76i72m1ygEz9RIsk4Dy0Xz4P/iHXWgh8qtNb?= =?us-ascii?Q?SBrmIExikSvzE3qPtVhdpeJX/qCJFPbntkYu7BFS/yhLnMa4Bcqp+A+cI9d0?= X-MS-Exchange-AntiSpam-MessageData-1: s77mQZj1IJ102g== X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60079dca-eac4-4756-6997-08de72aa1726 X-MS-Exchange-CrossTenant-AuthSource: BLAPR03MB5458.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2026 07:06:39.4894 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fbd72e03-d4a5-4110-adce-614d51f2077a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4U2IurJ6S3VFDpWaUhnGs8IT2S+Os7QFFSoiVhpyHIqFtE6J2llvNc893WUD0lJzCSroWtxLogIZ1eD5QtfjcMlphsk8n+z+d+N7WR4D4iojNQ8GWF8lJ/FDSuuiFuZW6EMuK747w3P+vxECO/0z5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR03MB5767 Content-Type: text/plain; charset="utf-8" In the current implementation, SVC client drivers such as socfpga-hwmon, intel_fcs, stratix10-soc, stratix10-rsu each send an SMC command that triggers a single thread in the stratix10-svc driver. Upon receiving a callback, the initiating client driver sends a stratix10-svc-done signal, terminating the thread without waiting for other pending SMC commands to complete. This leads to a timeout issue in the firmware SVC mailbox service when multiple client drivers send SMC commands concurrently. To resolve this issue, a dedicated thread is now created per channel. The stratix10-svc driver will support up to the number of channels defined by SVC_NUM_CHANNEL. Thread synchronization is handled using a mutex to prevent simultaneous issuance of SMC commands by multiple threads. Additionally, a thread task is now validated before invoking kthread_stop when the user aborts, ensuring safe termination. Timeout values have also been adjusted to accommodate the increased load from concurrent client driver activity. Fixes: 7ca5ce896524 ("firmware: add Intel Stratix10 service layer driver") Cc: stable@vger.kernel.org Signed-off-by: Ang Tien Sung Signed-off-by: Fong, Yan Kei Signed-off-by: Muhammad Amirul Asyraf Mohamad Jamian Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202602032325.MuglZ156-lkp@int= el.com/ --- Changes in v4: - Signed-off-by chain clean up - Remove duplicate inline comment on sdm_lock field - Move structure field comments to structure header - Remove unnecessary checks in stratix10_svc_done() - Fix error handling to properly free FIFOs on probe failure - Reorder error labels for proper cleanup cascade - Remove redundant fifo_size initialization Changes in v3: - Fix grammar: "will supports" -> "will support" - Add Fixes tag and Cc stable as suggested by reviewer Changes in v2: - Initialize 'svc' to NULL and add NULL check in error path to fix uninitia= lized variable warning --- --- drivers/firmware/stratix10-svc.c | 202 +++++++++++------- .../firmware/intel/stratix10-svc-client.h | 8 +- 2 files changed, 131 insertions(+), 79 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index 515b948ff320..77fa8da6ea92 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -37,9 +37,9 @@ * service layer will return error to FPGA manager when timeout occurs, * timeout is set to 30 seconds (30 * 1000) at Intel Stratix10 SoC. */ -#define SVC_NUM_DATA_IN_FIFO 32 +#define SVC_NUM_DATA_IN_FIFO 8 #define SVC_NUM_CHANNEL 4 -#define FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS 200 +#define FPGA_CONFIG_DATA_CLAIM_TIMEOUT_MS 2000 #define FPGA_CONFIG_STATUS_TIMEOUT_SEC 30 #define BYTE_TO_WORD_SIZE 4 =20 @@ -252,11 +252,10 @@ struct stratix10_async_ctrl { * @node: list management * @genpool: memory pool pointing to the memory region * @task: pointer to the thread task which handles SMC or HVC call - * @svc_fifo: a queue for storing service message data * @complete_status: state for completion - * @svc_fifo_lock: protect access to service message data queue * @invoke_fn: function to issue secure monitor call or hypervisor call * @svc: manages the list of client svc drivers + * @sdm_lock: only allows a single command single response to SDM * @actrl: async control structure * * This struct is used to create communication channels for service client= s, to @@ -269,12 +268,10 @@ struct stratix10_svc_controller { int num_active_client; struct list_head node; struct gen_pool *genpool; - struct task_struct *task; - struct kfifo svc_fifo; struct completion complete_status; - spinlock_t svc_fifo_lock; svc_invoke_fn *invoke_fn; struct stratix10_svc *svc; + struct mutex *sdm_lock; struct stratix10_async_ctrl actrl; }; =20 @@ -283,6 +280,9 @@ struct stratix10_svc_controller { * @ctrl: pointer to service controller which is the provider of this chan= nel * @scl: pointer to service client which owns the channel * @name: service client name associated with the channel + * @task: pointer to the thread task which handles SMC or HVC call + * @svc_fifo: a queue for storing service message data (separate fifo for = every channel) + * @svc_fifo_lock: protect access to service message data queue (locking p= ending fifo) * @lock: protect access to the channel * @async_chan: reference to asynchronous channel object for this channel * @@ -293,6 +293,9 @@ struct stratix10_svc_chan { struct stratix10_svc_controller *ctrl; struct stratix10_svc_client *scl; char *name; + struct task_struct *task; + struct kfifo svc_fifo; + spinlock_t svc_fifo_lock; spinlock_t lock; struct stratix10_async_chan *async_chan; }; @@ -527,13 +530,14 @@ static void svc_thread_recv_status_ok(struct stratix1= 0_svc_data *p_data, */ static int svc_normal_to_secure_thread(void *data) { - struct stratix10_svc_controller - *ctrl =3D (struct stratix10_svc_controller *)data; - struct stratix10_svc_data *pdata; - struct stratix10_svc_cb_data *cbdata; + struct stratix10_svc_chan *chan =3D (struct stratix10_svc_chan *)data; + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + struct stratix10_svc_data *pdata =3D NULL; + struct stratix10_svc_cb_data *cbdata =3D NULL; struct arm_smccc_res res; unsigned long a0, a1, a2, a3, a4, a5, a6, a7; int ret_fifo =3D 0; + bool sdm_lock_owned =3D false; =20 pdata =3D kmalloc(sizeof(*pdata), GFP_KERNEL); if (!pdata) @@ -555,12 +559,12 @@ static int svc_normal_to_secure_thread(void *data) a6 =3D 0; a7 =3D 0; =20 - pr_debug("smc_hvc_shm_thread is running\n"); + pr_debug("%s: %s: Thread is running!\n", __func__, chan->name); =20 while (!kthread_should_stop()) { - ret_fifo =3D kfifo_out_spinlocked(&ctrl->svc_fifo, + ret_fifo =3D kfifo_out_spinlocked(&chan->svc_fifo, pdata, sizeof(*pdata), - &ctrl->svc_fifo_lock); + &chan->svc_fifo_lock); =20 if (!ret_fifo) continue; @@ -569,6 +573,16 @@ static int svc_normal_to_secure_thread(void *data) (unsigned int)pdata->paddr, pdata->command, (unsigned int)pdata->size); =20 + /* SDM can only processs one command at a time */ + if (!sdm_lock_owned) { + /* Must not do mutex re-lock */ + pr_debug("%s: %s: Thread is waiting for mutex!\n", + __func__, chan->name); + guard(mutex)(ctrl->sdm_lock); + } + + sdm_lock_owned =3D true; + switch (pdata->command) { case COMMAND_RECONFIG_DATA_CLAIM: svc_thread_cmd_data_claim(ctrl, pdata, cbdata); @@ -702,8 +716,8 @@ static int svc_normal_to_secure_thread(void *data) pr_warn("it shouldn't happen\n"); break; } - pr_debug("%s: before SMC call -- a0=3D0x%016x a1=3D0x%016x", - __func__, + pr_debug("%s: %s: before SMC call -- a0=3D0x%016x a1=3D0x%016x", + __func__, chan->name, (unsigned int)a0, (unsigned int)a1); pr_debug(" a2=3D0x%016x\n", (unsigned int)a2); @@ -712,8 +726,8 @@ static int svc_normal_to_secure_thread(void *data) pr_debug(" a5=3D0x%016x\n", (unsigned int)a5); ctrl->invoke_fn(a0, a1, a2, a3, a4, a5, a6, a7, &res); =20 - pr_debug("%s: after SMC call -- res.a0=3D0x%016x", - __func__, (unsigned int)res.a0); + pr_debug("%s: %s: after SMC call -- res.a0=3D0x%016x", + __func__, chan->name, (unsigned int)res.a0); pr_debug(" res.a1=3D0x%016x, res.a2=3D0x%016x", (unsigned int)res.a1, (unsigned int)res.a2); pr_debug(" res.a3=3D0x%016x\n", (unsigned int)res.a3); @@ -728,6 +742,7 @@ static int svc_normal_to_secure_thread(void *data) cbdata->kaddr2 =3D NULL; cbdata->kaddr3 =3D NULL; pdata->chan->scl->receive_cb(pdata->chan->scl, cbdata); + sdm_lock_owned =3D false; continue; } =20 @@ -1697,21 +1712,21 @@ int stratix10_svc_send(struct stratix10_svc_chan *c= han, void *msg) return -ENOMEM; =20 /* first client will create kernel thread */ - if (!chan->ctrl->task) { - chan->ctrl->task =3D + if (!chan->task) { + chan->task =3D kthread_run_on_cpu(svc_normal_to_secure_thread, - (void *)chan->ctrl, + (void *)chan, cpu, "svc_smc_hvc_thread"); - if (IS_ERR(chan->ctrl->task)) { - dev_err(chan->ctrl->dev, - "failed to create svc_smc_hvc_thread\n"); - kfree(p_data); - return -EINVAL; - } + if (IS_ERR(chan->task)) { + dev_err(chan->ctrl->dev, + "failed to create svc_smc_hvc_thread\n"); + kfree(p_data); + return -EINVAL; + } } =20 - pr_debug("%s: sent P-va=3D%p, P-com=3D%x, P-size=3D%u\n", __func__, - p_msg->payload, p_msg->command, + pr_debug("%s: %s: sent P-va=3D%p, P-com=3D%x, P-size=3D%u\n", __func__, + chan->name, p_msg->payload, p_msg->command, (unsigned int)p_msg->payload_length); =20 if (list_empty(&svc_data_mem)) { @@ -1747,12 +1762,16 @@ int stratix10_svc_send(struct stratix10_svc_chan *c= han, void *msg) p_data->arg[2] =3D p_msg->arg[2]; p_data->size =3D p_msg->payload_length; p_data->chan =3D chan; - pr_debug("%s: put to FIFO pa=3D0x%016x, cmd=3D%x, size=3D%u\n", __func__, - (unsigned int)p_data->paddr, p_data->command, - (unsigned int)p_data->size); - ret =3D kfifo_in_spinlocked(&chan->ctrl->svc_fifo, p_data, + pr_debug("%s: %s: put to FIFO pa=3D0x%016x, cmd=3D%x, size=3D%u\n", + __func__, + chan->name, + (unsigned int)p_data->paddr, + p_data->command, + (unsigned int)p_data->size); + + ret =3D kfifo_in_spinlocked(&chan->svc_fifo, p_data, sizeof(*p_data), - &chan->ctrl->svc_fifo_lock); + &chan->svc_fifo_lock); =20 kfree(p_data); =20 @@ -1773,12 +1792,15 @@ EXPORT_SYMBOL_GPL(stratix10_svc_send); */ void stratix10_svc_done(struct stratix10_svc_chan *chan) { - /* stop thread when thread is running AND only one active client */ - if (chan->ctrl->task && chan->ctrl->num_active_client <=3D 1) { - pr_debug("svc_smc_hvc_shm_thread is stopped\n"); - kthread_stop(chan->ctrl->task); - chan->ctrl->task =3D NULL; + /* stop thread when thread is running */ + if (chan->task) { + pr_debug("%s: %s: svc_smc_hvc_shm_thread is stopping\n", + __func__, chan->name); + kthread_stop(chan->task); + chan->task =3D NULL; } + pr_debug("%s: %s: svc_smc_hvc_shm_thread has stopped\n", + __func__, chan->name); } EXPORT_SYMBOL_GPL(stratix10_svc_done); =20 @@ -1817,8 +1839,8 @@ void *stratix10_svc_allocate_memory(struct stratix10_= svc_chan *chan, pmem->paddr =3D pa; pmem->size =3D s; list_add_tail(&pmem->node, &svc_data_mem); - pr_debug("%s: va=3D%p, pa=3D0x%016x\n", __func__, - pmem->vaddr, (unsigned int)pmem->paddr); + pr_debug("%s: %s: va=3D%p, pa=3D0x%016x\n", __func__, + chan->name, pmem->vaddr, (unsigned int)pmem->paddr); =20 return (void *)va; } @@ -1855,6 +1877,11 @@ static const struct of_device_id stratix10_svc_drv_m= atch[] =3D { {}, }; =20 +/** + * mailbox_lock protects access to the to SDM if thread is busy + */ +static DEFINE_MUTEX(mailbox_lock); + static int stratix10_svc_drv_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -1862,7 +1889,7 @@ static int stratix10_svc_drv_probe(struct platform_de= vice *pdev) struct stratix10_svc_chan *chans; struct gen_pool *genpool; struct stratix10_svc_sh_memory *sh_memory; - struct stratix10_svc *svc; + struct stratix10_svc *svc =3D NULL; =20 svc_invoke_fn *invoke_fn; size_t fifo_size; @@ -1905,7 +1932,6 @@ static int stratix10_svc_drv_probe(struct platform_de= vice *pdev) controller->num_active_client =3D 0; controller->chans =3D chans; controller->genpool =3D genpool; - controller->task =3D NULL; controller->invoke_fn =3D invoke_fn; init_completion(&controller->complete_status); =20 @@ -1917,32 +1943,61 @@ static int stratix10_svc_drv_probe(struct platform_= device *pdev) } =20 fifo_size =3D sizeof(struct stratix10_svc_data) * SVC_NUM_DATA_IN_FIFO; - ret =3D kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL); + ret =3D kfifo_alloc(&chans->svc_fifo, fifo_size, GFP_KERNEL); if (ret) { dev_err(dev, "failed to allocate FIFO\n"); goto err_async_exit; } - spin_lock_init(&controller->svc_fifo_lock); + spin_lock_init(&chans->svc_fifo_lock); + /* + * This mutex is used to block threads from utilizing + * SDM to prevent out of order command tx + */ + controller->sdm_lock =3D &mailbox_lock; =20 chans[0].scl =3D NULL; chans[0].ctrl =3D controller; chans[0].name =3D SVC_CLIENT_FPGA; spin_lock_init(&chans[0].lock); + ret =3D kfifo_alloc(&chans[0].svc_fifo, fifo_size, GFP_KERNEL); + if (ret) { + dev_err(dev, "failed to allocate FIFO 0\n"); + goto err_free_chans_fifo; + } + spin_lock_init(&chans[0].svc_fifo_lock); =20 chans[1].scl =3D NULL; chans[1].ctrl =3D controller; chans[1].name =3D SVC_CLIENT_RSU; spin_lock_init(&chans[1].lock); + ret =3D kfifo_alloc(&chans[1].svc_fifo, fifo_size, GFP_KERNEL); + if (ret) { + dev_err(dev, "failed to allocate FIFO 1\n"); + goto err_free_fifo_fpga; + } + spin_lock_init(&chans[1].svc_fifo_lock); =20 chans[2].scl =3D NULL; chans[2].ctrl =3D controller; chans[2].name =3D SVC_CLIENT_FCS; spin_lock_init(&chans[2].lock); + ret =3D kfifo_alloc(&chans[2].svc_fifo, fifo_size, GFP_KERNEL); + if (ret) { + dev_err(dev, "failed to allocate FIFO 2\n"); + goto err_free_fifo_rsu; + } + spin_lock_init(&chans[2].svc_fifo_lock); =20 chans[3].scl =3D NULL; chans[3].ctrl =3D controller; chans[3].name =3D SVC_CLIENT_HWMON; spin_lock_init(&chans[3].lock); + ret =3D kfifo_alloc(&chans[3].svc_fifo, fifo_size, GFP_KERNEL); + if (ret) { + dev_err(dev, "failed to allocate FIFO 3\n"); + goto err_free_fifo_fcs; + } + spin_lock_init(&chans[3].svc_fifo_lock); =20 list_add_tail(&controller->node, &svc_ctrl); platform_set_drvdata(pdev, controller); @@ -1951,7 +2006,7 @@ static int stratix10_svc_drv_probe(struct platform_de= vice *pdev) svc =3D devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL); if (!svc) { ret =3D -ENOMEM; - goto err_free_kfifo; + goto err_free_fifo_hwmon; } controller->svc =3D svc; =20 @@ -1959,51 +2014,45 @@ static int stratix10_svc_drv_probe(struct platform_= device *pdev) if (!svc->stratix10_svc_rsu) { dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU); ret =3D -ENOMEM; - goto err_free_kfifo; + goto err_free_fifo_hwmon; } =20 ret =3D platform_device_add(svc->stratix10_svc_rsu); - if (ret) { - platform_device_put(svc->stratix10_svc_rsu); - goto err_free_kfifo; - } - - svc->intel_svc_fcs =3D platform_device_alloc(INTEL_FCS, 1); - if (!svc->intel_svc_fcs) { - dev_err(dev, "failed to allocate %s device\n", INTEL_FCS); - ret =3D -ENOMEM; - goto err_unregister_rsu_dev; - } - - ret =3D platform_device_add(svc->intel_svc_fcs); - if (ret) { - platform_device_put(svc->intel_svc_fcs); - goto err_unregister_rsu_dev; - } + if (ret) + goto err_put_device; =20 ret =3D of_platform_default_populate(dev_of_node(dev), NULL, dev); if (ret) - goto err_unregister_fcs_dev; + goto err_put_device; =20 pr_info("Intel Service Layer Driver Initialized\n"); =20 return 0; =20 -err_unregister_fcs_dev: - platform_device_unregister(svc->intel_svc_fcs); -err_unregister_rsu_dev: - platform_device_unregister(svc->stratix10_svc_rsu); -err_free_kfifo: - kfifo_free(&controller->svc_fifo); +err_put_device: + if (svc) + platform_device_put(svc->stratix10_svc_rsu); +err_free_fifo_hwmon: + kfifo_free(&chans[3].svc_fifo); +err_free_fifo_fcs: + kfifo_free(&chans[2].svc_fifo); +err_free_fifo_rsu: + kfifo_free(&chans[1].svc_fifo); +err_free_fifo_fpga: + kfifo_free(&chans[0].svc_fifo); +err_free_chans_fifo: + kfifo_free(&chans->svc_fifo); err_async_exit: stratix10_svc_async_exit(controller); err_destroy_pool: gen_pool_destroy(genpool); + return ret; } =20 static void stratix10_svc_drv_remove(struct platform_device *pdev) { + int i; struct stratix10_svc_controller *ctrl =3D platform_get_drvdata(pdev); struct stratix10_svc *svc =3D ctrl->svc; =20 @@ -2014,11 +2063,14 @@ static void stratix10_svc_drv_remove(struct platfor= m_device *pdev) platform_device_unregister(svc->intel_svc_fcs); platform_device_unregister(svc->stratix10_svc_rsu); =20 - kfifo_free(&ctrl->svc_fifo); - if (ctrl->task) { - kthread_stop(ctrl->task); - ctrl->task =3D NULL; + for (i =3D 0; i < SVC_NUM_CHANNEL; i++) { + if (ctrl->chans[i].task) { + kthread_stop(ctrl->chans[i].task); + ctrl->chans[i].task =3D NULL; + } + kfifo_free(&ctrl->chans[i].svc_fifo); } + if (ctrl->genpool) gen_pool_destroy(ctrl->genpool); list_del(&ctrl->node); diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/= linux/firmware/intel/stratix10-svc-client.h index d290060f4c73..91013161e9db 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -68,12 +68,12 @@ * timeout value used in Stratix10 FPGA manager driver. * timeout value used in RSU driver */ -#define SVC_RECONFIG_REQUEST_TIMEOUT_MS 300 -#define SVC_RECONFIG_BUFFER_TIMEOUT_MS 720 -#define SVC_RSU_REQUEST_TIMEOUT_MS 300 +#define SVC_RECONFIG_REQUEST_TIMEOUT_MS 5000 +#define SVC_RECONFIG_BUFFER_TIMEOUT_MS 5000 +#define SVC_RSU_REQUEST_TIMEOUT_MS 2000 #define SVC_FCS_REQUEST_TIMEOUT_MS 2000 #define SVC_COMPLETED_TIMEOUT_MS 30000 -#define SVC_HWMON_REQUEST_TIMEOUT_MS 300 +#define SVC_HWMON_REQUEST_TIMEOUT_MS 2000 =20 struct stratix10_svc_chan; =20 --=20 2.43.7