staging: brcm80211: implement mac80211 callback set_rts_threshold
[firefly-linux-kernel-4.4.55.git] / drivers / staging / brcm80211 / brcmsmac / wl_mac80211.c
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #define __UNDEF_NO_VERSION__
18
19 #include <linux/kernel.h>
20 #include <linux/etherdevice.h>
21 #include <linux/string.h>
22 #include <linux/pci_ids.h>
23 #include <bcmdefs.h>
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/sched.h>
27 #include <osl.h>
28 #define WLC_MAXBSSCFG           1       /* single BSS configs */
29
30 #include <wlc_cfg.h>
31 #include <net/mac80211.h>
32 #include <phy_version.h>
33 #include <bcmutils.h>
34 #include <pcicfg.h>
35 #include <wlioctl.h>
36 #include <wlc_key.h>
37 #include <sbhndpio.h>
38 #include <sbhnddma.h>
39 #include <wlc_channel.h>
40 #include <wlc_pub.h>
41 #include <wlc_scb.h>
42 #include <wl_dbg.h>
43 #include <wl_export.h>
44
45 #include <wl_mac80211.h>
46 #include <linux/firmware.h>
47 #include <wl_ucode.h>
48 #include <d11ucode_ext.h>
49
50
51 static void wl_timer(unsigned long data);
52 static void _wl_timer(wl_timer_t *t);
53
54
55 static int ieee_hw_init(struct ieee80211_hw *hw);
56 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
57
58 static int wl_linux_watchdog(void *ctx);
59
60 /* Flags we support */
61 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
62         FIF_ALLMULTI | \
63         FIF_FCSFAIL | \
64         FIF_PLCPFAIL | \
65         FIF_CONTROL | \
66         FIF_OTHER_BSS | \
67         FIF_BCN_PRBRESP_PROMISC)
68
69 static int wl_found;
70
71 #define WL_DEV_IF(dev)          ((struct wl_if *)netdev_priv(dev))
72 #define WL_INFO(dev)            ((struct wl_info *)(WL_DEV_IF(dev)->wl))
73 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev);
74 static void wl_release_fw(struct wl_info *wl);
75
76 /* local prototypes */
77 static int wl_start(struct sk_buff *skb, struct wl_info *wl);
78 static int wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw,
79                         struct sk_buff *skb);
80 static void wl_dpc(unsigned long data);
81
82 MODULE_AUTHOR("Broadcom Corporation");
83 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
84 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
85 MODULE_LICENSE("Dual BSD/GPL");
86
87 /* recognized PCI IDs */
88 static struct pci_device_id wl_id_table[] = {
89         {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},      /* 43225 2G */
90         {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},      /* 43224 DUAL */
91         {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},      /* 4313 DUAL */
92         {0}
93 };
94
95 MODULE_DEVICE_TABLE(pci, wl_id_table);
96 static void wl_remove(struct pci_dev *pdev);
97
98
99 #ifdef BCMDBG
100 static int msglevel = 0xdeadbeef;
101 module_param(msglevel, int, 0);
102 static int phymsglevel = 0xdeadbeef;
103 module_param(phymsglevel, int, 0);
104 #endif                          /* BCMDBG */
105
106 #define HW_TO_WL(hw)     (hw->priv)
107 #define WL_TO_HW(wl)      (wl->pub->ieee_hw)
108 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
109 static int wl_ops_start(struct ieee80211_hw *hw);
110 static void wl_ops_stop(struct ieee80211_hw *hw);
111 static int wl_ops_add_interface(struct ieee80211_hw *hw,
112                                 struct ieee80211_vif *vif);
113 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
114                                     struct ieee80211_vif *vif);
115 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
116 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
117                                     struct ieee80211_vif *vif,
118                                     struct ieee80211_bss_conf *info,
119                                     u32 changed);
120 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
121                                     unsigned int changed_flags,
122                                     unsigned int *total_flags, u64 multicast);
123 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
124                           bool set);
125 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
126 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
127 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
128 static int wl_ops_get_stats(struct ieee80211_hw *hw,
129                             struct ieee80211_low_level_stats *stats);
130 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
131 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
132                               struct ieee80211_vif *vif,
133                               enum sta_notify_cmd cmd,
134                               struct ieee80211_sta *sta);
135 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
136                           const struct ieee80211_tx_queue_params *params);
137 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
138 static int wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
139                       struct ieee80211_sta *sta);
140 static int wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
141                          struct ieee80211_sta *sta);
142 static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
143                            enum ieee80211_ampdu_mlme_action action,
144                            struct ieee80211_sta *sta, u16 tid, u16 *ssn);
145 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw);
146
147 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
148 {
149         int status;
150         struct wl_info *wl = hw->priv;
151         WL_LOCK(wl);
152         if (!wl->pub->up) {
153                 WL_ERROR("ops->tx called while down\n");
154                 status = -ENETDOWN;
155                 goto done;
156         }
157         status = wl_start(skb, wl);
158  done:
159         WL_UNLOCK(wl);
160         return status;
161 }
162
163 static int wl_ops_start(struct ieee80211_hw *hw)
164 {
165         struct wl_info *wl = hw->priv;
166         bool blocked;
167         /*
168           struct ieee80211_channel *curchan = hw->conf.channel;
169           WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
170         */
171
172         WL_LOCK(wl);
173         ieee80211_wake_queues(hw);
174         WL_UNLOCK(wl);
175         blocked = wl_rfkill_set_hw_state(wl);
176         if (!blocked)
177                 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
178
179         return 0;
180 }
181
182 static void wl_ops_stop(struct ieee80211_hw *hw)
183 {
184         struct wl_info *wl = hw->priv;
185         ASSERT(wl);
186         WL_LOCK(wl);
187         ieee80211_stop_queues(hw);
188         WL_UNLOCK(wl);
189 }
190
191 static int
192 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
193 {
194         struct wl_info *wl;
195         int err;
196
197         /* Just STA for now */
198         if (vif->type != NL80211_IFTYPE_AP &&
199             vif->type != NL80211_IFTYPE_MESH_POINT &&
200             vif->type != NL80211_IFTYPE_STATION &&
201             vif->type != NL80211_IFTYPE_WDS &&
202             vif->type != NL80211_IFTYPE_ADHOC) {
203                 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
204                          __func__, vif->type);
205                 return -EOPNOTSUPP;
206         }
207
208         wl = HW_TO_WL(hw);
209         WL_LOCK(wl);
210         err = wl_up(wl);
211         WL_UNLOCK(wl);
212
213         if (err != 0) {
214                 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
215         }
216         return err;
217 }
218
219 static void
220 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
221 {
222         struct wl_info *wl;
223
224         wl = HW_TO_WL(hw);
225
226         /* put driver in down state */
227         WL_LOCK(wl);
228         wl_down(wl);
229         WL_UNLOCK(wl);
230 }
231
232 static int
233 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
234                  enum nl80211_channel_type type)
235 {
236         struct wl_info *wl = HW_TO_WL(hw);
237         int err = 0;
238
239         switch (type) {
240         case NL80211_CHAN_HT20:
241         case NL80211_CHAN_NO_HT:
242                 WL_LOCK(wl);
243                 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
244                 WL_UNLOCK(wl);
245                 break;
246         case NL80211_CHAN_HT40MINUS:
247         case NL80211_CHAN_HT40PLUS:
248                 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
249                 break;
250         }
251
252         if (err)
253                 return -EIO;
254         return err;
255 }
256
257 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
258 {
259         struct ieee80211_conf *conf = &hw->conf;
260         struct wl_info *wl = HW_TO_WL(hw);
261         int err = 0;
262         int new_int;
263
264         if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
265                 WL_NONE("%s: Setting listen interval to %d\n",
266                         __func__, conf->listen_interval);
267                 if (wlc_iovar_setint
268                     (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
269                         WL_ERROR("%s: Error setting listen_interval\n",
270                                  __func__);
271                         err = -EIO;
272                         goto config_out;
273                 }
274                 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
275                 ASSERT(new_int == conf->listen_interval);
276         }
277         if (changed & IEEE80211_CONF_CHANGE_MONITOR)
278                 WL_NONE("Need to set monitor mode\n");
279         if (changed & IEEE80211_CONF_CHANGE_PS)
280                 WL_NONE("Need to set Power-save mode\n");
281
282         if (changed & IEEE80211_CONF_CHANGE_POWER) {
283                 WL_NONE("%s: Setting tx power to %d dbm\n",
284                         __func__, conf->power_level);
285                 if (wlc_iovar_setint
286                     (wl->wlc, "qtxpower", conf->power_level * 4)) {
287                         WL_ERROR("%s: Error setting power_level\n", __func__);
288                         err = -EIO;
289                         goto config_out;
290                 }
291                 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
292                 if (new_int != (conf->power_level * 4))
293                         WL_ERROR("%s: Power level req != actual, %d %d\n",
294                                  __func__, conf->power_level * 4, new_int);
295         }
296         if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
297                 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
298         }
299         if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
300                 WL_NONE("%s: srl %d, lrl %d\n",
301                         __func__,
302                         conf->short_frame_max_tx_count,
303                         conf->long_frame_max_tx_count);
304                 if (wlc_set
305                     (wl->wlc, WLC_SET_SRL,
306                      conf->short_frame_max_tx_count) < 0) {
307                         WL_ERROR("%s: Error setting srl\n", __func__);
308                         err = -EIO;
309                         goto config_out;
310                 }
311                 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
312                     < 0) {
313                         WL_ERROR("%s: Error setting lrl\n", __func__);
314                         err = -EIO;
315                         goto config_out;
316                 }
317         }
318
319  config_out:
320         return err;
321 }
322
323 static void
324 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
325                         struct ieee80211_vif *vif,
326                         struct ieee80211_bss_conf *info, u32 changed)
327 {
328         struct wl_info *wl = HW_TO_WL(hw);
329         int val;
330
331
332         if (changed & BSS_CHANGED_ASSOC) {
333                 WL_ERROR("Associated:\t%s\n", info->assoc ? "True" : "False");
334                 /* association status changed (associated/disassociated)
335                  * also implies a change in the AID.
336                  */
337         }
338         if (changed & BSS_CHANGED_ERP_CTS_PROT) {
339                 WL_NONE("Use_cts_prot:\t%s Implement me\n",
340                         info->use_cts_prot ? "True" : "False");
341                 /* CTS protection changed */
342         }
343         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
344                 WL_NONE("Short preamble:\t%s Implement me\n",
345                         info->use_short_preamble ? "True" : "False");
346                 /* preamble changed */
347         }
348         if (changed & BSS_CHANGED_ERP_SLOT) {
349                 WL_NONE("Changing short slot:\t%s\n",
350                         info->use_short_slot ? "True" : "False");
351                 if (info->use_short_slot)
352                         val = 1;
353                 else
354                         val = 0;
355                 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
356                 /* slot timing changed */
357         }
358
359         if (changed & BSS_CHANGED_HT) {
360                 WL_NONE("%s: HT mode - Implement me\n", __func__);
361                 /* 802.11n parameters changed */
362         }
363         if (changed & BSS_CHANGED_BASIC_RATES) {
364                 WL_NONE("Need to change Basic Rates:\t0x%x! Implement me\n",
365                         (u32) info->basic_rates);
366                 /* Basic rateset changed */
367         }
368         if (changed & BSS_CHANGED_BEACON_INT) {
369                 WL_NONE("Beacon Interval:\t%d Implement me\n",
370                         info->beacon_int);
371                 /* Beacon interval changed */
372         }
373         if (changed & BSS_CHANGED_BSSID) {
374                 WL_NONE("new BSSID:\taid %d  bss:%pM\n",
375                         info->aid, info->bssid);
376                 /* BSSID changed, for whatever reason (IBSS and managed mode) */
377                 /* FIXME: need to store bssid in bsscfg */
378                 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
379                                   info->bssid);
380         }
381         if (changed & BSS_CHANGED_BEACON) {
382                 WL_ERROR("BSS_CHANGED_BEACON\n");
383                 /* Beacon data changed, retrieve new beacon (beaconing modes) */
384         }
385         if (changed & BSS_CHANGED_BEACON_ENABLED) {
386                 WL_ERROR("Beacon enabled:\t%s\n",
387                          info->enable_beacon ? "True" : "False");
388                 /* Beaconing should be enabled/disabled (beaconing modes) */
389         }
390         return;
391 }
392
393 static void
394 wl_ops_configure_filter(struct ieee80211_hw *hw,
395                         unsigned int changed_flags,
396                         unsigned int *total_flags, u64 multicast)
397 {
398         struct wl_info *wl = hw->priv;
399
400         changed_flags &= MAC_FILTERS;
401         *total_flags &= MAC_FILTERS;
402         if (changed_flags & FIF_PROMISC_IN_BSS)
403                 WL_ERROR("FIF_PROMISC_IN_BSS\n");
404         if (changed_flags & FIF_ALLMULTI)
405                 WL_ERROR("FIF_ALLMULTI\n");
406         if (changed_flags & FIF_FCSFAIL)
407                 WL_ERROR("FIF_FCSFAIL\n");
408         if (changed_flags & FIF_PLCPFAIL)
409                 WL_ERROR("FIF_PLCPFAIL\n");
410         if (changed_flags & FIF_CONTROL)
411                 WL_ERROR("FIF_CONTROL\n");
412         if (changed_flags & FIF_OTHER_BSS)
413                 WL_ERROR("FIF_OTHER_BSS\n");
414         if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
415                 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
416                 WL_LOCK(wl);
417                 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
418                         wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
419                         wlc_mac_bcn_promisc_change(wl->wlc, 1);
420                 } else {
421                         wlc_mac_bcn_promisc_change(wl->wlc, 0);
422                         wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
423                 }
424                 WL_UNLOCK(wl);
425         }
426         return;
427 }
428
429 static int
430 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
431 {
432         WL_ERROR("%s: Enter\n", __func__);
433         return 0;
434 }
435
436 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
437 {
438         WL_NONE("Scan Start\n");
439         return;
440 }
441
442 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
443 {
444         WL_NONE("Scan Complete\n");
445         return;
446 }
447
448 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
449 {
450         WL_ERROR("%s: Enter\n", __func__);
451         return;
452 }
453
454 static int
455 wl_ops_get_stats(struct ieee80211_hw *hw,
456                  struct ieee80211_low_level_stats *stats)
457 {
458         WL_ERROR("%s: Enter\n", __func__);
459         return 0;
460 }
461
462 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
463 {
464         struct wl_info *wl = hw->priv;
465
466         WL_LOCK(wl);
467         wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
468         WL_UNLOCK(wl);
469         return 0;
470 }
471
472 static void
473 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
474                   enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
475 {
476         WL_NONE("%s: Enter\n", __func__);
477         switch (cmd) {
478         default:
479                 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
480                 break;
481         }
482         return;
483 }
484
485 static int
486 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
487                const struct ieee80211_tx_queue_params *params)
488 {
489         struct wl_info *wl = hw->priv;
490
491         WL_NONE("%s: Enter (WME config)\n", __func__);
492         WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
493                  params->txop, params->cw_min, params->cw_max, params->aifs);
494
495         WL_LOCK(wl);
496         wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
497         WL_UNLOCK(wl);
498
499         return 0;
500 }
501
502 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
503 {
504         WL_ERROR("%s: Enter\n", __func__);
505         return 0;
506 }
507
508 static int
509 wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
510            struct ieee80211_sta *sta)
511 {
512         struct scb *scb;
513
514         int i;
515         struct wl_info *wl = hw->priv;
516
517         /* Init the scb */
518         scb = (struct scb *)sta->drv_priv;
519         memset(scb, 0, sizeof(struct scb));
520         for (i = 0; i < NUMPRIO; i++)
521                 scb->seqctl[i] = 0xFFFF;
522         scb->seqctl_nonqos = 0xFFFF;
523         scb->magic = SCB_MAGIC;
524
525         wl->pub->global_scb = scb;
526         wl->pub->global_ampdu = &(scb->scb_ampdu);
527         wl->pub->global_ampdu->scb = scb;
528         wl->pub->global_ampdu->max_pdu = 16;
529         pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
530                   AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
531
532         sta->ht_cap.ht_supported = true;
533         sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
534         sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
535         sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
536             IEEE80211_HT_CAP_SGI_20 |
537             IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
538
539         /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
540         return 0;
541 }
542
543 static int
544 wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
545               struct ieee80211_sta *sta)
546 {
547         WL_NONE("%s: Enter\n", __func__);
548         return 0;
549 }
550
551 static int
552 wl_ampdu_action(struct ieee80211_hw *hw,
553                 struct ieee80211_vif *vif,
554                 enum ieee80211_ampdu_mlme_action action,
555                 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
556 {
557 #if defined(BCMDBG)
558         struct scb *scb = (struct scb *)sta->drv_priv;
559 #endif
560         struct wl_info *wl = hw->priv;
561
562         ASSERT(scb->magic == SCB_MAGIC);
563         switch (action) {
564         case IEEE80211_AMPDU_RX_START:
565                 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
566                 break;
567         case IEEE80211_AMPDU_RX_STOP:
568                 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
569                 break;
570         case IEEE80211_AMPDU_TX_START:
571                 if (!wlc_aggregatable(wl->wlc, tid)) {
572                         /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
573                         return -1;
574                 }
575                 /* XXX: Use the starting sequence number provided ... */
576                 *ssn = 0;
577                 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
578                 break;
579
580         case IEEE80211_AMPDU_TX_STOP:
581                 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
582                 break;
583         case IEEE80211_AMPDU_TX_OPERATIONAL:
584                 /* Not sure what to do here */
585                 /* Power save wakeup */
586                 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
587                         __func__);
588                 break;
589         default:
590                 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
591         }
592
593         return 0;
594 }
595
596 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
597 {
598         struct wl_info *wl = HW_TO_WL(hw);
599         bool blocked;
600
601         WL_LOCK(wl);
602         blocked = wlc_check_radio_disabled(wl->wlc);
603         WL_UNLOCK(wl);
604
605         WL_ERROR("wl: rfkill_poll: %d\n", blocked);
606         wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
607 }
608
609 static const struct ieee80211_ops wl_ops = {
610         .tx = wl_ops_tx,
611         .start = wl_ops_start,
612         .stop = wl_ops_stop,
613         .add_interface = wl_ops_add_interface,
614         .remove_interface = wl_ops_remove_interface,
615         .config = wl_ops_config,
616         .bss_info_changed = wl_ops_bss_info_changed,
617         .configure_filter = wl_ops_configure_filter,
618         .set_tim = wl_ops_set_tim,
619         .sw_scan_start = wl_ops_sw_scan_start,
620         .sw_scan_complete = wl_ops_sw_scan_complete,
621         .set_tsf = wl_ops_set_tsf,
622         .get_stats = wl_ops_get_stats,
623         .set_rts_threshold = wl_ops_set_rts_threshold,
624         .sta_notify = wl_ops_sta_notify,
625         .conf_tx = wl_ops_conf_tx,
626         .get_tsf = wl_ops_get_tsf,
627         .sta_add = wl_sta_add,
628         .sta_remove = wl_sta_remove,
629         .ampdu_action = wl_ampdu_action,
630         .rfkill_poll = wl_ops_rfkill_poll,
631 };
632
633 static int wl_set_hint(struct wl_info *wl, char *abbrev)
634 {
635         WL_ERROR("%s: Sending country code %c%c to MAC80211\n",
636                  __func__, abbrev[0], abbrev[1]);
637         return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
638 }
639
640 /**
641  * attach to the WL device.
642  *
643  * Attach to the WL device identified by vendor and device parameters.
644  * regs is a host accessible memory address pointing to WL device registers.
645  *
646  * wl_attach is not defined as static because in the case where no bus
647  * is defined, wl_attach will never be called, and thus, gcc will issue
648  * a warning that this function is defined but not used if we declare
649  * it as static.
650  */
651 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
652                             uint bustype, void *btparam, uint irq)
653 {
654         struct wl_info *wl;
655         struct osl_info *osh;
656         int unit, err;
657
658         unsigned long base_addr;
659         struct ieee80211_hw *hw;
660         u8 perm[ETH_ALEN];
661
662         unit = wl_found;
663         err = 0;
664
665         if (unit < 0) {
666                 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
667                 return NULL;
668         }
669
670         osh = osl_attach(btparam, bustype);
671         ASSERT(osh);
672
673         /* allocate private info */
674         hw = pci_get_drvdata(btparam);  /* btparam == pdev */
675         wl = hw->priv;
676         ASSERT(wl);
677
678         wl->osh = osh;
679         atomic_set(&wl->callbacks, 0);
680
681         /* setup the bottom half handler */
682         tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
683
684
685
686         base_addr = regs;
687
688         if (bustype == PCI_BUS) {
689                 wl->piomode = false;
690         } else if (bustype == RPC_BUS) {
691                 /* Do nothing */
692         } else {
693                 bustype = PCI_BUS;
694                 WL_TRACE("force to PCI\n");
695         }
696         wl->bcm_bustype = bustype;
697
698         wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
699         if (wl->regsva == NULL) {
700                 WL_ERROR("wl%d: ioremap() failed\n", unit);
701                 goto fail;
702         }
703         spin_lock_init(&wl->lock);
704         spin_lock_init(&wl->isr_lock);
705
706         /* prepare ucode */
707         if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
708                 printf("%s: Failed to find firmware usually in %s\n",
709                         KBUILD_MODNAME, "/lib/firmware/brcm");
710                 wl_release_fw(wl);
711                 wl_remove((struct pci_dev *)btparam);
712                 goto fail1;
713         }
714
715         /* common load-time initialization */
716         wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
717                              wl->regsva, wl->bcm_bustype, btparam, &err);
718         wl_release_fw(wl);
719         if (!wl->wlc) {
720                 printf("%s: wlc_attach() failed with code %d\n",
721                         KBUILD_MODNAME, err);
722                 goto fail;
723         }
724         wl->pub = wlc_pub(wl->wlc);
725
726         wl->pub->ieee_hw = hw;
727         ASSERT(wl->pub->ieee_hw);
728         ASSERT(wl->pub->ieee_hw->priv == wl);
729
730
731         if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
732                 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
733         }
734
735         /* register our interrupt handler */
736         if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
737                 WL_ERROR("wl%d: request_irq() failed\n", unit);
738                 goto fail;
739         }
740         wl->irq = irq;
741
742         /* register module */
743         wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
744                             NULL);
745
746         if (ieee_hw_init(hw)) {
747                 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
748                 goto fail;
749         }
750
751         bcopy(&wl->pub->cur_etheraddr, perm, ETH_ALEN);
752         ASSERT(is_valid_ether_addr(perm));
753         SET_IEEE80211_PERM_ADDR(hw, perm);
754
755         err = ieee80211_register_hw(hw);
756         if (err) {
757                 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
758                          __func__, err);
759         }
760
761         if (wl->pub->srom_ccode[0])
762                 err = wl_set_hint(wl, wl->pub->srom_ccode);
763         else
764                 err = wl_set_hint(wl, "US");
765         if (err) {
766                 WL_ERROR("%s: regulatory_hint failed, status %d\n",
767                          __func__, err);
768         }
769
770         wl_found++;
771         return wl;
772
773 fail:
774         wl_free(wl);
775 fail1:
776         return NULL;
777 }
778
779
780
781 #define CHAN2GHZ(channel, freqency, chflags)  { \
782         .band = IEEE80211_BAND_2GHZ, \
783         .center_freq = (freqency), \
784         .hw_value = (channel), \
785         .flags = chflags, \
786         .max_antenna_gain = 0, \
787         .max_power = 19, \
788 }
789
790 static struct ieee80211_channel wl_2ghz_chantable[] = {
791         CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
792         CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
793         CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
794         CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
795         CHAN2GHZ(5, 2432, 0),
796         CHAN2GHZ(6, 2437, 0),
797         CHAN2GHZ(7, 2442, 0),
798         CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
799         CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
800         CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
801         CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
802         CHAN2GHZ(12, 2467,
803                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
804                  IEEE80211_CHAN_NO_HT40PLUS),
805         CHAN2GHZ(13, 2472,
806                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
807                  IEEE80211_CHAN_NO_HT40PLUS),
808         CHAN2GHZ(14, 2484,
809                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
810                  IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
811 };
812
813 #define CHAN5GHZ(channel, chflags)  { \
814         .band = IEEE80211_BAND_5GHZ, \
815         .center_freq = 5000 + 5*(channel), \
816         .hw_value = (channel), \
817         .flags = chflags, \
818         .max_antenna_gain = 0, \
819         .max_power = 21, \
820 }
821
822 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
823         /* UNII-1 */
824         CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
825         CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
826         CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
827         CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
828         /* UNII-2 */
829         CHAN5GHZ(52,
830                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
831                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
832         CHAN5GHZ(56,
833                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
834                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
835         CHAN5GHZ(60,
836                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
837                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
838         CHAN5GHZ(64,
839                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
840                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
841         /* MID */
842         CHAN5GHZ(100,
843                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
844                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
845         CHAN5GHZ(104,
846                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
847                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
848         CHAN5GHZ(108,
849                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
850                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
851         CHAN5GHZ(112,
852                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
853                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
854         CHAN5GHZ(116,
855                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
856                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
857         CHAN5GHZ(120,
858                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
859                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
860         CHAN5GHZ(124,
861                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
862                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
863         CHAN5GHZ(128,
864                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
865                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
866         CHAN5GHZ(132,
867                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
868                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
869         CHAN5GHZ(136,
870                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
871                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
872         CHAN5GHZ(140,
873                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
874                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
875                  IEEE80211_CHAN_NO_HT40MINUS),
876         /* UNII-3 */
877         CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
878         CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
879         CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
880         CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
881         CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
882 };
883
884 #define RATE(rate100m, _flags) { \
885         .bitrate = (rate100m), \
886         .flags = (_flags), \
887         .hw_value = (rate100m / 5), \
888 }
889
890 static struct ieee80211_rate wl_legacy_ratetable[] = {
891         RATE(10, 0),
892         RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
893         RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
894         RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
895         RATE(60, 0),
896         RATE(90, 0),
897         RATE(120, 0),
898         RATE(180, 0),
899         RATE(240, 0),
900         RATE(360, 0),
901         RATE(480, 0),
902         RATE(540, 0),
903 };
904
905 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
906         .band = IEEE80211_BAND_2GHZ,
907         .channels = wl_2ghz_chantable,
908         .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
909         .bitrates = wl_legacy_ratetable,
910         .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
911         .ht_cap = {
912                    /* from include/linux/ieee80211.h */
913                    .cap = IEEE80211_HT_CAP_GRN_FLD |
914                    IEEE80211_HT_CAP_SGI_20 |
915                    IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
916                    .ht_supported = true,
917                    .ampdu_factor = AMPDU_RX_FACTOR_64K,
918                    .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
919                    .mcs = {
920                            /* placeholders for now */
921                            .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
922                            .rx_highest = 500,
923                            .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
924                    }
925 };
926
927 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
928         .band = IEEE80211_BAND_5GHZ,
929         .channels = wl_5ghz_nphy_chantable,
930         .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
931         .bitrates = wl_legacy_ratetable + 4,
932         .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
933         .ht_cap = {
934                    /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
935                    .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,     /* No 40 mhz yet */
936                    .ht_supported = true,
937                    .ampdu_factor = AMPDU_RX_FACTOR_64K,
938                    .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
939                    .mcs = {
940                            /* placeholders for now */
941                            .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
942                            .rx_highest = 500,
943                            .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
944                    }
945 };
946
947 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
948 {
949         struct wl_info *wl = HW_TO_WL(hw);
950         int has_5g;
951         char phy_list[4];
952
953         has_5g = 0;
954
955         hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
956         hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
957
958         if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
959                 WL_ERROR("Phy list failed\n");
960         }
961         WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
962
963         if (phy_list[0] == 'n' || phy_list[0] == 'c') {
964                 if (phy_list[0] == 'c') {
965                         /* Single stream */
966                         wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
967                         wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
968                 }
969                 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
970         } else {
971                 BUG();
972                 return -1;
973         }
974
975         /* Assume all bands use the same phy.  True for 11n devices. */
976         if (NBANDS_PUB(wl->pub) > 1) {
977                 has_5g++;
978                 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
979                         hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
980                             &wl_band_5GHz_nphy;
981                 } else {
982                         return -1;
983                 }
984         }
985
986         WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
987
988         return 0;
989 }
990
991 static int ieee_hw_init(struct ieee80211_hw *hw)
992 {
993         hw->flags = IEEE80211_HW_SIGNAL_DBM
994             /* | IEEE80211_HW_CONNECTION_MONITOR  What is this? */
995             | IEEE80211_HW_REPORTS_TX_ACK_STATUS
996             | IEEE80211_HW_AMPDU_AGGREGATION;
997
998         hw->extra_tx_headroom = wlc_get_header_len();
999         /* FIXME: should get this from wlc->machwcap */
1000         hw->queues = 4;
1001         /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1002          * mac80211/status.c:ieee80211_tx_status() checks this value,
1003          * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1004          * appears to always set 3 rates
1005          */
1006         hw->max_rates = 2;      /* Primary rate and 1 fallback rate */
1007
1008         hw->channel_change_time = 7 * 1000;     /* channel change time is dependant on chip and band  */
1009         hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1010
1011         hw->rate_control_algorithm = "minstrel_ht";
1012
1013         hw->sta_data_size = sizeof(struct scb);
1014         return ieee_hw_rate_init(hw);
1015 }
1016
1017 /**
1018  * determines if a device is a WL device, and if so, attaches it.
1019  *
1020  * This function determines if a device pointed to by pdev is a WL device,
1021  * and if so, performs a wl_attach() on it.
1022  *
1023  */
1024 int __devinit
1025 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1026 {
1027         int rc;
1028         struct wl_info *wl;
1029         struct ieee80211_hw *hw;
1030         u32 val;
1031
1032         ASSERT(pdev);
1033
1034         WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1035                  __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1036                  PCI_FUNC(pdev->devfn), pdev->irq);
1037
1038         if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1039             (((pdev->device & 0xff00) != 0x4300) &&
1040              ((pdev->device & 0xff00) != 0x4700) &&
1041              ((pdev->device < 43000) || (pdev->device > 43999))))
1042                 return -ENODEV;
1043
1044         rc = pci_enable_device(pdev);
1045         if (rc) {
1046                 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1047                          __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1048                          PCI_FUNC(pdev->devfn));
1049                 return -ENODEV;
1050         }
1051         pci_set_master(pdev);
1052
1053         pci_read_config_dword(pdev, 0x40, &val);
1054         if ((val & 0x0000ff00) != 0)
1055                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1056
1057         hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1058         if (!hw) {
1059                 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1060                 rc = -ENOMEM;
1061                 goto err_1;
1062         }
1063
1064         SET_IEEE80211_DEV(hw, &pdev->dev);
1065
1066         pci_set_drvdata(pdev, hw);
1067
1068         memset(hw->priv, 0, sizeof(*wl));
1069
1070         wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1071                        PCI_BUS, pdev, pdev->irq);
1072
1073         if (!wl) {
1074                 WL_ERROR("%s: %s: wl_attach failed!\n",
1075                          KBUILD_MODNAME, __func__);
1076                 return -ENODEV;
1077         }
1078         return 0;
1079  err_1:
1080         WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1081         return 0;
1082 }
1083
1084 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1085 {
1086         struct wl_info *wl;
1087         struct ieee80211_hw *hw;
1088
1089         WL_TRACE("wl: wl_suspend\n");
1090
1091         hw = pci_get_drvdata(pdev);
1092         wl = HW_TO_WL(hw);
1093         if (!wl) {
1094                 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1095                 return -ENODEV;
1096         }
1097
1098         /* only need to flag hw is down for proper resume */
1099         WL_LOCK(wl);
1100         wl->pub->hw_up = false;
1101         WL_UNLOCK(wl);
1102
1103         pci_save_state(pdev);
1104         pci_disable_device(pdev);
1105         return pci_set_power_state(pdev, PCI_D3hot);
1106 }
1107
1108 static int wl_resume(struct pci_dev *pdev)
1109 {
1110         struct wl_info *wl;
1111         struct ieee80211_hw *hw;
1112         int err = 0;
1113         u32 val;
1114
1115         WL_TRACE("wl: wl_resume\n");
1116         hw = pci_get_drvdata(pdev);
1117         wl = HW_TO_WL(hw);
1118         if (!wl) {
1119                 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1120                 return -ENODEV;
1121         }
1122
1123         err = pci_set_power_state(pdev, PCI_D0);
1124         if (err)
1125                 return err;
1126
1127         pci_restore_state(pdev);
1128
1129         err = pci_enable_device(pdev);
1130         if (err)
1131                 return err;
1132
1133         pci_set_master(pdev);
1134
1135         pci_read_config_dword(pdev, 0x40, &val);
1136         if ((val & 0x0000ff00) != 0)
1137                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1138
1139         /*
1140         *  done. driver will be put in up state
1141         *  in wl_ops_add_interface() call.
1142         */
1143         return err;
1144 }
1145
1146 static void wl_remove(struct pci_dev *pdev)
1147 {
1148         struct wl_info *wl;
1149         struct ieee80211_hw *hw;
1150
1151         hw = pci_get_drvdata(pdev);
1152         wl = HW_TO_WL(hw);
1153         if (!wl) {
1154                 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1155                 return;
1156         }
1157
1158         /* make sure rfkill is not using driver */
1159         wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1160         wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1161
1162         if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1163                 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1164                 return;
1165         }
1166         if (wl->wlc) {
1167                 ieee80211_unregister_hw(hw);
1168                 WL_LOCK(wl);
1169                 wl_down(wl);
1170                 WL_UNLOCK(wl);
1171                 WL_NONE("%s: Down\n", __func__);
1172         }
1173         pci_disable_device(pdev);
1174
1175         wl_free(wl);
1176
1177         pci_set_drvdata(pdev, NULL);
1178         ieee80211_free_hw(hw);
1179 }
1180
1181 static struct pci_driver wl_pci_driver = {
1182         .name     = KBUILD_MODNAME,
1183         .probe    = wl_pci_probe,
1184         .suspend  = wl_suspend,
1185         .resume   = wl_resume,
1186         .remove   = __devexit_p(wl_remove),
1187         .id_table = wl_id_table,
1188 };
1189
1190 /**
1191  * This is the main entry point for the WL driver.
1192  *
1193  * This function determines if a device pointed to by pdev is a WL device,
1194  * and if so, performs a wl_attach() on it.
1195  *
1196  */
1197 static int __init wl_module_init(void)
1198 {
1199         int error = -ENODEV;
1200
1201 #ifdef BCMDBG
1202         if (msglevel != 0xdeadbeef)
1203                 wl_msg_level = msglevel;
1204         else {
1205                 char *var = getvar(NULL, "wl_msglevel");
1206                 if (var)
1207                         wl_msg_level = simple_strtoul(var, NULL, 0);
1208         }
1209         {
1210                 extern u32 phyhal_msg_level;
1211
1212                 if (phymsglevel != 0xdeadbeef)
1213                         phyhal_msg_level = phymsglevel;
1214                 else {
1215                         char *var = getvar(NULL, "phy_msglevel");
1216                         if (var)
1217                                 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1218                 }
1219         }
1220 #endif                          /* BCMDBG */
1221
1222         error = pci_register_driver(&wl_pci_driver);
1223         if (!error)
1224                 return 0;
1225
1226
1227
1228         return error;
1229 }
1230
1231 /**
1232  * This function unloads the WL driver from the system.
1233  *
1234  * This function unconditionally unloads the WL driver module from the
1235  * system.
1236  *
1237  */
1238 static void __exit wl_module_exit(void)
1239 {
1240         pci_unregister_driver(&wl_pci_driver);
1241
1242 }
1243
1244 module_init(wl_module_init);
1245 module_exit(wl_module_exit);
1246
1247 /**
1248  * This function frees the WL per-device resources.
1249  *
1250  * This function frees resources owned by the WL device pointed to
1251  * by the wl parameter.
1252  *
1253  */
1254 void wl_free(struct wl_info *wl)
1255 {
1256         wl_timer_t *t, *next;
1257         struct osl_info *osh;
1258
1259         ASSERT(wl);
1260         /* free ucode data */
1261         if (wl->fw.fw_cnt)
1262                 wl_ucode_data_free();
1263         if (wl->irq)
1264                 free_irq(wl->irq, wl);
1265
1266         /* kill dpc */
1267         tasklet_kill(&wl->tasklet);
1268
1269         if (wl->pub) {
1270                 wlc_module_unregister(wl->pub, "linux", wl);
1271         }
1272
1273         /* free common resources */
1274         if (wl->wlc) {
1275                 wlc_detach(wl->wlc);
1276                 wl->wlc = NULL;
1277                 wl->pub = NULL;
1278         }
1279
1280         /* virtual interface deletion is deferred so we cannot spinwait */
1281
1282         /* wait for all pending callbacks to complete */
1283         while (atomic_read(&wl->callbacks) > 0)
1284                 schedule();
1285
1286         /* free timers */
1287         for (t = wl->timers; t; t = next) {
1288                 next = t->next;
1289 #ifdef BCMDBG
1290                 if (t->name)
1291                         kfree(t->name);
1292 #endif
1293                 kfree(t);
1294         }
1295
1296         osh = wl->osh;
1297
1298         /*
1299          * unregister_netdev() calls get_stats() which may read chip registers
1300          * so we cannot unmap the chip registers until after calling unregister_netdev() .
1301          */
1302         if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1303             wl->bcm_bustype != JTAG_BUS) {
1304                 iounmap((void *)wl->regsva);
1305         }
1306         wl->regsva = NULL;
1307
1308
1309         osl_detach(osh);
1310 }
1311
1312 /* transmit a packet */
1313 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1314 {
1315         if (!wl)
1316                 return -ENETDOWN;
1317
1318         return wl_start_int(wl, WL_TO_HW(wl), skb);
1319 }
1320
1321 static int BCMFASTPATH
1322 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1323 {
1324         wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1325         return NETDEV_TX_OK;
1326 }
1327
1328 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1329                       int prio)
1330 {
1331         WL_ERROR("Shouldn't be here %s\n", __func__);
1332 }
1333
1334 void wl_init(struct wl_info *wl)
1335 {
1336         WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1337
1338         wl_reset(wl);
1339
1340         wlc_init(wl->wlc);
1341 }
1342
1343 uint wl_reset(struct wl_info *wl)
1344 {
1345         WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1346
1347         wlc_reset(wl->wlc);
1348
1349         /* dpc will not be rescheduled */
1350         wl->resched = 0;
1351
1352         return 0;
1353 }
1354
1355 /*
1356  * These are interrupt on/off entry points. Disable interrupts
1357  * during interrupt state transition.
1358  */
1359 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1360 {
1361         unsigned long flags;
1362
1363         INT_LOCK(wl, flags);
1364         wlc_intrson(wl->wlc);
1365         INT_UNLOCK(wl, flags);
1366 }
1367
1368 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1369 {
1370         return true;
1371 }
1372
1373 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1374 {
1375         unsigned long flags;
1376         u32 status;
1377
1378         INT_LOCK(wl, flags);
1379         status = wlc_intrsoff(wl->wlc);
1380         INT_UNLOCK(wl, flags);
1381         return status;
1382 }
1383
1384 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1385 {
1386         unsigned long flags;
1387
1388         INT_LOCK(wl, flags);
1389         wlc_intrsrestore(wl->wlc, macintmask);
1390         INT_UNLOCK(wl, flags);
1391 }
1392
1393 int wl_up(struct wl_info *wl)
1394 {
1395         int error = 0;
1396
1397         if (wl->pub->up)
1398                 return 0;
1399
1400         error = wlc_up(wl->wlc);
1401
1402         return error;
1403 }
1404
1405 void wl_down(struct wl_info *wl)
1406 {
1407         uint callbacks, ret_val = 0;
1408
1409         /* call common down function */
1410         ret_val = wlc_down(wl->wlc);
1411         callbacks = atomic_read(&wl->callbacks) - ret_val;
1412
1413         /* wait for down callbacks to complete */
1414         WL_UNLOCK(wl);
1415
1416         /* For HIGH_only driver, it's important to actually schedule other work,
1417          * not just spin wait since everything runs at schedule level
1418          */
1419         SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1420
1421         WL_LOCK(wl);
1422 }
1423
1424 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1425 {
1426         struct wl_info *wl;
1427         bool ours, wantdpc;
1428         unsigned long flags;
1429
1430         wl = (struct wl_info *) dev_id;
1431
1432         WL_ISRLOCK(wl, flags);
1433
1434         /* call common first level interrupt handler */
1435         ours = wlc_isr(wl->wlc, &wantdpc);
1436         if (ours) {
1437                 /* if more to do... */
1438                 if (wantdpc) {
1439
1440                         /* ...and call the second level interrupt handler */
1441                         /* schedule dpc */
1442                         ASSERT(wl->resched == false);
1443                         tasklet_schedule(&wl->tasklet);
1444                 }
1445         }
1446
1447         WL_ISRUNLOCK(wl, flags);
1448
1449         return IRQ_RETVAL(ours);
1450 }
1451
1452 static void BCMFASTPATH wl_dpc(unsigned long data)
1453 {
1454         struct wl_info *wl;
1455
1456         wl = (struct wl_info *) data;
1457
1458         WL_LOCK(wl);
1459
1460         /* call the common second level interrupt handler */
1461         if (wl->pub->up) {
1462                 if (wl->resched) {
1463                         unsigned long flags;
1464
1465                         INT_LOCK(wl, flags);
1466                         wlc_intrsupd(wl->wlc);
1467                         INT_UNLOCK(wl, flags);
1468                 }
1469
1470                 wl->resched = wlc_dpc(wl->wlc, true);
1471         }
1472
1473         /* wlc_dpc() may bring the driver down */
1474         if (!wl->pub->up)
1475                 goto done;
1476
1477         /* re-schedule dpc */
1478         if (wl->resched)
1479                 tasklet_schedule(&wl->tasklet);
1480         else {
1481                 /* re-enable interrupts */
1482                 wl_intrson(wl);
1483         }
1484
1485  done:
1486         WL_UNLOCK(wl);
1487 }
1488
1489 static void wl_link_up(struct wl_info *wl, char *ifname)
1490 {
1491         WL_ERROR("wl%d: link up (%s)\n", wl->pub->unit, ifname);
1492 }
1493
1494 static void wl_link_down(struct wl_info *wl, char *ifname)
1495 {
1496         WL_ERROR("wl%d: link down (%s)\n", wl->pub->unit, ifname);
1497 }
1498
1499 void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
1500 {
1501
1502         switch (e->event.event_type) {
1503         case WLC_E_LINK:
1504         case WLC_E_NDIS_LINK:
1505                 if (e->event.flags & WLC_EVENT_MSG_LINK)
1506                         wl_link_up(wl, ifname);
1507                 else
1508                         wl_link_down(wl, ifname);
1509                 break;
1510         case WLC_E_RADIO:
1511                 break;
1512         }
1513 }
1514
1515 static void wl_timer(unsigned long data)
1516 {
1517         _wl_timer((wl_timer_t *) data);
1518 }
1519
1520 static void _wl_timer(wl_timer_t *t)
1521 {
1522         WL_LOCK(t->wl);
1523
1524         if (t->set) {
1525                 if (t->periodic) {
1526                         t->timer.expires = jiffies + t->ms * HZ / 1000;
1527                         atomic_inc(&t->wl->callbacks);
1528                         add_timer(&t->timer);
1529                         t->set = true;
1530                 } else
1531                         t->set = false;
1532
1533                 t->fn(t->arg);
1534         }
1535
1536         atomic_dec(&t->wl->callbacks);
1537
1538         WL_UNLOCK(t->wl);
1539 }
1540
1541 wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1542                           const char *name)
1543 {
1544         wl_timer_t *t;
1545
1546         t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1547         if (!t) {
1548                 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1549                 return 0;
1550         }
1551
1552         memset(t, 0, sizeof(wl_timer_t));
1553
1554         init_timer(&t->timer);
1555         t->timer.data = (unsigned long) t;
1556         t->timer.function = wl_timer;
1557         t->wl = wl;
1558         t->fn = fn;
1559         t->arg = arg;
1560         t->next = wl->timers;
1561         wl->timers = t;
1562
1563 #ifdef BCMDBG
1564         t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1565         if (t->name)
1566                 strcpy(t->name, name);
1567 #endif
1568
1569         return t;
1570 }
1571
1572 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1573  * as well as it's easier to make it periodic
1574  */
1575 void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1576 {
1577 #ifdef BCMDBG
1578         if (t->set) {
1579                 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1580                          __func__, t->name, periodic);
1581         }
1582 #endif
1583         ASSERT(!t->set);
1584
1585         t->ms = ms;
1586         t->periodic = (bool) periodic;
1587         t->set = true;
1588         t->timer.expires = jiffies + ms * HZ / 1000;
1589
1590         atomic_inc(&wl->callbacks);
1591         add_timer(&t->timer);
1592 }
1593
1594 /* return true if timer successfully deleted, false if still pending */
1595 bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1596 {
1597         if (t->set) {
1598                 t->set = false;
1599                 if (!del_timer(&t->timer)) {
1600                         return false;
1601                 }
1602                 atomic_dec(&wl->callbacks);
1603         }
1604
1605         return true;
1606 }
1607
1608 void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1609 {
1610         wl_timer_t *tmp;
1611
1612         /* delete the timer in case it is active */
1613         wl_del_timer(wl, t);
1614
1615         if (wl->timers == t) {
1616                 wl->timers = wl->timers->next;
1617 #ifdef BCMDBG
1618                 if (t->name)
1619                         kfree(t->name);
1620 #endif
1621                 kfree(t);
1622                 return;
1623
1624         }
1625
1626         tmp = wl->timers;
1627         while (tmp) {
1628                 if (tmp->next == t) {
1629                         tmp->next = t->next;
1630 #ifdef BCMDBG
1631                         if (t->name)
1632                                 kfree(t->name);
1633 #endif
1634                         kfree(t);
1635                         return;
1636                 }
1637                 tmp = tmp->next;
1638         }
1639
1640 }
1641
1642 static int wl_linux_watchdog(void *ctx)
1643 {
1644         struct wl_info *wl = (struct wl_info *) ctx;
1645         struct net_device_stats *stats = NULL;
1646         uint id;
1647         /* refresh stats */
1648         if (wl->pub->up) {
1649                 ASSERT(wl->stats_id < 2);
1650
1651                 id = 1 - wl->stats_id;
1652
1653                 stats = &wl->stats_watchdog[id];
1654                 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
1655                 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
1656                 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
1657                 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
1658                 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
1659                 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
1660                 stats->collisions = 0;
1661
1662                 stats->rx_length_errors = 0;
1663                 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1664                 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
1665                 stats->rx_frame_errors = 0;
1666                 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1667                 stats->rx_missed_errors = 0;
1668
1669                 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
1670
1671                 wl->stats_id = id;
1672
1673         }
1674
1675         return 0;
1676 }
1677
1678 struct wl_fw_hdr {
1679         u32 offset;
1680         u32 len;
1681         u32 idx;
1682 };
1683
1684 char *wl_firmwares[WL_MAX_FW] = {
1685         "brcm/bcm43xx",
1686         NULL
1687 };
1688
1689 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1690 {
1691         int i, entry;
1692         const u8 *pdata;
1693         struct wl_fw_hdr *hdr;
1694         for (i = 0; i < wl->fw.fw_cnt; i++) {
1695                 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1696                 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1697                      entry++, hdr++) {
1698                         if (hdr->idx == idx) {
1699                                 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1700                                 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1701                                 if (*pbuf == NULL) {
1702                                         printf("fail to alloc %d bytes\n",
1703                                                hdr->len);
1704                                 }
1705                                 bcopy(pdata, *pbuf, hdr->len);
1706                                 return 0;
1707                         }
1708                 }
1709         }
1710         printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
1711         *pbuf = NULL;
1712         return -1;
1713 }
1714
1715 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1716 {
1717         int i, entry;
1718         const u8 *pdata;
1719         struct wl_fw_hdr *hdr;
1720         for (i = 0; i < wl->fw.fw_cnt; i++) {
1721                 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1722                 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1723                      entry++, hdr++) {
1724                         if (hdr->idx == idx) {
1725                                 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1726                                 ASSERT(hdr->len == 4);
1727                                 *data = *((u32 *) pdata);
1728                                 return 0;
1729                         }
1730                 }
1731         }
1732         printf("ERROR: ucode tag:%d can not be found!\n", idx);
1733         return -1;
1734 }
1735
1736 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1737 {
1738         int status;
1739         struct device *device = &pdev->dev;
1740         char fw_name[100];
1741         int i;
1742
1743         memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1744         for (i = 0; i < WL_MAX_FW; i++) {
1745                 if (wl_firmwares[i] == NULL)
1746                         break;
1747                 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1748                         UCODE_LOADER_API_VER);
1749                 WL_NONE("request fw %s\n", fw_name);
1750                 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1751                 if (status) {
1752                         printf("%s: fail to load firmware %s\n",
1753                                 KBUILD_MODNAME, fw_name);
1754                         wl_release_fw(wl);
1755                         return status;
1756                 }
1757                 WL_NONE("request fw %s\n", fw_name);
1758                 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1759                         UCODE_LOADER_API_VER);
1760                 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1761                 if (status) {
1762                         printf("%s: fail to load firmware %s\n",
1763                                 KBUILD_MODNAME, fw_name);
1764                         wl_release_fw(wl);
1765                         return status;
1766                 }
1767                 wl->fw.hdr_num_entries[i] =
1768                     wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1769                 WL_NONE("request fw %s find: %d entries\n",
1770                         fw_name, wl->fw.hdr_num_entries[i]);
1771         }
1772         wl->fw.fw_cnt = i;
1773         return wl_ucode_data_init(wl);
1774 }
1775
1776 void wl_ucode_free_buf(void *p)
1777 {
1778         kfree(p);
1779 }
1780
1781 static void wl_release_fw(struct wl_info *wl)
1782 {
1783         int i;
1784         for (i = 0; i < WL_MAX_FW; i++) {
1785                 release_firmware(wl->fw.fw_bin[i]);
1786                 release_firmware(wl->fw.fw_hdr[i]);
1787         }
1788 }
1789
1790
1791 /*
1792  * checks validity of all firmware images loaded from user space
1793  */
1794 int wl_check_firmwares(struct wl_info *wl)
1795 {
1796         int i;
1797         int entry;
1798         int rc = 0;
1799         const struct firmware *fw;
1800         const struct firmware *fw_hdr;
1801         struct wl_fw_hdr *ucode_hdr;
1802         for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1803                 fw =  wl->fw.fw_bin[i];
1804                 fw_hdr = wl->fw.fw_hdr[i];
1805                 if (fw == NULL && fw_hdr == NULL) {
1806                         break;
1807                 } else if (fw == NULL || fw_hdr == NULL) {
1808                         WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1809                         rc = -EBADF;
1810                 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1811                         WL_ERROR("%s: non integral fw hdr file size %d/%zu\n",
1812                                  __func__, fw_hdr->size,
1813                                  sizeof(struct wl_fw_hdr));
1814                         rc = -EBADF;
1815                 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1816                         WL_ERROR("%s: out of bounds fw file size %d\n",
1817                                  __func__, fw->size);
1818                         rc = -EBADF;
1819                 } else {
1820                         /* check if ucode section overruns firmware image */
1821                         ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1822                         for (entry = 0; entry < wl->fw.hdr_num_entries[i] && rc;
1823                              entry++, ucode_hdr++) {
1824                                 if (ucode_hdr->offset + ucode_hdr->len >
1825                                     fw->size) {
1826                                         WL_ERROR("%s: conflicting bin/hdr\n",
1827                                                  __func__);
1828                                         rc = -EBADF;
1829                                 }
1830                         }
1831                 }
1832         }
1833         if (rc == 0 && wl->fw.fw_cnt != i) {
1834                 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1835                 rc = -EBADF;
1836         }
1837         return rc;
1838 }
1839
1840 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1841 {
1842         bool blocked = wlc_check_radio_disabled(wl->wlc);
1843
1844         WL_ERROR("%s: update hw state: blocked=%s\n", __func__, blocked ? "true" : "false");
1845         wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1846         if (blocked)
1847                 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1848         return blocked;
1849 }