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