Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3957247pxb; Tue, 2 Mar 2021 03:03:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcESuf3ZFvyGpZgIhp4imZ4wGnAd6TTtu7LA0KSJfCLHoUUU0afczOav9VhEx7yJ2eu/0J X-Received: by 2002:a17:906:a443:: with SMTP id cb3mr20114497ejb.542.1614683013111; Tue, 02 Mar 2021 03:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614683013; cv=none; d=google.com; s=arc-20160816; b=AzwYICzEFDbllj7we6yeN/jEVF9SzH2hZ/epG1X99CZCuDRhjDDN98X8n/ZO98SKEY ZOWOUNMyX3MKyO16zbhYhkllTqoYQyn9EWORRjroDkzFZBYp8P3HZzs6Pe9dcbQihH4n toVAiWsAoIKKj3OEUBiF3Oea1E2vyo672fOxtMckRBqlj29dIsG/iCuD6UKFRzoUFtMt 0DGiypNegVTaG7GHc4aGLTSmhEcghdc2Fl6G9fka2fTpypHVq6LEn1acggZEULTgZ+HO dNrhZqq/QfWNHL597S5SrmSKEY867VB8UpryXzT7Oe+hgk9SOUeyZe6OqJoVJ8JtFFG2 buNQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SAK5ZIrFTd/xjV+nDTEvr/vAYa/E25dhGOICNPYmXow=; b=kr52dI9ij9dc+EemAzBVYPg7Ot1OkRWdCfWsvaHYK1+82kK/5WFGTFfPBxZdaQAcoo EkLlYMEJ6YDpzQne+rHZkmGxBqkVmhDszSuL8TWF3feDKJFb6c/TFBND3whrJFr3E2Ve 6l4UGvJgK1ZxqIGVGEFgGBX8ergylaVFSba2uRfDkaQ8WWbRkJfjLMd3WyeIbSGk8jSK f/2aX//e8SkmOXlGI4QoLTHGzQmyY5S1tbjfUKBPmf9vYLQ6Pjz78qquf2goBmLxxAXn tYQUGu/R6zZritTCaRxodyVL3t3I2p9yiib86nwSMaw49pwjkvVmB64rSSt5wZv4Xyx6 Fi8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iSfUO7rz; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g1si12763254edw.485.2021.03.02.03.03.09; Tue, 02 Mar 2021 03:03:33 -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=@linuxfoundation.org header.s=korg header.b=iSfUO7rz; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380322AbhCBBuV (ORCPT + 99 others); Mon, 1 Mar 2021 20:50:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:48582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241698AbhCAT2n (ORCPT ); Mon, 1 Mar 2021 14:28:43 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6BE6965049; Mon, 1 Mar 2021 17:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619109; bh=Lh3KcIpt1rlEQPrwCoRqVQixD8turhgQ73SDjrYTb0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iSfUO7rzRsJVYwgRJhsOMtS7Cu8uv6OdlatLwJEZaZmtST3XrjZRz9u2cAgq9/NBz KvRDAI9F8Nustrcq/eMWaWL83r5OIW2reSIAgrd+l2NeJ9Z7fxtlnXenTgSGa+0dNs HFgaISjdB0h5LvllevQxuHHtQm8w7Csg46Ze/C2Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roja Rani Yarubandi , Akash Asthana , Wolfram Sang , Sasha Levin Subject: [PATCH 5.10 335/663] i2c: i2c-qcom-geni: Add shutdown callback for i2c Date: Mon, 1 Mar 2021 17:09:43 +0100 Message-Id: <20210301161158.425253438@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roja Rani Yarubandi [ Upstream commit e0371298ddc51761be257698554ea507ac8bf831 ] If the hardware is still accessing memory after SMMU translation is disabled (as part of smmu shutdown callback), then the IOVAs (I/O virtual address) which it was using will go on the bus as the physical addresses which will result in unknown crashes like NoC/interconnect errors. So, implement shutdown callback to i2c driver to stop on-going transfer and unmap DMA mappings during system "reboot" or "shutdown". Fixes: 37692de5d523 ("i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller") Signed-off-by: Roja Rani Yarubandi Reviewed-by: Akash Asthana Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-qcom-geni.c | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 4a6dd05d6dbf9..221cba687fe02 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -375,6 +375,32 @@ static void geni_i2c_tx_msg_cleanup(struct geni_i2c_dev *gi2c, } } +static void geni_i2c_stop_xfer(struct geni_i2c_dev *gi2c) +{ + int ret; + u32 geni_status; + struct i2c_msg *cur; + + /* Resume device, as runtime suspend can happen anytime during transfer */ + ret = pm_runtime_get_sync(gi2c->se.dev); + if (ret < 0) { + dev_err(gi2c->se.dev, "Failed to resume device: %d\n", ret); + return; + } + + geni_status = readl_relaxed(gi2c->se.base + SE_GENI_STATUS); + if (geni_status & M_GENI_CMD_ACTIVE) { + cur = gi2c->cur; + geni_i2c_abort_xfer(gi2c); + if (cur->flags & I2C_M_RD) + geni_i2c_rx_msg_cleanup(gi2c, cur); + else + geni_i2c_tx_msg_cleanup(gi2c, cur); + } + + pm_runtime_put_sync_suspend(gi2c->se.dev); +} + static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg, u32 m_param) { @@ -654,6 +680,13 @@ static int geni_i2c_remove(struct platform_device *pdev) return 0; } +static void geni_i2c_shutdown(struct platform_device *pdev) +{ + struct geni_i2c_dev *gi2c = platform_get_drvdata(pdev); + + geni_i2c_stop_xfer(gi2c); +} + static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev) { int ret; @@ -718,6 +751,7 @@ MODULE_DEVICE_TABLE(of, geni_i2c_dt_match); static struct platform_driver geni_i2c_driver = { .probe = geni_i2c_probe, .remove = geni_i2c_remove, + .shutdown = geni_i2c_shutdown, .driver = { .name = "geni_i2c", .pm = &geni_i2c_pm_ops, -- 2.27.0