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.
16 #include <linux/kernel.h>
17 #include <linux/ctype.h>
18 #include <linux/etherdevice.h>
19 #include <net/mac80211.h>
35 #include "wlc_types.h"
41 #include "wlc_bsscfg.h"
42 #include "phy/wlc_phy_hal.h"
43 #include "wlc_channel.h"
46 #include "wlc_phy_hal.h"
47 #include "wlc_phy_shim.h"
48 #include "wlc_antsel.h"
50 #include "wlc_ampdu.h"
51 #include "wl_export.h"
52 #include "wlc_alloc.h"
56 * Disable statistics counting for WME
58 #define WLCNTSET(a, b)
60 #define WLCNTADD(a, b)
65 #define RSN_CAP_4_REPLAY_CNTRS 2
66 #define RSN_CAP_16_REPLAY_CNTRS 3
68 #define WPA_CAP_4_REPLAY_CNTRS RSN_CAP_4_REPLAY_CNTRS
69 #define WPA_CAP_16_REPLAY_CNTRS RSN_CAP_16_REPLAY_CNTRS
72 * Indication for txflowcontrol that all priority bits in
73 * TXQ_STOP_FOR_PRIOFC_MASK are to be considered.
78 * buffer length needed for wlc_format_ssid
79 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
81 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
83 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
84 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
86 #ifndef WLC_MPC_MAX_DELAYCNT
87 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
89 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
90 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
92 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
93 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
95 /* Scale down delays to accommodate QT slow speed */
96 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
97 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
99 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
102 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
103 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
104 * this low resolution driver tick can be used for maintenance tasks such as phy
105 * calibration and scb update
108 /* watchdog trigger mode: OSL timer or TBTT */
109 #define WLC_WATCHDOG_TBTT(wlc) \
110 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
112 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
113 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
115 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
116 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
126 /* Find basic rate for a given rate */
127 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
128 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
129 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
131 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
133 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
135 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
137 #define SCAN_IN_PROGRESS(x) 0
139 #define EPI_VERSION_NUM 0x054b0b00
142 /* pointer to most recently allocated wl/wlc */
143 static struct wlc_info *wlc_info_dbg = (struct wlc_info *) (NULL);
148 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
149 * table and by the wlc_doiovar() function. No ordering is imposed:
150 * the table is keyed by name, and the function uses a switch.
156 IOV_BCN_LI_BCN, /* Beacon listen interval in # of beacons */
157 IOV_LAST /* In case of a need to check max ID number */
160 const bcm_iovar_t wlc_iovars[] = {
161 {"mpc", IOV_MPC, (0), IOVT_BOOL, 0},
162 {"rtsthresh", IOV_RTSTHRESH, (IOVF_WHL), IOVT_UINT16, 0},
163 {"qtxpower", IOV_QTXPOWER, (IOVF_WHL), IOVT_UINT32, 0},
164 {"bcn_li_bcn", IOV_BCN_LI_BCN, (0), IOVT_UINT8, 0},
168 const u8 prio2fifo[NUMPRIO] = {
169 TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */
170 TX_AC_BK_FIFO, /* 1 BK AC_BK Background */
171 TX_AC_BK_FIFO, /* 2 -- AC_BK Background */
172 TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */
173 TX_AC_VI_FIFO, /* 4 CL AC_VI Video */
174 TX_AC_VI_FIFO, /* 5 VI AC_VI Video */
175 TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */
176 TX_AC_VO_FIFO /* 7 NC AC_VO Voice */
179 /* precedences numbers for wlc queues. These are twice as may levels as
181 * Odd numbers are used for HI priority traffic at same precedence levels
182 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
184 #define _WLC_PREC_NONE 0 /* None = - */
185 #define _WLC_PREC_BK 2 /* BK - Background */
186 #define _WLC_PREC_BE 4 /* BE - Best-effort */
187 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
188 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
189 #define _WLC_PREC_VI 10 /* Vi - Video */
190 #define _WLC_PREC_VO 12 /* Vo - Voice */
191 #define _WLC_PREC_NC 14 /* NC - Network Control */
193 /* 802.1D Priority to precedence queue mapping */
194 const u8 wlc_prio2prec_map[] = {
195 _WLC_PREC_BE, /* 0 BE - Best-effort */
196 _WLC_PREC_BK, /* 1 BK - Background */
197 _WLC_PREC_NONE, /* 2 None = - */
198 _WLC_PREC_EE, /* 3 EE - Excellent-effort */
199 _WLC_PREC_CL, /* 4 CL - Controlled Load */
200 _WLC_PREC_VI, /* 5 Vi - Video */
201 _WLC_PREC_VO, /* 6 Vo - Voice */
202 _WLC_PREC_NC, /* 7 NC - Network Control */
205 /* Sanity check for tx_prec_map and fifo synchup
206 * Either there are some packets pending for the fifo, else if fifo is empty then
207 * all the corresponding precmap bits should be set
209 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
210 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
211 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
212 (wlc)->fifo2prec_map[(fifo)]))
214 /* TX FIFO number to WME/802.1E Access Category */
215 const u8 wme_fifo2ac[] = { AC_BK, AC_BE, AC_VI, AC_VO, AC_BE, AC_BE };
217 /* WME/802.1E Access Category to TX FIFO number */
218 static const u8 wme_ac2fifo[] = { 1, 0, 2, 3 };
220 static bool in_send_q = false;
222 /* Shared memory location index for various AC params */
223 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
226 static const char *fifo_names[] = {
227 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
229 static const char fifo_names[6][0];
232 static const u8 acbitmap2maxprio[] = {
233 PRIO_8021D_BE, PRIO_8021D_BE, PRIO_8021D_BK, PRIO_8021D_BK,
234 PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI,
235 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO,
236 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO
239 /* currently the best mechanism for determining SIFS is the band in use */
240 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
242 /* value for # replay counters currently supported */
243 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
245 /* local prototypes */
246 static u16 BCMFASTPATH wlc_d11hdrs_mac80211(struct wlc_info *wlc,
247 struct ieee80211_hw *hw,
249 struct scb *scb, uint frag,
250 uint nfrags, uint queue,
253 ratespec_t rspec_override);
255 static void wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat);
256 static void wlc_bss_default_init(struct wlc_info *wlc);
257 static void wlc_ucode_mac_upd(struct wlc_info *wlc);
258 static ratespec_t mac80211_wlc_set_nrate(struct wlc_info *wlc,
259 struct wlcband *cur_band, u32 int_val);
260 static void wlc_tx_prec_map_init(struct wlc_info *wlc);
261 static void wlc_watchdog(void *arg);
262 static void wlc_watchdog_by_timer(void *arg);
263 static u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate);
264 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg);
265 static int wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val,
266 const bcm_iovar_t *vi);
267 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc);
269 /* send and receive */
270 static struct wlc_txq_info *wlc_txq_alloc(struct wlc_info *wlc);
271 static void wlc_txq_free(struct wlc_info *wlc,
272 struct wlc_txq_info *qi);
273 static void wlc_txflowcontrol_signal(struct wlc_info *wlc,
274 struct wlc_txq_info *qi,
276 static void wlc_txflowcontrol_reset(struct wlc_info *wlc);
277 static u16 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec,
279 static void wlc_compute_cck_plcp(ratespec_t rate, uint length, u8 *plcp);
280 static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp);
281 static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp);
282 static u16 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate,
283 u8 preamble_type, uint next_frag_len);
284 static void wlc_recvctl(struct wlc_info *wlc,
285 d11rxhdr_t *rxh, struct sk_buff *p);
286 static uint wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t rate,
287 u8 preamble_type, uint dur);
288 static uint wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rate,
290 static uint wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rate,
292 /* interrupt, up/down, band */
293 static void wlc_setband(struct wlc_info *wlc, uint bandunit);
294 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc);
295 static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec);
296 static void wlc_bsinit(struct wlc_info *wlc);
297 static int wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
299 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc);
300 static bool wlc_radio_monitor_start(struct wlc_info *wlc);
301 static void wlc_radio_timer(void *arg);
302 static void wlc_radio_enable(struct wlc_info *wlc);
303 static void wlc_radio_upd(struct wlc_info *wlc);
305 /* scan, association, BSS */
306 static uint wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rate,
308 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap);
309 static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val);
310 static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val);
311 static void wlc_war16165(struct wlc_info *wlc, bool tx);
313 static void wlc_wme_retries_write(struct wlc_info *wlc);
314 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc);
315 static uint wlc_attach_module(struct wlc_info *wlc);
316 static void wlc_detach_module(struct wlc_info *wlc);
317 static void wlc_timers_deinit(struct wlc_info *wlc);
318 static void wlc_down_led_upd(struct wlc_info *wlc);
319 static uint wlc_down_del_timer(struct wlc_info *wlc);
320 static void wlc_ofdm_rateset_war(struct wlc_info *wlc);
321 static int _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
322 struct wlc_if *wlcif);
325 void wlc_get_rcmta(struct wlc_info *wlc, int idx, u8 *addr)
327 d11regs_t *regs = wlc->regs;
330 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc), __func__);
332 W_REG(®s->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2)));
333 (void)R_REG(®s->objaddr);
334 v32 = R_REG(®s->objdata);
336 addr[1] = (u8) (v32 >> 8);
337 addr[2] = (u8) (v32 >> 16);
338 addr[3] = (u8) (v32 >> 24);
339 W_REG(®s->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1)));
340 (void)R_REG(®s->objaddr);
341 v32 = R_REG(®s->objdata);
343 addr[5] = (u8) (v32 >> 8);
345 #endif /* defined(BCMDBG) */
347 /* keep the chip awake if needed */
348 bool wlc_stay_awake(struct wlc_info *wlc)
353 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
355 bool wlc_ps_allowed(struct wlc_info *wlc)
360 /* disallow PS when one of the following global conditions meets */
361 if (!wlc->pub->associated || !wlc->PMenabled || wlc->PM_override)
364 /* disallow PS when one of these meets when not scanning */
365 if (!wlc->PMblocked) {
366 if (AP_ACTIVE(wlc) || wlc->monitor)
370 FOREACH_AS_STA(wlc, idx, cfg) {
371 /* disallow PS when one of the following bsscfg specific conditions meets */
372 if (!cfg->BSS || !WLC_PORTOPEN(cfg))
375 if (!cfg->dtim_programmed)
382 void wlc_reset(struct wlc_info *wlc)
384 WL_TRACE("wl%d: wlc_reset\n", wlc->pub->unit);
386 wlc->check_for_unaligned_tbtt = false;
388 /* slurp up hw mac counters before core reset */
391 /* reset our snapshot of macstat counters */
392 memset((char *)wlc->core->macstat_snapshot, 0,
395 wlc_bmac_reset(wlc->hw);
396 wlc_ampdu_reset(wlc->ampdu);
401 void wlc_fatal_error(struct wlc_info *wlc)
403 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc->pub->unit);
407 /* Return the channel the driver should initialize during wlc_init.
408 * the channel may have to be changed from the currently configured channel
409 * if other configurations are in conflict (bandlocked, 11n mode disabled,
410 * invalid channel for current country, etc.)
412 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc)
414 chanspec_t chanspec =
415 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE |
418 /* make sure the channel is on the supported band if we are band-restricted */
419 if (wlc->bandlocked || NBANDS(wlc) == 1) {
420 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
422 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
426 struct scb global_scb;
428 static void wlc_init_scb(struct wlc_info *wlc, struct scb *scb)
431 scb->flags = SCB_WMECAP | SCB_HTCAP;
432 for (i = 0; i < NUMPRIO; i++)
436 void wlc_init(struct wlc_info *wlc)
441 wlc_bsscfg_t *bsscfg;
444 WL_TRACE("wl%d: wlc_init\n", wlc->pub->unit);
448 /* This will happen if a big-hammer was executed. In that case, we want to go back
449 * to the channel that we were on and not new channel
451 if (wlc->pub->associated)
452 chanspec = wlc->home_chanspec;
454 chanspec = wlc_init_chanspec(wlc);
456 wlc_bmac_init(wlc->hw, chanspec, mute);
458 wlc->seckeys = wlc_bmac_read_shm(wlc->hw, M_SECRXKEYS_PTR) * 2;
459 if (wlc->machwcap & MCAP_TKIPMIC)
461 wlc_bmac_read_shm(wlc->hw, M_TKMICKEYS_PTR) * 2;
463 /* update beacon listen interval */
466 (u8) (wlc_bmac_read_shm(wlc->hw, M_NOSLPZNATDTIM) >> 10);
467 ASSERT(wlc->bcn_wait_prd > 0);
469 /* the world is new again, so is our reported rate */
470 wlc_reprate_init(wlc);
472 /* write ethernet address to core */
473 FOREACH_BSS(wlc, i, bsscfg) {
475 wlc_set_bssid(bsscfg);
478 /* Update tsf_cfprep if associated and up */
479 if (wlc->pub->associated) {
480 FOREACH_BSS(wlc, i, bsscfg) {
484 /* get beacon period and convert to uS */
485 bi = bsscfg->current_bss->beacon_period << 10;
487 * update since init path would reset
490 W_REG(®s->tsf_cfprep,
491 (bi << CFPREP_CBI_SHIFT));
493 /* Update maccontrol PM related bits */
494 wlc_set_ps_ctrl(wlc);
501 wlc_key_hw_init_all(wlc);
503 wlc_bandinit_ordered(wlc, chanspec);
505 wlc_init_scb(wlc, &global_scb);
507 /* init probe response timeout */
508 wlc_write_shm(wlc, M_PRS_MAXTIME, wlc->prb_resp_timeout);
510 /* init max burst txop (framebursting) */
511 wlc_write_shm(wlc, M_MBURST_TXOP,
513 _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP));
515 /* initialize maximum allowed duty cycle */
516 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true);
517 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true);
519 /* Update some shared memory locations related to max AMPDU size allowed to received */
520 wlc_ampdu_shm_upd(wlc->ampdu);
522 /* band-specific inits */
525 /* Enable EDCF mode (while the MAC is suspended) */
526 if (EDCF_ENAB(wlc->pub)) {
527 OR_REG(®s->ifs_ctl, IFS_USEEDCF);
528 wlc_edcf_setparams(wlc->cfg, false);
531 /* Init precedence maps for empty FIFOs */
532 wlc_tx_prec_map_init(wlc);
534 /* read the ucode version if we have not yet done so */
535 if (wlc->ucode_rev == 0) {
537 wlc_read_shm(wlc, M_BOM_REV_MAJOR) << NBITS(u16);
538 wlc->ucode_rev |= wlc_read_shm(wlc, M_BOM_REV_MINOR);
541 /* ..now really unleash hell (allow the MAC out of suspend) */
544 /* clear tx flow control */
545 wlc_txflowcontrol_reset(wlc);
547 /* clear tx data fifo suspends */
548 wlc->tx_suspended = false;
550 /* enable the RF Disable Delay timer */
551 W_REG(&wlc->regs->rfdisabledly, RFDISABLE_DEFAULT);
553 /* initialize mpc delay */
554 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
557 * Initialize WME parameters; if they haven't been set by some other
558 * mechanism (IOVar, etc) then read them from the hardware.
560 if (WLC_WME_RETRY_SHORT_GET(wlc, 0) == 0) { /* Uninitialized; read from HW */
564 for (ac = 0; ac < AC_COUNT; ac++) {
565 wlc->wme_retries[ac] =
566 wlc_read_shm(wlc, M_AC_TXLMT_ADDR(ac));
571 void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc)
573 wlc->bcnmisc_monitor = promisc;
574 wlc_mac_bcn_promisc(wlc);
577 void wlc_mac_bcn_promisc(struct wlc_info *wlc)
579 if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) ||
580 wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor)
581 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, MCTL_BCNS_PROMISC);
583 wlc_mctrl(wlc, MCTL_BCNS_PROMISC, 0);
586 /* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
587 void wlc_mac_promisc(struct wlc_info *wlc)
589 u32 promisc_bits = 0;
591 /* promiscuous mode just sets MCTL_PROMISC
592 * Note: APs get all BSS traffic without the need to set the MCTL_PROMISC bit
593 * since all BSS data traffic is directed at the AP
595 if (PROMISC_ENAB(wlc->pub) && !AP_ENAB(wlc->pub) && !wlc->wet)
596 promisc_bits |= MCTL_PROMISC;
598 /* monitor mode needs both MCTL_PROMISC and MCTL_KEEPCONTROL
599 * Note: monitor mode also needs MCTL_BCNS_PROMISC, but that is
600 * handled in wlc_mac_bcn_promisc()
602 if (MONITOR_ENAB(wlc))
603 promisc_bits |= MCTL_PROMISC | MCTL_KEEPCONTROL;
605 wlc_mctrl(wlc, MCTL_PROMISC | MCTL_KEEPCONTROL, promisc_bits);
608 /* check if hps and wake states of sw and hw are in sync */
609 bool wlc_ps_check(struct wlc_info *wlc)
615 if (!AP_ACTIVE(wlc)) {
617 tmp = R_REG(&wlc->regs->maccontrol);
620 * If deviceremoved is detected, then don't take any action as
621 * this can be called in any context. Assume that caller will
622 * take care of the condition. This is just to avoid assert
624 if (tmp == 0xffffffff) {
625 WL_ERROR("wl%d: %s: dead chip\n",
626 wlc->pub->unit, __func__);
627 return DEVICEREMOVED(wlc);
630 hps = PS_ALLOWED(wlc);
632 if (hps != ((tmp & MCTL_HPS) != 0)) {
635 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
636 wlc->pub->unit, hps, tmp);
637 FOREACH_BSS(wlc, idx, cfg) {
638 if (!BSSCFG_STA(cfg))
644 /* For a monolithic build the wake check can be exact since it looks at wake
645 * override bits. The MCTL_WAKE bit should match the 'wake' value.
647 wake = STAY_AWAKE(wlc) || wlc->hw->wake_override;
648 wake_ok = (wake == ((tmp & MCTL_WAKE) != 0));
649 if (hps && !wake_ok) {
650 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
651 wlc->pub->unit, wake, tmp);
659 /* push sw hps and wake state through hardware */
660 void wlc_set_ps_ctrl(struct wlc_info *wlc)
666 hps = PS_ALLOWED(wlc);
667 wake = hps ? (STAY_AWAKE(wlc)) : true;
669 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
670 wlc->pub->unit, hps, wake);
672 v1 = R_REG(&wlc->regs->maccontrol);
679 wlc_mctrl(wlc, MCTL_WAKE | MCTL_HPS, v2);
681 awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0));
683 if (wake && !awake_before)
684 wlc_bmac_wait_for_wake(wlc->hw);
689 * Write this BSS config's MAC address to core.
690 * Updates RXE match engine.
692 int wlc_set_mac(wlc_bsscfg_t *cfg)
695 struct wlc_info *wlc = cfg->wlc;
697 if (cfg == wlc->cfg) {
698 /* enter the MAC addr into the RXE match registers */
699 wlc_set_addrmatch(wlc, RCM_MAC_OFFSET, cfg->cur_etheraddr);
702 wlc_ampdu_macaddr_upd(wlc);
707 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
708 * Updates RXE match engine.
710 void wlc_set_bssid(wlc_bsscfg_t *cfg)
712 struct wlc_info *wlc = cfg->wlc;
714 /* if primary config, we need to update BSSID in RXE match registers */
715 if (cfg == wlc->cfg) {
716 wlc_set_addrmatch(wlc, RCM_BSSID_OFFSET, cfg->BSSID);
718 #ifdef SUPPORT_HWKEYS
719 else if (BSSCFG_STA(cfg) && cfg->BSS) {
720 wlc_rcmta_add_bssid(wlc, cfg);
726 * Suspend the the MAC and update the slot timing
727 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
729 void wlc_switch_shortslot(struct wlc_info *wlc, bool shortslot)
734 ASSERT(wlc->band->gmode);
736 /* use the override if it is set */
737 if (wlc->shortslot_override != WLC_SHORTSLOT_AUTO)
738 shortslot = (wlc->shortslot_override == WLC_SHORTSLOT_ON);
740 if (wlc->shortslot == shortslot)
743 wlc->shortslot = shortslot;
745 /* update the capability based on current shortslot mode */
746 FOREACH_BSS(wlc, idx, cfg) {
747 if (!cfg->associated)
749 cfg->current_bss->capability &=
750 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
752 cfg->current_bss->capability |=
753 WLAN_CAPABILITY_SHORT_SLOT_TIME;
756 wlc_bmac_set_shortslot(wlc->hw, shortslot);
759 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc)
764 local = WLC_TXPWR_MAX;
765 if (wlc->pub->associated &&
766 (wf_chspec_ctlchan(wlc->chanspec) ==
767 wf_chspec_ctlchan(wlc->home_chanspec))) {
769 /* get the local power constraint if we are on the AP's
770 * channel [802.11h, 7.3.2.13]
772 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
774 (wlc->txpwr_local_max -
775 wlc->txpwr_local_constraint) * WLC_TXPWR_DB_FACTOR;
776 if (local_max > 0 && local_max < WLC_TXPWR_MAX)
777 return (u8) local_max;
785 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
786 void wlc_set_home_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
788 if (wlc->home_chanspec != chanspec) {
792 wlc->home_chanspec = chanspec;
794 FOREACH_BSS(wlc, idx, cfg) {
795 if (!cfg->associated)
798 cfg->current_bss->chanspec = chanspec;
804 static void wlc_set_phy_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
806 /* Save our copy of the chanspec */
807 wlc->chanspec = chanspec;
809 /* Set the chanspec and power limits for this locale after computing
810 * any 11h local tx power constraints.
812 wlc_channel_set_chanspec(wlc->cmi, chanspec,
813 wlc_local_constraint_qdbm(wlc));
815 if (wlc->stf->ss_algosel_auto)
816 wlc_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel,
819 wlc_stf_ss_update(wlc, wlc->band);
823 void wlc_set_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
826 bool switchband = false;
827 chanspec_t old_chanspec = wlc->chanspec;
829 if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) {
830 WL_ERROR("wl%d: %s: Bad channel %d\n",
831 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec));
832 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
836 /* Switch bands if necessary */
837 if (NBANDS(wlc) > 1) {
838 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
839 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) {
841 if (wlc->bandlocked) {
842 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
843 wlc->pub->unit, __func__,
844 CHSPEC_CHANNEL(chanspec));
847 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
848 * if the setband updates (wlc_bsinit) use low level calls to inspect and
849 * set state, the state inspected may be from the wrong band, or the
850 * following wlc_bmac_set_chanspec() may undo the work.
852 wlc_setband(wlc, bandunit);
856 ASSERT(N_ENAB(wlc->pub) || !CHSPEC_IS40(chanspec));
858 /* sync up phy/radio chanspec */
859 wlc_set_phy_chanspec(wlc, chanspec);
861 /* init antenna selection */
862 if (CHSPEC_WLC_BW(old_chanspec) != CHSPEC_WLC_BW(chanspec)) {
863 wlc_antsel_init(wlc->asi);
865 /* Fix the hardware rateset based on bw.
866 * Mainly add MCS32 for 40Mhz, remove MCS 32 for 20Mhz
868 wlc_rateset_bw_mcs_filter(&wlc->band->hw_rateset,
870 mimo_cap_40 ? CHSPEC_WLC_BW(chanspec)
874 /* update some mac configuration since chanspec changed */
875 wlc_ucode_mac_upd(wlc);
879 static int wlc_get_current_txpwr(struct wlc_info *wlc, void *pwr, uint len)
881 txpwr_limits_t txpwr;
883 tx_power_legacy_t *old_power = NULL;
888 if (len == sizeof(tx_power_legacy_t))
889 old_power = (tx_power_legacy_t *) pwr;
890 else if (len < sizeof(tx_power_t))
891 return BCME_BUFTOOSHORT;
893 memset(&power, 0, sizeof(tx_power_t));
895 power.chanspec = WLC_BAND_PI_RADIO_CHANSPEC;
896 if (wlc->pub->associated)
897 power.local_chanspec = wlc->home_chanspec;
899 /* Return the user target tx power limits for the various rates. Note wlc_phy.c's
900 * public interface only implements getting and setting a single value for all of
901 * rates, so we need to fill the array ourselves.
903 wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override);
904 for (r = 0; r < WL_TX_POWER_RATES; r++) {
905 power.user_limit[r] = (u8) qdbm;
908 power.local_max = wlc->txpwr_local_max * WLC_TXPWR_DB_FACTOR;
909 power.local_constraint =
910 wlc->txpwr_local_constraint * WLC_TXPWR_DB_FACTOR;
912 power.antgain[0] = wlc->bandstate[BAND_2G_INDEX]->antgain;
913 power.antgain[1] = wlc->bandstate[BAND_5G_INDEX]->antgain;
915 wlc_channel_reg_limits(wlc->cmi, power.chanspec, &txpwr);
917 #if WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK
918 #error "WL_TX_POWER_CCK_NUM != WLC_NUM_RATES_CCK"
921 /* CCK tx power limits */
922 for (c = 0, r = WL_TX_POWER_CCK_FIRST; c < WL_TX_POWER_CCK_NUM;
924 power.reg_limit[r] = txpwr.cck[c];
926 #if WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM
927 #error "WL_TX_POWER_OFDM_NUM != WLC_NUM_RATES_OFDM"
930 /* 20 MHz OFDM SISO tx power limits */
931 for (c = 0, r = WL_TX_POWER_OFDM_FIRST; c < WL_TX_POWER_OFDM_NUM;
933 power.reg_limit[r] = txpwr.ofdm[c];
935 if (WLC_PHY_11N_CAP(wlc->band)) {
937 /* 20 MHz OFDM CDD tx power limits */
938 for (c = 0, r = WL_TX_POWER_OFDM20_CDD_FIRST;
939 c < WL_TX_POWER_OFDM_NUM; c++, r++)
940 power.reg_limit[r] = txpwr.ofdm_cdd[c];
942 /* 40 MHz OFDM SISO tx power limits */
943 for (c = 0, r = WL_TX_POWER_OFDM40_SISO_FIRST;
944 c < WL_TX_POWER_OFDM_NUM; c++, r++)
945 power.reg_limit[r] = txpwr.ofdm_40_siso[c];
947 /* 40 MHz OFDM CDD tx power limits */
948 for (c = 0, r = WL_TX_POWER_OFDM40_CDD_FIRST;
949 c < WL_TX_POWER_OFDM_NUM; c++, r++)
950 power.reg_limit[r] = txpwr.ofdm_40_cdd[c];
952 #if WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM
953 #error "WL_TX_POWER_MCS_1_STREAM_NUM != WLC_NUM_RATES_MCS_1_STREAM"
956 /* 20MHz MCS0-7 SISO tx power limits */
957 for (c = 0, r = WL_TX_POWER_MCS20_SISO_FIRST;
958 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
959 power.reg_limit[r] = txpwr.mcs_20_siso[c];
961 /* 20MHz MCS0-7 CDD tx power limits */
962 for (c = 0, r = WL_TX_POWER_MCS20_CDD_FIRST;
963 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
964 power.reg_limit[r] = txpwr.mcs_20_cdd[c];
966 /* 20MHz MCS0-7 STBC tx power limits */
967 for (c = 0, r = WL_TX_POWER_MCS20_STBC_FIRST;
968 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
969 power.reg_limit[r] = txpwr.mcs_20_stbc[c];
971 /* 40MHz MCS0-7 SISO tx power limits */
972 for (c = 0, r = WL_TX_POWER_MCS40_SISO_FIRST;
973 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
974 power.reg_limit[r] = txpwr.mcs_40_siso[c];
976 /* 40MHz MCS0-7 CDD tx power limits */
977 for (c = 0, r = WL_TX_POWER_MCS40_CDD_FIRST;
978 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
979 power.reg_limit[r] = txpwr.mcs_40_cdd[c];
981 /* 40MHz MCS0-7 STBC tx power limits */
982 for (c = 0, r = WL_TX_POWER_MCS40_STBC_FIRST;
983 c < WLC_NUM_RATES_MCS_1_STREAM; c++, r++)
984 power.reg_limit[r] = txpwr.mcs_40_stbc[c];
986 #if WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM
987 #error "WL_TX_POWER_MCS_2_STREAM_NUM != WLC_NUM_RATES_MCS_2_STREAM"
990 /* 20MHz MCS8-15 SDM tx power limits */
991 for (c = 0, r = WL_TX_POWER_MCS20_SDM_FIRST;
992 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
993 power.reg_limit[r] = txpwr.mcs_20_mimo[c];
995 /* 40MHz MCS8-15 SDM tx power limits */
996 for (c = 0, r = WL_TX_POWER_MCS40_SDM_FIRST;
997 c < WLC_NUM_RATES_MCS_2_STREAM; c++, r++)
998 power.reg_limit[r] = txpwr.mcs_40_mimo[c];
1001 power.reg_limit[WL_TX_POWER_MCS_32] = txpwr.mcs32;
1004 wlc_phy_txpower_get_current(wlc->band->pi, &power,
1005 CHSPEC_CHANNEL(power.chanspec));
1007 /* copy the tx_power_t struct to the return buffer,
1008 * or convert to a tx_power_legacy_t struct
1011 memcpy(pwr, &power, sizeof(tx_power_t));
1013 int band_idx = CHSPEC_IS2G(power.chanspec) ? 0 : 1;
1015 memset(old_power, 0, sizeof(tx_power_legacy_t));
1017 old_power->txpwr_local_max = power.local_max;
1018 old_power->txpwr_local_constraint = power.local_constraint;
1019 if (CHSPEC_IS2G(power.chanspec)) {
1020 old_power->txpwr_chan_reg_max = txpwr.cck[0];
1021 old_power->txpwr_est_Pout[band_idx] =
1023 old_power->txpwr_est_Pout_gofdm = power.est_Pout[0];
1025 old_power->txpwr_chan_reg_max = txpwr.ofdm[0];
1026 old_power->txpwr_est_Pout[band_idx] = power.est_Pout[0];
1028 old_power->txpwr_antgain[0] = power.antgain[0];
1029 old_power->txpwr_antgain[1] = power.antgain[1];
1031 for (r = 0; r < NUM_PWRCTRL_RATES; r++) {
1032 old_power->txpwr_band_max[r] = power.user_limit[r];
1033 old_power->txpwr_limit[r] = power.reg_limit[r];
1034 old_power->txpwr_target[band_idx][r] = power.target[r];
1035 if (CHSPEC_IS2G(power.chanspec))
1036 old_power->txpwr_bphy_cck_max[r] =
1037 power.board_limit[r];
1039 old_power->txpwr_aphy_max[r] =
1040 power.board_limit[r];
1046 #endif /* defined(BCMDBG) */
1048 static u32 wlc_watchdog_backup_bi(struct wlc_info *wlc)
1051 bi = 2 * wlc->cfg->current_bss->dtim_period *
1052 wlc->cfg->current_bss->beacon_period;
1053 if (wlc->bcn_li_dtim)
1054 bi *= wlc->bcn_li_dtim;
1055 else if (wlc->bcn_li_bcn)
1056 /* recalculate bi based on bcn_li_bcn */
1057 bi = 2 * wlc->bcn_li_bcn * wlc->cfg->current_bss->beacon_period;
1059 if (bi < 2 * TIMER_INTERVAL_WATCHDOG)
1060 bi = 2 * TIMER_INTERVAL_WATCHDOG;
1064 /* Change to run the watchdog either from a periodic timer or from tbtt handler.
1065 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1067 void wlc_watchdog_upd(struct wlc_info *wlc, bool tbtt)
1069 /* make sure changing watchdog driver is allowed */
1070 if (!wlc->pub->up || !wlc->pub->align_wd_tbtt)
1072 if (!tbtt && wlc->WDarmed) {
1073 wl_del_timer(wlc->wl, wlc->wdtimer);
1074 wlc->WDarmed = false;
1077 /* stop watchdog timer and use tbtt interrupt to drive watchdog */
1078 if (tbtt && wlc->WDarmed) {
1079 wl_del_timer(wlc->wl, wlc->wdtimer);
1080 wlc->WDarmed = false;
1081 wlc->WDlast = OSL_SYSUPTIME();
1083 /* arm watchdog timer and drive the watchdog there */
1084 else if (!tbtt && !wlc->WDarmed) {
1085 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
1087 wlc->WDarmed = true;
1089 if (tbtt && !wlc->WDarmed) {
1090 wl_add_timer(wlc->wl, wlc->wdtimer, wlc_watchdog_backup_bi(wlc),
1092 wlc->WDarmed = true;
1096 ratespec_t wlc_lowest_basic_rspec(struct wlc_info *wlc, wlc_rateset_t *rs)
1098 ratespec_t lowest_basic_rspec;
1101 /* Use the lowest basic rate */
1102 lowest_basic_rspec = rs->rates[0] & RATE_MASK;
1103 for (i = 0; i < rs->count; i++) {
1104 if (rs->rates[i] & WLC_RATE_FLAG) {
1105 lowest_basic_rspec = rs->rates[i] & RATE_MASK;
1110 /* pick siso/cdd as default for OFDM (note no basic rate MCSs are supported yet) */
1111 if (IS_OFDM(lowest_basic_rspec)) {
1112 lowest_basic_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
1116 return lowest_basic_rspec;
1119 /* This function changes the phytxctl for beacon based on current beacon ratespec AND txant
1120 * setting as per this table:
1121 * ratespec CCK ant = wlc->stf->txant
1124 void wlc_beacon_phytxctl_txant_upd(struct wlc_info *wlc, ratespec_t bcn_rspec)
1127 u16 phytxant = wlc->stf->phytxant;
1128 u16 mask = PHY_TXC_ANT_MASK;
1130 /* for non-siso rates or default setting, use the available chains */
1131 if (WLC_PHY_11N_CAP(wlc->band)) {
1132 phytxant = wlc_stf_phytxchain_sel(wlc, bcn_rspec);
1135 phyctl = wlc_read_shm(wlc, M_BCN_PCTLWD);
1136 phyctl = (phyctl & ~mask) | phytxant;
1137 wlc_write_shm(wlc, M_BCN_PCTLWD, phyctl);
1140 /* centralized protection config change function to simplify debugging, no consistency checking
1141 * this should be called only on changes to avoid overhead in periodic function
1143 void wlc_protection_upd(struct wlc_info *wlc, uint idx, int val)
1145 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx, val);
1148 case WLC_PROT_G_SPEC:
1149 wlc->protection->_g = (bool) val;
1151 case WLC_PROT_G_OVR:
1152 wlc->protection->g_override = (s8) val;
1154 case WLC_PROT_G_USER:
1155 wlc->protection->gmode_user = (u8) val;
1157 case WLC_PROT_OVERLAP:
1158 wlc->protection->overlap = (s8) val;
1160 case WLC_PROT_N_USER:
1161 wlc->protection->nmode_user = (s8) val;
1163 case WLC_PROT_N_CFG:
1164 wlc->protection->n_cfg = (s8) val;
1166 case WLC_PROT_N_CFG_OVR:
1167 wlc->protection->n_cfg_override = (s8) val;
1169 case WLC_PROT_N_NONGF:
1170 wlc->protection->nongf = (bool) val;
1172 case WLC_PROT_N_NONGF_OVR:
1173 wlc->protection->nongf_override = (s8) val;
1175 case WLC_PROT_N_PAM_OVR:
1176 wlc->protection->n_pam_override = (s8) val;
1178 case WLC_PROT_N_OBSS:
1179 wlc->protection->n_obss = (bool) val;
1189 static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val)
1191 wlc->ht_cap.cap_info &= ~(IEEE80211_HT_CAP_SGI_20 |
1192 IEEE80211_HT_CAP_SGI_40);
1193 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_20) ?
1194 IEEE80211_HT_CAP_SGI_20 : 0;
1195 wlc->ht_cap.cap_info |= (val & WLC_N_SGI_40) ?
1196 IEEE80211_HT_CAP_SGI_40 : 0;
1199 wlc_update_beacon(wlc);
1200 wlc_update_probe_resp(wlc, true);
1204 static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val)
1206 wlc->stf->ldpc = val;
1208 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_LDPC_CODING;
1209 if (wlc->stf->ldpc != OFF)
1210 wlc->ht_cap.cap_info |= IEEE80211_HT_CAP_LDPC_CODING;
1213 wlc_update_beacon(wlc);
1214 wlc_update_probe_resp(wlc, true);
1215 wlc_phy_ldpc_override_set(wlc->band->pi, (val ? true : false));
1220 * ucode, hwmac update
1221 * Channel dependent updates for ucode and hw
1223 static void wlc_ucode_mac_upd(struct wlc_info *wlc)
1225 /* enable or disable any active IBSSs depending on whether or not
1226 * we are on the home channel
1228 if (wlc->home_chanspec == WLC_BAND_PI_RADIO_CHANSPEC) {
1229 if (wlc->pub->associated) {
1230 /* BMAC_NOTE: This is something that should be fixed in ucode inits.
1231 * I think that the ucode inits set up the bcn templates and shm values
1232 * with a bogus beacon. This should not be done in the inits. If ucode needs
1233 * to set up a beacon for testing, the test routines should write it down,
1234 * not expect the inits to populate a bogus beacon.
1236 if (WLC_PHY_11N_CAP(wlc->band)) {
1237 wlc_write_shm(wlc, M_BCN_TXTSF_OFFSET,
1238 wlc->band->bcntsfoff);
1242 /* disable an active IBSS if we are not on the home channel */
1245 /* update the various promisc bits */
1246 wlc_mac_bcn_promisc(wlc);
1247 wlc_mac_promisc(wlc);
1250 static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec)
1252 wlc_rateset_t default_rateset;
1254 uint i, band_order[2];
1256 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc->pub->unit);
1258 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1259 * figure out the right band to park on
1261 if (wlc->bandlocked || NBANDS(wlc) == 1) {
1262 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
1264 parkband = wlc->band->bandunit; /* updated in wlc_bandlock() */
1265 band_order[0] = band_order[1] = parkband;
1267 /* park on the band of the specified chanspec */
1268 parkband = CHSPEC_WLCBANDUNIT(chanspec);
1270 /* order so that parkband initialize last */
1271 band_order[0] = parkband ^ 1;
1272 band_order[1] = parkband;
1275 /* make each band operational, software state init */
1276 for (i = 0; i < NBANDS(wlc); i++) {
1277 uint j = band_order[i];
1279 wlc->band = wlc->bandstate[j];
1281 wlc_default_rateset(wlc, &default_rateset);
1283 /* fill in hw_rate */
1284 wlc_rateset_filter(&default_rateset, &wlc->band->hw_rateset,
1285 false, WLC_RATES_CCK_OFDM, RATE_MASK,
1286 (bool) N_ENAB(wlc->pub));
1288 /* init basic rate lookup */
1289 wlc_rate_lookup_init(wlc, &default_rateset);
1292 /* sync up phy/radio chanspec */
1293 wlc_set_phy_chanspec(wlc, chanspec);
1296 /* band-specific init */
1297 static void WLBANDINITFN(wlc_bsinit) (struct wlc_info *wlc)
1299 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1300 wlc->pub->unit, wlc->band->bandunit);
1302 /* write ucode ACK/CTS rate table */
1303 wlc_set_ratetable(wlc);
1305 /* update some band specific mac configuration */
1306 wlc_ucode_mac_upd(wlc);
1308 /* init antenna selection */
1309 wlc_antsel_init(wlc->asi);
1313 /* switch to and initialize new band */
1314 static void WLBANDINITFN(wlc_setband) (struct wlc_info *wlc, uint bandunit)
1319 ASSERT(NBANDS(wlc) > 1);
1320 ASSERT(!wlc->bandlocked);
1321 ASSERT(bandunit != wlc->band->bandunit || wlc->bandinit_pending);
1323 wlc->band = wlc->bandstate[bandunit];
1328 /* wait for at least one beacon before entering sleeping state */
1329 wlc->PMawakebcn = true;
1330 FOREACH_AS_STA(wlc, idx, cfg)
1331 cfg->PMawakebcn = true;
1332 wlc_set_ps_ctrl(wlc);
1334 /* band-specific initializations */
1338 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1339 void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe)
1341 static const wme_param_ie_t stadef = {
1344 WME_SUBTYPE_PARAM_IE,
1349 {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA,
1350 cpu_to_le16(EDCF_AC_BE_TXOP_STA)},
1351 {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA,
1352 cpu_to_le16(EDCF_AC_BK_TXOP_STA)},
1353 {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA,
1354 cpu_to_le16(EDCF_AC_VI_TXOP_STA)},
1355 {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA,
1356 cpu_to_le16(EDCF_AC_VO_TXOP_STA)}
1360 ASSERT(sizeof(*pe) == WME_PARAM_IE_LEN);
1361 memcpy(pe, &stadef, sizeof(*pe));
1364 void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg, bool suspend)
1367 shm_acparams_t acp_shm;
1369 struct ieee80211_tx_queue_params *params = arg;
1373 /* Only apply params if the core is out of reset and has clocks */
1375 WL_ERROR("wl%d: %s : no-clock\n", wlc->pub->unit, __func__);
1380 * AP uses AC params from wme_param_ie_ap.
1381 * AP advertises AC params from wme_param_ie.
1382 * STA uses AC params from wme_param_ie.
1385 wlc->wme_admctl = 0;
1388 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1389 /* find out which ac this set of params applies to */
1390 ASSERT(aci < AC_COUNT);
1391 /* set the admission control policy for this AC */
1392 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1394 /* fill in shm ac params struct */
1395 acp_shm.txop = le16_to_cpu(params->txop);
1396 /* convert from units of 32us to us for ucode */
1397 wlc->edcf_txop[aci & 0x3] = acp_shm.txop =
1398 EDCF_TXOP2USEC(acp_shm.txop);
1399 acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK);
1401 if (aci == AC_VI && acp_shm.txop == 0
1402 && acp_shm.aifs < EDCF_AIFSN_MAX)
1405 if (acp_shm.aifs < EDCF_AIFSN_MIN
1406 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1407 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1408 wlc->pub->unit, acp_shm.aifs);
1412 acp_shm.cwmin = params->cw_min;
1413 acp_shm.cwmax = params->cw_max;
1414 acp_shm.cwcur = acp_shm.cwmin;
1416 R_REG(&wlc->regs->tsf_random) & acp_shm.cwcur;
1417 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1418 /* Indicate the new params to the ucode */
1419 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1420 wme_shmemacindex(aci) *
1422 M_EDCF_STATUS_OFF));
1423 acp_shm.status |= WME_STATUS_NEWAC;
1425 /* Fill in shm acparam table */
1426 shm_entry = (u16 *) &acp_shm;
1427 for (i = 0; i < (int)sizeof(shm_acparams_t); i += 2)
1430 wme_shmemacindex(aci) * M_EDCF_QLEN + i,
1436 wlc_suspend_mac_and_wait(wlc);
1439 wlc_enable_mac(wlc);
1443 void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1445 struct wlc_info *wlc = cfg->wlc;
1447 edcf_acparam_t *edcf_acp;
1448 shm_acparams_t acp_shm;
1454 /* Only apply params if the core is out of reset and has clocks */
1459 * AP uses AC params from wme_param_ie_ap.
1460 * AP advertises AC params from wme_param_ie.
1461 * STA uses AC params from wme_param_ie.
1464 edcf_acp = (edcf_acparam_t *) &wlc->wme_param_ie.acparam[0];
1466 wlc->wme_admctl = 0;
1468 for (i = 0; i < AC_COUNT; i++, edcf_acp++) {
1469 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1470 /* find out which ac this set of params applies to */
1471 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
1472 ASSERT(aci < AC_COUNT);
1473 /* set the admission control policy for this AC */
1474 if (edcf_acp->ACI & EDCF_ACM_MASK) {
1475 wlc->wme_admctl |= 1 << aci;
1478 /* fill in shm ac params struct */
1479 acp_shm.txop = le16_to_cpu(edcf_acp->TXOP);
1480 /* convert from units of 32us to us for ucode */
1481 wlc->edcf_txop[aci] = acp_shm.txop =
1482 EDCF_TXOP2USEC(acp_shm.txop);
1483 acp_shm.aifs = (edcf_acp->ACI & EDCF_AIFSN_MASK);
1485 if (aci == AC_VI && acp_shm.txop == 0
1486 && acp_shm.aifs < EDCF_AIFSN_MAX)
1489 if (acp_shm.aifs < EDCF_AIFSN_MIN
1490 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1491 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1492 wlc->pub->unit, acp_shm.aifs);
1496 /* CWmin = 2^(ECWmin) - 1 */
1497 acp_shm.cwmin = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK);
1498 /* CWmax = 2^(ECWmax) - 1 */
1499 acp_shm.cwmax = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK)
1500 >> EDCF_ECWMAX_SHIFT);
1501 acp_shm.cwcur = acp_shm.cwmin;
1503 R_REG(&wlc->regs->tsf_random) & acp_shm.cwcur;
1504 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1505 /* Indicate the new params to the ucode */
1506 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1507 wme_shmemacindex(aci) *
1509 M_EDCF_STATUS_OFF));
1510 acp_shm.status |= WME_STATUS_NEWAC;
1512 /* Fill in shm acparam table */
1513 shm_entry = (u16 *) &acp_shm;
1514 for (j = 0; j < (int)sizeof(shm_acparams_t); j += 2)
1517 wme_shmemacindex(aci) * M_EDCF_QLEN + j,
1522 wlc_suspend_mac_and_wait(wlc);
1524 if (AP_ENAB(wlc->pub) && WME_ENAB(wlc->pub)) {
1525 wlc_update_beacon(wlc);
1526 wlc_update_probe_resp(wlc, false);
1530 wlc_enable_mac(wlc);
1534 bool wlc_timers_init(struct wlc_info *wlc, int unit)
1536 wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer,
1538 if (!wlc->wdtimer) {
1539 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit);
1543 wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer,
1545 if (!wlc->radio_timer) {
1546 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit);
1557 * Initialize wlc_info default values ...
1558 * may get overrides later in this function
1560 void wlc_info_init(struct wlc_info *wlc, int unit)
1563 /* Assume the device is there until proven otherwise */
1564 wlc->device_present = true;
1566 /* set default power output percentage to 100 percent */
1567 wlc->txpwr_percent = 100;
1569 /* Save our copy of the chanspec */
1570 wlc->chanspec = CH20MHZ_CHSPEC(1);
1572 /* initialize CCK preamble mode to unassociated state */
1573 wlc->shortpreamble = false;
1575 wlc->legacy_probe = true;
1577 /* various 802.11g modes */
1578 wlc->shortslot = false;
1579 wlc->shortslot_override = WLC_SHORTSLOT_AUTO;
1581 wlc->barker_overlap_control = true;
1582 wlc->barker_preamble = WLC_BARKER_SHORT_ALLOWED;
1583 wlc->txburst_limit_override = AUTO;
1585 wlc_protection_upd(wlc, WLC_PROT_G_OVR, WLC_PROTECTION_AUTO);
1586 wlc_protection_upd(wlc, WLC_PROT_G_SPEC, false);
1588 wlc_protection_upd(wlc, WLC_PROT_N_CFG_OVR, WLC_PROTECTION_AUTO);
1589 wlc_protection_upd(wlc, WLC_PROT_N_CFG, WLC_N_PROTECTION_OFF);
1590 wlc_protection_upd(wlc, WLC_PROT_N_NONGF_OVR, WLC_PROTECTION_AUTO);
1591 wlc_protection_upd(wlc, WLC_PROT_N_NONGF, false);
1592 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR, AUTO);
1594 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, WLC_PROTECTION_CTL_OVERLAP);
1596 /* 802.11g draft 4.0 NonERP elt advertisement */
1597 wlc->include_legacy_erp = true;
1599 wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF;
1600 wlc->stf->txant = ANT_TX_DEF;
1602 wlc->prb_resp_timeout = WLC_PRB_RESP_TIMEOUT;
1604 wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN;
1605 for (i = 0; i < NFIFO; i++)
1606 wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN;
1607 wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN;
1609 /* default rate fallback retry limits */
1610 wlc->SFBL = RETRY_SHORT_FB;
1611 wlc->LFBL = RETRY_LONG_FB;
1613 /* default mac retry limits */
1614 wlc->SRL = RETRY_SHORT_DEF;
1615 wlc->LRL = RETRY_LONG_DEF;
1618 wlc->PM = PM_OFF; /* User's setting of PM mode through IOCTL */
1619 wlc->PM_override = false; /* Prevents from going to PM if our AP is 'ill' */
1620 wlc->PMenabled = false; /* Current PM state */
1621 wlc->PMpending = false; /* Tracks whether STA indicated PM in the last attempt */
1622 wlc->PMblocked = false; /* To allow blocking going into PM during RM and scans */
1624 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1625 wlc->WME_PM_blocked = false;
1627 /* Init wme queuing method */
1628 wlc->wme_prec_queuing = false;
1630 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1632 /* Are we waiting for a response to PS-Poll that we sent */
1633 wlc->PSpoll = false;
1636 wlc->wme_apsd = true;
1637 wlc->apsd_sta_usp = false;
1638 wlc->apsd_trigger_timeout = 0; /* disable the trigger timer */
1639 wlc->apsd_trigger_ac = AC_BITMAP_ALL;
1641 /* Set flag to indicate that hw keys should be used when available. */
1642 wlc->wsec_swkeys = false;
1644 /* init the 4 static WEP default keys */
1645 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
1646 wlc->wsec_keys[i] = wlc->wsec_def_keys[i];
1647 wlc->wsec_keys[i]->idx = (u8) i;
1650 wlc->_regulatory_domain = false; /* 802.11d */
1652 /* WME QoS mode is Auto by default */
1653 wlc->pub->_wme = AUTO;
1655 #ifdef BCMSDIODEV_ENABLED
1656 wlc->pub->_priofc = true; /* enable priority flow control for sdio dongle */
1659 wlc->pub->_ampdu = AMPDU_AGG_HOST;
1660 wlc->pub->bcmerror = 0;
1661 wlc->ibss_allowed = true;
1662 wlc->ibss_coalesce_allowed = true;
1663 wlc->pub->_coex = ON;
1665 /* initialize mpc delay */
1666 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
1668 wlc->pr80838_war = true;
1671 static bool wlc_state_bmac_sync(struct wlc_info *wlc)
1673 wlc_bmac_state_t state_bmac;
1675 if (wlc_bmac_state_get(wlc->hw, &state_bmac) != 0)
1678 wlc->machwcap = state_bmac.machwcap;
1679 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR,
1680 (s8) state_bmac.preamble_ovr);
1685 static uint wlc_attach_module(struct wlc_info *wlc)
1689 unit = wlc->pub->unit;
1691 wlc->asi = wlc_antsel_attach(wlc);
1692 if (wlc->asi == NULL) {
1693 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit);
1698 wlc->ampdu = wlc_ampdu_attach(wlc);
1699 if (wlc->ampdu == NULL) {
1700 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit);
1705 if ((wlc_stf_attach(wlc) != 0)) {
1706 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit);
1714 struct wlc_pub *wlc_pub(void *wlc)
1716 return ((struct wlc_info *) wlc)->pub;
1719 #define CHIP_SUPPORTS_11N(wlc) 1
1722 * The common driver entry routine. Error codes should be unique
1724 void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1725 struct osl_info *osh, void *regsva, uint bustype,
1726 void *btparam, uint *perr)
1728 struct wlc_info *wlc;
1731 struct wlc_pub *pub;
1732 struct wlc_txq_info *qi;
1735 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1736 unit, __func__, vendor, device);
1738 ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS);
1739 ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS);
1741 /* some code depends on packed structures */
1742 ASSERT(sizeof(struct ethhdr) == ETH_HLEN);
1743 ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE);
1744 ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN);
1745 ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN);
1746 ASSERT(sizeof(d11txh_t) == D11_TXH_LEN);
1747 ASSERT(sizeof(d11rxhdr_t) == RXHDR_LEN);
1748 ASSERT(sizeof(struct ieee80211_hdr) == DOT11_A4_HDR_LEN);
1749 ASSERT(sizeof(struct ieee80211_rts) == DOT11_RTS_LEN);
1750 ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN);
1751 ASSERT(sizeof(struct ieee80211_ht_cap) == HT_CAP_IE_LEN);
1753 ASSERT(offsetof(wl_scan_params_t, channel_list) ==
1754 WL_SCAN_PARAMS_FIXED_SIZE);
1756 ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32)));
1757 ASSERT(ISPOWEROF2(MA_WINDOW_SZ));
1759 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
1762 * Number of replay counters value used in WPA IE must match # rxivs
1763 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1764 * 'RSN Information Element' figure 8 for this mapping.
1766 ASSERT((WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1767 && 16 == WLC_NUMRXIVS)
1768 || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1769 && 4 == WLC_NUMRXIVS));
1771 /* allocate struct wlc_info state and its substructures */
1772 wlc = (struct wlc_info *) wlc_attach_malloc(unit, &err, device);
1782 wlc->band = wlc->bandstate[0];
1783 wlc->core = wlc->corestate;
1787 wlc->btparam = btparam;
1788 pub->_piomode = piomode;
1789 wlc->bandinit_pending = false;
1790 /* By default restrict TKIP associations from 11n STA's */
1791 wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT;
1793 /* populate struct wlc_info with default values */
1794 wlc_info_init(wlc, unit);
1796 /* update sta/ap related parameters */
1799 /* 11n_disable nvram */
1800 n_disabled = getintvar(pub->vars, "11n_disable");
1802 /* register a module (to handle iovars) */
1803 wlc_module_register(wlc->pub, wlc_iovars, "wlc_iovars", wlc,
1804 wlc_doiovar, NULL, NULL);
1807 * low level attach steps(all hw accesses go
1808 * inside, no more in rest of the attach)
1810 err = wlc_bmac_attach(wlc, vendor, device, unit, piomode, regsva,
1815 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1816 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1818 if (!wlc_state_bmac_sync(wlc)) {
1823 pub->phy_11ncapable = WLC_PHY_11N_CAP(wlc->band);
1825 /* propagate *vars* from BMAC driver to high driver */
1826 wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size);
1829 /* set maximum allowed duty cycle */
1830 wlc->tx_duty_cycle_ofdm =
1831 (u16) getintvar(pub->vars, "tx_duty_cycle_ofdm");
1832 wlc->tx_duty_cycle_cck =
1833 (u16) getintvar(pub->vars, "tx_duty_cycle_cck");
1835 wlc_stf_phy_chain_calc(wlc);
1837 /* txchain 1: txant 0, txchain 2: txant 1 */
1838 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
1839 wlc->stf->txant = wlc->stf->hw_txchain - 1;
1841 /* push to BMAC driver */
1842 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain,
1843 wlc->stf->hw_rxchain);
1845 /* pull up some info resulting from the low attach */
1848 for (i = 0; i < NFIFO; i++)
1849 wlc->core->txavail[i] = wlc->hw->txavail[i];
1852 wlc_bmac_hw_etheraddr(wlc->hw, wlc->perm_etheraddr);
1854 memcpy(&pub->cur_etheraddr, &wlc->perm_etheraddr, ETH_ALEN);
1856 for (j = 0; j < NBANDS(wlc); j++) {
1857 /* Use band 1 for single band 11a */
1858 if (IS_SINGLEBAND_5G(wlc->deviceid))
1861 wlc->band = wlc->bandstate[j];
1863 if (!wlc_attach_stf_ant_init(wlc)) {
1868 /* default contention windows size limits */
1869 wlc->band->CWmin = APHY_CWMIN;
1870 wlc->band->CWmax = PHY_CWMAX;
1872 /* init gmode value */
1873 if (BAND_2G(wlc->band->bandtype)) {
1874 wlc->band->gmode = GMODE_AUTO;
1875 wlc_protection_upd(wlc, WLC_PROT_G_USER,
1879 /* init _n_enab supported mode */
1880 if (WLC_PHY_11N_CAP(wlc->band) && CHIP_SUPPORTS_11N(wlc)) {
1881 if (n_disabled & WLFEATURE_DISABLE_11N) {
1883 wlc_protection_upd(wlc, WLC_PROT_N_USER, OFF);
1885 pub->_n_enab = SUPPORT_11N;
1886 wlc_protection_upd(wlc, WLC_PROT_N_USER,
1888 SUPPORT_11N) ? WL_11N_2x2 :
1893 /* init per-band default rateset, depend on band->gmode */
1894 wlc_default_rateset(wlc, &wlc->band->defrateset);
1896 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1897 wlc_rateset_filter(&wlc->band->defrateset,
1898 &wlc->band->hw_rateset, false,
1899 WLC_RATES_CCK_OFDM, RATE_MASK,
1900 (bool) N_ENAB(wlc->pub));
1903 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1904 wlc_stf_phy_txant_upd(wlc);
1906 /* attach each modules */
1907 err = wlc_attach_module(wlc);
1911 if (!wlc_timers_init(wlc, unit)) {
1912 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit, __func__);
1917 /* depend on rateset, gmode */
1918 wlc->cmi = wlc_channel_mgr_attach(wlc);
1920 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1926 /* init default when all parameters are ready, i.e. ->rateset */
1927 wlc_bss_default_init(wlc);
1930 * Complete the wlc default state initializations..
1933 /* allocate our initial queue */
1934 qi = wlc_txq_alloc(wlc);
1936 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1941 wlc->active_queue = qi;
1943 wlc->bsscfg[0] = wlc->cfg;
1945 wlc->cfg->wlc = wlc;
1946 pub->txmaxpkts = MAXTXPKTS;
1948 pub->_cnt->version = WL_CNT_T_VERSION;
1949 pub->_cnt->length = sizeof(struct wl_cnt);
1951 WLCNTSET(pub->_wme_cnt->version, WL_WME_CNT_VERSION);
1952 WLCNTSET(pub->_wme_cnt->length, sizeof(wl_wme_cnt_t));
1954 wlc_wme_initparams_sta(wlc, &wlc->wme_param_ie);
1956 wlc->mimoft = FT_HT;
1957 wlc->ht_cap.cap_info = HT_CAP;
1958 if (HT_ENAB(wlc->pub))
1959 wlc->stf->ldpc = AUTO;
1961 wlc->mimo_40txbw = AUTO;
1962 wlc->ofdm_40txbw = AUTO;
1963 wlc->cck_40txbw = AUTO;
1964 wlc_update_mimo_band_bwcap(wlc, WLC_N_BW_20IN2G_40IN5G);
1966 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1967 wlc->rifs_advert = AUTO;
1969 /* Set default values of SGI */
1970 if (WLC_SGI_CAP_PHY(wlc)) {
1971 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1973 } else if (WLCISSSLPNPHY(wlc->band)) {
1974 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1977 wlc_ht_update_sgi_rx(wlc, 0);
1981 /* *******nvram 11n config overrides Start ********* */
1983 /* apply the sgi override from nvram conf */
1984 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_TX)
1987 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_RX)
1988 wlc_ht_update_sgi_rx(wlc, 0);
1990 /* apply the stbc override from nvram conf */
1991 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_TX) {
1992 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
1993 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
1994 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_TX_STBC;
1996 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_RX)
1997 wlc_stf_stbc_rx_set(wlc, HT_CAP_RX_STBC_NO);
1999 /* apply the GF override from nvram conf */
2000 if (n_disabled & WLFEATURE_DISABLE_11N_GF)
2001 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_GRN_FLD;
2003 /* initialize radio_mpc_disable according to wlc->mpc */
2004 wlc_radio_mpc_upd(wlc);
2006 if ((wlc->pub->sih->chip) == BCM43235_CHIP_ID) {
2007 if ((getintvar(wlc->pub->vars, "aa2g") == 7) ||
2008 (getintvar(wlc->pub->vars, "aa5g") == 7)) {
2009 wlc_bmac_antsel_set(wlc->hw, 1);
2012 wlc_bmac_antsel_set(wlc->hw, wlc->asi->antsel_avail);
2021 WL_ERROR("wl%d: %s: failed with err %d\n", unit, __func__, err);
2030 static void wlc_attach_antgain_init(struct wlc_info *wlc)
2033 unit = wlc->pub->unit;
2035 if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) {
2036 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2037 wlc->band->antgain = 8;
2038 } else if (wlc->band->antgain == -1) {
2039 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2041 wlc->band->antgain = 8;
2044 /* Older sroms specified gain in whole dbm only. In order
2045 * be able to specify qdbm granularity and remain backward compatible
2046 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2047 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2048 * -32 - 31. Examples: 0x1 = 1 db,
2049 * 0xc1 = 1.75 db (1 + 3 quarters),
2050 * 0x3f = -1 (-1 + 0 quarters),
2051 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2052 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2054 gain = wlc->band->antgain & 0x3f;
2055 gain <<= 2; /* Sign extend */
2057 fract = (wlc->band->antgain & 0xc0) >> 6;
2058 wlc->band->antgain = 4 * gain + fract;
2062 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc)
2069 unit = wlc->pub->unit;
2070 vars = wlc->pub->vars;
2071 bandtype = wlc->band->bandtype;
2073 /* get antennas available */
2074 aa = (s8) getintvar(vars, (BAND_5G(bandtype) ? "aa5g" : "aa2g"));
2076 aa = (s8) getintvar(vars,
2077 (BAND_5G(bandtype) ? "aa1" : "aa0"));
2078 if ((aa < 1) || (aa > 15)) {
2079 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2080 unit, __func__, aa);
2084 /* reset the defaults if we have a single antenna */
2086 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0;
2087 wlc->stf->txant = ANT_TX_FORCE_0;
2088 } else if (aa == 2) {
2089 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1;
2090 wlc->stf->txant = ANT_TX_FORCE_1;
2094 /* Compute Antenna Gain */
2095 wlc->band->antgain =
2096 (s8) getintvar(vars, (BAND_5G(bandtype) ? "ag1" : "ag0"));
2097 wlc_attach_antgain_init(wlc);
2103 static void wlc_timers_deinit(struct wlc_info *wlc)
2105 /* free timer state */
2107 wl_free_timer(wlc->wl, wlc->wdtimer);
2108 wlc->wdtimer = NULL;
2110 if (wlc->radio_timer) {
2111 wl_free_timer(wlc->wl, wlc->radio_timer);
2112 wlc->radio_timer = NULL;
2116 static void wlc_detach_module(struct wlc_info *wlc)
2119 wlc_antsel_detach(wlc->asi);
2124 wlc_ampdu_detach(wlc->ampdu);
2128 wlc_stf_detach(wlc);
2132 * Return a count of the number of driver callbacks still pending.
2134 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2135 * touch hardware registers since the d11core may be in reset and clock may not be available.
2136 * One exception is sb register access, which is possible if crystal is turned on
2137 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2139 uint wlc_detach(struct wlc_info *wlc)
2147 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
2149 ASSERT(!wlc->pub->up);
2151 callbacks += wlc_bmac_detach(wlc);
2153 /* delete software timers */
2154 if (!wlc_radio_monitor_stop(wlc))
2157 wlc_channel_mgr_detach(wlc->cmi);
2159 wlc_timers_deinit(wlc);
2161 wlc_detach_module(wlc);
2163 /* free other state */
2167 if (wlc->country_ie_override) {
2168 kfree(wlc->country_ie_override);
2169 wlc->country_ie_override = NULL;
2174 /* free dumpcb list */
2175 struct dumpcb_s *prev, *ptr;
2176 prev = ptr = wlc->dumpcb_head;
2182 wlc->dumpcb_head = NULL;
2185 /* Detach from iovar manager */
2186 wlc_module_unregister(wlc->pub, "wlc_iovars", wlc);
2188 while (wlc->tx_queues != NULL)
2189 wlc_txq_free(wlc, wlc->tx_queues);
2192 * consistency check: wlc_module_register/wlc_module_unregister calls
2193 * should match therefore nothing should be left here.
2195 for (i = 0; i < WLC_MAXMODULES; i++)
2196 ASSERT(wlc->modulecb[i].name[0] == '\0');
2198 wlc_detach_mfree(wlc);
2202 /* update state that depends on the current value of "ap" */
2203 void wlc_ap_upd(struct wlc_info *wlc)
2205 if (AP_ENAB(wlc->pub))
2206 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */
2208 wlc->PLCPHdr_override = WLC_PLCP_SHORT; /* STA-BSS; short capable */
2210 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2211 wlc->vlan_mode = AP_ENAB(wlc->pub) ? OFF : AUTO;
2217 /* read hwdisable state and propagate to wlc flag */
2218 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc)
2220 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off)
2223 if (wlc_bmac_radio_read_hwdisabled(wlc->hw)) {
2224 mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2226 mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2230 /* return true if Minimum Power Consumption should be entered, false otherwise */
2231 bool wlc_is_non_delay_mpc(struct wlc_info *wlc)
2236 bool wlc_ismpc(struct wlc_info *wlc)
2238 return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc));
2241 void wlc_radio_mpc_upd(struct wlc_info *wlc)
2243 bool mpc_radio, radio_state;
2246 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2247 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2248 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2249 * the radio is going down.
2252 if (!wlc->pub->radio_disabled)
2254 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2256 if (!wlc->pub->radio_disabled)
2257 wlc_radio_monitor_stop(wlc);
2262 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2263 * to go ON, always call radio_upd synchronously
2264 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2267 (mboolisset(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE) ? OFF :
2269 mpc_radio = (wlc_ismpc(wlc) == true) ? OFF : ON;
2271 if (radio_state == ON && mpc_radio == OFF)
2272 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2273 else if (radio_state == OFF && mpc_radio == ON) {
2274 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2276 if (wlc->mpc_offcnt < WLC_MPC_THRESHOLD) {
2277 wlc->mpc_dlycnt = WLC_MPC_MAX_DELAYCNT;
2279 wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
2280 wlc->mpc_dur += OSL_SYSUPTIME() - wlc->mpc_laston_ts;
2282 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2283 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2284 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2286 if ((wlc->prev_non_delay_mpc == false) &&
2287 (wlc_is_non_delay_mpc(wlc) == true) && wlc->mpc_delay_off) {
2288 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2290 wlc->prev_non_delay_mpc = wlc_is_non_delay_mpc(wlc);
2294 * centralized radio disable/enable function,
2295 * invoke radio enable/disable after updating hwradio status
2297 static void wlc_radio_upd(struct wlc_info *wlc)
2299 if (wlc->pub->radio_disabled) {
2300 wlc_radio_disable(wlc);
2302 wlc_radio_enable(wlc);
2306 /* maintain LED behavior in down state */
2307 static void wlc_down_led_upd(struct wlc_info *wlc)
2309 ASSERT(!wlc->pub->up);
2311 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2312 /* turn on sbclk if necessary */
2313 if (!AP_ENAB(wlc->pub)) {
2314 wlc_pllreq(wlc, true, WLC_PLLREQ_FLIP);
2316 wlc_pllreq(wlc, false, WLC_PLLREQ_FLIP);
2320 /* update hwradio status and return it */
2321 bool wlc_check_radio_disabled(struct wlc_info *wlc)
2323 wlc_radio_hwdisable_upd(wlc);
2325 return mboolisset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE) ? true : false;
2328 void wlc_radio_disable(struct wlc_info *wlc)
2330 if (!wlc->pub->up) {
2331 wlc_down_led_upd(wlc);
2335 wlc_radio_monitor_start(wlc);
2339 static void wlc_radio_enable(struct wlc_info *wlc)
2344 if (DEVICEREMOVED(wlc))
2347 if (!wlc->down_override) { /* imposed by wl down/out ioctl */
2352 /* periodical query hw radio button while driver is "down" */
2353 static void wlc_radio_timer(void *arg)
2355 struct wlc_info *wlc = (struct wlc_info *) arg;
2357 if (DEVICEREMOVED(wlc)) {
2358 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2363 /* cap mpc off count */
2364 if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT)
2367 /* validate all the reasons driver could be down and running this radio_timer */
2368 ASSERT(wlc->pub->radio_disabled || wlc->down_override);
2369 wlc_radio_hwdisable_upd(wlc);
2373 static bool wlc_radio_monitor_start(struct wlc_info *wlc)
2375 /* Don't start the timer if HWRADIO feature is disabled */
2376 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
2379 wlc->radio_monitor = true;
2380 wlc_pllreq(wlc, true, WLC_PLLREQ_RADIO_MON);
2381 wl_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true);
2385 bool wlc_radio_monitor_stop(struct wlc_info *wlc)
2387 if (!wlc->radio_monitor)
2390 ASSERT((wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO) !=
2393 wlc->radio_monitor = false;
2394 wlc_pllreq(wlc, false, WLC_PLLREQ_RADIO_MON);
2395 return wl_del_timer(wlc->wl, wlc->radio_timer);
2398 /* bring the driver down, but don't reset hardware */
2399 void wlc_out(struct wlc_info *wlc)
2401 wlc_bmac_set_noreset(wlc->hw, true);
2404 wlc_bmac_set_noreset(wlc->hw, false);
2406 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2409 /* This will make sure that when 'up' is done
2410 * after 'out' it'll restore hardware (especially gpios)
2412 wlc->pub->hw_up = false;
2416 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2417 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2418 * in prec_map. Of course, ignore this rule when block_datafifo is set
2420 static bool wlc_tx_prec_map_verify(struct wlc_info *wlc)
2422 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2425 if (!EDCF_ENAB(wlc->pub)) {
2426 if (!(WLC_TX_FIFO_CHECK(wlc, TX_DATA_FIFO) ||
2427 WLC_TX_FIFO_CHECK(wlc, TX_CTL_FIFO)))
2433 return WLC_TX_FIFO_CHECK(wlc, TX_AC_BK_FIFO)
2434 && WLC_TX_FIFO_CHECK(wlc, TX_AC_BE_FIFO)
2435 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VI_FIFO)
2436 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VO_FIFO);
2440 static void wlc_watchdog_by_timer(void *arg)
2442 struct wlc_info *wlc = (struct wlc_info *) arg;
2444 if (WLC_WATCHDOG_TBTT(wlc)) {
2445 /* set to normal osl watchdog period */
2446 wl_del_timer(wlc->wl, wlc->wdtimer);
2447 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
2452 /* common watchdog code */
2453 static void wlc_watchdog(void *arg)
2455 struct wlc_info *wlc = (struct wlc_info *) arg;
2459 WL_TRACE("wl%d: wlc_watchdog\n", wlc->pub->unit);
2464 if (DEVICEREMOVED(wlc)) {
2465 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2470 /* increment second count */
2473 /* delay radio disable */
2474 if (wlc->mpc_delay_off) {
2475 if (--wlc->mpc_delay_off == 0) {
2476 mboolset(wlc->pub->radio_disabled,
2477 WL_RADIO_MPC_DISABLE);
2478 if (wlc->mpc && wlc_ismpc(wlc))
2479 wlc->mpc_offcnt = 0;
2480 wlc->mpc_laston_ts = OSL_SYSUPTIME();
2485 wlc_radio_mpc_upd(wlc);
2486 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2487 wlc_radio_hwdisable_upd(wlc);
2489 /* if ismpc, driver should be in down state if up/down is allowed */
2490 if (wlc->mpc && wlc_ismpc(wlc))
2491 ASSERT(!wlc->pub->up);
2492 /* if radio is disable, driver may be down, quit here */
2493 if (wlc->pub->radio_disabled)
2496 wlc_bmac_watchdog(wlc);
2498 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2499 if ((wlc->pub->now % SW_TIMER_MAC_STAT_UPD) == 0)
2502 /* Manage TKIP countermeasures timers */
2503 FOREACH_BSS(wlc, i, cfg) {
2504 if (cfg->tk_cm_dt) {
2507 if (cfg->tk_cm_bt) {
2512 /* Call any registered watchdog handlers */
2513 for (i = 0; i < WLC_MAXMODULES; i++) {
2514 if (wlc->modulecb[i].watchdog_fn)
2515 wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl);
2518 if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable &&
2519 ((wlc->pub->now - wlc->tempsense_lasttime) >=
2520 WLC_TEMPSENSE_PERIOD)) {
2521 wlc->tempsense_lasttime = wlc->pub->now;
2522 wlc_tempsense_upd(wlc);
2524 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2525 ASSERT(wlc_bmac_taclear(wlc->hw, true));
2527 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2528 ASSERT(wlc_tx_prec_map_verify(wlc));
2530 ASSERT(wlc_ps_check(wlc));
2533 /* make interface operational */
2534 int wlc_up(struct wlc_info *wlc)
2536 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2538 /* HW is turned off so don't try to access it */
2539 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
2540 return BCME_RADIOOFF;
2542 if (!wlc->pub->hw_up) {
2543 wlc_bmac_hw_up(wlc->hw);
2544 wlc->pub->hw_up = true;
2547 if ((wlc->pub->boardflags & BFL_FEM)
2548 && (wlc->pub->sih->chip == BCM4313_CHIP_ID)) {
2549 if (wlc->pub->boardrev >= 0x1250
2550 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2551 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
2552 MHF5_4313_GPIOCTRL, WLC_BAND_ALL);
2554 wlc_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE, MHF4_EXTPA_ENABLE,
2560 * Need to read the hwradio status here to cover the case where the system
2561 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2562 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2563 * don't call radio_update to avoid looping wlc_up.
2565 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2567 if (!wlc->pub->radio_disabled) {
2568 int status = wlc_bmac_up_prep(wlc->hw);
2569 if (status == BCME_RADIOOFF) {
2571 (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) {
2573 wlc_bsscfg_t *bsscfg;
2574 mboolset(wlc->pub->radio_disabled,
2575 WL_RADIO_HW_DISABLE);
2577 FOREACH_BSS(wlc, idx, bsscfg) {
2578 if (!BSSCFG_STA(bsscfg)
2579 || !bsscfg->enable || !bsscfg->BSS)
2581 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2582 wlc->pub->unit, idx);
2589 if (wlc->pub->radio_disabled) {
2590 wlc_radio_monitor_start(wlc);
2594 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2597 wlc_radio_monitor_stop(wlc);
2599 /* Set EDCF hostflags */
2600 if (EDCF_ENAB(wlc->pub)) {
2601 wlc_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL);
2603 wlc_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL);
2606 if (WLC_WAR16165(wlc))
2607 wlc_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR,
2611 wlc->pub->up = true;
2613 if (wlc->bandinit_pending) {
2614 wlc_suspend_mac_and_wait(wlc);
2615 wlc_set_chanspec(wlc, wlc->default_bss->chanspec);
2616 wlc->bandinit_pending = false;
2617 wlc_enable_mac(wlc);
2620 wlc_bmac_up_finish(wlc->hw);
2622 /* other software states up after ISR is running */
2623 /* start APs that were to be brought up but are not up yet */
2624 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2626 /* Program the TX wme params with the current settings */
2627 wlc_wme_retries_write(wlc);
2629 /* start one second watchdog timer */
2630 ASSERT(!wlc->WDarmed);
2631 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true);
2632 wlc->WDarmed = true;
2634 /* ensure antenna config is up to date */
2635 wlc_stf_phy_txant_upd(wlc);
2636 /* ensure LDPC config is in sync */
2637 wlc_ht_update_ldpc(wlc, wlc->stf->ldpc);
2642 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2643 static void wlc_tx_prec_map_init(struct wlc_info *wlc)
2645 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2646 memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16));
2648 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2649 * if either is full.
2651 if (!EDCF_ENAB(wlc->pub)) {
2652 wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL;
2653 wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL;
2655 wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK;
2656 wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE;
2657 wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI;
2658 wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO;
2662 static uint wlc_down_del_timer(struct wlc_info *wlc)
2670 * Mark the interface nonoperational, stop the software mechanisms,
2671 * disable the hardware, free any transient buffer state.
2672 * Return a count of the number of driver callbacks still pending.
2674 uint wlc_down(struct wlc_info *wlc)
2679 bool dev_gone = false;
2680 struct wlc_txq_info *qi;
2682 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2684 /* check if we are already in the going down path */
2685 if (wlc->going_down) {
2686 WL_ERROR("wl%d: %s: Driver going down so return\n",
2687 wlc->pub->unit, __func__);
2693 /* in between, mpc could try to bring down again.. */
2694 wlc->going_down = true;
2696 callbacks += wlc_bmac_down_prep(wlc->hw);
2698 dev_gone = DEVICEREMOVED(wlc);
2700 /* Call any registered down handlers */
2701 for (i = 0; i < WLC_MAXMODULES; i++) {
2702 if (wlc->modulecb[i].down_fn)
2704 wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
2707 /* cancel the watchdog timer */
2709 if (!wl_del_timer(wlc->wl, wlc->wdtimer))
2711 wlc->WDarmed = false;
2713 /* cancel all other timers */
2714 callbacks += wlc_down_del_timer(wlc);
2716 /* interrupt must have been blocked */
2717 ASSERT((wlc->macintmask == 0) || !wlc->pub->up);
2719 wlc->pub->up = false;
2721 wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL);
2723 /* clear txq flow control */
2724 wlc_txflowcontrol_reset(wlc);
2726 /* flush tx queues */
2727 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
2728 pktq_flush(wlc->osh, &qi->q, true, NULL, 0);
2729 ASSERT(pktq_empty(&qi->q));
2732 callbacks += wlc_bmac_down_finish(wlc->hw);
2734 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2738 /* Verify all packets are flushed from the driver */
2739 if (wlc->osh->pktalloced != 0) {
2740 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2741 wlc->osh->pktalloced);
2744 /* Since all the packets should have been freed,
2745 * all callbacks should have been called
2747 for (i = 1; i <= wlc->pub->tunables->maxpktcb; i++)
2748 ASSERT(wlc->pkt_callback[i].fn == NULL);
2750 wlc->going_down = false;
2754 /* Set the current gmode configuration */
2755 int wlc_set_gmode(struct wlc_info *wlc, u8 gmode, bool config)
2760 /* Default to 54g Auto */
2761 s8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2762 bool shortslot_restrict = false; /* Restrict association to stations that support shortslot
2764 bool ignore_bcns = true; /* Ignore legacy beacons on the same channel */
2765 bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */
2766 int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2767 bool preamble_restrict = false; /* Restrict association to stations that support short
2770 struct wlcband *band;
2772 /* if N-support is enabled, allow Gmode set as long as requested
2773 * Gmode is not GMODE_LEGACY_B
2775 if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B)
2776 return BCME_UNSUPPORTED;
2778 /* verify that we are dealing with 2G band and grab the band pointer */
2779 if (wlc->band->bandtype == WLC_BAND_2G)
2781 else if ((NBANDS(wlc) > 1) &&
2782 (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G))
2783 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
2785 return BCME_BADBAND;
2787 /* Legacy or bust when no OFDM is supported by regulatory */
2788 if ((wlc_channel_locale_flags_in_band(wlc->cmi, band->bandunit) &
2789 WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B))
2792 /* update configuration value */
2794 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode);
2796 /* Clear supported rates filter */
2797 memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t));
2799 /* Clear rateset override */
2800 memset(&rs, 0, sizeof(wlc_rateset_t));
2803 case GMODE_LEGACY_B:
2804 shortslot = WLC_SHORTSLOT_OFF;
2805 wlc_rateset_copy(&gphy_legacy_rates, &rs);
2810 if (AP_ENAB(wlc->pub))
2811 wlc_rateset_copy(&cck_rates, &wlc->sup_rates_override);
2815 /* Accept defaults */
2820 preamble = WLC_PLCP_SHORT;
2821 preamble_restrict = true;
2824 case GMODE_PERFORMANCE:
2825 if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */
2826 wlc_rateset_copy(&cck_ofdm_rates,
2827 &wlc->sup_rates_override);
2829 shortslot = WLC_SHORTSLOT_ON;
2830 shortslot_restrict = true;
2832 preamble = WLC_PLCP_SHORT;
2833 preamble_restrict = true;
2838 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2839 wlc->pub->unit, __func__, gmode);
2840 return BCME_UNSUPPORTED;
2844 * If we are switching to gmode == GMODE_LEGACY_B,
2845 * clean up rate info that may refer to OFDM rates.
2847 if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) {
2848 band->gmode = gmode;
2849 if (band->rspec_override && !IS_CCK(band->rspec_override)) {
2850 band->rspec_override = 0;
2851 wlc_reprate_init(wlc);
2853 if (band->mrspec_override && !IS_CCK(band->mrspec_override)) {
2854 band->mrspec_override = 0;
2858 band->gmode = gmode;
2860 wlc->ignore_bcns = ignore_bcns;
2862 wlc->shortslot_override = shortslot;
2864 if (AP_ENAB(wlc->pub)) {
2865 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2866 wlc->PLCPHdr_override =
2868 WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO;
2871 if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG)
2872 || preamble == WLC_PLCP_SHORT)
2873 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2875 wlc->default_bss->capability &= ~WLAN_CAPABILITY_SHORT_PREAMBLE;
2877 /* Update shortslot capability bit for AP and IBSS */
2878 if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) ||
2879 shortslot == WLC_SHORTSLOT_ON)
2880 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2882 wlc->default_bss->capability &=
2883 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
2885 /* Use the default 11g rateset */
2887 wlc_rateset_copy(&cck_ofdm_rates, &rs);
2890 for (i = 0; i < rs.count; i++) {
2891 if (rs.rates[i] == WLC_RATE_6M
2892 || rs.rates[i] == WLC_RATE_12M
2893 || rs.rates[i] == WLC_RATE_24M)
2894 rs.rates[i] |= WLC_RATE_FLAG;
2898 /* Set default bss rateset */
2899 wlc->default_bss->rateset.count = rs.count;
2900 memcpy(wlc->default_bss->rateset.rates, rs.rates,
2901 sizeof(wlc->default_bss->rateset.rates));
2906 static int wlc_nmode_validate(struct wlc_info *wlc, s32 nmode)
2918 if (!(WLC_PHY_11N_CAP(wlc->band)))
2930 int wlc_set_nmode(struct wlc_info *wlc, s32 nmode)
2935 err = wlc_nmode_validate(wlc, nmode);
2942 wlc->pub->_n_enab = OFF;
2943 wlc->default_bss->flags &= ~WLC_BSS_HT;
2944 /* delete the mcs rates from the default and hw ratesets */
2945 wlc_rateset_mcs_clear(&wlc->default_bss->rateset);
2946 for (i = 0; i < NBANDS(wlc); i++) {
2947 memset(wlc->bandstate[i]->hw_rateset.mcs, 0,
2949 if (IS_MCS(wlc->band->rspec_override)) {
2950 wlc->bandstate[i]->rspec_override = 0;
2951 wlc_reprate_init(wlc);
2953 if (IS_MCS(wlc->band->mrspec_override))
2954 wlc->bandstate[i]->mrspec_override = 0;
2959 if (wlc->stf->txstreams == WL_11N_3x3)
2965 ASSERT(WLC_PHY_11N_CAP(wlc->band));
2966 /* force GMODE_AUTO if NMODE is ON */
2967 wlc_set_gmode(wlc, GMODE_AUTO, true);
2968 if (nmode == WL_11N_3x3)
2969 wlc->pub->_n_enab = SUPPORT_HT;
2971 wlc->pub->_n_enab = SUPPORT_11N;
2972 wlc->default_bss->flags |= WLC_BSS_HT;
2973 /* add the mcs rates to the default and hw ratesets */
2974 wlc_rateset_mcs_build(&wlc->default_bss->rateset,
2975 wlc->stf->txstreams);
2976 for (i = 0; i < NBANDS(wlc); i++)
2977 memcpy(wlc->bandstate[i]->hw_rateset.mcs,
2978 wlc->default_bss->rateset.mcs, MCSSET_LEN);
2989 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg)
2991 wlc_rateset_t rs, new;
2994 memcpy(&rs, rs_arg, sizeof(wlc_rateset_t));
2996 /* check for bad count value */
2997 if ((rs.count == 0) || (rs.count > WLC_NUMRATES))
2998 return BCME_BADRATESET;
3000 /* try the current band */
3001 bandunit = wlc->band->bandunit;
3002 memcpy(&new, &rs, sizeof(wlc_rateset_t));
3003 if (wlc_rate_hwrs_filter_sort_validate
3004 (&new, &wlc->bandstate[bandunit]->hw_rateset, true,
3005 wlc->stf->txstreams))
3008 /* try the other band */
3009 if (IS_MBAND_UNLOCKED(wlc)) {
3010 bandunit = OTHERBANDUNIT(wlc);
3011 memcpy(&new, &rs, sizeof(wlc_rateset_t));
3012 if (wlc_rate_hwrs_filter_sort_validate(&new,
3014 bandstate[bandunit]->
3016 wlc->stf->txstreams))
3023 /* apply new rateset */
3024 memcpy(&wlc->default_bss->rateset, &new, sizeof(wlc_rateset_t));
3025 memcpy(&wlc->bandstate[bandunit]->defrateset, &new,
3026 sizeof(wlc_rateset_t));
3030 /* simplified integer set interface for common ioctl handler */
3031 int wlc_set(struct wlc_info *wlc, int cmd, int arg)
3033 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
3036 /* simplified integer get interface for common ioctl handler */
3037 int wlc_get(struct wlc_info *wlc, int cmd, int *arg)
3039 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL);
3042 static void wlc_ofdm_rateset_war(struct wlc_info *wlc)
3047 if (wlc->cfg->associated)
3048 r = wlc->cfg->current_bss->rateset.rates[0];
3050 r = wlc->default_bss->rateset.rates[0];
3052 wlc_phy_ofdm_rateset_war(wlc->band->pi, war);
3058 wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3059 struct wlc_if *wlcif)
3061 return _wlc_ioctl(wlc, cmd, arg, len, wlcif);
3064 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3066 _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3067 struct wlc_if *wlcif)
3074 struct scb *nextscb;
3078 wlc_bsscfg_t *bsscfg;
3079 wlc_bss_info_t *current_bss;
3081 /* update bsscfg pointer */
3082 bsscfg = NULL; /* XXX: Hack bsscfg to be size one and use this globally */
3085 /* initialize the following to get rid of compiler warning */
3091 /* If the device is turned off, then it's not "removed" */
3092 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
3093 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
3098 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
3100 /* default argument is generic integer */
3101 pval = arg ? (int *)arg:NULL;
3103 /* This will prevent the misaligned access */
3104 if (pval && (u32) len >= sizeof(val))
3105 memcpy(&val, pval, sizeof(val));
3109 /* bool conversion to avoid duplication below */
3110 bool_val = val != 0;
3112 if (cmd != WLC_SET_CHANNEL)
3113 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3114 cmd, (uint)val, val, len);
3119 /* A few commands don't need any arguments; all the others do. */
3127 case WLC_START_CHANNEL_QA:
3132 if ((arg == NULL) || (len <= 0)) {
3133 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3134 wlc->pub->unit, __func__, cmd);
3135 bcmerror = BCME_BADARG;
3143 case WLC_GET_MSGLEVEL:
3144 *pval = wl_msg_level;
3147 case WLC_SET_MSGLEVEL:
3152 case WLC_GET_INSTANCE:
3153 *pval = wlc->pub->unit;
3156 case WLC_GET_CHANNEL:{
3157 channel_info_t *ci = (channel_info_t *) arg;
3159 ASSERT(len > (int)sizeof(ci));
3162 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC);
3163 ci->target_channel =
3164 CHSPEC_CHANNEL(wlc->default_bss->chanspec);
3165 ci->scan_channel = 0;
3170 case WLC_SET_CHANNEL:{
3171 chanspec_t chspec = CH20MHZ_CHSPEC(val);
3173 if (val < 0 || val > MAXCHANNEL) {
3174 bcmerror = BCME_OUTOFRANGECHAN;
3178 if (!wlc_valid_chanspec_db(wlc->cmi, chspec)) {
3179 bcmerror = BCME_BADCHAN;
3183 if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) {
3184 if (wlc->band->bandunit !=
3185 CHSPEC_WLCBANDUNIT(chspec))
3186 wlc->bandinit_pending = true;
3188 wlc->bandinit_pending = false;
3191 wlc->default_bss->chanspec = chspec;
3192 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3194 (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) {
3195 wlc_set_home_chanspec(wlc, chspec);
3196 wlc_suspend_mac_and_wait(wlc);
3197 wlc_set_chanspec(wlc, chspec);
3198 wlc_enable_mac(wlc);
3204 case WLC_GET_UCFLAGS:
3205 if (!wlc->pub->up) {
3206 bcmerror = BCME_NOTUP;
3210 /* optional band is stored in the second integer of incoming buffer */
3213 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3215 /* bcmerror checking */
3216 bcmerror = wlc_iocregchk(wlc, band);
3220 if (val >= MHFMAX) {
3221 bcmerror = BCME_RANGE;
3225 *pval = wlc_bmac_mhf_get(wlc->hw, (u8) val, WLC_BAND_AUTO);
3228 case WLC_SET_UCFLAGS:
3229 if (!wlc->pub->up) {
3230 bcmerror = BCME_NOTUP;
3234 /* optional band is stored in the second integer of incoming buffer */
3237 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3239 /* bcmerror checking */
3240 bcmerror = wlc_iocregchk(wlc, band);
3246 bcmerror = BCME_RANGE;
3250 wlc_mhf(wlc, (u8) i, 0xffff, (u16) (val >> NBITS(u16)),
3257 /* optional band is stored in the second integer of incoming buffer */
3260 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3262 /* bcmerror checking */
3263 bcmerror = wlc_iocregchk(wlc, band);
3268 bcmerror = BCME_BADADDR;
3272 *pval = wlc_read_shm(wlc, (u16) val);
3278 /* optional band is stored in the second integer of incoming buffer */
3281 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3283 /* bcmerror checking */
3284 bcmerror = wlc_iocregchk(wlc, band);
3289 bcmerror = BCME_BADADDR;
3293 wlc_write_shm(wlc, (u16) val,
3294 (u16) (val >> NBITS(u16)));
3297 case WLC_R_REG: /* MAC registers */
3299 r = (rw_reg_t *) arg;
3300 band = WLC_BAND_AUTO;
3302 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3303 bcmerror = BCME_BUFTOOSHORT;
3307 if (len >= (int)sizeof(rw_reg_t))
3310 /* bcmerror checking */
3311 bcmerror = wlc_iocregchk(wlc, band);
3315 if ((r->byteoff + r->size) > sizeof(d11regs_t)) {
3316 bcmerror = BCME_BADADDR;
3319 if (r->size == sizeof(u32))
3321 R_REG((u32 *)((unsigned char *)(unsigned long)regs +
3323 else if (r->size == sizeof(u16))
3325 R_REG((u16 *)((unsigned char *)(unsigned long)regs +
3328 bcmerror = BCME_BADADDR;
3333 r = (rw_reg_t *) arg;
3334 band = WLC_BAND_AUTO;
3336 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3337 bcmerror = BCME_BUFTOOSHORT;
3341 if (len >= (int)sizeof(rw_reg_t))
3344 /* bcmerror checking */
3345 bcmerror = wlc_iocregchk(wlc, band);
3349 if (r->byteoff + r->size > sizeof(d11regs_t)) {
3350 bcmerror = BCME_BADADDR;
3353 if (r->size == sizeof(u32))
3354 W_REG((u32 *)((unsigned char *)(unsigned long) regs +
3355 r->byteoff), r->val);
3356 else if (r->size == sizeof(u16))
3357 W_REG((u16 *)((unsigned char *)(unsigned long) regs +
3358 r->byteoff), r->val);
3360 bcmerror = BCME_BADADDR;
3365 *pval = wlc->stf->txant;
3369 bcmerror = wlc_stf_ant_txant_validate(wlc, (s8) val);
3373 wlc->stf->txant = (s8) val;
3375 /* if down, we are done */
3379 wlc_suspend_mac_and_wait(wlc);
3381 wlc_stf_phy_txant_upd(wlc);
3382 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
3384 wlc_enable_mac(wlc);
3388 case WLC_GET_ANTDIV:{
3391 /* return configured value if core is down */
3392 if (!wlc->pub->up) {
3393 *pval = wlc->stf->ant_rx_ovr;
3396 if (wlc_phy_ant_rxdiv_get
3397 (wlc->band->pi, &phy_antdiv))
3398 *pval = (int)phy_antdiv;
3400 *pval = (int)wlc->stf->ant_rx_ovr;
3405 case WLC_SET_ANTDIV:
3406 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3407 if ((val < -1) || (val > 3)) {
3408 bcmerror = BCME_RANGE;
3413 val = ANT_RX_DIV_DEF;
3415 wlc->stf->ant_rx_ovr = (u8) val;
3416 wlc_phy_ant_rxdiv_set(wlc->band->pi, (u8) val);
3419 case WLC_GET_RX_ANT:{ /* get latest used rx antenna */
3422 if (!wlc->pub->up) {
3423 bcmerror = BCME_NOTUP;
3427 rxstatus = R_REG(&wlc->regs->phyrxstatus0);
3428 if (rxstatus == 0xdead || rxstatus == (u16) -1) {
3429 bcmerror = BCME_ERROR;
3432 *pval = (rxstatus & PRXS0_RXANT_UPSUBBAND) ? 1 : 0;
3437 case WLC_GET_UCANTDIV:
3439 bcmerror = BCME_NOCLK;
3444 (wlc_bmac_mhf_get(wlc->hw, MHF1, WLC_BAND_AUTO) &
3448 case WLC_SET_UCANTDIV:{
3449 if (!wlc->pub->up) {
3450 bcmerror = BCME_NOTUP;
3454 /* if multiband, band must be locked */
3455 if (IS_MBAND_UNLOCKED(wlc)) {
3456 bcmerror = BCME_NOTBANDLOCKED;
3460 wlc_mhf(wlc, MHF1, MHF1_ANTDIV,
3461 (val ? MHF1_ANTDIV : 0), WLC_BAND_AUTO);
3464 #endif /* defined(BCMDBG) */
3471 if (val >= 1 && val <= RETRY_SHORT_MAX) {
3473 wlc->SRL = (u16) val;
3475 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3477 for (ac = 0; ac < AC_COUNT; ac++) {
3478 WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL);
3480 wlc_wme_retries_write(wlc);
3482 bcmerror = BCME_RANGE;
3490 if (val >= 1 && val <= 255) {
3492 wlc->LRL = (u16) val;
3494 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3496 for (ac = 0; ac < AC_COUNT; ac++) {
3497 WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL);
3499 wlc_wme_retries_write(wlc);
3501 bcmerror = BCME_RANGE;
3505 *pval = wlc->band->CWmin;
3510 bcmerror = BCME_NOCLK;
3514 if (val >= 1 && val <= 255) {
3515 wlc_set_cwmin(wlc, (u16) val);
3517 bcmerror = BCME_RANGE;
3521 *pval = wlc->band->CWmax;
3526 bcmerror = BCME_NOCLK;
3530 if (val >= 255 && val <= 2047) {
3531 wlc_set_cwmax(wlc, (u16) val);
3533 bcmerror = BCME_RANGE;
3536 case WLC_GET_RADIO: /* use mask if don't want to expose some internal bits */
3537 *pval = wlc->pub->radio_disabled;
3540 case WLC_SET_RADIO:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3543 u16 radiomask, radioval;
3545 WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE;
3548 radiomask = (val & 0xffff0000) >> 16;
3549 radioval = val & 0x0000ffff;
3551 if ((radiomask == 0) || (radiomask & ~validbits)
3552 || (radioval & ~validbits)
3553 || ((radioval & ~radiomask) != 0)) {
3554 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3556 bcmerror = BCME_RANGE;
3561 (wlc->pub->radio_disabled & ~radiomask) | radioval;
3562 wlc->pub->radio_disabled = new;
3564 wlc_radio_hwdisable_upd(wlc);
3569 case WLC_GET_PHYTYPE:
3570 *pval = WLC_PHYTYPE(wlc->band->phytype);
3575 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc))) {
3578 wsec_key_t *src_key = wlc->wsec_keys[val];
3580 if (len < (int)sizeof(key)) {
3581 bcmerror = BCME_BUFTOOSHORT;
3585 memset((char *)&key, 0, sizeof(key));
3587 key.index = src_key->id;
3588 key.len = src_key->len;
3589 memcpy(key.data, src_key->data, key.len);
3590 key.algo = src_key->algo;
3591 if (WSEC_SOFTKEY(wlc, src_key, bsscfg))
3592 key.flags |= WL_SOFT_KEY;
3593 if (src_key->flags & WSEC_PRIMARY_KEY)
3594 key.flags |= WL_PRIMARY_KEY;
3596 memcpy(key.ea, src_key->ea, ETH_ALEN);
3599 memcpy(arg, &key, sizeof(key));
3601 bcmerror = BCME_BADKEYIDX;
3603 #endif /* defined(BCMDBG) */
3607 wlc_iovar_op(wlc, "wsec_key", NULL, 0, arg, len, IOV_SET,
3611 case WLC_GET_KEY_SEQ:{
3614 if (len < DOT11_WPA_KEY_RSC_LEN) {
3615 bcmerror = BCME_BUFTOOSHORT;
3619 /* Return the key's tx iv as an EAPOL sequence counter.
3620 * This will be used to supply the RSC value to a supplicant.
3621 * The format is 8 bytes, with least significant in seq[0].
3624 key = WSEC_KEY(wlc, val);
3625 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc)) &&
3627 u8 seq[DOT11_WPA_KEY_RSC_LEN];
3630 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3631 if ((bsscfg->WPA_auth & WPA_AUTH_NONE) &&
3632 is_zero_ether_addr(key->ea)) {
3633 lo = bsscfg->wpa_none_txiv.lo;
3634 hi = bsscfg->wpa_none_txiv.hi;
3640 /* format the buffer, low to high */
3642 seq[1] = (lo >> 8) & 0xff;
3644 seq[3] = (hi >> 8) & 0xff;
3645 seq[4] = (hi >> 16) & 0xff;
3646 seq[5] = (hi >> 24) & 0xff;
3650 memcpy(arg, seq, sizeof(seq));
3652 bcmerror = BCME_BADKEYIDX;
3657 case WLC_GET_CURR_RATESET:{
3658 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3661 if (bsscfg->associated)
3662 rs = ¤t_bss->rateset;
3664 rs = &wlc->default_bss->rateset;
3666 if (len < (int)(rs->count + sizeof(rs->count))) {
3667 bcmerror = BCME_BUFTOOSHORT;
3671 /* Copy only legacy rateset section */
3672 ret_rs->count = rs->count;
3673 memcpy(&ret_rs->rates, &rs->rates, rs->count);
3677 case WLC_GET_RATESET:{
3679 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3681 memset(&rs, 0, sizeof(wlc_rateset_t));
3682 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs);
3684 if (len < (int)(rs.count + sizeof(rs.count))) {
3685 bcmerror = BCME_BUFTOOSHORT;
3689 /* Copy only legacy rateset section */
3690 ret_rs->count = rs.count;
3691 memcpy(&ret_rs->rates, &rs.rates, rs.count);
3695 case WLC_SET_RATESET:{
3697 wl_rateset_t *in_rs = (wl_rateset_t *) arg;
3699 if (len < (int)(in_rs->count + sizeof(in_rs->count))) {
3700 bcmerror = BCME_BUFTOOSHORT;
3704 if (in_rs->count > WLC_NUMRATES) {
3705 bcmerror = BCME_BUFTOOLONG;
3709 memset(&rs, 0, sizeof(wlc_rateset_t));
3711 /* Copy only legacy rateset section */
3712 rs.count = in_rs->count;
3713 memcpy(&rs.rates, &in_rs->rates, rs.count);
3715 /* merge rateset coming in with the current mcsset */
3716 if (N_ENAB(wlc->pub)) {
3717 if (bsscfg->associated)
3719 ¤t_bss->rateset.mcs[0],
3723 &wlc->default_bss->rateset.mcs[0],
3727 bcmerror = wlc_set_rateset(wlc, &rs);
3730 wlc_ofdm_rateset_war(wlc);
3735 case WLC_GET_BCNPRD:
3736 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3737 *pval = current_bss->beacon_period;
3739 *pval = wlc->default_bss->beacon_period;
3742 case WLC_SET_BCNPRD:
3743 /* range [1, 0xffff] */
3744 if (val >= DOT11_MIN_BEACON_PERIOD
3745 && val <= DOT11_MAX_BEACON_PERIOD) {
3746 wlc->default_bss->beacon_period = (u16) val;
3748 bcmerror = BCME_RANGE;
3751 case WLC_GET_DTIMPRD:
3752 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3753 *pval = current_bss->dtim_period;
3755 *pval = wlc->default_bss->dtim_period;
3758 case WLC_SET_DTIMPRD:
3759 /* range [1, 0xff] */
3760 if (val >= DOT11_MIN_DTIM_PERIOD
3761 && val <= DOT11_MAX_DTIM_PERIOD) {
3762 wlc->default_bss->dtim_period = (u8) val;
3764 bcmerror = BCME_RANGE;
3773 if ((val >= PM_OFF) && (val <= PM_MAX)) {
3777 /* Change watchdog driver to align watchdog with tbtt if possible */
3778 wlc_watchdog_upd(wlc, PS_ALLOWED(wlc));
3780 bcmerror = BCME_ERROR;
3782 #endif /* SUPPORT_PS */
3787 if (AP_ENAB(wlc->pub)) {
3788 bcmerror = BCME_NOTSTA;
3795 if (AP_ENAB(wlc->pub)) {
3796 bcmerror = BCME_NOTSTA;
3800 wlc->wake = val ? true : false;
3802 /* if down, we're done */
3806 /* apply to the mac */
3807 wlc_set_ps_ctrl(wlc);
3810 #endif /* SUPPORT_PS */
3812 case WLC_GET_REVINFO:
3813 bcmerror = wlc_get_revision_info(wlc, arg, (uint) len);
3817 *pval = (int)AP_ENAB(wlc->pub);
3821 if (bsscfg->associated)
3822 *pval = (int)current_bss->atim_window;
3824 *pval = (int)wlc->default_bss->atim_window;
3828 wlc->default_bss->atim_window = (u32) val;
3831 case WLC_GET_PKTCNTS:{
3832 get_pktcnt_t *pktcnt = (get_pktcnt_t *) pval;
3834 pktcnt->rx_good_pkt = wlc->pub->_cnt->rxframe;
3835 pktcnt->rx_bad_pkt = wlc->pub->_cnt->rxerror;
3836 pktcnt->tx_good_pkt =
3837 wlc->pub->_cnt->txfrmsnt;
3838 pktcnt->tx_bad_pkt =
3839 wlc->pub->_cnt->txerror +
3840 wlc->pub->_cnt->txfail;
3841 if (len >= (int)sizeof(get_pktcnt_t)) {
3842 /* Be backward compatible - only if buffer is large enough */
3843 pktcnt->rx_ocast_good_pkt =
3844 wlc->pub->_cnt->rxmfrmocast;
3849 #ifdef SUPPORT_HWKEY
3852 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_GET,
3858 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_SET,
3862 case WLC_GET_WPA_AUTH:
3863 *pval = (int)bsscfg->WPA_auth;
3866 case WLC_SET_WPA_AUTH:
3867 /* change of WPA_Auth modifies the PS_ALLOWED state */
3868 if (BSSCFG_STA(bsscfg)) {
3869 bsscfg->WPA_auth = (u16) val;
3871 bsscfg->WPA_auth = (u16) val;
3873 #endif /* SUPPORT_HWKEY */
3875 case WLC_GET_BANDLIST:
3876 /* count of number of bands, followed by each band type */
3877 *pval++ = NBANDS(wlc);
3878 *pval++ = wlc->band->bandtype;
3879 if (NBANDS(wlc) > 1)
3880 *pval++ = wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype;
3884 *pval = wlc->bandlocked ? wlc->band->bandtype : WLC_BAND_AUTO;
3887 case WLC_GET_PHYLIST:
3889 unsigned char *cp = arg;
3891 bcmerror = BCME_BUFTOOSHORT;
3895 if (WLCISNPHY(wlc->band)) {
3897 } else if (WLCISLCNPHY(wlc->band)) {
3899 } else if (WLCISSSLPNPHY(wlc->band)) {
3906 case WLC_GET_SHORTSLOT:
3907 *pval = wlc->shortslot;
3910 case WLC_GET_SHORTSLOT_OVERRIDE:
3911 *pval = wlc->shortslot_override;
3914 case WLC_SET_SHORTSLOT_OVERRIDE:
3915 if ((val != WLC_SHORTSLOT_AUTO) &&
3916 (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) {
3917 bcmerror = BCME_RANGE;
3921 wlc->shortslot_override = (s8) val;
3923 /* shortslot is an 11g feature, so no more work if we are
3924 * currently on the 5G band
3926 if (BAND_5G(wlc->band->bandtype))
3929 if (wlc->pub->up && wlc->pub->associated) {
3930 /* let watchdog or beacon processing update shortslot */
3931 } else if (wlc->pub->up) {
3932 /* unassociated shortslot is off */
3933 wlc_switch_shortslot(wlc, false);
3935 /* driver is down, so just update the wlc_info value */
3936 if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) {
3937 wlc->shortslot = false;
3940 (wlc->shortslot_override ==
3947 case WLC_GET_LEGACY_ERP:
3948 *pval = wlc->include_legacy_erp;
3951 case WLC_SET_LEGACY_ERP:
3952 if (wlc->include_legacy_erp == bool_val)
3955 wlc->include_legacy_erp = bool_val;
3957 if (AP_ENAB(wlc->pub) && wlc->clk) {
3958 wlc_update_beacon(wlc);
3959 wlc_update_probe_resp(wlc, true);
3964 if (wlc->band->bandtype == WLC_BAND_2G)
3965 *pval = wlc->band->gmode;
3966 else if (NBANDS(wlc) > 1)
3967 *pval = wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode;
3971 if (!wlc->pub->associated)
3972 bcmerror = wlc_set_gmode(wlc, (u8) val, true);
3974 bcmerror = BCME_ASSOCIATED;
3979 case WLC_GET_GMODE_PROTECTION:
3980 *pval = wlc->protection->_g;
3983 case WLC_GET_PROTECTION_CONTROL:
3984 *pval = wlc->protection->overlap;
3987 case WLC_SET_PROTECTION_CONTROL:
3988 if ((val != WLC_PROTECTION_CTL_OFF) &&
3989 (val != WLC_PROTECTION_CTL_LOCAL) &&
3990 (val != WLC_PROTECTION_CTL_OVERLAP)) {
3991 bcmerror = BCME_RANGE;
3995 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, (s8) val);
3997 /* Current g_protection will sync up to the specified control alg in watchdog
3998 * if the driver is up and associated.
3999 * If the driver is down or not associated, the control setting has no effect.
4003 case WLC_GET_GMODE_PROTECTION_OVERRIDE:
4004 *pval = wlc->protection->g_override;
4007 case WLC_SET_GMODE_PROTECTION_OVERRIDE:
4008 if ((val != WLC_PROTECTION_AUTO) &&
4009 (val != WLC_PROTECTION_OFF) && (val != WLC_PROTECTION_ON)) {
4010 bcmerror = BCME_RANGE;
4014 wlc_protection_upd(wlc, WLC_PROT_G_OVR, (s8) val);
4018 case WLC_SET_SUP_RATESET_OVERRIDE:{
4019 wlc_rateset_t rs, new;
4022 if (len < (int)sizeof(wlc_rateset_t)) {
4023 bcmerror = BCME_BUFTOOSHORT;
4026 memcpy(&rs, arg, sizeof(wlc_rateset_t));
4028 /* check for bad count value */
4029 if (rs.count > WLC_NUMRATES) {
4030 bcmerror = BCME_BADRATESET; /* invalid rateset */
4034 /* this command is only appropriate for gmode operation */
4035 if (!(wlc->band->gmode ||
4037 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4038 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4042 /* check for an empty rateset to clear the override */
4043 if (rs.count == 0) {
4044 memset(&wlc->sup_rates_override, 0,
4045 sizeof(wlc_rateset_t));
4049 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4050 wlc_rateset_filter(&rs, &new, false, WLC_RATES_CCK_OFDM,
4051 RATE_MASK, BSS_N_ENAB(wlc, bsscfg));
4052 wlc_rate_hwrs_filter_sort_validate(&new,
4055 wlc->stf->txstreams);
4056 if (rs.count != new.count) {
4057 bcmerror = BCME_BADRATESET; /* invalid rateset */
4061 /* apply new rateset to the override */
4062 memcpy(&wlc->sup_rates_override, &new,
4063 sizeof(wlc_rateset_t));
4065 /* update bcn and probe resp if needed */
4066 if (wlc->pub->up && AP_ENAB(wlc->pub)
4067 && wlc->pub->associated) {
4068 wlc_update_beacon(wlc);
4069 wlc_update_probe_resp(wlc, true);
4074 case WLC_GET_SUP_RATESET_OVERRIDE:
4075 /* this command is only appropriate for gmode operation */
4076 if (!(wlc->band->gmode ||
4078 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4079 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4082 if (len < (int)sizeof(wlc_rateset_t)) {
4083 bcmerror = BCME_BUFTOOSHORT;
4086 memcpy(arg, &wlc->sup_rates_override, sizeof(wlc_rateset_t));
4090 case WLC_GET_PRB_RESP_TIMEOUT:
4091 *pval = wlc->prb_resp_timeout;
4094 case WLC_SET_PRB_RESP_TIMEOUT:
4096 bcmerror = BCME_NOTDOWN;
4099 if (val < 0 || val >= 0xFFFF) {
4100 bcmerror = BCME_RANGE; /* bad value */
4103 wlc->prb_resp_timeout = (u16) val;
4106 case WLC_GET_KEY_PRIMARY:{
4109 /* treat the 'val' parm as the key id */
4110 key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4112 *pval = key->id == val ? true : false;
4114 bcmerror = BCME_BADKEYIDX;
4119 case WLC_SET_KEY_PRIMARY:{
4120 wsec_key_t *key, *old_key;
4122 bcmerror = BCME_BADKEYIDX;
4124 /* treat the 'val' parm as the key id */
4125 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
4126 key = bsscfg->bss_def_keys[i];
4127 if (key != NULL && key->id == val) {
4128 old_key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4129 if (old_key != NULL)
4132 key->flags |= WSEC_PRIMARY_KEY;
4133 bsscfg->wsec_index = i;
4149 /* validate the name value */
4151 for (i = 0; i < (uint) len && *name != '\0';
4155 if (i == (uint) len) {
4156 bcmerror = BCME_BUFTOOSHORT;
4159 i++; /* include the null in the string length */
4161 if (cmd == WLC_GET_VAR) {
4163 wlc_iovar_op(wlc, arg,
4164 (void *)((s8 *) arg + i),
4165 len - i, arg, len, IOV_GET,
4169 wlc_iovar_op(wlc, arg, NULL, 0,
4170 (void *)((s8 *) arg + i),
4171 len - i, IOV_SET, wlcif);
4176 case WLC_SET_WSEC_PMK:
4177 bcmerror = BCME_UNSUPPORTED;
4181 case WLC_CURRENT_PWR:
4183 bcmerror = BCME_NOTUP;
4185 bcmerror = wlc_get_current_txpwr(wlc, arg, len);
4190 WL_ERROR("%s: WLC_LAST\n", __func__);
4195 if (VALID_BCMERROR(bcmerror))
4196 wlc->pub->bcmerror = bcmerror;
4202 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4203 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4204 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4206 if (!(wlc->pub->hw_off))
4207 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok);
4213 /* consolidated register access ioctl error checking */
4214 int wlc_iocregchk(struct wlc_info *wlc, uint band)
4216 /* if band is specified, it must be the current band */
4217 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype))
4218 return BCME_BADBAND;
4220 /* if multiband and band is not specified, band must be locked */
4221 if ((band == WLC_BAND_AUTO) && IS_MBAND_UNLOCKED(wlc))
4222 return BCME_NOTBANDLOCKED;
4224 /* must have core clocks */
4230 #endif /* defined(BCMDBG) */
4233 /* For some ioctls, make sure that the pi pointer matches the current phy */
4234 int wlc_iocpichk(struct wlc_info *wlc, uint phytype)
4236 if (wlc->band->phytype != phytype)
4237 return BCME_BADBAND;
4242 /* Look up the given var name in the given table */
4243 static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table,
4246 const bcm_iovar_t *vi;
4247 const char *lookup_name;
4249 /* skip any ':' delimited option prefixes */
4250 lookup_name = strrchr(name, ':');
4251 if (lookup_name != NULL)
4256 ASSERT(table != NULL);
4258 for (vi = table; vi->name; vi++) {
4259 if (!strcmp(vi->name, lookup_name))
4262 /* ran to end of table */
4264 return NULL; /* var name not found */
4267 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4268 int wlc_iovar_getint(struct wlc_info *wlc, const char *name, int *arg)
4270 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET,
4274 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4275 int wlc_iovar_setint(struct wlc_info *wlc, const char *name, int arg)
4277 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg),
4281 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4282 int wlc_iovar_gets8(struct wlc_info *wlc, const char *name, s8 *arg)
4288 wlc_iovar_op(wlc, name, NULL, 0, &iovar_int, sizeof(iovar_int),
4291 *arg = (s8) iovar_int;
4297 * register iovar table, watchdog and down handlers.
4298 * calling function must keep 'iovars' until wlc_module_unregister is called.
4299 * 'iovar' must have the last entry's name field being NULL as terminator.
4301 int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
4302 const char *name, void *hdl, iovar_fn_t i_fn,
4303 watchdog_fn_t w_fn, down_fn_t d_fn)
4305 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4308 ASSERT(name != NULL);
4309 ASSERT(i_fn != NULL || w_fn != NULL || d_fn != NULL);
4311 /* find an empty entry and just add, no duplication check! */
4312 for (i = 0; i < WLC_MAXMODULES; i++) {
4313 if (wlc->modulecb[i].name[0] == '\0') {
4314 strncpy(wlc->modulecb[i].name, name,
4315 sizeof(wlc->modulecb[i].name) - 1);
4316 wlc->modulecb[i].iovars = iovars;
4317 wlc->modulecb[i].hdl = hdl;
4318 wlc->modulecb[i].iovar_fn = i_fn;
4319 wlc->modulecb[i].watchdog_fn = w_fn;
4320 wlc->modulecb[i].down_fn = d_fn;
4325 /* it is time to increase the capacity */
4326 ASSERT(i < WLC_MAXMODULES);
4327 return BCME_NORESOURCE;
4330 /* unregister module callbacks */
4331 int wlc_module_unregister(struct wlc_pub *pub, const char *name, void *hdl)
4333 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4337 return BCME_NOTFOUND;
4339 ASSERT(name != NULL);
4341 for (i = 0; i < WLC_MAXMODULES; i++) {
4342 if (!strcmp(wlc->modulecb[i].name, name) &&
4343 (wlc->modulecb[i].hdl == hdl)) {
4344 memset(&wlc->modulecb[i], 0, sizeof(struct modulecb));
4349 /* table not found! */
4350 return BCME_NOTFOUND;
4353 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4354 static void wlc_wme_retries_write(struct wlc_info *wlc)
4358 /* Need clock to do this */
4362 for (ac = 0; ac < AC_COUNT; ac++) {
4363 wlc_write_shm(wlc, M_AC_TXLMT_ADDR(ac), wlc->wme_retries[ac]);
4367 /* Get or set an iovar. The params/p_len pair specifies any additional
4368 * qualifying parameters (e.g. an "element index") for a get, while the
4369 * arg/len pair is the buffer for the value to be set or retrieved.
4370 * Operation (get/set) is specified by the last argument.
4371 * interface context provided by wlcif
4373 * All pointers may point into the same buffer.
4376 wlc_iovar_op(struct wlc_info *wlc, const char *name,
4377 void *params, int p_len, void *arg, int len,
4378 bool set, struct wlc_if *wlcif)
4382 const bcm_iovar_t *vi = NULL;
4386 ASSERT(name != NULL);
4390 /* Get MUST have return space */
4391 ASSERT(set || (arg && len));
4393 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
4395 /* Set does NOT take qualifiers */
4396 ASSERT(!set || (!params && !p_len));
4398 if (!set && (len == sizeof(int)) &&
4399 !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) {
4400 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4401 wlc->pub->unit, __func__, name);
4405 /* find the given iovar name */
4406 for (i = 0; i < WLC_MAXMODULES; i++) {
4407 if (!wlc->modulecb[i].iovars)
4409 vi = wlc_iovar_lookup(wlc->modulecb[i].iovars, name);
4413 /* iovar name not found */
4414 if (i >= WLC_MAXMODULES) {
4415 err = BCME_UNSUPPORTED;
4419 /* set up 'params' pointer in case this is a set command so that
4420 * the convenience int and bool code can be common to set and get
4422 if (params == NULL) {
4427 if (vi->type == IOVT_VOID)
4429 else if (vi->type == IOVT_BUFFER)
4432 /* all other types are integer sized */
4433 val_size = sizeof(int);
4435 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
4437 /* Do the actual parameter implementation */
4438 err = wlc->modulecb[i].iovar_fn(wlc->modulecb[i].hdl, vi, actionid,
4439 name, params, p_len, arg, len, val_size,
4447 wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi, void *arg, int len,
4450 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4454 /* check generic condition flags */
4456 if (((vi->flags & IOVF_SET_DOWN) && wlc->pub->up) ||
4457 ((vi->flags & IOVF_SET_UP) && !wlc->pub->up)) {
4458 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4459 } else if ((vi->flags & IOVF_SET_BAND)
4460 && IS_MBAND_UNLOCKED(wlc)) {
4461 err = BCME_NOTBANDLOCKED;
4462 } else if ((vi->flags & IOVF_SET_CLK) && !wlc->clk) {
4466 if (((vi->flags & IOVF_GET_DOWN) && wlc->pub->up) ||
4467 ((vi->flags & IOVF_GET_UP) && !wlc->pub->up)) {
4468 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4469 } else if ((vi->flags & IOVF_GET_BAND)
4470 && IS_MBAND_UNLOCKED(wlc)) {
4471 err = BCME_NOTBANDLOCKED;
4472 } else if ((vi->flags & IOVF_GET_CLK) && !wlc->clk) {
4480 /* length check on io buf */
4481 err = bcm_iovar_lencheck(vi, arg, len, set);
4485 /* On set, check value ranges for integer types */
4495 memcpy(&int_val, arg, sizeof(int));
4496 err = wlc_iovar_rangecheck(wlc, int_val, vi);
4504 /* handler for iovar table wlc_iovars */
4506 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4507 * iovar case, the switch statement maps the iovar id into separate get
4508 * and set values. If you add a new iovar to the switch you MUST use
4509 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4511 * Please use params for additional qualifying parameters.
4514 wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4515 const char *name, void *params, uint p_len, void *arg, int len,
4516 int val_size, struct wlc_if *wlcif)
4518 struct wlc_info *wlc = hdl;
4519 wlc_bsscfg_t *bsscfg;
4526 wlc_bss_info_t *current_bss;
4528 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
4533 err = wlc_iovar_check(wlc->pub, vi, arg, len, IOV_ISSET(actionid));
4537 /* convenience int and bool vals for first 8 bytes of buffer */
4538 if (p_len >= (int)sizeof(int_val))
4539 memcpy(&int_val, params, sizeof(int_val));
4541 if (p_len >= (int)sizeof(int_val) * 2)
4543 (void *)((unsigned long)params + sizeof(int_val)),
4546 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4547 ret_int_ptr = (s32 *) arg;
4549 bool_val = (int_val != 0) ? true : false;
4550 bool_val2 = (int_val2 != 0) ? true : false;
4552 WL_TRACE("wl%d: %s: id %d\n",
4553 wlc->pub->unit, __func__, IOV_ID(actionid));
4554 /* Do the actual parameter implementation */
4556 case IOV_SVAL(IOV_RTSTHRESH):
4557 wlc->RTSThresh = int_val;
4560 case IOV_GVAL(IOV_QTXPOWER):{
4564 err = wlc_phy_txpower_get(wlc->band->pi, &qdbm,
4569 /* Return qdbm units */
4571 qdbm | (override ? WL_TXPWR_OVERRIDE : 0);
4575 /* As long as override is false, this only sets the *user* targets.
4576 User can twiddle this all he wants with no harm.
4577 wlc_phy_txpower_set() explicitly sets override to false if
4578 not internal or test.
4580 case IOV_SVAL(IOV_QTXPOWER):{
4584 /* Remove override bit and clip to max qdbm value */
4585 qdbm = (u8)min_t(u32, (int_val & ~WL_TXPWR_OVERRIDE), 0xff);
4586 /* Extract override setting */
4587 override = (int_val & WL_TXPWR_OVERRIDE) ? true : false;
4589 wlc_phy_txpower_set(wlc->band->pi, qdbm, override);
4593 case IOV_GVAL(IOV_MPC):
4594 *ret_int_ptr = (s32) wlc->mpc;
4597 case IOV_SVAL(IOV_MPC):
4598 wlc->mpc = bool_val;
4599 wlc_radio_mpc_upd(wlc);
4603 case IOV_GVAL(IOV_BCN_LI_BCN):
4604 *ret_int_ptr = wlc->bcn_li_bcn;
4607 case IOV_SVAL(IOV_BCN_LI_BCN):
4608 wlc->bcn_li_bcn = (u8) int_val;
4610 wlc_bcn_li_upd(wlc);
4614 WL_ERROR("wl%d: %s: unsupported\n", wlc->pub->unit, __func__);
4615 err = BCME_UNSUPPORTED;
4619 goto exit; /* avoid unused label warning */
4626 wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val, const bcm_iovar_t *vi)
4632 /* Only ranged integers are checked */
4635 max_val |= 0x7fffffff;
4638 max_val |= 0x00007fff;
4641 max_val |= 0x0000007f;
4643 if (vi->flags & IOVF_NTRL)
4645 else if (vi->flags & IOVF_WHL)
4647 /* Signed values are checked against max_val and min_val */
4648 if ((s32) val < (s32) min_val
4649 || (s32) val > (s32) max_val)
4654 max_val |= 0xffffffff;
4657 max_val |= 0x0000ffff;
4660 max_val |= 0x000000ff;
4661 if (vi->flags & IOVF_NTRL)
4663 if ((val < min_val) || (val > max_val))
4672 static const char *supr_reason[] = {
4673 "None", "PMQ Entry", "Flush request",
4674 "Previous frag failure", "Channel mismatch",
4675 "Lifetime Expiry", "Underflow"
4678 static void wlc_print_txs_status(u16 s)
4680 printk(KERN_DEBUG "[15:12] %d frame attempts\n",
4681 (s & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT);
4682 printk(KERN_DEBUG " [11:8] %d rts attempts\n",
4683 (s & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT);
4684 printk(KERN_DEBUG " [7] %d PM mode indicated\n",
4685 ((s & TX_STATUS_PMINDCTD) ? 1 : 0));
4686 printk(KERN_DEBUG " [6] %d intermediate status\n",
4687 ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0));
4688 printk(KERN_DEBUG " [5] %d AMPDU\n",
4689 (s & TX_STATUS_AMPDU) ? 1 : 0);
4690 printk(KERN_DEBUG " [4:2] %d Frame Suppressed Reason (%s)\n",
4691 ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT),
4692 supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]);
4693 printk(KERN_DEBUG " [1] %d acked\n",
4694 ((s & TX_STATUS_ACK_RCV) ? 1 : 0));
4698 void wlc_print_txstatus(tx_status_t *txs)
4701 u16 s = txs->status;
4702 u16 ackphyrxsh = txs->ackphyrxsh;
4704 printk(KERN_DEBUG "\ntxpkt (MPDU) Complete\n");
4706 printk(KERN_DEBUG "FrameID: %04x ", txs->frameid);
4707 printk(KERN_DEBUG "TxStatus: %04x", s);
4708 printk(KERN_DEBUG "\n");
4710 wlc_print_txs_status(s);
4712 printk(KERN_DEBUG "LastTxTime: %04x ", txs->lasttxtime);
4713 printk(KERN_DEBUG "Seq: %04x ", txs->sequence);
4714 printk(KERN_DEBUG "PHYTxStatus: %04x ", txs->phyerr);
4715 printk(KERN_DEBUG "RxAckRSSI: %04x ",
4716 (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT);
4717 printk(KERN_DEBUG "RxAckSQ: %04x",
4718 (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
4719 printk(KERN_DEBUG "\n");
4720 #endif /* defined(BCMDBG) */
4724 wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat)
4729 v = le16_to_cpu(cur_stat);
4730 delta = (u16)(v - *macstat_snapshot);
4734 *macstat_snapshot = v;
4738 #define MACSTATUPD(name) \
4739 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4741 void wlc_statsupd(struct wlc_info *wlc)
4751 /* if driver down, make no sense to update stats */
4756 /* save last rx fifo 0 overflow count */
4757 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl;
4759 /* save last tx fifo underflow count */
4760 for (i = 0; i < NFIFO; i++)
4761 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i];
4764 /* Read mac stats from contiguous shared memory */
4765 wlc_bmac_copyfrom_shm(wlc->hw, M_UCODE_MACSTAT,
4766 &macstats, sizeof(macstat_t));
4768 /* update mac stats */
4769 MACSTATUPD(txallfrm);
4770 MACSTATUPD(txrtsfrm);
4771 MACSTATUPD(txctsfrm);
4772 MACSTATUPD(txackfrm);
4773 MACSTATUPD(txdnlfrm);
4774 MACSTATUPD(txbcnfrm);
4775 for (i = 0; i < NFIFO; i++)
4776 MACSTATUPD(txfunfl[i]);
4777 MACSTATUPD(txtplunfl);
4778 MACSTATUPD(txphyerr);
4779 MACSTATUPD(rxfrmtoolong);
4780 MACSTATUPD(rxfrmtooshrt);
4781 MACSTATUPD(rxinvmachdr);
4782 MACSTATUPD(rxbadfcs);
4783 MACSTATUPD(rxbadplcp);
4784 MACSTATUPD(rxcrsglitch);
4786 MACSTATUPD(rxdfrmucastmbss);
4787 MACSTATUPD(rxmfrmucastmbss);
4788 MACSTATUPD(rxcfrmucast);
4789 MACSTATUPD(rxrtsucast);
4790 MACSTATUPD(rxctsucast);
4791 MACSTATUPD(rxackucast);
4792 MACSTATUPD(rxdfrmocast);
4793 MACSTATUPD(rxmfrmocast);
4794 MACSTATUPD(rxcfrmocast);
4795 MACSTATUPD(rxrtsocast);
4796 MACSTATUPD(rxctsocast);
4797 MACSTATUPD(rxdfrmmcast);
4798 MACSTATUPD(rxmfrmmcast);
4799 MACSTATUPD(rxcfrmmcast);
4800 MACSTATUPD(rxbeaconmbss);
4801 MACSTATUPD(rxdfrmucastobss);
4802 MACSTATUPD(rxbeaconobss);
4803 MACSTATUPD(rxrsptmout);
4804 MACSTATUPD(bcntxcancl);
4805 MACSTATUPD(rxf0ovfl);
4806 MACSTATUPD(rxf1ovfl);
4807 MACSTATUPD(rxf2ovfl);
4808 MACSTATUPD(txsfovfl);
4809 MACSTATUPD(pmqovfl);
4810 MACSTATUPD(rxcgprqfrm);
4811 MACSTATUPD(rxcgprsqovfl);
4812 MACSTATUPD(txcgprsfail);
4813 MACSTATUPD(txcgprssuc);
4814 MACSTATUPD(prs_timeout);
4816 MACSTATUPD(frmscons);
4818 MACSTATUPD(txglitch_nack);
4819 MACSTATUPD(txburst);
4820 MACSTATUPD(phywatchdog);
4821 MACSTATUPD(pktengrxducast);
4822 MACSTATUPD(pktengrxdmcast);
4825 /* check for rx fifo 0 overflow */
4826 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
4828 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4829 wlc->pub->unit, delta);
4831 /* check for tx fifo underflows */
4832 for (i = 0; i < NFIFO; i++) {
4834 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
4837 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4838 wlc->pub->unit, delta, i);
4842 /* dot11 counter update */
4844 WLCNTSET(wlc->pub->_cnt->txrts,
4845 (wlc->pub->_cnt->rxctsucast -
4846 wlc->pub->_cnt->d11cnt_txrts_off));
4847 WLCNTSET(wlc->pub->_cnt->rxcrc,
4848 (wlc->pub->_cnt->rxbadfcs - wlc->pub->_cnt->d11cnt_rxcrc_off));
4849 WLCNTSET(wlc->pub->_cnt->txnocts,
4850 ((wlc->pub->_cnt->txrtsfrm - wlc->pub->_cnt->rxctsucast) -
4851 wlc->pub->_cnt->d11cnt_txnocts_off));
4853 /* merge counters from dma module */
4854 for (i = 0; i < NFIFO; i++) {
4855 if (wlc->hw->di[i]) {
4856 WLCNTADD(wlc->pub->_cnt->txnobuf,
4857 (wlc->hw->di[i])->txnobuf);
4858 WLCNTADD(wlc->pub->_cnt->rxnobuf,
4859 (wlc->hw->di[i])->rxnobuf);
4860 WLCNTADD(wlc->pub->_cnt->rxgiant,
4861 (wlc->hw->di[i])->rxgiants);
4862 dma_counterreset(wlc->hw->di[i]);
4867 * Aggregate transmit and receive errors that probably resulted
4868 * in the loss of a frame are computed on the fly.
4870 WLCNTSET(wlc->pub->_cnt->txerror,
4871 wlc->pub->_cnt->txnobuf + wlc->pub->_cnt->txnoassoc +
4872 wlc->pub->_cnt->txuflo + wlc->pub->_cnt->txrunt +
4873 wlc->pub->_cnt->dmade + wlc->pub->_cnt->dmada +
4874 wlc->pub->_cnt->dmape);
4875 WLCNTSET(wlc->pub->_cnt->rxerror,
4876 wlc->pub->_cnt->rxoflo + wlc->pub->_cnt->rxnobuf +
4877 wlc->pub->_cnt->rxfragerr + wlc->pub->_cnt->rxrunt +
4878 wlc->pub->_cnt->rxgiant + wlc->pub->_cnt->rxnoscb +
4879 wlc->pub->_cnt->rxbadsrcmac);
4880 for (i = 0; i < NFIFO; i++)
4881 wlc->pub->_cnt->rxerror += wlc->pub->_cnt->rxuflo[i];
4884 bool wlc_chipmatch(u16 vendor, u16 device)
4886 if (vendor != VENDOR_BROADCOM) {
4887 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor);
4891 if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID))
4894 if (device == BCM4313_D11N2G_ID)
4896 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
4899 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device);
4904 void wlc_print_txdesc(d11txh_t *txh)
4906 u16 mtcl = le16_to_cpu(txh->MacTxControlLow);
4907 u16 mtch = le16_to_cpu(txh->MacTxControlHigh);
4908 u16 mfc = le16_to_cpu(txh->MacFrameControl);
4909 u16 tfest = le16_to_cpu(txh->TxFesTimeNormal);
4910 u16 ptcw = le16_to_cpu(txh->PhyTxControlWord);
4911 u16 ptcw_1 = le16_to_cpu(txh->PhyTxControlWord_1);
4912 u16 ptcw_1_Fbr = le16_to_cpu(txh->PhyTxControlWord_1_Fbr);
4913 u16 ptcw_1_Rts = le16_to_cpu(txh->PhyTxControlWord_1_Rts);
4914 u16 ptcw_1_FbrRts = le16_to_cpu(txh->PhyTxControlWord_1_FbrRts);
4915 u16 mainrates = le16_to_cpu(txh->MainRates);
4916 u16 xtraft = le16_to_cpu(txh->XtraFrameTypes);
4918 u8 *ra = txh->TxFrameRA;
4919 u16 tfestfb = le16_to_cpu(txh->TxFesTimeFallback);
4920 u8 *rtspfb = txh->RTSPLCPFallback;
4921 u16 rtsdfb = le16_to_cpu(txh->RTSDurFallback);
4922 u8 *fragpfb = txh->FragPLCPFallback;
4923 u16 fragdfb = le16_to_cpu(txh->FragDurFallback);
4924 u16 mmodelen = le16_to_cpu(txh->MModeLen);
4925 u16 mmodefbrlen = le16_to_cpu(txh->MModeFbrLen);
4926 u16 tfid = le16_to_cpu(txh->TxFrameID);
4927 u16 txs = le16_to_cpu(txh->TxStatus);
4928 u16 mnmpdu = le16_to_cpu(txh->MaxNMpdus);
4929 u16 mabyte = le16_to_cpu(txh->MaxABytes_MRT);
4930 u16 mabyte_f = le16_to_cpu(txh->MaxABytes_FBR);
4931 u16 mmbyte = le16_to_cpu(txh->MinMBytes);
4933 u8 *rtsph = txh->RTSPhyHeader;
4934 struct ieee80211_rts rts = txh->rts_frame;
4937 /* add plcp header along with txh descriptor */
4938 prhex("Raw TxDesc + plcp header", (unsigned char *) txh, sizeof(d11txh_t) + 48);
4940 printk(KERN_DEBUG "TxCtlLow: %04x ", mtcl);
4941 printk(KERN_DEBUG "TxCtlHigh: %04x ", mtch);
4942 printk(KERN_DEBUG "FC: %04x ", mfc);
4943 printk(KERN_DEBUG "FES Time: %04x\n", tfest);
4944 printk(KERN_DEBUG "PhyCtl: %04x%s ", ptcw,
4945 (ptcw & PHY_TXC_SHORT_HDR) ? " short" : "");
4946 printk(KERN_DEBUG "PhyCtl_1: %04x ", ptcw_1);
4947 printk(KERN_DEBUG "PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr);
4948 printk(KERN_DEBUG "PhyCtl_1_Rts: %04x ", ptcw_1_Rts);
4949 printk(KERN_DEBUG "PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts);
4950 printk(KERN_DEBUG "MainRates: %04x ", mainrates);
4951 printk(KERN_DEBUG "XtraFrameTypes: %04x ", xtraft);
4952 printk(KERN_DEBUG "\n");
4954 bcm_format_hex(hexbuf, iv, sizeof(txh->IV));
4955 printk(KERN_DEBUG "SecIV: %s\n", hexbuf);
4956 bcm_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA));
4957 printk(KERN_DEBUG "RA: %s\n", hexbuf);
4959 printk(KERN_DEBUG "Fb FES Time: %04x ", tfestfb);
4960 bcm_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback));
4961 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
4962 printk(KERN_DEBUG "RTS DUR: %04x ", rtsdfb);
4963 bcm_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback));
4964 printk(KERN_DEBUG "PLCP: %s ", hexbuf);
4965 printk(KERN_DEBUG "DUR: %04x", fragdfb);
4966 printk(KERN_DEBUG "\n");
4968 printk(KERN_DEBUG "MModeLen: %04x ", mmodelen);
4969 printk(KERN_DEBUG "MModeFbrLen: %04x\n", mmodefbrlen);
4971 printk(KERN_DEBUG "FrameID: %04x\n", tfid);
4972 printk(KERN_DEBUG "TxStatus: %04x\n", txs);
4974 printk(KERN_DEBUG "MaxNumMpdu: %04x\n", mnmpdu);
4975 printk(KERN_DEBUG "MaxAggbyte: %04x\n", mabyte);
4976 printk(KERN_DEBUG "MaxAggbyte_fb: %04x\n", mabyte_f);
4977 printk(KERN_DEBUG "MinByte: %04x\n", mmbyte);
4979 bcm_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader));
4980 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
4981 bcm_format_hex(hexbuf, (u8 *) &rts, sizeof(txh->rts_frame));
4982 printk(KERN_DEBUG "RTS Frame: %s", hexbuf);
4983 printk(KERN_DEBUG "\n");
4985 #endif /* defined(BCMDBG) */
4988 void wlc_print_rxh(d11rxhdr_t *rxh)
4990 u16 len = rxh->RxFrameSize;
4991 u16 phystatus_0 = rxh->PhyRxStatus_0;
4992 u16 phystatus_1 = rxh->PhyRxStatus_1;
4993 u16 phystatus_2 = rxh->PhyRxStatus_2;
4994 u16 phystatus_3 = rxh->PhyRxStatus_3;
4995 u16 macstatus1 = rxh->RxStatus1;
4996 u16 macstatus2 = rxh->RxStatus2;
4999 static const bcm_bit_desc_t macstat_flags[] = {
5000 {RXS_FCSERR, "FCSErr"},
5001 {RXS_RESPFRAMETX, "Reply"},
5002 {RXS_PBPRES, "PADDING"},
5003 {RXS_DECATMPT, "DeCr"},
5004 {RXS_DECERR, "DeCrErr"},
5005 {RXS_BCNSENT, "Bcn"},
5009 prhex("Raw RxDesc", (unsigned char *) rxh, sizeof(d11rxhdr_t));
5011 bcm_format_flags(macstat_flags, macstatus1, flagstr, 64);
5013 snprintf(lenbuf, sizeof(lenbuf), "0x%x", len);
5015 printk(KERN_DEBUG "RxFrameSize: %6s (%d)%s\n", lenbuf, len,
5016 (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : "");
5017 printk(KERN_DEBUG "RxPHYStatus: %04x %04x %04x %04x\n",
5018 phystatus_0, phystatus_1, phystatus_2, phystatus_3);
5019 printk(KERN_DEBUG "RxMACStatus: %x %s\n", macstatus1, flagstr);
5020 printk(KERN_DEBUG "RXMACaggtype: %x\n",
5021 (macstatus2 & RXS_AGGTYPE_MASK));
5022 printk(KERN_DEBUG "RxTSFTime: %04x\n", rxh->RxTSFTime);
5024 #endif /* defined(BCMDBG) */
5027 int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len)
5031 char *endp = buf + SSID_FMT_BUF_LEN;
5033 if (ssid_len > IEEE80211_MAX_SSID_LEN)
5034 ssid_len = IEEE80211_MAX_SSID_LEN;
5036 for (i = 0; i < ssid_len; i++) {
5041 } else if (isprint((unsigned char) c)) {
5044 p += snprintf(p, (endp - p), "\\x%02X", c);
5050 return (int)(p - buf);
5052 #endif /* defined(BCMDBG) */
5054 static u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate)
5056 return wlc_bmac_rate_shm_offset(wlc->hw, rate);
5059 /* Callback for device removed */
5062 * Attempts to queue a packet onto a multiple-precedence queue,
5063 * if necessary evicting a lower precedence packet from the queue.
5065 * 'prec' is the precedence number that has already been mapped
5066 * from the packet priority.
5068 * Returns true if packet consumed (queued), false if not.
5071 wlc_prec_enq(struct wlc_info *wlc, struct pktq *q, void *pkt, int prec)
5073 return wlc_prec_enq_head(wlc, q, pkt, prec, false);
5077 wlc_prec_enq_head(struct wlc_info *wlc, struct pktq *q, struct sk_buff *pkt,
5078 int prec, bool head)
5081 int eprec = -1; /* precedence to evict from */
5083 /* Determine precedence from which to evict packet, if any */
5084 if (pktq_pfull(q, prec))
5086 else if (pktq_full(q)) {
5087 p = pktq_peek_tail(q, &eprec);
5090 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5091 __func__, eprec, prec);
5096 /* Evict if needed */
5098 bool discard_oldest;
5100 /* Detect queueing to unconfigured precedence */
5101 ASSERT(!pktq_pempty(q, eprec));
5103 discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec);
5105 /* Refuse newer packet unless configured to discard oldest */
5106 if (eprec == prec && !discard_oldest) {
5107 WL_ERROR("%s: No where to go, prec == %d\n",
5112 /* Evict packet according to discard policy */
5113 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
5117 /* Increment wme stats */
5118 if (WME_ENAB(wlc->pub)) {
5119 WLCNTINCR(wlc->pub->_wme_cnt->
5120 tx_failed[WME_PRIO2AC(p->priority)].packets);
5121 WLCNTADD(wlc->pub->_wme_cnt->
5122 tx_failed[WME_PRIO2AC(p->priority)].bytes,
5125 pkt_buf_free_skb(wlc->osh, p, true);
5126 wlc->pub->_cnt->txnobuf++;
5131 p = pktq_penq_head(q, prec, pkt);
5133 p = pktq_penq(q, prec, pkt);
5139 void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
5142 struct wlc_info *wlc = (struct wlc_info *) ctx;
5143 struct wlc_txq_info *qi = wlc->active_queue; /* Check me */
5144 struct pktq *q = &qi->q;
5147 prio = sdu->priority;
5149 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat);
5151 if (!wlc_prec_enq(wlc, q, sdu, prec)) {
5152 if (!EDCF_ENAB(wlc->pub)
5153 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
5154 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5157 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5158 pkt_buf_free_skb(wlc->osh, sdu, true);
5159 wlc->pub->_cnt->txnobuf++;
5162 /* Check if flow control needs to be turned on after enqueuing the packet
5163 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5164 * to drop instead of relying on stack to make the right decision
5166 if (!EDCF_ENAB(wlc->pub)
5167 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5168 if (pktq_len(q) >= wlc->pub->tunables->datahiwat) {
5169 wlc_txflowcontrol(wlc, qi, ON, ALLPRIO);
5171 } else if (wlc->pub->_priofc) {
5172 if (pktq_plen(q, wlc_prio2prec_map[prio]) >=
5173 wlc->pub->tunables->datahiwat) {
5174 wlc_txflowcontrol(wlc, qi, ON, prio);
5180 wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
5181 struct ieee80211_hw *hw)
5186 struct scb *scb = &global_scb;
5187 struct ieee80211_hdr *d11_header = (struct ieee80211_hdr *)(sdu->data);
5191 /* 802.11 standard requires management traffic to go at highest priority */
5192 prio = ieee80211_is_data(d11_header->frame_control) ? sdu->priority :
5194 fifo = prio2fifo[prio];
5196 ASSERT((uint) skb_headroom(sdu) >= TXOFF);
5197 ASSERT(!(sdu->next));
5198 ASSERT(!(sdu->prev));
5199 ASSERT(fifo < NFIFO);
5203 (wlc_d11hdrs_mac80211(wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0)))
5205 wlc_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio));
5206 wlc_send_q(wlc, wlc->active_queue);
5208 wlc->pub->_cnt->ieee_tx++;
5212 void BCMFASTPATH wlc_send_q(struct wlc_info *wlc, struct wlc_txq_info *qi)
5214 struct sk_buff *pkt[DOT11_MAXNUMFRAGS];
5217 int err = 0, i, count;
5219 struct pktq *q = &qi->q;
5220 struct ieee80211_tx_info *tx_info;
5222 /* only do work for the active queue */
5223 if (qi != wlc->active_queue)
5231 prec_map = wlc->tx_prec_map;
5233 /* Send all the enq'd pkts that we can.
5234 * Dequeue packets with precedence with empty HW fifo only
5236 while (prec_map && (pkt[0] = pktq_mdeq(q, prec_map, &prec))) {
5237 tx_info = IEEE80211_SKB_CB(pkt[0]);
5238 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
5239 err = wlc_sendampdu(wlc->ampdu, qi, pkt, prec);
5242 err = wlc_prep_pdu(wlc, pkt[0], &fifo);
5244 for (i = 0; i < count; i++) {
5245 wlc_txfifo(wlc, fifo, pkt[i], true, 1);
5250 if (err == BCME_BUSY) {
5251 pktq_penq_head(q, prec, pkt[0]);
5252 /* If send failed due to any other reason than a change in
5253 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5255 if (prec_map == wlc->tx_prec_map)
5257 prec_map = wlc->tx_prec_map;
5261 /* Check if flow control needs to be turned off after sending the packet */
5262 if (!EDCF_ENAB(wlc->pub)
5263 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5264 if (wlc_txflowcontrol_prio_isset(wlc, qi, ALLPRIO)
5265 && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) {
5266 wlc_txflowcontrol(wlc, qi, OFF, ALLPRIO);
5268 } else if (wlc->pub->_priofc) {
5270 for (prio = MAXPRIO; prio >= 0; prio--) {
5271 if (wlc_txflowcontrol_prio_isset(wlc, qi, prio) &&
5272 (pktq_plen(q, wlc_prio2prec_map[prio]) <
5273 wlc->pub->tunables->datahiwat / 2)) {
5274 wlc_txflowcontrol(wlc, qi, OFF, prio);
5282 * bcmc_fid_generate:
5283 * Generate frame ID for a BCMC packet. The frag field is not used
5284 * for MC frames so is used as part of the sequence number.
5287 bcmc_fid_generate(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh)
5291 frameid = le16_to_cpu(txh->TxFrameID) & ~(TXFID_SEQ_MASK |
5295 mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5302 wlc_txfifo(struct wlc_info *wlc, uint fifo, struct sk_buff *p, bool commit,
5305 u16 frameid = INVALIDFID;
5308 ASSERT(fifo < NFIFO);
5309 txh = (d11txh_t *) (p->data);
5311 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5312 * ucode or BSS info as appropriate.
5314 if (fifo == TX_BCMC_FIFO) {
5315 frameid = le16_to_cpu(txh->TxFrameID);
5319 if (WLC_WAR16165(wlc))
5320 wlc_war16165(wlc, true);
5323 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5324 * in wlc_bmac_txfifo()
5327 TXPKTPENDINC(wlc, fifo, txpktpend);
5328 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5329 txpktpend, TXPKTPENDGET(wlc, fifo));
5332 /* Commit BCMC sequence number in the SHM frame ID location */
5333 if (frameid != INVALIDFID)
5334 BCMCFID(wlc, frameid);
5336 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
5337 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5342 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec, uint length)
5345 uint mac_rate = RSPEC2RATE(rspec);
5348 if (IS_MCS(rspec)) {
5349 /* not supported yet */
5351 } else if (IS_OFDM(rspec)) {
5352 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5354 * Nbits = length * 8
5355 * Nbits/sym = Mbps * 4 = mac_rate * 2
5357 nsyms = CEIL((length * 8), (mac_rate * 2));
5359 /* usec = symbols * usec/symbol */
5360 usec = (u16) (nsyms * APHY_SYMBOL_TIME);
5371 usec = (length << 4) / 11;
5374 usec = (length << 3) / 11;
5377 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5378 wlc->pub->unit, rspec);
5379 ASSERT((const char *)"Bad phy_rate" == NULL);
5388 wlc_compute_plcp(struct wlc_info *wlc, ratespec_t rspec, uint length, u8 *plcp)
5390 if (IS_MCS(rspec)) {
5391 wlc_compute_mimo_plcp(rspec, length, plcp);
5392 } else if (IS_OFDM(rspec)) {
5393 wlc_compute_ofdm_plcp(rspec, length, plcp);
5395 wlc_compute_cck_plcp(rspec, length, plcp);
5400 /* Rate: 802.11 rate code, length: PSDU length in octets */
5401 static void wlc_compute_mimo_plcp(ratespec_t rspec, uint length, u8 *plcp)
5403 u8 mcs = (u8) (rspec & RSPEC_RATE_MASK);
5404 ASSERT(IS_MCS(rspec));
5406 if (RSPEC_IS40MHZ(rspec) || (mcs == 32))
5407 plcp[0] |= MIMO_PLCP_40MHZ;
5408 WLC_SET_MIMO_PLCP_LEN(plcp, length);
5409 plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */
5410 plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5411 plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5415 /* Rate: 802.11 rate code, length: PSDU length in octets */
5416 static void BCMFASTPATH
5417 wlc_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp)
5421 int rate = RSPEC2RATE(rspec);
5423 ASSERT(IS_OFDM(rspec));
5425 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5426 rate_signal = rate_info[rate] & RATE_MASK;
5427 ASSERT(rate_signal != 0);
5429 memset(plcp, 0, D11_PHY_HDR_LEN);
5430 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal);
5432 tmp = (length & 0xfff) << 5;
5433 plcp[2] |= (tmp >> 16) & 0xff;
5434 plcp[1] |= (tmp >> 8) & 0xff;
5435 plcp[0] |= tmp & 0xff;
5441 * Compute PLCP, but only requires actual rate and length of pkt.
5442 * Rate is given in the driver standard multiple of 500 kbps.
5443 * le is set for 11 Mbps rate if necessary.
5444 * Broken out for PRQ.
5447 static void wlc_cck_plcp_set(int rate_500, uint length, u8 *plcp)
5460 usec = (length << 4) / 11;
5461 if ((length << 4) - (usec * 11) > 0)
5465 usec = (length << 3) / 11;
5466 if ((length << 3) - (usec * 11) > 0) {
5468 if ((usec * 11) - (length << 3) >= 8)
5469 le = D11B_PLCP_SIGNAL_LE;
5474 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500);
5475 rate_500 = WLC_RATE_1M;
5479 /* PLCP signal byte */
5480 plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */
5481 /* PLCP service byte */
5482 plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED);
5483 /* PLCP length u16, little endian */
5484 plcp[2] = usec & 0xff;
5485 plcp[3] = (usec >> 8) & 0xff;
5491 /* Rate: 802.11 rate code, length: PSDU length in octets */
5492 static void wlc_compute_cck_plcp(ratespec_t rspec, uint length, u8 *plcp)
5494 int rate = RSPEC2RATE(rspec);
5496 ASSERT(IS_CCK(rspec));
5498 wlc_cck_plcp_set(rate, length, plcp);
5501 /* wlc_compute_frame_dur()
5503 * Calculate the 802.11 MAC header DUR field for MPDU
5504 * DUR for a single frame = 1 SIFS + 1 ACK
5505 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5507 * rate MPDU rate in unit of 500kbps
5508 * next_frag_len next MPDU length in bytes
5509 * preamble_type use short/GF or long/MM PLCP header
5511 static u16 BCMFASTPATH
5512 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate, u8 preamble_type,
5517 sifs = SIFS(wlc->band);
5520 dur += (u16) wlc_calc_ack_time(wlc, rate, preamble_type);
5522 if (next_frag_len) {
5523 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5525 /* add another SIFS and the frag time */
5528 (u16) wlc_calc_frame_time(wlc, rate, preamble_type,
5534 /* wlc_compute_rtscts_dur()
5536 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5537 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5538 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5540 * cts cts-to-self or rts/cts
5541 * rts_rate rts or cts rate in unit of 500kbps
5542 * rate next MPDU rate in unit of 500kbps
5543 * frame_len next MPDU frame length in bytes
5546 wlc_compute_rtscts_dur(struct wlc_info *wlc, bool cts_only, ratespec_t rts_rate,
5547 ratespec_t frame_rate, u8 rts_preamble_type,
5548 u8 frame_preamble_type, uint frame_len, bool ba)
5552 sifs = SIFS(wlc->band);
5554 if (!cts_only) { /* RTS/CTS */
5557 (u16) wlc_calc_cts_time(wlc, rts_rate,
5559 } else { /* CTS-TO-SELF */
5564 (u16) wlc_calc_frame_time(wlc, frame_rate, frame_preamble_type,
5568 (u16) wlc_calc_ba_time(wlc, frame_rate,
5569 WLC_SHORT_PREAMBLE);
5572 (u16) wlc_calc_ack_time(wlc, frame_rate,
5573 frame_preamble_type);
5577 static bool wlc_phy_rspec_check(struct wlc_info *wlc, u16 bw, ratespec_t rspec)
5579 if (IS_MCS(rspec)) {
5580 uint mcs = rspec & RSPEC_RATE_MASK;
5583 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5584 } else if ((mcs >= 8) && (mcs <= 23)) {
5585 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SDM);
5586 } else if (mcs == 32) {
5587 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5588 ASSERT(bw == PHY_TXC1_BW_40MHZ_DUP);
5590 } else if (IS_OFDM(rspec)) {
5591 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_STBC);
5593 ASSERT(IS_CCK(rspec));
5595 ASSERT((bw == PHY_TXC1_BW_20MHZ)
5596 || (bw == PHY_TXC1_BW_20MHZ_UP));
5597 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SISO);
5603 u16 BCMFASTPATH wlc_phytxctl1_calc(struct wlc_info *wlc, ratespec_t rspec)
5608 if (WLCISLCNPHY(wlc->band)) {
5609 bw = PHY_TXC1_BW_20MHZ;
5611 bw = RSPEC_GET_BW(rspec);
5612 /* 10Mhz is not supported yet */
5613 if (bw < PHY_TXC1_BW_20MHZ) {
5614 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5616 bw = PHY_TXC1_BW_20MHZ;
5619 wlc_phy_rspec_check(wlc, bw, rspec);
5622 if (IS_MCS(rspec)) {
5623 uint mcs = rspec & RSPEC_RATE_MASK;
5625 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5626 phyctl1 = RSPEC_PHYTXBYTE2(rspec);
5627 /* set the upper byte of phyctl1 */
5628 phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8);
5629 } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band)
5630 && !WLCISSSLPNPHY(wlc->band)) {
5631 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5632 /* Eventually MIMOPHY would also be converted to this format */
5633 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5634 phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5635 } else { /* legacy OFDM/CCK */
5637 /* get the phyctl byte from rate phycfg table */
5638 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec));
5640 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5644 /* set the upper byte of phyctl1 */
5646 (bw | (phycfg << 8) |
5647 (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5651 /* phy clock must support 40Mhz if tx descriptor uses it */
5652 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) {
5653 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ);
5654 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi));
5660 ratespec_t BCMFASTPATH
5661 wlc_rspec_to_rts_rspec(struct wlc_info *wlc, ratespec_t rspec, bool use_rspec,
5664 ratespec_t rts_rspec = 0;
5667 /* use frame rate as rts rate */
5670 } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) {
5671 /* Use 11Mbps as the g protection RTS target rate and fallback.
5672 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5673 * target in case 11 Mbps is not Basic.
5674 * 6 and 9 Mbps are not usually selected by rate selection, but even
5675 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5677 rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M);
5679 /* calculate RTS rate and fallback rate based on the frame rate
5680 * RTS must be sent at a basic rate since it is a
5681 * control frame, sec 9.6 of 802.11 spec
5683 rts_rspec = WLC_BASIC_RATE(wlc, rspec);
5686 if (WLC_PHY_11N_CAP(wlc->band)) {
5687 /* set rts txbw to correct side band */
5688 rts_rspec &= ~RSPEC_BW_MASK;
5690 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5691 * (DUP), otherwise send RTS on control channel
5693 if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec))
5694 rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT);
5696 rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5698 /* pick siso/cdd as default for ofdm */
5699 if (IS_OFDM(rts_rspec)) {
5700 rts_rspec &= ~RSPEC_STF_MASK;
5701 rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
5708 * Add d11txh_t, cck_phy_hdr_t.
5710 * 'p' data must start with 802.11 MAC header
5711 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5713 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5716 static u16 BCMFASTPATH
5717 wlc_d11hdrs_mac80211(struct wlc_info *wlc, struct ieee80211_hw *hw,
5718 struct sk_buff *p, struct scb *scb, uint frag,
5719 uint nfrags, uint queue, uint next_frag_len,
5720 wsec_key_t *key, ratespec_t rspec_override)
5722 struct ieee80211_hdr *h;
5724 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
5725 int len, phylen, rts_phylen;
5726 u16 frameid, mch, phyctl, xfts, mainrates;
5727 u16 seq = 0, mcl = 0, status = 0;
5728 ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = {
5729 WLC_RATE_1M, WLC_RATE_1M};
5730 bool use_rts = false;
5731 bool use_cts = false;
5732 bool use_rifs = false;
5733 bool short_preamble[2] = { false, false };
5734 u8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5735 u8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5736 u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN];
5737 struct ieee80211_rts *rts = NULL;
5741 bool hwtkmic = false;
5742 u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
5743 #define ANTCFG_NONE 0xFF
5744 u8 antcfg = ANTCFG_NONE;
5745 u8 fbantcfg = ANTCFG_NONE;
5746 uint phyctl1_stf = 0;
5748 struct ieee80211_tx_rate *txrate[2];
5750 struct ieee80211_tx_info *tx_info;
5753 u8 mimo_preamble_type;
5757 ASSERT(queue < NFIFO);
5759 /* locate 802.11 MAC header */
5760 h = (struct ieee80211_hdr *)(p->data);
5761 qos = ieee80211_is_data_qos(h->frame_control);
5763 /* compute length of frame in bytes for use in PLCP computations */
5765 phylen = len + FCS_LEN;
5767 /* If WEP enabled, add room in phylen for the additional bytes of
5768 * ICV which MAC generates. We do NOT add the additional bytes to
5769 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5773 phylen += key->icv_len;
5777 tx_info = IEEE80211_SKB_CB(p);
5781 plcp = skb_push(p, D11_PHY_HDR_LEN);
5783 /* add Broadcom tx descriptor header */
5784 txh = (d11txh_t *) skb_push(p, D11_TXH_LEN);
5785 memset(txh, 0, D11_TXH_LEN);
5788 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
5789 /* non-AP STA should never use BCMC queue */
5790 ASSERT(queue != TX_BCMC_FIFO);
5791 if (queue == TX_BCMC_FIFO) {
5792 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5793 WLCWLUNIT(wlc), __func__);
5794 frameid = bcmc_fid_generate(wlc, NULL, txh);
5796 /* Increment the counter for first fragment */
5797 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
5798 SCB_SEQNUM(scb, p->priority)++;
5801 /* extract fragment number from frame first */
5802 seq = le16_to_cpu(seq) & FRAGNUM_MASK;
5803 seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT);
5804 h->seq_ctrl = cpu_to_le16(seq);
5806 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5807 (queue & TXFID_QUEUE_MASK);
5810 frameid |= queue & TXFID_QUEUE_MASK;
5812 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5813 if (SCB_PS(scb) || ieee80211_is_beacon(h->frame_control))
5814 mcl |= TXC_IGNOREPMQ;
5816 ASSERT(hw->max_rates <= IEEE80211_TX_MAX_RATES);
5817 ASSERT(hw->max_rates == 2);
5819 txrate[0] = tx_info->control.rates;
5820 txrate[1] = txrate[0] + 1;
5822 ASSERT(txrate[0]->idx >= 0);
5823 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5824 if (txrate[1]->idx < 0) {
5825 txrate[1] = txrate[0];
5828 for (k = 0; k < hw->max_rates; k++) {
5830 txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false;
5832 ASSERT(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU));
5833 if ((txrate[k]->idx >= 0)
5834 && (txrate[k]->idx <
5835 hw->wiphy->bands[tx_info->band]->n_bitrates)) {
5837 hw->wiphy->bands[tx_info->band]->
5838 bitrates[txrate[k]->idx].hw_value;
5841 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ?
5844 ASSERT((txrate[k]->idx >= 0) &&
5846 hw->wiphy->bands[tx_info->band]->
5848 rate_val[k] = WLC_RATE_1M;
5851 rate_val[k] = txrate[k]->idx;
5853 /* Currently only support same setting for primay and fallback rates.
5854 * Unify flags for each rate into a single value for the frame
5858 flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false;
5861 flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false;
5864 rate_val[k] |= NRATE_MCS_INUSE;
5866 rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]);
5868 /* (1) RATE: determine and validate primary rate and fallback rates */
5869 if (!RSPEC_ACTIVE(rspec[k])) {
5870 ASSERT(RSPEC_ACTIVE(rspec[k]));
5871 rspec[k] = WLC_RATE_1M;
5873 if (!is_multicast_ether_addr(h->addr1)) {
5874 /* set tx antenna config */
5875 wlc_antsel_antcfg_get(wlc->asi, false, false, 0,
5876 0, &antcfg, &fbantcfg);
5881 phyctl1_stf = wlc->stf->ss_opmode;
5883 if (N_ENAB(wlc->pub)) {
5884 for (k = 0; k < hw->max_rates; k++) {
5885 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5886 if (((IS_MCS(rspec[k]) &&
5887 IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) ||
5889 && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
5890 || !(rspec[k] & RSPEC_OVERRIDE))) {
5891 rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
5893 /* For SISO MCS use STBC if possible */
5894 if (IS_MCS(rspec[k])
5895 && WLC_STF_SS_STBC_TX(wlc, scb)) {
5898 ASSERT(WLC_STBC_CAP_PHY(wlc));
5899 stc = 1; /* Nss for single stream is always 1 */
5901 (PHY_TXC1_MODE_STBC <<
5902 RSPEC_STF_SHIFT) | (stc <<
5906 (phyctl1_stf << RSPEC_STF_SHIFT);
5909 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5910 if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) {
5911 /* default txbw is 20in40 SB */
5912 mimo_ctlchbw = mimo_txbw =
5913 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
5914 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
5916 if (IS_MCS(rspec[k])) {
5917 /* mcs 32 must be 40b/w DUP */
5918 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5920 PHY_TXC1_BW_40MHZ_DUP;
5922 } else if (wlc->mimo_40txbw != AUTO)
5923 mimo_txbw = wlc->mimo_40txbw;
5924 /* else check if dst is using 40 Mhz */
5925 else if (scb->flags & SCB_IS40)
5926 mimo_txbw = PHY_TXC1_BW_40MHZ;
5927 } else if (IS_OFDM(rspec[k])) {
5928 if (wlc->ofdm_40txbw != AUTO)
5929 mimo_txbw = wlc->ofdm_40txbw;
5931 ASSERT(IS_CCK(rspec[k]));
5932 if (wlc->cck_40txbw != AUTO)
5933 mimo_txbw = wlc->cck_40txbw;
5936 /* mcs32 is 40 b/w only.
5937 * This is possible for probe packets on a STA during SCAN
5939 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5941 rspec[k] = RSPEC_MIMORATE;
5943 mimo_txbw = PHY_TXC1_BW_20MHZ;
5946 /* Set channel width */
5947 rspec[k] &= ~RSPEC_BW_MASK;
5948 if ((k == 0) || ((k > 0) && IS_MCS(rspec[k])))
5949 rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT);
5951 rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5955 if (IS_MCS(rspec[k])
5956 && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5957 rspec[k] |= RSPEC_SHORT_GI;
5958 else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
5959 rspec[k] &= ~RSPEC_SHORT_GI;
5961 rspec[k] &= ~RSPEC_SHORT_GI;
5964 mimo_preamble_type = WLC_MM_PREAMBLE;
5965 if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD)
5966 mimo_preamble_type = WLC_GF_PREAMBLE;
5968 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
5969 && (!IS_MCS(rspec[k]))) {
5970 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5971 WLCWLUNIT(wlc), __func__);
5972 ASSERT(0 && "Rate mismatch");
5975 if (IS_MCS(rspec[k])) {
5976 preamble_type[k] = mimo_preamble_type;
5978 /* if SGI is selected, then forced mm for single stream */
5979 if ((rspec[k] & RSPEC_SHORT_GI)
5980 && IS_SINGLE_STREAM(rspec[k] &
5982 preamble_type[k] = WLC_MM_PREAMBLE;
5986 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
5987 ASSERT(VALID_RATE_DBG(wlc, rspec[0]));
5989 /* should be better conditionalized */
5990 if (!IS_MCS(rspec[0])
5991 && (tx_info->control.rates[0].
5992 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
5993 preamble_type[k] = WLC_SHORT_PREAMBLE;
5995 ASSERT(!IS_MCS(rspec[0])
5996 || WLC_IS_MIMO_PREAMBLE(preamble_type[k]));
5999 for (k = 0; k < hw->max_rates; k++) {
6000 /* Set ctrlchbw as 20Mhz */
6001 ASSERT(!IS_MCS(rspec[k]));
6002 rspec[k] &= ~RSPEC_BW_MASK;
6003 rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
6005 /* for nphy, stf of ofdm frames must follow policies */
6006 if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) {
6007 rspec[k] &= ~RSPEC_STF_MASK;
6008 rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
6013 /* Reset these for use with AMPDU's */
6014 txrate[0]->count = 0;
6015 txrate[1]->count = 0;
6017 /* (2) PROTECTION, may change rspec */
6018 if ((ieee80211_is_data(h->frame_control) ||
6019 ieee80211_is_mgmt(h->frame_control)) &&
6020 (phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1))
6023 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
6024 wlc_compute_plcp(wlc, rspec[0], phylen, plcp);
6025 wlc_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
6026 memcpy(&txh->FragPLCPFallback,
6027 plcp_fallback, sizeof(txh->FragPLCPFallback));
6029 /* Length field now put in CCK FBR CRC field */
6030 if (IS_CCK(rspec[1])) {
6031 txh->FragPLCPFallback[4] = phylen & 0xff;
6032 txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
6035 /* MIMO-RATE: need validation ?? */
6037 IS_OFDM(rspec[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) plcp) :
6040 /* DUR field for main rate */
6041 if (!ieee80211_is_pspoll(h->frame_control) &&
6042 !is_multicast_ether_addr(h->addr1) && !use_rifs) {
6044 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0],
6046 h->duration_id = cpu_to_le16(durid);
6047 } else if (use_rifs) {
6048 /* NAV protect to end of next max packet size */
6050 (u16) wlc_calc_frame_time(wlc, rspec[0],
6052 DOT11_MAX_FRAG_LEN);
6053 durid += RIFS_11N_TIME;
6054 h->duration_id = cpu_to_le16(durid);
6057 /* DUR field for fallback rate */
6058 if (ieee80211_is_pspoll(h->frame_control))
6059 txh->FragDurFallback = h->duration_id;
6060 else if (is_multicast_ether_addr(h->addr1) || use_rifs)
6061 txh->FragDurFallback = 0;
6063 durid = wlc_compute_frame_dur(wlc, rspec[1],
6064 preamble_type[1], next_frag_len);
6065 txh->FragDurFallback = cpu_to_le16(durid);
6068 /* (4) MAC-HDR: MacTxControlLow */
6070 mcl |= TXC_STARTMSDU;
6072 if (!is_multicast_ether_addr(h->addr1))
6073 mcl |= TXC_IMMEDACK;
6075 if (BAND_5G(wlc->band->bandtype))
6076 mcl |= TXC_FREQBAND_5G;
6078 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC))
6081 /* set AMIC bit if using hardware TKIP MIC */
6085 txh->MacTxControlLow = cpu_to_le16(mcl);
6087 /* MacTxControlHigh */
6090 /* Set fallback rate preamble type */
6091 if ((preamble_type[1] == WLC_SHORT_PREAMBLE) ||
6092 (preamble_type[1] == WLC_GF_PREAMBLE)) {
6093 ASSERT((preamble_type[1] == WLC_GF_PREAMBLE) ||
6094 (!IS_MCS(rspec[1])));
6095 if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M)
6096 mch |= TXC_PREAMBLE_DATA_FB_SHORT;
6099 /* MacFrameControl */
6100 memcpy(&txh->MacFrameControl, &h->frame_control, sizeof(u16));
6101 txh->TxFesTimeNormal = cpu_to_le16(0);
6103 txh->TxFesTimeFallback = cpu_to_le16(0);
6106 memcpy(&txh->TxFrameRA, &h->addr1, ETH_ALEN);
6109 txh->TxFrameID = cpu_to_le16(frameid);
6111 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6112 * then we may need to reset the retry cnt's via the status reg
6114 txh->TxStatus = cpu_to_le16(status);
6116 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6117 * the END of previous structure so that it's compatible in driver.
6119 txh->MaxNMpdus = cpu_to_le16(0);
6120 txh->MaxABytes_MRT = cpu_to_le16(0);
6121 txh->MaxABytes_FBR = cpu_to_le16(0);
6122 txh->MinMBytes = cpu_to_le16(0);
6124 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6125 /* RTS PLCP header and RTS frame */
6126 if (use_rts || use_cts) {
6127 if (use_rts && use_cts)
6130 for (k = 0; k < 2; k++) {
6131 rts_rspec[k] = wlc_rspec_to_rts_rspec(wlc, rspec[k],
6136 if (!IS_OFDM(rts_rspec[0]) &&
6137 !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) ||
6138 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6139 rts_preamble_type[0] = WLC_SHORT_PREAMBLE;
6140 mch |= TXC_PREAMBLE_RTS_MAIN_SHORT;
6143 if (!IS_OFDM(rts_rspec[1]) &&
6144 !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) ||
6145 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6146 rts_preamble_type[1] = WLC_SHORT_PREAMBLE;
6147 mch |= TXC_PREAMBLE_RTS_FB_SHORT;
6150 /* RTS/CTS additions to MacTxControlLow */
6152 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDCTS);
6154 txh->MacTxControlLow |= cpu_to_le16(TXC_SENDRTS);
6155 txh->MacTxControlLow |= cpu_to_le16(TXC_LONGFRAME);
6158 /* RTS PLCP header */
6159 ASSERT(IS_ALIGNED((unsigned long)txh->RTSPhyHeader, sizeof(u16)));
6160 rts_plcp = txh->RTSPhyHeader;
6162 rts_phylen = DOT11_CTS_LEN + FCS_LEN;
6164 rts_phylen = DOT11_RTS_LEN + FCS_LEN;
6166 wlc_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp);
6168 /* fallback rate version of RTS PLCP header */
6169 wlc_compute_plcp(wlc, rts_rspec[1], rts_phylen,
6171 memcpy(&txh->RTSPLCPFallback, rts_plcp_fallback,
6172 sizeof(txh->RTSPLCPFallback));
6174 /* RTS frame fields... */
6175 rts = (struct ieee80211_rts *)&txh->rts_frame;
6177 durid = wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec[0],
6178 rspec[0], rts_preamble_type[0],
6179 preamble_type[0], phylen, false);
6180 rts->duration = cpu_to_le16(durid);
6181 /* fallback rate version of RTS DUR field */
6182 durid = wlc_compute_rtscts_dur(wlc, use_cts,
6183 rts_rspec[1], rspec[1],
6184 rts_preamble_type[1],
6185 preamble_type[1], phylen, false);
6186 txh->RTSDurFallback = cpu_to_le16(durid);
6189 rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
6190 IEEE80211_STYPE_CTS);
6192 memcpy(&rts->ra, &h->addr2, ETH_ALEN);
6194 rts->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
6195 IEEE80211_STYPE_RTS);
6197 memcpy(&rts->ra, &h->addr1, 2 * ETH_ALEN);
6201 * low 8 bits: main frag rate/mcs,
6202 * high 8 bits: rts/cts rate/mcs
6204 mainrates |= (IS_OFDM(rts_rspec[0]) ?
6205 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) :
6208 memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN);
6209 memset((char *)&txh->rts_frame, 0,
6210 sizeof(struct ieee80211_rts));
6211 memset((char *)txh->RTSPLCPFallback, 0,
6212 sizeof(txh->RTSPLCPFallback));
6213 txh->RTSDurFallback = 0;
6216 #ifdef SUPPORT_40MHZ
6217 /* add null delimiter count */
6218 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) {
6219 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] =
6220 wlc_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen);
6224 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6225 txh->MacTxControlHigh = cpu_to_le16(mch);
6227 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6228 txh->MainRates = cpu_to_le16(mainrates);
6230 /* XtraFrameTypes */
6231 xfts = FRAMETYPE(rspec[1], wlc->mimoft);
6232 xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT);
6233 xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT);
6235 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT;
6236 txh->XtraFrameTypes = cpu_to_le16(xfts);
6238 /* PhyTxControlWord */
6239 phyctl = FRAMETYPE(rspec[0], wlc->mimoft);
6240 if ((preamble_type[0] == WLC_SHORT_PREAMBLE) ||
6241 (preamble_type[0] == WLC_GF_PREAMBLE)) {
6242 ASSERT((preamble_type[0] == WLC_GF_PREAMBLE)
6243 || !IS_MCS(rspec[0]));
6244 if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M)
6245 phyctl |= PHY_TXC_SHORT_HDR;
6246 wlc->pub->_cnt->txprshort++;
6249 /* phytxant is properly bit shifted */
6250 phyctl |= wlc_stf_d11hdrs_phyctl_txant(wlc, rspec[0]);
6251 txh->PhyTxControlWord = cpu_to_le16(phyctl);
6253 /* PhyTxControlWord_1 */
6254 if (WLC_PHY_11N_CAP(wlc->band)) {
6257 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[0]);
6258 txh->PhyTxControlWord_1 = cpu_to_le16(phyctl1);
6259 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[1]);
6260 txh->PhyTxControlWord_1_Fbr = cpu_to_le16(phyctl1);
6262 if (use_rts || use_cts) {
6263 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[0]);
6264 txh->PhyTxControlWord_1_Rts = cpu_to_le16(phyctl1);
6265 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[1]);
6266 txh->PhyTxControlWord_1_FbrRts = cpu_to_le16(phyctl1);
6270 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6271 * fill in non-zero MModeLen and/or MModeFbrLen
6272 * it will be unnecessary if they are separated
6274 if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) {
6276 wlc_calc_lsig_len(wlc, rspec[0], phylen);
6277 txh->MModeLen = cpu_to_le16(mmodelen);
6280 if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) {
6282 wlc_calc_lsig_len(wlc, rspec[1], phylen);
6283 txh->MModeFbrLen = cpu_to_le16(mmodefbrlen);
6287 if (IS_MCS(rspec[0]))
6288 ASSERT(IS_MCS(rspec[1]));
6290 ASSERT(!IS_MCS(rspec[0]) ||
6291 ((preamble_type[0] == WLC_MM_PREAMBLE) == (txh->MModeLen != 0)));
6292 ASSERT(!IS_MCS(rspec[1]) ||
6293 ((preamble_type[1] == WLC_MM_PREAMBLE) ==
6294 (txh->MModeFbrLen != 0)));
6296 ac = wme_fifo2ac[queue];
6297 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
6298 uint frag_dur, dur, dur_fallback;
6300 ASSERT(!is_multicast_ether_addr(h->addr1));
6302 /* WME: Update TXOP threshold */
6303 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
6305 wlc_calc_frame_time(wlc, rspec[0], preamble_type[0],
6309 /* 1 RTS or CTS-to-self frame */
6311 wlc_calc_cts_time(wlc, rts_rspec[0],
6312 rts_preamble_type[0]);
6314 wlc_calc_cts_time(wlc, rts_rspec[1],
6315 rts_preamble_type[1]);
6316 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6317 dur += le16_to_cpu(rts->duration);
6319 le16_to_cpu(txh->RTSDurFallback);
6320 } else if (use_rifs) {
6324 /* frame + SIFS + ACK */
6327 wlc_compute_frame_dur(wlc, rspec[0],
6328 preamble_type[0], 0);
6331 wlc_calc_frame_time(wlc, rspec[1],
6335 wlc_compute_frame_dur(wlc, rspec[1],
6336 preamble_type[1], 0);
6338 /* NEED to set TxFesTimeNormal (hard) */
6339 txh->TxFesTimeNormal = cpu_to_le16((u16) dur);
6340 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6341 txh->TxFesTimeFallback =
6342 cpu_to_le16((u16) dur_fallback);
6344 /* update txop byte threshold (txop minus intraframe overhead) */
6345 if (wlc->edcf_txop[ac] >= (dur - frag_dur)) {
6350 wlc_calc_frame_len(wlc, rspec[0],
6356 /* range bound the fragthreshold */
6357 if (newfragthresh < DOT11_MIN_FRAG_LEN)
6360 else if (newfragthresh >
6361 wlc->usr_fragthresh)
6363 wlc->usr_fragthresh;
6364 /* update the fragthresh and do txc update */
6365 if (wlc->fragthresh[queue] !=
6366 (u16) newfragthresh) {
6367 wlc->fragthresh[queue] =
6368 (u16) newfragthresh;
6372 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6373 wlc->pub->unit, fifo_names[queue],
6374 RSPEC2RATE(rspec[0]));
6376 if (dur > wlc->edcf_txop[ac])
6377 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6378 wlc->pub->unit, __func__,
6380 phylen, wlc->fragthresh[queue],
6381 dur, wlc->edcf_txop[ac]);
6388 void wlc_tbtt(struct wlc_info *wlc, d11regs_t *regs)
6390 wlc_bsscfg_t *cfg = wlc->cfg;
6392 wlc->pub->_cnt->tbtt++;
6394 if (BSSCFG_STA(cfg)) {
6395 /* run watchdog here if the watchdog timer is not armed */
6396 if (WLC_WATCHDOG_TBTT(wlc)) {
6399 wl_del_timer(wlc->wl, wlc->wdtimer);
6400 wlc->WDarmed = false;
6403 cur = OSL_SYSUPTIME();
6404 delta = cur > wlc->WDlast ? cur - wlc->WDlast :
6405 (u32) ~0 - wlc->WDlast + cur + 1;
6406 if (delta >= TIMER_INTERVAL_WATCHDOG) {
6407 wlc_watchdog((void *)wlc);
6411 wl_add_timer(wlc->wl, wlc->wdtimer,
6412 wlc_watchdog_backup_bi(wlc), true);
6413 wlc->WDarmed = true;
6418 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6419 wlc->qvalid |= MCMD_DIRFRMQVAL;
6423 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6424 void wlc_hwtimer_gptimer_set(struct wlc_info *wlc, uint us)
6426 W_REG(&wlc->regs->gptimer, us);
6429 void wlc_hwtimer_gptimer_abort(struct wlc_info *wlc)
6431 W_REG(&wlc->regs->gptimer, 0);
6434 static void wlc_hwtimer_gptimer_cb(struct wlc_info *wlc)
6436 /* when interrupt is generated, the counter is loaded with last value
6437 * written and continue to decrement. So it has to be cleaned first
6439 W_REG(&wlc->regs->gptimer, 0);
6443 * This fn has all the high level dpc processing from wlc_dpc.
6444 * POLICY: no macinstatus change, no bounding loop.
6445 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6447 void wlc_high_dpc(struct wlc_info *wlc, u32 macintstatus)
6449 d11regs_t *regs = wlc->regs;
6452 static const bcm_bit_desc_t int_flags[] = {
6453 {MI_MACSSPNDD, "MACSSPNDD"},
6454 {MI_BCNTPL, "BCNTPL"},
6456 {MI_BCNSUCCESS, "BCNSUCCESS"},
6457 {MI_BCNCANCLD, "BCNCANCLD"},
6458 {MI_ATIMWINEND, "ATIMWINEND"},
6460 {MI_NSPECGEN_0, "NSPECGEN_0"},
6461 {MI_NSPECGEN_1, "NSPECGEN_1"},
6462 {MI_MACTXERR, "MACTXERR"},
6463 {MI_NSPECGEN_3, "NSPECGEN_3"},
6464 {MI_PHYTXERR, "PHYTXERR"},
6468 {MI_DMAINT, "DMAINT"},
6469 {MI_TXSTOP, "TXSTOP"},
6471 {MI_BG_NOISE, "BG_NOISE"},
6472 {MI_DTIM_TBTT, "DTIM_TBTT"},
6474 {MI_PWRUP, "PWRUP"},
6475 {MI_RFDISABLE, "RFDISABLE"},
6477 {MI_PHYCHANGED, "PHYCHANGED"},
6482 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) {
6483 bcm_format_flags(int_flags, macintstatus, flagstr,
6485 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6486 wlc->pub->unit, macintstatus, flagstr);
6490 if (macintstatus & MI_PRQ) {
6491 /* Process probe request FIFO */
6492 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6495 /* TBTT indication */
6496 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6497 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
6498 wlc_tbtt(wlc, regs);
6500 if (macintstatus & MI_GP0) {
6501 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6502 wlc->pub->unit, wlc->pub->now);
6504 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6505 __func__, wlc->pub->sih->chip,
6506 wlc->pub->sih->chiprev);
6508 wlc->pub->_cnt->psmwds++;
6514 /* gptimer timeout */
6515 if (macintstatus & MI_TO) {
6516 wlc_hwtimer_gptimer_cb(wlc);
6519 if (macintstatus & MI_RFDISABLE) {
6520 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6522 R_REG(®s->phydebug) & PDBG_RFD);
6523 /* delay the cleanup to wl_down in IBSS case */
6524 if ((R_REG(®s->phydebug) & PDBG_RFD)) {
6526 wlc_bsscfg_t *bsscfg;
6527 FOREACH_BSS(wlc, idx, bsscfg) {
6528 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable
6531 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6537 /* send any enq'd tx packets. Just makes sure to jump start tx */
6538 if (!pktq_empty(&wlc->active_queue->q))
6539 wlc_send_q(wlc, wlc->active_queue);
6541 ASSERT(wlc_ps_check(wlc));
6544 static void wlc_war16165(struct wlc_info *wlc, bool tx)
6547 /* the post-increment is used in STAY_AWAKE macro */
6548 if (wlc->txpend16165war++ == 0)
6549 wlc_set_ps_ctrl(wlc);
6551 wlc->txpend16165war--;
6552 if (wlc->txpend16165war == 0)
6553 wlc_set_ps_ctrl(wlc);
6557 /* process an individual tx_status_t */
6560 wlc_dotxstatus(struct wlc_info *wlc, tx_status_t *txs, u32 frm_tx2)
6565 struct scb *scb = NULL;
6567 int tx_rts, tx_frame_count, tx_rts_count;
6568 uint totlen, supr_status;
6570 struct ieee80211_hdr *h;
6572 struct ieee80211_tx_info *tx_info;
6573 struct ieee80211_tx_rate *txrate;
6576 (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */
6578 /* discard intermediate indications for ucode with one legitimate case:
6579 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6580 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6581 * transmission count)
6583 if (!(txs->status & TX_STATUS_AMPDU)
6584 && (txs->status & TX_STATUS_INTERMEDIATE)) {
6585 WLCNTADD(wlc->pub->_cnt->txnoack,
6587 status & TX_STATUS_FRM_RTX_MASK) >>
6588 TX_STATUS_FRM_RTX_SHIFT));
6589 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__);
6593 queue = txs->frameid & TXFID_QUEUE_MASK;
6594 ASSERT(queue < NFIFO);
6595 if (queue >= NFIFO) {
6600 p = GETNEXTTXP(wlc, queue);
6601 if (WLC_WAR16165(wlc))
6602 wlc_war16165(wlc, false);
6606 txh = (d11txh_t *) (p->data);
6607 mcl = le16_to_cpu(txh->MacTxControlLow);
6610 if (WL_ERROR_ON()) {
6611 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6612 txs->phyerr, txh->MainRates);
6613 wlc_print_txdesc(txh);
6615 wlc_print_txstatus(txs);
6618 ASSERT(txs->frameid == cpu_to_le16(txh->TxFrameID));
6619 if (txs->frameid != cpu_to_le16(txh->TxFrameID))
6622 tx_info = IEEE80211_SKB_CB(p);
6623 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
6625 scb = (struct scb *)tx_info->control.sta->drv_priv;
6627 if (N_ENAB(wlc->pub)) {
6628 u8 *plcp = (u8 *) (txh + 1);
6629 if (PLCP3_ISSGI(plcp[3]))
6630 wlc->pub->_cnt->txmpdu_sgi++;
6631 if (PLCP3_ISSTBC(plcp[3]))
6632 wlc->pub->_cnt->txmpdu_stbc++;
6635 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
6636 ASSERT((mcl & TXC_AMPDU_MASK) != TXC_AMPDU_NONE);
6637 wlc_ampdu_dotxstatus(wlc->ampdu, scb, p, txs);
6641 supr_status = txs->status & TX_STATUS_SUPR_MASK;
6642 if (supr_status == TX_STATUS_SUPR_BADCH)
6643 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6644 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec));
6646 tx_rts = cpu_to_le16(txh->MacTxControlLow) & TXC_SENDRTS;
6648 (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT;
6650 (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT;
6652 lastframe = !ieee80211_has_morefrags(h->frame_control);
6655 WL_ERROR("Not last frame!\n");
6658 ieee80211_tx_info_clear_status(tx_info);
6659 if (queue < AC_COUNT) {
6660 sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]);
6661 lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]);
6667 txrate = tx_info->status.rates;
6668 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6669 if ((tx_frame_count > sfbl) && (txrate[1].idx >= 0)) {
6670 /* rate selection requested a fallback rate and we used it */
6671 txrate->count = lfbl;
6672 txrate[1].count = tx_frame_count - lfbl;
6674 /* rate selection did not request fallback rate, or we didn't need it */
6675 txrate->count = tx_frame_count;
6676 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6678 txrate[1].count = 0;
6681 /* clear the rest of the rates */
6682 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
6684 txrate[i].count = 0;
6687 if (txs->status & TX_STATUS_ACK_RCV)
6688 tx_info->flags |= IEEE80211_TX_STAT_ACK;
6691 totlen = pkttotlen(p);
6694 wlc_txfifo_complete(wlc, queue, 1);
6700 /* remove PLCP & Broadcom tx descriptor header */
6701 skb_pull(p, D11_PHY_HDR_LEN);
6702 skb_pull(p, D11_TXH_LEN);
6703 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
6704 wlc->pub->_cnt->ieee_tx_status++;
6706 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6715 pkt_buf_free_skb(wlc->osh, p, true);
6722 wlc_txfifo_complete(struct wlc_info *wlc, uint fifo, s8 txpktpend)
6724 TXPKTPENDDEC(wlc, fifo, txpktpend);
6725 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6726 txpktpend, TXPKTPENDGET(wlc, fifo));
6728 /* There is more room; mark precedences related to this FIFO sendable */
6729 WLC_TX_FIFO_ENAB(wlc, fifo);
6730 ASSERT(TXPKTPENDGET(wlc, fifo) >= 0);
6732 if (!TXPKTPENDTOT(wlc)) {
6733 if (wlc->block_datafifo & DATA_BLOCK_TX_SUPR)
6734 wlc_bsscfg_tx_check(wlc);
6737 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6738 if (AP_ENAB(wlc->pub) &&
6739 wlc->bcmcfifo_drain && !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) {
6740 wlc->bcmcfifo_drain = false;
6741 wlc_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO);
6744 /* figure out which bsscfg is being worked on... */
6747 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6748 * return the offset (in us) of the TSF from the last TBTT
6750 u32 wlc_calc_tbtt_offset(u32 bp, u32 tsf_h, u32 tsf_l)
6752 u32 k, btklo, btkhi, offset;
6754 /* TBTT is always an even multiple of the beacon_interval,
6755 * so the TBTT less than or equal to the beacon timestamp is
6756 * the beacon timestamp minus the beacon timestamp modulo
6757 * the beacon interval.
6759 * TBTT = BT - (BT % BIu)
6760 * = (BTk - (BTk % BP)) * 2^10
6762 * BT = beacon timestamp (usec, 64bits)
6763 * BTk = beacon timestamp (Kusec, 54bits)
6764 * BP = beacon interval (Kusec, 16bits)
6765 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6767 * To keep the calculations in u32s, the modulo operation
6768 * on the high part of BT needs to be done in parts using the
6770 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6772 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6774 * So, if BTk[n] = u16 n [0,3] of BTk.
6775 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6776 * and the SUM term can be broken down:
6777 * (BTk[n] * 2^16n) % BP
6778 * (BTk[n] * (2^16n % BP)) % BP
6780 * Create a set of power of 2 mod BP constants:
6781 * K[n] = 2^(16n) % BP
6782 * = (K[n-1] * 2^16) % BP
6783 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6785 * BTk % BP = BTk[0-1] % BP +
6786 * (BTk[2] * K[2]) % BP +
6787 * (BTk[3] * K[3]) % BP
6789 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6792 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6793 btklo = (tsf_h << 22) | (tsf_l >> 10);
6794 btkhi = tsf_h >> 10;
6796 /* offset = BTk % BP */
6797 offset = btklo % bp;
6799 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6800 k = (u32) (1 << 16) % bp;
6801 k = (u32) (k * 1 << 16) % (u32) bp;
6803 /* offset += (BTk[2] * K[2]) % BP */
6804 offset += ((btkhi & 0xffff) * k) % bp;
6807 btkhi = btkhi >> 16;
6809 /* k[3] = (K[2] * 2^16) % BP */
6812 /* offset += (BTk[3] * K[3]) % BP */
6813 offset += ((btkhi & 0xffff) * k) % bp;
6815 offset = offset % bp;
6817 /* convert offset from kus to us by shifting up 10 bits and
6818 * add in the low 10 bits of tsf that we ignored
6820 offset = (offset << 10) + (tsf_l & 0x3FF);
6825 /* Update beacon listen interval in shared memory */
6826 void wlc_bcn_li_upd(struct wlc_info *wlc)
6828 if (AP_ENAB(wlc->pub))
6831 /* wake up every DTIM is the default */
6832 if (wlc->bcn_li_dtim == 1)
6833 wlc_write_shm(wlc, M_BCN_LI, 0);
6835 wlc_write_shm(wlc, M_BCN_LI,
6836 (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
6840 prep_mac80211_status(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p,
6841 struct ieee80211_rx_status *rx_status)
6844 wlc_d11rxhdr_t *wlc_rxh = (wlc_d11rxhdr_t *) rxh;
6848 unsigned char *plcp;
6850 wlc_read_tsf(wlc, &tsf_l, &tsf_h); /* mactime */
6851 rx_status->mactime = tsf_h;
6852 rx_status->mactime <<= 32;
6853 rx_status->mactime |= tsf_l;
6854 rx_status->flag |= RX_FLAG_TSFT;
6856 channel = WLC_CHAN_CHANNEL(rxh->RxChan);
6858 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
6860 rx_status->band = IEEE80211_BAND_5GHZ;
6861 rx_status->freq = ieee80211_ofdm_chan_to_freq(
6862 WF_CHAN_FACTOR_5_G/2, channel);
6865 rx_status->band = IEEE80211_BAND_2GHZ;
6866 rx_status->freq = ieee80211_dsss_chan_to_freq(channel);
6869 rx_status->signal = wlc_rxh->rssi; /* signal */
6873 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
6877 rspec = wlc_compute_rspec(rxh, plcp);
6878 if (IS_MCS(rspec)) {
6879 rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
6880 rx_status->flag |= RX_FLAG_HT;
6881 if (RSPEC_IS40MHZ(rspec))
6882 rx_status->flag |= RX_FLAG_40MHZ;
6884 switch (RSPEC2RATE(rspec)) {
6886 rx_status->rate_idx = 0;
6889 rx_status->rate_idx = 1;
6892 rx_status->rate_idx = 2;
6895 rx_status->rate_idx = 3;
6898 rx_status->rate_idx = 4;
6901 rx_status->rate_idx = 5;
6904 rx_status->rate_idx = 6;
6907 rx_status->rate_idx = 7;
6910 rx_status->rate_idx = 8;
6913 rx_status->rate_idx = 9;
6916 rx_status->rate_idx = 10;
6919 rx_status->rate_idx = 11;
6922 WL_ERROR("%s: Unknown rate\n", __func__);
6925 /* Determine short preamble and rate_idx */
6927 if (IS_CCK(rspec)) {
6928 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
6929 WL_ERROR("Short CCK\n");
6930 rx_status->flag |= RX_FLAG_SHORTPRE;
6931 } else if (IS_OFDM(rspec)) {
6932 rx_status->flag |= RX_FLAG_SHORTPRE;
6934 WL_ERROR("%s: Unknown modulation\n", __func__);
6938 if (PLCP3_ISSGI(plcp[3]))
6939 rx_status->flag |= RX_FLAG_SHORT_GI;
6941 if (rxh->RxStatus1 & RXS_DECERR) {
6942 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
6943 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__);
6945 if (rxh->RxStatus1 & RXS_FCSERR) {
6946 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
6947 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__);
6952 wlc_recvctl(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p)
6955 struct ieee80211_rx_status rx_status;
6957 struct sk_buff *skb = p;
6960 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
6961 * Test for INTERMEDIATE like so:
6962 * if (!(plcp[0] | plcp[1] | plcp[2]))
6965 memset(&rx_status, 0, sizeof(rx_status));
6966 prep_mac80211_status(wlc, rxh, p, &rx_status);
6968 /* mac header+body length, exclude CRC and plcp header */
6969 len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN;
6970 skb_pull(p, D11_PHY_HDR_LEN);
6971 __skb_trim(p, len_mpdu);
6976 ASSERT(IS_ALIGNED((unsigned long)skb->data, 2));
6978 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
6979 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
6981 wlc->pub->_cnt->ieee_rx++;
6982 wlc->osh->pktalloced--;
6986 void wlc_bss_list_free(struct wlc_info *wlc, struct wlc_bss_list *bss_list)
6991 WL_ERROR("%s: Attempting to free NULL list\n", __func__);
6994 /* inspect all BSS descriptor */
6995 for (index = 0; index < bss_list->count; index++) {
6996 kfree(bss_list->ptrs[index]);
6997 bss_list->ptrs[index] = NULL;
6999 bss_list->count = 0;
7002 /* Process received frames */
7004 * Return true if more frames need to be processed. false otherwise.
7005 * Param 'bound' indicates max. # frames to process before break out.
7008 void BCMFASTPATH wlc_recv(struct wlc_info *wlc, struct sk_buff *p)
7011 struct ieee80211_hdr *h;
7015 WL_TRACE("wl%d: wlc_recv\n", wlc->pub->unit);
7017 /* frame starts with rxhdr */
7018 rxh = (d11rxhdr_t *) (p->data);
7020 /* strip off rxhdr */
7021 skb_pull(p, wlc->hwrxoff);
7023 /* fixup rx header endianness */
7024 rxh->RxFrameSize = le16_to_cpu(rxh->RxFrameSize);
7025 rxh->PhyRxStatus_0 = le16_to_cpu(rxh->PhyRxStatus_0);
7026 rxh->PhyRxStatus_1 = le16_to_cpu(rxh->PhyRxStatus_1);
7027 rxh->PhyRxStatus_2 = le16_to_cpu(rxh->PhyRxStatus_2);
7028 rxh->PhyRxStatus_3 = le16_to_cpu(rxh->PhyRxStatus_3);
7029 rxh->PhyRxStatus_4 = le16_to_cpu(rxh->PhyRxStatus_4);
7030 rxh->PhyRxStatus_5 = le16_to_cpu(rxh->PhyRxStatus_5);
7031 rxh->RxStatus1 = le16_to_cpu(rxh->RxStatus1);
7032 rxh->RxStatus2 = le16_to_cpu(rxh->RxStatus2);
7033 rxh->RxTSFTime = le16_to_cpu(rxh->RxTSFTime);
7034 rxh->RxChan = le16_to_cpu(rxh->RxChan);
7036 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7037 if (rxh->RxStatus1 & RXS_PBPRES) {
7039 wlc->pub->_cnt->rxrunt++;
7040 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7041 wlc->pub->unit, p->len);
7047 h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN);
7050 if (rxh->RxStatus1 & RXS_FCSERR) {
7051 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
7052 WL_ERROR("FCSERR while scanning******* - tossing\n");
7055 WL_ERROR("RCSERR!!!\n");
7060 /* check received pkt has at least frame control field */
7061 if (len < D11_PHY_HDR_LEN + sizeof(h->frame_control)) {
7062 wlc->pub->_cnt->rxrunt++;
7066 is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK;
7068 /* explicitly test bad src address to avoid sending bad deauth */
7070 /* CTS and ACK CTL frames are w/o a2 */
7072 if (ieee80211_is_data(h->frame_control) ||
7073 ieee80211_is_mgmt(h->frame_control)) {
7074 if ((is_zero_ether_addr(h->addr2) ||
7075 is_multicast_ether_addr(h->addr2))) {
7076 WL_ERROR("wl%d: %s: dropping a frame with "
7077 "invalid src mac address, a2: %pM\n",
7078 wlc->pub->unit, __func__, h->addr2);
7079 wlc->pub->_cnt->rxbadsrcmac++;
7082 wlc->pub->_cnt->rxfrag++;
7086 /* due to sheer numbers, toss out probe reqs for now */
7087 if (ieee80211_is_probe_req(h->frame_control))
7091 WL_ERROR("%s: is_amsdu causing toss\n", __func__);
7095 wlc_recvctl(wlc, rxh, p);
7099 pkt_buf_free_skb(wlc->osh, p, false);
7102 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7103 * number of bytes goes in the length field
7105 * Formula given by HT PHY Spec v 1.13
7106 * len = 3(nsyms + nstream + 3) - 3
7109 wlc_calc_lsig_len(struct wlc_info *wlc, ratespec_t ratespec, uint mac_len)
7111 uint nsyms, len = 0, kNdps;
7113 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7114 wlc->pub->unit, RSPEC2RATE(ratespec), mac_len);
7116 if (IS_MCS(ratespec)) {
7117 uint mcs = ratespec & RSPEC_RATE_MASK;
7118 /* MCS_TXS(mcs) returns num tx streams - 1 */
7119 int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec);
7121 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7122 /* the payload duration calculation matches that of regular ofdm */
7123 /* 1000Ndbps = kbps * 4 */
7125 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7126 RSPEC_ISSGI(ratespec)) * 4;
7128 if (RSPEC_STC(ratespec) == 0)
7129 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7131 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7132 APHY_TAIL_NBITS) * 1000, kNdps);
7134 /* STBC needs to have even number of symbols */
7137 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7138 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7140 nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7141 /* 3 bytes/symbol @ legacy 6Mbps rate */
7142 len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */
7148 /* calculate frame duration of a given rate and length, return time in usec unit */
7150 wlc_calc_frame_time(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7153 uint nsyms, dur = 0, Ndps, kNdps;
7154 uint rate = RSPEC2RATE(ratespec);
7158 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit);
7162 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7163 wlc->pub->unit, ratespec, preamble_type, mac_len);
7165 if (IS_MCS(ratespec)) {
7166 uint mcs = ratespec & RSPEC_RATE_MASK;
7167 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7168 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7169 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type));
7171 dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7172 if (preamble_type == WLC_MM_PREAMBLE)
7174 /* 1000Ndbps = kbps * 4 */
7176 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7177 RSPEC_ISSGI(ratespec)) * 4;
7179 if (RSPEC_STC(ratespec) == 0)
7180 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7182 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7183 APHY_TAIL_NBITS) * 1000, kNdps);
7185 /* STBC needs to have even number of symbols */
7188 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7189 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7191 dur += APHY_SYMBOL_TIME * nsyms;
7192 if (BAND_2G(wlc->band->bandtype))
7193 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7194 } else if (IS_OFDM(rate)) {
7195 dur = APHY_PREAMBLE_TIME;
7196 dur += APHY_SIGNAL_TIME;
7197 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7199 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7201 CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS),
7203 dur += APHY_SYMBOL_TIME * nsyms;
7204 if (BAND_2G(wlc->band->bandtype))
7205 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7207 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7208 mac_len = mac_len * 8 * 2;
7209 /* calc ceiling of bits/rate = microseconds of air time */
7210 dur = (mac_len + rate - 1) / rate;
7211 if (preamble_type & WLC_SHORT_PREAMBLE)
7212 dur += BPHY_PLCP_SHORT_TIME;
7214 dur += BPHY_PLCP_TIME;
7219 /* The opposite of wlc_calc_frame_time */
7221 wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7224 uint nsyms, mac_len, Ndps, kNdps;
7225 uint rate = RSPEC2RATE(ratespec);
7227 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7228 wlc->pub->unit, ratespec, preamble_type, dur);
7230 if (IS_MCS(ratespec)) {
7231 uint mcs = ratespec & RSPEC_RATE_MASK;
7232 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7233 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7234 dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7235 /* payload calculation matches that of regular ofdm */
7236 if (BAND_2G(wlc->band->bandtype))
7237 dur -= DOT11_OFDM_SIGNAL_EXTENSION;
7238 /* kNdbps = kbps * 4 */
7240 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7241 RSPEC_ISSGI(ratespec)) * 4;
7242 nsyms = dur / APHY_SYMBOL_TIME;
7245 ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000;
7246 } else if (IS_OFDM(ratespec)) {
7247 dur -= APHY_PREAMBLE_TIME;
7248 dur -= APHY_SIGNAL_TIME;
7249 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7251 nsyms = dur / APHY_SYMBOL_TIME;
7254 (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8;
7256 if (preamble_type & WLC_SHORT_PREAMBLE)
7257 dur -= BPHY_PLCP_SHORT_TIME;
7259 dur -= BPHY_PLCP_TIME;
7260 mac_len = dur * rate;
7261 /* divide out factor of 2 in rate (1/2 mbps) */
7262 mac_len = mac_len / 8 / 2;
7268 wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7270 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7271 wlc->pub->unit, rspec, preamble_type);
7272 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7273 * or equal to the rate of the immediately previous frame in the FES
7275 rspec = WLC_BASIC_RATE(wlc, rspec);
7276 ASSERT(VALID_RATE_DBG(wlc, rspec));
7278 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7279 return wlc_calc_frame_time(wlc, rspec, preamble_type,
7280 (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
7284 static uint BCMFASTPATH
7285 wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7289 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7290 wlc->pub->unit, rspec, preamble_type);
7291 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7292 * or equal to the rate of the immediately previous frame in the FES
7294 rspec = WLC_BASIC_RATE(wlc, rspec);
7295 ASSERT(VALID_RATE_DBG(wlc, rspec));
7297 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7299 wlc_calc_frame_time(wlc, rspec, preamble_type,
7300 (DOT11_ACK_LEN + FCS_LEN));
7305 wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7307 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7308 wlc->pub->unit, rspec, preamble_type);
7309 return wlc_calc_ack_time(wlc, rspec, preamble_type);
7312 /* derive wlc->band->basic_rate[] table from 'rateset' */
7313 void wlc_rate_lookup_init(struct wlc_info *wlc, wlc_rateset_t *rateset)
7319 u8 *br = wlc->band->basic_rate;
7322 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7323 memset(br, 0, WLC_MAXRATE + 1);
7325 /* For each basic rate in the rates list, make an entry in the
7326 * best basic lookup.
7328 for (i = 0; i < rateset->count; i++) {
7329 /* only make an entry for a basic rate */
7330 if (!(rateset->rates[i] & WLC_RATE_FLAG))
7333 /* mask off basic bit */
7334 rate = (rateset->rates[i] & RATE_MASK);
7336 if (rate > WLC_MAXRATE) {
7337 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7345 /* The rate lookup table now has non-zero entries for each
7346 * basic rate, equal to the basic rate: br[basicN] = basicN
7348 * To look up the best basic rate corresponding to any
7349 * particular rate, code can use the basic_rate table
7352 * basic_rate = wlc->band->basic_rate[tx_rate]
7354 * Make sure there is a best basic rate entry for
7355 * every rate by walking up the table from low rates
7356 * to high, filling in holes in the lookup table
7359 for (i = 0; i < wlc->band->hw_rateset.count; i++) {
7360 rate = wlc->band->hw_rateset.rates[i];
7361 ASSERT(rate <= WLC_MAXRATE);
7363 if (br[rate] != 0) {
7364 /* This rate is a basic rate.
7365 * Keep track of the best basic rate so far by
7376 /* This rate is not a basic rate so figure out the
7377 * best basic rate less than this rate and fill in
7378 * the hole in the table
7381 br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic;
7386 if (IS_OFDM(rate)) {
7387 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7388 if (rate >= WLC_RATE_24M)
7389 mandatory = WLC_RATE_24M;
7390 else if (rate >= WLC_RATE_12M)
7391 mandatory = WLC_RATE_12M;
7393 mandatory = WLC_RATE_6M;
7395 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7399 br[rate] = mandatory;
7403 static void wlc_write_rate_shm(struct wlc_info *wlc, u8 rate, u8 basic_rate)
7406 u8 basic_phy_rate, basic_index;
7407 u16 dir_table, basic_table;
7410 /* Shared memory address for the table we are reading */
7411 dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
7413 /* Shared memory address for the table we are writing */
7414 basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
7417 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7418 * the index into the rate table.
7420 phy_rate = rate_info[rate] & RATE_MASK;
7421 basic_phy_rate = rate_info[basic_rate] & RATE_MASK;
7422 index = phy_rate & 0xf;
7423 basic_index = basic_phy_rate & 0xf;
7425 /* Find the SHM pointer to the ACK rate entry by looking in the
7428 basic_ptr = wlc_read_shm(wlc, (dir_table + basic_index * 2));
7430 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7431 * to the correct basic rate for the given incoming rate
7433 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr);
7436 static const wlc_rateset_t *wlc_rateset_get_hwrs(struct wlc_info *wlc)
7438 const wlc_rateset_t *rs_dflt;
7440 if (WLC_PHY_11N_CAP(wlc->band)) {
7441 if (BAND_5G(wlc->band->bandtype))
7442 rs_dflt = &ofdm_mimo_rates;
7444 rs_dflt = &cck_ofdm_mimo_rates;
7445 } else if (wlc->band->gmode)
7446 rs_dflt = &cck_ofdm_rates;
7448 rs_dflt = &cck_rates;
7453 void wlc_set_ratetable(struct wlc_info *wlc)
7455 const wlc_rateset_t *rs_dflt;
7457 u8 rate, basic_rate;
7460 rs_dflt = wlc_rateset_get_hwrs(wlc);
7461 ASSERT(rs_dflt != NULL);
7463 wlc_rateset_copy(rs_dflt, &rs);
7464 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7466 /* walk the phy rate table and update SHM basic rate lookup table */
7467 for (i = 0; i < rs.count; i++) {
7468 rate = rs.rates[i] & RATE_MASK;
7470 /* for a given rate WLC_BASIC_RATE returns the rate at
7471 * which a response ACK/CTS should be sent.
7473 basic_rate = WLC_BASIC_RATE(wlc, rate);
7474 if (basic_rate == 0) {
7475 /* This should only happen if we are using a
7476 * restricted rateset.
7478 basic_rate = rs.rates[0] & RATE_MASK;
7481 wlc_write_rate_shm(wlc, rate, basic_rate);
7486 * Return true if the specified rate is supported by the specified band.
7487 * WLC_BAND_AUTO indicates the current band.
7489 bool wlc_valid_rate(struct wlc_info *wlc, ratespec_t rspec, int band,
7492 wlc_rateset_t *hw_rateset;
7495 if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) {
7496 hw_rateset = &wlc->band->hw_rateset;
7497 } else if (NBANDS(wlc) > 1) {
7498 hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset;
7500 /* other band specified and we are a single band device */
7504 /* check if this is a mimo rate */
7505 if (IS_MCS(rspec)) {
7506 if (!VALID_MCS((rspec & RSPEC_RATE_MASK)))
7509 return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK));
7512 for (i = 0; i < hw_rateset->count; i++)
7513 if (hw_rateset->rates[i] == RSPEC2RATE(rspec))
7517 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7518 wlc->pub->unit, rspec);
7524 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap)
7527 struct wlcband *band;
7529 for (i = 0; i < NBANDS(wlc); i++) {
7530 if (IS_SINGLEBAND_5G(wlc->deviceid))
7532 band = wlc->bandstate[i];
7533 if (band->bandtype == WLC_BAND_5G) {
7534 if ((bwcap == WLC_N_BW_40ALL)
7535 || (bwcap == WLC_N_BW_20IN2G_40IN5G))
7536 band->mimo_cap_40 = true;
7538 band->mimo_cap_40 = false;
7540 ASSERT(band->bandtype == WLC_BAND_2G);
7541 if (bwcap == WLC_N_BW_40ALL)
7542 band->mimo_cap_40 = true;
7544 band->mimo_cap_40 = false;
7548 wlc->mimo_band_bwcap = bwcap;
7551 void wlc_mod_prb_rsp_rate_table(struct wlc_info *wlc, uint frame_len)
7553 const wlc_rateset_t *rs_dflt;
7557 u8 plcp[D11_PHY_HDR_LEN];
7561 sifs = SIFS(wlc->band);
7563 rs_dflt = wlc_rateset_get_hwrs(wlc);
7564 ASSERT(rs_dflt != NULL);
7566 wlc_rateset_copy(rs_dflt, &rs);
7567 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7569 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7570 for (i = 0; i < rs.count; i++) {
7571 rate = rs.rates[i] & RATE_MASK;
7573 entry_ptr = wlc_rate_shm_offset(wlc, rate);
7575 /* Calculate the Probe Response PLCP for the given rate */
7576 wlc_compute_plcp(wlc, rate, frame_len, plcp);
7578 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7580 (u16) wlc_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE,
7584 /* Update the SHM Rate Table entry Probe Response values */
7585 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS,
7586 (u16) (plcp[0] + (plcp[1] << 8)));
7587 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2,
7588 (u16) (plcp[2] + (plcp[3] << 8)));
7589 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur);
7594 wlc_compute_bcntsfoff(struct wlc_info *wlc, ratespec_t rspec,
7595 bool short_preamble, bool phydelay)
7599 if (IS_MCS(rspec)) {
7600 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7601 wlc->pub->unit, rspec);
7602 } else if (IS_OFDM(rspec)) {
7603 /* tx delay from MAC through phy to air (2.1 usec) +
7604 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7605 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7606 * bytes at beacon rate)
7608 bcntsfoff += phydelay ? D11A_PHY_TX_DELAY : 0;
7609 bcntsfoff += APHY_PREAMBLE_TIME + APHY_SIGNAL_TIME;
7611 wlc_compute_airtime(wlc, rspec,
7612 APHY_SERVICE_NBITS / 8 +
7615 /* tx delay from MAC through phy to air (3.4 usec) +
7616 * phy header time (long preamble + PLCP == 192 usec) +
7617 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7619 bcntsfoff += phydelay ? D11B_PHY_TX_DELAY : 0;
7621 short_preamble ? D11B_PHY_SPREHDR_TIME :
7622 D11B_PHY_LPREHDR_TIME;
7623 bcntsfoff += wlc_compute_airtime(wlc, rspec, DOT11_MAC_HDR_LEN);
7625 return (u16) (bcntsfoff);
7628 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7630 * PLCP header is 6 bytes.
7631 * 802.11 A3 header is 24 bytes.
7632 * Max beacon frame body template length is 112 bytes.
7633 * Max probe resp frame body template length is 110 bytes.
7635 * *len on input contains the max length of the packet available.
7637 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7638 * and included up to, but not including, the 4 byte FCS.
7641 wlc_bcn_prb_template(struct wlc_info *wlc, u16 type, ratespec_t bcn_rspec,
7642 wlc_bsscfg_t *cfg, u16 *buf, int *len)
7644 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
7645 cck_phy_hdr_t *plcp;
7646 struct ieee80211_mgmt *h;
7647 int hdr_len, body_len;
7649 ASSERT(*len >= 142);
7650 ASSERT(type == IEEE80211_STYPE_BEACON ||
7651 type == IEEE80211_STYPE_PROBE_RESP);
7653 if (MBSS_BCN_ENAB(cfg) && type == IEEE80211_STYPE_BEACON)
7654 hdr_len = DOT11_MAC_HDR_LEN;
7656 hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN;
7657 body_len = *len - hdr_len; /* calc buffer size provided for frame body */
7659 *len = hdr_len + body_len; /* return actual size */
7661 /* format PHY and MAC headers */
7662 memset((char *)buf, 0, hdr_len);
7664 plcp = (cck_phy_hdr_t *) buf;
7666 /* PLCP for Probe Response frames are filled in from core's rate table */
7667 if (type == IEEE80211_STYPE_BEACON && !MBSS_BCN_ENAB(cfg)) {
7669 wlc_compute_plcp(wlc, bcn_rspec,
7670 (DOT11_MAC_HDR_LEN + body_len + FCS_LEN),
7674 /* "Regular" and 16 MBSS but not for 4 MBSS */
7675 /* Update the phytxctl for the beacon based on the rspec */
7676 if (!SOFTBCN_ENAB(cfg))
7677 wlc_beacon_phytxctl_txant_upd(wlc, bcn_rspec);
7679 if (MBSS_BCN_ENAB(cfg) && type == IEEE80211_STYPE_BEACON)
7680 h = (struct ieee80211_mgmt *)&plcp[0];
7682 h = (struct ieee80211_mgmt *)&plcp[1];
7684 /* fill in 802.11 header */
7685 h->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | type);
7687 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7688 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7689 if (type == IEEE80211_STYPE_BEACON)
7690 memcpy(&h->da, ðer_bcast, ETH_ALEN);
7691 memcpy(&h->sa, &cfg->cur_etheraddr, ETH_ALEN);
7692 memcpy(&h->bssid, &cfg->BSSID, ETH_ALEN);
7694 /* SEQ filled in by MAC */
7699 int wlc_get_header_len()
7704 /* Update a beacon for a particular BSS
7705 * For MBSS, this updates the software template and sets "latest" to the index of the
7707 * Otherwise, it updates the hardware template.
7709 void wlc_bss_update_beacon(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7711 int len = BCN_TMPL_LEN;
7713 /* Clear the soft intmask */
7714 wlc->defmacintmask &= ~MI_BCNTPL;
7716 if (!cfg->up) { /* Only allow updates on an UP bss */
7720 /* Optimize: Some of if/else could be combined */
7721 if (!MBSS_BCN_ENAB(cfg) && HWBCN_ENAB(cfg)) {
7722 /* Hardware beaconing for this config */
7723 u16 bcn[BCN_TMPL_LEN / 2];
7724 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
7725 d11regs_t *regs = wlc->regs;
7727 /* Check if both templates are in use, if so sched. an interrupt
7728 * that will call back into this routine
7730 if ((R_REG(®s->maccommand) & both_valid) == both_valid) {
7731 /* clear any previous status */
7732 W_REG(®s->macintstatus, MI_BCNTPL);
7734 /* Check that after scheduling the interrupt both of the
7735 * templates are still busy. if not clear the int. & remask
7737 if ((R_REG(®s->maccommand) & both_valid) == both_valid) {
7738 wlc->defmacintmask |= MI_BCNTPL;
7743 wlc_lowest_basic_rspec(wlc, &cfg->current_bss->rateset);
7744 ASSERT(wlc_valid_rate
7745 (wlc, wlc->bcn_rspec,
7746 CHSPEC_IS2G(cfg->current_bss->
7747 chanspec) ? WLC_BAND_2G : WLC_BAND_5G,
7750 /* update the template and ucode shm */
7751 wlc_bcn_prb_template(wlc, IEEE80211_STYPE_BEACON,
7752 wlc->bcn_rspec, cfg, bcn, &len);
7753 wlc_write_hw_bcntemplates(wlc, bcn, len, false);
7758 * Update all beacons for the system.
7760 void wlc_update_beacon(struct wlc_info *wlc)
7763 wlc_bsscfg_t *bsscfg;
7765 /* update AP or IBSS beacons */
7766 FOREACH_BSS(wlc, idx, bsscfg) {
7767 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7768 wlc_bss_update_beacon(wlc, bsscfg);
7772 /* Write ssid into shared memory */
7773 void wlc_shm_ssid_upd(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7775 u8 *ssidptr = cfg->SSID;
7777 u8 ssidbuf[IEEE80211_MAX_SSID_LEN];
7779 /* padding the ssid with zero and copy it into shm */
7780 memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN);
7781 memcpy(ssidbuf, ssidptr, cfg->SSID_len);
7783 wlc_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN);
7785 if (!MBSS_BCN_ENAB(cfg))
7786 wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len);
7789 void wlc_update_probe_resp(struct wlc_info *wlc, bool suspend)
7792 wlc_bsscfg_t *bsscfg;
7794 /* update AP or IBSS probe responses */
7795 FOREACH_BSS(wlc, idx, bsscfg) {
7796 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7797 wlc_bss_update_probe_resp(wlc, bsscfg, suspend);
7802 wlc_bss_update_probe_resp(struct wlc_info *wlc, wlc_bsscfg_t *cfg, bool suspend)
7804 u16 prb_resp[BCN_TMPL_LEN / 2];
7805 int len = BCN_TMPL_LEN;
7807 /* write the probe response to hardware, or save in the config structure */
7808 if (!MBSS_PRB_ENAB(cfg)) {
7810 /* create the probe response template */
7811 wlc_bcn_prb_template(wlc, IEEE80211_STYPE_PROBE_RESP, 0, cfg,
7815 wlc_suspend_mac_and_wait(wlc);
7817 /* write the probe response into the template region */
7818 wlc_bmac_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
7819 (len + 3) & ~3, prb_resp);
7821 /* write the length of the probe response frame (+PLCP/-FCS) */
7822 wlc_write_shm(wlc, M_PRB_RESP_FRM_LEN, (u16) len);
7824 /* write the SSID and SSID length */
7825 wlc_shm_ssid_upd(wlc, cfg);
7828 * Write PLCP headers and durations for probe response frames at all rates.
7829 * Use the actual frame length covered by the PLCP header for the call to
7830 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7832 len += (-D11_PHY_HDR_LEN + FCS_LEN);
7833 wlc_mod_prb_rsp_rate_table(wlc, (u16) len);
7836 wlc_enable_mac(wlc);
7837 } else { /* Generating probe resp in sw; update local template */
7838 ASSERT(0 && "No software probe response support without MBSS");
7842 /* prepares pdu for transmission. returns BCM error codes */
7843 int wlc_prep_pdu(struct wlc_info *wlc, struct sk_buff *pdu, uint *fifop)
7847 struct ieee80211_hdr *h;
7851 txh = (d11txh_t *) (pdu->data);
7853 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
7856 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7857 fifo = le16_to_cpu(txh->TxFrameID) & TXFID_QUEUE_MASK;
7863 /* return if insufficient dma resources */
7864 if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) {
7865 /* Mark precedences related to this FIFO, unsendable */
7866 WLC_TX_FIFO_CLEAR(wlc, fifo);
7870 if (!ieee80211_is_data(txh->MacFrameControl))
7871 wlc->pub->_cnt->txctl++;
7876 /* init tx reported rate mechanism */
7877 void wlc_reprate_init(struct wlc_info *wlc)
7880 wlc_bsscfg_t *bsscfg;
7882 FOREACH_BSS(wlc, i, bsscfg) {
7883 wlc_bsscfg_reprate_init(bsscfg);
7887 /* per bsscfg init tx reported rate mechanism */
7888 void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg)
7890 bsscfg->txrspecidx = 0;
7891 memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec));
7894 /* Retrieve a consolidated set of revision information,
7895 * typically for the WLC_GET_REVINFO ioctl
7897 int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len)
7899 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf;
7901 if (len < WL_REV_INFO_LEGACY_LENGTH)
7902 return BCME_BUFTOOSHORT;
7904 rinfo->vendorid = wlc->vendorid;
7905 rinfo->deviceid = wlc->deviceid;
7906 rinfo->radiorev = (wlc->band->radiorev << IDCODE_REV_SHIFT) |
7907 (wlc->band->radioid << IDCODE_ID_SHIFT);
7908 rinfo->chiprev = wlc->pub->sih->chiprev;
7909 rinfo->corerev = wlc->pub->corerev;
7910 rinfo->boardid = wlc->pub->sih->boardtype;
7911 rinfo->boardvendor = wlc->pub->sih->boardvendor;
7912 rinfo->boardrev = wlc->pub->boardrev;
7913 rinfo->ucoderev = wlc->ucode_rev;
7914 rinfo->driverrev = EPI_VERSION_NUM;
7915 rinfo->bus = wlc->pub->sih->bustype;
7916 rinfo->chipnum = wlc->pub->sih->chip;
7918 if (len >= (offsetof(wlc_rev_info_t, chippkg))) {
7919 rinfo->phytype = wlc->band->phytype;
7920 rinfo->phyrev = wlc->band->phyrev;
7921 rinfo->anarev = 0; /* obsolete stuff, suppress */
7924 if (len >= sizeof(*rinfo)) {
7925 rinfo->chippkg = wlc->pub->sih->chippkg;
7931 void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs)
7933 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype,
7934 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7935 CHSPEC_WLC_BW(wlc->default_bss->chanspec),
7936 wlc->stf->txstreams);
7939 static void wlc_bss_default_init(struct wlc_info *wlc)
7941 chanspec_t chanspec;
7942 struct wlcband *band;
7943 wlc_bss_info_t *bi = wlc->default_bss;
7945 /* init default and target BSS with some sane initial values */
7946 memset((char *)(bi), 0, sizeof(wlc_bss_info_t));
7947 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT :
7948 BEACON_INTERVAL_DEFAULT;
7949 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT :
7950 DTIM_INTERVAL_DEFAULT;
7952 /* fill the default channel as the first valid channel
7953 * starting from the 2G channels
7955 chanspec = CH20MHZ_CHSPEC(1);
7956 ASSERT(chanspec != INVCHANSPEC);
7958 wlc->home_chanspec = bi->chanspec = chanspec;
7960 /* find the band of our default channel */
7962 if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec))
7963 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
7965 /* init bss rates to the band specific default rate set */
7966 wlc_rateset_default(&bi->rateset, NULL, band->phytype, band->bandtype,
7967 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
7968 CHSPEC_WLC_BW(chanspec), wlc->stf->txstreams);
7970 if (N_ENAB(wlc->pub))
7971 bi->flags |= WLC_BSS_HT;
7975 wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, u32 b_low)
7977 if (b_low > *a_low) {
7978 /* low half needs a carry */
7986 mac80211_wlc_set_nrate(struct wlc_info *wlc, struct wlcband *cur_band,
7989 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
7990 u8 rate = int_val & NRATE_RATE_MASK;
7992 bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE);
7993 bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT);
7994 bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY)
7995 == NRATE_OVERRIDE_MCS_ONLY);
7999 return (ratespec_t) rate;
8002 /* validate the combination of rate/mcs/stf is allowed */
8003 if (N_ENAB(wlc->pub) && ismcs) {
8004 /* mcs only allowed when nmode */
8005 if (stf > PHY_TXC1_MODE_SDM) {
8006 WL_ERROR("wl%d: %s: Invalid stf\n",
8007 WLCWLUNIT(wlc), __func__);
8008 bcmerror = BCME_RANGE;
8012 /* mcs 32 is a special case, DUP mode 40 only */
8014 if (!CHSPEC_IS40(wlc->home_chanspec) ||
8015 ((stf != PHY_TXC1_MODE_SISO)
8016 && (stf != PHY_TXC1_MODE_CDD))) {
8017 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8018 WLCWLUNIT(wlc), __func__);
8019 bcmerror = BCME_RANGE;
8022 /* mcs > 7 must use stf SDM */
8023 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
8024 /* mcs > 7 must use stf SDM */
8025 if (stf != PHY_TXC1_MODE_SDM) {
8026 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8027 WLCWLUNIT(wlc), __func__, rate);
8028 stf = PHY_TXC1_MODE_SDM;
8031 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8032 if ((stf > PHY_TXC1_MODE_STBC) ||
8033 (!WLC_STBC_CAP_PHY(wlc)
8034 && (stf == PHY_TXC1_MODE_STBC))) {
8035 WL_ERROR("wl%d: %s: Invalid STBC\n",
8036 WLCWLUNIT(wlc), __func__);
8037 bcmerror = BCME_RANGE;
8041 } else if (IS_OFDM(rate)) {
8042 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
8043 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8044 WLCWLUNIT(wlc), __func__);
8045 bcmerror = BCME_RANGE;
8048 } else if (IS_CCK(rate)) {
8049 if ((cur_band->bandtype != WLC_BAND_2G)
8050 || (stf != PHY_TXC1_MODE_SISO)) {
8051 WL_ERROR("wl%d: %s: Invalid CCK\n",
8052 WLCWLUNIT(wlc), __func__);
8053 bcmerror = BCME_RANGE;
8057 WL_ERROR("wl%d: %s: Unknown rate type\n",
8058 WLCWLUNIT(wlc), __func__);
8059 bcmerror = BCME_RANGE;
8062 /* make sure multiple antennae are available for non-siso rates */
8063 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
8064 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8065 WLCWLUNIT(wlc), __func__);
8066 bcmerror = BCME_RANGE;
8072 rspec |= RSPEC_MIMORATE;
8073 /* For STBC populate the STC field of the ratespec */
8074 if (stf == PHY_TXC1_MODE_STBC) {
8076 stc = 1; /* Nss for single stream is always 1 */
8077 rspec |= (stc << RSPEC_STC_SHIFT);
8081 rspec |= (stf << RSPEC_STF_SHIFT);
8083 if (override_mcs_only)
8084 rspec |= RSPEC_OVERRIDE_MCS_ONLY;
8087 rspec |= RSPEC_SHORT_GI;
8090 && !wlc_valid_rate(wlc, rspec, cur_band->bandtype, true)) {
8096 WL_ERROR("Hoark\n");
8100 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8102 wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
8105 int idle_busy_ratio_x_16 = 0;
8107 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
8108 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
8109 if (duty_cycle > 100 || duty_cycle < 0) {
8110 WL_ERROR("wl%d: duty cycle value off limit\n", wlc->pub->unit);
8114 idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle;
8115 /* Only write to shared memory when wl is up */
8117 wlc_write_shm(wlc, offset, (u16) idle_busy_ratio_x_16);
8120 wlc->tx_duty_cycle_ofdm = (u16) duty_cycle;
8122 wlc->tx_duty_cycle_cck = (u16) duty_cycle;
8127 /* Read a single u16 from shared memory.
8128 * SHM 'offset' needs to be an even address
8130 u16 wlc_read_shm(struct wlc_info *wlc, uint offset)
8132 return wlc_bmac_read_shm(wlc->hw, offset);
8135 /* Write a single u16 to shared memory.
8136 * SHM 'offset' needs to be an even address
8138 void wlc_write_shm(struct wlc_info *wlc, uint offset, u16 v)
8140 wlc_bmac_write_shm(wlc->hw, offset, v);
8143 /* Set a range of shared memory to a value.
8144 * SHM 'offset' needs to be an even address and
8145 * Range length 'len' must be an even number of bytes
8147 void wlc_set_shm(struct wlc_info *wlc, uint offset, u16 v, int len)
8149 /* offset and len need to be even */
8150 ASSERT((offset & 1) == 0);
8151 ASSERT((len & 1) == 0);
8156 wlc_bmac_set_shm(wlc->hw, offset, v, len);
8159 /* Copy a buffer to shared memory.
8160 * SHM 'offset' needs to be an even address and
8161 * Buffer length 'len' must be an even number of bytes
8163 void wlc_copyto_shm(struct wlc_info *wlc, uint offset, const void *buf, int len)
8165 /* offset and len need to be even */
8166 ASSERT((offset & 1) == 0);
8167 ASSERT((len & 1) == 0);
8171 wlc_bmac_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8175 /* Copy from shared memory to a buffer.
8176 * SHM 'offset' needs to be an even address and
8177 * Buffer length 'len' must be an even number of bytes
8179 void wlc_copyfrom_shm(struct wlc_info *wlc, uint offset, void *buf, int len)
8181 /* offset and len need to be even */
8182 ASSERT((offset & 1) == 0);
8183 ASSERT((len & 1) == 0);
8188 wlc_bmac_copyfrom_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8191 /* wrapper BMAC functions to for HIGH driver access */
8192 void wlc_mctrl(struct wlc_info *wlc, u32 mask, u32 val)
8194 wlc_bmac_mctrl(wlc->hw, mask, val);
8197 void wlc_corereset(struct wlc_info *wlc, u32 flags)
8199 wlc_bmac_corereset(wlc->hw, flags);
8202 void wlc_mhf(struct wlc_info *wlc, u8 idx, u16 mask, u16 val, int bands)
8204 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands);
8207 u16 wlc_mhf_get(struct wlc_info *wlc, u8 idx, int bands)
8209 return wlc_bmac_mhf_get(wlc->hw, idx, bands);
8212 int wlc_xmtfifo_sz_get(struct wlc_info *wlc, uint fifo, uint *blocks)
8214 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks);
8217 void wlc_write_template_ram(struct wlc_info *wlc, int offset, int len,
8220 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf);
8223 void wlc_write_hw_bcntemplates(struct wlc_info *wlc, void *bcn, int len,
8226 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both);
8230 wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
8233 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr);
8234 if (match_reg_offset == RCM_BSSID_OFFSET)
8235 memcpy(wlc->cfg->BSSID, addr, ETH_ALEN);
8238 void wlc_set_rcmta(struct wlc_info *wlc, int idx, const u8 *addr)
8240 wlc_bmac_set_rcmta(wlc->hw, idx, addr);
8243 void wlc_read_tsf(struct wlc_info *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr)
8245 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr);
8248 void wlc_set_cwmin(struct wlc_info *wlc, u16 newmin)
8250 wlc->band->CWmin = newmin;
8251 wlc_bmac_set_cwmin(wlc->hw, newmin);
8254 void wlc_set_cwmax(struct wlc_info *wlc, u16 newmax)
8256 wlc->band->CWmax = newmax;
8257 wlc_bmac_set_cwmax(wlc->hw, newmax);
8260 void wlc_fifoerrors(struct wlc_info *wlc)
8263 wlc_bmac_fifoerrors(wlc->hw);
8266 /* Search mem rw utilities */
8268 void wlc_pllreq(struct wlc_info *wlc, bool set, mbool req_bit)
8270 wlc_bmac_pllreq(wlc->hw, set, req_bit);
8273 void wlc_reset_bmac_done(struct wlc_info *wlc)
8277 void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode)
8279 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_SM_PS;
8280 wlc->ht_cap.cap_info |= (mimops_mode << IEEE80211_HT_CAP_SM_PS_SHIFT);
8282 if (AP_ENAB(wlc->pub) && wlc->clk) {
8283 wlc_update_beacon(wlc);
8284 wlc_update_probe_resp(wlc, true);
8288 /* check for the particular priority flow control bit being set */
8290 wlc_txflowcontrol_prio_isset(struct wlc_info *wlc, struct wlc_txq_info *q,
8295 if (prio == ALLPRIO) {
8296 prio_mask = TXQ_STOP_FOR_PRIOFC_MASK;
8298 ASSERT(prio >= 0 && prio <= MAXPRIO);
8299 prio_mask = NBITVAL(prio);
8302 return (q->stopped & prio_mask) == prio_mask;
8305 /* propogate the flow control to all interfaces using the given tx queue */
8306 void wlc_txflowcontrol(struct wlc_info *wlc, struct wlc_txq_info *qi,
8312 WL_TRACE("%s: flow control kicks in\n", __func__);
8314 if (prio == ALLPRIO) {
8315 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
8317 ASSERT(prio >= 0 && prio <= MAXPRIO);
8318 prio_bits = NBITVAL(prio);
8321 cur_bits = qi->stopped & prio_bits;
8323 /* Check for the case of no change and return early
8324 * Otherwise update the bit and continue
8327 if (cur_bits == prio_bits) {
8330 mboolset(qi->stopped, prio_bits);
8332 if (cur_bits == 0) {
8335 mboolclr(qi->stopped, prio_bits);
8338 /* If there is a flow control override we will not change the external
8339 * flow control state.
8341 if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) {
8345 wlc_txflowcontrol_signal(wlc, qi, on, prio);
8349 wlc_txflowcontrol_override(struct wlc_info *wlc, struct wlc_txq_info *qi,
8350 bool on, uint override)
8354 ASSERT(override != 0);
8355 ASSERT((override & TXQ_STOP_FOR_PRIOFC_MASK) == 0);
8357 prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK);
8359 /* Update the flow control bits and do an early return if there is
8360 * no change in the external flow control state.
8363 mboolset(qi->stopped, override);
8364 /* if there was a previous override bit on, then setting this
8365 * makes no difference.
8367 if (prev_override) {
8371 wlc_txflowcontrol_signal(wlc, qi, ON, ALLPRIO);
8373 mboolclr(qi->stopped, override);
8374 /* clearing an override bit will only make a difference for
8375 * flow control if it was the only bit set. For any other
8376 * override setting, just return
8378 if (prev_override != override) {
8382 if (qi->stopped == 0) {
8383 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8387 for (prio = MAXPRIO; prio >= 0; prio--) {
8388 if (!mboolisset(qi->stopped, NBITVAL(prio)))
8389 wlc_txflowcontrol_signal(wlc, qi, OFF,
8396 static void wlc_txflowcontrol_reset(struct wlc_info *wlc)
8398 struct wlc_txq_info *qi;
8400 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
8402 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8409 wlc_txflowcontrol_signal(struct wlc_info *wlc, struct wlc_txq_info *qi, bool on,
8412 struct wlc_if *wlcif;
8414 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
8415 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
8416 wl_txflowcontrol(wlc->wl, wlcif->wlif, on, prio);
8420 static struct wlc_txq_info *wlc_txq_alloc(struct wlc_info *wlc)
8422 struct wlc_txq_info *qi, *p;
8424 qi = wlc_calloc(wlc->pub->unit, sizeof(struct wlc_txq_info));
8427 * Have enough room for control packets along with HI watermark
8428 * Also, add room to txq for total psq packets if all the SCBs
8429 * leave PS mode. The watermark for flowcontrol to OS packets
8430 * will remain the same
8432 pktq_init(&qi->q, WLC_PREC_COUNT,
8433 (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT
8434 + wlc->pub->psq_pkts_total);
8436 /* add this queue to the the global list */
8439 wlc->tx_queues = qi;
8441 while (p->next != NULL)
8449 static void wlc_txq_free(struct wlc_info *wlc, struct wlc_txq_info *qi)
8451 struct wlc_txq_info *p;
8456 /* remove the queue from the linked list */
8459 wlc->tx_queues = p->next;
8461 while (p != NULL && p->next != qi)
8463 ASSERT(p->next == qi);
8465 p->next = p->next->next;
8472 * Flag 'scan in progress' to withold dynamic phy calibration
8474 void wlc_scan_start(struct wlc_info *wlc)
8476 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, true);
8479 void wlc_scan_stop(struct wlc_info *wlc)
8481 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, false);
8484 void wlc_associate_upd(struct wlc_info *wlc, bool state)
8486 wlc->pub->associated = state;
8487 wlc->cfg->associated = state;