ibmphp_core.c 34 KB

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