diff options
author | Diana Z <dzigterman@chromium.org> | 2021-09-26 22:58:48 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-15 22:42:50 +0000 |
commit | baceb4eb56d65f038ebe44b634fb4b7e858be379 (patch) | |
tree | cbd30c54b096beda625fb0b456b8e415962e4297 | |
parent | 37f77686d0d469259abb43da169cdf7b9dde5655 (diff) | |
download | chrome-ec-baceb4eb56d65f038ebe44b634fb4b7e858be379.tar.gz |
TCPMv2: Add DPM setup enum
Currently, the functions to set up VDMs return a VDO count to indicate
success versus an error. They also have a return of 0, which isn't
strictly defined in the documentation, but is used as an indication a
mode isn't supported in the TBT module at least.
Add a descriptive enum to indicate whether the module set up a message
successfully, has an unsupported mode, or encountered an error. These
should track roughly to the old positive, zero, and -1 values.
BRANCH=None
BUG=None
TEST=tast typec.Mode*.manual on voxel
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I05fe0ccc5f39e433dd4fbc39c97278b3c1542497
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3192235
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r-- | common/usbc/dp_alt_mode.c | 31 | ||||
-rw-r--r-- | common/usbc/tbt_alt_mode.c | 30 | ||||
-rw-r--r-- | common/usbc/usb_pd_dpm.c | 39 | ||||
-rw-r--r-- | include/usb_dp_alt_mode.h | 15 | ||||
-rw-r--r-- | include/usb_pd_dpm.h | 7 | ||||
-rw-r--r-- | include/usb_tbt_alt_mode.h | 20 |
6 files changed, 89 insertions, 53 deletions
diff --git a/common/usbc/dp_alt_mode.c b/common/usbc/dp_alt_mode.c index 9a3493c6e1..ecade62773 100644 --- a/common/usbc/dp_alt_mode.c +++ b/common/usbc/dp_alt_mode.c @@ -207,14 +207,15 @@ void dp_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd) } } -int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm) +enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count, + uint32_t *vdm) { const struct svdm_amode_data *modep = pd_get_amode_data(port, TCPCI_MSG_SOP, USB_SID_DISPLAYPORT); int vdo_count_ret; - if (vdo_count < VDO_MAX_SIZE) - return -1; + if (*vdo_count < VDO_MAX_SIZE) + return MSG_SETUP_ERROR; switch (dp_state[port]) { case DP_START: @@ -223,7 +224,7 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm) vdm[0] = pd_dfp_enter_mode(port, TCPCI_MSG_SOP, USB_SID_DISPLAYPORT, 0); if (vdm[0] == 0) - return -1; + return MSG_SETUP_ERROR; /* CMDT_INIT is 0, so this is a no-op */ vdm[0] |= VDO_CMDT(CMDT_INIT); vdm[0] |= VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPCI_MSG_SOP)); @@ -233,22 +234,22 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm) break; case DP_ENTER_ACKED: if (!(modep && modep->opos)) - return -1; + return MSG_SETUP_ERROR; vdo_count_ret = modep->fx->status(port, vdm); if (vdo_count_ret == 0) - return -1; + return MSG_SETUP_ERROR; vdm[0] |= PD_VDO_OPOS(modep->opos); vdm[0] |= VDO_CMDT(CMDT_INIT); vdm[0] |= VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPCI_MSG_SOP)); break; case DP_STATUS_ACKED: if (!(modep && modep->opos)) - return -1; + return MSG_SETUP_ERROR; vdo_count_ret = modep->fx->config(port, vdm); if (vdo_count_ret == 0) - return -1; + return MSG_SETUP_ERROR; vdm[0] |= VDO_CMDT(CMDT_INIT); vdm[0] |= VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPCI_MSG_SOP)); break; @@ -265,7 +266,7 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm) * TODO(b/159856063): Clean up the API to the fx functions. */ if (!(modep && modep->opos)) - return -1; + return MSG_SETUP_ERROR; usb_mux_set_safe_mode_exit(port); @@ -282,11 +283,17 @@ int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm) /* * DP mode is inactive. */ - return -1; + return MSG_SETUP_ERROR; default: CPRINTF("%s called with invalid state %d\n", __func__, dp_state[port]); - return -1; + return MSG_SETUP_ERROR; } - return vdo_count_ret; + + if (vdo_count_ret) { + *vdo_count = vdo_count_ret; + return MSG_SETUP_SUCCESS; + } + + return MSG_SETUP_UNSUPPORTED; } diff --git a/common/usbc/tbt_alt_mode.c b/common/usbc/tbt_alt_mode.c index 73e2796345..eb64519c1e 100644 --- a/common/usbc/tbt_alt_mode.c +++ b/common/usbc/tbt_alt_mode.c @@ -458,8 +458,9 @@ static bool tbt_mode_is_supported(int port, int vdo_count) return true; } -int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm, - enum tcpci_msg_type *tx_type) +enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count, + uint32_t *vdm, + enum tcpci_msg_type *tx_type) { struct svdm_amode_data *modep; int vdo_count_ret = 0; @@ -467,13 +468,13 @@ int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm, *tx_type = TCPCI_MSG_SOP; - if (vdo_count < VDO_MAX_SIZE) - return -1; + if (*vdo_count < VDO_MAX_SIZE) + return MSG_SETUP_ERROR; switch (tbt_state[port]) { case TBT_START: - if (!tbt_mode_is_supported(port, vdo_count)) - return 0; + if (!tbt_mode_is_supported(port, *vdo_count)) + return MSG_SETUP_UNSUPPORTED; if (!TBT_CHK_FLAG(port, TBT_FLAG_RETRY_DONE)) tbt_prints("attempt to enter mode", port); @@ -523,7 +524,7 @@ int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm, modep = pd_get_amode_data(port, TCPCI_MSG_SOP, USB_VID_INTEL); if (!(modep && modep->opos)) - return -1; + return MSG_SETUP_ERROR; usb_mux_set_safe_mode_exit(port); @@ -538,7 +539,7 @@ int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm, modep = pd_get_amode_data(port, TCPCI_MSG_SOP_PRIME, USB_VID_INTEL); if (!(modep && modep->opos)) - return -1; + return MSG_SETUP_ERROR; usb_mux_set_safe_mode_exit(port); @@ -554,7 +555,7 @@ int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm, modep = pd_get_amode_data(port, TCPCI_MSG_SOP_PRIME, USB_VID_INTEL); if (!(modep && modep->opos)) - return -1; + return MSG_SETUP_ERROR; usb_mux_set_safe_mode_exit(port); @@ -568,12 +569,17 @@ int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm, break; case TBT_INACTIVE: /* Thunderbolt mode is inactive */ - return 0; + return MSG_SETUP_UNSUPPORTED; default: CPRINTF("%s called with invalid state %d\n", __func__, tbt_state[port]); - return -1; + return MSG_SETUP_ERROR; } - return vdo_count_ret; + if (vdo_count_ret) { + *vdo_count = vdo_count_ret; + return MSG_SETUP_SUCCESS; + } + + return MSG_SETUP_UNSUPPORTED; } diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c index 5053f0a482..3e399489b2 100644 --- a/common/usbc/usb_pd_dpm.c +++ b/common/usbc/usb_pd_dpm.c @@ -235,6 +235,7 @@ static void dpm_attempt_mode_entry(int port) enum tcpci_msg_type tx_type = TCPCI_MSG_SOP; bool enter_mode_requested = IS_ENABLED(CONFIG_USB_PD_REQUIRE_AP_MODE_ENTRY) ? false : true; + enum dpm_msg_setup_status status = MSG_SETUP_UNSUPPORTED; if (pd_get_data_role(port) != PD_ROLE_DFP) { if (DPM_CHK_FLAG(port, DPM_FLAG_ENTER_DP | @@ -288,8 +289,9 @@ static void dpm_attempt_mode_entry(int port) * cable and USB4 mode with the port partner. */ if (tbt_cable_entry_required_for_usb4(port)) { - vdo_count = tbt_setup_next_vdm(port, - ARRAY_SIZE(vdm), vdm, &tx_type); + vdo_count = ARRAY_SIZE(vdm); + status = tbt_setup_next_vdm(port, &vdo_count, vdm, + &tx_type); } else { pd_dpm_request(port, DPM_REQUEST_ENTER_USB); return; @@ -303,24 +305,28 @@ static void dpm_attempt_mode_entry(int port) USB_VID_INTEL) && dpm_mode_entry_requested(port, TYPEC_MODE_TBT)) { enter_mode_requested = true; - vdo_count = tbt_setup_next_vdm(port, - ARRAY_SIZE(vdm), vdm, &tx_type); + vdo_count = ARRAY_SIZE(vdm); + status = tbt_setup_next_vdm(port, &vdo_count, vdm, + &tx_type); } /* If not, check if they support DisplayPort alt mode. */ - if (vdo_count == 0 && !DPM_CHK_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE) && + if (status == MSG_SETUP_UNSUPPORTED && + !DPM_CHK_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE) && pd_is_mode_discovered_for_svid(port, TCPCI_MSG_SOP, - USB_SID_DISPLAYPORT) && + USB_SID_DISPLAYPORT) && dpm_mode_entry_requested(port, TYPEC_MODE_DP)) { enter_mode_requested = true; - vdo_count = dp_setup_next_vdm(port, ARRAY_SIZE(vdm), vdm); + vdo_count = ARRAY_SIZE(vdm); + status = dp_setup_next_vdm(port, &vdo_count, vdm); } /* * If the PE didn't discover any supported (requested) alternate mode, * just mark setup done and get out of here. */ - if (vdo_count == 0 && !DPM_CHK_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE)) { + if (status != MSG_SETUP_SUCCESS && + !DPM_CHK_FLAG(port, DPM_FLAG_MODE_ENTRY_DONE)) { if (enter_mode_requested) { /* * TODO(b/168030639): Notify the AP that mode entry @@ -336,7 +342,7 @@ static void dpm_attempt_mode_entry(int port) return; } - if (vdo_count < 0) { + if (status != MSG_SETUP_SUCCESS) { dpm_set_mode_entry_done(port); CPRINTS("C%d: Couldn't construct alt mode VDM", port); return; @@ -356,8 +362,9 @@ static void dpm_attempt_mode_entry(int port) static void dpm_attempt_mode_exit(int port) { - uint32_t vdm = 0; - int vdo_count = 0; + uint32_t vdm[VDO_MAX_SIZE]; + int vdo_count = ARRAY_SIZE(vdm); + enum dpm_msg_setup_status status = MSG_SETUP_ERROR; enum tcpci_msg_type tx_type = TCPCI_MSG_SOP; if (IS_ENABLED(CONFIG_USB_PD_USB4) && @@ -374,18 +381,20 @@ static void dpm_attempt_mode_exit(int port) */ CPRINTS("C%d: TBT teardown", port); tbt_exit_mode_request(port); - vdo_count = tbt_setup_next_vdm(port, VDO_MAX_SIZE, &vdm, - &tx_type); + status = tbt_setup_next_vdm(port, &vdo_count, vdm, &tx_type); } else if (dp_is_active(port)) { CPRINTS("C%d: DP teardown", port); - vdo_count = dp_setup_next_vdm(port, VDO_MAX_SIZE, &vdm); + status = dp_setup_next_vdm(port, &vdo_count, vdm); } else { /* Clear exit mode request */ dpm_clear_mode_exit_request(port); return; } - if (!pd_setup_vdm_request(port, tx_type, &vdm, vdo_count)) { + if (status != MSG_SETUP_SUCCESS) + return; + + if (!pd_setup_vdm_request(port, tx_type, vdm, vdo_count)) { dpm_clear_mode_exit_request(port); return; } diff --git a/include/usb_dp_alt_mode.h b/include/usb_dp_alt_mode.h index ea824ea476..40b7c321dd 100644 --- a/include/usb_dp_alt_mode.h +++ b/include/usb_dp_alt_mode.h @@ -15,6 +15,7 @@ #include <stdint.h> #include "tcpm/tcpm.h" +#include "usb_pd_dpm.h" /* * Initialize DP state for the specified port. @@ -66,12 +67,14 @@ void dp_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd); /* * Construct the next DisplayPort VDM that should be sent. * - * @param port USB-C port number - * @param vdo_count The number of VDOs in vdm; must be at least VDO_MAX_SIZE - * @param vdm The VDM payload to be sent; output; must point to at least - * VDO_MAX_SIZE elements - * @return The number of VDOs written to VDM or -1 to indicate error + * @param[in] port USB-C port number + * @param[in,out] vdo_count The number of VDOs in vdm; must be at least + * VDO_MAX_SIZE. On success, number of populated VDOs + * @param[out] vdm The VDM payload to be sent; output; must point to at + * least VDO_MAX_SIZE elements + * @return enum dpm_msg_setup_status */ -int dp_setup_next_vdm(int port, int vdo_count, uint32_t *vdm); +enum dpm_msg_setup_status dp_setup_next_vdm(int port, int *vdo_count, + uint32_t *vdm); #endif /* __CROS_EC_USB_DP_ALT_MODE_H */ diff --git a/include/usb_pd_dpm.h b/include/usb_pd_dpm.h index 19d4c4fe6b..4a389b2116 100644 --- a/include/usb_pd_dpm.h +++ b/include/usb_pd_dpm.h @@ -108,4 +108,11 @@ int dpm_get_source_pdo(const uint32_t **src_pdo, const int port); */ int dpm_get_source_current(const int port); +/* Enum for modules to describe to the DPM their setup status */ +enum dpm_msg_setup_status { + MSG_SETUP_SUCCESS, + MSG_SETUP_ERROR, + MSG_SETUP_UNSUPPORTED, +}; + #endif /* __CROS_EC_USB_DPM_H */ diff --git a/include/usb_tbt_alt_mode.h b/include/usb_tbt_alt_mode.h index 1ea4828059..a187c1b42b 100644 --- a/include/usb_tbt_alt_mode.h +++ b/include/usb_tbt_alt_mode.h @@ -14,6 +14,7 @@ #include <stdint.h> #include "tcpm/tcpm.h" +#include "usb_pd_dpm.h" #include "usb_pd_tcpm.h" /* @@ -92,14 +93,17 @@ void intel_vdm_naked(int port, enum tcpci_msg_type type, uint8_t vdm_cmd); /* * Construct the next Thunderbolt VDM that should be sent. * - * @param port USB-C port number - * @param vdo_count The number of VDOs in vdm; must be at least VDO_MAX_SIZE - * @param vdm The VDM payload to be sent; output; must point to at least - * VDO_MAX_SIZE elements - * @param tx_type Transmit type(SOP, SOP', SOP'') for next VDM to be sent - * @return The number of VDOs written to VDM or -1 to indicate error + * @param[in] port USB-C port number + * @param[in,out] vdo_count The number of VDOs in vdm; must be at least + * VDO_MAX_SIZE. Filled with VDOs populated on success + * @param[out] vdm The VDM payload to be sent; output; must point to at + * least VDO_MAX_SIZE elements + * @param[out] tx_type Transmit type(SOP, SOP', SOP'') for next VDM to be + * sent + * @return enum dpm_msg_setup_status */ -int tbt_setup_next_vdm(int port, int vdo_count, uint32_t *vdm, - enum tcpci_msg_type *tx_type); +enum dpm_msg_setup_status tbt_setup_next_vdm(int port, int *vdo_count, + uint32_t *vdm, + enum tcpci_msg_type *tx_type); #endif |