xref: /wlan-driver/qcacld-3.0/core/hdd/src/wlan_hdd_sysfs_wlan_dbg.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /**
18  * DOC: wlan_hdd_sysfs_wlan_dbg.c
19  *
20  * Implementation for creating sysfs file wlan_dbg
21  */
22 
23 #include <wlan_hdd_includes.h>
24 #include "osif_psoc_sync.h"
25 #include <wlan_hdd_sysfs.h>
26 #include <wlan_hdd_sysfs_wlan_dbg.h>
27 
28 static ssize_t
__hdd_sysfs_wlan_dbg_store(struct hdd_context * hdd_ctx,struct kobj_attribute * attr,const char * buf,size_t count)29 __hdd_sysfs_wlan_dbg_store(struct hdd_context *hdd_ctx,
30 			   struct kobj_attribute *attr,
31 			       const char *buf, size_t count)
32 {
33 	char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1];
34 	char *sptr, *token;
35 	uint32_t val1, val2, val3;
36 	int ret;
37 
38 	if (!wlan_hdd_validate_modules_state(hdd_ctx))
39 		return -EINVAL;
40 
41 	ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
42 					      buf, count);
43 	if (ret) {
44 		hdd_err_rl("invalid input");
45 		return ret;
46 	}
47 
48 	sptr = buf_local;
49 	hdd_debug("set_wlan_dbg: count %zu buf_local:(%s)",
50 		  count, buf_local);
51 
52 	/* Get val1 */
53 	token = strsep(&sptr, " ");
54 	if (!token)
55 		return -EINVAL;
56 	if (kstrtou32(token, 0, &val1))
57 		return -EINVAL;
58 
59 	/* Get val2 */
60 	token = strsep(&sptr, " ");
61 	if (!token)
62 		return -EINVAL;
63 	if (kstrtou32(token, 0, &val2))
64 		return -EINVAL;
65 
66 	/* Get val3 */
67 	token = strsep(&sptr, " ");
68 	if (!token)
69 		return -EINVAL;
70 	if (kstrtou32(token, 0, &val3))
71 		return -EINVAL;
72 
73 	qdf_print_set_category_verbose(qdf_get_pidx(), val1, val2, val3);
74 
75 	return count;
76 }
77 
78 static ssize_t
hdd_sysfs_wlan_dbg_store(struct kobject * kobj,struct kobj_attribute * attr,const char * buf,size_t count)79 hdd_sysfs_wlan_dbg_store(struct kobject *kobj,
80 			 struct kobj_attribute *attr,
81 			 const char *buf, size_t count)
82 {
83 	struct osif_psoc_sync *psoc_sync;
84 	struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
85 	ssize_t errno_size;
86 	int ret;
87 
88 	ret = wlan_hdd_validate_context(hdd_ctx);
89 	if (ret)
90 		return ret;
91 
92 	errno_size = osif_psoc_sync_op_start(wiphy_dev(hdd_ctx->wiphy),
93 					     &psoc_sync);
94 	if (errno_size)
95 		return errno_size;
96 
97 	errno_size = __hdd_sysfs_wlan_dbg_store(hdd_ctx, attr,
98 						buf, count);
99 
100 	osif_psoc_sync_op_stop(psoc_sync);
101 
102 	return errno_size;
103 }
104 
105 static struct kobj_attribute set_wlan_dbg_attribute =
106 	__ATTR(wlan_dbg, 0220, NULL,
107 	       hdd_sysfs_wlan_dbg_store);
108 
hdd_sysfs_wlan_dbg_create(struct kobject * driver_kobject)109 int hdd_sysfs_wlan_dbg_create(struct kobject *driver_kobject)
110 {
111 	int error;
112 
113 	if (!driver_kobject) {
114 		hdd_err("could not get driver kobject!");
115 		return -EINVAL;
116 	}
117 
118 	error = sysfs_create_file(driver_kobject,
119 				  &set_wlan_dbg_attribute.attr);
120 	if (error)
121 		hdd_err("could not create wlan_dbg sysfs file");
122 
123 	return error;
124 }
125 
126 void
hdd_sysfs_wlan_dbg_destroy(struct kobject * driver_kobject)127 hdd_sysfs_wlan_dbg_destroy(struct kobject *driver_kobject)
128 {
129 	if (!driver_kobject) {
130 		hdd_err("could not get driver kobject!");
131 		return;
132 	}
133 	sysfs_remove_file(driver_kobject, &set_wlan_dbg_attribute.attr);
134 }
135