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