Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Krishna chaitanya chundru <quic_krichai@quicinc.com>,
	manivannan.sadhasivam@linaro.org, linux-pci@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	quic_vbadigan@quicinc.com, quic_nitegupt@quicinc.com,
	quic_skananth@quicinc.com, quic_ramkri@quicinc.com,
	krzysztof.kozlowski@linaro.org,
	Manivannan Sadhasivam <mani@kernel.org>,
	Jeffrey Hugo <quic_jhugo@quicinc.com>,
	Bo Liu <liubo03@inspur.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Dan Carpenter <error27@gmail.com>,
	"open list:MHI BUS" <mhi@lists.linux.dev>
Subject: Re: [PATCH v3 9/9] bus: mhi: ep: wake up host is the MHI state is in M3
Date: Fri, 7 Jul 2023 10:12:09 -0500	[thread overview]
Message-ID: <20230707151209.GA139708@bhelgaas> (raw)
In-Reply-To: <05b4d009-b50b-4971-9220-615f73db4acd@kadam.mountain>

On Fri, Jul 07, 2023 at 02:41:57PM +0300, Dan Carpenter wrote:
> On Fri, Jul 07, 2023 at 04:33:56PM +0530, Krishna chaitanya chundru wrote:
> > If the MHI state is in M3 then the most probably the host kept the
> > device in D3 hot or D3 cold, due to that endpoint transctions will not
> > be read by the host, so endpoint wakes up host to bring the host to D0
> > which eventually bring back the MHI state to M0.
> > 
> > Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
> > ---
> >  drivers/bus/mhi/ep/main.c | 28 ++++++++++++++++++++++++++++
> >  1 file changed, 28 insertions(+)
> > 
> > diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
> > index 6008818..46a8a3c 100644
> > --- a/drivers/bus/mhi/ep/main.c
> > +++ b/drivers/bus/mhi/ep/main.c
> > @@ -25,6 +25,27 @@ static DEFINE_IDA(mhi_ep_cntrl_ida);
> >  static int mhi_ep_create_device(struct mhi_ep_cntrl *mhi_cntrl, u32 ch_id);
> >  static int mhi_ep_destroy_device(struct device *dev, void *data);
> >  
> > +static bool mhi_ep_wake_host(struct mhi_ep_cntrl *mhi_cntrl)
> > +{
> > +	enum mhi_state state;
> > +	bool mhi_reset;
> > +	u32 count = 0;
> > +
> > +	mhi_cntrl->wakeup_host(mhi_cntrl);
> > +
> > +	/* Wait for Host to set the M0 state */
> > +	do {
> > +		msleep(M0_WAIT_DELAY_MS);
> > +		mhi_ep_mmio_get_mhi_state(mhi_cntrl, &state, &mhi_reset);
> > +		count++;
> > +	} while (state != MHI_STATE_M0 && count < M0_WAIT_COUNT);
> > +
> >+	if (state != MHI_STATE_M0)
> >+		return false;
> 
> Functions which return false on success are an abomination.  Also
> boolean functions should be named for the question they answer such
> as access_ok() or has_feature() etc.

+1.  Also nice if boolean functions do not have side effects, so in
this case, where mhi_ep_wake_host() *does* something that might fail,
I think "return 0 for success or negative error value" is easier to
read.

> Write it like this:
> 
> static int mhi_ep_wake_host(struct mhi_ep_cntrl *mhi_cntrl)
> {
> 	enum mhi_state state;
> 	bool mhi_reset;
> 	int count = 0;
> 
> 	mhi_cntrl->wakeup_host(mhi_cntrl);
> 
> 	while (count++ < M0_WAIT_COUNT) {
> 		msleep(M0_WAIT_DELAY_MS);
> 
> 		mhi_ep_mmio_get_mhi_state(mhi_cntrl, &state, &mhi_reset);
> 		if (state == MHI_STATE_M0)
> 			return 0;
> 	}
> 	return -ENODEV;
> }

  reply	other threads:[~2023-07-07 15:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 11:03 [PATCH v3 0/9] PCI: EPC: Add support to wake up host from D3 states Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 1/9] PCI: endpoint: Add dstate change notifier support Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 2/9] PCI: qcom-ep: Add support for D-state change notification Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 3/9] PCI: qcom-ep: Update the D-state log Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 4/9] PCI: epf-mhi: Add support for handling D-state notify from EPC Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 5/9] PCI: endpoint: Add wakeup host API to EPC core Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 6/9] pci: dwc: Add wakeup host op to pci_epc_ops Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 7/9] PCI: qcom-ep: Add wake up host op to dw_pcie_ep_ops Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 8/9] PCI: epf-mhi: Add wakeup host op Krishna chaitanya chundru
2023-07-07 11:03 ` [PATCH v3 9/9] bus: mhi: ep: wake up host is the MHI state is in M3 Krishna chaitanya chundru
2023-07-07 11:41   ` Dan Carpenter
2023-07-07 15:12     ` Bjorn Helgaas [this message]
2023-07-11  6:15       ` Krishna Chaitanya Chundru
2023-07-07 14:57 ` [PATCH v3 0/9] PCI: EPC: Add support to wake up host from D3 states Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230707151209.GA139708@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=liubo03@inspur.com \
    --cc=mani@kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=mhi@lists.linux.dev \
    --cc=quic_jhugo@quicinc.com \
    --cc=quic_krichai@quicinc.com \
    --cc=quic_nitegupt@quicinc.com \
    --cc=quic_ramkri@quicinc.com \
    --cc=quic_skananth@quicinc.com \
    --cc=quic_vbadigan@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox