From patchwork Sun Sep 1 06:18:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13786354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3EFABC54FC6 for ; Sun, 1 Sep 2024 06:26:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gdylpiHpF8/e2Kadkja3wGmTqD4jjwT8QtH1OIJ3eMg=; b=r825SFpRgrV0Qi1rgW24BUW/BU /vJaNfTPeCuIIMQnKmdRPTE1ih7FNjXB36mDq6eaLjHqSiTGB0Odqu3Jfi9qa1+BYAEXYsUPrPvmA /jMeshkWdnPgAXRGJ8apVVq4lBROBuh2Grv4VcuFpazbjPPRSILTrtJ71vY6Hr0CMOghtK4mGBlcU wlJRZ2QpklIaQG2Vg8hWmggrHZ3C1LQ6ZjqHFt8cB6ePffEEVIAL5nmA4jHc5F0D/BtuSlrWQax4Q hMGWXPa8nsgBEYIeDYDuK5L/RgHgYbm0fr2Rpyxujs80NbJ8bilF5dGLbCjB+Q7gVGRmqgfRQHzO3 bnkmg0jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ske2s-0000000B2HM-1heo; Sun, 01 Sep 2024 06:26:42 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1skdus-0000000B17Z-0PjV; Sun, 01 Sep 2024 06:18:27 +0000 Received: from umang.jain (unknown [IPv6:2405:201:2033:3865:19c8:9110:3e7:4518]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6253E670; Sun, 1 Sep 2024 08:17:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1725171434; bh=zn+Jxdj/y5r1FtKrH0dkOQMjWO/9rmeugEScZweFyoE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dV/rujbYtXOEMW8VCRC5LPQxoTJF9HA6vLWL9gz02Bvpp2pHEhNAPZdTSjs1YzXTq qoAIH/jBSAfzTOOG5HJp4m8ZMKmEwuoD1OyVa5TaopVnrpF1MAhMxiX9CFMNjGpcRx U0uxgPIs8wuRuGU44hkvCtL0fkL3I9FzhUqzoV9A= From: Umang Jain To: Florian Fainelli , Broadcom internal kernel review list , Greg Kroah-Hartman Cc: linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Kieran Bingham , Arnd Bergmann , Stefan Wahren , Dave Stevenson , Phil Elwell , Laurent Pinchart , Umang Jain Subject: [PATCH v3 3/7] staging: vchiq_core: Factor out bulk transfer for blocking mode Date: Sun, 1 Sep 2024 11:48:04 +0530 Message-ID: <20240901061808.187895-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240901061808.187895-1-umang.jain@ideasonboard.com> References: <20240901061808.187895-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240831_231826_300714_D1F5C58E X-CRM114-Status: GOOD ( 14.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Factor out bulk transfer for blocking mode into a separate dedicated function bulk_xfer_blocking_interruptible(). It is suffixed by "_interruptible" to denote that it can be interrupted and -EAGAIN can be returned. It would be up to the users of the function to retry the call in those cases. Adjust the calls to vchiq-dev.c ioctl interface and vchiq_arm.c for blocking bulk transfers. Signed-off-by: Umang Jain --- .../interface/vchiq_arm/vchiq_arm.c | 5 +-- .../interface/vchiq_arm/vchiq_core.c | 44 ++++++++++++++++--- .../interface/vchiq_arm/vchiq_core.h | 5 +++ .../interface/vchiq_arm/vchiq_dev.c | 6 +++ 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index c4d97dbf6ba8..688c9b1be868 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -968,9 +968,8 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handl return -ENOMEM; } - ret = vchiq_bulk_transfer(instance, handle, data, NULL, size, - &waiter->bulk_waiter, - VCHIQ_BULK_MODE_BLOCKING, dir); + ret = vchiq_bulk_xfer_blocking_interruptible(instance, handle, data, NULL, size, + &waiter->bulk_waiter, dir); if ((ret != -EAGAIN) || fatal_signal_pending(current) || !waiter->bulk_waiter.bulk) { struct vchiq_bulk *bulk = waiter->bulk_waiter.bulk; diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c index 6e3d24d4b720..c46634f39f4b 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c @@ -2985,6 +2985,42 @@ vchiq_remove_service(struct vchiq_instance *instance, unsigned int handle) return status; } +int +vchiq_bulk_xfer_blocking_interruptible(struct vchiq_instance *instance, unsigned int handle, + void *offset, void __user *uoffset, int size, + void __user *userdata, enum vchiq_bulk_dir dir) +{ + struct vchiq_service *service = find_service_by_handle(instance, handle); + struct bulk_waiter *bulk_waiter = NULL; + enum vchiq_bulk_mode mode = VCHIQ_BULK_MODE_BLOCKING; + int status = -EINVAL; + + if (!service) + return -EINVAL; + + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) + goto error_exit; + + if (!offset && !uoffset) + goto error_exit; + + if (vchiq_check_service(service)) + goto error_exit; + + bulk_waiter = userdata; + init_completion(&bulk_waiter->event); + bulk_waiter->actual = 0; + bulk_waiter->bulk = NULL; + + status = vchiq_bulk_xfer_queue_msg_interruptible(service, offset, uoffset, size, + userdata, mode, dir); + +error_exit: + vchiq_service_put(service); + + return status; +} + /* * This function may be called by kernel threads or user threads. * User threads may receive -EAGAIN to indicate that a signal has been @@ -2998,7 +3034,7 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, enum vchiq_bulk_mode mode, enum vchiq_bulk_dir dir) { struct vchiq_service *service = find_service_by_handle(instance, handle); - struct bulk_waiter *bulk_waiter = NULL; + struct bulk_waiter *bulk_waiter; struct vchiq_bulk *bulk; int status = -EINVAL; @@ -3018,12 +3054,6 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, case VCHIQ_BULK_MODE_NOCALLBACK: case VCHIQ_BULK_MODE_CALLBACK: break; - case VCHIQ_BULK_MODE_BLOCKING: - bulk_waiter = userdata; - init_completion(&bulk_waiter->event); - bulk_waiter->actual = 0; - bulk_waiter->bulk = NULL; - break; default: goto error_exit; } diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h index 985d9ea3a06a..2dd89101c1c6 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h @@ -474,6 +474,11 @@ extern int vchiq_bulk_xfer_waiting_interruptible(struct vchiq_instance *instance, unsigned int handle, struct bulk_waiter *userdata); +extern int +vchiq_bulk_xfer_blocking_interruptible(struct vchiq_instance *instance, unsigned int handle, + void *offset, void __user *uoffset, int size, + void __user *userdata, enum vchiq_bulk_dir dir); + extern int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, void *offset, void __user *uoffset, int size, void *userdata, enum vchiq_bulk_mode mode, diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c index 550838d2863b..830633f2326b 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c @@ -304,6 +304,12 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance, } userdata = &waiter->bulk_waiter; + + status = vchiq_bulk_xfer_blocking_interruptible(instance, args->handle, + NULL, args->data, args->size, + userdata, dir); + + goto bulk_transfer_handled; } else if (args->mode == VCHIQ_BULK_MODE_WAITING) { mutex_lock(&instance->bulk_waiter_list_mutex); list_for_each_entry(iter, &instance->bulk_waiter_list,