mac80211: pass vif param to conf_tx() callback
[deliverable/linux.git] / drivers / staging / brcm80211 / brcmsmac / mac80211_if.c
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #define __UNDEF_NO_VERSION__
18
19 #include <linux/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>
25 #include <defs.h>
26 #include "nicpci.h"
27 #include "phy/phy_int.h"
28 #include "d11.h"
29 #include "channel.h"
30 #include "scb.h"
31 #include "pub.h"
32 #include "ucode_loader.h"
33 #include "mac80211_if.h"
34
35 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
36
37 #define LOCK(wl) spin_lock_bh(&(wl)->lock)
38 #define UNLOCK(wl) spin_unlock_bh(&(wl)->lock)
39
40 /* locking from inside brcms_isr */
41 #define ISR_LOCK(wl, flags)\
42 do {\
43 spin_lock(&(wl)->isr_lock);\
44 (void)(flags); } \
45 while (0)
46
47 #define ISR_UNLOCK(wl, flags)\
48 do {\
49 spin_unlock(&(wl)->isr_lock);\
50 (void)(flags); } \
51 while (0)
52
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)
56
57 static void brcms_timer(unsigned long data);
58 static void _brcms_timer(struct brcms_timer *t);
59
60
61 static int ieee_hw_init(struct ieee80211_hw *hw);
62 static int ieee_hw_rate_init(struct ieee80211_hw *hw);
63
64 static int wl_linux_watchdog(void *ctx);
65
66 /* Flags we support */
67 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
68 FIF_ALLMULTI | \
69 FIF_FCSFAIL | \
70 FIF_PLCPFAIL | \
71 FIF_CONTROL | \
72 FIF_OTHER_BSS | \
73 FIF_BCN_PRBRESP_PROMISC)
74
75 static int n_adapters_found;
76
77 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev);
78 static void brcms_release_fw(struct brcms_info *wl);
79
80 /* local prototypes */
81 static void brcms_dpc(unsigned long data);
82 static irqreturn_t brcms_isr(int irq, void *dev_id);
83
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);
89
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");
94
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 */
100 /* 43224 Ven */
101 {PCI_VENDOR_ID_BROADCOM, 0x0576, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
102 {0}
103 };
104
105 MODULE_DEVICE_TABLE(pci, brcms_pci_id_table);
106
107 #ifdef BCMDBG
108 static int msglevel = 0xdeadbeef;
109 module_param(msglevel, int, 0);
110 static int phymsglevel = 0xdeadbeef;
111 module_param(phymsglevel, int, 0);
112 #endif /* BCMDBG */
113
114 #define HW_TO_WL(hw) (hw->priv)
115 #define WL_TO_HW(wl) (wl->pub->ieee_hw)
116
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,
128 u32 changed);
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,
133 bool set);
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,
137 struct ieee80211_vif *vif, u64 tsf);
138 static int brcms_ops_get_stats(struct ieee80211_hw *hw,
139 struct ieee80211_low_level_stats *stats);
140 static void brcms_ops_sta_notify(struct ieee80211_hw *hw,
141 struct ieee80211_vif *vif,
142 enum sta_notify_cmd cmd,
143 struct ieee80211_sta *sta);
144 static int brcms_ops_conf_tx(struct ieee80211_hw *hw,
145 struct ieee80211_vif *vif, u16 queue,
146 const struct ieee80211_tx_queue_params *params);
147 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw,
148 struct ieee80211_vif *vif);
149 static int brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
150 struct ieee80211_sta *sta);
151 static int brcms_ops_sta_remove(struct ieee80211_hw *hw,
152 struct ieee80211_vif *vif,
153 struct ieee80211_sta *sta);
154 static int brcms_ops_ampdu_action(struct ieee80211_hw *hw,
155 struct ieee80211_vif *vif,
156 enum ieee80211_ampdu_mlme_action action,
157 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
158 u8 buf_size);
159 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw);
160 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop);
161
162 static void brcms_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
163 {
164 struct brcms_info *wl = hw->priv;
165
166 LOCK(wl);
167 if (!wl->pub->up) {
168 wiphy_err(wl->wiphy, "ops->tx called while down\n");
169 kfree_skb(skb);
170 goto done;
171 }
172 brcms_c_sendpkt_mac80211(wl->wlc, skb, hw);
173 done:
174 UNLOCK(wl);
175 }
176
177 static int brcms_ops_start(struct ieee80211_hw *hw)
178 {
179 struct brcms_info *wl = hw->priv;
180 bool blocked;
181 /*
182 struct ieee80211_channel *curchan = hw->conf.channel;
183 */
184
185 ieee80211_wake_queues(hw);
186 LOCK(wl);
187 blocked = brcms_rfkill_set_hw_state(wl);
188 UNLOCK(wl);
189 if (!blocked)
190 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
191
192 return 0;
193 }
194
195 static void brcms_ops_stop(struct ieee80211_hw *hw)
196 {
197 ieee80211_stop_queues(hw);
198 }
199
200 static int
201 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
202 {
203 struct brcms_info *wl;
204 int err;
205
206 /* Just STA for now */
207 if (vif->type != NL80211_IFTYPE_AP &&
208 vif->type != NL80211_IFTYPE_MESH_POINT &&
209 vif->type != NL80211_IFTYPE_STATION &&
210 vif->type != NL80211_IFTYPE_WDS &&
211 vif->type != NL80211_IFTYPE_ADHOC) {
212 wiphy_err(hw->wiphy, "%s: Attempt to add type %d, only"
213 " STA for now\n", __func__, vif->type);
214 return -EOPNOTSUPP;
215 }
216
217 wl = HW_TO_WL(hw);
218 LOCK(wl);
219 err = brcms_up(wl);
220 UNLOCK(wl);
221
222 if (err != 0) {
223 wiphy_err(hw->wiphy, "%s: brcms_up() returned %d\n", __func__,
224 err);
225 }
226 return err;
227 }
228
229 static void
230 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
231 {
232 struct brcms_info *wl;
233
234 wl = HW_TO_WL(hw);
235
236 /* put driver in down state */
237 LOCK(wl);
238 brcms_down(wl);
239 UNLOCK(wl);
240 }
241
242 /*
243 * precondition: perimeter lock has been acquired
244 */
245 static int
246 ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
247 enum nl80211_channel_type type)
248 {
249 struct brcms_info *wl = HW_TO_WL(hw);
250 int err = 0;
251
252 switch (type) {
253 case NL80211_CHAN_HT20:
254 case NL80211_CHAN_NO_HT:
255 err = brcms_c_set(wl->wlc, BRCM_SET_CHANNEL, chan->hw_value);
256 break;
257 case NL80211_CHAN_HT40MINUS:
258 case NL80211_CHAN_HT40PLUS:
259 wiphy_err(hw->wiphy,
260 "%s: Need to implement 40 Mhz Channels!\n", __func__);
261 err = 1;
262 break;
263 }
264
265 if (err)
266 return -EIO;
267 return err;
268 }
269
270 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
271 {
272 struct ieee80211_conf *conf = &hw->conf;
273 struct brcms_info *wl = HW_TO_WL(hw);
274 int err = 0;
275 int new_int;
276 struct wiphy *wiphy = hw->wiphy;
277
278 LOCK(wl);
279 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
280 if (brcms_c_set_par(wl->wlc, IOV_BCN_LI_BCN,
281 conf->listen_interval) < 0) {
282 wiphy_err(wiphy, "%s: Error setting listen_interval\n",
283 __func__);
284 err = -EIO;
285 goto config_out;
286 }
287 brcms_c_get_par(wl->wlc, IOV_BCN_LI_BCN, &new_int);
288 }
289 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
290 wiphy_err(wiphy, "%s: change monitor mode: %s (implement)\n",
291 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
292 "true" : "false");
293 if (changed & IEEE80211_CONF_CHANGE_PS)
294 wiphy_err(wiphy, "%s: change power-save mode: %s (implement)\n",
295 __func__, conf->flags & IEEE80211_CONF_PS ?
296 "true" : "false");
297
298 if (changed & IEEE80211_CONF_CHANGE_POWER) {
299 if (brcms_c_set_par(wl->wlc, IOV_QTXPOWER,
300 conf->power_level * 4) < 0) {
301 wiphy_err(wiphy, "%s: Error setting power_level\n",
302 __func__);
303 err = -EIO;
304 goto config_out;
305 }
306 brcms_c_get_par(wl->wlc, IOV_QTXPOWER, &new_int);
307 if (new_int != (conf->power_level * 4))
308 wiphy_err(wiphy, "%s: Power level req != actual, %d %d"
309 "\n", __func__, conf->power_level * 4,
310 new_int);
311 }
312 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
313 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
314 }
315 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
316 if (brcms_c_set
317 (wl->wlc, BRCM_SET_SRL,
318 conf->short_frame_max_tx_count) < 0) {
319 wiphy_err(wiphy, "%s: Error setting srl\n", __func__);
320 err = -EIO;
321 goto config_out;
322 }
323 if (brcms_c_set(wl->wlc, BRCM_SET_LRL,
324 conf->long_frame_max_tx_count) < 0) {
325 wiphy_err(wiphy, "%s: Error setting lrl\n", __func__);
326 err = -EIO;
327 goto config_out;
328 }
329 }
330
331 config_out:
332 UNLOCK(wl);
333 return err;
334 }
335
336 static void
337 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
338 struct ieee80211_vif *vif,
339 struct ieee80211_bss_conf *info, u32 changed)
340 {
341 struct brcms_info *wl = HW_TO_WL(hw);
342 struct wiphy *wiphy = hw->wiphy;
343 int val;
344
345 if (changed & BSS_CHANGED_ASSOC) {
346 /* association status changed (associated/disassociated)
347 * also implies a change in the AID.
348 */
349 wiphy_err(wiphy, "%s: %s: %sassociated\n", KBUILD_MODNAME,
350 __func__, info->assoc ? "" : "dis");
351 LOCK(wl);
352 brcms_c_associate_upd(wl->wlc, info->assoc);
353 UNLOCK(wl);
354 }
355 if (changed & BSS_CHANGED_ERP_SLOT) {
356 /* slot timing changed */
357 if (info->use_short_slot)
358 val = 1;
359 else
360 val = 0;
361 LOCK(wl);
362 brcms_c_set(wl->wlc, BRCMS_SET_SHORTSLOT_OVERRIDE, val);
363 UNLOCK(wl);
364 }
365
366 if (changed & BSS_CHANGED_HT) {
367 /* 802.11n parameters changed */
368 u16 mode = info->ht_operation_mode;
369
370 LOCK(wl);
371 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
372 mode & IEEE80211_HT_OP_MODE_PROTECTION);
373 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
374 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
375 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
376 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
377 UNLOCK(wl);
378 }
379 if (changed & BSS_CHANGED_BASIC_RATES) {
380 struct ieee80211_supported_band *bi;
381 u32 br_mask, i;
382 u16 rate;
383 struct wl_rateset rs;
384 int error;
385
386 /* retrieve the current rates */
387 LOCK(wl);
388 error = brcms_c_ioctl(wl->wlc, BRCM_GET_CURR_RATESET,
389 &rs, sizeof(rs), NULL);
390 UNLOCK(wl);
391 if (error) {
392 wiphy_err(wiphy, "%s: retrieve rateset failed: %d\n",
393 __func__, error);
394 return;
395 }
396 br_mask = info->basic_rates;
397 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
398 for (i = 0; i < bi->n_bitrates; i++) {
399 /* convert to internal rate value */
400 rate = (bi->bitrates[i].bitrate << 1) / 10;
401
402 /* set/clear basic rate flag */
403 brcms_set_basic_rate(&rs, rate, br_mask & 1);
404 br_mask >>= 1;
405 }
406
407 /* update the rate set */
408 LOCK(wl);
409 brcms_c_ioctl(wl->wlc, BRCM_SET_RATESET, &rs, sizeof(rs), NULL);
410 UNLOCK(wl);
411 }
412 if (changed & BSS_CHANGED_BEACON_INT) {
413 /* Beacon interval changed */
414 LOCK(wl);
415 brcms_c_set(wl->wlc, BRCM_SET_BCNPRD, info->beacon_int);
416 UNLOCK(wl);
417 }
418 if (changed & BSS_CHANGED_BSSID) {
419 /* BSSID changed, for whatever reason (IBSS and managed mode) */
420 LOCK(wl);
421 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
422 info->bssid);
423 UNLOCK(wl);
424 }
425 if (changed & BSS_CHANGED_BEACON) {
426 /* Beacon data changed, retrieve new beacon (beaconing modes) */
427 wiphy_err(wiphy, "%s: beacon changed\n", __func__);
428 }
429 if (changed & BSS_CHANGED_BEACON_ENABLED) {
430 /* Beaconing should be enabled/disabled (beaconing modes) */
431 wiphy_err(wiphy, "%s: Beacon enabled: %s\n", __func__,
432 info->enable_beacon ? "true" : "false");
433 }
434 if (changed & BSS_CHANGED_CQM) {
435 /* Connection quality monitor config changed */
436 wiphy_err(wiphy, "%s: cqm change: threshold %d, hys %d "
437 " (implement)\n", __func__, info->cqm_rssi_thold,
438 info->cqm_rssi_hyst);
439 }
440 if (changed & BSS_CHANGED_IBSS) {
441 /* IBSS join status changed */
442 wiphy_err(wiphy, "%s: IBSS joined: %s (implement)\n", __func__,
443 info->ibss_joined ? "true" : "false");
444 }
445 if (changed & BSS_CHANGED_ARP_FILTER) {
446 /* Hardware ARP filter address list or state changed */
447 wiphy_err(wiphy, "%s: arp filtering: enabled %s, count %d"
448 " (implement)\n", __func__, info->arp_filter_enabled ?
449 "true" : "false", info->arp_addr_cnt);
450 }
451 if (changed & BSS_CHANGED_QOS) {
452 /*
453 * QoS for this association was enabled/disabled.
454 * Note that it is only ever disabled for station mode.
455 */
456 wiphy_err(wiphy, "%s: qos enabled: %s (implement)\n", __func__,
457 info->qos ? "true" : "false");
458 }
459 return;
460 }
461
462 static void
463 brcms_ops_configure_filter(struct ieee80211_hw *hw,
464 unsigned int changed_flags,
465 unsigned int *total_flags, u64 multicast)
466 {
467 struct brcms_info *wl = hw->priv;
468 struct wiphy *wiphy = hw->wiphy;
469
470 changed_flags &= MAC_FILTERS;
471 *total_flags &= MAC_FILTERS;
472 if (changed_flags & FIF_PROMISC_IN_BSS)
473 wiphy_err(wiphy, "FIF_PROMISC_IN_BSS\n");
474 if (changed_flags & FIF_ALLMULTI)
475 wiphy_err(wiphy, "FIF_ALLMULTI\n");
476 if (changed_flags & FIF_FCSFAIL)
477 wiphy_err(wiphy, "FIF_FCSFAIL\n");
478 if (changed_flags & FIF_PLCPFAIL)
479 wiphy_err(wiphy, "FIF_PLCPFAIL\n");
480 if (changed_flags & FIF_CONTROL)
481 wiphy_err(wiphy, "FIF_CONTROL\n");
482 if (changed_flags & FIF_OTHER_BSS)
483 wiphy_err(wiphy, "FIF_OTHER_BSS\n");
484 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
485 LOCK(wl);
486 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
487 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
488 brcms_c_mac_bcn_promisc_change(wl->wlc, 1);
489 } else {
490 brcms_c_mac_bcn_promisc_change(wl->wlc, 0);
491 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
492 }
493 UNLOCK(wl);
494 }
495 return;
496 }
497
498 static int
499 brcms_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
500 {
501 return 0;
502 }
503
504 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
505 {
506 struct brcms_info *wl = hw->priv;
507 LOCK(wl);
508 brcms_c_scan_start(wl->wlc);
509 UNLOCK(wl);
510 return;
511 }
512
513 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
514 {
515 struct brcms_info *wl = hw->priv;
516 LOCK(wl);
517 brcms_c_scan_stop(wl->wlc);
518 UNLOCK(wl);
519 return;
520 }
521
522 static void brcms_ops_set_tsf(struct ieee80211_hw *hw,
523 struct ieee80211_vif *vif, u64 tsf)
524 {
525 wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
526 return;
527 }
528
529 static int
530 brcms_ops_get_stats(struct ieee80211_hw *hw,
531 struct ieee80211_low_level_stats *stats)
532 {
533 struct brcms_info *wl = hw->priv;
534 struct wl_cnt *cnt;
535
536 LOCK(wl);
537 cnt = wl->pub->_cnt;
538 stats->dot11ACKFailureCount = 0;
539 stats->dot11RTSFailureCount = 0;
540 stats->dot11FCSErrorCount = 0;
541 stats->dot11RTSSuccessCount = 0;
542 UNLOCK(wl);
543 return 0;
544 }
545
546 static void
547 brcms_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
548 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
549 {
550 switch (cmd) {
551 default:
552 wiphy_err(hw->wiphy, "%s: Unknown cmd = %d\n", __func__,
553 cmd);
554 break;
555 }
556 return;
557 }
558
559 static int
560 brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
561 const struct ieee80211_tx_queue_params *params)
562 {
563 struct brcms_info *wl = hw->priv;
564
565 LOCK(wl);
566 brcms_c_wme_setparams(wl->wlc, queue, params, true);
567 UNLOCK(wl);
568
569 return 0;
570 }
571
572 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw,
573 struct ieee80211_vif *vif)
574 {
575 wiphy_err(hw->wiphy, "%s: Enter\n", __func__);
576 return 0;
577 }
578
579 static int
580 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
581 struct ieee80211_sta *sta)
582 {
583 struct scb *scb;
584
585 int i;
586 struct brcms_info *wl = hw->priv;
587
588 /* Init the scb */
589 scb = (struct scb *)sta->drv_priv;
590 memset(scb, 0, sizeof(struct scb));
591 for (i = 0; i < NUMPRIO; i++)
592 scb->seqctl[i] = 0xFFFF;
593 scb->seqctl_nonqos = 0xFFFF;
594 scb->magic = SCB_MAGIC;
595
596 wl->pub->global_scb = scb;
597 wl->pub->global_ampdu = &(scb->scb_ampdu);
598 wl->pub->global_ampdu->scb = scb;
599 wl->pub->global_ampdu->max_pdu = 16;
600 brcmu_pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
601 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
602
603 sta->ht_cap.ht_supported = true;
604 sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
605 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
606 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
607 IEEE80211_HT_CAP_SGI_20 |
608 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
609
610 /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */
611 return 0;
612 }
613
614 static int
615 brcms_ops_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
616 struct ieee80211_sta *sta)
617 {
618 return 0;
619 }
620
621 static int
622 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
623 struct ieee80211_vif *vif,
624 enum ieee80211_ampdu_mlme_action action,
625 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
626 u8 buf_size)
627 {
628 struct scb *scb = (struct scb *)sta->drv_priv;
629 struct brcms_info *wl = hw->priv;
630 int status;
631
632 if (WARN_ON(scb->magic != SCB_MAGIC))
633 return -EIDRM;
634 switch (action) {
635 case IEEE80211_AMPDU_RX_START:
636 break;
637 case IEEE80211_AMPDU_RX_STOP:
638 break;
639 case IEEE80211_AMPDU_TX_START:
640 LOCK(wl);
641 status = brcms_c_aggregatable(wl->wlc, tid);
642 UNLOCK(wl);
643 if (!status) {
644 wiphy_err(wl->wiphy, "START: tid %d is not agg\'able\n",
645 tid);
646 return -EINVAL;
647 }
648 /* Future improvement: Use the starting sequence number provided ... */
649 *ssn = 0;
650 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
651 break;
652
653 case IEEE80211_AMPDU_TX_STOP:
654 LOCK(wl);
655 brcms_c_ampdu_flush(wl->wlc, sta, tid);
656 UNLOCK(wl);
657 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
658 break;
659 case IEEE80211_AMPDU_TX_OPERATIONAL:
660 /*
661 * BA window size from ADDBA response ('buf_size') defines how
662 * many outstanding MPDUs are allowed for the BA stream by
663 * recipient and traffic class. 'ampdu_factor' gives maximum
664 * AMPDU size.
665 */
666 LOCK(wl);
667 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
668 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
669 sta->ht_cap.ampdu_factor)) - 1);
670 UNLOCK(wl);
671 /* Power save wakeup */
672 break;
673 default:
674 wiphy_err(wl->wiphy, "%s: Invalid command, ignoring\n",
675 __func__);
676 }
677
678 return 0;
679 }
680
681 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
682 {
683 struct brcms_info *wl = HW_TO_WL(hw);
684 bool blocked;
685
686 LOCK(wl);
687 blocked = brcms_c_check_radio_disabled(wl->wlc);
688 UNLOCK(wl);
689
690 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
691 }
692
693 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
694 {
695 struct brcms_info *wl = HW_TO_WL(hw);
696
697 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
698
699 /* wait for packet queue and dma fifos to run empty */
700 LOCK(wl);
701 brcms_c_wait_for_tx_completion(wl->wlc, drop);
702 UNLOCK(wl);
703 }
704
705 static const struct ieee80211_ops brcms_ops = {
706 .tx = brcms_ops_tx,
707 .start = brcms_ops_start,
708 .stop = brcms_ops_stop,
709 .add_interface = brcms_ops_add_interface,
710 .remove_interface = brcms_ops_remove_interface,
711 .config = brcms_ops_config,
712 .bss_info_changed = brcms_ops_bss_info_changed,
713 .configure_filter = brcms_ops_configure_filter,
714 .set_tim = brcms_ops_set_tim,
715 .sw_scan_start = brcms_ops_sw_scan_start,
716 .sw_scan_complete = brcms_ops_sw_scan_complete,
717 .set_tsf = brcms_ops_set_tsf,
718 .get_stats = brcms_ops_get_stats,
719 .sta_notify = brcms_ops_sta_notify,
720 .conf_tx = brcms_ops_conf_tx,
721 .get_tsf = brcms_ops_get_tsf,
722 .sta_add = brcms_ops_sta_add,
723 .sta_remove = brcms_ops_sta_remove,
724 .ampdu_action = brcms_ops_ampdu_action,
725 .rfkill_poll = brcms_ops_rfkill_poll,
726 .flush = brcms_ops_flush,
727 };
728
729 /*
730 * is called in brcms_pci_probe() context, therefore no locking required.
731 */
732 static int brcms_set_hint(struct brcms_info *wl, char *abbrev)
733 {
734 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
735 }
736
737 /**
738 * attach to the WL device.
739 *
740 * Attach to the WL device identified by vendor and device parameters.
741 * regs is a host accessible memory address pointing to WL device registers.
742 *
743 * brcms_attach is not defined as static because in the case where no bus
744 * is defined, wl_attach will never be called, and thus, gcc will issue
745 * a warning that this function is defined but not used if we declare
746 * it as static.
747 *
748 *
749 * is called in brcms_pci_probe() context, therefore no locking required.
750 */
751 static struct brcms_info *brcms_attach(u16 vendor, u16 device,
752 unsigned long regs,
753 uint bustype, void *btparam, uint irq)
754 {
755 struct brcms_info *wl = NULL;
756 int unit, err;
757 unsigned long base_addr;
758 struct ieee80211_hw *hw;
759 u8 perm[ETH_ALEN];
760
761 unit = n_adapters_found;
762 err = 0;
763
764 if (unit < 0) {
765 return NULL;
766 }
767
768 /* allocate private info */
769 hw = pci_get_drvdata(btparam); /* btparam == pdev */
770 if (hw != NULL)
771 wl = hw->priv;
772 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
773 return NULL;
774 wl->wiphy = hw->wiphy;
775
776 atomic_set(&wl->callbacks, 0);
777
778 /* setup the bottom half handler */
779 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
780
781
782
783 base_addr = regs;
784
785 if (bustype == PCI_BUS || bustype == RPC_BUS) {
786 /* Do nothing */
787 } else {
788 bustype = PCI_BUS;
789 BCMMSG(wl->wiphy, "force to PCI\n");
790 }
791 wl->bcm_bustype = bustype;
792
793 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
794 if (wl->regsva == NULL) {
795 wiphy_err(wl->wiphy, "wl%d: ioremap() failed\n", unit);
796 goto fail;
797 }
798 spin_lock_init(&wl->lock);
799 spin_lock_init(&wl->isr_lock);
800
801 /* prepare ucode */
802 if (brcms_request_fw(wl, (struct pci_dev *)btparam) < 0) {
803 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
804 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
805 brcms_release_fw(wl);
806 brcms_remove((struct pci_dev *)btparam);
807 return NULL;
808 }
809
810 /* common load-time initialization */
811 wl->wlc = brcms_c_attach((void *)wl, vendor, device, unit, false,
812 wl->regsva, wl->bcm_bustype, btparam, &err);
813 brcms_release_fw(wl);
814 if (!wl->wlc) {
815 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
816 KBUILD_MODNAME, err);
817 goto fail;
818 }
819 wl->pub = brcms_c_pub(wl->wlc);
820
821 wl->pub->ieee_hw = hw;
822
823 if (brcms_c_set_par(wl->wlc, IOV_MPC, 0) < 0) {
824 wiphy_err(wl->wiphy, "wl%d: Error setting MPC variable to 0\n",
825 unit);
826 }
827
828 /* register our interrupt handler */
829 if (request_irq(irq, brcms_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
830 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
831 goto fail;
832 }
833 wl->irq = irq;
834
835 /* register module */
836 brcms_c_module_register(wl->pub, "linux", wl, wl_linux_watchdog, NULL);
837
838 if (ieee_hw_init(hw)) {
839 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
840 __func__);
841 goto fail;
842 }
843
844 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
845 if (WARN_ON(!is_valid_ether_addr(perm)))
846 goto fail;
847 SET_IEEE80211_PERM_ADDR(hw, perm);
848
849 err = ieee80211_register_hw(hw);
850 if (err) {
851 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
852 "%d\n", __func__, err);
853 }
854
855 if (wl->pub->srom_ccode[0])
856 err = brcms_set_hint(wl, wl->pub->srom_ccode);
857 else
858 err = brcms_set_hint(wl, "US");
859 if (err) {
860 wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n",
861 __func__, err);
862 }
863
864 n_adapters_found++;
865 return wl;
866
867 fail:
868 brcms_free(wl);
869 return NULL;
870 }
871
872
873
874 #define CHAN2GHZ(channel, freqency, chflags) { \
875 .band = IEEE80211_BAND_2GHZ, \
876 .center_freq = (freqency), \
877 .hw_value = (channel), \
878 .flags = chflags, \
879 .max_antenna_gain = 0, \
880 .max_power = 19, \
881 }
882
883 static struct ieee80211_channel brcms_2ghz_chantable[] = {
884 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
885 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
886 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
887 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
888 CHAN2GHZ(5, 2432, 0),
889 CHAN2GHZ(6, 2437, 0),
890 CHAN2GHZ(7, 2442, 0),
891 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
892 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
893 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
894 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
895 CHAN2GHZ(12, 2467,
896 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
897 IEEE80211_CHAN_NO_HT40PLUS),
898 CHAN2GHZ(13, 2472,
899 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
900 IEEE80211_CHAN_NO_HT40PLUS),
901 CHAN2GHZ(14, 2484,
902 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
903 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
904 };
905
906 #define CHAN5GHZ(channel, chflags) { \
907 .band = IEEE80211_BAND_5GHZ, \
908 .center_freq = 5000 + 5*(channel), \
909 .hw_value = (channel), \
910 .flags = chflags, \
911 .max_antenna_gain = 0, \
912 .max_power = 21, \
913 }
914
915 static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
916 /* UNII-1 */
917 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
918 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
919 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
920 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
921 /* UNII-2 */
922 CHAN5GHZ(52,
923 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
924 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
925 CHAN5GHZ(56,
926 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
927 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
928 CHAN5GHZ(60,
929 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
930 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
931 CHAN5GHZ(64,
932 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
933 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
934 /* MID */
935 CHAN5GHZ(100,
936 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
937 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
938 CHAN5GHZ(104,
939 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
940 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
941 CHAN5GHZ(108,
942 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
943 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
944 CHAN5GHZ(112,
945 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
946 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
947 CHAN5GHZ(116,
948 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
949 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
950 CHAN5GHZ(120,
951 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
952 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
953 CHAN5GHZ(124,
954 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
955 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
956 CHAN5GHZ(128,
957 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
958 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
959 CHAN5GHZ(132,
960 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
961 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
962 CHAN5GHZ(136,
963 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
964 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
965 CHAN5GHZ(140,
966 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
967 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
968 IEEE80211_CHAN_NO_HT40MINUS),
969 /* UNII-3 */
970 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
971 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
972 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
973 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
974 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
975 };
976
977 #define RATE(rate100m, _flags) { \
978 .bitrate = (rate100m), \
979 .flags = (_flags), \
980 .hw_value = (rate100m / 5), \
981 }
982
983 static struct ieee80211_rate legacy_ratetable[] = {
984 RATE(10, 0),
985 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
986 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
987 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
988 RATE(60, 0),
989 RATE(90, 0),
990 RATE(120, 0),
991 RATE(180, 0),
992 RATE(240, 0),
993 RATE(360, 0),
994 RATE(480, 0),
995 RATE(540, 0),
996 };
997
998 static struct ieee80211_supported_band brcms_band_2GHz_nphy = {
999 .band = IEEE80211_BAND_2GHZ,
1000 .channels = brcms_2ghz_chantable,
1001 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
1002 .bitrates = legacy_ratetable,
1003 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
1004 .ht_cap = {
1005 /* from include/linux/ieee80211.h */
1006 .cap = IEEE80211_HT_CAP_GRN_FLD |
1007 IEEE80211_HT_CAP_SGI_20 |
1008 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1009 .ht_supported = true,
1010 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1011 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1012 .mcs = {
1013 /* placeholders for now */
1014 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1015 .rx_highest = 500,
1016 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1017 }
1018 };
1019
1020 static struct ieee80211_supported_band brcms_band_5GHz_nphy = {
1021 .band = IEEE80211_BAND_5GHZ,
1022 .channels = brcms_5ghz_nphy_chantable,
1023 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
1024 .bitrates = legacy_ratetable + 4,
1025 .n_bitrates = ARRAY_SIZE(legacy_ratetable) - 4,
1026 .ht_cap = {
1027 /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */
1028 .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 */
1029 .ht_supported = true,
1030 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
1031 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1032 .mcs = {
1033 /* placeholders for now */
1034 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1035 .rx_highest = 500,
1036 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1037 }
1038 };
1039
1040 /*
1041 * is called in brcms_pci_probe() context, therefore no locking required.
1042 */
1043 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1044 {
1045 struct brcms_info *wl = HW_TO_WL(hw);
1046 int has_5g;
1047 char phy_list[4];
1048
1049 has_5g = 0;
1050
1051 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1052 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1053
1054 if (brcms_c_get(wl->wlc, BRCM_GET_PHYLIST, (int *)&phy_list) < 0)
1055 wiphy_err(hw->wiphy, "Phy list failed\n");
1056
1057 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1058 if (phy_list[0] == 'c') {
1059 /* Single stream */
1060 brcms_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1061 brcms_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1062 }
1063 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &brcms_band_2GHz_nphy;
1064 } else {
1065 return -EPERM;
1066 }
1067
1068 /* Assume all bands use the same phy. True for 11n devices. */
1069 if (NBANDS_PUB(wl->pub) > 1) {
1070 has_5g++;
1071 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1072 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1073 &brcms_band_5GHz_nphy;
1074 } else {
1075 return -EPERM;
1076 }
1077 }
1078 return 0;
1079 }
1080
1081 /*
1082 * is called in brcms_pci_probe() context, therefore no locking required.
1083 */
1084 static int ieee_hw_init(struct ieee80211_hw *hw)
1085 {
1086 hw->flags = IEEE80211_HW_SIGNAL_DBM
1087 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1088 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1089 | IEEE80211_HW_AMPDU_AGGREGATION;
1090
1091 hw->extra_tx_headroom = brcms_c_get_header_len();
1092 hw->queues = N_TX_QUEUES;
1093 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1094
1095 hw->channel_change_time = 7 * 1000; /* channel change time is dependent on chip and band */
1096 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1097
1098 hw->rate_control_algorithm = "minstrel_ht";
1099
1100 hw->sta_data_size = sizeof(struct scb);
1101 return ieee_hw_rate_init(hw);
1102 }
1103
1104 /**
1105 * determines if a device is a WL device, and if so, attaches it.
1106 *
1107 * This function determines if a device pointed to by pdev is a WL device,
1108 * and if so, performs a brcms_attach() on it.
1109 *
1110 * Perimeter lock is initialized in the course of this function.
1111 */
1112 static int __devinit
1113 brcms_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1114 {
1115 int rc;
1116 struct brcms_info *wl;
1117 struct ieee80211_hw *hw;
1118 u32 val;
1119
1120 dev_info(&pdev->dev, "bus %d slot %d func %d irq %d\n",
1121 pdev->bus->number, PCI_SLOT(pdev->devfn),
1122 PCI_FUNC(pdev->devfn), pdev->irq);
1123
1124 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1125 ((pdev->device != 0x0576) &&
1126 ((pdev->device & 0xff00) != 0x4300) &&
1127 ((pdev->device & 0xff00) != 0x4700) &&
1128 ((pdev->device < 43000) || (pdev->device > 43999))))
1129 return -ENODEV;
1130
1131 rc = pci_enable_device(pdev);
1132 if (rc) {
1133 pr_err("%s: Cannot enable device %d-%d_%d\n",
1134 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1135 PCI_FUNC(pdev->devfn));
1136 return -ENODEV;
1137 }
1138 pci_set_master(pdev);
1139
1140 pci_read_config_dword(pdev, 0x40, &val);
1141 if ((val & 0x0000ff00) != 0)
1142 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1143
1144 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1145 if (!hw) {
1146 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1147 return -ENOMEM;
1148 }
1149
1150 SET_IEEE80211_DEV(hw, &pdev->dev);
1151
1152 pci_set_drvdata(pdev, hw);
1153
1154 memset(hw->priv, 0, sizeof(*wl));
1155
1156 wl = brcms_attach(pdev->vendor, pdev->device,
1157 pci_resource_start(pdev, 0), PCI_BUS, pdev,
1158 pdev->irq);
1159
1160 if (!wl) {
1161 pr_err("%s: %s: brcms_attach failed!\n", KBUILD_MODNAME,
1162 __func__);
1163 return -ENODEV;
1164 }
1165 return 0;
1166 }
1167
1168 static int brcms_suspend(struct pci_dev *pdev, pm_message_t state)
1169 {
1170 struct brcms_info *wl;
1171 struct ieee80211_hw *hw;
1172
1173 hw = pci_get_drvdata(pdev);
1174 wl = HW_TO_WL(hw);
1175 if (!wl) {
1176 wiphy_err(wl->wiphy,
1177 "brcms_suspend: pci_get_drvdata failed\n");
1178 return -ENODEV;
1179 }
1180
1181 /* only need to flag hw is down for proper resume */
1182 LOCK(wl);
1183 wl->pub->hw_up = false;
1184 UNLOCK(wl);
1185
1186 pci_save_state(pdev);
1187 pci_disable_device(pdev);
1188 return pci_set_power_state(pdev, PCI_D3hot);
1189 }
1190
1191 static int brcms_resume(struct pci_dev *pdev)
1192 {
1193 struct brcms_info *wl;
1194 struct ieee80211_hw *hw;
1195 int err = 0;
1196 u32 val;
1197
1198 hw = pci_get_drvdata(pdev);
1199 wl = HW_TO_WL(hw);
1200 if (!wl) {
1201 wiphy_err(wl->wiphy,
1202 "wl: brcms_resume: pci_get_drvdata failed\n");
1203 return -ENODEV;
1204 }
1205
1206 err = pci_set_power_state(pdev, PCI_D0);
1207 if (err)
1208 return err;
1209
1210 pci_restore_state(pdev);
1211
1212 err = pci_enable_device(pdev);
1213 if (err)
1214 return err;
1215
1216 pci_set_master(pdev);
1217
1218 pci_read_config_dword(pdev, 0x40, &val);
1219 if ((val & 0x0000ff00) != 0)
1220 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1221
1222 /*
1223 * done. driver will be put in up state
1224 * in brcms_ops_add_interface() call.
1225 */
1226 return err;
1227 }
1228
1229 /*
1230 * called from both kernel as from this kernel module.
1231 * precondition: perimeter lock is not acquired.
1232 */
1233 static void brcms_remove(struct pci_dev *pdev)
1234 {
1235 struct brcms_info *wl;
1236 struct ieee80211_hw *hw;
1237 int status;
1238
1239 hw = pci_get_drvdata(pdev);
1240 wl = HW_TO_WL(hw);
1241 if (!wl) {
1242 pr_err("wl: brcms_remove: pci_get_drvdata failed\n");
1243 return;
1244 }
1245
1246 LOCK(wl);
1247 status = brcms_c_chipmatch(pdev->vendor, pdev->device);
1248 UNLOCK(wl);
1249 if (!status) {
1250 wiphy_err(wl->wiphy, "wl: brcms_remove: chipmatch "
1251 "failed\n");
1252 return;
1253 }
1254 if (wl->wlc) {
1255 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
1256 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
1257 ieee80211_unregister_hw(hw);
1258 LOCK(wl);
1259 brcms_down(wl);
1260 UNLOCK(wl);
1261 }
1262 pci_disable_device(pdev);
1263
1264 brcms_free(wl);
1265
1266 pci_set_drvdata(pdev, NULL);
1267 ieee80211_free_hw(hw);
1268 }
1269
1270 static struct pci_driver brcms_pci_driver = {
1271 .name = KBUILD_MODNAME,
1272 .probe = brcms_pci_probe,
1273 .suspend = brcms_suspend,
1274 .resume = brcms_resume,
1275 .remove = __devexit_p(brcms_remove),
1276 .id_table = brcms_pci_id_table,
1277 };
1278
1279 /**
1280 * This is the main entry point for the WL driver.
1281 *
1282 * This function determines if a device pointed to by pdev is a WL device,
1283 * and if so, performs a brcms_attach() on it.
1284 *
1285 */
1286 static int __init brcms_module_init(void)
1287 {
1288 int error = -ENODEV;
1289
1290 #ifdef BCMDBG
1291 if (msglevel != 0xdeadbeef)
1292 brcm_msg_level = msglevel;
1293 if (phymsglevel != 0xdeadbeef)
1294 phyhal_msg_level = phymsglevel;
1295 #endif /* BCMDBG */
1296
1297 error = pci_register_driver(&brcms_pci_driver);
1298 if (!error)
1299 return 0;
1300
1301
1302
1303 return error;
1304 }
1305
1306 /**
1307 * This function unloads the WL driver from the system.
1308 *
1309 * This function unconditionally unloads the WL driver module from the
1310 * system.
1311 *
1312 */
1313 static void __exit brcms_module_exit(void)
1314 {
1315 pci_unregister_driver(&brcms_pci_driver);
1316
1317 }
1318
1319 module_init(brcms_module_init);
1320 module_exit(brcms_module_exit);
1321
1322 /**
1323 * This function frees the WL per-device resources.
1324 *
1325 * This function frees resources owned by the WL device pointed to
1326 * by the wl parameter.
1327 *
1328 * precondition: can both be called locked and unlocked
1329 *
1330 */
1331 static void brcms_free(struct brcms_info *wl)
1332 {
1333 struct brcms_timer *t, *next;
1334
1335 /* free ucode data */
1336 if (wl->fw.fw_cnt)
1337 brcms_ucode_data_free();
1338 if (wl->irq)
1339 free_irq(wl->irq, wl);
1340
1341 /* kill dpc */
1342 tasklet_kill(&wl->tasklet);
1343
1344 if (wl->pub) {
1345 brcms_c_module_unregister(wl->pub, "linux", wl);
1346 }
1347
1348 /* free common resources */
1349 if (wl->wlc) {
1350 brcms_c_detach(wl->wlc);
1351 wl->wlc = NULL;
1352 wl->pub = NULL;
1353 }
1354
1355 /* virtual interface deletion is deferred so we cannot spinwait */
1356
1357 /* wait for all pending callbacks to complete */
1358 while (atomic_read(&wl->callbacks) > 0)
1359 schedule();
1360
1361 /* free timers */
1362 for (t = wl->timers; t; t = next) {
1363 next = t->next;
1364 #ifdef BCMDBG
1365 kfree(t->name);
1366 #endif
1367 kfree(t);
1368 }
1369
1370 /*
1371 * unregister_netdev() calls get_stats() which may read chip registers
1372 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1373 */
1374 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1375 wl->bcm_bustype != JTAG_BUS) {
1376 iounmap((void *)wl->regsva);
1377 }
1378 wl->regsva = NULL;
1379 }
1380
1381 /* flags the given rate in rateset as requested */
1382 static void brcms_set_basic_rate(struct wl_rateset *rs, u16 rate, bool is_br)
1383 {
1384 u32 i;
1385
1386 for (i = 0; i < rs->count; i++) {
1387 if (rate != (rs->rates[i] & 0x7f))
1388 continue;
1389
1390 if (is_br)
1391 rs->rates[i] |= BRCMS_RATE_FLAG;
1392 else
1393 rs->rates[i] &= BRCMS_RATE_MASK;
1394 return;
1395 }
1396 }
1397
1398 /*
1399 * precondition: perimeter lock has been acquired
1400 */
1401 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1402 bool state, int prio)
1403 {
1404 wiphy_err(wl->wiphy, "Shouldn't be here %s\n", __func__);
1405 }
1406
1407 /*
1408 * precondition: perimeter lock has been acquired
1409 */
1410 void brcms_init(struct brcms_info *wl)
1411 {
1412 BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
1413 brcms_reset(wl);
1414
1415 brcms_c_init(wl->wlc);
1416 }
1417
1418 /*
1419 * precondition: perimeter lock has been acquired
1420 */
1421 uint brcms_reset(struct brcms_info *wl)
1422 {
1423 BCMMSG(WL_TO_HW(wl)->wiphy, "wl%d\n", wl->pub->unit);
1424 brcms_c_reset(wl->wlc);
1425
1426 /* dpc will not be rescheduled */
1427 wl->resched = 0;
1428
1429 return 0;
1430 }
1431
1432 /*
1433 * These are interrupt on/off entry points. Disable interrupts
1434 * during interrupt state transition.
1435 */
1436 void brcms_intrson(struct brcms_info *wl)
1437 {
1438 unsigned long flags;
1439
1440 INT_LOCK(wl, flags);
1441 brcms_c_intrson(wl->wlc);
1442 INT_UNLOCK(wl, flags);
1443 }
1444
1445 /*
1446 * precondition: perimeter lock has been acquired
1447 */
1448 bool wl_alloc_dma_resources(struct brcms_info *wl, uint addrwidth)
1449 {
1450 return true;
1451 }
1452
1453 u32 brcms_intrsoff(struct brcms_info *wl)
1454 {
1455 unsigned long flags;
1456 u32 status;
1457
1458 INT_LOCK(wl, flags);
1459 status = brcms_c_intrsoff(wl->wlc);
1460 INT_UNLOCK(wl, flags);
1461 return status;
1462 }
1463
1464 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1465 {
1466 unsigned long flags;
1467
1468 INT_LOCK(wl, flags);
1469 brcms_c_intrsrestore(wl->wlc, macintmask);
1470 INT_UNLOCK(wl, flags);
1471 }
1472
1473 /*
1474 * precondition: perimeter lock has been acquired
1475 */
1476 int brcms_up(struct brcms_info *wl)
1477 {
1478 int error = 0;
1479
1480 if (wl->pub->up)
1481 return 0;
1482
1483 error = brcms_c_up(wl->wlc);
1484
1485 return error;
1486 }
1487
1488 /*
1489 * precondition: perimeter lock has been acquired
1490 */
1491 void brcms_down(struct brcms_info *wl)
1492 {
1493 uint callbacks, ret_val = 0;
1494
1495 /* call common down function */
1496 ret_val = brcms_c_down(wl->wlc);
1497 callbacks = atomic_read(&wl->callbacks) - ret_val;
1498
1499 /* wait for down callbacks to complete */
1500 UNLOCK(wl);
1501
1502 /* For HIGH_only driver, it's important to actually schedule other work,
1503 * not just spin wait since everything runs at schedule level
1504 */
1505 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1506
1507 LOCK(wl);
1508 }
1509
1510 static irqreturn_t brcms_isr(int irq, void *dev_id)
1511 {
1512 struct brcms_info *wl;
1513 bool ours, wantdpc;
1514 unsigned long flags;
1515
1516 wl = (struct brcms_info *) dev_id;
1517
1518 ISR_LOCK(wl, flags);
1519
1520 /* call common first level interrupt handler */
1521 ours = brcms_c_isr(wl->wlc, &wantdpc);
1522 if (ours) {
1523 /* if more to do... */
1524 if (wantdpc) {
1525
1526 /* ...and call the second level interrupt handler */
1527 /* schedule dpc */
1528 tasklet_schedule(&wl->tasklet);
1529 }
1530 }
1531
1532 ISR_UNLOCK(wl, flags);
1533
1534 return IRQ_RETVAL(ours);
1535 }
1536
1537 static void brcms_dpc(unsigned long data)
1538 {
1539 struct brcms_info *wl;
1540
1541 wl = (struct brcms_info *) data;
1542
1543 LOCK(wl);
1544
1545 /* call the common second level interrupt handler */
1546 if (wl->pub->up) {
1547 if (wl->resched) {
1548 unsigned long flags;
1549
1550 INT_LOCK(wl, flags);
1551 brcms_c_intrsupd(wl->wlc);
1552 INT_UNLOCK(wl, flags);
1553 }
1554
1555 wl->resched = brcms_c_dpc(wl->wlc, true);
1556 }
1557
1558 /* brcms_c_dpc() may bring the driver down */
1559 if (!wl->pub->up)
1560 goto done;
1561
1562 /* re-schedule dpc */
1563 if (wl->resched)
1564 tasklet_schedule(&wl->tasklet);
1565 else {
1566 /* re-enable interrupts */
1567 brcms_intrson(wl);
1568 }
1569
1570 done:
1571 UNLOCK(wl);
1572 }
1573
1574 /*
1575 * is called by the kernel from software irq context
1576 */
1577 static void brcms_timer(unsigned long data)
1578 {
1579 _brcms_timer((struct brcms_timer *) data);
1580 }
1581
1582 /*
1583 * precondition: perimeter lock is not acquired
1584 */
1585 static void _brcms_timer(struct brcms_timer *t)
1586 {
1587 LOCK(t->wl);
1588
1589 if (t->set) {
1590 if (t->periodic) {
1591 t->timer.expires = jiffies + t->ms * HZ / 1000;
1592 atomic_inc(&t->wl->callbacks);
1593 add_timer(&t->timer);
1594 t->set = true;
1595 } else
1596 t->set = false;
1597
1598 t->fn(t->arg);
1599 }
1600
1601 atomic_dec(&t->wl->callbacks);
1602
1603 UNLOCK(t->wl);
1604 }
1605
1606 /*
1607 * Adds a timer to the list. Caller supplies a timer function.
1608 * Is called from wlc.
1609 *
1610 * precondition: perimeter lock has been acquired
1611 */
1612 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1613 void (*fn) (void *arg),
1614 void *arg, const char *name)
1615 {
1616 struct brcms_timer *t;
1617
1618 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1619 if (!t) {
1620 wiphy_err(wl->wiphy, "wl%d: brcms_init_timer: out of memory\n",
1621 wl->pub->unit);
1622 return 0;
1623 }
1624
1625 init_timer(&t->timer);
1626 t->timer.data = (unsigned long) t;
1627 t->timer.function = brcms_timer;
1628 t->wl = wl;
1629 t->fn = fn;
1630 t->arg = arg;
1631 t->next = wl->timers;
1632 wl->timers = t;
1633
1634 #ifdef BCMDBG
1635 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1636 if (t->name)
1637 strcpy(t->name, name);
1638 #endif
1639
1640 return t;
1641 }
1642
1643 /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1644 * as well as it's easier to make it periodic
1645 *
1646 * precondition: perimeter lock has been acquired
1647 */
1648 void brcms_add_timer(struct brcms_info *wl, struct brcms_timer *t, uint ms,
1649 int periodic)
1650 {
1651 #ifdef BCMDBG
1652 if (t->set) {
1653 wiphy_err(wl->wiphy, "%s: Already set. Name: %s, per %d\n",
1654 __func__, t->name, periodic);
1655 }
1656 #endif
1657 t->ms = ms;
1658 t->periodic = (bool) periodic;
1659 t->set = true;
1660 t->timer.expires = jiffies + ms * HZ / 1000;
1661
1662 atomic_inc(&wl->callbacks);
1663 add_timer(&t->timer);
1664 }
1665
1666 /*
1667 * return true if timer successfully deleted, false if still pending
1668 *
1669 * precondition: perimeter lock has been acquired
1670 */
1671 bool brcms_del_timer(struct brcms_info *wl, struct brcms_timer *t)
1672 {
1673 if (t->set) {
1674 t->set = false;
1675 if (!del_timer(&t->timer)) {
1676 return false;
1677 }
1678 atomic_dec(&wl->callbacks);
1679 }
1680
1681 return true;
1682 }
1683
1684 /*
1685 * precondition: perimeter lock has been acquired
1686 */
1687 void brcms_free_timer(struct brcms_info *wl, struct brcms_timer *t)
1688 {
1689 struct brcms_timer *tmp;
1690
1691 /* delete the timer in case it is active */
1692 brcms_del_timer(wl, t);
1693
1694 if (wl->timers == t) {
1695 wl->timers = wl->timers->next;
1696 #ifdef BCMDBG
1697 kfree(t->name);
1698 #endif
1699 kfree(t);
1700 return;
1701
1702 }
1703
1704 tmp = wl->timers;
1705 while (tmp) {
1706 if (tmp->next == t) {
1707 tmp->next = t->next;
1708 #ifdef BCMDBG
1709 kfree(t->name);
1710 #endif
1711 kfree(t);
1712 return;
1713 }
1714 tmp = tmp->next;
1715 }
1716
1717 }
1718
1719 /*
1720 * runs in software irq context
1721 *
1722 * precondition: perimeter lock is not acquired
1723 */
1724 static int wl_linux_watchdog(void *ctx)
1725 {
1726 return 0;
1727 }
1728
1729 struct firmware_hdr {
1730 u32 offset;
1731 u32 len;
1732 u32 idx;
1733 };
1734
1735 char *brcms_firmwares[MAX_FW_IMAGES] = {
1736 "brcm/bcm43xx",
1737 NULL
1738 };
1739
1740 /*
1741 * precondition: perimeter lock has been acquired
1742 */
1743 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1744 {
1745 int i, entry;
1746 const u8 *pdata;
1747 struct firmware_hdr *hdr;
1748 for (i = 0; i < wl->fw.fw_cnt; i++) {
1749 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1750 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1751 entry++, hdr++) {
1752 if (hdr->idx == idx) {
1753 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1754 *pbuf = kmalloc(hdr->len, GFP_ATOMIC);
1755 if (*pbuf == NULL) {
1756 wiphy_err(wl->wiphy, "fail to alloc %d"
1757 " bytes\n", hdr->len);
1758 goto fail;
1759 }
1760 memcpy(*pbuf, pdata, hdr->len);
1761 return 0;
1762 }
1763 }
1764 }
1765 wiphy_err(wl->wiphy, "ERROR: ucode buf tag:%d can not be found!\n",
1766 idx);
1767 *pbuf = NULL;
1768 fail:
1769 return -ENODATA;
1770 }
1771
1772 /*
1773 * Precondition: Since this function is called in brcms_pci_probe() context,
1774 * no locking is required.
1775 */
1776 int brcms_ucode_init_uint(struct brcms_info *wl, u32 *data, u32 idx)
1777 {
1778 int i, entry;
1779 const u8 *pdata;
1780 struct firmware_hdr *hdr;
1781 for (i = 0; i < wl->fw.fw_cnt; i++) {
1782 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1783 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1784 entry++, hdr++) {
1785 if (hdr->idx == idx) {
1786 pdata = wl->fw.fw_bin[i]->data + hdr->offset;
1787 if (hdr->len != 4) {
1788 wiphy_err(wl->wiphy,
1789 "ERROR: fw hdr len\n");
1790 return -ENOMSG;
1791 }
1792 *data = *((u32 *) pdata);
1793 return 0;
1794 }
1795 }
1796 }
1797 wiphy_err(wl->wiphy, "ERROR: ucode tag:%d can not be found!\n", idx);
1798 return -ENOMSG;
1799 }
1800
1801 /*
1802 * Precondition: Since this function is called in brcms_pci_probe() context,
1803 * no locking is required.
1804 */
1805 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev)
1806 {
1807 int status;
1808 struct device *device = &pdev->dev;
1809 char fw_name[100];
1810 int i;
1811
1812 memset((void *)&wl->fw, 0, sizeof(struct brcms_firmware));
1813 for (i = 0; i < MAX_FW_IMAGES; i++) {
1814 if (brcms_firmwares[i] == NULL)
1815 break;
1816 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
1817 UCODE_LOADER_API_VER);
1818 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
1819 if (status) {
1820 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
1821 KBUILD_MODNAME, fw_name);
1822 return status;
1823 }
1824 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
1825 UCODE_LOADER_API_VER);
1826 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
1827 if (status) {
1828 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
1829 KBUILD_MODNAME, fw_name);
1830 return status;
1831 }
1832 wl->fw.hdr_num_entries[i] =
1833 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
1834 }
1835 wl->fw.fw_cnt = i;
1836 return brcms_ucode_data_init(wl);
1837 }
1838
1839 /*
1840 * precondition: can both be called locked and unlocked
1841 */
1842 void brcms_ucode_free_buf(void *p)
1843 {
1844 kfree(p);
1845 }
1846
1847 /*
1848 * Precondition: Since this function is called in brcms_pci_probe() context,
1849 * no locking is required.
1850 */
1851 static void brcms_release_fw(struct brcms_info *wl)
1852 {
1853 int i;
1854 for (i = 0; i < MAX_FW_IMAGES; i++) {
1855 release_firmware(wl->fw.fw_bin[i]);
1856 release_firmware(wl->fw.fw_hdr[i]);
1857 }
1858 }
1859
1860
1861 /*
1862 * checks validity of all firmware images loaded from user space
1863 *
1864 * Precondition: Since this function is called in brcms_pci_probe() context,
1865 * no locking is required.
1866 */
1867 int brcms_check_firmwares(struct brcms_info *wl)
1868 {
1869 int i;
1870 int entry;
1871 int rc = 0;
1872 const struct firmware *fw;
1873 const struct firmware *fw_hdr;
1874 struct firmware_hdr *ucode_hdr;
1875 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1876 fw = wl->fw.fw_bin[i];
1877 fw_hdr = wl->fw.fw_hdr[i];
1878 if (fw == NULL && fw_hdr == NULL) {
1879 break;
1880 } else if (fw == NULL || fw_hdr == NULL) {
1881 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1882 __func__);
1883 rc = -EBADF;
1884 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1885 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1886 "size %zu/%zu\n", __func__, fw_hdr->size,
1887 sizeof(struct firmware_hdr));
1888 rc = -EBADF;
1889 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1890 wiphy_err(wl->wiphy, "%s: out of bounds fw file size "
1891 "%zu\n", __func__, fw->size);
1892 rc = -EBADF;
1893 } else {
1894 /* check if ucode section overruns firmware image */
1895 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1896 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1897 !rc; entry++, ucode_hdr++) {
1898 if (ucode_hdr->offset + ucode_hdr->len >
1899 fw->size) {
1900 wiphy_err(wl->wiphy,
1901 "%s: conflicting bin/hdr\n",
1902 __func__);
1903 rc = -EBADF;
1904 }
1905 }
1906 }
1907 }
1908 if (rc == 0 && wl->fw.fw_cnt != i) {
1909 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1910 wl->fw.fw_cnt);
1911 rc = -EBADF;
1912 }
1913 return rc;
1914 }
1915
1916 /*
1917 * precondition: perimeter lock has been acquired
1918 */
1919 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1920 {
1921 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1922
1923 UNLOCK(wl);
1924 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1925 if (blocked)
1926 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1927 LOCK(wl);
1928 return blocked;
1929 }
1930
1931 /*
1932 * precondition: perimeter lock has been acquired
1933 */
1934 void brcms_msleep(struct brcms_info *wl, uint ms)
1935 {
1936 UNLOCK(wl);
1937 msleep(ms);
1938 LOCK(wl);
1939 }
This page took 0.075505 seconds and 5 git commands to generate.