diff options
author | Ayushee <ayushee.shah@intel.com> | 2020-05-28 16:37:44 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-05 10:15:38 +0000 |
commit | 5fceb8b92e1fc492036d57d1d0f9df81c6c3e2ff (patch) | |
tree | 233b50aabac969285ad4ccd1c2174caa6f0b7d55 | |
parent | c9e0e383c9279c07ddcfa12c604a259da665bebb (diff) | |
download | chrome-ec-5fceb8b92e1fc492036d57d1d0f9df81c6c3e2ff.tar.gz |
usb_pd: USB4: Limit the cable speed
Added 'get_usb4_cable_speed()' to return USB4 speed as per the port, the
speed supported by DUT's port or cable speed whichever is lowest.
Added configuring the cable speed in cros_ec_usb_pd_control according to
the mux setting.
Removed 'set_max_usb4_cable_speed()' to retain cable's actual VDO
response.
BUG=b:157671582
BRANCH=none
TEST=1. Able to set USB4/USB3.2 Gen2 cable speed when DFP isn't gen 3
capable.
2. Able to limit cable speed according to the port, if the cable
speed is higher.
Signed-off-by: Ayushee <ayushee.shah@intel.com>
Change-Id: I21bba7e5a2aa8ca54f304ef8418320f319f020b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2220826
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | common/usb_pd_alt_mode_dfp.c | 44 | ||||
-rw-r--r-- | common/usb_pd_host_cmd.c | 13 | ||||
-rw-r--r-- | common/usb_pd_policy.c | 23 | ||||
-rw-r--r-- | include/ec_commands.h | 3 | ||||
-rw-r--r-- | include/usb_pd.h | 4 |
5 files changed, 48 insertions, 39 deletions
diff --git a/common/usb_pd_alt_mode_dfp.c b/common/usb_pd_alt_mode_dfp.c index 051fa9740c..42b21a6fa8 100644 --- a/common/usb_pd_alt_mode_dfp.c +++ b/common/usb_pd_alt_mode_dfp.c @@ -881,27 +881,47 @@ __overridable enum tbt_compat_cable_speed board_get_max_tbt_speed(int port) * ############################################################################ */ -enum usb_rev30_ss get_usb4_cable_speed(int port) +/* + * For Cable rev 3.0: USB4 cable speed is set according to speed supported by + * the port and the response received from the cable, whichever is least. + * + * For Cable rev 2.0: Since board_is_tbt_usb4_port() should not enabled if the + * port supports speed less than USB_R20_SS_U31_GEN1_GEN2, USB4 cable speed is + * set according to the cable response. + */ +static enum usb_rev30_ss board_get_max_usb_cable_speed(int port) { struct pd_cable *cable = pd_get_cable_attributes(port); - /* - * TODO: Return USB4 cable speed for USB3.2 Gen 2 cables if DFP isn't - * Gen 3 capable. + * Converting Thunderbolt-Compatible board speed to equivalent USB4 + * speed. */ - if ((cable->rev == PD_REV30) && - (get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE) && - ((cable->attr.p_rev30.ss != USB_R30_SS_U32_U40_GEN2) || - !IS_ENABLED(CONFIG_USB_PD_TBT_GEN3_CAPABLE))) { - return cable->attr.p_rev30.ss; - } + enum usb_rev30_ss max_usb4_speed = + board_get_max_tbt_speed(port) == TBT_SS_TBT_GEN3 ? + USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2; + return max_usb4_speed < cable->attr.p_rev30.ss ? + max_usb4_speed : cable->attr.p_rev30.ss; +} + +enum usb_rev30_ss get_usb4_cable_speed(int port) +{ + struct pd_cable *cable = pd_get_cable_attributes(port); + enum usb_rev30_ss max_rev30_usb4_speed; + + if (cable->rev == PD_REV30) { + max_rev30_usb4_speed = board_get_max_usb_cable_speed(port); + if (!IS_ENABLED(CONFIG_USB_PD_TBT_GEN3_CAPABLE) || + max_rev30_usb4_speed != USB_R30_SS_U32_U40_GEN2 || + get_usb_pd_cable_type(port) == IDH_PTYPE_ACABLE) + return max_rev30_usb4_speed; + } /* * Converting Thunderolt-Compatible cable speed to equivalent USB4 cable * speed. */ - return cable->cable_mode_resp.tbt_cable_speed == TBT_SS_TBT_GEN3 ? - USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2; + return get_tbt_cable_speed(port) == TBT_SS_TBT_GEN3 ? + USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2; } __overridable void svdm_safe_dp_mode(int port) diff --git a/common/usb_pd_host_cmd.c b/common/usb_pd_host_cmd.c index 11345a7624..8bd9f16aea 100644 --- a/common/usb_pd_host_cmd.c +++ b/common/usb_pd_host_cmd.c @@ -296,6 +296,7 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args) struct ec_response_usb_pd_control_v1 *r_v1 = args->response; struct ec_response_usb_pd_control *r = args->response; const char *task_state_name; + mux_state_t mux_state; if (p->port >= board_get_usb_pd_port_count()) return EC_RES_INVALID_PARAM; @@ -360,8 +361,16 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args) r_v2->control_flags = get_pd_control_flags(p->port); if (IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP)) { r_v2->dp_mode = get_dp_pin_mode(p->port); - r_v2->cable_speed = get_tbt_cable_speed(p->port); - r_v2->cable_gen = get_tbt_rounded_support(p->port); + mux_state = usb_mux_get(p->port); + if (mux_state & USB_PD_MUX_USB4_ENABLED) { + r_v2->cable_speed = + get_usb4_cable_speed(p->port); + } else if (mux_state & USB_PD_MUX_TBT_COMPAT_ENABLED) { + r_v2->cable_speed = + get_tbt_cable_speed(p->port); + r_v2->cable_gen = + get_tbt_rounded_support(p->port); + } } if (args->version == 1) diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index 38bb04f83b..8a92ac879f 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -346,28 +346,6 @@ static inline void disable_usb4_mode(int port) } /* - * For Cable rev 3.0: USB4 cable speed is set according to speed supported by - * the port and the response received from the cable, whichever is least. - * - * For Cable rev 2.0: Since board_is_tbt_usb4_port() should not enabled if the - * port supports speed less than USB_R20_SS_U31_GEN1_GEN2, USB4 cable speed is - * set according to the cable response. - */ -static void set_max_usb4_cable_speed(int port) -{ - /* - * Converting Thunderbolt-Compatible board speed to equivalent USB4 - * speed. - */ - enum usb_rev30_ss max_usb4_speed = - board_get_max_tbt_speed(port) == TBT_SS_TBT_GEN3 ? - USB_R30_SS_U40_GEN3 : USB_R30_SS_U32_U40_GEN2; - - if (max_usb4_speed < cable[port].attr.p_rev30.ss) - cable[port].attr.p_rev30.ss = max_usb4_speed; -} - -/* * Ref: USB Type-C Cable and Connector Specification * Figure 5-1 USB4 Discovery and Entry Flow Model. * @@ -410,7 +388,6 @@ static bool is_cable_ready_to_enter_usb4(int port, int cnt) is_vdo_present(cnt, VDO_INDEX_PTYPE_CABLE1)) { switch (cable[port].rev) { case PD_REV30: - set_max_usb4_cable_speed(port); switch (cable[port].attr.p_rev30.ss) { case USB_R30_SS_U40_GEN3: case USB_R30_SS_U32_U40_GEN1: diff --git a/include/ec_commands.h b/include/ec_commands.h index 82a34b1666..390df6a687 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -5349,7 +5349,8 @@ struct ec_response_usb_pd_control_v2 { uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ uint8_t reserved; /* Reserved for future use */ uint8_t control_flags; /* USB_PD_CTRL_*flags */ - uint8_t cable_speed; /* TBT_SS_* cable speed */ + /* TODO: b:158234949 Add definitions for cable speed */ + uint8_t cable_speed; /* USB_R30_SS/TBT_SS_* cable speed */ uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ } __ec_align1; diff --git a/include/usb_pd.h b/include/usb_pd.h index a81a6184b3..6765a44abb 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -1969,8 +1969,10 @@ enum idh_ptype get_usb_pd_cable_type(int port); */ void dfp_consume_cable_response(int port, int cnt, uint32_t *payload, uint16_t head); + /** - * Returns USB4 cable speed. + * Returns USB4 cable speed according to the port, if port supports lesser + * USB4 cable speed than the cable. * * For USB4 cable speed = USB3.2 Gen 2: * | |