~ubuntu-branches/ubuntu/gutsy/openipmi/gutsy

« back to all changes in this revision

Viewing changes to lib/oem_atca_fru.c

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2007-06-21 19:48:32 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070621194832-nqtxvxn4pu3ha3gh
Tags: 2.0.11-1
* new upstream release from 2007-02-25
  (closes: Bug#392788)
* added patch parts from Philipp Matthias Hahn <pmhahn@debian.org>
  Thank you!

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 */
29
29
 
30
30
#include <string.h>
 
31
#include <stdio.h> /* for sprintf */
31
32
#include <OpenIPMI/internal/ipmi_fru.h>
32
33
#include <OpenIPMI/internal/ipmi_int.h>
33
34
 
34
35
/***********************************************************************
35
36
 *
36
 
 * FRU Multi-record decoding
37
 
 *
38
 
 **********************************************************************/
39
 
 
40
 
static int
41
 
convert_int_to_fru_int(const char                *name,
42
 
                       int                       val,
43
 
                       const char                **rname,
44
 
                       enum ipmi_fru_data_type_e *dtype,
45
 
                       int                       *intval)
46
 
{
47
 
    if (rname)
48
 
        *rname = name;
49
 
    if (dtype)
50
 
        *dtype = IPMI_FRU_DATA_INT;
51
 
    if (intval)
52
 
        *intval = val;
53
 
    return 0;
54
 
}
55
 
 
56
 
static int
57
 
convert_str_to_fru_str(const char                *name,
58
 
                       enum ipmi_str_type_e      type,
59
 
                       unsigned int              len,
60
 
                       char                      *raw_data,
61
 
                       const char                **rname,
62
 
                       enum ipmi_fru_data_type_e *dtype,
63
 
                       int                       *intval,
64
 
                       char                      **data)
65
 
{
66
 
    if (rname)
67
 
        *rname = name;
68
 
    if (dtype) {
69
 
        switch (type) {
70
 
        case IPMI_ASCII_STR: *dtype = IPMI_FRU_DATA_ASCII; break;
71
 
        case IPMI_UNICODE_STR: *dtype = IPMI_FRU_DATA_BINARY; break;
72
 
        case IPMI_BINARY_STR: *dtype = IPMI_FRU_DATA_UNICODE; break;
73
 
        }
74
 
    }
75
 
    if (intval)
76
 
        *intval = len;
77
 
    if (data) {
78
 
        if (type == IPMI_ASCII_STR)
79
 
            len += 1;
80
 
        else if (len == 0)
81
 
            len = 1;
82
 
        *data = ipmi_mem_alloc(len);
83
 
        if (!(*data))
84
 
            return ENOMEM;
85
 
        if (type == IPMI_ASCII_STR) {
86
 
            memcpy(*data, raw_data, len-1);
87
 
            (*data)[len-1] = '\0';
88
 
        } else
89
 
            memcpy(*data, raw_data, len);
90
 
    }
91
 
    return 0;
92
 
}
93
 
 
94
 
typedef struct atca_p2p_cr_desc_s
95
 
{
96
 
    unsigned char channel_type;
97
 
    unsigned char slot_address;
98
 
    unsigned char channel_count;
99
 
    uint32_t      *chans;
100
 
} atca_p2p_cr_desc_t;
101
 
 
102
 
typedef struct atca_p2p_cr_s
103
 
{
104
 
    unsigned char      version;
105
 
    unsigned int       desc_count;
106
 
    atca_p2p_cr_desc_t *descs;
107
 
    ipmi_fru_t         *fru;
108
 
} atca_p2p_cr_t;
109
 
 
110
 
static void atca_p2p_cleanup_rec(atca_p2p_cr_t *rec)
111
 
{
112
 
    unsigned int i;
113
 
 
114
 
    if (rec->descs) {
115
 
        for (i=0; i<rec->desc_count; i++) {
116
 
            if (rec->descs[i].chans)
117
 
                ipmi_mem_free(rec->descs[i].chans);
118
 
        }
119
 
        ipmi_mem_free(rec->descs);
120
 
    }
121
 
    ipmi_mem_free(rec);
122
 
}
123
 
 
124
 
static void
125
 
atca_p2p_root_destroy(ipmi_fru_node_t *node)
126
 
{
127
 
    atca_p2p_cr_t *rec = _ipmi_fru_node_get_data(node);
128
 
    ipmi_fru_deref(rec->fru);
129
 
    atca_p2p_cleanup_rec(rec);
130
 
}
131
 
 
132
 
static void
133
 
atca_p2p_sub_destroy(ipmi_fru_node_t *node)
134
 
{
135
 
    ipmi_fru_node_t *root_node = _ipmi_fru_node_get_data2(node);
136
 
    ipmi_fru_put_node(root_node);
137
 
}
138
 
 
139
 
static int
140
 
atca_p2p_desc_entry_get_field(ipmi_fru_node_t           *pnode,
141
 
                              unsigned int              index,
142
 
                              const char                **name,
143
 
                              enum ipmi_fru_data_type_e *dtype,
144
 
                              int                       *intval,
145
 
                              time_t                    *time,
146
 
                              double                    *floatval,
147
 
                              char                      **data,
148
 
                              unsigned int              *data_len,
149
 
                              ipmi_fru_node_t           **sub_node)
150
 
{
151
 
    uint32_t rec = *((uint32_t *) _ipmi_fru_node_get_data(pnode));
152
 
    int      rv = 0;
153
 
 
154
 
    switch(index) {
155
 
    case 0:
156
 
        rv = convert_int_to_fru_int("remote slot", rec & 0xff,
157
 
                                    name, dtype, intval);
158
 
        break;
159
 
 
160
 
    case 1:
161
 
        rv = convert_int_to_fru_int("remote channel", (rec >> 8) & 0x1f,
162
 
                                    name, dtype, intval);
163
 
        break;
164
 
 
165
 
    case 2:
166
 
        rv = convert_int_to_fru_int("local channel", (rec >> 13) & 0x1f,
167
 
                                    name, dtype, intval);
168
 
        break;
169
 
 
170
 
    default:
171
 
        rv = EINVAL;
172
 
    }
173
 
 
174
 
    return rv;
175
 
}
176
 
 
177
 
static int
178
 
atca_p2p_desc_entry_array_get_field(ipmi_fru_node_t           *pnode,
179
 
                                    unsigned int              index,
180
 
                                    const char                **name,
181
 
                                    enum ipmi_fru_data_type_e *dtype,
182
 
                                    int                       *intval,
183
 
                                    time_t                    *time,
184
 
                                    double                    *floatval,
185
 
                                    char                      **data,
186
 
                                    unsigned int              *data_len,
187
 
                                    ipmi_fru_node_t           **sub_node)
188
 
{
189
 
    atca_p2p_cr_desc_t *rec = _ipmi_fru_node_get_data(pnode);
190
 
    ipmi_fru_node_t    *rnode = _ipmi_fru_node_get_data2(pnode);
191
 
    atca_p2p_cr_t      *rrec = _ipmi_fru_node_get_data(rnode);
192
 
    ipmi_fru_node_t    *node;
193
 
 
194
 
    if (index >= rec->channel_count)
195
 
        return EINVAL;
196
 
 
197
 
    if (name)
198
 
        *name = NULL; /* We are an array */
199
 
    if (dtype)
200
 
        *dtype = IPMI_FRU_DATA_SUB_NODE;
201
 
    if (intval)
202
 
        *intval = -1; /* Sub element is not an array */
203
 
    if (sub_node) {
204
 
        node = _ipmi_fru_node_alloc(rrec->fru);
205
 
        if (!node)
206
 
            return ENOMEM;
207
 
 
208
 
        ipmi_fru_get_node(rnode);
209
 
        _ipmi_fru_node_set_data(node, rec->chans + index);
210
 
        _ipmi_fru_node_set_data2(node, rnode);
211
 
        _ipmi_fru_node_set_get_field(node, atca_p2p_desc_entry_get_field);
212
 
        _ipmi_fru_node_set_destructor(node, atca_p2p_sub_destroy);
213
 
 
214
 
        *sub_node = node;
215
 
    }
216
 
    return 0;
217
 
}
218
 
 
219
 
 
220
 
static int
221
 
atca_p2p_desc_get_field(ipmi_fru_node_t           *pnode,
222
 
                        unsigned int              index,
223
 
                        const char                **name,
224
 
                        enum ipmi_fru_data_type_e *dtype,
225
 
                        int                       *intval,
226
 
                        time_t                    *time,
227
 
                        double                    *floatval,
228
 
                        char                      **data,
229
 
                        unsigned int              *data_len,
230
 
                        ipmi_fru_node_t           **sub_node)
231
 
{
232
 
    atca_p2p_cr_desc_t *rec = _ipmi_fru_node_get_data(pnode);
233
 
    ipmi_fru_node_t    *rnode = _ipmi_fru_node_get_data2(pnode);
234
 
    atca_p2p_cr_t      *rrec = _ipmi_fru_node_get_data(rnode);
235
 
    ipmi_fru_node_t    *node;
236
 
    int                rv = 0;
237
 
 
238
 
    switch(index) {
239
 
    case 0:
240
 
        rv = convert_int_to_fru_int("channel type", rec->channel_type,
241
 
                                    name, dtype, intval);
242
 
        break;
243
 
 
244
 
    case 1:
245
 
        rv = convert_int_to_fru_int("slot address", rec->slot_address,
246
 
                                    name, dtype, intval);
247
 
        break;
248
 
 
249
 
    case 2:
250
 
        if (name)
251
 
            *name = "channels";
252
 
        if (dtype)
253
 
            *dtype = IPMI_FRU_DATA_SUB_NODE;
254
 
        if (intval)
255
 
            *intval = rec->channel_count;
256
 
        if (sub_node) {
257
 
            node = _ipmi_fru_node_alloc(rrec->fru);
258
 
            if (!node)
259
 
                return ENOMEM;
260
 
            ipmi_fru_get_node(rnode);
261
 
            _ipmi_fru_node_set_data(node, rec);
262
 
            _ipmi_fru_node_set_data2(node, rnode);
263
 
            _ipmi_fru_node_set_get_field(node,
264
 
                                         atca_p2p_desc_entry_array_get_field);
265
 
            _ipmi_fru_node_set_destructor(node, atca_p2p_sub_destroy);
266
 
            *sub_node = node;
267
 
        }
268
 
        break;
269
 
 
270
 
    default:
271
 
        rv = EINVAL;
272
 
    }
273
 
 
274
 
    return rv;
275
 
}
276
 
 
277
 
static int
278
 
atca_p2p_desc_array_get_field(ipmi_fru_node_t           *pnode,
279
 
                              unsigned int              index,
280
 
                              const char                **name,
281
 
                              enum ipmi_fru_data_type_e *dtype,
282
 
                              int                       *intval,
283
 
                              time_t                    *time,
284
 
                              double                    *floatval,
285
 
                              char                      **data,
286
 
                              unsigned int              *data_len,
287
 
                              ipmi_fru_node_t           **sub_node)
288
 
{
289
 
    atca_p2p_cr_t   *rec = _ipmi_fru_node_get_data(pnode);
290
 
    ipmi_fru_node_t *rnode = _ipmi_fru_node_get_data2(pnode);
291
 
    atca_p2p_cr_t   *rrec = _ipmi_fru_node_get_data(rnode);
292
 
    ipmi_fru_node_t *node;
293
 
 
294
 
    if (index >= rec->desc_count)
295
 
        return EINVAL;
296
 
 
297
 
    if (name)
298
 
        *name = NULL; /* We are an array */
299
 
    if (dtype)
300
 
        *dtype = IPMI_FRU_DATA_SUB_NODE;
301
 
    if (intval)
302
 
        *intval = -1; /* Sub element is not an array */
303
 
    if (sub_node) {
304
 
        node = _ipmi_fru_node_alloc(rrec->fru);
305
 
        if (!node)
306
 
            return ENOMEM;
307
 
 
308
 
        ipmi_fru_get_node(rnode);
309
 
        _ipmi_fru_node_set_data(node, rec->descs + index);
310
 
        _ipmi_fru_node_set_data2(node, rnode);
311
 
        _ipmi_fru_node_set_get_field(node, atca_p2p_desc_get_field);
312
 
        _ipmi_fru_node_set_destructor(node, atca_p2p_sub_destroy);
313
 
 
314
 
        *sub_node = node;
315
 
    }
316
 
    return 0;
317
 
}
318
 
 
319
 
static int
320
 
atca_p2p_root_get_field(ipmi_fru_node_t           *rnode,
321
 
                        unsigned int              index,
322
 
                        const char                **name,
323
 
                        enum ipmi_fru_data_type_e *dtype,
324
 
                        int                       *intval,
325
 
                        time_t                    *time,
326
 
                        double                    *floatval,
327
 
                        char                      **data,
328
 
                        unsigned int              *data_len,
329
 
                        ipmi_fru_node_t           **sub_node)
330
 
{
331
 
    atca_p2p_cr_t   *rec = _ipmi_fru_node_get_data(rnode);
332
 
    ipmi_fru_node_t *node;
333
 
    int             rv = 0;
334
 
 
335
 
    switch(index) {
336
 
    case 0:
337
 
        rv = convert_int_to_fru_int("version", rec->version,
338
 
                                    name, dtype, intval);
339
 
        break;
340
 
 
341
 
    case 1:
342
 
        if (name)
343
 
            *name = "descriptors";
344
 
        if (dtype)
345
 
            *dtype = IPMI_FRU_DATA_SUB_NODE;
346
 
        if (intval)
347
 
            *intval = rec->desc_count;
348
 
        if (sub_node) {
349
 
            node = _ipmi_fru_node_alloc(rec->fru);
350
 
            if (!node)
351
 
                return ENOMEM;
352
 
            ipmi_fru_get_node(rnode);
353
 
            _ipmi_fru_node_set_data(node, rec);
354
 
            _ipmi_fru_node_set_data2(node, rnode);
355
 
            _ipmi_fru_node_set_get_field(node, atca_p2p_desc_array_get_field);
356
 
            _ipmi_fru_node_set_destructor(node, atca_p2p_sub_destroy);
357
 
            *sub_node = node;
358
 
        }
359
 
        break;
360
 
 
361
 
    default:
362
 
        rv = EINVAL;
363
 
    }
364
 
 
365
 
    return rv;
366
 
}
367
 
 
368
 
static int
369
 
atca_root_mr_p2p_cr(ipmi_fru_t          *fru,
370
 
                    unsigned char       *mr_data,
371
 
                    unsigned int        mr_data_len,
372
 
                    const char          **name,
373
 
                    ipmi_fru_node_t     **rnode)
374
 
{
375
 
    atca_p2p_cr_t      *rec;
376
 
    atca_p2p_cr_desc_t *drec;
377
 
    unsigned int       left;
378
 
    unsigned char      *p;
379
 
    int                i, j;
380
 
    ipmi_fru_node_t    *node;
381
 
    int                rv;
382
 
 
383
 
    mr_data += 4;
384
 
    mr_data_len -= 4;
385
 
 
386
 
    if (mr_data_len == 0)
387
 
        return EINVAL;
388
 
    
389
 
    if (mr_data[0] != 0) /* Only support version 0 */
390
 
        return ENOSYS;
391
 
 
392
 
    rec = ipmi_mem_alloc(sizeof(*rec));
393
 
    if (!rec)
394
 
        return ENOMEM;
395
 
    memset(rec, 0, sizeof(*rec));
396
 
 
397
 
    rec->version = mr_data[0];
398
 
    mr_data++;
399
 
    mr_data_len--;
400
 
 
401
 
    left = mr_data_len;
402
 
    p = mr_data;
403
 
    while (left > 0) {
404
 
        if (left < 3)
405
 
            goto out_invalid;
406
 
        left -= 3;
407
 
        if ((unsigned int) (p[2] * 3) > left)
408
 
            goto out_invalid;
409
 
        left -= p[2] * 3;
410
 
        p += 3 + (p[2] * 3);
411
 
        (rec->desc_count)++;
412
 
    }
413
 
    rec->descs = ipmi_mem_alloc(sizeof(atca_p2p_cr_desc_t) * rec->desc_count);
414
 
    if (!rec->descs)
415
 
        goto out_no_mem;
416
 
    memset(rec->descs, 0, sizeof(atca_p2p_cr_desc_t) * rec->desc_count);
417
 
 
418
 
    left = mr_data_len;
419
 
    p = mr_data;
420
 
    i = 0;
421
 
    while (left > 0) {
422
 
        drec = &(rec->descs[i]);
423
 
        drec->channel_type = p[0];
424
 
        drec->slot_address = p[1];
425
 
        drec->channel_count = p[2];
426
 
        drec->chans = ipmi_mem_alloc(sizeof(uint32_t) * p[2]);
427
 
        if (!drec->chans)
428
 
            goto out_no_mem;
429
 
        p += 3;
430
 
        left -= 3;
431
 
        for (j=0; j<drec->channel_count; j++) {
432
 
            drec->chans[j] = p[0] | (p[1] << 8) | (p[2] << 16);
433
 
            p += 3;
434
 
            left -= 3;
435
 
        }
436
 
        i++;
437
 
    }
438
 
 
439
 
    node = _ipmi_fru_node_alloc(fru);
440
 
    if (!node)
441
 
      goto out_no_mem;
442
 
 
443
 
    rec->fru = fru;
444
 
    ipmi_fru_ref(fru);
445
 
 
446
 
    _ipmi_fru_node_set_data(node, rec);
447
 
    _ipmi_fru_node_set_get_field(node, atca_p2p_root_get_field);
448
 
    _ipmi_fru_node_set_destructor(node, atca_p2p_root_destroy);
449
 
 
450
 
    *rnode = node;
451
 
 
452
 
    if (name)
453
 
        *name = "Point-to-Point Connectivity Record";
454
 
 
455
 
    return 0;
456
 
 
457
 
 out_invalid:
458
 
    rv = EINVAL;
459
 
    goto out_cleanup;
460
 
 
461
 
 out_no_mem:
462
 
    rv = ENOMEM;
463
 
    goto out_cleanup;
464
 
 
465
 
 out_cleanup:
466
 
    atca_p2p_cleanup_rec(rec);
467
 
    return rv;
468
 
}
469
 
 
470
 
typedef struct atca_addr_tab_desc_s
471
 
{
472
 
    unsigned char hw_addr;
473
 
    unsigned char site_number;
474
 
    unsigned char site_type;
475
 
} atca_addr_tab_desc_t;
476
 
 
477
 
typedef struct atca_addr_tab_s
478
 
{
479
 
    unsigned char        version;
480
 
    unsigned int         shelf_addr_len;
481
 
    enum ipmi_str_type_e shelf_addr_type;
482
 
    char                 shelf_addr[64];
483
 
    unsigned char        addr_count;
484
 
    atca_addr_tab_desc_t *addrs;
485
 
    ipmi_fru_t           *fru;
486
 
} atca_addr_tab_t;
487
 
 
488
 
static void atca_addr_tab_cleanup_rec(atca_addr_tab_t *rec)
489
 
{
490
 
    if (rec->addrs)
491
 
        ipmi_mem_free(rec->addrs);
492
 
    ipmi_mem_free(rec);
493
 
}
494
 
 
495
 
static void
496
 
atca_addr_tab_root_destroy(ipmi_fru_node_t *node)
497
 
{
498
 
    atca_addr_tab_t *rec = _ipmi_fru_node_get_data(node);
499
 
    ipmi_fru_deref(rec->fru);
500
 
    atca_addr_tab_cleanup_rec(rec);
501
 
}
502
 
 
503
 
static void
504
 
atca_addr_tab_sub_destroy(ipmi_fru_node_t *node)
505
 
{
506
 
    ipmi_fru_node_t *root_node = _ipmi_fru_node_get_data2(node);
507
 
    ipmi_fru_put_node(root_node);
508
 
}
509
 
 
510
 
static int
511
 
atca_addr_tab_desc_get_field(ipmi_fru_node_t           *pnode,
512
 
                             unsigned int              index,
513
 
                             const char                **name,
514
 
                             enum ipmi_fru_data_type_e *dtype,
515
 
                             int                       *intval,
516
 
                             time_t                    *time,
517
 
                             double                    *floatval,
518
 
                             char                      **data,
519
 
                             unsigned int              *data_len,
520
 
                             ipmi_fru_node_t           **sub_node)
521
 
{
522
 
    atca_addr_tab_desc_t *rec = _ipmi_fru_node_get_data(pnode);
523
 
    int                  rv = 0;
524
 
 
525
 
    switch(index) {
526
 
    case 0:
527
 
        rv = convert_int_to_fru_int("hardware address", rec->hw_addr,
528
 
                                    name, dtype, intval);
529
 
        break;
530
 
 
531
 
    case 1:
532
 
        rv = convert_int_to_fru_int("site number", rec->site_number,
533
 
                                    name, dtype, intval);
534
 
        break;
535
 
 
536
 
    case 2:
537
 
        rv = convert_int_to_fru_int("site type", rec->site_type,
538
 
                                    name, dtype, intval);
539
 
        break;
540
 
 
541
 
    default:
542
 
        rv = EINVAL;
543
 
    }
544
 
 
545
 
    return rv;
546
 
}
547
 
 
548
 
static int
549
 
atca_addr_tab_desc_array_get_field(ipmi_fru_node_t           *pnode,
550
 
                                   unsigned int              index,
551
 
                                   const char                **name,
552
 
                                   enum ipmi_fru_data_type_e *dtype,
553
 
                                   int                       *intval,
554
 
                                   time_t                    *time,
555
 
                                   double                    *floatval,
556
 
                                   char                      **data,
557
 
                                   unsigned int              *data_len,
558
 
                                   ipmi_fru_node_t           **sub_node)
559
 
{
560
 
    atca_addr_tab_t *rec = _ipmi_fru_node_get_data(pnode);
561
 
    ipmi_fru_node_t *rnode = _ipmi_fru_node_get_data2(pnode);
562
 
    atca_addr_tab_t *rrec = _ipmi_fru_node_get_data(rnode);
563
 
    ipmi_fru_node_t *node;
564
 
 
565
 
    if (index >= rec->addr_count)
566
 
        return EINVAL;
567
 
 
568
 
    if (name)
569
 
        *name = NULL; /* We are an array */
570
 
    if (dtype)
571
 
        *dtype = IPMI_FRU_DATA_SUB_NODE;
572
 
    if (intval)
573
 
        *intval = -1; /* Sub element is not an array */
574
 
    if (sub_node) {
575
 
        node = _ipmi_fru_node_alloc(rrec->fru);
576
 
        if (!node)
577
 
            return ENOMEM;
578
 
 
579
 
        ipmi_fru_get_node(rnode);
580
 
        _ipmi_fru_node_set_data(node, rec->addrs + index);
581
 
        _ipmi_fru_node_set_data2(node, rnode);
582
 
        _ipmi_fru_node_set_get_field(node, atca_addr_tab_desc_get_field);
583
 
        _ipmi_fru_node_set_destructor(node, atca_addr_tab_sub_destroy);
584
 
        *sub_node = node;
585
 
    }
586
 
    return 0;
587
 
}
588
 
 
589
 
static int
590
 
atca_addr_tab_root_get_field(ipmi_fru_node_t           *rnode,
591
 
                             unsigned int              index,
592
 
                             const char                **name,
593
 
                             enum ipmi_fru_data_type_e *dtype,
594
 
                             int                       *intval,
595
 
                             time_t                    *time,
596
 
                             double                    *floatval,
597
 
                             char                      **data,
598
 
                             unsigned int              *data_len,
599
 
                             ipmi_fru_node_t           **sub_node)
600
 
{
601
 
    atca_addr_tab_t *rec = _ipmi_fru_node_get_data(rnode);
602
 
    ipmi_fru_node_t *node;
603
 
    int             rv = 0;
604
 
 
605
 
    switch(index) {
606
 
    case 0:
607
 
        rv = convert_int_to_fru_int("version", rec->version,
608
 
                                    name, dtype, intval);
609
 
        break;
610
 
 
611
 
    case 1:
612
 
        rv = convert_str_to_fru_str("shelf address", rec->shelf_addr_type,
613
 
                                    rec->shelf_addr_len,
614
 
                                    rec->shelf_addr,
615
 
                                    name, dtype, intval, data);
616
 
        break;
617
 
 
618
 
    case 2:
619
 
        if (name)
620
 
            *name = "addresses";
621
 
        if (dtype)
622
 
            *dtype = IPMI_FRU_DATA_SUB_NODE;
623
 
        if (intval)
624
 
            *intval = rec->addr_count;
625
 
        if (sub_node) {
626
 
            node = _ipmi_fru_node_alloc(rec->fru);
627
 
            if (!node)
628
 
                return ENOMEM;
629
 
            ipmi_fru_get_node(rnode);
630
 
            _ipmi_fru_node_set_data(node, rec);
631
 
            _ipmi_fru_node_set_data2(node, rnode);
632
 
            _ipmi_fru_node_set_get_field(node,
633
 
                                         atca_addr_tab_desc_array_get_field);
634
 
            _ipmi_fru_node_set_destructor(node, atca_addr_tab_sub_destroy);
635
 
            *sub_node = node;
636
 
        }
637
 
        break;
638
 
 
639
 
    default:
640
 
        rv = EINVAL;
641
 
    }
642
 
 
643
 
    return rv;
644
 
}
645
 
 
646
 
static int
647
 
atca_root_mr_addr_tab(ipmi_fru_t          *fru,
648
 
                      unsigned char       *mr_data,
649
 
                      unsigned int        mr_data_len,
650
 
                      const char          **name,
651
 
                      ipmi_fru_node_t     **rnode)
652
 
{
653
 
    atca_addr_tab_t      *rec;
654
 
    unsigned char        *p;
655
 
    int                  i;
656
 
    ipmi_fru_node_t      *node;
657
 
    int                  rv;
658
 
 
659
 
    mr_data += 4;
660
 
    mr_data_len -= 4;
661
 
 
662
 
    /* Room for the version, shelf address, and address table entry count */
663
 
    if (mr_data_len < 23)
664
 
        return EINVAL;
665
 
    
666
 
    if (mr_data[0] != 0) /* Only support version 0 */
667
 
        return ENOSYS;
668
 
 
669
 
    rec = ipmi_mem_alloc(sizeof(*rec));
670
 
    if (!rec)
671
 
        return ENOMEM;
672
 
    memset(rec, 0, sizeof(*rec));
673
 
 
674
 
    rec->version = mr_data[0];
675
 
    mr_data++;
676
 
    mr_data_len--;
677
 
 
678
 
    p = mr_data;
679
 
    rv = ipmi_get_device_string(&p, mr_data_len,
680
 
                                rec->shelf_addr,
681
 
                                IPMI_STR_FRU_SEMANTICS, 0,
682
 
                                &rec->shelf_addr_type,
683
 
                                sizeof(rec->shelf_addr),
684
 
                                &rec->shelf_addr_len);
685
 
    if (rv)
686
 
        return rv;
687
 
    if ((p - mr_data) > 21)
688
 
        return EINVAL;
689
 
    mr_data += 21;
690
 
    mr_data_len -= 21;
691
 
 
692
 
    rec->addr_count = mr_data[0];
693
 
    mr_data++;
694
 
    mr_data_len--;
695
 
 
696
 
    if ((unsigned int) (rec->addr_count * 3) > mr_data_len)
697
 
        goto out_invalid;
698
 
 
699
 
    rec->addrs = ipmi_mem_alloc(sizeof(*(rec->addrs)) * rec->addr_count);
700
 
    if (!rec->addrs)
701
 
        goto out_no_mem;
702
 
 
703
 
    for (i=0; i<rec->addr_count; i++) {
704
 
        rec->addrs[i].hw_addr = mr_data[0];
705
 
        rec->addrs[i].site_number = mr_data[1];
706
 
        rec->addrs[i].site_type = mr_data[2];
707
 
        mr_data += 3;
708
 
        mr_data_len -= 3;
709
 
    }
710
 
 
711
 
    node = _ipmi_fru_node_alloc(fru);
712
 
    if (!node)
713
 
        goto out_no_mem;
714
 
 
715
 
    rec->fru = fru;
716
 
    ipmi_fru_ref(fru);
717
 
 
718
 
    _ipmi_fru_node_set_data(node, rec);
719
 
    _ipmi_fru_node_set_get_field(node, atca_addr_tab_root_get_field);
720
 
    _ipmi_fru_node_set_destructor(node, atca_addr_tab_root_destroy);
721
 
    *rnode = node;
722
 
 
723
 
    if (name)
724
 
        *name = "Address Table";
725
 
 
726
 
    return 0;
727
 
 
728
 
 out_invalid:
729
 
    rv = EINVAL;
730
 
    goto out_cleanup;
731
 
 
732
 
 out_no_mem:
733
 
    rv = ENOMEM;
734
 
    goto out_cleanup;
735
 
 
736
 
 out_cleanup:
737
 
    atca_addr_tab_cleanup_rec(rec);
738
 
    return rv;
739
 
}
 
37
 * Point-to-point connectivity record
 
38
 *
 
39
 **********************************************************************/
 
40
 
 
41
static ipmi_mr_item_layout_t p2p_cr_desc_ent_items[] = {
 
42
    { .name = "remote slot", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
43
      .start = 0, .length = 8,
 
44
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
45
    { .name = "remote channel", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
46
      .start = 8, .length = 5,
 
47
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
48
    { .name = "local channel ", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
49
      .start = 13, .length = 5,
 
50
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field }
 
51
};
 
52
static ipmi_mr_struct_layout_t p2p_cr_desc_ent = {
 
53
    .name = NULL, .length = 3,
 
54
    .item_count = 3, .items = p2p_cr_desc_ent_items,
 
55
    .array_count = 0, .arrays = NULL,
 
56
    .cleanup = ipmi_mr_struct_cleanup
 
57
};
 
58
static ipmi_mr_item_layout_t p2p_cr_desc_items[] = {
 
59
    { .name = "channel type", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
60
      .start = 0, .length = 1,
 
61
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
62
    { .name = "slot address", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
63
      .start = 1, .length = 1,
 
64
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field }
 
65
};
 
66
static ipmi_mr_array_layout_t p2p_cr_desc_arys[] = {
 
67
    { .name = "channels", .has_count = 1, .min_elem_size = 3, .settable = 1,
 
68
      .elem_layout = &p2p_cr_desc_ent,
 
69
      .elem_check = ipmi_mr_struct_elem_check,
 
70
      .elem_decode = ipmi_mr_struct_decode,
 
71
      .cleanup = ipmi_mr_struct_array_cleanup,
 
72
      .get_field = ipmi_mr_struct_array_get_field,
 
73
      .set_field = ipmi_mr_struct_array_set_field }
 
74
};
 
75
static ipmi_mr_struct_layout_t p2p_cr_desc = {
 
76
    .name = NULL, .length = 2,
 
77
    .item_count = 2, .items = p2p_cr_desc_items,
 
78
    .array_count = 1, .arrays = p2p_cr_desc_arys,
 
79
    .cleanup = ipmi_mr_struct_cleanup
 
80
};
 
81
static ipmi_mr_item_layout_t p2p_cr_items[] = {
 
82
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
83
      .start = 0, .length = 1,
 
84
      .set_field = NULL, .get_field = ipmi_mr_int_get_field }
 
85
};
 
86
static ipmi_mr_array_layout_t p2p_cr_arys[] = {
 
87
    { .name = "descriptors", .has_count = 0, .min_elem_size = 3, .settable = 1,
 
88
      .elem_layout = &p2p_cr_desc,
 
89
      .elem_check = ipmi_mr_struct_elem_check, .elem_decode = ipmi_mr_struct_decode,
 
90
      .cleanup = ipmi_mr_struct_array_cleanup,
 
91
      .get_field = ipmi_mr_struct_array_get_field,
 
92
      .set_field = ipmi_mr_struct_array_set_field }
 
93
};
 
94
static ipmi_mr_struct_layout_t p2p_cr = {
 
95
    .name = "Point-to-Point Connectivity Record", .length = 1,
 
96
    .item_count = 1, .items = p2p_cr_items,
 
97
    .array_count = 1, .arrays = p2p_cr_arys,
 
98
    .cleanup = ipmi_mr_struct_cleanup
 
99
};
 
100
 
 
101
 
 
102
/***********************************************************************
 
103
 *
 
104
 * Address table descriptor record
 
105
 *
 
106
 **********************************************************************/
 
107
 
 
108
static ipmi_mr_item_layout_t addr_tab_ent[] = {
 
109
    { .name = "hardware address", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
110
      .start = 0, .length = 1,
 
111
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
112
    { .name = "site_number", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
113
      .start = 1, .length = 1,
 
114
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
115
    { .name = "site_type", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
116
      .start = 2, .length = 1,
 
117
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field }
 
118
};
 
119
static ipmi_mr_struct_layout_t addr_tab_ents = {
 
120
    .name = NULL, .length = 3,
 
121
    .item_count = 3, .items = addr_tab_ent,
 
122
    .array_count = 0, .arrays = NULL,
 
123
    .cleanup = ipmi_mr_struct_cleanup
 
124
};
 
125
static ipmi_mr_item_layout_t addr_tab_items[] = {
 
126
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
127
      .start = 0, .length = 1,
 
128
      .set_field = NULL, .get_field = ipmi_mr_int_get_field },
 
129
    { .name = "shelf address", .dtype = IPMI_FRU_DATA_ASCII, .settable = 1,
 
130
      .start = 1, .length = 21,
 
131
      .set_field = ipmi_mr_str_set_field, .get_field = ipmi_mr_str_get_field },
 
132
};
 
133
static ipmi_mr_array_layout_t addr_tab_arys[] = {
 
134
    { .name = "addresses", .has_count = 1, .min_elem_size = 3, .settable = 1,
 
135
      .elem_layout = &addr_tab_ents,
 
136
      .elem_check = ipmi_mr_struct_elem_check, .elem_decode = ipmi_mr_struct_decode,
 
137
      .cleanup = ipmi_mr_struct_array_cleanup,
 
138
      .get_field = ipmi_mr_struct_array_get_field,
 
139
      .set_field = ipmi_mr_struct_array_set_field }
 
140
};
 
141
static ipmi_mr_struct_layout_t addr_tab = {
 
142
    .name = "Address Table", .length = 22,
 
143
    .item_count = 2, .items = addr_tab_items,
 
144
    .array_count = 1, .arrays = addr_tab_arys,
 
145
    .cleanup = ipmi_mr_struct_cleanup
 
146
};
 
147
 
 
148
 
 
149
/***********************************************************************
 
150
 *
 
151
 * Shelf power distribution record
 
152
 *
 
153
 **********************************************************************/
 
154
 
 
155
static ipmi_mr_item_layout_t pow_dist_f2f_items[] = {
 
156
    { .name = "hardware address", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
157
      .start = 0, .length = 1,
 
158
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
159
    { .name = "FRU device id", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
160
      .start = 1, .length = 1,
 
161
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field }
 
162
};
 
163
static ipmi_mr_struct_layout_t pow_dist_f2f = {
 
164
    .name = NULL, .length = 2,
 
165
    .item_count = 2, .items = pow_dist_f2f_items,
 
166
    .array_count = 0, .arrays = NULL,
 
167
    .cleanup = ipmi_mr_struct_cleanup
 
168
};
 
169
static ipmi_mr_item_layout_t pow_dist_maps_items[] = {
 
170
    { .name = "max extern avail current", .dtype = IPMI_FRU_DATA_FLOAT,
 
171
      .settable = 1,
 
172
      .start = 0, .length = 2,
 
173
      .u.multiplier = 0.1,
 
174
      .set_field = ipmi_mr_intfloat_set_field,
 
175
      .get_field = ipmi_mr_intfloat_get_field },
 
176
    { .name = "max internal current", .dtype = IPMI_FRU_DATA_FLOAT,
 
177
      .settable = 1,
 
178
      .start = 2, .length = 2,
 
179
      .u.multiplier = 0.1,
 
180
      .set_field = ipmi_mr_intfloat_set_field,
 
181
      .get_field = ipmi_mr_intfloat_get_field },
 
182
    { .name = "min operating voltage", .dtype = IPMI_FRU_DATA_FLOAT,
 
183
      .settable = 1,
 
184
      .start = 2, .length = 2,
 
185
      .u.multiplier = 0.5,
 
186
      .set_field = ipmi_mr_intfloat_set_field,
 
187
      .get_field = ipmi_mr_intfloat_get_field }
 
188
};
 
189
static ipmi_mr_array_layout_t pow_dist_maps_arys[] = {
 
190
    { .name = "feed to frus", .has_count = 1, .min_elem_size = 6,
 
191
      .settable = 1,
 
192
      .elem_layout = &pow_dist_f2f,
 
193
      .elem_check = ipmi_mr_struct_elem_check,
 
194
      .elem_decode = ipmi_mr_struct_decode,
 
195
      .cleanup = ipmi_mr_struct_array_cleanup,
 
196
      .get_field = ipmi_mr_struct_array_get_field,
 
197
      .set_field = ipmi_mr_struct_array_set_field }
 
198
};
 
199
static ipmi_mr_struct_layout_t pow_dist_maps = {
 
200
    .name = NULL, .length = 5,
 
201
    .item_count = 3, .items = pow_dist_maps_items,
 
202
    .array_count = 1, .arrays = pow_dist_maps_arys,
 
203
    .cleanup = ipmi_mr_struct_cleanup
 
204
};
 
205
static ipmi_mr_item_layout_t pow_dist_items[] = {
 
206
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
207
      .start = 0, .length = 1,
 
208
      .set_field = NULL, .get_field = ipmi_mr_int_get_field }
 
209
};
 
210
static ipmi_mr_array_layout_t pow_dist_arys[] = {
 
211
    { .name = "power feeds", .has_count = 1, .min_elem_size = 3, .settable = 1,
 
212
      .elem_layout = &pow_dist_maps,
 
213
      .elem_check = ipmi_mr_struct_elem_check,
 
214
      .elem_decode = ipmi_mr_struct_decode,
 
215
      .cleanup = ipmi_mr_struct_array_cleanup,
 
216
      .get_field = ipmi_mr_struct_array_get_field,
 
217
      .set_field = ipmi_mr_struct_array_set_field }
 
218
};
 
219
static ipmi_mr_struct_layout_t pow_dist = {
 
220
    .name = "Shelf Power Distribution", .length = 1,
 
221
    .item_count = 1, .items = pow_dist_items,
 
222
    .array_count = 1, .arrays = pow_dist_arys,
 
223
    .cleanup = ipmi_mr_struct_cleanup
 
224
};
 
225
 
 
226
 
 
227
/***********************************************************************
 
228
 *
 
229
 * Shelf activation and power management record
 
230
 *
 
231
 **********************************************************************/
 
232
 
 
233
static ipmi_mr_item_layout_t act_pm_desc[] = {
 
234
    { .name = "hardware address", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
235
      .start = 0, .length = 1,
 
236
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
237
    { .name = "FRU device id", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
238
      .start = 1, .length = 1,
 
239
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
240
    { .name = "max FRU power", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
241
      .start = 2, .length = 2,
 
242
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
243
    { .name = "shelf manager activation", .dtype = IPMI_FRU_DATA_BOOLEAN,
 
244
      .settable = 1,
 
245
      .start = 38, .length = 1,
 
246
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
247
    { .name = "delay before next power on", .dtype = IPMI_FRU_DATA_INT,
 
248
      .settable = 1,
 
249
      .start = 32, .length = 6,
 
250
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field }
 
251
};
 
252
static ipmi_mr_struct_layout_t act_pm_descs = {
 
253
    .name = NULL, .length = 5,
 
254
    .item_count = 5, .items = act_pm_desc,
 
255
    .array_count = 0, .arrays = NULL,
 
256
    .cleanup = ipmi_mr_struct_cleanup
 
257
};
 
258
static ipmi_mr_item_layout_t act_pm_items[] = {
 
259
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
260
      .start = 0, .length = 1,
 
261
      .set_field = NULL, .get_field = ipmi_mr_int_get_field },
 
262
    { .name = "allowance for activation readiness", .dtype = IPMI_FRU_DATA_INT,
 
263
      .settable = 1,
 
264
      .start = 1, .length = 1,
 
265
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field }
 
266
};
 
267
static ipmi_mr_array_layout_t act_pm_arys[] = {
 
268
    { .name = "activation power descriptors", .has_count = 1, .settable = 1,
 
269
      .min_elem_size = 5,
 
270
      .elem_layout = &act_pm_descs,
 
271
      .elem_check = ipmi_mr_struct_elem_check, .elem_decode = ipmi_mr_struct_decode,
 
272
      .cleanup = ipmi_mr_struct_array_cleanup,
 
273
      .get_field = ipmi_mr_struct_array_get_field,
 
274
      .set_field = ipmi_mr_struct_array_set_field }
 
275
};
 
276
static ipmi_mr_struct_layout_t act_pm = {
 
277
    .name = "Shelf Activation and Power Management", .length = 2,
 
278
    .item_count = 1, .items = act_pm_items,
 
279
    .array_count = 1, .arrays = act_pm_arys,
 
280
    .cleanup = ipmi_mr_struct_cleanup
 
281
};
 
282
 
 
283
 
 
284
/***********************************************************************
 
285
 *
 
286
 * Shelf manager IP connection record
 
287
 *
 
288
 **********************************************************************/
 
289
 
 
290
static ipmi_mr_item_layout_t ip_conn0_items[] = {
 
291
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
292
      .start = 0, .length = 1,
 
293
      .set_field = NULL, .get_field = ipmi_mr_int_get_field },
 
294
    { .name = "ip address", .dtype = IPMI_FRU_DATA_ASCII,
 
295
      .settable = 1,
 
296
      .start = 1, .length = 4,
 
297
      .set_field = ipmi_mr_ip_set_field, .get_field = ipmi_mr_ip_get_field }
 
298
};
 
299
static ipmi_mr_struct_layout_t ip_conn0 = {
 
300
    .name = "Shelf Manager IP Connection", .length = 5,
 
301
    .item_count = 2, .items = ip_conn0_items,
 
302
    .array_count = 0, .arrays = NULL,
 
303
    .cleanup = ipmi_mr_struct_cleanup
 
304
};
 
305
 
 
306
static ipmi_mr_item_layout_t ip_conn1_items[] = {
 
307
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
308
      .start = 0, .length = 1,
 
309
      .set_field = NULL, .get_field = ipmi_mr_int_get_field },
 
310
    { .name = "ip address", .dtype = IPMI_FRU_DATA_ASCII,
 
311
      .settable = 1,
 
312
      .start = 1, .length = 4,
 
313
      .set_field = ipmi_mr_ip_set_field, .get_field = ipmi_mr_ip_get_field },
 
314
    { .name = "gateway address", .dtype = IPMI_FRU_DATA_ASCII,
 
315
      .settable = 1,
 
316
      .start = 5, .length = 4,
 
317
      .set_field = ipmi_mr_ip_set_field, .get_field = ipmi_mr_ip_get_field },
 
318
    { .name = "subnet mask", .dtype = IPMI_FRU_DATA_ASCII,
 
319
      .settable = 1,
 
320
      .start = 9, .length = 4,
 
321
      .set_field = ipmi_mr_ip_set_field, .get_field = ipmi_mr_ip_get_field }
 
322
};
 
323
static ipmi_mr_struct_layout_t ip_conn1 = {
 
324
    .name = "Shelf Manager IP Connection", .length = 13,
 
325
    .item_count = 4, .items = ip_conn1_items,
 
326
    .array_count = 0, .arrays = NULL,
 
327
    .cleanup = ipmi_mr_struct_cleanup
 
328
};
 
329
 
 
330
static int
 
331
atca_root_ipmi_mr_shelf_mgr_ip_conn(ipmi_fru_t          *fru,
 
332
                               unsigned int        mr_rec_num,
 
333
                               unsigned char       *mr_data,
 
334
                               unsigned int        mr_data_len,
 
335
                               const char          **name,
 
336
                               ipmi_fru_node_t     **node)
 
337
{
 
338
    ipmi_mr_struct_layout_t *layout;
 
339
 
 
340
    if (mr_data_len < 5)
 
341
        return EINVAL;
 
342
    switch (mr_data[4]) {
 
343
    case 0: layout = &ip_conn0; break;
 
344
    case 1: layout = &ip_conn1; break;
 
345
    default:
 
346
        return EINVAL;
 
347
    }
 
348
    return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
349
                               layout, name, node);
 
350
}
 
351
 
 
352
/***********************************************************************
 
353
 *
 
354
 * Board point-to-point Connectivity record
 
355
 *
 
356
 **********************************************************************/
 
357
 
 
358
static ipmi_mr_item_layout_t guid_elem = {
 
359
    .name = "GUID", .dtype = IPMI_FRU_DATA_BINARY, .settable = 1,
 
360
    .start = 0, .length = 16,
 
361
    .set_field = ipmi_mr_binary_set_field,
 
362
    .get_field = ipmi_mr_binary_get_field
 
363
};
 
364
static ipmi_mr_tab_item_t link_if_tab = {
 
365
    .count = 3,
 
366
    .table = { "base", "fabric", "update channel" }
 
367
};
 
368
static ipmi_mr_item_layout_t link_desc[] = {
 
369
    { .name = "link grouping id", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
370
      .start = 24, .length = 8,
 
371
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
372
    { .name = "link type extension", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
373
      .start = 20, .length = 4,
 
374
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
375
    { .name = "link type", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
376
      .start = 12, .length = 8,
 
377
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
378
    { .name = "port 3 included", .dtype = IPMI_FRU_DATA_BOOLEAN, .settable = 1,
 
379
      .start = 11, .length = 1,
 
380
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
381
    { .name = "port 2 included", .dtype = IPMI_FRU_DATA_BOOLEAN, .settable = 1,
 
382
      .start = 10, .length = 1,
 
383
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
384
    { .name = "port 1 included", .dtype = IPMI_FRU_DATA_BOOLEAN, .settable = 1,
 
385
      .start = 9, .length = 1,
 
386
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
387
    { .name = "port 0 included", .dtype = IPMI_FRU_DATA_BOOLEAN, .settable = 1,
 
388
      .start = 8, .length = 1,
 
389
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field },
 
390
    { .name = "interface", .dtype = IPMI_FRU_DATA_ASCII, .settable = 1,
 
391
      .start = 6, .length = 2,
 
392
      .u.tab_data = &link_if_tab,
 
393
      .set_field = ipmi_mr_bitvaltab_set_field,
 
394
      .get_field = ipmi_mr_bitvaltab_get_field,
 
395
      .get_enum  = ipmi_mr_bitvaltab_get_enum },
 
396
    { .name = "channel number", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
397
      .start = 0, .length = 6,
 
398
      .set_field = ipmi_mr_bitint_set_field, .get_field = ipmi_mr_bitint_get_field }
 
399
};
 
400
static ipmi_mr_struct_layout_t link_descs = {
 
401
    .name = NULL, .length = 4,
 
402
    .item_count = 9, .items = link_desc,
 
403
    .array_count = 0, .arrays = NULL,
 
404
    .cleanup = ipmi_mr_struct_cleanup
 
405
};
 
406
static ipmi_mr_item_layout_t bp2p_conn_items[] = {
 
407
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
408
      .start = 0, .length = 1,
 
409
      .set_field = NULL, .get_field = ipmi_mr_int_get_field }
 
410
};
 
411
static ipmi_mr_array_layout_t bp2p_conn_arys[] = {
 
412
    { .name = "OEM GUIDs", .has_count = 1, .settable = 1,
 
413
      .min_elem_size = 16,
 
414
      .elem_layout = &guid_elem,
 
415
      .elem_check = ipmi_mr_item_elem_check,
 
416
      .elem_decode = ipmi_mr_item_decode,
 
417
      .cleanup = ipmi_mr_item_array_cleanup,
 
418
      .get_field = ipmi_mr_item_array_get_field,
 
419
      .set_field = ipmi_mr_item_array_set_field },
 
420
    { .name = "Link Descriptors", .has_count = 0,
 
421
      .min_elem_size = 4,
 
422
      .elem_layout = &link_descs,
 
423
      .elem_check = ipmi_mr_struct_elem_check,
 
424
      .elem_decode = ipmi_mr_struct_decode,
 
425
      .cleanup = ipmi_mr_struct_array_cleanup,
 
426
      .get_field = ipmi_mr_struct_array_get_field,
 
427
      .set_field = ipmi_mr_struct_array_set_field }
 
428
};
 
429
static ipmi_mr_struct_layout_t bp2p_conn = {
 
430
    .name = "Board P2P Connectivity", .length = 1,
 
431
    .item_count = 1, .items = bp2p_conn_items,
 
432
    .array_count = 2, .arrays = bp2p_conn_arys,
 
433
    .cleanup = ipmi_mr_struct_cleanup
 
434
};
 
435
 
 
436
 
 
437
/***********************************************************************
 
438
 *
 
439
 * Radial IPMB-0 Link Mapping
 
440
 *
 
441
 **********************************************************************/
 
442
 
 
443
static ipmi_mr_item_layout_t ipmb_link_mapping[] = {
 
444
    { .name = "hardware address", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
445
      .start = 0, .length = 1,
 
446
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
447
    { .name = "IPMB-0 link entry", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
448
      .start = 1, .length = 1,
 
449
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field }
 
450
};
 
451
static ipmi_mr_struct_layout_t ipmb_link_mappings = {
 
452
    .name = NULL, .length = 2,
 
453
    .item_count = 2, .items = ipmb_link_mapping,
 
454
    .array_count = 0, .arrays = NULL,
 
455
    .cleanup = ipmi_mr_struct_cleanup
 
456
};
 
457
static ipmi_mr_tab_item_t hub_info_if_tab = {
 
458
    .count = 4,
 
459
    .table = { NULL, "IPMB-A only", "IPMB-B only", "IPMB-A and IPMB-B" }
 
460
};
 
461
static ipmi_mr_item_layout_t hub_desc_items[] = {
 
462
    { .name = "hardware address", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
463
      .start = 0, .length = 1,
 
464
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
465
    { .name = "bus coverage", .dtype = IPMI_FRU_DATA_ASCII, .settable = 1,
 
466
      .start = 8, .length = 2,
 
467
      .u.tab_data = &hub_info_if_tab,
 
468
      .set_field = ipmi_mr_bitvaltab_set_field,
 
469
      .get_field = ipmi_mr_bitvaltab_get_field,
 
470
      .get_enum  = ipmi_mr_bitvaltab_get_enum }
 
471
};
 
472
static ipmi_mr_array_layout_t hub_desc_arys[] = {
 
473
    { .name = "IPMB-0 link mappings", .has_count = 1, .settable = 1,
 
474
      .min_elem_size = 4,
 
475
      .elem_layout = &ipmb_link_mappings,
 
476
      .elem_check = ipmi_mr_struct_elem_check,
 
477
      .elem_decode = ipmi_mr_struct_decode,
 
478
      .cleanup = ipmi_mr_struct_array_cleanup,
 
479
      .get_field = ipmi_mr_struct_array_get_field,
 
480
      .set_field = ipmi_mr_struct_array_set_field }
 
481
};
 
482
static ipmi_mr_struct_layout_t hub_descs = {
 
483
    .name = NULL, .length = 2,
 
484
    .item_count = 2, .items = hub_desc_items,
 
485
    .array_count = 1, .arrays = hub_desc_arys,
 
486
    .cleanup = ipmi_mr_struct_cleanup
 
487
};
 
488
static ipmi_mr_item_layout_t rad_ipmb_items[] = {
 
489
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
490
      .start = 0, .length = 1,
 
491
      .set_field = NULL, .get_field = ipmi_mr_int_get_field },
 
492
    { .name = "connecter definer", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
493
      .start = 1, .length = 3,
 
494
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
495
    { .name = "connecter version", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
496
      .start = 4, .length = 2,
 
497
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field }
 
498
};
 
499
static ipmi_mr_array_layout_t rad_ipmb_arys[] = {
 
500
    { .name = "hub descriptors", .has_count = 1, .settable = 1,
 
501
      .min_elem_size = 4,
 
502
      .elem_layout = &hub_descs,
 
503
      .elem_check = ipmi_mr_struct_elem_check,
 
504
      .elem_decode = ipmi_mr_struct_decode,
 
505
      .cleanup = ipmi_mr_struct_array_cleanup,
 
506
      .get_field = ipmi_mr_struct_array_get_field,
 
507
      .set_field = ipmi_mr_struct_array_set_field }
 
508
};
 
509
static ipmi_mr_struct_layout_t rad_ipmb = {
 
510
    .name = "Radial IPMB-0 Link Mapping", .length = 6,
 
511
    .item_count = 3, .items = rad_ipmb_items,
 
512
    .array_count = 1, .arrays = rad_ipmb_arys,
 
513
    .cleanup = ipmi_mr_struct_cleanup
 
514
};
 
515
 
 
516
/***********************************************************************
 
517
 *
 
518
 * Shelf fan geography record
 
519
 *
 
520
 **********************************************************************/
 
521
 
 
522
static ipmi_mr_item_layout_t fan_to_frus_items[] = {
 
523
    { .name = "hardware address", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
524
      .start = 0, .length = 1,
 
525
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
526
    { .name = "FRU device id", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
527
      .start = 1, .length = 1,
 
528
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
529
    { .name = "site number", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
530
      .start = 2, .length = 1,
 
531
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field },
 
532
    { .name = "site type", .dtype = IPMI_FRU_DATA_INT, .settable = 1,
 
533
      .start = 3, .length = 1,
 
534
      .set_field = ipmi_mr_int_set_field, .get_field = ipmi_mr_int_get_field }
 
535
};
 
536
static ipmi_mr_struct_layout_t fan_to_frus = {
 
537
    .name = NULL, .length = 4,
 
538
    .item_count = 4, .items = fan_to_frus_items,
 
539
    .array_count = 0, .arrays = NULL,
 
540
    .cleanup = ipmi_mr_struct_cleanup
 
541
};
 
542
static ipmi_mr_item_layout_t fan_geog_items[] = {
 
543
    { .name = "version", .dtype = IPMI_FRU_DATA_INT, .settable = 0,
 
544
      .start = 0, .length = 1,
 
545
      .set_field = NULL, .get_field = ipmi_mr_int_get_field }
 
546
};
 
547
static ipmi_mr_array_layout_t fan_geog_arys[] = {
 
548
    { .name = "fan to frus", .has_count = 1, .settable = 1,
 
549
      .min_elem_size = 4,
 
550
      .elem_layout = &fan_to_frus,
 
551
      .elem_check = ipmi_mr_struct_elem_check,
 
552
      .elem_decode = ipmi_mr_struct_decode,
 
553
      .cleanup = ipmi_mr_struct_array_cleanup,
 
554
      .get_field = ipmi_mr_struct_array_get_field,
 
555
      .set_field = ipmi_mr_struct_array_set_field }
 
556
};
 
557
static ipmi_mr_struct_layout_t fan_geog = {
 
558
    .name = "Shelf Fan Geography", .length = 1,
 
559
    .item_count = 1, .items = fan_geog_items,
 
560
    .array_count = 1, .arrays = fan_geog_arys,
 
561
    .cleanup = ipmi_mr_struct_cleanup
 
562
};
 
563
 
 
564
 
 
565
/***********************************************************************
 
566
 *
 
567
 * Initialization code
 
568
 *
 
569
 **********************************************************************/
740
570
 
741
571
int
742
 
_ipmi_atca_fru_get_mr_root(ipmi_fru_t          *fru,
743
 
                           unsigned int        manufacturer_id,
744
 
                           unsigned char       record_type_id,
745
 
                           unsigned char       *mr_data,
746
 
                           unsigned int        mr_data_len,
747
 
                           void                *cb_data,
748
 
                           const char          **name,
749
 
                           ipmi_fru_node_t     **node)
 
572
_ipmi_atca_fru_get_mr_root(ipmi_fru_t      *fru,
 
573
                           unsigned int    mr_rec_num,
 
574
                           unsigned int    manufacturer_id,
 
575
                           unsigned char   record_type_id,
 
576
                           unsigned char   *mr_data,
 
577
                           unsigned int    mr_data_len,
 
578
                           void            *cb_data,
 
579
                           const char      **name,
 
580
                           ipmi_fru_node_t **node)
750
581
{
751
582
    /* A record type and version number. */
752
583
    if (mr_data_len < 5)
754
585
 
755
586
    switch (mr_data[3]) {
756
587
    case 4: /* backplane point-to-point connectivity record */
757
 
        return atca_root_mr_p2p_cr(fru, mr_data, mr_data_len, name, node);
 
588
        if (mr_data[4] != 0)
 
589
            return EINVAL;
 
590
        return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
591
                                   &p2p_cr,
 
592
                                   name, node);
758
593
 
759
594
    case 0x10: /* shelf address table */
760
 
        return atca_root_mr_addr_tab(fru, mr_data, mr_data_len, name, node);
 
595
        if (mr_data[4] != 0)
 
596
            return EINVAL;
 
597
        return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
598
                                   &addr_tab,
 
599
                                   name, node);
 
600
 
 
601
    case 0x11: /* Shelf power distribution */
 
602
        if (mr_data[4] != 0)
 
603
            return EINVAL;
 
604
        return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
605
                                   &pow_dist,
 
606
                                   name, node);
 
607
 
 
608
    case 0x12: /* Shelf activation and power mgmt */
 
609
        if (mr_data[4] != 0)
 
610
            return EINVAL;
 
611
        return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
612
                                   &act_pm,
 
613
                                   name, node);
 
614
 
 
615
    case 0x13: /* Shelf Manager IP Connection Record */
 
616
        return atca_root_ipmi_mr_shelf_mgr_ip_conn(fru, mr_rec_num,
 
617
                                                   mr_data, mr_data_len,
 
618
                                                   name, node);
 
619
 
 
620
    case 0x14: /* Board p2p connectivity record */
 
621
        if (mr_data[4] != 0)
 
622
            return EINVAL;
 
623
        return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
624
                                   &bp2p_conn,
 
625
                                   name, node);
 
626
 
 
627
    case 0x15: /* radial ipmb0 link mapping */
 
628
        if (mr_data[4] != 0)
 
629
            return EINVAL;
 
630
        return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
631
                                   &rad_ipmb,
 
632
                                   name, node);
 
633
 
 
634
    case 0x1b: /* Shelf fan geography record */
 
635
        if (mr_data[4] != 0)
 
636
            return EINVAL;
 
637
        return ipmi_mr_struct_root(fru, mr_rec_num, mr_data+4, mr_data_len-4,
 
638
                                   &fan_geog,
 
639
                                   name, node);
761
640
 
762
641
    default:
763
642
        return ENOSYS;