Skip to content

Commit ae416e6

Browse files
kkaneshigejbarnes993
authored andcommitted
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: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent c27fb88 commit ae416e6

4 files changed

Lines changed: 39 additions & 39 deletions

File tree

‎drivers/pci/hotplug/pciehp.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct controller {
9393
u8 slot_device_offset;
9494
u32 first_slot; /* First physical slot number */ /* PCIE only has 1 slot */
9595
u8 slot_bus; /* Bus where the slots handled by this controller sit */
96-
u8 ctrlcap;
96+
u32 slot_cap;
9797
u8 cap_base;
9898
struct timer_list poll_timer;
9999
volatile int cmd_busy;
@@ -136,13 +136,13 @@ struct controller {
136136
#define HP_SUPR_RM_SUP 0x00000020
137137
#define EMI_PRSN 0x00020000
138138

139-
#define ATTN_BUTTN(cap) (cap & ATTN_BUTTN_PRSN)
140-
#define POWER_CTRL(cap) (cap & PWR_CTRL_PRSN)
141-
#define MRL_SENS(cap) (cap & MRL_SENS_PRSN)
142-
#define ATTN_LED(cap) (cap & ATTN_LED_PRSN)
143-
#define PWR_LED(cap) (cap & PWR_LED_PRSN)
144-
#define HP_SUPR_RM(cap) (cap & HP_SUPR_RM_SUP)
145-
#define EMI(cap) (cap & EMI_PRSN)
139+
#define ATTN_BUTTN(ctrl) ((ctrl)->slot_cap & ATTN_BUTTN_PRSN)
140+
#define POWER_CTRL(ctrl) ((ctrl)->slot_cap & PWR_CTRL_PRSN)
141+
#define MRL_SENS(ctrl) ((ctrl)->slot_cap & MRL_SENS_PRSN)
142+
#define ATTN_LED(ctrl) ((ctrl)->slot_cap & ATTN_LED_PRSN)
143+
#define PWR_LED(ctrl) ((ctrl)->slot_cap & PWR_LED_PRSN)
144+
#define HP_SUPR_RM(ctrl) ((ctrl)->slot_cap & HP_SUPR_RM_SUP)
145+
#define EMI(ctrl) ((ctrl)->slot_cap & EMI_PRSN)
146146

147147
extern int pciehp_sysfs_enable_slot(struct slot *slot);
148148
extern int pciehp_sysfs_disable_slot(struct slot *slot);

‎drivers/pci/hotplug/pciehp_core.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int init_slots(struct controller *ctrl)
258258
goto error_info;
259259
}
260260
/* create additional sysfs entries */
261-
if (EMI(ctrl->ctrlcap)) {
261+
if (EMI(ctrl)) {
262262
retval = sysfs_create_file(&hotplug_slot->kobj,
263263
&hotplug_slot_attr_lock.attr);
264264
if (retval) {
@@ -291,7 +291,7 @@ static void cleanup_slots(struct controller *ctrl)
291291
list_for_each_safe(tmp, next, &ctrl->slot_list) {
292292
slot = list_entry(tmp, struct slot, slot_list);
293293
list_del(&slot->slot_list);
294-
if (EMI(ctrl->ctrlcap))
294+
if (EMI(ctrl))
295295
sysfs_remove_file(&slot->hotplug_slot->kobj,
296296
&hotplug_slot_attr_lock.attr);
297297
cancel_delayed_work(&slot->work);
@@ -312,7 +312,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
312312

313313
hotplug_slot->info->attention_status = status;
314314

315-
if (ATTN_LED(slot->ctrl->ctrlcap))
315+
if (ATTN_LED(slot->ctrl))
316316
slot->hpc_ops->set_attention_status(slot, status);
317317

318318
return 0;
@@ -479,7 +479,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
479479
if (rc) /* -ENODEV: shouldn't happen, but deal with it */
480480
value = 0;
481481
}
482-
if ((POWER_CTRL(ctrl->ctrlcap)) && !value) {
482+
if ((POWER_CTRL(ctrl)) && !value) {
483483
rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
484484
if (rc)
485485
goto err_out_free_ctrl_slot;

‎drivers/pci/hotplug/pciehp_ctrl.c‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,18 @@ u8 pciehp_handle_power_fault(u8 hp_slot, struct controller *ctrl)
178178
static void set_slot_off(struct controller *ctrl, struct slot * pslot)
179179
{
180180
/* turn off slot, turn on Amber LED, turn off Green LED if supported*/
181-
if (POWER_CTRL(ctrl->ctrlcap)) {
181+
if (POWER_CTRL(ctrl)) {
182182
if (pslot->hpc_ops->power_off_slot(pslot)) {
183183
err("%s: Issue of Slot Power Off command failed\n",
184184
__func__);
185185
return;
186186
}
187187
}
188188

189-
if (PWR_LED(ctrl->ctrlcap))
189+
if (PWR_LED(ctrl))
190190
pslot->hpc_ops->green_led_off(pslot);
191191

192-
if (ATTN_LED(ctrl->ctrlcap)) {
192+
if (ATTN_LED(ctrl)) {
193193
if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
194194
err("%s: Issue of Set Attention Led command failed\n",
195195
__func__);
@@ -214,14 +214,14 @@ static int board_added(struct slot *p_slot)
214214
__func__, p_slot->device,
215215
ctrl->slot_device_offset, p_slot->hp_slot);
216216

217-
if (POWER_CTRL(ctrl->ctrlcap)) {
217+
if (POWER_CTRL(ctrl)) {
218218
/* Power on slot */
219219
retval = p_slot->hpc_ops->power_on_slot(p_slot);
220220
if (retval)
221221
return retval;
222222
}
223223

224-
if (PWR_LED(ctrl->ctrlcap))
224+
if (PWR_LED(ctrl))
225225
p_slot->hpc_ops->green_led_blink(p_slot);
226226

227227
/* Wait for ~1 second */
@@ -254,7 +254,7 @@ static int board_added(struct slot *p_slot)
254254
*/
255255
if (pcie_mch_quirk)
256256
pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
257-
if (PWR_LED(ctrl->ctrlcap))
257+
if (PWR_LED(ctrl))
258258
p_slot->hpc_ops->green_led_on(p_slot);
259259

260260
return 0;
@@ -279,7 +279,7 @@ static int remove_board(struct slot *p_slot)
279279

280280
dbg("In %s, hp_slot = %d\n", __func__, p_slot->hp_slot);
281281

282-
if (POWER_CTRL(ctrl->ctrlcap)) {
282+
if (POWER_CTRL(ctrl)) {
283283
/* power off slot */
284284
retval = p_slot->hpc_ops->power_off_slot(p_slot);
285285
if (retval) {
@@ -289,7 +289,7 @@ static int remove_board(struct slot *p_slot)
289289
}
290290
}
291291

292-
if (PWR_LED(ctrl->ctrlcap))
292+
if (PWR_LED(ctrl))
293293
/* turn off Green LED */
294294
p_slot->hpc_ops->green_led_off(p_slot);
295295

@@ -327,7 +327,7 @@ static void pciehp_power_thread(struct work_struct *work)
327327
case POWERON_STATE:
328328
mutex_unlock(&p_slot->lock);
329329
if (pciehp_enable_slot(p_slot) &&
330-
PWR_LED(p_slot->ctrl->ctrlcap))
330+
PWR_LED(p_slot->ctrl))
331331
p_slot->hpc_ops->green_led_off(p_slot);
332332
mutex_lock(&p_slot->lock);
333333
p_slot->state = STATIC_STATE;
@@ -409,9 +409,9 @@ static void handle_button_press_event(struct slot *p_slot)
409409
"press.\n", p_slot->name);
410410
}
411411
/* blink green LED and turn off amber */
412-
if (PWR_LED(ctrl->ctrlcap))
412+
if (PWR_LED(ctrl))
413413
p_slot->hpc_ops->green_led_blink(p_slot);
414-
if (ATTN_LED(ctrl->ctrlcap))
414+
if (ATTN_LED(ctrl))
415415
p_slot->hpc_ops->set_attention_status(p_slot, 0);
416416

417417
schedule_delayed_work(&p_slot->work, 5*HZ);
@@ -427,13 +427,13 @@ static void handle_button_press_event(struct slot *p_slot)
427427
dbg("%s: button cancel\n", __func__);
428428
cancel_delayed_work(&p_slot->work);
429429
if (p_slot->state == BLINKINGOFF_STATE) {
430-
if (PWR_LED(ctrl->ctrlcap))
430+
if (PWR_LED(ctrl))
431431
p_slot->hpc_ops->green_led_on(p_slot);
432432
} else {
433-
if (PWR_LED(ctrl->ctrlcap))
433+
if (PWR_LED(ctrl))
434434
p_slot->hpc_ops->green_led_off(p_slot);
435435
}
436-
if (ATTN_LED(ctrl->ctrlcap))
436+
if (ATTN_LED(ctrl))
437437
p_slot->hpc_ops->set_attention_status(p_slot, 0);
438438
info("PCI slot #%s - action canceled due to button press\n",
439439
p_slot->name);
@@ -492,16 +492,16 @@ static void interrupt_event_handler(struct work_struct *work)
492492
handle_button_press_event(p_slot);
493493
break;
494494
case INT_POWER_FAULT:
495-
if (!POWER_CTRL(ctrl->ctrlcap))
495+
if (!POWER_CTRL(ctrl))
496496
break;
497-
if (ATTN_LED(ctrl->ctrlcap))
497+
if (ATTN_LED(ctrl))
498498
p_slot->hpc_ops->set_attention_status(p_slot, 1);
499-
if (PWR_LED(ctrl->ctrlcap))
499+
if (PWR_LED(ctrl))
500500
p_slot->hpc_ops->green_led_off(p_slot);
501501
break;
502502
case INT_PRESENCE_ON:
503503
case INT_PRESENCE_OFF:
504-
if (!HP_SUPR_RM(ctrl->ctrlcap))
504+
if (!HP_SUPR_RM(ctrl))
505505
break;
506506
dbg("Surprise Removal\n");
507507
update_slot_info(p_slot);
@@ -531,7 +531,7 @@ int pciehp_enable_slot(struct slot *p_slot)
531531
mutex_unlock(&p_slot->ctrl->crit_sect);
532532
return -ENODEV;
533533
}
534-
if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
534+
if (MRL_SENS(p_slot->ctrl)) {
535535
rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
536536
if (rc || getstatus) {
537537
info("%s: latch open on slot(%s)\n", __func__,
@@ -541,7 +541,7 @@ int pciehp_enable_slot(struct slot *p_slot)
541541
}
542542
}
543543

544-
if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
544+
if (POWER_CTRL(p_slot->ctrl)) {
545545
rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
546546
if (rc || getstatus) {
547547
info("%s: already enabled on slot(%s)\n", __func__,
@@ -576,7 +576,7 @@ int pciehp_disable_slot(struct slot *p_slot)
576576
/* Check to see if (latch closed, card present, power on) */
577577
mutex_lock(&p_slot->ctrl->crit_sect);
578578

579-
if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {
579+
if (!HP_SUPR_RM(p_slot->ctrl)) {
580580
ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
581581
if (ret || !getstatus) {
582582
info("%s: no adapter on slot(%s)\n", __func__,
@@ -586,7 +586,7 @@ int pciehp_disable_slot(struct slot *p_slot)
586586
}
587587
}
588588

589-
if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
589+
if (MRL_SENS(p_slot->ctrl)) {
590590
ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
591591
if (ret || getstatus) {
592592
info("%s: latch open on slot(%s)\n", __func__,
@@ -596,7 +596,7 @@ int pciehp_disable_slot(struct slot *p_slot)
596596
}
597597
}
598598

599-
if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
599+
if (POWER_CTRL(p_slot->ctrl)) {
600600
ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
601601
if (ret || !getstatus) {
602602
info("%s: already disabled slot(%s)\n", __func__,

‎drivers/pci/hotplug/pciehp_hpc.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,11 @@ int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
10581058
}
10591059

10601060
cmd = PRSN_DETECT_ENABLE;
1061-
if (ATTN_BUTTN(ctrl->ctrlcap))
1061+
if (ATTN_BUTTN(ctrl))
10621062
cmd |= ATTN_BUTTN_ENABLE;
1063-
if (POWER_CTRL(ctrl->ctrlcap))
1063+
if (POWER_CTRL(ctrl))
10641064
cmd |= PWR_FAULT_DETECT_ENABLE;
1065-
if (MRL_SENS(ctrl->ctrlcap))
1065+
if (MRL_SENS(ctrl))
10661066
cmd |= MRL_DETECT_ENABLE;
10671067
if (!pciehp_poll_mode)
10681068
cmd |= HP_INTR_ENABLE;
@@ -1181,7 +1181,7 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev)
11811181
ctrl->slot_device_offset = 0;
11821182
ctrl->num_slots = 1;
11831183
ctrl->first_slot = slot_cap >> 19;
1184-
ctrl->ctrlcap = slot_cap & 0x0000007f;
1184+
ctrl->slot_cap = slot_cap;
11851185

11861186
rc = pcie_init_hardware_part1(ctrl, dev);
11871187
if (rc)

0 commit comments

Comments
 (0)