2023-04-18 16:42:25

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH v2 0/2] rpmsg: glink: Fix + cleanup in __qcom_glink_send()

Found these two things to fix/cleanup while poking around in the glink
code.

Bjorn Andersson (2):
rpmsg: glink: Propagate TX failures in intentless mode as well
rpmsg: glink: Consolidate TX_DATA and TX_DATA_CONT

drivers/rpmsg/qcom_glink_native.c | 50 ++++++++++---------------------
1 file changed, 16 insertions(+), 34 deletions(-)

--
2.25.1


2023-04-18 16:43:40

by Bjorn Andersson

[permalink] [raw]
Subject: [PATCH v2 2/2] rpmsg: glink: Consolidate TX_DATA and TX_DATA_CONT

Rather than duplicating most of the code for constructing the initial
TX_DATA and subsequent TX_DATA_CONT packets, roll them into a single
loop.

Signed-off-by: Bjorn Andersson <[email protected]>
---

Changes since v1:
- Reduced unnecessary complexity in the chunking condition

drivers/rpmsg/qcom_glink_native.c | 46 +++++++++----------------------
1 file changed, 13 insertions(+), 33 deletions(-)

diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
index 62634d020d13..7e6fad4e02f8 100644
--- a/drivers/rpmsg/qcom_glink_native.c
+++ b/drivers/rpmsg/qcom_glink_native.c
@@ -1309,7 +1309,7 @@ static int __qcom_glink_send(struct glink_channel *channel,
int ret;
unsigned long flags;
int chunk_size = len;
- int left_size = 0;
+ size_t offset = 0;

if (!glink->intentless) {
while (!intent) {
@@ -1343,49 +1343,29 @@ static int __qcom_glink_send(struct glink_channel *channel,
iid = intent->id;
}

- if (wait && chunk_size > SZ_8K) {
- chunk_size = SZ_8K;
- left_size = len - chunk_size;
- }
- req.msg.cmd = cpu_to_le16(GLINK_CMD_TX_DATA);
- req.msg.param1 = cpu_to_le16(channel->lcid);
- req.msg.param2 = cpu_to_le32(iid);
- req.chunk_size = cpu_to_le32(chunk_size);
- req.left_size = cpu_to_le32(left_size);
-
- ret = qcom_glink_tx(glink, &req, sizeof(req), data, chunk_size, wait);
-
- /* Mark intent available if we failed */
- if (ret) {
- if (intent)
- intent->in_use = false;
- return ret;
- }
-
- while (left_size > 0) {
- data = (void *)((char *)data + chunk_size);
- chunk_size = left_size;
- if (chunk_size > SZ_8K)
+ while (offset < len) {
+ chunk_size = len - offset;
+ if (chunk_size > SZ_8K && wait)
chunk_size = SZ_8K;
- left_size -= chunk_size;

- req.msg.cmd = cpu_to_le16(GLINK_CMD_TX_DATA_CONT);
+ req.msg.cmd = cpu_to_le16(offset == 0 ? GLINK_CMD_TX_DATA : GLINK_CMD_TX_DATA_CONT);
req.msg.param1 = cpu_to_le16(channel->lcid);
req.msg.param2 = cpu_to_le32(iid);
req.chunk_size = cpu_to_le32(chunk_size);
- req.left_size = cpu_to_le32(left_size);
+ req.left_size = cpu_to_le32(len - offset - chunk_size);

- ret = qcom_glink_tx(glink, &req, sizeof(req), data,
- chunk_size, wait);
-
- /* Mark intent available if we failed */
+ ret = qcom_glink_tx(glink, &req, sizeof(req), data + offset, chunk_size, wait);
if (ret) {
+ /* Mark intent available if we failed */
if (intent)
intent->in_use = false;
- break;
+ return ret;
}
+
+ offset += chunk_size;
}
- return ret;
+
+ return 0;
}

static int qcom_glink_send(struct rpmsg_endpoint *ept, void *data, int len)
--
2.25.1

2023-04-18 21:17:58

by Chris Lew

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] rpmsg: glink: Consolidate TX_DATA and TX_DATA_CONT



On 4/18/2023 9:30 AM, Bjorn Andersson wrote:
> Rather than duplicating most of the code for constructing the initial
> TX_DATA and subsequent TX_DATA_CONT packets, roll them into a single
> loop.
>
> Signed-off-by: Bjorn Andersson <[email protected]>
> ---
>
> Changes since v1:
> - Reduced unnecessary complexity in the chunking condition
>

Reviewed-by: Chris Lew <[email protected]>

> drivers/rpmsg/qcom_glink_native.c | 46 +++++++++----------------------
> 1 file changed, 13 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
> index 62634d020d13..7e6fad4e02f8 100644
> --- a/drivers/rpmsg/qcom_glink_native.c
> +++ b/drivers/rpmsg/qcom_glink_native.c
> @@ -1309,7 +1309,7 @@ static int __qcom_glink_send(struct glink_channel *channel,
> int ret;
> unsigned long flags;
> int chunk_size = len;
> - int left_size = 0;
> + size_t offset = 0;
>
> if (!glink->intentless) {
> while (!intent) {
> @@ -1343,49 +1343,29 @@ static int __qcom_glink_send(struct glink_channel *channel,
> iid = intent->id;
> }
>
> - if (wait && chunk_size > SZ_8K) {
> - chunk_size = SZ_8K;
> - left_size = len - chunk_size;
> - }
> - req.msg.cmd = cpu_to_le16(GLINK_CMD_TX_DATA);
> - req.msg.param1 = cpu_to_le16(channel->lcid);
> - req.msg.param2 = cpu_to_le32(iid);
> - req.chunk_size = cpu_to_le32(chunk_size);
> - req.left_size = cpu_to_le32(left_size);
> -
> - ret = qcom_glink_tx(glink, &req, sizeof(req), data, chunk_size, wait);
> -
> - /* Mark intent available if we failed */
> - if (ret) {
> - if (intent)
> - intent->in_use = false;
> - return ret;
> - }
> -
> - while (left_size > 0) {
> - data = (void *)((char *)data + chunk_size);
> - chunk_size = left_size;
> - if (chunk_size > SZ_8K)
> + while (offset < len) {
> + chunk_size = len - offset;
> + if (chunk_size > SZ_8K && wait)
> chunk_size = SZ_8K;
> - left_size -= chunk_size;
>
> - req.msg.cmd = cpu_to_le16(GLINK_CMD_TX_DATA_CONT);
> + req.msg.cmd = cpu_to_le16(offset == 0 ? GLINK_CMD_TX_DATA : GLINK_CMD_TX_DATA_CONT);
> req.msg.param1 = cpu_to_le16(channel->lcid);
> req.msg.param2 = cpu_to_le32(iid);
> req.chunk_size = cpu_to_le32(chunk_size);
> - req.left_size = cpu_to_le32(left_size);
> + req.left_size = cpu_to_le32(len - offset - chunk_size);
>
> - ret = qcom_glink_tx(glink, &req, sizeof(req), data,
> - chunk_size, wait);
> -
> - /* Mark intent available if we failed */
> + ret = qcom_glink_tx(glink, &req, sizeof(req), data + offset, chunk_size, wait);
> if (ret) {
> + /* Mark intent available if we failed */
> if (intent)
> intent->in_use = false;
> - break;
> + return ret;
> }
> +
> + offset += chunk_size;
> }
> - return ret;
> +
> + return 0;
> }
>
> static int qcom_glink_send(struct rpmsg_endpoint *ept, void *data, int len)
>

2023-04-19 02:01:06

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH v2 0/2] rpmsg: glink: Fix + cleanup in __qcom_glink_send()

On Tue, 18 Apr 2023 09:30:16 -0700, Bjorn Andersson wrote:
> Found these two things to fix/cleanup while poking around in the glink
> code.
>
> Bjorn Andersson (2):
> rpmsg: glink: Propagate TX failures in intentless mode as well
> rpmsg: glink: Consolidate TX_DATA and TX_DATA_CONT
>
> [...]

Applied, thanks!

[1/2] rpmsg: glink: Propagate TX failures in intentless mode as well
commit: f187a431c494348d8afdb77900fc879be73bdbf3
[2/2] rpmsg: glink: Consolidate TX_DATA and TX_DATA_CONT
commit: cc888eb072b6a48642e429a030b065d4da1d594b

Best regards,
--
Bjorn Andersson <[email protected]>