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 struct wcn36xx_cfg_val {
29 #define WCN36XX_CFG_VAL(id, val) \
31 .cfg_id = WCN36XX_HAL_CFG_ ## id, \
35 static struct wcn36xx_cfg_val wcn36xx_cfg_vals[] = {
36 WCN36XX_CFG_VAL(CURRENT_TX_ANTENNA, 1),
37 WCN36XX_CFG_VAL(CURRENT_RX_ANTENNA, 1),
38 WCN36XX_CFG_VAL(LOW_GAIN_OVERRIDE, 0),
39 WCN36XX_CFG_VAL(POWER_STATE_PER_CHAIN, 785),
40 WCN36XX_CFG_VAL(CAL_PERIOD, 5),
41 WCN36XX_CFG_VAL(CAL_CONTROL, 1),
42 WCN36XX_CFG_VAL(PROXIMITY, 0),
43 WCN36XX_CFG_VAL(NETWORK_DENSITY, 3),
44 WCN36XX_CFG_VAL(MAX_MEDIUM_TIME, 6000),
45 WCN36XX_CFG_VAL(MAX_MPDUS_IN_AMPDU, 64),
46 WCN36XX_CFG_VAL(RTS_THRESHOLD, 2347),
47 WCN36XX_CFG_VAL(SHORT_RETRY_LIMIT, 6),
48 WCN36XX_CFG_VAL(LONG_RETRY_LIMIT, 6),
49 WCN36XX_CFG_VAL(FRAGMENTATION_THRESHOLD, 8000),
50 WCN36XX_CFG_VAL(DYNAMIC_THRESHOLD_ZERO, 5),
51 WCN36XX_CFG_VAL(DYNAMIC_THRESHOLD_ONE, 10),
52 WCN36XX_CFG_VAL(DYNAMIC_THRESHOLD_TWO, 15),
53 WCN36XX_CFG_VAL(FIXED_RATE, 0),
54 WCN36XX_CFG_VAL(RETRYRATE_POLICY, 4),
55 WCN36XX_CFG_VAL(RETRYRATE_SECONDARY, 0),
56 WCN36XX_CFG_VAL(RETRYRATE_TERTIARY, 0),
57 WCN36XX_CFG_VAL(FORCE_POLICY_PROTECTION, 5),
58 WCN36XX_CFG_VAL(FIXED_RATE_MULTICAST_24GHZ, 1),
59 WCN36XX_CFG_VAL(FIXED_RATE_MULTICAST_5GHZ, 5),
60 WCN36XX_CFG_VAL(DEFAULT_RATE_INDEX_5GHZ, 5),
61 WCN36XX_CFG_VAL(MAX_BA_SESSIONS, 40),
62 WCN36XX_CFG_VAL(PS_DATA_INACTIVITY_TIMEOUT, 200),
63 WCN36XX_CFG_VAL(PS_ENABLE_BCN_FILTER, 1),
64 WCN36XX_CFG_VAL(PS_ENABLE_RSSI_MONITOR, 1),
65 WCN36XX_CFG_VAL(NUM_BEACON_PER_RSSI_AVERAGE, 20),
66 WCN36XX_CFG_VAL(STATS_PERIOD, 10),
67 WCN36XX_CFG_VAL(CFP_MAX_DURATION, 30000),
68 WCN36XX_CFG_VAL(FRAME_TRANS_ENABLED, 0),
69 WCN36XX_CFG_VAL(BA_THRESHOLD_HIGH, 128),
70 WCN36XX_CFG_VAL(MAX_BA_BUFFERS, 2560),
71 WCN36XX_CFG_VAL(DYNAMIC_PS_POLL_VALUE, 0),
72 WCN36XX_CFG_VAL(TX_PWR_CTRL_ENABLE, 1),
73 WCN36XX_CFG_VAL(ENABLE_CLOSE_LOOP, 1),
74 WCN36XX_CFG_VAL(ENABLE_LPWR_IMG_TRANSITION, 0),
75 WCN36XX_CFG_VAL(MAX_ASSOC_LIMIT, 10),
76 WCN36XX_CFG_VAL(ENABLE_MCC_ADAPTIVE_SCHEDULER, 0),
79 static int put_cfg_tlv_u32(struct wcn36xx *wcn, size_t *len, u32 id, u32 value)
81 struct wcn36xx_hal_cfg *entry;
84 if (*len + sizeof(*entry) + sizeof(u32) >= WCN36XX_HAL_BUF_SIZE) {
85 wcn36xx_err("Not enough room for TLV entry\n");
89 entry = (struct wcn36xx_hal_cfg *) (wcn->hal_buf + *len);
91 entry->len = sizeof(u32);
95 val = (u32 *) (entry + 1);
98 *len += sizeof(*entry) + sizeof(u32);
103 static void wcn36xx_smd_set_bss_nw_type(struct wcn36xx *wcn,
104 struct ieee80211_sta *sta,
105 struct wcn36xx_hal_config_bss_params *bss_params)
107 if (IEEE80211_BAND_5GHZ == WCN36XX_BAND(wcn))
108 bss_params->nw_type = WCN36XX_HAL_11A_NW_TYPE;
109 else if (sta && sta->ht_cap.ht_supported)
110 bss_params->nw_type = WCN36XX_HAL_11N_NW_TYPE;
111 else if (sta && (sta->supp_rates[IEEE80211_BAND_2GHZ] & 0x7f))
112 bss_params->nw_type = WCN36XX_HAL_11G_NW_TYPE;
114 bss_params->nw_type = WCN36XX_HAL_11B_NW_TYPE;
117 static inline u8 is_cap_supported(unsigned long caps, unsigned long flag)
119 return caps & flag ? 1 : 0;
121 static void wcn36xx_smd_set_bss_ht_params(struct ieee80211_vif *vif,
122 struct ieee80211_sta *sta,
123 struct wcn36xx_hal_config_bss_params *bss_params)
125 if (sta && sta->ht_cap.ht_supported) {
126 unsigned long caps = sta->ht_cap.cap;
127 bss_params->ht = sta->ht_cap.ht_supported;
128 bss_params->tx_channel_width_set = is_cap_supported(caps,
129 IEEE80211_HT_CAP_SUP_WIDTH_20_40);
130 bss_params->lsig_tx_op_protection_full_support =
131 is_cap_supported(caps,
132 IEEE80211_HT_CAP_LSIG_TXOP_PROT);
134 bss_params->ht_oper_mode = vif->bss_conf.ht_operation_mode;
135 bss_params->lln_non_gf_coexist =
136 !!(vif->bss_conf.ht_operation_mode &
137 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
138 /* IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT */
139 bss_params->dual_cts_protection = 0;
140 /* IEEE80211_HT_OP_MODE_PROTECTION_20MHZ */
141 bss_params->ht20_coexist = 0;
145 static void wcn36xx_smd_set_sta_ht_params(struct ieee80211_sta *sta,
146 struct wcn36xx_hal_config_sta_params *sta_params)
148 if (sta->ht_cap.ht_supported) {
149 unsigned long caps = sta->ht_cap.cap;
150 sta_params->ht_capable = sta->ht_cap.ht_supported;
151 sta_params->tx_channel_width_set = is_cap_supported(caps,
152 IEEE80211_HT_CAP_SUP_WIDTH_20_40);
153 sta_params->lsig_txop_protection = is_cap_supported(caps,
154 IEEE80211_HT_CAP_LSIG_TXOP_PROT);
156 sta_params->max_ampdu_size = sta->ht_cap.ampdu_factor;
157 sta_params->max_ampdu_density = sta->ht_cap.ampdu_density;
158 sta_params->max_amsdu_size = is_cap_supported(caps,
159 IEEE80211_HT_CAP_MAX_AMSDU);
160 sta_params->sgi_20Mhz = is_cap_supported(caps,
161 IEEE80211_HT_CAP_SGI_20);
162 sta_params->sgi_40mhz = is_cap_supported(caps,
163 IEEE80211_HT_CAP_SGI_40);
164 sta_params->green_field_capable = is_cap_supported(caps,
165 IEEE80211_HT_CAP_GRN_FLD);
166 sta_params->delayed_ba_support = is_cap_supported(caps,
167 IEEE80211_HT_CAP_DELAY_BA);
168 sta_params->dsss_cck_mode_40mhz = is_cap_supported(caps,
169 IEEE80211_HT_CAP_DSSSCCK40);
173 static void wcn36xx_smd_set_sta_default_ht_params(
174 struct wcn36xx_hal_config_sta_params *sta_params)
176 sta_params->ht_capable = 1;
177 sta_params->tx_channel_width_set = 1;
178 sta_params->lsig_txop_protection = 1;
179 sta_params->max_ampdu_size = 3;
180 sta_params->max_ampdu_density = 5;
181 sta_params->max_amsdu_size = 0;
182 sta_params->sgi_20Mhz = 1;
183 sta_params->sgi_40mhz = 1;
184 sta_params->green_field_capable = 1;
185 sta_params->delayed_ba_support = 0;
186 sta_params->dsss_cck_mode_40mhz = 1;
189 static void wcn36xx_smd_set_sta_params(struct wcn36xx *wcn,
190 struct ieee80211_vif *vif,
191 struct ieee80211_sta *sta,
192 struct wcn36xx_hal_config_sta_params *sta_params)
194 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
195 struct wcn36xx_sta *priv_sta = NULL;
196 if (vif->type == NL80211_IFTYPE_ADHOC ||
197 vif->type == NL80211_IFTYPE_AP ||
198 vif->type == NL80211_IFTYPE_MESH_POINT) {
199 sta_params->type = 1;
200 sta_params->sta_index = 0xFF;
202 sta_params->type = 0;
203 sta_params->sta_index = 1;
206 sta_params->listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
209 * In STA mode ieee80211_sta contains bssid and ieee80211_vif
210 * contains our mac address. In AP mode we are bssid so vif
211 * contains bssid and ieee80211_sta contains mac.
213 if (NL80211_IFTYPE_STATION == vif->type)
214 memcpy(&sta_params->mac, vif->addr, ETH_ALEN);
216 memcpy(&sta_params->bssid, vif->addr, ETH_ALEN);
218 sta_params->encrypt_type = priv_vif->encrypt_type;
219 sta_params->short_preamble_supported = true;
221 sta_params->rifs_mode = 0;
223 sta_params->action = 0;
224 sta_params->uapsd = 0;
225 sta_params->mimo_ps = WCN36XX_HAL_HT_MIMO_PS_STATIC;
226 sta_params->max_ampdu_duration = 0;
227 sta_params->bssid_index = priv_vif->bss_index;
231 priv_sta = (struct wcn36xx_sta *)sta->drv_priv;
232 if (NL80211_IFTYPE_STATION == vif->type)
233 memcpy(&sta_params->bssid, sta->addr, ETH_ALEN);
235 memcpy(&sta_params->mac, sta->addr, ETH_ALEN);
236 sta_params->wmm_enabled = sta->wme;
237 sta_params->max_sp_len = sta->max_sp;
238 sta_params->aid = priv_sta->aid;
239 wcn36xx_smd_set_sta_ht_params(sta, sta_params);
240 memcpy(&sta_params->supported_rates, &priv_sta->supported_rates,
241 sizeof(priv_sta->supported_rates));
243 wcn36xx_set_default_rates(&sta_params->supported_rates);
244 wcn36xx_smd_set_sta_default_ht_params(sta_params);
248 static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len)
252 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "HAL >>> ", wcn->hal_buf, len);
254 init_completion(&wcn->hal_rsp_compl);
256 ret = wcn->ctrl_ops->tx(wcn->hal_buf, len);
258 wcn36xx_err("HAL TX failed\n");
261 if (wait_for_completion_timeout(&wcn->hal_rsp_compl,
262 msecs_to_jiffies(HAL_MSG_TIMEOUT)) <= 0) {
263 wcn36xx_err("Timeout! No SMD response in %dms\n",
268 wcn36xx_dbg(WCN36XX_DBG_SMD, "SMD command completed in %dms",
269 jiffies_to_msecs(jiffies - start));
274 #define INIT_HAL_MSG(msg_body, type) \
276 memset(&msg_body, 0, sizeof(msg_body)); \
277 msg_body.header.msg_type = type; \
278 msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
279 msg_body.header.len = sizeof(msg_body); \
282 #define PREPARE_HAL_BUF(send_buf, msg_body) \
284 memset(send_buf, 0, msg_body.header.len); \
285 memcpy(send_buf, &msg_body, sizeof(msg_body)); \
288 static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
290 struct wcn36xx_fw_msg_status_rsp *rsp;
292 if (len < sizeof(struct wcn36xx_hal_msg_header) +
293 sizeof(struct wcn36xx_fw_msg_status_rsp))
296 rsp = (struct wcn36xx_fw_msg_status_rsp *)
297 (buf + sizeof(struct wcn36xx_hal_msg_header));
299 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status)
305 static int wcn36xx_smd_rsp_status_check_v2(struct wcn36xx *wcn, void *buf,
308 struct wcn36xx_fw_msg_status_rsp_v2 *rsp;
310 if (wcn->chip_version != WCN36XX_CHIP_3620 ||
311 len < sizeof(struct wcn36xx_hal_msg_header) + sizeof(*rsp))
312 return wcn36xx_smd_rsp_status_check(buf, len);
314 rsp = buf + sizeof(struct wcn36xx_hal_msg_header);
316 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status)
322 int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
324 struct nv_data *nv_d;
325 struct wcn36xx_hal_nv_img_download_req_msg msg_body;
331 ret = request_firmware(&wcn->nv, WLAN_NV_FILE, wcn->dev);
333 wcn36xx_err("Failed to load nv file %s: %d\n",
339 nv_d = (struct nv_data *)wcn->nv->data;
340 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ);
342 msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE;
344 msg_body.frag_number = 0;
345 /* hal_buf must be protected with mutex */
346 mutex_lock(&wcn->hal_mutex);
349 fw_bytes_left = wcn->nv->size - fm_offset - 4;
350 if (fw_bytes_left > WCN36XX_NV_FRAGMENT_SIZE) {
351 msg_body.last_fragment = 0;
352 msg_body.nv_img_buffer_size = WCN36XX_NV_FRAGMENT_SIZE;
354 msg_body.last_fragment = 1;
355 msg_body.nv_img_buffer_size = fw_bytes_left;
357 /* Do not forget update general message len */
358 msg_body.header.len = sizeof(msg_body) + fw_bytes_left;
362 /* Add load NV request message header */
363 memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body));
365 /* Add NV body itself */
366 memcpy(wcn->hal_buf + sizeof(msg_body),
367 &nv_d->table + fm_offset,
368 msg_body.nv_img_buffer_size);
370 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
373 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf,
376 wcn36xx_err("hal_load_nv response failed err=%d\n",
380 msg_body.frag_number++;
381 fm_offset += WCN36XX_NV_FRAGMENT_SIZE;
383 } while (msg_body.last_fragment != 1);
386 mutex_unlock(&wcn->hal_mutex);
390 static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len)
392 struct wcn36xx_hal_mac_start_rsp_msg *rsp;
394 if (len < sizeof(*rsp))
397 rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf;
399 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status)
402 memcpy(wcn->crm_version, rsp->start_rsp_params.crm_version,
403 WCN36XX_HAL_VERSION_LENGTH);
404 memcpy(wcn->wlan_version, rsp->start_rsp_params.wlan_version,
405 WCN36XX_HAL_VERSION_LENGTH);
407 /* null terminate the strings, just in case */
408 wcn->crm_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
409 wcn->wlan_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
411 wcn->fw_revision = rsp->start_rsp_params.version.revision;
412 wcn->fw_version = rsp->start_rsp_params.version.version;
413 wcn->fw_minor = rsp->start_rsp_params.version.minor;
414 wcn->fw_major = rsp->start_rsp_params.version.major;
416 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
417 wcn->wlan_version, wcn->crm_version);
419 wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
420 wcn->fw_major, wcn->fw_minor,
421 wcn->fw_version, wcn->fw_revision,
422 rsp->start_rsp_params.stations,
423 rsp->start_rsp_params.bssids);
428 int wcn36xx_smd_start(struct wcn36xx *wcn)
430 struct wcn36xx_hal_mac_start_req_msg msg_body, *body;
435 mutex_lock(&wcn->hal_mutex);
436 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ);
438 msg_body.params.type = DRIVER_TYPE_PRODUCTION;
439 msg_body.params.len = 0;
441 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
443 body = (struct wcn36xx_hal_mac_start_req_msg *)wcn->hal_buf;
444 len = body->header.len;
446 for (i = 0; i < ARRAY_SIZE(wcn36xx_cfg_vals); i++) {
447 ret = put_cfg_tlv_u32(wcn, &len, wcn36xx_cfg_vals[i].cfg_id,
448 wcn36xx_cfg_vals[i].value);
452 body->header.len = len;
453 body->params.len = len - sizeof(*body);
455 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n",
456 msg_body.params.type);
458 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
460 wcn36xx_err("Sending hal_start failed\n");
464 ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len);
466 wcn36xx_err("hal_start response failed err=%d\n", ret);
471 mutex_unlock(&wcn->hal_mutex);
475 int wcn36xx_smd_stop(struct wcn36xx *wcn)
477 struct wcn36xx_hal_mac_stop_req_msg msg_body;
480 mutex_lock(&wcn->hal_mutex);
481 INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ);
483 msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL;
485 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
487 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
489 wcn36xx_err("Sending hal_stop failed\n");
492 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
494 wcn36xx_err("hal_stop response failed err=%d\n", ret);
498 mutex_unlock(&wcn->hal_mutex);
502 int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode)
504 struct wcn36xx_hal_init_scan_req_msg msg_body;
507 mutex_lock(&wcn->hal_mutex);
508 INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ);
510 msg_body.mode = mode;
512 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
514 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode);
516 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
518 wcn36xx_err("Sending hal_init_scan failed\n");
521 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
523 wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
527 mutex_unlock(&wcn->hal_mutex);
531 int wcn36xx_smd_start_scan(struct wcn36xx *wcn)
533 struct wcn36xx_hal_start_scan_req_msg msg_body;
536 mutex_lock(&wcn->hal_mutex);
537 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ);
539 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
541 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
543 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n",
544 msg_body.scan_channel);
546 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
548 wcn36xx_err("Sending hal_start_scan failed\n");
551 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
553 wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
557 mutex_unlock(&wcn->hal_mutex);
561 int wcn36xx_smd_end_scan(struct wcn36xx *wcn)
563 struct wcn36xx_hal_end_scan_req_msg msg_body;
566 mutex_lock(&wcn->hal_mutex);
567 INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ);
569 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
571 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
573 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n",
574 msg_body.scan_channel);
576 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
578 wcn36xx_err("Sending hal_end_scan failed\n");
581 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
583 wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
587 mutex_unlock(&wcn->hal_mutex);
591 int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
592 enum wcn36xx_hal_sys_mode mode)
594 struct wcn36xx_hal_finish_scan_req_msg msg_body;
597 mutex_lock(&wcn->hal_mutex);
598 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ);
600 msg_body.mode = mode;
602 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
604 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n",
607 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
609 wcn36xx_err("Sending hal_finish_scan failed\n");
612 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
614 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
618 mutex_unlock(&wcn->hal_mutex);
622 static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
624 struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
627 ret = wcn36xx_smd_rsp_status_check(buf, len);
630 rsp = (struct wcn36xx_hal_switch_channel_rsp_msg *)buf;
631 wcn36xx_dbg(WCN36XX_DBG_HAL, "channel switched to: %d, status: %d\n",
632 rsp->channel_number, rsp->status);
636 int wcn36xx_smd_switch_channel(struct wcn36xx *wcn,
637 struct ieee80211_vif *vif, int ch)
639 struct wcn36xx_hal_switch_channel_req_msg msg_body;
642 mutex_lock(&wcn->hal_mutex);
643 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ);
645 msg_body.channel_number = (u8)ch;
646 msg_body.tx_mgmt_power = 0xbf;
647 msg_body.max_tx_power = 0xbf;
648 memcpy(msg_body.self_sta_mac_addr, vif->addr, ETH_ALEN);
650 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
652 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
654 wcn36xx_err("Sending hal_switch_channel failed\n");
657 ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len);
659 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret);
663 mutex_unlock(&wcn->hal_mutex);
667 static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len)
669 struct wcn36xx_hal_update_scan_params_resp *rsp;
671 rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf;
673 /* Remove the PNO version bit */
674 rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK));
676 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) {
677 wcn36xx_warn("error response from update scan\n");
684 int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn)
686 struct wcn36xx_hal_update_scan_params_req msg_body;
689 mutex_lock(&wcn->hal_mutex);
690 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ);
692 msg_body.dot11d_enabled = 0;
693 msg_body.dot11d_resolved = 0;
694 msg_body.channel_count = 26;
695 msg_body.active_min_ch_time = 60;
696 msg_body.active_max_ch_time = 120;
697 msg_body.passive_min_ch_time = 60;
698 msg_body.passive_max_ch_time = 110;
701 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
703 wcn36xx_dbg(WCN36XX_DBG_HAL,
704 "hal update scan params channel_count %d\n",
705 msg_body.channel_count);
707 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
709 wcn36xx_err("Sending hal_update_scan_params failed\n");
712 ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf,
715 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
720 mutex_unlock(&wcn->hal_mutex);
724 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn,
725 struct ieee80211_vif *vif,
729 struct wcn36xx_hal_add_sta_self_rsp_msg *rsp;
730 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
732 if (len < sizeof(*rsp))
735 rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf;
737 if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
738 wcn36xx_warn("hal add sta self failure: %d\n",
743 wcn36xx_dbg(WCN36XX_DBG_HAL,
744 "hal add sta self status %d self_sta_index %d dpu_index %d\n",
745 rsp->status, rsp->self_sta_index, rsp->dpu_index);
747 priv_vif->self_sta_index = rsp->self_sta_index;
748 priv_vif->self_dpu_desc_index = rsp->dpu_index;
753 int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif)
755 struct wcn36xx_hal_add_sta_self_req msg_body;
758 mutex_lock(&wcn->hal_mutex);
759 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ);
761 memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN);
763 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
765 wcn36xx_dbg(WCN36XX_DBG_HAL,
766 "hal add sta self self_addr %pM status %d\n",
767 msg_body.self_addr, msg_body.status);
769 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
771 wcn36xx_err("Sending hal_add_sta_self failed\n");
774 ret = wcn36xx_smd_add_sta_self_rsp(wcn,
779 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret);
783 mutex_unlock(&wcn->hal_mutex);
787 int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr)
789 struct wcn36xx_hal_del_sta_self_req_msg msg_body;
792 mutex_lock(&wcn->hal_mutex);
793 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ);
795 memcpy(&msg_body.self_addr, addr, ETH_ALEN);
797 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
799 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
801 wcn36xx_err("Sending hal_delete_sta_self failed\n");
804 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
806 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
811 mutex_unlock(&wcn->hal_mutex);
815 int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index)
817 struct wcn36xx_hal_delete_sta_req_msg msg_body;
820 mutex_lock(&wcn->hal_mutex);
821 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ);
823 msg_body.sta_index = sta_index;
825 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
827 wcn36xx_dbg(WCN36XX_DBG_HAL,
828 "hal delete sta sta_index %d\n",
831 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
833 wcn36xx_err("Sending hal_delete_sta failed\n");
836 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
838 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret);
842 mutex_unlock(&wcn->hal_mutex);
846 static int wcn36xx_smd_join_rsp(void *buf, size_t len)
848 struct wcn36xx_hal_join_rsp_msg *rsp;
850 if (wcn36xx_smd_rsp_status_check(buf, len))
853 rsp = (struct wcn36xx_hal_join_rsp_msg *)buf;
855 wcn36xx_dbg(WCN36XX_DBG_HAL,
856 "hal rsp join status %d tx_mgmt_power %d\n",
857 rsp->status, rsp->tx_mgmt_power);
862 int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch)
864 struct wcn36xx_hal_join_req_msg msg_body;
867 mutex_lock(&wcn->hal_mutex);
868 INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ);
870 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
871 memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN);
872 msg_body.channel = ch;
874 if (conf_is_ht40_minus(&wcn->hw->conf))
875 msg_body.secondary_channel_offset =
876 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY;
877 else if (conf_is_ht40_plus(&wcn->hw->conf))
878 msg_body.secondary_channel_offset =
879 PHY_DOUBLE_CHANNEL_LOW_PRIMARY;
881 msg_body.secondary_channel_offset =
882 PHY_SINGLE_CHANNEL_CENTERED;
884 msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE;
886 msg_body.max_tx_power = 0xbf;
887 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
889 wcn36xx_dbg(WCN36XX_DBG_HAL,
890 "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
891 msg_body.bssid, msg_body.self_sta_mac_addr,
892 msg_body.channel, msg_body.link_state);
894 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
896 wcn36xx_err("Sending hal_join failed\n");
899 ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len);
901 wcn36xx_err("hal_join response failed err=%d\n", ret);
905 mutex_unlock(&wcn->hal_mutex);
909 int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid,
911 enum wcn36xx_hal_link_state state)
913 struct wcn36xx_hal_set_link_state_req_msg msg_body;
916 mutex_lock(&wcn->hal_mutex);
917 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ);
919 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
920 memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN);
921 msg_body.state = state;
923 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
925 wcn36xx_dbg(WCN36XX_DBG_HAL,
926 "hal set link state bssid %pM self_mac_addr %pM state %d\n",
927 msg_body.bssid, msg_body.self_mac_addr, msg_body.state);
929 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
931 wcn36xx_err("Sending hal_set_link_st failed\n");
934 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
936 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret);
940 mutex_unlock(&wcn->hal_mutex);
944 static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx *wcn,
945 const struct wcn36xx_hal_config_sta_params *orig,
946 struct wcn36xx_hal_config_sta_params_v1 *v1)
948 /* convert orig to v1 format */
949 memcpy(&v1->bssid, orig->bssid, ETH_ALEN);
950 memcpy(&v1->mac, orig->mac, ETH_ALEN);
952 v1->type = orig->type;
953 v1->listen_interval = orig->listen_interval;
954 v1->ht_capable = orig->ht_capable;
956 v1->max_ampdu_size = orig->max_ampdu_size;
957 v1->max_ampdu_density = orig->max_ampdu_density;
958 v1->sgi_40mhz = orig->sgi_40mhz;
959 v1->sgi_20Mhz = orig->sgi_20Mhz;
961 memcpy(&v1->supported_rates, &orig->supported_rates,
962 sizeof(orig->supported_rates));
963 v1->sta_index = orig->sta_index;
966 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn,
967 struct ieee80211_sta *sta,
971 struct wcn36xx_hal_config_sta_rsp_msg *rsp;
972 struct config_sta_rsp_params *params;
973 struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
975 if (len < sizeof(*rsp))
978 rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf;
979 params = &rsp->params;
981 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
982 wcn36xx_warn("hal config sta response failure: %d\n",
987 sta_priv->sta_index = params->sta_index;
988 sta_priv->dpu_desc_index = params->dpu_index;
989 sta_priv->ucast_dpu_sign = params->uc_ucast_sig;
991 wcn36xx_dbg(WCN36XX_DBG_HAL,
992 "hal config sta rsp status %d sta_index %d bssid_index %d uc_ucast_sig %d p2p %d\n",
993 params->status, params->sta_index, params->bssid_index,
994 params->uc_ucast_sig, params->p2p);
999 static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn,
1000 const struct wcn36xx_hal_config_sta_req_msg *orig)
1002 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body;
1003 struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params;
1005 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ);
1007 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params,
1008 &msg_body.sta_params);
1010 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1012 wcn36xx_dbg(WCN36XX_DBG_HAL,
1013 "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
1014 sta->action, sta->sta_index, sta->bssid_index,
1015 sta->bssid, sta->type, sta->mac, sta->aid);
1017 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1020 int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1021 struct ieee80211_sta *sta)
1023 struct wcn36xx_hal_config_sta_req_msg msg;
1024 struct wcn36xx_hal_config_sta_params *sta_params;
1027 mutex_lock(&wcn->hal_mutex);
1028 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ);
1030 sta_params = &msg.sta_params;
1032 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
1034 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1035 ret = wcn36xx_smd_config_sta_v1(wcn, &msg);
1037 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1039 wcn36xx_dbg(WCN36XX_DBG_HAL,
1040 "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
1041 sta_params->action, sta_params->sta_index,
1042 sta_params->bssid_index, sta_params->bssid,
1043 sta_params->type, sta_params->mac, sta_params->aid);
1045 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1048 wcn36xx_err("Sending hal_config_sta failed\n");
1051 ret = wcn36xx_smd_config_sta_rsp(wcn,
1056 wcn36xx_err("hal_config_sta response failed err=%d\n", ret);
1060 mutex_unlock(&wcn->hal_mutex);
1064 static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn,
1065 const struct wcn36xx_hal_config_bss_req_msg *orig)
1067 struct wcn36xx_hal_config_bss_req_msg_v1 msg_body;
1068 struct wcn36xx_hal_config_bss_params_v1 *bss = &msg_body.bss_params;
1069 struct wcn36xx_hal_config_sta_params_v1 *sta = &bss->sta;
1071 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ);
1073 /* convert orig to v1 */
1074 memcpy(&msg_body.bss_params.bssid,
1075 &orig->bss_params.bssid, ETH_ALEN);
1076 memcpy(&msg_body.bss_params.self_mac_addr,
1077 &orig->bss_params.self_mac_addr, ETH_ALEN);
1079 msg_body.bss_params.bss_type = orig->bss_params.bss_type;
1080 msg_body.bss_params.oper_mode = orig->bss_params.oper_mode;
1081 msg_body.bss_params.nw_type = orig->bss_params.nw_type;
1083 msg_body.bss_params.short_slot_time_supported =
1084 orig->bss_params.short_slot_time_supported;
1085 msg_body.bss_params.lla_coexist = orig->bss_params.lla_coexist;
1086 msg_body.bss_params.llb_coexist = orig->bss_params.llb_coexist;
1087 msg_body.bss_params.llg_coexist = orig->bss_params.llg_coexist;
1088 msg_body.bss_params.ht20_coexist = orig->bss_params.ht20_coexist;
1089 msg_body.bss_params.lln_non_gf_coexist =
1090 orig->bss_params.lln_non_gf_coexist;
1092 msg_body.bss_params.lsig_tx_op_protection_full_support =
1093 orig->bss_params.lsig_tx_op_protection_full_support;
1094 msg_body.bss_params.rifs_mode = orig->bss_params.rifs_mode;
1095 msg_body.bss_params.beacon_interval = orig->bss_params.beacon_interval;
1096 msg_body.bss_params.dtim_period = orig->bss_params.dtim_period;
1097 msg_body.bss_params.tx_channel_width_set =
1098 orig->bss_params.tx_channel_width_set;
1099 msg_body.bss_params.oper_channel = orig->bss_params.oper_channel;
1100 msg_body.bss_params.ext_channel = orig->bss_params.ext_channel;
1102 msg_body.bss_params.reserved = orig->bss_params.reserved;
1104 memcpy(&msg_body.bss_params.ssid,
1105 &orig->bss_params.ssid,
1106 sizeof(orig->bss_params.ssid));
1108 msg_body.bss_params.action = orig->bss_params.action;
1109 msg_body.bss_params.rateset = orig->bss_params.rateset;
1110 msg_body.bss_params.ht = orig->bss_params.ht;
1111 msg_body.bss_params.obss_prot_enabled =
1112 orig->bss_params.obss_prot_enabled;
1113 msg_body.bss_params.rmf = orig->bss_params.rmf;
1114 msg_body.bss_params.ht_oper_mode = orig->bss_params.ht_oper_mode;
1115 msg_body.bss_params.dual_cts_protection =
1116 orig->bss_params.dual_cts_protection;
1118 msg_body.bss_params.max_probe_resp_retry_limit =
1119 orig->bss_params.max_probe_resp_retry_limit;
1120 msg_body.bss_params.hidden_ssid = orig->bss_params.hidden_ssid;
1121 msg_body.bss_params.proxy_probe_resp =
1122 orig->bss_params.proxy_probe_resp;
1123 msg_body.bss_params.edca_params_valid =
1124 orig->bss_params.edca_params_valid;
1126 memcpy(&msg_body.bss_params.acbe,
1127 &orig->bss_params.acbe,
1128 sizeof(orig->bss_params.acbe));
1129 memcpy(&msg_body.bss_params.acbk,
1130 &orig->bss_params.acbk,
1131 sizeof(orig->bss_params.acbk));
1132 memcpy(&msg_body.bss_params.acvi,
1133 &orig->bss_params.acvi,
1134 sizeof(orig->bss_params.acvi));
1135 memcpy(&msg_body.bss_params.acvo,
1136 &orig->bss_params.acvo,
1137 sizeof(orig->bss_params.acvo));
1139 msg_body.bss_params.ext_set_sta_key_param_valid =
1140 orig->bss_params.ext_set_sta_key_param_valid;
1142 memcpy(&msg_body.bss_params.ext_set_sta_key_param,
1143 &orig->bss_params.ext_set_sta_key_param,
1144 sizeof(orig->bss_params.acvo));
1146 msg_body.bss_params.wcn36xx_hal_persona =
1147 orig->bss_params.wcn36xx_hal_persona;
1148 msg_body.bss_params.spectrum_mgt_enable =
1149 orig->bss_params.spectrum_mgt_enable;
1150 msg_body.bss_params.tx_mgmt_power = orig->bss_params.tx_mgmt_power;
1151 msg_body.bss_params.max_tx_power = orig->bss_params.max_tx_power;
1153 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta,
1154 &msg_body.bss_params.sta);
1156 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1158 wcn36xx_dbg(WCN36XX_DBG_HAL,
1159 "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1160 bss->bssid, bss->self_mac_addr, bss->bss_type,
1161 bss->oper_mode, bss->nw_type);
1163 wcn36xx_dbg(WCN36XX_DBG_HAL,
1164 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1165 sta->bssid, sta->action, sta->sta_index,
1166 sta->bssid_index, sta->aid, sta->type, sta->mac);
1168 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1172 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn,
1173 struct ieee80211_vif *vif,
1177 struct wcn36xx_hal_config_bss_rsp_msg *rsp;
1178 struct wcn36xx_hal_config_bss_rsp_params *params;
1179 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
1181 if (len < sizeof(*rsp))
1184 rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf;
1185 params = &rsp->bss_rsp_params;
1187 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
1188 wcn36xx_warn("hal config bss response failure: %d\n",
1193 wcn36xx_dbg(WCN36XX_DBG_HAL,
1194 "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
1195 " sta_idx %d self_idx %d bcast_idx %d mac %pM"
1196 " power %d ucast_dpu_signature %d\n",
1197 params->status, params->bss_index, params->dpu_desc_index,
1198 params->bss_sta_index, params->bss_self_sta_index,
1199 params->bss_bcast_sta_idx, params->mac,
1200 params->tx_mgmt_power, params->ucast_dpu_signature);
1202 priv_vif->bss_index = params->bss_index;
1204 if (priv_vif->sta) {
1205 priv_vif->sta->bss_sta_index = params->bss_sta_index;
1206 priv_vif->sta->bss_dpu_desc_index = params->dpu_desc_index;
1209 priv_vif->self_ucast_dpu_sign = params->ucast_dpu_signature;
1214 int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1215 struct ieee80211_sta *sta, const u8 *bssid,
1218 struct wcn36xx_hal_config_bss_req_msg msg;
1219 struct wcn36xx_hal_config_bss_params *bss;
1220 struct wcn36xx_hal_config_sta_params *sta_params;
1221 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1224 mutex_lock(&wcn->hal_mutex);
1225 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ);
1227 bss = &msg.bss_params;
1228 sta_params = &bss->sta;
1230 WARN_ON(is_zero_ether_addr(bssid));
1232 memcpy(&bss->bssid, bssid, ETH_ALEN);
1234 memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN);
1236 if (vif->type == NL80211_IFTYPE_STATION) {
1237 bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE;
1241 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_MODE;
1242 } else if (vif->type == NL80211_IFTYPE_AP ||
1243 vif->type == NL80211_IFTYPE_MESH_POINT) {
1244 bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE;
1248 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE;
1249 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
1250 bss->bss_type = WCN36XX_HAL_IBSS_MODE;
1255 wcn36xx_warn("Unknown type for bss config: %d\n", vif->type);
1258 if (vif->type == NL80211_IFTYPE_STATION)
1259 wcn36xx_smd_set_bss_nw_type(wcn, sta, bss);
1261 bss->nw_type = WCN36XX_HAL_11N_NW_TYPE;
1263 bss->short_slot_time_supported = vif->bss_conf.use_short_slot;
1264 bss->lla_coexist = 0;
1265 bss->llb_coexist = 0;
1266 bss->llg_coexist = 0;
1268 bss->beacon_interval = vif->bss_conf.beacon_int;
1269 bss->dtim_period = vif_priv->dtim_period;
1271 wcn36xx_smd_set_bss_ht_params(vif, sta, bss);
1273 bss->oper_channel = WCN36XX_HW_CHANNEL(wcn);
1275 if (conf_is_ht40_minus(&wcn->hw->conf))
1276 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1277 else if (conf_is_ht40_plus(&wcn->hw->conf))
1278 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1280 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1283 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
1285 /* wcn->ssid is only valid in AP and IBSS mode */
1286 bss->ssid.length = vif_priv->ssid.length;
1287 memcpy(bss->ssid.ssid, vif_priv->ssid.ssid, vif_priv->ssid.length);
1289 bss->obss_prot_enabled = 0;
1291 bss->max_probe_resp_retry_limit = 0;
1292 bss->hidden_ssid = vif->bss_conf.hidden_ssid;
1293 bss->proxy_probe_resp = 0;
1294 bss->edca_params_valid = 0;
1296 /* FIXME: set acbe, acbk, acvi and acvo */
1298 bss->ext_set_sta_key_param_valid = 0;
1300 /* FIXME: set ext_set_sta_key_param */
1302 bss->spectrum_mgt_enable = 0;
1303 bss->tx_mgmt_power = 0;
1304 bss->max_tx_power = WCN36XX_MAX_POWER(wcn);
1306 bss->action = update;
1308 wcn36xx_dbg(WCN36XX_DBG_HAL,
1309 "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1310 bss->bssid, bss->self_mac_addr, bss->bss_type,
1311 bss->oper_mode, bss->nw_type);
1313 wcn36xx_dbg(WCN36XX_DBG_HAL,
1314 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1315 sta_params->bssid, sta_params->action,
1316 sta_params->sta_index, sta_params->bssid_index,
1317 sta_params->aid, sta_params->type,
1320 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1321 ret = wcn36xx_smd_config_bss_v1(wcn, &msg);
1323 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1325 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1328 wcn36xx_err("Sending hal_config_bss failed\n");
1331 ret = wcn36xx_smd_config_bss_rsp(wcn,
1336 wcn36xx_err("hal_config_bss response failed err=%d\n", ret);
1340 mutex_unlock(&wcn->hal_mutex);
1344 int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1346 struct wcn36xx_hal_delete_bss_req_msg msg_body;
1347 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
1350 mutex_lock(&wcn->hal_mutex);
1351 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ);
1353 msg_body.bss_index = priv_vif->bss_index;
1355 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1357 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index);
1359 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1361 wcn36xx_err("Sending hal_delete_bss failed\n");
1364 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1366 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret);
1370 mutex_unlock(&wcn->hal_mutex);
1374 int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1375 struct sk_buff *skb_beacon, u16 tim_off,
1378 struct wcn36xx_hal_send_beacon_req_msg msg_body;
1381 mutex_lock(&wcn->hal_mutex);
1382 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ);
1384 /* TODO need to find out why this is needed? */
1385 msg_body.beacon_length = skb_beacon->len + 6;
1387 if (BEACON_TEMPLATE_SIZE > msg_body.beacon_length) {
1388 memcpy(&msg_body.beacon, &skb_beacon->len, sizeof(u32));
1389 memcpy(&(msg_body.beacon[4]), skb_beacon->data,
1392 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1393 msg_body.beacon_length);
1397 memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
1399 /* TODO need to find out why this is needed? */
1400 if (vif->type == NL80211_IFTYPE_MESH_POINT)
1401 /* mesh beacon don't need this, so push further down */
1402 msg_body.tim_ie_offset = 256;
1404 msg_body.tim_ie_offset = tim_off+4;
1405 msg_body.p2p_ie_offset = p2p_off;
1406 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1408 wcn36xx_dbg(WCN36XX_DBG_HAL,
1409 "hal send beacon beacon_length %d\n",
1410 msg_body.beacon_length);
1412 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1414 wcn36xx_err("Sending hal_send_beacon failed\n");
1417 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1419 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
1423 mutex_unlock(&wcn->hal_mutex);
1427 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
1428 struct ieee80211_vif *vif,
1429 struct sk_buff *skb)
1431 struct wcn36xx_hal_send_probe_resp_req_msg msg;
1434 mutex_lock(&wcn->hal_mutex);
1435 INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
1437 if (skb->len > BEACON_TEMPLATE_SIZE) {
1438 wcn36xx_warn("probe response template is too big: %d\n",
1444 msg.probe_resp_template_len = skb->len;
1445 memcpy(&msg.probe_resp_template, skb->data, skb->len);
1447 memcpy(msg.bssid, vif->addr, ETH_ALEN);
1449 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1451 wcn36xx_dbg(WCN36XX_DBG_HAL,
1452 "hal update probe rsp len %d bssid %pM\n",
1453 msg.probe_resp_template_len, msg.bssid);
1455 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1457 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1460 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1462 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1467 mutex_unlock(&wcn->hal_mutex);
1471 int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
1472 enum ani_ed_type enc_type,
1478 struct wcn36xx_hal_set_sta_key_req_msg msg_body;
1481 mutex_lock(&wcn->hal_mutex);
1482 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
1484 msg_body.set_sta_key_params.sta_index = sta_index;
1485 msg_body.set_sta_key_params.enc_type = enc_type;
1487 msg_body.set_sta_key_params.key[0].id = keyidx;
1488 msg_body.set_sta_key_params.key[0].unicast = 1;
1489 msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX;
1490 msg_body.set_sta_key_params.key[0].pae_role = 0;
1491 msg_body.set_sta_key_params.key[0].length = keylen;
1492 memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen);
1493 msg_body.set_sta_key_params.single_tid_rc = 1;
1495 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1497 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1499 wcn36xx_err("Sending hal_set_stakey failed\n");
1502 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1504 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
1508 mutex_unlock(&wcn->hal_mutex);
1512 int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
1513 enum ani_ed_type enc_type,
1518 struct wcn36xx_hal_set_bss_key_req_msg msg_body;
1521 mutex_lock(&wcn->hal_mutex);
1522 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ);
1523 msg_body.bss_idx = 0;
1524 msg_body.enc_type = enc_type;
1525 msg_body.num_keys = 1;
1526 msg_body.keys[0].id = keyidx;
1527 msg_body.keys[0].unicast = 0;
1528 msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY;
1529 msg_body.keys[0].pae_role = 0;
1530 msg_body.keys[0].length = keylen;
1531 memcpy(msg_body.keys[0].key, key, keylen);
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_set_bsskey failed\n");
1540 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1542 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
1546 mutex_unlock(&wcn->hal_mutex);
1550 int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
1551 enum ani_ed_type enc_type,
1555 struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
1558 mutex_lock(&wcn->hal_mutex);
1559 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
1561 msg_body.sta_idx = sta_index;
1562 msg_body.enc_type = enc_type;
1563 msg_body.key_id = keyidx;
1565 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1567 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1569 wcn36xx_err("Sending hal_remove_stakey failed\n");
1572 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1574 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
1578 mutex_unlock(&wcn->hal_mutex);
1582 int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
1583 enum ani_ed_type enc_type,
1586 struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
1589 mutex_lock(&wcn->hal_mutex);
1590 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ);
1591 msg_body.bss_idx = 0;
1592 msg_body.enc_type = enc_type;
1593 msg_body.key_id = keyidx;
1595 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1597 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1599 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1602 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1604 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
1608 mutex_unlock(&wcn->hal_mutex);
1612 int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1614 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1615 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1618 mutex_lock(&wcn->hal_mutex);
1619 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
1621 msg_body.bss_index = vif_priv->bss_index;
1622 msg_body.tbtt = vif->bss_conf.sync_tsf;
1623 msg_body.dtim_period = vif_priv->dtim_period;
1625 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1627 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1629 wcn36xx_err("Sending hal_enter_bmps failed\n");
1632 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1634 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
1638 mutex_unlock(&wcn->hal_mutex);
1642 int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1644 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1645 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1648 mutex_lock(&wcn->hal_mutex);
1649 INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
1651 msg_body.bss_index = vif_priv->bss_index;
1653 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1655 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1657 wcn36xx_err("Sending hal_exit_bmps failed\n");
1660 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1662 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1666 mutex_unlock(&wcn->hal_mutex);
1669 int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
1671 struct wcn36xx_hal_set_power_params_req_msg msg_body;
1674 mutex_lock(&wcn->hal_mutex);
1675 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
1678 * When host is down ignore every second dtim
1681 msg_body.ignore_dtim = 1;
1682 msg_body.dtim_period = 2;
1684 msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
1686 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1688 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1690 wcn36xx_err("Sending hal_set_power_params failed\n");
1695 mutex_unlock(&wcn->hal_mutex);
1698 /* Notice: This function should be called after associated, or else it
1701 int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
1702 struct ieee80211_vif *vif,
1705 struct wcn36xx_hal_keep_alive_req_msg msg_body;
1706 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1709 mutex_lock(&wcn->hal_mutex);
1710 INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
1712 if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) {
1713 msg_body.bss_index = vif_priv->bss_index;
1714 msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT;
1715 msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD;
1716 } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) {
1717 /* TODO: it also support ARP response type */
1719 wcn36xx_warn("unknown keep alive packet type %d\n", packet_type);
1724 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1726 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1728 wcn36xx_err("Sending hal_keep_alive failed\n");
1731 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1733 wcn36xx_err("hal_keep_alive response failed err=%d\n", ret);
1737 mutex_unlock(&wcn->hal_mutex);
1741 int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
1742 u32 arg3, u32 arg4, u32 arg5)
1744 struct wcn36xx_hal_dump_cmd_req_msg msg_body;
1747 mutex_lock(&wcn->hal_mutex);
1748 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
1750 msg_body.arg1 = arg1;
1751 msg_body.arg2 = arg2;
1752 msg_body.arg3 = arg3;
1753 msg_body.arg4 = arg4;
1754 msg_body.arg5 = arg5;
1756 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1758 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1760 wcn36xx_err("Sending hal_dump_cmd failed\n");
1763 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1765 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
1769 mutex_unlock(&wcn->hal_mutex);
1773 void set_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1775 int arr_idx, bit_idx;
1777 if (cap < 0 || cap > 127) {
1778 wcn36xx_warn("error cap idx %d\n", cap);
1784 bitmap[arr_idx] |= (1 << bit_idx);
1787 int get_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1789 int arr_idx, bit_idx;
1792 if (cap < 0 || cap > 127) {
1793 wcn36xx_warn("error cap idx %d\n", cap);
1799 ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
1803 void clear_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1805 int arr_idx, bit_idx;
1807 if (cap < 0 || cap > 127) {
1808 wcn36xx_warn("error cap idx %d\n", cap);
1814 bitmap[arr_idx] &= ~(1 << bit_idx);
1817 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
1819 struct wcn36xx_hal_feat_caps_msg msg_body, *rsp;
1822 mutex_lock(&wcn->hal_mutex);
1823 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
1825 set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
1827 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1829 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1831 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1834 if (wcn->hal_rsp_len != sizeof(*rsp)) {
1835 wcn36xx_err("Invalid hal_feature_caps_exchange response");
1839 rsp = (struct wcn36xx_hal_feat_caps_msg *) wcn->hal_buf;
1841 for (i = 0; i < WCN36XX_HAL_CAPS_SIZE; i++)
1842 wcn->fw_feat_caps[i] = rsp->feat_caps[i];
1844 mutex_unlock(&wcn->hal_mutex);
1848 int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
1849 struct ieee80211_sta *sta,
1855 struct wcn36xx_hal_add_ba_session_req_msg msg_body;
1858 mutex_lock(&wcn->hal_mutex);
1859 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
1861 msg_body.sta_index = sta_index;
1862 memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
1863 msg_body.dialog_token = 0x10;
1866 /* Immediate BA because Delayed BA is not supported */
1867 msg_body.policy = 1;
1868 msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE;
1869 msg_body.timeout = 0;
1871 msg_body.ssn = *ssn;
1872 msg_body.direction = direction;
1874 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1876 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1878 wcn36xx_err("Sending hal_add_ba_session failed\n");
1881 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1883 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
1887 mutex_unlock(&wcn->hal_mutex);
1891 int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
1893 struct wcn36xx_hal_add_ba_req_msg msg_body;
1896 mutex_lock(&wcn->hal_mutex);
1897 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
1899 msg_body.session_id = 0;
1900 msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
1902 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1904 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1906 wcn36xx_err("Sending hal_add_ba failed\n");
1909 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1911 wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
1915 mutex_unlock(&wcn->hal_mutex);
1919 int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
1921 struct wcn36xx_hal_del_ba_req_msg msg_body;
1924 mutex_lock(&wcn->hal_mutex);
1925 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
1927 msg_body.sta_index = sta_index;
1929 msg_body.direction = 0;
1930 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1932 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1934 wcn36xx_err("Sending hal_del_ba failed\n");
1937 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1939 wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
1943 mutex_unlock(&wcn->hal_mutex);
1947 int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
1949 struct wcn36xx_hal_trigger_ba_req_msg msg_body;
1950 struct wcn36xx_hal_trigger_ba_req_candidate *candidate;
1953 mutex_lock(&wcn->hal_mutex);
1954 INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
1956 msg_body.session_id = 0;
1957 msg_body.candidate_cnt = 1;
1958 msg_body.header.len += sizeof(*candidate);
1959 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1961 candidate = (struct wcn36xx_hal_trigger_ba_req_candidate *)
1962 (wcn->hal_buf + sizeof(msg_body));
1963 candidate->sta_index = sta_index;
1964 candidate->tid_bitmap = 1;
1966 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1968 wcn36xx_err("Sending hal_trigger_ba failed\n");
1971 ret = wcn36xx_smd_rsp_status_check_v2(wcn, wcn->hal_buf,
1974 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
1978 mutex_unlock(&wcn->hal_mutex);
1982 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
1984 struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
1986 if (len != sizeof(*rsp)) {
1987 wcn36xx_warn("Bad TX complete indication\n");
1991 wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
1996 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
2000 struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
2001 struct ieee80211_vif *vif = NULL;
2002 struct wcn36xx_vif *tmp;
2004 /* Old FW does not have bss index */
2005 if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
2006 list_for_each_entry(tmp, &wcn->vif_list, list) {
2007 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
2009 vif = container_of((void *)tmp,
2010 struct ieee80211_vif,
2012 ieee80211_connection_loss(vif);
2017 if (len != sizeof(*rsp)) {
2018 wcn36xx_warn("Corrupted missed beacon indication\n");
2022 list_for_each_entry(tmp, &wcn->vif_list, list) {
2023 if (tmp->bss_index == rsp->bss_index) {
2024 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
2026 vif = container_of((void *)tmp,
2027 struct ieee80211_vif,
2029 ieee80211_connection_loss(vif);
2034 wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
2038 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
2042 struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
2043 struct wcn36xx_vif *tmp;
2044 struct ieee80211_sta *sta = NULL;
2046 if (len != sizeof(*rsp)) {
2047 wcn36xx_warn("Corrupted delete sta indication\n");
2051 list_for_each_entry(tmp, &wcn->vif_list, list) {
2052 if (sta && (tmp->sta->sta_index == rsp->sta_id)) {
2053 sta = container_of((void *)tmp->sta,
2054 struct ieee80211_sta,
2056 wcn36xx_dbg(WCN36XX_DBG_HAL,
2057 "delete station indication %pM index %d\n",
2060 ieee80211_report_low_ack(sta, 0);
2065 wcn36xx_warn("STA with addr %pM and index %d not found\n",
2071 int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
2073 struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
2077 mutex_lock(&wcn->hal_mutex);
2078 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
2080 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
2082 body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
2083 len = msg_body.header.len;
2085 put_cfg_tlv_u32(wcn, &len, cfg_id, value);
2086 body->header.len = len;
2087 body->len = len - sizeof(*body);
2089 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
2091 wcn36xx_err("Sending hal_update_cfg failed\n");
2094 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
2096 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
2100 mutex_unlock(&wcn->hal_mutex);
2103 static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
2105 struct wcn36xx_hal_msg_header *msg_header = buf;
2106 struct wcn36xx_hal_ind_msg *msg_ind;
2107 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len);
2109 switch (msg_header->msg_type) {
2110 case WCN36XX_HAL_START_RSP:
2111 case WCN36XX_HAL_CONFIG_STA_RSP:
2112 case WCN36XX_HAL_CONFIG_BSS_RSP:
2113 case WCN36XX_HAL_ADD_STA_SELF_RSP:
2114 case WCN36XX_HAL_STOP_RSP:
2115 case WCN36XX_HAL_DEL_STA_SELF_RSP:
2116 case WCN36XX_HAL_DELETE_STA_RSP:
2117 case WCN36XX_HAL_INIT_SCAN_RSP:
2118 case WCN36XX_HAL_START_SCAN_RSP:
2119 case WCN36XX_HAL_END_SCAN_RSP:
2120 case WCN36XX_HAL_FINISH_SCAN_RSP:
2121 case WCN36XX_HAL_DOWNLOAD_NV_RSP:
2122 case WCN36XX_HAL_DELETE_BSS_RSP:
2123 case WCN36XX_HAL_SEND_BEACON_RSP:
2124 case WCN36XX_HAL_SET_LINK_ST_RSP:
2125 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP:
2126 case WCN36XX_HAL_SET_BSSKEY_RSP:
2127 case WCN36XX_HAL_SET_STAKEY_RSP:
2128 case WCN36XX_HAL_RMV_STAKEY_RSP:
2129 case WCN36XX_HAL_RMV_BSSKEY_RSP:
2130 case WCN36XX_HAL_ENTER_BMPS_RSP:
2131 case WCN36XX_HAL_SET_POWER_PARAMS_RSP:
2132 case WCN36XX_HAL_EXIT_BMPS_RSP:
2133 case WCN36XX_HAL_KEEP_ALIVE_RSP:
2134 case WCN36XX_HAL_DUMP_COMMAND_RSP:
2135 case WCN36XX_HAL_ADD_BA_SESSION_RSP:
2136 case WCN36XX_HAL_ADD_BA_RSP:
2137 case WCN36XX_HAL_DEL_BA_RSP:
2138 case WCN36XX_HAL_TRIGGER_BA_RSP:
2139 case WCN36XX_HAL_UPDATE_CFG_RSP:
2140 case WCN36XX_HAL_JOIN_RSP:
2141 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP:
2142 case WCN36XX_HAL_CH_SWITCH_RSP:
2143 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
2144 memcpy(wcn->hal_buf, buf, len);
2145 wcn->hal_rsp_len = len;
2146 complete(&wcn->hal_rsp_compl);
2149 case WCN36XX_HAL_COEX_IND:
2150 case WCN36XX_HAL_AVOID_FREQ_RANGE_IND:
2151 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2152 case WCN36XX_HAL_MISSED_BEACON_IND:
2153 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2154 msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL);
2157 msg_ind->msg_len = len;
2158 msg_ind->msg = kmemdup(buf, len, GFP_KERNEL);
2159 if (!msg_ind->msg) {
2163 * FIXME: Do something smarter then just
2164 * printing an error.
2166 wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
2167 msg_header->msg_type);
2170 mutex_lock(&wcn->hal_ind_mutex);
2171 list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
2172 queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
2173 mutex_unlock(&wcn->hal_ind_mutex);
2174 wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n");
2177 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2178 msg_header->msg_type);
2181 static void wcn36xx_ind_smd_work(struct work_struct *work)
2183 struct wcn36xx *wcn =
2184 container_of(work, struct wcn36xx, hal_ind_work);
2185 struct wcn36xx_hal_msg_header *msg_header;
2186 struct wcn36xx_hal_ind_msg *hal_ind_msg;
2188 mutex_lock(&wcn->hal_ind_mutex);
2190 hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
2191 struct wcn36xx_hal_ind_msg,
2194 msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
2196 switch (msg_header->msg_type) {
2197 case WCN36XX_HAL_COEX_IND:
2198 case WCN36XX_HAL_AVOID_FREQ_RANGE_IND:
2200 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2201 wcn36xx_smd_tx_compl_ind(wcn,
2203 hal_ind_msg->msg_len);
2205 case WCN36XX_HAL_MISSED_BEACON_IND:
2206 wcn36xx_smd_missed_beacon_ind(wcn,
2208 hal_ind_msg->msg_len);
2210 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2211 wcn36xx_smd_delete_sta_context_ind(wcn,
2213 hal_ind_msg->msg_len);
2216 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2217 msg_header->msg_type);
2219 list_del(wcn->hal_ind_queue.next);
2220 kfree(hal_ind_msg->msg);
2222 mutex_unlock(&wcn->hal_ind_mutex);
2224 int wcn36xx_smd_open(struct wcn36xx *wcn)
2227 wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind");
2228 if (!wcn->hal_ind_wq) {
2229 wcn36xx_err("failed to allocate wq\n");
2233 INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work);
2234 INIT_LIST_HEAD(&wcn->hal_ind_queue);
2235 mutex_init(&wcn->hal_ind_mutex);
2237 ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
2239 wcn36xx_err("failed to open control channel\n");
2246 destroy_workqueue(wcn->hal_ind_wq);
2251 void wcn36xx_smd_close(struct wcn36xx *wcn)
2253 wcn->ctrl_ops->close();
2254 destroy_workqueue(wcn->hal_ind_wq);
2255 mutex_destroy(&wcn->hal_ind_mutex);