Merge branch 'topic/core-cleanup' into for-linus
[safe/jmp/linux-2.6] / drivers / pci / pcie / aer / aerdrv.c
index e11c031..7a711ee 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/pm.h>
@@ -24,6 +25,7 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/pcieport_if.h>
+#include <linux/slab.h>
 
 #include "aerdrv.h"
 #include "../../pci.h"
@@ -38,11 +40,8 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
 
-static int __devinit aer_probe (struct pcie_device *dev);
+static int __devinit aer_probe(struct pcie_device *dev);
 static void aer_remove(struct pcie_device *dev);
-static int aer_suspend(struct pcie_device *dev, pm_message_t state)
-{return 0;}
-static int aer_resume(struct pcie_device *dev) {return 0;}
 static pci_ers_result_t aer_error_detected(struct pci_dev *dev,
        enum pci_channel_state error);
 static void aer_error_resume(struct pci_dev *dev);
@@ -50,20 +49,17 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev);
 
 static struct pci_error_handlers aer_error_handlers = {
        .error_detected = aer_error_detected,
-       .resume = aer_error_resume,
+       .resume         = aer_error_resume,
 };
 
 static struct pcie_port_service_driver aerdriver = {
        .name           = "aer",
-       .port_type      = PCIE_ANY_PORT,
+       .port_type      = PCI_EXP_TYPE_ROOT_PORT,
        .service        = PCIE_PORT_SERVICE_AER,
 
        .probe          = aer_probe,
        .remove         = aer_remove,
 
-       .suspend        = aer_suspend,
-       .resume         = aer_resume,
-
        .err_handler    = &aer_error_handlers,
 
        .reset_link     = aer_root_reset,
@@ -83,7 +79,7 @@ void pci_no_aer(void)
  *
  * Invoked when Root Port detects AER messages.
  **/
-static irqreturn_t aer_irq(int irq, void *context)
+irqreturn_t aer_irq(int irq, void *context)
 {
        unsigned int status, id;
        struct pcie_device *pdev = (struct pcie_device *)context;
@@ -132,6 +128,7 @@ static irqreturn_t aer_irq(int irq, void *context)
 
        return IRQ_HANDLED;
 }
+EXPORT_SYMBOL_GPL(aer_irq);
 
 /**
  * aer_alloc_rpc - allocate Root Port data structure
@@ -139,12 +136,12 @@ static irqreturn_t aer_irq(int irq, void *context)
  *
  * Invoked when Root Port's AER service is loaded.
  **/
-static struct aer_rpcaer_alloc_rpc(struct pcie_device *dev)
+static struct aer_rpc *aer_alloc_rpc(struct pcie_device *dev)
 {
        struct aer_rpc *rpc;
 
-       if (!(rpc = kzalloc(sizeof(struct aer_rpc),
-               GFP_KERNEL)))
+       rpc = kzalloc(sizeof(struct aer_rpc), GFP_KERNEL);
+       if (!rpc)
                return NULL;
 
        /*
@@ -159,7 +156,7 @@ static struct aer_rpc* aer_alloc_rpc(struct pcie_device *dev)
        mutex_init(&rpc->rpc_mutex);
        init_waitqueue_head(&rpc->wait_release);
 
-       /* Use PCIE bus function to store rpc into PCIE device */
+       /* Use PCIe bus function to store rpc into PCIe device */
        set_service_data(dev, rpc);
 
        return rpc;
@@ -194,26 +191,28 @@ static void aer_remove(struct pcie_device *dev)
  *
  * Invoked when PCI Express bus loads AER service driver.
  **/
-static int __devinit aer_probe (struct pcie_device *dev)
+static int __devinit aer_probe(struct pcie_device *dev)
 {
        int status;
        struct aer_rpc *rpc;
        struct device *device = &dev->device;
 
        /* Init */
-       if ((status = aer_init(dev)))
+       status = aer_init(dev);
+       if (status)
                return status;
 
        /* Alloc rpc data structure */
-       if (!(rpc = aer_alloc_rpc(dev))) {
+       rpc = aer_alloc_rpc(dev);
+       if (!rpc) {
                dev_printk(KERN_DEBUG, device, "alloc rpc failed\n");
                aer_remove(dev);
                return -ENOMEM;
        }
 
        /* Request IRQ ISR */
-       if ((status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv",
-                               dev))) {
+       status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", dev);
+       if (status) {
                dev_printk(KERN_DEBUG, device, "request IRQ failed\n");
                aer_remove(dev);
                return status;
@@ -245,11 +244,17 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
 
        /* Assert Secondary Bus Reset */
        pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &p2p_ctrl);
-       p2p_ctrl |= PCI_CB_BRIDGE_CTL_CB_RESET;
+       p2p_ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
        pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
 
+       /*
+        * we should send hot reset message for 2ms to allow it time to
+        * propogate to all downstream ports
+        */
+       msleep(2);
+
        /* De-assert Secondary Bus Reset */
-       p2p_ctrl &= ~PCI_CB_BRIDGE_CTL_CB_RESET;
+       p2p_ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
        pci_write_config_word(dev, PCI_BRIDGE_CONTROL, p2p_ctrl);
 
        /*
@@ -297,7 +302,7 @@ static void aer_error_resume(struct pci_dev *dev)
        u16 reg16;
 
        /* Clean up Root device status */
-       pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
+       pos = pci_pcie_cap(dev);
        pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &reg16);
        pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, reg16);
 
@@ -321,6 +326,8 @@ static int __init aer_service_init(void)
 {
        if (pcie_aer_disable)
                return -ENXIO;
+       if (!pci_msi_enabled())
+               return -ENXIO;
        return pcie_port_service_register(&aerdriver);
 }