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