Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / pci / hotplug / pciehp_ctrl.c
CommitLineData
1da177e4
LT
1/*
2 * PCI Express Hot Plug Controller Driver
3 *
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
8 *
9 * All rights reserved.
10 *
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.
15 *
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.
21 *
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.
25 *
8cf4c195 26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
1da177e4
LT
27 *
28 */
29
1da177e4
LT
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/types.h>
1da177e4 33#include <linux/pci.h>
5d386e1a 34#include <linux/workqueue.h>
1da177e4
LT
35#include "../pci.h"
36#include "pciehp.h"
1da177e4 37
5d386e1a 38static void interrupt_event_handler(struct work_struct *work);
1da177e4 39
5d386e1a 40static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
49ed2b49 41{
5d386e1a
KK
42 struct event_info *info;
43
44 info = kmalloc(sizeof(*info), GFP_ATOMIC);
45 if (!info)
46 return -ENOMEM;
47
48 info->event_type = event_type;
49 info->p_slot = p_slot;
50 INIT_WORK(&info->work, interrupt_event_handler);
51
52 schedule_work(&info->work);
53
54 return 0;
49ed2b49
KK
55}
56
dbd79aed 57u8 pciehp_handle_attention_button(struct slot *p_slot)
1da177e4 58{
5d386e1a 59 u32 event_type;
7f2feec1 60 struct controller *ctrl = p_slot->ctrl;
1da177e4
LT
61
62 /* Attention Button Change */
18b341b7 63 ctrl_dbg(ctrl, "Attention button interrupt received\n");
1da177e4 64
1da177e4
LT
65 /*
66 * Button pressed - See if need to TAKE ACTION!!!
67 */
e1acb24f 68 ctrl_info(ctrl, "Button pressed on Slot(%s)\n", slot_name(p_slot));
5d386e1a 69 event_type = INT_BUTTON_PRESS;
1da177e4 70
5d386e1a 71 queue_interrupt_event(p_slot, event_type);
1da177e4
LT
72
73 return 0;
1da177e4
LT
74}
75
dbd79aed 76u8 pciehp_handle_switch_change(struct slot *p_slot)
1da177e4 77{
1da177e4 78 u8 getstatus;
5d386e1a 79 u32 event_type;
7f2feec1 80 struct controller *ctrl = p_slot->ctrl;
1da177e4
LT
81
82 /* Switch Change */
18b341b7 83 ctrl_dbg(ctrl, "Switch interrupt received\n");
1da177e4 84
1da177e4 85 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1da177e4
LT
86 if (getstatus) {
87 /*
88 * Switch opened
89 */
e1acb24f 90 ctrl_info(ctrl, "Latch open on Slot(%s)\n", slot_name(p_slot));
5d386e1a 91 event_type = INT_SWITCH_OPEN;
1da177e4
LT
92 } else {
93 /*
94 * Switch closed
95 */
e1acb24f 96 ctrl_info(ctrl, "Latch close on Slot(%s)\n", slot_name(p_slot));
5d386e1a 97 event_type = INT_SWITCH_CLOSE;
1da177e4
LT
98 }
99
5d386e1a 100 queue_interrupt_event(p_slot, event_type);
1da177e4 101
5d386e1a 102 return 1;
1da177e4
LT
103}
104
dbd79aed 105u8 pciehp_handle_presence_change(struct slot *p_slot)
1da177e4 106{
5d386e1a
KK
107 u32 event_type;
108 u8 presence_save;
7f2feec1 109 struct controller *ctrl = p_slot->ctrl;
1da177e4
LT
110
111 /* Presence Change */
18b341b7 112 ctrl_dbg(ctrl, "Presence/Notify input change\n");
1da177e4 113
1da177e4
LT
114 /* Switch is open, assume a presence change
115 * Save the presence state
116 */
ed6cbcf2
RS
117 p_slot->hpc_ops->get_adapter_status(p_slot, &presence_save);
118 if (presence_save) {
1da177e4
LT
119 /*
120 * Card Present
121 */
e1acb24f 122 ctrl_info(ctrl, "Card present on Slot(%s)\n", slot_name(p_slot));
5d386e1a 123 event_type = INT_PRESENCE_ON;
1da177e4
LT
124 } else {
125 /*
126 * Not Present
127 */
e1acb24f
AC
128 ctrl_info(ctrl, "Card not present on Slot(%s)\n",
129 slot_name(p_slot));
5d386e1a 130 event_type = INT_PRESENCE_OFF;
1da177e4
LT
131 }
132
5d386e1a 133 queue_interrupt_event(p_slot, event_type);
1da177e4 134
5d386e1a 135 return 1;
1da177e4
LT
136}
137
dbd79aed 138u8 pciehp_handle_power_fault(struct slot *p_slot)
1da177e4 139{
5d386e1a 140 u32 event_type;
7f2feec1 141 struct controller *ctrl = p_slot->ctrl;
1da177e4
LT
142
143 /* power fault */
18b341b7 144 ctrl_dbg(ctrl, "Power fault interrupt received\n");
1da177e4 145
1da177e4
LT
146 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
147 /*
148 * power fault Cleared
149 */
7f2feec1 150 ctrl_info(ctrl, "Power fault cleared on Slot(%s)\n",
e1acb24f 151 slot_name(p_slot));
5d386e1a 152 event_type = INT_POWER_FAULT_CLEAR;
1da177e4
LT
153 } else {
154 /*
155 * power fault
156 */
e1acb24f 157 ctrl_info(ctrl, "Power fault on Slot(%s)\n", slot_name(p_slot));
5d386e1a 158 event_type = INT_POWER_FAULT;
18b341b7 159 ctrl_info(ctrl, "Power fault bit %x set\n", 0);
1da177e4 160 }
1da177e4 161
5d386e1a
KK
162 queue_interrupt_event(p_slot, event_type);
163
164 return 1;
1da177e4
LT
165}
166
36ed27b0 167/* The following routines constitute the bulk of the
1da177e4
LT
168 hotplug controller logic
169 */
170
171static void set_slot_off(struct controller *ctrl, struct slot * pslot)
172{
1da177e4 173 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
ae416e6b 174 if (POWER_CTRL(ctrl)) {
36ed27b0 175 if (pslot->hpc_ops->power_off_slot(pslot)) {
7f2feec1 176 ctrl_err(ctrl,
18b341b7 177 "Issue of Slot Power Off command failed\n");
1da177e4
LT
178 return;
179 }
c7b4fee3
KK
180 /*
181 * After turning power off, we must wait for at least 1 second
182 * before taking any action that relies on power having been
183 * removed from the slot/adapter.
184 */
185 msleep(1000);
1da177e4
LT
186 }
187
ae416e6b 188 if (PWR_LED(ctrl))
36ed27b0 189 pslot->hpc_ops->green_led_off(pslot);
1da177e4 190
ae416e6b 191 if (ATTN_LED(ctrl)) {
44ef4cef 192 if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
18b341b7
TI
193 ctrl_err(ctrl,
194 "Issue of Set Attention Led command failed\n");
1da177e4
LT
195 return;
196 }
1da177e4 197 }
1da177e4
LT
198}
199
200/**
201 * board_added - Called after a board has been added to the system.
26e6c66e 202 * @p_slot: &slot where board is added
1da177e4 203 *
26e6c66e
RD
204 * Turns power on for the board.
205 * Configures board.
1da177e4 206 */
ed6cbcf2 207static int board_added(struct slot *p_slot)
1da177e4 208{
44ef4cef 209 int retval = 0;
ca22a5e4 210 struct controller *ctrl = p_slot->ctrl;
18b341b7 211 struct pci_bus *parent = ctrl->pci_dev->subordinate;
1da177e4 212
18b341b7 213 ctrl_dbg(ctrl, "%s: slot device, slot offset, hp slot = %d, %d, %d\n",
7f2feec1
TI
214 __func__, p_slot->device, ctrl->slot_device_offset,
215 p_slot->hp_slot);
1da177e4 216
ae416e6b 217 if (POWER_CTRL(ctrl)) {
1da177e4 218 /* Power on slot */
44ef4cef
KK
219 retval = p_slot->hpc_ops->power_on_slot(p_slot);
220 if (retval)
221 return retval;
1da177e4 222 }
36ed27b0 223
ae416e6b 224 if (PWR_LED(ctrl))
1da177e4 225 p_slot->hpc_ops->green_led_blink(p_slot);
1da177e4 226
44ef4cef
KK
227 /* Check link training status */
228 retval = p_slot->hpc_ops->check_lnk_status(ctrl);
229 if (retval) {
18b341b7 230 ctrl_err(ctrl, "Failed to check link status\n");
1da177e4 231 set_slot_off(ctrl, p_slot);
44ef4cef 232 return retval;
1da177e4
LT
233 }
234
1da177e4 235 /* Check for a power fault */
5a49f203 236 if (p_slot->hpc_ops->query_power_fault(p_slot)) {
18b341b7 237 ctrl_dbg(ctrl, "Power fault detected\n");
44ef4cef 238 retval = POWER_FAILURE;
71b720c0 239 goto err_exit;
1da177e4
LT
240 }
241
44ef4cef
KK
242 retval = pciehp_configure_device(p_slot);
243 if (retval) {
18b341b7
TI
244 ctrl_err(ctrl, "Cannot add device at %04x:%02x:%02x\n",
245 pci_domain_nr(parent), p_slot->bus, p_slot->device);
71b720c0
RS
246 goto err_exit;
247 }
1da177e4 248
71b720c0
RS
249 /*
250 * Some PCI Express root ports require fixup after hot-plug operation.
251 */
252 if (pcie_mch_quirk)
253 pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
ae416e6b 254 if (PWR_LED(ctrl))
71b720c0 255 p_slot->hpc_ops->green_led_on(p_slot);
44ef4cef 256
1da177e4 257 return 0;
71b720c0
RS
258
259err_exit:
260 set_slot_off(ctrl, p_slot);
44ef4cef 261 return retval;
1da177e4
LT
262}
263
1da177e4 264/**
26e6c66e
RD
265 * remove_board - Turns off slot and LEDs
266 * @p_slot: slot where board is being removed
1da177e4 267 */
ed6cbcf2 268static int remove_board(struct slot *p_slot)
1da177e4 269{
44ef4cef 270 int retval = 0;
ca22a5e4 271 struct controller *ctrl = p_slot->ctrl;
1da177e4 272
44ef4cef
KK
273 retval = pciehp_unconfigure_device(p_slot);
274 if (retval)
275 return retval;
1da177e4 276
18b341b7 277 ctrl_dbg(ctrl, "%s: hp_slot = %d\n", __func__, p_slot->hp_slot);
1da177e4 278
ae416e6b 279 if (POWER_CTRL(ctrl)) {
1da177e4 280 /* power off slot */
44ef4cef
KK
281 retval = p_slot->hpc_ops->power_off_slot(p_slot);
282 if (retval) {
18b341b7
TI
283 ctrl_err(ctrl,
284 "Issue of Slot Disable command failed\n");
44ef4cef 285 return retval;
1da177e4 286 }
c7b4fee3
KK
287 /*
288 * After turning power off, we must wait for at least 1 second
289 * before taking any action that relies on power having been
290 * removed from the slot/adapter.
291 */
292 msleep(1000);
1da177e4
LT
293 }
294
ae416e6b 295 if (PWR_LED(ctrl))
1da177e4
LT
296 /* turn off Green LED */
297 p_slot->hpc_ops->green_led_off(p_slot);
1da177e4 298
1da177e4
LT
299 return 0;
300}
301
5d386e1a
KK
302struct power_work_info {
303 struct slot *p_slot;
304 struct work_struct work;
305};
1da177e4
LT
306
307/**
26e6c66e
RD
308 * pciehp_power_thread - handle pushbutton events
309 * @work: &struct work_struct describing work to be done
1da177e4 310 *
26e6c66e 311 * Scheduled procedure to handle blocking stuff for the pushbuttons.
1da177e4 312 * Handles all pending events and exits.
1da177e4 313 */
5d386e1a 314static void pciehp_power_thread(struct work_struct *work)
1da177e4 315{
5d386e1a
KK
316 struct power_work_info *info =
317 container_of(work, struct power_work_info, work);
318 struct slot *p_slot = info->p_slot;
319
320 mutex_lock(&p_slot->lock);
321 switch (p_slot->state) {
322 case POWEROFF_STATE:
323 mutex_unlock(&p_slot->lock);
18b341b7
TI
324 ctrl_dbg(p_slot->ctrl,
325 "Disabling domain:bus:device=%04x:%02x:%02x\n",
326 pci_domain_nr(p_slot->ctrl->pci_dev->subordinate),
327 p_slot->bus, p_slot->device);
1da177e4 328 pciehp_disable_slot(p_slot);
5d386e1a 329 mutex_lock(&p_slot->lock);
1da177e4 330 p_slot->state = STATIC_STATE;
5d386e1a
KK
331 break;
332 case POWERON_STATE:
333 mutex_unlock(&p_slot->lock);
44ef4cef 334 if (pciehp_enable_slot(p_slot) &&
ae416e6b 335 PWR_LED(p_slot->ctrl))
1da177e4 336 p_slot->hpc_ops->green_led_off(p_slot);
5d386e1a 337 mutex_lock(&p_slot->lock);
1da177e4 338 p_slot->state = STATIC_STATE;
5d386e1a
KK
339 break;
340 default:
341 break;
1da177e4 342 }
5d386e1a 343 mutex_unlock(&p_slot->lock);
1da177e4 344
5d386e1a 345 kfree(info);
1da177e4
LT
346}
347
e325e1f0 348void pciehp_queue_pushbutton_work(struct work_struct *work)
1da177e4 349{
5d386e1a
KK
350 struct slot *p_slot = container_of(work, struct slot, work.work);
351 struct power_work_info *info;
1da177e4 352
5d386e1a
KK
353 info = kmalloc(sizeof(*info), GFP_KERNEL);
354 if (!info) {
7f2feec1
TI
355 ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n",
356 __func__);
1da177e4
LT
357 return;
358 }
5d386e1a
KK
359 info->p_slot = p_slot;
360 INIT_WORK(&info->work, pciehp_power_thread);
1da177e4 361
5d386e1a
KK
362 mutex_lock(&p_slot->lock);
363 switch (p_slot->state) {
364 case BLINKINGOFF_STATE:
1da177e4 365 p_slot->state = POWEROFF_STATE;
5d386e1a
KK
366 break;
367 case BLINKINGON_STATE:
1da177e4 368 p_slot->state = POWERON_STATE;
5d386e1a
KK
369 break;
370 default:
371 goto out;
1da177e4 372 }
5d386e1a
KK
373 queue_work(pciehp_wq, &info->work);
374 out:
375 mutex_unlock(&p_slot->lock);
1da177e4
LT
376}
377
1da177e4
LT
378static int update_slot_info(struct slot *slot)
379{
380 struct hotplug_slot_info *info;
1da177e4
LT
381 int result;
382
5d386e1a 383 info = kmalloc(sizeof(*info), GFP_KERNEL);
1da177e4
LT
384 if (!info)
385 return -ENOMEM;
386
1da177e4
LT
387 slot->hpc_ops->get_power_status(slot, &(info->power_status));
388 slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
389 slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
390 slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
391
1da177e4
LT
392 result = pci_hp_change_slot_info(slot->hotplug_slot, info);
393 kfree (info);
394 return result;
395}
396
5d386e1a
KK
397/*
398 * Note: This function must be called with slot->lock held
399 */
400static void handle_button_press_event(struct slot *p_slot)
1da177e4 401{
5d386e1a 402 struct controller *ctrl = p_slot->ctrl;
1da177e4 403 u8 getstatus;
1da177e4 404
5d386e1a
KK
405 switch (p_slot->state) {
406 case STATIC_STATE:
407 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
408 if (getstatus) {
409 p_slot->state = BLINKINGOFF_STATE;
7f2feec1
TI
410 ctrl_info(ctrl,
411 "PCI slot #%s - powering off due to button "
e1acb24f 412 "press.\n", slot_name(p_slot));
5d386e1a
KK
413 } else {
414 p_slot->state = BLINKINGON_STATE;
7f2feec1
TI
415 ctrl_info(ctrl,
416 "PCI slot #%s - powering on due to button "
e1acb24f 417 "press.\n", slot_name(p_slot));
5d386e1a
KK
418 }
419 /* blink green LED and turn off amber */
ae416e6b 420 if (PWR_LED(ctrl))
5d386e1a 421 p_slot->hpc_ops->green_led_blink(p_slot);
ae416e6b 422 if (ATTN_LED(ctrl))
5d386e1a
KK
423 p_slot->hpc_ops->set_attention_status(p_slot, 0);
424
425 schedule_delayed_work(&p_slot->work, 5*HZ);
426 break;
427 case BLINKINGOFF_STATE:
428 case BLINKINGON_STATE:
429 /*
430 * Cancel if we are still blinking; this means that we
431 * press the attention again before the 5 sec. limit
432 * expires to cancel hot-add or hot-remove
433 */
e1acb24f 434 ctrl_info(ctrl, "Button cancel on Slot(%s)\n", slot_name(p_slot));
5d386e1a
KK
435 cancel_delayed_work(&p_slot->work);
436 if (p_slot->state == BLINKINGOFF_STATE) {
ae416e6b 437 if (PWR_LED(ctrl))
5d386e1a
KK
438 p_slot->hpc_ops->green_led_on(p_slot);
439 } else {
ae416e6b 440 if (PWR_LED(ctrl))
5d386e1a
KK
441 p_slot->hpc_ops->green_led_off(p_slot);
442 }
ae416e6b 443 if (ATTN_LED(ctrl))
5d386e1a 444 p_slot->hpc_ops->set_attention_status(p_slot, 0);
7f2feec1 445 ctrl_info(ctrl, "PCI slot #%s - action canceled "
e1acb24f 446 "due to button press\n", slot_name(p_slot));
5d386e1a
KK
447 p_slot->state = STATIC_STATE;
448 break;
449 case POWEROFF_STATE:
450 case POWERON_STATE:
451 /*
452 * Ignore if the slot is on power-on or power-off state;
453 * this means that the previous attention button action
454 * to hot-add or hot-remove is undergoing
455 */
e1acb24f 456 ctrl_info(ctrl, "Button ignore on Slot(%s)\n", slot_name(p_slot));
5d386e1a
KK
457 update_slot_info(p_slot);
458 break;
459 default:
7f2feec1 460 ctrl_warn(ctrl, "Not a valid state\n");
5d386e1a 461 break;
1da177e4
LT
462 }
463}
464
5d386e1a
KK
465/*
466 * Note: This function must be called with slot->lock held
467 */
468static void handle_surprise_event(struct slot *p_slot)
469{
470 u8 getstatus;
471 struct power_work_info *info;
472
473 info = kmalloc(sizeof(*info), GFP_KERNEL);
474 if (!info) {
7f2feec1
TI
475 ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n",
476 __func__);
5d386e1a
KK
477 return;
478 }
479 info->p_slot = p_slot;
480 INIT_WORK(&info->work, pciehp_power_thread);
481
482 p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
483 if (!getstatus)
484 p_slot->state = POWEROFF_STATE;
485 else
486 p_slot->state = POWERON_STATE;
487
488 queue_work(pciehp_wq, &info->work);
489}
490
491static void interrupt_event_handler(struct work_struct *work)
492{
493 struct event_info *info = container_of(work, struct event_info, work);
494 struct slot *p_slot = info->p_slot;
495 struct controller *ctrl = p_slot->ctrl;
496
497 mutex_lock(&p_slot->lock);
498 switch (info->event_type) {
499 case INT_BUTTON_PRESS:
500 handle_button_press_event(p_slot);
501 break;
502 case INT_POWER_FAULT:
ae416e6b 503 if (!POWER_CTRL(ctrl))
5d386e1a 504 break;
ae416e6b 505 if (ATTN_LED(ctrl))
5d386e1a 506 p_slot->hpc_ops->set_attention_status(p_slot, 1);
ae416e6b 507 if (PWR_LED(ctrl))
5d386e1a
KK
508 p_slot->hpc_ops->green_led_off(p_slot);
509 break;
510 case INT_PRESENCE_ON:
511 case INT_PRESENCE_OFF:
ae416e6b 512 if (!HP_SUPR_RM(ctrl))
5d386e1a 513 break;
7f2feec1 514 ctrl_dbg(ctrl, "Surprise Removal\n");
5d386e1a
KK
515 update_slot_info(p_slot);
516 handle_surprise_event(p_slot);
517 break;
518 default:
519 update_slot_info(p_slot);
520 break;
521 }
522 mutex_unlock(&p_slot->lock);
523
524 kfree(info);
525}
526
1da177e4
LT
527int pciehp_enable_slot(struct slot *p_slot)
528{
529 u8 getstatus = 0;
530 int rc;
7f2feec1 531 struct controller *ctrl = p_slot->ctrl;
1da177e4
LT
532
533 /* Check to see if (latch closed, card present, power off) */
6aa4cdd0 534 mutex_lock(&p_slot->ctrl->crit_sect);
1da177e4
LT
535
536 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
537 if (rc || !getstatus) {
18b341b7 538 ctrl_info(ctrl, "No adapter on slot(%s)\n", slot_name(p_slot));
6aa4cdd0 539 mutex_unlock(&p_slot->ctrl->crit_sect);
c9d86d76 540 return -ENODEV;
1da177e4 541 }
ae416e6b 542 if (MRL_SENS(p_slot->ctrl)) {
1da177e4
LT
543 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
544 if (rc || getstatus) {
18b341b7
TI
545 ctrl_info(ctrl, "Latch open on slot(%s)\n",
546 slot_name(p_slot));
6aa4cdd0 547 mutex_unlock(&p_slot->ctrl->crit_sect);
c9d86d76 548 return -ENODEV;
1da177e4
LT
549 }
550 }
36ed27b0 551
ae416e6b 552 if (POWER_CTRL(p_slot->ctrl)) {
1da177e4
LT
553 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
554 if (rc || getstatus) {
18b341b7
TI
555 ctrl_info(ctrl, "Already enabled on slot(%s)\n",
556 slot_name(p_slot));
6aa4cdd0 557 mutex_unlock(&p_slot->ctrl->crit_sect);
c9d86d76 558 return -EINVAL;
1da177e4
LT
559 }
560 }
1da177e4 561
1da177e4 562 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1da177e4 563
ca22a5e4 564 rc = board_added(p_slot);
1da177e4 565 if (rc) {
1da177e4 566 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1da177e4
LT
567 }
568
9ef9977c 569 update_slot_info(p_slot);
1da177e4 570
dd5619cb 571 mutex_unlock(&p_slot->ctrl->crit_sect);
1da177e4
LT
572 return rc;
573}
574
575
576int pciehp_disable_slot(struct slot *p_slot)
577{
1da177e4 578 u8 getstatus = 0;
1da177e4 579 int ret = 0;
7f2feec1 580 struct controller *ctrl = p_slot->ctrl;
1da177e4
LT
581
582 if (!p_slot->ctrl)
583 return 1;
584
585 /* Check to see if (latch closed, card present, power on) */
6aa4cdd0 586 mutex_lock(&p_slot->ctrl->crit_sect);
1da177e4 587
ae416e6b 588 if (!HP_SUPR_RM(p_slot->ctrl)) {
1da177e4
LT
589 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
590 if (ret || !getstatus) {
18b341b7
TI
591 ctrl_info(ctrl, "No adapter on slot(%s)\n",
592 slot_name(p_slot));
6aa4cdd0 593 mutex_unlock(&p_slot->ctrl->crit_sect);
c9d86d76 594 return -ENODEV;
1da177e4
LT
595 }
596 }
597
ae416e6b 598 if (MRL_SENS(p_slot->ctrl)) {
1da177e4
LT
599 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
600 if (ret || getstatus) {
18b341b7
TI
601 ctrl_info(ctrl, "Latch open on slot(%s)\n",
602 slot_name(p_slot));
6aa4cdd0 603 mutex_unlock(&p_slot->ctrl->crit_sect);
c9d86d76 604 return -ENODEV;
1da177e4
LT
605 }
606 }
607
ae416e6b 608 if (POWER_CTRL(p_slot->ctrl)) {
1da177e4
LT
609 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
610 if (ret || !getstatus) {
18b341b7
TI
611 ctrl_info(ctrl, "Already disabled on slot(%s)\n",
612 slot_name(p_slot));
6aa4cdd0 613 mutex_unlock(&p_slot->ctrl->crit_sect);
c9d86d76 614 return -EINVAL;
1da177e4
LT
615 }
616 }
617
ca22a5e4
RS
618 ret = remove_board(p_slot);
619 update_slot_info(p_slot);
dd5619cb
KK
620
621 mutex_unlock(&p_slot->ctrl->crit_sect);
ca22a5e4 622 return ret;
1da177e4
LT
623}
624
5d386e1a
KK
625int pciehp_sysfs_enable_slot(struct slot *p_slot)
626{
627 int retval = -ENODEV;
7f2feec1 628 struct controller *ctrl = p_slot->ctrl;
5d386e1a
KK
629
630 mutex_lock(&p_slot->lock);
631 switch (p_slot->state) {
632 case BLINKINGON_STATE:
633 cancel_delayed_work(&p_slot->work);
634 case STATIC_STATE:
635 p_slot->state = POWERON_STATE;
636 mutex_unlock(&p_slot->lock);
637 retval = pciehp_enable_slot(p_slot);
638 mutex_lock(&p_slot->lock);
639 p_slot->state = STATIC_STATE;
640 break;
641 case POWERON_STATE:
7f2feec1 642 ctrl_info(ctrl, "Slot %s is already in powering on state\n",
e1acb24f 643 slot_name(p_slot));
5d386e1a
KK
644 break;
645 case BLINKINGOFF_STATE:
646 case POWEROFF_STATE:
e1acb24f
AC
647 ctrl_info(ctrl, "Already enabled on slot %s\n",
648 slot_name(p_slot));
5d386e1a
KK
649 break;
650 default:
e1acb24f
AC
651 ctrl_err(ctrl, "Not a valid state on slot %s\n",
652 slot_name(p_slot));
5d386e1a
KK
653 break;
654 }
655 mutex_unlock(&p_slot->lock);
656
657 return retval;
658}
659
660int pciehp_sysfs_disable_slot(struct slot *p_slot)
661{
662 int retval = -ENODEV;
7f2feec1 663 struct controller *ctrl = p_slot->ctrl;
5d386e1a
KK
664
665 mutex_lock(&p_slot->lock);
666 switch (p_slot->state) {
667 case BLINKINGOFF_STATE:
668 cancel_delayed_work(&p_slot->work);
669 case STATIC_STATE:
670 p_slot->state = POWEROFF_STATE;
671 mutex_unlock(&p_slot->lock);
672 retval = pciehp_disable_slot(p_slot);
673 mutex_lock(&p_slot->lock);
674 p_slot->state = STATIC_STATE;
675 break;
676 case POWEROFF_STATE:
7f2feec1 677 ctrl_info(ctrl, "Slot %s is already in powering off state\n",
e1acb24f 678 slot_name(p_slot));
5d386e1a
KK
679 break;
680 case BLINKINGON_STATE:
681 case POWERON_STATE:
e1acb24f
AC
682 ctrl_info(ctrl, "Already disabled on slot %s\n",
683 slot_name(p_slot));
5d386e1a
KK
684 break;
685 default:
e1acb24f
AC
686 ctrl_err(ctrl, "Not a valid state on slot %s\n",
687 slot_name(p_slot));
5d386e1a
KK
688 break;
689 }
690 mutex_unlock(&p_slot->lock);
691
692 return retval;
693}