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_params(struct wcn36xx *wcn,
119 struct ieee80211_vif *vif,
120 struct ieee80211_sta *sta,
121 struct wcn36xx_hal_config_sta_params *sta_params)
123 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
124 struct wcn36xx_sta *priv_sta = NULL;
125 if (vif->type == NL80211_IFTYPE_ADHOC ||
126 vif->type == NL80211_IFTYPE_AP ||
127 vif->type == NL80211_IFTYPE_MESH_POINT) {
128 sta_params->type = 1;
129 sta_params->sta_index = 0xFF;
131 sta_params->type = 0;
132 sta_params->sta_index = 1;
135 sta_params->listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
138 * In STA mode ieee80211_sta contains bssid and ieee80211_vif
139 * contains our mac address. In AP mode we are bssid so vif
140 * contains bssid and ieee80211_sta contains mac.
142 if (NL80211_IFTYPE_STATION == vif->type)
143 memcpy(&sta_params->mac, vif->addr, ETH_ALEN);
145 memcpy(&sta_params->bssid, vif->addr, ETH_ALEN);
147 sta_params->encrypt_type = priv_vif->encrypt_type;
148 sta_params->short_preamble_supported =
149 !(WCN36XX_FLAGS(wcn) &
150 IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE);
152 sta_params->rifs_mode = 0;
154 sta_params->action = 0;
155 sta_params->uapsd = 0;
156 sta_params->mimo_ps = WCN36XX_HAL_HT_MIMO_PS_STATIC;
157 sta_params->max_ampdu_duration = 0;
158 sta_params->bssid_index = priv_vif->bss_index;
162 priv_sta = (struct wcn36xx_sta *)sta->drv_priv;
163 if (NL80211_IFTYPE_STATION == vif->type)
164 memcpy(&sta_params->bssid, sta->addr, ETH_ALEN);
166 memcpy(&sta_params->mac, sta->addr, ETH_ALEN);
167 sta_params->wmm_enabled = sta->wme;
168 sta_params->max_sp_len = sta->max_sp;
169 sta_params->aid = priv_sta->aid;
170 wcn36xx_smd_set_sta_ht_params(sta, sta_params);
171 memcpy(&sta_params->supported_rates, &priv_sta->supported_rates,
172 sizeof(priv_sta->supported_rates));
174 wcn36xx_set_default_rates(&sta_params->supported_rates);
178 static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len)
181 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "HAL >>> ", wcn->hal_buf, len);
183 init_completion(&wcn->hal_rsp_compl);
184 ret = wcn->ctrl_ops->tx(wcn->hal_buf, len);
186 wcn36xx_err("HAL TX failed\n");
189 if (wait_for_completion_timeout(&wcn->hal_rsp_compl,
190 msecs_to_jiffies(HAL_MSG_TIMEOUT)) <= 0) {
191 wcn36xx_err("Timeout while waiting SMD response\n");
199 #define INIT_HAL_MSG(msg_body, type) \
201 memset(&msg_body, 0, sizeof(msg_body)); \
202 msg_body.header.msg_type = type; \
203 msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
204 msg_body.header.len = sizeof(msg_body); \
207 #define PREPARE_HAL_BUF(send_buf, msg_body) \
209 memset(send_buf, 0, msg_body.header.len); \
210 memcpy(send_buf, &msg_body, sizeof(msg_body)); \
213 static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
215 struct wcn36xx_fw_msg_status_rsp *rsp;
217 if (len < sizeof(struct wcn36xx_hal_msg_header) +
218 sizeof(struct wcn36xx_fw_msg_status_rsp))
221 rsp = (struct wcn36xx_fw_msg_status_rsp *)
222 (buf + sizeof(struct wcn36xx_hal_msg_header));
224 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status)
230 int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
232 const struct firmware *nv;
233 struct nv_data *nv_d;
234 struct wcn36xx_hal_nv_img_download_req_msg msg_body;
239 ret = request_firmware(&nv, WLAN_NV_FILE, wcn->dev);
241 wcn36xx_err("Failed to load nv file %s: %d\n",
246 nv_d = (struct nv_data *)nv->data;
247 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ);
249 msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE;
251 msg_body.frag_number = 0;
252 /* hal_buf must be protected with mutex */
253 mutex_lock(&wcn->hal_mutex);
256 fw_bytes_left = nv->size - fm_offset - 4;
257 if (fw_bytes_left > WCN36XX_NV_FRAGMENT_SIZE) {
258 msg_body.last_fragment = 0;
259 msg_body.nv_img_buffer_size = WCN36XX_NV_FRAGMENT_SIZE;
261 msg_body.last_fragment = 1;
262 msg_body.nv_img_buffer_size = fw_bytes_left;
264 /* Do not forget update general message len */
265 msg_body.header.len = sizeof(msg_body) + fw_bytes_left;
269 /* Add load NV request message header */
270 memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body));
272 /* Add NV body itself */
273 memcpy(wcn->hal_buf + sizeof(msg_body),
274 &nv_d->table + fm_offset,
275 msg_body.nv_img_buffer_size);
277 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
280 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf,
283 wcn36xx_err("hal_load_nv response failed err=%d\n",
287 msg_body.frag_number++;
288 fm_offset += WCN36XX_NV_FRAGMENT_SIZE;
290 } while (msg_body.last_fragment != 1);
293 mutex_unlock(&wcn->hal_mutex);
295 release_firmware(nv);
300 static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len)
302 struct wcn36xx_hal_mac_start_rsp_msg *rsp;
304 if (len < sizeof(*rsp))
307 rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf;
309 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status)
312 memcpy(wcn->crm_version, rsp->start_rsp_params.crm_version,
313 WCN36XX_HAL_VERSION_LENGTH);
314 memcpy(wcn->wlan_version, rsp->start_rsp_params.wlan_version,
315 WCN36XX_HAL_VERSION_LENGTH);
317 /* null terminate the strings, just in case */
318 wcn->crm_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
319 wcn->wlan_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
321 wcn->fw_revision = rsp->start_rsp_params.version.revision;
322 wcn->fw_version = rsp->start_rsp_params.version.version;
323 wcn->fw_minor = rsp->start_rsp_params.version.minor;
324 wcn->fw_major = rsp->start_rsp_params.version.major;
326 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
327 wcn->wlan_version, wcn->crm_version);
329 wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
330 wcn->fw_major, wcn->fw_minor,
331 wcn->fw_version, wcn->fw_revision,
332 rsp->start_rsp_params.stations,
333 rsp->start_rsp_params.bssids);
338 int wcn36xx_smd_start(struct wcn36xx *wcn)
340 struct wcn36xx_hal_mac_start_req_msg msg_body;
343 mutex_lock(&wcn->hal_mutex);
344 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ);
346 msg_body.params.type = DRIVER_TYPE_PRODUCTION;
347 msg_body.params.len = 0;
349 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
351 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n",
352 msg_body.params.type);
354 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
356 wcn36xx_err("Sending hal_start failed\n");
360 ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len);
362 wcn36xx_err("hal_start response failed err=%d\n", ret);
367 mutex_unlock(&wcn->hal_mutex);
371 int wcn36xx_smd_stop(struct wcn36xx *wcn)
373 struct wcn36xx_hal_mac_stop_req_msg msg_body;
376 mutex_lock(&wcn->hal_mutex);
377 INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ);
379 msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL;
381 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
383 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
385 wcn36xx_err("Sending hal_stop failed\n");
388 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
390 wcn36xx_err("hal_stop response failed err=%d\n", ret);
394 mutex_unlock(&wcn->hal_mutex);
398 int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode)
400 struct wcn36xx_hal_init_scan_req_msg msg_body;
403 mutex_lock(&wcn->hal_mutex);
404 INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ);
406 msg_body.mode = mode;
408 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
410 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode);
412 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
414 wcn36xx_err("Sending hal_init_scan failed\n");
417 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
419 wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
423 mutex_unlock(&wcn->hal_mutex);
427 int wcn36xx_smd_start_scan(struct wcn36xx *wcn)
429 struct wcn36xx_hal_start_scan_req_msg msg_body;
432 mutex_lock(&wcn->hal_mutex);
433 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ);
435 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
437 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
439 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n",
440 msg_body.scan_channel);
442 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
444 wcn36xx_err("Sending hal_start_scan failed\n");
447 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
449 wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
453 mutex_unlock(&wcn->hal_mutex);
457 int wcn36xx_smd_end_scan(struct wcn36xx *wcn)
459 struct wcn36xx_hal_end_scan_req_msg msg_body;
462 mutex_lock(&wcn->hal_mutex);
463 INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ);
465 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
467 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
469 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n",
470 msg_body.scan_channel);
472 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
474 wcn36xx_err("Sending hal_end_scan failed\n");
477 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
479 wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
483 mutex_unlock(&wcn->hal_mutex);
487 int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
488 enum wcn36xx_hal_sys_mode mode)
490 struct wcn36xx_hal_finish_scan_req_msg msg_body;
493 mutex_lock(&wcn->hal_mutex);
494 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ);
496 msg_body.mode = mode;
498 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
500 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n",
503 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
505 wcn36xx_err("Sending hal_finish_scan failed\n");
508 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
510 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
514 mutex_unlock(&wcn->hal_mutex);
518 static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
520 struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
523 ret = wcn36xx_smd_rsp_status_check(buf, len);
526 rsp = (struct wcn36xx_hal_switch_channel_rsp_msg *)buf;
527 wcn36xx_dbg(WCN36XX_DBG_HAL, "channel switched to: %d, status: %d\n",
528 rsp->channel_number, rsp->status);
532 int wcn36xx_smd_switch_channel(struct wcn36xx *wcn,
533 struct ieee80211_vif *vif, int ch)
535 struct wcn36xx_hal_switch_channel_req_msg msg_body;
538 mutex_lock(&wcn->hal_mutex);
539 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ);
541 msg_body.channel_number = (u8)ch;
542 msg_body.tx_mgmt_power = 0xbf;
543 msg_body.max_tx_power = 0xbf;
544 memcpy(msg_body.self_sta_mac_addr, vif->addr, ETH_ALEN);
546 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
548 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
550 wcn36xx_err("Sending hal_switch_channel failed\n");
553 ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len);
555 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret);
559 mutex_unlock(&wcn->hal_mutex);
563 static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len)
565 struct wcn36xx_hal_update_scan_params_resp *rsp;
567 rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf;
569 /* Remove the PNO version bit */
570 rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK));
572 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) {
573 wcn36xx_warn("error response from update scan\n");
580 int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn)
582 struct wcn36xx_hal_update_scan_params_req msg_body;
585 mutex_lock(&wcn->hal_mutex);
586 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ);
588 msg_body.dot11d_enabled = 0;
589 msg_body.dot11d_resolved = 0;
590 msg_body.channel_count = 26;
591 msg_body.active_min_ch_time = 60;
592 msg_body.active_max_ch_time = 120;
593 msg_body.passive_min_ch_time = 60;
594 msg_body.passive_max_ch_time = 110;
597 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
599 wcn36xx_dbg(WCN36XX_DBG_HAL,
600 "hal update scan params channel_count %d\n",
601 msg_body.channel_count);
603 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
605 wcn36xx_err("Sending hal_update_scan_params failed\n");
608 ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf,
611 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
616 mutex_unlock(&wcn->hal_mutex);
620 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn,
621 struct ieee80211_vif *vif,
625 struct wcn36xx_hal_add_sta_self_rsp_msg *rsp;
626 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
628 if (len < sizeof(*rsp))
631 rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf;
633 if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
634 wcn36xx_warn("hal add sta self failure: %d\n",
639 wcn36xx_dbg(WCN36XX_DBG_HAL,
640 "hal add sta self status %d self_sta_index %d dpu_index %d\n",
641 rsp->status, rsp->self_sta_index, rsp->dpu_index);
643 priv_vif->self_sta_index = rsp->self_sta_index;
644 priv_vif->self_dpu_desc_index = rsp->dpu_index;
649 int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif)
651 struct wcn36xx_hal_add_sta_self_req msg_body;
654 mutex_lock(&wcn->hal_mutex);
655 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ);
657 memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN);
659 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
661 wcn36xx_dbg(WCN36XX_DBG_HAL,
662 "hal add sta self self_addr %pM status %d\n",
663 msg_body.self_addr, msg_body.status);
665 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
667 wcn36xx_err("Sending hal_add_sta_self failed\n");
670 ret = wcn36xx_smd_add_sta_self_rsp(wcn,
675 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret);
679 mutex_unlock(&wcn->hal_mutex);
683 int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr)
685 struct wcn36xx_hal_del_sta_self_req_msg msg_body;
688 mutex_lock(&wcn->hal_mutex);
689 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ);
691 memcpy(&msg_body.self_addr, addr, ETH_ALEN);
693 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
695 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
697 wcn36xx_err("Sending hal_delete_sta_self failed\n");
700 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
702 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
707 mutex_unlock(&wcn->hal_mutex);
711 int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index)
713 struct wcn36xx_hal_delete_sta_req_msg msg_body;
716 mutex_lock(&wcn->hal_mutex);
717 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ);
719 msg_body.sta_index = sta_index;
721 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
723 wcn36xx_dbg(WCN36XX_DBG_HAL,
724 "hal delete sta sta_index %d\n",
727 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
729 wcn36xx_err("Sending hal_delete_sta failed\n");
732 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
734 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret);
738 mutex_unlock(&wcn->hal_mutex);
742 static int wcn36xx_smd_join_rsp(void *buf, size_t len)
744 struct wcn36xx_hal_join_rsp_msg *rsp;
746 if (wcn36xx_smd_rsp_status_check(buf, len))
749 rsp = (struct wcn36xx_hal_join_rsp_msg *)buf;
751 wcn36xx_dbg(WCN36XX_DBG_HAL,
752 "hal rsp join status %d tx_mgmt_power %d\n",
753 rsp->status, rsp->tx_mgmt_power);
758 int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch)
760 struct wcn36xx_hal_join_req_msg msg_body;
763 mutex_lock(&wcn->hal_mutex);
764 INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ);
766 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
767 memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN);
768 msg_body.channel = ch;
770 if (conf_is_ht40_minus(&wcn->hw->conf))
771 msg_body.secondary_channel_offset =
772 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY;
773 else if (conf_is_ht40_plus(&wcn->hw->conf))
774 msg_body.secondary_channel_offset =
775 PHY_DOUBLE_CHANNEL_LOW_PRIMARY;
777 msg_body.secondary_channel_offset =
778 PHY_SINGLE_CHANNEL_CENTERED;
780 msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE;
782 msg_body.max_tx_power = 0xbf;
783 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
785 wcn36xx_dbg(WCN36XX_DBG_HAL,
786 "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
787 msg_body.bssid, msg_body.self_sta_mac_addr,
788 msg_body.channel, msg_body.link_state);
790 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
792 wcn36xx_err("Sending hal_join failed\n");
795 ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len);
797 wcn36xx_err("hal_join response failed err=%d\n", ret);
801 mutex_unlock(&wcn->hal_mutex);
805 int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid,
807 enum wcn36xx_hal_link_state state)
809 struct wcn36xx_hal_set_link_state_req_msg msg_body;
812 mutex_lock(&wcn->hal_mutex);
813 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ);
815 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
816 memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN);
817 msg_body.state = state;
819 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
821 wcn36xx_dbg(WCN36XX_DBG_HAL,
822 "hal set link state bssid %pM self_mac_addr %pM state %d\n",
823 msg_body.bssid, msg_body.self_mac_addr, msg_body.state);
825 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
827 wcn36xx_err("Sending hal_set_link_st failed\n");
830 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
832 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret);
836 mutex_unlock(&wcn->hal_mutex);
840 static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx *wcn,
841 const struct wcn36xx_hal_config_sta_params *orig,
842 struct wcn36xx_hal_config_sta_params_v1 *v1)
844 /* convert orig to v1 format */
845 memcpy(&v1->bssid, orig->bssid, ETH_ALEN);
846 memcpy(&v1->mac, orig->mac, ETH_ALEN);
848 v1->type = orig->type;
849 v1->listen_interval = orig->listen_interval;
850 v1->ht_capable = orig->ht_capable;
852 v1->max_ampdu_size = orig->max_ampdu_size;
853 v1->max_ampdu_density = orig->max_ampdu_density;
854 v1->sgi_40mhz = orig->sgi_40mhz;
855 v1->sgi_20Mhz = orig->sgi_20Mhz;
857 memcpy(&v1->supported_rates, &orig->supported_rates,
858 sizeof(orig->supported_rates));
859 v1->sta_index = orig->sta_index;
862 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn,
863 struct ieee80211_sta *sta,
867 struct wcn36xx_hal_config_sta_rsp_msg *rsp;
868 struct config_sta_rsp_params *params;
869 struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
871 if (len < sizeof(*rsp))
874 rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf;
875 params = &rsp->params;
877 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
878 wcn36xx_warn("hal config sta response failure: %d\n",
883 sta_priv->sta_index = params->sta_index;
884 sta_priv->dpu_desc_index = params->dpu_index;
886 wcn36xx_dbg(WCN36XX_DBG_HAL,
887 "hal config sta rsp status %d sta_index %d bssid_index %d p2p %d\n",
888 params->status, params->sta_index, params->bssid_index,
894 static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn,
895 const struct wcn36xx_hal_config_sta_req_msg *orig)
897 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body;
898 struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params;
900 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ);
902 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params,
903 &msg_body.sta_params);
905 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
907 wcn36xx_dbg(WCN36XX_DBG_HAL,
908 "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
909 sta->action, sta->sta_index, sta->bssid_index,
910 sta->bssid, sta->type, sta->mac, sta->aid);
912 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
915 int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif,
916 struct ieee80211_sta *sta)
918 struct wcn36xx_hal_config_sta_req_msg msg;
919 struct wcn36xx_hal_config_sta_params *sta_params;
922 mutex_lock(&wcn->hal_mutex);
923 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ);
925 sta_params = &msg.sta_params;
927 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
929 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
930 ret = wcn36xx_smd_config_sta_v1(wcn, &msg);
932 PREPARE_HAL_BUF(wcn->hal_buf, msg);
934 wcn36xx_dbg(WCN36XX_DBG_HAL,
935 "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
936 sta_params->action, sta_params->sta_index,
937 sta_params->bssid_index, sta_params->bssid,
938 sta_params->type, sta_params->mac, sta_params->aid);
940 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
943 wcn36xx_err("Sending hal_config_sta failed\n");
946 ret = wcn36xx_smd_config_sta_rsp(wcn,
951 wcn36xx_err("hal_config_sta response failed err=%d\n", ret);
955 mutex_unlock(&wcn->hal_mutex);
959 static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn,
960 const struct wcn36xx_hal_config_bss_req_msg *orig)
962 struct wcn36xx_hal_config_bss_req_msg_v1 msg_body;
963 struct wcn36xx_hal_config_bss_params_v1 *bss = &msg_body.bss_params;
964 struct wcn36xx_hal_config_sta_params_v1 *sta = &bss->sta;
966 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ);
968 /* convert orig to v1 */
969 memcpy(&msg_body.bss_params.bssid,
970 &orig->bss_params.bssid, ETH_ALEN);
971 memcpy(&msg_body.bss_params.self_mac_addr,
972 &orig->bss_params.self_mac_addr, ETH_ALEN);
974 msg_body.bss_params.bss_type = orig->bss_params.bss_type;
975 msg_body.bss_params.oper_mode = orig->bss_params.oper_mode;
976 msg_body.bss_params.nw_type = orig->bss_params.nw_type;
978 msg_body.bss_params.short_slot_time_supported =
979 orig->bss_params.short_slot_time_supported;
980 msg_body.bss_params.lla_coexist = orig->bss_params.lla_coexist;
981 msg_body.bss_params.llb_coexist = orig->bss_params.llb_coexist;
982 msg_body.bss_params.llg_coexist = orig->bss_params.llg_coexist;
983 msg_body.bss_params.ht20_coexist = orig->bss_params.ht20_coexist;
984 msg_body.bss_params.lln_non_gf_coexist =
985 orig->bss_params.lln_non_gf_coexist;
987 msg_body.bss_params.lsig_tx_op_protection_full_support =
988 orig->bss_params.lsig_tx_op_protection_full_support;
989 msg_body.bss_params.rifs_mode = orig->bss_params.rifs_mode;
990 msg_body.bss_params.beacon_interval = orig->bss_params.beacon_interval;
991 msg_body.bss_params.dtim_period = orig->bss_params.dtim_period;
992 msg_body.bss_params.tx_channel_width_set =
993 orig->bss_params.tx_channel_width_set;
994 msg_body.bss_params.oper_channel = orig->bss_params.oper_channel;
995 msg_body.bss_params.ext_channel = orig->bss_params.ext_channel;
997 msg_body.bss_params.reserved = orig->bss_params.reserved;
999 memcpy(&msg_body.bss_params.ssid,
1000 &orig->bss_params.ssid,
1001 sizeof(orig->bss_params.ssid));
1003 msg_body.bss_params.action = orig->bss_params.action;
1004 msg_body.bss_params.rateset = orig->bss_params.rateset;
1005 msg_body.bss_params.ht = orig->bss_params.ht;
1006 msg_body.bss_params.obss_prot_enabled =
1007 orig->bss_params.obss_prot_enabled;
1008 msg_body.bss_params.rmf = orig->bss_params.rmf;
1009 msg_body.bss_params.ht_oper_mode = orig->bss_params.ht_oper_mode;
1010 msg_body.bss_params.dual_cts_protection =
1011 orig->bss_params.dual_cts_protection;
1013 msg_body.bss_params.max_probe_resp_retry_limit =
1014 orig->bss_params.max_probe_resp_retry_limit;
1015 msg_body.bss_params.hidden_ssid = orig->bss_params.hidden_ssid;
1016 msg_body.bss_params.proxy_probe_resp =
1017 orig->bss_params.proxy_probe_resp;
1018 msg_body.bss_params.edca_params_valid =
1019 orig->bss_params.edca_params_valid;
1021 memcpy(&msg_body.bss_params.acbe,
1022 &orig->bss_params.acbe,
1023 sizeof(orig->bss_params.acbe));
1024 memcpy(&msg_body.bss_params.acbk,
1025 &orig->bss_params.acbk,
1026 sizeof(orig->bss_params.acbk));
1027 memcpy(&msg_body.bss_params.acvi,
1028 &orig->bss_params.acvi,
1029 sizeof(orig->bss_params.acvi));
1030 memcpy(&msg_body.bss_params.acvo,
1031 &orig->bss_params.acvo,
1032 sizeof(orig->bss_params.acvo));
1034 msg_body.bss_params.ext_set_sta_key_param_valid =
1035 orig->bss_params.ext_set_sta_key_param_valid;
1037 memcpy(&msg_body.bss_params.ext_set_sta_key_param,
1038 &orig->bss_params.ext_set_sta_key_param,
1039 sizeof(orig->bss_params.acvo));
1041 msg_body.bss_params.wcn36xx_hal_persona =
1042 orig->bss_params.wcn36xx_hal_persona;
1043 msg_body.bss_params.spectrum_mgt_enable =
1044 orig->bss_params.spectrum_mgt_enable;
1045 msg_body.bss_params.tx_mgmt_power = orig->bss_params.tx_mgmt_power;
1046 msg_body.bss_params.max_tx_power = orig->bss_params.max_tx_power;
1048 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta,
1049 &msg_body.bss_params.sta);
1051 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1053 wcn36xx_dbg(WCN36XX_DBG_HAL,
1054 "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1055 bss->bssid, bss->self_mac_addr, bss->bss_type,
1056 bss->oper_mode, bss->nw_type);
1058 wcn36xx_dbg(WCN36XX_DBG_HAL,
1059 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1060 sta->bssid, sta->action, sta->sta_index,
1061 sta->bssid_index, sta->aid, sta->type, sta->mac);
1063 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1067 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn,
1068 struct ieee80211_vif *vif,
1072 struct wcn36xx_hal_config_bss_rsp_msg *rsp;
1073 struct wcn36xx_hal_config_bss_rsp_params *params;
1074 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
1076 if (len < sizeof(*rsp))
1079 rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf;
1080 params = &rsp->bss_rsp_params;
1082 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
1083 wcn36xx_warn("hal config bss response failure: %d\n",
1088 wcn36xx_dbg(WCN36XX_DBG_HAL,
1089 "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
1090 " sta_idx %d self_idx %d bcast_idx %d mac %pM"
1091 " power %d ucast_dpu_signature %d\n",
1092 params->status, params->bss_index, params->dpu_desc_index,
1093 params->bss_sta_index, params->bss_self_sta_index,
1094 params->bss_bcast_sta_idx, params->mac,
1095 params->tx_mgmt_power, params->ucast_dpu_signature);
1097 priv_vif->bss_index = params->bss_index;
1099 if (priv_vif->sta) {
1100 priv_vif->sta->bss_sta_index = params->bss_sta_index;
1101 priv_vif->sta->bss_dpu_desc_index = params->dpu_desc_index;
1104 priv_vif->ucast_dpu_signature = params->ucast_dpu_signature;
1109 int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1110 struct ieee80211_sta *sta, const u8 *bssid,
1113 struct wcn36xx_hal_config_bss_req_msg msg;
1114 struct wcn36xx_hal_config_bss_params *bss;
1115 struct wcn36xx_hal_config_sta_params *sta_params;
1116 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1119 mutex_lock(&wcn->hal_mutex);
1120 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ);
1122 bss = &msg.bss_params;
1123 sta_params = &bss->sta;
1125 WARN_ON(is_zero_ether_addr(bssid));
1127 memcpy(&bss->bssid, bssid, ETH_ALEN);
1129 memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN);
1131 if (vif->type == NL80211_IFTYPE_STATION) {
1132 bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE;
1136 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_MODE;
1137 } else if (vif->type == NL80211_IFTYPE_AP) {
1138 bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE;
1142 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE;
1143 } else if (vif->type == NL80211_IFTYPE_ADHOC ||
1144 vif->type == NL80211_IFTYPE_MESH_POINT) {
1145 bss->bss_type = WCN36XX_HAL_IBSS_MODE;
1150 wcn36xx_warn("Unknown type for bss config: %d\n", vif->type);
1153 if (vif->type == NL80211_IFTYPE_STATION)
1154 wcn36xx_smd_set_bss_nw_type(wcn, sta, bss);
1156 bss->nw_type = WCN36XX_HAL_11N_NW_TYPE;
1158 bss->short_slot_time_supported = vif->bss_conf.use_short_slot;
1159 bss->lla_coexist = 0;
1160 bss->llb_coexist = 0;
1161 bss->llg_coexist = 0;
1163 bss->beacon_interval = vif->bss_conf.beacon_int;
1164 bss->dtim_period = vif_priv->dtim_period;
1166 wcn36xx_smd_set_bss_ht_params(vif, sta, bss);
1168 bss->oper_channel = WCN36XX_HW_CHANNEL(wcn);
1170 if (conf_is_ht40_minus(&wcn->hw->conf))
1171 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1172 else if (conf_is_ht40_plus(&wcn->hw->conf))
1173 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1175 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1178 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
1180 /* wcn->ssid is only valid in AP and IBSS mode */
1181 bss->ssid.length = vif_priv->ssid.length;
1182 memcpy(bss->ssid.ssid, vif_priv->ssid.ssid, vif_priv->ssid.length);
1184 bss->obss_prot_enabled = 0;
1186 bss->max_probe_resp_retry_limit = 0;
1187 bss->hidden_ssid = vif->bss_conf.hidden_ssid;
1188 bss->proxy_probe_resp = 0;
1189 bss->edca_params_valid = 0;
1191 /* FIXME: set acbe, acbk, acvi and acvo */
1193 bss->ext_set_sta_key_param_valid = 0;
1195 /* FIXME: set ext_set_sta_key_param */
1197 bss->spectrum_mgt_enable = 0;
1198 bss->tx_mgmt_power = 0;
1199 bss->max_tx_power = WCN36XX_MAX_POWER(wcn);
1201 bss->action = update;
1203 wcn36xx_dbg(WCN36XX_DBG_HAL,
1204 "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1205 bss->bssid, bss->self_mac_addr, bss->bss_type,
1206 bss->oper_mode, bss->nw_type);
1208 wcn36xx_dbg(WCN36XX_DBG_HAL,
1209 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1210 sta_params->bssid, sta_params->action,
1211 sta_params->sta_index, sta_params->bssid_index,
1212 sta_params->aid, sta_params->type,
1215 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1216 ret = wcn36xx_smd_config_bss_v1(wcn, &msg);
1218 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1220 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1223 wcn36xx_err("Sending hal_config_bss failed\n");
1226 ret = wcn36xx_smd_config_bss_rsp(wcn,
1231 wcn36xx_err("hal_config_bss response failed err=%d\n", ret);
1235 mutex_unlock(&wcn->hal_mutex);
1239 int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1241 struct wcn36xx_hal_delete_bss_req_msg msg_body;
1242 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
1245 mutex_lock(&wcn->hal_mutex);
1246 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ);
1248 msg_body.bss_index = priv_vif->bss_index;
1250 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1252 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index);
1254 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1256 wcn36xx_err("Sending hal_delete_bss failed\n");
1259 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1261 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret);
1265 mutex_unlock(&wcn->hal_mutex);
1269 int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1270 struct sk_buff *skb_beacon, u16 tim_off,
1273 struct wcn36xx_hal_send_beacon_req_msg msg_body;
1276 mutex_lock(&wcn->hal_mutex);
1277 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ);
1279 /* TODO need to find out why this is needed? */
1280 msg_body.beacon_length = skb_beacon->len + 6;
1282 if (BEACON_TEMPLATE_SIZE > msg_body.beacon_length) {
1283 memcpy(&msg_body.beacon, &skb_beacon->len, sizeof(u32));
1284 memcpy(&(msg_body.beacon[4]), skb_beacon->data,
1287 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1288 msg_body.beacon_length);
1291 memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
1293 /* TODO need to find out why this is needed? */
1294 msg_body.tim_ie_offset = tim_off+4;
1295 msg_body.p2p_ie_offset = p2p_off;
1296 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1298 wcn36xx_dbg(WCN36XX_DBG_HAL,
1299 "hal send beacon beacon_length %d\n",
1300 msg_body.beacon_length);
1302 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1304 wcn36xx_err("Sending hal_send_beacon failed\n");
1307 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1309 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
1313 mutex_unlock(&wcn->hal_mutex);
1317 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
1318 struct ieee80211_vif *vif,
1319 struct sk_buff *skb)
1321 struct wcn36xx_hal_send_probe_resp_req_msg msg;
1324 mutex_lock(&wcn->hal_mutex);
1325 INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
1327 if (skb->len > BEACON_TEMPLATE_SIZE) {
1328 wcn36xx_warn("probe response template is too big: %d\n",
1333 msg.probe_resp_template_len = skb->len;
1334 memcpy(&msg.probe_resp_template, skb->data, skb->len);
1336 memcpy(msg.bssid, vif->addr, ETH_ALEN);
1338 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1340 wcn36xx_dbg(WCN36XX_DBG_HAL,
1341 "hal update probe rsp len %d bssid %pM\n",
1342 msg.probe_resp_template_len, msg.bssid);
1344 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1346 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1349 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1351 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1356 mutex_unlock(&wcn->hal_mutex);
1360 int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
1361 enum ani_ed_type enc_type,
1367 struct wcn36xx_hal_set_sta_key_req_msg msg_body;
1370 mutex_lock(&wcn->hal_mutex);
1371 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
1373 msg_body.set_sta_key_params.sta_index = sta_index;
1374 msg_body.set_sta_key_params.enc_type = enc_type;
1376 msg_body.set_sta_key_params.key[0].id = keyidx;
1377 msg_body.set_sta_key_params.key[0].unicast = 1;
1378 msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX;
1379 msg_body.set_sta_key_params.key[0].pae_role = 0;
1380 msg_body.set_sta_key_params.key[0].length = keylen;
1381 memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen);
1382 msg_body.set_sta_key_params.single_tid_rc = 1;
1384 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1386 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1388 wcn36xx_err("Sending hal_set_stakey failed\n");
1391 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1393 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
1397 mutex_unlock(&wcn->hal_mutex);
1401 int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
1402 enum ani_ed_type enc_type,
1407 struct wcn36xx_hal_set_bss_key_req_msg msg_body;
1410 mutex_lock(&wcn->hal_mutex);
1411 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ);
1412 msg_body.bss_idx = 0;
1413 msg_body.enc_type = enc_type;
1414 msg_body.num_keys = 1;
1415 msg_body.keys[0].id = keyidx;
1416 msg_body.keys[0].unicast = 0;
1417 msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY;
1418 msg_body.keys[0].pae_role = 0;
1419 msg_body.keys[0].length = keylen;
1420 memcpy(msg_body.keys[0].key, key, keylen);
1422 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1424 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1426 wcn36xx_err("Sending hal_set_bsskey failed\n");
1429 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1431 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
1435 mutex_unlock(&wcn->hal_mutex);
1439 int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
1440 enum ani_ed_type enc_type,
1444 struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
1447 mutex_lock(&wcn->hal_mutex);
1448 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
1450 msg_body.sta_idx = sta_index;
1451 msg_body.enc_type = enc_type;
1452 msg_body.key_id = keyidx;
1454 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1456 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1458 wcn36xx_err("Sending hal_remove_stakey failed\n");
1461 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1463 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
1467 mutex_unlock(&wcn->hal_mutex);
1471 int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
1472 enum ani_ed_type enc_type,
1475 struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
1478 mutex_lock(&wcn->hal_mutex);
1479 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ);
1480 msg_body.bss_idx = 0;
1481 msg_body.enc_type = enc_type;
1482 msg_body.key_id = keyidx;
1484 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1486 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1488 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1491 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1493 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
1497 mutex_unlock(&wcn->hal_mutex);
1501 int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1503 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1504 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1507 mutex_lock(&wcn->hal_mutex);
1508 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
1510 msg_body.bss_index = vif_priv->bss_index;
1511 msg_body.tbtt = vif->bss_conf.sync_tsf;
1512 msg_body.dtim_period = vif_priv->dtim_period;
1514 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1516 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1518 wcn36xx_err("Sending hal_enter_bmps failed\n");
1521 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1523 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
1527 mutex_unlock(&wcn->hal_mutex);
1531 int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1533 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1534 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1537 mutex_lock(&wcn->hal_mutex);
1538 INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
1540 msg_body.bss_index = vif_priv->bss_index;
1542 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1544 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1546 wcn36xx_err("Sending hal_exit_bmps failed\n");
1549 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1551 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1555 mutex_unlock(&wcn->hal_mutex);
1558 int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
1560 struct wcn36xx_hal_set_power_params_req_msg msg_body;
1563 mutex_lock(&wcn->hal_mutex);
1564 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
1567 * When host is down ignore every second dtim
1570 msg_body.ignore_dtim = 1;
1571 msg_body.dtim_period = 2;
1573 msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
1575 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1577 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1579 wcn36xx_err("Sending hal_set_power_params failed\n");
1584 mutex_unlock(&wcn->hal_mutex);
1587 /* Notice: This function should be called after associated, or else it
1590 int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
1591 struct ieee80211_vif *vif,
1594 struct wcn36xx_hal_keep_alive_req_msg msg_body;
1595 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1598 mutex_lock(&wcn->hal_mutex);
1599 INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
1601 if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) {
1602 msg_body.bss_index = vif_priv->bss_index;
1603 msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT;
1604 msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD;
1605 } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) {
1606 /* TODO: it also support ARP response type */
1608 wcn36xx_warn("unknow keep alive packet type %d\n", packet_type);
1612 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1614 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1616 wcn36xx_err("Sending hal_exit_bmps failed\n");
1619 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1621 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1625 mutex_unlock(&wcn->hal_mutex);
1629 int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
1630 u32 arg3, u32 arg4, u32 arg5)
1632 struct wcn36xx_hal_dump_cmd_req_msg msg_body;
1635 mutex_lock(&wcn->hal_mutex);
1636 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
1638 msg_body.arg1 = arg1;
1639 msg_body.arg2 = arg2;
1640 msg_body.arg3 = arg3;
1641 msg_body.arg4 = arg4;
1642 msg_body.arg5 = arg5;
1644 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1646 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1648 wcn36xx_err("Sending hal_dump_cmd failed\n");
1651 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1653 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
1657 mutex_unlock(&wcn->hal_mutex);
1661 static inline void set_feat_caps(u32 *bitmap,
1662 enum place_holder_in_cap_bitmap cap)
1664 int arr_idx, bit_idx;
1666 if (cap < 0 || cap > 127) {
1667 wcn36xx_warn("error cap idx %d\n", cap);
1673 bitmap[arr_idx] |= (1 << bit_idx);
1676 static inline int get_feat_caps(u32 *bitmap,
1677 enum place_holder_in_cap_bitmap cap)
1679 int arr_idx, bit_idx;
1682 if (cap < 0 || cap > 127) {
1683 wcn36xx_warn("error cap idx %d\n", cap);
1689 ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
1693 static inline void clear_feat_caps(u32 *bitmap,
1694 enum place_holder_in_cap_bitmap cap)
1696 int arr_idx, bit_idx;
1698 if (cap < 0 || cap > 127) {
1699 wcn36xx_warn("error cap idx %d\n", cap);
1705 bitmap[arr_idx] &= ~(1 << bit_idx);
1708 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
1710 struct wcn36xx_hal_feat_caps_msg msg_body;
1713 mutex_lock(&wcn->hal_mutex);
1714 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
1716 set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
1718 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1720 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1722 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1725 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1727 wcn36xx_err("hal_feature_caps_exchange response failed err=%d\n",
1732 mutex_unlock(&wcn->hal_mutex);
1736 int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
1737 struct ieee80211_sta *sta,
1743 struct wcn36xx_hal_add_ba_session_req_msg msg_body;
1746 mutex_lock(&wcn->hal_mutex);
1747 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
1749 msg_body.sta_index = sta_index;
1750 memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
1751 msg_body.dialog_token = 0x10;
1754 /* Immediate BA because Delayed BA is not supported */
1755 msg_body.policy = 1;
1756 msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE;
1757 msg_body.timeout = 0;
1759 msg_body.ssn = *ssn;
1760 msg_body.direction = direction;
1762 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1764 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1766 wcn36xx_err("Sending hal_add_ba_session failed\n");
1769 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1771 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
1775 mutex_unlock(&wcn->hal_mutex);
1779 int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
1781 struct wcn36xx_hal_add_ba_req_msg msg_body;
1784 mutex_lock(&wcn->hal_mutex);
1785 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
1787 msg_body.session_id = 0;
1788 msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
1790 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1792 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1794 wcn36xx_err("Sending hal_add_ba failed\n");
1797 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1799 wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
1803 mutex_unlock(&wcn->hal_mutex);
1807 int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
1809 struct wcn36xx_hal_del_ba_req_msg msg_body;
1812 mutex_lock(&wcn->hal_mutex);
1813 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
1815 msg_body.sta_index = sta_index;
1817 msg_body.direction = 0;
1818 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1820 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1822 wcn36xx_err("Sending hal_del_ba failed\n");
1825 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1827 wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
1831 mutex_unlock(&wcn->hal_mutex);
1835 int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
1837 struct wcn36xx_hal_trigger_ba_req_msg msg_body;
1838 struct wcn36xx_hal_trigget_ba_req_candidate *candidate;
1841 mutex_lock(&wcn->hal_mutex);
1842 INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
1844 msg_body.session_id = 0;
1845 msg_body.candidate_cnt = 1;
1846 msg_body.header.len += sizeof(*candidate);
1847 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1849 candidate = (struct wcn36xx_hal_trigget_ba_req_candidate *)
1850 (wcn->hal_buf + sizeof(msg_body));
1851 candidate->sta_index = sta_index;
1852 candidate->tid_bitmap = 1;
1854 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1856 wcn36xx_err("Sending hal_trigger_ba failed\n");
1859 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1861 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
1865 mutex_unlock(&wcn->hal_mutex);
1869 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
1871 struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
1873 if (len != sizeof(*rsp)) {
1874 wcn36xx_warn("Bad TX complete indication\n");
1878 wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
1883 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
1887 struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
1888 struct ieee80211_vif *vif = NULL;
1889 struct wcn36xx_vif *tmp;
1891 /* Old FW does not have bss index */
1892 if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1893 list_for_each_entry(tmp, &wcn->vif_list, list) {
1894 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
1896 vif = container_of((void *)tmp,
1897 struct ieee80211_vif,
1899 ieee80211_connection_loss(vif);
1904 if (len != sizeof(*rsp)) {
1905 wcn36xx_warn("Corrupted missed beacon indication\n");
1909 list_for_each_entry(tmp, &wcn->vif_list, list) {
1910 if (tmp->bss_index == rsp->bss_index) {
1911 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
1913 vif = container_of((void *)tmp,
1914 struct ieee80211_vif,
1916 ieee80211_connection_loss(vif);
1921 wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
1925 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
1929 struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
1930 struct wcn36xx_vif *tmp;
1931 struct ieee80211_sta *sta = NULL;
1933 if (len != sizeof(*rsp)) {
1934 wcn36xx_warn("Corrupted delete sta indication\n");
1938 list_for_each_entry(tmp, &wcn->vif_list, list) {
1939 if (sta && (tmp->sta->sta_index == rsp->sta_id)) {
1940 sta = container_of((void *)tmp->sta,
1941 struct ieee80211_sta,
1943 wcn36xx_dbg(WCN36XX_DBG_HAL,
1944 "delete station indication %pM index %d\n",
1947 ieee80211_report_low_ack(sta, 0);
1952 wcn36xx_warn("STA with addr %pM and index %d not found\n",
1958 int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
1960 struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
1964 mutex_lock(&wcn->hal_mutex);
1965 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
1967 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1969 body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
1970 len = msg_body.header.len;
1972 put_cfg_tlv_u32(wcn, &len, cfg_id, value);
1973 body->header.len = len;
1974 body->len = len - sizeof(*body);
1976 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
1978 wcn36xx_err("Sending hal_update_cfg failed\n");
1981 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1983 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
1987 mutex_unlock(&wcn->hal_mutex);
1990 static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
1992 struct wcn36xx_hal_msg_header *msg_header = buf;
1993 struct wcn36xx_hal_ind_msg *msg_ind;
1994 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len);
1996 switch (msg_header->msg_type) {
1997 case WCN36XX_HAL_START_RSP:
1998 case WCN36XX_HAL_CONFIG_STA_RSP:
1999 case WCN36XX_HAL_CONFIG_BSS_RSP:
2000 case WCN36XX_HAL_ADD_STA_SELF_RSP:
2001 case WCN36XX_HAL_STOP_RSP:
2002 case WCN36XX_HAL_DEL_STA_SELF_RSP:
2003 case WCN36XX_HAL_DELETE_STA_RSP:
2004 case WCN36XX_HAL_INIT_SCAN_RSP:
2005 case WCN36XX_HAL_START_SCAN_RSP:
2006 case WCN36XX_HAL_END_SCAN_RSP:
2007 case WCN36XX_HAL_FINISH_SCAN_RSP:
2008 case WCN36XX_HAL_DOWNLOAD_NV_RSP:
2009 case WCN36XX_HAL_DELETE_BSS_RSP:
2010 case WCN36XX_HAL_SEND_BEACON_RSP:
2011 case WCN36XX_HAL_SET_LINK_ST_RSP:
2012 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP:
2013 case WCN36XX_HAL_SET_BSSKEY_RSP:
2014 case WCN36XX_HAL_SET_STAKEY_RSP:
2015 case WCN36XX_HAL_RMV_STAKEY_RSP:
2016 case WCN36XX_HAL_RMV_BSSKEY_RSP:
2017 case WCN36XX_HAL_ENTER_BMPS_RSP:
2018 case WCN36XX_HAL_SET_POWER_PARAMS_RSP:
2019 case WCN36XX_HAL_EXIT_BMPS_RSP:
2020 case WCN36XX_HAL_KEEP_ALIVE_RSP:
2021 case WCN36XX_HAL_DUMP_COMMAND_RSP:
2022 case WCN36XX_HAL_ADD_BA_SESSION_RSP:
2023 case WCN36XX_HAL_ADD_BA_RSP:
2024 case WCN36XX_HAL_DEL_BA_RSP:
2025 case WCN36XX_HAL_TRIGGER_BA_RSP:
2026 case WCN36XX_HAL_UPDATE_CFG_RSP:
2027 case WCN36XX_HAL_JOIN_RSP:
2028 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP:
2029 case WCN36XX_HAL_CH_SWITCH_RSP:
2030 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
2031 memcpy(wcn->hal_buf, buf, len);
2032 wcn->hal_rsp_len = len;
2033 complete(&wcn->hal_rsp_compl);
2036 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2037 case WCN36XX_HAL_MISSED_BEACON_IND:
2038 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2039 mutex_lock(&wcn->hal_ind_mutex);
2040 msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL);
2041 msg_ind->msg_len = len;
2042 msg_ind->msg = kmalloc(len, GFP_KERNEL);
2043 memcpy(msg_ind->msg, buf, len);
2044 list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
2045 queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
2046 wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n");
2047 mutex_unlock(&wcn->hal_ind_mutex);
2050 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2051 msg_header->msg_type);
2054 static void wcn36xx_ind_smd_work(struct work_struct *work)
2056 struct wcn36xx *wcn =
2057 container_of(work, struct wcn36xx, hal_ind_work);
2058 struct wcn36xx_hal_msg_header *msg_header;
2059 struct wcn36xx_hal_ind_msg *hal_ind_msg;
2061 mutex_lock(&wcn->hal_ind_mutex);
2063 hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
2064 struct wcn36xx_hal_ind_msg,
2067 msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
2069 switch (msg_header->msg_type) {
2070 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2071 wcn36xx_smd_tx_compl_ind(wcn,
2073 hal_ind_msg->msg_len);
2075 case WCN36XX_HAL_MISSED_BEACON_IND:
2076 wcn36xx_smd_missed_beacon_ind(wcn,
2078 hal_ind_msg->msg_len);
2080 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2081 wcn36xx_smd_delete_sta_context_ind(wcn,
2083 hal_ind_msg->msg_len);
2086 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2087 msg_header->msg_type);
2089 list_del(wcn->hal_ind_queue.next);
2090 kfree(hal_ind_msg->msg);
2092 mutex_unlock(&wcn->hal_ind_mutex);
2094 int wcn36xx_smd_open(struct wcn36xx *wcn)
2097 wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind");
2098 if (!wcn->hal_ind_wq) {
2099 wcn36xx_err("failed to allocate wq\n");
2103 INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work);
2104 INIT_LIST_HEAD(&wcn->hal_ind_queue);
2105 mutex_init(&wcn->hal_ind_mutex);
2107 ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
2109 wcn36xx_err("failed to open control channel\n");
2116 destroy_workqueue(wcn->hal_ind_wq);
2121 void wcn36xx_smd_close(struct wcn36xx *wcn)
2123 wcn->ctrl_ops->close();
2124 destroy_workqueue(wcn->hal_ind_wq);
2125 mutex_destroy(&wcn->hal_ind_mutex);