2 * Functions to handle I2O controllers and I2O message handling
4 * Copyright (C) 1999-2002 Red Hat Software
6 * Written by Alan Cox, Building Number Three Ltd
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.
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
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.
28 #include <linux/module.h>
29 #include <linux/i2o.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
34 #define OSM_NAME "i2o"
35 #define OSM_VERSION "1.325"
36 #define OSM_DESCRIPTION "I2O subsystem"
38 /* global I2O controller list */
39 LIST_HEAD(i2o_controllers);
42 * global I2O System Table. Contains information about all the IOPs in the
43 * system. Used to inform IOPs about each others existence.
45 static struct i2o_dma i2o_systab;
47 static int i2o_hrt_get(struct i2o_controller *c);
50 * i2o_msg_get_wait - obtain an I2O message from the IOP
52 * @msg: pointer to a I2O message pointer
53 * @wait: how long to wait until timeout
55 * This function waits up to wait seconds for a message slot to be
58 * On a success the message is returned and the pointer to the message is
59 * set in msg. The returned message is the physical page frame offset
60 * address from the read port (see the i2o spec). If no message is
61 * available returns I2O_QUEUE_EMPTY and msg is leaved untouched.
63 struct i2o_message *i2o_msg_get_wait(struct i2o_controller *c, int wait)
65 unsigned long timeout = jiffies + wait * HZ;
66 struct i2o_message *msg;
68 while (IS_ERR(msg = i2o_msg_get(c))) {
69 if (time_after(jiffies, timeout)) {
70 osm_debug("%s: Timeout waiting for message frame.\n",
72 return ERR_PTR(-ETIMEDOUT);
74 schedule_timeout_uninterruptible(1);
80 #if BITS_PER_LONG == 64
82 * i2o_cntxt_list_add - Append a pointer to context list and return a id
83 * @c: controller to which the context list belong
84 * @ptr: pointer to add to the context list
86 * Because the context field in I2O is only 32-bit large, on 64-bit the
87 * pointer is to large to fit in the context field. The i2o_cntxt_list
88 * functions therefore map pointers to context fields.
90 * Returns context id > 0 on success or 0 on failure.
92 u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
94 struct i2o_context_list_element *entry;
98 osm_err("%s: couldn't add NULL pointer to context list!\n",
101 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
103 osm_err("%s: Could not allocate memory for context list element"
109 entry->timestamp = jiffies;
110 INIT_LIST_HEAD(&entry->list);
112 spin_lock_irqsave(&c->context_list_lock, flags);
114 if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
115 atomic_inc(&c->context_list_counter);
117 entry->context = atomic_read(&c->context_list_counter);
119 list_add(&entry->list, &c->context_list);
121 spin_unlock_irqrestore(&c->context_list_lock, flags);
123 osm_debug("%s: Add context to list %p -> %d\n", c->name, ptr, context);
125 return entry->context;
129 * i2o_cntxt_list_remove - Remove a pointer from the context list
130 * @c: controller to which the context list belong
131 * @ptr: pointer which should be removed from the context list
133 * Removes a previously added pointer from the context list and returns
134 * the matching context id.
136 * Returns context id on succes or 0 on failure.
138 u32 i2o_cntxt_list_remove(struct i2o_controller * c, void *ptr)
140 struct i2o_context_list_element *entry;
144 spin_lock_irqsave(&c->context_list_lock, flags);
145 list_for_each_entry(entry, &c->context_list, list)
146 if (entry->ptr == ptr) {
147 list_del(&entry->list);
148 context = entry->context;
152 spin_unlock_irqrestore(&c->context_list_lock, flags);
155 osm_warn("%s: Could not remove nonexistent ptr %p\n", c->name,
158 osm_debug("%s: remove ptr from context list %d -> %p\n", c->name,
165 * i2o_cntxt_list_get - Get a pointer from the context list and remove it
166 * @c: controller to which the context list belong
167 * @context: context id to which the pointer belong
169 * Returns pointer to the matching context id on success or NULL on
172 void *i2o_cntxt_list_get(struct i2o_controller *c, u32 context)
174 struct i2o_context_list_element *entry;
178 spin_lock_irqsave(&c->context_list_lock, flags);
179 list_for_each_entry(entry, &c->context_list, list)
180 if (entry->context == context) {
181 list_del(&entry->list);
186 spin_unlock_irqrestore(&c->context_list_lock, flags);
189 osm_warn("%s: context id %d not found\n", c->name, context);
191 osm_debug("%s: get ptr from context list %d -> %p\n", c->name, context,
198 * i2o_cntxt_list_get_ptr - Get a context id from the context list
199 * @c: controller to which the context list belong
200 * @ptr: pointer to which the context id should be fetched
202 * Returns context id which matches to the pointer on succes or 0 on
205 u32 i2o_cntxt_list_get_ptr(struct i2o_controller * c, void *ptr)
207 struct i2o_context_list_element *entry;
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;
217 spin_unlock_irqrestore(&c->context_list_lock, flags);
220 osm_warn("%s: Could not find nonexistent ptr %p\n", c->name,
223 osm_debug("%s: get context id from context list %p -> %d\n", c->name,
231 * i2o_iop_find - Find an I2O controller by id
232 * @unit: unit number of the I2O controller to search for
234 * Lookup the I2O controller on the controller list.
236 * Returns pointer to the I2O controller on success or NULL if not found.
238 struct i2o_controller *i2o_find_iop(int unit)
240 struct i2o_controller *c;
242 list_for_each_entry(c, &i2o_controllers, list) {
251 * i2o_iop_find_device - Find a I2O device on an I2O controller
252 * @c: I2O controller where the I2O device hangs on
253 * @tid: TID of the I2O device to search for
255 * Searches the devices of the I2O controller for a device with TID tid and
258 * Returns a pointer to the I2O device if found, otherwise NULL.
260 struct i2o_device *i2o_iop_find_device(struct i2o_controller *c, u16 tid)
262 struct i2o_device *dev;
264 list_for_each_entry(dev, &c->devices, list)
265 if (dev->lct_data.tid == tid)
272 * i2o_quiesce_controller - quiesce controller
275 * Quiesce an IOP. Causes IOP to make external operation quiescent
276 * (i2o 'READY' state). Internal operation of the IOP continues normally.
278 * Returns 0 on success or negative error code on failure.
280 static int i2o_iop_quiesce(struct i2o_controller *c)
282 struct i2o_message *msg;
283 i2o_status_block *sb = c->status_block.virt;
288 /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
289 if ((sb->iop_state != ADAPTER_STATE_READY) &&
290 (sb->iop_state != ADAPTER_STATE_OPERATIONAL))
293 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
297 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
299 cpu_to_le32(I2O_CMD_SYS_QUIESCE << 24 | HOST_TID << 12 |
302 /* Long timeout needed for quiesce if lots of devices */
303 if ((rc = i2o_msg_post_wait(c, msg, 240)))
304 osm_info("%s: Unable to quiesce (status=%#x).\n", c->name, -rc);
306 osm_debug("%s: Quiesced.\n", c->name);
308 i2o_status_get(c); // Entered READY state
314 * i2o_iop_enable - move controller from ready to OPERATIONAL
317 * Enable IOP. This allows the IOP to resume external operations and
318 * reverses the effect of a quiesce. Returns zero or an error code if
321 static int i2o_iop_enable(struct i2o_controller *c)
323 struct i2o_message *msg;
324 i2o_status_block *sb = c->status_block.virt;
329 /* Enable only allowed on READY state */
330 if (sb->iop_state != ADAPTER_STATE_READY)
333 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
337 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
339 cpu_to_le32(I2O_CMD_SYS_ENABLE << 24 | HOST_TID << 12 |
342 /* How long of a timeout do we need? */
343 if ((rc = i2o_msg_post_wait(c, msg, 240)))
344 osm_err("%s: Could not enable (status=%#x).\n", c->name, -rc);
346 osm_debug("%s: Enabled.\n", c->name);
348 i2o_status_get(c); // entered OPERATIONAL state
354 * i2o_iop_quiesce_all - Quiesce all I2O controllers on the system
356 * Quiesce all I2O controllers which are connected to the system.
358 static inline void i2o_iop_quiesce_all(void)
360 struct i2o_controller *c, *tmp;
362 list_for_each_entry_safe(c, tmp, &i2o_controllers, list) {
369 * i2o_iop_enable_all - Enables all controllers on the system
371 * Enables all I2O controllers which are connected to the system.
373 static inline void i2o_iop_enable_all(void)
375 struct i2o_controller *c, *tmp;
377 list_for_each_entry_safe(c, tmp, &i2o_controllers, list)
382 * i2o_clear_controller - Bring I2O controller into HOLD state
385 * Clear an IOP to HOLD state, ie. terminate external operations, clear all
386 * input queues and prepare for a system restart. IOP's internal operation
387 * continues normally and the outbound queue is alive. The IOP is not
388 * expected to rebuild its LCT.
390 * Returns 0 on success or negative error code on failure.
392 static int i2o_iop_clear(struct i2o_controller *c)
394 struct i2o_message *msg;
397 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
401 /* Quiesce all IOPs first */
402 i2o_iop_quiesce_all();
404 msg->u.head[0] = cpu_to_le32(FOUR_WORD_MSG_SIZE | SGL_OFFSET_0);
406 cpu_to_le32(I2O_CMD_ADAPTER_CLEAR << 24 | HOST_TID << 12 |
409 if ((rc = i2o_msg_post_wait(c, msg, 30)))
410 osm_info("%s: Unable to clear (status=%#x).\n", c->name, -rc);
412 osm_debug("%s: Cleared.\n", c->name);
414 /* Enable all IOPs */
415 i2o_iop_enable_all();
421 * i2o_iop_init_outbound_queue - setup the outbound message queue
424 * Clear and (re)initialize IOP's outbound queue and post the message
427 * Returns 0 on success or negative error code on failure.
429 static int i2o_iop_init_outbound_queue(struct i2o_controller *c)
432 volatile u8 *status = c->status.virt;
433 struct i2o_message *msg;
437 osm_debug("%s: Initializing Outbound Queue...\n", c->name);
439 memset(c->status.virt, 0, 4);
441 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
445 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6);
447 cpu_to_le32(I2O_CMD_OUTBOUND_INIT << 24 | HOST_TID << 12 |
449 msg->u.s.icntxt = cpu_to_le32(i2o_exec_driver.context);
450 msg->u.s.tcntxt = cpu_to_le32(0x00000000);
451 msg->body[0] = cpu_to_le32(PAGE_SIZE);
452 /* Outbound msg frame size in words and Initcode */
453 msg->body[1] = cpu_to_le32(I2O_OUTBOUND_MSG_FRAME_SIZE << 16 | 0x80);
454 msg->body[2] = cpu_to_le32(0xd0000004);
455 msg->body[3] = cpu_to_le32(i2o_dma_low(c->status.phys));
456 msg->body[4] = cpu_to_le32(i2o_dma_high(c->status.phys));
458 i2o_msg_post(c, msg);
460 timeout = jiffies + I2O_TIMEOUT_INIT_OUTBOUND_QUEUE * HZ;
461 while (*status <= I2O_CMD_IN_PROGRESS) {
462 if (time_after(jiffies, timeout)) {
463 osm_warn("%s: Timeout Initializing\n", c->name);
466 schedule_timeout_uninterruptible(1);
469 m = c->out_queue.phys;
472 for (i = 0; i < I2O_MAX_OUTBOUND_MSG_FRAMES; i++) {
473 i2o_flush_reply(c, m);
474 udelay(1); /* Promise */
475 m += I2O_OUTBOUND_MSG_FRAME_SIZE * sizeof(u32);
482 * i2o_iop_reset - reset an I2O controller
483 * @c: controller to reset
485 * Reset the IOP into INIT state and wait until IOP gets into RESET state.
486 * Terminate all external operations, clear IOP's inbound and outbound
487 * queues, terminate all DDMs, and reload the IOP's operating environment
488 * and all local DDMs. The IOP rebuilds its LCT.
490 static int i2o_iop_reset(struct i2o_controller *c)
492 volatile u8 *status = c->status.virt;
493 struct i2o_message *msg;
494 unsigned long timeout;
495 i2o_status_block *sb = c->status_block.virt;
498 osm_debug("%s: Resetting controller\n", c->name);
500 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
504 memset(c->status_block.virt, 0, 8);
506 /* Quiesce all IOPs first */
507 i2o_iop_quiesce_all();
509 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_0);
511 cpu_to_le32(I2O_CMD_ADAPTER_RESET << 24 | HOST_TID << 12 |
513 msg->u.s.icntxt = cpu_to_le32(i2o_exec_driver.context);
514 msg->u.s.tcntxt = cpu_to_le32(0x00000000);
515 msg->body[0] = cpu_to_le32(0x00000000);
516 msg->body[1] = cpu_to_le32(0x00000000);
517 msg->body[2] = cpu_to_le32(i2o_dma_low(c->status.phys));
518 msg->body[3] = cpu_to_le32(i2o_dma_high(c->status.phys));
520 i2o_msg_post(c, msg);
522 /* Wait for a reply */
523 timeout = jiffies + I2O_TIMEOUT_RESET * HZ;
525 if (time_after(jiffies, timeout))
528 schedule_timeout_uninterruptible(1);
532 case I2O_CMD_REJECTED:
533 osm_warn("%s: IOP reset rejected\n", c->name);
537 case I2O_CMD_IN_PROGRESS:
539 * Once the reset is sent, the IOP goes into the INIT state
540 * which is indeterminate. We need to wait until the IOP has
541 * rebooted before we can let the system talk to it. We read
542 * the inbound Free_List until a message is available. If we
543 * can't read one in the given ammount of time, we assume the
544 * IOP could not reboot properly.
546 osm_debug("%s: Reset in progress, waiting for reboot...\n",
549 while (IS_ERR(msg = i2o_msg_get_wait(c, I2O_TIMEOUT_RESET))) {
550 if (time_after(jiffies, timeout)) {
551 osm_err("%s: IOP reset timeout.\n", c->name);
555 schedule_timeout_uninterruptible(1);
559 /* from here all quiesce commands are safe */
562 /* verify if controller is in state RESET */
565 if (!c->promise && (sb->iop_state != ADAPTER_STATE_RESET))
566 osm_warn("%s: reset completed, but adapter not in RESET"
567 " state.\n", c->name);
569 osm_debug("%s: reset completed.\n", c->name);
574 osm_err("%s: IOP reset timeout.\n", c->name);
580 /* Enable all IOPs */
581 i2o_iop_enable_all();
587 * i2o_iop_activate - Bring controller up to HOLD
590 * This function brings an I2O controller into HOLD state. The adapter
591 * is reset if necessary and then the queues and resource table are read.
593 * Returns 0 on success or negative error code on failure.
595 static int i2o_iop_activate(struct i2o_controller *c)
597 i2o_status_block *sb = c->status_block.virt;
601 /* In INIT state, Wait Inbound Q to initialize (in i2o_status_get) */
602 /* In READY state, Get status */
604 rc = i2o_status_get(c);
606 osm_info("%s: Unable to obtain status, attempting a reset.\n",
608 rc = i2o_iop_reset(c);
613 if (sb->i2o_version > I2OVER15) {
614 osm_err("%s: Not running version 1.5 of the I2O Specification."
619 switch (sb->iop_state) {
620 case ADAPTER_STATE_FAULTED:
621 osm_err("%s: hardware fault\n", c->name);
624 case ADAPTER_STATE_READY:
625 case ADAPTER_STATE_OPERATIONAL:
626 case ADAPTER_STATE_HOLD:
627 case ADAPTER_STATE_FAILED:
628 osm_debug("%s: already running, trying to reset...\n", c->name);
629 rc = i2o_iop_reset(c);
635 state = sb->iop_state;
637 rc = i2o_iop_init_outbound_queue(c);
641 /* if adapter was not in RESET state clear now */
642 if (state != ADAPTER_STATE_RESET)
647 if (sb->iop_state != ADAPTER_STATE_HOLD) {
648 osm_err("%s: failed to bring IOP into HOLD state\n", c->name);
652 return i2o_hrt_get(c);
656 * i2o_iop_systab_set - Set the I2O System Table of the specified IOP
657 * @c: I2O controller to which the system table should be send
659 * Before the systab could be set i2o_systab_build() must be called.
661 * Returns 0 on success or negative error code on failure.
663 static int i2o_iop_systab_set(struct i2o_controller *c)
665 struct i2o_message *msg;
666 i2o_status_block *sb = c->status_block.virt;
667 struct device *dev = &c->pdev->dev;
668 struct resource *root;
671 if (sb->current_mem_size < sb->desired_mem_size) {
672 struct resource *res = &c->mem_resource;
673 res->name = c->pdev->bus->name;
674 res->flags = IORESOURCE_MEM;
677 osm_info("%s: requires private memory resources.\n", c->name);
678 root = pci_find_parent_resource(c->pdev, res);
680 osm_warn("%s: Can't find parent resource!\n", c->name);
681 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 */
684 sb->current_mem_size = 1 + res->end - res->start;
685 sb->current_mem_base = res->start;
686 osm_info("%s: allocated %ld bytes of PCI memory at "
687 "0x%08lX.\n", c->name,
688 1 + res->end - res->start, res->start);
692 if (sb->current_io_size < sb->desired_io_size) {
693 struct resource *res = &c->io_resource;
694 res->name = c->pdev->bus->name;
695 res->flags = IORESOURCE_IO;
698 osm_info("%s: requires private memory resources.\n", c->name);
699 root = pci_find_parent_resource(c->pdev, res);
701 osm_warn("%s: Can't find parent resource!\n", c->name);
702 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 */
705 sb->current_io_size = 1 + res->end - res->start;
706 sb->current_mem_base = res->start;
707 osm_info("%s: allocated %ld bytes of PCI I/O at 0x%08lX"
708 ".\n", c->name, 1 + res->end - res->start,
713 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
717 i2o_systab.phys = dma_map_single(dev, i2o_systab.virt, i2o_systab.len,
719 if (!i2o_systab.phys) {
724 msg->u.head[0] = cpu_to_le32(I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6);
726 cpu_to_le32(I2O_CMD_SYS_TAB_SET << 24 | HOST_TID << 12 |
730 * Provide three SGL-elements:
731 * System table (SysTab), Private memory space declaration and
732 * Private i/o space declaration
735 msg->body[0] = cpu_to_le32(c->unit + 2);
736 msg->body[1] = cpu_to_le32(0x00000000);
737 msg->body[2] = cpu_to_le32(0x54000000 | i2o_systab.len);
738 msg->body[3] = cpu_to_le32(i2o_systab.phys);
739 msg->body[4] = cpu_to_le32(0x54000000 | sb->current_mem_size);
740 msg->body[5] = cpu_to_le32(sb->current_mem_base);
741 msg->body[6] = cpu_to_le32(0xd4000000 | sb->current_io_size);
742 msg->body[6] = cpu_to_le32(sb->current_io_base);
744 rc = i2o_msg_post_wait(c, msg, 120);
746 dma_unmap_single(dev, i2o_systab.phys, i2o_systab.len,
750 osm_err("%s: Unable to set SysTab (status=%#x).\n", c->name,
753 osm_debug("%s: SysTab set.\n", c->name);
759 * i2o_iop_online - Bring a controller online into OPERATIONAL state.
762 * Send the system table and enable the I2O controller.
764 * Returns 0 on success or negative error code on failure.
766 static int i2o_iop_online(struct i2o_controller *c)
770 rc = i2o_iop_systab_set(c);
775 osm_debug("%s: Attempting to enable...\n", c->name);
776 rc = i2o_iop_enable(c);
784 * i2o_iop_remove - Remove the I2O controller from the I2O core
787 * Remove the I2O controller from the I2O core. If devices are attached to
788 * the controller remove these also and finally reset the controller.
790 void i2o_iop_remove(struct i2o_controller *c)
792 struct i2o_device *dev, *tmp;
794 osm_debug("%s: deleting controller\n", c->name);
796 i2o_driver_notify_controller_remove_all(c);
800 list_for_each_entry_safe(dev, tmp, &c->devices, list)
801 i2o_device_remove(dev);
803 device_del(&c->device);
805 /* Ask the IOP to switch to RESET state */
810 * i2o_systab_build - Build system table
812 * The system table contains information about all the IOPs in the system
813 * (duh) and is used by the Executives on the IOPs to establish peer2peer
814 * connections. We're not supporting peer2peer at the moment, but this
815 * will be needed down the road for things like lan2lan forwarding.
817 * Returns 0 on success or negative error code on failure.
819 static int i2o_systab_build(void)
821 struct i2o_controller *c, *tmp;
822 int num_controllers = 0;
825 struct i2o_sys_tbl *systab = i2o_systab.virt;
827 list_for_each_entry_safe(c, tmp, &i2o_controllers, list)
831 change_ind = systab->change_ind;
832 kfree(i2o_systab.virt);
836 i2o_systab.len = sizeof(struct i2o_sys_tbl) + num_controllers *
837 sizeof(struct i2o_sys_tbl_entry);
839 systab = i2o_systab.virt = kzalloc(i2o_systab.len, GFP_KERNEL);
841 osm_err("unable to allocate memory for System Table\n");
845 systab->version = I2OVERSION;
846 systab->change_ind = change_ind + 1;
848 list_for_each_entry_safe(c, tmp, &i2o_controllers, list) {
849 i2o_status_block *sb;
851 if (count >= num_controllers) {
852 osm_err("controller added while building system table"
857 sb = c->status_block.virt;
860 * Get updated IOP state so we have the latest information
862 * We should delete the controller at this point if it
863 * doesn't respond since if it's not on the system table
864 * it is techninically not part of the I2O subsystem...
866 if (unlikely(i2o_status_get(c))) {
867 osm_err("%s: Deleting b/c could not get status while "
868 "attempting to build system table\n", c->name);
870 continue; // try the next one
873 systab->iops[count].org_id = sb->org_id;
874 systab->iops[count].iop_id = c->unit + 2;
875 systab->iops[count].seg_num = 0;
876 systab->iops[count].i2o_version = sb->i2o_version;
877 systab->iops[count].iop_state = sb->iop_state;
878 systab->iops[count].msg_type = sb->msg_type;
879 systab->iops[count].frame_size = sb->inbound_frame_size;
880 systab->iops[count].last_changed = change_ind;
881 systab->iops[count].iop_capabilities = sb->iop_capabilities;
882 systab->iops[count].inbound_low =
883 i2o_dma_low(c->base.phys + I2O_IN_PORT);
884 systab->iops[count].inbound_high =
885 i2o_dma_high(c->base.phys + I2O_IN_PORT);
890 systab->num_entries = count;
896 * i2o_parse_hrt - Parse the hardware resource table.
899 * We don't do anything with it except dumping it (in debug mode).
903 static int i2o_parse_hrt(struct i2o_controller *c)
910 * i2o_status_get - Get the status block from the I2O controller
913 * Issue a status query on the controller. This updates the attached
914 * status block. The status block could then be accessed through
917 * Returns 0 on sucess or negative error code on failure.
919 int i2o_status_get(struct i2o_controller *c)
921 struct i2o_message *msg;
922 volatile u8 *status_block;
923 unsigned long timeout;
925 status_block = (u8 *) c->status_block.virt;
926 memset(c->status_block.virt, 0, sizeof(i2o_status_block));
928 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
932 msg->u.head[0] = cpu_to_le32(NINE_WORD_MSG_SIZE | SGL_OFFSET_0);
934 cpu_to_le32(I2O_CMD_STATUS_GET << 24 | HOST_TID << 12 |
936 msg->u.s.icntxt = cpu_to_le32(i2o_exec_driver.context);
937 msg->u.s.tcntxt = cpu_to_le32(0x00000000);
938 msg->body[0] = cpu_to_le32(0x00000000);
939 msg->body[1] = cpu_to_le32(0x00000000);
940 msg->body[2] = cpu_to_le32(i2o_dma_low(c->status_block.phys));
941 msg->body[3] = cpu_to_le32(i2o_dma_high(c->status_block.phys));
942 msg->body[4] = cpu_to_le32(sizeof(i2o_status_block)); /* always 88 bytes */
944 i2o_msg_post(c, msg);
946 /* Wait for a reply */
947 timeout = jiffies + I2O_TIMEOUT_STATUS_GET * HZ;
948 while (status_block[87] != 0xFF) {
949 if (time_after(jiffies, timeout)) {
950 osm_err("%s: Get status timeout.\n", c->name);
954 schedule_timeout_uninterruptible(1);
965 * i2o_hrt_get - Get the Hardware Resource Table from the I2O controller
966 * @c: I2O controller from which the HRT should be fetched
968 * The HRT contains information about possible hidden devices but is
969 * mostly useless to us.
971 * Returns 0 on success or negative error code on failure.
973 static int i2o_hrt_get(struct i2o_controller *c)
977 i2o_hrt *hrt = c->hrt.virt;
978 u32 size = sizeof(i2o_hrt);
979 struct device *dev = &c->pdev->dev;
981 for (i = 0; i < I2O_HRT_GET_TRIES; i++) {
982 struct i2o_message *msg;
984 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
988 msg->u.head[0] = cpu_to_le32(SIX_WORD_MSG_SIZE | SGL_OFFSET_4);
990 cpu_to_le32(I2O_CMD_HRT_GET << 24 | HOST_TID << 12 |
992 msg->body[0] = cpu_to_le32(0xd0000000 | c->hrt.len);
993 msg->body[1] = cpu_to_le32(c->hrt.phys);
995 rc = i2o_msg_post_wait_mem(c, msg, 20, &c->hrt);
998 osm_err("%s: Unable to get HRT (status=%#x)\n", c->name,
1003 size = hrt->num_entries * hrt->entry_len << 2;
1004 if (size > c->hrt.len) {
1005 if (i2o_dma_realloc(dev, &c->hrt, size, GFP_KERNEL))
1010 return i2o_parse_hrt(c);
1013 osm_err("%s: Unable to get HRT after %d tries, giving up\n", c->name,
1020 * i2o_iop_release - release the memory for a I2O controller
1021 * @dev: I2O controller which should be released
1023 * Release the allocated memory. This function is called if refcount of
1024 * device reaches 0 automatically.
1026 static void i2o_iop_release(struct device *dev)
1028 struct i2o_controller *c = to_i2o_controller(dev);
1034 * i2o_iop_alloc - Allocate and initialize a i2o_controller struct
1036 * Allocate the necessary memory for a i2o_controller struct and
1037 * initialize the lists and message mempool.
1039 * Returns a pointer to the I2O controller or a negative error code on
1042 struct i2o_controller *i2o_iop_alloc(void)
1044 static int unit = 0; /* 0 and 1 are NULL IOP and Local Host */
1045 struct i2o_controller *c;
1048 c = kzalloc(sizeof(*c), GFP_KERNEL);
1050 osm_err("i2o: Insufficient memory to allocate a I2O controller."
1052 return ERR_PTR(-ENOMEM);
1056 sprintf(c->name, "iop%d", c->unit);
1058 snprintf(poolname, sizeof(poolname), "i2o_%s_msg_inpool", c->name);
1060 (&c->in_msg, poolname, I2O_INBOUND_MSG_FRAME_SIZE * 4 + sizeof(u32),
1061 I2O_MSG_INPOOL_MIN)) {
1063 return ERR_PTR(-ENOMEM);
1066 INIT_LIST_HEAD(&c->devices);
1067 spin_lock_init(&c->lock);
1068 init_MUTEX(&c->lct_lock);
1070 device_initialize(&c->device);
1072 c->device.release = &i2o_iop_release;
1074 snprintf(c->device.bus_id, BUS_ID_SIZE, "iop%d", c->unit);
1076 #if BITS_PER_LONG == 64
1077 spin_lock_init(&c->context_list_lock);
1078 atomic_set(&c->context_list_counter, 0);
1079 INIT_LIST_HEAD(&c->context_list);
1086 * i2o_iop_add - Initialize the I2O controller and add him to the I2O core
1089 * Initialize the I2O controller and if no error occurs add him to the I2O
1092 * Returns 0 on success or negative error code on failure.
1094 int i2o_iop_add(struct i2o_controller *c)
1098 if ((rc = device_add(&c->device))) {
1099 osm_err("%s: could not add controller\n", c->name);
1103 osm_info("%s: Activating I2O controller...\n", c->name);
1104 osm_info("%s: This may take a few minutes if there are many devices\n",
1107 if ((rc = i2o_iop_activate(c))) {
1108 osm_err("%s: could not activate controller\n", c->name);
1112 osm_debug("%s: building sys table...\n", c->name);
1114 if ((rc = i2o_systab_build()))
1117 osm_debug("%s: online controller...\n", c->name);
1119 if ((rc = i2o_iop_online(c)))
1122 osm_debug("%s: getting LCT...\n", c->name);
1124 if ((rc = i2o_exec_lct_get(c)))
1127 list_add(&c->list, &i2o_controllers);
1129 i2o_driver_notify_controller_add_all(c);
1131 osm_info("%s: Controller added\n", c->name);
1136 device_del(&c->device);
1145 * i2o_event_register - Turn on/off event notification for a I2O device
1146 * @dev: I2O device which should receive the event registration request
1147 * @drv: driver which want to get notified
1148 * @tcntxt: transaction context to use with this notifier
1149 * @evt_mask: mask of events
1151 * Create and posts an event registration message to the task. No reply
1152 * is waited for, or expected. If you do not want further notifications,
1153 * call the i2o_event_register again with a evt_mask of 0.
1155 * Returns 0 on success or negative error code on failure.
1157 int i2o_event_register(struct i2o_device *dev, struct i2o_driver *drv,
1158 int tcntxt, u32 evt_mask)
1160 struct i2o_controller *c = dev->iop;
1161 struct i2o_message *msg;
1163 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
1165 return PTR_ERR(msg);
1167 msg->u.head[0] = cpu_to_le32(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0);
1169 cpu_to_le32(I2O_CMD_UTIL_EVT_REGISTER << 24 | HOST_TID << 12 | dev->
1171 msg->u.s.icntxt = cpu_to_le32(drv->context);
1172 msg->u.s.tcntxt = cpu_to_le32(tcntxt);
1173 msg->body[0] = cpu_to_le32(evt_mask);
1175 i2o_msg_post(c, msg);
1181 * i2o_iop_init - I2O main initialization function
1183 * Initialize the I2O drivers (OSM) functions, register the Executive OSM,
1184 * initialize the I2O PCI part and finally initialize I2O device stuff.
1186 * Returns 0 on success or negative error code on failure.
1188 static int __init i2o_iop_init(void)
1192 printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
1194 if ((rc = i2o_driver_init()))
1197 if ((rc = i2o_exec_init()))
1200 if ((rc = i2o_pci_init()))
1216 * i2o_iop_exit - I2O main exit function
1218 * Removes I2O controllers from PCI subsystem and shut down OSMs.
1220 static void __exit i2o_iop_exit(void)
1227 module_init(i2o_iop_init);
1228 module_exit(i2o_iop_exit);
1230 MODULE_AUTHOR("Red Hat Software");
1231 MODULE_LICENSE("GPL");
1232 MODULE_DESCRIPTION(OSM_DESCRIPTION);
1233 MODULE_VERSION(OSM_VERSION);
1235 #if BITS_PER_LONG == 64
1236 EXPORT_SYMBOL(i2o_cntxt_list_add);
1237 EXPORT_SYMBOL(i2o_cntxt_list_get);
1238 EXPORT_SYMBOL(i2o_cntxt_list_remove);
1239 EXPORT_SYMBOL(i2o_cntxt_list_get_ptr);
1241 EXPORT_SYMBOL(i2o_msg_get_wait);
1242 EXPORT_SYMBOL(i2o_msg_nop);
1243 EXPORT_SYMBOL(i2o_find_iop);
1244 EXPORT_SYMBOL(i2o_iop_find_device);
1245 EXPORT_SYMBOL(i2o_event_register);
1246 EXPORT_SYMBOL(i2o_status_get);
1247 EXPORT_SYMBOL(i2o_controllers);