1 /*
2 * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 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_gtx_bw_mask.c
20 *
21 * implementation for creating sysfs file gtx_bw_mask
22 */
23
24 #include <wlan_hdd_includes.h>
25 #include "osif_vdev_sync.h"
26 #include <wlan_hdd_sysfs.h>
27 #include <wlan_hdd_sysfs_gtx_bw_mask.h>
28 #include "wma.h"
29 #include "wma_api.h"
30
hdd_sysfs_set_green_tx_param(struct hdd_adapter * adapter,green_tx_param id,const char * id_string,int value)31 static int hdd_sysfs_set_green_tx_param(struct hdd_adapter *adapter,
32 green_tx_param id,
33 const char *id_string,
34 int value)
35 {
36 int errno;
37
38 hdd_debug("%s %d", id_string, value);
39 errno = wma_cli_set_command(adapter->deflink->vdev_id,
40 id, value, GTX_CMD);
41 if (errno)
42 hdd_err("Failed to set firmware, errno %d", errno);
43
44 return errno;
45 }
46
47 #define hdd_sysfs_set_green_tx_param(adapter, id, value) \
48 hdd_sysfs_set_green_tx_param(adapter, id, #id, value)
49
hdd_sysfs_get_green_tx_param(struct hdd_adapter * adapter,green_tx_param id,const char * id_string)50 static int hdd_sysfs_get_green_tx_param(struct hdd_adapter *adapter,
51 green_tx_param id,
52 const char *id_string)
53 {
54 int value;
55
56 value = wma_cli_get_command(adapter->deflink->vdev_id, id, GTX_CMD);
57
58 hdd_debug("%s %d", id_string, value);
59
60 return value;
61 }
62
63 #define hdd_sysfs_get_green_tx_param(adapter, id) \
64 hdd_sysfs_get_green_tx_param(adapter, id, #id)
65
66 static ssize_t
__hdd_sysfs_gtx_bw_mask_store(struct net_device * net_dev,char const * buf,size_t count)67 __hdd_sysfs_gtx_bw_mask_store(struct net_device *net_dev,
68 char const *buf, size_t count)
69 {
70 struct hdd_adapter *adapter = netdev_priv(net_dev);
71 char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1];
72 struct hdd_context *hdd_ctx;
73 char *sptr, *token;
74 uint32_t value;
75 int ret;
76
77 if (hdd_validate_adapter(adapter))
78 return -EINVAL;
79
80 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
81 ret = wlan_hdd_validate_context(hdd_ctx);
82 if (ret != 0)
83 return ret;
84
85 if (!wlan_hdd_validate_modules_state(hdd_ctx))
86 return -EINVAL;
87
88 ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
89 buf, count);
90
91 if (ret) {
92 hdd_err_rl("invalid input");
93 return ret;
94 }
95
96 sptr = buf_local;
97 hdd_debug("gtx_bw_mask: count %zu buf_local:(%s) net_devname %s",
98 count, buf_local, net_dev->name);
99
100 /* Get value */
101 token = strsep(&sptr, " ");
102 if (!token)
103 return -EINVAL;
104 if (kstrtou32(token, 0, &value))
105 return -EINVAL;
106
107 ret = hdd_sysfs_set_green_tx_param(adapter,
108 wmi_vdev_param_gtx_bw_mask,
109 value);
110
111 if (ret) {
112 hdd_err_rl("failed to set green tx BW Mask: %d", ret);
113 return ret;
114 }
115
116 return count;
117 }
118
119 static ssize_t
hdd_sysfs_gtx_bw_mask_store(struct device * dev,struct device_attribute * attr,char const * buf,size_t count)120 hdd_sysfs_gtx_bw_mask_store(struct device *dev,
121 struct device_attribute *attr,
122 char const *buf, size_t count)
123 {
124 struct net_device *net_dev = container_of(dev, struct net_device, dev);
125 struct osif_vdev_sync *vdev_sync;
126 ssize_t errno_size;
127
128 errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
129 if (errno_size)
130 return errno_size;
131
132 errno_size = __hdd_sysfs_gtx_bw_mask_store(net_dev, buf, count);
133
134 osif_vdev_sync_op_stop(vdev_sync);
135
136 return errno_size;
137 }
138
139 static ssize_t
__hdd_sysfs_gtx_bw_mask_show(struct net_device * net_dev,char * buf)140 __hdd_sysfs_gtx_bw_mask_show(struct net_device *net_dev, char *buf)
141 {
142 struct hdd_adapter *adapter = netdev_priv(net_dev);
143 struct hdd_context *hdd_ctx;
144 int ret, value;
145
146 if (hdd_validate_adapter(adapter))
147 return -EINVAL;
148
149 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
150 ret = wlan_hdd_validate_context(hdd_ctx);
151 if (ret != 0)
152 return ret;
153
154 if (!wlan_hdd_validate_modules_state(hdd_ctx))
155 return -EINVAL;
156
157 value = hdd_sysfs_get_green_tx_param(adapter,
158 wmi_vdev_param_gtx_bw_mask);
159 if (value < 0) {
160 hdd_err_rl("failed to get green tx BW Mask");
161 return -EINVAL;
162 }
163
164 return scnprintf(buf, PAGE_SIZE, "%d", value);
165 }
166
167 static ssize_t
hdd_sysfs_gtx_bw_mask_show(struct device * dev,struct device_attribute * attr,char * buf)168 hdd_sysfs_gtx_bw_mask_show(struct device *dev,
169 struct device_attribute *attr,
170 char *buf)
171 {
172 struct net_device *net_dev = container_of(dev, struct net_device, dev);
173 struct osif_vdev_sync *vdev_sync;
174 ssize_t errno_size;
175
176 errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
177 if (errno_size)
178 return errno_size;
179
180 errno_size = __hdd_sysfs_gtx_bw_mask_show(net_dev, buf);
181
182 osif_vdev_sync_op_stop(vdev_sync);
183
184 return errno_size;
185 }
186
187 static DEVICE_ATTR(gtx_bw_mask, 0660, hdd_sysfs_gtx_bw_mask_show,
188 hdd_sysfs_gtx_bw_mask_store);
189
hdd_sysfs_gtx_bw_mask_create(struct hdd_adapter * adapter)190 int hdd_sysfs_gtx_bw_mask_create(struct hdd_adapter *adapter)
191 {
192 int error;
193
194 error = device_create_file(&adapter->dev->dev,
195 &dev_attr_gtx_bw_mask);
196 if (error)
197 hdd_err("could not create gtx_bw_mask sysfs file");
198
199 return error;
200 }
201
hdd_sysfs_gtx_bw_mask_destroy(struct hdd_adapter * adapter)202 void hdd_sysfs_gtx_bw_mask_destroy(struct hdd_adapter *adapter)
203 {
204 device_remove_file(&adapter->dev->dev, &dev_attr_gtx_bw_mask);
205 }
206