pciehp_ctrl.c 17 KB

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