]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/fmc/fmc-dump.c
Merge tag 'pci-v4.15-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[mirror_ubuntu-bionic-kernel.git] / drivers / fmc / fmc-dump.c
CommitLineData
77864f2e
AR
1/*
2 * Copyright (C) 2013 CERN (www.cern.ch)
3 * Author: Alessandro Rubini <rubini@gnudd.com>
4 *
5 * Released according to the GNU GPL, version 2 or any later version.
6 *
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>
15
16static int fmc_must_dump_eeprom;
17module_param_named(dump_eeprom, fmc_must_dump_eeprom, int, 0644);
77864f2e
AR
18
19#define LINELEN 16
20
21/* Dumping 8k takes oh so much: avoid duplicate lines */
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 /* repeated line */
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}