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 X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FAKE_REPLY_C,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1422C3F2D1 for ; Wed, 4 Mar 2020 13:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 88DAE2166E for ; Wed, 4 Mar 2020 13:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583329405; bh=bd9ndjT7AYvi56VQfiR+K6l5n2gZ21sXBUyPecBW1VQ=; h=Date:From:To:Cc:Subject:In-Reply-To:List-ID:From; b=jUQp/8yp76Ds7+pLNT+UmO/YxZTxNb+D7gTFGKj4Vm+VzwMNhgfFh4YyrVJE74VIj z1TRITZdJsjFlCRCGJuniZcYxM8he4g5Ji8yoz0e/TAX+aOEGITYxIYXiQAA19dFH1 xkB04JrY0asm1dYBDFdo6nIIX1v9IFMZ65cUKF5Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729461AbgCDNnU (ORCPT ); Wed, 4 Mar 2020 08:43:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:57038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729398AbgCDNnU (ORCPT ); Wed, 4 Mar 2020 08:43:20 -0500 Received: from localhost (173-25-83-245.client.mchsi.com [173.25.83.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A86572146E; Wed, 4 Mar 2020 13:43:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583329400; bh=bd9ndjT7AYvi56VQfiR+K6l5n2gZ21sXBUyPecBW1VQ=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=uj1k1VthJWKcRmIO155xpN0EN9vdJ1x4kXfvIwF2NnU+2z49sHJ0NHovHboRXE53j Oft81aIkx9Zhwc0Bz0mfFd2x2bSqV2Irb1et1lBEiTP0dWqZRfJ79tNnst7hcMU+JM c44A/813tEeOxuxwgFTTJJrdzpw+pDCv/1JXGK04= Date: Wed, 4 Mar 2020 07:43:18 -0600 From: Bjorn Helgaas To: Heiner Kallweit Cc: Realtek linux nic maintainers , David Miller , Mirko Lindner , Stephen Hemminger , Clemens Ladisch , Jaroslav Kysela , Takashi Iwai , "linux-pci@vger.kernel.org" , Linux Kernel Mailing List , "netdev@vger.kernel.org" , alsa-devel@alsa-project.org Subject: Re: [PATCH v4 05/10] PCI: Add pci_status_get_and_clear_errors Message-ID: <20200304134318.GA193797@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Sat, Feb 29, 2020 at 11:24:23PM +0100, Heiner Kallweit wrote: > Several drivers use the following code sequence: > 1. Read PCI_STATUS > 2. Mask out non-error bits > 3. Action based on error bits set > 4. Write back set error bits to clear them > > As this is a repeated pattern, add a helper to the PCI core. > > Signed-off-by: Heiner Kallweit Acked-by: Bjorn Helgaas Nit: if you have any reason to revise this, I would prefer "pci_status_get_and_clear_errors()" (with parens) in the subject. > --- > v4: > - improve commit description > --- > drivers/pci/pci.c | 23 +++++++++++++++++++++++ > include/linux/pci.h | 1 + > 2 files changed, 24 insertions(+) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index d828ca835..c16b0ba2a 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -173,6 +173,29 @@ unsigned char pci_bus_max_busnr(struct pci_bus *bus) > } > EXPORT_SYMBOL_GPL(pci_bus_max_busnr); > > +/** > + * pci_status_get_and_clear_errors - return and clear error bits in PCI_STATUS > + * @pdev: the PCI device > + * > + * Returns error bits set in PCI_STATUS and clears them. > + */ > +int pci_status_get_and_clear_errors(struct pci_dev *pdev) > +{ > + u16 status; > + int ret; > + > + ret = pci_read_config_word(pdev, PCI_STATUS, &status); > + if (ret != PCIBIOS_SUCCESSFUL) > + return -EIO; > + > + status &= PCI_STATUS_ERROR_BITS; > + if (status) > + pci_write_config_word(pdev, PCI_STATUS, status); > + > + return status; > +} > +EXPORT_SYMBOL_GPL(pci_status_get_and_clear_errors); > + > #ifdef CONFIG_HAS_IOMEM > void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) > { > diff --git a/include/linux/pci.h b/include/linux/pci.h > index 101d71e0a..7beaf51e9 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -1210,6 +1210,7 @@ int pci_select_bars(struct pci_dev *dev, unsigned long flags); > bool pci_device_is_present(struct pci_dev *pdev); > void pci_ignore_hotplug(struct pci_dev *dev); > struct pci_dev *pci_real_dma_dev(struct pci_dev *dev); > +int pci_status_get_and_clear_errors(struct pci_dev *pdev); > > int __printf(6, 7) pci_request_irq(struct pci_dev *dev, unsigned int nr, > irq_handler_t handler, irq_handler_t thread_fn, void *dev_id, > -- > 2.25.1 > >