jsm: adding EEH handlers
[safe/jmp/linux-2.6] / drivers / serial / jsm / jsm_driver.c
index ac79cbe..108c3e0 100644 (file)
@@ -48,16 +48,26 @@ struct uart_driver jsm_uart_driver = {
        .nr             = NR_PORTS,
 };
 
+static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
+                                       pci_channel_state_t state);
+static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev);
+static void jsm_io_resume(struct pci_dev *pdev);
+
+static struct pci_error_handlers jsm_err_handler = {
+       .error_detected = jsm_io_error_detected,
+       .slot_reset = jsm_io_slot_reset,
+       .resume = jsm_io_resume,
+};
+
 int jsm_debug;
 module_param(jsm_debug, int, 0);
 MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
 
-static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int __devinit jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
        int rc = 0;
        struct jsm_board *brd;
        static int adapter_count = 0;
-       int retval;
 
        rc = pci_enable_device(pdev);
        if (rc) {
@@ -89,7 +99,6 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        else
                brd->maxports = 2;
 
-       spin_lock_init(&brd->bd_lock);
        spin_lock_init(&brd->bd_intr_lock);
 
        /* store which revision we have */
@@ -125,7 +134,7 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
 
        rc = request_irq(brd->irq, brd->bd_ops->intr,
-                       IRQF_DISABLED|IRQF_SHARED, "JSM", brd);
+                       IRQF_SHARED, "JSM", brd);
        if (rc) {
                printk(KERN_WARNING "Failed to hook IRQ %d\n",brd->irq);
                goto out_iounmap;
@@ -134,7 +143,7 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        rc = jsm_tty_init(brd);
        if (rc < 0) {
                dev_err(&pdev->dev, "Can't init tty devices (%d)\n", rc);
-               retval = -ENXIO;
+               rc = -ENXIO;
                goto out_free_irq;
        }
 
@@ -142,7 +151,7 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (rc < 0) {
                /* XXX: leaking all resources from jsm_tty_init here! */
                dev_err(&pdev->dev, "Can't init uart port (%d)\n", rc);
-               retval = -ENXIO;
+               rc = -ENXIO;
                goto out_free_irq;
        }
 
@@ -161,11 +170,12 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                /* XXX: leaking all resources from jsm_tty_init and
                        jsm_uart_port_init here! */
                dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
-               retval = -ENOMEM;
+               rc = -ENOMEM;
                goto out_free_irq;
        }
 
        pci_set_drvdata(pdev, brd);
+       pci_save_state(pdev);
 
        return 0;
  out_free_irq:
@@ -224,8 +234,42 @@ static struct pci_driver jsm_driver = {
        .id_table       = jsm_pci_tbl,
        .probe          = jsm_probe_one,
        .remove         = __devexit_p(jsm_remove_one),
+       .err_handler    = &jsm_err_handler,
 };
 
+static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
+                                       pci_channel_state_t state)
+{
+       struct jsm_board *brd = pci_get_drvdata(pdev);
+
+       jsm_remove_uart_port(brd);
+
+       return PCI_ERS_RESULT_NEED_RESET;
+}
+
+static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev)
+{
+       int rc;
+
+       rc = pci_enable_device(pdev);
+
+       if (rc)
+               return PCI_ERS_RESULT_DISCONNECT;
+
+       pci_set_master(pdev);
+
+       return PCI_ERS_RESULT_RECOVERED;
+}
+
+static void jsm_io_resume(struct pci_dev *pdev)
+{
+       struct jsm_board *brd = pci_get_drvdata(pdev);
+
+       pci_restore_state(pdev);
+
+       jsm_uart_port_init(brd);
+}
+
 static int __init jsm_init_module(void)
 {
        int rc;