2 * Core I2O structure managment
4 * (C) Copyright 1999 Red Hat Software
6 * Written by Alan Cox, Building Number Three Ltd
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
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>
48 #include <linux/reboot.h>
52 // #define DRIVERDEBUG
55 #define dprintk(s, args...) printk(s, ## args)
57 #define dprintk(s, args...)
61 static struct i2o_handler
*i2o_handlers
[MAX_I2O_MODULES
] = {NULL
};
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
*);
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 *);
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
;
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
,
132 i2o_unlock_controller
,
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 */
145 * Structures and definitions for synchronous message posting.
146 * See i2o_post_wait() for description.
148 struct i2o_post_wait_data
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
,
174 * Used when queing a reply to be handled later
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
205 DECLARE_MUTEX(evt_sem
);
206 DECLARE_WAIT_QUEUE_HEAD(evt_wait
);
208 static struct notifier_block i2o_reboot_notifier
=
217 * I2O Core reply handler
219 static void i2o_core_reply(struct i2o_handler
*h
, struct i2o_controller
*c
,
220 struct i2o_message
*m
)
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 */
249 i2o_report_status(KERN_INFO
, "i2o_core", msg
);
252 if(msg
[2]&0x80000000) // Post wait message
255 status
= -(msg
[4] & 0xFFFF);
257 status
= I2O_POST_WAIT_OK
;
259 i2o_post_wait_complete(context
, status
);
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
);
274 spin_unlock(&i2o_evt_lock
);
277 wake_up_interruptible(&evt_wait
);
281 if(m
->function
== I2O_CMD_LCT_NOTIFY
)
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",
296 i2o_dump_message(msg
);
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
313 int i2o_install_handler(struct i2o_handler
*h
)
316 down(&i2o_configuration_lock
);
317 for(i
=0;i
<MAX_I2O_MODULES
;i
++)
319 if(i2o_handlers
[i
]==NULL
)
323 up(&i2o_configuration_lock
);
327 up(&i2o_configuration_lock
);
332 * i2o_remove_handler - remove an i2o message 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
;
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
353 * i2o_install_device - attach a device to a controller
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
364 int i2o_install_device(struct i2o_controller
*c
, struct i2o_device
*d
)
368 down(&i2o_configuration_lock
);
375 for(i
= 0; i
< I2O_MAX_MANAGERS
; i
++)
376 d
->managers
[i
] = NULL
;
378 up(&i2o_configuration_lock
);
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
;
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
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
);
407 "Driver \"%s\" did not release device!\n", d
->owner
->name
);
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
);
438 printk(KERN_ERR
"i2o_delete_device: passed invalid device.\n");
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
)
457 down(&i2o_configuration_lock
);
463 ret
= __i2o_delete_device(d
);
465 up(&i2o_configuration_lock
);
471 * i2o_install_controller - attach a 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
)
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
);
493 up(&i2o_configuration_lock
);
496 i2o_controllers
[i
]=c
;
498 c
->next
=i2o_controller_chain
;
499 i2o_controller_chain
=c
;
501 c
->page_frame
= 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
);
512 printk(KERN_ERR
"No free i2o controller slots.\n");
513 up(&i2o_configuration_lock
);
518 * i2o_delete_controller - delete a 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
;
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
,
546 up(&i2o_configuration_lock
);
551 if(__i2o_delete_device(c
->devices
)<0)
553 /* Shouldnt happen */
555 up(&i2o_configuration_lock
);
561 * If this is shutdown time, the thread's already been killed
564 stat
= kill_proc(c
->lct_pid
, SIGTERM
, 1);
566 int count
= 10 * 100;
567 while(c
->lct_running
&& --count
) {
568 current
->state
= TASK_INTERRUPTIBLE
;
574 "%s: LCT thread still running!\n",
579 p
=&i2o_controller_chain
;
585 /* Ask the IOP to switch to RESET state */
586 i2o_reset_controller(c
);
592 up(&i2o_configuration_lock
);
595 kfree(c
->page_frame
);
601 kfree(c
->status_block
);
605 i2o_controllers
[c
->unit
]=NULL
;
606 memcpy(name
, c
->name
, strlen(c
->name
)+1);
608 dprintk(KERN_INFO
"%s: Deleted from controller chain.\n", name
);
610 i2o_num_controllers
--;
615 up(&i2o_configuration_lock
);
616 printk(KERN_ERR
"i2o_delete_controller: bad pointer!\n");
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
)
649 down(&i2o_configuration_lock
);
650 c
=i2o_controllers
[n
];
652 atomic_inc(&c
->users
);
653 up(&i2o_configuration_lock
);
658 * i2o_issue_claim - claim or release a device
660 * @c: controller to claim for
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
)
675 msg
[0] = FIVE_WORD_MSG_SIZE
| SGL_OFFSET_0
;
676 msg
[1] = cmd
<< 24 | HOST_TID
<<12 | tid
;
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
);
699 printk(KERN_INFO
"Device claim called, but dev allready owned by %s!",
701 up(&i2o_configuration_lock
);
706 if(i2o_issue_claim(I2O_CMD_UTIL_CLAIM
,d
->controller
,d
->lct_data
.tid
,
712 up(&i2o_configuration_lock
);
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
)
730 down(&i2o_configuration_lock
);
732 printk(KERN_INFO
"Claim release called, but not owned by %s!",
734 up(&i2o_configuration_lock
);
740 if(i2o_issue_claim(I2O_CMD_UTIL_RELEASE
, d
->controller
, d
->lct_data
.tid
,
747 up(&i2o_configuration_lock
);
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
)
759 if(d
->num_managers
== I2O_MAX_MANAGERS
)
762 for(i
= 0; i
< I2O_MAX_MANAGERS
; i
++)
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
)
784 for(i
=0; i
< I2O_MAX_MANAGERS
; i
++)
786 if(d
->managers
[i
] == h
)
788 d
->managers
[i
] = NULL
;
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
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
;
813 return i2o_post_this(c
, msg
, sizeof(msg
));
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
;
849 strcpy(current
->comm
, "i2oevtd");
854 down_interruptible(&evt_sem
);
855 if(signal_pending(current
))
857 dprintk(KERN_INFO
"I2O event thread dead\n");
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
);
870 spin_unlock_irqrestore(&i2o_evt_lock
, flags
);
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.
886 case I2O_EVT_IND_EXEC_RESOURCE_LIMITS
:
887 printk(KERN_ERR
"%s: Out of resources\n", c
->name
);
890 case I2O_EVT_IND_EXEC_POWER_FAIL
:
891 printk(KERN_ERR
"%s: Power failure\n", c
->name
);
894 case I2O_EVT_IND_EXEC_HW_FAIL
:
902 "Code Execution Exception",
903 "Watchdog Timer Expired"
907 printk(KERN_ERR
"%s: Hardware Failure: %s\n",
908 c
->name
, fail
[msg
[5]]);
910 printk(KERN_ERR
"%s: Unknown Hardware Failure\n", c
->name
);
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
);
926 memcpy(&d
->lct_data
, &msg
[5], sizeof(i2o_lct_entry
));
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
);
951 * LCT entry for a device has been modified, so update it
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
));
970 case I2O_EVT_IND_CONFIGURATION_FLAG
:
971 printk(KERN_WARNING
"%s requires user configuration\n", c
->name
);
974 case I2O_EVT_IND_GENERAL_WARNING
:
975 printk(KERN_WARNING
"%s: Warning notification received!"
976 "Check configuration for errors!\n", c
->name
);
980 printk(KERN_WARNING
"%s: No handler for event (0x%08x)\n", c
->name
, msg
[4]);
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
;
1008 exit_files(current
);
1012 sprintf(name
, "iop%d_lctd", c
->unit
);
1013 strcpy(current
->comm
, name
);
1019 down_interruptible(&c
->lct_sem
);
1020 if(signal_pending(current
))
1022 dprintk(KERN_ERR
"%s: LCT thread dead\n", c
->name
);
1027 entries
= c
->dlct
->table_size
;
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
);
1036 printk(KERN_INFO
"%s: Empty LCT???\n", c
->name
);
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
; )
1053 for(i
= 0; i
< entries
; i
++)
1055 if(d
->lct_data
.tid
== c
->dlct
->lct_entry
[i
].tid
)
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
);
1072 * Tell LCT to renotify us next time there is a change
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
)
1087 c
->lct
= kmalloc(c
->dlct
->table_size
<<2, GFP_KERNEL
);
1090 printk(KERN_ERR
"%s: No memory for LCT!\n", c
->name
);
1096 memcpy(c
->lct
, c
->dlct
, c
->dlct
->table_size
<<2);
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
;
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
);
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)];
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
);
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)
1163 static char *i2o_class_name
[] = {
1165 "Device Driver Module",
1170 "Fibre Channel Port",
1171 "Fibre Channel Device",
1175 "Floppy Controller",
1177 "Secondary Bus Port",
1178 "Peer Transport Agent",
1185 case I2O_CLASS_EXECUTIVE
:
1189 case I2O_CLASS_RANDOM_BLOCK_STORAGE
:
1191 case I2O_CLASS_SEQUENTIAL_STORAGE
:
1197 case I2O_CLASS_FIBRE_CHANNEL_PORT
:
1199 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL
:
1201 case I2O_CLASS_SCSI_PERIPHERAL
:
1203 case I2O_CLASS_ATE_PORT
:
1205 case I2O_CLASS_ATE_PERIPHERAL
:
1207 case I2O_CLASS_FLOPPY_CONTROLLER
:
1209 case I2O_CLASS_FLOPPY_DEVICE
:
1211 case I2O_CLASS_BUS_ADAPTER_PORT
:
1213 case I2O_CLASS_PEER_TRANSPORT_AGENT
:
1215 case I2O_CLASS_PEER_TRANSPORT
:
1219 return i2o_class_name
[idx
];
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
)
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",
1256 * i2o_report_controller_unit - print information about a tid
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
)
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)
1277 printk(KERN_INFO
" Vendor: %s\n", buf
);
1279 if((ret
=i2o_query_scalar(c
, unit
, 0xF100, 4, buf
, 16))>=0)
1282 printk(KERN_INFO
" Device: %s\n", buf
);
1285 if(i2o_query_scalar(c
, unit
, 0xF100, 5, buf
, 16)>=0)
1288 printk(KERN_INFO
" Description: %s\n", buf
);
1291 if((ret
=i2o_query_scalar(c
, unit
, 0xF100, 6, 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!
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
)
1330 u32
*rows
=(u32
*)c
->hrt
;
1340 printk(KERN_ERR
"%s: HRT table for controller is too new a version.\n",
1345 count
=p
[0]|(p
[1]<<8);
1348 printk(KERN_INFO
"%s: HRT has %d entries of %d bytes each.\n",
1349 c
->name
, count
, length
<<2);
1353 for(i
=0;i
<count
;i
++)
1355 printk(KERN_INFO
"Adapter %08X: ", rows
[0]);
1360 printk("TID %04X:[", state
&0xFFF);
1363 printk("H"); /* Hidden */
1366 printk("P"); /* Present */
1368 printk("C"); /* Controlled */
1371 printk("*"); /* Hard */
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));
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));
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));
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));
1398 case 4: /* PCI bus */
1399 printk("PCI %d: Bus %d Device %d Function %d",
1400 p
[2], d
[2], d
[1], d
[0]);
1403 case 0x80: /* Other */
1405 printk("Unsupported bus type.");
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
)
1425 struct i2o_device
*d
;
1426 i2o_lct
*lct
= c
->lct
;
1429 printk(KERN_ERR
"%s: LCT is empty???\n", c
->name
);
1433 max
= lct
->table_size
;
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
);
1444 d
= (struct i2o_device
*)kmalloc(sizeof(struct i2o_device
), GFP_KERNEL
);
1447 printk(KERN_CRIT
"i2o_core: Out of memory for I2O device data.\n");
1454 memcpy(&d
->lct_data
, &lct
->lct_entry
[i
], sizeof(i2o_lct_entry
));
1457 tid
= d
->lct_data
.tid
;
1459 i2o_report_controller_unit(c
, d
);
1461 i2o_install_device(c
, d
);
1468 * i2o_quiesce_controller - quiesce 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
)
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
))
1490 msg
[0] = FOUR_WORD_MSG_SIZE
|SGL_OFFSET_0
;
1491 msg
[1] = I2O_CMD_SYS_QUIESCE
<<24|HOST_TID
<<12|ADAPTER_TID
;
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",
1500 dprintk(KERN_INFO
"%s: Quiesced.\n", c
->name
);
1502 i2o_status_get(c
); // Entered READY state
1507 * i2o_enable_controller - move controller from ready to operational
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
)
1522 /* Enable only allowed on READY state */
1523 if(c
->status_block
->iop_state
!= ADAPTER_STATE_READY
)
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",
1535 dprintk(KERN_INFO
"%s: Enabled.\n", c
->name
);
1537 i2o_status_get(c
); // entered OPERATIONAL state
1543 * i2o_clear_controller - clear a 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
;
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
;
1567 if ((ret
=i2o_post_wait(c
, msg
, sizeof(msg
), 30)))
1568 printk(KERN_INFO
"%s: Unable to clear (status=%#x).\n",
1571 dprintk(KERN_INFO
"%s: Cleared.\n",c
->name
);
1575 /* Enable other IOPs */
1577 for (iop
= i2o_controller_chain
; iop
; iop
= iop
->next
)
1579 i2o_enable_controller(iop
);
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
;
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");
1611 msg
=(u32
*)(c
->mem_offset
+m
);
1613 status
=(void *)kmalloc(4, GFP_KERNEL
);
1615 printk(KERN_ERR
"IOP reset failed - no free memory.\n");
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
;
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 */
1635 if((jiffies
-time
)>=20*HZ
)
1637 printk(KERN_ERR
"IOP reset timeout.\n");
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",
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",
1671 m
= I2O_POST_READ32(c
);
1673 i2o_flush_reply(c
,m
);
1676 /* If IopReset was rejected or didn't perform reset, try IopClear */
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
);
1686 dprintk(KERN_INFO
"%s: Reset completed.\n", c
->name
);
1688 /* Enable other IOPs */
1690 for (iop
= i2o_controller_chain
; iop
; iop
= iop
->next
)
1692 i2o_enable_controller(iop
);
1700 * i2o_status_get - get the status block for the IOP
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
)
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",
1728 status_block
= (u8
*)c
->status_block
;
1729 memset(c
->status_block
,0,sizeof(i2o_status_block
));
1731 m
=i2o_wait_message(c
, "StatusGet");
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
;
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 */
1751 while(status_block
[87]!=0xFF)
1753 if((jiffies
-time
)>=5*HZ
)
1755 printk(KERN_ERR
"%s: Get status timeout.\n",c
->name
);
1763 printk(KERN_INFO
"%s: State = ", c
->name
);
1764 switch (c
->status_block
->iop_state
) {
1778 printk("OPERATIONAL\n");
1784 printk("FAULTED\n");
1787 printk("%x (unknown !!)\n",c
->status_block
->iop_state
);
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
)
1802 int ret
, size
= sizeof(i2o_hrt
);
1804 /* Read first just the header to figure out the real size */
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
);
1815 msg
[0]= SIX_WORD_MSG_SIZE
| SGL_OFFSET_4
;
1816 msg
[1]= I2O_CMD_HRT_GET
<<24 | HOST_TID
<<12 | ADAPTER_TID
;
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",
1827 if (c
->hrt
->num_entries
* c
->hrt
->entry_len
<< 2 > size
) {
1828 size
= c
->hrt
->num_entries
* c
->hrt
->entry_len
<< 2;
1832 } while (c
->hrt
== NULL
);
1834 i2o_parse_hrt(c
); // just for debugging
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
)
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
;
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",
1881 dprintk(KERN_INFO
"%s: SysTab set.\n", iop
->name
);
1883 i2o_status_get(iop
); // Entered READY state
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",
1904 if (i2o_activate_controller(iop
) < 0)
1905 i2o_delete_controller(iop
);
1908 /* Active IOPs in HOLD state */
1911 if (i2o_controller_chain
== NULL
)
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) {
1924 /* If IOP don't get online, we need to rebuild the System table */
1925 for (iop
= i2o_controller_chain
; iop
; iop
= niop
) {
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
) {
1971 i2o_delete_controller(iop
);
1976 * i2o_activate_controller - bring controller up to HOLD
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)
1997 if(iop
->status_block
->iop_state
== ADAPTER_STATE_FAULTED
) {
1998 printk(KERN_CRIT
"%s: hardware fault\n", iop
->name
);
2002 if (iop
->status_block
->i2o_version
> I2OVER15
) {
2003 printk(KERN_ERR
"%s: Not running vrs. 1.5. of the I2O Specification.\n",
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",
2015 if (i2o_reset_controller(iop
) < 0)
2019 if (i2o_init_outbound_q(iop
) < 0)
2022 if (i2o_post_outbound_messages(iop
))
2027 if (i2o_hrt_get(iop
) < 0)
2035 * i2o_init_outbound_queue - setup the outbound queue
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
)
2049 dprintk(KERN_INFO
"%s: Initializing Outbound Queue...\n", c
->name
);
2050 m
=i2o_wait_message(c
, "OutboundInit");
2053 msg
=(u32
*)(c
->mem_offset
+m
);
2055 status
= kmalloc(4,GFP_KERNEL
);
2057 printk(KERN_ERR
"%s: Outbound Queue initialization failed - no free memory.\n",
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
);
2078 while(status
[0] < I2O_CMD_REJECTED
)
2080 if((jiffies
-time
)>=30*HZ
)
2083 printk(KERN_ERR
"%s: Ignored queue initialize request.\n",
2086 printk(KERN_ERR
"%s: Outbound queue initialize timeout.\n",
2095 if(status
[0] != I2O_CMD_COMPLETED
)
2097 printk(KERN_ERR
"%s: IOP outbound initialise failed.\n", c
->name
);
2106 * i2o_post_outbound_messages - fill message queue
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
2114 int i2o_post_outbound_messages(struct i2o_controller
*c
)
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",
2126 m
=virt_to_bus(c
->page_frame
);
2130 for(i
=0; i
< NMBR_MSG_FRAMES
; i
++) {
2131 I2O_REPLY_WRITE32(c
,m
);
2133 m
+= MSG_FRAME_SIZE
;
2140 * Get the IOP's Logical Configuration Table
2142 int i2o_lct_get(struct i2o_controller
*c
)
2145 int ret
, size
= c
->status_block
->expected_lct_size
;
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",
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 */
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",
2173 if (c
->lct
->table_size
<< 2 > size
) {
2174 size
= c
->lct
->table_size
<< 2;
2178 } while (c
->lct
== NULL
);
2180 if ((ret
=i2o_parse_lct(c
)) < 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
)
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)
2216 /* In READY state */
2218 dprintk(KERN_INFO
"%s: Attempting to enable...\n", iop
->name
);
2219 if (i2o_enable_controller(iop
) < 0)
2222 /* In OPERATIONAL state */
2224 dprintk(KERN_INFO
"%s: Attempting to get/parse lct...\n", iop
->name
);
2225 if (i2o_lct_get(iop
) < 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
;
2245 sys_tbl_len
= sizeof(struct i2o_sys_tbl
) + // Header + IOPs
2246 (i2o_num_controllers
) *
2247 sizeof(struct i2o_sys_tbl_entry
);
2252 sys_tbl
= kmalloc(sys_tbl_len
, GFP_KERNEL
);
2254 printk(KERN_CRIT
"SysTab Set failed. Out of memory.\n");
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
)
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
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
]);
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
)
2330 unsigned long t
=jiffies
;
2335 m
= I2O_POST_READ32(c
);
2337 while(m
==0xFFFFFFFF && (jiffies
-t
)<HZ
);
2341 printk(KERN_ERR
"%s: Timeout waiting for message frame!\n",
2345 msg
= (u32
*)(c
->mem_offset
+ m
);
2346 memcpy_toio(msg
, data
, len
);
2347 i2o_post_message(c
,m
);
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
);
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
);
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
;
2389 if(status
== -ETIMEDOUT
)
2390 printk(KERN_INFO
"%s: POST WAIT TIMEOUT\n",c
->name
);
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.
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
) {
2406 p2
->next
= p1
->next
;
2408 post_wait_queue
= p1
->next
;
2413 spin_unlock_irqrestore(&post_wait_lock
, flags
);
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
);
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
)
2466 u8
*res
= (u8
*)reslist
;
2467 u32
*res32
= (u32
*)reslist
;
2468 u32
*restmp
= (u32
*)reslist
;
2473 msg
[0] = NINE_WORD_MSG_SIZE
| SGL_OFFSET_5
;
2474 msg
[1] = cmd
<< 24 | HOST_TID
<< 12 | tid
;
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
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"
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 */
2525 if (field
== -1) /* whole group */
2528 size
= i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET
, iop
, tid
,
2529 opblk
, sizeof(opblk
), resblk
, sizeof(resblk
));
2534 memcpy(buf
, resblk
+8, buflen
); /* cut off header */
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
)
2545 u8 resblk
[8+buflen
]; /* 8 bytes for header */
2548 opblk
= kmalloc(buflen
+64, GFP_KERNEL
);
2551 printk(KERN_ERR
"i2o: no memory for operation buffer.\n");
2555 opblk
[0] = 1; /* operation count */
2556 opblk
[1] = 0; /* pad */
2557 opblk
[2] = I2O_PARAMS_FIELD_SET
;
2560 if(field
== -1) { /* whole group */
2562 memcpy(opblk
+5, buf
, buflen
);
2564 else /* single 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
));
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
)
2601 opblk
= kmalloc(10 + ibuflen
, GFP_KERNEL
);
2604 printk(KERN_ERR
"i2o: no memory for query buffer.\n");
2608 opblk
[0] = 1; /* operation count */
2609 opblk
[1] = 0; /* pad */
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
);
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
)
2646 u8 resblk
[32]; /* min 8 bytes for header */
2649 opblk
= kmalloc(buflen
+64, GFP_KERNEL
);
2652 printk(KERN_ERR
"i2o: no memory for operation buffer.\n");
2656 opblk
[0] = 1; /* operation count */
2657 opblk
[1] = 0; /* pad */
2658 opblk
[2] = I2O_PARAMS_ROW_ADD
;
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
));
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 */
2689 "INVALID_MSG_FLAGS",
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
);
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
[] = {
2736 "ABORT_NO_DATA_TRANSFER",
2737 "ABORT_PARTIAL_TRANSFER",
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",
2748 if (req_status
> I2O_REPLY_STATUS_PROGRESS_REPORT
)
2749 printk("RequestStatus = %0#2x", req_status
);
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
[] = {
2766 "REPLY_BUFFER_FULL",
2768 "INSUFFICIENT_RESOURCE_SOFT",
2769 "INSUFFICIENT_RESOURCE_HARD",
2771 "CHAIN_BUFFER_TOO_LARGE",
2772 "UNSUPPORTED_FUNCTION",
2775 "INAPPROPRIATE_FUNCTION",
2776 "INVALID_INITIATOR_ADDRESS",
2777 "INVALID_MESSAGE_FLAGS",
2779 "INVALID_PARAMETER",
2781 "INVALID_TARGET_ADDRESS",
2782 "MESSAGE_TOO_LARGE",
2783 "MESSAGE_TOO_SMALL",
2784 "MISSING_PARAMETER",
2788 "UNSUPPORTED_VERSION",
2790 "DEVICE_NOT_AVAILABLE"
2793 if (detailed_status
> I2O_DSC_DEVICE_NOT_AVAILABLE
)
2794 printk(" / DetailedStatus = %0#4x.\n", detailed_status
);
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
2807 "DESTINATION_NOT_FOUND",
2813 "BAD_PACKET_DETECTED",
2816 "IOP_INTERNAL_ERROR",
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
);
2829 printk(" / %s.\n", LAN_DSC
[detailed_status
]);
2833 * Used for error reporting/debugging purposes
2835 static void i2o_report_util_cmd(u8 cmd
)
2838 case I2O_CMD_UTIL_NOP
:
2839 printk("UTIL_NOP, ");
2841 case I2O_CMD_UTIL_ABORT
:
2842 printk("UTIL_ABORT, ");
2844 case I2O_CMD_UTIL_CLAIM
:
2845 printk("UTIL_CLAIM, ");
2847 case I2O_CMD_UTIL_RELEASE
:
2848 printk("UTIL_CLAIM_RELEASE, ");
2850 case I2O_CMD_UTIL_CONFIG_DIALOG
:
2851 printk("UTIL_CONFIG_DIALOG, ");
2853 case I2O_CMD_UTIL_DEVICE_RESERVE
:
2854 printk("UTIL_DEVICE_RESERVE, ");
2856 case I2O_CMD_UTIL_DEVICE_RELEASE
:
2857 printk("UTIL_DEVICE_RELEASE, ");
2859 case I2O_CMD_UTIL_EVT_ACK
:
2860 printk("UTIL_EVENT_ACKNOWLEDGE, ");
2862 case I2O_CMD_UTIL_EVT_REGISTER
:
2863 printk("UTIL_EVENT_REGISTER, ");
2865 case I2O_CMD_UTIL_LOCK
:
2866 printk("UTIL_LOCK, ");
2868 case I2O_CMD_UTIL_LOCK_RELEASE
:
2869 printk("UTIL_LOCK_RELEASE, ");
2871 case I2O_CMD_UTIL_PARAMS_GET
:
2872 printk("UTIL_PARAMS_GET, ");
2874 case I2O_CMD_UTIL_PARAMS_SET
:
2875 printk("UTIL_PARAMS_SET, ");
2877 case I2O_CMD_UTIL_REPLY_FAULT_NOTIFY
:
2878 printk("UTIL_REPLY_FAULT_NOTIFY, ");
2881 printk("Cmd = %0#2x, ",cmd
);
2886 * Used for error reporting/debugging purposes
2888 static void i2o_report_exec_cmd(u8 cmd
)
2891 case I2O_CMD_ADAPTER_ASSIGN
:
2892 printk("EXEC_ADAPTER_ASSIGN, ");
2894 case I2O_CMD_ADAPTER_READ
:
2895 printk("EXEC_ADAPTER_READ, ");
2897 case I2O_CMD_ADAPTER_RELEASE
:
2898 printk("EXEC_ADAPTER_RELEASE, ");
2900 case I2O_CMD_BIOS_INFO_SET
:
2901 printk("EXEC_BIOS_INFO_SET, ");
2903 case I2O_CMD_BOOT_DEVICE_SET
:
2904 printk("EXEC_BOOT_DEVICE_SET, ");
2906 case I2O_CMD_CONFIG_VALIDATE
:
2907 printk("EXEC_CONFIG_VALIDATE, ");
2909 case I2O_CMD_CONN_SETUP
:
2910 printk("EXEC_CONN_SETUP, ");
2912 case I2O_CMD_DDM_DESTROY
:
2913 printk("EXEC_DDM_DESTROY, ");
2915 case I2O_CMD_DDM_ENABLE
:
2916 printk("EXEC_DDM_ENABLE, ");
2918 case I2O_CMD_DDM_QUIESCE
:
2919 printk("EXEC_DDM_QUIESCE, ");
2921 case I2O_CMD_DDM_RESET
:
2922 printk("EXEC_DDM_RESET, ");
2924 case I2O_CMD_DDM_SUSPEND
:
2925 printk("EXEC_DDM_SUSPEND, ");
2927 case I2O_CMD_DEVICE_ASSIGN
:
2928 printk("EXEC_DEVICE_ASSIGN, ");
2930 case I2O_CMD_DEVICE_RELEASE
:
2931 printk("EXEC_DEVICE_RELEASE, ");
2933 case I2O_CMD_HRT_GET
:
2934 printk("EXEC_HRT_GET, ");
2936 case I2O_CMD_ADAPTER_CLEAR
:
2937 printk("EXEC_IOP_CLEAR, ");
2939 case I2O_CMD_ADAPTER_CONNECT
:
2940 printk("EXEC_IOP_CONNECT, ");
2942 case I2O_CMD_ADAPTER_RESET
:
2943 printk("EXEC_IOP_RESET, ");
2945 case I2O_CMD_LCT_NOTIFY
:
2946 printk("EXEC_LCT_NOTIFY, ");
2948 case I2O_CMD_OUTBOUND_INIT
:
2949 printk("EXEC_OUTBOUND_INIT, ");
2951 case I2O_CMD_PATH_ENABLE
:
2952 printk("EXEC_PATH_ENABLE, ");
2954 case I2O_CMD_PATH_QUIESCE
:
2955 printk("EXEC_PATH_QUIESCE, ");
2957 case I2O_CMD_PATH_RESET
:
2958 printk("EXEC_PATH_RESET, ");
2960 case I2O_CMD_STATIC_MF_CREATE
:
2961 printk("EXEC_STATIC_MF_CREATE, ");
2963 case I2O_CMD_STATIC_MF_RELEASE
:
2964 printk("EXEC_STATIC_MF_RELEASE, ");
2966 case I2O_CMD_STATUS_GET
:
2967 printk("EXEC_STATUS_GET, ");
2969 case I2O_CMD_SW_DOWNLOAD
:
2970 printk("EXEC_SW_DOWNLOAD, ");
2972 case I2O_CMD_SW_UPLOAD
:
2973 printk("EXEC_SW_UPLOAD, ");
2975 case I2O_CMD_SW_REMOVE
:
2976 printk("EXEC_SW_REMOVE, ");
2978 case I2O_CMD_SYS_ENABLE
:
2979 printk("EXEC_SYS_ENABLE, ");
2981 case I2O_CMD_SYS_MODIFY
:
2982 printk("EXEC_SYS_MODIFY, ");
2984 case I2O_CMD_SYS_QUIESCE
:
2985 printk("EXEC_SYS_QUIESCE, ");
2987 case I2O_CMD_SYS_TAB_SET
:
2988 printk("EXEC_SYS_TAB_SET, ");
2991 printk("Cmd = %#02x, ",cmd
);
2996 * Used for error reporting/debugging purposes
2998 static void i2o_report_lan_cmd(u8 cmd
)
3001 case LAN_PACKET_SEND
:
3002 printk("LAN_PACKET_SEND, ");
3005 printk("LAN_SDU_SEND, ");
3007 case LAN_RECEIVE_POST
:
3008 printk("LAN_RECEIVE_POST, ");
3011 printk("LAN_RESET, ");
3014 printk("LAN_SUSPEND, ");
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
3043 printk("Cmd = %0#2x, ", cmd
); // Other cmds
3045 if (msg
[0] & MSG_FAIL
) {
3046 i2o_report_fail_status(req_status
, msg
);
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
);
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
)
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
]);
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
3089 struct i2o_controller
*c
= NULL
;
3091 if(code
!= SYS_RESTART
&& code
!= SYS_HALT
&& code
!= SYS_POWER_OFF
)
3094 printk(KERN_INFO
"Shutting down I2O system.\n");
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");
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)
3162 "i2o_core: Unable to install core handler.\nI2O stack not loaded!");
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");
3177 * Initialize event handling thread
3179 init_MUTEX_LOCKED(&evt_sem
);
3180 evt_pid
= kernel_thread(i2o_core_evt
, &evt_reply
, CLONE_SIGHAND
);
3183 printk(KERN_ERR
"I2O: Could not create event handler kernel thread\n");
3184 i2o_remove_handler(&i2o_core_handler
);
3188 printk(KERN_INFO
"I2O: Event thread created as pid %d\n", evt_pid
);
3190 if(i2o_num_controllers
)
3193 register_reboot_notifier(&i2o_reboot_notifier
);
3198 void cleanup_module(void)
3202 unregister_reboot_notifier(&i2o_reboot_notifier
);
3204 if(i2o_num_controllers
)
3208 * If this is shutdown time, the thread has already been killed
3211 stat
= kill_proc(evt_pid
, SIGTERM
, 1);
3213 int count
= 10 * 100;
3214 while(evt_running
&& count
--) {
3215 current
->state
= TASK_INTERRUPTIBLE
;
3216 schedule_timeout(1);
3220 printk(KERN_ERR
"i2o: Event thread still running!\n");
3224 #ifdef CONFIG_I2O_PCI_MODULE
3225 i2o_pci_core_detach();
3228 i2o_remove_handler(&i2o_core_handler
);
3230 unregister_reboot_notifier(&i2o_reboot_notifier
);
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)
3249 "i2o_core: Unable to install core handler.\nI2O stack not loaded!");
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
);
3270 #ifdef CONFIG_I2O_PCI
3274 if(i2o_num_controllers
)
3277 register_reboot_notifier(&i2o_reboot_notifier
);
3280 #ifdef CONFIG_I2O_BLOCK
3283 #ifdef CONFIG_I2O_LAN
3286 #ifdef CONFIG_I2O_PROC