netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, mlxsw@mellanox.com,
	jakub.kicinski@netronome.com, sthemmin@microsoft.com,
	dsahern@gmail.com, saeedm@mellanox.com, leon@kernel.org,
	f.fainelli@gmail.com
Subject: [patch net-next v3 7/8] netdevsim: implement fake flash updating with notifications
Date: Tue,  4 Jun 2019 15:40:43 +0200	[thread overview]
Message-ID: <20190604134044.2613-8-jiri@resnulli.us> (raw)
In-Reply-To: <20190604134044.2613-1-jiri@resnulli.us>

From: Jiri Pirko <jiri@mellanox.com>

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
v1->v2:
- added debugfs toggle to enable/disable flash status notifications
---
 drivers/net/netdevsim/dev.c       | 44 +++++++++++++++++++++++++++++++
 drivers/net/netdevsim/netdevsim.h |  1 +
 2 files changed, 45 insertions(+)

diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index b509b941d5ca..c5c417a3c0ce 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -38,6 +38,8 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
 	nsim_dev->ports_ddir = debugfs_create_dir("ports", nsim_dev->ddir);
 	if (IS_ERR_OR_NULL(nsim_dev->ports_ddir))
 		return PTR_ERR_OR_ZERO(nsim_dev->ports_ddir) ?: -EINVAL;
+	debugfs_create_bool("fw_update_status", 0600, nsim_dev->ddir,
+			    &nsim_dev->fw_update_status);
 	return 0;
 }
 
@@ -220,8 +222,49 @@ static int nsim_dev_reload(struct devlink *devlink,
 	return 0;
 }
 
+#define NSIM_DEV_FLASH_SIZE 500000
+#define NSIM_DEV_FLASH_CHUNK_SIZE 1000
+#define NSIM_DEV_FLASH_CHUNK_TIME_MS 10
+
+static int nsim_dev_flash_update(struct devlink *devlink, const char *file_name,
+				 const char *component,
+				 struct netlink_ext_ack *extack)
+{
+	struct nsim_dev *nsim_dev = devlink_priv(devlink);
+	int i;
+
+	if (nsim_dev->fw_update_status) {
+		devlink_flash_update_begin_notify(devlink);
+		devlink_flash_update_status_notify(devlink,
+						   "Preparing to flash",
+						   component, 0, 0);
+	}
+
+	for (i = 0; i < NSIM_DEV_FLASH_SIZE / NSIM_DEV_FLASH_CHUNK_SIZE; i++) {
+		if (nsim_dev->fw_update_status)
+			devlink_flash_update_status_notify(devlink, "Flashing",
+							   component,
+							   i * NSIM_DEV_FLASH_CHUNK_SIZE,
+							   NSIM_DEV_FLASH_SIZE);
+		msleep(NSIM_DEV_FLASH_CHUNK_TIME_MS);
+	}
+
+	if (nsim_dev->fw_update_status) {
+		devlink_flash_update_status_notify(devlink, "Flashing",
+						   component,
+						   NSIM_DEV_FLASH_SIZE,
+						   NSIM_DEV_FLASH_SIZE);
+		devlink_flash_update_status_notify(devlink, "Flashing done",
+						   component, 0, 0);
+		devlink_flash_update_end_notify(devlink);
+	}
+
+	return 0;
+}
+
 static const struct devlink_ops nsim_dev_devlink_ops = {
 	.reload = nsim_dev_reload,
+	.flash_update = nsim_dev_flash_update,
 };
 
 static struct nsim_dev *
@@ -240,6 +283,7 @@ nsim_dev_create(struct nsim_bus_dev *nsim_bus_dev, unsigned int port_count)
 	get_random_bytes(nsim_dev->switch_id.id, nsim_dev->switch_id.id_len);
 	INIT_LIST_HEAD(&nsim_dev->port_list);
 	mutex_init(&nsim_dev->port_list_lock);
+	nsim_dev->fw_update_status = true;
 
 	nsim_dev->fib_data = nsim_fib_create();
 	if (IS_ERR(nsim_dev->fib_data)) {
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 3f398797c2bc..79c05af2a7c0 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -157,6 +157,7 @@ struct nsim_dev {
 	struct netdev_phys_item_id switch_id;
 	struct list_head port_list;
 	struct mutex port_list_lock; /* protects port list */
+	bool fw_update_status;
 };
 
 int nsim_dev_init(void);
-- 
2.17.2


  parent reply	other threads:[~2019-06-04 13:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 13:40 [patch net-next v3 0/8] expose flash update status to user Jiri Pirko
2019-06-04 13:40 ` [patch net-next v3 1/8] mlxsw: Move firmware flash implementation to devlink Jiri Pirko
2019-06-04 13:40 ` [patch net-next v3 2/8] mlx5: " Jiri Pirko
2019-06-04 18:40   ` Saeed Mahameed
2019-06-04 13:40 ` [patch net-next v3 3/8] mlxfw: Propagate error messages through extack Jiri Pirko
2019-06-04 13:40 ` [patch net-next v3 4/8] devlink: allow driver to update progress of flash update Jiri Pirko
2019-06-04 13:40 ` [patch net-next v3 5/8] mlxfw: Introduce status_notify op and call it to notify about the status Jiri Pirko
2019-06-04 13:40 ` [patch net-next v3 6/8] mlxsw: Implement flash update status notifications Jiri Pirko
2019-06-04 13:40 ` Jiri Pirko [this message]
2019-06-04 17:54   ` [patch net-next v3 7/8] netdevsim: implement fake flash updating with notifications Jakub Kicinski
2019-06-04 13:40 ` [patch net-next v3 8/8] selftests: add basic netdevsim devlink flash testing Jiri Pirko
2019-06-04 17:55   ` Jakub Kicinski
2019-06-04 13:44 ` [patch net-next v3 1/3] header update Jiri Pirko
2019-06-04 13:54   ` Jiri Pirko
2019-06-04 13:44 ` [patch net-next v3 2/3] devlink: implement flash update status monitoring Jiri Pirko
2019-06-04 13:44 ` [patch net-next v3 3/3] devlink: implement flash " Jiri Pirko
2019-06-10 17:09   ` David Ahern
2019-06-10 17:24     ` Jakub Kicinski
2019-06-10 17:30       ` David Ahern
2019-06-10 17:47         ` Jakub Kicinski
2019-06-10 21:56           ` David Ahern
2019-06-10 22:06             ` Jakub Kicinski
2019-06-04 15:09 ` [patch net-next v3 0/8] expose flash update status to user Alexei Starovoitov
2019-06-04 21:21 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190604134044.2613-8-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=leon@kernel.org \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=sthemmin@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).