1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2019-2021 NXP
4 * This is an umbrella module for all network switches that are
5 * register-compatible with Ocelot and that perform I/O to their host CPU
6 * through an NPI (Node Processor Interface) Ethernet port.
8 #include <uapi/linux/if_bridge.h>
9 #include <soc/mscc/ocelot_vcap.h>
10 #include <soc/mscc/ocelot_qsys.h>
11 #include <soc/mscc/ocelot_sys.h>
12 #include <soc/mscc/ocelot_dev.h>
13 #include <soc/mscc/ocelot_ana.h>
14 #include <soc/mscc/ocelot_ptp.h>
15 #include <soc/mscc/ocelot.h>
16 #include <linux/dsa/8021q.h>
17 #include <linux/dsa/ocelot.h>
18 #include <linux/platform_device.h>
19 #include <linux/ptp_classify.h>
20 #include <linux/module.h>
21 #include <linux/of_net.h>
22 #include <linux/pci.h>
24 #include <net/pkt_sched.h>
28 /* Set up VCAP ES0 rules for pushing a tag_8021q VLAN towards the CPU such that
29 * the tagger can perform RX source port identification.
31 static int felix_tag_8021q_vlan_add_rx(struct felix *felix, int port, u16 vid)
33 struct ocelot_vcap_filter *outer_tagging_rule;
34 struct ocelot *ocelot = &felix->ocelot;
35 struct dsa_switch *ds = felix->ds;
36 int key_length, upstream, err;
38 key_length = ocelot->vcap[VCAP_ES0].keys[VCAP_ES0_IGR_PORT].length;
39 upstream = dsa_upstream_port(ds, port);
41 outer_tagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter),
43 if (!outer_tagging_rule)
46 outer_tagging_rule->key_type = OCELOT_VCAP_KEY_ANY;
47 outer_tagging_rule->prio = 1;
48 outer_tagging_rule->id.cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port);
49 outer_tagging_rule->id.tc_offload = false;
50 outer_tagging_rule->block_id = VCAP_ES0;
51 outer_tagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD;
52 outer_tagging_rule->lookup = 0;
53 outer_tagging_rule->ingress_port.value = port;
54 outer_tagging_rule->ingress_port.mask = GENMASK(key_length - 1, 0);
55 outer_tagging_rule->egress_port.value = upstream;
56 outer_tagging_rule->egress_port.mask = GENMASK(key_length - 1, 0);
57 outer_tagging_rule->action.push_outer_tag = OCELOT_ES0_TAG;
58 outer_tagging_rule->action.tag_a_tpid_sel = OCELOT_TAG_TPID_SEL_8021AD;
59 outer_tagging_rule->action.tag_a_vid_sel = 1;
60 outer_tagging_rule->action.vid_a_val = vid;
62 err = ocelot_vcap_filter_add(ocelot, outer_tagging_rule, NULL);
64 kfree(outer_tagging_rule);
69 static int felix_tag_8021q_vlan_del_rx(struct felix *felix, int port, u16 vid)
71 struct ocelot_vcap_filter *outer_tagging_rule;
72 struct ocelot_vcap_block *block_vcap_es0;
73 struct ocelot *ocelot = &felix->ocelot;
75 block_vcap_es0 = &ocelot->block[VCAP_ES0];
77 outer_tagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_es0,
79 if (!outer_tagging_rule)
82 return ocelot_vcap_filter_del(ocelot, outer_tagging_rule);
85 /* Set up VCAP IS1 rules for stripping the tag_8021q VLAN on TX and VCAP IS2
86 * rules for steering those tagged packets towards the correct destination port
88 static int felix_tag_8021q_vlan_add_tx(struct felix *felix, int port, u16 vid)
90 struct ocelot_vcap_filter *untagging_rule, *redirect_rule;
91 struct ocelot *ocelot = &felix->ocelot;
92 struct dsa_switch *ds = felix->ds;
95 untagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL);
99 redirect_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL);
100 if (!redirect_rule) {
101 kfree(untagging_rule);
105 upstream = dsa_upstream_port(ds, port);
107 untagging_rule->key_type = OCELOT_VCAP_KEY_ANY;
108 untagging_rule->ingress_port_mask = BIT(upstream);
109 untagging_rule->vlan.vid.value = vid;
110 untagging_rule->vlan.vid.mask = VLAN_VID_MASK;
111 untagging_rule->prio = 1;
112 untagging_rule->id.cookie = OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port);
113 untagging_rule->id.tc_offload = false;
114 untagging_rule->block_id = VCAP_IS1;
115 untagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD;
116 untagging_rule->lookup = 0;
117 untagging_rule->action.vlan_pop_cnt_ena = true;
118 untagging_rule->action.vlan_pop_cnt = 1;
119 untagging_rule->action.pag_override_mask = 0xff;
120 untagging_rule->action.pag_val = port;
122 err = ocelot_vcap_filter_add(ocelot, untagging_rule, NULL);
124 kfree(untagging_rule);
125 kfree(redirect_rule);
129 redirect_rule->key_type = OCELOT_VCAP_KEY_ANY;
130 redirect_rule->ingress_port_mask = BIT(upstream);
131 redirect_rule->pag = port;
132 redirect_rule->prio = 1;
133 redirect_rule->id.cookie = OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port);
134 redirect_rule->id.tc_offload = false;
135 redirect_rule->block_id = VCAP_IS2;
136 redirect_rule->type = OCELOT_VCAP_FILTER_OFFLOAD;
137 redirect_rule->lookup = 0;
138 redirect_rule->action.mask_mode = OCELOT_MASK_MODE_REDIRECT;
139 redirect_rule->action.port_mask = BIT(port);
141 err = ocelot_vcap_filter_add(ocelot, redirect_rule, NULL);
143 ocelot_vcap_filter_del(ocelot, untagging_rule);
144 kfree(redirect_rule);
151 static int felix_tag_8021q_vlan_del_tx(struct felix *felix, int port, u16 vid)
153 struct ocelot_vcap_filter *untagging_rule, *redirect_rule;
154 struct ocelot_vcap_block *block_vcap_is1;
155 struct ocelot_vcap_block *block_vcap_is2;
156 struct ocelot *ocelot = &felix->ocelot;
159 block_vcap_is1 = &ocelot->block[VCAP_IS1];
160 block_vcap_is2 = &ocelot->block[VCAP_IS2];
162 untagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is1,
167 err = ocelot_vcap_filter_del(ocelot, untagging_rule);
171 redirect_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is2,
176 return ocelot_vcap_filter_del(ocelot, redirect_rule);
179 static int felix_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid,
182 struct ocelot *ocelot = ds->priv;
185 /* tag_8021q.c assumes we are implementing this via port VLAN
186 * membership, which we aren't. So we don't need to add any VCAP filter
189 if (!dsa_is_user_port(ds, port))
192 err = felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid);
196 err = felix_tag_8021q_vlan_add_tx(ocelot_to_felix(ocelot), port, vid);
198 felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid);
205 static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid)
207 struct ocelot *ocelot = ds->priv;
210 if (!dsa_is_user_port(ds, port))
213 err = felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid);
217 err = felix_tag_8021q_vlan_del_tx(ocelot_to_felix(ocelot), port, vid);
219 felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid);
226 /* Alternatively to using the NPI functionality, that same hardware MAC
227 * connected internally to the enetc or fman DSA master can be configured to
228 * use the software-defined tag_8021q frame format. As far as the hardware is
229 * concerned, it thinks it is a "dumb switch" - the queues of the CPU port
230 * module are now disconnected from it, but can still be accessed through
231 * register-based MMIO.
233 static void felix_8021q_cpu_port_init(struct ocelot *ocelot, int port)
235 mutex_lock(&ocelot->fwd_domain_lock);
237 ocelot->ports[port]->is_dsa_8021q_cpu = true;
240 /* Overwrite PGID_CPU with the non-tagging port */
241 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, PGID_CPU);
243 ocelot_apply_bridge_fwd_mask(ocelot, true);
245 mutex_unlock(&ocelot->fwd_domain_lock);
248 static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port)
250 mutex_lock(&ocelot->fwd_domain_lock);
252 ocelot->ports[port]->is_dsa_8021q_cpu = false;
254 /* Restore PGID_CPU */
255 ocelot_write_rix(ocelot, BIT(ocelot->num_phys_ports), ANA_PGID_PGID,
258 ocelot_apply_bridge_fwd_mask(ocelot, true);
260 mutex_unlock(&ocelot->fwd_domain_lock);
263 /* On switches with no extraction IRQ wired, trapped packets need to be
264 * replicated over Ethernet as well, otherwise we'd get no notification of
265 * their arrival when using the ocelot-8021q tagging protocol.
267 static int felix_update_trapping_destinations(struct dsa_switch *ds,
268 bool using_tag_8021q)
270 struct ocelot *ocelot = ds->priv;
271 struct felix *felix = ocelot_to_felix(ocelot);
272 struct ocelot_vcap_filter *trap;
273 enum ocelot_mask_mode mask_mode;
274 unsigned long port_mask;
279 if (!felix->info->quirk_no_xtr_irq)
282 /* Figure out the current CPU port */
283 dsa_switch_for_each_cpu_port(dp, ds) {
288 /* We are sure that "cpu" was found, otherwise
289 * dsa_tree_setup_default_cpu() would have failed earlier.
292 /* Make sure all traps are set up for that destination */
293 list_for_each_entry(trap, &ocelot->traps, trap_list) {
294 /* Figure out the current trapping destination */
295 if (using_tag_8021q) {
296 /* Redirect to the tag_8021q CPU port. If timestamps
297 * are necessary, also copy trapped packets to the CPU
300 mask_mode = OCELOT_MASK_MODE_REDIRECT;
301 port_mask = BIT(cpu);
302 cpu_copy_ena = !!trap->take_ts;
304 /* Trap packets only to the CPU port module, which is
305 * redirected to the NPI port (the DSA CPU port)
307 mask_mode = OCELOT_MASK_MODE_PERMIT_DENY;
312 if (trap->action.mask_mode == mask_mode &&
313 trap->action.port_mask == port_mask &&
314 trap->action.cpu_copy_ena == cpu_copy_ena)
317 trap->action.mask_mode = mask_mode;
318 trap->action.port_mask = port_mask;
319 trap->action.cpu_copy_ena = cpu_copy_ena;
321 err = ocelot_vcap_filter_replace(ocelot, trap);
329 static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu)
331 struct ocelot *ocelot = ds->priv;
332 unsigned long cpu_flood;
336 felix_8021q_cpu_port_init(ocelot, cpu);
338 dsa_switch_for_each_available_port(dp, ds) {
339 /* This overwrites ocelot_init():
340 * Do not forward BPDU frames to the CPU port module,
342 * - When these packets are injected from the tag_8021q
343 * CPU port, we want them to go out, not loop back
345 * - STP traffic ingressing on a user port should go to
346 * the tag_8021q CPU port, not to the hardware CPU
349 ocelot_write_gix(ocelot,
350 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0),
351 ANA_PORT_CPU_FWD_BPDU_CFG, dp->index);
354 /* In tag_8021q mode, the CPU port module is unused, except for PTP
355 * frames. So we want to disable flooding of any kind to the CPU port
356 * module, since packets going there will end in a black hole.
358 cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports));
359 ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_UC);
360 ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC);
361 ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_BC);
363 err = dsa_tag_8021q_register(ds, htons(ETH_P_8021AD));
367 err = felix_update_trapping_destinations(ds, true);
369 goto out_tag_8021q_unregister;
371 /* The ownership of the CPU port module's queues might have just been
372 * transferred to the tag_8021q tagger from the NPI-based tagger.
373 * So there might still be all sorts of crap in the queues. On the
374 * other hand, the MMIO-based matching of PTP frames is very brittle,
375 * so we need to be careful that there are no extra frames to be
376 * dequeued over MMIO, since we would never know to discard them.
378 ocelot_drain_cpu_queue(ocelot, 0);
382 out_tag_8021q_unregister:
383 dsa_tag_8021q_unregister(ds);
387 static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu)
389 struct ocelot *ocelot = ds->priv;
393 err = felix_update_trapping_destinations(ds, false);
395 dev_err(ds->dev, "felix_teardown_mmio_filtering returned %d",
398 dsa_tag_8021q_unregister(ds);
400 dsa_switch_for_each_available_port(dp, ds) {
401 /* Restore the logic from ocelot_init:
402 * do not forward BPDU frames to the front ports.
404 ocelot_write_gix(ocelot,
405 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff),
406 ANA_PORT_CPU_FWD_BPDU_CFG,
410 felix_8021q_cpu_port_deinit(ocelot, cpu);
413 /* The CPU port module is connected to the Node Processor Interface (NPI). This
414 * is the mode through which frames can be injected from and extracted to an
415 * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU
416 * running Linux, and this forms a DSA setup together with the enetc or fman
419 static void felix_npi_port_init(struct ocelot *ocelot, int port)
423 ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M |
424 QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port),
427 /* NPI port Injection/Extraction configuration */
428 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR,
429 ocelot->npi_xtr_prefix);
430 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR,
431 ocelot->npi_inj_prefix);
433 /* Disable transmission of pause frames */
434 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0);
437 static void felix_npi_port_deinit(struct ocelot *ocelot, int port)
439 /* Restore hardware defaults */
440 int unused_port = ocelot->num_phys_ports + 2;
444 ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPU_PORT(unused_port),
447 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR,
448 OCELOT_TAG_PREFIX_DISABLED);
449 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR,
450 OCELOT_TAG_PREFIX_DISABLED);
452 /* Enable transmission of pause frames */
453 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1);
456 static int felix_setup_tag_npi(struct dsa_switch *ds, int cpu)
458 struct ocelot *ocelot = ds->priv;
459 unsigned long cpu_flood;
461 felix_npi_port_init(ocelot, cpu);
463 /* Include the CPU port module (and indirectly, the NPI port)
464 * in the forwarding mask for unknown unicast - the hardware
465 * default value for ANA_FLOODING_FLD_UNICAST excludes
466 * BIT(ocelot->num_phys_ports), and so does ocelot_init,
467 * since Ocelot relies on whitelisting MAC addresses towards
469 * We do this because DSA does not yet perform RX filtering,
470 * and the NPI port does not perform source address learning,
471 * so traffic sent to Linux is effectively unknown from the
472 * switch's perspective.
474 cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports));
475 ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_UC);
476 ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_MC);
477 ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_BC);
482 static void felix_teardown_tag_npi(struct dsa_switch *ds, int cpu)
484 struct ocelot *ocelot = ds->priv;
486 felix_npi_port_deinit(ocelot, cpu);
489 static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu,
490 enum dsa_tag_protocol proto)
495 case DSA_TAG_PROTO_SEVILLE:
496 case DSA_TAG_PROTO_OCELOT:
497 err = felix_setup_tag_npi(ds, cpu);
499 case DSA_TAG_PROTO_OCELOT_8021Q:
500 err = felix_setup_tag_8021q(ds, cpu);
503 err = -EPROTONOSUPPORT;
509 static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu,
510 enum dsa_tag_protocol proto)
513 case DSA_TAG_PROTO_SEVILLE:
514 case DSA_TAG_PROTO_OCELOT:
515 felix_teardown_tag_npi(ds, cpu);
517 case DSA_TAG_PROTO_OCELOT_8021Q:
518 felix_teardown_tag_8021q(ds, cpu);
525 /* This always leaves the switch in a consistent state, because although the
526 * tag_8021q setup can fail, the NPI setup can't. So either the change is made,
527 * or the restoration is guaranteed to work.
529 static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu,
530 enum dsa_tag_protocol proto)
532 struct ocelot *ocelot = ds->priv;
533 struct felix *felix = ocelot_to_felix(ocelot);
534 enum dsa_tag_protocol old_proto = felix->tag_proto;
537 if (proto != DSA_TAG_PROTO_SEVILLE &&
538 proto != DSA_TAG_PROTO_OCELOT &&
539 proto != DSA_TAG_PROTO_OCELOT_8021Q)
540 return -EPROTONOSUPPORT;
542 felix_del_tag_protocol(ds, cpu, old_proto);
544 err = felix_set_tag_protocol(ds, cpu, proto);
546 felix_set_tag_protocol(ds, cpu, old_proto);
550 felix->tag_proto = proto;
555 static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds,
557 enum dsa_tag_protocol mp)
559 struct ocelot *ocelot = ds->priv;
560 struct felix *felix = ocelot_to_felix(ocelot);
562 return felix->tag_proto;
565 static int felix_set_ageing_time(struct dsa_switch *ds,
566 unsigned int ageing_time)
568 struct ocelot *ocelot = ds->priv;
570 ocelot_set_ageing_time(ocelot, ageing_time);
575 static void felix_port_fast_age(struct dsa_switch *ds, int port)
577 struct ocelot *ocelot = ds->priv;
580 err = ocelot_mact_flush(ocelot, port);
582 dev_err(ds->dev, "Flushing MAC table on port %d returned %pe\n",
586 static int felix_fdb_dump(struct dsa_switch *ds, int port,
587 dsa_fdb_dump_cb_t *cb, void *data)
589 struct ocelot *ocelot = ds->priv;
591 return ocelot_fdb_dump(ocelot, port, cb, data);
594 static int felix_fdb_add(struct dsa_switch *ds, int port,
595 const unsigned char *addr, u16 vid,
598 struct ocelot *ocelot = ds->priv;
600 return ocelot_fdb_add(ocelot, port, addr, vid);
603 static int felix_fdb_del(struct dsa_switch *ds, int port,
604 const unsigned char *addr, u16 vid,
607 struct ocelot *ocelot = ds->priv;
609 return ocelot_fdb_del(ocelot, port, addr, vid);
612 static int felix_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag lag,
613 const unsigned char *addr, u16 vid,
616 struct ocelot *ocelot = ds->priv;
618 return ocelot_lag_fdb_add(ocelot, lag.dev, addr, vid);
621 static int felix_lag_fdb_del(struct dsa_switch *ds, struct dsa_lag lag,
622 const unsigned char *addr, u16 vid,
625 struct ocelot *ocelot = ds->priv;
627 return ocelot_lag_fdb_del(ocelot, lag.dev, addr, vid);
630 static int felix_mdb_add(struct dsa_switch *ds, int port,
631 const struct switchdev_obj_port_mdb *mdb,
634 struct ocelot *ocelot = ds->priv;
636 return ocelot_port_mdb_add(ocelot, port, mdb);
639 static int felix_mdb_del(struct dsa_switch *ds, int port,
640 const struct switchdev_obj_port_mdb *mdb,
643 struct ocelot *ocelot = ds->priv;
645 return ocelot_port_mdb_del(ocelot, port, mdb);
648 static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port,
651 struct ocelot *ocelot = ds->priv;
653 return ocelot_bridge_stp_state_set(ocelot, port, state);
656 static int felix_pre_bridge_flags(struct dsa_switch *ds, int port,
657 struct switchdev_brport_flags val,
658 struct netlink_ext_ack *extack)
660 struct ocelot *ocelot = ds->priv;
662 return ocelot_port_pre_bridge_flags(ocelot, port, val);
665 static int felix_bridge_flags(struct dsa_switch *ds, int port,
666 struct switchdev_brport_flags val,
667 struct netlink_ext_ack *extack)
669 struct ocelot *ocelot = ds->priv;
671 ocelot_port_bridge_flags(ocelot, port, val);
676 static int felix_bridge_join(struct dsa_switch *ds, int port,
677 struct dsa_bridge bridge, bool *tx_fwd_offload)
679 struct ocelot *ocelot = ds->priv;
681 ocelot_port_bridge_join(ocelot, port, bridge.dev);
686 static void felix_bridge_leave(struct dsa_switch *ds, int port,
687 struct dsa_bridge bridge)
689 struct ocelot *ocelot = ds->priv;
691 ocelot_port_bridge_leave(ocelot, port, bridge.dev);
694 static int felix_lag_join(struct dsa_switch *ds, int port,
696 struct netdev_lag_upper_info *info)
698 struct ocelot *ocelot = ds->priv;
700 return ocelot_port_lag_join(ocelot, port, lag.dev, info);
703 static int felix_lag_leave(struct dsa_switch *ds, int port,
706 struct ocelot *ocelot = ds->priv;
708 ocelot_port_lag_leave(ocelot, port, lag.dev);
713 static int felix_lag_change(struct dsa_switch *ds, int port)
715 struct dsa_port *dp = dsa_to_port(ds, port);
716 struct ocelot *ocelot = ds->priv;
718 ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled);
723 static int felix_vlan_prepare(struct dsa_switch *ds, int port,
724 const struct switchdev_obj_port_vlan *vlan,
725 struct netlink_ext_ack *extack)
727 struct ocelot *ocelot = ds->priv;
728 u16 flags = vlan->flags;
730 /* Ocelot switches copy frames as-is to the CPU, so the flags:
731 * egress-untagged or not, pvid or not, make no difference. This
732 * behavior is already better than what DSA just tries to approximate
733 * when it installs the VLAN with the same flags on the CPU port.
734 * Just accept any configuration, and don't let ocelot deny installing
735 * multiple native VLANs on the NPI port, because the switch doesn't
736 * look at the port tag settings towards the NPI interface anyway.
738 if (port == ocelot->npi)
741 return ocelot_vlan_prepare(ocelot, port, vlan->vid,
742 flags & BRIDGE_VLAN_INFO_PVID,
743 flags & BRIDGE_VLAN_INFO_UNTAGGED,
747 static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled,
748 struct netlink_ext_ack *extack)
750 struct ocelot *ocelot = ds->priv;
752 return ocelot_port_vlan_filtering(ocelot, port, enabled, extack);
755 static int felix_vlan_add(struct dsa_switch *ds, int port,
756 const struct switchdev_obj_port_vlan *vlan,
757 struct netlink_ext_ack *extack)
759 struct ocelot *ocelot = ds->priv;
760 u16 flags = vlan->flags;
763 err = felix_vlan_prepare(ds, port, vlan, extack);
767 return ocelot_vlan_add(ocelot, port, vlan->vid,
768 flags & BRIDGE_VLAN_INFO_PVID,
769 flags & BRIDGE_VLAN_INFO_UNTAGGED);
772 static int felix_vlan_del(struct dsa_switch *ds, int port,
773 const struct switchdev_obj_port_vlan *vlan)
775 struct ocelot *ocelot = ds->priv;
777 return ocelot_vlan_del(ocelot, port, vlan->vid);
780 static void felix_phylink_get_caps(struct dsa_switch *ds, int port,
781 struct phylink_config *config)
783 struct ocelot *ocelot = ds->priv;
785 /* This driver does not make use of the speed, duplex, pause or the
786 * advertisement in its mac_config, so it is safe to mark this driver
789 config->legacy_pre_march2020 = false;
791 __set_bit(ocelot->ports[port]->phy_mode,
792 config->supported_interfaces);
795 static void felix_phylink_validate(struct dsa_switch *ds, int port,
796 unsigned long *supported,
797 struct phylink_link_state *state)
799 struct ocelot *ocelot = ds->priv;
800 struct felix *felix = ocelot_to_felix(ocelot);
802 if (felix->info->phylink_validate)
803 felix->info->phylink_validate(ocelot, port, supported, state);
806 static struct phylink_pcs *felix_phylink_mac_select_pcs(struct dsa_switch *ds,
808 phy_interface_t iface)
810 struct ocelot *ocelot = ds->priv;
811 struct felix *felix = ocelot_to_felix(ocelot);
812 struct phylink_pcs *pcs = NULL;
814 if (felix->pcs && felix->pcs[port])
815 pcs = felix->pcs[port];
820 static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port,
821 unsigned int link_an_mode,
822 phy_interface_t interface)
824 struct ocelot *ocelot = ds->priv;
826 ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface,
830 static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port,
831 unsigned int link_an_mode,
832 phy_interface_t interface,
833 struct phy_device *phydev,
834 int speed, int duplex,
835 bool tx_pause, bool rx_pause)
837 struct ocelot *ocelot = ds->priv;
838 struct felix *felix = ocelot_to_felix(ocelot);
840 ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode,
841 interface, speed, duplex, tx_pause, rx_pause,
844 if (felix->info->port_sched_speed_set)
845 felix->info->port_sched_speed_set(ocelot, port, speed);
848 static void felix_port_qos_map_init(struct ocelot *ocelot, int port)
852 ocelot_rmw_gix(ocelot,
853 ANA_PORT_QOS_CFG_QOS_PCP_ENA,
854 ANA_PORT_QOS_CFG_QOS_PCP_ENA,
858 for (i = 0; i < OCELOT_NUM_TC * 2; i++) {
859 ocelot_rmw_ix(ocelot,
860 (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) |
861 ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i),
862 ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL |
863 ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M,
864 ANA_PORT_PCP_DEI_MAP,
869 static void felix_get_strings(struct dsa_switch *ds, int port,
870 u32 stringset, u8 *data)
872 struct ocelot *ocelot = ds->priv;
874 return ocelot_get_strings(ocelot, port, stringset, data);
877 static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data)
879 struct ocelot *ocelot = ds->priv;
881 ocelot_get_ethtool_stats(ocelot, port, data);
884 static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset)
886 struct ocelot *ocelot = ds->priv;
888 return ocelot_get_sset_count(ocelot, port, sset);
891 static int felix_get_ts_info(struct dsa_switch *ds, int port,
892 struct ethtool_ts_info *info)
894 struct ocelot *ocelot = ds->priv;
896 return ocelot_get_ts_info(ocelot, port, info);
899 static int felix_parse_ports_node(struct felix *felix,
900 struct device_node *ports_node,
901 phy_interface_t *port_phy_modes)
903 struct ocelot *ocelot = &felix->ocelot;
904 struct device *dev = felix->ocelot.dev;
905 struct device_node *child;
907 for_each_available_child_of_node(ports_node, child) {
908 phy_interface_t phy_mode;
912 /* Get switch port number from DT */
913 if (of_property_read_u32(child, "reg", &port) < 0) {
914 dev_err(dev, "Port number not defined in device tree "
915 "(property \"reg\")\n");
920 /* Get PHY mode from DT */
921 err = of_get_phy_mode(child, &phy_mode);
923 dev_err(dev, "Failed to read phy-mode or "
924 "phy-interface-type property for port %d\n",
930 err = felix->info->prevalidate_phy_mode(ocelot, port, phy_mode);
932 dev_err(dev, "Unsupported PHY mode %s on port %d\n",
933 phy_modes(phy_mode), port);
938 port_phy_modes[port] = phy_mode;
944 static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes)
946 struct device *dev = felix->ocelot.dev;
947 struct device_node *switch_node;
948 struct device_node *ports_node;
951 switch_node = dev->of_node;
953 ports_node = of_get_child_by_name(switch_node, "ports");
955 ports_node = of_get_child_by_name(switch_node, "ethernet-ports");
957 dev_err(dev, "Incorrect bindings: absent \"ports\" or \"ethernet-ports\" node\n");
961 err = felix_parse_ports_node(felix, ports_node, port_phy_modes);
962 of_node_put(ports_node);
967 static int felix_init_structs(struct felix *felix, int num_phys_ports)
969 struct ocelot *ocelot = &felix->ocelot;
970 phy_interface_t *port_phy_modes;
974 ocelot->num_phys_ports = num_phys_ports;
975 ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports,
976 sizeof(struct ocelot_port *), GFP_KERNEL);
980 ocelot->map = felix->info->map;
981 ocelot->stats_layout = felix->info->stats_layout;
982 ocelot->num_stats = felix->info->num_stats;
983 ocelot->num_mact_rows = felix->info->num_mact_rows;
984 ocelot->vcap = felix->info->vcap;
985 ocelot->vcap_pol.base = felix->info->vcap_pol_base;
986 ocelot->vcap_pol.max = felix->info->vcap_pol_max;
987 ocelot->vcap_pol.base2 = felix->info->vcap_pol_base2;
988 ocelot->vcap_pol.max2 = felix->info->vcap_pol_max2;
989 ocelot->ops = felix->info->ops;
990 ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT;
991 ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT;
992 ocelot->devlink = felix->ds->devlink;
994 port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t),
999 err = felix_parse_dt(felix, port_phy_modes);
1001 kfree(port_phy_modes);
1005 for (i = 0; i < TARGET_MAX; i++) {
1006 struct regmap *target;
1008 if (!felix->info->target_io_res[i].name)
1011 memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
1012 res.flags = IORESOURCE_MEM;
1013 res.start += felix->switch_base;
1014 res.end += felix->switch_base;
1016 target = felix->info->init_regmap(ocelot, &res);
1017 if (IS_ERR(target)) {
1018 dev_err(ocelot->dev,
1019 "Failed to map device memory space\n");
1020 kfree(port_phy_modes);
1021 return PTR_ERR(target);
1024 ocelot->targets[i] = target;
1027 err = ocelot_regfields_init(ocelot, felix->info->regfields);
1029 dev_err(ocelot->dev, "failed to init reg fields map\n");
1030 kfree(port_phy_modes);
1034 for (port = 0; port < num_phys_ports; port++) {
1035 struct ocelot_port *ocelot_port;
1036 struct regmap *target;
1038 ocelot_port = devm_kzalloc(ocelot->dev,
1039 sizeof(struct ocelot_port),
1042 dev_err(ocelot->dev,
1043 "failed to allocate port memory\n");
1044 kfree(port_phy_modes);
1048 memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
1049 res.flags = IORESOURCE_MEM;
1050 res.start += felix->switch_base;
1051 res.end += felix->switch_base;
1053 target = felix->info->init_regmap(ocelot, &res);
1054 if (IS_ERR(target)) {
1055 dev_err(ocelot->dev,
1056 "Failed to map memory space for port %d\n",
1058 kfree(port_phy_modes);
1059 return PTR_ERR(target);
1062 ocelot_port->phy_mode = port_phy_modes[port];
1063 ocelot_port->ocelot = ocelot;
1064 ocelot_port->target = target;
1065 ocelot->ports[port] = ocelot_port;
1068 kfree(port_phy_modes);
1070 if (felix->info->mdio_bus_alloc) {
1071 err = felix->info->mdio_bus_alloc(ocelot);
1079 static void ocelot_port_purge_txtstamp_skb(struct ocelot *ocelot, int port,
1080 struct sk_buff *skb)
1082 struct ocelot_port *ocelot_port = ocelot->ports[port];
1083 struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone;
1084 struct sk_buff *skb_match = NULL, *skb_tmp;
1085 unsigned long flags;
1090 spin_lock_irqsave(&ocelot_port->tx_skbs.lock, flags);
1092 skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) {
1095 __skb_unlink(skb, &ocelot_port->tx_skbs);
1100 spin_unlock_irqrestore(&ocelot_port->tx_skbs.lock, flags);
1102 WARN_ONCE(!skb_match,
1103 "Could not find skb clone in TX timestamping list\n");
1106 #define work_to_xmit_work(w) \
1107 container_of((w), struct felix_deferred_xmit_work, work)
1109 static void felix_port_deferred_xmit(struct kthread_work *work)
1111 struct felix_deferred_xmit_work *xmit_work = work_to_xmit_work(work);
1112 struct dsa_switch *ds = xmit_work->dp->ds;
1113 struct sk_buff *skb = xmit_work->skb;
1114 u32 rew_op = ocelot_ptp_rew_op(skb);
1115 struct ocelot *ocelot = ds->priv;
1116 int port = xmit_work->dp->index;
1120 if (ocelot_can_inject(ocelot, 0))
1124 } while (--retries);
1127 dev_err(ocelot->dev, "port %d failed to inject skb\n",
1129 ocelot_port_purge_txtstamp_skb(ocelot, port, skb);
1134 ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb);
1140 static int felix_connect_tag_protocol(struct dsa_switch *ds,
1141 enum dsa_tag_protocol proto)
1143 struct ocelot_8021q_tagger_data *tagger_data;
1146 case DSA_TAG_PROTO_OCELOT_8021Q:
1147 tagger_data = ocelot_8021q_tagger_data(ds);
1148 tagger_data->xmit_work_fn = felix_port_deferred_xmit;
1150 case DSA_TAG_PROTO_OCELOT:
1151 case DSA_TAG_PROTO_SEVILLE:
1154 return -EPROTONOSUPPORT;
1158 /* Hardware initialization done here so that we can allocate structures with
1159 * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing
1160 * us to allocate structures twice (leak memory) and map PCI memory twice
1161 * (which will not work).
1163 static int felix_setup(struct dsa_switch *ds)
1165 struct ocelot *ocelot = ds->priv;
1166 struct felix *felix = ocelot_to_felix(ocelot);
1167 struct dsa_port *dp;
1170 err = felix_init_structs(felix, ds->num_ports);
1174 err = ocelot_init(ocelot);
1176 goto out_mdiobus_free;
1179 err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps);
1181 dev_err(ocelot->dev,
1182 "Timestamp initialization failed\n");
1187 dsa_switch_for_each_available_port(dp, ds) {
1188 ocelot_init_port(ocelot, dp->index);
1190 /* Set the default QoS Classification based on PCP and DEI
1193 felix_port_qos_map_init(ocelot, dp->index);
1196 err = ocelot_devlink_sb_register(ocelot);
1198 goto out_deinit_ports;
1200 dsa_switch_for_each_cpu_port(dp, ds) {
1201 /* The initial tag protocol is NPI which always returns 0, so
1202 * there's no real point in checking for errors.
1204 felix_set_tag_protocol(ds, dp->index, felix->tag_proto);
1208 ds->mtu_enforcement_ingress = true;
1209 ds->assisted_learning_on_cpu_port = true;
1214 dsa_switch_for_each_available_port(dp, ds)
1215 ocelot_deinit_port(ocelot, dp->index);
1217 ocelot_deinit_timestamp(ocelot);
1218 ocelot_deinit(ocelot);
1221 if (felix->info->mdio_bus_free)
1222 felix->info->mdio_bus_free(ocelot);
1227 static void felix_teardown(struct dsa_switch *ds)
1229 struct ocelot *ocelot = ds->priv;
1230 struct felix *felix = ocelot_to_felix(ocelot);
1231 struct dsa_port *dp;
1233 dsa_switch_for_each_cpu_port(dp, ds) {
1234 felix_del_tag_protocol(ds, dp->index, felix->tag_proto);
1238 dsa_switch_for_each_available_port(dp, ds)
1239 ocelot_deinit_port(ocelot, dp->index);
1241 ocelot_devlink_sb_unregister(ocelot);
1242 ocelot_deinit_timestamp(ocelot);
1243 ocelot_deinit(ocelot);
1245 if (felix->info->mdio_bus_free)
1246 felix->info->mdio_bus_free(ocelot);
1249 static int felix_hwtstamp_get(struct dsa_switch *ds, int port,
1252 struct ocelot *ocelot = ds->priv;
1254 return ocelot_hwstamp_get(ocelot, port, ifr);
1257 static int felix_hwtstamp_set(struct dsa_switch *ds, int port,
1260 struct ocelot *ocelot = ds->priv;
1261 struct felix *felix = ocelot_to_felix(ocelot);
1262 bool using_tag_8021q;
1265 err = ocelot_hwstamp_set(ocelot, port, ifr);
1269 using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q;
1271 return felix_update_trapping_destinations(ds, using_tag_8021q);
1274 static bool felix_check_xtr_pkt(struct ocelot *ocelot, unsigned int ptp_type)
1276 struct felix *felix = ocelot_to_felix(ocelot);
1279 if (felix->tag_proto != DSA_TAG_PROTO_OCELOT_8021Q)
1282 if (!felix->info->quirk_no_xtr_irq)
1285 if (ptp_type == PTP_CLASS_NONE)
1288 while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp)) {
1289 struct sk_buff *skb;
1292 err = ocelot_xtr_poll_frame(ocelot, grp, &skb);
1296 /* We trap to the CPU port module all PTP frames, but
1297 * felix_rxtstamp() only gets called for event frames.
1298 * So we need to avoid sending duplicate general
1299 * message frames by running a second BPF classifier
1300 * here and dropping those.
1302 __skb_push(skb, ETH_HLEN);
1304 type = ptp_classify_raw(skb);
1306 __skb_pull(skb, ETH_HLEN);
1308 if (type == PTP_CLASS_NONE) {
1318 ocelot_drain_cpu_queue(ocelot, 0);
1323 static bool felix_rxtstamp(struct dsa_switch *ds, int port,
1324 struct sk_buff *skb, unsigned int type)
1326 u32 tstamp_lo = OCELOT_SKB_CB(skb)->tstamp_lo;
1327 struct skb_shared_hwtstamps *shhwtstamps;
1328 struct ocelot *ocelot = ds->priv;
1329 struct timespec64 ts;
1333 /* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb
1334 * for RX timestamping. Then free it, and poll for its copy through
1335 * MMIO in the CPU port module, and inject that into the stack from
1336 * ocelot_xtr_poll().
1338 if (felix_check_xtr_pkt(ocelot, type)) {
1343 ocelot_ptp_gettime64(&ocelot->ptp_info, &ts);
1344 tstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
1346 tstamp_hi = tstamp >> 32;
1347 if ((tstamp & 0xffffffff) < tstamp_lo)
1350 tstamp = ((u64)tstamp_hi << 32) | tstamp_lo;
1352 shhwtstamps = skb_hwtstamps(skb);
1353 memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
1354 shhwtstamps->hwtstamp = tstamp;
1358 static void felix_txtstamp(struct dsa_switch *ds, int port,
1359 struct sk_buff *skb)
1361 struct ocelot *ocelot = ds->priv;
1362 struct sk_buff *clone = NULL;
1367 if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) {
1368 dev_err_ratelimited(ds->dev,
1369 "port %d delivering skb without TX timestamp\n",
1375 OCELOT_SKB_CB(skb)->clone = clone;
1378 static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
1380 struct ocelot *ocelot = ds->priv;
1382 ocelot_port_set_maxlen(ocelot, port, new_mtu);
1387 static int felix_get_max_mtu(struct dsa_switch *ds, int port)
1389 struct ocelot *ocelot = ds->priv;
1391 return ocelot_get_max_mtu(ocelot, port);
1394 static int felix_cls_flower_add(struct dsa_switch *ds, int port,
1395 struct flow_cls_offload *cls, bool ingress)
1397 struct ocelot *ocelot = ds->priv;
1398 struct felix *felix = ocelot_to_felix(ocelot);
1399 bool using_tag_8021q;
1402 err = ocelot_cls_flower_replace(ocelot, port, cls, ingress);
1406 using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q;
1408 return felix_update_trapping_destinations(ds, using_tag_8021q);
1411 static int felix_cls_flower_del(struct dsa_switch *ds, int port,
1412 struct flow_cls_offload *cls, bool ingress)
1414 struct ocelot *ocelot = ds->priv;
1416 return ocelot_cls_flower_destroy(ocelot, port, cls, ingress);
1419 static int felix_cls_flower_stats(struct dsa_switch *ds, int port,
1420 struct flow_cls_offload *cls, bool ingress)
1422 struct ocelot *ocelot = ds->priv;
1424 return ocelot_cls_flower_stats(ocelot, port, cls, ingress);
1427 static int felix_port_policer_add(struct dsa_switch *ds, int port,
1428 struct dsa_mall_policer_tc_entry *policer)
1430 struct ocelot *ocelot = ds->priv;
1431 struct ocelot_policer pol = {
1432 .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8,
1433 .burst = policer->burst,
1436 return ocelot_port_policer_add(ocelot, port, &pol);
1439 static void felix_port_policer_del(struct dsa_switch *ds, int port)
1441 struct ocelot *ocelot = ds->priv;
1443 ocelot_port_policer_del(ocelot, port);
1446 static int felix_port_setup_tc(struct dsa_switch *ds, int port,
1447 enum tc_setup_type type,
1450 struct ocelot *ocelot = ds->priv;
1451 struct felix *felix = ocelot_to_felix(ocelot);
1453 if (felix->info->port_setup_tc)
1454 return felix->info->port_setup_tc(ds, port, type, type_data);
1459 static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index,
1461 struct devlink_sb_pool_info *pool_info)
1463 struct ocelot *ocelot = ds->priv;
1465 return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info);
1468 static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index,
1469 u16 pool_index, u32 size,
1470 enum devlink_sb_threshold_type threshold_type,
1471 struct netlink_ext_ack *extack)
1473 struct ocelot *ocelot = ds->priv;
1475 return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size,
1476 threshold_type, extack);
1479 static int felix_sb_port_pool_get(struct dsa_switch *ds, int port,
1480 unsigned int sb_index, u16 pool_index,
1483 struct ocelot *ocelot = ds->priv;
1485 return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index,
1489 static int felix_sb_port_pool_set(struct dsa_switch *ds, int port,
1490 unsigned int sb_index, u16 pool_index,
1491 u32 threshold, struct netlink_ext_ack *extack)
1493 struct ocelot *ocelot = ds->priv;
1495 return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index,
1499 static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port,
1500 unsigned int sb_index, u16 tc_index,
1501 enum devlink_sb_pool_type pool_type,
1502 u16 *p_pool_index, u32 *p_threshold)
1504 struct ocelot *ocelot = ds->priv;
1506 return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index,
1507 pool_type, p_pool_index,
1511 static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port,
1512 unsigned int sb_index, u16 tc_index,
1513 enum devlink_sb_pool_type pool_type,
1514 u16 pool_index, u32 threshold,
1515 struct netlink_ext_ack *extack)
1517 struct ocelot *ocelot = ds->priv;
1519 return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index,
1520 pool_type, pool_index, threshold,
1524 static int felix_sb_occ_snapshot(struct dsa_switch *ds,
1525 unsigned int sb_index)
1527 struct ocelot *ocelot = ds->priv;
1529 return ocelot_sb_occ_snapshot(ocelot, sb_index);
1532 static int felix_sb_occ_max_clear(struct dsa_switch *ds,
1533 unsigned int sb_index)
1535 struct ocelot *ocelot = ds->priv;
1537 return ocelot_sb_occ_max_clear(ocelot, sb_index);
1540 static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port,
1541 unsigned int sb_index, u16 pool_index,
1542 u32 *p_cur, u32 *p_max)
1544 struct ocelot *ocelot = ds->priv;
1546 return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index,
1550 static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port,
1551 unsigned int sb_index, u16 tc_index,
1552 enum devlink_sb_pool_type pool_type,
1553 u32 *p_cur, u32 *p_max)
1555 struct ocelot *ocelot = ds->priv;
1557 return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index,
1558 pool_type, p_cur, p_max);
1561 static int felix_mrp_add(struct dsa_switch *ds, int port,
1562 const struct switchdev_obj_mrp *mrp)
1564 struct ocelot *ocelot = ds->priv;
1566 return ocelot_mrp_add(ocelot, port, mrp);
1569 static int felix_mrp_del(struct dsa_switch *ds, int port,
1570 const struct switchdev_obj_mrp *mrp)
1572 struct ocelot *ocelot = ds->priv;
1574 return ocelot_mrp_add(ocelot, port, mrp);
1578 felix_mrp_add_ring_role(struct dsa_switch *ds, int port,
1579 const struct switchdev_obj_ring_role_mrp *mrp)
1581 struct ocelot *ocelot = ds->priv;
1583 return ocelot_mrp_add_ring_role(ocelot, port, mrp);
1587 felix_mrp_del_ring_role(struct dsa_switch *ds, int port,
1588 const struct switchdev_obj_ring_role_mrp *mrp)
1590 struct ocelot *ocelot = ds->priv;
1592 return ocelot_mrp_del_ring_role(ocelot, port, mrp);
1595 const struct dsa_switch_ops felix_switch_ops = {
1596 .get_tag_protocol = felix_get_tag_protocol,
1597 .change_tag_protocol = felix_change_tag_protocol,
1598 .connect_tag_protocol = felix_connect_tag_protocol,
1599 .setup = felix_setup,
1600 .teardown = felix_teardown,
1601 .set_ageing_time = felix_set_ageing_time,
1602 .get_strings = felix_get_strings,
1603 .get_ethtool_stats = felix_get_ethtool_stats,
1604 .get_sset_count = felix_get_sset_count,
1605 .get_ts_info = felix_get_ts_info,
1606 .phylink_get_caps = felix_phylink_get_caps,
1607 .phylink_validate = felix_phylink_validate,
1608 .phylink_mac_select_pcs = felix_phylink_mac_select_pcs,
1609 .phylink_mac_link_down = felix_phylink_mac_link_down,
1610 .phylink_mac_link_up = felix_phylink_mac_link_up,
1611 .port_fast_age = felix_port_fast_age,
1612 .port_fdb_dump = felix_fdb_dump,
1613 .port_fdb_add = felix_fdb_add,
1614 .port_fdb_del = felix_fdb_del,
1615 .lag_fdb_add = felix_lag_fdb_add,
1616 .lag_fdb_del = felix_lag_fdb_del,
1617 .port_mdb_add = felix_mdb_add,
1618 .port_mdb_del = felix_mdb_del,
1619 .port_pre_bridge_flags = felix_pre_bridge_flags,
1620 .port_bridge_flags = felix_bridge_flags,
1621 .port_bridge_join = felix_bridge_join,
1622 .port_bridge_leave = felix_bridge_leave,
1623 .port_lag_join = felix_lag_join,
1624 .port_lag_leave = felix_lag_leave,
1625 .port_lag_change = felix_lag_change,
1626 .port_stp_state_set = felix_bridge_stp_state_set,
1627 .port_vlan_filtering = felix_vlan_filtering,
1628 .port_vlan_add = felix_vlan_add,
1629 .port_vlan_del = felix_vlan_del,
1630 .port_hwtstamp_get = felix_hwtstamp_get,
1631 .port_hwtstamp_set = felix_hwtstamp_set,
1632 .port_rxtstamp = felix_rxtstamp,
1633 .port_txtstamp = felix_txtstamp,
1634 .port_change_mtu = felix_change_mtu,
1635 .port_max_mtu = felix_get_max_mtu,
1636 .port_policer_add = felix_port_policer_add,
1637 .port_policer_del = felix_port_policer_del,
1638 .cls_flower_add = felix_cls_flower_add,
1639 .cls_flower_del = felix_cls_flower_del,
1640 .cls_flower_stats = felix_cls_flower_stats,
1641 .port_setup_tc = felix_port_setup_tc,
1642 .devlink_sb_pool_get = felix_sb_pool_get,
1643 .devlink_sb_pool_set = felix_sb_pool_set,
1644 .devlink_sb_port_pool_get = felix_sb_port_pool_get,
1645 .devlink_sb_port_pool_set = felix_sb_port_pool_set,
1646 .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get,
1647 .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set,
1648 .devlink_sb_occ_snapshot = felix_sb_occ_snapshot,
1649 .devlink_sb_occ_max_clear = felix_sb_occ_max_clear,
1650 .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get,
1651 .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get,
1652 .port_mrp_add = felix_mrp_add,
1653 .port_mrp_del = felix_mrp_del,
1654 .port_mrp_add_ring_role = felix_mrp_add_ring_role,
1655 .port_mrp_del_ring_role = felix_mrp_del_ring_role,
1656 .tag_8021q_vlan_add = felix_tag_8021q_vlan_add,
1657 .tag_8021q_vlan_del = felix_tag_8021q_vlan_del,
1660 struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port)
1662 struct felix *felix = ocelot_to_felix(ocelot);
1663 struct dsa_switch *ds = felix->ds;
1665 if (!dsa_is_user_port(ds, port))
1668 return dsa_to_port(ds, port)->slave;
1671 int felix_netdev_to_port(struct net_device *dev)
1673 struct dsa_port *dp;
1675 dp = dsa_port_from_netdev(dev);