Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp528480lqc; Fri, 8 Mar 2024 05:02:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXNCrnC9E7cjqKZ/deEvTPpcR6DtCWHe3thJ/PO2rXQrJ/+y/2TN3u8GVncw4eYOl8qAy4WMK8qOxkRyB+44Xd0Nybs/3qIPmLHX3XwIA== X-Google-Smtp-Source: AGHT+IEzKbKL1Bh9vfFVKC8U0SBi38nk1uuzC4ST0JnqenwuiiJan4QSNCfRv9MZWUc/Z5Arar/Y X-Received: by 2002:a17:90a:4cc6:b0:29b:91a2:ee9d with SMTP id k64-20020a17090a4cc600b0029b91a2ee9dmr3792351pjh.24.1709902975269; Fri, 08 Mar 2024 05:02:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709902975; cv=pass; d=google.com; s=arc-20160816; b=UHT5a/eB1ySlngFzSDboI8AMeGHiUHcLRMMIUAohYaSdDLUESzYCrVSy4BteJOZGFf gMfFb8yq/QrmXXr2lMQHZDJ1HLVJHQ1+QmBONpHAAwqRl0h1X6ozuvJGY2iBn9eO6NaG 0CUVYYqvOwYgSMH3541t5oc/X5Kug5qTywv6zAshEmfsiVp+IyGpBD4Y6xc8BNJp1M3S cRqedpURQIG8w8YIuNvExU6T6nTkASUJMMewOpr5uhte5c8rpx9H51RFIXoqqrq2vBAW XJ+URH9g2RyRYByEvbUVHHe1wZhh5S+qFmSqjLjwmXUxYMMIGDm8PdBxzuboVq/2kaZX Casg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=tS/fUblKGmkjElmKOeg0k72aXdwBWcqJOUzZmrTMGZY=; fh=PkkeAgMBu5QrimF+qJn4FMMTbI6K0p7+aS2fQwEtGzI=; b=GXlyoSgAMXqzkzzR/42qFphQD2iws0yYV8/OFNpV5p7Np3vli4hOzxau1Jv9tMCqzR sZOnLlNTExAB5Fd0iW9hG2KvD/tERnveweMqd1ehI+9Yhpd7DhjC6/QmOMweVcCRfi0d NPX9XURVW6mbhVmemsTLtiZ0DtB1hJ6hFGBx1kEOG44QT6gteZXCf6Fv04DHOr9KAHNY O7MjV64EejcaDd21i3t1mNtwvW/sWwhiCpg+fOKp0ecqmRieP2Wv8H4md7QpxsUo+F9p jxrOVgHmWXJqT8yGXlgFTamGiOiGdgSEPcdzdrcSAWu757uD8JO4GhRQygdCcIyN9yzi r9QA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=r9xrE2na; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-97034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c26-20020a63725a000000b005dbde0102b0si16088376pgn.288.2024.03.08.05.02.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 05:02:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=r9xrE2na; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-97034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 134C3B21329 for ; Fri, 8 Mar 2024 13:02:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01B081CD39; Fri, 8 Mar 2024 13:02:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="r9xrE2na" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44CF0EEA9; Fri, 8 Mar 2024 13:02:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709902962; cv=none; b=F+LvqQ2IYg4wc1dVaKr92LkBgWhSMpBAWKACQ8obITmHzMWm/mwZw6BN1ti8XFv9MpFaAvP+sZ5/siMBpJlMYcCe7Prge58pgd/Zu2z/HpbHq06q+MzX1OMLCsNieFqX7PtcXsluOOVesqgzhC5r8LXvDG5fDhsuHvwf8j1n7qk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709902962; c=relaxed/simple; bh=I5YqwpsiX0KclggNHlj9WYV+KI4BcMpB3JvbIPa7aE8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cbmj0TbF/CVdz66wWcx7mDKaE+8o7Y4TQVI4Vw37TnNoGtiI16Xfq1rHhaRw+sCauJPpGXACkCCIoAXaAjpqPUUkBUZg7ftIDzCNZFNA3HOrKyNzoiE3F3AtfxkO1VCIZ8FfxJ9xIfgMWm/Xpt+G/gowgOgMNOBLFN27ISZf+wI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=r9xrE2na; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709902958; bh=I5YqwpsiX0KclggNHlj9WYV+KI4BcMpB3JvbIPa7aE8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=r9xrE2nabgTtZAH/PPwUSYXsCuq1IRkOzlpGXqpMVx5LSMT05p6H/i88jyvzyB6Wh PE7EdHwWohUfzABm8rD5N1ghF0/MjwxqPN5aBBOW5dIlUm/F/aLWGOqEWqnGQHLVo7 ULBh85CVs3dXCZOxihT5QadU54uug8BnLDGprKySAr3NvgO6ztAGYi7BOkRqk1HyC4 adRXIcKRw8ZvpLpWhciUs+rAi8kUB1HAcULzUrZmcXbKi6Lgu3bxdd9LzKRF6LQ6m/ BarzvfjjTD9u4Vxk1afjkPHnrdodV0RKzhsNAv0HvQQNbuHE2iZb29zOiNgR2v9BsX fbYrdehduz7vQ== Received: from [100.113.186.2] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 50CC937813CA; Fri, 8 Mar 2024 13:02:37 +0000 (UTC) Message-ID: Date: Fri, 8 Mar 2024 14:02:36 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] PCI: mediatek-gen3: Assert MAC reset only if PHY reset also present Content-Language: en-US To: =?UTF-8?B?Smlhbmp1biBXYW5nICjnjovlu7rlhpsp?= , "linux-pci@vger.kernel.org" Cc: "linux-kernel@vger.kernel.org" , "linux-mediatek@lists.infradead.org" , "wenst@chromium.org" , "kernel@collabora.com" , "p.zabel@pengutronix.de" , "robh@kernel.org" , "kw@linux.com" , "linux-arm-kernel@lists.infradead.org" , "bhelgaas@google.com" , "matthias.bgg@gmail.com" , "lpieralisi@kernel.org" , Ryder Lee , "nfraprado@collabora.com" References: <20240229092449.580971-1-angelogioacchino.delregno@collabora.com> <30824df32636dec25b9a5972b1ee8de76b295feb.camel@mediatek.com> <8a5a695ccbc4401954f7df5a9690af726fc59173.camel@mediatek.com> From: AngeloGioacchino Del Regno In-Reply-To: <8a5a695ccbc4401954f7df5a9690af726fc59173.camel@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Il 08/03/24 10:44, Jianjun Wang (王建军) ha scritto: > On Wed, 2024-03-06 at 09:50 +0100, AngeloGioacchino Del Regno wrote: >> Il 01/03/24 03:48, Jianjun Wang (王建军) ha scritto: >>> Hi Angelo, >>> >>> Thanks for your patch. >>> >>> On Thu, 2024-02-29 at 10:24 +0100, AngeloGioacchino Del Regno >>> wrote: >>>> Some SoCs have two PCI-Express controllers: in the case of >>>> MT8195, >>>> one of them is using a dedicated PHY, but the other uses a combo >>>> PHY >>>> that is shared with USB and in that case the PHY cannot be reset >>>> from the PCIe driver, or USB functionality will be unable to >>>> resume. >>>> >>>> Resetting the PCIe MAC without also resetting the PHY will result >>>> in >>>> a full system lockup at PCIe resume time and the only option to >>>> resume operation is to hard reboot the system (with a PMIC cut- >>>> off). >>>> >>>> To resolve this issue, check if we've got both a PHY and a MAC >>>> reset >>>> and, if not, never assert resets at PM suspend time: in that >>>> case, >>>> the link is still getting powered down as both the clocks and the >>>> power domains will go down anyway. >>>> >>>> Fixes: d537dc125f07 ("PCI: mediatek-gen3: Add system PM support") >>>> Signed-off-by: AngeloGioacchino Del Regno < >>>> angelogioacchino.delregno@collabora.com> >>>> --- >>>> >>>> Changes in v2: >>>> - Rebased over next-20240229 >>>> >>>> drivers/pci/controller/pcie-mediatek-gen3.c | 25 >>>> ++++++++++++++----- >>>> -- >>>> 1 file changed, 17 insertions(+), 8 deletions(-) >>>> >>>> diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c >>>> b/drivers/pci/controller/pcie-mediatek-gen3.c >>>> index 975b3024fb08..99b5d7a49be1 100644 >>>> --- a/drivers/pci/controller/pcie-mediatek-gen3.c >>>> +++ b/drivers/pci/controller/pcie-mediatek-gen3.c >>>> @@ -874,17 +874,26 @@ static int mtk_pcie_power_up(struct >>>> mtk_gen3_pcie *pcie) >>>> return err; >>>> } >>>> >>>> -static void mtk_pcie_power_down(struct mtk_gen3_pcie *pcie) >>>> +static void mtk_pcie_power_down(struct mtk_gen3_pcie *pcie, bool >>>> is_suspend) >>>> { >>>> + bool suspend_reset_supported = pcie->mac_reset && pcie- >>>>> phy_reset; >>>> >>>> + >>>> clk_bulk_disable_unprepare(pcie->num_clks, pcie->clks); >>>> >>>> pm_runtime_put_sync(pcie->dev); >>>> pm_runtime_disable(pcie->dev); >>>> - reset_control_assert(pcie->mac_reset); >>>> + >>>> + /* >>>> + * Assert MAC reset only if we also got a PHY reset, otherwise >>>> + * the system will lockup at PM resume time. >>>> + */ >>>> + if (is_suspend && suspend_reset_supported) >>>> + reset_control_assert(pcie->mac_reset); >>>> >>>> phy_power_off(pcie->phy); >>>> phy_exit(pcie->phy); >>>> - reset_control_assert(pcie->phy_reset); >>>> + if (is_suspend && suspend_reset_supported) >>>> + reset_control_assert(pcie->phy_reset); >>>> } >>>> >>>> static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie) >>>> @@ -920,7 +929,7 @@ static int mtk_pcie_setup(struct >>>> mtk_gen3_pcie >>>> *pcie) >>>> return 0; >>>> >>>> err_setup: >>>> - mtk_pcie_power_down(pcie); >>>> + mtk_pcie_power_down(pcie, false); >>>> >>>> return err; >>>> } >>>> @@ -951,7 +960,7 @@ static int mtk_pcie_probe(struct >>>> platform_device >>>> *pdev) >>>> err = pci_host_probe(host); >>>> if (err) { >>>> mtk_pcie_irq_teardown(pcie); >>>> - mtk_pcie_power_down(pcie); >>>> + mtk_pcie_power_down(pcie, false); >>>> return err; >>>> } >>>> >>>> @@ -969,7 +978,7 @@ static void mtk_pcie_remove(struct >>>> platform_device *pdev) >>>> pci_unlock_rescan_remove(); >>>> >>>> mtk_pcie_irq_teardown(pcie); >>>> - mtk_pcie_power_down(pcie); >>>> + mtk_pcie_power_down(pcie, false); >>> >>> Is there any reason not to reset the MAC and PHY when probe fails >>> and >>> driver removing? Some SoCs may not have MTCMOS to cut off their >>> power, >>> we need to assert the reset signal to save power in that case. >>> >> >> Sorry for the late reply - yes, there is a reason. >> >> On platforms needing this quirk, resetting at .remove() time will >> hang the >> machine if the module is reinserted later (hence, .probe() called at >> a later >> time). > > Does this only happen when the PCIe MAC is reset without resetting the > PHY? Is it related to the reset framework? > Happens only when MAC is reset without resetting the PHY after calling phy_power_off(); phy_exit(); It's not a reset framework issue, that's for sure. Angelo > Thanks. >> >> Regards, >> Angelo >> >>> Thanks. >>> >>>> } >>>> >>>> static void mtk_pcie_irq_save(struct mtk_gen3_pcie *pcie) >>>> @@ -1044,7 +1053,7 @@ static int mtk_pcie_suspend_noirq(struct >>>> device >>>> *dev) >>>> dev_dbg(pcie->dev, "entered L2 states successfully"); >>>> >>>> mtk_pcie_irq_save(pcie); >>>> - mtk_pcie_power_down(pcie); >>>> + mtk_pcie_power_down(pcie, true); >>>> >>>> return 0; >>>> } >>>> @@ -1060,7 +1069,7 @@ static int mtk_pcie_resume_noirq(struct >>>> device >>>> *dev) >>>> >>>> err = mtk_pcie_startup_port(pcie); >>>> if (err) { >>>> - mtk_pcie_power_down(pcie); >>>> + mtk_pcie_power_down(pcie, false); >>>> return err; >>>> } >>>> >> >> >> -- AngeloGioacchino Del Regno Senior Software Engineer Collabora Ltd. Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK Registered in England & Wales, no. 5513718