From: "Damien Riégel" <damien.riegel@silabs.com>
To: greybus-dev@lists.linaro.org
Cc: linux-kernel@vger.kernel.org, linux-devel@silabs.com,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Alex Elder" <elder@kernel.org>,
"Johan Hovold" <johan@kernel.org>,
"Damien Riégel" <damien.riegel@silabs.com>
Subject: [RFC 4/6] greybus: add API for async unidirectional transfer
Date: Fri, 4 Jul 2025 20:40:34 -0400 [thread overview]
Message-ID: <20250705004036.3828-5-damien.riegel@silabs.com> (raw)
In-Reply-To: <20250705004036.3828-1-damien.riegel@silabs.com>
This adds a helper function for unidirectional asynchronous transfer.
This is just for convenience as some drivers do these steps manually,
like the loopback driver in gb_loopback_async_operation().
Signed-off-by: Damien Riégel <damien.riegel@silabs.com>
---
drivers/greybus/operation.c | 52 +++++++++++++++++++++++++++++++
include/linux/greybus/operation.h | 4 +++
2 files changed, 56 insertions(+)
diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
index 8459e9bc074..a599b9d36cf 100644
--- a/drivers/greybus/operation.c
+++ b/drivers/greybus/operation.c
@@ -1174,6 +1174,58 @@ int gb_operation_sync_timeout(struct gb_connection *connection, int type,
}
EXPORT_SYMBOL_GPL(gb_operation_sync_timeout);
+/**
+ * gb_operation_unidirectional_async_timeout() - initiate an asynchronous unidirectional operation
+ * @connection: connection to use
+ * @callback: function called when operation completes
+ * @data: user-data, retrieved with gb_operation_get_data()
+ * @type: type of operation to send
+ * @request: memory buffer to copy the request from
+ * @request_size: size of @request
+ * @timeout: send timeout in milliseconds
+ *
+ * Initiate a unidirectional operation by sending a request message. Completion is notified by the
+ * user-provided callback. User can determine operation status with gb_operation_result().
+ * operation must be released with gb_operation_put().
+ *
+ * Note that successful send of a unidirectional operation does not imply that
+ * the request as actually reached the remote end of the connection.
+ */
+int gb_operation_unidirectional_async_timeout(struct gb_connection *connection,
+ gb_operation_callback callback, void *data,
+ int type, void *request, int request_size,
+ unsigned int timeout)
+{
+ struct gb_operation *operation;
+ int ret;
+
+ if (request_size && !request)
+ return -EINVAL;
+
+ operation = gb_operation_create_flags(connection, type,
+ request_size, 0,
+ GB_OPERATION_FLAG_UNIDIRECTIONAL,
+ GFP_KERNEL);
+ if (!operation)
+ return -ENOMEM;
+
+ gb_operation_set_data(operation, data);
+
+ if (request_size)
+ memcpy(operation->request->payload, request, request_size);
+
+ ret = gb_operation_request_send(operation, callback, timeout, GFP_KERNEL);
+ if (ret) {
+ dev_err(&connection->hd->dev,
+ "%s: asynchronous operation id 0x%04x of type 0x%02x failed: %d\n",
+ connection->name, operation->id, type, ret);
+ gb_operation_put(operation);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(gb_operation_unidirectional_async_timeout);
+
/**
* gb_operation_unidirectional_timeout() - initiate a unidirectional operation
* @connection: connection to use
diff --git a/include/linux/greybus/operation.h b/include/linux/greybus/operation.h
index cb8e4ef4522..01dd1d89d89 100644
--- a/include/linux/greybus/operation.h
+++ b/include/linux/greybus/operation.h
@@ -192,6 +192,10 @@ int gb_operation_sync_timeout(struct gb_connection *connection, int type,
void *request, int request_size,
void *response, int response_size,
unsigned int timeout);
+int gb_operation_unidirectional_async_timeout(struct gb_connection *connection,
+ gb_operation_callback callback, void *data,
+ int type, void *request, int request_size,
+ unsigned int timeout);
int gb_operation_unidirectional_timeout(struct gb_connection *connection,
int type, void *request, int request_size,
unsigned int timeout);
--
2.49.0
next prev parent reply other threads:[~2025-07-05 0:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-05 0:40 [RFC 0/6] Introducing CPC support in Greybus Damien Riégel
2025-07-05 0:40 ` [RFC 1/6] greybus: move host controller drivers comment in Makefile Damien Riégel
2025-07-16 13:20 ` Greg Kroah-Hartman
2025-07-05 0:40 ` [RFC 2/6] greybus: cpc: add core logic Damien Riégel
2025-07-16 13:21 ` Greg Kroah-Hartman
2025-07-05 0:40 ` [RFC 3/6] greybus: cpc: add SPI driver Damien Riégel
2025-07-05 0:40 ` Damien Riégel [this message]
2025-07-16 13:21 ` [RFC 4/6] greybus: add API for async unidirectional transfer Greg Kroah-Hartman
2025-07-05 0:40 ` [RFC 5/6] greybus: match device with bundle ID Damien Riégel
2025-07-16 13:19 ` Greg Kroah-Hartman
2025-07-05 0:40 ` [RFC 6/6] greybus: add class driver for Silabs Bluetooth Damien Riégel
2025-07-16 13:23 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250705004036.3828-5-damien.riegel@silabs.com \
--to=damien.riegel@silabs.com \
--cc=elder@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=johan@kernel.org \
--cc=linux-devel@silabs.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®