OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [message/] [i2o/] [i2o_proc.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.