Commit e48f1b67 authored by Rajat Jain's avatar Rajat Jain Committed by Bjorn Helgaas

PCI: pciehp: Use link change notifications for hot-plug and removal

A lot of systems do not have the fancy buttons and LEDs, and instead
want to rely only on the Link state change events to drive the hotplug
and removal state machinery.
(http://www.spinics.net/lists/hotplug/msg05802.html)

This patch adds support for that functionality. Here are the details
about the patch itself:

* Define and use interrupt events for linkup / linkdown.

* Make the pcie_isr() also look at link events, and direct control to
  corresponding (new) link state change handler function.

* Introduce the functions to handle link-up and link-down events and
  queue the add / removal work in the slot->wq to be processed by
  pciehp_power_thread()

As a side note, this patch also fixes the bug
https://bugzilla.kernel.org/show_bug.cgi?id=65521 "pciehp ignores Data Link
Layer State Changed bit."
Signed-off-by: default avatarRajat Jain <rajatxjain@gmail.com>
Signed-off-by: default avatarRajat Jain <rajatjain@juniper.net>
Signed-off-by: default avatarGuenter Roeck <groeck@juniper.net>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 4703389f
...@@ -109,6 +109,8 @@ struct controller { ...@@ -109,6 +109,8 @@ struct controller {
#define INT_BUTTON_PRESS 7 #define INT_BUTTON_PRESS 7
#define INT_BUTTON_RELEASE 8 #define INT_BUTTON_RELEASE 8
#define INT_BUTTON_CANCEL 9 #define INT_BUTTON_CANCEL 9
#define INT_LINK_UP 10
#define INT_LINK_DOWN 11
#define STATIC_STATE 0 #define STATIC_STATE 0
#define BLINKINGON_STATE 1 #define BLINKINGON_STATE 1
...@@ -132,6 +134,7 @@ u8 pciehp_handle_attention_button(struct slot *p_slot); ...@@ -132,6 +134,7 @@ u8 pciehp_handle_attention_button(struct slot *p_slot);
u8 pciehp_handle_switch_change(struct slot *p_slot); u8 pciehp_handle_switch_change(struct slot *p_slot);
u8 pciehp_handle_presence_change(struct slot *p_slot); u8 pciehp_handle_presence_change(struct slot *p_slot);
u8 pciehp_handle_power_fault(struct slot *p_slot); u8 pciehp_handle_power_fault(struct slot *p_slot);
void pciehp_handle_linkstate_change(struct slot *p_slot);
int pciehp_configure_device(struct slot *p_slot); int pciehp_configure_device(struct slot *p_slot);
int pciehp_unconfigure_device(struct slot *p_slot); int pciehp_unconfigure_device(struct slot *p_slot);
void pciehp_queue_pushbutton_work(struct work_struct *work); void pciehp_queue_pushbutton_work(struct work_struct *work);
......
...@@ -150,6 +150,27 @@ u8 pciehp_handle_power_fault(struct slot *p_slot) ...@@ -150,6 +150,27 @@ u8 pciehp_handle_power_fault(struct slot *p_slot)
return 1; return 1;
} }
void pciehp_handle_linkstate_change(struct slot *p_slot)
{
u32 event_type;
struct controller *ctrl = p_slot->ctrl;
/* Link Status Change */
ctrl_dbg(ctrl, "Data Link Layer State change\n");
if (pciehp_check_link_active(ctrl)) {
ctrl_info(ctrl, "slot(%s): Link Up event\n",
slot_name(p_slot));
event_type = INT_LINK_UP;
} else {
ctrl_info(ctrl, "slot(%s): Link Down event\n",
slot_name(p_slot));
event_type = INT_LINK_DOWN;
}
queue_interrupt_event(p_slot, event_type);
}
/* The following routines constitute the bulk of the /* The following routines constitute the bulk of the
hotplug controller logic hotplug controller logic
*/ */
...@@ -415,6 +436,69 @@ static void handle_surprise_event(struct slot *p_slot) ...@@ -415,6 +436,69 @@ static void handle_surprise_event(struct slot *p_slot)
queue_work(p_slot->wq, &info->work); queue_work(p_slot->wq, &info->work);
} }
/*
* Note: This function must be called with slot->lock held
*/
static void handle_link_event(struct slot *p_slot, u32 event)
{
struct controller *ctrl = p_slot->ctrl;
struct power_work_info *info;
info = kmalloc(sizeof(*info), GFP_KERNEL);
if (!info) {
ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n",
__func__);
return;
}
info->p_slot = p_slot;
INIT_WORK(&info->work, pciehp_power_thread);
switch (p_slot->state) {
case BLINKINGON_STATE:
case BLINKINGOFF_STATE:
cancel_delayed_work(&p_slot->work);
/* Fall through */
case STATIC_STATE:
p_slot->state = event == INT_LINK_UP ?
POWERON_STATE : POWEROFF_STATE;
queue_work(p_slot->wq, &info->work);
break;
case POWERON_STATE:
if (event == INT_LINK_UP) {
ctrl_info(ctrl,
"Link Up event ignored on slot(%s): already powering on\n",
slot_name(p_slot));
kfree(info);
} else {
ctrl_info(ctrl,
"Link Down event queued on slot(%s): currently getting powered on\n",
slot_name(p_slot));
p_slot->state = POWEROFF_STATE;
queue_work(p_slot->wq, &info->work);
}
break;
case POWEROFF_STATE:
if (event == INT_LINK_UP) {
ctrl_info(ctrl,
"Link Up event queued on slot(%s): currently getting powered off\n",
slot_name(p_slot));
p_slot->state = POWERON_STATE;
queue_work(p_slot->wq, &info->work);
} else {
ctrl_info(ctrl,
"Link Down event ignored on slot(%s): already powering off\n",
slot_name(p_slot));
kfree(info);
}
break;
default:
ctrl_err(ctrl, "Not a valid state on slot(%s)\n",
slot_name(p_slot));
kfree(info);
break;
}
}
static void interrupt_event_handler(struct work_struct *work) static void interrupt_event_handler(struct work_struct *work)
{ {
struct event_info *info = container_of(work, struct event_info, work); struct event_info *info = container_of(work, struct event_info, work);
...@@ -439,6 +523,10 @@ static void interrupt_event_handler(struct work_struct *work) ...@@ -439,6 +523,10 @@ static void interrupt_event_handler(struct work_struct *work)
ctrl_dbg(ctrl, "Surprise Removal\n"); ctrl_dbg(ctrl, "Surprise Removal\n");
handle_surprise_event(p_slot); handle_surprise_event(p_slot);
break; break;
case INT_LINK_UP:
case INT_LINK_DOWN:
handle_link_event(p_slot, info->event_type);
break;
default: default:
break; break;
} }
......
...@@ -540,7 +540,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id) ...@@ -540,7 +540,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
detected &= (PCI_EXP_SLTSTA_ABP | PCI_EXP_SLTSTA_PFD | detected &= (PCI_EXP_SLTSTA_ABP | PCI_EXP_SLTSTA_PFD |
PCI_EXP_SLTSTA_MRLSC | PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_MRLSC | PCI_EXP_SLTSTA_PDC |
PCI_EXP_SLTSTA_CC); PCI_EXP_SLTSTA_CC | PCI_EXP_SLTSTA_DLLSC);
detected &= ~intr_loc; detected &= ~intr_loc;
intr_loc |= detected; intr_loc |= detected;
if (!intr_loc) if (!intr_loc)
...@@ -579,6 +579,10 @@ static irqreturn_t pcie_isr(int irq, void *dev_id) ...@@ -579,6 +579,10 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
ctrl->power_fault_detected = 1; ctrl->power_fault_detected = 1;
pciehp_handle_power_fault(slot); pciehp_handle_power_fault(slot);
} }
if (intr_loc & PCI_EXP_SLTSTA_DLLSC)
pciehp_handle_linkstate_change(slot);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
......
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