pciehp_ctrl.c 17 KB

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