156051948SVladimir Oltean // SPDX-License-Identifier: GPL-2.0 23c9cfb52SVladimir Oltean /* Copyright 2019-2021 NXP 3375e1314SVladimir Oltean * 4375e1314SVladimir Oltean * This is an umbrella module for all network switches that are 5375e1314SVladimir Oltean * register-compatible with Ocelot and that perform I/O to their host CPU 6375e1314SVladimir Oltean * through an NPI (Node Processor Interface) Ethernet port. 756051948SVladimir Oltean */ 856051948SVladimir Oltean #include <uapi/linux/if_bridge.h> 907d985eeSVladimir Oltean #include <soc/mscc/ocelot_vcap.h> 10bdeced75SVladimir Oltean #include <soc/mscc/ocelot_qsys.h> 11bdeced75SVladimir Oltean #include <soc/mscc/ocelot_sys.h> 12bdeced75SVladimir Oltean #include <soc/mscc/ocelot_dev.h> 13bdeced75SVladimir Oltean #include <soc/mscc/ocelot_ana.h> 142b49d128SYangbo Lu #include <soc/mscc/ocelot_ptp.h> 1556051948SVladimir Oltean #include <soc/mscc/ocelot.h> 16e21268efSVladimir Oltean #include <linux/dsa/8021q.h> 1740d3f295SVladimir Oltean #include <linux/dsa/ocelot.h> 1884705fc1SMaxim Kochetkov #include <linux/platform_device.h> 190a6f17c6SVladimir Oltean #include <linux/ptp_classify.h> 2056051948SVladimir Oltean #include <linux/module.h> 21bdeced75SVladimir Oltean #include <linux/of_net.h> 2256051948SVladimir Oltean #include <linux/pci.h> 2356051948SVladimir Oltean #include <linux/of.h> 24fc411eaaSVladimir Oltean #include <net/pkt_sched.h> 2556051948SVladimir Oltean #include <net/dsa.h> 2656051948SVladimir Oltean #include "felix.h" 2756051948SVladimir Oltean 28f9cef64fSVladimir Oltean /* Translate the DSA database API into the ocelot switch library API, 29f9cef64fSVladimir Oltean * which uses VID 0 for all ports that aren't part of a bridge, 30f9cef64fSVladimir Oltean * and expects the bridge_dev to be NULL in that case. 31f9cef64fSVladimir Oltean */ 32f9cef64fSVladimir Oltean static struct net_device *felix_classify_db(struct dsa_db db) 33f9cef64fSVladimir Oltean { 34f9cef64fSVladimir Oltean switch (db.type) { 35f9cef64fSVladimir Oltean case DSA_DB_PORT: 36f9cef64fSVladimir Oltean case DSA_DB_LAG: 37f9cef64fSVladimir Oltean return NULL; 38f9cef64fSVladimir Oltean case DSA_DB_BRIDGE: 39f9cef64fSVladimir Oltean return db.bridge.dev; 40f9cef64fSVladimir Oltean default: 41f9cef64fSVladimir Oltean return ERR_PTR(-EOPNOTSUPP); 42f9cef64fSVladimir Oltean } 43f9cef64fSVladimir Oltean } 44f9cef64fSVladimir Oltean 45b903a6bdSVladimir Oltean static void felix_migrate_pgid_bit(struct dsa_switch *ds, int from, int to, 46b903a6bdSVladimir Oltean int pgid) 47b903a6bdSVladimir Oltean { 48b903a6bdSVladimir Oltean struct ocelot *ocelot = ds->priv; 49b903a6bdSVladimir Oltean bool on; 50b903a6bdSVladimir Oltean u32 val; 51b903a6bdSVladimir Oltean 52b903a6bdSVladimir Oltean val = ocelot_read_rix(ocelot, ANA_PGID_PGID, pgid); 53b903a6bdSVladimir Oltean on = !!(val & BIT(from)); 54b903a6bdSVladimir Oltean val &= ~BIT(from); 55b903a6bdSVladimir Oltean if (on) 56b903a6bdSVladimir Oltean val |= BIT(to); 57b903a6bdSVladimir Oltean else 58b903a6bdSVladimir Oltean val &= ~BIT(to); 59b903a6bdSVladimir Oltean 60b903a6bdSVladimir Oltean ocelot_write_rix(ocelot, val, ANA_PGID_PGID, pgid); 61b903a6bdSVladimir Oltean } 62b903a6bdSVladimir Oltean 63b903a6bdSVladimir Oltean static void felix_migrate_flood_to_npi_port(struct dsa_switch *ds, int port) 64b903a6bdSVladimir Oltean { 65b903a6bdSVladimir Oltean struct ocelot *ocelot = ds->priv; 66b903a6bdSVladimir Oltean 67b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, port, ocelot->num_phys_ports, PGID_UC); 68b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, port, ocelot->num_phys_ports, PGID_MC); 69b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, port, ocelot->num_phys_ports, PGID_BC); 70b903a6bdSVladimir Oltean } 71b903a6bdSVladimir Oltean 72b903a6bdSVladimir Oltean static void 73b903a6bdSVladimir Oltean felix_migrate_flood_to_tag_8021q_port(struct dsa_switch *ds, int port) 74b903a6bdSVladimir Oltean { 75b903a6bdSVladimir Oltean struct ocelot *ocelot = ds->priv; 76b903a6bdSVladimir Oltean 77b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, ocelot->num_phys_ports, port, PGID_UC); 78b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, ocelot->num_phys_ports, port, PGID_MC); 79b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, ocelot->num_phys_ports, port, PGID_BC); 80b903a6bdSVladimir Oltean } 81b903a6bdSVladimir Oltean 8204b67e18SVladimir Oltean /* Set up VCAP ES0 rules for pushing a tag_8021q VLAN towards the CPU such that 8304b67e18SVladimir Oltean * the tagger can perform RX source port identification. 8404b67e18SVladimir Oltean */ 8504b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add_rx(struct felix *felix, int port, u16 vid) 86e21268efSVladimir Oltean { 87e21268efSVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 88e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 89e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 90e21268efSVladimir Oltean int key_length, upstream, err; 91e21268efSVladimir Oltean 92e21268efSVladimir Oltean key_length = ocelot->vcap[VCAP_ES0].keys[VCAP_ES0_IGR_PORT].length; 93e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 94e21268efSVladimir Oltean 95e21268efSVladimir Oltean outer_tagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), 96e21268efSVladimir Oltean GFP_KERNEL); 97e21268efSVladimir Oltean if (!outer_tagging_rule) 98e21268efSVladimir Oltean return -ENOMEM; 99e21268efSVladimir Oltean 100e21268efSVladimir Oltean outer_tagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 101e21268efSVladimir Oltean outer_tagging_rule->prio = 1; 102c518afecSVladimir Oltean outer_tagging_rule->id.cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port); 103e21268efSVladimir Oltean outer_tagging_rule->id.tc_offload = false; 104e21268efSVladimir Oltean outer_tagging_rule->block_id = VCAP_ES0; 105e21268efSVladimir Oltean outer_tagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 106e21268efSVladimir Oltean outer_tagging_rule->lookup = 0; 107e21268efSVladimir Oltean outer_tagging_rule->ingress_port.value = port; 108e21268efSVladimir Oltean outer_tagging_rule->ingress_port.mask = GENMASK(key_length - 1, 0); 109e21268efSVladimir Oltean outer_tagging_rule->egress_port.value = upstream; 110e21268efSVladimir Oltean outer_tagging_rule->egress_port.mask = GENMASK(key_length - 1, 0); 111e21268efSVladimir Oltean outer_tagging_rule->action.push_outer_tag = OCELOT_ES0_TAG; 112e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_tpid_sel = OCELOT_TAG_TPID_SEL_8021AD; 113e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_vid_sel = 1; 114e21268efSVladimir Oltean outer_tagging_rule->action.vid_a_val = vid; 115e21268efSVladimir Oltean 116e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, outer_tagging_rule, NULL); 117e21268efSVladimir Oltean if (err) 118e21268efSVladimir Oltean kfree(outer_tagging_rule); 119e21268efSVladimir Oltean 120e21268efSVladimir Oltean return err; 121e21268efSVladimir Oltean } 122e21268efSVladimir Oltean 12304b67e18SVladimir Oltean static int felix_tag_8021q_vlan_del_rx(struct felix *felix, int port, u16 vid) 12404b67e18SVladimir Oltean { 12504b67e18SVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 12604b67e18SVladimir Oltean struct ocelot_vcap_block *block_vcap_es0; 12704b67e18SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 12804b67e18SVladimir Oltean 12904b67e18SVladimir Oltean block_vcap_es0 = &ocelot->block[VCAP_ES0]; 13004b67e18SVladimir Oltean 13104b67e18SVladimir Oltean outer_tagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_es0, 13204b67e18SVladimir Oltean port, false); 13304b67e18SVladimir Oltean if (!outer_tagging_rule) 13404b67e18SVladimir Oltean return -ENOENT; 13504b67e18SVladimir Oltean 13604b67e18SVladimir Oltean return ocelot_vcap_filter_del(ocelot, outer_tagging_rule); 13704b67e18SVladimir Oltean } 13804b67e18SVladimir Oltean 13904b67e18SVladimir Oltean /* Set up VCAP IS1 rules for stripping the tag_8021q VLAN on TX and VCAP IS2 14004b67e18SVladimir Oltean * rules for steering those tagged packets towards the correct destination port 14104b67e18SVladimir Oltean */ 14204b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add_tx(struct felix *felix, int port, u16 vid) 143e21268efSVladimir Oltean { 144e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 145e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 146e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 147e21268efSVladimir Oltean int upstream, err; 148e21268efSVladimir Oltean 149e21268efSVladimir Oltean untagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 150e21268efSVladimir Oltean if (!untagging_rule) 151e21268efSVladimir Oltean return -ENOMEM; 152e21268efSVladimir Oltean 153e21268efSVladimir Oltean redirect_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 154e21268efSVladimir Oltean if (!redirect_rule) { 155e21268efSVladimir Oltean kfree(untagging_rule); 156e21268efSVladimir Oltean return -ENOMEM; 157e21268efSVladimir Oltean } 158e21268efSVladimir Oltean 159e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 160e21268efSVladimir Oltean 161e21268efSVladimir Oltean untagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 162e21268efSVladimir Oltean untagging_rule->ingress_port_mask = BIT(upstream); 163e21268efSVladimir Oltean untagging_rule->vlan.vid.value = vid; 164e21268efSVladimir Oltean untagging_rule->vlan.vid.mask = VLAN_VID_MASK; 165e21268efSVladimir Oltean untagging_rule->prio = 1; 166c518afecSVladimir Oltean untagging_rule->id.cookie = OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port); 167e21268efSVladimir Oltean untagging_rule->id.tc_offload = false; 168e21268efSVladimir Oltean untagging_rule->block_id = VCAP_IS1; 169e21268efSVladimir Oltean untagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 170e21268efSVladimir Oltean untagging_rule->lookup = 0; 171e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt_ena = true; 172e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt = 1; 173e21268efSVladimir Oltean untagging_rule->action.pag_override_mask = 0xff; 174e21268efSVladimir Oltean untagging_rule->action.pag_val = port; 175e21268efSVladimir Oltean 176e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, untagging_rule, NULL); 177e21268efSVladimir Oltean if (err) { 178e21268efSVladimir Oltean kfree(untagging_rule); 179e21268efSVladimir Oltean kfree(redirect_rule); 180e21268efSVladimir Oltean return err; 181e21268efSVladimir Oltean } 182e21268efSVladimir Oltean 183e21268efSVladimir Oltean redirect_rule->key_type = OCELOT_VCAP_KEY_ANY; 184e21268efSVladimir Oltean redirect_rule->ingress_port_mask = BIT(upstream); 185e21268efSVladimir Oltean redirect_rule->pag = port; 186e21268efSVladimir Oltean redirect_rule->prio = 1; 187c518afecSVladimir Oltean redirect_rule->id.cookie = OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port); 188e21268efSVladimir Oltean redirect_rule->id.tc_offload = false; 189e21268efSVladimir Oltean redirect_rule->block_id = VCAP_IS2; 190e21268efSVladimir Oltean redirect_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 191e21268efSVladimir Oltean redirect_rule->lookup = 0; 192e21268efSVladimir Oltean redirect_rule->action.mask_mode = OCELOT_MASK_MODE_REDIRECT; 193e21268efSVladimir Oltean redirect_rule->action.port_mask = BIT(port); 194e21268efSVladimir Oltean 195e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, redirect_rule, NULL); 196e21268efSVladimir Oltean if (err) { 197e21268efSVladimir Oltean ocelot_vcap_filter_del(ocelot, untagging_rule); 198e21268efSVladimir Oltean kfree(redirect_rule); 199e21268efSVladimir Oltean return err; 200e21268efSVladimir Oltean } 201e21268efSVladimir Oltean 202e21268efSVladimir Oltean return 0; 203e21268efSVladimir Oltean } 204e21268efSVladimir Oltean 20504b67e18SVladimir Oltean static int felix_tag_8021q_vlan_del_tx(struct felix *felix, int port, u16 vid) 206e21268efSVladimir Oltean { 207e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 208e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is1; 209e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is2; 210e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 211e21268efSVladimir Oltean int err; 212e21268efSVladimir Oltean 213e21268efSVladimir Oltean block_vcap_is1 = &ocelot->block[VCAP_IS1]; 214e21268efSVladimir Oltean block_vcap_is2 = &ocelot->block[VCAP_IS2]; 215e21268efSVladimir Oltean 216e21268efSVladimir Oltean untagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is1, 217e21268efSVladimir Oltean port, false); 218e21268efSVladimir Oltean if (!untagging_rule) 21908f44db3SVladimir Oltean return -ENOENT; 220e21268efSVladimir Oltean 221e21268efSVladimir Oltean err = ocelot_vcap_filter_del(ocelot, untagging_rule); 222e21268efSVladimir Oltean if (err) 223e21268efSVladimir Oltean return err; 224e21268efSVladimir Oltean 225e21268efSVladimir Oltean redirect_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is2, 226e21268efSVladimir Oltean port, false); 227e21268efSVladimir Oltean if (!redirect_rule) 22804b67e18SVladimir Oltean return -ENOENT; 229e21268efSVladimir Oltean 230e21268efSVladimir Oltean return ocelot_vcap_filter_del(ocelot, redirect_rule); 231e21268efSVladimir Oltean } 232e21268efSVladimir Oltean 23304b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, 23404b67e18SVladimir Oltean u16 flags) 23504b67e18SVladimir Oltean { 23604b67e18SVladimir Oltean struct ocelot *ocelot = ds->priv; 23704b67e18SVladimir Oltean int err; 23804b67e18SVladimir Oltean 23904b67e18SVladimir Oltean /* tag_8021q.c assumes we are implementing this via port VLAN 24004b67e18SVladimir Oltean * membership, which we aren't. So we don't need to add any VCAP filter 24104b67e18SVladimir Oltean * for the CPU port. 24204b67e18SVladimir Oltean */ 24304b67e18SVladimir Oltean if (!dsa_is_user_port(ds, port)) 24404b67e18SVladimir Oltean return 0; 24504b67e18SVladimir Oltean 24604b67e18SVladimir Oltean err = felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid); 24704b67e18SVladimir Oltean if (err) 24804b67e18SVladimir Oltean return err; 24904b67e18SVladimir Oltean 25004b67e18SVladimir Oltean err = felix_tag_8021q_vlan_add_tx(ocelot_to_felix(ocelot), port, vid); 25104b67e18SVladimir Oltean if (err) { 25204b67e18SVladimir Oltean felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid); 25304b67e18SVladimir Oltean return err; 25404b67e18SVladimir Oltean } 25504b67e18SVladimir Oltean 25604b67e18SVladimir Oltean return 0; 25704b67e18SVladimir Oltean } 25804b67e18SVladimir Oltean 259e21268efSVladimir Oltean static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) 260e21268efSVladimir Oltean { 261e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 26204b67e18SVladimir Oltean int err; 263e21268efSVladimir Oltean 26404b67e18SVladimir Oltean if (!dsa_is_user_port(ds, port)) 26504b67e18SVladimir Oltean return 0; 266e21268efSVladimir Oltean 26704b67e18SVladimir Oltean err = felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid); 26804b67e18SVladimir Oltean if (err) 26904b67e18SVladimir Oltean return err; 27004b67e18SVladimir Oltean 27104b67e18SVladimir Oltean err = felix_tag_8021q_vlan_del_tx(ocelot_to_felix(ocelot), port, vid); 27204b67e18SVladimir Oltean if (err) { 27304b67e18SVladimir Oltean felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid); 27404b67e18SVladimir Oltean return err; 27504b67e18SVladimir Oltean } 276e21268efSVladimir Oltean 277e21268efSVladimir Oltean return 0; 278e21268efSVladimir Oltean } 279e21268efSVladimir Oltean 280e21268efSVladimir Oltean /* Alternatively to using the NPI functionality, that same hardware MAC 281e21268efSVladimir Oltean * connected internally to the enetc or fman DSA master can be configured to 282e21268efSVladimir Oltean * use the software-defined tag_8021q frame format. As far as the hardware is 283e21268efSVladimir Oltean * concerned, it thinks it is a "dumb switch" - the queues of the CPU port 284e21268efSVladimir Oltean * module are now disconnected from it, but can still be accessed through 285e21268efSVladimir Oltean * register-based MMIO. 286e21268efSVladimir Oltean */ 287e21268efSVladimir Oltean static void felix_8021q_cpu_port_init(struct ocelot *ocelot, int port) 288e21268efSVladimir Oltean { 2898abe1970SVladimir Oltean mutex_lock(&ocelot->fwd_domain_lock); 2908abe1970SVladimir Oltean 29154c31984SVladimir Oltean ocelot_port_set_dsa_8021q_cpu(ocelot, port); 292e21268efSVladimir Oltean 293e21268efSVladimir Oltean /* Overwrite PGID_CPU with the non-tagging port */ 294e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, PGID_CPU); 295e21268efSVladimir Oltean 2968abe1970SVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot, true); 2978abe1970SVladimir Oltean 2988abe1970SVladimir Oltean mutex_unlock(&ocelot->fwd_domain_lock); 299e21268efSVladimir Oltean } 300e21268efSVladimir Oltean 301e21268efSVladimir Oltean static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port) 302e21268efSVladimir Oltean { 3038abe1970SVladimir Oltean mutex_lock(&ocelot->fwd_domain_lock); 3048abe1970SVladimir Oltean 30554c31984SVladimir Oltean ocelot_port_unset_dsa_8021q_cpu(ocelot, port); 306e21268efSVladimir Oltean 307e21268efSVladimir Oltean /* Restore PGID_CPU */ 308e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(ocelot->num_phys_ports), ANA_PGID_PGID, 309e21268efSVladimir Oltean PGID_CPU); 310e21268efSVladimir Oltean 3118abe1970SVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot, true); 3128abe1970SVladimir Oltean 3138abe1970SVladimir Oltean mutex_unlock(&ocelot->fwd_domain_lock); 314e21268efSVladimir Oltean } 315e21268efSVladimir Oltean 31699348004SVladimir Oltean /* On switches with no extraction IRQ wired, trapped packets need to be 31799348004SVladimir Oltean * replicated over Ethernet as well, otherwise we'd get no notification of 31899348004SVladimir Oltean * their arrival when using the ocelot-8021q tagging protocol. 319c8c0ba4fSVladimir Oltean */ 32099348004SVladimir Oltean static int felix_update_trapping_destinations(struct dsa_switch *ds, 32199348004SVladimir Oltean bool using_tag_8021q) 322c8c0ba4fSVladimir Oltean { 32399348004SVladimir Oltean struct ocelot *ocelot = ds->priv; 32499348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 32599348004SVladimir Oltean struct ocelot_vcap_filter *trap; 32699348004SVladimir Oltean enum ocelot_mask_mode mask_mode; 32799348004SVladimir Oltean unsigned long port_mask; 3282960bb14SVladimir Oltean struct dsa_port *dp; 32999348004SVladimir Oltean bool cpu_copy_ena; 33099348004SVladimir Oltean int cpu = -1, err; 331c8c0ba4fSVladimir Oltean 33299348004SVladimir Oltean if (!felix->info->quirk_no_xtr_irq) 33399348004SVladimir Oltean return 0; 334c8c0ba4fSVladimir Oltean 33599348004SVladimir Oltean /* Figure out the current CPU port */ 3362960bb14SVladimir Oltean dsa_switch_for_each_cpu_port(dp, ds) { 3372960bb14SVladimir Oltean cpu = dp->index; 3388d5f7954SVladimir Oltean break; 339c8c0ba4fSVladimir Oltean } 3408d5f7954SVladimir Oltean 341d78637a8SVladimir Oltean /* We are sure that "cpu" was found, otherwise 342d78637a8SVladimir Oltean * dsa_tree_setup_default_cpu() would have failed earlier. 343d78637a8SVladimir Oltean */ 344c8c0ba4fSVladimir Oltean 34599348004SVladimir Oltean /* Make sure all traps are set up for that destination */ 34699348004SVladimir Oltean list_for_each_entry(trap, &ocelot->traps, trap_list) { 34799348004SVladimir Oltean /* Figure out the current trapping destination */ 34899348004SVladimir Oltean if (using_tag_8021q) { 34999348004SVladimir Oltean /* Redirect to the tag_8021q CPU port. If timestamps 35099348004SVladimir Oltean * are necessary, also copy trapped packets to the CPU 35199348004SVladimir Oltean * port module. 352c8c0ba4fSVladimir Oltean */ 35399348004SVladimir Oltean mask_mode = OCELOT_MASK_MODE_REDIRECT; 35499348004SVladimir Oltean port_mask = BIT(cpu); 35599348004SVladimir Oltean cpu_copy_ena = !!trap->take_ts; 356c8c0ba4fSVladimir Oltean } else { 35799348004SVladimir Oltean /* Trap packets only to the CPU port module, which is 35899348004SVladimir Oltean * redirected to the NPI port (the DSA CPU port) 359c8c0ba4fSVladimir Oltean */ 36099348004SVladimir Oltean mask_mode = OCELOT_MASK_MODE_PERMIT_DENY; 36199348004SVladimir Oltean port_mask = 0; 36299348004SVladimir Oltean cpu_copy_ena = true; 363c8c0ba4fSVladimir Oltean } 364c8c0ba4fSVladimir Oltean 36599348004SVladimir Oltean if (trap->action.mask_mode == mask_mode && 36699348004SVladimir Oltean trap->action.port_mask == port_mask && 36799348004SVladimir Oltean trap->action.cpu_copy_ena == cpu_copy_ena) 36899348004SVladimir Oltean continue; 369c8c0ba4fSVladimir Oltean 37099348004SVladimir Oltean trap->action.mask_mode = mask_mode; 37199348004SVladimir Oltean trap->action.port_mask = port_mask; 37299348004SVladimir Oltean trap->action.cpu_copy_ena = cpu_copy_ena; 3730a6f17c6SVladimir Oltean 37499348004SVladimir Oltean err = ocelot_vcap_filter_replace(ocelot, trap); 375c8c0ba4fSVladimir Oltean if (err) 376c8c0ba4fSVladimir Oltean return err; 37799348004SVladimir Oltean } 378c8c0ba4fSVladimir Oltean 37999348004SVladimir Oltean return 0; 380c8c0ba4fSVladimir Oltean } 381c8c0ba4fSVladimir Oltean 382c69f40acSVladimir Oltean static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) 383e21268efSVladimir Oltean { 384e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 3852960bb14SVladimir Oltean struct dsa_port *dp; 3862960bb14SVladimir Oltean int err; 387e21268efSVladimir Oltean 388e21268efSVladimir Oltean felix_8021q_cpu_port_init(ocelot, cpu); 389e21268efSVladimir Oltean 3902960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 391e21268efSVladimir Oltean /* This overwrites ocelot_init(): 392e21268efSVladimir Oltean * Do not forward BPDU frames to the CPU port module, 393e21268efSVladimir Oltean * for 2 reasons: 394e21268efSVladimir Oltean * - When these packets are injected from the tag_8021q 395e21268efSVladimir Oltean * CPU port, we want them to go out, not loop back 396e21268efSVladimir Oltean * into the system. 397e21268efSVladimir Oltean * - STP traffic ingressing on a user port should go to 398e21268efSVladimir Oltean * the tag_8021q CPU port, not to the hardware CPU 399e21268efSVladimir Oltean * port module. 400e21268efSVladimir Oltean */ 401e21268efSVladimir Oltean ocelot_write_gix(ocelot, 402e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0), 4032960bb14SVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, dp->index); 404e21268efSVladimir Oltean } 405e21268efSVladimir Oltean 4065da11eb4SVladimir Oltean err = dsa_tag_8021q_register(ds, htons(ETH_P_8021AD)); 407e21268efSVladimir Oltean if (err) 408d7b1fd52SVladimir Oltean return err; 409d7b1fd52SVladimir Oltean 41028de0f9fSVladimir Oltean err = ocelot_migrate_mdbs(ocelot, BIT(ocelot->num_phys_ports), 41128de0f9fSVladimir Oltean BIT(cpu)); 412f9cef64fSVladimir Oltean if (err) 413a51c1c3fSVladimir Oltean goto out_tag_8021q_unregister; 414b903a6bdSVladimir Oltean 415b903a6bdSVladimir Oltean felix_migrate_flood_to_tag_8021q_port(ds, cpu); 416f9cef64fSVladimir Oltean 417f9cef64fSVladimir Oltean err = felix_update_trapping_destinations(ds, true); 418f9cef64fSVladimir Oltean if (err) 419b903a6bdSVladimir Oltean goto out_migrate_flood; 420f9cef64fSVladimir Oltean 42199348004SVladimir Oltean /* The ownership of the CPU port module's queues might have just been 42299348004SVladimir Oltean * transferred to the tag_8021q tagger from the NPI-based tagger. 42399348004SVladimir Oltean * So there might still be all sorts of crap in the queues. On the 42499348004SVladimir Oltean * other hand, the MMIO-based matching of PTP frames is very brittle, 42599348004SVladimir Oltean * so we need to be careful that there are no extra frames to be 42699348004SVladimir Oltean * dequeued over MMIO, since we would never know to discard them. 42799348004SVladimir Oltean */ 42899348004SVladimir Oltean ocelot_drain_cpu_queue(ocelot, 0); 42999348004SVladimir Oltean 430e21268efSVladimir Oltean return 0; 431e21268efSVladimir Oltean 432b903a6bdSVladimir Oltean out_migrate_flood: 433b903a6bdSVladimir Oltean felix_migrate_flood_to_npi_port(ds, cpu); 43428de0f9fSVladimir Oltean ocelot_migrate_mdbs(ocelot, BIT(cpu), BIT(ocelot->num_phys_ports)); 435d7b1fd52SVladimir Oltean out_tag_8021q_unregister: 436d7b1fd52SVladimir Oltean dsa_tag_8021q_unregister(ds); 437e21268efSVladimir Oltean return err; 438e21268efSVladimir Oltean } 439e21268efSVladimir Oltean 440e21268efSVladimir Oltean static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) 441e21268efSVladimir Oltean { 442e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 4432960bb14SVladimir Oltean struct dsa_port *dp; 4442960bb14SVladimir Oltean int err; 445e21268efSVladimir Oltean 44699348004SVladimir Oltean err = felix_update_trapping_destinations(ds, false); 447c8c0ba4fSVladimir Oltean if (err) 448c8c0ba4fSVladimir Oltean dev_err(ds->dev, "felix_teardown_mmio_filtering returned %d", 449c8c0ba4fSVladimir Oltean err); 450c8c0ba4fSVladimir Oltean 451d7b1fd52SVladimir Oltean dsa_tag_8021q_unregister(ds); 452e21268efSVladimir Oltean 4532960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 454e21268efSVladimir Oltean /* Restore the logic from ocelot_init: 455e21268efSVladimir Oltean * do not forward BPDU frames to the front ports. 456e21268efSVladimir Oltean */ 457e21268efSVladimir Oltean ocelot_write_gix(ocelot, 458e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff), 459e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, 4602960bb14SVladimir Oltean dp->index); 461e21268efSVladimir Oltean } 462e21268efSVladimir Oltean 463e21268efSVladimir Oltean felix_8021q_cpu_port_deinit(ocelot, cpu); 464e21268efSVladimir Oltean } 465e21268efSVladimir Oltean 466adb3dccfSVladimir Oltean /* The CPU port module is connected to the Node Processor Interface (NPI). This 467adb3dccfSVladimir Oltean * is the mode through which frames can be injected from and extracted to an 468adb3dccfSVladimir Oltean * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU 469adb3dccfSVladimir Oltean * running Linux, and this forms a DSA setup together with the enetc or fman 470adb3dccfSVladimir Oltean * DSA master. 471adb3dccfSVladimir Oltean */ 472adb3dccfSVladimir Oltean static void felix_npi_port_init(struct ocelot *ocelot, int port) 473adb3dccfSVladimir Oltean { 474adb3dccfSVladimir Oltean ocelot->npi = port; 475adb3dccfSVladimir Oltean 476adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M | 477adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port), 478adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 479adb3dccfSVladimir Oltean 480adb3dccfSVladimir Oltean /* NPI port Injection/Extraction configuration */ 481adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 482adb3dccfSVladimir Oltean ocelot->npi_xtr_prefix); 483adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 484adb3dccfSVladimir Oltean ocelot->npi_inj_prefix); 485adb3dccfSVladimir Oltean 486adb3dccfSVladimir Oltean /* Disable transmission of pause frames */ 487adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0); 488adb3dccfSVladimir Oltean } 489adb3dccfSVladimir Oltean 490adb3dccfSVladimir Oltean static void felix_npi_port_deinit(struct ocelot *ocelot, int port) 491adb3dccfSVladimir Oltean { 492adb3dccfSVladimir Oltean /* Restore hardware defaults */ 493adb3dccfSVladimir Oltean int unused_port = ocelot->num_phys_ports + 2; 494adb3dccfSVladimir Oltean 495adb3dccfSVladimir Oltean ocelot->npi = -1; 496adb3dccfSVladimir Oltean 497adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPU_PORT(unused_port), 498adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 499adb3dccfSVladimir Oltean 500adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 501adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 502adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 503adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 504adb3dccfSVladimir Oltean 505adb3dccfSVladimir Oltean /* Enable transmission of pause frames */ 506adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); 507adb3dccfSVladimir Oltean } 508adb3dccfSVladimir Oltean 509c69f40acSVladimir Oltean static int felix_setup_tag_npi(struct dsa_switch *ds, int cpu) 510adb3dccfSVladimir Oltean { 511adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 512f9cef64fSVladimir Oltean int err; 513f9cef64fSVladimir Oltean 51428de0f9fSVladimir Oltean err = ocelot_migrate_mdbs(ocelot, BIT(cpu), 51528de0f9fSVladimir Oltean BIT(ocelot->num_phys_ports)); 516f9cef64fSVladimir Oltean if (err) 517a51c1c3fSVladimir Oltean return err; 518b903a6bdSVladimir Oltean 519b903a6bdSVladimir Oltean felix_migrate_flood_to_npi_port(ds, cpu); 520adb3dccfSVladimir Oltean 521adb3dccfSVladimir Oltean felix_npi_port_init(ocelot, cpu); 522adb3dccfSVladimir Oltean 523adb3dccfSVladimir Oltean return 0; 524adb3dccfSVladimir Oltean } 525adb3dccfSVladimir Oltean 526adb3dccfSVladimir Oltean static void felix_teardown_tag_npi(struct dsa_switch *ds, int cpu) 527adb3dccfSVladimir Oltean { 528adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 529adb3dccfSVladimir Oltean 530adb3dccfSVladimir Oltean felix_npi_port_deinit(ocelot, cpu); 531adb3dccfSVladimir Oltean } 532adb3dccfSVladimir Oltean 533adb3dccfSVladimir Oltean static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu, 534c69f40acSVladimir Oltean enum dsa_tag_protocol proto) 535adb3dccfSVladimir Oltean { 536adb3dccfSVladimir Oltean int err; 537adb3dccfSVladimir Oltean 538adb3dccfSVladimir Oltean switch (proto) { 5397c4bb540SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 540adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 541c69f40acSVladimir Oltean err = felix_setup_tag_npi(ds, cpu); 542adb3dccfSVladimir Oltean break; 543e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 544c69f40acSVladimir Oltean err = felix_setup_tag_8021q(ds, cpu); 545e21268efSVladimir Oltean break; 546adb3dccfSVladimir Oltean default: 547adb3dccfSVladimir Oltean err = -EPROTONOSUPPORT; 548adb3dccfSVladimir Oltean } 549adb3dccfSVladimir Oltean 550adb3dccfSVladimir Oltean return err; 551adb3dccfSVladimir Oltean } 552adb3dccfSVladimir Oltean 553adb3dccfSVladimir Oltean static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu, 554adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 555adb3dccfSVladimir Oltean { 556adb3dccfSVladimir Oltean switch (proto) { 5577c4bb540SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 558adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 559adb3dccfSVladimir Oltean felix_teardown_tag_npi(ds, cpu); 560adb3dccfSVladimir Oltean break; 561e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 562e21268efSVladimir Oltean felix_teardown_tag_8021q(ds, cpu); 563e21268efSVladimir Oltean break; 564adb3dccfSVladimir Oltean default: 565adb3dccfSVladimir Oltean break; 566adb3dccfSVladimir Oltean } 567adb3dccfSVladimir Oltean } 568adb3dccfSVladimir Oltean 569e21268efSVladimir Oltean /* This always leaves the switch in a consistent state, because although the 570e21268efSVladimir Oltean * tag_8021q setup can fail, the NPI setup can't. So either the change is made, 571e21268efSVladimir Oltean * or the restoration is guaranteed to work. 572e21268efSVladimir Oltean */ 573adb3dccfSVladimir Oltean static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu, 574adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 575adb3dccfSVladimir Oltean { 576adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 577adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 578adb3dccfSVladimir Oltean enum dsa_tag_protocol old_proto = felix->tag_proto; 57900fa91bcSVladimir Oltean bool cpu_port_active = false; 58000fa91bcSVladimir Oltean struct dsa_port *dp; 581adb3dccfSVladimir Oltean int err; 582adb3dccfSVladimir Oltean 5837c4bb540SVladimir Oltean if (proto != DSA_TAG_PROTO_SEVILLE && 5847c4bb540SVladimir Oltean proto != DSA_TAG_PROTO_OCELOT && 585e21268efSVladimir Oltean proto != DSA_TAG_PROTO_OCELOT_8021Q) 586adb3dccfSVladimir Oltean return -EPROTONOSUPPORT; 587adb3dccfSVladimir Oltean 58800fa91bcSVladimir Oltean /* We don't support multiple CPU ports, yet the DT blob may have 58900fa91bcSVladimir Oltean * multiple CPU ports defined. The first CPU port is the active one, 59000fa91bcSVladimir Oltean * the others are inactive. In this case, DSA will call 59100fa91bcSVladimir Oltean * ->change_tag_protocol() multiple times, once per CPU port. 59200fa91bcSVladimir Oltean * Since we implement the tagging protocol change towards "ocelot" or 59300fa91bcSVladimir Oltean * "seville" as effectively initializing the NPI port, what we are 59400fa91bcSVladimir Oltean * doing is effectively changing who the NPI port is to the last @cpu 59500fa91bcSVladimir Oltean * argument passed, which is an unused DSA CPU port and not the one 59600fa91bcSVladimir Oltean * that should actively pass traffic. 59700fa91bcSVladimir Oltean * Suppress DSA's calls on CPU ports that are inactive. 59800fa91bcSVladimir Oltean */ 59900fa91bcSVladimir Oltean dsa_switch_for_each_user_port(dp, ds) { 60000fa91bcSVladimir Oltean if (dp->cpu_dp->index == cpu) { 60100fa91bcSVladimir Oltean cpu_port_active = true; 60200fa91bcSVladimir Oltean break; 60300fa91bcSVladimir Oltean } 60400fa91bcSVladimir Oltean } 60500fa91bcSVladimir Oltean 60600fa91bcSVladimir Oltean if (!cpu_port_active) 60700fa91bcSVladimir Oltean return 0; 60800fa91bcSVladimir Oltean 609adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, cpu, old_proto); 610adb3dccfSVladimir Oltean 611c69f40acSVladimir Oltean err = felix_set_tag_protocol(ds, cpu, proto); 612adb3dccfSVladimir Oltean if (err) { 613c69f40acSVladimir Oltean felix_set_tag_protocol(ds, cpu, old_proto); 614adb3dccfSVladimir Oltean return err; 615adb3dccfSVladimir Oltean } 616adb3dccfSVladimir Oltean 617adb3dccfSVladimir Oltean felix->tag_proto = proto; 618adb3dccfSVladimir Oltean 619adb3dccfSVladimir Oltean return 0; 620adb3dccfSVladimir Oltean } 621adb3dccfSVladimir Oltean 62256051948SVladimir Oltean static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds, 6234d776482SFlorian Fainelli int port, 6244d776482SFlorian Fainelli enum dsa_tag_protocol mp) 62556051948SVladimir Oltean { 626adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 627adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 628adb3dccfSVladimir Oltean 629adb3dccfSVladimir Oltean return felix->tag_proto; 63056051948SVladimir Oltean } 63156051948SVladimir Oltean 63256051948SVladimir Oltean static int felix_set_ageing_time(struct dsa_switch *ds, 63356051948SVladimir Oltean unsigned int ageing_time) 63456051948SVladimir Oltean { 63556051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 63656051948SVladimir Oltean 63756051948SVladimir Oltean ocelot_set_ageing_time(ocelot, ageing_time); 63856051948SVladimir Oltean 63956051948SVladimir Oltean return 0; 64056051948SVladimir Oltean } 64156051948SVladimir Oltean 6425cad43a5SVladimir Oltean static void felix_port_fast_age(struct dsa_switch *ds, int port) 6435cad43a5SVladimir Oltean { 6445cad43a5SVladimir Oltean struct ocelot *ocelot = ds->priv; 6455cad43a5SVladimir Oltean int err; 6465cad43a5SVladimir Oltean 6475cad43a5SVladimir Oltean err = ocelot_mact_flush(ocelot, port); 6485cad43a5SVladimir Oltean if (err) 6495cad43a5SVladimir Oltean dev_err(ds->dev, "Flushing MAC table on port %d returned %pe\n", 6505cad43a5SVladimir Oltean port, ERR_PTR(err)); 6515cad43a5SVladimir Oltean } 6525cad43a5SVladimir Oltean 65356051948SVladimir Oltean static int felix_fdb_dump(struct dsa_switch *ds, int port, 65456051948SVladimir Oltean dsa_fdb_dump_cb_t *cb, void *data) 65556051948SVladimir Oltean { 65656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 65756051948SVladimir Oltean 65856051948SVladimir Oltean return ocelot_fdb_dump(ocelot, port, cb, data); 65956051948SVladimir Oltean } 66056051948SVladimir Oltean 66156051948SVladimir Oltean static int felix_fdb_add(struct dsa_switch *ds, int port, 662c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 663c2693363SVladimir Oltean struct dsa_db db) 66456051948SVladimir Oltean { 66554c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 66656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 66756051948SVladimir Oltean 66854c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 66954c31984SVladimir Oltean return PTR_ERR(bridge_dev); 67054c31984SVladimir Oltean 6717e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 6727e580490SVladimir Oltean dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) 6737e580490SVladimir Oltean return 0; 6747e580490SVladimir Oltean 67554c31984SVladimir Oltean return ocelot_fdb_add(ocelot, port, addr, vid, bridge_dev); 67656051948SVladimir Oltean } 67756051948SVladimir Oltean 67856051948SVladimir Oltean static int felix_fdb_del(struct dsa_switch *ds, int port, 679c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 680c2693363SVladimir Oltean struct dsa_db db) 68156051948SVladimir Oltean { 68254c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 68356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 68456051948SVladimir Oltean 68554c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 68654c31984SVladimir Oltean return PTR_ERR(bridge_dev); 68754c31984SVladimir Oltean 6887e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 6897e580490SVladimir Oltean dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) 6907e580490SVladimir Oltean return 0; 6917e580490SVladimir Oltean 69254c31984SVladimir Oltean return ocelot_fdb_del(ocelot, port, addr, vid, bridge_dev); 69356051948SVladimir Oltean } 69456051948SVladimir Oltean 695961d8b69SVladimir Oltean static int felix_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag lag, 696c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 697c2693363SVladimir Oltean struct dsa_db db) 698961d8b69SVladimir Oltean { 69954c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 700961d8b69SVladimir Oltean struct ocelot *ocelot = ds->priv; 701961d8b69SVladimir Oltean 70254c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 70354c31984SVladimir Oltean return PTR_ERR(bridge_dev); 70454c31984SVladimir Oltean 70554c31984SVladimir Oltean return ocelot_lag_fdb_add(ocelot, lag.dev, addr, vid, bridge_dev); 706961d8b69SVladimir Oltean } 707961d8b69SVladimir Oltean 708961d8b69SVladimir Oltean static int felix_lag_fdb_del(struct dsa_switch *ds, struct dsa_lag lag, 709c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 710c2693363SVladimir Oltean struct dsa_db db) 711961d8b69SVladimir Oltean { 71254c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 713961d8b69SVladimir Oltean struct ocelot *ocelot = ds->priv; 714961d8b69SVladimir Oltean 71554c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 71654c31984SVladimir Oltean return PTR_ERR(bridge_dev); 71754c31984SVladimir Oltean 71854c31984SVladimir Oltean return ocelot_lag_fdb_del(ocelot, lag.dev, addr, vid, bridge_dev); 719961d8b69SVladimir Oltean } 720961d8b69SVladimir Oltean 721a52b2da7SVladimir Oltean static int felix_mdb_add(struct dsa_switch *ds, int port, 722c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 723c2693363SVladimir Oltean struct dsa_db db) 724209edf95SVladimir Oltean { 72554c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 726209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 727209edf95SVladimir Oltean 72854c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 72954c31984SVladimir Oltean return PTR_ERR(bridge_dev); 73054c31984SVladimir Oltean 7317e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 7327e580490SVladimir Oltean dsa_mdb_present_in_other_db(ds, port, mdb, db)) 7337e580490SVladimir Oltean return 0; 7347e580490SVladimir Oltean 73554c31984SVladimir Oltean return ocelot_port_mdb_add(ocelot, port, mdb, bridge_dev); 736209edf95SVladimir Oltean } 737209edf95SVladimir Oltean 738209edf95SVladimir Oltean static int felix_mdb_del(struct dsa_switch *ds, int port, 739c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 740c2693363SVladimir Oltean struct dsa_db db) 741209edf95SVladimir Oltean { 74254c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 743209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 744209edf95SVladimir Oltean 74554c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 74654c31984SVladimir Oltean return PTR_ERR(bridge_dev); 74754c31984SVladimir Oltean 7487e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 7497e580490SVladimir Oltean dsa_mdb_present_in_other_db(ds, port, mdb, db)) 7507e580490SVladimir Oltean return 0; 7517e580490SVladimir Oltean 75254c31984SVladimir Oltean return ocelot_port_mdb_del(ocelot, port, mdb, bridge_dev); 753209edf95SVladimir Oltean } 754209edf95SVladimir Oltean 75556051948SVladimir Oltean static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, 75656051948SVladimir Oltean u8 state) 75756051948SVladimir Oltean { 75856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 75956051948SVladimir Oltean 76056051948SVladimir Oltean return ocelot_bridge_stp_state_set(ocelot, port, state); 76156051948SVladimir Oltean } 76256051948SVladimir Oltean 763421741eaSVladimir Oltean static int felix_pre_bridge_flags(struct dsa_switch *ds, int port, 764421741eaSVladimir Oltean struct switchdev_brport_flags val, 765421741eaSVladimir Oltean struct netlink_ext_ack *extack) 766421741eaSVladimir Oltean { 767421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 768421741eaSVladimir Oltean 769421741eaSVladimir Oltean return ocelot_port_pre_bridge_flags(ocelot, port, val); 770421741eaSVladimir Oltean } 771421741eaSVladimir Oltean 772421741eaSVladimir Oltean static int felix_bridge_flags(struct dsa_switch *ds, int port, 773421741eaSVladimir Oltean struct switchdev_brport_flags val, 774421741eaSVladimir Oltean struct netlink_ext_ack *extack) 775421741eaSVladimir Oltean { 776421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 777421741eaSVladimir Oltean 778421741eaSVladimir Oltean ocelot_port_bridge_flags(ocelot, port, val); 779421741eaSVladimir Oltean 780421741eaSVladimir Oltean return 0; 781421741eaSVladimir Oltean } 782421741eaSVladimir Oltean 78356051948SVladimir Oltean static int felix_bridge_join(struct dsa_switch *ds, int port, 78406b9cce4SVladimir Oltean struct dsa_bridge bridge, bool *tx_fwd_offload, 78506b9cce4SVladimir Oltean struct netlink_ext_ack *extack) 78656051948SVladimir Oltean { 78756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 78856051948SVladimir Oltean 78954c31984SVladimir Oltean return ocelot_port_bridge_join(ocelot, port, bridge.dev, bridge.num, 79054c31984SVladimir Oltean extack); 79156051948SVladimir Oltean } 79256051948SVladimir Oltean 79356051948SVladimir Oltean static void felix_bridge_leave(struct dsa_switch *ds, int port, 794d3eed0e5SVladimir Oltean struct dsa_bridge bridge) 79556051948SVladimir Oltean { 79656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 79756051948SVladimir Oltean 798d3eed0e5SVladimir Oltean ocelot_port_bridge_leave(ocelot, port, bridge.dev); 79956051948SVladimir Oltean } 80056051948SVladimir Oltean 8018fe6832eSVladimir Oltean static int felix_lag_join(struct dsa_switch *ds, int port, 802dedd6a00SVladimir Oltean struct dsa_lag lag, 8038fe6832eSVladimir Oltean struct netdev_lag_upper_info *info) 8048fe6832eSVladimir Oltean { 8058fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8068fe6832eSVladimir Oltean 807dedd6a00SVladimir Oltean return ocelot_port_lag_join(ocelot, port, lag.dev, info); 8088fe6832eSVladimir Oltean } 8098fe6832eSVladimir Oltean 8108fe6832eSVladimir Oltean static int felix_lag_leave(struct dsa_switch *ds, int port, 811dedd6a00SVladimir Oltean struct dsa_lag lag) 8128fe6832eSVladimir Oltean { 8138fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8148fe6832eSVladimir Oltean 815dedd6a00SVladimir Oltean ocelot_port_lag_leave(ocelot, port, lag.dev); 8168fe6832eSVladimir Oltean 8178fe6832eSVladimir Oltean return 0; 8188fe6832eSVladimir Oltean } 8198fe6832eSVladimir Oltean 8208fe6832eSVladimir Oltean static int felix_lag_change(struct dsa_switch *ds, int port) 8218fe6832eSVladimir Oltean { 8228fe6832eSVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 8238fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8248fe6832eSVladimir Oltean 8258fe6832eSVladimir Oltean ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); 8268fe6832eSVladimir Oltean 8278fe6832eSVladimir Oltean return 0; 8288fe6832eSVladimir Oltean } 8298fe6832eSVladimir Oltean 83056051948SVladimir Oltean static int felix_vlan_prepare(struct dsa_switch *ds, int port, 83101af940eSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 83201af940eSVladimir Oltean struct netlink_ext_ack *extack) 83356051948SVladimir Oltean { 8342f0402feSVladimir Oltean struct ocelot *ocelot = ds->priv; 835b7a9e0daSVladimir Oltean u16 flags = vlan->flags; 8362f0402feSVladimir Oltean 8379a720680SVladimir Oltean /* Ocelot switches copy frames as-is to the CPU, so the flags: 8389a720680SVladimir Oltean * egress-untagged or not, pvid or not, make no difference. This 8399a720680SVladimir Oltean * behavior is already better than what DSA just tries to approximate 8409a720680SVladimir Oltean * when it installs the VLAN with the same flags on the CPU port. 8419a720680SVladimir Oltean * Just accept any configuration, and don't let ocelot deny installing 8429a720680SVladimir Oltean * multiple native VLANs on the NPI port, because the switch doesn't 8439a720680SVladimir Oltean * look at the port tag settings towards the NPI interface anyway. 8449a720680SVladimir Oltean */ 8459a720680SVladimir Oltean if (port == ocelot->npi) 8469a720680SVladimir Oltean return 0; 8479a720680SVladimir Oltean 848b7a9e0daSVladimir Oltean return ocelot_vlan_prepare(ocelot, port, vlan->vid, 8492f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 85001af940eSVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED, 85101af940eSVladimir Oltean extack); 85256051948SVladimir Oltean } 85356051948SVladimir Oltean 85489153ed6SVladimir Oltean static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled, 85589153ed6SVladimir Oltean struct netlink_ext_ack *extack) 85656051948SVladimir Oltean { 85756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 85856051948SVladimir Oltean 8593b95d1b2SVladimir Oltean return ocelot_port_vlan_filtering(ocelot, port, enabled, extack); 86056051948SVladimir Oltean } 86156051948SVladimir Oltean 8621958d581SVladimir Oltean static int felix_vlan_add(struct dsa_switch *ds, int port, 86331046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 86431046a5fSVladimir Oltean struct netlink_ext_ack *extack) 86556051948SVladimir Oltean { 86656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 867183be6f9SVladimir Oltean u16 flags = vlan->flags; 8681958d581SVladimir Oltean int err; 86956051948SVladimir Oltean 87001af940eSVladimir Oltean err = felix_vlan_prepare(ds, port, vlan, extack); 8711958d581SVladimir Oltean if (err) 8721958d581SVladimir Oltean return err; 8731958d581SVladimir Oltean 8741958d581SVladimir Oltean return ocelot_vlan_add(ocelot, port, vlan->vid, 875183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 876183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 87756051948SVladimir Oltean } 87856051948SVladimir Oltean 87956051948SVladimir Oltean static int felix_vlan_del(struct dsa_switch *ds, int port, 88056051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 88156051948SVladimir Oltean { 88256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 88356051948SVladimir Oltean 884b7a9e0daSVladimir Oltean return ocelot_vlan_del(ocelot, port, vlan->vid); 88556051948SVladimir Oltean } 88656051948SVladimir Oltean 88779fda660SRussell King (Oracle) static void felix_phylink_get_caps(struct dsa_switch *ds, int port, 88879fda660SRussell King (Oracle) struct phylink_config *config) 88979fda660SRussell King (Oracle) { 89079fda660SRussell King (Oracle) struct ocelot *ocelot = ds->priv; 89179fda660SRussell King (Oracle) 892f6f04c02SRussell King (Oracle) /* This driver does not make use of the speed, duplex, pause or the 893f6f04c02SRussell King (Oracle) * advertisement in its mac_config, so it is safe to mark this driver 894f6f04c02SRussell King (Oracle) * as non-legacy. 895f6f04c02SRussell King (Oracle) */ 896f6f04c02SRussell King (Oracle) config->legacy_pre_march2020 = false; 897f6f04c02SRussell King (Oracle) 89879fda660SRussell King (Oracle) __set_bit(ocelot->ports[port]->phy_mode, 89979fda660SRussell King (Oracle) config->supported_interfaces); 90079fda660SRussell King (Oracle) } 90179fda660SRussell King (Oracle) 902bdeced75SVladimir Oltean static void felix_phylink_validate(struct dsa_switch *ds, int port, 903bdeced75SVladimir Oltean unsigned long *supported, 904bdeced75SVladimir Oltean struct phylink_link_state *state) 905bdeced75SVladimir Oltean { 906bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 907375e1314SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 908bdeced75SVladimir Oltean 909375e1314SVladimir Oltean if (felix->info->phylink_validate) 910375e1314SVladimir Oltean felix->info->phylink_validate(ocelot, port, supported, state); 911bdeced75SVladimir Oltean } 912bdeced75SVladimir Oltean 913864ba485SRussell King (Oracle) static struct phylink_pcs *felix_phylink_mac_select_pcs(struct dsa_switch *ds, 914864ba485SRussell King (Oracle) int port, 915864ba485SRussell King (Oracle) phy_interface_t iface) 916bdeced75SVladimir Oltean { 917bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 918bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 919864ba485SRussell King (Oracle) struct phylink_pcs *pcs = NULL; 920bdeced75SVladimir Oltean 92149af6a76SColin Foster if (felix->pcs && felix->pcs[port]) 922864ba485SRussell King (Oracle) pcs = felix->pcs[port]; 923864ba485SRussell King (Oracle) 924864ba485SRussell King (Oracle) return pcs; 925bdeced75SVladimir Oltean } 926bdeced75SVladimir Oltean 927bdeced75SVladimir Oltean static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, 928bdeced75SVladimir Oltean unsigned int link_an_mode, 929bdeced75SVladimir Oltean phy_interface_t interface) 930bdeced75SVladimir Oltean { 931bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 932bdeced75SVladimir Oltean 933e6e12df6SVladimir Oltean ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface, 934e6e12df6SVladimir Oltean FELIX_MAC_QUIRKS); 935bdeced75SVladimir Oltean } 936bdeced75SVladimir Oltean 937bdeced75SVladimir Oltean static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, 938bdeced75SVladimir Oltean unsigned int link_an_mode, 939bdeced75SVladimir Oltean phy_interface_t interface, 9405b502a7bSRussell King struct phy_device *phydev, 9415b502a7bSRussell King int speed, int duplex, 9425b502a7bSRussell King bool tx_pause, bool rx_pause) 943bdeced75SVladimir Oltean { 944bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 9457e14a2dcSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 946bdeced75SVladimir Oltean 947e6e12df6SVladimir Oltean ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode, 948e6e12df6SVladimir Oltean interface, speed, duplex, tx_pause, rx_pause, 949e6e12df6SVladimir Oltean FELIX_MAC_QUIRKS); 9507e14a2dcSVladimir Oltean 9517e14a2dcSVladimir Oltean if (felix->info->port_sched_speed_set) 9527e14a2dcSVladimir Oltean felix->info->port_sched_speed_set(ocelot, port, speed); 953bdeced75SVladimir Oltean } 954bdeced75SVladimir Oltean 955bd2b3161SXiaoliang Yang static void felix_port_qos_map_init(struct ocelot *ocelot, int port) 956bd2b3161SXiaoliang Yang { 957bd2b3161SXiaoliang Yang int i; 958bd2b3161SXiaoliang Yang 959bd2b3161SXiaoliang Yang ocelot_rmw_gix(ocelot, 960bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 961bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 962bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG, 963bd2b3161SXiaoliang Yang port); 964bd2b3161SXiaoliang Yang 96570d39a6eSVladimir Oltean for (i = 0; i < OCELOT_NUM_TC * 2; i++) { 966bd2b3161SXiaoliang Yang ocelot_rmw_ix(ocelot, 967bd2b3161SXiaoliang Yang (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) | 968bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i), 969bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL | 970bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M, 971bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP, 972bd2b3161SXiaoliang Yang port, i); 973bd2b3161SXiaoliang Yang } 974bd2b3161SXiaoliang Yang } 975bd2b3161SXiaoliang Yang 97656051948SVladimir Oltean static void felix_get_strings(struct dsa_switch *ds, int port, 97756051948SVladimir Oltean u32 stringset, u8 *data) 97856051948SVladimir Oltean { 97956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 98056051948SVladimir Oltean 98156051948SVladimir Oltean return ocelot_get_strings(ocelot, port, stringset, data); 98256051948SVladimir Oltean } 98356051948SVladimir Oltean 98456051948SVladimir Oltean static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) 98556051948SVladimir Oltean { 98656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 98756051948SVladimir Oltean 98856051948SVladimir Oltean ocelot_get_ethtool_stats(ocelot, port, data); 98956051948SVladimir Oltean } 99056051948SVladimir Oltean 99156051948SVladimir Oltean static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) 99256051948SVladimir Oltean { 99356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 99456051948SVladimir Oltean 99556051948SVladimir Oltean return ocelot_get_sset_count(ocelot, port, sset); 99656051948SVladimir Oltean } 99756051948SVladimir Oltean 99856051948SVladimir Oltean static int felix_get_ts_info(struct dsa_switch *ds, int port, 99956051948SVladimir Oltean struct ethtool_ts_info *info) 100056051948SVladimir Oltean { 100156051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 100256051948SVladimir Oltean 100356051948SVladimir Oltean return ocelot_get_ts_info(ocelot, port, info); 100456051948SVladimir Oltean } 100556051948SVladimir Oltean 1006acf242fcSColin Foster static const u32 felix_phy_match_table[PHY_INTERFACE_MODE_MAX] = { 1007acf242fcSColin Foster [PHY_INTERFACE_MODE_INTERNAL] = OCELOT_PORT_MODE_INTERNAL, 1008acf242fcSColin Foster [PHY_INTERFACE_MODE_SGMII] = OCELOT_PORT_MODE_SGMII, 1009acf242fcSColin Foster [PHY_INTERFACE_MODE_QSGMII] = OCELOT_PORT_MODE_QSGMII, 1010acf242fcSColin Foster [PHY_INTERFACE_MODE_USXGMII] = OCELOT_PORT_MODE_USXGMII, 1011*11ecf341SVladimir Oltean [PHY_INTERFACE_MODE_1000BASEX] = OCELOT_PORT_MODE_1000BASEX, 1012acf242fcSColin Foster [PHY_INTERFACE_MODE_2500BASEX] = OCELOT_PORT_MODE_2500BASEX, 1013acf242fcSColin Foster }; 1014acf242fcSColin Foster 1015acf242fcSColin Foster static int felix_validate_phy_mode(struct felix *felix, int port, 1016acf242fcSColin Foster phy_interface_t phy_mode) 1017acf242fcSColin Foster { 1018acf242fcSColin Foster u32 modes = felix->info->port_modes[port]; 1019acf242fcSColin Foster 1020acf242fcSColin Foster if (felix_phy_match_table[phy_mode] & modes) 1021acf242fcSColin Foster return 0; 1022acf242fcSColin Foster return -EOPNOTSUPP; 1023acf242fcSColin Foster } 1024acf242fcSColin Foster 1025bdeced75SVladimir Oltean static int felix_parse_ports_node(struct felix *felix, 1026bdeced75SVladimir Oltean struct device_node *ports_node, 1027bdeced75SVladimir Oltean phy_interface_t *port_phy_modes) 1028bdeced75SVladimir Oltean { 1029bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 1030bdeced75SVladimir Oltean struct device_node *child; 1031bdeced75SVladimir Oltean 103237fe45adSVladimir Oltean for_each_available_child_of_node(ports_node, child) { 1033bdeced75SVladimir Oltean phy_interface_t phy_mode; 1034bdeced75SVladimir Oltean u32 port; 1035bdeced75SVladimir Oltean int err; 1036bdeced75SVladimir Oltean 1037bdeced75SVladimir Oltean /* Get switch port number from DT */ 1038bdeced75SVladimir Oltean if (of_property_read_u32(child, "reg", &port) < 0) { 1039bdeced75SVladimir Oltean dev_err(dev, "Port number not defined in device tree " 1040bdeced75SVladimir Oltean "(property \"reg\")\n"); 1041bdeced75SVladimir Oltean of_node_put(child); 1042bdeced75SVladimir Oltean return -ENODEV; 1043bdeced75SVladimir Oltean } 1044bdeced75SVladimir Oltean 1045bdeced75SVladimir Oltean /* Get PHY mode from DT */ 1046bdeced75SVladimir Oltean err = of_get_phy_mode(child, &phy_mode); 1047bdeced75SVladimir Oltean if (err) { 1048bdeced75SVladimir Oltean dev_err(dev, "Failed to read phy-mode or " 1049bdeced75SVladimir Oltean "phy-interface-type property for port %d\n", 1050bdeced75SVladimir Oltean port); 1051bdeced75SVladimir Oltean of_node_put(child); 1052bdeced75SVladimir Oltean return -ENODEV; 1053bdeced75SVladimir Oltean } 1054bdeced75SVladimir Oltean 1055acf242fcSColin Foster err = felix_validate_phy_mode(felix, port, phy_mode); 1056bdeced75SVladimir Oltean if (err < 0) { 1057bdeced75SVladimir Oltean dev_err(dev, "Unsupported PHY mode %s on port %d\n", 1058bdeced75SVladimir Oltean phy_modes(phy_mode), port); 105959ebb430SSumera Priyadarsini of_node_put(child); 1060bdeced75SVladimir Oltean return err; 1061bdeced75SVladimir Oltean } 1062bdeced75SVladimir Oltean 1063bdeced75SVladimir Oltean port_phy_modes[port] = phy_mode; 1064bdeced75SVladimir Oltean } 1065bdeced75SVladimir Oltean 1066bdeced75SVladimir Oltean return 0; 1067bdeced75SVladimir Oltean } 1068bdeced75SVladimir Oltean 1069bdeced75SVladimir Oltean static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes) 1070bdeced75SVladimir Oltean { 1071bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 1072bdeced75SVladimir Oltean struct device_node *switch_node; 1073bdeced75SVladimir Oltean struct device_node *ports_node; 1074bdeced75SVladimir Oltean int err; 1075bdeced75SVladimir Oltean 1076bdeced75SVladimir Oltean switch_node = dev->of_node; 1077bdeced75SVladimir Oltean 1078bdeced75SVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ports"); 1079abecbfcdSVladimir Oltean if (!ports_node) 1080abecbfcdSVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ethernet-ports"); 1081bdeced75SVladimir Oltean if (!ports_node) { 1082abecbfcdSVladimir Oltean dev_err(dev, "Incorrect bindings: absent \"ports\" or \"ethernet-ports\" node\n"); 1083bdeced75SVladimir Oltean return -ENODEV; 1084bdeced75SVladimir Oltean } 1085bdeced75SVladimir Oltean 1086bdeced75SVladimir Oltean err = felix_parse_ports_node(felix, ports_node, port_phy_modes); 1087bdeced75SVladimir Oltean of_node_put(ports_node); 1088bdeced75SVladimir Oltean 1089bdeced75SVladimir Oltean return err; 1090bdeced75SVladimir Oltean } 1091bdeced75SVladimir Oltean 109256051948SVladimir Oltean static int felix_init_structs(struct felix *felix, int num_phys_ports) 109356051948SVladimir Oltean { 109456051948SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 1095bdeced75SVladimir Oltean phy_interface_t *port_phy_modes; 1096b4024c9eSClaudiu Manoil struct resource res; 109756051948SVladimir Oltean int port, i, err; 109856051948SVladimir Oltean 109956051948SVladimir Oltean ocelot->num_phys_ports = num_phys_ports; 110056051948SVladimir Oltean ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, 110156051948SVladimir Oltean sizeof(struct ocelot_port *), GFP_KERNEL); 110256051948SVladimir Oltean if (!ocelot->ports) 110356051948SVladimir Oltean return -ENOMEM; 110456051948SVladimir Oltean 110556051948SVladimir Oltean ocelot->map = felix->info->map; 110656051948SVladimir Oltean ocelot->stats_layout = felix->info->stats_layout; 110721ce7f3eSVladimir Oltean ocelot->num_mact_rows = felix->info->num_mact_rows; 110807d985eeSVladimir Oltean ocelot->vcap = felix->info->vcap; 110977043c37SXiaoliang Yang ocelot->vcap_pol.base = felix->info->vcap_pol_base; 111077043c37SXiaoliang Yang ocelot->vcap_pol.max = felix->info->vcap_pol_max; 111177043c37SXiaoliang Yang ocelot->vcap_pol.base2 = felix->info->vcap_pol_base2; 111277043c37SXiaoliang Yang ocelot->vcap_pol.max2 = felix->info->vcap_pol_max2; 111356051948SVladimir Oltean ocelot->ops = felix->info->ops; 1114cacea62fSVladimir Oltean ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT; 1115cacea62fSVladimir Oltean ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT; 1116f59fd9caSVladimir Oltean ocelot->devlink = felix->ds->devlink; 111756051948SVladimir Oltean 1118bdeced75SVladimir Oltean port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t), 1119bdeced75SVladimir Oltean GFP_KERNEL); 1120bdeced75SVladimir Oltean if (!port_phy_modes) 1121bdeced75SVladimir Oltean return -ENOMEM; 1122bdeced75SVladimir Oltean 1123bdeced75SVladimir Oltean err = felix_parse_dt(felix, port_phy_modes); 1124bdeced75SVladimir Oltean if (err) { 1125bdeced75SVladimir Oltean kfree(port_phy_modes); 1126bdeced75SVladimir Oltean return err; 1127bdeced75SVladimir Oltean } 1128bdeced75SVladimir Oltean 112956051948SVladimir Oltean for (i = 0; i < TARGET_MAX; i++) { 113056051948SVladimir Oltean struct regmap *target; 113156051948SVladimir Oltean 113256051948SVladimir Oltean if (!felix->info->target_io_res[i].name) 113356051948SVladimir Oltean continue; 113456051948SVladimir Oltean 1135b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->target_io_res[i], sizeof(res)); 1136b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1137375e1314SVladimir Oltean res.start += felix->switch_base; 1138375e1314SVladimir Oltean res.end += felix->switch_base; 113956051948SVladimir Oltean 1140242bd0c1SColin Foster target = felix->info->init_regmap(ocelot, &res); 114156051948SVladimir Oltean if (IS_ERR(target)) { 114256051948SVladimir Oltean dev_err(ocelot->dev, 114356051948SVladimir Oltean "Failed to map device memory space\n"); 1144bdeced75SVladimir Oltean kfree(port_phy_modes); 114556051948SVladimir Oltean return PTR_ERR(target); 114656051948SVladimir Oltean } 114756051948SVladimir Oltean 114856051948SVladimir Oltean ocelot->targets[i] = target; 114956051948SVladimir Oltean } 115056051948SVladimir Oltean 115156051948SVladimir Oltean err = ocelot_regfields_init(ocelot, felix->info->regfields); 115256051948SVladimir Oltean if (err) { 115356051948SVladimir Oltean dev_err(ocelot->dev, "failed to init reg fields map\n"); 1154bdeced75SVladimir Oltean kfree(port_phy_modes); 115556051948SVladimir Oltean return err; 115656051948SVladimir Oltean } 115756051948SVladimir Oltean 115856051948SVladimir Oltean for (port = 0; port < num_phys_ports; port++) { 115956051948SVladimir Oltean struct ocelot_port *ocelot_port; 116091c724cfSVladimir Oltean struct regmap *target; 116156051948SVladimir Oltean 116256051948SVladimir Oltean ocelot_port = devm_kzalloc(ocelot->dev, 116356051948SVladimir Oltean sizeof(struct ocelot_port), 116456051948SVladimir Oltean GFP_KERNEL); 116556051948SVladimir Oltean if (!ocelot_port) { 116656051948SVladimir Oltean dev_err(ocelot->dev, 116756051948SVladimir Oltean "failed to allocate port memory\n"); 1168bdeced75SVladimir Oltean kfree(port_phy_modes); 116956051948SVladimir Oltean return -ENOMEM; 117056051948SVladimir Oltean } 117156051948SVladimir Oltean 1172b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->port_io_res[port], sizeof(res)); 1173b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1174375e1314SVladimir Oltean res.start += felix->switch_base; 1175375e1314SVladimir Oltean res.end += felix->switch_base; 117656051948SVladimir Oltean 1177242bd0c1SColin Foster target = felix->info->init_regmap(ocelot, &res); 117891c724cfSVladimir Oltean if (IS_ERR(target)) { 117956051948SVladimir Oltean dev_err(ocelot->dev, 118091c724cfSVladimir Oltean "Failed to map memory space for port %d\n", 118191c724cfSVladimir Oltean port); 1182bdeced75SVladimir Oltean kfree(port_phy_modes); 118391c724cfSVladimir Oltean return PTR_ERR(target); 118456051948SVladimir Oltean } 118556051948SVladimir Oltean 1186bdeced75SVladimir Oltean ocelot_port->phy_mode = port_phy_modes[port]; 118756051948SVladimir Oltean ocelot_port->ocelot = ocelot; 118891c724cfSVladimir Oltean ocelot_port->target = target; 118956051948SVladimir Oltean ocelot->ports[port] = ocelot_port; 119056051948SVladimir Oltean } 119156051948SVladimir Oltean 1192bdeced75SVladimir Oltean kfree(port_phy_modes); 1193bdeced75SVladimir Oltean 1194bdeced75SVladimir Oltean if (felix->info->mdio_bus_alloc) { 1195bdeced75SVladimir Oltean err = felix->info->mdio_bus_alloc(ocelot); 1196bdeced75SVladimir Oltean if (err < 0) 1197bdeced75SVladimir Oltean return err; 1198bdeced75SVladimir Oltean } 1199bdeced75SVladimir Oltean 120056051948SVladimir Oltean return 0; 120156051948SVladimir Oltean } 120256051948SVladimir Oltean 12031328a883SVladimir Oltean static void ocelot_port_purge_txtstamp_skb(struct ocelot *ocelot, int port, 12041328a883SVladimir Oltean struct sk_buff *skb) 12051328a883SVladimir Oltean { 12061328a883SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 12071328a883SVladimir Oltean struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone; 12081328a883SVladimir Oltean struct sk_buff *skb_match = NULL, *skb_tmp; 12091328a883SVladimir Oltean unsigned long flags; 12101328a883SVladimir Oltean 12111328a883SVladimir Oltean if (!clone) 12121328a883SVladimir Oltean return; 12131328a883SVladimir Oltean 12141328a883SVladimir Oltean spin_lock_irqsave(&ocelot_port->tx_skbs.lock, flags); 12151328a883SVladimir Oltean 12161328a883SVladimir Oltean skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) { 12171328a883SVladimir Oltean if (skb != clone) 12181328a883SVladimir Oltean continue; 12191328a883SVladimir Oltean __skb_unlink(skb, &ocelot_port->tx_skbs); 12201328a883SVladimir Oltean skb_match = skb; 12211328a883SVladimir Oltean break; 12221328a883SVladimir Oltean } 12231328a883SVladimir Oltean 12241328a883SVladimir Oltean spin_unlock_irqrestore(&ocelot_port->tx_skbs.lock, flags); 12251328a883SVladimir Oltean 12261328a883SVladimir Oltean WARN_ONCE(!skb_match, 12271328a883SVladimir Oltean "Could not find skb clone in TX timestamping list\n"); 12281328a883SVladimir Oltean } 12291328a883SVladimir Oltean 123049f885b2SVladimir Oltean #define work_to_xmit_work(w) \ 123149f885b2SVladimir Oltean container_of((w), struct felix_deferred_xmit_work, work) 123249f885b2SVladimir Oltean 123349f885b2SVladimir Oltean static void felix_port_deferred_xmit(struct kthread_work *work) 123449f885b2SVladimir Oltean { 123549f885b2SVladimir Oltean struct felix_deferred_xmit_work *xmit_work = work_to_xmit_work(work); 123649f885b2SVladimir Oltean struct dsa_switch *ds = xmit_work->dp->ds; 123749f885b2SVladimir Oltean struct sk_buff *skb = xmit_work->skb; 123849f885b2SVladimir Oltean u32 rew_op = ocelot_ptp_rew_op(skb); 123949f885b2SVladimir Oltean struct ocelot *ocelot = ds->priv; 124049f885b2SVladimir Oltean int port = xmit_work->dp->index; 124149f885b2SVladimir Oltean int retries = 10; 124249f885b2SVladimir Oltean 124349f885b2SVladimir Oltean do { 124449f885b2SVladimir Oltean if (ocelot_can_inject(ocelot, 0)) 124549f885b2SVladimir Oltean break; 124649f885b2SVladimir Oltean 124749f885b2SVladimir Oltean cpu_relax(); 124849f885b2SVladimir Oltean } while (--retries); 124949f885b2SVladimir Oltean 125049f885b2SVladimir Oltean if (!retries) { 125149f885b2SVladimir Oltean dev_err(ocelot->dev, "port %d failed to inject skb\n", 125249f885b2SVladimir Oltean port); 12531328a883SVladimir Oltean ocelot_port_purge_txtstamp_skb(ocelot, port, skb); 125449f885b2SVladimir Oltean kfree_skb(skb); 125549f885b2SVladimir Oltean return; 125649f885b2SVladimir Oltean } 125749f885b2SVladimir Oltean 125849f885b2SVladimir Oltean ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb); 125949f885b2SVladimir Oltean 126049f885b2SVladimir Oltean consume_skb(skb); 126149f885b2SVladimir Oltean kfree(xmit_work); 126249f885b2SVladimir Oltean } 126349f885b2SVladimir Oltean 126435d97680SVladimir Oltean static int felix_connect_tag_protocol(struct dsa_switch *ds, 126535d97680SVladimir Oltean enum dsa_tag_protocol proto) 126649f885b2SVladimir Oltean { 126735d97680SVladimir Oltean struct ocelot_8021q_tagger_data *tagger_data; 126849f885b2SVladimir Oltean 126935d97680SVladimir Oltean switch (proto) { 127035d97680SVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 127135d97680SVladimir Oltean tagger_data = ocelot_8021q_tagger_data(ds); 127235d97680SVladimir Oltean tagger_data->xmit_work_fn = felix_port_deferred_xmit; 127349f885b2SVladimir Oltean return 0; 127435d97680SVladimir Oltean case DSA_TAG_PROTO_OCELOT: 127535d97680SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 127649f885b2SVladimir Oltean return 0; 127735d97680SVladimir Oltean default: 127835d97680SVladimir Oltean return -EPROTONOSUPPORT; 127949f885b2SVladimir Oltean } 128049f885b2SVladimir Oltean } 128149f885b2SVladimir Oltean 128256051948SVladimir Oltean /* Hardware initialization done here so that we can allocate structures with 128356051948SVladimir Oltean * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing 128456051948SVladimir Oltean * us to allocate structures twice (leak memory) and map PCI memory twice 128556051948SVladimir Oltean * (which will not work). 128656051948SVladimir Oltean */ 128756051948SVladimir Oltean static int felix_setup(struct dsa_switch *ds) 128856051948SVladimir Oltean { 128956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 129056051948SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1291f2e2662cSVladimir Oltean unsigned long cpu_flood; 12922960bb14SVladimir Oltean struct dsa_port *dp; 12932960bb14SVladimir Oltean int err; 129456051948SVladimir Oltean 129556051948SVladimir Oltean err = felix_init_structs(felix, ds->num_ports); 129656051948SVladimir Oltean if (err) 129756051948SVladimir Oltean return err; 129856051948SVladimir Oltean 1299d1cc0e93SVladimir Oltean err = ocelot_init(ocelot); 1300d1cc0e93SVladimir Oltean if (err) 13016b73b7c9SVladimir Oltean goto out_mdiobus_free; 1302d1cc0e93SVladimir Oltean 13032b49d128SYangbo Lu if (ocelot->ptp) { 13042ac7c6c5SVladimir Oltean err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); 13052b49d128SYangbo Lu if (err) { 13062b49d128SYangbo Lu dev_err(ocelot->dev, 13072b49d128SYangbo Lu "Timestamp initialization failed\n"); 13082b49d128SYangbo Lu ocelot->ptp = 0; 13092b49d128SYangbo Lu } 13102b49d128SYangbo Lu } 131156051948SVladimir Oltean 13122960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 13132960bb14SVladimir Oltean ocelot_init_port(ocelot, dp->index); 1314bd2b3161SXiaoliang Yang 1315bd2b3161SXiaoliang Yang /* Set the default QoS Classification based on PCP and DEI 1316bd2b3161SXiaoliang Yang * bits of vlan tag. 1317bd2b3161SXiaoliang Yang */ 13182960bb14SVladimir Oltean felix_port_qos_map_init(ocelot, dp->index); 131956051948SVladimir Oltean } 132056051948SVladimir Oltean 1321f59fd9caSVladimir Oltean err = ocelot_devlink_sb_register(ocelot); 1322f59fd9caSVladimir Oltean if (err) 13236b73b7c9SVladimir Oltean goto out_deinit_ports; 1324f59fd9caSVladimir Oltean 13252960bb14SVladimir Oltean dsa_switch_for_each_cpu_port(dp, ds) { 1326adb3dccfSVladimir Oltean /* The initial tag protocol is NPI which always returns 0, so 1327adb3dccfSVladimir Oltean * there's no real point in checking for errors. 13281cf3299bSVladimir Oltean */ 1329c69f40acSVladimir Oltean felix_set_tag_protocol(ds, dp->index, felix->tag_proto); 1330f2e2662cSVladimir Oltean 1331f2e2662cSVladimir Oltean /* Start off with flooding disabled towards the NPI port 1332f2e2662cSVladimir Oltean * (actually CPU port module). 1333f2e2662cSVladimir Oltean */ 1334f2e2662cSVladimir Oltean cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)); 1335f2e2662cSVladimir Oltean ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_UC); 1336f2e2662cSVladimir Oltean ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC); 1337f2e2662cSVladimir Oltean 13388d5f7954SVladimir Oltean break; 1339adb3dccfSVladimir Oltean } 13401cf3299bSVladimir Oltean 13410b912fc9SVladimir Oltean ds->mtu_enforcement_ingress = true; 1342c54913c1SVladimir Oltean ds->assisted_learning_on_cpu_port = true; 134354c31984SVladimir Oltean ds->fdb_isolation = true; 134454c31984SVladimir Oltean ds->max_num_bridges = ds->num_ports; 1345bdeced75SVladimir Oltean 134656051948SVladimir Oltean return 0; 13476b73b7c9SVladimir Oltean 13486b73b7c9SVladimir Oltean out_deinit_ports: 13492960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) 13502960bb14SVladimir Oltean ocelot_deinit_port(ocelot, dp->index); 13516b73b7c9SVladimir Oltean 13526b73b7c9SVladimir Oltean ocelot_deinit_timestamp(ocelot); 13536b73b7c9SVladimir Oltean ocelot_deinit(ocelot); 13546b73b7c9SVladimir Oltean 13556b73b7c9SVladimir Oltean out_mdiobus_free: 13566b73b7c9SVladimir Oltean if (felix->info->mdio_bus_free) 13576b73b7c9SVladimir Oltean felix->info->mdio_bus_free(ocelot); 13586b73b7c9SVladimir Oltean 13596b73b7c9SVladimir Oltean return err; 136056051948SVladimir Oltean } 136156051948SVladimir Oltean 136256051948SVladimir Oltean static void felix_teardown(struct dsa_switch *ds) 136356051948SVladimir Oltean { 136456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 1365bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 13662960bb14SVladimir Oltean struct dsa_port *dp; 1367bdeced75SVladimir Oltean 13682960bb14SVladimir Oltean dsa_switch_for_each_cpu_port(dp, ds) { 13692960bb14SVladimir Oltean felix_del_tag_protocol(ds, dp->index, felix->tag_proto); 13708d5f7954SVladimir Oltean break; 1371adb3dccfSVladimir Oltean } 1372adb3dccfSVladimir Oltean 13732960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) 13742960bb14SVladimir Oltean ocelot_deinit_port(ocelot, dp->index); 1375d19741b0SVladimir Oltean 137649f885b2SVladimir Oltean ocelot_devlink_sb_unregister(ocelot); 137749f885b2SVladimir Oltean ocelot_deinit_timestamp(ocelot); 137849f885b2SVladimir Oltean ocelot_deinit(ocelot); 137949f885b2SVladimir Oltean 1380d19741b0SVladimir Oltean if (felix->info->mdio_bus_free) 1381d19741b0SVladimir Oltean felix->info->mdio_bus_free(ocelot); 138256051948SVladimir Oltean } 138356051948SVladimir Oltean 1384c0bcf537SYangbo Lu static int felix_hwtstamp_get(struct dsa_switch *ds, int port, 1385c0bcf537SYangbo Lu struct ifreq *ifr) 1386c0bcf537SYangbo Lu { 1387c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1388c0bcf537SYangbo Lu 1389c0bcf537SYangbo Lu return ocelot_hwstamp_get(ocelot, port, ifr); 1390c0bcf537SYangbo Lu } 1391c0bcf537SYangbo Lu 1392c0bcf537SYangbo Lu static int felix_hwtstamp_set(struct dsa_switch *ds, int port, 1393c0bcf537SYangbo Lu struct ifreq *ifr) 1394c0bcf537SYangbo Lu { 1395c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 139699348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 139799348004SVladimir Oltean bool using_tag_8021q; 139899348004SVladimir Oltean int err; 1399c0bcf537SYangbo Lu 140099348004SVladimir Oltean err = ocelot_hwstamp_set(ocelot, port, ifr); 140199348004SVladimir Oltean if (err) 140299348004SVladimir Oltean return err; 140399348004SVladimir Oltean 140499348004SVladimir Oltean using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; 140599348004SVladimir Oltean 140699348004SVladimir Oltean return felix_update_trapping_destinations(ds, using_tag_8021q); 1407c0bcf537SYangbo Lu } 1408c0bcf537SYangbo Lu 1409d219b4b6SVladimir Oltean static bool felix_check_xtr_pkt(struct ocelot *ocelot) 14100a6f17c6SVladimir Oltean { 14110a6f17c6SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1412dbd03285SVladimir Oltean int err = 0, grp = 0; 14130a6f17c6SVladimir Oltean 14140a6f17c6SVladimir Oltean if (felix->tag_proto != DSA_TAG_PROTO_OCELOT_8021Q) 14150a6f17c6SVladimir Oltean return false; 14160a6f17c6SVladimir Oltean 14170a6f17c6SVladimir Oltean if (!felix->info->quirk_no_xtr_irq) 14180a6f17c6SVladimir Oltean return false; 14190a6f17c6SVladimir Oltean 14200a6f17c6SVladimir Oltean while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp)) { 14210a6f17c6SVladimir Oltean struct sk_buff *skb; 14220a6f17c6SVladimir Oltean unsigned int type; 14230a6f17c6SVladimir Oltean 14240a6f17c6SVladimir Oltean err = ocelot_xtr_poll_frame(ocelot, grp, &skb); 14250a6f17c6SVladimir Oltean if (err) 14260a6f17c6SVladimir Oltean goto out; 14270a6f17c6SVladimir Oltean 14280a6f17c6SVladimir Oltean /* We trap to the CPU port module all PTP frames, but 14290a6f17c6SVladimir Oltean * felix_rxtstamp() only gets called for event frames. 14300a6f17c6SVladimir Oltean * So we need to avoid sending duplicate general 14310a6f17c6SVladimir Oltean * message frames by running a second BPF classifier 14320a6f17c6SVladimir Oltean * here and dropping those. 14330a6f17c6SVladimir Oltean */ 14340a6f17c6SVladimir Oltean __skb_push(skb, ETH_HLEN); 14350a6f17c6SVladimir Oltean 14360a6f17c6SVladimir Oltean type = ptp_classify_raw(skb); 14370a6f17c6SVladimir Oltean 14380a6f17c6SVladimir Oltean __skb_pull(skb, ETH_HLEN); 14390a6f17c6SVladimir Oltean 14400a6f17c6SVladimir Oltean if (type == PTP_CLASS_NONE) { 14410a6f17c6SVladimir Oltean kfree_skb(skb); 14420a6f17c6SVladimir Oltean continue; 14430a6f17c6SVladimir Oltean } 14440a6f17c6SVladimir Oltean 14450a6f17c6SVladimir Oltean netif_rx(skb); 14460a6f17c6SVladimir Oltean } 14470a6f17c6SVladimir Oltean 14480a6f17c6SVladimir Oltean out: 14495d3bb7ddSVladimir Oltean if (err < 0) { 14505d3bb7ddSVladimir Oltean dev_err_ratelimited(ocelot->dev, 14515d3bb7ddSVladimir Oltean "Error during packet extraction: %pe\n", 14525d3bb7ddSVladimir Oltean ERR_PTR(err)); 14530a6f17c6SVladimir Oltean ocelot_drain_cpu_queue(ocelot, 0); 14545d3bb7ddSVladimir Oltean } 14550a6f17c6SVladimir Oltean 14560a6f17c6SVladimir Oltean return true; 14570a6f17c6SVladimir Oltean } 14580a6f17c6SVladimir Oltean 1459c0bcf537SYangbo Lu static bool felix_rxtstamp(struct dsa_switch *ds, int port, 1460c0bcf537SYangbo Lu struct sk_buff *skb, unsigned int type) 1461c0bcf537SYangbo Lu { 146292f62485SVladimir Oltean u32 tstamp_lo = OCELOT_SKB_CB(skb)->tstamp_lo; 1463c0bcf537SYangbo Lu struct skb_shared_hwtstamps *shhwtstamps; 1464c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1465c0bcf537SYangbo Lu struct timespec64 ts; 146692f62485SVladimir Oltean u32 tstamp_hi; 146792f62485SVladimir Oltean u64 tstamp; 1468c0bcf537SYangbo Lu 14690a6f17c6SVladimir Oltean /* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb 14700a6f17c6SVladimir Oltean * for RX timestamping. Then free it, and poll for its copy through 14710a6f17c6SVladimir Oltean * MMIO in the CPU port module, and inject that into the stack from 14720a6f17c6SVladimir Oltean * ocelot_xtr_poll(). 14730a6f17c6SVladimir Oltean */ 1474d219b4b6SVladimir Oltean if (felix_check_xtr_pkt(ocelot)) { 14750a6f17c6SVladimir Oltean kfree_skb(skb); 14760a6f17c6SVladimir Oltean return true; 14770a6f17c6SVladimir Oltean } 14780a6f17c6SVladimir Oltean 1479c0bcf537SYangbo Lu ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); 1480c0bcf537SYangbo Lu tstamp = ktime_set(ts.tv_sec, ts.tv_nsec); 1481c0bcf537SYangbo Lu 1482c0bcf537SYangbo Lu tstamp_hi = tstamp >> 32; 1483c0bcf537SYangbo Lu if ((tstamp & 0xffffffff) < tstamp_lo) 1484c0bcf537SYangbo Lu tstamp_hi--; 1485c0bcf537SYangbo Lu 1486c0bcf537SYangbo Lu tstamp = ((u64)tstamp_hi << 32) | tstamp_lo; 1487c0bcf537SYangbo Lu 1488c0bcf537SYangbo Lu shhwtstamps = skb_hwtstamps(skb); 1489c0bcf537SYangbo Lu memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); 1490c0bcf537SYangbo Lu shhwtstamps->hwtstamp = tstamp; 1491c0bcf537SYangbo Lu return false; 1492c0bcf537SYangbo Lu } 1493c0bcf537SYangbo Lu 14945c5416f5SYangbo Lu static void felix_txtstamp(struct dsa_switch *ds, int port, 14955c5416f5SYangbo Lu struct sk_buff *skb) 1496c0bcf537SYangbo Lu { 1497c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1498682eaad9SYangbo Lu struct sk_buff *clone = NULL; 1499c0bcf537SYangbo Lu 1500682eaad9SYangbo Lu if (!ocelot->ptp) 15015c5416f5SYangbo Lu return; 1502c0bcf537SYangbo Lu 150352849bcfSVladimir Oltean if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) { 150452849bcfSVladimir Oltean dev_err_ratelimited(ds->dev, 150552849bcfSVladimir Oltean "port %d delivering skb without TX timestamp\n", 150652849bcfSVladimir Oltean port); 1507682eaad9SYangbo Lu return; 150852849bcfSVladimir Oltean } 1509682eaad9SYangbo Lu 1510682eaad9SYangbo Lu if (clone) 1511c4b364ceSYangbo Lu OCELOT_SKB_CB(skb)->clone = clone; 15125c5416f5SYangbo Lu } 1513c0bcf537SYangbo Lu 15140b912fc9SVladimir Oltean static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 15150b912fc9SVladimir Oltean { 15160b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 15170b912fc9SVladimir Oltean 15180b912fc9SVladimir Oltean ocelot_port_set_maxlen(ocelot, port, new_mtu); 15190b912fc9SVladimir Oltean 15200b912fc9SVladimir Oltean return 0; 15210b912fc9SVladimir Oltean } 15220b912fc9SVladimir Oltean 15230b912fc9SVladimir Oltean static int felix_get_max_mtu(struct dsa_switch *ds, int port) 15240b912fc9SVladimir Oltean { 15250b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 15260b912fc9SVladimir Oltean 15270b912fc9SVladimir Oltean return ocelot_get_max_mtu(ocelot, port); 15280b912fc9SVladimir Oltean } 15290b912fc9SVladimir Oltean 153007d985eeSVladimir Oltean static int felix_cls_flower_add(struct dsa_switch *ds, int port, 153107d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 153207d985eeSVladimir Oltean { 153307d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 153499348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 153599348004SVladimir Oltean bool using_tag_8021q; 153699348004SVladimir Oltean int err; 153707d985eeSVladimir Oltean 153899348004SVladimir Oltean err = ocelot_cls_flower_replace(ocelot, port, cls, ingress); 153999348004SVladimir Oltean if (err) 154099348004SVladimir Oltean return err; 154199348004SVladimir Oltean 154299348004SVladimir Oltean using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; 154399348004SVladimir Oltean 154499348004SVladimir Oltean return felix_update_trapping_destinations(ds, using_tag_8021q); 154507d985eeSVladimir Oltean } 154607d985eeSVladimir Oltean 154707d985eeSVladimir Oltean static int felix_cls_flower_del(struct dsa_switch *ds, int port, 154807d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 154907d985eeSVladimir Oltean { 155007d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 155107d985eeSVladimir Oltean 155207d985eeSVladimir Oltean return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); 155307d985eeSVladimir Oltean } 155407d985eeSVladimir Oltean 155507d985eeSVladimir Oltean static int felix_cls_flower_stats(struct dsa_switch *ds, int port, 155607d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 155707d985eeSVladimir Oltean { 155807d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 155907d985eeSVladimir Oltean 156007d985eeSVladimir Oltean return ocelot_cls_flower_stats(ocelot, port, cls, ingress); 156107d985eeSVladimir Oltean } 156207d985eeSVladimir Oltean 1563fc411eaaSVladimir Oltean static int felix_port_policer_add(struct dsa_switch *ds, int port, 1564fc411eaaSVladimir Oltean struct dsa_mall_policer_tc_entry *policer) 1565fc411eaaSVladimir Oltean { 1566fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1567fc411eaaSVladimir Oltean struct ocelot_policer pol = { 1568fc411eaaSVladimir Oltean .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, 15695f035af7SPo Liu .burst = policer->burst, 1570fc411eaaSVladimir Oltean }; 1571fc411eaaSVladimir Oltean 1572fc411eaaSVladimir Oltean return ocelot_port_policer_add(ocelot, port, &pol); 1573fc411eaaSVladimir Oltean } 1574fc411eaaSVladimir Oltean 1575fc411eaaSVladimir Oltean static void felix_port_policer_del(struct dsa_switch *ds, int port) 1576fc411eaaSVladimir Oltean { 1577fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1578fc411eaaSVladimir Oltean 1579fc411eaaSVladimir Oltean ocelot_port_policer_del(ocelot, port); 1580fc411eaaSVladimir Oltean } 1581fc411eaaSVladimir Oltean 15825e497497SVladimir Oltean static int felix_port_mirror_add(struct dsa_switch *ds, int port, 15835e497497SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror, 15845e497497SVladimir Oltean bool ingress, struct netlink_ext_ack *extack) 15855e497497SVladimir Oltean { 15865e497497SVladimir Oltean struct ocelot *ocelot = ds->priv; 15875e497497SVladimir Oltean 15885e497497SVladimir Oltean return ocelot_port_mirror_add(ocelot, port, mirror->to_local_port, 15895e497497SVladimir Oltean ingress, extack); 15905e497497SVladimir Oltean } 15915e497497SVladimir Oltean 15925e497497SVladimir Oltean static void felix_port_mirror_del(struct dsa_switch *ds, int port, 15935e497497SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror) 15945e497497SVladimir Oltean { 15955e497497SVladimir Oltean struct ocelot *ocelot = ds->priv; 15965e497497SVladimir Oltean 15975e497497SVladimir Oltean ocelot_port_mirror_del(ocelot, port, mirror->ingress); 15985e497497SVladimir Oltean } 15995e497497SVladimir Oltean 1600de143c0eSXiaoliang Yang static int felix_port_setup_tc(struct dsa_switch *ds, int port, 1601de143c0eSXiaoliang Yang enum tc_setup_type type, 1602de143c0eSXiaoliang Yang void *type_data) 1603de143c0eSXiaoliang Yang { 1604de143c0eSXiaoliang Yang struct ocelot *ocelot = ds->priv; 1605de143c0eSXiaoliang Yang struct felix *felix = ocelot_to_felix(ocelot); 1606de143c0eSXiaoliang Yang 1607de143c0eSXiaoliang Yang if (felix->info->port_setup_tc) 1608de143c0eSXiaoliang Yang return felix->info->port_setup_tc(ds, port, type, type_data); 1609de143c0eSXiaoliang Yang else 1610de143c0eSXiaoliang Yang return -EOPNOTSUPP; 1611de143c0eSXiaoliang Yang } 1612de143c0eSXiaoliang Yang 1613f59fd9caSVladimir Oltean static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index, 1614f59fd9caSVladimir Oltean u16 pool_index, 1615f59fd9caSVladimir Oltean struct devlink_sb_pool_info *pool_info) 1616f59fd9caSVladimir Oltean { 1617f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1618f59fd9caSVladimir Oltean 1619f59fd9caSVladimir Oltean return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info); 1620f59fd9caSVladimir Oltean } 1621f59fd9caSVladimir Oltean 1622f59fd9caSVladimir Oltean static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index, 1623f59fd9caSVladimir Oltean u16 pool_index, u32 size, 1624f59fd9caSVladimir Oltean enum devlink_sb_threshold_type threshold_type, 1625f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1626f59fd9caSVladimir Oltean { 1627f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1628f59fd9caSVladimir Oltean 1629f59fd9caSVladimir Oltean return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size, 1630f59fd9caSVladimir Oltean threshold_type, extack); 1631f59fd9caSVladimir Oltean } 1632f59fd9caSVladimir Oltean 1633f59fd9caSVladimir Oltean static int felix_sb_port_pool_get(struct dsa_switch *ds, int port, 1634f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1635f59fd9caSVladimir Oltean u32 *p_threshold) 1636f59fd9caSVladimir Oltean { 1637f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1638f59fd9caSVladimir Oltean 1639f59fd9caSVladimir Oltean return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index, 1640f59fd9caSVladimir Oltean p_threshold); 1641f59fd9caSVladimir Oltean } 1642f59fd9caSVladimir Oltean 1643f59fd9caSVladimir Oltean static int felix_sb_port_pool_set(struct dsa_switch *ds, int port, 1644f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1645f59fd9caSVladimir Oltean u32 threshold, struct netlink_ext_ack *extack) 1646f59fd9caSVladimir Oltean { 1647f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1648f59fd9caSVladimir Oltean 1649f59fd9caSVladimir Oltean return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index, 1650f59fd9caSVladimir Oltean threshold, extack); 1651f59fd9caSVladimir Oltean } 1652f59fd9caSVladimir Oltean 1653f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port, 1654f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1655f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1656f59fd9caSVladimir Oltean u16 *p_pool_index, u32 *p_threshold) 1657f59fd9caSVladimir Oltean { 1658f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1659f59fd9caSVladimir Oltean 1660f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index, 1661f59fd9caSVladimir Oltean pool_type, p_pool_index, 1662f59fd9caSVladimir Oltean p_threshold); 1663f59fd9caSVladimir Oltean } 1664f59fd9caSVladimir Oltean 1665f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port, 1666f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1667f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1668f59fd9caSVladimir Oltean u16 pool_index, u32 threshold, 1669f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1670f59fd9caSVladimir Oltean { 1671f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1672f59fd9caSVladimir Oltean 1673f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index, 1674f59fd9caSVladimir Oltean pool_type, pool_index, threshold, 1675f59fd9caSVladimir Oltean extack); 1676f59fd9caSVladimir Oltean } 1677f59fd9caSVladimir Oltean 1678f59fd9caSVladimir Oltean static int felix_sb_occ_snapshot(struct dsa_switch *ds, 1679f59fd9caSVladimir Oltean unsigned int sb_index) 1680f59fd9caSVladimir Oltean { 1681f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1682f59fd9caSVladimir Oltean 1683f59fd9caSVladimir Oltean return ocelot_sb_occ_snapshot(ocelot, sb_index); 1684f59fd9caSVladimir Oltean } 1685f59fd9caSVladimir Oltean 1686f59fd9caSVladimir Oltean static int felix_sb_occ_max_clear(struct dsa_switch *ds, 1687f59fd9caSVladimir Oltean unsigned int sb_index) 1688f59fd9caSVladimir Oltean { 1689f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1690f59fd9caSVladimir Oltean 1691f59fd9caSVladimir Oltean return ocelot_sb_occ_max_clear(ocelot, sb_index); 1692f59fd9caSVladimir Oltean } 1693f59fd9caSVladimir Oltean 1694f59fd9caSVladimir Oltean static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port, 1695f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1696f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1697f59fd9caSVladimir Oltean { 1698f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1699f59fd9caSVladimir Oltean 1700f59fd9caSVladimir Oltean return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index, 1701f59fd9caSVladimir Oltean p_cur, p_max); 1702f59fd9caSVladimir Oltean } 1703f59fd9caSVladimir Oltean 1704f59fd9caSVladimir Oltean static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port, 1705f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1706f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1707f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1708f59fd9caSVladimir Oltean { 1709f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1710f59fd9caSVladimir Oltean 1711f59fd9caSVladimir Oltean return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index, 1712f59fd9caSVladimir Oltean pool_type, p_cur, p_max); 1713f59fd9caSVladimir Oltean } 1714f59fd9caSVladimir Oltean 1715a026c50bSHoratiu Vultur static int felix_mrp_add(struct dsa_switch *ds, int port, 1716a026c50bSHoratiu Vultur const struct switchdev_obj_mrp *mrp) 1717a026c50bSHoratiu Vultur { 1718a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1719a026c50bSHoratiu Vultur 1720a026c50bSHoratiu Vultur return ocelot_mrp_add(ocelot, port, mrp); 1721a026c50bSHoratiu Vultur } 1722a026c50bSHoratiu Vultur 1723a026c50bSHoratiu Vultur static int felix_mrp_del(struct dsa_switch *ds, int port, 1724a026c50bSHoratiu Vultur const struct switchdev_obj_mrp *mrp) 1725a026c50bSHoratiu Vultur { 1726a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1727a026c50bSHoratiu Vultur 1728a026c50bSHoratiu Vultur return ocelot_mrp_add(ocelot, port, mrp); 1729a026c50bSHoratiu Vultur } 1730a026c50bSHoratiu Vultur 1731a026c50bSHoratiu Vultur static int 1732a026c50bSHoratiu Vultur felix_mrp_add_ring_role(struct dsa_switch *ds, int port, 1733a026c50bSHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp) 1734a026c50bSHoratiu Vultur { 1735a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1736a026c50bSHoratiu Vultur 1737a026c50bSHoratiu Vultur return ocelot_mrp_add_ring_role(ocelot, port, mrp); 1738a026c50bSHoratiu Vultur } 1739a026c50bSHoratiu Vultur 1740a026c50bSHoratiu Vultur static int 1741a026c50bSHoratiu Vultur felix_mrp_del_ring_role(struct dsa_switch *ds, int port, 1742a026c50bSHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp) 1743a026c50bSHoratiu Vultur { 1744a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1745a026c50bSHoratiu Vultur 1746a026c50bSHoratiu Vultur return ocelot_mrp_del_ring_role(ocelot, port, mrp); 1747a026c50bSHoratiu Vultur } 1748a026c50bSHoratiu Vultur 1749978777d0SVladimir Oltean static int felix_port_get_default_prio(struct dsa_switch *ds, int port) 1750978777d0SVladimir Oltean { 1751978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1752978777d0SVladimir Oltean 1753978777d0SVladimir Oltean return ocelot_port_get_default_prio(ocelot, port); 1754978777d0SVladimir Oltean } 1755978777d0SVladimir Oltean 1756978777d0SVladimir Oltean static int felix_port_set_default_prio(struct dsa_switch *ds, int port, 1757978777d0SVladimir Oltean u8 prio) 1758978777d0SVladimir Oltean { 1759978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1760978777d0SVladimir Oltean 1761978777d0SVladimir Oltean return ocelot_port_set_default_prio(ocelot, port, prio); 1762978777d0SVladimir Oltean } 1763978777d0SVladimir Oltean 1764978777d0SVladimir Oltean static int felix_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) 1765978777d0SVladimir Oltean { 1766978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1767978777d0SVladimir Oltean 1768978777d0SVladimir Oltean return ocelot_port_get_dscp_prio(ocelot, port, dscp); 1769978777d0SVladimir Oltean } 1770978777d0SVladimir Oltean 1771978777d0SVladimir Oltean static int felix_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, 1772978777d0SVladimir Oltean u8 prio) 1773978777d0SVladimir Oltean { 1774978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1775978777d0SVladimir Oltean 1776978777d0SVladimir Oltean return ocelot_port_add_dscp_prio(ocelot, port, dscp, prio); 1777978777d0SVladimir Oltean } 1778978777d0SVladimir Oltean 1779978777d0SVladimir Oltean static int felix_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, 1780978777d0SVladimir Oltean u8 prio) 1781978777d0SVladimir Oltean { 1782978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1783978777d0SVladimir Oltean 1784978777d0SVladimir Oltean return ocelot_port_del_dscp_prio(ocelot, port, dscp, prio); 1785978777d0SVladimir Oltean } 1786978777d0SVladimir Oltean 1787375e1314SVladimir Oltean const struct dsa_switch_ops felix_switch_ops = { 178856051948SVladimir Oltean .get_tag_protocol = felix_get_tag_protocol, 1789adb3dccfSVladimir Oltean .change_tag_protocol = felix_change_tag_protocol, 179035d97680SVladimir Oltean .connect_tag_protocol = felix_connect_tag_protocol, 179156051948SVladimir Oltean .setup = felix_setup, 179256051948SVladimir Oltean .teardown = felix_teardown, 179356051948SVladimir Oltean .set_ageing_time = felix_set_ageing_time, 179456051948SVladimir Oltean .get_strings = felix_get_strings, 179556051948SVladimir Oltean .get_ethtool_stats = felix_get_ethtool_stats, 179656051948SVladimir Oltean .get_sset_count = felix_get_sset_count, 179756051948SVladimir Oltean .get_ts_info = felix_get_ts_info, 179879fda660SRussell King (Oracle) .phylink_get_caps = felix_phylink_get_caps, 1799bdeced75SVladimir Oltean .phylink_validate = felix_phylink_validate, 1800864ba485SRussell King (Oracle) .phylink_mac_select_pcs = felix_phylink_mac_select_pcs, 1801bdeced75SVladimir Oltean .phylink_mac_link_down = felix_phylink_mac_link_down, 1802bdeced75SVladimir Oltean .phylink_mac_link_up = felix_phylink_mac_link_up, 18035cad43a5SVladimir Oltean .port_fast_age = felix_port_fast_age, 180456051948SVladimir Oltean .port_fdb_dump = felix_fdb_dump, 180556051948SVladimir Oltean .port_fdb_add = felix_fdb_add, 180656051948SVladimir Oltean .port_fdb_del = felix_fdb_del, 1807961d8b69SVladimir Oltean .lag_fdb_add = felix_lag_fdb_add, 1808961d8b69SVladimir Oltean .lag_fdb_del = felix_lag_fdb_del, 1809209edf95SVladimir Oltean .port_mdb_add = felix_mdb_add, 1810209edf95SVladimir Oltean .port_mdb_del = felix_mdb_del, 1811421741eaSVladimir Oltean .port_pre_bridge_flags = felix_pre_bridge_flags, 1812421741eaSVladimir Oltean .port_bridge_flags = felix_bridge_flags, 181356051948SVladimir Oltean .port_bridge_join = felix_bridge_join, 181456051948SVladimir Oltean .port_bridge_leave = felix_bridge_leave, 18158fe6832eSVladimir Oltean .port_lag_join = felix_lag_join, 18168fe6832eSVladimir Oltean .port_lag_leave = felix_lag_leave, 18178fe6832eSVladimir Oltean .port_lag_change = felix_lag_change, 181856051948SVladimir Oltean .port_stp_state_set = felix_bridge_stp_state_set, 181956051948SVladimir Oltean .port_vlan_filtering = felix_vlan_filtering, 182056051948SVladimir Oltean .port_vlan_add = felix_vlan_add, 182156051948SVladimir Oltean .port_vlan_del = felix_vlan_del, 1822c0bcf537SYangbo Lu .port_hwtstamp_get = felix_hwtstamp_get, 1823c0bcf537SYangbo Lu .port_hwtstamp_set = felix_hwtstamp_set, 1824c0bcf537SYangbo Lu .port_rxtstamp = felix_rxtstamp, 1825c0bcf537SYangbo Lu .port_txtstamp = felix_txtstamp, 18260b912fc9SVladimir Oltean .port_change_mtu = felix_change_mtu, 18270b912fc9SVladimir Oltean .port_max_mtu = felix_get_max_mtu, 1828fc411eaaSVladimir Oltean .port_policer_add = felix_port_policer_add, 1829fc411eaaSVladimir Oltean .port_policer_del = felix_port_policer_del, 18305e497497SVladimir Oltean .port_mirror_add = felix_port_mirror_add, 18315e497497SVladimir Oltean .port_mirror_del = felix_port_mirror_del, 183207d985eeSVladimir Oltean .cls_flower_add = felix_cls_flower_add, 183307d985eeSVladimir Oltean .cls_flower_del = felix_cls_flower_del, 183407d985eeSVladimir Oltean .cls_flower_stats = felix_cls_flower_stats, 1835de143c0eSXiaoliang Yang .port_setup_tc = felix_port_setup_tc, 1836f59fd9caSVladimir Oltean .devlink_sb_pool_get = felix_sb_pool_get, 1837f59fd9caSVladimir Oltean .devlink_sb_pool_set = felix_sb_pool_set, 1838f59fd9caSVladimir Oltean .devlink_sb_port_pool_get = felix_sb_port_pool_get, 1839f59fd9caSVladimir Oltean .devlink_sb_port_pool_set = felix_sb_port_pool_set, 1840f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get, 1841f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set, 1842f59fd9caSVladimir Oltean .devlink_sb_occ_snapshot = felix_sb_occ_snapshot, 1843f59fd9caSVladimir Oltean .devlink_sb_occ_max_clear = felix_sb_occ_max_clear, 1844f59fd9caSVladimir Oltean .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get, 1845f59fd9caSVladimir Oltean .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get, 1846a026c50bSHoratiu Vultur .port_mrp_add = felix_mrp_add, 1847a026c50bSHoratiu Vultur .port_mrp_del = felix_mrp_del, 1848a026c50bSHoratiu Vultur .port_mrp_add_ring_role = felix_mrp_add_ring_role, 1849a026c50bSHoratiu Vultur .port_mrp_del_ring_role = felix_mrp_del_ring_role, 18505da11eb4SVladimir Oltean .tag_8021q_vlan_add = felix_tag_8021q_vlan_add, 18515da11eb4SVladimir Oltean .tag_8021q_vlan_del = felix_tag_8021q_vlan_del, 1852978777d0SVladimir Oltean .port_get_default_prio = felix_port_get_default_prio, 1853978777d0SVladimir Oltean .port_set_default_prio = felix_port_set_default_prio, 1854978777d0SVladimir Oltean .port_get_dscp_prio = felix_port_get_dscp_prio, 1855978777d0SVladimir Oltean .port_add_dscp_prio = felix_port_add_dscp_prio, 1856978777d0SVladimir Oltean .port_del_dscp_prio = felix_port_del_dscp_prio, 185756051948SVladimir Oltean }; 1858319e4dd1SVladimir Oltean 1859319e4dd1SVladimir Oltean struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) 1860319e4dd1SVladimir Oltean { 1861319e4dd1SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1862319e4dd1SVladimir Oltean struct dsa_switch *ds = felix->ds; 1863319e4dd1SVladimir Oltean 1864319e4dd1SVladimir Oltean if (!dsa_is_user_port(ds, port)) 1865319e4dd1SVladimir Oltean return NULL; 1866319e4dd1SVladimir Oltean 1867319e4dd1SVladimir Oltean return dsa_to_port(ds, port)->slave; 1868319e4dd1SVladimir Oltean } 1869319e4dd1SVladimir Oltean 1870319e4dd1SVladimir Oltean int felix_netdev_to_port(struct net_device *dev) 1871319e4dd1SVladimir Oltean { 1872319e4dd1SVladimir Oltean struct dsa_port *dp; 1873319e4dd1SVladimir Oltean 1874319e4dd1SVladimir Oltean dp = dsa_port_from_netdev(dev); 1875319e4dd1SVladimir Oltean if (IS_ERR(dp)) 1876319e4dd1SVladimir Oltean return -EINVAL; 1877319e4dd1SVladimir Oltean 1878319e4dd1SVladimir Oltean return dp->index; 1879319e4dd1SVladimir Oltean } 1880