]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
drivers: pci: add API to issue FLR on a PCI function if supported
authorAlex Marginean <alexm.osslist@gmail.com>
Fri, 7 Jun 2019 08:24:25 +0000 (11:24 +0300)
committerSimon Glass <sjg@chromium.org>
Wed, 10 Jul 2019 22:52:58 +0000 (16:52 -0600)
Adds dm_pci_flr API that issues a Function Level reset on a PCI-e function,
if FLR is supported.

Signed-off-by: Alex Marginean <alexm.osslist@gmail.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
drivers/pci/pci-uclass.c
include/pci.h

index 389aec15ce7b6ece8c0d608a0d9acf5454394b31..c74ebf6a7635c7579351049c289cca0de308066d 100644 (file)
@@ -1494,6 +1494,30 @@ int dm_pci_find_ext_capability(struct udevice *dev, int cap)
        return dm_pci_find_next_ext_capability(dev, 0, cap);
 }
 
+int dm_pci_flr(struct udevice *dev)
+{
+       int pcie_off;
+       u32 cap;
+
+       /* look for PCI Express Capability */
+       pcie_off = dm_pci_find_capability(dev, PCI_CAP_ID_EXP);
+       if (!pcie_off)
+               return -ENOENT;
+
+       /* check FLR capability */
+       dm_pci_read_config32(dev, pcie_off + PCI_EXP_DEVCAP, &cap);
+       if (!(cap & PCI_EXP_DEVCAP_FLR))
+               return -ENOENT;
+
+       dm_pci_clrset_config16(dev, pcie_off + PCI_EXP_DEVCTL, 0,
+                              PCI_EXP_DEVCTL_BCR_FLR);
+
+       /* wait 100ms, per PCI spec */
+       mdelay(100);
+
+       return 0;
+}
+
 UCLASS_DRIVER(pci) = {
        .id             = UCLASS_PCI,
        .name           = "pci",
index 0aab4381592867ecea2cb7ac78e8e6c52d878493..298d0d43559954c6d255b7476f98eadb3ed78437 100644 (file)
 #define  PCI_EA_IS_64          0x00000002      /* 64-bit field flag */
 #define  PCI_EA_FIELD_MASK     0xfffffffc      /* For Base & Max Offset */
 
+/* PCI Express capabilities */
+#define PCI_EXP_DEVCAP         4       /* Device capabilities */
+#define  PCI_EXP_DEVCAP_FLR     0x10000000 /* Function Level Reset */
+#define PCI_EXP_DEVCTL         8       /* Device Control */
+#define  PCI_EXP_DEVCTL_BCR_FLR 0x8000  /* Bridge Configuration Retry / FLR */
+
 /* Include the ID list */
 
 #include <pci_ids.h>
@@ -1426,6 +1432,14 @@ int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap);
  */
 int dm_pci_find_ext_capability(struct udevice *dev, int cap);
 
+/**
+ * dm_pci_flr() - Perform FLR if the device suppoorts it
+ *
+ * @dev:       PCI device to reset
+ * @return:    0 if OK, -ENOENT if FLR is not supported by dev
+ */
+int dm_pci_flr(struct udevice *dev);
+
 #define dm_pci_virt_to_bus(dev, addr, flags) \
        dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (flags))
 #define dm_pci_bus_to_virt(dev, addr, flags, len, map_flags) \