Import 2.4.0-test6pre3
[davej-history.git] / drivers / i2o / i2o_core.c
blobd39e32529fed46646258a3030cd9c80e44de7586
1 /*
2 * Core I2O structure managment
3 *
4 * (C) Copyright 1999 Red Hat Software
6 * Written by Alan Cox, Building Number Three Ltd
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your 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
16 * Fixes by:
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>
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/pci.h>
30 #include <linux/i2o.h>
32 #include <linux/errno.h>
33 #include <linux/init.h>
34 #include <linux/malloc.h>
35 #include <linux/spinlock.h>
36 #include <linux/smp_lock.h>
38 #include <linux/bitops.h>
39 #include <linux/wait.h>
40 #include <linux/delay.h>
41 #include <linux/timer.h>
42 #include <linux/tqueue.h>
43 #include <linux/interrupt.h>
44 #include <linux/sched.h>
45 #include <asm/semaphore.h>
47 #include <asm/io.h>
48 #include <linux/reboot.h>
50 #include "i2o_lan.h"
52 // #define DRIVERDEBUG
54 #ifdef DRIVERDEBUG
55 #define dprintk(s, args...) printk(s, ## args)
56 #else
57 #define dprintk(s, args...)
58 #endif
60 /* OSM table */
61 static struct i2o_handler *i2o_handlers[MAX_I2O_MODULES] = {NULL};
63 /* Controller list */
64 static struct i2o_controller *i2o_controllers[MAX_I2O_CONTROLLERS] = {NULL};
65 struct i2o_controller *i2o_controller_chain = NULL;
66 int i2o_num_controllers = 0;
68 /* Initiator Context for Core message */
69 static int core_context = 0;
71 /* Initialization && shutdown functions */
72 static void i2o_sys_init(void);
73 static void i2o_sys_shutdown(void);
74 static int i2o_reset_controller(struct i2o_controller *);
75 static int i2o_reboot_event(struct notifier_block *, unsigned long , void *);
76 static int i2o_online_controller(struct i2o_controller *);
77 static int i2o_init_outbound_q(struct i2o_controller *);
78 static int i2o_post_outbound_messages(struct i2o_controller *);
80 /* Reply handler */
81 static void i2o_core_reply(struct i2o_handler *, struct i2o_controller *,
82 struct i2o_message *);
84 /* Various helper functions */
85 static int i2o_lct_get(struct i2o_controller *);
86 static int i2o_lct_notify(struct i2o_controller *);
87 static int i2o_hrt_get(struct i2o_controller *);
89 static int i2o_build_sys_table(void);
90 static int i2o_systab_send(struct i2o_controller *c);
92 /* I2O core event handler */
93 static int i2o_core_evt(void *);
94 static int evt_pid;
95 static int evt_running;
97 /* Dynamic LCT update handler */
98 static int i2o_dyn_lct(void *);
100 void i2o_report_controller_unit(struct i2o_controller *, struct i2o_device *);
103 * I2O System Table. Contains information about
104 * all the IOPs in the system. Used to inform IOPs
105 * about each other's existence.
107 * sys_tbl_ver is the CurrentChangeIndicator that is
108 * used by IOPs to track changes.
110 static struct i2o_sys_tbl *sys_tbl = NULL;
111 static int sys_tbl_ind = 0;
112 static int sys_tbl_len = 0;
115 * This spin lock is used to keep a device from being
116 * added and deleted concurrently across CPUs or interrupts.
117 * This can occur when a user creates a device and immediatelly
118 * deletes it before the new_dev_notify() handler is called.
120 static spinlock_t i2o_dev_lock = SPIN_LOCK_UNLOCKED;
122 #ifdef MODULE
124 * Function table to send to bus specific layers
125 * See <include/linux/i2o.h> for explanation of this
127 static struct i2o_core_func_table i2o_core_functions =
129 i2o_install_controller,
130 i2o_activate_controller,
131 i2o_find_controller,
132 i2o_unlock_controller,
133 i2o_run_queue,
134 i2o_delete_controller
137 #ifdef CONFIG_I2O_PCI_MODULE
138 extern int i2o_pci_core_attach(struct i2o_core_func_table *);
139 extern void i2o_pci_core_detach(void);
140 #endif /* CONFIG_I2O_PCI_MODULE */
142 #endif /* MODULE */
145 * Structures and definitions for synchronous message posting.
146 * See i2o_post_wait() for description.
148 struct i2o_post_wait_data
150 int status;
151 u32 id;
152 wait_queue_head_t *wq;
153 struct i2o_post_wait_data *next;
155 static struct i2o_post_wait_data *post_wait_queue = NULL;
156 static u32 post_wait_id = 0; // Unique ID for each post_wait
157 static spinlock_t post_wait_lock = SPIN_LOCK_UNLOCKED;
158 static void i2o_post_wait_complete(u32, int);
160 /* OSM descriptor handler */
161 static struct i2o_handler i2o_core_handler =
163 (void *)i2o_core_reply,
164 NULL,
165 NULL,
166 NULL,
167 "I2O core layer",
169 I2O_CLASS_EXECUTIVE
174 * Used when queing a reply to be handled later
176 struct reply_info
178 struct i2o_controller *iop;
179 u32 msg[MSG_FRAME_SIZE];
181 static struct reply_info evt_reply;
182 static struct reply_info events[I2O_EVT_Q_LEN];
183 static int evt_in = 0;
184 static int evt_out = 0;
185 static int evt_q_len = 0;
186 #define MODINC(x,y) (x = x++ % y)
189 * I2O configuration spinlock. This isnt a big deal for contention
190 * so we have one only
193 static DECLARE_MUTEX(i2o_configuration_lock);
196 * Event spinlock. Used to keep event queue sane and from
197 * handling multiple events simultaneously.
199 static spinlock_t i2o_evt_lock = SPIN_LOCK_UNLOCKED;
202 * Semaphore used to syncrhonize event handling thread with
203 * interrupt handler.
205 DECLARE_MUTEX(evt_sem);
206 DECLARE_WAIT_QUEUE_HEAD(evt_wait);
208 static struct notifier_block i2o_reboot_notifier =
210 i2o_reboot_event,
211 NULL,
217 * I2O Core reply handler
219 static void i2o_core_reply(struct i2o_handler *h, struct i2o_controller *c,
220 struct i2o_message *m)
222 u32 *msg=(u32 *)m;
223 u32 status;
224 u32 context = msg[2];
226 if (msg[0] & MSG_FAIL) // Fail bit is set
228 u32 *preserved_msg = (u32*)(c->mem_offset + msg[7]);
230 i2o_report_status(KERN_INFO, "i2o_core", msg);
231 i2o_dump_message(preserved_msg);
233 /* If the failed request needs special treatment,
234 * it should be done here. */
236 /* Release the preserved msg by resubmitting it as a NOP */
238 preserved_msg[0] = THREE_WORD_MSG_SIZE | SGL_OFFSET_0;
239 preserved_msg[1] = I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | 0;
240 preserved_msg[2] = 0;
241 i2o_post_message(c, msg[7]);
243 /* If reply to i2o_post_wait failed, return causes a timeout */
245 return;
248 #ifdef DRIVERDEBUG
249 i2o_report_status(KERN_INFO, "i2o_core", msg);
250 #endif
252 if(msg[2]&0x80000000) // Post wait message
254 if (msg[4] >> 24)
255 status = -(msg[4] & 0xFFFF);
256 else
257 status = I2O_POST_WAIT_OK;
259 i2o_post_wait_complete(context, status);
260 return;
263 if(m->function == I2O_CMD_UTIL_EVT_REGISTER)
265 memcpy(events[evt_in].msg, msg, (msg[0]>>16)<<2);
266 events[evt_in].iop = c;
268 spin_lock(&i2o_evt_lock);
269 MODINC(evt_in, I2O_EVT_Q_LEN);
270 if(evt_q_len == I2O_EVT_Q_LEN)
271 MODINC(evt_out, I2O_EVT_Q_LEN);
272 else
273 evt_q_len++;
274 spin_unlock(&i2o_evt_lock);
276 up(&evt_sem);
277 wake_up_interruptible(&evt_wait);
278 return;
281 if(m->function == I2O_CMD_LCT_NOTIFY)
283 up(&c->lct_sem);
284 return;
288 * If this happens, we want to dump the message to the syslog so
289 * it can be sent back to the card manufacturer by the end user
290 * to aid in debugging.
293 printk(KERN_WARNING "%s: Unsolicited message reply sent to core!"
294 "Message dumped to syslog\n",
295 c->name);
296 i2o_dump_message(msg);
298 return;
302 * i2o_install_handler - install a message handler
303 * @h: Handler structure
305 * Install an I2O handler - these handle the asynchronous messaging
306 * from the card once it has initialised. If the table of handlers is
307 * full then -ENOSPC is returned. On a success 0 is returned and the
308 * context field is set by the function. The structure is part of the
309 * system from this time onwards. It must not be freed until it has
310 * been uninstalled
313 int i2o_install_handler(struct i2o_handler *h)
315 int i;
316 down(&i2o_configuration_lock);
317 for(i=0;i<MAX_I2O_MODULES;i++)
319 if(i2o_handlers[i]==NULL)
321 h->context = i;
322 i2o_handlers[i]=h;
323 up(&i2o_configuration_lock);
324 return 0;
327 up(&i2o_configuration_lock);
328 return -ENOSPC;
332 * i2o_remove_handler - remove an i2o message handler
333 * @h: handler
335 * Remove a message handler previously installed with i2o_install_handler.
336 * After this function returns the handler object can be freed or re-used
339 int i2o_remove_handler(struct i2o_handler *h)
341 i2o_handlers[h->context]=NULL;
342 return 0;
347 * Each I2O controller has a chain of devices on it.
348 * Each device has a pointer to it's LCT entry to be used
349 * for fun purposes.
353 * i2o_install_device - attach a device to a controller
354 * @c: controller
355 * @d: device
357 * Add a new device to an i2o controller. This can be called from
358 * non interrupt contexts only. It adds the device and marks it as
359 * unclaimed. The device memory becomes part of the kernel and must
360 * be uninstalled before being freed or reused. Zero is returned
361 * on success.
364 int i2o_install_device(struct i2o_controller *c, struct i2o_device *d)
366 int i;
368 down(&i2o_configuration_lock);
369 d->controller=c;
370 d->owner=NULL;
371 d->next=c->devices;
372 c->devices=d;
373 *d->dev_name = 0;
375 for(i = 0; i < I2O_MAX_MANAGERS; i++)
376 d->managers[i] = NULL;
378 up(&i2o_configuration_lock);
379 return 0;
382 /* we need this version to call out of i2o_delete_controller */
384 int __i2o_delete_device(struct i2o_device *d)
386 struct i2o_device **p;
387 int i;
389 p=&(d->controller->devices);
392 * Hey we have a driver!
393 * Check to see if the driver wants us to notify it of
394 * device deletion. If it doesn't we assume that it
395 * is unsafe to delete a device with an owner and
396 * fail.
398 if(d->owner)
400 if(d->owner->dev_del_notify)
402 dprintk(KERN_INFO "Device has owner, notifying\n");
403 d->owner->dev_del_notify(d->controller, d);
404 if(d->owner)
406 printk(KERN_WARNING
407 "Driver \"%s\" did not release device!\n", d->owner->name);
408 return -EBUSY;
411 else
412 return -EBUSY;
416 * Tell any other users who are talking to this device
417 * that it's going away. We assume that everything works.
419 for(i=0; i < I2O_MAX_MANAGERS; i++)
421 if(d->managers[i] && d->managers[i]->dev_del_notify)
422 d->managers[i]->dev_del_notify(d->controller, d);
425 while(*p!=NULL)
427 if(*p==d)
430 * Destroy
432 *p=d->next;
433 kfree(d);
434 return 0;
436 p=&((*p)->next);
438 printk(KERN_ERR "i2o_delete_device: passed invalid device.\n");
439 return -EINVAL;
443 * i2o_delete_device - remove an i2o device
444 * @d: device to remove
446 * This function unhooks a device from a controller. The device
447 * will not be unhooked if it has an owner who does not wish to free
448 * it, or if the owner lacks a dev_del_notify function. In that case
449 * -EBUSY is returned. On success 0 is returned. Other errors cause
450 * negative errno values to be returned
453 int i2o_delete_device(struct i2o_device *d)
455 int ret;
457 down(&i2o_configuration_lock);
460 * Seek, locate
463 ret = __i2o_delete_device(d);
465 up(&i2o_configuration_lock);
467 return ret;
471 * i2o_install_controller - attach a controller
472 * @c: controller
474 * Add a new controller to the i2o layer. This can be called from
475 * non interrupt contexts only. It adds the controller and marks it as
476 * unused with no devices. If the tables are full or memory allocations
477 * fail then a negative errno code is returned. On success zero is
478 * returned and the controller is bound to the system. The structure
479 * must not be freed or reused until being uninstalled.
482 int i2o_install_controller(struct i2o_controller *c)
484 int i;
485 down(&i2o_configuration_lock);
486 for(i=0;i<MAX_I2O_CONTROLLERS;i++)
488 if(i2o_controllers[i]==NULL)
490 c->dlct = (i2o_lct*)kmalloc(8192, GFP_KERNEL);
491 if(c->dlct==NULL)
493 up(&i2o_configuration_lock);
494 return -ENOMEM;
496 i2o_controllers[i]=c;
497 c->devices = NULL;
498 c->next=i2o_controller_chain;
499 i2o_controller_chain=c;
500 c->unit = i;
501 c->page_frame = NULL;
502 c->hrt = NULL;
503 c->lct = NULL;
504 c->status_block = NULL;
505 sprintf(c->name, "i2o/iop%d", i);
506 i2o_num_controllers++;
507 init_MUTEX_LOCKED(&c->lct_sem);
508 up(&i2o_configuration_lock);
509 return 0;
512 printk(KERN_ERR "No free i2o controller slots.\n");
513 up(&i2o_configuration_lock);
514 return -EBUSY;
518 * i2o_delete_controller - delete a controller
519 * @c: controller
521 * Remove an i2o controller from the system. If the controller or its
522 * devices are busy then -EBUSY is returned. On a failure a negative
523 * errno code is returned. On success zero is returned.
526 int i2o_delete_controller(struct i2o_controller *c)
528 struct i2o_controller **p;
529 int users;
530 char name[16];
531 int stat;
533 dprintk(KERN_INFO "Deleting controller %s\n", c->name);
536 * Clear event registration as this can cause weird behavior
538 if(c->status_block->iop_state == ADAPTER_STATE_OPERATIONAL)
539 i2o_event_register(c, core_context, 0, 0, 0);
541 down(&i2o_configuration_lock);
542 if((users=atomic_read(&c->users)))
544 dprintk(KERN_INFO "I2O: %d users for controller %s\n", users,
545 c->name);
546 up(&i2o_configuration_lock);
547 return -EBUSY;
549 while(c->devices)
551 if(__i2o_delete_device(c->devices)<0)
553 /* Shouldnt happen */
554 c->bus_disable(c);
555 up(&i2o_configuration_lock);
556 return -EBUSY;
561 * If this is shutdown time, the thread's already been killed
563 if(c->lct_running) {
564 stat = kill_proc(c->lct_pid, SIGTERM, 1);
565 if(!stat) {
566 int count = 10 * 100;
567 while(c->lct_running && --count) {
568 current->state = TASK_INTERRUPTIBLE;
569 schedule_timeout(1);
572 if(!count)
573 printk(KERN_ERR
574 "%s: LCT thread still running!\n",
575 c->name);
579 p=&i2o_controller_chain;
581 while(*p)
583 if(*p==c)
585 /* Ask the IOP to switch to RESET state */
586 i2o_reset_controller(c);
588 /* Release IRQ */
589 c->destructor(c);
591 *p=c->next;
592 up(&i2o_configuration_lock);
594 if(c->page_frame)
595 kfree(c->page_frame);
596 if(c->hrt)
597 kfree(c->hrt);
598 if(c->lct)
599 kfree(c->lct);
600 if(c->status_block)
601 kfree(c->status_block);
602 if(c->dlct)
603 kfree(c->dlct);
605 i2o_controllers[c->unit]=NULL;
606 memcpy(name, c->name, strlen(c->name)+1);
607 kfree(c);
608 dprintk(KERN_INFO "%s: Deleted from controller chain.\n", name);
610 i2o_num_controllers--;
611 return 0;
613 p=&((*p)->next);
615 up(&i2o_configuration_lock);
616 printk(KERN_ERR "i2o_delete_controller: bad pointer!\n");
617 return -ENOENT;
621 * i2o_unlock_controller - unlock a controller
622 * @c: controller to unlock
624 * Take a lock on an i2o controller. This prevents it being deleted.
625 * i2o controllers are not refcounted so a deletion of an in use device
626 * will fail, not take affect on the last dereference.
629 void i2o_unlock_controller(struct i2o_controller *c)
631 atomic_dec(&c->users);
635 * i2o_find_controller - return a locked controller
636 * @n: controller number
638 * Returns a pointer to the controller object. The controller is locked
639 * on return. NULL is returned if the controller is not found.
642 struct i2o_controller *i2o_find_controller(int n)
644 struct i2o_controller *c;
646 if(n<0 || n>=MAX_I2O_CONTROLLERS)
647 return NULL;
649 down(&i2o_configuration_lock);
650 c=i2o_controllers[n];
651 if(c!=NULL)
652 atomic_inc(&c->users);
653 up(&i2o_configuration_lock);
654 return c;
658 * i2o_issue_claim - claim or release a device
659 * @cmd: command
660 * @c: controller to claim for
661 * @tid: i2o task id
662 * @type: type of claim
664 * Issue I2O UTIL_CLAIM and UTIL_RELEASE messages. The message to be sent
665 * is set by cmd. The tid is the task id of the object to claim and the
666 * type is the claim type (see the i2o standard)
668 * Zero is returned on success.
671 static int i2o_issue_claim(u32 cmd, struct i2o_controller *c, int tid, u32 type)
673 u32 msg[5];
675 msg[0] = FIVE_WORD_MSG_SIZE | SGL_OFFSET_0;
676 msg[1] = cmd << 24 | HOST_TID<<12 | tid;
677 msg[3] = 0;
678 msg[4] = type;
680 return i2o_post_wait(c, msg, sizeof(msg), 60);
684 * i2o_claim_device - claim a device for use by an OSM
685 * @d: device to claim
686 * @h: handler for this device
688 * Do the leg work to assign a device to a given OSM on Linux. The
689 * kernel updates the internal handler data for the device and then
690 * performs an I2O claim for the device, attempting to claim the
691 * device as primary. If the attempt fails a negative errno code
692 * is returned. On success zero is returned.
695 int i2o_claim_device(struct i2o_device *d, struct i2o_handler *h)
697 down(&i2o_configuration_lock);
698 if (d->owner) {
699 printk(KERN_INFO "Device claim called, but dev allready owned by %s!",
700 h->name);
701 up(&i2o_configuration_lock);
702 return -EBUSY;
704 d->owner=h;
706 if(i2o_issue_claim(I2O_CMD_UTIL_CLAIM ,d->controller,d->lct_data.tid,
707 I2O_CLAIM_PRIMARY))
709 d->owner = NULL;
710 return -EBUSY;
712 up(&i2o_configuration_lock);
713 return 0;
717 * i2o_release_device - release a device that the OSM is using
718 * @d: device to claim
719 * @h: handler for this device
721 * Drop a claim by an OSM on a given I2O device. The handler is cleared
722 * and 0 is returned on success.
726 int i2o_release_device(struct i2o_device *d, struct i2o_handler *h)
728 int err = 0;
730 down(&i2o_configuration_lock);
731 if (d->owner != h) {
732 printk(KERN_INFO "Claim release called, but not owned by %s!",
733 h->name);
734 up(&i2o_configuration_lock);
735 return -ENOENT;
738 d->owner = NULL;
740 if(i2o_issue_claim(I2O_CMD_UTIL_RELEASE, d->controller, d->lct_data.tid,
741 I2O_CLAIM_PRIMARY))
743 err = -ENXIO;
744 d->owner = h;
747 up(&i2o_configuration_lock);
748 return err;
752 * Called by OSMs to let the core know that they want to be
753 * notified if the given device is deleted from the system.
755 int i2o_device_notify_on(struct i2o_device *d, struct i2o_handler *h)
757 int i;
759 if(d->num_managers == I2O_MAX_MANAGERS)
760 return -ENOSPC;
762 for(i = 0; i < I2O_MAX_MANAGERS; i++)
764 if(!d->managers[i])
766 d->managers[i] = h;
767 break;
771 d->num_managers++;
773 return 0;
777 * Called by OSMs to let the core know that they no longer
778 * are interested in the fate of the given device.
780 int i2o_device_notify_off(struct i2o_device *d, struct i2o_handler *h)
782 int i;
784 for(i=0; i < I2O_MAX_MANAGERS; i++)
786 if(d->managers[i] == h)
788 d->managers[i] = NULL;
789 d->num_managers--;
790 return 0;
794 return -ENOENT;
798 * Event registration API
800 int i2o_event_register(struct i2o_controller *c, u32 tid,
801 u32 init_context, u32 tr_context, u32 evt_mask)
803 u32 msg[5]; // Not performance critical, so we just
804 // i2o_post_this it instead of building it
805 // in IOP memory
807 msg[0] = FIVE_WORD_MSG_SIZE|SGL_OFFSET_0;
808 msg[1] = I2O_CMD_UTIL_EVT_REGISTER<<24 | HOST_TID<<12 | tid;
809 msg[2] = init_context;
810 msg[3] = tr_context;
811 msg[4] = evt_mask;
813 return i2o_post_this(c, msg, sizeof(msg));
817 * Event ack API
819 * We just take a pointer to the original UTIL_EVENT_REGISTER reply
820 * message and change the function code since that's what spec
821 * describes an EventAck message looking like.
824 int i2o_event_ack(struct i2o_controller *c, u32 *msg)
826 struct i2o_message *m = (struct i2o_message *)msg;
828 m->function = I2O_CMD_UTIL_EVT_ACK;
830 return i2o_post_wait(c, msg, m->size * 4, 2);
834 * Core event handler. Runs as a separate thread and is woken
835 * up whenever there is an Executive class event.
837 static int i2o_core_evt(void *reply_data)
839 struct reply_info *reply = (struct reply_info *) reply_data;
840 u32 *msg = reply->msg;
841 struct i2o_controller *c = NULL;
842 int flags;
844 lock_kernel();
845 exit_files(current);
846 daemonize();
847 unlock_kernel();
849 strcpy(current->comm, "i2oevtd");
850 evt_running = 1;
852 while(1)
854 down_interruptible(&evt_sem);
855 if(signal_pending(current))
857 dprintk(KERN_INFO "I2O event thread dead\n");
858 evt_running = 0;
859 return 0;
863 * Copy the data out of the queue so that we don't have to lock
864 * around the whole function and just around the qlen update
866 spin_lock_irqsave(&i2o_evt_lock, flags);
867 memcpy(reply, &events[evt_out], sizeof(struct reply_info));
868 MODINC(evt_out, I2O_EVT_Q_LEN);
869 evt_q_len--;
870 spin_unlock_irqrestore(&i2o_evt_lock, flags);
872 c = reply->iop;
873 dprintk(KERN_INFO "I2O IRTOS EVENT: iop%d, event %#10x\n", c->unit, msg[4]);
876 * We do not attempt to delete/quiesce/etc. the controller if
877 * some sort of error indidication occurs. We may want to do
878 * so in the future, but for now we just let the user deal with
879 * it. One reason for this is that what to do with an error
880 * or when to send what ærror is not really agreed on, so
881 * we get errors that may not be fatal but just look like they
882 * are...so let the user deal with it.
884 switch(msg[4])
886 case I2O_EVT_IND_EXEC_RESOURCE_LIMITS:
887 printk(KERN_ERR "%s: Out of resources\n", c->name);
888 break;
890 case I2O_EVT_IND_EXEC_POWER_FAIL:
891 printk(KERN_ERR "%s: Power failure\n", c->name);
892 break;
894 case I2O_EVT_IND_EXEC_HW_FAIL:
896 char *fail[] =
898 "Unknown Error",
899 "Power Lost",
900 "Code Violation",
901 "Parity Error",
902 "Code Execution Exception",
903 "Watchdog Timer Expired"
906 if(msg[5] <= 6)
907 printk(KERN_ERR "%s: Hardware Failure: %s\n",
908 c->name, fail[msg[5]]);
909 else
910 printk(KERN_ERR "%s: Unknown Hardware Failure\n", c->name);
912 break;
916 * New device created
917 * - Create a new i2o_device entry
918 * - Inform all interested drivers about this device's existence
920 case I2O_EVT_IND_EXEC_NEW_LCT_ENTRY:
922 struct i2o_device *d = (struct i2o_device *)
923 kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
924 int i;
926 memcpy(&d->lct_data, &msg[5], sizeof(i2o_lct_entry));
928 d->next = NULL;
929 d->controller = c;
930 d->flags = 0;
932 i2o_report_controller_unit(c, d);
933 i2o_install_device(c,d);
935 for(i = 0; i < MAX_I2O_MODULES; i++)
937 if(i2o_handlers[i] &&
938 i2o_handlers[i]->new_dev_notify &&
939 (i2o_handlers[i]->class&d->lct_data.class_id))
941 spin_lock(&i2o_dev_lock);
942 i2o_handlers[i]->new_dev_notify(c,d);
943 spin_unlock(&i2o_dev_lock);
947 break;
951 * LCT entry for a device has been modified, so update it
952 * internally.
954 case I2O_EVT_IND_EXEC_MODIFIED_LCT:
956 struct i2o_device *d;
957 i2o_lct_entry *new_lct = (i2o_lct_entry *)&msg[5];
959 for(d = c->devices; d; d = d->next)
961 if(d->lct_data.tid == new_lct->tid)
963 memcpy(&d->lct_data, new_lct, sizeof(i2o_lct_entry));
964 break;
967 break;
970 case I2O_EVT_IND_CONFIGURATION_FLAG:
971 printk(KERN_WARNING "%s requires user configuration\n", c->name);
972 break;
974 case I2O_EVT_IND_GENERAL_WARNING:
975 printk(KERN_WARNING "%s: Warning notification received!"
976 "Check configuration for errors!\n", c->name);
977 break;
979 default:
980 printk(KERN_WARNING "%s: No handler for event (0x%08x)\n", c->name, msg[4]);
981 break;
985 return 0;
989 * Dynamic LCT update. This compares the LCT with the currently
990 * installed devices to check for device deletions..this needed b/c there
991 * is no DELETED_LCT_ENTRY EventIndicator for the Executive class so
992 * we can't just have the event handler do this...annoying
994 * This is a hole in the spec that will hopefully be fixed someday.
996 static int i2o_dyn_lct(void *foo)
998 struct i2o_controller *c = (struct i2o_controller *)foo;
999 struct i2o_device *d = NULL;
1000 struct i2o_device *d1 = NULL;
1001 int i = 0;
1002 int found = 0;
1003 int entries;
1004 void *tmp;
1005 char name[16];
1007 lock_kernel();
1008 exit_files(current);
1009 daemonize();
1010 unlock_kernel();
1012 sprintf(name, "iop%d_lctd", c->unit);
1013 strcpy(current->comm, name);
1015 c->lct_running = 1;
1017 while(1)
1019 down_interruptible(&c->lct_sem);
1020 if(signal_pending(current))
1022 dprintk(KERN_ERR "%s: LCT thread dead\n", c->name);
1023 c->lct_running = 0;
1024 return 0;
1027 entries = c->dlct->table_size;
1028 entries -= 3;
1029 entries /= 9;
1031 dprintk(KERN_INFO "%s: Dynamic LCT Update\n",c->name);
1032 dprintk(KERN_INFO "%s: Dynamic LCT contains %d entries\n", c->name, entries);
1034 if(!entries)
1036 printk(KERN_INFO "%s: Empty LCT???\n", c->name);
1037 continue;
1041 * Loop through all the devices on the IOP looking for their
1042 * LCT data in the LCT. We assume that TIDs are not repeated.
1043 * as that is the only way to really tell. It's been confirmed
1044 * by the IRTOS vendor(s?) that TIDs are not reused until they
1045 * wrap arround(4096), and I doubt a system will up long enough
1046 * to create/delete that many devices.
1048 for(d = c->devices; d; )
1050 found = 0;
1051 d1 = d->next;
1053 for(i = 0; i < entries; i++)
1055 if(d->lct_data.tid == c->dlct->lct_entry[i].tid)
1057 found = 1;
1058 break;
1061 if(!found)
1063 dprintk(KERN_INFO "i2o_core: Deleted device!\n");
1064 spin_lock(&i2o_dev_lock);
1065 i2o_delete_device(d);
1066 spin_unlock(&i2o_dev_lock);
1068 d = d1;
1072 * Tell LCT to renotify us next time there is a change
1074 i2o_lct_notify(c);
1077 * Copy new LCT into public LCT
1079 * Possible race if someone is reading LCT while we are copying
1080 * over it. If this happens, we'll fix it then. but I doubt that
1081 * the LCT will get updated often enough or will get read by
1082 * a user often enough to worry.
1084 if(c->lct->table_size < c->dlct->table_size)
1086 tmp = c->lct;
1087 c->lct = kmalloc(c->dlct->table_size<<2, GFP_KERNEL);
1088 if(!c->lct)
1090 printk(KERN_ERR "%s: No memory for LCT!\n", c->name);
1091 c->lct = tmp;
1092 continue;
1094 kfree(tmp);
1096 memcpy(c->lct, c->dlct, c->dlct->table_size<<2);
1099 return 0;
1103 * i2o_run_queue - process pending events on a controller
1104 * @c: controller to process
1106 * This is called by the bus specific driver layer when an interrupt
1107 * or poll of this card interface is desired.
1110 void i2o_run_queue(struct i2o_controller *c)
1112 struct i2o_message *m;
1113 u32 mv;
1114 u32 *msg;
1117 * Old 960 steppings had a bug in the I2O unit that caused
1118 * the queue to appear empty when it wasn't.
1120 if((mv=I2O_REPLY_READ32(c))==0xFFFFFFFF)
1121 mv=I2O_REPLY_READ32(c);
1123 while(mv!=0xFFFFFFFF)
1125 struct i2o_handler *i;
1126 m=(struct i2o_message *)bus_to_virt(mv);
1127 msg=(u32*)m;
1130 * Temporary Debugging
1132 if(m->function==0x15)
1133 printk(KERN_ERR "%s: UTFR!\n", c->name);
1135 i=i2o_handlers[m->initiator_context&(MAX_I2O_MODULES-1)];
1136 if(i && i->reply)
1137 i->reply(i,c,m);
1138 else
1140 printk(KERN_WARNING "I2O: Spurious reply to handler %d\n",
1141 m->initiator_context&(MAX_I2O_MODULES-1));
1143 i2o_flush_reply(c,mv);
1144 mb();
1146 /* That 960 bug again... */
1147 if((mv=I2O_REPLY_READ32(c))==0xFFFFFFFF)
1148 mv=I2O_REPLY_READ32(c);
1154 * i2o_get_class_name - do i2o class name lookup
1155 * @class: class number
1157 * Return a descriptive string for an i2o class
1160 const char *i2o_get_class_name(int class)
1162 int idx = 16;
1163 static char *i2o_class_name[] = {
1164 "Executive",
1165 "Device Driver Module",
1166 "Block Device",
1167 "Tape Device",
1168 "LAN Interface",
1169 "WAN Interface",
1170 "Fibre Channel Port",
1171 "Fibre Channel Device",
1172 "SCSI Device",
1173 "ATE Port",
1174 "ATE Device",
1175 "Floppy Controller",
1176 "Floppy Device",
1177 "Secondary Bus Port",
1178 "Peer Transport Agent",
1179 "Peer Transport",
1180 "Unknown"
1183 switch(class&0xFFF)
1185 case I2O_CLASS_EXECUTIVE:
1186 idx = 0; break;
1187 case I2O_CLASS_DDM:
1188 idx = 1; break;
1189 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
1190 idx = 2; break;
1191 case I2O_CLASS_SEQUENTIAL_STORAGE:
1192 idx = 3; break;
1193 case I2O_CLASS_LAN:
1194 idx = 4; break;
1195 case I2O_CLASS_WAN:
1196 idx = 5; break;
1197 case I2O_CLASS_FIBRE_CHANNEL_PORT:
1198 idx = 6; break;
1199 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
1200 idx = 7; break;
1201 case I2O_CLASS_SCSI_PERIPHERAL:
1202 idx = 8; break;
1203 case I2O_CLASS_ATE_PORT:
1204 idx = 9; break;
1205 case I2O_CLASS_ATE_PERIPHERAL:
1206 idx = 10; break;
1207 case I2O_CLASS_FLOPPY_CONTROLLER:
1208 idx = 11; break;
1209 case I2O_CLASS_FLOPPY_DEVICE:
1210 idx = 12; break;
1211 case I2O_CLASS_BUS_ADAPTER_PORT:
1212 idx = 13; break;
1213 case I2O_CLASS_PEER_TRANSPORT_AGENT:
1214 idx = 14; break;
1215 case I2O_CLASS_PEER_TRANSPORT:
1216 idx = 15; break;
1219 return i2o_class_name[idx];
1224 * i2o_wait_message
1225 * @c: controller
1226 * @why: explanation
1228 * This function waits up to 5 seconds for a message slot to be
1229 * available. If no message is available it prints an error message
1230 * that is expected to be what the message will be used for (eg
1231 * "get_status"). 0xFFFFFFFF is returned on a failure.
1233 * On a success the message is returned. This is the physical page
1234 * frame offset address from the read port. (See the i2o spec)
1237 u32 i2o_wait_message(struct i2o_controller *c, char *why)
1239 long time=jiffies;
1240 u32 m;
1241 while((m=I2O_POST_READ32(c))==0xFFFFFFFF)
1243 if((jiffies-time)>=5*HZ)
1245 dprintk(KERN_ERR "%s: Timeout waiting for message frame to send %s.\n",
1246 c->name, why);
1247 return 0xFFFFFFFF;
1249 schedule();
1250 barrier();
1252 return m;
1256 * i2o_report_controller_unit - print information about a tid
1257 * @c: controller
1258 * @d: device
1260 * Dump an information block associated with a given unit (TID). The
1261 * tables are read and a block of text is output to printk that is
1262 * formatted intended for the user.
1265 void i2o_report_controller_unit(struct i2o_controller *c, struct i2o_device *d)
1267 char buf[64];
1268 char str[22];
1269 int ret;
1270 int unit = d->lct_data.tid;
1272 printk(KERN_INFO "Target ID %d.\n", unit);
1274 if((ret=i2o_query_scalar(c, unit, 0xF100, 3, buf, 16))>=0)
1276 buf[16]=0;
1277 printk(KERN_INFO " Vendor: %s\n", buf);
1279 if((ret=i2o_query_scalar(c, unit, 0xF100, 4, buf, 16))>=0)
1281 buf[16]=0;
1282 printk(KERN_INFO " Device: %s\n", buf);
1284 #if 0
1285 if(i2o_query_scalar(c, unit, 0xF100, 5, buf, 16)>=0)
1287 buf[16]=0;
1288 printk(KERN_INFO " Description: %s\n", buf);
1290 #endif
1291 if((ret=i2o_query_scalar(c, unit, 0xF100, 6, buf, 8))>=0)
1293 buf[8]=0;
1294 printk(KERN_INFO " Rev: %s\n", buf);
1297 printk(KERN_INFO " Class: ");
1298 sprintf(str, "%-21s", i2o_get_class_name(d->lct_data.class_id));
1299 printk("%s\n", str);
1301 printk(KERN_INFO " Subclass: 0x%04X\n", d->lct_data.sub_class);
1302 printk(KERN_INFO " Flags: ");
1304 if(d->lct_data.device_flags&(1<<0))
1305 printk("C"); // ConfigDialog requested
1306 if(d->lct_data.device_flags&(1<<1))
1307 printk("U"); // Multi-user capable
1308 if(!(d->lct_data.device_flags&(1<<4)))
1309 printk("P"); // Peer service enabled!
1310 if(!(d->lct_data.device_flags&(1<<5)))
1311 printk("M"); // Mgmt service enabled!
1312 printk("\n");
1318 * Parse the hardware resource table. Right now we print it out
1319 * and don't do a lot with it. We should collate these and then
1320 * interact with the Linux resource allocation block.
1322 * Lets prove we can read it first eh ?
1324 * This is full of endianisms!
1327 static int i2o_parse_hrt(struct i2o_controller *c)
1329 #ifdef DRIVERDEBUG
1330 u32 *rows=(u32*)c->hrt;
1331 u8 *p=(u8 *)c->hrt;
1332 u8 *d;
1333 int count;
1334 int length;
1335 int i;
1336 int state;
1338 if(p[3]!=0)
1340 printk(KERN_ERR "%s: HRT table for controller is too new a version.\n",
1341 c->name);
1342 return -1;
1345 count=p[0]|(p[1]<<8);
1346 length = p[2];
1348 printk(KERN_INFO "%s: HRT has %d entries of %d bytes each.\n",
1349 c->name, count, length<<2);
1351 rows+=2;
1353 for(i=0;i<count;i++)
1355 printk(KERN_INFO "Adapter %08X: ", rows[0]);
1356 p=(u8 *)(rows+1);
1357 d=(u8 *)(rows+2);
1358 state=p[1]<<8|p[0];
1360 printk("TID %04X:[", state&0xFFF);
1361 state>>=12;
1362 if(state&(1<<0))
1363 printk("H"); /* Hidden */
1364 if(state&(1<<2))
1366 printk("P"); /* Present */
1367 if(state&(1<<1))
1368 printk("C"); /* Controlled */
1370 if(state>9)
1371 printk("*"); /* Hard */
1373 printk("]:");
1375 switch(p[3]&0xFFFF)
1377 case 0:
1378 /* Adapter private bus - easy */
1379 printk("Local bus %d: I/O at 0x%04X Mem 0x%08X",
1380 p[2], d[1]<<8|d[0], *(u32 *)(d+4));
1381 break;
1382 case 1:
1383 /* ISA bus */
1384 printk("ISA %d: CSN %d I/O at 0x%04X Mem 0x%08X",
1385 p[2], d[2], d[1]<<8|d[0], *(u32 *)(d+4));
1386 break;
1388 case 2: /* EISA bus */
1389 printk("EISA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
1390 p[2], d[3], d[1]<<8|d[0], *(u32 *)(d+4));
1391 break;
1393 case 3: /* MCA bus */
1394 printk("MCA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
1395 p[2], d[3], d[1]<<8|d[0], *(u32 *)(d+4));
1396 break;
1398 case 4: /* PCI bus */
1399 printk("PCI %d: Bus %d Device %d Function %d",
1400 p[2], d[2], d[1], d[0]);
1401 break;
1403 case 0x80: /* Other */
1404 default:
1405 printk("Unsupported bus type.");
1406 break;
1408 printk("\n");
1409 rows+=length;
1411 #endif
1412 return 0;
1416 * The logical configuration table tells us what we can talk to
1417 * on the board. Most of the stuff isn't interesting to us.
1420 static int i2o_parse_lct(struct i2o_controller *c)
1422 int i;
1423 int max;
1424 int tid;
1425 struct i2o_device *d;
1426 i2o_lct *lct = c->lct;
1428 if (lct == NULL) {
1429 printk(KERN_ERR "%s: LCT is empty???\n", c->name);
1430 return -1;
1433 max = lct->table_size;
1434 max -= 3;
1435 max /= 9;
1437 printk(KERN_INFO "%s: LCT has %d entries.\n", c->name, max);
1439 if(lct->iop_flags&(1<<0))
1440 printk(KERN_WARNING "%s: Configuration dialog desired.\n", c->name);
1442 for(i=0;i<max;i++)
1444 d = (struct i2o_device *)kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
1445 if(d==NULL)
1447 printk(KERN_CRIT "i2o_core: Out of memory for I2O device data.\n");
1448 return -ENOMEM;
1451 d->controller = c;
1452 d->next = NULL;
1454 memcpy(&d->lct_data, &lct->lct_entry[i], sizeof(i2o_lct_entry));
1456 d->flags = 0;
1457 tid = d->lct_data.tid;
1459 i2o_report_controller_unit(c, d);
1461 i2o_install_device(c, d);
1463 return 0;
1468 * i2o_quiesce_controller - quiesce controller
1469 * @c: controller
1471 * Quiesce an IOP. Causes IOP to make external operation quiescent
1472 * (i2o 'READY' state). Internal operation of the IOP continues normally.
1475 int i2o_quiesce_controller(struct i2o_controller *c)
1477 u32 msg[4];
1478 int ret;
1480 i2o_status_get(c);
1482 /* SysQuiesce discarded if IOP not in READY or OPERATIONAL state */
1484 if ((c->status_block->iop_state != ADAPTER_STATE_READY) &&
1485 (c->status_block->iop_state != ADAPTER_STATE_OPERATIONAL))
1487 return 0;
1490 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
1491 msg[1] = I2O_CMD_SYS_QUIESCE<<24|HOST_TID<<12|ADAPTER_TID;
1492 msg[3] = 0;
1494 /* Long timeout needed for quiesce if lots of devices */
1496 if ((ret = i2o_post_wait(c, msg, sizeof(msg), 240)))
1497 printk(KERN_INFO "%s: Unable to quiesce (status=%#x).\n",
1498 c->name, -ret);
1499 else
1500 dprintk(KERN_INFO "%s: Quiesced.\n", c->name);
1502 i2o_status_get(c); // Entered READY state
1503 return ret;
1507 * i2o_enable_controller - move controller from ready to operational
1508 * @c: controller
1510 * Enable IOP. This allows the IOP to resume external operations and
1511 * reverses the effect of a quiesce. In the event of an error a negative
1512 * errno code is returned.
1515 int i2o_enable_controller(struct i2o_controller *c)
1517 u32 msg[4];
1518 int ret;
1520 i2o_status_get(c);
1522 /* Enable only allowed on READY state */
1523 if(c->status_block->iop_state != ADAPTER_STATE_READY)
1524 return -EINVAL;
1526 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
1527 msg[1]=I2O_CMD_SYS_ENABLE<<24|HOST_TID<<12|ADAPTER_TID;
1529 /* How long of a timeout do we need? */
1531 if ((ret = i2o_post_wait(c, msg, sizeof(msg), 240)))
1532 printk(KERN_ERR "%s: Could not enable (status=%#x).\n",
1533 c->name, -ret);
1534 else
1535 dprintk(KERN_INFO "%s: Enabled.\n", c->name);
1537 i2o_status_get(c); // entered OPERATIONAL state
1539 return ret;
1543 * i2o_clear_controller - clear a controller
1544 * @c: controller
1546 * Clear an IOP to HOLD state, ie. terminate external operations, clear all
1547 * input queues and prepare for a system restart. IOP's internal operation
1548 * continues normally and the outbound queue is alive.
1549 * The IOP is not expected to rebuild its LCT.
1552 int i2o_clear_controller(struct i2o_controller *c)
1554 struct i2o_controller *iop;
1555 u32 msg[4];
1556 int ret;
1558 /* Quiesce all IOPs first */
1560 for (iop = i2o_controller_chain; iop; iop = iop->next)
1561 i2o_quiesce_controller(iop);
1563 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
1564 msg[1]=I2O_CMD_ADAPTER_CLEAR<<24|HOST_TID<<12|ADAPTER_TID;
1565 msg[3]=0;
1567 if ((ret=i2o_post_wait(c, msg, sizeof(msg), 30)))
1568 printk(KERN_INFO "%s: Unable to clear (status=%#x).\n",
1569 c->name, -ret);
1570 else
1571 dprintk(KERN_INFO "%s: Cleared.\n",c->name);
1573 i2o_status_get(c);
1575 /* Enable other IOPs */
1577 for (iop = i2o_controller_chain; iop; iop = iop->next)
1578 if (iop != c)
1579 i2o_enable_controller(iop);
1581 return ret;
1586 * i2o_reset_controller
1587 * @c: controller to reset
1589 * Reset the IOP into INIT state and wait until IOP gets into RESET state.
1590 * Terminate all external operations, clear IOP's inbound and outbound
1591 * queues, terminate all DDMs, and reload the IOP's operating environment
1592 * and all local DDMs. The IOP rebuilds its LCT.
1595 static int i2o_reset_controller(struct i2o_controller *c)
1597 struct i2o_controller *iop;
1598 u32 m;
1599 u8 *status;
1600 u32 *msg;
1601 long time;
1603 /* Quiesce all IOPs first */
1605 for (iop = i2o_controller_chain; iop; iop = iop->next)
1606 i2o_quiesce_controller(iop);
1608 m=i2o_wait_message(c, "AdapterReset");
1609 if(m==0xFFFFFFFF)
1610 return -ETIMEDOUT;
1611 msg=(u32 *)(c->mem_offset+m);
1613 status=(void *)kmalloc(4, GFP_KERNEL);
1614 if(status==NULL) {
1615 printk(KERN_ERR "IOP reset failed - no free memory.\n");
1616 return -ENOMEM;
1618 memset(status, 0, 4);
1620 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
1621 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
1622 msg[2]=core_context;
1623 msg[3]=0;
1624 msg[4]=0;
1625 msg[5]=0;
1626 msg[6]=virt_to_bus(status);
1627 msg[7]=0; /* 64bit host FIXME */
1629 i2o_post_message(c,m);
1631 /* Wait for a reply */
1632 time=jiffies;
1633 while(status[0]==0)
1635 if((jiffies-time)>=20*HZ)
1637 printk(KERN_ERR "IOP reset timeout.\n");
1638 kfree(status);
1639 return -ETIMEDOUT;
1641 schedule();
1642 barrier();
1645 if (status[0]==I2O_CMD_IN_PROGRESS)
1648 * Once the reset is sent, the IOP goes into the INIT state
1649 * which is indeterminate. We need to wait until the IOP
1650 * has rebooted before we can let the system talk to
1651 * it. We read the inbound Free_List until a message is
1652 * available. If we can't read one in the given ammount of
1653 * time, we assume the IOP could not reboot properly.
1656 dprintk(KERN_INFO "%s: Reset in progress, waiting for reboot...\n",
1657 c->name);
1659 time = jiffies;
1660 m = I2O_POST_READ32(c);
1661 while(m == 0XFFFFFFFF)
1663 if((jiffies-time) >= 30*HZ)
1665 printk(KERN_ERR "%s: Timeout waiting for IOP reset.\n",
1666 c->name);
1667 return -ETIMEDOUT;
1669 schedule();
1670 barrier();
1671 m = I2O_POST_READ32(c);
1673 i2o_flush_reply(c,m);
1676 /* If IopReset was rejected or didn't perform reset, try IopClear */
1678 i2o_status_get(c);
1679 if (status[0] == I2O_CMD_REJECTED ||
1680 c->status_block->iop_state != ADAPTER_STATE_RESET)
1682 printk(KERN_WARNING "%s: Reset rejected, trying to clear\n",c->name);
1683 i2o_clear_controller(c);
1685 else
1686 dprintk(KERN_INFO "%s: Reset completed.\n", c->name);
1688 /* Enable other IOPs */
1690 for (iop = i2o_controller_chain; iop; iop = iop->next)
1691 if (iop != c)
1692 i2o_enable_controller(iop);
1694 kfree(status);
1695 return 0;
1700 * i2o_status_get - get the status block for the IOP
1701 * @c: controller
1703 * Issue a status query on the controller. This updates the
1704 * attached status_block. If the controller fails to reply or an
1705 * error occurs then a negative errno code is returned. On success
1706 * zero is returned and the status_blok is updated.
1709 int i2o_status_get(struct i2o_controller *c)
1711 long time;
1712 u32 m;
1713 u32 *msg;
1714 u8 *status_block;
1716 if (c->status_block == NULL)
1718 c->status_block = (i2o_status_block *)
1719 kmalloc(sizeof(i2o_status_block),GFP_KERNEL);
1720 if (c->status_block == NULL)
1722 printk(KERN_CRIT "%s: Get Status Block failed; Out of memory.\n",
1723 c->name);
1724 return -ENOMEM;
1728 status_block = (u8*)c->status_block;
1729 memset(c->status_block,0,sizeof(i2o_status_block));
1731 m=i2o_wait_message(c, "StatusGet");
1732 if(m==0xFFFFFFFF)
1733 return -ETIMEDOUT;
1734 msg=(u32 *)(c->mem_offset+m);
1736 msg[0]=NINE_WORD_MSG_SIZE|SGL_OFFSET_0;
1737 msg[1]=I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID;
1738 msg[2]=core_context;
1739 msg[3]=0;
1740 msg[4]=0;
1741 msg[5]=0;
1742 msg[6]=virt_to_bus(c->status_block);
1743 msg[7]=0; /* 64bit host FIXME */
1744 msg[8]=sizeof(i2o_status_block); /* always 88 bytes */
1746 i2o_post_message(c,m);
1748 /* Wait for a reply */
1750 time=jiffies;
1751 while(status_block[87]!=0xFF)
1753 if((jiffies-time)>=5*HZ)
1755 printk(KERN_ERR "%s: Get status timeout.\n",c->name);
1756 return -ETIMEDOUT;
1758 schedule();
1759 barrier();
1762 #ifdef DRIVERDEBUG
1763 printk(KERN_INFO "%s: State = ", c->name);
1764 switch (c->status_block->iop_state) {
1765 case 0x01:
1766 printk("INIT\n");
1767 break;
1768 case 0x02:
1769 printk("RESET\n");
1770 break;
1771 case 0x04:
1772 printk("HOLD\n");
1773 break;
1774 case 0x05:
1775 printk("READY\n");
1776 break;
1777 case 0x08:
1778 printk("OPERATIONAL\n");
1779 break;
1780 case 0x10:
1781 printk("FAILED\n");
1782 break;
1783 case 0x11:
1784 printk("FAULTED\n");
1785 break;
1786 default:
1787 printk("%x (unknown !!)\n",c->status_block->iop_state);
1789 #endif
1791 return 0;
1795 * Get the Hardware Resource Table for the device.
1796 * The HRT contains information about possible hidden devices
1797 * but is mostly useless to us
1799 int i2o_hrt_get(struct i2o_controller *c)
1801 u32 msg[6];
1802 int ret, size = sizeof(i2o_hrt);
1804 /* Read first just the header to figure out the real size */
1806 do {
1807 if (c->hrt == NULL) {
1808 c->hrt=kmalloc(size, GFP_KERNEL);
1809 if (c->hrt == NULL) {
1810 printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", c->name);
1811 return -ENOMEM;
1815 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
1816 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
1817 msg[3]= 0;
1818 msg[4]= (0xD0000000 | size); /* Simple transaction */
1819 msg[5]= virt_to_bus(c->hrt); /* Dump it here */
1821 if ((ret = i2o_post_wait(c, msg, sizeof(msg), 20))) {
1822 printk(KERN_ERR "%s: Unable to get HRT (status=%#x)\n",
1823 c->name, -ret);
1824 return ret;
1827 if (c->hrt->num_entries * c->hrt->entry_len << 2 > size) {
1828 size = c->hrt->num_entries * c->hrt->entry_len << 2;
1829 kfree(c->hrt);
1830 c->hrt = NULL;
1832 } while (c->hrt == NULL);
1834 i2o_parse_hrt(c); // just for debugging
1836 return 0;
1840 * Send the I2O System Table to the specified IOP
1842 * The system table contains information about all the IOPs in the
1843 * system. It is build and then sent to each IOP so that IOPs can
1844 * establish connections between each other.
1847 static int i2o_systab_send(struct i2o_controller *iop)
1849 u32 msg[12];
1850 u32 privmem[2];
1851 u32 privio[2];
1852 int ret;
1854 privmem[0] = iop->status_block->current_mem_base;
1855 privmem[1] = iop->status_block->current_mem_size;
1856 privio[0] = iop->status_block->current_io_base;
1857 privio[1] = iop->status_block->current_io_size;
1859 msg[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6;
1860 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
1861 msg[3] = 0;
1862 msg[4] = (0<<16) | ((iop->unit+2) << 12); /* Host 0 IOP ID (unit + 2) */
1863 msg[5] = 0; /* Segment 0 */
1866 * Provide three SGL-elements:
1867 * System table (SysTab), Private memory space declaration and
1868 * Private i/o space declaration
1870 msg[6] = 0x54000000 | sys_tbl_len;
1871 msg[7] = virt_to_bus(sys_tbl);
1872 msg[8] = 0x54000000 | 0;
1873 msg[9] = virt_to_bus(privmem);
1874 msg[10] = 0xD4000000 | 0;
1875 msg[11] = virt_to_bus(privio);
1877 if ((ret=i2o_post_wait(iop, msg, sizeof(msg), 120)))
1878 printk(KERN_INFO "%s: Unable to set SysTab (status=%#x).\n",
1879 iop->name, -ret);
1880 else
1881 dprintk(KERN_INFO "%s: SysTab set.\n", iop->name);
1883 i2o_status_get(iop); // Entered READY state
1885 return ret;
1890 * Initialize I2O subsystem.
1892 static void __init i2o_sys_init(void)
1894 struct i2o_controller *iop, *niop = NULL;
1896 printk(KERN_INFO "Activating I2O controllers...\n");
1897 printk(KERN_INFO "This may take a few minutes if there are many devices\n");
1899 /* In INIT state, Activate IOPs */
1900 for (iop = i2o_controller_chain; iop; iop = niop) {
1901 dprintk(KERN_INFO "Calling i2o_activate_controller for %s...\n",
1902 iop->name);
1903 niop = iop->next;
1904 if (i2o_activate_controller(iop) < 0)
1905 i2o_delete_controller(iop);
1908 /* Active IOPs in HOLD state */
1910 rebuild_sys_tab:
1911 if (i2o_controller_chain == NULL)
1912 return;
1915 * If build_sys_table fails, we kill everything and bail
1916 * as we can't init the IOPs w/o a system table
1918 dprintk(KERN_INFO "i2o_core: Calling i2o_build_sys_table...\n");
1919 if (i2o_build_sys_table() < 0) {
1920 i2o_sys_shutdown();
1921 return;
1924 /* If IOP don't get online, we need to rebuild the System table */
1925 for (iop = i2o_controller_chain; iop; iop = niop) {
1926 niop = iop->next;
1927 dprintk(KERN_INFO "Calling i2o_online_controller for %s...\n", iop->name);
1928 if (i2o_online_controller(iop) < 0) {
1929 i2o_delete_controller(iop);
1930 goto rebuild_sys_tab;
1934 /* Active IOPs now in OPERATIONAL state */
1937 * Register for status updates from all IOPs
1939 for(iop = i2o_controller_chain; iop; iop=iop->next) {
1941 /* Create a kernel thread to deal with dynamic LCT updates */
1942 iop->lct_pid = kernel_thread(i2o_dyn_lct, iop, CLONE_SIGHAND);
1944 /* Update change ind on DLCT */
1945 iop->dlct->change_ind = iop->lct->change_ind;
1947 /* Start dynamic LCT updates */
1948 i2o_lct_notify(iop);
1950 /* Register for all events from IRTOS */
1951 i2o_event_register(iop, core_context, 0, 0, 0xFFFFFFFF);
1956 * i2o_sys_shutdown - shutdown I2O system
1958 * Bring down each i2o controller and then return. Each controller
1959 * is taken through an orderly shutdown
1962 static void i2o_sys_shutdown(void)
1964 struct i2o_controller *iop, *niop;
1966 /* Delete all IOPs from the controller chain */
1967 /* that will reset all IOPs too */
1969 for (iop = i2o_controller_chain; iop; iop = niop) {
1970 niop = iop->next;
1971 i2o_delete_controller(iop);
1976 * i2o_activate_controller - bring controller up to HOLD
1977 * @iop: controller
1979 * This function brings an I2O controller into HOLD state. The adapter
1980 * is reset if neccessary and then the queues and resource table
1981 * are read. -1 is returned on a failure, 0 on success.
1985 int i2o_activate_controller(struct i2o_controller *iop)
1987 /* In INIT state, Wait Inbound Q to initialize (in i2o_status_get) */
1988 /* In READY state, Get status */
1990 if (i2o_status_get(iop) < 0) {
1991 printk(KERN_INFO "Unable to obtain status of %s, "
1992 "attempting a reset.\n", iop->name);
1993 if (i2o_reset_controller(iop) < 0)
1994 return -1;
1997 if(iop->status_block->iop_state == ADAPTER_STATE_FAULTED) {
1998 printk(KERN_CRIT "%s: hardware fault\n", iop->name);
1999 return -1;
2002 if (iop->status_block->i2o_version > I2OVER15) {
2003 printk(KERN_ERR "%s: Not running vrs. 1.5. of the I2O Specification.\n",
2004 iop->name);
2005 return -1;
2008 if (iop->status_block->iop_state == ADAPTER_STATE_READY ||
2009 iop->status_block->iop_state == ADAPTER_STATE_OPERATIONAL ||
2010 iop->status_block->iop_state == ADAPTER_STATE_HOLD ||
2011 iop->status_block->iop_state == ADAPTER_STATE_FAILED)
2013 dprintk(KERN_INFO "%s: Already running, trying to reset...\n",
2014 iop->name);
2015 if (i2o_reset_controller(iop) < 0)
2016 return -1;
2019 if (i2o_init_outbound_q(iop) < 0)
2020 return -1;
2022 if (i2o_post_outbound_messages(iop))
2023 return -1;
2025 /* In HOLD state */
2027 if (i2o_hrt_get(iop) < 0)
2028 return -1;
2030 return 0;
2035 * i2o_init_outbound_queue - setup the outbound queue
2036 * @c: controller
2038 * Clear and (re)initialize IOP's outbound queue. Returns 0 on
2039 * success or a negative errno code on a failure.
2042 int i2o_init_outbound_q(struct i2o_controller *c)
2044 u8 *status;
2045 u32 m;
2046 u32 *msg;
2047 u32 time;
2049 dprintk(KERN_INFO "%s: Initializing Outbound Queue...\n", c->name);
2050 m=i2o_wait_message(c, "OutboundInit");
2051 if(m==0xFFFFFFFF)
2052 return -ETIMEDOUT;
2053 msg=(u32 *)(c->mem_offset+m);
2055 status = kmalloc(4,GFP_KERNEL);
2056 if (status==NULL) {
2057 printk(KERN_ERR "%s: Outbound Queue initialization failed - no free memory.\n",
2058 c->name);
2059 return -ENOMEM;
2061 memset(status, 0, 4);
2063 msg[0]= EIGHT_WORD_MSG_SIZE| TRL_OFFSET_6;
2064 msg[1]= I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID;
2065 msg[2]= core_context;
2066 msg[3]= 0x0106; /* Transaction context */
2067 msg[4]= 4096; /* Host page frame size */
2068 /* Frame size is in words. Pick 128, its what everyone elses uses and
2069 other sizes break some adapters. */
2070 msg[5]= MSG_FRAME_SIZE<<16|0x80; /* Outbound msg frame size and Initcode */
2071 msg[6]= 0xD0000004; /* Simple SG LE, EOB */
2072 msg[7]= virt_to_bus(status);
2074 i2o_post_message(c,m);
2076 barrier();
2077 time=jiffies;
2078 while(status[0] < I2O_CMD_REJECTED)
2080 if((jiffies-time)>=30*HZ)
2082 if(status[0]==0x00)
2083 printk(KERN_ERR "%s: Ignored queue initialize request.\n",
2084 c->name);
2085 else
2086 printk(KERN_ERR "%s: Outbound queue initialize timeout.\n",
2087 c->name);
2088 kfree(status);
2089 return -ETIMEDOUT;
2091 schedule();
2092 barrier();
2095 if(status[0] != I2O_CMD_COMPLETED)
2097 printk(KERN_ERR "%s: IOP outbound initialise failed.\n", c->name);
2098 kfree(status);
2099 return -ETIMEDOUT;
2102 return 0;
2106 * i2o_post_outbound_messages - fill message queue
2107 * @c: controller
2109 * Allocate a message frame and load the messages into the IOP. The
2110 * function returns zero on success or a negative errno code on
2111 * failure.
2114 int i2o_post_outbound_messages(struct i2o_controller *c)
2116 int i;
2117 u32 m;
2118 /* Alloc space for IOP's outbound queue message frames */
2120 c->page_frame = kmalloc(MSG_POOL_SIZE, GFP_KERNEL);
2121 if(c->page_frame==NULL) {
2122 printk(KERN_CRIT "%s: Outbound Q initialize failed; out of memory.\n",
2123 c->name);
2124 return -ENOMEM;
2126 m=virt_to_bus(c->page_frame);
2128 /* Post frames */
2130 for(i=0; i< NMBR_MSG_FRAMES; i++) {
2131 I2O_REPLY_WRITE32(c,m);
2132 mb();
2133 m += MSG_FRAME_SIZE;
2136 return 0;
2140 * Get the IOP's Logical Configuration Table
2142 int i2o_lct_get(struct i2o_controller *c)
2144 u32 msg[8];
2145 int ret, size = c->status_block->expected_lct_size;
2147 do {
2148 if (c->lct == NULL) {
2149 c->lct = kmalloc(size, GFP_KERNEL);
2150 if(c->lct == NULL) {
2151 printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n",
2152 c->name);
2153 return -ENOMEM;
2156 memset(c->lct, 0, size);
2158 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
2159 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
2160 /* msg[2] filled in i2o_post_wait */
2161 msg[3] = 0;
2162 msg[4] = 0xFFFFFFFF; /* All devices */
2163 msg[5] = 0x00000000; /* Report now */
2164 msg[6] = 0xD0000000|size;
2165 msg[7] = virt_to_bus(c->lct);
2167 if ((ret=i2o_post_wait(c, msg, sizeof(msg), 120))) {
2168 printk(KERN_ERR "%s: LCT Get failed (status=%#x.\n",
2169 c->name, -ret);
2170 return ret;
2173 if (c->lct->table_size << 2 > size) {
2174 size = c->lct->table_size << 2;
2175 kfree(c->lct);
2176 c->lct = NULL;
2178 } while (c->lct == NULL);
2180 if ((ret=i2o_parse_lct(c)) < 0)
2181 return ret;
2183 return 0;
2187 * Like above, but used for async notification. The main
2188 * difference is that we keep track of the CurrentChangeIndiicator
2189 * so that we only get updates when it actually changes.
2192 int i2o_lct_notify(struct i2o_controller *c)
2194 u32 msg[8];
2196 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
2197 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
2198 msg[2] = core_context;
2199 msg[3] = 0xDEADBEEF;
2200 msg[4] = 0xFFFFFFFF; /* All devices */
2201 msg[5] = c->dlct->change_ind+1; /* Next change */
2202 msg[6] = 0xD0000000|8192;
2203 msg[7] = virt_to_bus(c->dlct);
2205 return i2o_post_this(c, msg, sizeof(msg));
2209 * Bring a controller online into OPERATIONAL state.
2211 int i2o_online_controller(struct i2o_controller *iop)
2213 if (i2o_systab_send(iop) < 0)
2214 return -1;
2216 /* In READY state */
2218 dprintk(KERN_INFO "%s: Attempting to enable...\n", iop->name);
2219 if (i2o_enable_controller(iop) < 0)
2220 return -1;
2222 /* In OPERATIONAL state */
2224 dprintk(KERN_INFO "%s: Attempting to get/parse lct...\n", iop->name);
2225 if (i2o_lct_get(iop) < 0)
2226 return -1;
2228 return 0;
2232 * Build system table
2234 * The system table contains information about all the IOPs in the
2235 * system (duh) and is used by the Executives on the IOPs to establish
2236 * peer2peer connections. We're not supporting peer2peer at the moment,
2237 * but this will be needed down the road for things like lan2lan forwarding.
2239 static int i2o_build_sys_table(void)
2241 struct i2o_controller *iop = NULL;
2242 struct i2o_controller *niop = NULL;
2243 int count = 0;
2245 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs
2246 (i2o_num_controllers) *
2247 sizeof(struct i2o_sys_tbl_entry);
2249 if(sys_tbl)
2250 kfree(sys_tbl);
2252 sys_tbl = kmalloc(sys_tbl_len, GFP_KERNEL);
2253 if(!sys_tbl) {
2254 printk(KERN_CRIT "SysTab Set failed. Out of memory.\n");
2255 return -ENOMEM;
2257 memset((void*)sys_tbl, 0, sys_tbl_len);
2259 sys_tbl->num_entries = i2o_num_controllers;
2260 sys_tbl->version = I2OVERSION; /* TODO: Version 2.0 */
2261 sys_tbl->change_ind = sys_tbl_ind++;
2263 for(iop = i2o_controller_chain; iop; iop = niop)
2265 niop = iop->next;
2268 * Get updated IOP state so we have the latest information
2270 * We should delete the controller at this point if it
2271 * doesn't respond since if it's not on the system table
2272 * it is techninically not part of the I2O subsyßtem...
2274 if(i2o_status_get(iop)) {
2275 printk(KERN_ERR "%s: Deleting b/c could not get status while"
2276 "attempting to build system table\n", iop->name);
2277 i2o_delete_controller(iop);
2278 sys_tbl->num_entries--;
2279 continue; // try the next one
2282 sys_tbl->iops[count].org_id = iop->status_block->org_id;
2283 sys_tbl->iops[count].iop_id = iop->unit + 2;
2284 sys_tbl->iops[count].seg_num = 0;
2285 sys_tbl->iops[count].i2o_version =
2286 iop->status_block->i2o_version;
2287 sys_tbl->iops[count].iop_state =
2288 iop->status_block->iop_state;
2289 sys_tbl->iops[count].msg_type =
2290 iop->status_block->msg_type;
2291 sys_tbl->iops[count].frame_size =
2292 iop->status_block->inbound_frame_size;
2293 sys_tbl->iops[count].last_changed = sys_tbl_ind - 1; // ??
2294 sys_tbl->iops[count].iop_capabilities =
2295 iop->status_block->iop_capabilities;
2296 sys_tbl->iops[count].inbound_low =
2297 (u32)virt_to_bus(iop->post_port);
2298 sys_tbl->iops[count].inbound_high = 0; // TODO: 64-bit support
2300 count++;
2303 #ifdef DRIVERDEBUG
2305 u32 *table;
2306 table = (u32*)sys_tbl;
2307 for(count = 0; count < (sys_tbl_len >>2); count++)
2308 printk(KERN_INFO "sys_tbl[%d] = %0#10x\n", count, table[count]);
2310 #endif
2312 return 0;
2317 * Run time support routines
2321 * Generic "post and forget" helpers. This is less efficient - we do
2322 * a memcpy for example that isnt strictly needed, but for most uses
2323 * this is simply not worth optimising
2326 int i2o_post_this(struct i2o_controller *c, u32 *data, int len)
2328 u32 m;
2329 u32 *msg;
2330 unsigned long t=jiffies;
2334 mb();
2335 m = I2O_POST_READ32(c);
2337 while(m==0xFFFFFFFF && (jiffies-t)<HZ);
2339 if(m==0xFFFFFFFF)
2341 printk(KERN_ERR "%s: Timeout waiting for message frame!\n",
2342 c->name);
2343 return -ETIMEDOUT;
2345 msg = (u32 *)(c->mem_offset + m);
2346 memcpy_toio(msg, data, len);
2347 i2o_post_message(c,m);
2348 return 0;
2352 * This core API allows an OSM to post a message and then be told whether
2353 * or not the system received a successful reply. It is useful when
2354 * the OSM does not want to know the exact 3
2356 int i2o_post_wait(struct i2o_controller *c, u32 *msg, int len, int timeout)
2358 DECLARE_WAIT_QUEUE_HEAD(wq_i2o_post);
2359 int status = 0;
2360 int flags = 0;
2361 struct i2o_post_wait_data *p1, *p2;
2362 struct i2o_post_wait_data *wait_data =
2363 kmalloc(sizeof(struct i2o_post_wait_data), GFP_KERNEL);
2365 if(!wait_data)
2366 return -ENOMEM;
2369 * The spin locking is needed to keep anyone from playing
2370 * with the queue pointers and id while we do the same
2372 spin_lock_irqsave(&post_wait_lock, flags);
2373 wait_data->next = post_wait_queue;
2374 post_wait_queue = wait_data;
2375 wait_data->id = (++post_wait_id) & 0x7fff;
2376 spin_unlock_irqrestore(&post_wait_lock, flags);
2378 wait_data->wq = &wq_i2o_post;
2379 wait_data->status = -ETIMEDOUT;
2381 msg[2] = 0x80000000|(u32)core_context|((u32)wait_data->id<<16);
2383 if ((status = i2o_post_this(c, msg, len))==0) {
2384 interruptible_sleep_on_timeout(&wq_i2o_post, HZ * timeout);
2385 status = wait_data->status;
2388 #ifdef DRIVERDEBUG
2389 if(status == -ETIMEDOUT)
2390 printk(KERN_INFO "%s: POST WAIT TIMEOUT\n",c->name);
2391 #endif
2394 * Remove the entry from the queue.
2395 * Since i2o_post_wait() may have been called again by
2396 * a different thread while we were waiting for this
2397 * instance to complete, we're not guaranteed that
2398 * this entry is at the head of the queue anymore, so
2399 * we need to search for it, find it, and delete it.
2401 p2 = NULL;
2402 spin_lock_irqsave(&post_wait_lock, flags);
2403 for(p1 = post_wait_queue; p1; p2 = p1, p1 = p1->next) {
2404 if(p1 == wait_data) {
2405 if(p2)
2406 p2->next = p1->next;
2407 else
2408 post_wait_queue = p1->next;
2410 break;
2413 spin_unlock_irqrestore(&post_wait_lock, flags);
2415 kfree(wait_data);
2417 return status;
2421 * i2o_post_wait is completed and we want to wake up the
2422 * sleeping proccess. Called by core's reply handler.
2424 static void i2o_post_wait_complete(u32 context, int status)
2426 struct i2o_post_wait_data *p1 = NULL;
2429 * We need to search through the post_wait
2430 * queue to see if the given message is still
2431 * outstanding. If not, it means that the IOP
2432 * took longer to respond to the message than we
2433 * had allowed and timer has already expired.
2434 * Not much we can do about that except log
2435 * it for debug purposes, increase timeout, and recompile
2437 * Lock needed to keep anyone from moving queue pointers
2438 * around while we're looking through them.
2440 spin_lock(&post_wait_lock);
2441 for(p1 = post_wait_queue; p1; p1 = p1->next) {
2442 if(p1->id == ((context >> 16) & 0x7fff)) {
2443 p1->status = status;
2444 wake_up_interruptible(p1->wq);
2445 spin_unlock(&post_wait_lock);
2446 return;
2449 spin_unlock(&post_wait_lock);
2451 printk(KERN_DEBUG "i2o_post_wait reply after timeout!\n");
2454 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
2456 * This function can be used for all UtilParamsGet/Set operations.
2457 * The OperationList is given in oplist-buffer,
2458 * and results are returned in reslist-buffer.
2459 * Note that the minimum sized reslist is 8 bytes and contains
2460 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
2462 int i2o_issue_params(int cmd, struct i2o_controller *iop, int tid,
2463 void *oplist, int oplen, void *reslist, int reslen)
2465 u32 msg[9];
2466 u8 *res = (u8 *)reslist;
2467 u32 *res32 = (u32*)reslist;
2468 u32 *restmp = (u32*)reslist;
2469 int len = 0;
2470 int i = 0;
2471 int wait_status;
2473 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
2474 msg[1] = cmd << 24 | HOST_TID << 12 | tid;
2475 msg[3] = 0;
2476 msg[4] = 0;
2477 msg[5] = 0x54000000 | oplen; /* OperationList */
2478 msg[6] = virt_to_bus(oplist);
2479 msg[7] = 0xD0000000 | reslen; /* ResultList */
2480 msg[8] = virt_to_bus(reslist);
2482 if((wait_status = i2o_post_wait(iop, msg, sizeof(msg), 10)))
2483 return wait_status; /* -DetailedStatus */
2486 * Calculate number of bytes of Result LIST
2487 * We need to loop through each Result BLOCK and grab the length
2489 restmp = res32 + 1;
2490 len = 1;
2491 for(i = 0; i < (res32[0]&0X0000FFFF); i++)
2493 if(restmp[0]&0x00FF0000) /* BlockStatus != SUCCESS */
2495 printk(KERN_WARNING "%s - Error:\n ErrorInfoSize = 0x%02x, "
2496 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
2497 (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET"
2498 : "PARAMS_GET",
2499 res32[1]>>24, (res32[1]>>16)&0xFF, res32[1]&0xFFFF);
2502 * If this is the only request,than we return an error
2504 if((res32[0]&0x0000FFFF) == 1)
2505 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
2508 len += restmp[0] & 0x0000FFFF; /* Length of res BLOCK */
2509 restmp += restmp[0] & 0x0000FFFF; /* Skip to next BLOCK */
2512 return (len << 2); /* bytes used by result list */
2516 * Query one scalar group value or a whole scalar group.
2518 int i2o_query_scalar(struct i2o_controller *iop, int tid,
2519 int group, int field, void *buf, int buflen)
2521 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
2522 u8 resblk[8+buflen]; /* 8 bytes for header */
2523 int size;
2525 if (field == -1) /* whole group */
2526 opblk[4] = -1;
2528 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, iop, tid,
2529 opblk, sizeof(opblk), resblk, sizeof(resblk));
2531 if (size < 0)
2532 return size;
2534 memcpy(buf, resblk+8, buflen); /* cut off header */
2535 return size;
2539 * Set a scalar group value or a whole group.
2541 int i2o_set_scalar(struct i2o_controller *iop, int tid,
2542 int group, int field, void *buf, int buflen)
2544 u16 *opblk;
2545 u8 resblk[8+buflen]; /* 8 bytes for header */
2546 int size;
2548 opblk = kmalloc(buflen+64, GFP_KERNEL);
2549 if (opblk == NULL)
2551 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
2552 return -ENOMEM;
2555 opblk[0] = 1; /* operation count */
2556 opblk[1] = 0; /* pad */
2557 opblk[2] = I2O_PARAMS_FIELD_SET;
2558 opblk[3] = group;
2560 if(field == -1) { /* whole group */
2561 opblk[4] = -1;
2562 memcpy(opblk+5, buf, buflen);
2564 else /* single field */
2566 opblk[4] = 1;
2567 opblk[5] = field;
2568 memcpy(opblk+6, buf, buflen);
2571 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid,
2572 opblk, 12+buflen, resblk, sizeof(resblk));
2574 kfree(opblk);
2575 return size;
2579 * if oper == I2O_PARAMS_TABLE_GET, get from all rows
2580 * if fieldcount == -1 return all fields
2581 * ibuf and ibuflen are unused (use NULL, 0)
2582 * else return specific fields
2583 * ibuf contains fieldindexes
2585 * if oper == I2O_PARAMS_LIST_GET, get from specific rows
2586 * if fieldcount == -1 return all fields
2587 * ibuf contains rowcount, keyvalues
2588 * else return specific fields
2589 * fieldcount is # of fieldindexes
2590 * ibuf contains fieldindexes, rowcount, keyvalues
2592 * You could also use directly function i2o_issue_params().
2594 int i2o_query_table(int oper, struct i2o_controller *iop, int tid, int group,
2595 int fieldcount, void *ibuf, int ibuflen,
2596 void *resblk, int reslen)
2598 u16 *opblk;
2599 int size;
2601 opblk = kmalloc(10 + ibuflen, GFP_KERNEL);
2602 if (opblk == NULL)
2604 printk(KERN_ERR "i2o: no memory for query buffer.\n");
2605 return -ENOMEM;
2608 opblk[0] = 1; /* operation count */
2609 opblk[1] = 0; /* pad */
2610 opblk[2] = oper;
2611 opblk[3] = group;
2612 opblk[4] = fieldcount;
2613 memcpy(opblk+5, ibuf, ibuflen); /* other params */
2615 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET,iop, tid,
2616 opblk, 10+ibuflen, resblk, reslen);
2618 kfree(opblk);
2619 return size;
2623 * Clear table group, i.e. delete all rows.
2625 int i2o_clear_table(struct i2o_controller *iop, int tid, int group)
2627 u16 opblk[] = { 1, 0, I2O_PARAMS_TABLE_CLEAR, group };
2628 u8 resblk[32]; /* min 8 bytes for result header */
2630 return i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid,
2631 opblk, sizeof(opblk), resblk, sizeof(resblk));
2635 * Add a new row into a table group.
2637 * if fieldcount==-1 then we add whole rows
2638 * buf contains rowcount, keyvalues
2639 * else just specific fields are given, rest use defaults
2640 * buf contains fieldindexes, rowcount, keyvalues
2642 int i2o_row_add_table(struct i2o_controller *iop, int tid,
2643 int group, int fieldcount, void *buf, int buflen)
2645 u16 *opblk;
2646 u8 resblk[32]; /* min 8 bytes for header */
2647 int size;
2649 opblk = kmalloc(buflen+64, GFP_KERNEL);
2650 if (opblk == NULL)
2652 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
2653 return -ENOMEM;
2656 opblk[0] = 1; /* operation count */
2657 opblk[1] = 0; /* pad */
2658 opblk[2] = I2O_PARAMS_ROW_ADD;
2659 opblk[3] = group;
2660 opblk[4] = fieldcount;
2661 memcpy(opblk+5, buf, buflen);
2663 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid,
2664 opblk, 10+buflen, resblk, sizeof(resblk));
2666 kfree(opblk);
2667 return size;
2672 * Used for error reporting/debugging purposes.
2673 * Following fail status are common to all classes.
2674 * The preserved message must be handled in the reply handler.
2676 void i2o_report_fail_status(u8 req_status, u32* msg)
2678 static char *FAIL_STATUS[] = {
2679 "0x80", /* not used */
2680 "SERVICE_SUSPENDED", /* 0x81 */
2681 "SERVICE_TERMINATED", /* 0x82 */
2682 "CONGESTION",
2683 "FAILURE",
2684 "STATE_ERROR",
2685 "TIME_OUT",
2686 "ROUTING_FAILURE",
2687 "INVALID_VERSION",
2688 "INVALID_OFFSET",
2689 "INVALID_MSG_FLAGS",
2690 "FRAME_TOO_SMALL",
2691 "FRAME_TOO_LARGE",
2692 "INVALID_TARGET_ID",
2693 "INVALID_INITIATOR_ID",
2694 "INVALID_INITIATOR_CONTEX", /* 0x8F */
2695 "UNKNOWN_FAILURE" /* 0xFF */
2698 if (req_status == I2O_FSC_TRANSPORT_UNKNOWN_FAILURE)
2699 printk("TRANSPORT_UNKNOWN_FAILURE (%0#2x)\n.", req_status);
2700 else
2701 printk("TRANSPORT_%s.\n", FAIL_STATUS[req_status & 0x0F]);
2703 /* Dump some details */
2705 printk(KERN_ERR " InitiatorId = %d, TargetId = %d\n",
2706 (msg[1] >> 12) & 0xFFF, msg[1] & 0xFFF);
2707 printk(KERN_ERR " LowestVersion = 0x%02X, HighestVersion = 0x%02X\n",
2708 (msg[4] >> 8) & 0xFF, msg[4] & 0xFF);
2709 printk(KERN_ERR " FailingHostUnit = 0x%04X, FailingIOP = 0x%03X\n",
2710 msg[5] >> 16, msg[5] & 0xFFF);
2712 printk(KERN_ERR " Severity: 0x%02X ", (msg[4] >> 16) & 0xFF);
2713 if (msg[4] & (1<<16))
2714 printk("(FormatError), "
2715 "this msg can never be delivered/processed.\n");
2716 if (msg[4] & (1<<17))
2717 printk("(PathError), "
2718 "this msg can no longer be delivered/processed.\n");
2719 if (msg[4] & (1<<18))
2720 printk("(PathState), "
2721 "the system state does not allow delivery.\n");
2722 if (msg[4] & (1<<19))
2723 printk("(Congestion), resources temporarily not available;"
2724 "do not retry immediately.\n");
2728 * Used for error reporting/debugging purposes.
2729 * Following reply status are common to all classes.
2731 void i2o_report_common_status(u8 req_status)
2733 static char *REPLY_STATUS[] = {
2734 "SUCCESS",
2735 "ABORT_DIRTY",
2736 "ABORT_NO_DATA_TRANSFER",
2737 "ABORT_PARTIAL_TRANSFER",
2738 "ERROR_DIRTY",
2739 "ERROR_NO_DATA_TRANSFER",
2740 "ERROR_PARTIAL_TRANSFER",
2741 "PROCESS_ABORT_DIRTY",
2742 "PROCESS_ABORT_NO_DATA_TRANSFER",
2743 "PROCESS_ABORT_PARTIAL_TRANSFER",
2744 "TRANSACTION_ERROR",
2745 "PROGRESS_REPORT"
2748 if (req_status > I2O_REPLY_STATUS_PROGRESS_REPORT)
2749 printk("RequestStatus = %0#2x", req_status);
2750 else
2751 printk("%s", REPLY_STATUS[req_status]);
2755 * Used for error reporting/debugging purposes.
2756 * Following detailed status are valid for executive class,
2757 * utility class, DDM class and for transaction error replies.
2759 static void i2o_report_common_dsc(u16 detailed_status)
2761 static char *COMMON_DSC[] = {
2762 "SUCCESS",
2763 "0x01", // not used
2764 "BAD_KEY",
2765 "TCL_ERROR",
2766 "REPLY_BUFFER_FULL",
2767 "NO_SUCH_PAGE",
2768 "INSUFFICIENT_RESOURCE_SOFT",
2769 "INSUFFICIENT_RESOURCE_HARD",
2770 "0x08", // not used
2771 "CHAIN_BUFFER_TOO_LARGE",
2772 "UNSUPPORTED_FUNCTION",
2773 "DEVICE_LOCKED",
2774 "DEVICE_RESET",
2775 "INAPPROPRIATE_FUNCTION",
2776 "INVALID_INITIATOR_ADDRESS",
2777 "INVALID_MESSAGE_FLAGS",
2778 "INVALID_OFFSET",
2779 "INVALID_PARAMETER",
2780 "INVALID_REQUEST",
2781 "INVALID_TARGET_ADDRESS",
2782 "MESSAGE_TOO_LARGE",
2783 "MESSAGE_TOO_SMALL",
2784 "MISSING_PARAMETER",
2785 "TIMEOUT",
2786 "UNKNOWN_ERROR",
2787 "UNKNOWN_FUNCTION",
2788 "UNSUPPORTED_VERSION",
2789 "DEVICE_BUSY",
2790 "DEVICE_NOT_AVAILABLE"
2793 if (detailed_status > I2O_DSC_DEVICE_NOT_AVAILABLE)
2794 printk(" / DetailedStatus = %0#4x.\n", detailed_status);
2795 else
2796 printk(" / %s.\n", COMMON_DSC[detailed_status]);
2800 * Used for error reporting/debugging purposes
2802 static void i2o_report_lan_dsc(u16 detailed_status)
2804 static char *LAN_DSC[] = { // Lan detailed status code strings
2805 "SUCCESS",
2806 "DEVICE_FAILURE",
2807 "DESTINATION_NOT_FOUND",
2808 "TRANSMIT_ERROR",
2809 "TRANSMIT_ABORTED",
2810 "RECEIVE_ERROR",
2811 "RECEIVE_ABORTED",
2812 "DMA_ERROR",
2813 "BAD_PACKET_DETECTED",
2814 "OUT_OF_MEMORY",
2815 "BUCKET_OVERRUN",
2816 "IOP_INTERNAL_ERROR",
2817 "CANCELED",
2818 "INVALID_TRANSACTION_CONTEXT",
2819 "DEST_ADDRESS_DETECTED",
2820 "DEST_ADDRESS_OMITTED",
2821 "PARTIAL_PACKET_RETURNED",
2822 "TEMP_SUSPENDED_STATE", // last Lan detailed status code
2823 "INVALID_REQUEST" // general detailed status code
2826 if (detailed_status > I2O_DSC_INVALID_REQUEST)
2827 printk(" / %0#4x.\n", detailed_status);
2828 else
2829 printk(" / %s.\n", LAN_DSC[detailed_status]);
2833 * Used for error reporting/debugging purposes
2835 static void i2o_report_util_cmd(u8 cmd)
2837 switch (cmd) {
2838 case I2O_CMD_UTIL_NOP:
2839 printk("UTIL_NOP, ");
2840 break;
2841 case I2O_CMD_UTIL_ABORT:
2842 printk("UTIL_ABORT, ");
2843 break;
2844 case I2O_CMD_UTIL_CLAIM:
2845 printk("UTIL_CLAIM, ");
2846 break;
2847 case I2O_CMD_UTIL_RELEASE:
2848 printk("UTIL_CLAIM_RELEASE, ");
2849 break;
2850 case I2O_CMD_UTIL_CONFIG_DIALOG:
2851 printk("UTIL_CONFIG_DIALOG, ");
2852 break;
2853 case I2O_CMD_UTIL_DEVICE_RESERVE:
2854 printk("UTIL_DEVICE_RESERVE, ");
2855 break;
2856 case I2O_CMD_UTIL_DEVICE_RELEASE:
2857 printk("UTIL_DEVICE_RELEASE, ");
2858 break;
2859 case I2O_CMD_UTIL_EVT_ACK:
2860 printk("UTIL_EVENT_ACKNOWLEDGE, ");
2861 break;
2862 case I2O_CMD_UTIL_EVT_REGISTER:
2863 printk("UTIL_EVENT_REGISTER, ");
2864 break;
2865 case I2O_CMD_UTIL_LOCK:
2866 printk("UTIL_LOCK, ");
2867 break;
2868 case I2O_CMD_UTIL_LOCK_RELEASE:
2869 printk("UTIL_LOCK_RELEASE, ");
2870 break;
2871 case I2O_CMD_UTIL_PARAMS_GET:
2872 printk("UTIL_PARAMS_GET, ");
2873 break;
2874 case I2O_CMD_UTIL_PARAMS_SET:
2875 printk("UTIL_PARAMS_SET, ");
2876 break;
2877 case I2O_CMD_UTIL_REPLY_FAULT_NOTIFY:
2878 printk("UTIL_REPLY_FAULT_NOTIFY, ");
2879 break;
2880 default:
2881 printk("Cmd = %0#2x, ",cmd);
2886 * Used for error reporting/debugging purposes
2888 static void i2o_report_exec_cmd(u8 cmd)
2890 switch (cmd) {
2891 case I2O_CMD_ADAPTER_ASSIGN:
2892 printk("EXEC_ADAPTER_ASSIGN, ");
2893 break;
2894 case I2O_CMD_ADAPTER_READ:
2895 printk("EXEC_ADAPTER_READ, ");
2896 break;
2897 case I2O_CMD_ADAPTER_RELEASE:
2898 printk("EXEC_ADAPTER_RELEASE, ");
2899 break;
2900 case I2O_CMD_BIOS_INFO_SET:
2901 printk("EXEC_BIOS_INFO_SET, ");
2902 break;
2903 case I2O_CMD_BOOT_DEVICE_SET:
2904 printk("EXEC_BOOT_DEVICE_SET, ");
2905 break;
2906 case I2O_CMD_CONFIG_VALIDATE:
2907 printk("EXEC_CONFIG_VALIDATE, ");
2908 break;
2909 case I2O_CMD_CONN_SETUP:
2910 printk("EXEC_CONN_SETUP, ");
2911 break;
2912 case I2O_CMD_DDM_DESTROY:
2913 printk("EXEC_DDM_DESTROY, ");
2914 break;
2915 case I2O_CMD_DDM_ENABLE:
2916 printk("EXEC_DDM_ENABLE, ");
2917 break;
2918 case I2O_CMD_DDM_QUIESCE:
2919 printk("EXEC_DDM_QUIESCE, ");
2920 break;
2921 case I2O_CMD_DDM_RESET:
2922 printk("EXEC_DDM_RESET, ");
2923 break;
2924 case I2O_CMD_DDM_SUSPEND:
2925 printk("EXEC_DDM_SUSPEND, ");
2926 break;
2927 case I2O_CMD_DEVICE_ASSIGN:
2928 printk("EXEC_DEVICE_ASSIGN, ");
2929 break;
2930 case I2O_CMD_DEVICE_RELEASE:
2931 printk("EXEC_DEVICE_RELEASE, ");
2932 break;
2933 case I2O_CMD_HRT_GET:
2934 printk("EXEC_HRT_GET, ");
2935 break;
2936 case I2O_CMD_ADAPTER_CLEAR:
2937 printk("EXEC_IOP_CLEAR, ");
2938 break;
2939 case I2O_CMD_ADAPTER_CONNECT:
2940 printk("EXEC_IOP_CONNECT, ");
2941 break;
2942 case I2O_CMD_ADAPTER_RESET:
2943 printk("EXEC_IOP_RESET, ");
2944 break;
2945 case I2O_CMD_LCT_NOTIFY:
2946 printk("EXEC_LCT_NOTIFY, ");
2947 break;
2948 case I2O_CMD_OUTBOUND_INIT:
2949 printk("EXEC_OUTBOUND_INIT, ");
2950 break;
2951 case I2O_CMD_PATH_ENABLE:
2952 printk("EXEC_PATH_ENABLE, ");
2953 break;
2954 case I2O_CMD_PATH_QUIESCE:
2955 printk("EXEC_PATH_QUIESCE, ");
2956 break;
2957 case I2O_CMD_PATH_RESET:
2958 printk("EXEC_PATH_RESET, ");
2959 break;
2960 case I2O_CMD_STATIC_MF_CREATE:
2961 printk("EXEC_STATIC_MF_CREATE, ");
2962 break;
2963 case I2O_CMD_STATIC_MF_RELEASE:
2964 printk("EXEC_STATIC_MF_RELEASE, ");
2965 break;
2966 case I2O_CMD_STATUS_GET:
2967 printk("EXEC_STATUS_GET, ");
2968 break;
2969 case I2O_CMD_SW_DOWNLOAD:
2970 printk("EXEC_SW_DOWNLOAD, ");
2971 break;
2972 case I2O_CMD_SW_UPLOAD:
2973 printk("EXEC_SW_UPLOAD, ");
2974 break;
2975 case I2O_CMD_SW_REMOVE:
2976 printk("EXEC_SW_REMOVE, ");
2977 break;
2978 case I2O_CMD_SYS_ENABLE:
2979 printk("EXEC_SYS_ENABLE, ");
2980 break;
2981 case I2O_CMD_SYS_MODIFY:
2982 printk("EXEC_SYS_MODIFY, ");
2983 break;
2984 case I2O_CMD_SYS_QUIESCE:
2985 printk("EXEC_SYS_QUIESCE, ");
2986 break;
2987 case I2O_CMD_SYS_TAB_SET:
2988 printk("EXEC_SYS_TAB_SET, ");
2989 break;
2990 default:
2991 printk("Cmd = %#02x, ",cmd);
2996 * Used for error reporting/debugging purposes
2998 static void i2o_report_lan_cmd(u8 cmd)
3000 switch (cmd) {
3001 case LAN_PACKET_SEND:
3002 printk("LAN_PACKET_SEND, ");
3003 break;
3004 case LAN_SDU_SEND:
3005 printk("LAN_SDU_SEND, ");
3006 break;
3007 case LAN_RECEIVE_POST:
3008 printk("LAN_RECEIVE_POST, ");
3009 break;
3010 case LAN_RESET:
3011 printk("LAN_RESET, ");
3012 break;
3013 case LAN_SUSPEND:
3014 printk("LAN_SUSPEND, ");
3015 break;
3016 default:
3017 printk("Cmd = %0#2x, ",cmd);
3022 * Used for error reporting/debugging purposes.
3023 * Report Cmd name, Request status, Detailed Status.
3025 void i2o_report_status(const char *severity, const char *str, u32 *msg)
3027 u8 cmd = (msg[1]>>24)&0xFF;
3028 u8 req_status = (msg[4]>>24)&0xFF;
3029 u16 detailed_status = msg[4]&0xFFFF;
3030 struct i2o_handler *h = i2o_handlers[msg[2] & (MAX_I2O_MODULES-1)];
3032 printk("%s%s: ", severity, str);
3034 if (cmd < 0x1F) // Utility cmd
3035 i2o_report_util_cmd(cmd);
3037 else if (cmd >= 0xA0 && cmd <= 0xEF) // Executive cmd
3038 i2o_report_exec_cmd(cmd);
3040 else if (h->class == I2O_CLASS_LAN && cmd >= 0x30 && cmd <= 0x3F)
3041 i2o_report_lan_cmd(cmd); // LAN cmd
3042 else
3043 printk("Cmd = %0#2x, ", cmd); // Other cmds
3045 if (msg[0] & MSG_FAIL) {
3046 i2o_report_fail_status(req_status, msg);
3047 return;
3050 i2o_report_common_status(req_status);
3052 if (cmd < 0x1F || (cmd >= 0xA0 && cmd <= 0xEF))
3053 i2o_report_common_dsc(detailed_status);
3054 else if (h->class == I2O_CLASS_LAN && cmd >= 0x30 && cmd <= 0x3F)
3055 i2o_report_lan_dsc(detailed_status);
3056 else
3057 printk(" / DetailedStatus = %0#4x.\n", detailed_status);
3060 /* Used to dump a message to syslog during debugging */
3061 void i2o_dump_message(u32 *msg)
3063 #ifdef DRIVERDEBUG
3064 int i;
3065 printk(KERN_INFO "Dumping I2O message size %d @ %p\n",
3066 msg[0]>>16&0xffff, msg);
3067 for(i = 0; i < ((msg[0]>>16)&0xffff); i++)
3068 printk(KERN_INFO " msg[%d] = %0#10x\n", i, msg[i]);
3069 #endif
3073 * I2O reboot/shutdown notification.
3075 * - Call each OSM's reboot notifier (if one exists)
3076 * - Quiesce each IOP in the system
3078 * Each IOP has to be quiesced before we can ensure that the system
3079 * can be properly shutdown as a transaction that has already been
3080 * acknowledged still needs to be placed in permanent store on the IOP.
3081 * The SysQuiesce causes the IOP to force all HDMs to complete their
3082 * transactions before returning, so only at that point is it safe
3085 static int i2o_reboot_event(struct notifier_block *n, unsigned long code, void
3088 int i = 0;
3089 struct i2o_controller *c = NULL;
3091 if(code != SYS_RESTART && code != SYS_HALT && code != SYS_POWER_OFF)
3092 return NOTIFY_DONE;
3094 printk(KERN_INFO "Shutting down I2O system.\n");
3095 printk(KERN_INFO
3096 " This could take a few minutes if there are many devices attached\n");
3098 for(i = 0; i < MAX_I2O_MODULES; i++)
3100 if(i2o_handlers[i] && i2o_handlers[i]->reboot_notify)
3101 i2o_handlers[i]->reboot_notify();
3104 for(c = i2o_controller_chain; c; c = c->next)
3106 if(i2o_quiesce_controller(c))
3108 printk(KERN_WARNING "i2o: Could not quiesce %s." "
3109 Verify setup on next system power up.\n", c->name);
3113 printk(KERN_INFO "I2O system down.\n");
3114 return NOTIFY_DONE;
3118 #ifdef MODULE
3120 EXPORT_SYMBOL(i2o_controller_chain);
3121 EXPORT_SYMBOL(i2o_num_controllers);
3122 EXPORT_SYMBOL(i2o_find_controller);
3123 EXPORT_SYMBOL(i2o_unlock_controller);
3124 EXPORT_SYMBOL(i2o_status_get);
3126 EXPORT_SYMBOL(i2o_install_handler);
3127 EXPORT_SYMBOL(i2o_remove_handler);
3129 EXPORT_SYMBOL(i2o_claim_device);
3130 EXPORT_SYMBOL(i2o_release_device);
3131 EXPORT_SYMBOL(i2o_device_notify_on);
3132 EXPORT_SYMBOL(i2o_device_notify_off);
3134 EXPORT_SYMBOL(i2o_post_this);
3135 EXPORT_SYMBOL(i2o_post_wait);
3137 EXPORT_SYMBOL(i2o_query_scalar);
3138 EXPORT_SYMBOL(i2o_set_scalar);
3139 EXPORT_SYMBOL(i2o_query_table);
3140 EXPORT_SYMBOL(i2o_clear_table);
3141 EXPORT_SYMBOL(i2o_row_add_table);
3142 EXPORT_SYMBOL(i2o_issue_params);
3144 EXPORT_SYMBOL(i2o_event_register);
3145 EXPORT_SYMBOL(i2o_event_ack);
3147 EXPORT_SYMBOL(i2o_report_status);
3148 EXPORT_SYMBOL(i2o_dump_message);
3150 EXPORT_SYMBOL(i2o_get_class_name);
3152 MODULE_AUTHOR("Red Hat Software");
3153 MODULE_DESCRIPTION("I2O Core");
3156 int init_module(void)
3158 printk(KERN_INFO "I2O Core - (C) Copyright 1999 Red Hat Software\n");
3159 if (i2o_install_handler(&i2o_core_handler) < 0)
3161 printk(KERN_ERR
3162 "i2o_core: Unable to install core handler.\nI2O stack not loaded!");
3163 return 0;
3166 core_context = i2o_core_handler.context;
3169 * Attach core to I2O PCI transport (and others as they are developed)
3171 #ifdef CONFIG_I2O_PCI_MODULE
3172 if(i2o_pci_core_attach(&i2o_core_functions) < 0)
3173 printk(KERN_INFO "i2o: No PCI I2O controllers found\n");
3174 #endif
3177 * Initialize event handling thread
3179 init_MUTEX_LOCKED(&evt_sem);
3180 evt_pid = kernel_thread(i2o_core_evt, &evt_reply, CLONE_SIGHAND);
3181 if(evt_pid < 0)
3183 printk(KERN_ERR "I2O: Could not create event handler kernel thread\n");
3184 i2o_remove_handler(&i2o_core_handler);
3185 return 0;
3187 else
3188 printk(KERN_INFO "I2O: Event thread created as pid %d\n", evt_pid);
3190 if(i2o_num_controllers)
3191 i2o_sys_init();
3193 register_reboot_notifier(&i2o_reboot_notifier);
3195 return 0;
3198 void cleanup_module(void)
3200 int stat;
3202 unregister_reboot_notifier(&i2o_reboot_notifier);
3204 if(i2o_num_controllers)
3205 i2o_sys_shutdown();
3208 * If this is shutdown time, the thread has already been killed
3210 if(evt_running) {
3211 stat = kill_proc(evt_pid, SIGTERM, 1);
3212 if(!stat) {
3213 int count = 10 * 100;
3214 while(evt_running && count--) {
3215 current->state = TASK_INTERRUPTIBLE;
3216 schedule_timeout(1);
3219 if(!count)
3220 printk(KERN_ERR "i2o: Event thread still running!\n");
3224 #ifdef CONFIG_I2O_PCI_MODULE
3225 i2o_pci_core_detach();
3226 #endif
3228 i2o_remove_handler(&i2o_core_handler);
3230 unregister_reboot_notifier(&i2o_reboot_notifier);
3233 #else
3235 extern int i2o_block_init(void);
3236 extern int i2o_config_init(void);
3237 extern int i2o_lan_init(void);
3238 extern int i2o_pci_init(void);
3239 extern int i2o_proc_init(void);
3240 extern int i2o_scsi_init(void);
3242 int __init i2o_init(void)
3244 printk(KERN_INFO "Loading I2O Core - (c) Copyright 1999 Red Hat Software\n");
3246 if (i2o_install_handler(&i2o_core_handler) < 0)
3248 printk(KERN_ERR
3249 "i2o_core: Unable to install core handler.\nI2O stack not loaded!");
3250 return 0;
3253 core_context = i2o_core_handler.context;
3256 * Initialize event handling thread
3257 * We may not find any controllers, but still want this as
3258 * down the road we may have hot pluggable controllers that
3259 * need to be dealt with.
3261 init_MUTEX_LOCKED(&evt_sem);
3262 if((evt_pid = kernel_thread(i2o_core_evt, &evt_reply, CLONE_SIGHAND)) < 0)
3264 printk(KERN_ERR "I2O: Could not create event handler kernel thread\n");
3265 i2o_remove_handler(&i2o_core_handler);
3266 return 0;
3270 #ifdef CONFIG_I2O_PCI
3271 i2o_pci_init();
3272 #endif
3274 if(i2o_num_controllers)
3275 i2o_sys_init();
3277 register_reboot_notifier(&i2o_reboot_notifier);
3279 i2o_config_init();
3280 #ifdef CONFIG_I2O_BLOCK
3281 i2o_block_init();
3282 #endif
3283 #ifdef CONFIG_I2O_LAN
3284 i2o_lan_init();
3285 #endif
3286 #ifdef CONFIG_I2O_PROC
3287 i2o_proc_init();
3288 #endif
3289 return 0;
3292 #endif