pciehp_ctrl.c 17 KB

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