Skip to content

Commit 60724d4

Browse files
ffainellidavem330
authored andcommitted
net: dsa: Add support for DSA specific notifiers
In preparation for communicating a given DSA network device's port number and switch index, create a specialized DSA notifier and two events: DSA_PORT_REGISTER and DSA_PORT_UNREGISTER that communicate: the slave network device (slave_dev), port number and switch number in the tree. This will be later used for network device drivers like bcmsysport which needs to cooperate with its DSA network devices to set-up queue mapping and scheduling. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3f7832c commit 60724d4

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

include/net/dsa.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,49 @@ static inline int dsa_switch_resume(struct dsa_switch *ds)
471471
}
472472
#endif /* CONFIG_PM_SLEEP */
473473

474+
enum dsa_notifier_type {
475+
DSA_PORT_REGISTER,
476+
DSA_PORT_UNREGISTER,
477+
};
478+
479+
struct dsa_notifier_info {
480+
struct net_device *dev;
481+
};
482+
483+
struct dsa_notifier_register_info {
484+
struct dsa_notifier_info info; /* must be first */
485+
struct net_device *master;
486+
unsigned int port_number;
487+
unsigned int switch_number;
488+
};
489+
490+
static inline struct net_device *
491+
dsa_notifier_info_to_dev(const struct dsa_notifier_info *info)
492+
{
493+
return info->dev;
494+
}
495+
496+
#if IS_ENABLED(CONFIG_NET_DSA)
497+
int register_dsa_notifier(struct notifier_block *nb);
498+
int unregister_dsa_notifier(struct notifier_block *nb);
499+
int call_dsa_notifiers(unsigned long val, struct net_device *dev,
500+
struct dsa_notifier_info *info);
501+
#else
502+
static inline int register_dsa_notifier(struct notifier_block *nb)
503+
{
504+
return 0;
505+
}
506+
507+
static inline int unregister_dsa_notifier(struct notifier_block *nb)
508+
{
509+
return 0;
510+
}
511+
512+
static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
513+
struct dsa_notifier_info *info)
514+
{
515+
return NOTIFY_DONE;
516+
}
517+
#endif
518+
474519
#endif

net/dsa/dsa.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/platform_device.h>
1515
#include <linux/slab.h>
1616
#include <linux/module.h>
17+
#include <linux/notifier.h>
1718
#include <linux/of.h>
1819
#include <linux/of_mdio.h>
1920
#include <linux/of_platform.h>
@@ -261,6 +262,28 @@ bool dsa_schedule_work(struct work_struct *work)
261262
return queue_work(dsa_owq, work);
262263
}
263264

265+
static ATOMIC_NOTIFIER_HEAD(dsa_notif_chain);
266+
267+
int register_dsa_notifier(struct notifier_block *nb)
268+
{
269+
return atomic_notifier_chain_register(&dsa_notif_chain, nb);
270+
}
271+
EXPORT_SYMBOL_GPL(register_dsa_notifier);
272+
273+
int unregister_dsa_notifier(struct notifier_block *nb)
274+
{
275+
return atomic_notifier_chain_unregister(&dsa_notif_chain, nb);
276+
}
277+
EXPORT_SYMBOL_GPL(unregister_dsa_notifier);
278+
279+
int call_dsa_notifiers(unsigned long val, struct net_device *dev,
280+
struct dsa_notifier_info *info)
281+
{
282+
info->dev = dev;
283+
return atomic_notifier_call_chain(&dsa_notif_chain, val, info);
284+
}
285+
EXPORT_SYMBOL_GPL(call_dsa_notifiers);
286+
264287
static int __init dsa_init_module(void)
265288
{
266289
int rc;

net/dsa/slave.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ int dsa_slave_resume(struct net_device *slave_dev)
11161116

11171117
int dsa_slave_create(struct dsa_port *port, const char *name)
11181118
{
1119+
struct dsa_notifier_register_info rinfo = { };
11191120
struct dsa_switch *ds = port->ds;
11201121
struct net_device *master;
11211122
struct net_device *slave_dev;
@@ -1177,6 +1178,12 @@ int dsa_slave_create(struct dsa_port *port, const char *name)
11771178
goto out_free;
11781179
}
11791180

1181+
rinfo.info.dev = slave_dev;
1182+
rinfo.master = master;
1183+
rinfo.port_number = p->dp->index;
1184+
rinfo.switch_number = p->dp->ds->index;
1185+
call_dsa_notifiers(DSA_PORT_REGISTER, slave_dev, &rinfo.info);
1186+
11801187
ret = register_netdev(slave_dev);
11811188
if (ret) {
11821189
netdev_err(master, "error %d registering interface %s\n",
@@ -1200,6 +1207,7 @@ int dsa_slave_create(struct dsa_port *port, const char *name)
12001207
void dsa_slave_destroy(struct net_device *slave_dev)
12011208
{
12021209
struct dsa_slave_priv *p = netdev_priv(slave_dev);
1210+
struct dsa_notifier_register_info rinfo = { };
12031211
struct device_node *port_dn;
12041212

12051213
port_dn = p->dp->dn;
@@ -1211,6 +1219,11 @@ void dsa_slave_destroy(struct net_device *slave_dev)
12111219
if (of_phy_is_fixed_link(port_dn))
12121220
of_phy_deregister_fixed_link(port_dn);
12131221
}
1222+
rinfo.info.dev = slave_dev;
1223+
rinfo.master = p->dp->cpu_dp->netdev;
1224+
rinfo.port_number = p->dp->index;
1225+
rinfo.switch_number = p->dp->ds->index;
1226+
call_dsa_notifiers(DSA_PORT_UNREGISTER, slave_dev, &rinfo.info);
12141227
unregister_netdev(slave_dev);
12151228
free_percpu(p->stats64);
12161229
free_netdev(slave_dev);

0 commit comments

Comments
 (0)