Merge tag 'powerpc-4.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[cascardo/linux.git] / arch / powerpc / platforms / powernv / pci-ioda.c
index bc0c91e..d4b33dd 100644 (file)
@@ -124,11 +124,31 @@ static inline bool pnv_pci_is_m64(struct pnv_phb *phb, struct resource *r)
                r->start < (phb->ioda.m64_base + phb->ioda.m64_size));
 }
 
+static inline bool pnv_pci_is_m64_flags(unsigned long resource_flags)
+{
+       unsigned long flags = (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH);
+
+       return (resource_flags & flags) == flags;
+}
+
 static struct pnv_ioda_pe *pnv_ioda_init_pe(struct pnv_phb *phb, int pe_no)
 {
+       s64 rc;
+
        phb->ioda.pe_array[pe_no].phb = phb;
        phb->ioda.pe_array[pe_no].pe_number = pe_no;
 
+       /*
+        * Clear the PE frozen state as it might be put into frozen state
+        * in the last PCI remove path. It's not harmful to do so when the
+        * PE is already in unfrozen state.
+        */
+       rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe_no,
+                                      OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
+       if (rc != OPAL_SUCCESS)
+               pr_warn("%s: Error %lld unfreezing PHB#%d-PE#%d\n",
+                       __func__, rc, phb->hose->global_number, pe_no);
+
        return &phb->ioda.pe_array[pe_no];
 }
 
@@ -410,7 +430,7 @@ static void __init pnv_ioda_parse_m64_window(struct pnv_phb *phb)
        struct device_node *dn = hose->dn;
        struct resource *res;
        u32 m64_range[2], i;
-       const u32 *r;
+       const __be32 *r;
        u64 pci_addr;
 
        if (phb->type != PNV_PHB_IODA1 && phb->type != PNV_PHB_IODA2) {
@@ -2711,15 +2731,21 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,
 }
 
 #ifdef CONFIG_PCI_MSI
-static void pnv_ioda2_msi_eoi(struct irq_data *d)
+int64_t pnv_opal_pci_msi_eoi(struct irq_chip *chip, unsigned int hw_irq)
 {
-       unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
-       struct irq_chip *chip = irq_data_get_irq_chip(d);
        struct pnv_phb *phb = container_of(chip, struct pnv_phb,
                                           ioda.irq_chip);
+
+       return opal_pci_msi_eoi(phb->opal_id, hw_irq);
+}
+
+static void pnv_ioda2_msi_eoi(struct irq_data *d)
+{
        int64_t rc;
+       unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
+       struct irq_chip *chip = irq_data_get_irq_chip(d);
 
-       rc = opal_pci_msi_eoi(phb->opal_id, hw_irq);
+       rc = pnv_opal_pci_msi_eoi(chip, hw_irq);
        WARN_ON_ONCE(rc);
 
        icp_native_eoi(d);
@@ -2749,6 +2775,16 @@ void pnv_set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq)
        irq_set_chip(virq, &phb->ioda.irq_chip);
 }
 
+/*
+ * Returns true iff chip is something that we could call
+ * pnv_opal_pci_msi_eoi for.
+ */
+bool is_pnv_opal_msi(struct irq_chip *chip)
+{
+       return chip->irq_eoi == pnv_ioda2_msi_eoi;
+}
+EXPORT_SYMBOL_GPL(is_pnv_opal_msi);
+
 static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
                                  unsigned int hwirq, unsigned int virq,
                                  unsigned int is_64, struct msi_msg *msg)
@@ -2871,7 +2907,7 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev)
                res = &pdev->resource[i + PCI_IOV_RESOURCES];
                if (!res->flags || res->parent)
                        continue;
-               if (!pnv_pci_is_m64(phb, res)) {
+               if (!pnv_pci_is_m64_flags(res->flags)) {
                        dev_warn(&pdev->dev, "Don't support SR-IOV with"
                                        " non M64 VF BAR%d: %pR. \n",
                                 i, res);
@@ -3026,6 +3062,38 @@ static void pnv_ioda_setup_pe_seg(struct pnv_ioda_pe *pe)
        }
 }
 
+#ifdef CONFIG_DEBUG_FS
+static int pnv_pci_diag_data_set(void *data, u64 val)
+{
+       struct pci_controller *hose;
+       struct pnv_phb *phb;
+       s64 ret;
+
+       if (val != 1ULL)
+               return -EINVAL;
+
+       hose = (struct pci_controller *)data;
+       if (!hose || !hose->private_data)
+               return -ENODEV;
+
+       phb = hose->private_data;
+
+       /* Retrieve the diag data from firmware */
+       ret = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag.blob,
+                                         PNV_PCI_DIAG_BUF_SIZE);
+       if (ret != OPAL_SUCCESS)
+               return -EIO;
+
+       /* Print the diag data to the kernel log */
+       pnv_pci_dump_phb_diag_data(phb->hose, phb->diag.blob);
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(pnv_pci_diag_data_fops, NULL,
+                       pnv_pci_diag_data_set, "%llu\n");
+
+#endif /* CONFIG_DEBUG_FS */
+
 static void pnv_pci_ioda_create_dbgfs(void)
 {
 #ifdef CONFIG_DEBUG_FS
@@ -3041,9 +3109,14 @@ static void pnv_pci_ioda_create_dbgfs(void)
 
                sprintf(name, "PCI%04x", hose->global_number);
                phb->dbgfs = debugfs_create_dir(name, powerpc_debugfs_root);
-               if (!phb->dbgfs)
+               if (!phb->dbgfs) {
                        pr_warning("%s: Error on creating debugfs on PHB#%x\n",
                                __func__, hose->global_number);
+                       continue;
+               }
+
+               debugfs_create_file("dump_diag_regs", 0200, phb->dbgfs, hose,
+                                   &pnv_pci_diag_data_fops);
        }
 #endif /* CONFIG_DEBUG_FS */
 }
@@ -3096,7 +3169,7 @@ static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,
         * alignment for any 64-bit resource, PCIe doesn't care and
         * bridges only do 64-bit prefetchable anyway.
         */
-       if (phb->ioda.m64_segsize && (type & IORESOURCE_MEM_64))
+       if (phb->ioda.m64_segsize && pnv_pci_is_m64_flags(type))
                return phb->ioda.m64_segsize;
        if (type & IORESOURCE_MEM)
                return phb->ioda.m32_segsize;
@@ -3756,10 +3829,11 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
        if (rc)
                pr_warning("  OPAL Error %ld performing IODA table reset !\n", rc);
 
-       /* If we're running in kdump kerenl, the previous kerenl never
+       /*
+        * If we're running in kdump kernel, the previous kernel never
         * shutdown PCI devices correctly. We already got IODA table
         * cleaned out. So we have to issue PHB reset to stop all PCI
-        * transactions from previous kerenl.
+        * transactions from previous kernel.
         */
        if (is_kdump_kernel()) {
                pr_info("  Issue PHB reset ...\n");