Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / drivers / fmc / fmc-dump.c
blobc91afd6388f63cfb1429f6ada93bdfd180c0f949
1 /*
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.
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>
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);
21 #define LINELEN 16
23 /* Dumping 8k takes oh so much: avoid duplicate lines */
24 static const uint8_t *dump_line(int addr, const uint8_t *line,
25 const uint8_t *prev)
27 int i;
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");
36 return line;
38 /* repeated line */
39 if (line == prev + LINELEN)
40 pr_info("[...]\n");
41 return prev;
44 void fmc_dump_eeprom(const struct fmc_device *fmc)
46 const uint8_t *line, *prev;
47 int i;
49 if (!fmc_must_dump_eeprom)
50 return;
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);
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);
63 void fmc_dump_sdb(const struct fmc_device *fmc)
65 const uint8_t *line, *prev;
66 int i, len;
68 if (!fmc->sdb)
69 return;
70 if (!fmc_must_dump_sdb)
71 return;
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)
78 return;
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;
96 prev = NULL;
97 for (i = 0; i < len; i += LINELEN, line += LINELEN)
98 prev = dump_line(i, line, prev);
99 return;