xref: /wlan-driver/qcacld-3.0/core/hdd/src/wlan_hdd_sysfs_rf_test_mode.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. 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 #include <wlan_hdd_includes.h>
18 #include "osif_psoc_sync.h"
19 #include <wlan_hdd_sysfs.h>
20 #include <wlan_hdd_sysfs_rf_test_mode.h>
21 
22 #define RF_TEST_MODE_ENABLE 1
23 
__hdd_sysfs_rf_test_mode_show(struct hdd_context * hdd_ctx,struct kobj_attribute * attr,char * buf)24 static ssize_t __hdd_sysfs_rf_test_mode_show(struct hdd_context *hdd_ctx,
25 					     struct kobj_attribute *attr,
26 					     char *buf)
27 {
28 	int ret = 0;
29 	bool value;
30 
31 	if (!hdd_ctx || !hdd_ctx->psoc) {
32 		hdd_err_rl("invalid input");
33 		return ret;
34 	}
35 
36 	ret = scnprintf(buf, PAGE_SIZE, "0x%x",
37 			ucfg_mlme_is_rf_test_mode_enabled(hdd_ctx->psoc,
38 							  &value));
39 
40 	return ret;
41 }
42 
hdd_sysfs_rf_test_mode_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)43 static ssize_t hdd_sysfs_rf_test_mode_show(struct kobject *kobj,
44 					   struct kobj_attribute *attr,
45 					   char *buf)
46 {
47 	struct osif_psoc_sync *psoc_sync;
48 	struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
49 	ssize_t errno_size;
50 
51 	if (!hdd_ctx) {
52 		hdd_err_rl("invalid input");
53 		return -EINVAL;
54 	}
55 
56 	errno_size = osif_psoc_sync_op_start(wiphy_dev(hdd_ctx->wiphy),
57 					     &psoc_sync);
58 	if (errno_size)
59 		return errno_size;
60 
61 	errno_size = __hdd_sysfs_rf_test_mode_show(hdd_ctx, attr, buf);
62 
63 	osif_psoc_sync_op_stop(psoc_sync);
64 
65 	return errno_size;
66 }
67 
68 static ssize_t
__hdd_sysfs_rf_test_mode_store(struct hdd_context * hdd_ctx,struct kobj_attribute * attr,const char * buf,size_t count)69 __hdd_sysfs_rf_test_mode_store(struct hdd_context *hdd_ctx,
70 			       struct kobj_attribute *attr,
71 			       const char *buf, size_t count)
72 {
73 	char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1];
74 	char *sptr, *token;
75 	uint32_t value;
76 	int ret = 0;
77 
78 	if (!hdd_ctx || !hdd_ctx->psoc) {
79 		hdd_err_rl("invalid hdd ctx");
80 		return ret;
81 	}
82 
83 	ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
84 					      buf, count);
85 
86 	if (ret) {
87 		hdd_err_rl("invalid input");
88 		return ret;
89 	}
90 
91 	sptr = buf_local;
92 	token = strsep(&sptr, " ");
93 	if (!token)
94 		return -EINVAL;
95 	if (kstrtou32(token, 0, &value))
96 		return -EINVAL;
97 
98 	hdd_debug("rf_test_mode: 0x%x", value);
99 
100 	/*
101 	 * To enable rf_test_mode if value set is greater than one
102 	 * adjust this value as one by default
103 	 */
104 	if (value > RF_TEST_MODE_ENABLE)
105 		value = RF_TEST_MODE_ENABLE;
106 
107 	ucfg_mlme_set_rf_test_mode_enabled(hdd_ctx->psoc, value);
108 
109 	return count;
110 }
111 
112 static ssize_t
hdd_sysfs_rf_test_mode_store(struct kobject * kobj,struct kobj_attribute * attr,char const * buf,size_t count)113 hdd_sysfs_rf_test_mode_store(struct kobject *kobj,
114 			     struct kobj_attribute *attr,
115 			     char const *buf, size_t count)
116 {
117 	struct osif_psoc_sync *psoc_sync;
118 	struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
119 	ssize_t errno_size;
120 
121 	if (!hdd_ctx) {
122 		hdd_err_rl("invalid input");
123 		return -EINVAL;
124 	}
125 
126 	errno_size = osif_psoc_sync_op_start(wiphy_dev(hdd_ctx->wiphy),
127 					     &psoc_sync);
128 	if (errno_size)
129 		return errno_size;
130 
131 	errno_size = __hdd_sysfs_rf_test_mode_store(hdd_ctx, attr, buf,
132 						    count);
133 
134 	osif_psoc_sync_op_stop(psoc_sync);
135 
136 	return errno_size;
137 }
138 
139 static struct kobj_attribute rf_test_mode_attribute =
140 	__ATTR(rf_test_mode, 0664, hdd_sysfs_rf_test_mode_show,
141 	       hdd_sysfs_rf_test_mode_store);
142 
hdd_sysfs_rf_test_mode_create(struct kobject * driver_kobject)143 int hdd_sysfs_rf_test_mode_create(struct kobject *driver_kobject)
144 {
145 	int error;
146 
147 	if (!driver_kobject) {
148 		hdd_err("could not get driver kobject!");
149 		return -EINVAL;
150 	}
151 
152 	error = sysfs_create_file(driver_kobject,
153 				  &rf_test_mode_attribute.attr);
154 	if (error)
155 		hdd_err("could not create rf_test_mode sysfs file");
156 
157 	return error;
158 }
159 
160 void
hdd_sysfs_rf_test_mode_destroy(struct kobject * driver_kobject)161 hdd_sysfs_rf_test_mode_destroy(struct kobject *driver_kobject)
162 {
163 	if (!driver_kobject) {
164 		hdd_err("could not get driver kobject!");
165 		return;
166 	}
167 	sysfs_remove_file(driver_kobject, &rf_test_mode_attribute.attr);
168 }
169