On 06/07/2017 10:15 AM, Vivien Didelot wrote: > Hi Florian, > > Florian Fainelli <f.faine...@gmail.com> writes: > >>> So as I said in v2, now that a driver is guaranteed that dp->cpu_dp is >>> correctly assigned at setup time, isn't better (especially for future >>> multi-CPU support) to provide an helper which returns the CPU port for a >>> given port? i.e. dsa_get_cpu_port(struct dsa_switch *ds, int port). >>> >>> Or is there something blocking? I might be wrong. >> >> mt7530.c needs access to the CPU port at ops->setup() time which is >> why this is still here. > > Yes, mt7530 is the only one doing this and has an hardcoded CPU port. So > what I meant was, shouldn't we have this instead: > > struct dsa_port *dsa_get_cpu_port(struct dsa_switch *ds, int port) > { > return ds->ports[port].cpu_dp; > }
We don't actually have a CPU port point to itself: + + for (i = 0; i < ds->num_ports; i++) { + p = &ds->ports[i]; + if (!dsa_port_is_valid(p) || + i == index) <============= + continue; + + p->cpu_dp = port; + } } > > And: > > - dn = ds->dst->cpu_dp->netdev->dev.of_node->parent; > + cpu_dp = dsa_get_cpu_port(ds, MT7530_CPU_PORT); > + dn = cpu_dp->netdev->dev.of_node->parent; If we are giving the port number to get its cpu_dp pointer back, that seems a bit pointless. I still think the helper with fls(ds->cpu_port_mask) - 1 is better in that it will return what you have configured from Device Tree/platform data. MT7530 does allow the CPU port being arbitrary, and it would disable MTK tags in that case. Thanks! -- Florian