]>
Commit | Line | Data |
---|---|---|
0c817338 LF |
1 | /****************************************************************************** |
2 | * | |
a8d76066 | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
0c817338 LF |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
0c817338 LF |
14 | * The full GNU General Public License is included in this distribution in the |
15 | * file called LICENSE. | |
16 | * | |
17 | * Contact Information: | |
18 | * wlanfae <wlanfae@realtek.com> | |
19 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | |
20 | * Hsinchu 300, Taiwan. | |
21 | * | |
22 | * Larry Finger <Larry.Finger@lwfinger.net> | |
0baa0fd7 | 23 | * |
0c817338 LF |
24 | *****************************************************************************/ |
25 | ||
26 | #include "wifi.h" | |
27 | #include "core.h" | |
28 | #include "cam.h" | |
29 | #include "base.h" | |
30 | #include "ps.h" | |
34ed780a | 31 | #include "pwrseqcmd.h" |
0c817338 | 32 | |
f7953b2a LF |
33 | #include "btcoexist/rtl_btc.h" |
34 | #include <linux/firmware.h> | |
b0302aba | 35 | #include <linux/export.h> |
f7953b2a | 36 | #include <net/cfg80211.h> |
b0302aba | 37 | |
25b13dbc LF |
38 | void rtl_addr_delay(u32 addr) |
39 | { | |
40 | if (addr == 0xfe) | |
41 | mdelay(50); | |
42 | else if (addr == 0xfd) | |
43 | mdelay(5); | |
44 | else if (addr == 0xfc) | |
45 | mdelay(1); | |
46 | else if (addr == 0xfb) | |
47 | udelay(50); | |
48 | else if (addr == 0xfa) | |
49 | udelay(5); | |
50 | else if (addr == 0xf9) | |
51 | udelay(1); | |
52 | } | |
53 | EXPORT_SYMBOL(rtl_addr_delay); | |
54 | ||
55 | void rtl_rfreg_delay(struct ieee80211_hw *hw, enum radio_path rfpath, u32 addr, | |
56 | u32 mask, u32 data) | |
57 | { | |
58 | if (addr == 0xfe) { | |
59 | mdelay(50); | |
60 | } else if (addr == 0xfd) { | |
61 | mdelay(5); | |
62 | } else if (addr == 0xfc) { | |
63 | mdelay(1); | |
64 | } else if (addr == 0xfb) { | |
65 | udelay(50); | |
66 | } else if (addr == 0xfa) { | |
67 | udelay(5); | |
68 | } else if (addr == 0xf9) { | |
69 | udelay(1); | |
70 | } else { | |
71 | rtl_set_rfreg(hw, rfpath, addr, mask, data); | |
72 | udelay(1); | |
73 | } | |
74 | } | |
75 | EXPORT_SYMBOL(rtl_rfreg_delay); | |
76 | ||
77 | void rtl_bb_delay(struct ieee80211_hw *hw, u32 addr, u32 data) | |
78 | { | |
79 | if (addr == 0xfe) { | |
80 | mdelay(50); | |
81 | } else if (addr == 0xfd) { | |
82 | mdelay(5); | |
83 | } else if (addr == 0xfc) { | |
84 | mdelay(1); | |
85 | } else if (addr == 0xfb) { | |
86 | udelay(50); | |
87 | } else if (addr == 0xfa) { | |
88 | udelay(5); | |
89 | } else if (addr == 0xf9) { | |
90 | udelay(1); | |
91 | } else { | |
92 | rtl_set_bbreg(hw, addr, MASKDWORD, data); | |
93 | udelay(1); | |
94 | } | |
95 | } | |
96 | EXPORT_SYMBOL(rtl_bb_delay); | |
97 | ||
b0302aba LF |
98 | void rtl_fw_cb(const struct firmware *firmware, void *context) |
99 | { | |
100 | struct ieee80211_hw *hw = context; | |
101 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
102 | int err; | |
103 | ||
104 | RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, | |
f7953b2a | 105 | "Firmware callback routine entered!\n"); |
b0302aba LF |
106 | complete(&rtlpriv->firmware_loading_complete); |
107 | if (!firmware) { | |
62009b7f LF |
108 | if (rtlpriv->cfg->alt_fw_name) { |
109 | err = request_firmware(&firmware, | |
110 | rtlpriv->cfg->alt_fw_name, | |
111 | rtlpriv->io.dev); | |
112 | pr_info("Loading alternative firmware %s\n", | |
113 | rtlpriv->cfg->alt_fw_name); | |
114 | if (!err) | |
115 | goto found_alt; | |
116 | } | |
b0302aba LF |
117 | pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name); |
118 | rtlpriv->max_fw_size = 0; | |
119 | return; | |
120 | } | |
62009b7f | 121 | found_alt: |
b0302aba LF |
122 | if (firmware->size > rtlpriv->max_fw_size) { |
123 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | |
124 | "Firmware is too big!\n"); | |
125 | release_firmware(firmware); | |
126 | return; | |
127 | } | |
128 | memcpy(rtlpriv->rtlhal.pfirmware, firmware->data, firmware->size); | |
129 | rtlpriv->rtlhal.fwsize = firmware->size; | |
130 | release_firmware(firmware); | |
b0302aba LF |
131 | } |
132 | EXPORT_SYMBOL(rtl_fw_cb); | |
133 | ||
0c817338 LF |
134 | /*mutex for start & stop is must here. */ |
135 | static int rtl_op_start(struct ieee80211_hw *hw) | |
136 | { | |
f7953b2a | 137 | int err = 0; |
0c817338 LF |
138 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
139 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | |
140 | ||
141 | if (!is_hal_stop(rtlhal)) | |
142 | return 0; | |
143 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) | |
144 | return 0; | |
8a09d6d8 | 145 | mutex_lock(&rtlpriv->locks.conf_mutex); |
0c817338 | 146 | err = rtlpriv->intf_ops->adapter_start(hw); |
32473284 LF |
147 | if (!err) |
148 | rtl_watch_dog_timer_callback((unsigned long)hw); | |
8a09d6d8 | 149 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
150 | return err; |
151 | } | |
152 | ||
153 | static void rtl_op_stop(struct ieee80211_hw *hw) | |
154 | { | |
155 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
156 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
157 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | |
158 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | |
f7953b2a | 159 | bool support_remote_wakeup = false; |
0c817338 LF |
160 | |
161 | if (is_hal_stop(rtlhal)) | |
162 | return; | |
163 | ||
f7953b2a LF |
164 | rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN, |
165 | (u8 *)(&support_remote_wakeup)); | |
26634c4b LF |
166 | /* here is must, because adhoc do stop and start, |
167 | * but stop with RFOFF may cause something wrong, | |
168 | * like adhoc TP | |
169 | */ | |
f7953b2a | 170 | if (unlikely(ppsc->rfpwr_state == ERFOFF)) |
0c817338 | 171 | rtl_ips_nic_on(hw); |
0c817338 | 172 | |
8a09d6d8 | 173 | mutex_lock(&rtlpriv->locks.conf_mutex); |
f7953b2a LF |
174 | /* if wowlan supported, DON'T clear connected info */ |
175 | if (!(support_remote_wakeup && | |
176 | rtlhal->enter_pnp_sleep)) { | |
177 | mac->link_state = MAC80211_NOLINK; | |
178 | memset(mac->bssid, 0, 6); | |
179 | mac->vendor = PEER_UNKNOWN; | |
0c817338 | 180 | |
f7953b2a LF |
181 | /* reset sec info */ |
182 | rtl_cam_reset_sec_info(hw); | |
0c817338 | 183 | |
f7953b2a LF |
184 | rtl_deinit_deferred_work(hw); |
185 | } | |
0c817338 LF |
186 | rtlpriv->intf_ops->adapter_stop(hw); |
187 | ||
8a09d6d8 | 188 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
189 | } |
190 | ||
36323f81 TH |
191 | static void rtl_op_tx(struct ieee80211_hw *hw, |
192 | struct ieee80211_tx_control *control, | |
193 | struct sk_buff *skb) | |
0c817338 LF |
194 | { |
195 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
196 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | |
197 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | |
0baa0fd7 C |
198 | struct rtl_tcb_desc tcb_desc; |
199 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); | |
0c817338 LF |
200 | |
201 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) | |
202 | goto err_free; | |
203 | ||
204 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) | |
205 | goto err_free; | |
206 | ||
36323f81 TH |
207 | if (!rtlpriv->intf_ops->waitq_insert(hw, control->sta, skb)) |
208 | rtlpriv->intf_ops->adapter_tx(hw, control->sta, skb, &tcb_desc); | |
7bb45683 | 209 | return; |
0c817338 LF |
210 | |
211 | err_free: | |
212 | dev_kfree_skb_any(skb); | |
0c817338 LF |
213 | } |
214 | ||
215 | static int rtl_op_add_interface(struct ieee80211_hw *hw, | |
216 | struct ieee80211_vif *vif) | |
217 | { | |
218 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
219 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
220 | int err = 0; | |
221 | ||
222 | if (mac->vif) { | |
223 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, | |
f30d7507 | 224 | "vif has been set!! mac->vif = 0x%p\n", mac->vif); |
0c817338 LF |
225 | return -EOPNOTSUPP; |
226 | } | |
227 | ||
f7953b2a LF |
228 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER; |
229 | ||
0c817338 LF |
230 | rtl_ips_nic_on(hw); |
231 | ||
8a09d6d8 | 232 | mutex_lock(&rtlpriv->locks.conf_mutex); |
26634c4b LF |
233 | switch (ieee80211_vif_type_p2p(vif)) { |
234 | case NL80211_IFTYPE_P2P_CLIENT: | |
235 | mac->p2p = P2P_ROLE_CLIENT; | |
236 | /*fall through*/ | |
0c817338 LF |
237 | case NL80211_IFTYPE_STATION: |
238 | if (mac->beacon_enabled == 1) { | |
239 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f30d7507 | 240 | "NL80211_IFTYPE_STATION\n"); |
0c817338 LF |
241 | mac->beacon_enabled = 0; |
242 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, | |
f7953b2a | 243 | rtlpriv->cfg->maps[RTL_IBSS_INT_MASKS]); |
0c817338 LF |
244 | } |
245 | break; | |
246 | case NL80211_IFTYPE_ADHOC: | |
247 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f30d7507 | 248 | "NL80211_IFTYPE_ADHOC\n"); |
0c817338 LF |
249 | |
250 | mac->link_state = MAC80211_LINKED; | |
251 | rtlpriv->cfg->ops->set_bcn_reg(hw); | |
0baa0fd7 C |
252 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) |
253 | mac->basic_rates = 0xfff; | |
254 | else | |
255 | mac->basic_rates = 0xff0; | |
256 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, | |
f7953b2a | 257 | (u8 *)(&mac->basic_rates)); |
0baa0fd7 | 258 | |
0c817338 | 259 | break; |
26634c4b LF |
260 | case NL80211_IFTYPE_P2P_GO: |
261 | mac->p2p = P2P_ROLE_GO; | |
262 | /*fall through*/ | |
0c817338 LF |
263 | case NL80211_IFTYPE_AP: |
264 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f30d7507 | 265 | "NL80211_IFTYPE_AP\n"); |
0baa0fd7 C |
266 | |
267 | mac->link_state = MAC80211_LINKED; | |
268 | rtlpriv->cfg->ops->set_bcn_reg(hw); | |
269 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) | |
270 | mac->basic_rates = 0xfff; | |
271 | else | |
272 | mac->basic_rates = 0xff0; | |
273 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, | |
f7953b2a | 274 | (u8 *)(&mac->basic_rates)); |
0c817338 | 275 | break; |
26634c4b LF |
276 | case NL80211_IFTYPE_MESH_POINT: |
277 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
278 | "NL80211_IFTYPE_MESH_POINT\n"); | |
279 | ||
280 | mac->link_state = MAC80211_LINKED; | |
281 | rtlpriv->cfg->ops->set_bcn_reg(hw); | |
282 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) | |
283 | mac->basic_rates = 0xfff; | |
284 | else | |
285 | mac->basic_rates = 0xff0; | |
286 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, | |
287 | (u8 *)(&mac->basic_rates)); | |
288 | break; | |
0c817338 LF |
289 | default: |
290 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | |
f7953b2a | 291 | "operation mode %d is not support!\n", vif->type); |
0c817338 LF |
292 | err = -EOPNOTSUPP; |
293 | goto out; | |
294 | } | |
295 | ||
26634c4b LF |
296 | if (mac->p2p) { |
297 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
298 | "p2p role %x\n", vif->type); | |
299 | mac->basic_rates = 0xff0;/*disable cck rate for p2p*/ | |
300 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, | |
301 | (u8 *)(&mac->basic_rates)); | |
302 | } | |
0c817338 LF |
303 | mac->vif = vif; |
304 | mac->opmode = vif->type; | |
305 | rtlpriv->cfg->ops->set_network_type(hw, vif->type); | |
306 | memcpy(mac->mac_addr, vif->addr, ETH_ALEN); | |
307 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr); | |
308 | ||
309 | out: | |
8a09d6d8 | 310 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
311 | return err; |
312 | } | |
313 | ||
314 | static void rtl_op_remove_interface(struct ieee80211_hw *hw, | |
315 | struct ieee80211_vif *vif) | |
316 | { | |
317 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
318 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
319 | ||
8a09d6d8 | 320 | mutex_lock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
321 | |
322 | /* Free beacon resources */ | |
26634c4b LF |
323 | if ((vif->type == NL80211_IFTYPE_AP) || |
324 | (vif->type == NL80211_IFTYPE_ADHOC) || | |
325 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { | |
0c817338 LF |
326 | if (mac->beacon_enabled == 1) { |
327 | mac->beacon_enabled = 0; | |
328 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, | |
f7953b2a | 329 | rtlpriv->cfg->maps[RTL_IBSS_INT_MASKS]); |
0c817338 LF |
330 | } |
331 | } | |
332 | ||
333 | /* | |
334 | *Note: We assume NL80211_IFTYPE_UNSPECIFIED as | |
335 | *NO LINK for our hardware. | |
336 | */ | |
26634c4b | 337 | mac->p2p = 0; |
0c817338 LF |
338 | mac->vif = NULL; |
339 | mac->link_state = MAC80211_NOLINK; | |
d458cdf7 | 340 | memset(mac->bssid, 0, ETH_ALEN); |
0baa0fd7 | 341 | mac->vendor = PEER_UNKNOWN; |
0c817338 LF |
342 | mac->opmode = NL80211_IFTYPE_UNSPECIFIED; |
343 | rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); | |
f7953b2a | 344 | |
8a09d6d8 | 345 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 | 346 | } |
26634c4b | 347 | static int rtl_op_change_interface(struct ieee80211_hw *hw, |
f7953b2a LF |
348 | struct ieee80211_vif *vif, |
349 | enum nl80211_iftype new_type, bool p2p) | |
26634c4b LF |
350 | { |
351 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
352 | int ret; | |
353 | rtl_op_remove_interface(hw, vif); | |
354 | ||
355 | vif->type = new_type; | |
356 | vif->p2p = p2p; | |
357 | ret = rtl_op_add_interface(hw, vif); | |
358 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f7953b2a | 359 | "p2p %x\n", p2p); |
26634c4b LF |
360 | return ret; |
361 | } | |
362 | ||
f7953b2a LF |
363 | #ifdef CONFIG_PM |
364 | static u16 crc16_ccitt(u8 data, u16 crc) | |
365 | { | |
366 | u8 shift_in, data_bit, crc_bit11, crc_bit4, crc_bit15; | |
367 | u8 i; | |
368 | u16 result; | |
369 | ||
370 | for (i = 0; i < 8; i++) { | |
371 | crc_bit15 = ((crc & BIT(15)) ? 1 : 0); | |
372 | data_bit = (data & (BIT(0) << i) ? 1 : 0); | |
373 | shift_in = crc_bit15 ^ data_bit; | |
374 | ||
375 | result = crc << 1; | |
376 | if (shift_in == 0) | |
377 | result &= (~BIT(0)); | |
378 | else | |
379 | result |= BIT(0); | |
380 | ||
381 | crc_bit11 = ((crc & BIT(11)) ? 1 : 0) ^ shift_in; | |
382 | if (crc_bit11 == 0) | |
383 | result &= (~BIT(12)); | |
384 | else | |
385 | result |= BIT(12); | |
386 | ||
387 | crc_bit4 = ((crc & BIT(4)) ? 1 : 0) ^ shift_in; | |
388 | if (crc_bit4 == 0) | |
389 | result &= (~BIT(5)); | |
390 | else | |
391 | result |= BIT(5); | |
392 | ||
393 | crc = result; | |
394 | } | |
395 | ||
396 | return crc; | |
397 | } | |
398 | ||
399 | static u16 _calculate_wol_pattern_crc(u8 *pattern, u16 len) | |
400 | { | |
401 | u16 crc = 0xffff; | |
402 | u32 i; | |
403 | ||
404 | for (i = 0; i < len; i++) | |
405 | crc = crc16_ccitt(pattern[i], crc); | |
406 | ||
407 | crc = ~crc; | |
408 | ||
409 | return crc; | |
410 | } | |
411 | ||
412 | static void _rtl_add_wowlan_patterns(struct ieee80211_hw *hw, | |
413 | struct cfg80211_wowlan *wow) | |
414 | { | |
415 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
416 | struct rtl_mac *mac = &rtlpriv->mac80211; | |
417 | struct cfg80211_pkt_pattern *patterns = wow->patterns; | |
418 | struct rtl_wow_pattern rtl_pattern; | |
419 | const u8 *pattern_os, *mask_os; | |
420 | u8 mask[MAX_WOL_BIT_MASK_SIZE] = {0}; | |
421 | u8 content[MAX_WOL_PATTERN_SIZE] = {0}; | |
422 | u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
423 | u8 multicast_addr1[2] = {0x33, 0x33}; | |
424 | u8 multicast_addr2[3] = {0x01, 0x00, 0x5e}; | |
425 | u8 i, mask_len; | |
426 | u16 j, len; | |
427 | ||
428 | for (i = 0; i < wow->n_patterns; i++) { | |
429 | memset(&rtl_pattern, 0, sizeof(struct rtl_wow_pattern)); | |
430 | memset(mask, 0, MAX_WOL_BIT_MASK_SIZE); | |
431 | if (patterns[i].pattern_len > MAX_WOL_PATTERN_SIZE) { | |
432 | RT_TRACE(rtlpriv, COMP_POWER, DBG_WARNING, | |
433 | "Pattern[%d] is too long\n", i); | |
434 | continue; | |
435 | } | |
436 | pattern_os = patterns[i].pattern; | |
437 | mask_len = DIV_ROUND_UP(patterns[i].pattern_len, 8); | |
438 | mask_os = patterns[i].mask; | |
439 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, | |
440 | "pattern content\n", pattern_os, | |
441 | patterns[i].pattern_len); | |
442 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, | |
443 | "mask content\n", mask_os, mask_len); | |
444 | /* 1. unicast? multicast? or broadcast? */ | |
445 | if (memcmp(pattern_os, broadcast_addr, 6) == 0) | |
446 | rtl_pattern.type = BROADCAST_PATTERN; | |
447 | else if (memcmp(pattern_os, multicast_addr1, 2) == 0 || | |
448 | memcmp(pattern_os, multicast_addr2, 3) == 0) | |
449 | rtl_pattern.type = MULTICAST_PATTERN; | |
450 | else if (memcmp(pattern_os, mac->mac_addr, 6) == 0) | |
451 | rtl_pattern.type = UNICAST_PATTERN; | |
452 | else | |
453 | rtl_pattern.type = UNKNOWN_TYPE; | |
454 | ||
455 | /* 2. translate mask_from_os to mask_for_hw */ | |
456 | ||
457 | /****************************************************************************** | |
458 | * pattern from OS uses 'ethenet frame', like this: | |
459 | ||
460 | | 6 | 6 | 2 | 20 | Variable | 4 | | |
461 | |--------+--------+------+-----------+------------+-----| | |
462 | | 802.3 Mac Header | IP Header | TCP Packet | FCS | | |
463 | | DA | SA | Type | | |
464 | ||
465 | * BUT, packet catched by our HW is in '802.11 frame', begin from LLC, | |
466 | ||
467 | | 24 or 30 | 6 | 2 | 20 | Variable | 4 | | |
468 | |-------------------+--------+------+-----------+------------+-----| | |
469 | | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS | | |
470 | | Others | Tpye | | |
471 | ||
472 | * Therefore, we need translate mask_from_OS to mask_to_hw. | |
473 | * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0, | |
474 | * because new mask[0~5] means 'SA', but our HW packet begins from LLC, | |
475 | * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match. | |
476 | ******************************************************************************/ | |
477 | ||
478 | /* Shift 6 bits */ | |
479 | for (j = 0; j < mask_len - 1; j++) { | |
480 | mask[j] = mask_os[j] >> 6; | |
481 | mask[j] |= (mask_os[j + 1] & 0x3F) << 2; | |
482 | } | |
483 | mask[j] = (mask_os[j] >> 6) & 0x3F; | |
484 | /* Set bit 0-5 to zero */ | |
485 | mask[0] &= 0xC0; | |
486 | ||
487 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, | |
488 | "mask to hw\n", mask, mask_len); | |
489 | for (j = 0; j < (MAX_WOL_BIT_MASK_SIZE + 1) / 4; j++) { | |
490 | rtl_pattern.mask[j] = mask[j * 4]; | |
491 | rtl_pattern.mask[j] |= (mask[j * 4 + 1] << 8); | |
492 | rtl_pattern.mask[j] |= (mask[j * 4 + 2] << 16); | |
493 | rtl_pattern.mask[j] |= (mask[j * 4 + 3] << 24); | |
494 | } | |
495 | ||
496 | /* To get the wake up pattern from the mask. | |
497 | * We do not count first 12 bits which means | |
498 | * DA[6] and SA[6] in the pattern to match HW design. | |
499 | */ | |
500 | len = 0; | |
501 | for (j = 12; j < patterns[i].pattern_len; j++) { | |
502 | if ((mask_os[j / 8] >> (j % 8)) & 0x01) { | |
503 | content[len] = pattern_os[j]; | |
504 | len++; | |
505 | } | |
506 | } | |
507 | ||
508 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, | |
509 | "pattern to hw\n", content, len); | |
510 | /* 3. calculate crc */ | |
511 | rtl_pattern.crc = _calculate_wol_pattern_crc(content, len); | |
512 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, | |
513 | "CRC_Remainder = 0x%x", rtl_pattern.crc); | |
514 | ||
515 | /* 4. write crc & mask_for_hw to hw */ | |
516 | rtlpriv->cfg->ops->add_wowlan_pattern(hw, &rtl_pattern, i); | |
517 | } | |
518 | rtl_write_byte(rtlpriv, 0x698, wow->n_patterns); | |
519 | } | |
520 | ||
521 | static int rtl_op_suspend(struct ieee80211_hw *hw, | |
522 | struct cfg80211_wowlan *wow) | |
523 | { | |
524 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
525 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); | |
526 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | |
527 | struct timeval ts; | |
528 | ||
529 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n"); | |
530 | if (WARN_ON(!wow)) | |
531 | return -EINVAL; | |
532 | ||
533 | /* to resolve s4 can not wake up*/ | |
534 | do_gettimeofday(&ts); | |
535 | rtlhal->last_suspend_sec = ts.tv_sec; | |
536 | ||
537 | if ((ppsc->wo_wlan_mode & WAKE_ON_PATTERN_MATCH) && wow->n_patterns) | |
538 | _rtl_add_wowlan_patterns(hw, wow); | |
539 | ||
540 | rtlhal->driver_is_goingto_unload = true; | |
541 | rtlhal->enter_pnp_sleep = true; | |
542 | ||
543 | rtl_lps_leave(hw); | |
544 | rtl_op_stop(hw); | |
545 | device_set_wakeup_enable(wiphy_dev(hw->wiphy), true); | |
546 | return 0; | |
547 | } | |
548 | ||
549 | static int rtl_op_resume(struct ieee80211_hw *hw) | |
550 | { | |
551 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
552 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); | |
553 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
554 | struct timeval ts; | |
555 | ||
556 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n"); | |
557 | rtlhal->driver_is_goingto_unload = false; | |
558 | rtlhal->enter_pnp_sleep = false; | |
559 | rtlhal->wake_from_pnp_sleep = true; | |
560 | ||
561 | /* to resovle s4 can not wake up*/ | |
562 | do_gettimeofday(&ts); | |
563 | if (ts.tv_sec - rtlhal->last_suspend_sec < 5) | |
564 | return -1; | |
565 | ||
566 | rtl_op_start(hw); | |
567 | device_set_wakeup_enable(wiphy_dev(hw->wiphy), false); | |
568 | ieee80211_resume_disconnect(mac->vif); | |
569 | rtlhal->wake_from_pnp_sleep = false; | |
570 | return 0; | |
571 | } | |
572 | #endif | |
573 | ||
0c817338 LF |
574 | static int rtl_op_config(struct ieee80211_hw *hw, u32 changed) |
575 | { | |
576 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
577 | struct rtl_phy *rtlphy = &(rtlpriv->phy); | |
578 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
579 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | |
580 | struct ieee80211_conf *conf = &hw->conf; | |
581 | ||
26634c4b LF |
582 | if (mac->skip_scan) |
583 | return 1; | |
584 | ||
8a09d6d8 | 585 | mutex_lock(&rtlpriv->locks.conf_mutex); |
f7953b2a | 586 | if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { /* BIT(2)*/ |
0c817338 | 587 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
f30d7507 | 588 | "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n"); |
0c817338 LF |
589 | } |
590 | ||
591 | /*For IPS */ | |
592 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { | |
593 | if (hw->conf.flags & IEEE80211_CONF_IDLE) | |
594 | rtl_ips_nic_off(hw); | |
595 | else | |
596 | rtl_ips_nic_on(hw); | |
597 | } else { | |
598 | /* | |
599 | *although rfoff may not cause by ips, but we will | |
600 | *check the reason in set_rf_power_state function | |
601 | */ | |
602 | if (unlikely(ppsc->rfpwr_state == ERFOFF)) | |
603 | rtl_ips_nic_on(hw); | |
604 | } | |
605 | ||
606 | /*For LPS */ | |
607 | if (changed & IEEE80211_CONF_CHANGE_PS) { | |
0baa0fd7 C |
608 | cancel_delayed_work(&rtlpriv->works.ps_work); |
609 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); | |
610 | if (conf->flags & IEEE80211_CONF_PS) { | |
611 | rtlpriv->psc.sw_ps_enabled = true; | |
612 | /* sleep here is must, or we may recv the beacon and | |
613 | * cause mac80211 into wrong ps state, this will cause | |
614 | * power save nullfunc send fail, and further cause | |
615 | * pkt loss, So sleep must quickly but not immediatly | |
616 | * because that will cause nullfunc send by mac80211 | |
617 | * fail, and cause pkt loss, we have tested that 5mA | |
618 | * is worked very well */ | |
3eda95de | 619 | if (!rtlpriv->psc.multi_buffered) |
0baa0fd7 | 620 | queue_delayed_work(rtlpriv->works.rtl_wq, |
f7953b2a LF |
621 | &rtlpriv->works.ps_work, |
622 | MSECS(5)); | |
0baa0fd7 C |
623 | } else { |
624 | rtl_swlps_rf_awake(hw); | |
625 | rtlpriv->psc.sw_ps_enabled = false; | |
626 | } | |
0c817338 LF |
627 | } |
628 | ||
629 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { | |
630 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f30d7507 JP |
631 | "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n", |
632 | hw->conf.long_frame_max_tx_count); | |
0c817338 LF |
633 | mac->retry_long = hw->conf.long_frame_max_tx_count; |
634 | mac->retry_short = hw->conf.long_frame_max_tx_count; | |
635 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT, | |
f7953b2a | 636 | (u8 *)(&hw->conf.long_frame_max_tx_count)); |
0c817338 LF |
637 | } |
638 | ||
f7953b2a LF |
639 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL && |
640 | !rtlpriv->proximity.proxim_on) { | |
675a0b04 | 641 | struct ieee80211_channel *channel = hw->conf.chandef.chan; |
f7953b2a LF |
642 | enum nl80211_chan_width width = hw->conf.chandef.width; |
643 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
0c817338 LF |
644 | u8 wide_chan = (u8) channel->hw_value; |
645 | ||
f7953b2a LF |
646 | /* channel_type is for 20&40M */ |
647 | if (width < NL80211_CHAN_WIDTH_80) | |
648 | channel_type = | |
649 | cfg80211_get_chandef_type(&hw->conf.chandef); | |
26634c4b LF |
650 | if (mac->act_scanning) |
651 | mac->n_channels++; | |
652 | ||
653 | if (rtlpriv->dm.supp_phymode_switch && | |
f7953b2a LF |
654 | mac->link_state < MAC80211_LINKED && |
655 | !mac->act_scanning) { | |
26634c4b LF |
656 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
657 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); | |
658 | } | |
659 | ||
0c817338 LF |
660 | /* |
661 | *because we should back channel to | |
662 | *current_network.chan in in scanning, | |
663 | *So if set_chan == current_network.chan | |
664 | *we should set it. | |
665 | *because mac80211 tell us wrong bw40 | |
666 | *info for cisco1253 bw20, so we modify | |
667 | *it here based on UPPER & LOWER | |
668 | */ | |
f7953b2a LF |
669 | |
670 | if (width >= NL80211_CHAN_WIDTH_80) { | |
671 | if (width == NL80211_CHAN_WIDTH_80) { | |
672 | u32 center = hw->conf.chandef.center_freq1; | |
673 | u32 primary = | |
674 | (u32)hw->conf.chandef.chan->center_freq; | |
675 | ||
676 | rtlphy->current_chan_bw = | |
677 | HT_CHANNEL_WIDTH_80; | |
678 | mac->bw_80 = true; | |
679 | mac->bw_40 = true; | |
680 | if (center > primary) { | |
681 | mac->cur_80_prime_sc = | |
682 | PRIME_CHNL_OFFSET_LOWER; | |
683 | if (center - primary == 10) { | |
684 | mac->cur_40_prime_sc = | |
685 | PRIME_CHNL_OFFSET_UPPER; | |
686 | ||
687 | wide_chan += 2; | |
688 | } else if (center - primary == 30) { | |
689 | mac->cur_40_prime_sc = | |
690 | PRIME_CHNL_OFFSET_LOWER; | |
691 | ||
692 | wide_chan += 6; | |
693 | } | |
694 | } else { | |
695 | mac->cur_80_prime_sc = | |
696 | PRIME_CHNL_OFFSET_UPPER; | |
697 | if (primary - center == 10) { | |
698 | mac->cur_40_prime_sc = | |
699 | PRIME_CHNL_OFFSET_LOWER; | |
700 | ||
701 | wide_chan -= 2; | |
702 | } else if (primary - center == 30) { | |
703 | mac->cur_40_prime_sc = | |
704 | PRIME_CHNL_OFFSET_UPPER; | |
705 | ||
706 | wide_chan -= 6; | |
707 | } | |
708 | } | |
709 | } | |
710 | } else { | |
711 | switch (channel_type) { | |
712 | case NL80211_CHAN_HT20: | |
713 | case NL80211_CHAN_NO_HT: | |
714 | /* SC */ | |
715 | mac->cur_40_prime_sc = | |
716 | PRIME_CHNL_OFFSET_DONT_CARE; | |
717 | rtlphy->current_chan_bw = | |
718 | HT_CHANNEL_WIDTH_20; | |
719 | mac->bw_40 = false; | |
720 | mac->bw_80 = false; | |
721 | break; | |
722 | case NL80211_CHAN_HT40MINUS: | |
723 | /* SC */ | |
724 | mac->cur_40_prime_sc = | |
725 | PRIME_CHNL_OFFSET_UPPER; | |
726 | rtlphy->current_chan_bw = | |
727 | HT_CHANNEL_WIDTH_20_40; | |
728 | mac->bw_40 = true; | |
729 | mac->bw_80 = false; | |
730 | ||
731 | /*wide channel */ | |
732 | wide_chan -= 2; | |
733 | ||
734 | break; | |
735 | case NL80211_CHAN_HT40PLUS: | |
736 | /* SC */ | |
737 | mac->cur_40_prime_sc = | |
738 | PRIME_CHNL_OFFSET_LOWER; | |
739 | rtlphy->current_chan_bw = | |
740 | HT_CHANNEL_WIDTH_20_40; | |
741 | mac->bw_40 = true; | |
742 | mac->bw_80 = false; | |
743 | ||
744 | /*wide channel */ | |
745 | wide_chan += 2; | |
746 | ||
747 | break; | |
748 | default: | |
749 | mac->bw_40 = false; | |
750 | mac->bw_80 = false; | |
751 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | |
752 | "switch case not processed\n"); | |
753 | break; | |
754 | } | |
0c817338 LF |
755 | } |
756 | ||
757 | if (wide_chan <= 0) | |
758 | wide_chan = 1; | |
0baa0fd7 | 759 | |
f7953b2a | 760 | /* In scanning, when before we offchannel we may send a ps=1 |
26634c4b LF |
761 | * null to AP, and then we may send a ps = 0 null to AP quickly, |
762 | * but first null may have caused AP to put lots of packet to | |
763 | * hw tx buffer. These packets must be tx'd before we go off | |
764 | * channel so we must delay more time to let AP flush these | |
765 | * packets before going offchannel, or dis-association or | |
766 | * delete BA will be caused by AP | |
0baa0fd7 | 767 | */ |
9c050440 MM |
768 | if (rtlpriv->mac80211.offchan_delay) { |
769 | rtlpriv->mac80211.offchan_delay = false; | |
0baa0fd7 C |
770 | mdelay(50); |
771 | } | |
f7953b2a | 772 | |
0c817338 LF |
773 | rtlphy->current_channel = wide_chan; |
774 | ||
0c817338 | 775 | rtlpriv->cfg->ops->switch_channel(hw); |
0baa0fd7 | 776 | rtlpriv->cfg->ops->set_channel_access(hw); |
f7953b2a | 777 | rtlpriv->cfg->ops->set_bw_mode(hw, channel_type); |
0c817338 LF |
778 | } |
779 | ||
8a09d6d8 | 780 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
781 | |
782 | return 0; | |
783 | } | |
784 | ||
785 | static void rtl_op_configure_filter(struct ieee80211_hw *hw, | |
f7953b2a LF |
786 | unsigned int changed_flags, |
787 | unsigned int *new_flags, u64 multicast) | |
0c817338 | 788 | { |
99958588 | 789 | bool update_rcr = false; |
0c817338 LF |
790 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
791 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
792 | ||
793 | *new_flags &= RTL_SUPPORTED_FILTERS; | |
f7953b2a | 794 | if (0 == changed_flags) |
0c817338 LF |
795 | return; |
796 | ||
797 | /*TODO: we disable broadcase now, so enable here */ | |
798 | if (changed_flags & FIF_ALLMULTI) { | |
799 | if (*new_flags & FIF_ALLMULTI) { | |
f7953b2a | 800 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] | |
0c817338 LF |
801 | rtlpriv->cfg->maps[MAC_RCR_AB]; |
802 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f30d7507 | 803 | "Enable receive multicast frame\n"); |
0c817338 | 804 | } else { |
f7953b2a | 805 | mac->rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] | |
0c817338 LF |
806 | rtlpriv->cfg->maps[MAC_RCR_AB]); |
807 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f30d7507 | 808 | "Disable receive multicast frame\n"); |
0c817338 | 809 | } |
99958588 | 810 | update_rcr = true; |
0c817338 LF |
811 | } |
812 | ||
813 | if (changed_flags & FIF_FCSFAIL) { | |
814 | if (*new_flags & FIF_FCSFAIL) { | |
f7953b2a | 815 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32]; |
0c817338 | 816 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
f30d7507 | 817 | "Enable receive FCS error frame\n"); |
0c817338 | 818 | } else { |
f7953b2a | 819 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32]; |
0c817338 | 820 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
f30d7507 | 821 | "Disable receive FCS error frame\n"); |
0c817338 | 822 | } |
99958588 LB |
823 | if (!update_rcr) |
824 | update_rcr = true; | |
0c817338 LF |
825 | } |
826 | ||
f7953b2a LF |
827 | /* if ssid not set to hw don't check bssid |
828 | * here just used for linked scanning, & linked | |
829 | * and nolink check bssid is set in set network_type | |
830 | */ | |
831 | if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) && | |
832 | (mac->link_state >= MAC80211_LINKED)) { | |
833 | if (mac->opmode != NL80211_IFTYPE_AP && | |
834 | mac->opmode != NL80211_IFTYPE_MESH_POINT) { | |
835 | if (*new_flags & FIF_BCN_PRBRESP_PROMISC) | |
836 | rtlpriv->cfg->ops->set_chk_bssid(hw, false); | |
837 | else | |
838 | rtlpriv->cfg->ops->set_chk_bssid(hw, true); | |
99958588 LB |
839 | if (update_rcr) |
840 | update_rcr = false; | |
f7953b2a LF |
841 | } |
842 | } | |
0c817338 LF |
843 | |
844 | if (changed_flags & FIF_CONTROL) { | |
845 | if (*new_flags & FIF_CONTROL) { | |
f7953b2a | 846 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF]; |
0c817338 LF |
847 | |
848 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f7953b2a | 849 | "Enable receive control frame.\n"); |
0c817338 | 850 | } else { |
f7953b2a | 851 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF]; |
0c817338 | 852 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
f7953b2a | 853 | "Disable receive control frame.\n"); |
0c817338 | 854 | } |
99958588 LB |
855 | if (!update_rcr) |
856 | update_rcr = true; | |
0c817338 LF |
857 | } |
858 | ||
859 | if (changed_flags & FIF_OTHER_BSS) { | |
860 | if (*new_flags & FIF_OTHER_BSS) { | |
f7953b2a | 861 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP]; |
0c817338 | 862 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
f7953b2a | 863 | "Enable receive other BSS's frame.\n"); |
0c817338 | 864 | } else { |
f7953b2a | 865 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP]; |
0c817338 | 866 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
f7953b2a | 867 | "Disable receive other BSS's frame.\n"); |
0c817338 | 868 | } |
99958588 LB |
869 | if (!update_rcr) |
870 | update_rcr = true; | |
0c817338 | 871 | } |
99958588 LB |
872 | |
873 | if (update_rcr) | |
874 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, | |
875 | (u8 *)(&mac->rx_conf)); | |
0c817338 | 876 | } |
0baa0fd7 C |
877 | static int rtl_op_sta_add(struct ieee80211_hw *hw, |
878 | struct ieee80211_vif *vif, | |
879 | struct ieee80211_sta *sta) | |
880 | { | |
881 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
882 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | |
26634c4b | 883 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
0baa0fd7 C |
884 | struct rtl_sta_info *sta_entry; |
885 | ||
886 | if (sta) { | |
f7953b2a | 887 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
26634c4b LF |
888 | spin_lock_bh(&rtlpriv->locks.entry_list_lock); |
889 | list_add_tail(&sta_entry->list, &rtlpriv->entry_list); | |
890 | spin_unlock_bh(&rtlpriv->locks.entry_list_lock); | |
0baa0fd7 C |
891 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
892 | sta_entry->wireless_mode = WIRELESS_MODE_G; | |
893 | if (sta->supp_rates[0] <= 0xf) | |
894 | sta_entry->wireless_mode = WIRELESS_MODE_B; | |
f7953b2a | 895 | if (sta->ht_cap.ht_supported) |
0baa0fd7 | 896 | sta_entry->wireless_mode = WIRELESS_MODE_N_24G; |
26634c4b LF |
897 | |
898 | if (vif->type == NL80211_IFTYPE_ADHOC) | |
899 | sta_entry->wireless_mode = WIRELESS_MODE_G; | |
0baa0fd7 C |
900 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
901 | sta_entry->wireless_mode = WIRELESS_MODE_A; | |
f7953b2a LF |
902 | if (sta->ht_cap.ht_supported) |
903 | sta_entry->wireless_mode = WIRELESS_MODE_N_5G; | |
904 | if (sta->vht_cap.vht_supported) | |
905 | sta_entry->wireless_mode = WIRELESS_MODE_AC_5G; | |
0baa0fd7 | 906 | |
26634c4b LF |
907 | if (vif->type == NL80211_IFTYPE_ADHOC) |
908 | sta_entry->wireless_mode = WIRELESS_MODE_A; | |
909 | } | |
910 | /*disable cck rate for p2p*/ | |
911 | if (mac->p2p) | |
912 | sta->supp_rates[0] &= 0xfffffff0; | |
0c817338 | 913 | |
26634c4b | 914 | memcpy(sta_entry->mac_addr, sta->addr, ETH_ALEN); |
0baa0fd7 | 915 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
f7953b2a | 916 | "Add sta addr is %pM\n", sta->addr); |
0baa0fd7 C |
917 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); |
918 | } | |
f7953b2a | 919 | |
0baa0fd7 C |
920 | return 0; |
921 | } | |
26634c4b | 922 | |
0baa0fd7 C |
923 | static int rtl_op_sta_remove(struct ieee80211_hw *hw, |
924 | struct ieee80211_vif *vif, | |
925 | struct ieee80211_sta *sta) | |
926 | { | |
927 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
928 | struct rtl_sta_info *sta_entry; | |
929 | if (sta) { | |
930 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, | |
f30d7507 | 931 | "Remove sta addr is %pM\n", sta->addr); |
f7953b2a | 932 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
0baa0fd7 C |
933 | sta_entry->wireless_mode = 0; |
934 | sta_entry->ratr_index = 0; | |
26634c4b LF |
935 | spin_lock_bh(&rtlpriv->locks.entry_list_lock); |
936 | list_del(&sta_entry->list); | |
937 | spin_unlock_bh(&rtlpriv->locks.entry_list_lock); | |
0baa0fd7 C |
938 | } |
939 | return 0; | |
940 | } | |
0c817338 LF |
941 | static int _rtl_get_hal_qnum(u16 queue) |
942 | { | |
943 | int qnum; | |
944 | ||
945 | switch (queue) { | |
946 | case 0: | |
947 | qnum = AC3_VO; | |
948 | break; | |
949 | case 1: | |
950 | qnum = AC2_VI; | |
951 | break; | |
952 | case 2: | |
953 | qnum = AC0_BE; | |
954 | break; | |
955 | case 3: | |
956 | qnum = AC1_BK; | |
957 | break; | |
958 | default: | |
959 | qnum = AC0_BE; | |
960 | break; | |
961 | } | |
962 | return qnum; | |
963 | } | |
964 | ||
965 | /* | |
26634c4b LF |
966 | *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3 |
967 | *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3 | |
0c817338 | 968 | */ |
8a3a3c85 | 969 | static int rtl_op_conf_tx(struct ieee80211_hw *hw, |
f7953b2a LF |
970 | struct ieee80211_vif *vif, u16 queue, |
971 | const struct ieee80211_tx_queue_params *param) | |
0c817338 LF |
972 | { |
973 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
974 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
975 | int aci; | |
976 | ||
977 | if (queue >= AC_MAX) { | |
978 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, | |
f30d7507 | 979 | "queue number %d is incorrect!\n", queue); |
0c817338 LF |
980 | return -EINVAL; |
981 | } | |
982 | ||
983 | aci = _rtl_get_hal_qnum(queue); | |
984 | mac->ac[aci].aifs = param->aifs; | |
17c9ac62 LF |
985 | mac->ac[aci].cw_min = cpu_to_le16(param->cw_min); |
986 | mac->ac[aci].cw_max = cpu_to_le16(param->cw_max); | |
987 | mac->ac[aci].tx_op = cpu_to_le16(param->txop); | |
0c817338 LF |
988 | memcpy(&mac->edca_param[aci], param, sizeof(*param)); |
989 | rtlpriv->cfg->ops->set_qos(hw, aci); | |
990 | return 0; | |
991 | } | |
992 | ||
993 | static void rtl_op_bss_info_changed(struct ieee80211_hw *hw, | |
f7953b2a LF |
994 | struct ieee80211_vif *vif, |
995 | struct ieee80211_bss_conf *bss_conf, | |
996 | u32 changed) | |
0c817338 LF |
997 | { |
998 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
0baa0fd7 | 999 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
0c817338 LF |
1000 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
1001 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | |
1002 | ||
8a09d6d8 | 1003 | mutex_lock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
1004 | if ((vif->type == NL80211_IFTYPE_ADHOC) || |
1005 | (vif->type == NL80211_IFTYPE_AP) || | |
1006 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { | |
0c817338 LF |
1007 | if ((changed & BSS_CHANGED_BEACON) || |
1008 | (changed & BSS_CHANGED_BEACON_ENABLED && | |
1009 | bss_conf->enable_beacon)) { | |
0c817338 LF |
1010 | if (mac->beacon_enabled == 0) { |
1011 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, | |
f30d7507 | 1012 | "BSS_CHANGED_BEACON_ENABLED\n"); |
0c817338 LF |
1013 | |
1014 | /*start hw beacon interrupt. */ | |
1015 | /*rtlpriv->cfg->ops->set_bcn_reg(hw); */ | |
1016 | mac->beacon_enabled = 1; | |
1017 | rtlpriv->cfg->ops->update_interrupt_mask(hw, | |
1018 | rtlpriv->cfg->maps | |
f7953b2a | 1019 | [RTL_IBSS_INT_MASKS], 0); |
0baa0fd7 C |
1020 | |
1021 | if (rtlpriv->cfg->ops->linked_set_reg) | |
1022 | rtlpriv->cfg->ops->linked_set_reg(hw); | |
0c817338 | 1023 | } |
0baa0fd7 C |
1024 | } |
1025 | if ((changed & BSS_CHANGED_BEACON_ENABLED && | |
f7953b2a | 1026 | !bss_conf->enable_beacon)) { |
0c817338 LF |
1027 | if (mac->beacon_enabled == 1) { |
1028 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, | |
f30d7507 | 1029 | "ADHOC DISABLE BEACON\n"); |
0c817338 LF |
1030 | |
1031 | mac->beacon_enabled = 0; | |
1032 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, | |
1033 | rtlpriv->cfg->maps | |
1034 | [RTL_IBSS_INT_MASKS]); | |
1035 | } | |
1036 | } | |
0c817338 LF |
1037 | if (changed & BSS_CHANGED_BEACON_INT) { |
1038 | RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE, | |
f30d7507 | 1039 | "BSS_CHANGED_BEACON_INT\n"); |
0c817338 LF |
1040 | mac->beacon_interval = bss_conf->beacon_int; |
1041 | rtlpriv->cfg->ops->set_bcn_intv(hw); | |
1042 | } | |
1043 | } | |
1044 | ||
1045 | /*TODO: reference to enum ieee80211_bss_change */ | |
1046 | if (changed & BSS_CHANGED_ASSOC) { | |
f7953b2a | 1047 | u8 mstatus; |
0c817338 | 1048 | if (bss_conf->assoc) { |
26634c4b | 1049 | struct ieee80211_sta *sta = NULL; |
f7953b2a LF |
1050 | u8 keep_alive = 10; |
1051 | ||
1052 | mstatus = RT_MEDIA_CONNECT; | |
0baa0fd7 C |
1053 | /* we should reset all sec info & cam |
1054 | * before set cam after linked, we should not | |
1055 | * reset in disassoc, that will cause tkip->wep | |
1056 | * fail because some flag will be wrong */ | |
1057 | /* reset sec info */ | |
1058 | rtl_cam_reset_sec_info(hw); | |
1059 | /* reset cam to fix wep fail issue | |
1060 | * when change from wpa to wep */ | |
1061 | rtl_cam_reset_all_entry(hw); | |
1062 | ||
0c817338 LF |
1063 | mac->link_state = MAC80211_LINKED; |
1064 | mac->cnt_after_linked = 0; | |
1065 | mac->assoc_id = bss_conf->aid; | |
d458cdf7 | 1066 | memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN); |
0c817338 | 1067 | |
0baa0fd7 C |
1068 | if (rtlpriv->cfg->ops->linked_set_reg) |
1069 | rtlpriv->cfg->ops->linked_set_reg(hw); | |
f7953b2a | 1070 | |
26634c4b LF |
1071 | rcu_read_lock(); |
1072 | sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid); | |
2cddad3c | 1073 | if (!sta) { |
2cddad3c LF |
1074 | rcu_read_unlock(); |
1075 | goto out; | |
1076 | } | |
26634c4b LF |
1077 | RT_TRACE(rtlpriv, COMP_EASY_CONCURRENT, DBG_LOUD, |
1078 | "send PS STATIC frame\n"); | |
1079 | if (rtlpriv->dm.supp_phymode_switch) { | |
1080 | if (sta->ht_cap.ht_supported) | |
1081 | rtl_send_smps_action(hw, sta, | |
f7953b2a | 1082 | IEEE80211_SMPS_STATIC); |
26634c4b | 1083 | } |
f7953b2a LF |
1084 | |
1085 | if (rtlhal->current_bandtype == BAND_ON_5G) { | |
1086 | mac->mode = WIRELESS_MODE_A; | |
1087 | } else { | |
1088 | if (sta->supp_rates[0] <= 0xf) | |
1089 | mac->mode = WIRELESS_MODE_B; | |
1090 | else | |
1091 | mac->mode = WIRELESS_MODE_G; | |
1092 | } | |
1093 | ||
1094 | if (sta->ht_cap.ht_supported) { | |
1095 | if (rtlhal->current_bandtype == BAND_ON_2_4G) | |
1096 | mac->mode = WIRELESS_MODE_N_24G; | |
1097 | else | |
1098 | mac->mode = WIRELESS_MODE_N_5G; | |
1099 | } | |
1100 | ||
1101 | if (sta->vht_cap.vht_supported) { | |
1102 | if (rtlhal->current_bandtype == BAND_ON_5G) | |
1103 | mac->mode = WIRELESS_MODE_AC_5G; | |
1104 | else | |
1105 | mac->mode = WIRELESS_MODE_AC_24G; | |
1106 | } | |
1107 | ||
1108 | if (vif->type == NL80211_IFTYPE_STATION && sta) | |
1109 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); | |
26634c4b LF |
1110 | rcu_read_unlock(); |
1111 | ||
f7953b2a LF |
1112 | /* to avoid AP Disassociation caused by inactivity */ |
1113 | rtlpriv->cfg->ops->set_hw_reg(hw, | |
1114 | HW_VAR_KEEP_ALIVE, | |
1115 | (u8 *)(&keep_alive)); | |
1116 | ||
0c817338 | 1117 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
f30d7507 | 1118 | "BSS_CHANGED_ASSOC\n"); |
0c817338 | 1119 | } else { |
f7953b2a LF |
1120 | mstatus = RT_MEDIA_DISCONNECT; |
1121 | ||
a269913c LF |
1122 | if (mac->link_state == MAC80211_LINKED) { |
1123 | rtlpriv->enter_ps = false; | |
1124 | schedule_work(&rtlpriv->works.lps_change_work); | |
1125 | } | |
26634c4b LF |
1126 | if (ppsc->p2p_ps_info.p2p_ps_mode > P2P_PS_NONE) |
1127 | rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE); | |
0c817338 | 1128 | mac->link_state = MAC80211_NOLINK; |
d458cdf7 | 1129 | memset(mac->bssid, 0, ETH_ALEN); |
0baa0fd7 | 1130 | mac->vendor = PEER_UNKNOWN; |
f7953b2a | 1131 | mac->mode = 0; |
0c817338 | 1132 | |
26634c4b LF |
1133 | if (rtlpriv->dm.supp_phymode_switch) { |
1134 | if (rtlpriv->cfg->ops->chk_switch_dmdp) | |
1135 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); | |
1136 | } | |
0c817338 | 1137 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
f30d7507 | 1138 | "BSS_CHANGED_UN_ASSOC\n"); |
0c817338 | 1139 | } |
f7953b2a LF |
1140 | rtlpriv->cfg->ops->set_network_type(hw, vif->type); |
1141 | /* For FW LPS: | |
1142 | * To tell firmware we have connected or disconnected | |
1143 | */ | |
1144 | rtlpriv->cfg->ops->set_hw_reg(hw, | |
1145 | HW_VAR_H2C_FW_JOINBSSRPT, | |
1146 | (u8 *)(&mstatus)); | |
1147 | ppsc->report_linked = (mstatus == RT_MEDIA_CONNECT) ? | |
1148 | true : false; | |
1149 | ||
1150 | if (rtlpriv->cfg->ops->get_btc_status()) | |
1151 | rtlpriv->btcoexist.btc_ops->btc_mediastatus_notify( | |
1152 | rtlpriv, mstatus); | |
0c817338 LF |
1153 | } |
1154 | ||
1155 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | |
1156 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, | |
f30d7507 | 1157 | "BSS_CHANGED_ERP_CTS_PROT\n"); |
0c817338 LF |
1158 | mac->use_cts_protect = bss_conf->use_cts_prot; |
1159 | } | |
1160 | ||
1161 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
1162 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, | |
f30d7507 | 1163 | "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n", |
f7953b2a | 1164 | bss_conf->use_short_preamble); |
0c817338 LF |
1165 | |
1166 | mac->short_preamble = bss_conf->use_short_preamble; | |
1167 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE, | |
f7953b2a | 1168 | (u8 *)(&mac->short_preamble)); |
0c817338 LF |
1169 | } |
1170 | ||
1171 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
1172 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, | |
f30d7507 | 1173 | "BSS_CHANGED_ERP_SLOT\n"); |
0c817338 LF |
1174 | |
1175 | if (bss_conf->use_short_slot) | |
1176 | mac->slot_time = RTL_SLOT_TIME_9; | |
1177 | else | |
1178 | mac->slot_time = RTL_SLOT_TIME_20; | |
1179 | ||
1180 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, | |
f7953b2a | 1181 | (u8 *)(&mac->slot_time)); |
0c817338 LF |
1182 | } |
1183 | ||
1184 | if (changed & BSS_CHANGED_HT) { | |
f7953b2a LF |
1185 | struct ieee80211_sta *sta = NULL; |
1186 | ||
1187 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, | |
1188 | "BSS_CHANGED_HT\n"); | |
1189 | ||
701c2be0 | 1190 | rcu_read_lock(); |
f7953b2a | 1191 | sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid); |
0c817338 LF |
1192 | if (sta) { |
1193 | if (sta->ht_cap.ampdu_density > | |
1194 | mac->current_ampdu_density) | |
1195 | mac->current_ampdu_density = | |
1196 | sta->ht_cap.ampdu_density; | |
1197 | if (sta->ht_cap.ampdu_factor < | |
1198 | mac->current_ampdu_factor) | |
1199 | mac->current_ampdu_factor = | |
1200 | sta->ht_cap.ampdu_factor; | |
1201 | } | |
701c2be0 | 1202 | rcu_read_unlock(); |
0c817338 LF |
1203 | |
1204 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY, | |
f7953b2a | 1205 | (u8 *)(&mac->max_mss_density)); |
0c817338 LF |
1206 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR, |
1207 | &mac->current_ampdu_factor); | |
1208 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE, | |
1209 | &mac->current_ampdu_density); | |
1210 | } | |
1211 | ||
1212 | if (changed & BSS_CHANGED_BSSID) { | |
0c817338 | 1213 | u32 basic_rates; |
f7953b2a | 1214 | struct ieee80211_sta *sta = NULL; |
0c817338 LF |
1215 | |
1216 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID, | |
f7953b2a | 1217 | (u8 *)bss_conf->bssid); |
0c817338 | 1218 | |
f7953b2a LF |
1219 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
1220 | "bssid: %pM\n", bss_conf->bssid); | |
0c817338 | 1221 | |
0baa0fd7 | 1222 | mac->vendor = PEER_UNKNOWN; |
d458cdf7 | 1223 | memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN); |
0c817338 | 1224 | |
701c2be0 | 1225 | rcu_read_lock(); |
f7953b2a | 1226 | sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid); |
0baa0fd7 C |
1227 | if (!sta) { |
1228 | rcu_read_unlock(); | |
1229 | goto out; | |
1230 | } | |
0c817338 | 1231 | |
0baa0fd7 C |
1232 | if (rtlhal->current_bandtype == BAND_ON_5G) { |
1233 | mac->mode = WIRELESS_MODE_A; | |
1234 | } else { | |
1235 | if (sta->supp_rates[0] <= 0xf) | |
1236 | mac->mode = WIRELESS_MODE_B; | |
1237 | else | |
1238 | mac->mode = WIRELESS_MODE_G; | |
1239 | } | |
1240 | ||
1241 | if (sta->ht_cap.ht_supported) { | |
1242 | if (rtlhal->current_bandtype == BAND_ON_2_4G) | |
0c817338 | 1243 | mac->mode = WIRELESS_MODE_N_24G; |
0baa0fd7 C |
1244 | else |
1245 | mac->mode = WIRELESS_MODE_N_5G; | |
1246 | } | |
0c817338 | 1247 | |
f7953b2a LF |
1248 | if (sta->vht_cap.vht_supported) { |
1249 | if (rtlhal->current_bandtype == BAND_ON_5G) | |
1250 | mac->mode = WIRELESS_MODE_AC_5G; | |
1251 | else | |
1252 | mac->mode = WIRELESS_MODE_AC_24G; | |
1253 | } | |
1254 | ||
0baa0fd7 C |
1255 | /* just station need it, because ibss & ap mode will |
1256 | * set in sta_add, and will be NULL here */ | |
f7953b2a | 1257 | if (vif->type == NL80211_IFTYPE_STATION) { |
0baa0fd7 | 1258 | struct rtl_sta_info *sta_entry; |
f7953b2a | 1259 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
0baa0fd7 C |
1260 | sta_entry->wireless_mode = mac->mode; |
1261 | } | |
1262 | ||
1263 | if (sta->ht_cap.ht_supported) { | |
1264 | mac->ht_enable = true; | |
1265 | ||
1266 | /* | |
1267 | * for cisco 1252 bw20 it's wrong | |
1268 | * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { | |
1269 | * mac->bw_40 = true; | |
1270 | * } | |
1271 | * */ | |
0c817338 LF |
1272 | } |
1273 | ||
f7953b2a LF |
1274 | if (sta->vht_cap.vht_supported) |
1275 | mac->vht_enable = true; | |
1276 | ||
0c817338 | 1277 | if (changed & BSS_CHANGED_BASIC_RATES) { |
26634c4b | 1278 | /* for 5G must << RATE_6M_INDEX = 4, |
0baa0fd7 C |
1279 | * because 5G have no cck rate*/ |
1280 | if (rtlhal->current_bandtype == BAND_ON_5G) | |
1281 | basic_rates = sta->supp_rates[1] << 4; | |
0c817338 | 1282 | else |
0baa0fd7 | 1283 | basic_rates = sta->supp_rates[0]; |
0c817338 LF |
1284 | |
1285 | mac->basic_rates = basic_rates; | |
1286 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, | |
2cddad3c | 1287 | (u8 *)(&basic_rates)); |
0c817338 | 1288 | } |
0baa0fd7 | 1289 | rcu_read_unlock(); |
0c817338 | 1290 | } |
0c817338 | 1291 | out: |
8a09d6d8 | 1292 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
1293 | } |
1294 | ||
37a41b4a | 1295 | static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
0c817338 LF |
1296 | { |
1297 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1298 | u64 tsf; | |
1299 | ||
f7953b2a | 1300 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&tsf)); |
0c817338 LF |
1301 | return tsf; |
1302 | } | |
1303 | ||
f7953b2a LF |
1304 | static void rtl_op_set_tsf(struct ieee80211_hw *hw, |
1305 | struct ieee80211_vif *vif, u64 tsf) | |
0c817338 LF |
1306 | { |
1307 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1308 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
6eab04a8 | 1309 | u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0; |
0c817338 LF |
1310 | |
1311 | mac->tsf = tsf; | |
f7953b2a | 1312 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&bibss)); |
0c817338 LF |
1313 | } |
1314 | ||
f7953b2a | 1315 | static void rtl_op_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
0c817338 LF |
1316 | { |
1317 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1318 | u8 tmp = 0; | |
1319 | ||
f7953b2a | 1320 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *)(&tmp)); |
0c817338 LF |
1321 | } |
1322 | ||
1323 | static void rtl_op_sta_notify(struct ieee80211_hw *hw, | |
1324 | struct ieee80211_vif *vif, | |
1325 | enum sta_notify_cmd cmd, | |
1326 | struct ieee80211_sta *sta) | |
1327 | { | |
1328 | switch (cmd) { | |
1329 | case STA_NOTIFY_SLEEP: | |
1330 | break; | |
1331 | case STA_NOTIFY_AWAKE: | |
1332 | break; | |
1333 | default: | |
1334 | break; | |
1335 | } | |
1336 | } | |
1337 | ||
1338 | static int rtl_op_ampdu_action(struct ieee80211_hw *hw, | |
1339 | struct ieee80211_vif *vif, | |
1340 | enum ieee80211_ampdu_mlme_action action, | |
0b01f030 JB |
1341 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
1342 | u8 buf_size) | |
0c817338 LF |
1343 | { |
1344 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1345 | ||
1346 | switch (action) { | |
1347 | case IEEE80211_AMPDU_TX_START: | |
1348 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, | |
f30d7507 | 1349 | "IEEE80211_AMPDU_TX_START: TID:%d\n", tid); |
f7953b2a | 1350 | return rtl_tx_agg_start(hw, vif, sta, tid, ssn); |
18b559d5 JB |
1351 | case IEEE80211_AMPDU_TX_STOP_CONT: |
1352 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
1353 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
0c817338 | 1354 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
f30d7507 | 1355 | "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid); |
f7953b2a | 1356 | return rtl_tx_agg_stop(hw, vif, sta, tid); |
0c817338 LF |
1357 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
1358 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, | |
f30d7507 | 1359 | "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid); |
0baa0fd7 | 1360 | rtl_tx_agg_oper(hw, sta, tid); |
0c817338 LF |
1361 | break; |
1362 | case IEEE80211_AMPDU_RX_START: | |
1363 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, | |
f30d7507 | 1364 | "IEEE80211_AMPDU_RX_START:TID:%d\n", tid); |
26634c4b | 1365 | return rtl_rx_agg_start(hw, sta, tid); |
0c817338 LF |
1366 | case IEEE80211_AMPDU_RX_STOP: |
1367 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, | |
f30d7507 | 1368 | "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid); |
26634c4b | 1369 | return rtl_rx_agg_stop(hw, sta, tid); |
0c817338 LF |
1370 | default: |
1371 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | |
f30d7507 | 1372 | "IEEE80211_AMPDU_ERR!!!!:\n"); |
0c817338 LF |
1373 | return -EOPNOTSUPP; |
1374 | } | |
1375 | return 0; | |
1376 | } | |
1377 | ||
a344d677 JB |
1378 | static void rtl_op_sw_scan_start(struct ieee80211_hw *hw, |
1379 | struct ieee80211_vif *vif, | |
1380 | const u8 *mac_addr) | |
0c817338 LF |
1381 | { |
1382 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1383 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
1384 | ||
f30d7507 | 1385 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n"); |
26634c4b LF |
1386 | mac->act_scanning = true; |
1387 | if (rtlpriv->link_info.higher_busytraffic) { | |
1388 | mac->skip_scan = true; | |
1389 | return; | |
1390 | } | |
0c817338 | 1391 | |
f7953b2a LF |
1392 | if (rtlpriv->cfg->ops->get_btc_status()) |
1393 | rtlpriv->btcoexist.btc_ops->btc_scan_notify(rtlpriv, 1); | |
1394 | ||
26634c4b LF |
1395 | if (rtlpriv->dm.supp_phymode_switch) { |
1396 | if (rtlpriv->cfg->ops->chk_switch_dmdp) | |
1397 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); | |
1398 | } | |
f7953b2a | 1399 | |
0c817338 | 1400 | if (mac->link_state == MAC80211_LINKED) { |
a269913c LF |
1401 | rtlpriv->enter_ps = false; |
1402 | schedule_work(&rtlpriv->works.lps_change_work); | |
0c817338 | 1403 | mac->link_state = MAC80211_LINKED_SCANNING; |
0baa0fd7 | 1404 | } else { |
0c817338 | 1405 | rtl_ips_nic_on(hw); |
0baa0fd7 C |
1406 | } |
1407 | ||
f7953b2a | 1408 | /* Dul mac */ |
0baa0fd7 | 1409 | rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false; |
0c817338 LF |
1410 | |
1411 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY); | |
f7953b2a | 1412 | rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP_BAND0); |
0c817338 LF |
1413 | } |
1414 | ||
a344d677 JB |
1415 | static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw, |
1416 | struct ieee80211_vif *vif) | |
0c817338 LF |
1417 | { |
1418 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1419 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
1420 | ||
f30d7507 | 1421 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n"); |
0c817338 | 1422 | mac->act_scanning = false; |
26634c4b LF |
1423 | mac->skip_scan = false; |
1424 | if (rtlpriv->link_info.higher_busytraffic) | |
1425 | return; | |
1426 | ||
f7953b2a | 1427 | /* p2p will use 1/6/11 to scan */ |
26634c4b LF |
1428 | if (mac->n_channels == 3) |
1429 | mac->p2p_in_use = true; | |
1430 | else | |
1431 | mac->p2p_in_use = false; | |
1432 | mac->n_channels = 0; | |
f7953b2a | 1433 | /* Dul mac */ |
0baa0fd7 C |
1434 | rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false; |
1435 | ||
0c817338 LF |
1436 | if (mac->link_state == MAC80211_LINKED_SCANNING) { |
1437 | mac->link_state = MAC80211_LINKED; | |
0baa0fd7 C |
1438 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
1439 | /* fix fwlps issue */ | |
1440 | rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); | |
1441 | } | |
0c817338 LF |
1442 | } |
1443 | ||
0baa0fd7 | 1444 | rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE); |
f7953b2a LF |
1445 | if (rtlpriv->cfg->ops->get_btc_status()) |
1446 | rtlpriv->btcoexist.btc_ops->btc_scan_notify(rtlpriv, 0); | |
0c817338 LF |
1447 | } |
1448 | ||
1449 | static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | |
1450 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, | |
1451 | struct ieee80211_key_conf *key) | |
1452 | { | |
1453 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
0c817338 LF |
1454 | u8 key_type = NO_ENCRYPTION; |
1455 | u8 key_idx; | |
1456 | bool group_key = false; | |
1457 | bool wep_only = false; | |
1458 | int err = 0; | |
1459 | u8 mac_addr[ETH_ALEN]; | |
1460 | u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
0c817338 LF |
1461 | |
1462 | if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) { | |
1463 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, | |
f30d7507 | 1464 | "not open hw encryption\n"); |
0c817338 LF |
1465 | return -ENOSPC; /*User disabled HW-crypto */ |
1466 | } | |
26634c4b LF |
1467 | /* To support IBSS, use sw-crypto for GTK */ |
1468 | if (((vif->type == NL80211_IFTYPE_ADHOC) || | |
f7953b2a LF |
1469 | (vif->type == NL80211_IFTYPE_MESH_POINT)) && |
1470 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) | |
26634c4b | 1471 | return -ENOSPC; |
0c817338 | 1472 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
f30d7507 | 1473 | "%s hardware based encryption for keyidx: %d, mac: %pM\n", |
f7953b2a LF |
1474 | cmd == SET_KEY ? "Using" : "Disabling", key->keyidx, |
1475 | sta ? sta->addr : bcast_addr); | |
0c817338 LF |
1476 | rtlpriv->sec.being_setkey = true; |
1477 | rtl_ips_nic_on(hw); | |
8a09d6d8 | 1478 | mutex_lock(&rtlpriv->locks.conf_mutex); |
0c817338 | 1479 | /* <1> get encryption alg */ |
0baa0fd7 | 1480 | |
0c817338 LF |
1481 | switch (key->cipher) { |
1482 | case WLAN_CIPHER_SUITE_WEP40: | |
1483 | key_type = WEP40_ENCRYPTION; | |
f30d7507 | 1484 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n"); |
0c817338 LF |
1485 | break; |
1486 | case WLAN_CIPHER_SUITE_WEP104: | |
f30d7507 | 1487 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n"); |
0c817338 | 1488 | key_type = WEP104_ENCRYPTION; |
0c817338 LF |
1489 | break; |
1490 | case WLAN_CIPHER_SUITE_TKIP: | |
1491 | key_type = TKIP_ENCRYPTION; | |
f30d7507 | 1492 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n"); |
0c817338 LF |
1493 | break; |
1494 | case WLAN_CIPHER_SUITE_CCMP: | |
1495 | key_type = AESCCMP_ENCRYPTION; | |
f30d7507 | 1496 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n"); |
0c817338 | 1497 | break; |
26634c4b | 1498 | case WLAN_CIPHER_SUITE_AES_CMAC: |
f7953b2a LF |
1499 | /* HW don't support CMAC encryption, |
1500 | * use software CMAC encryption | |
1501 | */ | |
26634c4b LF |
1502 | key_type = AESCMAC_ENCRYPTION; |
1503 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CMAC\n"); | |
1504 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, | |
f7953b2a | 1505 | "HW don't support CMAC encrypiton, use software CMAC encrypiton\n"); |
26634c4b LF |
1506 | err = -EOPNOTSUPP; |
1507 | goto out_unlock; | |
0c817338 | 1508 | default: |
f7953b2a LF |
1509 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
1510 | "alg_err:%x!!!!:\n", key->cipher); | |
0c817338 LF |
1511 | goto out_unlock; |
1512 | } | |
0baa0fd7 | 1513 | if (key_type == WEP40_ENCRYPTION || |
f7953b2a LF |
1514 | key_type == WEP104_ENCRYPTION || |
1515 | vif->type == NL80211_IFTYPE_ADHOC) | |
0baa0fd7 C |
1516 | rtlpriv->sec.use_defaultkey = true; |
1517 | ||
0c817338 LF |
1518 | /* <2> get key_idx */ |
1519 | key_idx = (u8) (key->keyidx); | |
1520 | if (key_idx > 3) | |
1521 | goto out_unlock; | |
1522 | /* <3> if pairwise key enable_hw_sec */ | |
1523 | group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE); | |
0baa0fd7 C |
1524 | |
1525 | /* wep always be group key, but there are two conditions: | |
1526 | * 1) wep only: is just for wep enc, in this condition | |
1527 | * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION | |
1528 | * will be true & enable_hw_sec will be set when wep | |
f7953b2a | 1529 | * ke setting. |
0baa0fd7 C |
1530 | * 2) wep(group) + AES(pairwise): some AP like cisco |
1531 | * may use it, in this condition enable_hw_sec will not | |
1532 | * be set when wep key setting */ | |
1533 | /* we must reset sec_info after lingked before set key, | |
1534 | * or some flag will be wrong*/ | |
26634c4b | 1535 | if (vif->type == NL80211_IFTYPE_AP || |
f7953b2a | 1536 | vif->type == NL80211_IFTYPE_MESH_POINT) { |
0baa0fd7 C |
1537 | if (!group_key || key_type == WEP40_ENCRYPTION || |
1538 | key_type == WEP104_ENCRYPTION) { | |
1539 | if (group_key) | |
1540 | wep_only = true; | |
1541 | rtlpriv->cfg->ops->enable_hw_sec(hw); | |
1542 | } | |
1543 | } else { | |
f7953b2a LF |
1544 | if ((!group_key) || (vif->type == NL80211_IFTYPE_ADHOC) || |
1545 | rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) { | |
0baa0fd7 C |
1546 | if (rtlpriv->sec.pairwise_enc_algorithm == |
1547 | NO_ENCRYPTION && | |
f7953b2a | 1548 | (key_type == WEP40_ENCRYPTION || |
0baa0fd7 C |
1549 | key_type == WEP104_ENCRYPTION)) |
1550 | wep_only = true; | |
1551 | rtlpriv->sec.pairwise_enc_algorithm = key_type; | |
1552 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, | |
f30d7507 JP |
1553 | "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n", |
1554 | key_type); | |
0baa0fd7 C |
1555 | rtlpriv->cfg->ops->enable_hw_sec(hw); |
1556 | } | |
0c817338 LF |
1557 | } |
1558 | /* <4> set key based on cmd */ | |
1559 | switch (cmd) { | |
1560 | case SET_KEY: | |
1561 | if (wep_only) { | |
1562 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, | |
f30d7507 | 1563 | "set WEP(group/pairwise) key\n"); |
0c817338 LF |
1564 | /* Pairwise key with an assigned MAC address. */ |
1565 | rtlpriv->sec.pairwise_enc_algorithm = key_type; | |
1566 | rtlpriv->sec.group_enc_algorithm = key_type; | |
1567 | /*set local buf about wep key. */ | |
1568 | memcpy(rtlpriv->sec.key_buf[key_idx], | |
1569 | key->key, key->keylen); | |
1570 | rtlpriv->sec.key_len[key_idx] = key->keylen; | |
ccd95369 | 1571 | eth_zero_addr(mac_addr); |
0c817338 LF |
1572 | } else if (group_key) { /* group key */ |
1573 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, | |
f30d7507 | 1574 | "set group key\n"); |
0c817338 LF |
1575 | /* group key */ |
1576 | rtlpriv->sec.group_enc_algorithm = key_type; | |
1577 | /*set local buf about group key. */ | |
1578 | memcpy(rtlpriv->sec.key_buf[key_idx], | |
1579 | key->key, key->keylen); | |
1580 | rtlpriv->sec.key_len[key_idx] = key->keylen; | |
1581 | memcpy(mac_addr, bcast_addr, ETH_ALEN); | |
1582 | } else { /* pairwise key */ | |
1583 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, | |
f30d7507 | 1584 | "set pairwise key\n"); |
0c817338 | 1585 | if (!sta) { |
9d833ed7 JP |
1586 | RT_ASSERT(false, |
1587 | "pairwise key without mac_addr\n"); | |
0baa0fd7 | 1588 | |
0c817338 LF |
1589 | err = -EOPNOTSUPP; |
1590 | goto out_unlock; | |
1591 | } | |
1592 | /* Pairwise key with an assigned MAC address. */ | |
1593 | rtlpriv->sec.pairwise_enc_algorithm = key_type; | |
1594 | /*set local buf about pairwise key. */ | |
1595 | memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX], | |
1596 | key->key, key->keylen); | |
1597 | rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen; | |
1598 | rtlpriv->sec.pairwise_key = | |
1599 | rtlpriv->sec.key_buf[PAIRWISE_KEYIDX]; | |
1600 | memcpy(mac_addr, sta->addr, ETH_ALEN); | |
1601 | } | |
1602 | rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr, | |
1603 | group_key, key_type, wep_only, | |
1604 | false); | |
1605 | /* <5> tell mac80211 do something: */ | |
1606 | /*must use sw generate IV, or can not work !!!!. */ | |
1607 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
1608 | key->hw_key_idx = key_idx; | |
1609 | if (key_type == TKIP_ENCRYPTION) | |
1610 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; | |
26634c4b LF |
1611 | /*use software CCMP encryption for management frames (MFP) */ |
1612 | if (key_type == AESCCMP_ENCRYPTION) | |
1613 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; | |
0c817338 LF |
1614 | break; |
1615 | case DISABLE_KEY: | |
1616 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, | |
f30d7507 | 1617 | "disable key delete one entry\n"); |
0c817338 | 1618 | /*set local buf about wep key. */ |
26634c4b | 1619 | if (vif->type == NL80211_IFTYPE_AP || |
f7953b2a | 1620 | vif->type == NL80211_IFTYPE_MESH_POINT) { |
0baa0fd7 C |
1621 | if (sta) |
1622 | rtl_cam_del_entry(hw, sta->addr); | |
1623 | } | |
0c817338 LF |
1624 | memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen); |
1625 | rtlpriv->sec.key_len[key_idx] = 0; | |
ccd95369 | 1626 | eth_zero_addr(mac_addr); |
0c817338 LF |
1627 | /* |
1628 | *mac80211 will delete entrys one by one, | |
1629 | *so don't use rtl_cam_reset_all_entry | |
1630 | *or clear all entry here. | |
1631 | */ | |
1632 | rtl_cam_delete_one_entry(hw, mac_addr, key_idx); | |
1633 | break; | |
1634 | default: | |
1635 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | |
f7953b2a | 1636 | "cmd_err:%x!!!!:\n", cmd); |
0c817338 LF |
1637 | } |
1638 | out_unlock: | |
8a09d6d8 | 1639 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
1640 | rtlpriv->sec.being_setkey = false; |
1641 | return err; | |
1642 | } | |
1643 | ||
1644 | static void rtl_op_rfkill_poll(struct ieee80211_hw *hw) | |
1645 | { | |
1646 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1647 | ||
1648 | bool radio_state; | |
1649 | bool blocked; | |
1650 | u8 valid = 0; | |
1651 | ||
1652 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) | |
1653 | return; | |
1654 | ||
8a09d6d8 | 1655 | mutex_lock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
1656 | |
1657 | /*if Radio On return true here */ | |
1658 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); | |
1659 | ||
1660 | if (valid) { | |
1661 | if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) { | |
1662 | rtlpriv->rfkill.rfkill_state = radio_state; | |
1663 | ||
1664 | RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, | |
f30d7507 | 1665 | "wireless radio switch turned %s\n", |
f7953b2a | 1666 | radio_state ? "on" : "off"); |
0c817338 LF |
1667 | |
1668 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; | |
1669 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); | |
1670 | } | |
1671 | } | |
1672 | ||
8a09d6d8 | 1673 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
0c817338 LF |
1674 | } |
1675 | ||
0baa0fd7 | 1676 | /* this function is called by mac80211 to flush tx buffer |
f7953b2a | 1677 | * before switch channle or power save, or tx buffer packet |
0baa0fd7 C |
1678 | * maybe send after offchannel or rf sleep, this may cause |
1679 | * dis-association by AP */ | |
f7953b2a LF |
1680 | static void rtl_op_flush(struct ieee80211_hw *hw, |
1681 | struct ieee80211_vif *vif, | |
1682 | u32 queues, | |
1683 | bool drop) | |
0baa0fd7 C |
1684 | { |
1685 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1686 | ||
1687 | if (rtlpriv->intf_ops->flush) | |
38506ece | 1688 | rtlpriv->intf_ops->flush(hw, queues, drop); |
0baa0fd7 C |
1689 | } |
1690 | ||
34ed780a LF |
1691 | /* Description: |
1692 | * This routine deals with the Power Configuration CMD | |
1693 | * parsing for RTL8723/RTL8188E Series IC. | |
1694 | * Assumption: | |
1695 | * We should follow specific format that was released from HW SD. | |
1696 | */ | |
1697 | bool rtl_hal_pwrseqcmdparsing(struct rtl_priv *rtlpriv, u8 cut_version, | |
1698 | u8 faversion, u8 interface_type, | |
1699 | struct wlan_pwr_cfg pwrcfgcmd[]) | |
1700 | { | |
1701 | struct wlan_pwr_cfg cfg_cmd = {0}; | |
1702 | bool polling_bit = false; | |
1703 | u32 ary_idx = 0; | |
1704 | u8 value = 0; | |
1705 | u32 offset = 0; | |
1706 | u32 polling_count = 0; | |
1707 | u32 max_polling_cnt = 5000; | |
1708 | ||
1709 | do { | |
1710 | cfg_cmd = pwrcfgcmd[ary_idx]; | |
1711 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, | |
1712 | "rtl_hal_pwrseqcmdparsing(): offset(%#x),cut_msk(%#x), famsk(%#x), interface_msk(%#x), base(%#x), cmd(%#x), msk(%#x), value(%#x)\n", | |
1713 | GET_PWR_CFG_OFFSET(cfg_cmd), | |
1714 | GET_PWR_CFG_CUT_MASK(cfg_cmd), | |
1715 | GET_PWR_CFG_FAB_MASK(cfg_cmd), | |
1716 | GET_PWR_CFG_INTF_MASK(cfg_cmd), | |
1717 | GET_PWR_CFG_BASE(cfg_cmd), GET_PWR_CFG_CMD(cfg_cmd), | |
1718 | GET_PWR_CFG_MASK(cfg_cmd), GET_PWR_CFG_VALUE(cfg_cmd)); | |
1719 | ||
1720 | if ((GET_PWR_CFG_FAB_MASK(cfg_cmd)&faversion) && | |
1721 | (GET_PWR_CFG_CUT_MASK(cfg_cmd)&cut_version) && | |
1722 | (GET_PWR_CFG_INTF_MASK(cfg_cmd)&interface_type)) { | |
1723 | switch (GET_PWR_CFG_CMD(cfg_cmd)) { | |
1724 | case PWR_CMD_READ: | |
1725 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, | |
1726 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n"); | |
1727 | break; | |
1728 | case PWR_CMD_WRITE: | |
1729 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, | |
1730 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_WRITE\n"); | |
1731 | offset = GET_PWR_CFG_OFFSET(cfg_cmd); | |
1732 | ||
1733 | /*Read the value from system register*/ | |
1734 | value = rtl_read_byte(rtlpriv, offset); | |
1735 | value &= (~(GET_PWR_CFG_MASK(cfg_cmd))); | |
1736 | value |= (GET_PWR_CFG_VALUE(cfg_cmd) & | |
1737 | GET_PWR_CFG_MASK(cfg_cmd)); | |
1738 | ||
1739 | /*Write the value back to sytem register*/ | |
1740 | rtl_write_byte(rtlpriv, offset, value); | |
1741 | break; | |
1742 | case PWR_CMD_POLLING: | |
1743 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, | |
1744 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_POLLING\n"); | |
1745 | polling_bit = false; | |
1746 | offset = GET_PWR_CFG_OFFSET(cfg_cmd); | |
1747 | ||
1748 | do { | |
1749 | value = rtl_read_byte(rtlpriv, offset); | |
1750 | ||
1751 | value &= GET_PWR_CFG_MASK(cfg_cmd); | |
1752 | if (value == | |
1753 | (GET_PWR_CFG_VALUE(cfg_cmd) & | |
1754 | GET_PWR_CFG_MASK(cfg_cmd))) | |
1755 | polling_bit = true; | |
1756 | else | |
1757 | udelay(10); | |
1758 | ||
1759 | if (polling_count++ > max_polling_cnt) | |
1760 | return false; | |
1761 | } while (!polling_bit); | |
1762 | break; | |
1763 | case PWR_CMD_DELAY: | |
1764 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, | |
1765 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_DELAY\n"); | |
1766 | if (GET_PWR_CFG_VALUE(cfg_cmd) == | |
1767 | PWRSEQ_DELAY_US) | |
1768 | udelay(GET_PWR_CFG_OFFSET(cfg_cmd)); | |
1769 | else | |
1770 | mdelay(GET_PWR_CFG_OFFSET(cfg_cmd)); | |
1771 | break; | |
1772 | case PWR_CMD_END: | |
1773 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, | |
1774 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_END\n"); | |
1775 | return true; | |
1776 | default: | |
1777 | RT_ASSERT(false, | |
1778 | "rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n"); | |
1779 | break; | |
1780 | } | |
1781 | } | |
1782 | ary_idx++; | |
1783 | } while (1); | |
1784 | ||
1785 | return true; | |
1786 | } | |
1787 | EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing); | |
557f9331 LF |
1788 | |
1789 | bool rtl_cmd_send_packet(struct ieee80211_hw *hw, struct sk_buff *skb) | |
1790 | { | |
1791 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1792 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); | |
1793 | struct rtl8192_tx_ring *ring; | |
1794 | struct rtl_tx_desc *pdesc; | |
1795 | unsigned long flags; | |
1796 | struct sk_buff *pskb = NULL; | |
1797 | ||
1798 | ring = &rtlpci->tx_ring[BEACON_QUEUE]; | |
1799 | ||
1800 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); | |
1801 | pskb = __skb_dequeue(&ring->queue); | |
1802 | if (pskb) | |
1803 | kfree_skb(pskb); | |
1804 | ||
1805 | /*this is wrong, fill_tx_cmddesc needs update*/ | |
1806 | pdesc = &ring->desc[0]; | |
1807 | ||
1808 | rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *)pdesc, 1, 1, skb); | |
1809 | ||
1810 | __skb_queue_tail(&ring->queue, skb); | |
1811 | ||
1812 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); | |
1813 | ||
1814 | rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE); | |
1815 | ||
1816 | return true; | |
1817 | } | |
1818 | EXPORT_SYMBOL(rtl_cmd_send_packet); | |
0c817338 LF |
1819 | const struct ieee80211_ops rtl_ops = { |
1820 | .start = rtl_op_start, | |
1821 | .stop = rtl_op_stop, | |
1822 | .tx = rtl_op_tx, | |
1823 | .add_interface = rtl_op_add_interface, | |
1824 | .remove_interface = rtl_op_remove_interface, | |
26634c4b | 1825 | .change_interface = rtl_op_change_interface, |
f7953b2a LF |
1826 | #ifdef CONFIG_PM |
1827 | .suspend = rtl_op_suspend, | |
1828 | .resume = rtl_op_resume, | |
1829 | #endif | |
0c817338 LF |
1830 | .config = rtl_op_config, |
1831 | .configure_filter = rtl_op_configure_filter, | |
1832 | .set_key = rtl_op_set_key, | |
1833 | .conf_tx = rtl_op_conf_tx, | |
1834 | .bss_info_changed = rtl_op_bss_info_changed, | |
1835 | .get_tsf = rtl_op_get_tsf, | |
1836 | .set_tsf = rtl_op_set_tsf, | |
1837 | .reset_tsf = rtl_op_reset_tsf, | |
1838 | .sta_notify = rtl_op_sta_notify, | |
1839 | .ampdu_action = rtl_op_ampdu_action, | |
1840 | .sw_scan_start = rtl_op_sw_scan_start, | |
1841 | .sw_scan_complete = rtl_op_sw_scan_complete, | |
1842 | .rfkill_poll = rtl_op_rfkill_poll, | |
f7953b2a LF |
1843 | .sta_add = rtl_op_sta_add, |
1844 | .sta_remove = rtl_op_sta_remove, | |
0baa0fd7 | 1845 | .flush = rtl_op_flush, |
0c817338 | 1846 | }; |
6f334c2b | 1847 | EXPORT_SYMBOL_GPL(rtl_ops); |
c0386f15 LF |
1848 | |
1849 | bool rtl_btc_status_false(void) | |
1850 | { | |
1851 | return false; | |
1852 | } | |
1853 | EXPORT_SYMBOL_GPL(rtl_btc_status_false); |