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 <linux/string.h>
27 #include <bcmendian.h>
39 #include <wlc_bsscfg.h>
40 #include <wlc_channel.h>
41 #include <wlc_event.h>
42 #include <wlc_mac80211.h>
45 #include <wlc_phy_hal.h>
46 #include <wlc_phy_shim.h>
47 #include <wlc_antsel.h>
49 #include <wlc_ampdu.h>
50 #include <wlc_event.h>
51 #include <wl_export.h>
52 #include "d11ucode_ext.h"
53 #include <wlc_alloc.h>
54 #include <net/mac80211.h>
58 * Disable statistics counting for WME
60 #define WLCNTSET(a, b)
62 #define WLCNTADD(a, b)
67 #define RSN_CAP_4_REPLAY_CNTRS 2
68 #define RSN_CAP_16_REPLAY_CNTRS 3
70 #define WPA_CAP_4_REPLAY_CNTRS RSN_CAP_4_REPLAY_CNTRS
71 #define WPA_CAP_16_REPLAY_CNTRS RSN_CAP_16_REPLAY_CNTRS
74 * buffer length needed for wlc_format_ssid
75 * 32 SSID chars, max of 4 chars for each SSID char "\xFF", plus NULL.
77 #define SSID_FMT_BUF_LEN ((4 * IEEE80211_MAX_SSID_LEN) + 1)
79 #define TIMER_INTERVAL_WATCHDOG 1000 /* watchdog timer, in unit of ms */
80 #define TIMER_INTERVAL_RADIOCHK 800 /* radio monitor timer, in unit of ms */
82 #ifndef WLC_MPC_MAX_DELAYCNT
83 #define WLC_MPC_MAX_DELAYCNT 10 /* Max MPC timeout, in unit of watchdog */
85 #define WLC_MPC_MIN_DELAYCNT 1 /* Min MPC timeout, in unit of watchdog */
86 #define WLC_MPC_THRESHOLD 3 /* MPC count threshold level */
88 #define BEACON_INTERVAL_DEFAULT 100 /* beacon interval, in unit of 1024TU */
89 #define DTIM_INTERVAL_DEFAULT 3 /* DTIM interval, in unit of beacon interval */
91 /* Scale down delays to accommodate QT slow speed */
92 #define BEACON_INTERVAL_DEF_QT 20 /* beacon interval, in unit of 1024TU */
93 #define DTIM_INTERVAL_DEF_QT 1 /* DTIM interval, in unit of beacon interval */
95 #define TBTT_ALIGN_LEEWAY_US 100 /* min leeway before first TBTT in us */
98 * driver maintains internal 'tick'(wlc->pub->now) which increments in 1s OS timer(soft
99 * watchdog) it is not a wall clock and won't increment when driver is in "down" state
100 * this low resolution driver tick can be used for maintenance tasks such as phy
101 * calibration and scb update
104 /* watchdog trigger mode: OSL timer or TBTT */
105 #define WLC_WATCHDOG_TBTT(wlc) \
106 (wlc->stas_associated > 0 && wlc->PM != PM_OFF && wlc->pub->align_wd_tbtt)
108 /* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
109 #define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
111 #define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
112 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
122 /* Find basic rate for a given rate */
123 #define WLC_BASIC_RATE(wlc, rspec) (IS_MCS(rspec) ? \
124 (wlc)->band->basic_rate[mcs_table[rspec & RSPEC_RATE_MASK].leg_ofdm] : \
125 (wlc)->band->basic_rate[rspec & RSPEC_RATE_MASK])
127 #define FRAMETYPE(r, mimoframe) (IS_MCS(r) ? mimoframe : (IS_CCK(r) ? FT_CCK : FT_OFDM))
129 #define RFDISABLE_DEFAULT 10000000 /* rfdisable delay timer 500 ms, runs of ALP clock */
131 #define WLC_TEMPSENSE_PERIOD 10 /* 10 second timeout */
133 #define SCAN_IN_PROGRESS(x) 0
135 #define EPI_VERSION_NUM 0x054b0b00
138 /* pointer to most recently allocated wl/wlc */
139 static struct wlc_info *wlc_info_dbg = (struct wlc_info *) (NULL);
144 /* Parameter IDs, for use only internally to wlc -- in the wlc_iovars
145 * table and by the wlc_doiovar() function. No ordering is imposed:
146 * the table is keyed by name, and the function uses a switch.
152 IOV_BCN_LI_BCN, /* Beacon listen interval in # of beacons */
153 IOV_LAST /* In case of a need to check max ID number */
156 const bcm_iovar_t wlc_iovars[] = {
157 {"mpc", IOV_MPC, (0), IOVT_BOOL, 0},
158 {"rtsthresh", IOV_RTSTHRESH, (IOVF_WHL), IOVT_UINT16, 0},
159 {"qtxpower", IOV_QTXPOWER, (IOVF_WHL), IOVT_UINT32, 0},
160 {"bcn_li_bcn", IOV_BCN_LI_BCN, (0), IOVT_UINT8, 0},
164 const u8 prio2fifo[NUMPRIO] = {
165 TX_AC_BE_FIFO, /* 0 BE AC_BE Best Effort */
166 TX_AC_BK_FIFO, /* 1 BK AC_BK Background */
167 TX_AC_BK_FIFO, /* 2 -- AC_BK Background */
168 TX_AC_BE_FIFO, /* 3 EE AC_BE Best Effort */
169 TX_AC_VI_FIFO, /* 4 CL AC_VI Video */
170 TX_AC_VI_FIFO, /* 5 VI AC_VI Video */
171 TX_AC_VO_FIFO, /* 6 VO AC_VO Voice */
172 TX_AC_VO_FIFO /* 7 NC AC_VO Voice */
175 /* precedences numbers for wlc queues. These are twice as may levels as
177 * Odd numbers are used for HI priority traffic at same precedence levels
178 * These constants are used ONLY by wlc_prio2prec_map. Do not use them elsewhere.
180 #define _WLC_PREC_NONE 0 /* None = - */
181 #define _WLC_PREC_BK 2 /* BK - Background */
182 #define _WLC_PREC_BE 4 /* BE - Best-effort */
183 #define _WLC_PREC_EE 6 /* EE - Excellent-effort */
184 #define _WLC_PREC_CL 8 /* CL - Controlled Load */
185 #define _WLC_PREC_VI 10 /* Vi - Video */
186 #define _WLC_PREC_VO 12 /* Vo - Voice */
187 #define _WLC_PREC_NC 14 /* NC - Network Control */
189 /* 802.1D Priority to precedence queue mapping */
190 const u8 wlc_prio2prec_map[] = {
191 _WLC_PREC_BE, /* 0 BE - Best-effort */
192 _WLC_PREC_BK, /* 1 BK - Background */
193 _WLC_PREC_NONE, /* 2 None = - */
194 _WLC_PREC_EE, /* 3 EE - Excellent-effort */
195 _WLC_PREC_CL, /* 4 CL - Controlled Load */
196 _WLC_PREC_VI, /* 5 Vi - Video */
197 _WLC_PREC_VO, /* 6 Vo - Voice */
198 _WLC_PREC_NC, /* 7 NC - Network Control */
201 /* Sanity check for tx_prec_map and fifo synchup
202 * Either there are some packets pending for the fifo, else if fifo is empty then
203 * all the corresponding precmap bits should be set
205 #define WLC_TX_FIFO_CHECK(wlc, fifo) (TXPKTPENDGET((wlc), (fifo)) || \
206 (TXPKTPENDGET((wlc), (fifo)) == 0 && \
207 ((wlc)->tx_prec_map & (wlc)->fifo2prec_map[(fifo)]) == \
208 (wlc)->fifo2prec_map[(fifo)]))
210 /* TX FIFO number to WME/802.1E Access Category */
211 const u8 wme_fifo2ac[] = { AC_BK, AC_BE, AC_VI, AC_VO, AC_BE, AC_BE };
213 /* WME/802.1E Access Category to TX FIFO number */
214 static const u8 wme_ac2fifo[] = { 1, 0, 2, 3 };
216 static bool in_send_q = false;
218 /* Shared memory location index for various AC params */
219 #define wme_shmemacindex(ac) wme_ac2fifo[ac]
222 static const char *fifo_names[] = {
223 "AC_BK", "AC_BE", "AC_VI", "AC_VO", "BCMC", "ATIM" };
225 static const char fifo_names[6][0];
228 static const u8 acbitmap2maxprio[] = {
229 PRIO_8021D_BE, PRIO_8021D_BE, PRIO_8021D_BK, PRIO_8021D_BK,
230 PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI, PRIO_8021D_VI,
231 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO,
232 PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO, PRIO_8021D_VO
235 /* currently the best mechanism for determining SIFS is the band in use */
236 #define SIFS(band) ((band)->bandtype == WLC_BAND_5G ? APHY_SIFS_TIME : BPHY_SIFS_TIME);
238 /* value for # replay counters currently supported */
239 #define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
241 /* local prototypes */
242 static u16 BCMFASTPATH wlc_d11hdrs_mac80211(struct wlc_info *wlc,
243 struct ieee80211_hw *hw,
245 struct scb *scb, uint frag,
246 uint nfrags, uint queue,
249 ratespec_t rspec_override);
251 static void wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat);
252 static void wlc_bss_default_init(struct wlc_info *wlc);
253 static void wlc_ucode_mac_upd(struct wlc_info *wlc);
254 static ratespec_t mac80211_wlc_set_nrate(struct wlc_info *wlc,
255 struct wlcband *cur_band, u32 int_val);
256 static void wlc_tx_prec_map_init(struct wlc_info *wlc);
257 static void wlc_watchdog(void *arg);
258 static void wlc_watchdog_by_timer(void *arg);
259 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg);
260 static int wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val,
261 const bcm_iovar_t *vi);
262 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc);
264 /* send and receive */
265 static wlc_txq_info_t *wlc_txq_alloc(struct wlc_info *wlc,
266 struct osl_info *osh);
267 static void wlc_txq_free(struct wlc_info *wlc, struct osl_info *osh,
269 static void wlc_txflowcontrol_signal(struct wlc_info *wlc, wlc_txq_info_t *qi,
271 static void wlc_txflowcontrol_reset(struct wlc_info *wlc);
272 static u16 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec,
274 static void wlc_compute_cck_plcp(ratespec_t rate, uint length, u8 *plcp);
275 static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp);
276 static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp);
277 static u16 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate,
278 u8 preamble_type, uint next_frag_len);
279 static void wlc_recvctl(struct wlc_info *wlc, struct osl_info *osh,
280 d11rxhdr_t *rxh, struct sk_buff *p);
281 static uint wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t rate,
282 u8 preamble_type, uint dur);
283 static uint wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rate,
285 static uint wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rate,
287 /* interrupt, up/down, band */
288 static void wlc_setband(struct wlc_info *wlc, uint bandunit);
289 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc);
290 static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec);
291 static void wlc_bsinit(struct wlc_info *wlc);
292 static int wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
294 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc);
295 static bool wlc_radio_monitor_start(struct wlc_info *wlc);
296 static void wlc_radio_timer(void *arg);
297 static void wlc_radio_enable(struct wlc_info *wlc);
298 static void wlc_radio_upd(struct wlc_info *wlc);
300 /* scan, association, BSS */
301 static uint wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rate,
303 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap);
304 static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val);
305 static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val);
306 static void wlc_war16165(struct wlc_info *wlc, bool tx);
308 static void wlc_process_eventq(void *arg);
309 static void wlc_wme_retries_write(struct wlc_info *wlc);
310 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc);
311 static uint wlc_attach_module(struct wlc_info *wlc);
312 static void wlc_detach_module(struct wlc_info *wlc);
313 static void wlc_timers_deinit(struct wlc_info *wlc);
314 static void wlc_down_led_upd(struct wlc_info *wlc);
315 static uint wlc_down_del_timer(struct wlc_info *wlc);
316 static void wlc_ofdm_rateset_war(struct wlc_info *wlc);
317 static int _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
318 struct wlc_if *wlcif);
321 void wlc_get_rcmta(struct wlc_info *wlc, int idx, u8 *addr)
323 d11regs_t *regs = wlc->regs;
325 struct osl_info *osh;
327 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc), __func__);
329 ASSERT(wlc->pub->corerev > 4);
333 W_REG(osh, ®s->objaddr, (OBJADDR_RCMTA_SEL | (idx * 2)));
334 (void)R_REG(osh, ®s->objaddr);
335 v32 = R_REG(osh, ®s->objdata);
337 addr[1] = (u8) (v32 >> 8);
338 addr[2] = (u8) (v32 >> 16);
339 addr[3] = (u8) (v32 >> 24);
340 W_REG(osh, ®s->objaddr, (OBJADDR_RCMTA_SEL | ((idx * 2) + 1)));
341 (void)R_REG(osh, ®s->objaddr);
342 v32 = R_REG(osh, (volatile u16 *)®s->objdata);
344 addr[5] = (u8) (v32 >> 8);
346 #endif /* defined(BCMDBG) */
348 /* keep the chip awake if needed */
349 bool wlc_stay_awake(struct wlc_info *wlc)
354 /* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
356 bool wlc_ps_allowed(struct wlc_info *wlc)
361 /* disallow PS when one of the following global conditions meets */
362 if (!wlc->pub->associated || !wlc->PMenabled || wlc->PM_override)
365 /* disallow PS when one of these meets when not scanning */
366 if (!wlc->PMblocked) {
367 if (AP_ACTIVE(wlc) || wlc->monitor)
371 FOREACH_AS_STA(wlc, idx, cfg) {
372 /* disallow PS when one of the following bsscfg specific conditions meets */
373 if (!cfg->BSS || !WLC_PORTOPEN(cfg))
376 if (!cfg->dtim_programmed)
383 void wlc_reset(struct wlc_info *wlc)
385 WL_TRACE("wl%d: wlc_reset\n", wlc->pub->unit);
387 wlc->check_for_unaligned_tbtt = false;
389 /* slurp up hw mac counters before core reset */
392 /* reset our snapshot of macstat counters */
393 memset((char *)wlc->core->macstat_snapshot, 0,
396 wlc_bmac_reset(wlc->hw);
397 wlc_ampdu_reset(wlc->ampdu);
402 void wlc_fatal_error(struct wlc_info *wlc)
404 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc->pub->unit);
408 /* Return the channel the driver should initialize during wlc_init.
409 * the channel may have to be changed from the currently configured channel
410 * if other configurations are in conflict (bandlocked, 11n mode disabled,
411 * invalid channel for current country, etc.)
413 static chanspec_t wlc_init_chanspec(struct wlc_info *wlc)
415 chanspec_t chanspec =
416 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE |
419 /* make sure the channel is on the supported band if we are band-restricted */
420 if (wlc->bandlocked || NBANDS(wlc) == 1) {
421 ASSERT(CHSPEC_WLCBANDUNIT(chanspec) == wlc->band->bandunit);
423 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
427 struct scb global_scb;
429 static void wlc_init_scb(struct wlc_info *wlc, struct scb *scb)
432 scb->flags = SCB_WMECAP | SCB_HTCAP;
433 for (i = 0; i < NUMPRIO; i++)
437 void wlc_init(struct wlc_info *wlc)
442 wlc_bsscfg_t *bsscfg;
445 WL_TRACE("wl%d: wlc_init\n", wlc->pub->unit);
449 /* This will happen if a big-hammer was executed. In that case, we want to go back
450 * to the channel that we were on and not new channel
452 if (wlc->pub->associated)
453 chanspec = wlc->home_chanspec;
455 chanspec = wlc_init_chanspec(wlc);
457 wlc_bmac_init(wlc->hw, chanspec, mute);
459 wlc->seckeys = wlc_bmac_read_shm(wlc->hw, M_SECRXKEYS_PTR) * 2;
460 if (D11REV_GE(wlc->pub->corerev, 15) && (wlc->machwcap & MCAP_TKIPMIC))
462 wlc_bmac_read_shm(wlc->hw, M_TKMICKEYS_PTR) * 2;
464 /* update beacon listen interval */
467 (u8) (wlc_bmac_read_shm(wlc->hw, M_NOSLPZNATDTIM) >> 10);
468 ASSERT(wlc->bcn_wait_prd > 0);
470 /* the world is new again, so is our reported rate */
471 wlc_reprate_init(wlc);
473 /* write ethernet address to core */
474 FOREACH_BSS(wlc, i, bsscfg) {
476 wlc_set_bssid(bsscfg);
479 /* Update tsf_cfprep if associated and up */
480 if (wlc->pub->associated) {
481 FOREACH_BSS(wlc, i, bsscfg) {
485 /* get beacon period from bsscfg and convert to uS */
486 bi = bsscfg->current_bss->beacon_period << 10;
487 /* update the tsf_cfprep register */
488 /* since init path would reset to default value */
489 W_REG(wlc->osh, ®s->tsf_cfprep,
490 (bi << CFPREP_CBI_SHIFT));
492 /* Update maccontrol PM related bits */
493 wlc_set_ps_ctrl(wlc);
500 wlc_key_hw_init_all(wlc);
502 wlc_bandinit_ordered(wlc, chanspec);
504 wlc_init_scb(wlc, &global_scb);
506 /* init probe response timeout */
507 wlc_write_shm(wlc, M_PRS_MAXTIME, wlc->prb_resp_timeout);
509 /* init max burst txop (framebursting) */
510 wlc_write_shm(wlc, M_MBURST_TXOP,
512 _rifs ? (EDCF_AC_VO_TXOP_AP << 5) : MAXFRAMEBURST_TXOP));
514 /* initialize maximum allowed duty cycle */
515 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_ofdm, true, true);
516 wlc_duty_cycle_set(wlc, wlc->tx_duty_cycle_cck, false, true);
518 /* Update some shared memory locations related to max AMPDU size allowed to received */
519 wlc_ampdu_shm_upd(wlc->ampdu);
521 /* band-specific inits */
524 /* Enable EDCF mode (while the MAC is suspended) */
525 if (EDCF_ENAB(wlc->pub)) {
526 OR_REG(wlc->osh, ®s->ifs_ctl, IFS_USEEDCF);
527 wlc_edcf_setparams(wlc->cfg, false);
530 /* Init precedence maps for empty FIFOs */
531 wlc_tx_prec_map_init(wlc);
533 /* read the ucode version if we have not yet done so */
534 if (wlc->ucode_rev == 0) {
536 wlc_read_shm(wlc, M_BOM_REV_MAJOR) << NBITS(u16);
537 wlc->ucode_rev |= wlc_read_shm(wlc, M_BOM_REV_MINOR);
540 /* ..now really unleash hell (allow the MAC out of suspend) */
543 /* clear tx flow control */
544 wlc_txflowcontrol_reset(wlc);
546 /* clear tx data fifo suspends */
547 wlc->tx_suspended = false;
549 /* enable the RF Disable Delay timer */
550 if (D11REV_GE(wlc->pub->corerev, 10))
551 W_REG(wlc->osh, &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) { /* Unintialized; 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->osh, &wlc->regs->maccontrol);
619 /* If deviceremoved is detected, then don't take any action as this can be called
620 * in any context. Assume that caller will take care of the condition. This is just
623 if (tmp == 0xffffffff) {
624 WL_ERROR("wl%d: %s: dead chip\n",
625 wlc->pub->unit, __func__);
626 return DEVICEREMOVED(wlc);
629 hps = PS_ALLOWED(wlc);
631 if (hps != ((tmp & MCTL_HPS) != 0)) {
634 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
635 wlc->pub->unit, hps, tmp);
636 FOREACH_BSS(wlc, idx, cfg) {
637 if (!BSSCFG_STA(cfg))
643 /* For a monolithic build the wake check can be exact since it looks at wake
644 * override bits. The MCTL_WAKE bit should match the 'wake' value.
646 wake = STAY_AWAKE(wlc) || wlc->hw->wake_override;
647 wake_ok = (wake == ((tmp & MCTL_WAKE) != 0));
648 if (hps && !wake_ok) {
649 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
650 wlc->pub->unit, wake, tmp);
658 /* push sw hps and wake state through hardware */
659 void wlc_set_ps_ctrl(struct wlc_info *wlc)
665 hps = PS_ALLOWED(wlc);
666 wake = hps ? (STAY_AWAKE(wlc)) : true;
668 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
669 wlc->pub->unit, hps, wake);
671 v1 = R_REG(wlc->osh, &wlc->regs->maccontrol);
678 wlc_mctrl(wlc, MCTL_WAKE | MCTL_HPS, v2);
680 awake_before = ((v1 & MCTL_WAKE) || ((v1 & MCTL_HPS) == 0));
682 if (wake && !awake_before)
683 wlc_bmac_wait_for_wake(wlc->hw);
688 * Write this BSS config's MAC address to core.
689 * Updates RXE match engine.
691 int wlc_set_mac(wlc_bsscfg_t *cfg)
694 struct wlc_info *wlc = cfg->wlc;
696 if (cfg == wlc->cfg) {
697 /* enter the MAC addr into the RXE match registers */
698 wlc_set_addrmatch(wlc, RCM_MAC_OFFSET, cfg->cur_etheraddr);
701 wlc_ampdu_macaddr_upd(wlc);
706 /* Write the BSS config's BSSID address to core (set_bssid in d11procs.tcl).
707 * Updates RXE match engine.
709 void wlc_set_bssid(wlc_bsscfg_t *cfg)
711 struct wlc_info *wlc = cfg->wlc;
713 /* if primary config, we need to update BSSID in RXE match registers */
714 if (cfg == wlc->cfg) {
715 wlc_set_addrmatch(wlc, RCM_BSSID_OFFSET, cfg->BSSID);
717 #ifdef SUPPORT_HWKEYS
718 else if (BSSCFG_STA(cfg) && cfg->BSS) {
719 wlc_rcmta_add_bssid(wlc, cfg);
725 * Suspend the the MAC and update the slot timing
726 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
728 void wlc_switch_shortslot(struct wlc_info *wlc, bool shortslot)
733 ASSERT(wlc->band->gmode);
735 /* use the override if it is set */
736 if (wlc->shortslot_override != WLC_SHORTSLOT_AUTO)
737 shortslot = (wlc->shortslot_override == WLC_SHORTSLOT_ON);
739 if (wlc->shortslot == shortslot)
742 wlc->shortslot = shortslot;
744 /* update the capability based on current shortslot mode */
745 FOREACH_BSS(wlc, idx, cfg) {
746 if (!cfg->associated)
748 cfg->current_bss->capability &=
749 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
751 cfg->current_bss->capability |=
752 WLAN_CAPABILITY_SHORT_SLOT_TIME;
755 wlc_bmac_set_shortslot(wlc->hw, shortslot);
758 static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc)
763 local = WLC_TXPWR_MAX;
764 if (wlc->pub->associated &&
765 (wf_chspec_ctlchan(wlc->chanspec) ==
766 wf_chspec_ctlchan(wlc->home_chanspec))) {
768 /* get the local power constraint if we are on the AP's
769 * channel [802.11h, 7.3.2.13]
771 /* Clamp the value between 0 and WLC_TXPWR_MAX w/o overflowing the target */
773 (wlc->txpwr_local_max -
774 wlc->txpwr_local_constraint) * WLC_TXPWR_DB_FACTOR;
775 if (local_max > 0 && local_max < WLC_TXPWR_MAX)
776 return (u8) local_max;
784 /* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
785 void wlc_set_home_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
787 if (wlc->home_chanspec != chanspec) {
791 wlc->home_chanspec = chanspec;
793 FOREACH_BSS(wlc, idx, cfg) {
794 if (!cfg->associated)
796 cfg->target_bss->chanspec = chanspec;
797 cfg->current_bss->chanspec = chanspec;
803 static void wlc_set_phy_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
805 /* Save our copy of the chanspec */
806 wlc->chanspec = chanspec;
808 /* Set the chanspec and power limits for this locale after computing
809 * any 11h local tx power constraints.
811 wlc_channel_set_chanspec(wlc->cmi, chanspec,
812 wlc_local_constraint_qdbm(wlc));
814 if (wlc->stf->ss_algosel_auto)
815 wlc_stf_ss_algo_channel_get(wlc, &wlc->stf->ss_algo_channel,
818 wlc_stf_ss_update(wlc, wlc->band);
822 void wlc_set_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
825 bool switchband = false;
826 chanspec_t old_chanspec = wlc->chanspec;
828 if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) {
829 WL_ERROR("wl%d: %s: Bad channel %d\n",
830 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec));
831 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
835 /* Switch bands if necessary */
836 if (NBANDS(wlc) > 1) {
837 bandunit = CHSPEC_WLCBANDUNIT(chanspec);
838 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) {
840 if (wlc->bandlocked) {
841 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
842 wlc->pub->unit, __func__,
843 CHSPEC_CHANNEL(chanspec));
846 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
847 * if the setband updates (wlc_bsinit) use low level calls to inspect and
848 * set state, the state inspected may be from the wrong band, or the
849 * following wlc_bmac_set_chanspec() may undo the work.
851 wlc_setband(wlc, bandunit);
855 ASSERT(N_ENAB(wlc->pub) || !CHSPEC_IS40(chanspec));
857 /* sync up phy/radio chanspec */
858 wlc_set_phy_chanspec(wlc, chanspec);
860 /* init antenna selection */
861 if (CHSPEC_WLC_BW(old_chanspec) != CHSPEC_WLC_BW(chanspec)) {
862 if (WLANTSEL_ENAB(wlc))
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 bcopy(&power, pwr, 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 if (WLANTSEL_ENAB(wlc))
1310 wlc_antsel_init(wlc->asi);
1314 /* switch to and initialize new band */
1315 static void WLBANDINITFN(wlc_setband) (struct wlc_info *wlc, uint bandunit)
1320 ASSERT(NBANDS(wlc) > 1);
1321 ASSERT(!wlc->bandlocked);
1322 ASSERT(bandunit != wlc->band->bandunit || wlc->bandinit_pending);
1324 wlc->band = wlc->bandstate[bandunit];
1329 /* wait for at least one beacon before entering sleeping state */
1330 wlc->PMawakebcn = true;
1331 FOREACH_AS_STA(wlc, idx, cfg)
1332 cfg->PMawakebcn = true;
1333 wlc_set_ps_ctrl(wlc);
1335 /* band-specific initializations */
1339 /* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1340 void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe)
1342 static const wme_param_ie_t stadef = {
1345 WME_SUBTYPE_PARAM_IE,
1350 {EDCF_AC_BE_ACI_STA, EDCF_AC_BE_ECW_STA,
1351 HTOL16(EDCF_AC_BE_TXOP_STA)},
1352 {EDCF_AC_BK_ACI_STA, EDCF_AC_BK_ECW_STA,
1353 HTOL16(EDCF_AC_BK_TXOP_STA)},
1354 {EDCF_AC_VI_ACI_STA, EDCF_AC_VI_ECW_STA,
1355 HTOL16(EDCF_AC_VI_TXOP_STA)},
1356 {EDCF_AC_VO_ACI_STA, EDCF_AC_VO_ECW_STA,
1357 HTOL16(EDCF_AC_VO_TXOP_STA)}
1361 ASSERT(sizeof(*pe) == WME_PARAM_IE_LEN);
1362 memcpy(pe, &stadef, sizeof(*pe));
1365 void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg, bool suspend)
1368 shm_acparams_t acp_shm;
1370 struct ieee80211_tx_queue_params *params = arg;
1374 /* Only apply params if the core is out of reset and has clocks */
1376 WL_ERROR("wl%d: %s : no-clock\n", wlc->pub->unit, __func__);
1381 * AP uses AC params from wme_param_ie_ap.
1382 * AP advertises AC params from wme_param_ie.
1383 * STA uses AC params from wme_param_ie.
1386 wlc->wme_admctl = 0;
1389 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1390 /* find out which ac this set of params applies to */
1391 ASSERT(aci < AC_COUNT);
1392 /* set the admission control policy for this AC */
1393 /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */
1395 /* fill in shm ac params struct */
1396 acp_shm.txop = ltoh16(params->txop);
1397 /* convert from units of 32us to us for ucode */
1398 wlc->edcf_txop[aci & 0x3] = acp_shm.txop =
1399 EDCF_TXOP2USEC(acp_shm.txop);
1400 acp_shm.aifs = (params->aifs & EDCF_AIFSN_MASK);
1402 if (aci == AC_VI && acp_shm.txop == 0
1403 && acp_shm.aifs < EDCF_AIFSN_MAX)
1406 if (acp_shm.aifs < EDCF_AIFSN_MIN
1407 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1408 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1409 wlc->pub->unit, acp_shm.aifs);
1413 acp_shm.cwmin = params->cw_min;
1414 acp_shm.cwmax = params->cw_max;
1415 acp_shm.cwcur = acp_shm.cwmin;
1417 R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur;
1418 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1419 /* Indicate the new params to the ucode */
1420 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1421 wme_shmemacindex(aci) *
1423 M_EDCF_STATUS_OFF));
1424 acp_shm.status |= WME_STATUS_NEWAC;
1426 /* Fill in shm acparam table */
1427 shm_entry = (u16 *) &acp_shm;
1428 for (i = 0; i < (int)sizeof(shm_acparams_t); i += 2)
1431 wme_shmemacindex(aci) * M_EDCF_QLEN + i,
1437 wlc_suspend_mac_and_wait(wlc);
1440 wlc_enable_mac(wlc);
1444 void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1446 struct wlc_info *wlc = cfg->wlc;
1448 edcf_acparam_t *edcf_acp;
1449 shm_acparams_t acp_shm;
1455 /* Only apply params if the core is out of reset and has clocks */
1460 * AP uses AC params from wme_param_ie_ap.
1461 * AP advertises AC params from wme_param_ie.
1462 * STA uses AC params from wme_param_ie.
1465 edcf_acp = (edcf_acparam_t *) &wlc->wme_param_ie.acparam[0];
1467 wlc->wme_admctl = 0;
1469 for (i = 0; i < AC_COUNT; i++, edcf_acp++) {
1470 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1471 /* find out which ac this set of params applies to */
1472 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
1473 ASSERT(aci < AC_COUNT);
1474 /* set the admission control policy for this AC */
1475 if (edcf_acp->ACI & EDCF_ACM_MASK) {
1476 wlc->wme_admctl |= 1 << aci;
1479 /* fill in shm ac params struct */
1480 acp_shm.txop = ltoh16(edcf_acp->TXOP);
1481 /* convert from units of 32us to us for ucode */
1482 wlc->edcf_txop[aci] = acp_shm.txop =
1483 EDCF_TXOP2USEC(acp_shm.txop);
1484 acp_shm.aifs = (edcf_acp->ACI & EDCF_AIFSN_MASK);
1486 if (aci == AC_VI && acp_shm.txop == 0
1487 && acp_shm.aifs < EDCF_AIFSN_MAX)
1490 if (acp_shm.aifs < EDCF_AIFSN_MIN
1491 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1492 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1493 wlc->pub->unit, acp_shm.aifs);
1497 /* CWmin = 2^(ECWmin) - 1 */
1498 acp_shm.cwmin = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK);
1499 /* CWmax = 2^(ECWmax) - 1 */
1500 acp_shm.cwmax = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK)
1501 >> EDCF_ECWMAX_SHIFT);
1502 acp_shm.cwcur = acp_shm.cwmin;
1504 R_REG(wlc->osh, &wlc->regs->tsf_random) & acp_shm.cwcur;
1505 acp_shm.reggap = acp_shm.bslots + acp_shm.aifs;
1506 /* Indicate the new params to the ucode */
1507 acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO +
1508 wme_shmemacindex(aci) *
1510 M_EDCF_STATUS_OFF));
1511 acp_shm.status |= WME_STATUS_NEWAC;
1513 /* Fill in shm acparam table */
1514 shm_entry = (u16 *) &acp_shm;
1515 for (j = 0; j < (int)sizeof(shm_acparams_t); j += 2)
1518 wme_shmemacindex(aci) * M_EDCF_QLEN + j,
1523 wlc_suspend_mac_and_wait(wlc);
1525 if (AP_ENAB(wlc->pub) && WME_ENAB(wlc->pub)) {
1526 wlc_update_beacon(wlc);
1527 wlc_update_probe_resp(wlc, false);
1531 wlc_enable_mac(wlc);
1535 bool wlc_timers_init(struct wlc_info *wlc, int unit)
1537 wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer,
1539 if (!wlc->wdtimer) {
1540 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit);
1544 wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer,
1546 if (!wlc->radio_timer) {
1547 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit);
1558 * Initialize wlc_info default values ...
1559 * may get overrides later in this function
1561 void wlc_info_init(struct wlc_info *wlc, int unit)
1564 /* Assume the device is there until proven otherwise */
1565 wlc->device_present = true;
1567 /* set default power output percentage to 100 percent */
1568 wlc->txpwr_percent = 100;
1570 /* Save our copy of the chanspec */
1571 wlc->chanspec = CH20MHZ_CHSPEC(1);
1573 /* initialize CCK preamble mode to unassociated state */
1574 wlc->shortpreamble = false;
1576 wlc->legacy_probe = true;
1578 /* various 802.11g modes */
1579 wlc->shortslot = false;
1580 wlc->shortslot_override = WLC_SHORTSLOT_AUTO;
1582 wlc->barker_overlap_control = true;
1583 wlc->barker_preamble = WLC_BARKER_SHORT_ALLOWED;
1584 wlc->txburst_limit_override = AUTO;
1586 wlc_protection_upd(wlc, WLC_PROT_G_OVR, WLC_PROTECTION_AUTO);
1587 wlc_protection_upd(wlc, WLC_PROT_G_SPEC, false);
1589 wlc_protection_upd(wlc, WLC_PROT_N_CFG_OVR, WLC_PROTECTION_AUTO);
1590 wlc_protection_upd(wlc, WLC_PROT_N_CFG, WLC_N_PROTECTION_OFF);
1591 wlc_protection_upd(wlc, WLC_PROT_N_NONGF_OVR, WLC_PROTECTION_AUTO);
1592 wlc_protection_upd(wlc, WLC_PROT_N_NONGF, false);
1593 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR, AUTO);
1595 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, WLC_PROTECTION_CTL_OVERLAP);
1597 /* 802.11g draft 4.0 NonERP elt advertisement */
1598 wlc->include_legacy_erp = true;
1600 wlc->stf->ant_rx_ovr = ANT_RX_DIV_DEF;
1601 wlc->stf->txant = ANT_TX_DEF;
1603 wlc->prb_resp_timeout = WLC_PRB_RESP_TIMEOUT;
1605 wlc->usr_fragthresh = DOT11_DEFAULT_FRAG_LEN;
1606 for (i = 0; i < NFIFO; i++)
1607 wlc->fragthresh[i] = DOT11_DEFAULT_FRAG_LEN;
1608 wlc->RTSThresh = DOT11_DEFAULT_RTS_LEN;
1610 /* default rate fallback retry limits */
1611 wlc->SFBL = RETRY_SHORT_FB;
1612 wlc->LFBL = RETRY_LONG_FB;
1614 /* default mac retry limits */
1615 wlc->SRL = RETRY_SHORT_DEF;
1616 wlc->LRL = RETRY_LONG_DEF;
1619 wlc->PM = PM_OFF; /* User's setting of PM mode through IOCTL */
1620 wlc->PM_override = false; /* Prevents from going to PM if our AP is 'ill' */
1621 wlc->PMenabled = false; /* Current PM state */
1622 wlc->PMpending = false; /* Tracks whether STA indicated PM in the last attempt */
1623 wlc->PMblocked = false; /* To allow blocking going into PM during RM and scans */
1625 /* In WMM Auto mode, PM is allowed if association is a UAPSD association */
1626 wlc->WME_PM_blocked = false;
1628 /* Init wme queuing method */
1629 wlc->wme_prec_queuing = false;
1631 /* Overrides for the core to stay awake under zillion conditions Look for STAY_AWAKE */
1633 /* Are we waiting for a response to PS-Poll that we sent */
1634 wlc->PSpoll = false;
1637 wlc->wme_apsd = true;
1638 wlc->apsd_sta_usp = false;
1639 wlc->apsd_trigger_timeout = 0; /* disable the trigger timer */
1640 wlc->apsd_trigger_ac = AC_BITMAP_ALL;
1642 /* Set flag to indicate that hw keys should be used when available. */
1643 wlc->wsec_swkeys = false;
1645 /* init the 4 static WEP default keys */
1646 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
1647 wlc->wsec_keys[i] = wlc->wsec_def_keys[i];
1648 wlc->wsec_keys[i]->idx = (u8) i;
1651 wlc->_regulatory_domain = false; /* 802.11d */
1653 /* WME QoS mode is Auto by default */
1654 wlc->pub->_wme = AUTO;
1656 #ifdef BCMSDIODEV_ENABLED
1657 wlc->pub->_priofc = true; /* enable priority flow control for sdio dongle */
1660 wlc->pub->_ampdu = AMPDU_AGG_HOST;
1661 wlc->pub->bcmerror = 0;
1662 wlc->ibss_allowed = true;
1663 wlc->ibss_coalesce_allowed = true;
1664 wlc->pub->_coex = ON;
1666 /* intialize mpc delay */
1667 wlc->mpc_delay_off = wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
1669 wlc->pr80838_war = true;
1672 static bool wlc_state_bmac_sync(struct wlc_info *wlc)
1674 wlc_bmac_state_t state_bmac;
1676 if (wlc_bmac_state_get(wlc->hw, &state_bmac) != 0)
1679 wlc->machwcap = state_bmac.machwcap;
1680 wlc_protection_upd(wlc, WLC_PROT_N_PAM_OVR,
1681 (s8) state_bmac.preamble_ovr);
1686 static uint wlc_attach_module(struct wlc_info *wlc)
1690 unit = wlc->pub->unit;
1692 wlc->asi = wlc_antsel_attach(wlc, wlc->osh, wlc->pub, wlc->hw);
1693 if (wlc->asi == NULL) {
1694 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit);
1699 wlc->ampdu = wlc_ampdu_attach(wlc);
1700 if (wlc->ampdu == NULL) {
1701 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit);
1706 /* Initialize event queue; needed before following calls */
1708 wlc_eventq_attach(wlc->pub, wlc, wlc->wl, wlc_process_eventq);
1709 if (wlc->eventq == NULL) {
1710 WL_ERROR("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit);
1715 if ((wlc_stf_attach(wlc) != 0)) {
1716 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit);
1724 struct wlc_pub *wlc_pub(void *wlc)
1726 return ((struct wlc_info *) wlc)->pub;
1729 #define CHIP_SUPPORTS_11N(wlc) 1
1732 * The common driver entry routine. Error codes should be unique
1734 void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1735 struct osl_info *osh, void *regsva, uint bustype,
1736 void *btparam, uint *perr)
1738 struct wlc_info *wlc;
1741 struct wlc_pub *pub;
1745 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1746 unit, __func__, vendor, device);
1748 ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS);
1749 ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS);
1751 /* some code depends on packed structures */
1752 ASSERT(sizeof(struct ethhdr) == ETH_HLEN);
1753 ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE);
1754 ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN);
1755 ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN);
1756 ASSERT(sizeof(d11txh_t) == D11_TXH_LEN);
1757 ASSERT(sizeof(d11rxhdr_t) == RXHDR_LEN);
1758 ASSERT(sizeof(struct ieee80211_hdr) == DOT11_A4_HDR_LEN);
1759 ASSERT(sizeof(struct ieee80211_rts) == DOT11_RTS_LEN);
1760 ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN);
1761 ASSERT(sizeof(struct ieee80211_ht_cap) == HT_CAP_IE_LEN);
1763 ASSERT(offsetof(wl_scan_params_t, channel_list) ==
1764 WL_SCAN_PARAMS_FIXED_SIZE);
1766 ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32)));
1767 ASSERT(ISPOWEROF2(MA_WINDOW_SZ));
1769 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
1772 * Number of replay counters value used in WPA IE must match # rxivs
1773 * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17
1774 * 'RSN Information Element' figure 8 for this mapping.
1776 ASSERT((WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1777 && 16 == WLC_NUMRXIVS)
1778 || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1779 && 4 == WLC_NUMRXIVS));
1781 /* allocate struct wlc_info state and its substructures */
1782 wlc = (struct wlc_info *) wlc_attach_malloc(osh, unit, &err, device);
1792 wlc->band = wlc->bandstate[0];
1793 wlc->core = wlc->corestate;
1797 wlc->btparam = btparam;
1798 pub->_piomode = piomode;
1799 wlc->bandinit_pending = false;
1800 /* By default restrict TKIP associations from 11n STA's */
1801 wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT;
1803 /* populate struct wlc_info with default values */
1804 wlc_info_init(wlc, unit);
1806 /* update sta/ap related parameters */
1809 /* 11n_disable nvram */
1810 n_disabled = getintvar(pub->vars, "11n_disable");
1812 /* register a module (to handle iovars) */
1813 wlc_module_register(wlc->pub, wlc_iovars, "wlc_iovars", wlc,
1814 wlc_doiovar, NULL, NULL);
1816 /* low level attach steps(all hw accesses go inside, no more in rest of the attach) */
1817 err = wlc_bmac_attach(wlc, vendor, device, unit, piomode, osh, regsva,
1822 /* for some states, due to different info pointer(e,g, wlc, wlc_hw) or master/slave split,
1823 * HIGH driver(both monolithic and HIGH_ONLY) needs to sync states FROM BMAC portion driver
1825 if (!wlc_state_bmac_sync(wlc)) {
1830 pub->phy_11ncapable = WLC_PHY_11N_CAP(wlc->band);
1832 /* propagate *vars* from BMAC driver to high driver */
1833 wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size);
1836 /* set maximum allowed duty cycle */
1837 wlc->tx_duty_cycle_ofdm =
1838 (u16) getintvar(pub->vars, "tx_duty_cycle_ofdm");
1839 wlc->tx_duty_cycle_cck =
1840 (u16) getintvar(pub->vars, "tx_duty_cycle_cck");
1842 wlc_stf_phy_chain_calc(wlc);
1844 /* txchain 1: txant 0, txchain 2: txant 1 */
1845 if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1))
1846 wlc->stf->txant = wlc->stf->hw_txchain - 1;
1848 /* push to BMAC driver */
1849 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain,
1850 wlc->stf->hw_rxchain);
1852 /* pull up some info resulting from the low attach */
1855 for (i = 0; i < NFIFO; i++)
1856 wlc->core->txavail[i] = wlc->hw->txavail[i];
1859 wlc_bmac_hw_etheraddr(wlc->hw, wlc->perm_etheraddr);
1861 bcopy((char *)&wlc->perm_etheraddr, (char *)&pub->cur_etheraddr,
1864 for (j = 0; j < NBANDS(wlc); j++) {
1865 /* Use band 1 for single band 11a */
1866 if (IS_SINGLEBAND_5G(wlc->deviceid))
1869 wlc->band = wlc->bandstate[j];
1871 if (!wlc_attach_stf_ant_init(wlc)) {
1876 /* default contention windows size limits */
1877 wlc->band->CWmin = APHY_CWMIN;
1878 wlc->band->CWmax = PHY_CWMAX;
1880 /* init gmode value */
1881 if (BAND_2G(wlc->band->bandtype)) {
1882 wlc->band->gmode = GMODE_AUTO;
1883 wlc_protection_upd(wlc, WLC_PROT_G_USER,
1887 /* init _n_enab supported mode */
1888 if (WLC_PHY_11N_CAP(wlc->band) && CHIP_SUPPORTS_11N(wlc)) {
1889 if (n_disabled & WLFEATURE_DISABLE_11N) {
1891 wlc_protection_upd(wlc, WLC_PROT_N_USER, OFF);
1893 pub->_n_enab = SUPPORT_11N;
1894 wlc_protection_upd(wlc, WLC_PROT_N_USER,
1896 SUPPORT_11N) ? WL_11N_2x2 :
1901 /* init per-band default rateset, depend on band->gmode */
1902 wlc_default_rateset(wlc, &wlc->band->defrateset);
1904 /* fill in hw_rateset (used early by WLC_SET_RATESET) */
1905 wlc_rateset_filter(&wlc->band->defrateset,
1906 &wlc->band->hw_rateset, false,
1907 WLC_RATES_CCK_OFDM, RATE_MASK,
1908 (bool) N_ENAB(wlc->pub));
1911 /* update antenna config due to wlc->stf->txant/txchain/ant_rx_ovr change */
1912 wlc_stf_phy_txant_upd(wlc);
1914 /* attach each modules */
1915 err = wlc_attach_module(wlc);
1919 if (!wlc_timers_init(wlc, unit)) {
1920 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit, __func__);
1925 /* depend on rateset, gmode */
1926 wlc->cmi = wlc_channel_mgr_attach(wlc);
1928 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1934 /* init default when all parameters are ready, i.e. ->rateset */
1935 wlc_bss_default_init(wlc);
1938 * Complete the wlc default state initializations..
1941 /* allocate our initial queue */
1942 qi = wlc_txq_alloc(wlc, osh);
1944 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1949 wlc->active_queue = qi;
1951 wlc->bsscfg[0] = wlc->cfg;
1953 wlc->cfg->wlc = wlc;
1954 pub->txmaxpkts = MAXTXPKTS;
1956 pub->_cnt->version = WL_CNT_T_VERSION;
1957 pub->_cnt->length = sizeof(struct wl_cnt);
1959 WLCNTSET(pub->_wme_cnt->version, WL_WME_CNT_VERSION);
1960 WLCNTSET(pub->_wme_cnt->length, sizeof(wl_wme_cnt_t));
1962 wlc_wme_initparams_sta(wlc, &wlc->wme_param_ie);
1964 wlc->mimoft = FT_HT;
1965 wlc->ht_cap.cap_info = HT_CAP;
1966 if (HT_ENAB(wlc->pub))
1967 wlc->stf->ldpc = AUTO;
1969 wlc->mimo_40txbw = AUTO;
1970 wlc->ofdm_40txbw = AUTO;
1971 wlc->cck_40txbw = AUTO;
1972 wlc_update_mimo_band_bwcap(wlc, WLC_N_BW_20IN2G_40IN5G);
1974 /* Enable setting the RIFS Mode bit by default in HT Info IE */
1975 wlc->rifs_advert = AUTO;
1977 /* Set default values of SGI */
1978 if (WLC_SGI_CAP_PHY(wlc)) {
1979 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1981 } else if (WLCISSSLPNPHY(wlc->band)) {
1982 wlc_ht_update_sgi_rx(wlc, (WLC_N_SGI_20 | WLC_N_SGI_40));
1985 wlc_ht_update_sgi_rx(wlc, 0);
1989 /* *******nvram 11n config overrides Start ********* */
1991 /* apply the sgi override from nvram conf */
1992 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_TX)
1995 if (n_disabled & WLFEATURE_DISABLE_11N_SGI_RX)
1996 wlc_ht_update_sgi_rx(wlc, 0);
1998 /* apply the stbc override from nvram conf */
1999 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_TX) {
2000 wlc->bandstate[BAND_2G_INDEX]->band_stf_stbc_tx = OFF;
2001 wlc->bandstate[BAND_5G_INDEX]->band_stf_stbc_tx = OFF;
2002 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_TX_STBC;
2004 if (n_disabled & WLFEATURE_DISABLE_11N_STBC_RX)
2005 wlc_stf_stbc_rx_set(wlc, HT_CAP_RX_STBC_NO);
2007 /* apply the GF override from nvram conf */
2008 if (n_disabled & WLFEATURE_DISABLE_11N_GF)
2009 wlc->ht_cap.cap_info &= ~IEEE80211_HT_CAP_GRN_FLD;
2011 /* initialize radio_mpc_disable according to wlc->mpc */
2012 wlc_radio_mpc_upd(wlc);
2014 if (WLANTSEL_ENAB(wlc)) {
2015 if ((wlc->pub->sih->chip) == BCM43235_CHIP_ID) {
2016 if ((getintvar(wlc->pub->vars, "aa2g") == 7) ||
2017 (getintvar(wlc->pub->vars, "aa5g") == 7)) {
2018 wlc_bmac_antsel_set(wlc->hw, 1);
2021 wlc_bmac_antsel_set(wlc->hw, wlc->asi->antsel_avail);
2031 WL_ERROR("wl%d: %s: failed with err %d\n", unit, __func__, err);
2040 static void wlc_attach_antgain_init(struct wlc_info *wlc)
2043 unit = wlc->pub->unit;
2045 if ((wlc->band->antgain == -1) && (wlc->pub->sromrev == 1)) {
2046 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2047 wlc->band->antgain = 8;
2048 } else if (wlc->band->antgain == -1) {
2049 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2051 wlc->band->antgain = 8;
2054 /* Older sroms specified gain in whole dbm only. In order
2055 * be able to specify qdbm granularity and remain backward compatible
2056 * the whole dbms are now encoded in only low 6 bits and remaining qdbms
2057 * are encoded in the hi 2 bits. 6 bit signed number ranges from
2058 * -32 - 31. Examples: 0x1 = 1 db,
2059 * 0xc1 = 1.75 db (1 + 3 quarters),
2060 * 0x3f = -1 (-1 + 0 quarters),
2061 * 0x7f = -.75 (-1 in low 6 bits + 1 quarters in hi 2 bits) = -3 qdbm.
2062 * 0xbf = -.50 (-1 in low 6 bits + 2 quarters in hi 2 bits) = -2 qdbm.
2064 gain = wlc->band->antgain & 0x3f;
2065 gain <<= 2; /* Sign extend */
2067 fract = (wlc->band->antgain & 0xc0) >> 6;
2068 wlc->band->antgain = 4 * gain + fract;
2072 static bool wlc_attach_stf_ant_init(struct wlc_info *wlc)
2079 unit = wlc->pub->unit;
2080 vars = wlc->pub->vars;
2081 bandtype = wlc->band->bandtype;
2083 /* get antennas available */
2084 aa = (s8) getintvar(vars, (BAND_5G(bandtype) ? "aa5g" : "aa2g"));
2086 aa = (s8) getintvar(vars,
2087 (BAND_5G(bandtype) ? "aa1" : "aa0"));
2088 if ((aa < 1) || (aa > 15)) {
2089 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2090 unit, __func__, aa);
2094 /* reset the defaults if we have a single antenna */
2096 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_0;
2097 wlc->stf->txant = ANT_TX_FORCE_0;
2098 } else if (aa == 2) {
2099 wlc->stf->ant_rx_ovr = ANT_RX_DIV_FORCE_1;
2100 wlc->stf->txant = ANT_TX_FORCE_1;
2104 /* Compute Antenna Gain */
2105 wlc->band->antgain =
2106 (s8) getintvar(vars, (BAND_5G(bandtype) ? "ag1" : "ag0"));
2107 wlc_attach_antgain_init(wlc);
2113 static void wlc_timers_deinit(struct wlc_info *wlc)
2115 /* free timer state */
2117 wl_free_timer(wlc->wl, wlc->wdtimer);
2118 wlc->wdtimer = NULL;
2120 if (wlc->radio_timer) {
2121 wl_free_timer(wlc->wl, wlc->radio_timer);
2122 wlc->radio_timer = NULL;
2126 static void wlc_detach_module(struct wlc_info *wlc)
2129 wlc_antsel_detach(wlc->asi);
2134 wlc_ampdu_detach(wlc->ampdu);
2138 wlc_stf_detach(wlc);
2142 * Return a count of the number of driver callbacks still pending.
2144 * General policy is that wlc_detach can only dealloc/free software states. It can NOT
2145 * touch hardware registers since the d11core may be in reset and clock may not be available.
2146 * One exception is sb register access, which is possible if crystal is turned on
2147 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2149 uint wlc_detach(struct wlc_info *wlc)
2157 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
2159 ASSERT(!wlc->pub->up);
2161 callbacks += wlc_bmac_detach(wlc);
2163 /* delete software timers */
2164 if (!wlc_radio_monitor_stop(wlc))
2168 wlc_eventq_detach(wlc->eventq);
2172 wlc_channel_mgr_detach(wlc->cmi);
2174 wlc_timers_deinit(wlc);
2176 wlc_detach_module(wlc);
2178 /* free other state */
2182 if (wlc->country_ie_override) {
2183 kfree(wlc->country_ie_override);
2184 wlc->country_ie_override = NULL;
2189 /* free dumpcb list */
2190 dumpcb_t *prev, *ptr;
2191 prev = ptr = wlc->dumpcb_head;
2197 wlc->dumpcb_head = NULL;
2200 /* Detach from iovar manager */
2201 wlc_module_unregister(wlc->pub, "wlc_iovars", wlc);
2203 while (wlc->tx_queues != NULL) {
2204 wlc_txq_free(wlc, wlc->osh, wlc->tx_queues);
2208 * consistency check: wlc_module_register/wlc_module_unregister calls
2209 * should match therefore nothing should be left here.
2211 for (i = 0; i < WLC_MAXMODULES; i++)
2212 ASSERT(wlc->modulecb[i].name[0] == '\0');
2214 wlc_detach_mfree(wlc, wlc->osh);
2218 /* update state that depends on the current value of "ap" */
2219 void wlc_ap_upd(struct wlc_info *wlc)
2221 if (AP_ENAB(wlc->pub))
2222 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */
2224 wlc->PLCPHdr_override = WLC_PLCP_SHORT; /* STA-BSS; short capable */
2226 /* disable vlan_mode on AP since some legacy STAs cannot rx tagged pkts */
2227 wlc->vlan_mode = AP_ENAB(wlc->pub) ? OFF : AUTO;
2233 /* read hwdisable state and propagate to wlc flag */
2234 static void wlc_radio_hwdisable_upd(struct wlc_info *wlc)
2236 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off)
2239 if (wlc_bmac_radio_read_hwdisabled(wlc->hw)) {
2240 mboolset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2242 mboolclr(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE);
2246 /* return true if Minimum Power Consumption should be entered, false otherwise */
2247 bool wlc_is_non_delay_mpc(struct wlc_info *wlc)
2252 bool wlc_ismpc(struct wlc_info *wlc)
2254 return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc));
2257 void wlc_radio_mpc_upd(struct wlc_info *wlc)
2259 bool mpc_radio, radio_state;
2262 * Clear the WL_RADIO_MPC_DISABLE bit when mpc feature is disabled
2263 * in case the WL_RADIO_MPC_DISABLE bit was set. Stop the radio
2264 * monitor also when WL_RADIO_MPC_DISABLE is the only reason that
2265 * the radio is going down.
2268 if (!wlc->pub->radio_disabled)
2270 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2272 if (!wlc->pub->radio_disabled)
2273 wlc_radio_monitor_stop(wlc);
2278 * sync ismpc logic with WL_RADIO_MPC_DISABLE bit in wlc->pub->radio_disabled
2279 * to go ON, always call radio_upd synchronously
2280 * to go OFF, postpone radio_upd to later when context is safe(e.g. watchdog)
2283 (mboolisset(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE) ? OFF :
2285 mpc_radio = (wlc_ismpc(wlc) == true) ? OFF : ON;
2287 if (radio_state == ON && mpc_radio == OFF)
2288 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2289 else if (radio_state == OFF && mpc_radio == ON) {
2290 mboolclr(wlc->pub->radio_disabled, WL_RADIO_MPC_DISABLE);
2292 if (wlc->mpc_offcnt < WLC_MPC_THRESHOLD) {
2293 wlc->mpc_dlycnt = WLC_MPC_MAX_DELAYCNT;
2295 wlc->mpc_dlycnt = WLC_MPC_MIN_DELAYCNT;
2296 wlc->mpc_dur += OSL_SYSUPTIME() - wlc->mpc_laston_ts;
2298 /* Below logic is meant to capture the transition from mpc off to mpc on for reasons
2299 * other than wlc->mpc_delay_off keeping the mpc off. In that case reset
2300 * wlc->mpc_delay_off to wlc->mpc_dlycnt, so that we restart the countdown of mpc_delay_off
2302 if ((wlc->prev_non_delay_mpc == false) &&
2303 (wlc_is_non_delay_mpc(wlc) == true) && wlc->mpc_delay_off) {
2304 wlc->mpc_delay_off = wlc->mpc_dlycnt;
2306 wlc->prev_non_delay_mpc = wlc_is_non_delay_mpc(wlc);
2310 * centralized radio disable/enable function,
2311 * invoke radio enable/disable after updating hwradio status
2313 static void wlc_radio_upd(struct wlc_info *wlc)
2315 if (wlc->pub->radio_disabled) {
2316 wlc_radio_disable(wlc);
2318 wlc_radio_enable(wlc);
2322 /* maintain LED behavior in down state */
2323 static void wlc_down_led_upd(struct wlc_info *wlc)
2325 ASSERT(!wlc->pub->up);
2327 /* maintain LEDs while in down state, turn on sbclk if not available yet */
2328 /* turn on sbclk if necessary */
2329 if (!AP_ENAB(wlc->pub)) {
2330 wlc_pllreq(wlc, true, WLC_PLLREQ_FLIP);
2332 wlc_pllreq(wlc, false, WLC_PLLREQ_FLIP);
2336 /* update hwradio status and return it */
2337 bool wlc_check_radio_disabled(struct wlc_info *wlc)
2339 wlc_radio_hwdisable_upd(wlc);
2341 return mboolisset(wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE) ? true : false;
2344 void wlc_radio_disable(struct wlc_info *wlc)
2346 if (!wlc->pub->up) {
2347 wlc_down_led_upd(wlc);
2351 wlc_radio_monitor_start(wlc);
2355 static void wlc_radio_enable(struct wlc_info *wlc)
2360 if (DEVICEREMOVED(wlc))
2363 if (!wlc->down_override) { /* imposed by wl down/out ioctl */
2368 /* periodical query hw radio button while driver is "down" */
2369 static void wlc_radio_timer(void *arg)
2371 struct wlc_info *wlc = (struct wlc_info *) arg;
2373 if (DEVICEREMOVED(wlc)) {
2374 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2379 /* cap mpc off count */
2380 if (wlc->mpc_offcnt < WLC_MPC_MAX_DELAYCNT)
2383 /* validate all the reasons driver could be down and running this radio_timer */
2384 ASSERT(wlc->pub->radio_disabled || wlc->down_override);
2385 wlc_radio_hwdisable_upd(wlc);
2389 static bool wlc_radio_monitor_start(struct wlc_info *wlc)
2391 /* Don't start the timer if HWRADIO feature is disabled */
2392 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
2395 wlc->radio_monitor = true;
2396 wlc_pllreq(wlc, true, WLC_PLLREQ_RADIO_MON);
2397 wl_add_timer(wlc->wl, wlc->radio_timer, TIMER_INTERVAL_RADIOCHK, true);
2401 bool wlc_radio_monitor_stop(struct wlc_info *wlc)
2403 if (!wlc->radio_monitor)
2406 ASSERT((wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO) !=
2409 wlc->radio_monitor = false;
2410 wlc_pllreq(wlc, false, WLC_PLLREQ_RADIO_MON);
2411 return wl_del_timer(wlc->wl, wlc->radio_timer);
2414 /* bring the driver down, but don't reset hardware */
2415 void wlc_out(struct wlc_info *wlc)
2417 wlc_bmac_set_noreset(wlc->hw, true);
2420 wlc_bmac_set_noreset(wlc->hw, false);
2422 /* core clk is true in BMAC driver due to noreset, need to mirror it in HIGH */
2425 /* This will make sure that when 'up' is done
2426 * after 'out' it'll restore hardware (especially gpios)
2428 wlc->pub->hw_up = false;
2432 /* Verify the sanity of wlc->tx_prec_map. This can be done only by making sure that
2433 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2434 * in prec_map. Of course, ignore this rule when block_datafifo is set
2436 static bool wlc_tx_prec_map_verify(struct wlc_info *wlc)
2438 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2441 if (!EDCF_ENAB(wlc->pub)) {
2442 if (!(WLC_TX_FIFO_CHECK(wlc, TX_DATA_FIFO) ||
2443 WLC_TX_FIFO_CHECK(wlc, TX_CTL_FIFO)))
2449 return WLC_TX_FIFO_CHECK(wlc, TX_AC_BK_FIFO)
2450 && WLC_TX_FIFO_CHECK(wlc, TX_AC_BE_FIFO)
2451 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VI_FIFO)
2452 && WLC_TX_FIFO_CHECK(wlc, TX_AC_VO_FIFO);
2456 static void wlc_watchdog_by_timer(void *arg)
2458 struct wlc_info *wlc = (struct wlc_info *) arg;
2460 if (WLC_WATCHDOG_TBTT(wlc)) {
2461 /* set to normal osl watchdog period */
2462 wl_del_timer(wlc->wl, wlc->wdtimer);
2463 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG,
2468 /* common watchdog code */
2469 static void wlc_watchdog(void *arg)
2471 struct wlc_info *wlc = (struct wlc_info *) arg;
2475 WL_TRACE("wl%d: wlc_watchdog\n", wlc->pub->unit);
2480 if (DEVICEREMOVED(wlc)) {
2481 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2486 /* increment second count */
2489 /* delay radio disable */
2490 if (wlc->mpc_delay_off) {
2491 if (--wlc->mpc_delay_off == 0) {
2492 mboolset(wlc->pub->radio_disabled,
2493 WL_RADIO_MPC_DISABLE);
2494 if (wlc->mpc && wlc_ismpc(wlc))
2495 wlc->mpc_offcnt = 0;
2496 wlc->mpc_laston_ts = OSL_SYSUPTIME();
2501 wlc_radio_mpc_upd(wlc);
2502 /* radio sync: sw/hw/mpc --> radio_disable/radio_enable */
2503 wlc_radio_hwdisable_upd(wlc);
2505 /* if ismpc, driver should be in down state if up/down is allowed */
2506 if (wlc->mpc && wlc_ismpc(wlc))
2507 ASSERT(!wlc->pub->up);
2508 /* if radio is disable, driver may be down, quit here */
2509 if (wlc->pub->radio_disabled)
2512 wlc_bmac_watchdog(wlc);
2514 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2515 if ((wlc->pub->now % SW_TIMER_MAC_STAT_UPD) == 0)
2518 /* Manage TKIP countermeasures timers */
2519 FOREACH_BSS(wlc, i, cfg) {
2520 if (cfg->tk_cm_dt) {
2523 if (cfg->tk_cm_bt) {
2528 /* Call any registered watchdog handlers */
2529 for (i = 0; i < WLC_MAXMODULES; i++) {
2530 if (wlc->modulecb[i].watchdog_fn)
2531 wlc->modulecb[i].watchdog_fn(wlc->modulecb[i].hdl);
2534 if (WLCISNPHY(wlc->band) && !wlc->pub->tempsense_disable &&
2535 ((wlc->pub->now - wlc->tempsense_lasttime) >=
2536 WLC_TEMPSENSE_PERIOD)) {
2537 wlc->tempsense_lasttime = wlc->pub->now;
2538 wlc_tempsense_upd(wlc);
2540 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2541 ASSERT(wlc_bmac_taclear(wlc->hw, true));
2543 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2544 ASSERT(wlc_tx_prec_map_verify(wlc));
2546 ASSERT(wlc_ps_check(wlc));
2549 /* make interface operational */
2550 int wlc_up(struct wlc_info *wlc)
2552 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2554 /* HW is turned off so don't try to access it */
2555 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
2556 return BCME_RADIOOFF;
2558 if (!wlc->pub->hw_up) {
2559 wlc_bmac_hw_up(wlc->hw);
2560 wlc->pub->hw_up = true;
2563 if ((wlc->pub->boardflags & BFL_FEM)
2564 && (wlc->pub->sih->chip == BCM4313_CHIP_ID)) {
2565 if (wlc->pub->boardrev >= 0x1250
2566 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2567 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
2568 MHF5_4313_GPIOCTRL, WLC_BAND_ALL);
2570 wlc_mhf(wlc, MHF4, MHF4_EXTPA_ENABLE, MHF4_EXTPA_ENABLE,
2576 * Need to read the hwradio status here to cover the case where the system
2577 * is loaded with the hw radio disabled. We do not want to bring the driver up in this case.
2578 * if radio is disabled, abort up, lower power, start radio timer and return 0(for NDIS)
2579 * don't call radio_update to avoid looping wlc_up.
2581 * wlc_bmac_up_prep() returns either 0 or BCME_RADIOOFF only
2583 if (!wlc->pub->radio_disabled) {
2584 int status = wlc_bmac_up_prep(wlc->hw);
2585 if (status == BCME_RADIOOFF) {
2587 (wlc->pub->radio_disabled, WL_RADIO_HW_DISABLE)) {
2589 wlc_bsscfg_t *bsscfg;
2590 mboolset(wlc->pub->radio_disabled,
2591 WL_RADIO_HW_DISABLE);
2593 FOREACH_BSS(wlc, idx, bsscfg) {
2594 if (!BSSCFG_STA(bsscfg)
2595 || !bsscfg->enable || !bsscfg->BSS)
2597 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2598 wlc->pub->unit, idx);
2605 if (wlc->pub->radio_disabled) {
2606 wlc_radio_monitor_start(wlc);
2610 /* wlc_bmac_up_prep has done wlc_corereset(). so clk is on, set it */
2613 wlc_radio_monitor_stop(wlc);
2615 /* Set EDCF hostflags */
2616 if (EDCF_ENAB(wlc->pub)) {
2617 wlc_mhf(wlc, MHF1, MHF1_EDCF, MHF1_EDCF, WLC_BAND_ALL);
2619 wlc_mhf(wlc, MHF1, MHF1_EDCF, 0, WLC_BAND_ALL);
2622 if (WLC_WAR16165(wlc))
2623 wlc_mhf(wlc, MHF2, MHF2_PCISLOWCLKWAR, MHF2_PCISLOWCLKWAR,
2627 wlc->pub->up = true;
2629 if (wlc->bandinit_pending) {
2630 wlc_suspend_mac_and_wait(wlc);
2631 wlc_set_chanspec(wlc, wlc->default_bss->chanspec);
2632 wlc->bandinit_pending = false;
2633 wlc_enable_mac(wlc);
2636 wlc_bmac_up_finish(wlc->hw);
2638 /* other software states up after ISR is running */
2639 /* start APs that were to be brought up but are not up yet */
2640 /* if (AP_ENAB(wlc->pub)) wlc_restart_ap(wlc->ap); */
2642 /* Program the TX wme params with the current settings */
2643 wlc_wme_retries_write(wlc);
2645 /* start one second watchdog timer */
2646 ASSERT(!wlc->WDarmed);
2647 wl_add_timer(wlc->wl, wlc->wdtimer, TIMER_INTERVAL_WATCHDOG, true);
2648 wlc->WDarmed = true;
2650 /* ensure antenna config is up to date */
2651 wlc_stf_phy_txant_upd(wlc);
2652 /* ensure LDPC config is in sync */
2653 wlc_ht_update_ldpc(wlc, wlc->stf->ldpc);
2658 /* Initialize the base precedence map for dequeueing from txq based on WME settings */
2659 static void wlc_tx_prec_map_init(struct wlc_info *wlc)
2661 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2662 memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16));
2664 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2665 * if either is full.
2667 if (!EDCF_ENAB(wlc->pub)) {
2668 wlc->fifo2prec_map[TX_DATA_FIFO] = WLC_PREC_BMP_ALL;
2669 wlc->fifo2prec_map[TX_CTL_FIFO] = WLC_PREC_BMP_ALL;
2671 wlc->fifo2prec_map[TX_AC_BK_FIFO] = WLC_PREC_BMP_AC_BK;
2672 wlc->fifo2prec_map[TX_AC_BE_FIFO] = WLC_PREC_BMP_AC_BE;
2673 wlc->fifo2prec_map[TX_AC_VI_FIFO] = WLC_PREC_BMP_AC_VI;
2674 wlc->fifo2prec_map[TX_AC_VO_FIFO] = WLC_PREC_BMP_AC_VO;
2678 static uint wlc_down_del_timer(struct wlc_info *wlc)
2686 * Mark the interface nonoperational, stop the software mechanisms,
2687 * disable the hardware, free any transient buffer state.
2688 * Return a count of the number of driver callbacks still pending.
2690 uint wlc_down(struct wlc_info *wlc)
2695 bool dev_gone = false;
2698 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2700 /* check if we are already in the going down path */
2701 if (wlc->going_down) {
2702 WL_ERROR("wl%d: %s: Driver going down so return\n",
2703 wlc->pub->unit, __func__);
2709 /* in between, mpc could try to bring down again.. */
2710 wlc->going_down = true;
2712 callbacks += wlc_bmac_down_prep(wlc->hw);
2714 dev_gone = DEVICEREMOVED(wlc);
2716 /* Call any registered down handlers */
2717 for (i = 0; i < WLC_MAXMODULES; i++) {
2718 if (wlc->modulecb[i].down_fn)
2720 wlc->modulecb[i].down_fn(wlc->modulecb[i].hdl);
2723 /* cancel the watchdog timer */
2725 if (!wl_del_timer(wlc->wl, wlc->wdtimer))
2727 wlc->WDarmed = false;
2729 /* cancel all other timers */
2730 callbacks += wlc_down_del_timer(wlc);
2732 /* interrupt must have been blocked */
2733 ASSERT((wlc->macintmask == 0) || !wlc->pub->up);
2735 wlc->pub->up = false;
2737 wlc_phy_mute_upd(wlc->band->pi, false, PHY_MUTE_ALL);
2739 /* clear txq flow control */
2740 wlc_txflowcontrol_reset(wlc);
2742 /* flush tx queues */
2743 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
2744 pktq_flush(wlc->osh, &qi->q, true, NULL, 0);
2745 ASSERT(pktq_empty(&qi->q));
2748 /* flush event queue.
2749 * Should be the last thing done after all the events are generated
2750 * Just delivers the events synchronously instead of waiting for a timer
2752 callbacks += wlc_eventq_down(wlc->eventq);
2754 callbacks += wlc_bmac_down_finish(wlc->hw);
2756 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2760 /* Verify all packets are flushed from the driver */
2761 if (wlc->osh->pktalloced != 0) {
2762 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2763 wlc->osh->pktalloced);
2766 /* Since all the packets should have been freed,
2767 * all callbacks should have been called
2769 for (i = 1; i <= wlc->pub->tunables->maxpktcb; i++)
2770 ASSERT(wlc->pkt_callback[i].fn == NULL);
2772 wlc->going_down = false;
2776 /* Set the current gmode configuration */
2777 int wlc_set_gmode(struct wlc_info *wlc, u8 gmode, bool config)
2782 /* Default to 54g Auto */
2783 s8 shortslot = WLC_SHORTSLOT_AUTO; /* Advertise and use shortslot (-1/0/1 Auto/Off/On) */
2784 bool shortslot_restrict = false; /* Restrict association to stations that support shortslot
2786 bool ignore_bcns = true; /* Ignore legacy beacons on the same channel */
2787 bool ofdm_basic = false; /* Make 6, 12, and 24 basic rates */
2788 int preamble = WLC_PLCP_LONG; /* Advertise and use short preambles (-1/0/1 Auto/Off/On) */
2789 bool preamble_restrict = false; /* Restrict association to stations that support short
2792 struct wlcband *band;
2794 /* if N-support is enabled, allow Gmode set as long as requested
2795 * Gmode is not GMODE_LEGACY_B
2797 if (N_ENAB(wlc->pub) && gmode == GMODE_LEGACY_B)
2798 return BCME_UNSUPPORTED;
2800 /* verify that we are dealing with 2G band and grab the band pointer */
2801 if (wlc->band->bandtype == WLC_BAND_2G)
2803 else if ((NBANDS(wlc) > 1) &&
2804 (wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype == WLC_BAND_2G))
2805 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
2807 return BCME_BADBAND;
2809 /* Legacy or bust when no OFDM is supported by regulatory */
2810 if ((wlc_channel_locale_flags_in_band(wlc->cmi, band->bandunit) &
2811 WLC_NO_OFDM) && (gmode != GMODE_LEGACY_B))
2814 /* update configuration value */
2816 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode);
2818 /* Clear supported rates filter */
2819 memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t));
2821 /* Clear rateset override */
2822 memset(&rs, 0, sizeof(wlc_rateset_t));
2825 case GMODE_LEGACY_B:
2826 shortslot = WLC_SHORTSLOT_OFF;
2827 wlc_rateset_copy(&gphy_legacy_rates, &rs);
2832 if (AP_ENAB(wlc->pub))
2833 wlc_rateset_copy(&cck_rates, &wlc->sup_rates_override);
2837 /* Accept defaults */
2842 preamble = WLC_PLCP_SHORT;
2843 preamble_restrict = true;
2846 case GMODE_PERFORMANCE:
2847 if (AP_ENAB(wlc->pub)) /* Put all rates into the Supported Rates element */
2848 wlc_rateset_copy(&cck_ofdm_rates,
2849 &wlc->sup_rates_override);
2851 shortslot = WLC_SHORTSLOT_ON;
2852 shortslot_restrict = true;
2854 preamble = WLC_PLCP_SHORT;
2855 preamble_restrict = true;
2860 WL_ERROR("wl%d: %s: invalid gmode %d\n",
2861 wlc->pub->unit, __func__, gmode);
2862 return BCME_UNSUPPORTED;
2866 * If we are switching to gmode == GMODE_LEGACY_B,
2867 * clean up rate info that may refer to OFDM rates.
2869 if ((gmode == GMODE_LEGACY_B) && (band->gmode != GMODE_LEGACY_B)) {
2870 band->gmode = gmode;
2871 if (band->rspec_override && !IS_CCK(band->rspec_override)) {
2872 band->rspec_override = 0;
2873 wlc_reprate_init(wlc);
2875 if (band->mrspec_override && !IS_CCK(band->mrspec_override)) {
2876 band->mrspec_override = 0;
2880 band->gmode = gmode;
2882 wlc->ignore_bcns = ignore_bcns;
2884 wlc->shortslot_override = shortslot;
2886 if (AP_ENAB(wlc->pub)) {
2887 /* wlc->ap->shortslot_restrict = shortslot_restrict; */
2888 wlc->PLCPHdr_override =
2890 WLC_PLCP_LONG) ? WLC_PLCP_SHORT : WLC_PLCP_AUTO;
2893 if ((AP_ENAB(wlc->pub) && preamble != WLC_PLCP_LONG)
2894 || preamble == WLC_PLCP_SHORT)
2895 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2897 wlc->default_bss->capability &= ~WLAN_CAPABILITY_SHORT_PREAMBLE;
2899 /* Update shortslot capability bit for AP and IBSS */
2900 if ((AP_ENAB(wlc->pub) && shortslot == WLC_SHORTSLOT_AUTO) ||
2901 shortslot == WLC_SHORTSLOT_ON)
2902 wlc->default_bss->capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2904 wlc->default_bss->capability &=
2905 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
2907 /* Use the default 11g rateset */
2909 wlc_rateset_copy(&cck_ofdm_rates, &rs);
2912 for (i = 0; i < rs.count; i++) {
2913 if (rs.rates[i] == WLC_RATE_6M
2914 || rs.rates[i] == WLC_RATE_12M
2915 || rs.rates[i] == WLC_RATE_24M)
2916 rs.rates[i] |= WLC_RATE_FLAG;
2920 /* Set default bss rateset */
2921 wlc->default_bss->rateset.count = rs.count;
2922 bcopy((char *)rs.rates, (char *)wlc->default_bss->rateset.rates,
2923 sizeof(wlc->default_bss->rateset.rates));
2928 static int wlc_nmode_validate(struct wlc_info *wlc, s32 nmode)
2940 if (!(WLC_PHY_11N_CAP(wlc->band)))
2952 int wlc_set_nmode(struct wlc_info *wlc, s32 nmode)
2957 err = wlc_nmode_validate(wlc, nmode);
2964 wlc->pub->_n_enab = OFF;
2965 wlc->default_bss->flags &= ~WLC_BSS_HT;
2966 /* delete the mcs rates from the default and hw ratesets */
2967 wlc_rateset_mcs_clear(&wlc->default_bss->rateset);
2968 for (i = 0; i < NBANDS(wlc); i++) {
2969 memset(wlc->bandstate[i]->hw_rateset.mcs, 0,
2971 if (IS_MCS(wlc->band->rspec_override)) {
2972 wlc->bandstate[i]->rspec_override = 0;
2973 wlc_reprate_init(wlc);
2975 if (IS_MCS(wlc->band->mrspec_override))
2976 wlc->bandstate[i]->mrspec_override = 0;
2981 if (wlc->stf->txstreams == WL_11N_3x3)
2987 ASSERT(WLC_PHY_11N_CAP(wlc->band));
2988 /* force GMODE_AUTO if NMODE is ON */
2989 wlc_set_gmode(wlc, GMODE_AUTO, true);
2990 if (nmode == WL_11N_3x3)
2991 wlc->pub->_n_enab = SUPPORT_HT;
2993 wlc->pub->_n_enab = SUPPORT_11N;
2994 wlc->default_bss->flags |= WLC_BSS_HT;
2995 /* add the mcs rates to the default and hw ratesets */
2996 wlc_rateset_mcs_build(&wlc->default_bss->rateset,
2997 wlc->stf->txstreams);
2998 for (i = 0; i < NBANDS(wlc); i++)
2999 memcpy(wlc->bandstate[i]->hw_rateset.mcs,
3000 wlc->default_bss->rateset.mcs, MCSSET_LEN);
3011 static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg)
3013 wlc_rateset_t rs, new;
3016 bcopy((char *)rs_arg, (char *)&rs, sizeof(wlc_rateset_t));
3018 /* check for bad count value */
3019 if ((rs.count == 0) || (rs.count > WLC_NUMRATES))
3020 return BCME_BADRATESET;
3022 /* try the current band */
3023 bandunit = wlc->band->bandunit;
3024 bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t));
3025 if (wlc_rate_hwrs_filter_sort_validate
3026 (&new, &wlc->bandstate[bandunit]->hw_rateset, true,
3027 wlc->stf->txstreams))
3030 /* try the other band */
3031 if (IS_MBAND_UNLOCKED(wlc)) {
3032 bandunit = OTHERBANDUNIT(wlc);
3033 bcopy((char *)&rs, (char *)&new, sizeof(wlc_rateset_t));
3034 if (wlc_rate_hwrs_filter_sort_validate(&new,
3036 bandstate[bandunit]->
3038 wlc->stf->txstreams))
3045 /* apply new rateset */
3046 bcopy((char *)&new, (char *)&wlc->default_bss->rateset,
3047 sizeof(wlc_rateset_t));
3048 bcopy((char *)&new, (char *)&wlc->bandstate[bandunit]->defrateset,
3049 sizeof(wlc_rateset_t));
3053 /* simplified integer set interface for common ioctl handler */
3054 int wlc_set(struct wlc_info *wlc, int cmd, int arg)
3056 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
3059 /* simplified integer get interface for common ioctl handler */
3060 int wlc_get(struct wlc_info *wlc, int cmd, int *arg)
3062 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL);
3065 static void wlc_ofdm_rateset_war(struct wlc_info *wlc)
3070 if (wlc->cfg->associated)
3071 r = wlc->cfg->current_bss->rateset.rates[0];
3073 r = wlc->default_bss->rateset.rates[0];
3075 wlc_phy_ofdm_rateset_war(wlc->band->pi, war);
3081 wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3082 struct wlc_if *wlcif)
3084 return _wlc_ioctl(wlc, cmd, arg, len, wlcif);
3087 /* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3089 _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3090 struct wlc_if *wlcif)
3097 struct scb *nextscb;
3101 wlc_bsscfg_t *bsscfg;
3102 struct osl_info *osh;
3103 wlc_bss_info_t *current_bss;
3105 /* update bsscfg pointer */
3106 bsscfg = NULL; /* XXX: Hack bsscfg to be size one and use this globally */
3109 /* initialize the following to get rid of compiler warning */
3115 /* If the device is turned off, then it's not "removed" */
3116 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
3117 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
3122 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
3124 /* default argument is generic integer */
3125 pval = arg ? (int *)arg:NULL;
3127 /* This will prevent the misaligned access */
3128 if (pval && (u32) len >= sizeof(val))
3129 bcopy(pval, &val, sizeof(val));
3133 /* bool conversion to avoid duplication below */
3134 bool_val = val != 0;
3136 if (cmd != WLC_SET_CHANNEL)
3137 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3138 cmd, (uint)val, val, len);
3144 /* A few commands don't need any arguments; all the others do. */
3152 case WLC_START_CHANNEL_QA:
3157 if ((arg == NULL) || (len <= 0)) {
3158 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3159 wlc->pub->unit, __func__, cmd);
3160 bcmerror = BCME_BADARG;
3168 case WLC_GET_MSGLEVEL:
3169 *pval = wl_msg_level;
3172 case WLC_SET_MSGLEVEL:
3177 case WLC_GET_INSTANCE:
3178 *pval = wlc->pub->unit;
3181 case WLC_GET_CHANNEL:{
3182 channel_info_t *ci = (channel_info_t *) arg;
3184 ASSERT(len > (int)sizeof(ci));
3187 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC);
3188 ci->target_channel =
3189 CHSPEC_CHANNEL(wlc->default_bss->chanspec);
3190 ci->scan_channel = 0;
3195 case WLC_SET_CHANNEL:{
3196 chanspec_t chspec = CH20MHZ_CHSPEC(val);
3198 if (val < 0 || val > MAXCHANNEL) {
3199 bcmerror = BCME_OUTOFRANGECHAN;
3203 if (!wlc_valid_chanspec_db(wlc->cmi, chspec)) {
3204 bcmerror = BCME_BADCHAN;
3208 if (!wlc->pub->up && IS_MBAND_UNLOCKED(wlc)) {
3209 if (wlc->band->bandunit !=
3210 CHSPEC_WLCBANDUNIT(chspec))
3211 wlc->bandinit_pending = true;
3213 wlc->bandinit_pending = false;
3216 wlc->default_bss->chanspec = chspec;
3217 /* wlc_BSSinit() will sanitize the rateset before using it.. */
3218 if (wlc->pub->up && !wlc->pub->associated &&
3219 (WLC_BAND_PI_RADIO_CHANSPEC != chspec)) {
3220 wlc_set_home_chanspec(wlc, chspec);
3221 wlc_suspend_mac_and_wait(wlc);
3222 wlc_set_chanspec(wlc, chspec);
3223 wlc_enable_mac(wlc);
3229 case WLC_GET_UCFLAGS:
3230 if (!wlc->pub->up) {
3231 bcmerror = BCME_NOTUP;
3235 /* optional band is stored in the second integer of incoming buffer */
3238 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3240 /* bcmerror checking */
3241 bcmerror = wlc_iocregchk(wlc, band);
3245 if (val >= MHFMAX) {
3246 bcmerror = BCME_RANGE;
3250 *pval = wlc_bmac_mhf_get(wlc->hw, (u8) val, WLC_BAND_AUTO);
3253 case WLC_SET_UCFLAGS:
3254 if (!wlc->pub->up) {
3255 bcmerror = BCME_NOTUP;
3259 /* optional band is stored in the second integer of incoming buffer */
3262 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3264 /* bcmerror checking */
3265 bcmerror = wlc_iocregchk(wlc, band);
3271 bcmerror = BCME_RANGE;
3275 wlc_mhf(wlc, (u8) i, 0xffff, (u16) (val >> NBITS(u16)),
3282 /* optional band is stored in the second integer of incoming buffer */
3285 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3287 /* bcmerror checking */
3288 bcmerror = wlc_iocregchk(wlc, band);
3293 bcmerror = BCME_BADADDR;
3297 *pval = wlc_read_shm(wlc, (u16) val);
3303 /* optional band is stored in the second integer of incoming buffer */
3306 (int)(2 * sizeof(int))) ? WLC_BAND_AUTO : ((int *)arg)[1];
3308 /* bcmerror checking */
3309 bcmerror = wlc_iocregchk(wlc, band);
3314 bcmerror = BCME_BADADDR;
3318 wlc_write_shm(wlc, (u16) val,
3319 (u16) (val >> NBITS(u16)));
3322 case WLC_R_REG: /* MAC registers */
3324 r = (rw_reg_t *) arg;
3325 band = WLC_BAND_AUTO;
3327 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3328 bcmerror = BCME_BUFTOOSHORT;
3332 if (len >= (int)sizeof(rw_reg_t))
3335 /* bcmerror checking */
3336 bcmerror = wlc_iocregchk(wlc, band);
3340 if ((r->byteoff + r->size) > sizeof(d11regs_t)) {
3341 bcmerror = BCME_BADADDR;
3344 if (r->size == sizeof(u32))
3347 (u32 *)((unsigned char *)(unsigned long)regs +
3349 else if (r->size == sizeof(u16))
3352 (u16 *)((unsigned char *)(unsigned long)regs +
3355 bcmerror = BCME_BADADDR;
3360 r = (rw_reg_t *) arg;
3361 band = WLC_BAND_AUTO;
3363 if (len < (int)(sizeof(rw_reg_t) - sizeof(uint))) {
3364 bcmerror = BCME_BUFTOOSHORT;
3368 if (len >= (int)sizeof(rw_reg_t))
3371 /* bcmerror checking */
3372 bcmerror = wlc_iocregchk(wlc, band);
3376 if (r->byteoff + r->size > sizeof(d11regs_t)) {
3377 bcmerror = BCME_BADADDR;
3380 if (r->size == sizeof(u32))
3382 (u32 *)((unsigned char *)(unsigned long) regs +
3383 r->byteoff), r->val);
3384 else if (r->size == sizeof(u16))
3386 (u16 *)((unsigned char *)(unsigned long) regs +
3387 r->byteoff), r->val);
3389 bcmerror = BCME_BADADDR;
3394 *pval = wlc->stf->txant;
3398 bcmerror = wlc_stf_ant_txant_validate(wlc, (s8) val);
3402 wlc->stf->txant = (s8) val;
3404 /* if down, we are done */
3408 wlc_suspend_mac_and_wait(wlc);
3410 wlc_stf_phy_txant_upd(wlc);
3411 wlc_beacon_phytxctl_txant_upd(wlc, wlc->bcn_rspec);
3413 wlc_enable_mac(wlc);
3417 case WLC_GET_ANTDIV:{
3420 /* return configured value if core is down */
3421 if (!wlc->pub->up) {
3422 *pval = wlc->stf->ant_rx_ovr;
3425 if (wlc_phy_ant_rxdiv_get
3426 (wlc->band->pi, &phy_antdiv))
3427 *pval = (int)phy_antdiv;
3429 *pval = (int)wlc->stf->ant_rx_ovr;
3434 case WLC_SET_ANTDIV:
3435 /* values are -1=driver default, 0=force0, 1=force1, 2=start1, 3=start0 */
3436 if ((val < -1) || (val > 3)) {
3437 bcmerror = BCME_RANGE;
3442 val = ANT_RX_DIV_DEF;
3444 wlc->stf->ant_rx_ovr = (u8) val;
3445 wlc_phy_ant_rxdiv_set(wlc->band->pi, (u8) val);
3448 case WLC_GET_RX_ANT:{ /* get latest used rx antenna */
3451 if (!wlc->pub->up) {
3452 bcmerror = BCME_NOTUP;
3456 rxstatus = R_REG(wlc->osh, &wlc->regs->phyrxstatus0);
3457 if (rxstatus == 0xdead || rxstatus == (u16) -1) {
3458 bcmerror = BCME_ERROR;
3461 *pval = (rxstatus & PRXS0_RXANT_UPSUBBAND) ? 1 : 0;
3466 case WLC_GET_UCANTDIV:
3468 bcmerror = BCME_NOCLK;
3473 (wlc_bmac_mhf_get(wlc->hw, MHF1, WLC_BAND_AUTO) &
3477 case WLC_SET_UCANTDIV:{
3478 if (!wlc->pub->up) {
3479 bcmerror = BCME_NOTUP;
3483 /* if multiband, band must be locked */
3484 if (IS_MBAND_UNLOCKED(wlc)) {
3485 bcmerror = BCME_NOTBANDLOCKED;
3489 /* 4322 supports antdiv in phy, no need to set it to ucode */
3490 if (WLCISNPHY(wlc->band)
3491 && D11REV_IS(wlc->pub->corerev, 16)) {
3492 WL_ERROR("wl%d: can't set ucantdiv for 4322\n",
3494 bcmerror = BCME_UNSUPPORTED;
3496 wlc_mhf(wlc, MHF1, MHF1_ANTDIV,
3497 (val ? MHF1_ANTDIV : 0), WLC_BAND_AUTO);
3500 #endif /* defined(BCMDBG) */
3507 if (val >= 1 && val <= RETRY_SHORT_MAX) {
3509 wlc->SRL = (u16) val;
3511 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3513 for (ac = 0; ac < AC_COUNT; ac++) {
3514 WLC_WME_RETRY_SHORT_SET(wlc, ac, wlc->SRL);
3516 wlc_wme_retries_write(wlc);
3518 bcmerror = BCME_RANGE;
3526 if (val >= 1 && val <= 255) {
3528 wlc->LRL = (u16) val;
3530 wlc_bmac_retrylimit_upd(wlc->hw, wlc->SRL, wlc->LRL);
3532 for (ac = 0; ac < AC_COUNT; ac++) {
3533 WLC_WME_RETRY_LONG_SET(wlc, ac, wlc->LRL);
3535 wlc_wme_retries_write(wlc);
3537 bcmerror = BCME_RANGE;
3541 *pval = wlc->band->CWmin;
3546 bcmerror = BCME_NOCLK;
3550 if (val >= 1 && val <= 255) {
3551 wlc_set_cwmin(wlc, (u16) val);
3553 bcmerror = BCME_RANGE;
3557 *pval = wlc->band->CWmax;
3562 bcmerror = BCME_NOCLK;
3566 if (val >= 255 && val <= 2047) {
3567 wlc_set_cwmax(wlc, (u16) val);
3569 bcmerror = BCME_RANGE;
3572 case WLC_GET_RADIO: /* use mask if don't want to expose some internal bits */
3573 *pval = wlc->pub->radio_disabled;
3576 case WLC_SET_RADIO:{ /* 32 bits input, higher 16 bits are mask, lower 16 bits are value to
3579 u16 radiomask, radioval;
3581 WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE;
3584 radiomask = (val & 0xffff0000) >> 16;
3585 radioval = val & 0x0000ffff;
3587 if ((radiomask == 0) || (radiomask & ~validbits)
3588 || (radioval & ~validbits)
3589 || ((radioval & ~radiomask) != 0)) {
3590 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3592 bcmerror = BCME_RANGE;
3597 (wlc->pub->radio_disabled & ~radiomask) | radioval;
3598 wlc->pub->radio_disabled = new;
3600 wlc_radio_hwdisable_upd(wlc);
3605 case WLC_GET_PHYTYPE:
3606 *pval = WLC_PHYTYPE(wlc->band->phytype);
3611 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc))) {
3614 wsec_key_t *src_key = wlc->wsec_keys[val];
3616 if (len < (int)sizeof(key)) {
3617 bcmerror = BCME_BUFTOOSHORT;
3621 memset((char *)&key, 0, sizeof(key));
3623 key.index = src_key->id;
3624 key.len = src_key->len;
3625 bcopy(src_key->data, key.data, key.len);
3626 key.algo = src_key->algo;
3627 if (WSEC_SOFTKEY(wlc, src_key, bsscfg))
3628 key.flags |= WL_SOFT_KEY;
3629 if (src_key->flags & WSEC_PRIMARY_KEY)
3630 key.flags |= WL_PRIMARY_KEY;
3632 bcopy(src_key->ea, key.ea,
3636 bcopy((char *)&key, arg, sizeof(key));
3638 bcmerror = BCME_BADKEYIDX;
3640 #endif /* defined(BCMDBG) */
3644 wlc_iovar_op(wlc, "wsec_key", NULL, 0, arg, len, IOV_SET,
3648 case WLC_GET_KEY_SEQ:{
3651 if (len < DOT11_WPA_KEY_RSC_LEN) {
3652 bcmerror = BCME_BUFTOOSHORT;
3656 /* Return the key's tx iv as an EAPOL sequence counter.
3657 * This will be used to supply the RSC value to a supplicant.
3658 * The format is 8 bytes, with least significant in seq[0].
3661 key = WSEC_KEY(wlc, val);
3662 if ((val >= 0) && (val < WLC_MAX_WSEC_KEYS(wlc)) &&
3664 u8 seq[DOT11_WPA_KEY_RSC_LEN];
3667 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3668 if ((bsscfg->WPA_auth & WPA_AUTH_NONE) &&
3669 is_zero_ether_addr(key->ea)) {
3670 lo = bsscfg->wpa_none_txiv.lo;
3671 hi = bsscfg->wpa_none_txiv.hi;
3677 /* format the buffer, low to high */
3679 seq[1] = (lo >> 8) & 0xff;
3681 seq[3] = (hi >> 8) & 0xff;
3682 seq[4] = (hi >> 16) & 0xff;
3683 seq[5] = (hi >> 24) & 0xff;
3687 bcopy((char *)seq, arg, sizeof(seq));
3689 bcmerror = BCME_BADKEYIDX;
3694 case WLC_GET_CURR_RATESET:{
3695 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3698 if (bsscfg->associated)
3699 rs = ¤t_bss->rateset;
3701 rs = &wlc->default_bss->rateset;
3703 if (len < (int)(rs->count + sizeof(rs->count))) {
3704 bcmerror = BCME_BUFTOOSHORT;
3708 /* Copy only legacy rateset section */
3709 ret_rs->count = rs->count;
3710 bcopy(&rs->rates, &ret_rs->rates, rs->count);
3714 case WLC_GET_RATESET:{
3716 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3718 memset(&rs, 0, sizeof(wlc_rateset_t));
3719 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs);
3721 if (len < (int)(rs.count + sizeof(rs.count))) {
3722 bcmerror = BCME_BUFTOOSHORT;
3726 /* Copy only legacy rateset section */
3727 ret_rs->count = rs.count;
3728 bcopy(&rs.rates, &ret_rs->rates, rs.count);
3732 case WLC_SET_RATESET:{
3734 wl_rateset_t *in_rs = (wl_rateset_t *) arg;
3736 if (len < (int)(in_rs->count + sizeof(in_rs->count))) {
3737 bcmerror = BCME_BUFTOOSHORT;
3741 if (in_rs->count > WLC_NUMRATES) {
3742 bcmerror = BCME_BUFTOOLONG;
3746 memset(&rs, 0, sizeof(wlc_rateset_t));
3748 /* Copy only legacy rateset section */
3749 rs.count = in_rs->count;
3750 bcopy(&in_rs->rates, &rs.rates, rs.count);
3752 /* merge rateset coming in with the current mcsset */
3753 if (N_ENAB(wlc->pub)) {
3754 if (bsscfg->associated)
3755 bcopy(¤t_bss->rateset.mcs[0],
3756 rs.mcs, MCSSET_LEN);
3758 bcopy(&wlc->default_bss->rateset.mcs[0],
3759 rs.mcs, MCSSET_LEN);
3762 bcmerror = wlc_set_rateset(wlc, &rs);
3765 wlc_ofdm_rateset_war(wlc);
3770 case WLC_GET_BCNPRD:
3771 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3772 *pval = current_bss->beacon_period;
3774 *pval = wlc->default_bss->beacon_period;
3777 case WLC_SET_BCNPRD:
3778 /* range [1, 0xffff] */
3779 if (val >= DOT11_MIN_BEACON_PERIOD
3780 && val <= DOT11_MAX_BEACON_PERIOD) {
3781 wlc->default_bss->beacon_period = (u16) val;
3783 bcmerror = BCME_RANGE;
3786 case WLC_GET_DTIMPRD:
3787 if (BSSCFG_STA(bsscfg) && bsscfg->BSS && bsscfg->associated)
3788 *pval = current_bss->dtim_period;
3790 *pval = wlc->default_bss->dtim_period;
3793 case WLC_SET_DTIMPRD:
3794 /* range [1, 0xff] */
3795 if (val >= DOT11_MIN_DTIM_PERIOD
3796 && val <= DOT11_MAX_DTIM_PERIOD) {
3797 wlc->default_bss->dtim_period = (u8) val;
3799 bcmerror = BCME_RANGE;
3808 if ((val >= PM_OFF) && (val <= PM_MAX)) {
3812 /* Change watchdog driver to align watchdog with tbtt if possible */
3813 wlc_watchdog_upd(wlc, PS_ALLOWED(wlc));
3815 bcmerror = BCME_ERROR;
3817 #endif /* SUPPORT_PS */
3822 if (AP_ENAB(wlc->pub)) {
3823 bcmerror = BCME_NOTSTA;
3830 if (AP_ENAB(wlc->pub)) {
3831 bcmerror = BCME_NOTSTA;
3835 wlc->wake = val ? true : false;
3837 /* if down, we're done */
3841 /* apply to the mac */
3842 wlc_set_ps_ctrl(wlc);
3845 #endif /* SUPPORT_PS */
3847 case WLC_GET_REVINFO:
3848 bcmerror = wlc_get_revision_info(wlc, arg, (uint) len);
3852 *pval = (int)AP_ENAB(wlc->pub);
3856 if (bsscfg->associated)
3857 *pval = (int)current_bss->atim_window;
3859 *pval = (int)wlc->default_bss->atim_window;
3863 wlc->default_bss->atim_window = (u32) val;
3866 case WLC_GET_PKTCNTS:{
3867 get_pktcnt_t *pktcnt = (get_pktcnt_t *) pval;
3869 pktcnt->rx_good_pkt = wlc->pub->_cnt->rxframe;
3870 pktcnt->rx_bad_pkt = wlc->pub->_cnt->rxerror;
3871 pktcnt->tx_good_pkt =
3872 wlc->pub->_cnt->txfrmsnt;
3873 pktcnt->tx_bad_pkt =
3874 wlc->pub->_cnt->txerror +
3875 wlc->pub->_cnt->txfail;
3876 if (len >= (int)sizeof(get_pktcnt_t)) {
3877 /* Be backward compatible - only if buffer is large enough */
3878 pktcnt->rx_ocast_good_pkt =
3879 wlc->pub->_cnt->rxmfrmocast;
3884 #ifdef SUPPORT_HWKEY
3887 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_GET,
3893 wlc_iovar_op(wlc, "wsec", NULL, 0, arg, len, IOV_SET,
3897 case WLC_GET_WPA_AUTH:
3898 *pval = (int)bsscfg->WPA_auth;
3901 case WLC_SET_WPA_AUTH:
3902 /* change of WPA_Auth modifies the PS_ALLOWED state */
3903 if (BSSCFG_STA(bsscfg)) {
3904 bsscfg->WPA_auth = (u16) val;
3906 bsscfg->WPA_auth = (u16) val;
3908 #endif /* SUPPORT_HWKEY */
3910 case WLC_GET_BANDLIST:
3911 /* count of number of bands, followed by each band type */
3912 *pval++ = NBANDS(wlc);
3913 *pval++ = wlc->band->bandtype;
3914 if (NBANDS(wlc) > 1)
3915 *pval++ = wlc->bandstate[OTHERBANDUNIT(wlc)]->bandtype;
3919 *pval = wlc->bandlocked ? wlc->band->bandtype : WLC_BAND_AUTO;
3922 case WLC_GET_PHYLIST:
3924 unsigned char *cp = arg;
3926 bcmerror = BCME_BUFTOOSHORT;
3930 if (WLCISNPHY(wlc->band)) {
3932 } else if (WLCISLCNPHY(wlc->band)) {
3934 } else if (WLCISSSLPNPHY(wlc->band)) {
3941 case WLC_GET_SHORTSLOT:
3942 *pval = wlc->shortslot;
3945 case WLC_GET_SHORTSLOT_OVERRIDE:
3946 *pval = wlc->shortslot_override;
3949 case WLC_SET_SHORTSLOT_OVERRIDE:
3950 if ((val != WLC_SHORTSLOT_AUTO) &&
3951 (val != WLC_SHORTSLOT_OFF) && (val != WLC_SHORTSLOT_ON)) {
3952 bcmerror = BCME_RANGE;
3956 wlc->shortslot_override = (s8) val;
3958 /* shortslot is an 11g feature, so no more work if we are
3959 * currently on the 5G band
3961 if (BAND_5G(wlc->band->bandtype))
3964 if (wlc->pub->up && wlc->pub->associated) {
3965 /* let watchdog or beacon processing update shortslot */
3966 } else if (wlc->pub->up) {
3967 /* unassociated shortslot is off */
3968 wlc_switch_shortslot(wlc, false);
3970 /* driver is down, so just update the wlc_info value */
3971 if (wlc->shortslot_override == WLC_SHORTSLOT_AUTO) {
3972 wlc->shortslot = false;
3975 (wlc->shortslot_override ==
3982 case WLC_GET_LEGACY_ERP:
3983 *pval = wlc->include_legacy_erp;
3986 case WLC_SET_LEGACY_ERP:
3987 if (wlc->include_legacy_erp == bool_val)
3990 wlc->include_legacy_erp = bool_val;
3992 if (AP_ENAB(wlc->pub) && wlc->clk) {
3993 wlc_update_beacon(wlc);
3994 wlc_update_probe_resp(wlc, true);
3999 if (wlc->band->bandtype == WLC_BAND_2G)
4000 *pval = wlc->band->gmode;
4001 else if (NBANDS(wlc) > 1)
4002 *pval = wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode;
4006 if (!wlc->pub->associated)
4007 bcmerror = wlc_set_gmode(wlc, (u8) val, true);
4009 bcmerror = BCME_ASSOCIATED;
4014 case WLC_GET_GMODE_PROTECTION:
4015 *pval = wlc->protection->_g;
4018 case WLC_GET_PROTECTION_CONTROL:
4019 *pval = wlc->protection->overlap;
4022 case WLC_SET_PROTECTION_CONTROL:
4023 if ((val != WLC_PROTECTION_CTL_OFF) &&
4024 (val != WLC_PROTECTION_CTL_LOCAL) &&
4025 (val != WLC_PROTECTION_CTL_OVERLAP)) {
4026 bcmerror = BCME_RANGE;
4030 wlc_protection_upd(wlc, WLC_PROT_OVERLAP, (s8) val);
4032 /* Current g_protection will sync up to the specified control alg in watchdog
4033 * if the driver is up and associated.
4034 * If the driver is down or not associated, the control setting has no effect.
4038 case WLC_GET_GMODE_PROTECTION_OVERRIDE:
4039 *pval = wlc->protection->g_override;
4042 case WLC_SET_GMODE_PROTECTION_OVERRIDE:
4043 if ((val != WLC_PROTECTION_AUTO) &&
4044 (val != WLC_PROTECTION_OFF) && (val != WLC_PROTECTION_ON)) {
4045 bcmerror = BCME_RANGE;
4049 wlc_protection_upd(wlc, WLC_PROT_G_OVR, (s8) val);
4053 case WLC_SET_SUP_RATESET_OVERRIDE:{
4054 wlc_rateset_t rs, new;
4057 if (len < (int)sizeof(wlc_rateset_t)) {
4058 bcmerror = BCME_BUFTOOSHORT;
4061 bcopy((char *)arg, (char *)&rs, sizeof(wlc_rateset_t));
4063 /* check for bad count value */
4064 if (rs.count > WLC_NUMRATES) {
4065 bcmerror = BCME_BADRATESET; /* invalid rateset */
4069 /* this command is only appropriate for gmode operation */
4070 if (!(wlc->band->gmode ||
4072 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4073 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4077 /* check for an empty rateset to clear the override */
4078 if (rs.count == 0) {
4079 memset(&wlc->sup_rates_override, 0,
4080 sizeof(wlc_rateset_t));
4084 /* validate rateset by comparing pre and post sorted against 11g hw rates */
4085 wlc_rateset_filter(&rs, &new, false, WLC_RATES_CCK_OFDM,
4086 RATE_MASK, BSS_N_ENAB(wlc, bsscfg));
4087 wlc_rate_hwrs_filter_sort_validate(&new,
4090 wlc->stf->txstreams);
4091 if (rs.count != new.count) {
4092 bcmerror = BCME_BADRATESET; /* invalid rateset */
4096 /* apply new rateset to the override */
4097 bcopy((char *)&new, (char *)&wlc->sup_rates_override,
4098 sizeof(wlc_rateset_t));
4100 /* update bcn and probe resp if needed */
4101 if (wlc->pub->up && AP_ENAB(wlc->pub)
4102 && wlc->pub->associated) {
4103 wlc_update_beacon(wlc);
4104 wlc_update_probe_resp(wlc, true);
4109 case WLC_GET_SUP_RATESET_OVERRIDE:
4110 /* this command is only appropriate for gmode operation */
4111 if (!(wlc->band->gmode ||
4113 && wlc->bandstate[OTHERBANDUNIT(wlc)]->gmode))) {
4114 bcmerror = BCME_BADBAND; /* gmode only command when not in gmode */
4117 if (len < (int)sizeof(wlc_rateset_t)) {
4118 bcmerror = BCME_BUFTOOSHORT;
4121 bcopy((char *)&wlc->sup_rates_override, (char *)arg,
4122 sizeof(wlc_rateset_t));
4126 case WLC_GET_PRB_RESP_TIMEOUT:
4127 *pval = wlc->prb_resp_timeout;
4130 case WLC_SET_PRB_RESP_TIMEOUT:
4132 bcmerror = BCME_NOTDOWN;
4135 if (val < 0 || val >= 0xFFFF) {
4136 bcmerror = BCME_RANGE; /* bad value */
4139 wlc->prb_resp_timeout = (u16) val;
4142 case WLC_GET_KEY_PRIMARY:{
4145 /* treat the 'val' parm as the key id */
4146 key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4148 *pval = key->id == val ? true : false;
4150 bcmerror = BCME_BADKEYIDX;
4155 case WLC_SET_KEY_PRIMARY:{
4156 wsec_key_t *key, *old_key;
4158 bcmerror = BCME_BADKEYIDX;
4160 /* treat the 'val' parm as the key id */
4161 for (i = 0; i < WSEC_MAX_DEFAULT_KEYS; i++) {
4162 key = bsscfg->bss_def_keys[i];
4163 if (key != NULL && key->id == val) {
4164 old_key = WSEC_BSS_DEFAULT_KEY(bsscfg);
4165 if (old_key != NULL)
4168 key->flags |= WSEC_PRIMARY_KEY;
4169 bsscfg->wsec_index = i;
4185 /* validate the name value */
4187 for (i = 0; i < (uint) len && *name != '\0';
4191 if (i == (uint) len) {
4192 bcmerror = BCME_BUFTOOSHORT;
4195 i++; /* include the null in the string length */
4197 if (cmd == WLC_GET_VAR) {
4199 wlc_iovar_op(wlc, arg,
4200 (void *)((s8 *) arg + i),
4201 len - i, arg, len, IOV_GET,
4205 wlc_iovar_op(wlc, arg, NULL, 0,
4206 (void *)((s8 *) arg + i),
4207 len - i, IOV_SET, wlcif);
4212 case WLC_SET_WSEC_PMK:
4213 bcmerror = BCME_UNSUPPORTED;
4217 case WLC_CURRENT_PWR:
4219 bcmerror = BCME_NOTUP;
4221 bcmerror = wlc_get_current_txpwr(wlc, arg, len);
4226 WL_ERROR("%s: WLC_LAST\n", __func__);
4231 if (VALID_BCMERROR(bcmerror))
4232 wlc->pub->bcmerror = bcmerror;
4238 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4239 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4240 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4242 if (!(wlc->pub->hw_off))
4243 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok);
4249 /* consolidated register access ioctl error checking */
4250 int wlc_iocregchk(struct wlc_info *wlc, uint band)
4252 /* if band is specified, it must be the current band */
4253 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype))
4254 return BCME_BADBAND;
4256 /* if multiband and band is not specified, band must be locked */
4257 if ((band == WLC_BAND_AUTO) && IS_MBAND_UNLOCKED(wlc))
4258 return BCME_NOTBANDLOCKED;
4260 /* must have core clocks */
4266 #endif /* defined(BCMDBG) */
4269 /* For some ioctls, make sure that the pi pointer matches the current phy */
4270 int wlc_iocpichk(struct wlc_info *wlc, uint phytype)
4272 if (wlc->band->phytype != phytype)
4273 return BCME_BADBAND;
4278 /* Look up the given var name in the given table */
4279 static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table,
4282 const bcm_iovar_t *vi;
4283 const char *lookup_name;
4285 /* skip any ':' delimited option prefixes */
4286 lookup_name = strrchr(name, ':');
4287 if (lookup_name != NULL)
4292 ASSERT(table != NULL);
4294 for (vi = table; vi->name; vi++) {
4295 if (!strcmp(vi->name, lookup_name))
4298 /* ran to end of table */
4300 return NULL; /* var name not found */
4303 /* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4304 int wlc_iovar_getint(struct wlc_info *wlc, const char *name, int *arg)
4306 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET,
4310 /* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4311 int wlc_iovar_setint(struct wlc_info *wlc, const char *name, int arg)
4313 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg),
4317 /* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4318 int wlc_iovar_gets8(struct wlc_info *wlc, const char *name, s8 *arg)
4324 wlc_iovar_op(wlc, name, NULL, 0, &iovar_int, sizeof(iovar_int),
4327 *arg = (s8) iovar_int;
4333 * register iovar table, watchdog and down handlers.
4334 * calling function must keep 'iovars' until wlc_module_unregister is called.
4335 * 'iovar' must have the last entry's name field being NULL as terminator.
4337 int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
4338 const char *name, void *hdl, iovar_fn_t i_fn,
4339 watchdog_fn_t w_fn, down_fn_t d_fn)
4341 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4344 ASSERT(name != NULL);
4345 ASSERT(i_fn != NULL || w_fn != NULL || d_fn != NULL);
4347 /* find an empty entry and just add, no duplication check! */
4348 for (i = 0; i < WLC_MAXMODULES; i++) {
4349 if (wlc->modulecb[i].name[0] == '\0') {
4350 strncpy(wlc->modulecb[i].name, name,
4351 sizeof(wlc->modulecb[i].name) - 1);
4352 wlc->modulecb[i].iovars = iovars;
4353 wlc->modulecb[i].hdl = hdl;
4354 wlc->modulecb[i].iovar_fn = i_fn;
4355 wlc->modulecb[i].watchdog_fn = w_fn;
4356 wlc->modulecb[i].down_fn = d_fn;
4361 /* it is time to increase the capacity */
4362 ASSERT(i < WLC_MAXMODULES);
4363 return BCME_NORESOURCE;
4366 /* unregister module callbacks */
4367 int wlc_module_unregister(struct wlc_pub *pub, const char *name, void *hdl)
4369 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4373 return BCME_NOTFOUND;
4375 ASSERT(name != NULL);
4377 for (i = 0; i < WLC_MAXMODULES; i++) {
4378 if (!strcmp(wlc->modulecb[i].name, name) &&
4379 (wlc->modulecb[i].hdl == hdl)) {
4380 memset(&wlc->modulecb[i], 0, sizeof(modulecb_t));
4385 /* table not found! */
4386 return BCME_NOTFOUND;
4389 /* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4390 static void wlc_wme_retries_write(struct wlc_info *wlc)
4394 /* Need clock to do this */
4398 for (ac = 0; ac < AC_COUNT; ac++) {
4399 wlc_write_shm(wlc, M_AC_TXLMT_ADDR(ac), wlc->wme_retries[ac]);
4403 /* Get or set an iovar. The params/p_len pair specifies any additional
4404 * qualifying parameters (e.g. an "element index") for a get, while the
4405 * arg/len pair is the buffer for the value to be set or retrieved.
4406 * Operation (get/set) is specified by the last argument.
4407 * interface context provided by wlcif
4409 * All pointers may point into the same buffer.
4412 wlc_iovar_op(struct wlc_info *wlc, const char *name,
4413 void *params, int p_len, void *arg, int len,
4414 bool set, struct wlc_if *wlcif)
4418 const bcm_iovar_t *vi = NULL;
4422 ASSERT(name != NULL);
4426 /* Get MUST have return space */
4427 ASSERT(set || (arg && len));
4429 ASSERT(!(wlc->pub->hw_off && wlc->pub->up));
4431 /* Set does NOT take qualifiers */
4432 ASSERT(!set || (!params && !p_len));
4434 if (!set && (len == sizeof(int)) &&
4435 !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) {
4436 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4437 wlc->pub->unit, __func__, name);
4441 /* find the given iovar name */
4442 for (i = 0; i < WLC_MAXMODULES; i++) {
4443 if (!wlc->modulecb[i].iovars)
4445 vi = wlc_iovar_lookup(wlc->modulecb[i].iovars, name);
4449 /* iovar name not found */
4450 if (i >= WLC_MAXMODULES) {
4451 err = BCME_UNSUPPORTED;
4455 /* set up 'params' pointer in case this is a set command so that
4456 * the convenience int and bool code can be common to set and get
4458 if (params == NULL) {
4463 if (vi->type == IOVT_VOID)
4465 else if (vi->type == IOVT_BUFFER)
4468 /* all other types are integer sized */
4469 val_size = sizeof(int);
4471 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
4473 /* Do the actual parameter implementation */
4474 err = wlc->modulecb[i].iovar_fn(wlc->modulecb[i].hdl, vi, actionid,
4475 name, params, p_len, arg, len, val_size,
4483 wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi, void *arg, int len,
4486 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4490 /* check generic condition flags */
4492 if (((vi->flags & IOVF_SET_DOWN) && wlc->pub->up) ||
4493 ((vi->flags & IOVF_SET_UP) && !wlc->pub->up)) {
4494 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4495 } else if ((vi->flags & IOVF_SET_BAND)
4496 && IS_MBAND_UNLOCKED(wlc)) {
4497 err = BCME_NOTBANDLOCKED;
4498 } else if ((vi->flags & IOVF_SET_CLK) && !wlc->clk) {
4502 if (((vi->flags & IOVF_GET_DOWN) && wlc->pub->up) ||
4503 ((vi->flags & IOVF_GET_UP) && !wlc->pub->up)) {
4504 err = (wlc->pub->up ? BCME_NOTDOWN : BCME_NOTUP);
4505 } else if ((vi->flags & IOVF_GET_BAND)
4506 && IS_MBAND_UNLOCKED(wlc)) {
4507 err = BCME_NOTBANDLOCKED;
4508 } else if ((vi->flags & IOVF_GET_CLK) && !wlc->clk) {
4516 /* length check on io buf */
4517 err = bcm_iovar_lencheck(vi, arg, len, set);
4521 /* On set, check value ranges for integer types */
4531 bcopy(arg, &int_val, sizeof(int));
4532 err = wlc_iovar_rangecheck(wlc, int_val, vi);
4540 /* handler for iovar table wlc_iovars */
4542 * IMPLEMENTATION NOTE: In order to avoid checking for get/set in each
4543 * iovar case, the switch statement maps the iovar id into separate get
4544 * and set values. If you add a new iovar to the switch you MUST use
4545 * IOV_GVAL and/or IOV_SVAL in the case labels to avoid conflict with
4547 * Please use params for additional qualifying parameters.
4550 wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4551 const char *name, void *params, uint p_len, void *arg, int len,
4552 int val_size, struct wlc_if *wlcif)
4554 struct wlc_info *wlc = hdl;
4555 wlc_bsscfg_t *bsscfg;
4562 wlc_bss_info_t *current_bss;
4564 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
4569 err = wlc_iovar_check(wlc->pub, vi, arg, len, IOV_ISSET(actionid));
4573 /* convenience int and bool vals for first 8 bytes of buffer */
4574 if (p_len >= (int)sizeof(int_val))
4575 bcopy(params, &int_val, sizeof(int_val));
4577 if (p_len >= (int)sizeof(int_val) * 2)
4578 bcopy((void *)((unsigned long)params + sizeof(int_val)), &int_val2,
4581 /* convenience int ptr for 4-byte gets (requires int aligned arg) */
4582 ret_int_ptr = (s32 *) arg;
4584 bool_val = (int_val != 0) ? true : false;
4585 bool_val2 = (int_val2 != 0) ? true : false;
4587 WL_TRACE("wl%d: %s: id %d\n",
4588 wlc->pub->unit, __func__, IOV_ID(actionid));
4589 /* Do the actual parameter implementation */
4591 case IOV_SVAL(IOV_RTSTHRESH):
4592 wlc->RTSThresh = int_val;
4595 case IOV_GVAL(IOV_QTXPOWER):{
4599 err = wlc_phy_txpower_get(wlc->band->pi, &qdbm,
4604 /* Return qdbm units */
4606 qdbm | (override ? WL_TXPWR_OVERRIDE : 0);
4610 /* As long as override is false, this only sets the *user* targets.
4611 User can twiddle this all he wants with no harm.
4612 wlc_phy_txpower_set() explicitly sets override to false if
4613 not internal or test.
4615 case IOV_SVAL(IOV_QTXPOWER):{
4619 /* Remove override bit and clip to max qdbm value */
4620 qdbm = (u8)min_t(u32, (int_val & ~WL_TXPWR_OVERRIDE), 0xff);
4621 /* Extract override setting */
4622 override = (int_val & WL_TXPWR_OVERRIDE) ? true : false;
4624 wlc_phy_txpower_set(wlc->band->pi, qdbm, override);
4628 case IOV_GVAL(IOV_MPC):
4629 *ret_int_ptr = (s32) wlc->mpc;
4632 case IOV_SVAL(IOV_MPC):
4633 wlc->mpc = bool_val;
4634 wlc_radio_mpc_upd(wlc);
4638 case IOV_GVAL(IOV_BCN_LI_BCN):
4639 *ret_int_ptr = wlc->bcn_li_bcn;
4642 case IOV_SVAL(IOV_BCN_LI_BCN):
4643 wlc->bcn_li_bcn = (u8) int_val;
4645 wlc_bcn_li_upd(wlc);
4649 WL_ERROR("wl%d: %s: unsupported\n", wlc->pub->unit, __func__);
4650 err = BCME_UNSUPPORTED;
4654 goto exit; /* avoid unused label warning */
4661 wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val, const bcm_iovar_t *vi)
4667 /* Only ranged integers are checked */
4670 max_val |= 0x7fffffff;
4673 max_val |= 0x00007fff;
4676 max_val |= 0x0000007f;
4678 if (vi->flags & IOVF_NTRL)
4680 else if (vi->flags & IOVF_WHL)
4682 /* Signed values are checked against max_val and min_val */
4683 if ((s32) val < (s32) min_val
4684 || (s32) val > (s32) max_val)
4689 max_val |= 0xffffffff;
4692 max_val |= 0x0000ffff;
4695 max_val |= 0x000000ff;
4696 if (vi->flags & IOVF_NTRL)
4698 if ((val < min_val) || (val > max_val))
4707 static const char *supr_reason[] = {
4708 "None", "PMQ Entry", "Flush request",
4709 "Previous frag failure", "Channel mismatch",
4710 "Lifetime Expiry", "Underflow"
4713 static void wlc_print_txs_status(u16 s)
4715 printk(KERN_DEBUG "[15:12] %d frame attempts\n",
4716 (s & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT);
4717 printk(KERN_DEBUG " [11:8] %d rts attempts\n",
4718 (s & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT);
4719 printk(KERN_DEBUG " [7] %d PM mode indicated\n",
4720 ((s & TX_STATUS_PMINDCTD) ? 1 : 0));
4721 printk(KERN_DEBUG " [6] %d intermediate status\n",
4722 ((s & TX_STATUS_INTERMEDIATE) ? 1 : 0));
4723 printk(KERN_DEBUG " [5] %d AMPDU\n",
4724 (s & TX_STATUS_AMPDU) ? 1 : 0);
4725 printk(KERN_DEBUG " [4:2] %d Frame Suppressed Reason (%s)\n",
4726 ((s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT),
4727 supr_reason[(s & TX_STATUS_SUPR_MASK) >> TX_STATUS_SUPR_SHIFT]);
4728 printk(KERN_DEBUG " [1] %d acked\n",
4729 ((s & TX_STATUS_ACK_RCV) ? 1 : 0));
4733 void wlc_print_txstatus(tx_status_t *txs)
4736 u16 s = txs->status;
4737 u16 ackphyrxsh = txs->ackphyrxsh;
4739 printk(KERN_DEBUG "\ntxpkt (MPDU) Complete\n");
4741 printk(KERN_DEBUG "FrameID: %04x ", txs->frameid);
4742 printk(KERN_DEBUG "TxStatus: %04x", s);
4743 printk(KERN_DEBUG "\n");
4745 wlc_print_txs_status(s);
4747 printk(KERN_DEBUG "LastTxTime: %04x ", txs->lasttxtime);
4748 printk(KERN_DEBUG "Seq: %04x ", txs->sequence);
4749 printk(KERN_DEBUG "PHYTxStatus: %04x ", txs->phyerr);
4750 printk(KERN_DEBUG "RxAckRSSI: %04x ",
4751 (ackphyrxsh & PRXS1_JSSI_MASK) >> PRXS1_JSSI_SHIFT);
4752 printk(KERN_DEBUG "RxAckSQ: %04x",
4753 (ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
4754 printk(KERN_DEBUG "\n");
4755 #endif /* defined(BCMDBG) */
4759 wlc_ctrupd_cache(u16 cur_stat, u16 *macstat_snapshot, u32 *macstat)
4764 v = ltoh16(cur_stat);
4765 delta = (u16)(v - *macstat_snapshot);
4769 *macstat_snapshot = v;
4773 #define MACSTATUPD(name) \
4774 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4776 void wlc_statsupd(struct wlc_info *wlc)
4786 /* if driver down, make no sense to update stats */
4791 /* save last rx fifo 0 overflow count */
4792 rxf0ovfl = wlc->core->macstat_snapshot->rxf0ovfl;
4794 /* save last tx fifo underflow count */
4795 for (i = 0; i < NFIFO; i++)
4796 txfunfl[i] = wlc->core->macstat_snapshot->txfunfl[i];
4799 /* Read mac stats from contiguous shared memory */
4800 wlc_bmac_copyfrom_shm(wlc->hw, M_UCODE_MACSTAT,
4801 &macstats, sizeof(macstat_t));
4803 /* update mac stats */
4804 MACSTATUPD(txallfrm);
4805 MACSTATUPD(txrtsfrm);
4806 MACSTATUPD(txctsfrm);
4807 MACSTATUPD(txackfrm);
4808 MACSTATUPD(txdnlfrm);
4809 MACSTATUPD(txbcnfrm);
4810 for (i = 0; i < NFIFO; i++)
4811 MACSTATUPD(txfunfl[i]);
4812 MACSTATUPD(txtplunfl);
4813 MACSTATUPD(txphyerr);
4814 MACSTATUPD(rxfrmtoolong);
4815 MACSTATUPD(rxfrmtooshrt);
4816 MACSTATUPD(rxinvmachdr);
4817 MACSTATUPD(rxbadfcs);
4818 MACSTATUPD(rxbadplcp);
4819 MACSTATUPD(rxcrsglitch);
4821 MACSTATUPD(rxdfrmucastmbss);
4822 MACSTATUPD(rxmfrmucastmbss);
4823 MACSTATUPD(rxcfrmucast);
4824 MACSTATUPD(rxrtsucast);
4825 MACSTATUPD(rxctsucast);
4826 MACSTATUPD(rxackucast);
4827 MACSTATUPD(rxdfrmocast);
4828 MACSTATUPD(rxmfrmocast);
4829 MACSTATUPD(rxcfrmocast);
4830 MACSTATUPD(rxrtsocast);
4831 MACSTATUPD(rxctsocast);
4832 MACSTATUPD(rxdfrmmcast);
4833 MACSTATUPD(rxmfrmmcast);
4834 MACSTATUPD(rxcfrmmcast);
4835 MACSTATUPD(rxbeaconmbss);
4836 MACSTATUPD(rxdfrmucastobss);
4837 MACSTATUPD(rxbeaconobss);
4838 MACSTATUPD(rxrsptmout);
4839 MACSTATUPD(bcntxcancl);
4840 MACSTATUPD(rxf0ovfl);
4841 MACSTATUPD(rxf1ovfl);
4842 MACSTATUPD(rxf2ovfl);
4843 MACSTATUPD(txsfovfl);
4844 MACSTATUPD(pmqovfl);
4845 MACSTATUPD(rxcgprqfrm);
4846 MACSTATUPD(rxcgprsqovfl);
4847 MACSTATUPD(txcgprsfail);
4848 MACSTATUPD(txcgprssuc);
4849 MACSTATUPD(prs_timeout);
4851 MACSTATUPD(frmscons);
4853 MACSTATUPD(txglitch_nack);
4854 MACSTATUPD(txburst);
4855 MACSTATUPD(phywatchdog);
4856 MACSTATUPD(pktengrxducast);
4857 MACSTATUPD(pktengrxdmcast);
4860 /* check for rx fifo 0 overflow */
4861 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
4863 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4864 wlc->pub->unit, delta);
4866 /* check for tx fifo underflows */
4867 for (i = 0; i < NFIFO; i++) {
4869 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
4872 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4873 wlc->pub->unit, delta, i);
4877 /* dot11 counter update */
4879 WLCNTSET(wlc->pub->_cnt->txrts,
4880 (wlc->pub->_cnt->rxctsucast -
4881 wlc->pub->_cnt->d11cnt_txrts_off));
4882 WLCNTSET(wlc->pub->_cnt->rxcrc,
4883 (wlc->pub->_cnt->rxbadfcs - wlc->pub->_cnt->d11cnt_rxcrc_off));
4884 WLCNTSET(wlc->pub->_cnt->txnocts,
4885 ((wlc->pub->_cnt->txrtsfrm - wlc->pub->_cnt->rxctsucast) -
4886 wlc->pub->_cnt->d11cnt_txnocts_off));
4888 /* merge counters from dma module */
4889 for (i = 0; i < NFIFO; i++) {
4890 if (wlc->hw->di[i]) {
4891 WLCNTADD(wlc->pub->_cnt->txnobuf,
4892 (wlc->hw->di[i])->txnobuf);
4893 WLCNTADD(wlc->pub->_cnt->rxnobuf,
4894 (wlc->hw->di[i])->rxnobuf);
4895 WLCNTADD(wlc->pub->_cnt->rxgiant,
4896 (wlc->hw->di[i])->rxgiants);
4897 dma_counterreset(wlc->hw->di[i]);
4902 * Aggregate transmit and receive errors that probably resulted
4903 * in the loss of a frame are computed on the fly.
4905 WLCNTSET(wlc->pub->_cnt->txerror,
4906 wlc->pub->_cnt->txnobuf + wlc->pub->_cnt->txnoassoc +
4907 wlc->pub->_cnt->txuflo + wlc->pub->_cnt->txrunt +
4908 wlc->pub->_cnt->dmade + wlc->pub->_cnt->dmada +
4909 wlc->pub->_cnt->dmape);
4910 WLCNTSET(wlc->pub->_cnt->rxerror,
4911 wlc->pub->_cnt->rxoflo + wlc->pub->_cnt->rxnobuf +
4912 wlc->pub->_cnt->rxfragerr + wlc->pub->_cnt->rxrunt +
4913 wlc->pub->_cnt->rxgiant + wlc->pub->_cnt->rxnoscb +
4914 wlc->pub->_cnt->rxbadsrcmac);
4915 for (i = 0; i < NFIFO; i++)
4916 wlc->pub->_cnt->rxerror += wlc->pub->_cnt->rxuflo[i];
4919 bool wlc_chipmatch(u16 vendor, u16 device)
4921 if (vendor != VENDOR_BROADCOM) {
4922 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor);
4926 if ((device == BCM43224_D11N_ID) || (device == BCM43225_D11N2G_ID))
4929 if (device == BCM4313_D11N2G_ID)
4931 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
4934 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device);
4939 void wlc_print_txdesc(d11txh_t *txh)
4941 u16 mtcl = ltoh16(txh->MacTxControlLow);
4942 u16 mtch = ltoh16(txh->MacTxControlHigh);
4943 u16 mfc = ltoh16(txh->MacFrameControl);
4944 u16 tfest = ltoh16(txh->TxFesTimeNormal);
4945 u16 ptcw = ltoh16(txh->PhyTxControlWord);
4946 u16 ptcw_1 = ltoh16(txh->PhyTxControlWord_1);
4947 u16 ptcw_1_Fbr = ltoh16(txh->PhyTxControlWord_1_Fbr);
4948 u16 ptcw_1_Rts = ltoh16(txh->PhyTxControlWord_1_Rts);
4949 u16 ptcw_1_FbrRts = ltoh16(txh->PhyTxControlWord_1_FbrRts);
4950 u16 mainrates = ltoh16(txh->MainRates);
4951 u16 xtraft = ltoh16(txh->XtraFrameTypes);
4953 u8 *ra = txh->TxFrameRA;
4954 u16 tfestfb = ltoh16(txh->TxFesTimeFallback);
4955 u8 *rtspfb = txh->RTSPLCPFallback;
4956 u16 rtsdfb = ltoh16(txh->RTSDurFallback);
4957 u8 *fragpfb = txh->FragPLCPFallback;
4958 u16 fragdfb = ltoh16(txh->FragDurFallback);
4959 u16 mmodelen = ltoh16(txh->MModeLen);
4960 u16 mmodefbrlen = ltoh16(txh->MModeFbrLen);
4961 u16 tfid = ltoh16(txh->TxFrameID);
4962 u16 txs = ltoh16(txh->TxStatus);
4963 u16 mnmpdu = ltoh16(txh->MaxNMpdus);
4964 u16 mabyte = ltoh16(txh->MaxABytes_MRT);
4965 u16 mabyte_f = ltoh16(txh->MaxABytes_FBR);
4966 u16 mmbyte = ltoh16(txh->MinMBytes);
4968 u8 *rtsph = txh->RTSPhyHeader;
4969 struct ieee80211_rts rts = txh->rts_frame;
4972 /* add plcp header along with txh descriptor */
4973 prhex("Raw TxDesc + plcp header", (unsigned char *) txh, sizeof(d11txh_t) + 48);
4975 printk(KERN_DEBUG "TxCtlLow: %04x ", mtcl);
4976 printk(KERN_DEBUG "TxCtlHigh: %04x ", mtch);
4977 printk(KERN_DEBUG "FC: %04x ", mfc);
4978 printk(KERN_DEBUG "FES Time: %04x\n", tfest);
4979 printk(KERN_DEBUG "PhyCtl: %04x%s ", ptcw,
4980 (ptcw & PHY_TXC_SHORT_HDR) ? " short" : "");
4981 printk(KERN_DEBUG "PhyCtl_1: %04x ", ptcw_1);
4982 printk(KERN_DEBUG "PhyCtl_1_Fbr: %04x\n", ptcw_1_Fbr);
4983 printk(KERN_DEBUG "PhyCtl_1_Rts: %04x ", ptcw_1_Rts);
4984 printk(KERN_DEBUG "PhyCtl_1_Fbr_Rts: %04x\n", ptcw_1_FbrRts);
4985 printk(KERN_DEBUG "MainRates: %04x ", mainrates);
4986 printk(KERN_DEBUG "XtraFrameTypes: %04x ", xtraft);
4987 printk(KERN_DEBUG "\n");
4989 bcm_format_hex(hexbuf, iv, sizeof(txh->IV));
4990 printk(KERN_DEBUG "SecIV: %s\n", hexbuf);
4991 bcm_format_hex(hexbuf, ra, sizeof(txh->TxFrameRA));
4992 printk(KERN_DEBUG "RA: %s\n", hexbuf);
4994 printk(KERN_DEBUG "Fb FES Time: %04x ", tfestfb);
4995 bcm_format_hex(hexbuf, rtspfb, sizeof(txh->RTSPLCPFallback));
4996 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
4997 printk(KERN_DEBUG "RTS DUR: %04x ", rtsdfb);
4998 bcm_format_hex(hexbuf, fragpfb, sizeof(txh->FragPLCPFallback));
4999 printk(KERN_DEBUG "PLCP: %s ", hexbuf);
5000 printk(KERN_DEBUG "DUR: %04x", fragdfb);
5001 printk(KERN_DEBUG "\n");
5003 printk(KERN_DEBUG "MModeLen: %04x ", mmodelen);
5004 printk(KERN_DEBUG "MModeFbrLen: %04x\n", mmodefbrlen);
5006 printk(KERN_DEBUG "FrameID: %04x\n", tfid);
5007 printk(KERN_DEBUG "TxStatus: %04x\n", txs);
5009 printk(KERN_DEBUG "MaxNumMpdu: %04x\n", mnmpdu);
5010 printk(KERN_DEBUG "MaxAggbyte: %04x\n", mabyte);
5011 printk(KERN_DEBUG "MaxAggbyte_fb: %04x\n", mabyte_f);
5012 printk(KERN_DEBUG "MinByte: %04x\n", mmbyte);
5014 bcm_format_hex(hexbuf, rtsph, sizeof(txh->RTSPhyHeader));
5015 printk(KERN_DEBUG "RTS PLCP: %s ", hexbuf);
5016 bcm_format_hex(hexbuf, (u8 *) &rts, sizeof(txh->rts_frame));
5017 printk(KERN_DEBUG "RTS Frame: %s", hexbuf);
5018 printk(KERN_DEBUG "\n");
5020 #endif /* defined(BCMDBG) */
5023 void wlc_print_rxh(d11rxhdr_t *rxh)
5025 u16 len = rxh->RxFrameSize;
5026 u16 phystatus_0 = rxh->PhyRxStatus_0;
5027 u16 phystatus_1 = rxh->PhyRxStatus_1;
5028 u16 phystatus_2 = rxh->PhyRxStatus_2;
5029 u16 phystatus_3 = rxh->PhyRxStatus_3;
5030 u16 macstatus1 = rxh->RxStatus1;
5031 u16 macstatus2 = rxh->RxStatus2;
5034 static const bcm_bit_desc_t macstat_flags[] = {
5035 {RXS_FCSERR, "FCSErr"},
5036 {RXS_RESPFRAMETX, "Reply"},
5037 {RXS_PBPRES, "PADDING"},
5038 {RXS_DECATMPT, "DeCr"},
5039 {RXS_DECERR, "DeCrErr"},
5040 {RXS_BCNSENT, "Bcn"},
5044 prhex("Raw RxDesc", (unsigned char *) rxh, sizeof(d11rxhdr_t));
5046 bcm_format_flags(macstat_flags, macstatus1, flagstr, 64);
5048 snprintf(lenbuf, sizeof(lenbuf), "0x%x", len);
5050 printk(KERN_DEBUG "RxFrameSize: %6s (%d)%s\n", lenbuf, len,
5051 (rxh->PhyRxStatus_0 & PRXS0_SHORTH) ? " short preamble" : "");
5052 printk(KERN_DEBUG "RxPHYStatus: %04x %04x %04x %04x\n",
5053 phystatus_0, phystatus_1, phystatus_2, phystatus_3);
5054 printk(KERN_DEBUG "RxMACStatus: %x %s\n", macstatus1, flagstr);
5055 printk(KERN_DEBUG "RXMACaggtype: %x\n",
5056 (macstatus2 & RXS_AGGTYPE_MASK));
5057 printk(KERN_DEBUG "RxTSFTime: %04x\n", rxh->RxTSFTime);
5059 #endif /* defined(BCMDBG) */
5062 int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len)
5066 char *endp = buf + SSID_FMT_BUF_LEN;
5068 if (ssid_len > IEEE80211_MAX_SSID_LEN)
5069 ssid_len = IEEE80211_MAX_SSID_LEN;
5071 for (i = 0; i < ssid_len; i++) {
5076 } else if (isprint((unsigned char) c)) {
5079 p += snprintf(p, (endp - p), "\\x%02X", c);
5085 return (int)(p - buf);
5087 #endif /* defined(BCMDBG) */
5089 u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate)
5091 return wlc_bmac_rate_shm_offset(wlc->hw, rate);
5094 /* Callback for device removed */
5097 * Attempts to queue a packet onto a multiple-precedence queue,
5098 * if necessary evicting a lower precedence packet from the queue.
5100 * 'prec' is the precedence number that has already been mapped
5101 * from the packet priority.
5103 * Returns true if packet consumed (queued), false if not.
5106 wlc_prec_enq(struct wlc_info *wlc, struct pktq *q, void *pkt, int prec)
5108 return wlc_prec_enq_head(wlc, q, pkt, prec, false);
5112 wlc_prec_enq_head(struct wlc_info *wlc, struct pktq *q, struct sk_buff *pkt,
5113 int prec, bool head)
5116 int eprec = -1; /* precedence to evict from */
5118 /* Determine precedence from which to evict packet, if any */
5119 if (pktq_pfull(q, prec))
5121 else if (pktq_full(q)) {
5122 p = pktq_peek_tail(q, &eprec);
5125 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5126 __func__, eprec, prec);
5131 /* Evict if needed */
5133 bool discard_oldest;
5135 /* Detect queueing to unconfigured precedence */
5136 ASSERT(!pktq_pempty(q, eprec));
5138 discard_oldest = AC_BITMAP_TST(wlc->wme_dp, eprec);
5140 /* Refuse newer packet unless configured to discard oldest */
5141 if (eprec == prec && !discard_oldest) {
5142 WL_ERROR("%s: No where to go, prec == %d\n",
5147 /* Evict packet according to discard policy */
5148 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
5152 /* Increment wme stats */
5153 if (WME_ENAB(wlc->pub)) {
5154 WLCNTINCR(wlc->pub->_wme_cnt->
5155 tx_failed[WME_PRIO2AC(p->priority)].packets);
5156 WLCNTADD(wlc->pub->_wme_cnt->
5157 tx_failed[WME_PRIO2AC(p->priority)].bytes,
5158 pkttotlen(wlc->osh, p));
5162 pkt_buf_free_skb(wlc->osh, p, true);
5163 wlc->pub->_cnt->txnobuf++;
5168 p = pktq_penq_head(q, prec, pkt);
5170 p = pktq_penq(q, prec, pkt);
5176 void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
5179 struct wlc_info *wlc = (struct wlc_info *) ctx;
5180 wlc_txq_info_t *qi = wlc->active_queue; /* Check me */
5181 struct pktq *q = &qi->q;
5184 prio = sdu->priority;
5186 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat);
5188 if (!wlc_prec_enq(wlc, q, sdu, prec)) {
5189 if (!EDCF_ENAB(wlc->pub)
5190 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
5191 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5194 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5195 pkt_buf_free_skb(wlc->osh, sdu, true);
5196 wlc->pub->_cnt->txnobuf++;
5199 /* Check if flow control needs to be turned on after enqueuing the packet
5200 * Don't turn on flow control if EDCF is enabled. Driver would make the decision on what
5201 * to drop instead of relying on stack to make the right decision
5203 if (!EDCF_ENAB(wlc->pub)
5204 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5205 if (pktq_len(q) >= wlc->pub->tunables->datahiwat) {
5206 wlc_txflowcontrol(wlc, qi, ON, ALLPRIO);
5208 } else if (wlc->pub->_priofc) {
5209 if (pktq_plen(q, wlc_prio2prec_map[prio]) >=
5210 wlc->pub->tunables->datahiwat) {
5211 wlc_txflowcontrol(wlc, qi, ON, prio);
5217 wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
5218 struct ieee80211_hw *hw)
5223 struct scb *scb = &global_scb;
5224 struct ieee80211_hdr *d11_header = (struct ieee80211_hdr *)(sdu->data);
5229 fc = ltoh16(d11_header->frame_control);
5230 type = (fc & IEEE80211_FCTL_FTYPE);
5232 /* 802.11 standard requires management traffic to go at highest priority */
5233 prio = (type == IEEE80211_FTYPE_DATA ? sdu->priority : MAXPRIO);
5234 fifo = prio2fifo[prio];
5236 ASSERT((uint) skb_headroom(sdu) >= TXOFF);
5237 ASSERT(!(sdu->next));
5238 ASSERT(!(sdu->prev));
5239 ASSERT(fifo < NFIFO);
5243 (wlc_d11hdrs_mac80211(wlc, hw, pkt, scb, 0, 1, fifo, 0, NULL, 0)))
5245 wlc_txq_enq(wlc, scb, pkt, WLC_PRIO_TO_PREC(prio));
5246 wlc_send_q(wlc, wlc->active_queue);
5248 wlc->pub->_cnt->ieee_tx++;
5252 void BCMFASTPATH wlc_send_q(struct wlc_info *wlc, wlc_txq_info_t *qi)
5254 struct sk_buff *pkt[DOT11_MAXNUMFRAGS];
5257 int err = 0, i, count;
5259 struct pktq *q = &qi->q;
5260 struct ieee80211_tx_info *tx_info;
5262 /* only do work for the active queue */
5263 if (qi != wlc->active_queue)
5271 prec_map = wlc->tx_prec_map;
5273 /* Send all the enq'd pkts that we can.
5274 * Dequeue packets with precedence with empty HW fifo only
5276 while (prec_map && (pkt[0] = pktq_mdeq(q, prec_map, &prec))) {
5277 tx_info = IEEE80211_SKB_CB(pkt[0]);
5278 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
5279 err = wlc_sendampdu(wlc->ampdu, qi, pkt, prec);
5282 err = wlc_prep_pdu(wlc, pkt[0], &fifo);
5284 for (i = 0; i < count; i++) {
5285 wlc_txfifo(wlc, fifo, pkt[i], true, 1);
5290 if (err == BCME_BUSY) {
5291 pktq_penq_head(q, prec, pkt[0]);
5292 /* If send failed due to any other reason than a change in
5293 * HW FIFO condition, quit. Otherwise, read the new prec_map!
5295 if (prec_map == wlc->tx_prec_map)
5297 prec_map = wlc->tx_prec_map;
5301 /* Check if flow control needs to be turned off after sending the packet */
5302 if (!EDCF_ENAB(wlc->pub)
5303 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) {
5304 if (wlc_txflowcontrol_prio_isset(wlc, qi, ALLPRIO)
5305 && (pktq_len(q) < wlc->pub->tunables->datahiwat / 2)) {
5306 wlc_txflowcontrol(wlc, qi, OFF, ALLPRIO);
5308 } else if (wlc->pub->_priofc) {
5310 for (prio = MAXPRIO; prio >= 0; prio--) {
5311 if (wlc_txflowcontrol_prio_isset(wlc, qi, prio) &&
5312 (pktq_plen(q, wlc_prio2prec_map[prio]) <
5313 wlc->pub->tunables->datahiwat / 2)) {
5314 wlc_txflowcontrol(wlc, qi, OFF, prio);
5322 * bcmc_fid_generate:
5323 * Generate frame ID for a BCMC packet. The frag field is not used
5324 * for MC frames so is used as part of the sequence number.
5327 bcmc_fid_generate(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh)
5331 frameid = ltoh16(txh->TxFrameID) & ~(TXFID_SEQ_MASK | TXFID_QUEUE_MASK);
5334 mc_fid_counter++) << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5341 wlc_txfifo(struct wlc_info *wlc, uint fifo, struct sk_buff *p, bool commit,
5344 u16 frameid = INVALIDFID;
5347 ASSERT(fifo < NFIFO);
5348 txh = (d11txh_t *) (p->data);
5350 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5351 * ucode or BSS info as appropriate.
5353 if (fifo == TX_BCMC_FIFO) {
5354 frameid = ltoh16(txh->TxFrameID);
5358 if (WLC_WAR16165(wlc))
5359 wlc_war16165(wlc, true);
5362 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5363 * in wlc_bmac_txfifo()
5366 TXPKTPENDINC(wlc, fifo, txpktpend);
5367 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5368 txpktpend, TXPKTPENDGET(wlc, fifo));
5371 /* Commit BCMC sequence number in the SHM frame ID location */
5372 if (frameid != INVALIDFID)
5373 BCMCFID(wlc, frameid);
5375 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
5376 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5381 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec, uint length)
5384 uint mac_rate = RSPEC2RATE(rspec);
5387 if (IS_MCS(rspec)) {
5388 /* not supported yet */
5390 } else if (IS_OFDM(rspec)) {
5391 /* nsyms = Ceiling(Nbits / (Nbits/sym))
5393 * Nbits = length * 8
5394 * Nbits/sym = Mbps * 4 = mac_rate * 2
5396 nsyms = CEIL((length * 8), (mac_rate * 2));
5398 /* usec = symbols * usec/symbol */
5399 usec = (u16) (nsyms * APHY_SYMBOL_TIME);
5410 usec = (length << 4) / 11;
5413 usec = (length << 3) / 11;
5416 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5417 wlc->pub->unit, rspec);
5418 ASSERT((const char *)"Bad phy_rate" == NULL);
5427 wlc_compute_plcp(struct wlc_info *wlc, ratespec_t rspec, uint length, u8 *plcp)
5429 if (IS_MCS(rspec)) {
5430 wlc_compute_mimo_plcp(rspec, length, plcp);
5431 } else if (IS_OFDM(rspec)) {
5432 wlc_compute_ofdm_plcp(rspec, length, plcp);
5434 wlc_compute_cck_plcp(rspec, length, plcp);
5439 /* Rate: 802.11 rate code, length: PSDU length in octets */
5440 static void wlc_compute_mimo_plcp(ratespec_t rspec, uint length, u8 *plcp)
5442 u8 mcs = (u8) (rspec & RSPEC_RATE_MASK);
5443 ASSERT(IS_MCS(rspec));
5445 if (RSPEC_IS40MHZ(rspec) || (mcs == 32))
5446 plcp[0] |= MIMO_PLCP_40MHZ;
5447 WLC_SET_MIMO_PLCP_LEN(plcp, length);
5448 plcp[3] = RSPEC_MIMOPLCP3(rspec); /* rspec already holds this byte */
5449 plcp[3] |= 0x7; /* set smoothing, not sounding ppdu & reserved */
5450 plcp[4] = 0; /* number of extension spatial streams bit 0 & 1 */
5454 /* Rate: 802.11 rate code, length: PSDU length in octets */
5455 static void BCMFASTPATH
5456 wlc_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp)
5460 int rate = RSPEC2RATE(rspec);
5462 ASSERT(IS_OFDM(rspec));
5464 /* encode rate per 802.11a-1999 sec 17.3.4.1, with lsb transmitted first */
5465 rate_signal = rate_info[rate] & RATE_MASK;
5466 ASSERT(rate_signal != 0);
5468 memset(plcp, 0, D11_PHY_HDR_LEN);
5469 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal);
5471 tmp = (length & 0xfff) << 5;
5472 plcp[2] |= (tmp >> 16) & 0xff;
5473 plcp[1] |= (tmp >> 8) & 0xff;
5474 plcp[0] |= tmp & 0xff;
5480 * Compute PLCP, but only requires actual rate and length of pkt.
5481 * Rate is given in the driver standard multiple of 500 kbps.
5482 * le is set for 11 Mbps rate if necessary.
5483 * Broken out for PRQ.
5486 static void wlc_cck_plcp_set(int rate_500, uint length, u8 *plcp)
5499 usec = (length << 4) / 11;
5500 if ((length << 4) - (usec * 11) > 0)
5504 usec = (length << 3) / 11;
5505 if ((length << 3) - (usec * 11) > 0) {
5507 if ((usec * 11) - (length << 3) >= 8)
5508 le = D11B_PLCP_SIGNAL_LE;
5513 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500);
5514 rate_500 = WLC_RATE_1M;
5518 /* PLCP signal byte */
5519 plcp[0] = rate_500 * 5; /* r (500kbps) * 5 == r (100kbps) */
5520 /* PLCP service byte */
5521 plcp[1] = (u8) (le | D11B_PLCP_SIGNAL_LOCKED);
5522 /* PLCP length u16, little endian */
5523 plcp[2] = usec & 0xff;
5524 plcp[3] = (usec >> 8) & 0xff;
5530 /* Rate: 802.11 rate code, length: PSDU length in octets */
5531 static void wlc_compute_cck_plcp(ratespec_t rspec, uint length, u8 *plcp)
5533 int rate = RSPEC2RATE(rspec);
5535 ASSERT(IS_CCK(rspec));
5537 wlc_cck_plcp_set(rate, length, plcp);
5540 /* wlc_compute_frame_dur()
5542 * Calculate the 802.11 MAC header DUR field for MPDU
5543 * DUR for a single frame = 1 SIFS + 1 ACK
5544 * DUR for a frame with following frags = 3 SIFS + 2 ACK + next frag time
5546 * rate MPDU rate in unit of 500kbps
5547 * next_frag_len next MPDU length in bytes
5548 * preamble_type use short/GF or long/MM PLCP header
5550 static u16 BCMFASTPATH
5551 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate, u8 preamble_type,
5556 sifs = SIFS(wlc->band);
5559 dur += (u16) wlc_calc_ack_time(wlc, rate, preamble_type);
5561 if (next_frag_len) {
5562 /* Double the current DUR to get 2 SIFS + 2 ACKs */
5564 /* add another SIFS and the frag time */
5567 (u16) wlc_calc_frame_time(wlc, rate, preamble_type,
5573 /* wlc_compute_rtscts_dur()
5575 * Calculate the 802.11 MAC header DUR field for an RTS or CTS frame
5576 * DUR for normal RTS/CTS w/ frame = 3 SIFS + 1 CTS + next frame time + 1 ACK
5577 * DUR for CTS-TO-SELF w/ frame = 2 SIFS + next frame time + 1 ACK
5579 * cts cts-to-self or rts/cts
5580 * rts_rate rts or cts rate in unit of 500kbps
5581 * rate next MPDU rate in unit of 500kbps
5582 * frame_len next MPDU frame length in bytes
5585 wlc_compute_rtscts_dur(struct wlc_info *wlc, bool cts_only, ratespec_t rts_rate,
5586 ratespec_t frame_rate, u8 rts_preamble_type,
5587 u8 frame_preamble_type, uint frame_len, bool ba)
5591 sifs = SIFS(wlc->band);
5593 if (!cts_only) { /* RTS/CTS */
5596 (u16) wlc_calc_cts_time(wlc, rts_rate,
5598 } else { /* CTS-TO-SELF */
5603 (u16) wlc_calc_frame_time(wlc, frame_rate, frame_preamble_type,
5607 (u16) wlc_calc_ba_time(wlc, frame_rate,
5608 WLC_SHORT_PREAMBLE);
5611 (u16) wlc_calc_ack_time(wlc, frame_rate,
5612 frame_preamble_type);
5616 static bool wlc_phy_rspec_check(struct wlc_info *wlc, u16 bw, ratespec_t rspec)
5618 if (IS_MCS(rspec)) {
5619 uint mcs = rspec & RSPEC_RATE_MASK;
5622 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5623 } else if ((mcs >= 8) && (mcs <= 23)) {
5624 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SDM);
5625 } else if (mcs == 32) {
5626 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_SDM);
5627 ASSERT(bw == PHY_TXC1_BW_40MHZ_DUP);
5629 } else if (IS_OFDM(rspec)) {
5630 ASSERT(RSPEC_STF(rspec) < PHY_TXC1_MODE_STBC);
5632 ASSERT(IS_CCK(rspec));
5634 ASSERT((bw == PHY_TXC1_BW_20MHZ)
5635 || (bw == PHY_TXC1_BW_20MHZ_UP));
5636 ASSERT(RSPEC_STF(rspec) == PHY_TXC1_MODE_SISO);
5642 u16 BCMFASTPATH wlc_phytxctl1_calc(struct wlc_info *wlc, ratespec_t rspec)
5647 if (WLCISLCNPHY(wlc->band)) {
5648 bw = PHY_TXC1_BW_20MHZ;
5650 bw = RSPEC_GET_BW(rspec);
5651 /* 10Mhz is not supported yet */
5652 if (bw < PHY_TXC1_BW_20MHZ) {
5653 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5655 bw = PHY_TXC1_BW_20MHZ;
5658 wlc_phy_rspec_check(wlc, bw, rspec);
5661 if (IS_MCS(rspec)) {
5662 uint mcs = rspec & RSPEC_RATE_MASK;
5664 /* bw, stf, coding-type is part of RSPEC_PHYTXBYTE2 returns */
5665 phyctl1 = RSPEC_PHYTXBYTE2(rspec);
5666 /* set the upper byte of phyctl1 */
5667 phyctl1 |= (mcs_table[mcs].tx_phy_ctl3 << 8);
5668 } else if (IS_CCK(rspec) && !WLCISLCNPHY(wlc->band)
5669 && !WLCISSSLPNPHY(wlc->band)) {
5670 /* In CCK mode LPPHY overloads OFDM Modulation bits with CCK Data Rate */
5671 /* Eventually MIMOPHY would also be converted to this format */
5672 /* 0 = 1Mbps; 1 = 2Mbps; 2 = 5.5Mbps; 3 = 11Mbps */
5673 phyctl1 = (bw | (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5674 } else { /* legacy OFDM/CCK */
5676 /* get the phyctl byte from rate phycfg table */
5677 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec));
5679 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5683 /* set the upper byte of phyctl1 */
5685 (bw | (phycfg << 8) |
5686 (RSPEC_STF(rspec) << PHY_TXC1_MODE_SHIFT));
5690 /* phy clock must support 40Mhz if tx descriptor uses it */
5691 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) {
5692 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ);
5693 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi));
5699 ratespec_t BCMFASTPATH
5700 wlc_rspec_to_rts_rspec(struct wlc_info *wlc, ratespec_t rspec, bool use_rspec,
5703 ratespec_t rts_rspec = 0;
5706 /* use frame rate as rts rate */
5709 } else if (wlc->band->gmode && wlc->protection->_g && !IS_CCK(rspec)) {
5710 /* Use 11Mbps as the g protection RTS target rate and fallback.
5711 * Use the WLC_BASIC_RATE() lookup to find the best basic rate under the
5712 * target in case 11 Mbps is not Basic.
5713 * 6 and 9 Mbps are not usually selected by rate selection, but even
5714 * if the OFDM rate we are protecting is 6 or 9 Mbps, 11 is more robust.
5716 rts_rspec = WLC_BASIC_RATE(wlc, WLC_RATE_11M);
5718 /* calculate RTS rate and fallback rate based on the frame rate
5719 * RTS must be sent at a basic rate since it is a
5720 * control frame, sec 9.6 of 802.11 spec
5722 rts_rspec = WLC_BASIC_RATE(wlc, rspec);
5725 if (WLC_PHY_11N_CAP(wlc->band)) {
5726 /* set rts txbw to correct side band */
5727 rts_rspec &= ~RSPEC_BW_MASK;
5729 /* if rspec/rspec_fallback is 40MHz, then send RTS on both 20MHz channel
5730 * (DUP), otherwise send RTS on control channel
5732 if (RSPEC_IS40MHZ(rspec) && !IS_CCK(rts_rspec))
5733 rts_rspec |= (PHY_TXC1_BW_40MHZ_DUP << RSPEC_BW_SHIFT);
5735 rts_rspec |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
5737 /* pick siso/cdd as default for ofdm */
5738 if (IS_OFDM(rts_rspec)) {
5739 rts_rspec &= ~RSPEC_STF_MASK;
5740 rts_rspec |= (wlc->stf->ss_opmode << RSPEC_STF_SHIFT);
5747 * Add d11txh_t, cck_phy_hdr_t.
5749 * 'p' data must start with 802.11 MAC header
5750 * 'p' must allow enough bytes of local headers to be "pushed" onto the packet
5752 * headroom == D11_PHY_HDR_LEN + D11_TXH_LEN (D11_TXH_LEN is now 104 bytes)
5755 static u16 BCMFASTPATH
5756 wlc_d11hdrs_mac80211(struct wlc_info *wlc, struct ieee80211_hw *hw,
5757 struct sk_buff *p, struct scb *scb, uint frag,
5758 uint nfrags, uint queue, uint next_frag_len,
5759 wsec_key_t *key, ratespec_t rspec_override)
5761 struct ieee80211_hdr *h;
5763 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
5764 struct osl_info *osh;
5765 int len, phylen, rts_phylen;
5766 u16 fc, type, frameid, mch, phyctl, xfts, mainrates;
5767 u16 seq = 0, mcl = 0, status = 0;
5768 ratespec_t rspec[2] = { WLC_RATE_1M, WLC_RATE_1M }, rts_rspec[2] = {
5769 WLC_RATE_1M, WLC_RATE_1M};
5770 bool use_rts = false;
5771 bool use_cts = false;
5772 bool use_rifs = false;
5773 bool short_preamble[2] = { false, false };
5774 u8 preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5775 u8 rts_preamble_type[2] = { WLC_LONG_PREAMBLE, WLC_LONG_PREAMBLE };
5776 u8 *rts_plcp, rts_plcp_fallback[D11_PHY_HDR_LEN];
5777 struct ieee80211_rts *rts = NULL;
5781 bool hwtkmic = false;
5782 u16 mimo_ctlchbw = PHY_TXC1_BW_20MHZ;
5784 #define ANTCFG_NONE 0xFF
5785 u8 antcfg = ANTCFG_NONE;
5786 u8 fbantcfg = ANTCFG_NONE;
5788 uint phyctl1_stf = 0;
5790 struct ieee80211_tx_rate *txrate[2];
5792 struct ieee80211_tx_info *tx_info;
5795 u8 mimo_preamble_type;
5799 ASSERT(queue < NFIFO);
5803 /* locate 802.11 MAC header */
5804 h = (struct ieee80211_hdr *)(p->data);
5805 fc = ltoh16(h->frame_control);
5806 type = (fc & IEEE80211_FCTL_FTYPE);
5808 qos = (type == IEEE80211_FTYPE_DATA &&
5809 FC_SUBTYPE_ANY_QOS(fc));
5811 /* compute length of frame in bytes for use in PLCP computations */
5812 len = pkttotlen(osh, p);
5813 phylen = len + FCS_LEN;
5815 /* If WEP enabled, add room in phylen for the additional bytes of
5816 * ICV which MAC generates. We do NOT add the additional bytes to
5817 * the packet itself, thus phylen = packet length + ICV_LEN + FCS_LEN
5821 phylen += key->icv_len;
5825 tx_info = IEEE80211_SKB_CB(p);
5829 plcp = skb_push(p, D11_PHY_HDR_LEN);
5831 /* add Broadcom tx descriptor header */
5832 txh = (d11txh_t *) skb_push(p, D11_TXH_LEN);
5833 memset(txh, 0, D11_TXH_LEN);
5836 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
5837 /* non-AP STA should never use BCMC queue */
5838 ASSERT(queue != TX_BCMC_FIFO);
5839 if (queue == TX_BCMC_FIFO) {
5840 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5841 WLCWLUNIT(wlc), __func__);
5842 frameid = bcmc_fid_generate(wlc, NULL, txh);
5844 /* Increment the counter for first fragment */
5845 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
5846 SCB_SEQNUM(scb, p->priority)++;
5849 /* extract fragment number from frame first */
5850 seq = ltoh16(seq) & FRAGNUM_MASK;
5851 seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT);
5852 h->seq_ctrl = htol16(seq);
5854 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
5855 (queue & TXFID_QUEUE_MASK);
5858 frameid |= queue & TXFID_QUEUE_MASK;
5860 /* set the ignpmq bit for all pkts tx'd in PS mode and for beacons */
5861 if (SCB_PS(scb) || ((fc & FC_KIND_MASK) == FC_BEACON))
5862 mcl |= TXC_IGNOREPMQ;
5864 ASSERT(hw->max_rates <= IEEE80211_TX_MAX_RATES);
5865 ASSERT(hw->max_rates == 2);
5867 txrate[0] = tx_info->control.rates;
5868 txrate[1] = txrate[0] + 1;
5870 ASSERT(txrate[0]->idx >= 0);
5871 /* if rate control algorithm didn't give us a fallback rate, use the primary rate */
5872 if (txrate[1]->idx < 0) {
5873 txrate[1] = txrate[0];
5876 for (k = 0; k < hw->max_rates; k++) {
5878 txrate[k]->flags & IEEE80211_TX_RC_MCS ? true : false;
5880 ASSERT(!(tx_info->flags & IEEE80211_TX_CTL_AMPDU));
5881 if ((txrate[k]->idx >= 0)
5882 && (txrate[k]->idx <
5883 hw->wiphy->bands[tx_info->band]->n_bitrates)) {
5885 hw->wiphy->bands[tx_info->band]->
5886 bitrates[txrate[k]->idx].hw_value;
5889 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE ?
5892 ASSERT((txrate[k]->idx >= 0) &&
5894 hw->wiphy->bands[tx_info->band]->
5896 rate_val[k] = WLC_RATE_1M;
5899 rate_val[k] = txrate[k]->idx;
5901 /* Currently only support same setting for primay and fallback rates.
5902 * Unify flags for each rate into a single value for the frame
5906 flags & IEEE80211_TX_RC_USE_RTS_CTS ? true : false;
5909 flags & IEEE80211_TX_RC_USE_CTS_PROTECT ? true : false;
5912 rate_val[k] |= NRATE_MCS_INUSE;
5914 rspec[k] = mac80211_wlc_set_nrate(wlc, wlc->band, rate_val[k]);
5916 /* (1) RATE: determine and validate primary rate and fallback rates */
5917 if (!RSPEC_ACTIVE(rspec[k])) {
5918 ASSERT(RSPEC_ACTIVE(rspec[k]));
5919 rspec[k] = WLC_RATE_1M;
5921 if (WLANTSEL_ENAB(wlc) &&
5922 !is_multicast_ether_addr(h->addr1)) {
5923 /* set tx antenna config */
5924 wlc_antsel_antcfg_get(wlc->asi, false, false, 0,
5925 0, &antcfg, &fbantcfg);
5930 phyctl1_stf = wlc->stf->ss_opmode;
5932 if (N_ENAB(wlc->pub)) {
5933 for (k = 0; k < hw->max_rates; k++) {
5934 /* apply siso/cdd to single stream mcs's or ofdm if rspec is auto selected */
5935 if (((IS_MCS(rspec[k]) &&
5936 IS_SINGLE_STREAM(rspec[k] & RSPEC_RATE_MASK)) ||
5938 && ((rspec[k] & RSPEC_OVERRIDE_MCS_ONLY)
5939 || !(rspec[k] & RSPEC_OVERRIDE))) {
5940 rspec[k] &= ~(RSPEC_STF_MASK | RSPEC_STC_MASK);
5942 /* For SISO MCS use STBC if possible */
5943 if (IS_MCS(rspec[k])
5944 && WLC_STF_SS_STBC_TX(wlc, scb)) {
5947 ASSERT(WLC_STBC_CAP_PHY(wlc));
5948 stc = 1; /* Nss for single stream is always 1 */
5950 (PHY_TXC1_MODE_STBC <<
5951 RSPEC_STF_SHIFT) | (stc <<
5955 (phyctl1_stf << RSPEC_STF_SHIFT);
5958 /* Is the phy configured to use 40MHZ frames? If so then pick the desired txbw */
5959 if (CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ) {
5960 /* default txbw is 20in40 SB */
5961 mimo_ctlchbw = mimo_txbw =
5962 CHSPEC_SB_UPPER(WLC_BAND_PI_RADIO_CHANSPEC)
5963 ? PHY_TXC1_BW_20MHZ_UP : PHY_TXC1_BW_20MHZ;
5965 if (IS_MCS(rspec[k])) {
5966 /* mcs 32 must be 40b/w DUP */
5967 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5969 PHY_TXC1_BW_40MHZ_DUP;
5971 } else if (wlc->mimo_40txbw != AUTO)
5972 mimo_txbw = wlc->mimo_40txbw;
5973 /* else check if dst is using 40 Mhz */
5974 else if (scb->flags & SCB_IS40)
5975 mimo_txbw = PHY_TXC1_BW_40MHZ;
5976 } else if (IS_OFDM(rspec[k])) {
5977 if (wlc->ofdm_40txbw != AUTO)
5978 mimo_txbw = wlc->ofdm_40txbw;
5980 ASSERT(IS_CCK(rspec[k]));
5981 if (wlc->cck_40txbw != AUTO)
5982 mimo_txbw = wlc->cck_40txbw;
5985 /* mcs32 is 40 b/w only.
5986 * This is possible for probe packets on a STA during SCAN
5988 if ((rspec[k] & RSPEC_RATE_MASK) == 32) {
5990 rspec[k] = RSPEC_MIMORATE;
5992 mimo_txbw = PHY_TXC1_BW_20MHZ;
5995 /* Set channel width */
5996 rspec[k] &= ~RSPEC_BW_MASK;
5997 if ((k == 0) || ((k > 0) && IS_MCS(rspec[k])))
5998 rspec[k] |= (mimo_txbw << RSPEC_BW_SHIFT);
6000 rspec[k] |= (mimo_ctlchbw << RSPEC_BW_SHIFT);
6004 if (IS_MCS(rspec[k])
6005 && (txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
6006 rspec[k] |= RSPEC_SHORT_GI;
6007 else if (!(txrate[k]->flags & IEEE80211_TX_RC_SHORT_GI))
6008 rspec[k] &= ~RSPEC_SHORT_GI;
6010 rspec[k] &= ~RSPEC_SHORT_GI;
6013 mimo_preamble_type = WLC_MM_PREAMBLE;
6014 if (txrate[k]->flags & IEEE80211_TX_RC_GREEN_FIELD)
6015 mimo_preamble_type = WLC_GF_PREAMBLE;
6017 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
6018 && (!IS_MCS(rspec[k]))) {
6019 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
6020 WLCWLUNIT(wlc), __func__);
6021 ASSERT(0 && "Rate mismatch");
6024 if (IS_MCS(rspec[k])) {
6025 preamble_type[k] = mimo_preamble_type;
6027 /* if SGI is selected, then forced mm for single stream */
6028 if ((rspec[k] & RSPEC_SHORT_GI)
6029 && IS_SINGLE_STREAM(rspec[k] &
6031 preamble_type[k] = WLC_MM_PREAMBLE;
6035 /* mimo bw field MUST now be valid in the rspec (it affects duration calculations) */
6036 ASSERT(VALID_RATE_DBG(wlc, rspec[0]));
6038 /* should be better conditionalized */
6039 if (!IS_MCS(rspec[0])
6040 && (tx_info->control.rates[0].
6041 flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE))
6042 preamble_type[k] = WLC_SHORT_PREAMBLE;
6044 ASSERT(!IS_MCS(rspec[0])
6045 || WLC_IS_MIMO_PREAMBLE(preamble_type[k]));
6048 for (k = 0; k < hw->max_rates; k++) {
6049 /* Set ctrlchbw as 20Mhz */
6050 ASSERT(!IS_MCS(rspec[k]));
6051 rspec[k] &= ~RSPEC_BW_MASK;
6052 rspec[k] |= (PHY_TXC1_BW_20MHZ << RSPEC_BW_SHIFT);
6054 /* for nphy, stf of ofdm frames must follow policies */
6055 if (WLCISNPHY(wlc->band) && IS_OFDM(rspec[k])) {
6056 rspec[k] &= ~RSPEC_STF_MASK;
6057 rspec[k] |= phyctl1_stf << RSPEC_STF_SHIFT;
6062 /* Reset these for use with AMPDU's */
6063 txrate[0]->count = 0;
6064 txrate[1]->count = 0;
6066 /* (2) PROTECTION, may change rspec */
6067 if ((ieee80211_is_data(fc) || ieee80211_is_mgmt(fc)) &&
6068 (phylen > wlc->RTSThresh) && !is_multicast_ether_addr(h->addr1))
6071 /* (3) PLCP: determine PLCP header and MAC duration, fill d11txh_t */
6072 wlc_compute_plcp(wlc, rspec[0], phylen, plcp);
6073 wlc_compute_plcp(wlc, rspec[1], phylen, plcp_fallback);
6074 bcopy(plcp_fallback, (char *)&txh->FragPLCPFallback,
6075 sizeof(txh->FragPLCPFallback));
6077 /* Length field now put in CCK FBR CRC field */
6078 if (IS_CCK(rspec[1])) {
6079 txh->FragPLCPFallback[4] = phylen & 0xff;
6080 txh->FragPLCPFallback[5] = (phylen & 0xff00) >> 8;
6083 /* MIMO-RATE: need validation ?? */
6085 IS_OFDM(rspec[0]) ? D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) plcp) :
6088 /* DUR field for main rate */
6089 if ((fc != FC_PS_POLL) &&
6090 !is_multicast_ether_addr(h->addr1) && !use_rifs) {
6092 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0],
6094 h->duration_id = htol16(durid);
6095 } else if (use_rifs) {
6096 /* NAV protect to end of next max packet size */
6098 (u16) wlc_calc_frame_time(wlc, rspec[0],
6100 DOT11_MAX_FRAG_LEN);
6101 durid += RIFS_11N_TIME;
6102 h->duration_id = htol16(durid);
6105 /* DUR field for fallback rate */
6106 if (fc == FC_PS_POLL)
6107 txh->FragDurFallback = h->duration_id;
6108 else if (is_multicast_ether_addr(h->addr1) || use_rifs)
6109 txh->FragDurFallback = 0;
6111 durid = wlc_compute_frame_dur(wlc, rspec[1],
6112 preamble_type[1], next_frag_len);
6113 txh->FragDurFallback = htol16(durid);
6116 /* (4) MAC-HDR: MacTxControlLow */
6118 mcl |= TXC_STARTMSDU;
6120 if (!is_multicast_ether_addr(h->addr1))
6121 mcl |= TXC_IMMEDACK;
6123 if (BAND_5G(wlc->band->bandtype))
6124 mcl |= TXC_FREQBAND_5G;
6126 if (CHSPEC_IS40(WLC_BAND_PI_RADIO_CHANSPEC))
6129 /* set AMIC bit if using hardware TKIP MIC */
6133 txh->MacTxControlLow = htol16(mcl);
6135 /* MacTxControlHigh */
6138 /* Set fallback rate preamble type */
6139 if ((preamble_type[1] == WLC_SHORT_PREAMBLE) ||
6140 (preamble_type[1] == WLC_GF_PREAMBLE)) {
6141 ASSERT((preamble_type[1] == WLC_GF_PREAMBLE) ||
6142 (!IS_MCS(rspec[1])));
6143 if (RSPEC2RATE(rspec[1]) != WLC_RATE_1M)
6144 mch |= TXC_PREAMBLE_DATA_FB_SHORT;
6147 /* MacFrameControl */
6148 bcopy((char *)&h->frame_control, (char *)&txh->MacFrameControl,
6150 txh->TxFesTimeNormal = htol16(0);
6152 txh->TxFesTimeFallback = htol16(0);
6155 bcopy((char *)&h->addr1, (char *)&txh->TxFrameRA, ETH_ALEN);
6158 txh->TxFrameID = htol16(frameid);
6160 /* TxStatus, Note the case of recreating the first frag of a suppressed frame
6161 * then we may need to reset the retry cnt's via the status reg
6163 txh->TxStatus = htol16(status);
6165 if (D11REV_GE(wlc->pub->corerev, 16)) {
6166 /* extra fields for ucode AMPDU aggregation, the new fields are added to
6167 * the END of previous structure so that it's compatible in driver.
6168 * In old rev ucode, these fields should be ignored
6170 txh->MaxNMpdus = htol16(0);
6171 txh->MaxABytes_MRT = htol16(0);
6172 txh->MaxABytes_FBR = htol16(0);
6173 txh->MinMBytes = htol16(0);
6176 /* (5) RTS/CTS: determine RTS/CTS PLCP header and MAC duration, furnish d11txh_t */
6177 /* RTS PLCP header and RTS frame */
6178 if (use_rts || use_cts) {
6179 if (use_rts && use_cts)
6182 for (k = 0; k < 2; k++) {
6183 rts_rspec[k] = wlc_rspec_to_rts_rspec(wlc, rspec[k],
6188 if (!IS_OFDM(rts_rspec[0]) &&
6189 !((RSPEC2RATE(rts_rspec[0]) == WLC_RATE_1M) ||
6190 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6191 rts_preamble_type[0] = WLC_SHORT_PREAMBLE;
6192 mch |= TXC_PREAMBLE_RTS_MAIN_SHORT;
6195 if (!IS_OFDM(rts_rspec[1]) &&
6196 !((RSPEC2RATE(rts_rspec[1]) == WLC_RATE_1M) ||
6197 (wlc->PLCPHdr_override == WLC_PLCP_LONG))) {
6198 rts_preamble_type[1] = WLC_SHORT_PREAMBLE;
6199 mch |= TXC_PREAMBLE_RTS_FB_SHORT;
6202 /* RTS/CTS additions to MacTxControlLow */
6204 txh->MacTxControlLow |= htol16(TXC_SENDCTS);
6206 txh->MacTxControlLow |= htol16(TXC_SENDRTS);
6207 txh->MacTxControlLow |= htol16(TXC_LONGFRAME);
6210 /* RTS PLCP header */
6211 ASSERT(IS_ALIGNED((unsigned long)txh->RTSPhyHeader, sizeof(u16)));
6212 rts_plcp = txh->RTSPhyHeader;
6214 rts_phylen = DOT11_CTS_LEN + FCS_LEN;
6216 rts_phylen = DOT11_RTS_LEN + FCS_LEN;
6218 wlc_compute_plcp(wlc, rts_rspec[0], rts_phylen, rts_plcp);
6220 /* fallback rate version of RTS PLCP header */
6221 wlc_compute_plcp(wlc, rts_rspec[1], rts_phylen,
6223 bcopy(rts_plcp_fallback, (char *)&txh->RTSPLCPFallback,
6224 sizeof(txh->RTSPLCPFallback));
6226 /* RTS frame fields... */
6227 rts = (struct ieee80211_rts *)&txh->rts_frame;
6229 durid = wlc_compute_rtscts_dur(wlc, use_cts, rts_rspec[0],
6230 rspec[0], rts_preamble_type[0],
6231 preamble_type[0], phylen, false);
6232 rts->duration = htol16(durid);
6233 /* fallback rate version of RTS DUR field */
6234 durid = wlc_compute_rtscts_dur(wlc, use_cts,
6235 rts_rspec[1], rspec[1],
6236 rts_preamble_type[1],
6237 preamble_type[1], phylen, false);
6238 txh->RTSDurFallback = htol16(durid);
6241 rts->frame_control = htol16(FC_CTS);
6242 bcopy((char *)&h->addr2, (char *)&rts->ra, ETH_ALEN);
6244 rts->frame_control = htol16((u16) FC_RTS);
6245 bcopy((char *)&h->addr1, (char *)&rts->ra,
6250 * low 8 bits: main frag rate/mcs,
6251 * high 8 bits: rts/cts rate/mcs
6253 mainrates |= (IS_OFDM(rts_rspec[0]) ?
6254 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) :
6257 memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN);
6258 memset((char *)&txh->rts_frame, 0,
6259 sizeof(struct ieee80211_rts));
6260 memset((char *)txh->RTSPLCPFallback, 0,
6261 sizeof(txh->RTSPLCPFallback));
6262 txh->RTSDurFallback = 0;
6265 #ifdef SUPPORT_40MHZ
6266 /* add null delimiter count */
6267 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && IS_MCS(rspec)) {
6268 txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM] =
6269 wlc_ampdu_null_delim_cnt(wlc->ampdu, scb, rspec, phylen);
6273 /* Now that RTS/RTS FB preamble types are updated, write the final value */
6274 txh->MacTxControlHigh = htol16(mch);
6276 /* MainRates (both the rts and frag plcp rates have been calculated now) */
6277 txh->MainRates = htol16(mainrates);
6279 /* XtraFrameTypes */
6280 xfts = FRAMETYPE(rspec[1], wlc->mimoft);
6281 xfts |= (FRAMETYPE(rts_rspec[0], wlc->mimoft) << XFTS_RTS_FT_SHIFT);
6282 xfts |= (FRAMETYPE(rts_rspec[1], wlc->mimoft) << XFTS_FBRRTS_FT_SHIFT);
6284 CHSPEC_CHANNEL(WLC_BAND_PI_RADIO_CHANSPEC) << XFTS_CHANNEL_SHIFT;
6285 txh->XtraFrameTypes = htol16(xfts);
6287 /* PhyTxControlWord */
6288 phyctl = FRAMETYPE(rspec[0], wlc->mimoft);
6289 if ((preamble_type[0] == WLC_SHORT_PREAMBLE) ||
6290 (preamble_type[0] == WLC_GF_PREAMBLE)) {
6291 ASSERT((preamble_type[0] == WLC_GF_PREAMBLE)
6292 || !IS_MCS(rspec[0]));
6293 if (RSPEC2RATE(rspec[0]) != WLC_RATE_1M)
6294 phyctl |= PHY_TXC_SHORT_HDR;
6295 wlc->pub->_cnt->txprshort++;
6298 /* phytxant is properly bit shifted */
6299 phyctl |= wlc_stf_d11hdrs_phyctl_txant(wlc, rspec[0]);
6300 txh->PhyTxControlWord = htol16(phyctl);
6302 /* PhyTxControlWord_1 */
6303 if (WLC_PHY_11N_CAP(wlc->band)) {
6306 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[0]);
6307 txh->PhyTxControlWord_1 = htol16(phyctl1);
6308 phyctl1 = wlc_phytxctl1_calc(wlc, rspec[1]);
6309 txh->PhyTxControlWord_1_Fbr = htol16(phyctl1);
6311 if (use_rts || use_cts) {
6312 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[0]);
6313 txh->PhyTxControlWord_1_Rts = htol16(phyctl1);
6314 phyctl1 = wlc_phytxctl1_calc(wlc, rts_rspec[1]);
6315 txh->PhyTxControlWord_1_FbrRts = htol16(phyctl1);
6319 * For mcs frames, if mixedmode(overloaded with long preamble) is going to be set,
6320 * fill in non-zero MModeLen and/or MModeFbrLen
6321 * it will be unnecessary if they are separated
6323 if (IS_MCS(rspec[0]) && (preamble_type[0] == WLC_MM_PREAMBLE)) {
6325 wlc_calc_lsig_len(wlc, rspec[0], phylen);
6326 txh->MModeLen = htol16(mmodelen);
6329 if (IS_MCS(rspec[1]) && (preamble_type[1] == WLC_MM_PREAMBLE)) {
6331 wlc_calc_lsig_len(wlc, rspec[1], phylen);
6332 txh->MModeFbrLen = htol16(mmodefbrlen);
6336 if (IS_MCS(rspec[0]))
6337 ASSERT(IS_MCS(rspec[1]));
6339 ASSERT(!IS_MCS(rspec[0]) ||
6340 ((preamble_type[0] == WLC_MM_PREAMBLE) == (txh->MModeLen != 0)));
6341 ASSERT(!IS_MCS(rspec[1]) ||
6342 ((preamble_type[1] == WLC_MM_PREAMBLE) ==
6343 (txh->MModeFbrLen != 0)));
6345 ac = wme_fifo2ac[queue];
6346 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
6347 uint frag_dur, dur, dur_fallback;
6349 ASSERT(!is_multicast_ether_addr(h->addr1));
6351 /* WME: Update TXOP threshold */
6352 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
6354 wlc_calc_frame_time(wlc, rspec[0], preamble_type[0],
6358 /* 1 RTS or CTS-to-self frame */
6360 wlc_calc_cts_time(wlc, rts_rspec[0],
6361 rts_preamble_type[0]);
6363 wlc_calc_cts_time(wlc, rts_rspec[1],
6364 rts_preamble_type[1]);
6365 /* (SIFS + CTS) + SIFS + frame + SIFS + ACK */
6366 dur += ltoh16(rts->duration);
6367 dur_fallback += ltoh16(txh->RTSDurFallback);
6368 } else if (use_rifs) {
6372 /* frame + SIFS + ACK */
6375 wlc_compute_frame_dur(wlc, rspec[0],
6376 preamble_type[0], 0);
6379 wlc_calc_frame_time(wlc, rspec[1],
6383 wlc_compute_frame_dur(wlc, rspec[1],
6384 preamble_type[1], 0);
6386 /* NEED to set TxFesTimeNormal (hard) */
6387 txh->TxFesTimeNormal = htol16((u16) dur);
6388 /* NEED to set fallback rate version of TxFesTimeNormal (hard) */
6389 txh->TxFesTimeFallback = htol16((u16) dur_fallback);
6391 /* update txop byte threshold (txop minus intraframe overhead) */
6392 if (wlc->edcf_txop[ac] >= (dur - frag_dur)) {
6397 wlc_calc_frame_len(wlc, rspec[0],
6403 /* range bound the fragthreshold */
6404 if (newfragthresh < DOT11_MIN_FRAG_LEN)
6407 else if (newfragthresh >
6408 wlc->usr_fragthresh)
6410 wlc->usr_fragthresh;
6411 /* update the fragthresh and do txc update */
6412 if (wlc->fragthresh[queue] !=
6413 (u16) newfragthresh) {
6414 wlc->fragthresh[queue] =
6415 (u16) newfragthresh;
6419 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6420 wlc->pub->unit, fifo_names[queue],
6421 RSPEC2RATE(rspec[0]));
6423 if (dur > wlc->edcf_txop[ac])
6424 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6425 wlc->pub->unit, __func__,
6427 phylen, wlc->fragthresh[queue],
6428 dur, wlc->edcf_txop[ac]);
6435 void wlc_tbtt(struct wlc_info *wlc, d11regs_t *regs)
6437 wlc_bsscfg_t *cfg = wlc->cfg;
6439 wlc->pub->_cnt->tbtt++;
6441 if (BSSCFG_STA(cfg)) {
6442 /* run watchdog here if the watchdog timer is not armed */
6443 if (WLC_WATCHDOG_TBTT(wlc)) {
6446 wl_del_timer(wlc->wl, wlc->wdtimer);
6447 wlc->WDarmed = false;
6450 cur = OSL_SYSUPTIME();
6451 delta = cur > wlc->WDlast ? cur - wlc->WDlast :
6452 (u32) ~0 - wlc->WDlast + cur + 1;
6453 if (delta >= TIMER_INTERVAL_WATCHDOG) {
6454 wlc_watchdog((void *)wlc);
6458 wl_add_timer(wlc->wl, wlc->wdtimer,
6459 wlc_watchdog_backup_bi(wlc), true);
6460 wlc->WDarmed = true;
6465 /* DirFrmQ is now valid...defer setting until end of ATIM window */
6466 wlc->qvalid |= MCMD_DIRFRMQVAL;
6470 /* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6471 void wlc_hwtimer_gptimer_set(struct wlc_info *wlc, uint us)
6473 ASSERT(wlc->pub->corerev >= 3); /* no gptimer in earlier revs */
6474 W_REG(wlc->osh, &wlc->regs->gptimer, us);
6477 void wlc_hwtimer_gptimer_abort(struct wlc_info *wlc)
6479 ASSERT(wlc->pub->corerev >= 3);
6480 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6483 static void wlc_hwtimer_gptimer_cb(struct wlc_info *wlc)
6485 /* when interrupt is generated, the counter is loaded with last value
6486 * written and continue to decrement. So it has to be cleaned first
6488 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6492 * This fn has all the high level dpc processing from wlc_dpc.
6493 * POLICY: no macinstatus change, no bounding loop.
6494 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6496 void wlc_high_dpc(struct wlc_info *wlc, u32 macintstatus)
6498 d11regs_t *regs = wlc->regs;
6501 static const bcm_bit_desc_t int_flags[] = {
6502 {MI_MACSSPNDD, "MACSSPNDD"},
6503 {MI_BCNTPL, "BCNTPL"},
6505 {MI_BCNSUCCESS, "BCNSUCCESS"},
6506 {MI_BCNCANCLD, "BCNCANCLD"},
6507 {MI_ATIMWINEND, "ATIMWINEND"},
6509 {MI_NSPECGEN_0, "NSPECGEN_0"},
6510 {MI_NSPECGEN_1, "NSPECGEN_1"},
6511 {MI_MACTXERR, "MACTXERR"},
6512 {MI_NSPECGEN_3, "NSPECGEN_3"},
6513 {MI_PHYTXERR, "PHYTXERR"},
6517 {MI_DMAINT, "DMAINT"},
6518 {MI_TXSTOP, "TXSTOP"},
6520 {MI_BG_NOISE, "BG_NOISE"},
6521 {MI_DTIM_TBTT, "DTIM_TBTT"},
6523 {MI_PWRUP, "PWRUP"},
6524 {MI_RFDISABLE, "RFDISABLE"},
6526 {MI_PHYCHANGED, "PHYCHANGED"},
6531 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) {
6532 bcm_format_flags(int_flags, macintstatus, flagstr,
6534 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6535 wlc->pub->unit, macintstatus, flagstr);
6539 if (macintstatus & MI_PRQ) {
6540 /* Process probe request FIFO */
6541 ASSERT(0 && "PRQ Interrupt in non-MBSS");
6544 /* TBTT indication */
6545 /* ucode only gives either TBTT or DTIM_TBTT, not both */
6546 if (macintstatus & (MI_TBTT | MI_DTIM_TBTT))
6547 wlc_tbtt(wlc, regs);
6549 if (macintstatus & MI_GP0) {
6550 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6551 wlc->pub->unit, wlc->pub->now);
6553 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6554 __func__, wlc->pub->sih->chip,
6555 wlc->pub->sih->chiprev);
6557 wlc->pub->_cnt->psmwds++;
6563 /* gptimer timeout */
6564 if (macintstatus & MI_TO) {
6565 wlc_hwtimer_gptimer_cb(wlc);
6568 if (macintstatus & MI_RFDISABLE) {
6569 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6571 R_REG(wlc->osh, ®s->phydebug) & PDBG_RFD);
6572 /* delay the cleanup to wl_down in IBSS case */
6573 if ((R_REG(wlc->osh, ®s->phydebug) & PDBG_RFD)) {
6575 wlc_bsscfg_t *bsscfg;
6576 FOREACH_BSS(wlc, idx, bsscfg) {
6577 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable
6580 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6586 /* send any enq'd tx packets. Just makes sure to jump start tx */
6587 if (!pktq_empty(&wlc->active_queue->q))
6588 wlc_send_q(wlc, wlc->active_queue);
6590 ASSERT(wlc_ps_check(wlc));
6593 static void *wlc_15420war(struct wlc_info *wlc, uint queue)
6595 struct hnddma_pub *di;
6598 ASSERT(queue < NFIFO);
6600 if ((D11REV_IS(wlc->pub->corerev, 4))
6601 || (D11REV_GT(wlc->pub->corerev, 6)))
6604 di = wlc->hw->di[queue];
6607 /* get next packet, ignoring XmtStatus.Curr */
6608 p = dma_getnexttxp(di, HNDDMA_RANGE_ALL);
6610 /* sw block tx dma */
6613 /* if tx ring is now empty, reset and re-init the tx dma channel */
6614 if (dma_txactive(wlc->hw->di[queue]) == 0) {
6615 wlc->pub->_cnt->txdmawar++;
6616 if (!dma_txreset(di))
6617 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
6618 wlc->pub->unit, __func__, queue);
6624 static void wlc_war16165(struct wlc_info *wlc, bool tx)
6627 /* the post-increment is used in STAY_AWAKE macro */
6628 if (wlc->txpend16165war++ == 0)
6629 wlc_set_ps_ctrl(wlc);
6631 wlc->txpend16165war--;
6632 if (wlc->txpend16165war == 0)
6633 wlc_set_ps_ctrl(wlc);
6637 /* process an individual tx_status_t */
6640 wlc_dotxstatus(struct wlc_info *wlc, tx_status_t *txs, u32 frm_tx2)
6645 struct scb *scb = NULL;
6647 struct osl_info *osh;
6648 int tx_rts, tx_frame_count, tx_rts_count;
6649 uint totlen, supr_status;
6651 struct ieee80211_hdr *h;
6654 struct ieee80211_tx_info *tx_info;
6655 struct ieee80211_tx_rate *txrate;
6658 (void)(frm_tx2); /* Compiler reference to avoid unused variable warning */
6660 /* discard intermediate indications for ucode with one legitimate case:
6661 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
6662 * tx of DATA failed. so it will start rts/cts from the beginning (resetting the rts
6663 * transmission count)
6665 if (!(txs->status & TX_STATUS_AMPDU)
6666 && (txs->status & TX_STATUS_INTERMEDIATE)) {
6667 WLCNTADD(wlc->pub->_cnt->txnoack,
6669 status & TX_STATUS_FRM_RTX_MASK) >>
6670 TX_STATUS_FRM_RTX_SHIFT));
6671 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__);
6676 queue = txs->frameid & TXFID_QUEUE_MASK;
6677 ASSERT(queue < NFIFO);
6678 if (queue >= NFIFO) {
6683 p = GETNEXTTXP(wlc, queue);
6684 if (WLC_WAR16165(wlc))
6685 wlc_war16165(wlc, false);
6687 p = wlc_15420war(wlc, queue);
6692 txh = (d11txh_t *) (p->data);
6693 mcl = ltoh16(txh->MacTxControlLow);
6696 if (WL_ERROR_ON()) {
6697 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6698 txs->phyerr, txh->MainRates);
6699 wlc_print_txdesc(txh);
6701 wlc_print_txstatus(txs);
6704 ASSERT(txs->frameid == htol16(txh->TxFrameID));
6705 if (txs->frameid != htol16(txh->TxFrameID))
6708 tx_info = IEEE80211_SKB_CB(p);
6709 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
6710 fc = ltoh16(h->frame_control);
6712 scb = (struct scb *)tx_info->control.sta->drv_priv;
6714 if (N_ENAB(wlc->pub)) {
6715 u8 *plcp = (u8 *) (txh + 1);
6716 if (PLCP3_ISSGI(plcp[3]))
6717 wlc->pub->_cnt->txmpdu_sgi++;
6718 if (PLCP3_ISSTBC(plcp[3]))
6719 wlc->pub->_cnt->txmpdu_stbc++;
6722 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
6723 ASSERT((mcl & TXC_AMPDU_MASK) != TXC_AMPDU_NONE);
6724 wlc_ampdu_dotxstatus(wlc->ampdu, scb, p, txs);
6728 supr_status = txs->status & TX_STATUS_SUPR_MASK;
6729 if (supr_status == TX_STATUS_SUPR_BADCH)
6730 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6731 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec));
6733 tx_rts = htol16(txh->MacTxControlLow) & TXC_SENDRTS;
6735 (txs->status & TX_STATUS_FRM_RTX_MASK) >> TX_STATUS_FRM_RTX_SHIFT;
6737 (txs->status & TX_STATUS_RTS_RTX_MASK) >> TX_STATUS_RTS_RTX_SHIFT;
6739 lastframe = (fc & IEEE80211_FCTL_MOREFRAGS) == 0;
6742 WL_ERROR("Not last frame!\n");
6745 ieee80211_tx_info_clear_status(tx_info);
6746 if (queue < AC_COUNT) {
6747 sfbl = WLC_WME_RETRY_SFB_GET(wlc, wme_fifo2ac[queue]);
6748 lfbl = WLC_WME_RETRY_LFB_GET(wlc, wme_fifo2ac[queue]);
6754 txrate = tx_info->status.rates;
6755 /* FIXME: this should use a combination of sfbl, lfbl depending on frame length and RTS setting */
6756 if ((tx_frame_count > sfbl) && (txrate[1].idx >= 0)) {
6757 /* rate selection requested a fallback rate and we used it */
6758 txrate->count = lfbl;
6759 txrate[1].count = tx_frame_count - lfbl;
6761 /* rate selection did not request fallback rate, or we didn't need it */
6762 txrate->count = tx_frame_count;
6763 /* rc80211_minstrel.c:minstrel_tx_status() expects unused rates to be marked with idx = -1 */
6765 txrate[1].count = 0;
6768 /* clear the rest of the rates */
6769 for (i = 2; i < IEEE80211_TX_MAX_RATES; i++) {
6771 txrate[i].count = 0;
6774 if (txs->status & TX_STATUS_ACK_RCV)
6775 tx_info->flags |= IEEE80211_TX_STAT_ACK;
6778 totlen = pkttotlen(osh, p);
6781 wlc_txfifo_complete(wlc, queue, 1);
6787 /* remove PLCP & Broadcom tx descriptor header */
6788 skb_pull(p, D11_PHY_HDR_LEN);
6789 skb_pull(p, D11_TXH_LEN);
6790 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
6791 wlc->pub->_cnt->ieee_tx_status++;
6793 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6802 pkt_buf_free_skb(osh, p, true);
6809 wlc_txfifo_complete(struct wlc_info *wlc, uint fifo, s8 txpktpend)
6811 TXPKTPENDDEC(wlc, fifo, txpktpend);
6812 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6813 txpktpend, TXPKTPENDGET(wlc, fifo));
6815 /* There is more room; mark precedences related to this FIFO sendable */
6816 WLC_TX_FIFO_ENAB(wlc, fifo);
6817 ASSERT(TXPKTPENDGET(wlc, fifo) >= 0);
6819 if (!TXPKTPENDTOT(wlc)) {
6820 if (wlc->block_datafifo & DATA_BLOCK_TX_SUPR)
6821 wlc_bsscfg_tx_check(wlc);
6824 /* Clear MHF2_TXBCMC_NOW flag if BCMC fifo has drained */
6825 if (AP_ENAB(wlc->pub) &&
6826 wlc->bcmcfifo_drain && !TXPKTPENDGET(wlc, TX_BCMC_FIFO)) {
6827 wlc->bcmcfifo_drain = false;
6828 wlc_mhf(wlc, MHF2, MHF2_TXBCMC_NOW, 0, WLC_BAND_AUTO);
6831 /* figure out which bsscfg is being worked on... */
6834 /* Given the beacon interval in kus, and a 64 bit TSF in us,
6835 * return the offset (in us) of the TSF from the last TBTT
6837 u32 wlc_calc_tbtt_offset(u32 bp, u32 tsf_h, u32 tsf_l)
6839 u32 k, btklo, btkhi, offset;
6841 /* TBTT is always an even multiple of the beacon_interval,
6842 * so the TBTT less than or equal to the beacon timestamp is
6843 * the beacon timestamp minus the beacon timestamp modulo
6844 * the beacon interval.
6846 * TBTT = BT - (BT % BIu)
6847 * = (BTk - (BTk % BP)) * 2^10
6849 * BT = beacon timestamp (usec, 64bits)
6850 * BTk = beacon timestamp (Kusec, 54bits)
6851 * BP = beacon interval (Kusec, 16bits)
6852 * BIu = BP * 2^10 = beacon interval (usec, 26bits)
6854 * To keep the calculations in u32s, the modulo operation
6855 * on the high part of BT needs to be done in parts using the
6857 * X*Y mod Z = ((X mod Z) * (Y mod Z)) mod Z
6859 * (X + Y) mod Z = ((X mod Z) + (Y mod Z)) mod Z
6861 * So, if BTk[n] = u16 n [0,3] of BTk.
6862 * BTk % BP = SUM((BTk[n] * 2^16n) % BP , 0<=n<4) % BP
6863 * and the SUM term can be broken down:
6864 * (BTk[n] * 2^16n) % BP
6865 * (BTk[n] * (2^16n % BP)) % BP
6867 * Create a set of power of 2 mod BP constants:
6868 * K[n] = 2^(16n) % BP
6869 * = (K[n-1] * 2^16) % BP
6870 * K[2] = 2^32 % BP = ((2^16 % BP) * 2^16) % BP
6872 * BTk % BP = BTk[0-1] % BP +
6873 * (BTk[2] * K[2]) % BP +
6874 * (BTk[3] * K[3]) % BP
6876 * Since K[n] < 2^16 and BTk[n] is < 2^16, then BTk[n] * K[n] < 2^32
6879 /* BTk = BT >> 10, btklo = BTk[0-3], bkthi = BTk[4-6] */
6880 btklo = (tsf_h << 22) | (tsf_l >> 10);
6881 btkhi = tsf_h >> 10;
6883 /* offset = BTk % BP */
6884 offset = btklo % bp;
6886 /* K[2] = ((2^16 % BP) * 2^16) % BP */
6887 k = (u32) (1 << 16) % bp;
6888 k = (u32) (k * 1 << 16) % (u32) bp;
6890 /* offset += (BTk[2] * K[2]) % BP */
6891 offset += ((btkhi & 0xffff) * k) % bp;
6894 btkhi = btkhi >> 16;
6896 /* k[3] = (K[2] * 2^16) % BP */
6899 /* offset += (BTk[3] * K[3]) % BP */
6900 offset += ((btkhi & 0xffff) * k) % bp;
6902 offset = offset % bp;
6904 /* convert offset from kus to us by shifting up 10 bits and
6905 * add in the low 10 bits of tsf that we ignored
6907 offset = (offset << 10) + (tsf_l & 0x3FF);
6912 /* Update beacon listen interval in shared memory */
6913 void wlc_bcn_li_upd(struct wlc_info *wlc)
6915 if (AP_ENAB(wlc->pub))
6918 /* wake up every DTIM is the default */
6919 if (wlc->bcn_li_dtim == 1)
6920 wlc_write_shm(wlc, M_BCN_LI, 0);
6922 wlc_write_shm(wlc, M_BCN_LI,
6923 (wlc->bcn_li_dtim << 8) | wlc->bcn_li_bcn);
6927 prep_mac80211_status(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p,
6928 struct ieee80211_rx_status *rx_status)
6931 wlc_d11rxhdr_t *wlc_rxh = (wlc_d11rxhdr_t *) rxh;
6935 unsigned char *plcp;
6937 wlc_read_tsf(wlc, &tsf_l, &tsf_h); /* mactime */
6938 rx_status->mactime = tsf_h;
6939 rx_status->mactime <<= 32;
6940 rx_status->mactime |= tsf_l;
6941 rx_status->flag |= RX_FLAG_TSFT;
6943 channel = WLC_CHAN_CHANNEL(rxh->RxChan);
6945 /* XXX Channel/badn needs to be filtered against whether we are single/dual band card */
6947 rx_status->band = IEEE80211_BAND_5GHZ;
6948 rx_status->freq = ieee80211_ofdm_chan_to_freq(
6949 WF_CHAN_FACTOR_5_G/2, channel);
6952 rx_status->band = IEEE80211_BAND_2GHZ;
6953 rx_status->freq = ieee80211_dsss_chan_to_freq(channel);
6956 rx_status->signal = wlc_rxh->rssi; /* signal */
6960 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
6964 rspec = wlc_compute_rspec(rxh, plcp);
6965 if (IS_MCS(rspec)) {
6966 rx_status->rate_idx = rspec & RSPEC_RATE_MASK;
6967 rx_status->flag |= RX_FLAG_HT;
6968 if (RSPEC_IS40MHZ(rspec))
6969 rx_status->flag |= RX_FLAG_40MHZ;
6971 switch (RSPEC2RATE(rspec)) {
6973 rx_status->rate_idx = 0;
6976 rx_status->rate_idx = 1;
6979 rx_status->rate_idx = 2;
6982 rx_status->rate_idx = 3;
6985 rx_status->rate_idx = 4;
6988 rx_status->rate_idx = 5;
6991 rx_status->rate_idx = 6;
6994 rx_status->rate_idx = 7;
6997 rx_status->rate_idx = 8;
7000 rx_status->rate_idx = 9;
7003 rx_status->rate_idx = 10;
7006 rx_status->rate_idx = 11;
7009 WL_ERROR("%s: Unknown rate\n", __func__);
7012 /* Determine short preamble and rate_idx */
7014 if (IS_CCK(rspec)) {
7015 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
7016 WL_ERROR("Short CCK\n");
7017 rx_status->flag |= RX_FLAG_SHORTPRE;
7018 } else if (IS_OFDM(rspec)) {
7019 rx_status->flag |= RX_FLAG_SHORTPRE;
7021 WL_ERROR("%s: Unknown modulation\n", __func__);
7025 if (PLCP3_ISSGI(plcp[3]))
7026 rx_status->flag |= RX_FLAG_SHORT_GI;
7028 if (rxh->RxStatus1 & RXS_DECERR) {
7029 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
7030 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__);
7032 if (rxh->RxStatus1 & RXS_FCSERR) {
7033 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
7034 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__);
7039 wlc_recvctl(struct wlc_info *wlc, struct osl_info *osh, d11rxhdr_t *rxh,
7043 struct ieee80211_rx_status rx_status;
7045 struct sk_buff *skb = p;
7048 * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE.
7049 * Test for INTERMEDIATE like so:
7050 * if (!(plcp[0] | plcp[1] | plcp[2]))
7053 memset(&rx_status, 0, sizeof(rx_status));
7054 prep_mac80211_status(wlc, rxh, p, &rx_status);
7056 /* mac header+body length, exclude CRC and plcp header */
7057 len_mpdu = p->len - D11_PHY_HDR_LEN - FCS_LEN;
7058 skb_pull(p, D11_PHY_HDR_LEN);
7059 __skb_trim(p, len_mpdu);
7064 ASSERT(IS_ALIGNED((unsigned long)skb->data, 2));
7066 memcpy(IEEE80211_SKB_RXCB(p), &rx_status, sizeof(rx_status));
7067 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
7069 wlc->pub->_cnt->ieee_rx++;
7074 void wlc_bss_list_free(struct wlc_info *wlc, wlc_bss_list_t *bss_list)
7080 WL_ERROR("%s: Attempting to free NULL list\n", __func__);
7083 /* inspect all BSS descriptor */
7084 for (index = 0; index < bss_list->count; index++) {
7085 bi = bss_list->ptrs[index];
7088 bss_list->ptrs[index] = NULL;
7091 bss_list->count = 0;
7094 /* Process received frames */
7096 * Return true if more frames need to be processed. false otherwise.
7097 * Param 'bound' indicates max. # frames to process before break out.
7100 void BCMFASTPATH wlc_recv(struct wlc_info *wlc, struct sk_buff *p)
7103 struct ieee80211_hdr *h;
7104 struct osl_info *osh;
7109 WL_TRACE("wl%d: wlc_recv\n", wlc->pub->unit);
7113 /* frame starts with rxhdr */
7114 rxh = (d11rxhdr_t *) (p->data);
7116 /* strip off rxhdr */
7117 skb_pull(p, wlc->hwrxoff);
7119 /* fixup rx header endianness */
7120 ltoh16_buf((void *)rxh, sizeof(d11rxhdr_t));
7122 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7123 if (rxh->RxStatus1 & RXS_PBPRES) {
7125 wlc->pub->_cnt->rxrunt++;
7126 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7127 wlc->pub->unit, p->len);
7133 h = (struct ieee80211_hdr *)(p->data + D11_PHY_HDR_LEN);
7136 if (rxh->RxStatus1 & RXS_FCSERR) {
7137 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
7138 WL_ERROR("FCSERR while scanning******* - tossing\n");
7141 WL_ERROR("RCSERR!!!\n");
7146 /* check received pkt has at least frame control field */
7147 if (len >= D11_PHY_HDR_LEN + sizeof(h->frame_control)) {
7148 fc = ltoh16(h->frame_control);
7150 wlc->pub->_cnt->rxrunt++;
7154 is_amsdu = rxh->RxStatus2 & RXS_AMSDU_MASK;
7156 /* explicitly test bad src address to avoid sending bad deauth */
7158 /* CTS and ACK CTL frames are w/o a2 */
7159 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
7160 (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
7161 if ((is_zero_ether_addr(h->addr2) ||
7162 is_multicast_ether_addr(h->addr2))) {
7163 WL_ERROR("wl%d: %s: dropping a frame with "
7164 "invalid src mac address, a2: %pM\n",
7165 wlc->pub->unit, __func__, h->addr2);
7166 wlc->pub->_cnt->rxbadsrcmac++;
7169 wlc->pub->_cnt->rxfrag++;
7173 /* due to sheer numbers, toss out probe reqs for now */
7174 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
7175 if ((fc & FC_KIND_MASK) == FC_PROBE_REQ)
7180 WL_ERROR("%s: is_amsdu causing toss\n", __func__);
7184 wlc_recvctl(wlc, osh, rxh, p);
7188 pkt_buf_free_skb(osh, p, false);
7191 /* calculate frame duration for Mixed-mode L-SIG spoofing, return
7192 * number of bytes goes in the length field
7194 * Formula given by HT PHY Spec v 1.13
7195 * len = 3(nsyms + nstream + 3) - 3
7198 wlc_calc_lsig_len(struct wlc_info *wlc, ratespec_t ratespec, uint mac_len)
7200 uint nsyms, len = 0, kNdps;
7202 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7203 wlc->pub->unit, RSPEC2RATE(ratespec), mac_len);
7205 if (IS_MCS(ratespec)) {
7206 uint mcs = ratespec & RSPEC_RATE_MASK;
7207 /* MCS_TXS(mcs) returns num tx streams - 1 */
7208 int tot_streams = (MCS_TXS(mcs) + 1) + RSPEC_STC(ratespec);
7210 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7211 /* the payload duration calculation matches that of regular ofdm */
7212 /* 1000Ndbps = kbps * 4 */
7214 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7215 RSPEC_ISSGI(ratespec)) * 4;
7217 if (RSPEC_STC(ratespec) == 0)
7218 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7220 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7221 APHY_TAIL_NBITS) * 1000, kNdps);
7223 /* STBC needs to have even number of symbols */
7226 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7227 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7229 nsyms += (tot_streams + 3); /* (+3) account for HT-SIG(2) and HT-STF(1) */
7230 /* 3 bytes/symbol @ legacy 6Mbps rate */
7231 len = (3 * nsyms) - 3; /* (-3) excluding service bits and tail bits */
7237 /* calculate frame duration of a given rate and length, return time in usec unit */
7239 wlc_calc_frame_time(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7242 uint nsyms, dur = 0, Ndps, kNdps;
7243 uint rate = RSPEC2RATE(ratespec);
7247 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit);
7251 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7252 wlc->pub->unit, ratespec, preamble_type, mac_len);
7254 if (IS_MCS(ratespec)) {
7255 uint mcs = ratespec & RSPEC_RATE_MASK;
7256 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7257 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7258 ASSERT(WLC_IS_MIMO_PREAMBLE(preamble_type));
7260 dur = PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7261 if (preamble_type == WLC_MM_PREAMBLE)
7263 /* 1000Ndbps = kbps * 4 */
7265 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7266 RSPEC_ISSGI(ratespec)) * 4;
7268 if (RSPEC_STC(ratespec) == 0)
7269 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7271 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7272 APHY_TAIL_NBITS) * 1000, kNdps);
7274 /* STBC needs to have even number of symbols */
7277 CEIL((APHY_SERVICE_NBITS + 8 * mac_len +
7278 APHY_TAIL_NBITS) * 1000, 2 * kNdps);
7280 dur += APHY_SYMBOL_TIME * nsyms;
7281 if (BAND_2G(wlc->band->bandtype))
7282 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7283 } else if (IS_OFDM(rate)) {
7284 dur = APHY_PREAMBLE_TIME;
7285 dur += APHY_SIGNAL_TIME;
7286 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7288 /* NSyms = CEILING((SERVICE + 8*NBytes + TAIL) / Ndbps) */
7290 CEIL((APHY_SERVICE_NBITS + 8 * mac_len + APHY_TAIL_NBITS),
7292 dur += APHY_SYMBOL_TIME * nsyms;
7293 if (BAND_2G(wlc->band->bandtype))
7294 dur += DOT11_OFDM_SIGNAL_EXTENSION;
7296 /* calc # bits * 2 so factor of 2 in rate (1/2 mbps) will divide out */
7297 mac_len = mac_len * 8 * 2;
7298 /* calc ceiling of bits/rate = microseconds of air time */
7299 dur = (mac_len + rate - 1) / rate;
7300 if (preamble_type & WLC_SHORT_PREAMBLE)
7301 dur += BPHY_PLCP_SHORT_TIME;
7303 dur += BPHY_PLCP_TIME;
7308 /* The opposite of wlc_calc_frame_time */
7310 wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7313 uint nsyms, mac_len, Ndps, kNdps;
7314 uint rate = RSPEC2RATE(ratespec);
7316 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7317 wlc->pub->unit, ratespec, preamble_type, dur);
7319 if (IS_MCS(ratespec)) {
7320 uint mcs = ratespec & RSPEC_RATE_MASK;
7321 int tot_streams = MCS_TXS(mcs) + RSPEC_STC(ratespec);
7322 ASSERT(WLC_PHY_11N_CAP(wlc->band));
7323 dur -= PREN_PREAMBLE + (tot_streams * PREN_PREAMBLE_EXT);
7324 /* payload calculation matches that of regular ofdm */
7325 if (BAND_2G(wlc->band->bandtype))
7326 dur -= DOT11_OFDM_SIGNAL_EXTENSION;
7327 /* kNdbps = kbps * 4 */
7329 MCS_RATE(mcs, RSPEC_IS40MHZ(ratespec),
7330 RSPEC_ISSGI(ratespec)) * 4;
7331 nsyms = dur / APHY_SYMBOL_TIME;
7334 ((APHY_SERVICE_NBITS + APHY_TAIL_NBITS) * 1000)) / 8000;
7335 } else if (IS_OFDM(ratespec)) {
7336 dur -= APHY_PREAMBLE_TIME;
7337 dur -= APHY_SIGNAL_TIME;
7338 /* Ndbps = Mbps * 4 = rate(500Kbps) * 2 */
7340 nsyms = dur / APHY_SYMBOL_TIME;
7343 (APHY_SERVICE_NBITS + APHY_TAIL_NBITS)) / 8;
7345 if (preamble_type & WLC_SHORT_PREAMBLE)
7346 dur -= BPHY_PLCP_SHORT_TIME;
7348 dur -= BPHY_PLCP_TIME;
7349 mac_len = dur * rate;
7350 /* divide out factor of 2 in rate (1/2 mbps) */
7351 mac_len = mac_len / 8 / 2;
7357 wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7359 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7360 wlc->pub->unit, rspec, preamble_type);
7361 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7362 * or equal to the rate of the immediately previous frame in the FES
7364 rspec = WLC_BASIC_RATE(wlc, rspec);
7365 ASSERT(VALID_RATE_DBG(wlc, rspec));
7367 /* BA len == 32 == 16(ctl hdr) + 4(ba len) + 8(bitmap) + 4(fcs) */
7368 return wlc_calc_frame_time(wlc, rspec, preamble_type,
7369 (DOT11_BA_LEN + DOT11_BA_BITMAP_LEN +
7373 static uint BCMFASTPATH
7374 wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7378 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7379 wlc->pub->unit, rspec, preamble_type);
7380 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7381 * or equal to the rate of the immediately previous frame in the FES
7383 rspec = WLC_BASIC_RATE(wlc, rspec);
7384 ASSERT(VALID_RATE_DBG(wlc, rspec));
7386 /* ACK frame len == 14 == 2(fc) + 2(dur) + 6(ra) + 4(fcs) */
7388 wlc_calc_frame_time(wlc, rspec, preamble_type,
7389 (DOT11_ACK_LEN + FCS_LEN));
7394 wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7396 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7397 wlc->pub->unit, rspec, preamble_type);
7398 return wlc_calc_ack_time(wlc, rspec, preamble_type);
7401 /* derive wlc->band->basic_rate[] table from 'rateset' */
7402 void wlc_rate_lookup_init(struct wlc_info *wlc, wlc_rateset_t *rateset)
7408 u8 *br = wlc->band->basic_rate;
7411 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7412 memset(br, 0, WLC_MAXRATE + 1);
7414 /* For each basic rate in the rates list, make an entry in the
7415 * best basic lookup.
7417 for (i = 0; i < rateset->count; i++) {
7418 /* only make an entry for a basic rate */
7419 if (!(rateset->rates[i] & WLC_RATE_FLAG))
7422 /* mask off basic bit */
7423 rate = (rateset->rates[i] & RATE_MASK);
7425 if (rate > WLC_MAXRATE) {
7426 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7434 /* The rate lookup table now has non-zero entries for each
7435 * basic rate, equal to the basic rate: br[basicN] = basicN
7437 * To look up the best basic rate corresponding to any
7438 * particular rate, code can use the basic_rate table
7441 * basic_rate = wlc->band->basic_rate[tx_rate]
7443 * Make sure there is a best basic rate entry for
7444 * every rate by walking up the table from low rates
7445 * to high, filling in holes in the lookup table
7448 for (i = 0; i < wlc->band->hw_rateset.count; i++) {
7449 rate = wlc->band->hw_rateset.rates[i];
7450 ASSERT(rate <= WLC_MAXRATE);
7452 if (br[rate] != 0) {
7453 /* This rate is a basic rate.
7454 * Keep track of the best basic rate so far by
7465 /* This rate is not a basic rate so figure out the
7466 * best basic rate less than this rate and fill in
7467 * the hole in the table
7470 br[rate] = IS_OFDM(rate) ? ofdm_basic : cck_basic;
7475 if (IS_OFDM(rate)) {
7476 /* In 11g and 11a, the OFDM mandatory rates are 6, 12, and 24 Mbps */
7477 if (rate >= WLC_RATE_24M)
7478 mandatory = WLC_RATE_24M;
7479 else if (rate >= WLC_RATE_12M)
7480 mandatory = WLC_RATE_12M;
7482 mandatory = WLC_RATE_6M;
7484 /* In 11b, all the CCK rates are mandatory 1 - 11 Mbps */
7488 br[rate] = mandatory;
7492 static void wlc_write_rate_shm(struct wlc_info *wlc, u8 rate, u8 basic_rate)
7495 u8 basic_phy_rate, basic_index;
7496 u16 dir_table, basic_table;
7499 /* Shared memory address for the table we are reading */
7500 dir_table = IS_OFDM(basic_rate) ? M_RT_DIRMAP_A : M_RT_DIRMAP_B;
7502 /* Shared memory address for the table we are writing */
7503 basic_table = IS_OFDM(rate) ? M_RT_BBRSMAP_A : M_RT_BBRSMAP_B;
7506 * for a given rate, the LS-nibble of the PLCP SIGNAL field is
7507 * the index into the rate table.
7509 phy_rate = rate_info[rate] & RATE_MASK;
7510 basic_phy_rate = rate_info[basic_rate] & RATE_MASK;
7511 index = phy_rate & 0xf;
7512 basic_index = basic_phy_rate & 0xf;
7514 /* Find the SHM pointer to the ACK rate entry by looking in the
7517 basic_ptr = wlc_read_shm(wlc, (dir_table + basic_index * 2));
7519 /* Update the SHM BSS-basic-rate-set mapping table with the pointer
7520 * to the correct basic rate for the given incoming rate
7522 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr);
7525 static const wlc_rateset_t *wlc_rateset_get_hwrs(struct wlc_info *wlc)
7527 const wlc_rateset_t *rs_dflt;
7529 if (WLC_PHY_11N_CAP(wlc->band)) {
7530 if (BAND_5G(wlc->band->bandtype))
7531 rs_dflt = &ofdm_mimo_rates;
7533 rs_dflt = &cck_ofdm_mimo_rates;
7534 } else if (wlc->band->gmode)
7535 rs_dflt = &cck_ofdm_rates;
7537 rs_dflt = &cck_rates;
7542 void wlc_set_ratetable(struct wlc_info *wlc)
7544 const wlc_rateset_t *rs_dflt;
7546 u8 rate, basic_rate;
7549 rs_dflt = wlc_rateset_get_hwrs(wlc);
7550 ASSERT(rs_dflt != NULL);
7552 wlc_rateset_copy(rs_dflt, &rs);
7553 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7555 /* walk the phy rate table and update SHM basic rate lookup table */
7556 for (i = 0; i < rs.count; i++) {
7557 rate = rs.rates[i] & RATE_MASK;
7559 /* for a given rate WLC_BASIC_RATE returns the rate at
7560 * which a response ACK/CTS should be sent.
7562 basic_rate = WLC_BASIC_RATE(wlc, rate);
7563 if (basic_rate == 0) {
7564 /* This should only happen if we are using a
7565 * restricted rateset.
7567 basic_rate = rs.rates[0] & RATE_MASK;
7570 wlc_write_rate_shm(wlc, rate, basic_rate);
7575 * Return true if the specified rate is supported by the specified band.
7576 * WLC_BAND_AUTO indicates the current band.
7578 bool wlc_valid_rate(struct wlc_info *wlc, ratespec_t rspec, int band,
7581 wlc_rateset_t *hw_rateset;
7584 if ((band == WLC_BAND_AUTO) || (band == wlc->band->bandtype)) {
7585 hw_rateset = &wlc->band->hw_rateset;
7586 } else if (NBANDS(wlc) > 1) {
7587 hw_rateset = &wlc->bandstate[OTHERBANDUNIT(wlc)]->hw_rateset;
7589 /* other band specified and we are a single band device */
7593 /* check if this is a mimo rate */
7594 if (IS_MCS(rspec)) {
7595 if (!VALID_MCS((rspec & RSPEC_RATE_MASK)))
7598 return isset(hw_rateset->mcs, (rspec & RSPEC_RATE_MASK));
7601 for (i = 0; i < hw_rateset->count; i++)
7602 if (hw_rateset->rates[i] == RSPEC2RATE(rspec))
7606 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7607 wlc->pub->unit, rspec);
7613 static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap)
7616 struct wlcband *band;
7618 for (i = 0; i < NBANDS(wlc); i++) {
7619 if (IS_SINGLEBAND_5G(wlc->deviceid))
7621 band = wlc->bandstate[i];
7622 if (band->bandtype == WLC_BAND_5G) {
7623 if ((bwcap == WLC_N_BW_40ALL)
7624 || (bwcap == WLC_N_BW_20IN2G_40IN5G))
7625 band->mimo_cap_40 = true;
7627 band->mimo_cap_40 = false;
7629 ASSERT(band->bandtype == WLC_BAND_2G);
7630 if (bwcap == WLC_N_BW_40ALL)
7631 band->mimo_cap_40 = true;
7633 band->mimo_cap_40 = false;
7637 wlc->mimo_band_bwcap = bwcap;
7640 void wlc_mod_prb_rsp_rate_table(struct wlc_info *wlc, uint frame_len)
7642 const wlc_rateset_t *rs_dflt;
7646 u8 plcp[D11_PHY_HDR_LEN];
7650 sifs = SIFS(wlc->band);
7652 rs_dflt = wlc_rateset_get_hwrs(wlc);
7653 ASSERT(rs_dflt != NULL);
7655 wlc_rateset_copy(rs_dflt, &rs);
7656 wlc_rateset_mcs_upd(&rs, wlc->stf->txstreams);
7658 /* walk the phy rate table and update MAC core SHM basic rate table entries */
7659 for (i = 0; i < rs.count; i++) {
7660 rate = rs.rates[i] & RATE_MASK;
7662 entry_ptr = wlc_rate_shm_offset(wlc, rate);
7664 /* Calculate the Probe Response PLCP for the given rate */
7665 wlc_compute_plcp(wlc, rate, frame_len, plcp);
7667 /* Calculate the duration of the Probe Response frame plus SIFS for the MAC */
7669 (u16) wlc_calc_frame_time(wlc, rate, WLC_LONG_PREAMBLE,
7673 /* Update the SHM Rate Table entry Probe Response values */
7674 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS,
7675 (u16) (plcp[0] + (plcp[1] << 8)));
7676 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_PLCP_POS + 2,
7677 (u16) (plcp[2] + (plcp[3] << 8)));
7678 wlc_write_shm(wlc, entry_ptr + M_RT_PRS_DUR_POS, dur);
7683 wlc_compute_bcntsfoff(struct wlc_info *wlc, ratespec_t rspec,
7684 bool short_preamble, bool phydelay)
7688 if (IS_MCS(rspec)) {
7689 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7690 wlc->pub->unit, rspec);
7691 } else if (IS_OFDM(rspec)) {
7692 /* tx delay from MAC through phy to air (2.1 usec) +
7693 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
7694 * PLCP SERVICE + MAC header time (SERVICE + FC + DUR + A1 + A2 + A3 + SEQ == 26
7695 * bytes at beacon rate)
7697 bcntsfoff += phydelay ? D11A_PHY_TX_DELAY : 0;
7698 bcntsfoff += APHY_PREAMBLE_TIME + APHY_SIGNAL_TIME;
7700 wlc_compute_airtime(wlc, rspec,
7701 APHY_SERVICE_NBITS / 8 +
7704 /* tx delay from MAC through phy to air (3.4 usec) +
7705 * phy header time (long preamble + PLCP == 192 usec) +
7706 * MAC header time (FC + DUR + A1 + A2 + A3 + SEQ == 24 bytes at beacon rate)
7708 bcntsfoff += phydelay ? D11B_PHY_TX_DELAY : 0;
7710 short_preamble ? D11B_PHY_SPREHDR_TIME :
7711 D11B_PHY_LPREHDR_TIME;
7712 bcntsfoff += wlc_compute_airtime(wlc, rspec, DOT11_MAC_HDR_LEN);
7714 return (u16) (bcntsfoff);
7717 /* Max buffering needed for beacon template/prb resp template is 142 bytes.
7719 * PLCP header is 6 bytes.
7720 * 802.11 A3 header is 24 bytes.
7721 * Max beacon frame body template length is 112 bytes.
7722 * Max probe resp frame body template length is 110 bytes.
7724 * *len on input contains the max length of the packet available.
7726 * The *len value is set to the number of bytes in buf used, and starts with the PLCP
7727 * and included up to, but not including, the 4 byte FCS.
7730 wlc_bcn_prb_template(struct wlc_info *wlc, uint type, ratespec_t bcn_rspec,
7731 wlc_bsscfg_t *cfg, u16 *buf, int *len)
7733 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
7734 cck_phy_hdr_t *plcp;
7735 struct ieee80211_mgmt *h;
7736 int hdr_len, body_len;
7738 ASSERT(*len >= 142);
7739 ASSERT(type == FC_BEACON || type == FC_PROBE_RESP);
7741 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
7742 hdr_len = DOT11_MAC_HDR_LEN;
7744 hdr_len = D11_PHY_HDR_LEN + DOT11_MAC_HDR_LEN;
7745 body_len = *len - hdr_len; /* calc buffer size provided for frame body */
7747 *len = hdr_len + body_len; /* return actual size */
7749 /* format PHY and MAC headers */
7750 memset((char *)buf, 0, hdr_len);
7752 plcp = (cck_phy_hdr_t *) buf;
7754 /* PLCP for Probe Response frames are filled in from core's rate table */
7755 if (type == FC_BEACON && !MBSS_BCN_ENAB(cfg)) {
7757 wlc_compute_plcp(wlc, bcn_rspec,
7758 (DOT11_MAC_HDR_LEN + body_len + FCS_LEN),
7762 /* "Regular" and 16 MBSS but not for 4 MBSS */
7763 /* Update the phytxctl for the beacon based on the rspec */
7764 if (!SOFTBCN_ENAB(cfg))
7765 wlc_beacon_phytxctl_txant_upd(wlc, bcn_rspec);
7767 if (MBSS_BCN_ENAB(cfg) && type == FC_BEACON)
7768 h = (struct ieee80211_mgmt *)&plcp[0];
7770 h = (struct ieee80211_mgmt *)&plcp[1];
7772 /* fill in 802.11 header */
7773 h->frame_control = htol16((u16) type);
7775 /* DUR is 0 for multicast bcn, or filled in by MAC for prb resp */
7776 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7777 if (type == FC_BEACON)
7778 bcopy((const char *)ðer_bcast, (char *)&h->da,
7780 bcopy((char *)&cfg->cur_etheraddr, (char *)&h->sa, ETH_ALEN);
7781 bcopy((char *)&cfg->BSSID, (char *)&h->bssid, ETH_ALEN);
7783 /* SEQ filled in by MAC */
7788 int wlc_get_header_len()
7793 /* Update a beacon for a particular BSS
7794 * For MBSS, this updates the software template and sets "latest" to the index of the
7796 * Otherwise, it updates the hardware template.
7798 void wlc_bss_update_beacon(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7800 int len = BCN_TMPL_LEN;
7802 /* Clear the soft intmask */
7803 wlc->defmacintmask &= ~MI_BCNTPL;
7805 if (!cfg->up) { /* Only allow updates on an UP bss */
7809 if (MBSS_BCN_ENAB(cfg)) { /* Optimize: Some of if/else could be combined */
7810 } else if (HWBCN_ENAB(cfg)) { /* Hardware beaconing for this config */
7811 u16 bcn[BCN_TMPL_LEN / 2];
7812 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
7813 d11regs_t *regs = wlc->regs;
7814 struct osl_info *osh = NULL;
7818 /* Check if both templates are in use, if so sched. an interrupt
7819 * that will call back into this routine
7821 if ((R_REG(osh, ®s->maccommand) & both_valid) == both_valid) {
7822 /* clear any previous status */
7823 W_REG(osh, ®s->macintstatus, MI_BCNTPL);
7825 /* Check that after scheduling the interrupt both of the
7826 * templates are still busy. if not clear the int. & remask
7828 if ((R_REG(osh, ®s->maccommand) & both_valid) == both_valid) {
7829 wlc->defmacintmask |= MI_BCNTPL;
7834 wlc_lowest_basic_rspec(wlc, &cfg->current_bss->rateset);
7835 ASSERT(wlc_valid_rate
7836 (wlc, wlc->bcn_rspec,
7837 CHSPEC_IS2G(cfg->current_bss->
7838 chanspec) ? WLC_BAND_2G : WLC_BAND_5G,
7841 /* update the template and ucode shm */
7842 wlc_bcn_prb_template(wlc, FC_BEACON, wlc->bcn_rspec, cfg, bcn,
7844 wlc_write_hw_bcntemplates(wlc, bcn, len, false);
7849 * Update all beacons for the system.
7851 void wlc_update_beacon(struct wlc_info *wlc)
7854 wlc_bsscfg_t *bsscfg;
7856 /* update AP or IBSS beacons */
7857 FOREACH_BSS(wlc, idx, bsscfg) {
7858 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7859 wlc_bss_update_beacon(wlc, bsscfg);
7863 /* Write ssid into shared memory */
7864 void wlc_shm_ssid_upd(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7866 u8 *ssidptr = cfg->SSID;
7868 u8 ssidbuf[IEEE80211_MAX_SSID_LEN];
7870 /* padding the ssid with zero and copy it into shm */
7871 memset(ssidbuf, 0, IEEE80211_MAX_SSID_LEN);
7872 bcopy(ssidptr, ssidbuf, cfg->SSID_len);
7874 wlc_copyto_shm(wlc, base, ssidbuf, IEEE80211_MAX_SSID_LEN);
7876 if (!MBSS_BCN_ENAB(cfg))
7877 wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len);
7880 void wlc_update_probe_resp(struct wlc_info *wlc, bool suspend)
7883 wlc_bsscfg_t *bsscfg;
7885 /* update AP or IBSS probe responses */
7886 FOREACH_BSS(wlc, idx, bsscfg) {
7887 if (bsscfg->up && (BSSCFG_AP(bsscfg) || !bsscfg->BSS))
7888 wlc_bss_update_probe_resp(wlc, bsscfg, suspend);
7893 wlc_bss_update_probe_resp(struct wlc_info *wlc, wlc_bsscfg_t *cfg, bool suspend)
7895 u16 prb_resp[BCN_TMPL_LEN / 2];
7896 int len = BCN_TMPL_LEN;
7898 /* write the probe response to hardware, or save in the config structure */
7899 if (!MBSS_PRB_ENAB(cfg)) {
7901 /* create the probe response template */
7902 wlc_bcn_prb_template(wlc, FC_PROBE_RESP, 0, cfg, prb_resp,
7906 wlc_suspend_mac_and_wait(wlc);
7908 /* write the probe response into the template region */
7909 wlc_bmac_write_template_ram(wlc->hw, T_PRS_TPL_BASE,
7910 (len + 3) & ~3, prb_resp);
7912 /* write the length of the probe response frame (+PLCP/-FCS) */
7913 wlc_write_shm(wlc, M_PRB_RESP_FRM_LEN, (u16) len);
7915 /* write the SSID and SSID length */
7916 wlc_shm_ssid_upd(wlc, cfg);
7919 * Write PLCP headers and durations for probe response frames at all rates.
7920 * Use the actual frame length covered by the PLCP header for the call to
7921 * wlc_mod_prb_rsp_rate_table() by subtracting the PLCP len and adding the FCS.
7923 len += (-D11_PHY_HDR_LEN + FCS_LEN);
7924 wlc_mod_prb_rsp_rate_table(wlc, (u16) len);
7927 wlc_enable_mac(wlc);
7928 } else { /* Generating probe resp in sw; update local template */
7929 ASSERT(0 && "No software probe response support without MBSS");
7933 /* prepares pdu for transmission. returns BCM error codes */
7934 int wlc_prep_pdu(struct wlc_info *wlc, struct sk_buff *pdu, uint *fifop)
7936 struct osl_info *osh;
7939 struct ieee80211_hdr *h;
7946 txh = (d11txh_t *) (pdu->data);
7948 h = (struct ieee80211_hdr *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
7950 fc = ltoh16(h->frame_control);
7952 /* get the pkt queue info. This was put at wlc_sendctl or wlc_send for PDU */
7953 fifo = ltoh16(txh->TxFrameID) & TXFID_QUEUE_MASK;
7959 /* return if insufficient dma resources */
7960 if (TXAVAIL(wlc, fifo) < MAX_DMA_SEGS) {
7961 /* Mark precedences related to this FIFO, unsendable */
7962 WLC_TX_FIFO_CLEAR(wlc, fifo);
7966 if ((ltoh16(txh->MacFrameControl) & IEEE80211_FCTL_FTYPE) !=
7967 IEEE80211_FTYPE_DATA)
7968 wlc->pub->_cnt->txctl++;
7973 /* init tx reported rate mechanism */
7974 void wlc_reprate_init(struct wlc_info *wlc)
7977 wlc_bsscfg_t *bsscfg;
7979 FOREACH_BSS(wlc, i, bsscfg) {
7980 wlc_bsscfg_reprate_init(bsscfg);
7984 /* per bsscfg init tx reported rate mechanism */
7985 void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg)
7987 bsscfg->txrspecidx = 0;
7988 memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec));
7991 /* Retrieve a consolidated set of revision information,
7992 * typically for the WLC_GET_REVINFO ioctl
7994 int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len)
7996 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf;
7998 if (len < WL_REV_INFO_LEGACY_LENGTH)
7999 return BCME_BUFTOOSHORT;
8001 rinfo->vendorid = wlc->vendorid;
8002 rinfo->deviceid = wlc->deviceid;
8003 rinfo->radiorev = (wlc->band->radiorev << IDCODE_REV_SHIFT) |
8004 (wlc->band->radioid << IDCODE_ID_SHIFT);
8005 rinfo->chiprev = wlc->pub->sih->chiprev;
8006 rinfo->corerev = wlc->pub->corerev;
8007 rinfo->boardid = wlc->pub->sih->boardtype;
8008 rinfo->boardvendor = wlc->pub->sih->boardvendor;
8009 rinfo->boardrev = wlc->pub->boardrev;
8010 rinfo->ucoderev = wlc->ucode_rev;
8011 rinfo->driverrev = EPI_VERSION_NUM;
8012 rinfo->bus = wlc->pub->sih->bustype;
8013 rinfo->chipnum = wlc->pub->sih->chip;
8015 if (len >= (offsetof(wlc_rev_info_t, chippkg))) {
8016 rinfo->phytype = wlc->band->phytype;
8017 rinfo->phyrev = wlc->band->phyrev;
8018 rinfo->anarev = 0; /* obsolete stuff, suppress */
8021 if (len >= sizeof(*rinfo)) {
8022 rinfo->chippkg = wlc->pub->sih->chippkg;
8028 void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs)
8030 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype,
8031 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
8032 CHSPEC_WLC_BW(wlc->default_bss->chanspec),
8033 wlc->stf->txstreams);
8036 static void wlc_bss_default_init(struct wlc_info *wlc)
8038 chanspec_t chanspec;
8039 struct wlcband *band;
8040 wlc_bss_info_t *bi = wlc->default_bss;
8042 /* init default and target BSS with some sane initial values */
8043 memset((char *)(bi), 0, sizeof(wlc_bss_info_t));
8044 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT :
8045 BEACON_INTERVAL_DEFAULT;
8046 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT :
8047 DTIM_INTERVAL_DEFAULT;
8049 /* fill the default channel as the first valid channel
8050 * starting from the 2G channels
8052 chanspec = CH20MHZ_CHSPEC(1);
8053 ASSERT(chanspec != INVCHANSPEC);
8055 wlc->home_chanspec = bi->chanspec = chanspec;
8057 /* find the band of our default channel */
8059 if (NBANDS(wlc) > 1 && band->bandunit != CHSPEC_WLCBANDUNIT(chanspec))
8060 band = wlc->bandstate[OTHERBANDUNIT(wlc)];
8062 /* init bss rates to the band specific default rate set */
8063 wlc_rateset_default(&bi->rateset, NULL, band->phytype, band->bandtype,
8064 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
8065 CHSPEC_WLC_BW(chanspec), wlc->stf->txstreams);
8067 if (N_ENAB(wlc->pub))
8068 bi->flags |= WLC_BSS_HT;
8071 /* Deferred event processing */
8072 static void wlc_process_eventq(void *arg)
8074 struct wlc_info *wlc = (struct wlc_info *) arg;
8077 while ((etmp = wlc_eventq_deq(wlc->eventq))) {
8078 /* Perform OS specific event processing */
8079 wl_event(wlc->wl, etmp->event.ifname, etmp);
8084 wlc_event_free(wlc->eventq, etmp);
8089 wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, u32 b_low)
8091 if (b_low > *a_low) {
8092 /* low half needs a carry */
8100 mac80211_wlc_set_nrate(struct wlc_info *wlc, struct wlcband *cur_band,
8103 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
8104 u8 rate = int_val & NRATE_RATE_MASK;
8106 bool ismcs = ((int_val & NRATE_MCS_INUSE) == NRATE_MCS_INUSE);
8107 bool issgi = ((int_val & NRATE_SGI_MASK) >> NRATE_SGI_SHIFT);
8108 bool override_mcs_only = ((int_val & NRATE_OVERRIDE_MCS_ONLY)
8109 == NRATE_OVERRIDE_MCS_ONLY);
8113 return (ratespec_t) rate;
8116 /* validate the combination of rate/mcs/stf is allowed */
8117 if (N_ENAB(wlc->pub) && ismcs) {
8118 /* mcs only allowed when nmode */
8119 if (stf > PHY_TXC1_MODE_SDM) {
8120 WL_ERROR("wl%d: %s: Invalid stf\n",
8121 WLCWLUNIT(wlc), __func__);
8122 bcmerror = BCME_RANGE;
8126 /* mcs 32 is a special case, DUP mode 40 only */
8128 if (!CHSPEC_IS40(wlc->home_chanspec) ||
8129 ((stf != PHY_TXC1_MODE_SISO)
8130 && (stf != PHY_TXC1_MODE_CDD))) {
8131 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8132 WLCWLUNIT(wlc), __func__);
8133 bcmerror = BCME_RANGE;
8136 /* mcs > 7 must use stf SDM */
8137 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
8138 /* mcs > 7 must use stf SDM */
8139 if (stf != PHY_TXC1_MODE_SDM) {
8140 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8141 WLCWLUNIT(wlc), __func__, rate);
8142 stf = PHY_TXC1_MODE_SDM;
8145 /* MCS 0-7 may use SISO, CDD, and for phy_rev >= 3 STBC */
8146 if ((stf > PHY_TXC1_MODE_STBC) ||
8147 (!WLC_STBC_CAP_PHY(wlc)
8148 && (stf == PHY_TXC1_MODE_STBC))) {
8149 WL_ERROR("wl%d: %s: Invalid STBC\n",
8150 WLCWLUNIT(wlc), __func__);
8151 bcmerror = BCME_RANGE;
8155 } else if (IS_OFDM(rate)) {
8156 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
8157 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8158 WLCWLUNIT(wlc), __func__);
8159 bcmerror = BCME_RANGE;
8162 } else if (IS_CCK(rate)) {
8163 if ((cur_band->bandtype != WLC_BAND_2G)
8164 || (stf != PHY_TXC1_MODE_SISO)) {
8165 WL_ERROR("wl%d: %s: Invalid CCK\n",
8166 WLCWLUNIT(wlc), __func__);
8167 bcmerror = BCME_RANGE;
8171 WL_ERROR("wl%d: %s: Unknown rate type\n",
8172 WLCWLUNIT(wlc), __func__);
8173 bcmerror = BCME_RANGE;
8176 /* make sure multiple antennae are available for non-siso rates */
8177 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
8178 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8179 WLCWLUNIT(wlc), __func__);
8180 bcmerror = BCME_RANGE;
8186 rspec |= RSPEC_MIMORATE;
8187 /* For STBC populate the STC field of the ratespec */
8188 if (stf == PHY_TXC1_MODE_STBC) {
8190 stc = 1; /* Nss for single stream is always 1 */
8191 rspec |= (stc << RSPEC_STC_SHIFT);
8195 rspec |= (stf << RSPEC_STF_SHIFT);
8197 if (override_mcs_only)
8198 rspec |= RSPEC_OVERRIDE_MCS_ONLY;
8201 rspec |= RSPEC_SHORT_GI;
8204 && !wlc_valid_rate(wlc, rspec, cur_band->bandtype, true)) {
8210 WL_ERROR("Hoark\n");
8214 /* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8216 wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
8219 int idle_busy_ratio_x_16 = 0;
8221 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
8222 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
8223 if (duty_cycle > 100 || duty_cycle < 0) {
8224 WL_ERROR("wl%d: duty cycle value off limit\n", wlc->pub->unit);
8228 idle_busy_ratio_x_16 = (100 - duty_cycle) * 16 / duty_cycle;
8229 /* Only write to shared memory when wl is up */
8231 wlc_write_shm(wlc, offset, (u16) idle_busy_ratio_x_16);
8234 wlc->tx_duty_cycle_ofdm = (u16) duty_cycle;
8236 wlc->tx_duty_cycle_cck = (u16) duty_cycle;
8241 /* Read a single u16 from shared memory.
8242 * SHM 'offset' needs to be an even address
8244 u16 wlc_read_shm(struct wlc_info *wlc, uint offset)
8246 return wlc_bmac_read_shm(wlc->hw, offset);
8249 /* Write a single u16 to shared memory.
8250 * SHM 'offset' needs to be an even address
8252 void wlc_write_shm(struct wlc_info *wlc, uint offset, u16 v)
8254 wlc_bmac_write_shm(wlc->hw, offset, v);
8257 /* Set a range of shared memory to a value.
8258 * SHM 'offset' needs to be an even address and
8259 * Range length 'len' must be an even number of bytes
8261 void wlc_set_shm(struct wlc_info *wlc, uint offset, u16 v, int len)
8263 /* offset and len need to be even */
8264 ASSERT((offset & 1) == 0);
8265 ASSERT((len & 1) == 0);
8270 wlc_bmac_set_shm(wlc->hw, offset, v, len);
8273 /* Copy a buffer to shared memory.
8274 * SHM 'offset' needs to be an even address and
8275 * Buffer length 'len' must be an even number of bytes
8277 void wlc_copyto_shm(struct wlc_info *wlc, uint offset, const void *buf, int len)
8279 /* offset and len need to be even */
8280 ASSERT((offset & 1) == 0);
8281 ASSERT((len & 1) == 0);
8285 wlc_bmac_copyto_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8289 /* Copy from shared memory to a buffer.
8290 * SHM 'offset' needs to be an even address and
8291 * Buffer length 'len' must be an even number of bytes
8293 void wlc_copyfrom_shm(struct wlc_info *wlc, uint offset, void *buf, int len)
8295 /* offset and len need to be even */
8296 ASSERT((offset & 1) == 0);
8297 ASSERT((len & 1) == 0);
8302 wlc_bmac_copyfrom_objmem(wlc->hw, offset, buf, len, OBJADDR_SHM_SEL);
8305 /* wrapper BMAC functions to for HIGH driver access */
8306 void wlc_mctrl(struct wlc_info *wlc, u32 mask, u32 val)
8308 wlc_bmac_mctrl(wlc->hw, mask, val);
8311 void wlc_corereset(struct wlc_info *wlc, u32 flags)
8313 wlc_bmac_corereset(wlc->hw, flags);
8316 void wlc_mhf(struct wlc_info *wlc, u8 idx, u16 mask, u16 val, int bands)
8318 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands);
8321 u16 wlc_mhf_get(struct wlc_info *wlc, u8 idx, int bands)
8323 return wlc_bmac_mhf_get(wlc->hw, idx, bands);
8326 int wlc_xmtfifo_sz_get(struct wlc_info *wlc, uint fifo, uint *blocks)
8328 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks);
8331 void wlc_write_template_ram(struct wlc_info *wlc, int offset, int len,
8334 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf);
8337 void wlc_write_hw_bcntemplates(struct wlc_info *wlc, void *bcn, int len,
8340 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both);
8344 wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
8347 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr);
8348 if (match_reg_offset == RCM_BSSID_OFFSET)
8349 memcpy(wlc->cfg->BSSID, addr, ETH_ALEN);
8352 void wlc_set_rcmta(struct wlc_info *wlc, int idx, const u8 *addr)
8354 wlc_bmac_set_rcmta(wlc->hw, idx, addr);
8357 void wlc_read_tsf(struct wlc_info *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr)
8359 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr);
8362 void wlc_set_cwmin(struct wlc_info *wlc, u16 newmin)
8364 wlc->band->CWmin = newmin;
8365 wlc_bmac_set_cwmin(wlc->hw, newmin);
8368 void wlc_set_cwmax(struct wlc_info *wlc, u16 newmax)
8370 wlc->band->CWmax = newmax;
8371 wlc_bmac_set_cwmax(wlc->hw, newmax);
8374 void wlc_fifoerrors(struct wlc_info *wlc)
8377 wlc_bmac_fifoerrors(wlc->hw);
8380 /* Search mem rw utilities */
8382 void wlc_pllreq(struct wlc_info *wlc, bool set, mbool req_bit)
8384 wlc_bmac_pllreq(wlc->hw, set, req_bit);
8387 void wlc_reset_bmac_done(struct wlc_info *wlc)
8391 void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode)
8393 wlc->ht_cap.cap_info &= ~HT_CAP_MIMO_PS_MASK;
8394 wlc->ht_cap.cap_info |= (mimops_mode << IEEE80211_HT_CAP_SM_PS_SHIFT);
8396 if (AP_ENAB(wlc->pub) && wlc->clk) {
8397 wlc_update_beacon(wlc);
8398 wlc_update_probe_resp(wlc, true);
8402 /* check for the particular priority flow control bit being set */
8404 wlc_txflowcontrol_prio_isset(struct wlc_info *wlc, wlc_txq_info_t *q, int prio)
8408 if (prio == ALLPRIO) {
8409 prio_mask = TXQ_STOP_FOR_PRIOFC_MASK;
8411 ASSERT(prio >= 0 && prio <= MAXPRIO);
8412 prio_mask = NBITVAL(prio);
8415 return (q->stopped & prio_mask) == prio_mask;
8418 /* propogate the flow control to all interfaces using the given tx queue */
8419 void wlc_txflowcontrol(struct wlc_info *wlc, wlc_txq_info_t *qi,
8425 WL_TRACE("%s: flow control kicks in\n", __func__);
8427 if (prio == ALLPRIO) {
8428 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
8430 ASSERT(prio >= 0 && prio <= MAXPRIO);
8431 prio_bits = NBITVAL(prio);
8434 cur_bits = qi->stopped & prio_bits;
8436 /* Check for the case of no change and return early
8437 * Otherwise update the bit and continue
8440 if (cur_bits == prio_bits) {
8443 mboolset(qi->stopped, prio_bits);
8445 if (cur_bits == 0) {
8448 mboolclr(qi->stopped, prio_bits);
8451 /* If there is a flow control override we will not change the external
8452 * flow control state.
8454 if (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK) {
8458 wlc_txflowcontrol_signal(wlc, qi, on, prio);
8462 wlc_txflowcontrol_override(struct wlc_info *wlc, wlc_txq_info_t *qi, bool on,
8467 ASSERT(override != 0);
8468 ASSERT((override & TXQ_STOP_FOR_PRIOFC_MASK) == 0);
8470 prev_override = (qi->stopped & ~TXQ_STOP_FOR_PRIOFC_MASK);
8472 /* Update the flow control bits and do an early return if there is
8473 * no change in the external flow control state.
8476 mboolset(qi->stopped, override);
8477 /* if there was a previous override bit on, then setting this
8478 * makes no difference.
8480 if (prev_override) {
8484 wlc_txflowcontrol_signal(wlc, qi, ON, ALLPRIO);
8486 mboolclr(qi->stopped, override);
8487 /* clearing an override bit will only make a difference for
8488 * flow control if it was the only bit set. For any other
8489 * override setting, just return
8491 if (prev_override != override) {
8495 if (qi->stopped == 0) {
8496 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8500 for (prio = MAXPRIO; prio >= 0; prio--) {
8501 if (!mboolisset(qi->stopped, NBITVAL(prio)))
8502 wlc_txflowcontrol_signal(wlc, qi, OFF,
8509 static void wlc_txflowcontrol_reset(struct wlc_info *wlc)
8513 for (qi = wlc->tx_queues; qi != NULL; qi = qi->next) {
8515 wlc_txflowcontrol_signal(wlc, qi, OFF, ALLPRIO);
8522 wlc_txflowcontrol_signal(struct wlc_info *wlc, wlc_txq_info_t *qi, bool on,
8525 struct wlc_if *wlcif;
8527 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
8528 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
8529 wl_txflowcontrol(wlc->wl, wlcif->wlif, on, prio);
8533 static wlc_txq_info_t *wlc_txq_alloc(struct wlc_info *wlc, struct osl_info *osh)
8535 wlc_txq_info_t *qi, *p;
8537 qi = (wlc_txq_info_t *) wlc_calloc(osh, wlc->pub->unit,
8538 sizeof(wlc_txq_info_t));
8543 /* Have enough room for control packets along with HI watermark */
8544 /* Also, add room to txq for total psq packets if all the SCBs leave PS mode */
8545 /* The watermark for flowcontrol to OS packets will remain the same */
8546 pktq_init(&qi->q, WLC_PREC_COUNT,
8547 (2 * wlc->pub->tunables->datahiwat) + PKTQ_LEN_DEFAULT +
8548 wlc->pub->psq_pkts_total);
8550 /* add this queue to the the global list */
8553 wlc->tx_queues = qi;
8555 while (p->next != NULL)
8563 static void wlc_txq_free(struct wlc_info *wlc, struct osl_info *osh,
8571 /* remove the queue from the linked list */
8574 wlc->tx_queues = p->next;
8576 while (p != NULL && p->next != qi)
8578 ASSERT(p->next == qi);
8580 p->next = p->next->next;
8587 * Flag 'scan in progress' to withold dynamic phy calibration
8589 void wlc_scan_start(struct wlc_info *wlc)
8591 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, true);
8594 void wlc_scan_stop(struct wlc_info *wlc)
8596 wlc_phy_hold_upd(wlc->band->pi, PHY_HOLD_FOR_SCAN, false);
8599 void wlc_associate_upd(struct wlc_info *wlc, bool state)
8601 wlc->pub->associated = state;
8602 wlc->cfg->associated = state;