Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp212625pxb; Wed, 11 Nov 2020 01:31:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyC93YLZHu/VNwEp0w2j9f4qJpA7xTE9Z1iFkLYVKp84AsGRRjR2lm4HjDs1VkiXycvOeTP X-Received: by 2002:a17:906:a385:: with SMTP id k5mr24116225ejz.492.1605087102752; Wed, 11 Nov 2020 01:31:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605087102; cv=none; d=google.com; s=arc-20160816; b=R62QMkhsOgmQmNqdduWg6O/NDVTm+r5gdcTmaEng2Q4AKcyiEdNyPPkXU1NYAdRMNC Qn5jPj9Ge/WCR+beYnJdN6CL/yvwqHDD6o9Qy3diTO2965oDRxa6l7sAFE+FrEsTP3sT akQIPCyuoY1FK+38eDxkfDib6a927hthqZ+CxBo6uoHwIr2/zPLSPt5nhDw4p+7QwZz1 xwCbqOkQtX+3JdJ7l12MjwbC+YPb8Nx7jGxAsl6Nn5Igdk3bzRGDDU6lwIeImiay3Dft WGi16qW8DLo09IX/fjM+631IdV/g/DhO131DGm4IWxJUMiJhDlFkBd1txRP3fKXr1Cxw RCaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Hto8516HAJLzFc1AEPbd08Jp3k7UFBmINebfBvvB8M0=; b=WE0oJHJQNeLw0GKBdRj/cRQKL/VxRNcYLAVCGczAG61eEYYwz9xaGasYCFH73oGcGk p6sjgOW2vD+Kc7iMP5M1+ydxFS4LPxW8guCZKzpNuwIFtt/QHkMM4HB4SadGgt75U8el StusmWuQvDBG/OH8Svq+YZUBCQfJA1H8fLZ16xfjSotoFZpykQYpqZKTPzJVY7/usSxE SjRZfWIUwluWWAIJJZaoM6ARDW1rVg+zGNScQ3zltIOe19DD2foWxwsBQT0UHFZdxsG8 ag2s29fto4YaO6/rFj2Pw0mXwiNfJg2FDla3I9I5/hC00UP9zeN4nM83tGdrWLJManhX xTTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pMiryk4s; 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 e4si943067ejq.356.2020.11.11.01.31.19; Wed, 11 Nov 2020 01:31:42 -0800 (PST) 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=pMiryk4s; 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 S1727149AbgKKJ13 (ORCPT + 99 others); Wed, 11 Nov 2020 04:27:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726176AbgKKJ12 (ORCPT ); Wed, 11 Nov 2020 04:27:28 -0500 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27538C0613D1 for ; Wed, 11 Nov 2020 01:27:28 -0800 (PST) Received: by mail-ed1-x541.google.com with SMTP id t9so1537636edq.8 for ; Wed, 11 Nov 2020 01:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hto8516HAJLzFc1AEPbd08Jp3k7UFBmINebfBvvB8M0=; b=pMiryk4sK1KUjZSBUMqz/g3gf2OJTek3O/E7Dv76J6n2bPpbAA1UMakfMGtkZowtOT 1YRYSZlZXAQEQpI+HIm4HcQfwwdUliUP0hTaUrQxWJNmaVvQ3fuhBI8R6vDnC+cQcus0 BxEKp2ur2o26qtAGL6jyQC9DjxWht1Zv+3JyatFry3GEE53t+N4NfV37exEMaW7eMqVX k6BbEjtkdiYPxGWEO/5aCCuqqX/ZgzmGNXWRxYoia0xyls2251v5m8WaS9nCTuOUzvW5 V4Pu/v+Q4LcBUt2u/fSxvez+qyX18beme9uNOVo1huIBdcT4XV/ka8v+JR67Opt0IKr6 /cGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Hto8516HAJLzFc1AEPbd08Jp3k7UFBmINebfBvvB8M0=; b=MV2ozwgA6ExnJvChcG7UC+TmDi1HqYaAgU4bybei9Q3mSqycR7M+zi57NGmEESYXXo +sXxhoIqRsnX5vHTriktbHX7XI1m4sPqx0BkZHAWg33mxOD0gkjUNix6pW8mkCM6yecd 0pn4uLR8VFyz/3Qr3k7xY9CPHe/5mGdMAWz7QinLujGp3AhNEe0scmDDZ0BeGJqHchv0 fph2QIdPmYkB3lP4VSSy8O4k+1sEnBLvm5VxEInuU8tXC+ZxEwo+18aW5WusRhh8ix4d ISQ0RjIEPZ1fM9rFALr5S5G0FUBkCUeKik7lKhA4eJDz2mjneGrTTFEQhs/mv53uQ/P7 ViCw== X-Gm-Message-State: AOAM533DgT/Xn4Jjsde5zn87HgKrXBLpPW8LvZU642JhzEJ7zCb9WPp8 s0SjN9GtxMqMzqQJEShesXo/Y+7emDXP7k3fUOsVPQ== X-Received: by 2002:a05:6402:88d:: with SMTP id e13mr26629041edy.366.1605086846758; Wed, 11 Nov 2020 01:27:26 -0800 (PST) MIME-Version: 1.0 References: <1604961850-27671-1-git-send-email-bbhatt@codeaurora.org> <1604961850-27671-4-git-send-email-bbhatt@codeaurora.org> <3710a3051c480bf9d125362303815831@codeaurora.org> In-Reply-To: <3710a3051c480bf9d125362303815831@codeaurora.org> From: Loic Poulain Date: Wed, 11 Nov 2020 10:33:16 +0100 Message-ID: Subject: Re: [PATCH v1 3/4] bus: mhi: core: Add support to pause or resume channel data transfers To: Bhaumik Bhatt Cc: Manivannan Sadhasivam , linux-arm-msm , Hemant Kumar , Jeffrey Hugo , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bhaumik, On Wed, 11 Nov 2020 at 01:40, Bhaumik Bhatt wrote: > > Hi Loic, > > On 2020-11-10 03:14, Loic Poulain wrote: > > Hi Bhaumik, > > > > On Mon, 9 Nov 2020 at 23:44, Bhaumik Bhatt > > wrote: > >> > >> Some MHI clients may want to request for pausing or resuming of the > >> data transfers for their channels. Enable them to do so using the new > >> APIs provided for the same. > >> > >> Signed-off-by: Bhaumik Bhatt > >> --- > >> drivers/bus/mhi/core/main.c | 41 > >> +++++++++++++++++++++++++++++++++++++++++ > >> include/linux/mhi.h | 16 ++++++++++++++++ > >> 2 files changed, 57 insertions(+) > >> > >> diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c > >> index 1226933..01845c6 100644 > >> --- a/drivers/bus/mhi/core/main.c > >> +++ b/drivers/bus/mhi/core/main.c > >> @@ -1560,6 +1560,47 @@ void mhi_unprepare_from_transfer(struct > >> mhi_device *mhi_dev) > >> } > >> EXPORT_SYMBOL_GPL(mhi_unprepare_from_transfer); > >> > >> +static int mhi_update_transfer_state(struct mhi_device *mhi_dev, > >> + enum mhi_ch_state_type to_state) > >> +{ > >> + struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl; > >> + struct mhi_chan *mhi_chan; > >> + int dir, ret; > >> + > >> + for (dir = 0; dir < 2; dir++) { > >> + mhi_chan = dir ? mhi_dev->ul_chan : mhi_dev->dl_chan; > >> + > >> + if (!mhi_chan) > >> + continue; > >> + > >> + /* > >> + * Bail out if one of the channels fail as client will > >> reset > >> + * both upon failure > >> + */ > >> + mutex_lock(&mhi_chan->mutex); > >> + ret = mhi_update_channel_state(mhi_cntrl, mhi_chan, > >> to_state); > >> + if (ret) { > >> + mutex_unlock(&mhi_chan->mutex); > >> + return ret; > >> + } > >> + mutex_unlock(&mhi_chan->mutex); > >> + } > >> + > >> + return 0; > >> +} > >> + > >> +int mhi_pause_transfer(struct mhi_device *mhi_dev) > >> +{ > >> + return mhi_update_transfer_state(mhi_dev, > >> MHI_CH_STATE_TYPE_STOP); > >> +} > >> +EXPORT_SYMBOL_GPL(mhi_pause_transfer); > >> + > >> +int mhi_resume_transfer(struct mhi_device *mhi_dev) > >> +{ > >> + return mhi_update_transfer_state(mhi_dev, > >> MHI_CH_STATE_TYPE_START); > >> +} > >> +EXPORT_SYMBOL_GPL(mhi_resume_transfer); > > > > Look like it is stop and start, not pause and resume? > I wanted to keep it pause and resume because it could get confusing for > someone > looking at this pair of APIs, that a client driver would also need to > "start" > channels after "preparing" them. Since that is not that case, and the > mhi_prepare_for_transfer() API itself is supposed to also start the > channels, it Yes, because prepare_for_transfer is actually init_and_start. I'm not in favor of hiding what is really done at mhi_core level, start is start and stop is stop, if it's correctly documented that should not be confusing. just saying (stop moves channels in stop state, start in enabled state), but other opinions are welcome. > would be better to keep these as "pause" and "resume" instead IMO. > > Any comments in favor or "stop" and "start"? > > > > TBH maybe we should rework/clarify MHI core and having well-defined > > states, maybe something like that: > > > > 1. When MHI core detects device for a driver, MHI core resets and > > initializes the channel(s), then call client driver probe function > > => channel UNKNOWN->DISABLED state > > => channel DISABLED->ENABLED state > > 2. When driver is ready for sending data, drivers calls > > mhi_start_transfer > > => Channel is ENABLED->RUNNING state > > 3. Driver performs normal data transfers > > 4. The driver can suspend/resume transfer, it stops (suspend) the > > channel, can > > => Channel is RUNNING->STOP > > => Channel is STOP->RUNNING > > ... > > 5. When device is removed, MHI core reset the channel > > => channel is (RUNNING|STOP) -> DISABLED > > > > Today mhi_prepare_for_transfer performs both ENABLE and RUNNING > > transition, the idea would be to keep channel enabling/disabling in > > the MHI core (before/after driver probe/remove) and channel start/stop > > managed by the client driver. > > > > Regards, > > Loic > > Your idea is good but it would not have much additional benefits and > would > involve MHI core "enabling" channels and allocating memory for each > channel > context when they are only declared as supported by the controller but > are not > actually being put to use. Ok, your point is valid. > > mhi_prepare_for_transfer() does both channel context initialization and > starts > the channels, which is good because it allocates memory when needed. So, > this > benefits system memory if a controller with support for many channels > exists but > only a few channels are used. > > Regarding the states to track from host: > -> DISABLED (We know channels are not active: in reset state or not > probed yet) > -> ENABLED (Active and running when needed for data transfers) > -> STOP (Paused: leaves the channel context as is since channels are not > reset) > -> SUSPENDED (Unload in progress: Entered before resetting > channels/remove()) > > BTW, we have the debugfs entry for "channels" that dumps the context to > show > exactly what the channel states are from device perspective. We can rely > on it > if needed. > > If there are some comments I can add to make things clear, please let me > know. > > Thanks, > Bhaumik > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora > Forum, > a Linux Foundation Collaborative Project