Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1307984pxx; Fri, 30 Oct 2020 07:11:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykBVYfYjb2CBTMRLtcQ5nUha530x0xmFL7MWf6IEToLYP1ZzRxUjvadvK+rn+9o1hznI3U X-Received: by 2002:a17:907:2662:: with SMTP id ci2mr2590450ejc.554.1604067111665; Fri, 30 Oct 2020 07:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604067111; cv=none; d=google.com; s=arc-20160816; b=x70uEcwvRh2BorzR1LzIUTBz9lyfrKf+A7/JdOwH3D6STp0pKcjgt9Bsn1mQ355o3O NVbfYS55KpTGmnmtDCR4GeVAy+S9BMPpHHse6lpy2h4aHAt92bN2OR6YC1z3hPgF2/aD Jzye7Q4rGOgCAw8B4G49WY9j+AhXq1IEFJVlzdcvntevm/Nm03ayrAFuQUpbHsjYP+ff HhQtGdNyvbNHokutT1VXXJ3NSdEaEk8kx4PNiSwPEf/DM/CHj6vT16tPJpvN5RuRj969 1S8V5POVUyyGZPoqUF9xKz80P6Plz10d9EWkLn0XePu4f9WG86fqHzbeJTdrrXa1ix7d ChSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=yBqO9G7V3vPOOfA9ymAqZAROQYhKNVf/l8jgGHJborE=; b=jRlvw4cCpoX567YpjN539yGBy9qOE3MgOo6hNZvqRi4eb5LdC3R1NWBIogQ+r5DGJi znSRrX1y4TbDLf6F80SW/2n/5TXO+e55bIZlMT5SjFBsoiITD3AO4RJsxSYh2vm7TGEP PGV17b7lHADb8A8qadpbG+iqrgOu6Dxr3s8zlS3KqZFIQaUdAgRfr6gnF3X6LcV2Kbmr XLxj3bwkm7mscbStsSzGs2kWmorDonyL80J4VXomuGvpHvY5A2zXKGNK8EP0Psj7K+F5 eAMF+91UZWiTF7tbRc3DTJsPzfpE8KgJ2iB3ru8Tkx1jsAcVgh0xDFM9aaaMlqIl3tmo xfAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PIR+UuD6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si4064486ejw.432.2020.10.30.07.11.26; Fri, 30 Oct 2020 07:11:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PIR+UuD6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726658AbgJ3OHJ (ORCPT + 99 others); Fri, 30 Oct 2020 10:07:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726402AbgJ3OHF (ORCPT ); Fri, 30 Oct 2020 10:07:05 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94D9C0613D2 for ; Fri, 30 Oct 2020 07:07:05 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id j18so5403453pfa.0 for ; Fri, 30 Oct 2020 07:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=yBqO9G7V3vPOOfA9ymAqZAROQYhKNVf/l8jgGHJborE=; b=PIR+UuD6KFQls7giuUI8Afy1DlrBj8v+prQYL1xkSz7JESNlAXMcVt+N99CwbU5MWc Z4CKmI6xVCNS+yl8qPIRNaJgTVJk5bufLlZXz6x6JLjor63fxzfiDFJG/M996j2P/2kF sgRdo0oEO1eJ+tzgod46GXKRzrhVs6Q8JFA6l9NDr/nFaG+RfvzHKLgGrYhTsGzwGXY5 EZRW2Tlh1nI07YPDZV2BC7WRy6bhdLJj+JFhbkhhYLb9w8cslLa5XlMjkGCbsU+FQiKt PJeF/CGz3IrixC4f09gZP1sJHfL8kMpGQqdFPbvGVgvW5aLv9HhVIFBAIRn6v0PypCZE G/iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=yBqO9G7V3vPOOfA9ymAqZAROQYhKNVf/l8jgGHJborE=; b=lfjdU/rdfKW4ZlVOgKeTElDwgBc+ygwsHoI8EBvtVQJAi9zWI+UrdJxsO+enc7Q2IE iw4/ZO9FhiRlyJg8EFPD3UvUz7dG55YHmEIv+VArZamROoyBipr0poODXjIvjkbYfaak n9r5MwfWf7SsT73S3iDssJrO3m14PVKfPvqUV5aJpMZ7e4cGakKUn2Sedazx6NWoQwCy ZXKcaoyRb7XoF2cZziqVqOfLXAdhWR3IY/5RnfVzQR1z3l4NW7Skn1NrKtA3S4L82uQb q3aMj3Mq+y8xPOkAQ2BjLhUgYsU016UwBwoXb+4TswbC3DCuATaf7ANmhuQNEpqieSOw jm8w== X-Gm-Message-State: AOAM532NEeuvqV62Q/xXU7lYdtJPonZi6ar2Yp5rt3qbww63+W3mYiJ3 e5yqFidI71N6i4FlVvvpvzE6 X-Received: by 2002:a62:3383:0:b029:160:bcd:370c with SMTP id z125-20020a6233830000b02901600bcd370cmr9630695pfz.56.1604066825064; Fri, 30 Oct 2020 07:07:05 -0700 (PDT) Received: from Mani-XPS-13-9360 ([2409:4072:918:28fe:10d5:aaf5:e319:ec72]) by smtp.gmail.com with ESMTPSA id j6sm5827888pgt.77.2020.10.30.07.07.00 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Oct 2020 07:07:04 -0700 (PDT) Date: Fri, 30 Oct 2020 19:36:56 +0530 From: Manivannan Sadhasivam To: Bhaumik Bhatt Cc: linux-arm-msm@vger.kernel.org, hemantk@codeaurora.org, jhugo@codeaurora.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 10/12] bus: mhi: core: Separate system error and power down handling Message-ID: <20201030140656.GL3818@Mani-XPS-13-9360> References: <1604031057-32820-1-git-send-email-bbhatt@codeaurora.org> <1604031057-32820-11-git-send-email-bbhatt@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1604031057-32820-11-git-send-email-bbhatt@codeaurora.org> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 29, 2020 at 09:10:55PM -0700, Bhaumik Bhatt wrote: > Currently, there exist a set of if...else statements in the > mhi_pm_disable_transition() function which make handling system > error and disable transitions differently complex. To make that > cleaner and facilitate differences in behavior, separate these > two transitions for MHI host. > And this results in a lot of duplicated code :/ Thanks, Mani > Signed-off-by: Bhaumik Bhatt > --- > drivers/bus/mhi/core/pm.c | 159 +++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 137 insertions(+), 22 deletions(-) > > diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c > index 1d04e401..347ae7d 100644 > --- a/drivers/bus/mhi/core/pm.c > +++ b/drivers/bus/mhi/core/pm.c > @@ -444,7 +444,7 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl) > return ret; > } > > -/* Handle SYS_ERR and Shutdown transitions */ > +/* Handle shutdown transitions */ > static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl, > enum mhi_pm_state transition_state) > { > @@ -460,10 +460,6 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl, > to_mhi_pm_state_str(mhi_cntrl->pm_state), > to_mhi_pm_state_str(transition_state)); > > - /* We must notify MHI control driver so it can clean up first */ > - if (transition_state == MHI_PM_SYS_ERR_PROCESS) > - mhi_cntrl->status_cb(mhi_cntrl, MHI_CB_SYS_ERROR); > - > mutex_lock(&mhi_cntrl->pm_mutex); > write_lock_irq(&mhi_cntrl->pm_lock); > prev_state = mhi_cntrl->pm_state; > @@ -502,11 +498,8 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl, > MHICTRL_RESET_SHIFT, > &in_reset) || > !in_reset, timeout); > - if ((!ret || in_reset) && cur_state == MHI_PM_SYS_ERR_PROCESS) { > + if (!ret || in_reset) > dev_err(dev, "Device failed to exit MHI Reset state\n"); > - mutex_unlock(&mhi_cntrl->pm_mutex); > - return; > - } > > /* > * Device will clear BHI_INTVEC as a part of RESET processing, > @@ -566,19 +559,142 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl, > er_ctxt->wp = er_ctxt->rbase; > } > > - if (cur_state == MHI_PM_SYS_ERR_PROCESS) { > - mhi_ready_state_transition(mhi_cntrl); > - } else { > - /* Move to disable state */ > - write_lock_irq(&mhi_cntrl->pm_lock); > - cur_state = mhi_tryset_pm_state(mhi_cntrl, MHI_PM_DISABLE); > - write_unlock_irq(&mhi_cntrl->pm_lock); > - if (unlikely(cur_state != MHI_PM_DISABLE)) > - dev_err(dev, "Error moving from PM state: %s to: %s\n", > - to_mhi_pm_state_str(cur_state), > - to_mhi_pm_state_str(MHI_PM_DISABLE)); > + /* Move to disable state */ > + write_lock_irq(&mhi_cntrl->pm_lock); > + cur_state = mhi_tryset_pm_state(mhi_cntrl, MHI_PM_DISABLE); > + write_unlock_irq(&mhi_cntrl->pm_lock); > + if (unlikely(cur_state != MHI_PM_DISABLE)) > + dev_err(dev, "Error moving from PM state: %s to: %s\n", > + to_mhi_pm_state_str(cur_state), > + to_mhi_pm_state_str(MHI_PM_DISABLE)); > + > + dev_dbg(dev, "Exiting with PM state: %s, MHI state: %s\n", > + to_mhi_pm_state_str(mhi_cntrl->pm_state), > + TO_MHI_STATE_STR(mhi_cntrl->dev_state)); > + > + mutex_unlock(&mhi_cntrl->pm_mutex); > +} > + > +/* Handle system error transitions */ > +static void mhi_pm_sys_error_transition(struct mhi_controller *mhi_cntrl) > +{ > + enum mhi_pm_state cur_state, prev_state; > + struct mhi_event *mhi_event; > + struct mhi_cmd_ctxt *cmd_ctxt; > + struct mhi_cmd *mhi_cmd; > + struct mhi_event_ctxt *er_ctxt; > + struct device *dev = &mhi_cntrl->mhi_dev->dev; > + int ret, i; > + > + dev_dbg(dev, "Transitioning from PM state: %s to: %s\n", > + to_mhi_pm_state_str(mhi_cntrl->pm_state), > + to_mhi_pm_state_str(MHI_PM_SYS_ERR_PROCESS)); > + > + /* We must notify MHI control driver so it can clean up first */ > + mhi_cntrl->status_cb(mhi_cntrl, MHI_CB_SYS_ERROR); > + > + mutex_lock(&mhi_cntrl->pm_mutex); > + write_lock_irq(&mhi_cntrl->pm_lock); > + prev_state = mhi_cntrl->pm_state; > + cur_state = mhi_tryset_pm_state(mhi_cntrl, MHI_PM_SYS_ERR_PROCESS); > + write_unlock_irq(&mhi_cntrl->pm_lock); > + > + if (cur_state != MHI_PM_SYS_ERR_PROCESS) { > + dev_err(dev, "Failed to transition from PM state: %s to: %s\n", > + to_mhi_pm_state_str(cur_state), > + to_mhi_pm_state_str(MHI_PM_SYS_ERR_PROCESS)); > + goto exit_sys_error_transition; > + } > + > + mhi_cntrl->ee = MHI_EE_DISABLE_TRANSITION; > + mhi_cntrl->dev_state = MHI_STATE_RESET; > + > + /* Wake up threads waiting for state transition */ > + wake_up_all(&mhi_cntrl->state_event); > + > + /* Trigger MHI RESET so that the device will not access host memory */ > + if (MHI_REG_ACCESS_VALID(prev_state)) { > + u32 in_reset = -1; > + unsigned long timeout = msecs_to_jiffies(mhi_cntrl->timeout_ms); > + > + dev_dbg(dev, "Triggering MHI Reset in device\n"); > + mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET); > + > + /* Wait for the reset bit to be cleared by the device */ > + ret = wait_event_timeout(mhi_cntrl->state_event, > + mhi_read_reg_field(mhi_cntrl, > + mhi_cntrl->regs, > + MHICTRL, > + MHICTRL_RESET_MASK, > + MHICTRL_RESET_SHIFT, > + &in_reset) || > + !in_reset, timeout); > + if (!ret || in_reset) { > + dev_err(dev, "Device failed to exit MHI Reset state\n"); > + goto exit_sys_error_transition; > + } > + > + /* > + * Device will clear BHI_INTVEC as a part of RESET processing, > + * hence re-program it > + */ > + mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0); > + } > + > + dev_dbg(dev, > + "Waiting for all pending event ring processing to complete\n"); > + mhi_event = mhi_cntrl->mhi_event; > + for (i = 0; i < mhi_cntrl->total_ev_rings; i++, mhi_event++) { > + if (mhi_event->offload_ev) > + continue; > + tasklet_kill(&mhi_event->task); > } > > + /* Release lock and wait for all pending threads to complete */ > + mutex_unlock(&mhi_cntrl->pm_mutex); > + dev_dbg(dev, "Waiting for all pending threads to complete\n"); > + wake_up_all(&mhi_cntrl->state_event); > + > + dev_dbg(dev, "Reset all active channels and remove MHI devices\n"); > + device_for_each_child(mhi_cntrl->cntrl_dev, NULL, mhi_destroy_device); > + > + mutex_lock(&mhi_cntrl->pm_mutex); > + > + WARN_ON(atomic_read(&mhi_cntrl->dev_wake)); > + WARN_ON(atomic_read(&mhi_cntrl->pending_pkts)); > + > + /* Reset the ev rings and cmd rings */ > + dev_dbg(dev, "Resetting EV CTXT and CMD CTXT\n"); > + mhi_cmd = mhi_cntrl->mhi_cmd; > + cmd_ctxt = mhi_cntrl->mhi_ctxt->cmd_ctxt; > + for (i = 0; i < NR_OF_CMD_RINGS; i++, mhi_cmd++, cmd_ctxt++) { > + struct mhi_ring *ring = &mhi_cmd->ring; > + > + ring->rp = ring->base; > + ring->wp = ring->base; > + cmd_ctxt->rp = cmd_ctxt->rbase; > + cmd_ctxt->wp = cmd_ctxt->rbase; > + } > + > + mhi_event = mhi_cntrl->mhi_event; > + er_ctxt = mhi_cntrl->mhi_ctxt->er_ctxt; > + for (i = 0; i < mhi_cntrl->total_ev_rings; i++, er_ctxt++, > + mhi_event++) { > + struct mhi_ring *ring = &mhi_event->ring; > + > + /* Skip offload events */ > + if (mhi_event->offload_ev) > + continue; > + > + ring->rp = ring->base; > + ring->wp = ring->base; > + er_ctxt->rp = er_ctxt->rbase; > + er_ctxt->wp = er_ctxt->rbase; > + } > + > + mhi_ready_state_transition(mhi_cntrl); > + > +exit_sys_error_transition: > dev_dbg(dev, "Exiting with PM state: %s, MHI state: %s\n", > to_mhi_pm_state_str(mhi_cntrl->pm_state), > TO_MHI_STATE_STR(mhi_cntrl->dev_state)); > @@ -666,8 +782,7 @@ void mhi_pm_st_worker(struct work_struct *work) > mhi_ready_state_transition(mhi_cntrl); > break; > case DEV_ST_TRANSITION_SYS_ERR: > - mhi_pm_disable_transition > - (mhi_cntrl, MHI_PM_SYS_ERR_PROCESS); > + mhi_pm_sys_error_transition(mhi_cntrl); > break; > case DEV_ST_TRANSITION_DISABLE: > mhi_pm_disable_transition > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project >