From nobody Tue Oct 7 18:27:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2761021767D; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; cv=none; b=VYAtyVpnTVMuvqMFSgzEe4TBaTe0L2bA5Z5NBGeIKVSUUvVy/wJOL03ubEwd3KRiSWkw6Yg51ZoZ7tZnXiHlOxFNPPvyNaWUK7uY/akLLmN7Ex/fKnkpOcQ12gEm8cES7p0x/r9jmI7OmmcZenznodFECWrcf4z5uhvcnM0IsAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; c=relaxed/simple; bh=9lgdtjlJsTHXMEL0blCsq/7tTtWLs7jUyFt4YWViNtI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=udRbJ9RW9dtZQ4BBPLQh3HLlo0xS30tsbB6FP2Itzw2/BWa0wQsMBLoMFAp1VlY1hqwRZ2Sf8ySYth0WMroJdvIkHbvxeJERgVtq4LnF7RMFZyqKCBNgUmNOpeYhLO4SFQDlOUXtxWNcM+YPenB/AsC9+UEdM4K649DPE5Mk4WI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dqbKuWzF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dqbKuWzF" Received: by smtp.kernel.org (Postfix) with ESMTPS id B1A2EC4CEED; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751950195; bh=9lgdtjlJsTHXMEL0blCsq/7tTtWLs7jUyFt4YWViNtI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dqbKuWzFC41kWPPNTE1SP64nTqdqUJv53241JCBfvN7sedliVAhRu1v5UVcrLqQWs l1J/xh02m55Qh52xOBCErEKsyh+lF3A7+exsNAXGuG2hC4IhMJKCofRBC1p7G0R0c8 egLFwjjr6g+FflB44SQYE7QYVxZhWxAkkAPCgfIvjqBd3qZvA2RWHJjppvxRUzOzzi IDvIdvXZ1qr7VhDJ8gsKFU4DB/rjdLl+bdMPqebvX0LGZps7UqJs7sXI2K8nUORYiJ tT3C9IQRaF64fJxnvR3IfseXwzQXk+sa7fbaZoh1Fq+PtumyUcs/YkXb5RR2s2jqeA 7UAdjYR8ZWzMQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3168C71130; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Tue, 08 Jul 2025 12:49:06 +0800 Subject: [PATCH RESEND v5 1/5] firmware: stratix10-svc: Add mutex lock and unlock in stratix10 memory allocation/free Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-sip_svc_upstream-v5-1-9c4289256d54@altera.com> References: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> In-Reply-To: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751950193; l=3746; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=QE+KovkU/XowK2W0xahzC8La4au8qJPO8bMmVQGHmLo=; b=61oPSdmYsY/8RATt+14R6rcBykTqR8UdMsydWoda4X7BXa25/JrzB/ghi1/GnXjnKt1sQzXhM 6yKW0XS5Q8LC4DC3HWpgGFFdb6Blyd6y+SmR4WCx9XbKsXONVqLwlbq X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao This commit adds a mutex lock to protect the stratix10_svc_allocate_memory and stratix10_svc_free_memory functions to ensure thread safety when allocating and freeing memory. This prevents potential race conditions and ensures synchronization. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index e3f990d888d71829f0ab22b8a59aa7af0316bea0..73c77b8e9f2b44a6729dd349ef0= 947ed47be681b 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2017-2018, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #include @@ -171,6 +172,10 @@ struct stratix10_svc_chan { =20 static LIST_HEAD(svc_ctrl); static LIST_HEAD(svc_data_mem); +/* svc_mem_lock protects access to the svc_data_mem list for + * concurrent multi-client operations + */ +static DEFINE_MUTEX(svc_mem_lock); =20 /** * svc_pa_to_va() - translate physical address to virtual address @@ -182,14 +187,18 @@ static LIST_HEAD(svc_data_mem); static void *svc_pa_to_va(unsigned long addr) { struct stratix10_svc_data_mem *pmem; + void *ret =3D NULL; =20 pr_debug("claim back P-addr=3D0x%016x\n", (unsigned int)addr); + mutex_lock(&svc_mem_lock); list_for_each_entry(pmem, &svc_data_mem, node) - if (pmem->paddr =3D=3D addr) - return pmem->vaddr; - - /* physical address is not found */ - return NULL; + if (pmem->paddr =3D=3D addr) { + /* physical address is found */ + ret =3D pmem->vaddr; + break; + } + mutex_unlock(&svc_mem_lock); + return ret; } =20 /** @@ -990,6 +999,7 @@ int stratix10_svc_send(struct stratix10_svc_chan *chan,= void *msg) p_data->flag =3D ct->flags; } } else { + mutex_lock(&svc_mem_lock); list_for_each_entry(p_mem, &svc_data_mem, node) if (p_mem->vaddr =3D=3D p_msg->payload) { p_data->paddr =3D p_mem->paddr; @@ -1006,6 +1016,7 @@ int stratix10_svc_send(struct stratix10_svc_chan *cha= n, void *msg) break; } } + mutex_unlock(&svc_mem_lock); } =20 p_data->command =3D p_msg->command; @@ -1072,9 +1083,12 @@ void *stratix10_svc_allocate_memory(struct stratix10= _svc_chan *chan, if (!pmem) return ERR_PTR(-ENOMEM); =20 + mutex_lock(&svc_mem_lock); va =3D gen_pool_alloc(genpool, s); - if (!va) + if (!va) { + mutex_unlock(&svc_mem_lock); return ERR_PTR(-ENOMEM); + } =20 memset((void *)va, 0, s); pa =3D gen_pool_virt_to_phys(genpool, va); @@ -1086,6 +1100,7 @@ void *stratix10_svc_allocate_memory(struct stratix10_= svc_chan *chan, pr_debug("%s: va=3D%p, pa=3D0x%016x\n", __func__, pmem->vaddr, (unsigned int)pmem->paddr); =20 + mutex_unlock(&svc_mem_lock); return (void *)va; } EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory); @@ -1100,6 +1115,7 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory); void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kadd= r) { struct stratix10_svc_data_mem *pmem; + mutex_lock(&svc_mem_lock); =20 list_for_each_entry(pmem, &svc_data_mem, node) if (pmem->vaddr =3D=3D kaddr) { @@ -1107,9 +1123,10 @@ void stratix10_svc_free_memory(struct stratix10_svc_= chan *chan, void *kaddr) (unsigned long)kaddr, pmem->size); pmem->vaddr =3D NULL; list_del(&pmem->node); + mutex_unlock(&svc_mem_lock); return; } - + mutex_unlock(&svc_mem_lock); list_del(&svc_data_mem); } EXPORT_SYMBOL_GPL(stratix10_svc_free_memory); --=20 2.35.3 From nobody Tue Oct 7 18:27:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 34A05218821; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; cv=none; b=DPHd/5I7sITCM8uvWazGNKGr8lZ60Hu6qwOWvH434Doscz6PMj+2enF+SC9mg5nSGD3Ecj0Xl/3xLYkuBQRjlMP+/wOrwjVb5NBWp1JnFvi1hbV7DAWPBlsNikaN3M8gBcavC7MnnowkOvByPLaQSZvT16HwW9dOAjaMXei2rk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; c=relaxed/simple; bh=lBthyPAfKhHtbhMUBAuoaz/8Tw5PYAJ1Odx6iC5j3ns=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P0Aa3wMPodN63GWhyKv1j+aVTBmQPilbzrWzpj1EsYmU90+ugh5NawB6SGpSQ4h1xXkAxccxgg0inlLMROc1XzjztRzVYg+q46nrz3fQM0axfV2qaOVqGlkGmmFxN3m6GyCAXsL/LU1q6L1jm5asMKwV16dAM5kLBvYvRzf5KCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mWiuw0dq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mWiuw0dq" Received: by smtp.kernel.org (Postfix) with ESMTPS id BDA02C4CEF0; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751950195; bh=lBthyPAfKhHtbhMUBAuoaz/8Tw5PYAJ1Odx6iC5j3ns=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mWiuw0dqGTuR6DzY5sOLlvskm9m2j8635xdOkyxPZErFrRZmtXWB2TlNzLz8QecfI Tw4Zlc8L94On6ZTWETY1hnvVmZQG+/wlM1OVk4BBz3MzU7QzHVCo84gvFTiJM8Rkgp BWmzoRsgLFahc6vIwqKaFh8AyGFENDSUZ71/T1F/E19/F9V0FocBFoU+0KxTKigqR+ jnG9MvG2opK/KXpmUF9LGfK+Xe3grU+hqTid26VLuQCgI5WDIeVeh0YKRxLSCMDfO+ 3tNdfuXmINXDCQIH+rm2ZLoXFocESZpv9AcwIoBf9kKeEZIwTac0bEkOu0BnTEouDA lRy8XJwUYLEiw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFE94C83F0D; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Tue, 08 Jul 2025 12:49:07 +0800 Subject: [PATCH RESEND v5 2/5] firmware: stratix10-svc: Implement ID pool management for asynchronous operations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-sip_svc_upstream-v5-2-9c4289256d54@altera.com> References: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> In-Reply-To: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751950193; l=6320; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=n18tKLs7MLh8G8eEquC0bpSpqdEDws81zjcXK5xIQgg=; b=RgKbq92m4gtHYTuVFyPGfyDCUjR+X43gsEi6VVxPT5jkwafMyFM2W0YDyDy91nbY0m+Fpd+Vn VKQZcqFLjJHCQdUb9v7KWob0M1b9upE/Ba8HnPzBb/XbZI5XguzXx4o X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Implement ID pool management API's which will be used for Stratix10 Asynchronous communication with Secure Device Manager. These API's will be used in subsequent patches for ID management in asynchronous operations. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 194 +++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 194 insertions(+) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index 73c77b8e9f2b44a6729dd349ef0947ed47be681b..a8c57963da993a3d6207dbf8026= 33bc82006ada7 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -170,6 +170,21 @@ struct stratix10_svc_chan { spinlock_t lock; }; =20 +/** + * struct stratix10_sip_id_pool - Structure representing a pool of IDs for + * asynchronous operations. + * @head: The head index of the ID pool. + * @size: The total size of the ID pool. + * @id_mask: Pointer to an array representing the mask of allocated I= Ds. + * @lock: Mutex lock to protect access to the ID pool. + */ +struct stratix10_sip_id_pool { + unsigned long head; + unsigned long size; + unsigned long *id_mask; + struct mutex lock; +}; + static LIST_HEAD(svc_ctrl); static LIST_HEAD(svc_data_mem); /* svc_mem_lock protects access to the svc_data_mem list for @@ -177,6 +192,185 @@ static LIST_HEAD(svc_data_mem); */ static DEFINE_MUTEX(svc_mem_lock); =20 +/** + * stratix10_id_pool_create - Create a new ID pool for Stratix10 + * async operation + * @size: The size of the ID pool to create + * + * This function allocates and initializes a new ID pool structure + * for Stratix10 async operations. It allocates memory for the ID + * pool structure and the associated bitmaps for ID management. + * + * Return: Pointer to the newly created ID pool structure, or NULL + * on failure. + */ +static struct stratix10_sip_id_pool *stratix10_id_pool_create(unsigned lon= g size) +{ + struct stratix10_sip_id_pool *id_pool =3D NULL; + + if (size =3D=3D 0) + return NULL; + + id_pool =3D kzalloc(sizeof(*id_pool), GFP_KERNEL); + if (!id_pool) + return NULL; + + id_pool->size =3D size; + + id_pool->id_mask =3D bitmap_zalloc(size, GFP_KERNEL); + if (!id_pool->id_mask) { + kfree(id_pool); + return NULL; + } + + mutex_init(&id_pool->lock); + + return id_pool; +} + +/** + * stratix10_id_pool_destroy - Destroy an ID pool for Stratix10 async oper= ation + * @id_pool: Pointer to the ID pool structure + * + * This function destroys an ID pool for Stratix10 async operations. It fi= rst + * checks if the ID pool is valid, then frees the associated bitmap and the + * ID pool structure itself. + * + * Return: 0 on success, -EINVAL if the ID pool is invalid. + */ +static int stratix10_id_pool_destroy(struct stratix10_sip_id_pool *id_pool) +{ + if (!id_pool) + return -EINVAL; + + mutex_lock(&id_pool->lock); + + if (id_pool->id_mask) + bitmap_free(id_pool->id_mask); + + mutex_unlock(&id_pool->lock); + mutex_destroy(&id_pool->lock); + + kfree(id_pool); + + return 0; +} + +/** + * stratix10_reserve_id - Reserve an ID in the ID pool + * @id_pool: Pointer to the ID pool structure + * @id: The ID to be reserved + * + * This function reserves an ID in the given ID pool. It first checks if + * the ID pool is valid and if the ID is within the valid range. + * + * Return: + * 0 on success, + * -EINVAL if the ID pool is invalid, the ID is out of range, or the ID is + * already reserved. + */ +static int stratix10_reserve_id(struct stratix10_sip_id_pool *id_pool, uns= igned long id) +{ + if (!id_pool) + return -EINVAL; + + if (id >=3D id_pool->size) + return -EINVAL; + + mutex_lock(&id_pool->lock); + + if (test_bit(id, id_pool->id_mask)) { + mutex_unlock(&id_pool->lock); + return -EINVAL; + } + set_bit(id, id_pool->id_mask); + + mutex_unlock(&id_pool->lock); + return 0; +} + +/** + * stratix10_allocate_id - Allocate an ID from the ID pool + * @id_pool: Pointer to the ID pool structure + * + * This function allocates an ID from the given ID pool. It searches for + * the next available ID in the pool, marks it as allocated, + * and returns it. + * + * Return: + * A non-negative integer representing the allocated ID on success + * -EINVAL if the id_pool is NULL + * -ENOMEM if no IDs are available in the pool + */ +static int stratix10_allocate_id(struct stratix10_sip_id_pool *id_pool) +{ + unsigned long tries =3D 0; + int id; + + if (!id_pool) + return -EINVAL; + + if (id_pool->head >=3D id_pool->size) + return -ENOMEM; + + mutex_lock(&id_pool->lock); + + do { + id_pool->head =3D find_next_zero_bit(id_pool->id_mask, + id_pool->size, id_pool->head); + if (id_pool->head >=3D id_pool->size) { + id_pool->head =3D 0; + tries++; + } + /* cycle through the whole bitmap at least once*/ + } while (tries < 2 && test_bit(id_pool->head, id_pool->id_mask)); + + if (tries >=3D 2) { + mutex_unlock(&id_pool->lock); + return -ENOMEM; + } + + set_bit(id_pool->head, id_pool->id_mask); + id =3D id_pool->head; + id_pool->head =3D (id_pool->head + 1) % id_pool->size; + mutex_unlock(&id_pool->lock); + return id; +} + +/** + * stratix10_deallocate_id - Deallocate an ID in the ID pool + * @id_pool: Pointer to the ID pool structure + * @id: The ID to be deallocated + * + * This function deallocates an ID in the given ID pool. It first + * checks if the ID pool is valid and if the ID is within the valid + * range. + * + * Return: + * 0 on success, + * -EINVAL if the ID pool is invalid, the ID is out of range, or the + * ID is not set. + */ +static int stratix10_deallocate_id(struct stratix10_sip_id_pool *id_pool, = unsigned long id) +{ + int ret =3D -EINVAL; + + if (!id_pool) + return ret; + + if (id >=3D id_pool->size) + return ret; + + mutex_lock(&id_pool->lock); + if (test_bit(id, id_pool->id_mask)) { + clear_bit(id, id_pool->id_mask); + ret =3D 0; + } + mutex_unlock(&id_pool->lock); + + return ret; +} + /** * svc_pa_to_va() - translate physical address to virtual address * @addr: to be translated physical address --=20 2.35.3 From nobody Tue Oct 7 18:27:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 00E311F790F; Tue, 8 Jul 2025 04:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; cv=none; b=K7rPFcX5HoAtNfM0w7VHFt81iuW61/j4LmP1mLu4qpL3wSjQhVPpZ9ig5tXinAMIBBV4ko5kFZkubkm4oibkzyBMSuX8feSboRhqPg12XCSPzf44E0GUBFqBYJjgtp9eLf5VhVTgd30kAt1GEIzbRtbrmtIqFRu+z/ZyclpmWsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; c=relaxed/simple; bh=0s+ZJhYG3WJL9gm9IuOR3KxQSb1JkECdslzKLBXyRw8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FNHN6mzdU3w8Mi+xbko7p+779oOQcj9ewTyNS+hNS4uXZPs8irqkydrCrjY50x155XC6KIlqq+oJYxOBP4NNN9IWHpsn1+eapIBrUmzbWwME3Um/L5qmjDh8qS25q6oQjlClscTKzgBNCKmLeuG0/8p9WKWSTGQOatRV0NrMdQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nu7c1sZO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Nu7c1sZO" Received: by smtp.kernel.org (Postfix) with ESMTPS id C900DC4CEFA; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751950195; bh=0s+ZJhYG3WJL9gm9IuOR3KxQSb1JkECdslzKLBXyRw8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Nu7c1sZO0nNtb9LiajtfffzxsJ5sQN51wgZZP6NE1nmW3G65YTo/WuJBN94qUkHFF IjSRO7mbypq8/YkLMgrifKPWmAsiYTODzDMP3Hjfr1ldkujO3nMsWMYILrWyHVkCif /j7xEYRq3ush+eZ/xL2N2Q00f97obcaAZHrgQHwgCBXkfDr/BvpMnfnSwle0ojPkyi t6Z8rc+ukfK8ttuDzJkRhUUm+yVqvngXZTs00Y9XP3tQA7XWSWAIIhL1HirE8Wi4tV 4KUuJWDKd86128fhdhAhe4ykBCKuQLXaRE5WlW0wOV0P96vJTJ3VlUHDYmy8pCuCA6 vQtykUKaIHUQg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE6F3C83F0A; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Tue, 08 Jul 2025 12:49:08 +0800 Subject: [PATCH RESEND v5 3/5] firmware: stratix10-svc: Add initial support for asynchronous communication with Stratix10 service channel Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-sip_svc_upstream-v5-3-9c4289256d54@altera.com> References: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> In-Reply-To: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751950193; l=34330; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=vdVM+qSBOCjWK864w8ZqQuHMSRRtxBDFTuDCsRuQtac=; b=cSSSmHce0zuvCWN6KfPHXycv9TsijR2vxJiLYHk9TtdrpO3aeswjQhDsQzab5MZcX0Ybuir4o H2ztbVpE0KBBHBKyDsdsSQYg/9HD6twsgg2wEYkzuqUlGWAsnP+av0R X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Introduce support for asynchronous communication with the Stratix10 service channel. Define new structures to enable asynchronous messaging with the Secure Device Manager (SDM). Add and remove asynchronous support for existing channels. Implement initialization and cleanup routines for the asynchronous framework. Enable sending and polling of messages to the SDM asynchronously. The new public functions added are: - stratix10_svc_add_async_client: Adds an client to the service channel. - stratix10_svc_remove_async_client: Removes an asynchronous client from the service channel. - stratix10_svc_async_send: Sends an asynchronous message to the SDM mailbox in EL3 secure firmware. - stratix10_svc_async_poll: Polls the status of an asynchronous service request in EL3 secure firmware. - stratix10_svc_async_done: Marks an asynchronous transaction as complete and free's up the resources. These changes enhance the functionality of the Stratix10 service channel by allowing for more efficient and flexible communication with the firmware. Signed-off-by: Mahesh Rao Reviewed-by: Matthew Gerlach --- drivers/firmware/stratix10-svc.c | 657 +++++++++++++++++= +++- include/linux/firmware/intel/stratix10-smc.h | 24 + .../linux/firmware/intel/stratix10-svc-client.h | 88 +++ 3 files changed, 765 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index a8c57963da993a3d6207dbf802633bc82006ada7..4480ba8b2e115809103f3632906= ac81e4fb8a63a 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -4,9 +4,11 @@ * Copyright (C) 2025, Altera Corporation */ =20 +#include #include #include #include +#include #include #include #include @@ -44,6 +46,47 @@ #define STRATIX10_RSU "stratix10-rsu" #define INTEL_FCS "intel-fcs" =20 +/*Maximum number of SDM client IDs.*/ +#define MAX_SDM_CLIENT_IDS 16 +/*Client ID for SIP Service Version 1.*/ +#define SIP_SVC_V1_CLIENT_ID 0x1 +/*Maximum number of SDM job IDs.*/ +#define MAX_SDM_JOB_IDS 16 +/*Number of bits used for asynchronous transaction hashing.*/ +#define ASYNC_TRX_HASH_BITS 3 +/* Total number of transaction IDs, which is a combination of + * client ID and job ID. + */ +#define TOTAL_TRANSACTION_IDS (MAX_SDM_CLIENT_IDS * MAX_SDM_JOB_IDS) + +/*Minimum major version of the ATF for Asynchronous transactions.*/ +#define ASYNC_ATF_MINIMUM_MAJOR_VERSION 0x3 +/*Minimum minor version of the ATF for Asynchronous transactions.*/ +#define ASYNC_ATF_MINIMUM_MINOR_VERSION 0x0 + +/* Job ID field in the transaction ID */ +#define STRATIX10_JOB_FIELD GENMASK(3, 0) +/* Client ID field in the transaction ID */ +#define STRATIX10_CLIENT_FIELD GENMASK(7, 4) +/* Transaction ID mask for Stratix10 service layer */ +#define STRATIX10_TRANS_ID_FIELD GENMASK(7, 0) + +/*Macro to extract the job ID from a transaction ID.*/ +#define STRATIX10_GET_JOBID(transaction_id) \ + (FIELD_GET(STRATIX10_JOB_FIELD, transaction_id)) +/*Macro to set the job ID in a transaction ID.*/ +#define STRATIX10_SET_JOBID(jobid) \ + (FIELD_PREP(STRATIX10_JOB_FIELD, jobid)) +/*Macro to set the client ID in a transaction ID.*/ +#define STRATIX10_SET_CLIENTID(clientid) \ + (FIELD_PREP(STRATIX10_CLIENT_FIELD, clientid)) +/*Macro to set a transaction ID using a client ID and a job ID.*/ +#define STRATIX10_SET_TRANSACTIONID(clientid, jobid) \ + (STRATIX10_SET_CLIENTID(clientid) | STRATIX10_SET_JOBID(jobid)) +/* Macro to set a transaction ID for SIP SMC Async transactions */ +#define STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(transaction_id) \ + (FIELD_PREP(STRATIX10_TRANS_ID_FIELD, transaction_id)) + typedef void (svc_invoke_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, @@ -64,7 +107,7 @@ struct stratix10_svc { * @sync_complete: state for a completion * @addr: physical address of shared memory block * @size: size of shared memory block - * @invoke_fn: function to issue secure monitor or hypervisor call + * @invoke_fn: service clients to handle secure monitor or hypervisor calls * * This struct is used to save physical address and size of shared memory * block. The shared memory blocked is allocated by secure monitor software @@ -122,6 +165,74 @@ struct stratix10_svc_data { u64 arg[3]; }; =20 +/** + * struct stratix10_svc_async_handler - Asynchronous handler for Stratix10 + * service layer + * @transaction_id: Unique identifier for the transaction + * @achan: Pointer to the asynchronous channel structure + * @cb_arg: Argument to be passed to the callback function + * @cb: Callback function to be called upon completion + * @msg: Pointer to the client message structure + * @next: Node in the hash list + * @res: Response structure to store result from the secure firmware + * + * This structure is used to handle asynchronous transactions in the + * Stratix10 service layer. It maintains the necessary information + * for processing and completing asynchronous requests. + */ + +struct stratix10_svc_async_handler { + u8 transaction_id; + struct stratix10_async_chan *achan; + void *cb_arg; + async_callback_t cb; + struct stratix10_svc_client_msg *msg; + struct hlist_node next; + struct arm_smccc_1_2_regs res; +}; + +/** + * struct stratix10_async_chan - Structure representing an asynchronous ch= annel + * @async_client_id: Unique client identifier for the asynchronous operati= on + * @job_id_pool: Pointer to the job ID pool associated with this channel + */ + +struct stratix10_async_chan { + unsigned long async_client_id; + struct stratix10_sip_id_pool *job_id_pool; +}; + +/** + * struct stratix10_async_ctrl - Control structure for Stratix10 + * asynchronous operations + * @initialized: Flag indicating whether the control structure has + * been initialized + * @invoke_fn: Function pointer for invoking Stratix10 service calls + * to EL3 secure firmware + * @async_id_pool: Pointer to the ID pool used for asynchronous + * operations + * @common_achan_refcount: Atomic reference count for the common + * asynchronous channel usage + * @common_async_chan: Pointer to the common asynchronous channel + * structure + * @trx_list_wr_lock: Spinlock for protecting the transaction list + * write operations + * @trx_list: Hash table for managing asynchronous transactions + */ + +struct stratix10_async_ctrl { + bool initialized; + void (*invoke_fn)(struct stratix10_async_ctrl *actrl, + const struct arm_smccc_1_2_regs *args, + struct arm_smccc_1_2_regs *res); + struct stratix10_sip_id_pool *async_id_pool; + atomic_t common_achan_refcount; + struct stratix10_async_chan *common_async_chan; + /* spinlock to protect the writes to trx_list hash table */ + spinlock_t trx_list_wr_lock; + DECLARE_HASHTABLE(trx_list, ASYNC_TRX_HASH_BITS); +}; + /** * struct stratix10_svc_controller - service controller * @dev: device @@ -135,6 +246,7 @@ struct stratix10_svc_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 + * @actrl: async control structure * * This struct is used to create communication channels for service client= s, to * handle secure monitor or hypervisor call. @@ -151,6 +263,7 @@ struct stratix10_svc_controller { struct completion complete_status; spinlock_t svc_fifo_lock; svc_invoke_fn *invoke_fn; + struct stratix10_async_ctrl actrl; }; =20 /** @@ -159,15 +272,17 @@ struct stratix10_svc_controller { * @scl: pointer to service client which owns the channel * @name: service client name associated with the channel * @lock: protect access to the channel + * @async_chan: reference to asynchronous channel object for this channel * - * This struct is used by service client to communicate with service layer= , each - * service client has its own channel created by service controller. + * This struct is used by service client to communicate with service layer. + * Each service client has its own channel created by service controller. */ struct stratix10_svc_chan { struct stratix10_svc_controller *ctrl; struct stratix10_svc_client *scl; char *name; spinlock_t lock; + struct stratix10_async_chan *async_chan; }; =20 /** @@ -1125,6 +1240,529 @@ struct stratix10_svc_chan *stratix10_svc_request_ch= annel_byname( } EXPORT_SYMBOL_GPL(stratix10_svc_request_channel_byname); =20 +/** + * stratix10_svc_add_async_client - Add an asynchronous client to the + * Stratix10 service channel. + * @chan: Pointer to the Stratix10 service channel structure. + * @use_unique_clientid: Boolean flag indicating whether to use a + * unique client ID. + * + * This function adds an asynchronous client to the specified + * Stratix10 service channel. If the `use_unique_clientid` flag is + * set to true, a unique client ID is allocated for the asynchronous + * channel. Otherwise, a common asynchronous channel is used. + * + * Return: 0 on success, or a negative error code on failure: + * -EINVAL if the channel is NULL or the async controller is + * not initialized. + * -EALREADY if the async channel is already allocated. + * -ENOMEM if memory allocation fails. + * Other negative values if ID allocation fails. + */ +int stratix10_svc_add_async_client(struct stratix10_svc_chan *chan, + bool use_unique_clientid) +{ + struct stratix10_svc_controller *ctrl; + struct stratix10_async_ctrl *actrl; + struct stratix10_async_chan *achan; + int ret =3D 0; + + if (!chan) + return -EINVAL; + + ctrl =3D chan->ctrl; + actrl =3D &ctrl->actrl; + + if (!actrl->initialized) { + dev_err(ctrl->dev, "Async controller not initialized\n"); + return -EINVAL; + } + + if (chan->async_chan) { + dev_err(ctrl->dev, "async channel already allocated\n"); + return -EALREADY; + } + + if (use_unique_clientid && + atomic_read(&actrl->common_achan_refcount) > 0) { + chan->async_chan =3D actrl->common_async_chan; + atomic_inc(&actrl->common_achan_refcount); + return 0; + } + + achan =3D kzalloc(sizeof(*achan), GFP_KERNEL); + if (!achan) + return -ENOMEM; + + achan->job_id_pool =3D stratix10_id_pool_create(MAX_SDM_JOB_IDS); + if (!achan->job_id_pool) { + dev_err(ctrl->dev, "Failed to create job id pool\n"); + kfree(achan); + return -ENOMEM; + } + + ret =3D stratix10_allocate_id(actrl->async_id_pool); + if (ret < 0) { + dev_err(ctrl->dev, + "Failed to allocate async client id\n"); + stratix10_id_pool_destroy(achan->job_id_pool); + kfree(achan); + return ret; + } + + achan->async_client_id =3D ret; + chan->async_chan =3D achan; + + if (use_unique_clientid && + atomic_read(&actrl->common_achan_refcount) =3D=3D 0) { + actrl->common_async_chan =3D achan; + atomic_inc(&actrl->common_achan_refcount); + } + + return 0; +} +EXPORT_SYMBOL_GPL(stratix10_svc_add_async_client); + +/** + * stratix10_svc_remove_async_client - Remove an asynchronous client + * from the Stratix10 service + * channel. + * @chan: Pointer to the Stratix10 service channel structure. + * + * This function removes an asynchronous client associated with the + * given service channel. It checks if the channel and the + * asynchronous channel are valid, and then proceeds to decrement + * the reference count for the common asynchronous channel if + * applicable. If the reference count reaches zero, it destroys the + * job ID pool and deallocates the asynchronous client ID. For + * non-common asynchronous channels, it directly destroys the job ID + * pool, deallocates the asynchronous client ID, and frees the + * memory allocated for the asynchronous channel. + * + * Return: 0 on success, -EINVAL if the channel or asynchronous + * channel is invalid. + */ +int stratix10_svc_remove_async_client(struct stratix10_svc_chan *chan) +{ + struct stratix10_svc_controller *ctrl; + struct stratix10_async_ctrl *actrl; + struct stratix10_async_chan *achan; + + if (!chan) + return -EINVAL; + + ctrl =3D chan->ctrl; + actrl =3D &ctrl->actrl; + achan =3D chan->async_chan; + + if (!achan) { + dev_err(ctrl->dev, "async channel not allocated\n"); + return -EINVAL; + } + + if (achan =3D=3D actrl->common_async_chan) { + atomic_dec(&actrl->common_achan_refcount); + if (atomic_read(&actrl->common_achan_refcount) =3D=3D 0) { + stratix10_id_pool_destroy(achan->job_id_pool); + stratix10_deallocate_id(actrl->async_id_pool, achan->async_client_id); + kfree(achan); + actrl->common_async_chan =3D NULL; + } + } else { + stratix10_id_pool_destroy(achan->job_id_pool); + stratix10_deallocate_id(actrl->async_id_pool, achan->async_client_id); + kfree(achan); + } + chan->async_chan =3D NULL; + + return 0; +} +EXPORT_SYMBOL_GPL(stratix10_svc_remove_async_client); + +/** + * stratix10_svc_async_send - Send an asynchronous message to the + * Stratix10 service + * @chan: Pointer to the service channel structure + * @msg: Pointer to the message to be sent + * @handler: Pointer to the handler for the asynchronous message + * used by caller for later reference. + * @cb: Callback function to be called upon completion + * @cb_arg: Argument to be passed to the callback function + * + * This function sends an asynchronous message to the SDM mailbox in + * EL3 secure firmware. It performs various checks and setups, + * including allocating a job ID, setting up the transaction ID and + * packaging it to El3 firmware. The function handles different + * commands by setting up the appropriate arguments for the SMC call. + * If the SMC call is successful, the handler is set up and the + * function returns 0. If the SMC call fails, appropriate error + * handling is performed along with cleanup of resources. + * + * Return: 0 on success, -EINVAL for invalid argument, -ENOMEM if + * memory is not available, -EAGAIN if EL3 firmware is busy, -EBADF + * if the message is rejected by EL3 firmware and -EIO on other + * errors from EL3 firmware. + */ +int stratix10_svc_async_send(struct stratix10_svc_chan *chan, void *msg, + void **handler, async_callback_t cb, void *cb_arg) +{ + struct stratix10_svc_client_msg *p_msg =3D (struct stratix10_svc_client_m= sg *)msg; + struct arm_smccc_1_2_regs args =3D { 0 }, res =3D { 0 }; + struct stratix10_svc_async_handler *handle =3D NULL; + struct stratix10_svc_controller *ctrl; + struct stratix10_async_ctrl *actrl; + struct stratix10_async_chan *achan; + int ret =3D 0; + + if (!chan || !msg || !handler) + return -EINVAL; + + achan =3D chan->async_chan; + ctrl =3D chan->ctrl; + actrl =3D &ctrl->actrl; + + if (!actrl->initialized) { + dev_err(ctrl->dev, "Async controller not initialized\n"); + return -EINVAL; + } + + if (!achan) { + dev_err(ctrl->dev, "Async channel not allocated\n"); + return -EINVAL; + } + + handle =3D kzalloc(sizeof(*handle), GFP_KERNEL); + if (!handle) + return -ENOMEM; + + ret =3D stratix10_allocate_id(achan->job_id_pool); + if (ret < 0) { + dev_err(ctrl->dev, "Failed to allocate job id\n"); + kfree(handle); + return -ENOMEM; + } + + handle->transaction_id =3D + STRATIX10_SET_TRANSACTIONID(achan->async_client_id, ret); + handle->cb =3D cb; + handle->msg =3D p_msg; + handle->cb_arg =3D cb_arg; + handle->achan =3D achan; + + /*set the transaction jobid in args.a1*/ + args.a1 =3D + STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(handle->transaction_id); + + switch (p_msg->command) { + default: + dev_err(ctrl->dev, "Invalid command ,%d\n", p_msg->command); + ret =3D -EINVAL; + goto deallocate_id; + } + + /** + * There is a chance that during the execution of async_send() + * in one core, an interrupt might be received in another core; + * to mitigate this we are adding the handle to the DB and then + * send the smc call. If the smc call is rejected or busy then + * we will deallocate the handle for the client to retry again. + */ + spin_lock(&actrl->trx_list_wr_lock); + hash_add_rcu(actrl->trx_list, &handle->next, handle->transaction_id); + spin_unlock(&actrl->trx_list_wr_lock); + synchronize_rcu(); + + actrl->invoke_fn(actrl, &args, &res); + + switch (res.a0) { + case INTEL_SIP_SMC_STATUS_OK: + dev_dbg(ctrl->dev, + "Async message sent with transaction_id 0x%02x\n", + handle->transaction_id); + *handler =3D handle; + return 0; + case INTEL_SIP_SMC_STATUS_BUSY: + dev_warn(ctrl->dev, "Mailbox is busy, try after some time\n"); + ret =3D -EAGAIN; + break; + case INTEL_SIP_SMC_STATUS_REJECTED: + dev_err(ctrl->dev, "Async message rejected\n"); + ret =3D -EBADF; + break; + default: + dev_err(ctrl->dev, + "Failed to send async message ,got status as %ld\n", + res.a0); + ret =3D -EIO; + } + + spin_lock(&actrl->trx_list_wr_lock); + hash_del_rcu(&handle->next); + spin_unlock(&actrl->trx_list_wr_lock); + synchronize_rcu(); + +deallocate_id: + stratix10_deallocate_id(achan->job_id_pool, + STRATIX10_GET_JOBID(handle->transaction_id)); + kfree(handle); + return ret; +} +EXPORT_SYMBOL_GPL(stratix10_svc_async_send); +/** + * stratix10_svc_async_poll - Polls the status of an asynchronous + * transaction. + * @chan: Pointer to the service channel structure. + * @tx_handle: Handle to the transaction being polled. + * @data: Pointer to the callback data structure. + * + * This function polls the status of an asynchronous transaction + * identified by the given transaction handle. It ensures that the + * necessary structures are initialized and valid before proceeding + * with the poll operation. The function sets up the necessary + * arguments for the SMC call, invokes the call, and prepares the + * response data if the call is successful. If the call fails, the + * function returns the error mapped to the SVC status error. + * + * Return: 0 on success, -EINVAL if any input parameter is invalid, + * -EAGAIN if the transaction is still in progress, + * -EPERM if the command is invalid, or other negative + * error codes on failure. + */ +int stratix10_svc_async_poll(struct stratix10_svc_chan *chan, void *tx_han= dle, + struct stratix10_svc_cb_data *data) +{ + struct stratix10_svc_async_handler *handle; + struct arm_smccc_1_2_regs args =3D { 0 }; + struct stratix10_svc_controller *ctrl; + struct stratix10_async_ctrl *actrl; + struct stratix10_async_chan *achan; + + if (!chan || !tx_handle || !data) + return -EINVAL; + + ctrl =3D chan->ctrl; + actrl =3D &ctrl->actrl; + achan =3D chan->async_chan; + + if (!achan) { + dev_err(ctrl->dev, "Async channel not allocated\n"); + return -EINVAL; + } + + handle =3D (struct stratix10_svc_async_handler *)tx_handle; + if (!hash_hashed(&handle->next)) { + dev_err(ctrl->dev, "Invalid transaction handler\n"); + return -EINVAL; + } + + args.a0 =3D INTEL_SIP_SMC_ASYNC_POLL; + args.a1 =3D + STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(handle->transaction_id); + + actrl->invoke_fn(actrl, &args, &handle->res); + + /*clear data for response*/ + memset(data, 0, sizeof(*data)); + + if (handle->res.a0 =3D=3D INTEL_SIP_SMC_STATUS_OK) { + return 0; + } else if (handle->res.a0 =3D=3D INTEL_SIP_SMC_STATUS_BUSY) { + dev_dbg(ctrl->dev, "async message is still in progress\n"); + return -EAGAIN; + } + + dev_err(ctrl->dev, + "Failed to poll async message ,got status as %ld\n", + handle->res.a0); + return -EINVAL; +} +EXPORT_SYMBOL_GPL(stratix10_svc_async_poll); + +/** + * stratix10_svc_async_done - Completes an asynchronous transaction. + * @chan: Pointer to the service channel structure. + * @tx_handle: Handle to the transaction being completed. + * + * This function completes an asynchronous transaction identified by + * the given transaction handle. It ensures that the necessary + * structures are initialized and valid before proceeding with the + * completion operation. The function deallocates the transaction ID, + * frees the memory allocated for the handler, and removes the handler + * from the transaction list. + * + * Return: 0 on success, -EINVAL if any input parameter is invalid, + * or other negative error codes on failure. + */ +int stratix10_svc_async_done(struct stratix10_svc_chan *chan, void *tx_han= dle) +{ + struct stratix10_svc_async_handler *handle; + struct stratix10_svc_controller *ctrl; + struct stratix10_async_chan *achan; + struct stratix10_async_ctrl *actrl; + + if (!chan || !tx_handle) + return -EINVAL; + + ctrl =3D chan->ctrl; + achan =3D chan->async_chan; + + if (!achan) { + dev_err(ctrl->dev, "async channel not allocated\n"); + return -EINVAL; + } + + handle =3D (struct stratix10_svc_async_handler *)tx_handle; + if (!hash_hashed(&handle->next)) { + dev_err(ctrl->dev, "Invalid transaction handle\n"); + return -EINVAL; + } + + actrl =3D &ctrl->actrl; + + spin_lock(&actrl->trx_list_wr_lock); + hash_del_rcu(&handle->next); + spin_unlock(&actrl->trx_list_wr_lock); + synchronize_rcu(); + stratix10_deallocate_id(achan->job_id_pool, + STRATIX10_GET_JOBID(handle->transaction_id)); + kfree(handle); + return 0; +} +EXPORT_SYMBOL_GPL(stratix10_svc_async_done); + +static inline void stratix10_smc_1_2(struct stratix10_async_ctrl *actrl, + const struct arm_smccc_1_2_regs *args, + struct arm_smccc_1_2_regs *res) +{ + arm_smccc_1_2_smc(args, res); +} + +/** + * stratix10_svc_async_init - Initialize the Stratix10 service + * controller for asynchronous operations. + * @controller: Pointer to the Stratix10 service controller structure. + * + * This function initializes the asynchronous service controller by + * setting up the necessary data structures and initializing the + * transaction list. + * + * Return: 0 on success, -EINVAL if the controller is NULL or already + * initialized, -ENOMEM if memory allocation fails, + * -EADDRINUSE if the client ID is already reserved, or other + * negative error codes on failure. + */ +static int stratix10_svc_async_init(struct stratix10_svc_controller *contr= oller) +{ + struct stratix10_async_ctrl *actrl; + struct arm_smccc_res res; + struct device *dev; + int ret; + + if (!controller) + return -EINVAL; + + actrl =3D &controller->actrl; + + if (actrl->initialized) + return -EINVAL; + + dev =3D controller->dev; + + controller->invoke_fn(INTEL_SIP_SMC_SVC_VERSION, 0, 0, 0, 0, 0, 0, 0, &re= s); + if (res.a0 !=3D INTEL_SIP_SMC_STATUS_OK && + !(res.a1 > ASYNC_ATF_MINIMUM_MAJOR_VERSION || + (res.a1 =3D=3D ASYNC_ATF_MINIMUM_MAJOR_VERSION && + res.a2 >=3D ASYNC_ATF_MINIMUM_MINOR_VERSION))) { + dev_err(dev, + "Intel Service Layer Driver: ATF version is not compatible for async op= eration\n"); + return -EINVAL; + } + + actrl->invoke_fn =3D stratix10_smc_1_2; + + actrl->async_id_pool =3D stratix10_id_pool_create(MAX_SDM_CLIENT_IDS); + if (!actrl->async_id_pool) + return -ENOMEM; + + /** + * SIP_SVC_V1_CLIENT_ID is used by V1 clients/stratix10_svc_send() + * for communicating with SDM synchronously. We need to restrict this + * in V3 usage to distinguish the V1 and V3 messages in El3 firmware. + */ + ret =3D stratix10_reserve_id(actrl->async_id_pool, SIP_SVC_V1_CLIENT_ID); + if (ret < 0) { + dev_err(dev, + "Intel Service Layer Driver: Error on reserving SIP_SVC_V1_CLIENT_ID\n"= ); + stratix10_id_pool_destroy(actrl->async_id_pool); + actrl->async_id_pool =3D NULL; + actrl->invoke_fn =3D NULL; + return -EADDRINUSE; + } + + spin_lock_init(&actrl->trx_list_wr_lock); + hash_init(actrl->trx_list); + atomic_set(&actrl->common_achan_refcount, 0); + + actrl->initialized =3D true; + return 0; +} + +/** + * stratix10_svc_async_exit - Clean up and exit the asynchronous + * service controller + * @ctrl: Pointer to the stratix10_svc_controller structure + * + * This function performs the necessary cleanup for the asynchronous + * service controller. It checks if the controller is valid and if it + * has been initialized. It then locks the transaction list and safely + * removes and deallocates each handler in the list. The function also + * removes any asynchronous clients associated with the controller's + * channels and destroys the asynchronous ID pool. Finally, it resets + * the asynchronous ID pool and invoke function pointers to NULL. + * + * Return: 0 on success, -EINVAL if the controller is invalid or not + * initialized. + */ +static int stratix10_svc_async_exit(struct stratix10_svc_controller *ctrl) +{ + struct stratix10_svc_async_handler *handler; + struct stratix10_async_ctrl *actrl; + struct hlist_node *tmp; + int i; + + if (!ctrl) + return -EINVAL; + + actrl =3D &ctrl->actrl; + + if (!actrl->initialized) + return -EINVAL; + + actrl->initialized =3D false; + + spin_lock(&actrl->trx_list_wr_lock); + hash_for_each_safe(actrl->trx_list, i, tmp, handler, next) { + stratix10_deallocate_id(handler->achan->job_id_pool, + STRATIX10_GET_JOBID(handler->transaction_id)); + hash_del_rcu(&handler->next); + kfree(handler); + } + spin_unlock(&actrl->trx_list_wr_lock); + + for (i =3D 0; i < SVC_NUM_CHANNEL; i++) { + if (ctrl->chans[i].async_chan) { + stratix10_svc_remove_async_client(&ctrl->chans[i]); + ctrl->chans[i].async_chan =3D NULL; + } + } + + stratix10_id_pool_destroy(actrl->async_id_pool); + actrl->async_id_pool =3D NULL; + actrl->invoke_fn =3D NULL; + + return 0; +} + /** * stratix10_svc_free_channel() - free service channel * @chan: service channel to be freed @@ -1385,11 +2023,18 @@ static int stratix10_svc_drv_probe(struct platform_= device *pdev) controller->invoke_fn =3D invoke_fn; init_completion(&controller->complete_status); =20 + ret =3D stratix10_svc_async_init(controller); + if (ret) { + dev_dbg(dev, "Intel Service Layer Driver: Error on stratix10_svc_async_i= nit %d\n", + ret); + goto err_destroy_pool; + } + fifo_size =3D sizeof(struct stratix10_svc_data) * SVC_NUM_DATA_IN_FIFO; ret =3D kfifo_alloc(&controller->svc_fifo, fifo_size, GFP_KERNEL); if (ret) { dev_err(dev, "failed to allocate FIFO\n"); - goto err_destroy_pool; + goto err_async_exit; } spin_lock_init(&controller->svc_fifo_lock); =20 @@ -1460,6 +2105,8 @@ static int stratix10_svc_drv_probe(struct platform_de= vice *pdev) platform_device_unregister(svc->stratix10_svc_rsu); err_free_kfifo: kfifo_free(&controller->svc_fifo); +err_async_exit: + stratix10_svc_async_exit(controller); err_destroy_pool: gen_pool_destroy(genpool); return ret; @@ -1470,6 +2117,8 @@ static void stratix10_svc_drv_remove(struct platform_= device *pdev) struct stratix10_svc *svc =3D dev_get_drvdata(&pdev->dev); struct stratix10_svc_controller *ctrl =3D platform_get_drvdata(pdev); =20 + stratix10_svc_async_exit(ctrl); + of_platform_depopulate(ctrl->dev); =20 platform_device_unregister(svc->intel_svc_fcs); diff --git a/include/linux/firmware/intel/stratix10-smc.h b/include/linux/f= irmware/intel/stratix10-smc.h index ee80ca4bb0d0c6d3aa99aeeca6a4980a315dcc43..c98ed992d23bed5aa344868ca0c= 77a2d19d94c06 100644 --- a/include/linux/firmware/intel/stratix10-smc.h +++ b/include/linux/firmware/intel/stratix10-smc.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2017-2018, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #ifndef __STRATIX10_SMC_H @@ -47,6 +48,10 @@ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \ ARM_SMCCC_OWNER_SIP, (func_num)) =20 +#define INTEL_SIP_SMC_ASYNC_VAL(func_name) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_SIP, (func_name)) + /** * Return values in INTEL_SIP_SMC_* call * @@ -620,4 +625,23 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_= CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_FCS_GET_PROVISION_DATA \ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FCS_GET_PROVISION_DATA) =20 +/** + * Request INTEL_SIP_SMC_ASYNC_POLL + * Async call used by service driver at EL1 to query mailbox response from= SDM. + * + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_POLL + * a1 transaction job id + * a2-17 will be used to return the response data + * + * Return status + * a0 INTEL_SIP_SMC_STATUS_OK + * a1-17 will contain the response values from mailbox for the previous se= nd transaction + * Or + * a0 INTEL_SIP_SMC_STATUS_NO_RESPONSE + * a1-17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL (0xC8) +#define INTEL_SIP_SMC_ASYNC_POLL \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL) #endif diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/= linux/firmware/intel/stratix10-svc-client.h index 60ed82112680e3674b6b7e9852d315922ffff33e..bda837815bae35fbf4df6280dba= 5bc02d747426e 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) 2017-2018, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #ifndef __STRATIX10_SVC_CLIENT_H @@ -284,5 +285,92 @@ int stratix10_svc_send(struct stratix10_svc_chan *chan= , void *msg); * request process. */ void stratix10_svc_done(struct stratix10_svc_chan *chan); + +/** + * typedef async_callback_t - A type definition for an asynchronous callba= ck function. + * + * This type defines a function pointer for an asynchronous callback. + * The callback function takes a single argument, which is a pointer to + * user-defined data. + * + * @param cb_arg A pointer to user-defined data passed to the callback fun= ction. + */ +typedef void (*async_callback_t)(void *cb_arg); + +/** + * stratix10_svc_add_async_client - Add an asynchronous client to a Strati= x 10 + * service channel. + * @chan: Pointer to the Stratix 10 service channel structure. + * @use_unique_clientid: Boolean flag indicating whether to use a unique c= lient ID. + * + * This function registers an asynchronous client with the specified Strat= ix 10 + * service channel. If the use_unique_clientid flag is set to true, a uniq= ue client + * ID will be assigned to the client. + * + * Return: 0 on success, or a negative error code on failure: + * -EINVAL if the channel is NULL or the async controller is not i= nitialized. + * -EALREADY if the async channel is already allocated. + * -ENOMEM if memory allocation fails. + * Other negative values if ID allocation fails + */ +int stratix10_svc_add_async_client(struct stratix10_svc_chan *chan, bool u= se_unique_clientid); + +/** + * stratix10_svc_remove_async_client - Remove an asynchronous client from = the Stratix 10 + * service channel. + * @chan: Pointer to the Stratix 10 service channel structure. + * + * This function removes an asynchronous client from the specified Stratix= 10 service channel. + * It is typically used to clean up and release resources associated with = the client. + * + * Return: 0 on success, -EINVAL if the channel or asynchronous channel is= invalid. + */ +int stratix10_svc_remove_async_client(struct stratix10_svc_chan *chan); + +/** + * stratix10_svc_async_send - Send an asynchronous message to the SDM mail= box + * in EL3 secure firmware. + * @chan: Pointer to the service channel structure. + * @msg: Pointer to the message to be sent. + * @handler: Pointer to the handler object used by caller to track the tra= nsaction. + * @cb: Callback function to be called upon completion. + * @cb_arg: Argument to be passed to the callback function. + * + * This function sends a message asynchronously to the SDM mailbox in EL3 = secure firmware. + * and registers a callback function to be invoked when the operation comp= letes. + * + * Return: 0 on success,and negative error codes on failure. + */ +int stratix10_svc_async_send(struct stratix10_svc_chan *chan, void *msg, v= oid **handler, + async_callback_t cb, void *cb_arg); + +/** + * stratix10_svc_async_poll - Polls the status of an asynchronous service = request. + * @chan: Pointer to the service channel structure. + * @tx_handle: Handle to the transaction being polled. + * @data: Pointer to the callback data structure to be filled with the res= ult. + * + * This function checks the status of an asynchronous service request + * and fills the provided callback data structure with the result. + * + * Return: 0 on success, -EINVAL if any input parameter is invalid or if t= he + * async controller is not initialized, -EAGAIN if the transaction= is + * still in progress, or other negative error codes on failure. + */ +int stratix10_svc_async_poll(struct stratix10_svc_chan *chan, void *tx_han= dle, + struct stratix10_svc_cb_data *data); + +/** + * stratix10_svc_async_done - Complete an asynchronous transaction + * @chan: Pointer to the service channel structure + * @tx_handle: Pointer to the transaction handle + * + * This function completes an asynchronous transaction by removing the + * transaction from the hash table and deallocating the associated resourc= es. + * + * Return: 0 on success, -EINVAL on invalid input or errors. + */ +int stratix10_svc_async_done(struct stratix10_svc_chan *chan, void *tx_han= dle); + #endif =20 --=20 2.35.3 From nobody Tue Oct 7 18:27:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 66460219313; Tue, 8 Jul 2025 04:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; cv=none; b=JI6eBqXPKXSLfU38vFkBgaCLId9QYxTVEELmJFSqsFW2qK5QaTvfhJnvU62xWoVJksDx8RWPgKc2hkb0S9nMQx4Rrdb139o5yHowbXDRsbsmSE+73alnAZgOUx+XwfEppe5sNAhwlXOjNJqAiZ11JDivOnKAXBk8M2w1FH6bqzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; c=relaxed/simple; bh=3fIQL4QWyco0hEODQOdUxUigyMr71zkRtJM9vlMRwG4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X3imsU5dEye+vD9POotJkpJHfamHrYIIQxARrlfjDZ5Agn5do0GlRrcCq/+BZl2CpAvDHeLm8wVvTXLbb8V/y17/3nRR0HeJahjBUIfO+eRMQ+qrwEkUMx3++j8CBhWrQuZq9bU+/CGtr13fDQGqpPwXbb5Mi7ao6x+iAcryey8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OxmxRlQi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OxmxRlQi" Received: by smtp.kernel.org (Postfix) with ESMTPS id D67A5C4CEFB; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751950195; bh=3fIQL4QWyco0hEODQOdUxUigyMr71zkRtJM9vlMRwG4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=OxmxRlQi0nAE9kN+rSgKV+FFd1HdK0+7jk7vql+0SP88+0R56vp9FZ6HbCkAE4ivq RHHcrPwyomqohSHW15da10TCMYUB+VIfLy8rkEPfCqE8iXx/lFKT8dMFqmJMbSYOxs 7SY0eMO9udlDC2YMpsKLrivlnJdWhQqnhqsQSwFEWT8cmzv/WKxlqzQdAZ/UKkwDlp IMGb8Gm6imDhuEO2428Pzj4bG3+A99rR2V5dxfcdrUmkVnQPh4SsOKSwvLh+TVbPs7 CZRPE3taFo0AauqzHg1jA61nTEAADGhv5hg/eFPZNnTFi/F5Pr9SsdMWnx0727Ads7 gpMQEqZ7GpGVw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBEBBC83F12; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Tue, 08 Jul 2025 12:49:09 +0800 Subject: [PATCH RESEND v5 4/5] firmware: stratix10-svc: Add support for RSU commands in asynchronous framework Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-sip_svc_upstream-v5-4-9c4289256d54@altera.com> References: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> In-Reply-To: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751950193; l=8242; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=iTm7E1YwxYmOVcZUGNFFE9XKR//QCEaHqnvM31rn93A=; b=r2wDCmj62B68zmV/a0CoZkxTGw6DYntyJfRcxrjjJPsDDe4IZanFHlsOljVMMsepyqqJZqOBz yHdAlgJvyyFB/0vkTfzGnM/F36rvYLBRMUBrxF866RTj9IJi9cZGJRp X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao Integrate Remote System Update(RSU) service commands into the asynchronous framework for communicating with SDM. This allows the RSU commands to be processed asynchronously, improving the responsiveness of the Stratix10 service channel. The asynchronous framework now supports the following RSU commands: * COMMAND_RSU_GET_SPT_TABLE * COMMAND_RSU_STATUS * COMMAND_RSU_NOTIFY Signed-off-by: Mahesh Rao --- drivers/firmware/stratix10-svc.c | 72 ++++++++++++++++++= ++++ include/linux/firmware/intel/stratix10-smc.h | 52 ++++++++++++++++ .../linux/firmware/intel/stratix10-svc-client.h | 4 ++ 3 files changed, 128 insertions(+) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index 4480ba8b2e115809103f3632906ac81e4fb8a63a..491a8149033f975d515444f0257= 23658c51aa1fe 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -87,6 +87,12 @@ #define STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(transaction_id) \ (FIELD_PREP(STRATIX10_TRANS_ID_FIELD, transaction_id)) =20 +/* 10-bit mask for extracting the SDM status code */ +#define STRATIX10_SDM_STATUS_MASK GENMASK(9, 0) +/* Macro to get the SDM mailbox error status */ +#define STRATIX10_GET_SDM_STATUS_CODE(status) \ + (FIELD_GET(STRATIX10_SDM_STATUS_MASK, status)) + typedef void (svc_invoke_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, @@ -1454,6 +1460,16 @@ int stratix10_svc_async_send(struct stratix10_svc_ch= an *chan, void *msg, STRATIX10_SIP_SMC_SET_TRANSACTIONID_X1(handle->transaction_id); =20 switch (p_msg->command) { + case COMMAND_RSU_GET_SPT_TABLE: + args.a0 =3D INTEL_SIP_SMC_ASYNC_RSU_GET_SPT; + break; + case COMMAND_RSU_STATUS: + args.a0 =3D INTEL_SIP_SMC_ASYNC_RSU_GET_ERROR_STATUS; + break; + case COMMAND_RSU_NOTIFY: + args.a0 =3D INTEL_SIP_SMC_ASYNC_RSU_NOTIFY; + args.a2 =3D p_msg->arg[0]; + break; default: dev_err(ctrl->dev, "Invalid command ,%d\n", p_msg->command); ret =3D -EINVAL; @@ -1508,6 +1524,56 @@ int stratix10_svc_async_send(struct stratix10_svc_ch= an *chan, void *msg, return ret; } EXPORT_SYMBOL_GPL(stratix10_svc_async_send); + +/** + * stratix10_svc_async_prepare_response - Prepare the response data for + * an asynchronous transaction. + * @chan: Pointer to the service channel structure. + * @handle: Pointer to the asynchronous handler structure. + * @data: Pointer to the callback data structure. + * + * This function prepares the response data for an asynchronous transactio= n. It + * extracts the response data from the SMC response structure and stores i= t in + * the callback data structure. The function also logs the completion of t= he + * asynchronous transaction. + * + * Return: 0 on success, -ENOENT if the command is invalid + */ +static int stratix10_svc_async_prepare_response(struct stratix10_svc_chan = *chan, + struct stratix10_svc_async_handler *handle, + struct stratix10_svc_cb_data *data) +{ + struct stratix10_svc_client_msg *p_msg =3D + (struct stratix10_svc_client_msg *)handle->msg; + struct stratix10_svc_controller *ctrl =3D chan->ctrl; + + data->status =3D STRATIX10_GET_SDM_STATUS_CODE(handle->res.a1); + + switch (p_msg->command) { + case COMMAND_RSU_NOTIFY: + break; + case COMMAND_RSU_GET_SPT_TABLE: + data->kaddr1 =3D (void *)&handle->res.a2; + data->kaddr2 =3D (void *)&handle->res.a3; + break; + case COMMAND_RSU_STATUS: + /* COMMAND_RSU_STATUS has more elements than the cb_data + * can acomodate, so passing the response structure to the + * response function to be handled before done command is + * executed by the client. + */ + data->kaddr1 =3D (void *)&handle->res; + break; + + default: + dev_alert(ctrl->dev, "Invalid command\n ,%d", p_msg->command); + return -ENOENT; + } + dev_dbg(ctrl->dev, "Async message completed transaction_id 0x%02x\n", + handle->transaction_id); + return 0; +} + /** * stratix10_svc_async_poll - Polls the status of an asynchronous * transaction. @@ -1536,6 +1602,7 @@ int stratix10_svc_async_poll(struct stratix10_svc_cha= n *chan, void *tx_handle, struct stratix10_svc_controller *ctrl; struct stratix10_async_ctrl *actrl; struct stratix10_async_chan *achan; + int ret; =20 if (!chan || !tx_handle || !data) return -EINVAL; @@ -1565,6 +1632,11 @@ int stratix10_svc_async_poll(struct stratix10_svc_ch= an *chan, void *tx_handle, memset(data, 0, sizeof(*data)); =20 if (handle->res.a0 =3D=3D INTEL_SIP_SMC_STATUS_OK) { + ret =3D stratix10_svc_async_prepare_response(chan, handle, data); + if (ret) { + dev_err(ctrl->dev, "Error in preparation of response,%d\n", ret); + WARN_ON_ONCE(1); + } return 0; } else if (handle->res.a0 =3D=3D INTEL_SIP_SMC_STATUS_BUSY) { dev_dbg(ctrl->dev, "async message is still in progress\n"); diff --git a/include/linux/firmware/intel/stratix10-smc.h b/include/linux/f= irmware/intel/stratix10-smc.h index c98ed992d23bed5aa344868ca0c77a2d19d94c06..f87273af5e284b8912d87eb9d71= 79eb3d43e40e1 100644 --- a/include/linux/firmware/intel/stratix10-smc.h +++ b/include/linux/firmware/intel/stratix10-smc.h @@ -644,4 +644,56 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_= CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL (0xC8) #define INTEL_SIP_SMC_ASYNC_POLL \ INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_POLL) + +/** + * Request INTEL_SIP_SMC_ASYNC_RSU_GET_SPT + * Async call to get RSU SPT from SDM. + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_RSU_GET_SPT + * a1 transaction job id + * a2-a17 not used + * + * Return status: + * a0 INTEL_SIP_SMC_STATUS_OK ,INTEL_SIP_SMC_STATUS_REJECTED + * or INTEL_SIP_SMC_STATUS_BUSY + * a1-a17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNC_ID_RSU_GET_SPT (0xEA) +#define INTEL_SIP_SMC_ASYNC_RSU_GET_SPT \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_RSU_GET_SPT) + +/** + * Request INTEL_SIP_SMC_ASYNC_RSU_GET_ERROR_STATUS + * Async call to get RSU error status from SDM. + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_RSU_GET_ERROR_STATUS + * a1 transaction job id + * a2-a17 not used + * + * Return status: + * a0 INTEL_SIP_SMC_STATUS_OK ,INTEL_SIP_SMC_STATUS_REJECTED + * or INTEL_SIP_SMC_STATUS_BUSY + * a1-a17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNC_ID_RSU_GET_ERROR_STATUS (0xEB) +#define INTEL_SIP_SMC_ASYNC_RSU_GET_ERROR_STATUS \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_RSU_GET_ERROR_STATUS) + +/** + * Request INTEL_SIP_SMC_ASYNC_RSU_NOTIFY + * Async call to send NOTIFY value to SDM. + * Call register usage: + * a0 INTEL_SIP_SMC_ASYNC_RSU_NOTIFY + * a1 transaction job id + * a2 notify value + * a3-a17 not used + * + * Return status: + * a0 INTEL_SIP_SMC_STATUS_OK ,INTEL_SIP_SMC_STATUS_REJECTED + * or INTEL_SIP_SMC_STATUS_BUSY + * a1-a17 not used + */ +#define INTEL_SIP_SMC_ASYNC_FUNC_ID_RSU_NOTIFY (0xEC) +#define INTEL_SIP_SMC_ASYNC_RSU_NOTIFY \ + INTEL_SIP_SMC_ASYNC_VAL(INTEL_SIP_SMC_ASYNC_FUNC_ID_RSU_NOTIFY) #endif diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/= linux/firmware/intel/stratix10-svc-client.h index bda837815bae35fbf4df6280dba5bc02d747426e..cf0eac5446147e9a92a1ddada23= bc183977123c0 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -125,6 +125,9 @@ struct stratix10_svc_chan; * @COMMAND_RSU_DCMF_STATUS: query firmware for the DCMF status * return status is SVC_STATUS_OK or SVC_STATUS_ERROR * + * @COMMAND_RSU_GET_SPT_TABLE: query firmware for SPT table + * return status is SVC_STATUS_OK or SVC_STATUS_ERROR + * * @COMMAND_FCS_REQUEST_SERVICE: request validation of image from firmware, * return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM * @@ -159,6 +162,7 @@ enum stratix10_svc_command_code { COMMAND_RSU_DCMF_VERSION, COMMAND_RSU_DCMF_STATUS, COMMAND_FIRMWARE_VERSION, + COMMAND_RSU_GET_SPT_TABLE, /* for FCS */ COMMAND_FCS_REQUEST_SERVICE =3D 20, COMMAND_FCS_SEND_CERTIFICATE, --=20 2.35.3 From nobody Tue Oct 7 18:27:29 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 53EB12192EB; Tue, 8 Jul 2025 04:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; cv=none; b=ECSjaOGiE+sHHfpPX8wrvpPDqTsbbHOXtqklXclNZhKV7uVj6gDsvX8ve1RXWKmuobs6jLllCGk3m3VGcOKQSrEHQAeJ2vVr8/tKxRmWhNCCGw4tIjXVd46pI3hDlz/S3s/SA+qatmL8rq0Yy3CVoIBctbqZV0Zs0TwZygWG7Y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751950196; c=relaxed/simple; bh=Mg5I9GQaPwUd+79TO7AVQNChtWaRs7LbsN5ONrDkgus=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PdzUndBQPqM42k3S/rOgQ2YW8ejrcMQYi4cLBwvCsGnCEOaOLadDrcasQSB5UhCh/GnMIEq91pI5K+6+qpdhSnGYOJCfOmRnsRSoNMcGpUXrCi6D70FyHAU/MipiZ0lskOTKC7HTmQcVMiTLE8fStzAC4DApMPgfyVBHnzOlGRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UfniWL+P; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UfniWL+P" Received: by smtp.kernel.org (Postfix) with ESMTPS id E255CC4CEFF; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751950195; bh=Mg5I9GQaPwUd+79TO7AVQNChtWaRs7LbsN5ONrDkgus=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=UfniWL+Paqj5XH3tGIdVC4ib3QP09x0oldGrm5p5sn1PFKrHio1H47jmHmPRYt0dR lkBgDv4wxq/4xK6a/+n6LKj1mcZf5FgVh9zJuozYyodqpRigCpxwCyYHlT28DB6k/K XgckI7ciuj+Dh2YfXPOeaXDDawDP/L+Kq0kBxE2hZYDR0oW/RYYpketvJ93rZ638rm ZWJsWI9uuNyNOXcYiFjaoYOhhaksQ9uMK6KpqYgx22cp0Ft3MR4RV19HS+ufkQiW4s mtuLYOeY0DlcUsE2ZXUu0LNWIc6Mxq8ZoHYkZ+rIFQOHYWRCOGh0VdIjkkpkmnr3c9 nucsEV6h1yWpg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9C42C83F09; Tue, 8 Jul 2025 04:49:55 +0000 (UTC) From: Mahesh Rao via B4 Relay Date: Tue, 08 Jul 2025 12:49:10 +0800 Subject: [PATCH RESEND v5 5/5] firmware: stratix10-rsu: Migrate RSU driver to use stratix10 asynchronous framework. Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-sip_svc_upstream-v5-5-9c4289256d54@altera.com> References: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> In-Reply-To: <20250708-sip_svc_upstream-v5-0-9c4289256d54@altera.com> To: Dinh Nguyen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mahesh Rao Cc: Matthew Gerlach , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1751950193; l=13278; i=mahesh.rao@altera.com; s=20250107; h=from:subject:message-id; bh=kI23gIa6PngF5SYH1gAyhV6qX0hobd+0qY9aPOd8c7U=; b=MfN761QNAFwiOfhDZz+i5iqVjtUyfAFw05Hs1SmtqpJMK+UQmEwpgF9309+lPQERF0j/0koxy x5AtmpcQLx1BzRHYOiuCGajtcNPPoy8OnCDq2cpsbgAIninLzzo9vVg X-Developer-Key: i=mahesh.rao@altera.com; a=ed25519; pk=tQiFUzoKxHrQLDtWeEeaeTeJTl/UfclUHWZy1fjSiyg= X-Endpoint-Received: by B4 Relay for mahesh.rao@altera.com/20250107 with auth_id=337 X-Original-From: Mahesh Rao Reply-To: mahesh.rao@altera.com From: Mahesh Rao * Add support for asynchronous communication to the RSU client channel. * Migrate functions that communicate with the SDM to use the asynchronous framework. Signed-off-by: Mahesh Rao --- drivers/firmware/stratix10-rsu.c | 272 ++++++++++++++++++++---------------= ---- 1 file changed, 142 insertions(+), 130 deletions(-) diff --git a/drivers/firmware/stratix10-rsu.c b/drivers/firmware/stratix10-= rsu.c index 1ea39a0a76c787c6396300734b636b4b3a0ae04d..53b67b242cf0afa4102340aa099= cef66b642effa 100644 --- a/drivers/firmware/stratix10-rsu.c +++ b/drivers/firmware/stratix10-rsu.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2018-2019, Intel Corporation + * Copyright (C) 2025, Altera Corporation */ =20 #include @@ -14,11 +15,9 @@ #include #include #include +#include =20 -#define RSU_STATE_MASK GENMASK_ULL(31, 0) -#define RSU_VERSION_MASK GENMASK_ULL(63, 32) -#define RSU_ERROR_LOCATION_MASK GENMASK_ULL(31, 0) -#define RSU_ERROR_DETAIL_MASK GENMASK_ULL(63, 32) +#define RSU_ERASE_SIZE_MASK GENMASK_ULL(63, 32) #define RSU_DCMF0_MASK GENMASK_ULL(31, 0) #define RSU_DCMF1_MASK GENMASK_ULL(63, 32) #define RSU_DCMF2_MASK GENMASK_ULL(31, 0) @@ -35,7 +34,8 @@ #define INVALID_DCMF_STATUS 0xFFFFFFFF #define INVALID_SPT_ADDRESS 0x0 =20 -#define RSU_GET_SPT_CMD 0x5A +#define RSU_RETRY_SLEEP_MS (1U) +#define RSU_ASYNC_MSG_RETRY (3U) #define RSU_GET_SPT_RESP_LEN (4 * sizeof(unsigned int)) =20 typedef void (*rsu_callback)(struct stratix10_svc_client *client, @@ -64,7 +64,6 @@ typedef void (*rsu_callback)(struct stratix10_svc_client = *client, * @max_retry: the preset max retry value * @spt0_address: address of spt0 * @spt1_address: address of spt1 - * @get_spt_response_buf: response from sdm for get_spt command */ struct stratix10_rsu_priv { struct stratix10_svc_chan *chan; @@ -99,47 +98,32 @@ struct stratix10_rsu_priv { =20 unsigned long spt0_address; unsigned long spt1_address; - - unsigned int *get_spt_response_buf; }; =20 +typedef void (*rsu_async_callback)(struct device *dev, + struct stratix10_rsu_priv *priv, struct stratix10_svc_cb_data *data); + /** - * rsu_status_callback() - Status callback from Intel Service Layer - * @client: pointer to service client + * rsu_async_status_callback() - Status callback from rsu_async_send() + * @dev: pointer to device object + * @priv: pointer to priv object * @data: pointer to callback data structure * - * Callback from Intel service layer for RSU status request. Status is - * only updated after a system reboot, so a get updated status call is - * made during driver probe. + * Callback from rsu_async_send() to get the system rsu error status. */ -static void rsu_status_callback(struct stratix10_svc_client *client, - struct stratix10_svc_cb_data *data) +static void rsu_async_status_callback(struct device *dev, + struct stratix10_rsu_priv *priv, + struct stratix10_svc_cb_data *data) { - struct stratix10_rsu_priv *priv =3D client->priv; - struct arm_smccc_res *res =3D (struct arm_smccc_res *)data->kaddr1; - - if (data->status =3D=3D BIT(SVC_STATUS_OK)) { - priv->status.version =3D FIELD_GET(RSU_VERSION_MASK, - res->a2); - priv->status.state =3D FIELD_GET(RSU_STATE_MASK, res->a2); - priv->status.fail_image =3D res->a1; - priv->status.current_image =3D res->a0; - priv->status.error_location =3D - FIELD_GET(RSU_ERROR_LOCATION_MASK, res->a3); - priv->status.error_details =3D - FIELD_GET(RSU_ERROR_DETAIL_MASK, res->a3); - } else { - dev_err(client->dev, "COMMAND_RSU_STATUS returned 0x%lX\n", - res->a0); - priv->status.version =3D 0; - priv->status.state =3D 0; - priv->status.fail_image =3D 0; - priv->status.current_image =3D 0; - priv->status.error_location =3D 0; - priv->status.error_details =3D 0; - } - - complete(&priv->completion); + struct arm_smccc_1_2_regs *res =3D (struct arm_smccc_1_2_regs *)data->kad= dr1; + + priv->status.current_image =3D res->a2; + priv->status.fail_image =3D res->a3; + priv->status.state =3D res->a4; + priv->status.version =3D res->a5; + priv->status.error_location =3D res->a7; + priv->status.error_details =3D res->a8; + priv->retry_counter =3D res->a9; } =20 /** @@ -163,32 +147,6 @@ static void rsu_command_callback(struct stratix10_svc_= client *client, complete(&priv->completion); } =20 -/** - * rsu_retry_callback() - Callback from Intel service layer for getting - * the current image's retry counter from the firmware - * @client: pointer to client - * @data: pointer to callback data structure - * - * Callback from Intel service layer for retry counter, which is used by - * user to know how many times the images is still allowed to reload - * itself before giving up and starting RSU fail-over flow. - */ -static void rsu_retry_callback(struct stratix10_svc_client *client, - struct stratix10_svc_cb_data *data) -{ - struct stratix10_rsu_priv *priv =3D client->priv; - unsigned int *counter =3D (unsigned int *)data->kaddr1; - - if (data->status =3D=3D BIT(SVC_STATUS_OK)) - priv->retry_counter =3D *counter; - else if (data->status =3D=3D BIT(SVC_STATUS_NO_SUPPORT)) - dev_warn(client->dev, "Secure FW doesn't support retry\n"); - else - dev_err(client->dev, "Failed to get retry counter %lu\n", - BIT(data->status)); - - complete(&priv->completion); -} =20 /** * rsu_max_retry_callback() - Callback from Intel service layer for getting @@ -270,34 +228,19 @@ static void rsu_dcmf_status_callback(struct stratix10= _svc_client *client, complete(&priv->completion); } =20 -static void rsu_get_spt_callback(struct stratix10_svc_client *client, - struct stratix10_svc_cb_data *data) +/** + * rsu_async_get_spt_table_callback() - Callback to be used by the rsu_asy= nc_send() + * to retrieve the SPT table information. + * @dev: pointer to device object + * @priv: pointer to priv object + * @data: pointer to callback data structure + */ +static void rsu_async_get_spt_table_callback(struct device *dev, + struct stratix10_rsu_priv *priv, + struct stratix10_svc_cb_data *data) { - struct stratix10_rsu_priv *priv =3D client->priv; - unsigned long *mbox_err =3D (unsigned long *)data->kaddr1; - unsigned long *resp_len =3D (unsigned long *)data->kaddr2; - - if (data->status !=3D BIT(SVC_STATUS_OK) || (*mbox_err) || - (*resp_len !=3D RSU_GET_SPT_RESP_LEN)) - goto error; - - priv->spt0_address =3D priv->get_spt_response_buf[0]; - priv->spt0_address <<=3D 32; - priv->spt0_address |=3D priv->get_spt_response_buf[1]; - - priv->spt1_address =3D priv->get_spt_response_buf[2]; - priv->spt1_address <<=3D 32; - priv->spt1_address |=3D priv->get_spt_response_buf[3]; - - goto complete; - -error: - dev_err(client->dev, "failed to get SPTs\n"); - -complete: - stratix10_svc_free_memory(priv->chan, priv->get_spt_response_buf); - priv->get_spt_response_buf =3D NULL; - complete(&priv->completion); + priv->spt0_address =3D *((unsigned long *)data->kaddr1); + priv->spt1_address =3D *((unsigned long *)data->kaddr2); } =20 /** @@ -329,14 +272,6 @@ static int rsu_send_msg(struct stratix10_rsu_priv *pri= v, if (arg) msg.arg[0] =3D arg; =20 - if (command =3D=3D COMMAND_MBOX_SEND_CMD) { - msg.arg[1] =3D 0; - msg.payload =3D NULL; - msg.payload_length =3D 0; - msg.payload_output =3D priv->get_spt_response_buf; - msg.payload_length_output =3D RSU_GET_SPT_RESP_LEN; - } - ret =3D stratix10_svc_send(priv->chan, &msg); if (ret < 0) goto status_done; @@ -362,6 +297,95 @@ static int rsu_send_msg(struct stratix10_rsu_priv *pri= v, return ret; } =20 +/** + * soc64_async_callback() - Callback from Intel service layer for async re= quests + * @ptr: pointer to the completion object + */ +static void soc64_async_callback(void *ptr) +{ + if (ptr) + complete(ptr); +} + +/** + * rsu_send_async_msg() - send an async message to Intel service layer + * @dev: pointer to device object + * @priv: pointer to rsu private data + * @command: RSU status or update command + * @arg: the request argument, notify status + * @callback: function pointer for the callback (status or update) + */ +static int rsu_send_async_msg(struct device *dev, struct stratix10_rsu_pri= v *priv, + enum stratix10_svc_command_code command, + unsigned long arg, + rsu_async_callback callback) +{ + struct stratix10_svc_client_msg msg =3D {0}; + struct stratix10_svc_cb_data data =3D {0}; + struct completion completion; + int status, index, ret; + void *handle =3D NULL; + + msg.command =3D command; + msg.arg[0] =3D arg; + + init_completion(&completion); + + for (index =3D 0; index < RSU_ASYNC_MSG_RETRY; index++) { + status =3D stratix10_svc_async_send(priv->chan, &msg, + &handle, soc64_async_callback, + &completion); + if (status =3D=3D 0) + break; + dev_warn(dev, "Failed to send async message\n"); + msleep(RSU_RETRY_SLEEP_MS); + } + + if (status && !handle) { + dev_err(dev, "Failed to send async message\n"); + return -ETIMEDOUT; + } + + ret =3D wait_for_completion_io_timeout(&completion, RSU_TIMEOUT); + if (ret > 0) + dev_dbg(dev, "Received async interrupt\n"); + else if (ret =3D=3D 0) + dev_dbg(dev, "Timeout occurred. Trying to poll the response\n"); + + for (index =3D 0; index < RSU_ASYNC_MSG_RETRY; index++) { + status =3D stratix10_svc_async_poll(priv->chan, handle, &data); + if (status =3D=3D -EAGAIN) { + dev_dbg(dev, "Async message is still in progress\n"); + } else if (status < 0) { + dev_alert(dev, "Failed to poll async message\n"); + ret =3D -ETIMEDOUT; + } else if (status =3D=3D 0) { + ret =3D 0; + break; + } + msleep(RSU_RETRY_SLEEP_MS); + } + + if (ret) { + dev_err(dev, "Failed to get async response\n"); + goto status_done; + } + + if (data.status =3D=3D 0) { + ret =3D 0; + if (callback) + callback(dev, priv, &data); + } else { + dev_err(dev, "%s returned 0x%x from SDM\n", __func__, + data.status); + ret =3D -EFAULT; + } + +status_done: + stratix10_svc_async_done(priv->chan, handle); + return ret; +} + /* * This driver exposes some optional features of the Intel Stratix 10 SoC = FPGA. * The sysfs interfaces exposed here are FPGA Remote System Update (RSU) @@ -597,27 +621,20 @@ static ssize_t notify_store(struct device *dev, if (ret) return ret; =20 - ret =3D rsu_send_msg(priv, COMMAND_RSU_NOTIFY, - status, rsu_command_callback); + ret =3D rsu_send_async_msg(dev, priv, COMMAND_RSU_NOTIFY, status, NULL); if (ret) { dev_err(dev, "Error, RSU notify returned %i\n", ret); return ret; } =20 /* to get the updated state */ - ret =3D rsu_send_msg(priv, COMMAND_RSU_STATUS, - 0, rsu_status_callback); + ret =3D rsu_send_async_msg(dev, priv, COMMAND_RSU_STATUS, 0, + rsu_async_status_callback); if (ret) { dev_err(dev, "Error, getting RSU status %i\n", ret); return ret; } =20 - ret =3D rsu_send_msg(priv, COMMAND_RSU_RETRY, 0, rsu_retry_callback); - if (ret) { - dev_err(dev, "Error, getting RSU retry %i\n", ret); - return ret; - } - return count; } =20 @@ -737,12 +754,19 @@ static int stratix10_rsu_probe(struct platform_device= *pdev) return PTR_ERR(priv->chan); } =20 + ret =3D stratix10_svc_add_async_client(priv->chan, false); + if (ret) { + dev_err(dev, "failed to add async client\n"); + stratix10_svc_free_channel(priv->chan); + return ret; + } + init_completion(&priv->completion); platform_set_drvdata(pdev, priv); =20 /* get the initial state from firmware */ - ret =3D rsu_send_msg(priv, COMMAND_RSU_STATUS, - 0, rsu_status_callback); + ret =3D rsu_send_async_msg(dev, priv, COMMAND_RSU_STATUS, 0, + rsu_async_status_callback); if (ret) { dev_err(dev, "Error, getting RSU status %i\n", ret); stratix10_svc_free_channel(priv->chan); @@ -763,12 +787,6 @@ static int stratix10_rsu_probe(struct platform_device = *pdev) stratix10_svc_free_channel(priv->chan); } =20 - ret =3D rsu_send_msg(priv, COMMAND_RSU_RETRY, 0, rsu_retry_callback); - if (ret) { - dev_err(dev, "Error, getting RSU retry %i\n", ret); - stratix10_svc_free_channel(priv->chan); - } - ret =3D rsu_send_msg(priv, COMMAND_RSU_MAX_RETRY, 0, rsu_max_retry_callback); if (ret) { @@ -776,18 +794,12 @@ static int stratix10_rsu_probe(struct platform_device= *pdev) stratix10_svc_free_channel(priv->chan); } =20 - priv->get_spt_response_buf =3D - stratix10_svc_allocate_memory(priv->chan, RSU_GET_SPT_RESP_LEN); =20 - if (IS_ERR(priv->get_spt_response_buf)) { - dev_err(dev, "failed to allocate get spt buffer\n"); - } else { - ret =3D rsu_send_msg(priv, COMMAND_MBOX_SEND_CMD, - RSU_GET_SPT_CMD, rsu_get_spt_callback); - if (ret) { - dev_err(dev, "Error, getting SPT table %i\n", ret); - stratix10_svc_free_channel(priv->chan); - } + ret =3D rsu_send_async_msg(dev, priv, COMMAND_RSU_GET_SPT_TABLE, 0, + rsu_async_get_spt_table_callback); + if (ret) { + dev_err(dev, "Error, getting SPT table %i\n", ret); + stratix10_svc_free_channel(priv->chan); } =20 return ret; --=20 2.35.3