]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pci/hotplug/pciehp_hpc.c
pciehp: change command polling frequency
[linux-2.6-omap-h63xx.git] / drivers / pci / hotplug / pciehp_hpc.c
index 891f81a0400c92cb434dcdbbee95dbfa96c0e213..5ef4baecac7973b07edfd04513e6f902b48c4e57 100644 (file)
@@ -247,23 +247,42 @@ static inline void pciehp_free_irq(struct controller *ctrl)
                free_irq(ctrl->pci_dev->irq, ctrl);
 }
 
-static inline int pcie_wait_cmd(struct controller *ctrl)
+static inline int pcie_poll_cmd(struct controller *ctrl)
+{
+       u16 slot_status;
+       int timeout = 1000;
+
+       if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) {
+               if (slot_status & CMD_COMPLETED) {
+                       pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED);
+                       return 1;
+               }
+       }
+       while (timeout > 1000) {
+               msleep(10);
+               timeout -= 10;
+               if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) {
+                       if (slot_status & CMD_COMPLETED) {
+                               pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED);
+                               return 1;
+                       }
+               }
+       }
+       return 0;       /* timeout */
+}
+
+static inline void pcie_wait_cmd(struct controller *ctrl, int poll)
 {
-       int retval = 0;
        unsigned int msecs = pciehp_poll_mode ? 2500 : 1000;
        unsigned long timeout = msecs_to_jiffies(msecs);
        int rc;
 
-       rc = wait_event_interruptible_timeout(ctrl->queue,
-                                             !ctrl->cmd_busy, timeout);
+       if (poll)
+               rc = pcie_poll_cmd(ctrl);
+       else
+               rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout);
        if (!rc)
                dbg("Command not completed in 1000 msec\n");
-       else if (rc < 0) {
-               retval = -EINTR;
-               info("Command was interrupted by a signal\n");
-       }
-
-       return retval;
 }
 
 /**
@@ -286,12 +305,28 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
                goto out;
        }
 
-       if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) {
-               /* After 1 sec and CMD_COMPLETED still not set, just
-                  proceed forward to issue the next command according
-                  to spec.  Just print out the error message */
-               dbg("%s: CMD_COMPLETED not clear after 1 sec.\n",
-                   __func__);
+       if (slot_status & CMD_COMPLETED) {
+               if (!ctrl->no_cmd_complete) {
+                       /*
+                        * After 1 sec and CMD_COMPLETED still not set, just
+                        * proceed forward to issue the next command according
+                        * to spec. Just print out the error message.
+                        */
+                       dbg("%s: CMD_COMPLETED not clear after 1 sec.\n",
+                           __func__);
+               } else if (!NO_CMD_CMPL(ctrl)) {
+                       /*
+                        * This controller semms to notify of command completed
+                        * event even though it supports none of power
+                        * controller, attention led, power led and EMI.
+                        */
+                       dbg("%s: Unexpected CMD_COMPLETED. Need to wait for "
+                           "command completed event.\n", __func__);
+                       ctrl->no_cmd_complete = 0;
+               } else {
+                       dbg("%s: Unexpected CMD_COMPLETED. Maybe the "
+                           "controller is broken.\n", __func__);
+               }
        }
 
        retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
@@ -315,8 +350,18 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
        /*
         * Wait for command completion.
         */
-       if (!retval)
-               retval = pcie_wait_cmd(ctrl);
+       if (!retval && !ctrl->no_cmd_complete) {
+               int poll = 0;
+               /*
+                * if hotplug interrupt is not enabled or command
+                * completed interrupt is not enabled, we need to poll
+                * command completed event.
+                */
+               if (!(slot_ctrl & HP_INTR_ENABLE) ||
+                   !(slot_ctrl & CMD_CMPL_INTR_ENABLE))
+                       poll = 1;
+                pcie_wait_cmd(ctrl, poll);
+       }
  out:
        mutex_unlock(&ctrl->ctrl_lock);
        return retval;
@@ -568,7 +613,7 @@ static void hpc_release_ctlr(struct controller *ctrl)
 {
        /* Mask Hot-plug Interrupt Enable */
        if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE))
-               err("%s: Cannot mask hotplut interrupt enable\n", __func__);
+               err("%s: Cannot mask hotplug interrupt enable\n", __func__);
 
        /* Free interrupt handler or interrupt polling timer */
        pciehp_free_irq(ctrl);
@@ -704,13 +749,6 @@ static int hpc_power_off_slot(struct slot * slot)
        }
        dbg("%s: SLOTCTRL %x write cmd %x\n",
            __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
-
-       /*
-        * After turning power off, we must wait for at least 1 second
-        * before taking any action that relies on power having been
-        * removed from the slot/adapter.
-        */
-       msleep(1000);
  out:
        if (changed)
                pcie_unmask_bad_dllp(ctrl);
@@ -722,6 +760,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
 {
        struct controller *ctrl = (struct controller *)dev_id;
        u16 detected, intr_loc;
+       struct slot *p_slot;
 
        /*
         * In order to guarantee that all interrupt events are
@@ -741,7 +780,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
                intr_loc |= detected;
                if (!intr_loc)
                        return IRQ_NONE;
-               if (pciehp_writew(ctrl, SLOTSTATUS, detected)) {
+               if (detected && pciehp_writew(ctrl, SLOTSTATUS, detected)) {
                        err("%s: Cannot write to SLOTSTATUS\n", __func__);
                        return IRQ_NONE;
                }
@@ -753,24 +792,41 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
        if (intr_loc & CMD_COMPLETED) {
                ctrl->cmd_busy = 0;
                smp_mb();
-               wake_up_interruptible(&ctrl->queue);
+               wake_up(&ctrl->queue);
        }
 
+       if (!(intr_loc & ~CMD_COMPLETED))
+               return IRQ_HANDLED;
+
+       /*
+        * Return without handling events if this handler routine is
+        * called before controller initialization is done. This may
+        * happen if hotplug event or another interrupt that shares
+        * the IRQ with pciehp arrives before slot initialization is
+        * done after interrupt handler is registered.
+        *
+        * FIXME - Need more structural fixes. We need to be ready to
+        * handle the event before installing interrupt handler.
+        */
+       p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
+       if (!p_slot || !p_slot->hpc_ops)
+               return IRQ_HANDLED;
+
        /* Check MRL Sensor Changed */
        if (intr_loc & MRL_SENS_CHANGED)
-               pciehp_handle_switch_change(0, ctrl);
+               pciehp_handle_switch_change(p_slot);
 
        /* Check Attention Button Pressed */
        if (intr_loc & ATTN_BUTTN_PRESSED)
-               pciehp_handle_attention_button(0, ctrl);
+               pciehp_handle_attention_button(p_slot);
 
        /* Check Presence Detect Changed */
        if (intr_loc & PRSN_DETECT_CHANGED)
-               pciehp_handle_presence_change(0, ctrl);
+               pciehp_handle_presence_change(p_slot);
 
        /* Check Power Fault Detected */
        if (intr_loc & PWR_FAULT_DETECTED)
-               pciehp_handle_power_fault(0, ctrl);
+               pciehp_handle_power_fault(p_slot);
 
        return IRQ_HANDLED;
 }
@@ -956,78 +1012,15 @@ static struct hpc_ops pciehp_hpc_ops = {
        .check_lnk_status               = hpc_check_lnk_status,
 };
 
-#ifdef CONFIG_ACPI
-static int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
-{
-       acpi_status status;
-       acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
-       struct pci_dev *pdev = dev;
-       struct pci_bus *parent;
-       struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
-
-       /*
-        * Per PCI firmware specification, we should run the ACPI _OSC
-        * method to get control of hotplug hardware before using it.
-        * If an _OSC is missing, we look for an OSHP to do the same thing.
-        * To handle different BIOS behavior, we look for _OSC and OSHP
-        * within the scope of the hotplug controller and its parents, upto
-        * the host bridge under which this controller exists.
-        */
-       while (!handle) {
-               /*
-                * This hotplug controller was not listed in the ACPI name
-                * space at all. Try to get acpi handle of parent pci bus.
-                */
-               if (!pdev || !pdev->bus->parent)
-                       break;
-               parent = pdev->bus->parent;
-               dbg("Could not find %s in acpi namespace, trying parent\n",
-                               pci_name(pdev));
-               if (!parent->self)
-                       /* Parent must be a host bridge */
-                       handle = acpi_get_pci_rootbridge_handle(
-                                       pci_domain_nr(parent),
-                                       parent->number);
-               else
-                       handle = DEVICE_ACPI_HANDLE(
-                                       &(parent->self->dev));
-               pdev = parent->self;
-       }
-
-       while (handle) {
-               acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
-               dbg("Trying to get hotplug control for %s \n",
-                       (char *)string.pointer);
-               status = pci_osc_control_set(handle,
-                               OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL |
-                               OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
-               if (status == AE_NOT_FOUND)
-                       status = acpi_run_oshp(handle);
-               if (ACPI_SUCCESS(status)) {
-                       dbg("Gained control for hotplug HW for pci %s (%s)\n",
-                               pci_name(dev), (char *)string.pointer);
-                       kfree(string.pointer);
-                       return 0;
-               }
-               if (acpi_root_bridge(handle))
-                       break;
-               chandle = handle;
-               status = acpi_get_parent(chandle, &handle);
-               if (ACPI_FAILURE(status))
-                       break;
-       }
-
-       dbg("Cannot get control of hotplug hardware for pci %s\n",
-                       pci_name(dev));
-
-       kfree(string.pointer);
-       return -1;
-}
-#endif
-
 static int pcie_init_hardware_part1(struct controller *ctrl,
                                    struct pcie_device *dev)
 {
+       /* Clear all remaining event bits in Slot Status register */
+       if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) {
+               err("%s: Cannot write to SLOTSTATUS register\n", __func__);
+               return -1;
+       }
+
        /* Mask Hot-plug Interrupt Enable */
        if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) {
                err("%s: Cannot mask hotplug interrupt enable\n", __func__);
@@ -1040,16 +1033,6 @@ int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
 {
        u16 cmd, mask;
 
-       /*
-        * We need to clear all events before enabling hotplug interrupt
-        * notification mechanism in order for hotplug controler to
-        * generate interrupts.
-        */
-       if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) {
-               err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
-               return -1;
-       }
-
        cmd = PRSN_DETECT_ENABLE;
        if (ATTN_BUTTN(ctrl))
                cmd |= ATTN_BUTTN_ENABLE;
@@ -1065,23 +1048,10 @@ int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
 
        if (pcie_write_cmd(ctrl, cmd, mask)) {
                err("%s: Cannot enable software notification\n", __func__);
-               goto abort;
+               return -1;
        }
 
-       if (pciehp_force)
-               dbg("Bypassing BIOS check for pciehp use on %s\n",
-                               pci_name(ctrl->pci_dev));
-       else if (pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev))
-               goto abort_disable_intr;
-
        return 0;
-
-       /* We end up here for the many possible ways to fail this API. */
-abort_disable_intr:
-       if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE))
-               err("%s : disabling interrupts failed\n", __func__);
-abort:
-       return -1;
 }
 
 static inline void dbg_ctrl(struct controller *ctrl)
@@ -1116,9 +1086,10 @@ static inline void dbg_ctrl(struct controller *ctrl)
        dbg("  Power Indicator      : %3s\n", PWR_LED(ctrl)    ? "yes" : "no");
        dbg("  Hot-Plug Surprise    : %3s\n", HP_SUPR_RM(ctrl) ? "yes" : "no");
        dbg("  EMI Present          : %3s\n", EMI(ctrl)        ? "yes" : "no");
+       dbg("  Comamnd Completed    : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes");
        pciehp_readw(ctrl, SLOTSTATUS, &reg16);
        dbg("Slot Status            : 0x%04x\n", reg16);
-       pciehp_readw(ctrl, SLOTSTATUS, &reg16);
+       pciehp_readw(ctrl, SLOTCTRL, &reg16);
        dbg("Slot Control           : 0x%04x\n", reg16);
 }
 
@@ -1147,6 +1118,15 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev)
        mutex_init(&ctrl->ctrl_lock);
        init_waitqueue_head(&ctrl->queue);
        dbg_ctrl(ctrl);
+       /*
+        * Controller doesn't notify of command completion if the "No
+        * Command Completed Support" bit is set in Slot Capability
+        * register or the controller supports none of power
+        * controller, attention led, power led and EMI.
+        */
+       if (NO_CMD_CMPL(ctrl) ||
+           !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl)))
+           ctrl->no_cmd_complete = 1;
 
        info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
             pdev->vendor, pdev->device,