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 45f9cef64fSVladimir Oltean static int felix_migrate_mdbs_to_npi_port(struct dsa_switch *ds, int port, 46f9cef64fSVladimir Oltean const unsigned char *addr, u16 vid, 47f9cef64fSVladimir Oltean struct dsa_db db) 48f9cef64fSVladimir Oltean { 49f9cef64fSVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 50f9cef64fSVladimir Oltean struct switchdev_obj_port_mdb mdb; 51f9cef64fSVladimir Oltean struct ocelot *ocelot = ds->priv; 52f9cef64fSVladimir Oltean int cpu = ocelot->num_phys_ports; 53f9cef64fSVladimir Oltean int err; 54f9cef64fSVladimir Oltean 55f9cef64fSVladimir Oltean memset(&mdb, 0, sizeof(mdb)); 56f9cef64fSVladimir Oltean ether_addr_copy(mdb.addr, addr); 57f9cef64fSVladimir Oltean mdb.vid = vid; 58f9cef64fSVladimir Oltean 59f9cef64fSVladimir Oltean err = ocelot_port_mdb_del(ocelot, port, &mdb, bridge_dev); 60f9cef64fSVladimir Oltean if (err) 61f9cef64fSVladimir Oltean return err; 62f9cef64fSVladimir Oltean 63f9cef64fSVladimir Oltean return ocelot_port_mdb_add(ocelot, cpu, &mdb, bridge_dev); 64f9cef64fSVladimir Oltean } 65f9cef64fSVladimir Oltean 66b903a6bdSVladimir Oltean static void felix_migrate_pgid_bit(struct dsa_switch *ds, int from, int to, 67b903a6bdSVladimir Oltean int pgid) 68b903a6bdSVladimir Oltean { 69b903a6bdSVladimir Oltean struct ocelot *ocelot = ds->priv; 70b903a6bdSVladimir Oltean bool on; 71b903a6bdSVladimir Oltean u32 val; 72b903a6bdSVladimir Oltean 73b903a6bdSVladimir Oltean val = ocelot_read_rix(ocelot, ANA_PGID_PGID, pgid); 74b903a6bdSVladimir Oltean on = !!(val & BIT(from)); 75b903a6bdSVladimir Oltean val &= ~BIT(from); 76b903a6bdSVladimir Oltean if (on) 77b903a6bdSVladimir Oltean val |= BIT(to); 78b903a6bdSVladimir Oltean else 79b903a6bdSVladimir Oltean val &= ~BIT(to); 80b903a6bdSVladimir Oltean 81b903a6bdSVladimir Oltean ocelot_write_rix(ocelot, val, ANA_PGID_PGID, pgid); 82b903a6bdSVladimir Oltean } 83b903a6bdSVladimir Oltean 84b903a6bdSVladimir Oltean static void felix_migrate_flood_to_npi_port(struct dsa_switch *ds, int port) 85b903a6bdSVladimir Oltean { 86b903a6bdSVladimir Oltean struct ocelot *ocelot = ds->priv; 87b903a6bdSVladimir Oltean 88b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, port, ocelot->num_phys_ports, PGID_UC); 89b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, port, ocelot->num_phys_ports, PGID_MC); 90b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, port, ocelot->num_phys_ports, PGID_BC); 91b903a6bdSVladimir Oltean } 92b903a6bdSVladimir Oltean 93b903a6bdSVladimir Oltean static void 94b903a6bdSVladimir Oltean felix_migrate_flood_to_tag_8021q_port(struct dsa_switch *ds, int port) 95b903a6bdSVladimir Oltean { 96b903a6bdSVladimir Oltean struct ocelot *ocelot = ds->priv; 97b903a6bdSVladimir Oltean 98b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, ocelot->num_phys_ports, port, PGID_UC); 99b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, ocelot->num_phys_ports, port, PGID_MC); 100b903a6bdSVladimir Oltean felix_migrate_pgid_bit(ds, ocelot->num_phys_ports, port, PGID_BC); 101b903a6bdSVladimir Oltean } 102b903a6bdSVladimir Oltean 103f9cef64fSVladimir Oltean static int 104f9cef64fSVladimir Oltean felix_migrate_mdbs_to_tag_8021q_port(struct dsa_switch *ds, int port, 105f9cef64fSVladimir Oltean const unsigned char *addr, u16 vid, 106f9cef64fSVladimir Oltean struct dsa_db db) 107f9cef64fSVladimir Oltean { 108f9cef64fSVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 109f9cef64fSVladimir Oltean struct switchdev_obj_port_mdb mdb; 110f9cef64fSVladimir Oltean struct ocelot *ocelot = ds->priv; 111f9cef64fSVladimir Oltean int cpu = ocelot->num_phys_ports; 112f9cef64fSVladimir Oltean int err; 113f9cef64fSVladimir Oltean 114f9cef64fSVladimir Oltean memset(&mdb, 0, sizeof(mdb)); 115f9cef64fSVladimir Oltean ether_addr_copy(mdb.addr, addr); 116f9cef64fSVladimir Oltean mdb.vid = vid; 117f9cef64fSVladimir Oltean 118f9cef64fSVladimir Oltean err = ocelot_port_mdb_del(ocelot, cpu, &mdb, bridge_dev); 119f9cef64fSVladimir Oltean if (err) 120f9cef64fSVladimir Oltean return err; 121f9cef64fSVladimir Oltean 122f9cef64fSVladimir Oltean return ocelot_port_mdb_add(ocelot, port, &mdb, bridge_dev); 123f9cef64fSVladimir Oltean } 124f9cef64fSVladimir Oltean 12504b67e18SVladimir Oltean /* Set up VCAP ES0 rules for pushing a tag_8021q VLAN towards the CPU such that 12604b67e18SVladimir Oltean * the tagger can perform RX source port identification. 12704b67e18SVladimir Oltean */ 12804b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add_rx(struct felix *felix, int port, u16 vid) 129e21268efSVladimir Oltean { 130e21268efSVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 131e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 132e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 133e21268efSVladimir Oltean int key_length, upstream, err; 134e21268efSVladimir Oltean 135e21268efSVladimir Oltean key_length = ocelot->vcap[VCAP_ES0].keys[VCAP_ES0_IGR_PORT].length; 136e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 137e21268efSVladimir Oltean 138e21268efSVladimir Oltean outer_tagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), 139e21268efSVladimir Oltean GFP_KERNEL); 140e21268efSVladimir Oltean if (!outer_tagging_rule) 141e21268efSVladimir Oltean return -ENOMEM; 142e21268efSVladimir Oltean 143e21268efSVladimir Oltean outer_tagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 144e21268efSVladimir Oltean outer_tagging_rule->prio = 1; 145c518afecSVladimir Oltean outer_tagging_rule->id.cookie = OCELOT_VCAP_ES0_TAG_8021Q_RXVLAN(ocelot, port); 146e21268efSVladimir Oltean outer_tagging_rule->id.tc_offload = false; 147e21268efSVladimir Oltean outer_tagging_rule->block_id = VCAP_ES0; 148e21268efSVladimir Oltean outer_tagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 149e21268efSVladimir Oltean outer_tagging_rule->lookup = 0; 150e21268efSVladimir Oltean outer_tagging_rule->ingress_port.value = port; 151e21268efSVladimir Oltean outer_tagging_rule->ingress_port.mask = GENMASK(key_length - 1, 0); 152e21268efSVladimir Oltean outer_tagging_rule->egress_port.value = upstream; 153e21268efSVladimir Oltean outer_tagging_rule->egress_port.mask = GENMASK(key_length - 1, 0); 154e21268efSVladimir Oltean outer_tagging_rule->action.push_outer_tag = OCELOT_ES0_TAG; 155e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_tpid_sel = OCELOT_TAG_TPID_SEL_8021AD; 156e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_vid_sel = 1; 157e21268efSVladimir Oltean outer_tagging_rule->action.vid_a_val = vid; 158e21268efSVladimir Oltean 159e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, outer_tagging_rule, NULL); 160e21268efSVladimir Oltean if (err) 161e21268efSVladimir Oltean kfree(outer_tagging_rule); 162e21268efSVladimir Oltean 163e21268efSVladimir Oltean return err; 164e21268efSVladimir Oltean } 165e21268efSVladimir Oltean 16604b67e18SVladimir Oltean static int felix_tag_8021q_vlan_del_rx(struct felix *felix, int port, u16 vid) 16704b67e18SVladimir Oltean { 16804b67e18SVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 16904b67e18SVladimir Oltean struct ocelot_vcap_block *block_vcap_es0; 17004b67e18SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 17104b67e18SVladimir Oltean 17204b67e18SVladimir Oltean block_vcap_es0 = &ocelot->block[VCAP_ES0]; 17304b67e18SVladimir Oltean 17404b67e18SVladimir Oltean outer_tagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_es0, 17504b67e18SVladimir Oltean port, false); 17604b67e18SVladimir Oltean if (!outer_tagging_rule) 17704b67e18SVladimir Oltean return -ENOENT; 17804b67e18SVladimir Oltean 17904b67e18SVladimir Oltean return ocelot_vcap_filter_del(ocelot, outer_tagging_rule); 18004b67e18SVladimir Oltean } 18104b67e18SVladimir Oltean 18204b67e18SVladimir Oltean /* Set up VCAP IS1 rules for stripping the tag_8021q VLAN on TX and VCAP IS2 18304b67e18SVladimir Oltean * rules for steering those tagged packets towards the correct destination port 18404b67e18SVladimir Oltean */ 18504b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add_tx(struct felix *felix, int port, u16 vid) 186e21268efSVladimir Oltean { 187e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 188e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 189e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 190e21268efSVladimir Oltean int upstream, err; 191e21268efSVladimir Oltean 192e21268efSVladimir Oltean untagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 193e21268efSVladimir Oltean if (!untagging_rule) 194e21268efSVladimir Oltean return -ENOMEM; 195e21268efSVladimir Oltean 196e21268efSVladimir Oltean redirect_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 197e21268efSVladimir Oltean if (!redirect_rule) { 198e21268efSVladimir Oltean kfree(untagging_rule); 199e21268efSVladimir Oltean return -ENOMEM; 200e21268efSVladimir Oltean } 201e21268efSVladimir Oltean 202e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 203e21268efSVladimir Oltean 204e21268efSVladimir Oltean untagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 205e21268efSVladimir Oltean untagging_rule->ingress_port_mask = BIT(upstream); 206e21268efSVladimir Oltean untagging_rule->vlan.vid.value = vid; 207e21268efSVladimir Oltean untagging_rule->vlan.vid.mask = VLAN_VID_MASK; 208e21268efSVladimir Oltean untagging_rule->prio = 1; 209c518afecSVladimir Oltean untagging_rule->id.cookie = OCELOT_VCAP_IS1_TAG_8021Q_TXVLAN(ocelot, port); 210e21268efSVladimir Oltean untagging_rule->id.tc_offload = false; 211e21268efSVladimir Oltean untagging_rule->block_id = VCAP_IS1; 212e21268efSVladimir Oltean untagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 213e21268efSVladimir Oltean untagging_rule->lookup = 0; 214e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt_ena = true; 215e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt = 1; 216e21268efSVladimir Oltean untagging_rule->action.pag_override_mask = 0xff; 217e21268efSVladimir Oltean untagging_rule->action.pag_val = port; 218e21268efSVladimir Oltean 219e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, untagging_rule, NULL); 220e21268efSVladimir Oltean if (err) { 221e21268efSVladimir Oltean kfree(untagging_rule); 222e21268efSVladimir Oltean kfree(redirect_rule); 223e21268efSVladimir Oltean return err; 224e21268efSVladimir Oltean } 225e21268efSVladimir Oltean 226e21268efSVladimir Oltean redirect_rule->key_type = OCELOT_VCAP_KEY_ANY; 227e21268efSVladimir Oltean redirect_rule->ingress_port_mask = BIT(upstream); 228e21268efSVladimir Oltean redirect_rule->pag = port; 229e21268efSVladimir Oltean redirect_rule->prio = 1; 230c518afecSVladimir Oltean redirect_rule->id.cookie = OCELOT_VCAP_IS2_TAG_8021Q_TXVLAN(ocelot, port); 231e21268efSVladimir Oltean redirect_rule->id.tc_offload = false; 232e21268efSVladimir Oltean redirect_rule->block_id = VCAP_IS2; 233e21268efSVladimir Oltean redirect_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 234e21268efSVladimir Oltean redirect_rule->lookup = 0; 235e21268efSVladimir Oltean redirect_rule->action.mask_mode = OCELOT_MASK_MODE_REDIRECT; 236e21268efSVladimir Oltean redirect_rule->action.port_mask = BIT(port); 237e21268efSVladimir Oltean 238e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, redirect_rule, NULL); 239e21268efSVladimir Oltean if (err) { 240e21268efSVladimir Oltean ocelot_vcap_filter_del(ocelot, untagging_rule); 241e21268efSVladimir Oltean kfree(redirect_rule); 242e21268efSVladimir Oltean return err; 243e21268efSVladimir Oltean } 244e21268efSVladimir Oltean 245e21268efSVladimir Oltean return 0; 246e21268efSVladimir Oltean } 247e21268efSVladimir Oltean 24804b67e18SVladimir Oltean static int felix_tag_8021q_vlan_del_tx(struct felix *felix, int port, u16 vid) 249e21268efSVladimir Oltean { 250e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 251e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is1; 252e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is2; 253e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 254e21268efSVladimir Oltean int err; 255e21268efSVladimir Oltean 256e21268efSVladimir Oltean block_vcap_is1 = &ocelot->block[VCAP_IS1]; 257e21268efSVladimir Oltean block_vcap_is2 = &ocelot->block[VCAP_IS2]; 258e21268efSVladimir Oltean 259e21268efSVladimir Oltean untagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is1, 260e21268efSVladimir Oltean port, false); 261e21268efSVladimir Oltean if (!untagging_rule) 26208f44db3SVladimir Oltean return -ENOENT; 263e21268efSVladimir Oltean 264e21268efSVladimir Oltean err = ocelot_vcap_filter_del(ocelot, untagging_rule); 265e21268efSVladimir Oltean if (err) 266e21268efSVladimir Oltean return err; 267e21268efSVladimir Oltean 268e21268efSVladimir Oltean redirect_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is2, 269e21268efSVladimir Oltean port, false); 270e21268efSVladimir Oltean if (!redirect_rule) 27104b67e18SVladimir Oltean return -ENOENT; 272e21268efSVladimir Oltean 273e21268efSVladimir Oltean return ocelot_vcap_filter_del(ocelot, redirect_rule); 274e21268efSVladimir Oltean } 275e21268efSVladimir Oltean 27604b67e18SVladimir Oltean static int felix_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, 27704b67e18SVladimir Oltean u16 flags) 27804b67e18SVladimir Oltean { 27904b67e18SVladimir Oltean struct ocelot *ocelot = ds->priv; 28004b67e18SVladimir Oltean int err; 28104b67e18SVladimir Oltean 28204b67e18SVladimir Oltean /* tag_8021q.c assumes we are implementing this via port VLAN 28304b67e18SVladimir Oltean * membership, which we aren't. So we don't need to add any VCAP filter 28404b67e18SVladimir Oltean * for the CPU port. 28504b67e18SVladimir Oltean */ 28604b67e18SVladimir Oltean if (!dsa_is_user_port(ds, port)) 28704b67e18SVladimir Oltean return 0; 28804b67e18SVladimir Oltean 28904b67e18SVladimir Oltean err = felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid); 29004b67e18SVladimir Oltean if (err) 29104b67e18SVladimir Oltean return err; 29204b67e18SVladimir Oltean 29304b67e18SVladimir Oltean err = felix_tag_8021q_vlan_add_tx(ocelot_to_felix(ocelot), port, vid); 29404b67e18SVladimir Oltean if (err) { 29504b67e18SVladimir Oltean felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid); 29604b67e18SVladimir Oltean return err; 29704b67e18SVladimir Oltean } 29804b67e18SVladimir Oltean 29904b67e18SVladimir Oltean return 0; 30004b67e18SVladimir Oltean } 30104b67e18SVladimir Oltean 302e21268efSVladimir Oltean static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) 303e21268efSVladimir Oltean { 304e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 30504b67e18SVladimir Oltean int err; 306e21268efSVladimir Oltean 30704b67e18SVladimir Oltean if (!dsa_is_user_port(ds, port)) 30804b67e18SVladimir Oltean return 0; 309e21268efSVladimir Oltean 31004b67e18SVladimir Oltean err = felix_tag_8021q_vlan_del_rx(ocelot_to_felix(ocelot), port, vid); 31104b67e18SVladimir Oltean if (err) 31204b67e18SVladimir Oltean return err; 31304b67e18SVladimir Oltean 31404b67e18SVladimir Oltean err = felix_tag_8021q_vlan_del_tx(ocelot_to_felix(ocelot), port, vid); 31504b67e18SVladimir Oltean if (err) { 31604b67e18SVladimir Oltean felix_tag_8021q_vlan_add_rx(ocelot_to_felix(ocelot), port, vid); 31704b67e18SVladimir Oltean return err; 31804b67e18SVladimir Oltean } 319e21268efSVladimir Oltean 320e21268efSVladimir Oltean return 0; 321e21268efSVladimir Oltean } 322e21268efSVladimir Oltean 323e21268efSVladimir Oltean /* Alternatively to using the NPI functionality, that same hardware MAC 324e21268efSVladimir Oltean * connected internally to the enetc or fman DSA master can be configured to 325e21268efSVladimir Oltean * use the software-defined tag_8021q frame format. As far as the hardware is 326e21268efSVladimir Oltean * concerned, it thinks it is a "dumb switch" - the queues of the CPU port 327e21268efSVladimir Oltean * module are now disconnected from it, but can still be accessed through 328e21268efSVladimir Oltean * register-based MMIO. 329e21268efSVladimir Oltean */ 330e21268efSVladimir Oltean static void felix_8021q_cpu_port_init(struct ocelot *ocelot, int port) 331e21268efSVladimir Oltean { 3328abe1970SVladimir Oltean mutex_lock(&ocelot->fwd_domain_lock); 3338abe1970SVladimir Oltean 33454c31984SVladimir Oltean ocelot_port_set_dsa_8021q_cpu(ocelot, port); 335e21268efSVladimir Oltean 336e21268efSVladimir Oltean /* Overwrite PGID_CPU with the non-tagging port */ 337e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, PGID_CPU); 338e21268efSVladimir Oltean 3398abe1970SVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot, true); 3408abe1970SVladimir Oltean 3418abe1970SVladimir Oltean mutex_unlock(&ocelot->fwd_domain_lock); 342e21268efSVladimir Oltean } 343e21268efSVladimir Oltean 344e21268efSVladimir Oltean static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port) 345e21268efSVladimir Oltean { 3468abe1970SVladimir Oltean mutex_lock(&ocelot->fwd_domain_lock); 3478abe1970SVladimir Oltean 34854c31984SVladimir Oltean ocelot_port_unset_dsa_8021q_cpu(ocelot, port); 349e21268efSVladimir Oltean 350e21268efSVladimir Oltean /* Restore PGID_CPU */ 351e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(ocelot->num_phys_ports), ANA_PGID_PGID, 352e21268efSVladimir Oltean PGID_CPU); 353e21268efSVladimir Oltean 3548abe1970SVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot, true); 3558abe1970SVladimir Oltean 3568abe1970SVladimir Oltean mutex_unlock(&ocelot->fwd_domain_lock); 357e21268efSVladimir Oltean } 358e21268efSVladimir Oltean 35999348004SVladimir Oltean /* On switches with no extraction IRQ wired, trapped packets need to be 36099348004SVladimir Oltean * replicated over Ethernet as well, otherwise we'd get no notification of 36199348004SVladimir Oltean * their arrival when using the ocelot-8021q tagging protocol. 362c8c0ba4fSVladimir Oltean */ 36399348004SVladimir Oltean static int felix_update_trapping_destinations(struct dsa_switch *ds, 36499348004SVladimir Oltean bool using_tag_8021q) 365c8c0ba4fSVladimir Oltean { 36699348004SVladimir Oltean struct ocelot *ocelot = ds->priv; 36799348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 36899348004SVladimir Oltean struct ocelot_vcap_filter *trap; 36999348004SVladimir Oltean enum ocelot_mask_mode mask_mode; 37099348004SVladimir Oltean unsigned long port_mask; 3712960bb14SVladimir Oltean struct dsa_port *dp; 37299348004SVladimir Oltean bool cpu_copy_ena; 37399348004SVladimir Oltean int cpu = -1, err; 374c8c0ba4fSVladimir Oltean 37599348004SVladimir Oltean if (!felix->info->quirk_no_xtr_irq) 37699348004SVladimir Oltean return 0; 377c8c0ba4fSVladimir Oltean 37899348004SVladimir Oltean /* Figure out the current CPU port */ 3792960bb14SVladimir Oltean dsa_switch_for_each_cpu_port(dp, ds) { 3802960bb14SVladimir Oltean cpu = dp->index; 3818d5f7954SVladimir Oltean break; 382c8c0ba4fSVladimir Oltean } 3838d5f7954SVladimir Oltean 384d78637a8SVladimir Oltean /* We are sure that "cpu" was found, otherwise 385d78637a8SVladimir Oltean * dsa_tree_setup_default_cpu() would have failed earlier. 386d78637a8SVladimir Oltean */ 387c8c0ba4fSVladimir Oltean 38899348004SVladimir Oltean /* Make sure all traps are set up for that destination */ 38999348004SVladimir Oltean list_for_each_entry(trap, &ocelot->traps, trap_list) { 39099348004SVladimir Oltean /* Figure out the current trapping destination */ 39199348004SVladimir Oltean if (using_tag_8021q) { 39299348004SVladimir Oltean /* Redirect to the tag_8021q CPU port. If timestamps 39399348004SVladimir Oltean * are necessary, also copy trapped packets to the CPU 39499348004SVladimir Oltean * port module. 395c8c0ba4fSVladimir Oltean */ 39699348004SVladimir Oltean mask_mode = OCELOT_MASK_MODE_REDIRECT; 39799348004SVladimir Oltean port_mask = BIT(cpu); 39899348004SVladimir Oltean cpu_copy_ena = !!trap->take_ts; 399c8c0ba4fSVladimir Oltean } else { 40099348004SVladimir Oltean /* Trap packets only to the CPU port module, which is 40199348004SVladimir Oltean * redirected to the NPI port (the DSA CPU port) 402c8c0ba4fSVladimir Oltean */ 40399348004SVladimir Oltean mask_mode = OCELOT_MASK_MODE_PERMIT_DENY; 40499348004SVladimir Oltean port_mask = 0; 40599348004SVladimir Oltean cpu_copy_ena = true; 406c8c0ba4fSVladimir Oltean } 407c8c0ba4fSVladimir Oltean 40899348004SVladimir Oltean if (trap->action.mask_mode == mask_mode && 40999348004SVladimir Oltean trap->action.port_mask == port_mask && 41099348004SVladimir Oltean trap->action.cpu_copy_ena == cpu_copy_ena) 41199348004SVladimir Oltean continue; 412c8c0ba4fSVladimir Oltean 41399348004SVladimir Oltean trap->action.mask_mode = mask_mode; 41499348004SVladimir Oltean trap->action.port_mask = port_mask; 41599348004SVladimir Oltean trap->action.cpu_copy_ena = cpu_copy_ena; 4160a6f17c6SVladimir Oltean 41799348004SVladimir Oltean err = ocelot_vcap_filter_replace(ocelot, trap); 418c8c0ba4fSVladimir Oltean if (err) 419c8c0ba4fSVladimir Oltean return err; 42099348004SVladimir Oltean } 421c8c0ba4fSVladimir Oltean 42299348004SVladimir Oltean return 0; 423c8c0ba4fSVladimir Oltean } 424c8c0ba4fSVladimir Oltean 425c69f40acSVladimir Oltean static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) 426e21268efSVladimir Oltean { 427e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 4282960bb14SVladimir Oltean struct dsa_port *dp; 4292960bb14SVladimir Oltean int err; 430e21268efSVladimir Oltean 431e21268efSVladimir Oltean felix_8021q_cpu_port_init(ocelot, cpu); 432e21268efSVladimir Oltean 4332960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 434e21268efSVladimir Oltean /* This overwrites ocelot_init(): 435e21268efSVladimir Oltean * Do not forward BPDU frames to the CPU port module, 436e21268efSVladimir Oltean * for 2 reasons: 437e21268efSVladimir Oltean * - When these packets are injected from the tag_8021q 438e21268efSVladimir Oltean * CPU port, we want them to go out, not loop back 439e21268efSVladimir Oltean * into the system. 440e21268efSVladimir Oltean * - STP traffic ingressing on a user port should go to 441e21268efSVladimir Oltean * the tag_8021q CPU port, not to the hardware CPU 442e21268efSVladimir Oltean * port module. 443e21268efSVladimir Oltean */ 444e21268efSVladimir Oltean ocelot_write_gix(ocelot, 445e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0), 4462960bb14SVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, dp->index); 447e21268efSVladimir Oltean } 448e21268efSVladimir Oltean 4495da11eb4SVladimir Oltean err = dsa_tag_8021q_register(ds, htons(ETH_P_8021AD)); 450e21268efSVladimir Oltean if (err) 451d7b1fd52SVladimir Oltean return err; 452d7b1fd52SVladimir Oltean 453c69f40acSVladimir Oltean err = dsa_port_walk_mdbs(ds, cpu, felix_migrate_mdbs_to_tag_8021q_port); 454f9cef64fSVladimir Oltean if (err) 455*a51c1c3fSVladimir Oltean goto out_tag_8021q_unregister; 456b903a6bdSVladimir Oltean 457b903a6bdSVladimir Oltean felix_migrate_flood_to_tag_8021q_port(ds, cpu); 458f9cef64fSVladimir Oltean 459f9cef64fSVladimir Oltean err = felix_update_trapping_destinations(ds, true); 460f9cef64fSVladimir Oltean if (err) 461b903a6bdSVladimir Oltean goto out_migrate_flood; 462f9cef64fSVladimir Oltean 46399348004SVladimir Oltean /* The ownership of the CPU port module's queues might have just been 46499348004SVladimir Oltean * transferred to the tag_8021q tagger from the NPI-based tagger. 46599348004SVladimir Oltean * So there might still be all sorts of crap in the queues. On the 46699348004SVladimir Oltean * other hand, the MMIO-based matching of PTP frames is very brittle, 46799348004SVladimir Oltean * so we need to be careful that there are no extra frames to be 46899348004SVladimir Oltean * dequeued over MMIO, since we would never know to discard them. 46999348004SVladimir Oltean */ 47099348004SVladimir Oltean ocelot_drain_cpu_queue(ocelot, 0); 47199348004SVladimir Oltean 472e21268efSVladimir Oltean return 0; 473e21268efSVladimir Oltean 474b903a6bdSVladimir Oltean out_migrate_flood: 475b903a6bdSVladimir Oltean felix_migrate_flood_to_npi_port(ds, cpu); 476f9cef64fSVladimir Oltean dsa_port_walk_mdbs(ds, cpu, felix_migrate_mdbs_to_npi_port); 477d7b1fd52SVladimir Oltean out_tag_8021q_unregister: 478d7b1fd52SVladimir Oltean dsa_tag_8021q_unregister(ds); 479e21268efSVladimir Oltean return err; 480e21268efSVladimir Oltean } 481e21268efSVladimir Oltean 482e21268efSVladimir Oltean static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) 483e21268efSVladimir Oltean { 484e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 4852960bb14SVladimir Oltean struct dsa_port *dp; 4862960bb14SVladimir Oltean int err; 487e21268efSVladimir Oltean 48899348004SVladimir Oltean err = felix_update_trapping_destinations(ds, false); 489c8c0ba4fSVladimir Oltean if (err) 490c8c0ba4fSVladimir Oltean dev_err(ds->dev, "felix_teardown_mmio_filtering returned %d", 491c8c0ba4fSVladimir Oltean err); 492c8c0ba4fSVladimir Oltean 493d7b1fd52SVladimir Oltean dsa_tag_8021q_unregister(ds); 494e21268efSVladimir Oltean 4952960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 496e21268efSVladimir Oltean /* Restore the logic from ocelot_init: 497e21268efSVladimir Oltean * do not forward BPDU frames to the front ports. 498e21268efSVladimir Oltean */ 499e21268efSVladimir Oltean ocelot_write_gix(ocelot, 500e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff), 501e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, 5022960bb14SVladimir Oltean dp->index); 503e21268efSVladimir Oltean } 504e21268efSVladimir Oltean 505e21268efSVladimir Oltean felix_8021q_cpu_port_deinit(ocelot, cpu); 506e21268efSVladimir Oltean } 507e21268efSVladimir Oltean 508adb3dccfSVladimir Oltean /* The CPU port module is connected to the Node Processor Interface (NPI). This 509adb3dccfSVladimir Oltean * is the mode through which frames can be injected from and extracted to an 510adb3dccfSVladimir Oltean * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU 511adb3dccfSVladimir Oltean * running Linux, and this forms a DSA setup together with the enetc or fman 512adb3dccfSVladimir Oltean * DSA master. 513adb3dccfSVladimir Oltean */ 514adb3dccfSVladimir Oltean static void felix_npi_port_init(struct ocelot *ocelot, int port) 515adb3dccfSVladimir Oltean { 516adb3dccfSVladimir Oltean ocelot->npi = port; 517adb3dccfSVladimir Oltean 518adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M | 519adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port), 520adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 521adb3dccfSVladimir Oltean 522adb3dccfSVladimir Oltean /* NPI port Injection/Extraction configuration */ 523adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 524adb3dccfSVladimir Oltean ocelot->npi_xtr_prefix); 525adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 526adb3dccfSVladimir Oltean ocelot->npi_inj_prefix); 527adb3dccfSVladimir Oltean 528adb3dccfSVladimir Oltean /* Disable transmission of pause frames */ 529adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0); 530adb3dccfSVladimir Oltean } 531adb3dccfSVladimir Oltean 532adb3dccfSVladimir Oltean static void felix_npi_port_deinit(struct ocelot *ocelot, int port) 533adb3dccfSVladimir Oltean { 534adb3dccfSVladimir Oltean /* Restore hardware defaults */ 535adb3dccfSVladimir Oltean int unused_port = ocelot->num_phys_ports + 2; 536adb3dccfSVladimir Oltean 537adb3dccfSVladimir Oltean ocelot->npi = -1; 538adb3dccfSVladimir Oltean 539adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPU_PORT(unused_port), 540adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 541adb3dccfSVladimir Oltean 542adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 543adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 544adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 545adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 546adb3dccfSVladimir Oltean 547adb3dccfSVladimir Oltean /* Enable transmission of pause frames */ 548adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); 549adb3dccfSVladimir Oltean } 550adb3dccfSVladimir Oltean 551c69f40acSVladimir Oltean static int felix_setup_tag_npi(struct dsa_switch *ds, int cpu) 552adb3dccfSVladimir Oltean { 553adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 554f9cef64fSVladimir Oltean int err; 555f9cef64fSVladimir Oltean 556c69f40acSVladimir Oltean err = dsa_port_walk_mdbs(ds, cpu, felix_migrate_mdbs_to_npi_port); 557f9cef64fSVladimir Oltean if (err) 558*a51c1c3fSVladimir Oltean return err; 559b903a6bdSVladimir Oltean 560b903a6bdSVladimir Oltean felix_migrate_flood_to_npi_port(ds, cpu); 561adb3dccfSVladimir Oltean 562adb3dccfSVladimir Oltean felix_npi_port_init(ocelot, cpu); 563adb3dccfSVladimir Oltean 564adb3dccfSVladimir Oltean return 0; 565adb3dccfSVladimir Oltean } 566adb3dccfSVladimir Oltean 567adb3dccfSVladimir Oltean static void felix_teardown_tag_npi(struct dsa_switch *ds, int cpu) 568adb3dccfSVladimir Oltean { 569adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 570adb3dccfSVladimir Oltean 571adb3dccfSVladimir Oltean felix_npi_port_deinit(ocelot, cpu); 572adb3dccfSVladimir Oltean } 573adb3dccfSVladimir Oltean 574adb3dccfSVladimir Oltean static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu, 575c69f40acSVladimir Oltean enum dsa_tag_protocol proto) 576adb3dccfSVladimir Oltean { 577adb3dccfSVladimir Oltean int err; 578adb3dccfSVladimir Oltean 579adb3dccfSVladimir Oltean switch (proto) { 5807c4bb540SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 581adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 582c69f40acSVladimir Oltean err = felix_setup_tag_npi(ds, cpu); 583adb3dccfSVladimir Oltean break; 584e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 585c69f40acSVladimir Oltean err = felix_setup_tag_8021q(ds, cpu); 586e21268efSVladimir Oltean break; 587adb3dccfSVladimir Oltean default: 588adb3dccfSVladimir Oltean err = -EPROTONOSUPPORT; 589adb3dccfSVladimir Oltean } 590adb3dccfSVladimir Oltean 591adb3dccfSVladimir Oltean return err; 592adb3dccfSVladimir Oltean } 593adb3dccfSVladimir Oltean 594adb3dccfSVladimir Oltean static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu, 595adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 596adb3dccfSVladimir Oltean { 597adb3dccfSVladimir Oltean switch (proto) { 5987c4bb540SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 599adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 600adb3dccfSVladimir Oltean felix_teardown_tag_npi(ds, cpu); 601adb3dccfSVladimir Oltean break; 602e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 603e21268efSVladimir Oltean felix_teardown_tag_8021q(ds, cpu); 604e21268efSVladimir Oltean break; 605adb3dccfSVladimir Oltean default: 606adb3dccfSVladimir Oltean break; 607adb3dccfSVladimir Oltean } 608adb3dccfSVladimir Oltean } 609adb3dccfSVladimir Oltean 610e21268efSVladimir Oltean /* This always leaves the switch in a consistent state, because although the 611e21268efSVladimir Oltean * tag_8021q setup can fail, the NPI setup can't. So either the change is made, 612e21268efSVladimir Oltean * or the restoration is guaranteed to work. 613e21268efSVladimir Oltean */ 614adb3dccfSVladimir Oltean static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu, 615adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 616adb3dccfSVladimir Oltean { 617adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 618adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 619adb3dccfSVladimir Oltean enum dsa_tag_protocol old_proto = felix->tag_proto; 62000fa91bcSVladimir Oltean bool cpu_port_active = false; 62100fa91bcSVladimir Oltean struct dsa_port *dp; 622adb3dccfSVladimir Oltean int err; 623adb3dccfSVladimir Oltean 6247c4bb540SVladimir Oltean if (proto != DSA_TAG_PROTO_SEVILLE && 6257c4bb540SVladimir Oltean proto != DSA_TAG_PROTO_OCELOT && 626e21268efSVladimir Oltean proto != DSA_TAG_PROTO_OCELOT_8021Q) 627adb3dccfSVladimir Oltean return -EPROTONOSUPPORT; 628adb3dccfSVladimir Oltean 62900fa91bcSVladimir Oltean /* We don't support multiple CPU ports, yet the DT blob may have 63000fa91bcSVladimir Oltean * multiple CPU ports defined. The first CPU port is the active one, 63100fa91bcSVladimir Oltean * the others are inactive. In this case, DSA will call 63200fa91bcSVladimir Oltean * ->change_tag_protocol() multiple times, once per CPU port. 63300fa91bcSVladimir Oltean * Since we implement the tagging protocol change towards "ocelot" or 63400fa91bcSVladimir Oltean * "seville" as effectively initializing the NPI port, what we are 63500fa91bcSVladimir Oltean * doing is effectively changing who the NPI port is to the last @cpu 63600fa91bcSVladimir Oltean * argument passed, which is an unused DSA CPU port and not the one 63700fa91bcSVladimir Oltean * that should actively pass traffic. 63800fa91bcSVladimir Oltean * Suppress DSA's calls on CPU ports that are inactive. 63900fa91bcSVladimir Oltean */ 64000fa91bcSVladimir Oltean dsa_switch_for_each_user_port(dp, ds) { 64100fa91bcSVladimir Oltean if (dp->cpu_dp->index == cpu) { 64200fa91bcSVladimir Oltean cpu_port_active = true; 64300fa91bcSVladimir Oltean break; 64400fa91bcSVladimir Oltean } 64500fa91bcSVladimir Oltean } 64600fa91bcSVladimir Oltean 64700fa91bcSVladimir Oltean if (!cpu_port_active) 64800fa91bcSVladimir Oltean return 0; 64900fa91bcSVladimir Oltean 650adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, cpu, old_proto); 651adb3dccfSVladimir Oltean 652c69f40acSVladimir Oltean err = felix_set_tag_protocol(ds, cpu, proto); 653adb3dccfSVladimir Oltean if (err) { 654c69f40acSVladimir Oltean felix_set_tag_protocol(ds, cpu, old_proto); 655adb3dccfSVladimir Oltean return err; 656adb3dccfSVladimir Oltean } 657adb3dccfSVladimir Oltean 658adb3dccfSVladimir Oltean felix->tag_proto = proto; 659adb3dccfSVladimir Oltean 660adb3dccfSVladimir Oltean return 0; 661adb3dccfSVladimir Oltean } 662adb3dccfSVladimir Oltean 66356051948SVladimir Oltean static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds, 6644d776482SFlorian Fainelli int port, 6654d776482SFlorian Fainelli enum dsa_tag_protocol mp) 66656051948SVladimir Oltean { 667adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 668adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 669adb3dccfSVladimir Oltean 670adb3dccfSVladimir Oltean return felix->tag_proto; 67156051948SVladimir Oltean } 67256051948SVladimir Oltean 67356051948SVladimir Oltean static int felix_set_ageing_time(struct dsa_switch *ds, 67456051948SVladimir Oltean unsigned int ageing_time) 67556051948SVladimir Oltean { 67656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 67756051948SVladimir Oltean 67856051948SVladimir Oltean ocelot_set_ageing_time(ocelot, ageing_time); 67956051948SVladimir Oltean 68056051948SVladimir Oltean return 0; 68156051948SVladimir Oltean } 68256051948SVladimir Oltean 6835cad43a5SVladimir Oltean static void felix_port_fast_age(struct dsa_switch *ds, int port) 6845cad43a5SVladimir Oltean { 6855cad43a5SVladimir Oltean struct ocelot *ocelot = ds->priv; 6865cad43a5SVladimir Oltean int err; 6875cad43a5SVladimir Oltean 6885cad43a5SVladimir Oltean err = ocelot_mact_flush(ocelot, port); 6895cad43a5SVladimir Oltean if (err) 6905cad43a5SVladimir Oltean dev_err(ds->dev, "Flushing MAC table on port %d returned %pe\n", 6915cad43a5SVladimir Oltean port, ERR_PTR(err)); 6925cad43a5SVladimir Oltean } 6935cad43a5SVladimir Oltean 69456051948SVladimir Oltean static int felix_fdb_dump(struct dsa_switch *ds, int port, 69556051948SVladimir Oltean dsa_fdb_dump_cb_t *cb, void *data) 69656051948SVladimir Oltean { 69756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 69856051948SVladimir Oltean 69956051948SVladimir Oltean return ocelot_fdb_dump(ocelot, port, cb, data); 70056051948SVladimir Oltean } 70156051948SVladimir Oltean 70256051948SVladimir Oltean static int felix_fdb_add(struct dsa_switch *ds, int port, 703c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 704c2693363SVladimir Oltean struct dsa_db db) 70556051948SVladimir Oltean { 70654c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 70756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 70856051948SVladimir Oltean 70954c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 71054c31984SVladimir Oltean return PTR_ERR(bridge_dev); 71154c31984SVladimir Oltean 7127e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 7137e580490SVladimir Oltean dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) 7147e580490SVladimir Oltean return 0; 7157e580490SVladimir Oltean 71654c31984SVladimir Oltean return ocelot_fdb_add(ocelot, port, addr, vid, bridge_dev); 71756051948SVladimir Oltean } 71856051948SVladimir Oltean 71956051948SVladimir Oltean static int felix_fdb_del(struct dsa_switch *ds, int port, 720c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 721c2693363SVladimir Oltean struct dsa_db db) 72256051948SVladimir Oltean { 72354c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 72456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 72556051948SVladimir Oltean 72654c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 72754c31984SVladimir Oltean return PTR_ERR(bridge_dev); 72854c31984SVladimir Oltean 7297e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 7307e580490SVladimir Oltean dsa_fdb_present_in_other_db(ds, port, addr, vid, db)) 7317e580490SVladimir Oltean return 0; 7327e580490SVladimir Oltean 73354c31984SVladimir Oltean return ocelot_fdb_del(ocelot, port, addr, vid, bridge_dev); 73456051948SVladimir Oltean } 73556051948SVladimir Oltean 736961d8b69SVladimir Oltean static int felix_lag_fdb_add(struct dsa_switch *ds, struct dsa_lag lag, 737c2693363SVladimir Oltean const unsigned char *addr, u16 vid, 738c2693363SVladimir Oltean struct dsa_db db) 739961d8b69SVladimir Oltean { 74054c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 741961d8b69SVladimir Oltean struct ocelot *ocelot = ds->priv; 742961d8b69SVladimir Oltean 74354c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 74454c31984SVladimir Oltean return PTR_ERR(bridge_dev); 74554c31984SVladimir Oltean 74654c31984SVladimir Oltean return ocelot_lag_fdb_add(ocelot, lag.dev, addr, vid, bridge_dev); 747961d8b69SVladimir Oltean } 748961d8b69SVladimir Oltean 749961d8b69SVladimir Oltean static int felix_lag_fdb_del(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_del(ocelot, lag.dev, addr, vid, bridge_dev); 760961d8b69SVladimir Oltean } 761961d8b69SVladimir Oltean 762a52b2da7SVladimir Oltean static int felix_mdb_add(struct dsa_switch *ds, int port, 763c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 764c2693363SVladimir Oltean struct dsa_db db) 765209edf95SVladimir Oltean { 76654c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 767209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 768209edf95SVladimir Oltean 76954c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 77054c31984SVladimir Oltean return PTR_ERR(bridge_dev); 77154c31984SVladimir Oltean 7727e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 7737e580490SVladimir Oltean dsa_mdb_present_in_other_db(ds, port, mdb, db)) 7747e580490SVladimir Oltean return 0; 7757e580490SVladimir Oltean 77654c31984SVladimir Oltean return ocelot_port_mdb_add(ocelot, port, mdb, bridge_dev); 777209edf95SVladimir Oltean } 778209edf95SVladimir Oltean 779209edf95SVladimir Oltean static int felix_mdb_del(struct dsa_switch *ds, int port, 780c2693363SVladimir Oltean const struct switchdev_obj_port_mdb *mdb, 781c2693363SVladimir Oltean struct dsa_db db) 782209edf95SVladimir Oltean { 78354c31984SVladimir Oltean struct net_device *bridge_dev = felix_classify_db(db); 784209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 785209edf95SVladimir Oltean 78654c31984SVladimir Oltean if (IS_ERR(bridge_dev)) 78754c31984SVladimir Oltean return PTR_ERR(bridge_dev); 78854c31984SVladimir Oltean 7897e580490SVladimir Oltean if (dsa_is_cpu_port(ds, port) && !bridge_dev && 7907e580490SVladimir Oltean dsa_mdb_present_in_other_db(ds, port, mdb, db)) 7917e580490SVladimir Oltean return 0; 7927e580490SVladimir Oltean 79354c31984SVladimir Oltean return ocelot_port_mdb_del(ocelot, port, mdb, bridge_dev); 794209edf95SVladimir Oltean } 795209edf95SVladimir Oltean 79656051948SVladimir Oltean static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, 79756051948SVladimir Oltean u8 state) 79856051948SVladimir Oltean { 79956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 80056051948SVladimir Oltean 80156051948SVladimir Oltean return ocelot_bridge_stp_state_set(ocelot, port, state); 80256051948SVladimir Oltean } 80356051948SVladimir Oltean 804421741eaSVladimir Oltean static int felix_pre_bridge_flags(struct dsa_switch *ds, int port, 805421741eaSVladimir Oltean struct switchdev_brport_flags val, 806421741eaSVladimir Oltean struct netlink_ext_ack *extack) 807421741eaSVladimir Oltean { 808421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 809421741eaSVladimir Oltean 810421741eaSVladimir Oltean return ocelot_port_pre_bridge_flags(ocelot, port, val); 811421741eaSVladimir Oltean } 812421741eaSVladimir Oltean 813421741eaSVladimir Oltean static int felix_bridge_flags(struct dsa_switch *ds, int port, 814421741eaSVladimir Oltean struct switchdev_brport_flags val, 815421741eaSVladimir Oltean struct netlink_ext_ack *extack) 816421741eaSVladimir Oltean { 817421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 818421741eaSVladimir Oltean 819421741eaSVladimir Oltean ocelot_port_bridge_flags(ocelot, port, val); 820421741eaSVladimir Oltean 821421741eaSVladimir Oltean return 0; 822421741eaSVladimir Oltean } 823421741eaSVladimir Oltean 82456051948SVladimir Oltean static int felix_bridge_join(struct dsa_switch *ds, int port, 82506b9cce4SVladimir Oltean struct dsa_bridge bridge, bool *tx_fwd_offload, 82606b9cce4SVladimir Oltean struct netlink_ext_ack *extack) 82756051948SVladimir Oltean { 82856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 82956051948SVladimir Oltean 83054c31984SVladimir Oltean return ocelot_port_bridge_join(ocelot, port, bridge.dev, bridge.num, 83154c31984SVladimir Oltean extack); 83256051948SVladimir Oltean } 83356051948SVladimir Oltean 83456051948SVladimir Oltean static void felix_bridge_leave(struct dsa_switch *ds, int port, 835d3eed0e5SVladimir Oltean struct dsa_bridge bridge) 83656051948SVladimir Oltean { 83756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 83856051948SVladimir Oltean 839d3eed0e5SVladimir Oltean ocelot_port_bridge_leave(ocelot, port, bridge.dev); 84056051948SVladimir Oltean } 84156051948SVladimir Oltean 8428fe6832eSVladimir Oltean static int felix_lag_join(struct dsa_switch *ds, int port, 843dedd6a00SVladimir Oltean struct dsa_lag lag, 8448fe6832eSVladimir Oltean struct netdev_lag_upper_info *info) 8458fe6832eSVladimir Oltean { 8468fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8478fe6832eSVladimir Oltean 848dedd6a00SVladimir Oltean return ocelot_port_lag_join(ocelot, port, lag.dev, info); 8498fe6832eSVladimir Oltean } 8508fe6832eSVladimir Oltean 8518fe6832eSVladimir Oltean static int felix_lag_leave(struct dsa_switch *ds, int port, 852dedd6a00SVladimir Oltean struct dsa_lag lag) 8538fe6832eSVladimir Oltean { 8548fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8558fe6832eSVladimir Oltean 856dedd6a00SVladimir Oltean ocelot_port_lag_leave(ocelot, port, lag.dev); 8578fe6832eSVladimir Oltean 8588fe6832eSVladimir Oltean return 0; 8598fe6832eSVladimir Oltean } 8608fe6832eSVladimir Oltean 8618fe6832eSVladimir Oltean static int felix_lag_change(struct dsa_switch *ds, int port) 8628fe6832eSVladimir Oltean { 8638fe6832eSVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 8648fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 8658fe6832eSVladimir Oltean 8668fe6832eSVladimir Oltean ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); 8678fe6832eSVladimir Oltean 8688fe6832eSVladimir Oltean return 0; 8698fe6832eSVladimir Oltean } 8708fe6832eSVladimir Oltean 87156051948SVladimir Oltean static int felix_vlan_prepare(struct dsa_switch *ds, int port, 87201af940eSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 87301af940eSVladimir Oltean struct netlink_ext_ack *extack) 87456051948SVladimir Oltean { 8752f0402feSVladimir Oltean struct ocelot *ocelot = ds->priv; 876b7a9e0daSVladimir Oltean u16 flags = vlan->flags; 8772f0402feSVladimir Oltean 8789a720680SVladimir Oltean /* Ocelot switches copy frames as-is to the CPU, so the flags: 8799a720680SVladimir Oltean * egress-untagged or not, pvid or not, make no difference. This 8809a720680SVladimir Oltean * behavior is already better than what DSA just tries to approximate 8819a720680SVladimir Oltean * when it installs the VLAN with the same flags on the CPU port. 8829a720680SVladimir Oltean * Just accept any configuration, and don't let ocelot deny installing 8839a720680SVladimir Oltean * multiple native VLANs on the NPI port, because the switch doesn't 8849a720680SVladimir Oltean * look at the port tag settings towards the NPI interface anyway. 8859a720680SVladimir Oltean */ 8869a720680SVladimir Oltean if (port == ocelot->npi) 8879a720680SVladimir Oltean return 0; 8889a720680SVladimir Oltean 889b7a9e0daSVladimir Oltean return ocelot_vlan_prepare(ocelot, port, vlan->vid, 8902f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 89101af940eSVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED, 89201af940eSVladimir Oltean extack); 89356051948SVladimir Oltean } 89456051948SVladimir Oltean 89589153ed6SVladimir Oltean static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled, 89689153ed6SVladimir Oltean struct netlink_ext_ack *extack) 89756051948SVladimir Oltean { 89856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 89956051948SVladimir Oltean 9003b95d1b2SVladimir Oltean return ocelot_port_vlan_filtering(ocelot, port, enabled, extack); 90156051948SVladimir Oltean } 90256051948SVladimir Oltean 9031958d581SVladimir Oltean static int felix_vlan_add(struct dsa_switch *ds, int port, 90431046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 90531046a5fSVladimir Oltean struct netlink_ext_ack *extack) 90656051948SVladimir Oltean { 90756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 908183be6f9SVladimir Oltean u16 flags = vlan->flags; 9091958d581SVladimir Oltean int err; 91056051948SVladimir Oltean 91101af940eSVladimir Oltean err = felix_vlan_prepare(ds, port, vlan, extack); 9121958d581SVladimir Oltean if (err) 9131958d581SVladimir Oltean return err; 9141958d581SVladimir Oltean 9151958d581SVladimir Oltean return ocelot_vlan_add(ocelot, port, vlan->vid, 916183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 917183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 91856051948SVladimir Oltean } 91956051948SVladimir Oltean 92056051948SVladimir Oltean static int felix_vlan_del(struct dsa_switch *ds, int port, 92156051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 92256051948SVladimir Oltean { 92356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 92456051948SVladimir Oltean 925b7a9e0daSVladimir Oltean return ocelot_vlan_del(ocelot, port, vlan->vid); 92656051948SVladimir Oltean } 92756051948SVladimir Oltean 92879fda660SRussell King (Oracle) static void felix_phylink_get_caps(struct dsa_switch *ds, int port, 92979fda660SRussell King (Oracle) struct phylink_config *config) 93079fda660SRussell King (Oracle) { 93179fda660SRussell King (Oracle) struct ocelot *ocelot = ds->priv; 93279fda660SRussell King (Oracle) 933f6f04c02SRussell King (Oracle) /* This driver does not make use of the speed, duplex, pause or the 934f6f04c02SRussell King (Oracle) * advertisement in its mac_config, so it is safe to mark this driver 935f6f04c02SRussell King (Oracle) * as non-legacy. 936f6f04c02SRussell King (Oracle) */ 937f6f04c02SRussell King (Oracle) config->legacy_pre_march2020 = false; 938f6f04c02SRussell King (Oracle) 93979fda660SRussell King (Oracle) __set_bit(ocelot->ports[port]->phy_mode, 94079fda660SRussell King (Oracle) config->supported_interfaces); 94179fda660SRussell King (Oracle) } 94279fda660SRussell King (Oracle) 943bdeced75SVladimir Oltean static void felix_phylink_validate(struct dsa_switch *ds, int port, 944bdeced75SVladimir Oltean unsigned long *supported, 945bdeced75SVladimir Oltean struct phylink_link_state *state) 946bdeced75SVladimir Oltean { 947bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 948375e1314SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 949bdeced75SVladimir Oltean 950375e1314SVladimir Oltean if (felix->info->phylink_validate) 951375e1314SVladimir Oltean felix->info->phylink_validate(ocelot, port, supported, state); 952bdeced75SVladimir Oltean } 953bdeced75SVladimir Oltean 954864ba485SRussell King (Oracle) static struct phylink_pcs *felix_phylink_mac_select_pcs(struct dsa_switch *ds, 955864ba485SRussell King (Oracle) int port, 956864ba485SRussell King (Oracle) phy_interface_t iface) 957bdeced75SVladimir Oltean { 958bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 959bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 960864ba485SRussell King (Oracle) struct phylink_pcs *pcs = NULL; 961bdeced75SVladimir Oltean 96249af6a76SColin Foster if (felix->pcs && felix->pcs[port]) 963864ba485SRussell King (Oracle) pcs = felix->pcs[port]; 964864ba485SRussell King (Oracle) 965864ba485SRussell King (Oracle) return pcs; 966bdeced75SVladimir Oltean } 967bdeced75SVladimir Oltean 968bdeced75SVladimir Oltean static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, 969bdeced75SVladimir Oltean unsigned int link_an_mode, 970bdeced75SVladimir Oltean phy_interface_t interface) 971bdeced75SVladimir Oltean { 972bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 973bdeced75SVladimir Oltean 974e6e12df6SVladimir Oltean ocelot_phylink_mac_link_down(ocelot, port, link_an_mode, interface, 975e6e12df6SVladimir Oltean FELIX_MAC_QUIRKS); 976bdeced75SVladimir Oltean } 977bdeced75SVladimir Oltean 978bdeced75SVladimir Oltean static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, 979bdeced75SVladimir Oltean unsigned int link_an_mode, 980bdeced75SVladimir Oltean phy_interface_t interface, 9815b502a7bSRussell King struct phy_device *phydev, 9825b502a7bSRussell King int speed, int duplex, 9835b502a7bSRussell King bool tx_pause, bool rx_pause) 984bdeced75SVladimir Oltean { 985bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 9867e14a2dcSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 987bdeced75SVladimir Oltean 988e6e12df6SVladimir Oltean ocelot_phylink_mac_link_up(ocelot, port, phydev, link_an_mode, 989e6e12df6SVladimir Oltean interface, speed, duplex, tx_pause, rx_pause, 990e6e12df6SVladimir Oltean FELIX_MAC_QUIRKS); 9917e14a2dcSVladimir Oltean 9927e14a2dcSVladimir Oltean if (felix->info->port_sched_speed_set) 9937e14a2dcSVladimir Oltean felix->info->port_sched_speed_set(ocelot, port, speed); 994bdeced75SVladimir Oltean } 995bdeced75SVladimir Oltean 996bd2b3161SXiaoliang Yang static void felix_port_qos_map_init(struct ocelot *ocelot, int port) 997bd2b3161SXiaoliang Yang { 998bd2b3161SXiaoliang Yang int i; 999bd2b3161SXiaoliang Yang 1000bd2b3161SXiaoliang Yang ocelot_rmw_gix(ocelot, 1001bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 1002bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 1003bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG, 1004bd2b3161SXiaoliang Yang port); 1005bd2b3161SXiaoliang Yang 100670d39a6eSVladimir Oltean for (i = 0; i < OCELOT_NUM_TC * 2; i++) { 1007bd2b3161SXiaoliang Yang ocelot_rmw_ix(ocelot, 1008bd2b3161SXiaoliang Yang (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) | 1009bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i), 1010bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL | 1011bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M, 1012bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP, 1013bd2b3161SXiaoliang Yang port, i); 1014bd2b3161SXiaoliang Yang } 1015bd2b3161SXiaoliang Yang } 1016bd2b3161SXiaoliang Yang 101756051948SVladimir Oltean static void felix_get_strings(struct dsa_switch *ds, int port, 101856051948SVladimir Oltean u32 stringset, u8 *data) 101956051948SVladimir Oltean { 102056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 102156051948SVladimir Oltean 102256051948SVladimir Oltean return ocelot_get_strings(ocelot, port, stringset, data); 102356051948SVladimir Oltean } 102456051948SVladimir Oltean 102556051948SVladimir Oltean static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) 102656051948SVladimir Oltean { 102756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 102856051948SVladimir Oltean 102956051948SVladimir Oltean ocelot_get_ethtool_stats(ocelot, port, data); 103056051948SVladimir Oltean } 103156051948SVladimir Oltean 103256051948SVladimir Oltean static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) 103356051948SVladimir Oltean { 103456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 103556051948SVladimir Oltean 103656051948SVladimir Oltean return ocelot_get_sset_count(ocelot, port, sset); 103756051948SVladimir Oltean } 103856051948SVladimir Oltean 103956051948SVladimir Oltean static int felix_get_ts_info(struct dsa_switch *ds, int port, 104056051948SVladimir Oltean struct ethtool_ts_info *info) 104156051948SVladimir Oltean { 104256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 104356051948SVladimir Oltean 104456051948SVladimir Oltean return ocelot_get_ts_info(ocelot, port, info); 104556051948SVladimir Oltean } 104656051948SVladimir Oltean 1047acf242fcSColin Foster static const u32 felix_phy_match_table[PHY_INTERFACE_MODE_MAX] = { 1048acf242fcSColin Foster [PHY_INTERFACE_MODE_INTERNAL] = OCELOT_PORT_MODE_INTERNAL, 1049acf242fcSColin Foster [PHY_INTERFACE_MODE_SGMII] = OCELOT_PORT_MODE_SGMII, 1050acf242fcSColin Foster [PHY_INTERFACE_MODE_QSGMII] = OCELOT_PORT_MODE_QSGMII, 1051acf242fcSColin Foster [PHY_INTERFACE_MODE_USXGMII] = OCELOT_PORT_MODE_USXGMII, 1052acf242fcSColin Foster [PHY_INTERFACE_MODE_2500BASEX] = OCELOT_PORT_MODE_2500BASEX, 1053acf242fcSColin Foster }; 1054acf242fcSColin Foster 1055acf242fcSColin Foster static int felix_validate_phy_mode(struct felix *felix, int port, 1056acf242fcSColin Foster phy_interface_t phy_mode) 1057acf242fcSColin Foster { 1058acf242fcSColin Foster u32 modes = felix->info->port_modes[port]; 1059acf242fcSColin Foster 1060acf242fcSColin Foster if (felix_phy_match_table[phy_mode] & modes) 1061acf242fcSColin Foster return 0; 1062acf242fcSColin Foster return -EOPNOTSUPP; 1063acf242fcSColin Foster } 1064acf242fcSColin Foster 1065bdeced75SVladimir Oltean static int felix_parse_ports_node(struct felix *felix, 1066bdeced75SVladimir Oltean struct device_node *ports_node, 1067bdeced75SVladimir Oltean phy_interface_t *port_phy_modes) 1068bdeced75SVladimir Oltean { 1069bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 1070bdeced75SVladimir Oltean struct device_node *child; 1071bdeced75SVladimir Oltean 107237fe45adSVladimir Oltean for_each_available_child_of_node(ports_node, child) { 1073bdeced75SVladimir Oltean phy_interface_t phy_mode; 1074bdeced75SVladimir Oltean u32 port; 1075bdeced75SVladimir Oltean int err; 1076bdeced75SVladimir Oltean 1077bdeced75SVladimir Oltean /* Get switch port number from DT */ 1078bdeced75SVladimir Oltean if (of_property_read_u32(child, "reg", &port) < 0) { 1079bdeced75SVladimir Oltean dev_err(dev, "Port number not defined in device tree " 1080bdeced75SVladimir Oltean "(property \"reg\")\n"); 1081bdeced75SVladimir Oltean of_node_put(child); 1082bdeced75SVladimir Oltean return -ENODEV; 1083bdeced75SVladimir Oltean } 1084bdeced75SVladimir Oltean 1085bdeced75SVladimir Oltean /* Get PHY mode from DT */ 1086bdeced75SVladimir Oltean err = of_get_phy_mode(child, &phy_mode); 1087bdeced75SVladimir Oltean if (err) { 1088bdeced75SVladimir Oltean dev_err(dev, "Failed to read phy-mode or " 1089bdeced75SVladimir Oltean "phy-interface-type property for port %d\n", 1090bdeced75SVladimir Oltean port); 1091bdeced75SVladimir Oltean of_node_put(child); 1092bdeced75SVladimir Oltean return -ENODEV; 1093bdeced75SVladimir Oltean } 1094bdeced75SVladimir Oltean 1095acf242fcSColin Foster err = felix_validate_phy_mode(felix, port, phy_mode); 1096bdeced75SVladimir Oltean if (err < 0) { 1097bdeced75SVladimir Oltean dev_err(dev, "Unsupported PHY mode %s on port %d\n", 1098bdeced75SVladimir Oltean phy_modes(phy_mode), port); 109959ebb430SSumera Priyadarsini of_node_put(child); 1100bdeced75SVladimir Oltean return err; 1101bdeced75SVladimir Oltean } 1102bdeced75SVladimir Oltean 1103bdeced75SVladimir Oltean port_phy_modes[port] = phy_mode; 1104bdeced75SVladimir Oltean } 1105bdeced75SVladimir Oltean 1106bdeced75SVladimir Oltean return 0; 1107bdeced75SVladimir Oltean } 1108bdeced75SVladimir Oltean 1109bdeced75SVladimir Oltean static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes) 1110bdeced75SVladimir Oltean { 1111bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 1112bdeced75SVladimir Oltean struct device_node *switch_node; 1113bdeced75SVladimir Oltean struct device_node *ports_node; 1114bdeced75SVladimir Oltean int err; 1115bdeced75SVladimir Oltean 1116bdeced75SVladimir Oltean switch_node = dev->of_node; 1117bdeced75SVladimir Oltean 1118bdeced75SVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ports"); 1119abecbfcdSVladimir Oltean if (!ports_node) 1120abecbfcdSVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ethernet-ports"); 1121bdeced75SVladimir Oltean if (!ports_node) { 1122abecbfcdSVladimir Oltean dev_err(dev, "Incorrect bindings: absent \"ports\" or \"ethernet-ports\" node\n"); 1123bdeced75SVladimir Oltean return -ENODEV; 1124bdeced75SVladimir Oltean } 1125bdeced75SVladimir Oltean 1126bdeced75SVladimir Oltean err = felix_parse_ports_node(felix, ports_node, port_phy_modes); 1127bdeced75SVladimir Oltean of_node_put(ports_node); 1128bdeced75SVladimir Oltean 1129bdeced75SVladimir Oltean return err; 1130bdeced75SVladimir Oltean } 1131bdeced75SVladimir Oltean 113256051948SVladimir Oltean static int felix_init_structs(struct felix *felix, int num_phys_ports) 113356051948SVladimir Oltean { 113456051948SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 1135bdeced75SVladimir Oltean phy_interface_t *port_phy_modes; 1136b4024c9eSClaudiu Manoil struct resource res; 113756051948SVladimir Oltean int port, i, err; 113856051948SVladimir Oltean 113956051948SVladimir Oltean ocelot->num_phys_ports = num_phys_ports; 114056051948SVladimir Oltean ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, 114156051948SVladimir Oltean sizeof(struct ocelot_port *), GFP_KERNEL); 114256051948SVladimir Oltean if (!ocelot->ports) 114356051948SVladimir Oltean return -ENOMEM; 114456051948SVladimir Oltean 114556051948SVladimir Oltean ocelot->map = felix->info->map; 114656051948SVladimir Oltean ocelot->stats_layout = felix->info->stats_layout; 114721ce7f3eSVladimir Oltean ocelot->num_mact_rows = felix->info->num_mact_rows; 114807d985eeSVladimir Oltean ocelot->vcap = felix->info->vcap; 114977043c37SXiaoliang Yang ocelot->vcap_pol.base = felix->info->vcap_pol_base; 115077043c37SXiaoliang Yang ocelot->vcap_pol.max = felix->info->vcap_pol_max; 115177043c37SXiaoliang Yang ocelot->vcap_pol.base2 = felix->info->vcap_pol_base2; 115277043c37SXiaoliang Yang ocelot->vcap_pol.max2 = felix->info->vcap_pol_max2; 115356051948SVladimir Oltean ocelot->ops = felix->info->ops; 1154cacea62fSVladimir Oltean ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT; 1155cacea62fSVladimir Oltean ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT; 1156f59fd9caSVladimir Oltean ocelot->devlink = felix->ds->devlink; 115756051948SVladimir Oltean 1158bdeced75SVladimir Oltean port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t), 1159bdeced75SVladimir Oltean GFP_KERNEL); 1160bdeced75SVladimir Oltean if (!port_phy_modes) 1161bdeced75SVladimir Oltean return -ENOMEM; 1162bdeced75SVladimir Oltean 1163bdeced75SVladimir Oltean err = felix_parse_dt(felix, port_phy_modes); 1164bdeced75SVladimir Oltean if (err) { 1165bdeced75SVladimir Oltean kfree(port_phy_modes); 1166bdeced75SVladimir Oltean return err; 1167bdeced75SVladimir Oltean } 1168bdeced75SVladimir Oltean 116956051948SVladimir Oltean for (i = 0; i < TARGET_MAX; i++) { 117056051948SVladimir Oltean struct regmap *target; 117156051948SVladimir Oltean 117256051948SVladimir Oltean if (!felix->info->target_io_res[i].name) 117356051948SVladimir Oltean continue; 117456051948SVladimir Oltean 1175b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->target_io_res[i], sizeof(res)); 1176b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1177375e1314SVladimir Oltean res.start += felix->switch_base; 1178375e1314SVladimir Oltean res.end += felix->switch_base; 117956051948SVladimir Oltean 1180242bd0c1SColin Foster target = felix->info->init_regmap(ocelot, &res); 118156051948SVladimir Oltean if (IS_ERR(target)) { 118256051948SVladimir Oltean dev_err(ocelot->dev, 118356051948SVladimir Oltean "Failed to map device memory space\n"); 1184bdeced75SVladimir Oltean kfree(port_phy_modes); 118556051948SVladimir Oltean return PTR_ERR(target); 118656051948SVladimir Oltean } 118756051948SVladimir Oltean 118856051948SVladimir Oltean ocelot->targets[i] = target; 118956051948SVladimir Oltean } 119056051948SVladimir Oltean 119156051948SVladimir Oltean err = ocelot_regfields_init(ocelot, felix->info->regfields); 119256051948SVladimir Oltean if (err) { 119356051948SVladimir Oltean dev_err(ocelot->dev, "failed to init reg fields map\n"); 1194bdeced75SVladimir Oltean kfree(port_phy_modes); 119556051948SVladimir Oltean return err; 119656051948SVladimir Oltean } 119756051948SVladimir Oltean 119856051948SVladimir Oltean for (port = 0; port < num_phys_ports; port++) { 119956051948SVladimir Oltean struct ocelot_port *ocelot_port; 120091c724cfSVladimir Oltean struct regmap *target; 120156051948SVladimir Oltean 120256051948SVladimir Oltean ocelot_port = devm_kzalloc(ocelot->dev, 120356051948SVladimir Oltean sizeof(struct ocelot_port), 120456051948SVladimir Oltean GFP_KERNEL); 120556051948SVladimir Oltean if (!ocelot_port) { 120656051948SVladimir Oltean dev_err(ocelot->dev, 120756051948SVladimir Oltean "failed to allocate port memory\n"); 1208bdeced75SVladimir Oltean kfree(port_phy_modes); 120956051948SVladimir Oltean return -ENOMEM; 121056051948SVladimir Oltean } 121156051948SVladimir Oltean 1212b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->port_io_res[port], sizeof(res)); 1213b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1214375e1314SVladimir Oltean res.start += felix->switch_base; 1215375e1314SVladimir Oltean res.end += felix->switch_base; 121656051948SVladimir Oltean 1217242bd0c1SColin Foster target = felix->info->init_regmap(ocelot, &res); 121891c724cfSVladimir Oltean if (IS_ERR(target)) { 121956051948SVladimir Oltean dev_err(ocelot->dev, 122091c724cfSVladimir Oltean "Failed to map memory space for port %d\n", 122191c724cfSVladimir Oltean port); 1222bdeced75SVladimir Oltean kfree(port_phy_modes); 122391c724cfSVladimir Oltean return PTR_ERR(target); 122456051948SVladimir Oltean } 122556051948SVladimir Oltean 1226bdeced75SVladimir Oltean ocelot_port->phy_mode = port_phy_modes[port]; 122756051948SVladimir Oltean ocelot_port->ocelot = ocelot; 122891c724cfSVladimir Oltean ocelot_port->target = target; 122956051948SVladimir Oltean ocelot->ports[port] = ocelot_port; 123056051948SVladimir Oltean } 123156051948SVladimir Oltean 1232bdeced75SVladimir Oltean kfree(port_phy_modes); 1233bdeced75SVladimir Oltean 1234bdeced75SVladimir Oltean if (felix->info->mdio_bus_alloc) { 1235bdeced75SVladimir Oltean err = felix->info->mdio_bus_alloc(ocelot); 1236bdeced75SVladimir Oltean if (err < 0) 1237bdeced75SVladimir Oltean return err; 1238bdeced75SVladimir Oltean } 1239bdeced75SVladimir Oltean 124056051948SVladimir Oltean return 0; 124156051948SVladimir Oltean } 124256051948SVladimir Oltean 12431328a883SVladimir Oltean static void ocelot_port_purge_txtstamp_skb(struct ocelot *ocelot, int port, 12441328a883SVladimir Oltean struct sk_buff *skb) 12451328a883SVladimir Oltean { 12461328a883SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 12471328a883SVladimir Oltean struct sk_buff *clone = OCELOT_SKB_CB(skb)->clone; 12481328a883SVladimir Oltean struct sk_buff *skb_match = NULL, *skb_tmp; 12491328a883SVladimir Oltean unsigned long flags; 12501328a883SVladimir Oltean 12511328a883SVladimir Oltean if (!clone) 12521328a883SVladimir Oltean return; 12531328a883SVladimir Oltean 12541328a883SVladimir Oltean spin_lock_irqsave(&ocelot_port->tx_skbs.lock, flags); 12551328a883SVladimir Oltean 12561328a883SVladimir Oltean skb_queue_walk_safe(&ocelot_port->tx_skbs, skb, skb_tmp) { 12571328a883SVladimir Oltean if (skb != clone) 12581328a883SVladimir Oltean continue; 12591328a883SVladimir Oltean __skb_unlink(skb, &ocelot_port->tx_skbs); 12601328a883SVladimir Oltean skb_match = skb; 12611328a883SVladimir Oltean break; 12621328a883SVladimir Oltean } 12631328a883SVladimir Oltean 12641328a883SVladimir Oltean spin_unlock_irqrestore(&ocelot_port->tx_skbs.lock, flags); 12651328a883SVladimir Oltean 12661328a883SVladimir Oltean WARN_ONCE(!skb_match, 12671328a883SVladimir Oltean "Could not find skb clone in TX timestamping list\n"); 12681328a883SVladimir Oltean } 12691328a883SVladimir Oltean 127049f885b2SVladimir Oltean #define work_to_xmit_work(w) \ 127149f885b2SVladimir Oltean container_of((w), struct felix_deferred_xmit_work, work) 127249f885b2SVladimir Oltean 127349f885b2SVladimir Oltean static void felix_port_deferred_xmit(struct kthread_work *work) 127449f885b2SVladimir Oltean { 127549f885b2SVladimir Oltean struct felix_deferred_xmit_work *xmit_work = work_to_xmit_work(work); 127649f885b2SVladimir Oltean struct dsa_switch *ds = xmit_work->dp->ds; 127749f885b2SVladimir Oltean struct sk_buff *skb = xmit_work->skb; 127849f885b2SVladimir Oltean u32 rew_op = ocelot_ptp_rew_op(skb); 127949f885b2SVladimir Oltean struct ocelot *ocelot = ds->priv; 128049f885b2SVladimir Oltean int port = xmit_work->dp->index; 128149f885b2SVladimir Oltean int retries = 10; 128249f885b2SVladimir Oltean 128349f885b2SVladimir Oltean do { 128449f885b2SVladimir Oltean if (ocelot_can_inject(ocelot, 0)) 128549f885b2SVladimir Oltean break; 128649f885b2SVladimir Oltean 128749f885b2SVladimir Oltean cpu_relax(); 128849f885b2SVladimir Oltean } while (--retries); 128949f885b2SVladimir Oltean 129049f885b2SVladimir Oltean if (!retries) { 129149f885b2SVladimir Oltean dev_err(ocelot->dev, "port %d failed to inject skb\n", 129249f885b2SVladimir Oltean port); 12931328a883SVladimir Oltean ocelot_port_purge_txtstamp_skb(ocelot, port, skb); 129449f885b2SVladimir Oltean kfree_skb(skb); 129549f885b2SVladimir Oltean return; 129649f885b2SVladimir Oltean } 129749f885b2SVladimir Oltean 129849f885b2SVladimir Oltean ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb); 129949f885b2SVladimir Oltean 130049f885b2SVladimir Oltean consume_skb(skb); 130149f885b2SVladimir Oltean kfree(xmit_work); 130249f885b2SVladimir Oltean } 130349f885b2SVladimir Oltean 130435d97680SVladimir Oltean static int felix_connect_tag_protocol(struct dsa_switch *ds, 130535d97680SVladimir Oltean enum dsa_tag_protocol proto) 130649f885b2SVladimir Oltean { 130735d97680SVladimir Oltean struct ocelot_8021q_tagger_data *tagger_data; 130849f885b2SVladimir Oltean 130935d97680SVladimir Oltean switch (proto) { 131035d97680SVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 131135d97680SVladimir Oltean tagger_data = ocelot_8021q_tagger_data(ds); 131235d97680SVladimir Oltean tagger_data->xmit_work_fn = felix_port_deferred_xmit; 131349f885b2SVladimir Oltean return 0; 131435d97680SVladimir Oltean case DSA_TAG_PROTO_OCELOT: 131535d97680SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 131649f885b2SVladimir Oltean return 0; 131735d97680SVladimir Oltean default: 131835d97680SVladimir Oltean return -EPROTONOSUPPORT; 131949f885b2SVladimir Oltean } 132049f885b2SVladimir Oltean } 132149f885b2SVladimir Oltean 132256051948SVladimir Oltean /* Hardware initialization done here so that we can allocate structures with 132356051948SVladimir Oltean * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing 132456051948SVladimir Oltean * us to allocate structures twice (leak memory) and map PCI memory twice 132556051948SVladimir Oltean * (which will not work). 132656051948SVladimir Oltean */ 132756051948SVladimir Oltean static int felix_setup(struct dsa_switch *ds) 132856051948SVladimir Oltean { 132956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 133056051948SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1331f2e2662cSVladimir Oltean unsigned long cpu_flood; 13322960bb14SVladimir Oltean struct dsa_port *dp; 13332960bb14SVladimir Oltean int err; 133456051948SVladimir Oltean 133556051948SVladimir Oltean err = felix_init_structs(felix, ds->num_ports); 133656051948SVladimir Oltean if (err) 133756051948SVladimir Oltean return err; 133856051948SVladimir Oltean 1339d1cc0e93SVladimir Oltean err = ocelot_init(ocelot); 1340d1cc0e93SVladimir Oltean if (err) 13416b73b7c9SVladimir Oltean goto out_mdiobus_free; 1342d1cc0e93SVladimir Oltean 13432b49d128SYangbo Lu if (ocelot->ptp) { 13442ac7c6c5SVladimir Oltean err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); 13452b49d128SYangbo Lu if (err) { 13462b49d128SYangbo Lu dev_err(ocelot->dev, 13472b49d128SYangbo Lu "Timestamp initialization failed\n"); 13482b49d128SYangbo Lu ocelot->ptp = 0; 13492b49d128SYangbo Lu } 13502b49d128SYangbo Lu } 135156051948SVladimir Oltean 13522960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) { 13532960bb14SVladimir Oltean ocelot_init_port(ocelot, dp->index); 1354bd2b3161SXiaoliang Yang 1355bd2b3161SXiaoliang Yang /* Set the default QoS Classification based on PCP and DEI 1356bd2b3161SXiaoliang Yang * bits of vlan tag. 1357bd2b3161SXiaoliang Yang */ 13582960bb14SVladimir Oltean felix_port_qos_map_init(ocelot, dp->index); 135956051948SVladimir Oltean } 136056051948SVladimir Oltean 1361f59fd9caSVladimir Oltean err = ocelot_devlink_sb_register(ocelot); 1362f59fd9caSVladimir Oltean if (err) 13636b73b7c9SVladimir Oltean goto out_deinit_ports; 1364f59fd9caSVladimir Oltean 13652960bb14SVladimir Oltean dsa_switch_for_each_cpu_port(dp, ds) { 1366adb3dccfSVladimir Oltean /* The initial tag protocol is NPI which always returns 0, so 1367adb3dccfSVladimir Oltean * there's no real point in checking for errors. 13681cf3299bSVladimir Oltean */ 1369c69f40acSVladimir Oltean felix_set_tag_protocol(ds, dp->index, felix->tag_proto); 1370f2e2662cSVladimir Oltean 1371f2e2662cSVladimir Oltean /* Start off with flooding disabled towards the NPI port 1372f2e2662cSVladimir Oltean * (actually CPU port module). 1373f2e2662cSVladimir Oltean */ 1374f2e2662cSVladimir Oltean cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)); 1375f2e2662cSVladimir Oltean ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_UC); 1376f2e2662cSVladimir Oltean ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC); 1377f2e2662cSVladimir Oltean 13788d5f7954SVladimir Oltean break; 1379adb3dccfSVladimir Oltean } 13801cf3299bSVladimir Oltean 13810b912fc9SVladimir Oltean ds->mtu_enforcement_ingress = true; 1382c54913c1SVladimir Oltean ds->assisted_learning_on_cpu_port = true; 138354c31984SVladimir Oltean ds->fdb_isolation = true; 138454c31984SVladimir Oltean ds->max_num_bridges = ds->num_ports; 1385bdeced75SVladimir Oltean 138656051948SVladimir Oltean return 0; 13876b73b7c9SVladimir Oltean 13886b73b7c9SVladimir Oltean out_deinit_ports: 13892960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) 13902960bb14SVladimir Oltean ocelot_deinit_port(ocelot, dp->index); 13916b73b7c9SVladimir Oltean 13926b73b7c9SVladimir Oltean ocelot_deinit_timestamp(ocelot); 13936b73b7c9SVladimir Oltean ocelot_deinit(ocelot); 13946b73b7c9SVladimir Oltean 13956b73b7c9SVladimir Oltean out_mdiobus_free: 13966b73b7c9SVladimir Oltean if (felix->info->mdio_bus_free) 13976b73b7c9SVladimir Oltean felix->info->mdio_bus_free(ocelot); 13986b73b7c9SVladimir Oltean 13996b73b7c9SVladimir Oltean return err; 140056051948SVladimir Oltean } 140156051948SVladimir Oltean 140256051948SVladimir Oltean static void felix_teardown(struct dsa_switch *ds) 140356051948SVladimir Oltean { 140456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 1405bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 14062960bb14SVladimir Oltean struct dsa_port *dp; 1407bdeced75SVladimir Oltean 14082960bb14SVladimir Oltean dsa_switch_for_each_cpu_port(dp, ds) { 14092960bb14SVladimir Oltean felix_del_tag_protocol(ds, dp->index, felix->tag_proto); 14108d5f7954SVladimir Oltean break; 1411adb3dccfSVladimir Oltean } 1412adb3dccfSVladimir Oltean 14132960bb14SVladimir Oltean dsa_switch_for_each_available_port(dp, ds) 14142960bb14SVladimir Oltean ocelot_deinit_port(ocelot, dp->index); 1415d19741b0SVladimir Oltean 141649f885b2SVladimir Oltean ocelot_devlink_sb_unregister(ocelot); 141749f885b2SVladimir Oltean ocelot_deinit_timestamp(ocelot); 141849f885b2SVladimir Oltean ocelot_deinit(ocelot); 141949f885b2SVladimir Oltean 1420d19741b0SVladimir Oltean if (felix->info->mdio_bus_free) 1421d19741b0SVladimir Oltean felix->info->mdio_bus_free(ocelot); 142256051948SVladimir Oltean } 142356051948SVladimir Oltean 1424c0bcf537SYangbo Lu static int felix_hwtstamp_get(struct dsa_switch *ds, int port, 1425c0bcf537SYangbo Lu struct ifreq *ifr) 1426c0bcf537SYangbo Lu { 1427c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1428c0bcf537SYangbo Lu 1429c0bcf537SYangbo Lu return ocelot_hwstamp_get(ocelot, port, ifr); 1430c0bcf537SYangbo Lu } 1431c0bcf537SYangbo Lu 1432c0bcf537SYangbo Lu static int felix_hwtstamp_set(struct dsa_switch *ds, int port, 1433c0bcf537SYangbo Lu struct ifreq *ifr) 1434c0bcf537SYangbo Lu { 1435c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 143699348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 143799348004SVladimir Oltean bool using_tag_8021q; 143899348004SVladimir Oltean int err; 1439c0bcf537SYangbo Lu 144099348004SVladimir Oltean err = ocelot_hwstamp_set(ocelot, port, ifr); 144199348004SVladimir Oltean if (err) 144299348004SVladimir Oltean return err; 144399348004SVladimir Oltean 144499348004SVladimir Oltean using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; 144599348004SVladimir Oltean 144699348004SVladimir Oltean return felix_update_trapping_destinations(ds, using_tag_8021q); 1447c0bcf537SYangbo Lu } 1448c0bcf537SYangbo Lu 1449d219b4b6SVladimir Oltean static bool felix_check_xtr_pkt(struct ocelot *ocelot) 14500a6f17c6SVladimir Oltean { 14510a6f17c6SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1452dbd03285SVladimir Oltean int err = 0, grp = 0; 14530a6f17c6SVladimir Oltean 14540a6f17c6SVladimir Oltean if (felix->tag_proto != DSA_TAG_PROTO_OCELOT_8021Q) 14550a6f17c6SVladimir Oltean return false; 14560a6f17c6SVladimir Oltean 14570a6f17c6SVladimir Oltean if (!felix->info->quirk_no_xtr_irq) 14580a6f17c6SVladimir Oltean return false; 14590a6f17c6SVladimir Oltean 14600a6f17c6SVladimir Oltean while (ocelot_read(ocelot, QS_XTR_DATA_PRESENT) & BIT(grp)) { 14610a6f17c6SVladimir Oltean struct sk_buff *skb; 14620a6f17c6SVladimir Oltean unsigned int type; 14630a6f17c6SVladimir Oltean 14640a6f17c6SVladimir Oltean err = ocelot_xtr_poll_frame(ocelot, grp, &skb); 14650a6f17c6SVladimir Oltean if (err) 14660a6f17c6SVladimir Oltean goto out; 14670a6f17c6SVladimir Oltean 14680a6f17c6SVladimir Oltean /* We trap to the CPU port module all PTP frames, but 14690a6f17c6SVladimir Oltean * felix_rxtstamp() only gets called for event frames. 14700a6f17c6SVladimir Oltean * So we need to avoid sending duplicate general 14710a6f17c6SVladimir Oltean * message frames by running a second BPF classifier 14720a6f17c6SVladimir Oltean * here and dropping those. 14730a6f17c6SVladimir Oltean */ 14740a6f17c6SVladimir Oltean __skb_push(skb, ETH_HLEN); 14750a6f17c6SVladimir Oltean 14760a6f17c6SVladimir Oltean type = ptp_classify_raw(skb); 14770a6f17c6SVladimir Oltean 14780a6f17c6SVladimir Oltean __skb_pull(skb, ETH_HLEN); 14790a6f17c6SVladimir Oltean 14800a6f17c6SVladimir Oltean if (type == PTP_CLASS_NONE) { 14810a6f17c6SVladimir Oltean kfree_skb(skb); 14820a6f17c6SVladimir Oltean continue; 14830a6f17c6SVladimir Oltean } 14840a6f17c6SVladimir Oltean 14850a6f17c6SVladimir Oltean netif_rx(skb); 14860a6f17c6SVladimir Oltean } 14870a6f17c6SVladimir Oltean 14880a6f17c6SVladimir Oltean out: 14895d3bb7ddSVladimir Oltean if (err < 0) { 14905d3bb7ddSVladimir Oltean dev_err_ratelimited(ocelot->dev, 14915d3bb7ddSVladimir Oltean "Error during packet extraction: %pe\n", 14925d3bb7ddSVladimir Oltean ERR_PTR(err)); 14930a6f17c6SVladimir Oltean ocelot_drain_cpu_queue(ocelot, 0); 14945d3bb7ddSVladimir Oltean } 14950a6f17c6SVladimir Oltean 14960a6f17c6SVladimir Oltean return true; 14970a6f17c6SVladimir Oltean } 14980a6f17c6SVladimir Oltean 1499c0bcf537SYangbo Lu static bool felix_rxtstamp(struct dsa_switch *ds, int port, 1500c0bcf537SYangbo Lu struct sk_buff *skb, unsigned int type) 1501c0bcf537SYangbo Lu { 150292f62485SVladimir Oltean u32 tstamp_lo = OCELOT_SKB_CB(skb)->tstamp_lo; 1503c0bcf537SYangbo Lu struct skb_shared_hwtstamps *shhwtstamps; 1504c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1505c0bcf537SYangbo Lu struct timespec64 ts; 150692f62485SVladimir Oltean u32 tstamp_hi; 150792f62485SVladimir Oltean u64 tstamp; 1508c0bcf537SYangbo Lu 15090a6f17c6SVladimir Oltean /* If the "no XTR IRQ" workaround is in use, tell DSA to defer this skb 15100a6f17c6SVladimir Oltean * for RX timestamping. Then free it, and poll for its copy through 15110a6f17c6SVladimir Oltean * MMIO in the CPU port module, and inject that into the stack from 15120a6f17c6SVladimir Oltean * ocelot_xtr_poll(). 15130a6f17c6SVladimir Oltean */ 1514d219b4b6SVladimir Oltean if (felix_check_xtr_pkt(ocelot)) { 15150a6f17c6SVladimir Oltean kfree_skb(skb); 15160a6f17c6SVladimir Oltean return true; 15170a6f17c6SVladimir Oltean } 15180a6f17c6SVladimir Oltean 1519c0bcf537SYangbo Lu ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); 1520c0bcf537SYangbo Lu tstamp = ktime_set(ts.tv_sec, ts.tv_nsec); 1521c0bcf537SYangbo Lu 1522c0bcf537SYangbo Lu tstamp_hi = tstamp >> 32; 1523c0bcf537SYangbo Lu if ((tstamp & 0xffffffff) < tstamp_lo) 1524c0bcf537SYangbo Lu tstamp_hi--; 1525c0bcf537SYangbo Lu 1526c0bcf537SYangbo Lu tstamp = ((u64)tstamp_hi << 32) | tstamp_lo; 1527c0bcf537SYangbo Lu 1528c0bcf537SYangbo Lu shhwtstamps = skb_hwtstamps(skb); 1529c0bcf537SYangbo Lu memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); 1530c0bcf537SYangbo Lu shhwtstamps->hwtstamp = tstamp; 1531c0bcf537SYangbo Lu return false; 1532c0bcf537SYangbo Lu } 1533c0bcf537SYangbo Lu 15345c5416f5SYangbo Lu static void felix_txtstamp(struct dsa_switch *ds, int port, 15355c5416f5SYangbo Lu struct sk_buff *skb) 1536c0bcf537SYangbo Lu { 1537c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1538682eaad9SYangbo Lu struct sk_buff *clone = NULL; 1539c0bcf537SYangbo Lu 1540682eaad9SYangbo Lu if (!ocelot->ptp) 15415c5416f5SYangbo Lu return; 1542c0bcf537SYangbo Lu 154352849bcfSVladimir Oltean if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) { 154452849bcfSVladimir Oltean dev_err_ratelimited(ds->dev, 154552849bcfSVladimir Oltean "port %d delivering skb without TX timestamp\n", 154652849bcfSVladimir Oltean port); 1547682eaad9SYangbo Lu return; 154852849bcfSVladimir Oltean } 1549682eaad9SYangbo Lu 1550682eaad9SYangbo Lu if (clone) 1551c4b364ceSYangbo Lu OCELOT_SKB_CB(skb)->clone = clone; 15525c5416f5SYangbo Lu } 1553c0bcf537SYangbo Lu 15540b912fc9SVladimir Oltean static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 15550b912fc9SVladimir Oltean { 15560b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 15570b912fc9SVladimir Oltean 15580b912fc9SVladimir Oltean ocelot_port_set_maxlen(ocelot, port, new_mtu); 15590b912fc9SVladimir Oltean 15600b912fc9SVladimir Oltean return 0; 15610b912fc9SVladimir Oltean } 15620b912fc9SVladimir Oltean 15630b912fc9SVladimir Oltean static int felix_get_max_mtu(struct dsa_switch *ds, int port) 15640b912fc9SVladimir Oltean { 15650b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 15660b912fc9SVladimir Oltean 15670b912fc9SVladimir Oltean return ocelot_get_max_mtu(ocelot, port); 15680b912fc9SVladimir Oltean } 15690b912fc9SVladimir Oltean 157007d985eeSVladimir Oltean static int felix_cls_flower_add(struct dsa_switch *ds, int port, 157107d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 157207d985eeSVladimir Oltean { 157307d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 157499348004SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 157599348004SVladimir Oltean bool using_tag_8021q; 157699348004SVladimir Oltean int err; 157707d985eeSVladimir Oltean 157899348004SVladimir Oltean err = ocelot_cls_flower_replace(ocelot, port, cls, ingress); 157999348004SVladimir Oltean if (err) 158099348004SVladimir Oltean return err; 158199348004SVladimir Oltean 158299348004SVladimir Oltean using_tag_8021q = felix->tag_proto == DSA_TAG_PROTO_OCELOT_8021Q; 158399348004SVladimir Oltean 158499348004SVladimir Oltean return felix_update_trapping_destinations(ds, using_tag_8021q); 158507d985eeSVladimir Oltean } 158607d985eeSVladimir Oltean 158707d985eeSVladimir Oltean static int felix_cls_flower_del(struct dsa_switch *ds, int port, 158807d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 158907d985eeSVladimir Oltean { 159007d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 159107d985eeSVladimir Oltean 159207d985eeSVladimir Oltean return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); 159307d985eeSVladimir Oltean } 159407d985eeSVladimir Oltean 159507d985eeSVladimir Oltean static int felix_cls_flower_stats(struct dsa_switch *ds, int port, 159607d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 159707d985eeSVladimir Oltean { 159807d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 159907d985eeSVladimir Oltean 160007d985eeSVladimir Oltean return ocelot_cls_flower_stats(ocelot, port, cls, ingress); 160107d985eeSVladimir Oltean } 160207d985eeSVladimir Oltean 1603fc411eaaSVladimir Oltean static int felix_port_policer_add(struct dsa_switch *ds, int port, 1604fc411eaaSVladimir Oltean struct dsa_mall_policer_tc_entry *policer) 1605fc411eaaSVladimir Oltean { 1606fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1607fc411eaaSVladimir Oltean struct ocelot_policer pol = { 1608fc411eaaSVladimir Oltean .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, 16095f035af7SPo Liu .burst = policer->burst, 1610fc411eaaSVladimir Oltean }; 1611fc411eaaSVladimir Oltean 1612fc411eaaSVladimir Oltean return ocelot_port_policer_add(ocelot, port, &pol); 1613fc411eaaSVladimir Oltean } 1614fc411eaaSVladimir Oltean 1615fc411eaaSVladimir Oltean static void felix_port_policer_del(struct dsa_switch *ds, int port) 1616fc411eaaSVladimir Oltean { 1617fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1618fc411eaaSVladimir Oltean 1619fc411eaaSVladimir Oltean ocelot_port_policer_del(ocelot, port); 1620fc411eaaSVladimir Oltean } 1621fc411eaaSVladimir Oltean 16225e497497SVladimir Oltean static int felix_port_mirror_add(struct dsa_switch *ds, int port, 16235e497497SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror, 16245e497497SVladimir Oltean bool ingress, struct netlink_ext_ack *extack) 16255e497497SVladimir Oltean { 16265e497497SVladimir Oltean struct ocelot *ocelot = ds->priv; 16275e497497SVladimir Oltean 16285e497497SVladimir Oltean return ocelot_port_mirror_add(ocelot, port, mirror->to_local_port, 16295e497497SVladimir Oltean ingress, extack); 16305e497497SVladimir Oltean } 16315e497497SVladimir Oltean 16325e497497SVladimir Oltean static void felix_port_mirror_del(struct dsa_switch *ds, int port, 16335e497497SVladimir Oltean struct dsa_mall_mirror_tc_entry *mirror) 16345e497497SVladimir Oltean { 16355e497497SVladimir Oltean struct ocelot *ocelot = ds->priv; 16365e497497SVladimir Oltean 16375e497497SVladimir Oltean ocelot_port_mirror_del(ocelot, port, mirror->ingress); 16385e497497SVladimir Oltean } 16395e497497SVladimir Oltean 1640de143c0eSXiaoliang Yang static int felix_port_setup_tc(struct dsa_switch *ds, int port, 1641de143c0eSXiaoliang Yang enum tc_setup_type type, 1642de143c0eSXiaoliang Yang void *type_data) 1643de143c0eSXiaoliang Yang { 1644de143c0eSXiaoliang Yang struct ocelot *ocelot = ds->priv; 1645de143c0eSXiaoliang Yang struct felix *felix = ocelot_to_felix(ocelot); 1646de143c0eSXiaoliang Yang 1647de143c0eSXiaoliang Yang if (felix->info->port_setup_tc) 1648de143c0eSXiaoliang Yang return felix->info->port_setup_tc(ds, port, type, type_data); 1649de143c0eSXiaoliang Yang else 1650de143c0eSXiaoliang Yang return -EOPNOTSUPP; 1651de143c0eSXiaoliang Yang } 1652de143c0eSXiaoliang Yang 1653f59fd9caSVladimir Oltean static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index, 1654f59fd9caSVladimir Oltean u16 pool_index, 1655f59fd9caSVladimir Oltean struct devlink_sb_pool_info *pool_info) 1656f59fd9caSVladimir Oltean { 1657f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1658f59fd9caSVladimir Oltean 1659f59fd9caSVladimir Oltean return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info); 1660f59fd9caSVladimir Oltean } 1661f59fd9caSVladimir Oltean 1662f59fd9caSVladimir Oltean static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index, 1663f59fd9caSVladimir Oltean u16 pool_index, u32 size, 1664f59fd9caSVladimir Oltean enum devlink_sb_threshold_type threshold_type, 1665f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1666f59fd9caSVladimir Oltean { 1667f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1668f59fd9caSVladimir Oltean 1669f59fd9caSVladimir Oltean return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size, 1670f59fd9caSVladimir Oltean threshold_type, extack); 1671f59fd9caSVladimir Oltean } 1672f59fd9caSVladimir Oltean 1673f59fd9caSVladimir Oltean static int felix_sb_port_pool_get(struct dsa_switch *ds, int port, 1674f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1675f59fd9caSVladimir Oltean u32 *p_threshold) 1676f59fd9caSVladimir Oltean { 1677f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1678f59fd9caSVladimir Oltean 1679f59fd9caSVladimir Oltean return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index, 1680f59fd9caSVladimir Oltean p_threshold); 1681f59fd9caSVladimir Oltean } 1682f59fd9caSVladimir Oltean 1683f59fd9caSVladimir Oltean static int felix_sb_port_pool_set(struct dsa_switch *ds, int port, 1684f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1685f59fd9caSVladimir Oltean u32 threshold, struct netlink_ext_ack *extack) 1686f59fd9caSVladimir Oltean { 1687f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1688f59fd9caSVladimir Oltean 1689f59fd9caSVladimir Oltean return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index, 1690f59fd9caSVladimir Oltean threshold, extack); 1691f59fd9caSVladimir Oltean } 1692f59fd9caSVladimir Oltean 1693f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port, 1694f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1695f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1696f59fd9caSVladimir Oltean u16 *p_pool_index, u32 *p_threshold) 1697f59fd9caSVladimir Oltean { 1698f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1699f59fd9caSVladimir Oltean 1700f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index, 1701f59fd9caSVladimir Oltean pool_type, p_pool_index, 1702f59fd9caSVladimir Oltean p_threshold); 1703f59fd9caSVladimir Oltean } 1704f59fd9caSVladimir Oltean 1705f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port, 1706f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1707f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1708f59fd9caSVladimir Oltean u16 pool_index, u32 threshold, 1709f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1710f59fd9caSVladimir Oltean { 1711f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1712f59fd9caSVladimir Oltean 1713f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index, 1714f59fd9caSVladimir Oltean pool_type, pool_index, threshold, 1715f59fd9caSVladimir Oltean extack); 1716f59fd9caSVladimir Oltean } 1717f59fd9caSVladimir Oltean 1718f59fd9caSVladimir Oltean static int felix_sb_occ_snapshot(struct dsa_switch *ds, 1719f59fd9caSVladimir Oltean unsigned int sb_index) 1720f59fd9caSVladimir Oltean { 1721f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1722f59fd9caSVladimir Oltean 1723f59fd9caSVladimir Oltean return ocelot_sb_occ_snapshot(ocelot, sb_index); 1724f59fd9caSVladimir Oltean } 1725f59fd9caSVladimir Oltean 1726f59fd9caSVladimir Oltean static int felix_sb_occ_max_clear(struct dsa_switch *ds, 1727f59fd9caSVladimir Oltean unsigned int sb_index) 1728f59fd9caSVladimir Oltean { 1729f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1730f59fd9caSVladimir Oltean 1731f59fd9caSVladimir Oltean return ocelot_sb_occ_max_clear(ocelot, sb_index); 1732f59fd9caSVladimir Oltean } 1733f59fd9caSVladimir Oltean 1734f59fd9caSVladimir Oltean static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port, 1735f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1736f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1737f59fd9caSVladimir Oltean { 1738f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1739f59fd9caSVladimir Oltean 1740f59fd9caSVladimir Oltean return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index, 1741f59fd9caSVladimir Oltean p_cur, p_max); 1742f59fd9caSVladimir Oltean } 1743f59fd9caSVladimir Oltean 1744f59fd9caSVladimir Oltean static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port, 1745f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1746f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1747f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1748f59fd9caSVladimir Oltean { 1749f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1750f59fd9caSVladimir Oltean 1751f59fd9caSVladimir Oltean return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index, 1752f59fd9caSVladimir Oltean pool_type, p_cur, p_max); 1753f59fd9caSVladimir Oltean } 1754f59fd9caSVladimir Oltean 1755a026c50bSHoratiu Vultur static int felix_mrp_add(struct dsa_switch *ds, int port, 1756a026c50bSHoratiu Vultur const struct switchdev_obj_mrp *mrp) 1757a026c50bSHoratiu Vultur { 1758a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1759a026c50bSHoratiu Vultur 1760a026c50bSHoratiu Vultur return ocelot_mrp_add(ocelot, port, mrp); 1761a026c50bSHoratiu Vultur } 1762a026c50bSHoratiu Vultur 1763a026c50bSHoratiu Vultur static int felix_mrp_del(struct dsa_switch *ds, int port, 1764a026c50bSHoratiu Vultur const struct switchdev_obj_mrp *mrp) 1765a026c50bSHoratiu Vultur { 1766a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1767a026c50bSHoratiu Vultur 1768a026c50bSHoratiu Vultur return ocelot_mrp_add(ocelot, port, mrp); 1769a026c50bSHoratiu Vultur } 1770a026c50bSHoratiu Vultur 1771a026c50bSHoratiu Vultur static int 1772a026c50bSHoratiu Vultur felix_mrp_add_ring_role(struct dsa_switch *ds, int port, 1773a026c50bSHoratiu Vultur const struct switchdev_obj_ring_role_mrp *mrp) 1774a026c50bSHoratiu Vultur { 1775a026c50bSHoratiu Vultur struct ocelot *ocelot = ds->priv; 1776a026c50bSHoratiu Vultur 1777a026c50bSHoratiu Vultur return ocelot_mrp_add_ring_role(ocelot, port, mrp); 1778a026c50bSHoratiu Vultur } 1779a026c50bSHoratiu Vultur 1780a026c50bSHoratiu Vultur static int 1781a026c50bSHoratiu Vultur felix_mrp_del_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_del_ring_role(ocelot, port, mrp); 1787a026c50bSHoratiu Vultur } 1788a026c50bSHoratiu Vultur 1789978777d0SVladimir Oltean static int felix_port_get_default_prio(struct dsa_switch *ds, int port) 1790978777d0SVladimir Oltean { 1791978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1792978777d0SVladimir Oltean 1793978777d0SVladimir Oltean return ocelot_port_get_default_prio(ocelot, port); 1794978777d0SVladimir Oltean } 1795978777d0SVladimir Oltean 1796978777d0SVladimir Oltean static int felix_port_set_default_prio(struct dsa_switch *ds, int port, 1797978777d0SVladimir Oltean u8 prio) 1798978777d0SVladimir Oltean { 1799978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1800978777d0SVladimir Oltean 1801978777d0SVladimir Oltean return ocelot_port_set_default_prio(ocelot, port, prio); 1802978777d0SVladimir Oltean } 1803978777d0SVladimir Oltean 1804978777d0SVladimir Oltean static int felix_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) 1805978777d0SVladimir Oltean { 1806978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1807978777d0SVladimir Oltean 1808978777d0SVladimir Oltean return ocelot_port_get_dscp_prio(ocelot, port, dscp); 1809978777d0SVladimir Oltean } 1810978777d0SVladimir Oltean 1811978777d0SVladimir Oltean static int felix_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, 1812978777d0SVladimir Oltean u8 prio) 1813978777d0SVladimir Oltean { 1814978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1815978777d0SVladimir Oltean 1816978777d0SVladimir Oltean return ocelot_port_add_dscp_prio(ocelot, port, dscp, prio); 1817978777d0SVladimir Oltean } 1818978777d0SVladimir Oltean 1819978777d0SVladimir Oltean static int felix_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, 1820978777d0SVladimir Oltean u8 prio) 1821978777d0SVladimir Oltean { 1822978777d0SVladimir Oltean struct ocelot *ocelot = ds->priv; 1823978777d0SVladimir Oltean 1824978777d0SVladimir Oltean return ocelot_port_del_dscp_prio(ocelot, port, dscp, prio); 1825978777d0SVladimir Oltean } 1826978777d0SVladimir Oltean 1827375e1314SVladimir Oltean const struct dsa_switch_ops felix_switch_ops = { 182856051948SVladimir Oltean .get_tag_protocol = felix_get_tag_protocol, 1829adb3dccfSVladimir Oltean .change_tag_protocol = felix_change_tag_protocol, 183035d97680SVladimir Oltean .connect_tag_protocol = felix_connect_tag_protocol, 183156051948SVladimir Oltean .setup = felix_setup, 183256051948SVladimir Oltean .teardown = felix_teardown, 183356051948SVladimir Oltean .set_ageing_time = felix_set_ageing_time, 183456051948SVladimir Oltean .get_strings = felix_get_strings, 183556051948SVladimir Oltean .get_ethtool_stats = felix_get_ethtool_stats, 183656051948SVladimir Oltean .get_sset_count = felix_get_sset_count, 183756051948SVladimir Oltean .get_ts_info = felix_get_ts_info, 183879fda660SRussell King (Oracle) .phylink_get_caps = felix_phylink_get_caps, 1839bdeced75SVladimir Oltean .phylink_validate = felix_phylink_validate, 1840864ba485SRussell King (Oracle) .phylink_mac_select_pcs = felix_phylink_mac_select_pcs, 1841bdeced75SVladimir Oltean .phylink_mac_link_down = felix_phylink_mac_link_down, 1842bdeced75SVladimir Oltean .phylink_mac_link_up = felix_phylink_mac_link_up, 18435cad43a5SVladimir Oltean .port_fast_age = felix_port_fast_age, 184456051948SVladimir Oltean .port_fdb_dump = felix_fdb_dump, 184556051948SVladimir Oltean .port_fdb_add = felix_fdb_add, 184656051948SVladimir Oltean .port_fdb_del = felix_fdb_del, 1847961d8b69SVladimir Oltean .lag_fdb_add = felix_lag_fdb_add, 1848961d8b69SVladimir Oltean .lag_fdb_del = felix_lag_fdb_del, 1849209edf95SVladimir Oltean .port_mdb_add = felix_mdb_add, 1850209edf95SVladimir Oltean .port_mdb_del = felix_mdb_del, 1851421741eaSVladimir Oltean .port_pre_bridge_flags = felix_pre_bridge_flags, 1852421741eaSVladimir Oltean .port_bridge_flags = felix_bridge_flags, 185356051948SVladimir Oltean .port_bridge_join = felix_bridge_join, 185456051948SVladimir Oltean .port_bridge_leave = felix_bridge_leave, 18558fe6832eSVladimir Oltean .port_lag_join = felix_lag_join, 18568fe6832eSVladimir Oltean .port_lag_leave = felix_lag_leave, 18578fe6832eSVladimir Oltean .port_lag_change = felix_lag_change, 185856051948SVladimir Oltean .port_stp_state_set = felix_bridge_stp_state_set, 185956051948SVladimir Oltean .port_vlan_filtering = felix_vlan_filtering, 186056051948SVladimir Oltean .port_vlan_add = felix_vlan_add, 186156051948SVladimir Oltean .port_vlan_del = felix_vlan_del, 1862c0bcf537SYangbo Lu .port_hwtstamp_get = felix_hwtstamp_get, 1863c0bcf537SYangbo Lu .port_hwtstamp_set = felix_hwtstamp_set, 1864c0bcf537SYangbo Lu .port_rxtstamp = felix_rxtstamp, 1865c0bcf537SYangbo Lu .port_txtstamp = felix_txtstamp, 18660b912fc9SVladimir Oltean .port_change_mtu = felix_change_mtu, 18670b912fc9SVladimir Oltean .port_max_mtu = felix_get_max_mtu, 1868fc411eaaSVladimir Oltean .port_policer_add = felix_port_policer_add, 1869fc411eaaSVladimir Oltean .port_policer_del = felix_port_policer_del, 18705e497497SVladimir Oltean .port_mirror_add = felix_port_mirror_add, 18715e497497SVladimir Oltean .port_mirror_del = felix_port_mirror_del, 187207d985eeSVladimir Oltean .cls_flower_add = felix_cls_flower_add, 187307d985eeSVladimir Oltean .cls_flower_del = felix_cls_flower_del, 187407d985eeSVladimir Oltean .cls_flower_stats = felix_cls_flower_stats, 1875de143c0eSXiaoliang Yang .port_setup_tc = felix_port_setup_tc, 1876f59fd9caSVladimir Oltean .devlink_sb_pool_get = felix_sb_pool_get, 1877f59fd9caSVladimir Oltean .devlink_sb_pool_set = felix_sb_pool_set, 1878f59fd9caSVladimir Oltean .devlink_sb_port_pool_get = felix_sb_port_pool_get, 1879f59fd9caSVladimir Oltean .devlink_sb_port_pool_set = felix_sb_port_pool_set, 1880f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get, 1881f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set, 1882f59fd9caSVladimir Oltean .devlink_sb_occ_snapshot = felix_sb_occ_snapshot, 1883f59fd9caSVladimir Oltean .devlink_sb_occ_max_clear = felix_sb_occ_max_clear, 1884f59fd9caSVladimir Oltean .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get, 1885f59fd9caSVladimir Oltean .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get, 1886a026c50bSHoratiu Vultur .port_mrp_add = felix_mrp_add, 1887a026c50bSHoratiu Vultur .port_mrp_del = felix_mrp_del, 1888a026c50bSHoratiu Vultur .port_mrp_add_ring_role = felix_mrp_add_ring_role, 1889a026c50bSHoratiu Vultur .port_mrp_del_ring_role = felix_mrp_del_ring_role, 18905da11eb4SVladimir Oltean .tag_8021q_vlan_add = felix_tag_8021q_vlan_add, 18915da11eb4SVladimir Oltean .tag_8021q_vlan_del = felix_tag_8021q_vlan_del, 1892978777d0SVladimir Oltean .port_get_default_prio = felix_port_get_default_prio, 1893978777d0SVladimir Oltean .port_set_default_prio = felix_port_set_default_prio, 1894978777d0SVladimir Oltean .port_get_dscp_prio = felix_port_get_dscp_prio, 1895978777d0SVladimir Oltean .port_add_dscp_prio = felix_port_add_dscp_prio, 1896978777d0SVladimir Oltean .port_del_dscp_prio = felix_port_del_dscp_prio, 189756051948SVladimir Oltean }; 1898319e4dd1SVladimir Oltean 1899319e4dd1SVladimir Oltean struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) 1900319e4dd1SVladimir Oltean { 1901319e4dd1SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1902319e4dd1SVladimir Oltean struct dsa_switch *ds = felix->ds; 1903319e4dd1SVladimir Oltean 1904319e4dd1SVladimir Oltean if (!dsa_is_user_port(ds, port)) 1905319e4dd1SVladimir Oltean return NULL; 1906319e4dd1SVladimir Oltean 1907319e4dd1SVladimir Oltean return dsa_to_port(ds, port)->slave; 1908319e4dd1SVladimir Oltean } 1909319e4dd1SVladimir Oltean 1910319e4dd1SVladimir Oltean int felix_netdev_to_port(struct net_device *dev) 1911319e4dd1SVladimir Oltean { 1912319e4dd1SVladimir Oltean struct dsa_port *dp; 1913319e4dd1SVladimir Oltean 1914319e4dd1SVladimir Oltean dp = dsa_port_from_netdev(dev); 1915319e4dd1SVladimir Oltean if (IS_ERR(dp)) 1916319e4dd1SVladimir Oltean return -EINVAL; 1917319e4dd1SVladimir Oltean 1918319e4dd1SVladimir Oltean return dp->index; 1919319e4dd1SVladimir Oltean } 1920