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