Skip to content

Commit ec5d9e8

Browse files
hkallweitdavem330
authored andcommitted
PCI: Add pci_status_get_and_clear_errors
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 <hkallweit1@gmail.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d6e055e commit ec5d9e8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/pci/pci.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ unsigned char pci_bus_max_busnr(struct pci_bus *bus)
173173
}
174174
EXPORT_SYMBOL_GPL(pci_bus_max_busnr);
175175

176+
/**
177+
* pci_status_get_and_clear_errors - return and clear error bits in PCI_STATUS
178+
* @pdev: the PCI device
179+
*
180+
* Returns error bits set in PCI_STATUS and clears them.
181+
*/
182+
int pci_status_get_and_clear_errors(struct pci_dev *pdev)
183+
{
184+
u16 status;
185+
int ret;
186+
187+
ret = pci_read_config_word(pdev, PCI_STATUS, &status);
188+
if (ret != PCIBIOS_SUCCESSFUL)
189+
return -EIO;
190+
191+
status &= PCI_STATUS_ERROR_BITS;
192+
if (status)
193+
pci_write_config_word(pdev, PCI_STATUS, status);
194+
195+
return status;
196+
}
197+
EXPORT_SYMBOL_GPL(pci_status_get_and_clear_errors);
198+
176199
#ifdef CONFIG_HAS_IOMEM
177200
void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
178201
{

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ int pci_select_bars(struct pci_dev *dev, unsigned long flags);
12101210
bool pci_device_is_present(struct pci_dev *pdev);
12111211
void pci_ignore_hotplug(struct pci_dev *dev);
12121212
struct pci_dev *pci_real_dma_dev(struct pci_dev *dev);
1213+
int pci_status_get_and_clear_errors(struct pci_dev *pdev);
12131214

12141215
int __printf(6, 7) pci_request_irq(struct pci_dev *dev, unsigned int nr,
12151216
irq_handler_t handler, irq_handler_t thread_fn, void *dev_id,

0 commit comments

Comments
 (0)