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); 302e21268efSVladimir Oltean 303e21268efSVladimir Oltean felix->dsa_8021q_ctx = kzalloc(sizeof(*felix->dsa_8021q_ctx), 304e21268efSVladimir Oltean GFP_KERNEL); 305e21268efSVladimir Oltean if (!felix->dsa_8021q_ctx) 306e21268efSVladimir Oltean return -ENOMEM; 307e21268efSVladimir Oltean 308e21268efSVladimir Oltean felix->dsa_8021q_ctx->ops = &felix_tag_8021q_ops; 309e21268efSVladimir Oltean felix->dsa_8021q_ctx->proto = htons(ETH_P_8021AD); 310e21268efSVladimir Oltean felix->dsa_8021q_ctx->ds = ds; 311e21268efSVladimir Oltean 312e21268efSVladimir Oltean err = dsa_8021q_setup(felix->dsa_8021q_ctx, true); 313e21268efSVladimir Oltean if (err) 314e21268efSVladimir Oltean goto out_free_dsa_8021_ctx; 315e21268efSVladimir Oltean 316e21268efSVladimir Oltean return 0; 317e21268efSVladimir Oltean 318e21268efSVladimir Oltean out_free_dsa_8021_ctx: 319e21268efSVladimir Oltean kfree(felix->dsa_8021q_ctx); 320e21268efSVladimir Oltean return err; 321e21268efSVladimir Oltean } 322e21268efSVladimir Oltean 323e21268efSVladimir Oltean static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) 324e21268efSVladimir Oltean { 325e21268efSVladimir Oltean struct ocelot *ocelot = ds->priv; 326e21268efSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 327e21268efSVladimir Oltean int err, port; 328e21268efSVladimir Oltean 329e21268efSVladimir Oltean err = dsa_8021q_setup(felix->dsa_8021q_ctx, false); 330e21268efSVladimir Oltean if (err) 331e21268efSVladimir Oltean dev_err(ds->dev, "dsa_8021q_setup returned %d", err); 332e21268efSVladimir Oltean 333e21268efSVladimir Oltean kfree(felix->dsa_8021q_ctx); 334e21268efSVladimir Oltean 335e21268efSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 336e21268efSVladimir Oltean if (dsa_is_unused_port(ds, port)) 337e21268efSVladimir Oltean continue; 338e21268efSVladimir Oltean 339e21268efSVladimir Oltean /* Restore the logic from ocelot_init: 340e21268efSVladimir Oltean * do not forward BPDU frames to the front ports. 341e21268efSVladimir Oltean */ 342e21268efSVladimir Oltean ocelot_write_gix(ocelot, 343e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff), 344e21268efSVladimir Oltean ANA_PORT_CPU_FWD_BPDU_CFG, 345e21268efSVladimir Oltean port); 346e21268efSVladimir Oltean } 347e21268efSVladimir Oltean 348e21268efSVladimir Oltean felix_8021q_cpu_port_deinit(ocelot, cpu); 349e21268efSVladimir Oltean } 350e21268efSVladimir Oltean 351adb3dccfSVladimir Oltean /* The CPU port module is connected to the Node Processor Interface (NPI). This 352adb3dccfSVladimir Oltean * is the mode through which frames can be injected from and extracted to an 353adb3dccfSVladimir Oltean * external CPU, over Ethernet. In NXP SoCs, the "external CPU" is the ARM CPU 354adb3dccfSVladimir Oltean * running Linux, and this forms a DSA setup together with the enetc or fman 355adb3dccfSVladimir Oltean * DSA master. 356adb3dccfSVladimir Oltean */ 357adb3dccfSVladimir Oltean static void felix_npi_port_init(struct ocelot *ocelot, int port) 358adb3dccfSVladimir Oltean { 359adb3dccfSVladimir Oltean ocelot->npi = port; 360adb3dccfSVladimir Oltean 361adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPUQ_MSK_M | 362adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG_EXT_CPU_PORT(port), 363adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 364adb3dccfSVladimir Oltean 365adb3dccfSVladimir Oltean /* NPI port Injection/Extraction configuration */ 366adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 367adb3dccfSVladimir Oltean ocelot->npi_xtr_prefix); 368adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 369adb3dccfSVladimir Oltean ocelot->npi_inj_prefix); 370adb3dccfSVladimir Oltean 371adb3dccfSVladimir Oltean /* Disable transmission of pause frames */ 372adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 0); 373adb3dccfSVladimir Oltean } 374adb3dccfSVladimir Oltean 375adb3dccfSVladimir Oltean static void felix_npi_port_deinit(struct ocelot *ocelot, int port) 376adb3dccfSVladimir Oltean { 377adb3dccfSVladimir Oltean /* Restore hardware defaults */ 378adb3dccfSVladimir Oltean int unused_port = ocelot->num_phys_ports + 2; 379adb3dccfSVladimir Oltean 380adb3dccfSVladimir Oltean ocelot->npi = -1; 381adb3dccfSVladimir Oltean 382adb3dccfSVladimir Oltean ocelot_write(ocelot, QSYS_EXT_CPU_CFG_EXT_CPU_PORT(unused_port), 383adb3dccfSVladimir Oltean QSYS_EXT_CPU_CFG); 384adb3dccfSVladimir Oltean 385adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_XTR_HDR, 386adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 387adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PORT_MODE_INCL_INJ_HDR, 388adb3dccfSVladimir Oltean OCELOT_TAG_PREFIX_DISABLED); 389adb3dccfSVladimir Oltean 390adb3dccfSVladimir Oltean /* Enable transmission of pause frames */ 391adb3dccfSVladimir Oltean ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, 1); 392adb3dccfSVladimir Oltean } 393adb3dccfSVladimir Oltean 394adb3dccfSVladimir Oltean static int felix_setup_tag_npi(struct dsa_switch *ds, int cpu) 395adb3dccfSVladimir Oltean { 396adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 397adb3dccfSVladimir Oltean unsigned long cpu_flood; 398adb3dccfSVladimir Oltean 399adb3dccfSVladimir Oltean felix_npi_port_init(ocelot, cpu); 400adb3dccfSVladimir Oltean 401adb3dccfSVladimir Oltean /* Include the CPU port module (and indirectly, the NPI port) 402adb3dccfSVladimir Oltean * in the forwarding mask for unknown unicast - the hardware 403adb3dccfSVladimir Oltean * default value for ANA_FLOODING_FLD_UNICAST excludes 404adb3dccfSVladimir Oltean * BIT(ocelot->num_phys_ports), and so does ocelot_init, 405adb3dccfSVladimir Oltean * since Ocelot relies on whitelisting MAC addresses towards 406adb3dccfSVladimir Oltean * PGID_CPU. 407adb3dccfSVladimir Oltean * We do this because DSA does not yet perform RX filtering, 408adb3dccfSVladimir Oltean * and the NPI port does not perform source address learning, 409adb3dccfSVladimir Oltean * so traffic sent to Linux is effectively unknown from the 410adb3dccfSVladimir Oltean * switch's perspective. 411adb3dccfSVladimir Oltean */ 412adb3dccfSVladimir Oltean cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports)); 413adb3dccfSVladimir Oltean ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_UC); 414*6edb9e8dSVladimir Oltean ocelot_rmw_rix(ocelot, cpu_flood, cpu_flood, ANA_PGID_PGID, PGID_MC); 415adb3dccfSVladimir Oltean 416adb3dccfSVladimir Oltean return 0; 417adb3dccfSVladimir Oltean } 418adb3dccfSVladimir Oltean 419adb3dccfSVladimir Oltean static void felix_teardown_tag_npi(struct dsa_switch *ds, int cpu) 420adb3dccfSVladimir Oltean { 421adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 422adb3dccfSVladimir Oltean 423adb3dccfSVladimir Oltean felix_npi_port_deinit(ocelot, cpu); 424adb3dccfSVladimir Oltean } 425adb3dccfSVladimir Oltean 426adb3dccfSVladimir Oltean static int felix_set_tag_protocol(struct dsa_switch *ds, int cpu, 427adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 428adb3dccfSVladimir Oltean { 429adb3dccfSVladimir Oltean int err; 430adb3dccfSVladimir Oltean 431adb3dccfSVladimir Oltean switch (proto) { 432adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 433adb3dccfSVladimir Oltean err = felix_setup_tag_npi(ds, cpu); 434adb3dccfSVladimir Oltean break; 435e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 436e21268efSVladimir Oltean err = felix_setup_tag_8021q(ds, cpu); 437e21268efSVladimir Oltean break; 438adb3dccfSVladimir Oltean default: 439adb3dccfSVladimir Oltean err = -EPROTONOSUPPORT; 440adb3dccfSVladimir Oltean } 441adb3dccfSVladimir Oltean 442adb3dccfSVladimir Oltean return err; 443adb3dccfSVladimir Oltean } 444adb3dccfSVladimir Oltean 445adb3dccfSVladimir Oltean static void felix_del_tag_protocol(struct dsa_switch *ds, int cpu, 446adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 447adb3dccfSVladimir Oltean { 448adb3dccfSVladimir Oltean switch (proto) { 449adb3dccfSVladimir Oltean case DSA_TAG_PROTO_OCELOT: 450adb3dccfSVladimir Oltean felix_teardown_tag_npi(ds, cpu); 451adb3dccfSVladimir Oltean break; 452e21268efSVladimir Oltean case DSA_TAG_PROTO_OCELOT_8021Q: 453e21268efSVladimir Oltean felix_teardown_tag_8021q(ds, cpu); 454e21268efSVladimir Oltean break; 455adb3dccfSVladimir Oltean default: 456adb3dccfSVladimir Oltean break; 457adb3dccfSVladimir Oltean } 458adb3dccfSVladimir Oltean } 459adb3dccfSVladimir Oltean 460e21268efSVladimir Oltean /* This always leaves the switch in a consistent state, because although the 461e21268efSVladimir Oltean * tag_8021q setup can fail, the NPI setup can't. So either the change is made, 462e21268efSVladimir Oltean * or the restoration is guaranteed to work. 463e21268efSVladimir Oltean */ 464adb3dccfSVladimir Oltean static int felix_change_tag_protocol(struct dsa_switch *ds, int cpu, 465adb3dccfSVladimir Oltean enum dsa_tag_protocol proto) 466adb3dccfSVladimir Oltean { 467adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 468adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 469adb3dccfSVladimir Oltean enum dsa_tag_protocol old_proto = felix->tag_proto; 470adb3dccfSVladimir Oltean int err; 471adb3dccfSVladimir Oltean 472e21268efSVladimir Oltean if (proto != DSA_TAG_PROTO_OCELOT && 473e21268efSVladimir Oltean proto != DSA_TAG_PROTO_OCELOT_8021Q) 474adb3dccfSVladimir Oltean return -EPROTONOSUPPORT; 475adb3dccfSVladimir Oltean 476adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, cpu, old_proto); 477adb3dccfSVladimir Oltean 478adb3dccfSVladimir Oltean err = felix_set_tag_protocol(ds, cpu, proto); 479adb3dccfSVladimir Oltean if (err) { 480adb3dccfSVladimir Oltean felix_set_tag_protocol(ds, cpu, old_proto); 481adb3dccfSVladimir Oltean return err; 482adb3dccfSVladimir Oltean } 483adb3dccfSVladimir Oltean 484adb3dccfSVladimir Oltean felix->tag_proto = proto; 485adb3dccfSVladimir Oltean 486adb3dccfSVladimir Oltean return 0; 487adb3dccfSVladimir Oltean } 488adb3dccfSVladimir Oltean 48956051948SVladimir Oltean static enum dsa_tag_protocol felix_get_tag_protocol(struct dsa_switch *ds, 4904d776482SFlorian Fainelli int port, 4914d776482SFlorian Fainelli enum dsa_tag_protocol mp) 49256051948SVladimir Oltean { 493adb3dccfSVladimir Oltean struct ocelot *ocelot = ds->priv; 494adb3dccfSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 495adb3dccfSVladimir Oltean 496adb3dccfSVladimir Oltean return felix->tag_proto; 49756051948SVladimir Oltean } 49856051948SVladimir Oltean 49956051948SVladimir Oltean static int felix_set_ageing_time(struct dsa_switch *ds, 50056051948SVladimir Oltean unsigned int ageing_time) 50156051948SVladimir Oltean { 50256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 50356051948SVladimir Oltean 50456051948SVladimir Oltean ocelot_set_ageing_time(ocelot, ageing_time); 50556051948SVladimir Oltean 50656051948SVladimir Oltean return 0; 50756051948SVladimir Oltean } 50856051948SVladimir Oltean 50956051948SVladimir Oltean static int felix_fdb_dump(struct dsa_switch *ds, int port, 51056051948SVladimir Oltean dsa_fdb_dump_cb_t *cb, void *data) 51156051948SVladimir Oltean { 51256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 51356051948SVladimir Oltean 51456051948SVladimir Oltean return ocelot_fdb_dump(ocelot, port, cb, data); 51556051948SVladimir Oltean } 51656051948SVladimir Oltean 51756051948SVladimir Oltean static int felix_fdb_add(struct dsa_switch *ds, int port, 51856051948SVladimir Oltean const unsigned char *addr, u16 vid) 51956051948SVladimir Oltean { 52056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 52156051948SVladimir Oltean 52287b0f983SVladimir Oltean return ocelot_fdb_add(ocelot, port, addr, vid); 52356051948SVladimir Oltean } 52456051948SVladimir Oltean 52556051948SVladimir Oltean static int felix_fdb_del(struct dsa_switch *ds, int port, 52656051948SVladimir Oltean const unsigned char *addr, u16 vid) 52756051948SVladimir Oltean { 52856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 52956051948SVladimir Oltean 53056051948SVladimir Oltean return ocelot_fdb_del(ocelot, port, addr, vid); 53156051948SVladimir Oltean } 53256051948SVladimir Oltean 533a52b2da7SVladimir Oltean static int felix_mdb_add(struct dsa_switch *ds, int port, 534209edf95SVladimir Oltean const struct switchdev_obj_port_mdb *mdb) 535209edf95SVladimir Oltean { 536209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 537209edf95SVladimir Oltean 538a52b2da7SVladimir Oltean return ocelot_port_mdb_add(ocelot, port, mdb); 539209edf95SVladimir Oltean } 540209edf95SVladimir Oltean 541209edf95SVladimir Oltean static int felix_mdb_del(struct dsa_switch *ds, int port, 542209edf95SVladimir Oltean const struct switchdev_obj_port_mdb *mdb) 543209edf95SVladimir Oltean { 544209edf95SVladimir Oltean struct ocelot *ocelot = ds->priv; 545209edf95SVladimir Oltean 546209edf95SVladimir Oltean return ocelot_port_mdb_del(ocelot, port, mdb); 547209edf95SVladimir Oltean } 548209edf95SVladimir Oltean 54956051948SVladimir Oltean static void felix_bridge_stp_state_set(struct dsa_switch *ds, int port, 55056051948SVladimir Oltean u8 state) 55156051948SVladimir Oltean { 55256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 55356051948SVladimir Oltean 55456051948SVladimir Oltean return ocelot_bridge_stp_state_set(ocelot, port, state); 55556051948SVladimir Oltean } 55656051948SVladimir Oltean 55756051948SVladimir Oltean static int felix_bridge_join(struct dsa_switch *ds, int port, 55856051948SVladimir Oltean struct net_device *br) 55956051948SVladimir Oltean { 56056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 56156051948SVladimir Oltean 56256051948SVladimir Oltean return ocelot_port_bridge_join(ocelot, port, br); 56356051948SVladimir Oltean } 56456051948SVladimir Oltean 56556051948SVladimir Oltean static void felix_bridge_leave(struct dsa_switch *ds, int port, 56656051948SVladimir Oltean struct net_device *br) 56756051948SVladimir Oltean { 56856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 56956051948SVladimir Oltean 57056051948SVladimir Oltean ocelot_port_bridge_leave(ocelot, port, br); 57156051948SVladimir Oltean } 57256051948SVladimir Oltean 5738fe6832eSVladimir Oltean static int felix_lag_join(struct dsa_switch *ds, int port, 5748fe6832eSVladimir Oltean struct net_device *bond, 5758fe6832eSVladimir Oltean struct netdev_lag_upper_info *info) 5768fe6832eSVladimir Oltean { 5778fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 5788fe6832eSVladimir Oltean 5798fe6832eSVladimir Oltean return ocelot_port_lag_join(ocelot, port, bond, info); 5808fe6832eSVladimir Oltean } 5818fe6832eSVladimir Oltean 5828fe6832eSVladimir Oltean static int felix_lag_leave(struct dsa_switch *ds, int port, 5838fe6832eSVladimir Oltean struct net_device *bond) 5848fe6832eSVladimir Oltean { 5858fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 5868fe6832eSVladimir Oltean 5878fe6832eSVladimir Oltean ocelot_port_lag_leave(ocelot, port, bond); 5888fe6832eSVladimir Oltean 5898fe6832eSVladimir Oltean return 0; 5908fe6832eSVladimir Oltean } 5918fe6832eSVladimir Oltean 5928fe6832eSVladimir Oltean static int felix_lag_change(struct dsa_switch *ds, int port) 5938fe6832eSVladimir Oltean { 5948fe6832eSVladimir Oltean struct dsa_port *dp = dsa_to_port(ds, port); 5958fe6832eSVladimir Oltean struct ocelot *ocelot = ds->priv; 5968fe6832eSVladimir Oltean 5978fe6832eSVladimir Oltean ocelot_port_lag_change(ocelot, port, dp->lag_tx_enabled); 5988fe6832eSVladimir Oltean 5998fe6832eSVladimir Oltean return 0; 6008fe6832eSVladimir Oltean } 6018fe6832eSVladimir Oltean 60256051948SVladimir Oltean static int felix_vlan_prepare(struct dsa_switch *ds, int port, 60356051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 60456051948SVladimir Oltean { 6052f0402feSVladimir Oltean struct ocelot *ocelot = ds->priv; 606b7a9e0daSVladimir Oltean u16 flags = vlan->flags; 6072f0402feSVladimir Oltean 6089a720680SVladimir Oltean /* Ocelot switches copy frames as-is to the CPU, so the flags: 6099a720680SVladimir Oltean * egress-untagged or not, pvid or not, make no difference. This 6109a720680SVladimir Oltean * behavior is already better than what DSA just tries to approximate 6119a720680SVladimir Oltean * when it installs the VLAN with the same flags on the CPU port. 6129a720680SVladimir Oltean * Just accept any configuration, and don't let ocelot deny installing 6139a720680SVladimir Oltean * multiple native VLANs on the NPI port, because the switch doesn't 6149a720680SVladimir Oltean * look at the port tag settings towards the NPI interface anyway. 6159a720680SVladimir Oltean */ 6169a720680SVladimir Oltean if (port == ocelot->npi) 6179a720680SVladimir Oltean return 0; 6189a720680SVladimir Oltean 619b7a9e0daSVladimir Oltean return ocelot_vlan_prepare(ocelot, port, vlan->vid, 6202f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 6212f0402feSVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 62256051948SVladimir Oltean } 62356051948SVladimir Oltean 624bae33f2bSVladimir Oltean static int felix_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) 62556051948SVladimir Oltean { 62656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 62756051948SVladimir Oltean 628bae33f2bSVladimir Oltean return ocelot_port_vlan_filtering(ocelot, port, enabled); 62956051948SVladimir Oltean } 63056051948SVladimir Oltean 6311958d581SVladimir Oltean static int felix_vlan_add(struct dsa_switch *ds, int port, 63256051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 63356051948SVladimir Oltean { 63456051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 635183be6f9SVladimir Oltean u16 flags = vlan->flags; 6361958d581SVladimir Oltean int err; 63756051948SVladimir Oltean 6381958d581SVladimir Oltean err = felix_vlan_prepare(ds, port, vlan); 6391958d581SVladimir Oltean if (err) 6401958d581SVladimir Oltean return err; 6411958d581SVladimir Oltean 6421958d581SVladimir Oltean return ocelot_vlan_add(ocelot, port, vlan->vid, 643183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_PVID, 644183be6f9SVladimir Oltean flags & BRIDGE_VLAN_INFO_UNTAGGED); 64556051948SVladimir Oltean } 64656051948SVladimir Oltean 64756051948SVladimir Oltean static int felix_vlan_del(struct dsa_switch *ds, int port, 64856051948SVladimir Oltean const struct switchdev_obj_port_vlan *vlan) 64956051948SVladimir Oltean { 65056051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 65156051948SVladimir Oltean 652b7a9e0daSVladimir Oltean return ocelot_vlan_del(ocelot, port, vlan->vid); 65356051948SVladimir Oltean } 65456051948SVladimir Oltean 65556051948SVladimir Oltean static int felix_port_enable(struct dsa_switch *ds, int port, 65656051948SVladimir Oltean struct phy_device *phy) 65756051948SVladimir Oltean { 65856051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 65956051948SVladimir Oltean 66056051948SVladimir Oltean ocelot_port_enable(ocelot, port, phy); 66156051948SVladimir Oltean 66256051948SVladimir Oltean return 0; 66356051948SVladimir Oltean } 66456051948SVladimir Oltean 66556051948SVladimir Oltean static void felix_port_disable(struct dsa_switch *ds, int port) 66656051948SVladimir Oltean { 66756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 66856051948SVladimir Oltean 66956051948SVladimir Oltean return ocelot_port_disable(ocelot, port); 67056051948SVladimir Oltean } 67156051948SVladimir Oltean 672bdeced75SVladimir Oltean static void felix_phylink_validate(struct dsa_switch *ds, int port, 673bdeced75SVladimir Oltean unsigned long *supported, 674bdeced75SVladimir Oltean struct phylink_link_state *state) 675bdeced75SVladimir Oltean { 676bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 677375e1314SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 678bdeced75SVladimir Oltean 679375e1314SVladimir Oltean if (felix->info->phylink_validate) 680375e1314SVladimir Oltean felix->info->phylink_validate(ocelot, port, supported, state); 681bdeced75SVladimir Oltean } 682bdeced75SVladimir Oltean 683bdeced75SVladimir Oltean static void felix_phylink_mac_config(struct dsa_switch *ds, int port, 684bdeced75SVladimir Oltean unsigned int link_an_mode, 685bdeced75SVladimir Oltean const struct phylink_link_state *state) 686bdeced75SVladimir Oltean { 687bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 688bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 689588d0550SIoana Ciornei struct dsa_port *dp = dsa_to_port(ds, port); 690bdeced75SVladimir Oltean 691588d0550SIoana Ciornei if (felix->pcs[port]) 692588d0550SIoana Ciornei phylink_set_pcs(dp->pl, &felix->pcs[port]->pcs); 693bdeced75SVladimir Oltean } 694bdeced75SVladimir Oltean 695bdeced75SVladimir Oltean static void felix_phylink_mac_link_down(struct dsa_switch *ds, int port, 696bdeced75SVladimir Oltean unsigned int link_an_mode, 697bdeced75SVladimir Oltean phy_interface_t interface) 698bdeced75SVladimir Oltean { 699bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 700bdeced75SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 701eb4733d7SVladimir Oltean int err; 702bdeced75SVladimir Oltean 703eb4733d7SVladimir Oltean ocelot_port_rmwl(ocelot_port, 0, DEV_MAC_ENA_CFG_RX_ENA, 704eb4733d7SVladimir Oltean DEV_MAC_ENA_CFG); 705eb4733d7SVladimir Oltean 706886e1387SVladimir Oltean ocelot_fields_write(ocelot, port, QSYS_SWITCH_PORT_MODE_PORT_ENA, 0); 707eb4733d7SVladimir Oltean 708eb4733d7SVladimir Oltean err = ocelot_port_flush(ocelot, port); 709eb4733d7SVladimir Oltean if (err) 710eb4733d7SVladimir Oltean dev_err(ocelot->dev, "failed to flush port %d: %d\n", 711eb4733d7SVladimir Oltean port, err); 712eb4733d7SVladimir Oltean 713eb4733d7SVladimir Oltean /* Put the port in reset. */ 714eb4733d7SVladimir Oltean ocelot_port_writel(ocelot_port, 715eb4733d7SVladimir Oltean DEV_CLOCK_CFG_MAC_TX_RST | 716eb4733d7SVladimir Oltean DEV_CLOCK_CFG_MAC_RX_RST | 717eb4733d7SVladimir Oltean DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000), 718eb4733d7SVladimir Oltean DEV_CLOCK_CFG); 719bdeced75SVladimir Oltean } 720bdeced75SVladimir Oltean 721bdeced75SVladimir Oltean static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, 722bdeced75SVladimir Oltean unsigned int link_an_mode, 723bdeced75SVladimir Oltean phy_interface_t interface, 7245b502a7bSRussell King struct phy_device *phydev, 7255b502a7bSRussell King int speed, int duplex, 7265b502a7bSRussell King bool tx_pause, bool rx_pause) 727bdeced75SVladimir Oltean { 728bdeced75SVladimir Oltean struct ocelot *ocelot = ds->priv; 729bdeced75SVladimir Oltean struct ocelot_port *ocelot_port = ocelot->ports[port]; 7307e14a2dcSVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 7317e14a2dcSVladimir Oltean u32 mac_fc_cfg; 732bdeced75SVladimir Oltean 7337e14a2dcSVladimir Oltean /* Take port out of reset by clearing the MAC_TX_RST, MAC_RX_RST and 7347e14a2dcSVladimir Oltean * PORT_RST bits in DEV_CLOCK_CFG. Note that the way this system is 7357e14a2dcSVladimir Oltean * integrated is that the MAC speed is fixed and it's the PCS who is 7367e14a2dcSVladimir Oltean * performing the rate adaptation, so we have to write "1000Mbps" into 7377e14a2dcSVladimir Oltean * the LINK_SPEED field of DEV_CLOCK_CFG (which is also its default 7387e14a2dcSVladimir Oltean * value). 7397e14a2dcSVladimir Oltean */ 7407e14a2dcSVladimir Oltean ocelot_port_writel(ocelot_port, 7417e14a2dcSVladimir Oltean DEV_CLOCK_CFG_LINK_SPEED(OCELOT_SPEED_1000), 7427e14a2dcSVladimir Oltean DEV_CLOCK_CFG); 7437e14a2dcSVladimir Oltean 7447e14a2dcSVladimir Oltean switch (speed) { 7457e14a2dcSVladimir Oltean case SPEED_10: 7467e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(3); 7477e14a2dcSVladimir Oltean break; 7487e14a2dcSVladimir Oltean case SPEED_100: 7497e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(2); 7507e14a2dcSVladimir Oltean break; 7517e14a2dcSVladimir Oltean case SPEED_1000: 7527e14a2dcSVladimir Oltean case SPEED_2500: 7537e14a2dcSVladimir Oltean mac_fc_cfg = SYS_MAC_FC_CFG_FC_LINK_SPEED(1); 7547e14a2dcSVladimir Oltean break; 7557e14a2dcSVladimir Oltean default: 7567e14a2dcSVladimir Oltean dev_err(ocelot->dev, "Unsupported speed on port %d: %d\n", 7577e14a2dcSVladimir Oltean port, speed); 7587e14a2dcSVladimir Oltean return; 7597e14a2dcSVladimir Oltean } 7607e14a2dcSVladimir Oltean 7617e14a2dcSVladimir Oltean /* handle Rx pause in all cases, with 2500base-X this is used for rate 7627e14a2dcSVladimir Oltean * adaptation. 7637e14a2dcSVladimir Oltean */ 7647e14a2dcSVladimir Oltean mac_fc_cfg |= SYS_MAC_FC_CFG_RX_FC_ENA; 7657e14a2dcSVladimir Oltean 7667e14a2dcSVladimir Oltean if (tx_pause) 7677e14a2dcSVladimir Oltean mac_fc_cfg |= SYS_MAC_FC_CFG_TX_FC_ENA | 7687e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_PAUSE_VAL_CFG(0xffff) | 7697e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_FC_LATENCY_CFG(0x7) | 7707e14a2dcSVladimir Oltean SYS_MAC_FC_CFG_ZERO_PAUSE_ENA; 7717e14a2dcSVladimir Oltean 7727e14a2dcSVladimir Oltean /* Flow control. Link speed is only used here to evaluate the time 7737e14a2dcSVladimir Oltean * specification in incoming pause frames. 7747e14a2dcSVladimir Oltean */ 7757e14a2dcSVladimir Oltean ocelot_write_rix(ocelot, mac_fc_cfg, SYS_MAC_FC_CFG, port); 7767e14a2dcSVladimir Oltean 7777e14a2dcSVladimir Oltean ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port); 7787e14a2dcSVladimir Oltean 7797e14a2dcSVladimir Oltean /* Undo the effects of felix_phylink_mac_link_down: 7807e14a2dcSVladimir Oltean * enable MAC module 7817e14a2dcSVladimir Oltean */ 782bdeced75SVladimir Oltean ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA | 783bdeced75SVladimir Oltean DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG); 784bdeced75SVladimir Oltean 785bdeced75SVladimir Oltean /* Enable receiving frames on the port, and activate auto-learning of 786bdeced75SVladimir Oltean * MAC addresses. 787bdeced75SVladimir Oltean */ 788bdeced75SVladimir Oltean ocelot_write_gix(ocelot, ANA_PORT_PORT_CFG_LEARNAUTO | 789bdeced75SVladimir Oltean ANA_PORT_PORT_CFG_RECV_ENA | 790bdeced75SVladimir Oltean ANA_PORT_PORT_CFG_PORTID_VAL(port), 791bdeced75SVladimir Oltean ANA_PORT_PORT_CFG, port); 792bdeced75SVladimir Oltean 793bdeced75SVladimir Oltean /* Core: Enable port for frame transfer */ 794886e1387SVladimir Oltean ocelot_fields_write(ocelot, port, 795886e1387SVladimir Oltean QSYS_SWITCH_PORT_MODE_PORT_ENA, 1); 7967e14a2dcSVladimir Oltean 7977e14a2dcSVladimir Oltean if (felix->info->port_sched_speed_set) 7987e14a2dcSVladimir Oltean felix->info->port_sched_speed_set(ocelot, port, speed); 799bdeced75SVladimir Oltean } 800bdeced75SVladimir Oltean 801bd2b3161SXiaoliang Yang static void felix_port_qos_map_init(struct ocelot *ocelot, int port) 802bd2b3161SXiaoliang Yang { 803bd2b3161SXiaoliang Yang int i; 804bd2b3161SXiaoliang Yang 805bd2b3161SXiaoliang Yang ocelot_rmw_gix(ocelot, 806bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 807bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG_QOS_PCP_ENA, 808bd2b3161SXiaoliang Yang ANA_PORT_QOS_CFG, 809bd2b3161SXiaoliang Yang port); 810bd2b3161SXiaoliang Yang 81170d39a6eSVladimir Oltean for (i = 0; i < OCELOT_NUM_TC * 2; i++) { 812bd2b3161SXiaoliang Yang ocelot_rmw_ix(ocelot, 813bd2b3161SXiaoliang Yang (ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL & i) | 814bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL(i), 815bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_DP_PCP_DEI_VAL | 816bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP_QOS_PCP_DEI_VAL_M, 817bd2b3161SXiaoliang Yang ANA_PORT_PCP_DEI_MAP, 818bd2b3161SXiaoliang Yang port, i); 819bd2b3161SXiaoliang Yang } 820bd2b3161SXiaoliang Yang } 821bd2b3161SXiaoliang Yang 82256051948SVladimir Oltean static void felix_get_strings(struct dsa_switch *ds, int port, 82356051948SVladimir Oltean u32 stringset, u8 *data) 82456051948SVladimir Oltean { 82556051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 82656051948SVladimir Oltean 82756051948SVladimir Oltean return ocelot_get_strings(ocelot, port, stringset, data); 82856051948SVladimir Oltean } 82956051948SVladimir Oltean 83056051948SVladimir Oltean static void felix_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data) 83156051948SVladimir Oltean { 83256051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 83356051948SVladimir Oltean 83456051948SVladimir Oltean ocelot_get_ethtool_stats(ocelot, port, data); 83556051948SVladimir Oltean } 83656051948SVladimir Oltean 83756051948SVladimir Oltean static int felix_get_sset_count(struct dsa_switch *ds, int port, int sset) 83856051948SVladimir Oltean { 83956051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 84056051948SVladimir Oltean 84156051948SVladimir Oltean return ocelot_get_sset_count(ocelot, port, sset); 84256051948SVladimir Oltean } 84356051948SVladimir Oltean 84456051948SVladimir Oltean static int felix_get_ts_info(struct dsa_switch *ds, int port, 84556051948SVladimir Oltean struct ethtool_ts_info *info) 84656051948SVladimir Oltean { 84756051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 84856051948SVladimir Oltean 84956051948SVladimir Oltean return ocelot_get_ts_info(ocelot, port, info); 85056051948SVladimir Oltean } 85156051948SVladimir Oltean 852bdeced75SVladimir Oltean static int felix_parse_ports_node(struct felix *felix, 853bdeced75SVladimir Oltean struct device_node *ports_node, 854bdeced75SVladimir Oltean phy_interface_t *port_phy_modes) 855bdeced75SVladimir Oltean { 856bdeced75SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 857bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 858bdeced75SVladimir Oltean struct device_node *child; 859bdeced75SVladimir Oltean 86037fe45adSVladimir Oltean for_each_available_child_of_node(ports_node, child) { 861bdeced75SVladimir Oltean phy_interface_t phy_mode; 862bdeced75SVladimir Oltean u32 port; 863bdeced75SVladimir Oltean int err; 864bdeced75SVladimir Oltean 865bdeced75SVladimir Oltean /* Get switch port number from DT */ 866bdeced75SVladimir Oltean if (of_property_read_u32(child, "reg", &port) < 0) { 867bdeced75SVladimir Oltean dev_err(dev, "Port number not defined in device tree " 868bdeced75SVladimir Oltean "(property \"reg\")\n"); 869bdeced75SVladimir Oltean of_node_put(child); 870bdeced75SVladimir Oltean return -ENODEV; 871bdeced75SVladimir Oltean } 872bdeced75SVladimir Oltean 873bdeced75SVladimir Oltean /* Get PHY mode from DT */ 874bdeced75SVladimir Oltean err = of_get_phy_mode(child, &phy_mode); 875bdeced75SVladimir Oltean if (err) { 876bdeced75SVladimir Oltean dev_err(dev, "Failed to read phy-mode or " 877bdeced75SVladimir Oltean "phy-interface-type property for port %d\n", 878bdeced75SVladimir Oltean port); 879bdeced75SVladimir Oltean of_node_put(child); 880bdeced75SVladimir Oltean return -ENODEV; 881bdeced75SVladimir Oltean } 882bdeced75SVladimir Oltean 883bdeced75SVladimir Oltean err = felix->info->prevalidate_phy_mode(ocelot, port, phy_mode); 884bdeced75SVladimir Oltean if (err < 0) { 885bdeced75SVladimir Oltean dev_err(dev, "Unsupported PHY mode %s on port %d\n", 886bdeced75SVladimir Oltean phy_modes(phy_mode), port); 88759ebb430SSumera Priyadarsini of_node_put(child); 888bdeced75SVladimir Oltean return err; 889bdeced75SVladimir Oltean } 890bdeced75SVladimir Oltean 891bdeced75SVladimir Oltean port_phy_modes[port] = phy_mode; 892bdeced75SVladimir Oltean } 893bdeced75SVladimir Oltean 894bdeced75SVladimir Oltean return 0; 895bdeced75SVladimir Oltean } 896bdeced75SVladimir Oltean 897bdeced75SVladimir Oltean static int felix_parse_dt(struct felix *felix, phy_interface_t *port_phy_modes) 898bdeced75SVladimir Oltean { 899bdeced75SVladimir Oltean struct device *dev = felix->ocelot.dev; 900bdeced75SVladimir Oltean struct device_node *switch_node; 901bdeced75SVladimir Oltean struct device_node *ports_node; 902bdeced75SVladimir Oltean int err; 903bdeced75SVladimir Oltean 904bdeced75SVladimir Oltean switch_node = dev->of_node; 905bdeced75SVladimir Oltean 906bdeced75SVladimir Oltean ports_node = of_get_child_by_name(switch_node, "ports"); 907bdeced75SVladimir Oltean if (!ports_node) { 908bdeced75SVladimir Oltean dev_err(dev, "Incorrect bindings: absent \"ports\" node\n"); 909bdeced75SVladimir Oltean return -ENODEV; 910bdeced75SVladimir Oltean } 911bdeced75SVladimir Oltean 912bdeced75SVladimir Oltean err = felix_parse_ports_node(felix, ports_node, port_phy_modes); 913bdeced75SVladimir Oltean of_node_put(ports_node); 914bdeced75SVladimir Oltean 915bdeced75SVladimir Oltean return err; 916bdeced75SVladimir Oltean } 917bdeced75SVladimir Oltean 91856051948SVladimir Oltean static int felix_init_structs(struct felix *felix, int num_phys_ports) 91956051948SVladimir Oltean { 92056051948SVladimir Oltean struct ocelot *ocelot = &felix->ocelot; 921bdeced75SVladimir Oltean phy_interface_t *port_phy_modes; 922b4024c9eSClaudiu Manoil struct resource res; 92356051948SVladimir Oltean int port, i, err; 92456051948SVladimir Oltean 92556051948SVladimir Oltean ocelot->num_phys_ports = num_phys_ports; 92656051948SVladimir Oltean ocelot->ports = devm_kcalloc(ocelot->dev, num_phys_ports, 92756051948SVladimir Oltean sizeof(struct ocelot_port *), GFP_KERNEL); 92856051948SVladimir Oltean if (!ocelot->ports) 92956051948SVladimir Oltean return -ENOMEM; 93056051948SVladimir Oltean 93156051948SVladimir Oltean ocelot->map = felix->info->map; 93256051948SVladimir Oltean ocelot->stats_layout = felix->info->stats_layout; 93356051948SVladimir Oltean ocelot->num_stats = felix->info->num_stats; 93421ce7f3eSVladimir Oltean ocelot->num_mact_rows = felix->info->num_mact_rows; 93507d985eeSVladimir Oltean ocelot->vcap = felix->info->vcap; 93656051948SVladimir Oltean ocelot->ops = felix->info->ops; 937cacea62fSVladimir Oltean ocelot->npi_inj_prefix = OCELOT_TAG_PREFIX_SHORT; 938cacea62fSVladimir Oltean ocelot->npi_xtr_prefix = OCELOT_TAG_PREFIX_SHORT; 939f59fd9caSVladimir Oltean ocelot->devlink = felix->ds->devlink; 94056051948SVladimir Oltean 941bdeced75SVladimir Oltean port_phy_modes = kcalloc(num_phys_ports, sizeof(phy_interface_t), 942bdeced75SVladimir Oltean GFP_KERNEL); 943bdeced75SVladimir Oltean if (!port_phy_modes) 944bdeced75SVladimir Oltean return -ENOMEM; 945bdeced75SVladimir Oltean 946bdeced75SVladimir Oltean err = felix_parse_dt(felix, port_phy_modes); 947bdeced75SVladimir Oltean if (err) { 948bdeced75SVladimir Oltean kfree(port_phy_modes); 949bdeced75SVladimir Oltean return err; 950bdeced75SVladimir Oltean } 951bdeced75SVladimir Oltean 95256051948SVladimir Oltean for (i = 0; i < TARGET_MAX; i++) { 95356051948SVladimir Oltean struct regmap *target; 95456051948SVladimir Oltean 95556051948SVladimir Oltean if (!felix->info->target_io_res[i].name) 95656051948SVladimir Oltean continue; 95756051948SVladimir Oltean 958b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->target_io_res[i], sizeof(res)); 959b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 960375e1314SVladimir Oltean res.start += felix->switch_base; 961375e1314SVladimir Oltean res.end += felix->switch_base; 96256051948SVladimir Oltean 963b4024c9eSClaudiu Manoil target = ocelot_regmap_init(ocelot, &res); 96456051948SVladimir Oltean if (IS_ERR(target)) { 96556051948SVladimir Oltean dev_err(ocelot->dev, 96656051948SVladimir Oltean "Failed to map device memory space\n"); 967bdeced75SVladimir Oltean kfree(port_phy_modes); 96856051948SVladimir Oltean return PTR_ERR(target); 96956051948SVladimir Oltean } 97056051948SVladimir Oltean 97156051948SVladimir Oltean ocelot->targets[i] = target; 97256051948SVladimir Oltean } 97356051948SVladimir Oltean 97456051948SVladimir Oltean err = ocelot_regfields_init(ocelot, felix->info->regfields); 97556051948SVladimir Oltean if (err) { 97656051948SVladimir Oltean dev_err(ocelot->dev, "failed to init reg fields map\n"); 977bdeced75SVladimir Oltean kfree(port_phy_modes); 97856051948SVladimir Oltean return err; 97956051948SVladimir Oltean } 98056051948SVladimir Oltean 98156051948SVladimir Oltean for (port = 0; port < num_phys_ports; port++) { 98256051948SVladimir Oltean struct ocelot_port *ocelot_port; 98391c724cfSVladimir Oltean struct regmap *target; 98467c24049SVladimir Oltean u8 *template; 98556051948SVladimir Oltean 98656051948SVladimir Oltean ocelot_port = devm_kzalloc(ocelot->dev, 98756051948SVladimir Oltean sizeof(struct ocelot_port), 98856051948SVladimir Oltean GFP_KERNEL); 98956051948SVladimir Oltean if (!ocelot_port) { 99056051948SVladimir Oltean dev_err(ocelot->dev, 99156051948SVladimir Oltean "failed to allocate port memory\n"); 992bdeced75SVladimir Oltean kfree(port_phy_modes); 99356051948SVladimir Oltean return -ENOMEM; 99456051948SVladimir Oltean } 99556051948SVladimir Oltean 996b4024c9eSClaudiu Manoil memcpy(&res, &felix->info->port_io_res[port], sizeof(res)); 997b4024c9eSClaudiu Manoil res.flags = IORESOURCE_MEM; 998375e1314SVladimir Oltean res.start += felix->switch_base; 999375e1314SVladimir Oltean res.end += felix->switch_base; 100056051948SVladimir Oltean 100191c724cfSVladimir Oltean target = ocelot_regmap_init(ocelot, &res); 100291c724cfSVladimir Oltean if (IS_ERR(target)) { 100356051948SVladimir Oltean dev_err(ocelot->dev, 100491c724cfSVladimir Oltean "Failed to map memory space for port %d\n", 100591c724cfSVladimir Oltean port); 1006bdeced75SVladimir Oltean kfree(port_phy_modes); 100791c724cfSVladimir Oltean return PTR_ERR(target); 100856051948SVladimir Oltean } 100956051948SVladimir Oltean 10105124197cSVladimir Oltean template = devm_kzalloc(ocelot->dev, OCELOT_TOTAL_TAG_LEN, 101167c24049SVladimir Oltean GFP_KERNEL); 101267c24049SVladimir Oltean if (!template) { 101367c24049SVladimir Oltean dev_err(ocelot->dev, 101467c24049SVladimir Oltean "Failed to allocate memory for DSA tag\n"); 101567c24049SVladimir Oltean kfree(port_phy_modes); 101667c24049SVladimir Oltean return -ENOMEM; 101767c24049SVladimir Oltean } 101867c24049SVladimir Oltean 1019bdeced75SVladimir Oltean ocelot_port->phy_mode = port_phy_modes[port]; 102056051948SVladimir Oltean ocelot_port->ocelot = ocelot; 102191c724cfSVladimir Oltean ocelot_port->target = target; 102267c24049SVladimir Oltean ocelot_port->xmit_template = template; 102356051948SVladimir Oltean ocelot->ports[port] = ocelot_port; 102467c24049SVladimir Oltean 102567c24049SVladimir Oltean felix->info->xmit_template_populate(ocelot, port); 102656051948SVladimir Oltean } 102756051948SVladimir Oltean 1028bdeced75SVladimir Oltean kfree(port_phy_modes); 1029bdeced75SVladimir Oltean 1030bdeced75SVladimir Oltean if (felix->info->mdio_bus_alloc) { 1031bdeced75SVladimir Oltean err = felix->info->mdio_bus_alloc(ocelot); 1032bdeced75SVladimir Oltean if (err < 0) 1033bdeced75SVladimir Oltean return err; 1034bdeced75SVladimir Oltean } 1035bdeced75SVladimir Oltean 103656051948SVladimir Oltean return 0; 103756051948SVladimir Oltean } 103856051948SVladimir Oltean 103956051948SVladimir Oltean /* Hardware initialization done here so that we can allocate structures with 104056051948SVladimir Oltean * devm without fear of dsa_register_switch returning -EPROBE_DEFER and causing 104156051948SVladimir Oltean * us to allocate structures twice (leak memory) and map PCI memory twice 104256051948SVladimir Oltean * (which will not work). 104356051948SVladimir Oltean */ 104456051948SVladimir Oltean static int felix_setup(struct dsa_switch *ds) 104556051948SVladimir Oltean { 104656051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 104756051948SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 104856051948SVladimir Oltean int port, err; 104956051948SVladimir Oltean 105056051948SVladimir Oltean err = felix_init_structs(felix, ds->num_ports); 105156051948SVladimir Oltean if (err) 105256051948SVladimir Oltean return err; 105356051948SVladimir Oltean 1054d1cc0e93SVladimir Oltean err = ocelot_init(ocelot); 1055d1cc0e93SVladimir Oltean if (err) 1056d1cc0e93SVladimir Oltean return err; 1057d1cc0e93SVladimir Oltean 10582b49d128SYangbo Lu if (ocelot->ptp) { 10592ac7c6c5SVladimir Oltean err = ocelot_init_timestamp(ocelot, felix->info->ptp_caps); 10602b49d128SYangbo Lu if (err) { 10612b49d128SYangbo Lu dev_err(ocelot->dev, 10622b49d128SYangbo Lu "Timestamp initialization failed\n"); 10632b49d128SYangbo Lu ocelot->ptp = 0; 10642b49d128SYangbo Lu } 10652b49d128SYangbo Lu } 106656051948SVladimir Oltean 106756051948SVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1068adb3dccfSVladimir Oltean if (dsa_is_unused_port(ds, port)) 1069adb3dccfSVladimir Oltean continue; 107056051948SVladimir Oltean 1071adb3dccfSVladimir Oltean ocelot_init_port(ocelot, port); 1072bd2b3161SXiaoliang Yang 1073bd2b3161SXiaoliang Yang /* Set the default QoS Classification based on PCP and DEI 1074bd2b3161SXiaoliang Yang * bits of vlan tag. 1075bd2b3161SXiaoliang Yang */ 1076bd2b3161SXiaoliang Yang felix_port_qos_map_init(ocelot, port); 107756051948SVladimir Oltean } 107856051948SVladimir Oltean 1079f59fd9caSVladimir Oltean err = ocelot_devlink_sb_register(ocelot); 1080f59fd9caSVladimir Oltean if (err) 1081f59fd9caSVladimir Oltean return err; 1082f59fd9caSVladimir Oltean 1083adb3dccfSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1084adb3dccfSVladimir Oltean if (!dsa_is_cpu_port(ds, port)) 1085adb3dccfSVladimir Oltean continue; 1086adb3dccfSVladimir Oltean 1087adb3dccfSVladimir Oltean /* The initial tag protocol is NPI which always returns 0, so 1088adb3dccfSVladimir Oltean * there's no real point in checking for errors. 10891cf3299bSVladimir Oltean */ 1090adb3dccfSVladimir Oltean felix_set_tag_protocol(ds, port, felix->tag_proto); 1091adb3dccfSVladimir Oltean } 10921cf3299bSVladimir Oltean 10930b912fc9SVladimir Oltean ds->mtu_enforcement_ingress = true; 1094c54913c1SVladimir Oltean ds->assisted_learning_on_cpu_port = true; 1095bdeced75SVladimir Oltean 109656051948SVladimir Oltean return 0; 109756051948SVladimir Oltean } 109856051948SVladimir Oltean 109956051948SVladimir Oltean static void felix_teardown(struct dsa_switch *ds) 110056051948SVladimir Oltean { 110156051948SVladimir Oltean struct ocelot *ocelot = ds->priv; 1102bdeced75SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1103e5fb512dSVladimir Oltean int port; 1104bdeced75SVladimir Oltean 1105adb3dccfSVladimir Oltean for (port = 0; port < ds->num_ports; port++) { 1106adb3dccfSVladimir Oltean if (!dsa_is_cpu_port(ds, port)) 1107adb3dccfSVladimir Oltean continue; 1108adb3dccfSVladimir Oltean 1109adb3dccfSVladimir Oltean felix_del_tag_protocol(ds, port, felix->tag_proto); 1110adb3dccfSVladimir Oltean } 1111adb3dccfSVladimir Oltean 1112f59fd9caSVladimir Oltean ocelot_devlink_sb_unregister(ocelot); 1113d19741b0SVladimir Oltean ocelot_deinit_timestamp(ocelot); 1114d19741b0SVladimir Oltean ocelot_deinit(ocelot); 111556051948SVladimir Oltean 1116e5fb512dSVladimir Oltean for (port = 0; port < ocelot->num_phys_ports; port++) 1117e5fb512dSVladimir Oltean ocelot_deinit_port(ocelot, port); 1118d19741b0SVladimir Oltean 1119d19741b0SVladimir Oltean if (felix->info->mdio_bus_free) 1120d19741b0SVladimir Oltean felix->info->mdio_bus_free(ocelot); 112156051948SVladimir Oltean } 112256051948SVladimir Oltean 1123c0bcf537SYangbo Lu static int felix_hwtstamp_get(struct dsa_switch *ds, int port, 1124c0bcf537SYangbo Lu struct ifreq *ifr) 1125c0bcf537SYangbo Lu { 1126c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1127c0bcf537SYangbo Lu 1128c0bcf537SYangbo Lu return ocelot_hwstamp_get(ocelot, port, ifr); 1129c0bcf537SYangbo Lu } 1130c0bcf537SYangbo Lu 1131c0bcf537SYangbo Lu static int felix_hwtstamp_set(struct dsa_switch *ds, int port, 1132c0bcf537SYangbo Lu struct ifreq *ifr) 1133c0bcf537SYangbo Lu { 1134c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1135c0bcf537SYangbo Lu 1136c0bcf537SYangbo Lu return ocelot_hwstamp_set(ocelot, port, ifr); 1137c0bcf537SYangbo Lu } 1138c0bcf537SYangbo Lu 1139c0bcf537SYangbo Lu static bool felix_rxtstamp(struct dsa_switch *ds, int port, 1140c0bcf537SYangbo Lu struct sk_buff *skb, unsigned int type) 1141c0bcf537SYangbo Lu { 1142c0bcf537SYangbo Lu struct skb_shared_hwtstamps *shhwtstamps; 1143c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1144c0bcf537SYangbo Lu u8 *extraction = skb->data - ETH_HLEN - OCELOT_TAG_LEN; 1145c0bcf537SYangbo Lu u32 tstamp_lo, tstamp_hi; 1146c0bcf537SYangbo Lu struct timespec64 ts; 1147c0bcf537SYangbo Lu u64 tstamp, val; 1148c0bcf537SYangbo Lu 1149c0bcf537SYangbo Lu ocelot_ptp_gettime64(&ocelot->ptp_info, &ts); 1150c0bcf537SYangbo Lu tstamp = ktime_set(ts.tv_sec, ts.tv_nsec); 1151c0bcf537SYangbo Lu 1152c0bcf537SYangbo Lu packing(extraction, &val, 116, 85, OCELOT_TAG_LEN, UNPACK, 0); 1153c0bcf537SYangbo Lu tstamp_lo = (u32)val; 1154c0bcf537SYangbo Lu 1155c0bcf537SYangbo Lu tstamp_hi = tstamp >> 32; 1156c0bcf537SYangbo Lu if ((tstamp & 0xffffffff) < tstamp_lo) 1157c0bcf537SYangbo Lu tstamp_hi--; 1158c0bcf537SYangbo Lu 1159c0bcf537SYangbo Lu tstamp = ((u64)tstamp_hi << 32) | tstamp_lo; 1160c0bcf537SYangbo Lu 1161c0bcf537SYangbo Lu shhwtstamps = skb_hwtstamps(skb); 1162c0bcf537SYangbo Lu memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); 1163c0bcf537SYangbo Lu shhwtstamps->hwtstamp = tstamp; 1164c0bcf537SYangbo Lu return false; 1165c0bcf537SYangbo Lu } 1166c0bcf537SYangbo Lu 11673243e04aSChen Wandun static bool felix_txtstamp(struct dsa_switch *ds, int port, 1168c0bcf537SYangbo Lu struct sk_buff *clone, unsigned int type) 1169c0bcf537SYangbo Lu { 1170c0bcf537SYangbo Lu struct ocelot *ocelot = ds->priv; 1171c0bcf537SYangbo Lu struct ocelot_port *ocelot_port = ocelot->ports[port]; 1172c0bcf537SYangbo Lu 1173e2f9a8feSVladimir Oltean if (ocelot->ptp && (skb_shinfo(clone)->tx_flags & SKBTX_HW_TSTAMP) && 1174e2f9a8feSVladimir Oltean ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) { 1175e2f9a8feSVladimir Oltean ocelot_port_add_txtstamp_skb(ocelot, port, clone); 1176c0bcf537SYangbo Lu return true; 1177e2f9a8feSVladimir Oltean } 1178c0bcf537SYangbo Lu 1179c0bcf537SYangbo Lu return false; 1180c0bcf537SYangbo Lu } 1181c0bcf537SYangbo Lu 11820b912fc9SVladimir Oltean static int felix_change_mtu(struct dsa_switch *ds, int port, int new_mtu) 11830b912fc9SVladimir Oltean { 11840b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 11850b912fc9SVladimir Oltean 11860b912fc9SVladimir Oltean ocelot_port_set_maxlen(ocelot, port, new_mtu); 11870b912fc9SVladimir Oltean 11880b912fc9SVladimir Oltean return 0; 11890b912fc9SVladimir Oltean } 11900b912fc9SVladimir Oltean 11910b912fc9SVladimir Oltean static int felix_get_max_mtu(struct dsa_switch *ds, int port) 11920b912fc9SVladimir Oltean { 11930b912fc9SVladimir Oltean struct ocelot *ocelot = ds->priv; 11940b912fc9SVladimir Oltean 11950b912fc9SVladimir Oltean return ocelot_get_max_mtu(ocelot, port); 11960b912fc9SVladimir Oltean } 11970b912fc9SVladimir Oltean 119807d985eeSVladimir Oltean static int felix_cls_flower_add(struct dsa_switch *ds, int port, 119907d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 120007d985eeSVladimir Oltean { 120107d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 120207d985eeSVladimir Oltean 120307d985eeSVladimir Oltean return ocelot_cls_flower_replace(ocelot, port, cls, ingress); 120407d985eeSVladimir Oltean } 120507d985eeSVladimir Oltean 120607d985eeSVladimir Oltean static int felix_cls_flower_del(struct dsa_switch *ds, int port, 120707d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 120807d985eeSVladimir Oltean { 120907d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 121007d985eeSVladimir Oltean 121107d985eeSVladimir Oltean return ocelot_cls_flower_destroy(ocelot, port, cls, ingress); 121207d985eeSVladimir Oltean } 121307d985eeSVladimir Oltean 121407d985eeSVladimir Oltean static int felix_cls_flower_stats(struct dsa_switch *ds, int port, 121507d985eeSVladimir Oltean struct flow_cls_offload *cls, bool ingress) 121607d985eeSVladimir Oltean { 121707d985eeSVladimir Oltean struct ocelot *ocelot = ds->priv; 121807d985eeSVladimir Oltean 121907d985eeSVladimir Oltean return ocelot_cls_flower_stats(ocelot, port, cls, ingress); 122007d985eeSVladimir Oltean } 122107d985eeSVladimir Oltean 1222fc411eaaSVladimir Oltean static int felix_port_policer_add(struct dsa_switch *ds, int port, 1223fc411eaaSVladimir Oltean struct dsa_mall_policer_tc_entry *policer) 1224fc411eaaSVladimir Oltean { 1225fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1226fc411eaaSVladimir Oltean struct ocelot_policer pol = { 1227fc411eaaSVladimir Oltean .rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8, 12285f035af7SPo Liu .burst = policer->burst, 1229fc411eaaSVladimir Oltean }; 1230fc411eaaSVladimir Oltean 1231fc411eaaSVladimir Oltean return ocelot_port_policer_add(ocelot, port, &pol); 1232fc411eaaSVladimir Oltean } 1233fc411eaaSVladimir Oltean 1234fc411eaaSVladimir Oltean static void felix_port_policer_del(struct dsa_switch *ds, int port) 1235fc411eaaSVladimir Oltean { 1236fc411eaaSVladimir Oltean struct ocelot *ocelot = ds->priv; 1237fc411eaaSVladimir Oltean 1238fc411eaaSVladimir Oltean ocelot_port_policer_del(ocelot, port); 1239fc411eaaSVladimir Oltean } 1240fc411eaaSVladimir Oltean 1241de143c0eSXiaoliang Yang static int felix_port_setup_tc(struct dsa_switch *ds, int port, 1242de143c0eSXiaoliang Yang enum tc_setup_type type, 1243de143c0eSXiaoliang Yang void *type_data) 1244de143c0eSXiaoliang Yang { 1245de143c0eSXiaoliang Yang struct ocelot *ocelot = ds->priv; 1246de143c0eSXiaoliang Yang struct felix *felix = ocelot_to_felix(ocelot); 1247de143c0eSXiaoliang Yang 1248de143c0eSXiaoliang Yang if (felix->info->port_setup_tc) 1249de143c0eSXiaoliang Yang return felix->info->port_setup_tc(ds, port, type, type_data); 1250de143c0eSXiaoliang Yang else 1251de143c0eSXiaoliang Yang return -EOPNOTSUPP; 1252de143c0eSXiaoliang Yang } 1253de143c0eSXiaoliang Yang 1254f59fd9caSVladimir Oltean static int felix_sb_pool_get(struct dsa_switch *ds, unsigned int sb_index, 1255f59fd9caSVladimir Oltean u16 pool_index, 1256f59fd9caSVladimir Oltean struct devlink_sb_pool_info *pool_info) 1257f59fd9caSVladimir Oltean { 1258f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1259f59fd9caSVladimir Oltean 1260f59fd9caSVladimir Oltean return ocelot_sb_pool_get(ocelot, sb_index, pool_index, pool_info); 1261f59fd9caSVladimir Oltean } 1262f59fd9caSVladimir Oltean 1263f59fd9caSVladimir Oltean static int felix_sb_pool_set(struct dsa_switch *ds, unsigned int sb_index, 1264f59fd9caSVladimir Oltean u16 pool_index, u32 size, 1265f59fd9caSVladimir Oltean enum devlink_sb_threshold_type threshold_type, 1266f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1267f59fd9caSVladimir Oltean { 1268f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1269f59fd9caSVladimir Oltean 1270f59fd9caSVladimir Oltean return ocelot_sb_pool_set(ocelot, sb_index, pool_index, size, 1271f59fd9caSVladimir Oltean threshold_type, extack); 1272f59fd9caSVladimir Oltean } 1273f59fd9caSVladimir Oltean 1274f59fd9caSVladimir Oltean static int felix_sb_port_pool_get(struct dsa_switch *ds, int port, 1275f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1276f59fd9caSVladimir Oltean u32 *p_threshold) 1277f59fd9caSVladimir Oltean { 1278f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1279f59fd9caSVladimir Oltean 1280f59fd9caSVladimir Oltean return ocelot_sb_port_pool_get(ocelot, port, sb_index, pool_index, 1281f59fd9caSVladimir Oltean p_threshold); 1282f59fd9caSVladimir Oltean } 1283f59fd9caSVladimir Oltean 1284f59fd9caSVladimir Oltean static int felix_sb_port_pool_set(struct dsa_switch *ds, int port, 1285f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1286f59fd9caSVladimir Oltean u32 threshold, struct netlink_ext_ack *extack) 1287f59fd9caSVladimir Oltean { 1288f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1289f59fd9caSVladimir Oltean 1290f59fd9caSVladimir Oltean return ocelot_sb_port_pool_set(ocelot, port, sb_index, pool_index, 1291f59fd9caSVladimir Oltean threshold, extack); 1292f59fd9caSVladimir Oltean } 1293f59fd9caSVladimir Oltean 1294f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_get(struct dsa_switch *ds, int port, 1295f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1296f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1297f59fd9caSVladimir Oltean u16 *p_pool_index, u32 *p_threshold) 1298f59fd9caSVladimir Oltean { 1299f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1300f59fd9caSVladimir Oltean 1301f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_get(ocelot, port, sb_index, tc_index, 1302f59fd9caSVladimir Oltean pool_type, p_pool_index, 1303f59fd9caSVladimir Oltean p_threshold); 1304f59fd9caSVladimir Oltean } 1305f59fd9caSVladimir Oltean 1306f59fd9caSVladimir Oltean static int felix_sb_tc_pool_bind_set(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 pool_index, u32 threshold, 1310f59fd9caSVladimir Oltean struct netlink_ext_ack *extack) 1311f59fd9caSVladimir Oltean { 1312f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1313f59fd9caSVladimir Oltean 1314f59fd9caSVladimir Oltean return ocelot_sb_tc_pool_bind_set(ocelot, port, sb_index, tc_index, 1315f59fd9caSVladimir Oltean pool_type, pool_index, threshold, 1316f59fd9caSVladimir Oltean extack); 1317f59fd9caSVladimir Oltean } 1318f59fd9caSVladimir Oltean 1319f59fd9caSVladimir Oltean static int felix_sb_occ_snapshot(struct dsa_switch *ds, 1320f59fd9caSVladimir Oltean unsigned int sb_index) 1321f59fd9caSVladimir Oltean { 1322f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1323f59fd9caSVladimir Oltean 1324f59fd9caSVladimir Oltean return ocelot_sb_occ_snapshot(ocelot, sb_index); 1325f59fd9caSVladimir Oltean } 1326f59fd9caSVladimir Oltean 1327f59fd9caSVladimir Oltean static int felix_sb_occ_max_clear(struct dsa_switch *ds, 1328f59fd9caSVladimir Oltean unsigned int sb_index) 1329f59fd9caSVladimir Oltean { 1330f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1331f59fd9caSVladimir Oltean 1332f59fd9caSVladimir Oltean return ocelot_sb_occ_max_clear(ocelot, sb_index); 1333f59fd9caSVladimir Oltean } 1334f59fd9caSVladimir Oltean 1335f59fd9caSVladimir Oltean static int felix_sb_occ_port_pool_get(struct dsa_switch *ds, int port, 1336f59fd9caSVladimir Oltean unsigned int sb_index, u16 pool_index, 1337f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1338f59fd9caSVladimir Oltean { 1339f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1340f59fd9caSVladimir Oltean 1341f59fd9caSVladimir Oltean return ocelot_sb_occ_port_pool_get(ocelot, port, sb_index, pool_index, 1342f59fd9caSVladimir Oltean p_cur, p_max); 1343f59fd9caSVladimir Oltean } 1344f59fd9caSVladimir Oltean 1345f59fd9caSVladimir Oltean static int felix_sb_occ_tc_port_bind_get(struct dsa_switch *ds, int port, 1346f59fd9caSVladimir Oltean unsigned int sb_index, u16 tc_index, 1347f59fd9caSVladimir Oltean enum devlink_sb_pool_type pool_type, 1348f59fd9caSVladimir Oltean u32 *p_cur, u32 *p_max) 1349f59fd9caSVladimir Oltean { 1350f59fd9caSVladimir Oltean struct ocelot *ocelot = ds->priv; 1351f59fd9caSVladimir Oltean 1352f59fd9caSVladimir Oltean return ocelot_sb_occ_tc_port_bind_get(ocelot, port, sb_index, tc_index, 1353f59fd9caSVladimir Oltean pool_type, p_cur, p_max); 1354f59fd9caSVladimir Oltean } 1355f59fd9caSVladimir Oltean 1356375e1314SVladimir Oltean const struct dsa_switch_ops felix_switch_ops = { 135756051948SVladimir Oltean .get_tag_protocol = felix_get_tag_protocol, 1358adb3dccfSVladimir Oltean .change_tag_protocol = felix_change_tag_protocol, 135956051948SVladimir Oltean .setup = felix_setup, 136056051948SVladimir Oltean .teardown = felix_teardown, 136156051948SVladimir Oltean .set_ageing_time = felix_set_ageing_time, 136256051948SVladimir Oltean .get_strings = felix_get_strings, 136356051948SVladimir Oltean .get_ethtool_stats = felix_get_ethtool_stats, 136456051948SVladimir Oltean .get_sset_count = felix_get_sset_count, 136556051948SVladimir Oltean .get_ts_info = felix_get_ts_info, 1366bdeced75SVladimir Oltean .phylink_validate = felix_phylink_validate, 1367bdeced75SVladimir Oltean .phylink_mac_config = felix_phylink_mac_config, 1368bdeced75SVladimir Oltean .phylink_mac_link_down = felix_phylink_mac_link_down, 1369bdeced75SVladimir Oltean .phylink_mac_link_up = felix_phylink_mac_link_up, 137056051948SVladimir Oltean .port_enable = felix_port_enable, 137156051948SVladimir Oltean .port_disable = felix_port_disable, 137256051948SVladimir Oltean .port_fdb_dump = felix_fdb_dump, 137356051948SVladimir Oltean .port_fdb_add = felix_fdb_add, 137456051948SVladimir Oltean .port_fdb_del = felix_fdb_del, 1375209edf95SVladimir Oltean .port_mdb_add = felix_mdb_add, 1376209edf95SVladimir Oltean .port_mdb_del = felix_mdb_del, 137756051948SVladimir Oltean .port_bridge_join = felix_bridge_join, 137856051948SVladimir Oltean .port_bridge_leave = felix_bridge_leave, 13798fe6832eSVladimir Oltean .port_lag_join = felix_lag_join, 13808fe6832eSVladimir Oltean .port_lag_leave = felix_lag_leave, 13818fe6832eSVladimir Oltean .port_lag_change = felix_lag_change, 138256051948SVladimir Oltean .port_stp_state_set = felix_bridge_stp_state_set, 138356051948SVladimir Oltean .port_vlan_filtering = felix_vlan_filtering, 138456051948SVladimir Oltean .port_vlan_add = felix_vlan_add, 138556051948SVladimir Oltean .port_vlan_del = felix_vlan_del, 1386c0bcf537SYangbo Lu .port_hwtstamp_get = felix_hwtstamp_get, 1387c0bcf537SYangbo Lu .port_hwtstamp_set = felix_hwtstamp_set, 1388c0bcf537SYangbo Lu .port_rxtstamp = felix_rxtstamp, 1389c0bcf537SYangbo Lu .port_txtstamp = felix_txtstamp, 13900b912fc9SVladimir Oltean .port_change_mtu = felix_change_mtu, 13910b912fc9SVladimir Oltean .port_max_mtu = felix_get_max_mtu, 1392fc411eaaSVladimir Oltean .port_policer_add = felix_port_policer_add, 1393fc411eaaSVladimir Oltean .port_policer_del = felix_port_policer_del, 139407d985eeSVladimir Oltean .cls_flower_add = felix_cls_flower_add, 139507d985eeSVladimir Oltean .cls_flower_del = felix_cls_flower_del, 139607d985eeSVladimir Oltean .cls_flower_stats = felix_cls_flower_stats, 1397de143c0eSXiaoliang Yang .port_setup_tc = felix_port_setup_tc, 1398f59fd9caSVladimir Oltean .devlink_sb_pool_get = felix_sb_pool_get, 1399f59fd9caSVladimir Oltean .devlink_sb_pool_set = felix_sb_pool_set, 1400f59fd9caSVladimir Oltean .devlink_sb_port_pool_get = felix_sb_port_pool_get, 1401f59fd9caSVladimir Oltean .devlink_sb_port_pool_set = felix_sb_port_pool_set, 1402f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_get = felix_sb_tc_pool_bind_get, 1403f59fd9caSVladimir Oltean .devlink_sb_tc_pool_bind_set = felix_sb_tc_pool_bind_set, 1404f59fd9caSVladimir Oltean .devlink_sb_occ_snapshot = felix_sb_occ_snapshot, 1405f59fd9caSVladimir Oltean .devlink_sb_occ_max_clear = felix_sb_occ_max_clear, 1406f59fd9caSVladimir Oltean .devlink_sb_occ_port_pool_get = felix_sb_occ_port_pool_get, 1407f59fd9caSVladimir Oltean .devlink_sb_occ_tc_port_bind_get= felix_sb_occ_tc_port_bind_get, 140856051948SVladimir Oltean }; 1409319e4dd1SVladimir Oltean 1410319e4dd1SVladimir Oltean struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) 1411319e4dd1SVladimir Oltean { 1412319e4dd1SVladimir Oltean struct felix *felix = ocelot_to_felix(ocelot); 1413319e4dd1SVladimir Oltean struct dsa_switch *ds = felix->ds; 1414319e4dd1SVladimir Oltean 1415319e4dd1SVladimir Oltean if (!dsa_is_user_port(ds, port)) 1416319e4dd1SVladimir Oltean return NULL; 1417319e4dd1SVladimir Oltean 1418319e4dd1SVladimir Oltean return dsa_to_port(ds, port)->slave; 1419319e4dd1SVladimir Oltean } 1420319e4dd1SVladimir Oltean 1421319e4dd1SVladimir Oltean int felix_netdev_to_port(struct net_device *dev) 1422319e4dd1SVladimir Oltean { 1423319e4dd1SVladimir Oltean struct dsa_port *dp; 1424319e4dd1SVladimir Oltean 1425319e4dd1SVladimir Oltean dp = dsa_port_from_netdev(dev); 1426319e4dd1SVladimir Oltean if (IS_ERR(dp)) 1427319e4dd1SVladimir Oltean return -EINVAL; 1428319e4dd1SVladimir Oltean 1429319e4dd1SVladimir Oltean return dp->index; 1430319e4dd1SVladimir Oltean } 1431