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 *vif_priv = wcn36xx_vif_to_priv(vif);
195 struct wcn36xx_sta *sta_priv = 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 = WCN36XX_HAL_STA_INVALID_IDX;
202 sta_params->type = 0;
203 sta_params->sta_index = vif_priv->self_sta_index;
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 = vif_priv->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 = vif_priv->bss_index;
231 sta_priv = wcn36xx_sta_to_priv(sta);
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 = sta_priv->aid;
239 wcn36xx_smd_set_sta_ht_params(sta, sta_params);
240 memcpy(&sta_params->supported_rates, &sta_priv->supported_rates,
241 sizeof(sta_priv->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, 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 static void init_hal_msg(struct wcn36xx_hal_msg_header *hdr,
275 enum wcn36xx_hal_host_msg_type msg_type,
278 memset(hdr, 0, msg_size + sizeof(*hdr));
279 hdr->msg_type = msg_type;
280 hdr->msg_version = WCN36XX_HAL_MSG_VERSION0;
281 hdr->len = msg_size + sizeof(*hdr);
284 #define INIT_HAL_MSG(msg_body, type) \
286 memset(&msg_body, 0, sizeof(msg_body)); \
287 msg_body.header.msg_type = type; \
288 msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
289 msg_body.header.len = sizeof(msg_body); \
292 #define PREPARE_HAL_BUF(send_buf, msg_body) \
294 memset(send_buf, 0, msg_body.header.len); \
295 memcpy(send_buf, &msg_body, sizeof(msg_body)); \
298 static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
300 struct wcn36xx_fw_msg_status_rsp *rsp;
302 if (len < sizeof(struct wcn36xx_hal_msg_header) +
303 sizeof(struct wcn36xx_fw_msg_status_rsp))
306 rsp = (struct wcn36xx_fw_msg_status_rsp *)
307 (buf + sizeof(struct wcn36xx_hal_msg_header));
309 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status)
315 int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
317 struct nv_data *nv_d;
318 struct wcn36xx_hal_nv_img_download_req_msg msg_body;
324 ret = request_firmware(&wcn->nv, WLAN_NV_FILE, wcn->dev);
326 wcn36xx_err("Failed to load nv file %s: %d\n",
332 nv_d = (struct nv_data *)wcn->nv->data;
333 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DOWNLOAD_NV_REQ);
335 msg_body.header.len += WCN36XX_NV_FRAGMENT_SIZE;
337 msg_body.frag_number = 0;
338 /* hal_buf must be protected with mutex */
339 mutex_lock(&wcn->hal_mutex);
342 fw_bytes_left = wcn->nv->size - fm_offset - 4;
343 if (fw_bytes_left > WCN36XX_NV_FRAGMENT_SIZE) {
344 msg_body.last_fragment = 0;
345 msg_body.nv_img_buffer_size = WCN36XX_NV_FRAGMENT_SIZE;
347 msg_body.last_fragment = 1;
348 msg_body.nv_img_buffer_size = fw_bytes_left;
350 /* Do not forget update general message len */
351 msg_body.header.len = sizeof(msg_body) + fw_bytes_left;
355 /* Add load NV request message header */
356 memcpy(wcn->hal_buf, &msg_body, sizeof(msg_body));
358 /* Add NV body itself */
359 memcpy(wcn->hal_buf + sizeof(msg_body),
360 &nv_d->table + fm_offset,
361 msg_body.nv_img_buffer_size);
363 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
366 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf,
369 wcn36xx_err("hal_load_nv response failed err=%d\n",
373 msg_body.frag_number++;
374 fm_offset += WCN36XX_NV_FRAGMENT_SIZE;
376 } while (msg_body.last_fragment != 1);
379 mutex_unlock(&wcn->hal_mutex);
383 static int wcn36xx_smd_start_rsp(struct wcn36xx *wcn, void *buf, size_t len)
385 struct wcn36xx_hal_mac_start_rsp_msg *rsp;
387 if (len < sizeof(*rsp))
390 rsp = (struct wcn36xx_hal_mac_start_rsp_msg *)buf;
392 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->start_rsp_params.status)
395 memcpy(wcn->crm_version, rsp->start_rsp_params.crm_version,
396 WCN36XX_HAL_VERSION_LENGTH);
397 memcpy(wcn->wlan_version, rsp->start_rsp_params.wlan_version,
398 WCN36XX_HAL_VERSION_LENGTH);
400 /* null terminate the strings, just in case */
401 wcn->crm_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
402 wcn->wlan_version[WCN36XX_HAL_VERSION_LENGTH] = '\0';
404 wcn->fw_revision = rsp->start_rsp_params.version.revision;
405 wcn->fw_version = rsp->start_rsp_params.version.version;
406 wcn->fw_minor = rsp->start_rsp_params.version.minor;
407 wcn->fw_major = rsp->start_rsp_params.version.major;
409 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
410 wcn->wlan_version, wcn->crm_version);
412 wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
413 wcn->fw_major, wcn->fw_minor,
414 wcn->fw_version, wcn->fw_revision,
415 rsp->start_rsp_params.stations,
416 rsp->start_rsp_params.bssids);
421 int wcn36xx_smd_start(struct wcn36xx *wcn)
423 struct wcn36xx_hal_mac_start_req_msg msg_body, *body;
428 mutex_lock(&wcn->hal_mutex);
429 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_REQ);
431 msg_body.params.type = DRIVER_TYPE_PRODUCTION;
432 msg_body.params.len = 0;
434 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
436 body = (struct wcn36xx_hal_mac_start_req_msg *)wcn->hal_buf;
437 len = body->header.len;
439 for (i = 0; i < ARRAY_SIZE(wcn36xx_cfg_vals); i++) {
440 ret = put_cfg_tlv_u32(wcn, &len, wcn36xx_cfg_vals[i].cfg_id,
441 wcn36xx_cfg_vals[i].value);
445 body->header.len = len;
446 body->params.len = len - sizeof(*body);
448 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start type %d\n",
449 msg_body.params.type);
451 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
453 wcn36xx_err("Sending hal_start failed\n");
457 ret = wcn36xx_smd_start_rsp(wcn, wcn->hal_buf, wcn->hal_rsp_len);
459 wcn36xx_err("hal_start response failed err=%d\n", ret);
464 mutex_unlock(&wcn->hal_mutex);
468 int wcn36xx_smd_stop(struct wcn36xx *wcn)
470 struct wcn36xx_hal_mac_stop_req_msg msg_body;
473 mutex_lock(&wcn->hal_mutex);
474 INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_REQ);
476 msg_body.stop_req_params.reason = HAL_STOP_TYPE_RF_KILL;
478 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
480 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
482 wcn36xx_err("Sending hal_stop failed\n");
485 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
487 wcn36xx_err("hal_stop response failed err=%d\n", ret);
491 mutex_unlock(&wcn->hal_mutex);
495 int wcn36xx_smd_init_scan(struct wcn36xx *wcn, enum wcn36xx_hal_sys_mode mode)
497 struct wcn36xx_hal_init_scan_req_msg msg_body;
500 mutex_lock(&wcn->hal_mutex);
501 INIT_HAL_MSG(msg_body, WCN36XX_HAL_INIT_SCAN_REQ);
503 msg_body.mode = mode;
505 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
507 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal init scan mode %d\n", msg_body.mode);
509 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
511 wcn36xx_err("Sending hal_init_scan failed\n");
514 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
516 wcn36xx_err("hal_init_scan response failed err=%d\n", ret);
520 mutex_unlock(&wcn->hal_mutex);
524 int wcn36xx_smd_start_scan(struct wcn36xx *wcn)
526 struct wcn36xx_hal_start_scan_req_msg msg_body;
529 mutex_lock(&wcn->hal_mutex);
530 INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_REQ);
532 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
534 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
536 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal start scan channel %d\n",
537 msg_body.scan_channel);
539 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
541 wcn36xx_err("Sending hal_start_scan failed\n");
544 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
546 wcn36xx_err("hal_start_scan response failed err=%d\n", ret);
550 mutex_unlock(&wcn->hal_mutex);
554 int wcn36xx_smd_end_scan(struct wcn36xx *wcn)
556 struct wcn36xx_hal_end_scan_req_msg msg_body;
559 mutex_lock(&wcn->hal_mutex);
560 INIT_HAL_MSG(msg_body, WCN36XX_HAL_END_SCAN_REQ);
562 msg_body.scan_channel = WCN36XX_HW_CHANNEL(wcn);
564 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
566 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal end scan channel %d\n",
567 msg_body.scan_channel);
569 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
571 wcn36xx_err("Sending hal_end_scan failed\n");
574 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
576 wcn36xx_err("hal_end_scan response failed err=%d\n", ret);
580 mutex_unlock(&wcn->hal_mutex);
584 int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
585 enum wcn36xx_hal_sys_mode mode)
587 struct wcn36xx_hal_finish_scan_req_msg msg_body;
590 mutex_lock(&wcn->hal_mutex);
591 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FINISH_SCAN_REQ);
593 msg_body.mode = mode;
595 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
597 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal finish scan mode %d\n",
600 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
602 wcn36xx_err("Sending hal_finish_scan failed\n");
605 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
607 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret);
611 mutex_unlock(&wcn->hal_mutex);
615 static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
617 struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
620 ret = wcn36xx_smd_rsp_status_check(buf, len);
623 rsp = (struct wcn36xx_hal_switch_channel_rsp_msg *)buf;
624 wcn36xx_dbg(WCN36XX_DBG_HAL, "channel switched to: %d, status: %d\n",
625 rsp->channel_number, rsp->status);
629 int wcn36xx_smd_switch_channel(struct wcn36xx *wcn,
630 struct ieee80211_vif *vif, int ch)
632 struct wcn36xx_hal_switch_channel_req_msg msg_body;
635 mutex_lock(&wcn->hal_mutex);
636 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CH_SWITCH_REQ);
638 msg_body.channel_number = (u8)ch;
639 msg_body.tx_mgmt_power = 0xbf;
640 msg_body.max_tx_power = 0xbf;
641 memcpy(msg_body.self_sta_mac_addr, vif->addr, ETH_ALEN);
643 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
645 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
647 wcn36xx_err("Sending hal_switch_channel failed\n");
650 ret = wcn36xx_smd_switch_channel_rsp(wcn->hal_buf, wcn->hal_rsp_len);
652 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret);
656 mutex_unlock(&wcn->hal_mutex);
660 static int wcn36xx_smd_update_scan_params_rsp(void *buf, size_t len)
662 struct wcn36xx_hal_update_scan_params_resp *rsp;
664 rsp = (struct wcn36xx_hal_update_scan_params_resp *)buf;
666 /* Remove the PNO version bit */
667 rsp->status &= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK));
669 if (WCN36XX_FW_MSG_RESULT_SUCCESS != rsp->status) {
670 wcn36xx_warn("error response from update scan\n");
677 int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn)
679 struct wcn36xx_hal_update_scan_params_req msg_body;
682 mutex_lock(&wcn->hal_mutex);
683 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ);
685 msg_body.dot11d_enabled = 0;
686 msg_body.dot11d_resolved = 0;
687 msg_body.channel_count = 26;
688 msg_body.active_min_ch_time = 60;
689 msg_body.active_max_ch_time = 120;
690 msg_body.passive_min_ch_time = 60;
691 msg_body.passive_max_ch_time = 110;
694 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
696 wcn36xx_dbg(WCN36XX_DBG_HAL,
697 "hal update scan params channel_count %d\n",
698 msg_body.channel_count);
700 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
702 wcn36xx_err("Sending hal_update_scan_params failed\n");
705 ret = wcn36xx_smd_update_scan_params_rsp(wcn->hal_buf,
708 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
713 mutex_unlock(&wcn->hal_mutex);
717 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx *wcn,
718 struct ieee80211_vif *vif,
722 struct wcn36xx_hal_add_sta_self_rsp_msg *rsp;
723 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
725 if (len < sizeof(*rsp))
728 rsp = (struct wcn36xx_hal_add_sta_self_rsp_msg *)buf;
730 if (rsp->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
731 wcn36xx_warn("hal add sta self failure: %d\n",
736 wcn36xx_dbg(WCN36XX_DBG_HAL,
737 "hal add sta self status %d self_sta_index %d dpu_index %d\n",
738 rsp->status, rsp->self_sta_index, rsp->dpu_index);
740 vif_priv->self_sta_index = rsp->self_sta_index;
741 vif_priv->self_dpu_desc_index = rsp->dpu_index;
746 int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif)
748 struct wcn36xx_hal_add_sta_self_req msg_body;
751 mutex_lock(&wcn->hal_mutex);
752 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_STA_SELF_REQ);
754 memcpy(&msg_body.self_addr, vif->addr, ETH_ALEN);
756 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
758 wcn36xx_dbg(WCN36XX_DBG_HAL,
759 "hal add sta self self_addr %pM status %d\n",
760 msg_body.self_addr, msg_body.status);
762 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
764 wcn36xx_err("Sending hal_add_sta_self failed\n");
767 ret = wcn36xx_smd_add_sta_self_rsp(wcn,
772 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret);
776 mutex_unlock(&wcn->hal_mutex);
780 int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr)
782 struct wcn36xx_hal_del_sta_self_req_msg msg_body;
785 mutex_lock(&wcn->hal_mutex);
786 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_STA_SELF_REQ);
788 memcpy(&msg_body.self_addr, addr, ETH_ALEN);
790 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
792 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
794 wcn36xx_err("Sending hal_delete_sta_self failed\n");
797 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
799 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
804 mutex_unlock(&wcn->hal_mutex);
808 int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index)
810 struct wcn36xx_hal_delete_sta_req_msg msg_body;
813 mutex_lock(&wcn->hal_mutex);
814 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_STA_REQ);
816 msg_body.sta_index = sta_index;
818 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
820 wcn36xx_dbg(WCN36XX_DBG_HAL,
821 "hal delete sta sta_index %d\n",
824 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
826 wcn36xx_err("Sending hal_delete_sta failed\n");
829 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
831 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret);
835 mutex_unlock(&wcn->hal_mutex);
839 static int wcn36xx_smd_join_rsp(void *buf, size_t len)
841 struct wcn36xx_hal_join_rsp_msg *rsp;
843 if (wcn36xx_smd_rsp_status_check(buf, len))
846 rsp = (struct wcn36xx_hal_join_rsp_msg *)buf;
848 wcn36xx_dbg(WCN36XX_DBG_HAL,
849 "hal rsp join status %d tx_mgmt_power %d\n",
850 rsp->status, rsp->tx_mgmt_power);
855 int wcn36xx_smd_join(struct wcn36xx *wcn, const u8 *bssid, u8 *vif, u8 ch)
857 struct wcn36xx_hal_join_req_msg msg_body;
860 mutex_lock(&wcn->hal_mutex);
861 INIT_HAL_MSG(msg_body, WCN36XX_HAL_JOIN_REQ);
863 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
864 memcpy(&msg_body.self_sta_mac_addr, vif, ETH_ALEN);
865 msg_body.channel = ch;
867 if (conf_is_ht40_minus(&wcn->hw->conf))
868 msg_body.secondary_channel_offset =
869 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY;
870 else if (conf_is_ht40_plus(&wcn->hw->conf))
871 msg_body.secondary_channel_offset =
872 PHY_DOUBLE_CHANNEL_LOW_PRIMARY;
874 msg_body.secondary_channel_offset =
875 PHY_SINGLE_CHANNEL_CENTERED;
877 msg_body.link_state = WCN36XX_HAL_LINK_PREASSOC_STATE;
879 msg_body.max_tx_power = 0xbf;
880 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
882 wcn36xx_dbg(WCN36XX_DBG_HAL,
883 "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
884 msg_body.bssid, msg_body.self_sta_mac_addr,
885 msg_body.channel, msg_body.link_state);
887 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
889 wcn36xx_err("Sending hal_join failed\n");
892 ret = wcn36xx_smd_join_rsp(wcn->hal_buf, wcn->hal_rsp_len);
894 wcn36xx_err("hal_join response failed err=%d\n", ret);
898 mutex_unlock(&wcn->hal_mutex);
902 int wcn36xx_smd_set_link_st(struct wcn36xx *wcn, const u8 *bssid,
904 enum wcn36xx_hal_link_state state)
906 struct wcn36xx_hal_set_link_state_req_msg msg_body;
909 mutex_lock(&wcn->hal_mutex);
910 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_LINK_ST_REQ);
912 memcpy(&msg_body.bssid, bssid, ETH_ALEN);
913 memcpy(&msg_body.self_mac_addr, sta_mac, ETH_ALEN);
914 msg_body.state = state;
916 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
918 wcn36xx_dbg(WCN36XX_DBG_HAL,
919 "hal set link state bssid %pM self_mac_addr %pM state %d\n",
920 msg_body.bssid, msg_body.self_mac_addr, msg_body.state);
922 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
924 wcn36xx_err("Sending hal_set_link_st failed\n");
927 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
929 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret);
933 mutex_unlock(&wcn->hal_mutex);
937 static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx *wcn,
938 const struct wcn36xx_hal_config_sta_params *orig,
939 struct wcn36xx_hal_config_sta_params_v1 *v1)
941 /* convert orig to v1 format */
942 memcpy(&v1->bssid, orig->bssid, ETH_ALEN);
943 memcpy(&v1->mac, orig->mac, ETH_ALEN);
945 v1->type = orig->type;
946 v1->short_preamble_supported = orig->short_preamble_supported;
947 v1->listen_interval = orig->listen_interval;
948 v1->wmm_enabled = orig->wmm_enabled;
949 v1->ht_capable = orig->ht_capable;
950 v1->tx_channel_width_set = orig->tx_channel_width_set;
951 v1->rifs_mode = orig->rifs_mode;
952 v1->lsig_txop_protection = orig->lsig_txop_protection;
953 v1->max_ampdu_size = orig->max_ampdu_size;
954 v1->max_ampdu_density = orig->max_ampdu_density;
955 v1->sgi_40mhz = orig->sgi_40mhz;
956 v1->sgi_20Mhz = orig->sgi_20Mhz;
958 v1->encrypt_type = orig->encrypt_type;
959 v1->action = orig->action;
960 v1->uapsd = orig->uapsd;
961 v1->max_sp_len = orig->max_sp_len;
962 v1->green_field_capable = orig->green_field_capable;
963 v1->mimo_ps = orig->mimo_ps;
964 v1->delayed_ba_support = orig->delayed_ba_support;
965 v1->max_ampdu_duration = orig->max_ampdu_duration;
966 v1->dsss_cck_mode_40mhz = orig->dsss_cck_mode_40mhz;
967 memcpy(&v1->supported_rates, &orig->supported_rates,
968 sizeof(orig->supported_rates));
969 v1->sta_index = orig->sta_index;
970 v1->bssid_index = orig->bssid_index;
974 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx *wcn,
975 struct ieee80211_sta *sta,
979 struct wcn36xx_hal_config_sta_rsp_msg *rsp;
980 struct config_sta_rsp_params *params;
981 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
983 if (len < sizeof(*rsp))
986 rsp = (struct wcn36xx_hal_config_sta_rsp_msg *)buf;
987 params = &rsp->params;
989 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
990 wcn36xx_warn("hal config sta response failure: %d\n",
995 sta_priv->sta_index = params->sta_index;
996 sta_priv->dpu_desc_index = params->dpu_index;
997 sta_priv->ucast_dpu_sign = params->uc_ucast_sig;
999 wcn36xx_dbg(WCN36XX_DBG_HAL,
1000 "hal config sta rsp status %d sta_index %d bssid_index %d uc_ucast_sig %d p2p %d\n",
1001 params->status, params->sta_index, params->bssid_index,
1002 params->uc_ucast_sig, params->p2p);
1007 static int wcn36xx_smd_config_sta_v1(struct wcn36xx *wcn,
1008 const struct wcn36xx_hal_config_sta_req_msg *orig)
1010 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body;
1011 struct wcn36xx_hal_config_sta_params_v1 *sta = &msg_body.sta_params;
1013 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_STA_REQ);
1015 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->sta_params,
1016 &msg_body.sta_params);
1018 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1020 wcn36xx_dbg(WCN36XX_DBG_HAL,
1021 "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
1022 sta->action, sta->sta_index, sta->bssid_index,
1023 sta->bssid, sta->type, sta->mac, sta->aid);
1025 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1028 int wcn36xx_smd_config_sta(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1029 struct ieee80211_sta *sta)
1031 struct wcn36xx_hal_config_sta_req_msg msg;
1032 struct wcn36xx_hal_config_sta_params *sta_params;
1035 mutex_lock(&wcn->hal_mutex);
1036 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_STA_REQ);
1038 sta_params = &msg.sta_params;
1040 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
1042 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1043 ret = wcn36xx_smd_config_sta_v1(wcn, &msg);
1045 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1047 wcn36xx_dbg(WCN36XX_DBG_HAL,
1048 "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
1049 sta_params->action, sta_params->sta_index,
1050 sta_params->bssid_index, sta_params->bssid,
1051 sta_params->type, sta_params->mac, sta_params->aid);
1053 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1056 wcn36xx_err("Sending hal_config_sta failed\n");
1059 ret = wcn36xx_smd_config_sta_rsp(wcn,
1064 wcn36xx_err("hal_config_sta response failed err=%d\n", ret);
1068 mutex_unlock(&wcn->hal_mutex);
1072 static int wcn36xx_smd_config_bss_v1(struct wcn36xx *wcn,
1073 const struct wcn36xx_hal_config_bss_req_msg *orig)
1075 struct wcn36xx_hal_config_bss_req_msg_v1 msg_body;
1076 struct wcn36xx_hal_config_bss_params_v1 *bss = &msg_body.bss_params;
1077 struct wcn36xx_hal_config_sta_params_v1 *sta = &bss->sta;
1079 INIT_HAL_MSG(msg_body, WCN36XX_HAL_CONFIG_BSS_REQ);
1081 /* convert orig to v1 */
1082 memcpy(&msg_body.bss_params.bssid,
1083 &orig->bss_params.bssid, ETH_ALEN);
1084 memcpy(&msg_body.bss_params.self_mac_addr,
1085 &orig->bss_params.self_mac_addr, ETH_ALEN);
1087 msg_body.bss_params.bss_type = orig->bss_params.bss_type;
1088 msg_body.bss_params.oper_mode = orig->bss_params.oper_mode;
1089 msg_body.bss_params.nw_type = orig->bss_params.nw_type;
1091 msg_body.bss_params.short_slot_time_supported =
1092 orig->bss_params.short_slot_time_supported;
1093 msg_body.bss_params.lla_coexist = orig->bss_params.lla_coexist;
1094 msg_body.bss_params.llb_coexist = orig->bss_params.llb_coexist;
1095 msg_body.bss_params.llg_coexist = orig->bss_params.llg_coexist;
1096 msg_body.bss_params.ht20_coexist = orig->bss_params.ht20_coexist;
1097 msg_body.bss_params.lln_non_gf_coexist =
1098 orig->bss_params.lln_non_gf_coexist;
1100 msg_body.bss_params.lsig_tx_op_protection_full_support =
1101 orig->bss_params.lsig_tx_op_protection_full_support;
1102 msg_body.bss_params.rifs_mode = orig->bss_params.rifs_mode;
1103 msg_body.bss_params.beacon_interval = orig->bss_params.beacon_interval;
1104 msg_body.bss_params.dtim_period = orig->bss_params.dtim_period;
1105 msg_body.bss_params.tx_channel_width_set =
1106 orig->bss_params.tx_channel_width_set;
1107 msg_body.bss_params.oper_channel = orig->bss_params.oper_channel;
1108 msg_body.bss_params.ext_channel = orig->bss_params.ext_channel;
1110 msg_body.bss_params.reserved = orig->bss_params.reserved;
1112 memcpy(&msg_body.bss_params.ssid,
1113 &orig->bss_params.ssid,
1114 sizeof(orig->bss_params.ssid));
1116 msg_body.bss_params.action = orig->bss_params.action;
1117 msg_body.bss_params.rateset = orig->bss_params.rateset;
1118 msg_body.bss_params.ht = orig->bss_params.ht;
1119 msg_body.bss_params.obss_prot_enabled =
1120 orig->bss_params.obss_prot_enabled;
1121 msg_body.bss_params.rmf = orig->bss_params.rmf;
1122 msg_body.bss_params.ht_oper_mode = orig->bss_params.ht_oper_mode;
1123 msg_body.bss_params.dual_cts_protection =
1124 orig->bss_params.dual_cts_protection;
1126 msg_body.bss_params.max_probe_resp_retry_limit =
1127 orig->bss_params.max_probe_resp_retry_limit;
1128 msg_body.bss_params.hidden_ssid = orig->bss_params.hidden_ssid;
1129 msg_body.bss_params.proxy_probe_resp =
1130 orig->bss_params.proxy_probe_resp;
1131 msg_body.bss_params.edca_params_valid =
1132 orig->bss_params.edca_params_valid;
1134 memcpy(&msg_body.bss_params.acbe,
1135 &orig->bss_params.acbe,
1136 sizeof(orig->bss_params.acbe));
1137 memcpy(&msg_body.bss_params.acbk,
1138 &orig->bss_params.acbk,
1139 sizeof(orig->bss_params.acbk));
1140 memcpy(&msg_body.bss_params.acvi,
1141 &orig->bss_params.acvi,
1142 sizeof(orig->bss_params.acvi));
1143 memcpy(&msg_body.bss_params.acvo,
1144 &orig->bss_params.acvo,
1145 sizeof(orig->bss_params.acvo));
1147 msg_body.bss_params.ext_set_sta_key_param_valid =
1148 orig->bss_params.ext_set_sta_key_param_valid;
1150 memcpy(&msg_body.bss_params.ext_set_sta_key_param,
1151 &orig->bss_params.ext_set_sta_key_param,
1152 sizeof(orig->bss_params.acvo));
1154 msg_body.bss_params.wcn36xx_hal_persona =
1155 orig->bss_params.wcn36xx_hal_persona;
1156 msg_body.bss_params.spectrum_mgt_enable =
1157 orig->bss_params.spectrum_mgt_enable;
1158 msg_body.bss_params.tx_mgmt_power = orig->bss_params.tx_mgmt_power;
1159 msg_body.bss_params.max_tx_power = orig->bss_params.max_tx_power;
1161 wcn36xx_smd_convert_sta_to_v1(wcn, &orig->bss_params.sta,
1162 &msg_body.bss_params.sta);
1164 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1166 wcn36xx_dbg(WCN36XX_DBG_HAL,
1167 "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1168 bss->bssid, bss->self_mac_addr, bss->bss_type,
1169 bss->oper_mode, bss->nw_type);
1171 wcn36xx_dbg(WCN36XX_DBG_HAL,
1172 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1173 sta->bssid, sta->action, sta->sta_index,
1174 sta->bssid_index, sta->aid, sta->type, sta->mac);
1176 return wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1180 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx *wcn,
1181 struct ieee80211_vif *vif,
1182 struct ieee80211_sta *sta,
1186 struct wcn36xx_hal_config_bss_rsp_msg *rsp;
1187 struct wcn36xx_hal_config_bss_rsp_params *params;
1188 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
1190 if (len < sizeof(*rsp))
1193 rsp = (struct wcn36xx_hal_config_bss_rsp_msg *)buf;
1194 params = &rsp->bss_rsp_params;
1196 if (params->status != WCN36XX_FW_MSG_RESULT_SUCCESS) {
1197 wcn36xx_warn("hal config bss response failure: %d\n",
1202 wcn36xx_dbg(WCN36XX_DBG_HAL,
1203 "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
1204 " sta_idx %d self_idx %d bcast_idx %d mac %pM"
1205 " power %d ucast_dpu_signature %d\n",
1206 params->status, params->bss_index, params->dpu_desc_index,
1207 params->bss_sta_index, params->bss_self_sta_index,
1208 params->bss_bcast_sta_idx, params->mac,
1209 params->tx_mgmt_power, params->ucast_dpu_signature);
1211 vif_priv->bss_index = params->bss_index;
1214 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
1215 sta_priv->bss_sta_index = params->bss_sta_index;
1216 sta_priv->bss_dpu_desc_index = params->dpu_desc_index;
1219 vif_priv->self_ucast_dpu_sign = params->ucast_dpu_signature;
1224 int wcn36xx_smd_config_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1225 struct ieee80211_sta *sta, const u8 *bssid,
1228 struct wcn36xx_hal_config_bss_req_msg msg;
1229 struct wcn36xx_hal_config_bss_params *bss;
1230 struct wcn36xx_hal_config_sta_params *sta_params;
1231 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
1234 mutex_lock(&wcn->hal_mutex);
1235 INIT_HAL_MSG(msg, WCN36XX_HAL_CONFIG_BSS_REQ);
1237 bss = &msg.bss_params;
1238 sta_params = &bss->sta;
1240 WARN_ON(is_zero_ether_addr(bssid));
1242 memcpy(&bss->bssid, bssid, ETH_ALEN);
1244 memcpy(bss->self_mac_addr, vif->addr, ETH_ALEN);
1246 if (vif->type == NL80211_IFTYPE_STATION) {
1247 bss->bss_type = WCN36XX_HAL_INFRASTRUCTURE_MODE;
1251 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_MODE;
1252 } else if (vif->type == NL80211_IFTYPE_AP ||
1253 vif->type == NL80211_IFTYPE_MESH_POINT) {
1254 bss->bss_type = WCN36XX_HAL_INFRA_AP_MODE;
1258 bss->wcn36xx_hal_persona = WCN36XX_HAL_STA_SAP_MODE;
1259 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
1260 bss->bss_type = WCN36XX_HAL_IBSS_MODE;
1265 wcn36xx_warn("Unknown type for bss config: %d\n", vif->type);
1268 if (vif->type == NL80211_IFTYPE_STATION)
1269 wcn36xx_smd_set_bss_nw_type(wcn, sta, bss);
1271 bss->nw_type = WCN36XX_HAL_11N_NW_TYPE;
1273 bss->short_slot_time_supported = vif->bss_conf.use_short_slot;
1274 bss->lla_coexist = 0;
1275 bss->llb_coexist = 0;
1276 bss->llg_coexist = 0;
1278 bss->beacon_interval = vif->bss_conf.beacon_int;
1279 bss->dtim_period = vif_priv->dtim_period;
1281 wcn36xx_smd_set_bss_ht_params(vif, sta, bss);
1283 bss->oper_channel = WCN36XX_HW_CHANNEL(wcn);
1285 if (conf_is_ht40_minus(&wcn->hw->conf))
1286 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1287 else if (conf_is_ht40_plus(&wcn->hw->conf))
1288 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1290 bss->ext_channel = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1293 wcn36xx_smd_set_sta_params(wcn, vif, sta, sta_params);
1295 /* wcn->ssid is only valid in AP and IBSS mode */
1296 bss->ssid.length = vif_priv->ssid.length;
1297 memcpy(bss->ssid.ssid, vif_priv->ssid.ssid, vif_priv->ssid.length);
1299 bss->obss_prot_enabled = 0;
1301 bss->max_probe_resp_retry_limit = 0;
1302 bss->hidden_ssid = vif->bss_conf.hidden_ssid;
1303 bss->proxy_probe_resp = 0;
1304 bss->edca_params_valid = 0;
1306 /* FIXME: set acbe, acbk, acvi and acvo */
1308 bss->ext_set_sta_key_param_valid = 0;
1310 /* FIXME: set ext_set_sta_key_param */
1312 bss->spectrum_mgt_enable = 0;
1313 bss->tx_mgmt_power = 0;
1314 bss->max_tx_power = WCN36XX_MAX_POWER(wcn);
1316 bss->action = update;
1318 wcn36xx_dbg(WCN36XX_DBG_HAL,
1319 "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1320 bss->bssid, bss->self_mac_addr, bss->bss_type,
1321 bss->oper_mode, bss->nw_type);
1323 wcn36xx_dbg(WCN36XX_DBG_HAL,
1324 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1325 sta_params->bssid, sta_params->action,
1326 sta_params->sta_index, sta_params->bssid_index,
1327 sta_params->aid, sta_params->type,
1330 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
1331 ret = wcn36xx_smd_config_bss_v1(wcn, &msg);
1333 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1335 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1338 wcn36xx_err("Sending hal_config_bss failed\n");
1341 ret = wcn36xx_smd_config_bss_rsp(wcn,
1347 wcn36xx_err("hal_config_bss response failed err=%d\n", ret);
1351 mutex_unlock(&wcn->hal_mutex);
1355 int wcn36xx_smd_delete_bss(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1357 struct wcn36xx_hal_delete_bss_req_msg msg_body;
1358 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
1361 mutex_lock(&wcn->hal_mutex);
1362 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DELETE_BSS_REQ);
1364 msg_body.bss_index = vif_priv->bss_index;
1366 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1368 wcn36xx_dbg(WCN36XX_DBG_HAL, "hal delete bss %d\n", msg_body.bss_index);
1370 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1372 wcn36xx_err("Sending hal_delete_bss failed\n");
1375 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1377 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret);
1381 mutex_unlock(&wcn->hal_mutex);
1385 int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
1386 struct sk_buff *skb_beacon, u16 tim_off,
1389 struct wcn36xx_hal_send_beacon_req_msg msg_body;
1390 int ret = 0, pad, pvm_len;
1393 mutex_lock(&wcn->hal_mutex);
1394 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SEND_BEACON_REQ);
1396 pvm_len = skb_beacon->data[tim_off + 1] - 3;
1397 pad = TIM_MIN_PVM_SIZE - pvm_len;
1399 /* Padding is irrelevant to mesh mode since tim_off is always 0. */
1400 if (vif->type == NL80211_IFTYPE_MESH_POINT)
1403 beacon_length = skb_beacon->len + pad;
1404 msg_body.template_length = beacon_length + sizeof(beacon_length);
1406 if (msg_body.template_length > BEACON_TEMPLATE_SIZE) {
1407 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1408 msg_body.template_length);
1412 msg_body.beacon_length = beacon_length;
1413 memcpy(msg_body.beacon, skb_beacon->data, skb_beacon->len);
1414 memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
1418 * The wcn36xx FW has a fixed size for the PVM in the TIM. If
1419 * given the beacon template from mac80211 with a PVM shorter
1420 * than the FW expectes it will overwrite the data after the
1423 wcn36xx_dbg(WCN36XX_DBG_HAL, "Pad TIM PVM. %d bytes at %d\n",
1425 memmove(&msg_body.beacon[tim_off + 5 + pvm_len + pad],
1426 &msg_body.beacon[tim_off + 5 + pvm_len],
1427 skb_beacon->len - (tim_off + 5 + pvm_len));
1428 memset(&msg_body.beacon[tim_off + 5 + pvm_len], 0, pad);
1429 msg_body.beacon[tim_off + 1] += pad;
1432 /* TODO need to find out why this is needed? */
1433 if (vif->type == NL80211_IFTYPE_MESH_POINT)
1434 /* mesh beacon don't need this, so push further down */
1435 msg_body.tim_ie_offset = 256;
1437 msg_body.tim_ie_offset = tim_off+4;
1438 msg_body.p2p_ie_offset = p2p_off;
1439 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1441 wcn36xx_dbg(WCN36XX_DBG_HAL,
1442 "hal send beacon beacon_length %d\n",
1443 msg_body.beacon_length);
1445 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1447 wcn36xx_err("Sending hal_send_beacon failed\n");
1450 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1452 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret);
1456 mutex_unlock(&wcn->hal_mutex);
1460 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
1461 struct ieee80211_vif *vif,
1462 struct sk_buff *skb)
1464 struct wcn36xx_hal_send_probe_resp_req_msg msg;
1467 mutex_lock(&wcn->hal_mutex);
1468 INIT_HAL_MSG(msg, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ);
1470 if (skb->len > BEACON_TEMPLATE_SIZE) {
1471 wcn36xx_warn("probe response template is too big: %d\n",
1477 msg.probe_resp_template_len = skb->len;
1478 memcpy(&msg.probe_resp_template, skb->data, skb->len);
1480 memcpy(msg.bssid, vif->addr, ETH_ALEN);
1482 PREPARE_HAL_BUF(wcn->hal_buf, msg);
1484 wcn36xx_dbg(WCN36XX_DBG_HAL,
1485 "hal update probe rsp len %d bssid %pM\n",
1486 msg.probe_resp_template_len, msg.bssid);
1488 ret = wcn36xx_smd_send_and_wait(wcn, msg.header.len);
1490 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1493 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1495 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1500 mutex_unlock(&wcn->hal_mutex);
1504 int wcn36xx_smd_set_stakey(struct wcn36xx *wcn,
1505 enum ani_ed_type enc_type,
1511 struct wcn36xx_hal_set_sta_key_req_msg msg_body;
1514 mutex_lock(&wcn->hal_mutex);
1515 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_STAKEY_REQ);
1517 msg_body.set_sta_key_params.sta_index = sta_index;
1518 msg_body.set_sta_key_params.enc_type = enc_type;
1520 msg_body.set_sta_key_params.key[0].id = keyidx;
1521 msg_body.set_sta_key_params.key[0].unicast = 1;
1522 msg_body.set_sta_key_params.key[0].direction = WCN36XX_HAL_TX_RX;
1523 msg_body.set_sta_key_params.key[0].pae_role = 0;
1524 msg_body.set_sta_key_params.key[0].length = keylen;
1525 memcpy(msg_body.set_sta_key_params.key[0].key, key, keylen);
1526 msg_body.set_sta_key_params.single_tid_rc = 1;
1528 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1530 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1532 wcn36xx_err("Sending hal_set_stakey failed\n");
1535 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1537 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret);
1541 mutex_unlock(&wcn->hal_mutex);
1545 int wcn36xx_smd_set_bsskey(struct wcn36xx *wcn,
1546 enum ani_ed_type enc_type,
1551 struct wcn36xx_hal_set_bss_key_req_msg msg_body;
1554 mutex_lock(&wcn->hal_mutex);
1555 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_BSSKEY_REQ);
1556 msg_body.bss_idx = 0;
1557 msg_body.enc_type = enc_type;
1558 msg_body.num_keys = 1;
1559 msg_body.keys[0].id = keyidx;
1560 msg_body.keys[0].unicast = 0;
1561 msg_body.keys[0].direction = WCN36XX_HAL_RX_ONLY;
1562 msg_body.keys[0].pae_role = 0;
1563 msg_body.keys[0].length = keylen;
1564 memcpy(msg_body.keys[0].key, key, keylen);
1566 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1568 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1570 wcn36xx_err("Sending hal_set_bsskey failed\n");
1573 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1575 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret);
1579 mutex_unlock(&wcn->hal_mutex);
1583 int wcn36xx_smd_remove_stakey(struct wcn36xx *wcn,
1584 enum ani_ed_type enc_type,
1588 struct wcn36xx_hal_remove_sta_key_req_msg msg_body;
1591 mutex_lock(&wcn->hal_mutex);
1592 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_STAKEY_REQ);
1594 msg_body.sta_idx = sta_index;
1595 msg_body.enc_type = enc_type;
1596 msg_body.key_id = keyidx;
1598 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1600 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1602 wcn36xx_err("Sending hal_remove_stakey failed\n");
1605 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1607 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret);
1611 mutex_unlock(&wcn->hal_mutex);
1615 int wcn36xx_smd_remove_bsskey(struct wcn36xx *wcn,
1616 enum ani_ed_type enc_type,
1619 struct wcn36xx_hal_remove_bss_key_req_msg msg_body;
1622 mutex_lock(&wcn->hal_mutex);
1623 INIT_HAL_MSG(msg_body, WCN36XX_HAL_RMV_BSSKEY_REQ);
1624 msg_body.bss_idx = 0;
1625 msg_body.enc_type = enc_type;
1626 msg_body.key_id = keyidx;
1628 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1630 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1632 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1635 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1637 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret);
1641 mutex_unlock(&wcn->hal_mutex);
1645 int wcn36xx_smd_enter_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1647 struct wcn36xx_hal_enter_bmps_req_msg msg_body;
1648 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
1651 mutex_lock(&wcn->hal_mutex);
1652 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ENTER_BMPS_REQ);
1654 msg_body.bss_index = vif_priv->bss_index;
1655 msg_body.tbtt = vif->bss_conf.sync_tsf;
1656 msg_body.dtim_period = vif_priv->dtim_period;
1658 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1660 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1662 wcn36xx_err("Sending hal_enter_bmps failed\n");
1665 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1667 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret);
1671 mutex_unlock(&wcn->hal_mutex);
1675 int wcn36xx_smd_exit_bmps(struct wcn36xx *wcn, struct ieee80211_vif *vif)
1677 struct wcn36xx_hal_exit_bmps_req_msg msg_body;
1678 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
1681 mutex_lock(&wcn->hal_mutex);
1682 INIT_HAL_MSG(msg_body, WCN36XX_HAL_EXIT_BMPS_REQ);
1684 msg_body.bss_index = vif_priv->bss_index;
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_exit_bmps failed\n");
1693 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1695 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret);
1699 mutex_unlock(&wcn->hal_mutex);
1702 int wcn36xx_smd_set_power_params(struct wcn36xx *wcn, bool ignore_dtim)
1704 struct wcn36xx_hal_set_power_params_req_msg msg_body;
1707 mutex_lock(&wcn->hal_mutex);
1708 INIT_HAL_MSG(msg_body, WCN36XX_HAL_SET_POWER_PARAMS_REQ);
1711 * When host is down ignore every second dtim
1714 msg_body.ignore_dtim = 1;
1715 msg_body.dtim_period = 2;
1717 msg_body.listen_interval = WCN36XX_LISTEN_INTERVAL(wcn);
1719 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1721 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1723 wcn36xx_err("Sending hal_set_power_params failed\n");
1728 mutex_unlock(&wcn->hal_mutex);
1731 /* Notice: This function should be called after associated, or else it
1734 int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
1735 struct ieee80211_vif *vif,
1738 struct wcn36xx_hal_keep_alive_req_msg msg_body;
1739 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
1742 mutex_lock(&wcn->hal_mutex);
1743 INIT_HAL_MSG(msg_body, WCN36XX_HAL_KEEP_ALIVE_REQ);
1745 if (packet_type == WCN36XX_HAL_KEEP_ALIVE_NULL_PKT) {
1746 msg_body.bss_index = vif_priv->bss_index;
1747 msg_body.packet_type = WCN36XX_HAL_KEEP_ALIVE_NULL_PKT;
1748 msg_body.time_period = WCN36XX_KEEP_ALIVE_TIME_PERIOD;
1749 } else if (packet_type == WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP) {
1750 /* TODO: it also support ARP response type */
1752 wcn36xx_warn("unknown keep alive packet type %d\n", packet_type);
1757 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1759 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1761 wcn36xx_err("Sending hal_keep_alive failed\n");
1764 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1766 wcn36xx_err("hal_keep_alive response failed err=%d\n", ret);
1770 mutex_unlock(&wcn->hal_mutex);
1774 int wcn36xx_smd_dump_cmd_req(struct wcn36xx *wcn, u32 arg1, u32 arg2,
1775 u32 arg3, u32 arg4, u32 arg5)
1777 struct wcn36xx_hal_dump_cmd_req_msg msg_body;
1780 mutex_lock(&wcn->hal_mutex);
1781 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DUMP_COMMAND_REQ);
1783 msg_body.arg1 = arg1;
1784 msg_body.arg2 = arg2;
1785 msg_body.arg3 = arg3;
1786 msg_body.arg4 = arg4;
1787 msg_body.arg5 = arg5;
1789 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1791 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1793 wcn36xx_err("Sending hal_dump_cmd failed\n");
1796 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1798 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret);
1802 mutex_unlock(&wcn->hal_mutex);
1806 void set_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1808 int arr_idx, bit_idx;
1810 if (cap < 0 || cap > 127) {
1811 wcn36xx_warn("error cap idx %d\n", cap);
1817 bitmap[arr_idx] |= (1 << bit_idx);
1820 int get_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1822 int arr_idx, bit_idx;
1825 if (cap < 0 || cap > 127) {
1826 wcn36xx_warn("error cap idx %d\n", cap);
1832 ret = (bitmap[arr_idx] & (1 << bit_idx)) ? 1 : 0;
1836 void clear_feat_caps(u32 *bitmap, enum place_holder_in_cap_bitmap cap)
1838 int arr_idx, bit_idx;
1840 if (cap < 0 || cap > 127) {
1841 wcn36xx_warn("error cap idx %d\n", cap);
1847 bitmap[arr_idx] &= ~(1 << bit_idx);
1850 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx *wcn)
1852 struct wcn36xx_hal_feat_caps_msg msg_body, *rsp;
1855 mutex_lock(&wcn->hal_mutex);
1856 INIT_HAL_MSG(msg_body, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ);
1858 set_feat_caps(msg_body.feat_caps, STA_POWERSAVE);
1860 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1862 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1864 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1867 if (wcn->hal_rsp_len != sizeof(*rsp)) {
1868 wcn36xx_err("Invalid hal_feature_caps_exchange response");
1872 rsp = (struct wcn36xx_hal_feat_caps_msg *) wcn->hal_buf;
1874 for (i = 0; i < WCN36XX_HAL_CAPS_SIZE; i++)
1875 wcn->fw_feat_caps[i] = rsp->feat_caps[i];
1877 mutex_unlock(&wcn->hal_mutex);
1881 int wcn36xx_smd_add_ba_session(struct wcn36xx *wcn,
1882 struct ieee80211_sta *sta,
1888 struct wcn36xx_hal_add_ba_session_req_msg msg_body;
1891 mutex_lock(&wcn->hal_mutex);
1892 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_SESSION_REQ);
1894 msg_body.sta_index = sta_index;
1895 memcpy(&msg_body.mac_addr, sta->addr, ETH_ALEN);
1896 msg_body.dialog_token = 0x10;
1899 /* Immediate BA because Delayed BA is not supported */
1900 msg_body.policy = 1;
1901 msg_body.buffer_size = WCN36XX_AGGR_BUFFER_SIZE;
1902 msg_body.timeout = 0;
1904 msg_body.ssn = *ssn;
1905 msg_body.direction = direction;
1907 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1909 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1911 wcn36xx_err("Sending hal_add_ba_session failed\n");
1914 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1916 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret);
1920 mutex_unlock(&wcn->hal_mutex);
1924 int wcn36xx_smd_add_ba(struct wcn36xx *wcn)
1926 struct wcn36xx_hal_add_ba_req_msg msg_body;
1929 mutex_lock(&wcn->hal_mutex);
1930 INIT_HAL_MSG(msg_body, WCN36XX_HAL_ADD_BA_REQ);
1932 msg_body.session_id = 0;
1933 msg_body.win_size = WCN36XX_AGGR_BUFFER_SIZE;
1935 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1937 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1939 wcn36xx_err("Sending hal_add_ba failed\n");
1942 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1944 wcn36xx_err("hal_add_ba response failed err=%d\n", ret);
1948 mutex_unlock(&wcn->hal_mutex);
1952 int wcn36xx_smd_del_ba(struct wcn36xx *wcn, u16 tid, u8 sta_index)
1954 struct wcn36xx_hal_del_ba_req_msg msg_body;
1957 mutex_lock(&wcn->hal_mutex);
1958 INIT_HAL_MSG(msg_body, WCN36XX_HAL_DEL_BA_REQ);
1960 msg_body.sta_index = sta_index;
1962 msg_body.direction = 0;
1963 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
1965 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
1967 wcn36xx_err("Sending hal_del_ba failed\n");
1970 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
1972 wcn36xx_err("hal_del_ba response failed err=%d\n", ret);
1976 mutex_unlock(&wcn->hal_mutex);
1980 static int wcn36xx_smd_trigger_ba_rsp(void *buf, int len)
1982 struct wcn36xx_hal_trigger_ba_rsp_msg *rsp;
1984 if (len < sizeof(*rsp))
1987 rsp = (struct wcn36xx_hal_trigger_ba_rsp_msg *) buf;
1991 int wcn36xx_smd_trigger_ba(struct wcn36xx *wcn, u8 sta_index)
1993 struct wcn36xx_hal_trigger_ba_req_msg msg_body;
1994 struct wcn36xx_hal_trigger_ba_req_candidate *candidate;
1997 mutex_lock(&wcn->hal_mutex);
1998 INIT_HAL_MSG(msg_body, WCN36XX_HAL_TRIGGER_BA_REQ);
2000 msg_body.session_id = 0;
2001 msg_body.candidate_cnt = 1;
2002 msg_body.header.len += sizeof(*candidate);
2003 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
2005 candidate = (struct wcn36xx_hal_trigger_ba_req_candidate *)
2006 (wcn->hal_buf + sizeof(msg_body));
2007 candidate->sta_index = sta_index;
2008 candidate->tid_bitmap = 1;
2010 ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
2012 wcn36xx_err("Sending hal_trigger_ba failed\n");
2015 ret = wcn36xx_smd_trigger_ba_rsp(wcn->hal_buf, wcn->hal_rsp_len);
2017 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret);
2021 mutex_unlock(&wcn->hal_mutex);
2025 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
2027 struct wcn36xx_hal_tx_compl_ind_msg *rsp = buf;
2029 if (len != sizeof(*rsp)) {
2030 wcn36xx_warn("Bad TX complete indication\n");
2034 wcn36xx_dxe_tx_ack_ind(wcn, rsp->status);
2039 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
2043 struct wcn36xx_hal_missed_beacon_ind_msg *rsp = buf;
2044 struct ieee80211_vif *vif = NULL;
2045 struct wcn36xx_vif *tmp;
2047 /* Old FW does not have bss index */
2048 if (wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
2049 list_for_each_entry(tmp, &wcn->vif_list, list) {
2050 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
2052 vif = wcn36xx_priv_to_vif(tmp);
2053 ieee80211_connection_loss(vif);
2058 if (len != sizeof(*rsp)) {
2059 wcn36xx_warn("Corrupted missed beacon indication\n");
2063 list_for_each_entry(tmp, &wcn->vif_list, list) {
2064 if (tmp->bss_index == rsp->bss_index) {
2065 wcn36xx_dbg(WCN36XX_DBG_HAL, "beacon missed bss_index %d\n",
2067 vif = wcn36xx_priv_to_vif(tmp);
2068 ieee80211_connection_loss(vif);
2073 wcn36xx_warn("BSS index %d not found\n", rsp->bss_index);
2077 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx *wcn,
2081 struct wcn36xx_hal_delete_sta_context_ind_msg *rsp = buf;
2082 struct wcn36xx_vif *tmp;
2083 struct ieee80211_sta *sta;
2085 if (len != sizeof(*rsp)) {
2086 wcn36xx_warn("Corrupted delete sta indication\n");
2090 wcn36xx_dbg(WCN36XX_DBG_HAL, "delete station indication %pM index %d\n",
2091 rsp->addr2, rsp->sta_id);
2093 list_for_each_entry(tmp, &wcn->vif_list, list) {
2095 sta = ieee80211_find_sta(wcn36xx_priv_to_vif(tmp), rsp->addr2);
2097 ieee80211_report_low_ack(sta, 0);
2103 wcn36xx_warn("STA with addr %pM and index %d not found\n",
2109 int wcn36xx_smd_update_cfg(struct wcn36xx *wcn, u32 cfg_id, u32 value)
2111 struct wcn36xx_hal_update_cfg_req_msg msg_body, *body;
2115 mutex_lock(&wcn->hal_mutex);
2116 INIT_HAL_MSG(msg_body, WCN36XX_HAL_UPDATE_CFG_REQ);
2118 PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
2120 body = (struct wcn36xx_hal_update_cfg_req_msg *) wcn->hal_buf;
2121 len = msg_body.header.len;
2123 put_cfg_tlv_u32(wcn, &len, cfg_id, value);
2124 body->header.len = len;
2125 body->len = len - sizeof(*body);
2127 ret = wcn36xx_smd_send_and_wait(wcn, body->header.len);
2129 wcn36xx_err("Sending hal_update_cfg failed\n");
2132 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
2134 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret);
2138 mutex_unlock(&wcn->hal_mutex);
2142 int wcn36xx_smd_set_mc_list(struct wcn36xx *wcn,
2143 struct ieee80211_vif *vif,
2144 struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp)
2146 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
2147 struct wcn36xx_hal_rcv_flt_pkt_set_mc_list_req_msg *msg_body = NULL;
2150 mutex_lock(&wcn->hal_mutex);
2152 msg_body = (struct wcn36xx_hal_rcv_flt_pkt_set_mc_list_req_msg *)
2154 init_hal_msg(&msg_body->header, WCN36XX_HAL_8023_MULTICAST_LIST_REQ,
2155 sizeof(msg_body->mc_addr_list));
2157 /* An empty list means all mc traffic will be received */
2159 memcpy(&msg_body->mc_addr_list, fp,
2160 sizeof(msg_body->mc_addr_list));
2162 msg_body->mc_addr_list.mc_addr_count = 0;
2164 msg_body->mc_addr_list.bss_index = vif_priv->bss_index;
2166 ret = wcn36xx_smd_send_and_wait(wcn, msg_body->header.len);
2168 wcn36xx_err("Sending HAL_8023_MULTICAST_LIST failed\n");
2171 ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
2173 wcn36xx_err("HAL_8023_MULTICAST_LIST rsp failed err=%d\n", ret);
2177 mutex_unlock(&wcn->hal_mutex);
2181 static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
2183 struct wcn36xx_hal_msg_header *msg_header = buf;
2184 struct wcn36xx_hal_ind_msg *msg_ind;
2185 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP, "SMD <<< ", buf, len);
2187 switch (msg_header->msg_type) {
2188 case WCN36XX_HAL_START_RSP:
2189 case WCN36XX_HAL_CONFIG_STA_RSP:
2190 case WCN36XX_HAL_CONFIG_BSS_RSP:
2191 case WCN36XX_HAL_ADD_STA_SELF_RSP:
2192 case WCN36XX_HAL_STOP_RSP:
2193 case WCN36XX_HAL_DEL_STA_SELF_RSP:
2194 case WCN36XX_HAL_DELETE_STA_RSP:
2195 case WCN36XX_HAL_INIT_SCAN_RSP:
2196 case WCN36XX_HAL_START_SCAN_RSP:
2197 case WCN36XX_HAL_END_SCAN_RSP:
2198 case WCN36XX_HAL_FINISH_SCAN_RSP:
2199 case WCN36XX_HAL_DOWNLOAD_NV_RSP:
2200 case WCN36XX_HAL_DELETE_BSS_RSP:
2201 case WCN36XX_HAL_SEND_BEACON_RSP:
2202 case WCN36XX_HAL_SET_LINK_ST_RSP:
2203 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP:
2204 case WCN36XX_HAL_SET_BSSKEY_RSP:
2205 case WCN36XX_HAL_SET_STAKEY_RSP:
2206 case WCN36XX_HAL_RMV_STAKEY_RSP:
2207 case WCN36XX_HAL_RMV_BSSKEY_RSP:
2208 case WCN36XX_HAL_ENTER_BMPS_RSP:
2209 case WCN36XX_HAL_SET_POWER_PARAMS_RSP:
2210 case WCN36XX_HAL_EXIT_BMPS_RSP:
2211 case WCN36XX_HAL_KEEP_ALIVE_RSP:
2212 case WCN36XX_HAL_DUMP_COMMAND_RSP:
2213 case WCN36XX_HAL_ADD_BA_SESSION_RSP:
2214 case WCN36XX_HAL_ADD_BA_RSP:
2215 case WCN36XX_HAL_DEL_BA_RSP:
2216 case WCN36XX_HAL_TRIGGER_BA_RSP:
2217 case WCN36XX_HAL_UPDATE_CFG_RSP:
2218 case WCN36XX_HAL_JOIN_RSP:
2219 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP:
2220 case WCN36XX_HAL_CH_SWITCH_RSP:
2221 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
2222 case WCN36XX_HAL_8023_MULTICAST_LIST_RSP:
2223 memcpy(wcn->hal_buf, buf, len);
2224 wcn->hal_rsp_len = len;
2225 complete(&wcn->hal_rsp_compl);
2228 case WCN36XX_HAL_DEL_BA_IND:
2229 case WCN36XX_HAL_PRINT_REG_INFO_IND:
2230 case WCN36XX_HAL_COEX_IND:
2231 case WCN36XX_HAL_AVOID_FREQ_RANGE_IND:
2232 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2233 case WCN36XX_HAL_MISSED_BEACON_IND:
2234 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2235 msg_ind = kmalloc(sizeof(*msg_ind), GFP_KERNEL);
2238 msg_ind->msg_len = len;
2239 msg_ind->msg = kmemdup(buf, len, GFP_KERNEL);
2240 if (!msg_ind->msg) {
2244 * FIXME: Do something smarter then just
2245 * printing an error.
2247 wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
2248 msg_header->msg_type);
2251 mutex_lock(&wcn->hal_ind_mutex);
2252 list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
2253 queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
2254 mutex_unlock(&wcn->hal_ind_mutex);
2255 wcn36xx_dbg(WCN36XX_DBG_HAL, "indication arrived\n");
2258 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2259 msg_header->msg_type);
2262 static void wcn36xx_ind_smd_work(struct work_struct *work)
2264 struct wcn36xx *wcn =
2265 container_of(work, struct wcn36xx, hal_ind_work);
2266 struct wcn36xx_hal_msg_header *msg_header;
2267 struct wcn36xx_hal_ind_msg *hal_ind_msg;
2269 mutex_lock(&wcn->hal_ind_mutex);
2271 hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
2272 struct wcn36xx_hal_ind_msg,
2275 msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
2277 switch (msg_header->msg_type) {
2278 case WCN36XX_HAL_DEL_BA_IND:
2279 case WCN36XX_HAL_PRINT_REG_INFO_IND:
2280 case WCN36XX_HAL_COEX_IND:
2281 case WCN36XX_HAL_AVOID_FREQ_RANGE_IND:
2283 case WCN36XX_HAL_OTA_TX_COMPL_IND:
2284 wcn36xx_smd_tx_compl_ind(wcn,
2286 hal_ind_msg->msg_len);
2288 case WCN36XX_HAL_MISSED_BEACON_IND:
2289 wcn36xx_smd_missed_beacon_ind(wcn,
2291 hal_ind_msg->msg_len);
2293 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
2294 wcn36xx_smd_delete_sta_context_ind(wcn,
2296 hal_ind_msg->msg_len);
2299 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2300 msg_header->msg_type);
2302 list_del(wcn->hal_ind_queue.next);
2303 kfree(hal_ind_msg->msg);
2305 mutex_unlock(&wcn->hal_ind_mutex);
2307 int wcn36xx_smd_open(struct wcn36xx *wcn)
2310 wcn->hal_ind_wq = create_freezable_workqueue("wcn36xx_smd_ind");
2311 if (!wcn->hal_ind_wq) {
2312 wcn36xx_err("failed to allocate wq\n");
2316 INIT_WORK(&wcn->hal_ind_work, wcn36xx_ind_smd_work);
2317 INIT_LIST_HEAD(&wcn->hal_ind_queue);
2318 mutex_init(&wcn->hal_ind_mutex);
2320 ret = wcn->ctrl_ops->open(wcn, wcn36xx_smd_rsp_process);
2322 wcn36xx_err("failed to open control channel\n");
2329 destroy_workqueue(wcn->hal_ind_wq);
2334 void wcn36xx_smd_close(struct wcn36xx *wcn)
2336 wcn->ctrl_ops->close(wcn);
2337 destroy_workqueue(wcn->hal_ind_wq);
2338 mutex_destroy(&wcn->hal_ind_mutex);