Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp31827805rwd; Fri, 7 Jul 2023 05:10:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlFNdZ5VjUdiVelfTdj31Ido1xURpQGr2Gr8P9mTBEoSoQKhp9WxMCO3VLUVXlgVoLmjZ0Sy X-Received: by 2002:a05:6870:c20e:b0:1b0:1c36:97a with SMTP id z14-20020a056870c20e00b001b01c36097amr5961403oae.27.1688731814743; Fri, 07 Jul 2023 05:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688731814; cv=none; d=google.com; s=arc-20160816; b=Oa4lehv3kJt0lNNfCNbklvk8tddRYQE1SDIOKypM97x1fWZ8pyL+neMHEArfU7ceoU KG3B9uDh0pChb8ZBWbVMFX9F9WiwuIke0vJT6vdYiOp7/E1jA2mFTmqe+UgPpbc72GZ2 TEgTjI8fcP9Sj7Mhpkjr85uqIm/D4JDA5NSWqBX3jMnL0XjFQVHPKYDo1jwFg9SnT8Xp u9N2xCnIn4lDSARlDNOGfg6rNkQyT0P5mSFIV4lNrmCQUDTpfSfRcuBln6aMf9isNiBY NeLDVab7G8YC+UcRW4ra728eO4DGrkyKv+RlzJPuF1u8Zj6xu5rMywDEXmaQ2UM8EoLl fPyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8wa7BsPp1pwuUXYKFDe8+3rIlSyzZmk8L9MfJjPY7Hc=; fh=qzyPQqR5x/q1o0ZAURcJedX0Bvlt3OLEavAenDtNvV4=; b=orjUSkAK9FeXh2JiLjS4H4VNGBlnd+bWbbYtAmzMr+C3Q1OPEQG0oLB3lXJ9498tjD ZDniYnwylEyJBD/d8A6ogBFA0zxLYlfRfQbO9UL42XqWiYD3gHFhZ/rcdq8lNa4cZuxU K+7Lr1q1k3WKiYSMKHpxojUdn4LNqnb5Ct7cbOlCOIdQpeF0DDaOe5uUtzd9uL59OVVW 7YWemfqKekCe3S3g181BrqbKUoX2eBZa3ruN9MvCoKVJoX3VFQIl8Q+yuFL+b6BSYTR5 g03Lj9J/AifAfaUxAPTo36M1x6ruqlkFqaSg7Jpz83W7GP5ql6aM1Pqam4Bs9yU5VV7n 3ipQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q4+p1BE3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x9-20020a631709000000b005538a3e801esi3703943pgl.535.2023.07.07.05.10.00; Fri, 07 Jul 2023 05:10:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q4+p1BE3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232258AbjGGLmP (ORCPT + 99 others); Fri, 7 Jul 2023 07:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231952AbjGGLmN (ORCPT ); Fri, 7 Jul 2023 07:42:13 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEC3E171D for ; Fri, 7 Jul 2023 04:42:04 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4fb96e2b573so2821937e87.3 for ; Fri, 07 Jul 2023 04:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688730123; x=1691322123; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8wa7BsPp1pwuUXYKFDe8+3rIlSyzZmk8L9MfJjPY7Hc=; b=Q4+p1BE3f451ZQ4nncfxOhnfmawK6shA59BM3UDHQl20cQtxz2Z6Brt9NDWxt/D6zF xhFDpWZCxjmpgG3BeBjXv9kHbc7lc4rhbQEbM1MhUvpRKiArZwYaJhn4/WOyZIWphda5 +tMxSzrkiOdB5eIOQWkp0T2zpZvIIFD+Bgf+CT07wRrad774qCuGuLVpyXuwTb5N6O29 gr+EWqyxblX7Bc2lzj6U4A4HJ0cOWE4z1EAtDWKX0inJFDyPH+CwhxukS8rLzLIx+j++ 38nFy/HGu2k++J+0d/nKQxEREgNDpEzVIn1q4zU/Jfk5IDh+grbthTxVAGwHmG1tKj6f w41A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688730123; x=1691322123; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8wa7BsPp1pwuUXYKFDe8+3rIlSyzZmk8L9MfJjPY7Hc=; b=GVD/V1e6dHdMZqxg9jru2AowWVbokm9FjP02c7HJaG1Gy1B93NbrUV5aDo9r9e5ygp rpQWcEXEui1JeH0og/w2yHx4N1kfMP/hr97QnlKdVx8iBMU8rlRdVXgqMa0QTB3jEH2H YXYwad54n+2tuEUIIVqxqQ3gOX3yIxZ32pUlqhBciHy0wktzd2HassY48qNcX28uxaks /GdWwcvlRDnaSXlgU8wOHIkeoFb41X3468INliDp+N7dpWEquoD2zf3S7Raw2oV7OTyU A2rttOXjLv4QFKluZ3sb+o/SFNyyUYpldI36voGdXcu7doqdZ2P68s5rva2V+40FpQD2 q8kw== X-Gm-Message-State: ABy/qLbr2ZLwrWUYVfGZ0du2WlNmXf31mdLi/L+cjqwzBPGTpk5zE4J6 Hp+u4tSeZoTMK6zsB1gV9CLnIg== X-Received: by 2002:a05:6512:230a:b0:4fb:758c:74ed with SMTP id o10-20020a056512230a00b004fb758c74edmr4579360lfu.35.1688730123070; Fri, 07 Jul 2023 04:42:03 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id 23-20020a05600c025700b003fbc9371193sm2216754wmj.13.2023.07.07.04.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 04:42:01 -0700 (PDT) Date: Fri, 7 Jul 2023 14:41:57 +0300 From: Dan Carpenter To: Krishna chaitanya chundru Cc: manivannan.sadhasivam@linaro.org, helgaas@kernel.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 , Jeffrey Hugo , Bo Liu , Greg Kroah-Hartman , Dan Carpenter , "open list:MHI BUS" Subject: Re: [PATCH v3 9/9] bus: mhi: ep: wake up host is the MHI state is in M3 Message-ID: <05b4d009-b50b-4971-9220-615f73db4acd@kadam.mountain> References: <1688727836-11141-1-git-send-email-quic_krichai@quicinc.com> <1688727836-11141-10-git-send-email-quic_krichai@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1688727836-11141-10-git-send-email-quic_krichai@quicinc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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. Actually, I think it's the caller which is wrong. This returns true on success and false on failure. But the caller assumes true is failure. It suggests that this has not been tested. > + > + return true; > +} 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; } > + > static int mhi_ep_send_event(struct mhi_ep_cntrl *mhi_cntrl, u32 ring_idx, > struct mhi_ring_element *el, bool bei) > { > @@ -464,6 +485,13 @@ int mhi_ep_queue_skb(struct mhi_ep_device *mhi_dev, struct sk_buff *skb) > buf_left = skb->len; > ring = &mhi_cntrl->mhi_chan[mhi_chan->chan].ring; > > + if (mhi_cntrl->mhi_state == MHI_STATE_M3) { > + if (mhi_ep_wake_host(mhi_cntrl)) { > + dev_err(dev, "Failed to wakeup host\n"); > + return -ENODEV; > + } Then this becomes: if (mhi_cntrl->mhi_state == MHI_STATE_M3) { ret = mhi_ep_wake_host(mhi_cntrl); if (ret) { dev_err(dev, "Failed to wakeup host\n"); return ret; } } regards, dan carpenter