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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *   Branden Bonaby <brandonbonaby94@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/hyperv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "hyperv_vmbus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static struct dentry *hv_debug_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static int hv_debugfs_delay_get(void *data, u64 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	*val = *(u32 *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static int hv_debugfs_delay_set(void *data, u64 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (val > 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	*(u32 *)data = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) DEFINE_DEBUGFS_ATTRIBUTE(hv_debugfs_delay_fops, hv_debugfs_delay_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			 hv_debugfs_delay_set, "%llu\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int hv_debugfs_state_get(void *data, u64 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	*val = *(bool *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int hv_debugfs_state_set(void *data, u64 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (val == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		*(bool *)data = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	else if (val == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		*(bool *)data = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) DEFINE_DEBUGFS_ATTRIBUTE(hv_debugfs_state_fops, hv_debugfs_state_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			 hv_debugfs_state_set, "%llu\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* Setup delay files to store test values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static int hv_debug_delay_files(struct hv_device *dev, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct vmbus_channel *channel = dev->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	char *buffer = "fuzz_test_buffer_interrupt_delay";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	char *message = "fuzz_test_message_delay";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int *buffer_val = &channel->fuzz_testing_interrupt_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int *message_val = &channel->fuzz_testing_message_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct dentry *buffer_file, *message_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	buffer_file = debugfs_create_file(buffer, 0644, root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 					  buffer_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 					  &hv_debugfs_delay_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (IS_ERR(buffer_file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		pr_debug("debugfs_hyperv: file %s not created\n", buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return PTR_ERR(buffer_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	message_file = debugfs_create_file(message, 0644, root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 					   message_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 					   &hv_debugfs_delay_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (IS_ERR(message_file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		pr_debug("debugfs_hyperv: file %s not created\n", message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return PTR_ERR(message_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /* Setup test state value for vmbus device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int hv_debug_set_test_state(struct hv_device *dev, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct vmbus_channel *channel = dev->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	bool *state = &channel->fuzz_testing_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	char *status = "fuzz_test_state";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct dentry *test_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	test_state = debugfs_create_file(status, 0644, root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 					 state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 					 &hv_debugfs_state_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (IS_ERR(test_state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		pr_debug("debugfs_hyperv: file %s not created\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return PTR_ERR(test_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Bind hv device to a dentry for debugfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static void hv_debug_set_dir_dentry(struct hv_device *dev, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (hv_debug_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		dev->debug_dir = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* Create all test dentry's and names for fuzz testing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int hv_debug_add_dev_dir(struct hv_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	const char *device = dev_name(&dev->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	char *delay_name = "delay";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct dentry *delay, *dev_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (!IS_ERR(hv_debug_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		dev_root = debugfs_create_dir(device, hv_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (IS_ERR(dev_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			pr_debug("debugfs_hyperv: hyperv/%s/ not created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				 device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			return PTR_ERR(dev_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		hv_debug_set_test_state(dev, dev_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		hv_debug_set_dir_dentry(dev, dev_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		delay = debugfs_create_dir(delay_name, dev_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (IS_ERR(delay)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			pr_debug("debugfs_hyperv: hyperv/%s/%s/ not created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				 device, delay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			return PTR_ERR(delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		ret = hv_debug_delay_files(dev, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	pr_debug("debugfs_hyperv: hyperv/ not in root debugfs path\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return PTR_ERR(hv_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* Remove dentry associated with released hv device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) void hv_debug_rm_dev_dir(struct hv_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!IS_ERR(hv_debug_root))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		debugfs_remove_recursive(dev->debug_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* Remove all dentrys associated with vmbus testing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) void hv_debug_rm_all_dir(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	debugfs_remove_recursive(hv_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* Delay buffer/message reads on a vmbus channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) void hv_debug_delay_test(struct vmbus_channel *channel, enum delay delay_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct vmbus_channel *test_channel =    channel->primary_channel ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 						channel->primary_channel :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 						channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	bool state = test_channel->fuzz_testing_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (delay_type == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			udelay(test_channel->fuzz_testing_interrupt_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			udelay(test_channel->fuzz_testing_message_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* Initialize top dentry for vmbus testing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int hv_debug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	hv_debug_root = debugfs_create_dir("hyperv", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (IS_ERR(hv_debug_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		pr_debug("debugfs_hyperv: hyperv/ not created\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return PTR_ERR(hv_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }