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. "Issue of Slot Power Off command failed\n");
  150. return;
  151. }
  152. }
  153. /*
  154. * After turning power off, we must wait for at least 1 second
  155. * before taking any action that relies on power having been
  156. * removed from the slot/adapter.
  157. */
  158. msleep(1000);
  159. if (PWR_LED(ctrl))
  160. pslot->hpc_ops->green_led_off(pslot);
  161. if (ATTN_LED(ctrl)) {
  162. if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
  163. ctrl_err(ctrl,
  164. "Issue of Set Attention Led command failed\n");
  165. return;
  166. }
  167. }
  168. }
  169. /**
  170. * board_added - Called after a board has been added to the system.
  171. * @p_slot: &slot where board is added
  172. *
  173. * Turns power on for the board.
  174. * Configures board.
  175. */
  176. static int board_added(struct slot *p_slot)
  177. {
  178. int retval = 0;
  179. struct controller *ctrl = p_slot->ctrl;
  180. struct pci_bus *parent = ctrl->pci_dev->subordinate;
  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, "Failed to check link status\n");
  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, "Power fault detected\n");
  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 at %04x:%02x:%02x\n",
  208. pci_domain_nr(parent), 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, "%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,
  240. "Issue of Slot Disable command failed\n");
  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,
  276. "Disabling domain:bus:device=%04x:%02x:%02x\n",
  277. pci_domain_nr(p_slot->ctrl->pci_dev->subordinate),
  278. p_slot->bus, p_slot->device);
  279. pciehp_disable_slot(p_slot);
  280. mutex_lock(&p_slot->lock);
  281. p_slot->state = STATIC_STATE;
  282. break;
  283. case POWERON_STATE:
  284. mutex_unlock(&p_slot->lock);
  285. if (pciehp_enable_slot(p_slot) &&
  286. PWR_LED(p_slot->ctrl))
  287. p_slot->hpc_ops->green_led_off(p_slot);
  288. mutex_lock(&p_slot->lock);
  289. p_slot->state = STATIC_STATE;
  290. break;
  291. default:
  292. break;
  293. }
  294. mutex_unlock(&p_slot->lock);
  295. kfree(info);
  296. }
  297. void pciehp_queue_pushbutton_work(struct work_struct *work)
  298. {
  299. struct slot *p_slot = container_of(work, struct slot, work.work);
  300. struct power_work_info *info;
  301. info = kmalloc(sizeof(*info), GFP_KERNEL);
  302. if (!info) {
  303. ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n",
  304. __func__);
  305. return;
  306. }
  307. info->p_slot = p_slot;
  308. INIT_WORK(&info->work, pciehp_power_thread);
  309. mutex_lock(&p_slot->lock);
  310. switch (p_slot->state) {
  311. case BLINKINGOFF_STATE:
  312. p_slot->state = POWEROFF_STATE;
  313. break;
  314. case BLINKINGON_STATE:
  315. p_slot->state = POWERON_STATE;
  316. break;
  317. default:
  318. goto out;
  319. }
  320. queue_work(pciehp_wq, &info->work);
  321. out:
  322. mutex_unlock(&p_slot->lock);
  323. }
  324. static int update_slot_info(struct slot *slot)
  325. {
  326. struct hotplug_slot_info *info;
  327. int result;
  328. info = kmalloc(sizeof(*info), GFP_KERNEL);
  329. if (!info)
  330. return -ENOMEM;
  331. slot->hpc_ops->get_power_status(slot, &(info->power_status));
  332. slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
  333. slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
  334. slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
  335. result = pci_hp_change_slot_info(slot->hotplug_slot, info);
  336. kfree (info);
  337. return result;
  338. }
  339. /*
  340. * Note: This function must be called with slot->lock held
  341. */
  342. static void handle_button_press_event(struct slot *p_slot)
  343. {
  344. struct controller *ctrl = p_slot->ctrl;
  345. u8 getstatus;
  346. switch (p_slot->state) {
  347. case STATIC_STATE:
  348. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  349. if (getstatus) {
  350. p_slot->state = BLINKINGOFF_STATE;
  351. ctrl_info(ctrl,
  352. "PCI slot #%s - powering off due to button "
  353. "press.\n", slot_name(p_slot));
  354. } else {
  355. p_slot->state = BLINKINGON_STATE;
  356. ctrl_info(ctrl,
  357. "PCI slot #%s - powering on due to button "
  358. "press.\n", slot_name(p_slot));
  359. }
  360. /* blink green LED and turn off amber */
  361. if (PWR_LED(ctrl))
  362. p_slot->hpc_ops->green_led_blink(p_slot);
  363. if (ATTN_LED(ctrl))
  364. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  365. schedule_delayed_work(&p_slot->work, 5*HZ);
  366. break;
  367. case BLINKINGOFF_STATE:
  368. case BLINKINGON_STATE:
  369. /*
  370. * Cancel if we are still blinking; this means that we
  371. * press the attention again before the 5 sec. limit
  372. * expires to cancel hot-add or hot-remove
  373. */
  374. ctrl_info(ctrl, "Button cancel on Slot(%s)\n", slot_name(p_slot));
  375. cancel_delayed_work(&p_slot->work);
  376. if (p_slot->state == BLINKINGOFF_STATE) {
  377. if (PWR_LED(ctrl))
  378. p_slot->hpc_ops->green_led_on(p_slot);
  379. } else {
  380. if (PWR_LED(ctrl))
  381. p_slot->hpc_ops->green_led_off(p_slot);
  382. }
  383. if (ATTN_LED(ctrl))
  384. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  385. ctrl_info(ctrl, "PCI slot #%s - action canceled "
  386. "due to button press\n", slot_name(p_slot));
  387. p_slot->state = STATIC_STATE;
  388. break;
  389. case POWEROFF_STATE:
  390. case POWERON_STATE:
  391. /*
  392. * Ignore if the slot is on power-on or power-off state;
  393. * this means that the previous attention button action
  394. * to hot-add or hot-remove is undergoing
  395. */
  396. ctrl_info(ctrl, "Button ignore on Slot(%s)\n", slot_name(p_slot));
  397. update_slot_info(p_slot);
  398. break;
  399. default:
  400. ctrl_warn(ctrl, "Not a valid state\n");
  401. break;
  402. }
  403. }
  404. /*
  405. * Note: This function must be called with slot->lock held
  406. */
  407. static void handle_surprise_event(struct slot *p_slot)
  408. {
  409. u8 getstatus;
  410. struct power_work_info *info;
  411. info = kmalloc(sizeof(*info), GFP_KERNEL);
  412. if (!info) {
  413. ctrl_err(p_slot->ctrl, "%s: Cannot allocate memory\n",
  414. __func__);
  415. return;
  416. }
  417. info->p_slot = p_slot;
  418. INIT_WORK(&info->work, pciehp_power_thread);
  419. p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  420. if (!getstatus)
  421. p_slot->state = POWEROFF_STATE;
  422. else
  423. p_slot->state = POWERON_STATE;
  424. queue_work(pciehp_wq, &info->work);
  425. }
  426. static void interrupt_event_handler(struct work_struct *work)
  427. {
  428. struct event_info *info = container_of(work, struct event_info, work);
  429. struct slot *p_slot = info->p_slot;
  430. struct controller *ctrl = p_slot->ctrl;
  431. mutex_lock(&p_slot->lock);
  432. switch (info->event_type) {
  433. case INT_BUTTON_PRESS:
  434. handle_button_press_event(p_slot);
  435. break;
  436. case INT_POWER_FAULT:
  437. if (!POWER_CTRL(ctrl))
  438. break;
  439. if (ATTN_LED(ctrl))
  440. p_slot->hpc_ops->set_attention_status(p_slot, 1);
  441. if (PWR_LED(ctrl))
  442. p_slot->hpc_ops->green_led_off(p_slot);
  443. break;
  444. case INT_PRESENCE_ON:
  445. case INT_PRESENCE_OFF:
  446. if (!HP_SUPR_RM(ctrl))
  447. break;
  448. ctrl_dbg(ctrl, "Surprise Removal\n");
  449. update_slot_info(p_slot);
  450. handle_surprise_event(p_slot);
  451. break;
  452. default:
  453. update_slot_info(p_slot);
  454. break;
  455. }
  456. mutex_unlock(&p_slot->lock);
  457. kfree(info);
  458. }
  459. int pciehp_enable_slot(struct slot *p_slot)
  460. {
  461. u8 getstatus = 0;
  462. int rc;
  463. struct controller *ctrl = p_slot->ctrl;
  464. /* Check to see if (latch closed, card present, power off) */
  465. mutex_lock(&p_slot->ctrl->crit_sect);
  466. rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  467. if (rc || !getstatus) {
  468. ctrl_info(ctrl, "No adapter on slot(%s)\n", 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, "Latch open on slot(%s)\n",
  476. 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, "Already enabled on slot(%s)\n",
  485. 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, "No adapter on slot(%s)\n",
  512. 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, "Latch open on slot(%s)\n",
  521. 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, "Already disabled on slot(%s)\n",
  530. 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. }