156051948SVladimir Oltean // SPDX-License-Identifier: GPL-2.0 2adb3dccfSVladimir Oltean /* Copyright 2019-2021 NXP Semiconductors 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> 1956051948SVladimir Oltean #include <linux/module.h> 20bdeced75SVladimir Oltean #include <linux/of_net.h> 2156051948SVladimir Oltean #include <linux/pci.h> 2256051948SVladimir Oltean #include <linux/of.h> 23588d0550SIoana Ciornei #include <linux/pcs-lynx.h> 24fc411eaaSVladimir Oltean #include <net/pkt_sched.h> 2556051948SVladimir Oltean #include <net/dsa.h> 2656051948SVladimir Oltean #include "felix.h" 2756051948SVladimir Oltean 28e21268efSVladimir Oltean static int felix_tag_8021q_rxvlan_add(struct felix *felix, int port, u16 vid, 29e21268efSVladimir Oltean bool pvid, bool untagged) 30e21268efSVladimir Oltean { 31e21268efSVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 32e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 33e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 34e21268efSVladimir Oltean int key_length, upstream, err; 35e21268efSVladimir Oltean 36e21268efSVladimir Oltean /* We don't need to install the rxvlan into the other ports' filtering 37e21268efSVladimir Oltean * tables, because we're just pushing the rxvlan when sending towards 38e21268efSVladimir Oltean * the CPU 39e21268efSVladimir Oltean */ 40e21268efSVladimir Oltean if (!pvid) 41e21268efSVladimir Oltean return 0; 42e21268efSVladimir Oltean 43e21268efSVladimir Oltean key_length = ocelot->vcap[VCAP_ES0].keys[VCAP_ES0_IGR_PORT].length; 44e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 45e21268efSVladimir Oltean 46e21268efSVladimir Oltean outer_tagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), 47e21268efSVladimir Oltean GFP_KERNEL); 48e21268efSVladimir Oltean if (!outer_tagging_rule) 49e21268efSVladimir Oltean return -ENOMEM; 50e21268efSVladimir Oltean 51e21268efSVladimir Oltean outer_tagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 52e21268efSVladimir Oltean outer_tagging_rule->prio = 1; 53e21268efSVladimir Oltean outer_tagging_rule->id.cookie = port; 54e21268efSVladimir Oltean outer_tagging_rule->id.tc_offload = false; 55e21268efSVladimir Oltean outer_tagging_rule->block_id = VCAP_ES0; 56e21268efSVladimir Oltean outer_tagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 57e21268efSVladimir Oltean outer_tagging_rule->lookup = 0; 58e21268efSVladimir Oltean outer_tagging_rule->ingress_port.value = port; 59e21268efSVladimir Oltean outer_tagging_rule->ingress_port.mask = GENMASK(key_length - 1, 0); 60e21268efSVladimir Oltean outer_tagging_rule->egress_port.value = upstream; 61e21268efSVladimir Oltean outer_tagging_rule->egress_port.mask = GENMASK(key_length - 1, 0); 62e21268efSVladimir Oltean outer_tagging_rule->action.push_outer_tag = OCELOT_ES0_TAG; 63e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_tpid_sel = OCELOT_TAG_TPID_SEL_8021AD; 64e21268efSVladimir Oltean outer_tagging_rule->action.tag_a_vid_sel = 1; 65e21268efSVladimir Oltean outer_tagging_rule->action.vid_a_val = vid; 66e21268efSVladimir Oltean 67e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, outer_tagging_rule, NULL); 68e21268efSVladimir Oltean if (err) 69e21268efSVladimir Oltean kfree(outer_tagging_rule); 70e21268efSVladimir Oltean 71e21268efSVladimir Oltean return err; 72e21268efSVladimir Oltean } 73e21268efSVladimir Oltean 74e21268efSVladimir Oltean static int felix_tag_8021q_txvlan_add(struct felix *felix, int port, u16 vid, 75e21268efSVladimir Oltean bool pvid, bool untagged) 76e21268efSVladimir Oltean { 77e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 78e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 79e21268efSVladimir Oltean struct dsa_switch *ds = felix->ds; 80e21268efSVladimir Oltean int upstream, err; 81e21268efSVladimir Oltean 82e21268efSVladimir Oltean /* tag_8021q.c assumes we are implementing this via port VLAN 83e21268efSVladimir Oltean * membership, which we aren't. So we don't need to add any VCAP filter 84e21268efSVladimir Oltean * for the CPU port. 85e21268efSVladimir Oltean */ 86e21268efSVladimir Oltean if (ocelot->ports[port]->is_dsa_8021q_cpu) 87e21268efSVladimir Oltean return 0; 88e21268efSVladimir Oltean 89e21268efSVladimir Oltean untagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 90e21268efSVladimir Oltean if (!untagging_rule) 91e21268efSVladimir Oltean return -ENOMEM; 92e21268efSVladimir Oltean 93e21268efSVladimir Oltean redirect_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); 94e21268efSVladimir Oltean if (!redirect_rule) { 95e21268efSVladimir Oltean kfree(untagging_rule); 96e21268efSVladimir Oltean return -ENOMEM; 97e21268efSVladimir Oltean } 98e21268efSVladimir Oltean 99e21268efSVladimir Oltean upstream = dsa_upstream_port(ds, port); 100e21268efSVladimir Oltean 101e21268efSVladimir Oltean untagging_rule->key_type = OCELOT_VCAP_KEY_ANY; 102e21268efSVladimir Oltean untagging_rule->ingress_port_mask = BIT(upstream); 103e21268efSVladimir Oltean untagging_rule->vlan.vid.value = vid; 104e21268efSVladimir Oltean untagging_rule->vlan.vid.mask = VLAN_VID_MASK; 105e21268efSVladimir Oltean untagging_rule->prio = 1; 106e21268efSVladimir Oltean untagging_rule->id.cookie = port; 107e21268efSVladimir Oltean untagging_rule->id.tc_offload = false; 108e21268efSVladimir Oltean untagging_rule->block_id = VCAP_IS1; 109e21268efSVladimir Oltean untagging_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 110e21268efSVladimir Oltean untagging_rule->lookup = 0; 111e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt_ena = true; 112e21268efSVladimir Oltean untagging_rule->action.vlan_pop_cnt = 1; 113e21268efSVladimir Oltean untagging_rule->action.pag_override_mask = 0xff; 114e21268efSVladimir Oltean untagging_rule->action.pag_val = port; 115e21268efSVladimir Oltean 116e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, untagging_rule, NULL); 117e21268efSVladimir Oltean if (err) { 118e21268efSVladimir Oltean kfree(untagging_rule); 119e21268efSVladimir Oltean kfree(redirect_rule); 120e21268efSVladimir Oltean return err; 121e21268efSVladimir Oltean } 122e21268efSVladimir Oltean 123e21268efSVladimir Oltean redirect_rule->key_type = OCELOT_VCAP_KEY_ANY; 124e21268efSVladimir Oltean redirect_rule->ingress_port_mask = BIT(upstream); 125e21268efSVladimir Oltean redirect_rule->pag = port; 126e21268efSVladimir Oltean redirect_rule->prio = 1; 127e21268efSVladimir Oltean redirect_rule->id.cookie = port; 128e21268efSVladimir Oltean redirect_rule->id.tc_offload = false; 129e21268efSVladimir Oltean redirect_rule->block_id = VCAP_IS2; 130e21268efSVladimir Oltean redirect_rule->type = OCELOT_VCAP_FILTER_OFFLOAD; 131e21268efSVladimir Oltean redirect_rule->lookup = 0; 132e21268efSVladimir Oltean redirect_rule->action.mask_mode = OCELOT_MASK_MODE_REDIRECT; 133e21268efSVladimir Oltean redirect_rule->action.port_mask = BIT(port); 134e21268efSVladimir Oltean 135e21268efSVladimir Oltean err = ocelot_vcap_filter_add(ocelot, redirect_rule, NULL); 136e21268efSVladimir Oltean if (err) { 137e21268efSVladimir Oltean ocelot_vcap_filter_del(ocelot, untagging_rule); 138e21268efSVladimir Oltean kfree(redirect_rule); 139e21268efSVladimir Oltean return err; 140e21268efSVladimir Oltean } 141e21268efSVladimir Oltean 142e21268efSVladimir Oltean return 0; 143e21268efSVladimir Oltean } 144e21268efSVladimir Oltean 145e21268efSVladimir Oltean static int felix_tag_8021q_vlan_add(struct dsa_switch *ds, int port, u16 vid, 146e21268efSVladimir Oltean u16 flags) 147e21268efSVladimir Oltean { 148e21268efSVladimir Oltean bool untagged = flags & BRIDGE_VLAN_INFO_UNTAGGED; 149e21268efSVladimir Oltean bool pvid = flags & BRIDGE_VLAN_INFO_PVID; 150e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 151e21268efSVladimir Oltean 152e21268efSVladimir Oltean if (vid_is_dsa_8021q_rxvlan(vid)) 153e21268efSVladimir Oltean return felix_tag_8021q_rxvlan_add(ocelot_to_felix(ocelot), 154e21268efSVladimir Oltean port, vid, pvid, untagged); 155e21268efSVladimir Oltean 156e21268efSVladimir Oltean if (vid_is_dsa_8021q_txvlan(vid)) 157e21268efSVladimir Oltean return felix_tag_8021q_txvlan_add(ocelot_to_felix(ocelot), 158e21268efSVladimir Oltean port, vid, pvid, untagged); 159e21268efSVladimir Oltean 160e21268efSVladimir Oltean return 0; 161e21268efSVladimir Oltean } 162e21268efSVladimir Oltean 163e21268efSVladimir Oltean static int felix_tag_8021q_rxvlan_del(struct felix *felix, int port, u16 vid) 164e21268efSVladimir Oltean { 165e21268efSVladimir Oltean struct ocelot_vcap_filter *outer_tagging_rule; 166e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_es0; 167e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 168e21268efSVladimir Oltean 169e21268efSVladimir Oltean block_vcap_es0 = &ocelot->block[VCAP_ES0]; 170e21268efSVladimir Oltean 171e21268efSVladimir Oltean outer_tagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_es0, 172e21268efSVladimir Oltean port, false); 173e21268efSVladimir Oltean /* In rxvlan_add, we had the "if (!pvid) return 0" logic to avoid 174e21268efSVladimir Oltean * installing outer tagging ES0 rules where they weren't needed. 175e21268efSVladimir Oltean * But in rxvlan_del, the API doesn't give us the "flags" anymore, 176e21268efSVladimir Oltean * so that forces us to be slightly sloppy here, and just assume that 177e21268efSVladimir Oltean * if we didn't find an outer_tagging_rule it means that there was 178e21268efSVladimir Oltean * none in the first place, i.e. rxvlan_del is called on a non-pvid 179e21268efSVladimir Oltean * port. This is most probably true though. 180e21268efSVladimir Oltean */ 181e21268efSVladimir Oltean if (!outer_tagging_rule) 182e21268efSVladimir Oltean return 0; 183e21268efSVladimir Oltean 184e21268efSVladimir Oltean return ocelot_vcap_filter_del(ocelot, outer_tagging_rule); 185e21268efSVladimir Oltean } 186e21268efSVladimir Oltean 187e21268efSVladimir Oltean static int felix_tag_8021q_txvlan_del(struct felix *felix, int port, u16 vid) 188e21268efSVladimir Oltean { 189e21268efSVladimir Oltean struct ocelot_vcap_filter *untagging_rule, *redirect_rule; 190e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is1; 191e21268efSVladimir Oltean struct ocelot_vcap_block *block_vcap_is2; 192e21268efSVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 193e21268efSVladimir Oltean int err; 194e21268efSVladimir Oltean 195e21268efSVladimir Oltean if (ocelot->ports[port]->is_dsa_8021q_cpu) 196e21268efSVladimir Oltean return 0; 197e21268efSVladimir Oltean 198e21268efSVladimir Oltean block_vcap_is1 = &ocelot->block[VCAP_IS1]; 199e21268efSVladimir Oltean block_vcap_is2 = &ocelot->block[VCAP_IS2]; 200e21268efSVladimir Oltean 201e21268efSVladimir Oltean untagging_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is1, 202e21268efSVladimir Oltean port, false); 203e21268efSVladimir Oltean if (!untagging_rule) 204e21268efSVladimir Oltean return 0; 205e21268efSVladimir Oltean 206e21268efSVladimir Oltean err = ocelot_vcap_filter_del(ocelot, untagging_rule); 207e21268efSVladimir Oltean if (err) 208e21268efSVladimir Oltean return err; 209e21268efSVladimir Oltean 210e21268efSVladimir Oltean redirect_rule = ocelot_vcap_block_find_filter_by_id(block_vcap_is2, 211e21268efSVladimir Oltean port, false); 212e21268efSVladimir Oltean if (!redirect_rule) 213e21268efSVladimir Oltean return 0; 214e21268efSVladimir Oltean 215e21268efSVladimir Oltean return ocelot_vcap_filter_del(ocelot, redirect_rule); 216e21268efSVladimir Oltean } 217e21268efSVladimir Oltean 218e21268efSVladimir Oltean static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) 219e21268efSVladimir Oltean { 220e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 221e21268efSVladimir Oltean 222e21268efSVladimir Oltean if (vid_is_dsa_8021q_rxvlan(vid)) 223e21268efSVladimir Oltean return felix_tag_8021q_rxvlan_del(ocelot_to_felix(ocelot), 224e21268efSVladimir Oltean port, vid); 225e21268efSVladimir Oltean 226e21268efSVladimir Oltean if (vid_is_dsa_8021q_txvlan(vid)) 227e21268efSVladimir Oltean return felix_tag_8021q_txvlan_del(ocelot_to_felix(ocelot), 228e21268efSVladimir Oltean port, vid); 229e21268efSVladimir Oltean 230e21268efSVladimir Oltean return 0; 231e21268efSVladimir Oltean } 232e21268efSVladimir Oltean 233e21268efSVladimir Oltean static const struct dsa_8021q_ops felix_tag_8021q_ops = { 234e21268efSVladimir Oltean .vlan_add = felix_tag_8021q_vlan_add, 235e21268efSVladimir Oltean .vlan_del = felix_tag_8021q_vlan_del, 236e21268efSVladimir Oltean }; 237e21268efSVladimir Oltean 238e21268efSVladimir Oltean /* Alternatively to using the NPI functionality, that same hardware MAC 239e21268efSVladimir Oltean * connected internally to the enetc or fman DSA master can be configured to 240e21268efSVladimir Oltean * use the software-defined tag_8021q frame format. As far as the hardware is 241e21268efSVladimir Oltean * concerned, it thinks it is a "dumb switch" - the queues of the CPU port 242e21268efSVladimir Oltean * module are now disconnected from it, but can still be accessed through 243e21268efSVladimir Oltean * register-based MMIO. 244e21268efSVladimir Oltean */ 245e21268efSVladimir Oltean static void felix_8021q_cpu_port_init(struct ocelot *ocelot, int port) 246e21268efSVladimir Oltean { 247e21268efSVladimir Oltean ocelot->ports[port]->is_dsa_8021q_cpu = true; 248e21268efSVladimir Oltean ocelot->npi = -1; 249e21268efSVladimir Oltean 250e21268efSVladimir Oltean /* Overwrite PGID_CPU with the non-tagging port */ 251e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, PGID_CPU); 252e21268efSVladimir Oltean 253e21268efSVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot); 254e21268efSVladimir Oltean } 255e21268efSVladimir Oltean 256e21268efSVladimir Oltean static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port) 257e21268efSVladimir Oltean { 258e21268efSVladimir Oltean ocelot->ports[port]->is_dsa_8021q_cpu = false; 259e21268efSVladimir Oltean 260e21268efSVladimir Oltean /* Restore PGID_CPU */ 261e21268efSVladimir Oltean ocelot_write_rix(ocelot, BIT(ocelot->num_phys_ports), ANA_PGID_PGID, 262e21268efSVladimir Oltean PGID_CPU); 263e21268efSVladimir Oltean 264e21268efSVladimir Oltean ocelot_apply_bridge_fwd_mask(ocelot); 265e21268efSVladimir Oltean } 266e21268efSVladimir Oltean 267e21268efSVladimir Oltean static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) 268e21268efSVladimir Oltean { 269e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 270e21268efSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 271e21268efSVladimir Oltean unsigned long cpu_flood; 272e21268efSVladimir Oltean int port, err; 273e21268efSVladimir Oltean 274e21268efSVladimir Oltean felix_8021q_cpu_port_init(ocelot, cpu); 275e21268efSVladimir Oltean 276e21268efSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 277e21268efSVladimir Oltean if (dsa_is_unused_port(ds, port)) 278e21268efSVladimir Oltean continue; 279e21268efSVladimir Oltean 280e21268efSVladimir Oltean /* This overwrites ocelot_init(): 281e21268efSVladimir Oltean * Do not forward BPDU frames to the CPU port module, 282e21268efSVladimir Oltean * for 2 reasons: 283e21268efSVladimir Oltean * - When these packets are injected from the tag_8021q 284e21268efSVladimir Oltean * CPU port, we want them to go out, not loop back 285e21268efSVladimir Oltean * into the system. 286e21268efSVladimir Oltean * - STP traffic ingressing on a user port should go to 287e21268efSVladimir Oltean * the tag_8021q CPU port, not to the hardware CPU 288e21268efSVladimir Oltean * port module. 289e21268efSVladimir Oltean */ 290e21268efSVladimir Oltean ocelot_write_gix(ocelot, 291e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0), 292e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, port); 293e21268efSVladimir Oltean } 294e21268efSVladimir Oltean 295e21268efSVladimir Oltean /* In tag_8021q mode, the CPU port module is unused. So we 296e21268efSVladimir Oltean * want to disable flooding of any kind to the CPU port module, 297e21268efSVladimir Oltean * since packets going there will end in a black hole. 298e21268efSVladimir Oltean */ 299e21268efSVladimir Oltean cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)); 300e21268efSVladimir Oltean ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_UC); 301e21268efSVladimir Oltean ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC); 302b360d94fSVladimir Oltean ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_BC); 303e21268efSVladimir Oltean 304e21268efSVladimir Oltean felix->dsa_8021q_ctx = kzalloc(sizeof(*felix->dsa_8021q_ctx), 305e21268efSVladimir Oltean GFP_KERNEL); 306e21268efSVladimir Oltean if (!felix->dsa_8021q_ctx) 307e21268efSVladimir Oltean return -ENOMEM; 308e21268efSVladimir Oltean 309e21268efSVladimir Oltean felix->dsa_8021q_ctx->ops = &felix_tag_8021q_ops; 310e21268efSVladimir Oltean felix->dsa_8021q_ctx->proto = htons(ETH_P_8021AD); 311e21268efSVladimir Oltean felix->dsa_8021q_ctx->ds = ds; 312e21268efSVladimir Oltean 313e21268efSVladimir Oltean err = dsa_8021q_setup(felix->dsa_8021q_ctx, true); 314e21268efSVladimir Oltean if (err) 315e21268efSVladimir Oltean goto out_free_dsa_8021_ctx; 316e21268efSVladimir Oltean 317e21268efSVladimir Oltean return 0; 318e21268efSVladimir Oltean 319e21268efSVladimir Oltean out_free_dsa_8021_ctx: 320e21268efSVladimir Oltean kfree(felix->dsa_8021q_ctx); 321e21268efSVladimir Oltean return err; 322e21268efSVladimir Oltean } 323e21268efSVladimir Oltean 324e21268efSVladimir Oltean static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) 325e21268efSVladimir Oltean { 326e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 327e21268efSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 328e21268efSVladimir Oltean int err, port; 329e21268efSVladimir Oltean 330e21268efSVladimir Oltean err = dsa_8021q_setup(felix->dsa_8021q_ctx, false); 331e21268efSVladimir Oltean if (err) 332e21268efSVladimir Oltean dev_err(ds->dev, "dsa_8021q_setup returned %d", err); 333e21268efSVladimir Oltean 334e21268efSVladimir Oltean kfree(felix->dsa_8021q_ctx); 335e21268efSVladimir Oltean 336e21268efSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 337e21268efSVladimir Oltean if (dsa_is_unused_port(ds, port)) 338e21268efSVladimir Oltean continue; 339e21268efSVladimir Oltean 340e21268efSVladimir Oltean /* Restore the logic from ocelot_init: 341e21268efSVladimir Oltean * do not forward BPDU frames to the front ports. 342e21268efSVladimir Oltean */ 343e21268efSVladimir Oltean ocelot_write_gix(ocelot, 344e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff), 345e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, 346e21268efSVladimir Oltean port); 347e21268efSVladimir Oltean } 348e21268efSVladimir Oltean 349e21268efSVladimir Oltean felix_8021q_cpu_port_deinit(ocelot, cpu); 350e21268efSVladimir Oltean } 351e21268efSVladimir Oltean 352adb3dccfSVladimir Oltean /* The CPU port module is connected to the Node Processor Interface (NPI). This 353adb3dccfSVladimir Oltean * is the mode through which frames can be injected from and extracted to an 354adb3dccfSVladimir Oltean * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU 355adb3dccfSVladimir Oltean * running Linux, and this forms a DSA setup together with the enetc or fman 356adb3dccfSVladimir Oltean * DSA master. 357adb3dccfSVladimir Oltean */ 358adb3dccfSVladimir Oltean static void felix_npi_port_init(struct ocelot *ocelot, int port) 359adb3dccfSVladimir Oltean { 360adb3dccfSVladimir Oltean ocelot->npi = port; 361adb3dccfSVladimir Oltean 362adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M | 363adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port), 364adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 365adb3dccfSVladimir Oltean 366adb3dccfSVladimir Oltean /* NPI port Injection/Extraction configuration */ 367adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 368adb3dccfSVladimir Oltean ocelot->npi_xtr_prefix); 369adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 370adb3dccfSVladimir Oltean ocelot->npi_inj_prefix); 371adb3dccfSVladimir Oltean 372adb3dccfSVladimir Oltean /* Disable transmission of pause frames */ 373adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0); 374adb3dccfSVladimir Oltean } 375adb3dccfSVladimir Oltean 376adb3dccfSVladimir Oltean static void felix_npi_port_deinit(struct ocelot *ocelot, int port) 377adb3dccfSVladimir Oltean { 378adb3dccfSVladimir Oltean /* Restore hardware defaults */ 379adb3dccfSVladimir Oltean int unused_port = ocelot->num_phys_ports + 2; 380adb3dccfSVladimir Oltean 381adb3dccfSVladimir Oltean ocelot->npi = -1; 382adb3dccfSVladimir Oltean 383adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPU_PORT(unused_port), 384adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 385adb3dccfSVladimir Oltean 386adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 387adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 388adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 389adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 390adb3dccfSVladimir Oltean 391adb3dccfSVladimir Oltean /* Enable transmission of pause frames */ 392adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); 393adb3dccfSVladimir Oltean } 394adb3dccfSVladimir Oltean 395adb3dccfSVladimir Oltean static int felix_setup_tag_npi(struct dsa_switch *ds, int cpu) 396adb3dccfSVladimir Oltean { 397adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 398adb3dccfSVladimir Oltean unsigned long cpu_flood; 399adb3dccfSVladimir Oltean 400adb3dccfSVladimir Oltean felix_npi_port_init(ocelot, cpu); 401adb3dccfSVladimir Oltean 402adb3dccfSVladimir Oltean /* Include the CPU port module (and indirectly, the NPI port) 403adb3dccfSVladimir Oltean * in the forwarding mask for unknown unicast - the hardware 404adb3dccfSVladimir Oltean * default value for ANA_FLOODING_FLD_UNICAST excludes 405adb3dccfSVladimir Oltean * BIT(ocelot->num_phys_ports), and so does ocelot_init, 406adb3dccfSVladimir Oltean * since Ocelot relies on whitelisting MAC addresses towards 407adb3dccfSVladimir Oltean * PGID_CPU. 408adb3dccfSVladimir Oltean * We do this because DSA does not yet perform RX filtering, 409adb3dccfSVladimir Oltean * and the NPI port does not perform source address learning, 410adb3dccfSVladimir Oltean * so traffic sent to Linux is effectively unknown from the 411adb3dccfSVladimir Oltean * switch's perspective. 412adb3dccfSVladimir Oltean */ 413adb3dccfSVladimir Oltean cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)); 414adb3dccfSVladimir Oltean ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_UC); 4156edb9e8dSVladimir Oltean ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_MC); 416b360d94fSVladimir Oltean ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_BC); 417adb3dccfSVladimir Oltean 418adb3dccfSVladimir Oltean return 0; 419adb3dccfSVladimir Oltean } 420adb3dccfSVladimir Oltean 421adb3dccfSVladimir Oltean static void felix_teardown_tag_npi(struct dsa_switch *ds, int cpu) 422adb3dccfSVladimir Oltean { 423adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 424adb3dccfSVladimir Oltean 425adb3dccfSVladimir Oltean felix_npi_port_deinit(ocelot, cpu); 426adb3dccfSVladimir Oltean } 427adb3dccfSVladimir Oltean 428adb3dccfSVladimir Oltean static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu, 429adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 430adb3dccfSVladimir Oltean { 431adb3dccfSVladimir Oltean int err; 432adb3dccfSVladimir Oltean 433adb3dccfSVladimir Oltean switch (proto) { 434*7c4bb540SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 435adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 436adb3dccfSVladimir Oltean err = felix_setup_tag_npi(ds, cpu); 437adb3dccfSVladimir Oltean break; 438e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 439e21268efSVladimir Oltean err = felix_setup_tag_8021q(ds, cpu); 440e21268efSVladimir Oltean break; 441adb3dccfSVladimir Oltean default: 442adb3dccfSVladimir Oltean err = -EPROTONOSUPPORT; 443adb3dccfSVladimir Oltean } 444adb3dccfSVladimir Oltean 445adb3dccfSVladimir Oltean return err; 446adb3dccfSVladimir Oltean } 447adb3dccfSVladimir Oltean 448adb3dccfSVladimir Oltean static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu, 449adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 450adb3dccfSVladimir Oltean { 451adb3dccfSVladimir Oltean switch (proto) { 452*7c4bb540SVladimir Oltean case DSA_TAG_PROTO_SEVILLE: 453adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 454adb3dccfSVladimir Oltean felix_teardown_tag_npi(ds, cpu); 455adb3dccfSVladimir Oltean break; 456e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 457e21268efSVladimir Oltean felix_teardown_tag_8021q(ds, cpu); 458e21268efSVladimir Oltean break; 459adb3dccfSVladimir Oltean default: 460adb3dccfSVladimir Oltean break; 461adb3dccfSVladimir Oltean } 462adb3dccfSVladimir Oltean } 463adb3dccfSVladimir Oltean 464e21268efSVladimir Oltean /* This always leaves the switch in a consistent state, because although the 465e21268efSVladimir Oltean * tag_8021q setup can fail, the NPI setup can't. So either the change is made, 466e21268efSVladimir Oltean * or the restoration is guaranteed to work. 467e21268efSVladimir Oltean */ 468adb3dccfSVladimir Oltean static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu, 469adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 470adb3dccfSVladimir Oltean { 471adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 472adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 473adb3dccfSVladimir Oltean enum dsa_tag_protocol old_proto = felix->tag_proto; 474adb3dccfSVladimir Oltean int err; 475adb3dccfSVladimir Oltean 476*7c4bb540SVladimir Oltean if (proto != DSA_TAG_PROTO_SEVILLE && 477*7c4bb540SVladimir Oltean proto != DSA_TAG_PROTO_OCELOT && 478e21268efSVladimir Oltean proto != DSA_TAG_PROTO_OCELOT_8021Q) 479adb3dccfSVladimir Oltean return -EPROTONOSUPPORT; 480adb3dccfSVladimir Oltean 481adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, cpu, old_proto); 482adb3dccfSVladimir Oltean 483adb3dccfSVladimir Oltean err = felix_set_tag_protocol(ds, cpu, proto); 484adb3dccfSVladimir Oltean if (err) { 485adb3dccfSVladimir Oltean felix_set_tag_protocol(ds, cpu, old_proto); 486adb3dccfSVladimir Oltean return err; 487adb3dccfSVladimir Oltean } 488adb3dccfSVladimir Oltean 489adb3dccfSVladimir Oltean felix->tag_proto = proto; 490adb3dccfSVladimir Oltean 491adb3dccfSVladimir Oltean return 0; 492adb3dccfSVladimir Oltean } 493adb3dccfSVladimir Oltean 49456051948SVladimir Oltean static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds, 4954d776482SFlorian Fainelli int port, 4964d776482SFlorian Fainelli enum dsa_tag_protocol mp) 49756051948SVladimir Oltean { 498adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 499adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 500adb3dccfSVladimir Oltean 501adb3dccfSVladimir Oltean return felix->tag_proto; 50256051948SVladimir Oltean } 50356051948SVladimir Oltean 50456051948SVladimir Oltean static int felix_set_ageing_time(struct dsa_switch *ds, 50556051948SVladimir Oltean unsigned int ageing_time) 50656051948SVladimir Oltean { 50756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 50856051948SVladimir Oltean 50956051948SVladimir Oltean ocelot_set_ageing_time(ocelot, ageing_time); 51056051948SVladimir Oltean 51156051948SVladimir Oltean return 0; 51256051948SVladimir Oltean } 51356051948SVladimir Oltean 51456051948SVladimir Oltean static int felix_fdb_dump(struct dsa_switch *ds, int port, 51556051948SVladimir Oltean dsa_fdb_dump_cb_t *cb, void *data) 51656051948SVladimir Oltean { 51756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 51856051948SVladimir Oltean 51956051948SVladimir Oltean return ocelot_fdb_dump(ocelot, port, cb, data); 52056051948SVladimir Oltean } 52156051948SVladimir Oltean 52256051948SVladimir Oltean static int felix_fdb_add(struct dsa_switch *ds, int port, 52356051948SVladimir Oltean const unsigned char *addr, u16 vid) 52456051948SVladimir Oltean { 52556051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 52656051948SVladimir Oltean 52787b0f983SVladimir Oltean return ocelot_fdb_add(ocelot, port, addr, vid); 52856051948SVladimir Oltean } 52956051948SVladimir Oltean 53056051948SVladimir Oltean static int felix_fdb_del(struct dsa_switch *ds, int port, 53156051948SVladimir Oltean const unsigned char *addr, u16 vid) 53256051948SVladimir Oltean { 53356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 53456051948SVladimir Oltean 53556051948SVladimir Oltean return ocelot_fdb_del(ocelot, port, addr, vid); 53656051948SVladimir Oltean } 53756051948SVladimir Oltean 538a52b2da7SVladimir Oltean static int felix_mdb_add(struct dsa_switch *ds, int port, 539209edf95SVladimir Oltean const struct switchdev_obj_port_mdb *mdb) 540209edf95SVladimir Oltean { 541209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 542209edf95SVladimir Oltean 543a52b2da7SVladimir Oltean return ocelot_port_mdb_add(ocelot, port, mdb); 544209edf95SVladimir Oltean } 545209edf95SVladimir Oltean 546209edf95SVladimir Oltean static int felix_mdb_del(struct dsa_switch *ds, int port, 547209edf95SVladimir Oltean const struct switchdev_obj_port_mdb *mdb) 548209edf95SVladimir Oltean { 549209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 550209edf95SVladimir Oltean 551209edf95SVladimir Oltean return ocelot_port_mdb_del(ocelot, port, mdb); 552209edf95SVladimir Oltean } 553209edf95SVladimir Oltean 55456051948SVladimir Oltean static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, 55556051948SVladimir Oltean u8 state) 55656051948SVladimir Oltean { 55756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 55856051948SVladimir Oltean 55956051948SVladimir Oltean return ocelot_bridge_stp_state_set(ocelot, port, state); 56056051948SVladimir Oltean } 56156051948SVladimir Oltean 562421741eaSVladimir Oltean static int felix_pre_bridge_flags(struct dsa_switch *ds, int port, 563421741eaSVladimir Oltean struct switchdev_brport_flags val, 564421741eaSVladimir Oltean struct netlink_ext_ack *extack) 565421741eaSVladimir Oltean { 566421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 567421741eaSVladimir Oltean 568421741eaSVladimir Oltean return ocelot_port_pre_bridge_flags(ocelot, port, val); 569421741eaSVladimir Oltean } 570421741eaSVladimir Oltean 571421741eaSVladimir Oltean static int felix_bridge_flags(struct dsa_switch *ds, int port, 572421741eaSVladimir Oltean struct switchdev_brport_flags val, 573421741eaSVladimir Oltean struct netlink_ext_ack *extack) 574421741eaSVladimir Oltean { 575421741eaSVladimir Oltean struct ocelot *ocelot = ds->priv; 576421741eaSVladimir Oltean 577421741eaSVladimir Oltean ocelot_port_bridge_flags(ocelot, port, val); 578421741eaSVladimir Oltean 579421741eaSVladimir Oltean return 0; 580421741eaSVladimir Oltean } 581421741eaSVladimir Oltean 58256051948SVladimir Oltean static int felix_bridge_join(struct dsa_switch *ds, int port, 58356051948SVladimir Oltean struct net_device *br) 58456051948SVladimir Oltean { 58556051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 58656051948SVladimir Oltean 58756051948SVladimir Oltean return ocelot_port_bridge_join(ocelot, port, br); 58856051948SVladimir Oltean } 58956051948SVladimir Oltean 59056051948SVladimir Oltean static void felix_bridge_leave(struct dsa_switch *ds, int port, 59156051948SVladimir Oltean struct net_device *br) 59256051948SVladimir Oltean { 59356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 59456051948SVladimir Oltean 59556051948SVladimir Oltean ocelot_port_bridge_leave(ocelot, port, br); 59656051948SVladimir Oltean } 59756051948SVladimir Oltean 5988fe6832eSVladimir Oltean static int felix_lag_join(struct dsa_switch *ds, int port, 5998fe6832eSVladimir Oltean struct net_device *bond, 6008fe6832eSVladimir Oltean struct netdev_lag_upper_info *info) 6018fe6832eSVladimir Oltean { 6028fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 6038fe6832eSVladimir Oltean 6048fe6832eSVladimir Oltean return ocelot_port_lag_join(ocelot, port, bond, info); 6058fe6832eSVladimir Oltean } 6068fe6832eSVladimir Oltean 6078fe6832eSVladimir Oltean static int felix_lag_leave(struct dsa_switch *ds, int port, 6088fe6832eSVladimir Oltean struct net_device *bond) 6098fe6832eSVladimir Oltean { 6108fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 6118fe6832eSVladimir Oltean 6128fe6832eSVladimir Oltean ocelot_port_lag_leave(ocelot, port, bond); 6138fe6832eSVladimir Oltean 6148fe6832eSVladimir Oltean return 0; 6158fe6832eSVladimir Oltean } 6168fe6832eSVladimir Oltean 6178fe6832eSVladimir Oltean static int felix_lag_change(struct dsa_switch *ds, int port) 6188fe6832eSVladimir Oltean { 6198fe6832eSVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 6208fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 6218fe6832eSVladimir Oltean 6228fe6832eSVladimir Oltean ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); 6238fe6832eSVladimir Oltean 6248fe6832eSVladimir Oltean return 0; 6258fe6832eSVladimir Oltean } 6268fe6832eSVladimir Oltean 62756051948SVladimir Oltean static int felix_vlan_prepare(struct dsa_switch *ds, int port, 62856051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 62956051948SVladimir Oltean { 6302f0402feSVladimir Oltean struct ocelot *ocelot = ds->priv; 631b7a9e0daSVladimir Oltean u16 flags = vlan->flags; 6322f0402feSVladimir Oltean 6339a720680SVladimir Oltean /* Ocelot switches copy frames as-is to the CPU, so the flags: 6349a720680SVladimir Oltean * egress-untagged or not, pvid or not, make no difference. This 6359a720680SVladimir Oltean * behavior is already better than what DSA just tries to approximate 6369a720680SVladimir Oltean * when it installs the VLAN with the same flags on the CPU port. 6379a720680SVladimir Oltean * Just accept any configuration, and don't let ocelot deny installing 6389a720680SVladimir Oltean * multiple native VLANs on the NPI port, because the switch doesn't 6399a720680SVladimir Oltean * look at the port tag settings towards the NPI interface anyway. 6409a720680SVladimir Oltean */ 6419a720680SVladimir Oltean if (port == ocelot->npi) 6429a720680SVladimir Oltean return 0; 6439a720680SVladimir Oltean 644b7a9e0daSVladimir Oltean return ocelot_vlan_prepare(ocelot, port, vlan->vid, 6452f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 6462f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 64756051948SVladimir Oltean } 64856051948SVladimir Oltean 649bae33f2bSVladimir Oltean static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) 65056051948SVladimir Oltean { 65156051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 65256051948SVladimir Oltean 653bae33f2bSVladimir Oltean return ocelot_port_vlan_filtering(ocelot, port, enabled); 65456051948SVladimir Oltean } 65556051948SVladimir Oltean 6561958d581SVladimir Oltean static int felix_vlan_add(struct dsa_switch *ds, int port, 65756051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 65856051948SVladimir Oltean { 65956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 660183be6f9SVladimir Oltean u16 flags = vlan->flags; 6611958d581SVladimir Oltean int err; 66256051948SVladimir Oltean 6631958d581SVladimir Oltean err = felix_vlan_prepare(ds, port, vlan); 6641958d581SVladimir Oltean if (err) 6651958d581SVladimir Oltean return err; 6661958d581SVladimir Oltean 6671958d581SVladimir Oltean return ocelot_vlan_add(ocelot, port, vlan->vid, 668183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 669183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 67056051948SVladimir Oltean } 67156051948SVladimir Oltean 67256051948SVladimir Oltean static int felix_vlan_del(struct dsa_switch *ds, int port, 67356051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 67456051948SVladimir Oltean { 67556051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 67656051948SVladimir Oltean 677b7a9e0daSVladimir Oltean return ocelot_vlan_del(ocelot, port, vlan->vid); 67856051948SVladimir Oltean } 67956051948SVladimir Oltean 68056051948SVladimir Oltean static int felix_port_enable(struct dsa_switch *ds, int port, 68156051948SVladimir Oltean struct phy_device *phy) 68256051948SVladimir Oltean { 68356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 68456051948SVladimir Oltean 68556051948SVladimir Oltean ocelot_port_enable(ocelot, port, phy); 68656051948SVladimir Oltean 68756051948SVladimir Oltean return 0; 68856051948SVladimir Oltean } 68956051948SVladimir Oltean 69056051948SVladimir Oltean static void felix_port_disable(struct dsa_switch *ds, int port) 69156051948SVladimir Oltean { 69256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 69356051948SVladimir Oltean 69456051948SVladimir Oltean return ocelot_port_disable(ocelot, port); 69556051948SVladimir Oltean } 69656051948SVladimir Oltean 697bdeced75SVladimir Oltean static void felix_phylink_validate(struct dsa_switch *ds, int port, 698bdeced75SVladimir Oltean unsigned long *supported, 699bdeced75SVladimir Oltean struct phylink_link_state *state) 700bdeced75SVladimir Oltean { 701bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 702375e1314SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 703bdeced75SVladimir Oltean 704375e1314SVladimir Oltean if (felix->info->phylink_validate) 705375e1314SVladimir Oltean felix->info->phylink_validate(ocelot, port, supported, state); 706bdeced75SVladimir Oltean } 707bdeced75SVladimir Oltean 708bdeced75SVladimir Oltean static void felix_phylink_mac_config(struct dsa_switch *ds, int port, 709bdeced75SVladimir Oltean unsigned int link_an_mode, 710bdeced75SVladimir Oltean const struct phylink_link_state *state) 711bdeced75SVladimir Oltean { 712bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 713bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 714588d0550SIoana Ciornei struct dsa_port *dp = dsa_to_port(ds, port); 715bdeced75SVladimir Oltean 716588d0550SIoana Ciornei if (felix->pcs[port]) 717588d0550SIoana Ciornei phylink_set_pcs(dp->pl, &felix->pcs[port]->pcs); 718bdeced75SVladimir Oltean } 719bdeced75SVladimir Oltean 720bdeced75SVladimir Oltean static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, 721bdeced75SVladimir Oltean unsigned int link_an_mode, 722bdeced75SVladimir Oltean phy_interface_t interface) 723bdeced75SVladimir Oltean { 724bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 725bdeced75SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 726eb4733d7SVladimir Oltean int err; 727bdeced75SVladimir Oltean 728eb4733d7SVladimir Oltean ocelot_port_rmwl(ocelot_port, 0, DEV_MAC_ENA_CFG_RX_ENA, 729eb4733d7SVladimir Oltean DEV_MAC_ENA_CFG); 730eb4733d7SVladimir Oltean 731886e1387SVladimir Oltean ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0); 732eb4733d7SVladimir Oltean 733eb4733d7SVladimir Oltean err = ocelot_port_flush(ocelot, port); 734eb4733d7SVladimir Oltean if (err) 735eb4733d7SVladimir Oltean dev_err(ocelot->dev, "failed to flush port %d: %d\n", 736eb4733d7SVladimir Oltean port, err); 737eb4733d7SVladimir Oltean 738eb4733d7SVladimir Oltean /* Put the port in reset. */ 739eb4733d7SVladimir Oltean ocelot_port_writel(ocelot_port, 740eb4733d7SVladimir Oltean DEV_CLOCK_CFG_MAC_TX_RST | 741eb4733d7SVladimir Oltean DEV_CLOCK_CFG_MAC_RX_RST | 742eb4733d7SVladimir Oltean DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000), 743eb4733d7SVladimir Oltean DEV_CLOCK_CFG); 744bdeced75SVladimir Oltean } 745bdeced75SVladimir Oltean 746bdeced75SVladimir Oltean static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, 747bdeced75SVladimir Oltean unsigned int link_an_mode, 748bdeced75SVladimir Oltean phy_interface_t interface, 7495b502a7bSRussell King struct phy_device *phydev, 7505b502a7bSRussell King int speed, int duplex, 7515b502a7bSRussell King bool tx_pause, bool rx_pause) 752bdeced75SVladimir Oltean { 753bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 754bdeced75SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 7557e14a2dcSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 7567e14a2dcSVladimir Oltean u32 mac_fc_cfg; 757bdeced75SVladimir Oltean 7587e14a2dcSVladimir Oltean /* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and 7597e14a2dcSVladimir Oltean * PORT_RST bits in DEV_CLOCK_CFG. Note that the way this system is 7607e14a2dcSVladimir Oltean * integrated is that the MAC speed is fixed and it's the PCS who is 7617e14a2dcSVladimir Oltean * performing the rate adaptation, so we have to write "1000Mbps" into 7627e14a2dcSVladimir Oltean * the LINK_SPEED field of DEV_CLOCK_CFG (which is also its default 7637e14a2dcSVladimir Oltean * value). 7647e14a2dcSVladimir Oltean */ 7657e14a2dcSVladimir Oltean ocelot_port_writel(ocelot_port, 7667e14a2dcSVladimir Oltean DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000), 7677e14a2dcSVladimir Oltean DEV_CLOCK_CFG); 7687e14a2dcSVladimir Oltean 7697e14a2dcSVladimir Oltean switch (speed) { 7707e14a2dcSVladimir Oltean case SPEED_10: 7717e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(3); 7727e14a2dcSVladimir Oltean break; 7737e14a2dcSVladimir Oltean case SPEED_100: 7747e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(2); 7757e14a2dcSVladimir Oltean break; 7767e14a2dcSVladimir Oltean case SPEED_1000: 7777e14a2dcSVladimir Oltean case SPEED_2500: 7787e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(1); 7797e14a2dcSVladimir Oltean break; 7807e14a2dcSVladimir Oltean default: 7817e14a2dcSVladimir Oltean dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n", 7827e14a2dcSVladimir Oltean port, speed); 7837e14a2dcSVladimir Oltean return; 7847e14a2dcSVladimir Oltean } 7857e14a2dcSVladimir Oltean 7867e14a2dcSVladimir Oltean /* handle Rx pause in all cases, with 2500base-X this is used for rate 7877e14a2dcSVladimir Oltean * adaptation. 7887e14a2dcSVladimir Oltean */ 7897e14a2dcSVladimir Oltean mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA; 7907e14a2dcSVladimir Oltean 7917e14a2dcSVladimir Oltean if (tx_pause) 7927e14a2dcSVladimir Oltean mac_fc_cfg |= SYS_MAC_FC_CFG_TX_FC_ENA | 7937e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) | 7947e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) | 7957e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_ZERO_PAUSE_ENA; 7967e14a2dcSVladimir Oltean 7977e14a2dcSVladimir Oltean /* Flow control. Link speed is only used here to evaluate the time 7987e14a2dcSVladimir Oltean * specification in incoming pause frames. 7997e14a2dcSVladimir Oltean */ 8007e14a2dcSVladimir Oltean ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port); 8017e14a2dcSVladimir Oltean 8027e14a2dcSVladimir Oltean ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port); 8037e14a2dcSVladimir Oltean 8047e14a2dcSVladimir Oltean /* Undo the effects of felix_phylink_mac_link_down: 8057e14a2dcSVladimir Oltean * enable MAC module 8067e14a2dcSVladimir Oltean */ 807bdeced75SVladimir Oltean ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA | 808bdeced75SVladimir Oltean DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG); 809bdeced75SVladimir Oltean 810bdeced75SVladimir Oltean /* Enable receiving frames on the port, and activate auto-learning of 811bdeced75SVladimir Oltean * MAC addresses. 812bdeced75SVladimir Oltean */ 813bdeced75SVladimir Oltean ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO | 814bdeced75SVladimir Oltean ANA_PORT_PORT_CFG_RECV_ENA | 815bdeced75SVladimir Oltean ANA_PORT_PORT_CFG_PORTID_VAL(port), 816bdeced75SVladimir Oltean ANA_PORT_PORT_CFG, port); 817bdeced75SVladimir Oltean 818bdeced75SVladimir Oltean /* Core: Enable port for frame transfer */ 819886e1387SVladimir Oltean ocelot_fields_write(ocelot, port, 820886e1387SVladimir Oltean QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); 8217e14a2dcSVladimir Oltean 8227e14a2dcSVladimir Oltean if (felix->info->port_sched_speed_set) 8237e14a2dcSVladimir Oltean felix->info->port_sched_speed_set(ocelot, port, speed); 824bdeced75SVladimir Oltean } 825bdeced75SVladimir Oltean 826bd2b3161SXiaoliang Yang static void felix_port_qos_map_init(struct ocelot *ocelot, int port) 827bd2b3161SXiaoliang Yang { 828bd2b3161SXiaoliang Yang int i; 829bd2b3161SXiaoliang Yang 830bd2b3161SXiaoliang Yang ocelot_rmw_gix(ocelot, 831bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 832bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 833bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG, 834bd2b3161SXiaoliang Yang port); 835bd2b3161SXiaoliang Yang 83670d39a6eSVladimir Oltean for (i = 0; i < OCELOT_NUM_TC * 2; i++) { 837bd2b3161SXiaoliang Yang ocelot_rmw_ix(ocelot, 838bd2b3161SXiaoliang Yang (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) | 839bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i), 840bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL | 841bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M, 842bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP, 843bd2b3161SXiaoliang Yang port, i); 844bd2b3161SXiaoliang Yang } 845bd2b3161SXiaoliang Yang } 846bd2b3161SXiaoliang Yang 84756051948SVladimir Oltean static void felix_get_strings(struct dsa_switch *ds, int port, 84856051948SVladimir Oltean u32 stringset, u8 *data) 84956051948SVladimir Oltean { 85056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 85156051948SVladimir Oltean 85256051948SVladimir Oltean return ocelot_get_strings(ocelot, port, stringset, data); 85356051948SVladimir Oltean } 85456051948SVladimir Oltean 85556051948SVladimir Oltean static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) 85656051948SVladimir Oltean { 85756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 85856051948SVladimir Oltean 85956051948SVladimir Oltean ocelot_get_ethtool_stats(ocelot, port, data); 86056051948SVladimir Oltean } 86156051948SVladimir Oltean 86256051948SVladimir Oltean static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) 86356051948SVladimir Oltean { 86456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 86556051948SVladimir Oltean 86656051948SVladimir Oltean return ocelot_get_sset_count(ocelot, port, sset); 86756051948SVladimir Oltean } 86856051948SVladimir Oltean 86956051948SVladimir Oltean static int felix_get_ts_info(struct dsa_switch *ds, int port, 87056051948SVladimir Oltean struct ethtool_ts_info *info) 87156051948SVladimir Oltean { 87256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 87356051948SVladimir Oltean 87456051948SVladimir Oltean return ocelot_get_ts_info(ocelot, port, info); 87556051948SVladimir Oltean } 87656051948SVladimir Oltean 877bdeced75SVladimir Oltean static int felix_parse_ports_node(struct felix *felix, 878bdeced75SVladimir Oltean struct device_node *ports_node, 879bdeced75SVladimir Oltean phy_interface_t *port_phy_modes) 880bdeced75SVladimir Oltean { 881bdeced75SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 882bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 883bdeced75SVladimir Oltean struct device_node *child; 884bdeced75SVladimir Oltean 88537fe45adSVladimir Oltean for_each_available_child_of_node(ports_node, child) { 886bdeced75SVladimir Oltean phy_interface_t phy_mode; 887bdeced75SVladimir Oltean u32 port; 888bdeced75SVladimir Oltean int err; 889bdeced75SVladimir Oltean 890bdeced75SVladimir Oltean /* Get switch port number from DT */ 891bdeced75SVladimir Oltean if (of_property_read_u32(child, "reg", &port) < 0) { 892bdeced75SVladimir Oltean dev_err(dev, "Port number not defined in device tree " 893bdeced75SVladimir Oltean "(property \"reg\")\n"); 894bdeced75SVladimir Oltean of_node_put(child); 895bdeced75SVladimir Oltean return -ENODEV; 896bdeced75SVladimir Oltean } 897bdeced75SVladimir Oltean 898bdeced75SVladimir Oltean /* Get PHY mode from DT */ 899bdeced75SVladimir Oltean err = of_get_phy_mode(child, &phy_mode); 900bdeced75SVladimir Oltean if (err) { 901bdeced75SVladimir Oltean dev_err(dev, "Failed to read phy-mode or " 902bdeced75SVladimir Oltean "phy-interface-type property for port %d\n", 903bdeced75SVladimir Oltean port); 904bdeced75SVladimir Oltean of_node_put(child); 905bdeced75SVladimir Oltean return -ENODEV; 906bdeced75SVladimir Oltean } 907bdeced75SVladimir Oltean 908bdeced75SVladimir Oltean err = felix->info->prevalidate_phy_mode(ocelot, port, phy_mode); 909bdeced75SVladimir Oltean if (err < 0) { 910bdeced75SVladimir Oltean dev_err(dev, "Unsupported PHY mode %s on port %d\n", 911bdeced75SVladimir Oltean phy_modes(phy_mode), port); 91259ebb430SSumera Priyadarsini of_node_put(child); 913bdeced75SVladimir Oltean return err; 914bdeced75SVladimir Oltean } 915bdeced75SVladimir Oltean 916bdeced75SVladimir Oltean port_phy_modes[port] = phy_mode; 917bdeced75SVladimir Oltean } 918bdeced75SVladimir Oltean 919bdeced75SVladimir Oltean return 0; 920bdeced75SVladimir Oltean } 921bdeced75SVladimir Oltean 922bdeced75SVladimir Oltean static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes) 923bdeced75SVladimir Oltean { 924bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 925bdeced75SVladimir Oltean struct device_node *switch_node; 926bdeced75SVladimir Oltean struct device_node *ports_node; 927bdeced75SVladimir Oltean int err; 928bdeced75SVladimir Oltean 929bdeced75SVladimir Oltean switch_node = dev->of_node; 930bdeced75SVladimir Oltean 931bdeced75SVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ports"); 932bdeced75SVladimir Oltean if (!ports_node) { 933bdeced75SVladimir Oltean dev_err(dev, "Incorrect bindings: absent \"ports\" node\n"); 934bdeced75SVladimir Oltean return -ENODEV; 935bdeced75SVladimir Oltean } 936bdeced75SVladimir Oltean 937bdeced75SVladimir Oltean err = felix_parse_ports_node(felix, ports_node, port_phy_modes); 938bdeced75SVladimir Oltean of_node_put(ports_node); 939bdeced75SVladimir Oltean 940bdeced75SVladimir Oltean return err; 941bdeced75SVladimir Oltean } 942bdeced75SVladimir Oltean 94356051948SVladimir Oltean static int felix_init_structs(struct felix *felix, int num_phys_ports) 94456051948SVladimir Oltean { 94556051948SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 946bdeced75SVladimir Oltean phy_interface_t *port_phy_modes; 947b4024c9eSClaudiu Manoil struct resource res; 94856051948SVladimir Oltean int port, i, err; 94956051948SVladimir Oltean 95056051948SVladimir Oltean ocelot->num_phys_ports = num_phys_ports; 95156051948SVladimir Oltean ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, 95256051948SVladimir Oltean sizeof(struct ocelot_port *), GFP_KERNEL); 95356051948SVladimir Oltean if (!ocelot->ports) 95456051948SVladimir Oltean return -ENOMEM; 95556051948SVladimir Oltean 95656051948SVladimir Oltean ocelot->map = felix->info->map; 95756051948SVladimir Oltean ocelot->stats_layout = felix->info->stats_layout; 95856051948SVladimir Oltean ocelot->num_stats = felix->info->num_stats; 95921ce7f3eSVladimir Oltean ocelot->num_mact_rows = felix->info->num_mact_rows; 96007d985eeSVladimir Oltean ocelot->vcap = felix->info->vcap; 96156051948SVladimir Oltean ocelot->ops = felix->info->ops; 962cacea62fSVladimir Oltean ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT; 963cacea62fSVladimir Oltean ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT; 964f59fd9caSVladimir Oltean ocelot->devlink = felix->ds->devlink; 96556051948SVladimir Oltean 966bdeced75SVladimir Oltean port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t), 967bdeced75SVladimir Oltean GFP_KERNEL); 968bdeced75SVladimir Oltean if (!port_phy_modes) 969bdeced75SVladimir Oltean return -ENOMEM; 970bdeced75SVladimir Oltean 971bdeced75SVladimir Oltean err = felix_parse_dt(felix, port_phy_modes); 972bdeced75SVladimir Oltean if (err) { 973bdeced75SVladimir Oltean kfree(port_phy_modes); 974bdeced75SVladimir Oltean return err; 975bdeced75SVladimir Oltean } 976bdeced75SVladimir Oltean 97756051948SVladimir Oltean for (i = 0; i < TARGET_MAX; i++) { 97856051948SVladimir Oltean struct regmap *target; 97956051948SVladimir Oltean 98056051948SVladimir Oltean if (!felix->info->target_io_res[i].name) 98156051948SVladimir Oltean continue; 98256051948SVladimir Oltean 983b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->target_io_res[i], sizeof(res)); 984b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 985375e1314SVladimir Oltean res.start += felix->switch_base; 986375e1314SVladimir Oltean res.end += felix->switch_base; 98756051948SVladimir Oltean 988b4024c9eSClaudiu Manoil target = ocelot_regmap_init(ocelot, &res); 98956051948SVladimir Oltean if (IS_ERR(target)) { 99056051948SVladimir Oltean dev_err(ocelot->dev, 99156051948SVladimir Oltean "Failed to map device memory space\n"); 992bdeced75SVladimir Oltean kfree(port_phy_modes); 99356051948SVladimir Oltean return PTR_ERR(target); 99456051948SVladimir Oltean } 99556051948SVladimir Oltean 99656051948SVladimir Oltean ocelot->targets[i] = target; 99756051948SVladimir Oltean } 99856051948SVladimir Oltean 99956051948SVladimir Oltean err = ocelot_regfields_init(ocelot, felix->info->regfields); 100056051948SVladimir Oltean if (err) { 100156051948SVladimir Oltean dev_err(ocelot->dev, "failed to init reg fields map\n"); 1002bdeced75SVladimir Oltean kfree(port_phy_modes); 100356051948SVladimir Oltean return err; 100456051948SVladimir Oltean } 100556051948SVladimir Oltean 100656051948SVladimir Oltean for (port = 0; port < num_phys_ports; port++) { 100756051948SVladimir Oltean struct ocelot_port *ocelot_port; 100891c724cfSVladimir Oltean struct regmap *target; 100956051948SVladimir Oltean 101056051948SVladimir Oltean ocelot_port = devm_kzalloc(ocelot->dev, 101156051948SVladimir Oltean sizeof(struct ocelot_port), 101256051948SVladimir Oltean GFP_KERNEL); 101356051948SVladimir Oltean if (!ocelot_port) { 101456051948SVladimir Oltean dev_err(ocelot->dev, 101556051948SVladimir Oltean "failed to allocate port memory\n"); 1016bdeced75SVladimir Oltean kfree(port_phy_modes); 101756051948SVladimir Oltean return -ENOMEM; 101856051948SVladimir Oltean } 101956051948SVladimir Oltean 1020b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->port_io_res[port], sizeof(res)); 1021b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1022375e1314SVladimir Oltean res.start += felix->switch_base; 1023375e1314SVladimir Oltean res.end += felix->switch_base; 102456051948SVladimir Oltean 102591c724cfSVladimir Oltean target = ocelot_regmap_init(ocelot, &res); 102691c724cfSVladimir Oltean if (IS_ERR(target)) { 102756051948SVladimir Oltean dev_err(ocelot->dev, 102891c724cfSVladimir Oltean "Failed to map memory space for port %d\n", 102991c724cfSVladimir Oltean port); 1030bdeced75SVladimir Oltean kfree(port_phy_modes); 103191c724cfSVladimir Oltean return PTR_ERR(target); 103256051948SVladimir Oltean } 103356051948SVladimir Oltean 1034bdeced75SVladimir Oltean ocelot_port->phy_mode = port_phy_modes[port]; 103556051948SVladimir Oltean ocelot_port->ocelot = ocelot; 103691c724cfSVladimir Oltean ocelot_port->target = target; 103756051948SVladimir Oltean ocelot->ports[port] = ocelot_port; 103856051948SVladimir Oltean } 103956051948SVladimir Oltean 1040bdeced75SVladimir Oltean kfree(port_phy_modes); 1041bdeced75SVladimir Oltean 1042bdeced75SVladimir Oltean if (felix->info->mdio_bus_alloc) { 1043bdeced75SVladimir Oltean err = felix->info->mdio_bus_alloc(ocelot); 1044bdeced75SVladimir Oltean if (err < 0) 1045bdeced75SVladimir Oltean return err; 1046bdeced75SVladimir Oltean } 1047bdeced75SVladimir Oltean 104856051948SVladimir Oltean return 0; 104956051948SVladimir Oltean } 105056051948SVladimir Oltean 105156051948SVladimir Oltean /* Hardware initialization done here so that we can allocate structures with 105256051948SVladimir Oltean * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing 105356051948SVladimir Oltean * us to allocate structures twice (leak memory) and map PCI memory twice 105456051948SVladimir Oltean * (which will not work). 105556051948SVladimir Oltean */ 105656051948SVladimir Oltean static int felix_setup(struct dsa_switch *ds) 105756051948SVladimir Oltean { 105856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 105956051948SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 106056051948SVladimir Oltean int port, err; 106156051948SVladimir Oltean 106256051948SVladimir Oltean err = felix_init_structs(felix, ds->num_ports); 106356051948SVladimir Oltean if (err) 106456051948SVladimir Oltean return err; 106556051948SVladimir Oltean 1066d1cc0e93SVladimir Oltean err = ocelot_init(ocelot); 1067d1cc0e93SVladimir Oltean if (err) 1068d1cc0e93SVladimir Oltean return err; 1069d1cc0e93SVladimir Oltean 10702b49d128SYangbo Lu if (ocelot->ptp) { 10712ac7c6c5SVladimir Oltean err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); 10722b49d128SYangbo Lu if (err) { 10732b49d128SYangbo Lu dev_err(ocelot->dev, 10742b49d128SYangbo Lu "Timestamp initialization failed\n"); 10752b49d128SYangbo Lu ocelot->ptp = 0; 10762b49d128SYangbo Lu } 10772b49d128SYangbo Lu } 107856051948SVladimir Oltean 107956051948SVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1080adb3dccfSVladimir Oltean if (dsa_is_unused_port(ds, port)) 1081adb3dccfSVladimir Oltean continue; 108256051948SVladimir Oltean 1083adb3dccfSVladimir Oltean ocelot_init_port(ocelot, port); 1084bd2b3161SXiaoliang Yang 1085bd2b3161SXiaoliang Yang /* Set the default QoS Classification based on PCP and DEI 1086bd2b3161SXiaoliang Yang * bits of vlan tag. 1087bd2b3161SXiaoliang Yang */ 1088bd2b3161SXiaoliang Yang felix_port_qos_map_init(ocelot, port); 108956051948SVladimir Oltean } 109056051948SVladimir Oltean 1091f59fd9caSVladimir Oltean err = ocelot_devlink_sb_register(ocelot); 1092f59fd9caSVladimir Oltean if (err) 1093f59fd9caSVladimir Oltean return err; 1094f59fd9caSVladimir Oltean 1095adb3dccfSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1096adb3dccfSVladimir Oltean if (!dsa_is_cpu_port(ds, port)) 1097adb3dccfSVladimir Oltean continue; 1098adb3dccfSVladimir Oltean 1099adb3dccfSVladimir Oltean /* The initial tag protocol is NPI which always returns 0, so 1100adb3dccfSVladimir Oltean * there's no real point in checking for errors. 11011cf3299bSVladimir Oltean */ 1102adb3dccfSVladimir Oltean felix_set_tag_protocol(ds, port, felix->tag_proto); 1103adb3dccfSVladimir Oltean } 11041cf3299bSVladimir Oltean 11050b912fc9SVladimir Oltean ds->mtu_enforcement_ingress = true; 1106c54913c1SVladimir Oltean ds->assisted_learning_on_cpu_port = true; 1107bdeced75SVladimir Oltean 110856051948SVladimir Oltean return 0; 110956051948SVladimir Oltean } 111056051948SVladimir Oltean 111156051948SVladimir Oltean static void felix_teardown(struct dsa_switch *ds) 111256051948SVladimir Oltean { 111356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 1114bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1115e5fb512dSVladimir Oltean int port; 1116bdeced75SVladimir Oltean 1117adb3dccfSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1118adb3dccfSVladimir Oltean if (!dsa_is_cpu_port(ds, port)) 1119adb3dccfSVladimir Oltean continue; 1120adb3dccfSVladimir Oltean 1121adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, port, felix->tag_proto); 1122adb3dccfSVladimir Oltean } 1123adb3dccfSVladimir Oltean 1124f59fd9caSVladimir Oltean ocelot_devlink_sb_unregister(ocelot); 1125d19741b0SVladimir Oltean ocelot_deinit_timestamp(ocelot); 1126d19741b0SVladimir Oltean ocelot_deinit(ocelot); 112756051948SVladimir Oltean 1128e5fb512dSVladimir Oltean for (port = 0; port < ocelot->num_phys_ports; port++) 1129e5fb512dSVladimir Oltean ocelot_deinit_port(ocelot, port); 1130d19741b0SVladimir Oltean 1131d19741b0SVladimir Oltean if (felix->info->mdio_bus_free) 1132d19741b0SVladimir Oltean felix->info->mdio_bus_free(ocelot); 113356051948SVladimir Oltean } 113456051948SVladimir Oltean 1135c0bcf537SYangbo Lu static int felix_hwtstamp_get(struct dsa_switch *ds, int port, 1136c0bcf537SYangbo Lu struct ifreq *ifr) 1137c0bcf537SYangbo Lu { 1138c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1139c0bcf537SYangbo Lu 1140c0bcf537SYangbo Lu return ocelot_hwstamp_get(ocelot, port, ifr); 1141c0bcf537SYangbo Lu } 1142c0bcf537SYangbo Lu 1143c0bcf537SYangbo Lu static int felix_hwtstamp_set(struct dsa_switch *ds, int port, 1144c0bcf537SYangbo Lu struct ifreq *ifr) 1145c0bcf537SYangbo Lu { 1146c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1147c0bcf537SYangbo Lu 1148c0bcf537SYangbo Lu return ocelot_hwstamp_set(ocelot, port, ifr); 1149c0bcf537SYangbo Lu } 1150c0bcf537SYangbo Lu 1151c0bcf537SYangbo Lu static bool felix_rxtstamp(struct dsa_switch *ds, int port, 1152c0bcf537SYangbo Lu struct sk_buff *skb, unsigned int type) 1153c0bcf537SYangbo Lu { 115440d3f295SVladimir Oltean u8 *extraction = skb->data - ETH_HLEN - OCELOT_TAG_LEN; 1155c0bcf537SYangbo Lu struct skb_shared_hwtstamps *shhwtstamps; 1156c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1157c0bcf537SYangbo Lu u32 tstamp_lo, tstamp_hi; 1158c0bcf537SYangbo Lu struct timespec64 ts; 1159c0bcf537SYangbo Lu u64 tstamp, val; 1160c0bcf537SYangbo Lu 1161c0bcf537SYangbo Lu ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); 1162c0bcf537SYangbo Lu tstamp = ktime_set(ts.tv_sec, ts.tv_nsec); 1163c0bcf537SYangbo Lu 116440d3f295SVladimir Oltean ocelot_xfh_get_rew_val(extraction, &val); 1165c0bcf537SYangbo Lu tstamp_lo = (u32)val; 1166c0bcf537SYangbo Lu 1167c0bcf537SYangbo Lu tstamp_hi = tstamp >> 32; 1168c0bcf537SYangbo Lu if ((tstamp & 0xffffffff) < tstamp_lo) 1169c0bcf537SYangbo Lu tstamp_hi--; 1170c0bcf537SYangbo Lu 1171c0bcf537SYangbo Lu tstamp = ((u64)tstamp_hi << 32) | tstamp_lo; 1172c0bcf537SYangbo Lu 1173c0bcf537SYangbo Lu shhwtstamps = skb_hwtstamps(skb); 1174c0bcf537SYangbo Lu memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); 1175c0bcf537SYangbo Lu shhwtstamps->hwtstamp = tstamp; 1176c0bcf537SYangbo Lu return false; 1177c0bcf537SYangbo Lu } 1178c0bcf537SYangbo Lu 11793243e04aSChen Wandun static bool felix_txtstamp(struct dsa_switch *ds, int port, 1180c0bcf537SYangbo Lu struct sk_buff *clone, unsigned int type) 1181c0bcf537SYangbo Lu { 1182c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1183c0bcf537SYangbo Lu struct ocelot_port *ocelot_port = ocelot->ports[port]; 1184c0bcf537SYangbo Lu 1185e2f9a8feSVladimir Oltean if (ocelot->ptp && (skb_shinfo(clone)->tx_flags & SKBTX_HW_TSTAMP) && 1186e2f9a8feSVladimir Oltean ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) { 1187e2f9a8feSVladimir Oltean ocelot_port_add_txtstamp_skb(ocelot, port, clone); 1188c0bcf537SYangbo Lu return true; 1189e2f9a8feSVladimir Oltean } 1190c0bcf537SYangbo Lu 1191c0bcf537SYangbo Lu return false; 1192c0bcf537SYangbo Lu } 1193c0bcf537SYangbo Lu 11940b912fc9SVladimir Oltean static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 11950b912fc9SVladimir Oltean { 11960b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 11970b912fc9SVladimir Oltean 11980b912fc9SVladimir Oltean ocelot_port_set_maxlen(ocelot, port, new_mtu); 11990b912fc9SVladimir Oltean 12000b912fc9SVladimir Oltean return 0; 12010b912fc9SVladimir Oltean } 12020b912fc9SVladimir Oltean 12030b912fc9SVladimir Oltean static int felix_get_max_mtu(struct dsa_switch *ds, int port) 12040b912fc9SVladimir Oltean { 12050b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 12060b912fc9SVladimir Oltean 12070b912fc9SVladimir Oltean return ocelot_get_max_mtu(ocelot, port); 12080b912fc9SVladimir Oltean } 12090b912fc9SVladimir Oltean 121007d985eeSVladimir Oltean static int felix_cls_flower_add(struct dsa_switch *ds, int port, 121107d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 121207d985eeSVladimir Oltean { 121307d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 121407d985eeSVladimir Oltean 121507d985eeSVladimir Oltean return ocelot_cls_flower_replace(ocelot, port, cls, ingress); 121607d985eeSVladimir Oltean } 121707d985eeSVladimir Oltean 121807d985eeSVladimir Oltean static int felix_cls_flower_del(struct dsa_switch *ds, int port, 121907d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 122007d985eeSVladimir Oltean { 122107d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 122207d985eeSVladimir Oltean 122307d985eeSVladimir Oltean return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); 122407d985eeSVladimir Oltean } 122507d985eeSVladimir Oltean 122607d985eeSVladimir Oltean static int felix_cls_flower_stats(struct dsa_switch *ds, int port, 122707d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 122807d985eeSVladimir Oltean { 122907d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 123007d985eeSVladimir Oltean 123107d985eeSVladimir Oltean return ocelot_cls_flower_stats(ocelot, port, cls, ingress); 123207d985eeSVladimir Oltean } 123307d985eeSVladimir Oltean 1234fc411eaaSVladimir Oltean static int felix_port_policer_add(struct dsa_switch *ds, int port, 1235fc411eaaSVladimir Oltean struct dsa_mall_policer_tc_entry *policer) 1236fc411eaaSVladimir Oltean { 1237fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1238fc411eaaSVladimir Oltean struct ocelot_policer pol = { 1239fc411eaaSVladimir Oltean .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, 12405f035af7SPo Liu .burst = policer->burst, 1241fc411eaaSVladimir Oltean }; 1242fc411eaaSVladimir Oltean 1243fc411eaaSVladimir Oltean return ocelot_port_policer_add(ocelot, port, &pol); 1244fc411eaaSVladimir Oltean } 1245fc411eaaSVladimir Oltean 1246fc411eaaSVladimir Oltean static void felix_port_policer_del(struct dsa_switch *ds, int port) 1247fc411eaaSVladimir Oltean { 1248fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1249fc411eaaSVladimir Oltean 1250fc411eaaSVladimir Oltean ocelot_port_policer_del(ocelot, port); 1251fc411eaaSVladimir Oltean } 1252fc411eaaSVladimir Oltean 1253de143c0eSXiaoliang Yang static int felix_port_setup_tc(struct dsa_switch *ds, int port, 1254de143c0eSXiaoliang Yang enum tc_setup_type type, 1255de143c0eSXiaoliang Yang void *type_data) 1256de143c0eSXiaoliang Yang { 1257de143c0eSXiaoliang Yang struct ocelot *ocelot = ds->priv; 1258de143c0eSXiaoliang Yang struct felix *felix = ocelot_to_felix(ocelot); 1259de143c0eSXiaoliang Yang 1260de143c0eSXiaoliang Yang if (felix->info->port_setup_tc) 1261de143c0eSXiaoliang Yang return felix->info->port_setup_tc(ds, port, type, type_data); 1262de143c0eSXiaoliang Yang else 1263de143c0eSXiaoliang Yang return -EOPNOTSUPP; 1264de143c0eSXiaoliang Yang } 1265de143c0eSXiaoliang Yang 1266f59fd9caSVladimir Oltean static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index, 1267f59fd9caSVladimir Oltean u16 pool_index, 1268f59fd9caSVladimir Oltean struct devlink_sb_pool_info *pool_info) 1269f59fd9caSVladimir Oltean { 1270f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1271f59fd9caSVladimir Oltean 1272f59fd9caSVladimir Oltean return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info); 1273f59fd9caSVladimir Oltean } 1274f59fd9caSVladimir Oltean 1275f59fd9caSVladimir Oltean static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index, 1276f59fd9caSVladimir Oltean u16 pool_index, u32 size, 1277f59fd9caSVladimir Oltean enum devlink_sb_threshold_type threshold_type, 1278f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1279f59fd9caSVladimir Oltean { 1280f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1281f59fd9caSVladimir Oltean 1282f59fd9caSVladimir Oltean return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size, 1283f59fd9caSVladimir Oltean threshold_type, extack); 1284f59fd9caSVladimir Oltean } 1285f59fd9caSVladimir Oltean 1286f59fd9caSVladimir Oltean static int felix_sb_port_pool_get(struct dsa_switch *ds, int port, 1287f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1288f59fd9caSVladimir Oltean u32 *p_threshold) 1289f59fd9caSVladimir Oltean { 1290f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1291f59fd9caSVladimir Oltean 1292f59fd9caSVladimir Oltean return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index, 1293f59fd9caSVladimir Oltean p_threshold); 1294f59fd9caSVladimir Oltean } 1295f59fd9caSVladimir Oltean 1296f59fd9caSVladimir Oltean static int felix_sb_port_pool_set(struct dsa_switch *ds, int port, 1297f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1298f59fd9caSVladimir Oltean u32 threshold, struct netlink_ext_ack *extack) 1299f59fd9caSVladimir Oltean { 1300f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1301f59fd9caSVladimir Oltean 1302f59fd9caSVladimir Oltean return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index, 1303f59fd9caSVladimir Oltean threshold, extack); 1304f59fd9caSVladimir Oltean } 1305f59fd9caSVladimir Oltean 1306f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port, 1307f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1308f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1309f59fd9caSVladimir Oltean u16 *p_pool_index, u32 *p_threshold) 1310f59fd9caSVladimir Oltean { 1311f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1312f59fd9caSVladimir Oltean 1313f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index, 1314f59fd9caSVladimir Oltean pool_type, p_pool_index, 1315f59fd9caSVladimir Oltean p_threshold); 1316f59fd9caSVladimir Oltean } 1317f59fd9caSVladimir Oltean 1318f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port, 1319f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1320f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1321f59fd9caSVladimir Oltean u16 pool_index, u32 threshold, 1322f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1323f59fd9caSVladimir Oltean { 1324f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1325f59fd9caSVladimir Oltean 1326f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index, 1327f59fd9caSVladimir Oltean pool_type, pool_index, threshold, 1328f59fd9caSVladimir Oltean extack); 1329f59fd9caSVladimir Oltean } 1330f59fd9caSVladimir Oltean 1331f59fd9caSVladimir Oltean static int felix_sb_occ_snapshot(struct dsa_switch *ds, 1332f59fd9caSVladimir Oltean unsigned int sb_index) 1333f59fd9caSVladimir Oltean { 1334f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1335f59fd9caSVladimir Oltean 1336f59fd9caSVladimir Oltean return ocelot_sb_occ_snapshot(ocelot, sb_index); 1337f59fd9caSVladimir Oltean } 1338f59fd9caSVladimir Oltean 1339f59fd9caSVladimir Oltean static int felix_sb_occ_max_clear(struct dsa_switch *ds, 1340f59fd9caSVladimir Oltean unsigned int sb_index) 1341f59fd9caSVladimir Oltean { 1342f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1343f59fd9caSVladimir Oltean 1344f59fd9caSVladimir Oltean return ocelot_sb_occ_max_clear(ocelot, sb_index); 1345f59fd9caSVladimir Oltean } 1346f59fd9caSVladimir Oltean 1347f59fd9caSVladimir Oltean static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port, 1348f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1349f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1350f59fd9caSVladimir Oltean { 1351f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1352f59fd9caSVladimir Oltean 1353f59fd9caSVladimir Oltean return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index, 1354f59fd9caSVladimir Oltean p_cur, p_max); 1355f59fd9caSVladimir Oltean } 1356f59fd9caSVladimir Oltean 1357f59fd9caSVladimir Oltean static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port, 1358f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1359f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1360f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1361f59fd9caSVladimir Oltean { 1362f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1363f59fd9caSVladimir Oltean 1364f59fd9caSVladimir Oltean return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index, 1365f59fd9caSVladimir Oltean pool_type, p_cur, p_max); 1366f59fd9caSVladimir Oltean } 1367f59fd9caSVladimir Oltean 1368375e1314SVladimir Oltean const struct dsa_switch_ops felix_switch_ops = { 136956051948SVladimir Oltean .get_tag_protocol = felix_get_tag_protocol, 1370adb3dccfSVladimir Oltean .change_tag_protocol = felix_change_tag_protocol, 137156051948SVladimir Oltean .setup = felix_setup, 137256051948SVladimir Oltean .teardown = felix_teardown, 137356051948SVladimir Oltean .set_ageing_time = felix_set_ageing_time, 137456051948SVladimir Oltean .get_strings = felix_get_strings, 137556051948SVladimir Oltean .get_ethtool_stats = felix_get_ethtool_stats, 137656051948SVladimir Oltean .get_sset_count = felix_get_sset_count, 137756051948SVladimir Oltean .get_ts_info = felix_get_ts_info, 1378bdeced75SVladimir Oltean .phylink_validate = felix_phylink_validate, 1379bdeced75SVladimir Oltean .phylink_mac_config = felix_phylink_mac_config, 1380bdeced75SVladimir Oltean .phylink_mac_link_down = felix_phylink_mac_link_down, 1381bdeced75SVladimir Oltean .phylink_mac_link_up = felix_phylink_mac_link_up, 138256051948SVladimir Oltean .port_enable = felix_port_enable, 138356051948SVladimir Oltean .port_disable = felix_port_disable, 138456051948SVladimir Oltean .port_fdb_dump = felix_fdb_dump, 138556051948SVladimir Oltean .port_fdb_add = felix_fdb_add, 138656051948SVladimir Oltean .port_fdb_del = felix_fdb_del, 1387209edf95SVladimir Oltean .port_mdb_add = felix_mdb_add, 1388209edf95SVladimir Oltean .port_mdb_del = felix_mdb_del, 1389421741eaSVladimir Oltean .port_pre_bridge_flags = felix_pre_bridge_flags, 1390421741eaSVladimir Oltean .port_bridge_flags = felix_bridge_flags, 139156051948SVladimir Oltean .port_bridge_join = felix_bridge_join, 139256051948SVladimir Oltean .port_bridge_leave = felix_bridge_leave, 13938fe6832eSVladimir Oltean .port_lag_join = felix_lag_join, 13948fe6832eSVladimir Oltean .port_lag_leave = felix_lag_leave, 13958fe6832eSVladimir Oltean .port_lag_change = felix_lag_change, 139656051948SVladimir Oltean .port_stp_state_set = felix_bridge_stp_state_set, 139756051948SVladimir Oltean .port_vlan_filtering = felix_vlan_filtering, 139856051948SVladimir Oltean .port_vlan_add = felix_vlan_add, 139956051948SVladimir Oltean .port_vlan_del = felix_vlan_del, 1400c0bcf537SYangbo Lu .port_hwtstamp_get = felix_hwtstamp_get, 1401c0bcf537SYangbo Lu .port_hwtstamp_set = felix_hwtstamp_set, 1402c0bcf537SYangbo Lu .port_rxtstamp = felix_rxtstamp, 1403c0bcf537SYangbo Lu .port_txtstamp = felix_txtstamp, 14040b912fc9SVladimir Oltean .port_change_mtu = felix_change_mtu, 14050b912fc9SVladimir Oltean .port_max_mtu = felix_get_max_mtu, 1406fc411eaaSVladimir Oltean .port_policer_add = felix_port_policer_add, 1407fc411eaaSVladimir Oltean .port_policer_del = felix_port_policer_del, 140807d985eeSVladimir Oltean .cls_flower_add = felix_cls_flower_add, 140907d985eeSVladimir Oltean .cls_flower_del = felix_cls_flower_del, 141007d985eeSVladimir Oltean .cls_flower_stats = felix_cls_flower_stats, 1411de143c0eSXiaoliang Yang .port_setup_tc = felix_port_setup_tc, 1412f59fd9caSVladimir Oltean .devlink_sb_pool_get = felix_sb_pool_get, 1413f59fd9caSVladimir Oltean .devlink_sb_pool_set = felix_sb_pool_set, 1414f59fd9caSVladimir Oltean .devlink_sb_port_pool_get = felix_sb_port_pool_get, 1415f59fd9caSVladimir Oltean .devlink_sb_port_pool_set = felix_sb_port_pool_set, 1416f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get, 1417f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set, 1418f59fd9caSVladimir Oltean .devlink_sb_occ_snapshot = felix_sb_occ_snapshot, 1419f59fd9caSVladimir Oltean .devlink_sb_occ_max_clear = felix_sb_occ_max_clear, 1420f59fd9caSVladimir Oltean .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get, 1421f59fd9caSVladimir Oltean .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get, 142256051948SVladimir Oltean }; 1423319e4dd1SVladimir Oltean 1424319e4dd1SVladimir Oltean struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) 1425319e4dd1SVladimir Oltean { 1426319e4dd1SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1427319e4dd1SVladimir Oltean struct dsa_switch *ds = felix->ds; 1428319e4dd1SVladimir Oltean 1429319e4dd1SVladimir Oltean if (!dsa_is_user_port(ds, port)) 1430319e4dd1SVladimir Oltean return NULL; 1431319e4dd1SVladimir Oltean 1432319e4dd1SVladimir Oltean return dsa_to_port(ds, port)->slave; 1433319e4dd1SVladimir Oltean } 1434319e4dd1SVladimir Oltean 1435319e4dd1SVladimir Oltean int felix_netdev_to_port(struct net_device *dev) 1436319e4dd1SVladimir Oltean { 1437319e4dd1SVladimir Oltean struct dsa_port *dp; 1438319e4dd1SVladimir Oltean 1439319e4dd1SVladimir Oltean dp = dsa_port_from_netdev(dev); 1440319e4dd1SVladimir Oltean if (IS_ERR(dp)) 1441319e4dd1SVladimir Oltean return -EINVAL; 1442319e4dd1SVladimir Oltean 1443319e4dd1SVladimir Oltean return dp->index; 1444319e4dd1SVladimir Oltean } 1445