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);
174 ieee80211_wake_queues(hw);
176 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;
188 ieee80211_stop_queues(hw);
193 wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
198 /* Just STA for now */
199 if (vif->type != NL80211_IFTYPE_AP &&
200 vif->type != NL80211_IFTYPE_MESH_POINT &&
201 vif->type != NL80211_IFTYPE_STATION &&
202 vif->type != NL80211_IFTYPE_WDS &&
203 vif->type != NL80211_IFTYPE_ADHOC) {
204 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
205 __func__, vif->type);
215 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
221 wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
227 /* put driver in down state */
234 * precondition: perimeter lock has been acquired
237 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
238 enum nl80211_channel_type type)
240 struct wl_info *wl = HW_TO_WL(hw);
244 case NL80211_CHAN_HT20:
245 case NL80211_CHAN_NO_HT:
246 err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value);
248 case NL80211_CHAN_HT40MINUS:
249 case NL80211_CHAN_HT40PLUS:
250 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
260 static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
262 struct ieee80211_conf *conf = &hw->conf;
263 struct wl_info *wl = HW_TO_WL(hw);
268 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
270 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
271 WL_ERROR("%s: Error setting listen_interval\n",
276 wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int);
277 ASSERT(new_int == conf->listen_interval);
279 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
280 WL_ERROR("%s: change monitor mode: %s (implement)\n", __func__,
281 conf->flags & IEEE80211_CONF_MONITOR ?
283 if (changed & IEEE80211_CONF_CHANGE_PS)
284 WL_ERROR("%s: change power-save mode: %s (implement)\n",
285 __func__, conf->flags & IEEE80211_CONF_PS ?
288 if (changed & IEEE80211_CONF_CHANGE_POWER) {
290 (wl->wlc, "qtxpower", conf->power_level * 4)) {
291 WL_ERROR("%s: Error setting power_level\n", __func__);
295 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
296 if (new_int != (conf->power_level * 4))
297 WL_ERROR("%s: Power level req != actual, %d %d\n",
298 __func__, conf->power_level * 4, new_int);
300 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
301 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
303 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
305 (wl->wlc, WLC_SET_SRL,
306 conf->short_frame_max_tx_count) < 0) {
307 WL_ERROR("%s: Error setting srl\n", __func__);
311 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
313 WL_ERROR("%s: Error setting lrl\n", __func__);
325 wl_ops_bss_info_changed(struct ieee80211_hw *hw,
326 struct ieee80211_vif *vif,
327 struct ieee80211_bss_conf *info, u32 changed)
329 struct wl_info *wl = HW_TO_WL(hw);
332 if (changed & BSS_CHANGED_ASSOC) {
333 /* association status changed (associated/disassociated)
334 * also implies a change in the AID.
336 WL_ERROR("%s: %s: %sassociated\n", KBUILD_MODNAME, __func__,
337 info->assoc ? "" : "dis");
338 wlc_associate_upd(wl->wlc, info->assoc);
340 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
341 /* CTS protection changed */
342 WL_ERROR("%s: use_cts_prot: %s (implement)\n", __func__,
343 info->use_cts_prot ? "true" : "false");
345 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
346 /* preamble changed */
347 WL_ERROR("%s: short preamble: %s (implement)\n", __func__,
348 info->use_short_preamble ? "true" : "false");
350 if (changed & BSS_CHANGED_ERP_SLOT) {
351 /* slot timing changed */
352 if (info->use_short_slot)
357 wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val);
361 if (changed & BSS_CHANGED_HT) {
362 /* 802.11n parameters changed */
363 u16 mode = info->ht_operation_mode;
364 WL_NONE("%s: HT mode: 0x%04X\n", __func__, mode);
365 wlc_protection_upd(wl->wlc, WLC_PROT_N_CFG,
366 mode & IEEE80211_HT_OP_MODE_PROTECTION);
367 wlc_protection_upd(wl->wlc, WLC_PROT_N_NONGF,
368 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
369 wlc_protection_upd(wl->wlc, WLC_PROT_N_OBSS,
370 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
372 if (changed & BSS_CHANGED_BASIC_RATES) {
373 /* Basic rateset changed */
374 WL_ERROR("%s: Need to change Basic Rates: 0x%x (implement)\n",
375 __func__, (u32) info->basic_rates);
377 if (changed & BSS_CHANGED_BEACON_INT) {
378 /* Beacon interval changed */
379 WL_NONE("%s: Beacon Interval: %d\n",
380 __func__, info->beacon_int);
381 wlc_set(wl->wlc, WLC_SET_BCNPRD, info->beacon_int);
383 if (changed & BSS_CHANGED_BSSID) {
384 /* BSSID changed, for whatever reason (IBSS and managed mode) */
385 WL_NONE("%s: new BSSID: aid %d bss:%pM\n", __func__,
386 info->aid, info->bssid);
388 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
392 if (changed & BSS_CHANGED_BEACON) {
393 /* Beacon data changed, retrieve new beacon (beaconing modes) */
394 WL_ERROR("%s: beacon changed\n", __func__);
396 if (changed & BSS_CHANGED_BEACON_ENABLED) {
397 /* Beaconing should be enabled/disabled (beaconing modes) */
398 WL_ERROR("%s: Beacon enabled: %s\n", __func__,
399 info->enable_beacon ? "true" : "false");
401 if (changed & BSS_CHANGED_CQM) {
402 /* Connection quality monitor config changed */
403 WL_ERROR("%s: cqm change: threshold %d, hys %d (implement)\n",
404 __func__, info->cqm_rssi_thold, info->cqm_rssi_hyst);
406 if (changed & BSS_CHANGED_IBSS) {
407 /* IBSS join status changed */
408 WL_ERROR("%s: IBSS joined: %s (implement)\n", __func__,
409 info->ibss_joined ? "true" : "false");
411 if (changed & BSS_CHANGED_ARP_FILTER) {
412 /* Hardware ARP filter address list or state changed */
413 WL_ERROR("%s: arp filtering: enabled %s, count %d (implement)\n",
414 __func__, info->arp_filter_enabled ? "true" : "false",
417 if (changed & BSS_CHANGED_QOS) {
419 * QoS for this association was enabled/disabled.
420 * Note that it is only ever disabled for station mode.
422 WL_ERROR("%s: qos enabled: %s (implement)\n", __func__,
423 info->qos ? "true" : "false");
425 if (changed & BSS_CHANGED_IDLE) {
426 /* Idle changed for this BSS/interface */
427 WL_ERROR("%s: BSS idle: %s (implement)\n", __func__,
428 info->idle ? "true" : "false");
434 wl_ops_configure_filter(struct ieee80211_hw *hw,
435 unsigned int changed_flags,
436 unsigned int *total_flags, u64 multicast)
438 struct wl_info *wl = hw->priv;
440 changed_flags &= MAC_FILTERS;
441 *total_flags &= MAC_FILTERS;
442 if (changed_flags & FIF_PROMISC_IN_BSS)
443 WL_ERROR("FIF_PROMISC_IN_BSS\n");
444 if (changed_flags & FIF_ALLMULTI)
445 WL_ERROR("FIF_ALLMULTI\n");
446 if (changed_flags & FIF_FCSFAIL)
447 WL_ERROR("FIF_FCSFAIL\n");
448 if (changed_flags & FIF_PLCPFAIL)
449 WL_ERROR("FIF_PLCPFAIL\n");
450 if (changed_flags & FIF_CONTROL)
451 WL_ERROR("FIF_CONTROL\n");
452 if (changed_flags & FIF_OTHER_BSS)
453 WL_ERROR("FIF_OTHER_BSS\n");
454 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
455 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
457 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
458 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
459 wlc_mac_bcn_promisc_change(wl->wlc, 1);
461 wlc_mac_bcn_promisc_change(wl->wlc, 0);
462 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
470 wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
472 WL_NONE("%s: Enter\n", __func__);
476 static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
478 struct wl_info *wl = hw->priv;
479 WL_NONE("Scan Start\n");
481 wlc_scan_start(wl->wlc);
486 static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
488 struct wl_info *wl = hw->priv;
489 WL_NONE("Scan Complete\n");
491 wlc_scan_stop(wl->wlc);
496 static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
498 WL_ERROR("%s: Enter\n", __func__);
503 wl_ops_get_stats(struct ieee80211_hw *hw,
504 struct ieee80211_low_level_stats *stats)
506 struct wl_info *wl = hw->priv;
511 stats->dot11ACKFailureCount = cnt->txnoack;
512 stats->dot11RTSFailureCount = cnt->txnocts;
513 stats->dot11FCSErrorCount = cnt->rxcrc;
514 stats->dot11RTSSuccessCount = cnt->txrts;
519 static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
521 struct wl_info *wl = hw->priv;
524 wlc_iovar_setint(wl->wlc, "rtsthresh", value & 0xFFFF);
530 wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
531 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
533 WL_NONE("%s: Enter\n", __func__);
536 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
543 wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
544 const struct ieee80211_tx_queue_params *params)
546 struct wl_info *wl = hw->priv;
548 WL_NONE("%s: Enter (WME config)\n", __func__);
549 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
550 params->txop, params->cw_min, params->cw_max, params->aifs);
553 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
559 static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
561 WL_ERROR("%s: Enter\n", __func__);
566 wl_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
567 struct ieee80211_sta *sta)
572 struct wl_info *wl = hw->priv;
575 scb = (struct scb *)sta->drv_priv;
576 memset(scb, 0, sizeof(struct scb));
577 for (i = 0; i < NUMPRIO; i++)
578 scb->seqctl[i] = 0xFFFF;
579 scb->seqctl_nonqos = 0xFFFF;
580 scb->magic = SCB_MAGIC;
582 wl->pub->global_scb = scb;
583 wl->pub->global_ampdu = &(scb->scb_ampdu);
584 wl->pub->global_ampdu->scb = scb;
585 wl->pub->global_ampdu->max_pdu = 16;
586 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
587 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
589 sta->ht_cap.ht_supported = true;
590 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
591 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
592 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
593 IEEE80211_HT_CAP_SGI_20 |
594 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
596 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
601 wl_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
602 struct ieee80211_sta *sta)
604 WL_NONE("%s: Enter\n", __func__);
609 wl_ops_ampdu_action(struct ieee80211_hw *hw,
610 struct ieee80211_vif *vif,
611 enum ieee80211_ampdu_mlme_action action,
612 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
615 struct scb *scb = (struct scb *)sta->drv_priv;
617 struct wl_info *wl = hw->priv;
620 ASSERT(scb->magic == SCB_MAGIC);
622 case IEEE80211_AMPDU_RX_START:
623 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
625 case IEEE80211_AMPDU_RX_STOP:
626 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
628 case IEEE80211_AMPDU_TX_START:
630 status = wlc_aggregatable(wl->wlc, tid);
633 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
636 /* XXX: Use the starting sequence number provided ... */
638 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
641 case IEEE80211_AMPDU_TX_STOP:
642 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
644 case IEEE80211_AMPDU_TX_OPERATIONAL:
645 /* Not sure what to do here */
646 /* Power save wakeup */
647 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
651 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
657 static void wl_ops_rfkill_poll(struct ieee80211_hw *hw)
659 struct wl_info *wl = HW_TO_WL(hw);
663 blocked = wlc_check_radio_disabled(wl->wlc);
666 WL_NONE("wl: rfkill_poll: %d\n", blocked);
667 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
670 static const struct ieee80211_ops wl_ops = {
672 .start = wl_ops_start,
674 .add_interface = wl_ops_add_interface,
675 .remove_interface = wl_ops_remove_interface,
676 .config = wl_ops_config,
677 .bss_info_changed = wl_ops_bss_info_changed,
678 .configure_filter = wl_ops_configure_filter,
679 .set_tim = wl_ops_set_tim,
680 .sw_scan_start = wl_ops_sw_scan_start,
681 .sw_scan_complete = wl_ops_sw_scan_complete,
682 .set_tsf = wl_ops_set_tsf,
683 .get_stats = wl_ops_get_stats,
684 .set_rts_threshold = wl_ops_set_rts_threshold,
685 .sta_notify = wl_ops_sta_notify,
686 .conf_tx = wl_ops_conf_tx,
687 .get_tsf = wl_ops_get_tsf,
688 .sta_add = wl_ops_sta_add,
689 .sta_remove = wl_ops_sta_remove,
690 .ampdu_action = wl_ops_ampdu_action,
691 .rfkill_poll = wl_ops_rfkill_poll,
695 * is called in wl_pci_probe() context, therefore no locking required.
697 static int wl_set_hint(struct wl_info *wl, char *abbrev)
699 WL_NONE("%s: Sending country code %c%c to MAC80211\n",
700 __func__, abbrev[0], abbrev[1]);
701 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
705 * attach to the WL device.
707 * Attach to the WL device identified by vendor and device parameters.
708 * regs is a host accessible memory address pointing to WL device registers.
710 * wl_attach is not defined as static because in the case where no bus
711 * is defined, wl_attach will never be called, and thus, gcc will issue
712 * a warning that this function is defined but not used if we declare
716 * is called in wl_pci_probe() context, therefore no locking required.
718 static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
719 uint bustype, void *btparam, uint irq)
722 struct osl_info *osh;
725 unsigned long base_addr;
726 struct ieee80211_hw *hw;
733 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
737 osh = osl_attach(btparam, bustype);
740 /* allocate private info */
741 hw = pci_get_drvdata(btparam); /* btparam == pdev */
746 atomic_set(&wl->callbacks, 0);
748 /* setup the bottom half handler */
749 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
755 if (bustype == PCI_BUS) {
757 } else if (bustype == RPC_BUS) {
761 WL_TRACE("force to PCI\n");
763 wl->bcm_bustype = bustype;
765 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
766 if (wl->regsva == NULL) {
767 WL_ERROR("wl%d: ioremap() failed\n", unit);
770 spin_lock_init(&wl->lock);
771 spin_lock_init(&wl->isr_lock);
774 if (wl_request_fw(wl, (struct pci_dev *)btparam) < 0) {
775 WL_ERROR("%s: Failed to find firmware usually in %s\n",
776 KBUILD_MODNAME, "/lib/firmware/brcm");
778 wl_remove((struct pci_dev *)btparam);
782 /* common load-time initialization */
783 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
784 wl->regsva, wl->bcm_bustype, btparam, &err);
787 WL_ERROR("%s: wlc_attach() failed with code %d\n",
788 KBUILD_MODNAME, err);
791 wl->pub = wlc_pub(wl->wlc);
793 wl->pub->ieee_hw = hw;
794 ASSERT(wl->pub->ieee_hw);
795 ASSERT(wl->pub->ieee_hw->priv == wl);
798 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
799 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
802 /* register our interrupt handler */
803 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
804 WL_ERROR("wl%d: request_irq() failed\n", unit);
809 /* register module */
810 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
813 if (ieee_hw_init(hw)) {
814 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
818 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
819 ASSERT(is_valid_ether_addr(perm));
820 SET_IEEE80211_PERM_ADDR(hw, perm);
822 err = ieee80211_register_hw(hw);
824 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
828 if (wl->pub->srom_ccode[0])
829 err = wl_set_hint(wl, wl->pub->srom_ccode);
831 err = wl_set_hint(wl, "US");
833 WL_ERROR("%s: regulatory_hint failed, status %d\n",
848 #define CHAN2GHZ(channel, freqency, chflags) { \
849 .band = IEEE80211_BAND_2GHZ, \
850 .center_freq = (freqency), \
851 .hw_value = (channel), \
853 .max_antenna_gain = 0, \
857 static struct ieee80211_channel wl_2ghz_chantable[] = {
858 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
859 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
860 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
861 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
862 CHAN2GHZ(5, 2432, 0),
863 CHAN2GHZ(6, 2437, 0),
864 CHAN2GHZ(7, 2442, 0),
865 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
866 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
867 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
868 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
870 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
871 IEEE80211_CHAN_NO_HT40PLUS),
873 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
874 IEEE80211_CHAN_NO_HT40PLUS),
876 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
877 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
880 #define CHAN5GHZ(channel, chflags) { \
881 .band = IEEE80211_BAND_5GHZ, \
882 .center_freq = 5000 + 5*(channel), \
883 .hw_value = (channel), \
885 .max_antenna_gain = 0, \
889 static struct ieee80211_channel wl_5ghz_nphy_chantable[] = {
891 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
892 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
893 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
894 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
897 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
898 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
900 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
901 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
903 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
904 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
906 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
907 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
910 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
911 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
913 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
914 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
916 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
917 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
919 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
920 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
922 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
923 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
925 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
926 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
928 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
929 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
931 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
932 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
934 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
935 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
937 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
938 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
940 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
941 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
942 IEEE80211_CHAN_NO_HT40MINUS),
944 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
945 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
946 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
947 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
948 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
951 #define RATE(rate100m, _flags) { \
952 .bitrate = (rate100m), \
954 .hw_value = (rate100m / 5), \
957 static struct ieee80211_rate wl_legacy_ratetable[] = {
959 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
960 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
961 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
972 static struct ieee80211_supported_band wl_band_2GHz_nphy = {
973 .band = IEEE80211_BAND_2GHZ,
974 .channels = wl_2ghz_chantable,
975 .n_channels = ARRAY_SIZE(wl_2ghz_chantable),
976 .bitrates = wl_legacy_ratetable,
977 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable),
979 /* from include/linux/ieee80211.h */
980 .cap = IEEE80211_HT_CAP_GRN_FLD |
981 IEEE80211_HT_CAP_SGI_20 |
982 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
983 .ht_supported = true,
984 .ampdu_factor = AMPDU_RX_FACTOR_64K,
985 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
987 /* placeholders for now */
988 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
990 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
994 static struct ieee80211_supported_band wl_band_5GHz_nphy = {
995 .band = IEEE80211_BAND_5GHZ,
996 .channels = wl_5ghz_nphy_chantable,
997 .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable),
998 .bitrates = wl_legacy_ratetable + 4,
999 .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4,
1001 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1002 .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 */
1003 .ht_supported = true,
1004 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1005 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1007 /* placeholders for now */
1008 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1010 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1015 * is called in wl_pci_probe() context, therefore no locking required.
1017 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1019 struct wl_info *wl = HW_TO_WL(hw);
1025 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1026 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1028 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1029 WL_ERROR("Phy list failed\n");
1031 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
1033 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1034 if (phy_list[0] == 'c') {
1036 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1037 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1039 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1045 /* Assume all bands use the same phy. True for 11n devices. */
1046 if (NBANDS_PUB(wl->pub) > 1) {
1048 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1049 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1056 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1062 * is called in wl_pci_probe() context, therefore no locking required.
1064 static int ieee_hw_init(struct ieee80211_hw *hw)
1066 hw->flags = IEEE80211_HW_SIGNAL_DBM
1067 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1068 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1069 | IEEE80211_HW_AMPDU_AGGREGATION;
1071 hw->extra_tx_headroom = wlc_get_header_len();
1072 /* FIXME: should get this from wlc->machwcap */
1074 /* FIXME: this doesn't seem to be used properly in minstrel_ht.
1075 * mac80211/status.c:ieee80211_tx_status() checks this value,
1076 * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate()
1077 * appears to always set 3 rates
1079 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1081 hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */
1082 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1084 hw->rate_control_algorithm = "minstrel_ht";
1086 hw->sta_data_size = sizeof(struct scb);
1087 return ieee_hw_rate_init(hw);
1091 * determines if a device is a WL device, and if so, attaches it.
1093 * This function determines if a device pointed to by pdev is a WL device,
1094 * and if so, performs a wl_attach() on it.
1096 * Perimeter lock is initialized in the course of this function.
1099 wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1103 struct ieee80211_hw *hw;
1108 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1109 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1110 PCI_FUNC(pdev->devfn), pdev->irq);
1112 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1113 (((pdev->device & 0xff00) != 0x4300) &&
1114 ((pdev->device & 0xff00) != 0x4700) &&
1115 ((pdev->device < 43000) || (pdev->device > 43999))))
1118 rc = pci_enable_device(pdev);
1120 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1121 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1122 PCI_FUNC(pdev->devfn));
1125 pci_set_master(pdev);
1127 pci_read_config_dword(pdev, 0x40, &val);
1128 if ((val & 0x0000ff00) != 0)
1129 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1131 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1133 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1138 SET_IEEE80211_DEV(hw, &pdev->dev);
1140 pci_set_drvdata(pdev, hw);
1142 memset(hw->priv, 0, sizeof(*wl));
1144 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1145 PCI_BUS, pdev, pdev->irq);
1148 WL_ERROR("%s: %s: wl_attach failed!\n",
1149 KBUILD_MODNAME, __func__);
1154 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1158 static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1161 struct ieee80211_hw *hw;
1163 WL_TRACE("wl: wl_suspend\n");
1165 hw = pci_get_drvdata(pdev);
1168 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1172 /* only need to flag hw is down for proper resume */
1174 wl->pub->hw_up = false;
1177 pci_save_state(pdev);
1178 pci_disable_device(pdev);
1179 return pci_set_power_state(pdev, PCI_D3hot);
1182 static int wl_resume(struct pci_dev *pdev)
1185 struct ieee80211_hw *hw;
1189 WL_TRACE("wl: wl_resume\n");
1190 hw = pci_get_drvdata(pdev);
1193 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1197 err = pci_set_power_state(pdev, PCI_D0);
1201 pci_restore_state(pdev);
1203 err = pci_enable_device(pdev);
1207 pci_set_master(pdev);
1209 pci_read_config_dword(pdev, 0x40, &val);
1210 if ((val & 0x0000ff00) != 0)
1211 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1214 * done. driver will be put in up state
1215 * in wl_ops_add_interface() call.
1221 * called from both kernel as from wl_*()
1222 * precondition: perimeter lock is not acquired.
1224 static void wl_remove(struct pci_dev *pdev)
1227 struct ieee80211_hw *hw;
1230 hw = pci_get_drvdata(pdev);
1233 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1238 status = wlc_chipmatch(pdev->vendor, pdev->device);
1241 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1245 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1246 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1247 ieee80211_unregister_hw(hw);
1251 WL_NONE("%s: Down\n", __func__);
1253 pci_disable_device(pdev);
1257 pci_set_drvdata(pdev, NULL);
1258 ieee80211_free_hw(hw);
1261 static struct pci_driver wl_pci_driver = {
1262 .name = KBUILD_MODNAME,
1263 .probe = wl_pci_probe,
1264 .suspend = wl_suspend,
1265 .resume = wl_resume,
1266 .remove = __devexit_p(wl_remove),
1267 .id_table = wl_id_table,
1271 * This is the main entry point for the WL driver.
1273 * This function determines if a device pointed to by pdev is a WL device,
1274 * and if so, performs a wl_attach() on it.
1277 static int __init wl_module_init(void)
1279 int error = -ENODEV;
1282 if (msglevel != 0xdeadbeef)
1283 wl_msg_level = msglevel;
1285 char *var = getvar(NULL, "wl_msglevel");
1287 wl_msg_level = simple_strtoul(var, NULL, 0);
1290 extern u32 phyhal_msg_level;
1292 if (phymsglevel != 0xdeadbeef)
1293 phyhal_msg_level = phymsglevel;
1295 char *var = getvar(NULL, "phy_msglevel");
1297 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1302 error = pci_register_driver(&wl_pci_driver);
1312 * This function unloads the WL driver from the system.
1314 * This function unconditionally unloads the WL driver module from the
1318 static void __exit wl_module_exit(void)
1320 pci_unregister_driver(&wl_pci_driver);
1324 module_init(wl_module_init);
1325 module_exit(wl_module_exit);
1328 * This function frees the WL per-device resources.
1330 * This function frees resources owned by the WL device pointed to
1331 * by the wl parameter.
1333 * precondition: can both be called locked and unlocked
1336 void wl_free(struct wl_info *wl)
1338 wl_timer_t *t, *next;
1339 struct osl_info *osh;
1342 /* free ucode data */
1344 wl_ucode_data_free();
1346 free_irq(wl->irq, wl);
1349 tasklet_kill(&wl->tasklet);
1352 wlc_module_unregister(wl->pub, "linux", wl);
1355 /* free common resources */
1357 wlc_detach(wl->wlc);
1362 /* virtual interface deletion is deferred so we cannot spinwait */
1364 /* wait for all pending callbacks to complete */
1365 while (atomic_read(&wl->callbacks) > 0)
1369 for (t = wl->timers; t; t = next) {
1381 * unregister_netdev() calls get_stats() which may read chip registers
1382 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1384 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1385 wl->bcm_bustype != JTAG_BUS) {
1386 iounmap((void *)wl->regsva);
1396 * precondition: perimeter lock has been acquired
1398 static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1403 return wl_start_int(wl, WL_TO_HW(wl), skb);
1406 static int BCMFASTPATH
1407 wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1409 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1410 return NETDEV_TX_OK;
1414 * precondition: perimeter lock has been acquired
1416 void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1419 WL_ERROR("Shouldn't be here %s\n", __func__);
1423 * precondition: perimeter lock has been acquired
1425 void wl_init(struct wl_info *wl)
1427 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1435 * precondition: perimeter lock has been acquired
1437 uint wl_reset(struct wl_info *wl)
1439 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1443 /* dpc will not be rescheduled */
1450 * These are interrupt on/off entry points. Disable interrupts
1451 * during interrupt state transition.
1453 void BCMFASTPATH wl_intrson(struct wl_info *wl)
1455 unsigned long flags;
1457 INT_LOCK(wl, flags);
1458 wlc_intrson(wl->wlc);
1459 INT_UNLOCK(wl, flags);
1463 * precondition: perimeter lock has been acquired
1465 bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1470 u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1472 unsigned long flags;
1475 INT_LOCK(wl, flags);
1476 status = wlc_intrsoff(wl->wlc);
1477 INT_UNLOCK(wl, flags);
1481 void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1483 unsigned long flags;
1485 INT_LOCK(wl, flags);
1486 wlc_intrsrestore(wl->wlc, macintmask);
1487 INT_UNLOCK(wl, flags);
1491 * precondition: perimeter lock has been acquired
1493 int wl_up(struct wl_info *wl)
1500 error = wlc_up(wl->wlc);
1506 * precondition: perimeter lock has been acquired
1508 void wl_down(struct wl_info *wl)
1510 uint callbacks, ret_val = 0;
1512 /* call common down function */
1513 ret_val = wlc_down(wl->wlc);
1514 callbacks = atomic_read(&wl->callbacks) - ret_val;
1516 /* wait for down callbacks to complete */
1519 /* For HIGH_only driver, it's important to actually schedule other work,
1520 * not just spin wait since everything runs at schedule level
1522 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1527 irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1531 unsigned long flags;
1533 wl = (struct wl_info *) dev_id;
1535 WL_ISRLOCK(wl, flags);
1537 /* call common first level interrupt handler */
1538 ours = wlc_isr(wl->wlc, &wantdpc);
1540 /* if more to do... */
1543 /* ...and call the second level interrupt handler */
1545 ASSERT(wl->resched == false);
1546 tasklet_schedule(&wl->tasklet);
1550 WL_ISRUNLOCK(wl, flags);
1552 return IRQ_RETVAL(ours);
1555 static void BCMFASTPATH wl_dpc(unsigned long data)
1559 wl = (struct wl_info *) data;
1563 /* call the common second level interrupt handler */
1566 unsigned long flags;
1568 INT_LOCK(wl, flags);
1569 wlc_intrsupd(wl->wlc);
1570 INT_UNLOCK(wl, flags);
1573 wl->resched = wlc_dpc(wl->wlc, true);
1576 /* wlc_dpc() may bring the driver down */
1580 /* re-schedule dpc */
1582 tasklet_schedule(&wl->tasklet);
1584 /* re-enable interrupts */
1592 static void wl_link_up(struct wl_info *wl, char *ifname)
1594 WL_NONE("wl%d: link up (%s)\n", wl->pub->unit, ifname);
1597 static void wl_link_down(struct wl_info *wl, char *ifname)
1599 WL_NONE("wl%d: link down (%s)\n", wl->pub->unit, ifname);
1603 * precondition: perimeter lock has been acquired
1605 void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
1608 switch (e->event.event_type) {
1610 case WLC_E_NDIS_LINK:
1611 if (e->event.flags & WLC_EVENT_MSG_LINK)
1612 wl_link_up(wl, ifname);
1614 wl_link_down(wl, ifname);
1622 * is called by the kernel from software irq context
1624 static void wl_timer(unsigned long data)
1626 _wl_timer((wl_timer_t *) data);
1630 * precondition: perimeter lock is not acquired
1632 static void _wl_timer(wl_timer_t *t)
1638 t->timer.expires = jiffies + t->ms * HZ / 1000;
1639 atomic_inc(&t->wl->callbacks);
1640 add_timer(&t->timer);
1648 atomic_dec(&t->wl->callbacks);
1654 * Adds a timer to the list. Caller supplies a timer function.
1655 * Is called from wlc.
1657 * precondition: perimeter lock has been acquired
1659 wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1664 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1666 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1670 memset(t, 0, sizeof(wl_timer_t));
1672 init_timer(&t->timer);
1673 t->timer.data = (unsigned long) t;
1674 t->timer.function = wl_timer;
1678 t->next = wl->timers;
1682 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1684 strcpy(t->name, name);
1690 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1691 * as well as it's easier to make it periodic
1693 * precondition: perimeter lock has been acquired
1695 void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1699 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1700 __func__, t->name, periodic);
1706 t->periodic = (bool) periodic;
1708 t->timer.expires = jiffies + ms * HZ / 1000;
1710 atomic_inc(&wl->callbacks);
1711 add_timer(&t->timer);
1715 * return true if timer successfully deleted, false if still pending
1717 * precondition: perimeter lock has been acquired
1719 bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1723 if (!del_timer(&t->timer)) {
1726 atomic_dec(&wl->callbacks);
1733 * precondition: perimeter lock has been acquired
1735 void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1739 /* delete the timer in case it is active */
1740 wl_del_timer(wl, t);
1742 if (wl->timers == t) {
1743 wl->timers = wl->timers->next;
1755 if (tmp->next == t) {
1756 tmp->next = t->next;
1770 * runs in software irq context
1772 * precondition: perimeter lock is not acquired
1774 static int wl_linux_watchdog(void *ctx)
1776 struct wl_info *wl = (struct wl_info *) ctx;
1778 struct net_device_stats *stats = NULL;
1782 ASSERT(wl->stats_id < 2);
1784 cnt = wl->pub->_cnt;
1785 id = 1 - wl->stats_id;
1786 stats = &wl->stats_watchdog[id];
1787 stats->rx_packets = cnt->rxframe;
1788 stats->tx_packets = cnt->txframe;
1789 stats->rx_bytes = cnt->rxbyte;
1790 stats->tx_bytes = cnt->txbyte;
1791 stats->rx_errors = cnt->rxerror;
1792 stats->tx_errors = cnt->txerror;
1793 stats->collisions = 0;
1795 stats->rx_length_errors = 0;
1796 stats->rx_over_errors = cnt->rxoflo;
1797 stats->rx_crc_errors = cnt->rxcrc;
1798 stats->rx_frame_errors = 0;
1799 stats->rx_fifo_errors = cnt->rxoflo;
1800 stats->rx_missed_errors = 0;
1802 stats->tx_fifo_errors = cnt->txuflo;
1816 char *wl_firmwares[WL_MAX_FW] = {
1822 * precondition: perimeter lock has been acquired
1824 int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
1828 struct wl_fw_hdr *hdr;
1829 for (i = 0; i < wl->fw.fw_cnt; i++) {
1830 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1831 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1833 if (hdr->idx == idx) {
1834 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1835 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1836 if (*pbuf == NULL) {
1837 WL_ERROR("fail to alloc %d bytes\n",
1841 memcpy(*pbuf, pdata, hdr->len);
1846 WL_ERROR("ERROR: ucode buf tag:%d can not be found!\n", idx);
1849 return BCME_NOTFOUND;
1853 * Precondition: Since this function is called in wl_pci_probe() context,
1854 * no locking is required.
1856 int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
1860 struct wl_fw_hdr *hdr;
1861 for (i = 0; i < wl->fw.fw_cnt; i++) {
1862 hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data;
1863 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1865 if (hdr->idx == idx) {
1866 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1867 ASSERT(hdr->len == 4);
1868 *data = *((u32 *) pdata);
1873 WL_ERROR("ERROR: ucode tag:%d can not be found!\n", idx);
1878 * Precondition: Since this function is called in wl_pci_probe() context,
1879 * no locking is required.
1881 static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
1884 struct device *device = &pdev->dev;
1888 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
1889 for (i = 0; i < WL_MAX_FW; i++) {
1890 if (wl_firmwares[i] == NULL)
1892 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
1893 UCODE_LOADER_API_VER);
1894 WL_NONE("request fw %s\n", fw_name);
1895 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1897 WL_ERROR("%s: fail to load firmware %s\n",
1898 KBUILD_MODNAME, fw_name);
1901 WL_NONE("request fw %s\n", fw_name);
1902 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
1903 UCODE_LOADER_API_VER);
1904 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1906 WL_ERROR("%s: fail to load firmware %s\n",
1907 KBUILD_MODNAME, fw_name);
1910 wl->fw.hdr_num_entries[i] =
1911 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
1912 WL_NONE("request fw %s find: %d entries\n",
1913 fw_name, wl->fw.hdr_num_entries[i]);
1916 return wl_ucode_data_init(wl);
1920 * precondition: can both be called locked and unlocked
1922 void wl_ucode_free_buf(void *p)
1928 * Precondition: Since this function is called in wl_pci_probe() context,
1929 * no locking is required.
1931 static void wl_release_fw(struct wl_info *wl)
1934 for (i = 0; i < WL_MAX_FW; i++) {
1935 release_firmware(wl->fw.fw_bin[i]);
1936 release_firmware(wl->fw.fw_hdr[i]);
1942 * checks validity of all firmware images loaded from user space
1944 * Precondition: Since this function is called in wl_pci_probe() context,
1945 * no locking is required.
1947 int wl_check_firmwares(struct wl_info *wl)
1952 const struct firmware *fw;
1953 const struct firmware *fw_hdr;
1954 struct wl_fw_hdr *ucode_hdr;
1955 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1956 fw = wl->fw.fw_bin[i];
1957 fw_hdr = wl->fw.fw_hdr[i];
1958 if (fw == NULL && fw_hdr == NULL) {
1960 } else if (fw == NULL || fw_hdr == NULL) {
1961 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1963 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1964 WL_ERROR("%s: non integral fw hdr file size %zu/%zu\n",
1965 __func__, fw_hdr->size,
1966 sizeof(struct wl_fw_hdr));
1968 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1969 WL_ERROR("%s: out of bounds fw file size %zu\n",
1970 __func__, fw->size);
1973 /* check if ucode section overruns firmware image */
1974 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1975 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1976 !rc; entry++, ucode_hdr++) {
1977 if (ucode_hdr->offset + ucode_hdr->len >
1979 WL_ERROR("%s: conflicting bin/hdr\n",
1986 if (rc == 0 && wl->fw.fw_cnt != i) {
1987 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1994 * precondition: perimeter lock has been acquired
1996 bool wl_rfkill_set_hw_state(struct wl_info *wl)
1998 bool blocked = wlc_check_radio_disabled(wl->wlc);
2000 WL_NONE("%s: update hw state: blocked=%s\n", __func__,
2001 blocked ? "true" : "false");
2003 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
2005 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);