1
2
3
4
5
6
7
8
9
10#include <linux/kernel.h>
11#include <linux/moduleparam.h>
12#include <linux/device.h>
13#include <linux/fmc.h>
14#include <linux/fmc-sdb.h>
15
16static int fmc_must_dump_eeprom;
17module_param_named(dump_eeprom, fmc_must_dump_eeprom, int, 0644);
18static int fmc_must_dump_sdb;
19module_param_named(dump_sdb, fmc_must_dump_sdb, int, 0644);
20
21#define LINELEN 16
22
23
24static const uint8_t *dump_line(int addr, const uint8_t *line,
25 const uint8_t *prev)
26{
27 int i;
28
29 if (!prev || memcmp(line, prev, LINELEN)) {
30 pr_info("%04x: ", addr);
31 for (i = 0; i < LINELEN; ) {
32 printk(KERN_CONT "%02x", line[i]);
33 i++;
34 printk(i & 3 ? " " : i & (LINELEN - 1) ? " " : "\n");
35 }
36 return line;
37 }
38
39 if (line == prev + LINELEN)
40 pr_info("[...]\n");
41 return prev;
42}
43
44void fmc_dump_eeprom(const struct fmc_device *fmc)
45{
46 const uint8_t *line, *prev;
47 int i;
48
49 if (!fmc_must_dump_eeprom)
50 return;
51
52 pr_info("FMC: %s (%s), slot %i, device %s\n", dev_name(fmc->hwdev),
53 fmc->carrier_name, fmc->slot_id, dev_name(&fmc->dev));
54 pr_info("FMC: dumping eeprom 0x%x (%i) bytes\n", fmc->eeprom_len,
55 fmc->eeprom_len);
56
57 line = fmc->eeprom;
58 prev = NULL;
59 for (i = 0; i < fmc->eeprom_len; i += LINELEN, line += LINELEN)
60 prev = dump_line(i, line, prev);
61}
62
63void fmc_dump_sdb(const struct fmc_device *fmc)
64{
65 const uint8_t *line, *prev;
66 int i, len;
67
68 if (!fmc->sdb)
69 return;
70 if (!fmc_must_dump_sdb)
71 return;
72
73
74 if (fmc_must_dump_sdb > 0)
75 fmc_show_sdb_tree(fmc);
76
77 if (fmc_must_dump_sdb == 1)
78 return;
79
80
81
82
83
84
85
86
87
88
89
90 pr_info("FMC: %s (%s), slot %i, device %s\n", dev_name(fmc->hwdev),
91 fmc->carrier_name, fmc->slot_id, dev_name(&fmc->dev));
92 pr_info("FMC: poor dump of sdb first level:\n");
93
94 len = fmc->sdb->len * sizeof(union sdb_record);
95 line = (void *)fmc->sdb->record;
96 prev = NULL;
97 for (i = 0; i < len; i += LINELEN, line += LINELEN)
98 prev = dump_line(i, line, prev);
99 return;
100}
101