Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp909285ybj; Thu, 7 May 2020 10:17:26 -0700 (PDT) X-Google-Smtp-Source: APiQypJUyMjaDKEMhE+qPr3xuAXpL+jEHb3n7CRnVrFLQ7yq0OUGPfbkzQ7TG6HfI7j7kyXcqMIH X-Received: by 2002:a50:950a:: with SMTP id u10mr13573661eda.45.1588871846371; Thu, 07 May 2020 10:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588871846; cv=none; d=google.com; s=arc-20160816; b=tk/7ntqCHc9HmsfsZSlbLoaUUFd8L1DCrHUds3+RWikzi34qDKYa6p3x9pVS5VN7G7 RQcR93mGjD3Hlq1zMYcgR2lFtrBU+zsppt7T1cDJsImy8C4ibk4YwC/XzWyoaDSZkQDB MI2GZjpa7elcsxI3IAA98S/PyQGuG5vm/ceqjA9zalsbTdAifTitrwPLuSn5JxHtGn7B CQe7mNyo2WZwPvzsHHlxQ5sDT49e7t8y2d74YjDbXHfCO7i12/gL8WpZgCxncqsdTeIp UD886onOrDF/tEWfQU0HAsIpAAyRecHmOIywajGES5AOCigbZfl+w09MLRmZxv38Vb38 473g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature; bh=vzkpzJDEjNzJyUMHwaXm9g/03jBlK8TCDgK+mM91/A0=; b=r8Rr0VDMARoD9+fmu0+Qf1QOLm3qEX3ukwR6mcart7fStlprjRiR2X9+zMUX7Jo/Xh RQ7CYTM52Q+V++QHl43GsHt6xg1p/CfMh+9CCISONn/PU2TExzcjyXghAlZJEeQ15xnr VJtPxJEDIueBRFw/dd9Yv59rD4J5tLposFABnNG8CKF3cPwL+nCWaKro3oUtGaFqggmX 8MDgVVE6MXdfheueZWt5z9k95FFo+ENzt8dIe0s3nV+pmXbklZvsvSuO1zVSJOYF1VIp DwEMgiOHe/Dn48TVjsKafMqm8j8QA7I2AXjWCteI7LWT9cka9sctejG7FChDNRxbU/0B rYUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=CBmUvuCb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k6si3526657edq.268.2020.05.07.10.17.00; Thu, 07 May 2020 10:17:26 -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=fail header.i=@mg.codeaurora.org header.s=smtp header.b=CBmUvuCb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727870AbgEGRNA (ORCPT + 99 others); Thu, 7 May 2020 13:13:00 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:21295 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726308AbgEGRM7 (ORCPT ); Thu, 7 May 2020 13:12:59 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1588871578; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=vzkpzJDEjNzJyUMHwaXm9g/03jBlK8TCDgK+mM91/A0=; b=CBmUvuCbRIqPCZsn/RPfK+rw7IGDvzlDZkmrz72UwQ3CtpPTAbEOz+wbJ8n5fGmRRcpAiPmk UvgY82RTm4TVQ+h8jUHxqgwYEFEk2tH+4WxnJZFFPm4MSb6fB4y+wotDp33SJcirYc7/23IK VzbG/c+eCaVpXQEUuPkqOlLYtb0= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5eb44199.7f979d3003e8-smtp-out-n01; Thu, 07 May 2020 17:12:57 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 80424C433D2; Thu, 7 May 2020 17:12:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from jhugo-perf-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jhugo) by smtp.codeaurora.org (Postfix) with ESMTPSA id E783DC433F2; Thu, 7 May 2020 17:12:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E783DC433F2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=jhugo@codeaurora.org From: Jeffrey Hugo To: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: bbhatt@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Jeffrey Hugo Subject: [PATCH] bus: mhi: core: Add soc_reset sysfs Date: Thu, 7 May 2020 11:12:44 -0600 Message-Id: <1588871564-18357-1-git-send-email-jhugo@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The MHI bus supports a standardized hardware reset, which is known as the "SoC Reset". This reset is similar to the reset sysfs for PCI devices - a hardware mechanism to reset the state back to square one. The MHI SoC Reset is described in the spec as a reset of last resort. If some unrecoverable error has occurred where other resets have failed, SoC Reset is the "big hammer" that ungracefully resets the device. This is effectivly the same as yanking the power on the device, and reapplying it. However, depending on the nature of the particular issue, the underlying transport link may remain active and configured. If the link remains up, the device will flag a MHI system error early in the boot process after the reset is executed, which allows the MHI bus to process a fatal error event, and clean up appropiately. While the SoC Reset is generally intended as a means of recovery when all else has failed, it can be useful in non-error scenarios. For example, if the device loads firmware from the host filesystem, the device may need to be fully rebooted inorder to pick up the new firmware. In this scenario, the system administrator may use the soc_reset sysfs to cause the device to pick up the new firmware that the admin placed on the filesystem. Signed-off-by: Jeffrey Hugo --- Documentation/ABI/testing/sysfs-bus-mhi | 10 +++++++++ MAINTAINERS | 1 + drivers/bus/mhi/core/boot.c | 4 +--- drivers/bus/mhi/core/init.c | 40 +++++++++++++++++++++++++++++++++ drivers/bus/mhi/core/main.c | 9 ++++++++ include/linux/mhi.h | 6 +++++ 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-mhi diff --git a/Documentation/ABI/testing/sysfs-bus-mhi b/Documentation/ABI/testing/sysfs-bus-mhi new file mode 100644 index 0000000..8b06404 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-mhi @@ -0,0 +1,10 @@ +What: /sys/bus/mhi/devices//soc_reset +Date: May 2020 +KernelVersion: 5.8 +Contact: linux-arm-msm@vger.kernel.org +Description: + Initiates a SoC reset on the MHI controller. A SoC reset is + a reset of last resort, and will require a complete re-init. + This can be useful as a method of recovery if the device is + non-responsive, or as a means of loading new firmware as a + system administration task. diff --git a/MAINTAINERS b/MAINTAINERS index e64e5db..f38edac 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11018,6 +11018,7 @@ M: Hemant Kumar L: linux-arm-msm@vger.kernel.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi.git +F: Documentation/ABI/testing/sysfs-bus-mhi F: Documentation/mhi/ F: drivers/bus/mhi/ F: include/linux/mhi.h diff --git a/drivers/bus/mhi/core/boot.c b/drivers/bus/mhi/core/boot.c index ebad5eb..ebb8e00 100644 --- a/drivers/bus/mhi/core/boot.c +++ b/drivers/bus/mhi/core/boot.c @@ -112,9 +112,7 @@ static int __mhi_download_rddm_in_panic(struct mhi_controller *mhi_cntrl) /* Hardware reset so force device to enter RDDM */ dev_dbg(dev, "Did not enter RDDM, do a host req reset\n"); - mhi_write_reg(mhi_cntrl, mhi_cntrl->regs, - MHI_SOC_RESET_REQ_OFFSET, - MHI_SOC_RESET_REQ); + mhi_do_soc_reset(mhi_cntrl); udelay(delayus); } diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index eb2ab05..198afe3 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -799,6 +799,39 @@ static int parse_config(struct mhi_controller *mhi_cntrl, return ret; } +static ssize_t soc_reset_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mhi_device *mhi_dev = container_of(dev, struct mhi_device, dev); + struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl; + unsigned long value; + int rc; + + rc = kstrtoul(buf, 0, &value); + + if (rc) { + count = -EINVAL; + goto out; + } + + mhi_do_soc_reset(mhi_cntrl); + +out: + return count; +} + +DEVICE_ATTR_WO(soc_reset); + +static struct attribute *reset_attrs[] = { + &dev_attr_soc_reset.attr, + NULL, +}; + +static struct attribute_group cntrl_soc_reset_group = { + .attrs = reset_attrs, +}; + int mhi_register_controller(struct mhi_controller *mhi_cntrl, struct mhi_controller_config *config) { @@ -909,8 +942,15 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, mhi_cntrl->mhi_dev = mhi_dev; + ret = device_add_group(&mhi_dev->dev, &cntrl_soc_reset_group); + if (ret) + goto error_add_reset; + return 0; +error_add_reset: + device_del(&mhi_dev->dev); + error_add_dev: put_device(&mhi_dev->dev); diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index 0ac0643..ec7c3a0 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -1519,3 +1519,12 @@ int mhi_poll(struct mhi_device *mhi_dev, u32 budget) return ret; } EXPORT_SYMBOL_GPL(mhi_poll); + +void mhi_do_soc_reset(struct mhi_controller *mhi_cntrl) +{ + if (mhi_cntrl) + mhi_write_reg(mhi_cntrl, mhi_cntrl->regs, + MHI_SOC_RESET_REQ_OFFSET, + MHI_SOC_RESET_REQ); +} +EXPORT_SYMBOL_GPL(mhi_do_soc_reset); diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 3d7c3c2..dcdacf2 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -701,4 +701,10 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir, int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir, struct sk_buff *skb, size_t len, enum mhi_flags mflags); +/** + * mhi_do_soc_reset - Perform a SoC reset to the specified controller + * @mhi_cntrl: Controller to reset + */ +void mhi_do_soc_reset(struct mhi_controller *mhi_cntrl); + #endif /* _MHI_H_ */ -- Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.