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);
18
19#define LINELEN 16
20
21
22static const uint8_t *dump_line(int addr, const uint8_t *line,
23 const uint8_t *prev)
24{
25 int i;
26
27 if (!prev || memcmp(line, prev, LINELEN)) {
28 pr_info("%04x: ", addr);
29 for (i = 0; i < LINELEN; ) {
30 printk(KERN_CONT "%02x", line[i]);
31 i++;
32 printk(i & 3 ? " " : i & (LINELEN - 1) ? " " : "\n");
33 }
34 return line;
35 }
36
37 if (line == prev + LINELEN)
38 pr_info("[...]\n");
39 return prev;
40}
41
42void fmc_dump_eeprom(const struct fmc_device *fmc)
43{
44 const uint8_t *line, *prev;
45 int i;
46
47 if (!fmc_must_dump_eeprom)
48 return;
49
50 pr_info("FMC: %s (%s), slot %i, device %s\n", dev_name(fmc->hwdev),
51 fmc->carrier_name, fmc->slot_id, dev_name(&fmc->dev));
52 pr_info("FMC: dumping eeprom 0x%x (%i) bytes\n", fmc->eeprom_len,
53 fmc->eeprom_len);
54
55 line = fmc->eeprom;
56 prev = NULL;
57 for (i = 0; i < fmc->eeprom_len; i += LINELEN, line += LINELEN)
58 prev = dump_line(i, line, prev);
59}
60