| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Support PCI/PCIe on PowerNV platforms | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Currently supports only P5IOC2 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 2011 Benjamin Herrenschmidt, IBM Corp. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version | 
					
						
							|  |  |  |  * 2 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/pci.h>
 | 
					
						
							|  |  |  | #include <linux/delay.h>
 | 
					
						
							|  |  |  | #include <linux/string.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | #include <linux/bootmem.h>
 | 
					
						
							|  |  |  | #include <linux/irq.h>
 | 
					
						
							|  |  |  | #include <linux/io.h>
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | #include <linux/msi.h>
 | 
					
						
							| 
									
										
										
										
											2013-05-21 13:33:09 +10:00
										 |  |  | #include <linux/iommu.h>
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <asm/sections.h>
 | 
					
						
							|  |  |  | #include <asm/io.h>
 | 
					
						
							|  |  |  | #include <asm/prom.h>
 | 
					
						
							|  |  |  | #include <asm/pci-bridge.h>
 | 
					
						
							|  |  |  | #include <asm/machdep.h>
 | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | #include <asm/msi_bitmap.h>
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | #include <asm/ppc-pci.h>
 | 
					
						
							|  |  |  | #include <asm/opal.h>
 | 
					
						
							|  |  |  | #include <asm/iommu.h>
 | 
					
						
							|  |  |  | #include <asm/tce.h>
 | 
					
						
							| 
									
										
										
										
											2012-03-15 18:18:00 +00:00
										 |  |  | #include <asm/firmware.h>
 | 
					
						
							| 
									
										
										
										
											2013-06-20 13:21:15 +08:00
										 |  |  | #include <asm/eeh_event.h>
 | 
					
						
							|  |  |  | #include <asm/eeh.h>
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "powernv.h"
 | 
					
						
							|  |  |  | #include "pci.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:07 +00:00
										 |  |  | /* Delay in usec */ | 
					
						
							|  |  |  | #define PCI_RESET_DELAY_US	3000000
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define cfg_dbg(fmt...)	do { } while(0)
 | 
					
						
							|  |  |  | //#define cfg_dbg(fmt...)	printk(fmt)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | #ifdef CONFIG_PCI_MSI
 | 
					
						
							|  |  |  | static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct pci_controller *hose = pci_bus_to_host(pdev->bus); | 
					
						
							|  |  |  | 	struct pnv_phb *phb = hose->private_data; | 
					
						
							| 
									
										
										
										
											2014-09-07 20:57:53 +02:00
										 |  |  | 	struct pci_dn *pdn = pci_get_pdn(pdev); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 	struct msi_desc *entry; | 
					
						
							|  |  |  | 	struct msi_msg msg; | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | 	int hwirq; | 
					
						
							|  |  |  | 	unsigned int virq; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 	int rc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-07 20:57:53 +02:00
										 |  |  | 	if (WARN_ON(!phb) || !phb->msi_bmp.bitmap) | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (pdn && pdn->force_32bit_msi && !phb->msi32_support) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_for_each_entry(entry, &pdev->msi_list, list) { | 
					
						
							|  |  |  | 		if (!entry->msi_attrib.is_64 && !phb->msi32_support) { | 
					
						
							|  |  |  | 			pr_warn("%s: Supports only 64-bit MSIs\n", | 
					
						
							|  |  |  | 				pci_name(pdev)); | 
					
						
							|  |  |  | 			return -ENXIO; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | 		hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, 1); | 
					
						
							|  |  |  | 		if (hwirq < 0) { | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 			pr_warn("%s: Failed to find a free MSI\n", | 
					
						
							|  |  |  | 				pci_name(pdev)); | 
					
						
							|  |  |  | 			return -ENOSPC; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | 		virq = irq_create_mapping(NULL, phb->msi_base + hwirq); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 		if (virq == NO_IRQ) { | 
					
						
							|  |  |  | 			pr_warn("%s: Failed to map MSI to linux irq\n", | 
					
						
							|  |  |  | 				pci_name(pdev)); | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | 			msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 			return -ENOMEM; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | 		rc = phb->msi_setup(phb, pdev, phb->msi_base + hwirq, | 
					
						
							| 
									
										
										
										
											2013-04-25 19:20:59 +00:00
										 |  |  | 				    virq, entry->msi_attrib.is_64, &msg); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 		if (rc) { | 
					
						
							|  |  |  | 			pr_warn("%s: Failed to setup MSI\n", pci_name(pdev)); | 
					
						
							|  |  |  | 			irq_dispose_mapping(virq); | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | 			msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 			return rc; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		irq_set_msi_desc(virq, entry); | 
					
						
							|  |  |  | 		write_msi_msg(virq, &msg); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pnv_teardown_msi_irqs(struct pci_dev *pdev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct pci_controller *hose = pci_bus_to_host(pdev->bus); | 
					
						
							|  |  |  | 	struct pnv_phb *phb = hose->private_data; | 
					
						
							|  |  |  | 	struct msi_desc *entry; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (WARN_ON(!phb)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_for_each_entry(entry, &pdev->msi_list, list) { | 
					
						
							|  |  |  | 		if (entry->irq == NO_IRQ) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		irq_set_msi_desc(entry->irq, NULL); | 
					
						
							| 
									
										
										
										
											2013-03-05 21:12:37 +00:00
										 |  |  | 		msi_bitmap_free_hwirqs(&phb->msi_bmp, | 
					
						
							|  |  |  | 			virq_to_hw(entry->irq) - phb->msi_base, 1); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 		irq_dispose_mapping(entry->irq); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif /* CONFIG_PCI_MSI */
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | static void pnv_pci_dump_p7ioc_diag_data(struct pci_controller *hose, | 
					
						
							|  |  |  | 					 struct OpalIoPhbErrorCommon *common) | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 	struct OpalIoP7IOCPhbErrorData *data; | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 	data = (struct OpalIoP7IOCPhbErrorData *)common; | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	pr_info("P7IOC PHB#%d Diag-data (Version: %d)\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 		hose->global_number, be32_to_cpu(common->version)); | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->brdgCtl) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("brdgCtl:     %08x\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be32_to_cpu(data->brdgCtl)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->portStatusReg || data->rootCmplxStatus || | 
					
						
							|  |  |  | 	    data->busAgentStatus) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("UtlSts:      %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be32_to_cpu(data->portStatusReg), | 
					
						
							|  |  |  | 			be32_to_cpu(data->rootCmplxStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->busAgentStatus)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->deviceStatus || data->slotStatus   || | 
					
						
							|  |  |  | 	    data->linkStatus   || data->devCmdStatus || | 
					
						
							|  |  |  | 	    data->devSecStatus) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootSts:     %08x %08x %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be32_to_cpu(data->deviceStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->slotStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->linkStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->devCmdStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->devSecStatus)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->rootErrorStatus   || data->uncorrErrorStatus || | 
					
						
							|  |  |  | 	    data->corrErrorStatus) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootErrSts:  %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be32_to_cpu(data->rootErrorStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->uncorrErrorStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->corrErrorStatus)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->tlpHdr1 || data->tlpHdr2 || | 
					
						
							|  |  |  | 	    data->tlpHdr3 || data->tlpHdr4) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootErrLog:  %08x %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be32_to_cpu(data->tlpHdr1), | 
					
						
							|  |  |  | 			be32_to_cpu(data->tlpHdr2), | 
					
						
							|  |  |  | 			be32_to_cpu(data->tlpHdr3), | 
					
						
							|  |  |  | 			be32_to_cpu(data->tlpHdr4)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->sourceId || data->errorClass || | 
					
						
							|  |  |  | 	    data->correlator) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootErrLog1: %08x %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be32_to_cpu(data->sourceId), | 
					
						
							|  |  |  | 			be64_to_cpu(data->errorClass), | 
					
						
							|  |  |  | 			be64_to_cpu(data->correlator)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->p7iocPlssr || data->p7iocCsr) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("PhbSts:      %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be64_to_cpu(data->p7iocPlssr), | 
					
						
							|  |  |  | 			be64_to_cpu(data->p7iocCsr)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->lemFir) | 
					
						
							|  |  |  | 		pr_info("Lem:         %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be64_to_cpu(data->lemFir), | 
					
						
							|  |  |  | 			be64_to_cpu(data->lemErrorMask), | 
					
						
							|  |  |  | 			be64_to_cpu(data->lemWOF)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->phbErrorStatus) | 
					
						
							|  |  |  | 		pr_info("PhbErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be64_to_cpu(data->phbErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->phbFirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->phbErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->phbErrorLog1)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->mmioErrorStatus) | 
					
						
							|  |  |  | 		pr_info("OutErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be64_to_cpu(data->mmioErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->mmioFirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->mmioErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->mmioErrorLog1)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->dma0ErrorStatus) | 
					
						
							|  |  |  | 		pr_info("InAErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be64_to_cpu(data->dma0ErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma0FirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma0ErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma0ErrorLog1)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->dma1ErrorStatus) | 
					
						
							|  |  |  | 		pr_info("InBErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			be64_to_cpu(data->dma1ErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma1FirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma1ErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma1ErrorLog1)); | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) { | 
					
						
							|  |  |  | 		if ((data->pestA[i] >> 63) == 0 && | 
					
						
							|  |  |  | 		    (data->pestB[i] >> 63) == 0) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("PE[%3d] A/B: %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-07-17 14:41:42 +10:00
										 |  |  | 			i, be64_to_cpu(data->pestA[i]), | 
					
						
							|  |  |  | 			be64_to_cpu(data->pestB[i])); | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | static void pnv_pci_dump_phb3_diag_data(struct pci_controller *hose, | 
					
						
							|  |  |  | 					struct OpalIoPhbErrorCommon *common) | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 	struct OpalIoPhb3ErrorData *data; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	data = (struct OpalIoPhb3ErrorData*)common; | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	pr_info("PHB3 PHB#%d Diag-data (Version: %d)\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 		hose->global_number, be32_to_cpu(common->version)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->brdgCtl) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("brdgCtl:     %08x\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be32_to_cpu(data->brdgCtl)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->portStatusReg || data->rootCmplxStatus || | 
					
						
							|  |  |  | 	    data->busAgentStatus) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("UtlSts:      %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be32_to_cpu(data->portStatusReg), | 
					
						
							|  |  |  | 			be32_to_cpu(data->rootCmplxStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->busAgentStatus)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->deviceStatus || data->slotStatus   || | 
					
						
							|  |  |  | 	    data->linkStatus   || data->devCmdStatus || | 
					
						
							|  |  |  | 	    data->devSecStatus) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootSts:     %08x %08x %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be32_to_cpu(data->deviceStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->slotStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->linkStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->devCmdStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->devSecStatus)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->rootErrorStatus || data->uncorrErrorStatus || | 
					
						
							|  |  |  | 	    data->corrErrorStatus) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootErrSts:  %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be32_to_cpu(data->rootErrorStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->uncorrErrorStatus), | 
					
						
							|  |  |  | 			be32_to_cpu(data->corrErrorStatus)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->tlpHdr1 || data->tlpHdr2 || | 
					
						
							|  |  |  | 	    data->tlpHdr3 || data->tlpHdr4) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootErrLog:  %08x %08x %08x %08x\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be32_to_cpu(data->tlpHdr1), | 
					
						
							|  |  |  | 			be32_to_cpu(data->tlpHdr2), | 
					
						
							|  |  |  | 			be32_to_cpu(data->tlpHdr3), | 
					
						
							|  |  |  | 			be32_to_cpu(data->tlpHdr4)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->sourceId || data->errorClass || | 
					
						
							|  |  |  | 	    data->correlator) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("RootErrLog1: %08x %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be32_to_cpu(data->sourceId), | 
					
						
							|  |  |  | 			be64_to_cpu(data->errorClass), | 
					
						
							|  |  |  | 			be64_to_cpu(data->correlator)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->nFir) | 
					
						
							|  |  |  | 		pr_info("nFir:        %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be64_to_cpu(data->nFir), | 
					
						
							|  |  |  | 			be64_to_cpu(data->nFirMask), | 
					
						
							|  |  |  | 			be64_to_cpu(data->nFirWOF)); | 
					
						
							| 
									
										
										
										
											2014-02-25 15:28:38 +08:00
										 |  |  | 	if (data->phbPlssr || data->phbCsr) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("PhbSts:      %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be64_to_cpu(data->phbPlssr), | 
					
						
							|  |  |  | 			be64_to_cpu(data->phbCsr)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->lemFir) | 
					
						
							|  |  |  | 		pr_info("Lem:         %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be64_to_cpu(data->lemFir), | 
					
						
							|  |  |  | 			be64_to_cpu(data->lemErrorMask), | 
					
						
							|  |  |  | 			be64_to_cpu(data->lemWOF)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->phbErrorStatus) | 
					
						
							|  |  |  | 		pr_info("PhbErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be64_to_cpu(data->phbErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->phbFirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->phbErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->phbErrorLog1)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->mmioErrorStatus) | 
					
						
							|  |  |  | 		pr_info("OutErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be64_to_cpu(data->mmioErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->mmioFirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->mmioErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->mmioErrorLog1)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->dma0ErrorStatus) | 
					
						
							|  |  |  | 		pr_info("InAErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be64_to_cpu(data->dma0ErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma0FirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma0ErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma0ErrorLog1)); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 	if (data->dma1ErrorStatus) | 
					
						
							|  |  |  | 		pr_info("InBErr:      %016llx %016llx %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			be64_to_cpu(data->dma1ErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma1FirstErrorStatus), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma1ErrorLog0), | 
					
						
							|  |  |  | 			be64_to_cpu(data->dma1ErrorLog1)); | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < OPAL_PHB3_NUM_PEST_REGS; i++) { | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 		if ((be64_to_cpu(data->pestA[i]) >> 63) == 0 && | 
					
						
							|  |  |  | 		    (be64_to_cpu(data->pestB[i]) >> 63) == 0) | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:10 +10:00
										 |  |  | 		pr_info("PE[%3d] A/B: %016llx %016llx\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 				i, be64_to_cpu(data->pestA[i]), | 
					
						
							|  |  |  | 				be64_to_cpu(data->pestB[i])); | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void pnv_pci_dump_phb_diag_data(struct pci_controller *hose, | 
					
						
							|  |  |  | 				unsigned char *log_buff) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct OpalIoPhbErrorCommon *common; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!hose || !log_buff) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	common = (struct OpalIoPhbErrorCommon *)log_buff; | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 	switch (be32_to_cpu(common->ioType)) { | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 	case OPAL_PHB_ERROR_DATA_TYPE_P7IOC: | 
					
						
							|  |  |  | 		pnv_pci_dump_p7ioc_diag_data(hose, common); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case OPAL_PHB_ERROR_DATA_TYPE_PHB3: | 
					
						
							|  |  |  | 		pnv_pci_dump_phb3_diag_data(hose, common); | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2013-11-22 16:28:45 +08:00
										 |  |  | 		pr_warn("%s: Unrecognized ioType %d\n", | 
					
						
							| 
									
										
										
										
											2014-06-09 16:58:51 +08:00
										 |  |  | 			__func__, be32_to_cpu(common->ioType)); | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pnv_pci_handle_eeh_config(struct pnv_phb *phb, u32 pe_no) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags, rc; | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	int has_diag, ret = 0; | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&phb->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	/* Fetch PHB diag-data */ | 
					
						
							| 
									
										
										
										
											2013-06-20 13:21:05 +08:00
										 |  |  | 	rc = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag.blob, | 
					
						
							|  |  |  | 					 PNV_PCI_DIAG_BUF_SIZE); | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 	has_diag = (rc == OPAL_SUCCESS); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	/* If PHB supports compound PE, to handle it */ | 
					
						
							|  |  |  | 	if (phb->unfreeze_pe) { | 
					
						
							|  |  |  | 		ret = phb->unfreeze_pe(phb, | 
					
						
							|  |  |  | 				       pe_no, | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 				       OPAL_EEH_ACTION_CLEAR_FREEZE_ALL); | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		rc = opal_pci_eeh_freeze_clear(phb->opal_id, | 
					
						
							|  |  |  | 					     pe_no, | 
					
						
							|  |  |  | 					     OPAL_EEH_ACTION_CLEAR_FREEZE_ALL); | 
					
						
							|  |  |  | 		if (rc) { | 
					
						
							|  |  |  | 			pr_warn("%s: Failure %ld clearing frozen " | 
					
						
							|  |  |  | 				"PHB#%x-PE#%x\n", | 
					
						
							|  |  |  | 				__func__, rc, phb->hose->global_number, | 
					
						
							|  |  |  | 				pe_no); | 
					
						
							|  |  |  | 			ret = -EIO; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * For now, let's only display the diag buffer when we fail to clear | 
					
						
							|  |  |  | 	 * the EEH status. We'll do more sensible things later when we have | 
					
						
							|  |  |  | 	 * proper EEH support. We need to make sure we don't pollute ourselves | 
					
						
							|  |  |  | 	 * with the normal errors generated when probing empty slots | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (has_diag && ret) | 
					
						
							|  |  |  | 		pnv_pci_dump_phb_diag_data(phb->hose, phb->diag.blob); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 	spin_unlock_irqrestore(&phb->lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | static void pnv_pci_config_check_eeh(struct pnv_phb *phb, | 
					
						
							|  |  |  | 				     struct device_node *dn) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	u8	fstate; | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 	__be16	pcierr; | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	int	pe_no; | 
					
						
							|  |  |  | 	s64	rc; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Get the PE#. During the PCI probe stage, we might not | 
					
						
							|  |  |  | 	 * setup that yet. So all ER errors should be mapped to | 
					
						
							| 
									
										
										
										
											2013-11-04 16:32:47 +08:00
										 |  |  | 	 * reserved PE. | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	pe_no = PCI_DN(dn)->pe_number; | 
					
						
							| 
									
										
										
										
											2013-11-04 16:32:47 +08:00
										 |  |  | 	if (pe_no == IODA_INVALID_PE) { | 
					
						
							|  |  |  | 		if (phb->type == PNV_PHB_P5IOC2) | 
					
						
							|  |  |  | 			pe_no = 0; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			pe_no = phb->ioda.reserved_pe; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Fetch frozen state. If the PHB support compound PE, | 
					
						
							|  |  |  | 	 * we need handle that case. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (phb->get_pe_state) { | 
					
						
							|  |  |  | 		fstate = phb->get_pe_state(phb, pe_no); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		rc = opal_pci_eeh_freeze_status(phb->opal_id, | 
					
						
							|  |  |  | 						pe_no, | 
					
						
							|  |  |  | 						&fstate, | 
					
						
							|  |  |  | 						&pcierr, | 
					
						
							|  |  |  | 						NULL); | 
					
						
							|  |  |  | 		if (rc) { | 
					
						
							|  |  |  | 			pr_warn("%s: Failure %lld getting PHB#%x-PE#%x state\n", | 
					
						
							|  |  |  | 				__func__, rc, phb->hose->global_number, pe_no); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	cfg_dbg(" -> EEH check, bdfn=%04x PE#%d fstate=%x\n", | 
					
						
							|  |  |  | 		(PCI_DN(dn)->busno << 8) | (PCI_DN(dn)->devfn), | 
					
						
							|  |  |  | 		pe_no, fstate); | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Clear the frozen state if applicable */ | 
					
						
							|  |  |  | 	if (fstate == OPAL_EEH_STOPPED_MMIO_FREEZE || | 
					
						
							|  |  |  | 	    fstate == OPAL_EEH_STOPPED_DMA_FREEZE  || | 
					
						
							|  |  |  | 	    fstate == OPAL_EEH_STOPPED_MMIO_DMA_FREEZE) { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * If PHB supports compound PE, freeze it for | 
					
						
							|  |  |  | 		 * consistency. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (phb->freeze_pe) | 
					
						
							|  |  |  | 			phb->freeze_pe(phb, pe_no); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 18:22:53 +00:00
										 |  |  | 		pnv_pci_handle_eeh_config(phb, pe_no); | 
					
						
							| 
									
										
										
										
											2014-07-21 14:42:35 +10:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | int pnv_pci_cfg_read(struct device_node *dn, | 
					
						
							|  |  |  | 		     int where, int size, u32 *val) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	struct pci_dn *pdn = PCI_DN(dn); | 
					
						
							|  |  |  | 	struct pnv_phb *phb = pdn->phb->private_data; | 
					
						
							|  |  |  | 	u32 bdfn = (pdn->busno << 8) | pdn->devfn; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	s64 rc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (size) { | 
					
						
							|  |  |  | 	case 1: { | 
					
						
							|  |  |  | 		u8 v8; | 
					
						
							|  |  |  | 		rc = opal_pci_config_read_byte(phb->opal_id, bdfn, where, &v8); | 
					
						
							|  |  |  | 		*val = (rc == OPAL_SUCCESS) ? v8 : 0xff; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	case 2: { | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 		__be16 v16; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 		rc = opal_pci_config_read_half_word(phb->opal_id, bdfn, where, | 
					
						
							|  |  |  | 						   &v16); | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 		*val = (rc == OPAL_SUCCESS) ? be16_to_cpu(v16) : 0xffff; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	case 4: { | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 		__be32 v32; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 		rc = opal_pci_config_read_word(phb->opal_id, bdfn, where, &v32); | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 		*val = (rc == OPAL_SUCCESS) ? be32_to_cpu(v32) : 0xffffffff; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return PCIBIOS_FUNC_NOT_SUPPORTED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n", | 
					
						
							|  |  |  | 		__func__, pdn->busno, pdn->devfn, where, size, *val); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	return PCIBIOS_SUCCESSFUL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | int pnv_pci_cfg_write(struct device_node *dn, | 
					
						
							|  |  |  | 		      int where, int size, u32 val) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	struct pci_dn *pdn = PCI_DN(dn); | 
					
						
							|  |  |  | 	struct pnv_phb *phb = pdn->phb->private_data; | 
					
						
							|  |  |  | 	u32 bdfn = (pdn->busno << 8) | pdn->devfn; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n", | 
					
						
							|  |  |  | 		pdn->busno, pdn->devfn, where, size, val); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	switch (size) { | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		opal_pci_config_write_byte(phb->opal_id, bdfn, where, val); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 2: | 
					
						
							|  |  |  | 		opal_pci_config_write_half_word(phb->opal_id, bdfn, where, val); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 4: | 
					
						
							|  |  |  | 		opal_pci_config_write_word(phb->opal_id, bdfn, where, val); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return PCIBIOS_FUNC_NOT_SUPPORTED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-20 13:21:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	return PCIBIOS_SUCCESSFUL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if CONFIG_EEH
 | 
					
						
							|  |  |  | static bool pnv_pci_cfg_check(struct pci_controller *hose, | 
					
						
							|  |  |  | 			      struct device_node *dn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct eeh_dev *edev = NULL; | 
					
						
							|  |  |  | 	struct pnv_phb *phb = hose->private_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* EEH not enabled ? */ | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:09 +10:00
										 |  |  | 	if (!(phb->flags & PNV_PHB_FLAG_EEH)) | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
                +-----------------+
                | PE#3     p2p#0  |
                |          p2p#1  |
                +-----------------+
                        |
                +-----------------+
                | PE#4     pdev#0 |
                |          pdev#1 |
                +-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
											
										 
											2014-04-24 18:00:19 +10:00
										 |  |  | 	/* PE reset or device removed ? */ | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	edev = of_node_to_eeh_dev(dn); | 
					
						
							| 
									
										
											  
											
												powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
                +-----------------+
                | PE#3     p2p#0  |
                |          p2p#1  |
                +-----------------+
                        |
                +-----------------+
                | PE#4     pdev#0 |
                |          pdev#1 |
                +-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
											
										 
											2014-04-24 18:00:19 +10:00
										 |  |  | 	if (edev) { | 
					
						
							|  |  |  | 		if (edev->pe && | 
					
						
							|  |  |  | 		    (edev->pe->state & EEH_PE_RESET)) | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (edev->mode & EEH_DEV_REMOVED) | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | static inline pnv_pci_cfg_check(struct pci_controller *hose, | 
					
						
							|  |  |  | 				struct device_node *dn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | #endif /* CONFIG_EEH */
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | static int pnv_pci_read_config(struct pci_bus *bus, | 
					
						
							|  |  |  | 			       unsigned int devfn, | 
					
						
							|  |  |  | 			       int where, int size, u32 *val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device_node *dn, *busdn = pci_bus_to_OF_node(bus); | 
					
						
							|  |  |  | 	struct pci_dn *pdn; | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	struct pnv_phb *phb; | 
					
						
							|  |  |  | 	bool found = false; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	*val = 0xFFFFFFFF; | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	for (dn = busdn->child; dn; dn = dn->sibling) { | 
					
						
							|  |  |  | 		pdn = PCI_DN(dn); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 		if (pdn && pdn->devfn == devfn) { | 
					
						
							|  |  |  | 			phb = pdn->phb->private_data; | 
					
						
							|  |  |  | 			found = true; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	if (!found || !pnv_pci_cfg_check(pdn->phb, dn)) | 
					
						
							|  |  |  | 		return PCIBIOS_DEVICE_NOT_FOUND; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = pnv_pci_cfg_read(dn, where, size, val); | 
					
						
							|  |  |  | 	if (phb->flags & PNV_PHB_FLAG_EEH) { | 
					
						
							|  |  |  | 		if (*val == EEH_IO_ERROR_VALUE(size) && | 
					
						
							|  |  |  | 		    eeh_dev_check_failure(of_node_to_eeh_dev(dn))) | 
					
						
							|  |  |  |                         return PCIBIOS_DEVICE_NOT_FOUND; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		pnv_pci_config_check_eeh(phb, dn); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pnv_pci_write_config(struct pci_bus *bus, | 
					
						
							|  |  |  | 				unsigned int devfn, | 
					
						
							|  |  |  | 				int where, int size, u32 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device_node *dn, *busdn = pci_bus_to_OF_node(bus); | 
					
						
							|  |  |  | 	struct pci_dn *pdn; | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	struct pnv_phb *phb; | 
					
						
							|  |  |  | 	bool found = false; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (dn = busdn->child; dn; dn = dn->sibling) { | 
					
						
							|  |  |  | 		pdn = PCI_DN(dn); | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 		if (pdn && pdn->devfn == devfn) { | 
					
						
							|  |  |  | 			phb = pdn->phb->private_data; | 
					
						
							|  |  |  | 			found = true; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-24 18:00:12 +10:00
										 |  |  | 	if (!found || !pnv_pci_cfg_check(pdn->phb, dn)) | 
					
						
							|  |  |  | 		return PCIBIOS_DEVICE_NOT_FOUND; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = pnv_pci_cfg_write(dn, where, size, val); | 
					
						
							|  |  |  | 	if (!(phb->flags & PNV_PHB_FLAG_EEH)) | 
					
						
							|  |  |  | 		pnv_pci_config_check_eeh(phb, dn); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | struct pci_ops pnv_pci_ops = { | 
					
						
							| 
									
										
										
										
											2013-06-27 13:46:48 +08:00
										 |  |  | 	.read  = pnv_pci_read_config, | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	.write = pnv_pci_write_config, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int pnv_tce_build(struct iommu_table *tbl, long index, long npages, | 
					
						
							|  |  |  | 			 unsigned long uaddr, enum dma_data_direction direction, | 
					
						
							| 
									
										
										
										
											2013-08-28 18:37:43 +10:00
										 |  |  | 			 struct dma_attrs *attrs, bool rm) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	u64 proto_tce; | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 	__be64 *tcep, *tces; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	u64 rpn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	proto_tce = TCE_PCI_READ; // Read allowed
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (direction != DMA_TO_DEVICE) | 
					
						
							|  |  |  | 		proto_tce |= TCE_PCI_WRITE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:06 +10:00
										 |  |  | 	tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset; | 
					
						
							| 
									
										
										
										
											2014-06-06 18:44:02 +10:00
										 |  |  | 	rpn = __pa(uaddr) >> tbl->it_page_shift; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 18:55:59 +00:00
										 |  |  | 	while (npages--) | 
					
						
							| 
									
										
										
										
											2014-06-06 18:44:02 +10:00
										 |  |  | 		*(tcep++) = cpu_to_be64(proto_tce | | 
					
						
							|  |  |  | 				(rpn++ << tbl->it_page_shift)); | 
					
						
							| 
									
										
										
										
											2011-11-06 18:55:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Some implementations won't cache invalid TCEs and thus may not
 | 
					
						
							|  |  |  | 	 * need that flush. We'll probably turn it_type into a bit mask | 
					
						
							|  |  |  | 	 * of flags if that becomes the case | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (tbl->it_type & TCE_PCI_SWINV_CREATE) | 
					
						
							| 
									
										
										
										
											2013-08-28 18:37:43 +10:00
										 |  |  | 		pnv_pci_ioda_tce_invalidate(tbl, tces, tcep - 1, rm); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 18:37:43 +10:00
										 |  |  | static int pnv_tce_build_vm(struct iommu_table *tbl, long index, long npages, | 
					
						
							|  |  |  | 			    unsigned long uaddr, | 
					
						
							|  |  |  | 			    enum dma_data_direction direction, | 
					
						
							|  |  |  | 			    struct dma_attrs *attrs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return pnv_tce_build(tbl, index, npages, uaddr, direction, attrs, | 
					
						
							|  |  |  | 			false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pnv_tce_free(struct iommu_table *tbl, long index, long npages, | 
					
						
							|  |  |  | 		bool rm) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 	__be64 *tcep, *tces; | 
					
						
							| 
									
										
										
										
											2011-11-06 18:55:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:06 +10:00
										 |  |  | 	tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (npages--) | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 		*(tcep++) = cpu_to_be64(0); | 
					
						
							| 
									
										
										
										
											2011-11-06 18:55:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-20 17:25:15 +00:00
										 |  |  | 	if (tbl->it_type & TCE_PCI_SWINV_FREE) | 
					
						
							| 
									
										
										
										
											2013-08-28 18:37:43 +10:00
										 |  |  | 		pnv_pci_ioda_tce_invalidate(tbl, tces, tcep - 1, rm); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pnv_tce_free_vm(struct iommu_table *tbl, long index, long npages) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pnv_tce_free(tbl, index, npages, false); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-04 15:19:35 +00:00
										 |  |  | static unsigned long pnv_tce_get(struct iommu_table *tbl, long index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ((u64 *)tbl->it_base)[index - tbl->it_offset]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 18:37:43 +10:00
										 |  |  | static int pnv_tce_build_rm(struct iommu_table *tbl, long index, long npages, | 
					
						
							|  |  |  | 			    unsigned long uaddr, | 
					
						
							|  |  |  | 			    enum dma_data_direction direction, | 
					
						
							|  |  |  | 			    struct dma_attrs *attrs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return pnv_tce_build(tbl, index, npages, uaddr, direction, attrs, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pnv_tce_free_rm(struct iommu_table *tbl, long index, long npages) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	pnv_tce_free(tbl, index, npages, true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | void pnv_pci_setup_iommu_table(struct iommu_table *tbl, | 
					
						
							|  |  |  | 			       void *tce_mem, u64 tce_size, | 
					
						
							| 
									
										
										
										
											2014-06-06 18:44:03 +10:00
										 |  |  | 			       u64 dma_offset, unsigned page_shift) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	tbl->it_blocksize = 16; | 
					
						
							|  |  |  | 	tbl->it_base = (unsigned long)tce_mem; | 
					
						
							| 
									
										
										
										
											2014-06-06 18:44:03 +10:00
										 |  |  | 	tbl->it_page_shift = page_shift; | 
					
						
							| 
									
										
										
										
											2013-12-09 18:17:02 +11:00
										 |  |  | 	tbl->it_offset = dma_offset >> tbl->it_page_shift; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	tbl->it_index = 0; | 
					
						
							|  |  |  | 	tbl->it_size = tce_size >> 3; | 
					
						
							|  |  |  | 	tbl->it_busno = 0; | 
					
						
							|  |  |  | 	tbl->it_type = TCE_PCI; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static struct iommu_table *pnv_pci_setup_bml_iommu(struct pci_controller *hose) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct iommu_table *tbl; | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 	const __be64 *basep, *swinvp; | 
					
						
							|  |  |  | 	const __be32 *sizep; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	basep = of_get_property(hose->dn, "linux,tce-base", NULL); | 
					
						
							|  |  |  | 	sizep = of_get_property(hose->dn, "linux,tce-size", NULL); | 
					
						
							|  |  |  | 	if (basep == NULL || sizep == NULL) { | 
					
						
							| 
									
										
										
										
											2011-11-06 18:55:59 +00:00
										 |  |  | 		pr_err("PCI: %s has missing tce entries !\n", | 
					
						
							|  |  |  | 		       hose->dn->full_name); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, hose->node); | 
					
						
							|  |  |  | 	if (WARN_ON(!tbl)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	pnv_pci_setup_iommu_table(tbl, __va(be64_to_cpup(basep)), | 
					
						
							| 
									
										
										
										
											2014-06-06 18:44:03 +10:00
										 |  |  | 				  be32_to_cpup(sizep), 0, IOMMU_PAGE_SHIFT_4K); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	iommu_init_table(tbl, hose->node); | 
					
						
							| 
									
										
										
										
											2013-05-21 13:33:09 +10:00
										 |  |  | 	iommu_register_group(tbl, pci_domain_nr(hose->bus), 0); | 
					
						
							| 
									
										
										
										
											2011-11-06 18:55:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Deal with SW invalidated TCEs when needed (BML way) */ | 
					
						
							|  |  |  | 	swinvp = of_get_property(hose->dn, "linux,tce-sw-invalidate-info", | 
					
						
							|  |  |  | 				 NULL); | 
					
						
							|  |  |  | 	if (swinvp) { | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:06 +10:00
										 |  |  | 		tbl->it_busno = be64_to_cpu(swinvp[1]); | 
					
						
							| 
									
										
										
										
											2013-09-23 12:05:01 +10:00
										 |  |  | 		tbl->it_index = (unsigned long)ioremap(be64_to_cpup(swinvp), 8); | 
					
						
							| 
									
										
										
										
											2011-11-06 18:55:59 +00:00
										 |  |  | 		tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	return tbl; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static void pnv_pci_dma_fallback_setup(struct pci_controller *hose, | 
					
						
							|  |  |  | 				       struct pci_dev *pdev) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct device_node *np = pci_bus_to_OF_node(hose->bus); | 
					
						
							|  |  |  | 	struct pci_dn *pdn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (np == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	pdn = PCI_DN(np); | 
					
						
							|  |  |  | 	if (!pdn->iommu_table) | 
					
						
							|  |  |  | 		pdn->iommu_table = pnv_pci_setup_bml_iommu(hose); | 
					
						
							|  |  |  | 	if (!pdn->iommu_table) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2013-11-21 17:43:14 +11:00
										 |  |  | 	set_iommu_table_base_and_group(&pdev->dev, pdn->iommu_table); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static void pnv_pci_dma_dev_setup(struct pci_dev *pdev) | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct pci_controller *hose = pci_bus_to_host(pdev->bus); | 
					
						
							|  |  |  | 	struct pnv_phb *phb = hose->private_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* If we have no phb structure, try to setup a fallback based on
 | 
					
						
							|  |  |  | 	 * the device-tree (RTAS PCI for example) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (phb && phb->dma_dev_setup) | 
					
						
							|  |  |  | 		phb->dma_dev_setup(phb, pdev); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		pnv_pci_dma_fallback_setup(hose, pdev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-11 11:32:38 +11:00
										 |  |  | int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct pci_controller *hose = pci_bus_to_host(pdev->bus); | 
					
						
							|  |  |  | 	struct pnv_phb *phb = hose->private_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (phb && phb->dma_set_mask) | 
					
						
							|  |  |  | 		return phb->dma_set_mask(phb, pdev, dma_mask); | 
					
						
							|  |  |  | 	return __dma_set_mask(&pdev->dev, dma_mask); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-30 12:39:10 +10:00
										 |  |  | u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct pci_controller *hose = pci_bus_to_host(pdev->bus); | 
					
						
							|  |  |  | 	struct pnv_phb *phb = hose->private_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (phb && phb->dma_get_required_mask) | 
					
						
							|  |  |  | 		return phb->dma_get_required_mask(phb, pdev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return __dma_get_required_mask(&pdev->dev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 16:59:18 +10:00
										 |  |  | void pnv_pci_shutdown(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct pci_controller *hose; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_for_each_entry(hose, &hose_list, list_node) { | 
					
						
							|  |  |  | 		struct pnv_phb *phb = hose->private_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (phb && phb->shutdown) | 
					
						
							|  |  |  | 			phb->shutdown(phb); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 19:20:57 +00:00
										 |  |  | /* Fixup wrong class code in p7ioc and p8 root complex */ | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static void pnv_p7ioc_rc_quirk(struct pci_dev *dev) | 
					
						
							| 
									
										
										
										
											2011-11-06 18:56:00 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	dev->class = PCI_CLASS_BRIDGE_PCI << 8; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM, 0x3b9, pnv_p7ioc_rc_quirk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:07 +00:00
										 |  |  | static int pnv_pci_probe_mode(struct pci_bus *bus) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct pci_controller *hose = pci_bus_to_host(bus); | 
					
						
							|  |  |  | 	const __be64 *tstamp; | 
					
						
							|  |  |  | 	u64 now, target; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* We hijack this as a way to ensure we have waited long
 | 
					
						
							|  |  |  | 	 * enough since the reset was lifted on the PCI bus | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (bus != hose->bus) | 
					
						
							|  |  |  | 		return PCI_PROBE_NORMAL; | 
					
						
							|  |  |  | 	tstamp = of_get_property(hose->dn, "reset-clear-timestamp", NULL); | 
					
						
							|  |  |  | 	if (!tstamp || !*tstamp) | 
					
						
							|  |  |  | 		return PCI_PROBE_NORMAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	now = mftb() / tb_ticks_per_usec; | 
					
						
							|  |  |  | 	target = (be64_to_cpup(tstamp) / tb_ticks_per_usec) | 
					
						
							|  |  |  | 		+ PCI_RESET_DELAY_US; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pr_devel("pci %04d: Reset target: 0x%llx now: 0x%llx\n", | 
					
						
							|  |  |  | 		 hose->global_number, target, now); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (now < target) | 
					
						
							|  |  |  | 		msleep((target - now + 999) / 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return PCI_PROBE_NORMAL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | void __init pnv_pci_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device_node *np; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 20:18:58 -07:00
										 |  |  | 	pci_add_flags(PCI_CAN_SKIP_ISA_ALIGN); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* OPAL absent, try POPAL first then RTAS detection of PHBs */ | 
					
						
							|  |  |  | 	if (!firmware_has_feature(FW_FEATURE_OPAL)) { | 
					
						
							|  |  |  | #ifdef CONFIG_PPC_POWERNV_RTAS
 | 
					
						
							|  |  |  | 		init_pci_config_tokens(); | 
					
						
							|  |  |  | 		find_and_init_phbs(); | 
					
						
							|  |  |  | #endif /* CONFIG_PPC_POWERNV_RTAS */
 | 
					
						
							| 
									
										
										
										
											2011-11-15 17:29:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	/* OPAL is here, do our normal stuff */ | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		int found_ioda = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Look for IODA IO-Hubs. We don't support mixing IODA
 | 
					
						
							|  |  |  | 		 * and p5ioc2 due to the need to change some global | 
					
						
							|  |  |  | 		 * probing flags | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		for_each_compatible_node(np, NULL, "ibm,ioda-hub") { | 
					
						
							|  |  |  | 			pnv_pci_init_ioda_hub(np); | 
					
						
							|  |  |  | 			found_ioda = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Look for p5ioc2 IO-Hubs */ | 
					
						
							| 
									
										
										
										
											2011-11-15 17:29:08 +00:00
										 |  |  | 		if (!found_ioda) | 
					
						
							|  |  |  | 			for_each_compatible_node(np, NULL, "ibm,p5ioc2") | 
					
						
							|  |  |  | 				pnv_pci_init_p5ioc2_hub(np); | 
					
						
							| 
									
										
										
										
											2013-04-25 19:20:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Look for ioda2 built-in PHB3's */ | 
					
						
							|  |  |  | 		for_each_compatible_node(np, NULL, "ibm,ioda2-phb") | 
					
						
							|  |  |  | 			pnv_pci_init_ioda2_phb(np); | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Setup the linkage between OF nodes and PHBs */ | 
					
						
							|  |  |  | 	pci_devs_phb_init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Configure IOMMU DMA hooks */ | 
					
						
							|  |  |  | 	ppc_md.pci_dma_dev_setup = pnv_pci_dma_dev_setup; | 
					
						
							| 
									
										
										
										
											2013-08-28 18:37:43 +10:00
										 |  |  | 	ppc_md.tce_build = pnv_tce_build_vm; | 
					
						
							|  |  |  | 	ppc_md.tce_free = pnv_tce_free_vm; | 
					
						
							|  |  |  | 	ppc_md.tce_build_rm = pnv_tce_build_rm; | 
					
						
							|  |  |  | 	ppc_md.tce_free_rm = pnv_tce_free_rm; | 
					
						
							| 
									
										
										
										
											2012-09-04 15:19:35 +00:00
										 |  |  | 	ppc_md.tce_get = pnv_tce_get; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:07 +00:00
										 |  |  | 	ppc_md.pci_probe_mode = pnv_pci_probe_mode; | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | 	set_pci_dma_ops(&dma_iommu_ops); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:06 +00:00
										 |  |  | 	/* Configure MSIs */ | 
					
						
							|  |  |  | #ifdef CONFIG_PCI_MSI
 | 
					
						
							|  |  |  | 	ppc_md.setup_msi_irqs = pnv_setup_msi_irqs; | 
					
						
							|  |  |  | 	ppc_md.teardown_msi_irqs = pnv_teardown_msi_irqs; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-09-19 17:45:05 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-21 17:43:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int tce_iommu_bus_notifier(struct notifier_block *nb, | 
					
						
							|  |  |  | 		unsigned long action, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (action) { | 
					
						
							|  |  |  | 	case BUS_NOTIFY_ADD_DEVICE: | 
					
						
							|  |  |  | 		return iommu_add_device(dev); | 
					
						
							|  |  |  | 	case BUS_NOTIFY_DEL_DEVICE: | 
					
						
							|  |  |  | 		if (dev->iommu_group) | 
					
						
							|  |  |  | 			iommu_del_device(dev); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct notifier_block tce_iommu_bus_nb = { | 
					
						
							|  |  |  | 	.notifier_call = tce_iommu_bus_notifier, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int __init tce_iommu_bus_notifier_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bus_register_notifier(&pci_bus_type, &tce_iommu_bus_nb); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-15 22:22:24 +10:00
										 |  |  | machine_subsys_initcall_sync(powernv, tce_iommu_bus_notifier_init); |