2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/etherdevice.h>
20 #include <linux/firmware.h>
21 #include <linux/bitops.h>
24 struct wcn36xx_cfg_val
{
29 #define WCN36XX_CFG_VAL(id, val) \
31 .cfg_id = WCN36XX_HAL_CFG_ ## id, \
35 static struct wcn36xx_cfg_val wcn36xx_cfg_vals
[] = {
36 WCN36XX_CFG_VAL(CURRENT_TX_ANTENNA
, 1),
37 WCN36XX_CFG_VAL(CURRENT_RX_ANTENNA
, 1),
38 WCN36XX_CFG_VAL(LOW_GAIN_OVERRIDE
, 0),
39 WCN36XX_CFG_VAL(POWER_STATE_PER_CHAIN
, 785),
40 WCN36XX_CFG_VAL(CAL_PERIOD
, 5),
41 WCN36XX_CFG_VAL(CAL_CONTROL
, 1),
42 WCN36XX_CFG_VAL(PROXIMITY
, 0),
43 WCN36XX_CFG_VAL(NETWORK_DENSITY
, 3),
44 WCN36XX_CFG_VAL(MAX_MEDIUM_TIME
, 6000),
45 WCN36XX_CFG_VAL(MAX_MPDUS_IN_AMPDU
, 64),
46 WCN36XX_CFG_VAL(RTS_THRESHOLD
, 2347),
47 WCN36XX_CFG_VAL(SHORT_RETRY_LIMIT
, 6),
48 WCN36XX_CFG_VAL(LONG_RETRY_LIMIT
, 6),
49 WCN36XX_CFG_VAL(FRAGMENTATION_THRESHOLD
, 8000),
50 WCN36XX_CFG_VAL(DYNAMIC_THRESHOLD_ZERO
, 5),
51 WCN36XX_CFG_VAL(DYNAMIC_THRESHOLD_ONE
, 10),
52 WCN36XX_CFG_VAL(DYNAMIC_THRESHOLD_TWO
, 15),
53 WCN36XX_CFG_VAL(FIXED_RATE
, 0),
54 WCN36XX_CFG_VAL(RETRYRATE_POLICY
, 4),
55 WCN36XX_CFG_VAL(RETRYRATE_SECONDARY
, 0),
56 WCN36XX_CFG_VAL(RETRYRATE_TERTIARY
, 0),
57 WCN36XX_CFG_VAL(FORCE_POLICY_PROTECTION
, 5),
58 WCN36XX_CFG_VAL(FIXED_RATE_MULTICAST_24GHZ
, 1),
59 WCN36XX_CFG_VAL(FIXED_RATE_MULTICAST_5GHZ
, 5),
60 WCN36XX_CFG_VAL(DEFAULT_RATE_INDEX_5GHZ
, 5),
61 WCN36XX_CFG_VAL(MAX_BA_SESSIONS
, 40),
62 WCN36XX_CFG_VAL(PS_DATA_INACTIVITY_TIMEOUT
, 200),
63 WCN36XX_CFG_VAL(PS_ENABLE_BCN_FILTER
, 1),
64 WCN36XX_CFG_VAL(PS_ENABLE_RSSI_MONITOR
, 1),
65 WCN36XX_CFG_VAL(NUM_BEACON_PER_RSSI_AVERAGE
, 20),
66 WCN36XX_CFG_VAL(STATS_PERIOD
, 10),
67 WCN36XX_CFG_VAL(CFP_MAX_DURATION
, 30000),
68 WCN36XX_CFG_VAL(FRAME_TRANS_ENABLED
, 0),
69 WCN36XX_CFG_VAL(BA_THRESHOLD_HIGH
, 128),
70 WCN36XX_CFG_VAL(MAX_BA_BUFFERS
, 2560),
71 WCN36XX_CFG_VAL(DYNAMIC_PS_POLL_VALUE
, 0),
72 WCN36XX_CFG_VAL(TX_PWR_CTRL_ENABLE
, 1),
73 WCN36XX_CFG_VAL(ENABLE_CLOSE_LOOP
, 1),
74 WCN36XX_CFG_VAL(ENABLE_LPWR_IMG_TRANSITION
, 0),
75 WCN36XX_CFG_VAL(MAX_ASSOC_LIMIT
, 10),
76 WCN36XX_CFG_VAL(ENABLE_MCC_ADAPTIVE_SCHEDULER
, 0),
79 static int put_cfg_tlv_u32(struct wcn36xx
*wcn
, size_t *len
, u32 id
, u32 value
)
81 struct wcn36xx_hal_cfg
*entry
;
84 if (*len
+ sizeof(*entry
) + sizeof(u32
) >= WCN36XX_HAL_BUF_SIZE
) {
85 wcn36xx_err("Not enough room for TLV entry\n");
89 entry
= (struct wcn36xx_hal_cfg
*) (wcn
->hal_buf
+ *len
);
91 entry
->len
= sizeof(u32
);
95 val
= (u32
*) (entry
+ 1);
98 *len
+= sizeof(*entry
) + sizeof(u32
);
103 static void wcn36xx_smd_set_bss_nw_type(struct wcn36xx
*wcn
,
104 struct ieee80211_sta
*sta
,
105 struct wcn36xx_hal_config_bss_params
*bss_params
)
107 if (IEEE80211_BAND_5GHZ
== WCN36XX_BAND(wcn
))
108 bss_params
->nw_type
= WCN36XX_HAL_11A_NW_TYPE
;
109 else if (sta
&& sta
->ht_cap
.ht_supported
)
110 bss_params
->nw_type
= WCN36XX_HAL_11N_NW_TYPE
;
111 else if (sta
&& (sta
->supp_rates
[IEEE80211_BAND_2GHZ
] & 0x7f))
112 bss_params
->nw_type
= WCN36XX_HAL_11G_NW_TYPE
;
114 bss_params
->nw_type
= WCN36XX_HAL_11B_NW_TYPE
;
117 static inline u8
is_cap_supported(unsigned long caps
, unsigned long flag
)
119 return caps
& flag
? 1 : 0;
121 static void wcn36xx_smd_set_bss_ht_params(struct ieee80211_vif
*vif
,
122 struct ieee80211_sta
*sta
,
123 struct wcn36xx_hal_config_bss_params
*bss_params
)
125 if (sta
&& sta
->ht_cap
.ht_supported
) {
126 unsigned long caps
= sta
->ht_cap
.cap
;
127 bss_params
->ht
= sta
->ht_cap
.ht_supported
;
128 bss_params
->tx_channel_width_set
= is_cap_supported(caps
,
129 IEEE80211_HT_CAP_SUP_WIDTH_20_40
);
130 bss_params
->lsig_tx_op_protection_full_support
=
131 is_cap_supported(caps
,
132 IEEE80211_HT_CAP_LSIG_TXOP_PROT
);
134 bss_params
->ht_oper_mode
= vif
->bss_conf
.ht_operation_mode
;
135 bss_params
->lln_non_gf_coexist
=
136 !!(vif
->bss_conf
.ht_operation_mode
&
137 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
138 /* IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT */
139 bss_params
->dual_cts_protection
= 0;
140 /* IEEE80211_HT_OP_MODE_PROTECTION_20MHZ */
141 bss_params
->ht20_coexist
= 0;
145 static void wcn36xx_smd_set_sta_ht_params(struct ieee80211_sta
*sta
,
146 struct wcn36xx_hal_config_sta_params
*sta_params
)
148 if (sta
->ht_cap
.ht_supported
) {
149 unsigned long caps
= sta
->ht_cap
.cap
;
150 sta_params
->ht_capable
= sta
->ht_cap
.ht_supported
;
151 sta_params
->tx_channel_width_set
= is_cap_supported(caps
,
152 IEEE80211_HT_CAP_SUP_WIDTH_20_40
);
153 sta_params
->lsig_txop_protection
= is_cap_supported(caps
,
154 IEEE80211_HT_CAP_LSIG_TXOP_PROT
);
156 sta_params
->max_ampdu_size
= sta
->ht_cap
.ampdu_factor
;
157 sta_params
->max_ampdu_density
= sta
->ht_cap
.ampdu_density
;
158 sta_params
->max_amsdu_size
= is_cap_supported(caps
,
159 IEEE80211_HT_CAP_MAX_AMSDU
);
160 sta_params
->sgi_20Mhz
= is_cap_supported(caps
,
161 IEEE80211_HT_CAP_SGI_20
);
162 sta_params
->sgi_40mhz
= is_cap_supported(caps
,
163 IEEE80211_HT_CAP_SGI_40
);
164 sta_params
->green_field_capable
= is_cap_supported(caps
,
165 IEEE80211_HT_CAP_GRN_FLD
);
166 sta_params
->delayed_ba_support
= is_cap_supported(caps
,
167 IEEE80211_HT_CAP_DELAY_BA
);
168 sta_params
->dsss_cck_mode_40mhz
= is_cap_supported(caps
,
169 IEEE80211_HT_CAP_DSSSCCK40
);
173 static void wcn36xx_smd_set_sta_default_ht_params(
174 struct wcn36xx_hal_config_sta_params
*sta_params
)
176 sta_params
->ht_capable
= 1;
177 sta_params
->tx_channel_width_set
= 1;
178 sta_params
->lsig_txop_protection
= 1;
179 sta_params
->max_ampdu_size
= 3;
180 sta_params
->max_ampdu_density
= 5;
181 sta_params
->max_amsdu_size
= 0;
182 sta_params
->sgi_20Mhz
= 1;
183 sta_params
->sgi_40mhz
= 1;
184 sta_params
->green_field_capable
= 1;
185 sta_params
->delayed_ba_support
= 0;
186 sta_params
->dsss_cck_mode_40mhz
= 1;
189 static void wcn36xx_smd_set_sta_params(struct wcn36xx
*wcn
,
190 struct ieee80211_vif
*vif
,
191 struct ieee80211_sta
*sta
,
192 struct wcn36xx_hal_config_sta_params
*sta_params
)
194 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
195 struct wcn36xx_sta
*priv_sta
= NULL
;
196 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
197 vif
->type
== NL80211_IFTYPE_AP
||
198 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
199 sta_params
->type
= 1;
200 sta_params
->sta_index
= 0xFF;
202 sta_params
->type
= 0;
203 sta_params
->sta_index
= 1;
206 sta_params
->listen_interval
= WCN36XX_LISTEN_INTERVAL(wcn
);
209 * In STA mode ieee80211_sta contains bssid and ieee80211_vif
210 * contains our mac address. In AP mode we are bssid so vif
211 * contains bssid and ieee80211_sta contains mac.
213 if (NL80211_IFTYPE_STATION
== vif
->type
)
214 memcpy(&sta_params
->mac
, vif
->addr
, ETH_ALEN
);
216 memcpy(&sta_params
->bssid
, vif
->addr
, ETH_ALEN
);
218 sta_params
->encrypt_type
= priv_vif
->encrypt_type
;
219 sta_params
->short_preamble_supported
=
220 !(WCN36XX_FLAGS(wcn
) &
221 IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
);
223 sta_params
->rifs_mode
= 0;
225 sta_params
->action
= 0;
226 sta_params
->uapsd
= 0;
227 sta_params
->mimo_ps
= WCN36XX_HAL_HT_MIMO_PS_STATIC
;
228 sta_params
->max_ampdu_duration
= 0;
229 sta_params
->bssid_index
= priv_vif
->bss_index
;
233 priv_sta
= (struct wcn36xx_sta
*)sta
->drv_priv
;
234 if (NL80211_IFTYPE_STATION
== vif
->type
)
235 memcpy(&sta_params
->bssid
, sta
->addr
, ETH_ALEN
);
237 memcpy(&sta_params
->mac
, sta
->addr
, ETH_ALEN
);
238 sta_params
->wmm_enabled
= sta
->wme
;
239 sta_params
->max_sp_len
= sta
->max_sp
;
240 sta_params
->aid
= priv_sta
->aid
;
241 wcn36xx_smd_set_sta_ht_params(sta
, sta_params
);
242 memcpy(&sta_params
->supported_rates
, &priv_sta
->supported_rates
,
243 sizeof(priv_sta
->supported_rates
));
245 wcn36xx_set_default_rates(&sta_params
->supported_rates
);
246 wcn36xx_smd_set_sta_default_ht_params(sta_params
);
250 static int wcn36xx_smd_send_and_wait(struct wcn36xx
*wcn
, size_t len
)
254 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP
, "HAL >>> ", wcn
->hal_buf
, len
);
256 init_completion(&wcn
->hal_rsp_compl
);
258 ret
= wcn
->ctrl_ops
->tx(wcn
->hal_buf
, len
);
260 wcn36xx_err("HAL TX failed\n");
263 if (wait_for_completion_timeout(&wcn
->hal_rsp_compl
,
264 msecs_to_jiffies(HAL_MSG_TIMEOUT
)) <= 0) {
265 wcn36xx_err("Timeout! No SMD response in %dms\n",
270 wcn36xx_dbg(WCN36XX_DBG_SMD
, "SMD command completed in %dms",
271 jiffies_to_msecs(jiffies
- start
));
276 #define INIT_HAL_MSG(msg_body, type) \
278 memset(&msg_body, 0, sizeof(msg_body)); \
279 msg_body.header.msg_type = type; \
280 msg_body.header.msg_version = WCN36XX_HAL_MSG_VERSION0; \
281 msg_body.header.len = sizeof(msg_body); \
284 #define PREPARE_HAL_BUF(send_buf, msg_body) \
286 memset(send_buf, 0, msg_body.header.len); \
287 memcpy(send_buf, &msg_body, sizeof(msg_body)); \
290 static int wcn36xx_smd_rsp_status_check(void *buf, size_t len)
292 struct wcn36xx_fw_msg_status_rsp
*rsp
;
294 if (len
< sizeof(struct wcn36xx_hal_msg_header
) +
295 sizeof(struct wcn36xx_fw_msg_status_rsp
))
298 rsp
= (struct wcn36xx_fw_msg_status_rsp
*)
299 (buf
+ sizeof(struct wcn36xx_hal_msg_header
));
301 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->status
)
307 int wcn36xx_smd_load_nv(struct wcn36xx
*wcn
)
309 struct nv_data
*nv_d
;
310 struct wcn36xx_hal_nv_img_download_req_msg msg_body
;
316 ret
= request_firmware(&wcn
->nv
, WLAN_NV_FILE
, wcn
->dev
);
318 wcn36xx_err("Failed to load nv file %s: %d\n",
324 nv_d
= (struct nv_data
*)wcn
->nv
->data
;
325 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DOWNLOAD_NV_REQ
);
327 msg_body
.header
.len
+= WCN36XX_NV_FRAGMENT_SIZE
;
329 msg_body
.frag_number
= 0;
330 /* hal_buf must be protected with mutex */
331 mutex_lock(&wcn
->hal_mutex
);
334 fw_bytes_left
= wcn
->nv
->size
- fm_offset
- 4;
335 if (fw_bytes_left
> WCN36XX_NV_FRAGMENT_SIZE
) {
336 msg_body
.last_fragment
= 0;
337 msg_body
.nv_img_buffer_size
= WCN36XX_NV_FRAGMENT_SIZE
;
339 msg_body
.last_fragment
= 1;
340 msg_body
.nv_img_buffer_size
= fw_bytes_left
;
342 /* Do not forget update general message len */
343 msg_body
.header
.len
= sizeof(msg_body
) + fw_bytes_left
;
347 /* Add load NV request message header */
348 memcpy(wcn
->hal_buf
, &msg_body
, sizeof(msg_body
));
350 /* Add NV body itself */
351 memcpy(wcn
->hal_buf
+ sizeof(msg_body
),
352 &nv_d
->table
+ fm_offset
,
353 msg_body
.nv_img_buffer_size
);
355 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
358 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
,
361 wcn36xx_err("hal_load_nv response failed err=%d\n",
365 msg_body
.frag_number
++;
366 fm_offset
+= WCN36XX_NV_FRAGMENT_SIZE
;
368 } while (msg_body
.last_fragment
!= 1);
371 mutex_unlock(&wcn
->hal_mutex
);
375 static int wcn36xx_smd_start_rsp(struct wcn36xx
*wcn
, void *buf
, size_t len
)
377 struct wcn36xx_hal_mac_start_rsp_msg
*rsp
;
379 if (len
< sizeof(*rsp
))
382 rsp
= (struct wcn36xx_hal_mac_start_rsp_msg
*)buf
;
384 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->start_rsp_params
.status
)
387 memcpy(wcn
->crm_version
, rsp
->start_rsp_params
.crm_version
,
388 WCN36XX_HAL_VERSION_LENGTH
);
389 memcpy(wcn
->wlan_version
, rsp
->start_rsp_params
.wlan_version
,
390 WCN36XX_HAL_VERSION_LENGTH
);
392 /* null terminate the strings, just in case */
393 wcn
->crm_version
[WCN36XX_HAL_VERSION_LENGTH
] = '\0';
394 wcn
->wlan_version
[WCN36XX_HAL_VERSION_LENGTH
] = '\0';
396 wcn
->fw_revision
= rsp
->start_rsp_params
.version
.revision
;
397 wcn
->fw_version
= rsp
->start_rsp_params
.version
.version
;
398 wcn
->fw_minor
= rsp
->start_rsp_params
.version
.minor
;
399 wcn
->fw_major
= rsp
->start_rsp_params
.version
.major
;
401 wcn36xx_info("firmware WLAN version '%s' and CRM version '%s'\n",
402 wcn
->wlan_version
, wcn
->crm_version
);
404 wcn36xx_info("firmware API %u.%u.%u.%u, %u stations, %u bssids\n",
405 wcn
->fw_major
, wcn
->fw_minor
,
406 wcn
->fw_version
, wcn
->fw_revision
,
407 rsp
->start_rsp_params
.stations
,
408 rsp
->start_rsp_params
.bssids
);
413 int wcn36xx_smd_start(struct wcn36xx
*wcn
)
415 struct wcn36xx_hal_mac_start_req_msg msg_body
, *body
;
420 mutex_lock(&wcn
->hal_mutex
);
421 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_START_REQ
);
423 msg_body
.params
.type
= DRIVER_TYPE_PRODUCTION
;
424 msg_body
.params
.len
= 0;
426 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
428 body
= (struct wcn36xx_hal_mac_start_req_msg
*)wcn
->hal_buf
;
429 len
= body
->header
.len
;
431 for (i
= 0; i
< ARRAY_SIZE(wcn36xx_cfg_vals
); i
++) {
432 ret
= put_cfg_tlv_u32(wcn
, &len
, wcn36xx_cfg_vals
[i
].cfg_id
,
433 wcn36xx_cfg_vals
[i
].value
);
437 body
->header
.len
= len
;
438 body
->params
.len
= len
- sizeof(*body
);
440 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal start type %d\n",
441 msg_body
.params
.type
);
443 ret
= wcn36xx_smd_send_and_wait(wcn
, body
->header
.len
);
445 wcn36xx_err("Sending hal_start failed\n");
449 ret
= wcn36xx_smd_start_rsp(wcn
, wcn
->hal_buf
, wcn
->hal_rsp_len
);
451 wcn36xx_err("hal_start response failed err=%d\n", ret
);
456 mutex_unlock(&wcn
->hal_mutex
);
460 int wcn36xx_smd_stop(struct wcn36xx
*wcn
)
462 struct wcn36xx_hal_mac_stop_req_msg msg_body
;
465 mutex_lock(&wcn
->hal_mutex
);
466 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_STOP_REQ
);
468 msg_body
.stop_req_params
.reason
= HAL_STOP_TYPE_RF_KILL
;
470 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
472 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
474 wcn36xx_err("Sending hal_stop failed\n");
477 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
479 wcn36xx_err("hal_stop response failed err=%d\n", ret
);
483 mutex_unlock(&wcn
->hal_mutex
);
487 int wcn36xx_smd_init_scan(struct wcn36xx
*wcn
, enum wcn36xx_hal_sys_mode mode
)
489 struct wcn36xx_hal_init_scan_req_msg msg_body
;
492 mutex_lock(&wcn
->hal_mutex
);
493 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_INIT_SCAN_REQ
);
495 msg_body
.mode
= mode
;
497 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
499 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal init scan mode %d\n", msg_body
.mode
);
501 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
503 wcn36xx_err("Sending hal_init_scan failed\n");
506 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
508 wcn36xx_err("hal_init_scan response failed err=%d\n", ret
);
512 mutex_unlock(&wcn
->hal_mutex
);
516 int wcn36xx_smd_start_scan(struct wcn36xx
*wcn
)
518 struct wcn36xx_hal_start_scan_req_msg msg_body
;
521 mutex_lock(&wcn
->hal_mutex
);
522 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_START_SCAN_REQ
);
524 msg_body
.scan_channel
= WCN36XX_HW_CHANNEL(wcn
);
526 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
528 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal start scan channel %d\n",
529 msg_body
.scan_channel
);
531 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
533 wcn36xx_err("Sending hal_start_scan failed\n");
536 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
538 wcn36xx_err("hal_start_scan response failed err=%d\n", ret
);
542 mutex_unlock(&wcn
->hal_mutex
);
546 int wcn36xx_smd_end_scan(struct wcn36xx
*wcn
)
548 struct wcn36xx_hal_end_scan_req_msg msg_body
;
551 mutex_lock(&wcn
->hal_mutex
);
552 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_END_SCAN_REQ
);
554 msg_body
.scan_channel
= WCN36XX_HW_CHANNEL(wcn
);
556 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
558 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal end scan channel %d\n",
559 msg_body
.scan_channel
);
561 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
563 wcn36xx_err("Sending hal_end_scan failed\n");
566 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
568 wcn36xx_err("hal_end_scan response failed err=%d\n", ret
);
572 mutex_unlock(&wcn
->hal_mutex
);
576 int wcn36xx_smd_finish_scan(struct wcn36xx
*wcn
,
577 enum wcn36xx_hal_sys_mode mode
)
579 struct wcn36xx_hal_finish_scan_req_msg msg_body
;
582 mutex_lock(&wcn
->hal_mutex
);
583 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_FINISH_SCAN_REQ
);
585 msg_body
.mode
= mode
;
587 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
589 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal finish scan mode %d\n",
592 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
594 wcn36xx_err("Sending hal_finish_scan failed\n");
597 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
599 wcn36xx_err("hal_finish_scan response failed err=%d\n", ret
);
603 mutex_unlock(&wcn
->hal_mutex
);
607 static int wcn36xx_smd_switch_channel_rsp(void *buf
, size_t len
)
609 struct wcn36xx_hal_switch_channel_rsp_msg
*rsp
;
612 ret
= wcn36xx_smd_rsp_status_check(buf
, len
);
615 rsp
= (struct wcn36xx_hal_switch_channel_rsp_msg
*)buf
;
616 wcn36xx_dbg(WCN36XX_DBG_HAL
, "channel switched to: %d, status: %d\n",
617 rsp
->channel_number
, rsp
->status
);
621 int wcn36xx_smd_switch_channel(struct wcn36xx
*wcn
,
622 struct ieee80211_vif
*vif
, int ch
)
624 struct wcn36xx_hal_switch_channel_req_msg msg_body
;
627 mutex_lock(&wcn
->hal_mutex
);
628 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CH_SWITCH_REQ
);
630 msg_body
.channel_number
= (u8
)ch
;
631 msg_body
.tx_mgmt_power
= 0xbf;
632 msg_body
.max_tx_power
= 0xbf;
633 memcpy(msg_body
.self_sta_mac_addr
, vif
->addr
, ETH_ALEN
);
635 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
637 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
639 wcn36xx_err("Sending hal_switch_channel failed\n");
642 ret
= wcn36xx_smd_switch_channel_rsp(wcn
->hal_buf
, wcn
->hal_rsp_len
);
644 wcn36xx_err("hal_switch_channel response failed err=%d\n", ret
);
648 mutex_unlock(&wcn
->hal_mutex
);
652 static int wcn36xx_smd_update_scan_params_rsp(void *buf
, size_t len
)
654 struct wcn36xx_hal_update_scan_params_resp
*rsp
;
656 rsp
= (struct wcn36xx_hal_update_scan_params_resp
*)buf
;
658 /* Remove the PNO version bit */
659 rsp
->status
&= (~(WCN36XX_FW_MSG_PNO_VERSION_MASK
));
661 if (WCN36XX_FW_MSG_RESULT_SUCCESS
!= rsp
->status
) {
662 wcn36xx_warn("error response from update scan\n");
669 int wcn36xx_smd_update_scan_params(struct wcn36xx
*wcn
)
671 struct wcn36xx_hal_update_scan_params_req msg_body
;
674 mutex_lock(&wcn
->hal_mutex
);
675 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_UPDATE_SCAN_PARAM_REQ
);
677 msg_body
.dot11d_enabled
= 0;
678 msg_body
.dot11d_resolved
= 0;
679 msg_body
.channel_count
= 26;
680 msg_body
.active_min_ch_time
= 60;
681 msg_body
.active_max_ch_time
= 120;
682 msg_body
.passive_min_ch_time
= 60;
683 msg_body
.passive_max_ch_time
= 110;
686 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
688 wcn36xx_dbg(WCN36XX_DBG_HAL
,
689 "hal update scan params channel_count %d\n",
690 msg_body
.channel_count
);
692 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
694 wcn36xx_err("Sending hal_update_scan_params failed\n");
697 ret
= wcn36xx_smd_update_scan_params_rsp(wcn
->hal_buf
,
700 wcn36xx_err("hal_update_scan_params response failed err=%d\n",
705 mutex_unlock(&wcn
->hal_mutex
);
709 static int wcn36xx_smd_add_sta_self_rsp(struct wcn36xx
*wcn
,
710 struct ieee80211_vif
*vif
,
714 struct wcn36xx_hal_add_sta_self_rsp_msg
*rsp
;
715 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
717 if (len
< sizeof(*rsp
))
720 rsp
= (struct wcn36xx_hal_add_sta_self_rsp_msg
*)buf
;
722 if (rsp
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
723 wcn36xx_warn("hal add sta self failure: %d\n",
728 wcn36xx_dbg(WCN36XX_DBG_HAL
,
729 "hal add sta self status %d self_sta_index %d dpu_index %d\n",
730 rsp
->status
, rsp
->self_sta_index
, rsp
->dpu_index
);
732 priv_vif
->self_sta_index
= rsp
->self_sta_index
;
733 priv_vif
->self_dpu_desc_index
= rsp
->dpu_index
;
738 int wcn36xx_smd_add_sta_self(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
740 struct wcn36xx_hal_add_sta_self_req msg_body
;
743 mutex_lock(&wcn
->hal_mutex
);
744 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_STA_SELF_REQ
);
746 memcpy(&msg_body
.self_addr
, vif
->addr
, ETH_ALEN
);
748 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
750 wcn36xx_dbg(WCN36XX_DBG_HAL
,
751 "hal add sta self self_addr %pM status %d\n",
752 msg_body
.self_addr
, msg_body
.status
);
754 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
756 wcn36xx_err("Sending hal_add_sta_self failed\n");
759 ret
= wcn36xx_smd_add_sta_self_rsp(wcn
,
764 wcn36xx_err("hal_add_sta_self response failed err=%d\n", ret
);
768 mutex_unlock(&wcn
->hal_mutex
);
772 int wcn36xx_smd_delete_sta_self(struct wcn36xx
*wcn
, u8
*addr
)
774 struct wcn36xx_hal_del_sta_self_req_msg msg_body
;
777 mutex_lock(&wcn
->hal_mutex
);
778 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DEL_STA_SELF_REQ
);
780 memcpy(&msg_body
.self_addr
, addr
, ETH_ALEN
);
782 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
784 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
786 wcn36xx_err("Sending hal_delete_sta_self failed\n");
789 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
791 wcn36xx_err("hal_delete_sta_self response failed err=%d\n",
796 mutex_unlock(&wcn
->hal_mutex
);
800 int wcn36xx_smd_delete_sta(struct wcn36xx
*wcn
, u8 sta_index
)
802 struct wcn36xx_hal_delete_sta_req_msg msg_body
;
805 mutex_lock(&wcn
->hal_mutex
);
806 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DELETE_STA_REQ
);
808 msg_body
.sta_index
= sta_index
;
810 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
812 wcn36xx_dbg(WCN36XX_DBG_HAL
,
813 "hal delete sta sta_index %d\n",
816 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
818 wcn36xx_err("Sending hal_delete_sta failed\n");
821 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
823 wcn36xx_err("hal_delete_sta response failed err=%d\n", ret
);
827 mutex_unlock(&wcn
->hal_mutex
);
831 static int wcn36xx_smd_join_rsp(void *buf
, size_t len
)
833 struct wcn36xx_hal_join_rsp_msg
*rsp
;
835 if (wcn36xx_smd_rsp_status_check(buf
, len
))
838 rsp
= (struct wcn36xx_hal_join_rsp_msg
*)buf
;
840 wcn36xx_dbg(WCN36XX_DBG_HAL
,
841 "hal rsp join status %d tx_mgmt_power %d\n",
842 rsp
->status
, rsp
->tx_mgmt_power
);
847 int wcn36xx_smd_join(struct wcn36xx
*wcn
, const u8
*bssid
, u8
*vif
, u8 ch
)
849 struct wcn36xx_hal_join_req_msg msg_body
;
852 mutex_lock(&wcn
->hal_mutex
);
853 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_JOIN_REQ
);
855 memcpy(&msg_body
.bssid
, bssid
, ETH_ALEN
);
856 memcpy(&msg_body
.self_sta_mac_addr
, vif
, ETH_ALEN
);
857 msg_body
.channel
= ch
;
859 if (conf_is_ht40_minus(&wcn
->hw
->conf
))
860 msg_body
.secondary_channel_offset
=
861 PHY_DOUBLE_CHANNEL_HIGH_PRIMARY
;
862 else if (conf_is_ht40_plus(&wcn
->hw
->conf
))
863 msg_body
.secondary_channel_offset
=
864 PHY_DOUBLE_CHANNEL_LOW_PRIMARY
;
866 msg_body
.secondary_channel_offset
=
867 PHY_SINGLE_CHANNEL_CENTERED
;
869 msg_body
.link_state
= WCN36XX_HAL_LINK_PREASSOC_STATE
;
871 msg_body
.max_tx_power
= 0xbf;
872 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
874 wcn36xx_dbg(WCN36XX_DBG_HAL
,
875 "hal join req bssid %pM self_sta_mac_addr %pM channel %d link_state %d\n",
876 msg_body
.bssid
, msg_body
.self_sta_mac_addr
,
877 msg_body
.channel
, msg_body
.link_state
);
879 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
881 wcn36xx_err("Sending hal_join failed\n");
884 ret
= wcn36xx_smd_join_rsp(wcn
->hal_buf
, wcn
->hal_rsp_len
);
886 wcn36xx_err("hal_join response failed err=%d\n", ret
);
890 mutex_unlock(&wcn
->hal_mutex
);
894 int wcn36xx_smd_set_link_st(struct wcn36xx
*wcn
, const u8
*bssid
,
896 enum wcn36xx_hal_link_state state
)
898 struct wcn36xx_hal_set_link_state_req_msg msg_body
;
901 mutex_lock(&wcn
->hal_mutex
);
902 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_LINK_ST_REQ
);
904 memcpy(&msg_body
.bssid
, bssid
, ETH_ALEN
);
905 memcpy(&msg_body
.self_mac_addr
, sta_mac
, ETH_ALEN
);
906 msg_body
.state
= state
;
908 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
910 wcn36xx_dbg(WCN36XX_DBG_HAL
,
911 "hal set link state bssid %pM self_mac_addr %pM state %d\n",
912 msg_body
.bssid
, msg_body
.self_mac_addr
, msg_body
.state
);
914 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
916 wcn36xx_err("Sending hal_set_link_st failed\n");
919 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
921 wcn36xx_err("hal_set_link_st response failed err=%d\n", ret
);
925 mutex_unlock(&wcn
->hal_mutex
);
929 static void wcn36xx_smd_convert_sta_to_v1(struct wcn36xx
*wcn
,
930 const struct wcn36xx_hal_config_sta_params
*orig
,
931 struct wcn36xx_hal_config_sta_params_v1
*v1
)
933 /* convert orig to v1 format */
934 memcpy(&v1
->bssid
, orig
->bssid
, ETH_ALEN
);
935 memcpy(&v1
->mac
, orig
->mac
, ETH_ALEN
);
937 v1
->type
= orig
->type
;
938 v1
->listen_interval
= orig
->listen_interval
;
939 v1
->ht_capable
= orig
->ht_capable
;
941 v1
->max_ampdu_size
= orig
->max_ampdu_size
;
942 v1
->max_ampdu_density
= orig
->max_ampdu_density
;
943 v1
->sgi_40mhz
= orig
->sgi_40mhz
;
944 v1
->sgi_20Mhz
= orig
->sgi_20Mhz
;
946 memcpy(&v1
->supported_rates
, &orig
->supported_rates
,
947 sizeof(orig
->supported_rates
));
948 v1
->sta_index
= orig
->sta_index
;
951 static int wcn36xx_smd_config_sta_rsp(struct wcn36xx
*wcn
,
952 struct ieee80211_sta
*sta
,
956 struct wcn36xx_hal_config_sta_rsp_msg
*rsp
;
957 struct config_sta_rsp_params
*params
;
958 struct wcn36xx_sta
*sta_priv
= (struct wcn36xx_sta
*)sta
->drv_priv
;
960 if (len
< sizeof(*rsp
))
963 rsp
= (struct wcn36xx_hal_config_sta_rsp_msg
*)buf
;
964 params
= &rsp
->params
;
966 if (params
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
967 wcn36xx_warn("hal config sta response failure: %d\n",
972 sta_priv
->sta_index
= params
->sta_index
;
973 sta_priv
->dpu_desc_index
= params
->dpu_index
;
974 sta_priv
->ucast_dpu_sign
= params
->uc_ucast_sig
;
976 wcn36xx_dbg(WCN36XX_DBG_HAL
,
977 "hal config sta rsp status %d sta_index %d bssid_index %d uc_ucast_sig %d p2p %d\n",
978 params
->status
, params
->sta_index
, params
->bssid_index
,
979 params
->uc_ucast_sig
, params
->p2p
);
984 static int wcn36xx_smd_config_sta_v1(struct wcn36xx
*wcn
,
985 const struct wcn36xx_hal_config_sta_req_msg
*orig
)
987 struct wcn36xx_hal_config_sta_req_msg_v1 msg_body
;
988 struct wcn36xx_hal_config_sta_params_v1
*sta
= &msg_body
.sta_params
;
990 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CONFIG_STA_REQ
);
992 wcn36xx_smd_convert_sta_to_v1(wcn
, &orig
->sta_params
,
993 &msg_body
.sta_params
);
995 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
997 wcn36xx_dbg(WCN36XX_DBG_HAL
,
998 "hal config sta v1 action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
999 sta
->action
, sta
->sta_index
, sta
->bssid_index
,
1000 sta
->bssid
, sta
->type
, sta
->mac
, sta
->aid
);
1002 return wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1005 int wcn36xx_smd_config_sta(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
1006 struct ieee80211_sta
*sta
)
1008 struct wcn36xx_hal_config_sta_req_msg msg
;
1009 struct wcn36xx_hal_config_sta_params
*sta_params
;
1012 mutex_lock(&wcn
->hal_mutex
);
1013 INIT_HAL_MSG(msg
, WCN36XX_HAL_CONFIG_STA_REQ
);
1015 sta_params
= &msg
.sta_params
;
1017 wcn36xx_smd_set_sta_params(wcn
, vif
, sta
, sta_params
);
1019 if (!wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
1020 ret
= wcn36xx_smd_config_sta_v1(wcn
, &msg
);
1022 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
1024 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1025 "hal config sta action %d sta_index %d bssid_index %d bssid %pM type %d mac %pM aid %d\n",
1026 sta_params
->action
, sta_params
->sta_index
,
1027 sta_params
->bssid_index
, sta_params
->bssid
,
1028 sta_params
->type
, sta_params
->mac
, sta_params
->aid
);
1030 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
1033 wcn36xx_err("Sending hal_config_sta failed\n");
1036 ret
= wcn36xx_smd_config_sta_rsp(wcn
,
1041 wcn36xx_err("hal_config_sta response failed err=%d\n", ret
);
1045 mutex_unlock(&wcn
->hal_mutex
);
1049 static int wcn36xx_smd_config_bss_v1(struct wcn36xx
*wcn
,
1050 const struct wcn36xx_hal_config_bss_req_msg
*orig
)
1052 struct wcn36xx_hal_config_bss_req_msg_v1 msg_body
;
1053 struct wcn36xx_hal_config_bss_params_v1
*bss
= &msg_body
.bss_params
;
1054 struct wcn36xx_hal_config_sta_params_v1
*sta
= &bss
->sta
;
1056 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_CONFIG_BSS_REQ
);
1058 /* convert orig to v1 */
1059 memcpy(&msg_body
.bss_params
.bssid
,
1060 &orig
->bss_params
.bssid
, ETH_ALEN
);
1061 memcpy(&msg_body
.bss_params
.self_mac_addr
,
1062 &orig
->bss_params
.self_mac_addr
, ETH_ALEN
);
1064 msg_body
.bss_params
.bss_type
= orig
->bss_params
.bss_type
;
1065 msg_body
.bss_params
.oper_mode
= orig
->bss_params
.oper_mode
;
1066 msg_body
.bss_params
.nw_type
= orig
->bss_params
.nw_type
;
1068 msg_body
.bss_params
.short_slot_time_supported
=
1069 orig
->bss_params
.short_slot_time_supported
;
1070 msg_body
.bss_params
.lla_coexist
= orig
->bss_params
.lla_coexist
;
1071 msg_body
.bss_params
.llb_coexist
= orig
->bss_params
.llb_coexist
;
1072 msg_body
.bss_params
.llg_coexist
= orig
->bss_params
.llg_coexist
;
1073 msg_body
.bss_params
.ht20_coexist
= orig
->bss_params
.ht20_coexist
;
1074 msg_body
.bss_params
.lln_non_gf_coexist
=
1075 orig
->bss_params
.lln_non_gf_coexist
;
1077 msg_body
.bss_params
.lsig_tx_op_protection_full_support
=
1078 orig
->bss_params
.lsig_tx_op_protection_full_support
;
1079 msg_body
.bss_params
.rifs_mode
= orig
->bss_params
.rifs_mode
;
1080 msg_body
.bss_params
.beacon_interval
= orig
->bss_params
.beacon_interval
;
1081 msg_body
.bss_params
.dtim_period
= orig
->bss_params
.dtim_period
;
1082 msg_body
.bss_params
.tx_channel_width_set
=
1083 orig
->bss_params
.tx_channel_width_set
;
1084 msg_body
.bss_params
.oper_channel
= orig
->bss_params
.oper_channel
;
1085 msg_body
.bss_params
.ext_channel
= orig
->bss_params
.ext_channel
;
1087 msg_body
.bss_params
.reserved
= orig
->bss_params
.reserved
;
1089 memcpy(&msg_body
.bss_params
.ssid
,
1090 &orig
->bss_params
.ssid
,
1091 sizeof(orig
->bss_params
.ssid
));
1093 msg_body
.bss_params
.action
= orig
->bss_params
.action
;
1094 msg_body
.bss_params
.rateset
= orig
->bss_params
.rateset
;
1095 msg_body
.bss_params
.ht
= orig
->bss_params
.ht
;
1096 msg_body
.bss_params
.obss_prot_enabled
=
1097 orig
->bss_params
.obss_prot_enabled
;
1098 msg_body
.bss_params
.rmf
= orig
->bss_params
.rmf
;
1099 msg_body
.bss_params
.ht_oper_mode
= orig
->bss_params
.ht_oper_mode
;
1100 msg_body
.bss_params
.dual_cts_protection
=
1101 orig
->bss_params
.dual_cts_protection
;
1103 msg_body
.bss_params
.max_probe_resp_retry_limit
=
1104 orig
->bss_params
.max_probe_resp_retry_limit
;
1105 msg_body
.bss_params
.hidden_ssid
= orig
->bss_params
.hidden_ssid
;
1106 msg_body
.bss_params
.proxy_probe_resp
=
1107 orig
->bss_params
.proxy_probe_resp
;
1108 msg_body
.bss_params
.edca_params_valid
=
1109 orig
->bss_params
.edca_params_valid
;
1111 memcpy(&msg_body
.bss_params
.acbe
,
1112 &orig
->bss_params
.acbe
,
1113 sizeof(orig
->bss_params
.acbe
));
1114 memcpy(&msg_body
.bss_params
.acbk
,
1115 &orig
->bss_params
.acbk
,
1116 sizeof(orig
->bss_params
.acbk
));
1117 memcpy(&msg_body
.bss_params
.acvi
,
1118 &orig
->bss_params
.acvi
,
1119 sizeof(orig
->bss_params
.acvi
));
1120 memcpy(&msg_body
.bss_params
.acvo
,
1121 &orig
->bss_params
.acvo
,
1122 sizeof(orig
->bss_params
.acvo
));
1124 msg_body
.bss_params
.ext_set_sta_key_param_valid
=
1125 orig
->bss_params
.ext_set_sta_key_param_valid
;
1127 memcpy(&msg_body
.bss_params
.ext_set_sta_key_param
,
1128 &orig
->bss_params
.ext_set_sta_key_param
,
1129 sizeof(orig
->bss_params
.acvo
));
1131 msg_body
.bss_params
.wcn36xx_hal_persona
=
1132 orig
->bss_params
.wcn36xx_hal_persona
;
1133 msg_body
.bss_params
.spectrum_mgt_enable
=
1134 orig
->bss_params
.spectrum_mgt_enable
;
1135 msg_body
.bss_params
.tx_mgmt_power
= orig
->bss_params
.tx_mgmt_power
;
1136 msg_body
.bss_params
.max_tx_power
= orig
->bss_params
.max_tx_power
;
1138 wcn36xx_smd_convert_sta_to_v1(wcn
, &orig
->bss_params
.sta
,
1139 &msg_body
.bss_params
.sta
);
1141 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1143 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1144 "hal config bss v1 bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1145 bss
->bssid
, bss
->self_mac_addr
, bss
->bss_type
,
1146 bss
->oper_mode
, bss
->nw_type
);
1148 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1149 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1150 sta
->bssid
, sta
->action
, sta
->sta_index
,
1151 sta
->bssid_index
, sta
->aid
, sta
->type
, sta
->mac
);
1153 return wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1157 static int wcn36xx_smd_config_bss_rsp(struct wcn36xx
*wcn
,
1158 struct ieee80211_vif
*vif
,
1162 struct wcn36xx_hal_config_bss_rsp_msg
*rsp
;
1163 struct wcn36xx_hal_config_bss_rsp_params
*params
;
1164 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1166 if (len
< sizeof(*rsp
))
1169 rsp
= (struct wcn36xx_hal_config_bss_rsp_msg
*)buf
;
1170 params
= &rsp
->bss_rsp_params
;
1172 if (params
->status
!= WCN36XX_FW_MSG_RESULT_SUCCESS
) {
1173 wcn36xx_warn("hal config bss response failure: %d\n",
1178 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1179 "hal config bss rsp status %d bss_idx %d dpu_desc_index %d"
1180 " sta_idx %d self_idx %d bcast_idx %d mac %pM"
1181 " power %d ucast_dpu_signature %d\n",
1182 params
->status
, params
->bss_index
, params
->dpu_desc_index
,
1183 params
->bss_sta_index
, params
->bss_self_sta_index
,
1184 params
->bss_bcast_sta_idx
, params
->mac
,
1185 params
->tx_mgmt_power
, params
->ucast_dpu_signature
);
1187 priv_vif
->bss_index
= params
->bss_index
;
1189 if (priv_vif
->sta
) {
1190 priv_vif
->sta
->bss_sta_index
= params
->bss_sta_index
;
1191 priv_vif
->sta
->bss_dpu_desc_index
= params
->dpu_desc_index
;
1194 priv_vif
->self_ucast_dpu_sign
= params
->ucast_dpu_signature
;
1199 int wcn36xx_smd_config_bss(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
1200 struct ieee80211_sta
*sta
, const u8
*bssid
,
1203 struct wcn36xx_hal_config_bss_req_msg msg
;
1204 struct wcn36xx_hal_config_bss_params
*bss
;
1205 struct wcn36xx_hal_config_sta_params
*sta_params
;
1206 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1209 mutex_lock(&wcn
->hal_mutex
);
1210 INIT_HAL_MSG(msg
, WCN36XX_HAL_CONFIG_BSS_REQ
);
1212 bss
= &msg
.bss_params
;
1213 sta_params
= &bss
->sta
;
1215 WARN_ON(is_zero_ether_addr(bssid
));
1217 memcpy(&bss
->bssid
, bssid
, ETH_ALEN
);
1219 memcpy(bss
->self_mac_addr
, vif
->addr
, ETH_ALEN
);
1221 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1222 bss
->bss_type
= WCN36XX_HAL_INFRASTRUCTURE_MODE
;
1226 bss
->wcn36xx_hal_persona
= WCN36XX_HAL_STA_MODE
;
1227 } else if (vif
->type
== NL80211_IFTYPE_AP
||
1228 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1229 bss
->bss_type
= WCN36XX_HAL_INFRA_AP_MODE
;
1233 bss
->wcn36xx_hal_persona
= WCN36XX_HAL_STA_SAP_MODE
;
1234 } else if (vif
->type
== NL80211_IFTYPE_ADHOC
) {
1235 bss
->bss_type
= WCN36XX_HAL_IBSS_MODE
;
1240 wcn36xx_warn("Unknown type for bss config: %d\n", vif
->type
);
1243 if (vif
->type
== NL80211_IFTYPE_STATION
)
1244 wcn36xx_smd_set_bss_nw_type(wcn
, sta
, bss
);
1246 bss
->nw_type
= WCN36XX_HAL_11N_NW_TYPE
;
1248 bss
->short_slot_time_supported
= vif
->bss_conf
.use_short_slot
;
1249 bss
->lla_coexist
= 0;
1250 bss
->llb_coexist
= 0;
1251 bss
->llg_coexist
= 0;
1253 bss
->beacon_interval
= vif
->bss_conf
.beacon_int
;
1254 bss
->dtim_period
= vif_priv
->dtim_period
;
1256 wcn36xx_smd_set_bss_ht_params(vif
, sta
, bss
);
1258 bss
->oper_channel
= WCN36XX_HW_CHANNEL(wcn
);
1260 if (conf_is_ht40_minus(&wcn
->hw
->conf
))
1261 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
1262 else if (conf_is_ht40_plus(&wcn
->hw
->conf
))
1263 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
1265 bss
->ext_channel
= IEEE80211_HT_PARAM_CHA_SEC_NONE
;
1268 wcn36xx_smd_set_sta_params(wcn
, vif
, sta
, sta_params
);
1270 /* wcn->ssid is only valid in AP and IBSS mode */
1271 bss
->ssid
.length
= vif_priv
->ssid
.length
;
1272 memcpy(bss
->ssid
.ssid
, vif_priv
->ssid
.ssid
, vif_priv
->ssid
.length
);
1274 bss
->obss_prot_enabled
= 0;
1276 bss
->max_probe_resp_retry_limit
= 0;
1277 bss
->hidden_ssid
= vif
->bss_conf
.hidden_ssid
;
1278 bss
->proxy_probe_resp
= 0;
1279 bss
->edca_params_valid
= 0;
1281 /* FIXME: set acbe, acbk, acvi and acvo */
1283 bss
->ext_set_sta_key_param_valid
= 0;
1285 /* FIXME: set ext_set_sta_key_param */
1287 bss
->spectrum_mgt_enable
= 0;
1288 bss
->tx_mgmt_power
= 0;
1289 bss
->max_tx_power
= WCN36XX_MAX_POWER(wcn
);
1291 bss
->action
= update
;
1293 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1294 "hal config bss bssid %pM self_mac_addr %pM bss_type %d oper_mode %d nw_type %d\n",
1295 bss
->bssid
, bss
->self_mac_addr
, bss
->bss_type
,
1296 bss
->oper_mode
, bss
->nw_type
);
1298 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1299 "- sta bssid %pM action %d sta_index %d bssid_index %d aid %d type %d mac %pM\n",
1300 sta_params
->bssid
, sta_params
->action
,
1301 sta_params
->sta_index
, sta_params
->bssid_index
,
1302 sta_params
->aid
, sta_params
->type
,
1305 if (!wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
1306 ret
= wcn36xx_smd_config_bss_v1(wcn
, &msg
);
1308 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
1310 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
1313 wcn36xx_err("Sending hal_config_bss failed\n");
1316 ret
= wcn36xx_smd_config_bss_rsp(wcn
,
1321 wcn36xx_err("hal_config_bss response failed err=%d\n", ret
);
1325 mutex_unlock(&wcn
->hal_mutex
);
1329 int wcn36xx_smd_delete_bss(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1331 struct wcn36xx_hal_delete_bss_req_msg msg_body
;
1332 struct wcn36xx_vif
*priv_vif
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1335 mutex_lock(&wcn
->hal_mutex
);
1336 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DELETE_BSS_REQ
);
1338 msg_body
.bss_index
= priv_vif
->bss_index
;
1340 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1342 wcn36xx_dbg(WCN36XX_DBG_HAL
, "hal delete bss %d\n", msg_body
.bss_index
);
1344 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1346 wcn36xx_err("Sending hal_delete_bss failed\n");
1349 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1351 wcn36xx_err("hal_delete_bss response failed err=%d\n", ret
);
1355 mutex_unlock(&wcn
->hal_mutex
);
1359 int wcn36xx_smd_send_beacon(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
,
1360 struct sk_buff
*skb_beacon
, u16 tim_off
,
1363 struct wcn36xx_hal_send_beacon_req_msg msg_body
;
1366 mutex_lock(&wcn
->hal_mutex
);
1367 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SEND_BEACON_REQ
);
1369 /* TODO need to find out why this is needed? */
1370 msg_body
.beacon_length
= skb_beacon
->len
+ 6;
1372 if (BEACON_TEMPLATE_SIZE
> msg_body
.beacon_length
) {
1373 memcpy(&msg_body
.beacon
, &skb_beacon
->len
, sizeof(u32
));
1374 memcpy(&(msg_body
.beacon
[4]), skb_beacon
->data
,
1377 wcn36xx_err("Beacon is to big: beacon size=%d\n",
1378 msg_body
.beacon_length
);
1382 memcpy(msg_body
.bssid
, vif
->addr
, ETH_ALEN
);
1384 /* TODO need to find out why this is needed? */
1385 if (vif
->type
== NL80211_IFTYPE_MESH_POINT
)
1386 /* mesh beacon don't need this, so push further down */
1387 msg_body
.tim_ie_offset
= 256;
1389 msg_body
.tim_ie_offset
= tim_off
+4;
1390 msg_body
.p2p_ie_offset
= p2p_off
;
1391 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1393 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1394 "hal send beacon beacon_length %d\n",
1395 msg_body
.beacon_length
);
1397 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1399 wcn36xx_err("Sending hal_send_beacon failed\n");
1402 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1404 wcn36xx_err("hal_send_beacon response failed err=%d\n", ret
);
1408 mutex_unlock(&wcn
->hal_mutex
);
1412 int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx
*wcn
,
1413 struct ieee80211_vif
*vif
,
1414 struct sk_buff
*skb
)
1416 struct wcn36xx_hal_send_probe_resp_req_msg msg
;
1419 mutex_lock(&wcn
->hal_mutex
);
1420 INIT_HAL_MSG(msg
, WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_REQ
);
1422 if (skb
->len
> BEACON_TEMPLATE_SIZE
) {
1423 wcn36xx_warn("probe response template is too big: %d\n",
1429 msg
.probe_resp_template_len
= skb
->len
;
1430 memcpy(&msg
.probe_resp_template
, skb
->data
, skb
->len
);
1432 memcpy(msg
.bssid
, vif
->addr
, ETH_ALEN
);
1434 PREPARE_HAL_BUF(wcn
->hal_buf
, msg
);
1436 wcn36xx_dbg(WCN36XX_DBG_HAL
,
1437 "hal update probe rsp len %d bssid %pM\n",
1438 msg
.probe_resp_template_len
, msg
.bssid
);
1440 ret
= wcn36xx_smd_send_and_wait(wcn
, msg
.header
.len
);
1442 wcn36xx_err("Sending hal_update_proberesp_tmpl failed\n");
1445 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1447 wcn36xx_err("hal_update_proberesp_tmpl response failed err=%d\n",
1452 mutex_unlock(&wcn
->hal_mutex
);
1456 int wcn36xx_smd_set_stakey(struct wcn36xx
*wcn
,
1457 enum ani_ed_type enc_type
,
1463 struct wcn36xx_hal_set_sta_key_req_msg msg_body
;
1466 mutex_lock(&wcn
->hal_mutex
);
1467 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_STAKEY_REQ
);
1469 msg_body
.set_sta_key_params
.sta_index
= sta_index
;
1470 msg_body
.set_sta_key_params
.enc_type
= enc_type
;
1472 msg_body
.set_sta_key_params
.key
[0].id
= keyidx
;
1473 msg_body
.set_sta_key_params
.key
[0].unicast
= 1;
1474 msg_body
.set_sta_key_params
.key
[0].direction
= WCN36XX_HAL_TX_RX
;
1475 msg_body
.set_sta_key_params
.key
[0].pae_role
= 0;
1476 msg_body
.set_sta_key_params
.key
[0].length
= keylen
;
1477 memcpy(msg_body
.set_sta_key_params
.key
[0].key
, key
, keylen
);
1478 msg_body
.set_sta_key_params
.single_tid_rc
= 1;
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_set_stakey failed\n");
1487 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1489 wcn36xx_err("hal_set_stakey response failed err=%d\n", ret
);
1493 mutex_unlock(&wcn
->hal_mutex
);
1497 int wcn36xx_smd_set_bsskey(struct wcn36xx
*wcn
,
1498 enum ani_ed_type enc_type
,
1503 struct wcn36xx_hal_set_bss_key_req_msg msg_body
;
1506 mutex_lock(&wcn
->hal_mutex
);
1507 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_BSSKEY_REQ
);
1508 msg_body
.bss_idx
= 0;
1509 msg_body
.enc_type
= enc_type
;
1510 msg_body
.num_keys
= 1;
1511 msg_body
.keys
[0].id
= keyidx
;
1512 msg_body
.keys
[0].unicast
= 0;
1513 msg_body
.keys
[0].direction
= WCN36XX_HAL_RX_ONLY
;
1514 msg_body
.keys
[0].pae_role
= 0;
1515 msg_body
.keys
[0].length
= keylen
;
1516 memcpy(msg_body
.keys
[0].key
, key
, keylen
);
1518 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1520 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1522 wcn36xx_err("Sending hal_set_bsskey failed\n");
1525 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1527 wcn36xx_err("hal_set_bsskey response failed err=%d\n", ret
);
1531 mutex_unlock(&wcn
->hal_mutex
);
1535 int wcn36xx_smd_remove_stakey(struct wcn36xx
*wcn
,
1536 enum ani_ed_type enc_type
,
1540 struct wcn36xx_hal_remove_sta_key_req_msg msg_body
;
1543 mutex_lock(&wcn
->hal_mutex
);
1544 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_RMV_STAKEY_REQ
);
1546 msg_body
.sta_idx
= sta_index
;
1547 msg_body
.enc_type
= enc_type
;
1548 msg_body
.key_id
= keyidx
;
1550 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1552 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1554 wcn36xx_err("Sending hal_remove_stakey failed\n");
1557 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1559 wcn36xx_err("hal_remove_stakey response failed err=%d\n", ret
);
1563 mutex_unlock(&wcn
->hal_mutex
);
1567 int wcn36xx_smd_remove_bsskey(struct wcn36xx
*wcn
,
1568 enum ani_ed_type enc_type
,
1571 struct wcn36xx_hal_remove_bss_key_req_msg msg_body
;
1574 mutex_lock(&wcn
->hal_mutex
);
1575 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_RMV_BSSKEY_REQ
);
1576 msg_body
.bss_idx
= 0;
1577 msg_body
.enc_type
= enc_type
;
1578 msg_body
.key_id
= keyidx
;
1580 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1582 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1584 wcn36xx_err("Sending hal_remove_bsskey failed\n");
1587 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1589 wcn36xx_err("hal_remove_bsskey response failed err=%d\n", ret
);
1593 mutex_unlock(&wcn
->hal_mutex
);
1597 int wcn36xx_smd_enter_bmps(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1599 struct wcn36xx_hal_enter_bmps_req_msg msg_body
;
1600 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1603 mutex_lock(&wcn
->hal_mutex
);
1604 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ENTER_BMPS_REQ
);
1606 msg_body
.bss_index
= vif_priv
->bss_index
;
1607 msg_body
.tbtt
= vif
->bss_conf
.sync_tsf
;
1608 msg_body
.dtim_period
= vif_priv
->dtim_period
;
1610 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1612 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1614 wcn36xx_err("Sending hal_enter_bmps failed\n");
1617 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1619 wcn36xx_err("hal_enter_bmps response failed err=%d\n", ret
);
1623 mutex_unlock(&wcn
->hal_mutex
);
1627 int wcn36xx_smd_exit_bmps(struct wcn36xx
*wcn
, struct ieee80211_vif
*vif
)
1629 struct wcn36xx_hal_enter_bmps_req_msg msg_body
;
1630 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1633 mutex_lock(&wcn
->hal_mutex
);
1634 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_EXIT_BMPS_REQ
);
1636 msg_body
.bss_index
= vif_priv
->bss_index
;
1638 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1640 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1642 wcn36xx_err("Sending hal_exit_bmps failed\n");
1645 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1647 wcn36xx_err("hal_exit_bmps response failed err=%d\n", ret
);
1651 mutex_unlock(&wcn
->hal_mutex
);
1654 int wcn36xx_smd_set_power_params(struct wcn36xx
*wcn
, bool ignore_dtim
)
1656 struct wcn36xx_hal_set_power_params_req_msg msg_body
;
1659 mutex_lock(&wcn
->hal_mutex
);
1660 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_SET_POWER_PARAMS_REQ
);
1663 * When host is down ignore every second dtim
1666 msg_body
.ignore_dtim
= 1;
1667 msg_body
.dtim_period
= 2;
1669 msg_body
.listen_interval
= WCN36XX_LISTEN_INTERVAL(wcn
);
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_set_power_params failed\n");
1680 mutex_unlock(&wcn
->hal_mutex
);
1683 /* Notice: This function should be called after associated, or else it
1686 int wcn36xx_smd_keep_alive_req(struct wcn36xx
*wcn
,
1687 struct ieee80211_vif
*vif
,
1690 struct wcn36xx_hal_keep_alive_req_msg msg_body
;
1691 struct wcn36xx_vif
*vif_priv
= (struct wcn36xx_vif
*)vif
->drv_priv
;
1694 mutex_lock(&wcn
->hal_mutex
);
1695 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_KEEP_ALIVE_REQ
);
1697 if (packet_type
== WCN36XX_HAL_KEEP_ALIVE_NULL_PKT
) {
1698 msg_body
.bss_index
= vif_priv
->bss_index
;
1699 msg_body
.packet_type
= WCN36XX_HAL_KEEP_ALIVE_NULL_PKT
;
1700 msg_body
.time_period
= WCN36XX_KEEP_ALIVE_TIME_PERIOD
;
1701 } else if (packet_type
== WCN36XX_HAL_KEEP_ALIVE_UNSOLICIT_ARP_RSP
) {
1702 /* TODO: it also support ARP response type */
1704 wcn36xx_warn("unknown keep alive packet type %d\n", packet_type
);
1709 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1711 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1713 wcn36xx_err("Sending hal_keep_alive failed\n");
1716 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1718 wcn36xx_err("hal_keep_alive response failed err=%d\n", ret
);
1722 mutex_unlock(&wcn
->hal_mutex
);
1726 int wcn36xx_smd_dump_cmd_req(struct wcn36xx
*wcn
, u32 arg1
, u32 arg2
,
1727 u32 arg3
, u32 arg4
, u32 arg5
)
1729 struct wcn36xx_hal_dump_cmd_req_msg msg_body
;
1732 mutex_lock(&wcn
->hal_mutex
);
1733 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DUMP_COMMAND_REQ
);
1735 msg_body
.arg1
= arg1
;
1736 msg_body
.arg2
= arg2
;
1737 msg_body
.arg3
= arg3
;
1738 msg_body
.arg4
= arg4
;
1739 msg_body
.arg5
= arg5
;
1741 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1743 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1745 wcn36xx_err("Sending hal_dump_cmd failed\n");
1748 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1750 wcn36xx_err("hal_dump_cmd response failed err=%d\n", ret
);
1754 mutex_unlock(&wcn
->hal_mutex
);
1758 void set_feat_caps(u32
*bitmap
, enum place_holder_in_cap_bitmap cap
)
1760 int arr_idx
, bit_idx
;
1762 if (cap
< 0 || cap
> 127) {
1763 wcn36xx_warn("error cap idx %d\n", cap
);
1769 bitmap
[arr_idx
] |= (1 << bit_idx
);
1772 int get_feat_caps(u32
*bitmap
, enum place_holder_in_cap_bitmap cap
)
1774 int arr_idx
, bit_idx
;
1777 if (cap
< 0 || cap
> 127) {
1778 wcn36xx_warn("error cap idx %d\n", cap
);
1784 ret
= (bitmap
[arr_idx
] & (1 << bit_idx
)) ? 1 : 0;
1788 void clear_feat_caps(u32
*bitmap
, enum place_holder_in_cap_bitmap cap
)
1790 int arr_idx
, bit_idx
;
1792 if (cap
< 0 || cap
> 127) {
1793 wcn36xx_warn("error cap idx %d\n", cap
);
1799 bitmap
[arr_idx
] &= ~(1 << bit_idx
);
1802 int wcn36xx_smd_feature_caps_exchange(struct wcn36xx
*wcn
)
1804 struct wcn36xx_hal_feat_caps_msg msg_body
, *rsp
;
1807 mutex_lock(&wcn
->hal_mutex
);
1808 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_REQ
);
1810 set_feat_caps(msg_body
.feat_caps
, STA_POWERSAVE
);
1812 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1814 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1816 wcn36xx_err("Sending hal_feature_caps_exchange failed\n");
1819 if (wcn
->hal_rsp_len
!= sizeof(*rsp
)) {
1820 wcn36xx_err("Invalid hal_feature_caps_exchange response");
1824 rsp
= (struct wcn36xx_hal_feat_caps_msg
*) wcn
->hal_buf
;
1826 for (i
= 0; i
< WCN36XX_HAL_CAPS_SIZE
; i
++)
1827 wcn
->fw_feat_caps
[i
] = rsp
->feat_caps
[i
];
1829 mutex_unlock(&wcn
->hal_mutex
);
1833 int wcn36xx_smd_add_ba_session(struct wcn36xx
*wcn
,
1834 struct ieee80211_sta
*sta
,
1840 struct wcn36xx_hal_add_ba_session_req_msg msg_body
;
1843 mutex_lock(&wcn
->hal_mutex
);
1844 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_BA_SESSION_REQ
);
1846 msg_body
.sta_index
= sta_index
;
1847 memcpy(&msg_body
.mac_addr
, sta
->addr
, ETH_ALEN
);
1848 msg_body
.dialog_token
= 0x10;
1851 /* Immediate BA because Delayed BA is not supported */
1852 msg_body
.policy
= 1;
1853 msg_body
.buffer_size
= WCN36XX_AGGR_BUFFER_SIZE
;
1854 msg_body
.timeout
= 0;
1856 msg_body
.ssn
= *ssn
;
1857 msg_body
.direction
= direction
;
1859 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1861 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1863 wcn36xx_err("Sending hal_add_ba_session failed\n");
1866 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1868 wcn36xx_err("hal_add_ba_session response failed err=%d\n", ret
);
1872 mutex_unlock(&wcn
->hal_mutex
);
1876 int wcn36xx_smd_add_ba(struct wcn36xx
*wcn
)
1878 struct wcn36xx_hal_add_ba_req_msg msg_body
;
1881 mutex_lock(&wcn
->hal_mutex
);
1882 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_ADD_BA_REQ
);
1884 msg_body
.session_id
= 0;
1885 msg_body
.win_size
= WCN36XX_AGGR_BUFFER_SIZE
;
1887 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1889 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1891 wcn36xx_err("Sending hal_add_ba failed\n");
1894 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1896 wcn36xx_err("hal_add_ba response failed err=%d\n", ret
);
1900 mutex_unlock(&wcn
->hal_mutex
);
1904 int wcn36xx_smd_del_ba(struct wcn36xx
*wcn
, u16 tid
, u8 sta_index
)
1906 struct wcn36xx_hal_del_ba_req_msg msg_body
;
1909 mutex_lock(&wcn
->hal_mutex
);
1910 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_DEL_BA_REQ
);
1912 msg_body
.sta_index
= sta_index
;
1914 msg_body
.direction
= 0;
1915 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1917 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1919 wcn36xx_err("Sending hal_del_ba failed\n");
1922 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1924 wcn36xx_err("hal_del_ba response failed err=%d\n", ret
);
1928 mutex_unlock(&wcn
->hal_mutex
);
1932 int wcn36xx_smd_trigger_ba(struct wcn36xx
*wcn
, u8 sta_index
)
1934 struct wcn36xx_hal_trigger_ba_req_msg msg_body
;
1935 struct wcn36xx_hal_trigger_ba_req_candidate
*candidate
;
1938 mutex_lock(&wcn
->hal_mutex
);
1939 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_TRIGGER_BA_REQ
);
1941 msg_body
.session_id
= 0;
1942 msg_body
.candidate_cnt
= 1;
1943 msg_body
.header
.len
+= sizeof(*candidate
);
1944 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
1946 candidate
= (struct wcn36xx_hal_trigger_ba_req_candidate
*)
1947 (wcn
->hal_buf
+ sizeof(msg_body
));
1948 candidate
->sta_index
= sta_index
;
1949 candidate
->tid_bitmap
= 1;
1951 ret
= wcn36xx_smd_send_and_wait(wcn
, msg_body
.header
.len
);
1953 wcn36xx_err("Sending hal_trigger_ba failed\n");
1956 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
1958 wcn36xx_err("hal_trigger_ba response failed err=%d\n", ret
);
1962 mutex_unlock(&wcn
->hal_mutex
);
1966 static int wcn36xx_smd_tx_compl_ind(struct wcn36xx
*wcn
, void *buf
, size_t len
)
1968 struct wcn36xx_hal_tx_compl_ind_msg
*rsp
= buf
;
1970 if (len
!= sizeof(*rsp
)) {
1971 wcn36xx_warn("Bad TX complete indication\n");
1975 wcn36xx_dxe_tx_ack_ind(wcn
, rsp
->status
);
1980 static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx
*wcn
,
1984 struct wcn36xx_hal_missed_beacon_ind_msg
*rsp
= buf
;
1985 struct ieee80211_vif
*vif
= NULL
;
1986 struct wcn36xx_vif
*tmp
;
1988 /* Old FW does not have bss index */
1989 if (wcn36xx_is_fw_version(wcn
, 1, 2, 2, 24)) {
1990 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
1991 wcn36xx_dbg(WCN36XX_DBG_HAL
, "beacon missed bss_index %d\n",
1993 vif
= container_of((void *)tmp
,
1994 struct ieee80211_vif
,
1996 ieee80211_connection_loss(vif
);
2001 if (len
!= sizeof(*rsp
)) {
2002 wcn36xx_warn("Corrupted missed beacon indication\n");
2006 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
2007 if (tmp
->bss_index
== rsp
->bss_index
) {
2008 wcn36xx_dbg(WCN36XX_DBG_HAL
, "beacon missed bss_index %d\n",
2010 vif
= container_of((void *)tmp
,
2011 struct ieee80211_vif
,
2013 ieee80211_connection_loss(vif
);
2018 wcn36xx_warn("BSS index %d not found\n", rsp
->bss_index
);
2022 static int wcn36xx_smd_delete_sta_context_ind(struct wcn36xx
*wcn
,
2026 struct wcn36xx_hal_delete_sta_context_ind_msg
*rsp
= buf
;
2027 struct wcn36xx_vif
*tmp
;
2028 struct ieee80211_sta
*sta
= NULL
;
2030 if (len
!= sizeof(*rsp
)) {
2031 wcn36xx_warn("Corrupted delete sta indication\n");
2035 list_for_each_entry(tmp
, &wcn
->vif_list
, list
) {
2036 if (sta
&& (tmp
->sta
->sta_index
== rsp
->sta_id
)) {
2037 sta
= container_of((void *)tmp
->sta
,
2038 struct ieee80211_sta
,
2040 wcn36xx_dbg(WCN36XX_DBG_HAL
,
2041 "delete station indication %pM index %d\n",
2044 ieee80211_report_low_ack(sta
, 0);
2049 wcn36xx_warn("STA with addr %pM and index %d not found\n",
2055 int wcn36xx_smd_update_cfg(struct wcn36xx
*wcn
, u32 cfg_id
, u32 value
)
2057 struct wcn36xx_hal_update_cfg_req_msg msg_body
, *body
;
2061 mutex_lock(&wcn
->hal_mutex
);
2062 INIT_HAL_MSG(msg_body
, WCN36XX_HAL_UPDATE_CFG_REQ
);
2064 PREPARE_HAL_BUF(wcn
->hal_buf
, msg_body
);
2066 body
= (struct wcn36xx_hal_update_cfg_req_msg
*) wcn
->hal_buf
;
2067 len
= msg_body
.header
.len
;
2069 put_cfg_tlv_u32(wcn
, &len
, cfg_id
, value
);
2070 body
->header
.len
= len
;
2071 body
->len
= len
- sizeof(*body
);
2073 ret
= wcn36xx_smd_send_and_wait(wcn
, body
->header
.len
);
2075 wcn36xx_err("Sending hal_update_cfg failed\n");
2078 ret
= wcn36xx_smd_rsp_status_check(wcn
->hal_buf
, wcn
->hal_rsp_len
);
2080 wcn36xx_err("hal_update_cfg response failed err=%d\n", ret
);
2084 mutex_unlock(&wcn
->hal_mutex
);
2087 static void wcn36xx_smd_rsp_process(struct wcn36xx
*wcn
, void *buf
, size_t len
)
2089 struct wcn36xx_hal_msg_header
*msg_header
= buf
;
2090 struct wcn36xx_hal_ind_msg
*msg_ind
;
2091 wcn36xx_dbg_dump(WCN36XX_DBG_SMD_DUMP
, "SMD <<< ", buf
, len
);
2093 switch (msg_header
->msg_type
) {
2094 case WCN36XX_HAL_START_RSP
:
2095 case WCN36XX_HAL_CONFIG_STA_RSP
:
2096 case WCN36XX_HAL_CONFIG_BSS_RSP
:
2097 case WCN36XX_HAL_ADD_STA_SELF_RSP
:
2098 case WCN36XX_HAL_STOP_RSP
:
2099 case WCN36XX_HAL_DEL_STA_SELF_RSP
:
2100 case WCN36XX_HAL_DELETE_STA_RSP
:
2101 case WCN36XX_HAL_INIT_SCAN_RSP
:
2102 case WCN36XX_HAL_START_SCAN_RSP
:
2103 case WCN36XX_HAL_END_SCAN_RSP
:
2104 case WCN36XX_HAL_FINISH_SCAN_RSP
:
2105 case WCN36XX_HAL_DOWNLOAD_NV_RSP
:
2106 case WCN36XX_HAL_DELETE_BSS_RSP
:
2107 case WCN36XX_HAL_SEND_BEACON_RSP
:
2108 case WCN36XX_HAL_SET_LINK_ST_RSP
:
2109 case WCN36XX_HAL_UPDATE_PROBE_RSP_TEMPLATE_RSP
:
2110 case WCN36XX_HAL_SET_BSSKEY_RSP
:
2111 case WCN36XX_HAL_SET_STAKEY_RSP
:
2112 case WCN36XX_HAL_RMV_STAKEY_RSP
:
2113 case WCN36XX_HAL_RMV_BSSKEY_RSP
:
2114 case WCN36XX_HAL_ENTER_BMPS_RSP
:
2115 case WCN36XX_HAL_SET_POWER_PARAMS_RSP
:
2116 case WCN36XX_HAL_EXIT_BMPS_RSP
:
2117 case WCN36XX_HAL_KEEP_ALIVE_RSP
:
2118 case WCN36XX_HAL_DUMP_COMMAND_RSP
:
2119 case WCN36XX_HAL_ADD_BA_SESSION_RSP
:
2120 case WCN36XX_HAL_ADD_BA_RSP
:
2121 case WCN36XX_HAL_DEL_BA_RSP
:
2122 case WCN36XX_HAL_TRIGGER_BA_RSP
:
2123 case WCN36XX_HAL_UPDATE_CFG_RSP
:
2124 case WCN36XX_HAL_JOIN_RSP
:
2125 case WCN36XX_HAL_UPDATE_SCAN_PARAM_RSP
:
2126 case WCN36XX_HAL_CH_SWITCH_RSP
:
2127 case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP
:
2128 memcpy(wcn
->hal_buf
, buf
, len
);
2129 wcn
->hal_rsp_len
= len
;
2130 complete(&wcn
->hal_rsp_compl
);
2133 case WCN36XX_HAL_OTA_TX_COMPL_IND
:
2134 case WCN36XX_HAL_MISSED_BEACON_IND
:
2135 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND
:
2136 msg_ind
= kmalloc(sizeof(*msg_ind
), GFP_KERNEL
);
2139 msg_ind
->msg_len
= len
;
2140 msg_ind
->msg
= kmemdup(buf
, len
, GFP_KERNEL
);
2141 if (!msg_ind
->msg
) {
2145 * FIXME: Do something smarter then just
2146 * printing an error.
2148 wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
2149 msg_header
->msg_type
);
2152 mutex_lock(&wcn
->hal_ind_mutex
);
2153 list_add_tail(&msg_ind
->list
, &wcn
->hal_ind_queue
);
2154 queue_work(wcn
->hal_ind_wq
, &wcn
->hal_ind_work
);
2155 mutex_unlock(&wcn
->hal_ind_mutex
);
2156 wcn36xx_dbg(WCN36XX_DBG_HAL
, "indication arrived\n");
2159 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2160 msg_header
->msg_type
);
2163 static void wcn36xx_ind_smd_work(struct work_struct
*work
)
2165 struct wcn36xx
*wcn
=
2166 container_of(work
, struct wcn36xx
, hal_ind_work
);
2167 struct wcn36xx_hal_msg_header
*msg_header
;
2168 struct wcn36xx_hal_ind_msg
*hal_ind_msg
;
2170 mutex_lock(&wcn
->hal_ind_mutex
);
2172 hal_ind_msg
= list_first_entry(&wcn
->hal_ind_queue
,
2173 struct wcn36xx_hal_ind_msg
,
2176 msg_header
= (struct wcn36xx_hal_msg_header
*)hal_ind_msg
->msg
;
2178 switch (msg_header
->msg_type
) {
2179 case WCN36XX_HAL_OTA_TX_COMPL_IND
:
2180 wcn36xx_smd_tx_compl_ind(wcn
,
2182 hal_ind_msg
->msg_len
);
2184 case WCN36XX_HAL_MISSED_BEACON_IND
:
2185 wcn36xx_smd_missed_beacon_ind(wcn
,
2187 hal_ind_msg
->msg_len
);
2189 case WCN36XX_HAL_DELETE_STA_CONTEXT_IND
:
2190 wcn36xx_smd_delete_sta_context_ind(wcn
,
2192 hal_ind_msg
->msg_len
);
2195 wcn36xx_err("SMD_EVENT (%d) not supported\n",
2196 msg_header
->msg_type
);
2198 list_del(wcn
->hal_ind_queue
.next
);
2199 kfree(hal_ind_msg
->msg
);
2201 mutex_unlock(&wcn
->hal_ind_mutex
);
2203 int wcn36xx_smd_open(struct wcn36xx
*wcn
)
2206 wcn
->hal_ind_wq
= create_freezable_workqueue("wcn36xx_smd_ind");
2207 if (!wcn
->hal_ind_wq
) {
2208 wcn36xx_err("failed to allocate wq\n");
2212 INIT_WORK(&wcn
->hal_ind_work
, wcn36xx_ind_smd_work
);
2213 INIT_LIST_HEAD(&wcn
->hal_ind_queue
);
2214 mutex_init(&wcn
->hal_ind_mutex
);
2216 ret
= wcn
->ctrl_ops
->open(wcn
, wcn36xx_smd_rsp_process
);
2218 wcn36xx_err("failed to open control channel\n");
2225 destroy_workqueue(wcn
->hal_ind_wq
);
2230 void wcn36xx_smd_close(struct wcn36xx
*wcn
)
2232 wcn
->ctrl_ops
->close();
2233 destroy_workqueue(wcn
->hal_ind_wq
);
2234 mutex_destroy(&wcn
->hal_ind_mutex
);