Lines Matching +full:fman +full:- +full:best +full:- +full:effort +full:- +full:port

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2019-2021 NXP
5 * register-compatible with Ocelot and that perform I/O to their host CPU
6 * through an NPI (Node Processor Interface) Ethernet port.
41 return ERR_PTR(-EOPNOTSUPP); in felix_classify_db()
48 struct ocelot *ocelot = ds->priv; in felix_cpu_port_for_conduit()
53 mutex_lock(&ocelot->fwd_domain_lock); in felix_cpu_port_for_conduit()
55 mutex_unlock(&ocelot->fwd_domain_lock); in felix_cpu_port_for_conduit()
60 cpu_dp = conduit->dsa_ptr; in felix_cpu_port_for_conduit()
61 return cpu_dp->index; in felix_cpu_port_for_conduit()
65 * felix_update_tag_8021q_rx_rule - Update VCAP ES0 tag_8021q rule after
70 * Source port identification for tag_8021q is done using VCAP ES0 rules on the
71 * CPU port(s). The ES0 tag B (inner tag from the packet) can be configured as
73 * - push_inner_tag=0: the inner tag is never pushed into the frame
79 * - push_inner_tag=1: the inner tag is always pushed. This is good when the
80 * classified VLAN is not a discardable quantity (the port
81 * is under a VLAN-aware bridge, and software needs to
84 * The point is that what is good for a VLAN-unaware port is not good for a
85 * VLAN-aware port, and vice versa. Thus, the RX tagging rules must be kept in
86 * sync with the VLAN filtering state of the port.
93 outer_tagging_rule->action.push_inner_tag = OCELOT_ES0_TAG; in felix_update_tag_8021q_rx_rule()
95 outer_tagging_rule->action.push_inner_tag = OCELOT_NO_ES0_TAG; in felix_update_tag_8021q_rx_rule()
99 * the tagger can perform RX source port identification.
101 static int felix_tag_8021q_vlan_add_rx(struct dsa_switch *ds, int port, in felix_tag_8021q_vlan_add_rx() argument
106 struct ocelot *ocelot = ds->priv; in felix_tag_8021q_vlan_add_rx()
110 key_length = ocelot->vcap[VCAP_ES0].keys[VCAP_ES0_IGR_PORT].length; in felix_tag_8021q_vlan_add_rx()
115 return -ENOMEM; in felix_tag_8021q_vlan_add_rx()
117 cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port, upstream); in felix_tag_8021q_vlan_add_rx()
119 outer_tagging_rule->key_type = OCELOT_VCAP_KEY_ANY; in felix_tag_8021q_vlan_add_rx()
120 outer_tagging_rule->prio = 1; in felix_tag_8021q_vlan_add_rx()
121 outer_tagging_rule->id.cookie = cookie; in felix_tag_8021q_vlan_add_rx()
122 outer_tagging_rule->id.tc_offload = false; in felix_tag_8021q_vlan_add_rx()
123 outer_tagging_rule->block_id = VCAP_ES0; in felix_tag_8021q_vlan_add_rx()
124 outer_tagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; in felix_tag_8021q_vlan_add_rx()
125 outer_tagging_rule->lookup = 0; in felix_tag_8021q_vlan_add_rx()
126 outer_tagging_rule->ingress_port.value = port; in felix_tag_8021q_vlan_add_rx()
127 outer_tagging_rule->ingress_port.mask = GENMASK(key_length - 1, 0); in felix_tag_8021q_vlan_add_rx()
128 outer_tagging_rule->egress_port.value = upstream; in felix_tag_8021q_vlan_add_rx()
129 outer_tagging_rule->egress_port.mask = GENMASK(key_length - 1, 0); in felix_tag_8021q_vlan_add_rx()
130 outer_tagging_rule->action.push_outer_tag = OCELOT_ES0_TAG; in felix_tag_8021q_vlan_add_rx()
131 outer_tagging_rule->action.tag_a_tpid_sel = OCELOT_TAG_TPID_SEL_8021AD; in felix_tag_8021q_vlan_add_rx()
132 outer_tagging_rule->action.tag_a_vid_sel = 1; in felix_tag_8021q_vlan_add_rx()
133 outer_tagging_rule->action.vid_a_val = vid; in felix_tag_8021q_vlan_add_rx()
135 outer_tagging_rule->action.tag_b_tpid_sel = OCELOT_TAG_TPID_SEL_8021Q; in felix_tag_8021q_vlan_add_rx()
150 static int felix_tag_8021q_vlan_del_rx(struct dsa_switch *ds, int port, in felix_tag_8021q_vlan_del_rx() argument
155 struct ocelot *ocelot = ds->priv; in felix_tag_8021q_vlan_del_rx()
158 block_vcap_es0 = &ocelot->block[VCAP_ES0]; in felix_tag_8021q_vlan_del_rx()
159 cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port, upstream); in felix_tag_8021q_vlan_del_rx()
164 return -ENOENT; in felix_tag_8021q_vlan_del_rx()
170 * rules for steering those tagged packets towards the correct destination port
172 static int felix_tag_8021q_vlan_add_tx(struct dsa_switch *ds, int port, in felix_tag_8021q_vlan_add_tx() argument
177 struct ocelot *ocelot = ds->priv; in felix_tag_8021q_vlan_add_tx()
183 return -ENOMEM; in felix_tag_8021q_vlan_add_tx()
188 return -ENOMEM; in felix_tag_8021q_vlan_add_tx()
191 cookie = OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port); in felix_tag_8021q_vlan_add_tx()
193 untagging_rule->key_type = OCELOT_VCAP_KEY_ANY; in felix_tag_8021q_vlan_add_tx()
194 untagging_rule->ingress_port_mask = cpu_ports; in felix_tag_8021q_vlan_add_tx()
195 untagging_rule->vlan.vid.value = vid; in felix_tag_8021q_vlan_add_tx()
196 untagging_rule->vlan.vid.mask = VLAN_VID_MASK; in felix_tag_8021q_vlan_add_tx()
197 untagging_rule->prio = 1; in felix_tag_8021q_vlan_add_tx()
198 untagging_rule->id.cookie = cookie; in felix_tag_8021q_vlan_add_tx()
199 untagging_rule->id.tc_offload = false; in felix_tag_8021q_vlan_add_tx()
200 untagging_rule->block_id = VCAP_IS1; in felix_tag_8021q_vlan_add_tx()
201 untagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; in felix_tag_8021q_vlan_add_tx()
202 untagging_rule->lookup = 0; in felix_tag_8021q_vlan_add_tx()
203 untagging_rule->action.vlan_pop_cnt_ena = true; in felix_tag_8021q_vlan_add_tx()
204 untagging_rule->action.vlan_pop_cnt = 1; in felix_tag_8021q_vlan_add_tx()
205 untagging_rule->action.pag_override_mask = 0xff; in felix_tag_8021q_vlan_add_tx()
206 untagging_rule->action.pag_val = port; in felix_tag_8021q_vlan_add_tx()
215 cookie = OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port); in felix_tag_8021q_vlan_add_tx()
217 redirect_rule->key_type = OCELOT_VCAP_KEY_ANY; in felix_tag_8021q_vlan_add_tx()
218 redirect_rule->ingress_port_mask = cpu_ports; in felix_tag_8021q_vlan_add_tx()
219 redirect_rule->pag = port; in felix_tag_8021q_vlan_add_tx()
220 redirect_rule->prio = 1; in felix_tag_8021q_vlan_add_tx()
221 redirect_rule->id.cookie = cookie; in felix_tag_8021q_vlan_add_tx()
222 redirect_rule->id.tc_offload = false; in felix_tag_8021q_vlan_add_tx()
223 redirect_rule->block_id = VCAP_IS2; in felix_tag_8021q_vlan_add_tx()
224 redirect_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; in felix_tag_8021q_vlan_add_tx()
225 redirect_rule->lookup = 0; in felix_tag_8021q_vlan_add_tx()
226 redirect_rule->action.mask_mode = OCELOT_MASK_MODE_REDIRECT; in felix_tag_8021q_vlan_add_tx()
227 redirect_rule->action.port_mask = BIT(port); in felix_tag_8021q_vlan_add_tx()
239 static int felix_tag_8021q_vlan_del_tx(struct dsa_switch *ds, int port, u16 vid) in felix_tag_8021q_vlan_del_tx() argument
244 struct ocelot *ocelot = ds->priv; in felix_tag_8021q_vlan_del_tx()
248 block_vcap_is1 = &ocelot->block[VCAP_IS1]; in felix_tag_8021q_vlan_del_tx()
249 block_vcap_is2 = &ocelot->block[VCAP_IS2]; in felix_tag_8021q_vlan_del_tx()
251 cookie = OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port); in felix_tag_8021q_vlan_del_tx()
255 return -ENOENT; in felix_tag_8021q_vlan_del_tx()
261 cookie = OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port); in felix_tag_8021q_vlan_del_tx()
265 return -ENOENT; in felix_tag_8021q_vlan_del_tx()
270 static int felix_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, in felix_tag_8021q_vlan_add() argument
273 struct dsa_port *dp = dsa_to_port(ds, port); in felix_tag_8021q_vlan_add()
277 /* tag_8021q.c assumes we are implementing this via port VLAN in felix_tag_8021q_vlan_add()
279 * for the CPU port. in felix_tag_8021q_vlan_add()
285 err = felix_tag_8021q_vlan_add_rx(ds, port, cpu_dp->index, vid, in felix_tag_8021q_vlan_add()
291 err = felix_tag_8021q_vlan_add_tx(ds, port, vid); in felix_tag_8021q_vlan_add()
299 felix_tag_8021q_vlan_del_rx(ds, port, cpu_dp->index, vid); in felix_tag_8021q_vlan_add()
304 static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) in felix_tag_8021q_vlan_del() argument
306 struct dsa_port *dp = dsa_to_port(ds, port); in felix_tag_8021q_vlan_del()
314 err = felix_tag_8021q_vlan_del_rx(ds, port, cpu_dp->index, vid); in felix_tag_8021q_vlan_del()
319 err = felix_tag_8021q_vlan_del_tx(ds, port, vid); in felix_tag_8021q_vlan_del()
327 felix_tag_8021q_vlan_add_rx(ds, port, cpu_dp->index, vid, in felix_tag_8021q_vlan_del()
333 static int felix_update_tag_8021q_rx_rules(struct dsa_switch *ds, int port, in felix_update_tag_8021q_rx_rules() argument
338 struct ocelot *ocelot = ds->priv; in felix_update_tag_8021q_rx_rules()
343 block_vcap_es0 = &ocelot->block[VCAP_ES0]; in felix_update_tag_8021q_rx_rules()
346 cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port, in felix_update_tag_8021q_rx_rules()
347 cpu_dp->index); in felix_update_tag_8021q_rx_rules()
368 if (WARN_ON(!trap->ingress_port_mask)) in felix_trap_get_cpu_port()
369 return -1; in felix_trap_get_cpu_port()
371 first_port = __ffs(trap->ingress_port_mask); in felix_trap_get_cpu_port()
374 return dp->cpu_dp->index; in felix_trap_get_cpu_port()
379 * their arrival when using the ocelot-8021q tagging protocol.
384 struct ocelot *ocelot = ds->priv; in felix_update_trapping_destinations()
393 if (!felix->info->quirk_no_xtr_irq) in felix_update_trapping_destinations()
399 block_vcap_is2 = &ocelot->block[VCAP_IS2]; in felix_update_trapping_destinations()
402 list_for_each_entry(trap, &block_vcap_is2->rules, list) { in felix_update_trapping_destinations()
403 if (!trap->is_trap) in felix_update_trapping_destinations()
408 /* Redirect to the tag_8021q CPU port. If timestamps in felix_update_trapping_destinations()
410 * port module. in felix_update_trapping_destinations()
414 cpu_copy_ena = !!trap->take_ts; in felix_update_trapping_destinations()
416 /* Trap packets only to the CPU port module, which is in felix_update_trapping_destinations()
417 * redirected to the NPI port (the DSA CPU port) in felix_update_trapping_destinations()
424 if (trap->action.mask_mode == mask_mode && in felix_update_trapping_destinations()
425 trap->action.port_mask == port_mask && in felix_update_trapping_destinations()
426 trap->action.cpu_copy_ena == cpu_copy_ena) in felix_update_trapping_destinations()
429 trap->action.mask_mode = mask_mode; in felix_update_trapping_destinations()
430 trap->action.port_mask = port_mask; in felix_update_trapping_destinations()
431 trap->action.cpu_copy_ena = cpu_copy_ena; in felix_update_trapping_destinations()
441 /* The CPU port module is connected to the Node Processor Interface (NPI). This
444 * running Linux, and this forms a DSA setup together with the enetc or fman
447 static void felix_npi_port_init(struct ocelot *ocelot, int port) in felix_npi_port_init() argument
449 ocelot->npi = port; in felix_npi_port_init()
452 QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port), in felix_npi_port_init()
455 /* NPI port Injection/Extraction configuration */ in felix_npi_port_init()
456 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, in felix_npi_port_init()
457 ocelot->npi_xtr_prefix); in felix_npi_port_init()
458 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, in felix_npi_port_init()
459 ocelot->npi_inj_prefix); in felix_npi_port_init()
462 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0); in felix_npi_port_init()
465 static void felix_npi_port_deinit(struct ocelot *ocelot, int port) in felix_npi_port_deinit() argument
468 int unused_port = ocelot->num_phys_ports + 2; in felix_npi_port_deinit()
470 ocelot->npi = -1; in felix_npi_port_deinit()
475 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, in felix_npi_port_deinit()
477 ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, in felix_npi_port_deinit()
481 ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); in felix_npi_port_deinit()
487 struct ocelot *ocelot = ds->priv; in felix_tag_npi_setup()
490 if (first_cpu_dp && dp->cpu_dp != first_cpu_dp) { in felix_tag_npi_setup()
491 dev_err(ds->dev, "Multiple NPI ports not supported\n"); in felix_tag_npi_setup()
492 return -EINVAL; in felix_tag_npi_setup()
495 first_cpu_dp = dp->cpu_dp; in felix_tag_npi_setup()
499 return -EINVAL; in felix_tag_npi_setup()
501 felix_npi_port_init(ocelot, first_cpu_dp->index); in felix_tag_npi_setup()
508 struct ocelot *ocelot = ds->priv; in felix_tag_npi_teardown()
510 felix_npi_port_deinit(ocelot, ocelot->npi); in felix_tag_npi_teardown()
515 struct ocelot *ocelot = ds->priv; in felix_tag_npi_get_host_fwd_mask()
517 return BIT(ocelot->num_phys_ports); in felix_tag_npi_get_host_fwd_mask()
520 static int felix_tag_npi_change_conduit(struct dsa_switch *ds, int port, in felix_tag_npi_change_conduit() argument
524 struct dsa_port *dp = dsa_to_port(ds, port), *other_dp; in felix_tag_npi_change_conduit()
525 struct ocelot *ocelot = ds->priv; in felix_tag_npi_change_conduit()
529 "LAG DSA conduit only supported using ocelot-8021q"); in felix_tag_npi_change_conduit()
530 return -EOPNOTSUPP; in felix_tag_npi_change_conduit()
533 /* Changing the NPI port breaks user ports still assigned to the old in felix_tag_npi_change_conduit()
538 struct net_device *user = other_dp->user; in felix_tag_npi_change_conduit()
540 if (other_dp != dp && (user->flags & IFF_UP) && in felix_tag_npi_change_conduit()
544 return -EOPNOTSUPP; in felix_tag_npi_change_conduit()
548 felix_npi_port_deinit(ocelot, ocelot->npi); in felix_tag_npi_change_conduit()
555 * connected internally to the enetc or fman DSA conduit can be configured to
556 * use the software-defined tag_8021q frame format. As far as the hardware is
557 * concerned, it thinks it is a "dumb switch" - the queues of the CPU port
559 * register-based MMIO.
570 struct ocelot *ocelot = ds->priv; in felix_tag_8021q_setup()
579 ocelot_port_setup_dsa_8021q_cpu(ocelot, dp->index); in felix_tag_8021q_setup()
582 ocelot_port_assign_dsa_8021q_cpu(ocelot, dp->index, in felix_tag_8021q_setup()
583 dp->cpu_dp->index); in felix_tag_8021q_setup()
587 * Do not forward BPDU frames to the CPU port module, in felix_tag_8021q_setup()
589 * - When these packets are injected from the tag_8021q in felix_tag_8021q_setup()
590 * CPU port, we want them to go out, not loop back in felix_tag_8021q_setup()
592 * - STP traffic ingressing on a user port should go to in felix_tag_8021q_setup()
593 * the tag_8021q CPU port, not to the hardware CPU in felix_tag_8021q_setup()
594 * port module. in felix_tag_8021q_setup()
598 ANA_PORT_CPU_FWD_BPDU_CFG, dp->index); in felix_tag_8021q_setup()
600 /* The ownership of the CPU port module's queues might have just been in felix_tag_8021q_setup()
601 * transferred to the tag_8021q tagger from the NPI-based tagger. in felix_tag_8021q_setup()
603 * other hand, the MMIO-based matching of PTP frames is very brittle, in felix_tag_8021q_setup()
612 * about whether the received packets were VLAN-tagged on the wire, in felix_tag_8021q_setup()
613 * since they are always tagged on egress towards the CPU port. in felix_tag_8021q_setup()
615 * Since using push_inner_tag=1 is unavoidable for VLAN-aware bridges, in felix_tag_8021q_setup()
619 ds->untag_vlan_aware_bridge_pvid = true; in felix_tag_8021q_setup()
626 struct ocelot *ocelot = ds->priv; in felix_tag_8021q_teardown()
636 dp->index); in felix_tag_8021q_teardown()
639 ocelot_port_unassign_dsa_8021q_cpu(ocelot, dp->index); in felix_tag_8021q_teardown()
642 ocelot_port_teardown_dsa_8021q_cpu(ocelot, dp->index); in felix_tag_8021q_teardown()
646 ds->untag_vlan_aware_bridge_pvid = false; in felix_tag_8021q_teardown()
654 static int felix_tag_8021q_change_conduit(struct dsa_switch *ds, int port, in felix_tag_8021q_change_conduit() argument
659 struct ocelot *ocelot = ds->priv; in felix_tag_8021q_change_conduit()
661 ocelot_port_unassign_dsa_8021q_cpu(ocelot, port); in felix_tag_8021q_change_conduit()
662 ocelot_port_assign_dsa_8021q_cpu(ocelot, port, cpu); in felix_tag_8021q_change_conduit()
677 struct ocelot *ocelot = ds->priv; in felix_set_host_flood()
697 struct ocelot *ocelot = ds->priv; in felix_migrate_host_flood()
702 mask = old_proto_ops->get_host_fwd_mask(ds); in felix_migrate_host_flood()
706 mask = proto_ops->get_host_fwd_mask(ds); in felix_migrate_host_flood()
707 felix_set_host_flood(ds, mask, !!felix->host_flood_uc_mask, in felix_migrate_host_flood()
708 !!felix->host_flood_mc_mask, true); in felix_migrate_host_flood()
715 struct ocelot *ocelot = ds->priv; in felix_migrate_mdbs()
721 from = old_proto_ops->get_host_fwd_mask(ds); in felix_migrate_mdbs()
722 to = proto_ops->get_host_fwd_mask(ds); in felix_migrate_mdbs()
730 * the CPU port is taking place here, just of the tagging protocol.
759 struct ocelot *ocelot = ds->priv; in felix_change_tag_protocol()
772 return -EPROTONOSUPPORT; in felix_change_tag_protocol()
775 old_proto_ops = felix->tag_proto_ops; in felix_change_tag_protocol()
780 err = proto_ops->setup(ds); in felix_change_tag_protocol()
789 old_proto_ops->teardown(ds); in felix_change_tag_protocol()
791 felix->tag_proto_ops = proto_ops; in felix_change_tag_protocol()
792 felix->tag_proto = proto; in felix_change_tag_protocol()
797 proto_ops->teardown(ds); in felix_change_tag_protocol()
803 int port, in felix_get_tag_protocol() argument
806 struct ocelot *ocelot = ds->priv; in felix_get_tag_protocol()
809 return felix->tag_proto; in felix_get_tag_protocol()
812 static void felix_port_set_host_flood(struct dsa_switch *ds, int port, in felix_port_set_host_flood() argument
815 struct ocelot *ocelot = ds->priv; in felix_port_set_host_flood()
820 felix->host_flood_uc_mask |= BIT(port); in felix_port_set_host_flood()
822 felix->host_flood_uc_mask &= ~BIT(port); in felix_port_set_host_flood()
825 felix->host_flood_mc_mask |= BIT(port); in felix_port_set_host_flood()
827 felix->host_flood_mc_mask &= ~BIT(port); in felix_port_set_host_flood()
829 mask = felix->tag_proto_ops->get_host_fwd_mask(ds); in felix_port_set_host_flood()
830 felix_set_host_flood(ds, mask, !!felix->host_flood_uc_mask, in felix_port_set_host_flood()
831 !!felix->host_flood_mc_mask, true); in felix_port_set_host_flood()
834 static int felix_port_change_conduit(struct dsa_switch *ds, int port, in felix_port_change_conduit() argument
838 struct ocelot *ocelot = ds->priv; in felix_port_change_conduit()
841 return felix->tag_proto_ops->change_conduit(ds, port, conduit, extack); in felix_port_change_conduit()
847 struct ocelot *ocelot = ds->priv; in felix_set_ageing_time()
854 static void felix_port_fast_age(struct dsa_switch *ds, int port) in felix_port_fast_age() argument
856 struct ocelot *ocelot = ds->priv; in felix_port_fast_age()
859 err = ocelot_mact_flush(ocelot, port); in felix_port_fast_age()
861 dev_err(ds->dev, "Flushing MAC table on port %d returned %pe\n", in felix_port_fast_age()
862 port, ERR_PTR(err)); in felix_port_fast_age()
865 static int felix_fdb_dump(struct dsa_switch *ds, int port, in felix_fdb_dump() argument
868 struct ocelot *ocelot = ds->priv; in felix_fdb_dump()
870 return ocelot_fdb_dump(ocelot, port, cb, data); in felix_fdb_dump()
873 static int felix_fdb_add(struct dsa_switch *ds, int port, in felix_fdb_add() argument
878 struct dsa_port *dp = dsa_to_port(ds, port); in felix_fdb_add()
879 struct ocelot *ocelot = ds->priv; in felix_fdb_add()
885 dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) in felix_fdb_add()
889 port = PGID_CPU; in felix_fdb_add()
891 return ocelot_fdb_add(ocelot, port, addr, vid, bridge_dev); in felix_fdb_add()
894 static int felix_fdb_del(struct dsa_switch *ds, int port, in felix_fdb_del() argument
899 struct dsa_port *dp = dsa_to_port(ds, port); in felix_fdb_del()
900 struct ocelot *ocelot = ds->priv; in felix_fdb_del()
906 dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) in felix_fdb_del()
910 port = PGID_CPU; in felix_fdb_del()
912 return ocelot_fdb_del(ocelot, port, addr, vid, bridge_dev); in felix_fdb_del()
920 struct ocelot *ocelot = ds->priv; in felix_lag_fdb_add()
933 struct ocelot *ocelot = ds->priv; in felix_lag_fdb_del()
941 static int felix_mdb_add(struct dsa_switch *ds, int port, in felix_mdb_add() argument
946 struct ocelot *ocelot = ds->priv; in felix_mdb_add()
951 if (dsa_is_cpu_port(ds, port) && !bridge_dev && in felix_mdb_add()
952 dsa_mdb_present_in_other_db(ds, port, mdb, db)) in felix_mdb_add()
955 if (port == ocelot->npi) in felix_mdb_add()
956 port = ocelot->num_phys_ports; in felix_mdb_add()
958 return ocelot_port_mdb_add(ocelot, port, mdb, bridge_dev); in felix_mdb_add()
961 static int felix_mdb_del(struct dsa_switch *ds, int port, in felix_mdb_del() argument
966 struct ocelot *ocelot = ds->priv; in felix_mdb_del()
971 if (dsa_is_cpu_port(ds, port) && !bridge_dev && in felix_mdb_del()
972 dsa_mdb_present_in_other_db(ds, port, mdb, db)) in felix_mdb_del()
975 if (port == ocelot->npi) in felix_mdb_del()
976 port = ocelot->num_phys_ports; in felix_mdb_del()
978 return ocelot_port_mdb_del(ocelot, port, mdb, bridge_dev); in felix_mdb_del()
981 static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, in felix_bridge_stp_state_set() argument
984 struct ocelot *ocelot = ds->priv; in felix_bridge_stp_state_set()
986 return ocelot_bridge_stp_state_set(ocelot, port, state); in felix_bridge_stp_state_set()
989 static int felix_pre_bridge_flags(struct dsa_switch *ds, int port, in felix_pre_bridge_flags() argument
993 struct ocelot *ocelot = ds->priv; in felix_pre_bridge_flags()
995 return ocelot_port_pre_bridge_flags(ocelot, port, val); in felix_pre_bridge_flags()
998 static int felix_bridge_flags(struct dsa_switch *ds, int port, in felix_bridge_flags() argument
1002 struct ocelot *ocelot = ds->priv; in felix_bridge_flags()
1004 if (port == ocelot->npi) in felix_bridge_flags()
1005 port = ocelot->num_phys_ports; in felix_bridge_flags()
1007 ocelot_port_bridge_flags(ocelot, port, val); in felix_bridge_flags()
1012 static int felix_bridge_join(struct dsa_switch *ds, int port, in felix_bridge_join() argument
1016 struct ocelot *ocelot = ds->priv; in felix_bridge_join()
1018 return ocelot_port_bridge_join(ocelot, port, bridge.dev, bridge.num, in felix_bridge_join()
1022 static void felix_bridge_leave(struct dsa_switch *ds, int port, in felix_bridge_leave() argument
1025 struct ocelot *ocelot = ds->priv; in felix_bridge_leave()
1027 ocelot_port_bridge_leave(ocelot, port, bridge.dev); in felix_bridge_leave()
1030 static int felix_lag_join(struct dsa_switch *ds, int port, in felix_lag_join() argument
1035 struct ocelot *ocelot = ds->priv; in felix_lag_join()
1038 err = ocelot_port_lag_join(ocelot, port, lag.dev, info, extack); in felix_lag_join()
1042 /* Update the logical LAG port that serves as tag_8021q CPU port */ in felix_lag_join()
1043 if (!dsa_is_cpu_port(ds, port)) in felix_lag_join()
1046 return felix_port_change_conduit(ds, port, lag.dev, extack); in felix_lag_join()
1049 static int felix_lag_leave(struct dsa_switch *ds, int port, in felix_lag_leave() argument
1052 struct ocelot *ocelot = ds->priv; in felix_lag_leave()
1054 ocelot_port_lag_leave(ocelot, port, lag.dev); in felix_lag_leave()
1056 /* Update the logical LAG port that serves as tag_8021q CPU port */ in felix_lag_leave()
1057 if (!dsa_is_cpu_port(ds, port)) in felix_lag_leave()
1060 return felix_port_change_conduit(ds, port, lag.dev, NULL); in felix_lag_leave()
1063 static int felix_lag_change(struct dsa_switch *ds, int port) in felix_lag_change() argument
1065 struct dsa_port *dp = dsa_to_port(ds, port); in felix_lag_change()
1066 struct ocelot *ocelot = ds->priv; in felix_lag_change()
1068 ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); in felix_lag_change()
1073 static int felix_vlan_prepare(struct dsa_switch *ds, int port, in felix_vlan_prepare() argument
1077 struct ocelot *ocelot = ds->priv; in felix_vlan_prepare()
1078 u16 flags = vlan->flags; in felix_vlan_prepare()
1080 /* Ocelot switches copy frames as-is to the CPU, so the flags: in felix_vlan_prepare()
1081 * egress-untagged or not, pvid or not, make no difference. This in felix_vlan_prepare()
1083 * when it installs the VLAN with the same flags on the CPU port. in felix_vlan_prepare()
1085 * multiple native VLANs on the NPI port, because the switch doesn't in felix_vlan_prepare()
1086 * look at the port tag settings towards the NPI interface anyway. in felix_vlan_prepare()
1088 if (port == ocelot->npi) in felix_vlan_prepare()
1091 return ocelot_vlan_prepare(ocelot, port, vlan->vid, in felix_vlan_prepare()
1097 static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled, in felix_vlan_filtering() argument
1100 struct ocelot *ocelot = ds->priv; in felix_vlan_filtering()
1105 err = ocelot_port_vlan_filtering(ocelot, port, enabled, extack); in felix_vlan_filtering()
1110 using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; in felix_vlan_filtering()
1112 err = felix_update_tag_8021q_rx_rules(ds, port, enabled); in felix_vlan_filtering()
1120 static int felix_vlan_add(struct dsa_switch *ds, int port, in felix_vlan_add() argument
1124 struct ocelot *ocelot = ds->priv; in felix_vlan_add()
1125 u16 flags = vlan->flags; in felix_vlan_add()
1128 err = felix_vlan_prepare(ds, port, vlan, extack); in felix_vlan_add()
1132 return ocelot_vlan_add(ocelot, port, vlan->vid, in felix_vlan_add()
1137 static int felix_vlan_del(struct dsa_switch *ds, int port, in felix_vlan_del() argument
1140 struct ocelot *ocelot = ds->priv; in felix_vlan_del()
1142 return ocelot_vlan_del(ocelot, port, vlan->vid); in felix_vlan_del()
1145 static void felix_phylink_get_caps(struct dsa_switch *ds, int port, in felix_phylink_get_caps() argument
1148 struct ocelot *ocelot = ds->priv; in felix_phylink_get_caps()
1150 config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | in felix_phylink_get_caps()
1154 __set_bit(ocelot->ports[port]->phy_mode, in felix_phylink_get_caps()
1155 config->supported_interfaces); in felix_phylink_get_caps()
1163 struct ocelot *ocelot = dp->ds->priv; in felix_phylink_mac_config()
1164 int port = dp->index; in felix_phylink_mac_config() local
1169 if (felix->info->phylink_mac_config) in felix_phylink_mac_config()
1170 felix->info->phylink_mac_config(ocelot, port, mode, state); in felix_phylink_mac_config()
1178 struct ocelot *ocelot = dp->ds->priv; in felix_phylink_mac_select_pcs()
1180 int port = dp->index; in felix_phylink_mac_select_pcs() local
1185 if (felix->pcs && felix->pcs[port]) in felix_phylink_mac_select_pcs()
1186 pcs = felix->pcs[port]; in felix_phylink_mac_select_pcs()
1196 struct ocelot *ocelot = dp->ds->priv; in felix_phylink_mac_link_down()
1197 int port = dp->index; in felix_phylink_mac_link_down() local
1202 ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface, in felix_phylink_mac_link_down()
1203 felix->info->quirks); in felix_phylink_mac_link_down()
1214 struct ocelot *ocelot = dp->ds->priv; in felix_phylink_mac_link_up()
1215 int port = dp->index; in felix_phylink_mac_link_up() local
1220 ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode, in felix_phylink_mac_link_up()
1222 felix->info->quirks); in felix_phylink_mac_link_up()
1224 if (felix->info->port_sched_speed_set) in felix_phylink_mac_link_up()
1225 felix->info->port_sched_speed_set(ocelot, port, speed); in felix_phylink_mac_link_up()
1228 static int felix_port_enable(struct dsa_switch *ds, int port, in felix_port_enable() argument
1231 struct dsa_port *dp = dsa_to_port(ds, port); in felix_port_enable()
1232 struct ocelot *ocelot = ds->priv; in felix_port_enable()
1237 if (ocelot->npi >= 0) { in felix_port_enable()
1240 if (felix_cpu_port_for_conduit(ds, conduit) != ocelot->npi) { in felix_port_enable()
1241 dev_err(ds->dev, "Multiple conduits are not allowed\n"); in felix_port_enable()
1242 return -EINVAL; in felix_port_enable()
1249 static void felix_port_qos_map_init(struct ocelot *ocelot, int port) in felix_port_qos_map_init() argument
1257 port); in felix_port_qos_map_init()
1266 port, i); in felix_port_qos_map_init()
1270 static void felix_get_stats64(struct dsa_switch *ds, int port, in felix_get_stats64() argument
1273 struct ocelot *ocelot = ds->priv; in felix_get_stats64()
1275 ocelot_port_get_stats64(ocelot, port, stats); in felix_get_stats64()
1278 static void felix_get_pause_stats(struct dsa_switch *ds, int port, in felix_get_pause_stats() argument
1281 struct ocelot *ocelot = ds->priv; in felix_get_pause_stats()
1283 ocelot_port_get_pause_stats(ocelot, port, pause_stats); in felix_get_pause_stats()
1286 static void felix_get_rmon_stats(struct dsa_switch *ds, int port, in felix_get_rmon_stats() argument
1290 struct ocelot *ocelot = ds->priv; in felix_get_rmon_stats()
1292 ocelot_port_get_rmon_stats(ocelot, port, rmon_stats, ranges); in felix_get_rmon_stats()
1295 static void felix_get_eth_ctrl_stats(struct dsa_switch *ds, int port, in felix_get_eth_ctrl_stats() argument
1298 struct ocelot *ocelot = ds->priv; in felix_get_eth_ctrl_stats()
1300 ocelot_port_get_eth_ctrl_stats(ocelot, port, ctrl_stats); in felix_get_eth_ctrl_stats()
1303 static void felix_get_eth_mac_stats(struct dsa_switch *ds, int port, in felix_get_eth_mac_stats() argument
1306 struct ocelot *ocelot = ds->priv; in felix_get_eth_mac_stats()
1308 ocelot_port_get_eth_mac_stats(ocelot, port, mac_stats); in felix_get_eth_mac_stats()
1311 static void felix_get_eth_phy_stats(struct dsa_switch *ds, int port, in felix_get_eth_phy_stats() argument
1314 struct ocelot *ocelot = ds->priv; in felix_get_eth_phy_stats()
1316 ocelot_port_get_eth_phy_stats(ocelot, port, phy_stats); in felix_get_eth_phy_stats()
1319 static void felix_get_ts_stats(struct dsa_switch *ds, int port, in felix_get_ts_stats() argument
1322 struct ocelot *ocelot = ds->priv; in felix_get_ts_stats()
1324 ocelot_port_get_ts_stats(ocelot, port, ts_stats); in felix_get_ts_stats()
1327 static void felix_get_strings(struct dsa_switch *ds, int port, in felix_get_strings() argument
1330 struct ocelot *ocelot = ds->priv; in felix_get_strings()
1332 return ocelot_get_strings(ocelot, port, stringset, data); in felix_get_strings()
1335 static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) in felix_get_ethtool_stats() argument
1337 struct ocelot *ocelot = ds->priv; in felix_get_ethtool_stats()
1339 ocelot_get_ethtool_stats(ocelot, port, data); in felix_get_ethtool_stats()
1342 static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) in felix_get_sset_count() argument
1344 struct ocelot *ocelot = ds->priv; in felix_get_sset_count()
1346 return ocelot_get_sset_count(ocelot, port, sset); in felix_get_sset_count()
1349 static int felix_get_ts_info(struct dsa_switch *ds, int port, in felix_get_ts_info() argument
1352 struct ocelot *ocelot = ds->priv; in felix_get_ts_info()
1354 return ocelot_get_ts_info(ocelot, port, info); in felix_get_ts_info()
1366 static int felix_validate_phy_mode(struct felix *felix, int port, in felix_validate_phy_mode() argument
1369 u32 modes = felix->info->port_modes[port]; in felix_validate_phy_mode()
1373 return -EOPNOTSUPP; in felix_validate_phy_mode()
1380 struct device *dev = felix->ocelot.dev; in felix_parse_ports_node()
1384 u32 port; in felix_parse_ports_node() local
1387 /* Get switch port number from DT */ in felix_parse_ports_node()
1388 if (of_property_read_u32(child, "reg", &port) < 0) { in felix_parse_ports_node()
1389 dev_err(dev, "Port number not defined in device tree " in felix_parse_ports_node()
1391 return -ENODEV; in felix_parse_ports_node()
1397 dev_err(dev, "Failed to read phy-mode or " in felix_parse_ports_node()
1398 "phy-interface-type property for port %d\n", in felix_parse_ports_node()
1399 port); in felix_parse_ports_node()
1400 return -ENODEV; in felix_parse_ports_node()
1403 err = felix_validate_phy_mode(felix, port, phy_mode); in felix_parse_ports_node()
1405 dev_info(dev, "Unsupported PHY mode %s on port %d\n", in felix_parse_ports_node()
1406 phy_modes(phy_mode), port); in felix_parse_ports_node()
1408 /* Leave port_phy_modes[port] = 0, which is also in felix_parse_ports_node()
1410 * best-effort to bring up as many ports as possible. in felix_parse_ports_node()
1415 port_phy_modes[port] = phy_mode; in felix_parse_ports_node()
1423 struct device *dev = felix->ocelot.dev; in felix_parse_dt()
1428 switch_node = dev->of_node; in felix_parse_dt()
1432 ports_node = of_get_child_by_name(switch_node, "ethernet-ports"); in felix_parse_dt()
1434 dev_err(dev, "Incorrect bindings: absent \"ports\" or \"ethernet-ports\" node\n"); in felix_parse_dt()
1435 return -ENODEV; in felix_parse_dt()
1447 struct ocelot *ocelot = &felix->ocelot; in felix_request_regmap_by_name()
1455 if (!felix->info->resources) in felix_request_regmap_by_name()
1456 return dev_get_regmap(ocelot->dev->parent, resource_name); in felix_request_regmap_by_name()
1458 for (i = 0; i < felix->info->num_resources; i++) { in felix_request_regmap_by_name()
1459 if (strcmp(resource_name, felix->info->resources[i].name)) in felix_request_regmap_by_name()
1462 memcpy(&res, &felix->info->resources[i], sizeof(res)); in felix_request_regmap_by_name()
1463 res.start += felix->switch_base; in felix_request_regmap_by_name()
1464 res.end += felix->switch_base; in felix_request_regmap_by_name()
1469 return ERR_PTR(-ENOENT); in felix_request_regmap_by_name()
1475 const char *resource_name = felix->info->resource_names[target]; in felix_request_regmap()
1486 static struct regmap *felix_request_port_regmap(struct felix *felix, int port) in felix_request_port_regmap() argument
1490 sprintf(resource_name, "port%d", port); in felix_request_port_regmap()
1497 struct ocelot *ocelot = &felix->ocelot; in felix_init_structs()
1500 int port, i, err; in felix_init_structs() local
1502 ocelot->num_phys_ports = num_phys_ports; in felix_init_structs()
1503 ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, in felix_init_structs()
1505 if (!ocelot->ports) in felix_init_structs()
1506 return -ENOMEM; in felix_init_structs()
1508 ocelot->map = felix->info->map; in felix_init_structs()
1509 ocelot->num_mact_rows = felix->info->num_mact_rows; in felix_init_structs()
1510 ocelot->vcap = felix->info->vcap; in felix_init_structs()
1511 ocelot->vcap_pol.base = felix->info->vcap_pol_base; in felix_init_structs()
1512 ocelot->vcap_pol.max = felix->info->vcap_pol_max; in felix_init_structs()
1513 ocelot->vcap_pol.base2 = felix->info->vcap_pol_base2; in felix_init_structs()
1514 ocelot->vcap_pol.max2 = felix->info->vcap_pol_max2; in felix_init_structs()
1515 ocelot->ops = felix->info->ops; in felix_init_structs()
1516 ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT; in felix_init_structs()
1517 ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT; in felix_init_structs()
1518 ocelot->devlink = felix->ds->devlink; in felix_init_structs()
1523 return -ENOMEM; in felix_init_structs()
1534 dev_err(ocelot->dev, in felix_init_structs()
1541 ocelot->targets[i] = target; in felix_init_structs()
1544 err = ocelot_regfields_init(ocelot, felix->info->regfields); in felix_init_structs()
1546 dev_err(ocelot->dev, "failed to init reg fields map\n"); in felix_init_structs()
1551 for (port = 0; port < num_phys_ports; port++) { in felix_init_structs()
1554 ocelot_port = devm_kzalloc(ocelot->dev, in felix_init_structs()
1558 dev_err(ocelot->dev, in felix_init_structs()
1559 "failed to allocate port memory\n"); in felix_init_structs()
1561 return -ENOMEM; in felix_init_structs()
1564 target = felix_request_port_regmap(felix, port); in felix_init_structs()
1566 dev_err(ocelot->dev, in felix_init_structs()
1567 "Failed to map memory space for port %d: %pe\n", in felix_init_structs()
1568 port, target); in felix_init_structs()
1573 ocelot_port->phy_mode = port_phy_modes[port]; in felix_init_structs()
1574 ocelot_port->ocelot = ocelot; in felix_init_structs()
1575 ocelot_port->target = target; in felix_init_structs()
1576 ocelot_port->index = port; in felix_init_structs()
1577 ocelot->ports[port] = ocelot_port; in felix_init_structs()
1582 if (felix->info->mdio_bus_alloc) { in felix_init_structs()
1583 err = felix->info->mdio_bus_alloc(ocelot); in felix_init_structs()
1591 static void ocelot_port_purge_txtstamp_skb(struct ocelot *ocelot, int port, in ocelot_port_purge_txtstamp_skb() argument
1594 struct ocelot_port *ocelot_port = ocelot->ports[port]; in ocelot_port_purge_txtstamp_skb()
1595 struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone; in ocelot_port_purge_txtstamp_skb()
1602 spin_lock_irqsave(&ocelot_port->tx_skbs.lock, flags); in ocelot_port_purge_txtstamp_skb()
1604 skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) { in ocelot_port_purge_txtstamp_skb()
1607 __skb_unlink(skb, &ocelot_port->tx_skbs); in ocelot_port_purge_txtstamp_skb()
1612 spin_unlock_irqrestore(&ocelot_port->tx_skbs.lock, flags); in ocelot_port_purge_txtstamp_skb()
1624 struct dsa_switch *ds = xmit_work->dp->ds; in felix_port_deferred_xmit()
1625 struct sk_buff *skb = xmit_work->skb; in felix_port_deferred_xmit()
1627 struct ocelot *ocelot = ds->priv; in felix_port_deferred_xmit()
1628 int port = xmit_work->dp->index; in felix_port_deferred_xmit() local
1638 } while (--retries); in felix_port_deferred_xmit()
1642 dev_err(ocelot->dev, "port %d failed to inject skb\n", in felix_port_deferred_xmit()
1643 port); in felix_port_deferred_xmit()
1644 ocelot_port_purge_txtstamp_skb(ocelot, port, skb); in felix_port_deferred_xmit()
1649 ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb); in felix_port_deferred_xmit()
1665 tagger_data->xmit_work_fn = felix_port_deferred_xmit; in felix_connect_tag_protocol()
1671 return -EPROTONOSUPPORT; in felix_connect_tag_protocol()
1677 struct ocelot *ocelot = ds->priv; in felix_setup()
1682 err = felix_init_structs(felix, ds->num_ports); in felix_setup()
1686 if (ocelot->targets[HSIO]) in felix_setup()
1693 if (ocelot->ptp) { in felix_setup()
1694 err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); in felix_setup()
1696 dev_err(ocelot->dev, in felix_setup()
1698 ocelot->ptp = 0; in felix_setup()
1703 ocelot_init_port(ocelot, dp->index); in felix_setup()
1705 if (felix->info->configure_serdes) in felix_setup()
1706 felix->info->configure_serdes(ocelot, dp->index, in felix_setup()
1707 dp->dn); in felix_setup()
1712 felix_port_qos_map_init(ocelot, dp->index); in felix_setup()
1715 if (felix->info->request_irq) { in felix_setup()
1716 err = felix->info->request_irq(ocelot); in felix_setup()
1718 dev_err(ocelot->dev, "Failed to request IRQ: %pe\n", in felix_setup()
1731 felix_change_tag_protocol(ds, felix->tag_proto); in felix_setup()
1733 ds->mtu_enforcement_ingress = true; in felix_setup()
1734 ds->assisted_learning_on_cpu_port = true; in felix_setup()
1735 ds->fdb_isolation = true; in felix_setup()
1736 ds->max_num_bridges = ds->num_ports; in felix_setup()
1742 ocelot_deinit_port(ocelot, dp->index); in felix_setup()
1748 if (felix->info->mdio_bus_free) in felix_setup()
1749 felix->info->mdio_bus_free(ocelot); in felix_setup()
1756 struct ocelot *ocelot = ds->priv; in felix_teardown()
1761 if (felix->tag_proto_ops) in felix_teardown()
1762 felix->tag_proto_ops->teardown(ds); in felix_teardown()
1766 ocelot_deinit_port(ocelot, dp->index); in felix_teardown()
1772 if (felix->info->mdio_bus_free) in felix_teardown()
1773 felix->info->mdio_bus_free(ocelot); in felix_teardown()
1776 static int felix_hwtstamp_get(struct dsa_switch *ds, int port, in felix_hwtstamp_get() argument
1779 struct ocelot *ocelot = ds->priv; in felix_hwtstamp_get()
1781 return ocelot_hwstamp_get(ocelot, port, ifr); in felix_hwtstamp_get()
1784 static int felix_hwtstamp_set(struct dsa_switch *ds, int port, in felix_hwtstamp_set() argument
1787 struct ocelot *ocelot = ds->priv; in felix_hwtstamp_set()
1792 err = ocelot_hwstamp_set(ocelot, port, ifr); in felix_hwtstamp_set()
1796 using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; in felix_hwtstamp_set()
1806 if (felix->tag_proto != DSA_TAG_PROTO_OCELOT_8021Q) in felix_check_xtr_pkt()
1809 if (!felix->info->quirk_no_xtr_irq) in felix_check_xtr_pkt()
1822 /* We trap to the CPU port module all PTP frames, but in felix_check_xtr_pkt()
1844 dev_err_ratelimited(ocelot->dev, in felix_check_xtr_pkt()
1855 static bool felix_rxtstamp(struct dsa_switch *ds, int port, in felix_rxtstamp() argument
1858 u32 tstamp_lo = OCELOT_SKB_CB(skb)->tstamp_lo; in felix_rxtstamp()
1860 struct ocelot *ocelot = ds->priv; in felix_rxtstamp()
1867 if (!(ocelot->ports[port]->trap_proto & OCELOT_PROTO_PTP_L2)) in felix_rxtstamp()
1872 if (!(ocelot->ports[port]->trap_proto & OCELOT_PROTO_PTP_L4)) in felix_rxtstamp()
1879 * MMIO in the CPU port module, and inject that into the stack from in felix_rxtstamp()
1887 ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); in felix_rxtstamp()
1892 tstamp_hi--; in felix_rxtstamp()
1898 shhwtstamps->hwtstamp = tstamp; in felix_rxtstamp()
1902 static void felix_txtstamp(struct dsa_switch *ds, int port, in felix_txtstamp() argument
1905 struct ocelot *ocelot = ds->priv; in felix_txtstamp()
1908 if (!ocelot->ptp) in felix_txtstamp()
1911 if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) { in felix_txtstamp()
1912 dev_err_ratelimited(ds->dev, in felix_txtstamp()
1913 "port %d delivering skb without TX timestamp\n", in felix_txtstamp()
1914 port); in felix_txtstamp()
1919 OCELOT_SKB_CB(skb)->clone = clone; in felix_txtstamp()
1922 static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) in felix_change_mtu() argument
1924 struct ocelot *ocelot = ds->priv; in felix_change_mtu()
1925 struct ocelot_port *ocelot_port = ocelot->ports[port]; in felix_change_mtu()
1927 ocelot_port_set_maxlen(ocelot, port, new_mtu); in felix_change_mtu()
1929 mutex_lock(&ocelot->fwd_domain_lock); in felix_change_mtu()
1931 if (ocelot_port->taprio && ocelot->ops->tas_guard_bands_update) in felix_change_mtu()
1932 ocelot->ops->tas_guard_bands_update(ocelot, port); in felix_change_mtu()
1934 mutex_unlock(&ocelot->fwd_domain_lock); in felix_change_mtu()
1939 static int felix_get_max_mtu(struct dsa_switch *ds, int port) in felix_get_max_mtu() argument
1941 struct ocelot *ocelot = ds->priv; in felix_get_max_mtu()
1943 return ocelot_get_max_mtu(ocelot, port); in felix_get_max_mtu()
1946 static int felix_cls_flower_add(struct dsa_switch *ds, int port, in felix_cls_flower_add() argument
1949 struct ocelot *ocelot = ds->priv; in felix_cls_flower_add()
1954 err = ocelot_cls_flower_replace(ocelot, port, cls, ingress); in felix_cls_flower_add()
1958 using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; in felix_cls_flower_add()
1963 static int felix_cls_flower_del(struct dsa_switch *ds, int port, in felix_cls_flower_del() argument
1966 struct ocelot *ocelot = ds->priv; in felix_cls_flower_del()
1968 return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); in felix_cls_flower_del()
1971 static int felix_cls_flower_stats(struct dsa_switch *ds, int port, in felix_cls_flower_stats() argument
1974 struct ocelot *ocelot = ds->priv; in felix_cls_flower_stats()
1976 return ocelot_cls_flower_stats(ocelot, port, cls, ingress); in felix_cls_flower_stats()
1979 static int felix_port_policer_add(struct dsa_switch *ds, int port, in felix_port_policer_add() argument
1982 struct ocelot *ocelot = ds->priv; in felix_port_policer_add()
1984 .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, in felix_port_policer_add()
1985 .burst = policer->burst, in felix_port_policer_add()
1988 return ocelot_port_policer_add(ocelot, port, &pol); in felix_port_policer_add()
1991 static void felix_port_policer_del(struct dsa_switch *ds, int port) in felix_port_policer_del() argument
1993 struct ocelot *ocelot = ds->priv; in felix_port_policer_del()
1995 ocelot_port_policer_del(ocelot, port); in felix_port_policer_del()
1998 static int felix_port_mirror_add(struct dsa_switch *ds, int port, in felix_port_mirror_add() argument
2002 struct ocelot *ocelot = ds->priv; in felix_port_mirror_add()
2004 return ocelot_port_mirror_add(ocelot, port, mirror->to_local_port, in felix_port_mirror_add()
2008 static void felix_port_mirror_del(struct dsa_switch *ds, int port, in felix_port_mirror_del() argument
2011 struct ocelot *ocelot = ds->priv; in felix_port_mirror_del()
2013 ocelot_port_mirror_del(ocelot, port, mirror->ingress); in felix_port_mirror_del()
2016 static int felix_port_setup_tc(struct dsa_switch *ds, int port, in felix_port_setup_tc() argument
2020 struct ocelot *ocelot = ds->priv; in felix_port_setup_tc()
2023 if (felix->info->port_setup_tc) in felix_port_setup_tc()
2024 return felix->info->port_setup_tc(ds, port, type, type_data); in felix_port_setup_tc()
2026 return -EOPNOTSUPP; in felix_port_setup_tc()
2033 struct ocelot *ocelot = ds->priv; in felix_sb_pool_get()
2043 struct ocelot *ocelot = ds->priv; in felix_sb_pool_set()
2049 static int felix_sb_port_pool_get(struct dsa_switch *ds, int port, in felix_sb_port_pool_get() argument
2053 struct ocelot *ocelot = ds->priv; in felix_sb_port_pool_get()
2055 return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index, in felix_sb_port_pool_get()
2059 static int felix_sb_port_pool_set(struct dsa_switch *ds, int port, in felix_sb_port_pool_set() argument
2063 struct ocelot *ocelot = ds->priv; in felix_sb_port_pool_set()
2065 return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index, in felix_sb_port_pool_set()
2069 static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port, in felix_sb_tc_pool_bind_get() argument
2074 struct ocelot *ocelot = ds->priv; in felix_sb_tc_pool_bind_get()
2076 return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index, in felix_sb_tc_pool_bind_get()
2081 static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port, in felix_sb_tc_pool_bind_set() argument
2087 struct ocelot *ocelot = ds->priv; in felix_sb_tc_pool_bind_set()
2089 return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index, in felix_sb_tc_pool_bind_set()
2097 struct ocelot *ocelot = ds->priv; in felix_sb_occ_snapshot()
2105 struct ocelot *ocelot = ds->priv; in felix_sb_occ_max_clear()
2110 static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port, in felix_sb_occ_port_pool_get() argument
2114 struct ocelot *ocelot = ds->priv; in felix_sb_occ_port_pool_get()
2116 return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index, in felix_sb_occ_port_pool_get()
2120 static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port, in felix_sb_occ_tc_port_bind_get() argument
2125 struct ocelot *ocelot = ds->priv; in felix_sb_occ_tc_port_bind_get()
2127 return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index, in felix_sb_occ_tc_port_bind_get()
2131 static int felix_mrp_add(struct dsa_switch *ds, int port, in felix_mrp_add() argument
2134 struct ocelot *ocelot = ds->priv; in felix_mrp_add()
2136 return ocelot_mrp_add(ocelot, port, mrp); in felix_mrp_add()
2139 static int felix_mrp_del(struct dsa_switch *ds, int port, in felix_mrp_del() argument
2142 struct ocelot *ocelot = ds->priv; in felix_mrp_del()
2144 return ocelot_mrp_add(ocelot, port, mrp); in felix_mrp_del()
2148 felix_mrp_add_ring_role(struct dsa_switch *ds, int port, in felix_mrp_add_ring_role() argument
2151 struct ocelot *ocelot = ds->priv; in felix_mrp_add_ring_role()
2153 return ocelot_mrp_add_ring_role(ocelot, port, mrp); in felix_mrp_add_ring_role()
2157 felix_mrp_del_ring_role(struct dsa_switch *ds, int port, in felix_mrp_del_ring_role() argument
2160 struct ocelot *ocelot = ds->priv; in felix_mrp_del_ring_role()
2162 return ocelot_mrp_del_ring_role(ocelot, port, mrp); in felix_mrp_del_ring_role()
2165 static int felix_port_get_default_prio(struct dsa_switch *ds, int port) in felix_port_get_default_prio() argument
2167 struct ocelot *ocelot = ds->priv; in felix_port_get_default_prio()
2169 return ocelot_port_get_default_prio(ocelot, port); in felix_port_get_default_prio()
2172 static int felix_port_set_default_prio(struct dsa_switch *ds, int port, in felix_port_set_default_prio() argument
2175 struct ocelot *ocelot = ds->priv; in felix_port_set_default_prio()
2177 return ocelot_port_set_default_prio(ocelot, port, prio); in felix_port_set_default_prio()
2180 static int felix_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) in felix_port_get_dscp_prio() argument
2182 struct ocelot *ocelot = ds->priv; in felix_port_get_dscp_prio()
2184 return ocelot_port_get_dscp_prio(ocelot, port, dscp); in felix_port_get_dscp_prio()
2187 static int felix_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, in felix_port_add_dscp_prio() argument
2190 struct ocelot *ocelot = ds->priv; in felix_port_add_dscp_prio()
2192 return ocelot_port_add_dscp_prio(ocelot, port, dscp, prio); in felix_port_add_dscp_prio()
2195 static int felix_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, in felix_port_del_dscp_prio() argument
2198 struct ocelot *ocelot = ds->priv; in felix_port_del_dscp_prio()
2200 return ocelot_port_del_dscp_prio(ocelot, port, dscp, prio); in felix_port_del_dscp_prio()
2203 static int felix_get_mm(struct dsa_switch *ds, int port, in felix_get_mm() argument
2206 struct ocelot *ocelot = ds->priv; in felix_get_mm()
2208 return ocelot_port_get_mm(ocelot, port, state); in felix_get_mm()
2211 static int felix_set_mm(struct dsa_switch *ds, int port, in felix_set_mm() argument
2215 struct ocelot *ocelot = ds->priv; in felix_set_mm()
2217 return ocelot_port_set_mm(ocelot, port, cfg, extack); in felix_set_mm()
2220 static void felix_get_mm_stats(struct dsa_switch *ds, int port, in felix_get_mm_stats() argument
2223 struct ocelot *ocelot = ds->priv; in felix_get_mm_stats()
2225 ocelot_port_get_mm_stats(ocelot, port, stats); in felix_get_mm_stats()
2329 return -ENOMEM; in felix_register_switch()
2333 return -ENOMEM; in felix_register_switch()
2337 ocelot = &felix->ocelot; in felix_register_switch()
2338 ocelot->dev = dev; in felix_register_switch()
2339 ocelot->num_flooding_pgids = num_flooding_pgids; in felix_register_switch()
2340 ocelot->ptp = ptp; in felix_register_switch()
2341 ocelot->mm_supported = mm_supported; in felix_register_switch()
2343 felix->info = info; in felix_register_switch()
2344 felix->switch_base = switch_base; in felix_register_switch()
2345 felix->ds = ds; in felix_register_switch()
2346 felix->tag_proto = init_tag_proto; in felix_register_switch()
2348 ds->dev = dev; in felix_register_switch()
2349 ds->num_ports = info->num_ports; in felix_register_switch()
2350 ds->num_tx_queues = OCELOT_NUM_TC; in felix_register_switch()
2351 ds->ops = &felix_switch_ops; in felix_register_switch()
2352 ds->phylink_mac_ops = &felix_phylink_mac_ops; in felix_register_switch()
2353 ds->priv = ocelot; in felix_register_switch()
2363 struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) in felix_port_to_netdev() argument
2366 struct dsa_switch *ds = felix->ds; in felix_port_to_netdev()
2368 if (!dsa_is_user_port(ds, port)) in felix_port_to_netdev()
2371 return dsa_to_port(ds, port)->user; in felix_port_to_netdev()
2381 return -EINVAL; in felix_netdev_to_port()
2383 return dp->index; in felix_netdev_to_port()