pciehp_ctrl.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. u8 hp_slot;
  181. int retval = 0;
  182. struct controller *ctrl = p_slot->ctrl;
  183. hp_slot = p_slot->device - ctrl->slot_device_offset;
  184. dbg("%s: slot device, slot offset, hp slot = %d, %d ,%d\n",
  185. __FUNCTION__, p_slot->device,
  186. ctrl->slot_device_offset, hp_slot);
  187. if (POWER_CTRL(ctrl->ctrlcap)) {
  188. /* Power on slot */
  189. retval = p_slot->hpc_ops->power_on_slot(p_slot);
  190. if (retval)
  191. return retval;
  192. }
  193. if (PWR_LED(ctrl->ctrlcap))
  194. p_slot->hpc_ops->green_led_blink(p_slot);
  195. /* Wait for ~1 second */
  196. msleep(1000);
  197. /* Check link training status */
  198. retval = p_slot->hpc_ops->check_lnk_status(ctrl);
  199. if (retval) {
  200. err("%s: Failed to check link status\n", __FUNCTION__);
  201. set_slot_off(ctrl, p_slot);
  202. return retval;
  203. }
  204. /* Check for a power fault */
  205. if (p_slot->hpc_ops->query_power_fault(p_slot)) {
  206. dbg("%s: power fault detected\n", __FUNCTION__);
  207. retval = POWER_FAILURE;
  208. goto err_exit;
  209. }
  210. retval = pciehp_configure_device(p_slot);
  211. if (retval) {
  212. err("Cannot add device 0x%x:%x\n", p_slot->bus,
  213. p_slot->device);
  214. goto err_exit;
  215. }
  216. /*
  217. * Some PCI Express root ports require fixup after hot-plug operation.
  218. */
  219. if (pcie_mch_quirk)
  220. pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
  221. if (PWR_LED(ctrl->ctrlcap))
  222. p_slot->hpc_ops->green_led_on(p_slot);
  223. return 0;
  224. err_exit:
  225. set_slot_off(ctrl, p_slot);
  226. return retval;
  227. }
  228. /**
  229. * remove_board - Turns off slot and LEDs
  230. * @p_slot: slot where board is being removed
  231. */
  232. static int remove_board(struct slot *p_slot)
  233. {
  234. u8 device;
  235. u8 hp_slot;
  236. int retval = 0;
  237. struct controller *ctrl = p_slot->ctrl;
  238. retval = pciehp_unconfigure_device(p_slot);
  239. if (retval)
  240. return retval;
  241. device = p_slot->device;
  242. hp_slot = p_slot->device - ctrl->slot_device_offset;
  243. p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  244. dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
  245. if (POWER_CTRL(ctrl->ctrlcap)) {
  246. /* power off slot */
  247. retval = p_slot->hpc_ops->power_off_slot(p_slot);
  248. if (retval) {
  249. err("%s: Issue of Slot Disable command failed\n",
  250. __FUNCTION__);
  251. return retval;
  252. }
  253. }
  254. if (PWR_LED(ctrl->ctrlcap))
  255. /* turn off Green LED */
  256. p_slot->hpc_ops->green_led_off(p_slot);
  257. return 0;
  258. }
  259. struct power_work_info {
  260. struct slot *p_slot;
  261. struct work_struct work;
  262. };
  263. /**
  264. * pciehp_power_thread - handle pushbutton events
  265. * @work: &struct work_struct describing work to be done
  266. *
  267. * Scheduled procedure to handle blocking stuff for the pushbuttons.
  268. * Handles all pending events and exits.
  269. */
  270. static void pciehp_power_thread(struct work_struct *work)
  271. {
  272. struct power_work_info *info =
  273. container_of(work, struct power_work_info, work);
  274. struct slot *p_slot = info->p_slot;
  275. mutex_lock(&p_slot->lock);
  276. switch (p_slot->state) {
  277. case POWEROFF_STATE:
  278. mutex_unlock(&p_slot->lock);
  279. dbg("%s: disabling bus:device(%x:%x)\n",
  280. __FUNCTION__, p_slot->bus, p_slot->device);
  281. pciehp_disable_slot(p_slot);
  282. mutex_lock(&p_slot->lock);
  283. p_slot->state = STATIC_STATE;
  284. break;
  285. case POWERON_STATE:
  286. mutex_unlock(&p_slot->lock);
  287. if (pciehp_enable_slot(p_slot) &&
  288. PWR_LED(p_slot->ctrl->ctrlcap))
  289. p_slot->hpc_ops->green_led_off(p_slot);
  290. mutex_lock(&p_slot->lock);
  291. p_slot->state = STATIC_STATE;
  292. break;
  293. default:
  294. break;
  295. }
  296. mutex_unlock(&p_slot->lock);
  297. kfree(info);
  298. }
  299. void pciehp_queue_pushbutton_work(struct work_struct *work)
  300. {
  301. struct slot *p_slot = container_of(work, struct slot, work.work);
  302. struct power_work_info *info;
  303. info = kmalloc(sizeof(*info), GFP_KERNEL);
  304. if (!info) {
  305. err("%s: Cannot allocate memory\n", __FUNCTION__);
  306. return;
  307. }
  308. info->p_slot = p_slot;
  309. INIT_WORK(&info->work, pciehp_power_thread);
  310. mutex_lock(&p_slot->lock);
  311. switch (p_slot->state) {
  312. case BLINKINGOFF_STATE:
  313. p_slot->state = POWEROFF_STATE;
  314. break;
  315. case BLINKINGON_STATE:
  316. p_slot->state = POWERON_STATE;
  317. break;
  318. default:
  319. goto out;
  320. }
  321. queue_work(pciehp_wq, &info->work);
  322. out:
  323. mutex_unlock(&p_slot->lock);
  324. }
  325. static int update_slot_info(struct slot *slot)
  326. {
  327. struct hotplug_slot_info *info;
  328. int result;
  329. info = kmalloc(sizeof(*info), GFP_KERNEL);
  330. if (!info)
  331. return -ENOMEM;
  332. slot->hpc_ops->get_power_status(slot, &(info->power_status));
  333. slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
  334. slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
  335. slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
  336. result = pci_hp_change_slot_info(slot->hotplug_slot, info);
  337. kfree (info);
  338. return result;
  339. }
  340. /*
  341. * Note: This function must be called with slot->lock held
  342. */
  343. static void handle_button_press_event(struct slot *p_slot)
  344. {
  345. struct controller *ctrl = p_slot->ctrl;
  346. u8 getstatus;
  347. switch (p_slot->state) {
  348. case STATIC_STATE:
  349. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  350. if (getstatus) {
  351. p_slot->state = BLINKINGOFF_STATE;
  352. info("PCI slot #%s - powering off due to button "
  353. "press.\n", p_slot->name);
  354. } else {
  355. p_slot->state = BLINKINGON_STATE;
  356. info("PCI slot #%s - powering on due to button "
  357. "press.\n", p_slot->name);
  358. }
  359. /* blink green LED and turn off amber */
  360. if (PWR_LED(ctrl->ctrlcap))
  361. p_slot->hpc_ops->green_led_blink(p_slot);
  362. if (ATTN_LED(ctrl->ctrlcap))
  363. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  364. schedule_delayed_work(&p_slot->work, 5*HZ);
  365. break;
  366. case BLINKINGOFF_STATE:
  367. case BLINKINGON_STATE:
  368. /*
  369. * Cancel if we are still blinking; this means that we
  370. * press the attention again before the 5 sec. limit
  371. * expires to cancel hot-add or hot-remove
  372. */
  373. info("Button cancel on Slot(%s)\n", p_slot->name);
  374. dbg("%s: button cancel\n", __FUNCTION__);
  375. cancel_delayed_work(&p_slot->work);
  376. if (p_slot->state == BLINKINGOFF_STATE) {
  377. if (PWR_LED(ctrl->ctrlcap))
  378. p_slot->hpc_ops->green_led_on(p_slot);
  379. } else {
  380. if (PWR_LED(ctrl->ctrlcap))
  381. p_slot->hpc_ops->green_led_off(p_slot);
  382. }
  383. if (ATTN_LED(ctrl->ctrlcap))
  384. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  385. info("PCI slot #%s - action canceled due to button press\n",
  386. p_slot->name);
  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. info("Button ignore on Slot(%s)\n", p_slot->name);
  397. update_slot_info(p_slot);
  398. break;
  399. default:
  400. warn("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. err("%s: Cannot allocate memory\n", __FUNCTION__);
  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->ctrlcap))
  437. break;
  438. if (ATTN_LED(ctrl->ctrlcap))
  439. p_slot->hpc_ops->set_attention_status(p_slot, 1);
  440. if (PWR_LED(ctrl->ctrlcap))
  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->ctrlcap))
  446. break;
  447. dbg("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. /* Check to see if (latch closed, card present, power off) */
  463. mutex_lock(&p_slot->ctrl->crit_sect);
  464. rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  465. if (rc || !getstatus) {
  466. info("%s: no adapter on slot(%s)\n", __FUNCTION__,
  467. p_slot->name);
  468. mutex_unlock(&p_slot->ctrl->crit_sect);
  469. return -ENODEV;
  470. }
  471. if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
  472. rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  473. if (rc || getstatus) {
  474. info("%s: latch open on slot(%s)\n", __FUNCTION__,
  475. p_slot->name);
  476. mutex_unlock(&p_slot->ctrl->crit_sect);
  477. return -ENODEV;
  478. }
  479. }
  480. if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
  481. rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  482. if (rc || getstatus) {
  483. info("%s: already enabled on slot(%s)\n", __FUNCTION__,
  484. p_slot->name);
  485. mutex_unlock(&p_slot->ctrl->crit_sect);
  486. return -EINVAL;
  487. }
  488. }
  489. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  490. rc = board_added(p_slot);
  491. if (rc) {
  492. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  493. }
  494. update_slot_info(p_slot);
  495. mutex_unlock(&p_slot->ctrl->crit_sect);
  496. return rc;
  497. }
  498. int pciehp_disable_slot(struct slot *p_slot)
  499. {
  500. u8 getstatus = 0;
  501. int ret = 0;
  502. if (!p_slot->ctrl)
  503. return 1;
  504. /* Check to see if (latch closed, card present, power on) */
  505. mutex_lock(&p_slot->ctrl->crit_sect);
  506. if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {
  507. ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  508. if (ret || !getstatus) {
  509. info("%s: no adapter on slot(%s)\n", __FUNCTION__,
  510. p_slot->name);
  511. mutex_unlock(&p_slot->ctrl->crit_sect);
  512. return -ENODEV;
  513. }
  514. }
  515. if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
  516. ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  517. if (ret || getstatus) {
  518. info("%s: latch open on slot(%s)\n", __FUNCTION__,
  519. p_slot->name);
  520. mutex_unlock(&p_slot->ctrl->crit_sect);
  521. return -ENODEV;
  522. }
  523. }
  524. if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
  525. ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  526. if (ret || !getstatus) {
  527. info("%s: already disabled slot(%s)\n", __FUNCTION__,
  528. p_slot->name);
  529. mutex_unlock(&p_slot->ctrl->crit_sect);
  530. return -EINVAL;
  531. }
  532. /*
  533. * After turning power off, we must wait for at least
  534. * 1 second before taking any action that relies on
  535. * power having been removed from the slot/adapter.
  536. */
  537. msleep(1000);
  538. }
  539. ret = remove_board(p_slot);
  540. update_slot_info(p_slot);
  541. mutex_unlock(&p_slot->ctrl->crit_sect);
  542. return ret;
  543. }
  544. int pciehp_sysfs_enable_slot(struct slot *p_slot)
  545. {
  546. int retval = -ENODEV;
  547. mutex_lock(&p_slot->lock);
  548. switch (p_slot->state) {
  549. case BLINKINGON_STATE:
  550. cancel_delayed_work(&p_slot->work);
  551. case STATIC_STATE:
  552. p_slot->state = POWERON_STATE;
  553. mutex_unlock(&p_slot->lock);
  554. retval = pciehp_enable_slot(p_slot);
  555. mutex_lock(&p_slot->lock);
  556. p_slot->state = STATIC_STATE;
  557. break;
  558. case POWERON_STATE:
  559. info("Slot %s is already in powering on state\n",
  560. p_slot->name);
  561. break;
  562. case BLINKINGOFF_STATE:
  563. case POWEROFF_STATE:
  564. info("Already enabled on slot %s\n", p_slot->name);
  565. break;
  566. default:
  567. err("Not a valid state on slot %s\n", p_slot->name);
  568. break;
  569. }
  570. mutex_unlock(&p_slot->lock);
  571. return retval;
  572. }
  573. int pciehp_sysfs_disable_slot(struct slot *p_slot)
  574. {
  575. int retval = -ENODEV;
  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. info("Slot %s is already in powering off state\n",
  589. p_slot->name);
  590. break;
  591. case BLINKINGON_STATE:
  592. case POWERON_STATE:
  593. info("Already disabled on slot %s\n", p_slot->name);
  594. break;
  595. default:
  596. err("Not a valid state on slot %s\n", p_slot->name);
  597. break;
  598. }
  599. mutex_unlock(&p_slot->lock);
  600. return retval;
  601. }