From: "Damien Riégel" <damien.riegel@silabs.com>
To: greybus-dev@lists.linaro.org, Johan Hovold <johan@kernel.org>,
Alex Elder <elder@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org
Cc: "Silicon Labs Kernel Team" <linux-devel@silabs.com>,
"Damien Riégel" <damien.riegel@silabs.com>
Subject: [RFC PATCH v2 04/12] greybus: cpc: pack cport ID in Greybus header
Date: Fri, 14 Nov 2025 10:07:30 -0500 [thread overview]
Message-ID: <20251114150738.32426-5-damien.riegel@silabs.com> (raw)
In-Reply-To: <20251114150738.32426-1-damien.riegel@silabs.com>
Take advantage of the padding bytes present in the Greybus header to
store the CPort ID and minize overhead. This technique is already used
by the es2 driver.
Signed-off-by: Damien Riégel <damien.riegel@silabs.com>
---
drivers/greybus/cpc/cpc.h | 3 +++
drivers/greybus/cpc/cport.c | 29 +++++++++++++++++++++++++++++
drivers/greybus/cpc/host.c | 13 ++++++++++++-
drivers/greybus/cpc/host.h | 2 +-
4 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/drivers/greybus/cpc/cpc.h b/drivers/greybus/cpc/cpc.h
index 7e032f6cf50..0f2d204d86d 100644
--- a/drivers/greybus/cpc/cpc.h
+++ b/drivers/greybus/cpc/cpc.h
@@ -24,6 +24,9 @@ struct cpc_cport {
struct cpc_cport *cpc_cport_alloc(u16 cport_id, gfp_t gfp_mask);
void cpc_cport_release(struct cpc_cport *cport);
+void cpc_cport_pack(struct gb_operation_msg_hdr *gb_hdr, u16 cport_id);
+u16 cpc_cport_unpack(struct gb_operation_msg_hdr *gb_hdr);
+
int cpc_cport_transmit(struct cpc_cport *cport, struct sk_buff *skb);
struct cpc_skb_cb {
diff --git a/drivers/greybus/cpc/cport.c b/drivers/greybus/cpc/cport.c
index ed0b8e8b0d7..0fc4ff0c5bb 100644
--- a/drivers/greybus/cpc/cport.c
+++ b/drivers/greybus/cpc/cport.c
@@ -3,6 +3,9 @@
* Copyright (c) 2025, Silicon Laboratories, Inc.
*/
+#include <linux/unaligned.h>
+#include <linux/skbuff.h>
+
#include "cpc.h"
#include "host.h"
@@ -31,6 +34,27 @@ void cpc_cport_release(struct cpc_cport *cport)
kfree(cport);
}
+/**
+ * cpc_cport_pack() - Pack CPort ID into Greybus Operation Message header.
+ * @gb_hdr: Greybus operation message header.
+ * @cport_id: CPort ID to pack.
+ */
+void cpc_cport_pack(struct gb_operation_msg_hdr *gb_hdr, u16 cport_id)
+{
+ put_unaligned_le16(cport_id, gb_hdr->pad);
+}
+
+/**
+ * cpc_cport_unpack() - Unpack CPort ID from Greybus Operation Message header.
+ * @gb_hdr: Greybus operation message header.
+ *
+ * Return: CPort ID packed in the header.
+ */
+u16 cpc_cport_unpack(struct gb_operation_msg_hdr *gb_hdr)
+{
+ return get_unaligned_le16(gb_hdr->pad);
+}
+
/**
* cpc_cport_transmit() - Transmit skb over cport.
* @cport: cport.
@@ -39,6 +63,11 @@ void cpc_cport_release(struct cpc_cport *cport)
int cpc_cport_transmit(struct cpc_cport *cport, struct sk_buff *skb)
{
struct cpc_host_device *cpc_hd = cport->cpc_hd;
+ struct gb_operation_msg_hdr *gb_hdr;
+
+ /* Inject cport ID in Greybus header */
+ gb_hdr = (struct gb_operation_msg_hdr *)skb->data;
+ cpc_cport_pack(gb_hdr, cport->id);
return cpc_hd_send_skb(cpc_hd, skb);
}
diff --git a/drivers/greybus/cpc/host.c b/drivers/greybus/cpc/host.c
index 2ca938c2b48..1d81c624dd6 100644
--- a/drivers/greybus/cpc/host.c
+++ b/drivers/greybus/cpc/host.c
@@ -204,8 +204,19 @@ void cpc_hd_message_sent(struct sk_buff *skb, int status)
}
EXPORT_SYMBOL_GPL(cpc_hd_message_sent);
-void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, u16 cport_id, u8 *data, size_t length)
+void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, u8 *data, size_t length)
{
+ struct gb_operation_msg_hdr *gb_hdr;
+ u16 cport_id;
+
+ /* Prevent an out-of-bound access if called with non-sensical parameters. */
+ if (!data || length < sizeof(*gb_hdr))
+ return;
+
+ /* Retrieve cport ID that was packed in Greybus header */
+ gb_hdr = (struct gb_operation_msg_hdr *)data;
+ cport_id = cpc_cport_unpack(gb_hdr);
+
greybus_data_rcvd(cpc_hd->gb_hd, cport_id, data, length);
}
EXPORT_SYMBOL_GPL(cpc_hd_rcvd);
diff --git a/drivers/greybus/cpc/host.h b/drivers/greybus/cpc/host.h
index 104d61e3bc5..86d205fcb59 100644
--- a/drivers/greybus/cpc/host.h
+++ b/drivers/greybus/cpc/host.h
@@ -45,7 +45,7 @@ struct cpc_host_device *cpc_hd_create(struct cpc_hd_driver *driver, struct devic
int cpc_hd_add(struct cpc_host_device *cpc_hd);
void cpc_hd_put(struct cpc_host_device *cpc_hd);
void cpc_hd_del(struct cpc_host_device *cpc_hd);
-void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, u16 cport_id, u8 *data, size_t length);
+void cpc_hd_rcvd(struct cpc_host_device *cpc_hd, u8 *data, size_t length);
void cpc_hd_message_sent(struct sk_buff *skb, int status);
int cpc_hd_send_skb(struct cpc_host_device *cpc_hd, struct sk_buff *skb);
--
2.49.0
next prev parent reply other threads:[~2025-11-14 15:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 15:07 [RFC PATCH v2 00/12] greybus: introduce CPC as transport layer Damien Riégel
2025-11-14 15:07 ` [RFC PATCH v2 01/12] greybus: cpc: add minimal CPC Host Device infrastructure Damien Riégel
2025-11-14 16:44 ` Yacin Belmihoub-Martel
2025-11-14 16:51 ` Yacin Belmihoub-Martel
2025-11-14 16:55 ` Yacin Belmihoub-Martel
2025-11-14 15:07 ` [RFC PATCH v2 02/12] greybus: cpc: introduce CPC cport structure Damien Riégel
2025-11-14 15:07 ` [RFC PATCH v2 03/12] greybus: cpc: use socket buffers instead of gb_message in TX path Damien Riégel
2025-11-14 15:07 ` Damien Riégel [this message]
2025-11-14 15:07 ` [RFC PATCH v2 05/12] greybus: cpc: switch RX path to socket buffers Damien Riégel
2025-11-14 15:07 ` [RFC PATCH v2 06/12] greybus: cpc: introduce CPC header structure Damien Riégel
2025-11-14 15:07 ` [RFC PATCH v2 07/12] greybus: cpc: account for CPC header size in RX and TX path Damien Riégel
2025-11-14 15:07 ` [RFC PATCH v2 08/12] greybus: cpc: add and validate sequence numbers Damien Riégel
2025-11-14 15:07 ` [RFC PATCH v2 09/12] greybus: cpc: acknowledge all incoming messages Damien Riégel
2025-11-14 15:07 ` [RFC PATCH v2 10/12] greybus: cpc: use holding queue instead of sending out immediately Damien Riégel
2025-11-14 19:53 ` Yacin Belmihoub-Martel
2025-11-14 15:07 ` [RFC PATCH v2 11/12] greybus: cpc: honour remote's RX window Damien Riégel
2025-11-14 20:28 ` Yacin Belmihoub-Martel
2025-11-14 15:07 ` [RFC PATCH v2 12/12] greybus: cpc: let host device drivers dequeue TX frames Damien Riégel
2025-11-25 15:26 ` [RFC PATCH v2 00/12] greybus: introduce CPC as transport layer Damien Riégel
2025-11-26 12:33 ` Greg Kroah-Hartman
2025-12-01 15:39 ` Damien Riégel
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=20251114150738.32426-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®