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