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_range_ext.c
20 *
21 * implementation for creating sysfs file range_ext
22 */
23
24 #include <wlan_hdd_includes.h>
25 #include "osif_vdev_sync.h"
26 #include <wlan_hdd_sysfs.h>
27 #include "wma_api.h"
28 #include "wlan_hdd_sysfs_range_ext.h"
29
30 static ssize_t
__hdd_sysfs_range_ext_show(struct net_device * net_dev,char * buf)31 __hdd_sysfs_range_ext_show(struct net_device *net_dev, char *buf)
32 {
33 struct hdd_adapter *adapter = netdev_priv(net_dev);
34 struct hdd_context *hdd_ctx;
35 int value;
36 int ret;
37
38 if (hdd_validate_adapter(adapter))
39 return -EINVAL;
40
41 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
42 ret = wlan_hdd_validate_context(hdd_ctx);
43 if (ret)
44 return ret;
45
46 if (!wlan_hdd_validate_modules_state(hdd_ctx))
47 return -EINVAL;
48
49 hdd_debug("GET wmi_vdev_param_he_range_ext");
50 value = wma_cli_get_command(adapter->deflink->vdev_id,
51 wmi_vdev_param_he_range_ext, VDEV_CMD);
52
53 return scnprintf(buf, PAGE_SIZE, "%d\n", value);
54 }
55
56 static ssize_t
hdd_sysfs_range_ext_show(struct device * dev,struct device_attribute * attr,char * buf)57 hdd_sysfs_range_ext_show(struct device *dev,
58 struct device_attribute *attr,
59 char *buf)
60 {
61 struct net_device *net_dev = container_of(dev, struct net_device, dev);
62 struct osif_vdev_sync *vdev_sync;
63 ssize_t err_size;
64
65 err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
66 if (err_size)
67 return err_size;
68
69 err_size = __hdd_sysfs_range_ext_show(net_dev, buf);
70
71 osif_vdev_sync_op_stop(vdev_sync);
72
73 return err_size;
74 }
75
__hdd_sysfs_range_ext_store(struct net_device * net_dev,char const * buf,size_t count)76 static ssize_t __hdd_sysfs_range_ext_store(struct net_device *net_dev,
77 char const *buf, size_t count)
78 {
79 struct hdd_adapter *adapter = netdev_priv(net_dev);
80 char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1];
81 struct hdd_context *hdd_ctx;
82 char *sptr, *token;
83 uint32_t value;
84 int ret, errno;
85
86 if (hdd_validate_adapter(adapter))
87 return -EINVAL;
88
89 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
90 ret = wlan_hdd_validate_context(hdd_ctx);
91 if (ret != 0)
92 return ret;
93
94 if (!wlan_hdd_validate_modules_state(hdd_ctx))
95 return -EINVAL;
96
97 ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
98 buf, count);
99
100 if (ret) {
101 hdd_err_rl("invalid input");
102 return ret;
103 }
104
105 sptr = buf_local;
106 hdd_debug("range_ext: count %zu buf_local:(%s) net_devname %s",
107 count, buf_local, net_dev->name);
108
109 /* Get value */
110 token = strsep(&sptr, " ");
111 if (!token)
112 return -EINVAL;
113 if (kstrtou32(token, 0, &value))
114 return -EINVAL;
115
116 hdd_debug("wmi_vdev_param_he_range_ext %d", value);
117 errno = wma_cli_set_command(adapter->deflink->vdev_id,
118 wmi_vdev_param_he_range_ext,
119 value, VDEV_CMD);
120 if (errno)
121 hdd_err("Failed to set he_range_ext firmware param, errno %d",
122 errno);
123
124 return count;
125 }
126
127 static ssize_t
hdd_sysfs_range_ext_store(struct device * dev,struct device_attribute * attr,char const * buf,size_t count)128 hdd_sysfs_range_ext_store(struct device *dev, struct device_attribute *attr,
129 char const *buf, size_t count)
130 {
131 struct net_device *net_dev = container_of(dev, struct net_device, dev);
132 struct osif_vdev_sync *vdev_sync;
133 ssize_t errno_size;
134
135 errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
136 if (errno_size)
137 return errno_size;
138
139 errno_size = __hdd_sysfs_range_ext_store(net_dev, buf, count);
140
141 osif_vdev_sync_op_stop(vdev_sync);
142
143 return errno_size;
144 }
145
146 static DEVICE_ATTR(range_ext, 0660, hdd_sysfs_range_ext_show,
147 hdd_sysfs_range_ext_store);
148
hdd_sysfs_range_ext_create(struct hdd_adapter * adapter)149 void hdd_sysfs_range_ext_create(struct hdd_adapter *adapter)
150 {
151 int error;
152
153 error = device_create_file(&adapter->dev->dev, &dev_attr_range_ext);
154 if (error)
155 hdd_err("could not create range_ext sysfs file");
156 }
157
hdd_sysfs_range_ext_destroy(struct hdd_adapter * adapter)158 void hdd_sysfs_range_ext_destroy(struct hdd_adapter *adapter)
159 {
160 device_remove_file(&adapter->dev->dev, &dev_attr_range_ext);
161 }
162