fmc-dump.c 1.5 KB

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