Commit | Line | Data |
---|---|---|
8e84c258 EK |
1 | /* |
2 | * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com> | |
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 ANY | |
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | |
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
18 | ||
19 | #include <linux/etherdevice.h> | |
20 | #include <linux/firmware.h> | |
21 | #include <linux/bitops.h> | |
22 | #include "smd.h" | |
23 | ||
24 | static int put_cfg_tlv_u32(struct wcn36xx *wcn, size_t *len, u32 id, u32 value) | |
25 | { | |
26 | struct wcn36xx_hal_cfg *entry; | |
27 | u32 *val; | |
28 | ||
29 | if (*len + sizeof(*entry) + sizeof(u32) >= WCN36XX_HAL_BUF_SIZE) { | |
30 | wcn36xx_err("Not enough room for TLV entry\n"); | |
31 | return -ENOMEM; | |
32 | } | |
33 | ||
34 | entry = (struct wcn36xx_hal_cfg *) (wcn->hal_buf + *len); | |
35 | entry->id = id; | |
36 | entry->len = sizeof(u32); | |
37 | entry->pad_bytes = 0; | |
38 | entry->reserve = 0; | |
39 | ||
40 | val = (u32 *) (entry + 1); | |
41 | *val = value; | |
42 | ||
43 | *len += sizeof(*entry) + sizeof(u32); | |
44 | ||
45 | return 0; | |
46 | } | |
47 | ||
48 | static void wcn36xx_smd_set_bss_nw_type(struct wcn36xx *wcn, | |
49 | struct ieee80211_sta *sta, | |
50 | struct wcn36xx_hal_config_bss_params *bss_params) | |
51 | { | |
52 | if (IEEE80211_BAND_5GHZ == WCN36XX_BAND(wcn)) | |
53 | bss_params->nw_type = WCN36XX_HAL_11A_NW_TYPE; | |
54 | else if (sta && sta->ht_cap.ht_supported) | |
55 | bss_params->nw_type = WCN36XX_HAL_11N_NW_TYPE; | |
56 | else if (sta && (sta->supp_rates[IEEE80211_BAND_2GHZ] & 0x7f)) | |
57 | bss_params->nw_type = WCN36XX_HAL_11G_NW_TYPE; | |
58 | else | |
59 | bss_params->nw_type = WCN36XX_HAL_11B_NW_TYPE; | |
60 | } | |
61 | ||
62 | static inline u8 is_cap_supported(unsigned long caps, unsigned long flag) | |
63 | { | |
64 | return caps & flag ? 1 : 0; | |
65 | } | |
66 | static void wcn36xx_smd_set_bss_ht_params(struct ieee80211_vif *vif, | |
67 | struct ieee80211_sta *sta, | |
68 | struct wcn36xx_hal_config_bss_params *bss_params) | |
69 | { | |
70 | if (sta && sta->ht_cap.ht_supported) { | |
71 | unsigned long caps = sta->ht_cap.cap; | |
72 | bss_params->ht = sta->ht_cap.ht_supported; | |
73 | bss_params->tx_channel_width_set = is_cap_supported(caps, | |
74 | IEEE80211_HT_CAP_SUP_WIDTH_20_40); | |
75 | bss_params->lsig_tx_op_protection_full_support = | |
76 | is_cap_supported(caps, | |
77 | IEEE80211_HT_CAP_LSIG_TXOP_PROT); | |
78 | ||
79 | bss_params->ht_oper_mode = vif->bss_conf.ht_operation_mode; | |
80 | bss_params->lln_non_gf_coexist = | |
81 | !!(vif->bss_conf.ht_operation_mode & | |
82 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); | |
83 | /* IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT */ | |
84 | bss_params->dual_cts_protection = 0; | |
85 | /* IEEE80211_HT_OP_MODE_PROTECTION_20MHZ */ | |
86 | bss_params->ht20_coexist = 0; | |
87 | } | |
88 | } | |
89 | ||
90 | static void wcn36xx_smd_set_sta_ht_params(struct ieee80211_sta *sta, | |
91 | struct wcn36xx_hal_config_sta_params *sta_params) | |
92 | { | |
93 | if (sta->ht_cap.ht_supported) { | |
94 | unsigned long caps = sta->ht_cap.cap; | |
95 | sta_params->ht_capable = sta->ht_cap.ht_supported; | |
96 | sta_params->tx_channel_width_set = is_cap_supported(caps, | |
97 | IEEE80211_HT_CAP_SUP_WIDTH_20_40); | |
98 | sta_params->lsig_txop_protection = is_cap_supported(caps, | |
99 | IEEE80211_HT_CAP_LSIG_TXOP_PROT); | |
100 | ||
101 | sta_params->max_ampdu_size = sta->ht_cap.ampdu_factor; | |
102 | sta_params->max_ampdu_density = sta->ht_cap.ampdu_density; | |
103 | sta_params->max_amsdu_size = is_cap_supported(caps, | |
104 | IEEE80211_HT_CAP_MAX_AMSDU); | |
105 | sta_params->sgi_20Mhz = is_cap_supported(caps, | |
106 | IEEE80211_HT_CAP_SGI_20); | |
107 | sta_params->sgi_40mhz = is_cap_supported(caps, | |
108 | IEEE80211_HT_CAP_SGI_40); | |
109 | sta_params->green_field_capable = is_cap_supported(caps, | |
110 | IEEE80211_HT_CAP_GRN_FLD); | |
111 | sta_params->delayed_ba_support = is_cap_supported(caps, | |
112 | IEEE80211_HT_CAP_DELAY_BA); | |
113 | sta_params->dsss_cck_mode_40mhz = is_cap_supported(caps, | |
114 | IEEE80211_HT_CAP_DSSSCCK40); | |
115 | } | |
116 | } | |
117 | ||
42bc702e CYY |
118 | static void wcn36xx_smd_set_sta_default_ht_params( |
119 | struct wcn36xx_hal_config_sta_params *sta_params) | |
120 | { | |
121 | sta_params->ht_capable = 1; | |
122 | sta_params->tx_channel_width_set = 1; | |
123 | sta_params->lsig_txop_protection = 1; | |
124 | sta_params->max_ampdu_size = 3; | |
125 | sta_params->max_ampdu_density = 5; | |
126 | sta_params->max_amsdu_size = 0; | |
127 | sta_params->sgi_20Mhz = 1; | |
128 | sta_params->sgi_40mhz = 1; | |
129 | sta_params->green_field_capable = 1; | |
130 | sta_params->delayed_ba_support = 0; | |
131 | sta_params->dsss_cck_mode_40mhz = 1; | |
132 | } | |
133 | ||
8e84c258 EK |
134 | static void wcn36xx_smd_set_sta_params(struct wcn36xx *wcn, |
135 | struct ieee80211_vif *vif, | |
136 | struct ieee80211_sta *sta, | |
137 | struct wcn36xx_hal_config_sta_params *sta_params) | |
138 | { | |
139 | struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv; | |
140 | struct wcn36xx_sta *priv_sta = NULL; | |
141 | if (vif->type == NL80211_IFTYPE_ADHOC || | |
142 | vif->type == NL80211_IFTYPE_AP || | |
143 | vif->type == NL80211_IFTYPE_MESH_POINT) { | |
144 | sta_params->type = 1; | |
145 | sta_params->sta_index = 0xFF; | |
146 | } else { | |
147 | sta_params->type = 0; | |
148 | sta_params->sta_index = 1; | |
149 | } | |
150 | ||
151 | sta_params->listen_interval = WCN36XX_LISTEN_INTERVAL(wcn); | |
152 | ||
153 | /* | |
154 | * In STA mode ieee80211_sta contains bssid and ieee80211_vif | |
155 | * contains our mac address. In AP mode we are bssid so vif | |
156 | * contains bssid and ieee80211_sta contains mac. | |
157 | */ | |
158 | if (NL80211_IFTYPE_STATION == vif->type) | |
159 | memcpy(&sta_params->mac, vif->addr, ETH_ALEN); | |
160 | else | |
161 | memcpy(&sta_params->bssid, vif->addr, ETH_ALEN); | |
162 | ||
163 | sta_params->encrypt_type = priv_vif->encrypt_type; | |
164 | sta_params->short_preamble_supported = | |
165 | !(WCN36XX_FLAGS(wcn) & | |
166 | IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE); | |
167 | ||
168 | sta_params->rifs_mode = 0; | |
169 | sta_params->rmf = 0; | |
170 | sta_params->action = 0; | |
171 | sta_params->uapsd = 0; | |
172 | sta_params->mimo_ps = WCN36XX_HAL_HT_MIMO_PS_STATIC; | |
173 | sta_params->max_ampdu_duration = 0; | |
174 | sta_params->bssid_index = priv_vif->bss_index; | |
175 | sta_params->p2p = 0; | |
176 | ||
177 | if (sta) { | |
178 | priv_sta = (struct wcn36xx_sta *)sta->drv_priv; | |
179 | if (NL80211_IFTYPE_STATION == vif->type) | |
180 | memcpy(&sta_params->bssid, sta->addr, ETH_ALEN); | |
181 | else | |
182 | memcpy(&sta_params->mac, sta->addr, ETH_ALEN); | |
183 | sta_params->wmm_enabled = sta->wme; | |
184 | sta_params->max_sp_len = sta->max_sp; | |
185 | sta_params->aid = priv_sta->aid; | |
186 | wcn36xx_smd_set_sta_ht_params(sta, sta_params); | |
187 | memcpy(&sta_params->supported_rates, &priv_sta->supported_rates, | |
188 | sizeof(priv_sta->supported_rates)); | |
189 | } else { | |
190 | wcn36xx_set_default_rates(&sta_params->supported_rates); | |
42bc702e | 191 | wcn36xx_smd_set_sta_default_ht_params(sta_params); |
8e84c258 EK |
192 | } |
193 | } | |
194 | ||
195 | static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len) | |
196 | { | |
197 | int ret = 0; | |
198 | wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "HAL >>> ", wcn->hal_buf, len); | |
199 | ||
200 | init_completion(&wcn->hal_rsp_compl); | |
201 | ret = wcn->ctrl_ops->tx(wcn->hal_buf, len); | |
202 | if (ret) { | |
203 | wcn36xx_err("HAL TX failed\n"); | |
204 | goto out; | |
205 | } | |
206 | if (wait_for_completion_timeout(&wcn->hal_rsp_compl, | |
207 | msecs_to_jiffies(HAL_MSG_TIMEOUT)) <= 0) { | |
208 | wcn36xx_err("Timeout while waiting SMD response\n"); | |
209 | ret = -ETIME; | |
210 | goto out; | |
211 | } | |
212 | out: | |
213 | return ret; | |
214 | } | |
215 | ||
216 | #define INIT_HAL_MSG(msg_body, type) \ | |
217 | do { \ | |
218 | memset(&msg_body, 0, sizeof(msg_body)); \ | |
219 | msg_body.header.msg_type = type; \ | |
220 | msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \ | |
221 | msg_body.header.len = sizeof(msg_body); \ | |
222 | } while (0) \ | |
223 | ||
224 | #define PREPARE_HAL_BUF(send_buf, msg_body) \ | |
225 | do { \ | |
226 | memset(send_buf, 0, msg_body.header.len); \ | |
227 | memcpy(send_buf, &msg_body, sizeof(msg_body)); \ | |
228 | } while (0) \ | |
229 | ||
230 | static int wcn36xx_smd_rsp_status_check(void *buf, size_t len) | |
231 | { | |
232 | struct wcn36xx_fw_msg_status_rsp *rsp; | |
233 | ||
234 | if (len < sizeof(struct wcn36xx_hal_msg_header) + | |
235 | sizeof(struct wcn36xx_fw_msg_status_rsp)) | |
236 | return -EIO; | |
237 | ||
238 | rsp = (struct wcn36xx_fw_msg_status_rsp *) | |
239 | (buf + sizeof(struct wcn36xx_hal_msg_header)); | |
240 | ||
241 | if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) | |
242 | return rsp->status; | |
243 | ||
244 | return 0; | |
245 | } | |
246 | ||
247 | int wcn36xx_smd_load_nv(struct wcn36xx *wcn) | |
248 | { | |
249 | const struct firmware *nv; | |
250 | struct nv_data *nv_d; | |
251 | struct wcn36xx_hal_nv_img_download_req_msg msg_body; | |
252 | int fw_bytes_left; | |
253 | int ret; | |
254 | u16 fm_offset = 0; | |
255 | ||
256 | ret = request_firmware(&nv, WLAN_NV_FILE, wcn->dev); | |
257 | if (ret) { | |
258 | wcn36xx_err("Failed to load nv file %s: %d\n", | |
259 | WLAN_NV_FILE, ret); | |
260 | goto out_free_nv; | |
261 | } | |
262 | ||
263 | nv_d = (struct nv_data *)nv->data; | |
264 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ); | |
265 | ||
266 | msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE; | |
267 | ||
268 | msg_body.frag_number = 0; | |
269 | /* hal_buf must be protected with mutex */ | |
270 | mutex_lock(&wcn->hal_mutex); | |
271 | ||
272 | do { | |
273 | fw_bytes_left = nv->size - fm_offset - 4; | |
274 | if (fw_bytes_left > WCN36XX_NV_FRAGMENT_SIZE) { | |
275 | msg_body.last_fragment = 0; | |
276 | msg_body.nv_img_buffer_size = WCN36XX_NV_FRAGMENT_SIZE; | |
277 | } else { | |
278 | msg_body.last_fragment = 1; | |
279 | msg_body.nv_img_buffer_size = fw_bytes_left; | |
280 | ||
281 | /* Do not forget update general message len */ | |
282 | msg_body.header.len = sizeof(msg_body) + fw_bytes_left; | |
283 | ||
284 | } | |
285 | ||
286 | /* Add load NV request message header */ | |
287 | memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body)); | |
288 | ||
289 | /* Add NV body itself */ | |
290 | memcpy(wcn->hal_buf + sizeof(msg_body), | |
291 | &nv_d->table + fm_offset, | |
292 | msg_body.nv_img_buffer_size); | |
293 | ||
294 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
295 | if (ret) | |
296 | goto out_unlock; | |
297 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, | |
298 | wcn->hal_rsp_len); | |
299 | if (ret) { | |
300 | wcn36xx_err("hal_load_nv response failed err=%d\n", | |
301 | ret); | |
302 | goto out_unlock; | |
303 | } | |
304 | msg_body.frag_number++; | |
305 | fm_offset += WCN36XX_NV_FRAGMENT_SIZE; | |
306 | ||
307 | } while (msg_body.last_fragment != 1); | |
308 | ||
309 | out_unlock: | |
310 | mutex_unlock(&wcn->hal_mutex); | |
311 | out_free_nv: | |
312 | release_firmware(nv); | |
313 | ||
314 | return ret; | |
315 | } | |
316 | ||
317 | static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len) | |
318 | { | |
319 | struct wcn36xx_hal_mac_start_rsp_msg *rsp; | |
320 | ||
321 | if (len < sizeof(*rsp)) | |
322 | return -EIO; | |
323 | ||
324 | rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf; | |
325 | ||
326 | if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status) | |
327 | return -EIO; | |
328 | ||
329 | memcpy(wcn->crm_version, rsp->start_rsp_params.crm_version, | |
330 | WCN36XX_HAL_VERSION_LENGTH); | |
331 | memcpy(wcn->wlan_version, rsp->start_rsp_params.wlan_version, | |
332 | WCN36XX_HAL_VERSION_LENGTH); | |
333 | ||
334 | /* null terminate the strings, just in case */ | |
335 | wcn->crm_version[WCN36XX_HAL_VERSION_LENGTH] = '\0'; | |
336 | wcn->wlan_version[WCN36XX_HAL_VERSION_LENGTH] = '\0'; | |
337 | ||
338 | wcn->fw_revision = rsp->start_rsp_params.version.revision; | |
339 | wcn->fw_version = rsp->start_rsp_params.version.version; | |
340 | wcn->fw_minor = rsp->start_rsp_params.version.minor; | |
341 | wcn->fw_major = rsp->start_rsp_params.version.major; | |
342 | ||
343 | wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n", | |
344 | wcn->wlan_version, wcn->crm_version); | |
345 | ||
346 | wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n", | |
347 | wcn->fw_major, wcn->fw_minor, | |
348 | wcn->fw_version, wcn->fw_revision, | |
349 | rsp->start_rsp_params.stations, | |
350 | rsp->start_rsp_params.bssids); | |
351 | ||
352 | return 0; | |
353 | } | |
354 | ||
355 | int wcn36xx_smd_start(struct wcn36xx *wcn) | |
356 | { | |
357 | struct wcn36xx_hal_mac_start_req_msg msg_body; | |
358 | int ret = 0; | |
359 | ||
360 | mutex_lock(&wcn->hal_mutex); | |
361 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ); | |
362 | ||
363 | msg_body.params.type = DRIVER_TYPE_PRODUCTION; | |
364 | msg_body.params.len = 0; | |
365 | ||
366 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
367 | ||
368 | wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n", | |
369 | msg_body.params.type); | |
370 | ||
371 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
372 | if (ret) { | |
373 | wcn36xx_err("Sending hal_start failed\n"); | |
374 | goto out; | |
375 | } | |
376 | ||
377 | ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len); | |
378 | if (ret) { | |
379 | wcn36xx_err("hal_start response failed err=%d\n", ret); | |
380 | goto out; | |
381 | } | |
382 | ||
383 | out: | |
384 | mutex_unlock(&wcn->hal_mutex); | |
385 | return ret; | |
386 | } | |
387 | ||
388 | int wcn36xx_smd_stop(struct wcn36xx *wcn) | |
389 | { | |
390 | struct wcn36xx_hal_mac_stop_req_msg msg_body; | |
391 | int ret = 0; | |
392 | ||
393 | mutex_lock(&wcn->hal_mutex); | |
394 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ); | |
395 | ||
396 | msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL; | |
397 | ||
398 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
399 | ||
400 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
401 | if (ret) { | |
402 | wcn36xx_err("Sending hal_stop failed\n"); | |
403 | goto out; | |
404 | } | |
405 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
406 | if (ret) { | |
407 | wcn36xx_err("hal_stop response failed err=%d\n", ret); | |
408 | goto out; | |
409 | } | |
410 | out: | |
411 | mutex_unlock(&wcn->hal_mutex); | |
412 | return ret; | |
413 | } | |
414 | ||
415 | int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode) | |
416 | { | |
417 | struct wcn36xx_hal_init_scan_req_msg msg_body; | |
418 | int ret = 0; | |
419 | ||
420 | mutex_lock(&wcn->hal_mutex); | |
421 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ); | |
422 | ||
423 | msg_body.mode = mode; | |
424 | ||
425 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
426 | ||
427 | wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode); | |
428 | ||
429 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
430 | if (ret) { | |
431 | wcn36xx_err("Sending hal_init_scan failed\n"); | |
432 | goto out; | |
433 | } | |
434 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
435 | if (ret) { | |
436 | wcn36xx_err("hal_init_scan response failed err=%d\n", ret); | |
437 | goto out; | |
438 | } | |
439 | out: | |
440 | mutex_unlock(&wcn->hal_mutex); | |
441 | return ret; | |
442 | } | |
443 | ||
444 | int wcn36xx_smd_start_scan(struct wcn36xx *wcn) | |
445 | { | |
446 | struct wcn36xx_hal_start_scan_req_msg msg_body; | |
447 | int ret = 0; | |
448 | ||
449 | mutex_lock(&wcn->hal_mutex); | |
450 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ); | |
451 | ||
452 | msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn); | |
453 | ||
454 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
455 | ||
456 | wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n", | |
457 | msg_body.scan_channel); | |
458 | ||
459 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
460 | if (ret) { | |
461 | wcn36xx_err("Sending hal_start_scan failed\n"); | |
462 | goto out; | |
463 | } | |
464 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
465 | if (ret) { | |
466 | wcn36xx_err("hal_start_scan response failed err=%d\n", ret); | |
467 | goto out; | |
468 | } | |
469 | out: | |
470 | mutex_unlock(&wcn->hal_mutex); | |
471 | return ret; | |
472 | } | |
473 | ||
474 | int wcn36xx_smd_end_scan(struct wcn36xx *wcn) | |
475 | { | |
476 | struct wcn36xx_hal_end_scan_req_msg msg_body; | |
477 | int ret = 0; | |
478 | ||
479 | mutex_lock(&wcn->hal_mutex); | |
480 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ); | |
481 | ||
482 | msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn); | |
483 | ||
484 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
485 | ||
486 | wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n", | |
487 | msg_body.scan_channel); | |
488 | ||
489 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
490 | if (ret) { | |
491 | wcn36xx_err("Sending hal_end_scan failed\n"); | |
492 | goto out; | |
493 | } | |
494 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
495 | if (ret) { | |
496 | wcn36xx_err("hal_end_scan response failed err=%d\n", ret); | |
497 | goto out; | |
498 | } | |
499 | out: | |
500 | mutex_unlock(&wcn->hal_mutex); | |
501 | return ret; | |
502 | } | |
503 | ||
504 | int wcn36xx_smd_finish_scan(struct wcn36xx *wcn, | |
505 | enum wcn36xx_hal_sys_mode mode) | |
506 | { | |
507 | struct wcn36xx_hal_finish_scan_req_msg msg_body; | |
508 | int ret = 0; | |
509 | ||
510 | mutex_lock(&wcn->hal_mutex); | |
511 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ); | |
512 | ||
513 | msg_body.mode = mode; | |
514 | ||
515 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
516 | ||
517 | wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n", | |
518 | msg_body.mode); | |
519 | ||
520 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
521 | if (ret) { | |
522 | wcn36xx_err("Sending hal_finish_scan failed\n"); | |
523 | goto out; | |
524 | } | |
525 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
526 | if (ret) { | |
527 | wcn36xx_err("hal_finish_scan response failed err=%d\n", ret); | |
528 | goto out; | |
529 | } | |
530 | out: | |
531 | mutex_unlock(&wcn->hal_mutex); | |
532 | return ret; | |
533 | } | |
534 | ||
535 | static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len) | |
536 | { | |
537 | struct wcn36xx_hal_switch_channel_rsp_msg *rsp; | |
538 | int ret = 0; | |
539 | ||
540 | ret = wcn36xx_smd_rsp_status_check(buf, len); | |
541 | if (ret) | |
542 | return ret; | |
543 | rsp = (struct wcn36xx_hal_switch_channel_rsp_msg *)buf; | |
544 | wcn36xx_dbg(WCN36XX_DBG_HAL, "channel switched to: %d, status: %d\n", | |
545 | rsp->channel_number, rsp->status); | |
546 | return ret; | |
547 | } | |
548 | ||
549 | int wcn36xx_smd_switch_channel(struct wcn36xx *wcn, | |
550 | struct ieee80211_vif *vif, int ch) | |
551 | { | |
552 | struct wcn36xx_hal_switch_channel_req_msg msg_body; | |
553 | int ret = 0; | |
554 | ||
555 | mutex_lock(&wcn->hal_mutex); | |
556 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ); | |
557 | ||
558 | msg_body.channel_number = (u8)ch; | |
559 | msg_body.tx_mgmt_power = 0xbf; | |
560 | msg_body.max_tx_power = 0xbf; | |
561 | memcpy(msg_body.self_sta_mac_addr, vif->addr, ETH_ALEN); | |
562 | ||
563 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
564 | ||
565 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
566 | if (ret) { | |
567 | wcn36xx_err("Sending hal_switch_channel failed\n"); | |
568 | goto out; | |
569 | } | |
570 | ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len); | |
571 | if (ret) { | |
572 | wcn36xx_err("hal_switch_channel response failed err=%d\n", ret); | |
573 | goto out; | |
574 | } | |
575 | out: | |
576 | mutex_unlock(&wcn->hal_mutex); | |
577 | return ret; | |
578 | } | |
579 | ||
580 | static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len) | |
581 | { | |
582 | struct wcn36xx_hal_update_scan_params_resp *rsp; | |
583 | ||
584 | rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf; | |
585 | ||
586 | /* Remove the PNO version bit */ | |
587 | rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK)); | |
588 | ||
589 | if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) { | |
590 | wcn36xx_warn("error response from update scan\n"); | |
591 | return rsp->status; | |
592 | } | |
593 | ||
594 | return 0; | |
595 | } | |
596 | ||
597 | int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn) | |
598 | { | |
599 | struct wcn36xx_hal_update_scan_params_req msg_body; | |
600 | int ret = 0; | |
601 | ||
602 | mutex_lock(&wcn->hal_mutex); | |
603 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ); | |
604 | ||
605 | msg_body.dot11d_enabled = 0; | |
606 | msg_body.dot11d_resolved = 0; | |
607 | msg_body.channel_count = 26; | |
608 | msg_body.active_min_ch_time = 60; | |
609 | msg_body.active_max_ch_time = 120; | |
610 | msg_body.passive_min_ch_time = 60; | |
611 | msg_body.passive_max_ch_time = 110; | |
612 | msg_body.state = 0; | |
613 | ||
614 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
615 | ||
616 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
617 | "hal update scan params channel_count %d\n", | |
618 | msg_body.channel_count); | |
619 | ||
620 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
621 | if (ret) { | |
622 | wcn36xx_err("Sending hal_update_scan_params failed\n"); | |
623 | goto out; | |
624 | } | |
625 | ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf, | |
626 | wcn->hal_rsp_len); | |
627 | if (ret) { | |
628 | wcn36xx_err("hal_update_scan_params response failed err=%d\n", | |
629 | ret); | |
630 | goto out; | |
631 | } | |
632 | out: | |
633 | mutex_unlock(&wcn->hal_mutex); | |
634 | return ret; | |
635 | } | |
636 | ||
637 | static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn, | |
638 | struct ieee80211_vif *vif, | |
639 | void *buf, | |
640 | size_t len) | |
641 | { | |
642 | struct wcn36xx_hal_add_sta_self_rsp_msg *rsp; | |
643 | struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv; | |
644 | ||
645 | if (len < sizeof(*rsp)) | |
646 | return -EINVAL; | |
647 | ||
648 | rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf; | |
649 | ||
650 | if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) { | |
651 | wcn36xx_warn("hal add sta self failure: %d\n", | |
652 | rsp->status); | |
653 | return rsp->status; | |
654 | } | |
655 | ||
656 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
657 | "hal add sta self status %d self_sta_index %d dpu_index %d\n", | |
658 | rsp->status, rsp->self_sta_index, rsp->dpu_index); | |
659 | ||
660 | priv_vif->self_sta_index = rsp->self_sta_index; | |
661 | priv_vif->self_dpu_desc_index = rsp->dpu_index; | |
662 | ||
663 | return 0; | |
664 | } | |
665 | ||
666 | int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif) | |
667 | { | |
668 | struct wcn36xx_hal_add_sta_self_req msg_body; | |
669 | int ret = 0; | |
670 | ||
671 | mutex_lock(&wcn->hal_mutex); | |
672 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ); | |
673 | ||
674 | memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN); | |
675 | ||
676 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
677 | ||
678 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
679 | "hal add sta self self_addr %pM status %d\n", | |
680 | msg_body.self_addr, msg_body.status); | |
681 | ||
682 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
683 | if (ret) { | |
684 | wcn36xx_err("Sending hal_add_sta_self failed\n"); | |
685 | goto out; | |
686 | } | |
687 | ret = wcn36xx_smd_add_sta_self_rsp(wcn, | |
688 | vif, | |
689 | wcn->hal_buf, | |
690 | wcn->hal_rsp_len); | |
691 | if (ret) { | |
692 | wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret); | |
693 | goto out; | |
694 | } | |
695 | out: | |
696 | mutex_unlock(&wcn->hal_mutex); | |
697 | return ret; | |
698 | } | |
699 | ||
700 | int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr) | |
701 | { | |
702 | struct wcn36xx_hal_del_sta_self_req_msg msg_body; | |
703 | int ret = 0; | |
704 | ||
705 | mutex_lock(&wcn->hal_mutex); | |
706 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ); | |
707 | ||
708 | memcpy(&msg_body.self_addr, addr, ETH_ALEN); | |
709 | ||
710 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
711 | ||
712 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
713 | if (ret) { | |
714 | wcn36xx_err("Sending hal_delete_sta_self failed\n"); | |
715 | goto out; | |
716 | } | |
717 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
718 | if (ret) { | |
719 | wcn36xx_err("hal_delete_sta_self response failed err=%d\n", | |
720 | ret); | |
721 | goto out; | |
722 | } | |
723 | out: | |
724 | mutex_unlock(&wcn->hal_mutex); | |
725 | return ret; | |
726 | } | |
727 | ||
728 | int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index) | |
729 | { | |
730 | struct wcn36xx_hal_delete_sta_req_msg msg_body; | |
731 | int ret = 0; | |
732 | ||
733 | mutex_lock(&wcn->hal_mutex); | |
734 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ); | |
735 | ||
736 | msg_body.sta_index = sta_index; | |
737 | ||
738 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
739 | ||
740 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
741 | "hal delete sta sta_index %d\n", | |
742 | msg_body.sta_index); | |
743 | ||
744 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
745 | if (ret) { | |
746 | wcn36xx_err("Sending hal_delete_sta failed\n"); | |
747 | goto out; | |
748 | } | |
749 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
750 | if (ret) { | |
751 | wcn36xx_err("hal_delete_sta response failed err=%d\n", ret); | |
752 | goto out; | |
753 | } | |
754 | out: | |
755 | mutex_unlock(&wcn->hal_mutex); | |
756 | return ret; | |
757 | } | |
758 | ||
759 | static int wcn36xx_smd_join_rsp(void *buf, size_t len) | |
760 | { | |
761 | struct wcn36xx_hal_join_rsp_msg *rsp; | |
762 | ||
763 | if (wcn36xx_smd_rsp_status_check(buf, len)) | |
764 | return -EIO; | |
765 | ||
766 | rsp = (struct wcn36xx_hal_join_rsp_msg *)buf; | |
767 | ||
768 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
769 | "hal rsp join status %d tx_mgmt_power %d\n", | |
770 | rsp->status, rsp->tx_mgmt_power); | |
771 | ||
772 | return 0; | |
773 | } | |
774 | ||
775 | int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch) | |
776 | { | |
777 | struct wcn36xx_hal_join_req_msg msg_body; | |
778 | int ret = 0; | |
779 | ||
780 | mutex_lock(&wcn->hal_mutex); | |
781 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ); | |
782 | ||
783 | memcpy(&msg_body.bssid, bssid, ETH_ALEN); | |
784 | memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN); | |
785 | msg_body.channel = ch; | |
786 | ||
787 | if (conf_is_ht40_minus(&wcn->hw->conf)) | |
788 | msg_body.secondary_channel_offset = | |
789 | PHY_DOUBLE_CHANNEL_HIGH_PRIMARY; | |
790 | else if (conf_is_ht40_plus(&wcn->hw->conf)) | |
791 | msg_body.secondary_channel_offset = | |
792 | PHY_DOUBLE_CHANNEL_LOW_PRIMARY; | |
793 | else | |
794 | msg_body.secondary_channel_offset = | |
795 | PHY_SINGLE_CHANNEL_CENTERED; | |
796 | ||
797 | msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE; | |
798 | ||
799 | msg_body.max_tx_power = 0xbf; | |
800 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
801 | ||
802 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
803 | "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n", | |
804 | msg_body.bssid, msg_body.self_sta_mac_addr, | |
805 | msg_body.channel, msg_body.link_state); | |
806 | ||
807 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
808 | if (ret) { | |
809 | wcn36xx_err("Sending hal_join failed\n"); | |
810 | goto out; | |
811 | } | |
812 | ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len); | |
813 | if (ret) { | |
814 | wcn36xx_err("hal_join response failed err=%d\n", ret); | |
815 | goto out; | |
816 | } | |
817 | out: | |
818 | mutex_unlock(&wcn->hal_mutex); | |
819 | return ret; | |
820 | } | |
821 | ||
822 | int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid, | |
823 | const u8 *sta_mac, | |
824 | enum wcn36xx_hal_link_state state) | |
825 | { | |
826 | struct wcn36xx_hal_set_link_state_req_msg msg_body; | |
827 | int ret = 0; | |
828 | ||
829 | mutex_lock(&wcn->hal_mutex); | |
830 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ); | |
831 | ||
832 | memcpy(&msg_body.bssid, bssid, ETH_ALEN); | |
833 | memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN); | |
834 | msg_body.state = state; | |
835 | ||
836 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
837 | ||
838 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
839 | "hal set link state bssid %pM self_mac_addr %pM state %d\n", | |
840 | msg_body.bssid, msg_body.self_mac_addr, msg_body.state); | |
841 | ||
842 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
843 | if (ret) { | |
844 | wcn36xx_err("Sending hal_set_link_st failed\n"); | |
845 | goto out; | |
846 | } | |
847 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
848 | if (ret) { | |
849 | wcn36xx_err("hal_set_link_st response failed err=%d\n", ret); | |
850 | goto out; | |
851 | } | |
852 | out: | |
853 | mutex_unlock(&wcn->hal_mutex); | |
854 | return ret; | |
855 | } | |
856 | ||
857 | static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx *wcn, | |
858 | const struct wcn36xx_hal_config_sta_params *orig, | |
859 | struct wcn36xx_hal_config_sta_params_v1 *v1) | |
860 | { | |
861 | /* convert orig to v1 format */ | |
862 | memcpy(&v1->bssid, orig->bssid, ETH_ALEN); | |
863 | memcpy(&v1->mac, orig->mac, ETH_ALEN); | |
864 | v1->aid = orig->aid; | |
865 | v1->type = orig->type; | |
866 | v1->listen_interval = orig->listen_interval; | |
867 | v1->ht_capable = orig->ht_capable; | |
868 | ||
869 | v1->max_ampdu_size = orig->max_ampdu_size; | |
870 | v1->max_ampdu_density = orig->max_ampdu_density; | |
871 | v1->sgi_40mhz = orig->sgi_40mhz; | |
872 | v1->sgi_20Mhz = orig->sgi_20Mhz; | |
873 | ||
874 | memcpy(&v1->supported_rates, &orig->supported_rates, | |
875 | sizeof(orig->supported_rates)); | |
876 | v1->sta_index = orig->sta_index; | |
877 | } | |
878 | ||
879 | static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn, | |
880 | struct ieee80211_sta *sta, | |
881 | void *buf, | |
882 | size_t len) | |
883 | { | |
884 | struct wcn36xx_hal_config_sta_rsp_msg *rsp; | |
885 | struct config_sta_rsp_params *params; | |
886 | struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv; | |
887 | ||
888 | if (len < sizeof(*rsp)) | |
889 | return -EINVAL; | |
890 | ||
891 | rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf; | |
892 | params = &rsp->params; | |
893 | ||
894 | if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) { | |
895 | wcn36xx_warn("hal config sta response failure: %d\n", | |
896 | params->status); | |
897 | return -EIO; | |
898 | } | |
899 | ||
900 | sta_priv->sta_index = params->sta_index; | |
901 | sta_priv->dpu_desc_index = params->dpu_index; | |
902 | ||
903 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
904 | "hal config sta rsp status %d sta_index %d bssid_index %d p2p %d\n", | |
905 | params->status, params->sta_index, params->bssid_index, | |
906 | params->p2p); | |
907 | ||
908 | return 0; | |
909 | } | |
910 | ||
911 | static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn, | |
912 | const struct wcn36xx_hal_config_sta_req_msg *orig) | |
913 | { | |
914 | struct wcn36xx_hal_config_sta_req_msg_v1 msg_body; | |
915 | struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params; | |
916 | ||
917 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ); | |
918 | ||
919 | wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params, | |
920 | &msg_body.sta_params); | |
921 | ||
922 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
923 | ||
924 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
925 | "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n", | |
926 | sta->action, sta->sta_index, sta->bssid_index, | |
927 | sta->bssid, sta->type, sta->mac, sta->aid); | |
928 | ||
929 | return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
930 | } | |
931 | ||
932 | int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif, | |
933 | struct ieee80211_sta *sta) | |
934 | { | |
935 | struct wcn36xx_hal_config_sta_req_msg msg; | |
936 | struct wcn36xx_hal_config_sta_params *sta_params; | |
937 | int ret = 0; | |
938 | ||
939 | mutex_lock(&wcn->hal_mutex); | |
940 | INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ); | |
941 | ||
942 | sta_params = &msg.sta_params; | |
943 | ||
944 | wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params); | |
945 | ||
946 | if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) { | |
947 | ret = wcn36xx_smd_config_sta_v1(wcn, &msg); | |
948 | } else { | |
949 | PREPARE_HAL_BUF(wcn->hal_buf, msg); | |
950 | ||
951 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
952 | "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n", | |
953 | sta_params->action, sta_params->sta_index, | |
954 | sta_params->bssid_index, sta_params->bssid, | |
955 | sta_params->type, sta_params->mac, sta_params->aid); | |
956 | ||
957 | ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len); | |
958 | } | |
959 | if (ret) { | |
960 | wcn36xx_err("Sending hal_config_sta failed\n"); | |
961 | goto out; | |
962 | } | |
963 | ret = wcn36xx_smd_config_sta_rsp(wcn, | |
964 | sta, | |
965 | wcn->hal_buf, | |
966 | wcn->hal_rsp_len); | |
967 | if (ret) { | |
968 | wcn36xx_err("hal_config_sta response failed err=%d\n", ret); | |
969 | goto out; | |
970 | } | |
971 | out: | |
972 | mutex_unlock(&wcn->hal_mutex); | |
973 | return ret; | |
974 | } | |
975 | ||
976 | static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn, | |
977 | const struct wcn36xx_hal_config_bss_req_msg *orig) | |
978 | { | |
979 | struct wcn36xx_hal_config_bss_req_msg_v1 msg_body; | |
980 | struct wcn36xx_hal_config_bss_params_v1 *bss = &msg_body.bss_params; | |
981 | struct wcn36xx_hal_config_sta_params_v1 *sta = &bss->sta; | |
982 | ||
983 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ); | |
984 | ||
985 | /* convert orig to v1 */ | |
986 | memcpy(&msg_body.bss_params.bssid, | |
987 | &orig->bss_params.bssid, ETH_ALEN); | |
988 | memcpy(&msg_body.bss_params.self_mac_addr, | |
989 | &orig->bss_params.self_mac_addr, ETH_ALEN); | |
990 | ||
991 | msg_body.bss_params.bss_type = orig->bss_params.bss_type; | |
992 | msg_body.bss_params.oper_mode = orig->bss_params.oper_mode; | |
993 | msg_body.bss_params.nw_type = orig->bss_params.nw_type; | |
994 | ||
995 | msg_body.bss_params.short_slot_time_supported = | |
996 | orig->bss_params.short_slot_time_supported; | |
997 | msg_body.bss_params.lla_coexist = orig->bss_params.lla_coexist; | |
998 | msg_body.bss_params.llb_coexist = orig->bss_params.llb_coexist; | |
999 | msg_body.bss_params.llg_coexist = orig->bss_params.llg_coexist; | |
1000 | msg_body.bss_params.ht20_coexist = orig->bss_params.ht20_coexist; | |
1001 | msg_body.bss_params.lln_non_gf_coexist = | |
1002 | orig->bss_params.lln_non_gf_coexist; | |
1003 | ||
1004 | msg_body.bss_params.lsig_tx_op_protection_full_support = | |
1005 | orig->bss_params.lsig_tx_op_protection_full_support; | |
1006 | msg_body.bss_params.rifs_mode = orig->bss_params.rifs_mode; | |
1007 | msg_body.bss_params.beacon_interval = orig->bss_params.beacon_interval; | |
1008 | msg_body.bss_params.dtim_period = orig->bss_params.dtim_period; | |
1009 | msg_body.bss_params.tx_channel_width_set = | |
1010 | orig->bss_params.tx_channel_width_set; | |
1011 | msg_body.bss_params.oper_channel = orig->bss_params.oper_channel; | |
1012 | msg_body.bss_params.ext_channel = orig->bss_params.ext_channel; | |
1013 | ||
1014 | msg_body.bss_params.reserved = orig->bss_params.reserved; | |
1015 | ||
1016 | memcpy(&msg_body.bss_params.ssid, | |
1017 | &orig->bss_params.ssid, | |
1018 | sizeof(orig->bss_params.ssid)); | |
1019 | ||
1020 | msg_body.bss_params.action = orig->bss_params.action; | |
1021 | msg_body.bss_params.rateset = orig->bss_params.rateset; | |
1022 | msg_body.bss_params.ht = orig->bss_params.ht; | |
1023 | msg_body.bss_params.obss_prot_enabled = | |
1024 | orig->bss_params.obss_prot_enabled; | |
1025 | msg_body.bss_params.rmf = orig->bss_params.rmf; | |
1026 | msg_body.bss_params.ht_oper_mode = orig->bss_params.ht_oper_mode; | |
1027 | msg_body.bss_params.dual_cts_protection = | |
1028 | orig->bss_params.dual_cts_protection; | |
1029 | ||
1030 | msg_body.bss_params.max_probe_resp_retry_limit = | |
1031 | orig->bss_params.max_probe_resp_retry_limit; | |
1032 | msg_body.bss_params.hidden_ssid = orig->bss_params.hidden_ssid; | |
1033 | msg_body.bss_params.proxy_probe_resp = | |
1034 | orig->bss_params.proxy_probe_resp; | |
1035 | msg_body.bss_params.edca_params_valid = | |
1036 | orig->bss_params.edca_params_valid; | |
1037 | ||
1038 | memcpy(&msg_body.bss_params.acbe, | |
1039 | &orig->bss_params.acbe, | |
1040 | sizeof(orig->bss_params.acbe)); | |
1041 | memcpy(&msg_body.bss_params.acbk, | |
1042 | &orig->bss_params.acbk, | |
1043 | sizeof(orig->bss_params.acbk)); | |
1044 | memcpy(&msg_body.bss_params.acvi, | |
1045 | &orig->bss_params.acvi, | |
1046 | sizeof(orig->bss_params.acvi)); | |
1047 | memcpy(&msg_body.bss_params.acvo, | |
1048 | &orig->bss_params.acvo, | |
1049 | sizeof(orig->bss_params.acvo)); | |
1050 | ||
1051 | msg_body.bss_params.ext_set_sta_key_param_valid = | |
1052 | orig->bss_params.ext_set_sta_key_param_valid; | |
1053 | ||
1054 | memcpy(&msg_body.bss_params.ext_set_sta_key_param, | |
1055 | &orig->bss_params.ext_set_sta_key_param, | |
1056 | sizeof(orig->bss_params.acvo)); | |
1057 | ||
1058 | msg_body.bss_params.wcn36xx_hal_persona = | |
1059 | orig->bss_params.wcn36xx_hal_persona; | |
1060 | msg_body.bss_params.spectrum_mgt_enable = | |
1061 | orig->bss_params.spectrum_mgt_enable; | |
1062 | msg_body.bss_params.tx_mgmt_power = orig->bss_params.tx_mgmt_power; | |
1063 | msg_body.bss_params.max_tx_power = orig->bss_params.max_tx_power; | |
1064 | ||
1065 | wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta, | |
1066 | &msg_body.bss_params.sta); | |
1067 | ||
1068 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1069 | ||
1070 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1071 | "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n", | |
1072 | bss->bssid, bss->self_mac_addr, bss->bss_type, | |
1073 | bss->oper_mode, bss->nw_type); | |
1074 | ||
1075 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1076 | "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n", | |
1077 | sta->bssid, sta->action, sta->sta_index, | |
1078 | sta->bssid_index, sta->aid, sta->type, sta->mac); | |
1079 | ||
1080 | return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1081 | } | |
1082 | ||
1083 | ||
1084 | static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn, | |
1085 | struct ieee80211_vif *vif, | |
1086 | void *buf, | |
1087 | size_t len) | |
1088 | { | |
1089 | struct wcn36xx_hal_config_bss_rsp_msg *rsp; | |
1090 | struct wcn36xx_hal_config_bss_rsp_params *params; | |
1091 | struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv; | |
1092 | ||
1093 | if (len < sizeof(*rsp)) | |
1094 | return -EINVAL; | |
1095 | ||
1096 | rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf; | |
1097 | params = &rsp->bss_rsp_params; | |
1098 | ||
1099 | if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) { | |
1100 | wcn36xx_warn("hal config bss response failure: %d\n", | |
1101 | params->status); | |
1102 | return -EIO; | |
1103 | } | |
1104 | ||
1105 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1106 | "hal config bss rsp status %d bss_idx %d dpu_desc_index %d" | |
1107 | " sta_idx %d self_idx %d bcast_idx %d mac %pM" | |
1108 | " power %d ucast_dpu_signature %d\n", | |
1109 | params->status, params->bss_index, params->dpu_desc_index, | |
1110 | params->bss_sta_index, params->bss_self_sta_index, | |
1111 | params->bss_bcast_sta_idx, params->mac, | |
1112 | params->tx_mgmt_power, params->ucast_dpu_signature); | |
1113 | ||
1114 | priv_vif->bss_index = params->bss_index; | |
1115 | ||
1116 | if (priv_vif->sta) { | |
1117 | priv_vif->sta->bss_sta_index = params->bss_sta_index; | |
1118 | priv_vif->sta->bss_dpu_desc_index = params->dpu_desc_index; | |
1119 | } | |
1120 | ||
1121 | priv_vif->ucast_dpu_signature = params->ucast_dpu_signature; | |
1122 | ||
1123 | return 0; | |
1124 | } | |
1125 | ||
1126 | int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif, | |
1127 | struct ieee80211_sta *sta, const u8 *bssid, | |
1128 | bool update) | |
1129 | { | |
1130 | struct wcn36xx_hal_config_bss_req_msg msg; | |
1131 | struct wcn36xx_hal_config_bss_params *bss; | |
1132 | struct wcn36xx_hal_config_sta_params *sta_params; | |
1133 | struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv; | |
1134 | int ret = 0; | |
1135 | ||
1136 | mutex_lock(&wcn->hal_mutex); | |
1137 | INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ); | |
1138 | ||
1139 | bss = &msg.bss_params; | |
1140 | sta_params = &bss->sta; | |
1141 | ||
1142 | WARN_ON(is_zero_ether_addr(bssid)); | |
1143 | ||
1144 | memcpy(&bss->bssid, bssid, ETH_ALEN); | |
1145 | ||
1146 | memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN); | |
1147 | ||
1148 | if (vif->type == NL80211_IFTYPE_STATION) { | |
1149 | bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE; | |
1150 | ||
1151 | /* STA */ | |
1152 | bss->oper_mode = 1; | |
1153 | bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_MODE; | |
1154 | } else if (vif->type == NL80211_IFTYPE_AP) { | |
1155 | bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE; | |
1156 | ||
1157 | /* AP */ | |
1158 | bss->oper_mode = 0; | |
1159 | bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE; | |
1160 | } else if (vif->type == NL80211_IFTYPE_ADHOC || | |
1161 | vif->type == NL80211_IFTYPE_MESH_POINT) { | |
1162 | bss->bss_type = WCN36XX_HAL_IBSS_MODE; | |
1163 | ||
1164 | /* STA */ | |
1165 | bss->oper_mode = 1; | |
1166 | } else { | |
1167 | wcn36xx_warn("Unknown type for bss config: %d\n", vif->type); | |
1168 | } | |
1169 | ||
1170 | if (vif->type == NL80211_IFTYPE_STATION) | |
1171 | wcn36xx_smd_set_bss_nw_type(wcn, sta, bss); | |
1172 | else | |
1173 | bss->nw_type = WCN36XX_HAL_11N_NW_TYPE; | |
1174 | ||
1175 | bss->short_slot_time_supported = vif->bss_conf.use_short_slot; | |
1176 | bss->lla_coexist = 0; | |
1177 | bss->llb_coexist = 0; | |
1178 | bss->llg_coexist = 0; | |
1179 | bss->rifs_mode = 0; | |
1180 | bss->beacon_interval = vif->bss_conf.beacon_int; | |
1181 | bss->dtim_period = vif_priv->dtim_period; | |
1182 | ||
1183 | wcn36xx_smd_set_bss_ht_params(vif, sta, bss); | |
1184 | ||
1185 | bss->oper_channel = WCN36XX_HW_CHANNEL(wcn); | |
1186 | ||
1187 | if (conf_is_ht40_minus(&wcn->hw->conf)) | |
1188 | bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_BELOW; | |
1189 | else if (conf_is_ht40_plus(&wcn->hw->conf)) | |
1190 | bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | |
1191 | else | |
1192 | bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE; | |
1193 | ||
1194 | bss->reserved = 0; | |
1195 | wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params); | |
1196 | ||
1197 | /* wcn->ssid is only valid in AP and IBSS mode */ | |
1198 | bss->ssid.length = vif_priv->ssid.length; | |
1199 | memcpy(bss->ssid.ssid, vif_priv->ssid.ssid, vif_priv->ssid.length); | |
1200 | ||
1201 | bss->obss_prot_enabled = 0; | |
1202 | bss->rmf = 0; | |
1203 | bss->max_probe_resp_retry_limit = 0; | |
1204 | bss->hidden_ssid = vif->bss_conf.hidden_ssid; | |
1205 | bss->proxy_probe_resp = 0; | |
1206 | bss->edca_params_valid = 0; | |
1207 | ||
1208 | /* FIXME: set acbe, acbk, acvi and acvo */ | |
1209 | ||
1210 | bss->ext_set_sta_key_param_valid = 0; | |
1211 | ||
1212 | /* FIXME: set ext_set_sta_key_param */ | |
1213 | ||
1214 | bss->spectrum_mgt_enable = 0; | |
1215 | bss->tx_mgmt_power = 0; | |
1216 | bss->max_tx_power = WCN36XX_MAX_POWER(wcn); | |
1217 | ||
1218 | bss->action = update; | |
1219 | ||
1220 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1221 | "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n", | |
1222 | bss->bssid, bss->self_mac_addr, bss->bss_type, | |
1223 | bss->oper_mode, bss->nw_type); | |
1224 | ||
1225 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1226 | "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n", | |
1227 | sta_params->bssid, sta_params->action, | |
1228 | sta_params->sta_index, sta_params->bssid_index, | |
1229 | sta_params->aid, sta_params->type, | |
1230 | sta_params->mac); | |
1231 | ||
1232 | if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) { | |
1233 | ret = wcn36xx_smd_config_bss_v1(wcn, &msg); | |
1234 | } else { | |
1235 | PREPARE_HAL_BUF(wcn->hal_buf, msg); | |
1236 | ||
1237 | ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len); | |
1238 | } | |
1239 | if (ret) { | |
1240 | wcn36xx_err("Sending hal_config_bss failed\n"); | |
1241 | goto out; | |
1242 | } | |
1243 | ret = wcn36xx_smd_config_bss_rsp(wcn, | |
1244 | vif, | |
1245 | wcn->hal_buf, | |
1246 | wcn->hal_rsp_len); | |
1247 | if (ret) { | |
1248 | wcn36xx_err("hal_config_bss response failed err=%d\n", ret); | |
1249 | goto out; | |
1250 | } | |
1251 | out: | |
1252 | mutex_unlock(&wcn->hal_mutex); | |
1253 | return ret; | |
1254 | } | |
1255 | ||
1256 | int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif) | |
1257 | { | |
1258 | struct wcn36xx_hal_delete_bss_req_msg msg_body; | |
1259 | struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv; | |
1260 | int ret = 0; | |
1261 | ||
1262 | mutex_lock(&wcn->hal_mutex); | |
1263 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ); | |
1264 | ||
1265 | msg_body.bss_index = priv_vif->bss_index; | |
1266 | ||
1267 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1268 | ||
1269 | wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index); | |
1270 | ||
1271 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1272 | if (ret) { | |
1273 | wcn36xx_err("Sending hal_delete_bss failed\n"); | |
1274 | goto out; | |
1275 | } | |
1276 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1277 | if (ret) { | |
1278 | wcn36xx_err("hal_delete_bss response failed err=%d\n", ret); | |
1279 | goto out; | |
1280 | } | |
1281 | out: | |
1282 | mutex_unlock(&wcn->hal_mutex); | |
1283 | return ret; | |
1284 | } | |
1285 | ||
1286 | int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif, | |
1287 | struct sk_buff *skb_beacon, u16 tim_off, | |
1288 | u16 p2p_off) | |
1289 | { | |
1290 | struct wcn36xx_hal_send_beacon_req_msg msg_body; | |
1291 | int ret = 0; | |
1292 | ||
1293 | mutex_lock(&wcn->hal_mutex); | |
1294 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ); | |
1295 | ||
1296 | /* TODO need to find out why this is needed? */ | |
1297 | msg_body.beacon_length = skb_beacon->len + 6; | |
1298 | ||
1299 | if (BEACON_TEMPLATE_SIZE > msg_body.beacon_length) { | |
1300 | memcpy(&msg_body.beacon, &skb_beacon->len, sizeof(u32)); | |
1301 | memcpy(&(msg_body.beacon[4]), skb_beacon->data, | |
1302 | skb_beacon->len); | |
1303 | } else { | |
1304 | wcn36xx_err("Beacon is to big: beacon size=%d\n", | |
1305 | msg_body.beacon_length); | |
95b48c2c DC |
1306 | ret = -ENOMEM; |
1307 | goto out; | |
8e84c258 EK |
1308 | } |
1309 | memcpy(msg_body.bssid, vif->addr, ETH_ALEN); | |
1310 | ||
1311 | /* TODO need to find out why this is needed? */ | |
1312 | msg_body.tim_ie_offset = tim_off+4; | |
1313 | msg_body.p2p_ie_offset = p2p_off; | |
1314 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1315 | ||
1316 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1317 | "hal send beacon beacon_length %d\n", | |
1318 | msg_body.beacon_length); | |
1319 | ||
1320 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1321 | if (ret) { | |
1322 | wcn36xx_err("Sending hal_send_beacon failed\n"); | |
1323 | goto out; | |
1324 | } | |
1325 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1326 | if (ret) { | |
1327 | wcn36xx_err("hal_send_beacon response failed err=%d\n", ret); | |
1328 | goto out; | |
1329 | } | |
1330 | out: | |
1331 | mutex_unlock(&wcn->hal_mutex); | |
1332 | return ret; | |
1333 | } | |
1334 | ||
1335 | int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn, | |
1336 | struct ieee80211_vif *vif, | |
1337 | struct sk_buff *skb) | |
1338 | { | |
1339 | struct wcn36xx_hal_send_probe_resp_req_msg msg; | |
1340 | int ret = 0; | |
1341 | ||
1342 | mutex_lock(&wcn->hal_mutex); | |
1343 | INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ); | |
1344 | ||
1345 | if (skb->len > BEACON_TEMPLATE_SIZE) { | |
1346 | wcn36xx_warn("probe response template is too big: %d\n", | |
1347 | skb->len); | |
1221c25a WY |
1348 | ret = -E2BIG; |
1349 | goto out; | |
8e84c258 EK |
1350 | } |
1351 | ||
1352 | msg.probe_resp_template_len = skb->len; | |
1353 | memcpy(&msg.probe_resp_template, skb->data, skb->len); | |
1354 | ||
1355 | memcpy(msg.bssid, vif->addr, ETH_ALEN); | |
1356 | ||
1357 | PREPARE_HAL_BUF(wcn->hal_buf, msg); | |
1358 | ||
1359 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1360 | "hal update probe rsp len %d bssid %pM\n", | |
1361 | msg.probe_resp_template_len, msg.bssid); | |
1362 | ||
1363 | ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len); | |
1364 | if (ret) { | |
1365 | wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n"); | |
1366 | goto out; | |
1367 | } | |
1368 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1369 | if (ret) { | |
1370 | wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n", | |
1371 | ret); | |
1372 | goto out; | |
1373 | } | |
1374 | out: | |
1375 | mutex_unlock(&wcn->hal_mutex); | |
1376 | return ret; | |
1377 | } | |
1378 | ||
1379 | int wcn36xx_smd_set_stakey(struct wcn36xx *wcn, | |
1380 | enum ani_ed_type enc_type, | |
1381 | u8 keyidx, | |
1382 | u8 keylen, | |
1383 | u8 *key, | |
1384 | u8 sta_index) | |
1385 | { | |
1386 | struct wcn36xx_hal_set_sta_key_req_msg msg_body; | |
1387 | int ret = 0; | |
1388 | ||
1389 | mutex_lock(&wcn->hal_mutex); | |
1390 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ); | |
1391 | ||
1392 | msg_body.set_sta_key_params.sta_index = sta_index; | |
1393 | msg_body.set_sta_key_params.enc_type = enc_type; | |
1394 | ||
1395 | msg_body.set_sta_key_params.key[0].id = keyidx; | |
1396 | msg_body.set_sta_key_params.key[0].unicast = 1; | |
1397 | msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX; | |
1398 | msg_body.set_sta_key_params.key[0].pae_role = 0; | |
1399 | msg_body.set_sta_key_params.key[0].length = keylen; | |
1400 | memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen); | |
1401 | msg_body.set_sta_key_params.single_tid_rc = 1; | |
1402 | ||
1403 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1404 | ||
1405 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1406 | if (ret) { | |
1407 | wcn36xx_err("Sending hal_set_stakey failed\n"); | |
1408 | goto out; | |
1409 | } | |
1410 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1411 | if (ret) { | |
1412 | wcn36xx_err("hal_set_stakey response failed err=%d\n", ret); | |
1413 | goto out; | |
1414 | } | |
1415 | out: | |
1416 | mutex_unlock(&wcn->hal_mutex); | |
1417 | return ret; | |
1418 | } | |
1419 | ||
1420 | int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn, | |
1421 | enum ani_ed_type enc_type, | |
1422 | u8 keyidx, | |
1423 | u8 keylen, | |
1424 | u8 *key) | |
1425 | { | |
1426 | struct wcn36xx_hal_set_bss_key_req_msg msg_body; | |
1427 | int ret = 0; | |
1428 | ||
1429 | mutex_lock(&wcn->hal_mutex); | |
1430 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ); | |
1431 | msg_body.bss_idx = 0; | |
1432 | msg_body.enc_type = enc_type; | |
1433 | msg_body.num_keys = 1; | |
1434 | msg_body.keys[0].id = keyidx; | |
1435 | msg_body.keys[0].unicast = 0; | |
1436 | msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY; | |
1437 | msg_body.keys[0].pae_role = 0; | |
1438 | msg_body.keys[0].length = keylen; | |
1439 | memcpy(msg_body.keys[0].key, key, keylen); | |
1440 | ||
1441 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1442 | ||
1443 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1444 | if (ret) { | |
1445 | wcn36xx_err("Sending hal_set_bsskey failed\n"); | |
1446 | goto out; | |
1447 | } | |
1448 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1449 | if (ret) { | |
1450 | wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret); | |
1451 | goto out; | |
1452 | } | |
1453 | out: | |
1454 | mutex_unlock(&wcn->hal_mutex); | |
1455 | return ret; | |
1456 | } | |
1457 | ||
1458 | int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn, | |
1459 | enum ani_ed_type enc_type, | |
1460 | u8 keyidx, | |
1461 | u8 sta_index) | |
1462 | { | |
1463 | struct wcn36xx_hal_remove_sta_key_req_msg msg_body; | |
1464 | int ret = 0; | |
1465 | ||
1466 | mutex_lock(&wcn->hal_mutex); | |
1467 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ); | |
1468 | ||
1469 | msg_body.sta_idx = sta_index; | |
1470 | msg_body.enc_type = enc_type; | |
1471 | msg_body.key_id = keyidx; | |
1472 | ||
1473 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1474 | ||
1475 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1476 | if (ret) { | |
1477 | wcn36xx_err("Sending hal_remove_stakey failed\n"); | |
1478 | goto out; | |
1479 | } | |
1480 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1481 | if (ret) { | |
1482 | wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret); | |
1483 | goto out; | |
1484 | } | |
1485 | out: | |
1486 | mutex_unlock(&wcn->hal_mutex); | |
1487 | return ret; | |
1488 | } | |
1489 | ||
1490 | int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn, | |
1491 | enum ani_ed_type enc_type, | |
1492 | u8 keyidx) | |
1493 | { | |
1494 | struct wcn36xx_hal_remove_bss_key_req_msg msg_body; | |
1495 | int ret = 0; | |
1496 | ||
1497 | mutex_lock(&wcn->hal_mutex); | |
1498 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ); | |
1499 | msg_body.bss_idx = 0; | |
1500 | msg_body.enc_type = enc_type; | |
1501 | msg_body.key_id = keyidx; | |
1502 | ||
1503 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1504 | ||
1505 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1506 | if (ret) { | |
1507 | wcn36xx_err("Sending hal_remove_bsskey failed\n"); | |
1508 | goto out; | |
1509 | } | |
1510 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1511 | if (ret) { | |
1512 | wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret); | |
1513 | goto out; | |
1514 | } | |
1515 | out: | |
1516 | mutex_unlock(&wcn->hal_mutex); | |
1517 | return ret; | |
1518 | } | |
1519 | ||
1520 | int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif) | |
1521 | { | |
1522 | struct wcn36xx_hal_enter_bmps_req_msg msg_body; | |
1523 | struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv; | |
1524 | int ret = 0; | |
1525 | ||
1526 | mutex_lock(&wcn->hal_mutex); | |
1527 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ); | |
1528 | ||
1529 | msg_body.bss_index = vif_priv->bss_index; | |
1530 | msg_body.tbtt = vif->bss_conf.sync_tsf; | |
1531 | msg_body.dtim_period = vif_priv->dtim_period; | |
1532 | ||
1533 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1534 | ||
1535 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1536 | if (ret) { | |
1537 | wcn36xx_err("Sending hal_enter_bmps failed\n"); | |
1538 | goto out; | |
1539 | } | |
1540 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1541 | if (ret) { | |
1542 | wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret); | |
1543 | goto out; | |
1544 | } | |
1545 | out: | |
1546 | mutex_unlock(&wcn->hal_mutex); | |
1547 | return ret; | |
1548 | } | |
1549 | ||
1550 | int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif) | |
1551 | { | |
1552 | struct wcn36xx_hal_enter_bmps_req_msg msg_body; | |
1553 | struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv; | |
1554 | int ret = 0; | |
1555 | ||
1556 | mutex_lock(&wcn->hal_mutex); | |
1557 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ); | |
1558 | ||
1559 | msg_body.bss_index = vif_priv->bss_index; | |
1560 | ||
1561 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1562 | ||
1563 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1564 | if (ret) { | |
1565 | wcn36xx_err("Sending hal_exit_bmps failed\n"); | |
1566 | goto out; | |
1567 | } | |
1568 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1569 | if (ret) { | |
1570 | wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret); | |
1571 | goto out; | |
1572 | } | |
1573 | out: | |
1574 | mutex_unlock(&wcn->hal_mutex); | |
1575 | return ret; | |
1576 | } | |
1577 | int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim) | |
1578 | { | |
1579 | struct wcn36xx_hal_set_power_params_req_msg msg_body; | |
1580 | int ret = 0; | |
1581 | ||
1582 | mutex_lock(&wcn->hal_mutex); | |
1583 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ); | |
1584 | ||
1585 | /* | |
1586 | * When host is down ignore every second dtim | |
1587 | */ | |
1588 | if (ignore_dtim) { | |
1589 | msg_body.ignore_dtim = 1; | |
1590 | msg_body.dtim_period = 2; | |
1591 | } | |
1592 | msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn); | |
1593 | ||
1594 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1595 | ||
1596 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1597 | if (ret) { | |
1598 | wcn36xx_err("Sending hal_set_power_params failed\n"); | |
1599 | goto out; | |
1600 | } | |
1601 | ||
1602 | out: | |
1603 | mutex_unlock(&wcn->hal_mutex); | |
1604 | return ret; | |
1605 | } | |
1606 | /* Notice: This function should be called after associated, or else it | |
1607 | * will be invalid | |
1608 | */ | |
1609 | int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn, | |
1610 | struct ieee80211_vif *vif, | |
1611 | int packet_type) | |
1612 | { | |
1613 | struct wcn36xx_hal_keep_alive_req_msg msg_body; | |
1614 | struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv; | |
1615 | int ret = 0; | |
1616 | ||
1617 | mutex_lock(&wcn->hal_mutex); | |
1618 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ); | |
1619 | ||
1620 | if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) { | |
1621 | msg_body.bss_index = vif_priv->bss_index; | |
1622 | msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT; | |
1623 | msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD; | |
1624 | } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) { | |
1625 | /* TODO: it also support ARP response type */ | |
1626 | } else { | |
1627 | wcn36xx_warn("unknow keep alive packet type %d\n", packet_type); | |
95b48c2c DC |
1628 | ret = -EINVAL; |
1629 | goto out; | |
8e84c258 EK |
1630 | } |
1631 | ||
1632 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1633 | ||
1634 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1635 | if (ret) { | |
1636 | wcn36xx_err("Sending hal_exit_bmps failed\n"); | |
1637 | goto out; | |
1638 | } | |
1639 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1640 | if (ret) { | |
1641 | wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret); | |
1642 | goto out; | |
1643 | } | |
1644 | out: | |
1645 | mutex_unlock(&wcn->hal_mutex); | |
1646 | return ret; | |
1647 | } | |
1648 | ||
1649 | int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2, | |
1650 | u32 arg3, u32 arg4, u32 arg5) | |
1651 | { | |
1652 | struct wcn36xx_hal_dump_cmd_req_msg msg_body; | |
1653 | int ret = 0; | |
1654 | ||
1655 | mutex_lock(&wcn->hal_mutex); | |
1656 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ); | |
1657 | ||
1658 | msg_body.arg1 = arg1; | |
1659 | msg_body.arg2 = arg2; | |
1660 | msg_body.arg3 = arg3; | |
1661 | msg_body.arg4 = arg4; | |
1662 | msg_body.arg5 = arg5; | |
1663 | ||
1664 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1665 | ||
1666 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1667 | if (ret) { | |
1668 | wcn36xx_err("Sending hal_dump_cmd failed\n"); | |
1669 | goto out; | |
1670 | } | |
1671 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1672 | if (ret) { | |
1673 | wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret); | |
1674 | goto out; | |
1675 | } | |
1676 | out: | |
1677 | mutex_unlock(&wcn->hal_mutex); | |
1678 | return ret; | |
1679 | } | |
1680 | ||
1681 | static inline void set_feat_caps(u32 *bitmap, | |
1682 | enum place_holder_in_cap_bitmap cap) | |
1683 | { | |
1684 | int arr_idx, bit_idx; | |
1685 | ||
1686 | if (cap < 0 || cap > 127) { | |
1687 | wcn36xx_warn("error cap idx %d\n", cap); | |
1688 | return; | |
1689 | } | |
1690 | ||
1691 | arr_idx = cap / 32; | |
1692 | bit_idx = cap % 32; | |
1693 | bitmap[arr_idx] |= (1 << bit_idx); | |
1694 | } | |
1695 | ||
1696 | static inline int get_feat_caps(u32 *bitmap, | |
1697 | enum place_holder_in_cap_bitmap cap) | |
1698 | { | |
1699 | int arr_idx, bit_idx; | |
1700 | int ret = 0; | |
1701 | ||
1702 | if (cap < 0 || cap > 127) { | |
1703 | wcn36xx_warn("error cap idx %d\n", cap); | |
1704 | return -EINVAL; | |
1705 | } | |
1706 | ||
1707 | arr_idx = cap / 32; | |
1708 | bit_idx = cap % 32; | |
1709 | ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0; | |
1710 | return ret; | |
1711 | } | |
1712 | ||
1713 | static inline void clear_feat_caps(u32 *bitmap, | |
1714 | enum place_holder_in_cap_bitmap cap) | |
1715 | { | |
1716 | int arr_idx, bit_idx; | |
1717 | ||
1718 | if (cap < 0 || cap > 127) { | |
1719 | wcn36xx_warn("error cap idx %d\n", cap); | |
1720 | return; | |
1721 | } | |
1722 | ||
1723 | arr_idx = cap / 32; | |
1724 | bit_idx = cap % 32; | |
1725 | bitmap[arr_idx] &= ~(1 << bit_idx); | |
1726 | } | |
1727 | ||
1728 | int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn) | |
1729 | { | |
1730 | struct wcn36xx_hal_feat_caps_msg msg_body; | |
1731 | int ret = 0; | |
1732 | ||
1733 | mutex_lock(&wcn->hal_mutex); | |
1734 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ); | |
1735 | ||
1736 | set_feat_caps(msg_body.feat_caps, STA_POWERSAVE); | |
1737 | ||
1738 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1739 | ||
1740 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1741 | if (ret) { | |
1742 | wcn36xx_err("Sending hal_feature_caps_exchange failed\n"); | |
1743 | goto out; | |
1744 | } | |
1745 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1746 | if (ret) { | |
1747 | wcn36xx_err("hal_feature_caps_exchange response failed err=%d\n", | |
1748 | ret); | |
1749 | goto out; | |
1750 | } | |
1751 | out: | |
1752 | mutex_unlock(&wcn->hal_mutex); | |
1753 | return ret; | |
1754 | } | |
1755 | ||
1756 | int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn, | |
1757 | struct ieee80211_sta *sta, | |
1758 | u16 tid, | |
1759 | u16 *ssn, | |
1760 | u8 direction, | |
1761 | u8 sta_index) | |
1762 | { | |
1763 | struct wcn36xx_hal_add_ba_session_req_msg msg_body; | |
1764 | int ret = 0; | |
1765 | ||
1766 | mutex_lock(&wcn->hal_mutex); | |
1767 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ); | |
1768 | ||
1769 | msg_body.sta_index = sta_index; | |
1770 | memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN); | |
1771 | msg_body.dialog_token = 0x10; | |
1772 | msg_body.tid = tid; | |
1773 | ||
1774 | /* Immediate BA because Delayed BA is not supported */ | |
1775 | msg_body.policy = 1; | |
1776 | msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE; | |
1777 | msg_body.timeout = 0; | |
1778 | if (ssn) | |
1779 | msg_body.ssn = *ssn; | |
1780 | msg_body.direction = direction; | |
1781 | ||
1782 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1783 | ||
1784 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1785 | if (ret) { | |
1786 | wcn36xx_err("Sending hal_add_ba_session failed\n"); | |
1787 | goto out; | |
1788 | } | |
1789 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1790 | if (ret) { | |
1791 | wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret); | |
1792 | goto out; | |
1793 | } | |
1794 | out: | |
1795 | mutex_unlock(&wcn->hal_mutex); | |
1796 | return ret; | |
1797 | } | |
1798 | ||
1799 | int wcn36xx_smd_add_ba(struct wcn36xx *wcn) | |
1800 | { | |
1801 | struct wcn36xx_hal_add_ba_req_msg msg_body; | |
1802 | int ret = 0; | |
1803 | ||
1804 | mutex_lock(&wcn->hal_mutex); | |
1805 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ); | |
1806 | ||
1807 | msg_body.session_id = 0; | |
1808 | msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE; | |
1809 | ||
1810 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1811 | ||
1812 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1813 | if (ret) { | |
1814 | wcn36xx_err("Sending hal_add_ba failed\n"); | |
1815 | goto out; | |
1816 | } | |
1817 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1818 | if (ret) { | |
1819 | wcn36xx_err("hal_add_ba response failed err=%d\n", ret); | |
1820 | goto out; | |
1821 | } | |
1822 | out: | |
1823 | mutex_unlock(&wcn->hal_mutex); | |
1824 | return ret; | |
1825 | } | |
1826 | ||
1827 | int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index) | |
1828 | { | |
1829 | struct wcn36xx_hal_del_ba_req_msg msg_body; | |
1830 | int ret = 0; | |
1831 | ||
1832 | mutex_lock(&wcn->hal_mutex); | |
1833 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ); | |
1834 | ||
1835 | msg_body.sta_index = sta_index; | |
1836 | msg_body.tid = tid; | |
1837 | msg_body.direction = 0; | |
1838 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1839 | ||
1840 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1841 | if (ret) { | |
1842 | wcn36xx_err("Sending hal_del_ba failed\n"); | |
1843 | goto out; | |
1844 | } | |
1845 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1846 | if (ret) { | |
1847 | wcn36xx_err("hal_del_ba response failed err=%d\n", ret); | |
1848 | goto out; | |
1849 | } | |
1850 | out: | |
1851 | mutex_unlock(&wcn->hal_mutex); | |
1852 | return ret; | |
1853 | } | |
1854 | ||
1855 | int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index) | |
1856 | { | |
1857 | struct wcn36xx_hal_trigger_ba_req_msg msg_body; | |
cddc6046 | 1858 | struct wcn36xx_hal_trigger_ba_req_candidate *candidate; |
8e84c258 EK |
1859 | int ret = 0; |
1860 | ||
1861 | mutex_lock(&wcn->hal_mutex); | |
1862 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ); | |
1863 | ||
1864 | msg_body.session_id = 0; | |
1865 | msg_body.candidate_cnt = 1; | |
1866 | msg_body.header.len += sizeof(*candidate); | |
1867 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1868 | ||
cddc6046 | 1869 | candidate = (struct wcn36xx_hal_trigger_ba_req_candidate *) |
8e84c258 EK |
1870 | (wcn->hal_buf + sizeof(msg_body)); |
1871 | candidate->sta_index = sta_index; | |
1872 | candidate->tid_bitmap = 1; | |
1873 | ||
1874 | ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len); | |
1875 | if (ret) { | |
1876 | wcn36xx_err("Sending hal_trigger_ba failed\n"); | |
1877 | goto out; | |
1878 | } | |
1879 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
1880 | if (ret) { | |
1881 | wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret); | |
1882 | goto out; | |
1883 | } | |
1884 | out: | |
1885 | mutex_unlock(&wcn->hal_mutex); | |
1886 | return ret; | |
1887 | } | |
1888 | ||
1889 | static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len) | |
1890 | { | |
1891 | struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf; | |
1892 | ||
1893 | if (len != sizeof(*rsp)) { | |
1894 | wcn36xx_warn("Bad TX complete indication\n"); | |
1895 | return -EIO; | |
1896 | } | |
1897 | ||
1898 | wcn36xx_dxe_tx_ack_ind(wcn, rsp->status); | |
1899 | ||
1900 | return 0; | |
1901 | } | |
1902 | ||
1903 | static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn, | |
1904 | void *buf, | |
1905 | size_t len) | |
1906 | { | |
1907 | struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf; | |
1908 | struct ieee80211_vif *vif = NULL; | |
1909 | struct wcn36xx_vif *tmp; | |
1910 | ||
1911 | /* Old FW does not have bss index */ | |
1912 | if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) { | |
1913 | list_for_each_entry(tmp, &wcn->vif_list, list) { | |
1914 | wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n", | |
1915 | tmp->bss_index); | |
1916 | vif = container_of((void *)tmp, | |
1917 | struct ieee80211_vif, | |
1918 | drv_priv); | |
1919 | ieee80211_connection_loss(vif); | |
1920 | } | |
1921 | return 0; | |
1922 | } | |
1923 | ||
1924 | if (len != sizeof(*rsp)) { | |
1925 | wcn36xx_warn("Corrupted missed beacon indication\n"); | |
1926 | return -EIO; | |
1927 | } | |
1928 | ||
1929 | list_for_each_entry(tmp, &wcn->vif_list, list) { | |
1930 | if (tmp->bss_index == rsp->bss_index) { | |
1931 | wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n", | |
1932 | rsp->bss_index); | |
1933 | vif = container_of((void *)tmp, | |
1934 | struct ieee80211_vif, | |
1935 | drv_priv); | |
1936 | ieee80211_connection_loss(vif); | |
1937 | return 0; | |
1938 | } | |
1939 | } | |
1940 | ||
1941 | wcn36xx_warn("BSS index %d not found\n", rsp->bss_index); | |
1942 | return -ENOENT; | |
1943 | } | |
1944 | ||
1945 | static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn, | |
1946 | void *buf, | |
1947 | size_t len) | |
1948 | { | |
1949 | struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf; | |
1950 | struct wcn36xx_vif *tmp; | |
1951 | struct ieee80211_sta *sta = NULL; | |
1952 | ||
1953 | if (len != sizeof(*rsp)) { | |
1954 | wcn36xx_warn("Corrupted delete sta indication\n"); | |
1955 | return -EIO; | |
1956 | } | |
1957 | ||
1958 | list_for_each_entry(tmp, &wcn->vif_list, list) { | |
1959 | if (sta && (tmp->sta->sta_index == rsp->sta_id)) { | |
1960 | sta = container_of((void *)tmp->sta, | |
1961 | struct ieee80211_sta, | |
1962 | drv_priv); | |
1963 | wcn36xx_dbg(WCN36XX_DBG_HAL, | |
1964 | "delete station indication %pM index %d\n", | |
1965 | rsp->addr2, | |
1966 | rsp->sta_id); | |
1967 | ieee80211_report_low_ack(sta, 0); | |
1968 | return 0; | |
1969 | } | |
1970 | } | |
1971 | ||
1972 | wcn36xx_warn("STA with addr %pM and index %d not found\n", | |
1973 | rsp->addr2, | |
1974 | rsp->sta_id); | |
1975 | return -ENOENT; | |
1976 | } | |
1977 | ||
1978 | int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value) | |
1979 | { | |
1980 | struct wcn36xx_hal_update_cfg_req_msg msg_body, *body; | |
1981 | size_t len; | |
1982 | int ret = 0; | |
1983 | ||
1984 | mutex_lock(&wcn->hal_mutex); | |
1985 | INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ); | |
1986 | ||
1987 | PREPARE_HAL_BUF(wcn->hal_buf, msg_body); | |
1988 | ||
1989 | body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf; | |
1990 | len = msg_body.header.len; | |
1991 | ||
1992 | put_cfg_tlv_u32(wcn, &len, cfg_id, value); | |
1993 | body->header.len = len; | |
1994 | body->len = len - sizeof(*body); | |
1995 | ||
1996 | ret = wcn36xx_smd_send_and_wait(wcn, body->header.len); | |
1997 | if (ret) { | |
1998 | wcn36xx_err("Sending hal_update_cfg failed\n"); | |
1999 | goto out; | |
2000 | } | |
2001 | ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len); | |
2002 | if (ret) { | |
2003 | wcn36xx_err("hal_update_cfg response failed err=%d\n", ret); | |
2004 | goto out; | |
2005 | } | |
2006 | out: | |
2007 | mutex_unlock(&wcn->hal_mutex); | |
2008 | return ret; | |
2009 | } | |
2010 | static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len) | |
2011 | { | |
2012 | struct wcn36xx_hal_msg_header *msg_header = buf; | |
2013 | struct wcn36xx_hal_ind_msg *msg_ind; | |
2014 | wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len); | |
2015 | ||
2016 | switch (msg_header->msg_type) { | |
2017 | case WCN36XX_HAL_START_RSP: | |
2018 | case WCN36XX_HAL_CONFIG_STA_RSP: | |
2019 | case WCN36XX_HAL_CONFIG_BSS_RSP: | |
2020 | case WCN36XX_HAL_ADD_STA_SELF_RSP: | |
2021 | case WCN36XX_HAL_STOP_RSP: | |
2022 | case WCN36XX_HAL_DEL_STA_SELF_RSP: | |
2023 | case WCN36XX_HAL_DELETE_STA_RSP: | |
2024 | case WCN36XX_HAL_INIT_SCAN_RSP: | |
2025 | case WCN36XX_HAL_START_SCAN_RSP: | |
2026 | case WCN36XX_HAL_END_SCAN_RSP: | |
2027 | case WCN36XX_HAL_FINISH_SCAN_RSP: | |
2028 | case WCN36XX_HAL_DOWNLOAD_NV_RSP: | |
2029 | case WCN36XX_HAL_DELETE_BSS_RSP: | |
2030 | case WCN36XX_HAL_SEND_BEACON_RSP: | |
2031 | case WCN36XX_HAL_SET_LINK_ST_RSP: | |
2032 | case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP: | |
2033 | case WCN36XX_HAL_SET_BSSKEY_RSP: | |
2034 | case WCN36XX_HAL_SET_STAKEY_RSP: | |
2035 | case WCN36XX_HAL_RMV_STAKEY_RSP: | |
2036 | case WCN36XX_HAL_RMV_BSSKEY_RSP: | |
2037 | case WCN36XX_HAL_ENTER_BMPS_RSP: | |
2038 | case WCN36XX_HAL_SET_POWER_PARAMS_RSP: | |
2039 | case WCN36XX_HAL_EXIT_BMPS_RSP: | |
2040 | case WCN36XX_HAL_KEEP_ALIVE_RSP: | |
2041 | case WCN36XX_HAL_DUMP_COMMAND_RSP: | |
2042 | case WCN36XX_HAL_ADD_BA_SESSION_RSP: | |
2043 | case WCN36XX_HAL_ADD_BA_RSP: | |
2044 | case WCN36XX_HAL_DEL_BA_RSP: | |
2045 | case WCN36XX_HAL_TRIGGER_BA_RSP: | |
2046 | case WCN36XX_HAL_UPDATE_CFG_RSP: | |
2047 | case WCN36XX_HAL_JOIN_RSP: | |
2048 | case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP: | |
2049 | case WCN36XX_HAL_CH_SWITCH_RSP: | |
2050 | case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP: | |
2051 | memcpy(wcn->hal_buf, buf, len); | |
2052 | wcn->hal_rsp_len = len; | |
2053 | complete(&wcn->hal_rsp_compl); | |
2054 | break; | |
2055 | ||
2056 | case WCN36XX_HAL_OTA_TX_COMPL_IND: | |
2057 | case WCN36XX_HAL_MISSED_BEACON_IND: | |
2058 | case WCN36XX_HAL_DELETE_STA_CONTEXT_IND: | |
2059 | mutex_lock(&wcn->hal_ind_mutex); | |
2060 | msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL); | |
3469adb3 MN |
2061 | if (msg_ind) { |
2062 | msg_ind->msg_len = len; | |
2063 | msg_ind->msg = kmalloc(len, GFP_KERNEL); | |
2064 | memcpy(msg_ind->msg, buf, len); | |
2065 | list_add_tail(&msg_ind->list, &wcn->hal_ind_queue); | |
2066 | queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work); | |
2067 | wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n"); | |
2068 | } | |
8e84c258 | 2069 | mutex_unlock(&wcn->hal_ind_mutex); |
3469adb3 MN |
2070 | if (msg_ind) |
2071 | break; | |
2072 | /* FIXME: Do something smarter then just printing an error. */ | |
2073 | wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n", | |
2074 | msg_header->msg_type); | |
8e84c258 EK |
2075 | break; |
2076 | default: | |
2077 | wcn36xx_err("SMD_EVENT (%d) not supported\n", | |
2078 | msg_header->msg_type); | |
2079 | } | |
2080 | } | |
2081 | static void wcn36xx_ind_smd_work(struct work_struct *work) | |
2082 | { | |
2083 | struct wcn36xx *wcn = | |
2084 | container_of(work, struct wcn36xx, hal_ind_work); | |
2085 | struct wcn36xx_hal_msg_header *msg_header; | |
2086 | struct wcn36xx_hal_ind_msg *hal_ind_msg; | |
2087 | ||
2088 | mutex_lock(&wcn->hal_ind_mutex); | |
2089 | ||
2090 | hal_ind_msg = list_first_entry(&wcn->hal_ind_queue, | |
2091 | struct wcn36xx_hal_ind_msg, | |
2092 | list); | |
2093 | ||
2094 | msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg; | |
2095 | ||
2096 | switch (msg_header->msg_type) { | |
2097 | case WCN36XX_HAL_OTA_TX_COMPL_IND: | |
2098 | wcn36xx_smd_tx_compl_ind(wcn, | |
2099 | hal_ind_msg->msg, | |
2100 | hal_ind_msg->msg_len); | |
2101 | break; | |
2102 | case WCN36XX_HAL_MISSED_BEACON_IND: | |
2103 | wcn36xx_smd_missed_beacon_ind(wcn, | |
2104 | hal_ind_msg->msg, | |
2105 | hal_ind_msg->msg_len); | |
2106 | break; | |
2107 | case WCN36XX_HAL_DELETE_STA_CONTEXT_IND: | |
2108 | wcn36xx_smd_delete_sta_context_ind(wcn, | |
2109 | hal_ind_msg->msg, | |
2110 | hal_ind_msg->msg_len); | |
2111 | break; | |
2112 | default: | |
2113 | wcn36xx_err("SMD_EVENT (%d) not supported\n", | |
2114 | msg_header->msg_type); | |
2115 | } | |
2116 | list_del(wcn->hal_ind_queue.next); | |
2117 | kfree(hal_ind_msg->msg); | |
2118 | kfree(hal_ind_msg); | |
2119 | mutex_unlock(&wcn->hal_ind_mutex); | |
2120 | } | |
2121 | int wcn36xx_smd_open(struct wcn36xx *wcn) | |
2122 | { | |
2123 | int ret = 0; | |
2124 | wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind"); | |
2125 | if (!wcn->hal_ind_wq) { | |
2126 | wcn36xx_err("failed to allocate wq\n"); | |
2127 | ret = -ENOMEM; | |
2128 | goto out; | |
2129 | } | |
2130 | INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work); | |
2131 | INIT_LIST_HEAD(&wcn->hal_ind_queue); | |
2132 | mutex_init(&wcn->hal_ind_mutex); | |
2133 | ||
2134 | ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process); | |
2135 | if (ret) { | |
2136 | wcn36xx_err("failed to open control channel\n"); | |
2137 | goto free_wq; | |
2138 | } | |
2139 | ||
2140 | return ret; | |
2141 | ||
2142 | free_wq: | |
2143 | destroy_workqueue(wcn->hal_ind_wq); | |
2144 | out: | |
2145 | return ret; | |
2146 | } | |
2147 | ||
2148 | void wcn36xx_smd_close(struct wcn36xx *wcn) | |
2149 | { | |
2150 | wcn->ctrl_ops->close(); | |
2151 | destroy_workqueue(wcn->hal_ind_wq); | |
2152 | mutex_destroy(&wcn->hal_ind_mutex); | |
2153 | } |