ibmphp_core.c 34 KB

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