Skip to content

Commit 4283c70

Browse files
committed
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: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Yinghai Lu <yinghai@kernel.org>
1 parent 62e4492 commit 4283c70

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

‎drivers/pci/hotplug/pciehp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct controller {
9292
struct slot *slot;
9393
wait_queue_head_t queue; /* sleep & wake process */
9494
u32 slot_cap;
95+
u32 slot_ctrl;
9596
struct timer_list poll_timer;
9697
unsigned int cmd_busy:1;
9798
unsigned int no_cmd_complete:1;

‎drivers/pci/hotplug/pciehp_hpc.c‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,27 @@ static int pcie_poll_cmd(struct controller *ctrl)
129129
return 0; /* timeout */
130130
}
131131

132-
static void pcie_wait_cmd(struct controller *ctrl, int poll)
132+
static void pcie_wait_cmd(struct controller *ctrl)
133133
{
134134
unsigned int msecs = pciehp_poll_mode ? 2500 : 1000;
135135
unsigned long timeout = msecs_to_jiffies(msecs);
136136
int rc;
137137

138-
if (poll)
139-
rc = pcie_poll_cmd(ctrl);
140-
else
138+
/*
139+
* If the controller does not generate notifications for command
140+
* completions, we never need to wait between writes.
141+
*/
142+
if (ctrl->no_cmd_complete)
143+
return;
144+
145+
if (!ctrl->cmd_busy)
146+
return;
147+
148+
if (ctrl->slot_ctrl & PCI_EXP_SLTCTL_HPIE &&
149+
ctrl->slot_ctrl & PCI_EXP_SLTCTL_CCIE)
141150
rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout);
151+
else
152+
rc = pcie_poll_cmd(ctrl);
142153
if (!rc)
143154
ctrl_dbg(ctrl, "Command not completed in 1000 msec\n");
144155
}
@@ -187,22 +198,12 @@ static void pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
187198
ctrl->cmd_busy = 1;
188199
smp_mb();
189200
pcie_capability_write_word(pdev, PCI_EXP_SLTCTL, slot_ctrl);
201+
ctrl->slot_ctrl = slot_ctrl;
190202

191203
/*
192204
* Wait for command completion.
193205
*/
194-
if (!ctrl->no_cmd_complete) {
195-
int poll = 0;
196-
/*
197-
* if hotplug interrupt is not enabled or command
198-
* completed interrupt is not enabled, we need to poll
199-
* command completed event.
200-
*/
201-
if (!(slot_ctrl & PCI_EXP_SLTCTL_HPIE) ||
202-
!(slot_ctrl & PCI_EXP_SLTCTL_CCIE))
203-
poll = 1;
204-
pcie_wait_cmd(ctrl, poll);
205-
}
206+
pcie_wait_cmd(ctrl);
206207
mutex_unlock(&ctrl->ctrl_lock);
207208
}
208209

0 commit comments

Comments
 (0)