pciehp_ctrl.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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 "../pci.h"
  35. #include "pciehp.h"
  36. static void interrupt_event_handler(struct controller *ctrl);
  37. static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
  38. static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
  39. static int event_finished;
  40. static unsigned long pushbutton_pending; /* = 0 */
  41. static unsigned long surprise_rm_pending; /* = 0 */
  42. static inline char *slot_name(struct slot *p_slot)
  43. {
  44. return p_slot->hotplug_slot->name;
  45. }
  46. u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id)
  47. {
  48. struct controller *ctrl = (struct controller *) inst_id;
  49. struct slot *p_slot;
  50. u8 rc = 0;
  51. u8 getstatus;
  52. struct event_info *taskInfo;
  53. /* Attention Button Change */
  54. dbg("pciehp: Attention button interrupt received.\n");
  55. /* This is the structure that tells the worker thread what to do */
  56. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  57. p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  58. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  59. ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
  60. taskInfo->hp_slot = hp_slot;
  61. rc++;
  62. /*
  63. * Button pressed - See if need to TAKE ACTION!!!
  64. */
  65. info("Button pressed on Slot(%s)\n", slot_name(p_slot));
  66. taskInfo->event_type = INT_BUTTON_PRESS;
  67. if ((p_slot->state == BLINKINGON_STATE)
  68. || (p_slot->state == BLINKINGOFF_STATE)) {
  69. /* Cancel if we are still blinking; this means that we press the
  70. * attention again before the 5 sec. limit expires to cancel hot-add
  71. * or hot-remove
  72. */
  73. taskInfo->event_type = INT_BUTTON_CANCEL;
  74. info("Button cancel on Slot(%s)\n", slot_name(p_slot));
  75. } else if ((p_slot->state == POWERON_STATE)
  76. || (p_slot->state == POWEROFF_STATE)) {
  77. /* Ignore if the slot is on power-on or power-off state; this
  78. * means that the previous attention button action to hot-add or
  79. * hot-remove is undergoing
  80. */
  81. taskInfo->event_type = INT_BUTTON_IGNORE;
  82. info("Button ignore on Slot(%s)\n", slot_name(p_slot));
  83. }
  84. if (rc)
  85. up(&event_semaphore); /* signal event thread that new event is posted */
  86. return 0;
  87. }
  88. u8 pciehp_handle_switch_change(u8 hp_slot, void *inst_id)
  89. {
  90. struct controller *ctrl = (struct controller *) inst_id;
  91. struct slot *p_slot;
  92. u8 rc = 0;
  93. u8 getstatus;
  94. struct event_info *taskInfo;
  95. /* Switch Change */
  96. dbg("pciehp: Switch interrupt received.\n");
  97. /* This is the structure that tells the worker thread
  98. * what to do
  99. */
  100. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  101. ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
  102. taskInfo->hp_slot = hp_slot;
  103. rc++;
  104. p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  105. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  106. if (getstatus) {
  107. /*
  108. * Switch opened
  109. */
  110. info("Latch open on Slot(%s)\n", slot_name(p_slot));
  111. taskInfo->event_type = INT_SWITCH_OPEN;
  112. } else {
  113. /*
  114. * Switch closed
  115. */
  116. info("Latch close on Slot(%s)\n", slot_name(p_slot));
  117. taskInfo->event_type = INT_SWITCH_CLOSE;
  118. }
  119. if (rc)
  120. up(&event_semaphore); /* signal event thread that new event is posted */
  121. return rc;
  122. }
  123. u8 pciehp_handle_presence_change(u8 hp_slot, void *inst_id)
  124. {
  125. struct controller *ctrl = (struct controller *) inst_id;
  126. struct slot *p_slot;
  127. u8 presence_save, rc = 0;
  128. struct event_info *taskInfo;
  129. /* Presence Change */
  130. dbg("pciehp: Presence/Notify input change.\n");
  131. /* This is the structure that tells the worker thread
  132. * what to do
  133. */
  134. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  135. ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
  136. taskInfo->hp_slot = hp_slot;
  137. rc++;
  138. p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  139. /* Switch is open, assume a presence change
  140. * Save the presence state
  141. */
  142. p_slot->hpc_ops->get_adapter_status(p_slot, &presence_save);
  143. if (presence_save) {
  144. /*
  145. * Card Present
  146. */
  147. info("Card present on Slot(%s)\n", slot_name(p_slot));
  148. taskInfo->event_type = INT_PRESENCE_ON;
  149. } else {
  150. /*
  151. * Not Present
  152. */
  153. info("Card not present on Slot(%s)\n", slot_name(p_slot));
  154. taskInfo->event_type = INT_PRESENCE_OFF;
  155. }
  156. if (rc)
  157. up(&event_semaphore); /* signal event thread that new event is posted */
  158. return rc;
  159. }
  160. u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
  161. {
  162. struct controller *ctrl = (struct controller *) inst_id;
  163. struct slot *p_slot;
  164. u8 rc = 0;
  165. struct event_info *taskInfo;
  166. /* power fault */
  167. dbg("pciehp: Power fault interrupt received.\n");
  168. /* this is the structure that tells the worker thread
  169. * what to do
  170. */
  171. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  172. ctrl->next_event = (ctrl->next_event + 1) % MAX_EVENTS;
  173. taskInfo->hp_slot = hp_slot;
  174. rc++;
  175. p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  176. if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
  177. /*
  178. * power fault Cleared
  179. */
  180. info("Power fault cleared on Slot(%s)\n", slot_name(p_slot));
  181. taskInfo->event_type = INT_POWER_FAULT_CLEAR;
  182. } else {
  183. /*
  184. * power fault
  185. */
  186. info("Power fault on Slot(%s)\n", slot_name(p_slot));
  187. taskInfo->event_type = INT_POWER_FAULT;
  188. info("power fault bit %x set\n", hp_slot);
  189. }
  190. if (rc)
  191. up(&event_semaphore); /* signal event thread that new event is posted */
  192. return rc;
  193. }
  194. /* The following routines constitute the bulk of the
  195. hotplug controller logic
  196. */
  197. static void set_slot_off(struct controller *ctrl, struct slot * pslot)
  198. {
  199. /* Wait for exclusive access to hardware */
  200. mutex_lock(&ctrl->ctrl_lock);
  201. /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
  202. if (POWER_CTRL(ctrl->ctrlcap)) {
  203. if (pslot->hpc_ops->power_off_slot(pslot)) {
  204. err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
  205. mutex_unlock(&ctrl->ctrl_lock);
  206. return;
  207. }
  208. wait_for_ctrl_irq (ctrl);
  209. }
  210. if (PWR_LED(ctrl->ctrlcap)) {
  211. pslot->hpc_ops->green_led_off(pslot);
  212. wait_for_ctrl_irq (ctrl);
  213. }
  214. if (ATTN_LED(ctrl->ctrlcap)) {
  215. if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
  216. err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
  217. mutex_unlock(&ctrl->ctrl_lock);
  218. return;
  219. }
  220. wait_for_ctrl_irq (ctrl);
  221. }
  222. /* Done with exclusive hardware access */
  223. mutex_unlock(&ctrl->ctrl_lock);
  224. }
  225. /**
  226. * board_added - Called after a board has been added to the system.
  227. *
  228. * Turns power on for the board
  229. * Configures board
  230. *
  231. */
  232. static int board_added(struct slot *p_slot)
  233. {
  234. u8 hp_slot;
  235. int rc = 0;
  236. struct controller *ctrl = p_slot->ctrl;
  237. hp_slot = p_slot->device - ctrl->slot_device_offset;
  238. dbg("%s: slot device, slot offset, hp slot = %d, %d ,%d\n",
  239. __FUNCTION__, p_slot->device,
  240. ctrl->slot_device_offset, hp_slot);
  241. /* Wait for exclusive access to hardware */
  242. mutex_lock(&ctrl->ctrl_lock);
  243. if (POWER_CTRL(ctrl->ctrlcap)) {
  244. /* Power on slot */
  245. rc = p_slot->hpc_ops->power_on_slot(p_slot);
  246. if (rc) {
  247. mutex_unlock(&ctrl->ctrl_lock);
  248. return -1;
  249. }
  250. /* Wait for the command to complete */
  251. wait_for_ctrl_irq (ctrl);
  252. }
  253. if (PWR_LED(ctrl->ctrlcap)) {
  254. p_slot->hpc_ops->green_led_blink(p_slot);
  255. /* Wait for the command to complete */
  256. wait_for_ctrl_irq (ctrl);
  257. }
  258. /* Done with exclusive hardware access */
  259. mutex_unlock(&ctrl->ctrl_lock);
  260. /* Wait for ~1 second */
  261. wait_for_ctrl_irq (ctrl);
  262. /* Check link training status */
  263. rc = p_slot->hpc_ops->check_lnk_status(ctrl);
  264. if (rc) {
  265. err("%s: Failed to check link status\n", __FUNCTION__);
  266. set_slot_off(ctrl, p_slot);
  267. return rc;
  268. }
  269. /* Check for a power fault */
  270. if (p_slot->hpc_ops->query_power_fault(p_slot)) {
  271. dbg("%s: power fault detected\n", __FUNCTION__);
  272. rc = POWER_FAILURE;
  273. goto err_exit;
  274. }
  275. rc = pciehp_configure_device(p_slot);
  276. if (rc) {
  277. err("Cannot add device 0x%x:%x\n", p_slot->bus,
  278. p_slot->device);
  279. goto err_exit;
  280. }
  281. /*
  282. * Some PCI Express root ports require fixup after hot-plug operation.
  283. */
  284. if (pcie_mch_quirk)
  285. pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
  286. if (PWR_LED(ctrl->ctrlcap)) {
  287. /* Wait for exclusive access to hardware */
  288. mutex_lock(&ctrl->ctrl_lock);
  289. p_slot->hpc_ops->green_led_on(p_slot);
  290. /* Wait for the command to complete */
  291. wait_for_ctrl_irq (ctrl);
  292. /* Done with exclusive hardware access */
  293. mutex_unlock(&ctrl->ctrl_lock);
  294. }
  295. return 0;
  296. err_exit:
  297. set_slot_off(ctrl, p_slot);
  298. return -1;
  299. }
  300. /**
  301. * remove_board - Turns off slot and LED's
  302. *
  303. */
  304. static int remove_board(struct slot *p_slot)
  305. {
  306. u8 device;
  307. u8 hp_slot;
  308. int rc;
  309. struct controller *ctrl = p_slot->ctrl;
  310. if (pciehp_unconfigure_device(p_slot))
  311. return 1;
  312. device = p_slot->device;
  313. hp_slot = p_slot->device - ctrl->slot_device_offset;
  314. p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  315. dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
  316. /* Wait for exclusive access to hardware */
  317. mutex_lock(&ctrl->ctrl_lock);
  318. if (POWER_CTRL(ctrl->ctrlcap)) {
  319. /* power off slot */
  320. rc = p_slot->hpc_ops->power_off_slot(p_slot);
  321. if (rc) {
  322. err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
  323. mutex_unlock(&ctrl->ctrl_lock);
  324. return rc;
  325. }
  326. /* Wait for the command to complete */
  327. wait_for_ctrl_irq (ctrl);
  328. }
  329. if (PWR_LED(ctrl->ctrlcap)) {
  330. /* turn off Green LED */
  331. p_slot->hpc_ops->green_led_off(p_slot);
  332. /* Wait for the command to complete */
  333. wait_for_ctrl_irq (ctrl);
  334. }
  335. /* Done with exclusive hardware access */
  336. mutex_unlock(&ctrl->ctrl_lock);
  337. return 0;
  338. }
  339. static void pushbutton_helper_thread(unsigned long data)
  340. {
  341. pushbutton_pending = data;
  342. up(&event_semaphore);
  343. }
  344. /**
  345. * pciehp_pushbutton_thread
  346. *
  347. * Scheduled procedure to handle blocking stuff for the pushbuttons
  348. * Handles all pending events and exits.
  349. *
  350. */
  351. static void pciehp_pushbutton_thread(unsigned long slot)
  352. {
  353. struct slot *p_slot = (struct slot *) slot;
  354. u8 getstatus;
  355. pushbutton_pending = 0;
  356. if (!p_slot) {
  357. dbg("%s: Error! slot NULL\n", __FUNCTION__);
  358. return;
  359. }
  360. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  361. if (getstatus) {
  362. p_slot->state = POWEROFF_STATE;
  363. dbg("%s: disabling bus:device(%x:%x)\n", __FUNCTION__,
  364. p_slot->bus, p_slot->device);
  365. pciehp_disable_slot(p_slot);
  366. p_slot->state = STATIC_STATE;
  367. } else {
  368. p_slot->state = POWERON_STATE;
  369. dbg("%s: adding bus:device(%x:%x)\n", __FUNCTION__,
  370. p_slot->bus, p_slot->device);
  371. if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
  372. /* Wait for exclusive access to hardware */
  373. mutex_lock(&p_slot->ctrl->ctrl_lock);
  374. p_slot->hpc_ops->green_led_off(p_slot);
  375. /* Wait for the command to complete */
  376. wait_for_ctrl_irq (p_slot->ctrl);
  377. /* Done with exclusive hardware access */
  378. mutex_unlock(&p_slot->ctrl->ctrl_lock);
  379. }
  380. p_slot->state = STATIC_STATE;
  381. }
  382. return;
  383. }
  384. /**
  385. * pciehp_surprise_rm_thread
  386. *
  387. * Scheduled procedure to handle blocking stuff for the surprise removal
  388. * Handles all pending events and exits.
  389. *
  390. */
  391. static void pciehp_surprise_rm_thread(unsigned long slot)
  392. {
  393. struct slot *p_slot = (struct slot *) slot;
  394. u8 getstatus;
  395. surprise_rm_pending = 0;
  396. if (!p_slot) {
  397. dbg("%s: Error! slot NULL\n", __FUNCTION__);
  398. return;
  399. }
  400. p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  401. if (!getstatus) {
  402. p_slot->state = POWEROFF_STATE;
  403. dbg("%s: removing bus:device(%x:%x)\n",
  404. __FUNCTION__, p_slot->bus, p_slot->device);
  405. pciehp_disable_slot(p_slot);
  406. p_slot->state = STATIC_STATE;
  407. } else {
  408. p_slot->state = POWERON_STATE;
  409. dbg("%s: adding bus:device(%x:%x)\n",
  410. __FUNCTION__, p_slot->bus, p_slot->device);
  411. if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
  412. /* Wait for exclusive access to hardware */
  413. mutex_lock(&p_slot->ctrl->ctrl_lock);
  414. p_slot->hpc_ops->green_led_off(p_slot);
  415. /* Wait for the command to complete */
  416. wait_for_ctrl_irq (p_slot->ctrl);
  417. /* Done with exclusive hardware access */
  418. mutex_unlock(&p_slot->ctrl->ctrl_lock);
  419. }
  420. p_slot->state = STATIC_STATE;
  421. }
  422. return;
  423. }
  424. /* this is the main worker thread */
  425. static int event_thread(void* data)
  426. {
  427. struct controller *ctrl;
  428. lock_kernel();
  429. daemonize("pciehpd_event");
  430. unlock_kernel();
  431. while (1) {
  432. dbg("!!!!event_thread sleeping\n");
  433. down_interruptible (&event_semaphore);
  434. dbg("event_thread woken finished = %d\n", event_finished);
  435. if (event_finished || signal_pending(current))
  436. break;
  437. /* Do stuff here */
  438. if (pushbutton_pending)
  439. pciehp_pushbutton_thread(pushbutton_pending);
  440. else if (surprise_rm_pending)
  441. pciehp_surprise_rm_thread(surprise_rm_pending);
  442. else
  443. for (ctrl = pciehp_ctrl_list; ctrl; ctrl=ctrl->next)
  444. interrupt_event_handler(ctrl);
  445. }
  446. dbg("event_thread signals exit\n");
  447. up(&event_exit);
  448. return 0;
  449. }
  450. int pciehp_event_start_thread(void)
  451. {
  452. int pid;
  453. /* initialize our semaphores */
  454. init_MUTEX_LOCKED(&event_exit);
  455. event_finished=0;
  456. init_MUTEX_LOCKED(&event_semaphore);
  457. pid = kernel_thread(event_thread, NULL, 0);
  458. if (pid < 0) {
  459. err ("Can't start up our event thread\n");
  460. return -1;
  461. }
  462. return 0;
  463. }
  464. void pciehp_event_stop_thread(void)
  465. {
  466. event_finished = 1;
  467. up(&event_semaphore);
  468. down(&event_exit);
  469. }
  470. static int update_slot_info(struct slot *slot)
  471. {
  472. struct hotplug_slot_info *info;
  473. /* char buffer[SLOT_NAME_SIZE]; */
  474. int result;
  475. info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
  476. if (!info)
  477. return -ENOMEM;
  478. /* make_slot_name (&buffer[0], SLOT_NAME_SIZE, slot); */
  479. slot->hpc_ops->get_power_status(slot, &(info->power_status));
  480. slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
  481. slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
  482. slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
  483. /* result = pci_hp_change_slot_info(buffer, info); */
  484. result = pci_hp_change_slot_info(slot->hotplug_slot, info);
  485. kfree (info);
  486. return result;
  487. }
  488. static void interrupt_event_handler(struct controller *ctrl)
  489. {
  490. int loop = 0;
  491. int change = 1;
  492. u8 hp_slot;
  493. u8 getstatus;
  494. struct slot *p_slot;
  495. while (change) {
  496. change = 0;
  497. for (loop = 0; loop < MAX_EVENTS; loop++) {
  498. if (ctrl->event_queue[loop].event_type != 0) {
  499. hp_slot = ctrl->event_queue[loop].hp_slot;
  500. p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  501. if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
  502. dbg("button cancel\n");
  503. del_timer(&p_slot->task_event);
  504. switch (p_slot->state) {
  505. case BLINKINGOFF_STATE:
  506. /* Wait for exclusive access to hardware */
  507. mutex_lock(&ctrl->ctrl_lock);
  508. if (PWR_LED(ctrl->ctrlcap)) {
  509. p_slot->hpc_ops->green_led_on(p_slot);
  510. /* Wait for the command to complete */
  511. wait_for_ctrl_irq (ctrl);
  512. }
  513. if (ATTN_LED(ctrl->ctrlcap)) {
  514. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  515. /* Wait for the command to complete */
  516. wait_for_ctrl_irq (ctrl);
  517. }
  518. /* Done with exclusive hardware access */
  519. mutex_unlock(&ctrl->ctrl_lock);
  520. break;
  521. case BLINKINGON_STATE:
  522. /* Wait for exclusive access to hardware */
  523. mutex_lock(&ctrl->ctrl_lock);
  524. if (PWR_LED(ctrl->ctrlcap)) {
  525. p_slot->hpc_ops->green_led_off(p_slot);
  526. /* Wait for the command to complete */
  527. wait_for_ctrl_irq (ctrl);
  528. }
  529. if (ATTN_LED(ctrl->ctrlcap)){
  530. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  531. /* Wait for the command to complete */
  532. wait_for_ctrl_irq (ctrl);
  533. }
  534. /* Done with exclusive hardware access */
  535. mutex_unlock(&ctrl->ctrl_lock);
  536. break;
  537. default:
  538. warn("Not a valid state\n");
  539. return;
  540. }
  541. info(msg_button_cancel, slot_name(p_slot));
  542. p_slot->state = STATIC_STATE;
  543. }
  544. /* ***********Button Pressed (No action on 1st press...) */
  545. else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
  546. if (ATTN_BUTTN(ctrl->ctrlcap)) {
  547. dbg("Button pressed\n");
  548. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  549. if (getstatus) {
  550. /* slot is on */
  551. dbg("slot is on\n");
  552. p_slot->state = BLINKINGOFF_STATE;
  553. info(msg_button_off, slot_name(p_slot));
  554. } else {
  555. /* slot is off */
  556. dbg("slot is off\n");
  557. p_slot->state = BLINKINGON_STATE;
  558. info(msg_button_on, slot_name(p_slot));
  559. }
  560. /* Wait for exclusive access to hardware */
  561. mutex_lock(&ctrl->ctrl_lock);
  562. /* blink green LED and turn off amber */
  563. if (PWR_LED(ctrl->ctrlcap)) {
  564. p_slot->hpc_ops->green_led_blink(p_slot);
  565. /* Wait for the command to complete */
  566. wait_for_ctrl_irq (ctrl);
  567. }
  568. if (ATTN_LED(ctrl->ctrlcap)) {
  569. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  570. /* Wait for the command to complete */
  571. wait_for_ctrl_irq (ctrl);
  572. }
  573. /* Done with exclusive hardware access */
  574. mutex_unlock(&ctrl->ctrl_lock);
  575. init_timer(&p_slot->task_event);
  576. p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
  577. p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
  578. p_slot->task_event.data = (unsigned long) p_slot;
  579. add_timer(&p_slot->task_event);
  580. }
  581. }
  582. /***********POWER FAULT********************/
  583. else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
  584. if (POWER_CTRL(ctrl->ctrlcap)) {
  585. dbg("power fault\n");
  586. /* Wait for exclusive access to hardware */
  587. mutex_lock(&ctrl->ctrl_lock);
  588. if (ATTN_LED(ctrl->ctrlcap)) {
  589. p_slot->hpc_ops->set_attention_status(p_slot, 1);
  590. wait_for_ctrl_irq (ctrl);
  591. }
  592. if (PWR_LED(ctrl->ctrlcap)) {
  593. p_slot->hpc_ops->green_led_off(p_slot);
  594. wait_for_ctrl_irq (ctrl);
  595. }
  596. /* Done with exclusive hardware access */
  597. mutex_unlock(&ctrl->ctrl_lock);
  598. }
  599. }
  600. /***********SURPRISE REMOVAL********************/
  601. else if ((ctrl->event_queue[loop].event_type == INT_PRESENCE_ON) ||
  602. (ctrl->event_queue[loop].event_type == INT_PRESENCE_OFF)) {
  603. if (HP_SUPR_RM(ctrl->ctrlcap)) {
  604. dbg("Surprise Removal\n");
  605. if (p_slot) {
  606. surprise_rm_pending = (unsigned long) p_slot;
  607. up(&event_semaphore);
  608. update_slot_info(p_slot);
  609. }
  610. }
  611. } else {
  612. /* refresh notification */
  613. if (p_slot)
  614. update_slot_info(p_slot);
  615. }
  616. ctrl->event_queue[loop].event_type = 0;
  617. change = 1;
  618. }
  619. } /* End of FOR loop */
  620. }
  621. }
  622. int pciehp_enable_slot(struct slot *p_slot)
  623. {
  624. u8 getstatus = 0;
  625. int rc;
  626. /* Check to see if (latch closed, card present, power off) */
  627. mutex_lock(&p_slot->ctrl->crit_sect);
  628. rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  629. if (rc || !getstatus) {
  630. info("%s: no adapter on slot(%s)\n", __FUNCTION__,
  631. slot_name(p_slot));
  632. mutex_unlock(&p_slot->ctrl->crit_sect);
  633. return -ENODEV;
  634. }
  635. if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
  636. rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  637. if (rc || getstatus) {
  638. info("%s: latch open on slot(%s)\n", __FUNCTION__,
  639. slot_name(p_slot));
  640. mutex_unlock(&p_slot->ctrl->crit_sect);
  641. return -ENODEV;
  642. }
  643. }
  644. if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
  645. rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  646. if (rc || getstatus) {
  647. info("%s: already enabled on slot(%s)\n", __FUNCTION__,
  648. slot_name(p_slot));
  649. mutex_unlock(&p_slot->ctrl->crit_sect);
  650. return -EINVAL;
  651. }
  652. }
  653. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  654. rc = board_added(p_slot);
  655. if (rc) {
  656. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  657. }
  658. update_slot_info(p_slot);
  659. mutex_unlock(&p_slot->ctrl->crit_sect);
  660. return rc;
  661. }
  662. int pciehp_disable_slot(struct slot *p_slot)
  663. {
  664. u8 getstatus = 0;
  665. int ret = 0;
  666. if (!p_slot->ctrl)
  667. return 1;
  668. /* Check to see if (latch closed, card present, power on) */
  669. mutex_lock(&p_slot->ctrl->crit_sect);
  670. if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {
  671. ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  672. if (ret || !getstatus) {
  673. info("%s: no adapter on slot(%s)\n", __FUNCTION__,
  674. slot_name(p_slot));
  675. mutex_unlock(&p_slot->ctrl->crit_sect);
  676. return -ENODEV;
  677. }
  678. }
  679. if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
  680. ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  681. if (ret || getstatus) {
  682. info("%s: latch open on slot(%s)\n", __FUNCTION__,
  683. slot_name(p_slot));
  684. mutex_unlock(&p_slot->ctrl->crit_sect);
  685. return -ENODEV;
  686. }
  687. }
  688. if (POWER_CTRL(p_slot->ctrl->ctrlcap)) {
  689. ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  690. if (ret || !getstatus) {
  691. info("%s: already disabled slot(%s)\n", __FUNCTION__,
  692. slot_name(p_slot));
  693. mutex_unlock(&p_slot->ctrl->crit_sect);
  694. return -EINVAL;
  695. }
  696. }
  697. ret = remove_board(p_slot);
  698. update_slot_info(p_slot);
  699. mutex_unlock(&p_slot->ctrl->crit_sect);
  700. return ret;
  701. }