2 * Copyright (C) 2013 CERN (www.cern.ch)
3 * Author: Alessandro Rubini <rubini@gnudd.com>
5 * Released according to the GNU GPL, version 2 or any later version.
7 * This work is part of the White Rabbit project, a research effort led
8 * by CERN, the European Institute for Nuclear Research.
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>
16 static int fmc_must_dump_eeprom;
17 module_param_named(dump_eeprom, fmc_must_dump_eeprom, int, 0644);
18 static int fmc_must_dump_sdb;
19 module_param_named(dump_sdb, fmc_must_dump_sdb, int, 0644);
23 /* Dumping 8k takes oh so much: avoid duplicate lines */
24 static const uint8_t *dump_line(int addr, const uint8_t *line,
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]);
34 printk(i & 3 ? " " : i & (LINELEN - 1) ? " " : "\n");
39 if (line == prev + LINELEN)
44 void fmc_dump_eeprom(const struct fmc_device *fmc)
46 const uint8_t *line, *prev;
49 if (!fmc_must_dump_eeprom)
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,
59 for (i = 0; i < fmc->eeprom_len; i += LINELEN, line += LINELEN)
60 prev = dump_line(i, line, prev);
63 void fmc_dump_sdb(const struct fmc_device *fmc)
65 const uint8_t *line, *prev;
70 if (!fmc_must_dump_sdb)
73 /* If the argument is not-zero, do simple dump (== show) */
74 if (fmc_must_dump_sdb > 0)
75 fmc_show_sdb_tree(fmc);
77 if (fmc_must_dump_sdb == 1)
80 /* If bigger than 1, dump it seriously, to help debugging */
83 * Here we should really use libsdbfs (which is designed to
84 * work in kernel space as well) , but it doesn't support
85 * directories yet, and it requires better intergration (it
86 * should be used instead of fmc-specific code).
88 * So, lazily, just dump the top-level array
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");
94 len = fmc->sdb->len * sizeof(union sdb_record);
95 line = (void *)fmc->sdb->record;
97 for (i = 0; i < len; i += LINELEN, line += LINELEN)
98 prev = dump_line(i, line, prev);