pciehp_ctrl.c 17 KB

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