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
)
199 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP
, "HAL >>> ", wcn
->hal_buf
, len
);
201 init_completion(&wcn
->hal_rsp_compl
);
203 ret
= wcn
->ctrl_ops
->tx(wcn
->hal_buf
, len
);
205 wcn36xx_err("HAL TX failed\n");
208 if (wait_for_completion_timeout(&wcn
->hal_rsp_compl
,
209 msecs_to_jiffies(HAL_MSG_TIMEOUT
)) <= 0) {
210 wcn36xx_err("Timeout! No SMD response in %dms\n",
215 wcn36xx_dbg(WCN36XX_DBG_SMD
, "SMD command completed in %dms",
216 jiffies_to_msecs(jiffies
- start
));
221 #define INIT_HAL_MSG(msg_body, type) \
223 memset(&msg_body, 0, sizeof(msg_body)); \
224 msg_body.header.msg_type = type; \
225 msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
226 msg_body.header.len = sizeof(msg_body); \
229 #define PREPARE_HAL_BUF(send_buf, msg_body) \
231 memset(send_buf, 0, msg_body.header.len); \
232 memcpy(send_buf, &msg_body, sizeof(msg_body)); \
235 static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
237 struct wcn36xx_fw_msg_status_rsp
*rsp
;
239 if (len
< sizeof(struct wcn36xx_hal_msg_header
) +
240 sizeof(struct wcn36xx_fw_msg_status_rsp
))
243 rsp
= (struct wcn36xx_fw_msg_status_rsp
*)
244 (buf
+ sizeof(struct wcn36xx_hal_msg_header
));
246 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->status
)
252 int wcn36xx_smd_load_nv(struct wcn36xx
*wcn
)
254 struct nv_data
*nv_d
;
255 struct wcn36xx_hal_nv_img_download_req_msg msg_body
;
261 ret
= request_firmware(&wcn
->nv
, WLAN_NV_FILE
, wcn
->dev
);
263 wcn36xx_err("Failed to load nv file %s: %d\n",
269 nv_d
= (struct nv_data
*)wcn
->nv
->data
;
270 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DOWNLOAD_NV_REQ
);
272 msg_body
.header
.len
+= WCN36XX_NV_FRAGMENT_SIZE
;
274 msg_body
.frag_number
= 0;
275 /* hal_buf must be protected with mutex */
276 mutex_lock(&wcn
->hal_mutex
);
279 fw_bytes_left
= wcn
->nv
->size
- fm_offset
- 4;
280 if (fw_bytes_left
> WCN36XX_NV_FRAGMENT_SIZE
) {
281 msg_body
.last_fragment
= 0;
282 msg_body
.nv_img_buffer_size
= WCN36XX_NV_FRAGMENT_SIZE
;
284 msg_body
.last_fragment
= 1;
285 msg_body
.nv_img_buffer_size
= fw_bytes_left
;
287 /* Do not forget update general message len */
288 msg_body
.header
.len
= sizeof(msg_body
) + fw_bytes_left
;
292 /* Add load NV request message header */
293 memcpy(wcn
->hal_buf
, &msg_body
, sizeof(msg_body
));
295 /* Add NV body itself */
296 memcpy(wcn
->hal_buf
+ sizeof(msg_body
),
297 &nv_d
->table
+ fm_offset
,
298 msg_body
.nv_img_buffer_size
);
300 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
303 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
,
306 wcn36xx_err("hal_load_nv response failed err=%d\n",
310 msg_body
.frag_number
++;
311 fm_offset
+= WCN36XX_NV_FRAGMENT_SIZE
;
313 } while (msg_body
.last_fragment
!= 1);
316 mutex_unlock(&wcn
->hal_mutex
);
320 static int wcn36xx_smd_start_rsp(struct wcn36xx
*wcn
, void *buf
, size_t len
)
322 struct wcn36xx_hal_mac_start_rsp_msg
*rsp
;
324 if (len
< sizeof(*rsp
))
327 rsp
= (struct wcn36xx_hal_mac_start_rsp_msg
*)buf
;
329 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->start_rsp_params
.status
)
332 memcpy(wcn
->crm_version
, rsp
->start_rsp_params
.crm_version
,
333 WCN36XX_HAL_VERSION_LENGTH
);
334 memcpy(wcn
->wlan_version
, rsp
->start_rsp_params
.wlan_version
,
335 WCN36XX_HAL_VERSION_LENGTH
);
337 /* null terminate the strings, just in case */
338 wcn
->crm_version
[WCN36XX_HAL_VERSION_LENGTH
] = '\0';
339 wcn
->wlan_version
[WCN36XX_HAL_VERSION_LENGTH
] = '\0';
341 wcn
->fw_revision
= rsp
->start_rsp_params
.version
.revision
;
342 wcn
->fw_version
= rsp
->start_rsp_params
.version
.version
;
343 wcn
->fw_minor
= rsp
->start_rsp_params
.version
.minor
;
344 wcn
->fw_major
= rsp
->start_rsp_params
.version
.major
;
346 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
347 wcn
->wlan_version
, wcn
->crm_version
);
349 wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
350 wcn
->fw_major
, wcn
->fw_minor
,
351 wcn
->fw_version
, wcn
->fw_revision
,
352 rsp
->start_rsp_params
.stations
,
353 rsp
->start_rsp_params
.bssids
);
358 int wcn36xx_smd_start(struct wcn36xx
*wcn
)
360 struct wcn36xx_hal_mac_start_req_msg msg_body
;
363 mutex_lock(&wcn
->hal_mutex
);
364 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_START_REQ
);
366 msg_body
.params
.type
= DRIVER_TYPE_PRODUCTION
;
367 msg_body
.params
.len
= 0;
369 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
371 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal start type %d\n",
372 msg_body
.params
.type
);
374 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
376 wcn36xx_err("Sending hal_start failed\n");
380 ret
= wcn36xx_smd_start_rsp(wcn
, wcn
->hal_buf
, wcn
->hal_rsp_len
);
382 wcn36xx_err("hal_start response failed err=%d\n", ret
);
387 mutex_unlock(&wcn
->hal_mutex
);
391 int wcn36xx_smd_stop(struct wcn36xx
*wcn
)
393 struct wcn36xx_hal_mac_stop_req_msg msg_body
;
396 mutex_lock(&wcn
->hal_mutex
);
397 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_STOP_REQ
);
399 msg_body
.stop_req_params
.reason
= HAL_STOP_TYPE_RF_KILL
;
401 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
403 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
405 wcn36xx_err("Sending hal_stop failed\n");
408 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
410 wcn36xx_err("hal_stop response failed err=%d\n", ret
);
414 mutex_unlock(&wcn
->hal_mutex
);
418 int wcn36xx_smd_init_scan(struct wcn36xx
*wcn
, enum wcn36xx_hal_sys_mode mode
)
420 struct wcn36xx_hal_init_scan_req_msg msg_body
;
423 mutex_lock(&wcn
->hal_mutex
);
424 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_INIT_SCAN_REQ
);
426 msg_body
.mode
= mode
;
428 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
430 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal init scan mode %d\n", msg_body
.mode
);
432 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
434 wcn36xx_err("Sending hal_init_scan failed\n");
437 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
439 wcn36xx_err("hal_init_scan response failed err=%d\n", ret
);
443 mutex_unlock(&wcn
->hal_mutex
);
447 int wcn36xx_smd_start_scan(struct wcn36xx
*wcn
)
449 struct wcn36xx_hal_start_scan_req_msg msg_body
;
452 mutex_lock(&wcn
->hal_mutex
);
453 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_START_SCAN_REQ
);
455 msg_body
.scan_channel
= WCN36XX_HW_CHANNEL(wcn
);
457 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
459 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal start scan channel %d\n",
460 msg_body
.scan_channel
);
462 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
464 wcn36xx_err("Sending hal_start_scan failed\n");
467 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
469 wcn36xx_err("hal_start_scan response failed err=%d\n", ret
);
473 mutex_unlock(&wcn
->hal_mutex
);
477 int wcn36xx_smd_end_scan(struct wcn36xx
*wcn
)
479 struct wcn36xx_hal_end_scan_req_msg msg_body
;
482 mutex_lock(&wcn
->hal_mutex
);
483 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_END_SCAN_REQ
);
485 msg_body
.scan_channel
= WCN36XX_HW_CHANNEL(wcn
);
487 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
489 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal end scan channel %d\n",
490 msg_body
.scan_channel
);
492 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
494 wcn36xx_err("Sending hal_end_scan failed\n");
497 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
499 wcn36xx_err("hal_end_scan response failed err=%d\n", ret
);
503 mutex_unlock(&wcn
->hal_mutex
);
507 int wcn36xx_smd_finish_scan(struct wcn36xx
*wcn
,
508 enum wcn36xx_hal_sys_mode mode
)
510 struct wcn36xx_hal_finish_scan_req_msg msg_body
;
513 mutex_lock(&wcn
->hal_mutex
);
514 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_FINISH_SCAN_REQ
);
516 msg_body
.mode
= mode
;
518 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
520 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal finish scan mode %d\n",
523 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
525 wcn36xx_err("Sending hal_finish_scan failed\n");
528 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
530 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret
);
534 mutex_unlock(&wcn
->hal_mutex
);
538 static int wcn36xx_smd_switch_channel_rsp(void *buf
, size_t len
)
540 struct wcn36xx_hal_switch_channel_rsp_msg
*rsp
;
543 ret
= wcn36xx_smd_rsp_status_check(buf
, len
);
546 rsp
= (struct wcn36xx_hal_switch_channel_rsp_msg
*)buf
;
547 wcn36xx_dbg(WCN36XX_DBG_HAL
, "channel switched to: %d, status: %d\n",
548 rsp
->channel_number
, rsp
->status
);
552 int wcn36xx_smd_switch_channel(struct wcn36xx
*wcn
,
553 struct ieee80211_vif
*vif
, int ch
)
555 struct wcn36xx_hal_switch_channel_req_msg msg_body
;
558 mutex_lock(&wcn
->hal_mutex
);
559 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CH_SWITCH_REQ
);
561 msg_body
.channel_number
= (u8
)ch
;
562 msg_body
.tx_mgmt_power
= 0xbf;
563 msg_body
.max_tx_power
= 0xbf;
564 memcpy(msg_body
.self_sta_mac_addr
, vif
->addr
, ETH_ALEN
);
566 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
568 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
570 wcn36xx_err("Sending hal_switch_channel failed\n");
573 ret
= wcn36xx_smd_switch_channel_rsp(wcn
->hal_buf
, wcn
->hal_rsp_len
);
575 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret
);
579 mutex_unlock(&wcn
->hal_mutex
);
583 static int wcn36xx_smd_update_scan_params_rsp(void *buf
, size_t len
)
585 struct wcn36xx_hal_update_scan_params_resp
*rsp
;
587 rsp
= (struct wcn36xx_hal_update_scan_params_resp
*)buf
;
589 /* Remove the PNO version bit */
590 rsp
->status
&= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK
));
592 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->status
) {
593 wcn36xx_warn("error response from update scan\n");
600 int wcn36xx_smd_update_scan_params(struct wcn36xx
*wcn
)
602 struct wcn36xx_hal_update_scan_params_req msg_body
;
605 mutex_lock(&wcn
->hal_mutex
);
606 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ
);
608 msg_body
.dot11d_enabled
= 0;
609 msg_body
.dot11d_resolved
= 0;
610 msg_body
.channel_count
= 26;
611 msg_body
.active_min_ch_time
= 60;
612 msg_body
.active_max_ch_time
= 120;
613 msg_body
.passive_min_ch_time
= 60;
614 msg_body
.passive_max_ch_time
= 110;
617 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
619 wcn36xx_dbg(WCN36XX_DBG_HAL
,
620 "hal update scan params channel_count %d\n",
621 msg_body
.channel_count
);
623 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
625 wcn36xx_err("Sending hal_update_scan_params failed\n");
628 ret
= wcn36xx_smd_update_scan_params_rsp(wcn
->hal_buf
,
631 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
636 mutex_unlock(&wcn
->hal_mutex
);
640 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx
*wcn
,
641 struct ieee80211_vif
*vif
,
645 struct wcn36xx_hal_add_sta_self_rsp_msg
*rsp
;
646 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
648 if (len
< sizeof(*rsp
))
651 rsp
= (struct wcn36xx_hal_add_sta_self_rsp_msg
*)buf
;
653 if (rsp
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
654 wcn36xx_warn("hal add sta self failure: %d\n",
659 wcn36xx_dbg(WCN36XX_DBG_HAL
,
660 "hal add sta self status %d self_sta_index %d dpu_index %d\n",
661 rsp
->status
, rsp
->self_sta_index
, rsp
->dpu_index
);
663 priv_vif
->self_sta_index
= rsp
->self_sta_index
;
664 priv_vif
->self_dpu_desc_index
= rsp
->dpu_index
;
669 int wcn36xx_smd_add_sta_self(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
671 struct wcn36xx_hal_add_sta_self_req msg_body
;
674 mutex_lock(&wcn
->hal_mutex
);
675 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_STA_SELF_REQ
);
677 memcpy(&msg_body
.self_addr
, vif
->addr
, ETH_ALEN
);
679 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
681 wcn36xx_dbg(WCN36XX_DBG_HAL
,
682 "hal add sta self self_addr %pM status %d\n",
683 msg_body
.self_addr
, msg_body
.status
);
685 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
687 wcn36xx_err("Sending hal_add_sta_self failed\n");
690 ret
= wcn36xx_smd_add_sta_self_rsp(wcn
,
695 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret
);
699 mutex_unlock(&wcn
->hal_mutex
);
703 int wcn36xx_smd_delete_sta_self(struct wcn36xx
*wcn
, u8
*addr
)
705 struct wcn36xx_hal_del_sta_self_req_msg msg_body
;
708 mutex_lock(&wcn
->hal_mutex
);
709 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DEL_STA_SELF_REQ
);
711 memcpy(&msg_body
.self_addr
, addr
, ETH_ALEN
);
713 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
715 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
717 wcn36xx_err("Sending hal_delete_sta_self failed\n");
720 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
722 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
727 mutex_unlock(&wcn
->hal_mutex
);
731 int wcn36xx_smd_delete_sta(struct wcn36xx
*wcn
, u8 sta_index
)
733 struct wcn36xx_hal_delete_sta_req_msg msg_body
;
736 mutex_lock(&wcn
->hal_mutex
);
737 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DELETE_STA_REQ
);
739 msg_body
.sta_index
= sta_index
;
741 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
743 wcn36xx_dbg(WCN36XX_DBG_HAL
,
744 "hal delete sta sta_index %d\n",
747 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
749 wcn36xx_err("Sending hal_delete_sta failed\n");
752 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
754 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret
);
758 mutex_unlock(&wcn
->hal_mutex
);
762 static int wcn36xx_smd_join_rsp(void *buf
, size_t len
)
764 struct wcn36xx_hal_join_rsp_msg
*rsp
;
766 if (wcn36xx_smd_rsp_status_check(buf
, len
))
769 rsp
= (struct wcn36xx_hal_join_rsp_msg
*)buf
;
771 wcn36xx_dbg(WCN36XX_DBG_HAL
,
772 "hal rsp join status %d tx_mgmt_power %d\n",
773 rsp
->status
, rsp
->tx_mgmt_power
);
778 int wcn36xx_smd_join(struct wcn36xx
*wcn
, const u8
*bssid
, u8
*vif
, u8 ch
)
780 struct wcn36xx_hal_join_req_msg msg_body
;
783 mutex_lock(&wcn
->hal_mutex
);
784 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_JOIN_REQ
);
786 memcpy(&msg_body
.bssid
, bssid
, ETH_ALEN
);
787 memcpy(&msg_body
.self_sta_mac_addr
, vif
, ETH_ALEN
);
788 msg_body
.channel
= ch
;
790 if (conf_is_ht40_minus(&wcn
->hw
->conf
))
791 msg_body
.secondary_channel_offset
=
792 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY
;
793 else if (conf_is_ht40_plus(&wcn
->hw
->conf
))
794 msg_body
.secondary_channel_offset
=
795 PHY_DOUBLE_CHANNEL_LOW_PRIMARY
;
797 msg_body
.secondary_channel_offset
=
798 PHY_SINGLE_CHANNEL_CENTERED
;
800 msg_body
.link_state
= WCN36XX_HAL_LINK_PREASSOC_STATE
;
802 msg_body
.max_tx_power
= 0xbf;
803 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
805 wcn36xx_dbg(WCN36XX_DBG_HAL
,
806 "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
807 msg_body
.bssid
, msg_body
.self_sta_mac_addr
,
808 msg_body
.channel
, msg_body
.link_state
);
810 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
812 wcn36xx_err("Sending hal_join failed\n");
815 ret
= wcn36xx_smd_join_rsp(wcn
->hal_buf
, wcn
->hal_rsp_len
);
817 wcn36xx_err("hal_join response failed err=%d\n", ret
);
821 mutex_unlock(&wcn
->hal_mutex
);
825 int wcn36xx_smd_set_link_st(struct wcn36xx
*wcn
, const u8
*bssid
,
827 enum wcn36xx_hal_link_state state
)
829 struct wcn36xx_hal_set_link_state_req_msg msg_body
;
832 mutex_lock(&wcn
->hal_mutex
);
833 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_LINK_ST_REQ
);
835 memcpy(&msg_body
.bssid
, bssid
, ETH_ALEN
);
836 memcpy(&msg_body
.self_mac_addr
, sta_mac
, ETH_ALEN
);
837 msg_body
.state
= state
;
839 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
841 wcn36xx_dbg(WCN36XX_DBG_HAL
,
842 "hal set link state bssid %pM self_mac_addr %pM state %d\n",
843 msg_body
.bssid
, msg_body
.self_mac_addr
, msg_body
.state
);
845 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
847 wcn36xx_err("Sending hal_set_link_st failed\n");
850 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
852 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret
);
856 mutex_unlock(&wcn
->hal_mutex
);
860 static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx
*wcn
,
861 const struct wcn36xx_hal_config_sta_params
*orig
,
862 struct wcn36xx_hal_config_sta_params_v1
*v1
)
864 /* convert orig to v1 format */
865 memcpy(&v1
->bssid
, orig
->bssid
, ETH_ALEN
);
866 memcpy(&v1
->mac
, orig
->mac
, ETH_ALEN
);
868 v1
->type
= orig
->type
;
869 v1
->listen_interval
= orig
->listen_interval
;
870 v1
->ht_capable
= orig
->ht_capable
;
872 v1
->max_ampdu_size
= orig
->max_ampdu_size
;
873 v1
->max_ampdu_density
= orig
->max_ampdu_density
;
874 v1
->sgi_40mhz
= orig
->sgi_40mhz
;
875 v1
->sgi_20Mhz
= orig
->sgi_20Mhz
;
877 memcpy(&v1
->supported_rates
, &orig
->supported_rates
,
878 sizeof(orig
->supported_rates
));
879 v1
->sta_index
= orig
->sta_index
;
882 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx
*wcn
,
883 struct ieee80211_sta
*sta
,
887 struct wcn36xx_hal_config_sta_rsp_msg
*rsp
;
888 struct config_sta_rsp_params
*params
;
889 struct wcn36xx_sta
*sta_priv
= (struct wcn36xx_sta
*)sta
->drv_priv
;
891 if (len
< sizeof(*rsp
))
894 rsp
= (struct wcn36xx_hal_config_sta_rsp_msg
*)buf
;
895 params
= &rsp
->params
;
897 if (params
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
898 wcn36xx_warn("hal config sta response failure: %d\n",
903 sta_priv
->sta_index
= params
->sta_index
;
904 sta_priv
->dpu_desc_index
= params
->dpu_index
;
906 wcn36xx_dbg(WCN36XX_DBG_HAL
,
907 "hal config sta rsp status %d sta_index %d bssid_index %d p2p %d\n",
908 params
->status
, params
->sta_index
, params
->bssid_index
,
914 static int wcn36xx_smd_config_sta_v1(struct wcn36xx
*wcn
,
915 const struct wcn36xx_hal_config_sta_req_msg
*orig
)
917 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body
;
918 struct wcn36xx_hal_config_sta_params_v1
*sta
= &msg_body
.sta_params
;
920 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CONFIG_STA_REQ
);
922 wcn36xx_smd_convert_sta_to_v1(wcn
, &orig
->sta_params
,
923 &msg_body
.sta_params
);
925 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
927 wcn36xx_dbg(WCN36XX_DBG_HAL
,
928 "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
929 sta
->action
, sta
->sta_index
, sta
->bssid_index
,
930 sta
->bssid
, sta
->type
, sta
->mac
, sta
->aid
);
932 return wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
935 int wcn36xx_smd_config_sta(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
936 struct ieee80211_sta
*sta
)
938 struct wcn36xx_hal_config_sta_req_msg msg
;
939 struct wcn36xx_hal_config_sta_params
*sta_params
;
942 mutex_lock(&wcn
->hal_mutex
);
943 INIT_HAL_MSG(msg
, WCN36XX_HAL_CONFIG_STA_REQ
);
945 sta_params
= &msg
.sta_params
;
947 wcn36xx_smd_set_sta_params(wcn
, vif
, sta
, sta_params
);
949 if (!wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
950 ret
= wcn36xx_smd_config_sta_v1(wcn
, &msg
);
952 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
954 wcn36xx_dbg(WCN36XX_DBG_HAL
,
955 "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
956 sta_params
->action
, sta_params
->sta_index
,
957 sta_params
->bssid_index
, sta_params
->bssid
,
958 sta_params
->type
, sta_params
->mac
, sta_params
->aid
);
960 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
963 wcn36xx_err("Sending hal_config_sta failed\n");
966 ret
= wcn36xx_smd_config_sta_rsp(wcn
,
971 wcn36xx_err("hal_config_sta response failed err=%d\n", ret
);
975 mutex_unlock(&wcn
->hal_mutex
);
979 static int wcn36xx_smd_config_bss_v1(struct wcn36xx
*wcn
,
980 const struct wcn36xx_hal_config_bss_req_msg
*orig
)
982 struct wcn36xx_hal_config_bss_req_msg_v1 msg_body
;
983 struct wcn36xx_hal_config_bss_params_v1
*bss
= &msg_body
.bss_params
;
984 struct wcn36xx_hal_config_sta_params_v1
*sta
= &bss
->sta
;
986 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CONFIG_BSS_REQ
);
988 /* convert orig to v1 */
989 memcpy(&msg_body
.bss_params
.bssid
,
990 &orig
->bss_params
.bssid
, ETH_ALEN
);
991 memcpy(&msg_body
.bss_params
.self_mac_addr
,
992 &orig
->bss_params
.self_mac_addr
, ETH_ALEN
);
994 msg_body
.bss_params
.bss_type
= orig
->bss_params
.bss_type
;
995 msg_body
.bss_params
.oper_mode
= orig
->bss_params
.oper_mode
;
996 msg_body
.bss_params
.nw_type
= orig
->bss_params
.nw_type
;
998 msg_body
.bss_params
.short_slot_time_supported
=
999 orig
->bss_params
.short_slot_time_supported
;
1000 msg_body
.bss_params
.lla_coexist
= orig
->bss_params
.lla_coexist
;
1001 msg_body
.bss_params
.llb_coexist
= orig
->bss_params
.llb_coexist
;
1002 msg_body
.bss_params
.llg_coexist
= orig
->bss_params
.llg_coexist
;
1003 msg_body
.bss_params
.ht20_coexist
= orig
->bss_params
.ht20_coexist
;
1004 msg_body
.bss_params
.lln_non_gf_coexist
=
1005 orig
->bss_params
.lln_non_gf_coexist
;
1007 msg_body
.bss_params
.lsig_tx_op_protection_full_support
=
1008 orig
->bss_params
.lsig_tx_op_protection_full_support
;
1009 msg_body
.bss_params
.rifs_mode
= orig
->bss_params
.rifs_mode
;
1010 msg_body
.bss_params
.beacon_interval
= orig
->bss_params
.beacon_interval
;
1011 msg_body
.bss_params
.dtim_period
= orig
->bss_params
.dtim_period
;
1012 msg_body
.bss_params
.tx_channel_width_set
=
1013 orig
->bss_params
.tx_channel_width_set
;
1014 msg_body
.bss_params
.oper_channel
= orig
->bss_params
.oper_channel
;
1015 msg_body
.bss_params
.ext_channel
= orig
->bss_params
.ext_channel
;
1017 msg_body
.bss_params
.reserved
= orig
->bss_params
.reserved
;
1019 memcpy(&msg_body
.bss_params
.ssid
,
1020 &orig
->bss_params
.ssid
,
1021 sizeof(orig
->bss_params
.ssid
));
1023 msg_body
.bss_params
.action
= orig
->bss_params
.action
;
1024 msg_body
.bss_params
.rateset
= orig
->bss_params
.rateset
;
1025 msg_body
.bss_params
.ht
= orig
->bss_params
.ht
;
1026 msg_body
.bss_params
.obss_prot_enabled
=
1027 orig
->bss_params
.obss_prot_enabled
;
1028 msg_body
.bss_params
.rmf
= orig
->bss_params
.rmf
;
1029 msg_body
.bss_params
.ht_oper_mode
= orig
->bss_params
.ht_oper_mode
;
1030 msg_body
.bss_params
.dual_cts_protection
=
1031 orig
->bss_params
.dual_cts_protection
;
1033 msg_body
.bss_params
.max_probe_resp_retry_limit
=
1034 orig
->bss_params
.max_probe_resp_retry_limit
;
1035 msg_body
.bss_params
.hidden_ssid
= orig
->bss_params
.hidden_ssid
;
1036 msg_body
.bss_params
.proxy_probe_resp
=
1037 orig
->bss_params
.proxy_probe_resp
;
1038 msg_body
.bss_params
.edca_params_valid
=
1039 orig
->bss_params
.edca_params_valid
;
1041 memcpy(&msg_body
.bss_params
.acbe
,
1042 &orig
->bss_params
.acbe
,
1043 sizeof(orig
->bss_params
.acbe
));
1044 memcpy(&msg_body
.bss_params
.acbk
,
1045 &orig
->bss_params
.acbk
,
1046 sizeof(orig
->bss_params
.acbk
));
1047 memcpy(&msg_body
.bss_params
.acvi
,
1048 &orig
->bss_params
.acvi
,
1049 sizeof(orig
->bss_params
.acvi
));
1050 memcpy(&msg_body
.bss_params
.acvo
,
1051 &orig
->bss_params
.acvo
,
1052 sizeof(orig
->bss_params
.acvo
));
1054 msg_body
.bss_params
.ext_set_sta_key_param_valid
=
1055 orig
->bss_params
.ext_set_sta_key_param_valid
;
1057 memcpy(&msg_body
.bss_params
.ext_set_sta_key_param
,
1058 &orig
->bss_params
.ext_set_sta_key_param
,
1059 sizeof(orig
->bss_params
.acvo
));
1061 msg_body
.bss_params
.wcn36xx_hal_persona
=
1062 orig
->bss_params
.wcn36xx_hal_persona
;
1063 msg_body
.bss_params
.spectrum_mgt_enable
=
1064 orig
->bss_params
.spectrum_mgt_enable
;
1065 msg_body
.bss_params
.tx_mgmt_power
= orig
->bss_params
.tx_mgmt_power
;
1066 msg_body
.bss_params
.max_tx_power
= orig
->bss_params
.max_tx_power
;
1068 wcn36xx_smd_convert_sta_to_v1(wcn
, &orig
->bss_params
.sta
,
1069 &msg_body
.bss_params
.sta
);
1071 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1073 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1074 "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1075 bss
->bssid
, bss
->self_mac_addr
, bss
->bss_type
,
1076 bss
->oper_mode
, bss
->nw_type
);
1078 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1079 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1080 sta
->bssid
, sta
->action
, sta
->sta_index
,
1081 sta
->bssid_index
, sta
->aid
, sta
->type
, sta
->mac
);
1083 return wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1087 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx
*wcn
,
1088 struct ieee80211_vif
*vif
,
1092 struct wcn36xx_hal_config_bss_rsp_msg
*rsp
;
1093 struct wcn36xx_hal_config_bss_rsp_params
*params
;
1094 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1096 if (len
< sizeof(*rsp
))
1099 rsp
= (struct wcn36xx_hal_config_bss_rsp_msg
*)buf
;
1100 params
= &rsp
->bss_rsp_params
;
1102 if (params
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
1103 wcn36xx_warn("hal config bss response failure: %d\n",
1108 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1109 "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
1110 " sta_idx %d self_idx %d bcast_idx %d mac %pM"
1111 " power %d ucast_dpu_signature %d\n",
1112 params
->status
, params
->bss_index
, params
->dpu_desc_index
,
1113 params
->bss_sta_index
, params
->bss_self_sta_index
,
1114 params
->bss_bcast_sta_idx
, params
->mac
,
1115 params
->tx_mgmt_power
, params
->ucast_dpu_signature
);
1117 priv_vif
->bss_index
= params
->bss_index
;
1119 if (priv_vif
->sta
) {
1120 priv_vif
->sta
->bss_sta_index
= params
->bss_sta_index
;
1121 priv_vif
->sta
->bss_dpu_desc_index
= params
->dpu_desc_index
;
1124 priv_vif
->ucast_dpu_signature
= params
->ucast_dpu_signature
;
1129 int wcn36xx_smd_config_bss(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
1130 struct ieee80211_sta
*sta
, const u8
*bssid
,
1133 struct wcn36xx_hal_config_bss_req_msg msg
;
1134 struct wcn36xx_hal_config_bss_params
*bss
;
1135 struct wcn36xx_hal_config_sta_params
*sta_params
;
1136 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1139 mutex_lock(&wcn
->hal_mutex
);
1140 INIT_HAL_MSG(msg
, WCN36XX_HAL_CONFIG_BSS_REQ
);
1142 bss
= &msg
.bss_params
;
1143 sta_params
= &bss
->sta
;
1145 WARN_ON(is_zero_ether_addr(bssid
));
1147 memcpy(&bss
->bssid
, bssid
, ETH_ALEN
);
1149 memcpy(bss
->self_mac_addr
, vif
->addr
, ETH_ALEN
);
1151 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1152 bss
->bss_type
= WCN36XX_HAL_INFRASTRUCTURE_MODE
;
1156 bss
->wcn36xx_hal_persona
= WCN36XX_HAL_STA_MODE
;
1157 } else if (vif
->type
== NL80211_IFTYPE_AP
||
1158 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1159 bss
->bss_type
= WCN36XX_HAL_INFRA_AP_MODE
;
1163 bss
->wcn36xx_hal_persona
= WCN36XX_HAL_STA_SAP_MODE
;
1164 } else if (vif
->type
== NL80211_IFTYPE_ADHOC
) {
1165 bss
->bss_type
= WCN36XX_HAL_IBSS_MODE
;
1170 wcn36xx_warn("Unknown type for bss config: %d\n", vif
->type
);
1173 if (vif
->type
== NL80211_IFTYPE_STATION
)
1174 wcn36xx_smd_set_bss_nw_type(wcn
, sta
, bss
);
1176 bss
->nw_type
= WCN36XX_HAL_11N_NW_TYPE
;
1178 bss
->short_slot_time_supported
= vif
->bss_conf
.use_short_slot
;
1179 bss
->lla_coexist
= 0;
1180 bss
->llb_coexist
= 0;
1181 bss
->llg_coexist
= 0;
1183 bss
->beacon_interval
= vif
->bss_conf
.beacon_int
;
1184 bss
->dtim_period
= vif_priv
->dtim_period
;
1186 wcn36xx_smd_set_bss_ht_params(vif
, sta
, bss
);
1188 bss
->oper_channel
= WCN36XX_HW_CHANNEL(wcn
);
1190 if (conf_is_ht40_minus(&wcn
->hw
->conf
))
1191 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
1192 else if (conf_is_ht40_plus(&wcn
->hw
->conf
))
1193 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
1195 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_NONE
;
1198 wcn36xx_smd_set_sta_params(wcn
, vif
, sta
, sta_params
);
1200 /* wcn->ssid is only valid in AP and IBSS mode */
1201 bss
->ssid
.length
= vif_priv
->ssid
.length
;
1202 memcpy(bss
->ssid
.ssid
, vif_priv
->ssid
.ssid
, vif_priv
->ssid
.length
);
1204 bss
->obss_prot_enabled
= 0;
1206 bss
->max_probe_resp_retry_limit
= 0;
1207 bss
->hidden_ssid
= vif
->bss_conf
.hidden_ssid
;
1208 bss
->proxy_probe_resp
= 0;
1209 bss
->edca_params_valid
= 0;
1211 /* FIXME: set acbe, acbk, acvi and acvo */
1213 bss
->ext_set_sta_key_param_valid
= 0;
1215 /* FIXME: set ext_set_sta_key_param */
1217 bss
->spectrum_mgt_enable
= 0;
1218 bss
->tx_mgmt_power
= 0;
1219 bss
->max_tx_power
= WCN36XX_MAX_POWER(wcn
);
1221 bss
->action
= update
;
1223 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1224 "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1225 bss
->bssid
, bss
->self_mac_addr
, bss
->bss_type
,
1226 bss
->oper_mode
, bss
->nw_type
);
1228 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1229 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1230 sta_params
->bssid
, sta_params
->action
,
1231 sta_params
->sta_index
, sta_params
->bssid_index
,
1232 sta_params
->aid
, sta_params
->type
,
1235 if (!wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
1236 ret
= wcn36xx_smd_config_bss_v1(wcn
, &msg
);
1238 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
1240 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
1243 wcn36xx_err("Sending hal_config_bss failed\n");
1246 ret
= wcn36xx_smd_config_bss_rsp(wcn
,
1251 wcn36xx_err("hal_config_bss response failed err=%d\n", ret
);
1255 mutex_unlock(&wcn
->hal_mutex
);
1259 int wcn36xx_smd_delete_bss(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1261 struct wcn36xx_hal_delete_bss_req_msg msg_body
;
1262 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1265 mutex_lock(&wcn
->hal_mutex
);
1266 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DELETE_BSS_REQ
);
1268 msg_body
.bss_index
= priv_vif
->bss_index
;
1270 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1272 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal delete bss %d\n", msg_body
.bss_index
);
1274 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1276 wcn36xx_err("Sending hal_delete_bss failed\n");
1279 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1281 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret
);
1285 mutex_unlock(&wcn
->hal_mutex
);
1289 int wcn36xx_smd_send_beacon(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
1290 struct sk_buff
*skb_beacon
, u16 tim_off
,
1293 struct wcn36xx_hal_send_beacon_req_msg msg_body
;
1296 mutex_lock(&wcn
->hal_mutex
);
1297 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SEND_BEACON_REQ
);
1299 /* TODO need to find out why this is needed? */
1300 msg_body
.beacon_length
= skb_beacon
->len
+ 6;
1302 if (BEACON_TEMPLATE_SIZE
> msg_body
.beacon_length
) {
1303 memcpy(&msg_body
.beacon
, &skb_beacon
->len
, sizeof(u32
));
1304 memcpy(&(msg_body
.beacon
[4]), skb_beacon
->data
,
1307 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1308 msg_body
.beacon_length
);
1312 memcpy(msg_body
.bssid
, vif
->addr
, ETH_ALEN
);
1314 /* TODO need to find out why this is needed? */
1315 if (vif
->type
== NL80211_IFTYPE_MESH_POINT
)
1316 /* mesh beacon don't need this, so push further down */
1317 msg_body
.tim_ie_offset
= 256;
1319 msg_body
.tim_ie_offset
= tim_off
+4;
1320 msg_body
.p2p_ie_offset
= p2p_off
;
1321 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1323 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1324 "hal send beacon beacon_length %d\n",
1325 msg_body
.beacon_length
);
1327 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1329 wcn36xx_err("Sending hal_send_beacon failed\n");
1332 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1334 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret
);
1338 mutex_unlock(&wcn
->hal_mutex
);
1342 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx
*wcn
,
1343 struct ieee80211_vif
*vif
,
1344 struct sk_buff
*skb
)
1346 struct wcn36xx_hal_send_probe_resp_req_msg msg
;
1349 mutex_lock(&wcn
->hal_mutex
);
1350 INIT_HAL_MSG(msg
, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ
);
1352 if (skb
->len
> BEACON_TEMPLATE_SIZE
) {
1353 wcn36xx_warn("probe response template is too big: %d\n",
1359 msg
.probe_resp_template_len
= skb
->len
;
1360 memcpy(&msg
.probe_resp_template
, skb
->data
, skb
->len
);
1362 memcpy(msg
.bssid
, vif
->addr
, ETH_ALEN
);
1364 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
1366 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1367 "hal update probe rsp len %d bssid %pM\n",
1368 msg
.probe_resp_template_len
, msg
.bssid
);
1370 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
1372 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1375 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1377 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1382 mutex_unlock(&wcn
->hal_mutex
);
1386 int wcn36xx_smd_set_stakey(struct wcn36xx
*wcn
,
1387 enum ani_ed_type enc_type
,
1393 struct wcn36xx_hal_set_sta_key_req_msg msg_body
;
1396 mutex_lock(&wcn
->hal_mutex
);
1397 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_STAKEY_REQ
);
1399 msg_body
.set_sta_key_params
.sta_index
= sta_index
;
1400 msg_body
.set_sta_key_params
.enc_type
= enc_type
;
1402 msg_body
.set_sta_key_params
.key
[0].id
= keyidx
;
1403 msg_body
.set_sta_key_params
.key
[0].unicast
= 1;
1404 msg_body
.set_sta_key_params
.key
[0].direction
= WCN36XX_HAL_TX_RX
;
1405 msg_body
.set_sta_key_params
.key
[0].pae_role
= 0;
1406 msg_body
.set_sta_key_params
.key
[0].length
= keylen
;
1407 memcpy(msg_body
.set_sta_key_params
.key
[0].key
, key
, keylen
);
1408 msg_body
.set_sta_key_params
.single_tid_rc
= 1;
1410 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1412 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1414 wcn36xx_err("Sending hal_set_stakey failed\n");
1417 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1419 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret
);
1423 mutex_unlock(&wcn
->hal_mutex
);
1427 int wcn36xx_smd_set_bsskey(struct wcn36xx
*wcn
,
1428 enum ani_ed_type enc_type
,
1433 struct wcn36xx_hal_set_bss_key_req_msg msg_body
;
1436 mutex_lock(&wcn
->hal_mutex
);
1437 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_BSSKEY_REQ
);
1438 msg_body
.bss_idx
= 0;
1439 msg_body
.enc_type
= enc_type
;
1440 msg_body
.num_keys
= 1;
1441 msg_body
.keys
[0].id
= keyidx
;
1442 msg_body
.keys
[0].unicast
= 0;
1443 msg_body
.keys
[0].direction
= WCN36XX_HAL_RX_ONLY
;
1444 msg_body
.keys
[0].pae_role
= 0;
1445 msg_body
.keys
[0].length
= keylen
;
1446 memcpy(msg_body
.keys
[0].key
, key
, keylen
);
1448 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1450 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1452 wcn36xx_err("Sending hal_set_bsskey failed\n");
1455 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1457 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret
);
1461 mutex_unlock(&wcn
->hal_mutex
);
1465 int wcn36xx_smd_remove_stakey(struct wcn36xx
*wcn
,
1466 enum ani_ed_type enc_type
,
1470 struct wcn36xx_hal_remove_sta_key_req_msg msg_body
;
1473 mutex_lock(&wcn
->hal_mutex
);
1474 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_RMV_STAKEY_REQ
);
1476 msg_body
.sta_idx
= sta_index
;
1477 msg_body
.enc_type
= enc_type
;
1478 msg_body
.key_id
= keyidx
;
1480 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1482 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1484 wcn36xx_err("Sending hal_remove_stakey failed\n");
1487 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1489 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret
);
1493 mutex_unlock(&wcn
->hal_mutex
);
1497 int wcn36xx_smd_remove_bsskey(struct wcn36xx
*wcn
,
1498 enum ani_ed_type enc_type
,
1501 struct wcn36xx_hal_remove_bss_key_req_msg msg_body
;
1504 mutex_lock(&wcn
->hal_mutex
);
1505 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_RMV_BSSKEY_REQ
);
1506 msg_body
.bss_idx
= 0;
1507 msg_body
.enc_type
= enc_type
;
1508 msg_body
.key_id
= keyidx
;
1510 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1512 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1514 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1517 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1519 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret
);
1523 mutex_unlock(&wcn
->hal_mutex
);
1527 int wcn36xx_smd_enter_bmps(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1529 struct wcn36xx_hal_enter_bmps_req_msg msg_body
;
1530 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1533 mutex_lock(&wcn
->hal_mutex
);
1534 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ENTER_BMPS_REQ
);
1536 msg_body
.bss_index
= vif_priv
->bss_index
;
1537 msg_body
.tbtt
= vif
->bss_conf
.sync_tsf
;
1538 msg_body
.dtim_period
= vif_priv
->dtim_period
;
1540 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1542 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1544 wcn36xx_err("Sending hal_enter_bmps failed\n");
1547 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1549 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret
);
1553 mutex_unlock(&wcn
->hal_mutex
);
1557 int wcn36xx_smd_exit_bmps(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1559 struct wcn36xx_hal_enter_bmps_req_msg msg_body
;
1560 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1563 mutex_lock(&wcn
->hal_mutex
);
1564 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_EXIT_BMPS_REQ
);
1566 msg_body
.bss_index
= vif_priv
->bss_index
;
1568 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1570 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1572 wcn36xx_err("Sending hal_exit_bmps failed\n");
1575 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1577 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret
);
1581 mutex_unlock(&wcn
->hal_mutex
);
1584 int wcn36xx_smd_set_power_params(struct wcn36xx
*wcn
, bool ignore_dtim
)
1586 struct wcn36xx_hal_set_power_params_req_msg msg_body
;
1589 mutex_lock(&wcn
->hal_mutex
);
1590 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_POWER_PARAMS_REQ
);
1593 * When host is down ignore every second dtim
1596 msg_body
.ignore_dtim
= 1;
1597 msg_body
.dtim_period
= 2;
1599 msg_body
.listen_interval
= WCN36XX_LISTEN_INTERVAL(wcn
);
1601 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1603 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1605 wcn36xx_err("Sending hal_set_power_params failed\n");
1610 mutex_unlock(&wcn
->hal_mutex
);
1613 /* Notice: This function should be called after associated, or else it
1616 int wcn36xx_smd_keep_alive_req(struct wcn36xx
*wcn
,
1617 struct ieee80211_vif
*vif
,
1620 struct wcn36xx_hal_keep_alive_req_msg msg_body
;
1621 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1624 mutex_lock(&wcn
->hal_mutex
);
1625 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_KEEP_ALIVE_REQ
);
1627 if (packet_type
== WCN36XX_HAL_KEEP_ALIVE_NULL_PKT
) {
1628 msg_body
.bss_index
= vif_priv
->bss_index
;
1629 msg_body
.packet_type
= WCN36XX_HAL_KEEP_ALIVE_NULL_PKT
;
1630 msg_body
.time_period
= WCN36XX_KEEP_ALIVE_TIME_PERIOD
;
1631 } else if (packet_type
== WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP
) {
1632 /* TODO: it also support ARP response type */
1634 wcn36xx_warn("unknow keep alive packet type %d\n", packet_type
);
1639 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1641 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1643 wcn36xx_err("Sending hal_keep_alive failed\n");
1646 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1648 wcn36xx_err("hal_keep_alive response failed err=%d\n", ret
);
1652 mutex_unlock(&wcn
->hal_mutex
);
1656 int wcn36xx_smd_dump_cmd_req(struct wcn36xx
*wcn
, u32 arg1
, u32 arg2
,
1657 u32 arg3
, u32 arg4
, u32 arg5
)
1659 struct wcn36xx_hal_dump_cmd_req_msg msg_body
;
1662 mutex_lock(&wcn
->hal_mutex
);
1663 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DUMP_COMMAND_REQ
);
1665 msg_body
.arg1
= arg1
;
1666 msg_body
.arg2
= arg2
;
1667 msg_body
.arg3
= arg3
;
1668 msg_body
.arg4
= arg4
;
1669 msg_body
.arg5
= arg5
;
1671 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1673 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1675 wcn36xx_err("Sending hal_dump_cmd failed\n");
1678 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1680 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret
);
1684 mutex_unlock(&wcn
->hal_mutex
);
1688 static inline void set_feat_caps(u32
*bitmap
,
1689 enum place_holder_in_cap_bitmap cap
)
1691 int arr_idx
, bit_idx
;
1693 if (cap
< 0 || cap
> 127) {
1694 wcn36xx_warn("error cap idx %d\n", cap
);
1700 bitmap
[arr_idx
] |= (1 << bit_idx
);
1703 static inline int get_feat_caps(u32
*bitmap
,
1704 enum place_holder_in_cap_bitmap cap
)
1706 int arr_idx
, bit_idx
;
1709 if (cap
< 0 || cap
> 127) {
1710 wcn36xx_warn("error cap idx %d\n", cap
);
1716 ret
= (bitmap
[arr_idx
] & (1 << bit_idx
)) ? 1 : 0;
1720 static inline void clear_feat_caps(u32
*bitmap
,
1721 enum place_holder_in_cap_bitmap cap
)
1723 int arr_idx
, bit_idx
;
1725 if (cap
< 0 || cap
> 127) {
1726 wcn36xx_warn("error cap idx %d\n", cap
);
1732 bitmap
[arr_idx
] &= ~(1 << bit_idx
);
1735 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx
*wcn
)
1737 struct wcn36xx_hal_feat_caps_msg msg_body
, *rsp
;
1740 mutex_lock(&wcn
->hal_mutex
);
1741 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ
);
1743 set_feat_caps(msg_body
.feat_caps
, STA_POWERSAVE
);
1745 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1747 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1749 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1752 if (wcn
->hal_rsp_len
!= sizeof(*rsp
)) {
1753 wcn36xx_err("Invalid hal_feature_caps_exchange response");
1757 rsp
= (struct wcn36xx_hal_feat_caps_msg
*) wcn
->hal_buf
;
1759 for (i
= 0; i
< WCN36XX_HAL_CAPS_SIZE
; i
++)
1760 wcn
->fw_feat_caps
[i
] = rsp
->feat_caps
[i
];
1762 mutex_unlock(&wcn
->hal_mutex
);
1766 int wcn36xx_smd_add_ba_session(struct wcn36xx
*wcn
,
1767 struct ieee80211_sta
*sta
,
1773 struct wcn36xx_hal_add_ba_session_req_msg msg_body
;
1776 mutex_lock(&wcn
->hal_mutex
);
1777 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_BA_SESSION_REQ
);
1779 msg_body
.sta_index
= sta_index
;
1780 memcpy(&msg_body
.mac_addr
, sta
->addr
, ETH_ALEN
);
1781 msg_body
.dialog_token
= 0x10;
1784 /* Immediate BA because Delayed BA is not supported */
1785 msg_body
.policy
= 1;
1786 msg_body
.buffer_size
= WCN36XX_AGGR_BUFFER_SIZE
;
1787 msg_body
.timeout
= 0;
1789 msg_body
.ssn
= *ssn
;
1790 msg_body
.direction
= direction
;
1792 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1794 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1796 wcn36xx_err("Sending hal_add_ba_session failed\n");
1799 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1801 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret
);
1805 mutex_unlock(&wcn
->hal_mutex
);
1809 int wcn36xx_smd_add_ba(struct wcn36xx
*wcn
)
1811 struct wcn36xx_hal_add_ba_req_msg msg_body
;
1814 mutex_lock(&wcn
->hal_mutex
);
1815 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_BA_REQ
);
1817 msg_body
.session_id
= 0;
1818 msg_body
.win_size
= WCN36XX_AGGR_BUFFER_SIZE
;
1820 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1822 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1824 wcn36xx_err("Sending hal_add_ba failed\n");
1827 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1829 wcn36xx_err("hal_add_ba response failed err=%d\n", ret
);
1833 mutex_unlock(&wcn
->hal_mutex
);
1837 int wcn36xx_smd_del_ba(struct wcn36xx
*wcn
, u16 tid
, u8 sta_index
)
1839 struct wcn36xx_hal_del_ba_req_msg msg_body
;
1842 mutex_lock(&wcn
->hal_mutex
);
1843 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DEL_BA_REQ
);
1845 msg_body
.sta_index
= sta_index
;
1847 msg_body
.direction
= 0;
1848 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1850 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1852 wcn36xx_err("Sending hal_del_ba failed\n");
1855 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1857 wcn36xx_err("hal_del_ba response failed err=%d\n", ret
);
1861 mutex_unlock(&wcn
->hal_mutex
);
1865 int wcn36xx_smd_trigger_ba(struct wcn36xx
*wcn
, u8 sta_index
)
1867 struct wcn36xx_hal_trigger_ba_req_msg msg_body
;
1868 struct wcn36xx_hal_trigger_ba_req_candidate
*candidate
;
1871 mutex_lock(&wcn
->hal_mutex
);
1872 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_TRIGGER_BA_REQ
);
1874 msg_body
.session_id
= 0;
1875 msg_body
.candidate_cnt
= 1;
1876 msg_body
.header
.len
+= sizeof(*candidate
);
1877 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1879 candidate
= (struct wcn36xx_hal_trigger_ba_req_candidate
*)
1880 (wcn
->hal_buf
+ sizeof(msg_body
));
1881 candidate
->sta_index
= sta_index
;
1882 candidate
->tid_bitmap
= 1;
1884 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1886 wcn36xx_err("Sending hal_trigger_ba failed\n");
1889 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1891 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret
);
1895 mutex_unlock(&wcn
->hal_mutex
);
1899 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx
*wcn
, void *buf
, size_t len
)
1901 struct wcn36xx_hal_tx_compl_ind_msg
*rsp
= buf
;
1903 if (len
!= sizeof(*rsp
)) {
1904 wcn36xx_warn("Bad TX complete indication\n");
1908 wcn36xx_dxe_tx_ack_ind(wcn
, rsp
->status
);
1913 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx
*wcn
,
1917 struct wcn36xx_hal_missed_beacon_ind_msg
*rsp
= buf
;
1918 struct ieee80211_vif
*vif
= NULL
;
1919 struct wcn36xx_vif
*tmp
;
1921 /* Old FW does not have bss index */
1922 if (wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
1923 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
1924 wcn36xx_dbg(WCN36XX_DBG_HAL
, "beacon missed bss_index %d\n",
1926 vif
= container_of((void *)tmp
,
1927 struct ieee80211_vif
,
1929 ieee80211_connection_loss(vif
);
1934 if (len
!= sizeof(*rsp
)) {
1935 wcn36xx_warn("Corrupted missed beacon indication\n");
1939 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
1940 if (tmp
->bss_index
== rsp
->bss_index
) {
1941 wcn36xx_dbg(WCN36XX_DBG_HAL
, "beacon missed bss_index %d\n",
1943 vif
= container_of((void *)tmp
,
1944 struct ieee80211_vif
,
1946 ieee80211_connection_loss(vif
);
1951 wcn36xx_warn("BSS index %d not found\n", rsp
->bss_index
);
1955 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx
*wcn
,
1959 struct wcn36xx_hal_delete_sta_context_ind_msg
*rsp
= buf
;
1960 struct wcn36xx_vif
*tmp
;
1961 struct ieee80211_sta
*sta
= NULL
;
1963 if (len
!= sizeof(*rsp
)) {
1964 wcn36xx_warn("Corrupted delete sta indication\n");
1968 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
1969 if (sta
&& (tmp
->sta
->sta_index
== rsp
->sta_id
)) {
1970 sta
= container_of((void *)tmp
->sta
,
1971 struct ieee80211_sta
,
1973 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1974 "delete station indication %pM index %d\n",
1977 ieee80211_report_low_ack(sta
, 0);
1982 wcn36xx_warn("STA with addr %pM and index %d not found\n",
1988 int wcn36xx_smd_update_cfg(struct wcn36xx
*wcn
, u32 cfg_id
, u32 value
)
1990 struct wcn36xx_hal_update_cfg_req_msg msg_body
, *body
;
1994 mutex_lock(&wcn
->hal_mutex
);
1995 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_UPDATE_CFG_REQ
);
1997 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1999 body
= (struct wcn36xx_hal_update_cfg_req_msg
*) wcn
->hal_buf
;
2000 len
= msg_body
.header
.len
;
2002 put_cfg_tlv_u32(wcn
, &len
, cfg_id
, value
);
2003 body
->header
.len
= len
;
2004 body
->len
= len
- sizeof(*body
);
2006 ret
= wcn36xx_smd_send_and_wait(wcn
, body
->header
.len
);
2008 wcn36xx_err("Sending hal_update_cfg failed\n");
2011 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
2013 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret
);
2017 mutex_unlock(&wcn
->hal_mutex
);
2020 static void wcn36xx_smd_rsp_process(struct wcn36xx
*wcn
, void *buf
, size_t len
)
2022 struct wcn36xx_hal_msg_header
*msg_header
= buf
;
2023 struct wcn36xx_hal_ind_msg
*msg_ind
;
2024 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP
, "SMD <<< ", buf
, len
);
2026 switch (msg_header
->msg_type
) {
2027 case WCN36XX_HAL_START_RSP
:
2028 case WCN36XX_HAL_CONFIG_STA_RSP
:
2029 case WCN36XX_HAL_CONFIG_BSS_RSP
:
2030 case WCN36XX_HAL_ADD_STA_SELF_RSP
:
2031 case WCN36XX_HAL_STOP_RSP
:
2032 case WCN36XX_HAL_DEL_STA_SELF_RSP
:
2033 case WCN36XX_HAL_DELETE_STA_RSP
:
2034 case WCN36XX_HAL_INIT_SCAN_RSP
:
2035 case WCN36XX_HAL_START_SCAN_RSP
:
2036 case WCN36XX_HAL_END_SCAN_RSP
:
2037 case WCN36XX_HAL_FINISH_SCAN_RSP
:
2038 case WCN36XX_HAL_DOWNLOAD_NV_RSP
:
2039 case WCN36XX_HAL_DELETE_BSS_RSP
:
2040 case WCN36XX_HAL_SEND_BEACON_RSP
:
2041 case WCN36XX_HAL_SET_LINK_ST_RSP
:
2042 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP
:
2043 case WCN36XX_HAL_SET_BSSKEY_RSP
:
2044 case WCN36XX_HAL_SET_STAKEY_RSP
:
2045 case WCN36XX_HAL_RMV_STAKEY_RSP
:
2046 case WCN36XX_HAL_RMV_BSSKEY_RSP
:
2047 case WCN36XX_HAL_ENTER_BMPS_RSP
:
2048 case WCN36XX_HAL_SET_POWER_PARAMS_RSP
:
2049 case WCN36XX_HAL_EXIT_BMPS_RSP
:
2050 case WCN36XX_HAL_KEEP_ALIVE_RSP
:
2051 case WCN36XX_HAL_DUMP_COMMAND_RSP
:
2052 case WCN36XX_HAL_ADD_BA_SESSION_RSP
:
2053 case WCN36XX_HAL_ADD_BA_RSP
:
2054 case WCN36XX_HAL_DEL_BA_RSP
:
2055 case WCN36XX_HAL_TRIGGER_BA_RSP
:
2056 case WCN36XX_HAL_UPDATE_CFG_RSP
:
2057 case WCN36XX_HAL_JOIN_RSP
:
2058 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP
:
2059 case WCN36XX_HAL_CH_SWITCH_RSP
:
2060 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP
:
2061 memcpy(wcn
->hal_buf
, buf
, len
);
2062 wcn
->hal_rsp_len
= len
;
2063 complete(&wcn
->hal_rsp_compl
);
2066 case WCN36XX_HAL_OTA_TX_COMPL_IND
:
2067 case WCN36XX_HAL_MISSED_BEACON_IND
:
2068 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND
:
2069 msg_ind
= kmalloc(sizeof(*msg_ind
), GFP_KERNEL
);
2072 msg_ind
->msg_len
= len
;
2073 msg_ind
->msg
= kmalloc(len
, GFP_KERNEL
);
2074 if (!msg_ind
->msg
) {
2078 * FIXME: Do something smarter then just
2079 * printing an error.
2081 wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
2082 msg_header
->msg_type
);
2085 memcpy(msg_ind
->msg
, buf
, len
);
2086 mutex_lock(&wcn
->hal_ind_mutex
);
2087 list_add_tail(&msg_ind
->list
, &wcn
->hal_ind_queue
);
2088 queue_work(wcn
->hal_ind_wq
, &wcn
->hal_ind_work
);
2089 mutex_unlock(&wcn
->hal_ind_mutex
);
2090 wcn36xx_dbg(WCN36XX_DBG_HAL
, "indication arrived\n");
2093 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2094 msg_header
->msg_type
);
2097 static void wcn36xx_ind_smd_work(struct work_struct
*work
)
2099 struct wcn36xx
*wcn
=
2100 container_of(work
, struct wcn36xx
, hal_ind_work
);
2101 struct wcn36xx_hal_msg_header
*msg_header
;
2102 struct wcn36xx_hal_ind_msg
*hal_ind_msg
;
2104 mutex_lock(&wcn
->hal_ind_mutex
);
2106 hal_ind_msg
= list_first_entry(&wcn
->hal_ind_queue
,
2107 struct wcn36xx_hal_ind_msg
,
2110 msg_header
= (struct wcn36xx_hal_msg_header
*)hal_ind_msg
->msg
;
2112 switch (msg_header
->msg_type
) {
2113 case WCN36XX_HAL_OTA_TX_COMPL_IND
:
2114 wcn36xx_smd_tx_compl_ind(wcn
,
2116 hal_ind_msg
->msg_len
);
2118 case WCN36XX_HAL_MISSED_BEACON_IND
:
2119 wcn36xx_smd_missed_beacon_ind(wcn
,
2121 hal_ind_msg
->msg_len
);
2123 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND
:
2124 wcn36xx_smd_delete_sta_context_ind(wcn
,
2126 hal_ind_msg
->msg_len
);
2129 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2130 msg_header
->msg_type
);
2132 list_del(wcn
->hal_ind_queue
.next
);
2133 kfree(hal_ind_msg
->msg
);
2135 mutex_unlock(&wcn
->hal_ind_mutex
);
2137 int wcn36xx_smd_open(struct wcn36xx
*wcn
)
2140 wcn
->hal_ind_wq
= create_freezable_workqueue("wcn36xx_smd_ind");
2141 if (!wcn
->hal_ind_wq
) {
2142 wcn36xx_err("failed to allocate wq\n");
2146 INIT_WORK(&wcn
->hal_ind_work
, wcn36xx_ind_smd_work
);
2147 INIT_LIST_HEAD(&wcn
->hal_ind_queue
);
2148 mutex_init(&wcn
->hal_ind_mutex
);
2150 ret
= wcn
->ctrl_ops
->open(wcn
, wcn36xx_smd_rsp_process
);
2152 wcn36xx_err("failed to open control channel\n");
2159 destroy_workqueue(wcn
->hal_ind_wq
);
2164 void wcn36xx_smd_close(struct wcn36xx
*wcn
)
2166 wcn
->ctrl_ops
->close();
2167 destroy_workqueue(wcn
->hal_ind_wq
);
2168 mutex_destroy(&wcn
->hal_ind_mutex
);