1 /*
2  * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 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_txrx_fw_st_rst.c
20  *
21  * implementation for creating sysfs file txrx_fw_st_rst
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_txrx_fw_st_rst.h>
28 #include "wma.h"
29 #include "wma_api.h"
30 
hdd_sysfs_set_vdev(struct hdd_adapter * adapter,int id,const char * id_string,int value)31 static int hdd_sysfs_set_vdev(struct hdd_adapter *adapter,
32 			      int id, const char *id_string,
33 			      int value)
34 {
35 	int errno;
36 
37 	hdd_debug("%s %d", id_string, value);
38 	errno = wma_cli_set_command(adapter->deflink->vdev_id,
39 				    id, value, VDEV_CMD);
40 	if (errno)
41 		hdd_err("Failed to set firmware, errno %d", errno);
42 
43 	return errno;
44 }
45 
46 #define hdd_sysfs_set_vdev(adapter, id, value) \
47 			   hdd_sysfs_set_vdev(adapter, id, #id, value)
48 
49 static ssize_t
__hdd_sysfs_txrx_fw_st_rst_store(struct net_device * net_dev,char const * buf,size_t count)50 __hdd_sysfs_txrx_fw_st_rst_store(struct net_device *net_dev,
51 				 char const *buf, size_t count)
52 {
53 	struct hdd_adapter *adapter = netdev_priv(net_dev);
54 	char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1];
55 	struct hdd_context *hdd_ctx;
56 	char *sptr, *token;
57 	uint32_t value;
58 	int ret;
59 
60 	if (hdd_validate_adapter(adapter))
61 		return -EINVAL;
62 
63 	hdd_ctx = WLAN_HDD_GET_CTX(adapter);
64 	ret = wlan_hdd_validate_context(hdd_ctx);
65 	if (ret != 0)
66 		return ret;
67 
68 	if (!wlan_hdd_validate_modules_state(hdd_ctx))
69 		return -EINVAL;
70 
71 	ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
72 					      buf, count);
73 
74 	if (ret) {
75 		hdd_err_rl("invalid input");
76 		return ret;
77 	}
78 
79 	sptr = buf_local;
80 	hdd_debug("txrx_fw_st_rst: count %zu buf_local:(%s) net_devname %s",
81 		  count, buf_local, net_dev->name);
82 
83 	/* Get value */
84 	token = strsep(&sptr, " ");
85 	if (!token)
86 		return -EINVAL;
87 	if (kstrtou32(token, 0, &value))
88 		return -EINVAL;
89 
90 	ret = hdd_sysfs_set_vdev(adapter,
91 				 WMA_VDEV_TXRX_FWSTATS_RESET_CMDID, value);
92 
93 	if (ret) {
94 		hdd_err_rl("failed to set txrx fw stats reset: %d", ret);
95 		return ret;
96 	}
97 
98 	return count;
99 }
100 
101 static ssize_t
hdd_sysfs_txrx_fw_st_rst_store(struct device * dev,struct device_attribute * attr,char const * buf,size_t count)102 hdd_sysfs_txrx_fw_st_rst_store(struct device *dev,
103 			       struct device_attribute *attr,
104 			       char const *buf, size_t count)
105 {
106 	struct net_device *net_dev = container_of(dev, struct net_device, dev);
107 	struct osif_vdev_sync *vdev_sync;
108 	ssize_t errno_size;
109 
110 	errno_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
111 	if (errno_size)
112 		return errno_size;
113 
114 	errno_size = __hdd_sysfs_txrx_fw_st_rst_store(net_dev, buf, count);
115 
116 	osif_vdev_sync_op_stop(vdev_sync);
117 
118 	return errno_size;
119 }
120 
121 static DEVICE_ATTR(txrx_fw_st_rst, 0220,
122 		   NULL, hdd_sysfs_txrx_fw_st_rst_store);
123 
hdd_sysfs_txrx_fw_st_rst_create(struct hdd_adapter * adapter)124 int hdd_sysfs_txrx_fw_st_rst_create(struct hdd_adapter *adapter)
125 {
126 	int error;
127 
128 	error = device_create_file(&adapter->dev->dev,
129 				   &dev_attr_txrx_fw_st_rst);
130 	if (error)
131 		hdd_err("could not create txrx_fw_st_rst sysfs file");
132 
133 	return error;
134 }
135 
hdd_sysfs_txrx_fw_st_rst_destroy(struct hdd_adapter * adapter)136 void hdd_sysfs_txrx_fw_st_rst_destroy(struct hdd_adapter *adapter)
137 {
138 	device_remove_file(&adapter->dev->dev, &dev_attr_txrx_fw_st_rst);
139 }
140