* [PATCH] usb: typec: ucsi: ucsi_glink: Increase buffer size to support UCSI v2
@ 2025-06-24 22:29 Anjelique Melendez
2025-06-25 1:25 ` Dmitry Baryshkov
2025-06-25 7:08 ` Greg KH
0 siblings, 2 replies; 3+ messages in thread
From: Anjelique Melendez @ 2025-06-24 22:29 UTC (permalink / raw)
To: heikki.krogerus, gregkh
Cc: lumag, neil.armstrong, johan+linaro, quic_bjorande, linux-usb,
linux-kernel, linux-arm-msm
UCSI v2 specification has increased the MSG_IN and MSG_OUT size from
16 bytes to 256 bytes each for the message exchange between OPM and PPM
This makes the total buffer size increase from 48 bytes to 528 bytes.
Update the buffer size to support this increase.
Signed-off-by: Anjelique Melendez <anjelique.melendez@oss.qualcomm.com>
---
drivers/usb/typec/ucsi/ucsi_glink.c | 50 ++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
index 8af79101a2fc..d20f01a0cd5c 100644
--- a/drivers/usb/typec/ucsi/ucsi_glink.c
+++ b/drivers/usb/typec/ucsi/ucsi_glink.c
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
* Copyright (c) 2023, Linaro Ltd
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/
#include <linux/auxiliary_bus.h>
#include <linux/module.h>
@@ -16,10 +17,11 @@
#define PMIC_GLINK_MAX_PORTS 3
-#define UCSI_BUF_SIZE 48
+#define UCSI_BUF_V1_SIZE 48
+#define UCSI_BUF_V2_SIZE 528
#define MSG_TYPE_REQ_RESP 1
-#define UCSI_BUF_SIZE 48
+#define UCSI_BUF_SIZE UCSI_BUF_V2_SIZE
#define UC_NOTIFY_RECEIVER_UCSI 0x0
#define UC_UCSI_READ_BUF_REQ 0x11
@@ -36,12 +38,24 @@ struct ucsi_read_buf_resp_msg {
u32 ret_code;
};
+struct ucsi_v1_read_buf_resp_msg {
+ struct pmic_glink_hdr hdr;
+ u8 buf[UCSI_BUF_V1_SIZE];
+ u32 ret_code;
+};
+
struct ucsi_write_buf_req_msg {
struct pmic_glink_hdr hdr;
u8 buf[UCSI_BUF_SIZE];
u32 reserved;
};
+struct ucsi_v1_write_buf_req_msg {
+ struct pmic_glink_hdr hdr;
+ u8 buf[UCSI_BUF_V1_SIZE];
+ u32 reserved;
+};
+
struct ucsi_write_buf_resp_msg {
struct pmic_glink_hdr hdr;
u32 ret_code;
@@ -133,6 +147,7 @@ static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned i
{
struct ucsi_write_buf_req_msg req = {};
unsigned long left;
+ size_t len;
int ret;
req.hdr.owner = PMIC_GLINK_OWNER_USBC;
@@ -142,7 +157,18 @@ static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned i
reinit_completion(&ucsi->write_ack);
- ret = pmic_glink_send(ucsi->client, &req, sizeof(req));
+ if (!ucsi->ucsi->version || ucsi->ucsi->version >= UCSI_VERSION_2_1) {
+ /* If UCSI version is unknown, use the maximum buffer size */
+ len = sizeof(req);
+ } else {
+ /*
+ * If UCSI V1, buffer size should be UCSI_BUF_V1_SIZE so update
+ * len accordingly
+ */
+ len = sizeof(struct ucsi_v1_write_buf_req_msg);
+ }
+
+ ret = pmic_glink_send(ucsi->client, &req, len);
if (ret < 0) {
dev_err(ucsi->dev, "failed to send UCSI write request: %d\n", ret);
return ret;
@@ -217,11 +243,25 @@ static const struct ucsi_operations pmic_glink_ucsi_ops = {
static void pmic_glink_ucsi_read_ack(struct pmic_glink_ucsi *ucsi, const void *data, int len)
{
const struct ucsi_read_buf_resp_msg *resp = data;
+ u32 ret_code, buffer_len;
+
+ if (!ucsi->ucsi->version || ucsi->ucsi->version >= UCSI_VERSION_2_1) {
+ /* If UCSI version is unknown, use the maximum buffer size */
+ ret_code = resp->ret_code;
+ buffer_len = UCSI_BUF_V2_SIZE;
+ } else {
+ /*
+ * If UCSI V1, use UCSI_BUF_V1_SIZE buffer size and
+ * update ret_code offset accordingly
+ */
+ ret_code = ((struct ucsi_v1_read_buf_resp_msg *)data)->ret_code;
+ buffer_len = UCSI_BUF_V1_SIZE;
+ }
- if (resp->ret_code)
+ if (ret_code)
return;
- memcpy(ucsi->read_buf, resp->buf, UCSI_BUF_SIZE);
+ memcpy(ucsi->read_buf, resp->buf, buffer_len);
complete(&ucsi->read_ack);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: typec: ucsi: ucsi_glink: Increase buffer size to support UCSI v2
2025-06-24 22:29 [PATCH] usb: typec: ucsi: ucsi_glink: Increase buffer size to support UCSI v2 Anjelique Melendez
@ 2025-06-25 1:25 ` Dmitry Baryshkov
2025-06-25 7:08 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Baryshkov @ 2025-06-25 1:25 UTC (permalink / raw)
To: Anjelique Melendez
Cc: heikki.krogerus, gregkh, lumag, neil.armstrong, johan+linaro,
quic_bjorande, linux-usb, linux-kernel, linux-arm-msm
On Tue, Jun 24, 2025 at 03:29:22PM -0700, Anjelique Melendez wrote:
> UCSI v2 specification has increased the MSG_IN and MSG_OUT size from
> 16 bytes to 256 bytes each for the message exchange between OPM and PPM
> This makes the total buffer size increase from 48 bytes to 528 bytes.
> Update the buffer size to support this increase.
>
> Signed-off-by: Anjelique Melendez <anjelique.melendez@oss.qualcomm.com>
> ---
> drivers/usb/typec/ucsi/ucsi_glink.c | 50 ++++++++++++++++++++++++++---
> 1 file changed, 45 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
> index 8af79101a2fc..d20f01a0cd5c 100644
> --- a/drivers/usb/typec/ucsi/ucsi_glink.c
> +++ b/drivers/usb/typec/ucsi/ucsi_glink.c
> @@ -2,6 +2,7 @@
> /*
> * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
> * Copyright (c) 2023, Linaro Ltd
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> */
> #include <linux/auxiliary_bus.h>
> #include <linux/module.h>
> @@ -16,10 +17,11 @@
>
> #define PMIC_GLINK_MAX_PORTS 3
>
> -#define UCSI_BUF_SIZE 48
> +#define UCSI_BUF_V1_SIZE 48
> +#define UCSI_BUF_V2_SIZE 528
Could you please define those using other UCSI defines?
>
> #define MSG_TYPE_REQ_RESP 1
> -#define UCSI_BUF_SIZE 48
> +#define UCSI_BUF_SIZE UCSI_BUF_V2_SIZE
I'd suggest to get rid of UCSI_BUF_SIZE and be explicit whether the code
should use v1 or v2 struct size.
>
> #define UC_NOTIFY_RECEIVER_UCSI 0x0
> #define UC_UCSI_READ_BUF_REQ 0x11
> @@ -36,12 +38,24 @@ struct ucsi_read_buf_resp_msg {
> u32 ret_code;
> };
>
> +struct ucsi_v1_read_buf_resp_msg {
> + struct pmic_glink_hdr hdr;
> + u8 buf[UCSI_BUF_V1_SIZE];
> + u32 ret_code;
> +};
> +
> struct ucsi_write_buf_req_msg {
> struct pmic_glink_hdr hdr;
> u8 buf[UCSI_BUF_SIZE];
> u32 reserved;
> };
>
> +struct ucsi_v1_write_buf_req_msg {
> + struct pmic_glink_hdr hdr;
> + u8 buf[UCSI_BUF_V1_SIZE];
> + u32 reserved;
> +};
> +
> struct ucsi_write_buf_resp_msg {
> struct pmic_glink_hdr hdr;
> u32 ret_code;
> @@ -133,6 +147,7 @@ static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned i
> {
> struct ucsi_write_buf_req_msg req = {};
> unsigned long left;
> + size_t len;
> int ret;
>
> req.hdr.owner = PMIC_GLINK_OWNER_USBC;
> @@ -142,7 +157,18 @@ static int pmic_glink_ucsi_locked_write(struct pmic_glink_ucsi *ucsi, unsigned i
>
> reinit_completion(&ucsi->write_ack);
>
> - ret = pmic_glink_send(ucsi->client, &req, sizeof(req));
> + if (!ucsi->ucsi->version || ucsi->ucsi->version >= UCSI_VERSION_2_1) {
> + /* If UCSI version is unknown, use the maximum buffer size */
> + len = sizeof(req);
> + } else {
> + /*
> + * If UCSI V1, buffer size should be UCSI_BUF_V1_SIZE so update
> + * len accordingly
> + */
> + len = sizeof(struct ucsi_v1_write_buf_req_msg);
> + }
> +
> + ret = pmic_glink_send(ucsi->client, &req, len);
> if (ret < 0) {
> dev_err(ucsi->dev, "failed to send UCSI write request: %d\n", ret);
> return ret;
> @@ -217,11 +243,25 @@ static const struct ucsi_operations pmic_glink_ucsi_ops = {
> static void pmic_glink_ucsi_read_ack(struct pmic_glink_ucsi *ucsi, const void *data, int len)
> {
> const struct ucsi_read_buf_resp_msg *resp = data;
> + u32 ret_code, buffer_len;
> +
> + if (!ucsi->ucsi->version || ucsi->ucsi->version >= UCSI_VERSION_2_1) {
Missing size checks.
> + /* If UCSI version is unknown, use the maximum buffer size */
> + ret_code = resp->ret_code;
> + buffer_len = UCSI_BUF_V2_SIZE;
> + } else {
> + /*
> + * If UCSI V1, use UCSI_BUF_V1_SIZE buffer size and
> + * update ret_code offset accordingly
> + */
> + ret_code = ((struct ucsi_v1_read_buf_resp_msg *)data)->ret_code;
> + buffer_len = UCSI_BUF_V1_SIZE;
> + }
>
> - if (resp->ret_code)
> + if (ret_code)
> return;
>
> - memcpy(ucsi->read_buf, resp->buf, UCSI_BUF_SIZE);
> + memcpy(ucsi->read_buf, resp->buf, buffer_len);
> complete(&ucsi->read_ack);
> }
>
> --
> 2.34.1
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: typec: ucsi: ucsi_glink: Increase buffer size to support UCSI v2
2025-06-24 22:29 [PATCH] usb: typec: ucsi: ucsi_glink: Increase buffer size to support UCSI v2 Anjelique Melendez
2025-06-25 1:25 ` Dmitry Baryshkov
@ 2025-06-25 7:08 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2025-06-25 7:08 UTC (permalink / raw)
To: Anjelique Melendez
Cc: heikki.krogerus, lumag, neil.armstrong, johan+linaro,
quic_bjorande, linux-usb, linux-kernel, linux-arm-msm
On Tue, Jun 24, 2025 at 03:29:22PM -0700, Anjelique Melendez wrote:
> UCSI v2 specification has increased the MSG_IN and MSG_OUT size from
> 16 bytes to 256 bytes each for the message exchange between OPM and PPM
> This makes the total buffer size increase from 48 bytes to 528 bytes.
> Update the buffer size to support this increase.
>
> Signed-off-by: Anjelique Melendez <anjelique.melendez@oss.qualcomm.com>
> ---
> drivers/usb/typec/ucsi/ucsi_glink.c | 50 ++++++++++++++++++++++++++---
> 1 file changed, 45 insertions(+), 5 deletions(-)
40 lines added new, but:
>
> diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
> index 8af79101a2fc..d20f01a0cd5c 100644
> --- a/drivers/usb/typec/ucsi/ucsi_glink.c
> +++ b/drivers/usb/typec/ucsi/ucsi_glink.c
> @@ -2,6 +2,7 @@
> /*
> * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
> * Copyright (c) 2023, Linaro Ltd
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
Please don't add odd characters, AND work with your corporate lawyers to
go over the rules for when you should, and should not, add your
copyright line to a file that you did not author from the beginning.
Hint, 40 lines added to a file that is 426 lines long does not trigger
this type of response based on the legal advice I was told to follow
many years ago, if yours differ, I would love to talk to your lawyers
about this please.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-25 7:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 22:29 [PATCH] usb: typec: ucsi: ucsi_glink: Increase buffer size to support UCSI v2 Anjelique Melendez
2025-06-25 1:25 ` Dmitry Baryshkov
2025-06-25 7:08 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox