ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / message / i2o / i2o_proc.c
1 /*
2  *   procfs handler for Linux I2O subsystem
3  *
4  *   (c) Copyright 1999 Deepak Saxena
5  *   
6  *   Originally written by Deepak Saxena(deepak@plexity.net)
7  *
8  *   This program is free software. You can redistribute it and/or
9  *   modify it under the terms of the GNU General Public License
10  *   as published by the Free Software Foundation; either version
11  *   2 of the License, or (at your option) any later version.
12  *
13  *   This is an initial test release. The code is based on the design
14  *   of the ide procfs system (drivers/block/ide-proc.c). Some code
15  *   taken from i2o-core module by Alan Cox.
16  *
17  *   DISCLAIMER: This code is still under development/test and may cause
18  *   your system to behave unpredictably.  Use at your own discretion.
19  *
20  *   LAN entries by Juha Sievänen (Juha.Sievanen@cs.Helsinki.FI),
21  *                  Auvo Häkkinen (Auvo.Hakkinen@cs.Helsinki.FI)
22  *   University of Helsinki, Department of Computer Science
23  */
24
25 /*
26  * set tabstop=3
27  */
28
29 /*
30  * TODO List
31  *
32  * - Add support for any version 2.0 spec changes once 2.0 IRTOS is
33  *   is available to test with
34  * - Clean up code to use official structure definitions 
35  */
36
37 // FIXME!
38 #define FMT_U64_HEX "0x%08x%08x"
39 #define U64_VAL(pu64) *((u32*)(pu64)+1), *((u32*)(pu64))
40
41 #include <linux/types.h>
42 #include <linux/kernel.h>
43 #include <linux/pci.h>
44 #include <linux/i2o.h>
45 #include <linux/proc_fs.h>
46 #include <linux/init.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/spinlock.h>
50 #include <linux/workqueue.h>
51
52 #include <asm/io.h>
53 #include <asm/uaccess.h>
54 #include <asm/byteorder.h>
55
56 #include "i2o_lan.h"
57
58 /*
59  * Structure used to define /proc entries
60  */
61 typedef struct _i2o_proc_entry_t
62 {
63         char *name;                     /* entry name */
64         mode_t mode;                    /* mode */
65         read_proc_t *read_proc;         /* read func */
66         write_proc_t *write_proc;       /* write func */
67 } i2o_proc_entry;
68
69 // #define DRIVERDEBUG
70
71 static int i2o_proc_read_lct(char *, char **, off_t, int, int *, void *);
72 static int i2o_proc_read_hrt(char *, char **, off_t, int, int *, void *);
73 static int i2o_proc_read_status(char *, char **, off_t, int, int *, void *);
74
75 static int i2o_proc_read_hw(char *, char **, off_t, int, int *, void *);
76 static int i2o_proc_read_ddm_table(char *, char **, off_t, int, int *, void *);
77 static int i2o_proc_read_driver_store(char *, char **, off_t, int, int *, void *);
78 static int i2o_proc_read_drivers_stored(char *, char **, off_t, int, int *, void *);
79
80 static int i2o_proc_read_groups(char *, char **, off_t, int, int *, void *);
81 static int i2o_proc_read_phys_device(char *, char **, off_t, int, int *, void *);
82 static int i2o_proc_read_claimed(char *, char **, off_t, int, int *, void *);
83 static int i2o_proc_read_users(char *, char **, off_t, int, int *, void *);
84 static int i2o_proc_read_priv_msgs(char *, char **, off_t, int, int *, void *);
85 static int i2o_proc_read_authorized_users(char *, char **, off_t, int, int *, void *);
86
87 static int i2o_proc_read_dev_name(char *, char **, off_t, int, int *, void *);
88 static int i2o_proc_read_dev_identity(char *, char **, off_t, int, int *, void *);
89 static int i2o_proc_read_ddm_identity(char *, char **, off_t, int, int *, void *);
90 static int i2o_proc_read_uinfo(char *, char **, off_t, int, int *, void *);
91 static int i2o_proc_read_sgl_limits(char *, char **, off_t, int, int *, void *);
92
93 static int i2o_proc_read_sensors(char *, char **, off_t, int, int *, void *);
94
95 static int print_serial_number(char *, int, u8 *, int);
96
97 static int i2o_proc_create_entries(void *, i2o_proc_entry *,
98                                    struct proc_dir_entry *);
99 static void i2o_proc_remove_entries(i2o_proc_entry *, struct proc_dir_entry *);
100 static int i2o_proc_add_controller(struct i2o_controller *, 
101                                    struct proc_dir_entry * );
102 static void i2o_proc_remove_controller(struct i2o_controller *, 
103                                        struct proc_dir_entry * );
104 static void i2o_proc_add_device(struct i2o_device *, struct proc_dir_entry *);
105 static void i2o_proc_remove_device(struct i2o_device *);
106 static int create_i2o_procfs(void);
107 static int destroy_i2o_procfs(void);
108 static void i2o_proc_new_dev(struct i2o_controller *, struct i2o_device *);
109 static void i2o_proc_dev_del(struct i2o_controller *, struct i2o_device *);
110
111 static int i2o_proc_read_lan_dev_info(char *, char **, off_t, int, int *,
112                                       void *);
113 static int i2o_proc_read_lan_mac_addr(char *, char **, off_t, int, int *,
114                                       void *);
115 static int i2o_proc_read_lan_mcast_addr(char *, char **, off_t, int, int *,
116                                         void *);
117 static int i2o_proc_read_lan_batch_control(char *, char **, off_t, int, int *,
118                                            void *);
119 static int i2o_proc_read_lan_operation(char *, char **, off_t, int, int *,
120                                        void *);
121 static int i2o_proc_read_lan_media_operation(char *, char **, off_t, int,
122                                              int *, void *);
123 static int i2o_proc_read_lan_alt_addr(char *, char **, off_t, int, int *,
124                                       void *);
125 static int i2o_proc_read_lan_tx_info(char *, char **, off_t, int, int *,
126                                      void *);
127 static int i2o_proc_read_lan_rx_info(char *, char **, off_t, int, int *,
128                                      void *);
129 static int i2o_proc_read_lan_hist_stats(char *, char **, off_t, int, int *,
130                                         void *);
131 static int i2o_proc_read_lan_eth_stats(char *, char **, off_t, int,
132                                        int *, void *);
133 static int i2o_proc_read_lan_tr_stats(char *, char **, off_t, int, int *,
134                                       void *);
135 static int i2o_proc_read_lan_fddi_stats(char *, char **, off_t, int, int *,
136                                         void *);
137
138 static struct proc_dir_entry *i2o_proc_dir_root;
139
140 /*
141  * I2O OSM descriptor
142  */
143 static struct i2o_handler i2o_proc_handler =
144 {
145         NULL,
146         i2o_proc_new_dev,
147         i2o_proc_dev_del,
148         NULL,
149         "I2O procfs Layer",
150         0,
151         0xffffffff      // All classes
152 };
153
154 /*
155  * IOP specific entries...write field just in case someone 
156  * ever wants one.
157  */
158 static i2o_proc_entry generic_iop_entries[] = 
159 {
160         {"hrt", S_IFREG|S_IRUGO, i2o_proc_read_hrt, NULL},
161         {"lct", S_IFREG|S_IRUGO, i2o_proc_read_lct, NULL},
162         {"status", S_IFREG|S_IRUGO, i2o_proc_read_status, NULL},
163         {"hw", S_IFREG|S_IRUGO, i2o_proc_read_hw, NULL},
164         {"ddm_table", S_IFREG|S_IRUGO, i2o_proc_read_ddm_table, NULL},
165         {"driver_store", S_IFREG|S_IRUGO, i2o_proc_read_driver_store, NULL},
166         {"drivers_stored", S_IFREG|S_IRUGO, i2o_proc_read_drivers_stored, NULL},
167         {NULL, 0, NULL, NULL}
168 };
169
170 /*
171  * Device specific entries
172  */
173 static i2o_proc_entry generic_dev_entries[] = 
174 {
175         {"groups", S_IFREG|S_IRUGO, i2o_proc_read_groups, NULL},
176         {"phys_dev", S_IFREG|S_IRUGO, i2o_proc_read_phys_device, NULL},
177         {"claimed", S_IFREG|S_IRUGO, i2o_proc_read_claimed, NULL},
178         {"users", S_IFREG|S_IRUGO, i2o_proc_read_users, NULL},
179         {"priv_msgs", S_IFREG|S_IRUGO, i2o_proc_read_priv_msgs, NULL},
180         {"authorized_users", S_IFREG|S_IRUGO, i2o_proc_read_authorized_users, NULL},
181         {"dev_identity", S_IFREG|S_IRUGO, i2o_proc_read_dev_identity, NULL},
182         {"ddm_identity", S_IFREG|S_IRUGO, i2o_proc_read_ddm_identity, NULL},
183         {"user_info", S_IFREG|S_IRUGO, i2o_proc_read_uinfo, NULL},
184         {"sgl_limits", S_IFREG|S_IRUGO, i2o_proc_read_sgl_limits, NULL},
185         {"sensors", S_IFREG|S_IRUGO, i2o_proc_read_sensors, NULL},
186         {NULL, 0, NULL, NULL}
187 };
188
189 /*
190  *  Storage unit specific entries (SCSI Periph, BS) with device names
191  */
192 static i2o_proc_entry rbs_dev_entries[] = 
193 {
194         {"dev_name", S_IFREG|S_IRUGO, i2o_proc_read_dev_name, NULL},
195         {NULL, 0, NULL, NULL}
196 };
197
198 #define SCSI_TABLE_SIZE 13
199 static char *scsi_devices[] = 
200 {
201         "Direct-Access Read/Write",
202         "Sequential-Access Storage",
203         "Printer",
204         "Processor",
205         "WORM Device",
206         "CD-ROM Device",
207         "Scanner Device",
208         "Optical Memory Device",
209         "Medium Changer Device",
210         "Communications Device",
211         "Graphics Art Pre-Press Device",
212         "Graphics Art Pre-Press Device",
213         "Array Controller Device"
214 };
215
216 /* private */
217
218 /*
219  * Generic LAN specific entries
220  * 
221  * Should groups with r/w entries have their own subdirectory?
222  *
223  */
224 static i2o_proc_entry lan_entries[] = 
225 {
226         {"lan_dev_info", S_IFREG|S_IRUGO, i2o_proc_read_lan_dev_info, NULL},
227         {"lan_mac_addr", S_IFREG|S_IRUGO, i2o_proc_read_lan_mac_addr, NULL},
228         {"lan_mcast_addr", S_IFREG|S_IRUGO|S_IWUSR,
229          i2o_proc_read_lan_mcast_addr, NULL},
230         {"lan_batch_ctrl", S_IFREG|S_IRUGO|S_IWUSR,
231          i2o_proc_read_lan_batch_control, NULL},
232         {"lan_operation", S_IFREG|S_IRUGO, i2o_proc_read_lan_operation, NULL},
233         {"lan_media_operation", S_IFREG|S_IRUGO,
234          i2o_proc_read_lan_media_operation, NULL},
235         {"lan_alt_addr", S_IFREG|S_IRUGO, i2o_proc_read_lan_alt_addr, NULL},
236         {"lan_tx_info", S_IFREG|S_IRUGO, i2o_proc_read_lan_tx_info, NULL},
237         {"lan_rx_info", S_IFREG|S_IRUGO, i2o_proc_read_lan_rx_info, NULL},
238
239         {"lan_hist_stats", S_IFREG|S_IRUGO, i2o_proc_read_lan_hist_stats, NULL},
240         {NULL, 0, NULL, NULL}
241 };
242
243 /*
244  * Port specific LAN entries
245  * 
246  */
247 static i2o_proc_entry lan_eth_entries[] = 
248 {
249         {"lan_eth_stats", S_IFREG|S_IRUGO, i2o_proc_read_lan_eth_stats, NULL},
250         {NULL, 0, NULL, NULL}
251 };
252
253 static i2o_proc_entry lan_tr_entries[] = 
254 {
255         {"lan_tr_stats", S_IFREG|S_IRUGO, i2o_proc_read_lan_tr_stats, NULL},
256         {NULL, 0, NULL, NULL}
257 };
258
259 static i2o_proc_entry lan_fddi_entries[] = 
260 {
261         {"lan_fddi_stats", S_IFREG|S_IRUGO, i2o_proc_read_lan_fddi_stats, NULL},
262         {NULL, 0, NULL, NULL}
263 };
264
265
266 static char *chtostr(u8 *chars, int n)
267 {
268         char tmp[256];
269         tmp[0] = 0;
270         return strncat(tmp, (char *)chars, n);
271 }
272
273 static int i2o_report_query_status(char *buf, int block_status, char *group)
274 {
275         switch (block_status)
276         {
277         case -ETIMEDOUT:
278                 return sprintf(buf, "Timeout reading group %s.\n",group);
279         case -ENOMEM:
280                 return sprintf(buf, "No free memory to read the table.\n");
281         case -I2O_PARAMS_STATUS_INVALID_GROUP_ID:
282                 return sprintf(buf, "Group %s not supported.\n", group);
283         default:
284                 return sprintf(buf, "Error reading group %s. BlockStatus 0x%02X\n",
285                                group, -block_status);
286         }
287 }
288
289 static char* bus_strings[] = 
290
291         "Local Bus", 
292         "ISA", 
293         "EISA", 
294         "MCA", 
295         "PCI",
296         "PCMCIA", 
297         "NUBUS", 
298         "CARDBUS"
299 };
300
301 static spinlock_t i2o_proc_lock = SPIN_LOCK_UNLOCKED;
302
303 int i2o_proc_read_hrt(char *buf, char **start, off_t offset, int count, 
304                       int *eof, void *data)
305 {
306         struct i2o_controller *c = (struct i2o_controller *)data;
307         i2o_hrt *hrt = (i2o_hrt *)c->hrt;
308         u32 bus;
309         int len, i;
310
311         spin_lock(&i2o_proc_lock);
312
313         len = 0;
314
315         if(hrt->hrt_version)
316         {
317                 len += sprintf(buf+len, 
318                                "HRT table for controller is too new a version.\n");
319                 spin_unlock(&i2o_proc_lock);
320                 return len;
321         }
322
323         if((hrt->num_entries * hrt->entry_len + 8) > 2048) {
324                 printk(KERN_WARNING "i2o_proc: HRT does not fit into buffer\n");
325                 len += sprintf(buf+len,
326                                "HRT table too big to fit in buffer.\n");
327                 spin_unlock(&i2o_proc_lock);
328                 return len;
329         }
330         
331         len += sprintf(buf+len, "HRT has %d entries of %d bytes each.\n",
332                        hrt->num_entries, hrt->entry_len << 2);
333
334         for(i = 0; i < hrt->num_entries && len < count; i++)
335         {
336                 len += sprintf(buf+len, "Entry %d:\n", i);
337                 len += sprintf(buf+len, "   Adapter ID: %0#10x\n", 
338                                         hrt->hrt_entry[i].adapter_id);
339                 len += sprintf(buf+len, "   Controlling tid: %0#6x\n",
340                                         hrt->hrt_entry[i].parent_tid);
341
342                 if(hrt->hrt_entry[i].bus_type != 0x80)
343                 {
344                         bus = hrt->hrt_entry[i].bus_type;
345                         len += sprintf(buf+len, "   %s Information\n", bus_strings[bus]);
346
347                         switch(bus)
348                         {
349                                 case I2O_BUS_LOCAL:
350                                         len += sprintf(buf+len, "     IOBase: %0#6x,",
351                                                                 hrt->hrt_entry[i].bus.local_bus.LbBaseIOPort);
352                                         len += sprintf(buf+len, " MemoryBase: %0#10x\n",
353                                                                 hrt->hrt_entry[i].bus.local_bus.LbBaseMemoryAddress);
354                                         break;
355
356                                 case I2O_BUS_ISA:
357                                         len += sprintf(buf+len, "     IOBase: %0#6x,",
358                                                                 hrt->hrt_entry[i].bus.isa_bus.IsaBaseIOPort);
359                                         len += sprintf(buf+len, " MemoryBase: %0#10x,",
360                                                                 hrt->hrt_entry[i].bus.isa_bus.IsaBaseMemoryAddress);
361                                         len += sprintf(buf+len, " CSN: %0#4x,",
362                                                                 hrt->hrt_entry[i].bus.isa_bus.CSN);
363                                         break;
364
365                                 case I2O_BUS_EISA:
366                                         len += sprintf(buf+len, "     IOBase: %0#6x,",
367                                                                 hrt->hrt_entry[i].bus.eisa_bus.EisaBaseIOPort);
368                                         len += sprintf(buf+len, " MemoryBase: %0#10x,",
369                                                                 hrt->hrt_entry[i].bus.eisa_bus.EisaBaseMemoryAddress);
370                                         len += sprintf(buf+len, " Slot: %0#4x,",
371                                                                 hrt->hrt_entry[i].bus.eisa_bus.EisaSlotNumber);
372                                         break;
373                          
374                                 case I2O_BUS_MCA:
375                                         len += sprintf(buf+len, "     IOBase: %0#6x,",
376                                                                 hrt->hrt_entry[i].bus.mca_bus.McaBaseIOPort);
377                                         len += sprintf(buf+len, " MemoryBase: %0#10x,",
378                                                                 hrt->hrt_entry[i].bus.mca_bus.McaBaseMemoryAddress);
379                                         len += sprintf(buf+len, " Slot: %0#4x,",
380                                                                 hrt->hrt_entry[i].bus.mca_bus.McaSlotNumber);
381                                         break;
382
383                                 case I2O_BUS_PCI:
384                                         len += sprintf(buf+len, "     Bus: %0#4x",
385                                                                 hrt->hrt_entry[i].bus.pci_bus.PciBusNumber);
386                                         len += sprintf(buf+len, " Dev: %0#4x",
387                                                                 hrt->hrt_entry[i].bus.pci_bus.PciDeviceNumber);
388                                         len += sprintf(buf+len, " Func: %0#4x",
389                                                                 hrt->hrt_entry[i].bus.pci_bus.PciFunctionNumber);
390                                         len += sprintf(buf+len, " Vendor: %0#6x",
391                                                                 hrt->hrt_entry[i].bus.pci_bus.PciVendorID);
392                                         len += sprintf(buf+len, " Device: %0#6x\n",
393                                                                 hrt->hrt_entry[i].bus.pci_bus.PciDeviceID);
394                                         break;
395
396                                 default:
397                                         len += sprintf(buf+len, "      Unsupported Bus Type\n");
398                         }
399                 }
400                 else
401                         len += sprintf(buf+len, "   Unknown Bus Type\n");
402         }
403
404         spin_unlock(&i2o_proc_lock);
405         
406         return len;
407 }
408
409 int i2o_proc_read_lct(char *buf, char **start, off_t offset, int len,
410         int *eof, void *data)
411 {
412         struct i2o_controller *c = (struct i2o_controller*)data;
413         i2o_lct *lct = (i2o_lct *)c->lct;
414         int entries;
415         int i;
416
417 #define BUS_TABLE_SIZE 3
418         static char *bus_ports[] =
419         {
420                 "Generic Bus",
421                 "SCSI Bus",
422                 "Fibre Channel Bus"
423         };
424
425         spin_lock(&i2o_proc_lock);
426         len = 0;
427
428         entries = (lct->table_size - 3)/9;
429
430         len += sprintf(buf, "LCT contains %d %s\n", entries,
431                                                 entries == 1 ? "entry" : "entries");
432         if(lct->boot_tid)       
433                 len += sprintf(buf+len, "Boot Device @ ID %d\n", lct->boot_tid);
434
435         len += 
436                 sprintf(buf+len, "Current Change Indicator: %#10x\n", lct->change_ind);
437
438         for(i = 0; i < entries; i++)
439         {
440                 len += sprintf(buf+len, "Entry %d\n", i);
441                 len += sprintf(buf+len, "  Class, SubClass  : %s", i2o_get_class_name(lct->lct_entry[i].class_id));
442         
443                 /*
444                  *      Classes which we'll print subclass info for
445                  */
446                 switch(lct->lct_entry[i].class_id & 0xFFF)
447                 {
448                         case I2O_CLASS_RANDOM_BLOCK_STORAGE:
449                                 switch(lct->lct_entry[i].sub_class)
450                                 {
451                                         case 0x00:
452                                                 len += sprintf(buf+len, ", Direct-Access Read/Write");
453                                                 break;
454
455                                         case 0x04:
456                                                 len += sprintf(buf+len, ", WORM Drive");
457                                                 break;
458         
459                                         case 0x05:
460                                                 len += sprintf(buf+len, ", CD-ROM Drive");
461                                                 break;
462
463                                         case 0x07:
464                                                 len += sprintf(buf+len, ", Optical Memory Device");
465                                                 break;
466
467                                         default:
468                                                 len += sprintf(buf+len, ", Unknown (0x%02x)",
469                                                                lct->lct_entry[i].sub_class);
470                                                 break;
471                                 }
472                                 break;
473
474                         case I2O_CLASS_LAN:
475                                 switch(lct->lct_entry[i].sub_class & 0xFF)
476                                 {
477                                         case 0x30:
478                                                 len += sprintf(buf+len, ", Ethernet");
479                                                 break;
480
481                                         case 0x40:
482                                                 len += sprintf(buf+len, ", 100base VG");
483                                                 break;
484
485                                         case 0x50:
486                                                 len += sprintf(buf+len, ", IEEE 802.5/Token-Ring");
487                                                 break;
488
489                                         case 0x60:
490                                                 len += sprintf(buf+len, ", ANSI X3T9.5 FDDI");
491                                                 break;
492                 
493                                         case 0x70:
494                                                 len += sprintf(buf+len, ", Fibre Channel");
495                                                 break;
496
497                                         default:
498                                                 len += sprintf(buf+len, ", Unknown Sub-Class (0x%02x)",
499                                                                lct->lct_entry[i].sub_class & 0xFF);
500                                                 break;
501                                 }
502                                 break;
503
504                         case I2O_CLASS_SCSI_PERIPHERAL:
505                                 if(lct->lct_entry[i].sub_class < SCSI_TABLE_SIZE)
506                                         len += sprintf(buf+len, ", %s", 
507                                                                 scsi_devices[lct->lct_entry[i].sub_class]);
508                                 else
509                                         len += sprintf(buf+len, ", Unknown Device Type");
510                                 break;
511
512                         case I2O_CLASS_BUS_ADAPTER_PORT:
513                                 if(lct->lct_entry[i].sub_class < BUS_TABLE_SIZE)
514                                         len += sprintf(buf+len, ", %s", 
515                                                                 bus_ports[lct->lct_entry[i].sub_class]);
516                                 else
517                                         len += sprintf(buf+len, ", Unknown Bus Type");
518                                 break;
519                 }
520                 len += sprintf(buf+len, "\n");
521                 
522                 len += sprintf(buf+len, "  Local TID        : 0x%03x\n", lct->lct_entry[i].tid);
523                 len += sprintf(buf+len, "  User TID         : 0x%03x\n", lct->lct_entry[i].user_tid);
524                 len += sprintf(buf+len, "  Parent TID       : 0x%03x\n", 
525                                         lct->lct_entry[i].parent_tid);
526                 len += sprintf(buf+len, "  Identity Tag     : 0x%x%x%x%x%x%x%x%x\n",
527                                         lct->lct_entry[i].identity_tag[0],
528                                         lct->lct_entry[i].identity_tag[1],
529                                         lct->lct_entry[i].identity_tag[2],
530                                         lct->lct_entry[i].identity_tag[3],
531                                         lct->lct_entry[i].identity_tag[4],
532                                         lct->lct_entry[i].identity_tag[5],
533                                         lct->lct_entry[i].identity_tag[6],
534                                         lct->lct_entry[i].identity_tag[7]);
535                 len += sprintf(buf+len, "  Change Indicator : %0#10x\n", 
536                                 lct->lct_entry[i].change_ind);
537                 len += sprintf(buf+len, "  Event Capab Mask : %0#10x\n", 
538                                 lct->lct_entry[i].device_flags);
539         }
540
541         spin_unlock(&i2o_proc_lock);
542         return len;
543 }
544
545 int i2o_proc_read_status(char *buf, char **start, off_t offset, int len, 
546                          int *eof, void *data)
547 {
548         struct i2o_controller *c = (struct i2o_controller*)data;
549         char prodstr[25];
550         int version;
551         
552         spin_lock(&i2o_proc_lock);
553         len = 0;
554
555         i2o_status_get(c); // reread the status block
556
557         len += sprintf(buf+len,"Organization ID        : %0#6x\n", 
558                                 c->status_block->org_id);
559
560         version = c->status_block->i2o_version;
561         
562 /* FIXME for Spec 2.0
563         if (version == 0x02) {
564                 len += sprintf(buf+len,"Lowest I2O version supported: ");
565                 switch(workspace[2]) {
566                         case 0x00:
567                                 len += sprintf(buf+len,"1.0\n");
568                                 break;
569                         case 0x01:
570                                 len += sprintf(buf+len,"1.5\n");
571                                 break;
572                         case 0x02:
573                                 len += sprintf(buf+len,"2.0\n");
574                                 break;
575                 }
576
577                 len += sprintf(buf+len, "Highest I2O version supported: ");
578                 switch(workspace[3]) {
579                         case 0x00:
580                                 len += sprintf(buf+len,"1.0\n");
581                                 break;
582                         case 0x01:
583                                 len += sprintf(buf+len,"1.5\n");
584                                 break;
585                         case 0x02:
586                                 len += sprintf(buf+len,"2.0\n");
587                                 break;
588                 }
589         }
590 */
591         len += sprintf(buf+len,"IOP ID                 : %0#5x\n", 
592                                 c->status_block->iop_id);
593         len += sprintf(buf+len,"Host Unit ID           : %0#6x\n",
594                                 c->status_block->host_unit_id);
595         len += sprintf(buf+len,"Segment Number         : %0#5x\n",
596                                 c->status_block->segment_number);
597
598         len += sprintf(buf+len, "I2O version            : ");
599         switch (version) {
600                 case 0x00:
601                         len += sprintf(buf+len,"1.0\n");
602                         break;
603                 case 0x01:
604                         len += sprintf(buf+len,"1.5\n");
605                         break;
606                 case 0x02:
607                         len += sprintf(buf+len,"2.0\n");
608                         break;
609                 default:
610                         len += sprintf(buf+len,"Unknown version\n");
611         }
612
613         len += sprintf(buf+len, "IOP State              : ");
614         switch (c->status_block->iop_state) {
615                 case 0x01:
616                         len += sprintf(buf+len,"INIT\n");
617                         break;
618
619                 case 0x02:
620                         len += sprintf(buf+len,"RESET\n");
621                         break;
622
623                 case 0x04:
624                         len += sprintf(buf+len,"HOLD\n");
625                         break;
626
627                 case 0x05:
628                         len += sprintf(buf+len,"READY\n");
629                         break;
630
631                 case 0x08:
632                         len += sprintf(buf+len,"OPERATIONAL\n");
633                         break;
634
635                 case 0x10:
636                         len += sprintf(buf+len,"FAILED\n");
637                         break;
638
639                 case 0x11:
640                         len += sprintf(buf+len,"FAULTED\n");
641                         break;
642
643                 default:
644                         len += sprintf(buf+len,"Unknown\n");
645                         break;
646         }
647
648         len += sprintf(buf+len,"Messenger Type         : ");
649         switch (c->status_block->msg_type) { 
650                 case 0x00:
651                         len += sprintf(buf+len,"Memory mapped\n");
652                         break;
653                 case 0x01:
654                         len += sprintf(buf+len,"Memory mapped only\n");
655                         break;
656                 case 0x02:
657                         len += sprintf(buf+len,"Remote only\n");
658                         break;
659                 case 0x03:
660                         len += sprintf(buf+len,"Memory mapped and remote\n");
661                         break;
662                 default:
663                         len += sprintf(buf+len,"Unknown\n");
664         }
665
666         len += sprintf(buf+len,"Inbound Frame Size     : %d bytes\n", 
667                                 c->status_block->inbound_frame_size<<2);
668         len += sprintf(buf+len,"Max Inbound Frames     : %d\n", 
669                                 c->status_block->max_inbound_frames);
670         len += sprintf(buf+len,"Current Inbound Frames : %d\n", 
671                                 c->status_block->cur_inbound_frames);
672         len += sprintf(buf+len,"Max Outbound Frames    : %d\n", 
673                                 c->status_block->max_outbound_frames);
674
675         /* Spec doesn't say if NULL terminated or not... */
676         memcpy(prodstr, c->status_block->product_id, 24);
677         prodstr[24] = '\0';
678         len += sprintf(buf+len,"Product ID             : %s\n", prodstr);
679         len += sprintf(buf+len,"Expected LCT Size      : %d bytes\n", 
680                                 c->status_block->expected_lct_size);
681
682         len += sprintf(buf+len,"IOP Capabilities\n");
683         len += sprintf(buf+len,"    Context Field Size Support : ");
684         switch (c->status_block->iop_capabilities & 0x0000003) {
685                 case 0:
686                         len += sprintf(buf+len,"Supports only 32-bit context fields\n");
687                         break;
688                 case 1:
689                         len += sprintf(buf+len,"Supports only 64-bit context fields\n");
690                         break;
691                 case 2:
692                         len += sprintf(buf+len,"Supports 32-bit and 64-bit context fields, "
693                                                 "but not concurrently\n");
694                         break;
695                 case 3:
696                         len += sprintf(buf+len,"Supports 32-bit and 64-bit context fields "
697                                                 "concurrently\n");
698                         break;
699                 default:
700                         len += sprintf(buf+len,"0x%08x\n",c->status_block->iop_capabilities);
701         }
702         len += sprintf(buf+len,"    Current Context Field Size : ");
703         switch (c->status_block->iop_capabilities & 0x0000000C) {
704                 case 0:
705                         len += sprintf(buf+len,"not configured\n");
706                         break;
707                 case 4:
708                         len += sprintf(buf+len,"Supports only 32-bit context fields\n");
709                         break;
710                 case 8:
711                         len += sprintf(buf+len,"Supports only 64-bit context fields\n");
712                         break;
713                 case 12:
714                         len += sprintf(buf+len,"Supports both 32-bit or 64-bit context fields "
715                                                 "concurrently\n");
716                         break;
717                 default:
718                         len += sprintf(buf+len,"\n");
719         }
720         len += sprintf(buf+len,"    Inbound Peer Support       : %s\n",
721                         (c->status_block->iop_capabilities & 0x00000010) ? "Supported" : "Not supported");
722         len += sprintf(buf+len,"    Outbound Peer Support      : %s\n",
723                         (c->status_block->iop_capabilities & 0x00000020) ? "Supported" : "Not supported");
724         len += sprintf(buf+len,"    Peer to Peer Support       : %s\n",
725                         (c->status_block->iop_capabilities & 0x00000040) ? "Supported" : "Not supported");
726
727         len += sprintf(buf+len, "Desired private memory size   : %d kB\n", 
728                                 c->status_block->desired_mem_size>>10);
729         len += sprintf(buf+len, "Allocated private memory size : %d kB\n", 
730                                 c->status_block->current_mem_size>>10);
731         len += sprintf(buf+len, "Private memory base address   : %0#10x\n", 
732                                 c->status_block->current_mem_base);
733         len += sprintf(buf+len, "Desired private I/O size      : %d kB\n", 
734                                 c->status_block->desired_io_size>>10);
735         len += sprintf(buf+len, "Allocated private I/O size    : %d kB\n", 
736                                 c->status_block->current_io_size>>10);
737         len += sprintf(buf+len, "Private I/O base address      : %0#10x\n", 
738                                 c->status_block->current_io_base);
739
740         spin_unlock(&i2o_proc_lock);
741
742         return len;
743 }
744
745 int i2o_proc_read_hw(char *buf, char **start, off_t offset, int len, 
746                      int *eof, void *data)
747 {
748         struct i2o_controller *c = (struct i2o_controller*)data;
749         static u32 work32[5];
750         static u8 *work8 = (u8*)work32;
751         static u16 *work16 = (u16*)work32;
752         int token;
753         u32 hwcap;
754
755         static char *cpu_table[] =
756         {
757                 "Intel 80960 series",
758                 "AMD2900 series",
759                 "Motorola 68000 series",
760                 "ARM series",
761                 "MIPS series",
762                 "Sparc series",
763                 "PowerPC series",
764                 "Intel x86 series"
765         };
766
767         spin_lock(&i2o_proc_lock);
768
769         len = 0;
770
771         token = i2o_query_scalar(c, ADAPTER_TID, 0x0000, -1, &work32, sizeof(work32));
772
773         if (token < 0) {
774                 len += i2o_report_query_status(buf+len, token,"0x0000 IOP Hardware");
775                 spin_unlock(&i2o_proc_lock);
776                 return len;
777         }
778
779         len += sprintf(buf+len, "I2O Vendor ID    : %0#6x\n", work16[0]);
780         len += sprintf(buf+len, "Product ID       : %0#6x\n", work16[1]);
781         len += sprintf(buf+len, "CPU              : ");
782         if(work8[16] > 8)
783                 len += sprintf(buf+len, "Unknown\n");
784         else
785                 len += sprintf(buf+len, "%s\n", cpu_table[work8[16]]);
786         /* Anyone using ProcessorVersion? */
787         
788         len += sprintf(buf+len, "RAM              : %dkB\n", work32[1]>>10);
789         len += sprintf(buf+len, "Non-Volatile Mem : %dkB\n", work32[2]>>10);
790
791         hwcap = work32[3];
792         len += sprintf(buf+len, "Capabilities : 0x%08x\n", hwcap);
793         len += sprintf(buf+len, "   [%s] Self booting\n",
794                         (hwcap&0x00000001) ? "+" : "-");
795         len += sprintf(buf+len, "   [%s] Upgradable IRTOS\n",
796                         (hwcap&0x00000002) ? "+" : "-");
797         len += sprintf(buf+len, "   [%s] Supports downloading DDMs\n",
798                         (hwcap&0x00000004) ? "+" : "-");
799         len += sprintf(buf+len, "   [%s] Supports installing DDMs\n",
800                         (hwcap&0x00000008) ? "+" : "-");
801         len += sprintf(buf+len, "   [%s] Battery-backed RAM\n",
802                         (hwcap&0x00000010) ? "+" : "-");
803
804         spin_unlock(&i2o_proc_lock);
805
806         return len;
807 }
808
809
810 /* Executive group 0003h - Executing DDM List (table) */
811 int i2o_proc_read_ddm_table(char *buf, char **start, off_t offset, int len, 
812                             int *eof, void *data)
813 {
814         struct i2o_controller *c = (struct i2o_controller*)data;
815         int token;
816         int i;
817
818         typedef struct _i2o_exec_execute_ddm_table {
819                 u16 ddm_tid;
820                 u8  module_type;
821                 u8  reserved;
822                 u16 i2o_vendor_id;
823                 u16 module_id;
824                 u8  module_name_version[28];
825                 u32 data_size;
826                 u32 code_size;
827         } i2o_exec_execute_ddm_table;
828
829         struct
830         {
831                 u16 result_count;
832                 u16 pad;
833                 u16 block_size;
834                 u8  block_status;
835                 u8  error_info_size;
836                 u16 row_count;
837                 u16 more_flag;
838                 i2o_exec_execute_ddm_table ddm_table[MAX_I2O_MODULES];
839         } *result;
840
841         i2o_exec_execute_ddm_table ddm_table;
842
843         result = kmalloc(sizeof(*result), GFP_KERNEL);
844         if(!result)
845                 return -ENOMEM;
846
847         spin_lock(&i2o_proc_lock);
848         len = 0;
849
850         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
851                                 c, ADAPTER_TID, 
852                                 0x0003, -1,
853                                 NULL, 0,
854                                 result, sizeof(*result));
855
856         if (token < 0) {
857                 len += i2o_report_query_status(buf+len, token,"0x0003 Executing DDM List");
858                 goto out;
859         }
860
861         len += sprintf(buf+len, "Tid   Module_type     Vendor Mod_id  Module_name             Vrs  Data_size Code_size\n");
862         ddm_table=result->ddm_table[0];
863
864         for(i=0; i < result->row_count; ddm_table=result->ddm_table[++i])
865         {
866                 len += sprintf(buf+len, "0x%03x ", ddm_table.ddm_tid & 0xFFF);
867
868                 switch(ddm_table.module_type)
869                 {
870                 case 0x01:
871                         len += sprintf(buf+len, "Downloaded DDM  ");
872                         break;                  
873                 case 0x22:
874                         len += sprintf(buf+len, "Embedded DDM    ");
875                         break;
876                 default:
877                         len += sprintf(buf+len, "                ");
878                 }
879
880                 len += sprintf(buf+len, "%-#7x", ddm_table.i2o_vendor_id);
881                 len += sprintf(buf+len, "%-#8x", ddm_table.module_id);
882                 len += sprintf(buf+len, "%-29s", chtostr(ddm_table.module_name_version, 28));
883                 len += sprintf(buf+len, "%9d  ", ddm_table.data_size);
884                 len += sprintf(buf+len, "%8d", ddm_table.code_size);
885
886                 len += sprintf(buf+len, "\n");
887         }
888 out:
889         spin_unlock(&i2o_proc_lock);
890         kfree(result);
891         return len;
892 }
893
894
895 /* Executive group 0004h - Driver Store (scalar) */
896 int i2o_proc_read_driver_store(char *buf, char **start, off_t offset, int len, 
897                      int *eof, void *data)
898 {
899         struct i2o_controller *c = (struct i2o_controller*)data;
900         u32 work32[8];
901         int token;
902
903         spin_lock(&i2o_proc_lock);
904
905         len = 0;
906
907         token = i2o_query_scalar(c, ADAPTER_TID, 0x0004, -1, &work32, sizeof(work32));
908         if (token < 0) {
909                 len += i2o_report_query_status(buf+len, token,"0x0004 Driver Store");
910                 spin_unlock(&i2o_proc_lock);
911                 return len;
912         }
913
914         len += sprintf(buf+len, "Module limit  : %d\n"
915                                 "Module count  : %d\n"
916                                 "Current space : %d kB\n"
917                                 "Free space    : %d kB\n", 
918                         work32[0], work32[1], work32[2]>>10, work32[3]>>10);
919
920         spin_unlock(&i2o_proc_lock);
921
922         return len;
923 }
924
925
926 /* Executive group 0005h - Driver Store Table (table) */
927 int i2o_proc_read_drivers_stored(char *buf, char **start, off_t offset,
928                                  int len, int *eof, void *data)
929 {
930         typedef struct _i2o_driver_store {
931                 u16 stored_ddm_index;
932                 u8  module_type;
933                 u8  reserved;
934                 u16 i2o_vendor_id;
935                 u16 module_id;
936                 u8  module_name_version[28];
937                 u8  date[8];
938                 u32 module_size;
939                 u32 mpb_size;
940                 u32 module_flags;
941         } i2o_driver_store_table;
942
943         struct i2o_controller *c = (struct i2o_controller*)data;
944         int token;
945         int i;
946
947         typedef struct
948         {
949                 u16 result_count;
950                 u16 pad;
951                 u16 block_size;
952                 u8  block_status;
953                 u8  error_info_size;
954                 u16 row_count;
955                 u16 more_flag;
956                 i2o_driver_store_table dst[MAX_I2O_MODULES];
957         } i2o_driver_result_table;
958         
959         i2o_driver_result_table *result;
960         i2o_driver_store_table *dst;
961
962
963         len = 0;
964         
965         result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
966         if(result == NULL)
967                 return -ENOMEM;
968
969         spin_lock(&i2o_proc_lock);
970
971         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
972                                 c, ADAPTER_TID, 0x0005, -1, NULL, 0, 
973                                 result, sizeof(*result));
974
975         if (token < 0) {
976                 len += i2o_report_query_status(buf+len, token,"0x0005 DRIVER STORE TABLE");
977                 spin_unlock(&i2o_proc_lock);
978                 kfree(result);
979                 return len;
980         }
981
982         len += sprintf(buf+len, "#  Module_type     Vendor Mod_id  Module_name             Vrs"  
983                                 "Date     Mod_size Par_size Flags\n");
984         for(i=0, dst=&result->dst[0]; i < result->row_count; dst=&result->dst[++i])
985         {
986                 len += sprintf(buf+len, "%-3d", dst->stored_ddm_index);
987                 switch(dst->module_type)
988                 {
989                 case 0x01:
990                         len += sprintf(buf+len, "Downloaded DDM  ");
991                         break;                  
992                 case 0x22:
993                         len += sprintf(buf+len, "Embedded DDM    ");
994                         break;
995                 default:
996                         len += sprintf(buf+len, "                ");
997                 }
998
999 #if 0
1000                 if(c->i2oversion == 0x02)
1001                         len += sprintf(buf+len, "%-d", dst->module_state);
1002 #endif
1003
1004                 len += sprintf(buf+len, "%-#7x", dst->i2o_vendor_id);
1005                 len += sprintf(buf+len, "%-#8x", dst->module_id);
1006                 len += sprintf(buf+len, "%-29s", chtostr(dst->module_name_version,28));
1007                 len += sprintf(buf+len, "%-9s", chtostr(dst->date,8));
1008                 len += sprintf(buf+len, "%8d ", dst->module_size);
1009                 len += sprintf(buf+len, "%8d ", dst->mpb_size);
1010                 len += sprintf(buf+len, "0x%04x", dst->module_flags);
1011 #if 0
1012                 if(c->i2oversion == 0x02)
1013                         len += sprintf(buf+len, "%d",
1014                                        dst->notification_level);
1015 #endif
1016                 len += sprintf(buf+len, "\n");
1017         }
1018
1019         spin_unlock(&i2o_proc_lock);
1020         kfree(result);
1021         return len;
1022 }
1023
1024
1025 /* Generic group F000h - Params Descriptor (table) */
1026 int i2o_proc_read_groups(char *buf, char **start, off_t offset, int len, 
1027                          int *eof, void *data)
1028 {
1029         struct i2o_device *d = (struct i2o_device*)data;
1030         int token;
1031         int i;
1032         u8 properties;
1033
1034         typedef struct _i2o_group_info
1035         {
1036                 u16 group_number;
1037                 u16 field_count;
1038                 u16 row_count;
1039                 u8  properties;
1040                 u8  reserved;
1041         } i2o_group_info;
1042
1043         struct
1044         {
1045                 u16 result_count;
1046                 u16 pad;
1047                 u16 block_size;
1048                 u8  block_status;
1049                 u8  error_info_size;
1050                 u16 row_count;
1051                 u16 more_flag;
1052                 i2o_group_info group[256];
1053         } *result;
1054
1055         result = kmalloc(sizeof(*result), GFP_KERNEL);
1056         if(!result)
1057                 return -ENOMEM;
1058
1059         spin_lock(&i2o_proc_lock);
1060
1061         len = 0;
1062
1063         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1064                                 d->controller, d->lct_data.tid, 0xF000, -1, NULL, 0,
1065                                 result, sizeof(*result));
1066
1067         if (token < 0) {
1068                 len = i2o_report_query_status(buf+len, token, "0xF000 Params Descriptor");
1069                 goto out;
1070         }
1071
1072         len += sprintf(buf+len, "#  Group   FieldCount RowCount Type   Add Del Clear\n");
1073
1074         for (i=0; i < result->row_count; i++)
1075         {
1076                 len += sprintf(buf+len, "%-3d", i);
1077                 len += sprintf(buf+len, "0x%04X ", result->group[i].group_number);
1078                 len += sprintf(buf+len, "%10d ", result->group[i].field_count);
1079                 len += sprintf(buf+len, "%8d ",  result->group[i].row_count);
1080
1081                 properties = result->group[i].properties;
1082                 if (properties & 0x1)   len += sprintf(buf+len, "Table  ");
1083                                 else    len += sprintf(buf+len, "Scalar ");
1084                 if (properties & 0x2)   len += sprintf(buf+len, " + ");
1085                                 else    len += sprintf(buf+len, " - ");
1086                 if (properties & 0x4)   len += sprintf(buf+len, "  + ");
1087                                 else    len += sprintf(buf+len, "  - ");
1088                 if (properties & 0x8)   len += sprintf(buf+len, "  + ");
1089                                 else    len += sprintf(buf+len, "  - ");
1090
1091                 len += sprintf(buf+len, "\n");
1092         }
1093
1094         if (result->more_flag)
1095                 len += sprintf(buf+len, "There is more...\n");
1096 out:
1097         spin_unlock(&i2o_proc_lock);
1098         kfree(result);
1099         return len;
1100 }
1101
1102
1103 /* Generic group F001h - Physical Device Table (table) */
1104 int i2o_proc_read_phys_device(char *buf, char **start, off_t offset, int len,
1105                               int *eof, void *data)
1106 {
1107         struct i2o_device *d = (struct i2o_device*)data;
1108         int token;
1109         int i;
1110
1111         struct
1112         {
1113                 u16 result_count;
1114                 u16 pad;
1115                 u16 block_size;
1116                 u8  block_status;
1117                 u8  error_info_size;
1118                 u16 row_count;
1119                 u16 more_flag;
1120                 u32 adapter_id[64];
1121         } result;
1122
1123         spin_lock(&i2o_proc_lock);
1124         len = 0;
1125
1126         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1127                                 d->controller, d->lct_data.tid,
1128                                 0xF001, -1, NULL, 0,
1129                                 &result, sizeof(result));
1130
1131         if (token < 0) {
1132                 len += i2o_report_query_status(buf+len, token,"0xF001 Physical Device Table");
1133                 spin_unlock(&i2o_proc_lock);
1134                 return len;
1135         }
1136
1137         if (result.row_count)
1138                 len += sprintf(buf+len, "#  AdapterId\n");
1139
1140         for (i=0; i < result.row_count; i++)
1141         {
1142                 len += sprintf(buf+len, "%-2d", i);
1143                 len += sprintf(buf+len, "%#7x\n", result.adapter_id[i]);
1144         }
1145
1146         if (result.more_flag)
1147                 len += sprintf(buf+len, "There is more...\n");
1148
1149         spin_unlock(&i2o_proc_lock);
1150         return len;
1151 }
1152
1153 /* Generic group F002h - Claimed Table (table) */
1154 int i2o_proc_read_claimed(char *buf, char **start, off_t offset, int len,
1155                           int *eof, void *data)
1156 {
1157         struct i2o_device *d = (struct i2o_device*)data;
1158         int token;
1159         int i;
1160
1161         struct {
1162                 u16 result_count;
1163                 u16 pad;
1164                 u16 block_size;
1165                 u8  block_status;
1166                 u8  error_info_size;
1167                 u16 row_count;
1168                 u16 more_flag;
1169                 u16 claimed_tid[64];
1170         } result;
1171
1172         spin_lock(&i2o_proc_lock);
1173         len = 0;
1174
1175         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1176                                 d->controller, d->lct_data.tid,
1177                                 0xF002, -1, NULL, 0,
1178                                 &result, sizeof(result));
1179
1180         if (token < 0) {
1181                 len += i2o_report_query_status(buf+len, token,"0xF002 Claimed Table");
1182                 spin_unlock(&i2o_proc_lock);
1183                 return len;
1184         }
1185
1186         if (result.row_count)
1187                 len += sprintf(buf+len, "#  ClaimedTid\n");
1188
1189         for (i=0; i < result.row_count; i++)
1190         {
1191                 len += sprintf(buf+len, "%-2d", i);
1192                 len += sprintf(buf+len, "%#7x\n", result.claimed_tid[i]);
1193         }
1194
1195         if (result.more_flag)
1196                 len += sprintf(buf+len, "There is more...\n");
1197
1198         spin_unlock(&i2o_proc_lock);
1199         return len;
1200 }
1201
1202 /* Generic group F003h - User Table (table) */
1203 int i2o_proc_read_users(char *buf, char **start, off_t offset, int len,
1204                         int *eof, void *data)
1205 {
1206         struct i2o_device *d = (struct i2o_device*)data;
1207         int token;
1208         int i;
1209
1210         typedef struct _i2o_user_table
1211         {
1212                 u16 instance;
1213                 u16 user_tid;
1214                 u8 claim_type;
1215                 u8  reserved1;
1216                 u16  reserved2;
1217         } i2o_user_table;
1218
1219         struct
1220         {
1221                 u16 result_count;
1222                 u16 pad;
1223                 u16 block_size;
1224                 u8  block_status;
1225                 u8  error_info_size;
1226                 u16 row_count;
1227                 u16 more_flag;
1228                 i2o_user_table user[64];
1229         } *result;
1230
1231         result = kmalloc(sizeof(*result), GFP_KERNEL);
1232         if(!result)
1233                 return -ENOMEM;
1234
1235         spin_lock(&i2o_proc_lock);
1236         len = 0;
1237
1238         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1239                                 d->controller, d->lct_data.tid,
1240                                 0xF003, -1, NULL, 0,
1241                                 result, sizeof(*result));
1242
1243         if (token < 0) {
1244                 len += i2o_report_query_status(buf+len, token,"0xF003 User Table");
1245                 goto out;
1246         }
1247
1248         len += sprintf(buf+len, "#  Instance UserTid ClaimType\n");
1249
1250         for(i=0; i < result->row_count; i++)
1251         {
1252                 len += sprintf(buf+len, "%-3d", i);
1253                 len += sprintf(buf+len, "%#8x ", result->user[i].instance);
1254                 len += sprintf(buf+len, "%#7x ", result->user[i].user_tid);
1255                 len += sprintf(buf+len, "%#9x\n", result->user[i].claim_type);
1256         }
1257
1258         if (result->more_flag)
1259                 len += sprintf(buf+len, "There is more...\n");
1260 out:
1261         spin_unlock(&i2o_proc_lock);
1262         kfree(result);
1263         return len;
1264 }
1265
1266 /* Generic group F005h - Private message extensions (table) (optional) */
1267 int i2o_proc_read_priv_msgs(char *buf, char **start, off_t offset, int len, 
1268                             int *eof, void *data)
1269 {
1270         struct i2o_device *d = (struct i2o_device*)data;
1271         int token;
1272         int i;
1273
1274         typedef struct _i2o_private
1275         {
1276                 u16 ext_instance;
1277                 u16 organization_id;
1278                 u16 x_function_code;
1279         } i2o_private;
1280
1281         struct
1282         {
1283                 u16 result_count;
1284                 u16 pad;
1285                 u16 block_size;
1286                 u8  block_status;
1287                 u8  error_info_size;
1288                 u16 row_count;
1289                 u16 more_flag;
1290                 i2o_private extension[64];
1291         } result;
1292
1293         spin_lock(&i2o_proc_lock);
1294
1295         len = 0;
1296
1297         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1298                                 d->controller, d->lct_data.tid,
1299                                 0xF000, -1,
1300                                 NULL, 0,
1301                                 &result, sizeof(result));
1302
1303         if (token < 0) {
1304                 len += i2o_report_query_status(buf+len, token,"0xF005 Private Message Extensions (optional)");
1305                 spin_unlock(&i2o_proc_lock);
1306                 return len;
1307         }
1308         
1309         len += sprintf(buf+len, "Instance#  OrgId  FunctionCode\n");
1310
1311         for(i=0; i < result.row_count; i++)
1312         {
1313                 len += sprintf(buf+len, "%0#9x ", result.extension[i].ext_instance);
1314                 len += sprintf(buf+len, "%0#6x ", result.extension[i].organization_id);
1315                 len += sprintf(buf+len, "%0#6x",  result.extension[i].x_function_code);
1316
1317                 len += sprintf(buf+len, "\n");
1318         }
1319
1320         if(result.more_flag)
1321                 len += sprintf(buf+len, "There is more...\n");
1322
1323         spin_unlock(&i2o_proc_lock);
1324
1325         return len;
1326 }
1327
1328
1329 /* Generic group F006h - Authorized User Table (table) */
1330 int i2o_proc_read_authorized_users(char *buf, char **start, off_t offset, int len,
1331                                    int *eof, void *data)
1332 {
1333         struct i2o_device *d = (struct i2o_device*)data;
1334         int token;
1335         int i;
1336
1337         struct
1338         {
1339                 u16 result_count;
1340                 u16 pad;
1341                 u16 block_size;
1342                 u8  block_status;
1343                 u8  error_info_size;
1344                 u16 row_count;
1345                 u16 more_flag;
1346                 u32 alternate_tid[64];
1347         } result;
1348
1349         spin_lock(&i2o_proc_lock);
1350         len = 0;
1351
1352         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1353                                 d->controller, d->lct_data.tid,
1354                                 0xF006, -1,
1355                                 NULL, 0,
1356                                 &result, sizeof(result));
1357
1358         if (token < 0) {
1359                 len += i2o_report_query_status(buf+len, token,"0xF006 Autohorized User Table");
1360                 spin_unlock(&i2o_proc_lock);
1361                 return len;
1362         }
1363
1364         if (result.row_count)
1365                 len += sprintf(buf+len, "#  AlternateTid\n");
1366
1367         for(i=0; i < result.row_count; i++)
1368         {
1369                 len += sprintf(buf+len, "%-2d", i);
1370                 len += sprintf(buf+len, "%#7x ", result.alternate_tid[i]);
1371         }
1372
1373         if (result.more_flag)
1374                 len += sprintf(buf+len, "There is more...\n");
1375
1376         spin_unlock(&i2o_proc_lock);
1377         return len;
1378 }
1379
1380
1381 /* Generic group F100h - Device Identity (scalar) */
1382 int i2o_proc_read_dev_identity(char *buf, char **start, off_t offset, int len, 
1383                                int *eof, void *data)
1384 {
1385         struct i2o_device *d = (struct i2o_device*)data;
1386         static u32 work32[128];         // allow for "stuff" + up to 256 byte (max) serial number
1387                                         // == (allow) 512d bytes (max)
1388         static u16 *work16 = (u16*)work32;
1389         int token;
1390
1391         spin_lock(&i2o_proc_lock);
1392         
1393         len = 0;
1394
1395         token = i2o_query_scalar(d->controller, d->lct_data.tid,
1396                                 0xF100, -1,
1397                                 &work32, sizeof(work32));
1398
1399         if (token < 0) {
1400                 len += i2o_report_query_status(buf+len, token ,"0xF100 Device Identity");
1401                 spin_unlock(&i2o_proc_lock);
1402                 return len;
1403         }
1404         
1405         len += sprintf(buf,     "Device Class  : %s\n", i2o_get_class_name(work16[0]));
1406         len += sprintf(buf+len, "Owner TID     : %0#5x\n", work16[2]);
1407         len += sprintf(buf+len, "Parent TID    : %0#5x\n", work16[3]);
1408         len += sprintf(buf+len, "Vendor info   : %s\n", chtostr((u8 *)(work32+2), 16));
1409         len += sprintf(buf+len, "Product info  : %s\n", chtostr((u8 *)(work32+6), 16));
1410         len += sprintf(buf+len, "Description   : %s\n", chtostr((u8 *)(work32+10), 16));
1411         len += sprintf(buf+len, "Product rev.  : %s\n", chtostr((u8 *)(work32+14), 8));
1412
1413         len += sprintf(buf+len, "Serial number : ");
1414         len = print_serial_number(buf, len,
1415                         (u8*)(work32+16),
1416                                                 /* allow for SNLen plus
1417                                                  * possible trailing '\0'
1418                                                  */
1419                         sizeof(work32)-(16*sizeof(u32))-2
1420                                 );
1421         len +=  sprintf(buf+len, "\n");
1422
1423         spin_unlock(&i2o_proc_lock);
1424
1425         return len;
1426 }
1427
1428
1429 int i2o_proc_read_dev_name(char *buf, char **start, off_t offset, int len,
1430         int *eof, void *data)
1431 {
1432         struct i2o_device *d = (struct i2o_device*)data;
1433
1434         if ( d->dev_name[0] == '\0' )
1435                 return 0;
1436
1437         len = sprintf(buf, "%s\n", d->dev_name);
1438
1439         return len;
1440 }
1441
1442
1443 /* Generic group F101h - DDM Identity (scalar) */
1444 int i2o_proc_read_ddm_identity(char *buf, char **start, off_t offset, int len, 
1445                               int *eof, void *data)
1446 {
1447         struct i2o_device *d = (struct i2o_device*)data;
1448         int token;
1449
1450         struct
1451         {
1452                 u16 ddm_tid;
1453                 u8 module_name[24];
1454                 u8 module_rev[8];
1455                 u8 sn_format;
1456                 u8 serial_number[12];
1457                 u8 pad[256]; // allow up to 256 byte (max) serial number
1458         } result;       
1459
1460         spin_lock(&i2o_proc_lock);
1461         
1462         len = 0;
1463
1464         token = i2o_query_scalar(d->controller, d->lct_data.tid, 
1465                                 0xF101, -1,
1466                                 &result, sizeof(result));
1467
1468         if (token < 0) {
1469                 len += i2o_report_query_status(buf+len, token,"0xF101 DDM Identity");
1470                 spin_unlock(&i2o_proc_lock);
1471                 return len;
1472         }
1473
1474         len += sprintf(buf,     "Registering DDM TID : 0x%03x\n", result.ddm_tid);
1475         len += sprintf(buf+len, "Module name         : %s\n", chtostr(result.module_name, 24));
1476         len += sprintf(buf+len, "Module revision     : %s\n", chtostr(result.module_rev, 8));
1477
1478         len += sprintf(buf+len, "Serial number       : ");
1479         len = print_serial_number(buf, len, result.serial_number, sizeof(result)-36);
1480                                 /* allow for SNLen plus possible trailing '\0' */
1481
1482         len += sprintf(buf+len, "\n");
1483
1484         spin_unlock(&i2o_proc_lock);
1485
1486         return len;
1487 }
1488
1489 /* Generic group F102h - User Information (scalar) */
1490 int i2o_proc_read_uinfo(char *buf, char **start, off_t offset, int len, 
1491                         int *eof, void *data)
1492 {
1493         struct i2o_device *d = (struct i2o_device*)data;
1494         int token;
1495
1496         struct
1497         {
1498                 u8 device_name[64];
1499                 u8 service_name[64];
1500                 u8 physical_location[64];
1501                 u8 instance_number[4];
1502         } result;
1503
1504         spin_lock(&i2o_proc_lock);
1505         len = 0;
1506
1507         token = i2o_query_scalar(d->controller, d->lct_data.tid,
1508                                 0xF102, -1,
1509                                 &result, sizeof(result));
1510
1511         if (token < 0) {
1512                 len += i2o_report_query_status(buf+len, token,"0xF102 User Information");
1513                 spin_unlock(&i2o_proc_lock);
1514                 return len;
1515         }
1516
1517         len += sprintf(buf,     "Device name     : %s\n", chtostr(result.device_name, 64));
1518         len += sprintf(buf+len, "Service name    : %s\n", chtostr(result.service_name, 64));
1519         len += sprintf(buf+len, "Physical name   : %s\n", chtostr(result.physical_location, 64));
1520         len += sprintf(buf+len, "Instance number : %s\n", chtostr(result.instance_number, 4));
1521
1522         spin_unlock(&i2o_proc_lock);
1523         return len;
1524 }
1525
1526 /* Generic group F103h - SGL Operating Limits (scalar) */
1527 int i2o_proc_read_sgl_limits(char *buf, char **start, off_t offset, int len, 
1528                              int *eof, void *data)
1529 {
1530         struct i2o_device *d = (struct i2o_device*)data;
1531         static u32 work32[12];
1532         static u16 *work16 = (u16 *)work32;
1533         static u8 *work8 = (u8 *)work32;
1534         int token;
1535
1536         spin_lock(&i2o_proc_lock);
1537         
1538         len = 0;
1539
1540         token = i2o_query_scalar(d->controller, d->lct_data.tid, 
1541                                  0xF103, -1,
1542                                  &work32, sizeof(work32));
1543
1544         if (token < 0) {
1545                 len += i2o_report_query_status(buf+len, token,"0xF103 SGL Operating Limits");
1546                 spin_unlock(&i2o_proc_lock);
1547                 return len;
1548         }
1549
1550         len += sprintf(buf,     "SGL chain size        : %d\n", work32[0]);
1551         len += sprintf(buf+len, "Max SGL chain size    : %d\n", work32[1]);
1552         len += sprintf(buf+len, "SGL chain size target : %d\n", work32[2]);
1553         len += sprintf(buf+len, "SGL frag count        : %d\n", work16[6]);
1554         len += sprintf(buf+len, "Max SGL frag count    : %d\n", work16[7]);
1555         len += sprintf(buf+len, "SGL frag count target : %d\n", work16[8]);
1556
1557         if (d->i2oversion == 0x02)
1558         {
1559                 len += sprintf(buf+len, "SGL data alignment    : %d\n", work16[8]);
1560                 len += sprintf(buf+len, "SGL addr limit        : %d\n", work8[20]);
1561                 len += sprintf(buf+len, "SGL addr sizes supported : ");
1562                 if (work8[21] & 0x01)
1563                         len += sprintf(buf+len, "32 bit ");
1564                 if (work8[21] & 0x02)
1565                         len += sprintf(buf+len, "64 bit ");
1566                 if (work8[21] & 0x04)
1567                         len += sprintf(buf+len, "96 bit ");
1568                 if (work8[21] & 0x08)
1569                         len += sprintf(buf+len, "128 bit ");
1570                 len += sprintf(buf+len, "\n");
1571         }
1572
1573         spin_unlock(&i2o_proc_lock);
1574
1575         return len;
1576 }
1577
1578 /* Generic group F200h - Sensors (scalar) */
1579 int i2o_proc_read_sensors(char *buf, char **start, off_t offset, int len,
1580                           int *eof, void *data)
1581 {
1582         struct i2o_device *d = (struct i2o_device*)data;
1583         int token;
1584
1585         struct
1586         {
1587                 u16 sensor_instance;
1588                 u8  component;
1589                 u16 component_instance;
1590                 u8  sensor_class;
1591                 u8  sensor_type;
1592                 u8  scaling_exponent;
1593                 u32 actual_reading;
1594                 u32 minimum_reading;
1595                 u32 low2lowcat_treshold;
1596                 u32 lowcat2low_treshold;
1597                 u32 lowwarn2low_treshold;
1598                 u32 low2lowwarn_treshold;
1599                 u32 norm2lowwarn_treshold;
1600                 u32 lowwarn2norm_treshold;
1601                 u32 nominal_reading;
1602                 u32 hiwarn2norm_treshold;
1603                 u32 norm2hiwarn_treshold;
1604                 u32 high2hiwarn_treshold;
1605                 u32 hiwarn2high_treshold;
1606                 u32 hicat2high_treshold;
1607                 u32 hi2hicat_treshold;
1608                 u32 maximum_reading;
1609                 u8  sensor_state;
1610                 u16 event_enable;
1611         } result;
1612         
1613         spin_lock(&i2o_proc_lock);      
1614         len = 0;
1615
1616         token = i2o_query_scalar(d->controller, d->lct_data.tid,
1617                                  0xF200, -1,
1618                                  &result, sizeof(result));
1619
1620         if (token < 0) {
1621                 len += i2o_report_query_status(buf+len, token,"0xF200 Sensors (optional)");
1622                 spin_unlock(&i2o_proc_lock);
1623                 return len;
1624         }
1625         
1626         len += sprintf(buf+len, "Sensor instance       : %d\n", result.sensor_instance);
1627
1628         len += sprintf(buf+len, "Component             : %d = ", result.component);
1629         switch (result.component)
1630         {
1631         case 0: len += sprintf(buf+len, "Other");               
1632                 break;
1633         case 1: len += sprintf(buf+len, "Planar logic Board");
1634                 break;
1635         case 2: len += sprintf(buf+len, "CPU");
1636                 break;
1637         case 3: len += sprintf(buf+len, "Chassis");
1638                 break;
1639         case 4: len += sprintf(buf+len, "Power Supply");
1640                 break;
1641         case 5: len += sprintf(buf+len, "Storage");
1642                 break;
1643         case 6: len += sprintf(buf+len, "External");
1644                 break;
1645         }               
1646         len += sprintf(buf+len,"\n");
1647
1648         len += sprintf(buf+len, "Component instance    : %d\n", result.component_instance);
1649         len += sprintf(buf+len, "Sensor class          : %s\n",
1650                                 result.sensor_class ? "Analog" : "Digital");
1651         
1652         len += sprintf(buf+len, "Sensor type           : %d = ",result.sensor_type);
1653         switch (result.sensor_type)
1654         {
1655         case 0: len += sprintf(buf+len, "Other\n");
1656                 break;
1657         case 1: len += sprintf(buf+len, "Thermal\n");
1658                 break;
1659         case 2: len += sprintf(buf+len, "DC voltage (DC volts)\n");
1660                 break;
1661         case 3: len += sprintf(buf+len, "AC voltage (AC volts)\n");
1662                 break;
1663         case 4: len += sprintf(buf+len, "DC current (DC amps)\n");
1664                 break;
1665         case 5: len += sprintf(buf+len, "AC current (AC volts)\n");
1666                 break;
1667         case 6: len += sprintf(buf+len, "Door open\n");
1668                 break;
1669         case 7: len += sprintf(buf+len, "Fan operational\n");
1670                 break;
1671         }                       
1672
1673         len += sprintf(buf+len, "Scaling exponent      : %d\n", result.scaling_exponent);
1674         len += sprintf(buf+len, "Actual reading        : %d\n", result.actual_reading);
1675         len += sprintf(buf+len, "Minimum reading       : %d\n", result.minimum_reading);
1676         len += sprintf(buf+len, "Low2LowCat treshold   : %d\n", result.low2lowcat_treshold);
1677         len += sprintf(buf+len, "LowCat2Low treshold   : %d\n", result.lowcat2low_treshold);
1678         len += sprintf(buf+len, "LowWarn2Low treshold  : %d\n", result.lowwarn2low_treshold);
1679         len += sprintf(buf+len, "Low2LowWarn treshold  : %d\n", result.low2lowwarn_treshold);
1680         len += sprintf(buf+len, "Norm2LowWarn treshold : %d\n", result.norm2lowwarn_treshold);
1681         len += sprintf(buf+len, "LowWarn2Norm treshold : %d\n", result.lowwarn2norm_treshold);
1682         len += sprintf(buf+len, "Nominal reading       : %d\n", result.nominal_reading);
1683         len += sprintf(buf+len, "HiWarn2Norm treshold  : %d\n", result.hiwarn2norm_treshold);
1684         len += sprintf(buf+len, "Norm2HiWarn treshold  : %d\n", result.norm2hiwarn_treshold);
1685         len += sprintf(buf+len, "High2HiWarn treshold  : %d\n", result.high2hiwarn_treshold);
1686         len += sprintf(buf+len, "HiWarn2High treshold  : %d\n", result.hiwarn2high_treshold);
1687         len += sprintf(buf+len, "HiCat2High treshold   : %d\n", result.hicat2high_treshold);
1688         len += sprintf(buf+len, "High2HiCat treshold   : %d\n", result.hi2hicat_treshold);
1689         len += sprintf(buf+len, "Maximum reading       : %d\n", result.maximum_reading);
1690
1691         len += sprintf(buf+len, "Sensor state          : %d = ", result.sensor_state);
1692         switch (result.sensor_state)
1693         {
1694         case 0:  len += sprintf(buf+len, "Normal\n");
1695                  break;
1696         case 1:  len += sprintf(buf+len, "Abnormal\n");
1697                  break;
1698         case 2:  len += sprintf(buf+len, "Unknown\n");
1699                  break;
1700         case 3:  len += sprintf(buf+len, "Low Catastrophic (LoCat)\n");
1701                  break;
1702         case 4:  len += sprintf(buf+len, "Low (Low)\n");
1703                  break;
1704         case 5:  len += sprintf(buf+len, "Low Warning (LoWarn)\n");
1705                  break;
1706         case 6:  len += sprintf(buf+len, "High Warning (HiWarn)\n");
1707                  break;
1708         case 7:  len += sprintf(buf+len, "High (High)\n");
1709                  break;
1710         case 8:  len += sprintf(buf+len, "High Catastrophic (HiCat)\n");
1711                  break;
1712         }                       
1713
1714         len += sprintf(buf+len, "Event_enable : 0x%02X\n", result.event_enable);
1715         len += sprintf(buf+len, "    [%s] Operational state change. \n",
1716                         (result.event_enable & 0x01) ? "+" : "-" );
1717         len += sprintf(buf+len, "    [%s] Low catastrophic. \n",
1718                         (result.event_enable & 0x02) ? "+" : "-" );
1719         len += sprintf(buf+len, "    [%s] Low reading. \n",
1720                         (result.event_enable & 0x04) ? "+" : "-" );
1721         len += sprintf(buf+len, "    [%s] Low warning. \n",
1722                         (result.event_enable & 0x08) ? "+" : "-" );
1723         len += sprintf(buf+len, "    [%s] Change back to normal from out of range state. \n",
1724                         (result.event_enable & 0x10) ? "+" : "-" );
1725         len += sprintf(buf+len, "    [%s] High warning. \n",
1726                         (result.event_enable & 0x20) ? "+" : "-" );
1727         len += sprintf(buf+len, "    [%s] High reading. \n",
1728                         (result.event_enable & 0x40) ? "+" : "-" );
1729         len += sprintf(buf+len, "    [%s] High catastrophic. \n",
1730                         (result.event_enable & 0x80) ? "+" : "-" );
1731
1732         spin_unlock(&i2o_proc_lock);
1733         return len;
1734 }
1735
1736
1737 static int print_serial_number(char *buff, int pos, u8 *serialno, int max_len)
1738 {
1739         int i;
1740
1741         /* 19990419 -sralston
1742          *      The I2O v1.5 (and v2.0 so far) "official specification"
1743          *      got serial numbers WRONG!
1744          *      Apparently, and despite what Section 3.4.4 says and
1745          *      Figure 3-35 shows (pg 3-39 in the pdf doc),
1746          *      the convention / consensus seems to be:
1747          *        + First byte is SNFormat
1748          *        + Second byte is SNLen (but only if SNFormat==7 (?))
1749          *        + (v2.0) SCSI+BS may use IEEE Registered (64 or 128 bit) format
1750          */
1751         switch(serialno[0])
1752         {
1753                 case I2O_SNFORMAT_BINARY:               /* Binary */
1754                         pos += sprintf(buff+pos, "0x");
1755                         for(i = 0; i < serialno[1]; i++)
1756                         {
1757                                 pos += sprintf(buff+pos, "%02X", serialno[2+i]);
1758                         }
1759                         break;
1760         
1761                 case I2O_SNFORMAT_ASCII:                /* ASCII */
1762                         if ( serialno[1] < ' ' )        /* printable or SNLen? */
1763                         {
1764                                 /* sanity */
1765                                 max_len = (max_len < serialno[1]) ? max_len : serialno[1];
1766                                 serialno[1+max_len] = '\0';
1767
1768                                 /* just print it */
1769                                 pos += sprintf(buff+pos, "%s", &serialno[2]);
1770                         }
1771                         else
1772                         {
1773                                 /* print chars for specified length */
1774                                 for(i = 0; i < serialno[1]; i++)
1775                                 {
1776                                         pos += sprintf(buff+pos, "%c", serialno[2+i]);
1777                                 }
1778                         }
1779                         break;
1780
1781                 case I2O_SNFORMAT_UNICODE:              /* UNICODE */
1782                         pos += sprintf(buff+pos, "UNICODE Format.  Can't Display\n");
1783                         break;
1784
1785                 case I2O_SNFORMAT_LAN48_MAC:            /* LAN-48 MAC Address */
1786                         pos += sprintf(buff+pos, 
1787                                                 "LAN-48 MAC address @ %02X:%02X:%02X:%02X:%02X:%02X",
1788                                                 serialno[2], serialno[3],
1789                                                 serialno[4], serialno[5],
1790                                                 serialno[6], serialno[7]);
1791                         break;
1792
1793                 case I2O_SNFORMAT_WAN:                  /* WAN MAC Address */
1794                         /* FIXME: Figure out what a WAN access address looks like?? */
1795                         pos += sprintf(buff+pos, "WAN Access Address");
1796                         break;
1797
1798 /* plus new in v2.0 */
1799                 case I2O_SNFORMAT_LAN64_MAC:            /* LAN-64 MAC Address */
1800                         /* FIXME: Figure out what a LAN-64 address really looks like?? */
1801                         pos += sprintf(buff+pos, 
1802                                                 "LAN-64 MAC address @ [?:%02X:%02X:?] %02X:%02X:%02X:%02X:%02X:%02X",
1803                                                 serialno[8], serialno[9],
1804                                                 serialno[2], serialno[3],
1805                                                 serialno[4], serialno[5],
1806                                                 serialno[6], serialno[7]);
1807                         break;
1808
1809
1810                 case I2O_SNFORMAT_DDM:                  /* I2O DDM */
1811                         pos += sprintf(buff+pos, 
1812                                                 "DDM: Tid=%03Xh, Rsvd=%04Xh, OrgId=%04Xh",
1813                                                 *(u16*)&serialno[2],
1814                                                 *(u16*)&serialno[4],
1815                                                 *(u16*)&serialno[6]);
1816                         break;
1817
1818                 case I2O_SNFORMAT_IEEE_REG64:           /* IEEE Registered (64-bit) */
1819                 case I2O_SNFORMAT_IEEE_REG128:          /* IEEE Registered (128-bit) */
1820                         /* FIXME: Figure if this is even close?? */
1821                         pos += sprintf(buff+pos, 
1822                                                 "IEEE NodeName(hi,lo)=(%08Xh:%08Xh), PortName(hi,lo)=(%08Xh:%08Xh)\n",
1823                                                 *(u32*)&serialno[2],
1824                                                 *(u32*)&serialno[6],
1825                                                 *(u32*)&serialno[10],
1826                                                 *(u32*)&serialno[14]);
1827                         break;
1828
1829
1830                 case I2O_SNFORMAT_UNKNOWN:              /* Unknown 0    */
1831                 case I2O_SNFORMAT_UNKNOWN2:             /* Unknown 0xff */
1832                 default:
1833                         pos += sprintf(buff+pos, "Unknown data format (0x%02x)",
1834                                        serialno[0]);
1835                         break;
1836         }
1837
1838         return pos;
1839 }
1840
1841 const char * i2o_get_connector_type(int conn)
1842 {
1843         int idx = 16;
1844         static char *i2o_connector_type[] = {
1845                 "OTHER",
1846                 "UNKNOWN",
1847                 "AUI",
1848                 "UTP",
1849                 "BNC",
1850                 "RJ45",
1851                 "STP DB9",
1852                 "FIBER MIC",
1853                 "APPLE AUI",
1854                 "MII",
1855                 "DB9",
1856                 "HSSDC",
1857                 "DUPLEX SC FIBER",
1858                 "DUPLEX ST FIBER",
1859                 "TNC/BNC",
1860                 "HW DEFAULT"
1861         };
1862
1863         switch(conn)
1864         {
1865         case 0x00000000:
1866                 idx = 0;
1867                 break;
1868         case 0x00000001:
1869                 idx = 1;
1870                 break;
1871         case 0x00000002:
1872                 idx = 2;
1873                 break;
1874         case 0x00000003:
1875                 idx = 3;
1876                 break;
1877         case 0x00000004:
1878                 idx = 4;
1879                 break;
1880         case 0x00000005:
1881                 idx = 5;
1882                 break;
1883         case 0x00000006:
1884                 idx = 6;
1885                 break;
1886         case 0x00000007:
1887                 idx = 7;
1888                 break;
1889         case 0x00000008:
1890                 idx = 8;
1891                 break;
1892         case 0x00000009:
1893                 idx = 9;
1894                 break;
1895         case 0x0000000A:
1896                 idx = 10;
1897                 break;
1898         case 0x0000000B:
1899                 idx = 11;
1900                 break;
1901         case 0x0000000C:
1902                 idx = 12;
1903                 break;
1904         case 0x0000000D:
1905                 idx = 13;
1906                 break;
1907         case 0x0000000E:
1908                 idx = 14;
1909                 break;
1910         case 0xFFFFFFFF:
1911                 idx = 15;
1912                 break;
1913         }
1914
1915         return i2o_connector_type[idx];
1916 }
1917
1918
1919 const char * i2o_get_connection_type(int conn)
1920 {
1921         int idx = 0;
1922         static char *i2o_connection_type[] = {
1923                 "Unknown",
1924                 "AUI",
1925                 "10BASE5",
1926                 "FIORL",
1927                 "10BASE2",
1928                 "10BROAD36",
1929                 "10BASE-T",
1930                 "10BASE-FP",
1931                 "10BASE-FB",
1932                 "10BASE-FL",
1933                 "100BASE-TX",
1934                 "100BASE-FX",
1935                 "100BASE-T4",
1936                 "1000BASE-SX",
1937                 "1000BASE-LX",
1938                 "1000BASE-CX",
1939                 "1000BASE-T",
1940                 "100VG-ETHERNET",
1941                 "100VG-TOKEN RING",
1942                 "4MBIT TOKEN RING",
1943                 "16 Mb Token Ring",
1944                 "125 MBAUD FDDI",
1945                 "Point-to-point",
1946                 "Arbitrated loop",
1947                 "Public loop",
1948                 "Fabric",
1949                 "Emulation",
1950                 "Other",
1951                 "HW default"
1952         };
1953
1954         switch(conn)
1955         {
1956         case I2O_LAN_UNKNOWN:
1957                 idx = 0;
1958                 break;
1959         case I2O_LAN_AUI:
1960                 idx = 1;
1961                 break;
1962         case I2O_LAN_10BASE5:
1963                 idx = 2;
1964                 break;
1965         case I2O_LAN_FIORL:
1966                 idx = 3;
1967                 break;
1968         case I2O_LAN_10BASE2:
1969                 idx = 4;
1970                 break;
1971         case I2O_LAN_10BROAD36:
1972                 idx = 5;
1973                 break;
1974         case I2O_LAN_10BASE_T:
1975                 idx = 6;
1976                 break;
1977         case I2O_LAN_10BASE_FP:
1978                 idx = 7;
1979                 break;
1980         case I2O_LAN_10BASE_FB:
1981                 idx = 8;
1982                 break;
1983         case I2O_LAN_10BASE_FL:
1984                 idx = 9;
1985                 break;
1986         case I2O_LAN_100BASE_TX:
1987                 idx = 10;
1988                 break;
1989         case I2O_LAN_100BASE_FX:
1990                 idx = 11;
1991                 break;
1992         case I2O_LAN_100BASE_T4:
1993                 idx = 12;
1994                 break;
1995         case I2O_LAN_1000BASE_SX:
1996                 idx = 13;
1997                 break;
1998         case I2O_LAN_1000BASE_LX:
1999                 idx = 14;
2000                 break;
2001         case I2O_LAN_1000BASE_CX:
2002                 idx = 15;
2003                 break;
2004         case I2O_LAN_1000BASE_T:
2005                 idx = 16;
2006                 break;
2007         case I2O_LAN_100VG_ETHERNET:
2008                 idx = 17;
2009                 break;
2010         case I2O_LAN_100VG_TR:
2011                 idx = 18;
2012                 break;
2013         case I2O_LAN_4MBIT:
2014                 idx = 19;
2015                 break;
2016         case I2O_LAN_16MBIT:
2017                 idx = 20;
2018                 break;
2019         case I2O_LAN_125MBAUD:
2020                 idx = 21;
2021                 break;
2022         case I2O_LAN_POINT_POINT:
2023                 idx = 22;
2024                 break;
2025         case I2O_LAN_ARB_LOOP:
2026                 idx = 23;
2027                 break;
2028         case I2O_LAN_PUBLIC_LOOP:
2029                 idx = 24;
2030                 break;
2031         case I2O_LAN_FABRIC:
2032                 idx = 25;
2033                 break;
2034         case I2O_LAN_EMULATION:
2035                 idx = 26;
2036                 break;
2037         case I2O_LAN_OTHER:
2038                 idx = 27;
2039                 break;
2040         case I2O_LAN_DEFAULT:
2041                 idx = 28;
2042                 break;
2043         }
2044
2045         return i2o_connection_type[idx];
2046 }
2047
2048
2049 /* LAN group 0000h - Device info (scalar) */
2050 int i2o_proc_read_lan_dev_info(char *buf, char **start, off_t offset, int len, 
2051                                int *eof, void *data)
2052 {
2053         struct i2o_device *d = (struct i2o_device*)data;
2054         static u32 work32[56];
2055         static u8 *work8 = (u8*)work32;
2056         static u16 *work16 = (u16*)work32;
2057         static u64 *work64 = (u64*)work32;
2058         int token;
2059
2060         spin_lock(&i2o_proc_lock);
2061         len = 0;
2062
2063         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2064                                  0x0000, -1, &work32, 56*4);
2065         if (token < 0) {
2066                 len += i2o_report_query_status(buf+len, token, "0x0000 LAN Device Info");
2067                 spin_unlock(&i2o_proc_lock);
2068                 return len;
2069         }
2070
2071         len += sprintf(buf, "LAN Type            : ");
2072         switch (work16[0])
2073         {
2074         case 0x0030:
2075                 len += sprintf(buf+len, "Ethernet, ");
2076                 break;
2077         case 0x0040:
2078                 len += sprintf(buf+len, "100Base VG, ");
2079                 break;
2080         case 0x0050:
2081                 len += sprintf(buf+len, "Token Ring, ");
2082                 break;
2083         case 0x0060:
2084                 len += sprintf(buf+len, "FDDI, ");
2085                 break;
2086         case 0x0070:
2087                 len += sprintf(buf+len, "Fibre Channel, ");
2088                 break;
2089         default:
2090                 len += sprintf(buf+len, "Unknown type (0x%04x), ", work16[0]);
2091                 break;
2092         }
2093
2094         if (work16[1]&0x00000001)
2095                 len += sprintf(buf+len, "emulated LAN, ");
2096         else
2097                 len += sprintf(buf+len, "physical LAN port, ");
2098
2099         if (work16[1]&0x00000002)
2100                 len += sprintf(buf+len, "full duplex\n");
2101         else
2102                 len += sprintf(buf+len, "simplex\n");
2103
2104         len += sprintf(buf+len, "Address format      : ");
2105         switch(work8[4]) {
2106         case 0x00:
2107                 len += sprintf(buf+len, "IEEE 48bit\n");
2108                 break;
2109         case 0x01:
2110                 len += sprintf(buf+len, "FC IEEE\n");
2111                 break;
2112         default:
2113                 len += sprintf(buf+len, "Unknown (0x%02x)\n", work8[4]);
2114                 break;
2115         }
2116
2117         len += sprintf(buf+len, "State               : ");
2118         switch(work8[5])
2119         {
2120         case 0x00:
2121                 len += sprintf(buf+len, "Unknown\n");
2122                 break;
2123         case 0x01:
2124                 len += sprintf(buf+len, "Unclaimed\n");
2125                 break;
2126         case 0x02:
2127                 len += sprintf(buf+len, "Operational\n");
2128                 break;
2129         case 0x03:
2130                 len += sprintf(buf+len, "Suspended\n");
2131                 break;
2132         case 0x04:
2133                 len += sprintf(buf+len, "Resetting\n");
2134                 break;
2135         case 0x05:
2136                 len += sprintf(buf+len, "ERROR: ");
2137                 if(work16[3]&0x0001)
2138                         len += sprintf(buf+len, "TxCU inoperative ");
2139                 if(work16[3]&0x0002)
2140                         len += sprintf(buf+len, "RxCU inoperative ");
2141                 if(work16[3]&0x0004)
2142                         len += sprintf(buf+len, "Local mem alloc ");
2143                 len += sprintf(buf+len, "\n");
2144                 break;
2145         case 0x06:
2146                 len += sprintf(buf+len, "Operational no Rx\n");
2147                 break;
2148         case 0x07:
2149                 len += sprintf(buf+len, "Suspended no Rx\n");
2150                 break;
2151         default:
2152                 len += sprintf(buf+len, "Unspecified\n");
2153                 break;
2154         }
2155
2156         len += sprintf(buf+len, "Min packet size     : %d\n", work32[2]);
2157         len += sprintf(buf+len, "Max packet size     : %d\n", work32[3]);
2158         len += sprintf(buf+len, "HW address          : "
2159                        "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2160                        work8[16],work8[17],work8[18],work8[19],
2161                        work8[20],work8[21],work8[22],work8[23]);
2162
2163         len += sprintf(buf+len, "Max Tx wire speed   : %d bps\n", (int)work64[3]);
2164         len += sprintf(buf+len, "Max Rx wire speed   : %d bps\n", (int)work64[4]);
2165
2166         len += sprintf(buf+len, "Min SDU packet size : 0x%08x\n", work32[10]);
2167         len += sprintf(buf+len, "Max SDU packet size : 0x%08x\n", work32[11]);
2168
2169         spin_unlock(&i2o_proc_lock);
2170         return len;
2171 }
2172
2173 /* LAN group 0001h - MAC address table (scalar) */
2174 int i2o_proc_read_lan_mac_addr(char *buf, char **start, off_t offset, int len, 
2175                                int *eof, void *data)
2176 {
2177         struct i2o_device *d = (struct i2o_device*)data;
2178         static u32 work32[48];
2179         static u8 *work8 = (u8*)work32;
2180         int token;
2181
2182         spin_lock(&i2o_proc_lock);      
2183         len = 0;
2184
2185         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2186                                  0x0001, -1, &work32, 48*4);
2187         if (token < 0) {
2188                 len += i2o_report_query_status(buf+len, token,"0x0001 LAN MAC Address");
2189                 spin_unlock(&i2o_proc_lock);
2190                 return len;
2191         }
2192
2193         len += sprintf(buf,     "Active address          : "
2194                        "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2195                        work8[0],work8[1],work8[2],work8[3],
2196                        work8[4],work8[5],work8[6],work8[7]);
2197         len += sprintf(buf+len, "Current address         : "
2198                        "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2199                        work8[8],work8[9],work8[10],work8[11],
2200                        work8[12],work8[13],work8[14],work8[15]);
2201         len += sprintf(buf+len, "Functional address mask : "
2202                        "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2203                        work8[16],work8[17],work8[18],work8[19],
2204                        work8[20],work8[21],work8[22],work8[23]);
2205
2206         len += sprintf(buf+len,"HW/DDM capabilities : 0x%08x\n", work32[7]);
2207         len += sprintf(buf+len,"    [%s] Unicast packets supported\n",
2208                        (work32[7]&0x00000001)?"+":"-");
2209         len += sprintf(buf+len,"    [%s] Promiscuous mode supported\n",
2210                        (work32[7]&0x00000002)?"+":"-");
2211         len += sprintf(buf+len,"    [%s] Promiscuous multicast mode supported\n",
2212                        (work32[7]&0x00000004)?"+":"-");
2213         len += sprintf(buf+len,"    [%s] Broadcast reception disabling supported\n",
2214                        (work32[7]&0x00000100)?"+":"-");
2215         len += sprintf(buf+len,"    [%s] Multicast reception disabling supported\n",
2216                        (work32[7]&0x00000200)?"+":"-");
2217         len += sprintf(buf+len,"    [%s] Functional address disabling supported\n",
2218                        (work32[7]&0x00000400)?"+":"-");
2219         len += sprintf(buf+len,"    [%s] MAC reporting supported\n",
2220                        (work32[7]&0x00000800)?"+":"-");
2221
2222         len += sprintf(buf+len,"Filter mask : 0x%08x\n", work32[6]);
2223         len += sprintf(buf+len,"    [%s] Unicast packets disable\n",
2224                 (work32[6]&0x00000001)?"+":"-");
2225         len += sprintf(buf+len,"    [%s] Promiscuous mode enable\n",
2226                 (work32[6]&0x00000002)?"+":"-");
2227         len += sprintf(buf+len,"    [%s] Promiscuous multicast mode enable\n",
2228                 (work32[6]&0x00000004)?"+":"-");        
2229         len += sprintf(buf+len,"    [%s] Broadcast packets disable\n",
2230                 (work32[6]&0x00000100)?"+":"-");
2231         len += sprintf(buf+len,"    [%s] Multicast packets disable\n",
2232                 (work32[6]&0x00000200)?"+":"-");
2233         len += sprintf(buf+len,"    [%s] Functional address disable\n",
2234                        (work32[6]&0x00000400)?"+":"-");
2235                        
2236         if (work32[7]&0x00000800) {
2237                 len += sprintf(buf+len, "    MAC reporting mode : ");
2238                 if (work32[6]&0x00000800)
2239                         len += sprintf(buf+len, "Pass only priority MAC packets to user\n");
2240                 else if (work32[6]&0x00001000)
2241                         len += sprintf(buf+len, "Pass all MAC packets to user\n");
2242                 else if (work32[6]&0x00001800)
2243                         len += sprintf(buf+len, "Pass all MAC packets (promiscuous) to user\n");
2244                 else
2245                         len += sprintf(buf+len, "Do not pass MAC packets to user\n");
2246         }
2247         len += sprintf(buf+len, "Number of multicast addresses : %d\n", work32[8]);
2248         len += sprintf(buf+len, "Perfect filtering for max %d multicast addresses\n",
2249                        work32[9]);
2250         len += sprintf(buf+len, "Imperfect filtering for max %d multicast addresses\n",
2251                        work32[10]);
2252
2253         spin_unlock(&i2o_proc_lock);
2254
2255         return len;
2256 }
2257
2258 /* LAN group 0002h - Multicast MAC address table (table) */
2259 int i2o_proc_read_lan_mcast_addr(char *buf, char **start, off_t offset,
2260                                  int len, int *eof, void *data)
2261 {
2262         struct i2o_device *d = (struct i2o_device*)data;
2263         int token;
2264         int i;
2265         u8 mc_addr[8];
2266
2267         struct
2268         {
2269                 u16 result_count;
2270                 u16 pad;
2271                 u16 block_size;
2272                 u8  block_status;
2273                 u8  error_info_size;
2274                 u16 row_count;
2275                 u16 more_flag;
2276                 u8  mc_addr[256][8];
2277         } *result;      
2278
2279         result = kmalloc(sizeof(*result), GFP_KERNEL);
2280         if(!result)
2281                 return -ENOMEM;
2282
2283         spin_lock(&i2o_proc_lock);      
2284         len = 0;
2285
2286         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
2287                                 d->controller, d->lct_data.tid, 0x0002, -1, 
2288                                 NULL, 0, result, sizeof(*result));
2289
2290         if (token < 0) {
2291                 len += i2o_report_query_status(buf+len, token,"0x002 LAN Multicast MAC Address");
2292                 goto out;
2293         }
2294
2295         for (i = 0; i < result->row_count; i++)
2296         {
2297                 memcpy(mc_addr, result->mc_addr[i], 8);
2298
2299                 len += sprintf(buf+len, "MC MAC address[%d]: "
2300                                "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2301                                i, mc_addr[0], mc_addr[1], mc_addr[2],
2302                                mc_addr[3], mc_addr[4], mc_addr[5],
2303                                mc_addr[6], mc_addr[7]);
2304         }
2305 out:
2306         spin_unlock(&i2o_proc_lock);
2307         kfree(result);
2308         return len;
2309 }
2310
2311 /* LAN group 0003h - Batch Control (scalar) */
2312 int i2o_proc_read_lan_batch_control(char *buf, char **start, off_t offset,
2313                                     int len, int *eof, void *data)
2314 {
2315         struct i2o_device *d = (struct i2o_device*)data;
2316         static u32 work32[9];
2317         int token;
2318
2319         spin_lock(&i2o_proc_lock);      
2320         len = 0;
2321
2322         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2323                                  0x0003, -1, &work32, 9*4);
2324         if (token < 0) {
2325                 len += i2o_report_query_status(buf+len, token,"0x0003 LAN Batch Control");
2326                 spin_unlock(&i2o_proc_lock);
2327                 return len;
2328         }
2329
2330         len += sprintf(buf, "Batch mode ");
2331         if (work32[0]&0x00000001)
2332                 len += sprintf(buf+len, "disabled");
2333         else
2334                 len += sprintf(buf+len, "enabled");
2335         if (work32[0]&0x00000002)
2336                 len += sprintf(buf+len, " (current setting)");
2337         if (work32[0]&0x00000004)
2338                 len += sprintf(buf+len, ", forced");
2339         else
2340                 len += sprintf(buf+len, ", toggle");
2341         len += sprintf(buf+len, "\n");
2342
2343         len += sprintf(buf+len, "Max Rx batch count : %d\n", work32[5]);
2344         len += sprintf(buf+len, "Max Rx batch delay : %d\n", work32[6]);
2345         len += sprintf(buf+len, "Max Tx batch delay : %d\n", work32[7]);
2346         len += sprintf(buf+len, "Max Tx batch count : %d\n", work32[8]);
2347
2348         spin_unlock(&i2o_proc_lock);
2349         return len;
2350 }
2351
2352 /* LAN group 0004h - LAN Operation (scalar) */
2353 int i2o_proc_read_lan_operation(char *buf, char **start, off_t offset, int len,
2354                                 int *eof, void *data)
2355 {
2356         struct i2o_device *d = (struct i2o_device*)data;
2357         static u32 work32[5];
2358         int token;
2359
2360         spin_lock(&i2o_proc_lock);      
2361         len = 0;
2362
2363         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2364                                  0x0004, -1, &work32, 20);
2365         if (token < 0) {
2366                 len += i2o_report_query_status(buf+len, token,"0x0004 LAN Operation");
2367                 spin_unlock(&i2o_proc_lock);
2368                 return len;
2369         }
2370
2371         len += sprintf(buf, "Packet prepadding (32b words) : %d\n", work32[0]);
2372         len += sprintf(buf+len, "Transmission error reporting  : %s\n",
2373                        (work32[1]&1)?"on":"off");
2374         len += sprintf(buf+len, "Bad packet handling           : %s\n",
2375                                 (work32[1]&0x2)?"by host":"by DDM");
2376         len += sprintf(buf+len, "Packet orphan limit           : %d\n", work32[2]);
2377
2378         len += sprintf(buf+len, "Tx modes : 0x%08x\n", work32[3]);
2379         len += sprintf(buf+len, "    [%s] HW CRC suppression\n",
2380                         (work32[3]&0x00000004) ? "+" : "-");
2381         len += sprintf(buf+len, "    [%s] HW IPv4 checksum\n",
2382                         (work32[3]&0x00000100) ? "+" : "-");
2383         len += sprintf(buf+len, "    [%s] HW TCP checksum\n",
2384                         (work32[3]&0x00000200) ? "+" : "-");
2385         len += sprintf(buf+len, "    [%s] HW UDP checksum\n",
2386                         (work32[3]&0x00000400) ? "+" : "-");
2387         len += sprintf(buf+len, "    [%s] HW RSVP checksum\n",
2388                         (work32[3]&0x00000800) ? "+" : "-");
2389         len += sprintf(buf+len, "    [%s] HW ICMP checksum\n",
2390                         (work32[3]&0x00001000) ? "+" : "-");
2391         len += sprintf(buf+len, "    [%s] Loopback suppression enable\n",
2392                         (work32[3]&0x00002000) ? "+" : "-");
2393
2394         len += sprintf(buf+len, "Rx modes : 0x%08x\n", work32[4]);
2395         len += sprintf(buf+len, "    [%s] FCS in payload\n",
2396                         (work32[4]&0x00000004) ? "+" : "-");
2397         len += sprintf(buf+len, "    [%s] HW IPv4 checksum validation\n",
2398                         (work32[4]&0x00000100) ? "+" : "-");
2399         len += sprintf(buf+len, "    [%s] HW TCP checksum validation\n",
2400                         (work32[4]&0x00000200) ? "+" : "-");
2401         len += sprintf(buf+len, "    [%s] HW UDP checksum validation\n",
2402                         (work32[4]&0x00000400) ? "+" : "-");
2403         len += sprintf(buf+len, "    [%s] HW RSVP checksum validation\n",
2404                         (work32[4]&0x00000800) ? "+" : "-");
2405         len += sprintf(buf+len, "    [%s] HW ICMP checksum validation\n",
2406                         (work32[4]&0x00001000) ? "+" : "-");
2407  
2408         spin_unlock(&i2o_proc_lock);
2409         return len;
2410 }
2411
2412 /* LAN group 0005h - Media operation (scalar) */
2413 int i2o_proc_read_lan_media_operation(char *buf, char **start, off_t offset,
2414                                       int len, int *eof, void *data)
2415 {
2416         struct i2o_device *d = (struct i2o_device*)data;
2417         int token;
2418
2419         struct
2420         {
2421                 u32 connector_type;
2422                 u32 connection_type;
2423                 u64 current_tx_wire_speed;
2424                 u64 current_rx_wire_speed;
2425                 u8  duplex_mode;
2426                 u8  link_status;
2427                 u8  reserved;
2428                 u8  duplex_mode_target;
2429                 u32 connector_type_target;
2430                 u32 connection_type_target;
2431         } result;       
2432
2433         spin_lock(&i2o_proc_lock);      
2434         len = 0;
2435
2436         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2437                                  0x0005, -1, &result, sizeof(result));
2438         if (token < 0) {
2439                 len += i2o_report_query_status(buf+len, token, "0x0005 LAN Media Operation");
2440                 spin_unlock(&i2o_proc_lock);
2441                 return len;
2442         }
2443
2444         len += sprintf(buf, "Connector type         : %s\n",
2445                        i2o_get_connector_type(result.connector_type));
2446         len += sprintf(buf+len, "Connection type        : %s\n",
2447                        i2o_get_connection_type(result.connection_type));
2448
2449         len += sprintf(buf+len, "Current Tx wire speed  : %d bps\n", (int)result.current_tx_wire_speed);
2450         len += sprintf(buf+len, "Current Rx wire speed  : %d bps\n", (int)result.current_rx_wire_speed);
2451         len += sprintf(buf+len, "Duplex mode            : %s duplex\n",
2452                         (result.duplex_mode)?"Full":"Half");
2453                         
2454         len += sprintf(buf+len, "Link status            : ");
2455         switch (result.link_status)
2456         {
2457         case 0x00:
2458                 len += sprintf(buf+len, "Unknown\n");
2459                 break;
2460         case 0x01:
2461                 len += sprintf(buf+len, "Normal\n");
2462                 break;
2463         case 0x02:
2464                 len += sprintf(buf+len, "Failure\n");
2465                 break;
2466         case 0x03:
2467                 len += sprintf(buf+len, "Reset\n");
2468                 break;
2469         default:
2470                 len += sprintf(buf+len, "Unspecified\n");
2471         }
2472         
2473         len += sprintf(buf+len, "Duplex mode target     : ");
2474         switch (result.duplex_mode_target){
2475                 case 0:
2476                         len += sprintf(buf+len, "Half duplex\n");
2477                         break;
2478                 case 1:
2479                         len += sprintf(buf+len, "Full duplex\n");
2480                         break;
2481                 default:
2482                         len += sprintf(buf+len, "\n");
2483         }
2484
2485         len += sprintf(buf+len, "Connector type target  : %s\n",
2486                        i2o_get_connector_type(result.connector_type_target));
2487         len += sprintf(buf+len, "Connection type target : %s\n",
2488                        i2o_get_connection_type(result.connection_type_target));
2489
2490         spin_unlock(&i2o_proc_lock);
2491         return len;
2492 }
2493
2494 /* LAN group 0006h - Alternate address (table) (optional) */
2495 int i2o_proc_read_lan_alt_addr(char *buf, char **start, off_t offset, int len,
2496                                int *eof, void *data)
2497 {
2498         struct i2o_device *d = (struct i2o_device*)data;
2499         int token;
2500         int i;
2501         u8 alt_addr[8];
2502         struct
2503         {
2504                 u16 result_count;
2505                 u16 pad;
2506                 u16 block_size;
2507                 u8  block_status;
2508                 u8  error_info_size;
2509                 u16 row_count;
2510                 u16 more_flag;
2511                 u8  alt_addr[256][8];
2512         } *result;      
2513
2514         result = kmalloc(sizeof(*result), GFP_KERNEL);
2515         if(!result)
2516                 return -ENOMEM;
2517
2518         spin_lock(&i2o_proc_lock);      
2519         len = 0;
2520
2521         token = i2o_query_table(I2O_PARAMS_TABLE_GET,
2522                                 d->controller, d->lct_data.tid,
2523                                 0x0006, -1, NULL, 0, result, sizeof(*result));
2524
2525         if (token < 0) {
2526                 len += i2o_report_query_status(buf+len, token, "0x0006 LAN Alternate Address (optional)");
2527                 goto out;
2528         }
2529
2530         for (i=0; i < result->row_count; i++)
2531         {
2532                 memcpy(alt_addr,result->alt_addr[i],8);
2533                 len += sprintf(buf+len, "Alternate address[%d]: "
2534                                "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2535                                i, alt_addr[0], alt_addr[1], alt_addr[2],
2536                                alt_addr[3], alt_addr[4], alt_addr[5],
2537                                alt_addr[6], alt_addr[7]);
2538         }
2539 out:
2540         spin_unlock(&i2o_proc_lock);
2541         kfree(result);
2542         return len;
2543 }
2544
2545
2546 /* LAN group 0007h - Transmit info (scalar) */
2547 int i2o_proc_read_lan_tx_info(char *buf, char **start, off_t offset, int len, 
2548                               int *eof, void *data)
2549 {
2550         struct i2o_device *d = (struct i2o_device*)data;
2551         static u32 work32[8];
2552         int token;
2553
2554         spin_lock(&i2o_proc_lock);      
2555         len = 0;
2556
2557         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2558                                  0x0007, -1, &work32, 8*4);
2559         if (token < 0) {
2560                 len += i2o_report_query_status(buf+len, token,"0x0007 LAN Transmit Info");
2561                 spin_unlock(&i2o_proc_lock);
2562                 return len;
2563         }
2564
2565         len += sprintf(buf,     "Tx Max SG elements per packet : %d\n", work32[0]);
2566         len += sprintf(buf+len, "Tx Max SG elements per chain  : %d\n", work32[1]);
2567         len += sprintf(buf+len, "Tx Max outstanding packets    : %d\n", work32[2]);
2568         len += sprintf(buf+len, "Tx Max packets per request    : %d\n", work32[3]);
2569
2570         len += sprintf(buf+len, "Tx modes : 0x%08x\n", work32[4]);
2571         len += sprintf(buf+len, "    [%s] No DA in SGL\n",
2572                                 (work32[4]&0x00000002) ? "+" : "-");
2573         len += sprintf(buf+len, "    [%s] CRC suppression\n",
2574                                 (work32[4]&0x00000004) ? "+" : "-");
2575         len += sprintf(buf+len, "    [%s] MAC insertion\n",
2576                                 (work32[4]&0x00000010) ? "+" : "-");
2577         len += sprintf(buf+len, "    [%s] RIF insertion\n",
2578                                 (work32[4]&0x00000020) ? "+" : "-");
2579         len += sprintf(buf+len, "    [%s] IPv4 checksum generation\n",
2580                                 (work32[4]&0x00000100) ? "+" : "-");
2581         len += sprintf(buf+len, "    [%s] TCP checksum generation\n",
2582                                 (work32[4]&0x00000200) ? "+" : "-");
2583         len += sprintf(buf+len, "    [%s] UDP checksum generation\n",
2584                                 (work32[4]&0x00000400) ? "+" : "-");
2585         len += sprintf(buf+len, "    [%s] RSVP checksum generation\n",
2586                                 (work32[4]&0x00000800) ? "+" : "-");
2587         len += sprintf(buf+len, "    [%s] ICMP checksum generation\n",
2588                                 (work32[4]&0x00001000) ? "+" : "-");
2589         len += sprintf(buf+len, "    [%s] Loopback enabled\n",
2590                                 (work32[4]&0x00010000) ? "+" : "-");
2591         len += sprintf(buf+len, "    [%s] Loopback suppression enabled\n",
2592                                 (work32[4]&0x00020000) ? "+" : "-");
2593
2594         spin_unlock(&i2o_proc_lock);
2595         return len;
2596 }
2597
2598 /* LAN group 0008h - Receive info (scalar) */
2599 int i2o_proc_read_lan_rx_info(char *buf, char **start, off_t offset, int len, 
2600                               int *eof, void *data)
2601 {
2602         struct i2o_device *d = (struct i2o_device*)data;
2603         static u32 work32[8];
2604         int token;
2605
2606         spin_lock(&i2o_proc_lock);      
2607         len = 0;
2608
2609         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2610                                  0x0008, -1, &work32, 8*4);
2611         if (token < 0) {
2612                 len += i2o_report_query_status(buf+len, token,"0x0008 LAN Receive Info");
2613                 spin_unlock(&i2o_proc_lock);
2614                 return len;
2615         }
2616
2617         len += sprintf(buf     ,"Rx Max size of chain element : %d\n", work32[0]);
2618         len += sprintf(buf+len, "Rx Max Buckets               : %d\n", work32[1]);
2619         len += sprintf(buf+len, "Rx Max Buckets in Reply      : %d\n", work32[3]);
2620         len += sprintf(buf+len, "Rx Max Packets in Bucket     : %d\n", work32[4]);
2621         len += sprintf(buf+len, "Rx Max Buckets in Post       : %d\n", work32[5]);
2622
2623         len += sprintf(buf+len, "Rx Modes : 0x%08x\n", work32[2]);
2624         len += sprintf(buf+len, "    [%s] FCS reception\n",
2625                                 (work32[2]&0x00000004) ? "+" : "-");
2626         len += sprintf(buf+len, "    [%s] IPv4 checksum validation \n",
2627                                 (work32[2]&0x00000100) ? "+" : "-");
2628         len += sprintf(buf+len, "    [%s] TCP checksum validation \n",
2629                                 (work32[2]&0x00000200) ? "+" : "-");
2630         len += sprintf(buf+len, "    [%s] UDP checksum validation \n",
2631                                 (work32[2]&0x00000400) ? "+" : "-");
2632         len += sprintf(buf+len, "    [%s] RSVP checksum validation \n",
2633                                 (work32[2]&0x00000800) ? "+" : "-");
2634         len += sprintf(buf+len, "    [%s] ICMP checksum validation \n",
2635                                 (work32[2]&0x00001000) ? "+" : "-");
2636
2637         spin_unlock(&i2o_proc_lock);
2638         return len;
2639 }
2640
2641 static int i2o_report_opt_field(char *buf, char *field_name,
2642                                 int field_nbr, int supp_fields, u64 *value)
2643 {
2644         if (supp_fields & (1 << field_nbr))
2645                 return sprintf(buf, "%-24s : " FMT_U64_HEX "\n", field_name, U64_VAL(value));
2646         else    
2647                 return sprintf(buf, "%-24s : Not supported\n", field_name);     
2648 }
2649
2650 /* LAN group 0100h - LAN Historical statistics (scalar) */
2651 /* LAN group 0180h - Supported Optional Historical Statistics (scalar) */
2652 /* LAN group 0182h - Optional Non Media Specific Transmit Historical Statistics (scalar) */
2653 /* LAN group 0183h - Optional Non Media Specific Receive Historical Statistics (scalar) */
2654
2655 int i2o_proc_read_lan_hist_stats(char *buf, char **start, off_t offset, int len,
2656                                  int *eof, void *data)
2657 {
2658         struct i2o_device *d = (struct i2o_device*)data;
2659         int token;
2660
2661         struct
2662         {
2663                 u64 tx_packets;
2664                 u64 tx_bytes;
2665                 u64 rx_packets;
2666                 u64 rx_bytes;
2667                 u64 tx_errors;
2668                 u64 rx_errors;
2669                 u64 rx_dropped;
2670                 u64 adapter_resets;
2671                 u64 adapter_suspends;
2672         } stats;                        // 0x0100
2673
2674         static u64 supp_groups[4];      // 0x0180
2675
2676         struct
2677         {
2678                 u64 tx_retries;
2679                 u64 tx_directed_bytes;
2680                 u64 tx_directed_packets;
2681                 u64 tx_multicast_bytes;
2682                 u64 tx_multicast_packets;
2683                 u64 tx_broadcast_bytes;
2684                 u64 tx_broadcast_packets;
2685                 u64 tx_group_addr_packets;
2686                 u64 tx_short_packets;
2687         } tx_stats;                     // 0x0182
2688
2689         struct
2690         {
2691                 u64 rx_crc_errors;
2692                 u64 rx_directed_bytes;
2693                 u64 rx_directed_packets;
2694                 u64 rx_multicast_bytes;
2695                 u64 rx_multicast_packets;
2696                 u64 rx_broadcast_bytes;
2697                 u64 rx_broadcast_packets;
2698                 u64 rx_group_addr_packets;
2699                 u64 rx_short_packets;
2700                 u64 rx_long_packets;
2701                 u64 rx_runt_packets;
2702         } rx_stats;                     // 0x0183
2703
2704         struct
2705         {
2706                 u64 ipv4_generate;
2707                 u64 ipv4_validate_success;
2708                 u64 ipv4_validate_errors;
2709                 u64 tcp_generate;
2710                 u64 tcp_validate_success;
2711                 u64 tcp_validate_errors;
2712                 u64 udp_generate;
2713                 u64 udp_validate_success;
2714                 u64 udp_validate_errors;
2715                 u64 rsvp_generate;
2716                 u64 rsvp_validate_success;
2717                 u64 rsvp_validate_errors;               
2718                 u64 icmp_generate;
2719                 u64 icmp_validate_success;
2720                 u64 icmp_validate_errors;
2721         } chksum_stats;                 // 0x0184
2722
2723         spin_lock(&i2o_proc_lock);      
2724         len = 0;
2725
2726         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2727                                  0x0100, -1, &stats, sizeof(stats));
2728         if (token < 0) {
2729                 len += i2o_report_query_status(buf+len, token,"0x100 LAN Statistics");
2730                 spin_unlock(&i2o_proc_lock);
2731                 return len;
2732         }
2733
2734         len += sprintf(buf+len, "Tx packets       : " FMT_U64_HEX "\n",
2735                        U64_VAL(&stats.tx_packets));
2736         len += sprintf(buf+len, "Tx bytes         : " FMT_U64_HEX "\n",
2737                        U64_VAL(&stats.tx_bytes));
2738         len += sprintf(buf+len, "Rx packets       : " FMT_U64_HEX "\n",
2739                        U64_VAL(&stats.rx_packets));
2740         len += sprintf(buf+len, "Rx bytes         : " FMT_U64_HEX "\n",
2741                        U64_VAL(&stats.rx_bytes));
2742         len += sprintf(buf+len, "Tx errors        : " FMT_U64_HEX "\n",
2743                        U64_VAL(&stats.tx_errors));
2744         len += sprintf(buf+len, "Rx errors        : " FMT_U64_HEX "\n",
2745                        U64_VAL(&stats.rx_errors));
2746         len += sprintf(buf+len, "Rx dropped       : " FMT_U64_HEX "\n",
2747                        U64_VAL(&stats.rx_dropped));
2748         len += sprintf(buf+len, "Adapter resets   : " FMT_U64_HEX "\n",
2749                        U64_VAL(&stats.adapter_resets));
2750         len += sprintf(buf+len, "Adapter suspends : " FMT_U64_HEX "\n",
2751                        U64_VAL(&stats.adapter_suspends));
2752
2753         /* Optional statistics follows */
2754         /* Get 0x0180 to see which optional groups/fields are supported */
2755
2756         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2757                                  0x0180, -1, &supp_groups, sizeof(supp_groups));
2758         
2759         if (token < 0) {
2760                 len += i2o_report_query_status(buf+len, token, "0x180 LAN Supported Optional Statistics");
2761                 spin_unlock(&i2o_proc_lock);
2762                 return len;
2763         }
2764
2765         if (supp_groups[1]) /* 0x0182 */
2766         {
2767                 token = i2o_query_scalar(d->controller, d->lct_data.tid,
2768                                         0x0182, -1, &tx_stats, sizeof(tx_stats));
2769
2770                 if (token < 0) {
2771                         len += i2o_report_query_status(buf+len, token,"0x182 LAN Optional Tx Historical Statistics");
2772                         spin_unlock(&i2o_proc_lock);
2773                         return len;
2774                 }
2775
2776                 len += sprintf(buf+len, "==== Optional TX statistics (group 0182h)\n");
2777
2778                 len += i2o_report_opt_field(buf+len, "Tx RetryCount",
2779                                         0, supp_groups[1], &tx_stats.tx_retries);
2780                 len += i2o_report_opt_field(buf+len, "Tx DirectedBytes",
2781                                         1, supp_groups[1], &tx_stats.tx_directed_bytes);
2782                 len += i2o_report_opt_field(buf+len, "Tx DirectedPackets",
2783                                         2, supp_groups[1], &tx_stats.tx_directed_packets);
2784                 len += i2o_report_opt_field(buf+len, "Tx MulticastBytes",
2785                                         3, supp_groups[1], &tx_stats.tx_multicast_bytes);
2786                 len += i2o_report_opt_field(buf+len, "Tx MulticastPackets",
2787                                         4, supp_groups[1], &tx_stats.tx_multicast_packets);
2788                 len += i2o_report_opt_field(buf+len, "Tx BroadcastBytes",
2789                                         5, supp_groups[1], &tx_stats.tx_broadcast_bytes);
2790                 len += i2o_report_opt_field(buf+len, "Tx BroadcastPackets",
2791                                         6, supp_groups[1], &tx_stats.tx_broadcast_packets);
2792                 len += i2o_report_opt_field(buf+len, "Tx TotalGroupAddrPackets",
2793                                         7, supp_groups[1], &tx_stats.tx_group_addr_packets);
2794                 len += i2o_report_opt_field(buf+len, "Tx TotalPacketsTooShort",
2795                                         8, supp_groups[1], &tx_stats.tx_short_packets);
2796         }
2797
2798         if (supp_groups[2]) /* 0x0183 */
2799         {
2800                 token = i2o_query_scalar(d->controller, d->lct_data.tid,
2801                                          0x0183, -1, &rx_stats, sizeof(rx_stats));
2802                 if (token < 0) {
2803                         len += i2o_report_query_status(buf+len, token,"0x183 LAN Optional Rx Historical Stats");
2804                         spin_unlock(&i2o_proc_lock);
2805                         return len;
2806                 }
2807
2808                 len += sprintf(buf+len, "==== Optional RX statistics (group 0183h)\n");
2809
2810                 len += i2o_report_opt_field(buf+len, "Rx CRCErrorCount",
2811                                         0, supp_groups[2], &rx_stats.rx_crc_errors);
2812                 len += i2o_report_opt_field(buf+len, "Rx DirectedBytes",
2813                                         1, supp_groups[2], &rx_stats.rx_directed_bytes);
2814                 len += i2o_report_opt_field(buf+len, "Rx DirectedPackets",
2815                                         2, supp_groups[2], &rx_stats.rx_directed_packets);
2816                 len += i2o_report_opt_field(buf+len, "Rx MulticastBytes",
2817                                         3, supp_groups[2], &rx_stats.rx_multicast_bytes);
2818                 len += i2o_report_opt_field(buf+len, "Rx MulticastPackets",
2819                                         4, supp_groups[2], &rx_stats.rx_multicast_packets);
2820                 len += i2o_report_opt_field(buf+len, "Rx BroadcastBytes",
2821                                         5, supp_groups[2], &rx_stats.rx_broadcast_bytes);
2822                 len += i2o_report_opt_field(buf+len, "Rx BroadcastPackets",
2823                                         6, supp_groups[2], &rx_stats.rx_broadcast_packets);
2824                 len += i2o_report_opt_field(buf+len, "Rx TotalGroupAddrPackets",
2825                                         7, supp_groups[2], &rx_stats.rx_group_addr_packets);
2826                 len += i2o_report_opt_field(buf+len, "Rx TotalPacketsTooShort",
2827                                         8, supp_groups[2], &rx_stats.rx_short_packets);
2828                 len += i2o_report_opt_field(buf+len, "Rx TotalPacketsTooLong",
2829                                         9, supp_groups[2], &rx_stats.rx_long_packets);
2830                 len += i2o_report_opt_field(buf+len, "Rx TotalPacketsRunt",
2831                                         10, supp_groups[2], &rx_stats.rx_runt_packets);
2832         }
2833         
2834         if (supp_groups[3]) /* 0x0184 */
2835         {
2836                 token = i2o_query_scalar(d->controller, d->lct_data.tid,
2837                                         0x0184, -1, &chksum_stats, sizeof(chksum_stats));
2838
2839                 if (token < 0) {
2840                         len += i2o_report_query_status(buf+len, token,"0x184 LAN Optional Chksum Historical Stats");
2841                         spin_unlock(&i2o_proc_lock);
2842                         return len;
2843                 }
2844
2845                 len += sprintf(buf+len, "==== Optional CHKSUM statistics (group 0x0184)\n");
2846
2847                 len += i2o_report_opt_field(buf+len, "IPv4 Generate",
2848                                         0, supp_groups[3], &chksum_stats.ipv4_generate);
2849                 len += i2o_report_opt_field(buf+len, "IPv4 ValidateSuccess",
2850                                         1, supp_groups[3], &chksum_stats.ipv4_validate_success);
2851                 len += i2o_report_opt_field(buf+len, "IPv4 ValidateError",
2852                                         2, supp_groups[3], &chksum_stats.ipv4_validate_errors);
2853                 len += i2o_report_opt_field(buf+len, "TCP  Generate",
2854                                         3, supp_groups[3], &chksum_stats.tcp_generate);
2855                 len += i2o_report_opt_field(buf+len, "TCP  ValidateSuccess",
2856                                         4, supp_groups[3], &chksum_stats.tcp_validate_success);
2857                 len += i2o_report_opt_field(buf+len, "TCP  ValidateError",
2858                                         5, supp_groups[3], &chksum_stats.tcp_validate_errors);
2859                 len += i2o_report_opt_field(buf+len, "UDP  Generate",
2860                                         6, supp_groups[3], &chksum_stats.udp_generate);
2861                 len += i2o_report_opt_field(buf+len, "UDP  ValidateSuccess",
2862                                         7, supp_groups[3], &chksum_stats.udp_validate_success);
2863                 len += i2o_report_opt_field(buf+len, "UDP  ValidateError",
2864                                         8, supp_groups[3], &chksum_stats.udp_validate_errors);
2865                 len += i2o_report_opt_field(buf+len, "RSVP Generate",
2866                                         9, supp_groups[3], &chksum_stats.rsvp_generate);
2867                 len += i2o_report_opt_field(buf+len, "RSVP ValidateSuccess",
2868                                         10, supp_groups[3], &chksum_stats.rsvp_validate_success);
2869                 len += i2o_report_opt_field(buf+len, "RSVP ValidateError",
2870                                         11, supp_groups[3], &chksum_stats.rsvp_validate_errors);
2871                 len += i2o_report_opt_field(buf+len, "ICMP Generate",
2872                                         12, supp_groups[3], &chksum_stats.icmp_generate);
2873                 len += i2o_report_opt_field(buf+len, "ICMP ValidateSuccess",
2874                                         13, supp_groups[3], &chksum_stats.icmp_validate_success);
2875                 len += i2o_report_opt_field(buf+len, "ICMP ValidateError",
2876                                         14, supp_groups[3], &chksum_stats.icmp_validate_errors);
2877         }
2878
2879         spin_unlock(&i2o_proc_lock);
2880         return len;
2881 }
2882
2883 /* LAN group 0200h - Required Ethernet Statistics (scalar) */
2884 /* LAN group 0280h - Optional Ethernet Statistics Supported (scalar) */
2885 /* LAN group 0281h - Optional Ethernet Historical Statistics (scalar) */
2886 int i2o_proc_read_lan_eth_stats(char *buf, char **start, off_t offset,
2887                                 int len, int *eof, void *data)
2888 {
2889         struct i2o_device *d = (struct i2o_device*)data;
2890         int token;
2891
2892         struct
2893         {
2894                 u64 rx_align_errors;
2895                 u64 tx_one_collisions;
2896                 u64 tx_multiple_collisions;
2897                 u64 tx_deferred;
2898                 u64 tx_late_collisions;
2899                 u64 tx_max_collisions;
2900                 u64 tx_carrier_lost;
2901                 u64 tx_excessive_deferrals;
2902         } stats;        
2903
2904         static u64 supp_fields;
2905         struct
2906         {
2907                 u64 rx_overrun;
2908                 u64 tx_underrun;
2909                 u64 tx_heartbeat_failure;       
2910         } hist_stats;
2911
2912         spin_lock(&i2o_proc_lock);      
2913         len = 0;
2914
2915         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2916                                  0x0200, -1, &stats, sizeof(stats));
2917
2918         if (token < 0) {
2919                 len += i2o_report_query_status(buf+len, token,"0x0200 LAN Ethernet Statistics");
2920                 spin_unlock(&i2o_proc_lock);
2921                 return len;
2922         }
2923
2924         len += sprintf(buf+len, "Rx alignment errors    : " FMT_U64_HEX "\n",
2925                        U64_VAL(&stats.rx_align_errors));
2926         len += sprintf(buf+len, "Tx one collisions      : " FMT_U64_HEX "\n",
2927                        U64_VAL(&stats.tx_one_collisions));
2928         len += sprintf(buf+len, "Tx multicollisions     : " FMT_U64_HEX "\n",
2929                        U64_VAL(&stats.tx_multiple_collisions));
2930         len += sprintf(buf+len, "Tx deferred            : " FMT_U64_HEX "\n",
2931                        U64_VAL(&stats.tx_deferred));
2932         len += sprintf(buf+len, "Tx late collisions     : " FMT_U64_HEX "\n",
2933                        U64_VAL(&stats.tx_late_collisions));
2934         len += sprintf(buf+len, "Tx max collisions      : " FMT_U64_HEX "\n",
2935                        U64_VAL(&stats.tx_max_collisions));
2936         len += sprintf(buf+len, "Tx carrier lost        : " FMT_U64_HEX "\n",
2937                        U64_VAL(&stats.tx_carrier_lost));
2938         len += sprintf(buf+len, "Tx excessive deferrals : " FMT_U64_HEX "\n",
2939                        U64_VAL(&stats.tx_excessive_deferrals));
2940
2941         /* Optional Ethernet statistics follows  */
2942         /* Get 0x0280 to see which optional fields are supported */
2943
2944         token = i2o_query_scalar(d->controller, d->lct_data.tid,
2945                                  0x0280, -1, &supp_fields, sizeof(supp_fields));
2946
2947         if (token < 0) {
2948                 len += i2o_report_query_status(buf+len, token,"0x0280 LAN Supported Optional Ethernet Statistics");
2949                 spin_unlock(&i2o_proc_lock);
2950                 return len;
2951         }
2952
2953         if (supp_fields) /* 0x0281 */
2954         {
2955                 token = i2o_query_scalar(d->controller, d->lct_data.tid,
2956                                          0x0281, -1, &stats, sizeof(stats));
2957
2958                 if (token < 0) {
2959                         len += i2o_report_query_status(buf+len, token,"0x0281 LAN Optional Ethernet Statistics");
2960                         spin_unlock(&i2o_proc_lock);
2961                         return len;
2962                 }
2963
2964                 len += sprintf(buf+len, "==== Optional ETHERNET statistics (group 0x0281)\n");
2965
2966                 len += i2o_report_opt_field(buf+len, "Rx Overrun",
2967                                         0, supp_fields, &hist_stats.rx_overrun);
2968                 len += i2o_report_opt_field(buf+len, "Tx Underrun",
2969                                         1, supp_fields, &hist_stats.tx_underrun);
2970                 len += i2o_report_opt_field(buf+len, "Tx HeartbeatFailure",
2971                                         2, supp_fields, &hist_stats.tx_heartbeat_failure);
2972         }
2973
2974         spin_unlock(&i2o_proc_lock);
2975         return len;
2976 }
2977
2978 /* LAN group 0300h - Required Token Ring Statistics (scalar) */
2979 /* LAN group 0380h, 0381h - Optional Statistics not yet defined (TODO) */
2980 int i2o_proc_read_lan_tr_stats(char *buf, char **start, off_t offset,
2981                                int len, int *eof, void *data)
2982 {
2983         struct i2o_device *d = (struct i2o_device*)data;
2984         static u64 work64[13];
2985         int token;
2986
2987         static char *ring_status[] =
2988         {
2989                 "",
2990                 "",
2991                 "",
2992                 "",
2993                 "",
2994                 "Ring Recovery",
2995                 "Single Station",
2996                 "Counter Overflow",
2997                 "Remove Received",
2998                 "",
2999                 "Auto-Removal Error 1",
3000                 "Lobe Wire Fault",
3001                 "Transmit Beacon",
3002                 "Soft Error",
3003                 "Hard Error",
3004                 "Signal Loss"
3005         };
3006
3007         spin_lock(&i2o_proc_lock);      
3008         len = 0;
3009
3010         token = i2o_query_scalar(d->controller, d->lct_data.tid,
3011                                  0x0300, -1, &work64, sizeof(work64));
3012
3013         if (token < 0) {
3014                 len += i2o_report_query_status(buf+len, token,"0x0300 Token Ring Statistics");
3015                 spin_unlock(&i2o_proc_lock);
3016                 return len;
3017         }
3018
3019         len += sprintf(buf,     "LineErrors          : " FMT_U64_HEX "\n",
3020                        U64_VAL(&work64[0]));
3021         len += sprintf(buf+len, "LostFrames          : " FMT_U64_HEX "\n",
3022                        U64_VAL(&work64[1]));
3023         len += sprintf(buf+len, "ACError             : " FMT_U64_HEX "\n",
3024                        U64_VAL(&work64[2]));
3025         len += sprintf(buf+len, "TxAbortDelimiter    : " FMT_U64_HEX "\n",
3026                        U64_VAL(&work64[3]));
3027         len += sprintf(buf+len, "BursErrors          : " FMT_U64_HEX "\n",
3028                        U64_VAL(&work64[4]));
3029         len += sprintf(buf+len, "FrameCopiedErrors   : " FMT_U64_HEX "\n",
3030                        U64_VAL(&work64[5]));
3031         len += sprintf(buf+len, "FrequencyErrors     : " FMT_U64_HEX "\n",
3032                        U64_VAL(&work64[6]));
3033         len += sprintf(buf+len, "InternalErrors      : " FMT_U64_HEX "\n",
3034                        U64_VAL(&work64[7]));
3035         len += sprintf(buf+len, "LastRingStatus      : %s\n", ring_status[work64[8]]);
3036         len += sprintf(buf+len, "TokenError          : " FMT_U64_HEX "\n",
3037                        U64_VAL(&work64[9]));
3038         len += sprintf(buf+len, "UpstreamNodeAddress : " FMT_U64_HEX "\n",
3039                        U64_VAL(&work64[10]));
3040         len += sprintf(buf+len, "LastRingID          : " FMT_U64_HEX "\n",
3041                        U64_VAL(&work64[11]));
3042         len += sprintf(buf+len, "LastBeaconType      : " FMT_U64_HEX "\n",
3043                        U64_VAL(&work64[12]));
3044
3045         spin_unlock(&i2o_proc_lock);
3046         return len;
3047 }
3048
3049 /* LAN group 0400h - Required FDDI Statistics (scalar) */
3050 /* LAN group 0480h, 0481h - Optional Statistics, not yet defined (TODO) */
3051 int i2o_proc_read_lan_fddi_stats(char *buf, char **start, off_t offset,
3052                                  int len, int *eof, void *data)
3053 {
3054         struct i2o_device *d = (struct i2o_device*)data;
3055         static u64 work64[11];
3056         int token;
3057
3058         static char *conf_state[] =
3059         {
3060                 "Isolated",
3061                 "Local a",
3062                 "Local b",
3063                 "Local ab",
3064                 "Local s",
3065                 "Wrap a",
3066                 "Wrap b",
3067                 "Wrap ab",
3068                 "Wrap s",
3069                 "C-Wrap a",
3070                 "C-Wrap b",
3071                 "C-Wrap s",
3072                 "Through",
3073         };
3074
3075         static char *ring_state[] =
3076         {
3077                 "Isolated",
3078                 "Non-op",
3079                 "Rind-op",
3080                 "Detect",
3081                 "Non-op-Dup",
3082                 "Ring-op-Dup",
3083                 "Directed",
3084                 "Trace"
3085         };
3086
3087         static char *link_state[] =
3088         {
3089                 "Off",
3090                 "Break",
3091                 "Trace",
3092                 "Connect",
3093                 "Next",
3094                 "Signal",
3095                 "Join",
3096                 "Verify",
3097                 "Active",
3098                 "Maintenance"
3099         };
3100
3101         spin_lock(&i2o_proc_lock);
3102         len = 0;
3103
3104         token = i2o_query_scalar(d->controller, d->lct_data.tid,
3105                                  0x0400, -1, &work64, sizeof(work64));
3106
3107         if (token < 0) {
3108                 len += i2o_report_query_status(buf+len, token,"0x0400 FDDI Required Statistics");
3109                 spin_unlock(&i2o_proc_lock);
3110                 return len;
3111         }
3112
3113         len += sprintf(buf+len, "ConfigurationState : %s\n", conf_state[work64[0]]);
3114         len += sprintf(buf+len, "UpstreamNode       : " FMT_U64_HEX "\n",
3115                        U64_VAL(&work64[1]));
3116         len += sprintf(buf+len, "DownStreamNode     : " FMT_U64_HEX "\n",
3117                        U64_VAL(&work64[2]));
3118         len += sprintf(buf+len, "FrameErrors        : " FMT_U64_HEX "\n",
3119                        U64_VAL(&work64[3]));
3120         len += sprintf(buf+len, "FramesLost         : " FMT_U64_HEX "\n",
3121                        U64_VAL(&work64[4]));
3122         len += sprintf(buf+len, "RingMgmtState      : %s\n", ring_state[work64[5]]);
3123         len += sprintf(buf+len, "LCTFailures        : " FMT_U64_HEX "\n",
3124                        U64_VAL(&work64[6]));
3125         len += sprintf(buf+len, "LEMRejects         : " FMT_U64_HEX "\n",
3126                        U64_VAL(&work64[7]));
3127         len += sprintf(buf+len, "LEMCount           : " FMT_U64_HEX "\n",
3128                        U64_VAL(&work64[8]));
3129         len += sprintf(buf+len, "LConnectionState   : %s\n",
3130                        link_state[work64[9]]);
3131
3132         spin_unlock(&i2o_proc_lock);
3133         return len;
3134 }
3135
3136 static int i2o_proc_create_entries(void *data, i2o_proc_entry *pentry,
3137                                    struct proc_dir_entry *parent)
3138 {
3139         struct proc_dir_entry *ent;
3140         
3141         while(pentry->name != NULL)
3142         {
3143                 ent = create_proc_entry(pentry->name, pentry->mode, parent);
3144                 if(!ent) return -1;
3145
3146                 ent->data = data;
3147                 ent->read_proc = pentry->read_proc;
3148                 ent->write_proc = pentry->write_proc;
3149                 ent->nlink = 1;
3150
3151                 pentry++;
3152         }
3153
3154         return 0;
3155 }
3156
3157 static void i2o_proc_remove_entries(i2o_proc_entry *pentry, 
3158                                     struct proc_dir_entry *parent)
3159 {
3160         while(pentry->name != NULL)
3161         {
3162                 remove_proc_entry(pentry->name, parent);
3163                 pentry++;
3164         }
3165 }
3166
3167 static int i2o_proc_add_controller(struct i2o_controller *pctrl, 
3168                                    struct proc_dir_entry *root )
3169 {
3170         struct proc_dir_entry *dir, *dir1;
3171         struct i2o_device *dev;
3172         char buff[10];
3173
3174         sprintf(buff, "iop%d", pctrl->unit);
3175
3176         dir = proc_mkdir(buff, root);
3177         if(!dir)
3178                 return -1;
3179
3180         pctrl->proc_entry = dir;
3181
3182         i2o_proc_create_entries(pctrl, generic_iop_entries, dir);
3183         
3184         for(dev = pctrl->devices; dev; dev = dev->next)
3185         {
3186                 sprintf(buff, "%0#5x", dev->lct_data.tid);
3187
3188                 dir1 = proc_mkdir(buff, dir);
3189                 dev->proc_entry = dir1;
3190
3191                 if(!dir1)
3192                         printk(KERN_INFO "i2o_proc: Could not allocate proc dir\n");
3193
3194                 i2o_proc_add_device(dev, dir1);
3195         }
3196
3197         return 0;
3198 }
3199
3200 void i2o_proc_new_dev(struct i2o_controller *c, struct i2o_device *d)
3201 {
3202         char buff[10];
3203
3204 #ifdef DRIVERDEBUG
3205         printk(KERN_INFO "Adding new device to /proc/i2o/iop%d\n", c->unit);
3206 #endif
3207         sprintf(buff, "%0#5x", d->lct_data.tid);
3208
3209         d->proc_entry = proc_mkdir(buff, c->proc_entry);
3210
3211         if(!d->proc_entry)
3212         {
3213                 printk(KERN_WARNING "i2o: Could not allocate procdir!\n");
3214                 return;
3215         }
3216
3217         i2o_proc_add_device(d, d->proc_entry);
3218 }
3219
3220 void i2o_proc_add_device(struct i2o_device *dev, struct proc_dir_entry *dir)
3221 {       
3222         i2o_proc_create_entries(dev, generic_dev_entries, dir);
3223
3224         /* Inform core that we want updates about this device's status */
3225         i2o_device_notify_on(dev, &i2o_proc_handler);
3226         switch(dev->lct_data.class_id)
3227         {
3228                 case I2O_CLASS_SCSI_PERIPHERAL:
3229                 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
3230                         i2o_proc_create_entries(dev, rbs_dev_entries, dir);
3231                         break;
3232                 case I2O_CLASS_LAN:
3233                         i2o_proc_create_entries(dev, lan_entries, dir);
3234                         switch(dev->lct_data.sub_class)
3235                         {
3236                                 case I2O_LAN_ETHERNET:
3237                                         i2o_proc_create_entries(dev, lan_eth_entries, dir);
3238                                         break;
3239                                 case I2O_LAN_FDDI:
3240                                         i2o_proc_create_entries(dev, lan_fddi_entries, dir);
3241                                         break;
3242                                 case I2O_LAN_TR:
3243                                         i2o_proc_create_entries(dev, lan_tr_entries, dir);
3244                                         break;
3245                                 default:
3246                                         break;
3247                         }
3248                         break;
3249                 default:
3250                         break;
3251         }
3252 }
3253
3254 static void i2o_proc_remove_controller(struct i2o_controller *pctrl, 
3255                                        struct proc_dir_entry *parent)
3256 {
3257         char buff[10];
3258         struct i2o_device *dev;
3259
3260         /* Remove unused device entries */
3261         for(dev=pctrl->devices; dev; dev=dev->next)
3262                 i2o_proc_remove_device(dev);
3263
3264         if(!atomic_read(&pctrl->proc_entry->count))
3265         {
3266                 sprintf(buff, "iop%d", pctrl->unit);
3267
3268                 i2o_proc_remove_entries(generic_iop_entries, pctrl->proc_entry);
3269
3270                 remove_proc_entry(buff, parent);
3271                 pctrl->proc_entry = NULL;
3272         }
3273 }
3274
3275 void i2o_proc_remove_device(struct i2o_device *dev)
3276 {
3277         struct proc_dir_entry *de=dev->proc_entry;
3278         char dev_id[10];
3279
3280         sprintf(dev_id, "%0#5x", dev->lct_data.tid);
3281
3282         i2o_device_notify_off(dev, &i2o_proc_handler);
3283         /* Would it be safe to remove _files_ even if they are in use? */
3284         if((de) && (!atomic_read(&de->count)))
3285         {
3286                 i2o_proc_remove_entries(generic_dev_entries, de);
3287                 switch(dev->lct_data.class_id)
3288                 {
3289                         case I2O_CLASS_SCSI_PERIPHERAL:
3290                         case I2O_CLASS_RANDOM_BLOCK_STORAGE:
3291                                 i2o_proc_remove_entries(rbs_dev_entries, de);
3292                                 break;
3293                         case I2O_CLASS_LAN:
3294                         {
3295                                 i2o_proc_remove_entries(lan_entries, de);
3296                                 switch(dev->lct_data.sub_class)
3297                                 {
3298                                 case I2O_LAN_ETHERNET:
3299                                         i2o_proc_remove_entries(lan_eth_entries, de);
3300                                         break;
3301                                 case I2O_LAN_FDDI:
3302                                         i2o_proc_remove_entries(lan_fddi_entries, de);
3303                                         break;
3304                                 case I2O_LAN_TR:
3305                                         i2o_proc_remove_entries(lan_tr_entries, de);
3306                                         break;
3307                                 }
3308                         }
3309                         remove_proc_entry(dev_id, dev->controller->proc_entry);
3310                 }
3311         }
3312 }
3313         
3314 void i2o_proc_dev_del(struct i2o_controller *c, struct i2o_device *d)
3315 {
3316 #ifdef DRIVERDEBUG
3317         printk(KERN_INFO "Deleting device %d from iop%d\n", 
3318                 d->lct_data.tid, c->unit);
3319 #endif
3320
3321         i2o_proc_remove_device(d);
3322 }
3323
3324 static int create_i2o_procfs(void)
3325 {
3326         struct i2o_controller *pctrl = NULL;
3327         int i;
3328
3329         i2o_proc_dir_root = proc_mkdir("i2o", 0);
3330         if(!i2o_proc_dir_root)
3331                 return -1;
3332
3333         for(i = 0; i < MAX_I2O_CONTROLLERS; i++)
3334         {
3335                 pctrl = i2o_find_controller(i);
3336                 if(pctrl)
3337                 {
3338                         i2o_proc_add_controller(pctrl, i2o_proc_dir_root);
3339                         i2o_unlock_controller(pctrl);
3340                 }
3341         };
3342
3343         return 0;
3344 }
3345
3346 static int __exit destroy_i2o_procfs(void)
3347 {
3348         struct i2o_controller *pctrl = NULL;
3349         int i;
3350
3351         for(i = 0; i < MAX_I2O_CONTROLLERS; i++)
3352         {
3353                 pctrl = i2o_find_controller(i);
3354                 if(pctrl)
3355                 {
3356                         i2o_proc_remove_controller(pctrl, i2o_proc_dir_root);
3357                         i2o_unlock_controller(pctrl);
3358                 }
3359         }
3360
3361         if(!atomic_read(&i2o_proc_dir_root->count))
3362                 remove_proc_entry("i2o", 0);
3363         else
3364                 return -1;
3365
3366         return 0;
3367 }
3368
3369 int __init i2o_proc_init(void)
3370 {
3371         if (i2o_install_handler(&i2o_proc_handler) < 0)
3372         {
3373                 printk(KERN_ERR "i2o_proc: Unable to install PROC handler.\n");
3374                 return 0;
3375         }
3376
3377         if(create_i2o_procfs())
3378                 return -EBUSY;
3379
3380         return 0;
3381 }
3382
3383 MODULE_AUTHOR("Deepak Saxena");
3384 MODULE_DESCRIPTION("I2O procfs Handler");
3385 MODULE_LICENSE("GPL");
3386
3387 static void __exit i2o_proc_exit(void)
3388 {
3389         destroy_i2o_procfs();
3390         i2o_remove_handler(&i2o_proc_handler);
3391 }
3392
3393 #ifdef MODULE
3394 module_init(i2o_proc_init);
3395 #endif
3396 module_exit(i2o_proc_exit);
3397