Commit 44ef4cef authored by Kenji Kaneshige's avatar Kenji Kaneshige Committed by Greg Kroah-Hartman

pciehp: cleanup wait command completion

This patch cleans up the code to wait for command completion.
Signed-off-by: default avatarKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: default avatarKristen Carlson Accardi <kristen.c.accardi@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 75e13178
...@@ -173,24 +173,6 @@ static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device) ...@@ -173,24 +173,6 @@ static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device)
return NULL; return NULL;
} }
static inline int wait_for_ctrl_irq(struct controller *ctrl)
{
DECLARE_WAITQUEUE(wait, current);
add_wait_queue(&ctrl->queue, &wait);
if (!pciehp_poll_mode)
/* Sleep for up to 1 second */
msleep_interruptible(1000);
else
msleep_interruptible(2500);
remove_wait_queue(&ctrl->queue, &wait);
if (signal_pending(current))
return -EINTR;
return 0;
}
struct hpc_ops { struct hpc_ops {
int (*power_on_slot)(struct slot *slot); int (*power_on_slot)(struct slot *slot);
int (*power_off_slot)(struct slot *slot); int (*power_off_slot)(struct slot *slot);
......
...@@ -374,25 +374,13 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_ ...@@ -374,25 +374,13 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
pciehp_ctrl_list = ctrl; pciehp_ctrl_list = ctrl;
} }
/* Wait for exclusive access to hardware */
mutex_lock(&ctrl->ctrl_lock);
t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */ t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
if ((POWER_CTRL(ctrl->ctrlcap)) && !value) { if ((POWER_CTRL(ctrl->ctrlcap)) && !value) {
rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/ rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
if (rc) { if (rc)
/* Done with exclusive hardware access */
mutex_unlock(&ctrl->ctrl_lock);
goto err_out_free_ctrl_slot; goto err_out_free_ctrl_slot;
} else
/* Wait for the command to complete */
wait_for_ctrl_irq (ctrl);
} }
/* Done with exclusive hardware access */
mutex_unlock(&ctrl->ctrl_lock);
return 0; return 0;
err_out_free_ctrl_slot: err_out_free_ctrl_slot:
......
This diff is collapsed.
...@@ -249,6 +249,24 @@ static void start_int_poll_timer(struct controller *ctrl, int sec) ...@@ -249,6 +249,24 @@ static void start_int_poll_timer(struct controller *ctrl, int sec)
add_timer(&ctrl->poll_timer); add_timer(&ctrl->poll_timer);
} }
static inline int pcie_wait_cmd(struct controller *ctrl)
{
DECLARE_WAITQUEUE(wait, current);
add_wait_queue(&ctrl->queue, &wait);
if (!pciehp_poll_mode)
/* Sleep for up to 1 second */
msleep_interruptible(1000);
else
msleep_interruptible(2500);
remove_wait_queue(&ctrl->queue, &wait);
if (signal_pending(current))
return -EINTR;
return 0;
}
static int pcie_write_cmd(struct slot *slot, u16 cmd) static int pcie_write_cmd(struct slot *slot, u16 cmd)
{ {
struct controller *ctrl = slot->ctrl; struct controller *ctrl = slot->ctrl;
...@@ -257,24 +275,34 @@ static int pcie_write_cmd(struct slot *slot, u16 cmd) ...@@ -257,24 +275,34 @@ static int pcie_write_cmd(struct slot *slot, u16 cmd)
DBG_ENTER_ROUTINE DBG_ENTER_ROUTINE
mutex_lock(&ctrl->ctrl_lock);
retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
if (retval) { if (retval) {
err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
return retval; goto out;
} }
if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) { if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) {
/* After 1 sec and CMD_COMPLETED still not set, just proceed forward to issue /* After 1 sec and CMD_COMPLETED still not set, just
the next command according to spec. Just print out the error message */ proceed forward to issue the next command according
dbg("%s : CMD_COMPLETED not clear after 1 sec.\n", __FUNCTION__); to spec. Just print out the error message */
dbg("%s: CMD_COMPLETED not clear after 1 sec.\n",
__FUNCTION__);
} }
retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE)); retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE));
if (retval) { if (retval) {
err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
return retval; goto out;
} }
/*
* Wait for command completion.
*/
retval = pcie_wait_cmd(ctrl);
out:
mutex_unlock(&ctrl->ctrl_lock);
DBG_LEAVE_ROUTINE DBG_LEAVE_ROUTINE
return retval; return retval;
} }
......
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