From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 385C0C433FE for ; Thu, 21 Oct 2021 00:25:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2279B60FDA for ; Thu, 21 Oct 2021 00:25:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231752AbhJUA2M (ORCPT ); Wed, 20 Oct 2021 20:28:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:44898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232587AbhJUA0g (ORCPT ); Wed, 20 Oct 2021 20:26:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 60C5F613A0; Thu, 21 Oct 2021 00:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634775861; bh=doc7mFVoN1+KAVOoT/ejQ/gIFA+0kecIC14EUT3j4N4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c8Csrl72XHO1ABkq62W937dZpowffXOzo9Qkl6Wd646EC8ZsXDxXV9sA24bIbl7ez uWGgONolIfckj4J3SrzXKHY9U7N3h+3Qe5GfMyY6h/ZfPD9WOnC5Bzf7YN1Jiofwsf aRUp7FiYBLPVJ/AP8ZPtfKEFaxj4IuHNx7LlST2mduKfpzZiuYhIsUtHB+WhsX+Wxg zhuN6OJbxbIYKF0dG6pxYlcfLgoeWGe9d9NdqCOV8/AXljGu0lxB23EXFjwy5Fyrav Bg9u999XEr3LI6VY4lNmwz68GNtA0UpgDqR131aX9aQA507EnjBXh5ReiJN3d8FdnS 7VtjAEAIMhx0A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kai Vehmanen , Takashi Iwai , Sasha Levin , perex@perex.cz, tiwai@suse.com, ranjani.sridharan@linux.intel.com, broonie@kernel.org, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 4.9 6/7] ALSA: hda: avoid write to STATESTS if controller is in reset Date: Wed, 20 Oct 2021 20:24:02 -0400 Message-Id: <20211021002404.1129946-6-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211021002404.1129946-1-sashal@kernel.org> References: <20211021002404.1129946-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kai Vehmanen [ Upstream commit b37a15188eae9d4c49c5bb035e0c8d4058e4d9b3 ] The snd_hdac_bus_reset_link() contains logic to clear STATESTS register before performing controller reset. This code dates back to an old bugfix in commit e8a7f136f5ed ("[ALSA] hda-intel - Improve HD-audio codec probing robustness"). Originally the code was added to azx_reset(). The code was moved around in commit a41d122449be ("ALSA: hda - Embed bus into controller object") and ended up to snd_hdac_bus_reset_link() and called primarily via snd_hdac_bus_init_chip(). The logic to clear STATESTS is correct when snd_hdac_bus_init_chip() is called when controller is not in reset. In this case, STATESTS can be cleared. This can be useful e.g. when forcing a controller reset to retry codec probe. A normal non-power-on reset will not clear the bits. However, this old logic is problematic when controller is already in reset. The HDA specification states that controller must be taken out of reset before writing to registers other than GCTL.CRST (1.0a spec, 3.3.7). The write to STATESTS in snd_hdac_bus_reset_link() will be lost if the controller is already in reset per the HDA specification mentioned. This has been harmless on older hardware. On newer generation of Intel PCIe based HDA controllers, if configured to report issues, this write will emit an unsupported request error. If ACPI Platform Error Interface (APEI) is enabled in kernel, this will end up to kernel log. Fix the code in snd_hdac_bus_reset_link() to only clear the STATESTS if the function is called when controller is not in reset. Otherwise clearing the bits is not possible and should be skipped. Signed-off-by: Kai Vehmanen Link: https://lore.kernel.org/r/20211012142935.3731820-1-kai.vehmanen@linux.intel.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/hda/hdac_controller.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/hda/hdac_controller.c b/sound/hda/hdac_controller.c index 00c6af2ae1c2..f0e112906c68 100644 --- a/sound/hda/hdac_controller.c +++ b/sound/hda/hdac_controller.c @@ -389,8 +389,9 @@ static int azx_reset(struct hdac_bus *bus, bool full_reset) if (!full_reset) goto skip_reset; - /* clear STATESTS */ - snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); + /* clear STATESTS if not in reset */ + if (snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) + snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK); /* reset controller */ snd_hdac_bus_enter_link_reset(bus); -- 2.33.0