xref: /wlan-dirver/qca-wifi-host-cmn/os_if/linux/twt/src/osif_twt_req.c (revision d0c05845839e5f2ba5a8dcebe0cd3e4cd4e8dfcf)
1 /*
2  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17  /**
18   *  DOC: osif_twt_req.c
19   *  This file contains twt request related osif APIs
20   */
21 #include <wlan_cfg80211.h>
22 #include <osif_twt_req.h>
23 #include <osif_twt_util.h>
24 #include <wlan_osif_request_manager.h>
25 #include <wlan_twt_ucfg_api.h>
26 #include <wlan_twt_ucfg_ext_api.h>
27 
28 #define TWT_DISABLE_COMPLETE_TIMEOUT 1000
29 #define TWT_ENABLE_COMPLETE_TIMEOUT  1000
30 
31 int osif_twt_requestor_enable(struct wlan_objmgr_psoc *psoc,
32 			      struct twt_enable_param *req)
33 {
34 	struct osif_request *request;
35 	int ret;
36 	QDF_STATUS status;
37 	struct twt_en_dis_priv *twt_en_priv;
38 	void *context;
39 	static const struct osif_request_params params = {
40 				.priv_size = sizeof(*twt_en_priv),
41 				.timeout_ms = TWT_ENABLE_COMPLETE_TIMEOUT,
42 	};
43 
44 	request = osif_request_alloc(&params);
45 	if (!request) {
46 		osif_err("Request allocation failure");
47 		return -ENOMEM;
48 	}
49 	context = osif_request_cookie(request);
50 
51 	status = ucfg_twt_requestor_enable(psoc, req, context);
52 	if (QDF_IS_STATUS_ERROR(status)) {
53 		osif_warn("Failed to send TWT requestor enable command");
54 		ret = qdf_status_to_os_return(status);
55 		goto cleanup;
56 	}
57 
58 	ret = osif_request_wait_for_response(request);
59 	if (ret) {
60 		osif_warn("TWT Requestor Enable timedout ret:%d", ret);
61 		ret = -ETIMEDOUT;
62 		goto cleanup;
63 	}
64 
65 cleanup:
66 	osif_request_put(request);
67 	return ret;
68 }
69 
70 int osif_twt_responder_enable(struct wlan_objmgr_psoc *psoc,
71 			      struct twt_enable_param *req)
72 {
73 	struct osif_request *request;
74 	int ret;
75 	QDF_STATUS status;
76 	struct twt_en_dis_priv *twt_en_priv;
77 	void *context;
78 	static const struct osif_request_params params = {
79 				.priv_size = sizeof(*twt_en_priv),
80 				.timeout_ms = TWT_ENABLE_COMPLETE_TIMEOUT,
81 	};
82 
83 	request = osif_request_alloc(&params);
84 	if (!request) {
85 		osif_err("Request allocation failure");
86 		return -ENOMEM;
87 	}
88 	context = osif_request_cookie(request);
89 
90 	status = ucfg_twt_responder_enable(psoc, req, context);
91 	if (QDF_IS_STATUS_ERROR(status)) {
92 		osif_warn("Failed to send TWT responder enable command");
93 		ret = qdf_status_to_os_return(status);
94 		goto cleanup;
95 	}
96 
97 	ret = osif_request_wait_for_response(request);
98 	if (ret) {
99 		osif_warn("TWT Responder Enable timedout ret:%d", ret);
100 		ret = -ETIMEDOUT;
101 		goto cleanup;
102 	}
103 
104 cleanup:
105 	osif_request_put(request);
106 	return ret;
107 }
108 
109 int osif_twt_requestor_disable(struct wlan_objmgr_psoc *psoc,
110 			       struct twt_disable_param *req)
111 {
112 	struct osif_request *request;
113 	int ret;
114 	QDF_STATUS status;
115 	struct twt_en_dis_priv *twt_en_priv;
116 	void *context;
117 	static const struct osif_request_params params = {
118 				.priv_size = sizeof(*twt_en_priv),
119 				.timeout_ms = TWT_DISABLE_COMPLETE_TIMEOUT,
120 	};
121 
122 	request = osif_request_alloc(&params);
123 	if (!request) {
124 		osif_err("Request allocation failure");
125 		return -ENOMEM;
126 	}
127 	context = osif_request_cookie(request);
128 
129 	status = ucfg_twt_requestor_disable(psoc, req, context);
130 	if (QDF_IS_STATUS_ERROR(status)) {
131 		osif_warn("Failed to send TWT requestor disable command");
132 		ret = qdf_status_to_os_return(status);
133 		goto cleanup;
134 	}
135 
136 	ret = osif_request_wait_for_response(request);
137 	if (ret) {
138 		osif_warn("TWT Requestor disable timedout ret:%d", ret);
139 		ret = -ETIMEDOUT;
140 		goto cleanup;
141 	}
142 
143 cleanup:
144 	osif_request_put(request);
145 	return ret;
146 }
147 
148 int osif_twt_responder_disable(struct wlan_objmgr_psoc *psoc,
149 			       struct twt_disable_param *req)
150 {
151 	struct osif_request *request;
152 	int ret;
153 	QDF_STATUS status;
154 	struct twt_en_dis_priv *twt_en_priv;
155 	void *context;
156 	static const struct osif_request_params params = {
157 				.priv_size = sizeof(*twt_en_priv),
158 				.timeout_ms = TWT_DISABLE_COMPLETE_TIMEOUT,
159 	};
160 
161 	request = osif_request_alloc(&params);
162 	if (!request) {
163 		osif_err("Request allocation failure");
164 		return -ENOMEM;
165 	}
166 	context = osif_request_cookie(request);
167 
168 	status = ucfg_twt_responder_disable(psoc, req, context);
169 	if (QDF_IS_STATUS_ERROR(status)) {
170 		osif_warn("Failed to send TWT responder disable command");
171 		ret = qdf_status_to_os_return(status);
172 		goto cleanup;
173 	}
174 
175 	ret = osif_request_wait_for_response(request);
176 	if (ret) {
177 		osif_warn("TWT Responder disable timedout ret:%d", ret);
178 		ret = -ETIMEDOUT;
179 		goto cleanup;
180 	}
181 
182 cleanup:
183 	osif_request_put(request);
184 	return ret;
185 }
186 
187