[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210113121222.733517-10-jiri@resnulli.us>
Date: Wed, 13 Jan 2021 13:12:21 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, kuba@...nel.org, jacob.e.keller@...el.com,
roopa@...dia.com, mlxsw@...dia.com
Subject: [patch net-next RFC 09/10] netdevsim: implement line card activation
From: Jiri Pirko <jiri@...dia.com>
On real HW, the activation typically happens upon line card insertion.
Emulate such event using write to debugfs file "active".
Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
drivers/net/netdevsim/dev.c | 81 +++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index 9e9a2a75ddf8..81d68269e121 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -64,6 +64,30 @@ nsim_dev_port_index(struct nsim_dev_linecard *nsim_dev_linecard,
port_index;
}
+static int
+nsim_dev_linecard_activate(struct nsim_dev_linecard *nsim_dev_linecard)
+{
+ struct nsim_dev_port *nsim_dev_port;
+
+ list_for_each_entry(nsim_dev_port, &nsim_dev_linecard->port_list,
+ list_lc)
+ netif_carrier_on(nsim_dev_port->ns->netdev);
+
+ devlink_linecard_activate(nsim_dev_linecard->devlink_linecard);
+ return 0;
+}
+
+static void
+nsim_dev_linecard_deactivate(struct nsim_dev_linecard *nsim_dev_linecard)
+{
+ struct nsim_dev_port *nsim_dev_port;
+
+ list_for_each_entry(nsim_dev_port, &nsim_dev_linecard->port_list,
+ list_lc)
+ netif_carrier_off(nsim_dev_port->ns->netdev);
+ devlink_linecard_deactivate(nsim_dev_linecard->devlink_linecard);
+}
+
static struct dentry *nsim_dev_ddir;
#define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32)
@@ -299,6 +323,61 @@ static void nsim_dev_port_debugfs_exit(struct nsim_dev_port *nsim_dev_port)
debugfs_remove_recursive(nsim_dev_port->ddir);
}
+static ssize_t nsim_dev_linecard_active_read(struct file *file,
+ char __user *data,
+ size_t count, loff_t *ppos)
+{
+ struct nsim_dev_linecard *nsim_dev_linecard = file->private_data;
+ char buf[3];
+
+ if (!nsim_dev_linecard->provisioned)
+ return -EOPNOTSUPP;
+
+ if (devlink_linecard_is_active(nsim_dev_linecard->devlink_linecard))
+ buf[0] = 'Y';
+ else
+ buf[0] = 'N';
+ buf[1] = '\n';
+ buf[2] = 0x00;
+ return simple_read_from_buffer(data, count, ppos, buf, strlen(buf));
+}
+
+static ssize_t nsim_dev_linecard_active_write(struct file *file,
+ const char __user *data,
+ size_t count, loff_t *ppos)
+{
+ struct nsim_dev_linecard *nsim_dev_linecard = file->private_data;
+ bool active;
+ bool bv;
+ int err;
+ int r;
+
+ if (!nsim_dev_linecard->provisioned)
+ return -EOPNOTSUPP;
+
+ active = devlink_linecard_is_active(nsim_dev_linecard->devlink_linecard);
+
+ r = kstrtobool_from_user(data, count, &bv);
+ if (!r && active != bv) {
+ if (bv) {
+ err = nsim_dev_linecard_activate(nsim_dev_linecard);
+ if (err)
+ return err;
+ } else {
+ nsim_dev_linecard_deactivate(nsim_dev_linecard);
+ }
+ }
+ return count;
+}
+
+static const struct file_operations nsim_dev_linecard_active_fops = {
+ .open = simple_open,
+ .read = nsim_dev_linecard_active_read,
+ .write = nsim_dev_linecard_active_write,
+ .llseek = generic_file_llseek,
+ .owner = THIS_MODULE,
+};
+
static ssize_t nsim_dev_linecard_type_read(struct file *file, char __user *data,
size_t count, loff_t *ppos)
{
@@ -334,6 +413,8 @@ nsim_dev_linecard_debugfs_init(struct nsim_dev *nsim_dev,
sprintf(dev_link_name, "../../../" DRV_NAME "%u",
nsim_dev->nsim_bus_dev->dev.id);
debugfs_create_symlink("dev", nsim_dev_linecard->ddir, dev_link_name);
+ debugfs_create_file("active", 0600, nsim_dev_linecard->ddir,
+ nsim_dev_linecard, &nsim_dev_linecard_active_fops);
debugfs_create_file("type", 0400, nsim_dev_linecard->ddir,
nsim_dev_linecard, &nsim_dev_linecard_type_fops);
--
2.26.2
Powered by blists - more mailing lists