git: e3c5f195a573 - stable/13 - LinuxKPI: pci.h add more defines and functions

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 17 Oct 2022 20:41:37 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=e3c5f195a57330e5881901c04e149d2704051b85

commit e3c5f195a57330e5881901c04e149d2704051b85
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-09-21 19:39:01 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-10-17 20:37:04 +0000

    LinuxKPI: pci.h add more defines and functions
    
    Add #defines for PCI_DEVICE_ID and repoint the PCI_VENDOR_ID one.
    Add dev_is_pci().
    Add pcie_capability_clear_word() according to similar implementations.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    hselasky, emaste
    Differential Revision: https://reviews.freebsd.org/D36653
    
    (cherry picked from commit c41d83548b6cf18b48af974ad995354f38cf04a4)
---
 sys/compat/linuxkpi/common/include/linux/pci.h | 29 ++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index 6493391926e2..79999c3912f7 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -4,7 +4,7 @@
  * Copyright (c) 2010 Panasas, Inc.
  * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
  * All rights reserved.
- * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2020-2022 The FreeBSD Foundation
  *
  * Portions of this software were developed by Björn Zeeb
  * under sponsorship from the FreeBSD Foundation.
@@ -108,7 +108,8 @@ MODULE_PNP_INFO("U32:vendor;U32:device;V32:subvendor;V32:subdevice",	\
 
 #define	to_pci_dev(n)	container_of(n, struct pci_dev, dev)
 
-#define	PCI_VENDOR_ID		PCIR_DEVVENDOR
+#define	PCI_VENDOR_ID		PCIR_VENDOR
+#define	PCI_DEVICE_ID		PCIR_DEVICE
 #define	PCI_COMMAND		PCIR_COMMAND
 #define	PCI_COMMAND_INTX_DISABLE	PCIM_CMD_INTxDIS
 #define	PCI_EXP_DEVCTL		PCIER_DEVICE_CTL		/* Device Control */
@@ -215,6 +216,7 @@ typedef int pci_power_t;
 #define	PCI_IRQ_LEGACY			0x01
 #define	PCI_IRQ_MSI			0x02
 #define	PCI_IRQ_MSIX			0x04
+#define	PCI_IRQ_ALL_TYPES		(PCI_IRQ_MSIX|PCI_IRQ_MSI|PCI_IRQ_LEGACY)
 
 struct pci_dev;
 
@@ -352,6 +354,13 @@ struct resource *_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size);
 struct pcim_iomap_devres *lkpi_pcim_iomap_devres_find(struct pci_dev *pdev);
 void lkpi_pcim_iomap_table_release(struct device *, void *);
 
+static inline bool
+dev_is_pci(struct device *dev)
+{
+
+	return (device_get_devclass(dev->bsddev) == devclass_find("pci"));
+}
+
 static inline int
 pci_resource_type(struct pci_dev *pdev, int bar)
 {
@@ -1183,6 +1192,22 @@ pcie_capability_set_word(struct pci_dev *dev, int pos, uint16_t val)
 	return (error);
 }
 
+static inline int
+pcie_capability_clear_word(struct pci_dev *dev, int pos, uint16_t val)
+{
+	int error;
+	uint16_t v;
+
+	error = pcie_capability_read_word(dev, pos, &v);
+	if (error != 0)
+		return (error);
+
+	v &= ~val;
+
+	error = pcie_capability_write_word(dev, pos, v);
+	return (error);
+}
+
 static inline int pcie_get_minimum_link(struct pci_dev *dev,
     enum pci_bus_speed *speed, enum pcie_link_width *width)
 {