ibmphp_core.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  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 = 0;
  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. return -ENOMEM;
  511. info->power_status = SLOT_PWRGD(slot_cur->status);
  512. info->attention_status = SLOT_ATTN(slot_cur->status,
  513. slot_cur->ext_status);
  514. info->latch_status = SLOT_LATCH(slot_cur->status);
  515. if (!SLOT_PRESENT(slot_cur->status)) {
  516. info->adapter_status = 0;
  517. /* info->max_adapter_speed_status = MAX_ADAPTER_NONE; */
  518. } else {
  519. info->adapter_status = 1;
  520. /* get_max_adapter_speed_1(slot_cur->hotplug_slot,
  521. &info->max_adapter_speed_status, 0); */
  522. }
  523. bus_speed = slot_cur->bus_on->current_speed;
  524. mode = slot_cur->bus_on->current_bus_mode;
  525. switch (bus_speed) {
  526. case BUS_SPEED_33:
  527. break;
  528. case BUS_SPEED_66:
  529. if (mode == BUS_MODE_PCIX)
  530. bus_speed += 0x01;
  531. else if (mode == BUS_MODE_PCI)
  532. ;
  533. else
  534. bus_speed = PCI_SPEED_UNKNOWN;
  535. break;
  536. case BUS_SPEED_100:
  537. case BUS_SPEED_133:
  538. bus_speed += 0x01;
  539. break;
  540. default:
  541. bus_speed = PCI_SPEED_UNKNOWN;
  542. }
  543. bus->cur_bus_speed = bus_speed;
  544. // To do: bus_names
  545. rc = pci_hp_change_slot_info(slot_cur->hotplug_slot, info);
  546. kfree(info);
  547. return rc;
  548. }
  549. /******************************************************************************
  550. * This function will return the pci_func, given bus and devfunc, or NULL. It
  551. * is called from visit routines
  552. ******************************************************************************/
  553. static struct pci_func *ibm_slot_find(u8 busno, u8 device, u8 function)
  554. {
  555. struct pci_func *func_cur;
  556. struct slot *slot_cur;
  557. list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) {
  558. if (slot_cur->func) {
  559. func_cur = slot_cur->func;
  560. while (func_cur) {
  561. if ((func_cur->busno == busno) &&
  562. (func_cur->device == device) &&
  563. (func_cur->function == function))
  564. return func_cur;
  565. func_cur = func_cur->next;
  566. }
  567. }
  568. }
  569. return NULL;
  570. }
  571. /*************************************************************
  572. * This routine frees up memory used by struct slot, including
  573. * the pointers to pci_func, bus, hotplug_slot, controller,
  574. * and deregistering from the hotplug core
  575. *************************************************************/
  576. static void free_slots(void)
  577. {
  578. struct slot *slot_cur, *next;
  579. debug("%s -- enter\n", __func__);
  580. list_for_each_entry_safe(slot_cur, next, &ibmphp_slot_head,
  581. ibm_slot_list) {
  582. pci_hp_del(slot_cur->hotplug_slot);
  583. slot_cur->ctrl = NULL;
  584. slot_cur->bus_on = NULL;
  585. /*
  586. * We don't want to actually remove the resources,
  587. * since ibmphp_free_resources() will do just that.
  588. */
  589. ibmphp_unconfigure_card(&slot_cur, -1);
  590. pci_hp_destroy(slot_cur->hotplug_slot);
  591. kfree(slot_cur->hotplug_slot->info);
  592. kfree(slot_cur->hotplug_slot);
  593. kfree(slot_cur);
  594. }
  595. debug("%s -- exit\n", __func__);
  596. }
  597. static void ibm_unconfigure_device(struct pci_func *func)
  598. {
  599. struct pci_dev *temp;
  600. u8 j;
  601. debug("inside %s\n", __func__);
  602. debug("func->device = %x, func->function = %x\n",
  603. func->device, func->function);
  604. debug("func->device << 3 | 0x0 = %x\n", func->device << 3 | 0x0);
  605. pci_lock_rescan_remove();
  606. for (j = 0; j < 0x08; j++) {
  607. temp = pci_get_domain_bus_and_slot(0, func->busno,
  608. (func->device << 3) | j);
  609. if (temp) {
  610. pci_stop_and_remove_bus_device(temp);
  611. pci_dev_put(temp);
  612. }
  613. }
  614. pci_dev_put(func->dev);
  615. pci_unlock_rescan_remove();
  616. }
  617. /*
  618. * The following function is to fix kernel bug regarding
  619. * getting bus entries, here we manually add those primary
  620. * bus entries to kernel bus structure whenever apply
  621. */
  622. static u8 bus_structure_fixup(u8 busno)
  623. {
  624. struct pci_bus *bus, *b;
  625. struct pci_dev *dev;
  626. u16 l;
  627. if (pci_find_bus(0, busno) || !(ibmphp_find_same_bus_num(busno)))
  628. return 1;
  629. bus = kmalloc(sizeof(*bus), GFP_KERNEL);
  630. if (!bus)
  631. return 1;
  632. dev = kmalloc(sizeof(*dev), GFP_KERNEL);
  633. if (!dev) {
  634. kfree(bus);
  635. return 1;
  636. }
  637. bus->number = busno;
  638. bus->ops = ibmphp_pci_bus->ops;
  639. dev->bus = bus;
  640. for (dev->devfn = 0; dev->devfn < 256; dev->devfn += 8) {
  641. if (!pci_read_config_word(dev, PCI_VENDOR_ID, &l) &&
  642. (l != 0x0000) && (l != 0xffff)) {
  643. debug("%s - Inside bus_structure_fixup()\n",
  644. __func__);
  645. b = pci_scan_bus(busno, ibmphp_pci_bus->ops, NULL);
  646. if (!b)
  647. continue;
  648. pci_bus_add_devices(b);
  649. break;
  650. }
  651. }
  652. kfree(dev);
  653. kfree(bus);
  654. return 0;
  655. }
  656. static int ibm_configure_device(struct pci_func *func)
  657. {
  658. struct pci_bus *child;
  659. int num;
  660. int flag = 0; /* this is to make sure we don't double scan the bus,
  661. for bridged devices primarily */
  662. pci_lock_rescan_remove();
  663. if (!(bus_structure_fixup(func->busno)))
  664. flag = 1;
  665. if (func->dev == NULL)
  666. func->dev = pci_get_domain_bus_and_slot(0, func->busno,
  667. PCI_DEVFN(func->device, func->function));
  668. if (func->dev == NULL) {
  669. struct pci_bus *bus = pci_find_bus(0, func->busno);
  670. if (!bus)
  671. goto out;
  672. num = pci_scan_slot(bus,
  673. PCI_DEVFN(func->device, func->function));
  674. if (num)
  675. pci_bus_add_devices(bus);
  676. func->dev = pci_get_domain_bus_and_slot(0, func->busno,
  677. PCI_DEVFN(func->device, func->function));
  678. if (func->dev == NULL) {
  679. err("ERROR... : pci_dev still NULL\n");
  680. goto out;
  681. }
  682. }
  683. if (!(flag) && (func->dev->hdr_type == PCI_HEADER_TYPE_BRIDGE)) {
  684. pci_hp_add_bridge(func->dev);
  685. child = func->dev->subordinate;
  686. if (child)
  687. pci_bus_add_devices(child);
  688. }
  689. out:
  690. pci_unlock_rescan_remove();
  691. return 0;
  692. }
  693. /*******************************************************
  694. * Returns whether the bus is empty or not
  695. *******************************************************/
  696. static int is_bus_empty(struct slot *slot_cur)
  697. {
  698. int rc;
  699. struct slot *tmp_slot;
  700. u8 i = slot_cur->bus_on->slot_min;
  701. while (i <= slot_cur->bus_on->slot_max) {
  702. if (i == slot_cur->number) {
  703. i++;
  704. continue;
  705. }
  706. tmp_slot = ibmphp_get_slot_from_physical_num(i);
  707. if (!tmp_slot)
  708. return 0;
  709. rc = slot_update(&tmp_slot);
  710. if (rc)
  711. return 0;
  712. if (SLOT_PRESENT(tmp_slot->status) &&
  713. SLOT_PWRGD(tmp_slot->status))
  714. return 0;
  715. i++;
  716. }
  717. return 1;
  718. }
  719. /***********************************************************
  720. * If the HPC permits and the bus currently empty, tries to set the
  721. * bus speed and mode at the maximum card and bus capability
  722. * Parameters: slot
  723. * Returns: bus is set (0) or error code
  724. ***********************************************************/
  725. static int set_bus(struct slot *slot_cur)
  726. {
  727. int rc;
  728. u8 speed;
  729. u8 cmd = 0x0;
  730. int retval;
  731. static const struct pci_device_id ciobx[] = {
  732. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 0x0101) },
  733. { },
  734. };
  735. debug("%s - entry slot # %d\n", __func__, slot_cur->number);
  736. if (SET_BUS_STATUS(slot_cur->ctrl) && is_bus_empty(slot_cur)) {
  737. rc = slot_update(&slot_cur);
  738. if (rc)
  739. return rc;
  740. speed = SLOT_SPEED(slot_cur->ext_status);
  741. debug("ext_status = %x, speed = %x\n", slot_cur->ext_status, speed);
  742. switch (speed) {
  743. case HPC_SLOT_SPEED_33:
  744. cmd = HPC_BUS_33CONVMODE;
  745. break;
  746. case HPC_SLOT_SPEED_66:
  747. if (SLOT_PCIX(slot_cur->ext_status)) {
  748. if ((slot_cur->supported_speed >= BUS_SPEED_66) &&
  749. (slot_cur->supported_bus_mode == BUS_MODE_PCIX))
  750. cmd = HPC_BUS_66PCIXMODE;
  751. else if (!SLOT_BUS_MODE(slot_cur->ext_status))
  752. /* if max slot/bus capability is 66 pci
  753. and there's no bus mode mismatch, then
  754. the adapter supports 66 pci */
  755. cmd = HPC_BUS_66CONVMODE;
  756. else
  757. cmd = HPC_BUS_33CONVMODE;
  758. } else {
  759. if (slot_cur->supported_speed >= BUS_SPEED_66)
  760. cmd = HPC_BUS_66CONVMODE;
  761. else
  762. cmd = HPC_BUS_33CONVMODE;
  763. }
  764. break;
  765. case HPC_SLOT_SPEED_133:
  766. switch (slot_cur->supported_speed) {
  767. case BUS_SPEED_33:
  768. cmd = HPC_BUS_33CONVMODE;
  769. break;
  770. case BUS_SPEED_66:
  771. if (slot_cur->supported_bus_mode == BUS_MODE_PCIX)
  772. cmd = HPC_BUS_66PCIXMODE;
  773. else
  774. cmd = HPC_BUS_66CONVMODE;
  775. break;
  776. case BUS_SPEED_100:
  777. cmd = HPC_BUS_100PCIXMODE;
  778. break;
  779. case BUS_SPEED_133:
  780. /* This is to take care of the bug in CIOBX chip */
  781. if (pci_dev_present(ciobx))
  782. ibmphp_hpc_writeslot(slot_cur,
  783. HPC_BUS_100PCIXMODE);
  784. cmd = HPC_BUS_133PCIXMODE;
  785. break;
  786. default:
  787. err("Wrong bus speed\n");
  788. return -ENODEV;
  789. }
  790. break;
  791. default:
  792. err("wrong slot speed\n");
  793. return -ENODEV;
  794. }
  795. debug("setting bus speed for slot %d, cmd %x\n",
  796. slot_cur->number, cmd);
  797. retval = ibmphp_hpc_writeslot(slot_cur, cmd);
  798. if (retval) {
  799. err("setting bus speed failed\n");
  800. return retval;
  801. }
  802. if (CTLR_RESULT(slot_cur->ctrl->status)) {
  803. err("command not completed successfully in set_bus\n");
  804. return -EIO;
  805. }
  806. }
  807. /* This is for x440, once Brandon fixes the firmware,
  808. will not need this delay */
  809. msleep(1000);
  810. debug("%s -Exit\n", __func__);
  811. return 0;
  812. }
  813. /* This routine checks the bus limitations that the slot is on from the BIOS.
  814. * This is used in deciding whether or not to power up the slot.
  815. * (electrical/spec limitations. For example, >1 133 MHz or >2 66 PCI cards on
  816. * same bus)
  817. * Parameters: slot
  818. * Returns: 0 = no limitations, -EINVAL = exceeded limitations on the bus
  819. */
  820. static int check_limitations(struct slot *slot_cur)
  821. {
  822. u8 i;
  823. struct slot *tmp_slot;
  824. u8 count = 0;
  825. u8 limitation = 0;
  826. for (i = slot_cur->bus_on->slot_min; i <= slot_cur->bus_on->slot_max; i++) {
  827. tmp_slot = ibmphp_get_slot_from_physical_num(i);
  828. if (!tmp_slot)
  829. return -ENODEV;
  830. if ((SLOT_PWRGD(tmp_slot->status)) &&
  831. !(SLOT_CONNECT(tmp_slot->status)))
  832. count++;
  833. }
  834. get_cur_bus_info(&slot_cur);
  835. switch (slot_cur->bus_on->current_speed) {
  836. case BUS_SPEED_33:
  837. limitation = slot_cur->bus_on->slots_at_33_conv;
  838. break;
  839. case BUS_SPEED_66:
  840. if (slot_cur->bus_on->current_bus_mode == BUS_MODE_PCIX)
  841. limitation = slot_cur->bus_on->slots_at_66_pcix;
  842. else
  843. limitation = slot_cur->bus_on->slots_at_66_conv;
  844. break;
  845. case BUS_SPEED_100:
  846. limitation = slot_cur->bus_on->slots_at_100_pcix;
  847. break;
  848. case BUS_SPEED_133:
  849. limitation = slot_cur->bus_on->slots_at_133_pcix;
  850. break;
  851. }
  852. if ((count + 1) > limitation)
  853. return -EINVAL;
  854. return 0;
  855. }
  856. static inline void print_card_capability(struct slot *slot_cur)
  857. {
  858. info("capability of the card is ");
  859. if ((slot_cur->ext_status & CARD_INFO) == PCIX133)
  860. info(" 133 MHz PCI-X\n");
  861. else if ((slot_cur->ext_status & CARD_INFO) == PCIX66)
  862. info(" 66 MHz PCI-X\n");
  863. else if ((slot_cur->ext_status & CARD_INFO) == PCI66)
  864. info(" 66 MHz PCI\n");
  865. else
  866. info(" 33 MHz PCI\n");
  867. }
  868. /* This routine will power on the slot, configure the device(s) and find the
  869. * drivers for them.
  870. * Parameters: hotplug_slot
  871. * Returns: 0 or failure codes
  872. */
  873. static int enable_slot(struct hotplug_slot *hs)
  874. {
  875. int rc, i, rcpr;
  876. struct slot *slot_cur;
  877. u8 function;
  878. struct pci_func *tmp_func;
  879. ibmphp_lock_operations();
  880. debug("ENABLING SLOT........\n");
  881. slot_cur = hs->private;
  882. rc = validate(slot_cur, ENABLE);
  883. if (rc) {
  884. err("validate function failed\n");
  885. goto error_nopower;
  886. }
  887. attn_LED_blink(slot_cur);
  888. rc = set_bus(slot_cur);
  889. if (rc) {
  890. err("was not able to set the bus\n");
  891. goto error_nopower;
  892. }
  893. /*-----------------debugging------------------------------*/
  894. get_cur_bus_info(&slot_cur);
  895. debug("the current bus speed right after set_bus = %x\n",
  896. slot_cur->bus_on->current_speed);
  897. /*----------------------------------------------------------*/
  898. rc = check_limitations(slot_cur);
  899. if (rc) {
  900. err("Adding this card exceeds the limitations of this bus.\n");
  901. err("(i.e., >1 133MHz cards running on same bus, or >2 66 PCI cards running on same bus.\n");
  902. err("Try hot-adding into another bus\n");
  903. rc = -EINVAL;
  904. goto error_nopower;
  905. }
  906. rc = power_on(slot_cur);
  907. if (rc) {
  908. err("something wrong when powering up... please see below for details\n");
  909. /* need to turn off before on, otherwise, blinking overwrites */
  910. attn_off(slot_cur);
  911. attn_on(slot_cur);
  912. if (slot_update(&slot_cur)) {
  913. attn_off(slot_cur);
  914. attn_on(slot_cur);
  915. rc = -ENODEV;
  916. goto exit;
  917. }
  918. /* Check to see the error of why it failed */
  919. if ((SLOT_POWER(slot_cur->status)) &&
  920. !(SLOT_PWRGD(slot_cur->status)))
  921. err("power fault occurred trying to power up\n");
  922. else if (SLOT_BUS_SPEED(slot_cur->status)) {
  923. err("bus speed mismatch occurred. please check current bus speed and card capability\n");
  924. print_card_capability(slot_cur);
  925. } else if (SLOT_BUS_MODE(slot_cur->ext_status)) {
  926. err("bus mode mismatch occurred. please check current bus mode and card capability\n");
  927. print_card_capability(slot_cur);
  928. }
  929. ibmphp_update_slot_info(slot_cur);
  930. goto exit;
  931. }
  932. debug("after power_on\n");
  933. /*-----------------------debugging---------------------------*/
  934. get_cur_bus_info(&slot_cur);
  935. debug("the current bus speed right after power_on = %x\n",
  936. slot_cur->bus_on->current_speed);
  937. /*----------------------------------------------------------*/
  938. rc = slot_update(&slot_cur);
  939. if (rc)
  940. goto error_power;
  941. rc = -EINVAL;
  942. if (SLOT_POWER(slot_cur->status) && !(SLOT_PWRGD(slot_cur->status))) {
  943. err("power fault occurred trying to power up...\n");
  944. goto error_power;
  945. }
  946. if (SLOT_POWER(slot_cur->status) && (SLOT_BUS_SPEED(slot_cur->status))) {
  947. err("bus speed mismatch occurred. please check current bus speed and card capability\n");
  948. print_card_capability(slot_cur);
  949. goto error_power;
  950. }
  951. /* Don't think this case will happen after above checks...
  952. * but just in case, for paranoia sake */
  953. if (!(SLOT_POWER(slot_cur->status))) {
  954. err("power on failed...\n");
  955. goto error_power;
  956. }
  957. slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
  958. if (!slot_cur->func) {
  959. /* We cannot do update_slot_info here, since no memory for
  960. * kmalloc n.e.ways, and update_slot_info allocates some */
  961. rc = -ENOMEM;
  962. goto error_power;
  963. }
  964. slot_cur->func->busno = slot_cur->bus;
  965. slot_cur->func->device = slot_cur->device;
  966. for (i = 0; i < 4; i++)
  967. slot_cur->func->irq[i] = slot_cur->irq[i];
  968. debug("b4 configure_card, slot_cur->bus = %x, slot_cur->device = %x\n",
  969. slot_cur->bus, slot_cur->device);
  970. if (ibmphp_configure_card(slot_cur->func, slot_cur->number)) {
  971. err("configure_card was unsuccessful...\n");
  972. /* true because don't need to actually deallocate resources,
  973. * just remove references */
  974. ibmphp_unconfigure_card(&slot_cur, 1);
  975. debug("after unconfigure_card\n");
  976. slot_cur->func = NULL;
  977. rc = -ENOMEM;
  978. goto error_power;
  979. }
  980. function = 0x00;
  981. do {
  982. tmp_func = ibm_slot_find(slot_cur->bus, slot_cur->func->device,
  983. function++);
  984. if (tmp_func && !(tmp_func->dev))
  985. ibm_configure_device(tmp_func);
  986. } while (tmp_func);
  987. attn_off(slot_cur);
  988. if (slot_update(&slot_cur)) {
  989. rc = -EFAULT;
  990. goto exit;
  991. }
  992. ibmphp_print_test();
  993. rc = ibmphp_update_slot_info(slot_cur);
  994. exit:
  995. ibmphp_unlock_operations();
  996. return rc;
  997. error_nopower:
  998. attn_off(slot_cur); /* need to turn off if was blinking b4 */
  999. attn_on(slot_cur);
  1000. error_cont:
  1001. rcpr = slot_update(&slot_cur);
  1002. if (rcpr) {
  1003. rc = rcpr;
  1004. goto exit;
  1005. }
  1006. ibmphp_update_slot_info(slot_cur);
  1007. goto exit;
  1008. error_power:
  1009. attn_off(slot_cur); /* need to turn off if was blinking b4 */
  1010. attn_on(slot_cur);
  1011. rcpr = power_off(slot_cur);
  1012. if (rcpr) {
  1013. rc = rcpr;
  1014. goto exit;
  1015. }
  1016. goto error_cont;
  1017. }
  1018. /**************************************************************
  1019. * HOT REMOVING ADAPTER CARD *
  1020. * INPUT: POINTER TO THE HOTPLUG SLOT STRUCTURE *
  1021. * OUTPUT: SUCCESS 0 ; FAILURE: UNCONFIGURE , VALIDATE *
  1022. * DISABLE POWER , *
  1023. **************************************************************/
  1024. static int ibmphp_disable_slot(struct hotplug_slot *hotplug_slot)
  1025. {
  1026. struct slot *slot = hotplug_slot->private;
  1027. int rc;
  1028. ibmphp_lock_operations();
  1029. rc = ibmphp_do_disable_slot(slot);
  1030. ibmphp_unlock_operations();
  1031. return rc;
  1032. }
  1033. int ibmphp_do_disable_slot(struct slot *slot_cur)
  1034. {
  1035. int rc;
  1036. u8 flag;
  1037. debug("DISABLING SLOT...\n");
  1038. if ((slot_cur == NULL) || (slot_cur->ctrl == NULL))
  1039. return -ENODEV;
  1040. flag = slot_cur->flag;
  1041. slot_cur->flag = 1;
  1042. if (flag == 1) {
  1043. rc = validate(slot_cur, DISABLE);
  1044. /* checking if powered off already & valid slot # */
  1045. if (rc)
  1046. goto error;
  1047. }
  1048. attn_LED_blink(slot_cur);
  1049. if (slot_cur->func == NULL) {
  1050. /* We need this for functions that were there on bootup */
  1051. slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
  1052. if (!slot_cur->func) {
  1053. rc = -ENOMEM;
  1054. goto error;
  1055. }
  1056. slot_cur->func->busno = slot_cur->bus;
  1057. slot_cur->func->device = slot_cur->device;
  1058. }
  1059. ibm_unconfigure_device(slot_cur->func);
  1060. /*
  1061. * If we got here from latch suddenly opening on operating card or
  1062. * a power fault, there's no power to the card, so cannot
  1063. * read from it to determine what resources it occupied. This operation
  1064. * is forbidden anyhow. The best we can do is remove it from kernel
  1065. * lists at least */
  1066. if (!flag) {
  1067. attn_off(slot_cur);
  1068. return 0;
  1069. }
  1070. rc = ibmphp_unconfigure_card(&slot_cur, 0);
  1071. slot_cur->func = NULL;
  1072. debug("in disable_slot. after unconfigure_card\n");
  1073. if (rc) {
  1074. err("could not unconfigure card.\n");
  1075. goto error;
  1076. }
  1077. rc = ibmphp_hpc_writeslot(slot_cur, HPC_SLOT_OFF);
  1078. if (rc)
  1079. goto error;
  1080. attn_off(slot_cur);
  1081. rc = slot_update(&slot_cur);
  1082. if (rc)
  1083. goto exit;
  1084. rc = ibmphp_update_slot_info(slot_cur);
  1085. ibmphp_print_test();
  1086. exit:
  1087. return rc;
  1088. error:
  1089. /* Need to turn off if was blinking b4 */
  1090. attn_off(slot_cur);
  1091. attn_on(slot_cur);
  1092. if (slot_update(&slot_cur)) {
  1093. rc = -EFAULT;
  1094. goto exit;
  1095. }
  1096. if (flag)
  1097. ibmphp_update_slot_info(slot_cur);
  1098. goto exit;
  1099. }
  1100. struct hotplug_slot_ops ibmphp_hotplug_slot_ops = {
  1101. .set_attention_status = set_attention_status,
  1102. .enable_slot = enable_slot,
  1103. .disable_slot = ibmphp_disable_slot,
  1104. .hardware_test = NULL,
  1105. .get_power_status = get_power_status,
  1106. .get_attention_status = get_attention_status,
  1107. .get_latch_status = get_latch_status,
  1108. .get_adapter_status = get_adapter_present,
  1109. /* .get_max_adapter_speed = get_max_adapter_speed,
  1110. .get_bus_name_status = get_bus_name,
  1111. */
  1112. };
  1113. static void ibmphp_unload(void)
  1114. {
  1115. free_slots();
  1116. debug("after slots\n");
  1117. ibmphp_free_resources();
  1118. debug("after resources\n");
  1119. ibmphp_free_bus_info_queue();
  1120. debug("after bus info\n");
  1121. ibmphp_free_ebda_hpc_queue();
  1122. debug("after ebda hpc\n");
  1123. ibmphp_free_ebda_pci_rsrc_queue();
  1124. debug("after ebda pci rsrc\n");
  1125. kfree(ibmphp_pci_bus);
  1126. }
  1127. static int __init ibmphp_init(void)
  1128. {
  1129. struct pci_bus *bus;
  1130. int i = 0;
  1131. int rc = 0;
  1132. init_flag = 1;
  1133. info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
  1134. ibmphp_pci_bus = kmalloc(sizeof(*ibmphp_pci_bus), GFP_KERNEL);
  1135. if (!ibmphp_pci_bus) {
  1136. rc = -ENOMEM;
  1137. goto exit;
  1138. }
  1139. bus = pci_find_bus(0, 0);
  1140. if (!bus) {
  1141. err("Can't find the root pci bus, can not continue\n");
  1142. rc = -ENODEV;
  1143. goto error;
  1144. }
  1145. memcpy(ibmphp_pci_bus, bus, sizeof(*ibmphp_pci_bus));
  1146. ibmphp_debug = debug;
  1147. ibmphp_hpc_initvars();
  1148. for (i = 0; i < 16; i++)
  1149. irqs[i] = 0;
  1150. rc = ibmphp_access_ebda();
  1151. if (rc)
  1152. goto error;
  1153. debug("after ibmphp_access_ebda()\n");
  1154. rc = ibmphp_rsrc_init();
  1155. if (rc)
  1156. goto error;
  1157. debug("AFTER Resource & EBDA INITIALIZATIONS\n");
  1158. max_slots = get_max_slots();
  1159. rc = ibmphp_register_pci();
  1160. if (rc)
  1161. goto error;
  1162. if (init_ops()) {
  1163. rc = -ENODEV;
  1164. goto error;
  1165. }
  1166. ibmphp_print_test();
  1167. rc = ibmphp_hpc_start_poll_thread();
  1168. if (rc)
  1169. goto error;
  1170. exit:
  1171. return rc;
  1172. error:
  1173. ibmphp_unload();
  1174. goto exit;
  1175. }
  1176. static void __exit ibmphp_exit(void)
  1177. {
  1178. ibmphp_hpc_stop_poll_thread();
  1179. debug("after polling\n");
  1180. ibmphp_unload();
  1181. debug("done\n");
  1182. }
  1183. module_init(ibmphp_init);
  1184. module_exit(ibmphp_exit);