From b0a3a4fc5df23043823a82b727c7cd4dd14b35d7 Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Wed, 12 Aug 2020 14:35:40 -0600 Subject: usbc: add GEN_NOT_SUPPORTED macro for unsupported states To enabled use of the IS_ENABLE macro we need to define some of the usb state machine states as extern variables that will never be linked. This allows the compiler to know about a state but will still fail the linking phase if the config option is not defined properly. This is just adding a convenience macro for this paradigm, not creating the paradigm itself. BRANCH=none BUG=none TEST=builds Signed-off-by: Jett Rink Change-Id: Ia19b5babd43d536f043745314481475cf25f6e01 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2353369 Reviewed-by: Edward Hill --- common/usbc/usb_pe_drp_sm.c | 51 ++++++++++------------------------ common/usbc/usb_prl_sm.c | 33 +++++++++++----------- common/usbc/usb_tc_drp_acc_trysrc_sm.c | 12 +++----- include/usb_sm.h | 3 ++ test/usb_pe.h | 8 ++---- 5 files changed, 41 insertions(+), 66 deletions(-) diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index 5f1db976d5..5b3e950f45 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -268,21 +268,16 @@ enum usb_pe_state { /* AMS Start parent - runs SenderResponseTimer */ PE_SENDER_RESPONSE, -#ifdef CONFIG_USB_PD_REV30 /* PD3.0 only states below here*/ PE_FRS_SNK_SRC_START_AMS, -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES PE_GIVE_BATTERY_CAP, PE_GIVE_BATTERY_STATUS, PE_SEND_ALERT, -#else PE_SRC_CHUNK_RECEIVED, PE_SNK_CHUNK_RECEIVED, -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ /* Super States */ PE_PRS_FRS_SHARED, -#endif /* CONFIG_USB_PD_REV30 */ }; /* @@ -409,66 +404,50 @@ static const char * const pe_state_names[] = { /* * Here and below, ensure that invalid states don't link properly. This lets us * use guard code with IS_ENABLED instead of ifdefs and still save flash space. - * Use STATIC_IF instead of bare extern to avoid a checkpatch.pl error. */ STATIC_IF(USB_PD_DEBUG_LABELS) const char **pe_state_names; #endif #ifndef CONFIG_USBC_VCONN -STATIC_IF(CONFIG_USBC_VCONN) - enum usb_pe_state PE_VCS_EVALUATE_SWAP_NOT_SUPPORTED; -STATIC_IF(CONFIG_USBC_VCONN) - enum usb_pe_state PE_VCS_SEND_SWAP_NOT_SUPPORTED; -STATIC_IF(CONFIG_USBC_VCONN) - enum usb_pe_state PE_VCS_WAIT_FOR_VCONN_SWAP_NOT_SUPPORTED; -STATIC_IF(CONFIG_USBC_VCONN) - enum usb_pe_state PE_VCS_TURN_ON_VCONN_SWAP_NOT_SUPPORTED; -STATIC_IF(CONFIG_USBC_VCONN) - enum usb_pe_state PE_VCS_TURN_OFF_VCONN_SWAP_NOT_SUPPORTED; -STATIC_IF(CONFIG_USBC_VCONN) - enum usb_pe_state PE_VCS_SEND_PS_RDY_SWAP_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(PE_VCS_EVALUATE_SWAP); #define PE_VCS_EVALUATE_SWAP PE_VCS_EVALUATE_SWAP_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_VCS_SEND_SWAP); #define PE_VCS_SEND_SWAP PE_VCS_SEND_SWAP_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_VCS_WAIT_FOR_VCONN_SWAP); #define PE_VCS_WAIT_FOR_VCONN_SWAP PE_VCS_WAIT_FOR_VCONN_SWAP_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_VCS_TURN_ON_VCONN_SWAP); #define PE_VCS_TURN_ON_VCONN_SWAP PE_VCS_TURN_ON_VCONN_SWAP_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_VCS_TURN_OFF_VCONN_SWAP); #define PE_VCS_TURN_OFF_VCONN_SWAP PE_VCS_TURN_OFF_VCONN_SWAP_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_VCS_SEND_PS_RDY_SWAP); #define PE_VCS_SEND_PS_RDY_SWAP PE_VCS_SEND_PS_RDY_SWAP_NOT_SUPPORTED #endif /* CONFIG_USBC_VCONN */ #ifndef CONFIG_USB_PD_REV30 -STATIC_IF(CONFIG_USB_PD_REV30) - enum usb_pe_state PE_FRS_SNK_SRC_START_AMS_NOT_SUPPORTED; -STATIC_IF(CONFIG_USB_PD_REV30) - enum usb_pe_state PE_PRS_FRS_SHARE_NOT_SUPPORTED; -STATIC_IF(CONFIG_USB_PD_REV30) - enum usb_pe_state PE_SRC_CHUNK_RECEIVED_NOT_SUPPORTED; -STATIC_IF(CONFIG_USB_PD_REV30) - enum usb_pe_state PE_SNK_CHUNK_RECEIVED_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(PE_FRS_SNK_SRC_START_AMS); #define PE_FRS_SNK_SRC_START_AMS PE_FRS_SNK_SRC_START_AMS_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_PRS_FRS_SHARED); #define PE_PRS_FRS_SHARED PE_PRS_FRS_SHARED_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_SRC_CHUNK_RECEIVED); #define PE_SRC_CHUNK_RECEIVED PE_SRC_CHUNK_RECEIVED_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_SNK_CHUNK_RECEIVED); #define PE_SNK_CHUNK_RECEIVED PE_SNK_CHUNK_RECEIVED_NOT_SUPPORTED void pe_set_frs_enable(int port, int enable); #endif /* CONFIG_USB_PD_REV30 */ #ifndef CONFIG_USB_PD_EXTENDED_MESSAGES -STATIC_IF(CONFIG_USB_PD_EXTENDED_MESSAGES) - enum usb_pe_state PE_GIVE_BATTERY_CAP_NOT_SUPPORTED; -STATIC_IF(CONFIG_USB_PD_EXTENDED_MESSAGES) - enum usb_pe_state PE_GIVE_BATTERY_STATUS_NOT_SUPPORTED; -STATIC_IF(CONFIG_USB_PD_EXTENDED_MESSAGES) - enum usb_pe_state PE_SEND_ALERT_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(PE_GIVE_BATTERY_CAP); #define PE_GIVE_BATTERY_CAP PE_GIVE_BATTERY_CAP_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_GIVE_BATTERY_STATUS); #define PE_GIVE_BATTERY_STATUS PE_GIVE_BATTERY_STATUS_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_SEND_ALERT); #define PE_SEND_ALERT PE_SEND_ALERT_NOT_SUPPORTED #endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ #ifdef CONFIG_USB_PD_EXTENDED_MESSAGES -STATIC_IF_NOT(CONFIG_USB_PD_EXTENDED_MESSAGES) - enum usb_pe_state PE_SRC_CHUNK_RECEIVED_NOT_SUPPORTED; -STATIC_IF_NOT(CONFIG_USB_PD_EXTENDED_MESSAGES) - enum usb_pe_state PE_SNK_CHUNK_RECEIVED_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(PE_SRC_CHUNK_RECEIVED); #define PE_SRC_CHUNK_RECEIVED PE_SRC_CHUNK_RECEIVED_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PE_SNK_CHUNK_RECEIVED); #define PE_SNK_CHUNK_RECEIVED PE_SNK_CHUNK_RECEIVED_NOT_SUPPORTED #endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c index ec22502523..6a065d0d31 100644 --- a/common/usbc/usb_prl_sm.c +++ b/common/usbc/usb_prl_sm.c @@ -307,45 +307,44 @@ static void prl_rx_wait_for_phy_message(const int port, int evt); static void prl_copy_msg_to_buffer(int port); #ifndef CONFIG_USB_PD_REV30 -extern enum usb_prl_tx_state PRL_TX_SRC_SOURCE_TX_NOT_SUPPORTED; -extern enum usb_prl_tx_state PRL_TX_SNK_START_AMS_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(PRL_TX_SRC_SOURCE_TX); #define PRL_TX_SRC_SOURCE_TX PRL_TX_SRC_SOURCE_TX_NOT_SUPPORTED +GEN_NOT_SUPPORTED(PRL_TX_SNK_START_AMS); #define PRL_TX_SNK_START_AMS PRL_TX_SNK_START_AMS_NOT_SUPPORTED -extern enum usb_rch_state - RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER_NOT_SUPPORTED; -extern enum usb_rch_state RCH_PASS_UP_MESSAGE_NOT_SUPPORTED; -extern enum usb_rch_state RCH_PROCESSING_EXTENDED_MESSAGE_NOT_SUPPORTED; -extern enum usb_rch_state RCH_REQUESTING_CHUNK_NOT_SUPPORTED; -extern enum usb_rch_state RCH_WAITING_CHUNK_NOT_SUPPORTED; -extern enum usb_rch_state RCH_REPORT_ERROR_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER); #define RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER \ RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER_NOT_SUPPORTED +GEN_NOT_SUPPORTED(RCH_PASS_UP_MESSAGE); #define RCH_PASS_UP_MESSAGE RCH_PASS_UP_MESSAGE_NOT_SUPPORTED +GEN_NOT_SUPPORTED(RCH_PROCESSING_EXTENDED_MESSAGE); #define RCH_PROCESSING_EXTENDED_MESSAGE \ RCH_PROCESSING_EXTENDED_MESSAGE_NOT_SUPPORTED +GEN_NOT_SUPPORTED(RCH_REQUESTING_CHUNK); #define RCH_REQUESTING_CHUNK RCH_REQUESTING_CHUNK_NOT_SUPPORTED +GEN_NOT_SUPPORTED(RCH_WAITING_CHUNK); #define RCH_WAITING_CHUNK RCH_WAITING_CHUNK_NOT_SUPPORTED +GEN_NOT_SUPPORTED(RCH_REPORT_ERROR); #define RCH_REPORT_ERROR RCH_REPORT_ERROR_NOT_SUPPORTED -extern enum usb_tch_state TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE_NOT_SUPPORTED; -extern enum usb_tch_state TCH_WAIT_FOR_TRANSMISSION_COMPLETE_NOT_SUPPORTED; -extern enum usb_tch_state TCH_CONSTRUCT_CHUNKED_MESSAGE_NOT_SUPPORTED; -extern enum usb_tch_state TCH_SENDING_CHUNKED_MESSAGE_NOT_SUPPORTED; -extern enum usb_tch_state TCH_WAIT_CHUNK_REQUEST_NOT_SUPPORTED; -extern enum usb_tch_state TCH_MESSAGE_RECEIVED_NOT_SUPPORTED; -extern enum usb_tch_state TCH_MESSAGE_SENT_NOT_SUPPORTED; -extern enum usb_tch_state TCH_REPORT_ERROR_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE); #define TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE \ TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TCH_WAIT_FOR_TRANSMISSION_COMPLETE); #define TCH_WAIT_FOR_TRANSMISSION_COMPLETE \ TCH_WAIT_FOR_TRANSMISSION_COMPLETE_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TCH_CONSTRUCT_CHUNKED_MESSAGE); #define TCH_CONSTRUCT_CHUNKED_MESSAGE \ TCH_CONSTRUCT_CHUNKED_MESSAGE_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TCH_SENDING_CHUNKED_MESSAGE); #define TCH_SENDING_CHUNKED_MESSAGE TCH_SENDING_CHUNKED_MESSAGE_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TCH_WAIT_CHUNK_REQUEST); #define TCH_WAIT_CHUNK_REQUEST TCH_WAIT_CHUNK_REQUEST_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TCH_MESSAGE_RECEIVED); #define TCH_MESSAGE_RECEIVED TCH_MESSAGE_RECEIVED_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TCH_MESSAGE_SENT); #define TCH_MESSAGE_SENT TCH_MESSAGE_SENT_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TCH_REPORT_ERROR); #define TCH_REPORT_ERROR TCH_REPORT_ERROR_NOT_SUPPORTED #endif /* !CONFIG_USB_PD_REV30 */ diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 864976da4c..32dff84fa1 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -191,23 +191,19 @@ static const struct usb_state tc_states[]; * IS_ENABLED to work. */ #ifndef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -STATIC_IF(CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE) - enum usb_tc_state TC_DRP_AUTO_TOGGLE_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(TC_DRP_AUTO_TOGGLE); #define TC_DRP_AUTO_TOGGLE TC_DRP_AUTO_TOGGLE_NOT_SUPPORTED #endif /* CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE */ #ifndef CONFIG_USB_PD_TCPC_LOW_POWER -STATIC_IF(CONFIG_USB_PD_TCPC_LOW_POWER) - enum usb_tc_state TC_LOW_POWER_MODE_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(TC_LOW_POWER_MODE); #define TC_LOW_POWER_MODE TC_LOW_POWER_MODE_NOT_SUPPORTED #endif /* CONFIG_USB_PD_TCPC_LOW_POWER */ #ifndef CONFIG_USB_PE_SM -STATIC_IF(CONFIG_USB_PE_SM) - enum usb_tc_state TC_CT_UNATTACHED_SNK_NOT_SUPPORTED; -STATIC_IF(CONFIG_USB_PE_SM) - enum usb_tc_state TC_CT_ATTACHED_SNK_NOT_SUPPORTED; +GEN_NOT_SUPPORTED(TC_CT_UNATTACHED_SNK); #define TC_CT_UNATTACHED_SNK TC_CT_UNATTACHED_SNK_NOT_SUPPORTED +GEN_NOT_SUPPORTED(TC_CT_ATTACHED_SNK); #define TC_CT_ATTACHED_SNK TC_CT_ATTACHED_SNK_NOT_SUPPORTED #endif /* CONFIG_USB_PE_SM */ diff --git a/include/usb_sm.h b/include/usb_sm.h index 5d89b4e890..d8eff5190a 100644 --- a/include/usb_sm.h +++ b/include/usb_sm.h @@ -105,4 +105,7 @@ struct test_sm_data { }; #endif +/* Creates a state machine state that will never link. Useful with IS_ENABLED */ +#define GEN_NOT_SUPPORTED(state) extern typeof(state) state ## _NOT_SUPPORTED + #endif /* __CROS_EC_USB_SM_H */ diff --git a/test/usb_pe.h b/test/usb_pe.h index 3ba11ce040..bb9cd3f508 100644 --- a/test/usb_pe.h +++ b/test/usb_pe.h @@ -131,21 +131,19 @@ enum usb_pe_state { PE_DR_SNK_GET_SINK_CAP, PE_DR_SNK_GIVE_SOURCE_CAP, -#ifdef CONFIG_USB_PD_REV30 + /* AMS Start parent - runs SenderResponseTimer */ + PE_SENDER_RESPONSE, + /* PD3.0 only states below here*/ PE_FRS_SNK_SRC_START_AMS, -#ifdef CONFIG_USB_PD_EXTENDED_MESSAGES PE_GIVE_BATTERY_CAP, PE_GIVE_BATTERY_STATUS, PE_SEND_ALERT, -#else PE_SRC_CHUNK_RECEIVED, PE_SNK_CHUNK_RECEIVED, -#endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ /* Super States */ PE_PRS_FRS_SHARED, -#endif /* CONFIG_USB_PD_REV30 */ }; void set_state_pe(const int port, const enum usb_pe_state new_state); -- cgit v1.2.1