iop.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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 = i2o_msg_in_to_virt(c, 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. return rc;
  385. }
  386. /**
  387. * i2o_iop_reset - reset an I2O controller
  388. * @c: controller to reset
  389. *
  390. * Reset the IOP into INIT state and wait until IOP gets into RESET state.
  391. * Terminate all external operations, clear IOP's inbound and outbound
  392. * queues, terminate all DDMs, and reload the IOP's operating environment
  393. * and all local DDMs. The IOP rebuilds its LCT.
  394. */
  395. static int i2o_iop_reset(struct i2o_controller *c)
  396. {
  397. u8 *status = c->status.virt;
  398. struct i2o_message __iomem *msg;
  399. u32 m;
  400. unsigned long timeout;
  401. i2o_status_block *sb = c->status_block.virt;
  402. int rc = 0;
  403. pr_debug("%s: Resetting controller\n", c->name);
  404. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  405. if (m == I2O_QUEUE_EMPTY)
  406. return -ETIMEDOUT;
  407. memset(status, 0, 8);
  408. /* Quiesce all IOPs first */
  409. i2o_iop_quiesce_all();
  410. writel(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  411. writel(I2O_CMD_ADAPTER_RESET << 24 | HOST_TID << 12 | ADAPTER_TID,
  412. &msg->u.head[1]);
  413. writel(i2o_exec_driver.context, &msg->u.s.icntxt);
  414. writel(0, &msg->u.s.tcntxt); //FIXME: use reasonable transaction context
  415. writel(0, &msg->body[0]);
  416. writel(0, &msg->body[1]);
  417. writel(i2o_ptr_low((void *)c->status.phys), &msg->body[2]);
  418. writel(i2o_ptr_high((void *)c->status.phys), &msg->body[3]);
  419. i2o_msg_post(c, m);
  420. /* Wait for a reply */
  421. timeout = jiffies + I2O_TIMEOUT_RESET * HZ;
  422. while (!*status) {
  423. if (time_after(jiffies, timeout)) {
  424. printk(KERN_ERR "%s: IOP reset timeout.\n", c->name);
  425. rc = -ETIMEDOUT;
  426. goto exit;
  427. }
  428. /* Promise bug */
  429. if (status[1] || status[4]) {
  430. *status = 0;
  431. break;
  432. }
  433. set_current_state(TASK_UNINTERRUPTIBLE);
  434. schedule_timeout(1);
  435. rmb();
  436. }
  437. if (*status == I2O_CMD_IN_PROGRESS) {
  438. /*
  439. * Once the reset is sent, the IOP goes into the INIT state
  440. * which is indeterminate. We need to wait until the IOP
  441. * has rebooted before we can let the system talk to
  442. * it. We read the inbound Free_List until a message is
  443. * available. If we can't read one in the given ammount of
  444. * time, we assume the IOP could not reboot properly.
  445. */
  446. pr_debug("%s: Reset in progress, waiting for reboot...\n",
  447. c->name);
  448. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET);
  449. while (m == I2O_QUEUE_EMPTY) {
  450. if (time_after(jiffies, timeout)) {
  451. printk(KERN_ERR "%s: IOP reset timeout.\n",
  452. c->name);
  453. rc = -ETIMEDOUT;
  454. goto exit;
  455. }
  456. set_current_state(TASK_UNINTERRUPTIBLE);
  457. schedule_timeout(1);
  458. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_RESET);
  459. }
  460. i2o_msg_nop(c, m);
  461. }
  462. /* from here all quiesce commands are safe */
  463. c->no_quiesce = 0;
  464. /* If IopReset was rejected or didn't perform reset, try IopClear */
  465. i2o_status_get(c);
  466. if (*status == I2O_CMD_REJECTED || sb->iop_state != ADAPTER_STATE_RESET) {
  467. printk(KERN_WARNING "%s: Reset rejected, trying to clear\n",
  468. c->name);
  469. i2o_iop_clear(c);
  470. } else
  471. pr_debug("%s: Reset completed.\n", c->name);
  472. exit:
  473. /* Enable all IOPs */
  474. i2o_iop_enable_all();
  475. return rc;
  476. };
  477. /**
  478. * i2o_iop_init_outbound_queue - setup the outbound message queue
  479. * @c: I2O controller
  480. *
  481. * Clear and (re)initialize IOP's outbound queue and post the message
  482. * frames to the IOP.
  483. *
  484. * Returns 0 on success or a negative errno code on failure.
  485. */
  486. static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
  487. {
  488. u8 *status = c->status.virt;
  489. u32 m;
  490. struct i2o_message __iomem *msg;
  491. ulong timeout;
  492. int i;
  493. pr_debug("%s: Initializing Outbound Queue...\n", c->name);
  494. memset(status, 0, 4);
  495. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  496. if (m == I2O_QUEUE_EMPTY)
  497. return -ETIMEDOUT;
  498. writel(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6, &msg->u.head[0]);
  499. writel(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 | ADAPTER_TID,
  500. &msg->u.head[1]);
  501. writel(i2o_exec_driver.context, &msg->u.s.icntxt);
  502. writel(0x00000000, &msg->u.s.tcntxt);
  503. writel(PAGE_SIZE, &msg->body[0]);
  504. writel(MSG_FRAME_SIZE << 16 | 0x80, &msg->body[1]); /* Outbound msg frame
  505. size in words and Initcode */
  506. writel(0xd0000004, &msg->body[2]);
  507. writel(i2o_ptr_low((void *)c->status.phys), &msg->body[3]);
  508. writel(i2o_ptr_high((void *)c->status.phys), &msg->body[4]);
  509. i2o_msg_post(c, m);
  510. timeout = jiffies + I2O_TIMEOUT_INIT_OUTBOUND_QUEUE * HZ;
  511. while (*status <= I2O_CMD_IN_PROGRESS) {
  512. if (time_after(jiffies, timeout)) {
  513. printk(KERN_WARNING "%s: Timeout Initializing\n",
  514. c->name);
  515. return -ETIMEDOUT;
  516. }
  517. set_current_state(TASK_UNINTERRUPTIBLE);
  518. schedule_timeout(1);
  519. rmb();
  520. }
  521. m = c->out_queue.phys;
  522. /* Post frames */
  523. for (i = 0; i < NMBR_MSG_FRAMES; i++) {
  524. i2o_flush_reply(c, m);
  525. udelay(1); /* Promise */
  526. m += MSG_FRAME_SIZE * 4;
  527. }
  528. return 0;
  529. }
  530. /**
  531. * i2o_iop_send_nop - send a core NOP message
  532. * @c: controller
  533. *
  534. * Send a no-operation message with a reply set to cause no
  535. * action either. Needed for bringing up promise controllers.
  536. */
  537. static int i2o_iop_send_nop(struct i2o_controller *c)
  538. {
  539. struct i2o_message __iomem *msg;
  540. u32 m = i2o_msg_get_wait(c, &msg, HZ);
  541. if (m == I2O_QUEUE_EMPTY)
  542. return -ETIMEDOUT;
  543. i2o_msg_nop(c, m);
  544. return 0;
  545. }
  546. /**
  547. * i2o_iop_activate - Bring controller up to HOLD
  548. * @c: controller
  549. *
  550. * This function brings an I2O controller into HOLD state. The adapter
  551. * is reset if necessary and then the queues and resource table are read.
  552. *
  553. * Returns 0 on success or negative error code on failure.
  554. */
  555. static int i2o_iop_activate(struct i2o_controller *c)
  556. {
  557. struct pci_dev *i960 = NULL;
  558. i2o_status_block *sb = c->status_block.virt;
  559. int rc;
  560. if (c->promise) {
  561. /* Beat up the hardware first of all */
  562. i960 =
  563. pci_find_slot(c->pdev->bus->number,
  564. PCI_DEVFN(PCI_SLOT(c->pdev->devfn), 0));
  565. if (i960)
  566. pci_write_config_word(i960, 0x42, 0);
  567. /* Follow this sequence precisely or the controller
  568. ceases to perform useful functions until reboot */
  569. if ((rc = i2o_iop_send_nop(c)))
  570. return rc;
  571. if ((rc = i2o_iop_reset(c)))
  572. return rc;
  573. }
  574. /* In INIT state, Wait Inbound Q to initialize (in i2o_status_get) */
  575. /* In READY state, Get status */
  576. rc = i2o_status_get(c);
  577. if (rc) {
  578. printk(KERN_INFO "%s: Unable to obtain status, "
  579. "attempting a reset.\n", c->name);
  580. if (i2o_iop_reset(c))
  581. return rc;
  582. }
  583. if (sb->i2o_version > I2OVER15) {
  584. printk(KERN_ERR "%s: Not running version 1.5 of the I2O "
  585. "Specification.\n", c->name);
  586. return -ENODEV;
  587. }
  588. switch (sb->iop_state) {
  589. case ADAPTER_STATE_FAULTED:
  590. printk(KERN_CRIT "%s: hardware fault\n", c->name);
  591. return -ENODEV;
  592. case ADAPTER_STATE_READY:
  593. case ADAPTER_STATE_OPERATIONAL:
  594. case ADAPTER_STATE_HOLD:
  595. case ADAPTER_STATE_FAILED:
  596. pr_debug("%s: already running, trying to reset...\n", c->name);
  597. if (i2o_iop_reset(c))
  598. return -ENODEV;
  599. }
  600. rc = i2o_iop_init_outbound_queue(c);
  601. if (rc)
  602. return rc;
  603. if (c->promise) {
  604. if ((rc = i2o_iop_send_nop(c)))
  605. return rc;
  606. if ((rc = i2o_status_get(c)))
  607. return rc;
  608. if (i960)
  609. pci_write_config_word(i960, 0x42, 0x3FF);
  610. }
  611. /* In HOLD state */
  612. rc = i2o_hrt_get(c);
  613. return rc;
  614. };
  615. /**
  616. * i2o_iop_systab_set - Set the I2O System Table of the specified IOP
  617. * @c: I2O controller to which the system table should be send
  618. *
  619. * Before the systab could be set i2o_systab_build() must be called.
  620. *
  621. * Returns 0 on success or negative error code on failure.
  622. */
  623. static int i2o_iop_systab_set(struct i2o_controller *c)
  624. {
  625. struct i2o_message __iomem *msg;
  626. u32 m;
  627. i2o_status_block *sb = c->status_block.virt;
  628. struct device *dev = &c->pdev->dev;
  629. struct resource *root;
  630. int rc;
  631. if (sb->current_mem_size < sb->desired_mem_size) {
  632. struct resource *res = &c->mem_resource;
  633. res->name = c->pdev->bus->name;
  634. res->flags = IORESOURCE_MEM;
  635. res->start = 0;
  636. res->end = 0;
  637. printk(KERN_INFO "%s: requires private memory resources.\n",
  638. c->name);
  639. root = pci_find_parent_resource(c->pdev, res);
  640. if (root == NULL)
  641. printk(KERN_WARNING "%s: Can't find parent resource!\n",
  642. c->name);
  643. 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 */
  644. NULL, NULL) >= 0) {
  645. c->mem_alloc = 1;
  646. sb->current_mem_size = 1 + res->end - res->start;
  647. sb->current_mem_base = res->start;
  648. printk(KERN_INFO "%s: allocated %ld bytes of PCI memory"
  649. " at 0x%08lX.\n", c->name,
  650. 1 + res->end - res->start, res->start);
  651. }
  652. }
  653. if (sb->current_io_size < sb->desired_io_size) {
  654. struct resource *res = &c->io_resource;
  655. res->name = c->pdev->bus->name;
  656. res->flags = IORESOURCE_IO;
  657. res->start = 0;
  658. res->end = 0;
  659. printk(KERN_INFO "%s: requires private memory resources.\n",
  660. c->name);
  661. root = pci_find_parent_resource(c->pdev, res);
  662. if (root == NULL)
  663. printk(KERN_WARNING "%s: Can't find parent resource!\n",
  664. c->name);
  665. 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 */
  666. NULL, NULL) >= 0) {
  667. c->io_alloc = 1;
  668. sb->current_io_size = 1 + res->end - res->start;
  669. sb->current_mem_base = res->start;
  670. printk(KERN_INFO "%s: allocated %ld bytes of PCI I/O at"
  671. " 0x%08lX.\n", c->name,
  672. 1 + res->end - res->start, res->start);
  673. }
  674. }
  675. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  676. if (m == I2O_QUEUE_EMPTY)
  677. return -ETIMEDOUT;
  678. i2o_systab.phys = dma_map_single(dev, i2o_systab.virt, i2o_systab.len,
  679. PCI_DMA_TODEVICE);
  680. if (!i2o_systab.phys) {
  681. i2o_msg_nop(c, m);
  682. return -ENOMEM;
  683. }
  684. writel(I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6, &msg->u.head[0]);
  685. writel(I2O_CMD_SYS_TAB_SET << 24 | HOST_TID << 12 | ADAPTER_TID,
  686. &msg->u.head[1]);
  687. /*
  688. * Provide three SGL-elements:
  689. * System table (SysTab), Private memory space declaration and
  690. * Private i/o space declaration
  691. *
  692. * FIXME: is this still true?
  693. * Nasty one here. We can't use dma_alloc_coherent to send the
  694. * same table to everyone. We have to go remap it for them all
  695. */
  696. writel(c->unit + 2, &msg->body[0]);
  697. writel(0, &msg->body[1]);
  698. writel(0x54000000 | i2o_systab.len, &msg->body[2]);
  699. writel(i2o_systab.phys, &msg->body[3]);
  700. writel(0x54000000 | sb->current_mem_size, &msg->body[4]);
  701. writel(sb->current_mem_base, &msg->body[5]);
  702. writel(0xd4000000 | sb->current_io_size, &msg->body[6]);
  703. writel(sb->current_io_base, &msg->body[6]);
  704. rc = i2o_msg_post_wait(c, m, 120);
  705. dma_unmap_single(dev, i2o_systab.phys, i2o_systab.len,
  706. PCI_DMA_TODEVICE);
  707. if (rc < 0)
  708. printk(KERN_ERR "%s: Unable to set SysTab (status=%#x).\n",
  709. c->name, -rc);
  710. else
  711. pr_debug("%s: SysTab set.\n", c->name);
  712. i2o_status_get(c); // Entered READY state
  713. return rc;
  714. }
  715. /**
  716. * i2o_iop_online - Bring a controller online into OPERATIONAL state.
  717. * @c: I2O controller
  718. *
  719. * Send the system table and enable the I2O controller.
  720. *
  721. * Returns 0 on success or negativer error code on failure.
  722. */
  723. static int i2o_iop_online(struct i2o_controller *c)
  724. {
  725. int rc;
  726. rc = i2o_iop_systab_set(c);
  727. if (rc)
  728. return rc;
  729. /* In READY state */
  730. pr_debug("%s: Attempting to enable...\n", c->name);
  731. rc = i2o_iop_enable(c);
  732. if (rc)
  733. return rc;
  734. return 0;
  735. };
  736. /**
  737. * i2o_iop_remove - Remove the I2O controller from the I2O core
  738. * @c: I2O controller
  739. *
  740. * Remove the I2O controller from the I2O core. If devices are attached to
  741. * the controller remove these also and finally reset the controller.
  742. */
  743. void i2o_iop_remove(struct i2o_controller *c)
  744. {
  745. struct i2o_device *dev, *tmp;
  746. pr_debug("%s: deleting controller\n", c->name);
  747. i2o_driver_notify_controller_remove_all(c);
  748. list_del(&c->list);
  749. list_for_each_entry_safe(dev, tmp, &c->devices, list)
  750. i2o_device_remove(dev);
  751. device_del(&c->device);
  752. /* Ask the IOP to switch to RESET state */
  753. i2o_iop_reset(c);
  754. put_device(&c->device);
  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 =
  823. i2o_dma_low(c->base.phys + I2O_IN_PORT);
  824. systab->iops[count].inbound_high =
  825. i2o_dma_high(c->base.phys + I2O_IN_PORT);
  826. count++;
  827. }
  828. systab->num_entries = count;
  829. return 0;
  830. };
  831. /**
  832. * i2o_parse_hrt - Parse the hardware resource table.
  833. * @c: I2O controller
  834. *
  835. * We don't do anything with it except dumping it (in debug mode).
  836. *
  837. * Returns 0.
  838. */
  839. static int i2o_parse_hrt(struct i2o_controller *c)
  840. {
  841. i2o_dump_hrt(c);
  842. return 0;
  843. };
  844. /**
  845. * i2o_status_get - Get the status block from the I2O controller
  846. * @c: I2O controller
  847. *
  848. * Issue a status query on the controller. This updates the attached
  849. * status block. The status block could then be accessed through
  850. * c->status_block.
  851. *
  852. * Returns 0 on sucess or negative error code on failure.
  853. */
  854. int i2o_status_get(struct i2o_controller *c)
  855. {
  856. struct i2o_message __iomem *msg;
  857. u32 m;
  858. u8 *status_block;
  859. unsigned long timeout;
  860. status_block = (u8 *) c->status_block.virt;
  861. memset(status_block, 0, sizeof(i2o_status_block));
  862. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  863. if (m == I2O_QUEUE_EMPTY)
  864. return -ETIMEDOUT;
  865. writel(NINE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  866. writel(I2O_CMD_STATUS_GET << 24 | HOST_TID << 12 | ADAPTER_TID,
  867. &msg->u.head[1]);
  868. writel(i2o_exec_driver.context, &msg->u.s.icntxt);
  869. writel(0, &msg->u.s.tcntxt); // FIXME: use resonable transaction context
  870. writel(0, &msg->body[0]);
  871. writel(0, &msg->body[1]);
  872. writel(i2o_ptr_low((void *)c->status_block.phys), &msg->body[2]);
  873. writel(i2o_ptr_high((void *)c->status_block.phys), &msg->body[3]);
  874. writel(sizeof(i2o_status_block), &msg->body[4]); /* always 88 bytes */
  875. i2o_msg_post(c, m);
  876. /* Wait for a reply */
  877. timeout = jiffies + I2O_TIMEOUT_STATUS_GET * HZ;
  878. while (status_block[87] != 0xFF) {
  879. if (time_after(jiffies, timeout)) {
  880. printk(KERN_ERR "%s: Get status timeout.\n", c->name);
  881. return -ETIMEDOUT;
  882. }
  883. set_current_state(TASK_UNINTERRUPTIBLE);
  884. schedule_timeout(1);
  885. rmb();
  886. }
  887. #ifdef DEBUG
  888. i2o_debug_state(c);
  889. #endif
  890. return 0;
  891. }
  892. /*
  893. * i2o_hrt_get - Get the Hardware Resource Table from the I2O controller
  894. * @c: I2O controller from which the HRT should be fetched
  895. *
  896. * The HRT contains information about possible hidden devices but is
  897. * mostly useless to us.
  898. *
  899. * Returns 0 on success or negativer error code on failure.
  900. */
  901. static int i2o_hrt_get(struct i2o_controller *c)
  902. {
  903. int rc;
  904. int i;
  905. i2o_hrt *hrt = c->hrt.virt;
  906. u32 size = sizeof(i2o_hrt);
  907. struct device *dev = &c->pdev->dev;
  908. for (i = 0; i < I2O_HRT_GET_TRIES; i++) {
  909. struct i2o_message __iomem *msg;
  910. u32 m;
  911. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  912. if (m == I2O_QUEUE_EMPTY)
  913. return -ETIMEDOUT;
  914. writel(SIX_WORD_MSG_SIZE | SGL_OFFSET_4, &msg->u.head[0]);
  915. writel(I2O_CMD_HRT_GET << 24 | HOST_TID << 12 | ADAPTER_TID,
  916. &msg->u.head[1]);
  917. writel(0xd0000000 | c->hrt.len, &msg->body[0]);
  918. writel(c->hrt.phys, &msg->body[1]);
  919. rc = i2o_msg_post_wait_mem(c, m, 20, &c->hrt);
  920. if (rc < 0) {
  921. printk(KERN_ERR "%s: Unable to get HRT (status=%#x)\n",
  922. c->name, -rc);
  923. return rc;
  924. }
  925. size = hrt->num_entries * hrt->entry_len << 2;
  926. if (size > c->hrt.len) {
  927. if (i2o_dma_realloc(dev, &c->hrt, size, GFP_KERNEL))
  928. return -ENOMEM;
  929. else
  930. hrt = c->hrt.virt;
  931. } else
  932. return i2o_parse_hrt(c);
  933. }
  934. printk(KERN_ERR "%s: Unable to get HRT after %d tries, giving up\n",
  935. c->name, I2O_HRT_GET_TRIES);
  936. return -EBUSY;
  937. }
  938. /**
  939. * i2o_iop_free - Free the i2o_controller struct
  940. * @c: I2O controller to free
  941. */
  942. void i2o_iop_free(struct i2o_controller *c)
  943. {
  944. kfree(c);
  945. };
  946. /**
  947. * i2o_iop_release - release the memory for a I2O controller
  948. * @dev: I2O controller which should be released
  949. *
  950. * Release the allocated memory. This function is called if refcount of
  951. * device reaches 0 automatically.
  952. */
  953. static void i2o_iop_release(struct device *dev)
  954. {
  955. struct i2o_controller *c = to_i2o_controller(dev);
  956. i2o_iop_free(c);
  957. };
  958. /**
  959. * i2o_iop_alloc - Allocate and initialize a i2o_controller struct
  960. *
  961. * Allocate the necessary memory for a i2o_controller struct and
  962. * initialize the lists.
  963. *
  964. * Returns a pointer to the I2O controller or a negative error code on
  965. * failure.
  966. */
  967. struct i2o_controller *i2o_iop_alloc(void)
  968. {
  969. static int unit = 0; /* 0 and 1 are NULL IOP and Local Host */
  970. struct i2o_controller *c;
  971. c = kmalloc(sizeof(*c), GFP_KERNEL);
  972. if (!c) {
  973. printk(KERN_ERR "i2o: Insufficient memory to allocate a I2O "
  974. "controller.\n");
  975. return ERR_PTR(-ENOMEM);
  976. }
  977. memset(c, 0, sizeof(*c));
  978. INIT_LIST_HEAD(&c->devices);
  979. spin_lock_init(&c->lock);
  980. init_MUTEX(&c->lct_lock);
  981. c->unit = unit++;
  982. sprintf(c->name, "iop%d", c->unit);
  983. device_initialize(&c->device);
  984. c->device.release = &i2o_iop_release;
  985. snprintf(c->device.bus_id, BUS_ID_SIZE, "iop%d", c->unit);
  986. #if BITS_PER_LONG == 64
  987. spin_lock_init(&c->context_list_lock);
  988. atomic_set(&c->context_list_counter, 0);
  989. INIT_LIST_HEAD(&c->context_list);
  990. #endif
  991. return c;
  992. };
  993. /**
  994. * i2o_iop_add - Initialize the I2O controller and add him to the I2O core
  995. * @c: controller
  996. *
  997. * Initialize the I2O controller and if no error occurs add him to the I2O
  998. * core.
  999. *
  1000. * Returns 0 on success or negative error code on failure.
  1001. */
  1002. int i2o_iop_add(struct i2o_controller *c)
  1003. {
  1004. int rc;
  1005. if((rc = device_add(&c->device))) {
  1006. printk(KERN_ERR "%s: could not register controller\n", c->name);
  1007. goto iop_reset;
  1008. }
  1009. printk(KERN_INFO "%s: Activating I2O controller...\n", c->name);
  1010. printk(KERN_INFO "%s: This may take a few minutes if there are many "
  1011. "devices\n", c->name);
  1012. if ((rc = i2o_iop_activate(c))) {
  1013. printk(KERN_ERR "%s: could not activate controller\n",
  1014. c->name);
  1015. goto iop_reset;
  1016. }
  1017. pr_debug("%s: building sys table...\n", c->name);
  1018. if ((rc = i2o_systab_build()))
  1019. goto iop_reset;
  1020. pr_debug("%s: online controller...\n", c->name);
  1021. if ((rc = i2o_iop_online(c)))
  1022. goto iop_reset;
  1023. pr_debug("%s: getting LCT...\n", c->name);
  1024. if ((rc = i2o_exec_lct_get(c)))
  1025. goto iop_reset;
  1026. list_add(&c->list, &i2o_controllers);
  1027. i2o_driver_notify_controller_add_all(c);
  1028. printk(KERN_INFO "%s: Controller added\n", c->name);
  1029. return 0;
  1030. iop_reset:
  1031. i2o_iop_reset(c);
  1032. return rc;
  1033. };
  1034. /**
  1035. * i2o_event_register - Turn on/off event notification for a I2O device
  1036. * @dev: I2O device which should receive the event registration request
  1037. * @drv: driver which want to get notified
  1038. * @tcntxt: transaction context to use with this notifier
  1039. * @evt_mask: mask of events
  1040. *
  1041. * Create and posts an event registration message to the task. No reply
  1042. * is waited for, or expected. If you do not want further notifications,
  1043. * call the i2o_event_register again with a evt_mask of 0.
  1044. *
  1045. * Returns 0 on success or -ETIMEDOUT if no message could be fetched for
  1046. * sending the request.
  1047. */
  1048. int i2o_event_register(struct i2o_device *dev, struct i2o_driver *drv,
  1049. int tcntxt, u32 evt_mask)
  1050. {
  1051. struct i2o_controller *c = dev->iop;
  1052. struct i2o_message __iomem *msg;
  1053. u32 m;
  1054. m = i2o_msg_get_wait(c, &msg, I2O_TIMEOUT_MESSAGE_GET);
  1055. if (m == I2O_QUEUE_EMPTY)
  1056. return -ETIMEDOUT;
  1057. writel(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  1058. writel(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | dev->lct_data.
  1059. tid, &msg->u.head[1]);
  1060. writel(drv->context, &msg->u.s.icntxt);
  1061. writel(tcntxt, &msg->u.s.tcntxt);
  1062. writel(evt_mask, &msg->body[0]);
  1063. i2o_msg_post(c, m);
  1064. return 0;
  1065. };
  1066. /**
  1067. * i2o_iop_init - I2O main initialization function
  1068. *
  1069. * Initialize the I2O drivers (OSM) functions, register the Executive OSM,
  1070. * initialize the I2O PCI part and finally initialize I2O device stuff.
  1071. *
  1072. * Returns 0 on success or negative error code on failure.
  1073. */
  1074. static int __init i2o_iop_init(void)
  1075. {
  1076. int rc = 0;
  1077. printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
  1078. rc = i2o_device_init();
  1079. if (rc)
  1080. goto exit;
  1081. rc = i2o_driver_init();
  1082. if (rc)
  1083. goto device_exit;
  1084. rc = i2o_exec_init();
  1085. if (rc)
  1086. goto driver_exit;
  1087. rc = i2o_pci_init();
  1088. if (rc < 0)
  1089. goto exec_exit;
  1090. return 0;
  1091. exec_exit:
  1092. i2o_exec_exit();
  1093. driver_exit:
  1094. i2o_driver_exit();
  1095. device_exit:
  1096. i2o_device_exit();
  1097. exit:
  1098. return rc;
  1099. }
  1100. /**
  1101. * i2o_iop_exit - I2O main exit function
  1102. *
  1103. * Removes I2O controllers from PCI subsystem and shut down OSMs.
  1104. */
  1105. static void __exit i2o_iop_exit(void)
  1106. {
  1107. i2o_pci_exit();
  1108. i2o_exec_exit();
  1109. i2o_driver_exit();
  1110. i2o_device_exit();
  1111. };
  1112. module_init(i2o_iop_init);
  1113. module_exit(i2o_iop_exit);
  1114. MODULE_AUTHOR("Red Hat Software");
  1115. MODULE_LICENSE("GPL");
  1116. MODULE_DESCRIPTION(OSM_DESCRIPTION);
  1117. MODULE_VERSION(OSM_VERSION);
  1118. #if BITS_PER_LONG == 64
  1119. EXPORT_SYMBOL(i2o_cntxt_list_add);
  1120. EXPORT_SYMBOL(i2o_cntxt_list_get);
  1121. EXPORT_SYMBOL(i2o_cntxt_list_remove);
  1122. EXPORT_SYMBOL(i2o_cntxt_list_get_ptr);
  1123. #endif
  1124. EXPORT_SYMBOL(i2o_msg_get_wait);
  1125. EXPORT_SYMBOL(i2o_msg_nop);
  1126. EXPORT_SYMBOL(i2o_find_iop);
  1127. EXPORT_SYMBOL(i2o_iop_find_device);
  1128. EXPORT_SYMBOL(i2o_event_register);
  1129. EXPORT_SYMBOL(i2o_status_get);
  1130. EXPORT_SYMBOL(i2o_controllers);