ibmphp_core.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * IBM Hot Plug Controller Driver
  4. *
  5. * Written By: Chuck Cole, Jyoti Shah, Tong Yu, Irene Zubarev, IBM Corporation
  6. *
  7. * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
  8. * Copyright (C) 2001-2003 IBM Corp.
  9. *
  10. * All rights reserved.
  11. *
  12. * Send feedback to <gregkh@us.ibm.com>
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/pci.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/delay.h>
  21. #include <linux/wait.h>
  22. #include "../pci.h"
  23. #include <asm/pci_x86.h> /* for struct irq_routing_table */
  24. #include <asm/io_apic.h>
  25. #include "ibmphp.h"
  26. #define attn_on(sl) ibmphp_hpc_writeslot(sl, HPC_SLOT_ATTNON)
  27. #define attn_off(sl) ibmphp_hpc_writeslot(sl, HPC_SLOT_ATTNOFF)
  28. #define attn_LED_blink(sl) ibmphp_hpc_writeslot(sl, HPC_SLOT_BLINKLED)
  29. #define get_ctrl_revision(sl, rev) ibmphp_hpc_readslot(sl, READ_REVLEVEL, rev)
  30. #define get_hpc_options(sl, opt) ibmphp_hpc_readslot(sl, READ_HPCOPTIONS, opt)
  31. #define DRIVER_VERSION "0.6"
  32. #define DRIVER_DESC "IBM Hot Plug PCI Controller Driver"
  33. int ibmphp_debug;
  34. static bool debug;
  35. module_param(debug, bool, S_IRUGO | S_IWUSR);
  36. MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
  37. MODULE_LICENSE("GPL");
  38. MODULE_DESCRIPTION(DRIVER_DESC);
  39. struct pci_bus *ibmphp_pci_bus;
  40. static int max_slots;
  41. static int irqs[16]; /* PIC mode IRQs we're using so far (in case MPS
  42. * tables don't provide default info for empty slots */
  43. static int init_flag;
  44. /*
  45. static int get_max_adapter_speed_1 (struct hotplug_slot *, u8 *, u8);
  46. static inline int get_max_adapter_speed (struct hotplug_slot *hs, u8 *value)
  47. {
  48. return get_max_adapter_speed_1 (hs, value, 1);
  49. }
  50. */
  51. static inline int get_cur_bus_info(struct slot **sl)
  52. {
  53. int rc = 1;
  54. struct slot *slot_cur = *sl;
  55. debug("options = %x\n", slot_cur->ctrl->options);
  56. debug("revision = %x\n", slot_cur->ctrl->revision);
  57. if (READ_BUS_STATUS(slot_cur->ctrl))
  58. rc = ibmphp_hpc_readslot(slot_cur, READ_BUSSTATUS, NULL);
  59. if (rc)
  60. return rc;
  61. slot_cur->bus_on->current_speed = CURRENT_BUS_SPEED(slot_cur->busstatus);
  62. if (READ_BUS_MODE(slot_cur->ctrl))
  63. slot_cur->bus_on->current_bus_mode =
  64. CURRENT_BUS_MODE(slot_cur->busstatus);
  65. else
  66. slot_cur->bus_on->current_bus_mode = 0xFF;
  67. debug("busstatus = %x, bus_speed = %x, bus_mode = %x\n",
  68. slot_cur->busstatus,
  69. slot_cur->bus_on->current_speed,
  70. slot_cur->bus_on->current_bus_mode);
  71. *sl = slot_cur;
  72. return 0;
  73. }
  74. static inline int slot_update(struct slot **sl)
  75. {
  76. int rc;
  77. rc = ibmphp_hpc_readslot(*sl, READ_ALLSTAT, NULL);
  78. if (rc)
  79. return rc;
  80. if (!init_flag)
  81. rc = get_cur_bus_info(sl);
  82. return rc;
  83. }
  84. static int __init get_max_slots(void)
  85. {
  86. struct slot *slot_cur;
  87. u8 slot_count = 0;
  88. list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) {
  89. /* sometimes the hot-pluggable slots start with 4 (not always from 1) */
  90. slot_count = max(slot_count, slot_cur->number);
  91. }
  92. return slot_count;
  93. }
  94. /* This routine will put the correct slot->device information per slot. It's
  95. * called from initialization of the slot structures. It will also assign
  96. * interrupt numbers per each slot.
  97. * Parameters: struct slot
  98. * Returns 0 or errors
  99. */
  100. int ibmphp_init_devno(struct slot **cur_slot)
  101. {
  102. struct irq_routing_table *rtable;
  103. int len;
  104. int loop;
  105. int i;
  106. rtable = pcibios_get_irq_routing_table();
  107. if (!rtable) {
  108. err("no BIOS routing table...\n");
  109. return -ENOMEM;
  110. }
  111. len = (rtable->size - sizeof(struct irq_routing_table)) /
  112. sizeof(struct irq_info);
  113. if (!len) {
  114. kfree(rtable);
  115. return -1;
  116. }
  117. for (loop = 0; loop < len; loop++) {
  118. if ((*cur_slot)->number == rtable->slots[loop].slot &&
  119. (*cur_slot)->bus == rtable->slots[loop].bus) {
  120. (*cur_slot)->device = PCI_SLOT(rtable->slots[loop].devfn);
  121. for (i = 0; i < 4; i++)
  122. (*cur_slot)->irq[i] = IO_APIC_get_PCI_irq_vector((int) (*cur_slot)->bus,
  123. (int) (*cur_slot)->device, i);
  124. debug("(*cur_slot)->irq[0] = %x\n",
  125. (*cur_slot)->irq[0]);
  126. debug("(*cur_slot)->irq[1] = %x\n",
  127. (*cur_slot)->irq[1]);
  128. debug("(*cur_slot)->irq[2] = %x\n",
  129. (*cur_slot)->irq[2]);
  130. debug("(*cur_slot)->irq[3] = %x\n",
  131. (*cur_slot)->irq[3]);
  132. debug("rtable->exclusive_irqs = %x\n",
  133. rtable->exclusive_irqs);
  134. debug("rtable->slots[loop].irq[0].bitmap = %x\n",
  135. rtable->slots[loop].irq[0].bitmap);
  136. debug("rtable->slots[loop].irq[1].bitmap = %x\n",
  137. rtable->slots[loop].irq[1].bitmap);
  138. debug("rtable->slots[loop].irq[2].bitmap = %x\n",
  139. rtable->slots[loop].irq[2].bitmap);
  140. debug("rtable->slots[loop].irq[3].bitmap = %x\n",
  141. rtable->slots[loop].irq[3].bitmap);
  142. debug("rtable->slots[loop].irq[0].link = %x\n",
  143. rtable->slots[loop].irq[0].link);
  144. debug("rtable->slots[loop].irq[1].link = %x\n",
  145. rtable->slots[loop].irq[1].link);
  146. debug("rtable->slots[loop].irq[2].link = %x\n",
  147. rtable->slots[loop].irq[2].link);
  148. debug("rtable->slots[loop].irq[3].link = %x\n",
  149. rtable->slots[loop].irq[3].link);
  150. debug("end of init_devno\n");
  151. kfree(rtable);
  152. return 0;
  153. }
  154. }
  155. kfree(rtable);
  156. return -1;
  157. }
  158. static inline int power_on(struct slot *slot_cur)
  159. {
  160. u8 cmd = HPC_SLOT_ON;
  161. int retval;
  162. retval = ibmphp_hpc_writeslot(slot_cur, cmd);
  163. if (retval) {
  164. err("power on failed\n");
  165. return retval;
  166. }
  167. if (CTLR_RESULT(slot_cur->ctrl->status)) {
  168. err("command not completed successfully in power_on\n");
  169. return -EIO;
  170. }
  171. msleep(3000); /* For ServeRAID cards, and some 66 PCI */
  172. return 0;
  173. }
  174. static inline int power_off(struct slot *slot_cur)
  175. {
  176. u8 cmd = HPC_SLOT_OFF;
  177. int retval;
  178. retval = ibmphp_hpc_writeslot(slot_cur, cmd);
  179. if (retval) {
  180. err("power off failed\n");
  181. return retval;
  182. }
  183. if (CTLR_RESULT(slot_cur->ctrl->status)) {
  184. err("command not completed successfully in power_off\n");
  185. retval = -EIO;
  186. }
  187. return retval;
  188. }
  189. static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
  190. {
  191. int rc = 0;
  192. struct slot *pslot;
  193. u8 cmd = 0x00; /* avoid compiler warning */
  194. debug("set_attention_status - Entry hotplug_slot[%lx] value[%x]\n",
  195. (ulong) hotplug_slot, value);
  196. ibmphp_lock_operations();
  197. if (hotplug_slot) {
  198. switch (value) {
  199. case HPC_SLOT_ATTN_OFF:
  200. cmd = HPC_SLOT_ATTNOFF;
  201. break;
  202. case HPC_SLOT_ATTN_ON:
  203. cmd = HPC_SLOT_ATTNON;
  204. break;
  205. case HPC_SLOT_ATTN_BLINK:
  206. cmd = HPC_SLOT_BLINKLED;
  207. break;
  208. default:
  209. rc = -ENODEV;
  210. err("set_attention_status - Error : invalid input [%x]\n",
  211. value);
  212. break;
  213. }
  214. if (rc == 0) {
  215. pslot = hotplug_slot->private;
  216. if (pslot)
  217. rc = ibmphp_hpc_writeslot(pslot, cmd);
  218. else
  219. rc = -ENODEV;
  220. }
  221. } else
  222. rc = -ENODEV;
  223. ibmphp_unlock_operations();
  224. debug("set_attention_status - Exit rc[%d]\n", rc);
  225. return rc;
  226. }
  227. static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
  228. {
  229. int rc = -ENODEV;
  230. struct slot *pslot;
  231. struct slot myslot;
  232. debug("get_attention_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
  233. (ulong) hotplug_slot, (ulong) value);
  234. ibmphp_lock_operations();
  235. if (hotplug_slot) {
  236. pslot = hotplug_slot->private;
  237. if (pslot) {
  238. memcpy(&myslot, pslot, sizeof(struct slot));
  239. rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
  240. &(myslot.status));
  241. if (!rc)
  242. rc = ibmphp_hpc_readslot(pslot,
  243. READ_EXTSLOTSTATUS,
  244. &(myslot.ext_status));
  245. if (!rc)
  246. *value = SLOT_ATTN(myslot.status,
  247. myslot.ext_status);
  248. }
  249. }
  250. ibmphp_unlock_operations();
  251. debug("get_attention_status - Exit rc[%d] value[%x]\n", rc, *value);
  252. return rc;
  253. }
  254. static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
  255. {
  256. int rc = -ENODEV;
  257. struct slot *pslot;
  258. struct slot myslot;
  259. debug("get_latch_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
  260. (ulong) hotplug_slot, (ulong) value);
  261. ibmphp_lock_operations();
  262. if (hotplug_slot) {
  263. pslot = hotplug_slot->private;
  264. if (pslot) {
  265. memcpy(&myslot, pslot, sizeof(struct slot));
  266. rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
  267. &(myslot.status));
  268. if (!rc)
  269. *value = SLOT_LATCH(myslot.status);
  270. }
  271. }
  272. ibmphp_unlock_operations();
  273. debug("get_latch_status - Exit rc[%d] rc[%x] value[%x]\n",
  274. rc, rc, *value);
  275. return rc;
  276. }
  277. static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
  278. {
  279. int rc = -ENODEV;
  280. struct slot *pslot;
  281. struct slot myslot;
  282. debug("get_power_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
  283. (ulong) hotplug_slot, (ulong) value);
  284. ibmphp_lock_operations();
  285. if (hotplug_slot) {
  286. pslot = hotplug_slot->private;
  287. if (pslot) {
  288. memcpy(&myslot, pslot, sizeof(struct slot));
  289. rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
  290. &(myslot.status));
  291. if (!rc)
  292. *value = SLOT_PWRGD(myslot.status);
  293. }
  294. }
  295. ibmphp_unlock_operations();
  296. debug("get_power_status - Exit rc[%d] rc[%x] value[%x]\n",
  297. rc, rc, *value);
  298. return rc;
  299. }
  300. static int get_adapter_present(struct hotplug_slot *hotplug_slot, u8 *value)
  301. {
  302. int rc = -ENODEV;
  303. struct slot *pslot;
  304. u8 present;
  305. struct slot myslot;
  306. debug("get_adapter_status - Entry hotplug_slot[%lx] pvalue[%lx]\n",
  307. (ulong) hotplug_slot, (ulong) value);
  308. ibmphp_lock_operations();
  309. if (hotplug_slot) {
  310. pslot = hotplug_slot->private;
  311. if (pslot) {
  312. memcpy(&myslot, pslot, sizeof(struct slot));
  313. rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
  314. &(myslot.status));
  315. if (!rc) {
  316. present = SLOT_PRESENT(myslot.status);
  317. if (present == HPC_SLOT_EMPTY)
  318. *value = 0;
  319. else
  320. *value = 1;
  321. }
  322. }
  323. }
  324. ibmphp_unlock_operations();
  325. debug("get_adapter_present - Exit rc[%d] value[%x]\n", rc, *value);
  326. return rc;
  327. }
  328. static int get_max_bus_speed(struct slot *slot)
  329. {
  330. int rc;
  331. u8 mode = 0;
  332. enum pci_bus_speed speed;
  333. struct pci_bus *bus = slot->hotplug_slot->pci_slot->bus;
  334. debug("%s - Entry slot[%p]\n", __func__, slot);
  335. ibmphp_lock_operations();
  336. mode = slot->supported_bus_mode;
  337. speed = slot->supported_speed;
  338. ibmphp_unlock_operations();
  339. switch (speed) {
  340. case BUS_SPEED_33:
  341. break;
  342. case BUS_SPEED_66:
  343. if (mode == BUS_MODE_PCIX)
  344. speed += 0x01;
  345. break;
  346. case BUS_SPEED_100:
  347. case BUS_SPEED_133:
  348. speed += 0x01;
  349. break;
  350. default:
  351. /* Note (will need to change): there would be soon 256, 512 also */
  352. rc = -ENODEV;
  353. }
  354. if (!rc)
  355. bus->max_bus_speed = speed;
  356. debug("%s - Exit rc[%d] speed[%x]\n", __func__, rc, speed);
  357. return rc;
  358. }
  359. /*
  360. static int get_max_adapter_speed_1(struct hotplug_slot *hotplug_slot, u8 *value, u8 flag)
  361. {
  362. int rc = -ENODEV;
  363. struct slot *pslot;
  364. struct slot myslot;
  365. debug("get_max_adapter_speed_1 - Entry hotplug_slot[%lx] pvalue[%lx]\n",
  366. (ulong)hotplug_slot, (ulong) value);
  367. if (flag)
  368. ibmphp_lock_operations();
  369. if (hotplug_slot && value) {
  370. pslot = hotplug_slot->private;
  371. if (pslot) {
  372. memcpy(&myslot, pslot, sizeof(struct slot));
  373. rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS,
  374. &(myslot.status));
  375. if (!(SLOT_LATCH (myslot.status)) &&
  376. (SLOT_PRESENT (myslot.status))) {
  377. rc = ibmphp_hpc_readslot(pslot,
  378. READ_EXTSLOTSTATUS,
  379. &(myslot.ext_status));
  380. if (!rc)
  381. *value = SLOT_SPEED(myslot.ext_status);
  382. } else
  383. *value = MAX_ADAPTER_NONE;
  384. }
  385. }
  386. if (flag)
  387. ibmphp_unlock_operations();
  388. debug("get_max_adapter_speed_1 - Exit rc[%d] value[%x]\n", rc, *value);
  389. return rc;
  390. }
  391. static int get_bus_name(struct hotplug_slot *hotplug_slot, char *value)
  392. {
  393. int rc = -ENODEV;
  394. struct slot *pslot = NULL;
  395. debug("get_bus_name - Entry hotplug_slot[%lx]\n", (ulong)hotplug_slot);
  396. ibmphp_lock_operations();
  397. if (hotplug_slot) {
  398. pslot = hotplug_slot->private;
  399. if (pslot) {
  400. rc = 0;
  401. snprintf(value, 100, "Bus %x", pslot->bus);
  402. }
  403. } else
  404. rc = -ENODEV;
  405. ibmphp_unlock_operations();
  406. debug("get_bus_name - Exit rc[%d] value[%x]\n", rc, *value);
  407. return rc;
  408. }
  409. */
  410. /****************************************************************************
  411. * This routine will initialize the ops data structure used in the validate
  412. * function. It will also power off empty slots that are powered on since BIOS
  413. * leaves those on, albeit disconnected
  414. ****************************************************************************/
  415. static int __init init_ops(void)
  416. {
  417. struct slot *slot_cur;
  418. int retval;
  419. int rc;
  420. list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) {
  421. debug("BEFORE GETTING SLOT STATUS, slot # %x\n",
  422. slot_cur->number);
  423. if (slot_cur->ctrl->revision == 0xFF)
  424. if (get_ctrl_revision(slot_cur,
  425. &slot_cur->ctrl->revision))
  426. return -1;
  427. if (slot_cur->bus_on->current_speed == 0xFF)
  428. if (get_cur_bus_info(&slot_cur))
  429. return -1;
  430. get_max_bus_speed(slot_cur);
  431. if (slot_cur->ctrl->options == 0xFF)
  432. if (get_hpc_options(slot_cur, &slot_cur->ctrl->options))
  433. return -1;
  434. retval = slot_update(&slot_cur);
  435. if (retval)
  436. return retval;
  437. debug("status = %x\n", slot_cur->status);
  438. debug("ext_status = %x\n", slot_cur->ext_status);
  439. debug("SLOT_POWER = %x\n", SLOT_POWER(slot_cur->status));
  440. debug("SLOT_PRESENT = %x\n", SLOT_PRESENT(slot_cur->status));
  441. debug("SLOT_LATCH = %x\n", SLOT_LATCH(slot_cur->status));
  442. if ((SLOT_PWRGD(slot_cur->status)) &&
  443. !(SLOT_PRESENT(slot_cur->status)) &&
  444. !(SLOT_LATCH(slot_cur->status))) {
  445. debug("BEFORE POWER OFF COMMAND\n");
  446. rc = power_off(slot_cur);
  447. if (rc)
  448. return rc;
  449. /* retval = slot_update(&slot_cur);
  450. * if (retval)
  451. * return retval;
  452. * ibmphp_update_slot_info(slot_cur);
  453. */
  454. }
  455. }
  456. init_flag = 0;
  457. return 0;
  458. }
  459. /* This operation will check whether the slot is within the bounds and
  460. * the operation is valid to perform on that slot
  461. * Parameters: slot, operation
  462. * Returns: 0 or error codes
  463. */
  464. static int validate(struct slot *slot_cur, int opn)
  465. {
  466. int number;
  467. int retval;
  468. if (!slot_cur)
  469. return -ENODEV;
  470. number = slot_cur->number;
  471. if ((number > max_slots) || (number < 0))
  472. return -EBADSLT;
  473. debug("slot_number in validate is %d\n", slot_cur->number);
  474. retval = slot_update(&slot_cur);
  475. if (retval)
  476. return retval;
  477. switch (opn) {
  478. case ENABLE:
  479. if (!(SLOT_PWRGD(slot_cur->status)) &&
  480. (SLOT_PRESENT(slot_cur->status)) &&
  481. !(SLOT_LATCH(slot_cur->status)))
  482. return 0;
  483. break;
  484. case DISABLE:
  485. if ((SLOT_PWRGD(slot_cur->status)) &&
  486. (SLOT_PRESENT(slot_cur->status)) &&
  487. !(SLOT_LATCH(slot_cur->status)))
  488. return 0;
  489. break;
  490. default:
  491. break;
  492. }
  493. err("validate failed....\n");
  494. return -EINVAL;
  495. }
  496. /****************************************************************************
  497. * This routine is for updating the data structures in the hotplug core
  498. * Parameters: struct slot
  499. * Returns: 0 or error
  500. ****************************************************************************/
  501. int ibmphp_update_slot_info(struct slot *slot_cur)
  502. {
  503. struct hotplug_slot_info *info;
  504. struct pci_bus *bus = slot_cur->hotplug_slot->pci_slot->bus;
  505. int rc;
  506. u8 bus_speed;
  507. u8 mode;
  508. info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
  509. if (!info) {
  510. err("out of system memory\n");
  511. return -ENOMEM;
  512. }
  513. info->power_status = SLOT_PWRGD(slot_cur->status);
  514. info->attention_status = SLOT_ATTN(slot_cur->status,
  515. slot_cur->ext_status);
  516. info->latch_status = SLOT_LATCH(slot_cur->status);
  517. if (!SLOT_PRESENT(slot_cur->status)) {
  518. info->adapter_status = 0;
  519. /* info->max_adapter_speed_status = MAX_ADAPTER_NONE; */
  520. } else {
  521. info->adapter_status = 1;
  522. /* get_max_adapter_speed_1(slot_cur->hotplug_slot,
  523. &info->max_adapter_speed_status, 0); */
  524. }
  525. bus_speed = slot_cur->bus_on->current_speed;
  526. mode = slot_cur->bus_on->current_bus_mode;
  527. switch (bus_speed) {
  528. case BUS_SPEED_33:
  529. break;
  530. case BUS_SPEED_66:
  531. if (mode == BUS_MODE_PCIX)
  532. bus_speed += 0x01;
  533. else if (mode == BUS_MODE_PCI)
  534. ;
  535. else
  536. bus_speed = PCI_SPEED_UNKNOWN;
  537. break;
  538. case BUS_SPEED_100:
  539. case BUS_SPEED_133:
  540. bus_speed += 0x01;
  541. break;
  542. default:
  543. bus_speed = PCI_SPEED_UNKNOWN;
  544. }
  545. bus->cur_bus_speed = bus_speed;
  546. // To do: bus_names
  547. rc = pci_hp_change_slot_info(slot_cur->hotplug_slot, info);
  548. kfree(info);
  549. return rc;
  550. }
  551. /******************************************************************************
  552. * This function will return the pci_func, given bus and devfunc, or NULL. It
  553. * is called from visit routines
  554. ******************************************************************************/
  555. static struct pci_func *ibm_slot_find(u8 busno, u8 device, u8 function)
  556. {
  557. struct pci_func *func_cur;
  558. struct slot *slot_cur;
  559. list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) {
  560. if (slot_cur->func) {
  561. func_cur = slot_cur->func;
  562. while (func_cur) {
  563. if ((func_cur->busno == busno) &&
  564. (func_cur->device == device) &&
  565. (func_cur->function == function))
  566. return func_cur;
  567. func_cur = func_cur->next;
  568. }
  569. }
  570. }
  571. return NULL;
  572. }
  573. /*************************************************************
  574. * This routine frees up memory used by struct slot, including
  575. * the pointers to pci_func, bus, hotplug_slot, controller,
  576. * and deregistering from the hotplug core
  577. *************************************************************/
  578. static void free_slots(void)
  579. {
  580. struct slot *slot_cur, *next;
  581. debug("%s -- enter\n", __func__);
  582. list_for_each_entry_safe(slot_cur, next, &ibmphp_slot_head,
  583. ibm_slot_list) {
  584. pci_hp_deregister(slot_cur->hotplug_slot);
  585. }
  586. debug("%s -- exit\n", __func__);
  587. }
  588. static void ibm_unconfigure_device(struct pci_func *func)
  589. {
  590. struct pci_dev *temp;
  591. u8 j;
  592. debug("inside %s\n", __func__);
  593. debug("func->device = %x, func->function = %x\n",
  594. func->device, func->function);
  595. debug("func->device << 3 | 0x0 = %x\n", func->device << 3 | 0x0);
  596. pci_lock_rescan_remove();
  597. for (j = 0; j < 0x08; j++) {
  598. temp = pci_get_bus_and_slot(func->busno, (func->device << 3) | j);
  599. if (temp) {
  600. pci_stop_and_remove_bus_device(temp);
  601. pci_dev_put(temp);
  602. }
  603. }
  604. pci_dev_put(func->dev);
  605. pci_unlock_rescan_remove();
  606. }
  607. /*
  608. * The following function is to fix kernel bug regarding
  609. * getting bus entries, here we manually add those primary
  610. * bus entries to kernel bus structure whenever apply
  611. */
  612. static u8 bus_structure_fixup(u8 busno)
  613. {
  614. struct pci_bus *bus, *b;
  615. struct pci_dev *dev;
  616. u16 l;
  617. if (pci_find_bus(0, busno) || !(ibmphp_find_same_bus_num(busno)))
  618. return 1;
  619. bus = kmalloc(sizeof(*bus), GFP_KERNEL);
  620. if (!bus) {
  621. err("%s - out of memory\n", __func__);
  622. return 1;
  623. }
  624. dev = kmalloc(sizeof(*dev), GFP_KERNEL);
  625. if (!dev) {
  626. kfree(bus);
  627. err("%s - out of memory\n", __func__);
  628. return 1;
  629. }
  630. bus->number = busno;
  631. bus->ops = ibmphp_pci_bus->ops;
  632. dev->bus = bus;
  633. for (dev->devfn = 0; dev->devfn < 256; dev->devfn += 8) {
  634. if (!pci_read_config_word(dev, PCI_VENDOR_ID, &l) &&
  635. (l != 0x0000) && (l != 0xffff)) {
  636. debug("%s - Inside bus_structure_fixup()\n",
  637. __func__);
  638. b = pci_scan_bus(busno, ibmphp_pci_bus->ops, NULL);
  639. if (!b)
  640. continue;
  641. pci_bus_add_devices(b);
  642. break;
  643. }
  644. }
  645. kfree(dev);
  646. kfree(bus);
  647. return 0;
  648. }
  649. static int ibm_configure_device(struct pci_func *func)
  650. {
  651. struct pci_bus *child;
  652. int num;
  653. int flag = 0; /* this is to make sure we don't double scan the bus,
  654. for bridged devices primarily */
  655. pci_lock_rescan_remove();
  656. if (!(bus_structure_fixup(func->busno)))
  657. flag = 1;
  658. if (func->dev == NULL)
  659. func->dev = pci_get_bus_and_slot(func->busno,
  660. PCI_DEVFN(func->device, func->function));
  661. if (func->dev == NULL) {
  662. struct pci_bus *bus = pci_find_bus(0, func->busno);
  663. if (!bus)
  664. goto out;
  665. num = pci_scan_slot(bus,
  666. PCI_DEVFN(func->device, func->function));
  667. if (num)
  668. pci_bus_add_devices(bus);
  669. func->dev = pci_get_bus_and_slot(func->busno,
  670. PCI_DEVFN(func->device, func->function));
  671. if (func->dev == NULL) {
  672. err("ERROR... : pci_dev still NULL\n");
  673. goto out;
  674. }
  675. }
  676. if (!(flag) && (func->dev->hdr_type == PCI_HEADER_TYPE_BRIDGE)) {
  677. pci_hp_add_bridge(func->dev);
  678. child = func->dev->subordinate;
  679. if (child)
  680. pci_bus_add_devices(child);
  681. }
  682. out:
  683. pci_unlock_rescan_remove();
  684. return 0;
  685. }
  686. /*******************************************************
  687. * Returns whether the bus is empty or not
  688. *******************************************************/
  689. static int is_bus_empty(struct slot *slot_cur)
  690. {
  691. int rc;
  692. struct slot *tmp_slot;
  693. u8 i = slot_cur->bus_on->slot_min;
  694. while (i <= slot_cur->bus_on->slot_max) {
  695. if (i == slot_cur->number) {
  696. i++;
  697. continue;
  698. }
  699. tmp_slot = ibmphp_get_slot_from_physical_num(i);
  700. if (!tmp_slot)
  701. return 0;
  702. rc = slot_update(&tmp_slot);
  703. if (rc)
  704. return 0;
  705. if (SLOT_PRESENT(tmp_slot->status) &&
  706. SLOT_PWRGD(tmp_slot->status))
  707. return 0;
  708. i++;
  709. }
  710. return 1;
  711. }
  712. /***********************************************************
  713. * If the HPC permits and the bus currently empty, tries to set the
  714. * bus speed and mode at the maximum card and bus capability
  715. * Parameters: slot
  716. * Returns: bus is set (0) or error code
  717. ***********************************************************/
  718. static int set_bus(struct slot *slot_cur)
  719. {
  720. int rc;
  721. u8 speed;
  722. u8 cmd = 0x0;
  723. int retval;
  724. static const struct pci_device_id ciobx[] = {
  725. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 0x0101) },
  726. { },
  727. };
  728. debug("%s - entry slot # %d\n", __func__, slot_cur->number);
  729. if (SET_BUS_STATUS(slot_cur->ctrl) && is_bus_empty(slot_cur)) {
  730. rc = slot_update(&slot_cur);
  731. if (rc)
  732. return rc;
  733. speed = SLOT_SPEED(slot_cur->ext_status);
  734. debug("ext_status = %x, speed = %x\n", slot_cur->ext_status, speed);
  735. switch (speed) {
  736. case HPC_SLOT_SPEED_33:
  737. cmd = HPC_BUS_33CONVMODE;
  738. break;
  739. case HPC_SLOT_SPEED_66:
  740. if (SLOT_PCIX(slot_cur->ext_status)) {
  741. if ((slot_cur->supported_speed >= BUS_SPEED_66) &&
  742. (slot_cur->supported_bus_mode == BUS_MODE_PCIX))
  743. cmd = HPC_BUS_66PCIXMODE;
  744. else if (!SLOT_BUS_MODE(slot_cur->ext_status))
  745. /* if max slot/bus capability is 66 pci
  746. and there's no bus mode mismatch, then
  747. the adapter supports 66 pci */
  748. cmd = HPC_BUS_66CONVMODE;
  749. else
  750. cmd = HPC_BUS_33CONVMODE;
  751. } else {
  752. if (slot_cur->supported_speed >= BUS_SPEED_66)
  753. cmd = HPC_BUS_66CONVMODE;
  754. else
  755. cmd = HPC_BUS_33CONVMODE;
  756. }
  757. break;
  758. case HPC_SLOT_SPEED_133:
  759. switch (slot_cur->supported_speed) {
  760. case BUS_SPEED_33:
  761. cmd = HPC_BUS_33CONVMODE;
  762. break;
  763. case BUS_SPEED_66:
  764. if (slot_cur->supported_bus_mode == BUS_MODE_PCIX)
  765. cmd = HPC_BUS_66PCIXMODE;
  766. else
  767. cmd = HPC_BUS_66CONVMODE;
  768. break;
  769. case BUS_SPEED_100:
  770. cmd = HPC_BUS_100PCIXMODE;
  771. break;
  772. case BUS_SPEED_133:
  773. /* This is to take care of the bug in CIOBX chip */
  774. if (pci_dev_present(ciobx))
  775. ibmphp_hpc_writeslot(slot_cur,
  776. HPC_BUS_100PCIXMODE);
  777. cmd = HPC_BUS_133PCIXMODE;
  778. break;
  779. default:
  780. err("Wrong bus speed\n");
  781. return -ENODEV;
  782. }
  783. break;
  784. default:
  785. err("wrong slot speed\n");
  786. return -ENODEV;
  787. }
  788. debug("setting bus speed for slot %d, cmd %x\n",
  789. slot_cur->number, cmd);
  790. retval = ibmphp_hpc_writeslot(slot_cur, cmd);
  791. if (retval) {
  792. err("setting bus speed failed\n");
  793. return retval;
  794. }
  795. if (CTLR_RESULT(slot_cur->ctrl->status)) {
  796. err("command not completed successfully in set_bus\n");
  797. return -EIO;
  798. }
  799. }
  800. /* This is for x440, once Brandon fixes the firmware,
  801. will not need this delay */
  802. msleep(1000);
  803. debug("%s -Exit\n", __func__);
  804. return 0;
  805. }
  806. /* This routine checks the bus limitations that the slot is on from the BIOS.
  807. * This is used in deciding whether or not to power up the slot.
  808. * (electrical/spec limitations. For example, >1 133 MHz or >2 66 PCI cards on
  809. * same bus)
  810. * Parameters: slot
  811. * Returns: 0 = no limitations, -EINVAL = exceeded limitations on the bus
  812. */
  813. static int check_limitations(struct slot *slot_cur)
  814. {
  815. u8 i;
  816. struct slot *tmp_slot;
  817. u8 count = 0;
  818. u8 limitation = 0;
  819. for (i = slot_cur->bus_on->slot_min; i <= slot_cur->bus_on->slot_max; i++) {
  820. tmp_slot = ibmphp_get_slot_from_physical_num(i);
  821. if (!tmp_slot)
  822. return -ENODEV;
  823. if ((SLOT_PWRGD(tmp_slot->status)) &&
  824. !(SLOT_CONNECT(tmp_slot->status)))
  825. count++;
  826. }
  827. get_cur_bus_info(&slot_cur);
  828. switch (slot_cur->bus_on->current_speed) {
  829. case BUS_SPEED_33:
  830. limitation = slot_cur->bus_on->slots_at_33_conv;
  831. break;
  832. case BUS_SPEED_66:
  833. if (slot_cur->bus_on->current_bus_mode == BUS_MODE_PCIX)
  834. limitation = slot_cur->bus_on->slots_at_66_pcix;
  835. else
  836. limitation = slot_cur->bus_on->slots_at_66_conv;
  837. break;
  838. case BUS_SPEED_100:
  839. limitation = slot_cur->bus_on->slots_at_100_pcix;
  840. break;
  841. case BUS_SPEED_133:
  842. limitation = slot_cur->bus_on->slots_at_133_pcix;
  843. break;
  844. }
  845. if ((count + 1) > limitation)
  846. return -EINVAL;
  847. return 0;
  848. }
  849. static inline void print_card_capability(struct slot *slot_cur)
  850. {
  851. info("capability of the card is ");
  852. if ((slot_cur->ext_status & CARD_INFO) == PCIX133)
  853. info(" 133 MHz PCI-X\n");
  854. else if ((slot_cur->ext_status & CARD_INFO) == PCIX66)
  855. info(" 66 MHz PCI-X\n");
  856. else if ((slot_cur->ext_status & CARD_INFO) == PCI66)
  857. info(" 66 MHz PCI\n");
  858. else
  859. info(" 33 MHz PCI\n");
  860. }
  861. /* This routine will power on the slot, configure the device(s) and find the
  862. * drivers for them.
  863. * Parameters: hotplug_slot
  864. * Returns: 0 or failure codes
  865. */
  866. static int enable_slot(struct hotplug_slot *hs)
  867. {
  868. int rc, i, rcpr;
  869. struct slot *slot_cur;
  870. u8 function;
  871. struct pci_func *tmp_func;
  872. ibmphp_lock_operations();
  873. debug("ENABLING SLOT........\n");
  874. slot_cur = hs->private;
  875. rc = validate(slot_cur, ENABLE);
  876. if (rc) {
  877. err("validate function failed\n");
  878. goto error_nopower;
  879. }
  880. attn_LED_blink(slot_cur);
  881. rc = set_bus(slot_cur);
  882. if (rc) {
  883. err("was not able to set the bus\n");
  884. goto error_nopower;
  885. }
  886. /*-----------------debugging------------------------------*/
  887. get_cur_bus_info(&slot_cur);
  888. debug("the current bus speed right after set_bus = %x\n",
  889. slot_cur->bus_on->current_speed);
  890. /*----------------------------------------------------------*/
  891. rc = check_limitations(slot_cur);
  892. if (rc) {
  893. err("Adding this card exceeds the limitations of this bus.\n");
  894. err("(i.e., >1 133MHz cards running on same bus, or >2 66 PCI cards running on same bus.\n");
  895. err("Try hot-adding into another bus\n");
  896. rc = -EINVAL;
  897. goto error_nopower;
  898. }
  899. rc = power_on(slot_cur);
  900. if (rc) {
  901. err("something wrong when powering up... please see below for details\n");
  902. /* need to turn off before on, otherwise, blinking overwrites */
  903. attn_off(slot_cur);
  904. attn_on(slot_cur);
  905. if (slot_update(&slot_cur)) {
  906. attn_off(slot_cur);
  907. attn_on(slot_cur);
  908. rc = -ENODEV;
  909. goto exit;
  910. }
  911. /* Check to see the error of why it failed */
  912. if ((SLOT_POWER(slot_cur->status)) &&
  913. !(SLOT_PWRGD(slot_cur->status)))
  914. err("power fault occurred trying to power up\n");
  915. else if (SLOT_BUS_SPEED(slot_cur->status)) {
  916. err("bus speed mismatch occurred. please check current bus speed and card capability\n");
  917. print_card_capability(slot_cur);
  918. } else if (SLOT_BUS_MODE(slot_cur->ext_status)) {
  919. err("bus mode mismatch occurred. please check current bus mode and card capability\n");
  920. print_card_capability(slot_cur);
  921. }
  922. ibmphp_update_slot_info(slot_cur);
  923. goto exit;
  924. }
  925. debug("after power_on\n");
  926. /*-----------------------debugging---------------------------*/
  927. get_cur_bus_info(&slot_cur);
  928. debug("the current bus speed right after power_on = %x\n",
  929. slot_cur->bus_on->current_speed);
  930. /*----------------------------------------------------------*/
  931. rc = slot_update(&slot_cur);
  932. if (rc)
  933. goto error_power;
  934. rc = -EINVAL;
  935. if (SLOT_POWER(slot_cur->status) && !(SLOT_PWRGD(slot_cur->status))) {
  936. err("power fault occurred trying to power up...\n");
  937. goto error_power;
  938. }
  939. if (SLOT_POWER(slot_cur->status) && (SLOT_BUS_SPEED(slot_cur->status))) {
  940. err("bus speed mismatch occurred. please check current bus speed and card capability\n");
  941. print_card_capability(slot_cur);
  942. goto error_power;
  943. }
  944. /* Don't think this case will happen after above checks...
  945. * but just in case, for paranoia sake */
  946. if (!(SLOT_POWER(slot_cur->status))) {
  947. err("power on failed...\n");
  948. goto error_power;
  949. }
  950. slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
  951. if (!slot_cur->func) {
  952. /* We cannot do update_slot_info here, since no memory for
  953. * kmalloc n.e.ways, and update_slot_info allocates some */
  954. err("out of system memory\n");
  955. rc = -ENOMEM;
  956. goto error_power;
  957. }
  958. slot_cur->func->busno = slot_cur->bus;
  959. slot_cur->func->device = slot_cur->device;
  960. for (i = 0; i < 4; i++)
  961. slot_cur->func->irq[i] = slot_cur->irq[i];
  962. debug("b4 configure_card, slot_cur->bus = %x, slot_cur->device = %x\n",
  963. slot_cur->bus, slot_cur->device);
  964. if (ibmphp_configure_card(slot_cur->func, slot_cur->number)) {
  965. err("configure_card was unsuccessful...\n");
  966. /* true because don't need to actually deallocate resources,
  967. * just remove references */
  968. ibmphp_unconfigure_card(&slot_cur, 1);
  969. debug("after unconfigure_card\n");
  970. slot_cur->func = NULL;
  971. rc = -ENOMEM;
  972. goto error_power;
  973. }
  974. function = 0x00;
  975. do {
  976. tmp_func = ibm_slot_find(slot_cur->bus, slot_cur->func->device,
  977. function++);
  978. if (tmp_func && !(tmp_func->dev))
  979. ibm_configure_device(tmp_func);
  980. } while (tmp_func);
  981. attn_off(slot_cur);
  982. if (slot_update(&slot_cur)) {
  983. rc = -EFAULT;
  984. goto exit;
  985. }
  986. ibmphp_print_test();
  987. rc = ibmphp_update_slot_info(slot_cur);
  988. exit:
  989. ibmphp_unlock_operations();
  990. return rc;
  991. error_nopower:
  992. attn_off(slot_cur); /* need to turn off if was blinking b4 */
  993. attn_on(slot_cur);
  994. error_cont:
  995. rcpr = slot_update(&slot_cur);
  996. if (rcpr) {
  997. rc = rcpr;
  998. goto exit;
  999. }
  1000. ibmphp_update_slot_info(slot_cur);
  1001. goto exit;
  1002. error_power:
  1003. attn_off(slot_cur); /* need to turn off if was blinking b4 */
  1004. attn_on(slot_cur);
  1005. rcpr = power_off(slot_cur);
  1006. if (rcpr) {
  1007. rc = rcpr;
  1008. goto exit;
  1009. }
  1010. goto error_cont;
  1011. }
  1012. /**************************************************************
  1013. * HOT REMOVING ADAPTER CARD *
  1014. * INPUT: POINTER TO THE HOTPLUG SLOT STRUCTURE *
  1015. * OUTPUT: SUCCESS 0 ; FAILURE: UNCONFIGURE , VALIDATE *
  1016. * DISABLE POWER , *
  1017. **************************************************************/
  1018. static int ibmphp_disable_slot(struct hotplug_slot *hotplug_slot)
  1019. {
  1020. struct slot *slot = hotplug_slot->private;
  1021. int rc;
  1022. ibmphp_lock_operations();
  1023. rc = ibmphp_do_disable_slot(slot);
  1024. ibmphp_unlock_operations();
  1025. return rc;
  1026. }
  1027. int ibmphp_do_disable_slot(struct slot *slot_cur)
  1028. {
  1029. int rc;
  1030. u8 flag;
  1031. debug("DISABLING SLOT...\n");
  1032. if ((slot_cur == NULL) || (slot_cur->ctrl == NULL))
  1033. return -ENODEV;
  1034. flag = slot_cur->flag;
  1035. slot_cur->flag = 1;
  1036. if (flag == 1) {
  1037. rc = validate(slot_cur, DISABLE);
  1038. /* checking if powered off already & valid slot # */
  1039. if (rc)
  1040. goto error;
  1041. }
  1042. attn_LED_blink(slot_cur);
  1043. if (slot_cur->func == NULL) {
  1044. /* We need this for functions that were there on bootup */
  1045. slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
  1046. if (!slot_cur->func) {
  1047. err("out of system memory\n");
  1048. rc = -ENOMEM;
  1049. goto error;
  1050. }
  1051. slot_cur->func->busno = slot_cur->bus;
  1052. slot_cur->func->device = slot_cur->device;
  1053. }
  1054. ibm_unconfigure_device(slot_cur->func);
  1055. /*
  1056. * If we got here from latch suddenly opening on operating card or
  1057. * a power fault, there's no power to the card, so cannot
  1058. * read from it to determine what resources it occupied. This operation
  1059. * is forbidden anyhow. The best we can do is remove it from kernel
  1060. * lists at least */
  1061. if (!flag) {
  1062. attn_off(slot_cur);
  1063. return 0;
  1064. }
  1065. rc = ibmphp_unconfigure_card(&slot_cur, 0);
  1066. slot_cur->func = NULL;
  1067. debug("in disable_slot. after unconfigure_card\n");
  1068. if (rc) {
  1069. err("could not unconfigure card.\n");
  1070. goto error;
  1071. }
  1072. rc = ibmphp_hpc_writeslot(slot_cur, HPC_SLOT_OFF);
  1073. if (rc)
  1074. goto error;
  1075. attn_off(slot_cur);
  1076. rc = slot_update(&slot_cur);
  1077. if (rc)
  1078. goto exit;
  1079. rc = ibmphp_update_slot_info(slot_cur);
  1080. ibmphp_print_test();
  1081. exit:
  1082. return rc;
  1083. error:
  1084. /* Need to turn off if was blinking b4 */
  1085. attn_off(slot_cur);
  1086. attn_on(slot_cur);
  1087. if (slot_update(&slot_cur)) {
  1088. rc = -EFAULT;
  1089. goto exit;
  1090. }
  1091. if (flag)
  1092. ibmphp_update_slot_info(slot_cur);
  1093. goto exit;
  1094. }
  1095. struct hotplug_slot_ops ibmphp_hotplug_slot_ops = {
  1096. .set_attention_status = set_attention_status,
  1097. .enable_slot = enable_slot,
  1098. .disable_slot = ibmphp_disable_slot,
  1099. .hardware_test = NULL,
  1100. .get_power_status = get_power_status,
  1101. .get_attention_status = get_attention_status,
  1102. .get_latch_status = get_latch_status,
  1103. .get_adapter_status = get_adapter_present,
  1104. /* .get_max_adapter_speed = get_max_adapter_speed,
  1105. .get_bus_name_status = get_bus_name,
  1106. */
  1107. };
  1108. static void ibmphp_unload(void)
  1109. {
  1110. free_slots();
  1111. debug("after slots\n");
  1112. ibmphp_free_resources();
  1113. debug("after resources\n");
  1114. ibmphp_free_bus_info_queue();
  1115. debug("after bus info\n");
  1116. ibmphp_free_ebda_hpc_queue();
  1117. debug("after ebda hpc\n");
  1118. ibmphp_free_ebda_pci_rsrc_queue();
  1119. debug("after ebda pci rsrc\n");
  1120. kfree(ibmphp_pci_bus);
  1121. }
  1122. static int __init ibmphp_init(void)
  1123. {
  1124. struct pci_bus *bus;
  1125. int i = 0;
  1126. int rc = 0;
  1127. init_flag = 1;
  1128. info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
  1129. ibmphp_pci_bus = kmalloc(sizeof(*ibmphp_pci_bus), GFP_KERNEL);
  1130. if (!ibmphp_pci_bus) {
  1131. err("out of memory\n");
  1132. rc = -ENOMEM;
  1133. goto exit;
  1134. }
  1135. bus = pci_find_bus(0, 0);
  1136. if (!bus) {
  1137. err("Can't find the root pci bus, can not continue\n");
  1138. rc = -ENODEV;
  1139. goto error;
  1140. }
  1141. memcpy(ibmphp_pci_bus, bus, sizeof(*ibmphp_pci_bus));
  1142. ibmphp_debug = debug;
  1143. ibmphp_hpc_initvars();
  1144. for (i = 0; i < 16; i++)
  1145. irqs[i] = 0;
  1146. rc = ibmphp_access_ebda();
  1147. if (rc)
  1148. goto error;
  1149. debug("after ibmphp_access_ebda()\n");
  1150. rc = ibmphp_rsrc_init();
  1151. if (rc)
  1152. goto error;
  1153. debug("AFTER Resource & EBDA INITIALIZATIONS\n");
  1154. max_slots = get_max_slots();
  1155. rc = ibmphp_register_pci();
  1156. if (rc)
  1157. goto error;
  1158. if (init_ops()) {
  1159. rc = -ENODEV;
  1160. goto error;
  1161. }
  1162. ibmphp_print_test();
  1163. rc = ibmphp_hpc_start_poll_thread();
  1164. if (rc)
  1165. goto error;
  1166. exit:
  1167. return rc;
  1168. error:
  1169. ibmphp_unload();
  1170. goto exit;
  1171. }
  1172. static void __exit ibmphp_exit(void)
  1173. {
  1174. ibmphp_hpc_stop_poll_thread();
  1175. debug("after polling\n");
  1176. ibmphp_unload();
  1177. debug("done\n");
  1178. }
  1179. module_init(ibmphp_init);
  1180. module_exit(ibmphp_exit);