]> www.infradead.org Git - linux.git/commitdiff
staging: vchiq: Factor out bulk transfer for VCHIQ_BULK_MODE_WAITING
authorUmang Jain <umang.jain@ideasonboard.com>
Tue, 10 Sep 2024 05:10:01 +0000 (10:40 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 11 Sep 2024 13:54:04 +0000 (15:54 +0200)
The bulk transfer is VCHIQ_BULK_MODE_WAITING is used by VCHIQ ioctl
interface. It is factored out to a separate function from
vchiq_bulk_transfer() to bulk_xfer_waiting_interruptible().

This is a part of vchiq_bulk_transfer refactoring. Each bulk mode
will have their dedicated functions to execute bulk transfers.
Each mode will be handled separately in subsequent patches.

bulk_xfer_waiting_interruptible() is suffixed with "_interruptible"
to denote that it can be interrupted when a signal is received.
-EAGAIN maybe returned in those cases, similar to what
vchiq_bulk_transfer() does.

Adjust the vchiq_irq_queue_bulk_tx_rx() in the vchiq-dev.c to call
bulk_xfer_waiting_interruptible() for waiting mode. A temporary
goto label has been introduced to jump the call execution over
vchiq_bulk_transfer() for waiting mode only. When all dedicated bulk
transfer calls are introduced, this label shall be dropped.

No function changes intended in this patch.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Tested-by: Stefan Wahren <wahrenst@gmx.net>
Link: https://lore.kernel.org/r/20240910051007.297227-2-umang.jain@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c

index 50af04b217f4b8a72063efce62276b7733e6a174..2239f59519be6f706b04da23123b1d2175da2761 100644 (file)
@@ -3023,10 +3023,6 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle,
                bulk_waiter->actual = 0;
                bulk_waiter->bulk = NULL;
                break;
-       case VCHIQ_BULK_MODE_WAITING:
-               bulk_waiter = userdata;
-               bulk = bulk_waiter->bulk;
-               goto waiting;
        default:
                goto error_exit;
        }
@@ -3115,11 +3111,8 @@ int vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle,
                state->id, service->localport, dir_char, queue->local_insert,
                queue->remote_insert, queue->process);
 
-waiting:
        vchiq_service_put(service);
 
-       status = 0;
-
        if (bulk_waiter) {
                bulk_waiter->bulk = bulk;
                if (wait_for_completion_interruptible(&bulk_waiter->event))
@@ -3128,7 +3121,7 @@ waiting:
                        status = -EINVAL;
        }
 
-       return status;
+       return 0;
 
 unlock_both_error_exit:
        mutex_unlock(&state->slot_mutex);
@@ -3143,6 +3136,50 @@ error_exit:
        return status;
 }
 
+/*
+ * This function is called by VCHIQ ioctl interface and is interruptible.
+ * It may receive -EAGAIN to indicate that a signal has been received
+ * and the call should be retried after being returned to user context.
+ */
+int
+vchiq_bulk_xfer_waiting_interruptible(struct vchiq_instance *instance,
+                                     unsigned int handle, struct bulk_waiter *userdata)
+{
+       struct vchiq_service *service = find_service_by_handle(instance, handle);
+       struct bulk_waiter *bulk_waiter;
+       int status = -EINVAL;
+
+       if (!service)
+               return -EINVAL;
+
+       if (!userdata)
+               goto error_exit;
+
+       if (service->srvstate != VCHIQ_SRVSTATE_OPEN)
+               goto error_exit;
+
+       if (vchiq_check_service(service))
+               goto error_exit;
+
+       bulk_waiter = userdata;
+
+       vchiq_service_put(service);
+
+       status = 0;
+
+       if (wait_for_completion_interruptible(&bulk_waiter->event))
+               return -EAGAIN;
+       else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
+               return -EINVAL;
+
+       return status;
+
+error_exit:
+       vchiq_service_put(service);
+
+       return status;
+}
+
 int
 vchiq_queue_message(struct vchiq_instance *instance, unsigned int handle,
                    ssize_t (*copy_callback)(void *context, void *dest,
index 77cc4d7ac0776888cc128864b3e8b9ac6f0a3f11..985d9ea3a06a5a8e14088febbc30d08c39fbb810 100644 (file)
@@ -470,6 +470,10 @@ vchiq_shutdown_internal(struct vchiq_state *state, struct vchiq_instance *instan
 extern void
 remote_event_pollall(struct vchiq_state *state);
 
+extern int
+vchiq_bulk_xfer_waiting_interruptible(struct vchiq_instance *instance,
+                                     unsigned int handle, struct bulk_waiter *userdata);
+
 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,
index 9cd2a64dce5e688ac4d2e11dbe45a743f9bf4726..550838d2863b8c304fac9f2f3ee23d9ca7408d29 100644 (file)
@@ -324,6 +324,10 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
                dev_dbg(service->state->dev, "arm: found bulk_waiter %pK for pid %d\n",
                        waiter, current->pid);
                userdata = &waiter->bulk_waiter;
+
+               status = vchiq_bulk_xfer_waiting_interruptible(instance, args->handle, userdata);
+
+               goto bulk_transfer_handled;
        } else {
                userdata = args->userdata;
        }
@@ -331,6 +335,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
        status = vchiq_bulk_transfer(instance, args->handle, NULL, args->data, args->size,
                                     userdata, args->mode, dir);
 
+bulk_transfer_handled:
        if (!waiter) {
                ret = 0;
                goto out;