shpchp_ctrl.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  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/config.h>
  30. #include <linux/module.h>
  31. #include <linux/kernel.h>
  32. #include <linux/types.h>
  33. #include <linux/slab.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/delay.h>
  37. #include <linux/wait.h>
  38. #include <linux/smp_lock.h>
  39. #include <linux/pci.h>
  40. #include "../pci.h"
  41. #include "shpchp.h"
  42. static void interrupt_event_handler(struct controller *ctrl);
  43. static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
  44. static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */
  45. static int event_finished;
  46. static unsigned long pushbutton_pending; /* = 0 */
  47. u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id)
  48. {
  49. struct controller *ctrl = (struct controller *) inst_id;
  50. struct slot *p_slot;
  51. u8 rc = 0;
  52. u8 getstatus;
  53. struct pci_func *func;
  54. struct event_info *taskInfo;
  55. /* Attention Button Change */
  56. dbg("shpchp: Attention button interrupt received.\n");
  57. func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
  58. /* This is the structure that tells the worker thread what to do */
  59. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  60. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  61. p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
  62. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  63. ctrl->next_event = (ctrl->next_event + 1) % 10;
  64. taskInfo->hp_slot = hp_slot;
  65. rc++;
  66. /*
  67. * Button pressed - See if need to TAKE ACTION!!!
  68. */
  69. info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot);
  70. taskInfo->event_type = INT_BUTTON_PRESS;
  71. if ((p_slot->state == BLINKINGON_STATE)
  72. || (p_slot->state == BLINKINGOFF_STATE)) {
  73. /* Cancel if we are still blinking; this means that we press the
  74. * attention again before the 5 sec. limit expires to cancel hot-add
  75. * or hot-remove
  76. */
  77. taskInfo->event_type = INT_BUTTON_CANCEL;
  78. info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot);
  79. } else if ((p_slot->state == POWERON_STATE)
  80. || (p_slot->state == POWEROFF_STATE)) {
  81. /* Ignore if the slot is on power-on or power-off state; this
  82. * means that the previous attention button action to hot-add or
  83. * hot-remove is undergoing
  84. */
  85. taskInfo->event_type = INT_BUTTON_IGNORE;
  86. info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot);
  87. }
  88. if (rc)
  89. up(&event_semaphore); /* signal event thread that new event is posted */
  90. return 0;
  91. }
  92. u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
  93. {
  94. struct controller *ctrl = (struct controller *) inst_id;
  95. struct slot *p_slot;
  96. u8 rc = 0;
  97. u8 getstatus;
  98. struct pci_func *func;
  99. struct event_info *taskInfo;
  100. /* Switch Change */
  101. dbg("shpchp: Switch interrupt received.\n");
  102. func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
  103. /* This is the structure that tells the worker thread
  104. * what to do
  105. */
  106. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  107. ctrl->next_event = (ctrl->next_event + 1) % 10;
  108. taskInfo->hp_slot = hp_slot;
  109. rc++;
  110. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  111. p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
  112. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  113. dbg("%s: Card present %x Power status %x\n", __FUNCTION__,
  114. func->presence_save, func->pwr_save);
  115. if (getstatus) {
  116. /*
  117. * Switch opened
  118. */
  119. info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
  120. func->switch_save = 0;
  121. taskInfo->event_type = INT_SWITCH_OPEN;
  122. if (func->pwr_save && func->presence_save) {
  123. taskInfo->event_type = INT_POWER_FAULT;
  124. err("Surprise Removal of card\n");
  125. }
  126. } else {
  127. /*
  128. * Switch closed
  129. */
  130. info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
  131. func->switch_save = 0x10;
  132. taskInfo->event_type = INT_SWITCH_CLOSE;
  133. }
  134. if (rc)
  135. up(&event_semaphore); /* signal event thread that new event is posted */
  136. return rc;
  137. }
  138. u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
  139. {
  140. struct controller *ctrl = (struct controller *) inst_id;
  141. struct slot *p_slot;
  142. u8 rc = 0;
  143. /*u8 temp_byte;*/
  144. struct pci_func *func;
  145. struct event_info *taskInfo;
  146. /* Presence Change */
  147. dbg("shpchp: Presence/Notify input change.\n");
  148. func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
  149. /* This is the structure that tells the worker thread
  150. * what to do
  151. */
  152. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  153. ctrl->next_event = (ctrl->next_event + 1) % 10;
  154. taskInfo->hp_slot = hp_slot;
  155. rc++;
  156. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  157. /*
  158. * Save the presence state
  159. */
  160. p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
  161. if (func->presence_save) {
  162. /*
  163. * Card Present
  164. */
  165. info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot);
  166. taskInfo->event_type = INT_PRESENCE_ON;
  167. } else {
  168. /*
  169. * Not Present
  170. */
  171. info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot);
  172. taskInfo->event_type = INT_PRESENCE_OFF;
  173. }
  174. if (rc)
  175. up(&event_semaphore); /* signal event thread that new event is posted */
  176. return rc;
  177. }
  178. u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
  179. {
  180. struct controller *ctrl = (struct controller *) inst_id;
  181. struct slot *p_slot;
  182. u8 rc = 0;
  183. struct pci_func *func;
  184. struct event_info *taskInfo;
  185. /* Power fault */
  186. dbg("shpchp: Power fault interrupt received.\n");
  187. func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
  188. /* This is the structure that tells the worker thread
  189. * what to do
  190. */
  191. taskInfo = &(ctrl->event_queue[ctrl->next_event]);
  192. ctrl->next_event = (ctrl->next_event + 1) % 10;
  193. taskInfo->hp_slot = hp_slot;
  194. rc++;
  195. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  196. if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
  197. /*
  198. * Power fault Cleared
  199. */
  200. info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
  201. func->status = 0x00;
  202. taskInfo->event_type = INT_POWER_FAULT_CLEAR;
  203. } else {
  204. /*
  205. * Power fault
  206. */
  207. info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
  208. taskInfo->event_type = INT_POWER_FAULT;
  209. /* set power fault status for this board */
  210. func->status = 0xFF;
  211. info("power fault bit %x set\n", hp_slot);
  212. }
  213. if (rc)
  214. up(&event_semaphore); /* signal event thread that new event is posted */
  215. return rc;
  216. }
  217. /**
  218. * shpchp_slot_create - Creates a node and adds it to the proper bus.
  219. * @busnumber - bus where new node is to be located
  220. *
  221. * Returns pointer to the new node or NULL if unsuccessful
  222. */
  223. struct pci_func *shpchp_slot_create(u8 busnumber)
  224. {
  225. struct pci_func *new_slot;
  226. struct pci_func *next;
  227. new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL);
  228. if (new_slot == NULL) {
  229. return(new_slot);
  230. }
  231. memset(new_slot, 0, sizeof(struct pci_func));
  232. new_slot->next = NULL;
  233. new_slot->configured = 1;
  234. if (shpchp_slot_list[busnumber] == NULL) {
  235. shpchp_slot_list[busnumber] = new_slot;
  236. } else {
  237. next = shpchp_slot_list[busnumber];
  238. while (next->next != NULL)
  239. next = next->next;
  240. next->next = new_slot;
  241. }
  242. return(new_slot);
  243. }
  244. /*
  245. * slot_remove - Removes a node from the linked list of slots.
  246. * @old_slot: slot to remove
  247. *
  248. * Returns 0 if successful, !0 otherwise.
  249. */
  250. static int slot_remove(struct pci_func * old_slot)
  251. {
  252. struct pci_func *next;
  253. if (old_slot == NULL)
  254. return(1);
  255. next = shpchp_slot_list[old_slot->bus];
  256. if (next == NULL) {
  257. return(1);
  258. }
  259. if (next == old_slot) {
  260. shpchp_slot_list[old_slot->bus] = old_slot->next;
  261. kfree(old_slot);
  262. return(0);
  263. }
  264. while ((next->next != old_slot) && (next->next != NULL)) {
  265. next = next->next;
  266. }
  267. if (next->next == old_slot) {
  268. next->next = old_slot->next;
  269. kfree(old_slot);
  270. return(0);
  271. } else
  272. return(2);
  273. }
  274. /**
  275. * bridge_slot_remove - Removes a node from the linked list of slots.
  276. * @bridge: bridge to remove
  277. *
  278. * Returns 0 if successful, !0 otherwise.
  279. */
  280. static int bridge_slot_remove(struct pci_func *bridge)
  281. {
  282. u8 subordinateBus, secondaryBus;
  283. u8 tempBus;
  284. struct pci_func *next;
  285. if (bridge == NULL)
  286. return(1);
  287. secondaryBus = (bridge->config_space[0x06] >> 8) & 0xFF;
  288. subordinateBus = (bridge->config_space[0x06] >> 16) & 0xFF;
  289. for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) {
  290. next = shpchp_slot_list[tempBus];
  291. while (!slot_remove(next)) {
  292. next = shpchp_slot_list[tempBus];
  293. }
  294. }
  295. next = shpchp_slot_list[bridge->bus];
  296. if (next == NULL) {
  297. return(1);
  298. }
  299. if (next == bridge) {
  300. shpchp_slot_list[bridge->bus] = bridge->next;
  301. kfree(bridge);
  302. return(0);
  303. }
  304. while ((next->next != bridge) && (next->next != NULL)) {
  305. next = next->next;
  306. }
  307. if (next->next == bridge) {
  308. next->next = bridge->next;
  309. kfree(bridge);
  310. return(0);
  311. } else
  312. return(2);
  313. }
  314. /**
  315. * shpchp_slot_find - Looks for a node by bus, and device, multiple functions accessed
  316. * @bus: bus to find
  317. * @device: device to find
  318. * @index: is 0 for first function found, 1 for the second...
  319. *
  320. * Returns pointer to the node if successful, %NULL otherwise.
  321. */
  322. struct pci_func *shpchp_slot_find(u8 bus, u8 device, u8 index)
  323. {
  324. int found = -1;
  325. struct pci_func *func;
  326. func = shpchp_slot_list[bus];
  327. if ((func == NULL) || ((func->device == device) && (index == 0)))
  328. return(func);
  329. if (func->device == device)
  330. found++;
  331. while (func->next != NULL) {
  332. func = func->next;
  333. if (func->device == device)
  334. found++;
  335. if (found == index)
  336. return(func);
  337. }
  338. return(NULL);
  339. }
  340. static int is_bridge(struct pci_func * func)
  341. {
  342. /* Check the header type */
  343. if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01)
  344. return 1;
  345. else
  346. return 0;
  347. }
  348. /* The following routines constitute the bulk of the
  349. hotplug controller logic
  350. */
  351. static u32 change_bus_speed(struct controller *ctrl, struct slot *p_slot, enum pci_bus_speed speed)
  352. {
  353. u32 rc = 0;
  354. dbg("%s: change to speed %d\n", __FUNCTION__, speed);
  355. down(&ctrl->crit_sect);
  356. if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) {
  357. err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
  358. up(&ctrl->crit_sect);
  359. return WRONG_BUS_FREQUENCY;
  360. }
  361. wait_for_ctrl_irq (ctrl);
  362. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  363. err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
  364. __FUNCTION__);
  365. err("%s: Error code (%d)\n", __FUNCTION__, rc);
  366. up(&ctrl->crit_sect);
  367. return WRONG_BUS_FREQUENCY;
  368. }
  369. up(&ctrl->crit_sect);
  370. return rc;
  371. }
  372. static u32 fix_bus_speed(struct controller *ctrl, struct slot *pslot, u8 flag,
  373. enum pci_bus_speed asp, enum pci_bus_speed bsp, enum pci_bus_speed msp)
  374. {
  375. u32 rc = 0;
  376. if (flag != 0) { /* Other slots on the same bus are occupied */
  377. if ( asp < bsp ) {
  378. err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bsp, asp);
  379. return WRONG_BUS_FREQUENCY;
  380. }
  381. } else {
  382. /* Other slots on the same bus are empty */
  383. if (msp == bsp) {
  384. /* if adapter_speed >= bus_speed, do nothing */
  385. if (asp < bsp) {
  386. /*
  387. * Try to lower bus speed to accommodate the adapter if other slots
  388. * on the same controller are empty
  389. */
  390. if ((rc = change_bus_speed(ctrl, pslot, asp)))
  391. return rc;
  392. }
  393. } else {
  394. if (asp < msp) {
  395. if ((rc = change_bus_speed(ctrl, pslot, asp)))
  396. return rc;
  397. } else {
  398. if ((rc = change_bus_speed(ctrl, pslot, msp)))
  399. return rc;
  400. }
  401. }
  402. }
  403. return rc;
  404. }
  405. /**
  406. * board_added - Called after a board has been added to the system.
  407. *
  408. * Turns power on for the board
  409. * Configures board
  410. *
  411. */
  412. static u32 board_added(struct pci_func * func, struct controller * ctrl)
  413. {
  414. u8 hp_slot;
  415. u8 slots_not_empty = 0;
  416. u32 rc = 0;
  417. struct slot *p_slot;
  418. enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed;
  419. u8 pi, mode;
  420. p_slot = shpchp_find_slot(ctrl, func->device);
  421. hp_slot = func->device - ctrl->slot_device_offset;
  422. dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);
  423. /* Wait for exclusive access to hardware */
  424. down(&ctrl->crit_sect);
  425. /* Power on slot without connecting to bus */
  426. rc = p_slot->hpc_ops->power_on_slot(p_slot);
  427. if (rc) {
  428. err("%s: Failed to power on slot\n", __FUNCTION__);
  429. /* Done with exclusive hardware access */
  430. up(&ctrl->crit_sect);
  431. return -1;
  432. }
  433. /* Wait for the command to complete */
  434. wait_for_ctrl_irq (ctrl);
  435. rc = p_slot->hpc_ops->check_cmd_status(ctrl);
  436. if (rc) {
  437. err("%s: Failed to power on slot, error code(%d)\n", __FUNCTION__, rc);
  438. /* Done with exclusive hardware access */
  439. up(&ctrl->crit_sect);
  440. return -1;
  441. }
  442. if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) {
  443. if (slots_not_empty)
  444. return WRONG_BUS_FREQUENCY;
  445. if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) {
  446. err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
  447. up(&ctrl->crit_sect);
  448. return WRONG_BUS_FREQUENCY;
  449. }
  450. wait_for_ctrl_irq (ctrl);
  451. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  452. err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
  453. __FUNCTION__);
  454. err("%s: Error code (%d)\n", __FUNCTION__, rc);
  455. up(&ctrl->crit_sect);
  456. return WRONG_BUS_FREQUENCY;
  457. }
  458. /* turn on board, blink green LED, turn off Amber LED */
  459. if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
  460. err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
  461. up(&ctrl->crit_sect);
  462. return rc;
  463. }
  464. wait_for_ctrl_irq (ctrl);
  465. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  466. err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
  467. up(&ctrl->crit_sect);
  468. return rc;
  469. }
  470. }
  471. rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &adapter_speed);
  472. /* 0 = PCI 33Mhz, 1 = PCI 66 Mhz, 2 = PCI-X 66 PA, 4 = PCI-X 66 ECC, */
  473. /* 5 = PCI-X 133 PA, 7 = PCI-X 133 ECC, 0xa = PCI-X 133 Mhz 266, */
  474. /* 0xd = PCI-X 133 Mhz 533 */
  475. /* This encoding is different from the one used in cur_bus_speed & */
  476. /* max_bus_speed */
  477. if (rc || adapter_speed == PCI_SPEED_UNKNOWN) {
  478. err("%s: Can't get adapter speed or bus mode mismatch\n", __FUNCTION__);
  479. /* Done with exclusive hardware access */
  480. up(&ctrl->crit_sect);
  481. return WRONG_BUS_FREQUENCY;
  482. }
  483. rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bus_speed);
  484. if (rc || bus_speed == PCI_SPEED_UNKNOWN) {
  485. err("%s: Can't get bus operation speed\n", __FUNCTION__);
  486. /* Done with exclusive hardware access */
  487. up(&ctrl->crit_sect);
  488. return WRONG_BUS_FREQUENCY;
  489. }
  490. rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed);
  491. if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) {
  492. err("%s: Can't get max bus operation speed\n", __FUNCTION__);
  493. max_bus_speed = bus_speed;
  494. }
  495. /* Done with exclusive hardware access */
  496. up(&ctrl->crit_sect);
  497. if ((rc = p_slot->hpc_ops->get_prog_int(p_slot, &pi))) {
  498. err("%s: Can't get controller programming interface, set it to 1\n", __FUNCTION__);
  499. pi = 1;
  500. }
  501. /* Check if there are other slots or devices on the same bus */
  502. if (!list_empty(&ctrl->pci_dev->subordinate->devices))
  503. slots_not_empty = 1;
  504. dbg("%s: slots_not_empty %d, pi %d\n", __FUNCTION__,
  505. slots_not_empty, pi);
  506. dbg("adapter_speed %d, bus_speed %d, max_bus_speed %d\n",
  507. adapter_speed, bus_speed, max_bus_speed);
  508. if (pi == 2) {
  509. dbg("%s: In PI = %d\n", __FUNCTION__, pi);
  510. if ((rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode))) {
  511. err("%s: Can't get Mode1_ECC, set mode to 0\n", __FUNCTION__);
  512. mode = 0;
  513. }
  514. switch (adapter_speed) {
  515. case PCI_SPEED_133MHz_PCIX_533:
  516. case PCI_SPEED_133MHz_PCIX_266:
  517. if ((bus_speed != adapter_speed) &&
  518. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  519. return rc;
  520. break;
  521. case PCI_SPEED_133MHz_PCIX_ECC:
  522. case PCI_SPEED_133MHz_PCIX:
  523. if (mode) { /* Bus - Mode 1 ECC */
  524. if ((bus_speed != 0x7) &&
  525. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  526. return rc;
  527. } else {
  528. if ((bus_speed != 0x4) &&
  529. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  530. return rc;
  531. }
  532. break;
  533. case PCI_SPEED_66MHz_PCIX_ECC:
  534. case PCI_SPEED_66MHz_PCIX:
  535. if (mode) { /* Bus - Mode 1 ECC */
  536. if ((bus_speed != 0x5) &&
  537. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  538. return rc;
  539. } else {
  540. if ((bus_speed != 0x2) &&
  541. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  542. return rc;
  543. }
  544. break;
  545. case PCI_SPEED_66MHz:
  546. if ((bus_speed != 0x1) &&
  547. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  548. return rc;
  549. break;
  550. case PCI_SPEED_33MHz:
  551. if (bus_speed > 0x0) {
  552. if (slots_not_empty == 0) {
  553. if ((rc = change_bus_speed(ctrl, p_slot, adapter_speed)))
  554. return rc;
  555. } else {
  556. err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
  557. return WRONG_BUS_FREQUENCY;
  558. }
  559. }
  560. break;
  561. default:
  562. err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
  563. return WRONG_BUS_FREQUENCY;
  564. }
  565. } else {
  566. /* If adpater_speed == bus_speed, nothing to do here */
  567. dbg("%s: In PI = %d\n", __FUNCTION__, pi);
  568. if ((adapter_speed != bus_speed) &&
  569. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  570. return rc;
  571. }
  572. down(&ctrl->crit_sect);
  573. /* turn on board, blink green LED, turn off Amber LED */
  574. if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
  575. err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
  576. up(&ctrl->crit_sect);
  577. return rc;
  578. }
  579. wait_for_ctrl_irq (ctrl);
  580. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  581. err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
  582. up(&ctrl->crit_sect);
  583. return rc;
  584. }
  585. up(&ctrl->crit_sect);
  586. /* Wait for ~1 second */
  587. dbg("%s: before long_delay\n", __FUNCTION__);
  588. wait_for_ctrl_irq (ctrl);
  589. dbg("%s: after long_delay\n", __FUNCTION__);
  590. dbg("%s: func status = %x\n", __FUNCTION__, func->status);
  591. /* Check for a power fault */
  592. if (func->status == 0xFF) {
  593. /* power fault occurred, but it was benign */
  594. dbg("%s: power fault\n", __FUNCTION__);
  595. rc = POWER_FAILURE;
  596. func->status = 0;
  597. goto err_exit;
  598. }
  599. if (shpchp_configure_device(p_slot)) {
  600. err("Cannot add device at 0x%x:0x%x\n", p_slot->bus,
  601. p_slot->device);
  602. goto err_exit;
  603. }
  604. shpchp_save_slot_config(ctrl, func);
  605. func->status = 0;
  606. func->switch_save = 0x10;
  607. func->is_a_board = 0x01;
  608. func->pwr_save = 1;
  609. /* Wait for exclusive access to hardware */
  610. down(&ctrl->crit_sect);
  611. p_slot->hpc_ops->green_led_on(p_slot);
  612. /* Wait for the command to complete */
  613. wait_for_ctrl_irq (ctrl);
  614. /* Done with exclusive hardware access */
  615. up(&ctrl->crit_sect);
  616. return 0;
  617. err_exit:
  618. /* Wait for exclusive access to hardware */
  619. down(&ctrl->crit_sect);
  620. /* turn off slot, turn on Amber LED, turn off Green LED */
  621. rc = p_slot->hpc_ops->slot_disable(p_slot);
  622. if (rc) {
  623. err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
  624. /* Done with exclusive hardware access */
  625. up(&ctrl->crit_sect);
  626. return rc;
  627. }
  628. /* Wait for the command to complete */
  629. wait_for_ctrl_irq (ctrl);
  630. rc = p_slot->hpc_ops->check_cmd_status(ctrl);
  631. if (rc) {
  632. err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
  633. /* Done with exclusive hardware access */
  634. up(&ctrl->crit_sect);
  635. return rc;
  636. }
  637. /* Done with exclusive hardware access */
  638. up(&ctrl->crit_sect);
  639. return(rc);
  640. }
  641. /**
  642. * remove_board - Turns off slot and LED's
  643. *
  644. */
  645. static u32 remove_board(struct pci_func *func, struct controller *ctrl)
  646. {
  647. u8 device;
  648. u8 hp_slot;
  649. u32 rc;
  650. struct slot *p_slot;
  651. if (func == NULL)
  652. return(1);
  653. if (shpchp_unconfigure_device(func))
  654. return(1);
  655. device = func->device;
  656. hp_slot = func->device - ctrl->slot_device_offset;
  657. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  658. dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
  659. /* Change status to shutdown */
  660. if (func->is_a_board)
  661. func->status = 0x01;
  662. func->configured = 0;
  663. /* Wait for exclusive access to hardware */
  664. down(&ctrl->crit_sect);
  665. /* turn off slot, turn on Amber LED, turn off Green LED */
  666. rc = p_slot->hpc_ops->slot_disable(p_slot);
  667. if (rc) {
  668. err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
  669. /* Done with exclusive hardware access */
  670. up(&ctrl->crit_sect);
  671. return rc;
  672. }
  673. /* Wait for the command to complete */
  674. wait_for_ctrl_irq (ctrl);
  675. rc = p_slot->hpc_ops->check_cmd_status(ctrl);
  676. if (rc) {
  677. err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
  678. /* Done with exclusive hardware access */
  679. up(&ctrl->crit_sect);
  680. return rc;
  681. }
  682. rc = p_slot->hpc_ops->set_attention_status(p_slot, 0);
  683. if (rc) {
  684. err("%s: Issue of Set Attention command failed\n", __FUNCTION__);
  685. /* Done with exclusive hardware access */
  686. up(&ctrl->crit_sect);
  687. return rc;
  688. }
  689. /* Wait for the command to complete */
  690. wait_for_ctrl_irq (ctrl);
  691. /* Done with exclusive hardware access */
  692. up(&ctrl->crit_sect);
  693. if (ctrl->add_support) {
  694. while (func) {
  695. if (is_bridge(func)) {
  696. dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus,
  697. func->device, func->function);
  698. bridge_slot_remove(func);
  699. } else
  700. dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus,
  701. func->device, func->function);
  702. slot_remove(func);
  703. func = shpchp_slot_find(ctrl->slot_bus, device, 0);
  704. }
  705. /* Setup slot structure with entry for empty slot */
  706. func = shpchp_slot_create(ctrl->slot_bus);
  707. if (func == NULL) {
  708. return(1);
  709. }
  710. func->bus = ctrl->slot_bus;
  711. func->device = device;
  712. func->function = 0;
  713. func->configured = 0;
  714. func->switch_save = 0x10;
  715. func->pwr_save = 0;
  716. func->is_a_board = 0;
  717. }
  718. return 0;
  719. }
  720. static void pushbutton_helper_thread (unsigned long data)
  721. {
  722. pushbutton_pending = data;
  723. up(&event_semaphore);
  724. }
  725. /**
  726. * shpchp_pushbutton_thread
  727. *
  728. * Scheduled procedure to handle blocking stuff for the pushbuttons
  729. * Handles all pending events and exits.
  730. *
  731. */
  732. static void shpchp_pushbutton_thread (unsigned long slot)
  733. {
  734. struct slot *p_slot = (struct slot *) slot;
  735. u8 getstatus;
  736. pushbutton_pending = 0;
  737. if (!p_slot) {
  738. dbg("%s: Error! slot NULL\n", __FUNCTION__);
  739. return;
  740. }
  741. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  742. if (getstatus) {
  743. p_slot->state = POWEROFF_STATE;
  744. dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
  745. shpchp_disable_slot(p_slot);
  746. p_slot->state = STATIC_STATE;
  747. } else {
  748. p_slot->state = POWERON_STATE;
  749. dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
  750. if (shpchp_enable_slot(p_slot)) {
  751. /* Wait for exclusive access to hardware */
  752. down(&p_slot->ctrl->crit_sect);
  753. p_slot->hpc_ops->green_led_off(p_slot);
  754. /* Wait for the command to complete */
  755. wait_for_ctrl_irq (p_slot->ctrl);
  756. /* Done with exclusive hardware access */
  757. up(&p_slot->ctrl->crit_sect);
  758. }
  759. p_slot->state = STATIC_STATE;
  760. }
  761. return;
  762. }
  763. /* this is the main worker thread */
  764. static int event_thread(void* data)
  765. {
  766. struct controller *ctrl;
  767. lock_kernel();
  768. daemonize("shpchpd_event");
  769. unlock_kernel();
  770. while (1) {
  771. dbg("!!!!event_thread sleeping\n");
  772. down_interruptible (&event_semaphore);
  773. dbg("event_thread woken finished = %d\n", event_finished);
  774. if (event_finished || signal_pending(current))
  775. break;
  776. /* Do stuff here */
  777. if (pushbutton_pending)
  778. shpchp_pushbutton_thread(pushbutton_pending);
  779. else
  780. for (ctrl = shpchp_ctrl_list; ctrl; ctrl=ctrl->next)
  781. interrupt_event_handler(ctrl);
  782. }
  783. dbg("event_thread signals exit\n");
  784. up(&event_exit);
  785. return 0;
  786. }
  787. int shpchp_event_start_thread (void)
  788. {
  789. int pid;
  790. /* initialize our semaphores */
  791. init_MUTEX_LOCKED(&event_exit);
  792. event_finished=0;
  793. init_MUTEX_LOCKED(&event_semaphore);
  794. pid = kernel_thread(event_thread, NULL, 0);
  795. if (pid < 0) {
  796. err ("Can't start up our event thread\n");
  797. return -1;
  798. }
  799. dbg("Our event thread pid = %d\n", pid);
  800. return 0;
  801. }
  802. void shpchp_event_stop_thread (void)
  803. {
  804. event_finished = 1;
  805. dbg("event_thread finish command given\n");
  806. up(&event_semaphore);
  807. dbg("wait for event_thread to exit\n");
  808. down(&event_exit);
  809. }
  810. static int update_slot_info (struct slot *slot)
  811. {
  812. struct hotplug_slot_info *info;
  813. int result;
  814. info = kmalloc(sizeof(*info), GFP_KERNEL);
  815. if (!info)
  816. return -ENOMEM;
  817. slot->hpc_ops->get_power_status(slot, &(info->power_status));
  818. slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
  819. slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
  820. slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
  821. result = pci_hp_change_slot_info(slot->hotplug_slot, info);
  822. kfree (info);
  823. return result;
  824. }
  825. static void interrupt_event_handler(struct controller *ctrl)
  826. {
  827. int loop = 0;
  828. int change = 1;
  829. struct pci_func *func;
  830. u8 hp_slot;
  831. u8 getstatus;
  832. struct slot *p_slot;
  833. dbg("%s:\n", __FUNCTION__);
  834. while (change) {
  835. change = 0;
  836. for (loop = 0; loop < 10; loop++) {
  837. if (ctrl->event_queue[loop].event_type != 0) {
  838. dbg("%s:loop %x event_type %x\n", __FUNCTION__, loop,
  839. ctrl->event_queue[loop].event_type);
  840. hp_slot = ctrl->event_queue[loop].hp_slot;
  841. func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
  842. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  843. dbg("%s: hp_slot %d, func %p, p_slot %p\n", __FUNCTION__, hp_slot, func, p_slot);
  844. if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
  845. dbg("%s: button cancel\n", __FUNCTION__);
  846. del_timer(&p_slot->task_event);
  847. switch (p_slot->state) {
  848. case BLINKINGOFF_STATE:
  849. /* Wait for exclusive access to hardware */
  850. down(&ctrl->crit_sect);
  851. p_slot->hpc_ops->green_led_on(p_slot);
  852. /* Wait for the command to complete */
  853. wait_for_ctrl_irq (ctrl);
  854. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  855. /* Wait for the command to complete */
  856. wait_for_ctrl_irq (ctrl);
  857. /* Done with exclusive hardware access */
  858. up(&ctrl->crit_sect);
  859. break;
  860. case BLINKINGON_STATE:
  861. /* Wait for exclusive access to hardware */
  862. down(&ctrl->crit_sect);
  863. p_slot->hpc_ops->green_led_off(p_slot);
  864. /* Wait for the command to complete */
  865. wait_for_ctrl_irq (ctrl);
  866. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  867. /* Wait for the command to complete */
  868. wait_for_ctrl_irq (ctrl);
  869. /* Done with exclusive hardware access */
  870. up(&ctrl->crit_sect);
  871. break;
  872. default:
  873. warn("Not a valid state\n");
  874. return;
  875. }
  876. info(msg_button_cancel, p_slot->number);
  877. p_slot->state = STATIC_STATE;
  878. } else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
  879. /* Button Pressed (No action on 1st press...) */
  880. dbg("%s: Button pressed\n", __FUNCTION__);
  881. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  882. if (getstatus) {
  883. /* slot is on */
  884. dbg("%s: slot is on\n", __FUNCTION__);
  885. p_slot->state = BLINKINGOFF_STATE;
  886. info(msg_button_off, p_slot->number);
  887. } else {
  888. /* slot is off */
  889. dbg("%s: slot is off\n", __FUNCTION__);
  890. p_slot->state = BLINKINGON_STATE;
  891. info(msg_button_on, p_slot->number);
  892. }
  893. /* Wait for exclusive access to hardware */
  894. down(&ctrl->crit_sect);
  895. /* blink green LED and turn off amber */
  896. p_slot->hpc_ops->green_led_blink(p_slot);
  897. /* Wait for the command to complete */
  898. wait_for_ctrl_irq (ctrl);
  899. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  900. /* Wait for the command to complete */
  901. wait_for_ctrl_irq (ctrl);
  902. /* Done with exclusive hardware access */
  903. up(&ctrl->crit_sect);
  904. init_timer(&p_slot->task_event);
  905. p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
  906. p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
  907. p_slot->task_event.data = (unsigned long) p_slot;
  908. dbg("%s: add_timer p_slot = %p\n", __FUNCTION__,(void *) p_slot);
  909. add_timer(&p_slot->task_event);
  910. } else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
  911. /***********POWER FAULT********************/
  912. dbg("%s: power fault\n", __FUNCTION__);
  913. /* Wait for exclusive access to hardware */
  914. down(&ctrl->crit_sect);
  915. p_slot->hpc_ops->set_attention_status(p_slot, 1);
  916. /* Wait for the command to complete */
  917. wait_for_ctrl_irq (ctrl);
  918. p_slot->hpc_ops->green_led_off(p_slot);
  919. /* Wait for the command to complete */
  920. wait_for_ctrl_irq (ctrl);
  921. /* Done with exclusive hardware access */
  922. up(&ctrl->crit_sect);
  923. } else {
  924. /* refresh notification */
  925. if (p_slot)
  926. update_slot_info(p_slot);
  927. }
  928. ctrl->event_queue[loop].event_type = 0;
  929. change = 1;
  930. }
  931. } /* End of FOR loop */
  932. }
  933. return;
  934. }
  935. int shpchp_enable_slot (struct slot *p_slot)
  936. {
  937. u8 getstatus = 0;
  938. int rc;
  939. struct pci_func *func;
  940. func = shpchp_slot_find(p_slot->bus, p_slot->device, 0);
  941. if (!func) {
  942. dbg("%s: Error! slot NULL\n", __FUNCTION__);
  943. return -ENODEV;
  944. }
  945. /* Check to see if (latch closed, card present, power off) */
  946. down(&p_slot->ctrl->crit_sect);
  947. rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  948. if (rc || !getstatus) {
  949. info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
  950. up(&p_slot->ctrl->crit_sect);
  951. return -ENODEV;
  952. }
  953. rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  954. if (rc || getstatus) {
  955. info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
  956. up(&p_slot->ctrl->crit_sect);
  957. return -ENODEV;
  958. }
  959. rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  960. if (rc || getstatus) {
  961. info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
  962. up(&p_slot->ctrl->crit_sect);
  963. return -ENODEV;
  964. }
  965. up(&p_slot->ctrl->crit_sect);
  966. slot_remove(func);
  967. func = shpchp_slot_create(p_slot->bus);
  968. if (func == NULL)
  969. return -ENOMEM;
  970. func->bus = p_slot->bus;
  971. func->device = p_slot->device;
  972. func->function = 0;
  973. func->configured = 0;
  974. func->is_a_board = 1;
  975. /* We have to save the presence info for these slots */
  976. p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
  977. p_slot->hpc_ops->get_power_status(p_slot, &(func->pwr_save));
  978. dbg("%s: func->pwr_save %x\n", __FUNCTION__, func->pwr_save);
  979. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  980. func->switch_save = !getstatus? 0x10:0;
  981. rc = board_added(func, p_slot->ctrl);
  982. if (rc) {
  983. if (is_bridge(func))
  984. bridge_slot_remove(func);
  985. else
  986. slot_remove(func);
  987. /* Setup slot structure with entry for empty slot */
  988. func = shpchp_slot_create(p_slot->bus);
  989. if (func == NULL)
  990. return -ENOMEM; /* Out of memory */
  991. func->bus = p_slot->bus;
  992. func->device = p_slot->device;
  993. func->function = 0;
  994. func->configured = 0;
  995. func->is_a_board = 1;
  996. /* We have to save the presence info for these slots */
  997. p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
  998. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  999. func->switch_save = !getstatus? 0x10:0;
  1000. }
  1001. if (p_slot)
  1002. update_slot_info(p_slot);
  1003. return rc;
  1004. }
  1005. int shpchp_disable_slot (struct slot *p_slot)
  1006. {
  1007. u8 class_code, header_type, BCR;
  1008. u8 index = 0;
  1009. u8 getstatus = 0;
  1010. u32 rc = 0;
  1011. int ret = 0;
  1012. unsigned int devfn;
  1013. struct pci_bus *pci_bus;
  1014. struct pci_func *func;
  1015. if (!p_slot->ctrl)
  1016. return -ENODEV;
  1017. pci_bus = p_slot->ctrl->pci_dev->subordinate;
  1018. /* Check to see if (latch closed, card present, power on) */
  1019. down(&p_slot->ctrl->crit_sect);
  1020. ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  1021. if (ret || !getstatus) {
  1022. info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
  1023. up(&p_slot->ctrl->crit_sect);
  1024. return -ENODEV;
  1025. }
  1026. ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  1027. if (ret || getstatus) {
  1028. info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
  1029. up(&p_slot->ctrl->crit_sect);
  1030. return -ENODEV;
  1031. }
  1032. ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  1033. if (ret || !getstatus) {
  1034. info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
  1035. up(&p_slot->ctrl->crit_sect);
  1036. return -ENODEV;
  1037. }
  1038. up(&p_slot->ctrl->crit_sect);
  1039. func = shpchp_slot_find(p_slot->bus, p_slot->device, index++);
  1040. /* Make sure there are no video controllers here
  1041. * for all func of p_slot
  1042. */
  1043. while (func && !rc) {
  1044. pci_bus->number = func->bus;
  1045. devfn = PCI_DEVFN(func->device, func->function);
  1046. /* Check the Class Code */
  1047. rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
  1048. if (rc)
  1049. return -ENODEV;
  1050. if (class_code == PCI_BASE_CLASS_DISPLAY) {
  1051. /* Display/Video adapter (not supported) */
  1052. rc = REMOVE_NOT_SUPPORTED;
  1053. } else {
  1054. /* See if it's a bridge */
  1055. rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &header_type);
  1056. if (rc)
  1057. return -ENODEV;
  1058. /* If it's a bridge, check the VGA Enable bit */
  1059. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
  1060. rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR);
  1061. if (rc)
  1062. return -ENODEV;
  1063. /* If the VGA Enable bit is set, remove isn't supported */
  1064. if (BCR & PCI_BRIDGE_CTL_VGA) {
  1065. rc = REMOVE_NOT_SUPPORTED;
  1066. }
  1067. }
  1068. }
  1069. func = shpchp_slot_find(p_slot->bus, p_slot->device, index++);
  1070. }
  1071. func = shpchp_slot_find(p_slot->bus, p_slot->device, 0);
  1072. if ((func != NULL) && !rc) {
  1073. rc = remove_board(func, p_slot->ctrl);
  1074. } else if (!rc)
  1075. rc = -ENODEV;
  1076. if (p_slot)
  1077. update_slot_info(p_slot);
  1078. return rc;
  1079. }