Skip to content

Commit 68bb8ea

Browse files
vivienJakub Kicinski
authored andcommitted
net: dsa: use dsa_to_port helper everywhere
Do not let the drivers access the ds->ports static array directly while there is a dsa_to_port helper for this purpose. At the same time, un-const this helper since the SJA1105 driver assigns the priv member of the returned dsa_port structure. Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
1 parent 88652bf commit 68bb8ea

12 files changed

Lines changed: 44 additions & 42 deletions

File tree

‎drivers/net/dsa/b53/b53_common.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
524524
if (!dsa_is_user_port(ds, port))
525525
return 0;
526526

527-
cpu_port = ds->ports[port].cpu_dp->index;
527+
cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
528528

529529
if (dev->ops->irq_enable)
530530
ret = dev->ops->irq_enable(dev, port);
@@ -1629,7 +1629,7 @@ EXPORT_SYMBOL(b53_fdb_dump);
16291629
int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
16301630
{
16311631
struct b53_device *dev = ds->priv;
1632-
s8 cpu_port = ds->ports[port].cpu_dp->index;
1632+
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
16331633
u16 pvlan, reg;
16341634
unsigned int i;
16351635

@@ -1675,7 +1675,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
16751675
{
16761676
struct b53_device *dev = ds->priv;
16771677
struct b53_vlan *vl = &dev->vlans[0];
1678-
s8 cpu_port = ds->ports[port].cpu_dp->index;
1678+
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
16791679
unsigned int i;
16801680
u16 pvlan, reg, pvid;
16811681

‎drivers/net/dsa/bcm_sf2.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ static void bcm_sf2_sw_fixed_state(struct dsa_switch *ds, int port,
662662
* state machine and make it go in PHY_FORCING state instead.
663663
*/
664664
if (!status->link)
665-
netif_carrier_off(ds->ports[port].slave);
665+
netif_carrier_off(dsa_to_port(ds, port)->slave);
666666
status->duplex = DUPLEX_FULL;
667667
} else {
668668
status->link = true;
@@ -728,7 +728,7 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)
728728
static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
729729
struct ethtool_wolinfo *wol)
730730
{
731-
struct net_device *p = ds->ports[port].cpu_dp->master;
731+
struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
732732
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
733733
struct ethtool_wolinfo pwol = { };
734734

@@ -752,9 +752,9 @@ static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
752752
static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
753753
struct ethtool_wolinfo *wol)
754754
{
755-
struct net_device *p = ds->ports[port].cpu_dp->master;
755+
struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
756756
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
757-
s8 cpu_port = ds->ports[port].cpu_dp->index;
757+
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
758758
struct ethtool_wolinfo pwol = { };
759759

760760
if (p->ethtool_ops->get_wol)

‎drivers/net/dsa/bcm_sf2_cfp.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ static int bcm_sf2_cfp_rule_insert(struct dsa_switch *ds, int port,
821821
struct ethtool_rx_flow_spec *fs)
822822
{
823823
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
824-
s8 cpu_port = ds->ports[port].cpu_dp->index;
824+
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
825825
__u64 ring_cookie = fs->ring_cookie;
826826
unsigned int queue_num, port_num;
827827
int ret;
@@ -1049,7 +1049,7 @@ static int bcm_sf2_cfp_rule_get_all(struct bcm_sf2_priv *priv,
10491049
int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
10501050
struct ethtool_rxnfc *nfc, u32 *rule_locs)
10511051
{
1052-
struct net_device *p = ds->ports[port].cpu_dp->master;
1052+
struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
10531053
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
10541054
int ret = 0;
10551055

@@ -1092,7 +1092,7 @@ int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
10921092
int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
10931093
struct ethtool_rxnfc *nfc)
10941094
{
1095-
struct net_device *p = ds->ports[port].cpu_dp->master;
1095+
struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master;
10961096
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
10971097
int ret = 0;
10981098

‎drivers/net/dsa/mt7530.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port)
862862

863863
for (i = 0; i < MT7530_NUM_PORTS; i++) {
864864
if (dsa_is_user_port(ds, i) &&
865-
dsa_port_is_vlan_filtering(&ds->ports[i])) {
865+
dsa_port_is_vlan_filtering(dsa_to_port(ds, i))) {
866866
all_user_ports_removed = false;
867867
break;
868868
}
@@ -922,7 +922,7 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port,
922922
* other port is still a VLAN-aware port.
923923
*/
924924
if (dsa_is_user_port(ds, i) && i != port &&
925-
!dsa_port_is_vlan_filtering(&ds->ports[i])) {
925+
!dsa_port_is_vlan_filtering(dsa_to_port(ds, i))) {
926926
if (dsa_to_port(ds, i)->bridge_dev != bridge)
927927
continue;
928928
if (priv->ports[i].enable)
@@ -1165,7 +1165,7 @@ mt7530_port_vlan_add(struct dsa_switch *ds, int port,
11651165
/* The port is kept as VLAN-unaware if bridge with vlan_filtering not
11661166
* being set.
11671167
*/
1168-
if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
1168+
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
11691169
return;
11701170

11711171
mutex_lock(&priv->reg_mutex);
@@ -1196,7 +1196,7 @@ mt7530_port_vlan_del(struct dsa_switch *ds, int port,
11961196
/* The port is kept as VLAN-unaware if bridge with vlan_filtering not
11971197
* being set.
11981198
*/
1199-
if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
1199+
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
12001200
return 0;
12011201

12021202
mutex_lock(&priv->reg_mutex);
@@ -1252,7 +1252,7 @@ mt7530_setup(struct dsa_switch *ds)
12521252
* controller also is the container for two GMACs nodes representing
12531253
* as two netdev instances.
12541254
*/
1255-
dn = ds->ports[MT7530_CPU_PORT].master->dev.of_node->parent;
1255+
dn = dsa_to_port(ds, MT7530_CPU_PORT)->master->dev.of_node->parent;
12561256

12571257
if (priv->id == ID_MT7530) {
12581258
priv->ethernet = syscon_node_to_regmap(dn);
@@ -1340,7 +1340,7 @@ mt7530_setup(struct dsa_switch *ds)
13401340

13411341
if (!dsa_is_unused_port(ds, 5)) {
13421342
priv->p5_intf_sel = P5_INTF_SEL_GMAC5;
1343-
interface = of_get_phy_mode(ds->ports[5].dn);
1343+
interface = of_get_phy_mode(dsa_to_port(ds, 5)->dn);
13441344
} else {
13451345
/* Scan the ethernet nodes. look for GMAC1, lookup used phy */
13461346
for_each_child_of_node(dn, mac_np) {

‎drivers/net/dsa/mv88e6xxx/chip.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port)
10751075
if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port))
10761076
return mv88e6xxx_port_mask(chip);
10771077

1078-
br = ds->ports[port].bridge_dev;
1078+
br = dsa_to_port(ds, port)->bridge_dev;
10791079
pvlan = 0;
10801080

10811081
/* Frames from user ports can egress any local DSA links and CPU ports,
@@ -1402,15 +1402,15 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
14021402
if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
14031403
continue;
14041404

1405-
if (!ds->ports[i].slave)
1405+
if (!dsa_to_port(ds, i)->slave)
14061406
continue;
14071407

14081408
if (vlan.member[i] ==
14091409
MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER)
14101410
continue;
14111411

14121412
if (dsa_to_port(ds, i)->bridge_dev ==
1413-
ds->ports[port].bridge_dev)
1413+
dsa_to_port(ds, port)->bridge_dev)
14141414
break; /* same bridge, check next VLAN */
14151415

14161416
if (!dsa_to_port(ds, i)->bridge_dev)
@@ -2042,7 +2042,7 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
20422042

20432043
/* Remap the Port VLAN of each local bridge group member */
20442044
for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) {
2045-
if (chip->ds->ports[port].bridge_dev == br) {
2045+
if (dsa_to_port(chip->ds, port)->bridge_dev == br) {
20462046
err = mv88e6xxx_port_vlan_map(chip, port);
20472047
if (err)
20482048
return err;
@@ -2059,7 +2059,7 @@ static int mv88e6xxx_bridge_map(struct mv88e6xxx_chip *chip,
20592059
break;
20602060

20612061
for (port = 0; port < ds->num_ports; ++port) {
2062-
if (ds->ports[port].bridge_dev == br) {
2062+
if (dsa_to_port(ds, port)->bridge_dev == br) {
20632063
err = mv88e6xxx_pvt_map(chip, dev, port);
20642064
if (err)
20652065
return err;

‎drivers/net/dsa/qca8k.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ qca8k_setup(struct dsa_switch *ds)
661661
return ret;
662662

663663
/* Initialize CPU port pad mode (xMII type, delays...) */
664-
phy_mode = of_get_phy_mode(ds->ports[QCA8K_CPU_PORT].dn);
664+
phy_mode = of_get_phy_mode(dsa_to_port(ds, QCA8K_CPU_PORT)->dn);
665665
if (phy_mode < 0) {
666666
pr_err("Can't find phy-mode for master device\n");
667667
return phy_mode;

‎drivers/net/dsa/sja1105/sja1105_main.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port,
10581058
l2_lookup.vlanid = vid;
10591059
l2_lookup.iotag = SJA1105_S_TAG;
10601060
l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
1061-
if (dsa_port_is_vlan_filtering(&ds->ports[port])) {
1061+
if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
10621062
l2_lookup.mask_vlanid = VLAN_VID_MASK;
10631063
l2_lookup.mask_iotag = BIT(0);
10641064
} else {
@@ -1121,7 +1121,7 @@ int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port,
11211121
l2_lookup.vlanid = vid;
11221122
l2_lookup.iotag = SJA1105_S_TAG;
11231123
l2_lookup.mask_macaddr = GENMASK_ULL(ETH_ALEN * 8 - 1, 0);
1124-
if (dsa_port_is_vlan_filtering(&ds->ports[port])) {
1124+
if (dsa_port_is_vlan_filtering(dsa_to_port(ds, port))) {
11251125
l2_lookup.mask_vlanid = VLAN_VID_MASK;
11261126
l2_lookup.mask_iotag = BIT(0);
11271127
} else {
@@ -1167,7 +1167,7 @@ static int sja1105_fdb_add(struct dsa_switch *ds, int port,
11671167
* for what gets printed in 'bridge fdb show'. In the case of zero,
11681168
* no VID gets printed at all.
11691169
*/
1170-
if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
1170+
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
11711171
vid = 0;
11721172

11731173
return priv->info->fdb_add_cmd(ds, port, addr, vid);
@@ -1178,7 +1178,7 @@ static int sja1105_fdb_del(struct dsa_switch *ds, int port,
11781178
{
11791179
struct sja1105_private *priv = ds->priv;
11801180

1181-
if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
1181+
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
11821182
vid = 0;
11831183

11841184
return priv->info->fdb_del_cmd(ds, port, addr, vid);
@@ -1217,7 +1217,7 @@ static int sja1105_fdb_dump(struct dsa_switch *ds, int port,
12171217
u64_to_ether_addr(l2_lookup.macaddr, macaddr);
12181218

12191219
/* We need to hide the dsa_8021q VLANs from the user. */
1220-
if (!dsa_port_is_vlan_filtering(&ds->ports[port]))
1220+
if (!dsa_port_is_vlan_filtering(dsa_to_port(ds, port)))
12211221
l2_lookup.vlanid = 0;
12221222
cb(macaddr, l2_lookup.vlanid, l2_lookup.lockeds, data);
12231223
}
@@ -1704,7 +1704,7 @@ static int sja1105_port_enable(struct dsa_switch *ds, int port,
17041704
if (!dsa_is_user_port(ds, port))
17051705
return 0;
17061706

1707-
slave = ds->ports[port].slave;
1707+
slave = dsa_to_port(ds, port)->slave;
17081708

17091709
slave->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
17101710

@@ -1736,7 +1736,7 @@ static int sja1105_mgmt_xmit(struct dsa_switch *ds, int port, int slot,
17361736
}
17371737

17381738
/* Transfer skb to the host port. */
1739-
dsa_enqueue_skb(skb, ds->ports[port].slave);
1739+
dsa_enqueue_skb(skb, dsa_to_port(ds, port)->slave);
17401740

17411741
/* Wait until the switch has processed the frame */
17421742
do {
@@ -2061,8 +2061,8 @@ static int sja1105_probe(struct spi_device *spi)
20612061
for (i = 0; i < SJA1105_NUM_PORTS; i++) {
20622062
struct sja1105_port *sp = &priv->ports[i];
20632063

2064-
ds->ports[i].priv = sp;
2065-
sp->dp = &ds->ports[i];
2064+
dsa_to_port(ds, i)->priv = sp;
2065+
sp->dp = dsa_to_port(ds, i);
20662066
sp->data = tagger_data;
20672067
}
20682068
mutex_init(&priv->ptp_data.lock);

‎include/net/dsa.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ struct dsa_switch {
278278
struct dsa_port ports[];
279279
};
280280

281-
static inline const struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
281+
static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
282282
{
283283
return &ds->ports[p];
284284
}

‎net/dsa/dsa.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
246246
#ifdef CONFIG_PM_SLEEP
247247
static bool dsa_is_port_initialized(struct dsa_switch *ds, int p)
248248
{
249-
return dsa_is_user_port(ds, p) && ds->ports[p].slave;
249+
const struct dsa_port *dp = dsa_to_port(ds, p);
250+
251+
return dp->type == DSA_PORT_TYPE_USER && dp->slave;
250252
}
251253

252254
int dsa_switch_suspend(struct dsa_switch *ds)
@@ -258,7 +260,7 @@ int dsa_switch_suspend(struct dsa_switch *ds)
258260
if (!dsa_is_port_initialized(ds, i))
259261
continue;
260262

261-
ret = dsa_slave_suspend(ds->ports[i].slave);
263+
ret = dsa_slave_suspend(dsa_to_port(ds, i)->slave);
262264
if (ret)
263265
return ret;
264266
}
@@ -285,7 +287,7 @@ int dsa_switch_resume(struct dsa_switch *ds)
285287
if (!dsa_is_port_initialized(ds, i))
286288
continue;
287289

288-
ret = dsa_slave_resume(ds->ports[i].slave);
290+
ret = dsa_slave_resume(dsa_to_port(ds, i)->slave);
289291
if (ret)
290292
return ret;
291293
}

‎net/dsa/dsa2.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
708708
goto out_put_node;
709709
}
710710

711-
dp = &ds->ports[reg];
711+
dp = dsa_to_port(ds, reg);
712712

713713
err = dsa_port_parse_of(dp, port);
714714
if (err)
@@ -787,7 +787,7 @@ static int dsa_switch_parse_ports(struct dsa_switch *ds,
787787
for (i = 0; i < DSA_MAX_PORTS; i++) {
788788
name = cd->port_names[i];
789789
dev = cd->netdev[i];
790-
dp = &ds->ports[i];
790+
dp = dsa_to_port(ds, i);
791791

792792
if (!name)
793793
continue;

0 commit comments

Comments
 (0)