Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2846329pxm; Mon, 28 Feb 2022 07:11:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEGxPkXSIfTjw8X/GmLpAWEcrPnczYSyYDGL2bn95JSl1W3QCRBV3mxHFOg6Thy7uRKZ76 X-Received: by 2002:a17:906:a1d3:b0:6d0:80ea:2fde with SMTP id bx19-20020a170906a1d300b006d080ea2fdemr14679314ejb.344.1646061096972; Mon, 28 Feb 2022 07:11:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646061096; cv=none; d=google.com; s=arc-20160816; b=sG7nzdqss2Lf4zs2FxpVfNmzvJNOuE5bhQ2vVRn0RQMBLib/EcT2E100viUDasKcLb CILvj5QeBO9WUbndLIxNnPc8glpC2P7JSH9ZX9T6azbtKnaX4CctfpjqHNKe1Dfwgqyw HN0vV12OPsY7aiIVgVwabRO5tJy4lQ5DIgRpOU7I0yurHBfNzfoSoUW4TcKdQs+zr7gG 1LJPYIdSSBUqf9cM2zxQ6hH/EnIj8gpH+KM/mV/G/SemokK9ARK8cya3ym5JXoT+xgB4 Bz2lFYuLw61oHOWftgunvPOdnVDc3wbcjF4jLmxdqv61Yp6RzJNZB1AtPqzByV9Sup9P woig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cjaL3c5klwAaHR8oe+s8/ml8ybVCH/8EnrQChldlR1Y=; b=q0+zHu+Lx+3+QOFgJ3xteTW8OpJPNbpDljbWbfin4Ej8GID3KtZU/Ztqt79STYGDf+ vokPn0xDt9M1AtyTLVzYcYvkvUQpMK8prCcqzUBJagtKnXq0N74qw5Q5ofe0HeUuE3Vm 1Xz0TYemFuwQxAwZuVNLOU7ujHzT4Twv6B/zKnlpRapO/hZOVnUyXj44cMz/6WIT2Vpt JqdgmBhpuskBxwSCESdujRj+c1mTCnOUjLTj9SVyPbuoLTowDNYNONKgMCPiIpK9jv/K 62doWBhzy0d1YfcRZczgsWBX1L8Jfg1kGqa8AUaXhbp2bAJSDwtnZKOrLeTPn4N8Qtzp 1G+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kMfFqpGc; 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 x24-20020a170906b09800b006d69d20e916si3475596ejy.603.2022.02.28.07.11.13; Mon, 28 Feb 2022 07:11:36 -0800 (PST) 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=kMfFqpGc; 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 S236811AbiB1Mqv (ORCPT + 99 others); Mon, 28 Feb 2022 07:46:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236702AbiB1Mqf (ORCPT ); Mon, 28 Feb 2022 07:46:35 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02FF475C04 for ; Mon, 28 Feb 2022 04:45:41 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id h17so5044372plc.5 for ; Mon, 28 Feb 2022 04:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cjaL3c5klwAaHR8oe+s8/ml8ybVCH/8EnrQChldlR1Y=; b=kMfFqpGcZ16z9fckg+IrxDNk3IZnNuqRPsKzp2J9kPuwZcz5F0NMDfiOj0jdPjn0mK IZJIrT5iZXWPjxrH9/WgTBUB3jk2xDhGVJfYU5EtABapv8fDljKOsIz0lfpf/QBst99s ABD57UmIain2MmSmdSIXUM0tFkMoqgTiXmESqE+1uGR+V7qC8+m2vGJQ3/ukoZMiwI2z WWw/gOcdjp+lzdsQ/LKdlZ+/ULud9XSVBBzkd/KSGTPSK5e3o/oN2DhKjBZj3hL83uY9 z2hzbz7VJ5fHdwVIZ57f3QhQd+tL8unut5YobYFGsogiiC/1FnmYvZK0B2UrwNchu/Di E2xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cjaL3c5klwAaHR8oe+s8/ml8ybVCH/8EnrQChldlR1Y=; b=VgKvRvnXDZBcO99g8MexYs+hzZ9xUAMiHQABVfdRymu6Dm0C7k3Juh8/hjNms14/I6 5fs1MS7MY1HBf4vw7zSdT7860AMX/uueuIDToS5ttOWxNz1rLU6pxhzFwbiGTtXz/bLD mI7Hudv93yzvb0RPphpT8GfiZyVhQGzhdZMhuc4e6XdIAaPTjoDOdzTAnpzGQaMSn8x6 eQcryUPm7WWjlun+jJhcRS8gah/2EYzYtsvHFaeE0VydOo0KqNj51B3hCJe+iP8OUpIh S9qdabo4dnlrU6bwugTnHwznaCasANC3Y05moG9rnySG3WgUiG7yYsAnfbuO/mnXc4Vg XYSQ== X-Gm-Message-State: AOAM531R/OUcptpYbOqwywBTxcD/3/3G95eSYjqZE0Dgxuh/1TXOHYU+ dHTZRKSnSlV9M0tceSE0minO X-Received: by 2002:a17:902:ab4c:b0:14f:bb61:ef0a with SMTP id ij12-20020a170902ab4c00b0014fbb61ef0amr20267134plb.84.1646052340421; Mon, 28 Feb 2022 04:45:40 -0800 (PST) Received: from localhost.localdomain ([117.207.25.37]) by smtp.gmail.com with ESMTPSA id y12-20020a056a00190c00b004f39e28fb87sm14256737pfi.98.2022.02.28.04.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:45:40 -0800 (PST) From: Manivannan Sadhasivam To: mhi@lists.linux.dev Cc: quic_hemantk@quicinc.com, quic_bbhatt@quicinc.com, quic_jhugo@quicinc.com, vinod.koul@linaro.org, bjorn.andersson@linaro.org, dmitry.baryshkov@linaro.org, quic_vbadigan@quicinc.com, quic_cang@quicinc.com, quic_skananth@quicinc.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, elder@linaro.org, Manivannan Sadhasivam Subject: [PATCH v4 19/27] bus: mhi: ep: Add support for powering down the MHI endpoint stack Date: Mon, 28 Feb 2022 18:13:36 +0530 Message-Id: <20220228124344.77359-20-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228124344.77359-1-manivannan.sadhasivam@linaro.org> References: <20220228124344.77359-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Add support for MHI endpoint power_down that includes stopping all available channels, destroying the channels, resetting the event and transfer rings and freeing the host cache. The stack will be powered down whenever the physical bus link goes down. Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/ep/main.c | 78 +++++++++++++++++++++++++++++++++++++++ include/linux/mhi_ep.h | 6 +++ 2 files changed, 84 insertions(+) diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c index 47807102baad..4956440273ad 100644 --- a/drivers/bus/mhi/ep/main.c +++ b/drivers/bus/mhi/ep/main.c @@ -21,6 +21,8 @@ static DEFINE_IDA(mhi_ep_cntrl_ida); +static int mhi_ep_destroy_device(struct device *dev, void *data); + static int mhi_ep_send_event(struct mhi_ep_cntrl *mhi_cntrl, u32 ring_idx, struct mhi_ring_element *el, bool bei) { @@ -432,6 +434,68 @@ static irqreturn_t mhi_ep_irq(int irq, void *data) return IRQ_HANDLED; } +static void mhi_ep_abort_transfer(struct mhi_ep_cntrl *mhi_cntrl) +{ + struct mhi_ep_ring *ch_ring, *ev_ring; + struct mhi_result result = {}; + struct mhi_ep_chan *mhi_chan; + int i; + + /* Stop all the channels */ + for (i = 0; i < mhi_cntrl->max_chan; i++) { + mhi_chan = &mhi_cntrl->mhi_chan[i]; + if (!mhi_chan->ring.started) + continue; + + mutex_lock(&mhi_chan->lock); + /* Send channel disconnect status to client drivers */ + if (mhi_chan->xfer_cb) { + result.transaction_status = -ENOTCONN; + result.bytes_xferd = 0; + mhi_chan->xfer_cb(mhi_chan->mhi_dev, &result); + } + + mhi_chan->state = MHI_CH_STATE_DISABLED; + mutex_unlock(&mhi_chan->lock); + } + + flush_workqueue(mhi_cntrl->wq); + + /* Destroy devices associated with all channels */ + device_for_each_child(&mhi_cntrl->mhi_dev->dev, NULL, mhi_ep_destroy_device); + + /* Stop and reset the transfer rings */ + for (i = 0; i < mhi_cntrl->max_chan; i++) { + mhi_chan = &mhi_cntrl->mhi_chan[i]; + if (!mhi_chan->ring.started) + continue; + + ch_ring = &mhi_cntrl->mhi_chan[i].ring; + mutex_lock(&mhi_chan->lock); + mhi_ep_ring_reset(mhi_cntrl, ch_ring); + mutex_unlock(&mhi_chan->lock); + } + + /* Stop and reset the event rings */ + for (i = 0; i < mhi_cntrl->event_rings; i++) { + ev_ring = &mhi_cntrl->mhi_event[i].ring; + if (!ev_ring->started) + continue; + + mutex_lock(&mhi_cntrl->event_lock); + mhi_ep_ring_reset(mhi_cntrl, ev_ring); + mutex_unlock(&mhi_cntrl->event_lock); + } + + /* Stop and reset the command ring */ + mhi_ep_ring_reset(mhi_cntrl, &mhi_cntrl->mhi_cmd->ring); + + mhi_ep_free_host_cfg(mhi_cntrl); + mhi_ep_mmio_mask_interrupts(mhi_cntrl); + + mhi_cntrl->enabled = false; +} + int mhi_ep_power_up(struct mhi_ep_cntrl *mhi_cntrl) { struct device *dev = &mhi_cntrl->mhi_dev->dev; @@ -486,6 +550,16 @@ int mhi_ep_power_up(struct mhi_ep_cntrl *mhi_cntrl) } EXPORT_SYMBOL_GPL(mhi_ep_power_up); +void mhi_ep_power_down(struct mhi_ep_cntrl *mhi_cntrl) +{ + if (mhi_cntrl->enabled) + mhi_ep_abort_transfer(mhi_cntrl); + + kfree(mhi_cntrl->mhi_event); + disable_irq(mhi_cntrl->irq); +} +EXPORT_SYMBOL_GPL(mhi_ep_power_down); + static void mhi_ep_release_device(struct device *dev) { struct mhi_ep_device *mhi_dev = to_mhi_ep_device(dev); @@ -765,6 +839,10 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl, } EXPORT_SYMBOL_GPL(mhi_ep_register_controller); +/* + * It is expected that the controller drivers will power down the MHI EP stack + * using "mhi_ep_power_down()" before calling this function to unregister themselves. + */ void mhi_ep_unregister_controller(struct mhi_ep_cntrl *mhi_cntrl) { struct mhi_ep_device *mhi_dev = mhi_cntrl->mhi_dev; diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h index 1b7dec859a5e..8e062a4c84f4 100644 --- a/include/linux/mhi_ep.h +++ b/include/linux/mhi_ep.h @@ -251,4 +251,10 @@ void mhi_ep_unregister_controller(struct mhi_ep_cntrl *mhi_cntrl); */ int mhi_ep_power_up(struct mhi_ep_cntrl *mhi_cntrl); +/** + * mhi_ep_power_down - Power down the MHI endpoint stack + * @mhi_cntrl: MHI controller + */ +void mhi_ep_power_down(struct mhi_ep_cntrl *mhi_cntrl); + #endif -- 2.25.1