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/etherdevice.h>
20 #include <linux/pci.h>
21 #include <linux/sched.h>
22 #include <linux/firmware.h>
23 #include <linux/interrupt.h>
24 #include <net/mac80211.h>
27 #include "phy/phy_int.h"
32 #include "ucode_loader.h"
33 #include "mac80211_if.h"
35 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
37 #define LOCK(wl) spin_lock_bh(&(wl)->lock)
38 #define UNLOCK(wl) spin_unlock_bh(&(wl)->lock)
40 /* locking from inside brcms_isr */
41 #define ISR_LOCK(wl, flags)\
43 spin_lock(&(wl)->isr_lock);\
47 #define ISR_UNLOCK(wl, flags)\
49 spin_unlock(&(wl)->isr_lock);\
53 /* locking under LOCK() to synchronize with brcms_isr */
54 #define INT_LOCK(wl, flags) spin_lock_irqsave(&(wl)->isr_lock, flags)
55 #define INT_UNLOCK(wl, flags) spin_unlock_irqrestore(&(wl)->isr_lock, flags)
57 static void brcms_timer(unsigned long data);
58 static void _brcms_timer(struct brcms_timer *t);
61 static int ieee_hw_init(struct ieee80211_hw *hw);
62 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
64 static int wl_linux_watchdog(void *ctx);
66 /* Flags we support */
67 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
73 FIF_BCN_PRBRESP_PROMISC)
75 static int n_adapters_found;
77 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev);
78 static void brcms_release_fw(struct brcms_info *wl);
80 /* local prototypes */
81 static void brcms_dpc(unsigned long data);
82 static irqreturn_t brcms_isr(int irq, void *dev_id);
84 static int __devinit brcms_pci_probe(struct pci_dev *pdev,
85 const struct pci_device_id *ent);
86 static void brcms_remove(struct pci_dev *pdev);
87 static void brcms_free(struct brcms_info *wl);
88 static void brcms_set_basic_rate(struct wl_rateset *rs, u16 rate, bool is_br);
90 MODULE_AUTHOR("Broadcom Corporation");
91 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
92 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
93 MODULE_LICENSE("Dual BSD/GPL");
95 /* recognized PCI IDs */
96 static DEFINE_PCI_DEVICE_TABLE(brcms_pci_id_table) = {
97 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
98 {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */
99 {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */
101 {PCI_VENDOR_ID_BROADCOM, 0x0576, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
105 MODULE_DEVICE_TABLE(pci, brcms_pci_id_table);
108 static int msglevel = 0xdeadbeef;
109 module_param(msglevel, int, 0);
110 static int phymsglevel = 0xdeadbeef;
111 module_param(phymsglevel, int, 0);
114 #define HW_TO_WL(hw) (hw->priv)
115 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
117 /* MAC80211 callback functions */
118 static int brcms_ops_start(struct ieee80211_hw *hw);
119 static void brcms_ops_stop(struct ieee80211_hw *hw);
120 static int brcms_ops_add_interface(struct ieee80211_hw *hw,
121 struct ieee80211_vif *vif);
122 static void brcms_ops_remove_interface(struct ieee80211_hw *hw,
123 struct ieee80211_vif *vif);
124 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed);
125 static void brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
126 struct ieee80211_vif *vif,
127 struct ieee80211_bss_conf *info,
129 static void brcms_ops_configure_filter(struct ieee80211_hw *hw,
130 unsigned int changed_flags,
131 unsigned int *total_flags, u64 multicast);
132 static int brcms_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
134 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw);
135 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw);
136 static void brcms_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf);
137 static int brcms_ops_get_stats(struct ieee80211_hw *hw,
138 struct ieee80211_low_level_stats *stats);
139 static void brcms_ops_sta_notify(struct ieee80211_hw *hw,
140 struct ieee80211_vif *vif,
141 enum sta_notify_cmd cmd,
142 struct ieee80211_sta *sta);
143 static int brcms_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
144 const struct ieee80211_tx_queue_params *params);
145 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw);
146 static int brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
147 struct ieee80211_sta *sta);
148 static int brcms_ops_sta_remove(struct ieee80211_hw *hw,
149 struct ieee80211_vif *vif,
150 struct ieee80211_sta *sta);
151 static int brcms_ops_ampdu_action(struct ieee80211_hw *hw,
152 struct ieee80211_vif *vif,
153 enum ieee80211_ampdu_mlme_action action,
154 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
156 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw);
157 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop);
159 static void brcms_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
161 struct brcms_info *wl = hw->priv;
165 wiphy_err(wl->wiphy, "ops->tx called while down\n");
169 brcms_c_sendpkt_mac80211(wl->wlc, skb, hw);
174 static int brcms_ops_start(struct ieee80211_hw *hw)
176 struct brcms_info *wl = hw->priv;
179 struct ieee80211_channel *curchan = hw->conf.channel;
182 ieee80211_wake_queues(hw);
184 blocked = brcms_rfkill_set_hw_state(wl);
187 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
192 static void brcms_ops_stop(struct ieee80211_hw *hw)
194 ieee80211_stop_queues(hw);
198 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
200 struct brcms_info *wl;
203 /* Just STA for now */
204 if (vif->type != NL80211_IFTYPE_AP &&
205 vif->type != NL80211_IFTYPE_MESH_POINT &&
206 vif->type != NL80211_IFTYPE_STATION &&
207 vif->type != NL80211_IFTYPE_WDS &&
208 vif->type != NL80211_IFTYPE_ADHOC) {
209 wiphy_err(hw->wiphy, "%s: Attempt to add type %d, only"
210 " STA for now\n", __func__, vif->type);
220 wiphy_err(hw->wiphy, "%s: brcms_up() returned %d\n", __func__,
227 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
229 struct brcms_info *wl;
233 /* put driver in down state */
240 * precondition: perimeter lock has been acquired
243 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
244 enum nl80211_channel_type type)
246 struct brcms_info *wl = HW_TO_WL(hw);
250 case NL80211_CHAN_HT20:
251 case NL80211_CHAN_NO_HT:
252 err = brcms_c_set(wl->wlc, BRCM_SET_CHANNEL, chan->hw_value);
254 case NL80211_CHAN_HT40MINUS:
255 case NL80211_CHAN_HT40PLUS:
257 "%s: Need to implement 40 Mhz Channels!\n", __func__);
267 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
269 struct ieee80211_conf *conf = &hw->conf;
270 struct brcms_info *wl = HW_TO_WL(hw);
273 struct wiphy *wiphy = hw->wiphy;
276 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
277 if (brcms_c_set_par(wl->wlc, IOV_BCN_LI_BCN,
278 conf->listen_interval) < 0) {
279 wiphy_err(wiphy, "%s: Error setting listen_interval\n",
284 brcms_c_get_par(wl->wlc, IOV_BCN_LI_BCN, &new_int);
286 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
287 wiphy_err(wiphy, "%s: change monitor mode: %s (implement)\n",
288 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
290 if (changed & IEEE80211_CONF_CHANGE_PS)
291 wiphy_err(wiphy, "%s: change power-save mode: %s (implement)\n",
292 __func__, conf->flags & IEEE80211_CONF_PS ?
295 if (changed & IEEE80211_CONF_CHANGE_POWER) {
296 if (brcms_c_set_par(wl->wlc, IOV_QTXPOWER,
297 conf->power_level * 4) < 0) {
298 wiphy_err(wiphy, "%s: Error setting power_level\n",
303 brcms_c_get_par(wl->wlc, IOV_QTXPOWER, &new_int);
304 if (new_int != (conf->power_level * 4))
305 wiphy_err(wiphy, "%s: Power level req != actual, %d %d"
306 "\n", __func__, conf->power_level * 4,
309 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
310 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
312 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
314 (wl->wlc, BRCM_SET_SRL,
315 conf->short_frame_max_tx_count) < 0) {
316 wiphy_err(wiphy, "%s: Error setting srl\n", __func__);
320 if (brcms_c_set(wl->wlc, BRCM_SET_LRL,
321 conf->long_frame_max_tx_count) < 0) {
322 wiphy_err(wiphy, "%s: Error setting lrl\n", __func__);
334 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
335 struct ieee80211_vif *vif,
336 struct ieee80211_bss_conf *info, u32 changed)
338 struct brcms_info *wl = HW_TO_WL(hw);
339 struct wiphy *wiphy = hw->wiphy;
342 if (changed & BSS_CHANGED_ASSOC) {
343 /* association status changed (associated/disassociated)
344 * also implies a change in the AID.
346 wiphy_err(wiphy, "%s: %s: %sassociated\n", KBUILD_MODNAME,
347 __func__, info->assoc ? "" : "dis");
349 brcms_c_associate_upd(wl->wlc, info->assoc);
352 if (changed & BSS_CHANGED_ERP_SLOT) {
353 /* slot timing changed */
354 if (info->use_short_slot)
359 brcms_c_set(wl->wlc, BRCMS_SET_SHORTSLOT_OVERRIDE, val);
363 if (changed & BSS_CHANGED_HT) {
364 /* 802.11n parameters changed */
365 u16 mode = info->ht_operation_mode;
368 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
369 mode & IEEE80211_HT_OP_MODE_PROTECTION);
370 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
371 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
372 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
373 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
376 if (changed & BSS_CHANGED_BASIC_RATES) {
377 struct ieee80211_supported_band *bi;
380 struct wl_rateset rs;
383 /* retrieve the current rates */
385 error = brcms_c_ioctl(wl->wlc, BRCM_GET_CURR_RATESET,
386 &rs, sizeof(rs), NULL);
389 wiphy_err(wiphy, "%s: retrieve rateset failed: %d\n",
393 br_mask = info->basic_rates;
394 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
395 for (i = 0; i < bi->n_bitrates; i++) {
396 /* convert to internal rate value */
397 rate = (bi->bitrates[i].bitrate << 1) / 10;
399 /* set/clear basic rate flag */
400 brcms_set_basic_rate(&rs, rate, br_mask & 1);
404 /* update the rate set */
406 brcms_c_ioctl(wl->wlc, BRCM_SET_RATESET, &rs, sizeof(rs), NULL);
409 if (changed & BSS_CHANGED_BEACON_INT) {
410 /* Beacon interval changed */
412 brcms_c_set(wl->wlc, BRCM_SET_BCNPRD, info->beacon_int);
415 if (changed & BSS_CHANGED_BSSID) {
416 /* BSSID changed, for whatever reason (IBSS and managed mode) */
418 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
422 if (changed & BSS_CHANGED_BEACON) {
423 /* Beacon data changed, retrieve new beacon (beaconing modes) */
424 wiphy_err(wiphy, "%s: beacon changed\n", __func__);
426 if (changed & BSS_CHANGED_BEACON_ENABLED) {
427 /* Beaconing should be enabled/disabled (beaconing modes) */
428 wiphy_err(wiphy, "%s: Beacon enabled: %s\n", __func__,
429 info->enable_beacon ? "true" : "false");
431 if (changed & BSS_CHANGED_CQM) {
432 /* Connection quality monitor config changed */
433 wiphy_err(wiphy, "%s: cqm change: threshold %d, hys %d "
434 " (implement)\n", __func__, info->cqm_rssi_thold,
435 info->cqm_rssi_hyst);
437 if (changed & BSS_CHANGED_IBSS) {
438 /* IBSS join status changed */
439 wiphy_err(wiphy, "%s: IBSS joined: %s (implement)\n", __func__,
440 info->ibss_joined ? "true" : "false");
442 if (changed & BSS_CHANGED_ARP_FILTER) {
443 /* Hardware ARP filter address list or state changed */
444 wiphy_err(wiphy, "%s: arp filtering: enabled %s, count %d"
445 " (implement)\n", __func__, info->arp_filter_enabled ?
446 "true" : "false", info->arp_addr_cnt);
448 if (changed & BSS_CHANGED_QOS) {
450 * QoS for this association was enabled/disabled.
451 * Note that it is only ever disabled for station mode.
453 wiphy_err(wiphy, "%s: qos enabled: %s (implement)\n", __func__,
454 info->qos ? "true" : "false");
460 brcms_ops_configure_filter(struct ieee80211_hw *hw,
461 unsigned int changed_flags,
462 unsigned int *total_flags, u64 multicast)
464 struct brcms_info *wl = hw->priv;
465 struct wiphy *wiphy = hw->wiphy;
467 changed_flags &= MAC_FILTERS;
468 *total_flags &= MAC_FILTERS;
469 if (changed_flags & FIF_PROMISC_IN_BSS)
470 wiphy_err(wiphy, "FIF_PROMISC_IN_BSS\n");
471 if (changed_flags & FIF_ALLMULTI)
472 wiphy_err(wiphy, "FIF_ALLMULTI\n");
473 if (changed_flags & FIF_FCSFAIL)
474 wiphy_err(wiphy, "FIF_FCSFAIL\n");
475 if (changed_flags & FIF_PLCPFAIL)
476 wiphy_err(wiphy, "FIF_PLCPFAIL\n");
477 if (changed_flags & FIF_CONTROL)
478 wiphy_err(wiphy, "FIF_CONTROL\n");
479 if (changed_flags & FIF_OTHER_BSS)
480 wiphy_err(wiphy, "FIF_OTHER_BSS\n");
481 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
483 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
484 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
485 brcms_c_mac_bcn_promisc_change(wl->wlc, 1);
487 brcms_c_mac_bcn_promisc_change(wl->wlc, 0);
488 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
496 brcms_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
501 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
503 struct brcms_info *wl = hw->priv;
505 brcms_c_scan_start(wl->wlc);
510 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
512 struct brcms_info *wl = hw->priv;
514 brcms_c_scan_stop(wl->wlc);
519 static void brcms_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
521 wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
526 brcms_ops_get_stats(struct ieee80211_hw *hw,
527 struct ieee80211_low_level_stats *stats)
529 struct brcms_info *wl = hw->priv;
534 stats->dot11ACKFailureCount = 0;
535 stats->dot11RTSFailureCount = 0;
536 stats->dot11FCSErrorCount = 0;
537 stats->dot11RTSSuccessCount = 0;
543 brcms_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
544 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
548 wiphy_err(hw->wiphy, "%s: Unknown cmd = %d\n", __func__,
556 brcms_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
557 const struct ieee80211_tx_queue_params *params)
559 struct brcms_info *wl = hw->priv;
562 brcms_c_wme_setparams(wl->wlc, queue, params, true);
568 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw)
570 wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
575 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
576 struct ieee80211_sta *sta)
581 struct brcms_info *wl = hw->priv;
584 scb = (struct scb *)sta->drv_priv;
585 memset(scb, 0, sizeof(struct scb));
586 for (i = 0; i < NUMPRIO; i++)
587 scb->seqctl[i] = 0xFFFF;
588 scb->seqctl_nonqos = 0xFFFF;
589 scb->magic = SCB_MAGIC;
591 wl->pub->global_scb = scb;
592 wl->pub->global_ampdu = &(scb->scb_ampdu);
593 wl->pub->global_ampdu->scb = scb;
594 wl->pub->global_ampdu->max_pdu = 16;
595 brcmu_pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
596 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
598 sta->ht_cap.ht_supported = true;
599 sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
600 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
601 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
602 IEEE80211_HT_CAP_SGI_20 |
603 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
605 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
610 brcms_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
611 struct ieee80211_sta *sta)
617 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
618 struct ieee80211_vif *vif,
619 enum ieee80211_ampdu_mlme_action action,
620 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
623 struct scb *scb = (struct scb *)sta->drv_priv;
624 struct brcms_info *wl = hw->priv;
627 if (WARN_ON(scb->magic != SCB_MAGIC))
630 case IEEE80211_AMPDU_RX_START:
632 case IEEE80211_AMPDU_RX_STOP:
634 case IEEE80211_AMPDU_TX_START:
636 status = brcms_c_aggregatable(wl->wlc, tid);
639 wiphy_err(wl->wiphy, "START: tid %d is not agg\'able\n",
643 /* Future improvement: Use the starting sequence number provided ... */
645 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
648 case IEEE80211_AMPDU_TX_STOP:
650 brcms_c_ampdu_flush(wl->wlc, sta, tid);
652 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
654 case IEEE80211_AMPDU_TX_OPERATIONAL:
656 * BA window size from ADDBA response ('buf_size') defines how
657 * many outstanding MPDUs are allowed for the BA stream by
658 * recipient and traffic class. 'ampdu_factor' gives maximum
662 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
663 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
664 sta->ht_cap.ampdu_factor)) - 1);
666 /* Power save wakeup */
669 wiphy_err(wl->wiphy, "%s: Invalid command, ignoring\n",
676 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
678 struct brcms_info *wl = HW_TO_WL(hw);
682 blocked = brcms_c_check_radio_disabled(wl->wlc);
685 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
688 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
690 struct brcms_info *wl = HW_TO_WL(hw);
692 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
694 /* wait for packet queue and dma fifos to run empty */
696 brcms_c_wait_for_tx_completion(wl->wlc, drop);
700 static const struct ieee80211_ops brcms_ops = {
702 .start = brcms_ops_start,
703 .stop = brcms_ops_stop,
704 .add_interface = brcms_ops_add_interface,
705 .remove_interface = brcms_ops_remove_interface,
706 .config = brcms_ops_config,
707 .bss_info_changed = brcms_ops_bss_info_changed,
708 .configure_filter = brcms_ops_configure_filter,
709 .set_tim = brcms_ops_set_tim,
710 .sw_scan_start = brcms_ops_sw_scan_start,
711 .sw_scan_complete = brcms_ops_sw_scan_complete,
712 .set_tsf = brcms_ops_set_tsf,
713 .get_stats = brcms_ops_get_stats,
714 .sta_notify = brcms_ops_sta_notify,
715 .conf_tx = brcms_ops_conf_tx,
716 .get_tsf = brcms_ops_get_tsf,
717 .sta_add = brcms_ops_sta_add,
718 .sta_remove = brcms_ops_sta_remove,
719 .ampdu_action = brcms_ops_ampdu_action,
720 .rfkill_poll = brcms_ops_rfkill_poll,
721 .flush = brcms_ops_flush,
725 * is called in brcms_pci_probe() context, therefore no locking required.
727 static int brcms_set_hint(struct brcms_info *wl, char *abbrev)
729 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
733 * attach to the WL device.
735 * Attach to the WL device identified by vendor and device parameters.
736 * regs is a host accessible memory address pointing to WL device registers.
738 * brcms_attach is not defined as static because in the case where no bus
739 * is defined, wl_attach will never be called, and thus, gcc will issue
740 * a warning that this function is defined but not used if we declare
744 * is called in brcms_pci_probe() context, therefore no locking required.
746 static struct brcms_info *brcms_attach(u16 vendor, u16 device,
748 uint bustype, void *btparam, uint irq)
750 struct brcms_info *wl = NULL;
752 unsigned long base_addr;
753 struct ieee80211_hw *hw;
756 unit = n_adapters_found;
763 /* allocate private info */
764 hw = pci_get_drvdata(btparam); /* btparam == pdev */
767 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
769 wl->wiphy = hw->wiphy;
771 atomic_set(&wl->callbacks, 0);
773 /* setup the bottom half handler */
774 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
780 if (bustype == PCI_BUS || bustype == RPC_BUS) {
784 BCMMSG(wl->wiphy, "force to PCI\n");
786 wl->bcm_bustype = bustype;
788 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
789 if (wl->regsva == NULL) {
790 wiphy_err(wl->wiphy, "wl%d: ioremap() failed\n", unit);
793 spin_lock_init(&wl->lock);
794 spin_lock_init(&wl->isr_lock);
797 if (brcms_request_fw(wl, (struct pci_dev *)btparam) < 0) {
798 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
799 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
800 brcms_release_fw(wl);
801 brcms_remove((struct pci_dev *)btparam);
805 /* common load-time initialization */
806 wl->wlc = brcms_c_attach((void *)wl, vendor, device, unit, false,
807 wl->regsva, wl->bcm_bustype, btparam, &err);
808 brcms_release_fw(wl);
810 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
811 KBUILD_MODNAME, err);
814 wl->pub = brcms_c_pub(wl->wlc);
816 wl->pub->ieee_hw = hw;
818 if (brcms_c_set_par(wl->wlc, IOV_MPC, 0) < 0) {
819 wiphy_err(wl->wiphy, "wl%d: Error setting MPC variable to 0\n",
823 /* register our interrupt handler */
824 if (request_irq(irq, brcms_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
825 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
830 /* register module */
831 brcms_c_module_register(wl->pub, "linux", wl, wl_linux_watchdog, NULL);
833 if (ieee_hw_init(hw)) {
834 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
839 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
840 if (WARN_ON(!is_valid_ether_addr(perm)))
842 SET_IEEE80211_PERM_ADDR(hw, perm);
844 err = ieee80211_register_hw(hw);
846 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
847 "%d\n", __func__, err);
850 if (wl->pub->srom_ccode[0])
851 err = brcms_set_hint(wl, wl->pub->srom_ccode);
853 err = brcms_set_hint(wl, "US");
855 wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n",
869 #define CHAN2GHZ(channel, freqency, chflags) { \
870 .band = IEEE80211_BAND_2GHZ, \
871 .center_freq = (freqency), \
872 .hw_value = (channel), \
874 .max_antenna_gain = 0, \
878 static struct ieee80211_channel brcms_2ghz_chantable[] = {
879 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
880 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
881 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
882 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
883 CHAN2GHZ(5, 2432, 0),
884 CHAN2GHZ(6, 2437, 0),
885 CHAN2GHZ(7, 2442, 0),
886 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
887 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
888 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
889 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
891 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
892 IEEE80211_CHAN_NO_HT40PLUS),
894 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
895 IEEE80211_CHAN_NO_HT40PLUS),
897 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
898 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
901 #define CHAN5GHZ(channel, chflags) { \
902 .band = IEEE80211_BAND_5GHZ, \
903 .center_freq = 5000 + 5*(channel), \
904 .hw_value = (channel), \
906 .max_antenna_gain = 0, \
910 static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
912 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
913 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
914 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
915 CHAN5GHZ(48, 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_HT40MINUS),
927 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
928 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
931 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
932 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
934 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
935 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
937 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
938 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
940 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
941 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
943 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
944 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
946 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
947 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
949 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
950 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
952 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
953 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
955 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
956 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
958 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
959 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
961 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
962 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
963 IEEE80211_CHAN_NO_HT40MINUS),
965 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
966 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
967 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
968 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
969 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
972 #define RATE(rate100m, _flags) { \
973 .bitrate = (rate100m), \
975 .hw_value = (rate100m / 5), \
978 static struct ieee80211_rate legacy_ratetable[] = {
980 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
981 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
982 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
993 static struct ieee80211_supported_band brcms_band_2GHz_nphy = {
994 .band = IEEE80211_BAND_2GHZ,
995 .channels = brcms_2ghz_chantable,
996 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
997 .bitrates = legacy_ratetable,
998 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
1000 /* from include/linux/ieee80211.h */
1001 .cap = IEEE80211_HT_CAP_GRN_FLD |
1002 IEEE80211_HT_CAP_SGI_20 |
1003 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1004 .ht_supported = true,
1005 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1006 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1008 /* placeholders for now */
1009 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1011 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1015 static struct ieee80211_supported_band brcms_band_5GHz_nphy = {
1016 .band = IEEE80211_BAND_5GHZ,
1017 .channels = brcms_5ghz_nphy_chantable,
1018 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
1019 .bitrates = legacy_ratetable + 4,
1020 .n_bitrates = ARRAY_SIZE(legacy_ratetable) - 4,
1022 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1023 .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 */
1024 .ht_supported = true,
1025 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1026 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1028 /* placeholders for now */
1029 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1031 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1036 * is called in brcms_pci_probe() context, therefore no locking required.
1038 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1040 struct brcms_info *wl = HW_TO_WL(hw);
1046 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1047 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1049 if (brcms_c_get(wl->wlc, BRCM_GET_PHYLIST, (int *)&phy_list) < 0)
1050 wiphy_err(hw->wiphy, "Phy list failed\n");
1052 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1053 if (phy_list[0] == 'c') {
1055 brcms_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1056 brcms_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1058 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &brcms_band_2GHz_nphy;
1063 /* Assume all bands use the same phy. True for 11n devices. */
1064 if (NBANDS_PUB(wl->pub) > 1) {
1066 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1067 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1068 &brcms_band_5GHz_nphy;
1077 * is called in brcms_pci_probe() context, therefore no locking required.
1079 static int ieee_hw_init(struct ieee80211_hw *hw)
1081 hw->flags = IEEE80211_HW_SIGNAL_DBM
1082 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1083 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1084 | IEEE80211_HW_AMPDU_AGGREGATION;
1086 hw->extra_tx_headroom = brcms_c_get_header_len();
1087 hw->queues = N_TX_QUEUES;
1088 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1090 hw->channel_change_time = 7 * 1000; /* channel change time is dependent on chip and band */
1091 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1093 hw->rate_control_algorithm = "minstrel_ht";
1095 hw->sta_data_size = sizeof(struct scb);
1096 return ieee_hw_rate_init(hw);
1100 * determines if a device is a WL device, and if so, attaches it.
1102 * This function determines if a device pointed to by pdev is a WL device,
1103 * and if so, performs a brcms_attach() on it.
1105 * Perimeter lock is initialized in the course of this function.
1107 static int __devinit
1108 brcms_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1111 struct brcms_info *wl;
1112 struct ieee80211_hw *hw;
1115 dev_info(&pdev->dev, "bus %d slot %d func %d irq %d\n",
1116 pdev->bus->number, PCI_SLOT(pdev->devfn),
1117 PCI_FUNC(pdev->devfn), pdev->irq);
1119 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1120 ((pdev->device != 0x0576) &&
1121 ((pdev->device & 0xff00) != 0x4300) &&
1122 ((pdev->device & 0xff00) != 0x4700) &&
1123 ((pdev->device < 43000) || (pdev->device > 43999))))
1126 rc = pci_enable_device(pdev);
1128 pr_err("%s: Cannot enable device %d-%d_%d\n",
1129 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1130 PCI_FUNC(pdev->devfn));
1133 pci_set_master(pdev);
1135 pci_read_config_dword(pdev, 0x40, &val);
1136 if ((val & 0x0000ff00) != 0)
1137 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1139 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1141 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1145 SET_IEEE80211_DEV(hw, &pdev->dev);
1147 pci_set_drvdata(pdev, hw);
1149 memset(hw->priv, 0, sizeof(*wl));
1151 wl = brcms_attach(pdev->vendor, pdev->device,
1152 pci_resource_start(pdev, 0), PCI_BUS, pdev,
1156 pr_err("%s: %s: brcms_attach failed!\n", KBUILD_MODNAME,
1163 static int brcms_suspend(struct pci_dev *pdev, pm_message_t state)
1165 struct brcms_info *wl;
1166 struct ieee80211_hw *hw;
1168 hw = pci_get_drvdata(pdev);
1171 wiphy_err(wl->wiphy,
1172 "brcms_suspend: pci_get_drvdata failed\n");
1176 /* only need to flag hw is down for proper resume */
1178 wl->pub->hw_up = false;
1181 pci_save_state(pdev);
1182 pci_disable_device(pdev);
1183 return pci_set_power_state(pdev, PCI_D3hot);
1186 static int brcms_resume(struct pci_dev *pdev)
1188 struct brcms_info *wl;
1189 struct ieee80211_hw *hw;
1193 hw = pci_get_drvdata(pdev);
1196 wiphy_err(wl->wiphy,
1197 "wl: brcms_resume: pci_get_drvdata failed\n");
1201 err = pci_set_power_state(pdev, PCI_D0);
1205 pci_restore_state(pdev);
1207 err = pci_enable_device(pdev);
1211 pci_set_master(pdev);
1213 pci_read_config_dword(pdev, 0x40, &val);
1214 if ((val & 0x0000ff00) != 0)
1215 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1218 * done. driver will be put in up state
1219 * in brcms_ops_add_interface() call.
1225 * called from both kernel as from this kernel module.
1226 * precondition: perimeter lock is not acquired.
1228 static void brcms_remove(struct pci_dev *pdev)
1230 struct brcms_info *wl;
1231 struct ieee80211_hw *hw;
1234 hw = pci_get_drvdata(pdev);
1237 pr_err("wl: brcms_remove: pci_get_drvdata failed\n");
1242 status = brcms_c_chipmatch(pdev->vendor, pdev->device);
1245 wiphy_err(wl->wiphy, "wl: brcms_remove: chipmatch "
1250 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1251 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1252 ieee80211_unregister_hw(hw);
1257 pci_disable_device(pdev);
1261 pci_set_drvdata(pdev, NULL);
1262 ieee80211_free_hw(hw);
1265 static struct pci_driver brcms_pci_driver = {
1266 .name = KBUILD_MODNAME,
1267 .probe = brcms_pci_probe,
1268 .suspend = brcms_suspend,
1269 .resume = brcms_resume,
1270 .remove = __devexit_p(brcms_remove),
1271 .id_table = brcms_pci_id_table,
1275 * This is the main entry point for the WL driver.
1277 * This function determines if a device pointed to by pdev is a WL device,
1278 * and if so, performs a brcms_attach() on it.
1281 static int __init brcms_module_init(void)
1283 int error = -ENODEV;
1286 if (msglevel != 0xdeadbeef)
1287 brcm_msg_level = msglevel;
1288 if (phymsglevel != 0xdeadbeef)
1289 phyhal_msg_level = phymsglevel;
1292 error = pci_register_driver(&brcms_pci_driver);
1302 * This function unloads the WL driver from the system.
1304 * This function unconditionally unloads the WL driver module from the
1308 static void __exit brcms_module_exit(void)
1310 pci_unregister_driver(&brcms_pci_driver);
1314 module_init(brcms_module_init);
1315 module_exit(brcms_module_exit);
1318 * This function frees the WL per-device resources.
1320 * This function frees resources owned by the WL device pointed to
1321 * by the wl parameter.
1323 * precondition: can both be called locked and unlocked
1326 static void brcms_free(struct brcms_info *wl)
1328 struct brcms_timer *t, *next;
1330 /* free ucode data */
1332 brcms_ucode_data_free();
1334 free_irq(wl->irq, wl);
1337 tasklet_kill(&wl->tasklet);
1340 brcms_c_module_unregister(wl->pub, "linux", wl);
1343 /* free common resources */
1345 brcms_c_detach(wl->wlc);
1350 /* virtual interface deletion is deferred so we cannot spinwait */
1352 /* wait for all pending callbacks to complete */
1353 while (atomic_read(&wl->callbacks) > 0)
1357 for (t = wl->timers; t; t = next) {
1366 * unregister_netdev() calls get_stats() which may read chip registers
1367 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1369 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1370 wl->bcm_bustype != JTAG_BUS) {
1371 iounmap((void *)wl->regsva);
1376 /* flags the given rate in rateset as requested */
1377 static void brcms_set_basic_rate(struct wl_rateset *rs, u16 rate, bool is_br)
1381 for (i = 0; i < rs->count; i++) {
1382 if (rate != (rs->rates[i] & 0x7f))
1386 rs->rates[i] |= BRCMS_RATE_FLAG;
1388 rs->rates[i] &= BRCMS_RATE_MASK;
1394 * precondition: perimeter lock has been acquired
1396 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1397 bool state, int prio)
1399 wiphy_err(wl->wiphy, "Shouldn't be here %s\n", __func__);
1403 * precondition: perimeter lock has been acquired
1405 void brcms_init(struct brcms_info *wl)
1407 BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
1410 brcms_c_init(wl->wlc);
1414 * precondition: perimeter lock has been acquired
1416 uint brcms_reset(struct brcms_info *wl)
1418 BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
1419 brcms_c_reset(wl->wlc);
1421 /* dpc will not be rescheduled */
1428 * These are interrupt on/off entry points. Disable interrupts
1429 * during interrupt state transition.
1431 void brcms_intrson(struct brcms_info *wl)
1433 unsigned long flags;
1435 INT_LOCK(wl, flags);
1436 brcms_c_intrson(wl->wlc);
1437 INT_UNLOCK(wl, flags);
1441 * precondition: perimeter lock has been acquired
1443 bool wl_alloc_dma_resources(struct brcms_info *wl, uint addrwidth)
1448 u32 brcms_intrsoff(struct brcms_info *wl)
1450 unsigned long flags;
1453 INT_LOCK(wl, flags);
1454 status = brcms_c_intrsoff(wl->wlc);
1455 INT_UNLOCK(wl, flags);
1459 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1461 unsigned long flags;
1463 INT_LOCK(wl, flags);
1464 brcms_c_intrsrestore(wl->wlc, macintmask);
1465 INT_UNLOCK(wl, flags);
1469 * precondition: perimeter lock has been acquired
1471 int brcms_up(struct brcms_info *wl)
1478 error = brcms_c_up(wl->wlc);
1484 * precondition: perimeter lock has been acquired
1486 void brcms_down(struct brcms_info *wl)
1488 uint callbacks, ret_val = 0;
1490 /* call common down function */
1491 ret_val = brcms_c_down(wl->wlc);
1492 callbacks = atomic_read(&wl->callbacks) - ret_val;
1494 /* wait for down callbacks to complete */
1497 /* For HIGH_only driver, it's important to actually schedule other work,
1498 * not just spin wait since everything runs at schedule level
1500 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1505 static irqreturn_t brcms_isr(int irq, void *dev_id)
1507 struct brcms_info *wl;
1509 unsigned long flags;
1511 wl = (struct brcms_info *) dev_id;
1513 ISR_LOCK(wl, flags);
1515 /* call common first level interrupt handler */
1516 ours = brcms_c_isr(wl->wlc, &wantdpc);
1518 /* if more to do... */
1521 /* ...and call the second level interrupt handler */
1523 tasklet_schedule(&wl->tasklet);
1527 ISR_UNLOCK(wl, flags);
1529 return IRQ_RETVAL(ours);
1532 static void brcms_dpc(unsigned long data)
1534 struct brcms_info *wl;
1536 wl = (struct brcms_info *) data;
1540 /* call the common second level interrupt handler */
1543 unsigned long flags;
1545 INT_LOCK(wl, flags);
1546 brcms_c_intrsupd(wl->wlc);
1547 INT_UNLOCK(wl, flags);
1550 wl->resched = brcms_c_dpc(wl->wlc, true);
1553 /* brcms_c_dpc() may bring the driver down */
1557 /* re-schedule dpc */
1559 tasklet_schedule(&wl->tasklet);
1561 /* re-enable interrupts */
1570 * is called by the kernel from software irq context
1572 static void brcms_timer(unsigned long data)
1574 _brcms_timer((struct brcms_timer *) data);
1578 * precondition: perimeter lock is not acquired
1580 static void _brcms_timer(struct brcms_timer *t)
1586 t->timer.expires = jiffies + t->ms * HZ / 1000;
1587 atomic_inc(&t->wl->callbacks);
1588 add_timer(&t->timer);
1596 atomic_dec(&t->wl->callbacks);
1602 * Adds a timer to the list. Caller supplies a timer function.
1603 * Is called from wlc.
1605 * precondition: perimeter lock has been acquired
1607 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1608 void (*fn) (void *arg),
1609 void *arg, const char *name)
1611 struct brcms_timer *t;
1613 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1615 wiphy_err(wl->wiphy, "wl%d: brcms_init_timer: out of memory\n",
1620 init_timer(&t->timer);
1621 t->timer.data = (unsigned long) t;
1622 t->timer.function = brcms_timer;
1626 t->next = wl->timers;
1630 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1632 strcpy(t->name, name);
1638 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1639 * as well as it's easier to make it periodic
1641 * precondition: perimeter lock has been acquired
1643 void brcms_add_timer(struct brcms_info *wl, struct brcms_timer *t, uint ms,
1648 wiphy_err(wl->wiphy, "%s: Already set. Name: %s, per %d\n",
1649 __func__, t->name, periodic);
1653 t->periodic = (bool) periodic;
1655 t->timer.expires = jiffies + ms * HZ / 1000;
1657 atomic_inc(&wl->callbacks);
1658 add_timer(&t->timer);
1662 * return true if timer successfully deleted, false if still pending
1664 * precondition: perimeter lock has been acquired
1666 bool brcms_del_timer(struct brcms_info *wl, struct brcms_timer *t)
1670 if (!del_timer(&t->timer)) {
1673 atomic_dec(&wl->callbacks);
1680 * precondition: perimeter lock has been acquired
1682 void brcms_free_timer(struct brcms_info *wl, struct brcms_timer *t)
1684 struct brcms_timer *tmp;
1686 /* delete the timer in case it is active */
1687 brcms_del_timer(wl, t);
1689 if (wl->timers == t) {
1690 wl->timers = wl->timers->next;
1701 if (tmp->next == t) {
1702 tmp->next = t->next;
1715 * runs in software irq context
1717 * precondition: perimeter lock is not acquired
1719 static int wl_linux_watchdog(void *ctx)
1724 struct firmware_hdr {
1730 char *brcms_firmwares[MAX_FW_IMAGES] = {
1736 * precondition: perimeter lock has been acquired
1738 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1742 struct firmware_hdr *hdr;
1743 for (i = 0; i < wl->fw.fw_cnt; i++) {
1744 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1745 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1747 if (hdr->idx == idx) {
1748 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1749 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1750 if (*pbuf == NULL) {
1751 wiphy_err(wl->wiphy, "fail to alloc %d"
1752 " bytes\n", hdr->len);
1755 memcpy(*pbuf, pdata, hdr->len);
1760 wiphy_err(wl->wiphy, "ERROR: ucode buf tag:%d can not be found!\n",
1768 * Precondition: Since this function is called in brcms_pci_probe() context,
1769 * no locking is required.
1771 int brcms_ucode_init_uint(struct brcms_info *wl, u32 *data, u32 idx)
1775 struct firmware_hdr *hdr;
1776 for (i = 0; i < wl->fw.fw_cnt; i++) {
1777 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1778 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1780 if (hdr->idx == idx) {
1781 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1782 if (hdr->len != 4) {
1783 wiphy_err(wl->wiphy,
1784 "ERROR: fw hdr len\n");
1787 *data = *((u32 *) pdata);
1792 wiphy_err(wl->wiphy, "ERROR: ucode tag:%d can not be found!\n", idx);
1797 * Precondition: Since this function is called in brcms_pci_probe() context,
1798 * no locking is required.
1800 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev)
1803 struct device *device = &pdev->dev;
1807 memset((void *)&wl->fw, 0, sizeof(struct brcms_firmware));
1808 for (i = 0; i < MAX_FW_IMAGES; i++) {
1809 if (brcms_firmwares[i] == NULL)
1811 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
1812 UCODE_LOADER_API_VER);
1813 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1815 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
1816 KBUILD_MODNAME, fw_name);
1819 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
1820 UCODE_LOADER_API_VER);
1821 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1823 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
1824 KBUILD_MODNAME, fw_name);
1827 wl->fw.hdr_num_entries[i] =
1828 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
1831 return brcms_ucode_data_init(wl);
1835 * precondition: can both be called locked and unlocked
1837 void brcms_ucode_free_buf(void *p)
1843 * Precondition: Since this function is called in brcms_pci_probe() context,
1844 * no locking is required.
1846 static void brcms_release_fw(struct brcms_info *wl)
1849 for (i = 0; i < MAX_FW_IMAGES; i++) {
1850 release_firmware(wl->fw.fw_bin[i]);
1851 release_firmware(wl->fw.fw_hdr[i]);
1857 * checks validity of all firmware images loaded from user space
1859 * Precondition: Since this function is called in brcms_pci_probe() context,
1860 * no locking is required.
1862 int brcms_check_firmwares(struct brcms_info *wl)
1867 const struct firmware *fw;
1868 const struct firmware *fw_hdr;
1869 struct firmware_hdr *ucode_hdr;
1870 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1871 fw = wl->fw.fw_bin[i];
1872 fw_hdr = wl->fw.fw_hdr[i];
1873 if (fw == NULL && fw_hdr == NULL) {
1875 } else if (fw == NULL || fw_hdr == NULL) {
1876 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1879 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1880 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1881 "size %zu/%zu\n", __func__, fw_hdr->size,
1882 sizeof(struct firmware_hdr));
1884 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1885 wiphy_err(wl->wiphy, "%s: out of bounds fw file size "
1886 "%zu\n", __func__, fw->size);
1889 /* check if ucode section overruns firmware image */
1890 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1891 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1892 !rc; entry++, ucode_hdr++) {
1893 if (ucode_hdr->offset + ucode_hdr->len >
1895 wiphy_err(wl->wiphy,
1896 "%s: conflicting bin/hdr\n",
1903 if (rc == 0 && wl->fw.fw_cnt != i) {
1904 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1912 * precondition: perimeter lock has been acquired
1914 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1916 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1919 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1921 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1927 * precondition: perimeter lock has been acquired
1929 void brcms_msleep(struct brcms_info *wl, uint ms)