shpchp_ctrl.c 34 KB

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