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 #define WL_DEV_IF(dev) ((struct wl_if *)netdev_priv(dev))
72 #define WL_INFO(dev) ((struct wl_info *)(WL_DEV_IF(dev)->wl))
73 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev);
74 static void wl_release_fw(struct wl_info *wl);
76 /* local prototypes */
77 static int wl_start(struct sk_buff *skb, struct wl_info *wl);
78 static int wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw,
80 static void wl_dpc(unsigned long data);
82 MODULE_AUTHOR("Broadcom Corporation");
83 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
84 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
85 MODULE_LICENSE("Dual BSD/GPL");
87 /* recognized PCI IDs */
88 static struct pci_device_id wl_id_table[] = {
89 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
90 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
91 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
95 MODULE_DEVICE_TABLE(pci, wl_id_table);
96 static void wl_remove(struct pci_dev *pdev);
100 static int msglevel = 0xdeadbeef;
101 module_param(msglevel, int, 0);
102 static int phymsglevel = 0xdeadbeef;
103 module_param(phymsglevel, int, 0);
106 #define HW_TO_WL(hw) (hw->priv)
107 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
108 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
109 static int wl_ops_start(struct ieee80211_hw *hw);
110 static void wl_ops_stop(struct ieee80211_hw *hw);
111 static int wl_ops_add_interface(struct ieee80211_hw *hw,
112 struct ieee80211_vif *vif);
113 static void wl_ops_remove_interface(struct ieee80211_hw *hw,
114 struct ieee80211_vif *vif);
115 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed);
116 static void wl_ops_bss_info_changed(struct ieee80211_hw *hw,
117 struct ieee80211_vif *vif,
118 struct ieee80211_bss_conf *info,
120 static void wl_ops_configure_filter(struct ieee80211_hw *hw,
121 unsigned int changed_flags,
122 unsigned int *total_flags, u64 multicast);
123 static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
125 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw);
126 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw);
127 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
128 static int wl_ops_get_stats(struct ieee80211_hw *hw,
129 struct ieee80211_low_level_stats *stats);
130 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
131 static void wl_ops_sta_notify(struct ieee80211_hw *hw,
132 struct ieee80211_vif *vif,
133 enum sta_notify_cmd cmd,
134 struct ieee80211_sta *sta);
135 static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
136 const struct ieee80211_tx_queue_params *params);
137 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw);
138 static int wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
139 struct ieee80211_sta *sta);
140 static int wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
141 struct ieee80211_sta *sta);
142 static int wl_ops_ampdu_action(struct ieee80211_hw *hw,
143 struct ieee80211_vif *vif,
144 enum ieee80211_ampdu_mlme_action action,
145 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
146 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw);
148 static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
151 struct wl_info *wl = hw->priv;
155 WL_ERROR("ops->tx called while down\n");
159 status = wl_start(skb, wl);
165 static int wl_ops_start(struct ieee80211_hw *hw)
167 struct wl_info *wl = hw->priv;
170 struct ieee80211_channel *curchan = hw->conf.channel;
171 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
175 ieee80211_wake_queues(hw);
177 blocked = wl_rfkill_set_hw_state(wl);
179 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
184 static void wl_ops_stop(struct ieee80211_hw *hw)
186 struct wl_info *wl = hw->priv;
189 ieee80211_stop_queues(hw);
194 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
199 /* Just STA for now */
200 if (vif->type != NL80211_IFTYPE_AP &&
201 vif->type != NL80211_IFTYPE_MESH_POINT &&
202 vif->type != NL80211_IFTYPE_STATION &&
203 vif->type != NL80211_IFTYPE_WDS &&
204 vif->type != NL80211_IFTYPE_ADHOC) {
205 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
206 __func__, vif->type);
216 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
222 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
228 /* put driver in down state */
235 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
236 enum nl80211_channel_type type)
238 struct wl_info *wl = HW_TO_WL(hw);
242 case NL80211_CHAN_HT20:
243 case NL80211_CHAN_NO_HT:
244 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
246 case NL80211_CHAN_HT40MINUS:
247 case NL80211_CHAN_HT40PLUS:
248 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
258 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
260 struct ieee80211_conf *conf = &hw->conf;
261 struct wl_info *wl = HW_TO_WL(hw);
266 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
268 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
269 WL_ERROR("%s: Error setting listen_interval\n",
274 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
275 ASSERT(new_int == conf->listen_interval);
277 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
278 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
279 conf->flags & IEEE80211_CONF_MONITOR ?
281 if (changed & IEEE80211_CONF_CHANGE_PS)
282 WL_ERROR("%s: change power-save mode: %s (implement)\n",
283 __func__, conf->flags & IEEE80211_CONF_PS ?
286 if (changed & IEEE80211_CONF_CHANGE_POWER) {
288 (wl->wlc, "qtxpower", conf->power_level * 4)) {
289 WL_ERROR("%s: Error setting power_level\n", __func__);
293 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
294 if (new_int != (conf->power_level * 4))
295 WL_ERROR("%s: Power level req != actual, %d %d\n",
296 __func__, conf->power_level * 4, new_int);
298 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
299 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
301 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
303 (wl->wlc, WLC_SET_SRL,
304 conf->short_frame_max_tx_count) < 0) {
305 WL_ERROR("%s: Error setting srl\n", __func__);
309 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
311 WL_ERROR("%s: Error setting lrl\n", __func__);
323 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
324 struct ieee80211_vif *vif,
325 struct ieee80211_bss_conf *info, u32 changed)
327 struct wl_info *wl = HW_TO_WL(hw);
330 if (changed & BSS_CHANGED_ASSOC) {
331 /* association status changed (associated/disassociated)
332 * also implies a change in the AID.
334 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
335 info->assoc ? "" : "dis");
336 wlc_associate_upd(wl->wlc, info->assoc);
338 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
339 /* CTS protection changed */
340 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
341 info->use_cts_prot ? "true" : "false");
343 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
344 /* preamble changed */
345 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
346 info->use_short_preamble ? "true" : "false");
348 if (changed & BSS_CHANGED_ERP_SLOT) {
349 /* slot timing changed */
350 if (info->use_short_slot)
354 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
357 if (changed & BSS_CHANGED_HT) {
358 /* 802.11n parameters changed */
359 u16 mode = info->ht_operation_mode;
360 WL_NONE("%s: HT mode: 0x%04X\n", __func__, mode);
361 wlc_protection_upd(wl->wlc, WLC_PROT_N_CFG,
362 mode & IEEE80211_HT_OP_MODE_PROTECTION);
363 wlc_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
364 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
365 wlc_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
366 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
368 if (changed & BSS_CHANGED_BASIC_RATES) {
369 /* Basic rateset changed */
370 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
371 __func__, (u32) info->basic_rates);
373 if (changed & BSS_CHANGED_BEACON_INT) {
374 /* Beacon interval changed */
375 WL_NONE("%s: Beacon Interval: %d (implement)\n",
376 __func__, info->beacon_int);
378 if (changed & BSS_CHANGED_BSSID) {
379 /* BSSID changed, for whatever reason (IBSS and managed mode) */
380 WL_NONE("%s: new BSSID: aid %d bss:%pM\n", __func__,
381 info->aid, info->bssid);
382 /* FIXME: need to store bssid in bsscfg */
383 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
386 if (changed & BSS_CHANGED_BEACON) {
387 /* Beacon data changed, retrieve new beacon (beaconing modes) */
388 WL_ERROR("%s: beacon changed\n", __func__);
390 if (changed & BSS_CHANGED_BEACON_ENABLED) {
391 /* Beaconing should be enabled/disabled (beaconing modes) */
392 WL_ERROR("%s: Beacon enabled: %s\n", __func__,
393 info->enable_beacon ? "true" : "false");
395 if (changed & BSS_CHANGED_CQM) {
396 /* Connection quality monitor config changed */
397 WL_ERROR("%s: cqm change: threshold %d, hys %d (implement)\n",
398 __func__, info->cqm_rssi_thold, info->cqm_rssi_hyst);
400 if (changed & BSS_CHANGED_IBSS) {
401 /* IBSS join status changed */
402 WL_ERROR("%s: IBSS joined: %s (implement)\n", __func__,
403 info->ibss_joined ? "true" : "false");
405 if (changed & BSS_CHANGED_ARP_FILTER) {
406 /* Hardware ARP filter address list or state changed */
407 WL_ERROR("%s: arp filtering: enabled %s, count %d (implement)\n",
408 __func__, info->arp_filter_enabled ? "true" : "false",
411 if (changed & BSS_CHANGED_QOS) {
413 * QoS for this association was enabled/disabled.
414 * Note that it is only ever disabled for station mode.
416 WL_ERROR("%s: qos enabled: %s (implement)\n", __func__,
417 info->qos ? "true" : "false");
419 if (changed & BSS_CHANGED_IDLE) {
420 /* Idle changed for this BSS/interface */
421 WL_ERROR("%s: BSS idle: %s (implement)\n", __func__,
422 info->idle ? "true" : "false");
428 wl_ops_configure_filter(struct ieee80211_hw *hw,
429 unsigned int changed_flags,
430 unsigned int *total_flags, u64 multicast)
432 struct wl_info *wl = hw->priv;
434 changed_flags &= MAC_FILTERS;
435 *total_flags &= MAC_FILTERS;
436 if (changed_flags & FIF_PROMISC_IN_BSS)
437 WL_ERROR("FIF_PROMISC_IN_BSS\n");
438 if (changed_flags & FIF_ALLMULTI)
439 WL_ERROR("FIF_ALLMULTI\n");
440 if (changed_flags & FIF_FCSFAIL)
441 WL_ERROR("FIF_FCSFAIL\n");
442 if (changed_flags & FIF_PLCPFAIL)
443 WL_ERROR("FIF_PLCPFAIL\n");
444 if (changed_flags & FIF_CONTROL)
445 WL_ERROR("FIF_CONTROL\n");
446 if (changed_flags & FIF_OTHER_BSS)
447 WL_ERROR("FIF_OTHER_BSS\n");
448 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
449 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
451 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
452 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
453 wlc_mac_bcn_promisc_change(wl->wlc, 1);
455 wlc_mac_bcn_promisc_change(wl->wlc, 0);
456 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
464 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
466 WL_NONE("%s: Enter\n", __func__);
470 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
472 struct wl_info *wl = hw->priv;
473 WL_NONE("Scan Start\n");
475 wlc_scan_start(wl->wlc);
480 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
482 struct wl_info *wl = hw->priv;
483 WL_NONE("Scan Complete\n");
485 wlc_scan_stop(wl->wlc);
490 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
492 WL_ERROR("%s: Enter\n", __func__);
497 wl_ops_get_stats(struct ieee80211_hw *hw,
498 struct ieee80211_low_level_stats *stats)
500 struct wl_info *wl = hw->priv;
505 stats->dot11ACKFailureCount = cnt->txnoack;
506 stats->dot11RTSFailureCount = cnt->txnocts;
507 stats->dot11FCSErrorCount = cnt->rxcrc;
508 stats->dot11RTSSuccessCount = cnt->txrts;
513 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
515 struct wl_info *wl = hw->priv;
518 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
524 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
525 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
527 WL_NONE("%s: Enter\n", __func__);
530 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
537 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
538 const struct ieee80211_tx_queue_params *params)
540 struct wl_info *wl = hw->priv;
542 WL_NONE("%s: Enter (WME config)\n", __func__);
543 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
544 params->txop, params->cw_min, params->cw_max, params->aifs);
547 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
553 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
555 WL_ERROR("%s: Enter\n", __func__);
560 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
561 struct ieee80211_sta *sta)
566 struct wl_info *wl = hw->priv;
569 scb = (struct scb *)sta->drv_priv;
570 memset(scb, 0, sizeof(struct scb));
571 for (i = 0; i < NUMPRIO; i++)
572 scb->seqctl[i] = 0xFFFF;
573 scb->seqctl_nonqos = 0xFFFF;
574 scb->magic = SCB_MAGIC;
576 wl->pub->global_scb = scb;
577 wl->pub->global_ampdu = &(scb->scb_ampdu);
578 wl->pub->global_ampdu->scb = scb;
579 wl->pub->global_ampdu->max_pdu = 16;
580 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
581 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
583 sta->ht_cap.ht_supported = true;
584 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
585 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
586 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
587 IEEE80211_HT_CAP_SGI_20 |
588 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
590 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
595 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
596 struct ieee80211_sta *sta)
598 WL_NONE("%s: Enter\n", __func__);
603 wl_ops_ampdu_action(struct ieee80211_hw *hw,
604 struct ieee80211_vif *vif,
605 enum ieee80211_ampdu_mlme_action action,
606 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
609 struct scb *scb = (struct scb *)sta->drv_priv;
611 struct wl_info *wl = hw->priv;
613 ASSERT(scb->magic == SCB_MAGIC);
615 case IEEE80211_AMPDU_RX_START:
616 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
618 case IEEE80211_AMPDU_RX_STOP:
619 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
621 case IEEE80211_AMPDU_TX_START:
622 if (!wlc_aggregatable(wl->wlc, tid)) {
623 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
626 /* XXX: Use the starting sequence number provided ... */
628 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
631 case IEEE80211_AMPDU_TX_STOP:
632 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
634 case IEEE80211_AMPDU_TX_OPERATIONAL:
635 /* Not sure what to do here */
636 /* Power save wakeup */
637 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
641 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
647 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
649 struct wl_info *wl = HW_TO_WL(hw);
653 blocked = wlc_check_radio_disabled(wl->wlc);
656 WL_NONE("wl: rfkill_poll: %d\n", blocked);
657 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
660 static const struct ieee80211_ops wl_ops = {
662 .start = wl_ops_start,
664 .add_interface = wl_ops_add_interface,
665 .remove_interface = wl_ops_remove_interface,
666 .config = wl_ops_config,
667 .bss_info_changed = wl_ops_bss_info_changed,
668 .configure_filter = wl_ops_configure_filter,
669 .set_tim = wl_ops_set_tim,
670 .sw_scan_start = wl_ops_sw_scan_start,
671 .sw_scan_complete = wl_ops_sw_scan_complete,
672 .set_tsf = wl_ops_set_tsf,
673 .get_stats = wl_ops_get_stats,
674 .set_rts_threshold = wl_ops_set_rts_threshold,
675 .sta_notify = wl_ops_sta_notify,
676 .conf_tx = wl_ops_conf_tx,
677 .get_tsf = wl_ops_get_tsf,
678 .sta_add = wl_ops_sta_add,
679 .sta_remove = wl_ops_sta_remove,
680 .ampdu_action = wl_ops_ampdu_action,
681 .rfkill_poll = wl_ops_rfkill_poll,
684 static int wl_set_hint(struct wl_info *wl, char *abbrev)
686 WL_NONE("%s: Sending country code %c%c to MAC80211\n",
687 __func__, abbrev[0], abbrev[1]);
688 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
692 * attach to the WL device.
694 * Attach to the WL device identified by vendor and device parameters.
695 * regs is a host accessible memory address pointing to WL device registers.
697 * wl_attach is not defined as static because in the case where no bus
698 * is defined, wl_attach will never be called, and thus, gcc will issue
699 * a warning that this function is defined but not used if we declare
702 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
703 uint bustype, void *btparam, uint irq)
706 struct osl_info *osh;
709 unsigned long base_addr;
710 struct ieee80211_hw *hw;
717 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
721 osh = osl_attach(btparam, bustype);
724 /* allocate private info */
725 hw = pci_get_drvdata(btparam); /* btparam == pdev */
730 atomic_set(&wl->callbacks, 0);
732 /* setup the bottom half handler */
733 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
739 if (bustype == PCI_BUS) {
741 } else if (bustype == RPC_BUS) {
745 WL_TRACE("force to PCI\n");
747 wl->bcm_bustype = bustype;
749 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
750 if (wl->regsva == NULL) {
751 WL_ERROR("wl%d: ioremap() failed\n", unit);
754 spin_lock_init(&wl->lock);
755 spin_lock_init(&wl->isr_lock);
758 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
759 WL_ERROR("%s: Failed to find firmware usually in %s\n",
760 KBUILD_MODNAME, "/lib/firmware/brcm");
762 wl_remove((struct pci_dev *)btparam);
766 /* common load-time initialization */
767 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
768 wl->regsva, wl->bcm_bustype, btparam, &err);
771 WL_ERROR("%s: wlc_attach() failed with code %d\n",
772 KBUILD_MODNAME, err);
775 wl->pub = wlc_pub(wl->wlc);
777 wl->pub->ieee_hw = hw;
778 ASSERT(wl->pub->ieee_hw);
779 ASSERT(wl->pub->ieee_hw->priv == wl);
782 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
783 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
786 /* register our interrupt handler */
787 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
788 WL_ERROR("wl%d: request_irq() failed\n", unit);
793 /* register module */
794 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
797 if (ieee_hw_init(hw)) {
798 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
802 bcopy(&wl->pub->cur_etheraddr, perm, ETH_ALEN);
803 ASSERT(is_valid_ether_addr(perm));
804 SET_IEEE80211_PERM_ADDR(hw, perm);
806 err = ieee80211_register_hw(hw);
808 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
812 if (wl->pub->srom_ccode[0])
813 err = wl_set_hint(wl, wl->pub->srom_ccode);
815 err = wl_set_hint(wl, "US");
817 WL_ERROR("%s: regulatory_hint failed, status %d\n",
832 #define CHAN2GHZ(channel, freqency, chflags) { \
833 .band = IEEE80211_BAND_2GHZ, \
834 .center_freq = (freqency), \
835 .hw_value = (channel), \
837 .max_antenna_gain = 0, \
841 static struct ieee80211_channel wl_2ghz_chantable[] = {
842 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
843 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
844 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
845 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
846 CHAN2GHZ(5, 2432, 0),
847 CHAN2GHZ(6, 2437, 0),
848 CHAN2GHZ(7, 2442, 0),
849 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
850 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
851 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
852 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
854 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
855 IEEE80211_CHAN_NO_HT40PLUS),
857 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
858 IEEE80211_CHAN_NO_HT40PLUS),
860 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
861 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
864 #define CHAN5GHZ(channel, chflags) { \
865 .band = IEEE80211_BAND_5GHZ, \
866 .center_freq = 5000 + 5*(channel), \
867 .hw_value = (channel), \
869 .max_antenna_gain = 0, \
873 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
875 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
876 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
877 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
878 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
881 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
882 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
884 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
885 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
887 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
888 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
890 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
891 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
894 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
895 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
897 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
898 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
900 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
901 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
903 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
904 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
906 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
907 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
909 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
910 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
912 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
913 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
915 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
916 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
918 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
919 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
921 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
922 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
924 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
925 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
926 IEEE80211_CHAN_NO_HT40MINUS),
928 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
929 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
930 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
931 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
932 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
935 #define RATE(rate100m, _flags) { \
936 .bitrate = (rate100m), \
938 .hw_value = (rate100m / 5), \
941 static struct ieee80211_rate wl_legacy_ratetable[] = {
943 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
944 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
945 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
956 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
957 .band = IEEE80211_BAND_2GHZ,
958 .channels = wl_2ghz_chantable,
959 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
960 .bitrates = wl_legacy_ratetable,
961 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
963 /* from include/linux/ieee80211.h */
964 .cap = IEEE80211_HT_CAP_GRN_FLD |
965 IEEE80211_HT_CAP_SGI_20 |
966 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
967 .ht_supported = true,
968 .ampdu_factor = AMPDU_RX_FACTOR_64K,
969 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
971 /* placeholders for now */
972 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
974 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
978 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
979 .band = IEEE80211_BAND_5GHZ,
980 .channels = wl_5ghz_nphy_chantable,
981 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
982 .bitrates = wl_legacy_ratetable + 4,
983 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
985 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
986 .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 */
987 .ht_supported = true,
988 .ampdu_factor = AMPDU_RX_FACTOR_64K,
989 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
991 /* placeholders for now */
992 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
994 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
998 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1000 struct wl_info *wl = HW_TO_WL(hw);
1006 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1007 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1009 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1010 WL_ERROR("Phy list failed\n");
1012 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
1014 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1015 if (phy_list[0] == 'c') {
1017 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1018 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1020 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1026 /* Assume all bands use the same phy. True for 11n devices. */
1027 if (NBANDS_PUB(wl->pub) > 1) {
1029 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1030 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1037 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1042 static int ieee_hw_init(struct ieee80211_hw *hw)
1044 hw->flags = IEEE80211_HW_SIGNAL_DBM
1045 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1046 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1047 | IEEE80211_HW_AMPDU_AGGREGATION;
1049 hw->extra_tx_headroom = wlc_get_header_len();
1050 /* FIXME: should get this from wlc->machwcap */
1052 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1053 * mac80211/status.c:ieee80211_tx_status() checks this value,
1054 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1055 * appears to always set 3 rates
1057 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1059 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1060 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1062 hw->rate_control_algorithm = "minstrel_ht";
1064 hw->sta_data_size = sizeof(struct scb);
1065 return ieee_hw_rate_init(hw);
1069 * determines if a device is a WL device, and if so, attaches it.
1071 * This function determines if a device pointed to by pdev is a WL device,
1072 * and if so, performs a wl_attach() on it.
1076 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1080 struct ieee80211_hw *hw;
1085 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1086 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1087 PCI_FUNC(pdev->devfn), pdev->irq);
1089 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1090 (((pdev->device & 0xff00) != 0x4300) &&
1091 ((pdev->device & 0xff00) != 0x4700) &&
1092 ((pdev->device < 43000) || (pdev->device > 43999))))
1095 rc = pci_enable_device(pdev);
1097 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1098 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1099 PCI_FUNC(pdev->devfn));
1102 pci_set_master(pdev);
1104 pci_read_config_dword(pdev, 0x40, &val);
1105 if ((val & 0x0000ff00) != 0)
1106 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1108 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1110 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1115 SET_IEEE80211_DEV(hw, &pdev->dev);
1117 pci_set_drvdata(pdev, hw);
1119 memset(hw->priv, 0, sizeof(*wl));
1121 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1122 PCI_BUS, pdev, pdev->irq);
1125 WL_ERROR("%s: %s: wl_attach failed!\n",
1126 KBUILD_MODNAME, __func__);
1131 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1135 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1138 struct ieee80211_hw *hw;
1140 WL_TRACE("wl: wl_suspend\n");
1142 hw = pci_get_drvdata(pdev);
1145 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1149 /* only need to flag hw is down for proper resume */
1151 wl->pub->hw_up = false;
1154 pci_save_state(pdev);
1155 pci_disable_device(pdev);
1156 return pci_set_power_state(pdev, PCI_D3hot);
1159 static int wl_resume(struct pci_dev *pdev)
1162 struct ieee80211_hw *hw;
1166 WL_TRACE("wl: wl_resume\n");
1167 hw = pci_get_drvdata(pdev);
1170 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1174 err = pci_set_power_state(pdev, PCI_D0);
1178 pci_restore_state(pdev);
1180 err = pci_enable_device(pdev);
1184 pci_set_master(pdev);
1186 pci_read_config_dword(pdev, 0x40, &val);
1187 if ((val & 0x0000ff00) != 0)
1188 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1191 * done. driver will be put in up state
1192 * in wl_ops_add_interface() call.
1197 static void wl_remove(struct pci_dev *pdev)
1200 struct ieee80211_hw *hw;
1202 hw = pci_get_drvdata(pdev);
1205 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1209 /* make sure rfkill is not using driver */
1210 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1211 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1213 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1214 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1218 ieee80211_unregister_hw(hw);
1222 WL_NONE("%s: Down\n", __func__);
1224 pci_disable_device(pdev);
1228 pci_set_drvdata(pdev, NULL);
1229 ieee80211_free_hw(hw);
1232 static struct pci_driver wl_pci_driver = {
1233 .name = KBUILD_MODNAME,
1234 .probe = wl_pci_probe,
1235 .suspend = wl_suspend,
1236 .resume = wl_resume,
1237 .remove = __devexit_p(wl_remove),
1238 .id_table = wl_id_table,
1242 * This is the main entry point for the WL driver.
1244 * This function determines if a device pointed to by pdev is a WL device,
1245 * and if so, performs a wl_attach() on it.
1248 static int __init wl_module_init(void)
1250 int error = -ENODEV;
1253 if (msglevel != 0xdeadbeef)
1254 wl_msg_level = msglevel;
1256 char *var = getvar(NULL, "wl_msglevel");
1258 wl_msg_level = simple_strtoul(var, NULL, 0);
1261 extern u32 phyhal_msg_level;
1263 if (phymsglevel != 0xdeadbeef)
1264 phyhal_msg_level = phymsglevel;
1266 char *var = getvar(NULL, "phy_msglevel");
1268 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1273 error = pci_register_driver(&wl_pci_driver);
1283 * This function unloads the WL driver from the system.
1285 * This function unconditionally unloads the WL driver module from the
1289 static void __exit wl_module_exit(void)
1291 pci_unregister_driver(&wl_pci_driver);
1295 module_init(wl_module_init);
1296 module_exit(wl_module_exit);
1299 * This function frees the WL per-device resources.
1301 * This function frees resources owned by the WL device pointed to
1302 * by the wl parameter.
1305 void wl_free(struct wl_info *wl)
1307 wl_timer_t *t, *next;
1308 struct osl_info *osh;
1311 /* free ucode data */
1313 wl_ucode_data_free();
1315 free_irq(wl->irq, wl);
1318 tasklet_kill(&wl->tasklet);
1321 wlc_module_unregister(wl->pub, "linux", wl);
1324 /* free common resources */
1326 wlc_detach(wl->wlc);
1331 /* virtual interface deletion is deferred so we cannot spinwait */
1333 /* wait for all pending callbacks to complete */
1334 while (atomic_read(&wl->callbacks) > 0)
1338 for (t = wl->timers; t; t = next) {
1350 * unregister_netdev() calls get_stats() which may read chip registers
1351 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1353 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1354 wl->bcm_bustype != JTAG_BUS) {
1355 iounmap((void *)wl->regsva);
1363 /* transmit a packet */
1364 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1369 return wl_start_int(wl, WL_TO_HW(wl), skb);
1372 static int BCMFASTPATH
1373 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1375 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1376 return NETDEV_TX_OK;
1379 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1382 WL_ERROR("Shouldn't be here %s\n", __func__);
1385 void wl_init(struct wl_info *wl)
1387 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1394 uint wl_reset(struct wl_info *wl)
1396 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1400 /* dpc will not be rescheduled */
1407 * These are interrupt on/off entry points. Disable interrupts
1408 * during interrupt state transition.
1410 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1412 unsigned long flags;
1414 INT_LOCK(wl, flags);
1415 wlc_intrson(wl->wlc);
1416 INT_UNLOCK(wl, flags);
1419 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1424 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1426 unsigned long flags;
1429 INT_LOCK(wl, flags);
1430 status = wlc_intrsoff(wl->wlc);
1431 INT_UNLOCK(wl, flags);
1435 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1437 unsigned long flags;
1439 INT_LOCK(wl, flags);
1440 wlc_intrsrestore(wl->wlc, macintmask);
1441 INT_UNLOCK(wl, flags);
1444 int wl_up(struct wl_info *wl)
1451 error = wlc_up(wl->wlc);
1456 void wl_down(struct wl_info *wl)
1458 uint callbacks, ret_val = 0;
1460 /* call common down function */
1461 ret_val = wlc_down(wl->wlc);
1462 callbacks = atomic_read(&wl->callbacks) - ret_val;
1464 /* wait for down callbacks to complete */
1467 /* For HIGH_only driver, it's important to actually schedule other work,
1468 * not just spin wait since everything runs at schedule level
1470 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1475 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1479 unsigned long flags;
1481 wl = (struct wl_info *) dev_id;
1483 WL_ISRLOCK(wl, flags);
1485 /* call common first level interrupt handler */
1486 ours = wlc_isr(wl->wlc, &wantdpc);
1488 /* if more to do... */
1491 /* ...and call the second level interrupt handler */
1493 ASSERT(wl->resched == false);
1494 tasklet_schedule(&wl->tasklet);
1498 WL_ISRUNLOCK(wl, flags);
1500 return IRQ_RETVAL(ours);
1503 static void BCMFASTPATH wl_dpc(unsigned long data)
1507 wl = (struct wl_info *) data;
1511 /* call the common second level interrupt handler */
1514 unsigned long flags;
1516 INT_LOCK(wl, flags);
1517 wlc_intrsupd(wl->wlc);
1518 INT_UNLOCK(wl, flags);
1521 wl->resched = wlc_dpc(wl->wlc, true);
1524 /* wlc_dpc() may bring the driver down */
1528 /* re-schedule dpc */
1530 tasklet_schedule(&wl->tasklet);
1532 /* re-enable interrupts */
1540 static void wl_link_up(struct wl_info *wl, char *ifname)
1542 WL_NONE("wl%d: link up (%s)\n", wl->pub->unit, ifname);
1545 static void wl_link_down(struct wl_info *wl, char *ifname)
1547 WL_NONE("wl%d: link down (%s)\n", wl->pub->unit, ifname);
1550 void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
1553 switch (e->event.event_type) {
1555 case WLC_E_NDIS_LINK:
1556 if (e->event.flags & WLC_EVENT_MSG_LINK)
1557 wl_link_up(wl, ifname);
1559 wl_link_down(wl, ifname);
1566 static void wl_timer(unsigned long data)
1568 _wl_timer((wl_timer_t *) data);
1571 static void _wl_timer(wl_timer_t *t)
1577 t->timer.expires = jiffies + t->ms * HZ / 1000;
1578 atomic_inc(&t->wl->callbacks);
1579 add_timer(&t->timer);
1587 atomic_dec(&t->wl->callbacks);
1592 wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1597 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1599 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1603 memset(t, 0, sizeof(wl_timer_t));
1605 init_timer(&t->timer);
1606 t->timer.data = (unsigned long) t;
1607 t->timer.function = wl_timer;
1611 t->next = wl->timers;
1615 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1617 strcpy(t->name, name);
1623 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1624 * as well as it's easier to make it periodic
1626 void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1630 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1631 __func__, t->name, periodic);
1637 t->periodic = (bool) periodic;
1639 t->timer.expires = jiffies + ms * HZ / 1000;
1641 atomic_inc(&wl->callbacks);
1642 add_timer(&t->timer);
1645 /* return true if timer successfully deleted, false if still pending */
1646 bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1650 if (!del_timer(&t->timer)) {
1653 atomic_dec(&wl->callbacks);
1659 void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1663 /* delete the timer in case it is active */
1664 wl_del_timer(wl, t);
1666 if (wl->timers == t) {
1667 wl->timers = wl->timers->next;
1679 if (tmp->next == t) {
1680 tmp->next = t->next;
1693 static int wl_linux_watchdog(void *ctx)
1695 struct wl_info *wl = (struct wl_info *) ctx;
1697 struct net_device_stats *stats = NULL;
1701 ASSERT(wl->stats_id < 2);
1703 cnt = wl->pub->_cnt;
1704 id = 1 - wl->stats_id;
1705 stats = &wl->stats_watchdog[id];
1706 stats->rx_packets = cnt->rxframe;
1707 stats->tx_packets = cnt->txframe;
1708 stats->rx_bytes = cnt->rxbyte;
1709 stats->tx_bytes = cnt->txbyte;
1710 stats->rx_errors = cnt->rxerror;
1711 stats->tx_errors = cnt->txerror;
1712 stats->collisions = 0;
1714 stats->rx_length_errors = 0;
1715 stats->rx_over_errors = cnt->rxoflo;
1716 stats->rx_crc_errors = cnt->rxcrc;
1717 stats->rx_frame_errors = 0;
1718 stats->rx_fifo_errors = cnt->rxoflo;
1719 stats->rx_missed_errors = 0;
1721 stats->tx_fifo_errors = cnt->txuflo;
1735 char *wl_firmwares[WL_MAX_FW] = {
1740 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1744 struct wl_fw_hdr *hdr;
1745 for (i = 0; i < wl->fw.fw_cnt; i++) {
1746 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1747 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1749 if (hdr->idx == idx) {
1750 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1751 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1752 if (*pbuf == NULL) {
1753 WL_ERROR("fail to alloc %d bytes\n",
1757 bcopy(pdata, *pbuf, hdr->len);
1762 WL_ERROR("ERROR: ucode buf tag:%d can not be found!\n", idx);
1768 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1772 struct wl_fw_hdr *hdr;
1773 for (i = 0; i < wl->fw.fw_cnt; i++) {
1774 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1775 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1777 if (hdr->idx == idx) {
1778 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1779 ASSERT(hdr->len == 4);
1780 *data = *((u32 *) pdata);
1785 WL_ERROR("ERROR: ucode tag:%d can not be found!\n", idx);
1789 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1792 struct device *device = &pdev->dev;
1796 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1797 for (i = 0; i < WL_MAX_FW; i++) {
1798 if (wl_firmwares[i] == NULL)
1800 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1801 UCODE_LOADER_API_VER);
1802 WL_NONE("request fw %s\n", fw_name);
1803 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1805 WL_ERROR("%s: fail to load firmware %s\n",
1806 KBUILD_MODNAME, fw_name);
1810 WL_NONE("request fw %s\n", fw_name);
1811 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1812 UCODE_LOADER_API_VER);
1813 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1815 WL_ERROR("%s: fail to load firmware %s\n",
1816 KBUILD_MODNAME, fw_name);
1820 wl->fw.hdr_num_entries[i] =
1821 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1822 WL_NONE("request fw %s find: %d entries\n",
1823 fw_name, wl->fw.hdr_num_entries[i]);
1826 return wl_ucode_data_init(wl);
1829 void wl_ucode_free_buf(void *p)
1834 static void wl_release_fw(struct wl_info *wl)
1837 for (i = 0; i < WL_MAX_FW; i++) {
1838 release_firmware(wl->fw.fw_bin[i]);
1839 release_firmware(wl->fw.fw_hdr[i]);
1845 * checks validity of all firmware images loaded from user space
1847 int wl_check_firmwares(struct wl_info *wl)
1852 const struct firmware *fw;
1853 const struct firmware *fw_hdr;
1854 struct wl_fw_hdr *ucode_hdr;
1855 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1856 fw = wl->fw.fw_bin[i];
1857 fw_hdr = wl->fw.fw_hdr[i];
1858 if (fw == NULL && fw_hdr == NULL) {
1860 } else if (fw == NULL || fw_hdr == NULL) {
1861 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1863 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1864 WL_ERROR("%s: non integral fw hdr file size %d/%zu\n",
1865 __func__, fw_hdr->size,
1866 sizeof(struct wl_fw_hdr));
1868 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1869 WL_ERROR("%s: out of bounds fw file size %d\n",
1870 __func__, fw->size);
1873 /* check if ucode section overruns firmware image */
1874 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1875 for (entry = 0; entry < wl->fw.hdr_num_entries[i] && rc;
1876 entry++, ucode_hdr++) {
1877 if (ucode_hdr->offset + ucode_hdr->len >
1879 WL_ERROR("%s: conflicting bin/hdr\n",
1886 if (rc == 0 && wl->fw.fw_cnt != i) {
1887 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1893 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1895 bool blocked = wlc_check_radio_disabled(wl->wlc);
1897 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
1898 blocked ? "true" : "false");
1899 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1901 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);