From nobody Mon Feb 9 08:30:41 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010030.outbound.protection.outlook.com [52.101.61.30]) (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 A3E891DC1AB for ; Thu, 5 Feb 2026 00:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.30 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770252669; cv=fail; b=RAnX2Khk2MrSapFq2VECM07VA0jmRgY9A4vDF6WCwNgZ2zUYoHNHbFgVkb1ZxXSTTz3h+ErgHrCXqYzJlGP/KGn4a/BApYth53DrHjQSSSU92z5jqOI8XmO7wBpEoW+oPSgP1BPTSWVOim8/MCUg9kG0WDl9AzoIplwoV+Z9u5Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770252669; c=relaxed/simple; bh=cLoeQN57mIvNR9Ex6b5O9+XavYfPQSOotlhSO+6zLyc=; h=From:To:Subject:Date:Message-Id:Content-Type:MIME-Version; b=iL5ugnmEDu/nS8MtPeyDzS2eRWDI0tsWspdpr+EzVsVyqT5gR3RYaojLmrIywmbbms9AAdGb9EJtdLzocR8r1r5xEWZETf7BxOcCS+uoIDI6RSMLBNmEeaszMKkQ/OYLhsun8WIRXNPp5h1EtxD31lVh6B+WWrP8Pwc8V2D15Kg= 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=aips7QtR; arc=fail smtp.client-ip=52.101.61.30 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="aips7QtR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uZLMfcdwOQNipmqAlyH0okXVal5Jo4ioffSAPGNvJjiitI4TBki1iNW3eXIY96mJadTLwrEv6t/JMUZ3BiMiKuUW+Z5BZ2+4t83/FHKOKd/C2e7I3L+fIOpc0eVD3cIj34MapZ1QoY8fjZxCtxOlX/56Hv5ampoYdkmGTosKTIgCiDpB98tbtC1U2EJiyFLkeWqS8ZRI/6gyS+SRLtdDjuupiJg3MNqFo+YLRXqCz0ojp+Og/kaf/hk3kQymk78fj6pOuA4v/YE6AKalTyuvrgFxwJN0dEIFXYlUb5TsT5MePNNvJd4x5hBUOmyCKH1WzHwokDY0GLONknIsYDskSA== 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=vhP7JYOypEYUGPNMo6N50GUZ0mr09KbTO/1lIexGK2I=; b=hARrSBsMCN8Zao8+fyjAyhnsODZRWlhhADjssgK4hEoli0zR0Vp26F7Oyuz0FvRGFRhbdce0JFdG9t9MhDeJKlG6ZBcw/S1A3lLI7XdOJv1wqnF9bLqp/HcbFKkWhOdq+hfpQg+t/z2sMPYy5SbuBQpHOCtkNj9IZAOBtKrZLrwv9+RkfJakZX3rELrGK/eCq1oRqioW/uKpxKHX7N9emjsJnVO06g19BQP8Krl/QpXZbHPbG/eh9Zt48QBPc66kElec0dSFLWlILz435Xkr9QESS+LsAm+saIEsUvjLeoEU3iaRdQ5iK8gFEUVy2ESxj/M2+w2A+q/gaPrAnH8xXQ== 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=vhP7JYOypEYUGPNMo6N50GUZ0mr09KbTO/1lIexGK2I=; b=aips7QtRlUPJqnc9JynTnX4U5quOe78KGzJCkoQw/Ncc71PAUg9dZKmm1jE/tBkJ2jRyOXZP10BnrwgNdV8MO/VlhOzqPGCVr8oQNPwoQ63ccoQulvoXfFnUqmPIaP7k15bFR1kXMpz8cjSysbcWm8AQxduMrRFTCKTLm5fjb1aBhusKU0ItFmByMmGkcmrDCvFMQDf2g/XzGNfCjsVv20JxyPPsyzvQfsu1K++3VIftJ3u202V2d5TpZu9AOb4yWg12y1+m/nh9KO/kgJK+Z9AOv1iV26ErV/cLpnCjwUXvjxBoWvn5IZNeo0tlRyAUUn9zo9YFdQ0z0kyn8EzP1Q== 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 BLAPR03MB5618.namprd03.prod.outlook.com (2603:10b6:208:294::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9587.13; Thu, 5 Feb 2026 00:51:06 +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.9587.013; Thu, 5 Feb 2026 00:51:05 +0000 From: Muhammad Amirul Asyraf Mohamad Jamian To: Dinh Nguyen , linux-kernel@vger.kernel.org, Ang Tien Sung Subject: [PATCH v2] firmware: stratix10-svc: Add Multi SVC clients support Date: Wed, 4 Feb 2026 16:51:02 -0800 Message-Id: <20260205005102.22108-1-muhammadamirulasyraf.mohamadjamian@altera.com> X-Mailer: git-send-email 2.26.2 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BYAPR21CA0029.namprd21.prod.outlook.com (2603:10b6:a03:114::39) 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_|BLAPR03MB5618:EE_ X-MS-Office365-Filtering-Correlation-Id: 4499c4ab-ab39-459f-3298-08de6450a453 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?FJ5KmI6oXiBgj2lzPtFiWLT4Pw5qoz/3SB+q/5GoPNXJ98xhJmHe13kYFEVa?= =?us-ascii?Q?TR/bj1STikODyhBXyAhd1QWI/Py5DFTzqfD6rW21ciyL2paTVdT4natFdED3?= =?us-ascii?Q?QDmoUFy5zNMHouQ2B5726T5Imn+c9g3h8vc2no8iRytLxFdl1ulExTe5Aiz6?= =?us-ascii?Q?YrtHa7s3MIs3GoBHqfUofkOrfsaJwUdhKn852Fs/Y9AFYNZEcsIU0vWnH4cv?= =?us-ascii?Q?E9yP61X/K1I0i2ja8wEzfzY1Fk+w3KbsewSVDAsopquaGghulXxGarJhrZVD?= =?us-ascii?Q?kNti7FaNaFXxkIFvFR1/SAa/zRgPCKfyXBWVmz3i88jmWetY1DBXw/Hy8rcx?= =?us-ascii?Q?ZQITclgRDkOUXfTCPSscw+V4Gkm1ukkdcPH4GVbIF++0aanKF0lopl2vdUN7?= =?us-ascii?Q?zRbY1NwXVgAkHxh4eV4i/LXd7ck6l8EGC5XcEO+mMYw9uHpd2R8fHhyQA8o+?= =?us-ascii?Q?kQmEoMpLe4FzkuGFOri01EZg7oE2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?= =?us-ascii?Q?OerjTF+7kEODiuqdVbV062BqUXYx77ag1yi3GxhRfmXZ7EqQeTAz3zJ/OJcn?= =?us-ascii?Q?nim9DP+G5fT8zqhCtQg9hGdYA/LK3bBAOJdCQgtsw5DY1jmoxlbiwtmBZjJZ?= =?us-ascii?Q?fpdoRQLXVr7/UaFeE0V9or9lSOG10wCOqbQP4cfUY06edWV82tGlRLl2e2+J?= =?us-ascii?Q?UOaVj3uQKPG+X4pczKMNBrjfbMNsJkiqfdlp/hXT?= 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?P1lUExvAHt3TSfCwa+6whWDzXZmXzhSQ3qtwXOjzNXsi/PUkqJN1xFFWFfbH?= =?us-ascii?Q?NWeeViib5Uws42PC0H7TUX+RVqOXtcHCwmgGyeJL6fXV02fbd3lb2Qpv3OtT?= =?us-ascii?Q?m+vaxzQVL9aKXlBT8dLJjFNu51mPl6xouUyMsm+A4HdoioDxBugJRkV20G13?= =?us-ascii?Q?0qlOltDtAZJgIM8y3cHnqF2Svr3hLhKaf7TU0gCiU8W8zMutDhHuGOqk1++s?= =?us-ascii?Q?egFDueb9MR4o1qRWAb3gMKNzxiSsmhzjRNAVZyb9FvKIo+tcMObh1sMjWdUF?= =?us-ascii?Q?vuBrlIyyoX4KsDZVPFJM9MohAUDODsxalhCNR5olqJ2gqHanCEt+jGKtlTdP?= =?us-ascii?Q?zLfrjYtgBJQk/4ClR1OAvVC1KG101qZPm/LaTs5O7Qkink24HSSylMzlUODG?= =?us-ascii?Q?vqdpfyyYoO9iiCXbKl0MZNDwUZVnrludYScW+ex+WD2j8DQHQq+SPZGwFLiu?= =?us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xDf2BOqEsaQtOsg/nkWk+ebXnySogyw?= =?us-ascii?Q?HQoJMXslzMBpioIEx18/g8lW6e5IPZCbuMLW/6Dqe3cbqVGk0a3buyFUvrez?= =?us-ascii?Q?MmhrG9mwsgH7djTqQOz1zTlovXMC1WTJlNcjH+U4DDxz07uyiLb7xbLnxtMu?= =?us-ascii?Q?sRWmyTHJ5HncrDMEtSkGlIUUp+dwIxS/jn/yLqlFPR+b/toFqaZ2jQVkmNpk?= =?us-ascii?Q?/Z1Inm3aL1uB/JCas98FiLXYcUU2mMqXLuTXhVpRqw9q2XkghqaNTPMteNM5?= =?us-ascii?Q?sht3eohRUxPLnn9LUWCnloYZWIDPR6MdqeeYlzDMX1S3hjwm8sfH/szDh5g5?= =?us-ascii?Q?ByQWRptpgaB/UFu6fYHrv/JuqZaUKCRtFsr711w66Y/GS/+89XiUi2mXeyRv?= =?us-ascii?Q?PZ+boVQCMnL4axhn82Ru66nOwcEMgUig5nVpdXMujfxlQIx13JmX/sGRlx4x?= X-MS-Exchange-AntiSpam-MessageData-1: Q4mmto9HC6e+Pg== X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4499c4ab-ab39-459f-3298-08de6450a453 X-MS-Exchange-CrossTenant-AuthSource: BLAPR03MB5458.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2026 00:51:05.6142 (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: xqohgsxz7nsi8wttth+u54zaqMWgKAuT+R36pkV9gmpPn5a9oeLtSStcm4aBrwls/EofDrJFdKcBdw8KxkXaVREmZG4QFf59KmSYWZ8SR4MpauqK1vtZUz4t5XkmbMpdJQFvEkf0DPJzUUHgo9+G0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR03MB5618 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 supports 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. Signed-off-by: Ang Tien Sung Signed-off-by: Fong, Yan Kei Signed-off-by: Khairul Anuar Romli 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 v2: - Initialize 'svc' to NULL and add NULL check in error path to fix uninitia= lized variable warning --- drivers/firmware/stratix10-svc.c | 203 +++++++++++------- .../firmware/intel/stratix10-svc-client.h | 8 +- 2 files changed, 130 insertions(+), 81 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index 515b948ff320..eb37e2813860 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; /* Protect SDM transaction until response */ 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 + * @svc_fifo_lock: protect access to service message data queue * @lock: protect access to the channel * @async_chan: reference to asynchronous channel object for this channel * @@ -293,6 +293,10 @@ struct stratix10_svc_chan { struct stratix10_svc_controller *ctrl; struct stratix10_svc_client *scl; char *name; + struct task_struct *task; + /* Separate fifo for every channel */ + struct kfifo svc_fifo; + spinlock_t svc_fifo_lock; /* locking pending fifo */ spinlock_t lock; struct stratix10_async_chan *async_chan; }; @@ -527,13 +531,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 +560,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 +574,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 +717,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 +727,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 +743,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 +1713,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 +1763,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 +1793,21 @@ 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) { + if (!IS_ERR(chan->task)) { + struct task_struct *task_to_stop =3D chan->task; + + chan->task =3D NULL; + pr_debug("%s: %s: svc_smc_hvc_shm_thread is stopping\n", + __func__, chan->name); + kthread_stop(task_to_stop); + } + + 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 +1846,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 +1884,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 +1896,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 +1939,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 +1950,63 @@ 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; + + fifo_size =3D sizeof(struct stratix10_svc_data) * SVC_NUM_DATA_IN_FIFO; =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"); + return ret; + } + 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"); + return ret; + } + 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"); + return ret; + } + 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"); + return ret; + } + spin_lock_init(&chans[3].svc_fifo_lock); =20 list_add_tail(&controller->node, &svc_ctrl); platform_set_drvdata(pdev, controller); @@ -1950,60 +2014,42 @@ static int stratix10_svc_drv_probe(struct platform_= device *pdev) /* add svc client device(s) */ svc =3D devm_kzalloc(dev, sizeof(*svc), GFP_KERNEL); if (!svc) { - ret =3D -ENOMEM; - goto err_free_kfifo; + return -ENOMEM; } controller->svc =3D svc; =20 svc->stratix10_svc_rsu =3D platform_device_alloc(STRATIX10_RSU, 0); if (!svc->stratix10_svc_rsu) { dev_err(dev, "failed to allocate %s device\n", STRATIX10_RSU); - ret =3D -ENOMEM; - goto err_free_kfifo; + return -ENOMEM; } =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_async_exit: stratix10_svc_async_exit(controller); +err_put_device: + if (svc) + platform_device_put(svc->stratix10_svc_rsu); 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 +2060,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