1
2
3
4
5
6
7
8
9
10
11#include <linux/list.h>
12#include <linux/netdevice.h>
13#include <linux/phy.h>
14#include "dsa_priv.h"
15#include "mv88e6xxx.h"
16
17static char *mv88e6123_61_65_probe(struct mii_bus *bus, int sw_addr)
18{
19 int ret;
20
21 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
22 if (ret >= 0) {
23 ret &= 0xfff0;
24 if (ret == 0x1210)
25 return "Marvell 88E6123";
26 if (ret == 0x1610)
27 return "Marvell 88E6161";
28 if (ret == 0x1650)
29 return "Marvell 88E6165";
30 }
31
32 return NULL;
33}
34
35static int mv88e6123_61_65_switch_reset(struct dsa_switch *ds)
36{
37 int i;
38 int ret;
39
40
41
42
43 for (i = 0; i < 8; i++) {
44 ret = REG_READ(REG_PORT(i), 0x04);
45 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
46 }
47
48
49
50
51 msleep(2);
52
53
54
55
56 REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
57
58
59
60
61 for (i = 0; i < 1000; i++) {
62 ret = REG_READ(REG_GLOBAL, 0x00);
63 if ((ret & 0xc800) == 0xc800)
64 break;
65
66 msleep(1);
67 }
68 if (i == 1000)
69 return -ETIMEDOUT;
70
71 return 0;
72}
73
74static int mv88e6123_61_65_setup_global(struct dsa_switch *ds)
75{
76 int ret;
77 int i;
78
79
80
81
82
83
84 REG_WRITE(REG_GLOBAL, 0x04, 0x0000);
85
86
87
88
89
90
91 REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
92
93
94
95
96 ret = mv88e6xxx_config_prio(ds);
97 if (ret < 0)
98 return ret;
99
100
101
102
103
104
105 REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1110));
106
107
108
109
110
111 REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
112
113
114
115
116
117 REG_WRITE(REG_GLOBAL2, 0x02, 0xffff);
118
119
120
121
122
123 REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
124
125
126
127
128
129
130
131
132
133 REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
134
135
136
137
138 for (i = 0; i < 32; i++) {
139 int nexthop;
140
141 nexthop = 0x1f;
142 if (i != ds->index && i < ds->dst->pd->nr_chips)
143 nexthop = ds->pd->rtable[i] & 0x1f;
144
145 REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
146 }
147
148
149
150
151 for (i = 0; i < 8; i++)
152 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0xff);
153
154
155
156
157 for (i = 0; i < 16; i++)
158 REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
159
160
161
162
163
164 for (i = 0; i < 6; i++)
165 REG_WRITE(REG_GLOBAL2, 0x09, 0x9000 | (i << 8));
166
167
168
169
170 REG_WRITE(REG_GLOBAL2, 0x0b, 0x9000);
171
172
173
174
175 for (i = 0; i < 16; i++)
176 REG_WRITE(REG_GLOBAL2, 0x0f, 0x8000 | (i << 8));
177
178
179
180 return 0;
181}
182
183static int mv88e6123_61_65_setup_port(struct dsa_switch *ds, int p)
184{
185 int addr = REG_PORT(p);
186 u16 val;
187
188
189
190
191
192
193
194 if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
195 REG_WRITE(addr, 0x01, 0x003e);
196 else
197 REG_WRITE(addr, 0x01, 0x0003);
198
199
200
201
202
203
204 REG_WRITE(addr, 0x02, 0x0000);
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 val = 0x0433;
222 if (dsa_is_cpu_port(ds, p)) {
223 if (ds->dst->tag_protocol == htons(ETH_P_EDSA))
224 val |= 0x3300;
225 else
226 val |= 0x0100;
227 }
228 if (ds->dsa_port_mask & (1 << p))
229 val |= 0x0100;
230 if (p == dsa_upstream_port(ds))
231 val |= 0x000c;
232 REG_WRITE(addr, 0x04, val);
233
234
235
236
237
238 REG_WRITE(addr, 0x05, dsa_is_cpu_port(ds, p) ? 0x8000 : 0x0000);
239
240
241
242
243
244
245
246 val = (p & 0xf) << 12;
247 if (dsa_is_cpu_port(ds, p))
248 val |= ds->phys_port_mask;
249 else
250 val |= 1 << dsa_upstream_port(ds);
251 REG_WRITE(addr, 0x06, val);
252
253
254
255
256
257 REG_WRITE(addr, 0x07, 0x0000);
258
259
260
261
262
263
264
265
266
267
268 REG_WRITE(addr, 0x08, 0x2080);
269
270
271
272
273 REG_WRITE(addr, 0x09, 0x0001);
274
275
276
277
278 REG_WRITE(addr, 0x0a, 0x0000);
279
280
281
282
283
284
285
286 REG_WRITE(addr, 0x0b, 1 << p);
287
288
289
290
291
292 REG_WRITE(addr, 0x0c, 0x0000);
293
294
295
296
297 REG_WRITE(addr, 0x0d, 0x0000);
298
299
300
301
302 REG_WRITE(addr, 0x0f, ETH_P_EDSA);
303
304
305
306
307
308 REG_WRITE(addr, 0x18, 0x3210);
309
310
311
312
313
314 REG_WRITE(addr, 0x19, 0x7654);
315
316 return 0;
317}
318
319static int mv88e6123_61_65_setup(struct dsa_switch *ds)
320{
321 struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
322 int i;
323 int ret;
324
325 mutex_init(&ps->smi_mutex);
326 mutex_init(&ps->stats_mutex);
327
328 ret = mv88e6123_61_65_switch_reset(ds);
329 if (ret < 0)
330 return ret;
331
332
333
334 ret = mv88e6123_61_65_setup_global(ds);
335 if (ret < 0)
336 return ret;
337
338 for (i = 0; i < 6; i++) {
339 ret = mv88e6123_61_65_setup_port(ds, i);
340 if (ret < 0)
341 return ret;
342 }
343
344 return 0;
345}
346
347static int mv88e6123_61_65_port_to_phy_addr(int port)
348{
349 if (port >= 0 && port <= 4)
350 return port;
351 return -1;
352}
353
354static int
355mv88e6123_61_65_phy_read(struct dsa_switch *ds, int port, int regnum)
356{
357 int addr = mv88e6123_61_65_port_to_phy_addr(port);
358 return mv88e6xxx_phy_read(ds, addr, regnum);
359}
360
361static int
362mv88e6123_61_65_phy_write(struct dsa_switch *ds,
363 int port, int regnum, u16 val)
364{
365 int addr = mv88e6123_61_65_port_to_phy_addr(port);
366 return mv88e6xxx_phy_write(ds, addr, regnum, val);
367}
368
369static struct mv88e6xxx_hw_stat mv88e6123_61_65_hw_stats[] = {
370 { "in_good_octets", 8, 0x00, },
371 { "in_bad_octets", 4, 0x02, },
372 { "in_unicast", 4, 0x04, },
373 { "in_broadcasts", 4, 0x06, },
374 { "in_multicasts", 4, 0x07, },
375 { "in_pause", 4, 0x16, },
376 { "in_undersize", 4, 0x18, },
377 { "in_fragments", 4, 0x19, },
378 { "in_oversize", 4, 0x1a, },
379 { "in_jabber", 4, 0x1b, },
380 { "in_rx_error", 4, 0x1c, },
381 { "in_fcs_error", 4, 0x1d, },
382 { "out_octets", 8, 0x0e, },
383 { "out_unicast", 4, 0x10, },
384 { "out_broadcasts", 4, 0x13, },
385 { "out_multicasts", 4, 0x12, },
386 { "out_pause", 4, 0x15, },
387 { "excessive", 4, 0x11, },
388 { "collisions", 4, 0x1e, },
389 { "deferred", 4, 0x05, },
390 { "single", 4, 0x14, },
391 { "multiple", 4, 0x17, },
392 { "out_fcs_error", 4, 0x03, },
393 { "late", 4, 0x1f, },
394 { "hist_64bytes", 4, 0x08, },
395 { "hist_65_127bytes", 4, 0x09, },
396 { "hist_128_255bytes", 4, 0x0a, },
397 { "hist_256_511bytes", 4, 0x0b, },
398 { "hist_512_1023bytes", 4, 0x0c, },
399 { "hist_1024_max_bytes", 4, 0x0d, },
400};
401
402static void
403mv88e6123_61_65_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
404{
405 mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6123_61_65_hw_stats),
406 mv88e6123_61_65_hw_stats, port, data);
407}
408
409static void
410mv88e6123_61_65_get_ethtool_stats(struct dsa_switch *ds,
411 int port, uint64_t *data)
412{
413 mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6123_61_65_hw_stats),
414 mv88e6123_61_65_hw_stats, port, data);
415}
416
417static int mv88e6123_61_65_get_sset_count(struct dsa_switch *ds)
418{
419 return ARRAY_SIZE(mv88e6123_61_65_hw_stats);
420}
421
422static struct dsa_switch_driver mv88e6123_61_65_switch_driver = {
423 .tag_protocol = cpu_to_be16(ETH_P_EDSA),
424 .priv_size = sizeof(struct mv88e6xxx_priv_state),
425 .probe = mv88e6123_61_65_probe,
426 .setup = mv88e6123_61_65_setup,
427 .set_addr = mv88e6xxx_set_addr_indirect,
428 .phy_read = mv88e6123_61_65_phy_read,
429 .phy_write = mv88e6123_61_65_phy_write,
430 .poll_link = mv88e6xxx_poll_link,
431 .get_strings = mv88e6123_61_65_get_strings,
432 .get_ethtool_stats = mv88e6123_61_65_get_ethtool_stats,
433 .get_sset_count = mv88e6123_61_65_get_sset_count,
434};
435
436static int __init mv88e6123_61_65_init(void)
437{
438 register_switch_driver(&mv88e6123_61_65_switch_driver);
439 return 0;
440}
441module_init(mv88e6123_61_65_init);
442
443static void __exit mv88e6123_61_65_cleanup(void)
444{
445 unregister_switch_driver(&mv88e6123_61_65_switch_driver);
446}
447module_exit(mv88e6123_61_65_cleanup);
448