From b2720d5f14246c088977bb8123422579d34b3dfa Mon Sep 17 00:00:00 2001 From: Diana Z Date: Mon, 16 Jan 2023 16:44:30 -0700 Subject: TCPMv2: Add host command VDM:Attention retrieval Add onto the existing VDM_RESPONSE host command to allow the AP to retrieve VDM:Attention messages. BRANCH=None BUG=b:208884535 TEST=build, deploy on skyrim and confirm ectool shows Attention messages from the queue until it empties Change-Id: Ice2e23b745f0faf892d2fd598c6e573e63e6a982 Signed-off-by: Diana Z Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4171491 Reviewed-by: Abe Levkoy --- common/usbc/usb_pd_dpm.c | 2 ++ common/usbc/usb_pd_host.c | 6 ++++++ include/ec_commands.h | 12 +++++++++++- util/ectool.cc | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c index e71cf99b86..2fc75bc746 100644 --- a/common/usbc/usb_pd_dpm.c +++ b/common/usbc/usb_pd_dpm.c @@ -199,6 +199,8 @@ static void vdm_attention_enqueue(int port, int length, uint32_t *buf) /* Note: this should not happen, but log anyway */ if (queue_add_unit(&dpm[port].attention_queue, &new_entry) == 0) CPRINTS("Error: Dropping port %d Attention", port); + else + pd_notify_event(port, PD_STATUS_EVENT_VDM_ATTENTION); mutex_unlock(&dpm[port].queue_lock); #endif /* CONFIG_USB_PD_VDM_AP_CONTROL */ diff --git a/common/usbc/usb_pd_host.c b/common/usbc/usb_pd_host.c index e2d1f36a61..76eaba4b7e 100644 --- a/common/usbc/usb_pd_host.c +++ b/common/usbc/usb_pd_host.c @@ -268,6 +268,12 @@ static enum ec_status hc_typec_vdm_response(struct host_cmd_handler_args *args) memcpy(r->vdm_response, data, r->vdm_data_objects * sizeof(uint32_t)); + r->vdm_attention_objects = + dpm_vdm_attention_pop(p->port, data, &r->vdm_attention_left); + if (r->vdm_attention_objects > 0) + memcpy(r->vdm_attention, data, + r->vdm_attention_objects * sizeof(uint32_t)); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_TYPEC_VDM_RESPONSE, hc_typec_vdm_response, diff --git a/include/ec_commands.h b/include/ec_commands.h index 35fe03d29d..1a059ce1a2 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -6929,6 +6929,7 @@ enum tcpc_cc_polarity { #define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5) #define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6) #define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7) +#define PD_STATUS_EVENT_VDM_ATTENTION BIT(8) /* * Encode and decode for BCD revision response @@ -7362,7 +7363,8 @@ struct ec_params_rgbkbd_set_color { } __ec_align1; /* - * Gather the response to the most recent VDM REQ from the AP + * Gather the response to the most recent VDM REQ from the AP, as well + * as popping the oldest VDM:Attention from the DPM queue */ #define EC_CMD_TYPEC_VDM_RESPONSE 0x013C @@ -7379,6 +7381,14 @@ struct ec_response_typec_vdm_response { uint16_t vdm_response_err; /* VDM data, including VDM header */ uint32_t vdm_response[VDO_MAX_SIZE]; + /* Number of 32-bit Attention fields filled in */ + uint8_t vdm_attention_objects; + /* Number of remaining messages to consume */ + uint8_t vdm_attention_left; + /* Reserved */ + uint16_t reserved1; + /* VDM:Attention contents */ + uint32_t vdm_attention[2]; } __ec_align1; /*****************************************************************************/ diff --git a/util/ectool.cc b/util/ectool.cc index c413654d32..c997e8e7c3 100644 --- a/util/ectool.cc +++ b/util/ectool.cc @@ -10729,6 +10729,17 @@ int cmd_typec_vdm_response(int argc, char *argv[]) r->vdm_response_err); } + if (r->vdm_attention_objects > 0) { + printf("VDM Attention:"); + for (i = 0; i < r->vdm_attention_objects; i++) + printf("\n 0x%08x", r->vdm_attention[i]); + printf("\n"); + printf("%d Attention messages remaining\n", + r->vdm_attention_left); + } else { + printf("No VDM Attention found"); + } + return 0; } -- cgit v1.2.1