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 4504b67e18SVladimir Oltean /* Set up VCAP ES0 rules for pushing a tag_8021q VLAN towards the CPU such that 4604b67e18SVladimir Oltean * the tagger can perform RX source port identification. 4704b67e18SVladimir Oltean */ 4804b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add_rx(struct felix *felix, int port, u16 vid) 49e21268efSVladimir Oltean { 50e21268efSVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 51e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 52e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 53e21268efSVladimir Oltean int key_length, upstream, err; 54e21268efSVladimir Oltean 55e21268efSVladimir Oltean key_length = ocelot->vcap[VCAP_ES0].keys[VCAP_ES0_IGR_PORT].length; 56e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 57e21268efSVladimir Oltean 58e21268efSVladimir Oltean outer_tagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), 59e21268efSVladimir Oltean GFP_KERNEL); 60e21268efSVladimir Oltean if (!outer_tagging_rule) 61e21268efSVladimir Oltean return -ENOMEM; 62e21268efSVladimir Oltean 63e21268efSVladimir Oltean outer_tagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 64e21268efSVladimir Oltean outer_tagging_rule->prio = 1; 65c518afecSVladimir Oltean outer_tagging_rule->id.cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port); 66e21268efSVladimir Oltean outer_tagging_rule->id.tc_offload = false; 67e21268efSVladimir Oltean outer_tagging_rule->block_id = VCAP_ES0; 68e21268efSVladimir Oltean outer_tagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 69e21268efSVladimir Oltean outer_tagging_rule->lookup = 0; 70e21268efSVladimir Oltean outer_tagging_rule->ingress_port.value = port; 71e21268efSVladimir Oltean outer_tagging_rule->ingress_port.mask = GENMASK(key_length - 1, 0); 72e21268efSVladimir Oltean outer_tagging_rule->egress_port.value = upstream; 73e21268efSVladimir Oltean outer_tagging_rule->egress_port.mask = GENMASK(key_length - 1, 0); 74e21268efSVladimir Oltean outer_tagging_rule->action.push_outer_tag = OCELOT_ES0_TAG; 75e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_tpid_sel = OCELOT_TAG_TPID_SEL_8021AD; 76e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_vid_sel = 1; 77e21268efSVladimir Oltean outer_tagging_rule->action.vid_a_val = vid; 78e21268efSVladimir Oltean 79e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, outer_tagging_rule, NULL); 80e21268efSVladimir Oltean if (err) 81e21268efSVladimir Oltean kfree(outer_tagging_rule); 82e21268efSVladimir Oltean 83e21268efSVladimir Oltean return err; 84e21268efSVladimir Oltean } 85e21268efSVladimir Oltean 8604b67e18SVladimir Oltean static int felix_tag_8021q_vlan_del_rx(struct felix *felix, int port, u16 vid) 8704b67e18SVladimir Oltean { 8804b67e18SVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 8904b67e18SVladimir Oltean struct ocelot_vcap_block *block_vcap_es0; 9004b67e18SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 9104b67e18SVladimir Oltean 9204b67e18SVladimir Oltean block_vcap_es0 = &ocelot->block[VCAP_ES0]; 9304b67e18SVladimir Oltean 9404b67e18SVladimir Oltean outer_tagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_es0, 9504b67e18SVladimir Oltean port, false); 9604b67e18SVladimir Oltean if (!outer_tagging_rule) 9704b67e18SVladimir Oltean return -ENOENT; 9804b67e18SVladimir Oltean 9904b67e18SVladimir Oltean return ocelot_vcap_filter_del(ocelot, outer_tagging_rule); 10004b67e18SVladimir Oltean } 10104b67e18SVladimir Oltean 10204b67e18SVladimir Oltean /* Set up VCAP IS1 rules for stripping the tag_8021q VLAN on TX and VCAP IS2 10304b67e18SVladimir Oltean * rules for steering those tagged packets towards the correct destination port 10404b67e18SVladimir Oltean */ 10504b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add_tx(struct felix *felix, int port, u16 vid) 106e21268efSVladimir Oltean { 107e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 108e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 109e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 110e21268efSVladimir Oltean int upstream, err; 111e21268efSVladimir Oltean 112e21268efSVladimir Oltean untagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 113e21268efSVladimir Oltean if (!untagging_rule) 114e21268efSVladimir Oltean return -ENOMEM; 115e21268efSVladimir Oltean 116e21268efSVladimir Oltean redirect_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 117e21268efSVladimir Oltean if (!redirect_rule) { 118e21268efSVladimir Oltean kfree(untagging_rule); 119e21268efSVladimir Oltean return -ENOMEM; 120e21268efSVladimir Oltean } 121e21268efSVladimir Oltean 122e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 123e21268efSVladimir Oltean 124e21268efSVladimir Oltean untagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 125e21268efSVladimir Oltean untagging_rule->ingress_port_mask = BIT(upstream); 126e21268efSVladimir Oltean untagging_rule->vlan.vid.value = vid; 127e21268efSVladimir Oltean untagging_rule->vlan.vid.mask = VLAN_VID_MASK; 128e21268efSVladimir Oltean untagging_rule->prio = 1; 129c518afecSVladimir Oltean untagging_rule->id.cookie = OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port); 130e21268efSVladimir Oltean untagging_rule->id.tc_offload = false; 131e21268efSVladimir Oltean untagging_rule->block_id = VCAP_IS1; 132e21268efSVladimir Oltean untagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 133e21268efSVladimir Oltean untagging_rule->lookup = 0; 134e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt_ena = true; 135e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt = 1; 136e21268efSVladimir Oltean untagging_rule->action.pag_override_mask = 0xff; 137e21268efSVladimir Oltean untagging_rule->action.pag_val = port; 138e21268efSVladimir Oltean 139e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, untagging_rule, NULL); 140e21268efSVladimir Oltean if (err) { 141e21268efSVladimir Oltean kfree(untagging_rule); 142e21268efSVladimir Oltean kfree(redirect_rule); 143e21268efSVladimir Oltean return err; 144e21268efSVladimir Oltean } 145e21268efSVladimir Oltean 146e21268efSVladimir Oltean redirect_rule->key_type = OCELOT_VCAP_KEY_ANY; 147e21268efSVladimir Oltean redirect_rule->ingress_port_mask = BIT(upstream); 148e21268efSVladimir Oltean redirect_rule->pag = port; 149e21268efSVladimir Oltean redirect_rule->prio = 1; 150c518afecSVladimir Oltean redirect_rule->id.cookie = OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port); 151e21268efSVladimir Oltean redirect_rule->id.tc_offload = false; 152e21268efSVladimir Oltean redirect_rule->block_id = VCAP_IS2; 153e21268efSVladimir Oltean redirect_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 154e21268efSVladimir Oltean redirect_rule->lookup = 0; 155e21268efSVladimir Oltean redirect_rule->action.mask_mode = OCELOT_MASK_MODE_REDIRECT; 156e21268efSVladimir Oltean redirect_rule->action.port_mask = BIT(port); 157e21268efSVladimir Oltean 158e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, redirect_rule, NULL); 159e21268efSVladimir Oltean if (err) { 160e21268efSVladimir Oltean ocelot_vcap_filter_del(ocelot, untagging_rule); 161e21268efSVladimir Oltean kfree(redirect_rule); 162e21268efSVladimir Oltean return err; 163e21268efSVladimir Oltean } 164e21268efSVladimir Oltean 165e21268efSVladimir Oltean return 0; 166e21268efSVladimir Oltean } 167e21268efSVladimir Oltean 16804b67e18SVladimir Oltean static int felix_tag_8021q_vlan_del_tx(struct felix *felix, int port, u16 vid) 169e21268efSVladimir Oltean { 170e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 171e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is1; 172e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is2; 173e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 174e21268efSVladimir Oltean int err; 175e21268efSVladimir Oltean 176e21268efSVladimir Oltean block_vcap_is1 = &ocelot->block[VCAP_IS1]; 177e21268efSVladimir Oltean block_vcap_is2 = &ocelot->block[VCAP_IS2]; 178e21268efSVladimir Oltean 179e21268efSVladimir Oltean untagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is1, 180e21268efSVladimir Oltean port, false); 181e21268efSVladimir Oltean if (!untagging_rule) 18208f44db3SVladimir Oltean return -ENOENT; 183e21268efSVladimir Oltean 184e21268efSVladimir Oltean err = ocelot_vcap_filter_del(ocelot, untagging_rule); 185e21268efSVladimir Oltean if (err) 186e21268efSVladimir Oltean return err; 187e21268efSVladimir Oltean 188e21268efSVladimir Oltean redirect_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is2, 189e21268efSVladimir Oltean port, false); 190e21268efSVladimir Oltean if (!redirect_rule) 19104b67e18SVladimir Oltean return -ENOENT; 192e21268efSVladimir Oltean 193e21268efSVladimir Oltean return ocelot_vcap_filter_del(ocelot, redirect_rule); 194e21268efSVladimir Oltean } 195e21268efSVladimir Oltean 19604b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, 19704b67e18SVladimir Oltean u16 flags) 19804b67e18SVladimir Oltean { 19904b67e18SVladimir Oltean struct ocelot *ocelot = ds->priv; 20004b67e18SVladimir Oltean int err; 20104b67e18SVladimir Oltean 20204b67e18SVladimir Oltean /* tag_8021q.c assumes we are implementing this via port VLAN 20304b67e18SVladimir Oltean * membership, which we aren't. So we don't need to add any VCAP filter 20404b67e18SVladimir Oltean * for the CPU port. 20504b67e18SVladimir Oltean */ 20604b67e18SVladimir Oltean if (!dsa_is_user_port(ds, port)) 20704b67e18SVladimir Oltean return 0; 20804b67e18SVladimir Oltean 20904b67e18SVladimir Oltean err = felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid); 21004b67e18SVladimir Oltean if (err) 21104b67e18SVladimir Oltean return err; 21204b67e18SVladimir Oltean 21304b67e18SVladimir Oltean err = felix_tag_8021q_vlan_add_tx(ocelot_to_felix(ocelot), port, vid); 21404b67e18SVladimir Oltean if (err) { 21504b67e18SVladimir Oltean felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid); 21604b67e18SVladimir Oltean return err; 21704b67e18SVladimir Oltean } 21804b67e18SVladimir Oltean 21904b67e18SVladimir Oltean return 0; 22004b67e18SVladimir Oltean } 22104b67e18SVladimir Oltean 222e21268efSVladimir Oltean static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) 223e21268efSVladimir Oltean { 224e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 22504b67e18SVladimir Oltean int err; 226e21268efSVladimir Oltean 22704b67e18SVladimir Oltean if (!dsa_is_user_port(ds, port)) 22804b67e18SVladimir Oltean return 0; 229e21268efSVladimir Oltean 23004b67e18SVladimir Oltean err = felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid); 23104b67e18SVladimir Oltean if (err) 23204b67e18SVladimir Oltean return err; 23304b67e18SVladimir Oltean 23404b67e18SVladimir Oltean err = felix_tag_8021q_vlan_del_tx(ocelot_to_felix(ocelot), port, vid); 23504b67e18SVladimir Oltean if (err) { 23604b67e18SVladimir Oltean felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid); 23704b67e18SVladimir Oltean return err; 23804b67e18SVladimir Oltean } 239e21268efSVladimir Oltean 240e21268efSVladimir Oltean return 0; 241e21268efSVladimir Oltean } 242e21268efSVladimir Oltean 243e21268efSVladimir Oltean /* Alternatively to using the NPI functionality, that same hardware MAC 244e21268efSVladimir Oltean * connected internally to the enetc or fman DSA master can be configured to 245e21268efSVladimir Oltean * use the software-defined tag_8021q frame format. As far as the hardware is 246e21268efSVladimir Oltean * concerned, it thinks it is a "dumb switch" - the queues of the CPU port 247e21268efSVladimir Oltean * module are now disconnected from it, but can still be accessed through 248e21268efSVladimir Oltean * register-based MMIO. 249e21268efSVladimir Oltean */ 250e21268efSVladimir Oltean static void felix_8021q_cpu_port_init(struct ocelot *ocelot, int port) 251e21268efSVladimir Oltean { 2528abe1970SVladimir Oltean mutex_lock(&ocelot->fwd_domain_lock); 2538abe1970SVladimir Oltean 25454c31984SVladimir Oltean ocelot_port_set_dsa_8021q_cpu(ocelot, port); 255e21268efSVladimir Oltean 256e21268efSVladimir Oltean /* Overwrite PGID_CPU with the non-tagging port */ 257e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, PGID_CPU); 258e21268efSVladimir Oltean 2598abe1970SVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot, true); 2608abe1970SVladimir Oltean 2618abe1970SVladimir Oltean mutex_unlock(&ocelot->fwd_domain_lock); 262e21268efSVladimir Oltean } 263e21268efSVladimir Oltean 264e21268efSVladimir Oltean static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port) 265e21268efSVladimir Oltean { 2668abe1970SVladimir Oltean mutex_lock(&ocelot->fwd_domain_lock); 2678abe1970SVladimir Oltean 26854c31984SVladimir Oltean ocelot_port_unset_dsa_8021q_cpu(ocelot, port); 269e21268efSVladimir Oltean 270e21268efSVladimir Oltean /* Restore PGID_CPU */ 271e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(ocelot->num_phys_ports), ANA_PGID_PGID, 272e21268efSVladimir Oltean PGID_CPU); 273e21268efSVladimir Oltean 2748abe1970SVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot, true); 2758abe1970SVladimir Oltean 2768abe1970SVladimir Oltean mutex_unlock(&ocelot->fwd_domain_lock); 277e21268efSVladimir Oltean } 278e21268efSVladimir Oltean 279c352e5e8SVladimir Oltean static int felix_trap_get_cpu_port(struct dsa_switch *ds, 280c352e5e8SVladimir Oltean const struct ocelot_vcap_filter *trap) 281c352e5e8SVladimir Oltean { 282c352e5e8SVladimir Oltean struct dsa_port *dp; 283c352e5e8SVladimir Oltean int first_port; 284c352e5e8SVladimir Oltean 285c352e5e8SVladimir Oltean if (WARN_ON(!trap->ingress_port_mask)) 286c352e5e8SVladimir Oltean return -1; 287c352e5e8SVladimir Oltean 288c352e5e8SVladimir Oltean first_port = __ffs(trap->ingress_port_mask); 289c352e5e8SVladimir Oltean dp = dsa_to_port(ds, first_port); 290c352e5e8SVladimir Oltean 291c352e5e8SVladimir Oltean return dp->cpu_dp->index; 292c352e5e8SVladimir Oltean } 293c352e5e8SVladimir Oltean 29499348004SVladimir Oltean /* On switches with no extraction IRQ wired, trapped packets need to be 29599348004SVladimir Oltean * replicated over Ethernet as well, otherwise we'd get no notification of 29699348004SVladimir Oltean * their arrival when using the ocelot-8021q tagging protocol. 297c8c0ba4fSVladimir Oltean */ 29899348004SVladimir Oltean static int felix_update_trapping_destinations(struct dsa_switch *ds, 29999348004SVladimir Oltean bool using_tag_8021q) 300c8c0ba4fSVladimir Oltean { 30199348004SVladimir Oltean struct ocelot *ocelot = ds->priv; 30299348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 303e1846cffSVladimir Oltean struct ocelot_vcap_block *block_vcap_is2; 30499348004SVladimir Oltean struct ocelot_vcap_filter *trap; 30599348004SVladimir Oltean enum ocelot_mask_mode mask_mode; 30699348004SVladimir Oltean unsigned long port_mask; 30799348004SVladimir Oltean bool cpu_copy_ena; 308c352e5e8SVladimir Oltean int err; 309c8c0ba4fSVladimir Oltean 31099348004SVladimir Oltean if (!felix->info->quirk_no_xtr_irq) 31199348004SVladimir Oltean return 0; 312c8c0ba4fSVladimir Oltean 313d78637a8SVladimir Oltean /* We are sure that "cpu" was found, otherwise 314d78637a8SVladimir Oltean * dsa_tree_setup_default_cpu() would have failed earlier. 315d78637a8SVladimir Oltean */ 316e1846cffSVladimir Oltean block_vcap_is2 = &ocelot->block[VCAP_IS2]; 317c8c0ba4fSVladimir Oltean 31899348004SVladimir Oltean /* Make sure all traps are set up for that destination */ 319e1846cffSVladimir Oltean list_for_each_entry(trap, &block_vcap_is2->rules, list) { 320e1846cffSVladimir Oltean if (!trap->is_trap) 321e1846cffSVladimir Oltean continue; 322e1846cffSVladimir Oltean 32399348004SVladimir Oltean /* Figure out the current trapping destination */ 32499348004SVladimir Oltean if (using_tag_8021q) { 32599348004SVladimir Oltean /* Redirect to the tag_8021q CPU port. If timestamps 32699348004SVladimir Oltean * are necessary, also copy trapped packets to the CPU 32799348004SVladimir Oltean * port module. 328c8c0ba4fSVladimir Oltean */ 32999348004SVladimir Oltean mask_mode = OCELOT_MASK_MODE_REDIRECT; 330c352e5e8SVladimir Oltean port_mask = BIT(felix_trap_get_cpu_port(ds, trap)); 33199348004SVladimir Oltean cpu_copy_ena = !!trap->take_ts; 332c8c0ba4fSVladimir Oltean } else { 33399348004SVladimir Oltean /* Trap packets only to the CPU port module, which is 33499348004SVladimir Oltean * redirected to the NPI port (the DSA CPU port) 335c8c0ba4fSVladimir Oltean */ 33699348004SVladimir Oltean mask_mode = OCELOT_MASK_MODE_PERMIT_DENY; 33799348004SVladimir Oltean port_mask = 0; 33899348004SVladimir Oltean cpu_copy_ena = true; 339c8c0ba4fSVladimir Oltean } 340c8c0ba4fSVladimir Oltean 34199348004SVladimir Oltean if (trap->action.mask_mode == mask_mode && 34299348004SVladimir Oltean trap->action.port_mask == port_mask && 34399348004SVladimir Oltean trap->action.cpu_copy_ena == cpu_copy_ena) 34499348004SVladimir Oltean continue; 345c8c0ba4fSVladimir Oltean 34699348004SVladimir Oltean trap->action.mask_mode = mask_mode; 34799348004SVladimir Oltean trap->action.port_mask = port_mask; 34899348004SVladimir Oltean trap->action.cpu_copy_ena = cpu_copy_ena; 3490a6f17c6SVladimir Oltean 35099348004SVladimir Oltean err = ocelot_vcap_filter_replace(ocelot, trap); 351c8c0ba4fSVladimir Oltean if (err) 352c8c0ba4fSVladimir Oltean return err; 35399348004SVladimir Oltean } 354c8c0ba4fSVladimir Oltean 35599348004SVladimir Oltean return 0; 356c8c0ba4fSVladimir Oltean } 357c8c0ba4fSVladimir Oltean 358adb3dccfSVladimir Oltean /* The CPU port module is connected to the Node Processor Interface (NPI). This 359adb3dccfSVladimir Oltean * is the mode through which frames can be injected from and extracted to an 360adb3dccfSVladimir Oltean * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU 361adb3dccfSVladimir Oltean * running Linux, and this forms a DSA setup together with the enetc or fman 362adb3dccfSVladimir Oltean * DSA master. 363adb3dccfSVladimir Oltean */ 364adb3dccfSVladimir Oltean static void felix_npi_port_init(struct ocelot *ocelot, int port) 365adb3dccfSVladimir Oltean { 366adb3dccfSVladimir Oltean ocelot->npi = port; 367adb3dccfSVladimir Oltean 368adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M | 369adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port), 370adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 371adb3dccfSVladimir Oltean 372adb3dccfSVladimir Oltean /* NPI port Injection/Extraction configuration */ 373adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 374adb3dccfSVladimir Oltean ocelot->npi_xtr_prefix); 375adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 376adb3dccfSVladimir Oltean ocelot->npi_inj_prefix); 377adb3dccfSVladimir Oltean 378adb3dccfSVladimir Oltean /* Disable transmission of pause frames */ 379adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0); 380adb3dccfSVladimir Oltean } 381adb3dccfSVladimir Oltean 382adb3dccfSVladimir Oltean static void felix_npi_port_deinit(struct ocelot *ocelot, int port) 383adb3dccfSVladimir Oltean { 384adb3dccfSVladimir Oltean /* Restore hardware defaults */ 385adb3dccfSVladimir Oltean int unused_port = ocelot->num_phys_ports + 2; 386adb3dccfSVladimir Oltean 387adb3dccfSVladimir Oltean ocelot->npi = -1; 388adb3dccfSVladimir Oltean 389adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPU_PORT(unused_port), 390adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 391adb3dccfSVladimir Oltean 392adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 393adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 394adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 395adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 396adb3dccfSVladimir Oltean 397adb3dccfSVladimir Oltean /* Enable transmission of pause frames */ 398adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); 399adb3dccfSVladimir Oltean } 400adb3dccfSVladimir Oltean 401*7a29d220SVladimir Oltean static int felix_tag_npi_setup(struct dsa_switch *ds) 402adb3dccfSVladimir Oltean { 403*7a29d220SVladimir Oltean struct dsa_port *dp, *first_cpu_dp = NULL; 404adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 405f9cef64fSVladimir Oltean 406*7a29d220SVladimir Oltean dsa_switch_for_each_user_port(dp, ds) { 407*7a29d220SVladimir Oltean if (first_cpu_dp && dp->cpu_dp != first_cpu_dp) { 408*7a29d220SVladimir Oltean dev_err(ds->dev, "Multiple NPI ports not supported\n"); 409*7a29d220SVladimir Oltean return -EINVAL; 410*7a29d220SVladimir Oltean } 411b903a6bdSVladimir Oltean 412*7a29d220SVladimir Oltean first_cpu_dp = dp->cpu_dp; 413*7a29d220SVladimir Oltean } 414adb3dccfSVladimir Oltean 415*7a29d220SVladimir Oltean if (!first_cpu_dp) 416*7a29d220SVladimir Oltean return -EINVAL; 417*7a29d220SVladimir Oltean 418*7a29d220SVladimir Oltean felix_npi_port_init(ocelot, first_cpu_dp->index); 419adb3dccfSVladimir Oltean 420adb3dccfSVladimir Oltean return 0; 421adb3dccfSVladimir Oltean } 422adb3dccfSVladimir Oltean 423*7a29d220SVladimir Oltean static void felix_tag_npi_teardown(struct dsa_switch *ds) 424adb3dccfSVladimir Oltean { 425adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 426adb3dccfSVladimir Oltean 427*7a29d220SVladimir Oltean felix_npi_port_deinit(ocelot, ocelot->npi); 428adb3dccfSVladimir Oltean } 429adb3dccfSVladimir Oltean 430*7a29d220SVladimir Oltean static unsigned long felix_tag_npi_get_host_fwd_mask(struct dsa_switch *ds) 431adb3dccfSVladimir Oltean { 432*7a29d220SVladimir Oltean struct ocelot *ocelot = ds->priv; 433*7a29d220SVladimir Oltean 434*7a29d220SVladimir Oltean return BIT(ocelot->num_phys_ports); 435*7a29d220SVladimir Oltean } 436*7a29d220SVladimir Oltean 437*7a29d220SVladimir Oltean static const struct felix_tag_proto_ops felix_tag_npi_proto_ops = { 438*7a29d220SVladimir Oltean .setup = felix_tag_npi_setup, 439*7a29d220SVladimir Oltean .teardown = felix_tag_npi_teardown, 440*7a29d220SVladimir Oltean .get_host_fwd_mask = felix_tag_npi_get_host_fwd_mask, 441*7a29d220SVladimir Oltean }; 442*7a29d220SVladimir Oltean 443*7a29d220SVladimir Oltean static int felix_tag_8021q_setup(struct dsa_switch *ds) 444*7a29d220SVladimir Oltean { 445*7a29d220SVladimir Oltean struct ocelot *ocelot = ds->priv; 446*7a29d220SVladimir Oltean struct dsa_port *dp, *cpu_dp; 447adb3dccfSVladimir Oltean int err; 448adb3dccfSVladimir Oltean 449*7a29d220SVladimir Oltean err = dsa_tag_8021q_register(ds, htons(ETH_P_8021AD)); 450*7a29d220SVladimir Oltean if (err) 451adb3dccfSVladimir Oltean return err; 452*7a29d220SVladimir Oltean 453*7a29d220SVladimir Oltean dsa_switch_for_each_cpu_port(cpu_dp, ds) { 454*7a29d220SVladimir Oltean felix_8021q_cpu_port_init(ocelot, cpu_dp->index); 455*7a29d220SVladimir Oltean 456*7a29d220SVladimir Oltean /* TODO we could support multiple CPU ports in tag_8021q mode */ 457*7a29d220SVladimir Oltean break; 458adb3dccfSVladimir Oltean } 459adb3dccfSVladimir Oltean 460*7a29d220SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 461*7a29d220SVladimir Oltean /* This overwrites ocelot_init(): 462*7a29d220SVladimir Oltean * Do not forward BPDU frames to the CPU port module, 463*7a29d220SVladimir Oltean * for 2 reasons: 464*7a29d220SVladimir Oltean * - When these packets are injected from the tag_8021q 465*7a29d220SVladimir Oltean * CPU port, we want them to go out, not loop back 466*7a29d220SVladimir Oltean * into the system. 467*7a29d220SVladimir Oltean * - STP traffic ingressing on a user port should go to 468*7a29d220SVladimir Oltean * the tag_8021q CPU port, not to the hardware CPU 469*7a29d220SVladimir Oltean * port module. 470*7a29d220SVladimir Oltean */ 471*7a29d220SVladimir Oltean ocelot_write_gix(ocelot, 472*7a29d220SVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0), 473*7a29d220SVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, dp->index); 474*7a29d220SVladimir Oltean } 475*7a29d220SVladimir Oltean 476*7a29d220SVladimir Oltean /* The ownership of the CPU port module's queues might have just been 477*7a29d220SVladimir Oltean * transferred to the tag_8021q tagger from the NPI-based tagger. 478*7a29d220SVladimir Oltean * So there might still be all sorts of crap in the queues. On the 479*7a29d220SVladimir Oltean * other hand, the MMIO-based matching of PTP frames is very brittle, 480*7a29d220SVladimir Oltean * so we need to be careful that there are no extra frames to be 481*7a29d220SVladimir Oltean * dequeued over MMIO, since we would never know to discard them. 482*7a29d220SVladimir Oltean */ 483*7a29d220SVladimir Oltean ocelot_drain_cpu_queue(ocelot, 0); 484*7a29d220SVladimir Oltean 485*7a29d220SVladimir Oltean return 0; 486*7a29d220SVladimir Oltean } 487*7a29d220SVladimir Oltean 488*7a29d220SVladimir Oltean static void felix_tag_8021q_teardown(struct dsa_switch *ds) 489adb3dccfSVladimir Oltean { 490*7a29d220SVladimir Oltean struct ocelot *ocelot = ds->priv; 491*7a29d220SVladimir Oltean struct dsa_port *dp, *cpu_dp; 492*7a29d220SVladimir Oltean 493*7a29d220SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 494*7a29d220SVladimir Oltean /* Restore the logic from ocelot_init: 495*7a29d220SVladimir Oltean * do not forward BPDU frames to the front ports. 496*7a29d220SVladimir Oltean */ 497*7a29d220SVladimir Oltean ocelot_write_gix(ocelot, 498*7a29d220SVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff), 499*7a29d220SVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, 500*7a29d220SVladimir Oltean dp->index); 501*7a29d220SVladimir Oltean } 502*7a29d220SVladimir Oltean 503*7a29d220SVladimir Oltean dsa_switch_for_each_cpu_port(cpu_dp, ds) { 504*7a29d220SVladimir Oltean felix_8021q_cpu_port_deinit(ocelot, cpu_dp->index); 505*7a29d220SVladimir Oltean 506*7a29d220SVladimir Oltean /* TODO we could support multiple CPU ports in tag_8021q mode */ 507adb3dccfSVladimir Oltean break; 508adb3dccfSVladimir Oltean } 509*7a29d220SVladimir Oltean 510*7a29d220SVladimir Oltean dsa_tag_8021q_unregister(ds); 511*7a29d220SVladimir Oltean } 512*7a29d220SVladimir Oltean 513*7a29d220SVladimir Oltean static unsigned long felix_tag_8021q_get_host_fwd_mask(struct dsa_switch *ds) 514*7a29d220SVladimir Oltean { 515*7a29d220SVladimir Oltean return dsa_cpu_ports(ds); 516*7a29d220SVladimir Oltean } 517*7a29d220SVladimir Oltean 518*7a29d220SVladimir Oltean static const struct felix_tag_proto_ops felix_tag_8021q_proto_ops = { 519*7a29d220SVladimir Oltean .setup = felix_tag_8021q_setup, 520*7a29d220SVladimir Oltean .teardown = felix_tag_8021q_teardown, 521*7a29d220SVladimir Oltean .get_host_fwd_mask = felix_tag_8021q_get_host_fwd_mask, 522*7a29d220SVladimir Oltean }; 523*7a29d220SVladimir Oltean 524*7a29d220SVladimir Oltean static void felix_set_host_flood(struct dsa_switch *ds, unsigned long mask, 525*7a29d220SVladimir Oltean bool uc, bool mc, bool bc) 526*7a29d220SVladimir Oltean { 527*7a29d220SVladimir Oltean struct ocelot *ocelot = ds->priv; 528*7a29d220SVladimir Oltean unsigned long val; 529*7a29d220SVladimir Oltean 530*7a29d220SVladimir Oltean val = uc ? mask : 0; 531*7a29d220SVladimir Oltean ocelot_rmw_rix(ocelot, val, mask, ANA_PGID_PGID, PGID_UC); 532*7a29d220SVladimir Oltean 533*7a29d220SVladimir Oltean val = mc ? mask : 0; 534*7a29d220SVladimir Oltean ocelot_rmw_rix(ocelot, val, mask, ANA_PGID_PGID, PGID_MC); 535*7a29d220SVladimir Oltean ocelot_rmw_rix(ocelot, val, mask, ANA_PGID_PGID, PGID_MCIPV4); 536*7a29d220SVladimir Oltean ocelot_rmw_rix(ocelot, val, mask, ANA_PGID_PGID, PGID_MCIPV6); 537*7a29d220SVladimir Oltean } 538*7a29d220SVladimir Oltean 539*7a29d220SVladimir Oltean static void 540*7a29d220SVladimir Oltean felix_migrate_host_flood(struct dsa_switch *ds, 541*7a29d220SVladimir Oltean const struct felix_tag_proto_ops *proto_ops, 542*7a29d220SVladimir Oltean const struct felix_tag_proto_ops *old_proto_ops) 543*7a29d220SVladimir Oltean { 544*7a29d220SVladimir Oltean struct ocelot *ocelot = ds->priv; 545*7a29d220SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 546*7a29d220SVladimir Oltean unsigned long mask; 547*7a29d220SVladimir Oltean 548*7a29d220SVladimir Oltean if (old_proto_ops) { 549*7a29d220SVladimir Oltean mask = old_proto_ops->get_host_fwd_mask(ds); 550*7a29d220SVladimir Oltean felix_set_host_flood(ds, mask, false, false, false); 551*7a29d220SVladimir Oltean } 552*7a29d220SVladimir Oltean 553*7a29d220SVladimir Oltean mask = proto_ops->get_host_fwd_mask(ds); 554*7a29d220SVladimir Oltean felix_set_host_flood(ds, mask, !!felix->host_flood_uc_mask, 555*7a29d220SVladimir Oltean !!felix->host_flood_mc_mask, true); 556*7a29d220SVladimir Oltean } 557*7a29d220SVladimir Oltean 558*7a29d220SVladimir Oltean static int felix_migrate_mdbs(struct dsa_switch *ds, 559*7a29d220SVladimir Oltean const struct felix_tag_proto_ops *proto_ops, 560*7a29d220SVladimir Oltean const struct felix_tag_proto_ops *old_proto_ops) 561*7a29d220SVladimir Oltean { 562*7a29d220SVladimir Oltean struct ocelot *ocelot = ds->priv; 563*7a29d220SVladimir Oltean unsigned long from, to; 564*7a29d220SVladimir Oltean 565*7a29d220SVladimir Oltean if (!old_proto_ops) 566*7a29d220SVladimir Oltean return 0; 567*7a29d220SVladimir Oltean 568*7a29d220SVladimir Oltean from = old_proto_ops->get_host_fwd_mask(ds); 569*7a29d220SVladimir Oltean to = proto_ops->get_host_fwd_mask(ds); 570*7a29d220SVladimir Oltean 571*7a29d220SVladimir Oltean return ocelot_migrate_mdbs(ocelot, from, to); 572*7a29d220SVladimir Oltean } 573*7a29d220SVladimir Oltean 574*7a29d220SVladimir Oltean /* Configure the shared hardware resources for a transition between 575*7a29d220SVladimir Oltean * @old_proto_ops and @proto_ops. 576*7a29d220SVladimir Oltean * Manual migration is needed because as far as DSA is concerned, no change of 577*7a29d220SVladimir Oltean * the CPU port is taking place here, just of the tagging protocol. 578*7a29d220SVladimir Oltean */ 579*7a29d220SVladimir Oltean static int 580*7a29d220SVladimir Oltean felix_tag_proto_setup_shared(struct dsa_switch *ds, 581*7a29d220SVladimir Oltean const struct felix_tag_proto_ops *proto_ops, 582*7a29d220SVladimir Oltean const struct felix_tag_proto_ops *old_proto_ops) 583*7a29d220SVladimir Oltean { 584*7a29d220SVladimir Oltean bool using_tag_8021q = (proto_ops == &felix_tag_8021q_proto_ops); 585*7a29d220SVladimir Oltean int err; 586*7a29d220SVladimir Oltean 587*7a29d220SVladimir Oltean err = felix_migrate_mdbs(ds, proto_ops, old_proto_ops); 588*7a29d220SVladimir Oltean if (err) 589*7a29d220SVladimir Oltean return err; 590*7a29d220SVladimir Oltean 591*7a29d220SVladimir Oltean felix_update_trapping_destinations(ds, using_tag_8021q); 592*7a29d220SVladimir Oltean 593*7a29d220SVladimir Oltean felix_migrate_host_flood(ds, proto_ops, old_proto_ops); 594*7a29d220SVladimir Oltean 595*7a29d220SVladimir Oltean return 0; 596adb3dccfSVladimir Oltean } 597adb3dccfSVladimir Oltean 598e21268efSVladimir Oltean /* This always leaves the switch in a consistent state, because although the 599e21268efSVladimir Oltean * tag_8021q setup can fail, the NPI setup can't. So either the change is made, 600e21268efSVladimir Oltean * or the restoration is guaranteed to work. 601e21268efSVladimir Oltean */ 602bacf93b0SVladimir Oltean static int felix_change_tag_protocol(struct dsa_switch *ds, 603adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 604adb3dccfSVladimir Oltean { 605*7a29d220SVladimir Oltean const struct felix_tag_proto_ops *old_proto_ops, *proto_ops; 606adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 607adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 608adb3dccfSVladimir Oltean int err; 609adb3dccfSVladimir Oltean 610*7a29d220SVladimir Oltean switch (proto) { 611*7a29d220SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 612*7a29d220SVladimir Oltean case DSA_TAG_PROTO_OCELOT: 613*7a29d220SVladimir Oltean proto_ops = &felix_tag_npi_proto_ops; 614bacf93b0SVladimir Oltean break; 615*7a29d220SVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 616*7a29d220SVladimir Oltean proto_ops = &felix_tag_8021q_proto_ops; 617*7a29d220SVladimir Oltean break; 618*7a29d220SVladimir Oltean default: 619*7a29d220SVladimir Oltean return -EPROTONOSUPPORT; 620bacf93b0SVladimir Oltean } 621bacf93b0SVladimir Oltean 622*7a29d220SVladimir Oltean old_proto_ops = felix->tag_proto_ops; 623*7a29d220SVladimir Oltean 624*7a29d220SVladimir Oltean err = proto_ops->setup(ds); 625*7a29d220SVladimir Oltean if (err) 626*7a29d220SVladimir Oltean goto setup_failed; 627*7a29d220SVladimir Oltean 628*7a29d220SVladimir Oltean err = felix_tag_proto_setup_shared(ds, proto_ops, old_proto_ops); 629*7a29d220SVladimir Oltean if (err) 630*7a29d220SVladimir Oltean goto setup_shared_failed; 631*7a29d220SVladimir Oltean 632*7a29d220SVladimir Oltean if (old_proto_ops) 633*7a29d220SVladimir Oltean old_proto_ops->teardown(ds); 634*7a29d220SVladimir Oltean 635*7a29d220SVladimir Oltean felix->tag_proto_ops = proto_ops; 636adb3dccfSVladimir Oltean felix->tag_proto = proto; 637adb3dccfSVladimir Oltean 638adb3dccfSVladimir Oltean return 0; 639*7a29d220SVladimir Oltean 640*7a29d220SVladimir Oltean setup_shared_failed: 641*7a29d220SVladimir Oltean proto_ops->teardown(ds); 642*7a29d220SVladimir Oltean setup_failed: 643*7a29d220SVladimir Oltean return err; 644adb3dccfSVladimir Oltean } 645adb3dccfSVladimir Oltean 64656051948SVladimir Oltean static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds, 6474d776482SFlorian Fainelli int port, 6484d776482SFlorian Fainelli enum dsa_tag_protocol mp) 64956051948SVladimir Oltean { 650adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 651adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 652adb3dccfSVladimir Oltean 653adb3dccfSVladimir Oltean return felix->tag_proto; 65456051948SVladimir Oltean } 65556051948SVladimir Oltean 65672c3b0c7SVladimir Oltean static void felix_port_set_host_flood(struct dsa_switch *ds, int port, 65772c3b0c7SVladimir Oltean bool uc, bool mc) 65872c3b0c7SVladimir Oltean { 65972c3b0c7SVladimir Oltean struct ocelot *ocelot = ds->priv; 66072c3b0c7SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 661*7a29d220SVladimir Oltean unsigned long mask; 66272c3b0c7SVladimir Oltean 66372c3b0c7SVladimir Oltean if (uc) 66472c3b0c7SVladimir Oltean felix->host_flood_uc_mask |= BIT(port); 66572c3b0c7SVladimir Oltean else 66672c3b0c7SVladimir Oltean felix->host_flood_uc_mask &= ~BIT(port); 66772c3b0c7SVladimir Oltean 66872c3b0c7SVladimir Oltean if (mc) 66972c3b0c7SVladimir Oltean felix->host_flood_mc_mask |= BIT(port); 67072c3b0c7SVladimir Oltean else 67172c3b0c7SVladimir Oltean felix->host_flood_mc_mask &= ~BIT(port); 67272c3b0c7SVladimir Oltean 673*7a29d220SVladimir Oltean mask = felix->tag_proto_ops->get_host_fwd_mask(ds); 674*7a29d220SVladimir Oltean felix_set_host_flood(ds, mask, !!felix->host_flood_uc_mask, 675*7a29d220SVladimir Oltean !!felix->host_flood_mc_mask, true); 67672c3b0c7SVladimir Oltean } 67772c3b0c7SVladimir Oltean 67856051948SVladimir Oltean static int felix_set_ageing_time(struct dsa_switch *ds, 67956051948SVladimir Oltean unsigned int ageing_time) 68056051948SVladimir Oltean { 68156051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 68256051948SVladimir Oltean 68356051948SVladimir Oltean ocelot_set_ageing_time(ocelot, ageing_time); 68456051948SVladimir Oltean 68556051948SVladimir Oltean return 0; 68656051948SVladimir Oltean } 68756051948SVladimir Oltean 6885cad43a5SVladimir Oltean static void felix_port_fast_age(struct dsa_switch *ds, int port) 6895cad43a5SVladimir Oltean { 6905cad43a5SVladimir Oltean struct ocelot *ocelot = ds->priv; 6915cad43a5SVladimir Oltean int err; 6925cad43a5SVladimir Oltean 6935cad43a5SVladimir Oltean err = ocelot_mact_flush(ocelot, port); 6945cad43a5SVladimir Oltean if (err) 6955cad43a5SVladimir Oltean dev_err(ds->dev, "Flushing MAC table on port %d returned %pe\n", 6965cad43a5SVladimir Oltean port, ERR_PTR(err)); 6975cad43a5SVladimir Oltean } 6985cad43a5SVladimir Oltean 69956051948SVladimir Oltean static int felix_fdb_dump(struct dsa_switch *ds, int port, 70056051948SVladimir Oltean dsa_fdb_dump_cb_t *cb, void *data) 70156051948SVladimir Oltean { 70256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 70356051948SVladimir Oltean 70456051948SVladimir Oltean return ocelot_fdb_dump(ocelot, port, cb, data); 70556051948SVladimir Oltean } 70656051948SVladimir Oltean 70756051948SVladimir Oltean static int felix_fdb_add(struct dsa_switch *ds, int port, 708c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 709c2693363SVladimir Oltean struct dsa_db db) 71056051948SVladimir Oltean { 71154c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 712e9b3ba43SVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 71356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 71456051948SVladimir Oltean 71554c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 71654c31984SVladimir Oltean return PTR_ERR(bridge_dev); 71754c31984SVladimir Oltean 718e9b3ba43SVladimir Oltean if (dsa_port_is_cpu(dp) && !bridge_dev && 7197e580490SVladimir Oltean dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) 7207e580490SVladimir Oltean return 0; 7217e580490SVladimir Oltean 722e9b3ba43SVladimir Oltean if (dsa_port_is_cpu(dp)) 723e9b3ba43SVladimir Oltean port = PGID_CPU; 724e9b3ba43SVladimir Oltean 72554c31984SVladimir Oltean return ocelot_fdb_add(ocelot, port, addr, vid, bridge_dev); 72656051948SVladimir Oltean } 72756051948SVladimir Oltean 72856051948SVladimir Oltean static int felix_fdb_del(struct dsa_switch *ds, int port, 729c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 730c2693363SVladimir Oltean struct dsa_db db) 73156051948SVladimir Oltean { 73254c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 733e9b3ba43SVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 73456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 73556051948SVladimir Oltean 73654c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 73754c31984SVladimir Oltean return PTR_ERR(bridge_dev); 73854c31984SVladimir Oltean 739e9b3ba43SVladimir Oltean if (dsa_port_is_cpu(dp) && !bridge_dev && 7407e580490SVladimir Oltean dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) 7417e580490SVladimir Oltean return 0; 7427e580490SVladimir Oltean 743e9b3ba43SVladimir Oltean if (dsa_port_is_cpu(dp)) 744e9b3ba43SVladimir Oltean port = PGID_CPU; 745e9b3ba43SVladimir Oltean 74654c31984SVladimir Oltean return ocelot_fdb_del(ocelot, port, addr, vid, bridge_dev); 74756051948SVladimir Oltean } 74856051948SVladimir Oltean 749961d8b69SVladimir Oltean static int felix_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag lag, 750c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 751c2693363SVladimir Oltean struct dsa_db db) 752961d8b69SVladimir Oltean { 75354c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 754961d8b69SVladimir Oltean struct ocelot *ocelot = ds->priv; 755961d8b69SVladimir Oltean 75654c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 75754c31984SVladimir Oltean return PTR_ERR(bridge_dev); 75854c31984SVladimir Oltean 75954c31984SVladimir Oltean return ocelot_lag_fdb_add(ocelot, lag.dev, addr, vid, bridge_dev); 760961d8b69SVladimir Oltean } 761961d8b69SVladimir Oltean 762961d8b69SVladimir Oltean static int felix_lag_fdb_del(struct dsa_switch *ds, struct dsa_lag lag, 763c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 764c2693363SVladimir Oltean struct dsa_db db) 765961d8b69SVladimir Oltean { 76654c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 767961d8b69SVladimir Oltean struct ocelot *ocelot = ds->priv; 768961d8b69SVladimir Oltean 76954c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 77054c31984SVladimir Oltean return PTR_ERR(bridge_dev); 77154c31984SVladimir Oltean 77254c31984SVladimir Oltean return ocelot_lag_fdb_del(ocelot, lag.dev, addr, vid, bridge_dev); 773961d8b69SVladimir Oltean } 774961d8b69SVladimir Oltean 775a52b2da7SVladimir Oltean static int felix_mdb_add(struct dsa_switch *ds, int port, 776c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 777c2693363SVladimir Oltean struct dsa_db db) 778209edf95SVladimir Oltean { 77954c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 780209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 781209edf95SVladimir Oltean 78254c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 78354c31984SVladimir Oltean return PTR_ERR(bridge_dev); 78454c31984SVladimir Oltean 7857e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 7867e580490SVladimir Oltean dsa_mdb_present_in_other_db(ds, port, mdb, db)) 7877e580490SVladimir Oltean return 0; 7887e580490SVladimir Oltean 7890ddf83cdSVladimir Oltean if (port == ocelot->npi) 7900ddf83cdSVladimir Oltean port = ocelot->num_phys_ports; 7910ddf83cdSVladimir Oltean 79254c31984SVladimir Oltean return ocelot_port_mdb_add(ocelot, port, mdb, bridge_dev); 793209edf95SVladimir Oltean } 794209edf95SVladimir Oltean 795209edf95SVladimir Oltean static int felix_mdb_del(struct dsa_switch *ds, int port, 796c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 797c2693363SVladimir Oltean struct dsa_db db) 798209edf95SVladimir Oltean { 79954c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 800209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 801209edf95SVladimir Oltean 80254c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 80354c31984SVladimir Oltean return PTR_ERR(bridge_dev); 80454c31984SVladimir Oltean 8057e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 8067e580490SVladimir Oltean dsa_mdb_present_in_other_db(ds, port, mdb, db)) 8077e580490SVladimir Oltean return 0; 8087e580490SVladimir Oltean 8090ddf83cdSVladimir Oltean if (port == ocelot->npi) 8100ddf83cdSVladimir Oltean port = ocelot->num_phys_ports; 8110ddf83cdSVladimir Oltean 81254c31984SVladimir Oltean return ocelot_port_mdb_del(ocelot, port, mdb, bridge_dev); 813209edf95SVladimir Oltean } 814209edf95SVladimir Oltean 81556051948SVladimir Oltean static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, 81656051948SVladimir Oltean u8 state) 81756051948SVladimir Oltean { 81856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 81956051948SVladimir Oltean 82056051948SVladimir Oltean return ocelot_bridge_stp_state_set(ocelot, port, state); 82156051948SVladimir Oltean } 82256051948SVladimir Oltean 823421741eaSVladimir Oltean static int felix_pre_bridge_flags(struct dsa_switch *ds, int port, 824421741eaSVladimir Oltean struct switchdev_brport_flags val, 825421741eaSVladimir Oltean struct netlink_ext_ack *extack) 826421741eaSVladimir Oltean { 827421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 828421741eaSVladimir Oltean 829421741eaSVladimir Oltean return ocelot_port_pre_bridge_flags(ocelot, port, val); 830421741eaSVladimir Oltean } 831421741eaSVladimir Oltean 832421741eaSVladimir Oltean static int felix_bridge_flags(struct dsa_switch *ds, int port, 833421741eaSVladimir Oltean struct switchdev_brport_flags val, 834421741eaSVladimir Oltean struct netlink_ext_ack *extack) 835421741eaSVladimir Oltean { 836421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 837421741eaSVladimir Oltean 838910ee6ccSVladimir Oltean if (port == ocelot->npi) 839910ee6ccSVladimir Oltean port = ocelot->num_phys_ports; 840910ee6ccSVladimir Oltean 841421741eaSVladimir Oltean ocelot_port_bridge_flags(ocelot, port, val); 842421741eaSVladimir Oltean 843421741eaSVladimir Oltean return 0; 844421741eaSVladimir Oltean } 845421741eaSVladimir Oltean 84656051948SVladimir Oltean static int felix_bridge_join(struct dsa_switch *ds, int port, 84706b9cce4SVladimir Oltean struct dsa_bridge bridge, bool *tx_fwd_offload, 84806b9cce4SVladimir Oltean struct netlink_ext_ack *extack) 84956051948SVladimir Oltean { 85056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 85156051948SVladimir Oltean 85254c31984SVladimir Oltean return ocelot_port_bridge_join(ocelot, port, bridge.dev, bridge.num, 85354c31984SVladimir Oltean extack); 85456051948SVladimir Oltean } 85556051948SVladimir Oltean 85656051948SVladimir Oltean static void felix_bridge_leave(struct dsa_switch *ds, int port, 857d3eed0e5SVladimir Oltean struct dsa_bridge bridge) 85856051948SVladimir Oltean { 85956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 86056051948SVladimir Oltean 861d3eed0e5SVladimir Oltean ocelot_port_bridge_leave(ocelot, port, bridge.dev); 86256051948SVladimir Oltean } 86356051948SVladimir Oltean 8648fe6832eSVladimir Oltean static int felix_lag_join(struct dsa_switch *ds, int port, 865dedd6a00SVladimir Oltean struct dsa_lag lag, 8668fe6832eSVladimir Oltean struct netdev_lag_upper_info *info) 8678fe6832eSVladimir Oltean { 8688fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8698fe6832eSVladimir Oltean 870dedd6a00SVladimir Oltean return ocelot_port_lag_join(ocelot, port, lag.dev, info); 8718fe6832eSVladimir Oltean } 8728fe6832eSVladimir Oltean 8738fe6832eSVladimir Oltean static int felix_lag_leave(struct dsa_switch *ds, int port, 874dedd6a00SVladimir Oltean struct dsa_lag lag) 8758fe6832eSVladimir Oltean { 8768fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8778fe6832eSVladimir Oltean 878dedd6a00SVladimir Oltean ocelot_port_lag_leave(ocelot, port, lag.dev); 8798fe6832eSVladimir Oltean 8808fe6832eSVladimir Oltean return 0; 8818fe6832eSVladimir Oltean } 8828fe6832eSVladimir Oltean 8838fe6832eSVladimir Oltean static int felix_lag_change(struct dsa_switch *ds, int port) 8848fe6832eSVladimir Oltean { 8858fe6832eSVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 8868fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8878fe6832eSVladimir Oltean 8888fe6832eSVladimir Oltean ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); 8898fe6832eSVladimir Oltean 8908fe6832eSVladimir Oltean return 0; 8918fe6832eSVladimir Oltean } 8928fe6832eSVladimir Oltean 89356051948SVladimir Oltean static int felix_vlan_prepare(struct dsa_switch *ds, int port, 89401af940eSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 89501af940eSVladimir Oltean struct netlink_ext_ack *extack) 89656051948SVladimir Oltean { 8972f0402feSVladimir Oltean struct ocelot *ocelot = ds->priv; 898b7a9e0daSVladimir Oltean u16 flags = vlan->flags; 8992f0402feSVladimir Oltean 9009a720680SVladimir Oltean /* Ocelot switches copy frames as-is to the CPU, so the flags: 9019a720680SVladimir Oltean * egress-untagged or not, pvid or not, make no difference. This 9029a720680SVladimir Oltean * behavior is already better than what DSA just tries to approximate 9039a720680SVladimir Oltean * when it installs the VLAN with the same flags on the CPU port. 9049a720680SVladimir Oltean * Just accept any configuration, and don't let ocelot deny installing 9059a720680SVladimir Oltean * multiple native VLANs on the NPI port, because the switch doesn't 9069a720680SVladimir Oltean * look at the port tag settings towards the NPI interface anyway. 9079a720680SVladimir Oltean */ 9089a720680SVladimir Oltean if (port == ocelot->npi) 9099a720680SVladimir Oltean return 0; 9109a720680SVladimir Oltean 911b7a9e0daSVladimir Oltean return ocelot_vlan_prepare(ocelot, port, vlan->vid, 9122f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 91301af940eSVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED, 91401af940eSVladimir Oltean extack); 91556051948SVladimir Oltean } 91656051948SVladimir Oltean 91789153ed6SVladimir Oltean static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled, 91889153ed6SVladimir Oltean struct netlink_ext_ack *extack) 91956051948SVladimir Oltean { 92056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 92156051948SVladimir Oltean 9223b95d1b2SVladimir Oltean return ocelot_port_vlan_filtering(ocelot, port, enabled, extack); 92356051948SVladimir Oltean } 92456051948SVladimir Oltean 9251958d581SVladimir Oltean static int felix_vlan_add(struct dsa_switch *ds, int port, 92631046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 92731046a5fSVladimir Oltean struct netlink_ext_ack *extack) 92856051948SVladimir Oltean { 92956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 930183be6f9SVladimir Oltean u16 flags = vlan->flags; 9311958d581SVladimir Oltean int err; 93256051948SVladimir Oltean 93301af940eSVladimir Oltean err = felix_vlan_prepare(ds, port, vlan, extack); 9341958d581SVladimir Oltean if (err) 9351958d581SVladimir Oltean return err; 9361958d581SVladimir Oltean 9371958d581SVladimir Oltean return ocelot_vlan_add(ocelot, port, vlan->vid, 938183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 939183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 94056051948SVladimir Oltean } 94156051948SVladimir Oltean 94256051948SVladimir Oltean static int felix_vlan_del(struct dsa_switch *ds, int port, 94356051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 94456051948SVladimir Oltean { 94556051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 94656051948SVladimir Oltean 947b7a9e0daSVladimir Oltean return ocelot_vlan_del(ocelot, port, vlan->vid); 94856051948SVladimir Oltean } 94956051948SVladimir Oltean 95079fda660SRussell King (Oracle) static void felix_phylink_get_caps(struct dsa_switch *ds, int port, 95179fda660SRussell King (Oracle) struct phylink_config *config) 95279fda660SRussell King (Oracle) { 95379fda660SRussell King (Oracle) struct ocelot *ocelot = ds->priv; 95479fda660SRussell King (Oracle) 955f6f04c02SRussell King (Oracle) /* This driver does not make use of the speed, duplex, pause or the 956f6f04c02SRussell King (Oracle) * advertisement in its mac_config, so it is safe to mark this driver 957f6f04c02SRussell King (Oracle) * as non-legacy. 958f6f04c02SRussell King (Oracle) */ 959f6f04c02SRussell King (Oracle) config->legacy_pre_march2020 = false; 960f6f04c02SRussell King (Oracle) 96179fda660SRussell King (Oracle) __set_bit(ocelot->ports[port]->phy_mode, 96279fda660SRussell King (Oracle) config->supported_interfaces); 96379fda660SRussell King (Oracle) } 96479fda660SRussell King (Oracle) 965bdeced75SVladimir Oltean static void felix_phylink_validate(struct dsa_switch *ds, int port, 966bdeced75SVladimir Oltean unsigned long *supported, 967bdeced75SVladimir Oltean struct phylink_link_state *state) 968bdeced75SVladimir Oltean { 969bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 970375e1314SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 971bdeced75SVladimir Oltean 972375e1314SVladimir Oltean if (felix->info->phylink_validate) 973375e1314SVladimir Oltean felix->info->phylink_validate(ocelot, port, supported, state); 974bdeced75SVladimir Oltean } 975bdeced75SVladimir Oltean 976864ba485SRussell King (Oracle) static struct phylink_pcs *felix_phylink_mac_select_pcs(struct dsa_switch *ds, 977864ba485SRussell King (Oracle) int port, 978864ba485SRussell King (Oracle) phy_interface_t iface) 979bdeced75SVladimir Oltean { 980bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 981bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 982864ba485SRussell King (Oracle) struct phylink_pcs *pcs = NULL; 983bdeced75SVladimir Oltean 98449af6a76SColin Foster if (felix->pcs && felix->pcs[port]) 985864ba485SRussell King (Oracle) pcs = felix->pcs[port]; 986864ba485SRussell King (Oracle) 987864ba485SRussell King (Oracle) return pcs; 988bdeced75SVladimir Oltean } 989bdeced75SVladimir Oltean 990bdeced75SVladimir Oltean static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, 991bdeced75SVladimir Oltean unsigned int link_an_mode, 992bdeced75SVladimir Oltean phy_interface_t interface) 993bdeced75SVladimir Oltean { 994bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 995bdeced75SVladimir Oltean 996e6e12df6SVladimir Oltean ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface, 997e6e12df6SVladimir Oltean FELIX_MAC_QUIRKS); 998bdeced75SVladimir Oltean } 999bdeced75SVladimir Oltean 1000bdeced75SVladimir Oltean static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, 1001bdeced75SVladimir Oltean unsigned int link_an_mode, 1002bdeced75SVladimir Oltean phy_interface_t interface, 10035b502a7bSRussell King struct phy_device *phydev, 10045b502a7bSRussell King int speed, int duplex, 10055b502a7bSRussell King bool tx_pause, bool rx_pause) 1006bdeced75SVladimir Oltean { 1007bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 10087e14a2dcSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1009bdeced75SVladimir Oltean 1010e6e12df6SVladimir Oltean ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode, 1011e6e12df6SVladimir Oltean interface, speed, duplex, tx_pause, rx_pause, 1012e6e12df6SVladimir Oltean FELIX_MAC_QUIRKS); 10137e14a2dcSVladimir Oltean 10147e14a2dcSVladimir Oltean if (felix->info->port_sched_speed_set) 10157e14a2dcSVladimir Oltean felix->info->port_sched_speed_set(ocelot, port, speed); 1016bdeced75SVladimir Oltean } 1017bdeced75SVladimir Oltean 1018bd2b3161SXiaoliang Yang static void felix_port_qos_map_init(struct ocelot *ocelot, int port) 1019bd2b3161SXiaoliang Yang { 1020bd2b3161SXiaoliang Yang int i; 1021bd2b3161SXiaoliang Yang 1022bd2b3161SXiaoliang Yang ocelot_rmw_gix(ocelot, 1023bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 1024bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 1025bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG, 1026bd2b3161SXiaoliang Yang port); 1027bd2b3161SXiaoliang Yang 102870d39a6eSVladimir Oltean for (i = 0; i < OCELOT_NUM_TC * 2; i++) { 1029bd2b3161SXiaoliang Yang ocelot_rmw_ix(ocelot, 1030bd2b3161SXiaoliang Yang (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) | 1031bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i), 1032bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL | 1033bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M, 1034bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP, 1035bd2b3161SXiaoliang Yang port, i); 1036bd2b3161SXiaoliang Yang } 1037bd2b3161SXiaoliang Yang } 1038bd2b3161SXiaoliang Yang 103956051948SVladimir Oltean static void felix_get_strings(struct dsa_switch *ds, int port, 104056051948SVladimir Oltean u32 stringset, u8 *data) 104156051948SVladimir Oltean { 104256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 104356051948SVladimir Oltean 104456051948SVladimir Oltean return ocelot_get_strings(ocelot, port, stringset, data); 104556051948SVladimir Oltean } 104656051948SVladimir Oltean 104756051948SVladimir Oltean static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) 104856051948SVladimir Oltean { 104956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 105056051948SVladimir Oltean 105156051948SVladimir Oltean ocelot_get_ethtool_stats(ocelot, port, data); 105256051948SVladimir Oltean } 105356051948SVladimir Oltean 105456051948SVladimir Oltean static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) 105556051948SVladimir Oltean { 105656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 105756051948SVladimir Oltean 105856051948SVladimir Oltean return ocelot_get_sset_count(ocelot, port, sset); 105956051948SVladimir Oltean } 106056051948SVladimir Oltean 106156051948SVladimir Oltean static int felix_get_ts_info(struct dsa_switch *ds, int port, 106256051948SVladimir Oltean struct ethtool_ts_info *info) 106356051948SVladimir Oltean { 106456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 106556051948SVladimir Oltean 106656051948SVladimir Oltean return ocelot_get_ts_info(ocelot, port, info); 106756051948SVladimir Oltean } 106856051948SVladimir Oltean 1069acf242fcSColin Foster static const u32 felix_phy_match_table[PHY_INTERFACE_MODE_MAX] = { 1070acf242fcSColin Foster [PHY_INTERFACE_MODE_INTERNAL] = OCELOT_PORT_MODE_INTERNAL, 1071acf242fcSColin Foster [PHY_INTERFACE_MODE_SGMII] = OCELOT_PORT_MODE_SGMII, 1072acf242fcSColin Foster [PHY_INTERFACE_MODE_QSGMII] = OCELOT_PORT_MODE_QSGMII, 1073acf242fcSColin Foster [PHY_INTERFACE_MODE_USXGMII] = OCELOT_PORT_MODE_USXGMII, 107411ecf341SVladimir Oltean [PHY_INTERFACE_MODE_1000BASEX] = OCELOT_PORT_MODE_1000BASEX, 1075acf242fcSColin Foster [PHY_INTERFACE_MODE_2500BASEX] = OCELOT_PORT_MODE_2500BASEX, 1076acf242fcSColin Foster }; 1077acf242fcSColin Foster 1078acf242fcSColin Foster static int felix_validate_phy_mode(struct felix *felix, int port, 1079acf242fcSColin Foster phy_interface_t phy_mode) 1080acf242fcSColin Foster { 1081acf242fcSColin Foster u32 modes = felix->info->port_modes[port]; 1082acf242fcSColin Foster 1083acf242fcSColin Foster if (felix_phy_match_table[phy_mode] & modes) 1084acf242fcSColin Foster return 0; 1085acf242fcSColin Foster return -EOPNOTSUPP; 1086acf242fcSColin Foster } 1087acf242fcSColin Foster 1088bdeced75SVladimir Oltean static int felix_parse_ports_node(struct felix *felix, 1089bdeced75SVladimir Oltean struct device_node *ports_node, 1090bdeced75SVladimir Oltean phy_interface_t *port_phy_modes) 1091bdeced75SVladimir Oltean { 1092bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 1093bdeced75SVladimir Oltean struct device_node *child; 1094bdeced75SVladimir Oltean 109537fe45adSVladimir Oltean for_each_available_child_of_node(ports_node, child) { 1096bdeced75SVladimir Oltean phy_interface_t phy_mode; 1097bdeced75SVladimir Oltean u32 port; 1098bdeced75SVladimir Oltean int err; 1099bdeced75SVladimir Oltean 1100bdeced75SVladimir Oltean /* Get switch port number from DT */ 1101bdeced75SVladimir Oltean if (of_property_read_u32(child, "reg", &port) < 0) { 1102bdeced75SVladimir Oltean dev_err(dev, "Port number not defined in device tree " 1103bdeced75SVladimir Oltean "(property \"reg\")\n"); 1104bdeced75SVladimir Oltean of_node_put(child); 1105bdeced75SVladimir Oltean return -ENODEV; 1106bdeced75SVladimir Oltean } 1107bdeced75SVladimir Oltean 1108bdeced75SVladimir Oltean /* Get PHY mode from DT */ 1109bdeced75SVladimir Oltean err = of_get_phy_mode(child, &phy_mode); 1110bdeced75SVladimir Oltean if (err) { 1111bdeced75SVladimir Oltean dev_err(dev, "Failed to read phy-mode or " 1112bdeced75SVladimir Oltean "phy-interface-type property for port %d\n", 1113bdeced75SVladimir Oltean port); 1114bdeced75SVladimir Oltean of_node_put(child); 1115bdeced75SVladimir Oltean return -ENODEV; 1116bdeced75SVladimir Oltean } 1117bdeced75SVladimir Oltean 1118acf242fcSColin Foster err = felix_validate_phy_mode(felix, port, phy_mode); 1119bdeced75SVladimir Oltean if (err < 0) { 1120bdeced75SVladimir Oltean dev_err(dev, "Unsupported PHY mode %s on port %d\n", 1121bdeced75SVladimir Oltean phy_modes(phy_mode), port); 112259ebb430SSumera Priyadarsini of_node_put(child); 1123bdeced75SVladimir Oltean return err; 1124bdeced75SVladimir Oltean } 1125bdeced75SVladimir Oltean 1126bdeced75SVladimir Oltean port_phy_modes[port] = phy_mode; 1127bdeced75SVladimir Oltean } 1128bdeced75SVladimir Oltean 1129bdeced75SVladimir Oltean return 0; 1130bdeced75SVladimir Oltean } 1131bdeced75SVladimir Oltean 1132bdeced75SVladimir Oltean static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes) 1133bdeced75SVladimir Oltean { 1134bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 1135bdeced75SVladimir Oltean struct device_node *switch_node; 1136bdeced75SVladimir Oltean struct device_node *ports_node; 1137bdeced75SVladimir Oltean int err; 1138bdeced75SVladimir Oltean 1139bdeced75SVladimir Oltean switch_node = dev->of_node; 1140bdeced75SVladimir Oltean 1141bdeced75SVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ports"); 1142abecbfcdSVladimir Oltean if (!ports_node) 1143abecbfcdSVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ethernet-ports"); 1144bdeced75SVladimir Oltean if (!ports_node) { 1145abecbfcdSVladimir Oltean dev_err(dev, "Incorrect bindings: absent \"ports\" or \"ethernet-ports\" node\n"); 1146bdeced75SVladimir Oltean return -ENODEV; 1147bdeced75SVladimir Oltean } 1148bdeced75SVladimir Oltean 1149bdeced75SVladimir Oltean err = felix_parse_ports_node(felix, ports_node, port_phy_modes); 1150bdeced75SVladimir Oltean of_node_put(ports_node); 1151bdeced75SVladimir Oltean 1152bdeced75SVladimir Oltean return err; 1153bdeced75SVladimir Oltean } 1154bdeced75SVladimir Oltean 115556051948SVladimir Oltean static int felix_init_structs(struct felix *felix, int num_phys_ports) 115656051948SVladimir Oltean { 115756051948SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 1158bdeced75SVladimir Oltean phy_interface_t *port_phy_modes; 1159b4024c9eSClaudiu Manoil struct resource res; 116056051948SVladimir Oltean int port, i, err; 116156051948SVladimir Oltean 116256051948SVladimir Oltean ocelot->num_phys_ports = num_phys_ports; 116356051948SVladimir Oltean ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, 116456051948SVladimir Oltean sizeof(struct ocelot_port *), GFP_KERNEL); 116556051948SVladimir Oltean if (!ocelot->ports) 116656051948SVladimir Oltean return -ENOMEM; 116756051948SVladimir Oltean 116856051948SVladimir Oltean ocelot->map = felix->info->map; 116956051948SVladimir Oltean ocelot->stats_layout = felix->info->stats_layout; 117021ce7f3eSVladimir Oltean ocelot->num_mact_rows = felix->info->num_mact_rows; 117107d985eeSVladimir Oltean ocelot->vcap = felix->info->vcap; 117277043c37SXiaoliang Yang ocelot->vcap_pol.base = felix->info->vcap_pol_base; 117377043c37SXiaoliang Yang ocelot->vcap_pol.max = felix->info->vcap_pol_max; 117477043c37SXiaoliang Yang ocelot->vcap_pol.base2 = felix->info->vcap_pol_base2; 117577043c37SXiaoliang Yang ocelot->vcap_pol.max2 = felix->info->vcap_pol_max2; 117656051948SVladimir Oltean ocelot->ops = felix->info->ops; 1177cacea62fSVladimir Oltean ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT; 1178cacea62fSVladimir Oltean ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT; 1179f59fd9caSVladimir Oltean ocelot->devlink = felix->ds->devlink; 118056051948SVladimir Oltean 1181bdeced75SVladimir Oltean port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t), 1182bdeced75SVladimir Oltean GFP_KERNEL); 1183bdeced75SVladimir Oltean if (!port_phy_modes) 1184bdeced75SVladimir Oltean return -ENOMEM; 1185bdeced75SVladimir Oltean 1186bdeced75SVladimir Oltean err = felix_parse_dt(felix, port_phy_modes); 1187bdeced75SVladimir Oltean if (err) { 1188bdeced75SVladimir Oltean kfree(port_phy_modes); 1189bdeced75SVladimir Oltean return err; 1190bdeced75SVladimir Oltean } 1191bdeced75SVladimir Oltean 119256051948SVladimir Oltean for (i = 0; i < TARGET_MAX; i++) { 119356051948SVladimir Oltean struct regmap *target; 119456051948SVladimir Oltean 119556051948SVladimir Oltean if (!felix->info->target_io_res[i].name) 119656051948SVladimir Oltean continue; 119756051948SVladimir Oltean 1198b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->target_io_res[i], sizeof(res)); 1199b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1200375e1314SVladimir Oltean res.start += felix->switch_base; 1201375e1314SVladimir Oltean res.end += felix->switch_base; 120256051948SVladimir Oltean 1203242bd0c1SColin Foster target = felix->info->init_regmap(ocelot, &res); 120456051948SVladimir Oltean if (IS_ERR(target)) { 120556051948SVladimir Oltean dev_err(ocelot->dev, 120656051948SVladimir Oltean "Failed to map device memory space\n"); 1207bdeced75SVladimir Oltean kfree(port_phy_modes); 120856051948SVladimir Oltean return PTR_ERR(target); 120956051948SVladimir Oltean } 121056051948SVladimir Oltean 121156051948SVladimir Oltean ocelot->targets[i] = target; 121256051948SVladimir Oltean } 121356051948SVladimir Oltean 121456051948SVladimir Oltean err = ocelot_regfields_init(ocelot, felix->info->regfields); 121556051948SVladimir Oltean if (err) { 121656051948SVladimir Oltean dev_err(ocelot->dev, "failed to init reg fields map\n"); 1217bdeced75SVladimir Oltean kfree(port_phy_modes); 121856051948SVladimir Oltean return err; 121956051948SVladimir Oltean } 122056051948SVladimir Oltean 122156051948SVladimir Oltean for (port = 0; port < num_phys_ports; port++) { 122256051948SVladimir Oltean struct ocelot_port *ocelot_port; 122391c724cfSVladimir Oltean struct regmap *target; 122456051948SVladimir Oltean 122556051948SVladimir Oltean ocelot_port = devm_kzalloc(ocelot->dev, 122656051948SVladimir Oltean sizeof(struct ocelot_port), 122756051948SVladimir Oltean GFP_KERNEL); 122856051948SVladimir Oltean if (!ocelot_port) { 122956051948SVladimir Oltean dev_err(ocelot->dev, 123056051948SVladimir Oltean "failed to allocate port memory\n"); 1231bdeced75SVladimir Oltean kfree(port_phy_modes); 123256051948SVladimir Oltean return -ENOMEM; 123356051948SVladimir Oltean } 123456051948SVladimir Oltean 1235b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->port_io_res[port], sizeof(res)); 1236b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1237375e1314SVladimir Oltean res.start += felix->switch_base; 1238375e1314SVladimir Oltean res.end += felix->switch_base; 123956051948SVladimir Oltean 1240242bd0c1SColin Foster target = felix->info->init_regmap(ocelot, &res); 124191c724cfSVladimir Oltean if (IS_ERR(target)) { 124256051948SVladimir Oltean dev_err(ocelot->dev, 124391c724cfSVladimir Oltean "Failed to map memory space for port %d\n", 124491c724cfSVladimir Oltean port); 1245bdeced75SVladimir Oltean kfree(port_phy_modes); 124691c724cfSVladimir Oltean return PTR_ERR(target); 124756051948SVladimir Oltean } 124856051948SVladimir Oltean 1249bdeced75SVladimir Oltean ocelot_port->phy_mode = port_phy_modes[port]; 125056051948SVladimir Oltean ocelot_port->ocelot = ocelot; 125191c724cfSVladimir Oltean ocelot_port->target = target; 125256051948SVladimir Oltean ocelot->ports[port] = ocelot_port; 125356051948SVladimir Oltean } 125456051948SVladimir Oltean 1255bdeced75SVladimir Oltean kfree(port_phy_modes); 1256bdeced75SVladimir Oltean 1257bdeced75SVladimir Oltean if (felix->info->mdio_bus_alloc) { 1258bdeced75SVladimir Oltean err = felix->info->mdio_bus_alloc(ocelot); 1259bdeced75SVladimir Oltean if (err < 0) 1260bdeced75SVladimir Oltean return err; 1261bdeced75SVladimir Oltean } 1262bdeced75SVladimir Oltean 126356051948SVladimir Oltean return 0; 126456051948SVladimir Oltean } 126556051948SVladimir Oltean 12661328a883SVladimir Oltean static void ocelot_port_purge_txtstamp_skb(struct ocelot *ocelot, int port, 12671328a883SVladimir Oltean struct sk_buff *skb) 12681328a883SVladimir Oltean { 12691328a883SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 12701328a883SVladimir Oltean struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone; 12711328a883SVladimir Oltean struct sk_buff *skb_match = NULL, *skb_tmp; 12721328a883SVladimir Oltean unsigned long flags; 12731328a883SVladimir Oltean 12741328a883SVladimir Oltean if (!clone) 12751328a883SVladimir Oltean return; 12761328a883SVladimir Oltean 12771328a883SVladimir Oltean spin_lock_irqsave(&ocelot_port->tx_skbs.lock, flags); 12781328a883SVladimir Oltean 12791328a883SVladimir Oltean skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) { 12801328a883SVladimir Oltean if (skb != clone) 12811328a883SVladimir Oltean continue; 12821328a883SVladimir Oltean __skb_unlink(skb, &ocelot_port->tx_skbs); 12831328a883SVladimir Oltean skb_match = skb; 12841328a883SVladimir Oltean break; 12851328a883SVladimir Oltean } 12861328a883SVladimir Oltean 12871328a883SVladimir Oltean spin_unlock_irqrestore(&ocelot_port->tx_skbs.lock, flags); 12881328a883SVladimir Oltean 12891328a883SVladimir Oltean WARN_ONCE(!skb_match, 12901328a883SVladimir Oltean "Could not find skb clone in TX timestamping list\n"); 12911328a883SVladimir Oltean } 12921328a883SVladimir Oltean 129349f885b2SVladimir Oltean #define work_to_xmit_work(w) \ 129449f885b2SVladimir Oltean container_of((w), struct felix_deferred_xmit_work, work) 129549f885b2SVladimir Oltean 129649f885b2SVladimir Oltean static void felix_port_deferred_xmit(struct kthread_work *work) 129749f885b2SVladimir Oltean { 129849f885b2SVladimir Oltean struct felix_deferred_xmit_work *xmit_work = work_to_xmit_work(work); 129949f885b2SVladimir Oltean struct dsa_switch *ds = xmit_work->dp->ds; 130049f885b2SVladimir Oltean struct sk_buff *skb = xmit_work->skb; 130149f885b2SVladimir Oltean u32 rew_op = ocelot_ptp_rew_op(skb); 130249f885b2SVladimir Oltean struct ocelot *ocelot = ds->priv; 130349f885b2SVladimir Oltean int port = xmit_work->dp->index; 130449f885b2SVladimir Oltean int retries = 10; 130549f885b2SVladimir Oltean 130649f885b2SVladimir Oltean do { 130749f885b2SVladimir Oltean if (ocelot_can_inject(ocelot, 0)) 130849f885b2SVladimir Oltean break; 130949f885b2SVladimir Oltean 131049f885b2SVladimir Oltean cpu_relax(); 131149f885b2SVladimir Oltean } while (--retries); 131249f885b2SVladimir Oltean 131349f885b2SVladimir Oltean if (!retries) { 131449f885b2SVladimir Oltean dev_err(ocelot->dev, "port %d failed to inject skb\n", 131549f885b2SVladimir Oltean port); 13161328a883SVladimir Oltean ocelot_port_purge_txtstamp_skb(ocelot, port, skb); 131749f885b2SVladimir Oltean kfree_skb(skb); 131849f885b2SVladimir Oltean return; 131949f885b2SVladimir Oltean } 132049f885b2SVladimir Oltean 132149f885b2SVladimir Oltean ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb); 132249f885b2SVladimir Oltean 132349f885b2SVladimir Oltean consume_skb(skb); 132449f885b2SVladimir Oltean kfree(xmit_work); 132549f885b2SVladimir Oltean } 132649f885b2SVladimir Oltean 132735d97680SVladimir Oltean static int felix_connect_tag_protocol(struct dsa_switch *ds, 132835d97680SVladimir Oltean enum dsa_tag_protocol proto) 132949f885b2SVladimir Oltean { 133035d97680SVladimir Oltean struct ocelot_8021q_tagger_data *tagger_data; 133149f885b2SVladimir Oltean 133235d97680SVladimir Oltean switch (proto) { 133335d97680SVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 133435d97680SVladimir Oltean tagger_data = ocelot_8021q_tagger_data(ds); 133535d97680SVladimir Oltean tagger_data->xmit_work_fn = felix_port_deferred_xmit; 133649f885b2SVladimir Oltean return 0; 133735d97680SVladimir Oltean case DSA_TAG_PROTO_OCELOT: 133835d97680SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 133949f885b2SVladimir Oltean return 0; 134035d97680SVladimir Oltean default: 134135d97680SVladimir Oltean return -EPROTONOSUPPORT; 134249f885b2SVladimir Oltean } 134349f885b2SVladimir Oltean } 134449f885b2SVladimir Oltean 134556051948SVladimir Oltean /* Hardware initialization done here so that we can allocate structures with 134656051948SVladimir Oltean * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing 134756051948SVladimir Oltean * us to allocate structures twice (leak memory) and map PCI memory twice 134856051948SVladimir Oltean * (which will not work). 134956051948SVladimir Oltean */ 135056051948SVladimir Oltean static int felix_setup(struct dsa_switch *ds) 135156051948SVladimir Oltean { 135256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 135356051948SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 13542960bb14SVladimir Oltean struct dsa_port *dp; 13552960bb14SVladimir Oltean int err; 135656051948SVladimir Oltean 135756051948SVladimir Oltean err = felix_init_structs(felix, ds->num_ports); 135856051948SVladimir Oltean if (err) 135956051948SVladimir Oltean return err; 136056051948SVladimir Oltean 1361d1cc0e93SVladimir Oltean err = ocelot_init(ocelot); 1362d1cc0e93SVladimir Oltean if (err) 13636b73b7c9SVladimir Oltean goto out_mdiobus_free; 1364d1cc0e93SVladimir Oltean 13652b49d128SYangbo Lu if (ocelot->ptp) { 13662ac7c6c5SVladimir Oltean err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); 13672b49d128SYangbo Lu if (err) { 13682b49d128SYangbo Lu dev_err(ocelot->dev, 13692b49d128SYangbo Lu "Timestamp initialization failed\n"); 13702b49d128SYangbo Lu ocelot->ptp = 0; 13712b49d128SYangbo Lu } 13722b49d128SYangbo Lu } 137356051948SVladimir Oltean 13742960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 13752960bb14SVladimir Oltean ocelot_init_port(ocelot, dp->index); 1376bd2b3161SXiaoliang Yang 1377bd2b3161SXiaoliang Yang /* Set the default QoS Classification based on PCP and DEI 1378bd2b3161SXiaoliang Yang * bits of vlan tag. 1379bd2b3161SXiaoliang Yang */ 13802960bb14SVladimir Oltean felix_port_qos_map_init(ocelot, dp->index); 138156051948SVladimir Oltean } 138256051948SVladimir Oltean 1383f59fd9caSVladimir Oltean err = ocelot_devlink_sb_register(ocelot); 1384f59fd9caSVladimir Oltean if (err) 13856b73b7c9SVladimir Oltean goto out_deinit_ports; 1386f59fd9caSVladimir Oltean 1387*7a29d220SVladimir Oltean /* The initial tag protocol is NPI which won't fail during initial 1388*7a29d220SVladimir Oltean * setup, there's no real point in checking for errors. 13891cf3299bSVladimir Oltean */ 1390*7a29d220SVladimir Oltean felix_change_tag_protocol(ds, felix->tag_proto); 13911cf3299bSVladimir Oltean 13920b912fc9SVladimir Oltean ds->mtu_enforcement_ingress = true; 1393c54913c1SVladimir Oltean ds->assisted_learning_on_cpu_port = true; 139454c31984SVladimir Oltean ds->fdb_isolation = true; 139554c31984SVladimir Oltean ds->max_num_bridges = ds->num_ports; 1396bdeced75SVladimir Oltean 139756051948SVladimir Oltean return 0; 13986b73b7c9SVladimir Oltean 13996b73b7c9SVladimir Oltean out_deinit_ports: 14002960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) 14012960bb14SVladimir Oltean ocelot_deinit_port(ocelot, dp->index); 14026b73b7c9SVladimir Oltean 14036b73b7c9SVladimir Oltean ocelot_deinit_timestamp(ocelot); 14046b73b7c9SVladimir Oltean ocelot_deinit(ocelot); 14056b73b7c9SVladimir Oltean 14066b73b7c9SVladimir Oltean out_mdiobus_free: 14076b73b7c9SVladimir Oltean if (felix->info->mdio_bus_free) 14086b73b7c9SVladimir Oltean felix->info->mdio_bus_free(ocelot); 14096b73b7c9SVladimir Oltean 14106b73b7c9SVladimir Oltean return err; 141156051948SVladimir Oltean } 141256051948SVladimir Oltean 141356051948SVladimir Oltean static void felix_teardown(struct dsa_switch *ds) 141456051948SVladimir Oltean { 141556051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 1416bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 14172960bb14SVladimir Oltean struct dsa_port *dp; 1418bdeced75SVladimir Oltean 1419*7a29d220SVladimir Oltean if (felix->tag_proto_ops) 1420*7a29d220SVladimir Oltean felix->tag_proto_ops->teardown(ds); 1421adb3dccfSVladimir Oltean 14222960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) 14232960bb14SVladimir Oltean ocelot_deinit_port(ocelot, dp->index); 1424d19741b0SVladimir Oltean 142549f885b2SVladimir Oltean ocelot_devlink_sb_unregister(ocelot); 142649f885b2SVladimir Oltean ocelot_deinit_timestamp(ocelot); 142749f885b2SVladimir Oltean ocelot_deinit(ocelot); 142849f885b2SVladimir Oltean 1429d19741b0SVladimir Oltean if (felix->info->mdio_bus_free) 1430d19741b0SVladimir Oltean felix->info->mdio_bus_free(ocelot); 143156051948SVladimir Oltean } 143256051948SVladimir Oltean 1433c0bcf537SYangbo Lu static int felix_hwtstamp_get(struct dsa_switch *ds, int port, 1434c0bcf537SYangbo Lu struct ifreq *ifr) 1435c0bcf537SYangbo Lu { 1436c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1437c0bcf537SYangbo Lu 1438c0bcf537SYangbo Lu return ocelot_hwstamp_get(ocelot, port, ifr); 1439c0bcf537SYangbo Lu } 1440c0bcf537SYangbo Lu 1441c0bcf537SYangbo Lu static int felix_hwtstamp_set(struct dsa_switch *ds, int port, 1442c0bcf537SYangbo Lu struct ifreq *ifr) 1443c0bcf537SYangbo Lu { 1444c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 144599348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 144699348004SVladimir Oltean bool using_tag_8021q; 144799348004SVladimir Oltean int err; 1448c0bcf537SYangbo Lu 144999348004SVladimir Oltean err = ocelot_hwstamp_set(ocelot, port, ifr); 145099348004SVladimir Oltean if (err) 145199348004SVladimir Oltean return err; 145299348004SVladimir Oltean 145399348004SVladimir Oltean using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; 145499348004SVladimir Oltean 145599348004SVladimir Oltean return felix_update_trapping_destinations(ds, using_tag_8021q); 1456c0bcf537SYangbo Lu } 1457c0bcf537SYangbo Lu 1458d219b4b6SVladimir Oltean static bool felix_check_xtr_pkt(struct ocelot *ocelot) 14590a6f17c6SVladimir Oltean { 14600a6f17c6SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1461dbd03285SVladimir Oltean int err = 0, grp = 0; 14620a6f17c6SVladimir Oltean 14630a6f17c6SVladimir Oltean if (felix->tag_proto != DSA_TAG_PROTO_OCELOT_8021Q) 14640a6f17c6SVladimir Oltean return false; 14650a6f17c6SVladimir Oltean 14660a6f17c6SVladimir Oltean if (!felix->info->quirk_no_xtr_irq) 14670a6f17c6SVladimir Oltean return false; 14680a6f17c6SVladimir Oltean 14690a6f17c6SVladimir Oltean while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp)) { 14700a6f17c6SVladimir Oltean struct sk_buff *skb; 14710a6f17c6SVladimir Oltean unsigned int type; 14720a6f17c6SVladimir Oltean 14730a6f17c6SVladimir Oltean err = ocelot_xtr_poll_frame(ocelot, grp, &skb); 14740a6f17c6SVladimir Oltean if (err) 14750a6f17c6SVladimir Oltean goto out; 14760a6f17c6SVladimir Oltean 14770a6f17c6SVladimir Oltean /* We trap to the CPU port module all PTP frames, but 14780a6f17c6SVladimir Oltean * felix_rxtstamp() only gets called for event frames. 14790a6f17c6SVladimir Oltean * So we need to avoid sending duplicate general 14800a6f17c6SVladimir Oltean * message frames by running a second BPF classifier 14810a6f17c6SVladimir Oltean * here and dropping those. 14820a6f17c6SVladimir Oltean */ 14830a6f17c6SVladimir Oltean __skb_push(skb, ETH_HLEN); 14840a6f17c6SVladimir Oltean 14850a6f17c6SVladimir Oltean type = ptp_classify_raw(skb); 14860a6f17c6SVladimir Oltean 14870a6f17c6SVladimir Oltean __skb_pull(skb, ETH_HLEN); 14880a6f17c6SVladimir Oltean 14890a6f17c6SVladimir Oltean if (type == PTP_CLASS_NONE) { 14900a6f17c6SVladimir Oltean kfree_skb(skb); 14910a6f17c6SVladimir Oltean continue; 14920a6f17c6SVladimir Oltean } 14930a6f17c6SVladimir Oltean 14940a6f17c6SVladimir Oltean netif_rx(skb); 14950a6f17c6SVladimir Oltean } 14960a6f17c6SVladimir Oltean 14970a6f17c6SVladimir Oltean out: 14985d3bb7ddSVladimir Oltean if (err < 0) { 14995d3bb7ddSVladimir Oltean dev_err_ratelimited(ocelot->dev, 15005d3bb7ddSVladimir Oltean "Error during packet extraction: %pe\n", 15015d3bb7ddSVladimir Oltean ERR_PTR(err)); 15020a6f17c6SVladimir Oltean ocelot_drain_cpu_queue(ocelot, 0); 15035d3bb7ddSVladimir Oltean } 15040a6f17c6SVladimir Oltean 15050a6f17c6SVladimir Oltean return true; 15060a6f17c6SVladimir Oltean } 15070a6f17c6SVladimir Oltean 1508c0bcf537SYangbo Lu static bool felix_rxtstamp(struct dsa_switch *ds, int port, 1509c0bcf537SYangbo Lu struct sk_buff *skb, unsigned int type) 1510c0bcf537SYangbo Lu { 151192f62485SVladimir Oltean u32 tstamp_lo = OCELOT_SKB_CB(skb)->tstamp_lo; 1512c0bcf537SYangbo Lu struct skb_shared_hwtstamps *shhwtstamps; 1513c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1514c0bcf537SYangbo Lu struct timespec64 ts; 151592f62485SVladimir Oltean u32 tstamp_hi; 151692f62485SVladimir Oltean u64 tstamp; 1517c0bcf537SYangbo Lu 15180a6f17c6SVladimir Oltean /* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb 15190a6f17c6SVladimir Oltean * for RX timestamping. Then free it, and poll for its copy through 15200a6f17c6SVladimir Oltean * MMIO in the CPU port module, and inject that into the stack from 15210a6f17c6SVladimir Oltean * ocelot_xtr_poll(). 15220a6f17c6SVladimir Oltean */ 1523d219b4b6SVladimir Oltean if (felix_check_xtr_pkt(ocelot)) { 15240a6f17c6SVladimir Oltean kfree_skb(skb); 15250a6f17c6SVladimir Oltean return true; 15260a6f17c6SVladimir Oltean } 15270a6f17c6SVladimir Oltean 1528c0bcf537SYangbo Lu ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); 1529c0bcf537SYangbo Lu tstamp = ktime_set(ts.tv_sec, ts.tv_nsec); 1530c0bcf537SYangbo Lu 1531c0bcf537SYangbo Lu tstamp_hi = tstamp >> 32; 1532c0bcf537SYangbo Lu if ((tstamp & 0xffffffff) < tstamp_lo) 1533c0bcf537SYangbo Lu tstamp_hi--; 1534c0bcf537SYangbo Lu 1535c0bcf537SYangbo Lu tstamp = ((u64)tstamp_hi << 32) | tstamp_lo; 1536c0bcf537SYangbo Lu 1537c0bcf537SYangbo Lu shhwtstamps = skb_hwtstamps(skb); 1538c0bcf537SYangbo Lu memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); 1539c0bcf537SYangbo Lu shhwtstamps->hwtstamp = tstamp; 1540c0bcf537SYangbo Lu return false; 1541c0bcf537SYangbo Lu } 1542c0bcf537SYangbo Lu 15435c5416f5SYangbo Lu static void felix_txtstamp(struct dsa_switch *ds, int port, 15445c5416f5SYangbo Lu struct sk_buff *skb) 1545c0bcf537SYangbo Lu { 1546c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1547682eaad9SYangbo Lu struct sk_buff *clone = NULL; 1548c0bcf537SYangbo Lu 1549682eaad9SYangbo Lu if (!ocelot->ptp) 15505c5416f5SYangbo Lu return; 1551c0bcf537SYangbo Lu 155252849bcfSVladimir Oltean if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) { 155352849bcfSVladimir Oltean dev_err_ratelimited(ds->dev, 155452849bcfSVladimir Oltean "port %d delivering skb without TX timestamp\n", 155552849bcfSVladimir Oltean port); 1556682eaad9SYangbo Lu return; 155752849bcfSVladimir Oltean } 1558682eaad9SYangbo Lu 1559682eaad9SYangbo Lu if (clone) 1560c4b364ceSYangbo Lu OCELOT_SKB_CB(skb)->clone = clone; 15615c5416f5SYangbo Lu } 1562c0bcf537SYangbo Lu 15630b912fc9SVladimir Oltean static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 15640b912fc9SVladimir Oltean { 15650b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 15660b912fc9SVladimir Oltean 15670b912fc9SVladimir Oltean ocelot_port_set_maxlen(ocelot, port, new_mtu); 15680b912fc9SVladimir Oltean 15690b912fc9SVladimir Oltean return 0; 15700b912fc9SVladimir Oltean } 15710b912fc9SVladimir Oltean 15720b912fc9SVladimir Oltean static int felix_get_max_mtu(struct dsa_switch *ds, int port) 15730b912fc9SVladimir Oltean { 15740b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 15750b912fc9SVladimir Oltean 15760b912fc9SVladimir Oltean return ocelot_get_max_mtu(ocelot, port); 15770b912fc9SVladimir Oltean } 15780b912fc9SVladimir Oltean 157907d985eeSVladimir Oltean static int felix_cls_flower_add(struct dsa_switch *ds, int port, 158007d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 158107d985eeSVladimir Oltean { 158207d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 158399348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 158499348004SVladimir Oltean bool using_tag_8021q; 158599348004SVladimir Oltean int err; 158607d985eeSVladimir Oltean 158799348004SVladimir Oltean err = ocelot_cls_flower_replace(ocelot, port, cls, ingress); 158899348004SVladimir Oltean if (err) 158999348004SVladimir Oltean return err; 159099348004SVladimir Oltean 159199348004SVladimir Oltean using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; 159299348004SVladimir Oltean 159399348004SVladimir Oltean return felix_update_trapping_destinations(ds, using_tag_8021q); 159407d985eeSVladimir Oltean } 159507d985eeSVladimir Oltean 159607d985eeSVladimir Oltean static int felix_cls_flower_del(struct dsa_switch *ds, int port, 159707d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 159807d985eeSVladimir Oltean { 159907d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 160007d985eeSVladimir Oltean 160107d985eeSVladimir Oltean return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); 160207d985eeSVladimir Oltean } 160307d985eeSVladimir Oltean 160407d985eeSVladimir Oltean static int felix_cls_flower_stats(struct dsa_switch *ds, int port, 160507d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 160607d985eeSVladimir Oltean { 160707d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 160807d985eeSVladimir Oltean 160907d985eeSVladimir Oltean return ocelot_cls_flower_stats(ocelot, port, cls, ingress); 161007d985eeSVladimir Oltean } 161107d985eeSVladimir Oltean 1612fc411eaaSVladimir Oltean static int felix_port_policer_add(struct dsa_switch *ds, int port, 1613fc411eaaSVladimir Oltean struct dsa_mall_policer_tc_entry *policer) 1614fc411eaaSVladimir Oltean { 1615fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1616fc411eaaSVladimir Oltean struct ocelot_policer pol = { 1617fc411eaaSVladimir Oltean .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, 16185f035af7SPo Liu .burst = policer->burst, 1619fc411eaaSVladimir Oltean }; 1620fc411eaaSVladimir Oltean 1621fc411eaaSVladimir Oltean return ocelot_port_policer_add(ocelot, port, &pol); 1622fc411eaaSVladimir Oltean } 1623fc411eaaSVladimir Oltean 1624fc411eaaSVladimir Oltean static void felix_port_policer_del(struct dsa_switch *ds, int port) 1625fc411eaaSVladimir Oltean { 1626fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1627fc411eaaSVladimir Oltean 1628fc411eaaSVladimir Oltean ocelot_port_policer_del(ocelot, port); 1629fc411eaaSVladimir Oltean } 1630fc411eaaSVladimir Oltean 16315e497497SVladimir Oltean static int felix_port_mirror_add(struct dsa_switch *ds, int port, 16325e497497SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror, 16335e497497SVladimir Oltean bool ingress, struct netlink_ext_ack *extack) 16345e497497SVladimir Oltean { 16355e497497SVladimir Oltean struct ocelot *ocelot = ds->priv; 16365e497497SVladimir Oltean 16375e497497SVladimir Oltean return ocelot_port_mirror_add(ocelot, port, mirror->to_local_port, 16385e497497SVladimir Oltean ingress, extack); 16395e497497SVladimir Oltean } 16405e497497SVladimir Oltean 16415e497497SVladimir Oltean static void felix_port_mirror_del(struct dsa_switch *ds, int port, 16425e497497SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror) 16435e497497SVladimir Oltean { 16445e497497SVladimir Oltean struct ocelot *ocelot = ds->priv; 16455e497497SVladimir Oltean 16465e497497SVladimir Oltean ocelot_port_mirror_del(ocelot, port, mirror->ingress); 16475e497497SVladimir Oltean } 16485e497497SVladimir Oltean 1649de143c0eSXiaoliang Yang static int felix_port_setup_tc(struct dsa_switch *ds, int port, 1650de143c0eSXiaoliang Yang enum tc_setup_type type, 1651de143c0eSXiaoliang Yang void *type_data) 1652de143c0eSXiaoliang Yang { 1653de143c0eSXiaoliang Yang struct ocelot *ocelot = ds->priv; 1654de143c0eSXiaoliang Yang struct felix *felix = ocelot_to_felix(ocelot); 1655de143c0eSXiaoliang Yang 1656de143c0eSXiaoliang Yang if (felix->info->port_setup_tc) 1657de143c0eSXiaoliang Yang return felix->info->port_setup_tc(ds, port, type, type_data); 1658de143c0eSXiaoliang Yang else 1659de143c0eSXiaoliang Yang return -EOPNOTSUPP; 1660de143c0eSXiaoliang Yang } 1661de143c0eSXiaoliang Yang 1662f59fd9caSVladimir Oltean static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index, 1663f59fd9caSVladimir Oltean u16 pool_index, 1664f59fd9caSVladimir Oltean struct devlink_sb_pool_info *pool_info) 1665f59fd9caSVladimir Oltean { 1666f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1667f59fd9caSVladimir Oltean 1668f59fd9caSVladimir Oltean return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info); 1669f59fd9caSVladimir Oltean } 1670f59fd9caSVladimir Oltean 1671f59fd9caSVladimir Oltean static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index, 1672f59fd9caSVladimir Oltean u16 pool_index, u32 size, 1673f59fd9caSVladimir Oltean enum devlink_sb_threshold_type threshold_type, 1674f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1675f59fd9caSVladimir Oltean { 1676f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1677f59fd9caSVladimir Oltean 1678f59fd9caSVladimir Oltean return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size, 1679f59fd9caSVladimir Oltean threshold_type, extack); 1680f59fd9caSVladimir Oltean } 1681f59fd9caSVladimir Oltean 1682f59fd9caSVladimir Oltean static int felix_sb_port_pool_get(struct dsa_switch *ds, int port, 1683f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1684f59fd9caSVladimir Oltean u32 *p_threshold) 1685f59fd9caSVladimir Oltean { 1686f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1687f59fd9caSVladimir Oltean 1688f59fd9caSVladimir Oltean return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index, 1689f59fd9caSVladimir Oltean p_threshold); 1690f59fd9caSVladimir Oltean } 1691f59fd9caSVladimir Oltean 1692f59fd9caSVladimir Oltean static int felix_sb_port_pool_set(struct dsa_switch *ds, int port, 1693f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1694f59fd9caSVladimir Oltean u32 threshold, struct netlink_ext_ack *extack) 1695f59fd9caSVladimir Oltean { 1696f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1697f59fd9caSVladimir Oltean 1698f59fd9caSVladimir Oltean return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index, 1699f59fd9caSVladimir Oltean threshold, extack); 1700f59fd9caSVladimir Oltean } 1701f59fd9caSVladimir Oltean 1702f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port, 1703f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1704f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1705f59fd9caSVladimir Oltean u16 *p_pool_index, u32 *p_threshold) 1706f59fd9caSVladimir Oltean { 1707f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1708f59fd9caSVladimir Oltean 1709f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index, 1710f59fd9caSVladimir Oltean pool_type, p_pool_index, 1711f59fd9caSVladimir Oltean p_threshold); 1712f59fd9caSVladimir Oltean } 1713f59fd9caSVladimir Oltean 1714f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port, 1715f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1716f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1717f59fd9caSVladimir Oltean u16 pool_index, u32 threshold, 1718f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1719f59fd9caSVladimir Oltean { 1720f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1721f59fd9caSVladimir Oltean 1722f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index, 1723f59fd9caSVladimir Oltean pool_type, pool_index, threshold, 1724f59fd9caSVladimir Oltean extack); 1725f59fd9caSVladimir Oltean } 1726f59fd9caSVladimir Oltean 1727f59fd9caSVladimir Oltean static int felix_sb_occ_snapshot(struct dsa_switch *ds, 1728f59fd9caSVladimir Oltean unsigned int sb_index) 1729f59fd9caSVladimir Oltean { 1730f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1731f59fd9caSVladimir Oltean 1732f59fd9caSVladimir Oltean return ocelot_sb_occ_snapshot(ocelot, sb_index); 1733f59fd9caSVladimir Oltean } 1734f59fd9caSVladimir Oltean 1735f59fd9caSVladimir Oltean static int felix_sb_occ_max_clear(struct dsa_switch *ds, 1736f59fd9caSVladimir Oltean unsigned int sb_index) 1737f59fd9caSVladimir Oltean { 1738f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1739f59fd9caSVladimir Oltean 1740f59fd9caSVladimir Oltean return ocelot_sb_occ_max_clear(ocelot, sb_index); 1741f59fd9caSVladimir Oltean } 1742f59fd9caSVladimir Oltean 1743f59fd9caSVladimir Oltean static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port, 1744f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1745f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1746f59fd9caSVladimir Oltean { 1747f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1748f59fd9caSVladimir Oltean 1749f59fd9caSVladimir Oltean return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index, 1750f59fd9caSVladimir Oltean p_cur, p_max); 1751f59fd9caSVladimir Oltean } 1752f59fd9caSVladimir Oltean 1753f59fd9caSVladimir Oltean static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port, 1754f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1755f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1756f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1757f59fd9caSVladimir Oltean { 1758f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1759f59fd9caSVladimir Oltean 1760f59fd9caSVladimir Oltean return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index, 1761f59fd9caSVladimir Oltean pool_type, p_cur, p_max); 1762f59fd9caSVladimir Oltean } 1763f59fd9caSVladimir Oltean 1764a026c50bSHoratiu Vultur static int felix_mrp_add(struct dsa_switch *ds, int port, 1765a026c50bSHoratiu Vultur const struct switchdev_obj_mrp *mrp) 1766a026c50bSHoratiu Vultur { 1767a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1768a026c50bSHoratiu Vultur 1769a026c50bSHoratiu Vultur return ocelot_mrp_add(ocelot, port, mrp); 1770a026c50bSHoratiu Vultur } 1771a026c50bSHoratiu Vultur 1772a026c50bSHoratiu Vultur static int felix_mrp_del(struct dsa_switch *ds, int port, 1773a026c50bSHoratiu Vultur const struct switchdev_obj_mrp *mrp) 1774a026c50bSHoratiu Vultur { 1775a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1776a026c50bSHoratiu Vultur 1777a026c50bSHoratiu Vultur return ocelot_mrp_add(ocelot, port, mrp); 1778a026c50bSHoratiu Vultur } 1779a026c50bSHoratiu Vultur 1780a026c50bSHoratiu Vultur static int 1781a026c50bSHoratiu Vultur felix_mrp_add_ring_role(struct dsa_switch *ds, int port, 1782a026c50bSHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp) 1783a026c50bSHoratiu Vultur { 1784a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1785a026c50bSHoratiu Vultur 1786a026c50bSHoratiu Vultur return ocelot_mrp_add_ring_role(ocelot, port, mrp); 1787a026c50bSHoratiu Vultur } 1788a026c50bSHoratiu Vultur 1789a026c50bSHoratiu Vultur static int 1790a026c50bSHoratiu Vultur felix_mrp_del_ring_role(struct dsa_switch *ds, int port, 1791a026c50bSHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp) 1792a026c50bSHoratiu Vultur { 1793a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1794a026c50bSHoratiu Vultur 1795a026c50bSHoratiu Vultur return ocelot_mrp_del_ring_role(ocelot, port, mrp); 1796a026c50bSHoratiu Vultur } 1797a026c50bSHoratiu Vultur 1798978777d0SVladimir Oltean static int felix_port_get_default_prio(struct dsa_switch *ds, int port) 1799978777d0SVladimir Oltean { 1800978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1801978777d0SVladimir Oltean 1802978777d0SVladimir Oltean return ocelot_port_get_default_prio(ocelot, port); 1803978777d0SVladimir Oltean } 1804978777d0SVladimir Oltean 1805978777d0SVladimir Oltean static int felix_port_set_default_prio(struct dsa_switch *ds, int port, 1806978777d0SVladimir Oltean u8 prio) 1807978777d0SVladimir Oltean { 1808978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1809978777d0SVladimir Oltean 1810978777d0SVladimir Oltean return ocelot_port_set_default_prio(ocelot, port, prio); 1811978777d0SVladimir Oltean } 1812978777d0SVladimir Oltean 1813978777d0SVladimir Oltean static int felix_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) 1814978777d0SVladimir Oltean { 1815978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1816978777d0SVladimir Oltean 1817978777d0SVladimir Oltean return ocelot_port_get_dscp_prio(ocelot, port, dscp); 1818978777d0SVladimir Oltean } 1819978777d0SVladimir Oltean 1820978777d0SVladimir Oltean static int felix_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, 1821978777d0SVladimir Oltean u8 prio) 1822978777d0SVladimir Oltean { 1823978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1824978777d0SVladimir Oltean 1825978777d0SVladimir Oltean return ocelot_port_add_dscp_prio(ocelot, port, dscp, prio); 1826978777d0SVladimir Oltean } 1827978777d0SVladimir Oltean 1828978777d0SVladimir Oltean static int felix_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, 1829978777d0SVladimir Oltean u8 prio) 1830978777d0SVladimir Oltean { 1831978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1832978777d0SVladimir Oltean 1833978777d0SVladimir Oltean return ocelot_port_del_dscp_prio(ocelot, port, dscp, prio); 1834978777d0SVladimir Oltean } 1835978777d0SVladimir Oltean 1836375e1314SVladimir Oltean const struct dsa_switch_ops felix_switch_ops = { 183756051948SVladimir Oltean .get_tag_protocol = felix_get_tag_protocol, 1838adb3dccfSVladimir Oltean .change_tag_protocol = felix_change_tag_protocol, 183935d97680SVladimir Oltean .connect_tag_protocol = felix_connect_tag_protocol, 184056051948SVladimir Oltean .setup = felix_setup, 184156051948SVladimir Oltean .teardown = felix_teardown, 184256051948SVladimir Oltean .set_ageing_time = felix_set_ageing_time, 184356051948SVladimir Oltean .get_strings = felix_get_strings, 184456051948SVladimir Oltean .get_ethtool_stats = felix_get_ethtool_stats, 184556051948SVladimir Oltean .get_sset_count = felix_get_sset_count, 184656051948SVladimir Oltean .get_ts_info = felix_get_ts_info, 184779fda660SRussell King (Oracle) .phylink_get_caps = felix_phylink_get_caps, 1848bdeced75SVladimir Oltean .phylink_validate = felix_phylink_validate, 1849864ba485SRussell King (Oracle) .phylink_mac_select_pcs = felix_phylink_mac_select_pcs, 1850bdeced75SVladimir Oltean .phylink_mac_link_down = felix_phylink_mac_link_down, 1851bdeced75SVladimir Oltean .phylink_mac_link_up = felix_phylink_mac_link_up, 18525cad43a5SVladimir Oltean .port_fast_age = felix_port_fast_age, 185356051948SVladimir Oltean .port_fdb_dump = felix_fdb_dump, 185456051948SVladimir Oltean .port_fdb_add = felix_fdb_add, 185556051948SVladimir Oltean .port_fdb_del = felix_fdb_del, 1856961d8b69SVladimir Oltean .lag_fdb_add = felix_lag_fdb_add, 1857961d8b69SVladimir Oltean .lag_fdb_del = felix_lag_fdb_del, 1858209edf95SVladimir Oltean .port_mdb_add = felix_mdb_add, 1859209edf95SVladimir Oltean .port_mdb_del = felix_mdb_del, 1860421741eaSVladimir Oltean .port_pre_bridge_flags = felix_pre_bridge_flags, 1861421741eaSVladimir Oltean .port_bridge_flags = felix_bridge_flags, 186256051948SVladimir Oltean .port_bridge_join = felix_bridge_join, 186356051948SVladimir Oltean .port_bridge_leave = felix_bridge_leave, 18648fe6832eSVladimir Oltean .port_lag_join = felix_lag_join, 18658fe6832eSVladimir Oltean .port_lag_leave = felix_lag_leave, 18668fe6832eSVladimir Oltean .port_lag_change = felix_lag_change, 186756051948SVladimir Oltean .port_stp_state_set = felix_bridge_stp_state_set, 186856051948SVladimir Oltean .port_vlan_filtering = felix_vlan_filtering, 186956051948SVladimir Oltean .port_vlan_add = felix_vlan_add, 187056051948SVladimir Oltean .port_vlan_del = felix_vlan_del, 1871c0bcf537SYangbo Lu .port_hwtstamp_get = felix_hwtstamp_get, 1872c0bcf537SYangbo Lu .port_hwtstamp_set = felix_hwtstamp_set, 1873c0bcf537SYangbo Lu .port_rxtstamp = felix_rxtstamp, 1874c0bcf537SYangbo Lu .port_txtstamp = felix_txtstamp, 18750b912fc9SVladimir Oltean .port_change_mtu = felix_change_mtu, 18760b912fc9SVladimir Oltean .port_max_mtu = felix_get_max_mtu, 1877fc411eaaSVladimir Oltean .port_policer_add = felix_port_policer_add, 1878fc411eaaSVladimir Oltean .port_policer_del = felix_port_policer_del, 18795e497497SVladimir Oltean .port_mirror_add = felix_port_mirror_add, 18805e497497SVladimir Oltean .port_mirror_del = felix_port_mirror_del, 188107d985eeSVladimir Oltean .cls_flower_add = felix_cls_flower_add, 188207d985eeSVladimir Oltean .cls_flower_del = felix_cls_flower_del, 188307d985eeSVladimir Oltean .cls_flower_stats = felix_cls_flower_stats, 1884de143c0eSXiaoliang Yang .port_setup_tc = felix_port_setup_tc, 1885f59fd9caSVladimir Oltean .devlink_sb_pool_get = felix_sb_pool_get, 1886f59fd9caSVladimir Oltean .devlink_sb_pool_set = felix_sb_pool_set, 1887f59fd9caSVladimir Oltean .devlink_sb_port_pool_get = felix_sb_port_pool_get, 1888f59fd9caSVladimir Oltean .devlink_sb_port_pool_set = felix_sb_port_pool_set, 1889f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get, 1890f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set, 1891f59fd9caSVladimir Oltean .devlink_sb_occ_snapshot = felix_sb_occ_snapshot, 1892f59fd9caSVladimir Oltean .devlink_sb_occ_max_clear = felix_sb_occ_max_clear, 1893f59fd9caSVladimir Oltean .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get, 1894f59fd9caSVladimir Oltean .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get, 1895a026c50bSHoratiu Vultur .port_mrp_add = felix_mrp_add, 1896a026c50bSHoratiu Vultur .port_mrp_del = felix_mrp_del, 1897a026c50bSHoratiu Vultur .port_mrp_add_ring_role = felix_mrp_add_ring_role, 1898a026c50bSHoratiu Vultur .port_mrp_del_ring_role = felix_mrp_del_ring_role, 18995da11eb4SVladimir Oltean .tag_8021q_vlan_add = felix_tag_8021q_vlan_add, 19005da11eb4SVladimir Oltean .tag_8021q_vlan_del = felix_tag_8021q_vlan_del, 1901978777d0SVladimir Oltean .port_get_default_prio = felix_port_get_default_prio, 1902978777d0SVladimir Oltean .port_set_default_prio = felix_port_set_default_prio, 1903978777d0SVladimir Oltean .port_get_dscp_prio = felix_port_get_dscp_prio, 1904978777d0SVladimir Oltean .port_add_dscp_prio = felix_port_add_dscp_prio, 1905978777d0SVladimir Oltean .port_del_dscp_prio = felix_port_del_dscp_prio, 190672c3b0c7SVladimir Oltean .port_set_host_flood = felix_port_set_host_flood, 190756051948SVladimir Oltean }; 1908319e4dd1SVladimir Oltean 1909319e4dd1SVladimir Oltean struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) 1910319e4dd1SVladimir Oltean { 1911319e4dd1SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1912319e4dd1SVladimir Oltean struct dsa_switch *ds = felix->ds; 1913319e4dd1SVladimir Oltean 1914319e4dd1SVladimir Oltean if (!dsa_is_user_port(ds, port)) 1915319e4dd1SVladimir Oltean return NULL; 1916319e4dd1SVladimir Oltean 1917319e4dd1SVladimir Oltean return dsa_to_port(ds, port)->slave; 1918319e4dd1SVladimir Oltean } 1919319e4dd1SVladimir Oltean 1920319e4dd1SVladimir Oltean int felix_netdev_to_port(struct net_device *dev) 1921319e4dd1SVladimir Oltean { 1922319e4dd1SVladimir Oltean struct dsa_port *dp; 1923319e4dd1SVladimir Oltean 1924319e4dd1SVladimir Oltean dp = dsa_port_from_netdev(dev); 1925319e4dd1SVladimir Oltean if (IS_ERR(dp)) 1926319e4dd1SVladimir Oltean return -EINVAL; 1927319e4dd1SVladimir Oltean 1928319e4dd1SVladimir Oltean return dp->index; 1929319e4dd1SVladimir Oltean } 1930