rt2800: correct BBP1_TX_POWER_CTRL mask
[pandora-kernel.git] / drivers / net / wireless / rtlwifi / 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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  * wlanfae <wlanfae@realtek.com>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <Larry.Finger@lwfinger.net>
27  *
28  *****************************************************************************/
29
30 #include "wifi.h"
31 #include "core.h"
32 #include "cam.h"
33 #include "base.h"
34 #include "ps.h"
35
36 /*mutex for start & stop is must here. */
37 static int rtl_op_start(struct ieee80211_hw *hw)
38 {
39         int err;
40         struct rtl_priv *rtlpriv = rtl_priv(hw);
41         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
42
43         if (!is_hal_stop(rtlhal))
44                 return 0;
45         if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
46                 return 0;
47         mutex_lock(&rtlpriv->locks.conf_mutex);
48         err = rtlpriv->intf_ops->adapter_start(hw);
49         if (!err)
50                 rtl_watch_dog_timer_callback((unsigned long)hw);
51         mutex_unlock(&rtlpriv->locks.conf_mutex);
52         return err;
53 }
54
55 static void rtl_op_stop(struct ieee80211_hw *hw)
56 {
57         struct rtl_priv *rtlpriv = rtl_priv(hw);
58         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
59         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
60         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
61
62         if (is_hal_stop(rtlhal))
63                 return;
64
65         if (unlikely(ppsc->rfpwr_state == ERFOFF)) {
66                 rtl_ips_nic_on(hw);
67                 mdelay(1);
68         }
69
70         mutex_lock(&rtlpriv->locks.conf_mutex);
71
72         mac->link_state = MAC80211_NOLINK;
73         memset(mac->bssid, 0, 6);
74         mac->vendor = PEER_UNKNOWN;
75
76         /*reset sec info */
77         rtl_cam_reset_sec_info(hw);
78
79         rtl_deinit_deferred_work(hw);
80         rtlpriv->intf_ops->adapter_stop(hw);
81
82         mutex_unlock(&rtlpriv->locks.conf_mutex);
83 }
84
85 static void rtl_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
86 {
87         struct rtl_priv *rtlpriv = rtl_priv(hw);
88         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
89         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
90         struct rtl_tcb_desc tcb_desc;
91         memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
92
93         if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
94                 goto err_free;
95
96         if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
97                 goto err_free;
98
99         if (!rtlpriv->intf_ops->waitq_insert(hw, skb))
100                 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
101
102         return;
103
104 err_free:
105         dev_kfree_skb_any(skb);
106 }
107
108 static int rtl_op_add_interface(struct ieee80211_hw *hw,
109                 struct ieee80211_vif *vif)
110 {
111         struct rtl_priv *rtlpriv = rtl_priv(hw);
112         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
113         int err = 0;
114
115         if (mac->vif) {
116                 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
117                          ("vif has been set!! mac->vif = 0x%p\n", mac->vif));
118                 return -EOPNOTSUPP;
119         }
120
121         rtl_ips_nic_on(hw);
122
123         mutex_lock(&rtlpriv->locks.conf_mutex);
124         switch (vif->type) {
125         case NL80211_IFTYPE_STATION:
126                 if (mac->beacon_enabled == 1) {
127                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
128                                  ("NL80211_IFTYPE_STATION\n"));
129                         mac->beacon_enabled = 0;
130                         rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
131                                         rtlpriv->cfg->maps
132                                         [RTL_IBSS_INT_MASKS]);
133                 }
134                 mac->link_state = MAC80211_LINKED;
135                 break;
136         case NL80211_IFTYPE_ADHOC:
137                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
138                          ("NL80211_IFTYPE_ADHOC\n"));
139
140                 mac->link_state = MAC80211_LINKED;
141                 rtlpriv->cfg->ops->set_bcn_reg(hw);
142                 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
143                         mac->basic_rates = 0xfff;
144                 else
145                         mac->basic_rates = 0xff0;
146                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
147                                 (u8 *) (&mac->basic_rates));
148
149                 break;
150         case NL80211_IFTYPE_AP:
151                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
152                          ("NL80211_IFTYPE_AP\n"));
153
154                 mac->link_state = MAC80211_LINKED;
155                 rtlpriv->cfg->ops->set_bcn_reg(hw);
156                 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
157                         mac->basic_rates = 0xfff;
158                 else
159                         mac->basic_rates = 0xff0;
160                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
161                                 (u8 *) (&mac->basic_rates));
162                 break;
163         default:
164                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
165                          ("operation mode %d is not support!\n", vif->type));
166                 err = -EOPNOTSUPP;
167                 goto out;
168         }
169
170         mac->vif = vif;
171         mac->opmode = vif->type;
172         rtlpriv->cfg->ops->set_network_type(hw, vif->type);
173         memcpy(mac->mac_addr, vif->addr, ETH_ALEN);
174         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
175
176 out:
177         mutex_unlock(&rtlpriv->locks.conf_mutex);
178         return err;
179 }
180
181 static void rtl_op_remove_interface(struct ieee80211_hw *hw,
182                 struct ieee80211_vif *vif)
183 {
184         struct rtl_priv *rtlpriv = rtl_priv(hw);
185         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
186
187         mutex_lock(&rtlpriv->locks.conf_mutex);
188
189         /* Free beacon resources */
190         if ((mac->opmode == NL80211_IFTYPE_AP) ||
191             (mac->opmode == NL80211_IFTYPE_ADHOC) ||
192             (mac->opmode == NL80211_IFTYPE_MESH_POINT)) {
193                 if (mac->beacon_enabled == 1) {
194                         mac->beacon_enabled = 0;
195                         rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
196                                         rtlpriv->cfg->maps
197                                         [RTL_IBSS_INT_MASKS]);
198                 }
199         }
200
201         /*
202          *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
203          *NO LINK for our hardware.
204          */
205         mac->vif = NULL;
206         mac->link_state = MAC80211_NOLINK;
207         memset(mac->bssid, 0, 6);
208         mac->vendor = PEER_UNKNOWN;
209         mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
210         rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
211         mutex_unlock(&rtlpriv->locks.conf_mutex);
212 }
213
214 static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
215 {
216         struct rtl_priv *rtlpriv = rtl_priv(hw);
217         struct rtl_phy *rtlphy = &(rtlpriv->phy);
218         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
219         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
220         struct ieee80211_conf *conf = &hw->conf;
221
222         mutex_lock(&rtlpriv->locks.conf_mutex);
223         if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {  /*BIT(2)*/
224                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
225                          ("IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n"));
226         }
227
228         /*For IPS */
229         if (changed & IEEE80211_CONF_CHANGE_IDLE) {
230                 if (hw->conf.flags & IEEE80211_CONF_IDLE)
231                         rtl_ips_nic_off(hw);
232                 else
233                         rtl_ips_nic_on(hw);
234         } else {
235                 /*
236                  *although rfoff may not cause by ips, but we will
237                  *check the reason in set_rf_power_state function
238                  */
239                 if (unlikely(ppsc->rfpwr_state == ERFOFF))
240                         rtl_ips_nic_on(hw);
241         }
242
243         /*For LPS */
244         if (changed & IEEE80211_CONF_CHANGE_PS) {
245                 cancel_delayed_work(&rtlpriv->works.ps_work);
246                 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
247                 if (conf->flags & IEEE80211_CONF_PS) {
248                         rtlpriv->psc.sw_ps_enabled = true;
249                         /* sleep here is must, or we may recv the beacon and
250                          * cause mac80211 into wrong ps state, this will cause
251                          * power save nullfunc send fail, and further cause
252                          * pkt loss, So sleep must quickly but not immediatly
253                          * because that will cause nullfunc send by mac80211
254                          * fail, and cause pkt loss, we have tested that 5mA
255                          * is worked very well */
256                         if (!rtlpriv->psc.multi_buffered)
257                                 queue_delayed_work(rtlpriv->works.rtl_wq,
258                                                 &rtlpriv->works.ps_work,
259                                                 MSECS(5));
260                 } else {
261                         rtl_swlps_rf_awake(hw);
262                         rtlpriv->psc.sw_ps_enabled = false;
263                 }
264         }
265
266         if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
267                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
268                          ("IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
269                           hw->conf.long_frame_max_tx_count));
270                 mac->retry_long = hw->conf.long_frame_max_tx_count;
271                 mac->retry_short = hw->conf.long_frame_max_tx_count;
272                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
273                                               (u8 *) (&hw->conf.
274                                                       long_frame_max_tx_count));
275         }
276
277         if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
278                 struct ieee80211_channel *channel = hw->conf.channel;
279                 u8 wide_chan = (u8) channel->hw_value;
280
281                 /*
282                  *because we should back channel to
283                  *current_network.chan in in scanning,
284                  *So if set_chan == current_network.chan
285                  *we should set it.
286                  *because mac80211 tell us wrong bw40
287                  *info for cisco1253 bw20, so we modify
288                  *it here based on UPPER & LOWER
289                  */
290                 switch (hw->conf.channel_type) {
291                 case NL80211_CHAN_HT20:
292                 case NL80211_CHAN_NO_HT:
293                         /* SC */
294                         mac->cur_40_prime_sc =
295                                 PRIME_CHNL_OFFSET_DONT_CARE;
296                         rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
297                         mac->bw_40 = false;
298                         break;
299                 case NL80211_CHAN_HT40MINUS:
300                         /* SC */
301                         mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
302                         rtlphy->current_chan_bw =
303                                 HT_CHANNEL_WIDTH_20_40;
304                         mac->bw_40 = true;
305
306                         /*wide channel */
307                         wide_chan -= 2;
308
309                         break;
310                 case NL80211_CHAN_HT40PLUS:
311                         /* SC */
312                         mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
313                         rtlphy->current_chan_bw =
314                                 HT_CHANNEL_WIDTH_20_40;
315                         mac->bw_40 = true;
316
317                         /*wide channel */
318                         wide_chan += 2;
319
320                         break;
321                 default:
322                         mac->bw_40 = false;
323                         RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
324                                         ("switch case not processed\n"));
325                         break;
326                 }
327
328                 if (wide_chan <= 0)
329                         wide_chan = 1;
330
331                 /* In scanning, before we go offchannel we may send a ps=1 null
332                  * to AP, and then we may send a ps = 0 null to AP quickly, but
333                  * first null may have caused AP to put lots of packet to hw tx
334                  * buffer. These packets must be tx'd before we go off channel
335                  * so we must delay more time to let AP flush these packets
336                  * before going offchannel, or dis-association or delete BA will
337                  * happen by AP
338                  */
339                 if (rtlpriv->mac80211.offchan_delay) {
340                         rtlpriv->mac80211.offchan_delay = false;
341                         mdelay(50);
342                 }
343                 rtlphy->current_channel = wide_chan;
344
345                 rtlpriv->cfg->ops->switch_channel(hw);
346                 rtlpriv->cfg->ops->set_channel_access(hw);
347                 rtlpriv->cfg->ops->set_bw_mode(hw,
348                                                hw->conf.channel_type);
349         }
350
351         mutex_unlock(&rtlpriv->locks.conf_mutex);
352
353         return 0;
354 }
355
356 static void rtl_op_configure_filter(struct ieee80211_hw *hw,
357                              unsigned int changed_flags,
358                              unsigned int *new_flags, u64 multicast)
359 {
360         struct rtl_priv *rtlpriv = rtl_priv(hw);
361         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
362
363         *new_flags &= RTL_SUPPORTED_FILTERS;
364         if (!changed_flags)
365                 return;
366
367         /*TODO: we disable broadcase now, so enable here */
368         if (changed_flags & FIF_ALLMULTI) {
369                 if (*new_flags & FIF_ALLMULTI) {
370                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] |
371                             rtlpriv->cfg->maps[MAC_RCR_AB];
372                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
373                                  ("Enable receive multicast frame.\n"));
374                 } else {
375                         mac->rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] |
376                                           rtlpriv->cfg->maps[MAC_RCR_AB]);
377                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
378                                  ("Disable receive multicast frame.\n"));
379                 }
380         }
381
382         if (changed_flags & FIF_FCSFAIL) {
383                 if (*new_flags & FIF_FCSFAIL) {
384                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32];
385                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
386                                  ("Enable receive FCS error frame.\n"));
387                 } else {
388                         mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32];
389                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
390                                  ("Disable receive FCS error frame.\n"));
391                 }
392         }
393
394         /* if ssid not set to hw don't check bssid
395          * here just used for linked scanning, & linked
396          * and nolink check bssid is set in set network_type */
397         if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
398                 (mac->link_state >= MAC80211_LINKED)) {
399                 if (mac->opmode != NL80211_IFTYPE_AP) {
400                         if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
401                                 rtlpriv->cfg->ops->set_chk_bssid(hw, false);
402                         } else {
403                                 rtlpriv->cfg->ops->set_chk_bssid(hw, true);
404                         }
405                 }
406         }
407
408         if (changed_flags & FIF_CONTROL) {
409                 if (*new_flags & FIF_CONTROL) {
410                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
411
412                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
413                                  ("Enable receive control frame.\n"));
414                 } else {
415                         mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
416                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
417                                  ("Disable receive control frame.\n"));
418                 }
419         }
420
421         if (changed_flags & FIF_OTHER_BSS) {
422                 if (*new_flags & FIF_OTHER_BSS) {
423                         mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP];
424                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
425                                  ("Enable receive other BSS's frame.\n"));
426                 } else {
427                         mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP];
428                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
429                                  ("Disable receive other BSS's frame.\n"));
430                 }
431         }
432 }
433 static int rtl_op_sta_add(struct ieee80211_hw *hw,
434                          struct ieee80211_vif *vif,
435                          struct ieee80211_sta *sta)
436 {
437         struct rtl_priv *rtlpriv = rtl_priv(hw);
438         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
439         struct rtl_sta_info *sta_entry;
440
441         if (sta) {
442                 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
443                 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
444                         sta_entry->wireless_mode = WIRELESS_MODE_G;
445                         if (sta->supp_rates[0] <= 0xf)
446                                 sta_entry->wireless_mode = WIRELESS_MODE_B;
447                         if (sta->ht_cap.ht_supported)
448                                 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
449                 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
450                         sta_entry->wireless_mode = WIRELESS_MODE_A;
451                         if (sta->ht_cap.ht_supported)
452                                 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
453                 }
454
455                 /* I found some times mac80211 give wrong supp_rates for adhoc*/
456                 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC)
457                         sta_entry->wireless_mode = WIRELESS_MODE_G;
458
459                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
460                         ("Add sta addr is %pM\n", sta->addr));
461                 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
462         }
463         return 0;
464 }
465 static int rtl_op_sta_remove(struct ieee80211_hw *hw,
466                                 struct ieee80211_vif *vif,
467                                 struct ieee80211_sta *sta)
468 {
469         struct rtl_priv *rtlpriv = rtl_priv(hw);
470         struct rtl_sta_info *sta_entry;
471         if (sta) {
472                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
473                         ("Remove sta addr is %pM\n", sta->addr));
474                 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
475                 sta_entry->wireless_mode = 0;
476                 sta_entry->ratr_index = 0;
477         }
478         return 0;
479 }
480 static int _rtl_get_hal_qnum(u16 queue)
481 {
482         int qnum;
483
484         switch (queue) {
485         case 0:
486                 qnum = AC3_VO;
487                 break;
488         case 1:
489                 qnum = AC2_VI;
490                 break;
491         case 2:
492                 qnum = AC0_BE;
493                 break;
494         case 3:
495                 qnum = AC1_BK;
496                 break;
497         default:
498                 qnum = AC0_BE;
499                 break;
500         }
501         return qnum;
502 }
503
504 /*
505  *for mac80211 VO=0, VI=1, BE=2, BK=3
506  *for rtl819x  BE=0, BK=1, VI=2, VO=3
507  */
508 static int rtl_op_conf_tx(struct ieee80211_hw *hw,
509                    struct ieee80211_vif *vif, u16 queue,
510                    const struct ieee80211_tx_queue_params *param)
511 {
512         struct rtl_priv *rtlpriv = rtl_priv(hw);
513         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
514         int aci;
515
516         if (queue >= AC_MAX) {
517                 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
518                          ("queue number %d is incorrect!\n", queue));
519                 return -EINVAL;
520         }
521
522         aci = _rtl_get_hal_qnum(queue);
523         mac->ac[aci].aifs = param->aifs;
524         mac->ac[aci].cw_min = cpu_to_le16(param->cw_min);
525         mac->ac[aci].cw_max = cpu_to_le16(param->cw_max);
526         mac->ac[aci].tx_op = cpu_to_le16(param->txop);
527         memcpy(&mac->edca_param[aci], param, sizeof(*param));
528         rtlpriv->cfg->ops->set_qos(hw, aci);
529         return 0;
530 }
531
532 static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
533                              struct ieee80211_vif *vif,
534                              struct ieee80211_bss_conf *bss_conf, u32 changed)
535 {
536         struct rtl_priv *rtlpriv = rtl_priv(hw);
537         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
538         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
539         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
540         struct ieee80211_sta *sta = NULL;
541
542         mutex_lock(&rtlpriv->locks.conf_mutex);
543         if ((vif->type == NL80211_IFTYPE_ADHOC) ||
544             (vif->type == NL80211_IFTYPE_AP) ||
545             (vif->type == NL80211_IFTYPE_MESH_POINT)) {
546                 if ((changed & BSS_CHANGED_BEACON) ||
547                     (changed & BSS_CHANGED_BEACON_ENABLED &&
548                      bss_conf->enable_beacon)) {
549                         if (mac->beacon_enabled == 0) {
550                                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
551                                          ("BSS_CHANGED_BEACON_ENABLED\n"));
552
553                                 /*start hw beacon interrupt. */
554                                 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
555                                 mac->beacon_enabled = 1;
556                                 rtlpriv->cfg->ops->update_interrupt_mask(hw,
557                                                 rtlpriv->cfg->maps
558                                                 [RTL_IBSS_INT_MASKS],
559                                                 0);
560
561                                 if (rtlpriv->cfg->ops->linked_set_reg)
562                                         rtlpriv->cfg->ops->linked_set_reg(hw);
563                         }
564                 }
565                 if ((changed & BSS_CHANGED_BEACON_ENABLED &&
566                         !bss_conf->enable_beacon)) {
567                         if (mac->beacon_enabled == 1) {
568                                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
569                                          ("ADHOC DISABLE BEACON\n"));
570
571                                 mac->beacon_enabled = 0;
572                                 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
573                                                 rtlpriv->cfg->maps
574                                                 [RTL_IBSS_INT_MASKS]);
575                         }
576                 }
577                 if (changed & BSS_CHANGED_BEACON_INT) {
578                         RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
579                                  ("BSS_CHANGED_BEACON_INT\n"));
580                         mac->beacon_interval = bss_conf->beacon_int;
581                         rtlpriv->cfg->ops->set_bcn_intv(hw);
582                 }
583         }
584
585         /*TODO: reference to enum ieee80211_bss_change */
586         if (changed & BSS_CHANGED_ASSOC) {
587                 if (bss_conf->assoc) {
588                         /* we should reset all sec info & cam
589                          * before set cam after linked, we should not
590                          * reset in disassoc, that will cause tkip->wep
591                          * fail because some flag will be wrong */
592                         /* reset sec info */
593                         rtl_cam_reset_sec_info(hw);
594                         /* reset cam to fix wep fail issue
595                          * when change from wpa to wep */
596                         rtl_cam_reset_all_entry(hw);
597
598                         mac->link_state = MAC80211_LINKED;
599                         mac->cnt_after_linked = 0;
600                         mac->assoc_id = bss_conf->aid;
601                         memcpy(mac->bssid, bss_conf->bssid, 6);
602
603                         if (rtlpriv->cfg->ops->linked_set_reg)
604                                 rtlpriv->cfg->ops->linked_set_reg(hw);
605                         if (mac->opmode == NL80211_IFTYPE_STATION && sta)
606                                 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
607                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
608                                  ("BSS_CHANGED_ASSOC\n"));
609                 } else {
610                         if (mac->link_state == MAC80211_LINKED)
611                                 rtl_lps_leave(hw);
612
613                         mac->link_state = MAC80211_NOLINK;
614                         memset(mac->bssid, 0, 6);
615
616                         /* reset sec info */
617                         rtl_cam_reset_sec_info(hw);
618
619                         rtl_cam_reset_all_entry(hw);
620                         mac->vendor = PEER_UNKNOWN;
621
622                         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
623                                  ("BSS_CHANGED_UN_ASSOC\n"));
624                 }
625         }
626
627         if (changed & BSS_CHANGED_ERP_CTS_PROT) {
628                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
629                          ("BSS_CHANGED_ERP_CTS_PROT\n"));
630                 mac->use_cts_protect = bss_conf->use_cts_prot;
631         }
632
633         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
634                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
635                          ("BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
636                           bss_conf->use_short_preamble));
637
638                 mac->short_preamble = bss_conf->use_short_preamble;
639                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE,
640                                               (u8 *) (&mac->short_preamble));
641         }
642
643         if (changed & BSS_CHANGED_ERP_SLOT) {
644                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
645                          ("BSS_CHANGED_ERP_SLOT\n"));
646
647                 if (bss_conf->use_short_slot)
648                         mac->slot_time = RTL_SLOT_TIME_9;
649                 else
650                         mac->slot_time = RTL_SLOT_TIME_20;
651
652                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
653                                               (u8 *) (&mac->slot_time));
654         }
655
656         if (changed & BSS_CHANGED_HT) {
657                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
658                          ("BSS_CHANGED_HT\n"));
659                 rcu_read_lock();
660                 sta = get_sta(hw, vif, bss_conf->bssid);
661                 if (sta) {
662                         if (sta->ht_cap.ampdu_density >
663                             mac->current_ampdu_density)
664                                 mac->current_ampdu_density =
665                                     sta->ht_cap.ampdu_density;
666                         if (sta->ht_cap.ampdu_factor <
667                             mac->current_ampdu_factor)
668                                 mac->current_ampdu_factor =
669                                     sta->ht_cap.ampdu_factor;
670                 }
671                 rcu_read_unlock();
672
673                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY,
674                                               (u8 *) (&mac->max_mss_density));
675                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR,
676                                               &mac->current_ampdu_factor);
677                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE,
678                                               &mac->current_ampdu_density);
679         }
680
681         if (changed & BSS_CHANGED_BSSID) {
682                 u32 basic_rates;
683
684                 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
685                                               (u8 *) bss_conf->bssid);
686
687                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
688                          ("%pM\n", bss_conf->bssid));
689
690                 mac->vendor = PEER_UNKNOWN;
691                 memcpy(mac->bssid, bss_conf->bssid, 6);
692                 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
693
694                 rcu_read_lock();
695                 sta = get_sta(hw, vif, bss_conf->bssid);
696                 if (!sta) {
697                         rcu_read_unlock();
698                         goto out;
699                 }
700
701                 if (rtlhal->current_bandtype == BAND_ON_5G) {
702                         mac->mode = WIRELESS_MODE_A;
703                 } else {
704                         if (sta->supp_rates[0] <= 0xf)
705                                 mac->mode = WIRELESS_MODE_B;
706                         else
707                                 mac->mode = WIRELESS_MODE_G;
708                 }
709
710                 if (sta->ht_cap.ht_supported) {
711                         if (rtlhal->current_bandtype == BAND_ON_2_4G)
712                                 mac->mode = WIRELESS_MODE_N_24G;
713                         else
714                                 mac->mode = WIRELESS_MODE_N_5G;
715                 }
716
717                 /* just station need it, because ibss & ap mode will
718                  * set in sta_add, and will be NULL here */
719                 if (mac->opmode == NL80211_IFTYPE_STATION) {
720                         struct rtl_sta_info *sta_entry;
721                         sta_entry = (struct rtl_sta_info *) sta->drv_priv;
722                         sta_entry->wireless_mode = mac->mode;
723                 }
724
725                 if (sta->ht_cap.ht_supported) {
726                         mac->ht_enable = true;
727
728                         /*
729                          * for cisco 1252 bw20 it's wrong
730                          * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
731                          *      mac->bw_40 = true;
732                          * }
733                          * */
734                 }
735
736                 if (changed & BSS_CHANGED_BASIC_RATES) {
737                         /* for 5G must << RATE_6M_INDEX=4,
738                          * because 5G have no cck rate*/
739                         if (rtlhal->current_bandtype == BAND_ON_5G)
740                                 basic_rates = sta->supp_rates[1] << 4;
741                         else
742                                 basic_rates = sta->supp_rates[0];
743
744                         mac->basic_rates = basic_rates;
745                         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
746                                         (u8 *) (&basic_rates));
747                 }
748                 rcu_read_unlock();
749         }
750
751         /*
752          * For FW LPS:
753          * To tell firmware we have connected
754          * to an AP. For 92SE/CE power save v2.
755          */
756         if (changed & BSS_CHANGED_ASSOC) {
757                 if (bss_conf->assoc) {
758                         if (ppsc->fwctrl_lps) {
759                                 u8 mstatus = RT_MEDIA_CONNECT;
760                                 rtlpriv->cfg->ops->set_hw_reg(hw,
761                                                       HW_VAR_H2C_FW_JOINBSSRPT,
762                                                       (u8 *) (&mstatus));
763                                 ppsc->report_linked = true;
764                         }
765                 } else {
766                         if (ppsc->fwctrl_lps) {
767                                 u8 mstatus = RT_MEDIA_DISCONNECT;
768                                 rtlpriv->cfg->ops->set_hw_reg(hw,
769                                                       HW_VAR_H2C_FW_JOINBSSRPT,
770                                                       (u8 *)(&mstatus));
771                                 ppsc->report_linked = false;
772                         }
773                 }
774         }
775
776 out:
777         mutex_unlock(&rtlpriv->locks.conf_mutex);
778 }
779
780 static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
781 {
782         struct rtl_priv *rtlpriv = rtl_priv(hw);
783         u64 tsf;
784
785         rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&tsf));
786         return tsf;
787 }
788
789 static void rtl_op_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
790                            u64 tsf)
791 {
792         struct rtl_priv *rtlpriv = rtl_priv(hw);
793         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
794         u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
795
796         mac->tsf = tsf;
797         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *) (&bibss));
798 }
799
800 static void rtl_op_reset_tsf(struct ieee80211_hw *hw,
801                              struct ieee80211_vif *vif)
802 {
803         struct rtl_priv *rtlpriv = rtl_priv(hw);
804         u8 tmp = 0;
805
806         rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *) (&tmp));
807 }
808
809 static void rtl_op_sta_notify(struct ieee80211_hw *hw,
810                               struct ieee80211_vif *vif,
811                               enum sta_notify_cmd cmd,
812                               struct ieee80211_sta *sta)
813 {
814         switch (cmd) {
815         case STA_NOTIFY_SLEEP:
816                 break;
817         case STA_NOTIFY_AWAKE:
818                 break;
819         default:
820                 break;
821         }
822 }
823
824 static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
825                                struct ieee80211_vif *vif,
826                                enum ieee80211_ampdu_mlme_action action,
827                                struct ieee80211_sta *sta, u16 tid, u16 *ssn,
828                                u8 buf_size)
829 {
830         struct rtl_priv *rtlpriv = rtl_priv(hw);
831
832         switch (action) {
833         case IEEE80211_AMPDU_TX_START:
834                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
835                          ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid));
836                 return rtl_tx_agg_start(hw, sta, tid, ssn);
837                 break;
838         case IEEE80211_AMPDU_TX_STOP:
839                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
840                          ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid));
841                 return rtl_tx_agg_stop(hw, sta, tid);
842                 break;
843         case IEEE80211_AMPDU_TX_OPERATIONAL:
844                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
845                          ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid));
846                 rtl_tx_agg_oper(hw, sta, tid);
847                 break;
848         case IEEE80211_AMPDU_RX_START:
849                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
850                          ("IEEE80211_AMPDU_RX_START:TID:%d\n", tid));
851                 break;
852         case IEEE80211_AMPDU_RX_STOP:
853                 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
854                          ("IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid));
855                 break;
856         default:
857                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
858                          ("IEEE80211_AMPDU_ERR!!!!:\n"));
859                 return -EOPNOTSUPP;
860         }
861         return 0;
862 }
863
864 static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
865 {
866         struct rtl_priv *rtlpriv = rtl_priv(hw);
867         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
868
869         mac->act_scanning = true;
870
871         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
872
873         if (mac->link_state == MAC80211_LINKED) {
874                 rtl_lps_leave(hw);
875                 mac->link_state = MAC80211_LINKED_SCANNING;
876         } else {
877                 rtl_ips_nic_on(hw);
878         }
879
880         /* Dual mac */
881         rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
882
883         rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
884         rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
885 }
886
887 static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
888 {
889         struct rtl_priv *rtlpriv = rtl_priv(hw);
890         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
891
892         RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
893         mac->act_scanning = false;
894         /* Dual mac */
895         rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
896
897         if (mac->link_state == MAC80211_LINKED_SCANNING) {
898                 mac->link_state = MAC80211_LINKED;
899                 if (mac->opmode == NL80211_IFTYPE_STATION) {
900                         /* fix fwlps issue */
901                         rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
902                 }
903         }
904
905         rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
906 }
907
908 static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
909                           struct ieee80211_vif *vif, struct ieee80211_sta *sta,
910                           struct ieee80211_key_conf *key)
911 {
912         struct rtl_priv *rtlpriv = rtl_priv(hw);
913         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
914         u8 key_type = NO_ENCRYPTION;
915         u8 key_idx;
916         bool group_key = false;
917         bool wep_only = false;
918         int err = 0;
919         u8 mac_addr[ETH_ALEN];
920         u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
921         u8 zero_addr[ETH_ALEN] = { 0 };
922
923         if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
924                 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
925                          ("not open hw encryption\n"));
926                 return -ENOSPC; /*User disabled HW-crypto */
927         }
928         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
929                  ("%s hardware based encryption for keyidx: %d, mac: %pM\n",
930                   cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
931                   sta ? sta->addr : bcast_addr));
932         rtlpriv->sec.being_setkey = true;
933         rtl_ips_nic_on(hw);
934         mutex_lock(&rtlpriv->locks.conf_mutex);
935         /* <1> get encryption alg */
936
937         switch (key->cipher) {
938         case WLAN_CIPHER_SUITE_WEP40:
939                 key_type = WEP40_ENCRYPTION;
940                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:WEP40\n"));
941                 break;
942         case WLAN_CIPHER_SUITE_WEP104:
943                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
944                          ("alg:WEP104\n"));
945                 key_type = WEP104_ENCRYPTION;
946                 break;
947         case WLAN_CIPHER_SUITE_TKIP:
948                 key_type = TKIP_ENCRYPTION;
949                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:TKIP\n"));
950                 break;
951         case WLAN_CIPHER_SUITE_CCMP:
952                 key_type = AESCCMP_ENCRYPTION;
953                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:CCMP\n"));
954                 break;
955         default:
956                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
957                          ("alg_err:%x!!!!:\n", key->cipher));
958                 goto out_unlock;
959         }
960         if (key_type == WEP40_ENCRYPTION ||
961                         key_type == WEP104_ENCRYPTION ||
962                         mac->opmode == NL80211_IFTYPE_ADHOC)
963                 rtlpriv->sec.use_defaultkey = true;
964
965         /* <2> get key_idx */
966         key_idx = (u8) (key->keyidx);
967         if (key_idx > 3)
968                 goto out_unlock;
969         /* <3> if pairwise key enable_hw_sec */
970         group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
971
972         /* wep always be group key, but there are two conditions:
973          * 1) wep only: is just for wep enc, in this condition
974          * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
975          * will be true & enable_hw_sec will be set when wep
976          * ke setting.
977          * 2) wep(group) + AES(pairwise): some AP like cisco
978          * may use it, in this condition enable_hw_sec will not
979          * be set when wep key setting */
980         /* we must reset sec_info after lingked before set key,
981          * or some flag will be wrong*/
982         if (mac->opmode == NL80211_IFTYPE_AP) {
983                 if (!group_key || key_type == WEP40_ENCRYPTION ||
984                         key_type == WEP104_ENCRYPTION) {
985                         if (group_key)
986                                 wep_only = true;
987                         rtlpriv->cfg->ops->enable_hw_sec(hw);
988                 }
989         } else {
990                 if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
991                      rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
992                         if (rtlpriv->sec.pairwise_enc_algorithm ==
993                             NO_ENCRYPTION &&
994                             (key_type == WEP40_ENCRYPTION ||
995                             key_type == WEP104_ENCRYPTION))
996                                 wep_only = true;
997                         rtlpriv->sec.pairwise_enc_algorithm = key_type;
998                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
999                                 ("set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1"
1000                                 " TKIP:2 AES:4 WEP104:5)\n", key_type));
1001                         rtlpriv->cfg->ops->enable_hw_sec(hw);
1002                 }
1003         }
1004         /* <4> set key based on cmd */
1005         switch (cmd) {
1006         case SET_KEY:
1007                 if (wep_only) {
1008                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1009                                  ("set WEP(group/pairwise) key\n"));
1010                         /* Pairwise key with an assigned MAC address. */
1011                         rtlpriv->sec.pairwise_enc_algorithm = key_type;
1012                         rtlpriv->sec.group_enc_algorithm = key_type;
1013                         /*set local buf about wep key. */
1014                         memcpy(rtlpriv->sec.key_buf[key_idx],
1015                                key->key, key->keylen);
1016                         rtlpriv->sec.key_len[key_idx] = key->keylen;
1017                         memcpy(mac_addr, zero_addr, ETH_ALEN);
1018                 } else if (group_key) { /* group key */
1019                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1020                                  ("set group key\n"));
1021                         /* group key */
1022                         rtlpriv->sec.group_enc_algorithm = key_type;
1023                         /*set local buf about group key. */
1024                         memcpy(rtlpriv->sec.key_buf[key_idx],
1025                                key->key, key->keylen);
1026                         rtlpriv->sec.key_len[key_idx] = key->keylen;
1027                         memcpy(mac_addr, bcast_addr, ETH_ALEN);
1028                 } else {        /* pairwise key */
1029                         RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1030                                  ("set pairwise key\n"));
1031                         if (!sta) {
1032                                 RT_ASSERT(false, ("pairwise key withnot"
1033                                                   "mac_addr\n"));
1034
1035                                 err = -EOPNOTSUPP;
1036                                 goto out_unlock;
1037                         }
1038                         /* Pairwise key with an assigned MAC address. */
1039                         rtlpriv->sec.pairwise_enc_algorithm = key_type;
1040                         /*set local buf about pairwise key. */
1041                         memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX],
1042                                key->key, key->keylen);
1043                         rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen;
1044                         rtlpriv->sec.pairwise_key =
1045                             rtlpriv->sec.key_buf[PAIRWISE_KEYIDX];
1046                         memcpy(mac_addr, sta->addr, ETH_ALEN);
1047                 }
1048                 rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
1049                                            group_key, key_type, wep_only,
1050                                            false);
1051                 /* <5> tell mac80211 do something: */
1052                 /*must use sw generate IV, or can not work !!!!. */
1053                 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1054                 key->hw_key_idx = key_idx;
1055                 if (key_type == TKIP_ENCRYPTION)
1056                         key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1057                 break;
1058         case DISABLE_KEY:
1059                 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1060                          ("disable key delete one entry\n"));
1061                 /*set local buf about wep key. */
1062                 if (mac->opmode == NL80211_IFTYPE_AP) {
1063                         if (sta)
1064                                 rtl_cam_del_entry(hw, sta->addr);
1065                 }
1066                 memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
1067                 rtlpriv->sec.key_len[key_idx] = 0;
1068                 memcpy(mac_addr, zero_addr, ETH_ALEN);
1069                 /*
1070                  *mac80211 will delete entrys one by one,
1071                  *so don't use rtl_cam_reset_all_entry
1072                  *or clear all entry here.
1073                  */
1074                 rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
1075
1076                 rtl_cam_reset_sec_info(hw);
1077
1078                 break;
1079         default:
1080                 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1081                          ("cmd_err:%x!!!!:\n", cmd));
1082         }
1083 out_unlock:
1084         mutex_unlock(&rtlpriv->locks.conf_mutex);
1085         rtlpriv->sec.being_setkey = false;
1086         return err;
1087 }
1088
1089 static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
1090 {
1091         struct rtl_priv *rtlpriv = rtl_priv(hw);
1092
1093         bool radio_state;
1094         bool blocked;
1095         u8 valid = 0;
1096
1097         if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1098                 return;
1099
1100         mutex_lock(&rtlpriv->locks.conf_mutex);
1101
1102         /*if Radio On return true here */
1103         radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
1104
1105         if (valid) {
1106                 if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
1107                         rtlpriv->rfkill.rfkill_state = radio_state;
1108
1109                         RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1110                                  (KERN_INFO "wireless radio switch turned %s\n",
1111                                   radio_state ? "on" : "off"));
1112
1113                         blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
1114                         wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1115                 }
1116         }
1117
1118         mutex_unlock(&rtlpriv->locks.conf_mutex);
1119 }
1120
1121 /* this function is called by mac80211 to flush tx buffer
1122  * before switch channle or power save, or tx buffer packet
1123  * maybe send after offchannel or rf sleep, this may cause
1124  * dis-association by AP */
1125 static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
1126 {
1127         struct rtl_priv *rtlpriv = rtl_priv(hw);
1128
1129         if (rtlpriv->intf_ops->flush)
1130                 rtlpriv->intf_ops->flush(hw, drop);
1131 }
1132
1133 const struct ieee80211_ops rtl_ops = {
1134         .start = rtl_op_start,
1135         .stop = rtl_op_stop,
1136         .tx = rtl_op_tx,
1137         .add_interface = rtl_op_add_interface,
1138         .remove_interface = rtl_op_remove_interface,
1139         .config = rtl_op_config,
1140         .configure_filter = rtl_op_configure_filter,
1141         .sta_add = rtl_op_sta_add,
1142         .sta_remove = rtl_op_sta_remove,
1143         .set_key = rtl_op_set_key,
1144         .conf_tx = rtl_op_conf_tx,
1145         .bss_info_changed = rtl_op_bss_info_changed,
1146         .get_tsf = rtl_op_get_tsf,
1147         .set_tsf = rtl_op_set_tsf,
1148         .reset_tsf = rtl_op_reset_tsf,
1149         .sta_notify = rtl_op_sta_notify,
1150         .ampdu_action = rtl_op_ampdu_action,
1151         .sw_scan_start = rtl_op_sw_scan_start,
1152         .sw_scan_complete = rtl_op_sw_scan_complete,
1153         .rfkill_poll = rtl_op_rfkill_poll,
1154         .flush = rtl_op_flush,
1155 };