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 int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
307 struct nv_data *nv_d;
308 struct wcn36xx_hal_nv_img_download_req_msg msg_body;
314 ret = request_firmware(&wcn->nv, WLAN_NV_FILE, wcn->dev);
316 wcn36xx_err("Failed to load nv file %s: %d\n",
322 nv_d = (struct nv_data *)wcn->nv->data;
323 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ);
325 msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE;
327 msg_body.frag_number = 0;
328 /* hal_buf must be protected with mutex */
329 mutex_lock(&wcn->hal_mutex);
332 fw_bytes_left = wcn->nv->size - fm_offset - 4;
333 if (fw_bytes_left > WCN36XX_NV_FRAGMENT_SIZE) {
334 msg_body.last_fragment = 0;
335 msg_body.nv_img_buffer_size = WCN36XX_NV_FRAGMENT_SIZE;
337 msg_body.last_fragment = 1;
338 msg_body.nv_img_buffer_size = fw_bytes_left;
340 /* Do not forget update general message len */
341 msg_body.header.len = sizeof(msg_body) + fw_bytes_left;
345 /* Add load NV request message header */
346 memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body));
348 /* Add NV body itself */
349 memcpy(wcn->hal_buf + sizeof(msg_body),
350 &nv_d->table + fm_offset,
351 msg_body.nv_img_buffer_size);
353 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
356 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf,
359 wcn36xx_err("hal_load_nv response failed err=%d\n",
363 msg_body.frag_number++;
364 fm_offset += WCN36XX_NV_FRAGMENT_SIZE;
366 } while (msg_body.last_fragment != 1);
369 mutex_unlock(&wcn->hal_mutex);
373 static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len)
375 struct wcn36xx_hal_mac_start_rsp_msg *rsp;
377 if (len < sizeof(*rsp))
380 rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf;
382 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status)
385 memcpy(wcn->crm_version, rsp->start_rsp_params.crm_version,
386 WCN36XX_HAL_VERSION_LENGTH);
387 memcpy(wcn->wlan_version, rsp->start_rsp_params.wlan_version,
388 WCN36XX_HAL_VERSION_LENGTH);
390 /* null terminate the strings, just in case */
391 wcn->crm_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
392 wcn->wlan_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
394 wcn->fw_revision = rsp->start_rsp_params.version.revision;
395 wcn->fw_version = rsp->start_rsp_params.version.version;
396 wcn->fw_minor = rsp->start_rsp_params.version.minor;
397 wcn->fw_major = rsp->start_rsp_params.version.major;
399 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
400 wcn->wlan_version, wcn->crm_version);
402 wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
403 wcn->fw_major, wcn->fw_minor,
404 wcn->fw_version, wcn->fw_revision,
405 rsp->start_rsp_params.stations,
406 rsp->start_rsp_params.bssids);
411 int wcn36xx_smd_start(struct wcn36xx *wcn)
413 struct wcn36xx_hal_mac_start_req_msg msg_body, *body;
418 mutex_lock(&wcn->hal_mutex);
419 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ);
421 msg_body.params.type = DRIVER_TYPE_PRODUCTION;
422 msg_body.params.len = 0;
424 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
426 body = (struct wcn36xx_hal_mac_start_req_msg *)wcn->hal_buf;
427 len = body->header.len;
429 for (i = 0; i < ARRAY_SIZE(wcn36xx_cfg_vals); i++) {
430 ret = put_cfg_tlv_u32(wcn, &len, wcn36xx_cfg_vals[i].cfg_id,
431 wcn36xx_cfg_vals[i].value);
435 body->header.len = len;
436 body->params.len = len - sizeof(*body);
438 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n",
439 msg_body.params.type);
441 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
443 wcn36xx_err("Sending hal_start failed\n");
447 ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len);
449 wcn36xx_err("hal_start response failed err=%d\n", ret);
454 mutex_unlock(&wcn->hal_mutex);
458 int wcn36xx_smd_stop(struct wcn36xx *wcn)
460 struct wcn36xx_hal_mac_stop_req_msg msg_body;
463 mutex_lock(&wcn->hal_mutex);
464 INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ);
466 msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL;
468 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
470 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
472 wcn36xx_err("Sending hal_stop failed\n");
475 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
477 wcn36xx_err("hal_stop response failed err=%d\n", ret);
481 mutex_unlock(&wcn->hal_mutex);
485 int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode)
487 struct wcn36xx_hal_init_scan_req_msg msg_body;
490 mutex_lock(&wcn->hal_mutex);
491 INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ);
493 msg_body.mode = mode;
495 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
497 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode);
499 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
501 wcn36xx_err("Sending hal_init_scan failed\n");
504 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
506 wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
510 mutex_unlock(&wcn->hal_mutex);
514 int wcn36xx_smd_start_scan(struct wcn36xx *wcn)
516 struct wcn36xx_hal_start_scan_req_msg msg_body;
519 mutex_lock(&wcn->hal_mutex);
520 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ);
522 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
524 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
526 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n",
527 msg_body.scan_channel);
529 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
531 wcn36xx_err("Sending hal_start_scan failed\n");
534 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
536 wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
540 mutex_unlock(&wcn->hal_mutex);
544 int wcn36xx_smd_end_scan(struct wcn36xx *wcn)
546 struct wcn36xx_hal_end_scan_req_msg msg_body;
549 mutex_lock(&wcn->hal_mutex);
550 INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ);
552 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
554 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
556 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n",
557 msg_body.scan_channel);
559 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
561 wcn36xx_err("Sending hal_end_scan failed\n");
564 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
566 wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
570 mutex_unlock(&wcn->hal_mutex);
574 int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
575 enum wcn36xx_hal_sys_mode mode)
577 struct wcn36xx_hal_finish_scan_req_msg msg_body;
580 mutex_lock(&wcn->hal_mutex);
581 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ);
583 msg_body.mode = mode;
585 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
587 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n",
590 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
592 wcn36xx_err("Sending hal_finish_scan failed\n");
595 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
597 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
601 mutex_unlock(&wcn->hal_mutex);
605 static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
607 struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
610 ret = wcn36xx_smd_rsp_status_check(buf, len);
613 rsp = (struct wcn36xx_hal_switch_channel_rsp_msg *)buf;
614 wcn36xx_dbg(WCN36XX_DBG_HAL, "channel switched to: %d, status: %d\n",
615 rsp->channel_number, rsp->status);
619 int wcn36xx_smd_switch_channel(struct wcn36xx *wcn,
620 struct ieee80211_vif *vif, int ch)
622 struct wcn36xx_hal_switch_channel_req_msg msg_body;
625 mutex_lock(&wcn->hal_mutex);
626 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ);
628 msg_body.channel_number = (u8)ch;
629 msg_body.tx_mgmt_power = 0xbf;
630 msg_body.max_tx_power = 0xbf;
631 memcpy(msg_body.self_sta_mac_addr, vif->addr, ETH_ALEN);
633 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
635 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
637 wcn36xx_err("Sending hal_switch_channel failed\n");
640 ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len);
642 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret);
646 mutex_unlock(&wcn->hal_mutex);
650 static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len)
652 struct wcn36xx_hal_update_scan_params_resp *rsp;
654 rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf;
656 /* Remove the PNO version bit */
657 rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK));
659 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) {
660 wcn36xx_warn("error response from update scan\n");
667 int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn)
669 struct wcn36xx_hal_update_scan_params_req msg_body;
672 mutex_lock(&wcn->hal_mutex);
673 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ);
675 msg_body.dot11d_enabled = 0;
676 msg_body.dot11d_resolved = 0;
677 msg_body.channel_count = 26;
678 msg_body.active_min_ch_time = 60;
679 msg_body.active_max_ch_time = 120;
680 msg_body.passive_min_ch_time = 60;
681 msg_body.passive_max_ch_time = 110;
684 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
686 wcn36xx_dbg(WCN36XX_DBG_HAL,
687 "hal update scan params channel_count %d\n",
688 msg_body.channel_count);
690 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
692 wcn36xx_err("Sending hal_update_scan_params failed\n");
695 ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf,
698 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
703 mutex_unlock(&wcn->hal_mutex);
707 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn,
708 struct ieee80211_vif *vif,
712 struct wcn36xx_hal_add_sta_self_rsp_msg *rsp;
713 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
715 if (len < sizeof(*rsp))
718 rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf;
720 if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
721 wcn36xx_warn("hal add sta self failure: %d\n",
726 wcn36xx_dbg(WCN36XX_DBG_HAL,
727 "hal add sta self status %d self_sta_index %d dpu_index %d\n",
728 rsp->status, rsp->self_sta_index, rsp->dpu_index);
730 priv_vif->self_sta_index = rsp->self_sta_index;
731 priv_vif->self_dpu_desc_index = rsp->dpu_index;
736 int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif)
738 struct wcn36xx_hal_add_sta_self_req msg_body;
741 mutex_lock(&wcn->hal_mutex);
742 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ);
744 memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN);
746 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
748 wcn36xx_dbg(WCN36XX_DBG_HAL,
749 "hal add sta self self_addr %pM status %d\n",
750 msg_body.self_addr, msg_body.status);
752 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
754 wcn36xx_err("Sending hal_add_sta_self failed\n");
757 ret = wcn36xx_smd_add_sta_self_rsp(wcn,
762 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret);
766 mutex_unlock(&wcn->hal_mutex);
770 int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr)
772 struct wcn36xx_hal_del_sta_self_req_msg msg_body;
775 mutex_lock(&wcn->hal_mutex);
776 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ);
778 memcpy(&msg_body.self_addr, addr, ETH_ALEN);
780 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
782 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
784 wcn36xx_err("Sending hal_delete_sta_self failed\n");
787 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
789 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
794 mutex_unlock(&wcn->hal_mutex);
798 int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index)
800 struct wcn36xx_hal_delete_sta_req_msg msg_body;
803 mutex_lock(&wcn->hal_mutex);
804 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ);
806 msg_body.sta_index = sta_index;
808 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
810 wcn36xx_dbg(WCN36XX_DBG_HAL,
811 "hal delete sta sta_index %d\n",
814 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
816 wcn36xx_err("Sending hal_delete_sta failed\n");
819 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
821 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret);
825 mutex_unlock(&wcn->hal_mutex);
829 static int wcn36xx_smd_join_rsp(void *buf, size_t len)
831 struct wcn36xx_hal_join_rsp_msg *rsp;
833 if (wcn36xx_smd_rsp_status_check(buf, len))
836 rsp = (struct wcn36xx_hal_join_rsp_msg *)buf;
838 wcn36xx_dbg(WCN36XX_DBG_HAL,
839 "hal rsp join status %d tx_mgmt_power %d\n",
840 rsp->status, rsp->tx_mgmt_power);
845 int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch)
847 struct wcn36xx_hal_join_req_msg msg_body;
850 mutex_lock(&wcn->hal_mutex);
851 INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ);
853 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
854 memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN);
855 msg_body.channel = ch;
857 if (conf_is_ht40_minus(&wcn->hw->conf))
858 msg_body.secondary_channel_offset =
859 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY;
860 else if (conf_is_ht40_plus(&wcn->hw->conf))
861 msg_body.secondary_channel_offset =
862 PHY_DOUBLE_CHANNEL_LOW_PRIMARY;
864 msg_body.secondary_channel_offset =
865 PHY_SINGLE_CHANNEL_CENTERED;
867 msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE;
869 msg_body.max_tx_power = 0xbf;
870 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
872 wcn36xx_dbg(WCN36XX_DBG_HAL,
873 "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
874 msg_body.bssid, msg_body.self_sta_mac_addr,
875 msg_body.channel, msg_body.link_state);
877 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
879 wcn36xx_err("Sending hal_join failed\n");
882 ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len);
884 wcn36xx_err("hal_join response failed err=%d\n", ret);
888 mutex_unlock(&wcn->hal_mutex);
892 int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid,
894 enum wcn36xx_hal_link_state state)
896 struct wcn36xx_hal_set_link_state_req_msg msg_body;
899 mutex_lock(&wcn->hal_mutex);
900 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ);
902 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
903 memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN);
904 msg_body.state = state;
906 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
908 wcn36xx_dbg(WCN36XX_DBG_HAL,
909 "hal set link state bssid %pM self_mac_addr %pM state %d\n",
910 msg_body.bssid, msg_body.self_mac_addr, msg_body.state);
912 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
914 wcn36xx_err("Sending hal_set_link_st failed\n");
917 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
919 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret);
923 mutex_unlock(&wcn->hal_mutex);
927 static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx *wcn,
928 const struct wcn36xx_hal_config_sta_params *orig,
929 struct wcn36xx_hal_config_sta_params_v1 *v1)
931 /* convert orig to v1 format */
932 memcpy(&v1->bssid, orig->bssid, ETH_ALEN);
933 memcpy(&v1->mac, orig->mac, ETH_ALEN);
935 v1->type = orig->type;
936 v1->listen_interval = orig->listen_interval;
937 v1->ht_capable = orig->ht_capable;
939 v1->max_ampdu_size = orig->max_ampdu_size;
940 v1->max_ampdu_density = orig->max_ampdu_density;
941 v1->sgi_40mhz = orig->sgi_40mhz;
942 v1->sgi_20Mhz = orig->sgi_20Mhz;
944 memcpy(&v1->supported_rates, &orig->supported_rates,
945 sizeof(orig->supported_rates));
946 v1->sta_index = orig->sta_index;
949 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn,
950 struct ieee80211_sta *sta,
954 struct wcn36xx_hal_config_sta_rsp_msg *rsp;
955 struct config_sta_rsp_params *params;
956 struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
958 if (len < sizeof(*rsp))
961 rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf;
962 params = &rsp->params;
964 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
965 wcn36xx_warn("hal config sta response failure: %d\n",
970 sta_priv->sta_index = params->sta_index;
971 sta_priv->dpu_desc_index = params->dpu_index;
972 sta_priv->ucast_dpu_sign = params->uc_ucast_sig;
974 wcn36xx_dbg(WCN36XX_DBG_HAL,
975 "hal config sta rsp status %d sta_index %d bssid_index %d uc_ucast_sig %d p2p %d\n",
976 params->status, params->sta_index, params->bssid_index,
977 params->uc_ucast_sig, params->p2p);
982 static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn,
983 const struct wcn36xx_hal_config_sta_req_msg *orig)
985 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body;
986 struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params;
988 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ);
990 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params,
991 &msg_body.sta_params);
993 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
995 wcn36xx_dbg(WCN36XX_DBG_HAL,
996 "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
997 sta->action, sta->sta_index, sta->bssid_index,
998 sta->bssid, sta->type, sta->mac, sta->aid);
1000 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1003 int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1004 struct ieee80211_sta *sta)
1006 struct wcn36xx_hal_config_sta_req_msg msg;
1007 struct wcn36xx_hal_config_sta_params *sta_params;
1010 mutex_lock(&wcn->hal_mutex);
1011 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ);
1013 sta_params = &msg.sta_params;
1015 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
1017 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1018 ret = wcn36xx_smd_config_sta_v1(wcn, &msg);
1020 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1022 wcn36xx_dbg(WCN36XX_DBG_HAL,
1023 "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
1024 sta_params->action, sta_params->sta_index,
1025 sta_params->bssid_index, sta_params->bssid,
1026 sta_params->type, sta_params->mac, sta_params->aid);
1028 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1031 wcn36xx_err("Sending hal_config_sta failed\n");
1034 ret = wcn36xx_smd_config_sta_rsp(wcn,
1039 wcn36xx_err("hal_config_sta response failed err=%d\n", ret);
1043 mutex_unlock(&wcn->hal_mutex);
1047 static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn,
1048 const struct wcn36xx_hal_config_bss_req_msg *orig)
1050 struct wcn36xx_hal_config_bss_req_msg_v1 msg_body;
1051 struct wcn36xx_hal_config_bss_params_v1 *bss = &msg_body.bss_params;
1052 struct wcn36xx_hal_config_sta_params_v1 *sta = &bss->sta;
1054 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ);
1056 /* convert orig to v1 */
1057 memcpy(&msg_body.bss_params.bssid,
1058 &orig->bss_params.bssid, ETH_ALEN);
1059 memcpy(&msg_body.bss_params.self_mac_addr,
1060 &orig->bss_params.self_mac_addr, ETH_ALEN);
1062 msg_body.bss_params.bss_type = orig->bss_params.bss_type;
1063 msg_body.bss_params.oper_mode = orig->bss_params.oper_mode;
1064 msg_body.bss_params.nw_type = orig->bss_params.nw_type;
1066 msg_body.bss_params.short_slot_time_supported =
1067 orig->bss_params.short_slot_time_supported;
1068 msg_body.bss_params.lla_coexist = orig->bss_params.lla_coexist;
1069 msg_body.bss_params.llb_coexist = orig->bss_params.llb_coexist;
1070 msg_body.bss_params.llg_coexist = orig->bss_params.llg_coexist;
1071 msg_body.bss_params.ht20_coexist = orig->bss_params.ht20_coexist;
1072 msg_body.bss_params.lln_non_gf_coexist =
1073 orig->bss_params.lln_non_gf_coexist;
1075 msg_body.bss_params.lsig_tx_op_protection_full_support =
1076 orig->bss_params.lsig_tx_op_protection_full_support;
1077 msg_body.bss_params.rifs_mode = orig->bss_params.rifs_mode;
1078 msg_body.bss_params.beacon_interval = orig->bss_params.beacon_interval;
1079 msg_body.bss_params.dtim_period = orig->bss_params.dtim_period;
1080 msg_body.bss_params.tx_channel_width_set =
1081 orig->bss_params.tx_channel_width_set;
1082 msg_body.bss_params.oper_channel = orig->bss_params.oper_channel;
1083 msg_body.bss_params.ext_channel = orig->bss_params.ext_channel;
1085 msg_body.bss_params.reserved = orig->bss_params.reserved;
1087 memcpy(&msg_body.bss_params.ssid,
1088 &orig->bss_params.ssid,
1089 sizeof(orig->bss_params.ssid));
1091 msg_body.bss_params.action = orig->bss_params.action;
1092 msg_body.bss_params.rateset = orig->bss_params.rateset;
1093 msg_body.bss_params.ht = orig->bss_params.ht;
1094 msg_body.bss_params.obss_prot_enabled =
1095 orig->bss_params.obss_prot_enabled;
1096 msg_body.bss_params.rmf = orig->bss_params.rmf;
1097 msg_body.bss_params.ht_oper_mode = orig->bss_params.ht_oper_mode;
1098 msg_body.bss_params.dual_cts_protection =
1099 orig->bss_params.dual_cts_protection;
1101 msg_body.bss_params.max_probe_resp_retry_limit =
1102 orig->bss_params.max_probe_resp_retry_limit;
1103 msg_body.bss_params.hidden_ssid = orig->bss_params.hidden_ssid;
1104 msg_body.bss_params.proxy_probe_resp =
1105 orig->bss_params.proxy_probe_resp;
1106 msg_body.bss_params.edca_params_valid =
1107 orig->bss_params.edca_params_valid;
1109 memcpy(&msg_body.bss_params.acbe,
1110 &orig->bss_params.acbe,
1111 sizeof(orig->bss_params.acbe));
1112 memcpy(&msg_body.bss_params.acbk,
1113 &orig->bss_params.acbk,
1114 sizeof(orig->bss_params.acbk));
1115 memcpy(&msg_body.bss_params.acvi,
1116 &orig->bss_params.acvi,
1117 sizeof(orig->bss_params.acvi));
1118 memcpy(&msg_body.bss_params.acvo,
1119 &orig->bss_params.acvo,
1120 sizeof(orig->bss_params.acvo));
1122 msg_body.bss_params.ext_set_sta_key_param_valid =
1123 orig->bss_params.ext_set_sta_key_param_valid;
1125 memcpy(&msg_body.bss_params.ext_set_sta_key_param,
1126 &orig->bss_params.ext_set_sta_key_param,
1127 sizeof(orig->bss_params.acvo));
1129 msg_body.bss_params.wcn36xx_hal_persona =
1130 orig->bss_params.wcn36xx_hal_persona;
1131 msg_body.bss_params.spectrum_mgt_enable =
1132 orig->bss_params.spectrum_mgt_enable;
1133 msg_body.bss_params.tx_mgmt_power = orig->bss_params.tx_mgmt_power;
1134 msg_body.bss_params.max_tx_power = orig->bss_params.max_tx_power;
1136 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta,
1137 &msg_body.bss_params.sta);
1139 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1141 wcn36xx_dbg(WCN36XX_DBG_HAL,
1142 "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1143 bss->bssid, bss->self_mac_addr, bss->bss_type,
1144 bss->oper_mode, bss->nw_type);
1146 wcn36xx_dbg(WCN36XX_DBG_HAL,
1147 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1148 sta->bssid, sta->action, sta->sta_index,
1149 sta->bssid_index, sta->aid, sta->type, sta->mac);
1151 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1155 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn,
1156 struct ieee80211_vif *vif,
1160 struct wcn36xx_hal_config_bss_rsp_msg *rsp;
1161 struct wcn36xx_hal_config_bss_rsp_params *params;
1162 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
1164 if (len < sizeof(*rsp))
1167 rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf;
1168 params = &rsp->bss_rsp_params;
1170 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
1171 wcn36xx_warn("hal config bss response failure: %d\n",
1176 wcn36xx_dbg(WCN36XX_DBG_HAL,
1177 "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
1178 " sta_idx %d self_idx %d bcast_idx %d mac %pM"
1179 " power %d ucast_dpu_signature %d\n",
1180 params->status, params->bss_index, params->dpu_desc_index,
1181 params->bss_sta_index, params->bss_self_sta_index,
1182 params->bss_bcast_sta_idx, params->mac,
1183 params->tx_mgmt_power, params->ucast_dpu_signature);
1185 priv_vif->bss_index = params->bss_index;
1187 if (priv_vif->sta) {
1188 priv_vif->sta->bss_sta_index = params->bss_sta_index;
1189 priv_vif->sta->bss_dpu_desc_index = params->dpu_desc_index;
1192 priv_vif->self_ucast_dpu_sign = params->ucast_dpu_signature;
1197 int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1198 struct ieee80211_sta *sta, const u8 *bssid,
1201 struct wcn36xx_hal_config_bss_req_msg msg;
1202 struct wcn36xx_hal_config_bss_params *bss;
1203 struct wcn36xx_hal_config_sta_params *sta_params;
1204 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1207 mutex_lock(&wcn->hal_mutex);
1208 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ);
1210 bss = &msg.bss_params;
1211 sta_params = &bss->sta;
1213 WARN_ON(is_zero_ether_addr(bssid));
1215 memcpy(&bss->bssid, bssid, ETH_ALEN);
1217 memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN);
1219 if (vif->type == NL80211_IFTYPE_STATION) {
1220 bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE;
1224 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_MODE;
1225 } else if (vif->type == NL80211_IFTYPE_AP ||
1226 vif->type == NL80211_IFTYPE_MESH_POINT) {
1227 bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE;
1231 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE;
1232 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
1233 bss->bss_type = WCN36XX_HAL_IBSS_MODE;
1238 wcn36xx_warn("Unknown type for bss config: %d\n", vif->type);
1241 if (vif->type == NL80211_IFTYPE_STATION)
1242 wcn36xx_smd_set_bss_nw_type(wcn, sta, bss);
1244 bss->nw_type = WCN36XX_HAL_11N_NW_TYPE;
1246 bss->short_slot_time_supported = vif->bss_conf.use_short_slot;
1247 bss->lla_coexist = 0;
1248 bss->llb_coexist = 0;
1249 bss->llg_coexist = 0;
1251 bss->beacon_interval = vif->bss_conf.beacon_int;
1252 bss->dtim_period = vif_priv->dtim_period;
1254 wcn36xx_smd_set_bss_ht_params(vif, sta, bss);
1256 bss->oper_channel = WCN36XX_HW_CHANNEL(wcn);
1258 if (conf_is_ht40_minus(&wcn->hw->conf))
1259 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1260 else if (conf_is_ht40_plus(&wcn->hw->conf))
1261 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1263 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1266 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
1268 /* wcn->ssid is only valid in AP and IBSS mode */
1269 bss->ssid.length = vif_priv->ssid.length;
1270 memcpy(bss->ssid.ssid, vif_priv->ssid.ssid, vif_priv->ssid.length);
1272 bss->obss_prot_enabled = 0;
1274 bss->max_probe_resp_retry_limit = 0;
1275 bss->hidden_ssid = vif->bss_conf.hidden_ssid;
1276 bss->proxy_probe_resp = 0;
1277 bss->edca_params_valid = 0;
1279 /* FIXME: set acbe, acbk, acvi and acvo */
1281 bss->ext_set_sta_key_param_valid = 0;
1283 /* FIXME: set ext_set_sta_key_param */
1285 bss->spectrum_mgt_enable = 0;
1286 bss->tx_mgmt_power = 0;
1287 bss->max_tx_power = WCN36XX_MAX_POWER(wcn);
1289 bss->action = update;
1291 wcn36xx_dbg(WCN36XX_DBG_HAL,
1292 "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1293 bss->bssid, bss->self_mac_addr, bss->bss_type,
1294 bss->oper_mode, bss->nw_type);
1296 wcn36xx_dbg(WCN36XX_DBG_HAL,
1297 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1298 sta_params->bssid, sta_params->action,
1299 sta_params->sta_index, sta_params->bssid_index,
1300 sta_params->aid, sta_params->type,
1303 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1304 ret = wcn36xx_smd_config_bss_v1(wcn, &msg);
1306 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1308 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1311 wcn36xx_err("Sending hal_config_bss failed\n");
1314 ret = wcn36xx_smd_config_bss_rsp(wcn,
1319 wcn36xx_err("hal_config_bss response failed err=%d\n", ret);
1323 mutex_unlock(&wcn->hal_mutex);
1327 int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1329 struct wcn36xx_hal_delete_bss_req_msg msg_body;
1330 struct wcn36xx_vif *priv_vif = (struct wcn36xx_vif *)vif->drv_priv;
1333 mutex_lock(&wcn->hal_mutex);
1334 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ);
1336 msg_body.bss_index = priv_vif->bss_index;
1338 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1340 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index);
1342 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1344 wcn36xx_err("Sending hal_delete_bss failed\n");
1347 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1349 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret);
1353 mutex_unlock(&wcn->hal_mutex);
1357 int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1358 struct sk_buff *skb_beacon, u16 tim_off,
1361 struct wcn36xx_hal_send_beacon_req_msg msg_body;
1364 mutex_lock(&wcn->hal_mutex);
1365 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ);
1367 msg_body.beacon_length = skb_beacon->len;
1368 /* TODO need to find out why + 6 is needed */
1369 msg_body.beacon_length6 = msg_body.beacon_length + 6;
1371 if (msg_body.beacon_length > BEACON_TEMPLATE_SIZE) {
1372 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1373 msg_body.beacon_length);
1377 memcpy(msg_body.beacon, skb_beacon->data, skb_beacon->len);
1378 memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
1380 /* TODO need to find out why this is needed? */
1381 if (vif->type == NL80211_IFTYPE_MESH_POINT)
1382 /* mesh beacon don't need this, so push further down */
1383 msg_body.tim_ie_offset = 256;
1385 msg_body.tim_ie_offset = tim_off+4;
1386 msg_body.p2p_ie_offset = p2p_off;
1387 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1389 wcn36xx_dbg(WCN36XX_DBG_HAL,
1390 "hal send beacon beacon_length %d\n",
1391 msg_body.beacon_length);
1393 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1395 wcn36xx_err("Sending hal_send_beacon failed\n");
1398 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1400 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
1404 mutex_unlock(&wcn->hal_mutex);
1408 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
1409 struct ieee80211_vif *vif,
1410 struct sk_buff *skb)
1412 struct wcn36xx_hal_send_probe_resp_req_msg msg;
1415 mutex_lock(&wcn->hal_mutex);
1416 INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
1418 if (skb->len > BEACON_TEMPLATE_SIZE) {
1419 wcn36xx_warn("probe response template is too big: %d\n",
1425 msg.probe_resp_template_len = skb->len;
1426 memcpy(&msg.probe_resp_template, skb->data, skb->len);
1428 memcpy(msg.bssid, vif->addr, ETH_ALEN);
1430 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1432 wcn36xx_dbg(WCN36XX_DBG_HAL,
1433 "hal update probe rsp len %d bssid %pM\n",
1434 msg.probe_resp_template_len, msg.bssid);
1436 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1438 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1441 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1443 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1448 mutex_unlock(&wcn->hal_mutex);
1452 int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
1453 enum ani_ed_type enc_type,
1459 struct wcn36xx_hal_set_sta_key_req_msg msg_body;
1462 mutex_lock(&wcn->hal_mutex);
1463 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
1465 msg_body.set_sta_key_params.sta_index = sta_index;
1466 msg_body.set_sta_key_params.enc_type = enc_type;
1468 msg_body.set_sta_key_params.key[0].id = keyidx;
1469 msg_body.set_sta_key_params.key[0].unicast = 1;
1470 msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX;
1471 msg_body.set_sta_key_params.key[0].pae_role = 0;
1472 msg_body.set_sta_key_params.key[0].length = keylen;
1473 memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen);
1474 msg_body.set_sta_key_params.single_tid_rc = 1;
1476 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1478 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1480 wcn36xx_err("Sending hal_set_stakey failed\n");
1483 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1485 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
1489 mutex_unlock(&wcn->hal_mutex);
1493 int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
1494 enum ani_ed_type enc_type,
1499 struct wcn36xx_hal_set_bss_key_req_msg msg_body;
1502 mutex_lock(&wcn->hal_mutex);
1503 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ);
1504 msg_body.bss_idx = 0;
1505 msg_body.enc_type = enc_type;
1506 msg_body.num_keys = 1;
1507 msg_body.keys[0].id = keyidx;
1508 msg_body.keys[0].unicast = 0;
1509 msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY;
1510 msg_body.keys[0].pae_role = 0;
1511 msg_body.keys[0].length = keylen;
1512 memcpy(msg_body.keys[0].key, key, keylen);
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_set_bsskey failed\n");
1521 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1523 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
1527 mutex_unlock(&wcn->hal_mutex);
1531 int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
1532 enum ani_ed_type enc_type,
1536 struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
1539 mutex_lock(&wcn->hal_mutex);
1540 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
1542 msg_body.sta_idx = sta_index;
1543 msg_body.enc_type = enc_type;
1544 msg_body.key_id = keyidx;
1546 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1548 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1550 wcn36xx_err("Sending hal_remove_stakey failed\n");
1553 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1555 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
1559 mutex_unlock(&wcn->hal_mutex);
1563 int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
1564 enum ani_ed_type enc_type,
1567 struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
1570 mutex_lock(&wcn->hal_mutex);
1571 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ);
1572 msg_body.bss_idx = 0;
1573 msg_body.enc_type = enc_type;
1574 msg_body.key_id = keyidx;
1576 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1578 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1580 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1583 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1585 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
1589 mutex_unlock(&wcn->hal_mutex);
1593 int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1595 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1596 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1599 mutex_lock(&wcn->hal_mutex);
1600 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
1602 msg_body.bss_index = vif_priv->bss_index;
1603 msg_body.tbtt = vif->bss_conf.sync_tsf;
1604 msg_body.dtim_period = vif_priv->dtim_period;
1606 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1608 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1610 wcn36xx_err("Sending hal_enter_bmps failed\n");
1613 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1615 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
1619 mutex_unlock(&wcn->hal_mutex);
1623 int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1625 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1626 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1629 mutex_lock(&wcn->hal_mutex);
1630 INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
1632 msg_body.bss_index = vif_priv->bss_index;
1634 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1636 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1638 wcn36xx_err("Sending hal_exit_bmps failed\n");
1641 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1643 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1647 mutex_unlock(&wcn->hal_mutex);
1650 int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
1652 struct wcn36xx_hal_set_power_params_req_msg msg_body;
1655 mutex_lock(&wcn->hal_mutex);
1656 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
1659 * When host is down ignore every second dtim
1662 msg_body.ignore_dtim = 1;
1663 msg_body.dtim_period = 2;
1665 msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
1667 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1669 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1671 wcn36xx_err("Sending hal_set_power_params failed\n");
1676 mutex_unlock(&wcn->hal_mutex);
1679 /* Notice: This function should be called after associated, or else it
1682 int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
1683 struct ieee80211_vif *vif,
1686 struct wcn36xx_hal_keep_alive_req_msg msg_body;
1687 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
1690 mutex_lock(&wcn->hal_mutex);
1691 INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
1693 if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) {
1694 msg_body.bss_index = vif_priv->bss_index;
1695 msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT;
1696 msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD;
1697 } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) {
1698 /* TODO: it also support ARP response type */
1700 wcn36xx_warn("unknown keep alive packet type %d\n", packet_type);
1705 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1707 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1709 wcn36xx_err("Sending hal_keep_alive failed\n");
1712 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1714 wcn36xx_err("hal_keep_alive response failed err=%d\n", ret);
1718 mutex_unlock(&wcn->hal_mutex);
1722 int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
1723 u32 arg3, u32 arg4, u32 arg5)
1725 struct wcn36xx_hal_dump_cmd_req_msg msg_body;
1728 mutex_lock(&wcn->hal_mutex);
1729 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
1731 msg_body.arg1 = arg1;
1732 msg_body.arg2 = arg2;
1733 msg_body.arg3 = arg3;
1734 msg_body.arg4 = arg4;
1735 msg_body.arg5 = arg5;
1737 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1739 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1741 wcn36xx_err("Sending hal_dump_cmd failed\n");
1744 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1746 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
1750 mutex_unlock(&wcn->hal_mutex);
1754 void set_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1756 int arr_idx, bit_idx;
1758 if (cap < 0 || cap > 127) {
1759 wcn36xx_warn("error cap idx %d\n", cap);
1765 bitmap[arr_idx] |= (1 << bit_idx);
1768 int get_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1770 int arr_idx, bit_idx;
1773 if (cap < 0 || cap > 127) {
1774 wcn36xx_warn("error cap idx %d\n", cap);
1780 ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
1784 void clear_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1786 int arr_idx, bit_idx;
1788 if (cap < 0 || cap > 127) {
1789 wcn36xx_warn("error cap idx %d\n", cap);
1795 bitmap[arr_idx] &= ~(1 << bit_idx);
1798 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
1800 struct wcn36xx_hal_feat_caps_msg msg_body, *rsp;
1803 mutex_lock(&wcn->hal_mutex);
1804 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
1806 set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
1808 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1810 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1812 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1815 if (wcn->hal_rsp_len != sizeof(*rsp)) {
1816 wcn36xx_err("Invalid hal_feature_caps_exchange response");
1820 rsp = (struct wcn36xx_hal_feat_caps_msg *) wcn->hal_buf;
1822 for (i = 0; i < WCN36XX_HAL_CAPS_SIZE; i++)
1823 wcn->fw_feat_caps[i] = rsp->feat_caps[i];
1825 mutex_unlock(&wcn->hal_mutex);
1829 int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
1830 struct ieee80211_sta *sta,
1836 struct wcn36xx_hal_add_ba_session_req_msg msg_body;
1839 mutex_lock(&wcn->hal_mutex);
1840 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
1842 msg_body.sta_index = sta_index;
1843 memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
1844 msg_body.dialog_token = 0x10;
1847 /* Immediate BA because Delayed BA is not supported */
1848 msg_body.policy = 1;
1849 msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE;
1850 msg_body.timeout = 0;
1852 msg_body.ssn = *ssn;
1853 msg_body.direction = direction;
1855 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1857 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1859 wcn36xx_err("Sending hal_add_ba_session failed\n");
1862 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1864 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
1868 mutex_unlock(&wcn->hal_mutex);
1872 int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
1874 struct wcn36xx_hal_add_ba_req_msg msg_body;
1877 mutex_lock(&wcn->hal_mutex);
1878 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
1880 msg_body.session_id = 0;
1881 msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
1883 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1885 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1887 wcn36xx_err("Sending hal_add_ba failed\n");
1890 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1892 wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
1896 mutex_unlock(&wcn->hal_mutex);
1900 int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
1902 struct wcn36xx_hal_del_ba_req_msg msg_body;
1905 mutex_lock(&wcn->hal_mutex);
1906 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
1908 msg_body.sta_index = sta_index;
1910 msg_body.direction = 0;
1911 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1913 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1915 wcn36xx_err("Sending hal_del_ba failed\n");
1918 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1920 wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
1924 mutex_unlock(&wcn->hal_mutex);
1928 int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
1930 struct wcn36xx_hal_trigger_ba_req_msg msg_body;
1931 struct wcn36xx_hal_trigger_ba_req_candidate *candidate;
1934 mutex_lock(&wcn->hal_mutex);
1935 INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
1937 msg_body.session_id = 0;
1938 msg_body.candidate_cnt = 1;
1939 msg_body.header.len += sizeof(*candidate);
1940 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1942 candidate = (struct wcn36xx_hal_trigger_ba_req_candidate *)
1943 (wcn->hal_buf + sizeof(msg_body));
1944 candidate->sta_index = sta_index;
1945 candidate->tid_bitmap = 1;
1947 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1949 wcn36xx_err("Sending hal_trigger_ba failed\n");
1952 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1954 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
1958 mutex_unlock(&wcn->hal_mutex);
1962 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
1964 struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
1966 if (len != sizeof(*rsp)) {
1967 wcn36xx_warn("Bad TX complete indication\n");
1971 wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
1976 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
1980 struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
1981 struct ieee80211_vif *vif = NULL;
1982 struct wcn36xx_vif *tmp;
1984 /* Old FW does not have bss index */
1985 if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1986 list_for_each_entry(tmp, &wcn->vif_list, list) {
1987 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
1989 vif = container_of((void *)tmp,
1990 struct ieee80211_vif,
1992 ieee80211_connection_loss(vif);
1997 if (len != sizeof(*rsp)) {
1998 wcn36xx_warn("Corrupted missed beacon indication\n");
2002 list_for_each_entry(tmp, &wcn->vif_list, list) {
2003 if (tmp->bss_index == rsp->bss_index) {
2004 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
2006 vif = container_of((void *)tmp,
2007 struct ieee80211_vif,
2009 ieee80211_connection_loss(vif);
2014 wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
2018 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
2022 struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
2023 struct wcn36xx_vif *tmp;
2024 struct ieee80211_sta *sta = NULL;
2026 if (len != sizeof(*rsp)) {
2027 wcn36xx_warn("Corrupted delete sta indication\n");
2031 list_for_each_entry(tmp, &wcn->vif_list, list) {
2032 if (sta && (tmp->sta->sta_index == rsp->sta_id)) {
2033 sta = container_of((void *)tmp->sta,
2034 struct ieee80211_sta,
2036 wcn36xx_dbg(WCN36XX_DBG_HAL,
2037 "delete station indication %pM index %d\n",
2040 ieee80211_report_low_ack(sta, 0);
2045 wcn36xx_warn("STA with addr %pM and index %d not found\n",
2051 int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
2053 struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
2057 mutex_lock(&wcn->hal_mutex);
2058 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
2060 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
2062 body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
2063 len = msg_body.header.len;
2065 put_cfg_tlv_u32(wcn, &len, cfg_id, value);
2066 body->header.len = len;
2067 body->len = len - sizeof(*body);
2069 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
2071 wcn36xx_err("Sending hal_update_cfg failed\n");
2074 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
2076 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
2080 mutex_unlock(&wcn->hal_mutex);
2083 static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
2085 struct wcn36xx_hal_msg_header *msg_header = buf;
2086 struct wcn36xx_hal_ind_msg *msg_ind;
2087 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len);
2089 switch (msg_header->msg_type) {
2090 case WCN36XX_HAL_START_RSP:
2091 case WCN36XX_HAL_CONFIG_STA_RSP:
2092 case WCN36XX_HAL_CONFIG_BSS_RSP:
2093 case WCN36XX_HAL_ADD_STA_SELF_RSP:
2094 case WCN36XX_HAL_STOP_RSP:
2095 case WCN36XX_HAL_DEL_STA_SELF_RSP:
2096 case WCN36XX_HAL_DELETE_STA_RSP:
2097 case WCN36XX_HAL_INIT_SCAN_RSP:
2098 case WCN36XX_HAL_START_SCAN_RSP:
2099 case WCN36XX_HAL_END_SCAN_RSP:
2100 case WCN36XX_HAL_FINISH_SCAN_RSP:
2101 case WCN36XX_HAL_DOWNLOAD_NV_RSP:
2102 case WCN36XX_HAL_DELETE_BSS_RSP:
2103 case WCN36XX_HAL_SEND_BEACON_RSP:
2104 case WCN36XX_HAL_SET_LINK_ST_RSP:
2105 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP:
2106 case WCN36XX_HAL_SET_BSSKEY_RSP:
2107 case WCN36XX_HAL_SET_STAKEY_RSP:
2108 case WCN36XX_HAL_RMV_STAKEY_RSP:
2109 case WCN36XX_HAL_RMV_BSSKEY_RSP:
2110 case WCN36XX_HAL_ENTER_BMPS_RSP:
2111 case WCN36XX_HAL_SET_POWER_PARAMS_RSP:
2112 case WCN36XX_HAL_EXIT_BMPS_RSP:
2113 case WCN36XX_HAL_KEEP_ALIVE_RSP:
2114 case WCN36XX_HAL_DUMP_COMMAND_RSP:
2115 case WCN36XX_HAL_ADD_BA_SESSION_RSP:
2116 case WCN36XX_HAL_ADD_BA_RSP:
2117 case WCN36XX_HAL_DEL_BA_RSP:
2118 case WCN36XX_HAL_TRIGGER_BA_RSP:
2119 case WCN36XX_HAL_UPDATE_CFG_RSP:
2120 case WCN36XX_HAL_JOIN_RSP:
2121 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP:
2122 case WCN36XX_HAL_CH_SWITCH_RSP:
2123 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
2124 memcpy(wcn->hal_buf, buf, len);
2125 wcn->hal_rsp_len = len;
2126 complete(&wcn->hal_rsp_compl);
2129 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2130 case WCN36XX_HAL_MISSED_BEACON_IND:
2131 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2132 msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL);
2135 msg_ind->msg_len = len;
2136 msg_ind->msg = kmemdup(buf, len, GFP_KERNEL);
2137 if (!msg_ind->msg) {
2141 * FIXME: Do something smarter then just
2142 * printing an error.
2144 wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
2145 msg_header->msg_type);
2148 mutex_lock(&wcn->hal_ind_mutex);
2149 list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
2150 queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
2151 mutex_unlock(&wcn->hal_ind_mutex);
2152 wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n");
2155 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2156 msg_header->msg_type);
2159 static void wcn36xx_ind_smd_work(struct work_struct *work)
2161 struct wcn36xx *wcn =
2162 container_of(work, struct wcn36xx, hal_ind_work);
2163 struct wcn36xx_hal_msg_header *msg_header;
2164 struct wcn36xx_hal_ind_msg *hal_ind_msg;
2166 mutex_lock(&wcn->hal_ind_mutex);
2168 hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
2169 struct wcn36xx_hal_ind_msg,
2172 msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
2174 switch (msg_header->msg_type) {
2175 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2176 wcn36xx_smd_tx_compl_ind(wcn,
2178 hal_ind_msg->msg_len);
2180 case WCN36XX_HAL_MISSED_BEACON_IND:
2181 wcn36xx_smd_missed_beacon_ind(wcn,
2183 hal_ind_msg->msg_len);
2185 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2186 wcn36xx_smd_delete_sta_context_ind(wcn,
2188 hal_ind_msg->msg_len);
2191 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2192 msg_header->msg_type);
2194 list_del(wcn->hal_ind_queue.next);
2195 kfree(hal_ind_msg->msg);
2197 mutex_unlock(&wcn->hal_ind_mutex);
2199 int wcn36xx_smd_open(struct wcn36xx *wcn)
2202 wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind");
2203 if (!wcn->hal_ind_wq) {
2204 wcn36xx_err("failed to allocate wq\n");
2208 INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work);
2209 INIT_LIST_HEAD(&wcn->hal_ind_queue);
2210 mutex_init(&wcn->hal_ind_mutex);
2212 ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
2214 wcn36xx_err("failed to open control channel\n");
2221 destroy_workqueue(wcn->hal_ind_wq);
2226 void wcn36xx_smd_close(struct wcn36xx *wcn)
2228 wcn->ctrl_ops->close();
2229 destroy_workqueue(wcn->hal_ind_wq);
2230 mutex_destroy(&wcn->hal_ind_mutex);