Lines Matching +full:add +full:- +full:ctrl

1 // SPDX-License-Identifier: GPL-2.0+
6 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
8 * Copyright (C) 2003-2004 Intel Corporation
34 return -ENOMEM; in queue_interrupt_event()
36 info->event_type = event_type; in queue_interrupt_event()
37 info->p_slot = p_slot; in queue_interrupt_event()
38 INIT_WORK(&info->work, interrupt_event_handler); in queue_interrupt_event()
40 queue_work(p_slot->wq, &info->work); in queue_interrupt_event()
45 u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl) in shpchp_handle_attention_button() argument
51 ctrl_dbg(ctrl, "Attention button interrupt received\n"); in shpchp_handle_attention_button()
53 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); in shpchp_handle_attention_button()
54 shpchp_get_adapter_status(p_slot, &p_slot->presence_save); in shpchp_handle_attention_button()
57 * Button pressed - See if need to TAKE ACTION!!! in shpchp_handle_attention_button()
59 ctrl_info(ctrl, "Button pressed on Slot(%s)\n", slot_name(p_slot)); in shpchp_handle_attention_button()
68 u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl) in shpchp_handle_switch_change() argument
75 ctrl_dbg(ctrl, "Switch interrupt received\n"); in shpchp_handle_switch_change()
77 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); in shpchp_handle_switch_change()
78 shpchp_get_adapter_status(p_slot, &p_slot->presence_save); in shpchp_handle_switch_change()
80 ctrl_dbg(ctrl, "Card present %x Power status %x\n", in shpchp_handle_switch_change()
81 p_slot->presence_save, p_slot->pwr_save); in shpchp_handle_switch_change()
87 ctrl_info(ctrl, "Latch open on Slot(%s)\n", slot_name(p_slot)); in shpchp_handle_switch_change()
89 if (p_slot->pwr_save && p_slot->presence_save) { in shpchp_handle_switch_change()
91 ctrl_err(ctrl, "Surprise Removal of card\n"); in shpchp_handle_switch_change()
97 ctrl_info(ctrl, "Latch close on Slot(%s)\n", slot_name(p_slot)); in shpchp_handle_switch_change()
106 u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl) in shpchp_handle_presence_change() argument
112 ctrl_dbg(ctrl, "Presence/Notify input change\n"); in shpchp_handle_presence_change()
114 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); in shpchp_handle_presence_change()
119 shpchp_get_adapter_status(p_slot, &p_slot->presence_save); in shpchp_handle_presence_change()
120 if (p_slot->presence_save) { in shpchp_handle_presence_change()
124 ctrl_info(ctrl, "Card present on Slot(%s)\n", in shpchp_handle_presence_change()
131 ctrl_info(ctrl, "Card not present on Slot(%s)\n", in shpchp_handle_presence_change()
141 u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl) in shpchp_handle_power_fault() argument
147 ctrl_dbg(ctrl, "Power fault interrupt received\n"); in shpchp_handle_power_fault()
149 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); in shpchp_handle_power_fault()
155 ctrl_info(ctrl, "Power fault cleared on Slot(%s)\n", in shpchp_handle_power_fault()
157 p_slot->status = 0x00; in shpchp_handle_power_fault()
163 ctrl_info(ctrl, "Power fault on Slot(%s)\n", slot_name(p_slot)); in shpchp_handle_power_fault()
166 p_slot->status = 0xFF; in shpchp_handle_power_fault()
167 ctrl_info(ctrl, "Power fault bit %x set\n", hp_slot); in shpchp_handle_power_fault()
178 static int change_bus_speed(struct controller *ctrl, struct slot *p_slot, in change_bus_speed() argument
183 ctrl_dbg(ctrl, "Change speed to %d\n", speed); in change_bus_speed()
186 ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n", in change_bus_speed()
193 static int fix_bus_speed(struct controller *ctrl, struct slot *pslot, in fix_bus_speed() argument
205 ctrl_err(ctrl, "Speed of bus %x and adapter %x mismatch\n", in fix_bus_speed()
214 rc = change_bus_speed(ctrl, pslot, asp); in fix_bus_speed()
217 rc = change_bus_speed(ctrl, pslot, msp); in fix_bus_speed()
223 * board_added - Called after a board has been added to the system.
235 struct controller *ctrl = p_slot->ctrl; in board_added() local
236 struct pci_bus *parent = ctrl->pci_dev->subordinate; in board_added()
238 hp_slot = p_slot->device - ctrl->slot_device_offset; in board_added()
240 ctrl_dbg(ctrl, "%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n", in board_added()
241 __func__, p_slot->device, ctrl->slot_device_offset, hp_slot); in board_added()
246 ctrl_err(ctrl, "Failed to power on slot\n"); in board_added()
247 return -1; in board_added()
250 if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) { in board_added()
253 ctrl_err(ctrl, "%s: Issue of set bus speed mode command failed\n", in board_added()
261 ctrl_err(ctrl, "Issue of Slot Enable command failed\n"); in board_added()
268 ctrl_err(ctrl, "Can't get adapter speed or bus mode mismatch\n"); in board_added()
272 bsp = ctrl->pci_dev->subordinate->cur_bus_speed; in board_added()
273 msp = ctrl->pci_dev->subordinate->max_bus_speed; in board_added()
276 if (!list_empty(&ctrl->pci_dev->subordinate->devices)) in board_added()
279 ctrl_dbg(ctrl, "%s: slots_not_empty %d, adapter_speed %d, bus_speed %d, max_bus_speed %d\n", in board_added()
283 rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, asp, bsp, msp); in board_added()
290 ctrl_err(ctrl, "Issue of Slot Enable command failed\n"); in board_added()
297 ctrl_dbg(ctrl, "%s: slot status = %x\n", __func__, p_slot->status); in board_added()
299 if (p_slot->status == 0xFF) { in board_added()
301 ctrl_dbg(ctrl, "%s: Power fault\n", __func__); in board_added()
302 p_slot->status = 0; in board_added()
307 ctrl_err(ctrl, "Cannot add device at %04x:%02x:%02x\n", in board_added()
308 pci_domain_nr(parent), p_slot->bus, p_slot->device); in board_added()
312 p_slot->status = 0; in board_added()
313 p_slot->is_a_board = 0x01; in board_added()
314 p_slot->pwr_save = 1; in board_added()
324 ctrl_err(ctrl, "%s: Issue of Slot Disable command failed\n", in board_added()
334 * remove_board - Turns off slot and LEDs
339 struct controller *ctrl = p_slot->ctrl; in remove_board() local
345 hp_slot = p_slot->device - ctrl->slot_device_offset; in remove_board()
346 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); in remove_board()
348 ctrl_dbg(ctrl, "%s: hp_slot = %d\n", __func__, hp_slot); in remove_board()
351 if (p_slot->is_a_board) in remove_board()
352 p_slot->status = 0x01; in remove_board()
357 ctrl_err(ctrl, "%s: Issue of Slot Disable command failed\n", in remove_board()
364 ctrl_err(ctrl, "Issue of Set Attention command failed\n"); in remove_board()
368 p_slot->pwr_save = 0; in remove_board()
369 p_slot->is_a_board = 0; in remove_board()
381 * shpchp_pushbutton_thread - handle pushbutton events
391 struct slot *p_slot = info->p_slot; in shpchp_pushbutton_thread()
393 mutex_lock(&p_slot->lock); in shpchp_pushbutton_thread()
394 switch (p_slot->state) { in shpchp_pushbutton_thread()
396 mutex_unlock(&p_slot->lock); in shpchp_pushbutton_thread()
398 mutex_lock(&p_slot->lock); in shpchp_pushbutton_thread()
399 p_slot->state = STATIC_STATE; in shpchp_pushbutton_thread()
402 mutex_unlock(&p_slot->lock); in shpchp_pushbutton_thread()
405 mutex_lock(&p_slot->lock); in shpchp_pushbutton_thread()
406 p_slot->state = STATIC_STATE; in shpchp_pushbutton_thread()
411 mutex_unlock(&p_slot->lock); in shpchp_pushbutton_thread()
423 ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n", in shpchp_queue_pushbutton_work()
427 info->p_slot = p_slot; in shpchp_queue_pushbutton_work()
428 INIT_WORK(&info->work, shpchp_pushbutton_thread); in shpchp_queue_pushbutton_work()
430 mutex_lock(&p_slot->lock); in shpchp_queue_pushbutton_work()
431 switch (p_slot->state) { in shpchp_queue_pushbutton_work()
433 p_slot->state = POWEROFF_STATE; in shpchp_queue_pushbutton_work()
436 p_slot->state = POWERON_STATE; in shpchp_queue_pushbutton_work()
442 queue_work(p_slot->wq, &info->work); in shpchp_queue_pushbutton_work()
444 mutex_unlock(&p_slot->lock); in shpchp_queue_pushbutton_work()
449 shpchp_get_power_status(slot, &slot->pwr_save); in update_slot_info()
450 shpchp_get_attention_status(slot, &slot->attention_save); in update_slot_info()
451 shpchp_get_latch_status(slot, &slot->latch_save); in update_slot_info()
452 shpchp_get_adapter_status(slot, &slot->presence_save); in update_slot_info()
456 * Note: This function must be called with slot->lock held
461 struct controller *ctrl = p_slot->ctrl; in handle_button_press_event() local
463 switch (p_slot->state) { in handle_button_press_event()
467 p_slot->state = BLINKINGOFF_STATE; in handle_button_press_event()
468 ctrl_info(ctrl, "PCI slot #%s - powering off due to button press\n", in handle_button_press_event()
471 p_slot->state = BLINKINGON_STATE; in handle_button_press_event()
472 ctrl_info(ctrl, "PCI slot #%s - powering on due to button press\n", in handle_button_press_event()
479 queue_delayed_work(p_slot->wq, &p_slot->work, 5*HZ); in handle_button_press_event()
486 * expires to cancel hot-add or hot-remove in handle_button_press_event()
488 ctrl_info(ctrl, "Button cancel on Slot(%s)\n", in handle_button_press_event()
490 cancel_delayed_work(&p_slot->work); in handle_button_press_event()
491 if (p_slot->state == BLINKINGOFF_STATE) in handle_button_press_event()
496 ctrl_info(ctrl, "PCI slot #%s - action canceled due to button press\n", in handle_button_press_event()
498 p_slot->state = STATIC_STATE; in handle_button_press_event()
503 * Ignore if the slot is on power-on or power-off state; in handle_button_press_event()
505 * to hot-add or hot-remove is undergoing in handle_button_press_event()
507 ctrl_info(ctrl, "Button ignore on Slot(%s)\n", in handle_button_press_event()
512 ctrl_warn(ctrl, "Not a valid state\n"); in handle_button_press_event()
520 struct slot *p_slot = info->p_slot; in interrupt_event_handler()
522 mutex_lock(&p_slot->lock); in interrupt_event_handler()
523 switch (info->event_type) { in interrupt_event_handler()
528 ctrl_dbg(p_slot->ctrl, "%s: Power fault\n", __func__); in interrupt_event_handler()
536 mutex_unlock(&p_slot->lock); in interrupt_event_handler()
545 int rc, retval = -ENODEV; in shpchp_enable_slot()
546 struct controller *ctrl = p_slot->ctrl; in shpchp_enable_slot() local
549 mutex_lock(&p_slot->ctrl->crit_sect); in shpchp_enable_slot()
552 ctrl_info(ctrl, "No adapter on slot(%s)\n", slot_name(p_slot)); in shpchp_enable_slot()
557 ctrl_info(ctrl, "Latch open on slot(%s)\n", slot_name(p_slot)); in shpchp_enable_slot()
562 ctrl_info(ctrl, "Already enabled on slot(%s)\n", in shpchp_enable_slot()
567 p_slot->is_a_board = 1; in shpchp_enable_slot()
570 shpchp_get_adapter_status(p_slot, &p_slot->presence_save); in shpchp_enable_slot()
571 shpchp_get_power_status(p_slot, &p_slot->pwr_save); in shpchp_enable_slot()
572 ctrl_dbg(ctrl, "%s: p_slot->pwr_save %x\n", __func__, p_slot->pwr_save); in shpchp_enable_slot()
575 if ((p_slot->ctrl->pci_dev->vendor == PCI_VENDOR_ID_AMD && in shpchp_enable_slot()
576 p_slot->ctrl->pci_dev->device == PCI_DEVICE_ID_AMD_POGO_7458) in shpchp_enable_slot()
577 && p_slot->ctrl->num_slots == 1) { in shpchp_enable_slot()
587 shpchp_get_adapter_status(p_slot, &p_slot->presence_save); in shpchp_enable_slot()
593 mutex_unlock(&p_slot->ctrl->crit_sect); in shpchp_enable_slot()
601 int rc, retval = -ENODEV; in shpchp_disable_slot()
602 struct controller *ctrl = p_slot->ctrl; in shpchp_disable_slot() local
604 if (!p_slot->ctrl) in shpchp_disable_slot()
605 return -ENODEV; in shpchp_disable_slot()
608 mutex_lock(&p_slot->ctrl->crit_sect); in shpchp_disable_slot()
612 ctrl_info(ctrl, "No adapter on slot(%s)\n", slot_name(p_slot)); in shpchp_disable_slot()
617 ctrl_info(ctrl, "Latch open on slot(%s)\n", slot_name(p_slot)); in shpchp_disable_slot()
622 ctrl_info(ctrl, "Already disabled on slot(%s)\n", in shpchp_disable_slot()
630 mutex_unlock(&p_slot->ctrl->crit_sect); in shpchp_disable_slot()
636 int retval = -ENODEV; in shpchp_sysfs_enable_slot()
637 struct controller *ctrl = p_slot->ctrl; in shpchp_sysfs_enable_slot() local
639 mutex_lock(&p_slot->lock); in shpchp_sysfs_enable_slot()
640 switch (p_slot->state) { in shpchp_sysfs_enable_slot()
642 cancel_delayed_work(&p_slot->work); in shpchp_sysfs_enable_slot()
645 p_slot->state = POWERON_STATE; in shpchp_sysfs_enable_slot()
646 mutex_unlock(&p_slot->lock); in shpchp_sysfs_enable_slot()
648 mutex_lock(&p_slot->lock); in shpchp_sysfs_enable_slot()
649 p_slot->state = STATIC_STATE; in shpchp_sysfs_enable_slot()
652 ctrl_info(ctrl, "Slot %s is already in powering on state\n", in shpchp_sysfs_enable_slot()
657 ctrl_info(ctrl, "Already enabled on slot %s\n", in shpchp_sysfs_enable_slot()
661 ctrl_err(ctrl, "Not a valid state on slot %s\n", in shpchp_sysfs_enable_slot()
665 mutex_unlock(&p_slot->lock); in shpchp_sysfs_enable_slot()
672 int retval = -ENODEV; in shpchp_sysfs_disable_slot()
673 struct controller *ctrl = p_slot->ctrl; in shpchp_sysfs_disable_slot() local
675 mutex_lock(&p_slot->lock); in shpchp_sysfs_disable_slot()
676 switch (p_slot->state) { in shpchp_sysfs_disable_slot()
678 cancel_delayed_work(&p_slot->work); in shpchp_sysfs_disable_slot()
681 p_slot->state = POWEROFF_STATE; in shpchp_sysfs_disable_slot()
682 mutex_unlock(&p_slot->lock); in shpchp_sysfs_disable_slot()
684 mutex_lock(&p_slot->lock); in shpchp_sysfs_disable_slot()
685 p_slot->state = STATIC_STATE; in shpchp_sysfs_disable_slot()
688 ctrl_info(ctrl, "Slot %s is already in powering off state\n", in shpchp_sysfs_disable_slot()
693 ctrl_info(ctrl, "Already disabled on slot %s\n", in shpchp_sysfs_disable_slot()
697 ctrl_err(ctrl, "Not a valid state on slot %s\n", in shpchp_sysfs_disable_slot()
701 mutex_unlock(&p_slot->lock); in shpchp_sysfs_disable_slot()