#include <linux/sched.h>               /* signal_pending() */
 #include <linux/pcieport_if.h>
 #include <linux/mutex.h>
+#include <linux/workqueue.h>
 
 #define MY_NAME        "pciehp"
 
 extern int pciehp_debug;
 extern int pciehp_force;
 extern struct workqueue_struct *pciehp_wq;
+extern struct workqueue_struct *pciehp_ordered_wq;
 
 #define dbg(format, arg...)                                            \
 do {                                                                   \
 
 int pciehp_poll_time;
 int pciehp_force;
 struct workqueue_struct *pciehp_wq;
+struct workqueue_struct *pciehp_ordered_wq;
 
 #define DRIVER_VERSION "0.4"
 #define DRIVER_AUTHOR  "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
 {
        int retval = 0;
 
+       pciehp_wq = alloc_workqueue("pciehp", 0, 0);
+       if (!pciehp_wq)
+               return -ENOMEM;
+
+       pciehp_ordered_wq = alloc_ordered_workqueue("pciehp_ordered", 0);
+       if (!pciehp_ordered_wq) {
+               destroy_workqueue(pciehp_wq);
+               return -ENOMEM;
+       }
+
        pciehp_firmware_init();
        retval = pcie_port_service_register(&hpdriver_portdrv);
        dbg("pcie_port_service_register = %d\n", retval);
        info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
-       if (retval)
+       if (retval) {
+               destroy_workqueue(pciehp_ordered_wq);
+               destroy_workqueue(pciehp_wq);
                dbg("Failure to register service\n");
+       }
        return retval;
 }
 
 static void __exit pcied_cleanup(void)
 {
        dbg("unload_pciehpd()\n");
+       destroy_workqueue(pciehp_ordered_wq);
+       destroy_workqueue(pciehp_wq);
        pcie_port_service_unregister(&hpdriver_portdrv);
        info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
 }
 
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/pci.h>
-#include <linux/workqueue.h>
 #include "../pci.h"
 #include "pciehp.h"
 
        info->p_slot = p_slot;
        INIT_WORK(&info->work, interrupt_event_handler);
 
-       schedule_work(&info->work);
+       queue_work(pciehp_wq, &info->work);
 
        return 0;
 }
                kfree(info);
                goto out;
        }
-       queue_work(pciehp_wq, &info->work);
+       queue_work(pciehp_ordered_wq, &info->work);
  out:
        mutex_unlock(&p_slot->lock);
 }
                if (ATTN_LED(ctrl))
                        pciehp_set_attention_status(p_slot, 0);
 
-               schedule_delayed_work(&p_slot->work, 5*HZ);
+               queue_delayed_work(pciehp_wq, &p_slot->work, 5*HZ);
                break;
        case BLINKINGOFF_STATE:
        case BLINKINGON_STATE:
        else
                p_slot->state = POWERON_STATE;
 
-       queue_work(pciehp_wq, &info->work);
+       queue_work(pciehp_ordered_wq, &info->work);
 }
 
 static void interrupt_event_handler(struct work_struct *work)
 
 #include "../pci.h"
 #include "pciehp.h"
 
-static atomic_t pciehp_num_controllers = ATOMIC_INIT(0);
-
 static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value)
 {
        struct pci_dev *dev = ctrl->pcie->port;
 {
        struct slot *slot = ctrl->slot;
        cancel_delayed_work(&slot->work);
-       flush_scheduled_work();
        flush_workqueue(pciehp_wq);
+       flush_workqueue(pciehp_ordered_wq);
        kfree(slot);
 }
 
        /* Disable sotfware notification */
        pcie_disable_notification(ctrl);
 
-       /*
-        * If this is the first controller to be initialized,
-        * initialize the pciehp work queue
-        */
-       if (atomic_add_return(1, &pciehp_num_controllers) == 1) {
-               pciehp_wq = create_singlethread_workqueue("pciehpd");
-               if (!pciehp_wq)
-                       goto abort_ctrl;
-       }
-
        ctrl_info(ctrl, "HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
                  pdev->vendor, pdev->device, pdev->subsystem_vendor,
                  pdev->subsystem_device);
 {
        pcie_shutdown_notification(ctrl);
        pcie_cleanup_slot(ctrl);
-       /*
-        * If this is the last controller to be released, destroy the
-        * pciehp work queue
-        */
-       if (atomic_dec_and_test(&pciehp_num_controllers))
-               destroy_workqueue(pciehp_wq);
        kfree(ctrl);
 }