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 #include <wlan_hdd_main.h>
19 #include <wlan_hdd_sysfs_ipa.h>
20 #include <wlan_ipa_ucfg_api.h>
21 #include <wlan_hdd_sysfs.h>
22 #include "osif_sync.h"
23
24 #ifdef IPA_OFFLOAD
25 #define MAX_USER_COMMAND_SIZE_IPAUCSTAT 4
26
__hdd_sysfs_ipaucstate_store(struct net_device * net_dev,const char __user * buf,size_t count)27 static ssize_t __hdd_sysfs_ipaucstate_store(struct net_device *net_dev,
28 const char __user *buf,
29 size_t count)
30 {
31 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(net_dev);
32 struct hdd_context *hdd_ctx;
33 uint8_t cmd[MAX_USER_COMMAND_SIZE_IPAUCSTAT] = {0};
34 int ret;
35 char *sptr, *token;
36 uint8_t set_value = 0;
37
38 hdd_enter();
39
40 if (hdd_validate_adapter(adapter))
41 return -EINVAL;
42
43 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
44 ret = wlan_hdd_validate_context(hdd_ctx);
45 if (ret)
46 return ret;
47
48 if (!wlan_hdd_validate_modules_state(hdd_ctx))
49 return -EINVAL;
50
51 if (!ucfg_ipa_is_enabled())
52 return -EINVAL;
53
54 if (adapter->device_mode != QDF_SAP_MODE)
55 return -EINVAL;
56
57 ret = hdd_sysfs_validate_and_copy_buf(cmd, sizeof(cmd),
58 buf, count);
59 if (ret) {
60 hdd_err_rl("invalid input");
61 return ret;
62 }
63
64 sptr = cmd;
65 /* Get set_value */
66 token = strsep(&sptr, " ");
67 if (!token)
68 return -EINVAL;
69 if (kstrtou8(token, 0, &set_value))
70 return -EINVAL;
71
72 /* If input value is non-zero get stats */
73 switch (set_value) {
74 case IPA_UC_STAT:
75 ucfg_ipa_uc_stat(hdd_ctx->pdev);
76 break;
77 case IPA_UC_INFO:
78 ucfg_ipa_uc_info(hdd_ctx->pdev);
79 break;
80 case IPA_UC_RT_DEBUG_HOST_DUMP:
81 ucfg_ipa_uc_rt_debug_host_dump(hdd_ctx->pdev);
82 break;
83 case IPA_DUMP_INFO:
84 ucfg_ipa_dump_info(hdd_ctx->pdev);
85 break;
86 default:
87 /* place holder for stats clean up
88 * Stats clean not implemented yet on FW and IPA
89 */
90 break;
91 }
92 hdd_exit();
93 return count;
94 }
95
hdd_sysfs_ipaucstate_store(struct device * dev,struct device_attribute * attr,char const * buf,size_t count)96 static ssize_t hdd_sysfs_ipaucstate_store(struct device *dev,
97 struct device_attribute *attr,
98 char const *buf, size_t count)
99 {
100 struct net_device *net_dev = container_of(dev, struct net_device, dev);
101 struct osif_vdev_sync *vdev_sync;
102 ssize_t err_size;
103
104 err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
105 if (err_size)
106 return err_size;
107
108 err_size = __hdd_sysfs_ipaucstate_store(net_dev, buf, count);
109
110 osif_vdev_sync_op_stop(vdev_sync);
111 return err_size;
112 }
113
114 static DEVICE_ATTR(ipaucstat, 0220,
115 NULL, hdd_sysfs_ipaucstate_store);
116
hdd_sysfs_ipa_create(struct hdd_adapter * adapter)117 void hdd_sysfs_ipa_create(struct hdd_adapter *adapter)
118 {
119 if (device_create_file(&adapter->dev->dev, &dev_attr_ipaucstat))
120 hdd_err("could not create wlan sysfs file");
121 }
122
hdd_sysfs_ipa_destroy(struct hdd_adapter * adapter)123 void hdd_sysfs_ipa_destroy(struct hdd_adapter *adapter)
124 {
125 device_remove_file(&adapter->dev->dev, &dev_attr_ipaucstat);
126 }
127 #endif
128