Commit ae416e6b authored by Kenji Kaneshige's avatar Kenji Kaneshige Committed by Jesse Barnes

pciehp: Fix wrong slot capability check

Current pciehp saves only 8bits of Slot Capability registers in
ctrl->ctrlcap. But it refers more than 8bit for checking EMI capability.
It is clearly a bug and EMI would never work. To fix this problem,
this patch saves full Slot Capability contens in ctrl->slot_cap. It also
reduce the redundant reads of Slot Capability register. And this pach
also cleans up the macros to check the slot capabilitys (e.g. MRL_SENS(),
and so on).
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 avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent c27fb883
...@@ -93,7 +93,7 @@ struct controller { ...@@ -93,7 +93,7 @@ struct controller {
u8 slot_device_offset; u8 slot_device_offset;
u32 first_slot; /* First physical slot number */ /* PCIE only has 1 slot */ u32 first_slot; /* First physical slot number */ /* PCIE only has 1 slot */
u8 slot_bus; /* Bus where the slots handled by this controller sit */ u8 slot_bus; /* Bus where the slots handled by this controller sit */
u8 ctrlcap; u32 slot_cap;
u8 cap_base; u8 cap_base;
struct timer_list poll_timer; struct timer_list poll_timer;
volatile int cmd_busy; volatile int cmd_busy;
...@@ -136,13 +136,13 @@ struct controller { ...@@ -136,13 +136,13 @@ struct controller {
#define HP_SUPR_RM_SUP 0x00000020 #define HP_SUPR_RM_SUP 0x00000020
#define EMI_PRSN 0x00020000 #define EMI_PRSN 0x00020000
#define ATTN_BUTTN(cap) (cap & ATTN_BUTTN_PRSN) #define ATTN_BUTTN(ctrl) ((ctrl)->slot_cap & ATTN_BUTTN_PRSN)
#define POWER_CTRL(cap) (cap & PWR_CTRL_PRSN) #define POWER_CTRL(ctrl) ((ctrl)->slot_cap & PWR_CTRL_PRSN)
#define MRL_SENS(cap) (cap & MRL_SENS_PRSN) #define MRL_SENS(ctrl) ((ctrl)->slot_cap & MRL_SENS_PRSN)
#define ATTN_LED(cap) (cap & ATTN_LED_PRSN) #define ATTN_LED(ctrl) ((ctrl)->slot_cap & ATTN_LED_PRSN)
#define PWR_LED(cap) (cap & PWR_LED_PRSN) #define PWR_LED(ctrl) ((ctrl)->slot_cap & PWR_LED_PRSN)
#define HP_SUPR_RM(cap) (cap & HP_SUPR_RM_SUP) #define HP_SUPR_RM(ctrl) ((ctrl)->slot_cap & HP_SUPR_RM_SUP)
#define EMI(cap) (cap & EMI_PRSN) #define EMI(ctrl) ((ctrl)->slot_cap & EMI_PRSN)
extern int pciehp_sysfs_enable_slot(struct slot *slot); extern int pciehp_sysfs_enable_slot(struct slot *slot);
extern int pciehp_sysfs_disable_slot(struct slot *slot); extern int pciehp_sysfs_disable_slot(struct slot *slot);
......
...@@ -258,7 +258,7 @@ static int init_slots(struct controller *ctrl) ...@@ -258,7 +258,7 @@ static int init_slots(struct controller *ctrl)
goto error_info; goto error_info;
} }
/* create additional sysfs entries */ /* create additional sysfs entries */
if (EMI(ctrl->ctrlcap)) { if (EMI(ctrl)) {
retval = sysfs_create_file(&hotplug_slot->kobj, retval = sysfs_create_file(&hotplug_slot->kobj,
&hotplug_slot_attr_lock.attr); &hotplug_slot_attr_lock.attr);
if (retval) { if (retval) {
...@@ -291,7 +291,7 @@ static void cleanup_slots(struct controller *ctrl) ...@@ -291,7 +291,7 @@ static void cleanup_slots(struct controller *ctrl)
list_for_each_safe(tmp, next, &ctrl->slot_list) { list_for_each_safe(tmp, next, &ctrl->slot_list) {
slot = list_entry(tmp, struct slot, slot_list); slot = list_entry(tmp, struct slot, slot_list);
list_del(&slot->slot_list); list_del(&slot->slot_list);
if (EMI(ctrl->ctrlcap)) if (EMI(ctrl))
sysfs_remove_file(&slot->hotplug_slot->kobj, sysfs_remove_file(&slot->hotplug_slot->kobj,
&hotplug_slot_attr_lock.attr); &hotplug_slot_attr_lock.attr);
cancel_delayed_work(&slot->work); cancel_delayed_work(&slot->work);
...@@ -312,7 +312,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status) ...@@ -312,7 +312,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
hotplug_slot->info->attention_status = status; hotplug_slot->info->attention_status = status;
if (ATTN_LED(slot->ctrl->ctrlcap)) if (ATTN_LED(slot->ctrl))
slot->hpc_ops->set_attention_status(slot, status); slot->hpc_ops->set_attention_status(slot, status);
return 0; return 0;
...@@ -479,7 +479,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_ ...@@ -479,7 +479,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
if (rc) /* -ENODEV: shouldn't happen, but deal with it */ if (rc) /* -ENODEV: shouldn't happen, but deal with it */
value = 0; value = 0;
} }
if ((POWER_CTRL(ctrl->ctrlcap)) && !value) { if ((POWER_CTRL(ctrl)) && !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)
goto err_out_free_ctrl_slot; goto err_out_free_ctrl_slot;
......
...@@ -178,7 +178,7 @@ u8 pciehp_handle_power_fault(u8 hp_slot, struct controller *ctrl) ...@@ -178,7 +178,7 @@ u8 pciehp_handle_power_fault(u8 hp_slot, struct controller *ctrl)
static void set_slot_off(struct controller *ctrl, struct slot * pslot) static void set_slot_off(struct controller *ctrl, struct slot * pslot)
{ {
/* turn off slot, turn on Amber LED, turn off Green LED if supported*/ /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
if (POWER_CTRL(ctrl->ctrlcap)) { if (POWER_CTRL(ctrl)) {
if (pslot->hpc_ops->power_off_slot(pslot)) { if (pslot->hpc_ops->power_off_slot(pslot)) {
err("%s: Issue of Slot Power Off command failed\n", err("%s: Issue of Slot Power Off command failed\n",
__func__); __func__);
...@@ -186,10 +186,10 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot) ...@@ -186,10 +186,10 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot)
} }
} }
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
pslot->hpc_ops->green_led_off(pslot); pslot->hpc_ops->green_led_off(pslot);
if (ATTN_LED(ctrl->ctrlcap)) { if (ATTN_LED(ctrl)) {
if (pslot->hpc_ops->set_attention_status(pslot, 1)) { if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
err("%s: Issue of Set Attention Led command failed\n", err("%s: Issue of Set Attention Led command failed\n",
__func__); __func__);
...@@ -214,14 +214,14 @@ static int board_added(struct slot *p_slot) ...@@ -214,14 +214,14 @@ static int board_added(struct slot *p_slot)
__func__, p_slot->device, __func__, p_slot->device,
ctrl->slot_device_offset, p_slot->hp_slot); ctrl->slot_device_offset, p_slot->hp_slot);
if (POWER_CTRL(ctrl->ctrlcap)) { if (POWER_CTRL(ctrl)) {
/* Power on slot */ /* Power on slot */
retval = p_slot->hpc_ops->power_on_slot(p_slot); retval = p_slot->hpc_ops->power_on_slot(p_slot);
if (retval) if (retval)
return retval; return retval;
} }
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
p_slot->hpc_ops->green_led_blink(p_slot); p_slot->hpc_ops->green_led_blink(p_slot);
/* Wait for ~1 second */ /* Wait for ~1 second */
...@@ -254,7 +254,7 @@ static int board_added(struct slot *p_slot) ...@@ -254,7 +254,7 @@ static int board_added(struct slot *p_slot)
*/ */
if (pcie_mch_quirk) if (pcie_mch_quirk)
pci_fixup_device(pci_fixup_final, ctrl->pci_dev); pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
p_slot->hpc_ops->green_led_on(p_slot); p_slot->hpc_ops->green_led_on(p_slot);
return 0; return 0;
...@@ -279,7 +279,7 @@ static int remove_board(struct slot *p_slot) ...@@ -279,7 +279,7 @@ static int remove_board(struct slot *p_slot)
dbg("In %s, hp_slot = %d\n", __func__, p_slot->hp_slot); dbg("In %s, hp_slot = %d\n", __func__, p_slot->hp_slot);
if (POWER_CTRL(ctrl->ctrlcap)) { if (POWER_CTRL(ctrl)) {
/* power off slot */ /* power off slot */
retval = p_slot->hpc_ops->power_off_slot(p_slot); retval = p_slot->hpc_ops->power_off_slot(p_slot);
if (retval) { if (retval) {
...@@ -289,7 +289,7 @@ static int remove_board(struct slot *p_slot) ...@@ -289,7 +289,7 @@ static int remove_board(struct slot *p_slot)
} }
} }
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
/* turn off Green LED */ /* turn off Green LED */
p_slot->hpc_ops->green_led_off(p_slot); p_slot->hpc_ops->green_led_off(p_slot);
...@@ -327,7 +327,7 @@ static void pciehp_power_thread(struct work_struct *work) ...@@ -327,7 +327,7 @@ static void pciehp_power_thread(struct work_struct *work)
case POWERON_STATE: case POWERON_STATE:
mutex_unlock(&p_slot->lock); mutex_unlock(&p_slot->lock);
if (pciehp_enable_slot(p_slot) && if (pciehp_enable_slot(p_slot) &&
PWR_LED(p_slot->ctrl->ctrlcap)) PWR_LED(p_slot->ctrl))
p_slot->hpc_ops->green_led_off(p_slot); p_slot->hpc_ops->green_led_off(p_slot);
mutex_lock(&p_slot->lock); mutex_lock(&p_slot->lock);
p_slot->state = STATIC_STATE; p_slot->state = STATIC_STATE;
...@@ -409,9 +409,9 @@ static void handle_button_press_event(struct slot *p_slot) ...@@ -409,9 +409,9 @@ static void handle_button_press_event(struct slot *p_slot)
"press.\n", p_slot->name); "press.\n", p_slot->name);
} }
/* blink green LED and turn off amber */ /* blink green LED and turn off amber */
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
p_slot->hpc_ops->green_led_blink(p_slot); p_slot->hpc_ops->green_led_blink(p_slot);
if (ATTN_LED(ctrl->ctrlcap)) if (ATTN_LED(ctrl))
p_slot->hpc_ops->set_attention_status(p_slot, 0); p_slot->hpc_ops->set_attention_status(p_slot, 0);
schedule_delayed_work(&p_slot->work, 5*HZ); schedule_delayed_work(&p_slot->work, 5*HZ);
...@@ -427,13 +427,13 @@ static void handle_button_press_event(struct slot *p_slot) ...@@ -427,13 +427,13 @@ static void handle_button_press_event(struct slot *p_slot)
dbg("%s: button cancel\n", __func__); dbg("%s: button cancel\n", __func__);
cancel_delayed_work(&p_slot->work); cancel_delayed_work(&p_slot->work);
if (p_slot->state == BLINKINGOFF_STATE) { if (p_slot->state == BLINKINGOFF_STATE) {
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
p_slot->hpc_ops->green_led_on(p_slot); p_slot->hpc_ops->green_led_on(p_slot);
} else { } else {
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
p_slot->hpc_ops->green_led_off(p_slot); p_slot->hpc_ops->green_led_off(p_slot);
} }
if (ATTN_LED(ctrl->ctrlcap)) if (ATTN_LED(ctrl))
p_slot->hpc_ops->set_attention_status(p_slot, 0); p_slot->hpc_ops->set_attention_status(p_slot, 0);
info("PCI slot #%s - action canceled due to button press\n", info("PCI slot #%s - action canceled due to button press\n",
p_slot->name); p_slot->name);
...@@ -492,16 +492,16 @@ static void interrupt_event_handler(struct work_struct *work) ...@@ -492,16 +492,16 @@ static void interrupt_event_handler(struct work_struct *work)
handle_button_press_event(p_slot); handle_button_press_event(p_slot);
break; break;
case INT_POWER_FAULT: case INT_POWER_FAULT:
if (!POWER_CTRL(ctrl->ctrlcap)) if (!POWER_CTRL(ctrl))
break; break;
if (ATTN_LED(ctrl->ctrlcap)) if (ATTN_LED(ctrl))
p_slot->hpc_ops->set_attention_status(p_slot, 1); p_slot->hpc_ops->set_attention_status(p_slot, 1);
if (PWR_LED(ctrl->ctrlcap)) if (PWR_LED(ctrl))
p_slot->hpc_ops->green_led_off(p_slot); p_slot->hpc_ops->green_led_off(p_slot);
break; break;
case INT_PRESENCE_ON: case INT_PRESENCE_ON:
case INT_PRESENCE_OFF: case INT_PRESENCE_OFF:
if (!HP_SUPR_RM(ctrl->ctrlcap)) if (!HP_SUPR_RM(ctrl))
break; break;
dbg("Surprise Removal\n"); dbg("Surprise Removal\n");
update_slot_info(p_slot); update_slot_info(p_slot);
...@@ -531,7 +531,7 @@ int pciehp_enable_slot(struct slot *p_slot) ...@@ -531,7 +531,7 @@ int pciehp_enable_slot(struct slot *p_slot)
mutex_unlock(&p_slot->ctrl->crit_sect); mutex_unlock(&p_slot->ctrl->crit_sect);
return -ENODEV; return -ENODEV;
} }
if (MRL_SENS(p_slot->ctrl->ctrlcap)) { if (MRL_SENS(p_slot->ctrl)) {
rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
if (rc || getstatus) { if (rc || getstatus) {
info("%s: latch open on slot(%s)\n", __func__, info("%s: latch open on slot(%s)\n", __func__,
...@@ -541,7 +541,7 @@ int pciehp_enable_slot(struct slot *p_slot) ...@@ -541,7 +541,7 @@ int pciehp_enable_slot(struct slot *p_slot)
} }
} }
if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { if (POWER_CTRL(p_slot->ctrl)) {
rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
if (rc || getstatus) { if (rc || getstatus) {
info("%s: already enabled on slot(%s)\n", __func__, info("%s: already enabled on slot(%s)\n", __func__,
...@@ -576,7 +576,7 @@ int pciehp_disable_slot(struct slot *p_slot) ...@@ -576,7 +576,7 @@ int pciehp_disable_slot(struct slot *p_slot)
/* Check to see if (latch closed, card present, power on) */ /* Check to see if (latch closed, card present, power on) */
mutex_lock(&p_slot->ctrl->crit_sect); mutex_lock(&p_slot->ctrl->crit_sect);
if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) { if (!HP_SUPR_RM(p_slot->ctrl)) {
ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
if (ret || !getstatus) { if (ret || !getstatus) {
info("%s: no adapter on slot(%s)\n", __func__, info("%s: no adapter on slot(%s)\n", __func__,
...@@ -586,7 +586,7 @@ int pciehp_disable_slot(struct slot *p_slot) ...@@ -586,7 +586,7 @@ int pciehp_disable_slot(struct slot *p_slot)
} }
} }
if (MRL_SENS(p_slot->ctrl->ctrlcap)) { if (MRL_SENS(p_slot->ctrl)) {
ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
if (ret || getstatus) { if (ret || getstatus) {
info("%s: latch open on slot(%s)\n", __func__, info("%s: latch open on slot(%s)\n", __func__,
...@@ -596,7 +596,7 @@ int pciehp_disable_slot(struct slot *p_slot) ...@@ -596,7 +596,7 @@ int pciehp_disable_slot(struct slot *p_slot)
} }
} }
if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { if (POWER_CTRL(p_slot->ctrl)) {
ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
if (ret || !getstatus) { if (ret || !getstatus) {
info("%s: already disabled slot(%s)\n", __func__, info("%s: already disabled slot(%s)\n", __func__,
......
...@@ -1058,11 +1058,11 @@ int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev) ...@@ -1058,11 +1058,11 @@ int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
} }
cmd = PRSN_DETECT_ENABLE; cmd = PRSN_DETECT_ENABLE;
if (ATTN_BUTTN(ctrl->ctrlcap)) if (ATTN_BUTTN(ctrl))
cmd |= ATTN_BUTTN_ENABLE; cmd |= ATTN_BUTTN_ENABLE;
if (POWER_CTRL(ctrl->ctrlcap)) if (POWER_CTRL(ctrl))
cmd |= PWR_FAULT_DETECT_ENABLE; cmd |= PWR_FAULT_DETECT_ENABLE;
if (MRL_SENS(ctrl->ctrlcap)) if (MRL_SENS(ctrl))
cmd |= MRL_DETECT_ENABLE; cmd |= MRL_DETECT_ENABLE;
if (!pciehp_poll_mode) if (!pciehp_poll_mode)
cmd |= HP_INTR_ENABLE; cmd |= HP_INTR_ENABLE;
...@@ -1181,7 +1181,7 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev) ...@@ -1181,7 +1181,7 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev)
ctrl->slot_device_offset = 0; ctrl->slot_device_offset = 0;
ctrl->num_slots = 1; ctrl->num_slots = 1;
ctrl->first_slot = slot_cap >> 19; ctrl->first_slot = slot_cap >> 19;
ctrl->ctrlcap = slot_cap & 0x0000007f; ctrl->slot_cap = slot_cap;
rc = pcie_init_hardware_part1(ctrl, dev); rc = pcie_init_hardware_part1(ctrl, dev);
if (rc) if (rc)
......
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