From 5fc2e8342a5ff651967c5fe5e94b854547aa0add Mon Sep 17 00:00:00 2001 From: Bojun Pan Date: Mon, 18 Mar 2019 20:32:48 -0700 Subject: [PATCH] msm: ipa4: do not send USB remote wakeup again if already sent Add the check to not send the remote wakeup again if last remote wakeup hasn't taken effect and usb state not been changed yet. Change-Id: I55b2285264f85dfa4befedae4a1af5e6eaf71c4b Signed-off-by: Bojun Pan --- .../platform/msm/ipa/ipa_clients/ipa_usb.c | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/drivers/platform/msm/ipa/ipa_clients/ipa_usb.c b/drivers/platform/msm/ipa/ipa_clients/ipa_usb.c index b3e28e650819..d2d3091fb7fe 100644 --- a/drivers/platform/msm/ipa/ipa_clients/ipa_usb.c +++ b/drivers/platform/msm/ipa/ipa_clients/ipa_usb.c @@ -165,6 +165,7 @@ struct ipa3_usb_transport_type_ctx { int (*ipa_usb_notify_cb)(enum ipa_usb_notify_event, void *user_data); void *user_data; enum ipa3_usb_state state; + bool rwakeup_pending; struct ipa_usb_xdci_chan_params ul_ch_params; struct ipa_usb_xdci_chan_params dl_ch_params; struct ipa3_usb_teth_prot_conn_params teth_conn_params; @@ -295,10 +296,12 @@ static bool ipa3_usb_set_state(enum ipa3_usb_state new_state, bool err_permit, unsigned long flags; int state_legal = false; enum ipa3_usb_state state; + bool rwakeup_pending; struct ipa3_usb_rm_context *rm_ctx; spin_lock_irqsave(&ipa3_usb_ctx->state_lock, flags); state = ipa3_usb_ctx->ttype_ctx[ttype].state; + rwakeup_pending = ipa3_usb_ctx->ttype_ctx[ttype].rwakeup_pending; switch (new_state) { case IPA_USB_INVALID: if (state == IPA_USB_INITIALIZED) @@ -338,8 +341,10 @@ static bool ipa3_usb_set_state(enum ipa3_usb_state new_state, bool err_permit, * In case of failure during resume, state is reverted * to original, which could be suspended. Allow it */ - (err_permit && state == IPA_USB_RESUME_IN_PROGRESS)) + (err_permit && state == IPA_USB_RESUME_IN_PROGRESS)) { state_legal = true; + rwakeup_pending = false; + } break; case IPA_USB_SUSPENDED_NO_RWAKEUP: if (state == IPA_USB_CONNECTED) @@ -361,6 +366,8 @@ static bool ipa3_usb_set_state(enum ipa3_usb_state new_state, bool err_permit, ipa3_usb_state_to_string(state), ipa3_usb_state_to_string(new_state)); ipa3_usb_ctx->ttype_ctx[ttype].state = new_state; + ipa3_usb_ctx->ttype_ctx[ttype].rwakeup_pending = + rwakeup_pending; } } else { IPA_USB_ERR("invalid state change %s -> %s\n", @@ -544,12 +551,42 @@ static void ipa3_usb_dpl_dummy_prod_notify_cb(void *user_data, static void ipa3_usb_wq_notify_remote_wakeup(struct work_struct *work) { - ipa3_usb_notify_do(IPA_USB_TRANSPORT_TETH, IPA_USB_REMOTE_WAKEUP); + bool rwakeup_pending; + unsigned long flags; + enum ipa3_usb_transport_type ttype = + IPA_USB_TRANSPORT_TETH; + + spin_lock_irqsave(&ipa3_usb_ctx->state_lock, flags); + rwakeup_pending = + ipa3_usb_ctx->ttype_ctx[ttype].rwakeup_pending; + if (!rwakeup_pending) { + rwakeup_pending = true; + ipa3_usb_notify_do(ttype, + IPA_USB_REMOTE_WAKEUP); + } + ipa3_usb_ctx->ttype_ctx[ttype].rwakeup_pending = + rwakeup_pending; + spin_unlock_irqrestore(&ipa3_usb_ctx->state_lock, flags); } static void ipa3_usb_wq_dpl_notify_remote_wakeup(struct work_struct *work) { - ipa3_usb_notify_do(IPA_USB_TRANSPORT_DPL, IPA_USB_REMOTE_WAKEUP); + bool rwakeup_pending; + unsigned long flags; + enum ipa3_usb_transport_type ttype = + IPA_USB_TRANSPORT_DPL; + + spin_lock_irqsave(&ipa3_usb_ctx->state_lock, flags); + rwakeup_pending = + ipa3_usb_ctx->ttype_ctx[ttype].rwakeup_pending; + if (!rwakeup_pending) { + rwakeup_pending = true; + ipa3_usb_notify_do(ttype, + IPA_USB_REMOTE_WAKEUP); + } + ipa3_usb_ctx->ttype_ctx[ttype].rwakeup_pending = + rwakeup_pending; + spin_unlock_irqrestore(&ipa3_usb_ctx->state_lock, flags); } static int ipa3_usb_cons_request_resource_cb_do(