]> git.ipfire.org Git - thirdparty/linux.git/blob
2052495
[thirdparty/linux.git] /
1 // SPDX-License-Identifier: (GPL-2.0 or MIT)
2 /*
3 * DSA driver for:
4 * Hirschmann Hellcreek TSN switch.
5 *
6 * Copyright (C) 2019,2020 Linutronix GmbH
7 * Author Kurt Kanzenbach <kurt@linutronix.de>
8 */
9
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/of.h>
14 #include <linux/of_device.h>
15 #include <linux/of_mdio.h>
16 #include <linux/platform_device.h>
17 #include <linux/bitops.h>
18 #include <linux/if_bridge.h>
19 #include <linux/if_vlan.h>
20 #include <linux/etherdevice.h>
21 #include <linux/random.h>
22 #include <linux/iopoll.h>
23 #include <linux/mutex.h>
24 #include <linux/delay.h>
25 #include <net/dsa.h>
26
27 #include "hellcreek.h"
28 #include "hellcreek_ptp.h"
29 #include "hellcreek_hwtstamp.h"
30
31 static const struct hellcreek_counter hellcreek_counter[] = {
32 { 0x00, "RxFiltered", },
33 { 0x01, "RxOctets1k", },
34 { 0x02, "RxVTAG", },
35 { 0x03, "RxL2BAD", },
36 { 0x04, "RxOverloadDrop", },
37 { 0x05, "RxUC", },
38 { 0x06, "RxMC", },
39 { 0x07, "RxBC", },
40 { 0x08, "RxRS<64", },
41 { 0x09, "RxRS64", },
42 { 0x0a, "RxRS65_127", },
43 { 0x0b, "RxRS128_255", },
44 { 0x0c, "RxRS256_511", },
45 { 0x0d, "RxRS512_1023", },
46 { 0x0e, "RxRS1024_1518", },
47 { 0x0f, "RxRS>1518", },
48 { 0x10, "TxTailDropQueue0", },
49 { 0x11, "TxTailDropQueue1", },
50 { 0x12, "TxTailDropQueue2", },
51 { 0x13, "TxTailDropQueue3", },
52 { 0x14, "TxTailDropQueue4", },
53 { 0x15, "TxTailDropQueue5", },
54 { 0x16, "TxTailDropQueue6", },
55 { 0x17, "TxTailDropQueue7", },
56 { 0x18, "RxTrafficClass0", },
57 { 0x19, "RxTrafficClass1", },
58 { 0x1a, "RxTrafficClass2", },
59 { 0x1b, "RxTrafficClass3", },
60 { 0x1c, "RxTrafficClass4", },
61 { 0x1d, "RxTrafficClass5", },
62 { 0x1e, "RxTrafficClass6", },
63 { 0x1f, "RxTrafficClass7", },
64 { 0x21, "TxOctets1k", },
65 { 0x22, "TxVTAG", },
66 { 0x23, "TxL2BAD", },
67 { 0x25, "TxUC", },
68 { 0x26, "TxMC", },
69 { 0x27, "TxBC", },
70 { 0x28, "TxTS<64", },
71 { 0x29, "TxTS64", },
72 { 0x2a, "TxTS65_127", },
73 { 0x2b, "TxTS128_255", },
74 { 0x2c, "TxTS256_511", },
75 { 0x2d, "TxTS512_1023", },
76 { 0x2e, "TxTS1024_1518", },
77 { 0x2f, "TxTS>1518", },
78 { 0x30, "TxTrafficClassOverrun0", },
79 { 0x31, "TxTrafficClassOverrun1", },
80 { 0x32, "TxTrafficClassOverrun2", },
81 { 0x33, "TxTrafficClassOverrun3", },
82 { 0x34, "TxTrafficClassOverrun4", },
83 { 0x35, "TxTrafficClassOverrun5", },
84 { 0x36, "TxTrafficClassOverrun6", },
85 { 0x37, "TxTrafficClassOverrun7", },
86 { 0x38, "TxTrafficClass0", },
87 { 0x39, "TxTrafficClass1", },
88 { 0x3a, "TxTrafficClass2", },
89 { 0x3b, "TxTrafficClass3", },
90 { 0x3c, "TxTrafficClass4", },
91 { 0x3d, "TxTrafficClass5", },
92 { 0x3e, "TxTrafficClass6", },
93 { 0x3f, "TxTrafficClass7", },
94 };
95
96 static u16 hellcreek_read(struct hellcreek *hellcreek, unsigned int offset)
97 {
98 return readw(hellcreek->base + offset);
99 }
100
101 static u16 hellcreek_read_ctrl(struct hellcreek *hellcreek)
102 {
103 return readw(hellcreek->base + HR_CTRL_C);
104 }
105
106 static u16 hellcreek_read_stat(struct hellcreek *hellcreek)
107 {
108 return readw(hellcreek->base + HR_SWSTAT);
109 }
110
111 static void hellcreek_write(struct hellcreek *hellcreek, u16 data,
112 unsigned int offset)
113 {
114 writew(data, hellcreek->base + offset);
115 }
116
117 static void hellcreek_select_port(struct hellcreek *hellcreek, int port)
118 {
119 u16 val = port << HR_PSEL_PTWSEL_SHIFT;
120
121 hellcreek_write(hellcreek, val, HR_PSEL);
122 }
123
124 static void hellcreek_select_prio(struct hellcreek *hellcreek, int prio)
125 {
126 u16 val = prio << HR_PSEL_PRTCWSEL_SHIFT;
127
128 hellcreek_write(hellcreek, val, HR_PSEL);
129 }
130
131 static void hellcreek_select_counter(struct hellcreek *hellcreek, int counter)
132 {
133 u16 val = counter << HR_CSEL_SHIFT;
134
135 hellcreek_write(hellcreek, val, HR_CSEL);
136
137 /* Data sheet states to wait at least 20 internal clock cycles */
138 ndelay(200);
139 }
140
141 static void hellcreek_select_vlan(struct hellcreek *hellcreek, int vid,
142 bool pvid)
143 {
144 u16 val = 0;
145
146 /* Set pvid bit first */
147 if (pvid)
148 val |= HR_VIDCFG_PVID;
149 hellcreek_write(hellcreek, val, HR_VIDCFG);
150
151 /* Set vlan */
152 val |= vid << HR_VIDCFG_VID_SHIFT;
153 hellcreek_write(hellcreek, val, HR_VIDCFG);
154 }
155
156 static int hellcreek_wait_until_ready(struct hellcreek *hellcreek)
157 {
158 u16 val;
159
160 /* Wait up to 1ms, although 3 us should be enough */
161 return readx_poll_timeout(hellcreek_read_ctrl, hellcreek,
162 val, val & HR_CTRL_C_READY,
163 3, 1000);
164 }
165
166 static int hellcreek_wait_until_transitioned(struct hellcreek *hellcreek)
167 {
168 u16 val;
169
170 return readx_poll_timeout_atomic(hellcreek_read_ctrl, hellcreek,
171 val, !(val & HR_CTRL_C_TRANSITION),
172 1, 1000);
173 }
174
175 static int hellcreek_wait_fdb_ready(struct hellcreek *hellcreek)
176 {
177 u16 val;
178
179 return readx_poll_timeout_atomic(hellcreek_read_stat, hellcreek,
180 val, !(val & HR_SWSTAT_BUSY),
181 1, 1000);
182 }
183
184 static int hellcreek_detect(struct hellcreek *hellcreek)
185 {
186 u16 id, rel_low, rel_high, date_low, date_high, tgd_ver;
187 u8 tgd_maj, tgd_min;
188 u32 rel, date;
189
190 id = hellcreek_read(hellcreek, HR_MODID_C);
191 rel_low = hellcreek_read(hellcreek, HR_REL_L_C);
192 rel_high = hellcreek_read(hellcreek, HR_REL_H_C);
193 date_low = hellcreek_read(hellcreek, HR_BLD_L_C);
194 date_high = hellcreek_read(hellcreek, HR_BLD_H_C);
195 tgd_ver = hellcreek_read(hellcreek, TR_TGDVER);
196
197 if (id != hellcreek->pdata->module_id)
198 return -ENODEV;
199
200 rel = rel_low | (rel_high << 16);
201 date = date_low | (date_high << 16);
202 tgd_maj = (tgd_ver & TR_TGDVER_REV_MAJ_MASK) >> TR_TGDVER_REV_MAJ_SHIFT;
203 tgd_min = (tgd_ver & TR_TGDVER_REV_MIN_MASK) >> TR_TGDVER_REV_MIN_SHIFT;
204
205 dev_info(hellcreek->dev, "Module ID=%02x Release=%04x Date=%04x TGD Version=%02x.%02x\n",
206 id, rel, date, tgd_maj, tgd_min);
207
208 return 0;
209 }
210
211 static void hellcreek_feature_detect(struct hellcreek *hellcreek)
212 {
213 u16 features;
214
215 features = hellcreek_read(hellcreek, HR_FEABITS0);
216
217 /* Currently we only detect the size of the FDB table */
218 hellcreek->fdb_entries = ((features & HR_FEABITS0_FDBBINS_MASK) >>
219 HR_FEABITS0_FDBBINS_SHIFT) * 32;
220
221 dev_info(hellcreek->dev, "Feature detect: FDB entries=%zu\n",
222 hellcreek->fdb_entries);
223 }
224
225 static enum dsa_tag_protocol hellcreek_get_tag_protocol(struct dsa_switch *ds,
226 int port,
227 enum dsa_tag_protocol mp)
228 {
229 return DSA_TAG_PROTO_HELLCREEK;
230 }
231
232 static int hellcreek_port_enable(struct dsa_switch *ds, int port,
233 struct phy_device *phy)
234 {
235 struct hellcreek *hellcreek = ds->priv;
236 struct hellcreek_port *hellcreek_port;
237 u16 val;
238
239 hellcreek_port = &hellcreek->ports[port];
240
241 dev_dbg(hellcreek->dev, "Enable port %d\n", port);
242
243 mutex_lock(&hellcreek->reg_lock);
244
245 hellcreek_select_port(hellcreek, port);
246 val = hellcreek_port->ptcfg;
247 val |= HR_PTCFG_ADMIN_EN;
248 hellcreek_write(hellcreek, val, HR_PTCFG);
249 hellcreek_port->ptcfg = val;
250
251 mutex_unlock(&hellcreek->reg_lock);
252
253 return 0;
254 }
255
256 static void hellcreek_port_disable(struct dsa_switch *ds, int port)
257 {
258 struct hellcreek *hellcreek = ds->priv;
259 struct hellcreek_port *hellcreek_port;
260 u16 val;
261
262 hellcreek_port = &hellcreek->ports[port];
263
264 dev_dbg(hellcreek->dev, "Disable port %d\n", port);
265
266 mutex_lock(&hellcreek->reg_lock);
267
268 hellcreek_select_port(hellcreek, port);
269 val = hellcreek_port->ptcfg;
270 val &= ~HR_PTCFG_ADMIN_EN;
271 hellcreek_write(hellcreek, val, HR_PTCFG);
272 hellcreek_port->ptcfg = val;
273
274 mutex_unlock(&hellcreek->reg_lock);
275 }
276
277 static void hellcreek_get_strings(struct dsa_switch *ds, int port,
278 u32 stringset, uint8_t *data)
279 {
280 int i;
281
282 for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i) {
283 const struct hellcreek_counter *counter = &hellcreek_counter[i];
284
285 strlcpy(data + i * ETH_GSTRING_LEN,
286 counter->name, ETH_GSTRING_LEN);
287 }
288 }
289
290 static int hellcreek_get_sset_count(struct dsa_switch *ds, int port, int sset)
291 {
292 if (sset != ETH_SS_STATS)
293 return 0;
294
295 return ARRAY_SIZE(hellcreek_counter);
296 }
297
298 static void hellcreek_get_ethtool_stats(struct dsa_switch *ds, int port,
299 uint64_t *data)
300 {
301 struct hellcreek *hellcreek = ds->priv;
302 struct hellcreek_port *hellcreek_port;
303 int i;
304
305 hellcreek_port = &hellcreek->ports[port];
306
307 for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i) {
308 const struct hellcreek_counter *counter = &hellcreek_counter[i];
309 u8 offset = counter->offset + port * 64;
310 u16 high, low;
311 u64 value;
312
313 mutex_lock(&hellcreek->reg_lock);
314
315 hellcreek_select_counter(hellcreek, offset);
316
317 /* The registers are locked internally by selecting the
318 * counter. So low and high can be read without reading high
319 * again.
320 */
321 high = hellcreek_read(hellcreek, HR_CRDH);
322 low = hellcreek_read(hellcreek, HR_CRDL);
323 value = ((u64)high << 16) | low;
324
325 hellcreek_port->counter_values[i] += value;
326 data[i] = hellcreek_port->counter_values[i];
327
328 mutex_unlock(&hellcreek->reg_lock);
329 }
330 }
331
332 static u16 hellcreek_private_vid(int port)
333 {
334 return VLAN_N_VID - port + 1;
335 }
336
337 static int hellcreek_vlan_prepare(struct dsa_switch *ds, int port,
338 const struct switchdev_obj_port_vlan *vlan)
339 {
340 struct hellcreek *hellcreek = ds->priv;
341 int i;
342
343 dev_dbg(hellcreek->dev, "VLAN prepare for port %d\n", port);
344
345 /* Restriction: Make sure that nobody uses the "private" VLANs. These
346 * VLANs are internally used by the driver to ensure port
347 * separation. Thus, they cannot be used by someone else.
348 */
349 for (i = 0; i < hellcreek->pdata->num_ports; ++i) {
350 const u16 restricted_vid = hellcreek_private_vid(i);
351
352 if (!dsa_is_user_port(ds, i))
353 continue;
354
355 if (vlan->vid == restricted_vid)
356 return -EBUSY;
357 }
358
359 return 0;
360 }
361
362 static void hellcreek_select_vlan_params(struct hellcreek *hellcreek, int port,
363 int *shift, int *mask)
364 {
365 switch (port) {
366 case 0:
367 *shift = HR_VIDMBRCFG_P0MBR_SHIFT;
368 *mask = HR_VIDMBRCFG_P0MBR_MASK;
369 break;
370 case 1:
371 *shift = HR_VIDMBRCFG_P1MBR_SHIFT;
372 *mask = HR_VIDMBRCFG_P1MBR_MASK;
373 break;
374 case 2:
375 *shift = HR_VIDMBRCFG_P2MBR_SHIFT;
376 *mask = HR_VIDMBRCFG_P2MBR_MASK;
377 break;
378 case 3:
379 *shift = HR_VIDMBRCFG_P3MBR_SHIFT;
380 *mask = HR_VIDMBRCFG_P3MBR_MASK;
381 break;
382 default:
383 *shift = *mask = 0;
384 dev_err(hellcreek->dev, "Unknown port %d selected!\n", port);
385 }
386 }
387
388 static void hellcreek_apply_vlan(struct hellcreek *hellcreek, int port, u16 vid,
389 bool pvid, bool untagged)
390 {
391 int shift, mask;
392 u16 val;
393
394 dev_dbg(hellcreek->dev, "Apply VLAN: port=%d vid=%u pvid=%d untagged=%d",
395 port, vid, pvid, untagged);
396
397 mutex_lock(&hellcreek->reg_lock);
398
399 hellcreek_select_port(hellcreek, port);
400 hellcreek_select_vlan(hellcreek, vid, pvid);
401
402 /* Setup port vlan membership */
403 hellcreek_select_vlan_params(hellcreek, port, &shift, &mask);
404 val = hellcreek->vidmbrcfg[vid];
405 val &= ~mask;
406 if (untagged)
407 val |= HELLCREEK_VLAN_UNTAGGED_MEMBER << shift;
408 else
409 val |= HELLCREEK_VLAN_TAGGED_MEMBER << shift;
410
411 hellcreek_write(hellcreek, val, HR_VIDMBRCFG);
412 hellcreek->vidmbrcfg[vid] = val;
413
414 mutex_unlock(&hellcreek->reg_lock);
415 }
416
417 static void hellcreek_unapply_vlan(struct hellcreek *hellcreek, int port,
418 u16 vid)
419 {
420 int shift, mask;
421 u16 val;
422
423 dev_dbg(hellcreek->dev, "Unapply VLAN: port=%d vid=%u\n", port, vid);
424
425 mutex_lock(&hellcreek->reg_lock);
426
427 hellcreek_select_vlan(hellcreek, vid, 0);
428
429 /* Setup port vlan membership */
430 hellcreek_select_vlan_params(hellcreek, port, &shift, &mask);
431 val = hellcreek->vidmbrcfg[vid];
432 val &= ~mask;
433 val |= HELLCREEK_VLAN_NO_MEMBER << shift;
434
435 hellcreek_write(hellcreek, val, HR_VIDMBRCFG);
436 hellcreek->vidmbrcfg[vid] = val;
437
438 mutex_unlock(&hellcreek->reg_lock);
439 }
440
441 static int hellcreek_vlan_add(struct dsa_switch *ds, int port,
442 const struct switchdev_obj_port_vlan *vlan)
443 {
444 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
445 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
446 struct hellcreek *hellcreek = ds->priv;
447 int err;
448
449 err = hellcreek_vlan_prepare(ds, port, vlan);
450 if (err)
451 return err;
452
453 dev_dbg(hellcreek->dev, "Add VLAN %d on port %d, %s, %s\n",
454 vlan->vid, port, untagged ? "untagged" : "tagged",
455 pvid ? "PVID" : "no PVID");
456
457 hellcreek_apply_vlan(hellcreek, port, vlan->vid, pvid, untagged);
458
459 return 0;
460 }
461
462 static int hellcreek_vlan_del(struct dsa_switch *ds, int port,
463 const struct switchdev_obj_port_vlan *vlan)
464 {
465 struct hellcreek *hellcreek = ds->priv;
466
467 dev_dbg(hellcreek->dev, "Remove VLAN %d on port %d\n", vlan->vid, port);
468
469 hellcreek_unapply_vlan(hellcreek, port, vlan->vid);
470
471 return 0;
472 }
473
474 static void hellcreek_port_stp_state_set(struct dsa_switch *ds, int port,
475 u8 state)
476 {
477 struct hellcreek *hellcreek = ds->priv;
478 struct hellcreek_port *hellcreek_port;
479 const char *new_state;
480 u16 val;
481
482 mutex_lock(&hellcreek->reg_lock);
483
484 hellcreek_port = &hellcreek->ports[port];
485 val = hellcreek_port->ptcfg;
486
487 switch (state) {
488 case BR_STATE_DISABLED:
489 new_state = "DISABLED";
490 val |= HR_PTCFG_BLOCKED;
491 val &= ~HR_PTCFG_LEARNING_EN;
492 break;
493 case BR_STATE_BLOCKING:
494 new_state = "BLOCKING";
495 val |= HR_PTCFG_BLOCKED;
496 val &= ~HR_PTCFG_LEARNING_EN;
497 break;
498 case BR_STATE_LISTENING:
499 new_state = "LISTENING";
500 val |= HR_PTCFG_BLOCKED;
501 val &= ~HR_PTCFG_LEARNING_EN;
502 break;
503 case BR_STATE_LEARNING:
504 new_state = "LEARNING";
505 val |= HR_PTCFG_BLOCKED;
506 val |= HR_PTCFG_LEARNING_EN;
507 break;
508 case BR_STATE_FORWARDING:
509 new_state = "FORWARDING";
510 val &= ~HR_PTCFG_BLOCKED;
511 val |= HR_PTCFG_LEARNING_EN;
512 break;
513 default:
514 new_state = "UNKNOWN";
515 }
516
517 hellcreek_select_port(hellcreek, port);
518 hellcreek_write(hellcreek, val, HR_PTCFG);
519 hellcreek_port->ptcfg = val;
520
521 mutex_unlock(&hellcreek->reg_lock);
522
523 dev_dbg(hellcreek->dev, "Configured STP state for port %d: %s\n",
524 port, new_state);
525 }
526
527 static void hellcreek_setup_ingressflt(struct hellcreek *hellcreek, int port,
528 bool enable)
529 {
530 struct hellcreek_port *hellcreek_port = &hellcreek->ports[port];
531 u16 ptcfg;
532
533 mutex_lock(&hellcreek->reg_lock);
534
535 ptcfg = hellcreek_port->ptcfg;
536
537 if (enable)
538 ptcfg |= HR_PTCFG_INGRESSFLT;
539 else
540 ptcfg &= ~HR_PTCFG_INGRESSFLT;
541
542 hellcreek_select_port(hellcreek, port);
543 hellcreek_write(hellcreek, ptcfg, HR_PTCFG);
544 hellcreek_port->ptcfg = ptcfg;
545
546 mutex_unlock(&hellcreek->reg_lock);
547 }
548
549 static void hellcreek_setup_vlan_awareness(struct hellcreek *hellcreek,
550 bool enable)
551 {
552 u16 swcfg;
553
554 mutex_lock(&hellcreek->reg_lock);
555
556 swcfg = hellcreek->swcfg;
557
558 if (enable)
559 swcfg |= HR_SWCFG_VLAN_UNAWARE;
560 else
561 swcfg &= ~HR_SWCFG_VLAN_UNAWARE;
562
563 hellcreek_write(hellcreek, swcfg, HR_SWCFG);
564
565 mutex_unlock(&hellcreek->reg_lock);
566 }
567
568 /* Default setup for DSA: VLAN <X>: CPU and Port <X> egress untagged. */
569 static void hellcreek_setup_vlan_membership(struct dsa_switch *ds, int port,
570 bool enabled)
571 {
572 const u16 vid = hellcreek_private_vid(port);
573 int upstream = dsa_upstream_port(ds, port);
574 struct hellcreek *hellcreek = ds->priv;
575
576 /* Apply vid to port as egress untagged and port vlan id */
577 if (enabled)
578 hellcreek_apply_vlan(hellcreek, port, vid, true, true);
579 else
580 hellcreek_unapply_vlan(hellcreek, port, vid);
581
582 /* Apply vid to cpu port as well */
583 if (enabled)
584 hellcreek_apply_vlan(hellcreek, upstream, vid, false, true);
585 else
586 hellcreek_unapply_vlan(hellcreek, upstream, vid);
587 }
588
589 static int hellcreek_port_bridge_join(struct dsa_switch *ds, int port,
590 struct net_device *br)
591 {
592 struct hellcreek *hellcreek = ds->priv;
593
594 dev_dbg(hellcreek->dev, "Port %d joins a bridge\n", port);
595
596 /* When joining a vlan_filtering bridge, keep the switch VLAN aware */
597 if (!ds->vlan_filtering)
598 hellcreek_setup_vlan_awareness(hellcreek, false);
599
600 /* Drop private vlans */
601 hellcreek_setup_vlan_membership(ds, port, false);
602
603 return 0;
604 }
605
606 static void hellcreek_port_bridge_leave(struct dsa_switch *ds, int port,
607 struct net_device *br)
608 {
609 struct hellcreek *hellcreek = ds->priv;
610
611 dev_dbg(hellcreek->dev, "Port %d leaves a bridge\n", port);
612
613 /* Enable VLAN awareness */
614 hellcreek_setup_vlan_awareness(hellcreek, true);
615
616 /* Enable private vlans */
617 hellcreek_setup_vlan_membership(ds, port, true);
618 }
619
620 static int __hellcreek_fdb_add(struct hellcreek *hellcreek,
621 const struct hellcreek_fdb_entry *entry)
622 {
623 u16 meta = 0;
624
625 dev_dbg(hellcreek->dev, "Add static FDB entry: MAC=%pM, MASK=0x%02x, "
626 "OBT=%d, REPRIO_EN=%d, PRIO=%d\n", entry->mac, entry->portmask,
627 entry->is_obt, entry->reprio_en, entry->reprio_tc);
628
629 /* Add mac address */
630 hellcreek_write(hellcreek, entry->mac[1] | (entry->mac[0] << 8), HR_FDBWDH);
631 hellcreek_write(hellcreek, entry->mac[3] | (entry->mac[2] << 8), HR_FDBWDM);
632 hellcreek_write(hellcreek, entry->mac[5] | (entry->mac[4] << 8), HR_FDBWDL);
633
634 /* Meta data */
635 meta |= entry->portmask << HR_FDBWRM0_PORTMASK_SHIFT;
636 if (entry->is_obt)
637 meta |= HR_FDBWRM0_OBT;
638 if (entry->reprio_en) {
639 meta |= HR_FDBWRM0_REPRIO_EN;
640 meta |= entry->reprio_tc << HR_FDBWRM0_REPRIO_TC_SHIFT;
641 }
642 hellcreek_write(hellcreek, meta, HR_FDBWRM0);
643
644 /* Commit */
645 hellcreek_write(hellcreek, 0x00, HR_FDBWRCMD);
646
647 /* Wait until done */
648 return hellcreek_wait_fdb_ready(hellcreek);
649 }
650
651 static int __hellcreek_fdb_del(struct hellcreek *hellcreek,
652 const struct hellcreek_fdb_entry *entry)
653 {
654 dev_dbg(hellcreek->dev, "Delete FDB entry: MAC=%pM!\n", entry->mac);
655
656 /* Delete by matching idx */
657 hellcreek_write(hellcreek, entry->idx | HR_FDBWRCMD_FDBDEL, HR_FDBWRCMD);
658
659 /* Wait until done */
660 return hellcreek_wait_fdb_ready(hellcreek);
661 }
662
663 /* Retrieve the index of a FDB entry by mac address. Currently we search through
664 * the complete table in hardware. If that's too slow, we might have to cache
665 * the complete FDB table in software.
666 */
667 static int hellcreek_fdb_get(struct hellcreek *hellcreek,
668 const unsigned char *dest,
669 struct hellcreek_fdb_entry *entry)
670 {
671 size_t i;
672
673 /* Set read pointer to zero: The read of HR_FDBMAX (read-only register)
674 * should reset the internal pointer. But, that doesn't work. The vendor
675 * suggested a subsequent write as workaround. Same for HR_FDBRDH below.
676 */
677 hellcreek_read(hellcreek, HR_FDBMAX);
678 hellcreek_write(hellcreek, 0x00, HR_FDBMAX);
679
680 /* We have to read the complete table, because the switch/driver might
681 * enter new entries anywhere.
682 */
683 for (i = 0; i < hellcreek->fdb_entries; ++i) {
684 unsigned char addr[ETH_ALEN];
685 u16 meta, mac;
686
687 meta = hellcreek_read(hellcreek, HR_FDBMDRD);
688 mac = hellcreek_read(hellcreek, HR_FDBRDL);
689 addr[5] = mac & 0xff;
690 addr[4] = (mac & 0xff00) >> 8;
691 mac = hellcreek_read(hellcreek, HR_FDBRDM);
692 addr[3] = mac & 0xff;
693 addr[2] = (mac & 0xff00) >> 8;
694 mac = hellcreek_read(hellcreek, HR_FDBRDH);
695 addr[1] = mac & 0xff;
696 addr[0] = (mac & 0xff00) >> 8;
697
698 /* Force next entry */
699 hellcreek_write(hellcreek, 0x00, HR_FDBRDH);
700
701 if (memcmp(addr, dest, ETH_ALEN))
702 continue;
703
704 /* Match found */
705 entry->idx = i;
706 entry->portmask = (meta & HR_FDBMDRD_PORTMASK_MASK) >>
707 HR_FDBMDRD_PORTMASK_SHIFT;
708 entry->age = (meta & HR_FDBMDRD_AGE_MASK) >>
709 HR_FDBMDRD_AGE_SHIFT;
710 entry->is_obt = !!(meta & HR_FDBMDRD_OBT);
711 entry->pass_blocked = !!(meta & HR_FDBMDRD_PASS_BLOCKED);
712 entry->is_static = !!(meta & HR_FDBMDRD_STATIC);
713 entry->reprio_tc = (meta & HR_FDBMDRD_REPRIO_TC_MASK) >>
714 HR_FDBMDRD_REPRIO_TC_SHIFT;
715 entry->reprio_en = !!(meta & HR_FDBMDRD_REPRIO_EN);
716 memcpy(entry->mac, addr, sizeof(addr));
717
718 return 0;
719 }
720
721 return -ENOENT;
722 }
723
724 static int hellcreek_fdb_add(struct dsa_switch *ds, int port,
725 const unsigned char *addr, u16 vid)
726 {
727 struct hellcreek_fdb_entry entry = { 0 };
728 struct hellcreek *hellcreek = ds->priv;
729 int ret;
730
731 dev_dbg(hellcreek->dev, "Add FDB entry for MAC=%pM\n", addr);
732
733 mutex_lock(&hellcreek->reg_lock);
734
735 ret = hellcreek_fdb_get(hellcreek, addr, &entry);
736 if (ret) {
737 /* Not found */
738 memcpy(entry.mac, addr, sizeof(entry.mac));
739 entry.portmask = BIT(port);
740
741 ret = __hellcreek_fdb_add(hellcreek, &entry);
742 if (ret) {
743 dev_err(hellcreek->dev, "Failed to add FDB entry!\n");
744 goto out;
745 }
746 } else {
747 /* Found */
748 ret = __hellcreek_fdb_del(hellcreek, &entry);
749 if (ret) {
750 dev_err(hellcreek->dev, "Failed to delete FDB entry!\n");
751 goto out;
752 }
753
754 entry.portmask |= BIT(port);
755
756 ret = __hellcreek_fdb_add(hellcreek, &entry);
757 if (ret) {
758 dev_err(hellcreek->dev, "Failed to add FDB entry!\n");
759 goto out;
760 }
761 }
762
763 out:
764 mutex_unlock(&hellcreek->reg_lock);
765
766 return ret;
767 }
768
769 static int hellcreek_fdb_del(struct dsa_switch *ds, int port,
770 const unsigned char *addr, u16 vid)
771 {
772 struct hellcreek_fdb_entry entry = { 0 };
773 struct hellcreek *hellcreek = ds->priv;
774 int ret;
775
776 dev_dbg(hellcreek->dev, "Delete FDB entry for MAC=%pM\n", addr);
777
778 mutex_lock(&hellcreek->reg_lock);
779
780 ret = hellcreek_fdb_get(hellcreek, addr, &entry);
781 if (ret) {
782 /* Not found */
783 dev_err(hellcreek->dev, "FDB entry for deletion not found!\n");
784 } else {
785 /* Found */
786 ret = __hellcreek_fdb_del(hellcreek, &entry);
787 if (ret) {
788 dev_err(hellcreek->dev, "Failed to delete FDB entry!\n");
789 goto out;
790 }
791
792 entry.portmask &= ~BIT(port);
793
794 if (entry.portmask != 0x00) {
795 ret = __hellcreek_fdb_add(hellcreek, &entry);
796 if (ret) {
797 dev_err(hellcreek->dev, "Failed to add FDB entry!\n");
798 goto out;
799 }
800 }
801 }
802
803 out:
804 mutex_unlock(&hellcreek->reg_lock);
805
806 return ret;
807 }
808
809 static int hellcreek_fdb_dump(struct dsa_switch *ds, int port,
810 dsa_fdb_dump_cb_t *cb, void *data)
811 {
812 struct hellcreek *hellcreek = ds->priv;
813 u16 entries;
814 size_t i;
815
816 mutex_lock(&hellcreek->reg_lock);
817
818 /* Set read pointer to zero: The read of HR_FDBMAX (read-only register)
819 * should reset the internal pointer. But, that doesn't work. The vendor
820 * suggested a subsequent write as workaround. Same for HR_FDBRDH below.
821 */
822 entries = hellcreek_read(hellcreek, HR_FDBMAX);
823 hellcreek_write(hellcreek, 0x00, HR_FDBMAX);
824
825 dev_dbg(hellcreek->dev, "FDB dump for port %d, entries=%d!\n", port, entries);
826
827 /* Read table */
828 for (i = 0; i < hellcreek->fdb_entries; ++i) {
829 unsigned char null_addr[ETH_ALEN] = { 0 };
830 struct hellcreek_fdb_entry entry = { 0 };
831 u16 meta, mac;
832
833 meta = hellcreek_read(hellcreek, HR_FDBMDRD);
834 mac = hellcreek_read(hellcreek, HR_FDBRDL);
835 entry.mac[5] = mac & 0xff;
836 entry.mac[4] = (mac & 0xff00) >> 8;
837 mac = hellcreek_read(hellcreek, HR_FDBRDM);
838 entry.mac[3] = mac & 0xff;
839 entry.mac[2] = (mac & 0xff00) >> 8;
840 mac = hellcreek_read(hellcreek, HR_FDBRDH);
841 entry.mac[1] = mac & 0xff;
842 entry.mac[0] = (mac & 0xff00) >> 8;
843
844 /* Force next entry */
845 hellcreek_write(hellcreek, 0x00, HR_FDBRDH);
846
847 /* Check valid */
848 if (!memcmp(entry.mac, null_addr, ETH_ALEN))
849 continue;
850
851 entry.portmask = (meta & HR_FDBMDRD_PORTMASK_MASK) >>
852 HR_FDBMDRD_PORTMASK_SHIFT;
853 entry.is_static = !!(meta & HR_FDBMDRD_STATIC);
854
855 /* Check port mask */
856 if (!(entry.portmask & BIT(port)))
857 continue;
858
859 cb(entry.mac, 0, entry.is_static, data);
860 }
861
862 mutex_unlock(&hellcreek->reg_lock);
863
864 return 0;
865 }
866
867 static int hellcreek_vlan_filtering(struct dsa_switch *ds, int port,
868 bool vlan_filtering)
869 {
870 struct hellcreek *hellcreek = ds->priv;
871
872 dev_dbg(hellcreek->dev, "%s VLAN filtering on port %d\n",
873 vlan_filtering ? "Enable" : "Disable", port);
874
875 /* Configure port to drop packages with not known vids */
876 hellcreek_setup_ingressflt(hellcreek, port, vlan_filtering);
877
878 /* Enable VLAN awareness on the switch. This save due to
879 * ds->vlan_filtering_is_global.
880 */
881 hellcreek_setup_vlan_awareness(hellcreek, vlan_filtering);
882
883 return 0;
884 }
885
886 static int hellcreek_enable_ip_core(struct hellcreek *hellcreek)
887 {
888 int ret;
889 u16 val;
890
891 mutex_lock(&hellcreek->reg_lock);
892
893 val = hellcreek_read(hellcreek, HR_CTRL_C);
894 val |= HR_CTRL_C_ENABLE;
895 hellcreek_write(hellcreek, val, HR_CTRL_C);
896 ret = hellcreek_wait_until_transitioned(hellcreek);
897
898 mutex_unlock(&hellcreek->reg_lock);
899
900 return ret;
901 }
902
903 static void hellcreek_setup_cpu_and_tunnel_port(struct hellcreek *hellcreek)
904 {
905 struct hellcreek_port *tunnel_port = &hellcreek->ports[TUNNEL_PORT];
906 struct hellcreek_port *cpu_port = &hellcreek->ports[CPU_PORT];
907 u16 ptcfg = 0;
908
909 ptcfg |= HR_PTCFG_LEARNING_EN | HR_PTCFG_ADMIN_EN;
910
911 mutex_lock(&hellcreek->reg_lock);
912
913 hellcreek_select_port(hellcreek, CPU_PORT);
914 hellcreek_write(hellcreek, ptcfg, HR_PTCFG);
915
916 hellcreek_select_port(hellcreek, TUNNEL_PORT);
917 hellcreek_write(hellcreek, ptcfg, HR_PTCFG);
918
919 cpu_port->ptcfg = ptcfg;
920 tunnel_port->ptcfg = ptcfg;
921
922 mutex_unlock(&hellcreek->reg_lock);
923 }
924
925 static void hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek)
926 {
927 int i;
928
929 /* The switch has multiple egress queues per port. The queue is selected
930 * via the PCP field in the VLAN header. The switch internally deals
931 * with traffic classes instead of PCP values and this mapping is
932 * configurable.
933 *
934 * The default mapping is (PCP - TC):
935 * 7 - 7
936 * 6 - 6
937 * 5 - 5
938 * 4 - 4
939 * 3 - 3
940 * 2 - 1
941 * 1 - 0
942 * 0 - 2
943 *
944 * The default should be an identity mapping.
945 */
946
947 for (i = 0; i < 8; ++i) {
948 mutex_lock(&hellcreek->reg_lock);
949
950 hellcreek_select_prio(hellcreek, i);
951 hellcreek_write(hellcreek,
952 i << HR_PRTCCFG_PCP_TC_MAP_SHIFT,
953 HR_PRTCCFG);
954
955 mutex_unlock(&hellcreek->reg_lock);
956 }
957 }
958
959 static int hellcreek_setup_fdb(struct hellcreek *hellcreek)
960 {
961 static struct hellcreek_fdb_entry ptp = {
962 /* MAC: 01-1B-19-00-00-00 */
963 .mac = { 0x01, 0x1b, 0x19, 0x00, 0x00, 0x00 },
964 .portmask = 0x03, /* Management ports */
965 .age = 0,
966 .is_obt = 0,
967 .pass_blocked = 0,
968 .is_static = 1,
969 .reprio_tc = 6, /* TC: 6 as per IEEE 802.1AS */
970 .reprio_en = 1,
971 };
972 static struct hellcreek_fdb_entry p2p = {
973 /* MAC: 01-80-C2-00-00-0E */
974 .mac = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e },
975 .portmask = 0x03, /* Management ports */
976 .age = 0,
977 .is_obt = 0,
978 .pass_blocked = 0,
979 .is_static = 1,
980 .reprio_tc = 6, /* TC: 6 as per IEEE 802.1AS */
981 .reprio_en = 1,
982 };
983 int ret;
984
985 mutex_lock(&hellcreek->reg_lock);
986 ret = __hellcreek_fdb_add(hellcreek, &ptp);
987 if (ret)
988 goto out;
989 ret = __hellcreek_fdb_add(hellcreek, &p2p);
990 out:
991 mutex_unlock(&hellcreek->reg_lock);
992
993 return ret;
994 }
995
996 static int hellcreek_setup(struct dsa_switch *ds)
997 {
998 struct hellcreek *hellcreek = ds->priv;
999 u16 swcfg = 0;
1000 int ret, i;
1001
1002 dev_dbg(hellcreek->dev, "Set up the switch\n");
1003
1004 /* Let's go */
1005 ret = hellcreek_enable_ip_core(hellcreek);
1006 if (ret) {
1007 dev_err(hellcreek->dev, "Failed to enable IP core!\n");
1008 return ret;
1009 }
1010
1011 /* Enable CPU/Tunnel ports */
1012 hellcreek_setup_cpu_and_tunnel_port(hellcreek);
1013
1014 /* Switch config: Keep defaults, enable FDB aging and learning and tag
1015 * each frame from/to cpu port for DSA tagging. Also enable the length
1016 * aware shaping mode. This eliminates the need for Qbv guard bands.
1017 */
1018 swcfg |= HR_SWCFG_FDBAGE_EN |
1019 HR_SWCFG_FDBLRN_EN |
1020 HR_SWCFG_ALWAYS_OBT |
1021 (HR_SWCFG_LAS_ON << HR_SWCFG_LAS_MODE_SHIFT);
1022 hellcreek->swcfg = swcfg;
1023 hellcreek_write(hellcreek, swcfg, HR_SWCFG);
1024
1025 /* Initial vlan membership to reflect port separation */
1026 for (i = 0; i < ds->num_ports; ++i) {
1027 if (!dsa_is_user_port(ds, i))
1028 continue;
1029
1030 hellcreek_setup_vlan_membership(ds, i, true);
1031 }
1032
1033 /* Configure PCP <-> TC mapping */
1034 hellcreek_setup_tc_identity_mapping(hellcreek);
1035
1036 /* Allow VLAN configurations while not filtering which is the default
1037 * for new DSA drivers.
1038 */
1039 ds->configure_vlan_while_not_filtering = true;
1040
1041 /* The VLAN awareness is a global switch setting. Therefore, mixed vlan
1042 * filtering setups are not supported.
1043 */
1044 ds->vlan_filtering_is_global = true;
1045
1046 /* Intercept _all_ PTP multicast traffic */
1047 ret = hellcreek_setup_fdb(hellcreek);
1048 if (ret) {
1049 dev_err(hellcreek->dev,
1050 "Failed to insert static PTP FDB entries\n");
1051 return ret;
1052 }
1053
1054 return 0;
1055 }
1056
1057 static void hellcreek_phylink_validate(struct dsa_switch *ds, int port,
1058 unsigned long *supported,
1059 struct phylink_link_state *state)
1060 {
1061 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
1062 struct hellcreek *hellcreek = ds->priv;
1063
1064 dev_dbg(hellcreek->dev, "Phylink validate for port %d\n", port);
1065
1066 /* The MAC settings are a hardware configuration option and cannot be
1067 * changed at run time or by strapping. Therefore the attached PHYs
1068 * should be programmed to only advertise settings which are supported
1069 * by the hardware.
1070 */
1071 if (hellcreek->pdata->is_100_mbits)
1072 phylink_set(mask, 100baseT_Full);
1073 else
1074 phylink_set(mask, 1000baseT_Full);
1075
1076 bitmap_and(supported, supported, mask,
1077 __ETHTOOL_LINK_MODE_MASK_NBITS);
1078 bitmap_and(state->advertising, state->advertising, mask,
1079 __ETHTOOL_LINK_MODE_MASK_NBITS);
1080 }
1081
1082 static int
1083 hellcreek_port_prechangeupper(struct dsa_switch *ds, int port,
1084 struct netdev_notifier_changeupper_info *info)
1085 {
1086 struct hellcreek *hellcreek = ds->priv;
1087 bool used = true;
1088 int ret = -EBUSY;
1089 u16 vid;
1090 int i;
1091
1092 dev_dbg(hellcreek->dev, "Pre change upper for port %d\n", port);
1093
1094 /*
1095 * Deny VLAN devices on top of lan ports with the same VLAN ids, because
1096 * it breaks the port separation due to the private VLANs. Example:
1097 *
1098 * lan0.100 *and* lan1.100 cannot be used in parallel. However, lan0.99
1099 * and lan1.100 works.
1100 */
1101
1102 if (!is_vlan_dev(info->upper_dev))
1103 return 0;
1104
1105 vid = vlan_dev_vlan_id(info->upper_dev);
1106
1107 /* For all ports, check bitmaps */
1108 mutex_lock(&hellcreek->vlan_lock);
1109 for (i = 0; i < hellcreek->pdata->num_ports; ++i) {
1110 if (!dsa_is_user_port(ds, i))
1111 continue;
1112
1113 if (port == i)
1114 continue;
1115
1116 used = used && test_bit(vid, hellcreek->ports[i].vlan_dev_bitmap);
1117 }
1118
1119 if (used)
1120 goto out;
1121
1122 /* Update bitmap */
1123 set_bit(vid, hellcreek->ports[port].vlan_dev_bitmap);
1124
1125 ret = 0;
1126
1127 out:
1128 mutex_unlock(&hellcreek->vlan_lock);
1129
1130 return ret;
1131 }
1132
1133 static const struct dsa_switch_ops hellcreek_ds_ops = {
1134 .get_ethtool_stats = hellcreek_get_ethtool_stats,
1135 .get_sset_count = hellcreek_get_sset_count,
1136 .get_strings = hellcreek_get_strings,
1137 .get_tag_protocol = hellcreek_get_tag_protocol,
1138 .get_ts_info = hellcreek_get_ts_info,
1139 .phylink_validate = hellcreek_phylink_validate,
1140 .port_bridge_join = hellcreek_port_bridge_join,
1141 .port_bridge_leave = hellcreek_port_bridge_leave,
1142 .port_disable = hellcreek_port_disable,
1143 .port_enable = hellcreek_port_enable,
1144 .port_fdb_add = hellcreek_fdb_add,
1145 .port_fdb_del = hellcreek_fdb_del,
1146 .port_fdb_dump = hellcreek_fdb_dump,
1147 .port_hwtstamp_set = hellcreek_port_hwtstamp_set,
1148 .port_hwtstamp_get = hellcreek_port_hwtstamp_get,
1149 .port_prechangeupper = hellcreek_port_prechangeupper,
1150 .port_rxtstamp = hellcreek_port_rxtstamp,
1151 .port_stp_state_set = hellcreek_port_stp_state_set,
1152 .port_txtstamp = hellcreek_port_txtstamp,
1153 .port_vlan_add = hellcreek_vlan_add,
1154 .port_vlan_del = hellcreek_vlan_del,
1155 .port_vlan_filtering = hellcreek_vlan_filtering,
1156 .setup = hellcreek_setup,
1157 };
1158
1159 static int hellcreek_probe(struct platform_device *pdev)
1160 {
1161 struct device *dev = &pdev->dev;
1162 struct hellcreek *hellcreek;
1163 struct resource *res;
1164 int ret, i;
1165
1166 hellcreek = devm_kzalloc(dev, sizeof(*hellcreek), GFP_KERNEL);
1167 if (!hellcreek)
1168 return -ENOMEM;
1169
1170 hellcreek->vidmbrcfg = devm_kcalloc(dev, VLAN_N_VID,
1171 sizeof(*hellcreek->vidmbrcfg),
1172 GFP_KERNEL);
1173 if (!hellcreek->vidmbrcfg)
1174 return -ENOMEM;
1175
1176 hellcreek->pdata = of_device_get_match_data(dev);
1177
1178 hellcreek->ports = devm_kcalloc(dev, hellcreek->pdata->num_ports,
1179 sizeof(*hellcreek->ports),
1180 GFP_KERNEL);
1181 if (!hellcreek->ports)
1182 return -ENOMEM;
1183
1184 for (i = 0; i < hellcreek->pdata->num_ports; ++i) {
1185 struct hellcreek_port *port = &hellcreek->ports[i];
1186
1187 port->counter_values =
1188 devm_kcalloc(dev,
1189 ARRAY_SIZE(hellcreek_counter),
1190 sizeof(*port->counter_values),
1191 GFP_KERNEL);
1192 if (!port->counter_values)
1193 return -ENOMEM;
1194
1195 port->vlan_dev_bitmap =
1196 devm_kcalloc(dev,
1197 BITS_TO_LONGS(VLAN_N_VID),
1198 sizeof(unsigned long),
1199 GFP_KERNEL);
1200 if (!port->vlan_dev_bitmap)
1201 return -ENOMEM;
1202
1203 port->hellcreek = hellcreek;
1204 port->port = i;
1205 }
1206
1207 mutex_init(&hellcreek->reg_lock);
1208 mutex_init(&hellcreek->vlan_lock);
1209 mutex_init(&hellcreek->ptp_lock);
1210
1211 hellcreek->dev = dev;
1212
1213 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tsn");
1214 if (!res) {
1215 dev_err(dev, "No memory region provided!\n");
1216 return -ENODEV;
1217 }
1218
1219 hellcreek->base = devm_ioremap_resource(dev, res);
1220 if (IS_ERR(hellcreek->base)) {
1221 dev_err(dev, "No memory available!\n");
1222 return PTR_ERR(hellcreek->base);
1223 }
1224
1225 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ptp");
1226 if (!res) {
1227 dev_err(dev, "No PTP memory region provided!\n");
1228 return -ENODEV;
1229 }
1230
1231 hellcreek->ptp_base = devm_ioremap_resource(dev, res);
1232 if (IS_ERR(hellcreek->ptp_base)) {
1233 dev_err(dev, "No memory available!\n");
1234 return PTR_ERR(hellcreek->ptp_base);
1235 }
1236
1237 ret = hellcreek_detect(hellcreek);
1238 if (ret) {
1239 dev_err(dev, "No (known) chip found!\n");
1240 return ret;
1241 }
1242
1243 ret = hellcreek_wait_until_ready(hellcreek);
1244 if (ret) {
1245 dev_err(dev, "Switch didn't become ready!\n");
1246 return ret;
1247 }
1248
1249 hellcreek_feature_detect(hellcreek);
1250
1251 hellcreek->ds = devm_kzalloc(dev, sizeof(*hellcreek->ds), GFP_KERNEL);
1252 if (!hellcreek->ds)
1253 return -ENOMEM;
1254
1255 hellcreek->ds->dev = dev;
1256 hellcreek->ds->priv = hellcreek;
1257 hellcreek->ds->ops = &hellcreek_ds_ops;
1258 hellcreek->ds->num_ports = hellcreek->pdata->num_ports;
1259 hellcreek->ds->num_tx_queues = HELLCREEK_NUM_EGRESS_QUEUES;
1260
1261 ret = dsa_register_switch(hellcreek->ds);
1262 if (ret) {
1263 dev_err_probe(dev, ret, "Unable to register switch\n");
1264 return ret;
1265 }
1266
1267 ret = hellcreek_ptp_setup(hellcreek);
1268 if (ret) {
1269 dev_err(dev, "Failed to setup PTP!\n");
1270 goto err_ptp_setup;
1271 }
1272
1273 ret = hellcreek_hwtstamp_setup(hellcreek);
1274 if (ret) {
1275 dev_err(dev, "Failed to setup hardware timestamping!\n");
1276 goto err_tstamp_setup;
1277 }
1278
1279 platform_set_drvdata(pdev, hellcreek);
1280
1281 return 0;
1282
1283 err_tstamp_setup:
1284 hellcreek_ptp_free(hellcreek);
1285 err_ptp_setup:
1286 dsa_unregister_switch(hellcreek->ds);
1287
1288 return ret;
1289 }
1290
1291 static int hellcreek_remove(struct platform_device *pdev)
1292 {
1293 struct hellcreek *hellcreek = platform_get_drvdata(pdev);
1294
1295 hellcreek_hwtstamp_free(hellcreek);
1296 hellcreek_ptp_free(hellcreek);
1297 dsa_unregister_switch(hellcreek->ds);
1298 platform_set_drvdata(pdev, NULL);
1299
1300 return 0;
1301 }
1302
1303 static const struct hellcreek_platform_data de1soc_r1_pdata = {
1304 .num_ports = 4,
1305 .is_100_mbits = 1,
1306 .qbv_support = 1,
1307 .qbv_on_cpu_port = 1,
1308 .qbu_support = 0,
1309 .module_id = 0x4c30,
1310 };
1311
1312 static const struct of_device_id hellcreek_of_match[] = {
1313 {
1314 .compatible = "hirschmann,hellcreek-de1soc-r1",
1315 .data = &de1soc_r1_pdata,
1316 },
1317 { /* sentinel */ },
1318 };
1319 MODULE_DEVICE_TABLE(of, hellcreek_of_match);
1320
1321 static struct platform_driver hellcreek_driver = {
1322 .probe = hellcreek_probe,
1323 .remove = hellcreek_remove,
1324 .driver = {
1325 .name = "hellcreek",
1326 .of_match_table = hellcreek_of_match,
1327 },
1328 };
1329 module_platform_driver(hellcreek_driver);
1330
1331 MODULE_AUTHOR("Kurt Kanzenbach <kurt@linutronix.de>");
1332 MODULE_DESCRIPTION("Hirschmann Hellcreek driver");
1333 MODULE_LICENSE("Dual MIT/GPL");