ibmphp_core.c 34 KB

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