* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / i2o / i2o_core.c
blobfe8a86483159433c56d555a4d24f92e56e2bd6be
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 #include <linux/i2o.h>
29 #include <linux/errno.h>
30 #include <linux/init.h>
31 #include <linux/malloc.h>
32 #include <linux/spinlock.h>
34 #include <asm/io.h>
36 #include "i2o_lan.h"
38 #define DRIVERDEBUG
41 * Size of the I2O module table
44 static struct i2o_handler *i2o_handlers[MAX_I2O_MODULES];
45 static struct i2o_controller *i2o_controllers[MAX_I2O_CONTROLLERS];
46 int i2o_num_controllers = 0;
47 static int core_context = 0;
48 static int reply_flag = 0;
50 extern int i2o_online_controller(struct i2o_controller *c);
51 static void i2o_core_reply(struct i2o_handler *, struct i2o_controller *,
52 struct i2o_message *);
53 static int i2o_add_management_user(struct i2o_device *, struct i2o_handler *);
54 static int i2o_remove_management_user(struct i2o_device *, struct i2o_handler *);
55 static void i2o_dump_message(u32 *);
57 #ifdef MODULE
58 /*
59 * Function table to send to bus specific layers
60 * See <include/linux/i2o.h> for explanation of this
62 static struct i2o_core_func_table i2o_core_functions =
64 i2o_install_controller,
65 i2o_activate_controller,
66 i2o_find_controller,
67 i2o_unlock_controller,
68 i2o_run_queue,
69 i2o_delete_controller
72 #ifdef CONFIG_I2O_PCI_MODULE
73 extern int i2o_pci_core_attach(struct i2o_core_func_table *);
74 extern void i2o_pci_core_detach(void);
75 #endif /* CONFIG_I2O_PCI_MODULE */
77 #endif /* MODULE */
80 /* Message handler */
81 static struct i2o_handler i2o_core_handler =
83 (void *)i2o_core_reply,
84 "I2O core layer",
89 * I2O configuration spinlock. This isnt a big deal for contention
90 * so we have one only
93 static spinlock_t i2o_configuration_lock = SPIN_LOCK_UNLOCKED;
95 void i2o_core_reply(struct i2o_handler *h, struct i2o_controller *c,
96 struct i2o_message *m)
98 u32 *msg=(u32 *)m;
99 u32 *flag = (u32 *)msg[3];
101 #if 0
102 i2o_report_status(KERN_INFO, "i2o_core", msg);
103 #endif
105 if (msg[0] & (1<<13)) // Fail bit is set
107 printk(KERN_ERR "IOP failed to process the msg:\n");
108 printk(KERN_ERR " Cmd = 0x%02X, InitiatorTid = %d, TargetTid =%d\n",
109 (msg[1] >> 24) & 0xFF, (msg[1] >> 12) & 0xFFF, msg[1] &
110 0xFFF);
111 printk(KERN_ERR " FailureCode = 0x%02X\n Severity = 0x%02X\n"
112 "LowestVersion = 0x%02X\n HighestVersion = 0x%02X\n",
113 msg[4] >> 24, (msg[4] >> 16) & 0xFF,
114 (msg[4] >> 8) & 0xFF, msg[4] & 0xFF);
115 printk(KERN_ERR " FailingHostUnit = 0x%04X\n FailingIOP = 0x%03X\n",
116 msg[5] >> 16, msg[5] & 0xFFF);
117 return;
120 if (msg[4] >> 24)
122 i2o_report_status(KERN_WARNING, "i2o_core", msg);
123 *flag = -(msg[4] & 0xFFFF);
125 else
126 *flag = I2O_POST_WAIT_OK;
130 * Install an I2O handler - these handle the asynchronous messaging
131 * from the card once it has initialised.
134 int i2o_install_handler(struct i2o_handler *h)
136 int i;
137 spin_lock(&i2o_configuration_lock);
138 for(i=0;i<MAX_I2O_MODULES;i++)
140 if(i2o_handlers[i]==NULL)
142 h->context = i;
143 i2o_handlers[i]=h;
144 spin_unlock(&i2o_configuration_lock);
145 return 0;
148 spin_unlock(&i2o_configuration_lock);
149 return -ENOSPC;
152 int i2o_remove_handler(struct i2o_handler *h)
154 i2o_handlers[h->context]=NULL;
155 return 0;
160 * Each I2O controller has a chain of devices on it - these match
161 * the useful parts of the LCT of the board.
164 int i2o_install_device(struct i2o_controller *c, struct i2o_device *d)
166 int i;
168 spin_lock(&i2o_configuration_lock);
169 d->controller=c;
170 d->owner=NULL;
171 d->next=c->devices;
172 c->devices=d;
173 *d->dev_name = 0;
174 d->owner = NULL;
176 for(i = 0; i < I2O_MAX_MANAGERS; i++)
177 d->managers[i] = NULL;
179 spin_unlock(&i2o_configuration_lock);
180 return 0;
183 /* we need this version to call out of i2o_delete_controller */
185 int __i2o_delete_device(struct i2o_device *d)
187 struct i2o_device **p;
189 p=&(d->controller->devices);
192 * Hey we have a driver!
195 if(d->owner)
196 return -EBUSY;
199 * Seek, locate
202 while(*p!=NULL)
204 if(*p==d)
207 * Destroy
209 *p=d->next;
210 kfree(d);
211 return 0;
213 p=&((*p)->next);
215 printk(KERN_ERR "i2o_delete_device: passed invalid device.\n");
216 return -EINVAL;
219 int i2o_delete_device(struct i2o_device *d)
221 int ret;
223 spin_lock(&i2o_configuration_lock);
225 ret = __i2o_delete_device(d);
227 spin_unlock(&i2o_configuration_lock);
229 return ret;
233 * Add and remove controllers from the I2O controller list
236 int i2o_install_controller(struct i2o_controller *c)
238 int i;
239 spin_lock(&i2o_configuration_lock);
240 for(i=0;i<MAX_I2O_CONTROLLERS;i++)
242 if(i2o_controllers[i]==NULL)
244 i2o_controllers[i]=c;
245 c->next=i2o_controller_chain;
246 i2o_controller_chain=c;
247 c->unit = i;
248 sprintf(c->name, "i2o/iop%d", i);
249 i2o_num_controllers++;
250 spin_unlock(&i2o_configuration_lock);
251 return 0;
254 printk(KERN_ERR "No free i2o controller slots.\n");
255 spin_unlock(&i2o_configuration_lock);
256 return -EBUSY;
259 int i2o_delete_controller(struct i2o_controller *c)
261 struct i2o_controller **p;
262 int users;
264 spin_lock(&i2o_configuration_lock);
265 if((users=atomic_read(&c->users)))
267 printk("I2O: %d users for controller iop%d\n", users, c->unit);
268 spin_unlock(&i2o_configuration_lock);
269 return -EBUSY;
271 while(c->devices)
273 if(__i2o_delete_device(c->devices)<0)
275 /* Shouldnt happen */
276 spin_unlock(&i2o_configuration_lock);
277 return -EBUSY;
281 p=&i2o_controller_chain;
283 /* Send first SysQuiesce to other IOPs */
284 while(*p)
286 if(*p!=c)
288 printk("Quiescing controller %p != %p\n", c, *p);
289 if(i2o_quiesce_controller(*p)<0)
290 printk(KERN_INFO "Unable to quiesce iop%d\n",
291 (*p)->unit);
293 p=&((*p)->next);
296 p=&i2o_controller_chain;
298 while(*p)
300 if(*p==c)
302 /* Ask the IOP to switch to HOLD state */
303 if (i2o_clear_controller(c) < 0)
304 printk("Unable to clear iop%d\n", c->unit);
306 /* Release IRQ */
307 c->destructor(c);
309 *p=c->next;
310 spin_unlock(&i2o_configuration_lock);
311 if(c->page_frame)
312 kfree(c->page_frame);
313 if(c->hrt)
314 kfree(c->hrt);
315 if(c->lct)
316 kfree(c->lct);
317 i2o_controllers[c->unit]=NULL;
318 kfree(c);
319 i2o_num_controllers--;
320 return 0;
322 p=&((*p)->next);
324 spin_unlock(&i2o_configuration_lock);
325 printk(KERN_ERR "i2o_delete_controller: bad pointer!\n");
326 return -ENOENT;
329 void i2o_unlock_controller(struct i2o_controller *c)
331 atomic_dec(&c->users);
334 struct i2o_controller *i2o_find_controller(int n)
336 struct i2o_controller *c;
338 if(n<0 || n>=MAX_I2O_CONTROLLERS)
339 return NULL;
341 spin_lock(&i2o_configuration_lock);
342 c=i2o_controllers[n];
343 if(c!=NULL)
344 atomic_inc(&c->users);
345 spin_unlock(&i2o_configuration_lock);
346 return c;
351 * Claim a device for use as either the primary user or just
352 * as a management/secondary user
354 int i2o_claim_device(struct i2o_device *d, struct i2o_handler *h, u32 type)
356 /* Device already has a primary user or too many managers */
357 if((type == I2O_CLAIM_PRIMARY && d->owner) ||
358 (d->num_managers == I2O_MAX_MANAGERS))
360 return -EBUSY;
363 if(i2o_issue_claim(d->controller,d->id, h->context, 1, &reply_flag, type) < 0)
365 return -EBUSY;
368 spin_lock(&i2o_configuration_lock);
369 if(d->owner)
371 spin_unlock(&i2o_configuration_lock);
372 return -EBUSY;
374 atomic_inc(&d->controller->users);
376 if(type == I2O_CLAIM_PRIMARY)
377 d->owner=h;
378 else
379 i2o_add_management_user(d, h);
381 spin_unlock(&i2o_configuration_lock);
382 return 0;
385 int i2o_release_device(struct i2o_device *d, struct i2o_handler *h, u32 type)
387 int err = 0;
389 spin_lock(&i2o_configuration_lock);
391 /* Primary user */
392 if(type == I2O_CLAIM_PRIMARY)
394 if(d->owner != h)
395 err = -ENOENT;
396 else
398 if(i2o_issue_claim(d->controller, d->id, h->context, 0,
399 &reply_flag, type) < 0)
401 err = -ENXIO;
403 else
405 d->owner = NULL;
406 atomic_dec(&d->controller->users);
410 spin_unlock(&i2o_configuration_lock);
411 return err;
414 /* Management or other user */
415 if(i2o_remove_management_user(d, h))
416 err = -ENOENT;
417 else
419 atomic_dec(&d->controller->users);
421 if(i2o_issue_claim(d->controller,d->id, h->context, 0,
422 &reply_flag, type) < 0)
423 err = -ENXIO;
426 spin_unlock(&i2o_configuration_lock);
427 return err;
430 int i2o_add_management_user(struct i2o_device *d, struct i2o_handler *h)
432 int i;
434 if(d->num_managers == I2O_MAX_MANAGERS)
435 return 1;
437 for(i = 0; i < I2O_MAX_MANAGERS; i++)
438 if(!d->managers[i])
439 d->managers[i] = h;
441 d->num_managers++;
443 return 0;
446 int i2o_remove_management_user(struct i2o_device *d, struct i2o_handler *h)
448 int i;
450 for(i=0; i < I2O_MAX_MANAGERS; i++)
452 if(d->managers[i] == h)
454 d->managers[i] = NULL;
455 return 0;
459 return -ENOENT;
463 * This is called by the bus specific driver layer when an interrupt
464 * or poll of this card interface is desired.
467 void i2o_run_queue(struct i2o_controller *c)
469 struct i2o_message *m;
470 u32 mv;
472 while((mv=I2O_REPLY_READ32(c))!=0xFFFFFFFF)
474 struct i2o_handler *i;
475 m=(struct i2o_message *)bus_to_virt(mv);
477 * Temporary Debugging
479 if(((m->function_addr>>24)&0xFF)==0x15)
480 printk("UTFR!\n");
481 // printk("dispatching.\n");
482 i=i2o_handlers[m->initiator_context&(MAX_I2O_MODULES-1)];
483 if(i)
484 i->reply(i,c,m);
485 else
487 printk("Spurious reply to handler %d\n",
488 m->initiator_context&(MAX_I2O_MODULES-1));
489 i2o_dump_message((u32*)m);
491 i2o_flush_reply(c,mv);
492 mb();
498 * Do i2o class name lookup
500 const char *i2o_get_class_name(int class)
502 int idx = 16;
503 static char *i2o_class_name[] = {
504 "Executive",
505 "Device Driver Module",
506 "Block Device",
507 "Tape Device",
508 "LAN Interface",
509 "WAN Interface",
510 "Fibre Channel Port",
511 "Fibre Channel Device",
512 "SCSI Device",
513 "ATE Port",
514 "ATE Device",
515 "Floppy Controller",
516 "Floppy Device",
517 "Secondary Bus Port",
518 "Peer Transport Agent",
519 "Peer Transport",
520 "Unknown"
523 switch(class&0xFFF)
525 case I2O_CLASS_EXECUTIVE:
526 idx = 0; break;
527 case I2O_CLASS_DDM:
528 idx = 1; break;
529 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
530 idx = 2; break;
531 case I2O_CLASS_SEQUENTIAL_STORAGE:
532 idx = 3; break;
533 case I2O_CLASS_LAN:
534 idx = 4; break;
535 case I2O_CLASS_WAN:
536 idx = 5; break;
537 case I2O_CLASS_FIBRE_CHANNEL_PORT:
538 idx = 6; break;
539 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
540 idx = 7; break;
541 case I2O_CLASS_SCSI_PERIPHERAL:
542 idx = 8; break;
543 case I2O_CLASS_ATE_PORT:
544 idx = 9; break;
545 case I2O_CLASS_ATE_PERIPHERAL:
546 idx = 10; break;
547 case I2O_CLASS_FLOPPY_CONTROLLER:
548 idx = 11; break;
549 case I2O_CLASS_FLOPPY_DEVICE:
550 idx = 12; break;
551 case I2O_CLASS_BUS_ADAPTER_PORT:
552 idx = 13; break;
553 case I2O_CLASS_PEER_TRANSPORT_AGENT:
554 idx = 14; break;
555 case I2O_CLASS_PEER_TRANSPORT:
556 idx = 15; break;
559 return i2o_class_name[idx];
564 * Wait up to 5 seconds for a message slot to be available.
567 u32 i2o_wait_message(struct i2o_controller *c, char *why)
569 long time=jiffies;
570 u32 m;
571 while((m=I2O_POST_READ32(c))==0xFFFFFFFF)
573 if((jiffies-time)>=5*HZ)
575 printk(KERN_ERR "%s: Timeout waiting for message frame to send %s.\n",
576 c->name, why);
577 return 0xFFFFFFFF;
579 schedule();
580 barrier();
582 return m;
587 * Wait up to timeout seconds for a reply to be available.
590 u32 i2o_wait_reply(struct i2o_controller *c, char *why, int timeout)
592 u32 m;
593 long time=jiffies;
595 while((m=I2O_REPLY_READ32(c))==0xFFFFFFFF)
597 if(jiffies-time >= timeout*HZ )
599 printk(KERN_ERR "%s: timeout waiting for %s reply.\n",
600 c->name, why);
601 return 0xFFFFFFFF;
603 schedule();
605 return m;
609 static int i2o_query_scalar_polled(struct i2o_controller *c, int tid, void *buf, int buflen,
610 int group, int field)
612 u32 m;
613 u32 *msg;
614 u16 op[8];
615 u32 *p;
616 int i;
617 u32 *rbuf;
619 op[0]=1; /* One Operation */
620 op[1]=0; /* PAD */
621 op[2]=1; /* FIELD_GET */
622 op[3]=group; /* group number */
623 op[4]=1; /* 1 field */
624 op[5]=field; /* Field number */
626 m=i2o_wait_message(c, "ParamsGet");
627 if(m==0xFFFFFFFF)
629 return -ETIMEDOUT;
632 msg=(u32 *)(c->mem_offset+m);
634 rbuf=kmalloc(buflen+32, GFP_KERNEL);
635 if(rbuf==NULL)
637 printk(KERN_ERR "No free memory for scalar read.\n");
638 return -ENOMEM;
641 msg[0]=NINE_WORD_MSG_SIZE|SGL_OFFSET_5;
642 msg[1]=I2O_CMD_UTIL_PARAMS_GET<<24|HOST_TID<<12|tid;
643 msg[2]=0; /* Context */
644 msg[3]=0;
645 msg[4]=0;
646 msg[5]=0x54000000|12;
647 msg[6]=virt_to_bus(op);
648 msg[7]=0xD0000000|(32+buflen);
649 msg[8]=virt_to_bus(rbuf);
651 i2o_post_message(c,m);
652 barrier();
655 * Now wait for a reply
658 m=i2o_wait_reply(c, "ParamsGet", 5);
660 if(m==0xFFFFFFFF)
662 kfree(rbuf);
663 return -ETIMEDOUT;
666 msg = (u32 *)bus_to_virt(m);
667 if(msg[4]>>24)
669 i2o_report_status(KERN_WARNING, "i2o_core", msg);
672 p=rbuf;
674 /* Ok 'p' is the reply block - lets see what happened */
675 /* p0->p2 are the header */
677 /* FIXME: endians - turn p3 to little endian */
679 if((p[0]&0xFFFF)!=1)
680 printk(KERN_WARNING "Suspicious field read return 0x%08X\n", p[0]);
682 i=(p[1]&0xFFFF)<<2; /* Message size */
683 if(i<buflen)
684 buflen=i;
686 /* Do we have an error block ? */
687 if(p[1]&0xFF000000)
689 printk(KERN_ERR "%s: error in field read.\n",
690 c->name);
691 kfree(rbuf);
692 return -EBADR;
695 /* p[1] holds the more flag and row count - we dont care */
697 /* Ok it worked p[2]-> hold the data */
698 memcpy(buf, p+2, buflen);
700 kfree(rbuf);
702 /* Finally return the message */
703 I2O_REPLY_WRITE32(c,m);
704 return buflen;
708 * Dump the information block associated with a given unit (TID)
711 void i2o_report_controller_unit(struct i2o_controller *c, int unit)
713 char buf[64];
715 if(i2o_query_scalar_polled(c, unit, buf, 16, 0xF100, 3)>=0)
717 buf[16]=0;
718 printk(KERN_INFO " Vendor: %s\n", buf);
720 if(i2o_query_scalar_polled(c, unit, buf, 16, 0xF100, 4)>=0)
722 buf[16]=0;
723 printk(KERN_INFO " Device: %s\n", buf);
725 #if 0
726 if(i2o_query_scalar_polled(c, unit, buf, 16, 0xF100, 5)>=0)
728 buf[16]=0;
729 printk(KERN_INFO "Description: %s\n", buf);
731 #endif
732 if(i2o_query_scalar_polled(c, unit, buf, 8, 0xF100, 6)>=0)
734 buf[8]=0;
735 printk(KERN_INFO " Rev: %s\n", buf);
741 * Parse the hardware resource table. Right now we print it out
742 * and don't do a lot with it. We should collate these and then
743 * interact with the Linux resource allocation block.
745 * Lets prove we can read it first eh ?
747 * This is full of endianisms!
750 static int i2o_parse_hrt(struct i2o_controller *c)
752 u32 *rows=c->hrt;
753 u8 *p=(u8 *)c->hrt;
754 u8 *d;
755 int count;
756 int length;
757 int i;
758 int state;
760 if(p[3]!=0)
762 printk(KERN_ERR "i2o: HRT table for controller is too new a version.\n");
763 return -1;
766 count=p[0]|(p[1]<<8);
767 length = p[2];
769 printk(KERN_INFO "HRT has %d entries of %d bytes each.\n",
770 count, length<<2);
772 rows+=2;
774 for(i=0;i<count;i++)
776 printk(KERN_INFO "Adapter %08X: ", rows[0]);
777 p=(u8 *)(rows+1);
778 d=(u8 *)(rows+2);
779 state=p[1]<<8|p[0];
781 printk("TID %04X:[", state&0xFFF);
782 state>>=12;
783 if(state&(1<<0))
784 printk("H"); /* Hidden */
785 if(state&(1<<2))
787 printk("P"); /* Present */
788 if(state&(1<<1))
789 printk("C"); /* Controlled */
791 if(state>9)
792 printk("*"); /* Hard */
794 printk("]:");
796 switch(p[3]&0xFFFF)
798 case 0:
799 /* Adapter private bus - easy */
800 printk("Local bus %d: I/O at 0x%04X Mem 0x%08X",
801 p[2], d[1]<<8|d[0], *(u32 *)(d+4));
802 break;
803 case 1:
804 /* ISA bus */
805 printk("ISA %d: CSN %d I/O at 0x%04X Mem 0x%08X",
806 p[2], d[2], d[1]<<8|d[0], *(u32 *)(d+4));
807 break;
809 case 2: /* EISA bus */
810 printk("EISA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
811 p[2], d[3], d[1]<<8|d[0], *(u32 *)(d+4));
812 break;
814 case 3: /* MCA bus */
815 printk("MCA %d: Slot %d I/O at 0x%04X Mem 0x%08X",
816 p[2], d[3], d[1]<<8|d[0], *(u32 *)(d+4));
817 break;
819 case 4: /* PCI bus */
820 printk("PCI %d: Bus %d Device %d Function %d",
821 p[2], d[2], d[1], d[0]);
822 break;
824 case 0x80: /* Other */
825 default:
826 printk("Unsupported bus type.");
827 break;
829 printk("\n");
830 rows+=length;
832 return 0;
836 * The logical configuration table tells us what we can talk to
837 * on the board. Most of the stuff isn't interesting to us.
840 static int i2o_parse_lct(struct i2o_controller *c)
842 int i;
843 int max;
844 int tid;
845 u32 *p;
846 struct i2o_device *d;
847 char str[22];
848 u32 *lct=(u32 *)c->lct;
850 max=lct[0]&0xFFFF;
852 max-=3;
853 max/=9;
855 if(max==0)
857 printk(KERN_ERR "LCT is empty????\n");
858 return -1;
861 printk(KERN_INFO "LCT has %d entries.\n", max);
863 if(max > 128)
865 printk(KERN_INFO "LCT was truncated.\n");
866 max=128;
869 if(lct[1]&(1<<0))
870 printk(KERN_WARNING "Configuration dialog desired.\n");
872 p=lct+3;
874 for(i=0;i<max;i++)
876 d = (struct i2o_device *)kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
877 if(d==NULL)
879 printk("i2o_core: Out of memory for LCT data.\n");
880 return -ENOMEM;
883 d->controller = c;
884 d->next = NULL;
886 d->id = tid = (p[0]>>16)&0xFFF;
887 d->class = p[3]&0xFFF;
888 d->subclass = p[4]&0xFFF;
889 d->parent = (p[5]>>12)&0xFFF;
890 d->flags = 0;
892 printk(KERN_INFO "TID %d.\n", tid);
894 i2o_report_controller_unit(c, tid);
896 i2o_install_device(c, d);
898 printk(KERN_INFO " Class: ");
900 sprintf(str, "%-21s", i2o_get_class_name(d->class));
901 printk("%s", str);
903 printk(" Subclass: 0x%03X Flags: ",
904 d->subclass);
906 if(p[2]&(1<<0))
907 printk("C"); // ConfigDialog requested
908 if(p[2]&(1<<1))
909 printk("M"); // Multi-user capable
910 if(!(p[2]&(1<<4)))
911 printk("P"); // Peer service enabled!
912 if(!(p[2]&(1<<5)))
913 printk("m"); // Mgmt service enabled!
914 printk("\n");
915 p+=9;
917 return 0;
920 /* Quiesce IOP */
921 int i2o_quiesce_controller(struct i2o_controller *c)
923 u32 msg[4];
925 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
926 msg[1]=I2O_CMD_SYS_QUIESCE<<24|HOST_TID<<12|ADAPTER_TID;
927 msg[2]=core_context;
928 msg[3]=(u32)&reply_flag;
930 /* Long timeout needed for quiesce if lots of devices */
931 return i2o_post_wait(c, ADAPTER_TID, msg, sizeof(msg), &reply_flag, 120);
935 int i2o_clear_controller(struct i2o_controller *c)
937 u32 msg[4];
939 /* First stop external operations for this IOP */
940 if(i2o_quiesce_controller(c)<0)
941 printk(KERN_INFO "Unable to quiesce iop%d\n", c->unit);
942 else
943 printk(KERN_INFO "Iop%d quiesced\n", c->unit);
945 /* Then clear the IOP */
946 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
947 msg[1]=I2O_CMD_ADAPTER_CLEAR<<24|HOST_TID<<12|ADAPTER_TID;
948 msg[2]=core_context;
949 msg[3]=(u32)&reply_flag;
951 return i2o_post_wait(c, ADAPTER_TID, msg, sizeof(msg), &reply_flag, 10);
955 /* Reset the IOP to sane state */
956 static int i2o_reset_controller(struct i2o_controller *c)
958 u32 m;
959 u8 *work8;
960 u32 *msg;
961 long time;
962 struct i2o_controller *iop;
964 /* First stop external operations */
965 for(iop=i2o_controller_chain; iop != NULL; iop=iop->next)
967 /* Quiesce is rejected on hold state */
968 if(iop->status != ADAPTER_STATE_HOLD)
970 if(i2o_quiesce_controller(iop)<0)
971 printk(KERN_INFO "Unable to quiesce iop%d\n",
972 iop->unit);
973 else
974 printk(KERN_DEBUG "%s quiesced\n", iop->name);
978 /* Then reset the IOP */
979 m=i2o_wait_message(c, "AdapterReset");
980 if(m==0xFFFFFFFF)
981 return -ETIMEDOUT;
983 msg=(u32 *)(c->mem_offset+m);
985 work8=(void *)kmalloc(4, GFP_KERNEL);
986 if(work8==NULL) {
987 printk(KERN_ERR "IOP reset failed - no free memory.\n");
988 return -ENOMEM;
991 memset(work8, 0, 4);
993 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
994 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
995 msg[2]=core_context;
996 msg[3]=(u32)&reply_flag;
997 msg[4]=0;
998 msg[5]=0;
999 msg[6]=virt_to_phys(work8);
1000 msg[7]=0; /* 64bit host FIXME */
1002 i2o_post_message(c,m);
1004 /* Wait for a reply */
1005 time=jiffies;
1007 while(work8[0]==0x01)
1009 if((jiffies-time)>=5*HZ)
1011 printk(KERN_ERR "IOP reset timeout.\n");
1012 kfree(work8);
1013 return -ETIMEDOUT;
1015 schedule();
1016 barrier();
1019 if (work8[0]==0x02)
1020 printk(KERN_WARNING "IOP Reset rejected\n");
1022 return 0;
1026 int i2o_status_get(struct i2o_controller *c)
1028 long time;
1029 u32 m;
1030 u32 *msg;
1031 u8 *status_block;
1033 status_block=(void *)kmalloc(88, GFP_KERNEL);
1034 if(status_block==NULL)
1036 printk(KERN_ERR "StatusGet failed - no free memory.\n");
1037 return -ENOMEM;
1040 m=i2o_wait_message(c, "StatusGet");
1041 if(m==0xFFFFFFFF)
1042 return -ETIMEDOUT;
1044 msg=(u32 *)(c->mem_offset+m);
1046 msg[0]=NINE_WORD_MSG_SIZE|SGL_OFFSET_0;
1047 msg[1]=I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID;
1048 msg[2]=core_context;
1049 msg[3]=0;
1050 msg[4]=0;
1051 msg[5]=0;
1052 msg[6]=virt_to_phys(status_block);
1053 msg[7]=0; /* 64bit host FIXME */
1054 msg[8]=88;
1056 i2o_post_message(c,m);
1058 /* Wait for a reply */
1059 time=jiffies;
1061 while(status_block[87]!=0xFF)
1063 if((jiffies-time)>=5*HZ)
1065 printk(KERN_ERR "IOP get status timeout.\n");
1066 return -ETIMEDOUT;
1068 schedule();
1069 barrier();
1072 /* Ok the reply has arrived. Fill in the important stuff */
1073 c->status = status_block[10];
1074 c->i2oversion = (status_block[9]>>4)&0xFF;
1075 c->inbound_size = (status_block[12]|(status_block[13]<<8))*4;
1077 return 0;
1081 int i2o_hrt_get(struct i2o_controller *c)
1083 u32 m;
1084 u32 *msg;
1086 c->hrt=kmalloc(2048, GFP_KERNEL);
1087 if(c->hrt==NULL)
1089 printk(KERN_ERR "IOP init failed; no memory.\n");
1090 return -ENOMEM;
1093 m=i2o_wait_message(c, "HRTGet");
1094 if(m==0xFFFFFFFF)
1095 return -ETIMEDOUT;
1097 msg=(u32 *)(c->mem_offset+m);
1099 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
1100 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
1101 msg[2]= core_context;
1102 msg[3]= 0x0; /* Transaction context */
1103 msg[4]= (0xD0000000 | 2048); /* Simple transaction , 2K */
1104 msg[5]= virt_to_phys(c->hrt); /* Dump it here */
1106 i2o_post_message(c,m);
1108 barrier();
1110 /* Now wait for a reply */
1111 m=i2o_wait_reply(c, "HRTGet", 5);
1113 if(m==0xFFFFFFFF)
1114 return -ETIMEDOUT;
1116 msg=(u32 *)bus_to_virt(m);
1118 if(msg[4]>>24)
1119 i2o_report_status(KERN_WARNING, "i2o_core", msg);
1121 I2O_REPLY_WRITE32(c,m);
1123 return 0;
1128 * Bring an I2O controller into HOLD state. See the 1.5
1129 * spec. Basically we go
1131 * Wait for the message queue to initialise.
1132 * If it didnt -> controller is dead
1134 * Send a get status using the message queue
1135 * Poll for a reply block 88 bytes long
1137 * Send an initialise outbound queue
1138 * Poll for a reply
1140 * Post our blank messages to the queue FIFO
1142 * Send GetHRT, Parse it
1145 int i2o_activate_controller(struct i2o_controller *c)
1147 long time;
1148 u32 m;
1149 u8 *workspace;
1150 u32 *msg;
1151 int i;
1152 int ret;
1154 printk(KERN_INFO "Configuring I2O controller at 0x%08X.\n",
1155 (u32)c->mem_phys);
1157 if((ret=i2o_status_get(c)))
1158 return ret;
1160 if(c->status == ADAPTER_STATE_FAULTED) /* not likely to be seen */
1162 printk(KERN_CRIT "i2o: iop%d has hardware fault\n",
1163 c->unit);
1164 return -1;
1168 * If the board is running, reset it - we have no idea
1169 * what kind of a mess the previous owner left it in.
1171 if(c->status == ADAPTER_STATE_HOLD ||
1172 c->status == ADAPTER_STATE_READY ||
1173 c->status == ADAPTER_STATE_OPERATIONAL ||
1174 c->status == ADAPTER_STATE_FAILED)
1176 if((ret=i2o_reset_controller(c)))
1177 return ret;
1179 if((ret=i2o_status_get(c)))
1180 return ret;
1183 workspace = (void *)kmalloc(88, GFP_KERNEL);
1184 if(workspace==NULL)
1186 printk(KERN_ERR "IOP initialisation failed - no free memory.\n");
1187 return -ENOMEM;
1190 memset(workspace, 0, 88);
1192 m=i2o_wait_message(c, "OutboundInit");
1193 if(m==0xFFFFFFFF)
1195 kfree(workspace);
1196 return -ETIMEDOUT;
1199 msg=(u32 *)(c->mem_offset+m);
1201 msg[0]= EIGHT_WORD_MSG_SIZE| TRL_OFFSET_6;
1202 msg[1]= I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID;
1203 msg[2]= core_context;
1204 msg[3]= 0x0106; /* Transaction context */
1205 msg[4]= 4096; /* Host page frame size */
1206 msg[5]= MSG_FRAME_SIZE<<16|0x80; /* Outbound msg frame size and Initcode */
1207 msg[6]= 0xD0000004; /* Simple SG LE, EOB */
1208 msg[7]= virt_to_phys(workspace);
1209 *((u32 *)workspace)=0;
1212 * Post it
1215 i2o_post_message(c,m);
1217 barrier();
1219 time=jiffies;
1221 while(workspace[0]!=I2O_CMD_OUTBOUND_INIT_COMPLETE)
1223 if((jiffies-time)>=5*HZ)
1225 printk(KERN_ERR "IOP outbound initialise failed.\n");
1226 kfree(workspace);
1227 return -ETIMEDOUT;
1229 schedule();
1230 barrier();
1233 kfree(workspace);
1235 /* TODO: v2.0: Set Executive class group 000Bh - OS Operating Info */
1237 c->page_frame = kmalloc(MSG_POOL_SIZE, GFP_KERNEL);
1238 if(c->page_frame==NULL)
1240 printk(KERN_ERR "IOP init failed: no memory for message page.\n");
1241 return -ENOMEM;
1244 m=virt_to_phys(c->page_frame);
1246 for(i=0; i< NMBR_MSG_FRAMES; i++)
1248 I2O_REPLY_WRITE32(c,m);
1249 mb();
1250 m+=MSG_FRAME_SIZE;
1254 * The outbound queue is initialised and loaded,
1256 * Now we need the Hardware Resource Table. We must ask for
1257 * this next we can't issue random messages yet.
1259 ret=i2o_hrt_get(c);
1260 if(ret)
1261 return ret;
1263 ret=i2o_parse_hrt(c);
1264 if(ret)
1265 return ret;
1267 return i2o_online_controller(c);
1268 // i2o_report_controller_unit(c, ADAPTER_TID);
1272 int i2o_lct_get(struct i2o_controller *c)
1274 u32 m;
1275 u32 *msg;
1277 m=i2o_wait_message(c, "LCTNotify");
1279 if(m==0xFFFFFFFF)
1280 return -ETIMEDOUT;
1282 msg=(u32 *)(c->mem_offset+m);
1284 c->lct = kmalloc(8192, GFP_KERNEL);
1285 if(c->lct==NULL)
1287 msg[0]=FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
1288 msg[1]= HOST_TID<<12|ADAPTER_TID; /* NOP */
1289 i2o_post_message(c,m);
1290 printk(KERN_ERR "No free memory for i2o controller buffer.\n");
1291 return -ENOMEM;
1294 memset(c->lct, 0, 8192);
1296 msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;
1297 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
1298 msg[2] = 0; /* Context not needed */
1299 msg[3] = 0;
1300 msg[4] = 0xFFFFFFFF; /* All devices */
1301 msg[5] = 0x00000000; /* Report now */
1302 msg[6] = 0xD0000000|8192;
1303 msg[7] = virt_to_bus(c->lct);
1305 i2o_post_message(c,m);
1307 barrier();
1309 /* Now wait for a reply */
1310 m=i2o_wait_reply(c, "LCTNotify", 5);
1312 if(m==0xFFFFFFFF)
1313 return -ETIMEDOUT;
1315 msg=(u32 *)bus_to_virt(m);
1317 /* TODO: Check TableSize for big LCTs and send new ExecLctNotify
1318 * with bigger workspace */
1320 if(msg[4]>>24)
1321 i2o_report_status(KERN_ERR, "i2o_core", msg);
1323 return 0;
1328 * Bring a controller online. Needs completing for multiple controllers
1331 int i2o_online_controller(struct i2o_controller *c)
1333 u32 m;
1334 u32 *msg;
1335 u32 systab[32];
1336 u32 privmem[2];
1337 u32 privio[2];
1338 int ret;
1340 systab[0]=1;
1341 systab[1]=0;
1342 systab[2]=0;
1343 systab[3]=0;
1344 systab[4]=0; /* Organisation ID */
1345 systab[5]=2; /* Ident 2 for now */
1346 systab[6]=0<<24|0<<16|I2OVERSION<<12|1; /* Memory mapped, IOPState, v1.5, segment 1 */
1347 systab[7]=MSG_FRAME_SIZE>>2; /* Message size */
1348 systab[8]=0; /* LastChanged */
1349 systab[9]=0; /* Should be IOP capabilities */
1350 systab[10]=virt_to_phys(c->post_port);
1351 systab[11]=0;
1353 privmem[0]=c->priv_mem; /* Private memory space base address */
1354 privmem[1]=c->priv_mem_size;
1355 privio[0]=c->priv_io; /* Private I/O address */
1356 privio[1]=c->priv_io_size;
1358 m=i2o_wait_message(c, "SysTabSet");
1359 if(m==0xFFFFFFFF)
1360 return -ETIMEDOUT;
1362 /* Now we build the systab */
1363 msg=(u32 *)(c->mem_offset+m);
1365 msg[0] = NINE_WORD_MSG_SIZE|SGL_OFFSET_6;
1366 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
1367 msg[2] = 0; /* Context not needed */
1368 msg[3] = 0;
1369 msg[4] = (1<<16)|(2<<12); /* Host 1 I2O 2 */
1370 msg[5] = 1; /* Segment 1 */
1373 * Scatter Gather List
1376 msg[6] = 0x54000000|48; /* One table for now */
1377 msg[7] = virt_to_phys(systab);
1378 msg[8] = 0xD4000000|48; /* One table for now */
1379 msg[9] = virt_to_phys(privmem);
1380 /* msg[10] = virt_to_phys(privio); */
1382 i2o_post_message(c,m);
1384 barrier();
1387 * Now wait for a reply
1391 m=i2o_wait_reply(c, "SysTabSet", 5);
1393 if(m==0xFFFFFFFF)
1394 return -ETIMEDOUT;
1396 msg=(u32 *)bus_to_virt(m);
1398 if(msg[4]>>24)
1400 i2o_report_status(KERN_ERR, "i2o_core", msg);
1402 I2O_REPLY_WRITE32(c,m);
1405 * Finally we go online
1408 m=i2o_wait_message(c, "SysEnable");
1410 if(m==0xFFFFFFFF)
1411 return -ETIMEDOUT;
1413 msg=(u32 *)(c->mem_offset+m);
1415 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
1416 msg[1] = I2O_CMD_SYS_ENABLE<<24 | HOST_TID<<12 | ADAPTER_TID;
1417 msg[2] = 0; /* Context not needed */
1418 msg[3] = 0;
1420 i2o_post_message(c,m);
1422 barrier();
1425 * Now wait for a reply
1429 m=i2o_wait_reply(c, "SysEnable", 240);
1431 if(m==0xFFFFFFFF)
1432 return -ETIMEDOUT;
1434 msg=(u32 *)bus_to_virt(m);
1436 if(msg[4]>>24)
1438 i2o_report_status(KERN_ERR, "i2o_core", msg);
1440 I2O_REPLY_WRITE32(c,m);
1443 * Grab the LCT, see what is attached
1446 ret=i2o_lct_get(c);
1447 if(ret)
1449 /* Maybe we should do also sthg else */
1450 return ret;
1453 ret=i2o_parse_lct(c);
1454 if(ret)
1455 return ret;
1457 I2O_REPLY_WRITE32(c,m);
1459 return 0;
1463 * Run time support routines
1467 * Generic "post and forget" helpers. This is less efficient - we do
1468 * a memcpy for example that isnt strictly needed, but for most uses
1469 * this is simply not worth optimising
1472 int i2o_post_this(struct i2o_controller *c, int tid, u32 *data, int len)
1474 u32 m;
1475 u32 *msg;
1476 unsigned long t=jiffies;
1480 mb();
1481 m = I2O_POST_READ32(c);
1483 while(m==0xFFFFFFFF && (jiffies-t)<HZ);
1486 if(m==0xFFFFFFFF)
1488 printk(KERN_ERR "i2o: controller not responding.\n");
1489 return -1;
1491 msg = bus_to_virt(c->mem_offset + m);
1492 memcpy(msg, data, len);
1493 i2o_post_message(c,m);
1494 return 0;
1498 * Post a message and wait for a response flag to be set. This API will
1499 * change to use wait_queue's one day
1502 int i2o_post_wait(struct i2o_controller *c, int tid, u32 *data, int len, int *flag, int timeout)
1504 unsigned long t=jiffies;
1506 *flag = 0;
1508 if(i2o_post_this(c, tid, data, len))
1509 return I2O_POST_WAIT_TIMEOUT;
1511 while(!*flag && (jiffies-t)<timeout*HZ)
1513 schedule();
1514 mb();
1517 if (*flag < 0)
1518 return *flag; /* DetailedStatus */
1520 if (*flag == 0)
1521 return I2O_POST_WAIT_TIMEOUT;
1523 return I2O_POST_WAIT_OK;
1527 * Issue UTIL_CLAIM messages
1530 int i2o_issue_claim(struct i2o_controller *c, int tid, int context, int onoff, int *flag, u32 type)
1532 u32 msg[6];
1534 msg[0] = FIVE_WORD_MSG_SIZE | SGL_OFFSET_0;
1535 if(onoff)
1536 msg[1] = I2O_CMD_UTIL_CLAIM << 24 | HOST_TID<<12 | tid;
1537 else
1538 msg[1] = I2O_CMD_UTIL_RELEASE << 24 | HOST_TID << 12 | tid;
1540 /* The 0x80000000 convention for flagging is assumed by this helper */
1542 msg[2] = 0x80000000|context;
1543 msg[3] = (u32)flag;
1544 msg[4] = type;
1546 return i2o_post_wait(c, tid, msg, 20, flag,2);
1549 /* Issue UTIL_PARAMS_GET or UTIL_PARAMS_SET
1551 * This function can be used for all UtilParamsGet/Set operations.
1552 * The OperationBlock is given in opblk-buffer,
1553 * and results are returned in resblk-buffer.
1554 * Note that the minimum sized resblk is 8 bytes and contains
1555 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
1557 int i2o_issue_params(int cmd,
1558 struct i2o_controller *iop, int tid, int context,
1559 void *opblk, int oplen, void *resblk, int reslen,
1560 int *flag)
1562 u32 msg[9];
1563 u8 *res = (u8 *)resblk;
1564 int res_count;
1565 int blk_size;
1566 int bytes;
1567 int wait_status;
1569 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
1570 msg[1] = cmd << 24 | HOST_TID << 12 | tid;
1571 msg[2] = context | 0x80000000;
1572 msg[3] = (u32)flag;
1573 msg[4] = 0;
1574 msg[5] = 0x54000000 | oplen; /* OperationBlock */
1575 msg[6] = virt_to_bus(opblk);
1576 msg[7] = 0xD0000000 | reslen; /* ResultBlock */
1577 msg[8] = virt_to_bus(resblk);
1579 wait_status = i2o_post_wait(iop, tid, msg, sizeof(msg), flag, 10);
1580 if (wait_status < 0)
1581 return wait_status; /* -DetailedStatus */
1583 if (res[1]&0x00FF0000) /* BlockStatus != SUCCESS */
1585 printk(KERN_WARNING "%s - Error:\n ErrorInfoSize = 0x%02x, "
1586 "BlockStatus = 0x%02x, BlockSize = 0x%04x\n",
1587 (cmd == I2O_CMD_UTIL_PARAMS_SET) ? "PARAMS_SET"
1588 : "PARAMS_GET",
1589 res[1]>>24, (res[1]>>16)&0xFF, res[1]&0xFFFF);
1590 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
1593 res_count = res[0] & 0xFFFF; /* # of resultblocks */
1594 bytes = 4;
1595 res += 4;
1596 while (res_count--)
1598 blk_size = (res[0] & 0xFFFF) << 2;
1599 bytes += blk_size;
1600 res += blk_size;
1603 return bytes; /* total sizeof Result List in bytes */
1607 * Query one scalar group value or a whole scalar group.
1609 int i2o_query_scalar(struct i2o_controller *iop, int tid, int context,
1610 int group, int field, void *buf, int buflen, int *flag)
1612 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
1613 u8 resblk[8+buflen]; /* 8 bytes for header */
1614 int size;
1616 if (field == -1) /* whole group */
1617 opblk[4] = -1;
1619 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, iop, tid, context,
1620 opblk, sizeof(opblk), resblk, sizeof(resblk), flag);
1622 if (size < 0)
1623 return size;
1625 memcpy(buf, resblk+8, buflen); /* cut off header */
1626 return buflen;
1630 * Set a scalar group value or a whole group.
1632 int i2o_set_scalar(struct i2o_controller *iop, int tid, int context,
1633 int group, int field, void *buf, int buflen, int *flag)
1635 u16 *opblk;
1636 u8 resblk[8+buflen]; /* 8 bytes for header */
1637 int size;
1639 opblk = kmalloc(buflen+64, GFP_KERNEL);
1640 if (opblk == NULL)
1642 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
1643 return -ENOMEM;
1646 opblk[0] = 1; /* operation count */
1647 opblk[1] = 0; /* pad */
1648 opblk[2] = I2O_PARAMS_FIELD_SET;
1649 opblk[3] = group;
1651 if(field == -1) { /* whole group */
1652 opblk[4] = -1;
1653 memcpy(opblk+5, buf, buflen);
1655 else /* single field */
1657 opblk[4] = 1;
1658 opblk[5] = field;
1659 memcpy(opblk+6, buf, buflen);
1662 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1663 opblk, 12+buflen, resblk, sizeof(resblk), flag);
1665 kfree(opblk);
1666 return size;
1670 * if oper == I2O_PARAMS_TABLE_GET:
1671 * Get all table group fields from all rows or
1672 * get specific table group fields from all rows.
1674 * if fieldcount == -1 we query all fields from all rows
1675 * ibuf is NULL and ibuflen is 0
1676 * else we query specific fields from all rows
1677 * ibuf contains fieldindexes
1679 * if oper == I2O_PARAMS_LIST_GET:
1680 * Get all table group fields from specified rows or
1681 * get specific table group fields from specified rows.
1683 * if fieldcount == -1 we query all fields from specified rows
1684 * ibuf contains rowcount, keyvalues
1685 * else we query specific fields from specified rows
1686 * ibuf contains fieldindexes, rowcount, keyvalues
1688 * You could also use directly function i2o_issue_params().
1690 int i2o_query_table(int oper,
1691 struct i2o_controller *iop, int tid, int context, int group,
1692 int fieldcount, void *ibuf, int ibuflen,
1693 void *resblk, int reslen, int *flag)
1695 u16 *opblk;
1696 int size;
1698 opblk = kmalloc(10 + ibuflen, GFP_KERNEL);
1699 if (opblk == NULL)
1701 printk(KERN_ERR "i2o: no memory for query buffer.\n");
1702 return -ENOMEM;
1705 opblk[0] = 1; /* operation count */
1706 opblk[1] = 0; /* pad */
1707 opblk[2] = oper;
1708 opblk[3] = group;
1709 opblk[4] = fieldcount;
1710 memcpy(opblk+5, ibuf, ibuflen); /* other params */
1712 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET,iop, tid, context,
1713 opblk, 10+ibuflen, resblk, reslen, flag);
1715 kfree(opblk);
1716 return size;
1720 * Clear table group, i.e. delete all rows.
1723 int i2o_clear_table(struct i2o_controller *iop, int tid, int context,
1724 int group, int *flag)
1726 u16 opblk[] = { 1, 0, I2O_PARAMS_TABLE_CLEAR, group };
1727 u8 resblk[32]; /* min 8 bytes for result header */
1729 return i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1730 opblk, sizeof(opblk), resblk, sizeof(resblk), flag);
1734 * Add a new row into a table group.
1736 * if fieldcount==-1 then we add whole rows
1737 * buf contains rowcount, keyvalues
1738 * else just specific fields are given, rest use defaults
1739 * buf contains fieldindexes, rowcount, keyvalues
1742 int i2o_row_add_table(struct i2o_controller *iop, int tid, int context,
1743 int group, int fieldcount, void *buf, int buflen,
1744 int *flag)
1746 u16 *opblk;
1747 u8 resblk[32]; /* min 8 bytes for header */
1748 int size;
1750 opblk = kmalloc(buflen+64, GFP_KERNEL);
1751 if (opblk == NULL)
1753 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
1754 return -ENOMEM;
1757 opblk[0] = 1; /* operation count */
1758 opblk[1] = 0; /* pad */
1759 opblk[2] = I2O_PARAMS_ROW_ADD;
1760 opblk[3] = group;
1761 opblk[4] = fieldcount;
1762 memcpy(opblk+5, buf, buflen);
1764 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1765 opblk, 10+buflen, resblk, sizeof(resblk), flag);
1767 kfree(opblk);
1768 return size;
1772 * Delete rows from a table group.
1775 int i2o_row_delete_table(struct i2o_controller *iop, int tid, int context,
1776 int group, int keycount, void *keys, int keyslen,
1777 int *flag)
1779 u16 *opblk;
1780 u8 resblk[32]; /* min 8 bytes for header */
1781 int size;
1783 opblk = kmalloc(keyslen+64, GFP_KERNEL);
1784 if (opblk == NULL)
1786 printk(KERN_ERR "i2o: no memory for operation buffer.\n");
1787 return -ENOMEM;
1790 opblk[0] = 1; /* operation count */
1791 opblk[1] = 0; /* pad */
1792 opblk[2] = I2O_PARAMS_ROW_DELETE;
1793 opblk[3] = group;
1794 opblk[4] = keycount;
1795 memcpy(opblk+5, keys, keyslen);
1797 size = i2o_issue_params(I2O_CMD_UTIL_PARAMS_SET, iop, tid, context,
1798 opblk, 10+keyslen, resblk, sizeof(resblk), flag);
1800 kfree(opblk);
1801 return size;
1804 void i2o_report_common_status(u8 req_status)
1806 /* the following reply status strings are common to all classes */
1808 static char *REPLY_STATUS[] = {
1809 "SUCCESS",
1810 "ABORT_DIRTY",
1811 "ABORT_NO_DATA_TRANSFER",
1812 "ABORT_PARTIAL_TRANSFER",
1813 "ERROR_DIRTY",
1814 "ERROR_NO_DATA_TRANSFER",
1815 "ERROR_PARTIAL_TRANSFER",
1816 "PROCESS_ABORT_DIRTY",
1817 "PROCESS_ABORT_NO_DATA_TRANSFER",
1818 "PROCESS_ABORT_PARTIAL_TRANSFER",
1819 "TRANSACTION_ERROR",
1820 "PROGRESS_REPORT"
1823 if (req_status > I2O_REPLY_STATUS_PROGRESS_REPORT)
1824 printk("%0#4x / ", req_status);
1825 else
1826 printk("%s / ", REPLY_STATUS[req_status]);
1828 return;
1831 static void i2o_report_common_dsc(u16 detailed_status)
1833 /* The following detailed statuscodes are valid
1834 - for executive class, utility class, DDM class and
1835 - for transaction error replies
1838 static char *COMMON_DSC[] = {
1839 "SUCCESS",
1840 "0x01", // not used
1841 "BAD_KEY",
1842 "TCL_ERROR",
1843 "REPLY_BUFFER_FULL",
1844 "NO_SUCH_PAGE",
1845 "INSUFFICIENT_RESOURCE_SOFT",
1846 "INSUFFICIENT_RESOURCE_HARD",
1847 "0x08", // not used
1848 "CHAIN_BUFFER_TOO_LARGE",
1849 "UNSUPPORTED_FUNCTION",
1850 "DEVICE_LOCKED",
1851 "DEVICE_RESET",
1852 "INAPPROPRIATE_FUNCTION",
1853 "INVALID_INITIATOR_ADDRESS",
1854 "INVALID_MESSAGE_FLAGS",
1855 "INVALID_OFFSET",
1856 "INVALID_PARAMETER",
1857 "INVALID_REQUEST",
1858 "INVALID_TARGET_ADDRESS",
1859 "MESSAGE_TOO_LARGE",
1860 "MESSAGE_TOO_SMALL",
1861 "MISSING_PARAMETER",
1862 "TIMEOUT",
1863 "UNKNOWN_ERROR",
1864 "UNKNOWN_FUNCTION",
1865 "UNSUPPORTED_VERSION",
1866 "DEVICE_BUSY",
1867 "DEVICE_NOT_AVAILABLE"
1870 if (detailed_status > I2O_DSC_DEVICE_NOT_AVAILABLE)
1871 printk("%0#4x.\n", detailed_status);
1872 else
1873 printk("%s.\n", COMMON_DSC[detailed_status]);
1875 return;
1878 static void i2o_report_lan_dsc(u16 detailed_status)
1880 static char *LAN_DSC[] = { // Lan detailed status code strings
1881 "SUCCESS",
1882 "DEVICE_FAILURE",
1883 "DESTINATION_NOT_FOUND",
1884 "TRANSMIT_ERROR",
1885 "TRANSMIT_ABORTED",
1886 "RECEIVE_ERROR",
1887 "RECEIVE_ABORTED",
1888 "DMA_ERROR",
1889 "BAD_PACKET_DETECTED",
1890 "OUT_OF_MEMORY",
1891 "BUCKET_OVERRUN",
1892 "IOP_INTERNAL_ERROR",
1893 "CANCELED",
1894 "INVALID_TRANSACTION_CONTEXT",
1895 "DEST_ADDRESS_DETECTED",
1896 "DEST_ADDRESS_OMITTED",
1897 "PARTIAL_PACKET_RETURNED",
1898 "TEMP_SUSPENDED_STATE", // last Lan detailed status code
1899 "INVALID_REQUEST" // general detailed status code
1902 if (detailed_status > I2O_DSC_INVALID_REQUEST)
1903 printk("%0#4x.\n", detailed_status);
1904 else
1905 printk("%s.\n", LAN_DSC[detailed_status]);
1907 return;
1910 static void i2o_report_util_cmd(u8 cmd)
1912 switch (cmd) {
1913 case I2O_CMD_UTIL_NOP:
1914 printk("UTIL_NOP, ");
1915 break;
1916 case I2O_CMD_UTIL_ABORT:
1917 printk("UTIL_ABORT, ");
1918 break;
1919 case I2O_CMD_UTIL_CLAIM:
1920 printk("UTIL_CLAIM, ");
1921 break;
1922 case I2O_CMD_UTIL_RELEASE:
1923 printk("UTIL_CLAIM_RELEASE, ");
1924 break;
1925 case I2O_CMD_UTIL_CONFIG_DIALOG:
1926 printk("UTIL_CONFIG_DIALOG, ");
1927 break;
1928 case I2O_CMD_UTIL_DEVICE_RESERVE:
1929 printk("UTIL_DEVICE_RESERVE, ");
1930 break;
1931 case I2O_CMD_UTIL_DEVICE_RELEASE:
1932 printk("UTIL_DEVICE_RELEASE, ");
1933 break;
1934 case I2O_CMD_UTIL_ACK:
1935 printk("UTIL_EVENT_ACKNOWLEDGE, ");
1936 break;
1937 case I2O_CMD_UTIL_EVT_REGISTER:
1938 printk("UTIL_EVENT_REGISTER, ");
1939 break;
1940 case I2O_CMD_UTIL_LOCK:
1941 printk("UTIL_LOCK, ");
1942 break;
1943 case I2O_CMD_UTIL_LOCK_RELEASE:
1944 printk("UTIL_LOCK_RELEASE, ");
1945 break;
1946 case I2O_CMD_UTIL_PARAMS_GET:
1947 printk("UTIL_PARAMS_GET, ");
1948 break;
1949 case I2O_CMD_UTIL_PARAMS_SET:
1950 printk("UTIL_PARAMS_SET, ");
1951 break;
1952 case I2O_CMD_UTIL_REPLY_FAULT_NOTIFY:
1953 printk("UTIL_REPLY_FAULT_NOTIFY, ");
1954 break;
1955 default:
1956 printk("%0#2x, ",cmd);
1959 return;
1963 static void i2o_report_exec_cmd(u8 cmd)
1965 switch (cmd) {
1966 case I2O_CMD_ADAPTER_ASSIGN:
1967 printk("EXEC_ADAPTER_ASSIGN, ");
1968 break;
1969 case I2O_CMD_ADAPTER_READ:
1970 printk("EXEC_ADAPTER_READ, ");
1971 break;
1972 case I2O_CMD_ADAPTER_RELEASE:
1973 printk("EXEC_ADAPTER_RELEASE, ");
1974 break;
1975 case I2O_CMD_BIOS_INFO_SET:
1976 printk("EXEC_BIOS_INFO_SET, ");
1977 break;
1978 case I2O_CMD_BOOT_DEVICE_SET:
1979 printk("EXEC_BOOT_DEVICE_SET, ");
1980 break;
1981 case I2O_CMD_CONFIG_VALIDATE:
1982 printk("EXEC_CONFIG_VALIDATE, ");
1983 break;
1984 case I2O_CMD_CONN_SETUP:
1985 printk("EXEC_CONN_SETUP, ");
1986 break;
1987 case I2O_CMD_DDM_DESTROY:
1988 printk("EXEC_DDM_DESTROY, ");
1989 break;
1990 case I2O_CMD_DDM_ENABLE:
1991 printk("EXEC_DDM_ENABLE, ");
1992 break;
1993 case I2O_CMD_DDM_QUIESCE:
1994 printk("EXEC_DDM_QUIESCE, ");
1995 break;
1996 case I2O_CMD_DDM_RESET:
1997 printk("EXEC_DDM_RESET, ");
1998 break;
1999 case I2O_CMD_DDM_SUSPEND:
2000 printk("EXEC_DDM_SUSPEND, ");
2001 break;
2002 case I2O_CMD_DEVICE_ASSIGN:
2003 printk("EXEC_DEVICE_ASSIGN, ");
2004 break;
2005 case I2O_CMD_DEVICE_RELEASE:
2006 printk("EXEC_DEVICE_RELEASE, ");
2007 break;
2008 case I2O_CMD_HRT_GET:
2009 printk("EXEC_HRT_GET, ");
2010 break;
2011 case I2O_CMD_ADAPTER_CLEAR:
2012 printk("EXEC_IOP_CLEAR, ");
2013 break;
2014 case I2O_CMD_ADAPTER_CONNECT:
2015 printk("EXEC_IOP_CONNECT, ");
2016 break;
2017 case I2O_CMD_ADAPTER_RESET:
2018 printk("EXEC_IOP_RESET, ");
2019 break;
2020 case I2O_CMD_LCT_NOTIFY:
2021 printk("EXEC_LCT_NOTIFY, ");
2022 break;
2023 case I2O_CMD_OUTBOUND_INIT:
2024 printk("EXEC_OUTBOUND_INIT, ");
2025 break;
2026 case I2O_CMD_PATH_ENABLE:
2027 printk("EXEC_PATH_ENABLE, ");
2028 break;
2029 case I2O_CMD_PATH_QUIESCE:
2030 printk("EXEC_PATH_QUIESCE, ");
2031 break;
2032 case I2O_CMD_PATH_RESET:
2033 printk("EXEC_PATH_RESET, ");
2034 break;
2035 case I2O_CMD_STATIC_MF_CREATE:
2036 printk("EXEC_STATIC_MF_CREATE, ");
2037 break;
2038 case I2O_CMD_STATIC_MF_RELEASE:
2039 printk("EXEC_STATIC_MF_RELEASE, ");
2040 break;
2041 case I2O_CMD_STATUS_GET:
2042 printk("EXEC_STATUS_GET, ");
2043 break;
2044 case I2O_CMD_SW_DOWNLOAD:
2045 printk("EXEC_SW_DOWNLOAD, ");
2046 break;
2047 case I2O_CMD_SW_UPLOAD:
2048 printk("EXEC_SW_UPLOAD, ");
2049 break;
2050 case I2O_CMD_SW_REMOVE:
2051 printk("EXEC_SW_REMOVE, ");
2052 break;
2053 case I2O_CMD_SYS_ENABLE:
2054 printk("EXEC_SYS_ENABLE, ");
2055 break;
2056 case I2O_CMD_SYS_MODIFY:
2057 printk("EXEC_SYS_MODIFY, ");
2058 break;
2059 case I2O_CMD_SYS_QUIESCE:
2060 printk("EXEC_SYS_QUIESCE, ");
2061 break;
2062 case I2O_CMD_SYS_TAB_SET:
2063 printk("EXEC_SYS_TAB_SET, ");
2064 break;
2065 default:
2066 printk("%02x, ",cmd);
2069 return;
2072 static void i2o_report_lan_cmd(u8 cmd)
2074 switch (cmd) {
2075 case LAN_PACKET_SEND:
2076 printk("LAN_PACKET_SEND, ");
2077 break;
2078 case LAN_SDU_SEND:
2079 printk("LAN_SDU_SEND, ");
2080 break;
2081 case LAN_RECEIVE_POST:
2082 printk("LAN_RECEIVE_POST, ");
2083 break;
2084 case LAN_RESET:
2085 printk("LAN_RESET, ");
2086 break;
2087 case LAN_SUSPEND:
2088 printk("LAN_SUSPEND, ");
2089 break;
2090 default:
2091 printk("%02x, ",cmd);
2094 return;
2097 /* TODO: Add support for other classes */
2098 void i2o_report_status(const char *severity, const char *module, u32 *msg)
2100 u8 cmd = (msg[1]>>24)&0xFF;
2101 u8 req_status = (msg[4]>>24)&0xFF;
2102 u16 detailed_status = msg[4]&0xFFFF;
2104 printk("%s%s: ", severity, module);
2106 if (cmd < 0x1F) { // Utility Class
2107 i2o_report_util_cmd(cmd);
2108 i2o_report_common_status(req_status);
2109 i2o_report_common_dsc(detailed_status);
2110 return;
2113 if (cmd >= 0x30 && cmd <= 0x3F) { // LAN class
2114 i2o_report_lan_cmd(cmd);
2115 i2o_report_common_status(req_status);
2116 i2o_report_lan_dsc(detailed_status);
2117 return;
2120 if (cmd >= 0xA0 && cmd <= 0xEF) { // Executive class
2121 i2o_report_exec_cmd(cmd);
2122 i2o_report_common_status(req_status);
2123 i2o_report_common_dsc(detailed_status);
2124 return;
2127 printk("%02x, %02x / %04x.\n", cmd, req_status, detailed_status);
2128 return;
2131 /* Used to dump a message to syslog during debugging */
2132 static void i2o_dump_message(u32 *msg)
2134 #ifdef DRIVERDEBUG
2135 int i;
2137 printk(KERN_INFO "Dumping I2O message @ %p\n", msg);
2138 for(i = 0; i < ((msg[0]>>16)&0xffff); i++)
2139 printk(KERN_INFO "\tmsg[%d] = %#10x\n", i, msg[i]);
2140 #endif
2143 #ifdef MODULE
2145 EXPORT_SYMBOL(i2o_install_handler);
2146 EXPORT_SYMBOL(i2o_remove_handler);
2147 EXPORT_SYMBOL(i2o_install_device);
2148 EXPORT_SYMBOL(i2o_delete_device);
2149 EXPORT_SYMBOL(i2o_quiesce_controller);
2150 EXPORT_SYMBOL(i2o_clear_controller);
2151 EXPORT_SYMBOL(i2o_install_controller);
2152 EXPORT_SYMBOL(i2o_delete_controller);
2153 EXPORT_SYMBOL(i2o_unlock_controller);
2154 EXPORT_SYMBOL(i2o_find_controller);
2155 EXPORT_SYMBOL(i2o_num_controllers);
2156 EXPORT_SYMBOL(i2o_claim_device);
2157 EXPORT_SYMBOL(i2o_release_device);
2158 EXPORT_SYMBOL(i2o_run_queue);
2159 EXPORT_SYMBOL(i2o_report_controller_unit);
2160 EXPORT_SYMBOL(i2o_activate_controller);
2161 EXPORT_SYMBOL(i2o_online_controller);
2162 EXPORT_SYMBOL(i2o_get_class_name);
2164 EXPORT_SYMBOL(i2o_query_scalar);
2165 EXPORT_SYMBOL(i2o_set_scalar);
2166 EXPORT_SYMBOL(i2o_query_table);
2167 EXPORT_SYMBOL(i2o_clear_table);
2168 EXPORT_SYMBOL(i2o_row_add_table);
2169 EXPORT_SYMBOL(i2o_row_delete_table);
2171 EXPORT_SYMBOL(i2o_post_this);
2172 EXPORT_SYMBOL(i2o_post_wait);
2173 EXPORT_SYMBOL(i2o_issue_claim);
2174 EXPORT_SYMBOL(i2o_issue_params);
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 int __init 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