-
Notifications
You must be signed in to change notification settings - Fork 78
/
print_mv6.c
298 lines (238 loc) · 6.01 KB
/
print_mv6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/* This file is part of phytool
*
* phytool is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* phytool is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with phytool. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdio.h>
#include <linux/mdio.h>
#include <net/if.h>
#include "phytool.h"
static const char *mv6_model_str(uint16_t id)
{
static char str[32];
switch (id & 0xfff0) {
case 0x0480:
return "mv88e6046";
case 0x0950:
return "mv88e6095";
case 0x0990:
return "mv88e6097";
case 0x1a70:
return "mv88e6185";
case 0x3520:
return "mv88e6352";
}
snprintf(str, sizeof(str), "UNKNOWN(0x%.4x)", id);
return str;
}
static const char *mv6_dev_str(uint16_t dev)
{
static char str[32];
if (dev < 0xf)
snprintf(str, sizeof(str), "phy:%d", dev);
else if (dev == 0xf)
return "serdes";
else if (dev)
snprintf(str, sizeof(str), "port:%d", dev - 0x10);
else if (dev == 0x1b)
return "global:1";
else if (dev == 0x1c)
return "global:2";
else if (dev == 0x1d)
return "global:3";
else
snprintf(str, sizeof(str), "port:RESERVED(0x%.2x)", dev);
return str;
}
static void print_mv6_heading(const struct loc *loc, int indent)
{
int port = loc_c45_port(loc), dev = loc_c45_dev(loc);
struct loc loc_id = *loc;
uint16_t id;
loc_id.phy_id = mdio_phy_id_c45(port, 0x10);
loc_id.reg = 3;
id = phy_read(&loc_id);
printf("%*smv6: model:%s dev:%d %s\n", indent, "",
mv6_model_str(id), port /* [sic] */, mv6_dev_str(dev));
}
static void mv6_port_ps(uint16_t val, int indent)
{
int speed = 10;
int mult = (val & 0x0300) >> 8;
while (mult) {
speed *= 10;
mult--;
}
printf("%*smv6: reg:PS(0x00) val:0x%.4x\n", indent, "", val);
print_attr_name("flags", indent + INDENT);
print_bool("pause-en", val & 0x8000);
putchar(' ');
print_bool("my-pause", val & 0x4000);
putchar(' ');
print_bool("phy-detect", val & 0x1000);
putchar(' ');
print_bool("link", val & 0x0800);
putchar(' ');
print_bool("eee", val & 0x0040);
putchar(' ');
print_bool("tx-paused", val & 0x0020);
putchar(' ');
print_bool("flow-ctrl", val & 0x0010);
putchar('\n');
print_attr_name("speed", indent + INDENT);
printf("%d-%s\n", speed, (val & 0x0400)? "full" : "half");
print_attr_name("mode", indent + INDENT);
printf("0x%x\n", val & 0xf);
}
static const char *mv6_egress_mode_str[] = {
"00, unmodified",
"01, untagged",
"10, tagged",
"11, reserved"
};
static const char *mv6_frame_mode_str[] = {
"00, normal",
"01, DSA",
"10, provider",
"11, ether type DSA"
};
static const char *mv6_initial_pri_str[] = {
"00, port defaults",
"01, tag prio",
"10, IP prio",
"11, tag & IP prio"
};
static const char *mv6_egress_floods_str[] = {
"00, deny UC & MC",
"01, allow UC",
"10, allow MC",
"11, allow UC & MC"
};
static const char *mv6_port_state_str[] = {
"00, disabled",
"01, blocking",
"10, learning",
"11, forwarding"
};
static void mv6_port_pc(uint16_t val, int indent)
{
int speed = 10;
int mult = (val & 0x0300) >> 8;
while (mult) {
speed *= 10;
mult--;
}
printf("%*smv6: reg:PC(0x04) val:0x%.4x\n", indent, "", val);
print_attr_name("flags", indent + INDENT);
print_bool("router-header", val & 0x0800);
putchar(' ');
print_bool("igmp-snoop", val & 0x0400);
putchar(' ');
print_bool("vlan-tunnel", val & 0x0080);
putchar(' ');
print_bool("tag-if-both", val & 0x0040);
putchar('\n');
print_attr_name("egress-mode", indent + INDENT);
puts(mv6_egress_mode_str[(val & 0x3000) >> 12]);
print_attr_name("frame-mode", indent + INDENT);
puts(mv6_frame_mode_str[(val & 0x0300) >> 8]);
print_attr_name("initial-pri", indent + INDENT);
puts(mv6_initial_pri_str[(val & 0x0030) >> 4]);
print_attr_name("egress-floods", indent + INDENT);
puts(mv6_egress_floods_str[(val & 0x000c) >> 2]);
print_attr_name("port-state", indent + INDENT);
puts(mv6_port_state_str[(val & 0x0003)]);
}
struct mv6_port_desc {
int summary[32];
void (*printer[32])(uint16_t val, int indent);
};
struct mv6_port_desc mv6_pd_port = {
.summary = { 0, 4, -1 },
.printer = {
mv6_port_ps,
NULL,
NULL,
NULL,
mv6_port_pc,
},
};
struct mv6_port_desc mv6_pd_serdes = {
.summary = { -1 },
.printer = {
},
};
struct mv6_port_desc mv6_pd_g1 = {
.summary = { -1 },
.printer = {
},
};
struct mv6_port_desc mv6_pd_g2 = {
.summary = { -1 },
.printer = {
},
};
struct mv6_port_desc mv6_pd_g3 = {
.summary = { -1 },
.printer = {
},
};
int mv6_port_one(const struct loc *loc, int indent, struct mv6_port_desc *pd)
{
int val = phy_read(loc);
if (val < 0)
return val;
if (loc->reg > 0x1f || !pd || !pd->printer[loc->reg])
printf("%*smv6: reg:0x%.2x val:0x%.4x\n", indent, "",
loc->reg, val);
else
pd->printer[loc->reg](val, indent);
return 0;
}
int print_mv6_port(const struct loc *loc, int indent, struct mv6_port_desc *pd)
{
struct loc loc_sum = *loc;
int i;
if (loc->reg != REG_SUMMARY)
return mv6_port_one(loc, indent, pd);
for (i = 0; pd->summary[i] >= 0; i++) {
loc_sum.reg = pd->summary[i];
mv6_port_one(&loc_sum, indent, pd);
putchar('\n');
}
return 0;
}
int print_mv6tool(const struct loc *loc, int indent)
{
int dev = loc_c45_dev(loc);
struct mv6_port_desc *pd = NULL;
if (!loc_is_c45(loc)) {
fprintf(stderr, "error: PHY must be a C45 dev:port pair\n");
return 1;
}
print_mv6_heading(loc, indent);
if (dev < 0xf)
return print_phytool(loc, indent + INDENT);
else if (dev == 0xf)
pd = &mv6_pd_serdes;
else if (dev < 0x1b)
pd = &mv6_pd_port;
else if (dev == 0x1b)
pd = &mv6_pd_g1;
else if (dev == 0x1c)
pd = &mv6_pd_g2;
else if (dev == 0x1d)
pd = &mv6_pd_g3;
return print_mv6_port(loc, indent + INDENT, pd);
}