2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
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.
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.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/etherdevice.h>
20 #include <linux/firmware.h>
21 #include <linux/bitops.h>
24 static int put_cfg_tlv_u32(struct wcn36xx *wcn, size_t *len, u32 id, u32 value)
26 struct wcn36xx_hal_cfg *entry;
29 if (*len + sizeof(*entry) + sizeof(u32) >= WCN36XX_HAL_BUF_SIZE) {
30 wcn36xx_err("Not enough room for TLV entry\n");
34 entry = (struct wcn36xx_hal_cfg *) (wcn->hal_buf + *len);
36 entry->len = sizeof(u32);
40 val = (u32 *) (entry + 1);
43 *len += sizeof(*entry) + sizeof(u32);
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)
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;
59 bss_params->nw_type = WCN36XX_HAL_11B_NW_TYPE;
62 static inline u8 is_cap_supported(unsigned long caps, unsigned long flag)
64 return caps & flag ? 1 : 0;
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)
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);
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;
90 static void wcn36xx_smd_set_sta_ht_params(struct ieee80211_sta *sta,
91 struct wcn36xx_hal_config_sta_params *sta_params)
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);
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);
118 static void wcn36xx_smd_set_sta_default_ht_params(
119 struct wcn36xx_hal_config_sta_params *sta_params)
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;
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)
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;
147 sta_params->type = 0;
148 sta_params->sta_index = 1;
151 sta_params->listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
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.
158 if (NL80211_IFTYPE_STATION == vif->type)
159 memcpy(&sta_params->mac, vif->addr, ETH_ALEN);
161 memcpy(&sta_params->bssid, vif->addr, ETH_ALEN);
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);
168 sta_params->rifs_mode = 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;
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);
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));
190 wcn36xx_set_default_rates(&sta_params->supported_rates);
191 wcn36xx_smd_set_sta_default_ht_params(sta_params);
195 static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len)
198 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "HAL >>> ", wcn->hal_buf, len);
200 init_completion(&wcn->hal_rsp_compl);
201 ret = wcn->ctrl_ops->tx(wcn->hal_buf, len);
203 wcn36xx_err("HAL TX failed\n");
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");
216 #define INIT_HAL_MSG(msg_body, type) \
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); \
224 #define PREPARE_HAL_BUF(send_buf, msg_body) \
226 memset(send_buf, 0, msg_body.header.len); \
227 memcpy(send_buf, &msg_body, sizeof(msg_body)); \
230 static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
232 struct wcn36xx_fw_msg_status_rsp *rsp;
234 if (len < sizeof(struct wcn36xx_hal_msg_header) +
235 sizeof(struct wcn36xx_fw_msg_status_rsp))
238 rsp = (struct wcn36xx_fw_msg_status_rsp *)
239 (buf + sizeof(struct wcn36xx_hal_msg_header));
241 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status)
247 int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
249 const struct firmware *nv;
250 struct nv_data *nv_d;
251 struct wcn36xx_hal_nv_img_download_req_msg msg_body;
256 ret = request_firmware(&nv, WLAN_NV_FILE, wcn->dev);
258 wcn36xx_err("Failed to load nv file %s: %d\n",
263 nv_d = (struct nv_data *)nv->data;
264 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ);
266 msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE;
268 msg_body.frag_number = 0;
269 /* hal_buf must be protected with mutex */
270 mutex_lock(&wcn->hal_mutex);
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;
278 msg_body.last_fragment = 1;
279 msg_body.nv_img_buffer_size = fw_bytes_left;
281 /* Do not forget update general message len */
282 msg_body.header.len = sizeof(msg_body) + fw_bytes_left;
286 /* Add load NV request message header */
287 memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body));
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);
294 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
297 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf,
300 wcn36xx_err("hal_load_nv response failed err=%d\n",
304 msg_body.frag_number++;
305 fm_offset += WCN36XX_NV_FRAGMENT_SIZE;
307 } while (msg_body.last_fragment != 1);
310 mutex_unlock(&wcn->hal_mutex);
312 release_firmware(nv);
317 static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len)
319 struct wcn36xx_hal_mac_start_rsp_msg *rsp;
321 if (len < sizeof(*rsp))
324 rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf;
326 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status)
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);
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';
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;
343 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
344 wcn->wlan_version, wcn->crm_version);
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);
355 int wcn36xx_smd_start(struct wcn36xx *wcn)
357 struct wcn36xx_hal_mac_start_req_msg msg_body;
360 mutex_lock(&wcn->hal_mutex);
361 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ);
363 msg_body.params.type = DRIVER_TYPE_PRODUCTION;
364 msg_body.params.len = 0;
366 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
368 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n",
369 msg_body.params.type);
371 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
373 wcn36xx_err("Sending hal_start failed\n");
377 ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len);
379 wcn36xx_err("hal_start response failed err=%d\n", ret);
384 mutex_unlock(&wcn->hal_mutex);
388 int wcn36xx_smd_stop(struct wcn36xx *wcn)
390 struct wcn36xx_hal_mac_stop_req_msg msg_body;
393 mutex_lock(&wcn->hal_mutex);
394 INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ);
396 msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL;
398 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
400 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
402 wcn36xx_err("Sending hal_stop failed\n");
405 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
407 wcn36xx_err("hal_stop response failed err=%d\n", ret);
411 mutex_unlock(&wcn->hal_mutex);
415 int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode)
417 struct wcn36xx_hal_init_scan_req_msg msg_body;
420 mutex_lock(&wcn->hal_mutex);
421 INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ);
423 msg_body.mode = mode;
425 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
427 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode);
429 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
431 wcn36xx_err("Sending hal_init_scan failed\n");
434 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
436 wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
440 mutex_unlock(&wcn->hal_mutex);
444 int wcn36xx_smd_start_scan(struct wcn36xx *wcn)
446 struct wcn36xx_hal_start_scan_req_msg msg_body;
449 mutex_lock(&wcn->hal_mutex);
450 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ);
452 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
454 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
456 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n",
457 msg_body.scan_channel);
459 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
461 wcn36xx_err("Sending hal_start_scan failed\n");
464 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
466 wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
470 mutex_unlock(&wcn->hal_mutex);
474 int wcn36xx_smd_end_scan(struct wcn36xx *wcn)
476 struct wcn36xx_hal_end_scan_req_msg msg_body;
479 mutex_lock(&wcn->hal_mutex);
480 INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ);
482 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
484 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
486 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n",
487 msg_body.scan_channel);
489 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
491 wcn36xx_err("Sending hal_end_scan failed\n");
494 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
496 wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
500 mutex_unlock(&wcn->hal_mutex);
504 int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
505 enum wcn36xx_hal_sys_mode mode)
507 struct wcn36xx_hal_finish_scan_req_msg msg_body;
510 mutex_lock(&wcn->hal_mutex);
511 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ);
513 msg_body.mode = mode;
515 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
517 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n",
520 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
522 wcn36xx_err("Sending hal_finish_scan failed\n");
525 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
527 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
531 mutex_unlock(&wcn->hal_mutex);
535 static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
537 struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
540 ret = wcn36xx_smd_rsp_status_check(buf, len);
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);
549 int wcn36xx_smd_switch_channel(struct wcn36xx *wcn,
550 struct ieee80211_vif *vif, int ch)
552 struct wcn36xx_hal_switch_channel_req_msg msg_body;
555 mutex_lock(&wcn->hal_mutex);
556 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ);
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);
563 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
565 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
567 wcn36xx_err("Sending hal_switch_channel failed\n");
570 ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len);
572 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret);
576 mutex_unlock(&wcn->hal_mutex);
580 static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len)
582 struct wcn36xx_hal_update_scan_params_resp *rsp;
584 rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf;
586 /* Remove the PNO version bit */
587 rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK));
589 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) {
590 wcn36xx_warn("error response from update scan\n");
597 int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn)
599 struct wcn36xx_hal_update_scan_params_req msg_body;
602 mutex_lock(&wcn->hal_mutex);
603 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ);
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;
614 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
616 wcn36xx_dbg(WCN36XX_DBG_HAL,
617 "hal update scan params channel_count %d\n",
618 msg_body.channel_count);
620 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
622 wcn36xx_err("Sending hal_update_scan_params failed\n");
625 ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf,
628 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
633 mutex_unlock(&wcn->hal_mutex);
637 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn,
638 struct ieee80211_vif *vif,
642 struct wcn36xx_hal_add_sta_self_rsp_msg *rsp;
643 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
645 if (len < sizeof(*rsp))
648 rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf;
650 if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
651 wcn36xx_warn("hal add sta self failure: %d\n",
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);
660 priv_vif->self_sta_index = rsp->self_sta_index;
661 priv_vif->self_dpu_desc_index = rsp->dpu_index;
666 int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif)
668 struct wcn36xx_hal_add_sta_self_req msg_body;
671 mutex_lock(&wcn->hal_mutex);
672 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ);
674 memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN);
676 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
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);
682 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
684 wcn36xx_err("Sending hal_add_sta_self failed\n");
687 ret = wcn36xx_smd_add_sta_self_rsp(wcn,
692 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret);
696 mutex_unlock(&wcn->hal_mutex);
700 int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr)
702 struct wcn36xx_hal_del_sta_self_req_msg msg_body;
705 mutex_lock(&wcn->hal_mutex);
706 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ);
708 memcpy(&msg_body.self_addr, addr, ETH_ALEN);
710 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
712 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
714 wcn36xx_err("Sending hal_delete_sta_self failed\n");
717 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
719 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
724 mutex_unlock(&wcn->hal_mutex);
728 int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index)
730 struct wcn36xx_hal_delete_sta_req_msg msg_body;
733 mutex_lock(&wcn->hal_mutex);
734 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ);
736 msg_body.sta_index = sta_index;
738 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
740 wcn36xx_dbg(WCN36XX_DBG_HAL,
741 "hal delete sta sta_index %d\n",
744 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
746 wcn36xx_err("Sending hal_delete_sta failed\n");
749 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
751 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret);
755 mutex_unlock(&wcn->hal_mutex);
759 static int wcn36xx_smd_join_rsp(void *buf, size_t len)
761 struct wcn36xx_hal_join_rsp_msg *rsp;
763 if (wcn36xx_smd_rsp_status_check(buf, len))
766 rsp = (struct wcn36xx_hal_join_rsp_msg *)buf;
768 wcn36xx_dbg(WCN36XX_DBG_HAL,
769 "hal rsp join status %d tx_mgmt_power %d\n",
770 rsp->status, rsp->tx_mgmt_power);
775 int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch)
777 struct wcn36xx_hal_join_req_msg msg_body;
780 mutex_lock(&wcn->hal_mutex);
781 INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ);
783 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
784 memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN);
785 msg_body.channel = ch;
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;
794 msg_body.secondary_channel_offset =
795 PHY_SINGLE_CHANNEL_CENTERED;
797 msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE;
799 msg_body.max_tx_power = 0xbf;
800 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
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);
807 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
809 wcn36xx_err("Sending hal_join failed\n");
812 ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len);
814 wcn36xx_err("hal_join response failed err=%d\n", ret);
818 mutex_unlock(&wcn->hal_mutex);
822 int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid,
824 enum wcn36xx_hal_link_state state)
826 struct wcn36xx_hal_set_link_state_req_msg msg_body;
829 mutex_lock(&wcn->hal_mutex);
830 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ);
832 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
833 memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN);
834 msg_body.state = state;
836 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
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);
842 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
844 wcn36xx_err("Sending hal_set_link_st failed\n");
847 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
849 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret);
853 mutex_unlock(&wcn->hal_mutex);
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)
861 /* convert orig to v1 format */
862 memcpy(&v1->bssid, orig->bssid, ETH_ALEN);
863 memcpy(&v1->mac, orig->mac, ETH_ALEN);
865 v1->type = orig->type;
866 v1->listen_interval = orig->listen_interval;
867 v1->ht_capable = orig->ht_capable;
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;
874 memcpy(&v1->supported_rates, &orig->supported_rates,
875 sizeof(orig->supported_rates));
876 v1->sta_index = orig->sta_index;
879 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn,
880 struct ieee80211_sta *sta,
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;
888 if (len < sizeof(*rsp))
891 rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf;
892 params = &rsp->params;
894 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
895 wcn36xx_warn("hal config sta response failure: %d\n",
900 sta_priv->sta_index = params->sta_index;
901 sta_priv->dpu_desc_index = params->dpu_index;
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,
911 static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn,
912 const struct wcn36xx_hal_config_sta_req_msg *orig)
914 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body;
915 struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params;
917 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ);
919 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params,
920 &msg_body.sta_params);
922 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
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);
929 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
932 int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif,
933 struct ieee80211_sta *sta)
935 struct wcn36xx_hal_config_sta_req_msg msg;
936 struct wcn36xx_hal_config_sta_params *sta_params;
939 mutex_lock(&wcn->hal_mutex);
940 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ);
942 sta_params = &msg.sta_params;
944 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
946 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
947 ret = wcn36xx_smd_config_sta_v1(wcn, &msg);
949 PREPARE_HAL_BUF(wcn->hal_buf, msg);
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);
957 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
960 wcn36xx_err("Sending hal_config_sta failed\n");
963 ret = wcn36xx_smd_config_sta_rsp(wcn,
968 wcn36xx_err("hal_config_sta response failed err=%d\n", ret);
972 mutex_unlock(&wcn->hal_mutex);
976 static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn,
977 const struct wcn36xx_hal_config_bss_req_msg *orig)
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;
983 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ);
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);
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;
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;
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;
1014 msg_body.bss_params.reserved = orig->bss_params.reserved;
1016 memcpy(&msg_body.bss_params.ssid,
1017 &orig->bss_params.ssid,
1018 sizeof(orig->bss_params.ssid));
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;
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;
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));
1051 msg_body.bss_params.ext_set_sta_key_param_valid =
1052 orig->bss_params.ext_set_sta_key_param_valid;
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));
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;
1065 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta,
1066 &msg_body.bss_params.sta);
1068 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
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);
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);
1080 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1084 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn,
1085 struct ieee80211_vif *vif,
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;
1093 if (len < sizeof(*rsp))
1096 rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf;
1097 params = &rsp->bss_rsp_params;
1099 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
1100 wcn36xx_warn("hal config bss response failure: %d\n",
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);
1114 priv_vif->bss_index = params->bss_index;
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;
1121 priv_vif->ucast_dpu_signature = params->ucast_dpu_signature;
1126 int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1127 struct ieee80211_sta *sta, const u8 *bssid,
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;
1136 mutex_lock(&wcn->hal_mutex);
1137 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ);
1139 bss = &msg.bss_params;
1140 sta_params = &bss->sta;
1142 WARN_ON(is_zero_ether_addr(bssid));
1144 memcpy(&bss->bssid, bssid, ETH_ALEN);
1146 memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN);
1148 if (vif->type == NL80211_IFTYPE_STATION) {
1149 bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE;
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;
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;
1167 wcn36xx_warn("Unknown type for bss config: %d\n", vif->type);
1170 if (vif->type == NL80211_IFTYPE_STATION)
1171 wcn36xx_smd_set_bss_nw_type(wcn, sta, bss);
1173 bss->nw_type = WCN36XX_HAL_11N_NW_TYPE;
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;
1180 bss->beacon_interval = vif->bss_conf.beacon_int;
1181 bss->dtim_period = vif_priv->dtim_period;
1183 wcn36xx_smd_set_bss_ht_params(vif, sta, bss);
1185 bss->oper_channel = WCN36XX_HW_CHANNEL(wcn);
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;
1192 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1195 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
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);
1201 bss->obss_prot_enabled = 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;
1208 /* FIXME: set acbe, acbk, acvi and acvo */
1210 bss->ext_set_sta_key_param_valid = 0;
1212 /* FIXME: set ext_set_sta_key_param */
1214 bss->spectrum_mgt_enable = 0;
1215 bss->tx_mgmt_power = 0;
1216 bss->max_tx_power = WCN36XX_MAX_POWER(wcn);
1218 bss->action = update;
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);
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,
1232 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1233 ret = wcn36xx_smd_config_bss_v1(wcn, &msg);
1235 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1237 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1240 wcn36xx_err("Sending hal_config_bss failed\n");
1243 ret = wcn36xx_smd_config_bss_rsp(wcn,
1248 wcn36xx_err("hal_config_bss response failed err=%d\n", ret);
1252 mutex_unlock(&wcn->hal_mutex);
1256 int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1258 struct wcn36xx_hal_delete_bss_req_msg msg_body;
1259 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
1262 mutex_lock(&wcn->hal_mutex);
1263 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ);
1265 msg_body.bss_index = priv_vif->bss_index;
1267 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1269 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index);
1271 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1273 wcn36xx_err("Sending hal_delete_bss failed\n");
1276 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1278 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret);
1282 mutex_unlock(&wcn->hal_mutex);
1286 int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1287 struct sk_buff *skb_beacon, u16 tim_off,
1290 struct wcn36xx_hal_send_beacon_req_msg msg_body;
1293 mutex_lock(&wcn->hal_mutex);
1294 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ);
1296 /* TODO need to find out why this is needed? */
1297 msg_body.beacon_length = skb_beacon->len + 6;
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,
1304 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1305 msg_body.beacon_length);
1309 memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
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);
1316 wcn36xx_dbg(WCN36XX_DBG_HAL,
1317 "hal send beacon beacon_length %d\n",
1318 msg_body.beacon_length);
1320 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1322 wcn36xx_err("Sending hal_send_beacon failed\n");
1325 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1327 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
1331 mutex_unlock(&wcn->hal_mutex);
1335 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
1336 struct ieee80211_vif *vif,
1337 struct sk_buff *skb)
1339 struct wcn36xx_hal_send_probe_resp_req_msg msg;
1342 mutex_lock(&wcn->hal_mutex);
1343 INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
1345 if (skb->len > BEACON_TEMPLATE_SIZE) {
1346 wcn36xx_warn("probe response template is too big: %d\n",
1352 msg.probe_resp_template_len = skb->len;
1353 memcpy(&msg.probe_resp_template, skb->data, skb->len);
1355 memcpy(msg.bssid, vif->addr, ETH_ALEN);
1357 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1359 wcn36xx_dbg(WCN36XX_DBG_HAL,
1360 "hal update probe rsp len %d bssid %pM\n",
1361 msg.probe_resp_template_len, msg.bssid);
1363 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1365 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1368 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1370 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1375 mutex_unlock(&wcn->hal_mutex);
1379 int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
1380 enum ani_ed_type enc_type,
1386 struct wcn36xx_hal_set_sta_key_req_msg msg_body;
1389 mutex_lock(&wcn->hal_mutex);
1390 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
1392 msg_body.set_sta_key_params.sta_index = sta_index;
1393 msg_body.set_sta_key_params.enc_type = enc_type;
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;
1403 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1405 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1407 wcn36xx_err("Sending hal_set_stakey failed\n");
1410 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1412 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
1416 mutex_unlock(&wcn->hal_mutex);
1420 int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
1421 enum ani_ed_type enc_type,
1426 struct wcn36xx_hal_set_bss_key_req_msg msg_body;
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);
1441 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1443 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1445 wcn36xx_err("Sending hal_set_bsskey failed\n");
1448 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1450 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
1454 mutex_unlock(&wcn->hal_mutex);
1458 int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
1459 enum ani_ed_type enc_type,
1463 struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
1466 mutex_lock(&wcn->hal_mutex);
1467 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
1469 msg_body.sta_idx = sta_index;
1470 msg_body.enc_type = enc_type;
1471 msg_body.key_id = keyidx;
1473 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1475 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1477 wcn36xx_err("Sending hal_remove_stakey failed\n");
1480 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1482 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
1486 mutex_unlock(&wcn->hal_mutex);
1490 int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
1491 enum ani_ed_type enc_type,
1494 struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
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;
1503 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1505 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1507 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1510 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1512 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
1516 mutex_unlock(&wcn->hal_mutex);
1520 int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1522 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1523 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1526 mutex_lock(&wcn->hal_mutex);
1527 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
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;
1533 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1535 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1537 wcn36xx_err("Sending hal_enter_bmps failed\n");
1540 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1542 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
1546 mutex_unlock(&wcn->hal_mutex);
1550 int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1552 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1553 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1556 mutex_lock(&wcn->hal_mutex);
1557 INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
1559 msg_body.bss_index = vif_priv->bss_index;
1561 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1563 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1565 wcn36xx_err("Sending hal_exit_bmps failed\n");
1568 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1570 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1574 mutex_unlock(&wcn->hal_mutex);
1577 int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
1579 struct wcn36xx_hal_set_power_params_req_msg msg_body;
1582 mutex_lock(&wcn->hal_mutex);
1583 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
1586 * When host is down ignore every second dtim
1589 msg_body.ignore_dtim = 1;
1590 msg_body.dtim_period = 2;
1592 msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
1594 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1596 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1598 wcn36xx_err("Sending hal_set_power_params failed\n");
1603 mutex_unlock(&wcn->hal_mutex);
1606 /* Notice: This function should be called after associated, or else it
1609 int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
1610 struct ieee80211_vif *vif,
1613 struct wcn36xx_hal_keep_alive_req_msg msg_body;
1614 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1617 mutex_lock(&wcn->hal_mutex);
1618 INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
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 */
1627 wcn36xx_warn("unknow keep alive packet type %d\n", packet_type);
1632 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1634 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1636 wcn36xx_err("Sending hal_exit_bmps failed\n");
1639 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1641 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1645 mutex_unlock(&wcn->hal_mutex);
1649 int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
1650 u32 arg3, u32 arg4, u32 arg5)
1652 struct wcn36xx_hal_dump_cmd_req_msg msg_body;
1655 mutex_lock(&wcn->hal_mutex);
1656 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
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;
1664 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1666 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1668 wcn36xx_err("Sending hal_dump_cmd failed\n");
1671 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1673 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
1677 mutex_unlock(&wcn->hal_mutex);
1681 static inline void set_feat_caps(u32 *bitmap,
1682 enum place_holder_in_cap_bitmap cap)
1684 int arr_idx, bit_idx;
1686 if (cap < 0 || cap > 127) {
1687 wcn36xx_warn("error cap idx %d\n", cap);
1693 bitmap[arr_idx] |= (1 << bit_idx);
1696 static inline int get_feat_caps(u32 *bitmap,
1697 enum place_holder_in_cap_bitmap cap)
1699 int arr_idx, bit_idx;
1702 if (cap < 0 || cap > 127) {
1703 wcn36xx_warn("error cap idx %d\n", cap);
1709 ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
1713 static inline void clear_feat_caps(u32 *bitmap,
1714 enum place_holder_in_cap_bitmap cap)
1716 int arr_idx, bit_idx;
1718 if (cap < 0 || cap > 127) {
1719 wcn36xx_warn("error cap idx %d\n", cap);
1725 bitmap[arr_idx] &= ~(1 << bit_idx);
1728 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
1730 struct wcn36xx_hal_feat_caps_msg msg_body;
1733 mutex_lock(&wcn->hal_mutex);
1734 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
1736 set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
1738 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1740 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1742 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1745 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1747 wcn36xx_err("hal_feature_caps_exchange response failed err=%d\n",
1752 mutex_unlock(&wcn->hal_mutex);
1756 int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
1757 struct ieee80211_sta *sta,
1763 struct wcn36xx_hal_add_ba_session_req_msg msg_body;
1766 mutex_lock(&wcn->hal_mutex);
1767 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
1769 msg_body.sta_index = sta_index;
1770 memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
1771 msg_body.dialog_token = 0x10;
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;
1779 msg_body.ssn = *ssn;
1780 msg_body.direction = direction;
1782 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1784 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1786 wcn36xx_err("Sending hal_add_ba_session failed\n");
1789 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1791 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
1795 mutex_unlock(&wcn->hal_mutex);
1799 int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
1801 struct wcn36xx_hal_add_ba_req_msg msg_body;
1804 mutex_lock(&wcn->hal_mutex);
1805 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
1807 msg_body.session_id = 0;
1808 msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
1810 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1812 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1814 wcn36xx_err("Sending hal_add_ba failed\n");
1817 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1819 wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
1823 mutex_unlock(&wcn->hal_mutex);
1827 int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
1829 struct wcn36xx_hal_del_ba_req_msg msg_body;
1832 mutex_lock(&wcn->hal_mutex);
1833 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
1835 msg_body.sta_index = sta_index;
1837 msg_body.direction = 0;
1838 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1840 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1842 wcn36xx_err("Sending hal_del_ba failed\n");
1845 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1847 wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
1851 mutex_unlock(&wcn->hal_mutex);
1855 int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
1857 struct wcn36xx_hal_trigger_ba_req_msg msg_body;
1858 struct wcn36xx_hal_trigger_ba_req_candidate *candidate;
1861 mutex_lock(&wcn->hal_mutex);
1862 INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
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);
1869 candidate = (struct wcn36xx_hal_trigger_ba_req_candidate *)
1870 (wcn->hal_buf + sizeof(msg_body));
1871 candidate->sta_index = sta_index;
1872 candidate->tid_bitmap = 1;
1874 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1876 wcn36xx_err("Sending hal_trigger_ba failed\n");
1879 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1881 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
1885 mutex_unlock(&wcn->hal_mutex);
1889 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
1891 struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
1893 if (len != sizeof(*rsp)) {
1894 wcn36xx_warn("Bad TX complete indication\n");
1898 wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
1903 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
1907 struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
1908 struct ieee80211_vif *vif = NULL;
1909 struct wcn36xx_vif *tmp;
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",
1916 vif = container_of((void *)tmp,
1917 struct ieee80211_vif,
1919 ieee80211_connection_loss(vif);
1924 if (len != sizeof(*rsp)) {
1925 wcn36xx_warn("Corrupted missed beacon indication\n");
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",
1933 vif = container_of((void *)tmp,
1934 struct ieee80211_vif,
1936 ieee80211_connection_loss(vif);
1941 wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
1945 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
1949 struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
1950 struct wcn36xx_vif *tmp;
1951 struct ieee80211_sta *sta = NULL;
1953 if (len != sizeof(*rsp)) {
1954 wcn36xx_warn("Corrupted delete sta indication\n");
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,
1963 wcn36xx_dbg(WCN36XX_DBG_HAL,
1964 "delete station indication %pM index %d\n",
1967 ieee80211_report_low_ack(sta, 0);
1972 wcn36xx_warn("STA with addr %pM and index %d not found\n",
1978 int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
1980 struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
1984 mutex_lock(&wcn->hal_mutex);
1985 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
1987 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1989 body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
1990 len = msg_body.header.len;
1992 put_cfg_tlv_u32(wcn, &len, cfg_id, value);
1993 body->header.len = len;
1994 body->len = len - sizeof(*body);
1996 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
1998 wcn36xx_err("Sending hal_update_cfg failed\n");
2001 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
2003 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
2007 mutex_unlock(&wcn->hal_mutex);
2010 static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
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);
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);
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);
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");
2069 mutex_unlock(&wcn->hal_ind_mutex);
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);
2077 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2078 msg_header->msg_type);
2081 static void wcn36xx_ind_smd_work(struct work_struct *work)
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;
2088 mutex_lock(&wcn->hal_ind_mutex);
2090 hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
2091 struct wcn36xx_hal_ind_msg,
2094 msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
2096 switch (msg_header->msg_type) {
2097 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2098 wcn36xx_smd_tx_compl_ind(wcn,
2100 hal_ind_msg->msg_len);
2102 case WCN36XX_HAL_MISSED_BEACON_IND:
2103 wcn36xx_smd_missed_beacon_ind(wcn,
2105 hal_ind_msg->msg_len);
2107 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2108 wcn36xx_smd_delete_sta_context_ind(wcn,
2110 hal_ind_msg->msg_len);
2113 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2114 msg_header->msg_type);
2116 list_del(wcn->hal_ind_queue.next);
2117 kfree(hal_ind_msg->msg);
2119 mutex_unlock(&wcn->hal_ind_mutex);
2121 int wcn36xx_smd_open(struct wcn36xx *wcn)
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");
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);
2134 ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
2136 wcn36xx_err("failed to open control channel\n");
2143 destroy_workqueue(wcn->hal_ind_wq);
2148 void wcn36xx_smd_close(struct wcn36xx *wcn)
2150 wcn->ctrl_ops->close();
2151 destroy_workqueue(wcn->hal_ind_wq);
2152 mutex_destroy(&wcn->hal_ind_mutex);