1  /*
2   * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3   *
4   * Permission to use, copy, modify, and/or distribute this software for
5   * any purpose with or without fee is hereby granted, provided that the
6   * above copyright notice and this permission notice appear in all
7   * copies.
8   *
9   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10   * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11   * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12   * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13   * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14   * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16   * PERFORMANCE OF THIS SOFTWARE.
17   */
18  
19  /**
20   * DOC: wlan_hdd_sysfs_wow_ito.c
21   *
22   * implementation for creating sysfs wow_ito
23   */
24  
25  #include <wlan_hdd_includes.h>
26  #include "osif_psoc_sync.h"
27  #include <wlan_hdd_sysfs.h>
28  #include <wlan_hdd_sysfs_wow_ito.h>
29  #include "wlan_pmo_ucfg_api.h"
30  #include "cfg_ucfg_api.h"
31  
32  static ssize_t
__hdd_sysfs_wow_ito_store(struct hdd_context * hdd_ctx,struct kobj_attribute * attr,const char * buf,size_t count)33  __hdd_sysfs_wow_ito_store(struct hdd_context *hdd_ctx,
34  			  struct kobj_attribute *attr,
35  			  const char *buf, size_t count)
36  {
37  	char buf_local[MAX_SYSFS_USER_COMMAND_SIZE_LENGTH + 1];
38  	char *sptr, *token;
39  	uint8_t value;
40  	int ret;
41  
42  	if (!wlan_hdd_validate_modules_state(hdd_ctx))
43  		return -EINVAL;
44  
45  	if (!hdd_ctx->psoc)
46  		return -EINVAL;
47  
48  	ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
49  					      buf, count);
50  	if (ret) {
51  		hdd_err_rl("invalid input");
52  		return ret;
53  	}
54  
55  	sptr = buf_local;
56  	hdd_debug("wow_ito: count %zu buf_local:(%s)",
57  		  count, buf_local);
58  
59  	/* Get value */
60  	token = strsep(&sptr, " ");
61  	if (!token)
62  		return -EINVAL;
63  	if (kstrtou8(token, 0, &value))
64  		return -EINVAL;
65  
66  	if (!cfg_in_range(CFG_PMO_WOW_DATA_INACTIVITY_TIMEOUT, value)) {
67  		hdd_err_rl("Invalid value %d", value);
68  		return -EINVAL;
69  	}
70  
71  	ucfg_pmo_set_wow_data_inactivity_timeout(hdd_ctx->psoc, value);
72  
73  	return count;
74  }
75  
76  static ssize_t
hdd_sysfs_wow_ito_store(struct kobject * kobj,struct kobj_attribute * attr,const char * buf,size_t count)77  hdd_sysfs_wow_ito_store(struct kobject *kobj,
78  			struct kobj_attribute *attr,
79  			const char *buf, size_t count)
80  {
81  	struct osif_psoc_sync *psoc_sync;
82  	struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
83  	ssize_t errno_size;
84  	int ret;
85  
86  	ret = wlan_hdd_validate_context(hdd_ctx);
87  	if (ret)
88  		return ret;
89  
90  	errno_size = osif_psoc_sync_op_start(wiphy_dev(hdd_ctx->wiphy),
91  					     &psoc_sync);
92  	if (errno_size)
93  		return errno_size;
94  
95  	errno_size = __hdd_sysfs_wow_ito_store(hdd_ctx, attr, buf, count);
96  
97  	osif_psoc_sync_op_stop(psoc_sync);
98  
99  	return errno_size;
100  }
101  
102  static struct kobj_attribute wow_ito_attribute =
103  	__ATTR(wow_ito, 0220, NULL,
104  	       hdd_sysfs_wow_ito_store);
105  
hdd_sysfs_wow_ito_create(struct kobject * driver_kobject)106  int hdd_sysfs_wow_ito_create(struct kobject *driver_kobject)
107  {
108  	int error;
109  
110  	if (!driver_kobject) {
111  		hdd_err("could not get driver kobject!");
112  		return -EINVAL;
113  	}
114  
115  	error = sysfs_create_file(driver_kobject,
116  				  &wow_ito_attribute.attr);
117  	if (error)
118  		hdd_err("could not create wow_ito sysfs file");
119  
120  	return error;
121  }
122  
123  void
hdd_sysfs_wow_ito_destroy(struct kobject * driver_kobject)124  hdd_sysfs_wow_ito_destroy(struct kobject *driver_kobject)
125  {
126  	if (!driver_kobject) {
127  		hdd_err("could not get driver kobject!");
128  		return;
129  	}
130  	sysfs_remove_file(driver_kobject, &wow_ito_attribute.attr);
131  }
132