ibmphp_core.c 34 KB

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