From 7eee98e1757cab7b024b62ab4fd1797ec60edbb5 Mon Sep 17 00:00:00 2001 From: Bhaumik Bhatt Date: Thu, 26 Mar 2020 18:19:36 -0700 Subject: [PATCH 1/4] mhi: cntrl: qcom: expand debug modes for new device bringup When bringing up a new device attach to the host driver, MHI controller can have more than one debug mode to allow for configurable versions and make it easier to choose firmware images and allow/disallow forced suspend/resume done to choose new PHY settings. Change-Id: Id2ecd98cfbaba40aca96bd167c34bfa5fd03818e Signed-off-by: Bhaumik Bhatt --- drivers/bus/mhi/controllers/mhi_qcom.c | 21 +++++++++++++++++---- drivers/bus/mhi/controllers/mhi_qcom.h | 9 +++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/bus/mhi/controllers/mhi_qcom.c b/drivers/bus/mhi/controllers/mhi_qcom.c index 7479dcef64de..cd252739c3a2 100644 --- a/drivers/bus/mhi/controllers/mhi_qcom.c +++ b/drivers/bus/mhi/controllers/mhi_qcom.c @@ -403,6 +403,11 @@ static int mhi_force_suspend(struct mhi_controller *mhi_cntrl) MHI_CNTRL_LOG("Entered\n"); + if (debug_mode == MHI_DEBUG_NO_D3 || debug_mode == MHI_FWIMAGE_NO_D3) { + MHI_CNTRL_LOG("Exited due to debug mode:%d\n", debug_mode); + return ret; + } + mutex_lock(&mhi_cntrl->pm_mutex); for (; itr; itr--) { @@ -676,7 +681,7 @@ static struct mhi_controller *mhi_register_controller(struct pci_dev *pci_dev) bool use_s1; u32 addr_win[2]; const char *iommu_dma_type; - int ret, i; + int ret, i, len; if (!of_node) return ERR_PTR(-ENODEV); @@ -752,14 +757,22 @@ static struct mhi_controller *mhi_register_controller(struct pci_dev *pci_dev) if (ret) goto error_register; - for (i = 0; i < ARRAY_SIZE(firmware_table); i++) { + len = ARRAY_SIZE(firmware_table); + for (i = 0; i < len; i++) { firmware_info = firmware_table + i; - /* debug mode always use default */ - if (!debug_mode && mhi_cntrl->dev_id == firmware_info->dev_id) + if (mhi_cntrl->dev_id == firmware_info->dev_id) break; } + if (debug_mode) { + if (debug_mode <= MHI_DEBUG_D3) + firmware_info = firmware_table + (len - 1); + MHI_CNTRL_LOG("fw info: debug_mode:%d dev_id:%d image:%s\n", + debug_mode, firmware_info->dev_id, + firmware_info->fw_image); + } + mhi_cntrl->fw_image = firmware_info->fw_image; mhi_cntrl->edl_image = firmware_info->edl_image; diff --git a/drivers/bus/mhi/controllers/mhi_qcom.h b/drivers/bus/mhi/controllers/mhi_qcom.h index 325be120486c..3b5e74b912c4 100644 --- a/drivers/bus/mhi/controllers/mhi_qcom.h +++ b/drivers/bus/mhi/controllers/mhi_qcom.h @@ -33,6 +33,15 @@ extern const char * const mhi_ee_str[MHI_EE_MAX]; #define TO_MHI_EXEC_STR(ee) (ee >= MHI_EE_MAX ? "INVALID_EE" : mhi_ee_str[ee]) +enum mhi_debug_mode { + MHI_DEBUG_MODE_OFF, + MHI_DEBUG_NO_D3, /* use debug.mbn as fw image and skip first M3/D3 */ + MHI_DEBUG_D3, /* use debug.mbn as fw image and allow first M3/D3 */ + MHI_FWIMAGE_NO_D3, /* use fw image if found and skip first M3/D3 */ + MHI_FWIMAGE_D3, /* use fw image if found and allow first M3/D3 */ + MHI_DEBUG_MODE_MAX = MHI_FWIMAGE_D3, +}; + enum mhi_suspend_mode { MHI_ACTIVE_STATE, MHI_DEFAULT_SUSPEND, From 20aba7d1d791192975cdccf69a2464c262f838f2 Mon Sep 17 00:00:00 2001 From: Bhaumik Bhatt Date: Tue, 26 May 2020 19:00:43 -0700 Subject: [PATCH 2/4] mhi: core: Separate rddm support and dump collection As of now, there is no way for MHI to know if device supports RDDM and host controller wishes to skip ramdump collection. Allow for that by letting the controller set the rddm support boolean which indicates device side support. If rddm_size is set to zero while the support for RDDM is present, that indicates disinterest in ramdump collection if RDDM execution environment is entered. Change-Id: I0a36219fc7782951aa1b81b9ec0d182ecfb3a916 Signed-off-by: Bhaumik Bhatt --- drivers/bus/mhi/core/mhi_boot.c | 4 ++++ drivers/bus/mhi/core/mhi_init.c | 2 +- drivers/bus/mhi/core/mhi_main.c | 2 +- drivers/bus/mhi/core/mhi_pm.c | 6 +++++- include/linux/mhi.h | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/bus/mhi/core/mhi_boot.c b/drivers/bus/mhi/core/mhi_boot.c index d5864a28548c..cfc37c975b26 100644 --- a/drivers/bus/mhi/core/mhi_boot.c +++ b/drivers/bus/mhi/core/mhi_boot.c @@ -278,6 +278,10 @@ int mhi_download_rddm_img(struct mhi_controller *mhi_cntrl, bool in_panic) void __iomem *base = mhi_cntrl->bhie; u32 rx_status; + /* device supports RDDM but controller wants to skip ramdumps */ + if (!mhi_cntrl->rddm_supported || !mhi_cntrl->rddm_image) + return -EINVAL; + if (in_panic) return __mhi_download_rddm_in_panic(mhi_cntrl); diff --git a/drivers/bus/mhi/core/mhi_init.c b/drivers/bus/mhi/core/mhi_init.c index 0dd29368d2f6..6f07329d19a5 100644 --- a/drivers/bus/mhi/core/mhi_init.c +++ b/drivers/bus/mhi/core/mhi_init.c @@ -1780,7 +1780,7 @@ int mhi_prepare_for_power_up(struct mhi_controller *mhi_cntrl) * allocate rddm table if specified, this table is for debug purpose * so we'll ignore erros */ - if (mhi_cntrl->rddm_size) { + if (mhi_cntrl->rddm_supported && mhi_cntrl->rddm_size) { mhi_alloc_bhie_table(mhi_cntrl, &mhi_cntrl->rddm_image, mhi_cntrl->rddm_size); diff --git a/drivers/bus/mhi/core/mhi_main.c b/drivers/bus/mhi/core/mhi_main.c index 510867b8857a..191b5f707ec1 100644 --- a/drivers/bus/mhi/core/mhi_main.c +++ b/drivers/bus/mhi/core/mhi_main.c @@ -1212,7 +1212,7 @@ int mhi_process_ctrl_ev_ring(struct mhi_controller *mhi_cntrl, * event instead of sys error state change event */ if (mhi_cntrl->ee == MHI_EE_RDDM || - mhi_cntrl->rddm_image) + mhi_cntrl->rddm_supported) break; MHI_ERR("MHI system error detected\n"); diff --git a/drivers/bus/mhi/core/mhi_pm.c b/drivers/bus/mhi/core/mhi_pm.c index 819ea9442f21..d8e3c2154d86 100644 --- a/drivers/bus/mhi/core/mhi_pm.c +++ b/drivers/bus/mhi/core/mhi_pm.c @@ -859,7 +859,7 @@ void mhi_process_sys_err(struct mhi_controller *mhi_cntrl) * if controller supports rddm, we do not process sys error state, * instead we will jump directly to rddm state */ - if (mhi_cntrl->rddm_image) { + if (mhi_cntrl->rddm_supported) { MHI_CNTRL_LOG( "Controller supports RDDM, skipping SYS_ERR_PROCESS\n"); return; @@ -1714,6 +1714,10 @@ int mhi_force_rddm_mode(struct mhi_controller *mhi_cntrl) to_mhi_pm_state_str(mhi_cntrl->pm_state), TO_MHI_EXEC_STR(mhi_cntrl->ee)); + /* device does not support RDDM */ + if (!mhi_cntrl->rddm_supported) + return -EINVAL; + /* device already in rddm */ if (mhi_cntrl->ee == MHI_EE_RDDM) return 0; diff --git a/include/linux/mhi.h b/include/linux/mhi.h index f6b8ffe30fc0..2f1d02f75d77 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -295,6 +295,7 @@ struct mhi_controller { /* mhi host manages downloading entire fbc images */ bool fbc_download; + bool rddm_supported; size_t rddm_size; size_t sbl_size; size_t seg_len; From e2bb50da93408e03716a572f69d8c4035a85b03e Mon Sep 17 00:00:00 2001 From: Bhaumik Bhatt Date: Thu, 21 May 2020 15:13:03 -0700 Subject: [PATCH 3/4] mhi: core: Move power down check within the RDDM image support If a controller supports RDDM, there is no need to process a SYS_ERROR. Hence, we can safely move the power down state check to reside within an RDDM supported controller as it allows for other controllers to handle scenarios such as receiving an early SYS_ERROR when in the PBL execution environment. Change-Id: I5c63a861b9dd178f5c967bdf252da9c47d3a2b56 Signed-off-by: Bhaumik Bhatt --- drivers/bus/mhi/core/mhi_main.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/bus/mhi/core/mhi_main.c b/drivers/bus/mhi/core/mhi_main.c index 191b5f707ec1..b577f9477edf 100644 --- a/drivers/bus/mhi/core/mhi_main.c +++ b/drivers/bus/mhi/core/mhi_main.c @@ -1638,20 +1638,20 @@ irqreturn_t mhi_intvec_threaded_handlr(int irq_number, void *dev) TO_MHI_EXEC_STR(ee), TO_MHI_STATE_STR(state)); - if (mhi_cntrl->power_down) { - write_unlock_irq(&mhi_cntrl->pm_lock); - goto exit_intvec; - } - if (state == MHI_STATE_SYS_ERR) { MHI_ERR("MHI system error detected\n"); pm_state = mhi_tryset_pm_state(mhi_cntrl, MHI_PM_SYS_ERR_DETECT); } - write_unlock_irq(&mhi_cntrl->pm_lock); - if (ee == MHI_EE_RDDM) { - write_lock_irq(&mhi_cntrl->pm_lock); + if (mhi_cntrl->rddm_supported) { + /* exit as power down is already initiated */ + if (mhi_cntrl->power_down || ee != MHI_EE_RDDM) { + write_unlock_irq(&mhi_cntrl->pm_lock); + goto exit_intvec; + } + + /* prevent multiple entries for RDDM execution environment */ if (mhi_cntrl->ee == MHI_EE_RDDM) { write_unlock_irq(&mhi_cntrl->pm_lock); goto exit_intvec; @@ -1670,6 +1670,8 @@ irqreturn_t mhi_intvec_threaded_handlr(int irq_number, void *dev) goto exit_intvec; } + write_unlock_irq(&mhi_cntrl->pm_lock); + /* if device is in RDDM, don't bother processing SYS_ERR */ if (ee != MHI_EE_RDDM && pm_state == MHI_PM_SYS_ERR_DETECT) { wake_up_all(&mhi_cntrl->state_event); From cc96a97351af4ed40edc7b92dfb6bf9d1bf4098c Mon Sep 17 00:00:00 2001 From: Bhaumik Bhatt Date: Tue, 26 May 2020 19:04:39 -0700 Subject: [PATCH 4/4] cnss2: set rddm support boolean for MHI Set the RDDM support boolean at power up for MHI to know that the device can enter RDDM execution environment. It can decide to skip SYS_ERROR handling based on the boolean whereas allow other aspects such as collection ramdumps if sufficient support is present. Change-Id: Iee74b6ae61166ea48617e1b75f05841079e1b83b Signed-off-by: Bhaumik Bhatt --- drivers/net/wireless/cnss2/pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/cnss2/pci.c b/drivers/net/wireless/cnss2/pci.c index e1c4cbd5846b..d3ab6dcf9def 100644 --- a/drivers/net/wireless/cnss2/pci.c +++ b/drivers/net/wireless/cnss2/pci.c @@ -4396,6 +4396,7 @@ static int cnss_pci_register_mhi(struct cnss_pci_data *pci_priv) mhi_ctrl->sbl_size = SZ_512K; mhi_ctrl->seg_len = SZ_512K; mhi_ctrl->fbc_download = true; + mhi_ctrl->rddm_supported = true; mhi_ctrl->log_buf = ipc_log_context_create(CNSS_IPC_LOG_PAGES, "cnss-mhi", 0);