staging: brcm80211: remove driver message upon initialization
[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         WL_ERROR("%s: Enter\n", __func__);
465         return 0;
466 }
467
468 static void
469 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
470                   enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
471 {
472         WL_NONE("%s: Enter\n", __func__);
473         switch (cmd) {
474         default:
475                 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
476                 break;
477         }
478         return;
479 }
480
481 static int
482 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
483                const struct ieee80211_tx_queue_params *params)
484 {
485         struct wl_info *wl = hw->priv;
486
487         WL_NONE("%s: Enter (WME config)\n", __func__);
488         WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
489                  params->txop, params->cw_min, params->cw_max, params->aifs);
490
491         WL_LOCK(wl);
492         wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
493         WL_UNLOCK(wl);
494
495         return 0;
496 }
497
498 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
499 {
500         WL_ERROR("%s: Enter\n", __func__);
501         return 0;
502 }
503
504 static int
505 wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
506            struct ieee80211_sta *sta)
507 {
508         struct scb *scb;
509
510         int i;
511         struct wl_info *wl = hw->priv;
512
513         /* Init the scb */
514         scb = (struct scb *)sta->drv_priv;
515         memset(scb, 0, sizeof(struct scb));
516         for (i = 0; i < NUMPRIO; i++)
517                 scb->seqctl[i] = 0xFFFF;
518         scb->seqctl_nonqos = 0xFFFF;
519         scb->magic = SCB_MAGIC;
520
521         wl->pub->global_scb = scb;
522         wl->pub->global_ampdu = &(scb->scb_ampdu);
523         wl->pub->global_ampdu->scb = scb;
524         wl->pub->global_ampdu->max_pdu = 16;
525         pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
526                   AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
527
528         sta->ht_cap.ht_supported = true;
529         sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
530         sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
531         sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
532             IEEE80211_HT_CAP_SGI_20 |
533             IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
534
535         /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
536         return 0;
537 }
538
539 static int
540 wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
541               struct ieee80211_sta *sta)
542 {
543         WL_NONE("%s: Enter\n", __func__);
544         return 0;
545 }
546
547 static int
548 wl_ampdu_action(struct ieee80211_hw *hw,
549                 struct ieee80211_vif *vif,
550                 enum ieee80211_ampdu_mlme_action action,
551                 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
552 {
553 #if defined(BCMDBG)
554         struct scb *scb = (struct scb *)sta->drv_priv;
555 #endif
556         struct wl_info *wl = hw->priv;
557
558         ASSERT(scb->magic == SCB_MAGIC);
559         switch (action) {
560         case IEEE80211_AMPDU_RX_START:
561                 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
562                 break;
563         case IEEE80211_AMPDU_RX_STOP:
564                 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
565                 break;
566         case IEEE80211_AMPDU_TX_START:
567                 if (!wlc_aggregatable(wl->wlc, tid)) {
568                         /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
569                         return -1;
570                 }
571                 /* XXX: Use the starting sequence number provided ... */
572                 *ssn = 0;
573                 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
574                 break;
575
576         case IEEE80211_AMPDU_TX_STOP:
577                 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
578                 break;
579         case IEEE80211_AMPDU_TX_OPERATIONAL:
580                 /* Not sure what to do here */
581                 /* Power save wakeup */
582                 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
583                         __func__);
584                 break;
585         default:
586                 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
587         }
588
589         return 0;
590 }
591
592 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
593 {
594         struct wl_info *wl = HW_TO_WL(hw);
595         bool blocked;
596
597         WL_LOCK(wl);
598         blocked = wlc_check_radio_disabled(wl->wlc);
599         WL_UNLOCK(wl);
600
601         WL_ERROR("wl: rfkill_poll: %d\n", blocked);
602         wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
603 }
604
605 static const struct ieee80211_ops wl_ops = {
606         .tx = wl_ops_tx,
607         .start = wl_ops_start,
608         .stop = wl_ops_stop,
609         .add_interface = wl_ops_add_interface,
610         .remove_interface = wl_ops_remove_interface,
611         .config = wl_ops_config,
612         .bss_info_changed = wl_ops_bss_info_changed,
613         .configure_filter = wl_ops_configure_filter,
614         .set_tim = wl_ops_set_tim,
615         .sw_scan_start = wl_ops_sw_scan_start,
616         .sw_scan_complete = wl_ops_sw_scan_complete,
617         .set_tsf = wl_ops_set_tsf,
618         .get_stats = wl_ops_get_stats,
619         .set_rts_threshold = wl_ops_set_rts_threshold,
620         .sta_notify = wl_ops_sta_notify,
621         .conf_tx = wl_ops_conf_tx,
622         .get_tsf = wl_ops_get_tsf,
623         .sta_add = wl_sta_add,
624         .sta_remove = wl_sta_remove,
625         .ampdu_action = wl_ampdu_action,
626         .rfkill_poll = wl_ops_rfkill_poll,
627 };
628
629 static int wl_set_hint(struct wl_info *wl, char *abbrev)
630 {
631         WL_ERROR("%s: Sending country code %c%c to MAC80211\n",
632                  __func__, abbrev[0], abbrev[1]);
633         return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
634 }
635
636 /**
637  * attach to the WL device.
638  *
639  * Attach to the WL device identified by vendor and device parameters.
640  * regs is a host accessible memory address pointing to WL device registers.
641  *
642  * wl_attach is not defined as static because in the case where no bus
643  * is defined, wl_attach will never be called, and thus, gcc will issue
644  * a warning that this function is defined but not used if we declare
645  * it as static.
646  */
647 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
648                             uint bustype, void *btparam, uint irq)
649 {
650         struct wl_info *wl;
651         struct osl_info *osh;
652         int unit, err;
653
654         unsigned long base_addr;
655         struct ieee80211_hw *hw;
656         u8 perm[ETH_ALEN];
657
658         unit = wl_found;
659         err = 0;
660
661         if (unit < 0) {
662                 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
663                 return NULL;
664         }
665
666         osh = osl_attach(btparam, bustype);
667         ASSERT(osh);
668
669         /* allocate private info */
670         hw = pci_get_drvdata(btparam);  /* btparam == pdev */
671         wl = hw->priv;
672         ASSERT(wl);
673
674         wl->osh = osh;
675         atomic_set(&wl->callbacks, 0);
676
677         /* setup the bottom half handler */
678         tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
679
680
681
682         base_addr = regs;
683
684         if (bustype == PCI_BUS) {
685                 wl->piomode = false;
686         } else if (bustype == RPC_BUS) {
687                 /* Do nothing */
688         } else {
689                 bustype = PCI_BUS;
690                 WL_TRACE("force to PCI\n");
691         }
692         wl->bcm_bustype = bustype;
693
694         wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
695         if (wl->regsva == NULL) {
696                 WL_ERROR("wl%d: ioremap() failed\n", unit);
697                 goto fail;
698         }
699         spin_lock_init(&wl->lock);
700         spin_lock_init(&wl->isr_lock);
701
702         /* prepare ucode */
703         if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
704                 printf("%s: Failed to find firmware usually in %s\n",
705                         KBUILD_MODNAME, "/lib/firmware/brcm");
706                 wl_release_fw(wl);
707                 wl_remove((struct pci_dev *)btparam);
708                 goto fail1;
709         }
710
711         /* common load-time initialization */
712         wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
713                              wl->regsva, wl->bcm_bustype, btparam, &err);
714         wl_release_fw(wl);
715         if (!wl->wlc) {
716                 printf("%s: wlc_attach() failed with code %d\n",
717                         KBUILD_MODNAME, err);
718                 goto fail;
719         }
720         wl->pub = wlc_pub(wl->wlc);
721
722         wl->pub->ieee_hw = hw;
723         ASSERT(wl->pub->ieee_hw);
724         ASSERT(wl->pub->ieee_hw->priv == wl);
725
726
727         if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
728                 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
729         }
730
731         /* register our interrupt handler */
732         if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
733                 WL_ERROR("wl%d: request_irq() failed\n", unit);
734                 goto fail;
735         }
736         wl->irq = irq;
737
738         /* register module */
739         wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
740                             NULL);
741
742         if (ieee_hw_init(hw)) {
743                 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
744                 goto fail;
745         }
746
747         bcopy(&wl->pub->cur_etheraddr, perm, ETH_ALEN);
748         ASSERT(is_valid_ether_addr(perm));
749         SET_IEEE80211_PERM_ADDR(hw, perm);
750
751         err = ieee80211_register_hw(hw);
752         if (err) {
753                 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
754                          __func__, err);
755         }
756
757         if (wl->pub->srom_ccode[0])
758                 err = wl_set_hint(wl, wl->pub->srom_ccode);
759         else
760                 err = wl_set_hint(wl, "US");
761         if (err) {
762                 WL_ERROR("%s: regulatory_hint failed, status %d\n",
763                          __func__, err);
764         }
765
766         wl_found++;
767         return wl;
768
769 fail:
770         wl_free(wl);
771 fail1:
772         return NULL;
773 }
774
775
776
777 #define CHAN2GHZ(channel, freqency, chflags)  { \
778         .band = IEEE80211_BAND_2GHZ, \
779         .center_freq = (freqency), \
780         .hw_value = (channel), \
781         .flags = chflags, \
782         .max_antenna_gain = 0, \
783         .max_power = 19, \
784 }
785
786 static struct ieee80211_channel wl_2ghz_chantable[] = {
787         CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
788         CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
789         CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
790         CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
791         CHAN2GHZ(5, 2432, 0),
792         CHAN2GHZ(6, 2437, 0),
793         CHAN2GHZ(7, 2442, 0),
794         CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
795         CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
796         CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
797         CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
798         CHAN2GHZ(12, 2467,
799                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
800                  IEEE80211_CHAN_NO_HT40PLUS),
801         CHAN2GHZ(13, 2472,
802                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
803                  IEEE80211_CHAN_NO_HT40PLUS),
804         CHAN2GHZ(14, 2484,
805                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
806                  IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
807 };
808
809 #define CHAN5GHZ(channel, chflags)  { \
810         .band = IEEE80211_BAND_5GHZ, \
811         .center_freq = 5000 + 5*(channel), \
812         .hw_value = (channel), \
813         .flags = chflags, \
814         .max_antenna_gain = 0, \
815         .max_power = 21, \
816 }
817
818 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
819         /* UNII-1 */
820         CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
821         CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
822         CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
823         CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
824         /* UNII-2 */
825         CHAN5GHZ(52,
826                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
827                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
828         CHAN5GHZ(56,
829                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
830                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
831         CHAN5GHZ(60,
832                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
833                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
834         CHAN5GHZ(64,
835                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
836                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
837         /* MID */
838         CHAN5GHZ(100,
839                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
840                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
841         CHAN5GHZ(104,
842                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
843                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
844         CHAN5GHZ(108,
845                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
846                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
847         CHAN5GHZ(112,
848                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
849                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
850         CHAN5GHZ(116,
851                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
852                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
853         CHAN5GHZ(120,
854                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
855                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
856         CHAN5GHZ(124,
857                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
858                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
859         CHAN5GHZ(128,
860                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
861                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
862         CHAN5GHZ(132,
863                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
864                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
865         CHAN5GHZ(136,
866                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
867                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
868         CHAN5GHZ(140,
869                  IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
870                  IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
871                  IEEE80211_CHAN_NO_HT40MINUS),
872         /* UNII-3 */
873         CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
874         CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
875         CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
876         CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
877         CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
878 };
879
880 #define RATE(rate100m, _flags) { \
881         .bitrate = (rate100m), \
882         .flags = (_flags), \
883         .hw_value = (rate100m / 5), \
884 }
885
886 static struct ieee80211_rate wl_legacy_ratetable[] = {
887         RATE(10, 0),
888         RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
889         RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
890         RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
891         RATE(60, 0),
892         RATE(90, 0),
893         RATE(120, 0),
894         RATE(180, 0),
895         RATE(240, 0),
896         RATE(360, 0),
897         RATE(480, 0),
898         RATE(540, 0),
899 };
900
901 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
902         .band = IEEE80211_BAND_2GHZ,
903         .channels = wl_2ghz_chantable,
904         .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
905         .bitrates = wl_legacy_ratetable,
906         .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
907         .ht_cap = {
908                    /* from include/linux/ieee80211.h */
909                    .cap = IEEE80211_HT_CAP_GRN_FLD |
910                    IEEE80211_HT_CAP_SGI_20 |
911                    IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
912                    .ht_supported = true,
913                    .ampdu_factor = AMPDU_RX_FACTOR_64K,
914                    .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
915                    .mcs = {
916                            /* placeholders for now */
917                            .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
918                            .rx_highest = 500,
919                            .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
920                    }
921 };
922
923 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
924         .band = IEEE80211_BAND_5GHZ,
925         .channels = wl_5ghz_nphy_chantable,
926         .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
927         .bitrates = wl_legacy_ratetable + 4,
928         .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
929         .ht_cap = {
930                    /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
931                    .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 */
932                    .ht_supported = true,
933                    .ampdu_factor = AMPDU_RX_FACTOR_64K,
934                    .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
935                    .mcs = {
936                            /* placeholders for now */
937                            .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
938                            .rx_highest = 500,
939                            .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
940                    }
941 };
942
943 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
944 {
945         struct wl_info *wl = HW_TO_WL(hw);
946         int has_5g;
947         char phy_list[4];
948
949         has_5g = 0;
950
951         hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
952         hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
953
954         if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
955                 WL_ERROR("Phy list failed\n");
956         }
957         WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
958
959         if (phy_list[0] == 'n' || phy_list[0] == 'c') {
960                 if (phy_list[0] == 'c') {
961                         /* Single stream */
962                         wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
963                         wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
964                 }
965                 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
966         } else {
967                 BUG();
968                 return -1;
969         }
970
971         /* Assume all bands use the same phy.  True for 11n devices. */
972         if (NBANDS_PUB(wl->pub) > 1) {
973                 has_5g++;
974                 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
975                         hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
976                             &wl_band_5GHz_nphy;
977                 } else {
978                         return -1;
979                 }
980         }
981
982         WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
983
984         return 0;
985 }
986
987 static int ieee_hw_init(struct ieee80211_hw *hw)
988 {
989         hw->flags = IEEE80211_HW_SIGNAL_DBM
990             /* | IEEE80211_HW_CONNECTION_MONITOR  What is this? */
991             | IEEE80211_HW_REPORTS_TX_ACK_STATUS
992             | IEEE80211_HW_AMPDU_AGGREGATION;
993
994         hw->extra_tx_headroom = wlc_get_header_len();
995         /* FIXME: should get this from wlc->machwcap */
996         hw->queues = 4;
997         /* FIXME: this doesn't seem to be used properly in minstrel_ht.
998          * mac80211/status.c:ieee80211_tx_status() checks this value,
999          * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1000          * appears to always set 3 rates
1001          */
1002         hw->max_rates = 2;      /* Primary rate and 1 fallback rate */
1003
1004         hw->channel_change_time = 7 * 1000;     /* channel change time is dependant on chip and band  */
1005         hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1006
1007         hw->rate_control_algorithm = "minstrel_ht";
1008
1009         hw->sta_data_size = sizeof(struct scb);
1010         return ieee_hw_rate_init(hw);
1011 }
1012
1013 /**
1014  * determines if a device is a WL device, and if so, attaches it.
1015  *
1016  * This function determines if a device pointed to by pdev is a WL device,
1017  * and if so, performs a wl_attach() on it.
1018  *
1019  */
1020 int __devinit
1021 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1022 {
1023         int rc;
1024         struct wl_info *wl;
1025         struct ieee80211_hw *hw;
1026         u32 val;
1027
1028         ASSERT(pdev);
1029
1030         WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1031                  __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1032                  PCI_FUNC(pdev->devfn), pdev->irq);
1033
1034         if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1035             (((pdev->device & 0xff00) != 0x4300) &&
1036              ((pdev->device & 0xff00) != 0x4700) &&
1037              ((pdev->device < 43000) || (pdev->device > 43999))))
1038                 return -ENODEV;
1039
1040         rc = pci_enable_device(pdev);
1041         if (rc) {
1042                 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1043                          __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1044                          PCI_FUNC(pdev->devfn));
1045                 return -ENODEV;
1046         }
1047         pci_set_master(pdev);
1048
1049         pci_read_config_dword(pdev, 0x40, &val);
1050         if ((val & 0x0000ff00) != 0)
1051                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1052
1053         hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1054         if (!hw) {
1055                 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1056                 rc = -ENOMEM;
1057                 goto err_1;
1058         }
1059
1060         SET_IEEE80211_DEV(hw, &pdev->dev);
1061
1062         pci_set_drvdata(pdev, hw);
1063
1064         memset(hw->priv, 0, sizeof(*wl));
1065
1066         wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1067                        PCI_BUS, pdev, pdev->irq);
1068
1069         if (!wl) {
1070                 WL_ERROR("%s: %s: wl_attach failed!\n",
1071                          KBUILD_MODNAME, __func__);
1072                 return -ENODEV;
1073         }
1074         return 0;
1075  err_1:
1076         WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1077         return 0;
1078 }
1079
1080 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1081 {
1082         struct wl_info *wl;
1083         struct ieee80211_hw *hw;
1084
1085         WL_TRACE("wl: wl_suspend\n");
1086
1087         hw = pci_get_drvdata(pdev);
1088         wl = HW_TO_WL(hw);
1089         if (!wl) {
1090                 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1091                 return -ENODEV;
1092         }
1093
1094         /* only need to flag hw is down for proper resume */
1095         WL_LOCK(wl);
1096         wl->pub->hw_up = false;
1097         WL_UNLOCK(wl);
1098
1099         pci_save_state(pdev);
1100         pci_disable_device(pdev);
1101         return pci_set_power_state(pdev, PCI_D3hot);
1102 }
1103
1104 static int wl_resume(struct pci_dev *pdev)
1105 {
1106         struct wl_info *wl;
1107         struct ieee80211_hw *hw;
1108         int err = 0;
1109         u32 val;
1110
1111         WL_TRACE("wl: wl_resume\n");
1112         hw = pci_get_drvdata(pdev);
1113         wl = HW_TO_WL(hw);
1114         if (!wl) {
1115                 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1116                 return -ENODEV;
1117         }
1118
1119         err = pci_set_power_state(pdev, PCI_D0);
1120         if (err)
1121                 return err;
1122
1123         pci_restore_state(pdev);
1124
1125         err = pci_enable_device(pdev);
1126         if (err)
1127                 return err;
1128
1129         pci_set_master(pdev);
1130
1131         pci_read_config_dword(pdev, 0x40, &val);
1132         if ((val & 0x0000ff00) != 0)
1133                 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1134
1135         /*
1136         *  done. driver will be put in up state
1137         *  in wl_ops_add_interface() call.
1138         */
1139         return err;
1140 }
1141
1142 static void wl_remove(struct pci_dev *pdev)
1143 {
1144         struct wl_info *wl;
1145         struct ieee80211_hw *hw;
1146
1147         hw = pci_get_drvdata(pdev);
1148         wl = HW_TO_WL(hw);
1149         if (!wl) {
1150                 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1151                 return;
1152         }
1153
1154         /* make sure rfkill is not using driver */
1155         wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1156         wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1157
1158         if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1159                 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1160                 return;
1161         }
1162         if (wl->wlc) {
1163                 ieee80211_unregister_hw(hw);
1164                 WL_LOCK(wl);
1165                 wl_down(wl);
1166                 WL_UNLOCK(wl);
1167                 WL_NONE("%s: Down\n", __func__);
1168         }
1169         pci_disable_device(pdev);
1170
1171         wl_free(wl);
1172
1173         pci_set_drvdata(pdev, NULL);
1174         ieee80211_free_hw(hw);
1175 }
1176
1177 static struct pci_driver wl_pci_driver = {
1178         .name     = KBUILD_MODNAME,
1179         .probe    = wl_pci_probe,
1180         .suspend  = wl_suspend,
1181         .resume   = wl_resume,
1182         .remove   = __devexit_p(wl_remove),
1183         .id_table = wl_id_table,
1184 };
1185
1186 /**
1187  * This is the main entry point for the WL driver.
1188  *
1189  * This function determines if a device pointed to by pdev is a WL device,
1190  * and if so, performs a wl_attach() on it.
1191  *
1192  */
1193 static int __init wl_module_init(void)
1194 {
1195         int error = -ENODEV;
1196
1197 #ifdef BCMDBG
1198         if (msglevel != 0xdeadbeef)
1199                 wl_msg_level = msglevel;
1200         else {
1201                 char *var = getvar(NULL, "wl_msglevel");
1202                 if (var)
1203                         wl_msg_level = simple_strtoul(var, NULL, 0);
1204         }
1205         {
1206                 extern u32 phyhal_msg_level;
1207
1208                 if (phymsglevel != 0xdeadbeef)
1209                         phyhal_msg_level = phymsglevel;
1210                 else {
1211                         char *var = getvar(NULL, "phy_msglevel");
1212                         if (var)
1213                                 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1214                 }
1215         }
1216 #endif                          /* BCMDBG */
1217
1218         error = pci_register_driver(&wl_pci_driver);
1219         if (!error)
1220                 return 0;
1221
1222
1223
1224         return error;
1225 }
1226
1227 /**
1228  * This function unloads the WL driver from the system.
1229  *
1230  * This function unconditionally unloads the WL driver module from the
1231  * system.
1232  *
1233  */
1234 static void __exit wl_module_exit(void)
1235 {
1236         pci_unregister_driver(&wl_pci_driver);
1237
1238 }
1239
1240 module_init(wl_module_init);
1241 module_exit(wl_module_exit);
1242
1243 /**
1244  * This function frees the WL per-device resources.
1245  *
1246  * This function frees resources owned by the WL device pointed to
1247  * by the wl parameter.
1248  *
1249  */
1250 void wl_free(struct wl_info *wl)
1251 {
1252         wl_timer_t *t, *next;
1253         struct osl_info *osh;
1254
1255         ASSERT(wl);
1256         /* free ucode data */
1257         if (wl->fw.fw_cnt)
1258                 wl_ucode_data_free();
1259         if (wl->irq)
1260                 free_irq(wl->irq, wl);
1261
1262         /* kill dpc */
1263         tasklet_kill(&wl->tasklet);
1264
1265         if (wl->pub) {
1266                 wlc_module_unregister(wl->pub, "linux", wl);
1267         }
1268
1269         /* free common resources */
1270         if (wl->wlc) {
1271                 wlc_detach(wl->wlc);
1272                 wl->wlc = NULL;
1273                 wl->pub = NULL;
1274         }
1275
1276         /* virtual interface deletion is deferred so we cannot spinwait */
1277
1278         /* wait for all pending callbacks to complete */
1279         while (atomic_read(&wl->callbacks) > 0)
1280                 schedule();
1281
1282         /* free timers */
1283         for (t = wl->timers; t; t = next) {
1284                 next = t->next;
1285 #ifdef BCMDBG
1286                 if (t->name)
1287                         kfree(t->name);
1288 #endif
1289                 kfree(t);
1290         }
1291
1292         osh = wl->osh;
1293
1294         /*
1295          * unregister_netdev() calls get_stats() which may read chip registers
1296          * so we cannot unmap the chip registers until after calling unregister_netdev() .
1297          */
1298         if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1299             wl->bcm_bustype != JTAG_BUS) {
1300                 iounmap((void *)wl->regsva);
1301         }
1302         wl->regsva = NULL;
1303
1304
1305         osl_detach(osh);
1306 }
1307
1308 /* transmit a packet */
1309 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1310 {
1311         if (!wl)
1312                 return -ENETDOWN;
1313
1314         return wl_start_int(wl, WL_TO_HW(wl), skb);
1315 }
1316
1317 static int BCMFASTPATH
1318 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1319 {
1320         wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1321         return NETDEV_TX_OK;
1322 }
1323
1324 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1325                       int prio)
1326 {
1327         WL_ERROR("Shouldn't be here %s\n", __func__);
1328 }
1329
1330 void wl_init(struct wl_info *wl)
1331 {
1332         WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1333
1334         wl_reset(wl);
1335
1336         wlc_init(wl->wlc);
1337 }
1338
1339 uint wl_reset(struct wl_info *wl)
1340 {
1341         WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1342
1343         wlc_reset(wl->wlc);
1344
1345         /* dpc will not be rescheduled */
1346         wl->resched = 0;
1347
1348         return 0;
1349 }
1350
1351 /*
1352  * These are interrupt on/off entry points. Disable interrupts
1353  * during interrupt state transition.
1354  */
1355 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1356 {
1357         unsigned long flags;
1358
1359         INT_LOCK(wl, flags);
1360         wlc_intrson(wl->wlc);
1361         INT_UNLOCK(wl, flags);
1362 }
1363
1364 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1365 {
1366         return true;
1367 }
1368
1369 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1370 {
1371         unsigned long flags;
1372         u32 status;
1373
1374         INT_LOCK(wl, flags);
1375         status = wlc_intrsoff(wl->wlc);
1376         INT_UNLOCK(wl, flags);
1377         return status;
1378 }
1379
1380 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1381 {
1382         unsigned long flags;
1383
1384         INT_LOCK(wl, flags);
1385         wlc_intrsrestore(wl->wlc, macintmask);
1386         INT_UNLOCK(wl, flags);
1387 }
1388
1389 int wl_up(struct wl_info *wl)
1390 {
1391         int error = 0;
1392
1393         if (wl->pub->up)
1394                 return 0;
1395
1396         error = wlc_up(wl->wlc);
1397
1398         return error;
1399 }
1400
1401 void wl_down(struct wl_info *wl)
1402 {
1403         uint callbacks, ret_val = 0;
1404
1405         /* call common down function */
1406         ret_val = wlc_down(wl->wlc);
1407         callbacks = atomic_read(&wl->callbacks) - ret_val;
1408
1409         /* wait for down callbacks to complete */
1410         WL_UNLOCK(wl);
1411
1412         /* For HIGH_only driver, it's important to actually schedule other work,
1413          * not just spin wait since everything runs at schedule level
1414          */
1415         SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1416
1417         WL_LOCK(wl);
1418 }
1419
1420 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1421 {
1422         struct wl_info *wl;
1423         bool ours, wantdpc;
1424         unsigned long flags;
1425
1426         wl = (struct wl_info *) dev_id;
1427
1428         WL_ISRLOCK(wl, flags);
1429
1430         /* call common first level interrupt handler */
1431         ours = wlc_isr(wl->wlc, &wantdpc);
1432         if (ours) {
1433                 /* if more to do... */
1434                 if (wantdpc) {
1435
1436                         /* ...and call the second level interrupt handler */
1437                         /* schedule dpc */
1438                         ASSERT(wl->resched == false);
1439                         tasklet_schedule(&wl->tasklet);
1440                 }
1441         }
1442
1443         WL_ISRUNLOCK(wl, flags);
1444
1445         return IRQ_RETVAL(ours);
1446 }
1447
1448 static void BCMFASTPATH wl_dpc(unsigned long data)
1449 {
1450         struct wl_info *wl;
1451
1452         wl = (struct wl_info *) data;
1453
1454         WL_LOCK(wl);
1455
1456         /* call the common second level interrupt handler */
1457         if (wl->pub->up) {
1458                 if (wl->resched) {
1459                         unsigned long flags;
1460
1461                         INT_LOCK(wl, flags);
1462                         wlc_intrsupd(wl->wlc);
1463                         INT_UNLOCK(wl, flags);
1464                 }
1465
1466                 wl->resched = wlc_dpc(wl->wlc, true);
1467         }
1468
1469         /* wlc_dpc() may bring the driver down */
1470         if (!wl->pub->up)
1471                 goto done;
1472
1473         /* re-schedule dpc */
1474         if (wl->resched)
1475                 tasklet_schedule(&wl->tasklet);
1476         else {
1477                 /* re-enable interrupts */
1478                 wl_intrson(wl);
1479         }
1480
1481  done:
1482         WL_UNLOCK(wl);
1483 }
1484
1485 static void wl_link_up(struct wl_info *wl, char *ifname)
1486 {
1487         WL_ERROR("wl%d: link up (%s)\n", wl->pub->unit, ifname);
1488 }
1489
1490 static void wl_link_down(struct wl_info *wl, char *ifname)
1491 {
1492         WL_ERROR("wl%d: link down (%s)\n", wl->pub->unit, ifname);
1493 }
1494
1495 void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
1496 {
1497
1498         switch (e->event.event_type) {
1499         case WLC_E_LINK:
1500         case WLC_E_NDIS_LINK:
1501                 if (e->event.flags & WLC_EVENT_MSG_LINK)
1502                         wl_link_up(wl, ifname);
1503                 else
1504                         wl_link_down(wl, ifname);
1505                 break;
1506         case WLC_E_RADIO:
1507                 break;
1508         }
1509 }
1510
1511 static void wl_timer(unsigned long data)
1512 {
1513         _wl_timer((wl_timer_t *) data);
1514 }
1515
1516 static void _wl_timer(wl_timer_t *t)
1517 {
1518         WL_LOCK(t->wl);
1519
1520         if (t->set) {
1521                 if (t->periodic) {
1522                         t->timer.expires = jiffies + t->ms * HZ / 1000;
1523                         atomic_inc(&t->wl->callbacks);
1524                         add_timer(&t->timer);
1525                         t->set = true;
1526                 } else
1527                         t->set = false;
1528
1529                 t->fn(t->arg);
1530         }
1531
1532         atomic_dec(&t->wl->callbacks);
1533
1534         WL_UNLOCK(t->wl);
1535 }
1536
1537 wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1538                           const char *name)
1539 {
1540         wl_timer_t *t;
1541
1542         t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1543         if (!t) {
1544                 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1545                 return 0;
1546         }
1547
1548         memset(t, 0, sizeof(wl_timer_t));
1549
1550         init_timer(&t->timer);
1551         t->timer.data = (unsigned long) t;
1552         t->timer.function = wl_timer;
1553         t->wl = wl;
1554         t->fn = fn;
1555         t->arg = arg;
1556         t->next = wl->timers;
1557         wl->timers = t;
1558
1559 #ifdef BCMDBG
1560         t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1561         if (t->name)
1562                 strcpy(t->name, name);
1563 #endif
1564
1565         return t;
1566 }
1567
1568 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1569  * as well as it's easier to make it periodic
1570  */
1571 void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1572 {
1573 #ifdef BCMDBG
1574         if (t->set) {
1575                 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1576                          __func__, t->name, periodic);
1577         }
1578 #endif
1579         ASSERT(!t->set);
1580
1581         t->ms = ms;
1582         t->periodic = (bool) periodic;
1583         t->set = true;
1584         t->timer.expires = jiffies + ms * HZ / 1000;
1585
1586         atomic_inc(&wl->callbacks);
1587         add_timer(&t->timer);
1588 }
1589
1590 /* return true if timer successfully deleted, false if still pending */
1591 bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1592 {
1593         if (t->set) {
1594                 t->set = false;
1595                 if (!del_timer(&t->timer)) {
1596                         return false;
1597                 }
1598                 atomic_dec(&wl->callbacks);
1599         }
1600
1601         return true;
1602 }
1603
1604 void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1605 {
1606         wl_timer_t *tmp;
1607
1608         /* delete the timer in case it is active */
1609         wl_del_timer(wl, t);
1610
1611         if (wl->timers == t) {
1612                 wl->timers = wl->timers->next;
1613 #ifdef BCMDBG
1614                 if (t->name)
1615                         kfree(t->name);
1616 #endif
1617                 kfree(t);
1618                 return;
1619
1620         }
1621
1622         tmp = wl->timers;
1623         while (tmp) {
1624                 if (tmp->next == t) {
1625                         tmp->next = t->next;
1626 #ifdef BCMDBG
1627                         if (t->name)
1628                                 kfree(t->name);
1629 #endif
1630                         kfree(t);
1631                         return;
1632                 }
1633                 tmp = tmp->next;
1634         }
1635
1636 }
1637
1638 static int wl_linux_watchdog(void *ctx)
1639 {
1640         struct wl_info *wl = (struct wl_info *) ctx;
1641         struct net_device_stats *stats = NULL;
1642         uint id;
1643         /* refresh stats */
1644         if (wl->pub->up) {
1645                 ASSERT(wl->stats_id < 2);
1646
1647                 id = 1 - wl->stats_id;
1648
1649                 stats = &wl->stats_watchdog[id];
1650                 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
1651                 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
1652                 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
1653                 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
1654                 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
1655                 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
1656                 stats->collisions = 0;
1657
1658                 stats->rx_length_errors = 0;
1659                 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1660                 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
1661                 stats->rx_frame_errors = 0;
1662                 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1663                 stats->rx_missed_errors = 0;
1664
1665                 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
1666
1667                 wl->stats_id = id;
1668
1669         }
1670
1671         return 0;
1672 }
1673
1674 struct wl_fw_hdr {
1675         u32 offset;
1676         u32 len;
1677         u32 idx;
1678 };
1679
1680 char *wl_firmwares[WL_MAX_FW] = {
1681         "brcm/bcm43xx",
1682         NULL
1683 };
1684
1685 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1686 {
1687         int i, entry;
1688         const u8 *pdata;
1689         struct wl_fw_hdr *hdr;
1690         for (i = 0; i < wl->fw.fw_cnt; i++) {
1691                 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1692                 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1693                      entry++, hdr++) {
1694                         if (hdr->idx == idx) {
1695                                 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1696                                 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1697                                 if (*pbuf == NULL) {
1698                                         printf("fail to alloc %d bytes\n",
1699                                                hdr->len);
1700                                 }
1701                                 bcopy(pdata, *pbuf, hdr->len);
1702                                 return 0;
1703                         }
1704                 }
1705         }
1706         printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
1707         *pbuf = NULL;
1708         return -1;
1709 }
1710
1711 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1712 {
1713         int i, entry;
1714         const u8 *pdata;
1715         struct wl_fw_hdr *hdr;
1716         for (i = 0; i < wl->fw.fw_cnt; i++) {
1717                 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1718                 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1719                      entry++, hdr++) {
1720                         if (hdr->idx == idx) {
1721                                 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1722                                 ASSERT(hdr->len == 4);
1723                                 *data = *((u32 *) pdata);
1724                                 return 0;
1725                         }
1726                 }
1727         }
1728         printf("ERROR: ucode tag:%d can not be found!\n", idx);
1729         return -1;
1730 }
1731
1732 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1733 {
1734         int status;
1735         struct device *device = &pdev->dev;
1736         char fw_name[100];
1737         int i;
1738
1739         memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1740         for (i = 0; i < WL_MAX_FW; i++) {
1741                 if (wl_firmwares[i] == NULL)
1742                         break;
1743                 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1744                         UCODE_LOADER_API_VER);
1745                 WL_NONE("request fw %s\n", fw_name);
1746                 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1747                 if (status) {
1748                         printf("%s: fail to load firmware %s\n",
1749                                 KBUILD_MODNAME, fw_name);
1750                         wl_release_fw(wl);
1751                         return status;
1752                 }
1753                 WL_NONE("request fw %s\n", fw_name);
1754                 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1755                         UCODE_LOADER_API_VER);
1756                 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1757                 if (status) {
1758                         printf("%s: fail to load firmware %s\n",
1759                                 KBUILD_MODNAME, fw_name);
1760                         wl_release_fw(wl);
1761                         return status;
1762                 }
1763                 wl->fw.hdr_num_entries[i] =
1764                     wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1765                 WL_NONE("request fw %s find: %d entries\n",
1766                         fw_name, wl->fw.hdr_num_entries[i]);
1767         }
1768         wl->fw.fw_cnt = i;
1769         return wl_ucode_data_init(wl);
1770 }
1771
1772 void wl_ucode_free_buf(void *p)
1773 {
1774         kfree(p);
1775 }
1776
1777 static void wl_release_fw(struct wl_info *wl)
1778 {
1779         int i;
1780         for (i = 0; i < WL_MAX_FW; i++) {
1781                 release_firmware(wl->fw.fw_bin[i]);
1782                 release_firmware(wl->fw.fw_hdr[i]);
1783         }
1784 }
1785
1786
1787 /*
1788  * checks validity of all firmware images loaded from user space
1789  */
1790 int wl_check_firmwares(struct wl_info *wl)
1791 {
1792         int i;
1793         int entry;
1794         int rc = 0;
1795         const struct firmware *fw;
1796         const struct firmware *fw_hdr;
1797         struct wl_fw_hdr *ucode_hdr;
1798         for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1799                 fw =  wl->fw.fw_bin[i];
1800                 fw_hdr = wl->fw.fw_hdr[i];
1801                 if (fw == NULL && fw_hdr == NULL) {
1802                         break;
1803                 } else if (fw == NULL || fw_hdr == NULL) {
1804                         WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1805                         rc = -EBADF;
1806                 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1807                         WL_ERROR("%s: non integral fw hdr file size %d/%zu\n",
1808                                  __func__, fw_hdr->size,
1809                                  sizeof(struct wl_fw_hdr));
1810                         rc = -EBADF;
1811                 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1812                         WL_ERROR("%s: out of bounds fw file size %d\n",
1813                                  __func__, fw->size);
1814                         rc = -EBADF;
1815                 } else {
1816                         /* check if ucode section overruns firmware image */
1817                         ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1818                         for (entry = 0; entry < wl->fw.hdr_num_entries[i] && rc;
1819                              entry++, ucode_hdr++) {
1820                                 if (ucode_hdr->offset + ucode_hdr->len >
1821                                     fw->size) {
1822                                         WL_ERROR("%s: conflicting bin/hdr\n",
1823                                                  __func__);
1824                                         rc = -EBADF;
1825                                 }
1826                         }
1827                 }
1828         }
1829         if (rc == 0 && wl->fw.fw_cnt != i) {
1830                 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1831                 rc = -EBADF;
1832         }
1833         return rc;
1834 }
1835
1836 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1837 {
1838         bool blocked = wlc_check_radio_disabled(wl->wlc);
1839
1840         WL_ERROR("%s: update hw state: blocked=%s\n", __func__, blocked ? "true" : "false");
1841         wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1842         if (blocked)
1843                 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1844         return blocked;
1845 }