Import 2.3.18pre1
[davej-history.git] / drivers / i2o / i2o_core.c
bloba8395b15c491bab42d462fe959bbff65a0018d1b
1 /*
2 * Core I2O structure managment
4 * (C) Copyright 1999 Red Hat Software
5 *
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
16 * Fixes by Philipp Rumpf
17 * Juha Sievänen <Juha.Sievanen@cs.Helsinki.FI>
18 * Auvo Häkkinen <Auvo.Hakkinen@cs.Helsinki.FI>
19 * Deepak Saxena <deepak@plexity.net>
22 #include <linux/config.h>
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/pci.h>
27 #if defined(CONFIG_I2O_PCI) || defined (CONFIG_I2O_PCI_MODULE)
28 #include <linux/i2o.h>
29 #endif
31 #include <linux/errno.h>
32 #include <linux/init.h>
33 #include <linux/malloc.h>
34 #include <linux/spinlock.h>
36 #include <asm/io.h>
38 #include "i2o_lan.h"
40 #define DRIVERDEBUG
43 * Size of the I2O module table
46 static struct i2o_handler *i2o_handlers[MAX_I2O_MODULES];
47 static struct i2o_controller *i2o_controllers[MAX_I2O_CONTROLLERS];
48 int i2o_num_controllers = 0;
49 static int core_context = 0;
50 static int reply_flag = 0;
52 extern int i2o_online_controller(struct i2o_controller *c);
53 static void i2o_core_reply(struct i2o_handler *, struct i2o_controller *,
54 struct i2o_message *);
55 static int i2o_add_management_user(struct i2o_device *, struct i2o_handler *);
56 static int i2o_remove_management_user(struct i2o_device *, struct i2o_handler *);
57 static void i2o_dump_message(u32 *);
59 #ifdef MODULE
60 /*
61 * Function table to send to bus specific layers
62 * See <include/linux/i2o.h> for explanation of this
64 static struct i2o_core_func_table i2o_core_functions =
66 i2o_install_controller,
67 i2o_activate_controller,
68 i2o_find_controller,
69 i2o_unlock_controller,
70 i2o_run_queue,
71 i2o_delete_controller
74 #ifdef CONFIG_I2O_PCI_MODULE
75 extern int i2o_pci_core_attach(struct i2o_core_func_table *);
76 extern void i2o_pci_core_detach(void);
77 #endif /* CONFIG_I2O_PCI_MODULE */
79 #endif /* MODULE */
82 /* Message handler */
83 static struct i2o_handler i2o_core_handler =
85 (void *)i2o_core_reply,
86 "I2O core layer",
91 * I2O configuration spinlock. This isnt a big deal for contention
92 * so we have one only
95 static spinlock_t i2o_configuration_lock = SPIN_LOCK_UNLOCKED;
97 void i2o_core_reply(struct i2o_handler *h, struct i2o_controller *c,
98 struct i2o_message *m)
100 u32 *msg=(u32 *)m;
101 u32 *flag = (u32 *)msg[3];
103 #if 0
104 i2o_report_status(KERN_INFO, "i2o_core", msg);
105 #endif
107 if (msg[0] & (1<<13)) // Fail bit is set
109 printk(KERN_ERR "IOP failed to process the msg:\n");
110 printk(KERN_ERR " Cmd = 0x%02X, InitiatorTid = %d, TargetTid =%d\n",
111 (msg[1] >> 24) & 0xFF, (msg[1] >> 12) & 0xFFF, msg[1] &
112 0xFFF);
113 printk(KERN_ERR " FailureCode = 0x%02X\n Severity = 0x%02X\n"
114 "LowestVersion = 0x%02X\n HighestVersion = 0x%02X\n",
115 msg[4] >> 24, (msg[4] >> 16) & 0xFF,
116 (msg[4] >> 8) & 0xFF, msg[4] & 0xFF);
117 printk(KERN_ERR " FailingHostUnit = 0x%04X\n FailingIOP = 0x%03X\n",
118 msg[5] >> 16, msg[5] & 0xFFF);
119 return;
122 if (msg[4] >> 24)
124 i2o_report_status(KERN_WARNING, "i2o_core", msg);
125 *flag = -(msg[4] & 0xFFFF);
127 else
128 *flag = I2O_POST_WAIT_OK;
132 * Install an I2O handler - these handle the asynchronous messaging
133 * from the card once it has initialised.
136 int i2o_install_handler(struct i2o_handler *h)
138 int i;
139 spin_lock(&i2o_configuration_lock);
140 for(i=0;i<MAX_I2O_MODULES;i++)
142 if(i2o_handlers[i]==NULL)
144 h->context = i;
145 i2o_handlers[i]=h;
146 spin_unlock(&i2o_configuration_lock);
147 return 0;
150 spin_unlock(&i2o_configuration_lock);
151 return -ENOSPC;
154 int i2o_remove_handler(struct i2o_handler *h)
156 i2o_handlers[h->context]=NULL;
157 return 0;
162 * Each I2O controller has a chain of devices on it - these match
163 * the useful parts of the LCT of the board.
166 int i2o_install_device(struct i2o_controller *c, struct i2o_device *d)
168 int i;
170 spin_lock(&i2o_configuration_lock);
171 d->controller=c;
172 d->owner=NULL;
173 d->next=c->devices;
174 c->devices=d;
175 *d->dev_name = 0;
176 d->owner = NULL;
178 for(i = 0; i < I2O_MAX_MANAGERS; i++)
179 d->managers[i] = NULL;
181 spin_unlock(&i2o_configuration_lock);
182 return 0;
185 /* we need this version to call out of i2o_delete_controller */
187 int __i2o_delete_device(struct i2o_device *d)
189 struct i2o_device **p;
191 p=&(d->controller->devices);
194 * Hey we have a driver!
197 if(d->owner)
198 return -EBUSY;
201 * Seek, locate
204 while(*p!=NULL)
206 if(*p==d)
209 * Destroy
211 *p=d->next;
212 kfree(d);
213 return 0;
215 p=&((*p)->next);
217 printk(KERN_ERR "i2o_delete_device: passed invalid device.\n");
218 return -EINVAL;
221 int i2o_delete_device(struct i2o_device *d)
223 int ret;
225 spin_lock(&i2o_configuration_lock);
227 ret = __i2o_delete_device(d);
229 spin_unlock(&i2o_configuration_lock);
231 return ret;
235 * Add and remove controllers from the I2O controller list
238 int i2o_install_controller(struct i2o_controller *c)
240 int i;
241 spin_lock(&i2o_configuration_lock);
242 for(i=0;i<MAX_I2O_CONTROLLERS;i++)
244 if(i2o_controllers[i]==NULL)
246 i2o_controllers[i]=c;
247 c->next=i2o_controller_chain;
248 i2o_controller_chain=c;
249 c->unit = i;
250 sprintf(c->name, "i2o/iop%d", i);
251 i2o_num_controllers++;
252 spin_unlock(&i2o_configuration_lock);
253 return 0;
256 printk(KERN_ERR "No free i2o controller slots.\n");
257 spin_unlock(&i2o_configuration_lock);
258 return -EBUSY;
261 int i2o_delete_controller(struct i2o_controller *c)
263 struct i2o_controller **p;
265 spin_lock(&i2o_configuration_lock);
266 if(atomic_read(&c->users))
268 printk("Someone is using controller iop%d\n", c->unit);
269 spin_unlock(&i2o_configuration_lock);
270 return -EBUSY;
272 while(c->devices)
274 if(__i2o_delete_device(c->devices)<0)
276 /* Shouldnt happen */
277 spin_unlock(&i2o_configuration_lock);
278 return -EBUSY;
281 // c->destructor(c); /* We dont want to free the IRQ yet */
283 p=&i2o_controller_chain;
285 /* Send first SysQuiesce to other IOPs */
286 while(*p)
288 if(*p!=c)
290 printk("Quiescing controller %p != %p\n", c, *p);
291 if(i2o_quiesce_controller(*p)<0)
292 printk(KERN_INFO "Unable to quiesce iop%d\n",
293 (*p)->unit);
295 p=&((*p)->next);
298 p=&i2o_controller_chain;
300 while(*p)
302 if(*p==c)
304 /* Ask the IOP to switch to HOLD state */
305 if (i2o_clear_controller(c) < 0)
306 printk("Unable to clear iop%d\n", c->unit);
308 /* Release IRQ */
309 c->destructor(c);
311 *p=c->next;
312 spin_unlock(&i2o_configuration_lock);
313 if(c->page_frame)
314 kfree(c->page_frame);
315 if(c->hrt)
316 kfree(c->hrt);
317 if(c->lct)
318 kfree(c->lct);
319 i2o_controllers[c->unit]=NULL;
320 kfree(c);
321 i2o_num_controllers--;
322 return 0;
324 p=&((*p)->next);
326 spin_unlock(&i2o_configuration_lock);
327 printk(KERN_ERR "i2o_delete_controller: bad pointer!\n");
328 return -ENOENT;
331 void i2o_unlock_controller(struct i2o_controller *c)
333 atomic_dec(&c->users);
336 struct i2o_controller *i2o_find_controller(int n)
338 struct i2o_controller *c;
340 if(n<0 || n>=MAX_I2O_CONTROLLERS)
341 return NULL;
343 spin_lock(&i2o_configuration_lock);
344 c=i2o_controllers[n];
345 if(c!=NULL)
346 atomic_inc(&c->users);
347 spin_unlock(&i2o_configuration_lock);
348 return c;
353 * Claim a device for use as either the primary user or just
354 * as a management/secondary user
356 int i2o_claim_device(struct i2o_device *d, struct i2o_handler *h, u32 type)
358 /* Device already has a primary user or too many managers */
359 if((type == I2O_CLAIM_PRIMARY && d->owner) ||
360 (d->num_managers == I2O_MAX_MANAGERS))
362 return -EBUSY;
365 if(i2o_issue_claim(d->controller,d->id, h->context, 1, &reply_flag, type) < 0)
367 return -EBUSY;
370 spin_lock(&i2o_configuration_lock);
371 if(d->owner)
373 spin_unlock(&i2o_configuration_lock);
374 return -EBUSY;
376 atomic_inc(&d->controller->users);
378 if(type == I2O_CLAIM_PRIMARY)
379 d->owner=h;
380 else
381 i2o_add_management_user(d, h);
383 spin_unlock(&i2o_configuration_lock);
384 return 0;
387 int i2o_release_device(struct i2o_device *d, struct i2o_handler *h, u32 type)
389 int err = 0;
391 spin_lock(&i2o_configuration_lock);
393 /* Primary user */
394 if(type == I2O_CLAIM_PRIMARY)
396 if(d->owner != h)
397 err = -ENOENT;
398 else
400 if(i2o_issue_claim(d->controller,d->id, h->context, 0, &reply_flag, type) < 0)
402 err = -ENXIO;
404 else
406 d->owner = NULL;
407 atomic_dec(&d->controller->users);
411 spin_unlock(&i2o_configuration_lock);
412 return err;
415 /* Management or other user */
416 if(i2o_remove_management_user(d, h))
417 err = -ENOENT;
418 else
420 atomic_dec(&d->controller->users);
422 if(i2o_issue_claim(d->controller,d->id, h->context, 0,
423 &reply_flag, type) < 0)
424 err = -ENXIO;
427 spin_unlock(&i2o_configuration_lock);
428 return err;
431 int i2o_add_management_user(struct i2o_device *d, struct i2o_handler *h)
433 int i;
435 if(d->num_managers == I2O_MAX_MANAGERS)
436 return 1;
438 for(i = 0; i < I2O_MAX_MANAGERS; i++)
439 if(!d->managers[i])
440 d->managers[i] = h;
442 d->num_managers++;
444 return 0;
447 int i2o_remove_management_user(struct i2o_device *d, struct i2o_handler *h)
449 int i;
451 for(i=0; i < I2O_MAX_MANAGERS; i++)
453 if(d->managers[i] == h)
455 d->managers[i] = NULL;
456 return 0;
460 return -ENOENT;
464 * This is called by the bus specific driver layer when an interrupt
465 * or poll of this card interface is desired.
468 void i2o_run_queue(struct i2o_controller *c)
470 struct i2o_message *m;
471 u32 mv;
473 while((mv=I2O_REPLY_READ32(c))!=0xFFFFFFFF)
475 struct i2o_handler *i;
476 m=(struct i2o_message *)bus_to_virt(mv);
478 * Temporary Debugging
480 if(((m->function_addr>>24)&0xFF)==0x15)
481 printk("UTFR!\n");
482 // printk("dispatching.\n");
483 i=i2o_handlers[m->initiator_context&(MAX_I2O_MODULES-1)];
484 if(i)
485 i->reply(i,c,m);
486 else
488 printk("Spurious reply to handler %d\n",
489 m->initiator_context&(MAX_I2O_MODULES-1));
490 i2o_dump_message((u32*)m);
492 i2o_flush_reply(c,mv);
493 mb();
499 * Do i2o class name lookup
501 const char *i2o_get_class_name(int class)
503 int idx = 16;
504 static char *i2o_class_name[] = {
505 "Executive",
506 "Device Driver Module",
507 "Block Device",
508 "Tape Device",
509 "LAN Interface",
510 "WAN Interface",
511 "Fibre Channel Port",
512 "Fibre Channel Device",
513 "SCSI Device",
514 "ATE Port",
515 "ATE Device",
516 "Floppy Controller",
517 "Floppy Device",
518 "Secondary Bus Port",
519 "Peer Transport Agent",
520 "Peer Transport",
521 "Unknown"
524 switch(class&0xFFF)
526 case I2O_CLASS_EXECUTIVE:
527 idx = 0; break;
528 case I2O_CLASS_DDM:
529 idx = 1; break;
530 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
531 idx = 2; break;
532 case I2O_CLASS_SEQUENTIAL_STORAGE:
533 idx = 3; break;
534 case I2O_CLASS_LAN:
535 idx = 4; break;
536 case I2O_CLASS_WAN:
537 idx = 5; break;
538 case I2O_CLASS_FIBRE_CHANNEL_PORT:
539 idx = 6; break;
540 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
541 idx = 7; break;
542 case I2O_CLASS_SCSI_PERIPHERAL:
543 idx = 8; break;
544 case I2O_CLASS_ATE_PORT:
545 idx = 9; break;
546 case I2O_CLASS_ATE_PERIPHERAL:
547 idx = 10; break;
548 case I2O_CLASS_FLOPPY_CONTROLLER:
549 idx = 11; break;
550 case I2O_CLASS_FLOPPY_DEVICE:
551 idx = 12; break;
552 case I2O_CLASS_BUS_ADAPTER_PORT:
553 idx = 13; break;
554 case I2O_CLASS_PEER_TRANSPORT_AGENT:
555 idx = 14; break;
556 case I2O_CLASS_PEER_TRANSPORT:
557 idx = 15; break;
560 return i2o_class_name[idx];
565 * Wait up to 5 seconds for a message slot to be available.
568 u32 i2o_wait_message(struct i2o_controller *c, char *why)
570 long time=jiffies;
571 u32 m;
572 while((m=I2O_POST_READ32(c))==0xFFFFFFFF)
574 if((jiffies-time)>=5*HZ)
576 printk(KERN_ERR "%s: Timeout waiting for message frame to send %s.\n",
577 c->name, why);
578 return 0xFFFFFFFF;
580 schedule();
581 barrier();
583 return m;
588 * Wait up to timeout seconds for a reply to be available.
591 u32 i2o_wait_reply(struct i2o_controller *c, char *why, int timeout)
593 u32 m;
594 long time=jiffies;
596 while((m=I2O_REPLY_READ32(c))==0xFFFFFFFF)
598 if(jiffies-time >= timeout*HZ )
600 printk(KERN_ERR "%s: timeout waiting for %s reply.\n",
601 c->name, why);
602 return 0xFFFFFFFF;
604 schedule();
606 return m;
610 static int i2o_query_scalar_polled(struct i2o_controller *c, int tid, void *buf, int buflen,
611 int group, int field)
613 u32 m;
614 u32 *msg;
615 u16 op[8];
616 u32 *p;
617 int i;
618 u32 *rbuf;
620 op[0]=1; /* One Operation */
621 op[1]=0; /* PAD */
622 op[2]=1; /* FIELD_GET */
623 op[3]=group; /* group number */
624 op[4]=1; /* 1 field */
625 op[5]=field; /* Field number */
627 m=i2o_wait_message(c, "ParamsGet");
628 if(m==0xFFFFFFFF)
630 return -ETIMEDOUT;
633 msg=(u32 *)(c->mem_offset+m);
635 rbuf=kmalloc(buflen+32, GFP_KERNEL);
636 if(rbuf==NULL)
638 printk(KERN_ERR "No free memory for scalar read.\n");
639 return -ENOMEM;
642 msg[0]=NINE_WORD_MSG_SIZE|SGL_OFFSET_5;
643 msg[1]=I2O_CMD_UTIL_PARAMS_GET<<24|HOST_TID<<12|tid;
644 msg[2]=0; /* Context */
645 msg[3]=0;
646 msg[4]=0;
647 msg[5]=0x54000000|12;
648 msg[6]=virt_to_bus(op);
649 msg[7]=0xD0000000|(32+buflen);
650 msg[8]=virt_to_bus(rbuf);
652 i2o_post_message(c,m);
653 barrier();
656 * Now wait for a reply
659 m=i2o_wait_reply(c, "ParamsGet", 5);
661 if(m==0xFFFFFFFF)
663 kfree(rbuf);
664 return -ETIMEDOUT;
667 msg = (u32 *)bus_to_virt(m);
668 if(msg[4]>>24)
670 i2o_report_status(KERN_WARNING, "i2o_core", msg);
673 p=rbuf;
675 /* Ok 'p' is the reply block - lets see what happened */
676 /* p0->p2 are the header */
678 /* FIXME: endians - turn p3 to little endian */
680 if((p[0]&0xFFFF)!=1)
681 printk(KERN_WARNING "Suspicious field read return 0x%08X\n", p[0]);
683 i=(p[1]&0xFFFF)<<2; /* Message size */
684 if(i<buflen)
685 buflen=i;
687 /* Do we have an error block ? */
688 if(p[1]&0xFF000000)
690 printk(KERN_ERR "%s: error in field read.\n",
691 c->name);
692 kfree(rbuf);
693 return -EBADR;
696 /* p[1] holds the more flag and row count - we dont care */
698 /* Ok it worked p[2]-> hold the data */
699 memcpy(buf, p+2, buflen);
701 kfree(rbuf);
703 /* Finally return the message */
704 I2O_REPLY_WRITE32(c,m);
705 return buflen;
709 * Dump the information block associated with a given unit (TID)
712 void i2o_report_controller_unit(struct i2o_controller *c, int unit)
714 char buf[64];
716 if(i2o_query_scalar_polled(c, unit, buf, 16, 0xF100, 3)>=0)
718 buf[16]=0;
719 printk(KERN_INFO " Vendor: %s\n", buf);
721 if(i2o_query_scalar_polled(c, unit, buf, 16, 0xF100, 4)>=0)
723 buf[16]=0;
724 printk(KERN_INFO " Device: %s\n", buf);
726 #if 0
727 if(i2o_query_scalar_polled(c, unit, buf, 16, 0xF100, 5)>=0)
729 buf[16]=0;
730 printk(KERN_INFO "Description: %s\n", buf);
732 #endif
733 if(i2o_query_scalar_polled(c, unit, buf, 8, 0xF100, 6)>=0)
735 buf[8]=0;
736 printk(KERN_INFO " Rev: %s\n", buf);
742 * Parse the hardware resource table. Right now we print it out
743 * and don't do a lot with it. We should collate these and then
744 * interact with the Linux resource allocation block.
746 * Lets prove we can read it first eh ?
748 * This is full of endianisms!
751 static int i2o_parse_hrt(struct i2o_controller *c)
753 u32 *rows=c->hrt;
754 u8 *p=(u8 *)c->hrt;
755 u8 *d;
756 int count;
757 int length;
758 int i;
759 int state;
761 if(p[3]!=0)
763 printk(KERN_ERR "i2o: HRT table for controller is too new a version.\n");
764 return -1;
767 count=p[0]|(p[1]<<8);
768 length = p[2];
770 printk(KERN_INFO "HRT has %d entries of %d bytes each.\n",
771 count, length<<2);
773 rows+=2;
775 for(i=0;i<count;i++)
777 printk(KERN_INFO "Adapter %08X: ", rows[0]);
778 p=(u8 *)(rows+1);
779 d=(u8 *)(rows+2);
780 state=p[1]<<8|p[0];
782 printk("TID %04X:[", state&0xFFF);
783 state>>=12;
784 if(state&(1<<0))
785 printk("H"); /* Hidden */
786 if(state&(1<<2))
788 printk("P"); /* Present */
789 if(state&(1<<1))
790 printk("C"); /* Controlled */
792 if(state>9)
793 printk("*"); /* Hard */
795 printk("]:");
797 switch(p[3]&0xFFFF)
799 case 0:
800 /* Adapter private bus - easy */
801 printk("Local bus %d: I/O at 0x%04X Mem 0x%08X",
802 p[2], d[1]<<8|d[0], *(u32 *)(d+4));
803 break;
804 case 1:
805 /* ISA bus */
806 printk("ISA %d: CSN %d I/O at 0x%04X Mem 0x%08X",
807 p[2], d[2], d[1]<<8|d[0], *(u32 *)(d+4));
808 break;
810 case 2: /* EISA bus */
811 printk("EISA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
812 p[2], d[3], d[1]<<8|d[0], *(u32 *)(d+4));
813 break;
815 case 3: /* MCA bus */
816 printk("MCA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
817 p[2], d[3], d[1]<<8|d[0], *(u32 *)(d+4));
818 break;
820 case 4: /* PCI bus */
821 printk("PCI %d: Bus %d Device %d Function %d",
822 p[2], d[2], d[1], d[0]);
823 break;
825 case 0x80: /* Other */
826 default:
827 printk("Unsupported bus type.");
828 break;
830 printk("\n");
831 rows+=length;
833 return 0;
837 * The logical configuration table tells us what we can talk to
838 * on the board. Most of the stuff isn't interesting to us.
841 static int i2o_parse_lct(struct i2o_controller *c)
843 int i;
844 int max;
845 int tid;
846 u32 *p;
847 struct i2o_device *d;
848 char str[22];
849 u32 *lct=(u32 *)c->lct;
851 max=lct[0]&0xFFFF;
853 max-=3;
854 max/=9;
856 if(max==0)
858 printk(KERN_ERR "LCT is empty????\n");
859 return -1;
862 printk(KERN_INFO "LCT has %d entries.\n", max);
864 if(max > 128)
866 printk(KERN_INFO "LCT was truncated.\n");
867 max=128;
870 if(lct[1]&(1<<0))
871 printk(KERN_WARNING "Configuration dialog desired.\n");
873 p=lct+3;
875 for(i=0;i<max;i++)
877 d = (struct i2o_device *)kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
878 if(d==NULL)
880 printk("i2o_core: Out of memory for LCT data.\n");
881 return -ENOMEM;
884 d->controller = c;
885 d->next = NULL;
887 d->id = tid = (p[0]>>16)&0xFFF;
888 d->class = p[3]&0xFFF;
889 d->subclass = p[4]&0xFFF;
890 d->parent = (p[5]>>12)&0xFFF;
891 d->flags = 0;
893 printk(KERN_INFO "TID %d.\n", tid);
895 i2o_report_controller_unit(c, tid);
897 i2o_install_device(c, d);
899 printk(KERN_INFO " Class: ");
901 sprintf(str, "%-21s", i2o_get_class_name(d->class));
902 printk("%s", str);
904 printk(" Subclass: 0x%03X Flags: ",
905 d->subclass);
907 if(p[2]&(1<<0))
908 printk("C"); // ConfigDialog requested
909 if(p[2]&(1<<1))
910 printk("M"); // Multi-user capable
911 if(!(p[2]&(1<<4)))
912 printk("P"); // Peer service enabled!
913 if(!(p[2]&(1<<5)))
914 printk("m"); // Mgmt service enabled!
915 printk("\n");
916 p+=9;
918 return 0;
921 /* Quiesce IOP */
922 int i2o_quiesce_controller(struct i2o_controller *c)
924 u32 msg[4];
926 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
927 msg[1]=I2O_CMD_SYS_QUIESCE<<24|HOST_TID<<12|ADAPTER_TID;
928 msg[2]=core_context;
929 msg[3]=(u32)&reply_flag;
931 /* Long timeout needed for quiesce if lots of devices */
932 return i2o_post_wait(c, ADAPTER_TID, msg, sizeof(msg), &reply_flag, 120);
936 int i2o_clear_controller(struct i2o_controller *c)
938 u32 msg[4];
940 /* First stop external operations for this IOP */
941 if(i2o_quiesce_controller(c)<0)
942 printk(KERN_INFO "Unable to quiesce iop%d\n", c->unit);
943 else
944 printk(KERN_INFO "Iop%d quiesced\n", c->unit);
946 /* Then clear the IOP */
947 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
948 msg[1]=I2O_CMD_ADAPTER_CLEAR<<24|HOST_TID<<12|ADAPTER_TID;
949 msg[2]=core_context;
950 msg[3]=(u32)&reply_flag;
952 return i2o_post_wait(c, ADAPTER_TID, msg, sizeof(msg), &reply_flag, 10);
956 /* Reset the IOP to sane state */
957 static int i2o_reset_controller(struct i2o_controller *c)
959 u32 m;
960 u8 *work8;
961 u32 *msg;
962 long time;
963 struct i2o_controller *iop;
965 /* First stop external operations */
966 for(iop=i2o_controller_chain; iop != NULL; iop=iop->next)
968 /* Quiesce is rejected on hold state */
969 if(iop->status != ADAPTER_STATE_HOLD)
971 if(i2o_quiesce_controller(iop)<0)
972 printk(KERN_INFO "Unable to quiesce iop%d\n",
973 iop->unit);
974 else
975 printk(KERN_DEBUG "%s quiesced\n", iop->name);
979 /* Then reset the IOP */
980 m=i2o_wait_message(c, "AdapterReset");
981 if(m==0xFFFFFFFF)
982 return -ETIMEDOUT;
984 msg=(u32 *)(c->mem_offset+m);
986 work8=(void *)kmalloc(4, GFP_KERNEL);
987 if(work8==NULL) {
988 printk(KERN_ERR "IOP reset failed - no free memory.\n");
989 return -ENOMEM;
992 memset(work8, 0, 4);
994 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
995 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
996 msg[2]=core_context;
997 msg[3]=(u32)&reply_flag;
998 msg[4]=0;
999 msg[5]=0;
1000 msg[6]=virt_to_phys(work8);
1001 msg[7]=0; /* 64bit host FIXME */
1003 i2o_post_message(c,m);
1005 /* Wait for a reply */
1006 time=jiffies;
1008 while(work8[0]==0x01)
1010 if((jiffies-time)>=5*HZ)
1012 printk(KERN_ERR "IOP reset timeout.\n");
1013 kfree(work8);
1014 return -ETIMEDOUT;
1016 schedule();
1017 barrier();
1020 if (work8[0]==0x02)
1021 printk(KERN_WARNING "IOP Reset rejected\n");
1023 return 0;
1027 int i2o_status_get(struct i2o_controller *c)
1029 long time;
1030 u32 m;
1031 u32 *msg;
1032 u8 *status_block;
1034 status_block=(void *)kmalloc(88, GFP_KERNEL);
1035 if(status_block==NULL)
1037 printk(KERN_ERR "StatusGet failed - no free memory.\n");
1038 return -ENOMEM;
1041 m=i2o_wait_message(c, "StatusGet");
1042 if(m==0xFFFFFFFF)
1043 return -ETIMEDOUT;
1045 msg=(u32 *)(c->mem_offset+m);
1047 msg[0]=NINE_WORD_MSG_SIZE|SGL_OFFSET_0;
1048 msg[1]=I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID;
1049 msg[2]=core_context;
1050 msg[3]=0;
1051 msg[4]=0;
1052 msg[5]=0;
1053 msg[6]=virt_to_phys(status_block);
1054 msg[7]=0; /* 64bit host FIXME */
1055 msg[8]=88;
1057 i2o_post_message(c,m);
1059 /* Wait for a reply */
1060 time=jiffies;
1062 while(status_block[87]!=0xFF)
1064 if((jiffies-time)>=5*HZ)
1066 printk(KERN_ERR "IOP get status timeout.\n");
1067 return -ETIMEDOUT;
1069 schedule();
1070 barrier();
1073 /* Ok the reply has arrived. Fill in the important stuff */
1074 c->status = status_block[10];
1075 c->i2oversion = (status_block[9]>>4)&0xFF;
1076 c->inbound_size = (status_block[12]|(status_block[13]<<8))*4;
1078 return 0;
1082 int i2o_hrt_get(struct i2o_controller *c)
1084 u32 m;
1085 u32 *msg;
1087 c->hrt=kmalloc(2048, GFP_KERNEL);
1088 if(c->hrt==NULL)
1090 printk(KERN_ERR "IOP init failed; no memory.\n");
1091 return -ENOMEM;
1094 m=i2o_wait_message(c, "HRTGet");
1095 if(m==0xFFFFFFFF)
1096 return -ETIMEDOUT;
1098 msg=(u32 *)(c->mem_offset+m);
1100 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
1101 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
1102 msg[2]= core_context;
1103 msg[3]= 0x0; /* Transaction context */
1104 msg[4]= (0xD0000000 | 2048); /* Simple transaction , 2K */
1105 msg[5]= virt_to_phys(c->hrt); /* Dump it here */
1107 i2o_post_message(c,m);
1109 barrier();
1111 /* Now wait for a reply */
1112 m=i2o_wait_reply(c, "HRTGet", 5);
1114 if(m==0xFFFFFFFF)
1115 return -ETIMEDOUT;
1117 msg=(u32 *)bus_to_virt(m);
1119 if(msg[4]>>24)
1120 i2o_report_status(KERN_WARNING, "i2o_core", msg);
1122 I2O_REPLY_WRITE32(c,m);
1124 return 0;
1129 * Bring an I2O controller into HOLD state. See the 1.5
1130 * spec. Basically we go
1132 * Wait for the message queue to initialise.
1133 * If it didnt -> controller is dead
1135 * Send a get status using the message queue
1136 * Poll for a reply block 88 bytes long
1138 * Send an initialise outbound queue
1139 * Poll for a reply
1141 * Post our blank messages to the queue FIFO
1143 * Send GetHRT, Parse it
1146 int i2o_activate_controller(struct i2o_controller *c)
1148 long time;
1149 u32 m;
1150 u8 *workspace;
1151 u32 *msg;
1152 int i;
1153 int ret;
1155 printk(KERN_INFO "Configuring I2O controller at 0x%08X.\n",
1156 (u32)c->mem_phys);
1158 if((ret=i2o_status_get(c)))
1159 return ret;
1161 if(c->status == ADAPTER_STATE_FAULTED) /* not likely to be seen */
1163 printk(KERN_CRIT "i2o: iop%d has hardware fault\n",
1164 c->unit);
1165 return -1;
1169 * If the board is running, reset it - we have no idea
1170 * what kind of a mess the previous owner left it in.
1172 if(c->status == ADAPTER_STATE_HOLD ||
1173 c->status == ADAPTER_STATE_READY ||
1174 c->status == ADAPTER_STATE_OPERATIONAL ||
1175 c->status == ADAPTER_STATE_FAILED)
1177 if((ret=i2o_reset_controller(c)))
1178 return ret;
1180 if((ret=i2o_status_get(c)))
1181 return ret;
1184 workspace = (void *)kmalloc(88, GFP_KERNEL);
1185 if(workspace==NULL)
1187 printk(KERN_ERR "IOP initialisation failed - no free memory.\n");
1188 return -ENOMEM;
1191 memset(workspace, 0, 88);
1193 m=i2o_wait_message(c, "OutboundInit");
1194 if(m==0xFFFFFFFF)
1196 kfree(workspace);
1197 return -ETIMEDOUT;
1200 msg=(u32 *)(c->mem_offset+m);
1202 msg[0]= EIGHT_WORD_MSG_SIZE| TRL_OFFSET_6;
1203 msg[1]= I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID;
1204 msg[2]= core_context;
1205 msg[3]= 0x0106; /* Transaction context */
1206 msg[4]= 4096; /* Host page frame size */
1207 msg[5]= MSG_FRAME_SIZE<<16|0x80; /* Outbound msg frame size and Initcode */
1208 msg[6]= 0xD0000004; /* Simple SG LE, EOB */
1209 msg[7]= virt_to_phys(workspace);
1210 *((u32 *)workspace)=0;
1213 * Post it
1216 i2o_post_message(c,m);
1218 barrier();
1220 time=jiffies;
1222 while(workspace[0]!=I2O_CMD_OUTBOUND_INIT_COMPLETE)
1224 if((jiffies-time)>=5*HZ)
1226 printk(KERN_ERR "IOP outbound initialise failed.\n");
1227 kfree(workspace);
1228 return -ETIMEDOUT;
1230 schedule();
1231 barrier();
1234 kfree(workspace);
1236 /* TODO: v2.0: Set Executive class group 000Bh - OS Operating Info */
1238 c->page_frame = kmalloc(MSG_POOL_SIZE, GFP_KERNEL);
1239 if(c->page_frame==NULL)
1241 printk(KERN_ERR "IOP init failed: no memory for message page.\n");
1242 return -ENOMEM;
1245 m=virt_to_phys(c->page_frame);
1247 for(i=0; i< NMBR_MSG_FRAMES; i++)
1249 I2O_REPLY_WRITE32(c,m);
1250 mb();
1251 m+=MSG_FRAME_SIZE;
1255 * The outbound queue is initialised and loaded,
1257 * Now we need the Hardware Resource Table. We must ask for
1258 * this next we can't issue random messages yet.
1260 ret=i2o_hrt_get(c);
1261 if(ret)
1262 return ret;
1264 ret=i2o_parse_hrt(c);
1265 if(ret)
1266 return ret;
1268 return i2o_online_controller(c);
1269 // i2o_report_controller_unit(c, ADAPTER_TID);
1273 int i2o_lct_get(struct i2o_controller *c)
1275 u32 m;
1276 u32 *msg;
1278 m=i2o_wait_message(c, "LCTNotify");
1280 if(m==0xFFFFFFFF)
1281 return -ETIMEDOUT;
1283 msg=(u32 *)(c->mem_offset+m);
1285 c->lct = kmalloc(8192, GFP_KERNEL);
1286 if(c->lct==NULL)
1288 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
1289 msg[1]= HOST_TID<<12|ADAPTER_TID; /* NOP */
1290 i2o_post_message(c,m);
1291 printk(KERN_ERR "No free memory for i2o controller buffer.\n");
1292 return -ENOMEM;
1295 memset(c->lct, 0, 8192);
1297 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
1298 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
1299 msg[2] = 0; /* Context not needed */
1300 msg[3] = 0;
1301 msg[4] = 0xFFFFFFFF; /* All devices */
1302 msg[5] = 0x00000000; /* Report now */
1303 msg[6] = 0xD0000000|8192;
1304 msg[7] = virt_to_bus(c->lct);
1306 i2o_post_message(c,m);
1308 barrier();
1310 /* Now wait for a reply */
1311 m=i2o_wait_reply(c, "LCTNotify", 5);
1313 if(m==0xFFFFFFFF)
1314 return -ETIMEDOUT;
1316 msg=(u32 *)bus_to_virt(m);
1318 /* TODO: Check TableSize for big LCTs and send new ExecLctNotify
1319 * with bigger workspace */
1321 if(msg[4]>>24)
1322 i2o_report_status(KERN_ERR, "i2o_core", msg);
1324 return 0;
1329 * Bring a controller online. Needs completing for multiple controllers
1332 int i2o_online_controller(struct i2o_controller *c)
1334 u32 m;
1335 u32 *msg;
1336 u32 systab[32];
1337 u32 privmem[2];
1338 u32 privio[2];
1339 int ret;
1341 systab[0]=1;
1342 systab[1]=0;
1343 systab[2]=0;
1344 systab[3]=0;
1345 systab[4]=0; /* Organisation ID */
1346 systab[5]=2; /* Ident 2 for now */
1347 systab[6]=0<<24|0<<16|I2OVERSION<<12|1; /* Memory mapped, IOPState, v1.5, segment 1 */
1348 systab[7]=MSG_FRAME_SIZE>>2; /* Message size */
1349 systab[8]=0; /* LastChanged */
1350 systab[9]=0; /* Should be IOP capabilities */
1351 systab[10]=virt_to_phys(c->post_port);
1352 systab[11]=0;
1354 privmem[0]=c->priv_mem; /* Private memory space base address */
1355 privmem[1]=c->priv_mem_size;
1356 privio[0]=c->priv_io; /* Private I/O address */
1357 privio[1]=c->priv_io_size;
1359 m=i2o_wait_message(c, "SysTabSet");
1360 if(m==0xFFFFFFFF)
1361 return -ETIMEDOUT;
1363 /* Now we build the systab */
1364 msg=(u32 *)(c->mem_offset+m);
1366 msg[0] = NINE_WORD_MSG_SIZE|SGL_OFFSET_6;
1367 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
1368 msg[2] = 0; /* Context not needed */
1369 msg[3] = 0;
1370 msg[4] = (1<<16)|(2<<12); /* Host 1 I2O 2 */
1371 msg[5] = 1; /* Segment 1 */
1374 * Scatter Gather List
1377 msg[6] = 0x54000000|48; /* One table for now */
1378 msg[7] = virt_to_phys(systab);
1379 msg[8] = 0xD4000000|48; /* One table for now */
1380 msg[9] = virt_to_phys(privmem);
1381 /* msg[10] = virt_to_phys(privio); */
1383 i2o_post_message(c,m);
1385 barrier();
1388 * Now wait for a reply
1392 m=i2o_wait_reply(c, "SysTabSet", 5);
1394 if(m==0xFFFFFFFF)
1395 return -ETIMEDOUT;
1397 msg=(u32 *)bus_to_virt(m);
1399 if(msg[4]>>24)
1401 i2o_report_status(KERN_ERR, "i2o_core", msg);
1403 I2O_REPLY_WRITE32(c,m);
1406 * Finally we go online
1409 m=i2o_wait_message(c, "SysEnable");
1411 if(m==0xFFFFFFFF)
1412 return -ETIMEDOUT;
1414 msg=(u32 *)(c->mem_offset+m);
1416 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
1417 msg[1] = I2O_CMD_SYS_ENABLE<<24 | HOST_TID<<12 | ADAPTER_TID;
1418 msg[2] = 0; /* Context not needed */
1419 msg[3] = 0;
1421 i2o_post_message(c,m);
1423 barrier();
1426 * Now wait for a reply
1430 m=i2o_wait_reply(c, "SysEnable", 240);
1432 if(m==0xFFFFFFFF)
1433 return -ETIMEDOUT;
1435 msg=(u32 *)bus_to_virt(m);
1437 if(msg[4]>>24)
1439 i2o_report_status(KERN_ERR, "i2o_core", msg);
1441 I2O_REPLY_WRITE32(c,m);
1444 * Grab the LCT, see what is attached
1447 ret=i2o_lct_get(c);
1448 if(ret)
1450 /* Maybe we should do also sthg else */
1451 return ret;
1454 ret=i2o_parse_lct(c);
1455 if(ret)
1456 return ret;
1458 I2O_REPLY_WRITE32(c,m);
1460 return 0;
1464 * Run time support routines
1468 * Generic "post and forget" helpers. This is less efficient - we do
1469 * a memcpy for example that isnt strictly needed, but for most uses
1470 * this is simply not worth optimising
1473 int i2o_post_this(struct i2o_controller *c, int tid, u32 *data, int len)
1475 u32 m;
1476 u32 *msg;
1477 unsigned long t=jiffies;
1481 mb();
1482 m = I2O_POST_READ32(c);
1484 while(m==0xFFFFFFFF && (jiffies-t)<HZ);
1487 if(m==0xFFFFFFFF)
1489 printk(KERN_ERR "i2o: controller not responding.\n");
1490 return -1;
1492 msg = bus_to_virt(c->mem_offset + m);
1493 memcpy(msg, data, len);
1494 i2o_post_message(c,m);
1495 return 0;
1499 * Post a message and wait for a response flag to be set. This API will
1500 * change to use wait_queue's one day
1503 int i2o_post_wait(struct i2o_controller *c, int tid, u32 *data, int len, int *flag, int timeout)
1505 unsigned long t=jiffies;
1507 *flag = 0;
1509 if(i2o_post_this(c, tid, data, len))
1510 return I2O_POST_WAIT_TIMEOUT;
1512 while(!*flag && (jiffies-t)<timeout*HZ)
1514 schedule();
1515 mb();
1518 if (*flag < 0)
1519 return *flag; /* DetailedStatus */
1521 if (*flag == 0)
1522 return I2O_POST_WAIT_TIMEOUT;
1524 return I2O_POST_WAIT_OK;
1528 * Issue UTIL_CLAIM messages
1531 int i2o_issue_claim(struct i2o_controller *c, int tid, int context, int onoff, int *flag, u32 type)
1533 u32 msg[6];
1535 msg[0] = FIVE_WORD_MSG_SIZE | SGL_OFFSET_0;
1536 if(onoff)
1537 msg[1] = I2O_CMD_UTIL_CLAIM << 24 | HOST_TID<<12 | tid;
1538 else
1539 msg[1] = I2O_CMD_UTIL_RELEASE << 24 | HOST_TID << 12 | tid;
1541 /* The 0x80000000 convention for flagging is assumed by this helper */
1543 msg[2] = 0x80000000|context;
1544 msg[3] = (u32)flag;
1545 msg[4] = type;
1547 return i2o_post_wait(c, tid, msg, 20, flag,2);
1550 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
1552 * This function can be used for all UtilParamsGet/Set operations.
1553 * The OperationBlock is given in opblk-buffer,
1554 * and results are returned in resblk-buffer.
1555 * Note that the minimum sized resblk is 8 bytes and contains
1556 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
1558 int i2o_issue_params(int cmd,
1559 struct i2o_controller *iop, int tid, int context,
1560 void *opblk, int oplen, void *resblk, int reslen,
1561 int *flag)
1563 u32 msg[9];
1564 u8 *res = (u8 *)resblk;
1565 int res_count;
1566 int blk_size;
1567 int bytes;
1568 int wait_status;
1570 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
1571 msg[1] = cmd << 24 | HOST_TID << 12 | tid;
1572 msg[2] = context | 0x80000000;
1573 msg[3] = (u32)flag;
1574 msg[4] = 0;
1575 msg[5] = 0x54000000 | oplen; /* OperationBlock */
1576 msg[6] = virt_to_bus(opblk);
1577 msg[7] = 0xD0000000 | reslen; /* ResultBlock */
1578 msg[8] = virt_to_bus(resblk);
1580 wait_status = i2o_post_wait(iop, tid, msg, sizeof(msg), flag, 10);
1581 if (wait_status < 0)
1582 return wait_status; /* -DetailedStatus */
1584 if (res[1]&0x00FF0000) /* BlockStatus != SUCCESS */
1586 printk(KERN_WARNING "%s - Error:\n ErrorInfoSize = 0x%02x, "
1587 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
1588 (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET"
1589 : "PARAMS_GET",
1590 res[1]>>24, (res[1]>>16)&0xFF, res[1]&0xFFFF);
1591 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
1594 res_count = res[0] & 0xFFFF; /* # of resultblocks */
1595 bytes = 4;
1596 res += 4;
1597 while (res_count--)
1599 blk_size = (res[0] & 0xFFFF) << 2;
1600 bytes += blk_size;
1601 res += blk_size;
1604 return bytes; /* total sizeof Result List in bytes */
1608 * Query one scalar group value or a whole scalar group.
1610 int i2o_query_scalar(struct i2o_controller *iop, int tid, int context,
1611 int group, int field, void *buf, int buflen, int *flag)
1613 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
1614 u8 resblk[8+buflen]; /* 8 bytes for header */
1615 int size;
1617 if (field == -1) /* whole group */
1618 opblk[4] = -1;
1620 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, iop, tid, context,
1621 opblk, sizeof(opblk), resblk, sizeof(resblk), flag);
1623 if (size < 0)
1624 return size;
1626 memcpy(buf, resblk+8, buflen); /* cut off header */
1627 return buflen;
1631 * Set a scalar group value or a whole group.
1633 int i2o_set_scalar(struct i2o_controller *iop, int tid, int context,
1634 int group, int field, void *buf, int buflen, int *flag)
1636 u16 *opblk;
1637 u8 resblk[8+buflen]; /* 8 bytes for header */
1638 int size;
1640 opblk = kmalloc(buflen+64, GFP_KERNEL);
1641 if (opblk == NULL)
1643 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
1644 return -ENOMEM;
1647 opblk[0] = 1; /* operation count */
1648 opblk[1] = 0; /* pad */
1649 opblk[2] = I2O_PARAMS_FIELD_SET;
1650 opblk[3] = group;
1652 if(field == -1) { /* whole group */
1653 opblk[4] = -1;
1654 memcpy(opblk+5, buf, buflen);
1656 else /* single field */
1658 opblk[4] = 1;
1659 opblk[5] = field;
1660 memcpy(opblk+6, buf, buflen);
1663 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1664 opblk, 12+buflen, resblk, sizeof(resblk), flag);
1666 kfree(opblk);
1667 return size;
1671 * if oper == I2O_PARAMS_TABLE_GET:
1672 * Get all table group fields from all rows or
1673 * get specific table group fields from all rows.
1675 * if fieldcount == -1 we query all fields from all rows
1676 * ibuf is NULL and ibuflen is 0
1677 * else we query specific fields from all rows
1678 * ibuf contains fieldindexes
1680 * if oper == I2O_PARAMS_LIST_GET:
1681 * Get all table group fields from specified rows or
1682 * get specific table group fields from specified rows.
1684 * if fieldcount == -1 we query all fields from specified rows
1685 * ibuf contains rowcount, keyvalues
1686 * else we query specific fields from specified rows
1687 * ibuf contains fieldindexes, rowcount, keyvalues
1689 * You could also use directly function i2o_issue_params().
1691 int i2o_query_table(int oper,
1692 struct i2o_controller *iop, int tid, int context, int group,
1693 int fieldcount, void *ibuf, int ibuflen,
1694 void *resblk, int reslen, int *flag)
1696 u16 *opblk;
1697 int size;
1699 opblk = kmalloc(10 + ibuflen, GFP_KERNEL);
1700 if (opblk == NULL)
1702 printk(KERN_ERR "i2o: no memory for query buffer.\n");
1703 return -ENOMEM;
1706 opblk[0] = 1; /* operation count */
1707 opblk[1] = 0; /* pad */
1708 opblk[2] = oper;
1709 opblk[3] = group;
1710 opblk[4] = fieldcount;
1711 memcpy(opblk+5, ibuf, ibuflen); /* other params */
1713 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET,iop, tid, context,
1714 opblk, 10+ibuflen, resblk, reslen, flag);
1716 kfree(opblk);
1717 return size;
1721 * Clear table group, i.e. delete all rows.
1724 int i2o_clear_table(struct i2o_controller *iop, int tid, int context,
1725 int group, int *flag)
1727 u16 opblk[] = { 1, 0, I2O_PARAMS_TABLE_CLEAR, group };
1728 u8 resblk[32]; /* min 8 bytes for result header */
1730 return i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1731 opblk, sizeof(opblk), resblk, sizeof(resblk), flag);
1735 * Add a new row into a table group.
1737 * if fieldcount==-1 then we add whole rows
1738 * buf contains rowcount, keyvalues
1739 * else just specific fields are given, rest use defaults
1740 * buf contains fieldindexes, rowcount, keyvalues
1743 int i2o_row_add_table(struct i2o_controller *iop, int tid, int context,
1744 int group, int fieldcount, void *buf, int buflen,
1745 int *flag)
1747 u16 *opblk;
1748 u8 resblk[32]; /* min 8 bytes for header */
1749 int size;
1751 opblk = kmalloc(buflen+64, GFP_KERNEL);
1752 if (opblk == NULL)
1754 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
1755 return -ENOMEM;
1758 opblk[0] = 1; /* operation count */
1759 opblk[1] = 0; /* pad */
1760 opblk[2] = I2O_PARAMS_ROW_ADD;
1761 opblk[3] = group;
1762 opblk[4] = fieldcount;
1763 memcpy(opblk+5, buf, buflen);
1765 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1766 opblk, 10+buflen, resblk, sizeof(resblk), flag);
1768 kfree(opblk);
1769 return size;
1773 * Delete rows from a table group.
1776 int i2o_row_delete_table(struct i2o_controller *iop, int tid, int context,
1777 int group, int keycount, void *keys, int keyslen,
1778 int *flag)
1780 u16 *opblk;
1781 u8 resblk[32]; /* min 8 bytes for header */
1782 int size;
1784 opblk = kmalloc(keyslen+64, GFP_KERNEL);
1785 if (opblk == NULL)
1787 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
1788 return -ENOMEM;
1791 opblk[0] = 1; /* operation count */
1792 opblk[1] = 0; /* pad */
1793 opblk[2] = I2O_PARAMS_ROW_DELETE;
1794 opblk[3] = group;
1795 opblk[4] = keycount;
1796 memcpy(opblk+5, keys, keyslen);
1798 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1799 opblk, 10+keyslen, resblk, sizeof(resblk), flag);
1801 kfree(opblk);
1802 return size;
1805 void i2o_report_common_status(u8 req_status)
1807 /* the following reply status strings are common to all classes */
1809 static char *REPLY_STATUS[] = {
1810 "SUCCESS",
1811 "ABORT_DIRTY",
1812 "ABORT_NO_DATA_TRANSFER",
1813 "ABORT_PARTIAL_TRANSFER",
1814 "ERROR_DIRTY",
1815 "ERROR_NO_DATA_TRANSFER",
1816 "ERROR_PARTIAL_TRANSFER",
1817 "PROCESS_ABORT_DIRTY",
1818 "PROCESS_ABORT_NO_DATA_TRANSFER",
1819 "PROCESS_ABORT_PARTIAL_TRANSFER",
1820 "TRANSACTION_ERROR",
1821 "PROGRESS_REPORT"
1824 if (req_status > I2O_REPLY_STATUS_PROGRESS_REPORT)
1825 printk("%0#4x / ", req_status);
1826 else
1827 printk("%s / ", REPLY_STATUS[req_status]);
1829 return;
1832 static void i2o_report_common_dsc(u16 detailed_status)
1834 /* The following detailed statuscodes are valid
1835 - for executive class, utility class, DDM class and
1836 - for transaction error replies
1839 static char *COMMON_DSC[] = {
1840 "SUCCESS",
1841 "0x01", // not used
1842 "BAD_KEY",
1843 "TCL_ERROR",
1844 "REPLY_BUFFER_FULL",
1845 "NO_SUCH_PAGE",
1846 "INSUFFICIENT_RESOURCE_SOFT",
1847 "INSUFFICIENT_RESOURCE_HARD",
1848 "0x08", // not used
1849 "CHAIN_BUFFER_TOO_LARGE",
1850 "UNSUPPORTED_FUNCTION",
1851 "DEVICE_LOCKED",
1852 "DEVICE_RESET",
1853 "INAPPROPRIATE_FUNCTION",
1854 "INVALID_INITIATOR_ADDRESS",
1855 "INVALID_MESSAGE_FLAGS",
1856 "INVALID_OFFSET",
1857 "INVALID_PARAMETER",
1858 "INVALID_REQUEST",
1859 "INVALID_TARGET_ADDRESS",
1860 "MESSAGE_TOO_LARGE",
1861 "MESSAGE_TOO_SMALL",
1862 "MISSING_PARAMETER",
1863 "TIMEOUT",
1864 "UNKNOWN_ERROR",
1865 "UNKNOWN_FUNCTION",
1866 "UNSUPPORTED_VERSION",
1867 "DEVICE_BUSY",
1868 "DEVICE_NOT_AVAILABLE"
1871 if (detailed_status > I2O_DSC_DEVICE_NOT_AVAILABLE)
1872 printk("%0#4x.\n", detailed_status);
1873 else
1874 printk("%s.\n", COMMON_DSC[detailed_status]);
1876 return;
1879 static void i2o_report_lan_dsc(u16 detailed_status)
1881 static char *LAN_DSC[] = { // Lan detailed status code strings
1882 "SUCCESS",
1883 "DEVICE_FAILURE",
1884 "DESTINATION_NOT_FOUND",
1885 "TRANSMIT_ERROR",
1886 "TRANSMIT_ABORTED",
1887 "RECEIVE_ERROR",
1888 "RECEIVE_ABORTED",
1889 "DMA_ERROR",
1890 "BAD_PACKET_DETECTED",
1891 "OUT_OF_MEMORY",
1892 "BUCKET_OVERRUN",
1893 "IOP_INTERNAL_ERROR",
1894 "CANCELED",
1895 "INVALID_TRANSACTION_CONTEXT",
1896 "DEST_ADDRESS_DETECTED",
1897 "DEST_ADDRESS_OMITTED",
1898 "PARTIAL_PACKET_RETURNED",
1899 "TEMP_SUSPENDED_STATE", // last Lan detailed status code
1900 "INVALID_REQUEST" // general detailed status code
1903 if (detailed_status > I2O_DSC_INVALID_REQUEST)
1904 printk("%0#4x.\n", detailed_status);
1905 else
1906 printk("%s.\n", LAN_DSC[detailed_status]);
1908 return;
1911 static void i2o_report_util_cmd(u8 cmd)
1913 switch (cmd) {
1914 case I2O_CMD_UTIL_NOP:
1915 printk("UTIL_NOP, ");
1916 break;
1917 case I2O_CMD_UTIL_ABORT:
1918 printk("UTIL_ABORT, ");
1919 break;
1920 case I2O_CMD_UTIL_CLAIM:
1921 printk("UTIL_CLAIM, ");
1922 break;
1923 case I2O_CMD_UTIL_RELEASE:
1924 printk("UTIL_CLAIM_RELEASE, ");
1925 break;
1926 case I2O_CMD_UTIL_CONFIG_DIALOG:
1927 printk("UTIL_CONFIG_DIALOG, ");
1928 break;
1929 case I2O_CMD_UTIL_DEVICE_RESERVE:
1930 printk("UTIL_DEVICE_RESERVE, ");
1931 break;
1932 case I2O_CMD_UTIL_DEVICE_RELEASE:
1933 printk("UTIL_DEVICE_RELEASE, ");
1934 break;
1935 case I2O_CMD_UTIL_ACK:
1936 printk("UTIL_EVENT_ACKNOWLEDGE, ");
1937 break;
1938 case I2O_CMD_UTIL_EVT_REGISTER:
1939 printk("UTIL_EVENT_REGISTER, ");
1940 break;
1941 case I2O_CMD_UTIL_LOCK:
1942 printk("UTIL_LOCK, ");
1943 break;
1944 case I2O_CMD_UTIL_LOCK_RELEASE:
1945 printk("UTIL_LOCK_RELEASE, ");
1946 break;
1947 case I2O_CMD_UTIL_PARAMS_GET:
1948 printk("UTIL_PARAMS_GET, ");
1949 break;
1950 case I2O_CMD_UTIL_PARAMS_SET:
1951 printk("UTIL_PARAMS_SET, ");
1952 break;
1953 case I2O_CMD_UTIL_REPLY_FAULT_NOTIFY:
1954 printk("UTIL_REPLY_FAULT_NOTIFY, ");
1955 break;
1956 default:
1957 printk("%0#2x, ",cmd);
1960 return;
1964 static void i2o_report_exec_cmd(u8 cmd)
1966 switch (cmd) {
1967 case I2O_CMD_ADAPTER_ASSIGN:
1968 printk("EXEC_ADAPTER_ASSIGN, ");
1969 break;
1970 case I2O_CMD_ADAPTER_READ:
1971 printk("EXEC_ADAPTER_READ, ");
1972 break;
1973 case I2O_CMD_ADAPTER_RELEASE:
1974 printk("EXEC_ADAPTER_RELEASE, ");
1975 break;
1976 case I2O_CMD_BIOS_INFO_SET:
1977 printk("EXEC_BIOS_INFO_SET, ");
1978 break;
1979 case I2O_CMD_BOOT_DEVICE_SET:
1980 printk("EXEC_BOOT_DEVICE_SET, ");
1981 break;
1982 case I2O_CMD_CONFIG_VALIDATE:
1983 printk("EXEC_CONFIG_VALIDATE, ");
1984 break;
1985 case I2O_CMD_CONN_SETUP:
1986 printk("EXEC_CONN_SETUP, ");
1987 break;
1988 case I2O_CMD_DDM_DESTROY:
1989 printk("EXEC_DDM_DESTROY, ");
1990 break;
1991 case I2O_CMD_DDM_ENABLE:
1992 printk("EXEC_DDM_ENABLE, ");
1993 break;
1994 case I2O_CMD_DDM_QUIESCE:
1995 printk("EXEC_DDM_QUIESCE, ");
1996 break;
1997 case I2O_CMD_DDM_RESET:
1998 printk("EXEC_DDM_RESET, ");
1999 break;
2000 case I2O_CMD_DDM_SUSPEND:
2001 printk("EXEC_DDM_SUSPEND, ");
2002 break;
2003 case I2O_CMD_DEVICE_ASSIGN:
2004 printk("EXEC_DEVICE_ASSIGN, ");
2005 break;
2006 case I2O_CMD_DEVICE_RELEASE:
2007 printk("EXEC_DEVICE_RELEASE, ");
2008 break;
2009 case I2O_CMD_HRT_GET:
2010 printk("EXEC_HRT_GET, ");
2011 break;
2012 case I2O_CMD_ADAPTER_CLEAR:
2013 printk("EXEC_IOP_CLEAR, ");
2014 break;
2015 case I2O_CMD_ADAPTER_CONNECT:
2016 printk("EXEC_IOP_CONNECT, ");
2017 break;
2018 case I2O_CMD_ADAPTER_RESET:
2019 printk("EXEC_IOP_RESET, ");
2020 break;
2021 case I2O_CMD_LCT_NOTIFY:
2022 printk("EXEC_LCT_NOTIFY, ");
2023 break;
2024 case I2O_CMD_OUTBOUND_INIT:
2025 printk("EXEC_OUTBOUND_INIT, ");
2026 break;
2027 case I2O_CMD_PATH_ENABLE:
2028 printk("EXEC_PATH_ENABLE, ");
2029 break;
2030 case I2O_CMD_PATH_QUIESCE:
2031 printk("EXEC_PATH_QUIESCE, ");
2032 break;
2033 case I2O_CMD_PATH_RESET:
2034 printk("EXEC_PATH_RESET, ");
2035 break;
2036 case I2O_CMD_STATIC_MF_CREATE:
2037 printk("EXEC_STATIC_MF_CREATE, ");
2038 break;
2039 case I2O_CMD_STATIC_MF_RELEASE:
2040 printk("EXEC_STATIC_MF_RELEASE, ");
2041 break;
2042 case I2O_CMD_STATUS_GET:
2043 printk("EXEC_STATUS_GET, ");
2044 break;
2045 case I2O_CMD_SW_DOWNLOAD:
2046 printk("EXEC_SW_DOWNLOAD, ");
2047 break;
2048 case I2O_CMD_SW_UPLOAD:
2049 printk("EXEC_SW_UPLOAD, ");
2050 break;
2051 case I2O_CMD_SW_REMOVE:
2052 printk("EXEC_SW_REMOVE, ");
2053 break;
2054 case I2O_CMD_SYS_ENABLE:
2055 printk("EXEC_SYS_ENABLE, ");
2056 break;
2057 case I2O_CMD_SYS_MODIFY:
2058 printk("EXEC_SYS_MODIFY, ");
2059 break;
2060 case I2O_CMD_SYS_QUIESCE:
2061 printk("EXEC_SYS_QUIESCE, ");
2062 break;
2063 case I2O_CMD_SYS_TAB_SET:
2064 printk("EXEC_SYS_TAB_SET, ");
2065 break;
2066 default:
2067 printk("%02x, ",cmd);
2070 return;
2073 static void i2o_report_lan_cmd(u8 cmd)
2075 switch (cmd) {
2076 case LAN_PACKET_SEND:
2077 printk("LAN_PACKET_SEND, ");
2078 break;
2079 case LAN_SDU_SEND:
2080 printk("LAN_SDU_SEND, ");
2081 break;
2082 case LAN_RECEIVE_POST:
2083 printk("LAN_RECEIVE_POST, ");
2084 break;
2085 case LAN_RESET:
2086 printk("LAN_RESET, ");
2087 break;
2088 case LAN_SUSPEND:
2089 printk("LAN_SUSPEND, ");
2090 break;
2091 default:
2092 printk("%02x, ",cmd);
2095 return;
2098 /* TODO: Add support for other classes */
2099 void i2o_report_status(const char *severity, const char *module, u32 *msg)
2101 u8 cmd = (msg[1]>>24)&0xFF;
2102 u8 req_status = (msg[4]>>24)&0xFF;
2103 u16 detailed_status = msg[4]&0xFFFF;
2105 printk("%s%s: ", severity, module);
2107 if (cmd < 0x1F) { // Utility Class
2108 i2o_report_util_cmd(cmd);
2109 i2o_report_common_status(req_status);
2110 i2o_report_common_dsc(detailed_status);
2111 return;
2114 if (cmd >= 0x30 && cmd <= 0x3F) { // LAN class
2115 i2o_report_lan_cmd(cmd);
2116 i2o_report_common_status(req_status);
2117 i2o_report_lan_dsc(detailed_status);
2118 return;
2121 if (cmd >= 0xA0 && cmd <= 0xEF) { // Executive class
2122 i2o_report_exec_cmd(cmd);
2123 i2o_report_common_status(req_status);
2124 i2o_report_common_dsc(detailed_status);
2125 return;
2128 printk("%02x, %02x / %04x.\n", cmd, req_status, detailed_status);
2129 return;
2132 /* Used to dump a message to syslog during debugging */
2133 static void i2o_dump_message(u32 *msg)
2135 #ifdef DRIVERDEBUG
2136 int i;
2138 printk(KERN_INFO "Dumping I2O message @ %p\n", msg);
2139 for(i = 0; i < ((msg[0]>>16)&0xffff); i++)
2140 printk(KERN_INFO "\tmsg[%d] = %#10x\n", i, msg[i]);
2141 #endif
2144 #ifdef MODULE
2146 EXPORT_SYMBOL(i2o_install_handler);
2147 EXPORT_SYMBOL(i2o_remove_handler);
2148 EXPORT_SYMBOL(i2o_install_device);
2149 EXPORT_SYMBOL(i2o_delete_device);
2150 EXPORT_SYMBOL(i2o_quiesce_controller);
2151 EXPORT_SYMBOL(i2o_clear_controller);
2152 EXPORT_SYMBOL(i2o_install_controller);
2153 EXPORT_SYMBOL(i2o_delete_controller);
2154 EXPORT_SYMBOL(i2o_unlock_controller);
2155 EXPORT_SYMBOL(i2o_find_controller);
2156 EXPORT_SYMBOL(i2o_num_controllers);
2157 EXPORT_SYMBOL(i2o_claim_device);
2158 EXPORT_SYMBOL(i2o_release_device);
2159 EXPORT_SYMBOL(i2o_run_queue);
2160 EXPORT_SYMBOL(i2o_report_controller_unit);
2161 EXPORT_SYMBOL(i2o_activate_controller);
2162 EXPORT_SYMBOL(i2o_online_controller);
2163 EXPORT_SYMBOL(i2o_get_class_name);
2165 EXPORT_SYMBOL(i2o_query_scalar);
2166 EXPORT_SYMBOL(i2o_set_scalar);
2167 EXPORT_SYMBOL(i2o_query_table);
2168 EXPORT_SYMBOL(i2o_clear_table);
2169 EXPORT_SYMBOL(i2o_row_add_table);
2170 EXPORT_SYMBOL(i2o_row_delete_table);
2172 EXPORT_SYMBOL(i2o_post_this);
2173 EXPORT_SYMBOL(i2o_post_wait);
2174 EXPORT_SYMBOL(i2o_issue_claim);
2176 EXPORT_SYMBOL(i2o_report_status);
2178 MODULE_AUTHOR("Red Hat Software");
2179 MODULE_DESCRIPTION("I2O Core");
2182 int init_module(void)
2184 if (i2o_install_handler(&i2o_core_handler) < 0)
2186 printk(KERN_ERR "i2o_core: Unable to install core handler.\n");
2187 return 0;
2190 core_context = i2o_core_handler.context;
2193 * Attach core to I2O PCI subsystem
2195 #ifdef CONFIG_I2O_PCI_MODULE
2196 if(i2o_pci_core_attach(&i2o_core_functions) < 0)
2197 printk(KERN_INFO "No PCI I2O controllers found\n");
2198 #endif
2200 return 0;
2203 void cleanup_module(void)
2205 #ifdef CONFIG_I2O_PCI_MODULE
2206 i2o_pci_core_detach();
2207 #endif
2209 i2o_remove_handler(&i2o_core_handler);
2212 #else
2214 extern int i2o_block_init(void);
2215 extern int i2o_config_init(void);
2216 extern int i2o_lan_init(void);
2217 extern int i2o_pci_init(void);
2218 extern int i2o_proc_init(void);
2219 extern int i2o_scsi_init(void);
2221 __init int i2o_init(void)
2223 if (i2o_install_handler(&i2o_core_handler) < 0)
2225 printk(KERN_ERR "i2o_core: Unable to install core handler.\n");
2226 return 0;
2229 core_context = i2o_core_handler.context;
2230 #ifdef CONFIG_I2O_PCI
2231 i2o_pci_init();
2232 #endif
2233 i2o_config_init();
2234 #ifdef CONFIG_I2O_BLOCK
2235 i2o_block_init();
2236 #endif
2237 #ifdef CONFIG_I2O_SCSI
2238 i2o_scsi_init();
2239 #endif
2240 #ifdef CONFIG_I2O_LAN
2241 i2o_lan_init();
2242 #endif
2243 #ifdef CONFIG_I2O_PROC
2244 i2o_proc_init();
2245 #endif
2246 return 0;
2249 #endif