wcn36xx: Improve feature caps exchange
[deliverable/linux.git] / drivers / net / wireless / ath / wcn36xx / smd.c
CommitLineData
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
24static 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
48static 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
62static inline u8 is_cap_supported(unsigned long caps, unsigned long flag)
63{
64 return caps & flag ? 1 : 0;
65}
66static 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
90static 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
118static 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
134static 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
195static 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 }
212out:
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
230static 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
247int 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
309out_unlock:
310 mutex_unlock(&wcn->hal_mutex);
311out_free_nv:
312 release_firmware(nv);
313
314 return ret;
315}
316
317static 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
355int 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
383out:
384 mutex_unlock(&wcn->hal_mutex);
385 return ret;
386}
387
388int 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 }
410out:
411 mutex_unlock(&wcn->hal_mutex);
412 return ret;
413}
414
415int 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 }
439out:
440 mutex_unlock(&wcn->hal_mutex);
441 return ret;
442}
443
444int 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 }
469out:
470 mutex_unlock(&wcn->hal_mutex);
471 return ret;
472}
473
474int 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 }
499out:
500 mutex_unlock(&wcn->hal_mutex);
501 return ret;
502}
503
504int 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 }
530out:
531 mutex_unlock(&wcn->hal_mutex);
532 return ret;
533}
534
535static 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
549int 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 }
575out:
576 mutex_unlock(&wcn->hal_mutex);
577 return ret;
578}
579
580static 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
597int 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 }
632out:
633 mutex_unlock(&wcn->hal_mutex);
634 return ret;
635}
636
637static 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
666int 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 }
695out:
696 mutex_unlock(&wcn->hal_mutex);
697 return ret;
698}
699
700int 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 }
723out:
724 mutex_unlock(&wcn->hal_mutex);
725 return ret;
726}
727
728int 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 }
754out:
755 mutex_unlock(&wcn->hal_mutex);
756 return ret;
757}
758
759static 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
775int 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 }
817out:
818 mutex_unlock(&wcn->hal_mutex);
819 return ret;
820}
821
822int 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 }
852out:
853 mutex_unlock(&wcn->hal_mutex);
854 return ret;
855}
856
857static 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
879static 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
911static 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
932int 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 }
971out:
972 mutex_unlock(&wcn->hal_mutex);
973 return ret;
974}
975
976static 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
1084static 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
1126int 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;
fa643ae2
CYY
1154 } else if (vif->type == NL80211_IFTYPE_AP ||
1155 vif->type == NL80211_IFTYPE_MESH_POINT) {
8e84c258
EK
1156 bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE;
1157
1158 /* AP */
1159 bss->oper_mode = 0;
1160 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE;
fa643ae2 1161 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
8e84c258
EK
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 }
1251out:
1252 mutex_unlock(&wcn->hal_mutex);
1253 return ret;
1254}
1255
1256int 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 }
1281out:
1282 mutex_unlock(&wcn->hal_mutex);
1283 return ret;
1284}
1285
1286int 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? */
fa643ae2
CYY
1312 if (vif->type == NL80211_IFTYPE_MESH_POINT)
1313 /* mesh beacon don't need this, so push further down */
1314 msg_body.tim_ie_offset = 256;
1315 else
1316 msg_body.tim_ie_offset = tim_off+4;
8e84c258
EK
1317 msg_body.p2p_ie_offset = p2p_off;
1318 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1319
1320 wcn36xx_dbg(WCN36XX_DBG_HAL,
1321 "hal send beacon beacon_length %d\n",
1322 msg_body.beacon_length);
1323
1324 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1325 if (ret) {
1326 wcn36xx_err("Sending hal_send_beacon failed\n");
1327 goto out;
1328 }
1329 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1330 if (ret) {
1331 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
1332 goto out;
1333 }
1334out:
1335 mutex_unlock(&wcn->hal_mutex);
1336 return ret;
1337}
1338
1339int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
1340 struct ieee80211_vif *vif,
1341 struct sk_buff *skb)
1342{
1343 struct wcn36xx_hal_send_probe_resp_req_msg msg;
1344 int ret = 0;
1345
1346 mutex_lock(&wcn->hal_mutex);
1347 INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
1348
1349 if (skb->len > BEACON_TEMPLATE_SIZE) {
1350 wcn36xx_warn("probe response template is too big: %d\n",
1351 skb->len);
1221c25a
WY
1352 ret = -E2BIG;
1353 goto out;
8e84c258
EK
1354 }
1355
1356 msg.probe_resp_template_len = skb->len;
1357 memcpy(&msg.probe_resp_template, skb->data, skb->len);
1358
1359 memcpy(msg.bssid, vif->addr, ETH_ALEN);
1360
1361 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1362
1363 wcn36xx_dbg(WCN36XX_DBG_HAL,
1364 "hal update probe rsp len %d bssid %pM\n",
1365 msg.probe_resp_template_len, msg.bssid);
1366
1367 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1368 if (ret) {
1369 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1370 goto out;
1371 }
1372 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1373 if (ret) {
1374 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1375 ret);
1376 goto out;
1377 }
1378out:
1379 mutex_unlock(&wcn->hal_mutex);
1380 return ret;
1381}
1382
1383int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
1384 enum ani_ed_type enc_type,
1385 u8 keyidx,
1386 u8 keylen,
1387 u8 *key,
1388 u8 sta_index)
1389{
1390 struct wcn36xx_hal_set_sta_key_req_msg msg_body;
1391 int ret = 0;
1392
1393 mutex_lock(&wcn->hal_mutex);
1394 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
1395
1396 msg_body.set_sta_key_params.sta_index = sta_index;
1397 msg_body.set_sta_key_params.enc_type = enc_type;
1398
1399 msg_body.set_sta_key_params.key[0].id = keyidx;
1400 msg_body.set_sta_key_params.key[0].unicast = 1;
1401 msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX;
1402 msg_body.set_sta_key_params.key[0].pae_role = 0;
1403 msg_body.set_sta_key_params.key[0].length = keylen;
1404 memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen);
1405 msg_body.set_sta_key_params.single_tid_rc = 1;
1406
1407 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1408
1409 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1410 if (ret) {
1411 wcn36xx_err("Sending hal_set_stakey failed\n");
1412 goto out;
1413 }
1414 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1415 if (ret) {
1416 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
1417 goto out;
1418 }
1419out:
1420 mutex_unlock(&wcn->hal_mutex);
1421 return ret;
1422}
1423
1424int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
1425 enum ani_ed_type enc_type,
1426 u8 keyidx,
1427 u8 keylen,
1428 u8 *key)
1429{
1430 struct wcn36xx_hal_set_bss_key_req_msg msg_body;
1431 int ret = 0;
1432
1433 mutex_lock(&wcn->hal_mutex);
1434 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ);
1435 msg_body.bss_idx = 0;
1436 msg_body.enc_type = enc_type;
1437 msg_body.num_keys = 1;
1438 msg_body.keys[0].id = keyidx;
1439 msg_body.keys[0].unicast = 0;
1440 msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY;
1441 msg_body.keys[0].pae_role = 0;
1442 msg_body.keys[0].length = keylen;
1443 memcpy(msg_body.keys[0].key, key, keylen);
1444
1445 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1446
1447 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1448 if (ret) {
1449 wcn36xx_err("Sending hal_set_bsskey failed\n");
1450 goto out;
1451 }
1452 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1453 if (ret) {
1454 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
1455 goto out;
1456 }
1457out:
1458 mutex_unlock(&wcn->hal_mutex);
1459 return ret;
1460}
1461
1462int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
1463 enum ani_ed_type enc_type,
1464 u8 keyidx,
1465 u8 sta_index)
1466{
1467 struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
1468 int ret = 0;
1469
1470 mutex_lock(&wcn->hal_mutex);
1471 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
1472
1473 msg_body.sta_idx = sta_index;
1474 msg_body.enc_type = enc_type;
1475 msg_body.key_id = keyidx;
1476
1477 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1478
1479 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1480 if (ret) {
1481 wcn36xx_err("Sending hal_remove_stakey failed\n");
1482 goto out;
1483 }
1484 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1485 if (ret) {
1486 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
1487 goto out;
1488 }
1489out:
1490 mutex_unlock(&wcn->hal_mutex);
1491 return ret;
1492}
1493
1494int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
1495 enum ani_ed_type enc_type,
1496 u8 keyidx)
1497{
1498 struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
1499 int ret = 0;
1500
1501 mutex_lock(&wcn->hal_mutex);
1502 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ);
1503 msg_body.bss_idx = 0;
1504 msg_body.enc_type = enc_type;
1505 msg_body.key_id = keyidx;
1506
1507 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1508
1509 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1510 if (ret) {
1511 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1512 goto out;
1513 }
1514 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1515 if (ret) {
1516 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
1517 goto out;
1518 }
1519out:
1520 mutex_unlock(&wcn->hal_mutex);
1521 return ret;
1522}
1523
1524int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1525{
1526 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1527 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1528 int ret = 0;
1529
1530 mutex_lock(&wcn->hal_mutex);
1531 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
1532
1533 msg_body.bss_index = vif_priv->bss_index;
1534 msg_body.tbtt = vif->bss_conf.sync_tsf;
1535 msg_body.dtim_period = vif_priv->dtim_period;
1536
1537 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1538
1539 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1540 if (ret) {
1541 wcn36xx_err("Sending hal_enter_bmps failed\n");
1542 goto out;
1543 }
1544 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1545 if (ret) {
1546 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
1547 goto out;
1548 }
1549out:
1550 mutex_unlock(&wcn->hal_mutex);
1551 return ret;
1552}
1553
1554int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1555{
1556 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1557 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1558 int ret = 0;
1559
1560 mutex_lock(&wcn->hal_mutex);
1561 INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
1562
1563 msg_body.bss_index = vif_priv->bss_index;
1564
1565 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1566
1567 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1568 if (ret) {
1569 wcn36xx_err("Sending hal_exit_bmps failed\n");
1570 goto out;
1571 }
1572 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1573 if (ret) {
1574 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1575 goto out;
1576 }
1577out:
1578 mutex_unlock(&wcn->hal_mutex);
1579 return ret;
1580}
1581int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
1582{
1583 struct wcn36xx_hal_set_power_params_req_msg msg_body;
1584 int ret = 0;
1585
1586 mutex_lock(&wcn->hal_mutex);
1587 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
1588
1589 /*
1590 * When host is down ignore every second dtim
1591 */
1592 if (ignore_dtim) {
1593 msg_body.ignore_dtim = 1;
1594 msg_body.dtim_period = 2;
1595 }
1596 msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
1597
1598 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1599
1600 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1601 if (ret) {
1602 wcn36xx_err("Sending hal_set_power_params failed\n");
1603 goto out;
1604 }
1605
1606out:
1607 mutex_unlock(&wcn->hal_mutex);
1608 return ret;
1609}
1610/* Notice: This function should be called after associated, or else it
1611 * will be invalid
1612 */
1613int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
1614 struct ieee80211_vif *vif,
1615 int packet_type)
1616{
1617 struct wcn36xx_hal_keep_alive_req_msg msg_body;
1618 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1619 int ret = 0;
1620
1621 mutex_lock(&wcn->hal_mutex);
1622 INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
1623
1624 if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) {
1625 msg_body.bss_index = vif_priv->bss_index;
1626 msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT;
1627 msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD;
1628 } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) {
1629 /* TODO: it also support ARP response type */
1630 } else {
1631 wcn36xx_warn("unknow keep alive packet type %d\n", packet_type);
95b48c2c
DC
1632 ret = -EINVAL;
1633 goto out;
8e84c258
EK
1634 }
1635
1636 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1637
1638 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1639 if (ret) {
08762322 1640 wcn36xx_err("Sending hal_keep_alive failed\n");
8e84c258
EK
1641 goto out;
1642 }
1643 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1644 if (ret) {
08762322 1645 wcn36xx_err("hal_keep_alive response failed err=%d\n", ret);
8e84c258
EK
1646 goto out;
1647 }
1648out:
1649 mutex_unlock(&wcn->hal_mutex);
1650 return ret;
1651}
1652
1653int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
1654 u32 arg3, u32 arg4, u32 arg5)
1655{
1656 struct wcn36xx_hal_dump_cmd_req_msg msg_body;
1657 int ret = 0;
1658
1659 mutex_lock(&wcn->hal_mutex);
1660 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
1661
1662 msg_body.arg1 = arg1;
1663 msg_body.arg2 = arg2;
1664 msg_body.arg3 = arg3;
1665 msg_body.arg4 = arg4;
1666 msg_body.arg5 = arg5;
1667
1668 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1669
1670 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1671 if (ret) {
1672 wcn36xx_err("Sending hal_dump_cmd failed\n");
1673 goto out;
1674 }
1675 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1676 if (ret) {
1677 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
1678 goto out;
1679 }
1680out:
1681 mutex_unlock(&wcn->hal_mutex);
1682 return ret;
1683}
1684
1685static inline void set_feat_caps(u32 *bitmap,
1686 enum place_holder_in_cap_bitmap cap)
1687{
1688 int arr_idx, bit_idx;
1689
1690 if (cap < 0 || cap > 127) {
1691 wcn36xx_warn("error cap idx %d\n", cap);
1692 return;
1693 }
1694
1695 arr_idx = cap / 32;
1696 bit_idx = cap % 32;
1697 bitmap[arr_idx] |= (1 << bit_idx);
1698}
1699
1700static inline int get_feat_caps(u32 *bitmap,
1701 enum place_holder_in_cap_bitmap cap)
1702{
1703 int arr_idx, bit_idx;
1704 int ret = 0;
1705
1706 if (cap < 0 || cap > 127) {
1707 wcn36xx_warn("error cap idx %d\n", cap);
1708 return -EINVAL;
1709 }
1710
1711 arr_idx = cap / 32;
1712 bit_idx = cap % 32;
1713 ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
1714 return ret;
1715}
1716
1717static inline void clear_feat_caps(u32 *bitmap,
1718 enum place_holder_in_cap_bitmap cap)
1719{
1720 int arr_idx, bit_idx;
1721
1722 if (cap < 0 || cap > 127) {
1723 wcn36xx_warn("error cap idx %d\n", cap);
1724 return;
1725 }
1726
1727 arr_idx = cap / 32;
1728 bit_idx = cap % 32;
1729 bitmap[arr_idx] &= ~(1 << bit_idx);
1730}
1731
1732int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
1733{
c951da46
PF
1734 struct wcn36xx_hal_feat_caps_msg msg_body, *rsp;
1735 int ret = 0, i;
8e84c258
EK
1736
1737 mutex_lock(&wcn->hal_mutex);
1738 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
1739
1740 set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
1741
1742 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1743
1744 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1745 if (ret) {
1746 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1747 goto out;
1748 }
c951da46
PF
1749 if (wcn->hal_rsp_len != sizeof(*rsp)) {
1750 wcn36xx_err("Invalid hal_feature_caps_exchange response");
8e84c258
EK
1751 goto out;
1752 }
c951da46
PF
1753
1754 rsp = (struct wcn36xx_hal_feat_caps_msg *) wcn->hal_buf;
1755
1756 for (i = 0; i < WCN36XX_HAL_CAPS_SIZE; i++)
1757 wcn->fw_feat_caps[i] = rsp->feat_caps[i];
8e84c258
EK
1758out:
1759 mutex_unlock(&wcn->hal_mutex);
1760 return ret;
1761}
1762
1763int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
1764 struct ieee80211_sta *sta,
1765 u16 tid,
1766 u16 *ssn,
1767 u8 direction,
1768 u8 sta_index)
1769{
1770 struct wcn36xx_hal_add_ba_session_req_msg msg_body;
1771 int ret = 0;
1772
1773 mutex_lock(&wcn->hal_mutex);
1774 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
1775
1776 msg_body.sta_index = sta_index;
1777 memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
1778 msg_body.dialog_token = 0x10;
1779 msg_body.tid = tid;
1780
1781 /* Immediate BA because Delayed BA is not supported */
1782 msg_body.policy = 1;
1783 msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE;
1784 msg_body.timeout = 0;
1785 if (ssn)
1786 msg_body.ssn = *ssn;
1787 msg_body.direction = direction;
1788
1789 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1790
1791 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1792 if (ret) {
1793 wcn36xx_err("Sending hal_add_ba_session failed\n");
1794 goto out;
1795 }
1796 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1797 if (ret) {
1798 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
1799 goto out;
1800 }
1801out:
1802 mutex_unlock(&wcn->hal_mutex);
1803 return ret;
1804}
1805
1806int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
1807{
1808 struct wcn36xx_hal_add_ba_req_msg msg_body;
1809 int ret = 0;
1810
1811 mutex_lock(&wcn->hal_mutex);
1812 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
1813
1814 msg_body.session_id = 0;
1815 msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
1816
1817 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1818
1819 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1820 if (ret) {
1821 wcn36xx_err("Sending hal_add_ba failed\n");
1822 goto out;
1823 }
1824 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1825 if (ret) {
1826 wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
1827 goto out;
1828 }
1829out:
1830 mutex_unlock(&wcn->hal_mutex);
1831 return ret;
1832}
1833
1834int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
1835{
1836 struct wcn36xx_hal_del_ba_req_msg msg_body;
1837 int ret = 0;
1838
1839 mutex_lock(&wcn->hal_mutex);
1840 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
1841
1842 msg_body.sta_index = sta_index;
1843 msg_body.tid = tid;
1844 msg_body.direction = 0;
1845 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1846
1847 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1848 if (ret) {
1849 wcn36xx_err("Sending hal_del_ba failed\n");
1850 goto out;
1851 }
1852 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1853 if (ret) {
1854 wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
1855 goto out;
1856 }
1857out:
1858 mutex_unlock(&wcn->hal_mutex);
1859 return ret;
1860}
1861
1862int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
1863{
1864 struct wcn36xx_hal_trigger_ba_req_msg msg_body;
cddc6046 1865 struct wcn36xx_hal_trigger_ba_req_candidate *candidate;
8e84c258
EK
1866 int ret = 0;
1867
1868 mutex_lock(&wcn->hal_mutex);
1869 INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
1870
1871 msg_body.session_id = 0;
1872 msg_body.candidate_cnt = 1;
1873 msg_body.header.len += sizeof(*candidate);
1874 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1875
cddc6046 1876 candidate = (struct wcn36xx_hal_trigger_ba_req_candidate *)
8e84c258
EK
1877 (wcn->hal_buf + sizeof(msg_body));
1878 candidate->sta_index = sta_index;
1879 candidate->tid_bitmap = 1;
1880
1881 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1882 if (ret) {
1883 wcn36xx_err("Sending hal_trigger_ba failed\n");
1884 goto out;
1885 }
1886 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1887 if (ret) {
1888 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
1889 goto out;
1890 }
1891out:
1892 mutex_unlock(&wcn->hal_mutex);
1893 return ret;
1894}
1895
1896static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
1897{
1898 struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
1899
1900 if (len != sizeof(*rsp)) {
1901 wcn36xx_warn("Bad TX complete indication\n");
1902 return -EIO;
1903 }
1904
1905 wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
1906
1907 return 0;
1908}
1909
1910static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
1911 void *buf,
1912 size_t len)
1913{
1914 struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
1915 struct ieee80211_vif *vif = NULL;
1916 struct wcn36xx_vif *tmp;
1917
1918 /* Old FW does not have bss index */
1919 if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1920 list_for_each_entry(tmp, &wcn->vif_list, list) {
1921 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
1922 tmp->bss_index);
1923 vif = container_of((void *)tmp,
1924 struct ieee80211_vif,
1925 drv_priv);
1926 ieee80211_connection_loss(vif);
1927 }
1928 return 0;
1929 }
1930
1931 if (len != sizeof(*rsp)) {
1932 wcn36xx_warn("Corrupted missed beacon indication\n");
1933 return -EIO;
1934 }
1935
1936 list_for_each_entry(tmp, &wcn->vif_list, list) {
1937 if (tmp->bss_index == rsp->bss_index) {
1938 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
1939 rsp->bss_index);
1940 vif = container_of((void *)tmp,
1941 struct ieee80211_vif,
1942 drv_priv);
1943 ieee80211_connection_loss(vif);
1944 return 0;
1945 }
1946 }
1947
1948 wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
1949 return -ENOENT;
1950}
1951
1952static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
1953 void *buf,
1954 size_t len)
1955{
1956 struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
1957 struct wcn36xx_vif *tmp;
1958 struct ieee80211_sta *sta = NULL;
1959
1960 if (len != sizeof(*rsp)) {
1961 wcn36xx_warn("Corrupted delete sta indication\n");
1962 return -EIO;
1963 }
1964
1965 list_for_each_entry(tmp, &wcn->vif_list, list) {
1966 if (sta && (tmp->sta->sta_index == rsp->sta_id)) {
1967 sta = container_of((void *)tmp->sta,
1968 struct ieee80211_sta,
1969 drv_priv);
1970 wcn36xx_dbg(WCN36XX_DBG_HAL,
1971 "delete station indication %pM index %d\n",
1972 rsp->addr2,
1973 rsp->sta_id);
1974 ieee80211_report_low_ack(sta, 0);
1975 return 0;
1976 }
1977 }
1978
1979 wcn36xx_warn("STA with addr %pM and index %d not found\n",
1980 rsp->addr2,
1981 rsp->sta_id);
1982 return -ENOENT;
1983}
1984
1985int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
1986{
1987 struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
1988 size_t len;
1989 int ret = 0;
1990
1991 mutex_lock(&wcn->hal_mutex);
1992 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
1993
1994 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1995
1996 body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
1997 len = msg_body.header.len;
1998
1999 put_cfg_tlv_u32(wcn, &len, cfg_id, value);
2000 body->header.len = len;
2001 body->len = len - sizeof(*body);
2002
2003 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
2004 if (ret) {
2005 wcn36xx_err("Sending hal_update_cfg failed\n");
2006 goto out;
2007 }
2008 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
2009 if (ret) {
2010 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
2011 goto out;
2012 }
2013out:
2014 mutex_unlock(&wcn->hal_mutex);
2015 return ret;
2016}
2017static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
2018{
2019 struct wcn36xx_hal_msg_header *msg_header = buf;
2020 struct wcn36xx_hal_ind_msg *msg_ind;
2021 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len);
2022
2023 switch (msg_header->msg_type) {
2024 case WCN36XX_HAL_START_RSP:
2025 case WCN36XX_HAL_CONFIG_STA_RSP:
2026 case WCN36XX_HAL_CONFIG_BSS_RSP:
2027 case WCN36XX_HAL_ADD_STA_SELF_RSP:
2028 case WCN36XX_HAL_STOP_RSP:
2029 case WCN36XX_HAL_DEL_STA_SELF_RSP:
2030 case WCN36XX_HAL_DELETE_STA_RSP:
2031 case WCN36XX_HAL_INIT_SCAN_RSP:
2032 case WCN36XX_HAL_START_SCAN_RSP:
2033 case WCN36XX_HAL_END_SCAN_RSP:
2034 case WCN36XX_HAL_FINISH_SCAN_RSP:
2035 case WCN36XX_HAL_DOWNLOAD_NV_RSP:
2036 case WCN36XX_HAL_DELETE_BSS_RSP:
2037 case WCN36XX_HAL_SEND_BEACON_RSP:
2038 case WCN36XX_HAL_SET_LINK_ST_RSP:
2039 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP:
2040 case WCN36XX_HAL_SET_BSSKEY_RSP:
2041 case WCN36XX_HAL_SET_STAKEY_RSP:
2042 case WCN36XX_HAL_RMV_STAKEY_RSP:
2043 case WCN36XX_HAL_RMV_BSSKEY_RSP:
2044 case WCN36XX_HAL_ENTER_BMPS_RSP:
2045 case WCN36XX_HAL_SET_POWER_PARAMS_RSP:
2046 case WCN36XX_HAL_EXIT_BMPS_RSP:
2047 case WCN36XX_HAL_KEEP_ALIVE_RSP:
2048 case WCN36XX_HAL_DUMP_COMMAND_RSP:
2049 case WCN36XX_HAL_ADD_BA_SESSION_RSP:
2050 case WCN36XX_HAL_ADD_BA_RSP:
2051 case WCN36XX_HAL_DEL_BA_RSP:
2052 case WCN36XX_HAL_TRIGGER_BA_RSP:
2053 case WCN36XX_HAL_UPDATE_CFG_RSP:
2054 case WCN36XX_HAL_JOIN_RSP:
2055 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP:
2056 case WCN36XX_HAL_CH_SWITCH_RSP:
2057 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
2058 memcpy(wcn->hal_buf, buf, len);
2059 wcn->hal_rsp_len = len;
2060 complete(&wcn->hal_rsp_compl);
2061 break;
2062
2063 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2064 case WCN36XX_HAL_MISSED_BEACON_IND:
2065 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
8e84c258 2066 msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL);
90accd0b
MN
2067 if (!msg_ind)
2068 goto nomem;
2069 msg_ind->msg_len = len;
2070 msg_ind->msg = kmalloc(len, GFP_KERNEL);
2071 if (!msg_ind->msg) {
2072 kfree(msg_ind);
2073nomem:
2074 /*
2075 * FIXME: Do something smarter then just
2076 * printing an error.
2077 */
2078 wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
2079 msg_header->msg_type);
2080 break;
3469adb3 2081 }
90accd0b
MN
2082 memcpy(msg_ind->msg, buf, len);
2083 mutex_lock(&wcn->hal_ind_mutex);
2084 list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
2085 queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
8e84c258 2086 mutex_unlock(&wcn->hal_ind_mutex);
90accd0b 2087 wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n");
8e84c258
EK
2088 break;
2089 default:
2090 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2091 msg_header->msg_type);
2092 }
2093}
2094static void wcn36xx_ind_smd_work(struct work_struct *work)
2095{
2096 struct wcn36xx *wcn =
2097 container_of(work, struct wcn36xx, hal_ind_work);
2098 struct wcn36xx_hal_msg_header *msg_header;
2099 struct wcn36xx_hal_ind_msg *hal_ind_msg;
2100
2101 mutex_lock(&wcn->hal_ind_mutex);
2102
2103 hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
2104 struct wcn36xx_hal_ind_msg,
2105 list);
2106
2107 msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
2108
2109 switch (msg_header->msg_type) {
2110 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2111 wcn36xx_smd_tx_compl_ind(wcn,
2112 hal_ind_msg->msg,
2113 hal_ind_msg->msg_len);
2114 break;
2115 case WCN36XX_HAL_MISSED_BEACON_IND:
2116 wcn36xx_smd_missed_beacon_ind(wcn,
2117 hal_ind_msg->msg,
2118 hal_ind_msg->msg_len);
2119 break;
2120 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2121 wcn36xx_smd_delete_sta_context_ind(wcn,
2122 hal_ind_msg->msg,
2123 hal_ind_msg->msg_len);
2124 break;
2125 default:
2126 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2127 msg_header->msg_type);
2128 }
2129 list_del(wcn->hal_ind_queue.next);
2130 kfree(hal_ind_msg->msg);
2131 kfree(hal_ind_msg);
2132 mutex_unlock(&wcn->hal_ind_mutex);
2133}
2134int wcn36xx_smd_open(struct wcn36xx *wcn)
2135{
2136 int ret = 0;
2137 wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind");
2138 if (!wcn->hal_ind_wq) {
2139 wcn36xx_err("failed to allocate wq\n");
2140 ret = -ENOMEM;
2141 goto out;
2142 }
2143 INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work);
2144 INIT_LIST_HEAD(&wcn->hal_ind_queue);
2145 mutex_init(&wcn->hal_ind_mutex);
2146
2147 ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
2148 if (ret) {
2149 wcn36xx_err("failed to open control channel\n");
2150 goto free_wq;
2151 }
2152
2153 return ret;
2154
2155free_wq:
2156 destroy_workqueue(wcn->hal_ind_wq);
2157out:
2158 return ret;
2159}
2160
2161void wcn36xx_smd_close(struct wcn36xx *wcn)
2162{
2163 wcn->ctrl_ops->close();
2164 destroy_workqueue(wcn->hal_ind_wq);
2165 mutex_destroy(&wcn->hal_ind_mutex);
2166}
This page took 0.135216 seconds and 5 git commands to generate.