Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "netdevsim.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) nsim_dev_empty_reporter_dump(struct devlink_health_reporter *reporter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 			     struct devlink_fmsg *fmsg, void *priv_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 			     struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) nsim_dev_empty_reporter_diagnose(struct devlink_health_reporter *reporter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 				 struct devlink_fmsg *fmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 				 struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct devlink_health_reporter_ops nsim_dev_empty_reporter_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.name = "empty",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.dump = nsim_dev_empty_reporter_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.diagnose = nsim_dev_empty_reporter_diagnose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) struct nsim_dev_dummy_reporter_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	char *break_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) nsim_dev_dummy_reporter_recover(struct devlink_health_reporter *reporter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 				void *priv_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 				struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct nsim_dev_dummy_reporter_ctx *ctx = priv_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (health->fail_recover) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		/* For testing purposes, user set debugfs fail_recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		 * value to true. Fail right away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		NL_SET_ERR_MSG_MOD(extack, "User setup the recover to fail for testing purposes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		kfree(health->recovered_break_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		health->recovered_break_msg = kstrdup(ctx->break_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 						      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		if (!health->recovered_break_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int nsim_dev_dummy_fmsg_put(struct devlink_fmsg *fmsg, u32 binary_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	char *binary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	err = devlink_fmsg_bool_pair_put(fmsg, "test_bool", true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	err = devlink_fmsg_u8_pair_put(fmsg, "test_u8", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	err = devlink_fmsg_u32_pair_put(fmsg, "test_u32", 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	err = devlink_fmsg_u64_pair_put(fmsg, "test_u64", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	err = devlink_fmsg_string_pair_put(fmsg, "test_string", "somestring");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	binary = kmalloc(binary_len, GFP_KERNEL | __GFP_NOWARN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!binary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	get_random_bytes(binary, binary_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	err = devlink_fmsg_binary_pair_put(fmsg, "test_binary", binary, binary_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	kfree(binary);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	err = devlink_fmsg_pair_nest_start(fmsg, "test_nest");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	err = devlink_fmsg_obj_nest_start(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	err = devlink_fmsg_bool_pair_put(fmsg, "nested_test_bool", false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	err = devlink_fmsg_u8_pair_put(fmsg, "nested_test_u8", false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	err = devlink_fmsg_obj_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	err = devlink_fmsg_pair_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_bool_array");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		err = devlink_fmsg_bool_put(fmsg, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	err = devlink_fmsg_arr_pair_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_u8_array");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		err = devlink_fmsg_u8_put(fmsg, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	err = devlink_fmsg_arr_pair_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_u32_array");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		err = devlink_fmsg_u32_put(fmsg, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	err = devlink_fmsg_arr_pair_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_u64_array");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		err = devlink_fmsg_u64_put(fmsg, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	err = devlink_fmsg_arr_pair_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	err = devlink_fmsg_arr_pair_nest_start(fmsg, "test_array_of_objects");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		err = devlink_fmsg_obj_nest_start(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		err = devlink_fmsg_bool_pair_put(fmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 						 "in_array_nested_test_bool",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 						 false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		err = devlink_fmsg_u8_pair_put(fmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 					       "in_array_nested_test_u8",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 					       i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		err = devlink_fmsg_obj_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return devlink_fmsg_arr_pair_nest_end(fmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) nsim_dev_dummy_reporter_dump(struct devlink_health_reporter *reporter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			     struct devlink_fmsg *fmsg, void *priv_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			     struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct nsim_dev_dummy_reporter_ctx *ctx = priv_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		err = devlink_fmsg_string_pair_put(fmsg, "break_message",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 						   ctx->break_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return nsim_dev_dummy_fmsg_put(fmsg, health->binary_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) nsim_dev_dummy_reporter_diagnose(struct devlink_health_reporter *reporter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 				 struct devlink_fmsg *fmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				 struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct nsim_dev_health *health = devlink_health_reporter_priv(reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (health->recovered_break_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		err = devlink_fmsg_string_pair_put(fmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 						   "recovered_break_message",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 						   health->recovered_break_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return nsim_dev_dummy_fmsg_put(fmsg, health->binary_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static const
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct devlink_health_reporter_ops nsim_dev_dummy_reporter_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.name = "dummy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.recover = nsim_dev_dummy_reporter_recover,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.dump = nsim_dev_dummy_reporter_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	.diagnose = nsim_dev_dummy_reporter_diagnose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static ssize_t nsim_dev_health_break_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 					   const char __user *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					   size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct nsim_dev_health *health = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct nsim_dev_dummy_reporter_ctx ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	char *break_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	break_msg = kmalloc(count + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (!break_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (copy_from_user(break_msg, data, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	break_msg[count] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (break_msg[count - 1] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		break_msg[count - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	ctx.break_msg = break_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	err = devlink_health_report(health->dummy_reporter, break_msg, &ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	kfree(break_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return err ?: count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static const struct file_operations nsim_dev_health_break_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	.open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	.write = nsim_dev_health_break_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct nsim_dev_health *health = &nsim_dev->health;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	health->empty_reporter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		devlink_health_reporter_create(devlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 					       &nsim_dev_empty_reporter_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 					       0, health);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (IS_ERR(health->empty_reporter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return PTR_ERR(health->empty_reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	health->dummy_reporter =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		devlink_health_reporter_create(devlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 					       &nsim_dev_dummy_reporter_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 					       0, health);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (IS_ERR(health->dummy_reporter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		err = PTR_ERR(health->dummy_reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		goto err_empty_reporter_destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	health->ddir = debugfs_create_dir("health", nsim_dev->ddir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (IS_ERR(health->ddir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		err = PTR_ERR(health->ddir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		goto err_dummy_reporter_destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	health->recovered_break_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	debugfs_create_file("break_health", 0200, health->ddir, health,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			    &nsim_dev_health_break_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	health->binary_len = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	debugfs_create_u32("binary_len", 0600, health->ddir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			   &health->binary_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	health->fail_recover = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	debugfs_create_bool("fail_recover", 0600, health->ddir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			    &health->fail_recover);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) err_dummy_reporter_destroy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	devlink_health_reporter_destroy(health->dummy_reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) err_empty_reporter_destroy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	devlink_health_reporter_destroy(health->empty_reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) void nsim_dev_health_exit(struct nsim_dev *nsim_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct nsim_dev_health *health = &nsim_dev->health;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	debugfs_remove_recursive(health->ddir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	kfree(health->recovered_break_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	devlink_health_reporter_destroy(health->dummy_reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	devlink_health_reporter_destroy(health->empty_reporter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }