Commit 4283c70e authored by Bjorn Helgaas's avatar Bjorn Helgaas

PCI: pciehp: Make pcie_wait_cmd() self-contained

pcie_wait_cmd() waits for the controller to finish a hotplug command.  Move
the associated logic (to determine whether waiting is required and whether
we're using interrupts or polling) from pcie_write_cmd() to
pcie_wait_cmd().

No functional change.

Tested-by: Rajat Jain <rajatxjain@gmail.com>	(IDT 807a controller)
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: default avatarYinghai Lu <yinghai@kernel.org>
parent 62e4492c
...@@ -92,6 +92,7 @@ struct controller { ...@@ -92,6 +92,7 @@ struct controller {
struct slot *slot; struct slot *slot;
wait_queue_head_t queue; /* sleep & wake process */ wait_queue_head_t queue; /* sleep & wake process */
u32 slot_cap; u32 slot_cap;
u32 slot_ctrl;
struct timer_list poll_timer; struct timer_list poll_timer;
unsigned int cmd_busy:1; unsigned int cmd_busy:1;
unsigned int no_cmd_complete:1; unsigned int no_cmd_complete:1;
......
...@@ -129,16 +129,27 @@ static int pcie_poll_cmd(struct controller *ctrl) ...@@ -129,16 +129,27 @@ static int pcie_poll_cmd(struct controller *ctrl)
return 0; /* timeout */ return 0; /* timeout */
} }
static void pcie_wait_cmd(struct controller *ctrl, int poll) static void pcie_wait_cmd(struct controller *ctrl)
{ {
unsigned int msecs = pciehp_poll_mode ? 2500 : 1000; unsigned int msecs = pciehp_poll_mode ? 2500 : 1000;
unsigned long timeout = msecs_to_jiffies(msecs); unsigned long timeout = msecs_to_jiffies(msecs);
int rc; int rc;
if (poll) /*
rc = pcie_poll_cmd(ctrl); * If the controller does not generate notifications for command
else * completions, we never need to wait between writes.
*/
if (ctrl->no_cmd_complete)
return;
if (!ctrl->cmd_busy)
return;
if (ctrl->slot_ctrl & PCI_EXP_SLTCTL_HPIE &&
ctrl->slot_ctrl & PCI_EXP_SLTCTL_CCIE)
rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout); rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout);
else
rc = pcie_poll_cmd(ctrl);
if (!rc) if (!rc)
ctrl_dbg(ctrl, "Command not completed in 1000 msec\n"); ctrl_dbg(ctrl, "Command not completed in 1000 msec\n");
} }
...@@ -187,22 +198,12 @@ static void pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask) ...@@ -187,22 +198,12 @@ static void pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
ctrl->cmd_busy = 1; ctrl->cmd_busy = 1;
smp_mb(); smp_mb();
pcie_capability_write_word(pdev, PCI_EXP_SLTCTL, slot_ctrl); pcie_capability_write_word(pdev, PCI_EXP_SLTCTL, slot_ctrl);
ctrl->slot_ctrl = slot_ctrl;
/* /*
* Wait for command completion. * Wait for command completion.
*/ */
if (!ctrl->no_cmd_complete) { pcie_wait_cmd(ctrl);
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 & PCI_EXP_SLTCTL_HPIE) ||
!(slot_ctrl & PCI_EXP_SLTCTL_CCIE))
poll = 1;
pcie_wait_cmd(ctrl, poll);
}
mutex_unlock(&ctrl->ctrl_lock); mutex_unlock(&ctrl->ctrl_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment