shpchp_ctrl.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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. * @secondaryBus: secondary PCI bus number for bridge being removed
  278. * @subordinateBus: subordinate PCI bus number for bridge being removed
  279. *
  280. * Returns 0 if successful, !0 otherwise.
  281. */
  282. static int bridge_slot_remove(struct pci_func *bridge, u8 secondaryBus,
  283. u8 subordinateBus)
  284. {
  285. u8 tempBus;
  286. struct pci_func *next;
  287. if (bridge == NULL)
  288. return(1);
  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, struct controller *ctrl)
  341. {
  342. u8 hdr_type;
  343. struct pci_bus *bus = ctrl->pci_dev->subordinate;
  344. /*
  345. * Note: device may have just been hot-added and not yet scanned
  346. * by the pci core, so its pci_dev structure may not exist yet
  347. */
  348. pci_bus_read_config_byte(bus, PCI_DEVFN(func->device, func->function),
  349. PCI_HEADER_TYPE, &hdr_type);
  350. if ((hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE)
  351. return 1;
  352. else
  353. return 0;
  354. }
  355. /* The following routines constitute the bulk of the
  356. hotplug controller logic
  357. */
  358. static u32 change_bus_speed(struct controller *ctrl, struct slot *p_slot, enum pci_bus_speed speed)
  359. {
  360. u32 rc = 0;
  361. dbg("%s: change to speed %d\n", __FUNCTION__, speed);
  362. down(&ctrl->crit_sect);
  363. if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) {
  364. err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
  365. up(&ctrl->crit_sect);
  366. return WRONG_BUS_FREQUENCY;
  367. }
  368. wait_for_ctrl_irq (ctrl);
  369. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  370. err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
  371. __FUNCTION__);
  372. err("%s: Error code (%d)\n", __FUNCTION__, rc);
  373. up(&ctrl->crit_sect);
  374. return WRONG_BUS_FREQUENCY;
  375. }
  376. up(&ctrl->crit_sect);
  377. return rc;
  378. }
  379. static u32 fix_bus_speed(struct controller *ctrl, struct slot *pslot, u8 flag,
  380. enum pci_bus_speed asp, enum pci_bus_speed bsp, enum pci_bus_speed msp)
  381. {
  382. u32 rc = 0;
  383. if (flag != 0) { /* Other slots on the same bus are occupied */
  384. if ( asp < bsp ) {
  385. err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bsp, asp);
  386. return WRONG_BUS_FREQUENCY;
  387. }
  388. } else {
  389. /* Other slots on the same bus are empty */
  390. if (msp == bsp) {
  391. /* if adapter_speed >= bus_speed, do nothing */
  392. if (asp < bsp) {
  393. /*
  394. * Try to lower bus speed to accommodate the adapter if other slots
  395. * on the same controller are empty
  396. */
  397. if ((rc = change_bus_speed(ctrl, pslot, asp)))
  398. return rc;
  399. }
  400. } else {
  401. if (asp < msp) {
  402. if ((rc = change_bus_speed(ctrl, pslot, asp)))
  403. return rc;
  404. } else {
  405. if ((rc = change_bus_speed(ctrl, pslot, msp)))
  406. return rc;
  407. }
  408. }
  409. }
  410. return rc;
  411. }
  412. /**
  413. * board_added - Called after a board has been added to the system.
  414. *
  415. * Turns power on for the board
  416. * Configures board
  417. *
  418. */
  419. static u32 board_added(struct pci_func * func, struct controller * ctrl)
  420. {
  421. u8 hp_slot;
  422. u8 slots_not_empty = 0;
  423. u32 rc = 0;
  424. struct slot *p_slot;
  425. enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed;
  426. u8 pi, mode;
  427. p_slot = shpchp_find_slot(ctrl, func->device);
  428. hp_slot = func->device - ctrl->slot_device_offset;
  429. dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);
  430. /* Wait for exclusive access to hardware */
  431. down(&ctrl->crit_sect);
  432. /* Power on slot without connecting to bus */
  433. rc = p_slot->hpc_ops->power_on_slot(p_slot);
  434. if (rc) {
  435. err("%s: Failed to power on slot\n", __FUNCTION__);
  436. /* Done with exclusive hardware access */
  437. up(&ctrl->crit_sect);
  438. return -1;
  439. }
  440. /* Wait for the command to complete */
  441. wait_for_ctrl_irq (ctrl);
  442. rc = p_slot->hpc_ops->check_cmd_status(ctrl);
  443. if (rc) {
  444. err("%s: Failed to power on slot, error code(%d)\n", __FUNCTION__, rc);
  445. /* Done with exclusive hardware access */
  446. up(&ctrl->crit_sect);
  447. return -1;
  448. }
  449. if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) {
  450. if (slots_not_empty)
  451. return WRONG_BUS_FREQUENCY;
  452. if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) {
  453. err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
  454. up(&ctrl->crit_sect);
  455. return WRONG_BUS_FREQUENCY;
  456. }
  457. wait_for_ctrl_irq (ctrl);
  458. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  459. err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
  460. __FUNCTION__);
  461. err("%s: Error code (%d)\n", __FUNCTION__, rc);
  462. up(&ctrl->crit_sect);
  463. return WRONG_BUS_FREQUENCY;
  464. }
  465. /* turn on board, blink green LED, turn off Amber LED */
  466. if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
  467. err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
  468. up(&ctrl->crit_sect);
  469. return rc;
  470. }
  471. wait_for_ctrl_irq (ctrl);
  472. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  473. err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
  474. up(&ctrl->crit_sect);
  475. return rc;
  476. }
  477. }
  478. rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &adapter_speed);
  479. /* 0 = PCI 33Mhz, 1 = PCI 66 Mhz, 2 = PCI-X 66 PA, 4 = PCI-X 66 ECC, */
  480. /* 5 = PCI-X 133 PA, 7 = PCI-X 133 ECC, 0xa = PCI-X 133 Mhz 266, */
  481. /* 0xd = PCI-X 133 Mhz 533 */
  482. /* This encoding is different from the one used in cur_bus_speed & */
  483. /* max_bus_speed */
  484. if (rc || adapter_speed == PCI_SPEED_UNKNOWN) {
  485. err("%s: Can't get adapter speed or bus mode mismatch\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_cur_bus_speed(p_slot, &bus_speed);
  491. if (rc || bus_speed == PCI_SPEED_UNKNOWN) {
  492. err("%s: Can't get bus operation speed\n", __FUNCTION__);
  493. /* Done with exclusive hardware access */
  494. up(&ctrl->crit_sect);
  495. return WRONG_BUS_FREQUENCY;
  496. }
  497. rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed);
  498. if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) {
  499. err("%s: Can't get max bus operation speed\n", __FUNCTION__);
  500. max_bus_speed = bus_speed;
  501. }
  502. /* Done with exclusive hardware access */
  503. up(&ctrl->crit_sect);
  504. if ((rc = p_slot->hpc_ops->get_prog_int(p_slot, &pi))) {
  505. err("%s: Can't get controller programming interface, set it to 1\n", __FUNCTION__);
  506. pi = 1;
  507. }
  508. /* Check if there are other slots or devices on the same bus */
  509. if (!list_empty(&ctrl->pci_dev->subordinate->devices))
  510. slots_not_empty = 1;
  511. dbg("%s: slots_not_empty %d, pi %d\n", __FUNCTION__,
  512. slots_not_empty, pi);
  513. dbg("adapter_speed %d, bus_speed %d, max_bus_speed %d\n",
  514. adapter_speed, bus_speed, max_bus_speed);
  515. if (pi == 2) {
  516. dbg("%s: In PI = %d\n", __FUNCTION__, pi);
  517. if ((rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode))) {
  518. err("%s: Can't get Mode1_ECC, set mode to 0\n", __FUNCTION__);
  519. mode = 0;
  520. }
  521. switch (adapter_speed) {
  522. case PCI_SPEED_133MHz_PCIX_533:
  523. case PCI_SPEED_133MHz_PCIX_266:
  524. if ((bus_speed != adapter_speed) &&
  525. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  526. return rc;
  527. break;
  528. case PCI_SPEED_133MHz_PCIX_ECC:
  529. case PCI_SPEED_133MHz_PCIX:
  530. if (mode) { /* Bus - Mode 1 ECC */
  531. if ((bus_speed != 0x7) &&
  532. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  533. return rc;
  534. } else {
  535. if ((bus_speed != 0x4) &&
  536. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  537. return rc;
  538. }
  539. break;
  540. case PCI_SPEED_66MHz_PCIX_ECC:
  541. case PCI_SPEED_66MHz_PCIX:
  542. if (mode) { /* Bus - Mode 1 ECC */
  543. if ((bus_speed != 0x5) &&
  544. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  545. return rc;
  546. } else {
  547. if ((bus_speed != 0x2) &&
  548. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  549. return rc;
  550. }
  551. break;
  552. case PCI_SPEED_66MHz:
  553. if ((bus_speed != 0x1) &&
  554. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  555. return rc;
  556. break;
  557. case PCI_SPEED_33MHz:
  558. if (bus_speed > 0x0) {
  559. if (slots_not_empty == 0) {
  560. if ((rc = change_bus_speed(ctrl, p_slot, adapter_speed)))
  561. return rc;
  562. } else {
  563. err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
  564. return WRONG_BUS_FREQUENCY;
  565. }
  566. }
  567. break;
  568. default:
  569. err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
  570. return WRONG_BUS_FREQUENCY;
  571. }
  572. } else {
  573. /* If adpater_speed == bus_speed, nothing to do here */
  574. dbg("%s: In PI = %d\n", __FUNCTION__, pi);
  575. if ((adapter_speed != bus_speed) &&
  576. ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
  577. return rc;
  578. }
  579. down(&ctrl->crit_sect);
  580. /* turn on board, blink green LED, turn off Amber LED */
  581. if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
  582. err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
  583. up(&ctrl->crit_sect);
  584. return rc;
  585. }
  586. wait_for_ctrl_irq (ctrl);
  587. if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
  588. err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
  589. up(&ctrl->crit_sect);
  590. return rc;
  591. }
  592. up(&ctrl->crit_sect);
  593. /* Wait for ~1 second */
  594. dbg("%s: before long_delay\n", __FUNCTION__);
  595. wait_for_ctrl_irq (ctrl);
  596. dbg("%s: after long_delay\n", __FUNCTION__);
  597. dbg("%s: func status = %x\n", __FUNCTION__, func->status);
  598. /* Check for a power fault */
  599. if (func->status == 0xFF) {
  600. /* power fault occurred, but it was benign */
  601. dbg("%s: power fault\n", __FUNCTION__);
  602. rc = POWER_FAILURE;
  603. func->status = 0;
  604. goto err_exit;
  605. }
  606. if (shpchp_configure_device(p_slot)) {
  607. err("Cannot add device at 0x%x:0x%x\n", p_slot->bus,
  608. p_slot->device);
  609. goto err_exit;
  610. }
  611. func->status = 0;
  612. func->switch_save = 0x10;
  613. func->is_a_board = 0x01;
  614. func->pwr_save = 1;
  615. /* Wait for exclusive access to hardware */
  616. down(&ctrl->crit_sect);
  617. p_slot->hpc_ops->green_led_on(p_slot);
  618. /* Wait for the command to complete */
  619. wait_for_ctrl_irq (ctrl);
  620. /* Done with exclusive hardware access */
  621. up(&ctrl->crit_sect);
  622. return 0;
  623. err_exit:
  624. /* Wait for exclusive access to hardware */
  625. down(&ctrl->crit_sect);
  626. /* turn off slot, turn on Amber LED, turn off Green LED */
  627. rc = p_slot->hpc_ops->slot_disable(p_slot);
  628. if (rc) {
  629. err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
  630. /* Done with exclusive hardware access */
  631. up(&ctrl->crit_sect);
  632. return rc;
  633. }
  634. /* Wait for the command to complete */
  635. wait_for_ctrl_irq (ctrl);
  636. rc = p_slot->hpc_ops->check_cmd_status(ctrl);
  637. if (rc) {
  638. err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
  639. /* Done with exclusive hardware access */
  640. up(&ctrl->crit_sect);
  641. return rc;
  642. }
  643. /* Done with exclusive hardware access */
  644. up(&ctrl->crit_sect);
  645. return(rc);
  646. }
  647. /**
  648. * remove_board - Turns off slot and LED's
  649. *
  650. */
  651. static u32 remove_board(struct pci_func *func, struct controller *ctrl)
  652. {
  653. u8 device;
  654. u8 hp_slot;
  655. u32 rc;
  656. struct slot *p_slot;
  657. u8 secondary = 0, subordinate = 0;
  658. int remove_bridge;
  659. if (func == NULL)
  660. return(1);
  661. if ((remove_bridge = is_bridge(func, ctrl))) {
  662. /* Stash away bus information before we destroy it */
  663. secondary = func->pci_dev->subordinate->secondary;
  664. subordinate = func->pci_dev->subordinate->subordinate;
  665. }
  666. if (shpchp_unconfigure_device(func))
  667. return(1);
  668. device = func->device;
  669. hp_slot = func->device - ctrl->slot_device_offset;
  670. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  671. dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
  672. /* Change status to shutdown */
  673. if (func->is_a_board)
  674. func->status = 0x01;
  675. func->configured = 0;
  676. /* Wait for exclusive access to hardware */
  677. down(&ctrl->crit_sect);
  678. /* turn off slot, turn on Amber LED, turn off Green LED */
  679. rc = p_slot->hpc_ops->slot_disable(p_slot);
  680. if (rc) {
  681. err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
  682. /* Done with exclusive hardware access */
  683. up(&ctrl->crit_sect);
  684. return rc;
  685. }
  686. /* Wait for the command to complete */
  687. wait_for_ctrl_irq (ctrl);
  688. rc = p_slot->hpc_ops->check_cmd_status(ctrl);
  689. if (rc) {
  690. err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
  691. /* Done with exclusive hardware access */
  692. up(&ctrl->crit_sect);
  693. return rc;
  694. }
  695. rc = p_slot->hpc_ops->set_attention_status(p_slot, 0);
  696. if (rc) {
  697. err("%s: Issue of Set Attention command failed\n", __FUNCTION__);
  698. /* Done with exclusive hardware access */
  699. up(&ctrl->crit_sect);
  700. return rc;
  701. }
  702. /* Wait for the command to complete */
  703. wait_for_ctrl_irq (ctrl);
  704. /* Done with exclusive hardware access */
  705. up(&ctrl->crit_sect);
  706. if (ctrl->add_support) {
  707. while (func) {
  708. if (remove_bridge) {
  709. dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus,
  710. func->device, func->function);
  711. bridge_slot_remove(func, secondary,
  712. subordinate);
  713. } else
  714. dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus,
  715. func->device, func->function);
  716. slot_remove(func);
  717. func = shpchp_slot_find(ctrl->slot_bus, device, 0);
  718. }
  719. /* Setup slot structure with entry for empty slot */
  720. func = shpchp_slot_create(ctrl->slot_bus);
  721. if (func == NULL) {
  722. return(1);
  723. }
  724. func->bus = ctrl->slot_bus;
  725. func->device = device;
  726. func->function = 0;
  727. func->configured = 0;
  728. func->switch_save = 0x10;
  729. func->pwr_save = 0;
  730. func->is_a_board = 0;
  731. }
  732. return 0;
  733. }
  734. static void pushbutton_helper_thread (unsigned long data)
  735. {
  736. pushbutton_pending = data;
  737. up(&event_semaphore);
  738. }
  739. /**
  740. * shpchp_pushbutton_thread
  741. *
  742. * Scheduled procedure to handle blocking stuff for the pushbuttons
  743. * Handles all pending events and exits.
  744. *
  745. */
  746. static void shpchp_pushbutton_thread (unsigned long slot)
  747. {
  748. struct slot *p_slot = (struct slot *) slot;
  749. u8 getstatus;
  750. pushbutton_pending = 0;
  751. if (!p_slot) {
  752. dbg("%s: Error! slot NULL\n", __FUNCTION__);
  753. return;
  754. }
  755. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  756. if (getstatus) {
  757. p_slot->state = POWEROFF_STATE;
  758. dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
  759. shpchp_disable_slot(p_slot);
  760. p_slot->state = STATIC_STATE;
  761. } else {
  762. p_slot->state = POWERON_STATE;
  763. dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
  764. if (shpchp_enable_slot(p_slot)) {
  765. /* Wait for exclusive access to hardware */
  766. down(&p_slot->ctrl->crit_sect);
  767. p_slot->hpc_ops->green_led_off(p_slot);
  768. /* Wait for the command to complete */
  769. wait_for_ctrl_irq (p_slot->ctrl);
  770. /* Done with exclusive hardware access */
  771. up(&p_slot->ctrl->crit_sect);
  772. }
  773. p_slot->state = STATIC_STATE;
  774. }
  775. return;
  776. }
  777. /* this is the main worker thread */
  778. static int event_thread(void* data)
  779. {
  780. struct controller *ctrl;
  781. lock_kernel();
  782. daemonize("shpchpd_event");
  783. unlock_kernel();
  784. while (1) {
  785. dbg("!!!!event_thread sleeping\n");
  786. down_interruptible (&event_semaphore);
  787. dbg("event_thread woken finished = %d\n", event_finished);
  788. if (event_finished || signal_pending(current))
  789. break;
  790. /* Do stuff here */
  791. if (pushbutton_pending)
  792. shpchp_pushbutton_thread(pushbutton_pending);
  793. else
  794. for (ctrl = shpchp_ctrl_list; ctrl; ctrl=ctrl->next)
  795. interrupt_event_handler(ctrl);
  796. }
  797. dbg("event_thread signals exit\n");
  798. up(&event_exit);
  799. return 0;
  800. }
  801. int shpchp_event_start_thread (void)
  802. {
  803. int pid;
  804. /* initialize our semaphores */
  805. init_MUTEX_LOCKED(&event_exit);
  806. event_finished=0;
  807. init_MUTEX_LOCKED(&event_semaphore);
  808. pid = kernel_thread(event_thread, NULL, 0);
  809. if (pid < 0) {
  810. err ("Can't start up our event thread\n");
  811. return -1;
  812. }
  813. dbg("Our event thread pid = %d\n", pid);
  814. return 0;
  815. }
  816. void shpchp_event_stop_thread (void)
  817. {
  818. event_finished = 1;
  819. dbg("event_thread finish command given\n");
  820. up(&event_semaphore);
  821. dbg("wait for event_thread to exit\n");
  822. down(&event_exit);
  823. }
  824. static int update_slot_info (struct slot *slot)
  825. {
  826. struct hotplug_slot_info *info;
  827. int result;
  828. info = kmalloc(sizeof(*info), GFP_KERNEL);
  829. if (!info)
  830. return -ENOMEM;
  831. slot->hpc_ops->get_power_status(slot, &(info->power_status));
  832. slot->hpc_ops->get_attention_status(slot, &(info->attention_status));
  833. slot->hpc_ops->get_latch_status(slot, &(info->latch_status));
  834. slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status));
  835. result = pci_hp_change_slot_info(slot->hotplug_slot, info);
  836. kfree (info);
  837. return result;
  838. }
  839. static void interrupt_event_handler(struct controller *ctrl)
  840. {
  841. int loop = 0;
  842. int change = 1;
  843. struct pci_func *func;
  844. u8 hp_slot;
  845. u8 getstatus;
  846. struct slot *p_slot;
  847. dbg("%s:\n", __FUNCTION__);
  848. while (change) {
  849. change = 0;
  850. for (loop = 0; loop < 10; loop++) {
  851. if (ctrl->event_queue[loop].event_type != 0) {
  852. dbg("%s:loop %x event_type %x\n", __FUNCTION__, loop,
  853. ctrl->event_queue[loop].event_type);
  854. hp_slot = ctrl->event_queue[loop].hp_slot;
  855. func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
  856. p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
  857. dbg("%s: hp_slot %d, func %p, p_slot %p\n", __FUNCTION__, hp_slot, func, p_slot);
  858. if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
  859. dbg("%s: button cancel\n", __FUNCTION__);
  860. del_timer(&p_slot->task_event);
  861. switch (p_slot->state) {
  862. case BLINKINGOFF_STATE:
  863. /* Wait for exclusive access to hardware */
  864. down(&ctrl->crit_sect);
  865. p_slot->hpc_ops->green_led_on(p_slot);
  866. /* Wait for the command to complete */
  867. wait_for_ctrl_irq (ctrl);
  868. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  869. /* Wait for the command to complete */
  870. wait_for_ctrl_irq (ctrl);
  871. /* Done with exclusive hardware access */
  872. up(&ctrl->crit_sect);
  873. break;
  874. case BLINKINGON_STATE:
  875. /* Wait for exclusive access to hardware */
  876. down(&ctrl->crit_sect);
  877. p_slot->hpc_ops->green_led_off(p_slot);
  878. /* Wait for the command to complete */
  879. wait_for_ctrl_irq (ctrl);
  880. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  881. /* Wait for the command to complete */
  882. wait_for_ctrl_irq (ctrl);
  883. /* Done with exclusive hardware access */
  884. up(&ctrl->crit_sect);
  885. break;
  886. default:
  887. warn("Not a valid state\n");
  888. return;
  889. }
  890. info(msg_button_cancel, p_slot->number);
  891. p_slot->state = STATIC_STATE;
  892. } else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
  893. /* Button Pressed (No action on 1st press...) */
  894. dbg("%s: Button pressed\n", __FUNCTION__);
  895. p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  896. if (getstatus) {
  897. /* slot is on */
  898. dbg("%s: slot is on\n", __FUNCTION__);
  899. p_slot->state = BLINKINGOFF_STATE;
  900. info(msg_button_off, p_slot->number);
  901. } else {
  902. /* slot is off */
  903. dbg("%s: slot is off\n", __FUNCTION__);
  904. p_slot->state = BLINKINGON_STATE;
  905. info(msg_button_on, p_slot->number);
  906. }
  907. /* Wait for exclusive access to hardware */
  908. down(&ctrl->crit_sect);
  909. /* blink green LED and turn off amber */
  910. p_slot->hpc_ops->green_led_blink(p_slot);
  911. /* Wait for the command to complete */
  912. wait_for_ctrl_irq (ctrl);
  913. p_slot->hpc_ops->set_attention_status(p_slot, 0);
  914. /* Wait for the command to complete */
  915. wait_for_ctrl_irq (ctrl);
  916. /* Done with exclusive hardware access */
  917. up(&ctrl->crit_sect);
  918. init_timer(&p_slot->task_event);
  919. p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
  920. p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
  921. p_slot->task_event.data = (unsigned long) p_slot;
  922. dbg("%s: add_timer p_slot = %p\n", __FUNCTION__,(void *) p_slot);
  923. add_timer(&p_slot->task_event);
  924. } else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
  925. /***********POWER FAULT********************/
  926. dbg("%s: power fault\n", __FUNCTION__);
  927. /* Wait for exclusive access to hardware */
  928. down(&ctrl->crit_sect);
  929. p_slot->hpc_ops->set_attention_status(p_slot, 1);
  930. /* Wait for the command to complete */
  931. wait_for_ctrl_irq (ctrl);
  932. p_slot->hpc_ops->green_led_off(p_slot);
  933. /* Wait for the command to complete */
  934. wait_for_ctrl_irq (ctrl);
  935. /* Done with exclusive hardware access */
  936. up(&ctrl->crit_sect);
  937. } else {
  938. /* refresh notification */
  939. if (p_slot)
  940. update_slot_info(p_slot);
  941. }
  942. ctrl->event_queue[loop].event_type = 0;
  943. change = 1;
  944. }
  945. } /* End of FOR loop */
  946. }
  947. return;
  948. }
  949. int shpchp_enable_slot (struct slot *p_slot)
  950. {
  951. u8 getstatus = 0;
  952. int rc;
  953. struct pci_func *func;
  954. func = shpchp_slot_find(p_slot->bus, p_slot->device, 0);
  955. if (!func) {
  956. dbg("%s: Error! slot NULL\n", __FUNCTION__);
  957. return -ENODEV;
  958. }
  959. /* Check to see if (latch closed, card present, power off) */
  960. down(&p_slot->ctrl->crit_sect);
  961. rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  962. if (rc || !getstatus) {
  963. info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
  964. up(&p_slot->ctrl->crit_sect);
  965. return -ENODEV;
  966. }
  967. rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  968. if (rc || getstatus) {
  969. info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
  970. up(&p_slot->ctrl->crit_sect);
  971. return -ENODEV;
  972. }
  973. rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  974. if (rc || getstatus) {
  975. info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
  976. up(&p_slot->ctrl->crit_sect);
  977. return -ENODEV;
  978. }
  979. up(&p_slot->ctrl->crit_sect);
  980. slot_remove(func);
  981. func = shpchp_slot_create(p_slot->bus);
  982. if (func == NULL)
  983. return -ENOMEM;
  984. func->bus = p_slot->bus;
  985. func->device = p_slot->device;
  986. func->function = 0;
  987. func->configured = 0;
  988. func->is_a_board = 1;
  989. /* We have to save the presence info for these slots */
  990. p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
  991. p_slot->hpc_ops->get_power_status(p_slot, &(func->pwr_save));
  992. dbg("%s: func->pwr_save %x\n", __FUNCTION__, func->pwr_save);
  993. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  994. func->switch_save = !getstatus? 0x10:0;
  995. rc = board_added(func, p_slot->ctrl);
  996. if (rc) {
  997. if (is_bridge(func, p_slot->ctrl)) {
  998. u8 secondary = func->pci_dev->subordinate->secondary;
  999. u8 subordinate =
  1000. func->pci_dev->subordinate->subordinate;
  1001. bridge_slot_remove(func, secondary, subordinate);
  1002. } else
  1003. slot_remove(func);
  1004. /* Setup slot structure with entry for empty slot */
  1005. func = shpchp_slot_create(p_slot->bus);
  1006. if (func == NULL)
  1007. return -ENOMEM; /* Out of memory */
  1008. func->bus = p_slot->bus;
  1009. func->device = p_slot->device;
  1010. func->function = 0;
  1011. func->configured = 0;
  1012. func->is_a_board = 1;
  1013. /* We have to save the presence info for these slots */
  1014. p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
  1015. p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  1016. func->switch_save = !getstatus? 0x10:0;
  1017. }
  1018. if (p_slot)
  1019. update_slot_info(p_slot);
  1020. return rc;
  1021. }
  1022. int shpchp_disable_slot (struct slot *p_slot)
  1023. {
  1024. u8 class_code, header_type, BCR;
  1025. u8 index = 0;
  1026. u8 getstatus = 0;
  1027. u32 rc = 0;
  1028. int ret = 0;
  1029. unsigned int devfn;
  1030. struct pci_bus *pci_bus;
  1031. struct pci_func *func;
  1032. if (!p_slot->ctrl)
  1033. return -ENODEV;
  1034. pci_bus = p_slot->ctrl->pci_dev->subordinate;
  1035. /* Check to see if (latch closed, card present, power on) */
  1036. down(&p_slot->ctrl->crit_sect);
  1037. ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
  1038. if (ret || !getstatus) {
  1039. info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
  1040. up(&p_slot->ctrl->crit_sect);
  1041. return -ENODEV;
  1042. }
  1043. ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
  1044. if (ret || getstatus) {
  1045. info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
  1046. up(&p_slot->ctrl->crit_sect);
  1047. return -ENODEV;
  1048. }
  1049. ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
  1050. if (ret || !getstatus) {
  1051. info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
  1052. up(&p_slot->ctrl->crit_sect);
  1053. return -ENODEV;
  1054. }
  1055. up(&p_slot->ctrl->crit_sect);
  1056. func = shpchp_slot_find(p_slot->bus, p_slot->device, index++);
  1057. /* Make sure there are no video controllers here
  1058. * for all func of p_slot
  1059. */
  1060. while (func && !rc) {
  1061. pci_bus->number = func->bus;
  1062. devfn = PCI_DEVFN(func->device, func->function);
  1063. /* Check the Class Code */
  1064. rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
  1065. if (rc)
  1066. return -ENODEV;
  1067. if (class_code == PCI_BASE_CLASS_DISPLAY) {
  1068. /* Display/Video adapter (not supported) */
  1069. rc = REMOVE_NOT_SUPPORTED;
  1070. } else {
  1071. /* See if it's a bridge */
  1072. rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &header_type);
  1073. if (rc)
  1074. return -ENODEV;
  1075. /* If it's a bridge, check the VGA Enable bit */
  1076. if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
  1077. rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR);
  1078. if (rc)
  1079. return -ENODEV;
  1080. /* If the VGA Enable bit is set, remove isn't supported */
  1081. if (BCR & PCI_BRIDGE_CTL_VGA) {
  1082. rc = REMOVE_NOT_SUPPORTED;
  1083. }
  1084. }
  1085. }
  1086. func = shpchp_slot_find(p_slot->bus, p_slot->device, index++);
  1087. }
  1088. func = shpchp_slot_find(p_slot->bus, p_slot->device, 0);
  1089. if ((func != NULL) && !rc) {
  1090. rc = remove_board(func, p_slot->ctrl);
  1091. } else if (!rc)
  1092. rc = -ENODEV;
  1093. if (p_slot)
  1094. update_slot_info(p_slot);
  1095. return rc;
  1096. }