2 * Standard Hot Plug Controller Driver
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/slab.h>
35 #include <linux/workqueue.h>
36 #include <linux/interrupt.h>
37 #include <linux/delay.h>
38 #include <linux/wait.h>
39 #include <linux/smp_lock.h>
40 #include <linux/pci.h>
44 static void interrupt_event_handler(struct controller *ctrl);
46 static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
47 static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
48 static int event_finished;
49 static unsigned long pushbutton_pending; /* = 0 */
51 u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id)
53 struct controller *ctrl = (struct controller *) inst_id;
57 struct event_info *taskInfo;
59 /* Attention Button Change */
60 dbg("shpchp: Attention button interrupt received.\n");
62 /* This is the structure that tells the worker thread what to do */
63 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
64 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
66 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
67 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
69 ctrl->next_event = (ctrl->next_event + 1) % 10;
70 taskInfo->hp_slot = hp_slot;
75 * Button pressed - See if need to TAKE ACTION!!!
77 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot);
78 taskInfo->event_type = INT_BUTTON_PRESS;
80 if ((p_slot->state == BLINKINGON_STATE)
81 || (p_slot->state == BLINKINGOFF_STATE)) {
82 /* Cancel if we are still blinking; this means that we press the
83 * attention again before the 5 sec. limit expires to cancel hot-add
86 taskInfo->event_type = INT_BUTTON_CANCEL;
87 info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot);
88 } else if ((p_slot->state == POWERON_STATE)
89 || (p_slot->state == POWEROFF_STATE)) {
90 /* Ignore if the slot is on power-on or power-off state; this
91 * means that the previous attention button action to hot-add or
92 * hot-remove is undergoing
94 taskInfo->event_type = INT_BUTTON_IGNORE;
95 info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot);
99 up(&event_semaphore); /* signal event thread that new event is posted */
105 u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
107 struct controller *ctrl = (struct controller *) inst_id;
111 struct event_info *taskInfo;
114 dbg("shpchp: Switch interrupt received.\n");
116 /* This is the structure that tells the worker thread
119 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
120 ctrl->next_event = (ctrl->next_event + 1) % 10;
121 taskInfo->hp_slot = hp_slot;
124 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
125 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
126 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
127 dbg("%s: Card present %x Power status %x\n", __FUNCTION__,
128 p_slot->presence_save, p_slot->pwr_save);
134 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
135 taskInfo->event_type = INT_SWITCH_OPEN;
136 if (p_slot->pwr_save && p_slot->presence_save) {
137 taskInfo->event_type = INT_POWER_FAULT;
138 err("Surprise Removal of card\n");
144 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
145 taskInfo->event_type = INT_SWITCH_CLOSE;
149 up(&event_semaphore); /* signal event thread that new event is posted */
154 u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
156 struct controller *ctrl = (struct controller *) inst_id;
160 struct event_info *taskInfo;
162 /* Presence Change */
163 dbg("shpchp: Presence/Notify input change.\n");
165 /* This is the structure that tells the worker thread
168 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
169 ctrl->next_event = (ctrl->next_event + 1) % 10;
170 taskInfo->hp_slot = hp_slot;
173 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
176 * Save the presence state
178 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
179 if (p_slot->presence_save) {
183 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot);
184 taskInfo->event_type = INT_PRESENCE_ON;
189 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot);
190 taskInfo->event_type = INT_PRESENCE_OFF;
194 up(&event_semaphore); /* signal event thread that new event is posted */
199 u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
201 struct controller *ctrl = (struct controller *) inst_id;
204 struct event_info *taskInfo;
207 dbg("shpchp: Power fault interrupt received.\n");
209 /* This is the structure that tells the worker thread
212 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
213 ctrl->next_event = (ctrl->next_event + 1) % 10;
214 taskInfo->hp_slot = hp_slot;
217 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
219 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
221 * Power fault Cleared
223 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
224 p_slot->status = 0x00;
225 taskInfo->event_type = INT_POWER_FAULT_CLEAR;
230 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
231 taskInfo->event_type = INT_POWER_FAULT;
232 /* set power fault status for this board */
233 p_slot->status = 0xFF;
234 info("power fault bit %x set\n", hp_slot);
237 up(&event_semaphore); /* signal event thread that new event is posted */
242 /* The following routines constitute the bulk of the
243 hotplug controller logic
245 static u32 change_bus_speed(struct controller *ctrl, struct slot *p_slot, enum pci_bus_speed speed)
249 dbg("%s: change to speed %d\n", __FUNCTION__, speed);
250 down(&ctrl->crit_sect);
251 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) {
252 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
253 up(&ctrl->crit_sect);
254 return WRONG_BUS_FREQUENCY;
256 wait_for_ctrl_irq (ctrl);
258 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
259 err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
261 err("%s: Error code (%d)\n", __FUNCTION__, rc);
262 up(&ctrl->crit_sect);
263 return WRONG_BUS_FREQUENCY;
265 up(&ctrl->crit_sect);
269 static u32 fix_bus_speed(struct controller *ctrl, struct slot *pslot, u8 flag,
270 enum pci_bus_speed asp, enum pci_bus_speed bsp, enum pci_bus_speed msp)
274 if (flag != 0) { /* Other slots on the same bus are occupied */
276 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bsp, asp);
277 return WRONG_BUS_FREQUENCY;
280 /* Other slots on the same bus are empty */
282 /* if adapter_speed >= bus_speed, do nothing */
285 * Try to lower bus speed to accommodate the adapter if other slots
286 * on the same controller are empty
288 if ((rc = change_bus_speed(ctrl, pslot, asp)))
293 if ((rc = change_bus_speed(ctrl, pslot, asp)))
296 if ((rc = change_bus_speed(ctrl, pslot, msp)))
305 * board_added - Called after a board has been added to the system.
307 * Turns power on for the board
311 static u32 board_added(struct slot *p_slot)
314 u8 slots_not_empty = 0;
316 enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed;
318 struct controller *ctrl = p_slot->ctrl;
320 hp_slot = p_slot->device - ctrl->slot_device_offset;
322 dbg("%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n",
323 __FUNCTION__, p_slot->device,
324 ctrl->slot_device_offset, hp_slot);
326 /* Wait for exclusive access to hardware */
327 down(&ctrl->crit_sect);
329 /* Power on slot without connecting to bus */
330 rc = p_slot->hpc_ops->power_on_slot(p_slot);
332 err("%s: Failed to power on slot\n", __FUNCTION__);
333 /* Done with exclusive hardware access */
334 up(&ctrl->crit_sect);
338 /* Wait for the command to complete */
339 wait_for_ctrl_irq (ctrl);
341 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
343 err("%s: Failed to power on slot, error code(%d)\n", __FUNCTION__, rc);
344 /* Done with exclusive hardware access */
345 up(&ctrl->crit_sect);
350 if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) {
352 return WRONG_BUS_FREQUENCY;
354 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) {
355 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
356 up(&ctrl->crit_sect);
357 return WRONG_BUS_FREQUENCY;
359 wait_for_ctrl_irq (ctrl);
361 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
362 err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
364 err("%s: Error code (%d)\n", __FUNCTION__, rc);
365 up(&ctrl->crit_sect);
366 return WRONG_BUS_FREQUENCY;
368 /* turn on board, blink green LED, turn off Amber LED */
369 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
370 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
371 up(&ctrl->crit_sect);
374 wait_for_ctrl_irq (ctrl);
376 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
377 err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
378 up(&ctrl->crit_sect);
383 rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &adapter_speed);
384 /* 0 = PCI 33Mhz, 1 = PCI 66 Mhz, 2 = PCI-X 66 PA, 4 = PCI-X 66 ECC, */
385 /* 5 = PCI-X 133 PA, 7 = PCI-X 133 ECC, 0xa = PCI-X 133 Mhz 266, */
386 /* 0xd = PCI-X 133 Mhz 533 */
387 /* This encoding is different from the one used in cur_bus_speed & */
390 if (rc || adapter_speed == PCI_SPEED_UNKNOWN) {
391 err("%s: Can't get adapter speed or bus mode mismatch\n", __FUNCTION__);
392 /* Done with exclusive hardware access */
393 up(&ctrl->crit_sect);
394 return WRONG_BUS_FREQUENCY;
397 rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bus_speed);
398 if (rc || bus_speed == PCI_SPEED_UNKNOWN) {
399 err("%s: Can't get bus operation speed\n", __FUNCTION__);
400 /* Done with exclusive hardware access */
401 up(&ctrl->crit_sect);
402 return WRONG_BUS_FREQUENCY;
405 rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed);
406 if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) {
407 err("%s: Can't get max bus operation speed\n", __FUNCTION__);
408 max_bus_speed = bus_speed;
411 /* Done with exclusive hardware access */
412 up(&ctrl->crit_sect);
414 if ((rc = p_slot->hpc_ops->get_prog_int(p_slot, &pi))) {
415 err("%s: Can't get controller programming interface, set it to 1\n", __FUNCTION__);
419 /* Check if there are other slots or devices on the same bus */
420 if (!list_empty(&ctrl->pci_dev->subordinate->devices))
423 dbg("%s: slots_not_empty %d, pi %d\n", __FUNCTION__,
424 slots_not_empty, pi);
425 dbg("adapter_speed %d, bus_speed %d, max_bus_speed %d\n",
426 adapter_speed, bus_speed, max_bus_speed);
429 dbg("%s: In PI = %d\n", __FUNCTION__, pi);
430 if ((rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode))) {
431 err("%s: Can't get Mode1_ECC, set mode to 0\n", __FUNCTION__);
435 switch (adapter_speed) {
436 case PCI_SPEED_133MHz_PCIX_533:
437 case PCI_SPEED_133MHz_PCIX_266:
438 if ((bus_speed != adapter_speed) &&
439 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
442 case PCI_SPEED_133MHz_PCIX_ECC:
443 case PCI_SPEED_133MHz_PCIX:
444 if (mode) { /* Bus - Mode 1 ECC */
445 if ((bus_speed != 0x7) &&
446 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
449 if ((bus_speed != 0x4) &&
450 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
454 case PCI_SPEED_66MHz_PCIX_ECC:
455 case PCI_SPEED_66MHz_PCIX:
456 if (mode) { /* Bus - Mode 1 ECC */
457 if ((bus_speed != 0x5) &&
458 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
461 if ((bus_speed != 0x2) &&
462 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
466 case PCI_SPEED_66MHz:
467 if ((bus_speed != 0x1) &&
468 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
471 case PCI_SPEED_33MHz:
472 if (bus_speed > 0x0) {
473 if (slots_not_empty == 0) {
474 if ((rc = change_bus_speed(ctrl, p_slot, adapter_speed)))
477 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
478 return WRONG_BUS_FREQUENCY;
483 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
484 return WRONG_BUS_FREQUENCY;
487 /* If adpater_speed == bus_speed, nothing to do here */
488 dbg("%s: In PI = %d\n", __FUNCTION__, pi);
489 if ((adapter_speed != bus_speed) &&
490 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
494 down(&ctrl->crit_sect);
495 /* turn on board, blink green LED, turn off Amber LED */
496 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
497 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
498 up(&ctrl->crit_sect);
501 wait_for_ctrl_irq (ctrl);
503 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
504 err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
505 up(&ctrl->crit_sect);
509 up(&ctrl->crit_sect);
511 /* Wait for ~1 second */
512 dbg("%s: before long_delay\n", __FUNCTION__);
513 wait_for_ctrl_irq (ctrl);
514 dbg("%s: after long_delay\n", __FUNCTION__);
516 dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status);
517 /* Check for a power fault */
518 if (p_slot->status == 0xFF) {
519 /* power fault occurred, but it was benign */
520 dbg("%s: power fault\n", __FUNCTION__);
526 if (shpchp_configure_device(p_slot)) {
527 err("Cannot add device at 0x%x:0x%x\n", p_slot->bus,
533 p_slot->is_a_board = 0x01;
534 p_slot->pwr_save = 1;
536 /* Wait for exclusive access to hardware */
537 down(&ctrl->crit_sect);
539 p_slot->hpc_ops->green_led_on(p_slot);
541 /* Wait for the command to complete */
542 wait_for_ctrl_irq (ctrl);
544 /* Done with exclusive hardware access */
545 up(&ctrl->crit_sect);
550 /* Wait for exclusive access to hardware */
551 down(&ctrl->crit_sect);
553 /* turn off slot, turn on Amber LED, turn off Green LED */
554 rc = p_slot->hpc_ops->slot_disable(p_slot);
556 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
557 /* Done with exclusive hardware access */
558 up(&ctrl->crit_sect);
561 /* Wait for the command to complete */
562 wait_for_ctrl_irq (ctrl);
564 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
566 err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
567 /* Done with exclusive hardware access */
568 up(&ctrl->crit_sect);
572 /* Done with exclusive hardware access */
573 up(&ctrl->crit_sect);
580 * remove_board - Turns off slot and LED's
583 static u32 remove_board(struct slot *p_slot)
585 struct controller *ctrl = p_slot->ctrl;
589 if (shpchp_unconfigure_device(p_slot))
592 hp_slot = p_slot->device - ctrl->slot_device_offset;
593 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
595 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
597 /* Change status to shutdown */
598 if (p_slot->is_a_board)
599 p_slot->status = 0x01;
601 /* Wait for exclusive access to hardware */
602 down(&ctrl->crit_sect);
604 /* turn off slot, turn on Amber LED, turn off Green LED */
605 rc = p_slot->hpc_ops->slot_disable(p_slot);
607 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
608 /* Done with exclusive hardware access */
609 up(&ctrl->crit_sect);
612 /* Wait for the command to complete */
613 wait_for_ctrl_irq (ctrl);
615 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
617 err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
618 /* Done with exclusive hardware access */
619 up(&ctrl->crit_sect);
623 rc = p_slot->hpc_ops->set_attention_status(p_slot, 0);
625 err("%s: Issue of Set Attention command failed\n", __FUNCTION__);
626 /* Done with exclusive hardware access */
627 up(&ctrl->crit_sect);
630 /* Wait for the command to complete */
631 wait_for_ctrl_irq (ctrl);
633 /* Done with exclusive hardware access */
634 up(&ctrl->crit_sect);
636 p_slot->pwr_save = 0;
637 p_slot->is_a_board = 0;
643 static void pushbutton_helper_thread (unsigned long data)
645 pushbutton_pending = data;
647 up(&event_semaphore);
652 * shpchp_pushbutton_thread
654 * Scheduled procedure to handle blocking stuff for the pushbuttons
655 * Handles all pending events and exits.
658 static void shpchp_pushbutton_thread (unsigned long slot)
660 struct slot *p_slot = (struct slot *) slot;
663 pushbutton_pending = 0;
666 dbg("%s: Error! slot NULL\n", __FUNCTION__);
670 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
672 p_slot->state = POWEROFF_STATE;
673 dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
675 shpchp_disable_slot(p_slot);
676 p_slot->state = STATIC_STATE;
678 p_slot->state = POWERON_STATE;
679 dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
681 if (shpchp_enable_slot(p_slot)) {
682 /* Wait for exclusive access to hardware */
683 down(&p_slot->ctrl->crit_sect);
685 p_slot->hpc_ops->green_led_off(p_slot);
687 /* Wait for the command to complete */
688 wait_for_ctrl_irq (p_slot->ctrl);
690 /* Done with exclusive hardware access */
691 up(&p_slot->ctrl->crit_sect);
693 p_slot->state = STATIC_STATE;
700 /* this is the main worker thread */
701 static int event_thread(void* data)
703 struct controller *ctrl;
705 daemonize("shpchpd_event");
709 dbg("!!!!event_thread sleeping\n");
710 down_interruptible (&event_semaphore);
711 dbg("event_thread woken finished = %d\n", event_finished);
712 if (event_finished || signal_pending(current))
715 if (pushbutton_pending)
716 shpchp_pushbutton_thread(pushbutton_pending);
718 for (ctrl = shpchp_ctrl_list; ctrl; ctrl=ctrl->next)
719 interrupt_event_handler(ctrl);
721 dbg("event_thread signals exit\n");
726 int shpchp_event_start_thread (void)
730 /* initialize our semaphores */
731 init_MUTEX_LOCKED(&event_exit);
734 init_MUTEX_LOCKED(&event_semaphore);
735 pid = kernel_thread(event_thread, NULL, 0);
738 err ("Can't start up our event thread\n");
741 dbg("Our event thread pid = %d\n", pid);
746 void shpchp_event_stop_thread (void)
749 dbg("event_thread finish command given\n");
750 up(&event_semaphore);
751 dbg("wait for event_thread to exit\n");
756 static int update_slot_info (struct slot *slot)
758 struct hotplug_slot_info *info;
761 info = kmalloc(sizeof(*info), GFP_KERNEL);
765 slot->hpc_ops->get_power_status(slot, &(info->power_status));
766 slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
767 slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
768 slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
770 result = pci_hp_change_slot_info(slot->hotplug_slot, info);
775 static void interrupt_event_handler(struct controller *ctrl)
783 dbg("%s:\n", __FUNCTION__);
787 for (loop = 0; loop < 10; loop++) {
788 if (ctrl->event_queue[loop].event_type != 0) {
789 dbg("%s:loop %x event_type %x\n", __FUNCTION__, loop,
790 ctrl->event_queue[loop].event_type);
791 hp_slot = ctrl->event_queue[loop].hp_slot;
793 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
795 dbg("%s: hp_slot %d, p_slot %p\n",
796 __FUNCTION__, hp_slot, p_slot);
798 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
799 dbg("%s: button cancel\n", __FUNCTION__);
800 del_timer(&p_slot->task_event);
802 switch (p_slot->state) {
803 case BLINKINGOFF_STATE:
804 /* Wait for exclusive access to hardware */
805 down(&ctrl->crit_sect);
807 p_slot->hpc_ops->green_led_on(p_slot);
808 /* Wait for the command to complete */
809 wait_for_ctrl_irq (ctrl);
811 p_slot->hpc_ops->set_attention_status(p_slot, 0);
813 /* Wait for the command to complete */
814 wait_for_ctrl_irq (ctrl);
816 /* Done with exclusive hardware access */
817 up(&ctrl->crit_sect);
819 case BLINKINGON_STATE:
820 /* Wait for exclusive access to hardware */
821 down(&ctrl->crit_sect);
823 p_slot->hpc_ops->green_led_off(p_slot);
824 /* Wait for the command to complete */
825 wait_for_ctrl_irq (ctrl);
827 p_slot->hpc_ops->set_attention_status(p_slot, 0);
828 /* Wait for the command to complete */
829 wait_for_ctrl_irq (ctrl);
831 /* Done with exclusive hardware access */
832 up(&ctrl->crit_sect);
836 warn("Not a valid state\n");
839 info(msg_button_cancel, p_slot->number);
840 p_slot->state = STATIC_STATE;
841 } else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
842 /* Button Pressed (No action on 1st press...) */
843 dbg("%s: Button pressed\n", __FUNCTION__);
845 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
848 dbg("%s: slot is on\n", __FUNCTION__);
849 p_slot->state = BLINKINGOFF_STATE;
850 info(msg_button_off, p_slot->number);
853 dbg("%s: slot is off\n", __FUNCTION__);
854 p_slot->state = BLINKINGON_STATE;
855 info(msg_button_on, p_slot->number);
858 /* Wait for exclusive access to hardware */
859 down(&ctrl->crit_sect);
861 /* blink green LED and turn off amber */
862 p_slot->hpc_ops->green_led_blink(p_slot);
863 /* Wait for the command to complete */
864 wait_for_ctrl_irq (ctrl);
866 p_slot->hpc_ops->set_attention_status(p_slot, 0);
868 /* Wait for the command to complete */
869 wait_for_ctrl_irq (ctrl);
871 /* Done with exclusive hardware access */
872 up(&ctrl->crit_sect);
874 init_timer(&p_slot->task_event);
875 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
876 p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
877 p_slot->task_event.data = (unsigned long) p_slot;
879 dbg("%s: add_timer p_slot = %p\n", __FUNCTION__,(void *) p_slot);
880 add_timer(&p_slot->task_event);
881 } else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
882 /***********POWER FAULT********************/
883 dbg("%s: power fault\n", __FUNCTION__);
884 /* Wait for exclusive access to hardware */
885 down(&ctrl->crit_sect);
887 p_slot->hpc_ops->set_attention_status(p_slot, 1);
888 /* Wait for the command to complete */
889 wait_for_ctrl_irq (ctrl);
891 p_slot->hpc_ops->green_led_off(p_slot);
892 /* Wait for the command to complete */
893 wait_for_ctrl_irq (ctrl);
895 /* Done with exclusive hardware access */
896 up(&ctrl->crit_sect);
898 /* refresh notification */
900 update_slot_info(p_slot);
903 ctrl->event_queue[loop].event_type = 0;
907 } /* End of FOR loop */
914 int shpchp_enable_slot (struct slot *p_slot)
919 /* Check to see if (latch closed, card present, power off) */
920 down(&p_slot->ctrl->crit_sect);
921 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
922 if (rc || !getstatus) {
923 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
924 up(&p_slot->ctrl->crit_sect);
927 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
928 if (rc || getstatus) {
929 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
930 up(&p_slot->ctrl->crit_sect);
933 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
934 if (rc || getstatus) {
935 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
936 up(&p_slot->ctrl->crit_sect);
939 up(&p_slot->ctrl->crit_sect);
941 p_slot->is_a_board = 1;
943 /* We have to save the presence info for these slots */
944 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
945 p_slot->hpc_ops->get_power_status(p_slot, &(p_slot->pwr_save));
946 dbg("%s: p_slot->pwr_save %x\n", __FUNCTION__, p_slot->pwr_save);
947 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
949 rc = board_added(p_slot);
951 p_slot->hpc_ops->get_adapter_status(p_slot,
952 &(p_slot->presence_save));
953 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
956 update_slot_info(p_slot);
961 int shpchp_disable_slot (struct slot *p_slot)
970 /* Check to see if (latch closed, card present, power on) */
971 down(&p_slot->ctrl->crit_sect);
973 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
974 if (ret || !getstatus) {
975 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
976 up(&p_slot->ctrl->crit_sect);
979 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
980 if (ret || getstatus) {
981 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
982 up(&p_slot->ctrl->crit_sect);
985 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
986 if (ret || !getstatus) {
987 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
988 up(&p_slot->ctrl->crit_sect);
991 up(&p_slot->ctrl->crit_sect);
993 rc = remove_board(p_slot);
994 update_slot_info(p_slot);