2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #define __UNDEF_NO_VERSION__
19 #include <linux/kernel.h>
20 #include <linux/etherdevice.h>
21 #include <linux/string.h>
22 #include <linux/pci_ids.h>
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/sched.h>
28 #define WLC_MAXBSSCFG 1 /* single BSS configs */
31 #include <net/mac80211.h>
32 #include <phy_version.h>
39 #include <wlc_channel.h>
43 #include <wl_export.h>
45 #include <wl_mac80211.h>
46 #include <linux/firmware.h>
48 #include <d11ucode_ext.h>
51 static void wl_timer(unsigned long data);
52 static void _wl_timer(wl_timer_t *t);
55 static int ieee_hw_init(struct ieee80211_hw *hw);
56 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
58 static int wl_linux_watchdog(void *ctx);
60 /* Flags we support */
61 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
67 FIF_BCN_PRBRESP_PROMISC)
71 struct ieee80211_tkip_data {
72 #define TKIP_KEY_LEN 32
88 u32 dot11RSNAStatsTKIPReplays;
89 u32 dot11RSNAStatsTKIPICVErrors;
90 u32 dot11RSNAStatsTKIPLocalMICFailures;
94 struct crypto_tfm *tfm_arc4;
95 struct crypto_tfm *tfm_michael;
97 /* scratch buffers for virt_to_page() (crypto API) */
98 u8 rx_hdr[16], tx_hdr[16];
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);
106 /* local prototypes */
107 static void wl_dpc(unsigned long data);
109 MODULE_AUTHOR("Broadcom Corporation");
110 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
111 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
112 MODULE_LICENSE("Dual BSD/GPL");
114 /* recognized PCI IDs */
115 static struct pci_device_id wl_id_table[] = {
116 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
117 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
118 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
122 MODULE_DEVICE_TABLE(pci, wl_id_table);
123 static void wl_remove(struct pci_dev *pdev);
127 static int msglevel = 0xdeadbeef;
128 module_param(msglevel, int, 0);
129 static int phymsglevel = 0xdeadbeef;
130 module_param(phymsglevel, int, 0);
133 #define HW_TO_WL(hw) (hw->priv)
134 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
135 static int wl_ops_start(struct ieee80211_hw *hw);
136 static void wl_ops_stop(struct ieee80211_hw *hw);
137 static int wl_ops_add_interface(struct ieee80211_hw *hw,
138 struct ieee80211_vif *vif);
139 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
140 struct ieee80211_vif *vif);
141 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
142 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
143 struct ieee80211_vif *vif,
144 struct ieee80211_bss_conf *info,
146 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
147 unsigned int changed_flags,
148 unsigned int *total_flags, u64 multicast);
149 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
151 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
152 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
153 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
154 static int wl_ops_get_stats(struct ieee80211_hw *hw,
155 struct ieee80211_low_level_stats *stats);
156 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
157 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
158 struct ieee80211_vif *vif,
159 enum sta_notify_cmd cmd,
160 struct ieee80211_sta *sta);
161 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
162 const struct ieee80211_tx_queue_params *params);
163 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
164 static int wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
165 struct ieee80211_sta *sta);
166 static int wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
167 struct ieee80211_sta *sta);
168 static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
169 enum ieee80211_ampdu_mlme_action action,
170 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
172 static void wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
174 struct wl_info *wl = hw->priv;
177 WL_ERROR("ops->tx called while down\n");
181 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
186 static int wl_ops_start(struct ieee80211_hw *hw)
188 struct wl_info *wl = hw->priv;
190 struct ieee80211_channel *curchan = hw->conf.channel;
191 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
195 ieee80211_wake_queues(hw);
201 static void wl_ops_stop(struct ieee80211_hw *hw)
203 struct wl_info *wl = hw->priv;
206 ieee80211_stop_queues(hw);
211 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
216 /* Just STA for now */
217 if (vif->type != NL80211_IFTYPE_AP &&
218 vif->type != NL80211_IFTYPE_MESH_POINT &&
219 vif->type != NL80211_IFTYPE_STATION &&
220 vif->type != NL80211_IFTYPE_WDS &&
221 vif->type != NL80211_IFTYPE_ADHOC) {
222 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
223 __func__, vif->type);
233 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
238 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
244 /* put driver in down state */
251 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
252 enum nl80211_channel_type type)
254 struct wl_info *wl = HW_TO_WL(hw);
258 case NL80211_CHAN_HT20:
259 case NL80211_CHAN_NO_HT:
260 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
262 case NL80211_CHAN_HT40MINUS:
263 case NL80211_CHAN_HT40PLUS:
264 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
273 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
275 struct ieee80211_conf *conf = &hw->conf;
276 struct wl_info *wl = HW_TO_WL(hw);
281 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
282 WL_NONE("%s: Setting listen interval to %d\n",
283 __func__, conf->listen_interval);
285 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
286 WL_ERROR("%s: Error setting listen_interval\n",
291 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
292 ASSERT(new_int == conf->listen_interval);
294 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
295 WL_NONE("Need to set monitor mode\n");
296 if (changed & IEEE80211_CONF_CHANGE_PS)
297 WL_NONE("Need to set Power-save mode\n");
299 if (changed & IEEE80211_CONF_CHANGE_POWER) {
300 WL_NONE("%s: Setting tx power to %d dbm\n",
301 __func__, conf->power_level);
303 (wl->wlc, "qtxpower", conf->power_level * 4)) {
304 WL_ERROR("%s: Error setting power_level\n", __func__);
308 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
309 if (new_int != (conf->power_level * 4))
310 WL_ERROR("%s: Power level req != actual, %d %d\n",
311 __func__, conf->power_level * 4, new_int);
313 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
314 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
316 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
317 WL_NONE("%s: srl %d, lrl %d\n",
319 conf->short_frame_max_tx_count,
320 conf->long_frame_max_tx_count);
322 (wl->wlc, WLC_SET_SRL,
323 conf->short_frame_max_tx_count) < 0) {
324 WL_ERROR("%s: Error setting srl\n", __func__);
328 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
330 WL_ERROR("%s: Error setting lrl\n", __func__);
342 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
343 struct ieee80211_vif *vif,
344 struct ieee80211_bss_conf *info, u32 changed)
346 struct wl_info *wl = HW_TO_WL(hw);
350 if (changed & BSS_CHANGED_ASSOC) {
351 WL_ERROR("Associated:\t%s\n", info->assoc ? "True" : "False");
352 /* association status changed (associated/disassociated)
353 * also implies a change in the AID.
356 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
357 WL_NONE("Use_cts_prot:\t%s Implement me\n",
358 info->use_cts_prot ? "True" : "False");
359 /* CTS protection changed */
361 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
362 WL_NONE("Short preamble:\t%s Implement me\n",
363 info->use_short_preamble ? "True" : "False");
364 /* preamble changed */
366 if (changed & BSS_CHANGED_ERP_SLOT) {
367 WL_NONE("Changing short slot:\t%s\n",
368 info->use_short_slot ? "True" : "False");
369 if (info->use_short_slot)
373 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
374 /* slot timing changed */
377 if (changed & BSS_CHANGED_HT) {
378 WL_NONE("%s: HT mode - Implement me\n", __func__);
379 /* 802.11n parameters changed */
381 if (changed & BSS_CHANGED_BASIC_RATES) {
382 WL_NONE("Need to change Basic Rates:\t0x%x! Implement me\n",
383 (u32) info->basic_rates);
384 /* Basic rateset changed */
386 if (changed & BSS_CHANGED_BEACON_INT) {
387 WL_NONE("Beacon Interval:\t%d Implement me\n",
389 /* Beacon interval changed */
391 if (changed & BSS_CHANGED_BSSID) {
392 WL_NONE("new BSSID:\taid %d bss:%pM\n",
393 info->aid, info->bssid);
394 /* BSSID changed, for whatever reason (IBSS and managed mode) */
395 /* FIXME: need to store bssid in bsscfg */
396 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
397 (struct ether_addr *)info->bssid);
399 if (changed & BSS_CHANGED_BEACON) {
400 WL_ERROR("BSS_CHANGED_BEACON\n");
401 /* Beacon data changed, retrieve new beacon (beaconing modes) */
403 if (changed & BSS_CHANGED_BEACON_ENABLED) {
404 WL_ERROR("Beacon enabled:\t%s\n",
405 info->enable_beacon ? "True" : "False");
406 /* Beaconing should be enabled/disabled (beaconing modes) */
412 wl_ops_configure_filter(struct ieee80211_hw *hw,
413 unsigned int changed_flags,
414 unsigned int *total_flags, u64 multicast)
416 struct wl_info *wl = hw->priv;
418 changed_flags &= MAC_FILTERS;
419 *total_flags &= MAC_FILTERS;
420 if (changed_flags & FIF_PROMISC_IN_BSS)
421 WL_ERROR("FIF_PROMISC_IN_BSS\n");
422 if (changed_flags & FIF_ALLMULTI)
423 WL_ERROR("FIF_ALLMULTI\n");
424 if (changed_flags & FIF_FCSFAIL)
425 WL_ERROR("FIF_FCSFAIL\n");
426 if (changed_flags & FIF_PLCPFAIL)
427 WL_ERROR("FIF_PLCPFAIL\n");
428 if (changed_flags & FIF_CONTROL)
429 WL_ERROR("FIF_CONTROL\n");
430 if (changed_flags & FIF_OTHER_BSS)
431 WL_ERROR("FIF_OTHER_BSS\n");
432 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
433 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
435 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
436 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
437 wlc_mac_bcn_promisc_change(wl->wlc, 1);
439 wlc_mac_bcn_promisc_change(wl->wlc, 0);
440 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
448 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
450 WL_ERROR("%s: Enter\n", __func__);
454 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
456 struct wl_info *wl = hw->priv;
457 WL_NONE("Scan Start\n");
459 wlc_scan_start(wl->wlc);
464 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
466 struct wl_info *wl = hw->priv;
467 WL_NONE("Scan Complete\n");
469 wlc_scan_stop(wl->wlc);
474 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
476 WL_ERROR("%s: Enter\n", __func__);
481 wl_ops_get_stats(struct ieee80211_hw *hw,
482 struct ieee80211_low_level_stats *stats)
484 WL_ERROR("%s: Enter\n", __func__);
488 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
490 WL_ERROR("%s: Enter\n", __func__);
495 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
496 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
498 WL_NONE("%s: Enter\n", __func__);
501 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
508 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
509 const struct ieee80211_tx_queue_params *params)
511 struct wl_info *wl = hw->priv;
513 WL_NONE("%s: Enter (WME config)\n", __func__);
514 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
515 params->txop, params->cw_min, params->cw_max, params->aifs);
518 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
524 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
526 WL_ERROR("%s: Enter\n", __func__);
531 wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
532 struct ieee80211_sta *sta)
537 struct wl_info *wl = hw->priv;
540 scb = (struct scb *)sta->drv_priv;
541 memset(scb, 0, sizeof(struct scb));
542 for (i = 0; i < NUMPRIO; i++)
543 scb->seqctl[i] = 0xFFFF;
544 scb->seqctl_nonqos = 0xFFFF;
545 scb->magic = SCB_MAGIC;
547 wl->pub->global_scb = scb;
548 wl->pub->global_ampdu = &(scb->scb_ampdu);
549 wl->pub->global_ampdu->scb = scb;
550 wl->pub->global_ampdu->max_pdu = 16;
551 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
552 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
554 sta->ht_cap.ht_supported = true;
555 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
556 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
557 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
558 IEEE80211_HT_CAP_SGI_20 |
559 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
561 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
566 wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
567 struct ieee80211_sta *sta)
569 WL_NONE("%s: Enter\n", __func__);
574 wl_ampdu_action(struct ieee80211_hw *hw,
575 struct ieee80211_vif *vif,
576 enum ieee80211_ampdu_mlme_action action,
577 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
580 struct scb *scb = (struct scb *)sta->drv_priv;
582 struct wl_info *wl = hw->priv;
584 ASSERT(scb->magic == SCB_MAGIC);
586 case IEEE80211_AMPDU_RX_START:
587 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
589 case IEEE80211_AMPDU_RX_STOP:
590 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
592 case IEEE80211_AMPDU_TX_START:
593 if (!wlc_aggregatable(wl->wlc, tid)) {
594 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
597 /* XXX: Use the starting sequence number provided ... */
599 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
602 case IEEE80211_AMPDU_TX_STOP:
603 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
605 case IEEE80211_AMPDU_TX_OPERATIONAL:
606 /* Not sure what to do here */
607 /* Power save wakeup */
608 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
612 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
618 static const struct ieee80211_ops wl_ops = {
620 .start = wl_ops_start,
622 .add_interface = wl_ops_add_interface,
623 .remove_interface = wl_ops_remove_interface,
624 .config = wl_ops_config,
625 .bss_info_changed = wl_ops_bss_info_changed,
626 .configure_filter = wl_ops_configure_filter,
627 .set_tim = wl_ops_set_tim,
628 .sw_scan_start = wl_ops_sw_scan_start,
629 .sw_scan_complete = wl_ops_sw_scan_complete,
630 .set_tsf = wl_ops_set_tsf,
631 .get_stats = wl_ops_get_stats,
632 .set_rts_threshold = wl_ops_set_rts_threshold,
633 .sta_notify = wl_ops_sta_notify,
634 .conf_tx = wl_ops_conf_tx,
635 .get_tsf = wl_ops_get_tsf,
636 .sta_add = wl_sta_add,
637 .sta_remove = wl_sta_remove,
638 .ampdu_action = wl_ampdu_action,
641 static int wl_set_hint(struct wl_info *wl, char *abbrev)
643 WL_ERROR("%s: Sending country code %c%c to MAC80211\n",
644 __func__, abbrev[0], abbrev[1]);
645 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
649 * attach to the WL device.
651 * Attach to the WL device identified by vendor and device parameters.
652 * regs is a host accessible memory address pointing to WL device registers.
654 * wl_attach is not defined as static because in the case where no bus
655 * is defined, wl_attach will never be called, and thus, gcc will issue
656 * a warning that this function is defined but not used if we declare
659 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
660 uint bustype, void *btparam, uint irq)
663 struct osl_info *osh;
666 unsigned long base_addr;
667 struct ieee80211_hw *hw;
674 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
678 osh = osl_attach(btparam, bustype);
681 /* allocate private info */
682 hw = pci_get_drvdata(btparam); /* btparam == pdev */
687 atomic_set(&wl->callbacks, 0);
689 /* setup the bottom half handler */
690 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
696 if (bustype == PCI_BUS) {
698 } else if (bustype == RPC_BUS) {
702 WL_TRACE("force to PCI\n");
704 wl->bcm_bustype = bustype;
706 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
707 if (wl->regsva == NULL) {
708 WL_ERROR("wl%d: ioremap() failed\n", unit);
711 spin_lock_init(&wl->lock);
712 spin_lock_init(&wl->isr_lock);
715 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
716 printf("%s: Failed to find firmware usually in %s\n",
717 KBUILD_MODNAME, "/lib/firmware/brcm");
719 wl_remove((struct pci_dev *)btparam);
723 /* common load-time initialization */
724 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
725 wl->regsva, wl->bcm_bustype, btparam, &err);
728 printf("%s: wlc_attach() failed with code %d\n",
729 KBUILD_MODNAME, err);
732 wl->pub = wlc_pub(wl->wlc);
734 wl->pub->ieee_hw = hw;
735 ASSERT(wl->pub->ieee_hw);
736 ASSERT(wl->pub->ieee_hw->priv == wl);
739 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
740 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
743 /* register our interrupt handler */
744 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
745 WL_ERROR("wl%d: request_irq() failed\n", unit);
750 /* register module */
751 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
754 if (ieee_hw_init(hw)) {
755 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
759 bcopy(&wl->pub->cur_etheraddr, perm, ETH_ALEN);
760 ASSERT(is_valid_ether_addr(perm));
761 SET_IEEE80211_PERM_ADDR(hw, perm);
763 err = ieee80211_register_hw(hw);
765 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
769 if (wl->pub->srom_ccode[0])
770 err = wl_set_hint(wl, wl->pub->srom_ccode);
772 err = wl_set_hint(wl, "US");
774 WL_ERROR("%s: regulatory_hint failed, status %d\n",
777 WL_ERROR("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver (" PHY_VERSION_STR ")",
781 printf(" (Compiled at " __TIME__ " on " __DATE__ ")");
796 #define CHAN2GHZ(channel, freqency, chflags) { \
797 .band = IEEE80211_BAND_2GHZ, \
798 .center_freq = (freqency), \
799 .hw_value = (channel), \
801 .max_antenna_gain = 0, \
805 static struct ieee80211_channel wl_2ghz_chantable[] = {
806 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
807 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
808 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
809 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
810 CHAN2GHZ(5, 2432, 0),
811 CHAN2GHZ(6, 2437, 0),
812 CHAN2GHZ(7, 2442, 0),
813 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
814 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
815 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
816 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
818 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
819 IEEE80211_CHAN_NO_HT40PLUS),
821 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
822 IEEE80211_CHAN_NO_HT40PLUS),
824 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
825 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
828 #define CHAN5GHZ(channel, chflags) { \
829 .band = IEEE80211_BAND_5GHZ, \
830 .center_freq = 5000 + 5*(channel), \
831 .hw_value = (channel), \
833 .max_antenna_gain = 0, \
837 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
839 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
840 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
841 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
842 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
845 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
846 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
848 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
849 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
851 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
852 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
854 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
855 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
858 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
859 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
861 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
862 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
864 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
865 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
867 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
868 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
870 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
871 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
873 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
874 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
876 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
877 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
879 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
880 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
882 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
883 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
885 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
886 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
888 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
889 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
890 IEEE80211_CHAN_NO_HT40MINUS),
892 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
893 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
894 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
895 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
896 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
899 #define RATE(rate100m, _flags) { \
900 .bitrate = (rate100m), \
902 .hw_value = (rate100m / 5), \
905 static struct ieee80211_rate wl_legacy_ratetable[] = {
907 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
908 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
909 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
920 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
921 .band = IEEE80211_BAND_2GHZ,
922 .channels = wl_2ghz_chantable,
923 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
924 .bitrates = wl_legacy_ratetable,
925 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
927 /* from include/linux/ieee80211.h */
928 .cap = IEEE80211_HT_CAP_GRN_FLD |
929 IEEE80211_HT_CAP_SGI_20 |
930 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
931 .ht_supported = true,
932 .ampdu_factor = AMPDU_RX_FACTOR_64K,
933 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
935 /* placeholders for now */
936 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
938 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
942 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
943 .band = IEEE80211_BAND_5GHZ,
944 .channels = wl_5ghz_nphy_chantable,
945 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
946 .bitrates = wl_legacy_ratetable + 4,
947 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
949 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
950 .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 */
951 .ht_supported = true,
952 .ampdu_factor = AMPDU_RX_FACTOR_64K,
953 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
955 /* placeholders for now */
956 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
958 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
962 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
964 struct wl_info *wl = HW_TO_WL(hw);
970 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
971 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
973 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
974 WL_ERROR("Phy list failed\n");
976 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
978 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
979 if (phy_list[0] == 'c') {
981 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
982 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
984 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
990 /* Assume all bands use the same phy. True for 11n devices. */
991 if (NBANDS_PUB(wl->pub) > 1) {
993 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
994 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1001 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1006 static int ieee_hw_init(struct ieee80211_hw *hw)
1008 hw->flags = IEEE80211_HW_SIGNAL_DBM
1009 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1010 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1011 | IEEE80211_HW_AMPDU_AGGREGATION;
1013 hw->extra_tx_headroom = wlc_get_header_len();
1014 /* FIXME: should get this from wlc->machwcap */
1016 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1017 * mac80211/status.c:ieee80211_tx_status() checks this value,
1018 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1019 * appears to always set 3 rates
1021 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1023 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1024 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1026 hw->rate_control_algorithm = "minstrel_ht";
1028 hw->sta_data_size = sizeof(struct scb);
1029 return ieee_hw_rate_init(hw);
1033 * determines if a device is a WL device, and if so, attaches it.
1035 * This function determines if a device pointed to by pdev is a WL device,
1036 * and if so, performs a wl_attach() on it.
1040 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1044 struct ieee80211_hw *hw;
1049 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1050 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1051 PCI_FUNC(pdev->devfn), pdev->irq);
1053 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1054 (((pdev->device & 0xff00) != 0x4300) &&
1055 ((pdev->device & 0xff00) != 0x4700) &&
1056 ((pdev->device < 43000) || (pdev->device > 43999))))
1059 rc = pci_enable_device(pdev);
1061 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1062 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1063 PCI_FUNC(pdev->devfn));
1066 pci_set_master(pdev);
1068 pci_read_config_dword(pdev, 0x40, &val);
1069 if ((val & 0x0000ff00) != 0)
1070 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1072 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1074 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1079 SET_IEEE80211_DEV(hw, &pdev->dev);
1081 pci_set_drvdata(pdev, hw);
1083 memset(hw->priv, 0, sizeof(*wl));
1085 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1086 PCI_BUS, pdev, pdev->irq);
1089 WL_ERROR("%s: %s: wl_attach failed!\n",
1090 KBUILD_MODNAME, __func__);
1095 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1099 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1102 struct ieee80211_hw *hw;
1104 WL_TRACE("wl: wl_suspend\n");
1106 hw = pci_get_drvdata(pdev);
1109 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1113 /* only need to flag hw is down for proper resume */
1115 wl->pub->hw_up = false;
1118 pci_save_state(pdev);
1119 pci_disable_device(pdev);
1120 return pci_set_power_state(pdev, PCI_D3hot);
1123 static int wl_resume(struct pci_dev *pdev)
1126 struct ieee80211_hw *hw;
1130 WL_TRACE("wl: wl_resume\n");
1131 hw = pci_get_drvdata(pdev);
1134 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1138 err = pci_set_power_state(pdev, PCI_D0);
1142 pci_restore_state(pdev);
1144 err = pci_enable_device(pdev);
1148 pci_set_master(pdev);
1150 pci_read_config_dword(pdev, 0x40, &val);
1151 if ((val & 0x0000ff00) != 0)
1152 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1155 * done. driver will be put in up state
1156 * in wl_ops_add_interface() call.
1161 static void wl_remove(struct pci_dev *pdev)
1164 struct ieee80211_hw *hw;
1166 hw = pci_get_drvdata(pdev);
1169 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1172 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1173 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1177 ieee80211_unregister_hw(hw);
1181 WL_NONE("%s: Down\n", __func__);
1183 pci_disable_device(pdev);
1187 pci_set_drvdata(pdev, NULL);
1188 ieee80211_free_hw(hw);
1191 static struct pci_driver wl_pci_driver = {
1192 .name = "brcm80211",
1193 .probe = wl_pci_probe,
1194 .suspend = wl_suspend,
1195 .resume = wl_resume,
1196 .remove = __devexit_p(wl_remove),
1197 .id_table = wl_id_table,
1201 * This is the main entry point for the WL driver.
1203 * This function determines if a device pointed to by pdev is a WL device,
1204 * and if so, performs a wl_attach() on it.
1207 static int __init wl_module_init(void)
1209 int error = -ENODEV;
1212 if (msglevel != 0xdeadbeef)
1213 wl_msg_level = msglevel;
1215 char *var = getvar(NULL, "wl_msglevel");
1217 wl_msg_level = simple_strtoul(var, NULL, 0);
1220 extern u32 phyhal_msg_level;
1222 if (phymsglevel != 0xdeadbeef)
1223 phyhal_msg_level = phymsglevel;
1225 char *var = getvar(NULL, "phy_msglevel");
1227 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1232 error = pci_register_driver(&wl_pci_driver);
1242 * This function unloads the WL driver from the system.
1244 * This function unconditionally unloads the WL driver module from the
1248 static void __exit wl_module_exit(void)
1250 pci_unregister_driver(&wl_pci_driver);
1254 module_init(wl_module_init);
1255 module_exit(wl_module_exit);
1258 * This function frees the WL per-device resources.
1260 * This function frees resources owned by the WL device pointed to
1261 * by the wl parameter.
1264 void wl_free(struct wl_info *wl)
1266 wl_timer_t *t, *next;
1267 struct osl_info *osh;
1270 /* free ucode data */
1272 wl_ucode_data_free();
1274 free_irq(wl->irq, wl);
1277 tasklet_kill(&wl->tasklet);
1280 wlc_module_unregister(wl->pub, "linux", wl);
1283 /* free common resources */
1285 wlc_detach(wl->wlc);
1290 /* virtual interface deletion is deferred so we cannot spinwait */
1292 /* wait for all pending callbacks to complete */
1293 while (atomic_read(&wl->callbacks) > 0)
1297 for (t = wl->timers; t; t = next) {
1309 * unregister_netdev() calls get_stats() which may read chip registers
1310 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1312 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1313 wl->bcm_bustype != JTAG_BUS) {
1314 iounmap((void *)wl->regsva);
1322 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1325 WL_ERROR("Shouldn't be here %s\n", __func__);
1328 void wl_init(struct wl_info *wl)
1330 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1337 uint wl_reset(struct wl_info *wl)
1339 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1343 /* dpc will not be rescheduled */
1350 * These are interrupt on/off entry points. Disable interrupts
1351 * during interrupt state transition.
1353 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1355 unsigned long flags;
1357 INT_LOCK(wl, flags);
1358 wlc_intrson(wl->wlc);
1359 INT_UNLOCK(wl, flags);
1362 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1367 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1369 unsigned long flags;
1372 INT_LOCK(wl, flags);
1373 status = wlc_intrsoff(wl->wlc);
1374 INT_UNLOCK(wl, flags);
1378 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1380 unsigned long flags;
1382 INT_LOCK(wl, flags);
1383 wlc_intrsrestore(wl->wlc, macintmask);
1384 INT_UNLOCK(wl, flags);
1387 int wl_up(struct wl_info *wl)
1394 error = wlc_up(wl->wlc);
1399 void wl_down(struct wl_info *wl)
1401 uint callbacks, ret_val = 0;
1403 /* call common down function */
1404 ret_val = wlc_down(wl->wlc);
1405 callbacks = atomic_read(&wl->callbacks) - ret_val;
1407 /* wait for down callbacks to complete */
1410 /* For HIGH_only driver, it's important to actually schedule other work,
1411 * not just spin wait since everything runs at schedule level
1413 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1418 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1422 unsigned long flags;
1424 wl = (struct wl_info *) dev_id;
1426 WL_ISRLOCK(wl, flags);
1428 /* call common first level interrupt handler */
1429 ours = wlc_isr(wl->wlc, &wantdpc);
1431 /* if more to do... */
1434 /* ...and call the second level interrupt handler */
1436 ASSERT(wl->resched == false);
1437 tasklet_schedule(&wl->tasklet);
1441 WL_ISRUNLOCK(wl, flags);
1443 return IRQ_RETVAL(ours);
1446 static void BCMFASTPATH wl_dpc(unsigned long data)
1450 wl = (struct wl_info *) data;
1454 /* call the common second level interrupt handler */
1457 unsigned long flags;
1459 INT_LOCK(wl, flags);
1460 wlc_intrsupd(wl->wlc);
1461 INT_UNLOCK(wl, flags);
1464 wl->resched = wlc_dpc(wl->wlc, true);
1467 /* wlc_dpc() may bring the driver down */
1471 /* re-schedule dpc */
1473 tasklet_schedule(&wl->tasklet);
1475 /* re-enable interrupts */
1483 static void wl_link_up(struct wl_info *wl, char *ifname)
1485 WL_ERROR("wl%d: link up (%s)\n", wl->pub->unit, ifname);
1488 static void wl_link_down(struct wl_info *wl, char *ifname)
1490 WL_ERROR("wl%d: link down (%s)\n", wl->pub->unit, ifname);
1493 void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
1496 switch (e->event.event_type) {
1498 case WLC_E_NDIS_LINK:
1499 if (e->event.flags & WLC_EVENT_MSG_LINK)
1500 wl_link_up(wl, ifname);
1502 wl_link_down(wl, ifname);
1509 static void wl_timer(unsigned long data)
1511 _wl_timer((wl_timer_t *) data);
1514 static void _wl_timer(wl_timer_t *t)
1520 t->timer.expires = jiffies + t->ms * HZ / 1000;
1521 atomic_inc(&t->wl->callbacks);
1522 add_timer(&t->timer);
1530 atomic_dec(&t->wl->callbacks);
1535 wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1540 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1542 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1546 memset(t, 0, sizeof(wl_timer_t));
1548 init_timer(&t->timer);
1549 t->timer.data = (unsigned long) t;
1550 t->timer.function = wl_timer;
1554 t->next = wl->timers;
1558 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1560 strcpy(t->name, name);
1566 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1567 * as well as it's easier to make it periodic
1569 void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1573 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1574 __func__, t->name, periodic);
1580 t->periodic = (bool) periodic;
1582 t->timer.expires = jiffies + ms * HZ / 1000;
1584 atomic_inc(&wl->callbacks);
1585 add_timer(&t->timer);
1588 /* return true if timer successfully deleted, false if still pending */
1589 bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1593 if (!del_timer(&t->timer)) {
1596 atomic_dec(&wl->callbacks);
1602 void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1606 /* delete the timer in case it is active */
1607 wl_del_timer(wl, t);
1609 if (wl->timers == t) {
1610 wl->timers = wl->timers->next;
1622 if (tmp->next == t) {
1623 tmp->next = t->next;
1636 static int wl_linux_watchdog(void *ctx)
1638 struct wl_info *wl = (struct wl_info *) ctx;
1639 struct net_device_stats *stats = NULL;
1643 ASSERT(wl->stats_id < 2);
1645 id = 1 - wl->stats_id;
1647 stats = &wl->stats_watchdog[id];
1648 stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe);
1649 stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe);
1650 stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte);
1651 stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte);
1652 stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror);
1653 stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror);
1654 stats->collisions = 0;
1656 stats->rx_length_errors = 0;
1657 stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1658 stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc);
1659 stats->rx_frame_errors = 0;
1660 stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo);
1661 stats->rx_missed_errors = 0;
1663 stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo);
1678 char *wl_firmwares[WL_MAX_FW] = {
1683 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1687 struct wl_fw_hdr *hdr;
1688 for (i = 0; i < wl->fw.fw_cnt; i++) {
1689 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1690 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1692 if (hdr->idx == idx) {
1693 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1694 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1695 if (*pbuf == NULL) {
1696 printf("fail to alloc %d bytes\n",
1699 bcopy(pdata, *pbuf, hdr->len);
1704 printf("ERROR: ucode buf tag:%d can not be found!\n", idx);
1709 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1713 struct wl_fw_hdr *hdr;
1714 for (i = 0; i < wl->fw.fw_cnt; i++) {
1715 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1716 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1718 if (hdr->idx == idx) {
1719 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1720 ASSERT(hdr->len == 4);
1721 *data = *((u32 *) pdata);
1726 printf("ERROR: ucode tag:%d can not be found!\n", idx);
1730 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1733 struct device *device = &pdev->dev;
1737 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1738 for (i = 0; i < WL_MAX_FW; i++) {
1739 if (wl_firmwares[i] == NULL)
1741 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1742 UCODE_LOADER_API_VER);
1743 WL_NONE("request fw %s\n", fw_name);
1744 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1746 printf("%s: fail to load firmware %s\n",
1747 KBUILD_MODNAME, fw_name);
1751 WL_NONE("request fw %s\n", fw_name);
1752 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1753 UCODE_LOADER_API_VER);
1754 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1756 printf("%s: fail to load firmware %s\n",
1757 KBUILD_MODNAME, fw_name);
1761 wl->fw.hdr_num_entries[i] =
1762 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1763 WL_NONE("request fw %s find: %d entries\n",
1764 fw_name, wl->fw.hdr_num_entries[i]);
1767 return wl_ucode_data_init(wl);
1770 void wl_ucode_free_buf(void *p)
1775 static void wl_release_fw(struct wl_info *wl)
1778 for (i = 0; i < WL_MAX_FW; i++) {
1779 release_firmware(wl->fw.fw_bin[i]);
1780 release_firmware(wl->fw.fw_hdr[i]);
1786 * checks validity of all firmware images loaded from user space
1788 int wl_check_firmwares(struct wl_info *wl)
1793 const struct firmware *fw;
1794 const struct firmware *fw_hdr;
1795 struct wl_fw_hdr *ucode_hdr;
1796 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1797 fw = wl->fw.fw_bin[i];
1798 fw_hdr = wl->fw.fw_hdr[i];
1799 if (fw == NULL && fw_hdr == NULL) {
1801 } else if (fw == NULL || fw_hdr == NULL) {
1802 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1804 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1805 WL_ERROR("%s: non integral fw hdr file size %d/%zu\n",
1806 __func__, fw_hdr->size,
1807 sizeof(struct wl_fw_hdr));
1809 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1810 WL_ERROR("%s: out of bounds fw file size %d\n",
1811 __func__, fw->size);
1814 /* check if ucode section overruns firmware image */
1815 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1816 for (entry = 0; entry < wl->fw.hdr_num_entries[i] && rc;
1817 entry++, ucode_hdr++) {
1818 if (ucode_hdr->offset + ucode_hdr->len >
1820 WL_ERROR("%s: conflicting bin/hdr\n",
1827 if (rc == 0 && wl->fw.fw_cnt != i) {
1828 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);