Skip to content

Commit d8f375e

Browse files
committed
Merge branch 'net-dsa-loop-Preparatory-changes-for-802-1Q-data-path'
net: dsa: loop: Preparatory changes for 802.1Q data path Florian Fainelli says: ==================== These patches are all meant to help pave the way for a 802.1Q data path added to the mockup driver, making it more useful than just testing for configuration. Sending those out now since there is no real need to wait. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 59b328c + 947b6ef commit d8f375e

File tree

2 files changed

+64
-38
lines changed

2 files changed

+64
-38
lines changed

drivers/net/dsa/dsa_loop.c

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,18 @@
1414
#include <linux/workqueue.h>
1515
#include <linux/module.h>
1616
#include <linux/if_bridge.h>
17+
#include <linux/dsa/loop.h>
1718
#include <net/dsa.h>
1819

1920
#include "dsa_loop.h"
2021

21-
struct dsa_loop_vlan {
22-
u16 members;
23-
u16 untagged;
24-
};
25-
26-
struct dsa_loop_mib_entry {
27-
char name[ETH_GSTRING_LEN];
28-
unsigned long val;
29-
};
30-
31-
enum dsa_loop_mib_counters {
32-
DSA_LOOP_PHY_READ_OK,
33-
DSA_LOOP_PHY_READ_ERR,
34-
DSA_LOOP_PHY_WRITE_OK,
35-
DSA_LOOP_PHY_WRITE_ERR,
36-
__DSA_LOOP_CNT_MAX,
37-
};
38-
3922
static struct dsa_loop_mib_entry dsa_loop_mibs[] = {
4023
[DSA_LOOP_PHY_READ_OK] = { "phy_read_ok", },
4124
[DSA_LOOP_PHY_READ_ERR] = { "phy_read_err", },
4225
[DSA_LOOP_PHY_WRITE_OK] = { "phy_write_ok", },
4326
[DSA_LOOP_PHY_WRITE_ERR] = { "phy_write_err", },
4427
};
4528

46-
struct dsa_loop_port {
47-
struct dsa_loop_mib_entry mib[__DSA_LOOP_CNT_MAX];
48-
};
49-
50-
#define DSA_LOOP_VLANS 5
51-
52-
struct dsa_loop_priv {
53-
struct mii_bus *bus;
54-
unsigned int port_base;
55-
struct dsa_loop_vlan vlans[DSA_LOOP_VLANS];
56-
struct net_device *netdev;
57-
struct dsa_loop_port ports[DSA_MAX_PORTS];
58-
u16 pvid;
59-
};
60-
6129
static struct phy_device *phydevs[PHY_MAX_ADDR];
6230

6331
static enum dsa_tag_protocol dsa_loop_get_protocol(struct dsa_switch *ds,
@@ -191,7 +159,7 @@ dsa_loop_port_vlan_prepare(struct dsa_switch *ds, int port,
191159
/* Just do a sleeping operation to make lockdep checks effective */
192160
mdiobus_read(bus, ps->port_base + port, MII_BMSR);
193161

194-
if (vlan->vid_end > DSA_LOOP_VLANS)
162+
if (vlan->vid_end > ARRAY_SIZE(ps->vlans))
195163
return -ERANGE;
196164

197165
return 0;
@@ -224,7 +192,7 @@ static void dsa_loop_port_vlan_add(struct dsa_switch *ds, int port,
224192
}
225193

226194
if (pvid)
227-
ps->pvid = vid;
195+
ps->ports[port].pvid = vid;
228196
}
229197

230198
static int dsa_loop_port_vlan_del(struct dsa_switch *ds, int port,
@@ -234,7 +202,7 @@ static int dsa_loop_port_vlan_del(struct dsa_switch *ds, int port,
234202
struct dsa_loop_priv *ps = ds->priv;
235203
struct mii_bus *bus = ps->bus;
236204
struct dsa_loop_vlan *vl;
237-
u16 vid, pvid = ps->pvid;
205+
u16 vid, pvid = ps->ports[port].pvid;
238206

239207
/* Just do a sleeping operation to make lockdep checks effective */
240208
mdiobus_read(bus, ps->port_base + port, MII_BMSR);
@@ -252,11 +220,26 @@ static int dsa_loop_port_vlan_del(struct dsa_switch *ds, int port,
252220
dev_dbg(ds->dev, "%s: port: %d vlan: %d, %stagged, pvid: %d\n",
253221
__func__, port, vid, untagged ? "un" : "", pvid);
254222
}
255-
ps->pvid = pvid;
223+
ps->ports[port].pvid = pvid;
224+
225+
return 0;
226+
}
227+
228+
static int dsa_loop_port_change_mtu(struct dsa_switch *ds, int port,
229+
int new_mtu)
230+
{
231+
struct dsa_loop_priv *priv = ds->priv;
232+
233+
priv->ports[port].mtu = new_mtu;
256234

257235
return 0;
258236
}
259237

238+
static int dsa_loop_port_max_mtu(struct dsa_switch *ds, int port)
239+
{
240+
return ETH_MAX_MTU;
241+
}
242+
260243
static const struct dsa_switch_ops dsa_loop_driver = {
261244
.get_tag_protocol = dsa_loop_get_protocol,
262245
.setup = dsa_loop_setup,
@@ -273,6 +256,8 @@ static const struct dsa_switch_ops dsa_loop_driver = {
273256
.port_vlan_prepare = dsa_loop_port_vlan_prepare,
274257
.port_vlan_add = dsa_loop_port_vlan_add,
275258
.port_vlan_del = dsa_loop_port_vlan_del,
259+
.port_change_mtu = dsa_loop_port_change_mtu,
260+
.port_max_mtu = dsa_loop_port_max_mtu,
276261
};
277262

278263
static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
@@ -290,7 +275,7 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
290275
return -ENOMEM;
291276

292277
ds->dev = &mdiodev->dev;
293-
ds->num_ports = DSA_MAX_PORTS;
278+
ds->num_ports = DSA_LOOP_NUM_PORTS;
294279

295280
ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL);
296281
if (!ps)

include/linux/dsa/loop.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef DSA_LOOP_H
3+
#define DSA_LOOP_H
4+
5+
#include <linux/types.h>
6+
#include <linux/ethtool.h>
7+
#include <net/dsa.h>
8+
9+
struct dsa_loop_vlan {
10+
u16 members;
11+
u16 untagged;
12+
};
13+
14+
struct dsa_loop_mib_entry {
15+
char name[ETH_GSTRING_LEN];
16+
unsigned long val;
17+
};
18+
19+
enum dsa_loop_mib_counters {
20+
DSA_LOOP_PHY_READ_OK,
21+
DSA_LOOP_PHY_READ_ERR,
22+
DSA_LOOP_PHY_WRITE_OK,
23+
DSA_LOOP_PHY_WRITE_ERR,
24+
__DSA_LOOP_CNT_MAX,
25+
};
26+
27+
struct dsa_loop_port {
28+
struct dsa_loop_mib_entry mib[__DSA_LOOP_CNT_MAX];
29+
u16 pvid;
30+
int mtu;
31+
};
32+
33+
struct dsa_loop_priv {
34+
struct mii_bus *bus;
35+
unsigned int port_base;
36+
struct dsa_loop_vlan vlans[VLAN_N_VID];
37+
struct net_device *netdev;
38+
struct dsa_loop_port ports[DSA_MAX_PORTS];
39+
};
40+
41+
#endif /* DSA_LOOP_H */

0 commit comments

Comments
 (0)