summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorli feng <li1.feng@intel.com>2020-08-21 11:01:02 -0700
committerCommit Bot <commit-bot@chromium.org>2020-08-28 22:32:00 +0000
commitb71c0ab3f72f0207e03649a9c27bc8a0b4bb04da (patch)
tree30791b7674cd765a367b76cb8f43216bda392455 /common
parentcb0d7601582f84b8e64953cbba5b3f6dc4642742 (diff)
downloadchrome-ec-b71c0ab3f72f0207e03649a9c27bc8a0b4bb04da.tar.gz
TCPMv2: set VDM response buffer and length
Pass tx_emsg[port].buf to VDM response implementation functions Convert data objects count to bytes VDM header in VDM response message should not use USB_VID_GOOGLE as SVID to respond to all requests. Save SVID from received request and compose response VDM header with this SVID. BUG=b:148528713,b:157163664 BRANCH=none TEST=Connect volteer to Gatkex DFP port, with CL:2370045, check VDM response messages from Volteer have correct contents. Signed-off-by: li feng <li1.feng@intel.com> Change-Id: I7403af1449abfa4ebf6b43ded457e3654396aadb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2368067 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/usbc/usb_pe_drp_sm.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 4f6ff2ac1c..7683fe1aaf 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -4923,9 +4923,10 @@ static void pe_vdm_request_dpm_exit(int port)
*/
static void pe_vdm_response_entry(int port)
{
- int ret = 0;
+ int response_size_bytes = 0;
uint32_t *rx_payload;
uint32_t *tx_payload;
+ uint16_t vdo_vdm_svid;
uint8_t vdo_cmd;
int cmd_type;
svdm_rsp_func func = NULL;
@@ -4937,6 +4938,8 @@ static void pe_vdm_response_entry(int port)
/* Get the message */
rx_payload = (uint32_t *)rx_emsg[port].buf;
+
+ vdo_vdm_svid = PD_VDO_VID(rx_payload[0]);
vdo_cmd = PD_VDO_CMD(rx_payload[0]);
cmd_type = PD_VDO_CMDT(rx_payload[0]);
rx_payload[0] &= ~VDO_CMDT_MASK;
@@ -4987,19 +4990,33 @@ static void pe_vdm_response_entry(int port)
tx_payload = (uint32_t *)tx_emsg[port].buf;
if (func) {
- ret = func(port, rx_payload);
- if (ret)
+ /*
+ * Designed in TCPMv1, svdm_response functions use same
+ * buffer to take received data and overwrite with response
+ * data. To work with this interface, here copy rx data to
+ * tx buffer and pass tx_payload to func.
+ * TODO(b/166455363): change the interface to pass both rx
+ * and tx buffer
+ */
+ memcpy(tx_payload, rx_payload, rx_emsg[port].len);
+ /*
+ * Return value of func is the data objects count in payload.
+ * return 1 means only VDM header, no VDO.
+ */
+ response_size_bytes =
+ func(port, tx_payload) * sizeof(*tx_payload);
+ if (response_size_bytes > 0)
/* ACK */
tx_payload[0] = VDO(
- USB_VID_GOOGLE,
+ vdo_vdm_svid,
1, /* Structured VDM */
VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP))
| VDO_CMDT(CMDT_RSP_ACK) |
vdo_cmd);
- else if (!ret)
+ else if (response_size_bytes == 0)
/* NAK */
tx_payload[0] = VDO(
- USB_VID_GOOGLE,
+ vdo_vdm_svid,
1, /* Structured VDM */
VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP))
| VDO_CMDT(CMDT_RSP_NAK) |
@@ -5007,27 +5024,27 @@ static void pe_vdm_response_entry(int port)
else
/* BUSY */
tx_payload[0] = VDO(
- USB_VID_GOOGLE,
+ vdo_vdm_svid,
1, /* Structured VDM */
VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP))
| VDO_CMDT(CMDT_RSP_BUSY) |
vdo_cmd);
- if (ret <= 0)
- ret = 4;
+ if (response_size_bytes <= 0)
+ response_size_bytes = 4;
} else {
- /* not supported : NACK it */
+ /* not supported : NAK it */
tx_payload[0] = VDO(
- USB_VID_GOOGLE,
+ vdo_vdm_svid,
1, /* Structured VDM */
VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP)) |
VDO_CMDT(CMDT_RSP_NAK) |
vdo_cmd);
- ret = 4;
+ response_size_bytes = 4;
}
/* Send ACK, NAK, or BUSY */
- tx_emsg[port].len = ret;
+ tx_emsg[port].len = response_size_bytes;
send_data_msg(port, TCPC_TX_SOP, PD_DATA_VENDOR_DEF);
}