shpchp_ctrl.c 22 KB

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