summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyushee <ayushee.shah@intel.com>2020-06-16 13:55:08 -0700
committerCommit Bot <commit-bot@chromium.org>2020-06-26 09:30:36 +0000
commitd8c83aa6b30658ccb8d8ef1e46cc5d30dc491ebe (patch)
treed0c870e4d524ed59ac17e68eb42e41d6c7baafe3
parentc0cee430c75fd428876416c7b3ede705c19dce0f (diff)
downloadchrome-ec-d8c83aa6b30658ccb8d8ef1e46cc5d30dc491ebe.tar.gz
usb_pd: Remove pd_cable dependent Thunderbolt code from common code
1. Separated the common functions needed to check for port/cable's Thunderbolt mode compatibility back into TCPMv1. 2. Refactored the common Thunderbolt mode functions using pd_cable structure for mode information by adding a. Generic function that returns the Discover Mode response of specified SVID. b. Thunderbolt specific functiion that returns Discover Mode response of Intel SVID. 3. Removed the redundant pd_cable structure from DRP state machine policy engine. BUG=b:158294748 b:150611251 BRANCH=None TEST=1. Able to enter into Thunderbolt mode on TCPMv1 Change-Id: I30c8f1a007228408e08520502db00601ca3a2521 Signed-off-by: Ayushee <ayushee.shah@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2249020 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Commit-Queue: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--common/usb_pd_alt_mode_dfp.c117
-rw-r--r--common/usb_pd_host_cmd.c10
-rw-r--r--common/usb_pd_policy.c59
-rw-r--r--common/usbc/usb_pe_drp_sm.c14
-rw-r--r--common/usbc/usb_sm.c26
-rw-r--r--driver/retimer/bb_retimer.c5
-rw-r--r--include/usb_pd.h80
7 files changed, 129 insertions, 182 deletions
diff --git a/common/usb_pd_alt_mode_dfp.c b/common/usb_pd_alt_mode_dfp.c
index dcca9dde47..2310c47d0e 100644
--- a/common/usb_pd_alt_mode_dfp.c
+++ b/common/usb_pd_alt_mode_dfp.c
@@ -579,6 +579,27 @@ enum pd_discovery_state pd_get_modes_discovery(int port,
return mode_data->discovery;
}
+int pd_get_mode_vdo_for_svid(int port, enum tcpm_transmit_type type,
+ uint16_t svid, uint32_t *vdo_out)
+{
+ int idx;
+ struct pd_discovery *disc;
+
+ if (type >= DISCOVERY_TYPE_COUNT)
+ return 0;
+
+ disc = pd_get_am_discovery(port, type);
+
+ for (idx = 0; idx < disc->svid_cnt; ++idx) {
+ if (pd_get_svid(port, idx, type) == svid) {
+ memcpy(vdo_out, disc->svids[idx].mode_vdo,
+ sizeof(uint32_t) * disc->svids[idx].mode_cnt);
+ return disc->svids[idx].mode_cnt;
+ }
+ }
+ return 0;
+}
+
struct svid_mode_data *pd_get_next_mode(int port,
enum tcpm_transmit_type type)
{
@@ -728,6 +749,14 @@ bool is_active_cable_element_retimer(int port)
* ############################################################################
*/
+uint32_t pd_get_tbt_mode_vdo(int port, enum tcpm_transmit_type type)
+{
+ uint32_t tbt_mode_vdo[PDO_MODES];
+
+ return pd_get_mode_vdo_for_svid(port, type, USB_VID_INTEL,
+ tbt_mode_vdo) ? tbt_mode_vdo[0] : 0;
+}
+
/* TODO (b/148528713): Need to enable Thunderbolt-compatible mode on TCPMv2 */
void set_tbt_compat_mode_ready(int port)
{
@@ -779,59 +808,28 @@ bool is_tbt_cable_superspeed(int port)
USB_R20_SS_U31_GEN1_GEN2;
}
-bool is_modal(int port, int cnt, const uint32_t *payload)
-{
- return is_vdo_present(cnt, VDO_INDEX_IDH) &&
- PD_IDH_IS_MODAL(payload[VDO_INDEX_IDH]);
-}
-
-bool is_tbt_compat_mode(int port, int cnt, const uint32_t *payload)
-{
- /*
- * Ref: USB Type-C cable and connector specification
- * F.2.5 TBT3 Device Discover Mode Responses
- */
- return is_vdo_present(cnt, VDO_INDEX_IDH) &&
- PD_VDO_RESP_MODE_INTEL_TBT(payload[VDO_INDEX_IDH]);
-}
-
enum tbt_compat_cable_speed get_tbt_cable_speed(int port)
{
- struct pd_cable *cable = pd_get_cable_attributes(port);
+ union tbt_mode_resp_cable cable_mode_resp = {
+ .raw_value = pd_get_tbt_mode_vdo(port, TCPC_TX_SOP_PRIME) };
enum tbt_compat_cable_speed max_tbt_speed =
board_get_max_tbt_speed(port);
- return cable->cable_mode_resp.tbt_cable_speed > max_tbt_speed ?
- max_tbt_speed : cable->cable_mode_resp.tbt_cable_speed;
-}
-
-bool cable_supports_tbt_speed(int port)
-{
- enum tbt_compat_cable_speed tbt_cable_speed =
- get_tbt_cable_speed(port);
-
- return (tbt_cable_speed == TBT_SS_TBT_GEN3 ||
- tbt_cable_speed == TBT_SS_U32_GEN1_GEN2);
+ return cable_mode_resp.tbt_cable_speed > max_tbt_speed ?
+ max_tbt_speed : cable_mode_resp.tbt_cable_speed;
}
-/*
- * Enter Thunderbolt-compatible mode
- * Reference: USB Type-C cable and connector specification, Release 2.0
- */
int enter_tbt_compat_mode(int port, enum tcpm_transmit_type sop,
uint32_t *payload)
{
union tbt_dev_mode_enter_cmd enter_dev_mode = { .raw_value = 0 };
- struct pd_cable *cable = pd_get_cable_attributes(port);
+ union tbt_mode_resp_device dev_mode_resp;
+ union tbt_mode_resp_cable cable_mode_resp;
/* Table F-12 TBT3 Cable Enter Mode Command */
- /*
- * Although TCPMv2 contemplates separate mode storage for each SOP
- * type, TCPMv1 stores everything in the array for SOP.
- */
- /* TODO(b/148528713): Make this function generic to TCPM version. */
- payload[0] = pd_dfp_enter_mode(port, TCPC_TX_SOP, USB_VID_INTEL, 0) |
- VDO_SVDM_VERS(VDM_VER20);
+ payload[0] = pd_dfp_enter_mode(port, sop, USB_VID_INTEL, 0) |
+ VDO_CMDT(CMDT_INIT) |
+ VDO_SVDM_VERS(pd_get_vdo_ver(port, TCPC_TX_SOP));
/* For TBT3 Cable Enter Mode Command, number of Objects is 1 */
if ((sop == TCPC_TX_SOP_PRIME) ||
@@ -840,27 +838,29 @@ int enter_tbt_compat_mode(int port, enum tcpm_transmit_type sop,
usb_mux_set_safe_mode(port);
+ dev_mode_resp.raw_value = pd_get_tbt_mode_vdo(port, TCPC_TX_SOP);
+ cable_mode_resp.raw_value =
+ pd_get_tbt_mode_vdo(port, TCPC_TX_SOP_PRIME);
+
/* Table F-13 TBT3 Device Enter Mode Command */
- enter_dev_mode.vendor_spec_b1 =
- cable->dev_mode_resp.vendor_spec_b1;
- enter_dev_mode.vendor_spec_b0 =
- cable->dev_mode_resp.vendor_spec_b0;
- enter_dev_mode.intel_spec_b0 = cable->dev_mode_resp.intel_spec_b0;
+ enter_dev_mode.vendor_spec_b1 = dev_mode_resp.vendor_spec_b1;
+ enter_dev_mode.vendor_spec_b0 = dev_mode_resp.vendor_spec_b0;
+ enter_dev_mode.intel_spec_b0 = dev_mode_resp.intel_spec_b0;
enter_dev_mode.cable =
get_usb_pd_cable_type(port) == IDH_PTYPE_PCABLE ?
TBT_ENTER_PASSIVE_CABLE : TBT_ENTER_ACTIVE_CABLE;
- if (cable->cable_mode_resp.tbt_cable_speed == TBT_SS_TBT_GEN3) {
+ if (cable_mode_resp.tbt_cable_speed == TBT_SS_TBT_GEN3) {
enter_dev_mode.lsrx_comm =
- cable->cable_mode_resp.lsrx_comm;
+ cable_mode_resp.lsrx_comm;
enter_dev_mode.retimer_type =
- cable->cable_mode_resp.retimer_type;
+ cable_mode_resp.retimer_type;
enter_dev_mode.tbt_cable =
- cable->cable_mode_resp.tbt_cable;
+ cable_mode_resp.tbt_cable;
enter_dev_mode.tbt_rounded =
- cable->cable_mode_resp.tbt_rounded;
+ cable_mode_resp.tbt_rounded;
enter_dev_mode.tbt_cable_speed =
- cable->cable_mode_resp.tbt_cable_speed;
+ cable_mode_resp.tbt_cable_speed;
} else {
enter_dev_mode.tbt_cable_speed = TBT_SS_U32_GEN1_GEN2;
}
@@ -872,14 +872,23 @@ int enter_tbt_compat_mode(int port, enum tcpm_transmit_type sop,
return 2;
}
+enum tbt_compat_rounded_support get_tbt_rounded_support(int port)
+{
+ union tbt_mode_resp_cable cable_mode_resp = {
+ .raw_value = pd_get_tbt_mode_vdo(port, TCPC_TX_SOP_PRIME) };
+
+ /* tbt_rounded_support is zero when uninitialized */
+ return cable_mode_resp.tbt_rounded;
+}
+
/* Return the current cable speed received from Cable Discover Mode command */
__overridable enum tbt_compat_cable_speed board_get_max_tbt_speed(int port)
{
- struct pd_cable *cable = pd_get_cable_attributes(port);
+ union tbt_mode_resp_cable cable_mode_resp = {
+ .raw_value = pd_get_tbt_mode_vdo(port, TCPC_TX_SOP_PRIME) };
- return cable->cable_mode_resp.tbt_cable_speed;
+ return cable_mode_resp.tbt_cable_speed;
}
-
/*
* ############################################################################
*
diff --git a/common/usb_pd_host_cmd.c b/common/usb_pd_host_cmd.c
index 3a26018e64..19e74b47aa 100644
--- a/common/usb_pd_host_cmd.c
+++ b/common/usb_pd_host_cmd.c
@@ -253,8 +253,14 @@ static const mux_state_t typec_mux_map[USB_PD_CTRL_MUX_COUNT] = {
*/
static uint8_t get_pd_control_flags(int port)
{
- union tbt_mode_resp_cable cable_resp = get_cable_tbt_vdo(port);
- union tbt_mode_resp_device device_resp = get_dev_tbt_vdo(port);
+ union tbt_mode_resp_cable cable_resp;
+ union tbt_mode_resp_device device_resp;
+
+ if (!IS_ENABLED(CONFIG_USB_PD_ALT_MODE_DFP))
+ return 0;
+
+ cable_resp.raw_value = pd_get_tbt_mode_vdo(port, TCPC_TX_SOP_PRIME);
+ device_resp.raw_value = pd_get_tbt_mode_vdo(port, TCPC_TX_SOP);
/*
* Ref: USB Type-C Cable and Connector Specification
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index 2ab397c0e7..28f7e8b265 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -164,30 +164,6 @@ void reset_pd_cable(int port)
cable[port].last_sop_p_p_msg_id = INVALID_MSG_ID_COUNTER;
}
-union tbt_mode_resp_cable get_cable_tbt_vdo(int port)
-{
- /*
- * Return Discover mode SOP prime response for Thunderbolt-compatible
- * mode SVDO.
- */
- return cable[port].cable_mode_resp;
-}
-
-union tbt_mode_resp_device get_dev_tbt_vdo(int port)
-{
- /*
- * Return Discover mode SOP response for Thunderbolt-compatible
- * mode SVDO.
- */
- return cable[port].dev_mode_resp;
-}
-
-enum tbt_compat_rounded_support get_tbt_rounded_support(int port)
-{
- /* tbt_rounded_support is zero when uninitialized */
- return cable[port].cable_mode_resp.tbt_rounded;
-}
-
bool should_enter_usb4_mode(int port)
{
return IS_ENABLED(CONFIG_USB_PD_USB4) &&
@@ -212,7 +188,33 @@ void disable_enter_usb4_mode(int port)
static struct pd_discovery
discovery[CONFIG_USB_PD_PORT_MAX_COUNT][DISCOVERY_TYPE_COUNT];
-static struct partner_active_modes partner_amodes[CONFIG_USB_PD_PORT_MAX_COUNT];
+static struct partner_active_modes
+ partner_amodes[CONFIG_USB_PD_PORT_MAX_COUNT][AMODE_TYPE_COUNT];
+
+static bool is_modal(int port, int cnt, const uint32_t *payload)
+{
+ return is_vdo_present(cnt, VDO_INDEX_IDH) &&
+ PD_IDH_IS_MODAL(payload[VDO_INDEX_IDH]);
+}
+
+static bool is_tbt_compat_mode(int port, int cnt, const uint32_t *payload)
+{
+ /*
+ * Ref: USB Type-C cable and connector specification
+ * F.2.5 TBT3 Device Discover Mode Responses
+ */
+ return is_vdo_present(cnt, VDO_INDEX_IDH) &&
+ PD_VDO_RESP_MODE_INTEL_TBT(payload[VDO_INDEX_IDH]);
+}
+
+static bool cable_supports_tbt_speed(int port)
+{
+ enum tbt_compat_cable_speed tbt_cable_speed =
+ get_tbt_cable_speed(port);
+
+ return (tbt_cable_speed == TBT_SS_TBT_GEN3 ||
+ tbt_cable_speed == TBT_SS_U32_GEN1_GEN2);
+}
static bool is_tbt_compat_enabled(int port)
{
@@ -374,7 +376,7 @@ struct partner_active_modes *pd_get_partner_active_modes(int port,
enum tcpm_transmit_type type)
{
assert(type < AMODE_TYPE_COUNT);
- return &partner_amodes[port];
+ return &partner_amodes[port][type];
}
/* Note: Enter mode flag is not needed by TCPMv1 */
@@ -382,11 +384,6 @@ void pd_set_dfp_enter_mode_flag(int port, bool set)
{
}
-struct pd_cable *pd_get_cable_attributes(int port)
-{
- return &cable[port];
-}
-
static int process_am_discover_ident_sop(int port, int cnt,
uint32_t head, uint32_t *payload,
enum tcpm_transmit_type *rtype)
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index a4a4c7fa0b..4710ced9fe 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -446,10 +446,6 @@ static struct policy_engine {
/* state specific state machine variable */
enum sub_state sub;
- /* Cable DiscoverIdentity VDOs */
- struct pd_cable cable;
-
- /* TODO(b/150611251): Store full partner DiscoverIdentity response */
/* PD_VDO_INVALID is used when there is an invalid VDO */
int32_t ama_vdo;
int32_t vpd_vdo;
@@ -1573,7 +1569,6 @@ static void pe_src_startup_entry(int port)
pe[port].ama_vdo = PD_VDO_INVALID;
pe[port].vpd_vdo = PD_VDO_INVALID;
pe[port].discover_identity_counter = 0;
- memset(&pe[port].cable, 0, sizeof(struct pd_cable));
/* Reset dr swap attempt counter */
pe[port].dr_swap_attempt_counter = 0;
@@ -2330,7 +2325,6 @@ static void pe_snk_startup_entry(int port)
PE_CLR_FLAG(port, PE_FLAGS_VDM_SETUP_DONE);
pd_dfp_discovery_init(port);
pe[port].discover_identity_counter = 0;
- memset(&pe[port].cable, 0, sizeof(struct pd_cable));
/* Reset dr swap attempt counter */
pe[port].dr_swap_attempt_counter = 0;
@@ -4371,7 +4365,8 @@ static void pe_vdm_identity_request_cbl_run(int port)
* Explicit Contract
*/
if (prl_get_rev(port, TCPC_TX_SOP) != PD_REV20)
- prl_set_rev(port, sop, pe[port].cable.rev);
+ prl_set_rev(port, sop,
+ pd_get_vdo_ver(port, TCPC_TX_SOP_PRIME));
} else if (response_result == PD_DISC_FAIL) {
/*
* PE_INIT_PORT_VDM_IDENTITY_NAKed and PE_SRC_VDM_Identity_NAKed
@@ -5409,11 +5404,6 @@ struct partner_active_modes *pd_get_partner_active_modes(int port,
return &pe[port].partner_amodes[type];
}
-struct pd_cable *pd_get_cable_attributes(int port)
-{
- return &pe[port].cable;
-}
-
void pd_set_dfp_enter_mode_flag(int port, bool set)
{
if (set)
diff --git a/common/usbc/usb_sm.c b/common/usbc/usb_sm.c
index fbc227ded5..99bed2b1bb 100644
--- a/common/usbc/usb_sm.c
+++ b/common/usbc/usb_sm.c
@@ -191,29 +191,3 @@ void run_state(const int port, struct sm_ctx *const ctx)
call_run_functions(port, internal, ctx->current);
internal->running = false;
}
-
-/* TODO (b/148528713): Need to enable Thunderbolt-compatible mode on TCPMv2 */
-union tbt_mode_resp_cable get_cable_tbt_vdo(int port)
-{
- union tbt_mode_resp_cable cable_resp = {
- .raw_value = 0,
- };
-
- return cable_resp;
-}
-
-union tbt_mode_resp_device get_dev_tbt_vdo(int port)
-{
- union tbt_mode_resp_device dev_resp = {
- .raw_value = 0,
- };
-
- return dev_resp;
-}
-
-enum tbt_compat_rounded_support get_tbt_rounded_support(int port)
-{
- enum tbt_compat_rounded_support tbt_round = 0;
-
- return tbt_round;
-}
diff --git a/driver/retimer/bb_retimer.c b/driver/retimer/bb_retimer.c
index ea287a927b..8855f049b1 100644
--- a/driver/retimer/bb_retimer.c
+++ b/driver/retimer/bb_retimer.c
@@ -165,8 +165,9 @@ static void retimer_set_state_dfp(int port, mux_state_t mux_state,
*set_retimer_con |= BB_RETIMER_ACTIVE_PASSIVE;
if (mux_state & USB_PD_MUX_TBT_COMPAT_ENABLED) {
- cable_resp = get_cable_tbt_vdo(port);
- dev_resp = get_dev_tbt_vdo(port);
+ cable_resp.raw_value =
+ pd_get_tbt_mode_vdo(port, TCPC_TX_SOP_PRIME);
+ dev_resp.raw_value = pd_get_tbt_mode_vdo(port, TCPC_TX_SOP);
/*
* Bit 2: RE_TIMER_DRIVER
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 9384a13295..a7720e9264 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1753,6 +1753,21 @@ enum pd_discovery_state pd_get_modes_discovery(int port,
enum tcpm_transmit_type type);
/**
+ * Returns the mode vdo count of the specified SVID and sets
+ * the vdo_out with it's discovered mode VDO.
+ *
+ * @param port USB-C port number
+ * @param type Transmit type (SOP, SOP') for VDM
+ * @param svid SVID to get
+ * @param vdo_out Discover Mode VDO response to set
+ * Note: It must be able to fit wihin PDO_MODES VDOs.
+ * @return Mode VDO cnt of specified SVID if is discovered,
+ * 0 otherwise
+ */
+int pd_get_mode_vdo_for_svid(int port, enum tcpm_transmit_type type,
+ uint16_t svid, uint32_t *vdo_out);
+
+/**
* Get a pointer to mode data for the next SVID with undiscovered modes. This
* data may indicate that discovery failed.
*
@@ -1908,15 +1923,6 @@ struct partner_active_modes *pd_get_partner_active_modes(int port,
enum tcpm_transmit_type type);
/*
- * Return the pointer to PD cable attributes
- * Note: Caller function can mutate the data in this structure.
- *
- * @param port USB-C port number
- * @return pointer to PD cable attributes
- */
-struct pd_cable *pd_get_cable_attributes(int port);
-
-/*
* Returns True if cable supports USB2 connection
*
* @param port USB-C port number
@@ -2042,22 +2048,6 @@ void disable_enter_usb4_mode(int port);
bool should_enter_usb4_mode(int port);
/**
- * Return the response of discover mode SOP prime, with SVID = 0x8087
- *
- * @param port USB-C port number
- * @return cable mode response vdo
- */
-union tbt_mode_resp_cable get_cable_tbt_vdo(int port);
-
-/**
- * Return the response of discover mode SOP, with SVID = 0x8087
- *
- * @param port USB-C port number
- * @return device mode response vdo
- */
-union tbt_mode_resp_device get_dev_tbt_vdo(int port);
-
-/**
* Return Thunderbolt rounded support
* Rounded support indicates if the cable can support rounding the
* frequency depending upon the cable generation.
@@ -2068,6 +2058,16 @@ union tbt_mode_resp_device get_dev_tbt_vdo(int port);
enum tbt_compat_rounded_support get_tbt_rounded_support(int port);
/**
+ * Returns the first discovered Mode VDO for Intel SVID
+ *
+ * @param port USB-C port number
+ * @param type Transmit type (SOP, SOP') for VDM
+ * @return Discover Mode VDO for Intel SVID if the Intel mode VDO is
+ * discovered, 0 otherwise
+ */
+uint32_t pd_get_tbt_mode_vdo(int port, enum tcpm_transmit_type type);
+
+/**
* Sets the Mux state to Thunderbolt-Compatible mode
*
* @param port USB-C port number
@@ -2083,27 +2083,6 @@ void set_tbt_compat_mode_ready(int port);
bool is_tbt_cable_superspeed(int port);
/**
- * Check if product supports any Modal Operation (Alternate Modes)
- *
- * @param port USB-C port number
- * @param cnt number of data objects in payload
- * @param payload payload data
- * @return True if product supports Modal Operation, false otherwise
- */
-bool is_modal(int port, int cnt, const uint32_t *payload);
-
-/**
- * Checks if Device discover mode response contains Thunderbolt alternate mode
- *
- * @param port USB-C port number
- * @param cnt number of data objects in payload
- * @param payload payload data
- * @return True if Thunderbolt Alternate mode response is received,
- * false otherwise
- */
-bool is_tbt_compat_mode(int port, int cnt, const uint32_t *payload);
-
-/**
* Returns Thunderbolt-compatible cable speed according to the port if,
* port supports lesser speed than the cable
*
@@ -2112,15 +2091,6 @@ bool is_tbt_compat_mode(int port, int cnt, const uint32_t *payload);
*/
enum tbt_compat_cable_speed get_tbt_cable_speed(int port);
-/*
- * Checks if the cable supports Thunderbolt speed.
- *
- * @param port USB-C port number
- * @return True if the Thunderbolt cable speed is TBT_SS_TBT_GEN3 or
- * TBT_SS_U32_GEN1_GEN2, false otherwise
- */
-bool cable_supports_tbt_speed(int port);
-
/**
* Fills the TBT3 objects in the payload and returns the number
* of objects it has filled.