Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cdc42de authored by Siddartha Mohanadoss's avatar Siddartha Mohanadoss
Browse files

bus: mhi: Update mhi_send_cmd timeout based on DB write



In some cases it takes more than few seconds for resume to occur
from run time suspend which switches MHI from suspend back to resume.
Under such conditions while queuing the start command unless
the host has resumed it will not ring the DB. Currently
the timeout is shorter and does not consider cases where the DB
is written or not. Update mhi_send_cmd to have a different
timeout for cases where the DB is not written yet.

Change-Id: I787e3884c6c2f8dbd569f370728ff6aadb462fe3
Signed-off-by: default avatarSiddartha Mohanadoss <smohanad@codeaurora.org>
parent d4ba3a24
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -243,6 +243,9 @@ extern struct bus_type mhi_bus_type;
#define REMOTE_TICKS_TO_US(x) (div_u64((x) * 100ULL, \
			       div_u64(mhi_cntrl->remote_timer_freq, 10000ULL)))

/* Wait time to allow runtime framework to resume MHI in milliseconds */
#define MHI_RESUME_TIME	(30000)

struct mhi_event_ctxt {
	u32 reserved : 8;
	u32 intmodc : 8;
+24 −1
Original line number Diff line number Diff line
@@ -1701,7 +1701,8 @@ int mhi_send_cmd(struct mhi_controller *mhi_cntrl,
	struct mhi_cmd *mhi_cmd = &mhi_cntrl->mhi_cmd[PRIMARY_CMD_RING];
	struct mhi_ring *ring = &mhi_cmd->ring;
	struct mhi_sfr_info *sfr_info;
	int chan = 0;
	int chan = 0, ret = 0;
	bool cmd_db_not_set = false;

	MHI_VERB("Entered, MHI pm_state:%s dev_state:%s ee:%s\n",
		 to_mhi_pm_state_str(mhi_cntrl->pm_state),
@@ -1759,11 +1760,33 @@ int mhi_send_cmd(struct mhi_controller *mhi_cntrl,
	/* queue to hardware */
	mhi_add_ring_element(mhi_cntrl, ring);
	read_lock_bh(&mhi_cntrl->pm_lock);
	/*
	 * If elements are queued to the command ring and MHI state is
	 * not M0 since MHI is in suspend or its in transition to M0, the DB
	 * will not be rung. Under such condition give it enough time from
	 * the apps to have the opportunity to resume so it can write the DB.
	 */
	if (likely(MHI_DB_ACCESS_VALID(mhi_cntrl)))
		mhi_ring_cmd_db(mhi_cntrl, mhi_cmd);
	else
		cmd_db_not_set = true;
	read_unlock_bh(&mhi_cntrl->pm_lock);
	spin_unlock_bh(&mhi_cmd->lock);

	if (cmd_db_not_set) {
		ret = wait_event_timeout(mhi_cntrl->state_event,
			MHI_DB_ACCESS_VALID(mhi_cntrl) ||
			MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state),
			msecs_to_jiffies(MHI_RESUME_TIME));
		if (!ret || MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) {
			MHI_ERR(
				"Did not enter M0, cur_state:%s pm_state:%s\n",
				TO_MHI_STATE_STR(mhi_cntrl->dev_state),
				to_mhi_pm_state_str(mhi_cntrl->pm_state));
			return -EIO;
		}
	}

	return 0;
}