Import 2.3.13pre7
[davej-history.git] / drivers / i2o / i2o_proc.c
blobf0d8afe39e0d364a85b2ae9003e29077ee75f9b8
1 /*
2 * procfs handler for Linux I2O subsystem
4 * Copyright (c) 1999 Intel Corporation
5 *
6 * Originally written by Deepak Saxena(deepak@plexity.net)
8 * This program is free software. You can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 * 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.
17 * DISCLAIMER: This code is still under development/test and may cause
18 * your system to behave unpredictably. Use at your own discretion.
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
26 * set tabstop=3
30 * TODO List
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
37 // FIXME!
38 #define FMT_U64_HEX "0x%08x%08x"
39 #define U64_VAL(pu64) *((u32*)(pu64)+1), *((u32*)(pu64))
41 #include <linux/config.h>
42 #include <linux/types.h>
43 #include <linux/kernel.h>
44 #include <linux/i2o.h>
45 #include <linux/proc_fs.h>
46 #include <linux/init.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
50 #include <asm/io.h>
51 #include <asm/uaccess.h>
52 #include <asm/byteorder.h>
53 #include <asm/spinlock.h>
56 #include "i2o_proc.h"
58 #include "i2o_lan.h"
61 * Structure used to define /proc entries
63 typedef struct _i2o_proc_entry_t
65 char *name; /* entry name */
66 mode_t mode; /* mode */
67 read_proc_t *read_proc; /* read func */
68 write_proc_t *write_proc; /* write func */
69 } i2o_proc_entry;
71 static int proc_context = 0;
74 static int i2o_proc_read_lct(char *, char **, off_t, int, int *, void *);
75 static int i2o_proc_read_hrt(char *, char **, off_t, int, int *, void *);
76 static int i2o_proc_read_stat(char *, char **, off_t, int, int *, void *);
77 static int i2o_proc_read_hw(char *, char **, off_t, int, int *, void *);
78 static int i2o_proc_read_dst(char *, char **, off_t, int, int *, void *);
79 static int i2o_proc_read_ddm_table(char *, char **, off_t, int, int *, void *);
80 static int i2o_proc_read_ds(char *, char **, off_t, int, int *, void *);
81 static int i2o_proc_read_groups(char *, char **, off_t, int, int *, void *);
82 static int i2o_proc_read_priv_msgs(char *, char **, off_t, int, int *, void *);
83 static int i2o_proc_read_dev(char *, char **, off_t, int, int *, void *);
84 static int i2o_proc_read_dev_name(char *, char **, off_t, int, int *, void *);
85 static int i2o_proc_read_ddm(char *, char **, off_t, int, int *, void *);
86 static int i2o_proc_read_uinfo(char *, char **, off_t, int, int *, void *);
87 static int i2o_proc_read_sgl_limits(char *, char **, off_t, int, int *, void *);
88 static int print_serial_number(char *, int, u8 *, int);
89 static int i2o_proc_create_entries(void *,
90 i2o_proc_entry *, struct proc_dir_entry *);
91 static void i2o_proc_remove_entries(i2o_proc_entry *, struct proc_dir_entry *);
92 static int i2o_proc_add_controller(struct i2o_controller *,
93 struct proc_dir_entry * );
94 static void i2o_proc_remove_controller(struct i2o_controller *,
95 struct proc_dir_entry * );
96 static int create_i2o_procfs(void);
97 static int destroy_i2o_procfs(void);
98 static void i2o_proc_reply(struct i2o_handler *, struct i2o_controller *,
99 struct i2o_message *);
101 static int i2o_proc_read_lan_dev_info(char *, char **, off_t, int, int *,
102 void *);
103 static int i2o_proc_read_lan_mac_addr(char *, char **, off_t, int, int *,
104 void *);
105 static int i2o_proc_read_lan_mcast_addr(char *, char **, off_t, int, int *,
106 void *);
107 static int i2o_proc_read_lan_batch_control(char *, char **, off_t, int, int *,
108 void *);
109 static int i2o_proc_read_lan_operation(char *, char **, off_t, int, int *,
110 void *);
111 static int i2o_proc_read_lan_media_operation(char *, char **, off_t, int,
112 int *, void *);
113 static int i2o_proc_read_lan_alt_addr(char *, char **, off_t, int, int *,
114 void *);
115 static int i2o_proc_read_lan_tx_info(char *, char **, off_t, int, int *,
116 void *);
117 static int i2o_proc_read_lan_rx_info(char *, char **, off_t, int, int *,
118 void *);
119 static int i2o_proc_read_lan_hist_stats(char *, char **, off_t, int, int *,
120 void *);
121 static int i2o_proc_read_lan_supp_opt_stats(char *, char **, off_t, int, int *,
122 void *);
123 static int i2o_proc_read_lan_opt_tx_hist_stats(char *, char **, off_t, int,
124 int *, void *);
125 static int i2o_proc_read_lan_opt_rx_hist_stats(char *, char **, off_t, int,
126 int *, void *);
127 static int i2o_proc_read_lan_eth_stats(char *, char **, off_t, int,
128 int *, void *);
129 static int i2o_proc_read_lan_supp_eth_stats(char *, char **, off_t, int, int *,
130 void *);
131 static int i2o_proc_read_lan_opt_eth_stats(char *, char **, off_t, int, int *,
132 void *);
133 static int i2o_proc_read_lan_tr_stats(char *, char **, off_t, int, int *,
134 void *);
135 static int i2o_proc_read_lan_fddi_stats(char *, char **, off_t, int, int *,
136 void *);
138 static struct proc_dir_entry *i2o_proc_dir_root;
141 * Message handler
143 static struct i2o_handler i2o_proc_handler =
145 (void *)i2o_proc_reply,
146 "I2O procfs Layer",
148 0xffffffff // All classes
152 * IOP specific entries...write field just in case someone
153 * ever wants one.
155 static i2o_proc_entry generic_iop_entries[] =
157 {"hrt", S_IFREG|S_IRUGO, i2o_proc_read_hrt, NULL},
158 {"lct", S_IFREG|S_IRUGO, i2o_proc_read_lct, NULL},
159 {"stat", S_IFREG|S_IRUGO, i2o_proc_read_stat, NULL},
160 {"hw", S_IFREG|S_IRUGO, i2o_proc_read_hw, NULL},
161 {"dst", S_IFREG|S_IRUGO, i2o_proc_read_dst, NULL},
162 {"ddm_table", S_IFREG|S_IRUGO, i2o_proc_read_ddm_table, NULL},
163 {"ds", S_IFREG|S_IRUGO, i2o_proc_read_ds, NULL},
164 {NULL, 0, NULL, NULL}
168 * Device specific entries
170 static i2o_proc_entry generic_dev_entries[] =
172 {"groups", S_IFREG|S_IRUGO, i2o_proc_read_groups, NULL},
173 {"priv_msgs", S_IFREG|S_IRUGO, i2o_proc_read_priv_msgs, NULL},
174 {"dev_identity", S_IFREG|S_IRUGO, i2o_proc_read_dev, NULL},
175 {"ddm_identity", S_IFREG|S_IRUGO, i2o_proc_read_ddm, NULL},
176 {"sgl_limits", S_IFREG|S_IRUGO, i2o_proc_read_sgl_limits, NULL},
177 {"user_info", S_IFREG|S_IRUGO, i2o_proc_read_uinfo, NULL},
178 {NULL, 0, NULL, NULL}
182 * Storage unit specific entries (SCSI Periph, BS) with device names
184 static i2o_proc_entry rbs_dev_entries[] =
186 {"dev_name", S_IFREG|S_IRUGO, i2o_proc_read_dev_name, NULL},
187 {NULL, 0, NULL, NULL}
190 #define SCSI_TABLE_SIZE 13
191 static char *scsi_devices[] =
193 "Direct-Access Read/Write",
194 "Sequential-Access Storage",
195 "Printer",
196 "Processor",
197 "WORM Device",
198 "CD-ROM Device",
199 "Scanner Device",
200 "Optical Memory Device",
201 "Medium Changer Device",
202 "Communications Device",
203 "Graphics Art Pre-Press Device",
204 "Graphics Art Pre-Press Device",
205 "Array Controller Device"
208 /* private */
211 * Generic LAN specific entries
213 * Should groups with r/w entries have their own subdirectory?
216 static i2o_proc_entry lan_entries[] =
218 /* LAN param groups 0000h-0008h */
219 {"lan_dev_info", S_IFREG|S_IRUGO, i2o_proc_read_lan_dev_info, NULL},
220 {"lan_mac_addr", S_IFREG|S_IRUGO, i2o_proc_read_lan_mac_addr, NULL},
221 {"lan_mcast_addr", S_IFREG|S_IRUGO|S_IWUSR,
222 i2o_proc_read_lan_mcast_addr, NULL},
223 {"lan_batch_ctrl", S_IFREG|S_IRUGO|S_IWUSR,
224 i2o_proc_read_lan_batch_control, NULL},
225 {"lan_operation", S_IFREG|S_IRUGO, i2o_proc_read_lan_operation, NULL},
226 {"lan_media_operation", S_IFREG|S_IRUGO,
227 i2o_proc_read_lan_media_operation, NULL},
228 {"lan_alt_addr", S_IFREG|S_IRUGO, i2o_proc_read_lan_alt_addr, NULL},
229 {"lan_tx_info", S_IFREG|S_IRUGO, i2o_proc_read_lan_tx_info, NULL},
230 {"lan_rx_info", S_IFREG|S_IRUGO, i2o_proc_read_lan_rx_info, NULL},
231 /* LAN param groups 0100h, 0180h, 0182h, 0183h */
232 {"lan_stats", S_IFREG|S_IRUGO, i2o_proc_read_lan_hist_stats, NULL},
233 {"lan_supp_opt_stats", S_IFREG|S_IRUGO,
234 i2o_proc_read_lan_supp_opt_stats, NULL},
235 {"lan_opt_tx_stats", S_IFREG|S_IRUGO,
236 i2o_proc_read_lan_opt_tx_hist_stats, NULL},
237 {"lan_opt_rx_stats", S_IFREG|S_IRUGO,
238 i2o_proc_read_lan_opt_rx_hist_stats, NULL},
239 /* TODO: LAN param group 0184h */
240 {NULL, 0, NULL, NULL}
244 * Ethernet specific LAN entries
247 static i2o_proc_entry lan_eth_entries[] =
249 /* LAN param groups 0200h, 0280h, 0281h */
250 {"lan_eth_stat", S_IFREG|S_IRUGO, i2o_proc_read_lan_eth_stats, NULL},
251 {"lan_supp_eth_stats", S_IFREG|S_IRUGO,
252 i2o_proc_read_lan_supp_eth_stats, NULL},
253 {"lan_opt_eth_stats", S_IFREG|S_IRUGO,
254 i2o_proc_read_lan_opt_eth_stats, NULL},
255 {NULL, 0, NULL, NULL}
259 * Token Ring specific LAN entries
262 static i2o_proc_entry lan_tr_entries[] =
264 /* LAN param group 0300h */
265 {"lan_tr_stats", S_IFREG|S_IRUGO,
266 i2o_proc_read_lan_tr_stats, NULL},
267 /* TODO: LAN param group 0380h, 0381h */
268 {NULL, 0, NULL, NULL}
272 * FDDI specific LAN entries
275 static i2o_proc_entry lan_fddi_entries[] =
277 /* LAN param group 0400h */
278 {"lan_fddi_stats", S_IFREG|S_IRUGO,
279 i2o_proc_read_lan_fddi_stats, NULL},
280 /* TODO: LAN param group 0480h, 0481h */
281 {NULL, 0, NULL, NULL}
285 static u32 i2o_proc_token = 0;
287 static char *chtostr(u8 *chars, int n)
289 char tmp[256];
290 tmp[0] = 0;
291 return strncat(tmp, (char *)chars, n);
294 static char* bus_strings[] =
296 "Local Bus",
297 "ISA",
298 "EISA",
299 "MCA",
300 "PCI",
301 "PCMCIA",
302 "NUBUS",
303 "CARDBUS"
306 static spinlock_t i2o_proc_lock = SPIN_LOCK_UNLOCKED;
308 void i2o_proc_reply(struct i2o_handler *phdlr, struct i2o_controller *pctrl,
309 struct i2o_message *pmsg)
311 i2o_proc_token = I2O_POST_WAIT_OK;
314 int i2o_proc_read_hrt(char *buf, char **start, off_t offset, int len,
315 int *eof, void *data)
317 struct i2o_controller *c = (struct i2o_controller *)data;
318 pi2o_hrt hrt;
319 u32 msg[6];
320 u32 *workspace;
321 u32 bus;
322 int count;
323 int i;
324 int token;
326 spin_lock(&i2o_proc_lock);
328 len = 0;
330 workspace = kmalloc(2048, GFP_KERNEL);
331 hrt = (pi2o_hrt)workspace;
332 if(workspace==NULL)
334 len += sprintf(buf, "No free memory for HRT buffer\n");
335 spin_unlock(&i2o_proc_lock);
336 return len;
339 memset(workspace, 0, 2048);
341 msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;
342 msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;
343 msg[2]= (u32)proc_context;
344 msg[3]= 0;
345 msg[4]= (0xD0000000 | 2048);
346 msg[5]= virt_to_phys(workspace);
348 token = i2o_post_wait(c, ADAPTER_TID, msg, 6*4, &i2o_proc_token,2);
349 if(token == I2O_POST_WAIT_TIMEOUT)
351 kfree(workspace);
352 len += sprintf(buf, "Timeout waiting for HRT\n");
353 spin_unlock(&i2o_proc_lock);
354 return len;
357 if(hrt->hrt_version)
359 kfree(workspace);
360 len += sprintf(buf+len,
361 "HRT table for controller is too new a version.\n");
362 spin_unlock(&i2o_proc_lock);
363 return len;
366 count = hrt->num_entries;
368 if((count * hrt->entry_len + 8) > 2048) {
369 printk(KERN_WARNING "i2o_proc: HRT does not fit into buffer\n");
370 kfree(workspace);
371 len += sprintf(buf+len,
372 "HRT table too big to fit in buffer.\n");
373 spin_unlock(&i2o_proc_lock);
374 return len;
377 len += sprintf(buf+len, "HRT has %d entries of %d bytes each.\n",
378 count, hrt->entry_len);
380 for(i = 0; i < count; i++)
382 len += sprintf(buf+len, "Entry %d:\n", i);
383 len += sprintf(buf+len, " Adapter ID: %0#10x\n",
384 hrt->hrt_entry[i].adapter_id);
385 len += sprintf(buf+len, " Controlled by: %0#6x\n",
386 hrt->hrt_entry[i].parent_tid);
387 len += sprintf(buf+len, " Bus#%d\n",
388 hrt->hrt_entry[i].bus_num);
390 if(hrt->hrt_entry[i].bus_type != 0x80)
392 bus = hrt->hrt_entry[i].bus_type;
393 len += sprintf(buf+len, " %s Information\n", bus_strings[bus]);
395 switch(bus)
397 case I2O_BUS_LOCAL:
398 len += sprintf(buf+len, " IOBase: %0#6x,",
399 hrt->hrt_entry[i].bus.local_bus.LbBaseIOPort);
400 len += sprintf(buf+len, " MemoryBase: %0#10x\n",
401 hrt->hrt_entry[i].bus.local_bus.LbBaseMemoryAddress);
402 break;
404 case I2O_BUS_ISA:
405 len += sprintf(buf+len, " IOBase: %0#6x,",
406 hrt->hrt_entry[i].bus.isa_bus.IsaBaseIOPort);
407 len += sprintf(buf+len, " MemoryBase: %0#10x,",
408 hrt->hrt_entry[i].bus.isa_bus.IsaBaseMemoryAddress);
409 len += sprintf(buf+len, " CSN: %0#4x,",
410 hrt->hrt_entry[i].bus.isa_bus.CSN);
411 break;
413 case I2O_BUS_EISA:
414 len += sprintf(buf+len, " IOBase: %0#6x,",
415 hrt->hrt_entry[i].bus.eisa_bus.EisaBaseIOPort);
416 len += sprintf(buf+len, " MemoryBase: %0#10x,",
417 hrt->hrt_entry[i].bus.eisa_bus.EisaBaseMemoryAddress);
418 len += sprintf(buf+len, " Slot: %0#4x,",
419 hrt->hrt_entry[i].bus.eisa_bus.EisaSlotNumber);
420 break;
422 case I2O_BUS_MCA:
423 len += sprintf(buf+len, " IOBase: %0#6x,",
424 hrt->hrt_entry[i].bus.mca_bus.McaBaseIOPort);
425 len += sprintf(buf+len, " MemoryBase: %0#10x,",
426 hrt->hrt_entry[i].bus.mca_bus.McaBaseMemoryAddress);
427 len += sprintf(buf+len, " Slot: %0#4x,",
428 hrt->hrt_entry[i].bus.mca_bus.McaSlotNumber);
429 break;
431 case I2O_BUS_PCI:
432 len += sprintf(buf+len, " Bus: %0#4x",
433 hrt->hrt_entry[i].bus.pci_bus.PciBusNumber);
434 len += sprintf(buf+len, " Dev: %0#4x",
435 hrt->hrt_entry[i].bus.pci_bus.PciDeviceNumber);
436 len += sprintf(buf+len, " Func: %0#4x",
437 hrt->hrt_entry[i].bus.pci_bus.PciFunctionNumber);
438 len += sprintf(buf+len, " Vendor: %0#6x",
439 hrt->hrt_entry[i].bus.pci_bus.PciVendorID);
440 len += sprintf(buf+len, " Device: %0#6x\n",
441 hrt->hrt_entry[i].bus.pci_bus.PciDeviceID);
442 break;
444 default:
445 len += sprintf(buf+len, " Unsupported Bus Type\n");
448 else
449 len += sprintf(buf+len, " Unknown Bus Type\n");
452 kfree(workspace);
454 spin_unlock(&i2o_proc_lock);
456 return len;
459 int i2o_proc_read_lct(char *buf, char **start, off_t offset, int len,
460 int *eof, void *data)
462 struct i2o_controller *c = (struct i2o_controller*)data;
463 u32 msg[8];
464 u32 *workspace;
465 pi2o_lct lct; /* = (pi2o_lct)c->lct; */
466 int entries;
467 int token;
468 int i;
470 #define BUS_TABLE_SIZE 3
471 static char *bus_ports[] =
473 "Generic Bus",
474 "SCSI Bus",
475 "Fibre Channel Bus"
478 spin_lock(&i2o_proc_lock);
480 len = 0;
482 workspace = kmalloc(8192, GFP_KERNEL);
483 lct = (pi2o_lct)workspace;
484 if(workspace==NULL)
486 len += sprintf(buf, "No free memory for LCT buffer\n");
487 spin_unlock(&i2o_proc_lock);
488 return len;
491 memset(workspace, 0, 8192);
493 msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_6;
494 msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;
495 msg[2] = (u32)proc_context;
496 msg[3] = 0;
497 msg[4] = 0xFFFFFFFF; /* All devices */
498 msg[5] = 0x00000000; /* Report now */
499 msg[6] = 0xD0000000|8192;
500 msg[7] = virt_to_bus(workspace);
502 token = i2o_post_wait(c, ADAPTER_TID, msg, 8*4, &i2o_proc_token,2);
503 if(token == I2O_POST_WAIT_TIMEOUT)
505 kfree(workspace);
506 len += sprintf(buf, "Timeout waiting for LCT\n");
507 spin_unlock(&i2o_proc_lock);
508 return len;
511 entries = (lct->table_size - 3)/9;
513 len += sprintf(buf, "LCT contains %d %s\n", entries,
514 entries == 1 ? "entry" : "entries");
515 if(lct->boot_tid)
516 len += sprintf(buf+len, "Boot Device @ ID %d\n", lct->boot_tid);
518 for(i = 0; i < entries; i++)
520 len += sprintf(buf+len, "Entry %d\n", i);
522 len += sprintf(buf+len, " %s", i2o_get_class_name(lct->lct_entry[i].class_id));
525 * Classes which we'll print subclass info for
527 switch(lct->lct_entry[i].class_id & 0xFFF)
529 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
530 switch(lct->lct_entry[i].sub_class)
532 case 0x00:
533 len += sprintf(buf+len, ": Direct-Access Read/Write");
534 break;
536 case 0x04:
537 len += sprintf(buf+len, ": WORM Drive");
538 break;
540 case 0x05:
541 len += sprintf(buf+len, ": CD-ROM Drive");
542 break;
544 case 0x07:
545 len += sprintf(buf+len, ": Optical Memory Device");
546 break;
548 default:
549 len += sprintf(buf+len, ": Unknown (0x%02x)",
550 lct->lct_entry[i].sub_class);
551 break;
553 break;
555 case I2O_CLASS_LAN:
556 switch(lct->lct_entry[i].sub_class & 0xFF)
558 case 0x30:
559 len += sprintf(buf+len, ": Ethernet");
560 break;
562 case 0x40:
563 len += sprintf(buf+len, ": 100base VG");
564 break;
566 case 0x50:
567 len += sprintf(buf+len, ": IEEE 802.5/Token-Ring");
568 break;
570 case 0x60:
571 len += sprintf(buf+len, ": ANSI X3T9.5 FDDI");
572 break;
574 case 0x70:
575 len += sprintf(buf+len, ": Fibre Channel");
576 break;
578 default:
579 len += sprintf(buf+len, ": Unknown Sub-Class (0x%02x)",
580 lct->lct_entry[i].sub_class & 0xFF);
581 break;
583 break;
585 case I2O_CLASS_SCSI_PERIPHERAL:
586 if(lct->lct_entry[i].sub_class < SCSI_TABLE_SIZE)
587 len += sprintf(buf+len, ": %s",
588 scsi_devices[lct->lct_entry[i].sub_class]);
589 else
590 len += sprintf(buf+len, ": Unknown Device Type");
591 break;
593 case I2O_CLASS_BUS_ADAPTER_PORT:
594 if(lct->lct_entry[i].sub_class < BUS_TABLE_SIZE)
595 len += sprintf(buf+len, ": %s",
596 bus_ports[lct->lct_entry[i].sub_class]);
597 else
598 len += sprintf(buf+len, ": Unknown Bus Type");
599 break;
601 len += sprintf(buf+len, "\n");
603 len += sprintf(buf+len, " Local TID: 0x%03x\n", lct->lct_entry[i].tid);
604 len += sprintf(buf+len, " User TID: 0x%03x\n", lct->lct_entry[i].user_tid);
605 len += sprintf(buf+len, " Parent TID: 0x%03x\n",
606 lct->lct_entry[i].parent_tid);
607 len += sprintf(buf+len, " Identity Tag: 0x%x%x%x%x%x%x%x%x\n",
608 lct->lct_entry[i].identity_tag[0],
609 lct->lct_entry[i].identity_tag[1],
610 lct->lct_entry[i].identity_tag[2],
611 lct->lct_entry[i].identity_tag[3],
612 lct->lct_entry[i].identity_tag[4],
613 lct->lct_entry[i].identity_tag[5],
614 lct->lct_entry[i].identity_tag[6],
615 lct->lct_entry[i].identity_tag[7]);
616 len += sprintf(buf+len, " Change Indicator: %0#10x\n",
617 lct->lct_entry[i].change_ind);
618 len += sprintf(buf+len, " Device Flags: %0#10x\n",
619 lct->lct_entry[i].device_flags);
622 kfree(workspace);
623 spin_unlock(&i2o_proc_lock);
625 return len;
628 int i2o_proc_read_stat(char *buf, char **start, off_t offset, int len,
629 int *eof, void *data)
631 struct i2o_controller *c = (struct i2o_controller*)data;
632 u32 *msg;
633 u32 m;
634 u8 *workspace;
635 u16 *work16;
636 u32 *work32;
637 long time;
638 char prodstr[25];
639 int version;
641 spin_lock(&i2o_proc_lock);
643 len = 0;
645 workspace = (u8*)kmalloc(88, GFP_KERNEL);
646 if(!workspace)
648 len += sprintf(buf, "No memory for status transfer\n");
649 spin_unlock(&i2o_proc_lock);
650 return len;
653 m = I2O_POST_READ32(c);
654 if(m == 0xFFFFFFFF)
656 len += sprintf(buf, "Could not get inbound message frame from IOP!\n");
657 kfree(workspace);
658 spin_unlock(&i2o_proc_lock);
659 return len;
662 msg = (u32 *)(m+c->mem_offset);
664 memset(workspace, 0, 88);
665 work32 = (u32*)workspace;
666 work16 = (u16*)workspace;
668 msg[0] = NINE_WORD_MSG_SIZE|SGL_OFFSET_0;
669 msg[1] = I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID;
670 msg[2] = msg[3] = msg[4] = msg[5] = 0;
671 msg[6] = virt_to_phys(workspace);
672 msg[7] = 0; /* FIXME: 64-bit */
673 msg[8] = 88;
676 * hmm...i2o_post_message should just take ptr to message, and
677 * determine offset on it's own...less work for OSM developers
679 i2o_post_message(c, m);
681 time = jiffies;
683 while(workspace[87] != 0xFF)
685 if(jiffies-time >= 2*HZ)
687 len += sprintf(buf, "Timeout waiting for status reply\n");
688 kfree(workspace);
689 spin_unlock(&i2o_proc_lock);
690 return len;
692 schedule();
693 barrier();
696 len += sprintf(buf+len, "Organization ID: %0#6x\n", work16[0]);
698 version = workspace[9]&0xF0>>4;
699 if(version == 0x02) {
700 len += sprintf(buf+len, "Lowest I2O version supported: ");
701 switch(workspace[2]) {
702 case 0x00:
703 len += sprintf(buf+len, "1.0\n");
704 break;
705 case 0x01:
706 len += sprintf(buf+len, "1.5\n");
707 break;
708 case 0x02:
709 len += sprintf(buf+len, "2.0\n");
710 break;
713 len += sprintf(buf+len, "Highest I2O version supported: ");
714 switch(workspace[3]) {
715 case 0x00:
716 len += sprintf(buf+len, "1.0\n");
717 break;
718 case 0x01:
719 len += sprintf(buf+len, "1.5\n");
720 break;
721 case 0x02:
722 len += sprintf(buf+len, "2.0\n");
723 break;
727 len += sprintf(buf+len, "IOP ID: %0#5x\n", work16[2]&0xFFF);
728 len += sprintf(buf+len, "Host Unit ID: %0#6x\n", work16[3]);
729 len += sprintf(buf+len, "Segment Number: %0#5x\n", work16[4]&0XFFF);
731 len += sprintf(buf+len, "I2O version: ");
732 switch(version)
734 case 0x00:
735 len += sprintf(buf+len, "1.0\n");
736 break;
737 case 0x01:
738 len += sprintf(buf+len, "1.5\n");
739 break;
740 case 0x02:
741 len += sprintf(buf+len, "2.0\n");
742 break;
743 default:
744 len += sprintf(buf+len, "Unknown version\n");
747 len += sprintf(buf+len, "IOP State: ");
748 switch(workspace[10])
750 case 0x01:
751 len += sprintf(buf+len, "Init\n");
752 break;
754 case 0x02:
755 len += sprintf(buf+len, "Reset\n");
756 break;
758 case 0x04:
759 len += sprintf(buf+len, "Hold\n");
760 break;
762 case 0x05:
763 len += sprintf(buf+len, "Hold\n");
764 break;
766 case 0x08:
767 len += sprintf(buf+len, "Operational\n");
768 break;
770 case 0x10:
771 len += sprintf(buf+len, "FAILED\n");
772 break;
774 case 0x11:
775 len += sprintf(buf+len, "FAULTED\n");
776 break;
778 default:
779 len += sprintf(buf+len, "Unknown\n");
780 break;
783 /* 0x00 is the only type supported w/spec 1.5 */
784 /* Added 2.0 types */
785 len += sprintf(buf+len, "Messenger Type: ");
786 switch (workspace[11])
788 case 0x00:
789 len += sprintf(buf+len, "Memory mapped\n");
790 break;
791 case 0x01:
792 len += sprintf(buf+len, "Memory mapped only\n");
793 break;
794 case 0x02:
795 len += sprintf(buf+len, "Remote only\n");
796 break;
797 case 0x03:
798 len += sprintf(buf+len, "Memory mapped and remote\n");
799 break;
800 default:
801 len += sprintf(buf+len, "Unknown\n");
802 break;
804 len += sprintf(buf+len, "Inbound Frame Size: %d bytes\n", work16[6]*4);
805 len += sprintf(buf+len, "Max Inbound Frames: %d\n", work32[4]);
806 len += sprintf(buf+len, "Current Inbound Frames: %d\n", work32[5]);
807 len += sprintf(buf+len, "Max Outbound Frames: %d\n", work32[6]);
809 /* Spec doesn't say if NULL terminated or not... */
810 memcpy(prodstr, work32+7, 24);
811 prodstr[24] = '\0';
812 len += sprintf(buf+len, "Product ID: %s\n", prodstr);
814 len += sprintf(buf+len, "LCT Size: %d\n", work32[13]);
816 len += sprintf(buf+len, "Desired private memory space: %d kB\n",
817 work32[15]>>10);
818 len += sprintf(buf+len, "Allocated private memory space: %d kB\n",
819 work32[16]>>10);
820 len += sprintf(buf+len, "Private memory base address: %0#10x\n",
821 work32[17]);
822 len += sprintf(buf+len, "Desired private I/O space: %d kB\n",
823 work32[18]>>10);
824 len += sprintf(buf+len, "Allocated private I/O space: %d kB\n",
825 work32[19]>>10);
826 len += sprintf(buf+len, "Private I/O base address: %0#10x\n",
827 work32[20]);
829 kfree(workspace);
830 spin_unlock(&i2o_proc_lock);
832 return len;
835 int i2o_proc_read_hw(char *buf, char **start, off_t offset, int len,
836 int *eof, void *data)
838 struct i2o_controller *c = (struct i2o_controller*)data;
839 static u32 work32[5];
840 static u8 *work8 = (u8*)work32;
841 static u16 *work16 = (u16*)work32;
842 int token;
843 u32 hwcap;
845 static char *cpu_table[] =
847 "Intel 80960 series",
848 "AMD2900 series",
849 "Motorola 68000 series",
850 "ARM series",
851 "MIPS series",
852 "Sparc series",
853 "PowerPC series",
854 "Intel x86 series"
857 spin_lock(&i2o_proc_lock);
859 len = 0;
861 token = i2o_query_scalar(c, ADAPTER_TID, proc_context,
862 0, // ParamGroup 0x0000h
863 -1, // all fields
864 &work32,
865 sizeof(work32),
866 &i2o_proc_token);
868 if(token < 0)
870 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
871 spin_unlock(&i2o_proc_lock);
872 return len;
875 len += sprintf(buf, "IOP Hardware Information Table (group = 0x0000)\n");
877 len += sprintf(buf+len, "I2O Vendor ID : %0#6x\n", work16[0]);
878 len += sprintf(buf+len, "Product ID : %0#6x\n", work16[1]);
879 len += sprintf(buf+len, "RAM : %dkB\n", work32[1]>>10);
880 len += sprintf(buf+len, "Non-Volatile Storage : %dkB\n", work32[2]>>10);
882 hwcap = work32[3];
883 len += sprintf(buf+len, "Capabilities :\n");
884 if(hwcap&0x00000001)
885 len += sprintf(buf+len, " Self-booting\n");
886 if(hwcap&0x00000002)
887 len += sprintf(buf+len, " Upgradable IRTOS\n");
888 if(hwcap&0x00000004)
889 len += sprintf(buf+len, " Supports downloading DDMs\n");
890 if(hwcap&0x00000008)
891 len += sprintf(buf+len, " Supports installing DDMs\n");
892 if(hwcap&0x00000010)
893 len += sprintf(buf+len, " Battery-backed RAM\n");
895 len += sprintf(buf+len, "CPU : ");
896 if(work8[16] > 8)
897 len += sprintf(buf+len, "Unknown\n");
898 else
899 len += sprintf(buf+len, "%s\n", cpu_table[work8[16]]);
900 /* Anyone using ProcessorVersion? */
902 spin_unlock(&i2o_proc_lock);
904 return len;
908 /* Executive group 0003h - Executing DDM List (table) */
909 int i2o_proc_read_ddm_table(char *buf, char **start, off_t offset, int len,
910 int *eof, void *data)
912 struct i2o_controller *c = (struct i2o_controller*)data;
913 int token;
914 int i;
916 typedef struct _i2o_exec_execute_ddm_table {
917 u16 ddm_tid;
918 u8 module_type;
919 u8 reserved;
920 u16 i2o_vendor_id;
921 u16 module_id;
922 u8 module_name[24];
923 u8 module_version[4];
924 u32 data_size;
925 u32 code_size;
926 } i2o_exec_execute_ddm_table, *pi2o_exec_execute_ddm_table;
928 struct
930 u16 result_count;
931 u16 pad;
932 u16 block_size;
933 u8 block_status;
934 u8 error_info_size;
935 u16 row_count;
936 u16 more_flag;
937 i2o_exec_execute_ddm_table ddm_table[MAX_I2O_MODULES];
938 } result;
940 i2o_exec_execute_ddm_table ddm_table;
942 spin_lock(&i2o_proc_lock);
943 len = 0;
945 token = i2o_query_table(I2O_PARAMS_TABLE_GET,
946 c, ADAPTER_TID, proc_context,
947 0x0003, -1,
948 NULL, 0,
949 &result, sizeof(result), &i2o_proc_token);
951 if (token<0)
952 switch (token)
954 case -ETIMEDOUT:
955 len += sprintf(buf, "Timeout reading table.\n");
956 spin_unlock(&i2o_proc_lock);
957 return len;
958 break;
959 case -ENOMEM:
960 len += sprintf(buf, "No free memory to read the table.\n");
961 spin_unlock(&i2o_proc_lock);
962 return len;
963 break;
964 default:
965 len += sprintf(buf, "Error reading group. BlockStatus %d\n",
966 token);
967 spin_unlock(&i2o_proc_lock);
968 return len;
971 len += sprintf(buf+len, "Tid Type Vendor Id Name Vrs Data_size Code_size\n");
972 ddm_table=result.ddm_table[0];
974 for(i=0; i < result.row_count; ddm_table=result.ddm_table[++i])
976 len += sprintf(buf+len, "0x%03x ", ddm_table.ddm_tid & 0xFFF);
978 switch(ddm_table.module_type)
980 case 0x01:
981 len += sprintf(buf+len, "Downloaded DDM ");
982 break;
983 case 0x22:
984 len += sprintf(buf+len, "Embedded DDM ");
985 break;
986 default:
987 len += sprintf(buf+len, " ");
990 len += sprintf(buf+len, "%-0#7x", ddm_table.i2o_vendor_id);
991 len += sprintf(buf+len, "%-0#7x", ddm_table.module_id);
992 len += sprintf(buf+len, "%-25s", chtostr(ddm_table.module_name, 24));
993 len += sprintf(buf+len, "%-6s", chtostr(ddm_table.module_version,4));
994 len += sprintf(buf+len, "%8d ", ddm_table.data_size);
995 len += sprintf(buf+len, "%8d", ddm_table.code_size);
997 len += sprintf(buf+len, "\n");
1000 spin_unlock(&i2o_proc_lock);
1002 return len;
1006 /* Executive group 0004h - Driver Store (scalar) */
1007 int i2o_proc_read_ds(char *buf, char **start, off_t offset, int len,
1008 int *eof, void *data)
1010 struct i2o_controller *c = (struct i2o_controller*)data;
1011 u32 work32[8];
1012 int token;
1014 spin_lock(&i2o_proc_lock);
1016 len = 0;
1018 token = i2o_query_scalar(c, ADAPTER_TID, proc_context, 0x0004, -1,
1019 &work32, sizeof(work32), &i2o_proc_token);
1021 if (token<0)
1023 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
1024 spin_unlock(&i2o_proc_lock);
1025 return len;
1028 len += sprintf(buf+len, "Module limit : %d\n"
1029 "Module count : %d\n"
1030 "Current space : %d kB\n"
1031 "Free space : %d kB\n",
1032 work32[0], work32[1], work32[2]>>10, work32[3]>>10);
1034 spin_unlock(&i2o_proc_lock);
1036 return len;
1040 /* Executive group 0005h - Driver Store Table (table) */
1041 int i2o_proc_read_dst(char *buf, char **start, off_t offset, int len,
1042 int *eof, void *data)
1044 typedef struct _i2o_driver_store {
1045 u16 stored_ddm_index;
1046 u8 module_type;
1047 u8 reserved;
1048 u16 i2o_vendor_id;
1049 u16 module_id;
1050 u8 module_name_version[28];
1051 u8 date[8];
1052 u32 module_size;
1053 u32 mpb_size;
1054 u32 module_flags;
1055 } i2o_driver_store_table;
1057 struct i2o_controller *c = (struct i2o_controller*)data;
1058 int token;
1059 int i;
1061 struct
1063 u16 result_count;
1064 u16 pad;
1065 u16 block_size;
1066 u8 block_status;
1067 u8 error_info_size;
1068 u16 row_count;
1069 u16 more_flag;
1070 i2o_driver_store_table dst[MAX_I2O_MODULES];
1071 } result;
1073 i2o_driver_store_table dst;
1075 spin_lock(&i2o_proc_lock);
1077 len = 0;
1079 token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1080 c, ADAPTER_TID, proc_context,
1081 0x0005, -1,
1082 NULL, 0,
1083 &result, sizeof(result), &i2o_proc_token);
1085 if (token<0)
1086 switch (token)
1088 case -ETIMEDOUT:
1089 len += sprintf(buf, "Timeout reading table.\n");
1090 spin_unlock(&i2o_proc_lock);
1091 return len;
1092 break;
1093 case -ENOMEM:
1094 len += sprintf(buf, "No free memory to read the table.\n");
1095 spin_unlock(&i2o_proc_lock);
1096 return len;
1097 break;
1098 default:
1099 len += sprintf(buf, "Error reading group. "
1100 "BlockStatus %d\n",token);
1101 spin_unlock(&i2o_proc_lock);
1102 return len;
1105 len += sprintf(buf+len, "# Type Vendor Id Name Vrs Date Mod_size Par_size Flags\n");
1107 for(i=0, dst=result.dst[0]; i < result.row_count; dst=result.dst[++i])
1109 len += sprintf(buf+len, "%-3d", dst.stored_ddm_index);
1110 switch(dst.module_type)
1112 case 0x01:
1113 len += sprintf(buf+len, "Downloaded DDM ");
1114 break;
1115 case 0x22:
1116 len += sprintf(buf+len, "Embedded DDM ");
1117 break;
1118 default:
1119 len += sprintf(buf+len, " ");
1122 #if 0
1123 if(c->i2oversion == 0x02)
1124 len += sprintf(buf+len, "%-d", dst.module_state);
1125 #endif
1127 len += sprintf(buf+len, "%-0#7x", dst.i2o_vendor_id);
1128 len += sprintf(buf+len, "%-0#8x", dst.module_id);
1129 len += sprintf(buf+len, "%-29s", chtostr(dst.module_name_version,28));
1130 len += sprintf(buf+len, "%-9s", chtostr(dst.date,8));
1131 len += sprintf(buf+len, "%8d ", dst.module_size);
1132 len += sprintf(buf+len, "%8d ", dst.mpb_size);
1133 len += sprintf(buf+len, "0x%04x", dst.module_flags);
1134 #if 0
1135 if(c->i2oversion == 0x02)
1136 len += sprintf(buf+len, "%d",
1137 dst.notification_level);
1138 #endif
1139 len += sprintf(buf+len, "\n");
1142 spin_unlock(&i2o_proc_lock);
1144 return len;
1148 /* Generic group F000h - Params Descriptor (table) */
1149 int i2o_proc_read_groups(char *buf, char **start, off_t offset, int len,
1150 int *eof, void *data)
1152 struct i2o_controller *c = (struct i2o_controller*)data;
1153 int token;
1154 int i;
1155 int rows;
1156 u16 work16[2048];
1157 u16 *group=work16;
1158 int more;
1160 spin_lock(&i2o_proc_lock);
1162 len = 0;
1164 token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1165 c, ADAPTER_TID, proc_context,
1166 0xF000, -1,
1167 NULL, 0,
1168 &work16, sizeof(work16), &i2o_proc_token);
1170 if (token<0)
1171 switch (token)
1173 case -ETIMEDOUT:
1174 len += sprintf(buf, "Timeout reading table.\n");
1175 spin_unlock(&i2o_proc_lock);
1176 return len;
1177 break;
1178 case -ENOMEM:
1179 len += sprintf(buf, "No free memory to read the table.\n");
1180 spin_unlock(&i2o_proc_lock);
1181 return len;
1182 break;
1183 default:
1184 len += sprintf(buf, "Error reading table. BlockStatus %d\n",
1185 token);
1186 spin_unlock(&i2o_proc_lock);
1187 return len;
1190 rows=work16[4];
1191 more=work16[5];
1193 len += sprintf(buf+len, "\nPARAMS DESCRIPTOR TABLE:\n\n");
1194 len += sprintf(buf+len, "# Group FieldCount RowCount Type Add Del Clear\n");
1196 group+=64;
1198 for(i=0; i < rows; i++, group+=16)
1200 len += sprintf(buf+len, "%-3d", i);
1202 len += sprintf(buf+len, "%-0#6x ", group[0]);
1203 len += sprintf(buf+len, "%10d ", group[1]);
1204 len += sprintf(buf+len, "%8d ", group[2]);
1206 if(group[3]&0x1)
1207 len += sprintf(buf+len, "Table ");
1208 else
1209 len += sprintf(buf+len, "Scalar ");
1210 if(group[3]&0x2)
1211 len += sprintf(buf+len, "x ");
1212 else
1213 len += sprintf(buf+len, " ");
1214 if(group[3]&0x4)
1215 len += sprintf(buf+len, "x ");
1216 else
1217 len += sprintf(buf+len, " ");
1218 if(group[3]&0x8)
1219 len += sprintf(buf+len, "x ");
1220 else
1221 len += sprintf(buf+len, " ");
1223 len += sprintf(buf+len, "\n");
1226 if(more)
1227 len += sprintf(buf+len, "There is more...\n");
1229 spin_unlock(&i2o_proc_lock);
1231 return len;
1235 /* Generic group F005h - Private message extensions (table) */
1236 int i2o_proc_read_priv_msgs(char *buf, char **start, off_t offset, int len,
1237 int *eof, void *data)
1239 struct i2o_controller *c = (struct i2o_controller*)data;
1240 int token;
1241 int i;
1242 int rows;
1243 int more;
1244 u16 work16[1024];
1245 u16 *field=work16;
1247 spin_lock(&i2o_proc_lock);
1249 len = 0;
1251 token = i2o_query_table(I2O_PARAMS_TABLE_GET,
1252 c, ADAPTER_TID, proc_context,
1253 0xF000, -1,
1254 NULL, 0,
1255 &work16, sizeof(work16), &i2o_proc_token);
1257 if (token<0)
1258 switch (token)
1260 case -ETIMEDOUT:
1261 len += sprintf(buf, "Timeout reading table.\n");
1262 spin_unlock(&i2o_proc_lock);
1263 return len;
1264 break;
1265 case -ENOMEM:
1266 len += sprintf(buf, "No free memory to read the table.\n");
1267 spin_unlock(&i2o_proc_lock);
1268 return len;
1269 break;
1270 default:
1271 len += sprintf(buf, "Error reading field. BlockStatus %d\n",
1272 token);
1273 spin_unlock(&i2o_proc_lock);
1274 return len;
1277 rows=work16[4];
1278 more=work16[5];
1280 len += sprintf(buf+len, "Instance# OrgId FunctionCode\n");
1282 field+=64;
1283 for(i=0; i < rows; i++, field+=16)
1285 len += sprintf(buf+len, "%0#9x ", field[0]);
1286 len += sprintf(buf+len, "%0#6x ", work16[1]);
1287 len += sprintf(buf+len, "%0#6x", work16[2]);
1289 len += sprintf(buf+len, "\n");
1292 if(more)
1293 len += sprintf(buf+len, "There is more...\n");
1295 spin_unlock(&i2o_proc_lock);
1297 return len;
1301 int i2o_proc_read_dev(char *buf, char **start, off_t offset, int len,
1302 int *eof, void *data)
1304 struct i2o_device *d = (struct i2o_device*)data;
1305 static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
1306 // == (allow) 512d bytes (max)
1307 static u16 *work16 = (u16*)work32;
1308 int token;
1310 spin_lock(&i2o_proc_lock);
1312 len = 0;
1314 token = i2o_query_scalar(d->controller, d->id, proc_context,
1315 0xF100, // ParamGroup F100h (Device Identity)
1316 -1, // all fields
1317 &work32,
1318 sizeof(work32),
1319 &i2o_proc_token);
1321 if(token < 0)
1323 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
1324 spin_unlock(&i2o_proc_lock);
1325 return len;
1328 len += sprintf(buf, "Device Class : %s\n", i2o_get_class_name(work16[0]));
1329 len += sprintf(buf+len, "Owner TID : %0#5x\n", work16[2]);
1330 len += sprintf(buf+len, "Parent TID : %0#5x\n", work16[3]);
1331 len += sprintf(buf+len, "Vendor info : %s\n", chtostr((u8 *)(work32+2), 16));
1332 len += sprintf(buf+len, "Product info : %s\n", chtostr((u8 *)(work32+6), 16));
1333 len += sprintf(buf+len, "Description : %s\n", chtostr((u8 *)(work32+10), 16));
1334 len += sprintf(buf+len, "Product rev. : %s\n", chtostr((u8 *)(work32+14), 8));
1336 len += sprintf(buf+len, "Serial number : ");
1337 len = print_serial_number(buf, len,
1338 (u8*)(work32+16),
1339 /* allow for SNLen plus
1340 * possible trailing '\0'
1342 sizeof(work32)-(16*sizeof(u32))-2
1344 len += sprintf(buf+len, "\n");
1346 spin_unlock(&i2o_proc_lock);
1348 return len;
1352 int i2o_proc_read_dev_name(char *buf, char **start, off_t offset, int len,
1353 int *eof, void *data)
1355 struct i2o_device *d = (struct i2o_device*)data;
1357 if ( d->dev_name[0] == '\0' )
1358 return 0;
1360 len = sprintf(buf, "%s\n", d->dev_name);
1362 return len;
1367 int i2o_proc_read_ddm(char *buf, char **start, off_t offset, int len,
1368 int *eof, void *data)
1370 struct i2o_device *d = (struct i2o_device*)data;
1371 static u32 work32[128];
1372 static u16 *work16 = (u16*)work32;
1373 int token;
1375 spin_lock(&i2o_proc_lock);
1377 len = 0;
1379 token = i2o_query_scalar(d->controller, d->id, proc_context,
1380 0xF101, // ParamGroup F101h (DDM Identity)
1381 -1, // all fields
1382 &work32,
1383 sizeof(work32),
1384 &i2o_proc_token);
1386 if(token < 0)
1388 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
1389 spin_unlock(&i2o_proc_lock);
1390 return len;
1393 len += sprintf(buf, "Registering DDM TID : 0x%03x\n", work16[0]&0xFFF);
1394 len += sprintf(buf+len, "Module name : %s\n", chtostr((u8 *)(work16+1), 24));
1395 len += sprintf(buf+len, "Module revision : %s\n", chtostr((u8 *)(work16+13), 8));
1397 len += sprintf(buf+len, "Serial number : ");
1398 len = print_serial_number(buf, len,
1399 (u8*)(work16+17),
1400 /* allow for SNLen plus
1401 * possible trailing '\0'
1403 sizeof(work32)-(17*sizeof(u16))-2
1405 len += sprintf(buf+len, "\n");
1407 spin_unlock(&i2o_proc_lock);
1409 return len;
1412 int i2o_proc_read_uinfo(char *buf, char **start, off_t offset, int len,
1413 int *eof, void *data)
1415 struct i2o_device *d = (struct i2o_device*)data;
1416 static u32 work32[256];
1417 int token;
1419 spin_lock(&i2o_proc_lock);
1421 len = 0;
1423 token = i2o_query_scalar(d->controller, d->id, proc_context,
1424 0xF102, // ParamGroup F102h (User Information)
1425 -1, // all fields
1426 &work32,
1427 sizeof(work32),
1428 &i2o_proc_token);
1430 if(token < 0)
1432 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
1433 spin_unlock(&i2o_proc_lock);
1434 return len;
1437 len += sprintf(buf, "Device name : %s\n", chtostr((u8 *)work32, 64));
1438 len += sprintf(buf+len, "Service name : %s\n", chtostr((u8 *)(work32+16), 64));
1439 len += sprintf(buf+len, "Physical name : %s\n", chtostr((u8 *)(work32+32), 64));
1440 len += sprintf(buf+len, "Instance number : %s\n", chtostr((u8 *)(work32+48), 4));
1442 spin_unlock(&i2o_proc_lock);
1444 return len;
1448 int i2o_proc_read_sgl_limits(char *buf, char **start, off_t offset, int len,
1449 int *eof, void *data)
1451 struct i2o_device *d = (struct i2o_device*)data;
1452 static u32 work32[12];
1453 static u16 *work16 = (u16 *)work32;
1454 static u8 *work8 = (u8 *)work32;
1455 int token;
1457 spin_lock(&i2o_proc_lock);
1459 len = 0;
1461 token = i2o_query_scalar(d->controller, d->id, proc_context,
1462 0xF103, // ParamGroup F103h (SGL Operating Limits)
1463 -1, // all fields
1464 &work32,
1465 sizeof(work32),
1466 &i2o_proc_token);
1468 if(token < 0)
1470 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
1471 spin_unlock(&i2o_proc_lock);
1472 return len;
1475 len += sprintf(buf, "SGL chain size : %d\n", work32[0]);
1476 len += sprintf(buf+len, "Max SGL chain size : %d\n", work32[1]);
1477 len += sprintf(buf+len, "SGL chain size target : %d\n", work32[2]);
1478 len += sprintf(buf+len, "SGL frag count : %d\n", work16[6]);
1479 len += sprintf(buf+len, "Max SGL frag count : %d\n", work16[7]);
1480 len += sprintf(buf+len, "SGL frag count target : %d\n", work16[8]);
1482 if (d->i2oversion == 0x02)
1484 len += sprintf(buf+len, "SGL data alignment : %d\n", work16[8]);
1485 len += sprintf(buf+len, "SGL addr limit : %d\n", work8[20]);
1486 len += sprintf(buf+len, "SGL addr sizes supported : ");
1487 if (work8[21] & 0x01)
1488 len += sprintf(buf+len, "32 bit ");
1489 if (work8[21] & 0x02)
1490 len += sprintf(buf+len, "64 bit ");
1491 if (work8[21] & 0x04)
1492 len += sprintf(buf+len, "96 bit ");
1493 if (work8[21] & 0x08)
1494 len += sprintf(buf+len, "128 bit ");
1495 len += sprintf(buf+len, "\n");
1498 spin_unlock(&i2o_proc_lock);
1500 return len;
1504 static int print_serial_number(char *buff, int pos, u8 *serialno, int max_len)
1506 int i;
1508 /* 19990419 -sralston
1509 * The I2O v1.5 (and v2.0 so far) "official specification"
1510 * got serial numbers WRONG!
1511 * Apparently, and despite what Section 3.4.4 says and
1512 * Figure 3-35 shows (pg 3-39 in the pdf doc),
1513 * the convention / consensus seems to be:
1514 * + First byte is SNFormat
1515 * + Second byte is SNLen (but only if SNFormat==7 (?))
1516 * + (v2.0) SCSI+BS may use IEEE Registered (64 or 128 bit) format
1518 switch(serialno[0])
1520 case I2O_SNFORMAT_BINARY: /* Binary */
1521 pos += sprintf(buff+pos, "0x");
1522 for(i = 0; i < serialno[1]; i++)
1524 pos += sprintf(buff+pos, "%02X", serialno[2+i]);
1526 break;
1528 case I2O_SNFORMAT_ASCII: /* ASCII */
1529 if ( serialno[1] < ' ' ) /* printable or SNLen? */
1531 /* sanity */
1532 max_len = (max_len < serialno[1]) ? max_len : serialno[1];
1533 serialno[1+max_len] = '\0';
1535 /* just print it */
1536 pos += sprintf(buff+pos, "%s", &serialno[2]);
1538 else
1540 /* print chars for specified length */
1541 for(i = 0; i < serialno[1]; i++)
1543 pos += sprintf(buff+pos, "%c", serialno[2+i]);
1546 break;
1548 case I2O_SNFORMAT_UNICODE: /* UNICODE */
1549 pos += sprintf(buff+pos, "UNICODE Format. Can't Display\n");
1550 break;
1552 case I2O_SNFORMAT_LAN48_MAC: /* LAN-48 MAC Address */
1553 pos += sprintf(buff+pos,
1554 "LAN-48 MAC address @ %02X:%02X:%02X:%02X:%02X:%02X",
1555 serialno[2], serialno[3],
1556 serialno[4], serialno[5],
1557 serialno[6], serialno[7]);
1558 break;
1560 case I2O_SNFORMAT_WAN: /* WAN MAC Address */
1561 /* FIXME: Figure out what a WAN access address looks like?? */
1562 pos += sprintf(buff+pos, "WAN Access Address");
1563 break;
1565 /* plus new in v2.0 */
1566 case I2O_SNFORMAT_LAN64_MAC: /* LAN-64 MAC Address */
1567 /* FIXME: Figure out what a LAN-64 address really looks like?? */
1568 pos += sprintf(buff+pos,
1569 "LAN-64 MAC address @ [?:%02X:%02X:?] %02X:%02X:%02X:%02X:%02X:%02X",
1570 serialno[8], serialno[9],
1571 serialno[2], serialno[3],
1572 serialno[4], serialno[5],
1573 serialno[6], serialno[7]);
1574 break;
1577 case I2O_SNFORMAT_DDM: /* I2O DDM */
1578 pos += sprintf(buff+pos,
1579 "DDM: Tid=%03Xh, Rsvd=%04Xh, OrgId=%04Xh",
1580 *(u16*)&serialno[2],
1581 *(u16*)&serialno[4],
1582 *(u16*)&serialno[6]);
1583 break;
1585 case I2O_SNFORMAT_IEEE_REG64: /* IEEE Registered (64-bit) */
1586 case I2O_SNFORMAT_IEEE_REG128: /* IEEE Registered (128-bit) */
1587 /* FIXME: Figure if this is even close?? */
1588 pos += sprintf(buff+pos,
1589 "IEEE NodeName(hi,lo)=(%08Xh:%08Xh), PortName(hi,lo)=(%08Xh:%08Xh)\n",
1590 *(u32*)&serialno[2],
1591 *(u32*)&serialno[6],
1592 *(u32*)&serialno[10],
1593 *(u32*)&serialno[14]);
1594 break;
1597 case I2O_SNFORMAT_UNKNOWN: /* Unknown 0 */
1598 case I2O_SNFORMAT_UNKNOWN2: /* Unknown 0xff */
1599 default:
1600 pos += sprintf(buff+pos, "Unknown data format (0x%02x)",
1601 serialno[0]);
1602 break;
1605 return pos;
1608 const char * i2o_get_connector_type(int conn)
1610 int idx = 16;
1611 static char *i2o_connector_type[] = {
1612 "OTHER",
1613 "UNKNOWN",
1614 "AUI",
1615 "UTP",
1616 "BNC",
1617 "RJ45",
1618 "STP DB9",
1619 "FIBER MIC",
1620 "APPLE AUI",
1621 "MII",
1622 "DB9",
1623 "HSSDC",
1624 "DUPLEX SC FIBER",
1625 "DUPLEX ST FIBER",
1626 "TNC/BNC",
1627 "HW DEFAULT"
1630 switch(conn)
1632 case 0x00000000:
1633 idx = 0;
1634 break;
1635 case 0x00000001:
1636 idx = 1;
1637 break;
1638 case 0x00000002:
1639 idx = 2;
1640 break;
1641 case 0x00000003:
1642 idx = 3;
1643 break;
1644 case 0x00000004:
1645 idx = 4;
1646 break;
1647 case 0x00000005:
1648 idx = 5;
1649 break;
1650 case 0x00000006:
1651 idx = 6;
1652 break;
1653 case 0x00000007:
1654 idx = 7;
1655 break;
1656 case 0x00000008:
1657 idx = 8;
1658 break;
1659 case 0x00000009:
1660 idx = 9;
1661 break;
1662 case 0x0000000A:
1663 idx = 10;
1664 break;
1665 case 0x0000000B:
1666 idx = 11;
1667 break;
1668 case 0x0000000C:
1669 idx = 12;
1670 break;
1671 case 0x0000000D:
1672 idx = 13;
1673 break;
1674 case 0x0000000E:
1675 idx = 14;
1676 break;
1677 case 0xFFFFFFFF:
1678 idx = 15;
1679 break;
1682 return i2o_connector_type[idx];
1686 const char * i2o_get_connection_type(int conn)
1688 int idx = 0;
1689 static char *i2o_connection_type[] = {
1690 "Unknown",
1691 "AUI",
1692 "10BASE5",
1693 "FIORL",
1694 "10BASE2",
1695 "10BROAD36",
1696 "10BASE-T",
1697 "10BASE-FP",
1698 "10BASE-FB",
1699 "10BASE-FL",
1700 "100BASE-TX",
1701 "100BASE-FX",
1702 "100BASE-T4",
1703 "1000BASE-SX",
1704 "1000BASE-LX",
1705 "1000BASE-CX",
1706 "1000BASE-T",
1707 "100VG-ETHERNET",
1708 "100VG-TOKEN RING",
1709 "4MBIT TOKEN RING",
1710 "16 Mb Token Ring",
1711 "125 MBAUD FDDI",
1712 "Point-to-point",
1713 "Arbitrated loop",
1714 "Public loop",
1715 "Fabric",
1716 "Emulation",
1717 "Other",
1718 "HW default"
1721 switch(conn)
1723 case I2O_LAN_UNKNOWN:
1724 idx = 0;
1725 break;
1726 case I2O_LAN_AUI:
1727 idx = 1;
1728 break;
1729 case I2O_LAN_10BASE5:
1730 idx = 2;
1731 break;
1732 case I2O_LAN_FIORL:
1733 idx = 3;
1734 break;
1735 case I2O_LAN_10BASE2:
1736 idx = 4;
1737 break;
1738 case I2O_LAN_10BROAD36:
1739 idx = 5;
1740 break;
1741 case I2O_LAN_10BASE_T:
1742 idx = 6;
1743 break;
1744 case I2O_LAN_10BASE_FP:
1745 idx = 7;
1746 break;
1747 case I2O_LAN_10BASE_FB:
1748 idx = 8;
1749 break;
1750 case I2O_LAN_10BASE_FL:
1751 idx = 9;
1752 break;
1753 case I2O_LAN_100BASE_TX:
1754 idx = 10;
1755 break;
1756 case I2O_LAN_100BASE_FX:
1757 idx = 11;
1758 break;
1759 case I2O_LAN_100BASE_T4:
1760 idx = 12;
1761 break;
1762 case I2O_LAN_1000BASE_SX:
1763 idx = 13;
1764 break;
1765 case I2O_LAN_1000BASE_LX:
1766 idx = 14;
1767 break;
1768 case I2O_LAN_1000BASE_CX:
1769 idx = 15;
1770 break;
1771 case I2O_LAN_1000BASE_T:
1772 idx = 16;
1773 break;
1774 case I2O_LAN_100VG_ETHERNET:
1775 idx = 17;
1776 break;
1777 case I2O_LAN_100VG_TR:
1778 idx = 18;
1779 break;
1780 case I2O_LAN_4MBIT:
1781 idx = 19;
1782 break;
1783 case I2O_LAN_16MBIT:
1784 idx = 20;
1785 break;
1786 case I2O_LAN_125MBAUD:
1787 idx = 21;
1788 break;
1789 case I2O_LAN_POINT_POINT:
1790 idx = 22;
1791 break;
1792 case I2O_LAN_ARB_LOOP:
1793 idx = 23;
1794 break;
1795 case I2O_LAN_PUBLIC_LOOP:
1796 idx = 24;
1797 break;
1798 case I2O_LAN_FABRIC:
1799 idx = 25;
1800 break;
1801 case I2O_LAN_EMULATION:
1802 idx = 26;
1803 break;
1804 case I2O_LAN_OTHER:
1805 idx = 27;
1806 break;
1807 case I2O_LAN_DEFAULT:
1808 idx = 28;
1809 break;
1812 return i2o_connection_type[idx];
1816 /* LAN group 0000h - Device info (scalar) */
1817 int i2o_proc_read_lan_dev_info(char *buf, char **start, off_t offset, int len,
1818 int *eof, void *data)
1820 struct i2o_device *d = (struct i2o_device*)data;
1821 static u32 work32[56];
1822 static u8 *work8 = (u8*)work32;
1823 static u16 *work16 = (u16*)work32;
1824 static u64 *work64 = (u64*)work32;
1825 int token;
1827 spin_lock(&i2o_proc_lock);
1829 len = 0;
1831 token = i2o_query_scalar(d->controller, d->id, proc_context,
1832 0x0000, -1, &work32, 56*4, &i2o_proc_token);
1833 if(token < 0)
1835 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
1836 spin_unlock(&i2o_proc_lock);
1837 return len;
1840 len += sprintf(buf, "LAN Type : ");
1841 switch (work16[0])
1843 case 0x0030:
1844 len += sprintf(buf+len, "Ethernet, ");
1845 break;
1846 case 0x0040:
1847 len += sprintf(buf+len, "100Base VG, ");
1848 break;
1849 case 0x0050:
1850 len += sprintf(buf+len, "Token Ring, ");
1851 break;
1852 case 0x0060:
1853 len += sprintf(buf+len, "FDDI, ");
1854 break;
1855 case 0x0070:
1856 len += sprintf(buf+len, "Fibre Channel, ");
1857 break;
1858 default:
1859 len += sprintf(buf+len, "Unknown type (0x%04x), ", work16[0]);
1860 break;
1863 if (work16[1]&0x00000001)
1864 len += sprintf(buf+len, "emulated LAN, ");
1865 else
1866 len += sprintf(buf+len, "physical LAN port, ");
1868 if (work16[1]&0x00000002)
1869 len += sprintf(buf+len, "full duplex\n");
1870 else
1871 len += sprintf(buf+len, "simplex\n");
1873 len += sprintf(buf+len, "Address format : ");
1874 switch(work8[4]) {
1875 case 0x00:
1876 len += sprintf(buf+len, "IEEE 48bit\n");
1877 break;
1878 case 0x01:
1879 len += sprintf(buf+len, "FC IEEE\n");
1880 break;
1881 default:
1882 len += sprintf(buf+len, "Unknown (0x%02x)\n", work8[4]);
1883 break;
1886 len += sprintf(buf+len, "State : ");
1887 switch(work8[5])
1889 case 0x00:
1890 len += sprintf(buf+len, "Unknown\n");
1891 break;
1892 case 0x01:
1893 len += sprintf(buf+len, "Unclaimed\n");
1894 break;
1895 case 0x02:
1896 len += sprintf(buf+len, "Operational\n");
1897 break;
1898 case 0x03:
1899 len += sprintf(buf+len, "Suspended\n");
1900 break;
1901 case 0x04:
1902 len += sprintf(buf+len, "Resetting\n");
1903 break;
1904 case 0x05:
1905 len += sprintf(buf+len, "ERROR: ");
1906 if(work16[3]&0x0001)
1907 len += sprintf(buf+len, "TxCU inoperative ");
1908 if(work16[3]&0x0002)
1909 len += sprintf(buf+len, "RxCU inoperative ");
1910 if(work16[3]&0x0004)
1911 len += sprintf(buf+len, "Local mem alloc ");
1912 len += sprintf(buf+len, "\n");
1913 break;
1914 case 0x06:
1915 len += sprintf(buf+len, "Operational no Rx\n");
1916 break;
1917 case 0x07:
1918 len += sprintf(buf+len, "Suspended no Rx\n");
1919 break;
1920 default:
1921 len += sprintf(buf+len, "Unspecified\n");
1922 break;
1925 len += sprintf(buf+len, "Min packet size : %d\n", work32[2]);
1926 len += sprintf(buf+len, "Max packet size : %d\n", work32[3]);
1927 len += sprintf(buf+len, "HW address : "
1928 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1929 work8[16],work8[17],work8[18],work8[19],
1930 work8[20],work8[21],work8[22],work8[23]);
1932 len += sprintf(buf+len, "Max Tx wire speed : %d bps\n", work64[3]);
1933 len += sprintf(buf+len, "Max Rx wire speed : %d bps\n", work64[4]);
1935 len += sprintf(buf+len, "Min SDU packet size : 0x%08x\n", work32[10]);
1936 len += sprintf(buf+len, "Max SDU packet size : 0x%08x\n", work32[11]);
1938 spin_unlock(&i2o_proc_lock);
1939 return len;
1942 /* LAN group 0001h - MAC address table (scalar) */
1943 int i2o_proc_read_lan_mac_addr(char *buf, char **start, off_t offset, int len,
1944 int *eof, void *data)
1946 struct i2o_device *d = (struct i2o_device*)data;
1947 static u32 work32[48];
1948 static u8 *work8 = (u8*)work32;
1949 int token;
1951 spin_lock(&i2o_proc_lock);
1952 len = 0;
1954 token = i2o_query_scalar(d->controller, d->id, proc_context,
1955 0x0001, -1, &work32, 48*4, &i2o_proc_token);
1956 if(token < 0)
1958 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
1959 spin_unlock(&i2o_proc_lock);
1960 return len;
1963 len += sprintf(buf, "Active address : "
1964 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1965 work8[0],work8[1],work8[2],work8[3],
1966 work8[4],work8[5],work8[6],work8[7]);
1967 len += sprintf(buf+len, "Current address : "
1968 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1969 work8[8],work8[9],work8[10],work8[11],
1970 work8[12],work8[13],work8[14],work8[15]);
1971 len += sprintf(buf+len, "Functional address mask : "
1972 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1973 work8[16],work8[17],work8[18],work8[19],
1974 work8[20],work8[21],work8[22],work8[23]);
1976 len += sprintf(buf+len, "HW/DDM capabilities : 0x%08x\n", work32[7]);
1977 len += sprintf(buf+len, " Unicast packets %ssupported\n",
1978 (work32[7]&0x00000001)?"":"not ");
1979 len += sprintf(buf+len, " Promiscuous mode %ssupported\n",
1980 (work32[7]&0x00000002)?"":"not");
1981 len += sprintf(buf+len, " Promiscuous multicast mode %ssupported\n",
1982 (work32[7]&0x00000004)?"":"not ");
1983 len += sprintf(buf+len," Broadcast reception disabling %ssupported\n",
1984 (work32[7]&0x00000100)?"":"not ");
1985 len += sprintf(buf+len," Multicast reception disabling %ssupported\n",
1986 (work32[7]&0x00000200)?"":"not ");
1987 len += sprintf(buf+len," Functional address disabling %ssupported\n",
1988 (work32[7]&0x00000400)?"":"not ");
1989 len += sprintf(buf+len, " MAC reporting %ssupported\n",
1990 (work32[7]&0x00000800)?"":"not ");
1992 len += sprintf(buf+len, "Filter mask : 0x%08x\n", work32[6]);
1993 len += sprintf(buf+len, " Unicast packets %s\n",
1994 (work32[6]&0x00000001)?"rejected":"enabled");
1995 len += sprintf(buf+len, " Promiscuous mode %s\n",
1996 (work32[6]&0x00000002)?"enabled":"disabled");
1997 len += sprintf(buf+len, " Promiscuous multicast mode %s\n",
1998 (work32[6]&0x00000004)?"enabled":"disabled");
1999 len += sprintf(buf+len, " Broadcast packets %s\n",
2000 (work32[6]&0x00000100)?"rejected":"enabled");
2001 len += sprintf(buf+len, " Multicast packets %s\n",
2002 (work32[6]&0x00000200)?"rejected":"enabled");
2003 len += sprintf(buf+len, " Functional address %s\n",
2004 (work32[6]&0x00000400)?"ignored":"enabled");
2006 if (work32[7]&0x00000800)
2008 len += sprintf(buf+len, " MAC reporting mode : ");
2009 if (work32[6]&0x00000800)
2010 len += sprintf(buf+len, "Pass only priority MAC packets to user\n");
2011 else if (work32[6]&0x00001000)
2012 len += sprintf(buf+len, "Pass all MAC packets to user\n");
2013 else if (work32[6]&0x00001800)
2014 len += sprintf(buf+len, "Pass all MAC packets (promiscuous) to user\n");
2015 else
2016 len += sprintf(buf+len, "Do not pass MAC packets to user\n");
2018 len += sprintf(buf+len, "Number of multicast addresses : %d\n", work32[8]);
2019 len += sprintf(buf+len, "Perfect filtering for max %d multicast addresses\n",
2020 work32[9]);
2021 len += sprintf(buf+len, "Imperfect filtering for max %d multicast addresses\n",
2022 work32[10]);
2024 spin_unlock(&i2o_proc_lock);
2026 return len;
2029 /* LAN group 0002h - Multicast MAC address table (table) */
2030 int i2o_proc_read_lan_mcast_addr(char *buf, char **start, off_t offset,
2031 int len, int *eof, void *data)
2033 struct i2o_device *d = (struct i2o_device*)data;
2034 static u32 field32[64];
2035 static u8 *field8 = (u8 *)field32;
2036 static u16 *field16 = (u16 *)field32;
2037 int token;
2038 int i;
2040 spin_lock(&i2o_proc_lock);
2041 len = 0;
2043 token = i2o_query_table(I2O_PARAMS_TABLE_GET,
2044 d->controller, d->id, proc_context, 0x0002, -1,
2045 NULL, 0, &field32, sizeof(field32),
2046 &i2o_proc_token);
2048 if (token<0)
2049 switch (token) {
2050 case -ETIMEDOUT:
2051 len += sprintf(buf, "Timeout reading table.\n");
2052 spin_unlock(&i2o_proc_lock);
2053 return len;
2054 break;
2055 case -ENOMEM:
2056 len += sprintf(buf, "No free memory to read the table.\n");
2057 spin_unlock(&i2o_proc_lock);
2058 return len;
2059 break;
2060 default:
2061 len += sprintf(buf, "Error reading field. BlockStatus %d\n",
2062 token);
2063 spin_unlock(&i2o_proc_lock);
2064 return len;
2067 len += sprintf(buf, "RowCount=%d, MoreFlag=%d\n",
2068 field16[0], field16[1]);
2070 field8=(u8 *)&field16[2];
2072 for(i=0; i<field16[0]; i++, field8+=8)
2074 len += sprintf(buf+len, "MC MAC address[%d]: "
2075 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2077 field8[0], field8[1], field8[2],
2078 field8[3], field8[4], field8[5],
2079 field8[6], field8[7]);
2082 spin_unlock(&i2o_proc_lock);
2083 return len;
2086 /* LAN group 0003h - Batch Control (scalar) */
2087 int i2o_proc_read_lan_batch_control(char *buf, char **start, off_t offset,
2088 int len, int *eof, void *data)
2090 struct i2o_device *d = (struct i2o_device*)data;
2091 static u32 work32[9];
2092 int token;
2094 spin_lock(&i2o_proc_lock);
2095 len = 0;
2097 token = i2o_query_scalar(d->controller, d->id, proc_context,
2098 0x0003, -1, &work32, 9*4, &i2o_proc_token);
2099 if(token < 0)
2101 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2102 spin_unlock(&i2o_proc_lock);
2103 return len;
2106 len += sprintf(buf, "Batch mode ");
2107 if (work32[0]&0x00000001)
2108 len += sprintf(buf+len, "disabled");
2109 else
2110 len += sprintf(buf+len, "enabled");
2111 if (work32[0]&0x00000002)
2112 len += sprintf(buf+len, " (current setting)");
2113 if (work32[0]&0x00000004)
2114 len += sprintf(buf+len, ", forced");
2115 else
2116 len += sprintf(buf+len, ", toggle");
2117 len += sprintf(buf+len, "\n");
2119 if(d->i2oversion == 0x00) { /* Reserved in 1.53 and 2.0 */
2120 len += sprintf(buf+len, "Rising load delay : %d ms\n",
2121 work32[1]/10);
2122 len += sprintf(buf+len, "Rising load threshold : %d ms\n",
2123 work32[2]/10);
2124 len += sprintf(buf+len, "Falling load delay : %d ms\n",
2125 work32[3]/10);
2126 len += sprintf(buf+len, "Falling load threshold : %d ms\n",
2127 work32[4]/10);
2130 len += sprintf(buf+len, "Max Rx batch count : %d\n", work32[5]);
2131 len += sprintf(buf+len, "Max Rx batch delay : %d\n", work32[6]);
2133 if(d->i2oversion == 0x00) {
2134 len += sprintf(buf+len,
2135 "Transmission completion reporting delay : %d ms\n",
2136 work32[7]);
2137 } else {
2138 len += sprintf(buf+len, "Max Tx batch delay : %d\n", work32[7]);
2139 len += sprintf(buf+len, "Max Tx batch count : %d\n", work32[8]);
2142 spin_unlock(&i2o_proc_lock);
2143 return len;
2146 /* LAN group 0004h - LAN Operation (scalar) */
2147 int i2o_proc_read_lan_operation(char *buf, char **start, off_t offset, int len,
2148 int *eof, void *data)
2150 struct i2o_device *d = (struct i2o_device*)data;
2151 static u32 work32[5];
2152 int token;
2154 spin_lock(&i2o_proc_lock);
2155 len = 0;
2157 token = i2o_query_scalar(d->controller, d->id, proc_context,
2158 0x0004, -1, &work32, 20, &i2o_proc_token);
2159 if(token < 0)
2161 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2162 spin_unlock(&i2o_proc_lock);
2163 return len;
2166 len += sprintf(buf, "Packet prepadding (32b words) : %d\n", work32[0]);
2167 len += sprintf(buf+len, "Transmission error reporting : %s\n",
2168 (work32[1]&1)?"on":"off");
2169 len += sprintf(buf+len, "Bad packet handling : %s\n",
2170 (work32[1]&0x2)?"by host":"by DDM");
2171 len += sprintf(buf+len, "Packet orphan limit : %d\n", work32[2]);
2173 len += sprintf(buf+len, "Tx modes :\n");
2174 if (work32[3]&0x00000004)
2175 len += sprintf(buf+len, " HW CRC supressed\n");
2176 else
2177 len += sprintf(buf+len, " HW CRC\n");
2178 if (work32[3]&0x00000100)
2179 len += sprintf(buf+len, " HW IPv4 checksumming\n");
2180 if (work32[3]&0x00000200)
2181 len += sprintf(buf+len, " HW TCP checksumming\n");
2182 if (work32[3]&0x00000400)
2183 len += sprintf(buf+len, " HW UDP checksumming\n");
2184 if (work32[3]&0x00000800)
2185 len += sprintf(buf+len, " HW RSVP checksumming\n");
2186 if (work32[3]&0x00001000)
2187 len += sprintf(buf+len, " HW ICMP checksumming\n");
2188 if (work32[3]&0x00002000)
2189 len += sprintf(buf+len, " Loopback packet not delivered\n");
2191 len += sprintf(buf+len, "Rx modes :\n");
2192 if (work32[4]&0x00000004)
2193 len += sprintf(buf+len, " FCS in payload\n");
2194 if (work32[4]&0x00000100)
2195 len += sprintf(buf+len, " HW IPv4 checksum validation\n");
2196 if (work32[4]&0x00000200)
2197 len += sprintf(buf+len, " HW TCP checksum validation\n");
2198 if (work32[4]&0x00000400)
2199 len += sprintf(buf+len, " HW UDP checksum validation\n");
2200 if (work32[4]&0x00000800)
2201 len += sprintf(buf+len, " HW RSVP checksum validation\n");
2202 if (work32[4]&0x00001000)
2203 len += sprintf(buf+len, " HW ICMP checksum validation\n");
2205 spin_unlock(&i2o_proc_lock);
2206 return len;
2209 /* LAN group 0005h - Media operation (scalar) */
2210 int i2o_proc_read_lan_media_operation(char *buf, char **start, off_t offset,
2211 int len, int *eof, void *data)
2213 struct i2o_device *d = (struct i2o_device*)data;
2214 static u32 work32[9];
2215 static u8 *work8 = (u8*)work32;
2216 static u64 *work64 = (u64*)work32;
2217 int token;
2219 spin_lock(&i2o_proc_lock);
2220 len = 0;
2222 token = i2o_query_scalar(d->controller, d->id, proc_context,
2223 0x0005, -1, &work32, 36, &i2o_proc_token);
2224 if(token < 0)
2226 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2227 spin_unlock(&i2o_proc_lock);
2228 return len;
2231 len += sprintf(buf, "Connector type : %s\n",
2232 i2o_get_connector_type(work32[0]));
2233 len += sprintf(buf+len, "Connection type : %s\n",
2234 i2o_get_connection_type(work32[1]));
2236 len += sprintf(buf+len, "Current Tx wire speed : %d bps\n", work64[1]);
2237 len += sprintf(buf+len, "Current Rx wire speed : %d bps\n", work64[2]);
2239 len += sprintf(buf+len, "Duplex mode : %s duplex\n",
2240 (work8[24]&1)?"Full":"Half");
2241 len += sprintf(buf+len, "Link status : ");
2242 if(work8[25] == 0x00)
2243 len += sprintf(buf+len, "Unknown\n");
2244 else if(work8[25] == 0x01)
2245 len += sprintf(buf+len, "Normal\n");
2246 else if(work8[25] == 0x02)
2247 len += sprintf(buf+len, "Failure\n");
2248 else if(work8[25] == 0x03)
2249 len += sprintf(buf+len, "Reset\n");
2250 else
2251 len += sprintf(buf+len, "Unspecified\n");
2253 if (d->i2oversion == 0x00) { /* Reserved in 1.53 and 2.0 */
2254 len += sprintf(buf+len, "Bad packets handled by : %s\n",
2255 (work8[26] == 0xFF)?"host":"DDM");
2257 if (d->i2oversion != 0x00) {
2258 len += sprintf(buf+len, "Duplex mode target : ");
2259 switch (work8[27]) {
2260 case 0:
2261 len += sprintf(buf+len, "Half duplex\n");
2262 break;
2263 case 1:
2264 len += sprintf(buf+len, "Full duplex\n");
2265 break;
2266 default:
2267 len += sprintf(buf+len, "\n");
2268 break;
2271 len += sprintf(buf+len, "Connector type target : %s\n",
2272 i2o_get_connector_type(work32[7]));
2273 len += sprintf(buf+len, "Connection type target : %s\n",
2274 i2o_get_connection_type(work32[8]));
2277 spin_unlock(&i2o_proc_lock);
2278 return len;
2281 /* LAN group 0006h - Alternate address (table) */
2282 int i2o_proc_read_lan_alt_addr(char *buf, char **start, off_t offset, int len,
2283 int *eof, void *data)
2285 struct i2o_device *d = (struct i2o_device*)data;
2286 static u32 field32[64];
2287 static u8 *field8 = (u8 *)field32;
2288 static u16 *field16 = (u16 *)field32;
2289 int token;
2290 int i;
2292 spin_lock(&i2o_proc_lock);
2293 len = 0;
2295 token = i2o_query_table(I2O_PARAMS_TABLE_GET,
2296 d->controller, d->id, proc_context, 0x0006, -1,
2297 NULL, 0, &field32, sizeof(field32),
2298 &i2o_proc_token);
2300 if (token<0)
2301 switch (token) {
2302 case -ETIMEDOUT:
2303 len += sprintf(buf, "Timeout reading table.\n");
2304 spin_unlock(&i2o_proc_lock);
2305 return len;
2306 break;
2307 case -ENOMEM:
2308 len += sprintf(buf, "No free memory to read the table.\n");
2309 spin_unlock(&i2o_proc_lock);
2310 return len;
2311 break;
2312 default:
2313 len += sprintf(buf, "Error reading field. BlockStatus %d\n",
2314 token);
2315 spin_unlock(&i2o_proc_lock);
2316 return len;
2319 len += sprintf(buf,"RowCount=%d, MoreFlag=%d\n", field16[0],
2320 field16[1]);
2322 field8=(u8 *)&field16[2];
2324 for(i=0; i<field16[0]; i++, field8+=8)
2326 len += sprintf(buf+len, "Alternate address[%d]: "
2327 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
2329 field8[0], field8[1], field8[2],
2330 field8[3], field8[4], field8[5],
2331 field8[6], field8[7]);
2334 spin_unlock(&i2o_proc_lock);
2335 return len;
2339 /* LAN group 0007h - Transmit info (scalar) */
2340 int i2o_proc_read_lan_tx_info(char *buf, char **start, off_t offset, int len,
2341 int *eof, void *data)
2343 struct i2o_device *d = (struct i2o_device*)data;
2344 static u32 work32[8];
2345 int token;
2347 spin_lock(&i2o_proc_lock);
2348 len = 0;
2350 token = i2o_query_scalar(d->controller, d->id, proc_context,
2351 0x0007, -1, &work32, 8*4, &i2o_proc_token);
2352 if(token < 0)
2354 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2355 spin_unlock(&i2o_proc_lock);
2356 return len;
2359 len += sprintf(buf, "Max SG Elements per packet : %d\n", work32[0]);
2360 len += sprintf(buf+len, "Max SG Elements per chain : %d\n", work32[1]);
2361 len += sprintf(buf+len, "Max outstanding packets : %d\n", work32[2]);
2362 len += sprintf(buf+len, "Max packets per request : %d\n", work32[3]);
2364 len += sprintf(buf+len, "Tx modes :\n");
2365 if(work32[4]&0x00000002)
2366 len += sprintf(buf+len, " No DA in SGL\n");
2367 if(work32[4]&0x00000004)
2368 len += sprintf(buf+len, " CRC suppression\n");
2369 if(work32[4]&0x00000008)
2370 len += sprintf(buf+len, " Loop suppression\n");
2371 if(work32[4]&0x00000010)
2372 len += sprintf(buf+len, " MAC insertion\n");
2373 if(work32[4]&0x00000020)
2374 len += sprintf(buf+len, " RIF insertion\n");
2375 if(work32[4]&0x00000100)
2376 len += sprintf(buf+len, " IPv4 checksum\n");
2377 if(work32[4]&0x00000200)
2378 len += sprintf(buf+len, " TCP checksum\n");
2379 if(work32[4]&0x00000400)
2380 len += sprintf(buf+len, " UDP checksum\n");
2381 if(work32[4]&0x00000800)
2382 len += sprintf(buf+len, " RSVP checksum\n");
2383 if(work32[4]&0x00001000)
2384 len += sprintf(buf+len, " ICMP checksum\n");
2385 if (d->i2oversion == 0x00) {
2386 if(work32[4]&0x00008000)
2387 len += sprintf(buf+len, " Loopback enabled\n");
2388 if(work32[4]&0x00010000)
2389 len += sprintf(buf+len, " Loopback suppression enabled\n");
2390 } else {
2391 if(work32[4]&0x00010000)
2392 len += sprintf(buf+len, " Loopback enabled\n");
2393 if(work32[4]&0x00020000)
2394 len += sprintf(buf+len, " Loopback suppression enabled\n");
2397 spin_unlock(&i2o_proc_lock);
2398 return len;
2401 /* LAN group 0008h - Receive info (scalar) */
2402 int i2o_proc_read_lan_rx_info(char *buf, char **start, off_t offset, int len,
2403 int *eof, void *data)
2405 struct i2o_device *d = (struct i2o_device*)data;
2406 static u32 work32[8];
2407 int token;
2409 spin_lock(&i2o_proc_lock);
2410 len = 0;
2412 token = i2o_query_scalar(d->controller, d->id, proc_context,
2413 0x0008, -1, &work32, 8*4, &i2o_proc_token);
2414 if(token < 0)
2416 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2417 spin_unlock(&i2o_proc_lock);
2418 return len;
2421 len += sprintf(buf,"Max size of chain element : %d\n", work32[0]);
2422 len += sprintf(buf+len, "Max number of buckets : %d\n", work32[1]);
2424 if (d->i2oversion > 0x00) { /* not in 1.5 */
2425 len += sprintf(buf+len, "RxModes : %d\n", work32[2]);
2426 len += sprintf(buf+len, "RxMaxBucketsReply : %d\n", work32[3]);
2427 len += sprintf(buf+len, "RxMaxPacketsPerBuckets : %d\n", work32[4]);
2428 len += sprintf(buf+len, "RxMaxPostBuckets : %d\n", work32[5]);
2431 spin_unlock(&i2o_proc_lock);
2432 return len;
2436 /* LAN group 0100h - LAN Historical statistics (scalar) */
2437 int i2o_proc_read_lan_hist_stats(char *buf, char **start, off_t offset, int len,
2438 int *eof, void *data)
2440 struct i2o_device *d = (struct i2o_device*)data;
2441 static u64 work64[9];
2442 int token;
2444 spin_lock(&i2o_proc_lock);
2445 len = 0;
2447 token = i2o_query_scalar(d->controller, d->id, proc_context,
2448 0x0100, -1, &work64, 9*8, &i2o_proc_token);
2449 if(token < 0)
2451 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2452 spin_unlock(&i2o_proc_lock);
2453 return len;
2456 len += sprintf(buf, "Tx packets : " FMT_U64_HEX "\n",
2457 U64_VAL(&work64[0]));
2458 len += sprintf(buf+len, "Tx bytes : " FMT_U64_HEX "\n",
2459 U64_VAL(&work64[1]));
2460 len += sprintf(buf+len, "Rx packets : " FMT_U64_HEX "\n",
2461 U64_VAL(&work64[2]));
2462 len += sprintf(buf+len, "Rx bytes : " FMT_U64_HEX "\n",
2463 U64_VAL(&work64[3]));
2464 len += sprintf(buf+len, "Tx errors : " FMT_U64_HEX "\n",
2465 U64_VAL(&work64[4]));
2466 len += sprintf(buf+len, "Rx errors : " FMT_U64_HEX "\n",
2467 U64_VAL(&work64[5]));
2468 len += sprintf(buf+len, "Rx dropped : " FMT_U64_HEX "\n",
2469 U64_VAL(&work64[6]));
2470 len += sprintf(buf+len, "Adapter resets : " FMT_U64_HEX "\n",
2471 U64_VAL(&work64[7]));
2472 len += sprintf(buf+len, "Adapter suspends : " FMT_U64_HEX "\n",
2473 U64_VAL(&work64[8]));
2475 spin_unlock(&i2o_proc_lock);
2476 return len;
2480 /* LAN group 0180h - Supported Optional Historical Statistics (scalar) */
2481 int i2o_proc_read_lan_supp_opt_stats(char *buf, char **start, off_t offset,
2482 int len, int *eof, void *data)
2484 struct i2o_device *d = (struct i2o_device*)data;
2485 static u64 work64[4];
2486 int token;
2488 spin_lock(&i2o_proc_lock);
2490 len = 0;
2492 token = i2o_query_scalar(d->controller, d->id, proc_context,
2493 0x0180, -1, &work64, 4*8, &i2o_proc_token);
2494 if(token < 0)
2496 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2497 spin_unlock(&i2o_proc_lock);
2498 return len;
2501 if (d->i2oversion == 0x00)
2502 len += sprintf(buf, "Supported stats : " FMT_U64_HEX " \n",
2503 U64_VAL(&work64[0]));
2504 else
2506 len += sprintf(buf, "Supported stats (0182h) : " FMT_U64_HEX " \n",
2507 U64_VAL(&work64[1]));
2508 len += sprintf(buf, "Supported stats (0183h) : " FMT_U64_HEX " \n",
2509 U64_VAL(&work64[2]));
2510 len += sprintf(buf, "Supported stats (0184h) : " FMT_U64_HEX " \n",
2511 U64_VAL(&work64[3]));
2514 spin_unlock(&i2o_proc_lock);
2515 return len;
2519 /* LAN group 0182h - Optional Non Media Specific Transmit Historical Statistics
2520 * (scalar) */
2521 int i2o_proc_read_lan_opt_tx_hist_stats(char *buf, char **start, off_t offset,
2522 int len, int *eof, void *data)
2524 struct i2o_device *d = (struct i2o_device*)data;
2525 static u64 work64[9];
2526 int token;
2528 spin_lock(&i2o_proc_lock);
2530 len = 0;
2532 token = i2o_query_scalar(d->controller, d->id, proc_context,
2533 0x0182, -1, &work64, 9*8, &i2o_proc_token);
2534 if(token < 0)
2536 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2537 spin_unlock(&i2o_proc_lock);
2538 return len;
2541 len += sprintf(buf, "TxRetryCount : " FMT_U64_HEX "\n",
2542 U64_VAL(&work64[0]));
2543 len += sprintf(buf+len, "DirectedBytesTx : " FMT_U64_HEX "\n",
2544 U64_VAL(&work64[1]));
2545 len += sprintf(buf+len, "DirectedPacketsTx : " FMT_U64_HEX "\n",
2546 U64_VAL(&work64[2]));
2547 len += sprintf(buf+len, "MulticastBytesTx : " FMT_U64_HEX "\n",
2548 U64_VAL(&work64[3]));
2549 len += sprintf(buf+len, "MulticastPacketsTx : " FMT_U64_HEX "\n",
2550 U64_VAL(&work64[4]));
2551 len += sprintf(buf+len, "BroadcastBytesTx : " FMT_U64_HEX "\n",
2552 U64_VAL(&work64[5]));
2553 len += sprintf(buf+len, "BroadcastPacketsTx : " FMT_U64_HEX "\n",
2554 U64_VAL(&work64[6]));
2555 len += sprintf(buf+len, "TotalGroupAddrTxCount : " FMT_U64_HEX "\n",
2556 U64_VAL(&work64[7]));
2557 len += sprintf(buf+len, "TotalTxPacketsTooShort : " FMT_U64_HEX "\n",
2558 U64_VAL(&work64[8]));
2560 spin_unlock(&i2o_proc_lock);
2561 return len;
2564 /* LAN group 0183h - Optional Non Media Specific Receive Historical Statistics
2565 * (scalar) */
2566 int i2o_proc_read_lan_opt_rx_hist_stats(char *buf, char **start, off_t offset,
2567 int len, int *eof, void *data)
2569 struct i2o_device *d = (struct i2o_device*)data;
2570 static u64 work64[11];
2571 int token;
2573 spin_lock(&i2o_proc_lock);
2575 len = 0;
2577 token = i2o_query_scalar(d->controller, d->id, proc_context,
2578 0x0183, -1, &work64, 11*8, &i2o_proc_token);
2579 if(token < 0)
2581 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2582 spin_unlock(&i2o_proc_lock);
2583 return len;
2586 len += sprintf(buf, "ReceiveCRCErrorCount : " FMT_U64_HEX "\n",
2587 U64_VAL(&work64[0]));
2588 len += sprintf(buf+len, "DirectedBytesRx : " FMT_U64_HEX "\n",
2589 U64_VAL(&work64[1]));
2590 len += sprintf(buf+len, "DirectedPacketsRx : " FMT_U64_HEX "\n",
2591 U64_VAL(&work64[2]));
2592 len += sprintf(buf+len, "MulticastBytesRx : " FMT_U64_HEX "\n",
2593 U64_VAL(&work64[3]));
2594 len += sprintf(buf+len, "MulticastPacketsRx : " FMT_U64_HEX "\n",
2595 U64_VAL(&work64[4]));
2596 len += sprintf(buf+len, "BroadcastBytesRx : " FMT_U64_HEX "\n",
2597 U64_VAL(&work64[5]));
2598 len += sprintf(buf+len, "BroadcastPacketsRx : " FMT_U64_HEX "\n",
2599 U64_VAL(&work64[6]));
2600 len += sprintf(buf+len, "TotalGroupAddrRxCount : " FMT_U64_HEX "\n",
2601 U64_VAL(&work64[7]));
2602 len += sprintf(buf+len, "TotalRxPacketsTooShort : " FMT_U64_HEX "\n",
2603 U64_VAL(&work64[8]));
2604 len += sprintf(buf+len, "TotalRxPacketsTooLong : " FMT_U64_HEX "\n",
2605 U64_VAL(&work64[9]));
2606 len += sprintf(buf+len, "TotalRuntPacketsReceived : " FMT_U64_HEX "\n",
2607 U64_VAL(&work64[10]));
2609 spin_unlock(&i2o_proc_lock);
2610 return len;
2613 /* LAN group 0200h - Required Ethernet Statistics (scalar) */
2614 int i2o_proc_read_lan_eth_stats(char *buf, char **start, off_t offset,
2615 int len, int *eof, void *data)
2617 struct i2o_device *d = (struct i2o_device*)data;
2618 static u64 work64[8];
2619 int token;
2622 spin_lock(&i2o_proc_lock);
2624 len = 0;
2626 token = i2o_query_scalar(d->controller, d->id, proc_context,
2627 0x0200, -1, &work64, 8*8, &i2o_proc_token);
2628 if(token < 0)
2630 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2631 spin_unlock(&i2o_proc_lock);
2632 return len;
2635 len += sprintf(buf, "Rx alignment errors : " FMT_U64_HEX "\n",
2636 U64_VAL(&work64[0]));
2637 len += sprintf(buf+len, "Tx one collisions : " FMT_U64_HEX "\n",
2638 U64_VAL(&work64[1]));
2639 len += sprintf(buf+len, "Tx multicollisions : " FMT_U64_HEX "\n",
2640 U64_VAL(&work64[2]));
2641 len += sprintf(buf+len, "Tx deferred : " FMT_U64_HEX "\n",
2642 U64_VAL(&work64[3]));
2643 len += sprintf(buf+len, "Tx late collisions : " FMT_U64_HEX "\n",
2644 U64_VAL(&work64[4]));
2645 len += sprintf(buf+len, "Tx max collisions : " FMT_U64_HEX "\n",
2646 U64_VAL(&work64[5]));
2647 len += sprintf(buf+len, "Tx carrier lost : " FMT_U64_HEX "\n",
2648 U64_VAL(&work64[6]));
2649 len += sprintf(buf+len, "Tx excessive deferrals : " FMT_U64_HEX "\n",
2650 U64_VAL(&work64[7]));
2652 spin_unlock(&i2o_proc_lock);
2653 return len;
2656 /* LAN group 0280h - Supported Ethernet Historical Statistics (scalar) */
2657 int i2o_proc_read_lan_supp_eth_stats(char *buf, char **start, off_t offset,
2658 int len, int *eof, void *data)
2660 struct i2o_device *d = (struct i2o_device*)data;
2661 static u64 work64[1];
2662 int token;
2664 spin_lock(&i2o_proc_lock);
2666 len = 0;
2668 token = i2o_query_scalar(d->controller, d->id, proc_context,
2669 0x0280, -1, &work64, 8, &i2o_proc_token);
2670 if(token < 0)
2672 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2673 spin_unlock(&i2o_proc_lock);
2674 return len;
2677 len += sprintf(buf, "Supported stats : " FMT_U64_HEX "\n",
2678 U64_VAL(&work64[0]));
2680 spin_unlock(&i2o_proc_lock);
2681 return len;
2684 /* LAN group 0281h - Optional Ethernet Historical Statistics (scalar) */
2685 int i2o_proc_read_lan_opt_eth_stats(char *buf, char **start, off_t offset,
2686 int len, int *eof, void *data)
2688 struct i2o_device *d = (struct i2o_device*)data;
2689 static u64 work64[3];
2690 int token;
2692 spin_lock(&i2o_proc_lock);
2694 len = 0;
2696 token = i2o_query_scalar(d->controller, d->id, proc_context,
2697 0x0281, -1, &work64, 3*8, &i2o_proc_token);
2698 if(token < 0)
2700 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2701 spin_unlock(&i2o_proc_lock);
2702 return len;
2705 len += sprintf(buf, "Rx overrun : " FMT_U64_HEX "\n",
2706 U64_VAL(&work64[0]));
2707 len += sprintf(buf, "Tx underrun : " FMT_U64_HEX "\n",
2708 U64_VAL(&work64[1]));
2709 len += sprintf(buf, "Tx heartbeat failure : " FMT_U64_HEX "\n",
2710 U64_VAL(&work64[2]));
2712 spin_unlock(&i2o_proc_lock);
2713 return len;
2716 /* LAN group 0300h - Required Token Ring Statistics (scalar) */
2717 int i2o_proc_read_lan_tr_stats(char *buf, char **start, off_t offset,
2718 int len, int *eof, void *data)
2720 struct i2o_device *d = (struct i2o_device*)data;
2721 static u64 work64[13];
2722 int token;
2724 static char *ring_status[] =
2731 "Ring Recovery",
2732 "Single Station",
2733 "Counter Overflow",
2734 "Remove Received",
2736 "Auto-Removal Error 1",
2737 "Lobe Wire Fault",
2738 "Transmit Beacon",
2739 "Soft Error",
2740 "Hard Error",
2741 "Signal Loss"
2744 spin_lock(&i2o_proc_lock);
2746 len = 0;
2748 token = i2o_query_scalar(d->controller, d->id, proc_context,
2749 0x0300, -1, &work64, 13*8, &i2o_proc_token);
2750 if(token < 0)
2752 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2753 spin_unlock(&i2o_proc_lock);
2754 return len;
2757 len += sprintf(buf, "LineErrors : " FMT_U64_HEX "\n",
2758 U64_VAL(&work64[0]));
2759 len += sprintf(buf+len, "LostFrames : " FMT_U64_HEX "\n",
2760 U64_VAL(&work64[1]));
2761 len += sprintf(buf+len, "ACError : " FMT_U64_HEX "\n",
2762 U64_VAL(&work64[2]));
2763 len += sprintf(buf+len, "TxAbortDelimiter : " FMT_U64_HEX "\n",
2764 U64_VAL(&work64[3]));
2765 len += sprintf(buf+len, "BursErrors : " FMT_U64_HEX "\n",
2766 U64_VAL(&work64[4]));
2767 len += sprintf(buf+len, "FrameCopiedErrors : " FMT_U64_HEX "\n",
2768 U64_VAL(&work64[5]));
2769 len += sprintf(buf+len, "FrequencyErrors : " FMT_U64_HEX "\n",
2770 U64_VAL(&work64[6]));
2771 len += sprintf(buf+len, "InternalErrors : " FMT_U64_HEX "\n",
2772 U64_VAL(&work64[7]));
2773 len += sprintf(buf+len, "LastRingStatus : %s\n", ring_status[work64[8]]);
2774 len += sprintf(buf+len, "TokenError : " FMT_U64_HEX "\n",
2775 U64_VAL(&work64[9]));
2776 len += sprintf(buf+len, "UpstreamNodeAddress : " FMT_U64_HEX "\n",
2777 U64_VAL(&work64[10]));
2778 len += sprintf(buf+len, "LastRingID : " FMT_U64_HEX "\n",
2779 U64_VAL(&work64[11]));
2780 len += sprintf(buf+len, "LastBeaconType : " FMT_U64_HEX "\n",
2781 U64_VAL(&work64[12]));
2783 spin_unlock(&i2o_proc_lock);
2784 return len;
2787 /* LAN group 0400h - Required FDDI Statistics (scalar) */
2788 int i2o_proc_read_lan_fddi_stats(char *buf, char **start, off_t offset,
2789 int len, int *eof, void *data)
2791 struct i2o_device *d = (struct i2o_device*)data;
2792 static u64 work64[11];
2793 int token;
2795 static char *conf_state[] =
2797 "Isolated",
2798 "Local a",
2799 "Local b",
2800 "Local ab",
2801 "Local s",
2802 "Wrap a",
2803 "Wrap b",
2804 "Wrap ab",
2805 "Wrap s",
2806 "C-Wrap a",
2807 "C-Wrap b",
2808 "C-Wrap s",
2809 "Through",
2812 static char *ring_state[] =
2814 "Isolated",
2815 "Non-op",
2816 "Rind-op",
2817 "Detect",
2818 "Non-op-Dup",
2819 "Ring-op-Dup",
2820 "Directed",
2821 "Trace"
2824 static char *link_state[] =
2826 "Off",
2827 "Break",
2828 "Trace",
2829 "Connect",
2830 "Next",
2831 "Signal",
2832 "Join",
2833 "Verify",
2834 "Active",
2835 "Maintenance"
2838 spin_lock(&i2o_proc_lock);
2840 len = 0;
2842 token = i2o_query_scalar(d->controller, d->id, proc_context,
2843 0x0400, -1, &work64, 11*8, &i2o_proc_token);
2844 if(token < 0)
2846 len += sprintf(buf, "Timeout waiting for reply from IOP\n");
2847 spin_unlock(&i2o_proc_lock);
2848 return len;
2851 len += sprintf(buf, "ConfigurationState : %s\n", conf_state[work64[0]]);
2852 len += sprintf(buf+len, "UpstreamNode : " FMT_U64_HEX "\n",
2853 U64_VAL(&work64[1]));
2854 len += sprintf(buf+len, "DownStreamNode : " FMT_U64_HEX "\n",
2855 U64_VAL(&work64[2]));
2856 len += sprintf(buf+len, "FrameErrors : " FMT_U64_HEX "\n",
2857 U64_VAL(&work64[3]));
2858 len += sprintf(buf+len, "FramesLost : " FMT_U64_HEX "\n",
2859 U64_VAL(&work64[4]));
2860 len += sprintf(buf+len, "RingMgmtState : %s\n", ring_state[work64[5]]);
2861 len += sprintf(buf+len, "LCTFailures: " FMT_U64_HEX "\n",
2862 U64_VAL(&work64[6]));
2863 len += sprintf(buf+len, "LEMRejects : " FMT_U64_HEX "\n",
2864 U64_VAL(&work64[7]));
2865 len += sprintf(buf+len, "LEMCount : " FMT_U64_HEX "\n",
2866 U64_VAL(&work64[8]));
2867 len += sprintf(buf+len, "LConnectionState : %s\n",
2868 link_state[work64[9]]);
2870 spin_unlock(&i2o_proc_lock);
2871 return len;
2874 static int i2o_proc_create_entries(void *data, i2o_proc_entry *pentry,
2875 struct proc_dir_entry *parent)
2877 struct proc_dir_entry *ent;
2879 while(pentry->name != NULL)
2881 ent = create_proc_entry(pentry->name, pentry->mode, parent);
2882 if(!ent) return -1;
2884 ent->data = data;
2885 ent->read_proc = pentry->read_proc;
2886 ent->write_proc = pentry->write_proc;
2887 ent->nlink = 1;
2889 pentry++;
2892 return 0;
2895 static void i2o_proc_remove_entries(i2o_proc_entry *pentry,
2896 struct proc_dir_entry *parent)
2898 while(pentry->name != NULL)
2900 remove_proc_entry(pentry->name, parent);
2901 pentry++;
2905 static int i2o_proc_add_controller(struct i2o_controller *pctrl,
2906 struct proc_dir_entry *root )
2908 struct proc_dir_entry *dir, *dir1;
2909 struct i2o_device *dev;
2910 char buff[10];
2912 sprintf(buff, "iop%d", pctrl->unit);
2914 dir = create_proc_entry(buff, S_IFDIR, root);
2915 if(!dir)
2916 return -1;
2918 pctrl->proc_entry = dir;
2920 i2o_proc_create_entries(pctrl, generic_iop_entries, dir);
2922 for(dev = pctrl->devices; dev; dev = dev->next)
2924 sprintf(buff, "%0#5x", dev->id);
2926 dir1 = create_proc_entry(buff, S_IFDIR, dir);
2927 dev->proc_entry = dir1;
2929 if(!dir1)
2930 printk(KERN_INFO "i2o_proc: Could not allocate proc dir\n");
2932 i2o_proc_create_entries(dev, generic_dev_entries, dir1);
2934 switch(dev->class)
2936 case I2O_CLASS_SCSI_PERIPHERAL:
2937 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
2938 i2o_proc_create_entries(dev, rbs_dev_entries, dir1);
2939 break;
2940 case I2O_CLASS_LAN:
2941 i2o_proc_create_entries(dev, lan_entries, dir1);
2942 switch(dev->subclass)
2944 case I2O_LAN_ETHERNET:
2945 i2o_proc_create_entries(dev, lan_eth_entries,
2946 dir1);
2947 break;
2948 case I2O_LAN_FDDI:
2949 i2o_proc_create_entries(dev, lan_fddi_entries,
2950 dir1);
2951 break;
2952 case I2O_LAN_TR:
2953 i2o_proc_create_entries(dev, lan_tr_entries,
2954 dir1);
2955 break;
2956 default:
2957 break;
2959 break;
2960 default:
2961 break;
2965 return 0;
2968 static void i2o_proc_remove_controller(struct i2o_controller *pctrl,
2969 struct proc_dir_entry *parent)
2971 char buff[10];
2972 char dev_id[10];
2973 struct proc_dir_entry *de;
2974 struct i2o_device *dev;
2976 /* Remove unused device entries */
2977 for(dev=pctrl->devices; dev; dev=dev->next)
2979 de=dev->proc_entry;
2980 sprintf(dev_id, "%0#5x", dev->id);
2982 /* Would it be safe to remove _files_ even if they are in use? */
2983 if((de) && (!de->count))
2985 i2o_proc_remove_entries(generic_dev_entries, de);
2987 switch(dev->class)
2989 case I2O_CLASS_SCSI_PERIPHERAL:
2990 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
2991 i2o_proc_remove_entries(rbs_dev_entries, de);
2992 break;
2993 case I2O_CLASS_LAN:
2994 i2o_proc_remove_entries(lan_entries, de);
2995 switch(dev->subclass)
2997 case I2O_LAN_ETHERNET:
2998 i2o_proc_remove_entries(lan_eth_entries, de);
2999 break;
3000 case I2O_LAN_FDDI:
3001 i2o_proc_remove_entries(lan_fddi_entries, de);
3002 break;
3003 case I2O_LAN_TR:
3004 i2o_proc_remove_entries(lan_tr_entries, de);
3005 break;
3008 remove_proc_entry(dev_id, parent);
3012 if(!pctrl->proc_entry->count)
3014 sprintf(buff, "iop%d", pctrl->unit);
3016 i2o_proc_remove_entries(generic_iop_entries, pctrl->proc_entry);
3018 remove_proc_entry(buff, parent);
3019 pctrl->proc_entry = NULL;
3023 static int create_i2o_procfs(void)
3025 struct i2o_controller *pctrl = NULL;
3026 int i;
3028 i2o_proc_dir_root = create_proc_entry("i2o", S_IFDIR, 0);
3029 if(!i2o_proc_dir_root)
3030 return -1;
3032 for(i = 0; i < MAX_I2O_CONTROLLERS; i++)
3034 pctrl = i2o_find_controller(i);
3035 if(pctrl)
3037 i2o_proc_add_controller(pctrl, i2o_proc_dir_root);
3038 i2o_unlock_controller(pctrl);
3042 return 0;
3045 static int destroy_i2o_procfs(void)
3047 struct i2o_controller *pctrl = NULL;
3048 int i;
3050 if(!i2o_find_controller(0))
3051 return -1;
3053 for(i = 0; i < MAX_I2O_CONTROLLERS; i++)
3055 pctrl = i2o_find_controller(i);
3056 if(pctrl)
3058 i2o_proc_remove_controller(pctrl, i2o_proc_dir_root);
3059 i2o_unlock_controller(pctrl);
3063 if(!i2o_proc_dir_root->count)
3064 remove_proc_entry("i2o", 0);
3065 else
3066 return -1;
3068 return 0;
3071 #ifdef MODULE
3072 #define i2o_proc_init init_module
3073 #endif
3075 __init int i2o_proc_init(void)
3077 if(create_i2o_procfs())
3078 return -EBUSY;
3080 if (i2o_install_handler(&i2o_proc_handler) < 0)
3082 printk(KERN_ERR "i2o_proc: Unable to install PROC handler.\n");
3083 return 0;
3086 proc_context = i2o_proc_handler.context;
3088 return 0;
3091 #ifdef MODULE
3094 MODULE_AUTHOR("Deepak Saxena");
3095 MODULE_DESCRIPTION("I2O procfs Handler");
3097 void cleanup_module(void)
3099 destroy_i2o_procfs();
3100 i2o_remove_handler(&i2o_proc_handler);
3102 #endif