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 22C6FC433FE for ; Wed, 17 Nov 2021 23:58:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B43561AD2 for ; Wed, 17 Nov 2021 23:58:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241772AbhKRABc (ORCPT ); Wed, 17 Nov 2021 19:01:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:59276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241730AbhKRABN (ORCPT ); Wed, 17 Nov 2021 19:01:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C8D5A61AD2; Wed, 17 Nov 2021 23:58:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637193494; bh=jt1bptChpIJAfJm7hhcvnL0z6T39eDJjHsyLzG8zD1Y=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=lyKjNjZh0qOCqIMVIpeRoNDwhdUJ/tL20BWpiwNwGttOe0RfGC7KJ4PhUovOify8k CPIwK9uSUQMg7VMxx+ystTmi5eBYFIkTtVD4sE8ulLOvbgkfTXGOpyI5/5ntrQgvl0 CfZ1WfNlECodqxIGcyQGBzURqYPwL89BjB4irtfrZDGz99G0bGiOvyoqAHp04d3fBv aBxC568xp2R7kzM9biPqbt5SZcYkGOgkMTsagR6oWZfjlJq8OfZ4tIYBwT1Dm+Bjb+ xfWKIqeKqVbpwaZ3tBQdETriNpArC0Ads/tlo1ukjZbgXjypi2+h68mtdIpt5Dhoxd 4UKc+KstDfPQQ== Date: Wed, 17 Nov 2021 17:58:12 -0600 From: Bjorn Helgaas To: Naveen Naidu Cc: bhelgaas@google.com, Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , linux-hyperv@vger.kernel.org, Heiko Stuebner , linux-pci@vger.kernel.org, Shawn Lin , Binghui Wang , Kuppuswamy Sathyanarayanan , Oliver O'Halloran , Thomas Petazzoni , Russell Currey , Lorenzo Pieralisi , Toan Le , "K. Y. Srinivasan" , Nirmal Patel , Marek Vasut , Rob Herring , Wei Liu , linux-samsung-soc@vger.kernel.org, Marc Zyngier , Joyce Ooi , Dexuan Cui , Jianjun Wang , linux-rockchip@lists.infradead.org, "maintainer:BROADCOM IPROC ARM ARCHITECTURE" , Jonathan Derrick , Xiaowei Song , linux-kernel-mentees@lists.linuxfoundation.org, Robert Richter , Sean V Kelley , Ray Jui , Haiyang Zhang , Ryder Lee , linux-mediatek@lists.infradead.org, Matthias Brugger , Stephen Hemminger , linux-arm-kernel@lists.infradead.org, Qiuxu Zhuo , Scott Branden , linuxppc-dev@lists.ozlabs.org, Yoshihiro Shimoda , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Lukas Wunner , Jingoo Han , Shawn Guo , Pali =?iso-8859-1?Q?Roh=E1r?= Subject: Re: [PATCH v3 01/25] PCI: Add PCI_ERROR_RESPONSE and it's related definitions Message-ID: <20211117235812.GA1786428@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 21, 2021 at 08:37:26PM +0530, Naveen Naidu wrote: > An MMIO read from a PCI device that doesn't exist or doesn't respond > causes a PCI error. There's no real data to return to satisfy the > CPU read, so most hardware fabricates ~0 data. > > Add a PCI_ERROR_RESPONSE definition for that and use it where > appropriate to make these checks consistent and easier to find. > > Also add helper definitions SET_PCI_ERROR_RESPONSE and > RESPONSE_IS_PCI_ERROR to make the code more readable. > > Suggested-by: Bjorn Helgaas > Signed-off-by: Naveen Naidu > --- > include/linux/pci.h | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/include/linux/pci.h b/include/linux/pci.h > index cd8aa6fce204..689c8277c584 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -154,6 +154,15 @@ enum pci_interrupt_pin { > /* The number of legacy PCI INTx interrupts */ > #define PCI_NUM_INTX 4 > > +/* > + * Reading from a device that doesn't respond typically returns ~0. A > + * successful read from a device may also return ~0, so you need additional > + * information to reliably identify errors. > + */ > +#define PCI_ERROR_RESPONSE (~0ULL) > +#define SET_PCI_ERROR_RESPONSE(val) (*(val) = ((typeof(*(val))) PCI_ERROR_RESPONSE)) > +#define RESPONSE_IS_PCI_ERROR(val) ((val) == ((typeof(val)) PCI_ERROR_RESPONSE)) Beautiful! I really like this. I would prefer the macros to start with "PCI_", e.g., PCI_SET_ERROR_RESPONSE(). I think "RESPONSE_IS_PCI_ERROR()" is too strong because (as the comment says), ~0 *may* indicate an error. Or it may be a successful read of a register that happens to contain ~0. Possibilities to convey the idea that this isn't definitive: PCI_POSSIBLE_ERROR_RESPONSE(val) # a little long PCI_LIKELY_ERROR(val) # we really have no idea whether PCI_PROBABLE_ERROR(val) # likely or probable PCI_POSSIBLE_ERROR(val) # promising? Can you rebase to my "main" branch (v5.16-rc1), tweak the above, and collect up the acks/reviews? We should also browse drivers outside drivers/pci for places we could use these. Not necessarily as part of this series, although if authors there object, it would be good to learn that earlier than later. Drivers that implement pci_error_handlers might be a fruitful place to start. But you've done a great job finding users of ~0 and 0xffff... in drivers/pci/, too. > + > /* > * pci_power_t values must match the bits in the Capabilities PME_Support > * and Control/Status PowerState fields in the Power Management capability. > -- > 2.25.1 > > _______________________________________________ > Linux-kernel-mentees mailing list > Linux-kernel-mentees@lists.linuxfoundation.org > https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees