Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5991395pxb; Tue, 16 Feb 2021 12:54:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzuBycVxIEyiP8Ebk46SeFtyhqh9HiMXMlHBieX2gwcJ2QbTL1lKpqTqCOiMkSCOXcIvNM X-Received: by 2002:a17:906:c049:: with SMTP id bm9mr21764947ejb.535.1613508868003; Tue, 16 Feb 2021 12:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613508867; cv=none; d=google.com; s=arc-20160816; b=Ke11Pz6fSBDOqqWZ84NJFK/FikNZScSpy/Q6yYkbIOJCb/gF1/sbYGKjJ7U6ZwkFpl gXgcfDYV3MZz+8WqhH7sAwAV5NRr79444fK8aAVPsfgiJ1C3a9YOc0F88kTbZK0j1HQr popztPxbbO9HHraUS/TuU1i1u7TOIloz1B9zN9U4YesA2+PIqDy1u5t8utv5SOLalXO/ niuuD1+6Uek251c2EkLuc/SML8N6GI2fOMipU+QgPdPuY8I3TzVZn1WSfpzU/AmyYljM yS53r+jhdTBtwk+C3XmkK3Am1ZTVkanjwQEatf66VqHjTrhMwWmbj1ZAtZkcjNo3DPsJ pMmg== 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 :message-id:date:subject:cc:to:from:dmarc-filter:sender :dkim-signature; bh=DJ/cCF5+Vw35+SimUiMhAKV4yrK2QxIJTWhxd5v/t40=; b=aSze2cl12q76AMEnGIHA9I66ZFbUiu1ZAstaSpf00r0fU+KThWDMImRRdpg8Yaz/Md sy7eFmhUFJvu5ELY29M3Ab2r8/mhpipIWkjEpPk1szOK8UIpkIV7AeAPNoao222ifLkx 8mQEcCxxSlsAlsL52I5sOZi4bJ8m0lesI+wfTZ7yb6HE3dPw2FWqr6TFG+Ni1xHCFNRa igsAFFNq1jHDnniQjqFsf2UYEiuqVIDDSZVoRtOafjdUDJZUymysIDYKHtIxXrUZXmCV iO2N76TZc4cYeTI66Jgnv+OgL+1A2A3Vg2L3mROeZ8QGPWCcVMSO9eXJxXw8F9TyOjNO Un1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=Ep28obXm; 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 k7si8351ejb.442.2021.02.16.12.54.02; Tue, 16 Feb 2021 12:54:27 -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=@mg.codeaurora.org header.s=smtp header.b=Ep28obXm; 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 S230243AbhBPUx1 (ORCPT + 99 others); Tue, 16 Feb 2021 15:53:27 -0500 Received: from m42-2.mailgun.net ([69.72.42.2]:50123 "EHLO m42-2.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbhBPUx0 (ORCPT ); Tue, 16 Feb 2021 15:53:26 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1613508785; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: Cc: To: From: Sender; bh=DJ/cCF5+Vw35+SimUiMhAKV4yrK2QxIJTWhxd5v/t40=; b=Ep28obXmFoOWGBRwtEOuwSn8SHNZ0yvkH2TxHe1FFWhmJFKWIl5OuLhPOGngtDFZXShbO5qJ w5jWkQs9v4Gp//KBkw3xeSoBsKGcbw6uJ9SyZ9RpwOYtegjHniJ2VLNVD0cRfCd2XLt5Z//y 8bD8ofM4DQII+4XRJxE7TY0uQP8= X-Mailgun-Sending-Ip: 69.72.42.2 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 smtp-out-n07.prod.us-east-1.postgun.com with SMTP id 602c309206bddda9dfe82bf7 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 16 Feb 2021 20:52:34 GMT Sender: jhugo=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 5EAE8C43462; Tue, 16 Feb 2021 20:52:33 +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=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from jhugo-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 413C8C433CA; Tue, 16 Feb 2021 20:52:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 413C8C433CA 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=fail smtp.mailfrom=jhugo@codeaurora.org From: Jeffrey Hugo To: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org Cc: bbhatt@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Jeffrey Hugo Subject: [PATCH] mhi_bus: core: Wait for ready state after reset Date: Tue, 16 Feb 2021 13:52:25 -0700 Message-Id: <1613508745-32324-1-git-send-email-jhugo@codeaurora.org> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After the device has signaled the end of reset by clearing the reset bit, it will automatically reinit MHI and the internal device structures. Once That is done, the device will signal it has entered the ready state. Signaling the ready state involves sending an interrupt (MSI) to the host which might cause IOMMU faults if it occurs at the wrong time. If the controller is being powered down, and possibly removed, then the reset flow would only wait for the end of reset. At which point, the host and device would start a race. The host may complete its reset work, and remove the interrupt handler, which would cause the interrupt to be disabled in the IOMMU. If that occurs before the device signals the ready state, then the IOMMU will fault since it blocked an interrupt. While harmless, the fault would appear like a serious issue has occurred so let's silence it by making sure the device hits the ready state before the host completes its reset processing. Signed-off-by: Jeffrey Hugo --- drivers/bus/mhi/core/pm.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c index ef8fb4a..dc69074 100644 --- a/drivers/bus/mhi/core/pm.c +++ b/drivers/bus/mhi/core/pm.c @@ -463,7 +463,7 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl) /* Trigger MHI RESET so that the device will not access host memory */ if (!MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state)) { - u32 in_reset = -1; + u32 in_reset = -1, ready = 0; unsigned long timeout = msecs_to_jiffies(mhi_cntrl->timeout_ms); dev_dbg(dev, "Triggering MHI Reset in device\n"); @@ -486,6 +486,25 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl) * hence re-program it */ mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0); + + if (!MHI_IN_PBL(mhi_get_exec_env(mhi_cntrl))) { + /* wait for ready to be set */ + ret = wait_event_timeout(mhi_cntrl->state_event, + mhi_read_reg_field(mhi_cntrl, + mhi_cntrl->regs, + MHISTATUS, + MHISTATUS_READY_MASK, + MHISTATUS_READY_SHIFT, + &ready) + || ready, timeout); + if ((!ret || !ready) && + cur_state == MHI_PM_SYS_ERR_PROCESS) { + dev_err(dev, + "Device failed to enter READY state\n"); + mutex_unlock(&mhi_cntrl->pm_mutex); + return; + } + } } dev_dbg(dev, -- Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.