ibmphp_core.c 34 KB

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