summaryrefslogtreecommitdiffstats
path: root/drivers/net/netdevsim
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 17:39:57 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 17:39:57 +0000
commitdc50eab76b709d68175a358d6e23a5a3890764d3 (patch)
treec754d0390db060af0213ff994f0ac310e4cfd6e9 /drivers/net/netdevsim
parentAdding debian version 6.6.15-2. (diff)
downloadlinux-dc50eab76b709d68175a358d6e23a5a3890764d3.tar.xz
linux-dc50eab76b709d68175a358d6e23a5a3890764d3.zip
Merging upstream version 6.7.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/net/netdevsim')
-rw-r--r--drivers/net/netdevsim/bus.c12
-rw-r--r--drivers/net/netdevsim/dev.c8
-rw-r--r--drivers/net/netdevsim/health.c118
-rw-r--r--drivers/net/netdevsim/netdev.c1
4 files changed, 49 insertions, 90 deletions
diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index 0787ad252d..bcbc1e19ed 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -3,11 +3,13 @@
* Copyright (C) 2019 Mellanox Technologies. All rights reserved
*/
+#include <linux/completion.h>
#include <linux/device.h>
#include <linux/idr.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/mutex.h>
+#include <linux/refcount.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
@@ -17,6 +19,8 @@ static DEFINE_IDA(nsim_bus_dev_ids);
static LIST_HEAD(nsim_bus_dev_list);
static DEFINE_MUTEX(nsim_bus_dev_list_lock);
static bool nsim_bus_enable;
+static refcount_t nsim_bus_devs; /* Including the bus itself. */
+static DECLARE_COMPLETION(nsim_bus_devs_released);
static struct nsim_bus_dev *to_nsim_bus_dev(struct device *dev)
{
@@ -121,6 +125,8 @@ static void nsim_bus_dev_release(struct device *dev)
nsim_bus_dev = container_of(dev, struct nsim_bus_dev, dev);
kfree(nsim_bus_dev);
+ if (refcount_dec_and_test(&nsim_bus_devs))
+ complete(&nsim_bus_devs_released);
}
static struct device_type nsim_bus_dev_type = {
@@ -170,6 +176,7 @@ new_device_store(const struct bus_type *bus, const char *buf, size_t count)
goto err;
}
+ refcount_inc(&nsim_bus_devs);
/* Allow using nsim_bus_dev */
smp_store_release(&nsim_bus_dev->init, true);
@@ -326,6 +333,7 @@ int nsim_bus_init(void)
err = driver_register(&nsim_driver);
if (err)
goto err_bus_unregister;
+ refcount_set(&nsim_bus_devs, 1);
/* Allow using resources */
smp_store_release(&nsim_bus_enable, true);
return 0;
@@ -341,6 +349,8 @@ void nsim_bus_exit(void)
/* Disallow using resources */
smp_store_release(&nsim_bus_enable, false);
+ if (refcount_dec_and_test(&nsim_bus_devs))
+ complete(&nsim_bus_devs_released);
mutex_lock(&nsim_bus_dev_list_lock);
list_for_each_entry_safe(nsim_bus_dev, tmp, &nsim_bus_dev_list, list) {
@@ -349,6 +359,8 @@ void nsim_bus_exit(void)
}
mutex_unlock(&nsim_bus_dev_list_lock);
+ wait_for_completion(&nsim_bus_devs_released);
+
driver_unregister(&nsim_driver);
bus_unregister(&nsim_bus);
}
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index b4d3b9cde8..92a7a36b93 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -835,14 +835,14 @@ static void nsim_dev_trap_report_work(struct work_struct *work)
trap_report_dw.work);
nsim_dev = nsim_trap_data->nsim_dev;
- /* For each running port and enabled packet trap, generate a UDP
- * packet with a random 5-tuple and report it.
- */
if (!devl_trylock(priv_to_devlink(nsim_dev))) {
- schedule_delayed_work(&nsim_dev->trap_data->trap_report_dw, 0);
+ schedule_delayed_work(&nsim_dev->trap_data->trap_report_dw, 1);
return;
}
+ /* For each running port and enabled packet trap, generate a UDP
+ * packet with a random 5-tuple and report it.
+ */
list_for_each_entry(nsim_dev_port, &nsim_dev->port_list, list) {
if (!netif_running(nsim_dev_port->ns->netdev))
continue;
diff --git a/drivers/net/netdevsim/health.c b/drivers/net/netdevsim/health.c
index eb04ed715d..70e8bdf34b 100644
--- a/drivers/net/netdevsim/health.c
+++ b/drivers/net/netdevsim/health.c
@@ -63,91 +63,45 @@ nsim_dev_dummy_reporter_recover(struct devlink_health_reporter *reporter,
static int nsim_dev_dummy_fmsg_put(struct devlink_fmsg *fmsg, u32 binary_len)
{
char *binary;
- int err;
int i;
- err = devlink_fmsg_bool_pair_put(fmsg, "test_bool", true);
- if (err)
- return err;
- err = devlink_fmsg_u8_pair_put(fmsg, "test_u8", 1);
- if (err)
- return err;
- err = devlink_fmsg_u32_pair_put(fmsg, "test_u32", 3);
- if (err)
- return err;
- err = devlink_fmsg_u64_pair_put(fmsg, "test_u64", 4);
- if (err)
- return err;
- err = devlink_fmsg_string_pair_put(fmsg, "test_string", "somestring");
- if (err)
- return err;
+ devlink_fmsg_bool_pair_put(fmsg, "test_bool", true);
+ devlink_fmsg_u8_pair_put(fmsg, "test_u8", 1);
+ devlink_fmsg_u32_pair_put(fmsg, "test_u32", 3);
+ devlink_fmsg_u64_pair_put(fmsg, "test_u64", 4);
+ devlink_fmsg_string_pair_put(fmsg, "test_string", "somestring");
binary = kmalloc(binary_len, GFP_KERNEL | __GFP_NOWARN);
if (!binary)
return -ENOMEM;
get_random_bytes(binary, binary_len);
- err = devlink_fmsg_binary_pair_put(fmsg, "test_binary", binary, binary_len);
+ devlink_fmsg_binary_pair_put(fmsg, "test_binary", binary, binary_len);
kfree(binary);
- if (err)
- return err;
- err = devlink_fmsg_pair_nest_start(fmsg, "test_nest");
- if (err)
- return err;
- err = devlink_fmsg_obj_nest_start(fmsg);
- if (err)
- return err;
- err = devlink_fmsg_bool_pair_put(fmsg, "nested_test_bool", false);
- if (err)
- return err;
- err = devlink_fmsg_u8_pair_put(fmsg, "nested_test_u8", false);
- if (err)
- return err;
- err = devlink_fmsg_obj_nest_end(fmsg);
- if (err)
- return err;
- err = devlink_fmsg_pair_nest_end(fmsg);
- if (err)
- return err;
+ devlink_fmsg_pair_nest_start(fmsg, "test_nest");
+ devlink_fmsg_obj_nest_start(fmsg);
+ devlink_fmsg_bool_pair_put(fmsg, "nested_test_bool", false);
+ devlink_fmsg_u8_pair_put(fmsg, "nested_test_u8", false);
+ devlink_fmsg_obj_nest_end(fmsg);
+ devlink_fmsg_pair_nest_end(fmsg);
+ devlink_fmsg_arr_pair_nest_end(fmsg);
+ devlink_fmsg_arr_pair_nest_start(fmsg, "test_u32_array");
- err = devlink_fmsg_arr_pair_nest_end(fmsg);
- if (err)
- return err;
+ for (i = 0; i < 10; i++)
+ devlink_fmsg_u32_put(fmsg, i);
+ devlink_fmsg_arr_pair_nest_end(fmsg);
+ devlink_fmsg_arr_pair_nest_start(fmsg, "test_array_of_objects");
- err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_u32_array");
- if (err)
- return err;
for (i = 0; i < 10; i++) {
- err = devlink_fmsg_u32_put(fmsg, i);
- if (err)
- return err;
+ devlink_fmsg_obj_nest_start(fmsg);
+ devlink_fmsg_bool_pair_put(fmsg, "in_array_nested_test_bool",
+ false);
+ devlink_fmsg_u8_pair_put(fmsg, "in_array_nested_test_u8", i);
+ devlink_fmsg_obj_nest_end(fmsg);
}
- err = devlink_fmsg_arr_pair_nest_end(fmsg);
- if (err)
- return err;
+ devlink_fmsg_arr_pair_nest_end(fmsg);
- err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_array_of_objects");
- if (err)
- return err;
- for (i = 0; i < 10; i++) {
- err = devlink_fmsg_obj_nest_start(fmsg);
- if (err)
- return err;
- err = devlink_fmsg_bool_pair_put(fmsg,
- "in_array_nested_test_bool",
- false);
- if (err)
- return err;
- err = devlink_fmsg_u8_pair_put(fmsg,
- "in_array_nested_test_u8",
- i);
- if (err)
- return err;
- err = devlink_fmsg_obj_nest_end(fmsg);
- if (err)
- return err;
- }
- return devlink_fmsg_arr_pair_nest_end(fmsg);
+ return 0;
}
static int
@@ -157,14 +111,10 @@ nsim_dev_dummy_reporter_dump(struct devlink_health_reporter *reporter,
{
struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
struct nsim_dev_dummy_reporter_ctx *ctx = priv_ctx;
- int err;
- if (ctx) {
- err = devlink_fmsg_string_pair_put(fmsg, "break_message",
- ctx->break_msg);
- if (err)
- return err;
- }
+ if (ctx)
+ devlink_fmsg_string_pair_put(fmsg, "break_message", ctx->break_msg);
+
return nsim_dev_dummy_fmsg_put(fmsg, health->binary_len);
}
@@ -174,15 +124,11 @@ nsim_dev_dummy_reporter_diagnose(struct devlink_health_reporter *reporter,
struct netlink_ext_ack *extack)
{
struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
- int err;
- if (health->recovered_break_msg) {
- err = devlink_fmsg_string_pair_put(fmsg,
- "recovered_break_message",
- health->recovered_break_msg);
- if (err)
- return err;
- }
+ if (health->recovered_break_msg)
+ devlink_fmsg_string_pair_put(fmsg, "recovered_break_message",
+ health->recovered_break_msg);
+
return nsim_dev_dummy_fmsg_put(fmsg, health->binary_len);
}
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index d8ca82addf..77e8250282 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -475,4 +475,5 @@ static void __exit nsim_module_exit(void)
module_init(nsim_module_init);
module_exit(nsim_module_exit);
MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Simulated networking device for testing");
MODULE_ALIAS_RTNL_LINK(DRV_NAME);