Skip to content

Commit 6d3c8c0

Browse files
ffainellidavem330
authored andcommitted
net: dsa: Remove master_netdev and use dst->cpu_dp->netdev
In preparation for supporting multiple CPU ports, remove dst->master_netdev and ds->master_netdev and replace them with only one instance of the common object we have for a port: struct dsa_port::netdev. ds->master_netdev is currently write only and would be helpful in the case where we have two switches, both with CPU ports, and also connected within each other, which the multi-CPU port patch series would address. While at it, introduce a helper function used in net/dsa/slave.c to immediately get a reference on the master network device called dsa_master_netdev(). Reviewed-by: Vivien Didelot <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 38b6ec5 commit 6d3c8c0

File tree

8 files changed

+40
-48
lines changed

8 files changed

+40
-48
lines changed

drivers/net/dsa/bcm_sf2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)
806806
static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
807807
struct ethtool_wolinfo *wol)
808808
{
809-
struct net_device *p = ds->dst[ds->index].master_netdev;
809+
struct net_device *p = ds->dst[ds->index].cpu_dp->netdev;
810810
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
811811
struct ethtool_wolinfo pwol;
812812

@@ -829,7 +829,7 @@ static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
829829
static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
830830
struct ethtool_wolinfo *wol)
831831
{
832-
struct net_device *p = ds->dst[ds->index].master_netdev;
832+
struct net_device *p = ds->dst[ds->index].cpu_dp->netdev;
833833
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
834834
s8 cpu_port = ds->dst->cpu_dp->index;
835835
struct ethtool_wolinfo pwol;

drivers/net/dsa/mt7530.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,11 @@ mt7530_setup(struct dsa_switch *ds)
912912
struct device_node *dn;
913913
struct mt7530_dummy_poll p;
914914

915-
/* The parent node of master_netdev which holds the common system
915+
/* The parent node of cpu_dp->netdev which holds the common system
916916
* controller also is the container for two GMACs nodes representing
917917
* as two netdev instances.
918918
*/
919-
dn = ds->master_netdev->dev.of_node->parent;
919+
dn = ds->dst->cpu_dp->netdev->dev.of_node->parent;
920920
priv->ethernet = syscon_node_to_regmap(dn);
921921
if (IS_ERR(priv->ethernet))
922922
return PTR_ERR(priv->ethernet);

include/net/dsa.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ struct dsa_switch {
226226
*/
227227
s8 rtable[DSA_MAX_SWITCHES];
228228

229-
/*
230-
* The lower device this switch uses to talk to the host
231-
*/
232-
struct net_device *master_netdev;
233-
234229
/*
235230
* Slave mii_bus and devices for the individual ports.
236231
*/

net/dsa/dsa.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ int dsa_cpu_port_ethtool_setup(struct dsa_port *cpu_dp)
118118
struct net_device *master;
119119
struct ethtool_ops *cpu_ops;
120120

121-
master = ds->dst->master_netdev;
122-
if (ds->master_netdev)
123-
master = ds->master_netdev;
124-
121+
master = ds->dst->cpu_dp->netdev;
125122
cpu_ops = devm_kzalloc(ds->dev, sizeof(*cpu_ops), GFP_KERNEL);
126123
if (!cpu_ops)
127124
return -ENOMEM;
@@ -142,9 +139,7 @@ void dsa_cpu_port_ethtool_restore(struct dsa_port *cpu_dp)
142139
struct dsa_switch *ds = cpu_dp->ds;
143140
struct net_device *master;
144141

145-
master = ds->dst->master_netdev;
146-
if (ds->master_netdev)
147-
master = ds->master_netdev;
142+
master = ds->dst->cpu_dp->netdev;
148143

149144
master->ethtool_ops = ds->dst->master_orig_ethtool_ops;
150145
}

net/dsa/dsa2.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
337337
return err;
338338

339339
if (ds->ops->set_addr) {
340-
err = ds->ops->set_addr(ds, dst->master_netdev->dev_addr);
340+
err = ds->ops->set_addr(ds, dst->cpu_dp->netdev->dev_addr);
341341
if (err < 0)
342342
return err;
343343
}
@@ -444,7 +444,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
444444
* sent to the tag format's receive function.
445445
*/
446446
wmb();
447-
dst->master_netdev->dsa_ptr = dst;
447+
dst->cpu_dp->netdev->dsa_ptr = dst;
448448
dst->applied = true;
449449

450450
return 0;
@@ -458,7 +458,7 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
458458
if (!dst->applied)
459459
return;
460460

461-
dst->master_netdev->dsa_ptr = NULL;
461+
dst->cpu_dp->netdev->dsa_ptr = NULL;
462462

463463
/* If we used a tagging format that doesn't have an ethertype
464464
* field, make sure that all packets from this point get sent
@@ -504,14 +504,10 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
504504
if (!ethernet_dev)
505505
return -EPROBE_DEFER;
506506

507-
if (!ds->master_netdev)
508-
ds->master_netdev = ethernet_dev;
509-
510-
if (!dst->master_netdev)
511-
dst->master_netdev = ethernet_dev;
512-
513-
if (!dst->cpu_dp)
507+
if (!dst->cpu_dp) {
514508
dst->cpu_dp = port;
509+
dst->cpu_dp->netdev = ethernet_dev;
510+
}
515511

516512
tag_protocol = ds->ops->get_tag_protocol(ds);
517513
dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
@@ -578,7 +574,7 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst)
578574
return err;
579575
}
580576

581-
if (!dst->master_netdev) {
577+
if (!dst->cpu_dp->netdev) {
582578
pr_warn("Tree has no master device\n");
583579
return -EINVAL;
584580
}

net/dsa/dsa_priv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,9 @@ extern const struct dsa_device_ops qca_netdev_ops;
183183
/* tag_trailer.c */
184184
extern const struct dsa_device_ops trailer_netdev_ops;
185185

186+
static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p)
187+
{
188+
return p->dp->ds->dst->cpu_dp->netdev;
189+
}
190+
186191
#endif

net/dsa/legacy.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
101101
struct dsa_switch_tree *dst = ds->dst;
102102
struct dsa_chip_data *cd = ds->cd;
103103
bool valid_name_found = false;
104+
struct net_device *master;
104105
int index = ds->index;
105106
int i, ret;
106107

108+
master = dst->cpu_dp->netdev;
109+
107110
/*
108111
* Validate supplied switch configuration.
109112
*/
@@ -116,7 +119,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
116119

117120
if (!strcmp(name, "cpu")) {
118121
if (dst->cpu_dp) {
119-
netdev_err(dst->master_netdev,
122+
netdev_err(master,
120123
"multiple cpu ports?!\n");
121124
return -EINVAL;
122125
}
@@ -168,7 +171,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
168171
return ret;
169172

170173
if (ops->set_addr) {
171-
ret = ops->set_addr(ds, dst->master_netdev->dev_addr);
174+
ret = ops->set_addr(ds, master->dev_addr);
172175
if (ret < 0)
173176
return ret;
174177
}
@@ -195,14 +198,14 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
195198

196199
ret = dsa_slave_create(ds, parent, i, cd->port_names[i]);
197200
if (ret < 0)
198-
netdev_err(dst->master_netdev, "[%d]: can't create dsa slave device for port %d(%s): %d\n",
201+
netdev_err(master, "[%d]: can't create dsa slave device for port %d(%s): %d\n",
199202
index, i, cd->port_names[i], ret);
200203
}
201204

202205
/* Perform configuration of the CPU and DSA ports */
203206
ret = dsa_cpu_dsa_setups(ds, parent);
204207
if (ret < 0)
205-
netdev_err(dst->master_netdev, "[%d] : can't configure CPU and DSA ports\n",
208+
netdev_err(master, "[%d] : can't configure CPU and DSA ports\n",
206209
index);
207210

208211
ret = dsa_cpu_port_ethtool_setup(ds->dst->cpu_dp);
@@ -217,6 +220,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
217220
struct device *parent, struct device *host_dev)
218221
{
219222
struct dsa_chip_data *cd = dst->pd->chip + index;
223+
struct net_device *master = dst->cpu_dp->netdev;
220224
const struct dsa_switch_ops *ops;
221225
struct dsa_switch *ds;
222226
int ret;
@@ -228,11 +232,11 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
228232
*/
229233
ops = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
230234
if (!ops) {
231-
netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
235+
netdev_err(master, "[%d]: could not detect attached switch\n",
232236
index);
233237
return ERR_PTR(-EINVAL);
234238
}
235-
netdev_info(dst->master_netdev, "[%d]: detected a %s switch\n",
239+
netdev_info(master, "[%d]: detected a %s switch\n",
236240
index, name);
237241

238242

@@ -575,7 +579,7 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
575579
unsigned configured = 0;
576580

577581
dst->pd = pd;
578-
dst->master_netdev = dev;
582+
dst->cpu_dp->netdev = dev;
579583

580584
for (i = 0; i < pd->nr_chips; i++) {
581585
struct dsa_switch *ds;
@@ -671,7 +675,7 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
671675
{
672676
int i;
673677

674-
dst->master_netdev->dsa_ptr = NULL;
678+
dst->cpu_dp->netdev->dsa_ptr = NULL;
675679

676680
/* If we used a tagging format that doesn't have an ethertype
677681
* field, make sure that all packets from this point get sent
@@ -688,7 +692,7 @@ static void dsa_remove_dst(struct dsa_switch_tree *dst)
688692

689693
dsa_cpu_port_ethtool_restore(dst->cpu_dp);
690694

691-
dev_put(dst->master_netdev);
695+
dev_put(dst->cpu_dp->netdev);
692696
}
693697

694698
static int dsa_remove(struct platform_device *pdev)

net/dsa/slave.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ static int dsa_slave_get_iflink(const struct net_device *dev)
6666
{
6767
struct dsa_slave_priv *p = netdev_priv(dev);
6868

69-
return p->dp->ds->dst->master_netdev->ifindex;
69+
return dsa_master_netdev(p)->ifindex;
7070
}
7171

7272
static int dsa_slave_open(struct net_device *dev)
7373
{
7474
struct dsa_slave_priv *p = netdev_priv(dev);
7575
struct dsa_port *dp = p->dp;
7676
struct dsa_switch *ds = dp->ds;
77-
struct net_device *master = ds->dst->master_netdev;
77+
struct net_device *master = dsa_master_netdev(p);
7878
u8 stp_state = dp->bridge_dev ? BR_STATE_BLOCKING : BR_STATE_FORWARDING;
7979
int err;
8080

@@ -127,7 +127,7 @@ static int dsa_slave_open(struct net_device *dev)
127127
static int dsa_slave_close(struct net_device *dev)
128128
{
129129
struct dsa_slave_priv *p = netdev_priv(dev);
130-
struct net_device *master = p->dp->ds->dst->master_netdev;
130+
struct net_device *master = dsa_master_netdev(p);
131131
struct dsa_switch *ds = p->dp->ds;
132132

133133
if (p->phy)
@@ -154,7 +154,7 @@ static int dsa_slave_close(struct net_device *dev)
154154
static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
155155
{
156156
struct dsa_slave_priv *p = netdev_priv(dev);
157-
struct net_device *master = p->dp->ds->dst->master_netdev;
157+
struct net_device *master = dsa_master_netdev(p);
158158

159159
if (change & IFF_ALLMULTI)
160160
dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1);
@@ -165,7 +165,7 @@ static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
165165
static void dsa_slave_set_rx_mode(struct net_device *dev)
166166
{
167167
struct dsa_slave_priv *p = netdev_priv(dev);
168-
struct net_device *master = p->dp->ds->dst->master_netdev;
168+
struct net_device *master = dsa_master_netdev(p);
169169

170170
dev_mc_sync(master, dev);
171171
dev_uc_sync(master, dev);
@@ -174,7 +174,7 @@ static void dsa_slave_set_rx_mode(struct net_device *dev)
174174
static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
175175
{
176176
struct dsa_slave_priv *p = netdev_priv(dev);
177-
struct net_device *master = p->dp->ds->dst->master_netdev;
177+
struct net_device *master = dsa_master_netdev(p);
178178
struct sockaddr *addr = a;
179179
int err;
180180

@@ -375,7 +375,7 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
375375
/* Queue the SKB for transmission on the parent interface, but
376376
* do not modify its EtherType
377377
*/
378-
nskb->dev = p->dp->ds->dst->master_netdev;
378+
nskb->dev = dsa_master_netdev(p);
379379
dev_queue_xmit(nskb);
380380

381381
return NETDEV_TX_OK;
@@ -684,8 +684,7 @@ static int dsa_slave_netpoll_setup(struct net_device *dev,
684684
struct netpoll_info *ni)
685685
{
686686
struct dsa_slave_priv *p = netdev_priv(dev);
687-
struct dsa_switch *ds = p->dp->ds;
688-
struct net_device *master = ds->dst->master_netdev;
687+
struct net_device *master = dsa_master_netdev(p);
689688
struct netpoll *netpoll;
690689
int err = 0;
691690

@@ -1143,9 +1142,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
11431142
struct dsa_slave_priv *p;
11441143
int ret;
11451144

1146-
master = ds->dst->master_netdev;
1147-
if (ds->master_netdev)
1148-
master = ds->master_netdev;
1145+
master = ds->dst->cpu_dp->netdev;
11491146

11501147
slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name,
11511148
NET_NAME_UNKNOWN, ether_setup);

0 commit comments

Comments
 (0)