2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/etherdevice.h>
20 #include <linux/firmware.h>
21 #include <linux/bitops.h>
24 static int put_cfg_tlv_u32(struct wcn36xx
*wcn
, size_t *len
, u32 id
, u32 value
)
26 struct wcn36xx_hal_cfg
*entry
;
29 if (*len
+ sizeof(*entry
) + sizeof(u32
) >= WCN36XX_HAL_BUF_SIZE
) {
30 wcn36xx_err("Not enough room for TLV entry\n");
34 entry
= (struct wcn36xx_hal_cfg
*) (wcn
->hal_buf
+ *len
);
36 entry
->len
= sizeof(u32
);
40 val
= (u32
*) (entry
+ 1);
43 *len
+= sizeof(*entry
) + sizeof(u32
);
48 static void wcn36xx_smd_set_bss_nw_type(struct wcn36xx
*wcn
,
49 struct ieee80211_sta
*sta
,
50 struct wcn36xx_hal_config_bss_params
*bss_params
)
52 if (IEEE80211_BAND_5GHZ
== WCN36XX_BAND(wcn
))
53 bss_params
->nw_type
= WCN36XX_HAL_11A_NW_TYPE
;
54 else if (sta
&& sta
->ht_cap
.ht_supported
)
55 bss_params
->nw_type
= WCN36XX_HAL_11N_NW_TYPE
;
56 else if (sta
&& (sta
->supp_rates
[IEEE80211_BAND_2GHZ
] & 0x7f))
57 bss_params
->nw_type
= WCN36XX_HAL_11G_NW_TYPE
;
59 bss_params
->nw_type
= WCN36XX_HAL_11B_NW_TYPE
;
62 static inline u8
is_cap_supported(unsigned long caps
, unsigned long flag
)
64 return caps
& flag
? 1 : 0;
66 static void wcn36xx_smd_set_bss_ht_params(struct ieee80211_vif
*vif
,
67 struct ieee80211_sta
*sta
,
68 struct wcn36xx_hal_config_bss_params
*bss_params
)
70 if (sta
&& sta
->ht_cap
.ht_supported
) {
71 unsigned long caps
= sta
->ht_cap
.cap
;
72 bss_params
->ht
= sta
->ht_cap
.ht_supported
;
73 bss_params
->tx_channel_width_set
= is_cap_supported(caps
,
74 IEEE80211_HT_CAP_SUP_WIDTH_20_40
);
75 bss_params
->lsig_tx_op_protection_full_support
=
76 is_cap_supported(caps
,
77 IEEE80211_HT_CAP_LSIG_TXOP_PROT
);
79 bss_params
->ht_oper_mode
= vif
->bss_conf
.ht_operation_mode
;
80 bss_params
->lln_non_gf_coexist
=
81 !!(vif
->bss_conf
.ht_operation_mode
&
82 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
83 /* IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT */
84 bss_params
->dual_cts_protection
= 0;
85 /* IEEE80211_HT_OP_MODE_PROTECTION_20MHZ */
86 bss_params
->ht20_coexist
= 0;
90 static void wcn36xx_smd_set_sta_ht_params(struct ieee80211_sta
*sta
,
91 struct wcn36xx_hal_config_sta_params
*sta_params
)
93 if (sta
->ht_cap
.ht_supported
) {
94 unsigned long caps
= sta
->ht_cap
.cap
;
95 sta_params
->ht_capable
= sta
->ht_cap
.ht_supported
;
96 sta_params
->tx_channel_width_set
= is_cap_supported(caps
,
97 IEEE80211_HT_CAP_SUP_WIDTH_20_40
);
98 sta_params
->lsig_txop_protection
= is_cap_supported(caps
,
99 IEEE80211_HT_CAP_LSIG_TXOP_PROT
);
101 sta_params
->max_ampdu_size
= sta
->ht_cap
.ampdu_factor
;
102 sta_params
->max_ampdu_density
= sta
->ht_cap
.ampdu_density
;
103 sta_params
->max_amsdu_size
= is_cap_supported(caps
,
104 IEEE80211_HT_CAP_MAX_AMSDU
);
105 sta_params
->sgi_20Mhz
= is_cap_supported(caps
,
106 IEEE80211_HT_CAP_SGI_20
);
107 sta_params
->sgi_40mhz
= is_cap_supported(caps
,
108 IEEE80211_HT_CAP_SGI_40
);
109 sta_params
->green_field_capable
= is_cap_supported(caps
,
110 IEEE80211_HT_CAP_GRN_FLD
);
111 sta_params
->delayed_ba_support
= is_cap_supported(caps
,
112 IEEE80211_HT_CAP_DELAY_BA
);
113 sta_params
->dsss_cck_mode_40mhz
= is_cap_supported(caps
,
114 IEEE80211_HT_CAP_DSSSCCK40
);
118 static void wcn36xx_smd_set_sta_default_ht_params(
119 struct wcn36xx_hal_config_sta_params
*sta_params
)
121 sta_params
->ht_capable
= 1;
122 sta_params
->tx_channel_width_set
= 1;
123 sta_params
->lsig_txop_protection
= 1;
124 sta_params
->max_ampdu_size
= 3;
125 sta_params
->max_ampdu_density
= 5;
126 sta_params
->max_amsdu_size
= 0;
127 sta_params
->sgi_20Mhz
= 1;
128 sta_params
->sgi_40mhz
= 1;
129 sta_params
->green_field_capable
= 1;
130 sta_params
->delayed_ba_support
= 0;
131 sta_params
->dsss_cck_mode_40mhz
= 1;
134 static void wcn36xx_smd_set_sta_params(struct wcn36xx
*wcn
,
135 struct ieee80211_vif
*vif
,
136 struct ieee80211_sta
*sta
,
137 struct wcn36xx_hal_config_sta_params
*sta_params
)
139 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
140 struct wcn36xx_sta
*priv_sta
= NULL
;
141 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
142 vif
->type
== NL80211_IFTYPE_AP
||
143 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
144 sta_params
->type
= 1;
145 sta_params
->sta_index
= 0xFF;
147 sta_params
->type
= 0;
148 sta_params
->sta_index
= 1;
151 sta_params
->listen_interval
= WCN36XX_LISTEN_INTERVAL(wcn
);
154 * In STA mode ieee80211_sta contains bssid and ieee80211_vif
155 * contains our mac address. In AP mode we are bssid so vif
156 * contains bssid and ieee80211_sta contains mac.
158 if (NL80211_IFTYPE_STATION
== vif
->type
)
159 memcpy(&sta_params
->mac
, vif
->addr
, ETH_ALEN
);
161 memcpy(&sta_params
->bssid
, vif
->addr
, ETH_ALEN
);
163 sta_params
->encrypt_type
= priv_vif
->encrypt_type
;
164 sta_params
->short_preamble_supported
=
165 !(WCN36XX_FLAGS(wcn
) &
166 IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
);
168 sta_params
->rifs_mode
= 0;
170 sta_params
->action
= 0;
171 sta_params
->uapsd
= 0;
172 sta_params
->mimo_ps
= WCN36XX_HAL_HT_MIMO_PS_STATIC
;
173 sta_params
->max_ampdu_duration
= 0;
174 sta_params
->bssid_index
= priv_vif
->bss_index
;
178 priv_sta
= (struct wcn36xx_sta
*)sta
->drv_priv
;
179 if (NL80211_IFTYPE_STATION
== vif
->type
)
180 memcpy(&sta_params
->bssid
, sta
->addr
, ETH_ALEN
);
182 memcpy(&sta_params
->mac
, sta
->addr
, ETH_ALEN
);
183 sta_params
->wmm_enabled
= sta
->wme
;
184 sta_params
->max_sp_len
= sta
->max_sp
;
185 sta_params
->aid
= priv_sta
->aid
;
186 wcn36xx_smd_set_sta_ht_params(sta
, sta_params
);
187 memcpy(&sta_params
->supported_rates
, &priv_sta
->supported_rates
,
188 sizeof(priv_sta
->supported_rates
));
190 wcn36xx_set_default_rates(&sta_params
->supported_rates
);
191 wcn36xx_smd_set_sta_default_ht_params(sta_params
);
195 static int wcn36xx_smd_send_and_wait(struct wcn36xx
*wcn
, size_t len
)
198 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP
, "HAL >>> ", wcn
->hal_buf
, len
);
200 init_completion(&wcn
->hal_rsp_compl
);
201 ret
= wcn
->ctrl_ops
->tx(wcn
->hal_buf
, len
);
203 wcn36xx_err("HAL TX failed\n");
206 if (wait_for_completion_timeout(&wcn
->hal_rsp_compl
,
207 msecs_to_jiffies(HAL_MSG_TIMEOUT
)) <= 0) {
208 wcn36xx_err("Timeout while waiting SMD response\n");
216 #define INIT_HAL_MSG(msg_body, type) \
218 memset(&msg_body, 0, sizeof(msg_body)); \
219 msg_body.header.msg_type = type; \
220 msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
221 msg_body.header.len = sizeof(msg_body); \
224 #define PREPARE_HAL_BUF(send_buf, msg_body) \
226 memset(send_buf, 0, msg_body.header.len); \
227 memcpy(send_buf, &msg_body, sizeof(msg_body)); \
230 static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
232 struct wcn36xx_fw_msg_status_rsp
*rsp
;
234 if (len
< sizeof(struct wcn36xx_hal_msg_header
) +
235 sizeof(struct wcn36xx_fw_msg_status_rsp
))
238 rsp
= (struct wcn36xx_fw_msg_status_rsp
*)
239 (buf
+ sizeof(struct wcn36xx_hal_msg_header
));
241 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->status
)
247 int wcn36xx_smd_load_nv(struct wcn36xx
*wcn
)
249 const struct firmware
*nv
;
250 struct nv_data
*nv_d
;
251 struct wcn36xx_hal_nv_img_download_req_msg msg_body
;
256 ret
= request_firmware(&nv
, WLAN_NV_FILE
, wcn
->dev
);
258 wcn36xx_err("Failed to load nv file %s: %d\n",
263 nv_d
= (struct nv_data
*)nv
->data
;
264 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DOWNLOAD_NV_REQ
);
266 msg_body
.header
.len
+= WCN36XX_NV_FRAGMENT_SIZE
;
268 msg_body
.frag_number
= 0;
269 /* hal_buf must be protected with mutex */
270 mutex_lock(&wcn
->hal_mutex
);
273 fw_bytes_left
= nv
->size
- fm_offset
- 4;
274 if (fw_bytes_left
> WCN36XX_NV_FRAGMENT_SIZE
) {
275 msg_body
.last_fragment
= 0;
276 msg_body
.nv_img_buffer_size
= WCN36XX_NV_FRAGMENT_SIZE
;
278 msg_body
.last_fragment
= 1;
279 msg_body
.nv_img_buffer_size
= fw_bytes_left
;
281 /* Do not forget update general message len */
282 msg_body
.header
.len
= sizeof(msg_body
) + fw_bytes_left
;
286 /* Add load NV request message header */
287 memcpy(wcn
->hal_buf
, &msg_body
, sizeof(msg_body
));
289 /* Add NV body itself */
290 memcpy(wcn
->hal_buf
+ sizeof(msg_body
),
291 &nv_d
->table
+ fm_offset
,
292 msg_body
.nv_img_buffer_size
);
294 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
297 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
,
300 wcn36xx_err("hal_load_nv response failed err=%d\n",
304 msg_body
.frag_number
++;
305 fm_offset
+= WCN36XX_NV_FRAGMENT_SIZE
;
307 } while (msg_body
.last_fragment
!= 1);
310 mutex_unlock(&wcn
->hal_mutex
);
312 release_firmware(nv
);
317 static int wcn36xx_smd_start_rsp(struct wcn36xx
*wcn
, void *buf
, size_t len
)
319 struct wcn36xx_hal_mac_start_rsp_msg
*rsp
;
321 if (len
< sizeof(*rsp
))
324 rsp
= (struct wcn36xx_hal_mac_start_rsp_msg
*)buf
;
326 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->start_rsp_params
.status
)
329 memcpy(wcn
->crm_version
, rsp
->start_rsp_params
.crm_version
,
330 WCN36XX_HAL_VERSION_LENGTH
);
331 memcpy(wcn
->wlan_version
, rsp
->start_rsp_params
.wlan_version
,
332 WCN36XX_HAL_VERSION_LENGTH
);
334 /* null terminate the strings, just in case */
335 wcn
->crm_version
[WCN36XX_HAL_VERSION_LENGTH
] = '\0';
336 wcn
->wlan_version
[WCN36XX_HAL_VERSION_LENGTH
] = '\0';
338 wcn
->fw_revision
= rsp
->start_rsp_params
.version
.revision
;
339 wcn
->fw_version
= rsp
->start_rsp_params
.version
.version
;
340 wcn
->fw_minor
= rsp
->start_rsp_params
.version
.minor
;
341 wcn
->fw_major
= rsp
->start_rsp_params
.version
.major
;
343 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
344 wcn
->wlan_version
, wcn
->crm_version
);
346 wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
347 wcn
->fw_major
, wcn
->fw_minor
,
348 wcn
->fw_version
, wcn
->fw_revision
,
349 rsp
->start_rsp_params
.stations
,
350 rsp
->start_rsp_params
.bssids
);
355 int wcn36xx_smd_start(struct wcn36xx
*wcn
)
357 struct wcn36xx_hal_mac_start_req_msg msg_body
;
360 mutex_lock(&wcn
->hal_mutex
);
361 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_START_REQ
);
363 msg_body
.params
.type
= DRIVER_TYPE_PRODUCTION
;
364 msg_body
.params
.len
= 0;
366 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
368 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal start type %d\n",
369 msg_body
.params
.type
);
371 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
373 wcn36xx_err("Sending hal_start failed\n");
377 ret
= wcn36xx_smd_start_rsp(wcn
, wcn
->hal_buf
, wcn
->hal_rsp_len
);
379 wcn36xx_err("hal_start response failed err=%d\n", ret
);
384 mutex_unlock(&wcn
->hal_mutex
);
388 int wcn36xx_smd_stop(struct wcn36xx
*wcn
)
390 struct wcn36xx_hal_mac_stop_req_msg msg_body
;
393 mutex_lock(&wcn
->hal_mutex
);
394 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_STOP_REQ
);
396 msg_body
.stop_req_params
.reason
= HAL_STOP_TYPE_RF_KILL
;
398 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
400 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
402 wcn36xx_err("Sending hal_stop failed\n");
405 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
407 wcn36xx_err("hal_stop response failed err=%d\n", ret
);
411 mutex_unlock(&wcn
->hal_mutex
);
415 int wcn36xx_smd_init_scan(struct wcn36xx
*wcn
, enum wcn36xx_hal_sys_mode mode
)
417 struct wcn36xx_hal_init_scan_req_msg msg_body
;
420 mutex_lock(&wcn
->hal_mutex
);
421 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_INIT_SCAN_REQ
);
423 msg_body
.mode
= mode
;
425 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
427 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal init scan mode %d\n", msg_body
.mode
);
429 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
431 wcn36xx_err("Sending hal_init_scan failed\n");
434 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
436 wcn36xx_err("hal_init_scan response failed err=%d\n", ret
);
440 mutex_unlock(&wcn
->hal_mutex
);
444 int wcn36xx_smd_start_scan(struct wcn36xx
*wcn
)
446 struct wcn36xx_hal_start_scan_req_msg msg_body
;
449 mutex_lock(&wcn
->hal_mutex
);
450 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_START_SCAN_REQ
);
452 msg_body
.scan_channel
= WCN36XX_HW_CHANNEL(wcn
);
454 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
456 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal start scan channel %d\n",
457 msg_body
.scan_channel
);
459 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
461 wcn36xx_err("Sending hal_start_scan failed\n");
464 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
466 wcn36xx_err("hal_start_scan response failed err=%d\n", ret
);
470 mutex_unlock(&wcn
->hal_mutex
);
474 int wcn36xx_smd_end_scan(struct wcn36xx
*wcn
)
476 struct wcn36xx_hal_end_scan_req_msg msg_body
;
479 mutex_lock(&wcn
->hal_mutex
);
480 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_END_SCAN_REQ
);
482 msg_body
.scan_channel
= WCN36XX_HW_CHANNEL(wcn
);
484 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
486 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal end scan channel %d\n",
487 msg_body
.scan_channel
);
489 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
491 wcn36xx_err("Sending hal_end_scan failed\n");
494 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
496 wcn36xx_err("hal_end_scan response failed err=%d\n", ret
);
500 mutex_unlock(&wcn
->hal_mutex
);
504 int wcn36xx_smd_finish_scan(struct wcn36xx
*wcn
,
505 enum wcn36xx_hal_sys_mode mode
)
507 struct wcn36xx_hal_finish_scan_req_msg msg_body
;
510 mutex_lock(&wcn
->hal_mutex
);
511 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_FINISH_SCAN_REQ
);
513 msg_body
.mode
= mode
;
515 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
517 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal finish scan mode %d\n",
520 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
522 wcn36xx_err("Sending hal_finish_scan failed\n");
525 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
527 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret
);
531 mutex_unlock(&wcn
->hal_mutex
);
535 static int wcn36xx_smd_switch_channel_rsp(void *buf
, size_t len
)
537 struct wcn36xx_hal_switch_channel_rsp_msg
*rsp
;
540 ret
= wcn36xx_smd_rsp_status_check(buf
, len
);
543 rsp
= (struct wcn36xx_hal_switch_channel_rsp_msg
*)buf
;
544 wcn36xx_dbg(WCN36XX_DBG_HAL
, "channel switched to: %d, status: %d\n",
545 rsp
->channel_number
, rsp
->status
);
549 int wcn36xx_smd_switch_channel(struct wcn36xx
*wcn
,
550 struct ieee80211_vif
*vif
, int ch
)
552 struct wcn36xx_hal_switch_channel_req_msg msg_body
;
555 mutex_lock(&wcn
->hal_mutex
);
556 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CH_SWITCH_REQ
);
558 msg_body
.channel_number
= (u8
)ch
;
559 msg_body
.tx_mgmt_power
= 0xbf;
560 msg_body
.max_tx_power
= 0xbf;
561 memcpy(msg_body
.self_sta_mac_addr
, vif
->addr
, ETH_ALEN
);
563 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
565 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
567 wcn36xx_err("Sending hal_switch_channel failed\n");
570 ret
= wcn36xx_smd_switch_channel_rsp(wcn
->hal_buf
, wcn
->hal_rsp_len
);
572 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret
);
576 mutex_unlock(&wcn
->hal_mutex
);
580 static int wcn36xx_smd_update_scan_params_rsp(void *buf
, size_t len
)
582 struct wcn36xx_hal_update_scan_params_resp
*rsp
;
584 rsp
= (struct wcn36xx_hal_update_scan_params_resp
*)buf
;
586 /* Remove the PNO version bit */
587 rsp
->status
&= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK
));
589 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->status
) {
590 wcn36xx_warn("error response from update scan\n");
597 int wcn36xx_smd_update_scan_params(struct wcn36xx
*wcn
)
599 struct wcn36xx_hal_update_scan_params_req msg_body
;
602 mutex_lock(&wcn
->hal_mutex
);
603 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ
);
605 msg_body
.dot11d_enabled
= 0;
606 msg_body
.dot11d_resolved
= 0;
607 msg_body
.channel_count
= 26;
608 msg_body
.active_min_ch_time
= 60;
609 msg_body
.active_max_ch_time
= 120;
610 msg_body
.passive_min_ch_time
= 60;
611 msg_body
.passive_max_ch_time
= 110;
614 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
616 wcn36xx_dbg(WCN36XX_DBG_HAL
,
617 "hal update scan params channel_count %d\n",
618 msg_body
.channel_count
);
620 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
622 wcn36xx_err("Sending hal_update_scan_params failed\n");
625 ret
= wcn36xx_smd_update_scan_params_rsp(wcn
->hal_buf
,
628 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
633 mutex_unlock(&wcn
->hal_mutex
);
637 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx
*wcn
,
638 struct ieee80211_vif
*vif
,
642 struct wcn36xx_hal_add_sta_self_rsp_msg
*rsp
;
643 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
645 if (len
< sizeof(*rsp
))
648 rsp
= (struct wcn36xx_hal_add_sta_self_rsp_msg
*)buf
;
650 if (rsp
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
651 wcn36xx_warn("hal add sta self failure: %d\n",
656 wcn36xx_dbg(WCN36XX_DBG_HAL
,
657 "hal add sta self status %d self_sta_index %d dpu_index %d\n",
658 rsp
->status
, rsp
->self_sta_index
, rsp
->dpu_index
);
660 priv_vif
->self_sta_index
= rsp
->self_sta_index
;
661 priv_vif
->self_dpu_desc_index
= rsp
->dpu_index
;
666 int wcn36xx_smd_add_sta_self(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
668 struct wcn36xx_hal_add_sta_self_req msg_body
;
671 mutex_lock(&wcn
->hal_mutex
);
672 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_STA_SELF_REQ
);
674 memcpy(&msg_body
.self_addr
, vif
->addr
, ETH_ALEN
);
676 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
678 wcn36xx_dbg(WCN36XX_DBG_HAL
,
679 "hal add sta self self_addr %pM status %d\n",
680 msg_body
.self_addr
, msg_body
.status
);
682 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
684 wcn36xx_err("Sending hal_add_sta_self failed\n");
687 ret
= wcn36xx_smd_add_sta_self_rsp(wcn
,
692 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret
);
696 mutex_unlock(&wcn
->hal_mutex
);
700 int wcn36xx_smd_delete_sta_self(struct wcn36xx
*wcn
, u8
*addr
)
702 struct wcn36xx_hal_del_sta_self_req_msg msg_body
;
705 mutex_lock(&wcn
->hal_mutex
);
706 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DEL_STA_SELF_REQ
);
708 memcpy(&msg_body
.self_addr
, addr
, ETH_ALEN
);
710 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
712 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
714 wcn36xx_err("Sending hal_delete_sta_self failed\n");
717 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
719 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
724 mutex_unlock(&wcn
->hal_mutex
);
728 int wcn36xx_smd_delete_sta(struct wcn36xx
*wcn
, u8 sta_index
)
730 struct wcn36xx_hal_delete_sta_req_msg msg_body
;
733 mutex_lock(&wcn
->hal_mutex
);
734 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DELETE_STA_REQ
);
736 msg_body
.sta_index
= sta_index
;
738 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
740 wcn36xx_dbg(WCN36XX_DBG_HAL
,
741 "hal delete sta sta_index %d\n",
744 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
746 wcn36xx_err("Sending hal_delete_sta failed\n");
749 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
751 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret
);
755 mutex_unlock(&wcn
->hal_mutex
);
759 static int wcn36xx_smd_join_rsp(void *buf
, size_t len
)
761 struct wcn36xx_hal_join_rsp_msg
*rsp
;
763 if (wcn36xx_smd_rsp_status_check(buf
, len
))
766 rsp
= (struct wcn36xx_hal_join_rsp_msg
*)buf
;
768 wcn36xx_dbg(WCN36XX_DBG_HAL
,
769 "hal rsp join status %d tx_mgmt_power %d\n",
770 rsp
->status
, rsp
->tx_mgmt_power
);
775 int wcn36xx_smd_join(struct wcn36xx
*wcn
, const u8
*bssid
, u8
*vif
, u8 ch
)
777 struct wcn36xx_hal_join_req_msg msg_body
;
780 mutex_lock(&wcn
->hal_mutex
);
781 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_JOIN_REQ
);
783 memcpy(&msg_body
.bssid
, bssid
, ETH_ALEN
);
784 memcpy(&msg_body
.self_sta_mac_addr
, vif
, ETH_ALEN
);
785 msg_body
.channel
= ch
;
787 if (conf_is_ht40_minus(&wcn
->hw
->conf
))
788 msg_body
.secondary_channel_offset
=
789 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY
;
790 else if (conf_is_ht40_plus(&wcn
->hw
->conf
))
791 msg_body
.secondary_channel_offset
=
792 PHY_DOUBLE_CHANNEL_LOW_PRIMARY
;
794 msg_body
.secondary_channel_offset
=
795 PHY_SINGLE_CHANNEL_CENTERED
;
797 msg_body
.link_state
= WCN36XX_HAL_LINK_PREASSOC_STATE
;
799 msg_body
.max_tx_power
= 0xbf;
800 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
802 wcn36xx_dbg(WCN36XX_DBG_HAL
,
803 "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
804 msg_body
.bssid
, msg_body
.self_sta_mac_addr
,
805 msg_body
.channel
, msg_body
.link_state
);
807 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
809 wcn36xx_err("Sending hal_join failed\n");
812 ret
= wcn36xx_smd_join_rsp(wcn
->hal_buf
, wcn
->hal_rsp_len
);
814 wcn36xx_err("hal_join response failed err=%d\n", ret
);
818 mutex_unlock(&wcn
->hal_mutex
);
822 int wcn36xx_smd_set_link_st(struct wcn36xx
*wcn
, const u8
*bssid
,
824 enum wcn36xx_hal_link_state state
)
826 struct wcn36xx_hal_set_link_state_req_msg msg_body
;
829 mutex_lock(&wcn
->hal_mutex
);
830 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_LINK_ST_REQ
);
832 memcpy(&msg_body
.bssid
, bssid
, ETH_ALEN
);
833 memcpy(&msg_body
.self_mac_addr
, sta_mac
, ETH_ALEN
);
834 msg_body
.state
= state
;
836 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
838 wcn36xx_dbg(WCN36XX_DBG_HAL
,
839 "hal set link state bssid %pM self_mac_addr %pM state %d\n",
840 msg_body
.bssid
, msg_body
.self_mac_addr
, msg_body
.state
);
842 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
844 wcn36xx_err("Sending hal_set_link_st failed\n");
847 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
849 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret
);
853 mutex_unlock(&wcn
->hal_mutex
);
857 static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx
*wcn
,
858 const struct wcn36xx_hal_config_sta_params
*orig
,
859 struct wcn36xx_hal_config_sta_params_v1
*v1
)
861 /* convert orig to v1 format */
862 memcpy(&v1
->bssid
, orig
->bssid
, ETH_ALEN
);
863 memcpy(&v1
->mac
, orig
->mac
, ETH_ALEN
);
865 v1
->type
= orig
->type
;
866 v1
->listen_interval
= orig
->listen_interval
;
867 v1
->ht_capable
= orig
->ht_capable
;
869 v1
->max_ampdu_size
= orig
->max_ampdu_size
;
870 v1
->max_ampdu_density
= orig
->max_ampdu_density
;
871 v1
->sgi_40mhz
= orig
->sgi_40mhz
;
872 v1
->sgi_20Mhz
= orig
->sgi_20Mhz
;
874 memcpy(&v1
->supported_rates
, &orig
->supported_rates
,
875 sizeof(orig
->supported_rates
));
876 v1
->sta_index
= orig
->sta_index
;
879 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx
*wcn
,
880 struct ieee80211_sta
*sta
,
884 struct wcn36xx_hal_config_sta_rsp_msg
*rsp
;
885 struct config_sta_rsp_params
*params
;
886 struct wcn36xx_sta
*sta_priv
= (struct wcn36xx_sta
*)sta
->drv_priv
;
888 if (len
< sizeof(*rsp
))
891 rsp
= (struct wcn36xx_hal_config_sta_rsp_msg
*)buf
;
892 params
= &rsp
->params
;
894 if (params
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
895 wcn36xx_warn("hal config sta response failure: %d\n",
900 sta_priv
->sta_index
= params
->sta_index
;
901 sta_priv
->dpu_desc_index
= params
->dpu_index
;
903 wcn36xx_dbg(WCN36XX_DBG_HAL
,
904 "hal config sta rsp status %d sta_index %d bssid_index %d p2p %d\n",
905 params
->status
, params
->sta_index
, params
->bssid_index
,
911 static int wcn36xx_smd_config_sta_v1(struct wcn36xx
*wcn
,
912 const struct wcn36xx_hal_config_sta_req_msg
*orig
)
914 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body
;
915 struct wcn36xx_hal_config_sta_params_v1
*sta
= &msg_body
.sta_params
;
917 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CONFIG_STA_REQ
);
919 wcn36xx_smd_convert_sta_to_v1(wcn
, &orig
->sta_params
,
920 &msg_body
.sta_params
);
922 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
924 wcn36xx_dbg(WCN36XX_DBG_HAL
,
925 "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
926 sta
->action
, sta
->sta_index
, sta
->bssid_index
,
927 sta
->bssid
, sta
->type
, sta
->mac
, sta
->aid
);
929 return wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
932 int wcn36xx_smd_config_sta(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
933 struct ieee80211_sta
*sta
)
935 struct wcn36xx_hal_config_sta_req_msg msg
;
936 struct wcn36xx_hal_config_sta_params
*sta_params
;
939 mutex_lock(&wcn
->hal_mutex
);
940 INIT_HAL_MSG(msg
, WCN36XX_HAL_CONFIG_STA_REQ
);
942 sta_params
= &msg
.sta_params
;
944 wcn36xx_smd_set_sta_params(wcn
, vif
, sta
, sta_params
);
946 if (!wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
947 ret
= wcn36xx_smd_config_sta_v1(wcn
, &msg
);
949 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
951 wcn36xx_dbg(WCN36XX_DBG_HAL
,
952 "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
953 sta_params
->action
, sta_params
->sta_index
,
954 sta_params
->bssid_index
, sta_params
->bssid
,
955 sta_params
->type
, sta_params
->mac
, sta_params
->aid
);
957 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
960 wcn36xx_err("Sending hal_config_sta failed\n");
963 ret
= wcn36xx_smd_config_sta_rsp(wcn
,
968 wcn36xx_err("hal_config_sta response failed err=%d\n", ret
);
972 mutex_unlock(&wcn
->hal_mutex
);
976 static int wcn36xx_smd_config_bss_v1(struct wcn36xx
*wcn
,
977 const struct wcn36xx_hal_config_bss_req_msg
*orig
)
979 struct wcn36xx_hal_config_bss_req_msg_v1 msg_body
;
980 struct wcn36xx_hal_config_bss_params_v1
*bss
= &msg_body
.bss_params
;
981 struct wcn36xx_hal_config_sta_params_v1
*sta
= &bss
->sta
;
983 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CONFIG_BSS_REQ
);
985 /* convert orig to v1 */
986 memcpy(&msg_body
.bss_params
.bssid
,
987 &orig
->bss_params
.bssid
, ETH_ALEN
);
988 memcpy(&msg_body
.bss_params
.self_mac_addr
,
989 &orig
->bss_params
.self_mac_addr
, ETH_ALEN
);
991 msg_body
.bss_params
.bss_type
= orig
->bss_params
.bss_type
;
992 msg_body
.bss_params
.oper_mode
= orig
->bss_params
.oper_mode
;
993 msg_body
.bss_params
.nw_type
= orig
->bss_params
.nw_type
;
995 msg_body
.bss_params
.short_slot_time_supported
=
996 orig
->bss_params
.short_slot_time_supported
;
997 msg_body
.bss_params
.lla_coexist
= orig
->bss_params
.lla_coexist
;
998 msg_body
.bss_params
.llb_coexist
= orig
->bss_params
.llb_coexist
;
999 msg_body
.bss_params
.llg_coexist
= orig
->bss_params
.llg_coexist
;
1000 msg_body
.bss_params
.ht20_coexist
= orig
->bss_params
.ht20_coexist
;
1001 msg_body
.bss_params
.lln_non_gf_coexist
=
1002 orig
->bss_params
.lln_non_gf_coexist
;
1004 msg_body
.bss_params
.lsig_tx_op_protection_full_support
=
1005 orig
->bss_params
.lsig_tx_op_protection_full_support
;
1006 msg_body
.bss_params
.rifs_mode
= orig
->bss_params
.rifs_mode
;
1007 msg_body
.bss_params
.beacon_interval
= orig
->bss_params
.beacon_interval
;
1008 msg_body
.bss_params
.dtim_period
= orig
->bss_params
.dtim_period
;
1009 msg_body
.bss_params
.tx_channel_width_set
=
1010 orig
->bss_params
.tx_channel_width_set
;
1011 msg_body
.bss_params
.oper_channel
= orig
->bss_params
.oper_channel
;
1012 msg_body
.bss_params
.ext_channel
= orig
->bss_params
.ext_channel
;
1014 msg_body
.bss_params
.reserved
= orig
->bss_params
.reserved
;
1016 memcpy(&msg_body
.bss_params
.ssid
,
1017 &orig
->bss_params
.ssid
,
1018 sizeof(orig
->bss_params
.ssid
));
1020 msg_body
.bss_params
.action
= orig
->bss_params
.action
;
1021 msg_body
.bss_params
.rateset
= orig
->bss_params
.rateset
;
1022 msg_body
.bss_params
.ht
= orig
->bss_params
.ht
;
1023 msg_body
.bss_params
.obss_prot_enabled
=
1024 orig
->bss_params
.obss_prot_enabled
;
1025 msg_body
.bss_params
.rmf
= orig
->bss_params
.rmf
;
1026 msg_body
.bss_params
.ht_oper_mode
= orig
->bss_params
.ht_oper_mode
;
1027 msg_body
.bss_params
.dual_cts_protection
=
1028 orig
->bss_params
.dual_cts_protection
;
1030 msg_body
.bss_params
.max_probe_resp_retry_limit
=
1031 orig
->bss_params
.max_probe_resp_retry_limit
;
1032 msg_body
.bss_params
.hidden_ssid
= orig
->bss_params
.hidden_ssid
;
1033 msg_body
.bss_params
.proxy_probe_resp
=
1034 orig
->bss_params
.proxy_probe_resp
;
1035 msg_body
.bss_params
.edca_params_valid
=
1036 orig
->bss_params
.edca_params_valid
;
1038 memcpy(&msg_body
.bss_params
.acbe
,
1039 &orig
->bss_params
.acbe
,
1040 sizeof(orig
->bss_params
.acbe
));
1041 memcpy(&msg_body
.bss_params
.acbk
,
1042 &orig
->bss_params
.acbk
,
1043 sizeof(orig
->bss_params
.acbk
));
1044 memcpy(&msg_body
.bss_params
.acvi
,
1045 &orig
->bss_params
.acvi
,
1046 sizeof(orig
->bss_params
.acvi
));
1047 memcpy(&msg_body
.bss_params
.acvo
,
1048 &orig
->bss_params
.acvo
,
1049 sizeof(orig
->bss_params
.acvo
));
1051 msg_body
.bss_params
.ext_set_sta_key_param_valid
=
1052 orig
->bss_params
.ext_set_sta_key_param_valid
;
1054 memcpy(&msg_body
.bss_params
.ext_set_sta_key_param
,
1055 &orig
->bss_params
.ext_set_sta_key_param
,
1056 sizeof(orig
->bss_params
.acvo
));
1058 msg_body
.bss_params
.wcn36xx_hal_persona
=
1059 orig
->bss_params
.wcn36xx_hal_persona
;
1060 msg_body
.bss_params
.spectrum_mgt_enable
=
1061 orig
->bss_params
.spectrum_mgt_enable
;
1062 msg_body
.bss_params
.tx_mgmt_power
= orig
->bss_params
.tx_mgmt_power
;
1063 msg_body
.bss_params
.max_tx_power
= orig
->bss_params
.max_tx_power
;
1065 wcn36xx_smd_convert_sta_to_v1(wcn
, &orig
->bss_params
.sta
,
1066 &msg_body
.bss_params
.sta
);
1068 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1070 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1071 "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1072 bss
->bssid
, bss
->self_mac_addr
, bss
->bss_type
,
1073 bss
->oper_mode
, bss
->nw_type
);
1075 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1076 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1077 sta
->bssid
, sta
->action
, sta
->sta_index
,
1078 sta
->bssid_index
, sta
->aid
, sta
->type
, sta
->mac
);
1080 return wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1084 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx
*wcn
,
1085 struct ieee80211_vif
*vif
,
1089 struct wcn36xx_hal_config_bss_rsp_msg
*rsp
;
1090 struct wcn36xx_hal_config_bss_rsp_params
*params
;
1091 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1093 if (len
< sizeof(*rsp
))
1096 rsp
= (struct wcn36xx_hal_config_bss_rsp_msg
*)buf
;
1097 params
= &rsp
->bss_rsp_params
;
1099 if (params
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
1100 wcn36xx_warn("hal config bss response failure: %d\n",
1105 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1106 "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
1107 " sta_idx %d self_idx %d bcast_idx %d mac %pM"
1108 " power %d ucast_dpu_signature %d\n",
1109 params
->status
, params
->bss_index
, params
->dpu_desc_index
,
1110 params
->bss_sta_index
, params
->bss_self_sta_index
,
1111 params
->bss_bcast_sta_idx
, params
->mac
,
1112 params
->tx_mgmt_power
, params
->ucast_dpu_signature
);
1114 priv_vif
->bss_index
= params
->bss_index
;
1116 if (priv_vif
->sta
) {
1117 priv_vif
->sta
->bss_sta_index
= params
->bss_sta_index
;
1118 priv_vif
->sta
->bss_dpu_desc_index
= params
->dpu_desc_index
;
1121 priv_vif
->ucast_dpu_signature
= params
->ucast_dpu_signature
;
1126 int wcn36xx_smd_config_bss(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
1127 struct ieee80211_sta
*sta
, const u8
*bssid
,
1130 struct wcn36xx_hal_config_bss_req_msg msg
;
1131 struct wcn36xx_hal_config_bss_params
*bss
;
1132 struct wcn36xx_hal_config_sta_params
*sta_params
;
1133 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1136 mutex_lock(&wcn
->hal_mutex
);
1137 INIT_HAL_MSG(msg
, WCN36XX_HAL_CONFIG_BSS_REQ
);
1139 bss
= &msg
.bss_params
;
1140 sta_params
= &bss
->sta
;
1142 WARN_ON(is_zero_ether_addr(bssid
));
1144 memcpy(&bss
->bssid
, bssid
, ETH_ALEN
);
1146 memcpy(bss
->self_mac_addr
, vif
->addr
, ETH_ALEN
);
1148 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1149 bss
->bss_type
= WCN36XX_HAL_INFRASTRUCTURE_MODE
;
1153 bss
->wcn36xx_hal_persona
= WCN36XX_HAL_STA_MODE
;
1154 } else if (vif
->type
== NL80211_IFTYPE_AP
||
1155 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1156 bss
->bss_type
= WCN36XX_HAL_INFRA_AP_MODE
;
1160 bss
->wcn36xx_hal_persona
= WCN36XX_HAL_STA_SAP_MODE
;
1161 } else if (vif
->type
== NL80211_IFTYPE_ADHOC
) {
1162 bss
->bss_type
= WCN36XX_HAL_IBSS_MODE
;
1167 wcn36xx_warn("Unknown type for bss config: %d\n", vif
->type
);
1170 if (vif
->type
== NL80211_IFTYPE_STATION
)
1171 wcn36xx_smd_set_bss_nw_type(wcn
, sta
, bss
);
1173 bss
->nw_type
= WCN36XX_HAL_11N_NW_TYPE
;
1175 bss
->short_slot_time_supported
= vif
->bss_conf
.use_short_slot
;
1176 bss
->lla_coexist
= 0;
1177 bss
->llb_coexist
= 0;
1178 bss
->llg_coexist
= 0;
1180 bss
->beacon_interval
= vif
->bss_conf
.beacon_int
;
1181 bss
->dtim_period
= vif_priv
->dtim_period
;
1183 wcn36xx_smd_set_bss_ht_params(vif
, sta
, bss
);
1185 bss
->oper_channel
= WCN36XX_HW_CHANNEL(wcn
);
1187 if (conf_is_ht40_minus(&wcn
->hw
->conf
))
1188 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
1189 else if (conf_is_ht40_plus(&wcn
->hw
->conf
))
1190 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
1192 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_NONE
;
1195 wcn36xx_smd_set_sta_params(wcn
, vif
, sta
, sta_params
);
1197 /* wcn->ssid is only valid in AP and IBSS mode */
1198 bss
->ssid
.length
= vif_priv
->ssid
.length
;
1199 memcpy(bss
->ssid
.ssid
, vif_priv
->ssid
.ssid
, vif_priv
->ssid
.length
);
1201 bss
->obss_prot_enabled
= 0;
1203 bss
->max_probe_resp_retry_limit
= 0;
1204 bss
->hidden_ssid
= vif
->bss_conf
.hidden_ssid
;
1205 bss
->proxy_probe_resp
= 0;
1206 bss
->edca_params_valid
= 0;
1208 /* FIXME: set acbe, acbk, acvi and acvo */
1210 bss
->ext_set_sta_key_param_valid
= 0;
1212 /* FIXME: set ext_set_sta_key_param */
1214 bss
->spectrum_mgt_enable
= 0;
1215 bss
->tx_mgmt_power
= 0;
1216 bss
->max_tx_power
= WCN36XX_MAX_POWER(wcn
);
1218 bss
->action
= update
;
1220 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1221 "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1222 bss
->bssid
, bss
->self_mac_addr
, bss
->bss_type
,
1223 bss
->oper_mode
, bss
->nw_type
);
1225 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1226 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1227 sta_params
->bssid
, sta_params
->action
,
1228 sta_params
->sta_index
, sta_params
->bssid_index
,
1229 sta_params
->aid
, sta_params
->type
,
1232 if (!wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
1233 ret
= wcn36xx_smd_config_bss_v1(wcn
, &msg
);
1235 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
1237 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
1240 wcn36xx_err("Sending hal_config_bss failed\n");
1243 ret
= wcn36xx_smd_config_bss_rsp(wcn
,
1248 wcn36xx_err("hal_config_bss response failed err=%d\n", ret
);
1252 mutex_unlock(&wcn
->hal_mutex
);
1256 int wcn36xx_smd_delete_bss(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1258 struct wcn36xx_hal_delete_bss_req_msg msg_body
;
1259 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1262 mutex_lock(&wcn
->hal_mutex
);
1263 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DELETE_BSS_REQ
);
1265 msg_body
.bss_index
= priv_vif
->bss_index
;
1267 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1269 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal delete bss %d\n", msg_body
.bss_index
);
1271 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1273 wcn36xx_err("Sending hal_delete_bss failed\n");
1276 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1278 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret
);
1282 mutex_unlock(&wcn
->hal_mutex
);
1286 int wcn36xx_smd_send_beacon(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
1287 struct sk_buff
*skb_beacon
, u16 tim_off
,
1290 struct wcn36xx_hal_send_beacon_req_msg msg_body
;
1293 mutex_lock(&wcn
->hal_mutex
);
1294 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SEND_BEACON_REQ
);
1296 /* TODO need to find out why this is needed? */
1297 msg_body
.beacon_length
= skb_beacon
->len
+ 6;
1299 if (BEACON_TEMPLATE_SIZE
> msg_body
.beacon_length
) {
1300 memcpy(&msg_body
.beacon
, &skb_beacon
->len
, sizeof(u32
));
1301 memcpy(&(msg_body
.beacon
[4]), skb_beacon
->data
,
1304 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1305 msg_body
.beacon_length
);
1309 memcpy(msg_body
.bssid
, vif
->addr
, ETH_ALEN
);
1311 /* TODO need to find out why this is needed? */
1312 if (vif
->type
== NL80211_IFTYPE_MESH_POINT
)
1313 /* mesh beacon don't need this, so push further down */
1314 msg_body
.tim_ie_offset
= 256;
1316 msg_body
.tim_ie_offset
= tim_off
+4;
1317 msg_body
.p2p_ie_offset
= p2p_off
;
1318 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1320 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1321 "hal send beacon beacon_length %d\n",
1322 msg_body
.beacon_length
);
1324 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1326 wcn36xx_err("Sending hal_send_beacon failed\n");
1329 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1331 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret
);
1335 mutex_unlock(&wcn
->hal_mutex
);
1339 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx
*wcn
,
1340 struct ieee80211_vif
*vif
,
1341 struct sk_buff
*skb
)
1343 struct wcn36xx_hal_send_probe_resp_req_msg msg
;
1346 mutex_lock(&wcn
->hal_mutex
);
1347 INIT_HAL_MSG(msg
, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ
);
1349 if (skb
->len
> BEACON_TEMPLATE_SIZE
) {
1350 wcn36xx_warn("probe response template is too big: %d\n",
1356 msg
.probe_resp_template_len
= skb
->len
;
1357 memcpy(&msg
.probe_resp_template
, skb
->data
, skb
->len
);
1359 memcpy(msg
.bssid
, vif
->addr
, ETH_ALEN
);
1361 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
1363 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1364 "hal update probe rsp len %d bssid %pM\n",
1365 msg
.probe_resp_template_len
, msg
.bssid
);
1367 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
1369 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1372 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1374 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1379 mutex_unlock(&wcn
->hal_mutex
);
1383 int wcn36xx_smd_set_stakey(struct wcn36xx
*wcn
,
1384 enum ani_ed_type enc_type
,
1390 struct wcn36xx_hal_set_sta_key_req_msg msg_body
;
1393 mutex_lock(&wcn
->hal_mutex
);
1394 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_STAKEY_REQ
);
1396 msg_body
.set_sta_key_params
.sta_index
= sta_index
;
1397 msg_body
.set_sta_key_params
.enc_type
= enc_type
;
1399 msg_body
.set_sta_key_params
.key
[0].id
= keyidx
;
1400 msg_body
.set_sta_key_params
.key
[0].unicast
= 1;
1401 msg_body
.set_sta_key_params
.key
[0].direction
= WCN36XX_HAL_TX_RX
;
1402 msg_body
.set_sta_key_params
.key
[0].pae_role
= 0;
1403 msg_body
.set_sta_key_params
.key
[0].length
= keylen
;
1404 memcpy(msg_body
.set_sta_key_params
.key
[0].key
, key
, keylen
);
1405 msg_body
.set_sta_key_params
.single_tid_rc
= 1;
1407 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1409 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1411 wcn36xx_err("Sending hal_set_stakey failed\n");
1414 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1416 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret
);
1420 mutex_unlock(&wcn
->hal_mutex
);
1424 int wcn36xx_smd_set_bsskey(struct wcn36xx
*wcn
,
1425 enum ani_ed_type enc_type
,
1430 struct wcn36xx_hal_set_bss_key_req_msg msg_body
;
1433 mutex_lock(&wcn
->hal_mutex
);
1434 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_BSSKEY_REQ
);
1435 msg_body
.bss_idx
= 0;
1436 msg_body
.enc_type
= enc_type
;
1437 msg_body
.num_keys
= 1;
1438 msg_body
.keys
[0].id
= keyidx
;
1439 msg_body
.keys
[0].unicast
= 0;
1440 msg_body
.keys
[0].direction
= WCN36XX_HAL_RX_ONLY
;
1441 msg_body
.keys
[0].pae_role
= 0;
1442 msg_body
.keys
[0].length
= keylen
;
1443 memcpy(msg_body
.keys
[0].key
, key
, keylen
);
1445 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1447 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1449 wcn36xx_err("Sending hal_set_bsskey failed\n");
1452 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1454 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret
);
1458 mutex_unlock(&wcn
->hal_mutex
);
1462 int wcn36xx_smd_remove_stakey(struct wcn36xx
*wcn
,
1463 enum ani_ed_type enc_type
,
1467 struct wcn36xx_hal_remove_sta_key_req_msg msg_body
;
1470 mutex_lock(&wcn
->hal_mutex
);
1471 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_RMV_STAKEY_REQ
);
1473 msg_body
.sta_idx
= sta_index
;
1474 msg_body
.enc_type
= enc_type
;
1475 msg_body
.key_id
= keyidx
;
1477 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1479 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1481 wcn36xx_err("Sending hal_remove_stakey failed\n");
1484 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1486 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret
);
1490 mutex_unlock(&wcn
->hal_mutex
);
1494 int wcn36xx_smd_remove_bsskey(struct wcn36xx
*wcn
,
1495 enum ani_ed_type enc_type
,
1498 struct wcn36xx_hal_remove_bss_key_req_msg msg_body
;
1501 mutex_lock(&wcn
->hal_mutex
);
1502 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_RMV_BSSKEY_REQ
);
1503 msg_body
.bss_idx
= 0;
1504 msg_body
.enc_type
= enc_type
;
1505 msg_body
.key_id
= keyidx
;
1507 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1509 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1511 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1514 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1516 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret
);
1520 mutex_unlock(&wcn
->hal_mutex
);
1524 int wcn36xx_smd_enter_bmps(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1526 struct wcn36xx_hal_enter_bmps_req_msg msg_body
;
1527 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1530 mutex_lock(&wcn
->hal_mutex
);
1531 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ENTER_BMPS_REQ
);
1533 msg_body
.bss_index
= vif_priv
->bss_index
;
1534 msg_body
.tbtt
= vif
->bss_conf
.sync_tsf
;
1535 msg_body
.dtim_period
= vif_priv
->dtim_period
;
1537 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1539 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1541 wcn36xx_err("Sending hal_enter_bmps failed\n");
1544 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1546 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret
);
1550 mutex_unlock(&wcn
->hal_mutex
);
1554 int wcn36xx_smd_exit_bmps(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1556 struct wcn36xx_hal_enter_bmps_req_msg msg_body
;
1557 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1560 mutex_lock(&wcn
->hal_mutex
);
1561 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_EXIT_BMPS_REQ
);
1563 msg_body
.bss_index
= vif_priv
->bss_index
;
1565 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1567 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1569 wcn36xx_err("Sending hal_exit_bmps failed\n");
1572 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1574 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret
);
1578 mutex_unlock(&wcn
->hal_mutex
);
1581 int wcn36xx_smd_set_power_params(struct wcn36xx
*wcn
, bool ignore_dtim
)
1583 struct wcn36xx_hal_set_power_params_req_msg msg_body
;
1586 mutex_lock(&wcn
->hal_mutex
);
1587 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_POWER_PARAMS_REQ
);
1590 * When host is down ignore every second dtim
1593 msg_body
.ignore_dtim
= 1;
1594 msg_body
.dtim_period
= 2;
1596 msg_body
.listen_interval
= WCN36XX_LISTEN_INTERVAL(wcn
);
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_set_power_params failed\n");
1607 mutex_unlock(&wcn
->hal_mutex
);
1610 /* Notice: This function should be called after associated, or else it
1613 int wcn36xx_smd_keep_alive_req(struct wcn36xx
*wcn
,
1614 struct ieee80211_vif
*vif
,
1617 struct wcn36xx_hal_keep_alive_req_msg msg_body
;
1618 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1621 mutex_lock(&wcn
->hal_mutex
);
1622 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_KEEP_ALIVE_REQ
);
1624 if (packet_type
== WCN36XX_HAL_KEEP_ALIVE_NULL_PKT
) {
1625 msg_body
.bss_index
= vif_priv
->bss_index
;
1626 msg_body
.packet_type
= WCN36XX_HAL_KEEP_ALIVE_NULL_PKT
;
1627 msg_body
.time_period
= WCN36XX_KEEP_ALIVE_TIME_PERIOD
;
1628 } else if (packet_type
== WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP
) {
1629 /* TODO: it also support ARP response type */
1631 wcn36xx_warn("unknow keep alive packet type %d\n", packet_type
);
1636 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1638 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1640 wcn36xx_err("Sending hal_exit_bmps failed\n");
1643 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1645 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret
);
1649 mutex_unlock(&wcn
->hal_mutex
);
1653 int wcn36xx_smd_dump_cmd_req(struct wcn36xx
*wcn
, u32 arg1
, u32 arg2
,
1654 u32 arg3
, u32 arg4
, u32 arg5
)
1656 struct wcn36xx_hal_dump_cmd_req_msg msg_body
;
1659 mutex_lock(&wcn
->hal_mutex
);
1660 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DUMP_COMMAND_REQ
);
1662 msg_body
.arg1
= arg1
;
1663 msg_body
.arg2
= arg2
;
1664 msg_body
.arg3
= arg3
;
1665 msg_body
.arg4
= arg4
;
1666 msg_body
.arg5
= arg5
;
1668 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1670 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1672 wcn36xx_err("Sending hal_dump_cmd failed\n");
1675 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1677 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret
);
1681 mutex_unlock(&wcn
->hal_mutex
);
1685 static inline void set_feat_caps(u32
*bitmap
,
1686 enum place_holder_in_cap_bitmap cap
)
1688 int arr_idx
, bit_idx
;
1690 if (cap
< 0 || cap
> 127) {
1691 wcn36xx_warn("error cap idx %d\n", cap
);
1697 bitmap
[arr_idx
] |= (1 << bit_idx
);
1700 static inline int get_feat_caps(u32
*bitmap
,
1701 enum place_holder_in_cap_bitmap cap
)
1703 int arr_idx
, bit_idx
;
1706 if (cap
< 0 || cap
> 127) {
1707 wcn36xx_warn("error cap idx %d\n", cap
);
1713 ret
= (bitmap
[arr_idx
] & (1 << bit_idx
)) ? 1 : 0;
1717 static inline void clear_feat_caps(u32
*bitmap
,
1718 enum place_holder_in_cap_bitmap cap
)
1720 int arr_idx
, bit_idx
;
1722 if (cap
< 0 || cap
> 127) {
1723 wcn36xx_warn("error cap idx %d\n", cap
);
1729 bitmap
[arr_idx
] &= ~(1 << bit_idx
);
1732 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx
*wcn
)
1734 struct wcn36xx_hal_feat_caps_msg msg_body
;
1737 mutex_lock(&wcn
->hal_mutex
);
1738 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ
);
1740 set_feat_caps(msg_body
.feat_caps
, STA_POWERSAVE
);
1742 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1744 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1746 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1749 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1751 wcn36xx_err("hal_feature_caps_exchange response failed err=%d\n",
1756 mutex_unlock(&wcn
->hal_mutex
);
1760 int wcn36xx_smd_add_ba_session(struct wcn36xx
*wcn
,
1761 struct ieee80211_sta
*sta
,
1767 struct wcn36xx_hal_add_ba_session_req_msg msg_body
;
1770 mutex_lock(&wcn
->hal_mutex
);
1771 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_BA_SESSION_REQ
);
1773 msg_body
.sta_index
= sta_index
;
1774 memcpy(&msg_body
.mac_addr
, sta
->addr
, ETH_ALEN
);
1775 msg_body
.dialog_token
= 0x10;
1778 /* Immediate BA because Delayed BA is not supported */
1779 msg_body
.policy
= 1;
1780 msg_body
.buffer_size
= WCN36XX_AGGR_BUFFER_SIZE
;
1781 msg_body
.timeout
= 0;
1783 msg_body
.ssn
= *ssn
;
1784 msg_body
.direction
= direction
;
1786 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1788 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1790 wcn36xx_err("Sending hal_add_ba_session failed\n");
1793 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1795 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret
);
1799 mutex_unlock(&wcn
->hal_mutex
);
1803 int wcn36xx_smd_add_ba(struct wcn36xx
*wcn
)
1805 struct wcn36xx_hal_add_ba_req_msg msg_body
;
1808 mutex_lock(&wcn
->hal_mutex
);
1809 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_BA_REQ
);
1811 msg_body
.session_id
= 0;
1812 msg_body
.win_size
= WCN36XX_AGGR_BUFFER_SIZE
;
1814 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1816 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1818 wcn36xx_err("Sending hal_add_ba failed\n");
1821 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1823 wcn36xx_err("hal_add_ba response failed err=%d\n", ret
);
1827 mutex_unlock(&wcn
->hal_mutex
);
1831 int wcn36xx_smd_del_ba(struct wcn36xx
*wcn
, u16 tid
, u8 sta_index
)
1833 struct wcn36xx_hal_del_ba_req_msg msg_body
;
1836 mutex_lock(&wcn
->hal_mutex
);
1837 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DEL_BA_REQ
);
1839 msg_body
.sta_index
= sta_index
;
1841 msg_body
.direction
= 0;
1842 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1844 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1846 wcn36xx_err("Sending hal_del_ba failed\n");
1849 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1851 wcn36xx_err("hal_del_ba response failed err=%d\n", ret
);
1855 mutex_unlock(&wcn
->hal_mutex
);
1859 int wcn36xx_smd_trigger_ba(struct wcn36xx
*wcn
, u8 sta_index
)
1861 struct wcn36xx_hal_trigger_ba_req_msg msg_body
;
1862 struct wcn36xx_hal_trigger_ba_req_candidate
*candidate
;
1865 mutex_lock(&wcn
->hal_mutex
);
1866 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_TRIGGER_BA_REQ
);
1868 msg_body
.session_id
= 0;
1869 msg_body
.candidate_cnt
= 1;
1870 msg_body
.header
.len
+= sizeof(*candidate
);
1871 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1873 candidate
= (struct wcn36xx_hal_trigger_ba_req_candidate
*)
1874 (wcn
->hal_buf
+ sizeof(msg_body
));
1875 candidate
->sta_index
= sta_index
;
1876 candidate
->tid_bitmap
= 1;
1878 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1880 wcn36xx_err("Sending hal_trigger_ba failed\n");
1883 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1885 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret
);
1889 mutex_unlock(&wcn
->hal_mutex
);
1893 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx
*wcn
, void *buf
, size_t len
)
1895 struct wcn36xx_hal_tx_compl_ind_msg
*rsp
= buf
;
1897 if (len
!= sizeof(*rsp
)) {
1898 wcn36xx_warn("Bad TX complete indication\n");
1902 wcn36xx_dxe_tx_ack_ind(wcn
, rsp
->status
);
1907 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx
*wcn
,
1911 struct wcn36xx_hal_missed_beacon_ind_msg
*rsp
= buf
;
1912 struct ieee80211_vif
*vif
= NULL
;
1913 struct wcn36xx_vif
*tmp
;
1915 /* Old FW does not have bss index */
1916 if (wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
1917 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
1918 wcn36xx_dbg(WCN36XX_DBG_HAL
, "beacon missed bss_index %d\n",
1920 vif
= container_of((void *)tmp
,
1921 struct ieee80211_vif
,
1923 ieee80211_connection_loss(vif
);
1928 if (len
!= sizeof(*rsp
)) {
1929 wcn36xx_warn("Corrupted missed beacon indication\n");
1933 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
1934 if (tmp
->bss_index
== rsp
->bss_index
) {
1935 wcn36xx_dbg(WCN36XX_DBG_HAL
, "beacon missed bss_index %d\n",
1937 vif
= container_of((void *)tmp
,
1938 struct ieee80211_vif
,
1940 ieee80211_connection_loss(vif
);
1945 wcn36xx_warn("BSS index %d not found\n", rsp
->bss_index
);
1949 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx
*wcn
,
1953 struct wcn36xx_hal_delete_sta_context_ind_msg
*rsp
= buf
;
1954 struct wcn36xx_vif
*tmp
;
1955 struct ieee80211_sta
*sta
= NULL
;
1957 if (len
!= sizeof(*rsp
)) {
1958 wcn36xx_warn("Corrupted delete sta indication\n");
1962 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
1963 if (sta
&& (tmp
->sta
->sta_index
== rsp
->sta_id
)) {
1964 sta
= container_of((void *)tmp
->sta
,
1965 struct ieee80211_sta
,
1967 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1968 "delete station indication %pM index %d\n",
1971 ieee80211_report_low_ack(sta
, 0);
1976 wcn36xx_warn("STA with addr %pM and index %d not found\n",
1982 int wcn36xx_smd_update_cfg(struct wcn36xx
*wcn
, u32 cfg_id
, u32 value
)
1984 struct wcn36xx_hal_update_cfg_req_msg msg_body
, *body
;
1988 mutex_lock(&wcn
->hal_mutex
);
1989 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_UPDATE_CFG_REQ
);
1991 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1993 body
= (struct wcn36xx_hal_update_cfg_req_msg
*) wcn
->hal_buf
;
1994 len
= msg_body
.header
.len
;
1996 put_cfg_tlv_u32(wcn
, &len
, cfg_id
, value
);
1997 body
->header
.len
= len
;
1998 body
->len
= len
- sizeof(*body
);
2000 ret
= wcn36xx_smd_send_and_wait(wcn
, body
->header
.len
);
2002 wcn36xx_err("Sending hal_update_cfg failed\n");
2005 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
2007 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret
);
2011 mutex_unlock(&wcn
->hal_mutex
);
2014 static void wcn36xx_smd_rsp_process(struct wcn36xx
*wcn
, void *buf
, size_t len
)
2016 struct wcn36xx_hal_msg_header
*msg_header
= buf
;
2017 struct wcn36xx_hal_ind_msg
*msg_ind
;
2018 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP
, "SMD <<< ", buf
, len
);
2020 switch (msg_header
->msg_type
) {
2021 case WCN36XX_HAL_START_RSP
:
2022 case WCN36XX_HAL_CONFIG_STA_RSP
:
2023 case WCN36XX_HAL_CONFIG_BSS_RSP
:
2024 case WCN36XX_HAL_ADD_STA_SELF_RSP
:
2025 case WCN36XX_HAL_STOP_RSP
:
2026 case WCN36XX_HAL_DEL_STA_SELF_RSP
:
2027 case WCN36XX_HAL_DELETE_STA_RSP
:
2028 case WCN36XX_HAL_INIT_SCAN_RSP
:
2029 case WCN36XX_HAL_START_SCAN_RSP
:
2030 case WCN36XX_HAL_END_SCAN_RSP
:
2031 case WCN36XX_HAL_FINISH_SCAN_RSP
:
2032 case WCN36XX_HAL_DOWNLOAD_NV_RSP
:
2033 case WCN36XX_HAL_DELETE_BSS_RSP
:
2034 case WCN36XX_HAL_SEND_BEACON_RSP
:
2035 case WCN36XX_HAL_SET_LINK_ST_RSP
:
2036 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP
:
2037 case WCN36XX_HAL_SET_BSSKEY_RSP
:
2038 case WCN36XX_HAL_SET_STAKEY_RSP
:
2039 case WCN36XX_HAL_RMV_STAKEY_RSP
:
2040 case WCN36XX_HAL_RMV_BSSKEY_RSP
:
2041 case WCN36XX_HAL_ENTER_BMPS_RSP
:
2042 case WCN36XX_HAL_SET_POWER_PARAMS_RSP
:
2043 case WCN36XX_HAL_EXIT_BMPS_RSP
:
2044 case WCN36XX_HAL_KEEP_ALIVE_RSP
:
2045 case WCN36XX_HAL_DUMP_COMMAND_RSP
:
2046 case WCN36XX_HAL_ADD_BA_SESSION_RSP
:
2047 case WCN36XX_HAL_ADD_BA_RSP
:
2048 case WCN36XX_HAL_DEL_BA_RSP
:
2049 case WCN36XX_HAL_TRIGGER_BA_RSP
:
2050 case WCN36XX_HAL_UPDATE_CFG_RSP
:
2051 case WCN36XX_HAL_JOIN_RSP
:
2052 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP
:
2053 case WCN36XX_HAL_CH_SWITCH_RSP
:
2054 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP
:
2055 memcpy(wcn
->hal_buf
, buf
, len
);
2056 wcn
->hal_rsp_len
= len
;
2057 complete(&wcn
->hal_rsp_compl
);
2060 case WCN36XX_HAL_OTA_TX_COMPL_IND
:
2061 case WCN36XX_HAL_MISSED_BEACON_IND
:
2062 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND
:
2063 msg_ind
= kmalloc(sizeof(*msg_ind
), GFP_KERNEL
);
2066 msg_ind
->msg_len
= len
;
2067 msg_ind
->msg
= kmalloc(len
, GFP_KERNEL
);
2068 if (!msg_ind
->msg
) {
2072 * FIXME: Do something smarter then just
2073 * printing an error.
2075 wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
2076 msg_header
->msg_type
);
2079 memcpy(msg_ind
->msg
, buf
, len
);
2080 mutex_lock(&wcn
->hal_ind_mutex
);
2081 list_add_tail(&msg_ind
->list
, &wcn
->hal_ind_queue
);
2082 queue_work(wcn
->hal_ind_wq
, &wcn
->hal_ind_work
);
2083 mutex_unlock(&wcn
->hal_ind_mutex
);
2084 wcn36xx_dbg(WCN36XX_DBG_HAL
, "indication arrived\n");
2087 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2088 msg_header
->msg_type
);
2091 static void wcn36xx_ind_smd_work(struct work_struct
*work
)
2093 struct wcn36xx
*wcn
=
2094 container_of(work
, struct wcn36xx
, hal_ind_work
);
2095 struct wcn36xx_hal_msg_header
*msg_header
;
2096 struct wcn36xx_hal_ind_msg
*hal_ind_msg
;
2098 mutex_lock(&wcn
->hal_ind_mutex
);
2100 hal_ind_msg
= list_first_entry(&wcn
->hal_ind_queue
,
2101 struct wcn36xx_hal_ind_msg
,
2104 msg_header
= (struct wcn36xx_hal_msg_header
*)hal_ind_msg
->msg
;
2106 switch (msg_header
->msg_type
) {
2107 case WCN36XX_HAL_OTA_TX_COMPL_IND
:
2108 wcn36xx_smd_tx_compl_ind(wcn
,
2110 hal_ind_msg
->msg_len
);
2112 case WCN36XX_HAL_MISSED_BEACON_IND
:
2113 wcn36xx_smd_missed_beacon_ind(wcn
,
2115 hal_ind_msg
->msg_len
);
2117 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND
:
2118 wcn36xx_smd_delete_sta_context_ind(wcn
,
2120 hal_ind_msg
->msg_len
);
2123 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2124 msg_header
->msg_type
);
2126 list_del(wcn
->hal_ind_queue
.next
);
2127 kfree(hal_ind_msg
->msg
);
2129 mutex_unlock(&wcn
->hal_ind_mutex
);
2131 int wcn36xx_smd_open(struct wcn36xx
*wcn
)
2134 wcn
->hal_ind_wq
= create_freezable_workqueue("wcn36xx_smd_ind");
2135 if (!wcn
->hal_ind_wq
) {
2136 wcn36xx_err("failed to allocate wq\n");
2140 INIT_WORK(&wcn
->hal_ind_work
, wcn36xx_ind_smd_work
);
2141 INIT_LIST_HEAD(&wcn
->hal_ind_queue
);
2142 mutex_init(&wcn
->hal_ind_mutex
);
2144 ret
= wcn
->ctrl_ops
->open(wcn
, wcn36xx_smd_rsp_process
);
2146 wcn36xx_err("failed to open control channel\n");
2153 destroy_workqueue(wcn
->hal_ind_wq
);
2158 void wcn36xx_smd_close(struct wcn36xx
*wcn
)
2160 wcn
->ctrl_ops
->close();
2161 destroy_workqueue(wcn
->hal_ind_wq
);
2162 mutex_destroy(&wcn
->hal_ind_mutex
);