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