blob: 5de60b2a05b08a3a7f36a01447457f5b524b65f3 [file] [log] [blame]
Vivien Didelotcb8e9802018-12-18 14:06:35 -05001#include <stdio.h>
2#include <string.h>
3
4#include "internal.h"
5
Vivien Didelotff99e462018-12-18 14:06:36 -05006/* Macros and dump functions for the 16-bit mv88e6xxx per-port registers */
7
8#define REG(_reg, _name, _val) \
9 printf("%.02u: %-38.38s 0x%.4x\n", _reg, _name, _val)
10
11#define FIELD(_name, _fmt, ...) \
12 printf(" %-36.36s " _fmt "\n", _name, ##__VA_ARGS__)
13
14#define FIELD_BITMAP(_name, _val) \
15 FIELD(_name, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", \
16 ((_val) & 0x0001) ? "0 " : "", \
17 ((_val) & 0x0002) ? "1 " : "", \
18 ((_val) & 0x0004) ? "2 " : "", \
19 ((_val) & 0x0008) ? "3 " : "", \
20 ((_val) & 0x0010) ? "4 " : "", \
21 ((_val) & 0x0020) ? "5 " : "", \
22 ((_val) & 0x0040) ? "6 " : "", \
23 ((_val) & 0x0080) ? "7 " : "", \
24 ((_val) & 0x0100) ? "8 " : "", \
25 ((_val) & 0x0200) ? "9 " : "", \
26 ((_val) & 0x0400) ? "10 " : "", \
27 ((_val) & 0x0800) ? "11 " : "", \
28 ((_val) & 0x1000) ? "12 " : "", \
29 ((_val) & 0x2000) ? "13 " : "", \
30 ((_val) & 0x4000) ? "14 " : "", \
31 ((_val) & 0x8000) ? "15 " : "")
32
33struct dsa_mv88e6xxx_switch {
34 void (*dump)(int reg, u16 val);
35 const char *name;
36 u16 id;
37};
38
39static const struct dsa_mv88e6xxx_switch dsa_mv88e6xxx_switches[] = {
40};
41
42static int dsa_mv88e6xxx_dump_regs(struct ethtool_regs *regs)
43{
44 const struct dsa_mv88e6xxx_switch *sw = NULL;
45 const u16 *data = (u16 *)regs->data;
46 u16 id;
47 int i;
48
49 /* Marvell chips have 32 per-port 16-bit registers */
50 if (regs->len < 32 * 2)
51 return 1;
52
53 id = regs->version & 0xfff0;
54
55 for (i = 0; i < ARRAY_SIZE(dsa_mv88e6xxx_switches); i++) {
56 if (id == dsa_mv88e6xxx_switches[i].id) {
57 sw = &dsa_mv88e6xxx_switches[i];
58 break;
59 }
60 }
61
62 if (!sw)
63 return 1;
64
65 printf("%s Switch Port Registers\n", sw->name);
66 printf("------------------------------\n");
67
68 for (i = 0; i < 32; i++)
69 if (sw->dump)
70 sw->dump(i, data[i]);
71 else
72 REG(i, "", data[i]);
73
74 return 0;
75}
76
77#undef FIELD_BITMAP
78#undef FIELD
79#undef REG
80
Vivien Didelotcb8e9802018-12-18 14:06:35 -050081int dsa_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs)
82{
83 /* DSA per-driver register dump */
Vivien Didelotff99e462018-12-18 14:06:36 -050084 if (!dsa_mv88e6xxx_dump_regs(regs))
85 return 0;
Vivien Didelotcb8e9802018-12-18 14:06:35 -050086
87 /* Fallback to hexdump */
88 return 1;
89}