ibmphp_core.c 34 KB

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