staging: brcm80211: made name lookup arrays more const
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / brcm80211 / brcmsmac / main.c
blobb89b0ec8c17df30ca538be0fda3d0189edc9b878
1 /*
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 #include <linux/pci_ids.h>
18 #include <net/mac80211.h>
20 #include <brcm_hw_ids.h>
21 #include <aiutils.h>
22 #include "rate.h"
23 #include "scb.h"
24 #include "phy/phy_hal.h"
25 #include "channel.h"
26 #include "bmac.h"
27 #include "antsel.h"
28 #include "stf.h"
29 #include "ampdu.h"
30 #include "alloc.h"
31 #include "mac80211_if.h"
32 #include "main.h"
35 * WPA(2) definitions
37 #define RSN_CAP_4_REPLAY_CNTRS 2
38 #define RSN_CAP_16_REPLAY_CNTRS 3
40 #define WPA_CAP_4_REPLAY_CNTRS RSN_CAP_4_REPLAY_CNTRS
41 #define WPA_CAP_16_REPLAY_CNTRS RSN_CAP_16_REPLAY_CNTRS
44 * Indication for txflowcontrol that all priority bits in
45 * TXQ_STOP_FOR_PRIOFC_MASK are to be considered.
47 #define ALLPRIO -1
50 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
52 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
54 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
55 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
57 #ifndef WLC_MPC_MAX_DELAYCNT
58 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
59 #endif
60 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
61 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
63 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
64 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
66 /* Scale down delays to accommodate QT slow speed */
67 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
68 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
70 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
72 /* Software feature flag defines used by wlfeatureflag */
73 #define WL_SWFL_NOHWRADIO 0x0004
74 #define WL_SWFL_FLOWCONTROL 0x0008 /* Enable backpressure to OS stack */
75 #define WL_SWFL_WLBSSSORT 0x0010 /* Per-port supports sorting of BSS */
77 /* n-mode support capability */
78 /* 2x2 includes both 1x1 & 2x2 devices
79 * reserved #define 2 for future when we want to separate 1x1 & 2x2 and
80 * control it independently
82 #define WL_11N_2x2 1
83 #define WL_11N_3x3 3
84 #define WL_11N_4x4 4
86 /* define 11n feature disable flags */
87 #define WLFEATURE_DISABLE_11N 0x00000001
88 #define WLFEATURE_DISABLE_11N_STBC_TX 0x00000002
89 #define WLFEATURE_DISABLE_11N_STBC_RX 0x00000004
90 #define WLFEATURE_DISABLE_11N_SGI_TX 0x00000008
91 #define WLFEATURE_DISABLE_11N_SGI_RX 0x00000010
92 #define WLFEATURE_DISABLE_11N_AMPDU_TX 0x00000020
93 #define WLFEATURE_DISABLE_11N_AMPDU_RX 0x00000040
94 #define WLFEATURE_DISABLE_11N_GF 0x00000080
96 #define EDCF_ACI_MASK 0x60
97 #define EDCF_ACI_SHIFT 5
98 #define EDCF_ECWMIN_MASK 0x0f
99 #define EDCF_ECWMAX_SHIFT 4
100 #define EDCF_AIFSN_MASK 0x0f
101 #define EDCF_AIFSN_MAX 15
102 #define EDCF_ECWMAX_MASK 0xf0
104 #define EDCF_AC_BE_TXOP_STA 0x0000
105 #define EDCF_AC_BK_TXOP_STA 0x0000
106 #define EDCF_AC_VO_ACI_STA 0x62
107 #define EDCF_AC_VO_ECW_STA 0x32
108 #define EDCF_AC_VI_ACI_STA 0x42
109 #define EDCF_AC_VI_ECW_STA 0x43
110 #define EDCF_AC_BK_ECW_STA 0xA4
111 #define EDCF_AC_VI_TXOP_STA 0x005e
112 #define EDCF_AC_VO_TXOP_STA 0x002f
113 #define EDCF_AC_BE_ACI_STA 0x03
114 #define EDCF_AC_BE_ECW_STA 0xA4
115 #define EDCF_AC_BK_ACI_STA 0x27
116 #define EDCF_AC_VO_TXOP_AP 0x002f
118 #define EDCF_TXOP2USEC(txop) ((txop) << 5)
119 #define EDCF_ECW2CW(exp) ((1 << (exp)) - 1)
121 #define APHY_SYMBOL_TIME 4
122 #define APHY_PREAMBLE_TIME 16
123 #define APHY_SIGNAL_TIME 4
124 #define APHY_SIFS_TIME 16
125 #define APHY_SERVICE_NBITS 16
126 #define APHY_TAIL_NBITS 6
127 #define BPHY_SIFS_TIME 10
128 #define BPHY_PLCP_SHORT_TIME 96
130 #define PREN_PREAMBLE 24
131 #define PREN_MM_EXT 12
132 #define PREN_PREAMBLE_EXT 4
134 #define DOT11_MAC_HDR_LEN 24
135 #define DOT11_ACK_LEN 10
136 #define DOT11_BA_LEN 4
137 #define DOT11_OFDM_SIGNAL_EXTENSION 6
138 #define DOT11_MIN_FRAG_LEN 256
139 #define DOT11_RTS_LEN 16
140 #define DOT11_CTS_LEN 10
141 #define DOT11_BA_BITMAP_LEN 128
142 #define DOT11_MIN_BEACON_PERIOD 1
143 #define DOT11_MAX_BEACON_PERIOD 0xFFFF
144 #define DOT11_MAXNUMFRAGS 16
145 #define DOT11_MAX_FRAG_LEN 2346
147 #define BPHY_PLCP_TIME 192
148 #define RIFS_11N_TIME 2
150 #define WME_VER 1
151 #define WME_SUBTYPE_PARAM_IE 1
152 #define WME_TYPE 2
153 #define WME_OUI "\x00\x50\xf2"
155 #define AC_BE 0
156 #define AC_BK 1
157 #define AC_VI 2
158 #define AC_VO 3
161 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
162 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
163 * this low resolution driver tick can be used for maintenance tasks such as phy
164 * calibration and scb update
167 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
168 #define BCMCFID(wlc, fid) brcms_b_write_shm((wlc)->hw, M_BCMC_FID, (fid))
170 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
171 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
173 /* debug/trace */
174 uint brcm_msg_level =
175 #if defined(BCMDBG)
176 LOG_ERROR_VAL;
177 #else
179 #endif /* BCMDBG */
181 /* Find basic rate for a given rate */
182 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
183 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
184 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
186 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
188 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
190 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
192 #define SCAN_IN_PROGRESS(x) 0
194 #define EPI_VERSION_NUM 0x054b0b00
196 #ifdef BCMDBG
197 /* pointer to most recently allocated wl/wlc */
198 static struct brcms_c_info *wlc_info_dbg = (struct brcms_c_info *) (NULL);
199 #endif
201 const u8 prio2fifo[NUMPRIO] = {
202 TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */
203 TX_AC_BK_FIFO, /* 1 BK AC_BK Background */
204 TX_AC_BK_FIFO, /* 2 -- AC_BK Background */
205 TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */
206 TX_AC_VI_FIFO, /* 4 CL AC_VI Video */
207 TX_AC_VI_FIFO, /* 5 VI AC_VI Video */
208 TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */
209 TX_AC_VO_FIFO /* 7 NC AC_VO Voice */
212 /* precedences numbers for wlc queues. These are twice as may levels as
213 * 802.1D priorities.
214 * Odd numbers are used for HI priority traffic at same precedence levels
215 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
217 #define _WLC_PREC_NONE 0 /* None = - */
218 #define _WLC_PREC_BK 2 /* BK - Background */
219 #define _WLC_PREC_BE 4 /* BE - Best-effort */
220 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
221 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
222 #define _WLC_PREC_VI 10 /* Vi - Video */
223 #define _WLC_PREC_VO 12 /* Vo - Voice */
224 #define _WLC_PREC_NC 14 /* NC - Network Control */
226 #define MAXMACLIST 64 /* max # source MAC matches */
227 #define BCN_TEMPLATE_COUNT 2
229 #define WLC_BSSCFG_HW_BCN 0x20 /* The BSS is generating beacons in HW */
231 #define HWBCN_ENAB(cfg) (((cfg)->flags & WLC_BSSCFG_HW_BCN) != 0)
232 #define HWPRB_ENAB(cfg) (((cfg)->flags & WLC_BSSCFG_HW_PRB) != 0)
234 #define MBSS_BCN_ENAB(cfg) 0
235 #define MBSS_PRB_ENAB(cfg) 0
236 #define SOFTBCN_ENAB(pub) (0)
238 /* 802.1D Priority to precedence queue mapping */
239 const u8 wlc_prio2prec_map[] = {
240 _WLC_PREC_BE, /* 0 BE - Best-effort */
241 _WLC_PREC_BK, /* 1 BK - Background */
242 _WLC_PREC_NONE, /* 2 None = - */
243 _WLC_PREC_EE, /* 3 EE - Excellent-effort */
244 _WLC_PREC_CL, /* 4 CL - Controlled Load */
245 _WLC_PREC_VI, /* 5 Vi - Video */
246 _WLC_PREC_VO, /* 6 Vo - Voice */
247 _WLC_PREC_NC, /* 7 NC - Network Control */
250 /* Check if a particular BSS config is AP or STA */
251 #define BSSCFG_AP(cfg) (0)
252 #define BSSCFG_STA(cfg) (1)
253 #define BSSCFG_IBSS(cfg) (!(cfg)->BSS)
255 /* As above for all non-NULL BSS configs */
256 #define FOREACH_BSS(wlc, idx, cfg) \
257 for (idx = 0; (int) idx < WLC_MAXBSSCFG; idx++) \
258 if ((cfg = (wlc)->bsscfg[idx]))
260 /* Sanity check for tx_prec_map and fifo synchup
261 * Either there are some packets pending for the fifo, else if fifo is empty then
262 * all the corresponding precmap bits should be set
264 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
265 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
266 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
267 (wlc)->fifo2prec_map[(fifo)]))
269 /* TX FIFO number to WME/802.1E Access Category */
270 const u8 wme_fifo2ac[] = { AC_BK, AC_BE, AC_VI, AC_VO, AC_BE, AC_BE };
272 /* WME/802.1E Access Category to TX FIFO number */
273 static const u8 wme_ac2fifo[] = { 1, 0, 2, 3 };
275 static bool in_send_q;
277 /* Shared memory location index for various AC params */
278 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
280 #ifdef BCMDBG
281 static const char * const fifo_names[] = {
282 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
283 #else
284 static const char fifo_names[6][0];
285 #endif
287 static const u8 acbitmap2maxprio[] = {
288 PRIO_8021D_BE, PRIO_8021D_BE, PRIO_8021D_BK, PRIO_8021D_BK,
289 PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI,
290 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO,
291 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO
294 /* currently the best mechanism for determining SIFS is the band in use */
295 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
297 /* value for # replay counters currently supported */
298 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
300 /* local prototypes */
301 static u16 brcms_c_d11hdrs_mac80211(struct brcms_c_info *wlc,
302 struct ieee80211_hw *hw,
303 struct sk_buff *p,
304 struct scb *scb, uint frag,
305 uint nfrags, uint queue,
306 uint next_frag_len,
307 struct wsec_key *key,
308 ratespec_t rspec_override);
309 static void brcms_c_bss_default_init(struct brcms_c_info *wlc);
310 static void brcms_c_ucode_mac_upd(struct brcms_c_info *wlc);
311 static ratespec_t mac80211_wlc_set_nrate(struct brcms_c_info *wlc,
312 struct brcms_band *cur_band,
313 u32 int_val);
314 static void brcms_c_tx_prec_map_init(struct brcms_c_info *wlc);
315 static void brcms_c_watchdog(void *arg);
316 static void brcms_c_watchdog_by_timer(void *arg);
317 static u16 brcms_c_rate_shm_offset(struct brcms_c_info *wlc, u8 rate);
318 static int brcms_c_set_rateset(struct brcms_c_info *wlc, wlc_rateset_t *rs_arg);
319 static u8 brcms_c_local_constraint_qdbm(struct brcms_c_info *wlc);
321 /* send and receive */
322 static struct brcms_txq_info *brcms_c_txq_alloc(struct brcms_c_info *wlc);
323 static void brcms_c_txq_free(struct brcms_c_info *wlc,
324 struct brcms_txq_info *qi);
325 static void brcms_c_txflowcontrol_signal(struct brcms_c_info *wlc,
326 struct brcms_txq_info *qi,
327 bool on, int prio);
328 static void brcms_c_txflowcontrol_reset(struct brcms_c_info *wlc);
329 static void brcms_c_compute_cck_plcp(struct brcms_c_info *wlc, ratespec_t rate,
330 uint length, u8 *plcp);
331 static void brcms_c_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp);
332 static void brcms_c_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp);
333 static u16 brcms_c_compute_frame_dur(struct brcms_c_info *wlc, ratespec_t rate,
334 u8 preamble_type, uint next_frag_len);
335 static u64 brcms_c_recover_tsf64(struct brcms_c_info *wlc,
336 struct brcms_d11rxhdr *rxh);
337 static void brcms_c_recvctl(struct brcms_c_info *wlc,
338 struct d11rxhdr *rxh, struct sk_buff *p);
339 static uint brcms_c_calc_frame_len(struct brcms_c_info *wlc, ratespec_t rate,
340 u8 preamble_type, uint dur);
341 static uint brcms_c_calc_ack_time(struct brcms_c_info *wlc, ratespec_t rate,
342 u8 preamble_type);
343 static uint brcms_c_calc_cts_time(struct brcms_c_info *wlc, ratespec_t rate,
344 u8 preamble_type);
345 /* interrupt, up/down, band */
346 static void brcms_c_setband(struct brcms_c_info *wlc, uint bandunit);
347 static chanspec_t brcms_c_init_chanspec(struct brcms_c_info *wlc);
348 static void brcms_c_bandinit_ordered(struct brcms_c_info *wlc,
349 chanspec_t chanspec);
350 static void brcms_c_bsinit(struct brcms_c_info *wlc);
351 static int brcms_c_duty_cycle_set(struct brcms_c_info *wlc, int duty_cycle,
352 bool isOFDM, bool writeToShm);
353 static void brcms_c_radio_hwdisable_upd(struct brcms_c_info *wlc);
354 static bool brcms_c_radio_monitor_start(struct brcms_c_info *wlc);
355 static void brcms_c_radio_timer(void *arg);
356 static void brcms_c_radio_enable(struct brcms_c_info *wlc);
357 static void brcms_c_radio_upd(struct brcms_c_info *wlc);
359 /* scan, association, BSS */
360 static uint brcms_c_calc_ba_time(struct brcms_c_info *wlc, ratespec_t rate,
361 u8 preamble_type);
362 static void brcms_c_update_mimo_band_bwcap(struct brcms_c_info *wlc, u8 bwcap);
363 static void brcms_c_ht_update_sgi_rx(struct brcms_c_info *wlc, int val);
364 static void brcms_c_ht_update_ldpc(struct brcms_c_info *wlc, s8 val);
365 static void brcms_c_war16165(struct brcms_c_info *wlc, bool tx);
367 static void brcms_c_wme_retries_write(struct brcms_c_info *wlc);
368 static bool brcms_c_attach_stf_ant_init(struct brcms_c_info *wlc);
369 static uint brcms_c_attach_module(struct brcms_c_info *wlc);
370 static void brcms_c_detach_module(struct brcms_c_info *wlc);
371 static void brcms_c_timers_deinit(struct brcms_c_info *wlc);
372 static void brcms_c_down_led_upd(struct brcms_c_info *wlc);
373 static uint brcms_c_down_del_timer(struct brcms_c_info *wlc);
374 static void brcms_c_ofdm_rateset_war(struct brcms_c_info *wlc);
375 static int _brcms_c_ioctl(struct brcms_c_info *wlc, int cmd, void *arg, int len,
376 struct brcms_c_if *wlcif);
378 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
380 bool brcms_c_ps_allowed(struct brcms_c_info *wlc)
382 int idx;
383 struct brcms_bss_cfg *cfg;
385 /* disallow PS when one of the following global conditions meets */
386 if (!wlc->pub->associated)
387 return false;
389 /* disallow PS when one of these meets when not scanning */
390 if (AP_ACTIVE(wlc) || wlc->monitor)
391 return false;
393 for (idx = 0; idx < WLC_MAXBSSCFG; idx++) {
394 cfg = wlc->bsscfg[idx];
395 if (cfg && BSSCFG_STA(cfg) && cfg->associated) {
397 * disallow PS when one of the following
398 * bsscfg specific conditions meets
400 if (!cfg->BSS || !WLC_PORTOPEN(cfg))
401 return false;
403 if (!cfg->dtim_programmed)
404 return false;
408 return true;
411 void brcms_c_reset(struct brcms_c_info *wlc)
413 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
415 /* slurp up hw mac counters before core reset */
416 brcms_c_statsupd(wlc);
418 /* reset our snapshot of macstat counters */
419 memset((char *)wlc->core->macstat_snapshot, 0,
420 sizeof(struct macstat));
422 brcms_b_reset(wlc->hw);
425 void brcms_c_fatal_error(struct brcms_c_info *wlc)
427 wiphy_err(wlc->wiphy, "wl%d: fatal error, reinitializing\n",
428 wlc->pub->unit);
429 brcms_init(wlc->wl);
432 /* Return the channel the driver should initialize during brcms_c_init.
433 * the channel may have to be changed from the currently configured channel
434 * if other configurations are in conflict (bandlocked, 11n mode disabled,
435 * invalid channel for current country, etc.)
437 static chanspec_t brcms_c_init_chanspec(struct brcms_c_info *wlc)
439 chanspec_t chanspec =
440 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE |
441 WL_CHANSPEC_BAND_2G;
443 return chanspec;
446 struct scb global_scb;
448 static void brcms_c_init_scb(struct brcms_c_info *wlc, struct scb *scb)
450 int i;
451 scb->flags = SCB_WMECAP | SCB_HTCAP;
452 for (i = 0; i < NUMPRIO; i++)
453 scb->seqnum[i] = 0;
456 void brcms_c_init(struct brcms_c_info *wlc)
458 d11regs_t *regs;
459 chanspec_t chanspec;
460 int i;
461 struct brcms_bss_cfg *bsscfg;
462 bool mute = false;
464 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
466 regs = wlc->regs;
468 /* This will happen if a big-hammer was executed. In that case, we want to go back
469 * to the channel that we were on and not new channel
471 if (wlc->pub->associated)
472 chanspec = wlc->home_chanspec;
473 else
474 chanspec = brcms_c_init_chanspec(wlc);
476 brcms_b_init(wlc->hw, chanspec, mute);
478 /* update beacon listen interval */
479 brcms_c_bcn_li_upd(wlc);
481 /* the world is new again, so is our reported rate */
482 brcms_c_reprate_init(wlc);
484 /* write ethernet address to core */
485 FOREACH_BSS(wlc, i, bsscfg) {
486 brcms_c_set_mac(bsscfg);
487 brcms_c_set_bssid(bsscfg);
490 /* Update tsf_cfprep if associated and up */
491 if (wlc->pub->associated) {
492 FOREACH_BSS(wlc, i, bsscfg) {
493 if (bsscfg->up) {
494 u32 bi;
496 /* get beacon period and convert to uS */
497 bi = bsscfg->current_bss->beacon_period << 10;
499 * update since init path would reset
500 * to default value
502 W_REG(&regs->tsf_cfprep,
503 (bi << CFPREP_CBI_SHIFT));
505 /* Update maccontrol PM related bits */
506 brcms_c_set_ps_ctrl(wlc);
508 break;
513 brcms_c_bandinit_ordered(wlc, chanspec);
515 brcms_c_init_scb(wlc, &global_scb);
517 /* init probe response timeout */
518 brcms_c_write_shm(wlc, M_PRS_MAXTIME, wlc->prb_resp_timeout);
520 /* init max burst txop (framebursting) */
521 brcms_c_write_shm(wlc, M_MBURST_TXOP,
522 (wlc->
523 _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP));
525 /* initialize maximum allowed duty cycle */
526 brcms_c_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true);
527 brcms_c_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true);
529 /* Update some shared memory locations related to max AMPDU size allowed to received */
530 brcms_c_ampdu_shm_upd(wlc->ampdu);
532 /* band-specific inits */
533 brcms_c_bsinit(wlc);
535 /* Enable EDCF mode (while the MAC is suspended) */
536 if (EDCF_ENAB(wlc->pub)) {
537 OR_REG(&regs->ifs_ctl, IFS_USEEDCF);
538 brcms_c_edcf_setparams(wlc, false);
541 /* Init precedence maps for empty FIFOs */
542 brcms_c_tx_prec_map_init(wlc);
544 /* read the ucode version if we have not yet done so */
545 if (wlc->ucode_rev == 0) {
546 wlc->ucode_rev =
547 brcms_c_read_shm(wlc, M_BOM_REV_MAJOR) << NBITS(u16);
548 wlc->ucode_rev |= brcms_c_read_shm(wlc, M_BOM_REV_MINOR);
551 /* ..now really unleash hell (allow the MAC out of suspend) */
552 brcms_c_enable_mac(wlc);
554 /* clear tx flow control */
555 brcms_c_txflowcontrol_reset(wlc);
557 /* clear tx data fifo suspends */
558 wlc->tx_suspended = false;
560 /* enable the RF Disable Delay timer */
561 W_REG(&wlc->regs->rfdisabledly, RFDISABLE_DEFAULT);
563 /* initialize mpc delay */
564 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
567 * Initialize WME parameters; if they haven't been set by some other
568 * mechanism (IOVar, etc) then read them from the hardware.
570 if (WLC_WME_RETRY_SHORT_GET(wlc, 0) == 0) { /* Uninitialized; read from HW */
571 int ac;
573 for (ac = 0; ac < AC_COUNT; ac++) {
574 wlc->wme_retries[ac] =
575 brcms_c_read_shm(wlc, M_AC_TXLMT_ADDR(ac));
580 void brcms_c_mac_bcn_promisc_change(struct brcms_c_info *wlc, bool promisc)
582 wlc->bcnmisc_monitor = promisc;
583 brcms_c_mac_bcn_promisc(wlc);
586 void brcms_c_mac_bcn_promisc(struct brcms_c_info *wlc)
588 if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) ||
589 wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor)
590 brcms_c_mctrl(wlc, MCTL_BCNS_PROMISC, MCTL_BCNS_PROMISC);
591 else
592 brcms_c_mctrl(wlc, MCTL_BCNS_PROMISC, 0);
595 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
596 void brcms_c_mac_promisc(struct brcms_c_info *wlc)
598 u32 promisc_bits = 0;
600 /* promiscuous mode just sets MCTL_PROMISC
601 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
602 * since all BSS data traffic is directed at the AP
604 if (PROMISC_ENAB(wlc->pub) && !AP_ENAB(wlc->pub))
605 promisc_bits |= MCTL_PROMISC;
607 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
608 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
609 * handled in brcms_c_mac_bcn_promisc()
611 if (MONITOR_ENAB(wlc))
612 promisc_bits |= MCTL_PROMISC | MCTL_KEEPCONTROL;
614 brcms_c_mctrl(wlc, MCTL_PROMISC | MCTL_KEEPCONTROL, promisc_bits);
617 /* push sw hps and wake state through hardware */
618 void brcms_c_set_ps_ctrl(struct brcms_c_info *wlc)
620 u32 v1, v2;
621 bool hps;
622 bool awake_before;
624 hps = PS_ALLOWED(wlc);
626 BCMMSG(wlc->wiphy, "wl%d: hps %d\n", wlc->pub->unit, hps);
628 v1 = R_REG(&wlc->regs->maccontrol);
629 v2 = MCTL_WAKE;
630 if (hps)
631 v2 |= MCTL_HPS;
633 brcms_c_mctrl(wlc, MCTL_WAKE | MCTL_HPS, v2);
635 awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0));
637 if (!awake_before)
638 brcms_b_wait_for_wake(wlc->hw);
643 * Write this BSS config's MAC address to core.
644 * Updates RXE match engine.
646 int brcms_c_set_mac(struct brcms_bss_cfg *cfg)
648 int err = 0;
649 struct brcms_c_info *wlc = cfg->wlc;
651 if (cfg == wlc->cfg) {
652 /* enter the MAC addr into the RXE match registers */
653 brcms_c_set_addrmatch(wlc, RCM_MAC_OFFSET, cfg->cur_etheraddr);
656 brcms_c_ampdu_macaddr_upd(wlc);
658 return err;
661 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
662 * Updates RXE match engine.
664 void brcms_c_set_bssid(struct brcms_bss_cfg *cfg)
666 struct brcms_c_info *wlc = cfg->wlc;
668 /* if primary config, we need to update BSSID in RXE match registers */
669 if (cfg == wlc->cfg) {
670 brcms_c_set_addrmatch(wlc, RCM_BSSID_OFFSET, cfg->BSSID);
672 #ifdef SUPPORT_HWKEYS
673 else if (BSSCFG_STA(cfg) && cfg->BSS) {
674 brcms_c_rcmta_add_bssid(wlc, cfg);
676 #endif
680 * Suspend the the MAC and update the slot timing
681 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
683 void brcms_c_switch_shortslot(struct brcms_c_info *wlc, bool shortslot)
685 int idx;
686 struct brcms_bss_cfg *cfg;
688 /* use the override if it is set */
689 if (wlc->shortslot_override != WLC_SHORTSLOT_AUTO)
690 shortslot = (wlc->shortslot_override == WLC_SHORTSLOT_ON);
692 if (wlc->shortslot == shortslot)
693 return;
695 wlc->shortslot = shortslot;
697 /* update the capability based on current shortslot mode */
698 FOREACH_BSS(wlc, idx, cfg) {
699 if (!cfg->associated)
700 continue;
701 cfg->current_bss->capability &=
702 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
703 if (wlc->shortslot)
704 cfg->current_bss->capability |=
705 WLAN_CAPABILITY_SHORT_SLOT_TIME;
708 brcms_b_set_shortslot(wlc->hw, shortslot);
711 static u8 brcms_c_local_constraint_qdbm(struct brcms_c_info *wlc)
713 u8 local;
714 s16 local_max;
716 local = WLC_TXPWR_MAX;
717 if (wlc->pub->associated &&
718 (brcmu_chspec_ctlchan(wlc->chanspec) ==
719 brcmu_chspec_ctlchan(wlc->home_chanspec))) {
721 /* get the local power constraint if we are on the AP's
722 * channel [802.11h, 7.3.2.13]
724 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
725 local_max =
726 (wlc->txpwr_local_max -
727 wlc->txpwr_local_constraint) * WLC_TXPWR_DB_FACTOR;
728 if (local_max > 0 && local_max < WLC_TXPWR_MAX)
729 return (u8) local_max;
730 if (local_max < 0)
731 return 0;
734 return local;
737 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
738 void brcms_c_set_home_chanspec(struct brcms_c_info *wlc, chanspec_t chanspec)
740 if (wlc->home_chanspec != chanspec) {
741 int idx;
742 struct brcms_bss_cfg *cfg;
744 wlc->home_chanspec = chanspec;
746 FOREACH_BSS(wlc, idx, cfg) {
747 if (!cfg->associated)
748 continue;
750 cfg->current_bss->chanspec = chanspec;
756 static void brcms_c_set_phy_chanspec(struct brcms_c_info *wlc,
757 chanspec_t chanspec)
759 /* Save our copy of the chanspec */
760 wlc->chanspec = chanspec;
762 /* Set the chanspec and power limits for this locale after computing
763 * any 11h local tx power constraints.
765 brcms_c_channel_set_chanspec(wlc->cmi, chanspec,
766 brcms_c_local_constraint_qdbm(wlc));
768 if (wlc->stf->ss_algosel_auto)
769 brcms_c_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel,
770 chanspec);
772 brcms_c_stf_ss_update(wlc, wlc->band);
776 void brcms_c_set_chanspec(struct brcms_c_info *wlc, chanspec_t chanspec)
778 uint bandunit;
779 bool switchband = false;
780 chanspec_t old_chanspec = wlc->chanspec;
782 if (!brcms_c_valid_chanspec_db(wlc->cmi, chanspec)) {
783 wiphy_err(wlc->wiphy, "wl%d: %s: Bad channel %d\n",
784 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec));
785 return;
788 /* Switch bands if necessary */
789 if (NBANDS(wlc) > 1) {
790 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
791 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) {
792 switchband = true;
793 if (wlc->bandlocked) {
794 wiphy_err(wlc->wiphy, "wl%d: %s: chspec %d "
795 "band is locked!\n",
796 wlc->pub->unit, __func__,
797 CHSPEC_CHANNEL(chanspec));
798 return;
801 * should the setband call come after the
802 * brcms_b_chanspec() ? if the setband updates
803 * (brcms_c_bsinit) use low level calls to inspect and
804 * set state, the state inspected may be from the wrong
805 * band, or the following brcms_b_set_chanspec() may
806 * undo the work.
808 brcms_c_setband(wlc, bandunit);
812 /* sync up phy/radio chanspec */
813 brcms_c_set_phy_chanspec(wlc, chanspec);
815 /* init antenna selection */
816 if (CHSPEC_WLC_BW(old_chanspec) != CHSPEC_WLC_BW(chanspec)) {
817 brcms_c_antsel_init(wlc->asi);
819 /* Fix the hardware rateset based on bw.
820 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
822 brcms_c_rateset_bw_mcs_filter(&wlc->band->hw_rateset,
823 wlc->band->
824 mimo_cap_40 ? CHSPEC_WLC_BW(chanspec)
825 : 0);
828 /* update some mac configuration since chanspec changed */
829 brcms_c_ucode_mac_upd(wlc);
832 ratespec_t brcms_c_lowest_basic_rspec(struct brcms_c_info *wlc,
833 wlc_rateset_t *rs)
835 ratespec_t lowest_basic_rspec;
836 uint i;
838 /* Use the lowest basic rate */
839 lowest_basic_rspec = rs->rates[0] & WLC_RATE_MASK;
840 for (i = 0; i < rs->count; i++) {
841 if (rs->rates[i] & WLC_RATE_FLAG) {
842 lowest_basic_rspec = rs->rates[i] & WLC_RATE_MASK;
843 break;
846 #if NCONF
847 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
848 if (IS_OFDM(lowest_basic_rspec)) {
849 lowest_basic_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
851 #endif
853 return lowest_basic_rspec;
856 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
857 * setting as per this table:
858 * ratespec CCK ant = wlc->stf->txant
859 * OFDM ant = 3
861 void brcms_c_beacon_phytxctl_txant_upd(struct brcms_c_info *wlc,
862 ratespec_t bcn_rspec)
864 u16 phyctl;
865 u16 phytxant = wlc->stf->phytxant;
866 u16 mask = PHY_TXC_ANT_MASK;
868 /* for non-siso rates or default setting, use the available chains */
869 if (WLC_PHY_11N_CAP(wlc->band)) {
870 phytxant = brcms_c_stf_phytxchain_sel(wlc, bcn_rspec);
873 phyctl = brcms_c_read_shm(wlc, M_BCN_PCTLWD);
874 phyctl = (phyctl & ~mask) | phytxant;
875 brcms_c_write_shm(wlc, M_BCN_PCTLWD, phyctl);
878 /* centralized protection config change function to simplify debugging, no consistency checking
879 * this should be called only on changes to avoid overhead in periodic function
881 void brcms_c_protection_upd(struct brcms_c_info *wlc, uint idx, int val)
883 BCMMSG(wlc->wiphy, "idx %d, val %d\n", idx, val);
885 switch (idx) {
886 case WLC_PROT_G_SPEC:
887 wlc->protection->_g = (bool) val;
888 break;
889 case WLC_PROT_G_OVR:
890 wlc->protection->g_override = (s8) val;
891 break;
892 case WLC_PROT_G_USER:
893 wlc->protection->gmode_user = (u8) val;
894 break;
895 case WLC_PROT_OVERLAP:
896 wlc->protection->overlap = (s8) val;
897 break;
898 case WLC_PROT_N_USER:
899 wlc->protection->nmode_user = (s8) val;
900 break;
901 case WLC_PROT_N_CFG:
902 wlc->protection->n_cfg = (s8) val;
903 break;
904 case WLC_PROT_N_CFG_OVR:
905 wlc->protection->n_cfg_override = (s8) val;
906 break;
907 case WLC_PROT_N_NONGF:
908 wlc->protection->nongf = (bool) val;
909 break;
910 case WLC_PROT_N_NONGF_OVR:
911 wlc->protection->nongf_override = (s8) val;
912 break;
913 case WLC_PROT_N_PAM_OVR:
914 wlc->protection->n_pam_override = (s8) val;
915 break;
916 case WLC_PROT_N_OBSS:
917 wlc->protection->n_obss = (bool) val;
918 break;
920 default:
921 break;
926 static void brcms_c_ht_update_sgi_rx(struct brcms_c_info *wlc, int val)
928 wlc->ht_cap.cap_info &= ~(IEEE80211_HT_CAP_SGI_20 |
929 IEEE80211_HT_CAP_SGI_40);
930 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_20) ?
931 IEEE80211_HT_CAP_SGI_20 : 0;
932 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_40) ?
933 IEEE80211_HT_CAP_SGI_40 : 0;
935 if (wlc->pub->up) {
936 brcms_c_update_beacon(wlc);
937 brcms_c_update_probe_resp(wlc, true);
941 static void brcms_c_ht_update_ldpc(struct brcms_c_info *wlc, s8 val)
943 wlc->stf->ldpc = val;
945 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_LDPC_CODING;
946 if (wlc->stf->ldpc != OFF)
947 wlc->ht_cap.cap_info |= IEEE80211_HT_CAP_LDPC_CODING;
949 if (wlc->pub->up) {
950 brcms_c_update_beacon(wlc);
951 brcms_c_update_probe_resp(wlc, true);
952 wlc_phy_ldpc_override_set(wlc->band->pi, (val ? true : false));
957 * ucode, hwmac update
958 * Channel dependent updates for ucode and hw
960 static void brcms_c_ucode_mac_upd(struct brcms_c_info *wlc)
962 /* enable or disable any active IBSSs depending on whether or not
963 * we are on the home channel
965 if (wlc->home_chanspec == WLC_BAND_PI_RADIO_CHANSPEC) {
966 if (wlc->pub->associated) {
967 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
968 * I think that the ucode inits set up the bcn templates and shm values
969 * with a bogus beacon. This should not be done in the inits. If ucode needs
970 * to set up a beacon for testing, the test routines should write it down,
971 * not expect the inits to populate a bogus beacon.
973 if (WLC_PHY_11N_CAP(wlc->band)) {
974 brcms_c_write_shm(wlc, M_BCN_TXTSF_OFFSET,
975 wlc->band->bcntsfoff);
978 } else {
979 /* disable an active IBSS if we are not on the home channel */
982 /* update the various promisc bits */
983 brcms_c_mac_bcn_promisc(wlc);
984 brcms_c_mac_promisc(wlc);
987 static void brcms_c_bandinit_ordered(struct brcms_c_info *wlc,
988 chanspec_t chanspec)
990 wlc_rateset_t default_rateset;
991 uint parkband;
992 uint i, band_order[2];
994 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
996 * We might have been bandlocked during down and the chip power-cycled (hibernate).
997 * figure out the right band to park on
999 if (wlc->bandlocked || NBANDS(wlc) == 1) {
1000 /* updated in brcms_c_bandlock() */
1001 parkband = wlc->band->bandunit;
1002 band_order[0] = band_order[1] = parkband;
1003 } else {
1004 /* park on the band of the specified chanspec */
1005 parkband = CHSPEC_WLCBANDUNIT(chanspec);
1007 /* order so that parkband initialize last */
1008 band_order[0] = parkband ^ 1;
1009 band_order[1] = parkband;
1012 /* make each band operational, software state init */
1013 for (i = 0; i < NBANDS(wlc); i++) {
1014 uint j = band_order[i];
1016 wlc->band = wlc->bandstate[j];
1018 brcms_default_rateset(wlc, &default_rateset);
1020 /* fill in hw_rate */
1021 brcms_c_rateset_filter(&default_rateset, &wlc->band->hw_rateset,
1022 false, WLC_RATES_CCK_OFDM, WLC_RATE_MASK,
1023 (bool) N_ENAB(wlc->pub));
1025 /* init basic rate lookup */
1026 brcms_c_rate_lookup_init(wlc, &default_rateset);
1029 /* sync up phy/radio chanspec */
1030 brcms_c_set_phy_chanspec(wlc, chanspec);
1033 /* band-specific init */
1034 static void WLBANDINITFN(brcms_c_bsinit) (struct brcms_c_info *wlc)
1036 BCMMSG(wlc->wiphy, "wl%d: bandunit %d\n",
1037 wlc->pub->unit, wlc->band->bandunit);
1039 /* write ucode ACK/CTS rate table */
1040 brcms_c_set_ratetable(wlc);
1042 /* update some band specific mac configuration */
1043 brcms_c_ucode_mac_upd(wlc);
1045 /* init antenna selection */
1046 brcms_c_antsel_init(wlc->asi);
1050 /* switch to and initialize new band */
1051 static void WLBANDINITFN(brcms_c_setband) (struct brcms_c_info *wlc,
1052 uint bandunit)
1054 int idx;
1055 struct brcms_bss_cfg *cfg;
1057 wlc->band = wlc->bandstate[bandunit];
1059 if (!wlc->pub->up)
1060 return;
1062 /* wait for at least one beacon before entering sleeping state */
1063 for (idx = 0; idx < WLC_MAXBSSCFG; idx++) {
1064 cfg = wlc->bsscfg[idx];
1065 if (cfg && BSSCFG_STA(cfg) && cfg->associated)
1066 cfg->PMawakebcn = true;
1068 brcms_c_set_ps_ctrl(wlc);
1070 /* band-specific initializations */
1071 brcms_c_bsinit(wlc);
1074 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1075 void
1076 brcms_c_wme_initparams_sta(struct brcms_c_info *wlc, struct wme_param_ie *pe)
1078 static const struct wme_param_ie stadef = {
1079 WME_OUI,
1080 WME_TYPE,
1081 WME_SUBTYPE_PARAM_IE,
1082 WME_VER,
1086 {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA,
1087 cpu_to_le16(EDCF_AC_BE_TXOP_STA)},
1088 {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA,
1089 cpu_to_le16(EDCF_AC_BK_TXOP_STA)},
1090 {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA,
1091 cpu_to_le16(EDCF_AC_VI_TXOP_STA)},
1092 {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA,
1093 cpu_to_le16(EDCF_AC_VO_TXOP_STA)}
1096 memcpy(pe, &stadef, sizeof(*pe));
1099 void brcms_c_wme_setparams(struct brcms_c_info *wlc, u16 aci,
1100 const struct ieee80211_tx_queue_params *params,
1101 bool suspend)
1103 int i;
1104 struct shm_acparams acp_shm;
1105 u16 *shm_entry;
1107 /* Only apply params if the core is out of reset and has clocks */
1108 if (!wlc->clk) {
1109 wiphy_err(wlc->wiphy, "wl%d: %s : no-clock\n", wlc->pub->unit,
1110 __func__);
1111 return;
1114 do {
1115 memset((char *)&acp_shm, 0, sizeof(struct shm_acparams));
1116 /* fill in shm ac params struct */
1117 acp_shm.txop = le16_to_cpu(params->txop);
1118 /* convert from units of 32us to us for ucode */
1119 wlc->edcf_txop[aci & 0x3] = acp_shm.txop =
1120 EDCF_TXOP2USEC(acp_shm.txop);
1121 acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK);
1123 if (aci == AC_VI && acp_shm.txop == 0
1124 && acp_shm.aifs < EDCF_AIFSN_MAX)
1125 acp_shm.aifs++;
1127 if (acp_shm.aifs < EDCF_AIFSN_MIN
1128 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1129 wiphy_err(wlc->wiphy, "wl%d: edcf_setparams: bad "
1130 "aifs %d\n", wlc->pub->unit, acp_shm.aifs);
1131 continue;
1134 acp_shm.cwmin = params->cw_min;
1135 acp_shm.cwmax = params->cw_max;
1136 acp_shm.cwcur = acp_shm.cwmin;
1137 acp_shm.bslots =
1138 R_REG(&wlc->regs->tsf_random) & acp_shm.cwcur;
1139 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1140 /* Indicate the new params to the ucode */
1141 acp_shm.status = brcms_c_read_shm(wlc, (M_EDCF_QINFO +
1142 wme_shmemacindex(aci) *
1143 M_EDCF_QLEN +
1144 M_EDCF_STATUS_OFF));
1145 acp_shm.status |= WME_STATUS_NEWAC;
1147 /* Fill in shm acparam table */
1148 shm_entry = (u16 *) &acp_shm;
1149 for (i = 0; i < (int)sizeof(struct shm_acparams); i += 2)
1150 brcms_c_write_shm(wlc,
1151 M_EDCF_QINFO +
1152 wme_shmemacindex(aci) * M_EDCF_QLEN + i,
1153 *shm_entry++);
1155 } while (0);
1157 if (suspend)
1158 brcms_c_suspend_mac_and_wait(wlc);
1160 if (suspend)
1161 brcms_c_enable_mac(wlc);
1165 void brcms_c_edcf_setparams(struct brcms_c_info *wlc, bool suspend)
1167 u16 aci;
1168 int i_ac;
1169 struct edcf_acparam *edcf_acp;
1171 struct ieee80211_tx_queue_params txq_pars;
1172 struct ieee80211_tx_queue_params *params = &txq_pars;
1175 * AP uses AC params from wme_param_ie_ap.
1176 * AP advertises AC params from wme_param_ie.
1177 * STA uses AC params from wme_param_ie.
1180 edcf_acp = (struct edcf_acparam *) &wlc->wme_param_ie.acparam[0];
1182 for (i_ac = 0; i_ac < AC_COUNT; i_ac++, edcf_acp++) {
1183 /* find out which ac this set of params applies to */
1184 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
1186 /* fill in shm ac params struct */
1187 params->txop = edcf_acp->TXOP;
1188 params->aifs = edcf_acp->ACI;
1190 /* CWmin = 2^(ECWmin) - 1 */
1191 params->cw_min = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK);
1192 /* CWmax = 2^(ECWmax) - 1 */
1193 params->cw_max = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK)
1194 >> EDCF_ECWMAX_SHIFT);
1195 brcms_c_wme_setparams(wlc, aci, params, suspend);
1198 if (suspend)
1199 brcms_c_suspend_mac_and_wait(wlc);
1201 if (AP_ENAB(wlc->pub) && WME_ENAB(wlc->pub)) {
1202 brcms_c_update_beacon(wlc);
1203 brcms_c_update_probe_resp(wlc, false);
1206 if (suspend)
1207 brcms_c_enable_mac(wlc);
1211 bool brcms_c_timers_init(struct brcms_c_info *wlc, int unit)
1213 wlc->wdtimer = brcms_init_timer(wlc->wl, brcms_c_watchdog_by_timer,
1214 wlc, "watchdog");
1215 if (!wlc->wdtimer) {
1216 wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for wdtimer "
1217 "failed\n", unit);
1218 goto fail;
1221 wlc->radio_timer = brcms_init_timer(wlc->wl, brcms_c_radio_timer,
1222 wlc, "radio");
1223 if (!wlc->radio_timer) {
1224 wiphy_err(wlc->wiphy, "wl%d: wl_init_timer for radio_timer "
1225 "failed\n", unit);
1226 goto fail;
1229 return true;
1231 fail:
1232 return false;
1236 * Initialize brcms_c_info default values ...
1237 * may get overrides later in this function
1239 void brcms_c_info_init(struct brcms_c_info *wlc, int unit)
1241 int i;
1242 /* Assume the device is there until proven otherwise */
1243 wlc->device_present = true;
1245 /* Save our copy of the chanspec */
1246 wlc->chanspec = CH20MHZ_CHSPEC(1);
1248 /* various 802.11g modes */
1249 wlc->shortslot = false;
1250 wlc->shortslot_override = WLC_SHORTSLOT_AUTO;
1252 brcms_c_protection_upd(wlc, WLC_PROT_G_OVR, WLC_PROTECTION_AUTO);
1253 brcms_c_protection_upd(wlc, WLC_PROT_G_SPEC, false);
1255 brcms_c_protection_upd(wlc, WLC_PROT_N_CFG_OVR, WLC_PROTECTION_AUTO);
1256 brcms_c_protection_upd(wlc, WLC_PROT_N_CFG, WLC_N_PROTECTION_OFF);
1257 brcms_c_protection_upd(wlc, WLC_PROT_N_NONGF_OVR, WLC_PROTECTION_AUTO);
1258 brcms_c_protection_upd(wlc, WLC_PROT_N_NONGF, false);
1259 brcms_c_protection_upd(wlc, WLC_PROT_N_PAM_OVR, AUTO);
1261 brcms_c_protection_upd(wlc, WLC_PROT_OVERLAP,
1262 WLC_PROTECTION_CTL_OVERLAP);
1264 /* 802.11g draft 4.0 NonERP elt advertisement */
1265 wlc->include_legacy_erp = true;
1267 wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF;
1268 wlc->stf->txant = ANT_TX_DEF;
1270 wlc->prb_resp_timeout = WLC_PRB_RESP_TIMEOUT;
1272 wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN;
1273 for (i = 0; i < NFIFO; i++)
1274 wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN;
1275 wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN;
1277 /* default rate fallback retry limits */
1278 wlc->SFBL = RETRY_SHORT_FB;
1279 wlc->LFBL = RETRY_LONG_FB;
1281 /* default mac retry limits */
1282 wlc->SRL = RETRY_SHORT_DEF;
1283 wlc->LRL = RETRY_LONG_DEF;
1285 /* Set flag to indicate that hw keys should be used when available. */
1286 wlc->wsec_swkeys = false;
1288 /* init the 4 static WEP default keys */
1289 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
1290 wlc->wsec_keys[i] = wlc->wsec_def_keys[i];
1291 wlc->wsec_keys[i]->idx = (u8) i;
1294 /* WME QoS mode is Auto by default */
1295 wlc->pub->_wme = AUTO;
1297 #ifdef BCMSDIODEV_ENABLED
1298 wlc->pub->_priofc = true; /* enable priority flow control for sdio dongle */
1299 #endif
1301 wlc->pub->_ampdu = AMPDU_AGG_HOST;
1302 wlc->pub->bcmerror = 0;
1303 wlc->pub->_coex = ON;
1305 /* initialize mpc delay */
1306 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
1309 static bool brcms_c_state_bmac_sync(struct brcms_c_info *wlc)
1311 struct brcms_b_state state_bmac;
1313 if (brcms_b_state_get(wlc->hw, &state_bmac) != 0)
1314 return false;
1316 wlc->machwcap = state_bmac.machwcap;
1317 brcms_c_protection_upd(wlc, WLC_PROT_N_PAM_OVR,
1318 (s8) state_bmac.preamble_ovr);
1320 return true;
1323 static uint brcms_c_attach_module(struct brcms_c_info *wlc)
1325 uint err = 0;
1326 uint unit;
1327 unit = wlc->pub->unit;
1329 wlc->asi = brcms_c_antsel_attach(wlc);
1330 if (wlc->asi == NULL) {
1331 wiphy_err(wlc->wiphy, "wl%d: attach: antsel_attach "
1332 "failed\n", unit);
1333 err = 44;
1334 goto fail;
1337 wlc->ampdu = brcms_c_ampdu_attach(wlc);
1338 if (wlc->ampdu == NULL) {
1339 wiphy_err(wlc->wiphy, "wl%d: attach: ampdu_attach "
1340 "failed\n", unit);
1341 err = 50;
1342 goto fail;
1345 if ((brcms_c_stf_attach(wlc) != 0)) {
1346 wiphy_err(wlc->wiphy, "wl%d: attach: stf_attach "
1347 "failed\n", unit);
1348 err = 68;
1349 goto fail;
1351 fail:
1352 return err;
1355 struct brcms_pub *brcms_c_pub(void *wlc)
1357 return ((struct brcms_c_info *) wlc)->pub;
1360 #define CHIP_SUPPORTS_11N(wlc) 1
1363 * The common driver entry routine. Error codes should be unique
1365 void *brcms_c_attach(struct brcms_info *wl, u16 vendor, u16 device, uint unit,
1366 bool piomode, void *regsva, uint bustype, void *btparam,
1367 uint *perr)
1369 struct brcms_c_info *wlc;
1370 uint err = 0;
1371 uint j;
1372 struct brcms_pub *pub;
1373 uint n_disabled;
1375 /* allocate struct brcms_c_info state and its substructures */
1376 wlc = (struct brcms_c_info *) brcms_c_attach_malloc(unit, &err, device);
1377 if (wlc == NULL)
1378 goto fail;
1379 wlc->wiphy = wl->wiphy;
1380 pub = wlc->pub;
1382 #if defined(BCMDBG)
1383 wlc_info_dbg = wlc;
1384 #endif
1386 wlc->band = wlc->bandstate[0];
1387 wlc->core = wlc->corestate;
1388 wlc->wl = wl;
1389 pub->unit = unit;
1390 pub->_piomode = piomode;
1391 wlc->bandinit_pending = false;
1393 /* populate struct brcms_c_info with default values */
1394 brcms_c_info_init(wlc, unit);
1396 /* update sta/ap related parameters */
1397 brcms_c_ap_upd(wlc);
1399 /* 11n_disable nvram */
1400 n_disabled = getintvar(pub->vars, "11n_disable");
1403 * low level attach steps(all hw accesses go
1404 * inside, no more in rest of the attach)
1406 err = brcms_b_attach(wlc, vendor, device, unit, piomode, regsva,
1407 bustype, btparam);
1408 if (err)
1409 goto fail;
1411 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1412 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1414 if (!brcms_c_state_bmac_sync(wlc)) {
1415 err = 20;
1416 goto fail;
1419 pub->phy_11ncapable = WLC_PHY_11N_CAP(wlc->band);
1421 /* propagate *vars* from BMAC driver to high driver */
1422 brcms_b_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size);
1425 /* set maximum allowed duty cycle */
1426 wlc->tx_duty_cycle_ofdm =
1427 (u16) getintvar(pub->vars, "tx_duty_cycle_ofdm");
1428 wlc->tx_duty_cycle_cck =
1429 (u16) getintvar(pub->vars, "tx_duty_cycle_cck");
1431 brcms_c_stf_phy_chain_calc(wlc);
1433 /* txchain 1: txant 0, txchain 2: txant 1 */
1434 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
1435 wlc->stf->txant = wlc->stf->hw_txchain - 1;
1437 /* push to BMAC driver */
1438 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain,
1439 wlc->stf->hw_rxchain);
1441 /* pull up some info resulting from the low attach */
1443 int i;
1444 for (i = 0; i < NFIFO; i++)
1445 wlc->core->txavail[i] = wlc->hw->txavail[i];
1448 brcms_b_hw_etheraddr(wlc->hw, wlc->perm_etheraddr);
1450 memcpy(&pub->cur_etheraddr, &wlc->perm_etheraddr, ETH_ALEN);
1452 for (j = 0; j < NBANDS(wlc); j++) {
1453 /* Use band 1 for single band 11a */
1454 if (IS_SINGLEBAND_5G(wlc->deviceid))
1455 j = BAND_5G_INDEX;
1457 wlc->band = wlc->bandstate[j];
1459 if (!brcms_c_attach_stf_ant_init(wlc)) {
1460 err = 24;
1461 goto fail;
1464 /* default contention windows size limits */
1465 wlc->band->CWmin = APHY_CWMIN;
1466 wlc->band->CWmax = PHY_CWMAX;
1468 /* init gmode value */
1469 if (BAND_2G(wlc->band->bandtype)) {
1470 wlc->band->gmode = GMODE_AUTO;
1471 brcms_c_protection_upd(wlc, WLC_PROT_G_USER,
1472 wlc->band->gmode);
1475 /* init _n_enab supported mode */
1476 if (WLC_PHY_11N_CAP(wlc->band) && CHIP_SUPPORTS_11N(wlc)) {
1477 if (n_disabled & WLFEATURE_DISABLE_11N) {
1478 pub->_n_enab = OFF;
1479 brcms_c_protection_upd(wlc, WLC_PROT_N_USER,
1480 OFF);
1481 } else {
1482 pub->_n_enab = SUPPORT_11N;
1483 brcms_c_protection_upd(wlc, WLC_PROT_N_USER,
1484 ((pub->_n_enab ==
1485 SUPPORT_11N) ? WL_11N_2x2 :
1486 WL_11N_3x3));
1490 /* init per-band default rateset, depend on band->gmode */
1491 brcms_default_rateset(wlc, &wlc->band->defrateset);
1493 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1494 brcms_c_rateset_filter(&wlc->band->defrateset,
1495 &wlc->band->hw_rateset, false,
1496 WLC_RATES_CCK_OFDM, WLC_RATE_MASK,
1497 (bool) N_ENAB(wlc->pub));
1500 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1501 brcms_c_stf_phy_txant_upd(wlc);
1503 /* attach each modules */
1504 err = brcms_c_attach_module(wlc);
1505 if (err != 0)
1506 goto fail;
1508 if (!brcms_c_timers_init(wlc, unit)) {
1509 wiphy_err(wl->wiphy, "wl%d: %s: init_timer failed\n", unit,
1510 __func__);
1511 err = 32;
1512 goto fail;
1515 /* depend on rateset, gmode */
1516 wlc->cmi = brcms_c_channel_mgr_attach(wlc);
1517 if (!wlc->cmi) {
1518 wiphy_err(wl->wiphy, "wl%d: %s: channel_mgr_attach failed"
1519 "\n", unit, __func__);
1520 err = 33;
1521 goto fail;
1524 /* init default when all parameters are ready, i.e. ->rateset */
1525 brcms_c_bss_default_init(wlc);
1528 * Complete the wlc default state initializations..
1531 /* allocate our initial queue */
1532 wlc->pkt_queue = brcms_c_txq_alloc(wlc);
1533 if (wlc->pkt_queue == NULL) {
1534 wiphy_err(wl->wiphy, "wl%d: %s: failed to malloc tx queue\n",
1535 unit, __func__);
1536 err = 100;
1537 goto fail;
1540 wlc->bsscfg[0] = wlc->cfg;
1541 wlc->cfg->_idx = 0;
1542 wlc->cfg->wlc = wlc;
1543 pub->txmaxpkts = MAXTXPKTS;
1545 brcms_c_wme_initparams_sta(wlc, &wlc->wme_param_ie);
1547 wlc->mimoft = FT_HT;
1548 wlc->ht_cap.cap_info = HT_CAP;
1549 if (HT_ENAB(wlc->pub))
1550 wlc->stf->ldpc = AUTO;
1552 wlc->mimo_40txbw = AUTO;
1553 wlc->ofdm_40txbw = AUTO;
1554 wlc->cck_40txbw = AUTO;
1555 brcms_c_update_mimo_band_bwcap(wlc, WLC_N_BW_20IN2G_40IN5G);
1557 /* Set default values of SGI */
1558 if (WLC_SGI_CAP_PHY(wlc)) {
1559 brcms_c_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1560 wlc->sgi_tx = AUTO;
1561 } else if (WLCISSSLPNPHY(wlc->band)) {
1562 brcms_c_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1563 wlc->sgi_tx = AUTO;
1564 } else {
1565 brcms_c_ht_update_sgi_rx(wlc, 0);
1566 wlc->sgi_tx = OFF;
1569 /* *******nvram 11n config overrides Start ********* */
1571 /* apply the sgi override from nvram conf */
1572 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_TX)
1573 wlc->sgi_tx = OFF;
1575 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_RX)
1576 brcms_c_ht_update_sgi_rx(wlc, 0);
1578 /* apply the stbc override from nvram conf */
1579 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_TX) {
1580 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
1581 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
1582 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_TX_STBC;
1584 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_RX)
1585 brcms_c_stf_stbc_rx_set(wlc, HT_CAP_RX_STBC_NO);
1587 /* apply the GF override from nvram conf */
1588 if (n_disabled & WLFEATURE_DISABLE_11N_GF)
1589 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_GRN_FLD;
1591 /* initialize radio_mpc_disable according to wlc->mpc */
1592 brcms_c_radio_mpc_upd(wlc);
1593 brcms_b_antsel_set(wlc->hw, wlc->asi->antsel_avail);
1595 if (perr)
1596 *perr = 0;
1598 return (void *)wlc;
1600 fail:
1601 wiphy_err(wl->wiphy, "wl%d: %s: failed with err %d\n",
1602 unit, __func__, err);
1603 if (wlc)
1604 brcms_c_detach(wlc);
1606 if (perr)
1607 *perr = err;
1608 return NULL;
1611 static void brcms_c_attach_antgain_init(struct brcms_c_info *wlc)
1613 uint unit;
1614 unit = wlc->pub->unit;
1616 if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) {
1617 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
1618 wlc->band->antgain = 8;
1619 } else if (wlc->band->antgain == -1) {
1620 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in"
1621 " srom, using 2dB\n", unit, __func__);
1622 wlc->band->antgain = 8;
1623 } else {
1624 s8 gain, fract;
1625 /* Older sroms specified gain in whole dbm only. In order
1626 * be able to specify qdbm granularity and remain backward compatible
1627 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
1628 * are encoded in the hi 2 bits. 6 bit signed number ranges from
1629 * -32 - 31. Examples: 0x1 = 1 db,
1630 * 0xc1 = 1.75 db (1 + 3 quarters),
1631 * 0x3f = -1 (-1 + 0 quarters),
1632 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
1633 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
1635 gain = wlc->band->antgain & 0x3f;
1636 gain <<= 2; /* Sign extend */
1637 gain >>= 2;
1638 fract = (wlc->band->antgain & 0xc0) >> 6;
1639 wlc->band->antgain = 4 * gain + fract;
1643 static bool brcms_c_attach_stf_ant_init(struct brcms_c_info *wlc)
1645 int aa;
1646 uint unit;
1647 char *vars;
1648 int bandtype;
1650 unit = wlc->pub->unit;
1651 vars = wlc->pub->vars;
1652 bandtype = wlc->band->bandtype;
1654 /* get antennas available */
1655 aa = (s8) getintvar(vars, (BAND_5G(bandtype) ? "aa5g" : "aa2g"));
1656 if (aa == 0)
1657 aa = (s8) getintvar(vars,
1658 (BAND_5G(bandtype) ? "aa1" : "aa0"));
1659 if ((aa < 1) || (aa > 15)) {
1660 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid antennas available in"
1661 " srom (0x%x), using 3\n", unit, __func__, aa);
1662 aa = 3;
1665 /* reset the defaults if we have a single antenna */
1666 if (aa == 1) {
1667 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0;
1668 wlc->stf->txant = ANT_TX_FORCE_0;
1669 } else if (aa == 2) {
1670 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1;
1671 wlc->stf->txant = ANT_TX_FORCE_1;
1672 } else {
1675 /* Compute Antenna Gain */
1676 wlc->band->antgain =
1677 (s8) getintvar(vars, (BAND_5G(bandtype) ? "ag1" : "ag0"));
1678 brcms_c_attach_antgain_init(wlc);
1680 return true;
1684 static void brcms_c_timers_deinit(struct brcms_c_info *wlc)
1686 /* free timer state */
1687 if (wlc->wdtimer) {
1688 brcms_free_timer(wlc->wl, wlc->wdtimer);
1689 wlc->wdtimer = NULL;
1691 if (wlc->radio_timer) {
1692 brcms_free_timer(wlc->wl, wlc->radio_timer);
1693 wlc->radio_timer = NULL;
1697 static void brcms_c_detach_module(struct brcms_c_info *wlc)
1699 if (wlc->asi) {
1700 brcms_c_antsel_detach(wlc->asi);
1701 wlc->asi = NULL;
1704 if (wlc->ampdu) {
1705 brcms_c_ampdu_detach(wlc->ampdu);
1706 wlc->ampdu = NULL;
1709 brcms_c_stf_detach(wlc);
1713 * Return a count of the number of driver callbacks still pending.
1715 * General policy is that brcms_c_detach can only dealloc/free software states.
1716 * It can NOT touch hardware registers since the d11core may be in reset and
1717 * clock may not be available.
1718 * One exception is sb register access, which is possible if crystal is turned
1719 * on after "down" state, driver should avoid software timer with the exception
1720 * of radio_monitor.
1722 uint brcms_c_detach(struct brcms_c_info *wlc)
1724 uint callbacks = 0;
1726 if (wlc == NULL)
1727 return 0;
1729 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
1731 callbacks += brcms_b_detach(wlc);
1733 /* delete software timers */
1734 if (!brcms_c_radio_monitor_stop(wlc))
1735 callbacks++;
1737 brcms_c_channel_mgr_detach(wlc->cmi);
1739 brcms_c_timers_deinit(wlc);
1741 brcms_c_detach_module(wlc);
1744 while (wlc->tx_queues != NULL)
1745 brcms_c_txq_free(wlc, wlc->tx_queues);
1747 brcms_c_detach_mfree(wlc);
1748 return callbacks;
1751 /* update state that depends on the current value of "ap" */
1752 void brcms_c_ap_upd(struct brcms_c_info *wlc)
1754 if (AP_ENAB(wlc->pub))
1755 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */
1756 else
1757 wlc->PLCPHdr_override = WLC_PLCP_SHORT; /* STA-BSS; short capable */
1759 /* fixup mpc */
1760 wlc->mpc = true;
1763 /* read hwdisable state and propagate to wlc flag */
1764 static void brcms_c_radio_hwdisable_upd(struct brcms_c_info *wlc)
1766 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off)
1767 return;
1769 if (brcms_b_radio_read_hwdisabled(wlc->hw)) {
1770 mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
1771 } else {
1772 mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
1776 /* return true if Minimum Power Consumption should be entered, false otherwise */
1777 bool brcms_c_is_non_delay_mpc(struct brcms_c_info *wlc)
1779 return false;
1782 bool brcms_c_ismpc(struct brcms_c_info *wlc)
1784 return (wlc->mpc_delay_off == 0) && (brcms_c_is_non_delay_mpc(wlc));
1787 void brcms_c_radio_mpc_upd(struct brcms_c_info *wlc)
1789 bool mpc_radio, radio_state;
1792 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
1793 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
1794 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
1795 * the radio is going down.
1797 if (!wlc->mpc) {
1798 if (!wlc->pub->radio_disabled)
1799 return;
1800 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
1801 brcms_c_radio_upd(wlc);
1802 if (!wlc->pub->radio_disabled)
1803 brcms_c_radio_monitor_stop(wlc);
1804 return;
1808 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
1809 * to go ON, always call radio_upd synchronously
1810 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
1812 radio_state =
1813 (mboolisset(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE) ? OFF :
1814 ON);
1815 mpc_radio = (brcms_c_ismpc(wlc) == true) ? OFF : ON;
1817 if (radio_state == ON && mpc_radio == OFF)
1818 wlc->mpc_delay_off = wlc->mpc_dlycnt;
1819 else if (radio_state == OFF && mpc_radio == ON) {
1820 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
1821 brcms_c_radio_upd(wlc);
1822 if (wlc->mpc_offcnt < WLC_MPC_THRESHOLD) {
1823 wlc->mpc_dlycnt = WLC_MPC_MAX_DELAYCNT;
1824 } else
1825 wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
1826 wlc->mpc_dur += OSL_SYSUPTIME() - wlc->mpc_laston_ts;
1828 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
1829 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
1830 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
1832 if ((wlc->prev_non_delay_mpc == false) &&
1833 (brcms_c_is_non_delay_mpc(wlc) == true) && wlc->mpc_delay_off) {
1834 wlc->mpc_delay_off = wlc->mpc_dlycnt;
1836 wlc->prev_non_delay_mpc = brcms_c_is_non_delay_mpc(wlc);
1840 * centralized radio disable/enable function,
1841 * invoke radio enable/disable after updating hwradio status
1843 static void brcms_c_radio_upd(struct brcms_c_info *wlc)
1845 if (wlc->pub->radio_disabled) {
1846 brcms_c_radio_disable(wlc);
1847 } else {
1848 brcms_c_radio_enable(wlc);
1852 /* maintain LED behavior in down state */
1853 static void brcms_c_down_led_upd(struct brcms_c_info *wlc)
1855 /* maintain LEDs while in down state, turn on sbclk if not available yet */
1856 /* turn on sbclk if necessary */
1857 if (!AP_ENAB(wlc->pub)) {
1858 brcms_c_pllreq(wlc, true, WLC_PLLREQ_FLIP);
1860 brcms_c_pllreq(wlc, false, WLC_PLLREQ_FLIP);
1864 /* update hwradio status and return it */
1865 bool brcms_c_check_radio_disabled(struct brcms_c_info *wlc)
1867 brcms_c_radio_hwdisable_upd(wlc);
1869 return mboolisset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE) ? true : false;
1872 void brcms_c_radio_disable(struct brcms_c_info *wlc)
1874 if (!wlc->pub->up) {
1875 brcms_c_down_led_upd(wlc);
1876 return;
1879 brcms_c_radio_monitor_start(wlc);
1880 brcms_down(wlc->wl);
1883 static void brcms_c_radio_enable(struct brcms_c_info *wlc)
1885 if (wlc->pub->up)
1886 return;
1888 if (DEVICEREMOVED(wlc))
1889 return;
1891 brcms_up(wlc->wl);
1894 /* periodical query hw radio button while driver is "down" */
1895 static void brcms_c_radio_timer(void *arg)
1897 struct brcms_c_info *wlc = (struct brcms_c_info *) arg;
1899 if (DEVICEREMOVED(wlc)) {
1900 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit,
1901 __func__);
1902 brcms_down(wlc->wl);
1903 return;
1906 /* cap mpc off count */
1907 if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT)
1908 wlc->mpc_offcnt++;
1910 brcms_c_radio_hwdisable_upd(wlc);
1911 brcms_c_radio_upd(wlc);
1914 static bool brcms_c_radio_monitor_start(struct brcms_c_info *wlc)
1916 /* Don't start the timer if HWRADIO feature is disabled */
1917 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
1918 return true;
1920 wlc->radio_monitor = true;
1921 brcms_c_pllreq(wlc, true, WLC_PLLREQ_RADIO_MON);
1922 brcms_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK,
1923 true);
1924 return true;
1927 bool brcms_c_radio_monitor_stop(struct brcms_c_info *wlc)
1929 if (!wlc->radio_monitor)
1930 return true;
1932 wlc->radio_monitor = false;
1933 brcms_c_pllreq(wlc, false, WLC_PLLREQ_RADIO_MON);
1934 return brcms_del_timer(wlc->wl, wlc->radio_timer);
1937 static void brcms_c_watchdog_by_timer(void *arg)
1939 brcms_c_watchdog(arg);
1942 /* common watchdog code */
1943 static void brcms_c_watchdog(void *arg)
1945 struct brcms_c_info *wlc = (struct brcms_c_info *) arg;
1946 int i;
1947 struct brcms_bss_cfg *cfg;
1949 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
1951 if (!wlc->pub->up)
1952 return;
1954 if (DEVICEREMOVED(wlc)) {
1955 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit,
1956 __func__);
1957 brcms_down(wlc->wl);
1958 return;
1961 /* increment second count */
1962 wlc->pub->now++;
1964 /* delay radio disable */
1965 if (wlc->mpc_delay_off) {
1966 if (--wlc->mpc_delay_off == 0) {
1967 mboolset(wlc->pub->radio_disabled,
1968 WL_RADIO_MPC_DISABLE);
1969 if (wlc->mpc && brcms_c_ismpc(wlc))
1970 wlc->mpc_offcnt = 0;
1971 wlc->mpc_laston_ts = OSL_SYSUPTIME();
1975 /* mpc sync */
1976 brcms_c_radio_mpc_upd(wlc);
1977 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
1978 brcms_c_radio_hwdisable_upd(wlc);
1979 brcms_c_radio_upd(wlc);
1980 /* if radio is disable, driver may be down, quit here */
1981 if (wlc->pub->radio_disabled)
1982 return;
1984 brcms_b_watchdog(wlc);
1986 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
1987 if ((wlc->pub->now % SW_TIMER_MAC_STAT_UPD) == 0)
1988 brcms_c_statsupd(wlc);
1990 /* Manage TKIP countermeasures timers */
1991 FOREACH_BSS(wlc, i, cfg) {
1992 if (cfg->tk_cm_dt) {
1993 cfg->tk_cm_dt--;
1995 if (cfg->tk_cm_bt) {
1996 cfg->tk_cm_bt--;
2000 /* Call any registered watchdog handlers */
2001 for (i = 0; i < WLC_MAXMODULES; i++) {
2002 if (wlc->modulecb[i].watchdog_fn)
2003 wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl);
2006 if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable &&
2007 ((wlc->pub->now - wlc->tempsense_lasttime) >=
2008 WLC_TEMPSENSE_PERIOD)) {
2009 wlc->tempsense_lasttime = wlc->pub->now;
2010 brcms_c_tempsense_upd(wlc);
2014 /* make interface operational */
2015 int brcms_c_up(struct brcms_c_info *wlc)
2017 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
2019 /* HW is turned off so don't try to access it */
2020 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
2021 return -ENOMEDIUM;
2023 if (!wlc->pub->hw_up) {
2024 brcms_b_hw_up(wlc->hw);
2025 wlc->pub->hw_up = true;
2028 if ((wlc->pub->boardflags & BFL_FEM)
2029 && (wlc->pub->sih->chip == BCM4313_CHIP_ID)) {
2030 if (wlc->pub->boardrev >= 0x1250
2031 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2032 brcms_c_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
2033 MHF5_4313_GPIOCTRL, WLC_BAND_ALL);
2034 } else {
2035 brcms_c_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE,
2036 MHF4_EXTPA_ENABLE, WLC_BAND_ALL);
2041 * Need to read the hwradio status here to cover the case where the system
2042 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2043 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2044 * don't call radio_update to avoid looping brcms_c_up.
2046 * brcms_b_up_prep() returns either 0 or -BCME_RADIOOFF only
2048 if (!wlc->pub->radio_disabled) {
2049 int status = brcms_b_up_prep(wlc->hw);
2050 if (status == -ENOMEDIUM) {
2051 if (!mboolisset
2052 (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) {
2053 int idx;
2054 struct brcms_bss_cfg *bsscfg;
2055 mboolset(wlc->pub->radio_disabled,
2056 WL_RADIO_HW_DISABLE);
2058 FOREACH_BSS(wlc, idx, bsscfg) {
2059 if (!BSSCFG_STA(bsscfg)
2060 || !bsscfg->enable || !bsscfg->BSS)
2061 continue;
2062 wiphy_err(wlc->wiphy, "wl%d.%d: up"
2063 ": rfdisable -> "
2064 "bsscfg_disable()\n",
2065 wlc->pub->unit, idx);
2071 if (wlc->pub->radio_disabled) {
2072 brcms_c_radio_monitor_start(wlc);
2073 return 0;
2076 /* brcms_b_up_prep has done brcms_c_corereset(). so clk is on, set it */
2077 wlc->clk = true;
2079 brcms_c_radio_monitor_stop(wlc);
2081 /* Set EDCF hostflags */
2082 if (EDCF_ENAB(wlc->pub)) {
2083 brcms_c_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL);
2084 } else {
2085 brcms_c_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL);
2088 if (WLC_WAR16165(wlc))
2089 brcms_c_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR,
2090 WLC_BAND_ALL);
2092 brcms_init(wlc->wl);
2093 wlc->pub->up = true;
2095 if (wlc->bandinit_pending) {
2096 brcms_c_suspend_mac_and_wait(wlc);
2097 brcms_c_set_chanspec(wlc, wlc->default_bss->chanspec);
2098 wlc->bandinit_pending = false;
2099 brcms_c_enable_mac(wlc);
2102 brcms_b_up_finish(wlc->hw);
2104 /* other software states up after ISR is running */
2105 /* start APs that were to be brought up but are not up yet */
2106 /* if (AP_ENAB(wlc->pub)) brcms_c_restart_ap(wlc->ap); */
2108 /* Program the TX wme params with the current settings */
2109 brcms_c_wme_retries_write(wlc);
2111 /* start one second watchdog timer */
2112 brcms_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true);
2113 wlc->WDarmed = true;
2115 /* ensure antenna config is up to date */
2116 brcms_c_stf_phy_txant_upd(wlc);
2117 /* ensure LDPC config is in sync */
2118 brcms_c_ht_update_ldpc(wlc, wlc->stf->ldpc);
2120 return 0;
2123 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2124 static void brcms_c_tx_prec_map_init(struct brcms_c_info *wlc)
2126 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2127 memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16));
2129 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2130 * if either is full.
2132 if (!EDCF_ENAB(wlc->pub)) {
2133 wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL;
2134 wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL;
2135 } else {
2136 wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK;
2137 wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE;
2138 wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI;
2139 wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO;
2143 static uint brcms_c_down_del_timer(struct brcms_c_info *wlc)
2145 uint callbacks = 0;
2147 return callbacks;
2151 * Mark the interface nonoperational, stop the software mechanisms,
2152 * disable the hardware, free any transient buffer state.
2153 * Return a count of the number of driver callbacks still pending.
2155 uint brcms_c_down(struct brcms_c_info *wlc)
2158 uint callbacks = 0;
2159 int i;
2160 bool dev_gone = false;
2161 struct brcms_txq_info *qi;
2163 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
2165 /* check if we are already in the going down path */
2166 if (wlc->going_down) {
2167 wiphy_err(wlc->wiphy, "wl%d: %s: Driver going down so return"
2168 "\n", wlc->pub->unit, __func__);
2169 return 0;
2171 if (!wlc->pub->up)
2172 return callbacks;
2174 /* in between, mpc could try to bring down again.. */
2175 wlc->going_down = true;
2177 callbacks += brcms_b_bmac_down_prep(wlc->hw);
2179 dev_gone = DEVICEREMOVED(wlc);
2181 /* Call any registered down handlers */
2182 for (i = 0; i < WLC_MAXMODULES; i++) {
2183 if (wlc->modulecb[i].down_fn)
2184 callbacks +=
2185 wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
2188 /* cancel the watchdog timer */
2189 if (wlc->WDarmed) {
2190 if (!brcms_del_timer(wlc->wl, wlc->wdtimer))
2191 callbacks++;
2192 wlc->WDarmed = false;
2194 /* cancel all other timers */
2195 callbacks += brcms_c_down_del_timer(wlc);
2197 wlc->pub->up = false;
2199 wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL);
2201 /* clear txq flow control */
2202 brcms_c_txflowcontrol_reset(wlc);
2204 /* flush tx queues */
2205 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
2206 brcmu_pktq_flush(&qi->q, true, NULL, NULL);
2209 callbacks += brcms_b_down_finish(wlc->hw);
2211 /* brcms_b_down_finish has done brcms_c_coredisable(). so clk is off */
2212 wlc->clk = false;
2214 wlc->going_down = false;
2215 return callbacks;
2218 /* Set the current gmode configuration */
2219 int brcms_c_set_gmode(struct brcms_c_info *wlc, u8 gmode, bool config)
2221 int ret = 0;
2222 uint i;
2223 wlc_rateset_t rs;
2224 /* Default to 54g Auto */
2225 s8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2226 bool shortslot_restrict = false; /* Restrict association to stations that support shortslot
2228 bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */
2229 int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2230 bool preamble_restrict = false; /* Restrict association to stations that support short
2231 * preambles
2233 struct brcms_band *band;
2235 /* if N-support is enabled, allow Gmode set as long as requested
2236 * Gmode is not GMODE_LEGACY_B
2238 if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B)
2239 return -ENOTSUPP;
2241 /* verify that we are dealing with 2G band and grab the band pointer */
2242 if (wlc->band->bandtype == WLC_BAND_2G)
2243 band = wlc->band;
2244 else if ((NBANDS(wlc) > 1) &&
2245 (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G))
2246 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
2247 else
2248 return -EINVAL;
2250 /* Legacy or bust when no OFDM is supported by regulatory */
2251 if ((brcms_c_channel_locale_flags_in_band(wlc->cmi, band->bandunit) &
2252 WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B))
2253 return -EINVAL;
2255 /* update configuration value */
2256 if (config == true)
2257 brcms_c_protection_upd(wlc, WLC_PROT_G_USER, gmode);
2259 /* Clear supported rates filter */
2260 memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t));
2262 /* Clear rateset override */
2263 memset(&rs, 0, sizeof(wlc_rateset_t));
2265 switch (gmode) {
2266 case GMODE_LEGACY_B:
2267 shortslot = WLC_SHORTSLOT_OFF;
2268 brcms_c_rateset_copy(&gphy_legacy_rates, &rs);
2270 break;
2272 case GMODE_LRS:
2273 if (AP_ENAB(wlc->pub))
2274 brcms_c_rateset_copy(&cck_rates,
2275 &wlc->sup_rates_override);
2276 break;
2278 case GMODE_AUTO:
2279 /* Accept defaults */
2280 break;
2282 case GMODE_ONLY:
2283 ofdm_basic = true;
2284 preamble = WLC_PLCP_SHORT;
2285 preamble_restrict = true;
2286 break;
2288 case GMODE_PERFORMANCE:
2289 if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */
2290 brcms_c_rateset_copy(&cck_ofdm_rates,
2291 &wlc->sup_rates_override);
2293 shortslot = WLC_SHORTSLOT_ON;
2294 shortslot_restrict = true;
2295 ofdm_basic = true;
2296 preamble = WLC_PLCP_SHORT;
2297 preamble_restrict = true;
2298 break;
2300 default:
2301 /* Error */
2302 wiphy_err(wlc->wiphy, "wl%d: %s: invalid gmode %d\n",
2303 wlc->pub->unit, __func__, gmode);
2304 return -ENOTSUPP;
2308 * If we are switching to gmode == GMODE_LEGACY_B,
2309 * clean up rate info that may refer to OFDM rates.
2311 if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) {
2312 band->gmode = gmode;
2313 if (band->rspec_override && !IS_CCK(band->rspec_override)) {
2314 band->rspec_override = 0;
2315 brcms_c_reprate_init(wlc);
2317 if (band->mrspec_override && !IS_CCK(band->mrspec_override)) {
2318 band->mrspec_override = 0;
2322 band->gmode = gmode;
2324 wlc->shortslot_override = shortslot;
2326 if (AP_ENAB(wlc->pub)) {
2327 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2328 wlc->PLCPHdr_override =
2329 (preamble !=
2330 WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO;
2333 if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG)
2334 || preamble == WLC_PLCP_SHORT)
2335 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2336 else
2337 wlc->default_bss->capability &= ~WLAN_CAPABILITY_SHORT_PREAMBLE;
2339 /* Update shortslot capability bit for AP and IBSS */
2340 if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) ||
2341 shortslot == WLC_SHORTSLOT_ON)
2342 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2343 else
2344 wlc->default_bss->capability &=
2345 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
2347 /* Use the default 11g rateset */
2348 if (!rs.count)
2349 brcms_c_rateset_copy(&cck_ofdm_rates, &rs);
2351 if (ofdm_basic) {
2352 for (i = 0; i < rs.count; i++) {
2353 if (rs.rates[i] == WLC_RATE_6M
2354 || rs.rates[i] == WLC_RATE_12M
2355 || rs.rates[i] == WLC_RATE_24M)
2356 rs.rates[i] |= WLC_RATE_FLAG;
2360 /* Set default bss rateset */
2361 wlc->default_bss->rateset.count = rs.count;
2362 memcpy(wlc->default_bss->rateset.rates, rs.rates,
2363 sizeof(wlc->default_bss->rateset.rates));
2365 return ret;
2368 static int brcms_c_nmode_validate(struct brcms_c_info *wlc, s32 nmode)
2370 int err = 0;
2372 switch (nmode) {
2374 case OFF:
2375 break;
2377 case AUTO:
2378 case WL_11N_2x2:
2379 case WL_11N_3x3:
2380 if (!(WLC_PHY_11N_CAP(wlc->band)))
2381 err = -EINVAL;
2382 break;
2384 default:
2385 err = -EINVAL;
2386 break;
2389 return err;
2392 int brcms_c_set_nmode(struct brcms_c_info *wlc, s32 nmode)
2394 uint i;
2395 int err;
2397 err = brcms_c_nmode_validate(wlc, nmode);
2398 if (err)
2399 return err;
2401 switch (nmode) {
2402 case OFF:
2403 wlc->pub->_n_enab = OFF;
2404 wlc->default_bss->flags &= ~WLC_BSS_HT;
2405 /* delete the mcs rates from the default and hw ratesets */
2406 brcms_c_rateset_mcs_clear(&wlc->default_bss->rateset);
2407 for (i = 0; i < NBANDS(wlc); i++) {
2408 memset(wlc->bandstate[i]->hw_rateset.mcs, 0,
2409 MCSSET_LEN);
2410 if (IS_MCS(wlc->band->rspec_override)) {
2411 wlc->bandstate[i]->rspec_override = 0;
2412 brcms_c_reprate_init(wlc);
2414 if (IS_MCS(wlc->band->mrspec_override))
2415 wlc->bandstate[i]->mrspec_override = 0;
2417 break;
2419 case AUTO:
2420 if (wlc->stf->txstreams == WL_11N_3x3)
2421 nmode = WL_11N_3x3;
2422 else
2423 nmode = WL_11N_2x2;
2424 case WL_11N_2x2:
2425 case WL_11N_3x3:
2426 /* force GMODE_AUTO if NMODE is ON */
2427 brcms_c_set_gmode(wlc, GMODE_AUTO, true);
2428 if (nmode == WL_11N_3x3)
2429 wlc->pub->_n_enab = SUPPORT_HT;
2430 else
2431 wlc->pub->_n_enab = SUPPORT_11N;
2432 wlc->default_bss->flags |= WLC_BSS_HT;
2433 /* add the mcs rates to the default and hw ratesets */
2434 brcms_c_rateset_mcs_build(&wlc->default_bss->rateset,
2435 wlc->stf->txstreams);
2436 for (i = 0; i < NBANDS(wlc); i++)
2437 memcpy(wlc->bandstate[i]->hw_rateset.mcs,
2438 wlc->default_bss->rateset.mcs, MCSSET_LEN);
2439 break;
2441 default:
2442 break;
2445 return err;
2448 static int brcms_c_set_rateset(struct brcms_c_info *wlc, wlc_rateset_t *rs_arg)
2450 wlc_rateset_t rs, new;
2451 uint bandunit;
2453 memcpy(&rs, rs_arg, sizeof(wlc_rateset_t));
2455 /* check for bad count value */
2456 if ((rs.count == 0) || (rs.count > WLC_NUMRATES))
2457 return -EINVAL;
2459 /* try the current band */
2460 bandunit = wlc->band->bandunit;
2461 memcpy(&new, &rs, sizeof(wlc_rateset_t));
2462 if (brcms_c_rate_hwrs_filter_sort_validate
2463 (&new, &wlc->bandstate[bandunit]->hw_rateset, true,
2464 wlc->stf->txstreams))
2465 goto good;
2467 /* try the other band */
2468 if (IS_MBAND_UNLOCKED(wlc)) {
2469 bandunit = OTHERBANDUNIT(wlc);
2470 memcpy(&new, &rs, sizeof(wlc_rateset_t));
2471 if (brcms_c_rate_hwrs_filter_sort_validate(&new,
2472 &wlc->
2473 bandstate[bandunit]->
2474 hw_rateset, true,
2475 wlc->stf->txstreams))
2476 goto good;
2479 return -EBADE;
2481 good:
2482 /* apply new rateset */
2483 memcpy(&wlc->default_bss->rateset, &new, sizeof(wlc_rateset_t));
2484 memcpy(&wlc->bandstate[bandunit]->defrateset, &new,
2485 sizeof(wlc_rateset_t));
2486 return 0;
2489 /* simplified integer set interface for common ioctl handler */
2490 int brcms_c_set(struct brcms_c_info *wlc, int cmd, int arg)
2492 return brcms_c_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
2495 /* simplified integer get interface for common ioctl handler */
2496 int brcms_c_get(struct brcms_c_info *wlc, int cmd, int *arg)
2498 return brcms_c_ioctl(wlc, cmd, arg, sizeof(int), NULL);
2501 static void brcms_c_ofdm_rateset_war(struct brcms_c_info *wlc)
2503 u8 r;
2504 bool war = false;
2506 if (wlc->cfg->associated)
2507 r = wlc->cfg->current_bss->rateset.rates[0];
2508 else
2509 r = wlc->default_bss->rateset.rates[0];
2511 wlc_phy_ofdm_rateset_war(wlc->band->pi, war);
2513 return;
2517 brcms_c_ioctl(struct brcms_c_info *wlc, int cmd, void *arg, int len,
2518 struct brcms_c_if *wlcif)
2520 return _brcms_c_ioctl(wlc, cmd, arg, len, wlcif);
2523 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
2524 static int
2525 _brcms_c_ioctl(struct brcms_c_info *wlc, int cmd, void *arg, int len,
2526 struct brcms_c_if *wlcif)
2528 int val, *pval;
2529 bool bool_val;
2530 int bcmerror;
2531 struct scb *nextscb;
2532 bool ta_ok;
2533 uint band;
2534 struct brcms_bss_cfg *bsscfg;
2535 struct brcms_bss_info *current_bss;
2537 /* update bsscfg pointer */
2538 bsscfg = wlc->cfg;
2539 current_bss = bsscfg->current_bss;
2541 /* initialize the following to get rid of compiler warning */
2542 nextscb = NULL;
2543 ta_ok = false;
2544 band = 0;
2546 /* If the device is turned off, then it's not "removed" */
2547 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
2548 wiphy_err(wlc->wiphy, "wl%d: %s: dead chip\n", wlc->pub->unit,
2549 __func__);
2550 brcms_down(wlc->wl);
2551 return -EBADE;
2554 /* default argument is generic integer */
2555 pval = arg ? (int *)arg : NULL;
2557 /* This will prevent the misaligned access */
2558 if (pval && (u32) len >= sizeof(val))
2559 memcpy(&val, pval, sizeof(val));
2560 else
2561 val = 0;
2563 /* bool conversion to avoid duplication below */
2564 bool_val = val != 0;
2565 bcmerror = 0;
2567 if ((arg == NULL) || (len <= 0)) {
2568 wiphy_err(wlc->wiphy, "wl%d: %s: Command %d needs arguments\n",
2569 wlc->pub->unit, __func__, cmd);
2570 bcmerror = -EINVAL;
2571 goto done;
2574 switch (cmd) {
2576 case WLC_SET_CHANNEL:{
2577 chanspec_t chspec = CH20MHZ_CHSPEC(val);
2579 if (val < 0 || val > MAXCHANNEL) {
2580 bcmerror = -EINVAL;
2581 break;
2584 if (!brcms_c_valid_chanspec_db(wlc->cmi, chspec)) {
2585 bcmerror = -EINVAL;
2586 break;
2589 if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) {
2590 if (wlc->band->bandunit !=
2591 CHSPEC_WLCBANDUNIT(chspec))
2592 wlc->bandinit_pending = true;
2593 else
2594 wlc->bandinit_pending = false;
2597 wlc->default_bss->chanspec = chspec;
2598 /* brcms_c_BSSinit() will sanitize the rateset before
2599 * using it.. */
2600 if (wlc->pub->up &&
2601 (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) {
2602 brcms_c_set_home_chanspec(wlc, chspec);
2603 brcms_c_suspend_mac_and_wait(wlc);
2604 brcms_c_set_chanspec(wlc, chspec);
2605 brcms_c_enable_mac(wlc);
2607 break;
2610 case WLC_SET_SRL:
2611 if (val >= 1 && val <= RETRY_SHORT_MAX) {
2612 int ac;
2613 wlc->SRL = (u16) val;
2615 brcms_b_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
2617 for (ac = 0; ac < AC_COUNT; ac++) {
2618 WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL);
2620 brcms_c_wme_retries_write(wlc);
2621 } else
2622 bcmerror = -EINVAL;
2623 break;
2625 case WLC_SET_LRL:
2626 if (val >= 1 && val <= 255) {
2627 int ac;
2628 wlc->LRL = (u16) val;
2630 brcms_b_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
2632 for (ac = 0; ac < AC_COUNT; ac++) {
2633 WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL);
2635 brcms_c_wme_retries_write(wlc);
2636 } else
2637 bcmerror = -EINVAL;
2638 break;
2640 case WLC_GET_CURR_RATESET:{
2641 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
2642 wlc_rateset_t *rs;
2644 if (wlc->pub->associated)
2645 rs = &current_bss->rateset;
2646 else
2647 rs = &wlc->default_bss->rateset;
2649 if (len < (int)(rs->count + sizeof(rs->count))) {
2650 bcmerror = -EOVERFLOW;
2651 break;
2654 /* Copy only legacy rateset section */
2655 ret_rs->count = rs->count;
2656 memcpy(&ret_rs->rates, &rs->rates, rs->count);
2657 break;
2660 case WLC_SET_RATESET:{
2661 wlc_rateset_t rs;
2662 wl_rateset_t *in_rs = (wl_rateset_t *) arg;
2664 if (len < (int)(in_rs->count + sizeof(in_rs->count))) {
2665 bcmerror = -EOVERFLOW;
2666 break;
2669 if (in_rs->count > WLC_NUMRATES) {
2670 bcmerror = -ENOBUFS;
2671 break;
2674 memset(&rs, 0, sizeof(wlc_rateset_t));
2676 /* Copy only legacy rateset section */
2677 rs.count = in_rs->count;
2678 memcpy(&rs.rates, &in_rs->rates, rs.count);
2680 /* merge rateset coming in with the current mcsset */
2681 if (N_ENAB(wlc->pub)) {
2682 if (bsscfg->associated)
2683 memcpy(rs.mcs,
2684 &current_bss->rateset.mcs[0],
2685 MCSSET_LEN);
2686 else
2687 memcpy(rs.mcs,
2688 &wlc->default_bss->rateset.mcs[0],
2689 MCSSET_LEN);
2692 bcmerror = brcms_c_set_rateset(wlc, &rs);
2694 if (!bcmerror)
2695 brcms_c_ofdm_rateset_war(wlc);
2697 break;
2700 case WLC_SET_BCNPRD:
2701 /* range [1, 0xffff] */
2702 if (val >= DOT11_MIN_BEACON_PERIOD
2703 && val <= DOT11_MAX_BEACON_PERIOD) {
2704 wlc->default_bss->beacon_period = (u16) val;
2705 } else
2706 bcmerror = -EINVAL;
2707 break;
2709 case WLC_GET_PHYLIST:
2711 unsigned char *cp = arg;
2712 if (len < 3) {
2713 bcmerror = -EOVERFLOW;
2714 break;
2717 if (WLCISNPHY(wlc->band)) {
2718 *cp++ = 'n';
2719 } else if (WLCISLCNPHY(wlc->band)) {
2720 *cp++ = 'c';
2721 } else if (WLCISSSLPNPHY(wlc->band)) {
2722 *cp++ = 's';
2724 *cp = '\0';
2725 break;
2728 case WLC_SET_SHORTSLOT_OVERRIDE:
2729 if ((val != WLC_SHORTSLOT_AUTO) &&
2730 (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) {
2731 bcmerror = -EINVAL;
2732 break;
2735 wlc->shortslot_override = (s8) val;
2737 /* shortslot is an 11g feature, so no more work if we are
2738 * currently on the 5G band
2740 if (BAND_5G(wlc->band->bandtype))
2741 break;
2743 if (wlc->pub->up && wlc->pub->associated) {
2744 /* let watchdog or beacon processing update shortslot */
2745 } else if (wlc->pub->up) {
2746 /* unassociated shortslot is off */
2747 brcms_c_switch_shortslot(wlc, false);
2748 } else {
2749 /* driver is down, so just update the brcms_c_info
2750 * value */
2751 if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) {
2752 wlc->shortslot = false;
2753 } else {
2754 wlc->shortslot =
2755 (wlc->shortslot_override ==
2756 WLC_SHORTSLOT_ON);
2760 break;
2763 done:
2765 if (bcmerror)
2766 wlc->pub->bcmerror = bcmerror;
2768 return bcmerror;
2772 * register watchdog and down handlers.
2774 int brcms_c_module_register(struct brcms_pub *pub,
2775 const char *name, void *hdl,
2776 watchdog_fn_t w_fn, down_fn_t d_fn)
2778 struct brcms_c_info *wlc = (struct brcms_c_info *) pub->wlc;
2779 int i;
2781 /* find an empty entry and just add, no duplication check! */
2782 for (i = 0; i < WLC_MAXMODULES; i++) {
2783 if (wlc->modulecb[i].name[0] == '\0') {
2784 strncpy(wlc->modulecb[i].name, name,
2785 sizeof(wlc->modulecb[i].name) - 1);
2786 wlc->modulecb[i].hdl = hdl;
2787 wlc->modulecb[i].watchdog_fn = w_fn;
2788 wlc->modulecb[i].down_fn = d_fn;
2789 return 0;
2793 return -ENOSR;
2796 /* unregister module callbacks */
2798 brcms_c_module_unregister(struct brcms_pub *pub, const char *name, void *hdl)
2800 struct brcms_c_info *wlc = (struct brcms_c_info *) pub->wlc;
2801 int i;
2803 if (wlc == NULL)
2804 return -ENODATA;
2806 for (i = 0; i < WLC_MAXMODULES; i++) {
2807 if (!strcmp(wlc->modulecb[i].name, name) &&
2808 (wlc->modulecb[i].hdl == hdl)) {
2809 memset(&wlc->modulecb[i], 0, sizeof(struct modulecb));
2810 return 0;
2814 /* table not found! */
2815 return -ENODATA;
2818 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
2819 static void brcms_c_wme_retries_write(struct brcms_c_info *wlc)
2821 int ac;
2823 /* Need clock to do this */
2824 if (!wlc->clk)
2825 return;
2827 for (ac = 0; ac < AC_COUNT; ac++) {
2828 brcms_c_write_shm(wlc, M_AC_TXLMT_ADDR(ac),
2829 wlc->wme_retries[ac]);
2833 #ifdef BCMDBG
2834 static const char * const supr_reason[] = {
2835 "None", "PMQ Entry", "Flush request",
2836 "Previous frag failure", "Channel mismatch",
2837 "Lifetime Expiry", "Underflow"
2840 static void brcms_c_print_txs_status(u16 s)
2842 printk(KERN_DEBUG "[15:12] %d frame attempts\n",
2843 (s & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT);
2844 printk(KERN_DEBUG " [11:8] %d rts attempts\n",
2845 (s & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT);
2846 printk(KERN_DEBUG " [7] %d PM mode indicated\n",
2847 ((s & TX_STATUS_PMINDCTD) ? 1 : 0));
2848 printk(KERN_DEBUG " [6] %d intermediate status\n",
2849 ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0));
2850 printk(KERN_DEBUG " [5] %d AMPDU\n",
2851 (s & TX_STATUS_AMPDU) ? 1 : 0);
2852 printk(KERN_DEBUG " [4:2] %d Frame Suppressed Reason (%s)\n",
2853 ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT),
2854 supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]);
2855 printk(KERN_DEBUG " [1] %d acked\n",
2856 ((s & TX_STATUS_ACK_RCV) ? 1 : 0));
2858 #endif /* BCMDBG */
2860 void brcms_c_print_txstatus(struct tx_status *txs)
2862 #if defined(BCMDBG)
2863 u16 s = txs->status;
2864 u16 ackphyrxsh = txs->ackphyrxsh;
2866 printk(KERN_DEBUG "\ntxpkt (MPDU) Complete\n");
2868 printk(KERN_DEBUG "FrameID: %04x ", txs->frameid);
2869 printk(KERN_DEBUG "TxStatus: %04x", s);
2870 printk(KERN_DEBUG "\n");
2872 brcms_c_print_txs_status(s);
2874 printk(KERN_DEBUG "LastTxTime: %04x ", txs->lasttxtime);
2875 printk(KERN_DEBUG "Seq: %04x ", txs->sequence);
2876 printk(KERN_DEBUG "PHYTxStatus: %04x ", txs->phyerr);
2877 printk(KERN_DEBUG "RxAckRSSI: %04x ",
2878 (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT);
2879 printk(KERN_DEBUG "RxAckSQ: %04x",
2880 (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
2881 printk(KERN_DEBUG "\n");
2882 #endif /* defined(BCMDBG) */
2885 void brcms_c_statsupd(struct brcms_c_info *wlc)
2887 int i;
2888 struct macstat macstats;
2889 #ifdef BCMDBG
2890 u16 delta;
2891 u16 rxf0ovfl;
2892 u16 txfunfl[NFIFO];
2893 #endif /* BCMDBG */
2895 /* if driver down, make no sense to update stats */
2896 if (!wlc->pub->up)
2897 return;
2899 #ifdef BCMDBG
2900 /* save last rx fifo 0 overflow count */
2901 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl;
2903 /* save last tx fifo underflow count */
2904 for (i = 0; i < NFIFO; i++)
2905 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i];
2906 #endif /* BCMDBG */
2908 /* Read mac stats from contiguous shared memory */
2909 brcms_b_copyfrom_shm(wlc->hw, M_UCODE_MACSTAT,
2910 &macstats, sizeof(struct macstat));
2912 #ifdef BCMDBG
2913 /* check for rx fifo 0 overflow */
2914 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
2915 if (delta)
2916 wiphy_err(wlc->wiphy, "wl%d: %u rx fifo 0 overflows!\n",
2917 wlc->pub->unit, delta);
2919 /* check for tx fifo underflows */
2920 for (i = 0; i < NFIFO; i++) {
2921 delta =
2922 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
2923 txfunfl[i]);
2924 if (delta)
2925 wiphy_err(wlc->wiphy, "wl%d: %u tx fifo %d underflows!"
2926 "\n", wlc->pub->unit, delta, i);
2928 #endif /* BCMDBG */
2930 /* merge counters from dma module */
2931 for (i = 0; i < NFIFO; i++) {
2932 if (wlc->hw->di[i]) {
2933 dma_counterreset(wlc->hw->di[i]);
2938 bool brcms_c_chipmatch(u16 vendor, u16 device)
2940 if (vendor != PCI_VENDOR_ID_BROADCOM) {
2941 pr_err("chipmatch: unknown vendor id %04x\n", vendor);
2942 return false;
2945 if (device == BCM43224_D11N_ID_VEN1)
2946 return true;
2947 if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID))
2948 return true;
2949 if (device == BCM4313_D11N2G_ID)
2950 return true;
2951 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
2952 return true;
2954 pr_err("chipmatch: unknown device id %04x\n", device);
2955 return false;
2958 #if defined(BCMDBG)
2959 void brcms_c_print_txdesc(struct d11txh *txh)
2961 u16 mtcl = le16_to_cpu(txh->MacTxControlLow);
2962 u16 mtch = le16_to_cpu(txh->MacTxControlHigh);
2963 u16 mfc = le16_to_cpu(txh->MacFrameControl);
2964 u16 tfest = le16_to_cpu(txh->TxFesTimeNormal);
2965 u16 ptcw = le16_to_cpu(txh->PhyTxControlWord);
2966 u16 ptcw_1 = le16_to_cpu(txh->PhyTxControlWord_1);
2967 u16 ptcw_1_Fbr = le16_to_cpu(txh->PhyTxControlWord_1_Fbr);
2968 u16 ptcw_1_Rts = le16_to_cpu(txh->PhyTxControlWord_1_Rts);
2969 u16 ptcw_1_FbrRts = le16_to_cpu(txh->PhyTxControlWord_1_FbrRts);
2970 u16 mainrates = le16_to_cpu(txh->MainRates);
2971 u16 xtraft = le16_to_cpu(txh->XtraFrameTypes);
2972 u8 *iv = txh->IV;
2973 u8 *ra = txh->TxFrameRA;
2974 u16 tfestfb = le16_to_cpu(txh->TxFesTimeFallback);
2975 u8 *rtspfb = txh->RTSPLCPFallback;
2976 u16 rtsdfb = le16_to_cpu(txh->RTSDurFallback);
2977 u8 *fragpfb = txh->FragPLCPFallback;
2978 u16 fragdfb = le16_to_cpu(txh->FragDurFallback);
2979 u16 mmodelen = le16_to_cpu(txh->MModeLen);
2980 u16 mmodefbrlen = le16_to_cpu(txh->MModeFbrLen);
2981 u16 tfid = le16_to_cpu(txh->TxFrameID);
2982 u16 txs = le16_to_cpu(txh->TxStatus);
2983 u16 mnmpdu = le16_to_cpu(txh->MaxNMpdus);
2984 u16 mabyte = le16_to_cpu(txh->MaxABytes_MRT);
2985 u16 mabyte_f = le16_to_cpu(txh->MaxABytes_FBR);
2986 u16 mmbyte = le16_to_cpu(txh->MinMBytes);
2988 u8 *rtsph = txh->RTSPhyHeader;
2989 struct ieee80211_rts rts = txh->rts_frame;
2990 char hexbuf[256];
2992 /* add plcp header along with txh descriptor */
2993 printk(KERN_DEBUG "Raw TxDesc + plcp header:\n");
2994 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
2995 txh, sizeof(struct d11txh) + 48);
2997 printk(KERN_DEBUG "TxCtlLow: %04x ", mtcl);
2998 printk(KERN_DEBUG "TxCtlHigh: %04x ", mtch);
2999 printk(KERN_DEBUG "FC: %04x ", mfc);
3000 printk(KERN_DEBUG "FES Time: %04x\n", tfest);
3001 printk(KERN_DEBUG "PhyCtl: %04x%s ", ptcw,
3002 (ptcw & PHY_TXC_SHORT_HDR) ? " short" : "");
3003 printk(KERN_DEBUG "PhyCtl_1: %04x ", ptcw_1);
3004 printk(KERN_DEBUG "PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr);
3005 printk(KERN_DEBUG "PhyCtl_1_Rts: %04x ", ptcw_1_Rts);
3006 printk(KERN_DEBUG "PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts);
3007 printk(KERN_DEBUG "MainRates: %04x ", mainrates);
3008 printk(KERN_DEBUG "XtraFrameTypes: %04x ", xtraft);
3009 printk(KERN_DEBUG "\n");
3011 brcmu_format_hex(hexbuf, iv, sizeof(txh->IV));
3012 printk(KERN_DEBUG "SecIV: %s\n", hexbuf);
3013 brcmu_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA));
3014 printk(KERN_DEBUG "RA: %s\n", hexbuf);
3016 printk(KERN_DEBUG "Fb FES Time: %04x ", tfestfb);
3017 brcmu_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback));
3018 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
3019 printk(KERN_DEBUG "RTS DUR: %04x ", rtsdfb);
3020 brcmu_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback));
3021 printk(KERN_DEBUG "PLCP: %s ", hexbuf);
3022 printk(KERN_DEBUG "DUR: %04x", fragdfb);
3023 printk(KERN_DEBUG "\n");
3025 printk(KERN_DEBUG "MModeLen: %04x ", mmodelen);
3026 printk(KERN_DEBUG "MModeFbrLen: %04x\n", mmodefbrlen);
3028 printk(KERN_DEBUG "FrameID: %04x\n", tfid);
3029 printk(KERN_DEBUG "TxStatus: %04x\n", txs);
3031 printk(KERN_DEBUG "MaxNumMpdu: %04x\n", mnmpdu);
3032 printk(KERN_DEBUG "MaxAggbyte: %04x\n", mabyte);
3033 printk(KERN_DEBUG "MaxAggbyte_fb: %04x\n", mabyte_f);
3034 printk(KERN_DEBUG "MinByte: %04x\n", mmbyte);
3036 brcmu_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader));
3037 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
3038 brcmu_format_hex(hexbuf, (u8 *) &rts, sizeof(txh->rts_frame));
3039 printk(KERN_DEBUG "RTS Frame: %s", hexbuf);
3040 printk(KERN_DEBUG "\n");
3042 #endif /* defined(BCMDBG) */
3044 #if defined(BCMDBG)
3045 void brcms_c_print_rxh(struct d11rxhdr *rxh)
3047 u16 len = rxh->RxFrameSize;
3048 u16 phystatus_0 = rxh->PhyRxStatus_0;
3049 u16 phystatus_1 = rxh->PhyRxStatus_1;
3050 u16 phystatus_2 = rxh->PhyRxStatus_2;
3051 u16 phystatus_3 = rxh->PhyRxStatus_3;
3052 u16 macstatus1 = rxh->RxStatus1;
3053 u16 macstatus2 = rxh->RxStatus2;
3054 char flagstr[64];
3055 char lenbuf[20];
3056 static const struct brcmu_bit_desc macstat_flags[] = {
3057 {RXS_FCSERR, "FCSErr"},
3058 {RXS_RESPFRAMETX, "Reply"},
3059 {RXS_PBPRES, "PADDING"},
3060 {RXS_DECATMPT, "DeCr"},
3061 {RXS_DECERR, "DeCrErr"},
3062 {RXS_BCNSENT, "Bcn"},
3063 {0, NULL}
3066 printk(KERN_DEBUG "Raw RxDesc:\n");
3067 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, rxh,
3068 sizeof(struct d11rxhdr));
3070 brcmu_format_flags(macstat_flags, macstatus1, flagstr, 64);
3072 snprintf(lenbuf, sizeof(lenbuf), "0x%x", len);
3074 printk(KERN_DEBUG "RxFrameSize: %6s (%d)%s\n", lenbuf, len,
3075 (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : "");
3076 printk(KERN_DEBUG "RxPHYStatus: %04x %04x %04x %04x\n",
3077 phystatus_0, phystatus_1, phystatus_2, phystatus_3);
3078 printk(KERN_DEBUG "RxMACStatus: %x %s\n", macstatus1, flagstr);
3079 printk(KERN_DEBUG "RXMACaggtype: %x\n",
3080 (macstatus2 & RXS_AGGTYPE_MASK));
3081 printk(KERN_DEBUG "RxTSFTime: %04x\n", rxh->RxTSFTime);
3083 #endif /* defined(BCMDBG) */
3085 static u16 brcms_c_rate_shm_offset(struct brcms_c_info *wlc, u8 rate)
3087 return brcms_b_rate_shm_offset(wlc->hw, rate);
3090 /* Callback for device removed */
3093 * Attempts to queue a packet onto a multiple-precedence queue,
3094 * if necessary evicting a lower precedence packet from the queue.
3096 * 'prec' is the precedence number that has already been mapped
3097 * from the packet priority.
3099 * Returns true if packet consumed (queued), false if not.
3101 bool
3102 brcms_c_prec_enq(struct brcms_c_info *wlc, struct pktq *q, void *pkt, int prec)
3104 return brcms_c_prec_enq_head(wlc, q, pkt, prec, false);
3107 bool
3108 brcms_c_prec_enq_head(struct brcms_c_info *wlc, struct pktq *q,
3109 struct sk_buff *pkt, int prec, bool head)
3111 struct sk_buff *p;
3112 int eprec = -1; /* precedence to evict from */
3114 /* Determine precedence from which to evict packet, if any */
3115 if (pktq_pfull(q, prec))
3116 eprec = prec;
3117 else if (pktq_full(q)) {
3118 p = brcmu_pktq_peek_tail(q, &eprec);
3119 if (eprec > prec) {
3120 wiphy_err(wlc->wiphy, "%s: Failing: eprec %d > prec %d"
3121 "\n", __func__, eprec, prec);
3122 return false;
3126 /* Evict if needed */
3127 if (eprec >= 0) {
3128 bool discard_oldest;
3130 discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec);
3132 /* Refuse newer packet unless configured to discard oldest */
3133 if (eprec == prec && !discard_oldest) {
3134 wiphy_err(wlc->wiphy, "%s: No where to go, prec == %d"
3135 "\n", __func__, prec);
3136 return false;
3139 /* Evict packet according to discard policy */
3140 p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) :
3141 brcmu_pktq_pdeq_tail(q, eprec);
3142 brcmu_pkt_buf_free_skb(p);
3145 /* Enqueue */
3146 if (head)
3147 p = brcmu_pktq_penq_head(q, prec, pkt);
3148 else
3149 p = brcmu_pktq_penq(q, prec, pkt);
3151 return true;
3154 void brcms_c_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
3155 uint prec)
3157 struct brcms_c_info *wlc = (struct brcms_c_info *) ctx;
3158 struct brcms_txq_info *qi = wlc->pkt_queue; /* Check me */
3159 struct pktq *q = &qi->q;
3160 int prio;
3162 prio = sdu->priority;
3164 if (!brcms_c_prec_enq(wlc, q, sdu, prec)) {
3165 if (!EDCF_ENAB(wlc->pub)
3166 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
3167 wiphy_err(wlc->wiphy, "wl%d: txq_enq: txq overflow"
3168 "\n", wlc->pub->unit);
3171 * we might hit this condtion in case
3172 * packet flooding from mac80211 stack
3174 brcmu_pkt_buf_free_skb(sdu);
3177 /* Check if flow control needs to be turned on after enqueuing the packet
3178 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
3179 * to drop instead of relying on stack to make the right decision
3181 if (!EDCF_ENAB(wlc->pub)
3182 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
3183 if (pktq_len(q) >= wlc->pub->tunables->datahiwat) {
3184 brcms_c_txflowcontrol(wlc, qi, ON, ALLPRIO);
3186 } else if (wlc->pub->_priofc) {
3187 if (pktq_plen(q, wlc_prio2prec_map[prio]) >=
3188 wlc->pub->tunables->datahiwat) {
3189 brcms_c_txflowcontrol(wlc, qi, ON, prio);
3194 bool
3195 brcms_c_sendpkt_mac80211(struct brcms_c_info *wlc, struct sk_buff *sdu,
3196 struct ieee80211_hw *hw)
3198 u8 prio;
3199 uint fifo;
3200 void *pkt;
3201 struct scb *scb = &global_scb;
3202 struct ieee80211_hdr *d11_header = (struct ieee80211_hdr *)(sdu->data);
3204 /* 802.11 standard requires management traffic to go at highest priority */
3205 prio = ieee80211_is_data(d11_header->frame_control) ? sdu->priority :
3206 MAXPRIO;
3207 fifo = prio2fifo[prio];
3208 pkt = sdu;
3209 if (unlikely
3210 (brcms_c_d11hdrs_mac80211(
3211 wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0)))
3212 return -EINVAL;
3213 brcms_c_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio));
3214 brcms_c_send_q(wlc);
3215 return 0;
3218 void brcms_c_send_q(struct brcms_c_info *wlc)
3220 struct sk_buff *pkt[DOT11_MAXNUMFRAGS];
3221 int prec;
3222 u16 prec_map;
3223 int err = 0, i, count;
3224 uint fifo;
3225 struct brcms_txq_info *qi = wlc->pkt_queue;
3226 struct pktq *q = &qi->q;
3227 struct ieee80211_tx_info *tx_info;
3229 if (in_send_q)
3230 return;
3231 else
3232 in_send_q = true;
3234 prec_map = wlc->tx_prec_map;
3236 /* Send all the enq'd pkts that we can.
3237 * Dequeue packets with precedence with empty HW fifo only
3239 while (prec_map && (pkt[0] = brcmu_pktq_mdeq(q, prec_map, &prec))) {
3240 tx_info = IEEE80211_SKB_CB(pkt[0]);
3241 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
3242 err = brcms_c_sendampdu(wlc->ampdu, qi, pkt, prec);
3243 } else {
3244 count = 1;
3245 err = brcms_c_prep_pdu(wlc, pkt[0], &fifo);
3246 if (!err) {
3247 for (i = 0; i < count; i++) {
3248 brcms_c_txfifo(wlc, fifo, pkt[i], true,
3254 if (err == -EBUSY) {
3255 brcmu_pktq_penq_head(q, prec, pkt[0]);
3256 /* If send failed due to any other reason than a change in
3257 * HW FIFO condition, quit. Otherwise, read the new prec_map!
3259 if (prec_map == wlc->tx_prec_map)
3260 break;
3261 prec_map = wlc->tx_prec_map;
3265 /* Check if flow control needs to be turned off after sending the packet */
3266 if (!EDCF_ENAB(wlc->pub)
3267 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
3268 if (brcms_c_txflowcontrol_prio_isset(wlc, qi, ALLPRIO)
3269 && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) {
3270 brcms_c_txflowcontrol(wlc, qi, OFF, ALLPRIO);
3272 } else if (wlc->pub->_priofc) {
3273 int prio;
3274 for (prio = MAXPRIO; prio >= 0; prio--) {
3275 if (brcms_c_txflowcontrol_prio_isset(wlc, qi, prio) &&
3276 (pktq_plen(q, wlc_prio2prec_map[prio]) <
3277 wlc->pub->tunables->datahiwat / 2)) {
3278 brcms_c_txflowcontrol(wlc, qi, OFF, prio);
3282 in_send_q = false;
3286 * bcmc_fid_generate:
3287 * Generate frame ID for a BCMC packet. The frag field is not used
3288 * for MC frames so is used as part of the sequence number.
3290 static inline u16
3291 bcmc_fid_generate(struct brcms_c_info *wlc, struct brcms_bss_cfg *bsscfg,
3292 struct d11txh *txh)
3294 u16 frameid;
3296 frameid = le16_to_cpu(txh->TxFrameID) & ~(TXFID_SEQ_MASK |
3297 TXFID_QUEUE_MASK);
3298 frameid |=
3299 (((wlc->
3300 mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
3301 TX_BCMC_FIFO;
3303 return frameid;
3306 void
3307 brcms_c_txfifo(struct brcms_c_info *wlc, uint fifo, struct sk_buff *p,
3308 bool commit, s8 txpktpend)
3310 u16 frameid = INVALIDFID;
3311 struct d11txh *txh;
3313 txh = (struct d11txh *) (p->data);
3315 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
3316 * ucode or BSS info as appropriate.
3318 if (fifo == TX_BCMC_FIFO) {
3319 frameid = le16_to_cpu(txh->TxFrameID);
3323 if (WLC_WAR16165(wlc))
3324 brcms_c_war16165(wlc, true);
3327 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
3328 * in brcms_b_txfifo()
3330 if (commit) {
3331 TXPKTPENDINC(wlc, fifo, txpktpend);
3332 BCMMSG(wlc->wiphy, "pktpend inc %d to %d\n",
3333 txpktpend, TXPKTPENDGET(wlc, fifo));
3336 /* Commit BCMC sequence number in the SHM frame ID location */
3337 if (frameid != INVALIDFID)
3338 BCMCFID(wlc, frameid);
3340 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
3341 wiphy_err(wlc->wiphy, "txfifo: fatal, toss frames !!!\n");
3345 void
3346 brcms_c_compute_plcp(struct brcms_c_info *wlc, ratespec_t rspec,
3347 uint length, u8 *plcp)
3349 if (IS_MCS(rspec)) {
3350 brcms_c_compute_mimo_plcp(rspec, length, plcp);
3351 } else if (IS_OFDM(rspec)) {
3352 brcms_c_compute_ofdm_plcp(rspec, length, plcp);
3353 } else {
3354 brcms_c_compute_cck_plcp(wlc, rspec, length, plcp);
3356 return;
3359 /* Rate: 802.11 rate code, length: PSDU length in octets */
3360 static void brcms_c_compute_mimo_plcp(ratespec_t rspec, uint length, u8 *plcp)
3362 u8 mcs = (u8) (rspec & RSPEC_RATE_MASK);
3363 plcp[0] = mcs;
3364 if (RSPEC_IS40MHZ(rspec) || (mcs == 32))
3365 plcp[0] |= MIMO_PLCP_40MHZ;
3366 WLC_SET_MIMO_PLCP_LEN(plcp, length);
3367 plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */
3368 plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
3369 plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */
3370 plcp[5] = 0;
3373 /* Rate: 802.11 rate code, length: PSDU length in octets */
3374 static void
3375 brcms_c_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp)
3377 u8 rate_signal;
3378 u32 tmp = 0;
3379 int rate = RSPEC2RATE(rspec);
3381 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
3382 rate_signal = rate_info[rate] & WLC_RATE_MASK;
3383 memset(plcp, 0, D11_PHY_HDR_LEN);
3384 D11A_PHY_HDR_SRATE((struct ofdm_phy_hdr *) plcp, rate_signal);
3386 tmp = (length & 0xfff) << 5;
3387 plcp[2] |= (tmp >> 16) & 0xff;
3388 plcp[1] |= (tmp >> 8) & 0xff;
3389 plcp[0] |= tmp & 0xff;
3391 return;
3395 * Compute PLCP, but only requires actual rate and length of pkt.
3396 * Rate is given in the driver standard multiple of 500 kbps.
3397 * le is set for 11 Mbps rate if necessary.
3398 * Broken out for PRQ.
3401 static void brcms_c_cck_plcp_set(struct brcms_c_info *wlc, int rate_500,
3402 uint length, u8 *plcp)
3404 u16 usec = 0;
3405 u8 le = 0;
3407 switch (rate_500) {
3408 case WLC_RATE_1M:
3409 usec = length << 3;
3410 break;
3411 case WLC_RATE_2M:
3412 usec = length << 2;
3413 break;
3414 case WLC_RATE_5M5:
3415 usec = (length << 4) / 11;
3416 if ((length << 4) - (usec * 11) > 0)
3417 usec++;
3418 break;
3419 case WLC_RATE_11M:
3420 usec = (length << 3) / 11;
3421 if ((length << 3) - (usec * 11) > 0) {
3422 usec++;
3423 if ((usec * 11) - (length << 3) >= 8)
3424 le = D11B_PLCP_SIGNAL_LE;
3426 break;
3428 default:
3429 wiphy_err(wlc->wiphy, "brcms_c_cck_plcp_set: unsupported rate %d"
3430 "\n", rate_500);
3431 rate_500 = WLC_RATE_1M;
3432 usec = length << 3;
3433 break;
3435 /* PLCP signal byte */
3436 plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */
3437 /* PLCP service byte */
3438 plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED);
3439 /* PLCP length u16, little endian */
3440 plcp[2] = usec & 0xff;
3441 plcp[3] = (usec >> 8) & 0xff;
3442 /* PLCP CRC16 */
3443 plcp[4] = 0;
3444 plcp[5] = 0;
3447 /* Rate: 802.11 rate code, length: PSDU length in octets */
3448 static void brcms_c_compute_cck_plcp(struct brcms_c_info *wlc, ratespec_t rspec,
3449 uint length, u8 *plcp)
3451 int rate = RSPEC2RATE(rspec);
3453 brcms_c_cck_plcp_set(wlc, rate, length, plcp);
3456 /* brcms_c_compute_frame_dur()
3458 * Calculate the 802.11 MAC header DUR field for MPDU
3459 * DUR for a single frame = 1 SIFS + 1 ACK
3460 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
3462 * rate MPDU rate in unit of 500kbps
3463 * next_frag_len next MPDU length in bytes
3464 * preamble_type use short/GF or long/MM PLCP header
3466 static u16
3467 brcms_c_compute_frame_dur(struct brcms_c_info *wlc, ratespec_t rate,
3468 u8 preamble_type, uint next_frag_len)
3470 u16 dur, sifs;
3472 sifs = SIFS(wlc->band);
3474 dur = sifs;
3475 dur += (u16) brcms_c_calc_ack_time(wlc, rate, preamble_type);
3477 if (next_frag_len) {
3478 /* Double the current DUR to get 2 SIFS + 2 ACKs */
3479 dur *= 2;
3480 /* add another SIFS and the frag time */
3481 dur += sifs;
3482 dur +=
3483 (u16) brcms_c_calc_frame_time(wlc, rate, preamble_type,
3484 next_frag_len);
3486 return dur;
3489 /* brcms_c_compute_rtscts_dur()
3491 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
3492 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
3493 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
3495 * cts cts-to-self or rts/cts
3496 * rts_rate rts or cts rate in unit of 500kbps
3497 * rate next MPDU rate in unit of 500kbps
3498 * frame_len next MPDU frame length in bytes
3501 brcms_c_compute_rtscts_dur(struct brcms_c_info *wlc, bool cts_only,
3502 ratespec_t rts_rate,
3503 ratespec_t frame_rate, u8 rts_preamble_type,
3504 u8 frame_preamble_type, uint frame_len, bool ba)
3506 u16 dur, sifs;
3508 sifs = SIFS(wlc->band);
3510 if (!cts_only) { /* RTS/CTS */
3511 dur = 3 * sifs;
3512 dur +=
3513 (u16) brcms_c_calc_cts_time(wlc, rts_rate,
3514 rts_preamble_type);
3515 } else { /* CTS-TO-SELF */
3516 dur = 2 * sifs;
3519 dur +=
3520 (u16) brcms_c_calc_frame_time(wlc, frame_rate, frame_preamble_type,
3521 frame_len);
3522 if (ba)
3523 dur +=
3524 (u16) brcms_c_calc_ba_time(wlc, frame_rate,
3525 WLC_SHORT_PREAMBLE);
3526 else
3527 dur +=
3528 (u16) brcms_c_calc_ack_time(wlc, frame_rate,
3529 frame_preamble_type);
3530 return dur;
3533 u16 brcms_c_phytxctl1_calc(struct brcms_c_info *wlc, ratespec_t rspec)
3535 u16 phyctl1 = 0;
3536 u16 bw;
3538 if (WLCISLCNPHY(wlc->band)) {
3539 bw = PHY_TXC1_BW_20MHZ;
3540 } else {
3541 bw = RSPEC_GET_BW(rspec);
3542 /* 10Mhz is not supported yet */
3543 if (bw < PHY_TXC1_BW_20MHZ) {
3544 wiphy_err(wlc->wiphy, "phytxctl1_calc: bw %d is "
3545 "not supported yet, set to 20L\n", bw);
3546 bw = PHY_TXC1_BW_20MHZ;
3550 if (IS_MCS(rspec)) {
3551 uint mcs = rspec & RSPEC_RATE_MASK;
3553 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
3554 phyctl1 = RSPEC_PHYTXBYTE2(rspec);
3555 /* set the upper byte of phyctl1 */
3556 phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8);
3557 } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band)
3558 && !WLCISSSLPNPHY(wlc->band)) {
3559 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
3560 /* Eventually MIMOPHY would also be converted to this format */
3561 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
3562 phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
3563 } else { /* legacy OFDM/CCK */
3564 s16 phycfg;
3565 /* get the phyctl byte from rate phycfg table */
3566 phycfg = brcms_c_rate_legacy_phyctl(RSPEC2RATE(rspec));
3567 if (phycfg == -1) {
3568 wiphy_err(wlc->wiphy, "phytxctl1_calc: wrong "
3569 "legacy OFDM/CCK rate\n");
3570 phycfg = 0;
3572 /* set the upper byte of phyctl1 */
3573 phyctl1 =
3574 (bw | (phycfg << 8) |
3575 (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
3577 return phyctl1;
3580 ratespec_t
3581 brcms_c_rspec_to_rts_rspec(struct brcms_c_info *wlc, ratespec_t rspec,
3582 bool use_rspec, u16 mimo_ctlchbw)
3584 ratespec_t rts_rspec = 0;
3586 if (use_rspec) {
3587 /* use frame rate as rts rate */
3588 rts_rspec = rspec;
3590 } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) {
3591 /* Use 11Mbps as the g protection RTS target rate and fallback.
3592 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
3593 * target in case 11 Mbps is not Basic.
3594 * 6 and 9 Mbps are not usually selected by rate selection, but even
3595 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
3597 rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M);
3598 } else {
3599 /* calculate RTS rate and fallback rate based on the frame rate
3600 * RTS must be sent at a basic rate since it is a
3601 * control frame, sec 9.6 of 802.11 spec
3603 rts_rspec = WLC_BASIC_RATE(wlc, rspec);
3606 if (WLC_PHY_11N_CAP(wlc->band)) {
3607 /* set rts txbw to correct side band */
3608 rts_rspec &= ~RSPEC_BW_MASK;
3610 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
3611 * (DUP), otherwise send RTS on control channel
3613 if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec))
3614 rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT);
3615 else
3616 rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
3618 /* pick siso/cdd as default for ofdm */
3619 if (IS_OFDM(rts_rspec)) {
3620 rts_rspec &= ~RSPEC_STF_MASK;
3621 rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
3624 return rts_rspec;
3628 * Add struct d11txh, struct cck_phy_hdr.
3630 * 'p' data must start with 802.11 MAC header
3631 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
3633 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
3636 static u16
3637 brcms_c_d11hdrs_mac80211(struct brcms_c_info *wlc, struct ieee80211_hw *hw,
3638 struct sk_buff *p, struct scb *scb, uint frag,
3639 uint nfrags, uint queue, uint next_frag_len,
3640 struct wsec_key *key, ratespec_t rspec_override)
3642 struct ieee80211_hdr *h;
3643 struct d11txh *txh;
3644 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
3645 int len, phylen, rts_phylen;
3646 u16 mch, phyctl, xfts, mainrates;
3647 u16 seq = 0, mcl = 0, status = 0, frameid = 0;
3648 ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = {
3649 WLC_RATE_1M, WLC_RATE_1M};
3650 bool use_rts = false;
3651 bool use_cts = false;
3652 bool use_rifs = false;
3653 bool short_preamble[2] = { false, false };
3654 u8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
3655 u8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
3656 u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN];
3657 struct ieee80211_rts *rts = NULL;
3658 bool qos;
3659 uint ac;
3660 u32 rate_val[2];
3661 bool hwtkmic = false;
3662 u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
3663 #define ANTCFG_NONE 0xFF
3664 u8 antcfg = ANTCFG_NONE;
3665 u8 fbantcfg = ANTCFG_NONE;
3666 uint phyctl1_stf = 0;
3667 u16 durid = 0;
3668 struct ieee80211_tx_rate *txrate[2];
3669 int k;
3670 struct ieee80211_tx_info *tx_info;
3671 bool is_mcs[2];
3672 u16 mimo_txbw;
3673 u8 mimo_preamble_type;
3675 /* locate 802.11 MAC header */
3676 h = (struct ieee80211_hdr *)(p->data);
3677 qos = ieee80211_is_data_qos(h->frame_control);
3679 /* compute length of frame in bytes for use in PLCP computations */
3680 len = brcmu_pkttotlen(p);
3681 phylen = len + FCS_LEN;
3683 /* If WEP enabled, add room in phylen for the additional bytes of
3684 * ICV which MAC generates. We do NOT add the additional bytes to
3685 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
3686 * in this case
3688 if (key) {
3689 phylen += key->icv_len;
3692 /* Get tx_info */
3693 tx_info = IEEE80211_SKB_CB(p);
3695 /* add PLCP */
3696 plcp = skb_push(p, D11_PHY_HDR_LEN);
3698 /* add Broadcom tx descriptor header */
3699 txh = (struct d11txh *) skb_push(p, D11_TXH_LEN);
3700 memset(txh, 0, D11_TXH_LEN);
3702 /* setup frameid */
3703 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
3704 /* non-AP STA should never use BCMC queue */
3705 if (queue == TX_BCMC_FIFO) {
3706 wiphy_err(wlc->wiphy, "wl%d: %s: ASSERT queue == "
3707 "TX_BCMC!\n", WLCWLUNIT(wlc), __func__);
3708 frameid = bcmc_fid_generate(wlc, NULL, txh);
3709 } else {
3710 /* Increment the counter for first fragment */
3711 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
3712 SCB_SEQNUM(scb, p->priority)++;
3715 /* extract fragment number from frame first */
3716 seq = le16_to_cpu(seq) & FRAGNUM_MASK;
3717 seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT);
3718 h->seq_ctrl = cpu_to_le16(seq);
3720 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
3721 (queue & TXFID_QUEUE_MASK);
3724 frameid |= queue & TXFID_QUEUE_MASK;
3726 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
3727 if (SCB_PS(scb) || ieee80211_is_beacon(h->frame_control))
3728 mcl |= TXC_IGNOREPMQ;
3730 txrate[0] = tx_info->control.rates;
3731 txrate[1] = txrate[0] + 1;
3733 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
3734 if (txrate[1]->idx < 0) {
3735 txrate[1] = txrate[0];
3738 for (k = 0; k < hw->max_rates; k++) {
3739 is_mcs[k] =
3740 txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false;
3741 if (!is_mcs[k]) {
3742 if ((txrate[k]->idx >= 0)
3743 && (txrate[k]->idx <
3744 hw->wiphy->bands[tx_info->band]->n_bitrates)) {
3745 rate_val[k] =
3746 hw->wiphy->bands[tx_info->band]->
3747 bitrates[txrate[k]->idx].hw_value;
3748 short_preamble[k] =
3749 txrate[k]->
3750 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ?
3751 true : false;
3752 } else {
3753 rate_val[k] = WLC_RATE_1M;
3755 } else {
3756 rate_val[k] = txrate[k]->idx;
3758 /* Currently only support same setting for primay and fallback rates.
3759 * Unify flags for each rate into a single value for the frame
3761 use_rts |=
3762 txrate[k]->
3763 flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false;
3764 use_cts |=
3765 txrate[k]->
3766 flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false;
3768 if (is_mcs[k])
3769 rate_val[k] |= NRATE_MCS_INUSE;
3771 rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]);
3773 /* (1) RATE: determine and validate primary rate and fallback rates */
3774 if (!RSPEC_ACTIVE(rspec[k])) {
3775 rspec[k] = WLC_RATE_1M;
3776 } else {
3777 if (!is_multicast_ether_addr(h->addr1)) {
3778 /* set tx antenna config */
3779 brcms_c_antsel_antcfg_get(wlc->asi, false,
3780 false, 0, 0, &antcfg, &fbantcfg);
3785 phyctl1_stf = wlc->stf->ss_opmode;
3787 if (N_ENAB(wlc->pub)) {
3788 for (k = 0; k < hw->max_rates; k++) {
3789 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
3790 if (((IS_MCS(rspec[k]) &&
3791 IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) ||
3792 IS_OFDM(rspec[k]))
3793 && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
3794 || !(rspec[k] & RSPEC_OVERRIDE))) {
3795 rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
3797 /* For SISO MCS use STBC if possible */
3798 if (IS_MCS(rspec[k])
3799 && WLC_STF_SS_STBC_TX(wlc, scb)) {
3800 u8 stc;
3802 stc = 1; /* Nss for single stream is always 1 */
3803 rspec[k] |=
3804 (PHY_TXC1_MODE_STBC <<
3805 RSPEC_STF_SHIFT) | (stc <<
3806 RSPEC_STC_SHIFT);
3807 } else
3808 rspec[k] |=
3809 (phyctl1_stf << RSPEC_STF_SHIFT);
3812 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
3813 if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) {
3814 /* default txbw is 20in40 SB */
3815 mimo_ctlchbw = mimo_txbw =
3816 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
3817 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
3819 if (IS_MCS(rspec[k])) {
3820 /* mcs 32 must be 40b/w DUP */
3821 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
3822 mimo_txbw =
3823 PHY_TXC1_BW_40MHZ_DUP;
3824 /* use override */
3825 } else if (wlc->mimo_40txbw != AUTO)
3826 mimo_txbw = wlc->mimo_40txbw;
3827 /* else check if dst is using 40 Mhz */
3828 else if (scb->flags & SCB_IS40)
3829 mimo_txbw = PHY_TXC1_BW_40MHZ;
3830 } else if (IS_OFDM(rspec[k])) {
3831 if (wlc->ofdm_40txbw != AUTO)
3832 mimo_txbw = wlc->ofdm_40txbw;
3833 } else {
3834 if (wlc->cck_40txbw != AUTO)
3835 mimo_txbw = wlc->cck_40txbw;
3837 } else {
3838 /* mcs32 is 40 b/w only.
3839 * This is possible for probe packets on a STA during SCAN
3841 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
3842 /* mcs 0 */
3843 rspec[k] = RSPEC_MIMORATE;
3845 mimo_txbw = PHY_TXC1_BW_20MHZ;
3848 /* Set channel width */
3849 rspec[k] &= ~RSPEC_BW_MASK;
3850 if ((k == 0) || ((k > 0) && IS_MCS(rspec[k])))
3851 rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT);
3852 else
3853 rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
3855 /* Set Short GI */
3856 #ifdef NOSGIYET
3857 if (IS_MCS(rspec[k])
3858 && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
3859 rspec[k] |= RSPEC_SHORT_GI;
3860 else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
3861 rspec[k] &= ~RSPEC_SHORT_GI;
3862 #else
3863 rspec[k] &= ~RSPEC_SHORT_GI;
3864 #endif
3866 mimo_preamble_type = WLC_MM_PREAMBLE;
3867 if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD)
3868 mimo_preamble_type = WLC_GF_PREAMBLE;
3870 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
3871 && (!IS_MCS(rspec[k]))) {
3872 wiphy_err(wlc->wiphy, "wl%d: %s: IEEE80211_TX_"
3873 "RC_MCS != IS_MCS(rspec)\n",
3874 WLCWLUNIT(wlc), __func__);
3877 if (IS_MCS(rspec[k])) {
3878 preamble_type[k] = mimo_preamble_type;
3880 /* if SGI is selected, then forced mm for single stream */
3881 if ((rspec[k] & RSPEC_SHORT_GI)
3882 && IS_SINGLE_STREAM(rspec[k] &
3883 RSPEC_RATE_MASK)) {
3884 preamble_type[k] = WLC_MM_PREAMBLE;
3888 /* should be better conditionalized */
3889 if (!IS_MCS(rspec[0])
3890 && (tx_info->control.rates[0].
3891 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
3892 preamble_type[k] = WLC_SHORT_PREAMBLE;
3894 } else {
3895 for (k = 0; k < hw->max_rates; k++) {
3896 /* Set ctrlchbw as 20Mhz */
3897 rspec[k] &= ~RSPEC_BW_MASK;
3898 rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
3900 /* for nphy, stf of ofdm frames must follow policies */
3901 if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) {
3902 rspec[k] &= ~RSPEC_STF_MASK;
3903 rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
3908 /* Reset these for use with AMPDU's */
3909 txrate[0]->count = 0;
3910 txrate[1]->count = 0;
3912 /* (2) PROTECTION, may change rspec */
3913 if ((ieee80211_is_data(h->frame_control) ||
3914 ieee80211_is_mgmt(h->frame_control)) &&
3915 (phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1))
3916 use_rts = true;
3918 /* (3) PLCP: determine PLCP header and MAC duration,
3919 * fill struct d11txh */
3920 brcms_c_compute_plcp(wlc, rspec[0], phylen, plcp);
3921 brcms_c_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
3922 memcpy(&txh->FragPLCPFallback,
3923 plcp_fallback, sizeof(txh->FragPLCPFallback));
3925 /* Length field now put in CCK FBR CRC field */
3926 if (IS_CCK(rspec[1])) {
3927 txh->FragPLCPFallback[4] = phylen & 0xff;
3928 txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
3931 /* MIMO-RATE: need validation ?? */
3932 mainrates = IS_OFDM(rspec[0]) ?
3933 D11A_PHY_HDR_GRATE((struct ofdm_phy_hdr *) plcp) :
3934 plcp[0];
3936 /* DUR field for main rate */
3937 if (!ieee80211_is_pspoll(h->frame_control) &&
3938 !is_multicast_ether_addr(h->addr1) && !use_rifs) {
3939 durid =
3940 brcms_c_compute_frame_dur(wlc, rspec[0], preamble_type[0],
3941 next_frag_len);
3942 h->duration_id = cpu_to_le16(durid);
3943 } else if (use_rifs) {
3944 /* NAV protect to end of next max packet size */
3945 durid =
3946 (u16) brcms_c_calc_frame_time(wlc, rspec[0],
3947 preamble_type[0],
3948 DOT11_MAX_FRAG_LEN);
3949 durid += RIFS_11N_TIME;
3950 h->duration_id = cpu_to_le16(durid);
3953 /* DUR field for fallback rate */
3954 if (ieee80211_is_pspoll(h->frame_control))
3955 txh->FragDurFallback = h->duration_id;
3956 else if (is_multicast_ether_addr(h->addr1) || use_rifs)
3957 txh->FragDurFallback = 0;
3958 else {
3959 durid = brcms_c_compute_frame_dur(wlc, rspec[1],
3960 preamble_type[1], next_frag_len);
3961 txh->FragDurFallback = cpu_to_le16(durid);
3964 /* (4) MAC-HDR: MacTxControlLow */
3965 if (frag == 0)
3966 mcl |= TXC_STARTMSDU;
3968 if (!is_multicast_ether_addr(h->addr1))
3969 mcl |= TXC_IMMEDACK;
3971 if (BAND_5G(wlc->band->bandtype))
3972 mcl |= TXC_FREQBAND_5G;
3974 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC))
3975 mcl |= TXC_BW_40;
3977 /* set AMIC bit if using hardware TKIP MIC */
3978 if (hwtkmic)
3979 mcl |= TXC_AMIC;
3981 txh->MacTxControlLow = cpu_to_le16(mcl);
3983 /* MacTxControlHigh */
3984 mch = 0;
3986 /* Set fallback rate preamble type */
3987 if ((preamble_type[1] == WLC_SHORT_PREAMBLE) ||
3988 (preamble_type[1] == WLC_GF_PREAMBLE)) {
3989 if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M)
3990 mch |= TXC_PREAMBLE_DATA_FB_SHORT;
3993 /* MacFrameControl */
3994 memcpy(&txh->MacFrameControl, &h->frame_control, sizeof(u16));
3995 txh->TxFesTimeNormal = cpu_to_le16(0);
3997 txh->TxFesTimeFallback = cpu_to_le16(0);
3999 /* TxFrameRA */
4000 memcpy(&txh->TxFrameRA, &h->addr1, ETH_ALEN);
4002 /* TxFrameID */
4003 txh->TxFrameID = cpu_to_le16(frameid);
4005 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
4006 * then we may need to reset the retry cnt's via the status reg
4008 txh->TxStatus = cpu_to_le16(status);
4010 /* extra fields for ucode AMPDU aggregation, the new fields are added to
4011 * the END of previous structure so that it's compatible in driver.
4013 txh->MaxNMpdus = cpu_to_le16(0);
4014 txh->MaxABytes_MRT = cpu_to_le16(0);
4015 txh->MaxABytes_FBR = cpu_to_le16(0);
4016 txh->MinMBytes = cpu_to_le16(0);
4018 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration,
4019 * furnish struct d11txh */
4020 /* RTS PLCP header and RTS frame */
4021 if (use_rts || use_cts) {
4022 if (use_rts && use_cts)
4023 use_cts = false;
4025 for (k = 0; k < 2; k++) {
4026 rts_rspec[k] = brcms_c_rspec_to_rts_rspec(wlc, rspec[k],
4027 false,
4028 mimo_ctlchbw);
4031 if (!IS_OFDM(rts_rspec[0]) &&
4032 !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) ||
4033 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
4034 rts_preamble_type[0] = WLC_SHORT_PREAMBLE;
4035 mch |= TXC_PREAMBLE_RTS_MAIN_SHORT;
4038 if (!IS_OFDM(rts_rspec[1]) &&
4039 !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) ||
4040 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
4041 rts_preamble_type[1] = WLC_SHORT_PREAMBLE;
4042 mch |= TXC_PREAMBLE_RTS_FB_SHORT;
4045 /* RTS/CTS additions to MacTxControlLow */
4046 if (use_cts) {
4047 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDCTS);
4048 } else {
4049 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDRTS);
4050 txh->MacTxControlLow |= cpu_to_le16(TXC_LONGFRAME);
4053 /* RTS PLCP header */
4054 rts_plcp = txh->RTSPhyHeader;
4055 if (use_cts)
4056 rts_phylen = DOT11_CTS_LEN + FCS_LEN;
4057 else
4058 rts_phylen = DOT11_RTS_LEN + FCS_LEN;
4060 brcms_c_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp);
4062 /* fallback rate version of RTS PLCP header */
4063 brcms_c_compute_plcp(wlc, rts_rspec[1], rts_phylen,
4064 rts_plcp_fallback);
4065 memcpy(&txh->RTSPLCPFallback, rts_plcp_fallback,
4066 sizeof(txh->RTSPLCPFallback));
4068 /* RTS frame fields... */
4069 rts = (struct ieee80211_rts *)&txh->rts_frame;
4071 durid = brcms_c_compute_rtscts_dur(wlc, use_cts, rts_rspec[0],
4072 rspec[0], rts_preamble_type[0],
4073 preamble_type[0], phylen, false);
4074 rts->duration = cpu_to_le16(durid);
4075 /* fallback rate version of RTS DUR field */
4076 durid = brcms_c_compute_rtscts_dur(wlc, use_cts,
4077 rts_rspec[1], rspec[1],
4078 rts_preamble_type[1],
4079 preamble_type[1], phylen, false);
4080 txh->RTSDurFallback = cpu_to_le16(durid);
4082 if (use_cts) {
4083 rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
4084 IEEE80211_STYPE_CTS);
4086 memcpy(&rts->ra, &h->addr2, ETH_ALEN);
4087 } else {
4088 rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
4089 IEEE80211_STYPE_RTS);
4091 memcpy(&rts->ra, &h->addr1, 2 * ETH_ALEN);
4094 /* mainrate
4095 * low 8 bits: main frag rate/mcs,
4096 * high 8 bits: rts/cts rate/mcs
4098 mainrates |= (IS_OFDM(rts_rspec[0]) ?
4099 D11A_PHY_HDR_GRATE(
4100 (struct ofdm_phy_hdr *) rts_plcp) :
4101 rts_plcp[0]) << 8;
4102 } else {
4103 memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN);
4104 memset((char *)&txh->rts_frame, 0,
4105 sizeof(struct ieee80211_rts));
4106 memset((char *)txh->RTSPLCPFallback, 0,
4107 sizeof(txh->RTSPLCPFallback));
4108 txh->RTSDurFallback = 0;
4111 #ifdef SUPPORT_40MHZ
4112 /* add null delimiter count */
4113 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) {
4114 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] =
4115 brcm_c_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen);
4117 #endif
4119 /* Now that RTS/RTS FB preamble types are updated, write the final value */
4120 txh->MacTxControlHigh = cpu_to_le16(mch);
4122 /* MainRates (both the rts and frag plcp rates have been calculated now) */
4123 txh->MainRates = cpu_to_le16(mainrates);
4125 /* XtraFrameTypes */
4126 xfts = FRAMETYPE(rspec[1], wlc->mimoft);
4127 xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT);
4128 xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT);
4129 xfts |=
4130 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT;
4131 txh->XtraFrameTypes = cpu_to_le16(xfts);
4133 /* PhyTxControlWord */
4134 phyctl = FRAMETYPE(rspec[0], wlc->mimoft);
4135 if ((preamble_type[0] == WLC_SHORT_PREAMBLE) ||
4136 (preamble_type[0] == WLC_GF_PREAMBLE)) {
4137 if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M)
4138 phyctl |= PHY_TXC_SHORT_HDR;
4141 /* phytxant is properly bit shifted */
4142 phyctl |= brcms_c_stf_d11hdrs_phyctl_txant(wlc, rspec[0]);
4143 txh->PhyTxControlWord = cpu_to_le16(phyctl);
4145 /* PhyTxControlWord_1 */
4146 if (WLC_PHY_11N_CAP(wlc->band)) {
4147 u16 phyctl1 = 0;
4149 phyctl1 = brcms_c_phytxctl1_calc(wlc, rspec[0]);
4150 txh->PhyTxControlWord_1 = cpu_to_le16(phyctl1);
4151 phyctl1 = brcms_c_phytxctl1_calc(wlc, rspec[1]);
4152 txh->PhyTxControlWord_1_Fbr = cpu_to_le16(phyctl1);
4154 if (use_rts || use_cts) {
4155 phyctl1 = brcms_c_phytxctl1_calc(wlc, rts_rspec[0]);
4156 txh->PhyTxControlWord_1_Rts = cpu_to_le16(phyctl1);
4157 phyctl1 = brcms_c_phytxctl1_calc(wlc, rts_rspec[1]);
4158 txh->PhyTxControlWord_1_FbrRts = cpu_to_le16(phyctl1);
4162 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
4163 * fill in non-zero MModeLen and/or MModeFbrLen
4164 * it will be unnecessary if they are separated
4166 if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) {
4167 u16 mmodelen =
4168 brcms_c_calc_lsig_len(wlc, rspec[0], phylen);
4169 txh->MModeLen = cpu_to_le16(mmodelen);
4172 if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) {
4173 u16 mmodefbrlen =
4174 brcms_c_calc_lsig_len(wlc, rspec[1], phylen);
4175 txh->MModeFbrLen = cpu_to_le16(mmodefbrlen);
4179 ac = skb_get_queue_mapping(p);
4180 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
4181 uint frag_dur, dur, dur_fallback;
4183 /* WME: Update TXOP threshold */
4184 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
4185 frag_dur =
4186 brcms_c_calc_frame_time(wlc, rspec[0],
4187 preamble_type[0], phylen);
4189 if (rts) {
4190 /* 1 RTS or CTS-to-self frame */
4191 dur =
4192 brcms_c_calc_cts_time(wlc, rts_rspec[0],
4193 rts_preamble_type[0]);
4194 dur_fallback =
4195 brcms_c_calc_cts_time(wlc, rts_rspec[1],
4196 rts_preamble_type[1]);
4197 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
4198 dur += le16_to_cpu(rts->duration);
4199 dur_fallback +=
4200 le16_to_cpu(txh->RTSDurFallback);
4201 } else if (use_rifs) {
4202 dur = frag_dur;
4203 dur_fallback = 0;
4204 } else {
4205 /* frame + SIFS + ACK */
4206 dur = frag_dur;
4207 dur +=
4208 brcms_c_compute_frame_dur(wlc, rspec[0],
4209 preamble_type[0], 0);
4211 dur_fallback =
4212 brcms_c_calc_frame_time(wlc, rspec[1],
4213 preamble_type[1],
4214 phylen);
4215 dur_fallback +=
4216 brcms_c_compute_frame_dur(wlc, rspec[1],
4217 preamble_type[1], 0);
4219 /* NEED to set TxFesTimeNormal (hard) */
4220 txh->TxFesTimeNormal = cpu_to_le16((u16) dur);
4221 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
4222 txh->TxFesTimeFallback =
4223 cpu_to_le16((u16) dur_fallback);
4225 /* update txop byte threshold (txop minus intraframe overhead) */
4226 if (wlc->edcf_txop[ac] >= (dur - frag_dur)) {
4228 uint newfragthresh;
4230 newfragthresh =
4231 brcms_c_calc_frame_len(wlc,
4232 rspec[0], preamble_type[0],
4233 (wlc->edcf_txop[ac] -
4234 (dur - frag_dur)));
4235 /* range bound the fragthreshold */
4236 if (newfragthresh < DOT11_MIN_FRAG_LEN)
4237 newfragthresh =
4238 DOT11_MIN_FRAG_LEN;
4239 else if (newfragthresh >
4240 wlc->usr_fragthresh)
4241 newfragthresh =
4242 wlc->usr_fragthresh;
4243 /* update the fragthresh and do txc update */
4244 if (wlc->fragthresh[queue] !=
4245 (u16) newfragthresh) {
4246 wlc->fragthresh[queue] =
4247 (u16) newfragthresh;
4250 } else
4251 wiphy_err(wlc->wiphy, "wl%d: %s txop invalid "
4252 "for rate %d\n",
4253 wlc->pub->unit, fifo_names[queue],
4254 RSPEC2RATE(rspec[0]));
4256 if (dur > wlc->edcf_txop[ac])
4257 wiphy_err(wlc->wiphy, "wl%d: %s: %s txop "
4258 "exceeded phylen %d/%d dur %d/%d\n",
4259 wlc->pub->unit, __func__,
4260 fifo_names[queue],
4261 phylen, wlc->fragthresh[queue],
4262 dur, wlc->edcf_txop[ac]);
4266 return 0;
4269 void brcms_c_tbtt(struct brcms_c_info *wlc)
4271 struct brcms_bss_cfg *cfg = wlc->cfg;
4273 if (!cfg->BSS) {
4274 /* DirFrmQ is now valid...defer setting until end of ATIM window */
4275 wlc->qvalid |= MCMD_DIRFRMQVAL;
4279 static void brcms_c_war16165(struct brcms_c_info *wlc, bool tx)
4281 if (tx) {
4282 /* the post-increment is used in STAY_AWAKE macro */
4283 if (wlc->txpend16165war++ == 0)
4284 brcms_c_set_ps_ctrl(wlc);
4285 } else {
4286 wlc->txpend16165war--;
4287 if (wlc->txpend16165war == 0)
4288 brcms_c_set_ps_ctrl(wlc);
4292 /* process an individual struct tx_status */
4293 /* WLC_HIGH_API */
4294 bool
4295 brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs, u32 frm_tx2)
4297 struct sk_buff *p;
4298 uint queue;
4299 struct d11txh *txh;
4300 struct scb *scb = NULL;
4301 bool free_pdu;
4302 int tx_rts, tx_frame_count, tx_rts_count;
4303 uint totlen, supr_status;
4304 bool lastframe;
4305 struct ieee80211_hdr *h;
4306 u16 mcl;
4307 struct ieee80211_tx_info *tx_info;
4308 struct ieee80211_tx_rate *txrate;
4309 int i;
4311 (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */
4313 /* discard intermediate indications for ucode with one legitimate case:
4314 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
4315 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
4316 * transmission count)
4318 if (!(txs->status & TX_STATUS_AMPDU)
4319 && (txs->status & TX_STATUS_INTERMEDIATE)) {
4320 wiphy_err(wlc->wiphy, "%s: INTERMEDIATE but not AMPDU\n",
4321 __func__);
4322 return false;
4325 queue = txs->frameid & TXFID_QUEUE_MASK;
4326 if (queue >= NFIFO) {
4327 p = NULL;
4328 goto fatal;
4331 p = GETNEXTTXP(wlc, queue);
4332 if (WLC_WAR16165(wlc))
4333 brcms_c_war16165(wlc, false);
4334 if (p == NULL)
4335 goto fatal;
4337 txh = (struct d11txh *) (p->data);
4338 mcl = le16_to_cpu(txh->MacTxControlLow);
4340 if (txs->phyerr) {
4341 if (WL_ERROR_ON()) {
4342 wiphy_err(wlc->wiphy, "phyerr 0x%x, rate 0x%x\n",
4343 txs->phyerr, txh->MainRates);
4344 brcms_c_print_txdesc(txh);
4346 brcms_c_print_txstatus(txs);
4349 if (txs->frameid != cpu_to_le16(txh->TxFrameID))
4350 goto fatal;
4351 tx_info = IEEE80211_SKB_CB(p);
4352 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
4354 if (tx_info->control.sta)
4355 scb = (struct scb *)tx_info->control.sta->drv_priv;
4357 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
4358 brcms_c_ampdu_dotxstatus(wlc->ampdu, scb, p, txs);
4359 return false;
4362 supr_status = txs->status & TX_STATUS_SUPR_MASK;
4363 if (supr_status == TX_STATUS_SUPR_BADCH)
4364 BCMMSG(wlc->wiphy,
4365 "%s: Pkt tx suppressed, possibly channel %d\n",
4366 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec));
4368 tx_rts = cpu_to_le16(txh->MacTxControlLow) & TXC_SENDRTS;
4369 tx_frame_count =
4370 (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT;
4371 tx_rts_count =
4372 (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT;
4374 lastframe = !ieee80211_has_morefrags(h->frame_control);
4376 if (!lastframe) {
4377 wiphy_err(wlc->wiphy, "Not last frame!\n");
4378 } else {
4380 * Set information to be consumed by Minstrel ht.
4382 * The "fallback limit" is the number of tx attempts a given
4383 * MPDU is sent at the "primary" rate. Tx attempts beyond that
4384 * limit are sent at the "secondary" rate.
4385 * A 'short frame' does not exceed RTS treshold.
4387 u16 sfbl, /* Short Frame Rate Fallback Limit */
4388 lfbl, /* Long Frame Rate Fallback Limit */
4389 fbl;
4391 if (queue < AC_COUNT) {
4392 sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]);
4393 lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]);
4394 } else {
4395 sfbl = wlc->SFBL;
4396 lfbl = wlc->LFBL;
4399 txrate = tx_info->status.rates;
4400 if (txrate[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
4401 fbl = lfbl;
4402 else
4403 fbl = sfbl;
4405 ieee80211_tx_info_clear_status(tx_info);
4407 if ((tx_frame_count > fbl) && (txrate[1].idx >= 0)) {
4408 /* rate selection requested a fallback rate and we used it */
4409 txrate[0].count = fbl;
4410 txrate[1].count = tx_frame_count - fbl;
4411 } else {
4412 /* rate selection did not request fallback rate, or we didn't need it */
4413 txrate[0].count = tx_frame_count;
4414 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
4415 txrate[1].idx = -1;
4416 txrate[1].count = 0;
4419 /* clear the rest of the rates */
4420 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
4421 txrate[i].idx = -1;
4422 txrate[i].count = 0;
4425 if (txs->status & TX_STATUS_ACK_RCV)
4426 tx_info->flags |= IEEE80211_TX_STAT_ACK;
4429 totlen = brcmu_pkttotlen(p);
4430 free_pdu = true;
4432 brcms_c_txfifo_complete(wlc, queue, 1);
4434 if (lastframe) {
4435 p->next = NULL;
4436 p->prev = NULL;
4437 /* remove PLCP & Broadcom tx descriptor header */
4438 skb_pull(p, D11_PHY_HDR_LEN);
4439 skb_pull(p, D11_TXH_LEN);
4440 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
4441 } else {
4442 wiphy_err(wlc->wiphy, "%s: Not last frame => not calling "
4443 "tx_status\n", __func__);
4446 return false;
4448 fatal:
4449 if (p)
4450 brcmu_pkt_buf_free_skb(p);
4452 return true;
4456 void
4457 brcms_c_txfifo_complete(struct brcms_c_info *wlc, uint fifo, s8 txpktpend)
4459 TXPKTPENDDEC(wlc, fifo, txpktpend);
4460 BCMMSG(wlc->wiphy, "pktpend dec %d to %d\n", txpktpend,
4461 TXPKTPENDGET(wlc, fifo));
4463 /* There is more room; mark precedences related to this FIFO sendable */
4464 WLC_TX_FIFO_ENAB(wlc, fifo);
4466 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
4467 if (AP_ENAB(wlc->pub) &&
4468 !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) {
4469 brcms_c_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO);
4472 /* figure out which bsscfg is being worked on... */
4475 /* Update beacon listen interval in shared memory */
4476 void brcms_c_bcn_li_upd(struct brcms_c_info *wlc)
4478 if (AP_ENAB(wlc->pub))
4479 return;
4481 /* wake up every DTIM is the default */
4482 if (wlc->bcn_li_dtim == 1)
4483 brcms_c_write_shm(wlc, M_BCN_LI, 0);
4484 else
4485 brcms_c_write_shm(wlc, M_BCN_LI,
4486 (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
4490 * recover 64bit TSF value from the 16bit TSF value in the rx header
4491 * given the assumption that the TSF passed in header is within 65ms
4492 * of the current tsf.
4494 * 6 5 4 4 3 2 1
4495 * 3.......6.......8.......0.......2.......4.......6.......8......0
4496 * |<---------- tsf_h ----------->||<--- tsf_l -->||<-RxTSFTime ->|
4498 * The RxTSFTime are the lowest 16 bits and provided by the ucode. The
4499 * tsf_l is filled in by brcms_b_recv, which is done earlier in the
4500 * receive call sequence after rx interrupt. Only the higher 16 bits
4501 * are used. Finally, the tsf_h is read from the tsf register.
4503 static u64 brcms_c_recover_tsf64(struct brcms_c_info *wlc,
4504 struct brcms_d11rxhdr *rxh)
4506 u32 tsf_h, tsf_l;
4507 u16 rx_tsf_0_15, rx_tsf_16_31;
4509 brcms_b_read_tsf(wlc->hw, &tsf_l, &tsf_h);
4511 rx_tsf_16_31 = (u16)(tsf_l >> 16);
4512 rx_tsf_0_15 = rxh->rxhdr.RxTSFTime;
4515 * a greater tsf time indicates the low 16 bits of
4516 * tsf_l wrapped, so decrement the high 16 bits.
4518 if ((u16)tsf_l < rx_tsf_0_15) {
4519 rx_tsf_16_31 -= 1;
4520 if (rx_tsf_16_31 == 0xffff)
4521 tsf_h -= 1;
4524 return ((u64)tsf_h << 32) | (((u32)rx_tsf_16_31 << 16) + rx_tsf_0_15);
4527 static void
4528 prep_mac80211_status(struct brcms_c_info *wlc, struct d11rxhdr *rxh,
4529 struct sk_buff *p,
4530 struct ieee80211_rx_status *rx_status)
4532 struct brcms_d11rxhdr *wlc_rxh = (struct brcms_d11rxhdr *) rxh;
4533 int preamble;
4534 int channel;
4535 ratespec_t rspec;
4536 unsigned char *plcp;
4538 /* fill in TSF and flag its presence */
4539 rx_status->mactime = brcms_c_recover_tsf64(wlc, wlc_rxh);
4540 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
4542 channel = WLC_CHAN_CHANNEL(rxh->RxChan);
4544 if (channel > 14) {
4545 rx_status->band = IEEE80211_BAND_5GHZ;
4546 rx_status->freq = ieee80211_ofdm_chan_to_freq(
4547 WF_CHAN_FACTOR_5_G/2, channel);
4549 } else {
4550 rx_status->band = IEEE80211_BAND_2GHZ;
4551 rx_status->freq = ieee80211_dsss_chan_to_freq(channel);
4554 rx_status->signal = wlc_rxh->rssi; /* signal */
4556 /* noise */
4557 /* qual */
4558 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
4560 plcp = p->data;
4562 rspec = brcms_c_compute_rspec(rxh, plcp);
4563 if (IS_MCS(rspec)) {
4564 rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
4565 rx_status->flag |= RX_FLAG_HT;
4566 if (RSPEC_IS40MHZ(rspec))
4567 rx_status->flag |= RX_FLAG_40MHZ;
4568 } else {
4569 switch (RSPEC2RATE(rspec)) {
4570 case WLC_RATE_1M:
4571 rx_status->rate_idx = 0;
4572 break;
4573 case WLC_RATE_2M:
4574 rx_status->rate_idx = 1;
4575 break;
4576 case WLC_RATE_5M5:
4577 rx_status->rate_idx = 2;
4578 break;
4579 case WLC_RATE_11M:
4580 rx_status->rate_idx = 3;
4581 break;
4582 case WLC_RATE_6M:
4583 rx_status->rate_idx = 4;
4584 break;
4585 case WLC_RATE_9M:
4586 rx_status->rate_idx = 5;
4587 break;
4588 case WLC_RATE_12M:
4589 rx_status->rate_idx = 6;
4590 break;
4591 case WLC_RATE_18M:
4592 rx_status->rate_idx = 7;
4593 break;
4594 case WLC_RATE_24M:
4595 rx_status->rate_idx = 8;
4596 break;
4597 case WLC_RATE_36M:
4598 rx_status->rate_idx = 9;
4599 break;
4600 case WLC_RATE_48M:
4601 rx_status->rate_idx = 10;
4602 break;
4603 case WLC_RATE_54M:
4604 rx_status->rate_idx = 11;
4605 break;
4606 default:
4607 wiphy_err(wlc->wiphy, "%s: Unknown rate\n", __func__);
4610 /* Determine short preamble and rate_idx */
4611 preamble = 0;
4612 if (IS_CCK(rspec)) {
4613 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
4614 rx_status->flag |= RX_FLAG_SHORTPRE;
4615 } else if (IS_OFDM(rspec)) {
4616 rx_status->flag |= RX_FLAG_SHORTPRE;
4617 } else {
4618 wiphy_err(wlc->wiphy, "%s: Unknown modulation\n",
4619 __func__);
4623 if (PLCP3_ISSGI(plcp[3]))
4624 rx_status->flag |= RX_FLAG_SHORT_GI;
4626 if (rxh->RxStatus1 & RXS_DECERR) {
4627 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
4628 wiphy_err(wlc->wiphy, "%s: RX_FLAG_FAILED_PLCP_CRC\n",
4629 __func__);
4631 if (rxh->RxStatus1 & RXS_FCSERR) {
4632 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
4633 wiphy_err(wlc->wiphy, "%s: RX_FLAG_FAILED_FCS_CRC\n",
4634 __func__);
4638 static void
4639 brcms_c_recvctl(struct brcms_c_info *wlc, struct d11rxhdr *rxh,
4640 struct sk_buff *p)
4642 int len_mpdu;
4643 struct ieee80211_rx_status rx_status;
4645 memset(&rx_status, 0, sizeof(rx_status));
4646 prep_mac80211_status(wlc, rxh, p, &rx_status);
4648 /* mac header+body length, exclude CRC and plcp header */
4649 len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN;
4650 skb_pull(p, D11_PHY_HDR_LEN);
4651 __skb_trim(p, len_mpdu);
4653 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
4654 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
4655 return;
4658 /* Process received frames */
4660 * Return true if more frames need to be processed. false otherwise.
4661 * Param 'bound' indicates max. # frames to process before break out.
4663 /* WLC_HIGH_API */
4664 void brcms_c_recv(struct brcms_c_info *wlc, struct sk_buff *p)
4666 struct d11rxhdr *rxh;
4667 struct ieee80211_hdr *h;
4668 uint len;
4669 bool is_amsdu;
4671 BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
4673 /* frame starts with rxhdr */
4674 rxh = (struct d11rxhdr *) (p->data);
4676 /* strip off rxhdr */
4677 skb_pull(p, WL_HWRXOFF);
4679 /* fixup rx header endianness */
4680 rxh->RxFrameSize = le16_to_cpu(rxh->RxFrameSize);
4681 rxh->PhyRxStatus_0 = le16_to_cpu(rxh->PhyRxStatus_0);
4682 rxh->PhyRxStatus_1 = le16_to_cpu(rxh->PhyRxStatus_1);
4683 rxh->PhyRxStatus_2 = le16_to_cpu(rxh->PhyRxStatus_2);
4684 rxh->PhyRxStatus_3 = le16_to_cpu(rxh->PhyRxStatus_3);
4685 rxh->PhyRxStatus_4 = le16_to_cpu(rxh->PhyRxStatus_4);
4686 rxh->PhyRxStatus_5 = le16_to_cpu(rxh->PhyRxStatus_5);
4687 rxh->RxStatus1 = le16_to_cpu(rxh->RxStatus1);
4688 rxh->RxStatus2 = le16_to_cpu(rxh->RxStatus2);
4689 rxh->RxTSFTime = le16_to_cpu(rxh->RxTSFTime);
4690 rxh->RxChan = le16_to_cpu(rxh->RxChan);
4692 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
4693 if (rxh->RxStatus1 & RXS_PBPRES) {
4694 if (p->len < 2) {
4695 wiphy_err(wlc->wiphy, "wl%d: recv: rcvd runt of "
4696 "len %d\n", wlc->pub->unit, p->len);
4697 goto toss;
4699 skb_pull(p, 2);
4702 h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN);
4703 len = p->len;
4705 if (rxh->RxStatus1 & RXS_FCSERR) {
4706 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
4707 wiphy_err(wlc->wiphy, "FCSERR while scanning******* -"
4708 " tossing\n");
4709 goto toss;
4710 } else {
4711 wiphy_err(wlc->wiphy, "RCSERR!!!\n");
4712 goto toss;
4716 /* check received pkt has at least frame control field */
4717 if (len < D11_PHY_HDR_LEN + sizeof(h->frame_control)) {
4718 goto toss;
4721 is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK;
4723 /* explicitly test bad src address to avoid sending bad deauth */
4724 if (!is_amsdu) {
4725 /* CTS and ACK CTL frames are w/o a2 */
4727 if (ieee80211_is_data(h->frame_control) ||
4728 ieee80211_is_mgmt(h->frame_control)) {
4729 if ((is_zero_ether_addr(h->addr2) ||
4730 is_multicast_ether_addr(h->addr2))) {
4731 wiphy_err(wlc->wiphy, "wl%d: %s: dropping a "
4732 "frame with invalid src mac address,"
4733 " a2: %pM\n",
4734 wlc->pub->unit, __func__, h->addr2);
4735 goto toss;
4740 /* due to sheer numbers, toss out probe reqs for now */
4741 if (ieee80211_is_probe_req(h->frame_control))
4742 goto toss;
4744 if (is_amsdu)
4745 goto toss;
4747 brcms_c_recvctl(wlc, rxh, p);
4748 return;
4750 toss:
4751 brcmu_pkt_buf_free_skb(p);
4754 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
4755 * number of bytes goes in the length field
4757 * Formula given by HT PHY Spec v 1.13
4758 * len = 3(nsyms + nstream + 3) - 3
4761 brcms_c_calc_lsig_len(struct brcms_c_info *wlc, ratespec_t ratespec,
4762 uint mac_len)
4764 uint nsyms, len = 0, kNdps;
4766 BCMMSG(wlc->wiphy, "wl%d: rate %d, len%d\n",
4767 wlc->pub->unit, RSPEC2RATE(ratespec), mac_len);
4769 if (IS_MCS(ratespec)) {
4770 uint mcs = ratespec & RSPEC_RATE_MASK;
4771 /* MCS_TXS(mcs) returns num tx streams - 1 */
4772 int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec);
4774 /* the payload duration calculation matches that of regular ofdm */
4775 /* 1000Ndbps = kbps * 4 */
4776 kNdps =
4777 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
4778 RSPEC_ISSGI(ratespec)) * 4;
4780 if (RSPEC_STC(ratespec) == 0)
4781 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
4782 nsyms =
4783 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
4784 APHY_TAIL_NBITS) * 1000, kNdps);
4785 else
4786 /* STBC needs to have even number of symbols */
4787 nsyms =
4789 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
4790 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
4792 nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
4793 /* 3 bytes/symbol @ legacy 6Mbps rate */
4794 len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */
4797 return (u16) len;
4800 /* calculate frame duration of a given rate and length, return time in usec unit */
4801 uint
4802 brcms_c_calc_frame_time(struct brcms_c_info *wlc, ratespec_t ratespec,
4803 u8 preamble_type, uint mac_len)
4805 uint nsyms, dur = 0, Ndps, kNdps;
4806 uint rate = RSPEC2RATE(ratespec);
4808 if (rate == 0) {
4809 wiphy_err(wlc->wiphy, "wl%d: WAR: using rate of 1 mbps\n",
4810 wlc->pub->unit);
4811 rate = WLC_RATE_1M;
4814 BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, preamble_type %d, len%d\n",
4815 wlc->pub->unit, ratespec, preamble_type, mac_len);
4817 if (IS_MCS(ratespec)) {
4818 uint mcs = ratespec & RSPEC_RATE_MASK;
4819 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
4821 dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
4822 if (preamble_type == WLC_MM_PREAMBLE)
4823 dur += PREN_MM_EXT;
4824 /* 1000Ndbps = kbps * 4 */
4825 kNdps =
4826 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
4827 RSPEC_ISSGI(ratespec)) * 4;
4829 if (RSPEC_STC(ratespec) == 0)
4830 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
4831 nsyms =
4832 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
4833 APHY_TAIL_NBITS) * 1000, kNdps);
4834 else
4835 /* STBC needs to have even number of symbols */
4836 nsyms =
4838 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
4839 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
4841 dur += APHY_SYMBOL_TIME * nsyms;
4842 if (BAND_2G(wlc->band->bandtype))
4843 dur += DOT11_OFDM_SIGNAL_EXTENSION;
4844 } else if (IS_OFDM(rate)) {
4845 dur = APHY_PREAMBLE_TIME;
4846 dur += APHY_SIGNAL_TIME;
4847 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
4848 Ndps = rate * 2;
4849 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
4850 nsyms =
4851 CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS),
4852 Ndps);
4853 dur += APHY_SYMBOL_TIME * nsyms;
4854 if (BAND_2G(wlc->band->bandtype))
4855 dur += DOT11_OFDM_SIGNAL_EXTENSION;
4856 } else {
4857 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
4858 mac_len = mac_len * 8 * 2;
4859 /* calc ceiling of bits/rate = microseconds of air time */
4860 dur = (mac_len + rate - 1) / rate;
4861 if (preamble_type & WLC_SHORT_PREAMBLE)
4862 dur += BPHY_PLCP_SHORT_TIME;
4863 else
4864 dur += BPHY_PLCP_TIME;
4866 return dur;
4869 /* The opposite of brcms_c_calc_frame_time */
4870 static uint
4871 brcms_c_calc_frame_len(struct brcms_c_info *wlc, ratespec_t ratespec,
4872 u8 preamble_type, uint dur)
4874 uint nsyms, mac_len, Ndps, kNdps;
4875 uint rate = RSPEC2RATE(ratespec);
4877 BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, preamble_type %d, dur %d\n",
4878 wlc->pub->unit, ratespec, preamble_type, dur);
4880 if (IS_MCS(ratespec)) {
4881 uint mcs = ratespec & RSPEC_RATE_MASK;
4882 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
4883 dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
4884 /* payload calculation matches that of regular ofdm */
4885 if (BAND_2G(wlc->band->bandtype))
4886 dur -= DOT11_OFDM_SIGNAL_EXTENSION;
4887 /* kNdbps = kbps * 4 */
4888 kNdps =
4889 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
4890 RSPEC_ISSGI(ratespec)) * 4;
4891 nsyms = dur / APHY_SYMBOL_TIME;
4892 mac_len =
4893 ((nsyms * kNdps) -
4894 ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000;
4895 } else if (IS_OFDM(ratespec)) {
4896 dur -= APHY_PREAMBLE_TIME;
4897 dur -= APHY_SIGNAL_TIME;
4898 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
4899 Ndps = rate * 2;
4900 nsyms = dur / APHY_SYMBOL_TIME;
4901 mac_len =
4902 ((nsyms * Ndps) -
4903 (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8;
4904 } else {
4905 if (preamble_type & WLC_SHORT_PREAMBLE)
4906 dur -= BPHY_PLCP_SHORT_TIME;
4907 else
4908 dur -= BPHY_PLCP_TIME;
4909 mac_len = dur * rate;
4910 /* divide out factor of 2 in rate (1/2 mbps) */
4911 mac_len = mac_len / 8 / 2;
4913 return mac_len;
4916 static uint
4917 brcms_c_calc_ba_time(struct brcms_c_info *wlc, ratespec_t rspec,
4918 u8 preamble_type)
4920 BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, "
4921 "preamble_type %d\n", wlc->pub->unit, rspec, preamble_type);
4922 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
4923 * or equal to the rate of the immediately previous frame in the FES
4925 rspec = WLC_BASIC_RATE(wlc, rspec);
4926 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
4927 return brcms_c_calc_frame_time(wlc, rspec, preamble_type,
4928 (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
4929 FCS_LEN));
4932 static uint
4933 brcms_c_calc_ack_time(struct brcms_c_info *wlc, ratespec_t rspec,
4934 u8 preamble_type)
4936 uint dur = 0;
4938 BCMMSG(wlc->wiphy, "wl%d: rspec 0x%x, preamble_type %d\n",
4939 wlc->pub->unit, rspec, preamble_type);
4940 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
4941 * or equal to the rate of the immediately previous frame in the FES
4943 rspec = WLC_BASIC_RATE(wlc, rspec);
4944 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
4945 dur =
4946 brcms_c_calc_frame_time(wlc, rspec, preamble_type,
4947 (DOT11_ACK_LEN + FCS_LEN));
4948 return dur;
4951 static uint
4952 brcms_c_calc_cts_time(struct brcms_c_info *wlc, ratespec_t rspec,
4953 u8 preamble_type)
4955 BCMMSG(wlc->wiphy, "wl%d: ratespec 0x%x, preamble_type %d\n",
4956 wlc->pub->unit, rspec, preamble_type);
4957 return brcms_c_calc_ack_time(wlc, rspec, preamble_type);
4960 /* derive wlc->band->basic_rate[] table from 'rateset' */
4961 void brcms_c_rate_lookup_init(struct brcms_c_info *wlc, wlc_rateset_t *rateset)
4963 u8 rate;
4964 u8 mandatory;
4965 u8 cck_basic = 0;
4966 u8 ofdm_basic = 0;
4967 u8 *br = wlc->band->basic_rate;
4968 uint i;
4970 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
4971 memset(br, 0, WLC_MAXRATE + 1);
4973 /* For each basic rate in the rates list, make an entry in the
4974 * best basic lookup.
4976 for (i = 0; i < rateset->count; i++) {
4977 /* only make an entry for a basic rate */
4978 if (!(rateset->rates[i] & WLC_RATE_FLAG))
4979 continue;
4981 /* mask off basic bit */
4982 rate = (rateset->rates[i] & WLC_RATE_MASK);
4984 if (rate > WLC_MAXRATE) {
4985 wiphy_err(wlc->wiphy, "brcms_c_rate_lookup_init: "
4986 "invalid rate 0x%X in rate set\n",
4987 rateset->rates[i]);
4988 continue;
4991 br[rate] = rate;
4994 /* The rate lookup table now has non-zero entries for each
4995 * basic rate, equal to the basic rate: br[basicN] = basicN
4997 * To look up the best basic rate corresponding to any
4998 * particular rate, code can use the basic_rate table
4999 * like this
5001 * basic_rate = wlc->band->basic_rate[tx_rate]
5003 * Make sure there is a best basic rate entry for
5004 * every rate by walking up the table from low rates
5005 * to high, filling in holes in the lookup table
5008 for (i = 0; i < wlc->band->hw_rateset.count; i++) {
5009 rate = wlc->band->hw_rateset.rates[i];
5011 if (br[rate] != 0) {
5012 /* This rate is a basic rate.
5013 * Keep track of the best basic rate so far by
5014 * modulation type.
5016 if (IS_OFDM(rate))
5017 ofdm_basic = rate;
5018 else
5019 cck_basic = rate;
5021 continue;
5024 /* This rate is not a basic rate so figure out the
5025 * best basic rate less than this rate and fill in
5026 * the hole in the table
5029 br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic;
5031 if (br[rate] != 0)
5032 continue;
5034 if (IS_OFDM(rate)) {
5035 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
5036 if (rate >= WLC_RATE_24M)
5037 mandatory = WLC_RATE_24M;
5038 else if (rate >= WLC_RATE_12M)
5039 mandatory = WLC_RATE_12M;
5040 else
5041 mandatory = WLC_RATE_6M;
5042 } else {
5043 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
5044 mandatory = rate;
5047 br[rate] = mandatory;
5051 static void brcms_c_write_rate_shm(struct brcms_c_info *wlc, u8 rate,
5052 u8 basic_rate)
5054 u8 phy_rate, index;
5055 u8 basic_phy_rate, basic_index;
5056 u16 dir_table, basic_table;
5057 u16 basic_ptr;
5059 /* Shared memory address for the table we are reading */
5060 dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
5062 /* Shared memory address for the table we are writing */
5063 basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
5066 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
5067 * the index into the rate table.
5069 phy_rate = rate_info[rate] & WLC_RATE_MASK;
5070 basic_phy_rate = rate_info[basic_rate] & WLC_RATE_MASK;
5071 index = phy_rate & 0xf;
5072 basic_index = basic_phy_rate & 0xf;
5074 /* Find the SHM pointer to the ACK rate entry by looking in the
5075 * Direct-map Table
5077 basic_ptr = brcms_c_read_shm(wlc, (dir_table + basic_index * 2));
5079 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
5080 * to the correct basic rate for the given incoming rate
5082 brcms_c_write_shm(wlc, (basic_table + index * 2), basic_ptr);
5085 static const wlc_rateset_t *brcms_c_rateset_get_hwrs(struct brcms_c_info *wlc)
5087 const wlc_rateset_t *rs_dflt;
5089 if (WLC_PHY_11N_CAP(wlc->band)) {
5090 if (BAND_5G(wlc->band->bandtype))
5091 rs_dflt = &ofdm_mimo_rates;
5092 else
5093 rs_dflt = &cck_ofdm_mimo_rates;
5094 } else if (wlc->band->gmode)
5095 rs_dflt = &cck_ofdm_rates;
5096 else
5097 rs_dflt = &cck_rates;
5099 return rs_dflt;
5102 void brcms_c_set_ratetable(struct brcms_c_info *wlc)
5104 const wlc_rateset_t *rs_dflt;
5105 wlc_rateset_t rs;
5106 u8 rate, basic_rate;
5107 uint i;
5109 rs_dflt = brcms_c_rateset_get_hwrs(wlc);
5111 brcms_c_rateset_copy(rs_dflt, &rs);
5112 brcms_c_rateset_mcs_upd(&rs, wlc->stf->txstreams);
5114 /* walk the phy rate table and update SHM basic rate lookup table */
5115 for (i = 0; i < rs.count; i++) {
5116 rate = rs.rates[i] & WLC_RATE_MASK;
5118 /* for a given rate WLC_BASIC_RATE returns the rate at
5119 * which a response ACK/CTS should be sent.
5121 basic_rate = WLC_BASIC_RATE(wlc, rate);
5122 if (basic_rate == 0) {
5123 /* This should only happen if we are using a
5124 * restricted rateset.
5126 basic_rate = rs.rates[0] & WLC_RATE_MASK;
5129 brcms_c_write_rate_shm(wlc, rate, basic_rate);
5134 * Return true if the specified rate is supported by the specified band.
5135 * WLC_BAND_AUTO indicates the current band.
5137 bool brcms_c_valid_rate(struct brcms_c_info *wlc, ratespec_t rspec, int band,
5138 bool verbose)
5140 wlc_rateset_t *hw_rateset;
5141 uint i;
5143 if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) {
5144 hw_rateset = &wlc->band->hw_rateset;
5145 } else if (NBANDS(wlc) > 1) {
5146 hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset;
5147 } else {
5148 /* other band specified and we are a single band device */
5149 return false;
5152 /* check if this is a mimo rate */
5153 if (IS_MCS(rspec)) {
5154 if (!VALID_MCS((rspec & RSPEC_RATE_MASK)))
5155 goto error;
5157 return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK));
5160 for (i = 0; i < hw_rateset->count; i++)
5161 if (hw_rateset->rates[i] == RSPEC2RATE(rspec))
5162 return true;
5163 error:
5164 if (verbose) {
5165 wiphy_err(wlc->wiphy, "wl%d: valid_rate: rate spec 0x%x "
5166 "not in hw_rateset\n", wlc->pub->unit, rspec);
5169 return false;
5172 static void brcms_c_update_mimo_band_bwcap(struct brcms_c_info *wlc, u8 bwcap)
5174 uint i;
5175 struct brcms_band *band;
5177 for (i = 0; i < NBANDS(wlc); i++) {
5178 if (IS_SINGLEBAND_5G(wlc->deviceid))
5179 i = BAND_5G_INDEX;
5180 band = wlc->bandstate[i];
5181 if (band->bandtype == WLC_BAND_5G) {
5182 if ((bwcap == WLC_N_BW_40ALL)
5183 || (bwcap == WLC_N_BW_20IN2G_40IN5G))
5184 band->mimo_cap_40 = true;
5185 else
5186 band->mimo_cap_40 = false;
5187 } else {
5188 if (bwcap == WLC_N_BW_40ALL)
5189 band->mimo_cap_40 = true;
5190 else
5191 band->mimo_cap_40 = false;
5196 void brcms_c_mod_prb_rsp_rate_table(struct brcms_c_info *wlc, uint frame_len)
5198 const wlc_rateset_t *rs_dflt;
5199 wlc_rateset_t rs;
5200 u8 rate;
5201 u16 entry_ptr;
5202 u8 plcp[D11_PHY_HDR_LEN];
5203 u16 dur, sifs;
5204 uint i;
5206 sifs = SIFS(wlc->band);
5208 rs_dflt = brcms_c_rateset_get_hwrs(wlc);
5210 brcms_c_rateset_copy(rs_dflt, &rs);
5211 brcms_c_rateset_mcs_upd(&rs, wlc->stf->txstreams);
5213 /* walk the phy rate table and update MAC core SHM basic rate table entries */
5214 for (i = 0; i < rs.count; i++) {
5215 rate = rs.rates[i] & WLC_RATE_MASK;
5217 entry_ptr = brcms_c_rate_shm_offset(wlc, rate);
5219 /* Calculate the Probe Response PLCP for the given rate */
5220 brcms_c_compute_plcp(wlc, rate, frame_len, plcp);
5222 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
5223 dur =
5224 (u16) brcms_c_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE,
5225 frame_len);
5226 dur += sifs;
5228 /* Update the SHM Rate Table entry Probe Response values */
5229 brcms_c_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS,
5230 (u16) (plcp[0] + (plcp[1] << 8)));
5231 brcms_c_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2,
5232 (u16) (plcp[2] + (plcp[3] << 8)));
5233 brcms_c_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur);
5237 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
5239 * PLCP header is 6 bytes.
5240 * 802.11 A3 header is 24 bytes.
5241 * Max beacon frame body template length is 112 bytes.
5242 * Max probe resp frame body template length is 110 bytes.
5244 * *len on input contains the max length of the packet available.
5246 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
5247 * and included up to, but not including, the 4 byte FCS.
5249 static void
5250 brcms_c_bcn_prb_template(struct brcms_c_info *wlc, u16 type,
5251 ratespec_t bcn_rspec,
5252 struct brcms_bss_cfg *cfg, u16 *buf, int *len)
5254 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
5255 struct cck_phy_hdr *plcp;
5256 struct ieee80211_mgmt *h;
5257 int hdr_len, body_len;
5259 if (MBSS_BCN_ENAB(cfg) && type == IEEE80211_STYPE_BEACON)
5260 hdr_len = DOT11_MAC_HDR_LEN;
5261 else
5262 hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN;
5263 body_len = *len - hdr_len; /* calc buffer size provided for frame body */
5265 *len = hdr_len + body_len; /* return actual size */
5267 /* format PHY and MAC headers */
5268 memset((char *)buf, 0, hdr_len);
5270 plcp = (struct cck_phy_hdr *) buf;
5272 /* PLCP for Probe Response frames are filled in from core's rate table */
5273 if (type == IEEE80211_STYPE_BEACON && !MBSS_BCN_ENAB(cfg)) {
5274 /* fill in PLCP */
5275 brcms_c_compute_plcp(wlc, bcn_rspec,
5276 (DOT11_MAC_HDR_LEN + body_len + FCS_LEN),
5277 (u8 *) plcp);
5280 /* "Regular" and 16 MBSS but not for 4 MBSS */
5281 /* Update the phytxctl for the beacon based on the rspec */
5282 if (!SOFTBCN_ENAB(cfg))
5283 brcms_c_beacon_phytxctl_txant_upd(wlc, bcn_rspec);
5285 if (MBSS_BCN_ENAB(cfg) && type == IEEE80211_STYPE_BEACON)
5286 h = (struct ieee80211_mgmt *)&plcp[0];
5287 else
5288 h = (struct ieee80211_mgmt *)&plcp[1];
5290 /* fill in 802.11 header */
5291 h->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | type);
5293 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
5294 /* A1 filled in by MAC for prb resp, broadcast for bcn */
5295 if (type == IEEE80211_STYPE_BEACON)
5296 memcpy(&h->da, &ether_bcast, ETH_ALEN);
5297 memcpy(&h->sa, &cfg->cur_etheraddr, ETH_ALEN);
5298 memcpy(&h->bssid, &cfg->BSSID, ETH_ALEN);
5300 /* SEQ filled in by MAC */
5302 return;
5305 int brcms_c_get_header_len()
5307 return TXOFF;
5310 /* Update a beacon for a particular BSS
5311 * For MBSS, this updates the software template and sets "latest" to the index of the
5312 * template updated.
5313 * Otherwise, it updates the hardware template.
5315 void brcms_c_bss_update_beacon(struct brcms_c_info *wlc,
5316 struct brcms_bss_cfg *cfg)
5318 int len = BCN_TMPL_LEN;
5320 /* Clear the soft intmask */
5321 wlc->defmacintmask &= ~MI_BCNTPL;
5323 if (!cfg->up) { /* Only allow updates on an UP bss */
5324 return;
5327 /* Optimize: Some of if/else could be combined */
5328 if (!MBSS_BCN_ENAB(cfg) && HWBCN_ENAB(cfg)) {
5329 /* Hardware beaconing for this config */
5330 u16 bcn[BCN_TMPL_LEN / 2];
5331 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
5332 d11regs_t *regs = wlc->regs;
5334 /* Check if both templates are in use, if so sched. an interrupt
5335 * that will call back into this routine
5337 if ((R_REG(&regs->maccommand) & both_valid) == both_valid) {
5338 /* clear any previous status */
5339 W_REG(&regs->macintstatus, MI_BCNTPL);
5341 /* Check that after scheduling the interrupt both of the
5342 * templates are still busy. if not clear the int. & remask
5344 if ((R_REG(&regs->maccommand) & both_valid) == both_valid) {
5345 wlc->defmacintmask |= MI_BCNTPL;
5346 return;
5349 wlc->bcn_rspec =
5350 brcms_c_lowest_basic_rspec(wlc, &cfg->current_bss->rateset);
5351 /* update the template and ucode shm */
5352 brcms_c_bcn_prb_template(wlc, IEEE80211_STYPE_BEACON,
5353 wlc->bcn_rspec, cfg, bcn, &len);
5354 brcms_c_write_hw_bcntemplates(wlc, bcn, len, false);
5359 * Update all beacons for the system.
5361 void brcms_c_update_beacon(struct brcms_c_info *wlc)
5363 int idx;
5364 struct brcms_bss_cfg *bsscfg;
5366 /* update AP or IBSS beacons */
5367 FOREACH_BSS(wlc, idx, bsscfg) {
5368 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
5369 brcms_c_bss_update_beacon(wlc, bsscfg);
5373 /* Write ssid into shared memory */
5374 void brcms_c_shm_ssid_upd(struct brcms_c_info *wlc, struct brcms_bss_cfg *cfg)
5376 u8 *ssidptr = cfg->SSID;
5377 u16 base = M_SSID;
5378 u8 ssidbuf[IEEE80211_MAX_SSID_LEN];
5380 /* padding the ssid with zero and copy it into shm */
5381 memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN);
5382 memcpy(ssidbuf, ssidptr, cfg->SSID_len);
5384 brcms_c_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN);
5386 if (!MBSS_BCN_ENAB(cfg))
5387 brcms_c_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len);
5390 void brcms_c_update_probe_resp(struct brcms_c_info *wlc, bool suspend)
5392 int idx;
5393 struct brcms_bss_cfg *bsscfg;
5395 /* update AP or IBSS probe responses */
5396 FOREACH_BSS(wlc, idx, bsscfg) {
5397 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
5398 brcms_c_bss_update_probe_resp(wlc, bsscfg, suspend);
5402 void
5403 brcms_c_bss_update_probe_resp(struct brcms_c_info *wlc,
5404 struct brcms_bss_cfg *cfg,
5405 bool suspend)
5407 u16 prb_resp[BCN_TMPL_LEN / 2];
5408 int len = BCN_TMPL_LEN;
5410 /* write the probe response to hardware, or save in the config structure */
5411 if (!MBSS_PRB_ENAB(cfg)) {
5413 /* create the probe response template */
5414 brcms_c_bcn_prb_template(wlc, IEEE80211_STYPE_PROBE_RESP, 0,
5415 cfg, prb_resp, &len);
5417 if (suspend)
5418 brcms_c_suspend_mac_and_wait(wlc);
5420 /* write the probe response into the template region */
5421 brcms_b_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
5422 (len + 3) & ~3, prb_resp);
5424 /* write the length of the probe response frame (+PLCP/-FCS) */
5425 brcms_c_write_shm(wlc, M_PRB_RESP_FRM_LEN, (u16) len);
5427 /* write the SSID and SSID length */
5428 brcms_c_shm_ssid_upd(wlc, cfg);
5431 * Write PLCP headers and durations for probe response frames at all rates.
5432 * Use the actual frame length covered by the PLCP header for the call to
5433 * brcms_c_mod_prb_rsp_rate_table() by subtracting the PLCP len
5434 * and adding the FCS.
5436 len += (-D11_PHY_HDR_LEN + FCS_LEN);
5437 brcms_c_mod_prb_rsp_rate_table(wlc, (u16) len);
5439 if (suspend)
5440 brcms_c_enable_mac(wlc);
5441 } else { /* Generating probe resp in sw; update local template */
5442 /* error: No software probe response support without MBSS */
5446 /* prepares pdu for transmission. returns BCM error codes */
5447 int brcms_c_prep_pdu(struct brcms_c_info *wlc, struct sk_buff *pdu, uint *fifop)
5449 uint fifo;
5450 struct d11txh *txh;
5451 struct ieee80211_hdr *h;
5452 struct scb *scb;
5454 txh = (struct d11txh *) (pdu->data);
5455 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
5457 /* get the pkt queue info. This was put at brcms_c_sendctl or
5458 * brcms_c_send for PDU */
5459 fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
5461 scb = NULL;
5463 *fifop = fifo;
5465 /* return if insufficient dma resources */
5466 if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) {
5467 /* Mark precedences related to this FIFO, unsendable */
5468 WLC_TX_FIFO_CLEAR(wlc, fifo);
5469 return -EBUSY;
5471 return 0;
5474 /* init tx reported rate mechanism */
5475 void brcms_c_reprate_init(struct brcms_c_info *wlc)
5477 int i;
5478 struct brcms_bss_cfg *bsscfg;
5480 FOREACH_BSS(wlc, i, bsscfg) {
5481 brcms_c_bsscfg_reprate_init(bsscfg);
5485 /* per bsscfg init tx reported rate mechanism */
5486 void brcms_c_bsscfg_reprate_init(struct brcms_bss_cfg *bsscfg)
5488 bsscfg->txrspecidx = 0;
5489 memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec));
5492 void brcms_default_rateset(struct brcms_c_info *wlc, wlc_rateset_t *rs)
5494 brcms_c_rateset_default(rs, NULL, wlc->band->phytype,
5495 wlc->band->bandtype, false, WLC_RATE_MASK_FULL,
5496 (bool) N_ENAB(wlc->pub),
5497 CHSPEC_WLC_BW(wlc->default_bss->chanspec),
5498 wlc->stf->txstreams);
5501 static void brcms_c_bss_default_init(struct brcms_c_info *wlc)
5503 chanspec_t chanspec;
5504 struct brcms_band *band;
5505 struct brcms_bss_info *bi = wlc->default_bss;
5507 /* init default and target BSS with some sane initial values */
5508 memset((char *)(bi), 0, sizeof(struct brcms_bss_info));
5509 bi->beacon_period = BEACON_INTERVAL_DEFAULT;
5510 bi->dtim_period = DTIM_INTERVAL_DEFAULT;
5512 /* fill the default channel as the first valid channel
5513 * starting from the 2G channels
5515 chanspec = CH20MHZ_CHSPEC(1);
5516 wlc->home_chanspec = bi->chanspec = chanspec;
5518 /* find the band of our default channel */
5519 band = wlc->band;
5520 if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec))
5521 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
5523 /* init bss rates to the band specific default rate set */
5524 brcms_c_rateset_default(&bi->rateset, NULL, band->phytype,
5525 band->bandtype, false, WLC_RATE_MASK_FULL,
5526 (bool) N_ENAB(wlc->pub), CHSPEC_WLC_BW(chanspec),
5527 wlc->stf->txstreams);
5529 if (N_ENAB(wlc->pub))
5530 bi->flags |= WLC_BSS_HT;
5533 static ratespec_t
5534 mac80211_wlc_set_nrate(struct brcms_c_info *wlc, struct brcms_band *cur_band,
5535 u32 int_val)
5537 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
5538 u8 rate = int_val & NRATE_RATE_MASK;
5539 ratespec_t rspec;
5540 bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE);
5541 bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT);
5542 bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY)
5543 == NRATE_OVERRIDE_MCS_ONLY);
5544 int bcmerror = 0;
5546 if (!ismcs) {
5547 return (ratespec_t) rate;
5550 /* validate the combination of rate/mcs/stf is allowed */
5551 if (N_ENAB(wlc->pub) && ismcs) {
5552 /* mcs only allowed when nmode */
5553 if (stf > PHY_TXC1_MODE_SDM) {
5554 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid stf\n",
5555 WLCWLUNIT(wlc), __func__);
5556 bcmerror = -EINVAL;
5557 goto done;
5560 /* mcs 32 is a special case, DUP mode 40 only */
5561 if (rate == 32) {
5562 if (!CHSPEC_IS40(wlc->home_chanspec) ||
5563 ((stf != PHY_TXC1_MODE_SISO)
5564 && (stf != PHY_TXC1_MODE_CDD))) {
5565 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid mcs "
5566 "32\n", WLCWLUNIT(wlc), __func__);
5567 bcmerror = -EINVAL;
5568 goto done;
5570 /* mcs > 7 must use stf SDM */
5571 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
5572 /* mcs > 7 must use stf SDM */
5573 if (stf != PHY_TXC1_MODE_SDM) {
5574 BCMMSG(wlc->wiphy, "wl%d: enabling "
5575 "SDM mode for mcs %d\n",
5576 WLCWLUNIT(wlc), rate);
5577 stf = PHY_TXC1_MODE_SDM;
5579 } else {
5580 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
5581 if ((stf > PHY_TXC1_MODE_STBC) ||
5582 (!WLC_STBC_CAP_PHY(wlc)
5583 && (stf == PHY_TXC1_MODE_STBC))) {
5584 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid STBC"
5585 "\n", WLCWLUNIT(wlc), __func__);
5586 bcmerror = -EINVAL;
5587 goto done;
5590 } else if (IS_OFDM(rate)) {
5591 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
5592 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid OFDM\n",
5593 WLCWLUNIT(wlc), __func__);
5594 bcmerror = -EINVAL;
5595 goto done;
5597 } else if (IS_CCK(rate)) {
5598 if ((cur_band->bandtype != WLC_BAND_2G)
5599 || (stf != PHY_TXC1_MODE_SISO)) {
5600 wiphy_err(wlc->wiphy, "wl%d: %s: Invalid CCK\n",
5601 WLCWLUNIT(wlc), __func__);
5602 bcmerror = -EINVAL;
5603 goto done;
5605 } else {
5606 wiphy_err(wlc->wiphy, "wl%d: %s: Unknown rate type\n",
5607 WLCWLUNIT(wlc), __func__);
5608 bcmerror = -EINVAL;
5609 goto done;
5611 /* make sure multiple antennae are available for non-siso rates */
5612 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
5613 wiphy_err(wlc->wiphy, "wl%d: %s: SISO antenna but !SISO "
5614 "request\n", WLCWLUNIT(wlc), __func__);
5615 bcmerror = -EINVAL;
5616 goto done;
5619 rspec = rate;
5620 if (ismcs) {
5621 rspec |= RSPEC_MIMORATE;
5622 /* For STBC populate the STC field of the ratespec */
5623 if (stf == PHY_TXC1_MODE_STBC) {
5624 u8 stc;
5625 stc = 1; /* Nss for single stream is always 1 */
5626 rspec |= (stc << RSPEC_STC_SHIFT);
5630 rspec |= (stf << RSPEC_STF_SHIFT);
5632 if (override_mcs_only)
5633 rspec |= RSPEC_OVERRIDE_MCS_ONLY;
5635 if (issgi)
5636 rspec |= RSPEC_SHORT_GI;
5638 if ((rate != 0)
5639 && !brcms_c_valid_rate(wlc, rspec, cur_band->bandtype, true)) {
5640 return rate;
5643 return rspec;
5644 done:
5645 return rate;
5648 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
5649 static int
5650 brcms_c_duty_cycle_set(struct brcms_c_info *wlc, int duty_cycle, bool isOFDM,
5651 bool writeToShm)
5653 int idle_busy_ratio_x_16 = 0;
5654 uint offset =
5655 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
5656 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
5657 if (duty_cycle > 100 || duty_cycle < 0) {
5658 wiphy_err(wlc->wiphy, "wl%d: duty cycle value off limit\n",
5659 wlc->pub->unit);
5660 return -EINVAL;
5662 if (duty_cycle)
5663 idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle;
5664 /* Only write to shared memory when wl is up */
5665 if (writeToShm)
5666 brcms_c_write_shm(wlc, offset, (u16) idle_busy_ratio_x_16);
5668 if (isOFDM)
5669 wlc->tx_duty_cycle_ofdm = (u16) duty_cycle;
5670 else
5671 wlc->tx_duty_cycle_cck = (u16) duty_cycle;
5673 return 0;
5676 /* Read a single u16 from shared memory.
5677 * SHM 'offset' needs to be an even address
5679 u16 brcms_c_read_shm(struct brcms_c_info *wlc, uint offset)
5681 return brcms_b_read_shm(wlc->hw, offset);
5684 /* Write a single u16 to shared memory.
5685 * SHM 'offset' needs to be an even address
5687 void brcms_c_write_shm(struct brcms_c_info *wlc, uint offset, u16 v)
5689 brcms_b_write_shm(wlc->hw, offset, v);
5692 /* Copy a buffer to shared memory.
5693 * SHM 'offset' needs to be an even address and
5694 * Buffer length 'len' must be an even number of bytes
5696 void brcms_c_copyto_shm(struct brcms_c_info *wlc, uint offset, const void *buf,
5697 int len)
5699 /* offset and len need to be even */
5700 if (len <= 0 || (offset & 1) || (len & 1))
5701 return;
5703 brcms_b_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
5707 /* wrapper BMAC functions to for HIGH driver access */
5708 void brcms_c_mctrl(struct brcms_c_info *wlc, u32 mask, u32 val)
5710 brcms_b_mctrl(wlc->hw, mask, val);
5713 void brcms_c_mhf(struct brcms_c_info *wlc, u8 idx, u16 mask, u16 val, int bands)
5715 brcms_b_mhf(wlc->hw, idx, mask, val, bands);
5718 int brcms_c_xmtfifo_sz_get(struct brcms_c_info *wlc, uint fifo, uint *blocks)
5720 return brcms_b_xmtfifo_sz_get(wlc->hw, fifo, blocks);
5723 void brcms_c_write_template_ram(struct brcms_c_info *wlc, int offset, int len,
5724 void *buf)
5726 brcms_b_write_template_ram(wlc->hw, offset, len, buf);
5729 void brcms_c_write_hw_bcntemplates(struct brcms_c_info *wlc, void *bcn, int len,
5730 bool both)
5732 brcms_b_write_hw_bcntemplates(wlc->hw, bcn, len, both);
5735 void
5736 brcms_c_set_addrmatch(struct brcms_c_info *wlc, int match_reg_offset,
5737 const u8 *addr)
5739 brcms_b_set_addrmatch(wlc->hw, match_reg_offset, addr);
5740 if (match_reg_offset == RCM_BSSID_OFFSET)
5741 memcpy(wlc->cfg->BSSID, addr, ETH_ALEN);
5744 void brcms_c_pllreq(struct brcms_c_info *wlc, bool set, mbool req_bit)
5746 brcms_b_pllreq(wlc->hw, set, req_bit);
5749 void brcms_c_reset_bmac_done(struct brcms_c_info *wlc)
5753 /* check for the particular priority flow control bit being set */
5754 bool
5755 brcms_c_txflowcontrol_prio_isset(struct brcms_c_info *wlc,
5756 struct brcms_txq_info *q,
5757 int prio)
5759 uint prio_mask;
5761 if (prio == ALLPRIO) {
5762 prio_mask = TXQ_STOP_FOR_PRIOFC_MASK;
5763 } else {
5764 prio_mask = NBITVAL(prio);
5767 return (q->stopped & prio_mask) == prio_mask;
5770 /* propagate the flow control to all interfaces using the given tx queue */
5771 void brcms_c_txflowcontrol(struct brcms_c_info *wlc,
5772 struct brcms_txq_info *qi,
5773 bool on, int prio)
5775 uint prio_bits;
5776 uint cur_bits;
5778 BCMMSG(wlc->wiphy, "flow control kicks in\n");
5780 if (prio == ALLPRIO) {
5781 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
5782 } else {
5783 prio_bits = NBITVAL(prio);
5786 cur_bits = qi->stopped & prio_bits;
5788 /* Check for the case of no change and return early
5789 * Otherwise update the bit and continue
5791 if (on) {
5792 if (cur_bits == prio_bits) {
5793 return;
5795 mboolset(qi->stopped, prio_bits);
5796 } else {
5797 if (cur_bits == 0) {
5798 return;
5800 mboolclr(qi->stopped, prio_bits);
5803 /* If there is a flow control override we will not change the external
5804 * flow control state.
5806 if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) {
5807 return;
5810 brcms_c_txflowcontrol_signal(wlc, qi, on, prio);
5813 void
5814 brcms_c_txflowcontrol_override(struct brcms_c_info *wlc,
5815 struct brcms_txq_info *qi,
5816 bool on, uint override)
5818 uint prev_override;
5820 prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK);
5822 /* Update the flow control bits and do an early return if there is
5823 * no change in the external flow control state.
5825 if (on) {
5826 mboolset(qi->stopped, override);
5827 /* if there was a previous override bit on, then setting this
5828 * makes no difference.
5830 if (prev_override) {
5831 return;
5834 brcms_c_txflowcontrol_signal(wlc, qi, ON, ALLPRIO);
5835 } else {
5836 mboolclr(qi->stopped, override);
5837 /* clearing an override bit will only make a difference for
5838 * flow control if it was the only bit set. For any other
5839 * override setting, just return
5841 if (prev_override != override) {
5842 return;
5845 if (qi->stopped == 0) {
5846 brcms_c_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
5847 } else {
5848 int prio;
5850 for (prio = MAXPRIO; prio >= 0; prio--) {
5851 if (!mboolisset(qi->stopped, NBITVAL(prio)))
5852 brcms_c_txflowcontrol_signal(
5853 wlc, qi, OFF, prio);
5859 static void brcms_c_txflowcontrol_reset(struct brcms_c_info *wlc)
5861 struct brcms_txq_info *qi;
5863 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
5864 if (qi->stopped) {
5865 brcms_c_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
5866 qi->stopped = 0;
5871 static void
5872 brcms_c_txflowcontrol_signal(struct brcms_c_info *wlc,
5873 struct brcms_txq_info *qi, bool on, int prio)
5875 #ifdef NON_FUNCTIONAL
5876 /* wlcif_list is never filled so this function is not functional */
5877 struct brcms_c_if *wlcif;
5879 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
5880 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
5881 brcms_txflowcontrol(wlc->wl, wlcif->wlif, on, prio);
5883 #endif
5886 static struct brcms_txq_info *brcms_c_txq_alloc(struct brcms_c_info *wlc)
5888 struct brcms_txq_info *qi, *p;
5890 qi = kzalloc(sizeof(struct brcms_txq_info), GFP_ATOMIC);
5891 if (qi != NULL) {
5893 * Have enough room for control packets along with HI watermark
5894 * Also, add room to txq for total psq packets if all the SCBs
5895 * leave PS mode. The watermark for flowcontrol to OS packets
5896 * will remain the same
5898 brcmu_pktq_init(&qi->q, WLC_PREC_COUNT,
5899 (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT
5900 + wlc->pub->psq_pkts_total);
5902 /* add this queue to the the global list */
5903 p = wlc->tx_queues;
5904 if (p == NULL) {
5905 wlc->tx_queues = qi;
5906 } else {
5907 while (p->next != NULL)
5908 p = p->next;
5909 p->next = qi;
5912 return qi;
5915 static void brcms_c_txq_free(struct brcms_c_info *wlc,
5916 struct brcms_txq_info *qi)
5918 struct brcms_txq_info *p;
5920 if (qi == NULL)
5921 return;
5923 /* remove the queue from the linked list */
5924 p = wlc->tx_queues;
5925 if (p == qi)
5926 wlc->tx_queues = p->next;
5927 else {
5928 while (p != NULL && p->next != qi)
5929 p = p->next;
5930 if (p != NULL)
5931 p->next = p->next->next;
5934 kfree(qi);
5938 * Flag 'scan in progress' to withhold dynamic phy calibration
5940 void brcms_c_scan_start(struct brcms_c_info *wlc)
5942 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, true);
5945 void brcms_c_scan_stop(struct brcms_c_info *wlc)
5947 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, false);
5950 void brcms_c_associate_upd(struct brcms_c_info *wlc, bool state)
5952 wlc->pub->associated = state;
5953 wlc->cfg->associated = state;
5957 * When a remote STA/AP is removed by Mac80211, or when it can no longer accept
5958 * AMPDU traffic, packets pending in hardware have to be invalidated so that
5959 * when later on hardware releases them, they can be handled appropriately.
5961 void brcms_c_inval_dma_pkts(struct brcms_hardware *hw,
5962 struct ieee80211_sta *sta,
5963 void (*dma_callback_fn))
5965 struct dma_pub *dmah;
5966 int i;
5967 for (i = 0; i < NFIFO; i++) {
5968 dmah = hw->di[i];
5969 if (dmah != NULL)
5970 dma_walk_packets(dmah, dma_callback_fn, sta);
5974 int brcms_c_get_curband(struct brcms_c_info *wlc)
5976 return wlc->band->bandunit;
5979 void brcms_c_wait_for_tx_completion(struct brcms_c_info *wlc, bool drop)
5981 /* flush packet queue when requested */
5982 if (drop)
5983 brcmu_pktq_flush(&wlc->pkt_queue->q, false, NULL, NULL);
5985 /* wait for queue and DMA fifos to run dry */
5986 while (!pktq_empty(&wlc->pkt_queue->q) ||
5987 TXPKTPENDTOT(wlc) > 0) {
5988 brcms_msleep(wlc->wl, 1);
5992 int brcms_c_set_par(struct brcms_c_info *wlc, enum wlc_par_id par_id,
5993 int int_val)
5995 int err = 0;
5997 switch (par_id) {
5998 case IOV_BCN_LI_BCN:
5999 wlc->bcn_li_bcn = (u8) int_val;
6000 if (wlc->pub->up)
6001 brcms_c_bcn_li_upd(wlc);
6002 break;
6003 /* As long as override is false, this only sets the *user*
6004 targets. User can twiddle this all he wants with no harm.
6005 wlc_phy_txpower_set() explicitly sets override to false if
6006 not internal or test.
6008 case IOV_QTXPOWER:{
6009 u8 qdbm;
6010 bool override;
6012 /* Remove override bit and clip to max qdbm value */
6013 qdbm = (u8)min_t(u32, (int_val & ~WL_TXPWR_OVERRIDE), 0xff);
6014 /* Extract override setting */
6015 override = (int_val & WL_TXPWR_OVERRIDE) ? true : false;
6016 err =
6017 wlc_phy_txpower_set(wlc->band->pi, qdbm, override);
6018 break;
6020 case IOV_MPC:
6021 wlc->mpc = (bool)int_val;
6022 brcms_c_radio_mpc_upd(wlc);
6023 break;
6024 default:
6025 err = -ENOTSUPP;
6027 return err;
6030 int brcms_c_get_par(struct brcms_c_info *wlc, enum wlc_par_id par_id,
6031 int *ret_int_ptr)
6033 int err = 0;
6035 switch (par_id) {
6036 case IOV_BCN_LI_BCN:
6037 *ret_int_ptr = wlc->bcn_li_bcn;
6038 break;
6039 case IOV_QTXPOWER: {
6040 uint qdbm;
6041 bool override;
6043 err = wlc_phy_txpower_get(wlc->band->pi, &qdbm,
6044 &override);
6045 if (err != 0)
6046 return err;
6048 /* Return qdbm units */
6049 *ret_int_ptr =
6050 qdbm | (override ? WL_TXPWR_OVERRIDE : 0);
6051 break;
6053 case IOV_MPC:
6054 *ret_int_ptr = (s32) wlc->mpc;
6055 break;
6056 default:
6057 err = -ENOTSUPP;
6059 return err;
6063 * Search the name=value vars for a specific one and return its value.
6064 * Returns NULL if not found.
6066 char *getvar(char *vars, const char *name)
6068 char *s;
6069 int len;
6071 if (!name)
6072 return NULL;
6074 len = strlen(name);
6075 if (len == 0)
6076 return NULL;
6078 /* first look in vars[] */
6079 for (s = vars; s && *s;) {
6080 if ((memcmp(s, name, len) == 0) && (s[len] == '='))
6081 return &s[len + 1];
6083 while (*s++)
6086 /* nothing found */
6087 return NULL;
6091 * Search the vars for a specific one and return its value as
6092 * an integer. Returns 0 if not found.
6094 int getintvar(char *vars, const char *name)
6096 char *val;
6098 val = getvar(vars, name);
6099 if (val == NULL)
6100 return 0;
6102 return simple_strtoul(val, NULL, 0);