summaryrefslogtreecommitdiffstats
path: root/drivers/net/netdevsim
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-07-17 10:53:19 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-18 15:10:33 +0200
commit5f07655b803eca4c215bac9aa61f4bf19f6ecd5e (patch)
tree4e794f76343c9b2843f6ec362aeefdd5431d335c /drivers/net/netdevsim
parentc23e014a4ba1a9448cbbd74916377f23a7da2fc2 (diff)
downloadlinux-5f07655b803eca4c215bac9aa61f4bf19f6ecd5e.tar.gz
linux-5f07655b803eca4c215bac9aa61f4bf19f6ecd5e.tar.bz2
linux-5f07655b803eca4c215bac9aa61f4bf19f6ecd5e.zip
netdevsim: add switch_id attribute
Grouping netdevsim devices into "ASICs" will soon be supported. Add switch_id attribute to all netdevsims. For now each netdevsim will have its switch_id matching the device id. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'drivers/net/netdevsim')
-rw-r--r--drivers/net/netdevsim/netdev.c24
-rw-r--r--drivers/net/netdevsim/netdevsim.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index a7b179f0d954..9125637ef5d8 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -22,6 +22,7 @@
#include <net/netlink.h>
#include <net/pkt_cls.h>
#include <net/rtnetlink.h>
+#include <net/switchdev.h>
#include "netdevsim.h"
@@ -144,12 +145,34 @@ static struct device_type nsim_dev_type = {
.release = nsim_dev_release,
};
+static int
+nsim_port_attr_get(struct net_device *dev, struct switchdev_attr *attr)
+{
+ struct netdevsim *ns = netdev_priv(dev);
+
+ switch (attr->id) {
+ case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
+ attr->u.ppid.id_len = sizeof(ns->switch_id);
+ memcpy(&attr->u.ppid.id, &ns->switch_id,
+ attr->u.ppid.id_len);
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static const struct switchdev_ops nsim_switchdev_ops = {
+ .switchdev_port_attr_get = nsim_port_attr_get,
+};
+
static int nsim_init(struct net_device *dev)
{
struct netdevsim *ns = netdev_priv(dev);
int err;
ns->netdev = dev;
+ ns->switch_id = nsim_dev_id;
+
ns->ddir = debugfs_create_dir(netdev_name(dev), nsim_ddir);
if (IS_ERR_OR_NULL(ns->ddir))
return -ENOMEM;
@@ -166,6 +189,7 @@ static int nsim_init(struct net_device *dev)
goto err_bpf_uninit;
SET_NETDEV_DEV(dev, &ns->dev);
+ SWITCHDEV_SET_OPS(dev, &nsim_switchdev_ops);
err = nsim_devlink_setup(ns);
if (err)
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 0aeabbe81cc6..e2f232325259 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -59,6 +59,7 @@ struct netdevsim {
struct u64_stats_sync syncp;
struct device dev;
+ u32 switch_id;
struct dentry *ddir;