ibmphp_core.c 34 KB

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