1 /*
2  * Copyright (c) 2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: wlan_hdd_sysfs_dp_aggregation.c
20  *
21  * implementation for creating sysfs files:
22  *
23  * dp_aggregation
24  */
25 
26 #include <wlan_hdd_includes.h>
27 #include "osif_psoc_sync.h"
28 #include <wlan_hdd_sysfs.h>
29 #include <wlan_hdd_sysfs_dp_aggregation.h>
30 #include "wlan_dp_ucfg_api.h"
31 
32 static ssize_t
__hdd_sysfs_dp_aggregation_show(struct hdd_context * hdd_ctx,struct kobj_attribute * attr,char * buf)33 __hdd_sysfs_dp_aggregation_show(struct hdd_context *hdd_ctx,
34 				struct kobj_attribute *attr, char *buf)
35 {
36 	if (!wlan_hdd_validate_modules_state(hdd_ctx))
37 		return -EINVAL;
38 
39 	hdd_debug("dp_aggregation: %d",
40 		  ucfg_dp_get_rx_aggregation_val(hdd_ctx->psoc));
41 
42 	return 0;
43 }
44 
hdd_sysfs_dp_aggregation_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)45 static ssize_t hdd_sysfs_dp_aggregation_show(struct kobject *kobj,
46 					     struct kobj_attribute *attr,
47 					     char *buf)
48 {
49 	struct osif_psoc_sync *psoc_sync;
50 	struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
51 	ssize_t errno_size;
52 	int ret;
53 
54 	ret = wlan_hdd_validate_context(hdd_ctx);
55 	if (ret != 0)
56 		return ret;
57 
58 	errno_size = osif_psoc_sync_op_start(wiphy_dev(hdd_ctx->wiphy),
59 					     &psoc_sync);
60 	if (errno_size)
61 		return errno_size;
62 
63 	errno_size = __hdd_sysfs_dp_aggregation_show(hdd_ctx, attr, buf);
64 
65 	osif_psoc_sync_op_stop(psoc_sync);
66 
67 	return errno_size;
68 }
69 
70 static ssize_t
__hdd_sysfs_dp_aggregation_store(struct hdd_context * hdd_ctx,struct kobj_attribute * attr,const char * buf,size_t count)71 __hdd_sysfs_dp_aggregation_store(struct hdd_context *hdd_ctx,
72 				 struct kobj_attribute *attr, const char *buf,
73 				 size_t count)
74 {
75 	char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1];
76 	char *sptr, *token;
77 	uint32_t value;
78 	int ret;
79 
80 	if (!wlan_hdd_validate_modules_state(hdd_ctx))
81 		return -EINVAL;
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("dp_aggregation: %d", value);
99 
100 	ucfg_dp_rx_skip_fisa(value);
101 	ucfg_dp_set_rx_aggregation_val(hdd_ctx->psoc, !!value);
102 
103 	return count;
104 }
105 
106 static ssize_t
hdd_sysfs_dp_aggregation_store(struct kobject * kobj,struct kobj_attribute * attr,char const * buf,size_t count)107 hdd_sysfs_dp_aggregation_store(struct kobject *kobj,
108 			       struct kobj_attribute *attr,
109 			       char const *buf, size_t count)
110 {
111 	struct osif_psoc_sync *psoc_sync;
112 	struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
113 	ssize_t errno_size;
114 	int ret;
115 
116 	ret = wlan_hdd_validate_context(hdd_ctx);
117 	if (ret != 0)
118 		return ret;
119 
120 	errno_size = osif_psoc_sync_op_start(wiphy_dev(hdd_ctx->wiphy),
121 					     &psoc_sync);
122 	if (errno_size)
123 		return errno_size;
124 
125 	errno_size = __hdd_sysfs_dp_aggregation_store(hdd_ctx, attr,
126 						      buf, count);
127 
128 	osif_psoc_sync_op_stop(psoc_sync);
129 
130 	return errno_size;
131 }
132 
133 static struct kobj_attribute dp_aggregation_attribute =
134 	__ATTR(dp_aggregation, 0664, hdd_sysfs_dp_aggregation_show,
135 	       hdd_sysfs_dp_aggregation_store);
136 
hdd_sysfs_dp_aggregation_create(struct kobject * driver_kobject)137 int hdd_sysfs_dp_aggregation_create(struct kobject *driver_kobject)
138 {
139 	int error;
140 
141 	if (!driver_kobject) {
142 		hdd_err("could not get driver kobject!");
143 		return -EINVAL;
144 	}
145 
146 	error = sysfs_create_file(driver_kobject,
147 				  &dp_aggregation_attribute.attr);
148 	if (error)
149 		hdd_err("could not create dp_aggregation sysfs file");
150 
151 	return error;
152 }
153 
154 void
hdd_sysfs_dp_aggregation_destroy(struct kobject * driver_kobject)155 hdd_sysfs_dp_aggregation_destroy(struct kobject *driver_kobject)
156 {
157 	if (!driver_kobject) {
158 		hdd_err("could not get driver kobject!");
159 		return;
160 	}
161 
162 	sysfs_remove_file(driver_kobject, &dp_aggregation_attribute.attr);
163 }
164