[PATCH] s390: dasd open counter
[linux-2.6.22.y-op.git] / drivers / pci / hotplug / pciehp_ctrl.c
blob83c4b865718a15239361b9f314391b9f31d32de4
1 /*
2 * PCI Express 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
9 * All rights reserved.
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
20 * details.
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/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/smp_lock.h>
34 #include <linux/pci.h>
35 #include "../pci.h"
36 #include "pciehp.h"
38 static void interrupt_event_handler(struct controller *ctrl);
40 static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
41 static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
42 static int event_finished;
43 static unsigned long pushbutton_pending; /* = 0 */
44 static unsigned long surprise_rm_pending; /* = 0 */
46 u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
48 struct controller *ctrl = (struct controller *) inst_id;
49 struct slot *p_slot;
50 u8 rc = 0;
51 u8 getstatus;
52 struct event_info *taskInfo;
54 /* Attention Button Change */
55 dbg("pciehp: Attention button interrupt received.\n");
57 /* This is the structure that tells the worker thread what to do */
58 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
59 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
61 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
63 ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
64 taskInfo->hp_slot = hp_slot;
66 rc++;
69 * Button pressed - See if need to TAKE ACTION!!!
71 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot);
72 taskInfo->event_type = INT_BUTTON_PRESS;
74 if ((p_slot->state == BLINKINGON_STATE)
75 || (p_slot->state == BLINKINGOFF_STATE)) {
76 /* Cancel if we are still blinking; this means that we press the
77 * attention again before the 5 sec. limit expires to cancel hot-add
78 * or hot-remove
80 taskInfo->event_type = INT_BUTTON_CANCEL;
81 info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot);
82 } else if ((p_slot->state == POWERON_STATE)
83 || (p_slot->state == POWEROFF_STATE)) {
84 /* Ignore if the slot is on power-on or power-off state; this
85 * means that the previous attention button action to hot-add or
86 * hot-remove is undergoing
88 taskInfo->event_type = INT_BUTTON_IGNORE;
89 info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot);
92 if (rc)
93 up(&event_semaphore); /* signal event thread that new event is posted */
95 return 0;
99 u8 pciehp_handle_switch_change(u8 hp_slot, void *inst_id)
101 struct controller *ctrl = (struct controller *) inst_id;
102 struct slot *p_slot;
103 u8 rc = 0;
104 u8 getstatus;
105 struct event_info *taskInfo;
107 /* Switch Change */
108 dbg("pciehp: Switch interrupt received.\n");
110 /* This is the structure that tells the worker thread
111 * what to do
113 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
114 ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
115 taskInfo->hp_slot = hp_slot;
117 rc++;
118 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
119 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
121 if (getstatus) {
123 * Switch opened
125 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
126 taskInfo->event_type = INT_SWITCH_OPEN;
127 } else {
129 * Switch closed
131 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
132 taskInfo->event_type = INT_SWITCH_CLOSE;
135 if (rc)
136 up(&event_semaphore); /* signal event thread that new event is posted */
138 return rc;
141 u8 pciehp_handle_presence_change(u8 hp_slot, void *inst_id)
143 struct controller *ctrl = (struct controller *) inst_id;
144 struct slot *p_slot;
145 u8 presence_save, rc = 0;
146 struct event_info *taskInfo;
148 /* Presence Change */
149 dbg("pciehp: Presence/Notify input change.\n");
151 /* This is the structure that tells the worker thread
152 * what to do
154 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
155 ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
156 taskInfo->hp_slot = hp_slot;
158 rc++;
159 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
161 /* Switch is open, assume a presence change
162 * Save the presence state
164 p_slot->hpc_ops->get_adapter_status(p_slot, &presence_save);
165 if (presence_save) {
167 * Card Present
169 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot);
170 taskInfo->event_type = INT_PRESENCE_ON;
171 } else {
173 * Not Present
175 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot);
176 taskInfo->event_type = INT_PRESENCE_OFF;
179 if (rc)
180 up(&event_semaphore); /* signal event thread that new event is posted */
182 return rc;
185 u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
187 struct controller *ctrl = (struct controller *) inst_id;
188 struct slot *p_slot;
189 u8 rc = 0;
190 struct event_info *taskInfo;
192 /* power fault */
193 dbg("pciehp: Power fault interrupt received.\n");
195 /* this is the structure that tells the worker thread
196 * what to do
198 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
199 ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
200 taskInfo->hp_slot = hp_slot;
202 rc++;
203 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
205 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
207 * power fault Cleared
209 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
210 taskInfo->event_type = INT_POWER_FAULT_CLEAR;
211 } else {
213 * power fault
215 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
216 taskInfo->event_type = INT_POWER_FAULT;
217 info("power fault bit %x set\n", hp_slot);
219 if (rc)
220 up(&event_semaphore); /* signal event thread that new event is posted */
222 return rc;
225 /* The following routines constitute the bulk of the
226 hotplug controller logic
229 static void set_slot_off(struct controller *ctrl, struct slot * pslot)
231 /* Wait for exclusive access to hardware */
232 down(&ctrl->crit_sect);
234 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
235 if (POWER_CTRL(ctrl->ctrlcap)) {
236 if (pslot->hpc_ops->power_off_slot(pslot)) {
237 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
238 up(&ctrl->crit_sect);
239 return;
241 wait_for_ctrl_irq (ctrl);
244 if (PWR_LED(ctrl->ctrlcap)) {
245 pslot->hpc_ops->green_led_off(pslot);
246 wait_for_ctrl_irq (ctrl);
249 if (ATTN_LED(ctrl->ctrlcap)) {
250 if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
251 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
252 up(&ctrl->crit_sect);
253 return;
255 wait_for_ctrl_irq (ctrl);
258 /* Done with exclusive hardware access */
259 up(&ctrl->crit_sect);
263 * board_added - Called after a board has been added to the system.
265 * Turns power on for the board
266 * Configures board
269 static int board_added(struct slot *p_slot)
271 u8 hp_slot;
272 int rc = 0;
273 struct controller *ctrl = p_slot->ctrl;
275 hp_slot = p_slot->device - ctrl->slot_device_offset;
277 dbg("%s: slot device, slot offset, hp slot = %d, %d ,%d\n",
278 __FUNCTION__, p_slot->device,
279 ctrl->slot_device_offset, hp_slot);
281 /* Wait for exclusive access to hardware */
282 down(&ctrl->crit_sect);
284 if (POWER_CTRL(ctrl->ctrlcap)) {
285 /* Power on slot */
286 rc = p_slot->hpc_ops->power_on_slot(p_slot);
287 if (rc) {
288 up(&ctrl->crit_sect);
289 return -1;
292 /* Wait for the command to complete */
293 wait_for_ctrl_irq (ctrl);
296 if (PWR_LED(ctrl->ctrlcap)) {
297 p_slot->hpc_ops->green_led_blink(p_slot);
299 /* Wait for the command to complete */
300 wait_for_ctrl_irq (ctrl);
303 /* Done with exclusive hardware access */
304 up(&ctrl->crit_sect);
306 /* Wait for ~1 second */
307 wait_for_ctrl_irq (ctrl);
309 /* Check link training status */
310 rc = p_slot->hpc_ops->check_lnk_status(ctrl);
311 if (rc) {
312 err("%s: Failed to check link status\n", __FUNCTION__);
313 set_slot_off(ctrl, p_slot);
314 return rc;
317 /* Check for a power fault */
318 if (p_slot->hpc_ops->query_power_fault(p_slot)) {
319 dbg("%s: power fault detected\n", __FUNCTION__);
320 rc = POWER_FAILURE;
321 goto err_exit;
324 rc = pciehp_configure_device(p_slot);
325 if (rc) {
326 err("Cannot add device 0x%x:%x\n", p_slot->bus,
327 p_slot->device);
328 goto err_exit;
332 * Some PCI Express root ports require fixup after hot-plug operation.
334 if (pcie_mch_quirk)
335 pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
336 if (PWR_LED(ctrl->ctrlcap)) {
337 /* Wait for exclusive access to hardware */
338 down(&ctrl->crit_sect);
340 p_slot->hpc_ops->green_led_on(p_slot);
342 /* Wait for the command to complete */
343 wait_for_ctrl_irq (ctrl);
345 /* Done with exclusive hardware access */
346 up(&ctrl->crit_sect);
348 return 0;
350 err_exit:
351 set_slot_off(ctrl, p_slot);
352 return -1;
357 * remove_board - Turns off slot and LED's
360 static int remove_board(struct slot *p_slot)
362 u8 device;
363 u8 hp_slot;
364 int rc;
365 struct controller *ctrl = p_slot->ctrl;
367 if (pciehp_unconfigure_device(p_slot))
368 return 1;
370 device = p_slot->device;
372 hp_slot = p_slot->device - ctrl->slot_device_offset;
373 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
375 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
377 /* Wait for exclusive access to hardware */
378 down(&ctrl->crit_sect);
380 if (POWER_CTRL(ctrl->ctrlcap)) {
381 /* power off slot */
382 rc = p_slot->hpc_ops->power_off_slot(p_slot);
383 if (rc) {
384 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
385 up(&ctrl->crit_sect);
386 return rc;
388 /* Wait for the command to complete */
389 wait_for_ctrl_irq (ctrl);
392 if (PWR_LED(ctrl->ctrlcap)) {
393 /* turn off Green LED */
394 p_slot->hpc_ops->green_led_off(p_slot);
396 /* Wait for the command to complete */
397 wait_for_ctrl_irq (ctrl);
400 /* Done with exclusive hardware access */
401 up(&ctrl->crit_sect);
403 return 0;
407 static void pushbutton_helper_thread(unsigned long data)
409 pushbutton_pending = data;
411 up(&event_semaphore);
415 * pciehp_pushbutton_thread
417 * Scheduled procedure to handle blocking stuff for the pushbuttons
418 * Handles all pending events and exits.
421 static void pciehp_pushbutton_thread(unsigned long slot)
423 struct slot *p_slot = (struct slot *) slot;
424 u8 getstatus;
426 pushbutton_pending = 0;
428 if (!p_slot) {
429 dbg("%s: Error! slot NULL\n", __FUNCTION__);
430 return;
433 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
434 if (getstatus) {
435 p_slot->state = POWEROFF_STATE;
436 dbg("%s: disabling bus:device(%x:%x)\n", __FUNCTION__,
437 p_slot->bus, p_slot->device);
439 pciehp_disable_slot(p_slot);
440 p_slot->state = STATIC_STATE;
441 } else {
442 p_slot->state = POWERON_STATE;
443 dbg("%s: adding bus:device(%x:%x)\n", __FUNCTION__,
444 p_slot->bus, p_slot->device);
446 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
447 /* Wait for exclusive access to hardware */
448 down(&p_slot->ctrl->crit_sect);
450 p_slot->hpc_ops->green_led_off(p_slot);
452 /* Wait for the command to complete */
453 wait_for_ctrl_irq (p_slot->ctrl);
455 /* Done with exclusive hardware access */
456 up(&p_slot->ctrl->crit_sect);
458 p_slot->state = STATIC_STATE;
461 return;
465 * pciehp_surprise_rm_thread
467 * Scheduled procedure to handle blocking stuff for the surprise removal
468 * Handles all pending events and exits.
471 static void pciehp_surprise_rm_thread(unsigned long slot)
473 struct slot *p_slot = (struct slot *) slot;
474 u8 getstatus;
476 surprise_rm_pending = 0;
478 if (!p_slot) {
479 dbg("%s: Error! slot NULL\n", __FUNCTION__);
480 return;
483 p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
484 if (!getstatus) {
485 p_slot->state = POWEROFF_STATE;
486 dbg("%s: removing bus:device(%x:%x)\n",
487 __FUNCTION__, p_slot->bus, p_slot->device);
489 pciehp_disable_slot(p_slot);
490 p_slot->state = STATIC_STATE;
491 } else {
492 p_slot->state = POWERON_STATE;
493 dbg("%s: adding bus:device(%x:%x)\n",
494 __FUNCTION__, p_slot->bus, p_slot->device);
496 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
497 /* Wait for exclusive access to hardware */
498 down(&p_slot->ctrl->crit_sect);
500 p_slot->hpc_ops->green_led_off(p_slot);
502 /* Wait for the command to complete */
503 wait_for_ctrl_irq (p_slot->ctrl);
505 /* Done with exclusive hardware access */
506 up(&p_slot->ctrl->crit_sect);
508 p_slot->state = STATIC_STATE;
511 return;
516 /* this is the main worker thread */
517 static int event_thread(void* data)
519 struct controller *ctrl;
520 lock_kernel();
521 daemonize("pciehpd_event");
523 unlock_kernel();
525 while (1) {
526 dbg("!!!!event_thread sleeping\n");
527 down_interruptible (&event_semaphore);
528 dbg("event_thread woken finished = %d\n", event_finished);
529 if (event_finished || signal_pending(current))
530 break;
531 /* Do stuff here */
532 if (pushbutton_pending)
533 pciehp_pushbutton_thread(pushbutton_pending);
534 else if (surprise_rm_pending)
535 pciehp_surprise_rm_thread(surprise_rm_pending);
536 else
537 for (ctrl = pciehp_ctrl_list; ctrl; ctrl=ctrl->next)
538 interrupt_event_handler(ctrl);
540 dbg("event_thread signals exit\n");
541 up(&event_exit);
542 return 0;
545 int pciehp_event_start_thread(void)
547 int pid;
549 /* initialize our semaphores */
550 init_MUTEX_LOCKED(&event_exit);
551 event_finished=0;
553 init_MUTEX_LOCKED(&event_semaphore);
554 pid = kernel_thread(event_thread, NULL, 0);
556 if (pid < 0) {
557 err ("Can't start up our event thread\n");
558 return -1;
560 return 0;
564 void pciehp_event_stop_thread(void)
566 event_finished = 1;
567 up(&event_semaphore);
568 down(&event_exit);
572 static int update_slot_info(struct slot *slot)
574 struct hotplug_slot_info *info;
575 /* char buffer[SLOT_NAME_SIZE]; */
576 int result;
578 info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
579 if (!info)
580 return -ENOMEM;
582 /* make_slot_name (&buffer[0], SLOT_NAME_SIZE, slot); */
584 slot->hpc_ops->get_power_status(slot, &(info->power_status));
585 slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
586 slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
587 slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
589 /* result = pci_hp_change_slot_info(buffer, info); */
590 result = pci_hp_change_slot_info(slot->hotplug_slot, info);
591 kfree (info);
592 return result;
595 static void interrupt_event_handler(struct controller *ctrl)
597 int loop = 0;
598 int change = 1;
599 u8 hp_slot;
600 u8 getstatus;
601 struct slot *p_slot;
603 while (change) {
604 change = 0;
606 for (loop = 0; loop < MAX_EVENTS; loop++) {
607 if (ctrl->event_queue[loop].event_type != 0) {
608 hp_slot = ctrl->event_queue[loop].hp_slot;
610 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
612 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
613 dbg("button cancel\n");
614 del_timer(&p_slot->task_event);
616 switch (p_slot->state) {
617 case BLINKINGOFF_STATE:
618 /* Wait for exclusive access to hardware */
619 down(&ctrl->crit_sect);
621 if (PWR_LED(ctrl->ctrlcap)) {
622 p_slot->hpc_ops->green_led_on(p_slot);
623 /* Wait for the command to complete */
624 wait_for_ctrl_irq (ctrl);
626 if (ATTN_LED(ctrl->ctrlcap)) {
627 p_slot->hpc_ops->set_attention_status(p_slot, 0);
629 /* Wait for the command to complete */
630 wait_for_ctrl_irq (ctrl);
632 /* Done with exclusive hardware access */
633 up(&ctrl->crit_sect);
634 break;
635 case BLINKINGON_STATE:
636 /* Wait for exclusive access to hardware */
637 down(&ctrl->crit_sect);
639 if (PWR_LED(ctrl->ctrlcap)) {
640 p_slot->hpc_ops->green_led_off(p_slot);
641 /* Wait for the command to complete */
642 wait_for_ctrl_irq (ctrl);
644 if (ATTN_LED(ctrl->ctrlcap)){
645 p_slot->hpc_ops->set_attention_status(p_slot, 0);
646 /* Wait for the command to complete */
647 wait_for_ctrl_irq (ctrl);
649 /* Done with exclusive hardware access */
650 up(&ctrl->crit_sect);
652 break;
653 default:
654 warn("Not a valid state\n");
655 return;
657 info(msg_button_cancel, p_slot->number);
658 p_slot->state = STATIC_STATE;
660 /* ***********Button Pressed (No action on 1st press...) */
661 else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
663 if (ATTN_BUTTN(ctrl->ctrlcap)) {
664 dbg("Button pressed\n");
665 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
666 if (getstatus) {
667 /* slot is on */
668 dbg("slot is on\n");
669 p_slot->state = BLINKINGOFF_STATE;
670 info(msg_button_off, p_slot->number);
671 } else {
672 /* slot is off */
673 dbg("slot is off\n");
674 p_slot->state = BLINKINGON_STATE;
675 info(msg_button_on, p_slot->number);
678 /* Wait for exclusive access to hardware */
679 down(&ctrl->crit_sect);
681 /* blink green LED and turn off amber */
682 if (PWR_LED(ctrl->ctrlcap)) {
683 p_slot->hpc_ops->green_led_blink(p_slot);
684 /* Wait for the command to complete */
685 wait_for_ctrl_irq (ctrl);
688 if (ATTN_LED(ctrl->ctrlcap)) {
689 p_slot->hpc_ops->set_attention_status(p_slot, 0);
691 /* Wait for the command to complete */
692 wait_for_ctrl_irq (ctrl);
695 /* Done with exclusive hardware access */
696 up(&ctrl->crit_sect);
698 init_timer(&p_slot->task_event);
699 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
700 p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
701 p_slot->task_event.data = (unsigned long) p_slot;
703 add_timer(&p_slot->task_event);
706 /***********POWER FAULT********************/
707 else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
708 if (POWER_CTRL(ctrl->ctrlcap)) {
709 dbg("power fault\n");
710 /* Wait for exclusive access to hardware */
711 down(&ctrl->crit_sect);
713 if (ATTN_LED(ctrl->ctrlcap)) {
714 p_slot->hpc_ops->set_attention_status(p_slot, 1);
715 wait_for_ctrl_irq (ctrl);
718 if (PWR_LED(ctrl->ctrlcap)) {
719 p_slot->hpc_ops->green_led_off(p_slot);
720 wait_for_ctrl_irq (ctrl);
723 /* Done with exclusive hardware access */
724 up(&ctrl->crit_sect);
727 /***********SURPRISE REMOVAL********************/
728 else if ((ctrl->event_queue[loop].event_type == INT_PRESENCE_ON) ||
729 (ctrl->event_queue[loop].event_type == INT_PRESENCE_OFF)) {
730 if (HP_SUPR_RM(ctrl->ctrlcap)) {
731 dbg("Surprise Removal\n");
732 if (p_slot) {
733 surprise_rm_pending = (unsigned long) p_slot;
734 up(&event_semaphore);
735 update_slot_info(p_slot);
738 } else {
739 /* refresh notification */
740 if (p_slot)
741 update_slot_info(p_slot);
744 ctrl->event_queue[loop].event_type = 0;
746 change = 1;
748 } /* End of FOR loop */
753 int pciehp_enable_slot(struct slot *p_slot)
755 u8 getstatus = 0;
756 int rc;
758 /* Check to see if (latch closed, card present, power off) */
759 down(&p_slot->ctrl->crit_sect);
761 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
762 if (rc || !getstatus) {
763 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
764 up(&p_slot->ctrl->crit_sect);
765 return 1;
767 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
768 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
769 if (rc || getstatus) {
770 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
771 up(&p_slot->ctrl->crit_sect);
772 return 1;
776 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
777 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
778 if (rc || getstatus) {
779 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
780 up(&p_slot->ctrl->crit_sect);
781 return 1;
784 up(&p_slot->ctrl->crit_sect);
786 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
788 rc = board_added(p_slot);
789 if (rc) {
790 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
793 if (p_slot)
794 update_slot_info(p_slot);
796 return rc;
800 int pciehp_disable_slot(struct slot *p_slot)
802 u8 getstatus = 0;
803 int ret = 0;
805 if (!p_slot->ctrl)
806 return 1;
808 /* Check to see if (latch closed, card present, power on) */
809 down(&p_slot->ctrl->crit_sect);
811 if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {
812 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
813 if (ret || !getstatus) {
814 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
815 up(&p_slot->ctrl->crit_sect);
816 return 1;
820 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
821 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
822 if (ret || getstatus) {
823 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
824 up(&p_slot->ctrl->crit_sect);
825 return 1;
829 if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
830 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
831 if (ret || !getstatus) {
832 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
833 up(&p_slot->ctrl->crit_sect);
834 return 1;
838 up(&p_slot->ctrl->crit_sect);
840 ret = remove_board(p_slot);
841 update_slot_info(p_slot);
842 return ret;