From fc63288a51cdf39b1bf147bdf26f5311518a77d2 Mon Sep 17 00:00:00 2001 From: Sujeev Dias Date: Mon, 16 May 2016 16:05:52 -0700 Subject: [PATCH] mhi: core: change logs to print MHI_STATEs in text Instead of printing enum index convert MHI_STATE enum to text representation for easier interpretation of debug logs. CRs-Fixed: 1012249 Change-Id: I97a9a7ff293c739531d8197334a0f0a35bf20419 Signed-off-by: Sujeev Dias --- drivers/platform/msm/mhi/mhi_main.c | 13 ++-- drivers/platform/msm/mhi/mhi_pm.c | 11 +-- drivers/platform/msm/mhi/mhi_states.c | 98 +++++++++++++++++---------- drivers/platform/msm/mhi/mhi_sys.c | 15 +++- drivers/platform/msm/mhi/mhi_sys.h | 4 ++ 5 files changed, 92 insertions(+), 49 deletions(-) diff --git a/drivers/platform/msm/mhi/mhi_main.c b/drivers/platform/msm/mhi/mhi_main.c index a061d4ab50cb..a8da2f9ef9fb 100644 --- a/drivers/platform/msm/mhi/mhi_main.c +++ b/drivers/platform/msm/mhi/mhi_main.c @@ -520,9 +520,9 @@ static inline int mhi_queue_tre(struct mhi_device_ctxt } } else { mhi_log(MHI_MSG_VERBOSE, - "Wakeup, pending data state %d chan state %d\n", - mhi_dev_ctxt->mhi_state, - chan_ctxt->mhi_chan_state); + "Wakeup, pending data state %s chan state %d\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + chan_ctxt->mhi_chan_state); ret_val = 0; } return ret_val; @@ -766,10 +766,9 @@ int mhi_send_cmd(struct mhi_device_ctxt *mhi_dev_ctxt, } mhi_log(MHI_MSG_INFO, - "Entered, MHI state %d dev_exec_env %d chan %d cmd %d\n", - mhi_dev_ctxt->mhi_state, - mhi_dev_ctxt->dev_exec_env, - chan, cmd); + "Entered, MHI state %s dev_exec_env %d chan %d cmd %d\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + mhi_dev_ctxt->dev_exec_env, chan, cmd); mhi_log(MHI_MSG_INFO, "Getting Reference %d", chan); pm_runtime_get(&mhi_dev_ctxt->dev_info->pcie_device->dev); /* diff --git a/drivers/platform/msm/mhi/mhi_pm.c b/drivers/platform/msm/mhi/mhi_pm.c index a928c05b805a..d62d4189d3f3 100644 --- a/drivers/platform/msm/mhi/mhi_pm.c +++ b/drivers/platform/msm/mhi/mhi_pm.c @@ -46,8 +46,8 @@ int mhi_pci_suspend(struct device *dev) if (NULL == mhi_dev_ctxt) return -EINVAL; - mhi_log(MHI_MSG_INFO, "Entered, MHI state %d\n", - mhi_dev_ctxt->mhi_state); + mhi_log(MHI_MSG_INFO, "Entered, MHI state %s\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state)); atomic_set(&mhi_dev_ctxt->flags.pending_resume, 1); r = mhi_initiate_m3(mhi_dev_ctxt); @@ -115,7 +115,8 @@ int mhi_pci_resume(struct device *dev) break; default: mhi_log(MHI_MSG_INFO, - "Wait complete state: %d\n", mhi_dev_ctxt->mhi_state); + "Wait complete state: %s\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state)); r = 0; } exit: @@ -181,8 +182,8 @@ ssize_t sysfs_init_m0(struct device *dev, struct device_attribute *attr, } mhi_initiate_m0(mhi_dev_ctxt); mhi_log(MHI_MSG_CRITICAL, - "Current mhi_state = 0x%x\n", - mhi_dev_ctxt->mhi_state); + "Current mhi_state = %s\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state)); return count; } diff --git a/drivers/platform/msm/mhi/mhi_states.c b/drivers/platform/msm/mhi/mhi_states.c index ca4520a3c57d..63007a991d4c 100644 --- a/drivers/platform/msm/mhi/mhi_states.c +++ b/drivers/platform/msm/mhi/mhi_states.c @@ -17,6 +17,29 @@ #include #include +static const char *state_transition_str(enum STATE_TRANSITION state) +{ + static const char * const mhi_states_transition_str[] = { + "RESET", + "READY", + "M0", + "M1", + "M2", + "M3", + "BHI", + "SBL", + "AMSS", + "LINK_DOWN", + "WAKE" + }; + + if (state == STATE_TRANSITION_SYS_ERR) + return "SYS_ERR"; + + return (state <= STATE_TRANSITION_WAKE) ? + mhi_states_transition_str[state] : "Invalid"; +} + static inline void mhi_set_m_state(struct mhi_device_ctxt *mhi_dev_ctxt, enum MHI_STATE new_state) { @@ -150,8 +173,9 @@ static int process_m0_transition( "Transitioning from M1.\n"); } else { mhi_log(MHI_MSG_INFO, - "MHI State %d link state %d. Quitting\n", - mhi_dev_ctxt->mhi_state, mhi_dev_ctxt->flags.link_up); + "MHI State %s link state %d. Quitting\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + mhi_dev_ctxt->flags.link_up); } read_lock_irqsave(&mhi_dev_ctxt->xfer_lock, flags); @@ -196,8 +220,8 @@ static int process_m1_transition( int r = 0; mhi_log(MHI_MSG_INFO, - "Processing M1 state transition from state %d\n", - mhi_dev_ctxt->mhi_state); + "Processing M1 state transition from state %s\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state)); write_lock_irqsave(&mhi_dev_ctxt->xfer_lock, flags); if (!mhi_dev_ctxt->flags.pending_M3) { @@ -444,8 +468,8 @@ static int process_reset_transition( STATE_TRANSITION_RESET); if (0 != r) mhi_log(MHI_MSG_CRITICAL, - "Failed to initiate 0x%x state trans\n", - STATE_TRANSITION_RESET); + "Failed to initiate %s state trans\n", + state_transition_str(STATE_TRANSITION_RESET)); break; default: mhi_log(MHI_MSG_CRITICAL, @@ -475,8 +499,8 @@ static int process_reset_transition( STATE_TRANSITION_READY); if (0 != r) mhi_log(MHI_MSG_CRITICAL, - "Failed to initiate 0x%x state trans\n", - STATE_TRANSITION_READY); + "Failed to initiate %s state trans\n", + state_transition_str(STATE_TRANSITION_READY)); return r; } @@ -636,8 +660,8 @@ int mhi_trigger_reset(struct mhi_device_ctxt *mhi_dev_ctxt) STATE_TRANSITION_RESET); if (0 != r) mhi_log(MHI_MSG_CRITICAL, - "Failed to initiate 0x%x state trans ret %d\n", - STATE_TRANSITION_RESET, r); + "Failed to initiate %s state trans ret %d\n", + state_transition_str(STATE_TRANSITION_RESET), r); mhi_log(MHI_MSG_INFO, "Exiting\n"); return r; } @@ -648,8 +672,8 @@ static int process_stt_work_item( { int r = 0; - mhi_log(MHI_MSG_INFO, "Transitioning to %d\n", - (int)cur_work_item); + mhi_log(MHI_MSG_INFO, "Transitioning to %s\n", + state_transition_str(cur_work_item)); trace_mhi_state(cur_work_item); switch (cur_work_item) { case STATE_TRANSITION_BHI: @@ -689,7 +713,8 @@ static int process_stt_work_item( break; default: mhi_log(MHI_MSG_ERROR, - "Unrecongized state: %d\n", cur_work_item); + "Unrecongized state: %s\n", + state_transition_str(cur_work_item)); break; } return r; @@ -762,8 +787,8 @@ int mhi_init_state_transition(struct mhi_device_ctxt *mhi_dev_ctxt, BUG_ON(nr_avail_work_items <= 0); mhi_log(MHI_MSG_VERBOSE, - "Processing state transition %x\n", - new_state); + "Processing state transition %s\n", + state_transition_str(new_state)); *(enum STATE_TRANSITION *)stt_ring->wp = new_state; r = ctxt_add_element(stt_ring, (void **)&cur_work_item); BUG_ON(r); @@ -778,13 +803,14 @@ int mhi_initiate_m0(struct mhi_device_ctxt *mhi_dev_ctxt) unsigned long flags; mhi_log(MHI_MSG_INFO, - "Entered MHI state %d, Pending M0 %d Pending M3 %d\n", - mhi_dev_ctxt->mhi_state, mhi_dev_ctxt->flags.pending_M0, - mhi_dev_ctxt->flags.pending_M3); + "Entered MHI state %s, Pending M0 %d Pending M3 %d\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + mhi_dev_ctxt->flags.pending_M0, + mhi_dev_ctxt->flags.pending_M3); mutex_lock(&mhi_dev_ctxt->pm_lock); mhi_log(MHI_MSG_INFO, - "Waiting for M0 M1 or M3. Currently %d...\n", - mhi_dev_ctxt->mhi_state); + "Waiting for M0 M1 or M3. Currently %s...\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state)); r = wait_event_interruptible_timeout(*mhi_dev_ctxt->mhi_ev_wq.m3_event, mhi_dev_ctxt->mhi_state == MHI_STATE_M3 || @@ -794,9 +820,9 @@ int mhi_initiate_m0(struct mhi_device_ctxt *mhi_dev_ctxt) switch (r) { case 0: mhi_log(MHI_MSG_CRITICAL, - "Timeout: State %d after %d ms\n", - mhi_dev_ctxt->mhi_state, - MHI_MAX_SUSPEND_TIMEOUT); + "Timeout: State %s after %d ms\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + MHI_MAX_SUSPEND_TIMEOUT); mhi_dev_ctxt->counters.m0_event_timeouts++; r = -ETIME; goto exit; @@ -806,7 +832,8 @@ int mhi_initiate_m0(struct mhi_device_ctxt *mhi_dev_ctxt) goto exit; default: mhi_log(MHI_MSG_INFO, - "Wait complete state: %d\n", mhi_dev_ctxt->mhi_state); + "Wait complete state: %s\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state)); r = 0; break; } @@ -814,8 +841,8 @@ int mhi_initiate_m0(struct mhi_device_ctxt *mhi_dev_ctxt) mhi_dev_ctxt->mhi_state == MHI_STATE_M1) { mhi_assert_device_wake(mhi_dev_ctxt); mhi_log(MHI_MSG_INFO, - "MHI state %d, done\n", - mhi_dev_ctxt->mhi_state); + "MHI state %s, done\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state)); goto exit; } else { if (0 != mhi_turn_on_pcie_link(mhi_dev_ctxt)) { @@ -864,9 +891,10 @@ int mhi_initiate_m3(struct mhi_device_ctxt *mhi_dev_ctxt) int r = 0, abort_m3 = 0; mhi_log(MHI_MSG_INFO, - "Entered MHI state %d, Pending M0 %d Pending M3 %d\n", - mhi_dev_ctxt->mhi_state, mhi_dev_ctxt->flags.pending_M0, - mhi_dev_ctxt->flags.pending_M3); + "Entered MHI state %s, Pending M0 %d Pending M3 %d\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + mhi_dev_ctxt->flags.pending_M0, + mhi_dev_ctxt->flags.pending_M3); mutex_lock(&mhi_dev_ctxt->pm_lock); switch (mhi_dev_ctxt->mhi_state) { case MHI_STATE_RESET: @@ -906,9 +934,9 @@ int mhi_initiate_m3(struct mhi_device_ctxt *mhi_dev_ctxt) break; case MHI_STATE_M3: mhi_log(MHI_MSG_INFO, - "MHI state %d, link state %d.\n", - mhi_dev_ctxt->mhi_state, - mhi_dev_ctxt->flags.link_up); + "MHI state %s, link state %d.\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + mhi_dev_ctxt->flags.link_up); if (mhi_dev_ctxt->flags.link_up) r = -EAGAIN; else @@ -916,9 +944,9 @@ int mhi_initiate_m3(struct mhi_device_ctxt *mhi_dev_ctxt) goto exit; default: mhi_log(MHI_MSG_INFO, - "MHI state %d, link state %d.\n", - mhi_dev_ctxt->mhi_state, - mhi_dev_ctxt->flags.link_up); + "MHI state %s, link state %d.\n", + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), + mhi_dev_ctxt->flags.link_up); break; } while (atomic_read(&mhi_dev_ctxt->counters.outbound_acks)) { diff --git a/drivers/platform/msm/mhi/mhi_sys.c b/drivers/platform/msm/mhi/mhi_sys.c index b8652770275e..3a13e6a51609 100644 --- a/drivers/platform/msm/mhi/mhi_sys.c +++ b/drivers/platform/msm/mhi/mhi_sys.c @@ -34,6 +34,17 @@ MODULE_PARM_DESC(mhi_msg_lvl, "dbg lvl"); module_param(mhi_ipc_log_lvl, uint, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(mhi_ipc_log_lvl, "dbg lvl"); +const char * const mhi_states_str[MHI_STATE_LIMIT] = { + "RESET", + "READY", + "M0", + "M1", + "M2", + "M3", + "BHI", + "SYS_ERR", +}; + static ssize_t mhi_dbgfs_chan_read(struct file *fp, char __user *buf, size_t count, loff_t *offp) { @@ -225,9 +236,9 @@ static ssize_t mhi_dbgfs_state_read(struct file *fp, char __user *buf, amnt_copied = scnprintf(mhi_dev_ctxt->chan_info, MHI_LOG_SIZE, - "%s %u %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d, %s, %d, %s %d\n", + "%s %s %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d, %s, %d, %s %d\n", "Our State:", - mhi_dev_ctxt->mhi_state, + TO_MHI_STATE_STR(mhi_dev_ctxt->mhi_state), "M0->M1:", mhi_dev_ctxt->counters.m0_m1, "M0<-M1:", diff --git a/drivers/platform/msm/mhi/mhi_sys.h b/drivers/platform/msm/mhi/mhi_sys.h index 765fd46ef2dd..a948a2354de7 100644 --- a/drivers/platform/msm/mhi/mhi_sys.h +++ b/drivers/platform/msm/mhi/mhi_sys.h @@ -46,6 +46,10 @@ extern void *mhi_ipc_log; "[%s] " _msg, __func__, ##__VA_ARGS__); \ } while (0) +extern const char * const mhi_states_str[MHI_STATE_LIMIT]; +#define TO_MHI_STATE_STR(state) (((state) >= MHI_STATE_LIMIT) ? \ + "INVALID_STATE" : mhi_states_str[state]) + irqreturn_t mhi_msi_handlr(int msi_number, void *dev_id); struct mhi_meminfo {