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> 1784705fc1SMaxim Kochetkov #include <linux/platform_device.h> 18c0bcf537SYangbo Lu #include <linux/packing.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); 302*b360d94fSVladimir 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); 416*b360d94fSVladimir 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) { 434adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 435adb3dccfSVladimir Oltean err = felix_setup_tag_npi(ds, cpu); 436adb3dccfSVladimir Oltean break; 437e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 438e21268efSVladimir Oltean err = felix_setup_tag_8021q(ds, cpu); 439e21268efSVladimir Oltean break; 440adb3dccfSVladimir Oltean default: 441adb3dccfSVladimir Oltean err = -EPROTONOSUPPORT; 442adb3dccfSVladimir Oltean } 443adb3dccfSVladimir Oltean 444adb3dccfSVladimir Oltean return err; 445adb3dccfSVladimir Oltean } 446adb3dccfSVladimir Oltean 447adb3dccfSVladimir Oltean static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu, 448adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 449adb3dccfSVladimir Oltean { 450adb3dccfSVladimir Oltean switch (proto) { 451adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 452adb3dccfSVladimir Oltean felix_teardown_tag_npi(ds, cpu); 453adb3dccfSVladimir Oltean break; 454e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 455e21268efSVladimir Oltean felix_teardown_tag_8021q(ds, cpu); 456e21268efSVladimir Oltean break; 457adb3dccfSVladimir Oltean default: 458adb3dccfSVladimir Oltean break; 459adb3dccfSVladimir Oltean } 460adb3dccfSVladimir Oltean } 461adb3dccfSVladimir Oltean 462e21268efSVladimir Oltean /* This always leaves the switch in a consistent state, because although the 463e21268efSVladimir Oltean * tag_8021q setup can fail, the NPI setup can't. So either the change is made, 464e21268efSVladimir Oltean * or the restoration is guaranteed to work. 465e21268efSVladimir Oltean */ 466adb3dccfSVladimir Oltean static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu, 467adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 468adb3dccfSVladimir Oltean { 469adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 470adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 471adb3dccfSVladimir Oltean enum dsa_tag_protocol old_proto = felix->tag_proto; 472adb3dccfSVladimir Oltean int err; 473adb3dccfSVladimir Oltean 474e21268efSVladimir Oltean if (proto != DSA_TAG_PROTO_OCELOT && 475e21268efSVladimir Oltean proto != DSA_TAG_PROTO_OCELOT_8021Q) 476adb3dccfSVladimir Oltean return -EPROTONOSUPPORT; 477adb3dccfSVladimir Oltean 478adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, cpu, old_proto); 479adb3dccfSVladimir Oltean 480adb3dccfSVladimir Oltean err = felix_set_tag_protocol(ds, cpu, proto); 481adb3dccfSVladimir Oltean if (err) { 482adb3dccfSVladimir Oltean felix_set_tag_protocol(ds, cpu, old_proto); 483adb3dccfSVladimir Oltean return err; 484adb3dccfSVladimir Oltean } 485adb3dccfSVladimir Oltean 486adb3dccfSVladimir Oltean felix->tag_proto = proto; 487adb3dccfSVladimir Oltean 488adb3dccfSVladimir Oltean return 0; 489adb3dccfSVladimir Oltean } 490adb3dccfSVladimir Oltean 49156051948SVladimir Oltean static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds, 4924d776482SFlorian Fainelli int port, 4934d776482SFlorian Fainelli enum dsa_tag_protocol mp) 49456051948SVladimir Oltean { 495adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 496adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 497adb3dccfSVladimir Oltean 498adb3dccfSVladimir Oltean return felix->tag_proto; 49956051948SVladimir Oltean } 50056051948SVladimir Oltean 50156051948SVladimir Oltean static int felix_set_ageing_time(struct dsa_switch *ds, 50256051948SVladimir Oltean unsigned int ageing_time) 50356051948SVladimir Oltean { 50456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 50556051948SVladimir Oltean 50656051948SVladimir Oltean ocelot_set_ageing_time(ocelot, ageing_time); 50756051948SVladimir Oltean 50856051948SVladimir Oltean return 0; 50956051948SVladimir Oltean } 51056051948SVladimir Oltean 51156051948SVladimir Oltean static int felix_fdb_dump(struct dsa_switch *ds, int port, 51256051948SVladimir Oltean dsa_fdb_dump_cb_t *cb, void *data) 51356051948SVladimir Oltean { 51456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 51556051948SVladimir Oltean 51656051948SVladimir Oltean return ocelot_fdb_dump(ocelot, port, cb, data); 51756051948SVladimir Oltean } 51856051948SVladimir Oltean 51956051948SVladimir Oltean static int felix_fdb_add(struct dsa_switch *ds, int port, 52056051948SVladimir Oltean const unsigned char *addr, u16 vid) 52156051948SVladimir Oltean { 52256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 52356051948SVladimir Oltean 52487b0f983SVladimir Oltean return ocelot_fdb_add(ocelot, port, addr, vid); 52556051948SVladimir Oltean } 52656051948SVladimir Oltean 52756051948SVladimir Oltean static int felix_fdb_del(struct dsa_switch *ds, int port, 52856051948SVladimir Oltean const unsigned char *addr, u16 vid) 52956051948SVladimir Oltean { 53056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 53156051948SVladimir Oltean 53256051948SVladimir Oltean return ocelot_fdb_del(ocelot, port, addr, vid); 53356051948SVladimir Oltean } 53456051948SVladimir Oltean 535a52b2da7SVladimir Oltean static int felix_mdb_add(struct dsa_switch *ds, int port, 536209edf95SVladimir Oltean const struct switchdev_obj_port_mdb *mdb) 537209edf95SVladimir Oltean { 538209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 539209edf95SVladimir Oltean 540a52b2da7SVladimir Oltean return ocelot_port_mdb_add(ocelot, port, mdb); 541209edf95SVladimir Oltean } 542209edf95SVladimir Oltean 543209edf95SVladimir Oltean static int felix_mdb_del(struct dsa_switch *ds, int port, 544209edf95SVladimir Oltean const struct switchdev_obj_port_mdb *mdb) 545209edf95SVladimir Oltean { 546209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 547209edf95SVladimir Oltean 548209edf95SVladimir Oltean return ocelot_port_mdb_del(ocelot, port, mdb); 549209edf95SVladimir Oltean } 550209edf95SVladimir Oltean 55156051948SVladimir Oltean static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, 55256051948SVladimir Oltean u8 state) 55356051948SVladimir Oltean { 55456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 55556051948SVladimir Oltean 55656051948SVladimir Oltean return ocelot_bridge_stp_state_set(ocelot, port, state); 55756051948SVladimir Oltean } 55856051948SVladimir Oltean 55956051948SVladimir Oltean static int felix_bridge_join(struct dsa_switch *ds, int port, 56056051948SVladimir Oltean struct net_device *br) 56156051948SVladimir Oltean { 56256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 56356051948SVladimir Oltean 56456051948SVladimir Oltean return ocelot_port_bridge_join(ocelot, port, br); 56556051948SVladimir Oltean } 56656051948SVladimir Oltean 56756051948SVladimir Oltean static void felix_bridge_leave(struct dsa_switch *ds, int port, 56856051948SVladimir Oltean struct net_device *br) 56956051948SVladimir Oltean { 57056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 57156051948SVladimir Oltean 57256051948SVladimir Oltean ocelot_port_bridge_leave(ocelot, port, br); 57356051948SVladimir Oltean } 57456051948SVladimir Oltean 5758fe6832eSVladimir Oltean static int felix_lag_join(struct dsa_switch *ds, int port, 5768fe6832eSVladimir Oltean struct net_device *bond, 5778fe6832eSVladimir Oltean struct netdev_lag_upper_info *info) 5788fe6832eSVladimir Oltean { 5798fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 5808fe6832eSVladimir Oltean 5818fe6832eSVladimir Oltean return ocelot_port_lag_join(ocelot, port, bond, info); 5828fe6832eSVladimir Oltean } 5838fe6832eSVladimir Oltean 5848fe6832eSVladimir Oltean static int felix_lag_leave(struct dsa_switch *ds, int port, 5858fe6832eSVladimir Oltean struct net_device *bond) 5868fe6832eSVladimir Oltean { 5878fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 5888fe6832eSVladimir Oltean 5898fe6832eSVladimir Oltean ocelot_port_lag_leave(ocelot, port, bond); 5908fe6832eSVladimir Oltean 5918fe6832eSVladimir Oltean return 0; 5928fe6832eSVladimir Oltean } 5938fe6832eSVladimir Oltean 5948fe6832eSVladimir Oltean static int felix_lag_change(struct dsa_switch *ds, int port) 5958fe6832eSVladimir Oltean { 5968fe6832eSVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 5978fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 5988fe6832eSVladimir Oltean 5998fe6832eSVladimir Oltean ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); 6008fe6832eSVladimir Oltean 6018fe6832eSVladimir Oltean return 0; 6028fe6832eSVladimir Oltean } 6038fe6832eSVladimir Oltean 60456051948SVladimir Oltean static int felix_vlan_prepare(struct dsa_switch *ds, int port, 60556051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 60656051948SVladimir Oltean { 6072f0402feSVladimir Oltean struct ocelot *ocelot = ds->priv; 608b7a9e0daSVladimir Oltean u16 flags = vlan->flags; 6092f0402feSVladimir Oltean 6109a720680SVladimir Oltean /* Ocelot switches copy frames as-is to the CPU, so the flags: 6119a720680SVladimir Oltean * egress-untagged or not, pvid or not, make no difference. This 6129a720680SVladimir Oltean * behavior is already better than what DSA just tries to approximate 6139a720680SVladimir Oltean * when it installs the VLAN with the same flags on the CPU port. 6149a720680SVladimir Oltean * Just accept any configuration, and don't let ocelot deny installing 6159a720680SVladimir Oltean * multiple native VLANs on the NPI port, because the switch doesn't 6169a720680SVladimir Oltean * look at the port tag settings towards the NPI interface anyway. 6179a720680SVladimir Oltean */ 6189a720680SVladimir Oltean if (port == ocelot->npi) 6199a720680SVladimir Oltean return 0; 6209a720680SVladimir Oltean 621b7a9e0daSVladimir Oltean return ocelot_vlan_prepare(ocelot, port, vlan->vid, 6222f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 6232f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 62456051948SVladimir Oltean } 62556051948SVladimir Oltean 626bae33f2bSVladimir Oltean static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) 62756051948SVladimir Oltean { 62856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 62956051948SVladimir Oltean 630bae33f2bSVladimir Oltean return ocelot_port_vlan_filtering(ocelot, port, enabled); 63156051948SVladimir Oltean } 63256051948SVladimir Oltean 6331958d581SVladimir Oltean static int felix_vlan_add(struct dsa_switch *ds, int port, 63456051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 63556051948SVladimir Oltean { 63656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 637183be6f9SVladimir Oltean u16 flags = vlan->flags; 6381958d581SVladimir Oltean int err; 63956051948SVladimir Oltean 6401958d581SVladimir Oltean err = felix_vlan_prepare(ds, port, vlan); 6411958d581SVladimir Oltean if (err) 6421958d581SVladimir Oltean return err; 6431958d581SVladimir Oltean 6441958d581SVladimir Oltean return ocelot_vlan_add(ocelot, port, vlan->vid, 645183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 646183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 64756051948SVladimir Oltean } 64856051948SVladimir Oltean 64956051948SVladimir Oltean static int felix_vlan_del(struct dsa_switch *ds, int port, 65056051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 65156051948SVladimir Oltean { 65256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 65356051948SVladimir Oltean 654b7a9e0daSVladimir Oltean return ocelot_vlan_del(ocelot, port, vlan->vid); 65556051948SVladimir Oltean } 65656051948SVladimir Oltean 65756051948SVladimir Oltean static int felix_port_enable(struct dsa_switch *ds, int port, 65856051948SVladimir Oltean struct phy_device *phy) 65956051948SVladimir Oltean { 66056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 66156051948SVladimir Oltean 66256051948SVladimir Oltean ocelot_port_enable(ocelot, port, phy); 66356051948SVladimir Oltean 66456051948SVladimir Oltean return 0; 66556051948SVladimir Oltean } 66656051948SVladimir Oltean 66756051948SVladimir Oltean static void felix_port_disable(struct dsa_switch *ds, int port) 66856051948SVladimir Oltean { 66956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 67056051948SVladimir Oltean 67156051948SVladimir Oltean return ocelot_port_disable(ocelot, port); 67256051948SVladimir Oltean } 67356051948SVladimir Oltean 674bdeced75SVladimir Oltean static void felix_phylink_validate(struct dsa_switch *ds, int port, 675bdeced75SVladimir Oltean unsigned long *supported, 676bdeced75SVladimir Oltean struct phylink_link_state *state) 677bdeced75SVladimir Oltean { 678bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 679375e1314SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 680bdeced75SVladimir Oltean 681375e1314SVladimir Oltean if (felix->info->phylink_validate) 682375e1314SVladimir Oltean felix->info->phylink_validate(ocelot, port, supported, state); 683bdeced75SVladimir Oltean } 684bdeced75SVladimir Oltean 685bdeced75SVladimir Oltean static void felix_phylink_mac_config(struct dsa_switch *ds, int port, 686bdeced75SVladimir Oltean unsigned int link_an_mode, 687bdeced75SVladimir Oltean const struct phylink_link_state *state) 688bdeced75SVladimir Oltean { 689bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 690bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 691588d0550SIoana Ciornei struct dsa_port *dp = dsa_to_port(ds, port); 692bdeced75SVladimir Oltean 693588d0550SIoana Ciornei if (felix->pcs[port]) 694588d0550SIoana Ciornei phylink_set_pcs(dp->pl, &felix->pcs[port]->pcs); 695bdeced75SVladimir Oltean } 696bdeced75SVladimir Oltean 697bdeced75SVladimir Oltean static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, 698bdeced75SVladimir Oltean unsigned int link_an_mode, 699bdeced75SVladimir Oltean phy_interface_t interface) 700bdeced75SVladimir Oltean { 701bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 702bdeced75SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 703eb4733d7SVladimir Oltean int err; 704bdeced75SVladimir Oltean 705eb4733d7SVladimir Oltean ocelot_port_rmwl(ocelot_port, 0, DEV_MAC_ENA_CFG_RX_ENA, 706eb4733d7SVladimir Oltean DEV_MAC_ENA_CFG); 707eb4733d7SVladimir Oltean 708886e1387SVladimir Oltean ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0); 709eb4733d7SVladimir Oltean 710eb4733d7SVladimir Oltean err = ocelot_port_flush(ocelot, port); 711eb4733d7SVladimir Oltean if (err) 712eb4733d7SVladimir Oltean dev_err(ocelot->dev, "failed to flush port %d: %d\n", 713eb4733d7SVladimir Oltean port, err); 714eb4733d7SVladimir Oltean 715eb4733d7SVladimir Oltean /* Put the port in reset. */ 716eb4733d7SVladimir Oltean ocelot_port_writel(ocelot_port, 717eb4733d7SVladimir Oltean DEV_CLOCK_CFG_MAC_TX_RST | 718eb4733d7SVladimir Oltean DEV_CLOCK_CFG_MAC_RX_RST | 719eb4733d7SVladimir Oltean DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000), 720eb4733d7SVladimir Oltean DEV_CLOCK_CFG); 721bdeced75SVladimir Oltean } 722bdeced75SVladimir Oltean 723bdeced75SVladimir Oltean static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, 724bdeced75SVladimir Oltean unsigned int link_an_mode, 725bdeced75SVladimir Oltean phy_interface_t interface, 7265b502a7bSRussell King struct phy_device *phydev, 7275b502a7bSRussell King int speed, int duplex, 7285b502a7bSRussell King bool tx_pause, bool rx_pause) 729bdeced75SVladimir Oltean { 730bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 731bdeced75SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 7327e14a2dcSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 7337e14a2dcSVladimir Oltean u32 mac_fc_cfg; 734bdeced75SVladimir Oltean 7357e14a2dcSVladimir Oltean /* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and 7367e14a2dcSVladimir Oltean * PORT_RST bits in DEV_CLOCK_CFG. Note that the way this system is 7377e14a2dcSVladimir Oltean * integrated is that the MAC speed is fixed and it's the PCS who is 7387e14a2dcSVladimir Oltean * performing the rate adaptation, so we have to write "1000Mbps" into 7397e14a2dcSVladimir Oltean * the LINK_SPEED field of DEV_CLOCK_CFG (which is also its default 7407e14a2dcSVladimir Oltean * value). 7417e14a2dcSVladimir Oltean */ 7427e14a2dcSVladimir Oltean ocelot_port_writel(ocelot_port, 7437e14a2dcSVladimir Oltean DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000), 7447e14a2dcSVladimir Oltean DEV_CLOCK_CFG); 7457e14a2dcSVladimir Oltean 7467e14a2dcSVladimir Oltean switch (speed) { 7477e14a2dcSVladimir Oltean case SPEED_10: 7487e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(3); 7497e14a2dcSVladimir Oltean break; 7507e14a2dcSVladimir Oltean case SPEED_100: 7517e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(2); 7527e14a2dcSVladimir Oltean break; 7537e14a2dcSVladimir Oltean case SPEED_1000: 7547e14a2dcSVladimir Oltean case SPEED_2500: 7557e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(1); 7567e14a2dcSVladimir Oltean break; 7577e14a2dcSVladimir Oltean default: 7587e14a2dcSVladimir Oltean dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n", 7597e14a2dcSVladimir Oltean port, speed); 7607e14a2dcSVladimir Oltean return; 7617e14a2dcSVladimir Oltean } 7627e14a2dcSVladimir Oltean 7637e14a2dcSVladimir Oltean /* handle Rx pause in all cases, with 2500base-X this is used for rate 7647e14a2dcSVladimir Oltean * adaptation. 7657e14a2dcSVladimir Oltean */ 7667e14a2dcSVladimir Oltean mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA; 7677e14a2dcSVladimir Oltean 7687e14a2dcSVladimir Oltean if (tx_pause) 7697e14a2dcSVladimir Oltean mac_fc_cfg |= SYS_MAC_FC_CFG_TX_FC_ENA | 7707e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) | 7717e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) | 7727e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_ZERO_PAUSE_ENA; 7737e14a2dcSVladimir Oltean 7747e14a2dcSVladimir Oltean /* Flow control. Link speed is only used here to evaluate the time 7757e14a2dcSVladimir Oltean * specification in incoming pause frames. 7767e14a2dcSVladimir Oltean */ 7777e14a2dcSVladimir Oltean ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port); 7787e14a2dcSVladimir Oltean 7797e14a2dcSVladimir Oltean ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port); 7807e14a2dcSVladimir Oltean 7817e14a2dcSVladimir Oltean /* Undo the effects of felix_phylink_mac_link_down: 7827e14a2dcSVladimir Oltean * enable MAC module 7837e14a2dcSVladimir Oltean */ 784bdeced75SVladimir Oltean ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA | 785bdeced75SVladimir Oltean DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG); 786bdeced75SVladimir Oltean 787bdeced75SVladimir Oltean /* Enable receiving frames on the port, and activate auto-learning of 788bdeced75SVladimir Oltean * MAC addresses. 789bdeced75SVladimir Oltean */ 790bdeced75SVladimir Oltean ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO | 791bdeced75SVladimir Oltean ANA_PORT_PORT_CFG_RECV_ENA | 792bdeced75SVladimir Oltean ANA_PORT_PORT_CFG_PORTID_VAL(port), 793bdeced75SVladimir Oltean ANA_PORT_PORT_CFG, port); 794bdeced75SVladimir Oltean 795bdeced75SVladimir Oltean /* Core: Enable port for frame transfer */ 796886e1387SVladimir Oltean ocelot_fields_write(ocelot, port, 797886e1387SVladimir Oltean QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); 7987e14a2dcSVladimir Oltean 7997e14a2dcSVladimir Oltean if (felix->info->port_sched_speed_set) 8007e14a2dcSVladimir Oltean felix->info->port_sched_speed_set(ocelot, port, speed); 801bdeced75SVladimir Oltean } 802bdeced75SVladimir Oltean 803bd2b3161SXiaoliang Yang static void felix_port_qos_map_init(struct ocelot *ocelot, int port) 804bd2b3161SXiaoliang Yang { 805bd2b3161SXiaoliang Yang int i; 806bd2b3161SXiaoliang Yang 807bd2b3161SXiaoliang Yang ocelot_rmw_gix(ocelot, 808bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 809bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 810bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG, 811bd2b3161SXiaoliang Yang port); 812bd2b3161SXiaoliang Yang 81370d39a6eSVladimir Oltean for (i = 0; i < OCELOT_NUM_TC * 2; i++) { 814bd2b3161SXiaoliang Yang ocelot_rmw_ix(ocelot, 815bd2b3161SXiaoliang Yang (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) | 816bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i), 817bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL | 818bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M, 819bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP, 820bd2b3161SXiaoliang Yang port, i); 821bd2b3161SXiaoliang Yang } 822bd2b3161SXiaoliang Yang } 823bd2b3161SXiaoliang Yang 82456051948SVladimir Oltean static void felix_get_strings(struct dsa_switch *ds, int port, 82556051948SVladimir Oltean u32 stringset, u8 *data) 82656051948SVladimir Oltean { 82756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 82856051948SVladimir Oltean 82956051948SVladimir Oltean return ocelot_get_strings(ocelot, port, stringset, data); 83056051948SVladimir Oltean } 83156051948SVladimir Oltean 83256051948SVladimir Oltean static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) 83356051948SVladimir Oltean { 83456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 83556051948SVladimir Oltean 83656051948SVladimir Oltean ocelot_get_ethtool_stats(ocelot, port, data); 83756051948SVladimir Oltean } 83856051948SVladimir Oltean 83956051948SVladimir Oltean static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) 84056051948SVladimir Oltean { 84156051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 84256051948SVladimir Oltean 84356051948SVladimir Oltean return ocelot_get_sset_count(ocelot, port, sset); 84456051948SVladimir Oltean } 84556051948SVladimir Oltean 84656051948SVladimir Oltean static int felix_get_ts_info(struct dsa_switch *ds, int port, 84756051948SVladimir Oltean struct ethtool_ts_info *info) 84856051948SVladimir Oltean { 84956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 85056051948SVladimir Oltean 85156051948SVladimir Oltean return ocelot_get_ts_info(ocelot, port, info); 85256051948SVladimir Oltean } 85356051948SVladimir Oltean 854bdeced75SVladimir Oltean static int felix_parse_ports_node(struct felix *felix, 855bdeced75SVladimir Oltean struct device_node *ports_node, 856bdeced75SVladimir Oltean phy_interface_t *port_phy_modes) 857bdeced75SVladimir Oltean { 858bdeced75SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 859bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 860bdeced75SVladimir Oltean struct device_node *child; 861bdeced75SVladimir Oltean 86237fe45adSVladimir Oltean for_each_available_child_of_node(ports_node, child) { 863bdeced75SVladimir Oltean phy_interface_t phy_mode; 864bdeced75SVladimir Oltean u32 port; 865bdeced75SVladimir Oltean int err; 866bdeced75SVladimir Oltean 867bdeced75SVladimir Oltean /* Get switch port number from DT */ 868bdeced75SVladimir Oltean if (of_property_read_u32(child, "reg", &port) < 0) { 869bdeced75SVladimir Oltean dev_err(dev, "Port number not defined in device tree " 870bdeced75SVladimir Oltean "(property \"reg\")\n"); 871bdeced75SVladimir Oltean of_node_put(child); 872bdeced75SVladimir Oltean return -ENODEV; 873bdeced75SVladimir Oltean } 874bdeced75SVladimir Oltean 875bdeced75SVladimir Oltean /* Get PHY mode from DT */ 876bdeced75SVladimir Oltean err = of_get_phy_mode(child, &phy_mode); 877bdeced75SVladimir Oltean if (err) { 878bdeced75SVladimir Oltean dev_err(dev, "Failed to read phy-mode or " 879bdeced75SVladimir Oltean "phy-interface-type property for port %d\n", 880bdeced75SVladimir Oltean port); 881bdeced75SVladimir Oltean of_node_put(child); 882bdeced75SVladimir Oltean return -ENODEV; 883bdeced75SVladimir Oltean } 884bdeced75SVladimir Oltean 885bdeced75SVladimir Oltean err = felix->info->prevalidate_phy_mode(ocelot, port, phy_mode); 886bdeced75SVladimir Oltean if (err < 0) { 887bdeced75SVladimir Oltean dev_err(dev, "Unsupported PHY mode %s on port %d\n", 888bdeced75SVladimir Oltean phy_modes(phy_mode), port); 88959ebb430SSumera Priyadarsini of_node_put(child); 890bdeced75SVladimir Oltean return err; 891bdeced75SVladimir Oltean } 892bdeced75SVladimir Oltean 893bdeced75SVladimir Oltean port_phy_modes[port] = phy_mode; 894bdeced75SVladimir Oltean } 895bdeced75SVladimir Oltean 896bdeced75SVladimir Oltean return 0; 897bdeced75SVladimir Oltean } 898bdeced75SVladimir Oltean 899bdeced75SVladimir Oltean static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes) 900bdeced75SVladimir Oltean { 901bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 902bdeced75SVladimir Oltean struct device_node *switch_node; 903bdeced75SVladimir Oltean struct device_node *ports_node; 904bdeced75SVladimir Oltean int err; 905bdeced75SVladimir Oltean 906bdeced75SVladimir Oltean switch_node = dev->of_node; 907bdeced75SVladimir Oltean 908bdeced75SVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ports"); 909bdeced75SVladimir Oltean if (!ports_node) { 910bdeced75SVladimir Oltean dev_err(dev, "Incorrect bindings: absent \"ports\" node\n"); 911bdeced75SVladimir Oltean return -ENODEV; 912bdeced75SVladimir Oltean } 913bdeced75SVladimir Oltean 914bdeced75SVladimir Oltean err = felix_parse_ports_node(felix, ports_node, port_phy_modes); 915bdeced75SVladimir Oltean of_node_put(ports_node); 916bdeced75SVladimir Oltean 917bdeced75SVladimir Oltean return err; 918bdeced75SVladimir Oltean } 919bdeced75SVladimir Oltean 92056051948SVladimir Oltean static int felix_init_structs(struct felix *felix, int num_phys_ports) 92156051948SVladimir Oltean { 92256051948SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 923bdeced75SVladimir Oltean phy_interface_t *port_phy_modes; 924b4024c9eSClaudiu Manoil struct resource res; 92556051948SVladimir Oltean int port, i, err; 92656051948SVladimir Oltean 92756051948SVladimir Oltean ocelot->num_phys_ports = num_phys_ports; 92856051948SVladimir Oltean ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, 92956051948SVladimir Oltean sizeof(struct ocelot_port *), GFP_KERNEL); 93056051948SVladimir Oltean if (!ocelot->ports) 93156051948SVladimir Oltean return -ENOMEM; 93256051948SVladimir Oltean 93356051948SVladimir Oltean ocelot->map = felix->info->map; 93456051948SVladimir Oltean ocelot->stats_layout = felix->info->stats_layout; 93556051948SVladimir Oltean ocelot->num_stats = felix->info->num_stats; 93621ce7f3eSVladimir Oltean ocelot->num_mact_rows = felix->info->num_mact_rows; 93707d985eeSVladimir Oltean ocelot->vcap = felix->info->vcap; 93856051948SVladimir Oltean ocelot->ops = felix->info->ops; 939cacea62fSVladimir Oltean ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT; 940cacea62fSVladimir Oltean ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT; 941f59fd9caSVladimir Oltean ocelot->devlink = felix->ds->devlink; 94256051948SVladimir Oltean 943bdeced75SVladimir Oltean port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t), 944bdeced75SVladimir Oltean GFP_KERNEL); 945bdeced75SVladimir Oltean if (!port_phy_modes) 946bdeced75SVladimir Oltean return -ENOMEM; 947bdeced75SVladimir Oltean 948bdeced75SVladimir Oltean err = felix_parse_dt(felix, port_phy_modes); 949bdeced75SVladimir Oltean if (err) { 950bdeced75SVladimir Oltean kfree(port_phy_modes); 951bdeced75SVladimir Oltean return err; 952bdeced75SVladimir Oltean } 953bdeced75SVladimir Oltean 95456051948SVladimir Oltean for (i = 0; i < TARGET_MAX; i++) { 95556051948SVladimir Oltean struct regmap *target; 95656051948SVladimir Oltean 95756051948SVladimir Oltean if (!felix->info->target_io_res[i].name) 95856051948SVladimir Oltean continue; 95956051948SVladimir Oltean 960b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->target_io_res[i], sizeof(res)); 961b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 962375e1314SVladimir Oltean res.start += felix->switch_base; 963375e1314SVladimir Oltean res.end += felix->switch_base; 96456051948SVladimir Oltean 965b4024c9eSClaudiu Manoil target = ocelot_regmap_init(ocelot, &res); 96656051948SVladimir Oltean if (IS_ERR(target)) { 96756051948SVladimir Oltean dev_err(ocelot->dev, 96856051948SVladimir Oltean "Failed to map device memory space\n"); 969bdeced75SVladimir Oltean kfree(port_phy_modes); 97056051948SVladimir Oltean return PTR_ERR(target); 97156051948SVladimir Oltean } 97256051948SVladimir Oltean 97356051948SVladimir Oltean ocelot->targets[i] = target; 97456051948SVladimir Oltean } 97556051948SVladimir Oltean 97656051948SVladimir Oltean err = ocelot_regfields_init(ocelot, felix->info->regfields); 97756051948SVladimir Oltean if (err) { 97856051948SVladimir Oltean dev_err(ocelot->dev, "failed to init reg fields map\n"); 979bdeced75SVladimir Oltean kfree(port_phy_modes); 98056051948SVladimir Oltean return err; 98156051948SVladimir Oltean } 98256051948SVladimir Oltean 98356051948SVladimir Oltean for (port = 0; port < num_phys_ports; port++) { 98456051948SVladimir Oltean struct ocelot_port *ocelot_port; 98591c724cfSVladimir Oltean struct regmap *target; 98667c24049SVladimir Oltean u8 *template; 98756051948SVladimir Oltean 98856051948SVladimir Oltean ocelot_port = devm_kzalloc(ocelot->dev, 98956051948SVladimir Oltean sizeof(struct ocelot_port), 99056051948SVladimir Oltean GFP_KERNEL); 99156051948SVladimir Oltean if (!ocelot_port) { 99256051948SVladimir Oltean dev_err(ocelot->dev, 99356051948SVladimir Oltean "failed to allocate port memory\n"); 994bdeced75SVladimir Oltean kfree(port_phy_modes); 99556051948SVladimir Oltean return -ENOMEM; 99656051948SVladimir Oltean } 99756051948SVladimir Oltean 998b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->port_io_res[port], sizeof(res)); 999b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 1000375e1314SVladimir Oltean res.start += felix->switch_base; 1001375e1314SVladimir Oltean res.end += felix->switch_base; 100256051948SVladimir Oltean 100391c724cfSVladimir Oltean target = ocelot_regmap_init(ocelot, &res); 100491c724cfSVladimir Oltean if (IS_ERR(target)) { 100556051948SVladimir Oltean dev_err(ocelot->dev, 100691c724cfSVladimir Oltean "Failed to map memory space for port %d\n", 100791c724cfSVladimir Oltean port); 1008bdeced75SVladimir Oltean kfree(port_phy_modes); 100991c724cfSVladimir Oltean return PTR_ERR(target); 101056051948SVladimir Oltean } 101156051948SVladimir Oltean 10125124197cSVladimir Oltean template = devm_kzalloc(ocelot->dev, OCELOT_TOTAL_TAG_LEN, 101367c24049SVladimir Oltean GFP_KERNEL); 101467c24049SVladimir Oltean if (!template) { 101567c24049SVladimir Oltean dev_err(ocelot->dev, 101667c24049SVladimir Oltean "Failed to allocate memory for DSA tag\n"); 101767c24049SVladimir Oltean kfree(port_phy_modes); 101867c24049SVladimir Oltean return -ENOMEM; 101967c24049SVladimir Oltean } 102067c24049SVladimir Oltean 1021bdeced75SVladimir Oltean ocelot_port->phy_mode = port_phy_modes[port]; 102256051948SVladimir Oltean ocelot_port->ocelot = ocelot; 102391c724cfSVladimir Oltean ocelot_port->target = target; 102467c24049SVladimir Oltean ocelot_port->xmit_template = template; 102556051948SVladimir Oltean ocelot->ports[port] = ocelot_port; 102667c24049SVladimir Oltean 102767c24049SVladimir Oltean felix->info->xmit_template_populate(ocelot, port); 102856051948SVladimir Oltean } 102956051948SVladimir Oltean 1030bdeced75SVladimir Oltean kfree(port_phy_modes); 1031bdeced75SVladimir Oltean 1032bdeced75SVladimir Oltean if (felix->info->mdio_bus_alloc) { 1033bdeced75SVladimir Oltean err = felix->info->mdio_bus_alloc(ocelot); 1034bdeced75SVladimir Oltean if (err < 0) 1035bdeced75SVladimir Oltean return err; 1036bdeced75SVladimir Oltean } 1037bdeced75SVladimir Oltean 103856051948SVladimir Oltean return 0; 103956051948SVladimir Oltean } 104056051948SVladimir Oltean 104156051948SVladimir Oltean /* Hardware initialization done here so that we can allocate structures with 104256051948SVladimir Oltean * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing 104356051948SVladimir Oltean * us to allocate structures twice (leak memory) and map PCI memory twice 104456051948SVladimir Oltean * (which will not work). 104556051948SVladimir Oltean */ 104656051948SVladimir Oltean static int felix_setup(struct dsa_switch *ds) 104756051948SVladimir Oltean { 104856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 104956051948SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 105056051948SVladimir Oltean int port, err; 105156051948SVladimir Oltean 105256051948SVladimir Oltean err = felix_init_structs(felix, ds->num_ports); 105356051948SVladimir Oltean if (err) 105456051948SVladimir Oltean return err; 105556051948SVladimir Oltean 1056d1cc0e93SVladimir Oltean err = ocelot_init(ocelot); 1057d1cc0e93SVladimir Oltean if (err) 1058d1cc0e93SVladimir Oltean return err; 1059d1cc0e93SVladimir Oltean 10602b49d128SYangbo Lu if (ocelot->ptp) { 10612ac7c6c5SVladimir Oltean err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); 10622b49d128SYangbo Lu if (err) { 10632b49d128SYangbo Lu dev_err(ocelot->dev, 10642b49d128SYangbo Lu "Timestamp initialization failed\n"); 10652b49d128SYangbo Lu ocelot->ptp = 0; 10662b49d128SYangbo Lu } 10672b49d128SYangbo Lu } 106856051948SVladimir Oltean 106956051948SVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1070adb3dccfSVladimir Oltean if (dsa_is_unused_port(ds, port)) 1071adb3dccfSVladimir Oltean continue; 107256051948SVladimir Oltean 1073adb3dccfSVladimir Oltean ocelot_init_port(ocelot, port); 1074bd2b3161SXiaoliang Yang 1075bd2b3161SXiaoliang Yang /* Set the default QoS Classification based on PCP and DEI 1076bd2b3161SXiaoliang Yang * bits of vlan tag. 1077bd2b3161SXiaoliang Yang */ 1078bd2b3161SXiaoliang Yang felix_port_qos_map_init(ocelot, port); 107956051948SVladimir Oltean } 108056051948SVladimir Oltean 1081f59fd9caSVladimir Oltean err = ocelot_devlink_sb_register(ocelot); 1082f59fd9caSVladimir Oltean if (err) 1083f59fd9caSVladimir Oltean return err; 1084f59fd9caSVladimir Oltean 1085adb3dccfSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1086adb3dccfSVladimir Oltean if (!dsa_is_cpu_port(ds, port)) 1087adb3dccfSVladimir Oltean continue; 1088adb3dccfSVladimir Oltean 1089adb3dccfSVladimir Oltean /* The initial tag protocol is NPI which always returns 0, so 1090adb3dccfSVladimir Oltean * there's no real point in checking for errors. 10911cf3299bSVladimir Oltean */ 1092adb3dccfSVladimir Oltean felix_set_tag_protocol(ds, port, felix->tag_proto); 1093adb3dccfSVladimir Oltean } 10941cf3299bSVladimir Oltean 10950b912fc9SVladimir Oltean ds->mtu_enforcement_ingress = true; 1096c54913c1SVladimir Oltean ds->assisted_learning_on_cpu_port = true; 1097bdeced75SVladimir Oltean 109856051948SVladimir Oltean return 0; 109956051948SVladimir Oltean } 110056051948SVladimir Oltean 110156051948SVladimir Oltean static void felix_teardown(struct dsa_switch *ds) 110256051948SVladimir Oltean { 110356051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 1104bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1105e5fb512dSVladimir Oltean int port; 1106bdeced75SVladimir Oltean 1107adb3dccfSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1108adb3dccfSVladimir Oltean if (!dsa_is_cpu_port(ds, port)) 1109adb3dccfSVladimir Oltean continue; 1110adb3dccfSVladimir Oltean 1111adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, port, felix->tag_proto); 1112adb3dccfSVladimir Oltean } 1113adb3dccfSVladimir Oltean 1114f59fd9caSVladimir Oltean ocelot_devlink_sb_unregister(ocelot); 1115d19741b0SVladimir Oltean ocelot_deinit_timestamp(ocelot); 1116d19741b0SVladimir Oltean ocelot_deinit(ocelot); 111756051948SVladimir Oltean 1118e5fb512dSVladimir Oltean for (port = 0; port < ocelot->num_phys_ports; port++) 1119e5fb512dSVladimir Oltean ocelot_deinit_port(ocelot, port); 1120d19741b0SVladimir Oltean 1121d19741b0SVladimir Oltean if (felix->info->mdio_bus_free) 1122d19741b0SVladimir Oltean felix->info->mdio_bus_free(ocelot); 112356051948SVladimir Oltean } 112456051948SVladimir Oltean 1125c0bcf537SYangbo Lu static int felix_hwtstamp_get(struct dsa_switch *ds, int port, 1126c0bcf537SYangbo Lu struct ifreq *ifr) 1127c0bcf537SYangbo Lu { 1128c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1129c0bcf537SYangbo Lu 1130c0bcf537SYangbo Lu return ocelot_hwstamp_get(ocelot, port, ifr); 1131c0bcf537SYangbo Lu } 1132c0bcf537SYangbo Lu 1133c0bcf537SYangbo Lu static int felix_hwtstamp_set(struct dsa_switch *ds, int port, 1134c0bcf537SYangbo Lu struct ifreq *ifr) 1135c0bcf537SYangbo Lu { 1136c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1137c0bcf537SYangbo Lu 1138c0bcf537SYangbo Lu return ocelot_hwstamp_set(ocelot, port, ifr); 1139c0bcf537SYangbo Lu } 1140c0bcf537SYangbo Lu 1141c0bcf537SYangbo Lu static bool felix_rxtstamp(struct dsa_switch *ds, int port, 1142c0bcf537SYangbo Lu struct sk_buff *skb, unsigned int type) 1143c0bcf537SYangbo Lu { 1144c0bcf537SYangbo Lu struct skb_shared_hwtstamps *shhwtstamps; 1145c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1146c0bcf537SYangbo Lu u8 *extraction = skb->data - ETH_HLEN - OCELOT_TAG_LEN; 1147c0bcf537SYangbo Lu u32 tstamp_lo, tstamp_hi; 1148c0bcf537SYangbo Lu struct timespec64 ts; 1149c0bcf537SYangbo Lu u64 tstamp, val; 1150c0bcf537SYangbo Lu 1151c0bcf537SYangbo Lu ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); 1152c0bcf537SYangbo Lu tstamp = ktime_set(ts.tv_sec, ts.tv_nsec); 1153c0bcf537SYangbo Lu 1154c0bcf537SYangbo Lu packing(extraction, &val, 116, 85, OCELOT_TAG_LEN, UNPACK, 0); 1155c0bcf537SYangbo Lu tstamp_lo = (u32)val; 1156c0bcf537SYangbo Lu 1157c0bcf537SYangbo Lu tstamp_hi = tstamp >> 32; 1158c0bcf537SYangbo Lu if ((tstamp & 0xffffffff) < tstamp_lo) 1159c0bcf537SYangbo Lu tstamp_hi--; 1160c0bcf537SYangbo Lu 1161c0bcf537SYangbo Lu tstamp = ((u64)tstamp_hi << 32) | tstamp_lo; 1162c0bcf537SYangbo Lu 1163c0bcf537SYangbo Lu shhwtstamps = skb_hwtstamps(skb); 1164c0bcf537SYangbo Lu memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); 1165c0bcf537SYangbo Lu shhwtstamps->hwtstamp = tstamp; 1166c0bcf537SYangbo Lu return false; 1167c0bcf537SYangbo Lu } 1168c0bcf537SYangbo Lu 11693243e04aSChen Wandun static bool felix_txtstamp(struct dsa_switch *ds, int port, 1170c0bcf537SYangbo Lu struct sk_buff *clone, unsigned int type) 1171c0bcf537SYangbo Lu { 1172c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1173c0bcf537SYangbo Lu struct ocelot_port *ocelot_port = ocelot->ports[port]; 1174c0bcf537SYangbo Lu 1175e2f9a8feSVladimir Oltean if (ocelot->ptp && (skb_shinfo(clone)->tx_flags & SKBTX_HW_TSTAMP) && 1176e2f9a8feSVladimir Oltean ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) { 1177e2f9a8feSVladimir Oltean ocelot_port_add_txtstamp_skb(ocelot, port, clone); 1178c0bcf537SYangbo Lu return true; 1179e2f9a8feSVladimir Oltean } 1180c0bcf537SYangbo Lu 1181c0bcf537SYangbo Lu return false; 1182c0bcf537SYangbo Lu } 1183c0bcf537SYangbo Lu 11840b912fc9SVladimir Oltean static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 11850b912fc9SVladimir Oltean { 11860b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 11870b912fc9SVladimir Oltean 11880b912fc9SVladimir Oltean ocelot_port_set_maxlen(ocelot, port, new_mtu); 11890b912fc9SVladimir Oltean 11900b912fc9SVladimir Oltean return 0; 11910b912fc9SVladimir Oltean } 11920b912fc9SVladimir Oltean 11930b912fc9SVladimir Oltean static int felix_get_max_mtu(struct dsa_switch *ds, int port) 11940b912fc9SVladimir Oltean { 11950b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 11960b912fc9SVladimir Oltean 11970b912fc9SVladimir Oltean return ocelot_get_max_mtu(ocelot, port); 11980b912fc9SVladimir Oltean } 11990b912fc9SVladimir Oltean 120007d985eeSVladimir Oltean static int felix_cls_flower_add(struct dsa_switch *ds, int port, 120107d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 120207d985eeSVladimir Oltean { 120307d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 120407d985eeSVladimir Oltean 120507d985eeSVladimir Oltean return ocelot_cls_flower_replace(ocelot, port, cls, ingress); 120607d985eeSVladimir Oltean } 120707d985eeSVladimir Oltean 120807d985eeSVladimir Oltean static int felix_cls_flower_del(struct dsa_switch *ds, int port, 120907d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 121007d985eeSVladimir Oltean { 121107d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 121207d985eeSVladimir Oltean 121307d985eeSVladimir Oltean return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); 121407d985eeSVladimir Oltean } 121507d985eeSVladimir Oltean 121607d985eeSVladimir Oltean static int felix_cls_flower_stats(struct dsa_switch *ds, int port, 121707d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 121807d985eeSVladimir Oltean { 121907d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 122007d985eeSVladimir Oltean 122107d985eeSVladimir Oltean return ocelot_cls_flower_stats(ocelot, port, cls, ingress); 122207d985eeSVladimir Oltean } 122307d985eeSVladimir Oltean 1224fc411eaaSVladimir Oltean static int felix_port_policer_add(struct dsa_switch *ds, int port, 1225fc411eaaSVladimir Oltean struct dsa_mall_policer_tc_entry *policer) 1226fc411eaaSVladimir Oltean { 1227fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1228fc411eaaSVladimir Oltean struct ocelot_policer pol = { 1229fc411eaaSVladimir Oltean .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, 12305f035af7SPo Liu .burst = policer->burst, 1231fc411eaaSVladimir Oltean }; 1232fc411eaaSVladimir Oltean 1233fc411eaaSVladimir Oltean return ocelot_port_policer_add(ocelot, port, &pol); 1234fc411eaaSVladimir Oltean } 1235fc411eaaSVladimir Oltean 1236fc411eaaSVladimir Oltean static void felix_port_policer_del(struct dsa_switch *ds, int port) 1237fc411eaaSVladimir Oltean { 1238fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1239fc411eaaSVladimir Oltean 1240fc411eaaSVladimir Oltean ocelot_port_policer_del(ocelot, port); 1241fc411eaaSVladimir Oltean } 1242fc411eaaSVladimir Oltean 1243de143c0eSXiaoliang Yang static int felix_port_setup_tc(struct dsa_switch *ds, int port, 1244de143c0eSXiaoliang Yang enum tc_setup_type type, 1245de143c0eSXiaoliang Yang void *type_data) 1246de143c0eSXiaoliang Yang { 1247de143c0eSXiaoliang Yang struct ocelot *ocelot = ds->priv; 1248de143c0eSXiaoliang Yang struct felix *felix = ocelot_to_felix(ocelot); 1249de143c0eSXiaoliang Yang 1250de143c0eSXiaoliang Yang if (felix->info->port_setup_tc) 1251de143c0eSXiaoliang Yang return felix->info->port_setup_tc(ds, port, type, type_data); 1252de143c0eSXiaoliang Yang else 1253de143c0eSXiaoliang Yang return -EOPNOTSUPP; 1254de143c0eSXiaoliang Yang } 1255de143c0eSXiaoliang Yang 1256f59fd9caSVladimir Oltean static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index, 1257f59fd9caSVladimir Oltean u16 pool_index, 1258f59fd9caSVladimir Oltean struct devlink_sb_pool_info *pool_info) 1259f59fd9caSVladimir Oltean { 1260f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1261f59fd9caSVladimir Oltean 1262f59fd9caSVladimir Oltean return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info); 1263f59fd9caSVladimir Oltean } 1264f59fd9caSVladimir Oltean 1265f59fd9caSVladimir Oltean static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index, 1266f59fd9caSVladimir Oltean u16 pool_index, u32 size, 1267f59fd9caSVladimir Oltean enum devlink_sb_threshold_type threshold_type, 1268f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1269f59fd9caSVladimir Oltean { 1270f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1271f59fd9caSVladimir Oltean 1272f59fd9caSVladimir Oltean return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size, 1273f59fd9caSVladimir Oltean threshold_type, extack); 1274f59fd9caSVladimir Oltean } 1275f59fd9caSVladimir Oltean 1276f59fd9caSVladimir Oltean static int felix_sb_port_pool_get(struct dsa_switch *ds, int port, 1277f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1278f59fd9caSVladimir Oltean u32 *p_threshold) 1279f59fd9caSVladimir Oltean { 1280f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1281f59fd9caSVladimir Oltean 1282f59fd9caSVladimir Oltean return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index, 1283f59fd9caSVladimir Oltean p_threshold); 1284f59fd9caSVladimir Oltean } 1285f59fd9caSVladimir Oltean 1286f59fd9caSVladimir Oltean static int felix_sb_port_pool_set(struct dsa_switch *ds, int port, 1287f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1288f59fd9caSVladimir Oltean u32 threshold, struct netlink_ext_ack *extack) 1289f59fd9caSVladimir Oltean { 1290f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1291f59fd9caSVladimir Oltean 1292f59fd9caSVladimir Oltean return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index, 1293f59fd9caSVladimir Oltean threshold, extack); 1294f59fd9caSVladimir Oltean } 1295f59fd9caSVladimir Oltean 1296f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port, 1297f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1298f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1299f59fd9caSVladimir Oltean u16 *p_pool_index, u32 *p_threshold) 1300f59fd9caSVladimir Oltean { 1301f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1302f59fd9caSVladimir Oltean 1303f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index, 1304f59fd9caSVladimir Oltean pool_type, p_pool_index, 1305f59fd9caSVladimir Oltean p_threshold); 1306f59fd9caSVladimir Oltean } 1307f59fd9caSVladimir Oltean 1308f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_set(struct dsa_switch *ds, int port, 1309f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1310f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1311f59fd9caSVladimir Oltean u16 pool_index, u32 threshold, 1312f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1313f59fd9caSVladimir Oltean { 1314f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1315f59fd9caSVladimir Oltean 1316f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index, 1317f59fd9caSVladimir Oltean pool_type, pool_index, threshold, 1318f59fd9caSVladimir Oltean extack); 1319f59fd9caSVladimir Oltean } 1320f59fd9caSVladimir Oltean 1321f59fd9caSVladimir Oltean static int felix_sb_occ_snapshot(struct dsa_switch *ds, 1322f59fd9caSVladimir Oltean unsigned int sb_index) 1323f59fd9caSVladimir Oltean { 1324f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1325f59fd9caSVladimir Oltean 1326f59fd9caSVladimir Oltean return ocelot_sb_occ_snapshot(ocelot, sb_index); 1327f59fd9caSVladimir Oltean } 1328f59fd9caSVladimir Oltean 1329f59fd9caSVladimir Oltean static int felix_sb_occ_max_clear(struct dsa_switch *ds, 1330f59fd9caSVladimir Oltean unsigned int sb_index) 1331f59fd9caSVladimir Oltean { 1332f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1333f59fd9caSVladimir Oltean 1334f59fd9caSVladimir Oltean return ocelot_sb_occ_max_clear(ocelot, sb_index); 1335f59fd9caSVladimir Oltean } 1336f59fd9caSVladimir Oltean 1337f59fd9caSVladimir Oltean static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port, 1338f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1339f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1340f59fd9caSVladimir Oltean { 1341f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1342f59fd9caSVladimir Oltean 1343f59fd9caSVladimir Oltean return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index, 1344f59fd9caSVladimir Oltean p_cur, p_max); 1345f59fd9caSVladimir Oltean } 1346f59fd9caSVladimir Oltean 1347f59fd9caSVladimir Oltean static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port, 1348f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1349f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1350f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1351f59fd9caSVladimir Oltean { 1352f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1353f59fd9caSVladimir Oltean 1354f59fd9caSVladimir Oltean return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index, 1355f59fd9caSVladimir Oltean pool_type, p_cur, p_max); 1356f59fd9caSVladimir Oltean } 1357f59fd9caSVladimir Oltean 1358375e1314SVladimir Oltean const struct dsa_switch_ops felix_switch_ops = { 135956051948SVladimir Oltean .get_tag_protocol = felix_get_tag_protocol, 1360adb3dccfSVladimir Oltean .change_tag_protocol = felix_change_tag_protocol, 136156051948SVladimir Oltean .setup = felix_setup, 136256051948SVladimir Oltean .teardown = felix_teardown, 136356051948SVladimir Oltean .set_ageing_time = felix_set_ageing_time, 136456051948SVladimir Oltean .get_strings = felix_get_strings, 136556051948SVladimir Oltean .get_ethtool_stats = felix_get_ethtool_stats, 136656051948SVladimir Oltean .get_sset_count = felix_get_sset_count, 136756051948SVladimir Oltean .get_ts_info = felix_get_ts_info, 1368bdeced75SVladimir Oltean .phylink_validate = felix_phylink_validate, 1369bdeced75SVladimir Oltean .phylink_mac_config = felix_phylink_mac_config, 1370bdeced75SVladimir Oltean .phylink_mac_link_down = felix_phylink_mac_link_down, 1371bdeced75SVladimir Oltean .phylink_mac_link_up = felix_phylink_mac_link_up, 137256051948SVladimir Oltean .port_enable = felix_port_enable, 137356051948SVladimir Oltean .port_disable = felix_port_disable, 137456051948SVladimir Oltean .port_fdb_dump = felix_fdb_dump, 137556051948SVladimir Oltean .port_fdb_add = felix_fdb_add, 137656051948SVladimir Oltean .port_fdb_del = felix_fdb_del, 1377209edf95SVladimir Oltean .port_mdb_add = felix_mdb_add, 1378209edf95SVladimir Oltean .port_mdb_del = felix_mdb_del, 137956051948SVladimir Oltean .port_bridge_join = felix_bridge_join, 138056051948SVladimir Oltean .port_bridge_leave = felix_bridge_leave, 13818fe6832eSVladimir Oltean .port_lag_join = felix_lag_join, 13828fe6832eSVladimir Oltean .port_lag_leave = felix_lag_leave, 13838fe6832eSVladimir Oltean .port_lag_change = felix_lag_change, 138456051948SVladimir Oltean .port_stp_state_set = felix_bridge_stp_state_set, 138556051948SVladimir Oltean .port_vlan_filtering = felix_vlan_filtering, 138656051948SVladimir Oltean .port_vlan_add = felix_vlan_add, 138756051948SVladimir Oltean .port_vlan_del = felix_vlan_del, 1388c0bcf537SYangbo Lu .port_hwtstamp_get = felix_hwtstamp_get, 1389c0bcf537SYangbo Lu .port_hwtstamp_set = felix_hwtstamp_set, 1390c0bcf537SYangbo Lu .port_rxtstamp = felix_rxtstamp, 1391c0bcf537SYangbo Lu .port_txtstamp = felix_txtstamp, 13920b912fc9SVladimir Oltean .port_change_mtu = felix_change_mtu, 13930b912fc9SVladimir Oltean .port_max_mtu = felix_get_max_mtu, 1394fc411eaaSVladimir Oltean .port_policer_add = felix_port_policer_add, 1395fc411eaaSVladimir Oltean .port_policer_del = felix_port_policer_del, 139607d985eeSVladimir Oltean .cls_flower_add = felix_cls_flower_add, 139707d985eeSVladimir Oltean .cls_flower_del = felix_cls_flower_del, 139807d985eeSVladimir Oltean .cls_flower_stats = felix_cls_flower_stats, 1399de143c0eSXiaoliang Yang .port_setup_tc = felix_port_setup_tc, 1400f59fd9caSVladimir Oltean .devlink_sb_pool_get = felix_sb_pool_get, 1401f59fd9caSVladimir Oltean .devlink_sb_pool_set = felix_sb_pool_set, 1402f59fd9caSVladimir Oltean .devlink_sb_port_pool_get = felix_sb_port_pool_get, 1403f59fd9caSVladimir Oltean .devlink_sb_port_pool_set = felix_sb_port_pool_set, 1404f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get, 1405f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set, 1406f59fd9caSVladimir Oltean .devlink_sb_occ_snapshot = felix_sb_occ_snapshot, 1407f59fd9caSVladimir Oltean .devlink_sb_occ_max_clear = felix_sb_occ_max_clear, 1408f59fd9caSVladimir Oltean .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get, 1409f59fd9caSVladimir Oltean .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get, 141056051948SVladimir Oltean }; 1411319e4dd1SVladimir Oltean 1412319e4dd1SVladimir Oltean struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) 1413319e4dd1SVladimir Oltean { 1414319e4dd1SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1415319e4dd1SVladimir Oltean struct dsa_switch *ds = felix->ds; 1416319e4dd1SVladimir Oltean 1417319e4dd1SVladimir Oltean if (!dsa_is_user_port(ds, port)) 1418319e4dd1SVladimir Oltean return NULL; 1419319e4dd1SVladimir Oltean 1420319e4dd1SVladimir Oltean return dsa_to_port(ds, port)->slave; 1421319e4dd1SVladimir Oltean } 1422319e4dd1SVladimir Oltean 1423319e4dd1SVladimir Oltean int felix_netdev_to_port(struct net_device *dev) 1424319e4dd1SVladimir Oltean { 1425319e4dd1SVladimir Oltean struct dsa_port *dp; 1426319e4dd1SVladimir Oltean 1427319e4dd1SVladimir Oltean dp = dsa_port_from_netdev(dev); 1428319e4dd1SVladimir Oltean if (IS_ERR(dp)) 1429319e4dd1SVladimir Oltean return -EINVAL; 1430319e4dd1SVladimir Oltean 1431319e4dd1SVladimir Oltean return dp->index; 1432319e4dd1SVladimir Oltean } 1433