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 static int felix_tag_8021q_rxvlan_add(struct felix *felix, int port, u16 vid,
29 bool pvid, bool untagged)
31 struct ocelot_vcap_filter *outer_tagging_rule;
32 struct ocelot *ocelot = &felix->ocelot;
33 struct dsa_switch *ds = felix->ds;
34 int key_length, upstream, err;
36 /* We don't need to install the rxvlan into the other ports' filtering
37 * tables, because we're just pushing the rxvlan when sending towards
43 key_length = ocelot->vcap[VCAP_ES0].keys[VCAP_ES0_IGR_PORT].length;
44 upstream = dsa_upstream_port(ds, port);
46 outer_tagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter),
48 if (!outer_tagging_rule)
51 outer_tagging_rule->key_type = OCELOT_VCAP_KEY_ANY;
52 outer_tagging_rule->prio = 1;
53 outer_tagging_rule->id.cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port);
54 outer_tagging_rule->id.tc_offload = false;
55 outer_tagging_rule->block_id = VCAP_ES0;
56 outer_tagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD;
57 outer_tagging_rule->lookup = 0;
58 outer_tagging_rule->ingress_port.value = port;
59 outer_tagging_rule->ingress_port.mask = GENMASK(key_length - 1, 0);
60 outer_tagging_rule->egress_port.value = upstream;
61 outer_tagging_rule->egress_port.mask = GENMASK(key_length - 1, 0);
62 outer_tagging_rule->action.push_outer_tag = OCELOT_ES0_TAG;
63 outer_tagging_rule->action.tag_a_tpid_sel = OCELOT_TAG_TPID_SEL_8021AD;
64 outer_tagging_rule->action.tag_a_vid_sel = 1;
65 outer_tagging_rule->action.vid_a_val = vid;
67 err = ocelot_vcap_filter_add(ocelot, outer_tagging_rule, NULL);
69 kfree(outer_tagging_rule);
74 static int felix_tag_8021q_txvlan_add(struct felix *felix, int port, u16 vid,
75 bool pvid, bool untagged)
77 struct ocelot_vcap_filter *untagging_rule, *redirect_rule;
78 struct ocelot *ocelot = &felix->ocelot;
79 struct dsa_switch *ds = felix->ds;
82 /* tag_8021q.c assumes we are implementing this via port VLAN
83 * membership, which we aren't. So we don't need to add any VCAP filter
86 if (ocelot->ports[port]->is_dsa_8021q_cpu)
89 untagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL);
93 redirect_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL);
95 kfree(untagging_rule);
99 upstream = dsa_upstream_port(ds, port);
101 untagging_rule->key_type = OCELOT_VCAP_KEY_ANY;
102 untagging_rule->ingress_port_mask = BIT(upstream);
103 untagging_rule->vlan.vid.value = vid;
104 untagging_rule->vlan.vid.mask = VLAN_VID_MASK;
105 untagging_rule->prio = 1;
106 untagging_rule->id.cookie = OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port);
107 untagging_rule->id.tc_offload = false;
108 untagging_rule->block_id = VCAP_IS1;
109 untagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD;
110 untagging_rule->lookup = 0;
111 untagging_rule->action.vlan_pop_cnt_ena = true;
112 untagging_rule->action.vlan_pop_cnt = 1;
113 untagging_rule->action.pag_override_mask = 0xff;
114 untagging_rule->action.pag_val = port;
116 err = ocelot_vcap_filter_add(ocelot, untagging_rule, NULL);
118 kfree(untagging_rule);
119 kfree(redirect_rule);
123 redirect_rule->key_type = OCELOT_VCAP_KEY_ANY;
124 redirect_rule->ingress_port_mask = BIT(upstream);
125 redirect_rule->pag = port;
126 redirect_rule->prio = 1;
127 redirect_rule->id.cookie = OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port);
128 redirect_rule->id.tc_offload = false;
129 redirect_rule->block_id = VCAP_IS2;
130 redirect_rule->type = OCELOT_VCAP_FILTER_OFFLOAD;
131 redirect_rule->lookup = 0;
132 redirect_rule->action.mask_mode = OCELOT_MASK_MODE_REDIRECT;
133 redirect_rule->action.port_mask = BIT(port);
135 err = ocelot_vcap_filter_add(ocelot, redirect_rule, NULL);
137 ocelot_vcap_filter_del(ocelot, untagging_rule);
138 kfree(redirect_rule);
145 static int felix_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid,
148 bool untagged = flags & BRIDGE_VLAN_INFO_UNTAGGED;
149 bool pvid = flags & BRIDGE_VLAN_INFO_PVID;
150 struct ocelot *ocelot = ds->priv;
152 if (vid_is_dsa_8021q_rxvlan(vid))
153 return felix_tag_8021q_rxvlan_add(ocelot_to_felix(ocelot),
154 port, vid, pvid, untagged);
156 if (vid_is_dsa_8021q_txvlan(vid))
157 return felix_tag_8021q_txvlan_add(ocelot_to_felix(ocelot),
158 port, vid, pvid, untagged);
163 static int felix_tag_8021q_rxvlan_del(struct felix *felix, int port, u16 vid)
165 struct ocelot_vcap_filter *outer_tagging_rule;
166 struct ocelot_vcap_block *block_vcap_es0;
167 struct ocelot *ocelot = &felix->ocelot;
169 block_vcap_es0 = &ocelot->block[VCAP_ES0];
171 outer_tagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_es0,
173 /* In rxvlan_add, we had the "if (!pvid) return 0" logic to avoid
174 * installing outer tagging ES0 rules where they weren't needed.
175 * But in rxvlan_del, the API doesn't give us the "flags" anymore,
176 * so that forces us to be slightly sloppy here, and just assume that
177 * if we didn't find an outer_tagging_rule it means that there was
178 * none in the first place, i.e. rxvlan_del is called on a non-pvid
179 * port. This is most probably true though.
181 if (!outer_tagging_rule)
184 return ocelot_vcap_filter_del(ocelot, outer_tagging_rule);
187 static int felix_tag_8021q_txvlan_del(struct felix *felix, int port, u16 vid)
189 struct ocelot_vcap_filter *untagging_rule, *redirect_rule;
190 struct ocelot_vcap_block *block_vcap_is1;
191 struct ocelot_vcap_block *block_vcap_is2;
192 struct ocelot *ocelot = &felix->ocelot;
195 if (ocelot->ports[port]->is_dsa_8021q_cpu)
198 block_vcap_is1 = &ocelot->block[VCAP_IS1];
199 block_vcap_is2 = &ocelot->block[VCAP_IS2];
201 untagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is1,
206 err = ocelot_vcap_filter_del(ocelot, untagging_rule);
210 redirect_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is2,
215 return ocelot_vcap_filter_del(ocelot, redirect_rule);
218 static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid)
220 struct ocelot *ocelot = ds->priv;
222 if (vid_is_dsa_8021q_rxvlan(vid))
223 return felix_tag_8021q_rxvlan_del(ocelot_to_felix(ocelot),
226 if (vid_is_dsa_8021q_txvlan(vid))
227 return felix_tag_8021q_txvlan_del(ocelot_to_felix(ocelot),
233 /* Alternatively to using the NPI functionality, that same hardware MAC
234 * connected internally to the enetc or fman DSA master can be configured to
235 * use the software-defined tag_8021q frame format. As far as the hardware is
236 * concerned, it thinks it is a "dumb switch" - the queues of the CPU port
237 * module are now disconnected from it, but can still be accessed through
238 * register-based MMIO.
240 static void felix_8021q_cpu_port_init(struct ocelot *ocelot, int port)
242 mutex_lock(&ocelot->fwd_domain_lock);
244 ocelot->ports[port]->is_dsa_8021q_cpu = true;
247 /* Overwrite PGID_CPU with the non-tagging port */
248 ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, PGID_CPU);
250 ocelot_apply_bridge_fwd_mask(ocelot, true);
252 mutex_unlock(&ocelot->fwd_domain_lock);
255 static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port)
257 mutex_lock(&ocelot->fwd_domain_lock);
259 ocelot->ports[port]->is_dsa_8021q_cpu = false;
261 /* Restore PGID_CPU */
262 ocelot_write_rix(ocelot, BIT(ocelot->num_phys_ports), ANA_PGID_PGID,
265 ocelot_apply_bridge_fwd_mask(ocelot, true);
267 mutex_unlock(&ocelot->fwd_domain_lock);
270 /* On switches with no extraction IRQ wired, trapped packets need to be
271 * replicated over Ethernet as well, otherwise we'd get no notification of
272 * their arrival when using the ocelot-8021q tagging protocol.
274 static int felix_update_trapping_destinations(struct dsa_switch *ds,
275 bool using_tag_8021q)
277 struct ocelot *ocelot = ds->priv;
278 struct felix *felix = ocelot_to_felix(ocelot);
279 struct ocelot_vcap_filter *trap;
280 enum ocelot_mask_mode mask_mode;
281 unsigned long port_mask;
286 if (!felix->info->quirk_no_xtr_irq)
289 /* Figure out the current CPU port */
290 dsa_switch_for_each_cpu_port(dp, ds) {
295 /* We are sure that "cpu" was found, otherwise
296 * dsa_tree_setup_default_cpu() would have failed earlier.
299 /* Make sure all traps are set up for that destination */
300 list_for_each_entry(trap, &ocelot->traps, trap_list) {
301 /* Figure out the current trapping destination */
302 if (using_tag_8021q) {
303 /* Redirect to the tag_8021q CPU port. If timestamps
304 * are necessary, also copy trapped packets to the CPU
307 mask_mode = OCELOT_MASK_MODE_REDIRECT;
308 port_mask = BIT(cpu);
309 cpu_copy_ena = !!trap->take_ts;
311 /* Trap packets only to the CPU port module, which is
312 * redirected to the NPI port (the DSA CPU port)
314 mask_mode = OCELOT_MASK_MODE_PERMIT_DENY;
319 if (trap->action.mask_mode == mask_mode &&
320 trap->action.port_mask == port_mask &&
321 trap->action.cpu_copy_ena == cpu_copy_ena)
324 trap->action.mask_mode = mask_mode;
325 trap->action.port_mask = port_mask;
326 trap->action.cpu_copy_ena = cpu_copy_ena;
328 err = ocelot_vcap_filter_replace(ocelot, trap);
336 static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu)
338 struct ocelot *ocelot = ds->priv;
339 unsigned long cpu_flood;
343 felix_8021q_cpu_port_init(ocelot, cpu);
345 dsa_switch_for_each_available_port(dp, ds) {
346 /* This overwrites ocelot_init():
347 * Do not forward BPDU frames to the CPU port module,
349 * - When these packets are injected from the tag_8021q
350 * CPU port, we want them to go out, not loop back
352 * - STP traffic ingressing on a user port should go to
353 * the tag_8021q CPU port, not to the hardware CPU
356 ocelot_write_gix(ocelot,
357 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0),
358 ANA_PORT_CPU_FWD_BPDU_CFG, dp->index);
361 /* In tag_8021q mode, the CPU port module is unused, except for PTP
362 * frames. So we want to disable flooding of any kind to the CPU port
363 * module, since packets going there will end in a black hole.
365 cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports));
366 ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_UC);
367 ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC);
368 ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_BC);
370 err = dsa_tag_8021q_register(ds, htons(ETH_P_8021AD));
374 err = felix_update_trapping_destinations(ds, true);
376 goto out_tag_8021q_unregister;
378 /* The ownership of the CPU port module's queues might have just been
379 * transferred to the tag_8021q tagger from the NPI-based tagger.
380 * So there might still be all sorts of crap in the queues. On the
381 * other hand, the MMIO-based matching of PTP frames is very brittle,
382 * so we need to be careful that there are no extra frames to be
383 * dequeued over MMIO, since we would never know to discard them.
385 ocelot_drain_cpu_queue(ocelot, 0);
389 out_tag_8021q_unregister:
390 dsa_tag_8021q_unregister(ds);
394 static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu)
396 struct ocelot *ocelot = ds->priv;
400 err = felix_update_trapping_destinations(ds, false);
402 dev_err(ds->dev, "felix_teardown_mmio_filtering returned %d",
405 dsa_tag_8021q_unregister(ds);
407 dsa_switch_for_each_available_port(dp, ds) {
408 /* Restore the logic from ocelot_init:
409 * do not forward BPDU frames to the front ports.
411 ocelot_write_gix(ocelot,
412 ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff),
413 ANA_PORT_CPU_FWD_BPDU_CFG,
417 felix_8021q_cpu_port_deinit(ocelot, cpu);
420 /* The CPU port module is connected to the Node Processor Interface (NPI). This
421 * is the mode through which frames can be injected from and extracted to an
422 * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU
423 * running Linux, and this forms a DSA setup together with the enetc or fman
426 static void felix_npi_port_init(struct ocelot *ocelot, int port)
430 ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M |
431 QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port),
434 /* NPI port Injection/Extraction configuration */
435 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR,
436 ocelot->npi_xtr_prefix);
437 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR,
438 ocelot->npi_inj_prefix);
440 /* Disable transmission of pause frames */
441 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0);
444 static void felix_npi_port_deinit(struct ocelot *ocelot, int port)
446 /* Restore hardware defaults */
447 int unused_port = ocelot->num_phys_ports + 2;
451 ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPU_PORT(unused_port),
454 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR,
455 OCELOT_TAG_PREFIX_DISABLED);
456 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR,
457 OCELOT_TAG_PREFIX_DISABLED);
459 /* Enable transmission of pause frames */
460 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1);
463 static int felix_setup_tag_npi(struct dsa_switch *ds, int cpu)
465 struct ocelot *ocelot = ds->priv;
466 unsigned long cpu_flood;
468 felix_npi_port_init(ocelot, cpu);
470 /* Include the CPU port module (and indirectly, the NPI port)
471 * in the forwarding mask for unknown unicast - the hardware
472 * default value for ANA_FLOODING_FLD_UNICAST excludes
473 * BIT(ocelot->num_phys_ports), and so does ocelot_init,
474 * since Ocelot relies on whitelisting MAC addresses towards
476 * We do this because DSA does not yet perform RX filtering,
477 * and the NPI port does not perform source address learning,
478 * so traffic sent to Linux is effectively unknown from the
479 * switch's perspective.
481 cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports));
482 ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_UC);
483 ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_MC);
484 ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_BC);
489 static void felix_teardown_tag_npi(struct dsa_switch *ds, int cpu)
491 struct ocelot *ocelot = ds->priv;
493 felix_npi_port_deinit(ocelot, cpu);
496 static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu,
497 enum dsa_tag_protocol proto)
502 case DSA_TAG_PROTO_SEVILLE:
503 case DSA_TAG_PROTO_OCELOT:
504 err = felix_setup_tag_npi(ds, cpu);
506 case DSA_TAG_PROTO_OCELOT_8021Q:
507 err = felix_setup_tag_8021q(ds, cpu);
510 err = -EPROTONOSUPPORT;
516 static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu,
517 enum dsa_tag_protocol proto)
520 case DSA_TAG_PROTO_SEVILLE:
521 case DSA_TAG_PROTO_OCELOT:
522 felix_teardown_tag_npi(ds, cpu);
524 case DSA_TAG_PROTO_OCELOT_8021Q:
525 felix_teardown_tag_8021q(ds, cpu);
532 /* This always leaves the switch in a consistent state, because although the
533 * tag_8021q setup can fail, the NPI setup can't. So either the change is made,
534 * or the restoration is guaranteed to work.
536 static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu,
537 enum dsa_tag_protocol proto)
539 struct ocelot *ocelot = ds->priv;
540 struct felix *felix = ocelot_to_felix(ocelot);
541 enum dsa_tag_protocol old_proto = felix->tag_proto;
544 if (proto != DSA_TAG_PROTO_SEVILLE &&
545 proto != DSA_TAG_PROTO_OCELOT &&
546 proto != DSA_TAG_PROTO_OCELOT_8021Q)
547 return -EPROTONOSUPPORT;
549 felix_del_tag_protocol(ds, cpu, old_proto);
551 err = felix_set_tag_protocol(ds, cpu, proto);
553 felix_set_tag_protocol(ds, cpu, old_proto);
557 felix->tag_proto = proto;
562 static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds,
564 enum dsa_tag_protocol mp)
566 struct ocelot *ocelot = ds->priv;
567 struct felix *felix = ocelot_to_felix(ocelot);
569 return felix->tag_proto;
572 static int felix_set_ageing_time(struct dsa_switch *ds,
573 unsigned int ageing_time)
575 struct ocelot *ocelot = ds->priv;
577 ocelot_set_ageing_time(ocelot, ageing_time);
582 static void felix_port_fast_age(struct dsa_switch *ds, int port)
584 struct ocelot *ocelot = ds->priv;
587 err = ocelot_mact_flush(ocelot, port);
589 dev_err(ds->dev, "Flushing MAC table on port %d returned %pe\n",
593 static int felix_fdb_dump(struct dsa_switch *ds, int port,
594 dsa_fdb_dump_cb_t *cb, void *data)
596 struct ocelot *ocelot = ds->priv;
598 return ocelot_fdb_dump(ocelot, port, cb, data);
601 static int felix_fdb_add(struct dsa_switch *ds, int port,
602 const unsigned char *addr, u16 vid)
604 struct ocelot *ocelot = ds->priv;
606 return ocelot_fdb_add(ocelot, port, addr, vid);
609 static int felix_fdb_del(struct dsa_switch *ds, int port,
610 const unsigned char *addr, u16 vid)
612 struct ocelot *ocelot = ds->priv;
614 return ocelot_fdb_del(ocelot, port, addr, vid);
617 static int felix_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag lag,
618 const unsigned char *addr, u16 vid)
620 struct ocelot *ocelot = ds->priv;
622 return ocelot_lag_fdb_add(ocelot, lag.dev, addr, vid);
625 static int felix_lag_fdb_del(struct dsa_switch *ds, struct dsa_lag lag,
626 const unsigned char *addr, u16 vid)
628 struct ocelot *ocelot = ds->priv;
630 return ocelot_lag_fdb_del(ocelot, lag.dev, addr, vid);
633 static int felix_mdb_add(struct dsa_switch *ds, int port,
634 const struct switchdev_obj_port_mdb *mdb)
636 struct ocelot *ocelot = ds->priv;
638 return ocelot_port_mdb_add(ocelot, port, mdb);
641 static int felix_mdb_del(struct dsa_switch *ds, int port,
642 const struct switchdev_obj_port_mdb *mdb)
644 struct ocelot *ocelot = ds->priv;
646 return ocelot_port_mdb_del(ocelot, port, mdb);
649 static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port,
652 struct ocelot *ocelot = ds->priv;
654 return ocelot_bridge_stp_state_set(ocelot, port, state);
657 static int felix_pre_bridge_flags(struct dsa_switch *ds, int port,
658 struct switchdev_brport_flags val,
659 struct netlink_ext_ack *extack)
661 struct ocelot *ocelot = ds->priv;
663 return ocelot_port_pre_bridge_flags(ocelot, port, val);
666 static int felix_bridge_flags(struct dsa_switch *ds, int port,
667 struct switchdev_brport_flags val,
668 struct netlink_ext_ack *extack)
670 struct ocelot *ocelot = ds->priv;
672 ocelot_port_bridge_flags(ocelot, port, val);
677 static int felix_bridge_join(struct dsa_switch *ds, int port,
678 struct dsa_bridge bridge, bool *tx_fwd_offload)
680 struct ocelot *ocelot = ds->priv;
682 ocelot_port_bridge_join(ocelot, port, bridge.dev);
687 static void felix_bridge_leave(struct dsa_switch *ds, int port,
688 struct dsa_bridge bridge)
690 struct ocelot *ocelot = ds->priv;
692 ocelot_port_bridge_leave(ocelot, port, bridge.dev);
695 static int felix_lag_join(struct dsa_switch *ds, int port,
697 struct netdev_lag_upper_info *info)
699 struct ocelot *ocelot = ds->priv;
701 return ocelot_port_lag_join(ocelot, port, lag.dev, info);
704 static int felix_lag_leave(struct dsa_switch *ds, int port,
707 struct ocelot *ocelot = ds->priv;
709 ocelot_port_lag_leave(ocelot, port, lag.dev);
714 static int felix_lag_change(struct dsa_switch *ds, int port)
716 struct dsa_port *dp = dsa_to_port(ds, port);
717 struct ocelot *ocelot = ds->priv;
719 ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled);
724 static int felix_vlan_prepare(struct dsa_switch *ds, int port,
725 const struct switchdev_obj_port_vlan *vlan,
726 struct netlink_ext_ack *extack)
728 struct ocelot *ocelot = ds->priv;
729 u16 flags = vlan->flags;
731 /* Ocelot switches copy frames as-is to the CPU, so the flags:
732 * egress-untagged or not, pvid or not, make no difference. This
733 * behavior is already better than what DSA just tries to approximate
734 * when it installs the VLAN with the same flags on the CPU port.
735 * Just accept any configuration, and don't let ocelot deny installing
736 * multiple native VLANs on the NPI port, because the switch doesn't
737 * look at the port tag settings towards the NPI interface anyway.
739 if (port == ocelot->npi)
742 return ocelot_vlan_prepare(ocelot, port, vlan->vid,
743 flags & BRIDGE_VLAN_INFO_PVID,
744 flags & BRIDGE_VLAN_INFO_UNTAGGED,
748 static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled,
749 struct netlink_ext_ack *extack)
751 struct ocelot *ocelot = ds->priv;
753 return ocelot_port_vlan_filtering(ocelot, port, enabled, extack);
756 static int felix_vlan_add(struct dsa_switch *ds, int port,
757 const struct switchdev_obj_port_vlan *vlan,
758 struct netlink_ext_ack *extack)
760 struct ocelot *ocelot = ds->priv;
761 u16 flags = vlan->flags;
764 err = felix_vlan_prepare(ds, port, vlan, extack);
768 return ocelot_vlan_add(ocelot, port, vlan->vid,
769 flags & BRIDGE_VLAN_INFO_PVID,
770 flags & BRIDGE_VLAN_INFO_UNTAGGED);
773 static int felix_vlan_del(struct dsa_switch *ds, int port,
774 const struct switchdev_obj_port_vlan *vlan)
776 struct ocelot *ocelot = ds->priv;
778 return ocelot_vlan_del(ocelot, port, vlan->vid);
781 static void felix_phylink_get_caps(struct dsa_switch *ds, int port,
782 struct phylink_config *config)
784 struct ocelot *ocelot = ds->priv;
786 __set_bit(ocelot->ports[port]->phy_mode,
787 config->supported_interfaces);
790 static void felix_phylink_validate(struct dsa_switch *ds, int port,
791 unsigned long *supported,
792 struct phylink_link_state *state)
794 struct ocelot *ocelot = ds->priv;
795 struct felix *felix = ocelot_to_felix(ocelot);
797 if (felix->info->phylink_validate)
798 felix->info->phylink_validate(ocelot, port, supported, state);
801 static struct phylink_pcs *felix_phylink_mac_select_pcs(struct dsa_switch *ds,
803 phy_interface_t iface)
805 struct ocelot *ocelot = ds->priv;
806 struct felix *felix = ocelot_to_felix(ocelot);
807 struct phylink_pcs *pcs = NULL;
809 if (felix->pcs && felix->pcs[port])
810 pcs = felix->pcs[port];
815 static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port,
816 unsigned int link_an_mode,
817 phy_interface_t interface)
819 struct ocelot *ocelot = ds->priv;
821 ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface,
825 static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port,
826 unsigned int link_an_mode,
827 phy_interface_t interface,
828 struct phy_device *phydev,
829 int speed, int duplex,
830 bool tx_pause, bool rx_pause)
832 struct ocelot *ocelot = ds->priv;
833 struct felix *felix = ocelot_to_felix(ocelot);
835 ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode,
836 interface, speed, duplex, tx_pause, rx_pause,
839 if (felix->info->port_sched_speed_set)
840 felix->info->port_sched_speed_set(ocelot, port, speed);
843 static void felix_port_qos_map_init(struct ocelot *ocelot, int port)
847 ocelot_rmw_gix(ocelot,
848 ANA_PORT_QOS_CFG_QOS_PCP_ENA,
849 ANA_PORT_QOS_CFG_QOS_PCP_ENA,
853 for (i = 0; i < OCELOT_NUM_TC * 2; i++) {
854 ocelot_rmw_ix(ocelot,
855 (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) |
856 ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i),
857 ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL |
858 ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M,
859 ANA_PORT_PCP_DEI_MAP,
864 static void felix_get_strings(struct dsa_switch *ds, int port,
865 u32 stringset, u8 *data)
867 struct ocelot *ocelot = ds->priv;
869 return ocelot_get_strings(ocelot, port, stringset, data);
872 static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data)
874 struct ocelot *ocelot = ds->priv;
876 ocelot_get_ethtool_stats(ocelot, port, data);
879 static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset)
881 struct ocelot *ocelot = ds->priv;
883 return ocelot_get_sset_count(ocelot, port, sset);
886 static int felix_get_ts_info(struct dsa_switch *ds, int port,
887 struct ethtool_ts_info *info)
889 struct ocelot *ocelot = ds->priv;
891 return ocelot_get_ts_info(ocelot, port, info);
894 static int felix_parse_ports_node(struct felix *felix,
895 struct device_node *ports_node,
896 phy_interface_t *port_phy_modes)
898 struct ocelot *ocelot = &felix->ocelot;
899 struct device *dev = felix->ocelot.dev;
900 struct device_node *child;
902 for_each_available_child_of_node(ports_node, child) {
903 phy_interface_t phy_mode;
907 /* Get switch port number from DT */
908 if (of_property_read_u32(child, "reg", &port) < 0) {
909 dev_err(dev, "Port number not defined in device tree "
910 "(property \"reg\")\n");
915 /* Get PHY mode from DT */
916 err = of_get_phy_mode(child, &phy_mode);
918 dev_err(dev, "Failed to read phy-mode or "
919 "phy-interface-type property for port %d\n",
925 err = felix->info->prevalidate_phy_mode(ocelot, port, phy_mode);
927 dev_err(dev, "Unsupported PHY mode %s on port %d\n",
928 phy_modes(phy_mode), port);
933 port_phy_modes[port] = phy_mode;
939 static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes)
941 struct device *dev = felix->ocelot.dev;
942 struct device_node *switch_node;
943 struct device_node *ports_node;
946 switch_node = dev->of_node;
948 ports_node = of_get_child_by_name(switch_node, "ports");
950 ports_node = of_get_child_by_name(switch_node, "ethernet-ports");
952 dev_err(dev, "Incorrect bindings: absent \"ports\" or \"ethernet-ports\" node\n");
956 err = felix_parse_ports_node(felix, ports_node, port_phy_modes);
957 of_node_put(ports_node);
962 static int felix_init_structs(struct felix *felix, int num_phys_ports)
964 struct ocelot *ocelot = &felix->ocelot;
965 phy_interface_t *port_phy_modes;
969 ocelot->num_phys_ports = num_phys_ports;
970 ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports,
971 sizeof(struct ocelot_port *), GFP_KERNEL);
975 ocelot->map = felix->info->map;
976 ocelot->stats_layout = felix->info->stats_layout;
977 ocelot->num_stats = felix->info->num_stats;
978 ocelot->num_mact_rows = felix->info->num_mact_rows;
979 ocelot->vcap = felix->info->vcap;
980 ocelot->vcap_pol.base = felix->info->vcap_pol_base;
981 ocelot->vcap_pol.max = felix->info->vcap_pol_max;
982 ocelot->vcap_pol.base2 = felix->info->vcap_pol_base2;
983 ocelot->vcap_pol.max2 = felix->info->vcap_pol_max2;
984 ocelot->ops = felix->info->ops;
985 ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT;
986 ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT;
987 ocelot->devlink = felix->ds->devlink;
989 port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t),
994 err = felix_parse_dt(felix, port_phy_modes);
996 kfree(port_phy_modes);
1000 for (i = 0; i < TARGET_MAX; i++) {
1001 struct regmap *target;
1003 if (!felix->info->target_io_res[i].name)
1006 memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
1007 res.flags = IORESOURCE_MEM;
1008 res.start += felix->switch_base;
1009 res.end += felix->switch_base;
1011 target = felix->info->init_regmap(ocelot, &res);
1012 if (IS_ERR(target)) {
1013 dev_err(ocelot->dev,
1014 "Failed to map device memory space\n");
1015 kfree(port_phy_modes);
1016 return PTR_ERR(target);
1019 ocelot->targets[i] = target;
1022 err = ocelot_regfields_init(ocelot, felix->info->regfields);
1024 dev_err(ocelot->dev, "failed to init reg fields map\n");
1025 kfree(port_phy_modes);
1029 for (port = 0; port < num_phys_ports; port++) {
1030 struct ocelot_port *ocelot_port;
1031 struct regmap *target;
1033 ocelot_port = devm_kzalloc(ocelot->dev,
1034 sizeof(struct ocelot_port),
1037 dev_err(ocelot->dev,
1038 "failed to allocate port memory\n");
1039 kfree(port_phy_modes);
1043 memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
1044 res.flags = IORESOURCE_MEM;
1045 res.start += felix->switch_base;
1046 res.end += felix->switch_base;
1048 target = felix->info->init_regmap(ocelot, &res);
1049 if (IS_ERR(target)) {
1050 dev_err(ocelot->dev,
1051 "Failed to map memory space for port %d\n",
1053 kfree(port_phy_modes);
1054 return PTR_ERR(target);
1057 ocelot_port->phy_mode = port_phy_modes[port];
1058 ocelot_port->ocelot = ocelot;
1059 ocelot_port->target = target;
1060 ocelot->ports[port] = ocelot_port;
1063 kfree(port_phy_modes);
1065 if (felix->info->mdio_bus_alloc) {
1066 err = felix->info->mdio_bus_alloc(ocelot);
1074 static void ocelot_port_purge_txtstamp_skb(struct ocelot *ocelot, int port,
1075 struct sk_buff *skb)
1077 struct ocelot_port *ocelot_port = ocelot->ports[port];
1078 struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone;
1079 struct sk_buff *skb_match = NULL, *skb_tmp;
1080 unsigned long flags;
1085 spin_lock_irqsave(&ocelot_port->tx_skbs.lock, flags);
1087 skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) {
1090 __skb_unlink(skb, &ocelot_port->tx_skbs);
1095 spin_unlock_irqrestore(&ocelot_port->tx_skbs.lock, flags);
1097 WARN_ONCE(!skb_match,
1098 "Could not find skb clone in TX timestamping list\n");
1101 #define work_to_xmit_work(w) \
1102 container_of((w), struct felix_deferred_xmit_work, work)
1104 static void felix_port_deferred_xmit(struct kthread_work *work)
1106 struct felix_deferred_xmit_work *xmit_work = work_to_xmit_work(work);
1107 struct dsa_switch *ds = xmit_work->dp->ds;
1108 struct sk_buff *skb = xmit_work->skb;
1109 u32 rew_op = ocelot_ptp_rew_op(skb);
1110 struct ocelot *ocelot = ds->priv;
1111 int port = xmit_work->dp->index;
1115 if (ocelot_can_inject(ocelot, 0))
1119 } while (--retries);
1122 dev_err(ocelot->dev, "port %d failed to inject skb\n",
1124 ocelot_port_purge_txtstamp_skb(ocelot, port, skb);
1129 ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb);
1135 static int felix_connect_tag_protocol(struct dsa_switch *ds,
1136 enum dsa_tag_protocol proto)
1138 struct ocelot_8021q_tagger_data *tagger_data;
1141 case DSA_TAG_PROTO_OCELOT_8021Q:
1142 tagger_data = ocelot_8021q_tagger_data(ds);
1143 tagger_data->xmit_work_fn = felix_port_deferred_xmit;
1145 case DSA_TAG_PROTO_OCELOT:
1146 case DSA_TAG_PROTO_SEVILLE:
1149 return -EPROTONOSUPPORT;
1153 /* Hardware initialization done here so that we can allocate structures with
1154 * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing
1155 * us to allocate structures twice (leak memory) and map PCI memory twice
1156 * (which will not work).
1158 static int felix_setup(struct dsa_switch *ds)
1160 struct ocelot *ocelot = ds->priv;
1161 struct felix *felix = ocelot_to_felix(ocelot);
1162 struct dsa_port *dp;
1165 err = felix_init_structs(felix, ds->num_ports);
1169 err = ocelot_init(ocelot);
1171 goto out_mdiobus_free;
1174 err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps);
1176 dev_err(ocelot->dev,
1177 "Timestamp initialization failed\n");
1182 dsa_switch_for_each_available_port(dp, ds) {
1183 ocelot_init_port(ocelot, dp->index);
1185 /* Set the default QoS Classification based on PCP and DEI
1188 felix_port_qos_map_init(ocelot, dp->index);
1191 err = ocelot_devlink_sb_register(ocelot);
1193 goto out_deinit_ports;
1195 dsa_switch_for_each_cpu_port(dp, ds) {
1196 /* The initial tag protocol is NPI which always returns 0, so
1197 * there's no real point in checking for errors.
1199 felix_set_tag_protocol(ds, dp->index, felix->tag_proto);
1203 ds->mtu_enforcement_ingress = true;
1204 ds->assisted_learning_on_cpu_port = true;
1209 dsa_switch_for_each_available_port(dp, ds)
1210 ocelot_deinit_port(ocelot, dp->index);
1212 ocelot_deinit_timestamp(ocelot);
1213 ocelot_deinit(ocelot);
1216 if (felix->info->mdio_bus_free)
1217 felix->info->mdio_bus_free(ocelot);
1222 static void felix_teardown(struct dsa_switch *ds)
1224 struct ocelot *ocelot = ds->priv;
1225 struct felix *felix = ocelot_to_felix(ocelot);
1226 struct dsa_port *dp;
1228 dsa_switch_for_each_cpu_port(dp, ds) {
1229 felix_del_tag_protocol(ds, dp->index, felix->tag_proto);
1233 dsa_switch_for_each_available_port(dp, ds)
1234 ocelot_deinit_port(ocelot, dp->index);
1236 ocelot_devlink_sb_unregister(ocelot);
1237 ocelot_deinit_timestamp(ocelot);
1238 ocelot_deinit(ocelot);
1240 if (felix->info->mdio_bus_free)
1241 felix->info->mdio_bus_free(ocelot);
1244 static int felix_hwtstamp_get(struct dsa_switch *ds, int port,
1247 struct ocelot *ocelot = ds->priv;
1249 return ocelot_hwstamp_get(ocelot, port, ifr);
1252 static int felix_hwtstamp_set(struct dsa_switch *ds, int port,
1255 struct ocelot *ocelot = ds->priv;
1256 struct felix *felix = ocelot_to_felix(ocelot);
1257 bool using_tag_8021q;
1260 err = ocelot_hwstamp_set(ocelot, port, ifr);
1264 using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q;
1266 return felix_update_trapping_destinations(ds, using_tag_8021q);
1269 static bool felix_check_xtr_pkt(struct ocelot *ocelot, unsigned int ptp_type)
1271 struct felix *felix = ocelot_to_felix(ocelot);
1274 if (felix->tag_proto != DSA_TAG_PROTO_OCELOT_8021Q)
1277 if (!felix->info->quirk_no_xtr_irq)
1280 if (ptp_type == PTP_CLASS_NONE)
1283 while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp)) {
1284 struct sk_buff *skb;
1287 err = ocelot_xtr_poll_frame(ocelot, grp, &skb);
1291 /* We trap to the CPU port module all PTP frames, but
1292 * felix_rxtstamp() only gets called for event frames.
1293 * So we need to avoid sending duplicate general
1294 * message frames by running a second BPF classifier
1295 * here and dropping those.
1297 __skb_push(skb, ETH_HLEN);
1299 type = ptp_classify_raw(skb);
1301 __skb_pull(skb, ETH_HLEN);
1303 if (type == PTP_CLASS_NONE) {
1313 ocelot_drain_cpu_queue(ocelot, 0);
1318 static bool felix_rxtstamp(struct dsa_switch *ds, int port,
1319 struct sk_buff *skb, unsigned int type)
1321 u32 tstamp_lo = OCELOT_SKB_CB(skb)->tstamp_lo;
1322 struct skb_shared_hwtstamps *shhwtstamps;
1323 struct ocelot *ocelot = ds->priv;
1324 struct timespec64 ts;
1328 /* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb
1329 * for RX timestamping. Then free it, and poll for its copy through
1330 * MMIO in the CPU port module, and inject that into the stack from
1331 * ocelot_xtr_poll().
1333 if (felix_check_xtr_pkt(ocelot, type)) {
1338 ocelot_ptp_gettime64(&ocelot->ptp_info, &ts);
1339 tstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
1341 tstamp_hi = tstamp >> 32;
1342 if ((tstamp & 0xffffffff) < tstamp_lo)
1345 tstamp = ((u64)tstamp_hi << 32) | tstamp_lo;
1347 shhwtstamps = skb_hwtstamps(skb);
1348 memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
1349 shhwtstamps->hwtstamp = tstamp;
1353 static void felix_txtstamp(struct dsa_switch *ds, int port,
1354 struct sk_buff *skb)
1356 struct ocelot *ocelot = ds->priv;
1357 struct sk_buff *clone = NULL;
1362 if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) {
1363 dev_err_ratelimited(ds->dev,
1364 "port %d delivering skb without TX timestamp\n",
1370 OCELOT_SKB_CB(skb)->clone = clone;
1373 static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
1375 struct ocelot *ocelot = ds->priv;
1377 ocelot_port_set_maxlen(ocelot, port, new_mtu);
1382 static int felix_get_max_mtu(struct dsa_switch *ds, int port)
1384 struct ocelot *ocelot = ds->priv;
1386 return ocelot_get_max_mtu(ocelot, port);
1389 static int felix_cls_flower_add(struct dsa_switch *ds, int port,
1390 struct flow_cls_offload *cls, bool ingress)
1392 struct ocelot *ocelot = ds->priv;
1393 struct felix *felix = ocelot_to_felix(ocelot);
1394 bool using_tag_8021q;
1397 err = ocelot_cls_flower_replace(ocelot, port, cls, ingress);
1401 using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q;
1403 return felix_update_trapping_destinations(ds, using_tag_8021q);
1406 static int felix_cls_flower_del(struct dsa_switch *ds, int port,
1407 struct flow_cls_offload *cls, bool ingress)
1409 struct ocelot *ocelot = ds->priv;
1411 return ocelot_cls_flower_destroy(ocelot, port, cls, ingress);
1414 static int felix_cls_flower_stats(struct dsa_switch *ds, int port,
1415 struct flow_cls_offload *cls, bool ingress)
1417 struct ocelot *ocelot = ds->priv;
1419 return ocelot_cls_flower_stats(ocelot, port, cls, ingress);
1422 static int felix_port_policer_add(struct dsa_switch *ds, int port,
1423 struct dsa_mall_policer_tc_entry *policer)
1425 struct ocelot *ocelot = ds->priv;
1426 struct ocelot_policer pol = {
1427 .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8,
1428 .burst = policer->burst,
1431 return ocelot_port_policer_add(ocelot, port, &pol);
1434 static void felix_port_policer_del(struct dsa_switch *ds, int port)
1436 struct ocelot *ocelot = ds->priv;
1438 ocelot_port_policer_del(ocelot, port);
1441 static int felix_port_setup_tc(struct dsa_switch *ds, int port,
1442 enum tc_setup_type type,
1445 struct ocelot *ocelot = ds->priv;
1446 struct felix *felix = ocelot_to_felix(ocelot);
1448 if (felix->info->port_setup_tc)
1449 return felix->info->port_setup_tc(ds, port, type, type_data);
1454 static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index,
1456 struct devlink_sb_pool_info *pool_info)
1458 struct ocelot *ocelot = ds->priv;
1460 return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info);
1463 static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index,
1464 u16 pool_index, u32 size,
1465 enum devlink_sb_threshold_type threshold_type,
1466 struct netlink_ext_ack *extack)
1468 struct ocelot *ocelot = ds->priv;
1470 return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size,
1471 threshold_type, extack);
1474 static int felix_sb_port_pool_get(struct dsa_switch *ds, int port,
1475 unsigned int sb_index, u16 pool_index,
1478 struct ocelot *ocelot = ds->priv;
1480 return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index,
1484 static int felix_sb_port_pool_set(struct dsa_switch *ds, int port,
1485 unsigned int sb_index, u16 pool_index,
1486 u32 threshold, struct netlink_ext_ack *extack)
1488 struct ocelot *ocelot = ds->priv;
1490 return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index,
1494 static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port,
1495 unsigned int sb_index, u16 tc_index,
1496 enum devlink_sb_pool_type pool_type,
1497 u16 *p_pool_index, u32 *p_threshold)
1499 struct ocelot *ocelot = ds->priv;
1501 return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index,
1502 pool_type, p_pool_index,
1506 static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port,
1507 unsigned int sb_index, u16 tc_index,
1508 enum devlink_sb_pool_type pool_type,
1509 u16 pool_index, u32 threshold,
1510 struct netlink_ext_ack *extack)
1512 struct ocelot *ocelot = ds->priv;
1514 return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index,
1515 pool_type, pool_index, threshold,
1519 static int felix_sb_occ_snapshot(struct dsa_switch *ds,
1520 unsigned int sb_index)
1522 struct ocelot *ocelot = ds->priv;
1524 return ocelot_sb_occ_snapshot(ocelot, sb_index);
1527 static int felix_sb_occ_max_clear(struct dsa_switch *ds,
1528 unsigned int sb_index)
1530 struct ocelot *ocelot = ds->priv;
1532 return ocelot_sb_occ_max_clear(ocelot, sb_index);
1535 static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port,
1536 unsigned int sb_index, u16 pool_index,
1537 u32 *p_cur, u32 *p_max)
1539 struct ocelot *ocelot = ds->priv;
1541 return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index,
1545 static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port,
1546 unsigned int sb_index, u16 tc_index,
1547 enum devlink_sb_pool_type pool_type,
1548 u32 *p_cur, u32 *p_max)
1550 struct ocelot *ocelot = ds->priv;
1552 return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index,
1553 pool_type, p_cur, p_max);
1556 static int felix_mrp_add(struct dsa_switch *ds, int port,
1557 const struct switchdev_obj_mrp *mrp)
1559 struct ocelot *ocelot = ds->priv;
1561 return ocelot_mrp_add(ocelot, port, mrp);
1564 static int felix_mrp_del(struct dsa_switch *ds, int port,
1565 const struct switchdev_obj_mrp *mrp)
1567 struct ocelot *ocelot = ds->priv;
1569 return ocelot_mrp_add(ocelot, port, mrp);
1573 felix_mrp_add_ring_role(struct dsa_switch *ds, int port,
1574 const struct switchdev_obj_ring_role_mrp *mrp)
1576 struct ocelot *ocelot = ds->priv;
1578 return ocelot_mrp_add_ring_role(ocelot, port, mrp);
1582 felix_mrp_del_ring_role(struct dsa_switch *ds, int port,
1583 const struct switchdev_obj_ring_role_mrp *mrp)
1585 struct ocelot *ocelot = ds->priv;
1587 return ocelot_mrp_del_ring_role(ocelot, port, mrp);
1590 const struct dsa_switch_ops felix_switch_ops = {
1591 .get_tag_protocol = felix_get_tag_protocol,
1592 .change_tag_protocol = felix_change_tag_protocol,
1593 .connect_tag_protocol = felix_connect_tag_protocol,
1594 .setup = felix_setup,
1595 .teardown = felix_teardown,
1596 .set_ageing_time = felix_set_ageing_time,
1597 .get_strings = felix_get_strings,
1598 .get_ethtool_stats = felix_get_ethtool_stats,
1599 .get_sset_count = felix_get_sset_count,
1600 .get_ts_info = felix_get_ts_info,
1601 .phylink_get_caps = felix_phylink_get_caps,
1602 .phylink_validate = felix_phylink_validate,
1603 .phylink_mac_select_pcs = felix_phylink_mac_select_pcs,
1604 .phylink_mac_link_down = felix_phylink_mac_link_down,
1605 .phylink_mac_link_up = felix_phylink_mac_link_up,
1606 .port_fast_age = felix_port_fast_age,
1607 .port_fdb_dump = felix_fdb_dump,
1608 .port_fdb_add = felix_fdb_add,
1609 .port_fdb_del = felix_fdb_del,
1610 .lag_fdb_add = felix_lag_fdb_add,
1611 .lag_fdb_del = felix_lag_fdb_del,
1612 .port_mdb_add = felix_mdb_add,
1613 .port_mdb_del = felix_mdb_del,
1614 .port_pre_bridge_flags = felix_pre_bridge_flags,
1615 .port_bridge_flags = felix_bridge_flags,
1616 .port_bridge_join = felix_bridge_join,
1617 .port_bridge_leave = felix_bridge_leave,
1618 .port_lag_join = felix_lag_join,
1619 .port_lag_leave = felix_lag_leave,
1620 .port_lag_change = felix_lag_change,
1621 .port_stp_state_set = felix_bridge_stp_state_set,
1622 .port_vlan_filtering = felix_vlan_filtering,
1623 .port_vlan_add = felix_vlan_add,
1624 .port_vlan_del = felix_vlan_del,
1625 .port_hwtstamp_get = felix_hwtstamp_get,
1626 .port_hwtstamp_set = felix_hwtstamp_set,
1627 .port_rxtstamp = felix_rxtstamp,
1628 .port_txtstamp = felix_txtstamp,
1629 .port_change_mtu = felix_change_mtu,
1630 .port_max_mtu = felix_get_max_mtu,
1631 .port_policer_add = felix_port_policer_add,
1632 .port_policer_del = felix_port_policer_del,
1633 .cls_flower_add = felix_cls_flower_add,
1634 .cls_flower_del = felix_cls_flower_del,
1635 .cls_flower_stats = felix_cls_flower_stats,
1636 .port_setup_tc = felix_port_setup_tc,
1637 .devlink_sb_pool_get = felix_sb_pool_get,
1638 .devlink_sb_pool_set = felix_sb_pool_set,
1639 .devlink_sb_port_pool_get = felix_sb_port_pool_get,
1640 .devlink_sb_port_pool_set = felix_sb_port_pool_set,
1641 .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get,
1642 .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set,
1643 .devlink_sb_occ_snapshot = felix_sb_occ_snapshot,
1644 .devlink_sb_occ_max_clear = felix_sb_occ_max_clear,
1645 .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get,
1646 .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get,
1647 .port_mrp_add = felix_mrp_add,
1648 .port_mrp_del = felix_mrp_del,
1649 .port_mrp_add_ring_role = felix_mrp_add_ring_role,
1650 .port_mrp_del_ring_role = felix_mrp_del_ring_role,
1651 .tag_8021q_vlan_add = felix_tag_8021q_vlan_add,
1652 .tag_8021q_vlan_del = felix_tag_8021q_vlan_del,
1655 struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port)
1657 struct felix *felix = ocelot_to_felix(ocelot);
1658 struct dsa_switch *ds = felix->ds;
1660 if (!dsa_is_user_port(ds, port))
1663 return dsa_to_port(ds, port)->slave;
1666 int felix_netdev_to_port(struct net_device *dev)
1668 struct dsa_port *dp;
1670 dp = dsa_port_from_netdev(dev);