iop.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. /*
  2. * Functions to handle I2O controllers and I2O message handling
  3. *
  4. * Copyright (C) 1999-2002 Red Hat Software
  5. *
  6. * Written by Alan Cox, Building Number Three Ltd
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * A lot of the I2O message side code from this is taken from the
  14. * Red Creek RCPCI45 adapter driver by Red Creek Communications
  15. *
  16. * Fixes/additions:
  17. * Philipp Rumpf
  18. * Juha Sievänen <Juha.Sievanen@cs.Helsinki.FI>
  19. * Auvo Häkkinen <Auvo.Hakkinen@cs.Helsinki.FI>
  20. * Deepak Saxena <deepak@plexity.net>
  21. * Boji T Kannanthanam <boji.t.kannanthanam@intel.com>
  22. * Alan Cox <alan@redhat.com>:
  23. * Ported to Linux 2.5.
  24. * Markus Lidel <Markus.Lidel@shadowconnect.com>:
  25. * Minor fixes for 2.6.
  26. */
  27. #include <linux/module.h>
  28. #include <linux/i2o.h>
  29. #include <linux/delay.h>
  30. #define OSM_VERSION "$Rev$"
  31. #define OSM_DESCRIPTION "I2O subsystem"
  32. /* global I2O controller list */
  33. LIST_HEAD(i2o_controllers);
  34. /*
  35. * global I2O System Table. Contains information about all the IOPs in the
  36. * system. Used to inform IOPs about each others existence.
  37. */
  38. static struct i2o_dma i2o_systab;
  39. static int i2o_hrt_get(struct i2o_controller *c);
  40. /* Module internal functions from other sources */
  41. extern struct i2o_driver i2o_exec_driver;
  42. extern int i2o_exec_lct_get(struct i2o_controller *);
  43. extern void i2o_device_remove(struct i2o_device *);
  44. extern int __init i2o_driver_init(void);
  45. extern void __exit i2o_driver_exit(void);
  46. extern int __init i2o_exec_init(void);
  47. extern void __exit i2o_exec_exit(void);
  48. extern int __init i2o_pci_init(void);
  49. extern void __exit i2o_pci_exit(void);
  50. extern int i2o_device_init(void);
  51. extern void i2o_device_exit(void);
  52. /**
  53. * i2o_msg_nop - Returns a message which is not used
  54. * @c: I2O controller from which the message was created
  55. * @m: message which should be returned
  56. *
  57. * If you fetch a message via i2o_msg_get, and can't use it, you must
  58. * return the message with this function. Otherwise the message frame
  59. * is lost.
  60. */
  61. void i2o_msg_nop(struct i2o_controller *c, u32 m)
  62. {
  63. struct i2o_message __iomem *msg = c->in_queue.virt + m;
  64. writel(THREE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  65. writel(I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | ADAPTER_TID,
  66. &msg->u.head[1]);
  67. writel(0, &msg->u.head[2]);
  68. writel(0, &msg->u.head[3]);
  69. i2o_msg_post(c, m);
  70. };
  71. /**
  72. * i2o_msg_get_wait - obtain an I2O message from the IOP
  73. * @c: I2O controller
  74. * @msg: pointer to a I2O message pointer
  75. * @wait: how long to wait until timeout
  76. *
  77. * This function waits up to wait seconds for a message slot to be
  78. * available.
  79. *
  80. * On a success the message is returned and the pointer to the message is
  81. * set in msg. The returned message is the physical page frame offset
  82. * address from the read port (see the i2o spec). If no message is
  83. * available returns I2O_QUEUE_EMPTY and msg is leaved untouched.
  84. */
  85. u32 i2o_msg_get_wait(struct i2o_controller *c, struct i2o_message __iomem **msg,
  86. int wait)
  87. {
  88. unsigned long timeout = jiffies + wait * HZ;
  89. u32 m;
  90. while ((m = i2o_msg_get(c, msg)) == I2O_QUEUE_EMPTY) {
  91. if (time_after(jiffies, timeout)) {
  92. pr_debug("%s: Timeout waiting for message frame.\n",
  93. c->name);
  94. return I2O_QUEUE_EMPTY;
  95. }
  96. set_current_state(TASK_UNINTERRUPTIBLE);
  97. schedule_timeout(1);
  98. }
  99. return m;
  100. };
  101. #if BITS_PER_LONG == 64
  102. /**
  103. * i2o_cntxt_list_add - Append a pointer to context list and return a id
  104. * @c: controller to which the context list belong
  105. * @ptr: pointer to add to the context list
  106. *
  107. * Because the context field in I2O is only 32-bit large, on 64-bit the
  108. * pointer is to large to fit in the context field. The i2o_cntxt_list
  109. * functions therefore map pointers to context fields.
  110. *
  111. * Returns context id > 0 on success or 0 on failure.
  112. */
  113. u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
  114. {
  115. struct i2o_context_list_element *entry;
  116. unsigned long flags;
  117. if (!ptr)
  118. printk(KERN_ERR "%s: couldn't add NULL pointer to context list!"
  119. "\n", c->name);
  120. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  121. if (!entry) {
  122. printk(KERN_ERR "%s: Could not allocate memory for context "
  123. "list element\n", c->name);
  124. return 0;
  125. }
  126. entry->ptr = ptr;
  127. entry->timestamp = jiffies;
  128. INIT_LIST_HEAD(&entry->list);
  129. spin_lock_irqsave(&c->context_list_lock, flags);
  130. if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
  131. atomic_inc(&c->context_list_counter);
  132. entry->context = atomic_read(&c->context_list_counter);
  133. list_add(&entry->list, &c->context_list);
  134. spin_unlock_irqrestore(&c->context_list_lock, flags);
  135. pr_debug("%s: Add context to list %p -> %d\n", c->name, ptr, context);
  136. return entry->context;
  137. };
  138. /**
  139. * i2o_cntxt_list_remove - Remove a pointer from the context list
  140. * @c: controller to which the context list belong
  141. * @ptr: pointer which should be removed from the context list
  142. *
  143. * Removes a previously added pointer from the context list and returns
  144. * the matching context id.
  145. *
  146. * Returns context id on succes or 0 on failure.
  147. */
  148. u32 i2o_cntxt_list_remove(struct i2o_controller * c, void *ptr)
  149. {
  150. struct i2o_context_list_element *entry;
  151. u32 context = 0;
  152. unsigned long flags;
  153. spin_lock_irqsave(&c->context_list_lock, flags);
  154. list_for_each_entry(entry, &c->context_list, list)
  155. if (entry->ptr == ptr) {
  156. list_del(&entry->list);
  157. context = entry->context;
  158. kfree(entry);
  159. break;
  160. }
  161. spin_unlock_irqrestore(&c->context_list_lock, flags);
  162. if (!context)
  163. printk(KERN_WARNING "%s: Could not remove nonexistent ptr "
  164. "%p\n", c->name, ptr);
  165. pr_debug("%s: remove ptr from context list %d -> %p\n", c->name,
  166. context, ptr);
  167. return context;
  168. };
  169. /**
  170. * i2o_cntxt_list_get - Get a pointer from the context list and remove it
  171. * @c: controller to which the context list belong
  172. * @context: context id to which the pointer belong
  173. *
  174. * Returns pointer to the matching context id on success or NULL on
  175. * failure.
  176. */
  177. void *i2o_cntxt_list_get(struct i2o_controller *c, u32 context)
  178. {
  179. struct i2o_context_list_element *entry;
  180. unsigned long flags;
  181. void *ptr = NULL;
  182. spin_lock_irqsave(&c->context_list_lock, flags);
  183. list_for_each_entry(entry, &c->context_list, list)
  184. if (entry->context == context) {
  185. list_del(&entry->list);
  186. ptr = entry->ptr;
  187. kfree(entry);
  188. break;
  189. }
  190. spin_unlock_irqrestore(&c->context_list_lock, flags);
  191. if (!ptr)
  192. printk(KERN_WARNING "%s: context id %d not found\n", c->name,
  193. context);
  194. pr_debug("%s: get ptr from context list %d -> %p\n", c->name, context,
  195. ptr);
  196. return ptr;
  197. };
  198. /**
  199. * i2o_cntxt_list_get_ptr - Get a context id from the context list
  200. * @c: controller to which the context list belong
  201. * @ptr: pointer to which the context id should be fetched
  202. *
  203. * Returns context id which matches to the pointer on succes or 0 on
  204. * failure.
  205. */
  206. u32 i2o_cntxt_list_get_ptr(struct i2o_controller * c, void *ptr)
  207. {
  208. struct i2o_context_list_element *entry;
  209. u32 context = 0;
  210. unsigned long flags;
  211. spin_lock_irqsave(&c->context_list_lock, flags);
  212. list_for_each_entry(entry, &c->context_list, list)
  213. if (entry->ptr == ptr) {
  214. context = entry->context;
  215. break;
  216. }
  217. spin_unlock_irqrestore(&c->context_list_lock, flags);
  218. if (!context)
  219. printk(KERN_WARNING "%s: Could not find nonexistent ptr "
  220. "%p\n", c->name, ptr);
  221. pr_debug("%s: get context id from context list %p -> %d\n", c->name,
  222. ptr, context);
  223. return context;
  224. };
  225. #endif
  226. /**
  227. * i2o_iop_find - Find an I2O controller by id
  228. * @unit: unit number of the I2O controller to search for
  229. *
  230. * Lookup the I2O controller on the controller list.
  231. *
  232. * Returns pointer to the I2O controller on success or NULL if not found.
  233. */
  234. struct i2o_controller *i2o_find_iop(int unit)
  235. {
  236. struct i2o_controller *c;
  237. list_for_each_entry(c, &i2o_controllers, list) {
  238. if (c->unit == unit)
  239. return c;
  240. }
  241. return NULL;
  242. };
  243. /**
  244. * i2o_iop_find_device - Find a I2O device on an I2O controller
  245. * @c: I2O controller where the I2O device hangs on
  246. * @tid: TID of the I2O device to search for
  247. *
  248. * Searches the devices of the I2O controller for a device with TID tid and
  249. * returns it.
  250. *
  251. * Returns a pointer to the I2O device if found, otherwise NULL.
  252. */
  253. struct i2o_device *i2o_iop_find_device(struct i2o_controller *c, u16 tid)
  254. {
  255. struct i2o_device *dev;
  256. list_for_each_entry(dev, &c->devices, list)
  257. if (dev->lct_data.tid == tid)
  258. return dev;
  259. return NULL;
  260. };
  261. /**
  262. * i2o_quiesce_controller - quiesce controller
  263. * @c: controller
  264. *
  265. * Quiesce an IOP. Causes IOP to make external operation quiescent
  266. * (i2o 'READY' state). Internal operation of the IOP continues normally.
  267. *
  268. * Returns 0 on success or negative error code on failure.
  269. */
  270. static int i2o_iop_quiesce(struct i2o_controller *c)
  271. {
  272. struct i2o_message __iomem *msg;
  273. u32 m;
  274. i2o_status_block *sb = c->status_block.virt;
  275. int rc;
  276. i2o_status_get(c);
  277. /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
  278. if ((sb->iop_state != ADAPTER_STATE_READY) &&
  279. (sb->iop_state != ADAPTER_STATE_OPERATIONAL))
  280. return 0;
  281. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  282. if (m == I2O_QUEUE_EMPTY)
  283. return -ETIMEDOUT;
  284. writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  285. writel(I2O_CMD_SYS_QUIESCE << 24 | HOST_TID << 12 | ADAPTER_TID,
  286. &msg->u.head[1]);
  287. /* Long timeout needed for quiesce if lots of devices */
  288. if ((rc = i2o_msg_post_wait(c, m, 240)))
  289. printk(KERN_INFO "%s: Unable to quiesce (status=%#x).\n",
  290. c->name, -rc);
  291. else
  292. pr_debug("%s: Quiesced.\n", c->name);
  293. i2o_status_get(c); // Entered READY state
  294. return rc;
  295. };
  296. /**
  297. * i2o_iop_enable - move controller from ready to OPERATIONAL
  298. * @c: I2O controller
  299. *
  300. * Enable IOP. This allows the IOP to resume external operations and
  301. * reverses the effect of a quiesce. Returns zero or an error code if
  302. * an error occurs.
  303. */
  304. static int i2o_iop_enable(struct i2o_controller *c)
  305. {
  306. struct i2o_message __iomem *msg;
  307. u32 m;
  308. i2o_status_block *sb = c->status_block.virt;
  309. int rc;
  310. i2o_status_get(c);
  311. /* Enable only allowed on READY state */
  312. if (sb->iop_state != ADAPTER_STATE_READY)
  313. return -EINVAL;
  314. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  315. if (m == I2O_QUEUE_EMPTY)
  316. return -ETIMEDOUT;
  317. writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  318. writel(I2O_CMD_SYS_ENABLE << 24 | HOST_TID << 12 | ADAPTER_TID,
  319. &msg->u.head[1]);
  320. /* How long of a timeout do we need? */
  321. if ((rc = i2o_msg_post_wait(c, m, 240)))
  322. printk(KERN_ERR "%s: Could not enable (status=%#x).\n",
  323. c->name, -rc);
  324. else
  325. pr_debug("%s: Enabled.\n", c->name);
  326. i2o_status_get(c); // entered OPERATIONAL state
  327. return rc;
  328. };
  329. /**
  330. * i2o_iop_quiesce_all - Quiesce all I2O controllers on the system
  331. *
  332. * Quiesce all I2O controllers which are connected to the system.
  333. */
  334. static inline void i2o_iop_quiesce_all(void)
  335. {
  336. struct i2o_controller *c, *tmp;
  337. list_for_each_entry_safe(c, tmp, &i2o_controllers, list) {
  338. if (!c->no_quiesce)
  339. i2o_iop_quiesce(c);
  340. }
  341. };
  342. /**
  343. * i2o_iop_enable_all - Enables all controllers on the system
  344. *
  345. * Enables all I2O controllers which are connected to the system.
  346. */
  347. static inline void i2o_iop_enable_all(void)
  348. {
  349. struct i2o_controller *c, *tmp;
  350. list_for_each_entry_safe(c, tmp, &i2o_controllers, list)
  351. i2o_iop_enable(c);
  352. };
  353. /**
  354. * i2o_clear_controller - Bring I2O controller into HOLD state
  355. * @c: controller
  356. *
  357. * Clear an IOP to HOLD state, ie. terminate external operations, clear all
  358. * input queues and prepare for a system restart. IOP's internal operation
  359. * continues normally and the outbound queue is alive. The IOP is not
  360. * expected to rebuild its LCT.
  361. *
  362. * Returns 0 on success or negative error code on failure.
  363. */
  364. static int i2o_iop_clear(struct i2o_controller *c)
  365. {
  366. struct i2o_message __iomem *msg;
  367. u32 m;
  368. int rc;
  369. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  370. if (m == I2O_QUEUE_EMPTY)
  371. return -ETIMEDOUT;
  372. /* Quiesce all IOPs first */
  373. i2o_iop_quiesce_all();
  374. writel(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  375. writel(I2O_CMD_ADAPTER_CLEAR << 24 | HOST_TID << 12 | ADAPTER_TID,
  376. &msg->u.head[1]);
  377. if ((rc = i2o_msg_post_wait(c, m, 30)))
  378. printk(KERN_INFO "%s: Unable to clear (status=%#x).\n",
  379. c->name, -rc);
  380. else
  381. pr_debug("%s: Cleared.\n", c->name);
  382. /* Enable all IOPs */
  383. i2o_iop_enable_all();
  384. i2o_status_get(c);
  385. return rc;
  386. }
  387. /**
  388. * i2o_iop_reset - reset an I2O controller
  389. * @c: controller to reset
  390. *
  391. * Reset the IOP into INIT state and wait until IOP gets into RESET state.
  392. * Terminate all external operations, clear IOP's inbound and outbound
  393. * queues, terminate all DDMs, and reload the IOP's operating environment
  394. * and all local DDMs. The IOP rebuilds its LCT.
  395. */
  396. static int i2o_iop_reset(struct i2o_controller *c)
  397. {
  398. u8 *status = c->status.virt;
  399. struct i2o_message __iomem *msg;
  400. u32 m;
  401. unsigned long timeout;
  402. i2o_status_block *sb = c->status_block.virt;
  403. int rc = 0;
  404. pr_debug("%s: Resetting controller\n", c->name);
  405. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  406. if (m == I2O_QUEUE_EMPTY)
  407. return -ETIMEDOUT;
  408. memset(status, 0, 8);
  409. /* Quiesce all IOPs first */
  410. i2o_iop_quiesce_all();
  411. writel(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  412. writel(I2O_CMD_ADAPTER_RESET << 24 | HOST_TID << 12 | ADAPTER_TID,
  413. &msg->u.head[1]);
  414. writel(i2o_exec_driver.context, &msg->u.s.icntxt);
  415. writel(0, &msg->u.s.tcntxt); //FIXME: use reasonable transaction context
  416. writel(0, &msg->body[0]);
  417. writel(0, &msg->body[1]);
  418. writel(i2o_ptr_low((void *)c->status.phys), &msg->body[2]);
  419. writel(i2o_ptr_high((void *)c->status.phys), &msg->body[3]);
  420. i2o_msg_post(c, m);
  421. /* Wait for a reply */
  422. timeout = jiffies + I2O_TIMEOUT_RESET * HZ;
  423. while (!*status) {
  424. if (time_after(jiffies, timeout)) {
  425. printk(KERN_ERR "%s: IOP reset timeout.\n", c->name);
  426. rc = -ETIMEDOUT;
  427. goto exit;
  428. }
  429. /* Promise bug */
  430. if (status[1] || status[4]) {
  431. *status = 0;
  432. break;
  433. }
  434. set_current_state(TASK_UNINTERRUPTIBLE);
  435. schedule_timeout(1);
  436. rmb();
  437. }
  438. if (*status == I2O_CMD_IN_PROGRESS) {
  439. /*
  440. * Once the reset is sent, the IOP goes into the INIT state
  441. * which is indeterminate. We need to wait until the IOP
  442. * has rebooted before we can let the system talk to
  443. * it. We read the inbound Free_List until a message is
  444. * available. If we can't read one in the given ammount of
  445. * time, we assume the IOP could not reboot properly.
  446. */
  447. pr_debug("%s: Reset in progress, waiting for reboot...\n",
  448. c->name);
  449. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET);
  450. while (m == I2O_QUEUE_EMPTY) {
  451. if (time_after(jiffies, timeout)) {
  452. printk(KERN_ERR "%s: IOP reset timeout.\n",
  453. c->name);
  454. rc = -ETIMEDOUT;
  455. goto exit;
  456. }
  457. set_current_state(TASK_UNINTERRUPTIBLE);
  458. schedule_timeout(1);
  459. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET);
  460. }
  461. i2o_msg_nop(c, m);
  462. }
  463. /* from here all quiesce commands are safe */
  464. c->no_quiesce = 0;
  465. /* If IopReset was rejected or didn't perform reset, try IopClear */
  466. i2o_status_get(c);
  467. if (*status == I2O_CMD_REJECTED || sb->iop_state != ADAPTER_STATE_RESET) {
  468. printk(KERN_WARNING "%s: Reset rejected, trying to clear\n",
  469. c->name);
  470. i2o_iop_clear(c);
  471. } else
  472. pr_debug("%s: Reset completed.\n", c->name);
  473. exit:
  474. /* Enable all IOPs */
  475. i2o_iop_enable_all();
  476. return rc;
  477. };
  478. /**
  479. * i2o_iop_init_outbound_queue - setup the outbound message queue
  480. * @c: I2O controller
  481. *
  482. * Clear and (re)initialize IOP's outbound queue and post the message
  483. * frames to the IOP.
  484. *
  485. * Returns 0 on success or a negative errno code on failure.
  486. */
  487. static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
  488. {
  489. u8 *status = c->status.virt;
  490. u32 m;
  491. struct i2o_message __iomem *msg;
  492. ulong timeout;
  493. int i;
  494. pr_debug("%s: Initializing Outbound Queue...\n", c->name);
  495. memset(status, 0, 4);
  496. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  497. if (m == I2O_QUEUE_EMPTY)
  498. return -ETIMEDOUT;
  499. writel(EIGHT_WORD_MSG_SIZE | TRL_OFFSET_6, &msg->u.head[0]);
  500. writel(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 | ADAPTER_TID,
  501. &msg->u.head[1]);
  502. writel(i2o_exec_driver.context, &msg->u.s.icntxt);
  503. writel(0x0106, &msg->u.s.tcntxt); /* FIXME: why 0x0106, maybe in
  504. Spec? */
  505. writel(PAGE_SIZE, &msg->body[0]);
  506. writel(MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]); /* Outbound msg frame
  507. size in words and Initcode */
  508. writel(0xd0000004, &msg->body[2]);
  509. writel(i2o_ptr_low((void *)c->status.phys), &msg->body[3]);
  510. writel(i2o_ptr_high((void *)c->status.phys), &msg->body[4]);
  511. i2o_msg_post(c, m);
  512. timeout = jiffies + I2O_TIMEOUT_INIT_OUTBOUND_QUEUE * HZ;
  513. while (*status <= I2O_CMD_IN_PROGRESS) {
  514. if (time_after(jiffies, timeout)) {
  515. printk(KERN_WARNING "%s: Timeout Initializing\n",
  516. c->name);
  517. return -ETIMEDOUT;
  518. }
  519. set_current_state(TASK_UNINTERRUPTIBLE);
  520. schedule_timeout(1);
  521. rmb();
  522. }
  523. m = c->out_queue.phys;
  524. /* Post frames */
  525. for (i = 0; i < NMBR_MSG_FRAMES; i++) {
  526. i2o_flush_reply(c, m);
  527. udelay(1); /* Promise */
  528. m += MSG_FRAME_SIZE * 4;
  529. }
  530. return 0;
  531. }
  532. /**
  533. * i2o_iop_send_nop - send a core NOP message
  534. * @c: controller
  535. *
  536. * Send a no-operation message with a reply set to cause no
  537. * action either. Needed for bringing up promise controllers.
  538. */
  539. static int i2o_iop_send_nop(struct i2o_controller *c)
  540. {
  541. struct i2o_message __iomem *msg;
  542. u32 m = i2o_msg_get_wait(c, &msg, HZ);
  543. if (m == I2O_QUEUE_EMPTY)
  544. return -ETIMEDOUT;
  545. i2o_msg_nop(c, m);
  546. return 0;
  547. }
  548. /**
  549. * i2o_iop_activate - Bring controller up to HOLD
  550. * @c: controller
  551. *
  552. * This function brings an I2O controller into HOLD state. The adapter
  553. * is reset if necessary and then the queues and resource table are read.
  554. *
  555. * Returns 0 on success or negative error code on failure.
  556. */
  557. static int i2o_iop_activate(struct i2o_controller *c)
  558. {
  559. struct pci_dev *i960 = NULL;
  560. i2o_status_block *sb = c->status_block.virt;
  561. int rc;
  562. if (c->promise) {
  563. /* Beat up the hardware first of all */
  564. i960 =
  565. pci_find_slot(c->pdev->bus->number,
  566. PCI_DEVFN(PCI_SLOT(c->pdev->devfn), 0));
  567. if (i960)
  568. pci_write_config_word(i960, 0x42, 0);
  569. /* Follow this sequence precisely or the controller
  570. ceases to perform useful functions until reboot */
  571. if ((rc = i2o_iop_send_nop(c)))
  572. return rc;
  573. if ((rc = i2o_iop_reset(c)))
  574. return rc;
  575. }
  576. /* In INIT state, Wait Inbound Q to initialize (in i2o_status_get) */
  577. /* In READY state, Get status */
  578. rc = i2o_status_get(c);
  579. if (rc) {
  580. printk(KERN_INFO "%s: Unable to obtain status, "
  581. "attempting a reset.\n", c->name);
  582. if (i2o_iop_reset(c))
  583. return rc;
  584. }
  585. if (sb->i2o_version > I2OVER15) {
  586. printk(KERN_ERR "%s: Not running version 1.5 of the I2O "
  587. "Specification.\n", c->name);
  588. return -ENODEV;
  589. }
  590. switch (sb->iop_state) {
  591. case ADAPTER_STATE_FAULTED:
  592. printk(KERN_CRIT "%s: hardware fault\n", c->name);
  593. return -ENODEV;
  594. case ADAPTER_STATE_READY:
  595. case ADAPTER_STATE_OPERATIONAL:
  596. case ADAPTER_STATE_HOLD:
  597. case ADAPTER_STATE_FAILED:
  598. pr_debug("%s: already running, trying to reset...\n", c->name);
  599. if (i2o_iop_reset(c))
  600. return -ENODEV;
  601. }
  602. rc = i2o_iop_init_outbound_queue(c);
  603. if (rc)
  604. return rc;
  605. if (c->promise) {
  606. if ((rc = i2o_iop_send_nop(c)))
  607. return rc;
  608. if ((rc = i2o_status_get(c)))
  609. return rc;
  610. if (i960)
  611. pci_write_config_word(i960, 0x42, 0x3FF);
  612. }
  613. /* In HOLD state */
  614. rc = i2o_hrt_get(c);
  615. return rc;
  616. };
  617. /**
  618. * i2o_iop_systab_set - Set the I2O System Table of the specified IOP
  619. * @c: I2O controller to which the system table should be send
  620. *
  621. * Before the systab could be set i2o_systab_build() must be called.
  622. *
  623. * Returns 0 on success or negative error code on failure.
  624. */
  625. static int i2o_iop_systab_set(struct i2o_controller *c)
  626. {
  627. struct i2o_message __iomem *msg;
  628. u32 m;
  629. i2o_status_block *sb = c->status_block.virt;
  630. struct device *dev = &c->pdev->dev;
  631. struct resource *root;
  632. int rc;
  633. if (sb->current_mem_size < sb->desired_mem_size) {
  634. struct resource *res = &c->mem_resource;
  635. res->name = c->pdev->bus->name;
  636. res->flags = IORESOURCE_MEM;
  637. res->start = 0;
  638. res->end = 0;
  639. printk(KERN_INFO "%s: requires private memory resources.\n",
  640. c->name);
  641. root = pci_find_parent_resource(c->pdev, res);
  642. if (root == NULL)
  643. printk(KERN_WARNING "%s: Can't find parent resource!\n",
  644. c->name);
  645. if (root && allocate_resource(root, res, sb->desired_mem_size, sb->desired_mem_size, sb->desired_mem_size, 1 << 20, /* Unspecified, so use 1Mb and play safe */
  646. NULL, NULL) >= 0) {
  647. c->mem_alloc = 1;
  648. sb->current_mem_size = 1 + res->end - res->start;
  649. sb->current_mem_base = res->start;
  650. printk(KERN_INFO "%s: allocated %ld bytes of PCI memory"
  651. " at 0x%08lX.\n", c->name,
  652. 1 + res->end - res->start, res->start);
  653. }
  654. }
  655. if (sb->current_io_size < sb->desired_io_size) {
  656. struct resource *res = &c->io_resource;
  657. res->name = c->pdev->bus->name;
  658. res->flags = IORESOURCE_IO;
  659. res->start = 0;
  660. res->end = 0;
  661. printk(KERN_INFO "%s: requires private memory resources.\n",
  662. c->name);
  663. root = pci_find_parent_resource(c->pdev, res);
  664. if (root == NULL)
  665. printk(KERN_WARNING "%s: Can't find parent resource!\n",
  666. c->name);
  667. if (root && allocate_resource(root, res, sb->desired_io_size, sb->desired_io_size, sb->desired_io_size, 1 << 20, /* Unspecified, so use 1Mb and play safe */
  668. NULL, NULL) >= 0) {
  669. c->io_alloc = 1;
  670. sb->current_io_size = 1 + res->end - res->start;
  671. sb->current_mem_base = res->start;
  672. printk(KERN_INFO "%s: allocated %ld bytes of PCI I/O at"
  673. " 0x%08lX.\n", c->name,
  674. 1 + res->end - res->start, res->start);
  675. }
  676. }
  677. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  678. if (m == I2O_QUEUE_EMPTY)
  679. return -ETIMEDOUT;
  680. i2o_systab.phys = dma_map_single(dev, i2o_systab.virt, i2o_systab.len,
  681. PCI_DMA_TODEVICE);
  682. if (!i2o_systab.phys) {
  683. i2o_msg_nop(c, m);
  684. return -ENOMEM;
  685. }
  686. writel(I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6, &msg->u.head[0]);
  687. writel(I2O_CMD_SYS_TAB_SET << 24 | HOST_TID << 12 | ADAPTER_TID,
  688. &msg->u.head[1]);
  689. /*
  690. * Provide three SGL-elements:
  691. * System table (SysTab), Private memory space declaration and
  692. * Private i/o space declaration
  693. *
  694. * FIXME: is this still true?
  695. * Nasty one here. We can't use dma_alloc_coherent to send the
  696. * same table to everyone. We have to go remap it for them all
  697. */
  698. writel(c->unit + 2, &msg->body[0]);
  699. writel(0, &msg->body[1]);
  700. writel(0x54000000 | i2o_systab.len, &msg->body[2]);
  701. writel(i2o_systab.phys, &msg->body[3]);
  702. writel(0x54000000 | sb->current_mem_size, &msg->body[4]);
  703. writel(sb->current_mem_base, &msg->body[5]);
  704. writel(0xd4000000 | sb->current_io_size, &msg->body[6]);
  705. writel(sb->current_io_base, &msg->body[6]);
  706. rc = i2o_msg_post_wait(c, m, 120);
  707. dma_unmap_single(dev, i2o_systab.phys, i2o_systab.len,
  708. PCI_DMA_TODEVICE);
  709. if (rc < 0)
  710. printk(KERN_ERR "%s: Unable to set SysTab (status=%#x).\n",
  711. c->name, -rc);
  712. else
  713. pr_debug("%s: SysTab set.\n", c->name);
  714. i2o_status_get(c); // Entered READY state
  715. return rc;
  716. }
  717. /**
  718. * i2o_iop_online - Bring a controller online into OPERATIONAL state.
  719. * @c: I2O controller
  720. *
  721. * Send the system table and enable the I2O controller.
  722. *
  723. * Returns 0 on success or negativer error code on failure.
  724. */
  725. static int i2o_iop_online(struct i2o_controller *c)
  726. {
  727. int rc;
  728. rc = i2o_iop_systab_set(c);
  729. if (rc)
  730. return rc;
  731. /* In READY state */
  732. pr_debug("%s: Attempting to enable...\n", c->name);
  733. rc = i2o_iop_enable(c);
  734. if (rc)
  735. return rc;
  736. return 0;
  737. };
  738. /**
  739. * i2o_iop_remove - Remove the I2O controller from the I2O core
  740. * @c: I2O controller
  741. *
  742. * Remove the I2O controller from the I2O core. If devices are attached to
  743. * the controller remove these also and finally reset the controller.
  744. */
  745. void i2o_iop_remove(struct i2o_controller *c)
  746. {
  747. struct i2o_device *dev, *tmp;
  748. pr_debug("%s: deleting controller\n", c->name);
  749. i2o_driver_notify_controller_remove_all(c);
  750. list_del(&c->list);
  751. list_for_each_entry_safe(dev, tmp, &c->devices, list)
  752. i2o_device_remove(dev);
  753. /* Ask the IOP to switch to RESET state */
  754. i2o_iop_reset(c);
  755. }
  756. /**
  757. * i2o_systab_build - Build system table
  758. *
  759. * The system table contains information about all the IOPs in the system
  760. * (duh) and is used by the Executives on the IOPs to establish peer2peer
  761. * connections. We're not supporting peer2peer at the moment, but this
  762. * will be needed down the road for things like lan2lan forwarding.
  763. *
  764. * Returns 0 on success or negative error code on failure.
  765. */
  766. static int i2o_systab_build(void)
  767. {
  768. struct i2o_controller *c, *tmp;
  769. int num_controllers = 0;
  770. u32 change_ind = 0;
  771. int count = 0;
  772. struct i2o_sys_tbl *systab = i2o_systab.virt;
  773. list_for_each_entry_safe(c, tmp, &i2o_controllers, list)
  774. num_controllers++;
  775. if (systab) {
  776. change_ind = systab->change_ind;
  777. kfree(i2o_systab.virt);
  778. }
  779. /* Header + IOPs */
  780. i2o_systab.len = sizeof(struct i2o_sys_tbl) + num_controllers *
  781. sizeof(struct i2o_sys_tbl_entry);
  782. systab = i2o_systab.virt = kmalloc(i2o_systab.len, GFP_KERNEL);
  783. if (!systab) {
  784. printk(KERN_ERR "i2o: unable to allocate memory for System "
  785. "Table\n");
  786. return -ENOMEM;
  787. }
  788. memset(systab, 0, i2o_systab.len);
  789. systab->version = I2OVERSION;
  790. systab->change_ind = change_ind + 1;
  791. list_for_each_entry_safe(c, tmp, &i2o_controllers, list) {
  792. i2o_status_block *sb;
  793. if (count >= num_controllers) {
  794. printk(KERN_ERR "i2o: controller added while building "
  795. "system table\n");
  796. break;
  797. }
  798. sb = c->status_block.virt;
  799. /*
  800. * Get updated IOP state so we have the latest information
  801. *
  802. * We should delete the controller at this point if it
  803. * doesn't respond since if it's not on the system table
  804. * it is techninically not part of the I2O subsystem...
  805. */
  806. if (unlikely(i2o_status_get(c))) {
  807. printk(KERN_ERR "%s: Deleting b/c could not get status"
  808. " while attempting to build system table\n",
  809. c->name);
  810. i2o_iop_remove(c);
  811. continue; // try the next one
  812. }
  813. systab->iops[count].org_id = sb->org_id;
  814. systab->iops[count].iop_id = c->unit + 2;
  815. systab->iops[count].seg_num = 0;
  816. systab->iops[count].i2o_version = sb->i2o_version;
  817. systab->iops[count].iop_state = sb->iop_state;
  818. systab->iops[count].msg_type = sb->msg_type;
  819. systab->iops[count].frame_size = sb->inbound_frame_size;
  820. systab->iops[count].last_changed = change_ind;
  821. systab->iops[count].iop_capabilities = sb->iop_capabilities;
  822. systab->iops[count].inbound_low = i2o_ptr_low(c->post_port);
  823. systab->iops[count].inbound_high = i2o_ptr_high(c->post_port);
  824. count++;
  825. }
  826. systab->num_entries = count;
  827. return 0;
  828. };
  829. /**
  830. * i2o_parse_hrt - Parse the hardware resource table.
  831. * @c: I2O controller
  832. *
  833. * We don't do anything with it except dumping it (in debug mode).
  834. *
  835. * Returns 0.
  836. */
  837. static int i2o_parse_hrt(struct i2o_controller *c)
  838. {
  839. i2o_dump_hrt(c);
  840. return 0;
  841. };
  842. /**
  843. * i2o_status_get - Get the status block from the I2O controller
  844. * @c: I2O controller
  845. *
  846. * Issue a status query on the controller. This updates the attached
  847. * status block. The status block could then be accessed through
  848. * c->status_block.
  849. *
  850. * Returns 0 on sucess or negative error code on failure.
  851. */
  852. int i2o_status_get(struct i2o_controller *c)
  853. {
  854. struct i2o_message __iomem *msg;
  855. u32 m;
  856. u8 *status_block;
  857. unsigned long timeout;
  858. status_block = (u8 *) c->status_block.virt;
  859. memset(status_block, 0, sizeof(i2o_status_block));
  860. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  861. if (m == I2O_QUEUE_EMPTY)
  862. return -ETIMEDOUT;
  863. writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  864. writel(I2O_CMD_STATUS_GET << 24 | HOST_TID << 12 | ADAPTER_TID,
  865. &msg->u.head[1]);
  866. writel(i2o_exec_driver.context, &msg->u.s.icntxt);
  867. writel(0, &msg->u.s.tcntxt); // FIXME: use resonable transaction context
  868. writel(0, &msg->body[0]);
  869. writel(0, &msg->body[1]);
  870. writel(i2o_ptr_low((void *)c->status_block.phys), &msg->body[2]);
  871. writel(i2o_ptr_high((void *)c->status_block.phys), &msg->body[3]);
  872. writel(sizeof(i2o_status_block), &msg->body[4]); /* always 88 bytes */
  873. i2o_msg_post(c, m);
  874. /* Wait for a reply */
  875. timeout = jiffies + I2O_TIMEOUT_STATUS_GET * HZ;
  876. while (status_block[87] != 0xFF) {
  877. if (time_after(jiffies, timeout)) {
  878. printk(KERN_ERR "%s: Get status timeout.\n", c->name);
  879. return -ETIMEDOUT;
  880. }
  881. set_current_state(TASK_UNINTERRUPTIBLE);
  882. schedule_timeout(1);
  883. rmb();
  884. }
  885. #ifdef DEBUG
  886. i2o_debug_state(c);
  887. #endif
  888. return 0;
  889. }
  890. /*
  891. * i2o_hrt_get - Get the Hardware Resource Table from the I2O controller
  892. * @c: I2O controller from which the HRT should be fetched
  893. *
  894. * The HRT contains information about possible hidden devices but is
  895. * mostly useless to us.
  896. *
  897. * Returns 0 on success or negativer error code on failure.
  898. */
  899. static int i2o_hrt_get(struct i2o_controller *c)
  900. {
  901. int rc;
  902. int i;
  903. i2o_hrt *hrt = c->hrt.virt;
  904. u32 size = sizeof(i2o_hrt);
  905. struct device *dev = &c->pdev->dev;
  906. for (i = 0; i < I2O_HRT_GET_TRIES; i++) {
  907. struct i2o_message __iomem *msg;
  908. u32 m;
  909. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  910. if (m == I2O_QUEUE_EMPTY)
  911. return -ETIMEDOUT;
  912. writel(SIX_WORD_MSG_SIZE | SGL_OFFSET_4, &msg->u.head[0]);
  913. writel(I2O_CMD_HRT_GET << 24 | HOST_TID << 12 | ADAPTER_TID,
  914. &msg->u.head[1]);
  915. writel(0xd0000000 | c->hrt.len, &msg->body[0]);
  916. writel(c->hrt.phys, &msg->body[1]);
  917. rc = i2o_msg_post_wait_mem(c, m, 20, &c->hrt);
  918. if (rc < 0) {
  919. printk(KERN_ERR "%s: Unable to get HRT (status=%#x)\n",
  920. c->name, -rc);
  921. return rc;
  922. }
  923. size = hrt->num_entries * hrt->entry_len << 2;
  924. if (size > c->hrt.len) {
  925. if (i2o_dma_realloc(dev, &c->hrt, size, GFP_KERNEL))
  926. return -ENOMEM;
  927. else
  928. hrt = c->hrt.virt;
  929. } else
  930. return i2o_parse_hrt(c);
  931. }
  932. printk(KERN_ERR "%s: Unable to get HRT after %d tries, giving up\n",
  933. c->name, I2O_HRT_GET_TRIES);
  934. return -EBUSY;
  935. }
  936. /**
  937. * i2o_iop_alloc - Allocate and initialize a i2o_controller struct
  938. *
  939. * Allocate the necessary memory for a i2o_controller struct and
  940. * initialize the lists.
  941. *
  942. * Returns a pointer to the I2O controller or a negative error code on
  943. * failure.
  944. */
  945. struct i2o_controller *i2o_iop_alloc(void)
  946. {
  947. static int unit = 0; /* 0 and 1 are NULL IOP and Local Host */
  948. struct i2o_controller *c;
  949. c = kmalloc(sizeof(*c), GFP_KERNEL);
  950. if (!c) {
  951. printk(KERN_ERR "i2o: Insufficient memory to allocate a I2O "
  952. "controller.\n");
  953. return ERR_PTR(-ENOMEM);
  954. }
  955. memset(c, 0, sizeof(*c));
  956. INIT_LIST_HEAD(&c->devices);
  957. spin_lock_init(&c->lock);
  958. init_MUTEX(&c->lct_lock);
  959. c->unit = unit++;
  960. sprintf(c->name, "iop%d", c->unit);
  961. #if BITS_PER_LONG == 64
  962. spin_lock_init(&c->context_list_lock);
  963. atomic_set(&c->context_list_counter, 0);
  964. INIT_LIST_HEAD(&c->context_list);
  965. #endif
  966. return c;
  967. };
  968. /**
  969. * i2o_iop_free - Free the i2o_controller struct
  970. * @c: I2O controller to free
  971. */
  972. void i2o_iop_free(struct i2o_controller *c)
  973. {
  974. kfree(c);
  975. };
  976. /**
  977. * i2o_iop_add - Initialize the I2O controller and add him to the I2O core
  978. * @c: controller
  979. *
  980. * Initialize the I2O controller and if no error occurs add him to the I2O
  981. * core.
  982. *
  983. * Returns 0 on success or negative error code on failure.
  984. */
  985. int i2o_iop_add(struct i2o_controller *c)
  986. {
  987. int rc;
  988. printk(KERN_INFO "%s: Activating I2O controller...\n", c->name);
  989. printk(KERN_INFO "%s: This may take a few minutes if there are many "
  990. "devices\n", c->name);
  991. if ((rc = i2o_iop_activate(c))) {
  992. printk(KERN_ERR "%s: could not activate controller\n",
  993. c->name);
  994. i2o_iop_reset(c);
  995. return rc;
  996. }
  997. pr_debug("%s: building sys table...\n", c->name);
  998. if ((rc = i2o_systab_build())) {
  999. i2o_iop_reset(c);
  1000. return rc;
  1001. }
  1002. pr_debug("%s: online controller...\n", c->name);
  1003. if ((rc = i2o_iop_online(c))) {
  1004. i2o_iop_reset(c);
  1005. return rc;
  1006. }
  1007. pr_debug("%s: getting LCT...\n", c->name);
  1008. if ((rc = i2o_exec_lct_get(c))) {
  1009. i2o_iop_reset(c);
  1010. return rc;
  1011. }
  1012. list_add(&c->list, &i2o_controllers);
  1013. i2o_driver_notify_controller_add_all(c);
  1014. printk(KERN_INFO "%s: Controller added\n", c->name);
  1015. return 0;
  1016. };
  1017. /**
  1018. * i2o_event_register - Turn on/off event notification for a I2O device
  1019. * @dev: I2O device which should receive the event registration request
  1020. * @drv: driver which want to get notified
  1021. * @tcntxt: transaction context to use with this notifier
  1022. * @evt_mask: mask of events
  1023. *
  1024. * Create and posts an event registration message to the task. No reply
  1025. * is waited for, or expected. If you do not want further notifications,
  1026. * call the i2o_event_register again with a evt_mask of 0.
  1027. *
  1028. * Returns 0 on success or -ETIMEDOUT if no message could be fetched for
  1029. * sending the request.
  1030. */
  1031. int i2o_event_register(struct i2o_device *dev, struct i2o_driver *drv,
  1032. int tcntxt, u32 evt_mask)
  1033. {
  1034. struct i2o_controller *c = dev->iop;
  1035. struct i2o_message __iomem *msg;
  1036. u32 m;
  1037. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  1038. if (m == I2O_QUEUE_EMPTY)
  1039. return -ETIMEDOUT;
  1040. writel(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  1041. writel(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | dev->lct_data.
  1042. tid, &msg->u.head[1]);
  1043. writel(drv->context, &msg->u.s.icntxt);
  1044. writel(tcntxt, &msg->u.s.tcntxt);
  1045. writel(evt_mask, &msg->body[0]);
  1046. i2o_msg_post(c, m);
  1047. return 0;
  1048. };
  1049. /**
  1050. * i2o_iop_init - I2O main initialization function
  1051. *
  1052. * Initialize the I2O drivers (OSM) functions, register the Executive OSM,
  1053. * initialize the I2O PCI part and finally initialize I2O device stuff.
  1054. *
  1055. * Returns 0 on success or negative error code on failure.
  1056. */
  1057. static int __init i2o_iop_init(void)
  1058. {
  1059. int rc = 0;
  1060. printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
  1061. rc = i2o_device_init();
  1062. if (rc)
  1063. goto exit;
  1064. rc = i2o_driver_init();
  1065. if (rc)
  1066. goto device_exit;
  1067. rc = i2o_exec_init();
  1068. if (rc)
  1069. goto driver_exit;
  1070. rc = i2o_pci_init();
  1071. if (rc < 0)
  1072. goto exec_exit;
  1073. return 0;
  1074. exec_exit:
  1075. i2o_exec_exit();
  1076. driver_exit:
  1077. i2o_driver_exit();
  1078. device_exit:
  1079. i2o_device_exit();
  1080. exit:
  1081. return rc;
  1082. }
  1083. /**
  1084. * i2o_iop_exit - I2O main exit function
  1085. *
  1086. * Removes I2O controllers from PCI subsystem and shut down OSMs.
  1087. */
  1088. static void __exit i2o_iop_exit(void)
  1089. {
  1090. i2o_pci_exit();
  1091. i2o_exec_exit();
  1092. i2o_driver_exit();
  1093. i2o_device_exit();
  1094. };
  1095. module_init(i2o_iop_init);
  1096. module_exit(i2o_iop_exit);
  1097. MODULE_AUTHOR("Red Hat Software");
  1098. MODULE_LICENSE("GPL");
  1099. MODULE_DESCRIPTION(OSM_DESCRIPTION);
  1100. MODULE_VERSION(OSM_VERSION);
  1101. #if BITS_PER_LONG == 64
  1102. EXPORT_SYMBOL(i2o_cntxt_list_add);
  1103. EXPORT_SYMBOL(i2o_cntxt_list_get);
  1104. EXPORT_SYMBOL(i2o_cntxt_list_remove);
  1105. EXPORT_SYMBOL(i2o_cntxt_list_get_ptr);
  1106. #endif
  1107. EXPORT_SYMBOL(i2o_msg_get_wait);
  1108. EXPORT_SYMBOL(i2o_msg_nop);
  1109. EXPORT_SYMBOL(i2o_find_iop);
  1110. EXPORT_SYMBOL(i2o_iop_find_device);
  1111. EXPORT_SYMBOL(i2o_event_register);
  1112. EXPORT_SYMBOL(i2o_status_get);
  1113. EXPORT_SYMBOL(i2o_controllers);